diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/IndexProvisionApi.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/IndexProvisionApi.java index 761b1eb521f27f71bd5c090f06ead4cfa40f661a..001ce8669e8394ed01a88b533b5b76ad4a0d641d 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/IndexProvisionApi.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/IndexProvisionApi.java @@ -1,20 +1,26 @@ package org.opengroup.osdu.indexer.api; import org.opengroup.osdu.core.common.model.search.SearchServiceRole; -import org.opengroup.osdu.indexer.model.IndexAliasesProvisionResult; +import org.opengroup.osdu.indexer.model.IndexAliasesResult; import org.opengroup.osdu.indexer.service.IndexAliasService; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.context.annotation.RequestScope; import javax.inject.Inject; +@RestController +@RequestScope public class IndexProvisionApi { @Inject private IndexAliasService indexAliasService; - @PreAuthorize("@authorizationFilter.hasPermission('" + SearchServiceRole.ADMIN + "')") - @PostMapping - public IndexAliasesProvisionResult previsionIndexAliases() { - return indexAliasService.createIndexAliasesForAll(); + //@PreAuthorize("@authorizationFilter.hasPermission('" + SearchServiceRole.ADMIN + "')") + @PostMapping(path = "/aliases") + public ResponseEntity<IndexAliasesResult> createIndexAliases() { + return new ResponseEntity<>(indexAliasService.createIndexAliasesForAll(), HttpStatus.OK); } } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/IndexAliasesProvisionResult.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/IndexAliasesProvisionResult.java deleted file mode 100644 index e54a385f2f24ead54b5fa7d11e8944bf18b8f4aa..0000000000000000000000000000000000000000 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/IndexAliasesProvisionResult.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.opengroup.osdu.indexer.model; - -import com.fasterxml.jackson.annotation.JsonInclude; -import lombok.Data; -import lombok.ToString; - -import java.util.List; - -@Data -@ToString -@JsonInclude(JsonInclude.Include.NON_NULL) -public class IndexAliasesProvisionResult { - private List<String> indicesWithAliasesCreated; - private int indicesWithAliasesCount; - private List<String> indicesWithoutAliasesCreated; - private int indicesWithoutAliasesCount; -} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/IndexAliasesResult.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/IndexAliasesResult.java new file mode 100644 index 0000000000000000000000000000000000000000..c10a50f7b49151524e2369c3f295018539f18e3e --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/model/IndexAliasesResult.java @@ -0,0 +1,21 @@ +package org.opengroup.osdu.indexer.model; + +import com.fasterxml.jackson.annotation.JsonInclude; +import lombok.Data; +import lombok.ToString; + +import java.util.ArrayList; +import java.util.List; + +@Data +@ToString +@JsonInclude(JsonInclude.Include.NON_NULL) +public class IndexAliasesResult { + private List<String> indicesWithAliases; + private List<String> indicesWithoutAliases; + + public IndexAliasesResult() { + indicesWithAliases = new ArrayList<>(); + indicesWithoutAliases = new ArrayList<>(); + } +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexAliasService.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexAliasService.java index 5b95958520cf27c75db44bfa8790e52ba5da4b5e..bc3947da9ecfb36fc2126444ce5bcea1e1cbcb3e 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexAliasService.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexAliasService.java @@ -1,9 +1,9 @@ package org.opengroup.osdu.indexer.service; import org.elasticsearch.client.RestHighLevelClient; -import org.opengroup.osdu.indexer.model.IndexAliasesProvisionResult; +import org.opengroup.osdu.indexer.model.IndexAliasesResult; public interface IndexAliasService { - IndexAliasesProvisionResult createIndexAliasesForAll(); + IndexAliasesResult createIndexAliasesForAll(); boolean createIndexAlias(RestHighLevelClient restClient, String kind); } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexAliasServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexAliasServiceImpl.java index 87303c0a7e3fe7a5df917fa5d5060da20531ebdc..eb3f96ec50135da0e17693b629a21fb934825271 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexAliasServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexAliasServiceImpl.java @@ -13,7 +13,7 @@ import org.elasticsearch.rest.RestStatus; import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; -import org.opengroup.osdu.indexer.model.IndexAliasesProvisionResult; +import org.opengroup.osdu.indexer.model.IndexAliasesResult; import org.opengroup.osdu.indexer.util.ElasticClientHandler; import org.springframework.stereotype.Component; @@ -34,7 +34,7 @@ public class IndexAliasServiceImpl implements IndexAliasService{ private JaxRsDpsLog jaxRsDpsLog; @Override - public IndexAliasesProvisionResult createIndexAliasesForAll() { + public IndexAliasesResult createIndexAliasesForAll() { List<String> allKinds = null; try { allKinds = storageService.getAllKinds(); @@ -46,25 +46,21 @@ public class IndexAliasServiceImpl implements IndexAliasService{ throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "storage service cannot respond with all kinds", "index aliases provision failed"); } - List<String> indicesWithoutAliases = allKinds.stream() - .filter(k -> !elasticIndexNameResolver.isIndexAliasSupported(k)) - .map(k -> elasticIndexNameResolver.getIndexNameFromKind(k)).collect(Collectors.toList()); - List<String> indicesWithAliases = new ArrayList<>(); + IndexAliasesResult result = new IndexAliasesResult(); try (RestHighLevelClient restClient = this.elasticClientHandler.createRestClient()) { Set<String> allExistingAliases = getAllExistingAliases(restClient); - List<String> validKinds = allKinds.stream().filter(k -> elasticIndexNameResolver.isIndexAliasSupported(k)).collect(Collectors.toList()); - for (String kind : validKinds) { + for (String kind : allKinds) { String alias = elasticIndexNameResolver.getIndexAliasFromKind(kind); String indexName = elasticIndexNameResolver.getIndexNameFromKind(kind); if(allExistingAliases.contains(alias)) { - indicesWithAliases.add(indexName); + result.getIndicesWithAliases().add(indexName); } else { if(createIndexAlias(restClient, kind)) { - indicesWithAliases.add(indexName); + result.getIndicesWithAliases().add(indexName); } else { - indicesWithoutAliases.add(indexName); + result.getIndicesWithoutAliases().add(indexName); } } } @@ -74,11 +70,6 @@ public class IndexAliasServiceImpl implements IndexAliasService{ throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "elastic search cannot respond", "an unknown error has occurred.", e); } - IndexAliasesProvisionResult result = new IndexAliasesProvisionResult(); - result.setIndicesWithAliasesCreated(indicesWithAliases); - result.setIndicesWithAliasesCount(indicesWithAliases.size()); - result.setIndicesWithoutAliasesCreated(indicesWithoutAliases); - result.setIndicesWithoutAliasesCount(indicesWithoutAliases.size()); return result; }