diff --git a/tests/jenkins/TestPublishDistributionBuildResults.groovy b/tests/jenkins/TestPublishDistributionBuildResults.groovy index dc8ace9b..50c7edc6 100644 --- a/tests/jenkins/TestPublishDistributionBuildResults.groovy +++ b/tests/jenkins/TestPublishDistributionBuildResults.groovy @@ -106,9 +106,6 @@ class TestPublishDistributionBuildResults extends BuildPipelineTest { "type": "keyword" } } - }, - "aliases": { - "opensearch-distribution-build-results": {} } }' curl -I "METRICS_HOST_URL/test-index" --aws-sigv4 "aws:amz:us-east-1:es" --user "null:null" -H "x-amz-security-token:null" | grep -E "HTTP\\/[0-9]+(\\.[0-9]+)? 200" @@ -119,6 +116,22 @@ class TestPublishDistributionBuildResults extends BuildPipelineTest { create_index_response=$(curl -s -XPUT "METRICS_HOST_URL/test-index" --aws-sigv4 "aws:amz:us-east-1:es" --user "null:null" -H "x-amz-security-token:null" -H 'Content-Type: application/json' -d "${INDEX_MAPPING}") if [[ $create_index_response == *'"acknowledged":true'* ]]; then echo "Index created successfully." + echo "Updating alias..." + update_alias_response=\$(curl -s -XPOST "METRICS_HOST_URL/_aliases" --aws-sigv4 "aws:amz:us-east-1:es" --user "null:null" -H "x-amz-security-token:null" -H "Content-Type: application/json" -d '{ + "actions": [ + { + "add": { + "index": "test-index", + "alias": "opensearch-distribution-build-results" + } + } + ] + }') + if [[ \$update_alias_response == *'"acknowledged":true'* ]]; then + echo "Alias updated successfully." + else + echo "Failed to update alias. Error message: \$update_alias_response" + fi else echo "Failed to create index. Error message: $create_index_response" exit 1 diff --git a/vars/publishDistributionBuildResults.groovy b/vars/publishDistributionBuildResults.groovy index abe83303..7a4e1e75 100644 --- a/vars/publishDistributionBuildResults.groovy +++ b/vars/publishDistributionBuildResults.groovy @@ -114,9 +114,6 @@ void indexFailedTestData(indexName, testRecordsFile) { "type": "keyword" } } - }, - "aliases": { - "opensearch-distribution-build-results": {} } }' curl -I "${METRICS_HOST_URL}/${indexName}" --aws-sigv4 \"aws:amz:us-east-1:es\" --user \"${awsAccessKey}:${awsSecretKey}\" -H \"x-amz-security-token:${awsSessionToken}\" | grep -E "HTTP\\/[0-9]+(\\.[0-9]+)? 200" @@ -127,6 +124,22 @@ void indexFailedTestData(indexName, testRecordsFile) { create_index_response=\$(curl -s -XPUT "${METRICS_HOST_URL}/${indexName}" --aws-sigv4 \"aws:amz:us-east-1:es\" --user \"${awsAccessKey}:${awsSecretKey}\" -H \"x-amz-security-token:${awsSessionToken}\" -H 'Content-Type: application/json' -d "\${INDEX_MAPPING}") if [[ \$create_index_response == *'"acknowledged":true'* ]]; then echo "Index created successfully." + echo "Updating alias..." + update_alias_response=\$(curl -s -XPOST "${METRICS_HOST_URL}/_aliases" --aws-sigv4 "aws:amz:us-east-1:es" --user "${awsAccessKey}:${awsSecretKey}" -H "x-amz-security-token:${awsSessionToken}" -H "Content-Type: application/json" -d '{ + "actions": [ + { + "add": { + "index": "${indexName}", + "alias": "opensearch-distribution-build-results" + } + } + ] + }') + if [[ \$update_alias_response == *'"acknowledged":true'* ]]; then + echo "Alias updated successfully." + else + echo "Failed to update alias. Error message: \$update_alias_response" + fi else echo "Failed to create index. Error message: \$create_index_response" exit 1 diff --git a/vars/publishGradleCheckTestResults.groovy b/vars/publishGradleCheckTestResults.groovy index 8e023133..d3eb4054 100644 --- a/vars/publishGradleCheckTestResults.groovy +++ b/vars/publishGradleCheckTestResults.groovy @@ -164,9 +164,6 @@ void indexFailedTestData() { "type": "keyword" } } - }, - "aliases": { - "gradle-check": {} } }' echo "INDEX NAME IS \$INDEX_NAME" @@ -178,6 +175,22 @@ void indexFailedTestData() { create_index_response=\$(curl -s -XPUT "${METRICS_HOST_URL}/\${INDEX_NAME}" --aws-sigv4 \"aws:amz:us-east-1:es\" --user \"${awsAccessKey}:${awsSecretKey}\" -H \"x-amz-security-token:${awsSessionToken}\" -H 'Content-Type: application/json' -d "\${INDEX_MAPPING}") if [[ \$create_index_response == *'"acknowledged":true'* ]]; then echo "Index created successfully." + echo "Updating alias..." + update_alias_response=\$(curl -s -XPOST "${METRICS_HOST_URL}/_aliases" --aws-sigv4 \"aws:amz:us-east-1:es\" --user \"${awsAccessKey}:${awsSecretKey}\" -H \"x-amz-security-token:${awsSessionToken}\" -H "Content-Type: application/json" -d '{ + "actions": [ + { + "add": { + "index": "\${INDEX_NAME}", + "alias": "gradle-check" + } + } + ] + }') + if [[ \$update_alias_response == *'"acknowledged":true'* ]]; then + echo "Alias updated successfully." + else + echo "Failed to update alias. Error message: \$update_alias_response" + fi else echo "Failed to create index. Error message: \$create_index_response" exit 1