Skip to content

Commit

Permalink
Reduce code difference (#670)
Browse files Browse the repository at this point in the history
Signed-off-by: bowenlan-amzn <[email protected]>
(cherry picked from commit 536eb70)
  • Loading branch information
bowenlan-amzn authored and github-actions[bot] committed Jan 30, 2023
1 parent 8ac614d commit 8433bef
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
25 changes: 16 additions & 9 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ buildscript {
if (isSnapshot) {
opensearch_build += "-SNAPSHOT"
}
if (!isSnapshot) {
opensearch_version = opensearch_version.replace("-SNAPSHOT","")
}
opensearch_no_snapshot = opensearch_version.replace("-SNAPSHOT","")
job_scheduler_resource_folder = "src/test/resources/job-scheduler"

Expand Down Expand Up @@ -66,7 +69,7 @@ buildscript {

plugins {
id 'nebula.ospackage' version "8.3.0"
id "com.dorongold.task-tree" version "1.5"
id "com.dorongold.task-tree" version "2.1.1"
}

apply plugin: 'java'
Expand Down Expand Up @@ -281,10 +284,16 @@ test {
}

ext.getPluginResource = { download_to_folder, download_from_src ->
project.mkdir download_to_folder
ant.get(src: download_from_src,
dest: download_to_folder,
httpusecaches: false)
def src_split = download_from_src.split("/")
def download_file = src_split[src_split.length-1]
if (!fileTree(download_to_folder).contains(new File("$project.rootDir/$download_to_folder/$download_file"))) {
println("Downloading ${download_file}")
project.delete download_to_folder
project.mkdir download_to_folder
ant.get(src: download_from_src,
dest: download_to_folder,
httpusecaches: false)
}
return fileTree(download_to_folder).getSingleFile()
}

Expand Down Expand Up @@ -459,12 +468,10 @@ String bwc_im_resource_location = bwcFilePath + "indexmanagement/" + bwcVersion
// Downloads the bwc job scheduler version
String bwc_js_download_url = "https://github.com/opendistro-for-elasticsearch/job-scheduler/releases/download/v" +
bwcJobSchedulerVersion + "/job-scheduler-artifacts.zip"
getPluginResource(bwc_js_resource_location, bwc_js_download_url)

// Downloads the bwc index management version
String bwc_im_download_url = "https://github.com/opendistro-for-elasticsearch/index-management/releases/download/v" +
bwcVersion + "/index-management-artifacts.zip"
getPluginResource(bwc_im_resource_location, bwc_im_download_url)

2.times {i ->
testClusters {
Expand All @@ -478,7 +485,7 @@ getPluginResource(bwc_im_resource_location, bwc_im_download_url)
return new RegularFile() {
@Override
File getAsFile() {
return fileTree(bwc_js_resource_location).getSingleFile()
return getPluginResource(bwc_js_resource_location, bwc_js_download_url)
}
}
}
Expand All @@ -490,7 +497,7 @@ getPluginResource(bwc_im_resource_location, bwc_im_download_url)
return new RegularFile() {
@Override
File getAsFile() {
return fileTree(bwc_im_resource_location).getSingleFile()
return getPluginResource(bwc_im_resource_location, bwc_im_download_url)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndex
import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings.Companion.TEMPLATE_MIGRATION_CONTROL
import org.opensearch.indexmanagement.indexstatemanagement.transport.action.managedIndex.ManagedIndexAction
import org.opensearch.indexmanagement.indexstatemanagement.transport.action.managedIndex.ManagedIndexRequest
import org.opensearch.indexmanagement.indexstatemanagement.util.DEFAULT_INDEX_TYPE
import org.opensearch.indexmanagement.indexstatemanagement.util.ISM_TEMPLATE_FIELD
import org.opensearch.indexmanagement.indexstatemanagement.util.deleteManagedIndexMetadataRequest
import org.opensearch.indexmanagement.indexstatemanagement.util.deleteManagedIndexRequest
Expand Down Expand Up @@ -313,7 +314,7 @@ class ManagedIndexCoordinator(
/**
* build requests to create jobs for indices matching ISM templates
*/
@Suppress("NestedBlockDepth")
@Suppress("NestedBlockDepth", "ComplexCondition")
private suspend fun createManagedIndexRequests(
clusterState: ClusterState,
indexNames: List<String>
Expand All @@ -326,10 +327,15 @@ class ManagedIndexCoordinator(
val ismIndicesMetadata: Map<String, ISMIndexMetadata> = indexMetadataProvider.getISMIndexMetadataByType(indexNames = indexNames)
// Iterate over each unmanaged hot/warm index and if it matches an ISM template add a managed index config index request
indexNames.forEach { indexName ->
val defaultIndexMetadataService = indexMetadataProvider.services[DEFAULT_INDEX_TYPE] as DefaultIndexMetadataService
// If there is a custom index uuid associated with the index, we do not auto manage it
// This is because cold index uses custom uuid, and we do not auto manage cold-to-warm index
val indexMetadata = clusterState.metadata.index(indexName)
val wasOffCluster = defaultIndexMetadataService.getCustomIndexUUID(indexMetadata) != indexMetadata.indexUUID
val ismIndexMetadata = ismIndicesMetadata[indexName]
// We try to find lookup name instead of using index name as datastream indices need the alias to match policy
val lookupName = findIndexLookupName(indexName, clusterState)
if (lookupName != null && !indexMetadataProvider.isUnManageableIndex(lookupName) && ismIndexMetadata != null) {
if (lookupName != null && !indexMetadataProvider.isUnManageableIndex(lookupName) && ismIndexMetadata != null && !wasOffCluster) {
val creationDate = ismIndexMetadata.indexCreationDate
val indexUuid = ismIndexMetadata.indexUuid
findMatchingPolicy(lookupName, creationDate, policiesWithTemplates)
Expand Down

0 comments on commit 8433bef

Please sign in to comment.