Skip to content

Commit

Permalink
Reduce code difference (opensearch-project#670) (opensearch-project#674)
Browse files Browse the repository at this point in the history
Signed-off-by: bowenlan-amzn <bowenlan23@gmail.com>
  • Loading branch information
bowenlan-amzn authored Jan 31, 2023
1 parent 98de5cb commit 56f5822
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
24 changes: 16 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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 @@ -80,7 +83,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 @@ -324,10 +327,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 @@ -642,7 +651,6 @@ 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" +
Expand Down Expand Up @@ -688,7 +696,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 @@ -700,7 +708,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 @@ -315,7 +316,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 @@ -328,10 +329,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 56f5822

Please sign in to comment.