Skip to content

Commit 536eb70

Browse files
Reduce code difference (#670)
Signed-off-by: bowenlan-amzn <[email protected]>
1 parent 76d530f commit 536eb70

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

build.gradle

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ buildscript {
4242
if (isSnapshot) {
4343
opensearch_build += "-SNAPSHOT"
4444
}
45+
if (!isSnapshot) {
46+
opensearch_version = opensearch_version.replace("-SNAPSHOT","")
47+
}
4548
opensearch_no_snapshot = opensearch_version.replace("-SNAPSHOT","")
4649
job_scheduler_resource_folder = "src/test/resources/job-scheduler"
4750

@@ -80,7 +83,7 @@ buildscript {
8083

8184
plugins {
8285
id 'nebula.ospackage' version "8.3.0"
83-
id "com.dorongold.task-tree" version "1.5"
86+
id "com.dorongold.task-tree" version "2.1.1"
8487
}
8588

8689
apply plugin: 'java'
@@ -324,10 +327,16 @@ test {
324327
}
325328

326329
ext.getPluginResource = { download_to_folder, download_from_src ->
327-
project.mkdir download_to_folder
328-
ant.get(src: download_from_src,
329-
dest: download_to_folder,
330-
httpusecaches: false)
330+
def src_split = download_from_src.split("/")
331+
def download_file = src_split[src_split.length-1]
332+
if (!fileTree(download_to_folder).contains(new File("$project.rootDir/$download_to_folder/$download_file"))) {
333+
println("Downloading ${download_file}")
334+
project.delete download_to_folder
335+
project.mkdir download_to_folder
336+
ant.get(src: download_from_src,
337+
dest: download_to_folder,
338+
httpusecaches: false)
339+
}
331340
return fileTree(download_to_folder).getSingleFile()
332341
}
333342

@@ -637,12 +646,10 @@ String bwc_im_resource_location = bwcFilePath + "indexmanagement/" + bwcVersion
637646
// Downloads the bwc job scheduler version
638647
String bwc_js_download_url = "https://github.com/opendistro-for-elasticsearch/job-scheduler/releases/download/v" +
639648
bwcJobSchedulerVersion + "/job-scheduler-artifacts.zip"
640-
getPluginResource(bwc_js_resource_location, bwc_js_download_url)
641649

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

647654
2.times {i ->
648655
testClusters {
@@ -656,7 +663,7 @@ getPluginResource(bwc_im_resource_location, bwc_im_download_url)
656663
return new RegularFile() {
657664
@Override
658665
File getAsFile() {
659-
return fileTree(bwc_js_resource_location).getSingleFile()
666+
return getPluginResource(bwc_js_resource_location, bwc_js_download_url)
660667
}
661668
}
662669
}
@@ -668,7 +675,7 @@ getPluginResource(bwc_im_resource_location, bwc_im_download_url)
668675
return new RegularFile() {
669676
@Override
670677
File getAsFile() {
671-
return fileTree(bwc_im_resource_location).getSingleFile()
678+
return getPluginResource(bwc_im_resource_location, bwc_im_download_url)
672679
}
673680
}
674681
}

src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexCoordinator.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndex
6464
import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings.Companion.TEMPLATE_MIGRATION_CONTROL
6565
import org.opensearch.indexmanagement.indexstatemanagement.transport.action.managedIndex.ManagedIndexAction
6666
import org.opensearch.indexmanagement.indexstatemanagement.transport.action.managedIndex.ManagedIndexRequest
67+
import org.opensearch.indexmanagement.indexstatemanagement.util.DEFAULT_INDEX_TYPE
6768
import org.opensearch.indexmanagement.indexstatemanagement.util.ISM_TEMPLATE_FIELD
6869
import org.opensearch.indexmanagement.indexstatemanagement.util.deleteManagedIndexMetadataRequest
6970
import org.opensearch.indexmanagement.indexstatemanagement.util.deleteManagedIndexRequest
@@ -315,7 +316,7 @@ class ManagedIndexCoordinator(
315316
/**
316317
* build requests to create jobs for indices matching ISM templates
317318
*/
318-
@Suppress("NestedBlockDepth")
319+
@Suppress("NestedBlockDepth", "ComplexCondition")
319320
private suspend fun createManagedIndexRequests(
320321
clusterState: ClusterState,
321322
indexNames: List<String>
@@ -328,10 +329,15 @@ class ManagedIndexCoordinator(
328329
val ismIndicesMetadata: Map<String, ISMIndexMetadata> = indexMetadataProvider.getISMIndexMetadataByType(indexNames = indexNames)
329330
// Iterate over each unmanaged hot/warm index and if it matches an ISM template add a managed index config index request
330331
indexNames.forEach { indexName ->
332+
val defaultIndexMetadataService = indexMetadataProvider.services[DEFAULT_INDEX_TYPE] as DefaultIndexMetadataService
333+
// If there is a custom index uuid associated with the index, we do not auto manage it
334+
// This is because cold index uses custom uuid, and we do not auto manage cold-to-warm index
335+
val indexMetadata = clusterState.metadata.index(indexName)
336+
val wasOffCluster = defaultIndexMetadataService.getCustomIndexUUID(indexMetadata) != indexMetadata.indexUUID
331337
val ismIndexMetadata = ismIndicesMetadata[indexName]
332338
// We try to find lookup name instead of using index name as datastream indices need the alias to match policy
333339
val lookupName = findIndexLookupName(indexName, clusterState)
334-
if (lookupName != null && !indexMetadataProvider.isUnManageableIndex(lookupName) && ismIndexMetadata != null) {
340+
if (lookupName != null && !indexMetadataProvider.isUnManageableIndex(lookupName) && ismIndexMetadata != null && !wasOffCluster) {
335341
val creationDate = ismIndexMetadata.indexCreationDate
336342
val indexUuid = ismIndexMetadata.indexUuid
337343
findMatchingPolicy(lookupName, creationDate, policiesWithTemplates)

0 commit comments

Comments
 (0)