diff --git a/devops/service-pipeline.yml b/devops/service-pipeline.yml new file mode 100644 index 0000000000000000000000000000000000000000..ace49b2028ce071910db39917d04a77b340dae67 --- /dev/null +++ b/devops/service-pipeline.yml @@ -0,0 +1,67 @@ +##################### +# README: Defines a template to be used as a starting point for defining a service pipeline +##################### + +trigger: + batch: true + branches: + include: + - master + paths: + exclude: + - /**/*.md + - .gitignore + - images/ + +pr: + autoCancel: true + branches: + include: + - '*' + paths: + exclude: + - /**/*.md + - .gitignore + - images/ + +variables: + - group: 'Azure Common Secrets' + - group: 'Azure - Common' + + - name: serviceName + value: 'indexer' + +resources: + repositories: + - repository: infrastructure-templates + type: git + name: open-data-ecosystem/infrastructure-templates + +stages: + - template: devops/service-pipelines/build-stage.yml@infrastructure-templates + parameters: + mavenGoal: 'package' + mavenPublishJUnitResults: true + serviceCoreMavenOptions: '--settings ./indexer-core/maven/settings.xml -DVSTS_FEED_TOKEN=$(VSTS_FEED_TOKEN) -U' + mavenOptions: '--settings ./provider/${{ variables.serviceName }}-azure/maven/settings.xml -DVSTS_FEED_TOKEN=$(VSTS_FEED_TOKEN) -U -P indexer-azure' + copyFileContents: | + pom.xml + provider/${{ variables.serviceName }}-azure/maven/settings.xml + provider/${{ variables.serviceName }}-azure/pom.xml + provider/${{ variables.serviceName }}-azure/target/*-spring-boot.jar + copyFileContentsToFlatten: '' + serviceBase: ${{ variables.serviceName }} + testingRootFolder: 'testing' + - template: devops/service-pipelines/deploy-stages.yml@infrastructure-templates + parameters: + serviceName: ${{ variables.serviceName }} + testCoreMavenPomFile: 'testing/indexer-test-core/pom.xml' + testCoreMavenOptions: '--settings $(System.DefaultWorkingDirectory)/drop/deploy/testing/maven/settings.xml -DVSTS_FEED_TOKEN=$(VSTS_FEED_TOKEN) -U' + providers: + - name: Azure + # Merges into Master + ${{ if eq(variables['Build.SourceBranchName'], 'master') }}: + environments: ['devint', 'qa', 'prod'] + # PR updates / creations + ${{ if ne(variables['Build.SourceBranchName'], 'master') }}: + environments: ['devint'] diff --git a/indexer-core/pom.xml b/indexer-core/pom.xml index 9311a2dafc890e6c3dfe15cd2bd4d3c15fb87ddc..6012b4efe37bada412276e8a2eaa673a57cebb51 100644 --- a/indexer-core/pom.xml +++ b/indexer-core/pom.xml @@ -5,10 +5,11 @@ <parent> <groupId>org.opengroup.osdu.indexer</groupId> <artifactId>indexer-service</artifactId> - <version>1.0.3-SNAPSHOT</version> + <version>1.0.4-SNAPSHOT</version> </parent> <artifactId>indexer-core</artifactId> + <version>1.0.4-SNAPSHOT</version> <name>indexer-core</name> <description>Indexer Service Core</description> <packaging>jar</packaging> @@ -17,12 +18,7 @@ <dependency> <groupId>org.opengroup.osdu</groupId> <artifactId>os-core-common</artifactId> - <version>0.0.8</version> - </dependency> - <dependency> - <groupId>org.opengroup.osdu</groupId> - <artifactId>indexer-search-core-lib</artifactId> - <version>1.0.22</version> + <version>0.0.12</version> </dependency> <!-- spring boot dependencies --> diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/HealthCheckApi.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/HealthCheckApi.java index c6c7d1b8edc8c89279b610a330afdebbe2d55396..d19ac9d042d9727b901d0148b34ea4a0dc3289e4 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/HealthCheckApi.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/HealthCheckApi.java @@ -15,7 +15,6 @@ package org.opengroup.osdu.indexer.api; import lombok.extern.java.Log; -import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/RecordIndexerApi.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/RecordIndexerApi.java index 545570a22505e968ce7070578f5a978cb43d73fc..cfa3f23415108db2b88c95386b28de7d7679789f 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/RecordIndexerApi.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/RecordIndexerApi.java @@ -20,9 +20,9 @@ import com.google.gson.Gson; import com.google.gson.JsonParseException; import io.swagger.annotations.ApiOperation; import lombok.extern.java.Log; -import org.opengroup.osdu.core.common.model.core.DpsHeaders; -import org.opengroup.osdu.core.common.model.coreis.AppException; -import org.opengroup.osdu.core.common.model.coreis.RecordChangedMessages; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.model.search.RecordChangedMessages; import org.opengroup.osdu.indexer.SwaggerDoc; import org.opengroup.osdu.core.common.model.indexer.JobStatus; import org.opengroup.osdu.core.common.model.indexer.RecordReindexRequest; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/ReindexApi.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/ReindexApi.java index b4a7f30a05db4ad8d2422698eb582c61b8906f6c..5df99479e436aa6a66ef8dd803c549922cdf40ea 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/ReindexApi.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/api/ReindexApi.java @@ -14,8 +14,8 @@ package org.opengroup.osdu.indexer.api; -import org.opengroup.osdu.core.common.model.coreis.SearchServiceRole; -import org.opengroup.osdu.core.common.model.indexer.AuditLogger; +import org.opengroup.osdu.core.common.model.search.SearchServiceRole; +import org.opengroup.osdu.indexer.logging.AuditLogger; import org.opengroup.osdu.core.common.model.indexer.RecordReindexRequest; import org.opengroup.osdu.indexer.service.ReindexService; import org.springframework.http.ResponseEntity; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/auth/AuthorizationServiceEntitlements.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/auth/AuthorizationServiceEntitlements.java deleted file mode 100644 index 45dc213c4a6a35d7a605452b9a9436eced189ee6..0000000000000000000000000000000000000000 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/auth/AuthorizationServiceEntitlements.java +++ /dev/null @@ -1,108 +0,0 @@ -// Copyright 2017-2019, Schlumberger -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.opengroup.osdu.indexer.auth; - -import org.opengroup.osdu.core.common.model.core.DpsHeaders; -import org.opengroup.osdu.core.common.model.core.entitlements.EntitlementsException; -import org.opengroup.osdu.core.common.model.core.entitlements.GroupInfo; -import org.opengroup.osdu.core.common.model.core.entitlements.Groups; -import org.opengroup.osdu.core.common.model.coreis.AppException; -import org.opengroup.osdu.core.common.model.coreis.AuthorizationResponse; -import org.opengroup.osdu.core.common.service.core.HttpResponse; -import org.opengroup.osdu.core.common.service.core.entitlements.IEntitlementsFactory; -import org.opengroup.osdu.core.common.service.core.entitlements.IEntitlementsService; -import org.opengroup.osdu.core.common.service.coreis.HeadersUtil; -import org.opengroup.osdu.core.common.service.coreis.JaxRsDpsLog; -import org.opengroup.osdu.core.common.spi.coreis.AuthorizationService; -import org.springframework.context.annotation.Lazy; -import org.springframework.stereotype.Service; -import org.springframework.web.context.annotation.RequestScope; - -import javax.inject.Inject; -import java.util.ArrayList; -import java.util.List; -import java.util.stream.Collectors; - -@Service -@RequestScope -public class AuthorizationServiceEntitlements implements AuthorizationService { - - private static final String TENANT_GROUP_FORMAT = "@%s"; - - @Inject - private IEntitlementsFactory factory; - @Inject - @Lazy - private JaxRsDpsLog jaxRsDpsLog; - - @Override - public AuthorizationResponse authorizeAny(DpsHeaders headers, String... roles) { - AuthorizationResponse authorizationResponse = null; - IEntitlementsService service = factory.create(headers); - try { - authorizationResponse = authorizeAny(headers, service.getGroups(), roles); - } catch (EntitlementsException e) { - handleEntitlementsException(e, headers); - } - return authorizationResponse; - } - - @Override - public AuthorizationResponse authorizeAny(String tenantName, DpsHeaders headers, String... roles) { - IEntitlementsService service = factory.create(headers); - AuthorizationResponse authorizationResponse = null; - try { - Groups groups = service.getGroups(); - List<GroupInfo> allGroups = new ArrayList<>(groups.getGroups()); - groups.setGroups(groups.getGroups().stream().filter(groupInfo -> groupInfo.getEmail() - .contains(String.format(TENANT_GROUP_FORMAT, tenantName))).collect(Collectors.toList())); - - authorizationResponse = authorizeAny(headers, groups, roles); - groups.setGroups(allGroups); - } catch (EntitlementsException e) { - handleEntitlementsException(e, headers); - } - return authorizationResponse; - } - - private void handleEntitlementsException(EntitlementsException e, DpsHeaders headers) { - HttpResponse response = e.getHttpResponse(); - throw new AppException(response.getResponseCode(), "Access denied", "The user is not authorized to perform this action", HeadersUtil.toLogMsg(headers, null), e); - } - - private AuthorizationResponse authorizeAny(DpsHeaders headers, Groups groups, String... roles) { - String userEmail = null; - List<String> logMessages = new ArrayList<>(); - Long curTimeStamp = System.currentTimeMillis(); - Long latency = System.currentTimeMillis() - curTimeStamp; - - logMessages.add(String.format("entitlements-api latency: %s", latency)); - logMessages.add(String.format("groups: %s", getEmailFromGroups(groups))); - if (groups != null) { - userEmail = groups.getMemberEmail(); - if (groups.any(roles)) { - return AuthorizationResponse.builder().user(userEmail).groups(groups).build(); - } - } - jaxRsDpsLog.info(String.join(" | ", logMessages)); - jaxRsDpsLog.info(HeadersUtil.toLogMsg(headers, userEmail)); - throw AppException.createUnauthorized("required search service roles are missing for user"); - } - - private String getEmailFromGroups(Groups groups) { - if (groups == null) return ""; - return groups.getGroups().stream().map(GroupInfo::getEmail).collect(Collectors.joining(" | ")); - } -} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/logging/AuditEvents.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/logging/AuditEvents.java new file mode 100644 index 0000000000000000000000000000000000000000..bfc441ac9850b3cdb5b2e9b8217d5560920fd487 --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/logging/AuditEvents.java @@ -0,0 +1,218 @@ +// Copyright 2017-2019, Schlumberger +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.opengroup.osdu.indexer.logging; + +import com.google.common.base.Strings; +import org.opengroup.osdu.core.common.logging.audit.AuditAction; +import org.opengroup.osdu.core.common.logging.audit.AuditPayload; +import org.opengroup.osdu.core.common.logging.audit.AuditStatus; + +import java.util.List; + +public class AuditEvents { + + private static final String INDEX_CREATE_RECORD_ACTION_ID = "IN001"; + private static final String INDEX_CREATE_RECORDS_SUCCESS = "Successfully created record in index"; + private static final String INDEX_CREATE_RECORDS_FAILURE = "Failed creating record in index"; + + private static final String INDEX_UPDATE_RECORD_ACTION_ID = "IN002"; + private static final String INDEX_UPDATE_RECORDS_SUCCESS = "Successfully updated record in index"; + private static final String INDEX_UPDATE_RECORDS_FAILURE = "Failed updating record in index"; + + private static final String INDEX_DELETE_RECORD_ACTION_ID = "IN003"; + private static final String INDEX_DELETE_RECORDS_SUCCESS = "Successfully deleted record in index"; + private static final String INDEX_DELETE_RECORDS_FAILURE = "Failed deleting record in index"; + + private static final String INDEX_PURGE_RECORD_ACTION_ID = "IN004"; + + private static final String REINDEX_KIND_ACTION_ID = "IN007"; + private static final String REINDEX_KIND_OPERATION = "Reindex kind"; + + private static final String COPY_INDEX_ACTION_ID = "IN008"; + private static final String COPY_INDEX_OPERATION = "Copy index"; + + private static final String GET_TASK_STATUS_ACTION_ID = "IN009"; + private static final String GET_TASK_STATUS_OPERATION = "Get task status"; + + private static final String RUN_JOB_ACTION_ID = "IN010"; + private static final String RUN_JOB_MESSAGE_SUCCESS = "Index clean-up status job run success"; + + private static final String INDEX_MAPPING_UPDATE_ACTION_ID = "IN0011"; + private static final String INDEX_MAPPING_UPDATE_SUCCESS = "Successfully updated index mapping"; + private static final String INDEX_MAPPING_UPDATE_FAILURE = "Failed updating index mapping"; + + private final String user; + + public AuditEvents(String user) { + if (Strings.isNullOrEmpty(user)) { + throw new IllegalArgumentException("User not provided for audit events."); + } + this.user = user; + } + + public AuditPayload getIndexCreateRecordSuccessEvent(List<String> resources) { + return AuditPayload.builder() + .action(AuditAction.CREATE) + .status(AuditStatus.SUCCESS) + .actionId(INDEX_CREATE_RECORD_ACTION_ID) + .message(INDEX_CREATE_RECORDS_SUCCESS) + .resources(resources) + .user(this.user) + .build(); + } + + public AuditPayload getIndexCreateRecordFailEvent(List<String> resources) { + return AuditPayload.builder() + .action(AuditAction.CREATE) + .status(AuditStatus.FAILURE) + .actionId(INDEX_CREATE_RECORD_ACTION_ID) + .message(INDEX_CREATE_RECORDS_FAILURE) + .resources(resources) + .user(this.user) + .build(); + } + + public AuditPayload getIndexUpdateRecordSuccessEvent(List<String> resources) { + return AuditPayload.builder() + .action(AuditAction.UPDATE) + .status(AuditStatus.SUCCESS) + .actionId(INDEX_UPDATE_RECORD_ACTION_ID) + .message(INDEX_UPDATE_RECORDS_SUCCESS) + .resources(resources) + .user(this.user) + .build(); + } + + public AuditPayload getIndexUpdateRecordFailEvent(List<String> resources) { + return AuditPayload.builder() + .action(AuditAction.UPDATE) + .status(AuditStatus.FAILURE) + .actionId(INDEX_UPDATE_RECORD_ACTION_ID) + .message(INDEX_UPDATE_RECORDS_FAILURE) + .resources(resources) + .user(this.user) + .build(); + } + + public AuditPayload getIndexDeleteRecordSuccessEvent(List<String> resources) { + return AuditPayload.builder() + .action(AuditAction.DELETE) + .status(AuditStatus.SUCCESS) + .actionId(INDEX_DELETE_RECORD_ACTION_ID) + .message(INDEX_DELETE_RECORDS_SUCCESS) + .resources(resources) + .user(this.user) + .build(); + } + + public AuditPayload getIndexDeleteRecordFailEvent(List<String> resources) { + return AuditPayload.builder() + .action(AuditAction.DELETE) + .status(AuditStatus.FAILURE) + .actionId(INDEX_DELETE_RECORD_ACTION_ID) + .message(INDEX_DELETE_RECORDS_FAILURE) + .resources(resources) + .user(this.user) + .build(); + } + + public AuditPayload getIndexPurgeRecordSuccessEvent(List<String> resources) { + return AuditPayload.builder() + .action(AuditAction.DELETE) + .status(AuditStatus.SUCCESS) + .actionId(INDEX_PURGE_RECORD_ACTION_ID) + .message(INDEX_DELETE_RECORDS_SUCCESS) + .resources(resources) + .user(this.user) + .build(); + } + + public AuditPayload getIndexPurgeRecordFailEvent(List<String> resources) { + return AuditPayload.builder() + .action(AuditAction.DELETE) + .status(AuditStatus.FAILURE) + .actionId(INDEX_PURGE_RECORD_ACTION_ID) + .message(INDEX_DELETE_RECORDS_FAILURE) + .resources(resources) + .user(this.user) + .build(); + } + + public AuditPayload getReindexEvent(List<String> resources) { + return AuditPayload.builder() + .action(AuditAction.CREATE) + .status(AuditStatus.SUCCESS) + .actionId(REINDEX_KIND_ACTION_ID) + .message(REINDEX_KIND_OPERATION) + .resources(resources) + .user(this.user) + .build(); + } + + public AuditPayload getCopyIndexEvent(List<String> resources) { + return AuditPayload.builder() + .action(AuditAction.CREATE) + .status(AuditStatus.SUCCESS) + .actionId(COPY_INDEX_ACTION_ID) + .message(COPY_INDEX_OPERATION) + .resources(resources) + .user(this.user) + .build(); + } + + public AuditPayload getTaskStatusEvent(List<String> resources) { + return AuditPayload.builder() + .action(AuditAction.READ) + .status(AuditStatus.SUCCESS) + .actionId(GET_TASK_STATUS_ACTION_ID) + .message(GET_TASK_STATUS_OPERATION) + .resources(resources) + .user(this.user) + .build(); + } + + public AuditPayload getIndexCleanUpJobRunEvent(List<String> resources) { + return AuditPayload.builder() + .action(AuditAction.JOB_RUN) + .status(AuditStatus.SUCCESS) + .user(this.user) + .actionId(RUN_JOB_ACTION_ID) + .message(RUN_JOB_MESSAGE_SUCCESS) + .resources(resources) + .build(); + } + + public AuditPayload getIndexMappingUpdateEvent(List<String> resources, boolean isSuccess) { + if (isSuccess) { + return AuditPayload.builder() + .action(AuditAction.UPDATE) + .status(AuditStatus.SUCCESS) + .actionId(INDEX_MAPPING_UPDATE_ACTION_ID) + .message(INDEX_MAPPING_UPDATE_SUCCESS) + .resources(resources) + .user(this.user) + .build(); + } else { + return AuditPayload.builder() + .action(AuditAction.UPDATE) + .status(AuditStatus.FAILURE) + .actionId(INDEX_MAPPING_UPDATE_ACTION_ID) + .message(INDEX_MAPPING_UPDATE_FAILURE) + .resources(resources) + .user(this.user) + .build(); + } + } +} \ No newline at end of file diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/logging/AuditLogger.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/logging/AuditLogger.java new file mode 100644 index 0000000000000000000000000000000000000000..aaf148f82d20bbc05b674225cafe68a881dc4a52 --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/logging/AuditLogger.java @@ -0,0 +1,102 @@ +// Copyright 2017-2019, Schlumberger +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.opengroup.osdu.indexer.logging; + +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.logging.audit.AuditPayload; +import org.springframework.stereotype.Component; +import org.springframework.web.context.annotation.RequestScope; + +import javax.inject.Inject; +import java.util.List; + +@Component +@RequestScope +public class AuditLogger { + + @Inject + private JaxRsDpsLog logger; + @Inject + private DpsHeaders headers; + + private AuditEvents events = null; + + private AuditEvents getAuditEvents() { + if (this.events == null) { + this.events = new AuditEvents(this.headers.getUserEmail()); + } + return this.events; + } + + public void indexCreateRecordSuccess(List<String> resources) { + this.writeLog(this.getAuditEvents().getIndexCreateRecordSuccessEvent(resources)); + } + + public void indexCreateRecordFail(List<String> resources) { + this.writeLog(this.getAuditEvents().getIndexCreateRecordFailEvent(resources)); + } + + public void indexUpdateRecordSuccess(List<String> resources) { + this.writeLog(this.getAuditEvents().getIndexUpdateRecordSuccessEvent(resources)); + } + + public void indexUpdateRecordFail(List<String> resources) { + this.writeLog(this.getAuditEvents().getIndexUpdateRecordFailEvent(resources)); + } + + public void indexDeleteRecordSuccess(List<String> resources) { + this.writeLog(this.getAuditEvents().getIndexDeleteRecordSuccessEvent(resources)); + } + + public void indexDeleteRecordFail(List<String> resources) { + this.writeLog(this.getAuditEvents().getIndexDeleteRecordFailEvent(resources)); + } + + public void indexPurgeRecordSuccess(List<String> resources) { + this.writeLog(this.getAuditEvents().getIndexPurgeRecordSuccessEvent(resources)); + } + + public void indexPurgeRecordFail(List<String> resources) { + this.writeLog(this.getAuditEvents().getIndexPurgeRecordFailEvent(resources)); + } + + public void getReindex(List<String> resources) { + this.writeLog(this.getAuditEvents().getReindexEvent(resources)); + } + + public void copyIndex(List<String> resources) { + this.writeLog(this.getAuditEvents().getCopyIndexEvent(resources)); + } + + public void getTaskStatus(List<String> resources) { + this.writeLog(this.getAuditEvents().getTaskStatusEvent(resources)); + } + + public void getIndexCleanUpJobRun(List<String> resources) { + this.writeLog(this.getAuditEvents().getIndexCleanUpJobRunEvent(resources)); + } + + public void indexMappingUpdateSuccess(List<String> resources) { + this.writeLog(this.getAuditEvents().getIndexMappingUpdateEvent(resources,true)); + } + public void indexMappingUpdateFail(List<String> resources) { + this.writeLog(this.getAuditEvents().getIndexMappingUpdateEvent(resources,false)); + } + + private void writeLog(AuditPayload log) { + this.logger.audit(log); + } +} \ No newline at end of file diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/middleware/AuthorizationFilter.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/middleware/AuthorizationFilter.java index 2cdf3fbd6dc6b00705093bf0091bb44d2f2203ac..54ad9405496b8fee1163d5285e8c12c1b56bdb3a 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/middleware/AuthorizationFilter.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/middleware/AuthorizationFilter.java @@ -1,10 +1,9 @@ package org.opengroup.osdu.indexer.middleware; -import com.google.common.base.Strings; import lombok.extern.java.Log; -import org.opengroup.osdu.core.common.model.core.DpsHeaders; -import org.opengroup.osdu.core.common.model.coreis.AuthorizationResponse; -import org.opengroup.osdu.core.common.spi.coreis.AuthorizationService; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.entitlements.AuthorizationResponse; +import org.opengroup.osdu.core.common.provider.interfaces.IAuthorizationService; import org.springframework.stereotype.Component; import org.springframework.web.context.annotation.RequestScope; import javax.inject.Inject; @@ -15,7 +14,7 @@ import javax.inject.Inject; public class AuthorizationFilter { @Inject - private AuthorizationService authorizationService; + private IAuthorizationService authorizationService; private DpsHeaders headers; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/provider/interfaces/IPublisher.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/provider/interfaces/IPublisher.java new file mode 100644 index 0000000000000000000000000000000000000000..ec24e6562c71efa07f83e384d64d5b346cc7c5f3 --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/provider/interfaces/IPublisher.java @@ -0,0 +1,9 @@ +package org.opengroup.osdu.indexer.provider.interfaces; + +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.indexer.JobStatus; + +public interface IPublisher { + + public void publishStatusChangedTagsToTopic(DpsHeaders headers, JobStatus indexerBatchStatus) throws Exception; +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/provider/interfaces/ISchemaCache.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/provider/interfaces/ISchemaCache.java new file mode 100644 index 0000000000000000000000000000000000000000..27004e63380bd049725a40d9bb34b61778dbe657 --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/provider/interfaces/ISchemaCache.java @@ -0,0 +1,6 @@ +package org.opengroup.osdu.indexer.provider.interfaces; + +import org.opengroup.osdu.core.common.cache.ICache; + +public interface ISchemaCache <String,V> extends ICache<String, V> { +} diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/AttributeParsingServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/AttributeParsingServiceImpl.java index f737ad6beda38488059342def67382cff48315f6..4ed8c46cd7a449316be62014aa6ab3b1f6e0a304 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/AttributeParsingServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/AttributeParsingServiceImpl.java @@ -22,7 +22,7 @@ import com.google.gson.reflect.TypeToken; import org.apache.http.HttpStatus; import org.opengroup.osdu.core.common.model.indexer.IndexingStatus; import org.opengroup.osdu.core.common.model.indexer.JobStatus; -import org.opengroup.osdu.core.common.model.core.Constants; +import org.opengroup.osdu.core.common.Constants; import org.opengroup.osdu.core.common.model.indexer.ElasticType; import org.opengroup.osdu.core.common.model.indexer.IndexSchema; import org.opengroup.osdu.indexer.util.parser.DateTimeParser; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/CronServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/CronServiceImpl.java index 7478b7b6c0bd82ff8359f5559095379e5c099416..03deefe99b233578e60634789ba4258444a6c17c 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/CronServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/CronServiceImpl.java @@ -18,12 +18,12 @@ package org.opengroup.osdu.indexer.service; import org.elasticsearch.client.ResponseException; import org.elasticsearch.client.RestHighLevelClient; -import org.opengroup.osdu.core.common.model.coreis.AppException; -import org.opengroup.osdu.core.common.model.coreis.IndexInfo; -import org.opengroup.osdu.core.common.service.coreis.JaxRsDpsLog; -import org.opengroup.osdu.core.common.spi.coreis.IRequestInfo; -import org.opengroup.osdu.core.common.service.coreis.IndicesService; -import org.opengroup.osdu.is.core.util.ElasticClientHandler; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.model.search.IndexInfo; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; +import org.opengroup.osdu.core.common.search.IndicesService; +import org.opengroup.osdu.indexer.util.ElasticClientHandler; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/ElasticSettingServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/ElasticSettingServiceImpl.java index 99329dc643ba84c4a17d338b8c3fd84cad4be94a..aff7fa2c76761dc537f165ac14c7399b18cff758 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/ElasticSettingServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/ElasticSettingServiceImpl.java @@ -15,25 +15,25 @@ package org.opengroup.osdu.indexer.service; import org.apache.http.HttpStatus; -import org.opengroup.osdu.core.common.model.core.ClusterSettings; -import org.opengroup.osdu.core.common.model.core.TenantInfo; -import org.opengroup.osdu.core.common.model.coreis.AppException; -import org.opengroup.osdu.core.common.service.coreis.JaxRsDpsLog; -import org.opengroup.osdu.core.common.spi.coreis.ElasticRepository; -import org.opengroup.osdu.core.common.spi.coreis.IElasticCredentialsCache; -import org.opengroup.osdu.core.common.service.coreis.TenantInfoService; -import org.opengroup.osdu.is.core.service.ElasticSettingService; +import org.opengroup.osdu.core.common.model.search.ClusterSettings; +import org.opengroup.osdu.core.common.model.tenant.TenantInfo; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.provider.interfaces.IElasticRepository; +import org.opengroup.osdu.core.common.provider.interfaces.IElasticCredentialsCache; +import org.opengroup.osdu.core.common.model.indexer.IElasticSettingService; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import javax.inject.Inject; @Service -public class ElasticSettingServiceImpl implements ElasticSettingService { +public class ElasticSettingServiceImpl implements IElasticSettingService { @Inject - private TenantInfoService tenantInfoServiceProvider; + private TenantInfo tenantInfo; + @Inject - private ElasticRepository elasticRepository; + private IElasticRepository elasticRepository; @Inject private IElasticCredentialsCache elasticCredentialCache; @Inject @@ -45,8 +45,6 @@ public class ElasticSettingServiceImpl implements ElasticSettingService { @Override public ClusterSettings getElasticClusterInformation() { - TenantInfo tenantInfo = this.tenantInfoServiceProvider.getTenantInfo(); - String cacheKey = String.format("%s-%s", GAE_SERVICE, tenantInfo.getName()); ClusterSettings clusterInfo = (ClusterSettings) this.elasticCredentialCache.get(cacheKey); if (clusterInfo != null) { diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/GeometryConversionService.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/GeometryConversionService.java index e032c66b3c59aa08c0fa2c104dab1871b1e70e93..83aadeadf483f71aca465ed4754713a242588061 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/GeometryConversionService.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/GeometryConversionService.java @@ -15,7 +15,7 @@ package org.opengroup.osdu.indexer.service; import com.google.gson.internal.LinkedTreeMap; -import org.opengroup.osdu.core.common.model.core.Constants; +import org.opengroup.osdu.core.common.Constants; import org.springframework.stereotype.Service; import org.springframework.web.context.annotation.RequestScope; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexCopyService.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexCopyService.java index 465c28aed3f5262f8719eb1f7a287a8f803a8a7d..88e20720f510b3f7d0f31c31707b2501ddd1ba5c 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexCopyService.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexCopyService.java @@ -15,7 +15,7 @@ package org.opengroup.osdu.indexer.service; -import org.opengroup.osdu.core.common.model.coreis.AppException; +import org.opengroup.osdu.core.common.model.http.AppException; import java.io.IOException; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexCopyServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexCopyServiceImpl.java index 966c796a755b9543dbbb26b30843ae48b03b22bb..1a02c456ded766a73da95636ed4e7ae8e6718768 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexCopyServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexCopyServiceImpl.java @@ -25,15 +25,16 @@ import org.apache.http.util.EntityUtils; import org.elasticsearch.client.Request; import org.elasticsearch.client.Response; import org.elasticsearch.client.RestHighLevelClient; -import org.opengroup.osdu.core.common.model.core.ClusterSettings; -import org.opengroup.osdu.core.common.model.core.DpsHeaders; -import org.opengroup.osdu.core.common.model.core.TenantInfo; -import org.opengroup.osdu.core.common.model.coreis.AppException; -import org.opengroup.osdu.core.common.service.coreis.*; -import org.opengroup.osdu.core.common.model.indexer.AuditLogger; -import org.opengroup.osdu.core.common.spi.coreis.IHeadersInfo; -import org.opengroup.osdu.is.core.service.ElasticSettingService; -import org.opengroup.osdu.is.core.util.ElasticClientHandler; +import org.opengroup.osdu.core.common.model.search.ClusterSettings; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.tenant.TenantInfo; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; +import org.opengroup.osdu.core.common.search.IndicesService; +import org.opengroup.osdu.core.common.search.Preconditions; +import org.opengroup.osdu.indexer.logging.AuditLogger; +import org.opengroup.osdu.core.common.model.indexer.IElasticSettingService; +import org.opengroup.osdu.indexer.util.ElasticClientHandler; import org.springframework.stereotype.Service; import javax.inject.Inject; @@ -52,11 +53,11 @@ public class IndexCopyServiceImpl implements IndexCopyService { @Inject private IndicesService indicesService; @Inject - private ElasticSettingService elasticSettingService; + private IElasticSettingService elasticSettingService; @Inject private IndexerMappingService mappingService; @Inject - private IHeadersInfo headersInfo; + private DpsHeaders headersInfo; @Inject private AuditLogger auditLogger; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaService.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaService.java index 02257801e8d23649c55ed04c38a317be5a7761e9..e0a7f7a649ec2788162fd43c7cb800e021e07983 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaService.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaService.java @@ -14,7 +14,7 @@ package org.opengroup.osdu.indexer.service; -import org.opengroup.osdu.core.common.model.coreis.AppException; +import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.indexer.IndexSchema; import org.opengroup.osdu.core.common.model.indexer.OperationType; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java index 12a84303f7586f838db9a0751c5dc5c39b09579b..6148991bd175232a10733fbe1cd0e24daf70b29e 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexSchemaServiceImpl.java @@ -18,19 +18,20 @@ import com.google.common.base.Strings; import com.google.gson.Gson; import org.elasticsearch.ElasticsearchStatusException; import org.elasticsearch.client.RestHighLevelClient; -import org.opengroup.osdu.core.common.model.coreis.AppException; -import org.opengroup.osdu.is.core.util.ElasticClientHandler; -import org.opengroup.osdu.core.common.service.coreis.ElasticIndexNameResolver; -import org.opengroup.osdu.core.common.service.coreis.IndicesService; -import org.opengroup.osdu.core.common.service.coreis.JaxRsDpsLog; +import org.opengroup.osdu.core.common.model.storage.SchemaItem; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.indexer.util.ElasticClientHandler; +import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; +import org.opengroup.osdu.core.common.search.IndicesService; import org.opengroup.osdu.core.common.model.indexer.IndexSchema; import org.opengroup.osdu.core.common.model.indexer.OperationType; -import org.opengroup.osdu.core.common.model.indexer.Schema; +import org.opengroup.osdu.core.common.model.storage.Schema; import org.opengroup.osdu.core.common.model.indexer.StorageType; -import org.opengroup.osdu.core.common.spi.indexer.ISchemaCache; +import org.opengroup.osdu.indexer.provider.interfaces.ISchemaCache; import org.opengroup.osdu.indexer.util.TypeMapper; -import org.opengroup.osdu.core.common.model.coreis.RequestStatus; -import org.opengroup.osdu.core.common.model.coreis.RecordMetaAttribute; +import org.opengroup.osdu.core.common.model.http.RequestStatus; +import org.opengroup.osdu.core.common.model.search.RecordMetaAttribute; import org.apache.http.HttpStatus; import org.springframework.stereotype.Service; @@ -171,14 +172,14 @@ public class IndexSchemaServiceImpl implements IndexSchemaService { Map<String, String> data = new HashMap<>(); Map<String, Object> meta = new HashMap<>(); - if (schemaObj.getSchema() != null && !schemaObj.getSchema().isEmpty()) { - for (Schema.Mapping schemaInfo : schemaObj.getSchema()) { - String dataType = schemaInfo.getKind(); + if (schemaObj.getSchema() != null && schemaObj.getSchema().length > 0) { + for (SchemaItem schemaItem : schemaObj.getSchema()) { + String dataType = schemaItem.getKind(); String elasticDataType = TypeMapper.getIndexerType(dataType); if (elasticDataType == null) { elasticDataType = TypeMapper.getIndexerType(StorageType.STRING.getValue()); } - data.put(schemaInfo.getPath(), elasticDataType); + data.put(schemaItem.getPath(), elasticDataType); } } diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerMappingService.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerMappingService.java index ad1b3d4f2a3dcaf52228412c6117ac5d28682563..a411ffa08401af8239697c126d0972197d722e59 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerMappingService.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerMappingService.java @@ -15,14 +15,14 @@ package org.opengroup.osdu.indexer.service; import org.elasticsearch.client.RestHighLevelClient; -import org.opengroup.osdu.core.common.service.coreis.MappingService; +import org.opengroup.osdu.core.common.search.IMappingService; import org.opengroup.osdu.core.common.model.indexer.IndexSchema; import java.io.IOException; import java.util.Map; import java.util.Set; -public interface IndexerMappingService extends MappingService { +public interface IndexerMappingService extends IMappingService { String createMapping(RestHighLevelClient client, IndexSchema schema, String index, boolean merge) throws IOException; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceImpl.java index 65f5cca91a44bf765272f092af66b195f7f09e87..33d34bac44b4a428df4f10d62a5962939f7fbc5f 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceImpl.java @@ -37,15 +37,14 @@ import org.elasticsearch.index.reindex.BulkByScrollResponse; import org.elasticsearch.index.reindex.UpdateByQueryRequest; import com.google.gson.Gson; -import org.opengroup.osdu.core.common.model.core.Constants; -import org.opengroup.osdu.core.common.model.coreis.AppException; -import org.opengroup.osdu.core.common.model.coreis.RecordMetaAttribute; -import org.opengroup.osdu.core.common.service.coreis.JaxRsDpsLog; -import org.opengroup.osdu.core.common.service.coreis.Preconditions; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.Constants; +import org.opengroup.osdu.core.common.model.search.RecordMetaAttribute; +import org.opengroup.osdu.core.common.search.Preconditions; import org.opengroup.osdu.core.common.model.indexer.IndexSchema; import org.opengroup.osdu.core.common.model.indexer.Records; -import org.opengroup.osdu.is.core.service.MappingServiceImpl; -import org.opengroup.osdu.is.core.util.ElasticClientHandler; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.indexer.util.ElasticClientHandler; import org.springframework.stereotype.Service; import javax.inject.Inject; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerService.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerService.java index 88bba90c9e1e72eb3b22f37c12d54a23ba2919c1..4ae323c7656efb92132a5c64c69564f867ed183c 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerService.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerService.java @@ -18,7 +18,7 @@ import java.util.List; import org.opengroup.osdu.core.common.model.indexer.JobStatus; import org.opengroup.osdu.core.common.model.indexer.RecordInfo; -import org.opengroup.osdu.core.common.model.coreis.RecordChangedMessages; +import org.opengroup.osdu.core.common.model.search.RecordChangedMessages; public interface IndexerService { diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerServiceImpl.java index 953aaa9e987b94149805fd169c9d398b2ac14cb0..ac64f0db78300eef8952b9744039770567d89402 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndexerServiceImpl.java @@ -30,20 +30,23 @@ import org.elasticsearch.client.RestHighLevelClient; import org.elasticsearch.common.unit.TimeValue; import org.elasticsearch.common.xcontent.XContentType; import org.elasticsearch.rest.RestStatus; -import org.opengroup.osdu.core.common.model.core.Constants; -import org.opengroup.osdu.core.common.model.core.DpsHeaders; -import org.opengroup.osdu.core.common.model.coreis.AppException; +import org.opengroup.osdu.core.common.model.entitlements.Acl; +import org.opengroup.osdu.core.common.Constants; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.indexer.*; -import org.opengroup.osdu.core.common.service.coreis.JaxRsDpsLog; -import org.opengroup.osdu.core.common.spi.indexer.IPublisher; +import org.opengroup.osdu.core.common.model.storage.ConversionStatus; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.indexer.provider.interfaces.IPublisher; +import org.opengroup.osdu.indexer.logging.AuditLogger; import org.opengroup.osdu.indexer.util.IndexerQueueTaskBuilder; -import org.opengroup.osdu.core.common.model.coreis.RequestStatus; -import org.opengroup.osdu.core.common.model.coreis.RecordChangedMessages; -import org.opengroup.osdu.core.common.model.coreis.RecordMetaAttribute; -import org.opengroup.osdu.core.common.spi.coreis.IRequestInfo; -import org.opengroup.osdu.core.common.service.coreis.IndicesService; -import org.opengroup.osdu.is.core.util.ElasticClientHandler; -import org.opengroup.osdu.core.common.service.coreis.ElasticIndexNameResolver; +import org.opengroup.osdu.core.common.model.http.RequestStatus; +import org.opengroup.osdu.core.common.model.search.RecordChangedMessages; +import org.opengroup.osdu.core.common.model.search.RecordMetaAttribute; +import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; +import org.opengroup.osdu.core.common.search.IndicesService; +import org.opengroup.osdu.indexer.util.ElasticClientHandler; +import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.beanutils.NestedNullException; import org.springframework.stereotype.Service; @@ -498,7 +501,7 @@ public class IndexerServiceImpl implements IndexerService { indexerPayload.put(RecordMetaAttribute.TYPE.getValue(), record.getType()); indexerPayload.put(RecordMetaAttribute.VERSION.getValue(), record.getVersion()); indexerPayload.put(RecordMetaAttribute.ACL.getValue(), record.getAcl()); - indexerPayload.put(RecordMetaAttribute.X_ACL.getValue(), StorageAcl.flattenAcl(record.getAcl())); + indexerPayload.put(RecordMetaAttribute.X_ACL.getValue(), Acl.flattenAcl(record.getAcl())); indexerPayload.put(RecordMetaAttribute.LEGAL.getValue(), record.getLegal()); indexerPayload.put(RecordMetaAttribute.INDEX_STATUS.getValue(), record.getIndexProgress()); if (record.getAncestry() != null) { diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndicesServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndicesServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..22374fc32075455e31df5dd9e4b912f34d9d3292 --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/IndicesServiceImpl.java @@ -0,0 +1,230 @@ +// Copyright 2017-2019, Schlumberger +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.opengroup.osdu.indexer.service; + +import com.google.common.base.Strings; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; +import com.lambdaworks.redis.RedisException; +import org.apache.http.HttpStatus; +import org.apache.http.util.EntityUtils; +import org.elasticsearch.ElasticsearchException; +import org.elasticsearch.ElasticsearchStatusException; +import org.elasticsearch.action.admin.indices.create.CreateIndexRequest; +import org.elasticsearch.action.admin.indices.create.CreateIndexResponse; +import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; +import org.elasticsearch.action.admin.indices.get.GetIndexRequest; +import org.elasticsearch.action.support.master.AcknowledgedResponse; +import org.elasticsearch.client.Request; +import org.elasticsearch.client.RequestOptions; +import org.elasticsearch.client.Response; +import org.elasticsearch.client.RestHighLevelClient; +import org.elasticsearch.common.settings.Settings; +import org.elasticsearch.common.unit.TimeValue; +import org.elasticsearch.common.xcontent.XContentType; +import org.elasticsearch.rest.RestStatus; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.search.IndicesService; +import org.opengroup.osdu.core.common.provider.interfaces.IIndexCache; +import org.opengroup.osdu.core.common.model.search.IndexInfo; +import org.opengroup.osdu.indexer.util.ElasticClientHandler; +import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; +import org.opengroup.osdu.core.common.search.Preconditions; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.web.context.annotation.RequestScope; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +@Service +@RequestScope +public class IndicesServiceImpl implements IndicesService { + + @Autowired + private ElasticClientHandler elasticClientHandler; + @Autowired + private ElasticIndexNameResolver elasticIndexNameResolver; + @Autowired + private IIndexCache indicesExistCache; + @Autowired + private JaxRsDpsLog log; + + private TimeValue REQUEST_TIMEOUT = TimeValue.timeValueMinutes(1); + + private static final Settings DEFAULT_INDEX_SETTINGS = Settings.builder() + .put("index.refresh_interval", "30s") + .put("index.number_of_replicas", "1") + .put("index.number_of_shards", "1").build(); + + /** + * Create a new index in Elasticsearch + * + * @param client Elasticsearch client + * @param index Index name + * @param settings Settings if any, null if no specific settings + * @param type type in index, required if type is specified + * @param mapping mapping if any, must be a json map + * @throws ElasticsearchStatusException, IOException if it cannot create index + */ + public boolean createIndex(RestHighLevelClient client, String index, Settings settings, String type, Map<String, Object> mapping) throws ElasticsearchStatusException, IOException { + + Preconditions.checkArgument(client, Objects::nonNull, "client cannot be null"); + Preconditions.checkArgument(index, Objects::nonNull, "index cannot be null"); + + try { + CreateIndexRequest request = new CreateIndexRequest(index); + request.settings(settings != null ? settings : DEFAULT_INDEX_SETTINGS); + if (mapping != null) { + String mappingJsonString = new Gson().toJson(mapping, Map.class); + request.mapping(type, mappingJsonString, XContentType.JSON); + } + request.timeout(REQUEST_TIMEOUT); + CreateIndexResponse response = client.indices().create(request, RequestOptions.DEFAULT); + + // cache the index status + boolean indexStatus = response.isAcknowledged() && response.isShardsAcknowledged(); + if (indexStatus) this.indicesExistCache.put(index, true); + + return indexStatus; + } catch (ElasticsearchStatusException e) { + if (e.status() == RestStatus.BAD_REQUEST && (e.getMessage().contains("resource_already_exists_exception"))) { + log.info("Index already exists. Ignoring error..."); + // cache the index status + this.indicesExistCache.put(index, true); + return true; + } + throw e; + } + } + + /** + * Check if an index already exists + * + * @param index Index name + * @return index details if index already exists + * @throws IOException if request cannot be processed + */ + public boolean isIndexExist(RestHighLevelClient client, String index) throws IOException { + try { + try { + Boolean isIndexExist = (Boolean) this.indicesExistCache.get(index); + if (isIndexExist != null && isIndexExist) return true; + } catch (RedisException ex) { + //In case the format of cache changes then clean the cache + this.indicesExistCache.delete(index); + } + GetIndexRequest request = new GetIndexRequest(); + request.indices(index); + boolean exists = client.indices().exists(request, RequestOptions.DEFAULT); + if (exists) this.indicesExistCache.put(index, true); + return exists; + } catch (ElasticsearchException exception) { + if (exception.status() == RestStatus.NOT_FOUND) return false; + throw new AppException( + exception.status().getStatus(), + exception.getMessage(), + String.format("Error getting index: %s status", index), + exception); + } + } + + /** + * Deletes index if user has required role: search.admin + * + * @param client Elasticsearch client + * @param index Index name + */ + public boolean deleteIndex(RestHighLevelClient client, String index) throws Exception { + boolean responseStatus = removeIndexInElasticsearch(client, index); + if (responseStatus) { + this.indicesExistCache.delete(index); + } + return responseStatus; + } + + /** + * Deletes index if user has required role: search.admin + * + * @param index Index name + */ + public boolean deleteIndex(String index) throws Exception { + try (RestHighLevelClient client = this.elasticClientHandler.createRestClient()) { + return deleteIndex(client, index); + } + } + + /** + * Remove index in Elasticsearch + * + * @param client Elasticsearch client + * @param index Index name + * @throws Exception Throws {@link AppException} if index is not found or elastic cannot delete the index + */ + private boolean removeIndexInElasticsearch(RestHighLevelClient client, String index) throws Exception { + + Preconditions.checkArgument(client, Objects::nonNull, "client cannot be null"); + Preconditions.checkArgument(index, Objects::nonNull, "index cannot be null"); + + try { + DeleteIndexRequest request = new DeleteIndexRequest(index); + request.timeout(REQUEST_TIMEOUT); + AcknowledgedResponse response = client.indices().delete(request, RequestOptions.DEFAULT); + if (!response.isAcknowledged()) { + throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Index deletion error", String.format("Could not delete index %s", index)); + } + return true; + } catch (ElasticsearchException exception) { + if (exception.status() == RestStatus.NOT_FOUND) { + throw new AppException(HttpStatus.SC_NOT_FOUND, "Index deletion error", notFoundErrorMessage(index), exception); + } else if (exception.status() == RestStatus.BAD_REQUEST && exception.getMessage().contains("Cannot delete indices that are being snapshotted")) { + throw new AppException(HttpStatus.SC_CONFLICT, "Index deletion error", "Unable to delete the index because it is currently locked. Try again in few minutes.", exception); + } + throw exception; + } + } + + // cron may not have kind but index delete api may + private String notFoundErrorMessage(String index) { + String kind = this.elasticIndexNameResolver.getKindFromIndexName(index); + return Strings.isNullOrEmpty(kind) ? String.format("Index %s not found", index) : String.format("Kind %s not found", kind); + } + + /** + * Remove index in Elasticsearch + * + * @param client Elasticsearch client + * @param indexPattern Index pattern + * @throws IOException Throws {@link IOException} if elastic cannot complete the request + */ + public List<IndexInfo> getIndexInfo(RestHighLevelClient client, String indexPattern) throws IOException { + + Preconditions.checkArgument(client, Objects::nonNull, "client cannot be null"); + + String requestUrl = Strings.isNullOrEmpty(indexPattern) + ? "/_cat/indices/*,-.*?h=index,docs.count,creation.date&s=docs.count:asc&format=json" + : String.format("/_cat/indices/%s?h=index,docs.count,creation.date&format=json", indexPattern); + + Request request = new Request("GET", requestUrl); + Response response = client.getLowLevelClient().performRequest(request); + String str = EntityUtils.toString(response.getEntity()); + final Type typeOf = new TypeToken<List<IndexInfo>>() {}.getType(); + return new Gson().fromJson(str, typeOf); + } +} \ No newline at end of file diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/MappingServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/MappingServiceImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..6b52cc19b4a8e9f56339ce41bebfc79db0aa0c54 --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/MappingServiceImpl.java @@ -0,0 +1,93 @@ +// Copyright 2017-2019, Schlumberger +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.opengroup.osdu.indexer.service; + +import org.apache.http.HttpStatus; +import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; +import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; +import org.elasticsearch.client.RequestOptions; +import org.elasticsearch.client.RestHighLevelClient; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; +import org.opengroup.osdu.core.common.search.IndicesService; +import org.opengroup.osdu.core.common.search.IMappingService; +import org.opengroup.osdu.core.common.search.Preconditions; +import org.opengroup.osdu.indexer.util.ElasticClientHandler; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; +import org.springframework.web.context.annotation.RequestScope; + +import java.io.IOException; +import java.util.Objects; + +@Service +@RequestScope +public class MappingServiceImpl implements IMappingService { + + @Autowired + private IndicesService indicesService; + @Autowired + private ElasticClientHandler elasticClientHandler; + @Autowired + private ElasticIndexNameResolver elasticIndexNameResolver; + +// private TimeValue REQUEST_TIMEOUT = TimeValue.timeValueMinutes(1); + + /* + * Get index schema + * + * @param index Index name + * @param requestHeaders Incoming request headers + * @throws Exception Throws exception if elastic cannot find index. + * */ + @Override + public String getIndexSchema(String index) throws Exception { + + try (RestHighLevelClient client = this.elasticClientHandler.createRestClient()) { + return this.getIndexMapping(client, index); + } + } + + /** + * Gets elastic mapping for index + * + * @param client Elasticsearch client + * @param index Index name + * @return mapping Index mapping + * @throws Exception Throws exception if elastic cannot find index. + */ + public String getIndexMapping(RestHighLevelClient client, String index) throws Exception { + + Preconditions.checkArgument(client, Objects::nonNull, "client cannot be null"); + Preconditions.checkArgument(index, Objects::nonNull, "index cannot be null"); + + // check if index exist + boolean indexExist = indicesService.isIndexExist(client, index); + if (!indexExist) { + throw new AppException(HttpStatus.SC_NOT_FOUND, "Kind not found", String.format("Kind %s not found", this.elasticIndexNameResolver.getKindFromIndexName(index))); + } + + try { + GetMappingsRequest request = new GetMappingsRequest(); + request.indices(index); + // TODO: enable this once server is migrated > v6.6.2 + // request.masterNodeTimeout(REQUEST_TIMEOUT); + GetMappingsResponse response = client.indices().getMapping(request, RequestOptions.DEFAULT); + return response.toString(); + } catch (IOException e) { + throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Unknown error", String.format("Error retrieving mapping for kind %s", this.elasticIndexNameResolver.getKindFromIndexName(index)), e); + } + } +} \ No newline at end of file diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/ReindexServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/ReindexServiceImpl.java index f887b994e1fee5ee0a38d0de0febd1e7f4814231..16a8c0d03d41e2566283c0528adfc87d4001d682 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/ReindexServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/ReindexServiceImpl.java @@ -18,16 +18,16 @@ import com.google.common.base.Strings; import com.google.gson.Gson; import lombok.extern.java.Log; import org.apache.http.HttpStatus; -import org.opengroup.osdu.core.common.model.core.DpsHeaders; -import org.opengroup.osdu.core.common.model.coreis.AppException; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.indexer.OperationType; -import org.opengroup.osdu.core.common.service.coreis.JaxRsDpsLog; import org.opengroup.osdu.core.common.model.indexer.RecordQueryResponse; import org.opengroup.osdu.core.common.model.indexer.RecordReindexRequest; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.indexer.util.IndexerQueueTaskBuilder; import org.opengroup.osdu.core.common.model.indexer.RecordInfo; -import org.opengroup.osdu.core.common.model.coreis.RecordChangedMessages; -import org.opengroup.osdu.core.common.spi.coreis.IRequestInfo; +import org.opengroup.osdu.core.common.model.search.RecordChangedMessages; +import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; import org.springframework.stereotype.Component; import javax.inject.Inject; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/StorageService.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/StorageService.java index 6c7de1f5e9f425802e18e6730cc128789f8dc698..ab8e9901294893255b0f00a7632ee0145c37f1fa 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/StorageService.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/StorageService.java @@ -14,7 +14,7 @@ package org.opengroup.osdu.indexer.service; -import org.opengroup.osdu.core.common.model.coreis.AppException; +import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.indexer.RecordQueryResponse; import org.opengroup.osdu.core.common.model.indexer.RecordReindexRequest; import org.opengroup.osdu.core.common.model.indexer.Records; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/StorageServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/StorageServiceImpl.java index 21e383aa7be974a5a7a7d74e29b399b4ec0a03af..ec0fbd948171d8c0990dd60403be5a652a5f1761 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/StorageServiceImpl.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/StorageServiceImpl.java @@ -20,15 +20,17 @@ import com.google.common.collect.Lists; import com.google.common.reflect.TypeToken; import com.google.gson.Gson; import lombok.extern.java.Log; -import org.opengroup.osdu.core.common.model.core.DpsHeaders; -import org.opengroup.osdu.core.common.model.coreis.AppException; -import org.opengroup.osdu.core.common.model.coreis.HttpResponse; -import org.opengroup.osdu.core.common.model.coreis.RequestStatus; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.model.http.HttpResponse; +import org.opengroup.osdu.core.common.model.http.RequestStatus; import org.opengroup.osdu.core.common.model.indexer.*; -import org.opengroup.osdu.core.common.service.coreis.JaxRsDpsLog; -import org.opengroup.osdu.core.common.service.coreis.UrlFetchService; -import org.opengroup.osdu.core.common.model.coreis.RecordMetaAttribute; -import org.opengroup.osdu.core.common.spi.coreis.IRequestInfo; +import org.opengroup.osdu.core.common.model.storage.ConversionStatus; +import org.opengroup.osdu.core.common.model.storage.RecordIds; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.http.IUrlFetchService; +import org.opengroup.osdu.core.common.model.search.RecordMetaAttribute; +import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; import org.apache.http.HttpStatus; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -43,8 +45,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import static org.opengroup.osdu.core.common.model.coreis.SlbHeaders.SLB_FRAME_OF_REFERENCE; -import static org.opengroup.osdu.core.common.model.core.Constants.SLB_FRAME_OF_REFERENCE_VALUE; +import static org.opengroup.osdu.core.common.model.http.DpsHeaders.FRAME_OF_REFERENCE; +import static org.opengroup.osdu.core.common.Constants.SLB_FRAME_OF_REFERENCE_VALUE; @Log @Component @@ -53,7 +55,7 @@ public class StorageServiceImpl implements StorageService { private final Gson gson = new Gson(); @Inject - private UrlFetchService urlFetchService; + private IUrlFetchService urlFetchService; @Inject private JobStatus jobStatus; @Inject @@ -95,7 +97,7 @@ public class StorageServiceImpl implements StorageService { // Map<String, String> headers = this.requestInfo.getHeadersMap(); DpsHeaders headers = this.requestInfo.getHeaders(); - headers.put(SLB_FRAME_OF_REFERENCE, SLB_FRAME_OF_REFERENCE_VALUE); + headers.put(FRAME_OF_REFERENCE, SLB_FRAME_OF_REFERENCE_VALUE); HttpResponse response = this.urlFetchService.sendRequest(HttpMethods.POST, STORAGE_QUERY_RECORD_FOR_CONVERSION_HOST, headers, null, body); String dataFromStorage = response.getBody(); if (Strings.isNullOrEmpty(dataFromStorage)) { diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/TenantInfoServiceImpl.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/TenantInfoServiceImpl.java deleted file mode 100644 index fd71a5597050a52332887588388bc3fba47bad56..0000000000000000000000000000000000000000 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/service/TenantInfoServiceImpl.java +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2017-2019, Schlumberger -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.opengroup.osdu.indexer.service; - - -import org.opengroup.osdu.core.common.model.core.DpsHeaders; -import org.opengroup.osdu.core.common.model.core.ITenantFactory; -import org.opengroup.osdu.core.common.model.core.TenantInfo; -import org.opengroup.osdu.core.common.model.coreis.AppException; -import org.opengroup.osdu.core.common.service.coreis.TenantInfoService; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Component; -import javax.inject.Inject; - -@Component -public class TenantInfoServiceImpl implements TenantInfoService { - - @Inject - private ITenantFactory tenantFactory; - @Inject - @Qualifier("dpsHeaderFactorySearch") - private DpsHeaders headersInfo; - - @Inject - @Qualifier("TenantInfoFactorySearch") - private TenantInfo tenantInfo; - - public TenantInfo getTenantInfo() { - - if(this.headersInfo == null) - throw AppException.createUnauthorized(String.format("could not retrieve headers info ")); - - TenantInfo tenantInfo = this.tenantFactory.getTenantInfo(this.headersInfo.getPartitionId()); - if (tenantInfo == null) - throw AppException.createUnauthorized(String.format("could not retrieve tenant info for account id: %s", headersInfo.getPartitionId())); - - return tenantInfo; - } -} \ No newline at end of file diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/ElasticClientHandler.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/ElasticClientHandler.java new file mode 100644 index 0000000000000000000000000000000000000000..fcc90699042b27fb2c4e67b7c3d4f24e97bf8267 --- /dev/null +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/ElasticClientHandler.java @@ -0,0 +1,102 @@ +// Copyright 2017-2019, Schlumberger +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.opengroup.osdu.indexer.util; + +import org.apache.http.Header; +import org.apache.http.HttpHost; +import org.apache.http.HttpStatus; +import org.apache.http.message.BasicHeader; +import org.elasticsearch.client.RestClient; +import org.elasticsearch.client.RestClientBuilder; +import org.elasticsearch.client.RestHighLevelClient; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.model.search.ClusterSettings; +import org.opengroup.osdu.core.common.model.indexer.IElasticSettingService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +import java.util.Base64; + +@Component +public class ElasticClientHandler { + + // Elastic cluster Rest client settings + private static final int CLOUD_REST_CLIENT_PORT = 9243; + private static final int REST_CLIENT_CONNECT_TIMEOUT = 60000; + private static final int REST_CLIENT_SOCKET_TIMEOUT = 60000; + private static final int REST_CLIENT_RETRY_TIMEOUT = 60000; + + @Autowired + private IElasticSettingService elasticSettingService; + + public RestHighLevelClient createRestClient() { + return getCloudRestClient(elasticSettingService.getElasticClusterInformation()); + } + // TODO: Remove this temporary implementation when ECE CCS is utilized + public RestHighLevelClient createRestClient(final ClusterSettings clusterSettings) { + return getCloudRestClient(clusterSettings); + } + + private RestHighLevelClient getCloudRestClient(final ClusterSettings clusterSettings) { + + String cluster = null; + String host = null; + int port = CLOUD_REST_CLIENT_PORT; + String protocolScheme = "https"; + String tls = "true"; + + try { + cluster = clusterSettings.getHost(); + host = clusterSettings.getHost(); + port = clusterSettings.getPort(); + if(!clusterSettings.isHttps()){ + protocolScheme = "http"; + } + + if(!clusterSettings.isTls()){ + tls = "false"; + } + String basicEncoded = Base64.getEncoder().encodeToString(clusterSettings.getUserNameAndPassword().getBytes()); + String basicAuthenticationHeaderVal = String.format("Basic %s", basicEncoded); + + RestClientBuilder builder = RestClient.builder(new HttpHost(host, port, protocolScheme)); + builder.setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder.setConnectTimeout(REST_CLIENT_CONNECT_TIMEOUT) + .setSocketTimeout(REST_CLIENT_SOCKET_TIMEOUT)); + builder.setMaxRetryTimeoutMillis(REST_CLIENT_RETRY_TIMEOUT); + + Header[] defaultHeaders = new Header[]{ + new BasicHeader("client.transport.nodes_sampler_interval", "30s"), + new BasicHeader("client.transport.ping_timeout", "30s"), + new BasicHeader("client.transport.sniff", "false"), + new BasicHeader("request.headers.X-Found-Cluster", cluster), + new BasicHeader("cluster.name", cluster), + new BasicHeader("xpack.security.transport.ssl.enabled", tls), + new BasicHeader("Authorization", basicAuthenticationHeaderVal), + }; + + builder.setDefaultHeaders(defaultHeaders); + return new RestHighLevelClient(builder); + } catch (AppException e) { + throw e; + } catch (Exception e) { + throw new AppException( + HttpStatus.SC_INTERNAL_SERVER_ERROR, + "search client error", + "error creating search client", + String.format("Elastic client connection params, cluster: %s, host: %s, port: %s", cluster, host, port), + e); + } + } +} \ No newline at end of file diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/IndexerQueueTaskBuilder.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/IndexerQueueTaskBuilder.java index fd724bc3318f5251d9638e5b5770ebb270473b3a..3621691c10e7fb0e62aa153d781302798eb4d7f2 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/IndexerQueueTaskBuilder.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/IndexerQueueTaskBuilder.java @@ -17,11 +17,11 @@ package org.opengroup.osdu.indexer.util; import com.google.api.client.http.HttpMethods; import com.google.gson.Gson; import lombok.extern.java.Log; -import org.opengroup.osdu.core.common.model.core.DpsHeaders; -import org.opengroup.osdu.core.common.model.coreis.CloudTaskRequest; -import org.opengroup.osdu.core.common.service.coreis.JaxRsDpsLog; -import org.opengroup.osdu.core.common.model.coreis.HttpResponse; -import org.opengroup.osdu.core.common.service.coreis.UrlFetchService; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.search.CloudTaskRequest; +import org.opengroup.osdu.core.common.model.http.HttpResponse; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.http.IUrlFetchService; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.web.context.annotation.RequestScope; @@ -29,16 +29,16 @@ import org.springframework.web.context.annotation.RequestScope; import java.net.URISyntaxException; import javax.inject.Inject; -import static org.opengroup.osdu.core.common.model.core.Constants.REINDEX_RELATIVE_URL; -import static org.opengroup.osdu.core.common.model.core.Constants.WORKER_RELATIVE_URL; +import static org.opengroup.osdu.core.common.Constants.REINDEX_RELATIVE_URL; +import static org.opengroup.osdu.core.common.Constants.WORKER_RELATIVE_URL; -@Log -@Component -@RequestScope -public class IndexerQueueTaskBuilder { + @Log + @Component + @RequestScope + public class IndexerQueueTaskBuilder { @Inject - private UrlFetchService urlFetchService; + private IUrlFetchService urlFetchService; @Inject private JaxRsDpsLog jaxRsDpsLog; diff --git a/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/TypeMapper.java b/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/TypeMapper.java index 4241dbf9c90150cb930ae74d559319f14a828b49..11b2935c2066a0f932714003089bd4b2489fb723 100644 --- a/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/TypeMapper.java +++ b/indexer-core/src/main/java/org/opengroup/osdu/indexer/util/TypeMapper.java @@ -14,12 +14,12 @@ package org.opengroup.osdu.indexer.util; -import org.opengroup.osdu.core.common.model.core.Constants; -import org.opengroup.osdu.core.common.model.coreis.AclRole; +import org.opengroup.osdu.core.common.Constants; +import org.opengroup.osdu.core.common.model.entitlements.AclRole; import org.opengroup.osdu.core.common.model.indexer.ElasticType; import org.opengroup.osdu.core.common.model.indexer.Records; import org.opengroup.osdu.core.common.model.indexer.StorageType; -import org.opengroup.osdu.core.common.model.coreis.RecordMetaAttribute; +import org.opengroup.osdu.core.common.model.search.RecordMetaAttribute; import java.util.HashMap; import java.util.Map; diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/RecordIndexerApiTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/RecordIndexerApiTest.java index d8106c5635d443202dbfc1d8633fc35f544331f1..72fc5f925d859745ba37be0768bff2f43abeda01 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/RecordIndexerApiTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/RecordIndexerApiTest.java @@ -17,20 +17,18 @@ package org.opengroup.osdu.indexer.api; import com.google.gson.Gson; import org.junit.Assert; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.opengroup.osdu.core.common.model.core.DpsHeaders; -import org.opengroup.osdu.core.common.model.coreis.AppException; -import org.opengroup.osdu.core.common.service.coreis.Config; -import org.opengroup.osdu.core.common.service.coreis.JaxRsDpsLog; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.search.Config; import org.opengroup.osdu.indexer.service.IndexerService; import org.opengroup.osdu.indexer.util.IndexerQueueTaskBuilder; -import org.opengroup.osdu.core.common.model.coreis.RecordChangedMessages; -import org.opengroup.osdu.core.common.service.coreis.Config; -import org.opengroup.osdu.core.common.service.coreis.HeadersUtil; +import org.opengroup.osdu.core.common.model.search.RecordChangedMessages; +import org.opengroup.osdu.core.common.http.HeadersUtil; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.springframework.http.HttpStatus; diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/ReindexApiTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/ReindexApiTest.java index bc33aaf4ccf858631f6af3b921c6bd5d1187704a..88a101b5df8f2e996b0602ac47c7940292ed01d3 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/ReindexApiTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/api/ReindexApiTest.java @@ -19,8 +19,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.opengroup.osdu.core.common.model.coreis.AppException; -import org.opengroup.osdu.core.common.model.indexer.AuditLogger; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.indexer.logging.AuditLogger; import org.opengroup.osdu.core.common.model.indexer.RecordReindexRequest; import org.opengroup.osdu.indexer.service.ReindexService; diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/auth/AuthorizationServiceEntitlementsTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/auth/AuthorizationServiceEntitlementsTest.java deleted file mode 100644 index 73533139e713ab0b5059931baa375e82345d7462..0000000000000000000000000000000000000000 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/auth/AuthorizationServiceEntitlementsTest.java +++ /dev/null @@ -1,153 +0,0 @@ -// Copyright 2017-2019, Schlumberger -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.opengroup.osdu.indexer.auth; - -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; -import org.opengroup.osdu.core.common.model.core.entitlements.EntitlementsException; -import org.opengroup.osdu.core.common.service.core.entitlements.IEntitlementsFactory; -import org.opengroup.osdu.core.common.service.core.entitlements.IEntitlementsService; -import org.opengroup.osdu.core.common.model.core.entitlements.GroupInfo; -import org.opengroup.osdu.core.common.model.core.entitlements.Groups; -import org.opengroup.osdu.core.common.model.core.DpsHeaders; -import org.opengroup.osdu.core.common.model.coreis.AppException; -import org.opengroup.osdu.core.common.service.core.HttpResponse; -import org.opengroup.osdu.core.common.service.coreis.JaxRsDpsLog; -import org.opengroup.osdu.core.common.model.coreis.AuthorizationResponse; -import org.springframework.test.context.junit4.SpringRunner; - -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.when; - -@RunWith(SpringRunner.class) -public class AuthorizationServiceEntitlementsTest { - - @Mock - private IEntitlementsFactory entitlementsFactory; - @Mock - private IEntitlementsService service; - @Mock - private JaxRsDpsLog log; - @InjectMocks - private AuthorizationServiceEntitlements sut; - - @Before - public void setup() { - when(entitlementsFactory.create(any())).thenReturn(service); - } - - @Test - public void should_returnUser_when_ussrHasPermission() throws EntitlementsException { - - sut = createSut("service.search.user"); - - AuthorizationResponse result = sut.authorizeAny(DpsHeaders.createFromMap(new HashMap<>()), "service.search.user"); - - assertEquals("iamtester@dps.com", result.getUser()); - } - - @Test - public void should_returnUser_when_ussrHasAnyPermission() throws EntitlementsException { - - sut = createSut("service.search.user"); - - AuthorizationResponse result = sut.authorizeAny(DpsHeaders.createFromMap(new HashMap<>()), "service.search.user", "service.search.owner"); - - assertEquals("iamtester@dps.com", result.getUser()); - } - - @Test - public void should_throwUnauthorized_when_userDoesNotHaveRequiredPermission() throws EntitlementsException { - sut = createSut("service.search.user"); - - try { - sut.authorizeAny(DpsHeaders.createFromMap(new HashMap<>()), "service.search.owner"); - fail("expected exception"); - } catch (AppException ex) { - assertEquals(401, ex.getError().getCode()); - } - } - - @Test - public void should_throwUnauthorized_when_userDoesNotBelongToAnyGroup() throws EntitlementsException { - sut = createSut("service.search.user"); - HttpResponse response = new HttpResponse(); - response.setResponseCode(401); - when(service.getGroups()).thenThrow(new EntitlementsException("", response)); - - try { - sut.authorizeAny(DpsHeaders.createFromMap(new HashMap<>()), "service.search.owner"); - fail("expected exception"); - } catch (AppException ex) { - assertEquals(401, ex.getError().getCode()); - } - } - - @Test - public void should_throwServerError_when_getGroupsThrowsServerError() throws EntitlementsException { - sut = createSut("service.search.user"); - HttpResponse response = new HttpResponse(); - response.setResponseCode(500); - when(service.getGroups()).thenThrow(new EntitlementsException("", response)); - try { - sut.authorizeAny(DpsHeaders.createFromMap(new HashMap<>()), "service.search.owner"); - fail("expected exception"); - } catch (AppException ex) { - assertEquals(500, ex.getError().getCode()); - } - } - - @Test - public void should_throw403AppError_when_getGroupsThrows400EntitlementsError() throws EntitlementsException { - sut = createSut("service.search.user"); - HttpResponse response = new HttpResponse(); - response.setResponseCode(403); - when(service.getGroups()).thenThrow(new EntitlementsException("", response)); - try { - sut.authorizeAny(DpsHeaders.createFromMap(new HashMap<>()), "service.search.owner"); - fail("expected exception"); - } catch (AppException ex) { - assertEquals(403, ex.getError().getCode()); - } - } - - private AuthorizationServiceEntitlements createSut(String... roles) throws EntitlementsException { - - List<GroupInfo> groupInfos = new ArrayList<>(); - - for (String s : roles) { - GroupInfo group = new GroupInfo(); - group.setName(s); - groupInfos.add(group); - } - - Groups output = new Groups(); - output.setMemberEmail("iamtester@dps.com"); - output.setGroups(groupInfos); - - when(service.getGroups()).thenReturn(output); - - return sut; - } -} diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/logging/AuditEventsTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/logging/AuditEventsTest.java index 9a5b09a3a57da2f9be4ecfda697b5efe739f225b..9f9b8d7123f5cd0243d9190f73df5a9b393d335b 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/logging/AuditEventsTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/logging/AuditEventsTest.java @@ -17,9 +17,8 @@ package org.opengroup.osdu.indexer.logging; import com.google.common.collect.Lists; import org.junit.Test; import org.junit.runner.RunWith; -import org.opengroup.osdu.core.common.model.core.AuditAction; -import org.opengroup.osdu.core.common.model.core.AuditStatus; -import org.opengroup.osdu.core.common.model.indexer.AuditEvents; +import org.opengroup.osdu.core.common.logging.audit.AuditAction; +import org.opengroup.osdu.core.common.logging.audit.AuditStatus; import org.springframework.test.context.junit4.SpringRunner; import java.util.Map; diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/logging/AuditLoggerTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/logging/AuditLoggerTest.java index a8cfcbffb8a35c9cde44738bcb9d1451c55cb92a..d6e0cf1a06705e47e08f82918a59b2f8ba2fb6b5 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/logging/AuditLoggerTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/logging/AuditLoggerTest.java @@ -21,10 +21,9 @@ import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.opengroup.osdu.core.common.model.core.AuditPayload; -import org.opengroup.osdu.core.common.model.indexer.AuditLogger; -import org.opengroup.osdu.core.common.service.coreis.JaxRsDpsLog; -import org.opengroup.osdu.core.common.spi.coreis.IHeadersInfo; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.logging.audit.AuditPayload; import org.springframework.test.context.junit4.SpringRunner; import java.util.Map; @@ -38,13 +37,13 @@ public class AuditLoggerTest { @Mock private JaxRsDpsLog logger; @Mock - private IHeadersInfo headers; + private DpsHeaders headers; @InjectMocks private AuditLogger sut; @Before public void setup() { - when(this.headers.getUser()).thenReturn("testUser"); + when(this.headers.getUserEmail()).thenReturn("testUser"); } @Test diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/logging/JaxRsDpsLogTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/logging/JaxRsDpsLogTest.java index bd5624bd54223d8fb2086c324226d2edcfac4d61..3e9f19913838e05283b33240856b23a43592b41f 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/logging/JaxRsDpsLogTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/logging/JaxRsDpsLogTest.java @@ -20,12 +20,11 @@ import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.opengroup.osdu.core.common.model.core.AuditPayload; -import org.opengroup.osdu.core.common.model.core.DpsHeaders; -import org.opengroup.osdu.core.common.model.core.DpsLog; -import org.opengroup.osdu.core.common.model.core.Request; -import org.opengroup.osdu.core.common.model.indexer.ServiceLogId; -import org.opengroup.osdu.core.common.service.coreis.JaxRsDpsLog; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.http.Request; +import org.opengroup.osdu.core.common.logging.ILogger; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.logging.audit.AuditPayload; import org.powermock.core.classloader.annotations.PrepareForTest; import org.springframework.test.context.junit4.SpringRunner; @@ -39,18 +38,15 @@ import static org.mockito.Mockito.*; @Ignore @RunWith(SpringRunner.class) -@PrepareForTest({DpsLog.class}) +@PrepareForTest({ILogger.class}) public class JaxRsDpsLogTest { @Mock - private DpsLog log; + private ILogger log; @InjectMocks private JaxRsDpsLog sut; - @InjectMocks - private ServiceLogId logId; - @Test public void should_includeAllHeadersExceptAuth_when_writingALog() { this.sut.info("msg"); @@ -60,9 +56,6 @@ public class JaxRsDpsLogTest { assertEquals("cor123", argument.getValue().get(DpsHeaders.CORRELATION_ID)); assertFalse(argument.getValue().containsKey("authorization")); - when(logId.getAppLog()).thenReturn("search.app"); - when(logId.getAuditLog()).thenReturn("search.audit"); - when(logId.getRequestLog()).thenReturn("search.request"); } @Test diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/model/RecordChagedMessagesTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/model/RecordChagedMessagesTest.java index de936e7aac444684806a6ee7b5f658650480793d..071d140ae39a1ebf709c4e1712f74da23feb2918 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/model/RecordChagedMessagesTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/model/RecordChagedMessagesTest.java @@ -18,8 +18,8 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.opengroup.osdu.core.common.model.core.DpsHeaders; -import org.opengroup.osdu.core.common.model.coreis.RecordChangedMessages; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.search.RecordChangedMessages; import org.springframework.test.context.junit4.SpringRunner; import java.util.HashMap; diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/AttributeParsingServiceImplTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/AttributeParsingServiceImplTest.java index 8c369cb72b43c5f3b07467bdddf9d07bb929408b..a9ae625fd821fb58893b7dc79bceb2cb893e450b 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/AttributeParsingServiceImplTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/AttributeParsingServiceImplTest.java @@ -20,7 +20,7 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.opengroup.osdu.core.common.model.indexer.JobStatus; -import org.opengroup.osdu.core.common.service.coreis.JaxRsDpsLog; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.indexer.util.parser.DateTimeParser; import org.opengroup.osdu.indexer.util.parser.NumberParser; import org.springframework.test.context.junit4.SpringRunner; diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/GeometryConversionServiceTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/GeometryConversionServiceTest.java index e5cf8889a53cc411db4bddddf39e937a77963081..9795772efc04c14107662877d9d654491a99645f 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/GeometryConversionServiceTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/GeometryConversionServiceTest.java @@ -18,7 +18,7 @@ import com.google.gson.internal.LinkedTreeMap; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.opengroup.osdu.core.common.model.core.Constants; +import org.opengroup.osdu.core.common.Constants; import org.springframework.test.context.junit4.SpringRunner; import java.util.ArrayList; diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndicesServiceTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndicesServiceTest.java new file mode 100644 index 0000000000000000000000000000000000000000..0051012ef572f075e91df197310e2557786c69ce --- /dev/null +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/IndicesServiceTest.java @@ -0,0 +1,222 @@ +// Copyright 2017-2019, Schlumberger +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.opengroup.osdu.indexer.service; + +import com.google.common.reflect.TypeToken; +import com.google.gson.Gson; + +import org.apache.http.HttpEntity; +import org.apache.http.HttpStatus; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.util.EntityUtils; +import org.elasticsearch.ElasticsearchStatusException; +import org.elasticsearch.action.support.master.AcknowledgedResponse; +import org.elasticsearch.client.*; +import org.elasticsearch.rest.RestStatus; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.provider.interfaces.IIndexCache; +import org.opengroup.osdu.core.common.model.search.IndexInfo; +import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; +import org.opengroup.osdu.indexer.util.ElasticClientHandler; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.springframework.context.annotation.Lazy; +import org.springframework.test.context.junit4.SpringRunner; + +import java.io.IOException; +import java.lang.reflect.Type; +import java.util.List; + +import static junit.framework.TestCase.assertTrue; +import static org.junit.Assert.*; +import static org.mockito.Mockito.*; +import static org.mockito.MockitoAnnotations.initMocks; + +@RunWith(SpringRunner.class) +@PrepareForTest({RestHighLevelClient.class, IndicesClient.class, EntityUtils.class}) +public class IndicesServiceTest { + @Mock + private ElasticClientHandler elasticClientHandler; + @Mock + private ElasticIndexNameResolver elasticIndexNameResolver; + @Mock + private IIndexCache indicesExistCache; + @Mock + @Lazy + private JaxRsDpsLog log; + @Mock + private RestClient restClient; + @Mock + private Response response; + @Mock + private HttpEntity httpEntity; + @InjectMocks + private IndicesServiceImpl sut; + + private RestHighLevelClient restHighLevelClient; + private IndicesClient indicesClient; + + @Before + public void setup() { + initMocks(this); + indicesClient = PowerMockito.mock(IndicesClient.class); + restHighLevelClient = PowerMockito.mock(RestHighLevelClient.class); + } + + @Test + public void delete_existingElasticIndex() throws Exception { + AcknowledgedResponse indexResponse = new AcknowledgedResponse(true); + + when(elasticClientHandler.createRestClient()).thenReturn(restHighLevelClient); + doReturn(indicesClient).when(restHighLevelClient).indices(); + doReturn(indexResponse).when(indicesClient).delete(any(), any(RequestOptions.class)); + boolean response = this.sut.deleteIndex("anyIndex"); + assertTrue(response); + } + + @Test + public void delete_existingElasticIndex_usingSameClient() throws Exception { + AcknowledgedResponse indexResponse = new AcknowledgedResponse(true); + + when(elasticClientHandler.createRestClient()).thenReturn(restHighLevelClient); + doReturn(indicesClient).when(restHighLevelClient).indices(); + doReturn(indexResponse).when(indicesClient).delete(any(), any(RequestOptions.class)); + boolean response = this.sut.deleteIndex(restHighLevelClient, "anyIndex"); + assertTrue(response); + } + + @Test + public void should_throw_internalServerException_delete_isNotAcknowledged() throws Exception { + AcknowledgedResponse indexResponse = new AcknowledgedResponse(false); + when(elasticClientHandler.createRestClient()).thenReturn(restHighLevelClient); + doReturn(indicesClient).when(restHighLevelClient).indices(); + doReturn(indexResponse).when(indicesClient).delete(any(), any(RequestOptions.class)); + + try { + this.sut.deleteIndex("anyIndex"); + fail("Should not succeed!"); + } catch (AppException e) { + assertEquals(HttpStatus.SC_INTERNAL_SERVER_ERROR, e.getError().getCode()); + assertEquals("Could not delete index anyIndex", e.getError().getMessage()); + assertEquals("Index deletion error", e.getError().getReason()); + } catch (Exception e) { + fail("Should not throw this exception " + e.getMessage()); + } + } + + @Test + public void should_throwAppException_when_delete_existingElasticIndex_and_backupIsRunning() throws Exception { + ElasticsearchStatusException exception = new ElasticsearchStatusException( + "Cannot delete indices that are being snapshotted: [[anyIndex/8IXuPeFnTJGEu_LjjXrHwA]]. Try again after snapshot finishes or cancel the currently running snapshot.", RestStatus.BAD_REQUEST); + when(elasticClientHandler.createRestClient()).thenReturn(restHighLevelClient); + doReturn(indicesClient).when(restHighLevelClient).indices(); + doThrow(exception).when(indicesClient).delete(any(), any(RequestOptions.class)); + + try { + this.sut.deleteIndex("anyIndex"); + fail("Should not succeed!"); + } catch (AppException e) { + assertEquals(HttpStatus.SC_CONFLICT, e.getError().getCode()); + assertEquals("Unable to delete the index because it is currently locked. Try again in few minutes.", e.getError().getMessage()); + assertEquals("Index deletion error", e.getError().getReason()); + } catch (Exception e) { + fail("Should not throw this exception " + e.getMessage()); + } + } + + @Test + public void should_throwAppException_when_delete_nonExistent_index() throws Exception { + ElasticsearchStatusException exception = new ElasticsearchStatusException("no such index", RestStatus.NOT_FOUND); + when(elasticClientHandler.createRestClient()).thenReturn(restHighLevelClient); + doReturn(indicesClient).when(restHighLevelClient).indices(); + doThrow(exception).when(indicesClient).delete(any(), any(RequestOptions.class)); + + try { + this.sut.deleteIndex("anyIndex"); + fail("Should not succeed!"); + } catch (AppException e) { + assertEquals(HttpStatus.SC_NOT_FOUND, e.getError().getCode()); + assertEquals("Index anyIndex not found", e.getError().getMessage()); + assertEquals("Index deletion error", e.getError().getReason()); + } catch (Exception e) { + fail("Should not throw this exception " + e.getMessage()); + } + } + + @Test + public void should_get_valid_indexInfo() throws IOException { + String responseJson = "[" + + " {" + + " \"index\": \"tenant1-aapg-file-1.0.0\"," + + " \"docs.count\": \"92\"," + + " \"creation.date\": \"1545912860994\"" + + " }" + + "]"; + Request request = new Request("GET", "/_cat/indices/*,-.*?h=index,docs.count,creation.date&s=docs.count:asc&format=json"); + StringEntity entity = new StringEntity(responseJson, ContentType.APPLICATION_JSON); + when(this.restHighLevelClient.getLowLevelClient()).thenReturn(this.restClient); + when(this.restClient.performRequest(request)).thenReturn(response); + when(this.response.getEntity()).thenReturn(entity); + + List<IndexInfo> infos = this.sut.getIndexInfo(this.restHighLevelClient, ""); + assertNotNull(infos); + assertEquals(1, infos.size()); + } + + @Test + public void should_get_valid_indexInfoByPattern() throws IOException { + String responseJson = "[" + + " {" + + " \"index\": \"tenant1-aapg-file-1.0.0\"," + + " \"docs.count\": \"92\"," + + " \"creation.date\": \"1545912860994\"" + + " }," + + " {" + + " \"index\": \"tenant1-aapg-document-1.0.0\"," + + " \"docs.count\": \"0\"," + + " \"creation.date\": \"1545912868416\"" + + " }" + + "]"; + Request request = new Request("GET", "/_cat/indices/tenant1-aapg-*?h=index,docs.count,creation.date&format=json"); + StringEntity entity = new StringEntity(responseJson, ContentType.APPLICATION_JSON); + when(this.restHighLevelClient.getLowLevelClient()).thenReturn(this.restClient); + when(this.restClient.performRequest(request)).thenReturn(response); + when(this.response.getEntity()).thenReturn(entity); + + List<IndexInfo> infos = this.sut.getIndexInfo(this.restHighLevelClient, "tenant1-aapg-*"); + assertNotNull(infos); + assertEquals(2, infos.size()); + } + + @Test + public void should_properly_deserialize_indices_get_response() { + String jsonResponse = "[{\"index\":\"tenant1-test-hello-1.0.1\",\"docs.count\":\"1\",\"creation.date\":\"1551996907769\"}]"; + + final Type typeOf = new TypeToken<List<IndexInfo>>() {}.getType(); + List<IndexInfo> indicesList = new Gson().fromJson(jsonResponse, typeOf); + + assertEquals(1, indicesList.size()); + assertEquals("tenant1-test-hello-1.0.1", indicesList.get(0).getName()); + assertEquals("1", indicesList.get(0).getDocumentCount()); + assertEquals("1551996907769", indicesList.get(0).getCreationDate()); + } +} \ No newline at end of file diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/MappingServiceImplTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/MappingServiceImplTest.java new file mode 100644 index 0000000000000000000000000000000000000000..e57dd3c33a2d6910f753d22ee40e9ebdf1287f4f --- /dev/null +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/service/MappingServiceImplTest.java @@ -0,0 +1,104 @@ +// Copyright 2017-2019, Schlumberger +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +/* +package org.opengroup.osdu.is.core.service; + +import org.apache.http.HttpStatus; +import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsResponse; +import org.elasticsearch.client.IndicesClient; +import org.elasticsearch.client.RequestOptions; +import org.elasticsearch.client.RestHighLevelClient; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.model.indexer.IElasticSettingService; +import org.opengroup.osdu.core.common.service.coreis.*; +import org.opengroup.osdu.is.core.util.ElasticClientHandler; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.springframework.test.context.junit4.SpringRunner; + +import java.io.IOException; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.*; +import static org.mockito.MockitoAnnotations.initMocks; + +@RunWith(SpringRunner.class) +@PrepareForTest({RestHighLevelClient.class, IndicesClient.class, GetMappingsResponse.class}) +public class MappingServiceImplTest { + @Mock + private IElasticSettingService elasticSettingService; + @Mock + private ElasticClientHandler elasticClientHandler; + @Mock + private ElasticIndexNameResolver elasticIndexNameResolver; + @Mock + private IndicesService indicesService; + @InjectMocks + private MappingServiceImpl sut; + + private RestHighLevelClient restHighLevelClient; + private IndicesClient indicesClient; + private GetMappingsResponse mappingsResponse; + private String index = "anyindex"; + + @Before + public void setup() { + initMocks(this); + this.indicesClient = PowerMockito.mock(IndicesClient.class); + this.restHighLevelClient = PowerMockito.mock(RestHighLevelClient.class); + this.mappingsResponse = PowerMockito.mock(GetMappingsResponse.class); + } + + @Test + public void error_when_get_mapping_from_non_exists_elastic_index() throws Exception { + try { + when(this.indicesService.isIndexExist(restHighLevelClient, index)).thenReturn(false); + + this.sut.getIndexMapping(restHighLevelClient, index); + fail("expected exception"); + } catch (AppException ex) { + assertEquals(HttpStatus.SC_NOT_FOUND, ex.getError().getCode()); + } + } + + @Test(expected = AppException.class) + public void error_when_get_mapping_failed_from_existing_elastic_index() throws Exception { + when(this.indicesService.isIndexExist(this.restHighLevelClient, this.index)).thenReturn(true); + doReturn(this.indicesClient).when(this.restHighLevelClient).indices(); + doThrow(new IOException()).when(this.indicesClient).getMapping(any(), any(RequestOptions.class)); + + this.sut.getIndexMapping(this.restHighLevelClient, this.index); + + fail("expected exception"); + } + + @Test + public void get_mapping_from_existing_elastic_index() throws Exception { + when(this.indicesService.isIndexExist(restHighLevelClient, index)).thenReturn(true); + doReturn(this.indicesClient).when(this.restHighLevelClient).indices(); + doReturn(this.mappingsResponse).when(this.indicesClient).getMapping(any(), any(RequestOptions.class)); + doReturn("dummy").when(this.mappingsResponse).toString(); + + String mapping = this.sut.getIndexMapping(restHighLevelClient, index); + + // TODO + assertEquals("dummy", mapping); + } +}*/ \ No newline at end of file diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/ElasticClientHandlerTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/ElasticClientHandlerTest.java new file mode 100644 index 0000000000000000000000000000000000000000..dc7d6db42dded11847ccc7dce7b8dc3030161e70 --- /dev/null +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/ElasticClientHandlerTest.java @@ -0,0 +1,102 @@ +// Copyright 2017-2019, Schlumberger +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.opengroup.osdu.indexer.util; + +import org.apache.http.HttpHost; +import org.elasticsearch.client.RestClient; +import org.elasticsearch.client.RestClientBuilder; +import org.elasticsearch.client.RestHighLevelClient; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.search.Config; +import org.opengroup.osdu.core.common.model.indexer.IElasticSettingService; +import org.opengroup.osdu.core.common.model.search.ClusterSettings; +import org.opengroup.osdu.core.common.model.search.DeploymentEnvironment; +import org.powermock.core.classloader.annotations.PrepareForTest; +import org.springframework.test.context.junit4.SpringRunner; + +import static org.junit.Assert.assertEquals; +import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.initMocks; + +@Ignore +@RunWith(SpringRunner.class) +@PrepareForTest({Config.class, RestClientBuilder.class, RestClient.class, RestHighLevelClient.class}) +public class ElasticClientHandlerTest { + + @Mock + private IElasticSettingService elasticSettingService; + + @Mock + private RestClientBuilder builder; + + @Mock + private RestClient restClient; + @Mock + private JaxRsDpsLog log; + + @InjectMocks + private ElasticClientHandler elasticClientHandler; + + @Before + public void setup() { + initMocks(this); + +// mockStatic(Config.class); +// mockStatic(RestClient.class); + } + + @Test + public void createRestClient_when_deployment_env_is_saas() { + ClusterSettings clusterSettings = new ClusterSettings("H", 1, "U:P"); + when(Config.getDeploymentEnvironment()).thenReturn(DeploymentEnvironment.CLOUD); + when(elasticSettingService.getElasticClusterInformation()).thenReturn(clusterSettings); + when(RestClient.builder(new HttpHost("H", 1, "https"))).thenReturn(builder); + when(builder.setRequestConfigCallback(requestConfigBuilder -> requestConfigBuilder.setConnectTimeout(5000).setSocketTimeout(60000))).thenReturn(builder); + when(builder.build()).thenReturn(restClient); + + RestHighLevelClient returned = this.elasticClientHandler.createRestClient(); + + assertEquals(restClient, returned.getLowLevelClient()); + } + + @Test(expected = AppException.class) + public void failed_createRestClientForSaaS_when_restclient_is_null() { + ClusterSettings clusterSettings = new ClusterSettings("H", 1, "U:P"); + when(Config.getDeploymentEnvironment()).thenReturn(DeploymentEnvironment.CLOUD); + when(elasticSettingService.getElasticClusterInformation()).thenReturn(clusterSettings); + when(RestClient.builder(new HttpHost("H", 1, "https"))).thenReturn(builder); + when(builder.build()).thenReturn(null); + + this.elasticClientHandler.createRestClient(); + } + + @Test(expected = AppException.class) + public void failed_createRestClientForSaaS_when_getcluster_info_throws_exception() { + when(Config.getDeploymentEnvironment()).thenReturn(DeploymentEnvironment.CLOUD); + when(elasticSettingService.getElasticClusterInformation()).thenThrow(new AppException(1, "", "")); + when(RestClient.builder(new HttpHost("H", 1, "https"))).thenReturn(builder); + + this.elasticClientHandler.createRestClient(); + } +} + + diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/JobStatusTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/JobStatusTest.java index d2d19299c9dd3b68cd39e28a44ce28ef0e771f38..9e61f1cde0e3b673086cd13a671db65a9bb18d3a 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/JobStatusTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/JobStatusTest.java @@ -25,8 +25,8 @@ import org.opengroup.osdu.core.common.model.indexer.IndexingStatus; import org.opengroup.osdu.core.common.model.indexer.OperationType; import org.opengroup.osdu.core.common.model.indexer.RecordStatus; import org.opengroup.osdu.core.common.model.indexer.RecordInfo; -import org.opengroup.osdu.core.common.service.coreis.JaxRsDpsLog; import org.opengroup.osdu.core.common.model.indexer.Records; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.springframework.test.context.junit4.SpringRunner; import java.lang.reflect.Type; diff --git a/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/RecordInfoTest.java b/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/RecordInfoTest.java index f06fbd6e18091e021bc44ca9391b04049047bf9d..a919a0c4bc2e52144332b8d5cd6a8228cdda4db8 100644 --- a/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/RecordInfoTest.java +++ b/indexer-core/src/test/java/org/opengroup/osdu/indexer/util/RecordInfoTest.java @@ -20,7 +20,7 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; -import org.opengroup.osdu.core.common.model.coreis.AppException; +import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.core.common.model.indexer.OperationType; import org.opengroup.osdu.core.common.model.indexer.RecordInfo; import org.springframework.http.HttpStatus; diff --git a/pom.xml b/pom.xml index c4b02c3a03f913f670860bbcf75e183b7279b33c..ab061f485ab4bfba4d832157237970e7e900cdab 100644 --- a/pom.xml +++ b/pom.xml @@ -14,7 +14,7 @@ <groupId>org.opengroup.osdu.indexer</groupId> <artifactId>indexer-service</artifactId> <packaging>pom</packaging> - <version>1.0.3-SNAPSHOT</version> + <version>1.0.4-SNAPSHOT</version> <description>Indexer Service</description> <properties> diff --git a/provider/indexer-aws/azure-build.yml b/provider/indexer-aws/azure-build.yml index 78e2e712788ead2ab0269e0c7a5b7b2be0d1ea1b..8379aecec711c68a49e528be0d21e0cd9d809bc7 100644 --- a/provider/indexer-aws/azure-build.yml +++ b/provider/indexer-aws/azure-build.yml @@ -18,7 +18,7 @@ steps: displayName: 'build, test, code coverage' inputs: mavenPomFile: 'pom.xml' - options: '--settings ./indexer-core/maven/settings.xml -DVSTS_FEED_TOKEN=$(VSTS_FEED_TOKEN)' + options: '--settings ./indexer-core/maven/settings.xml -DVSTS_FEED_TOKEN=$(VSTS_FEED_TOKEN) -U' testResultsFiles: '**/*/TEST-*.xml' codeCoverageToolOption: JaCoCo goals: 'install' diff --git a/provider/indexer-aws/pom.xml b/provider/indexer-aws/pom.xml index 872ab23987ffc5ce3fc4e3b2f5810899ac1ac504..abac644bc00790c76cdf7de06352d266344b2209 100644 --- a/provider/indexer-aws/pom.xml +++ b/provider/indexer-aws/pom.xml @@ -19,7 +19,7 @@ <parent> <groupId>org.opengroup.osdu.indexer</groupId> <artifactId>indexer-service</artifactId> - <version>1.0.2</version> + <version>1.0.4-SNAPSHOT</version> <relativePath>../..</relativePath> </parent> @@ -39,17 +39,17 @@ <dependency> <groupId>org.opengroup.osdu</groupId> <artifactId>os-core-common</artifactId> - <version>0.0.8</version> + <version>0.0.12</version> </dependency> <dependency> <groupId>org.opengroup.osdu.indexer</groupId> <artifactId>indexer-core</artifactId> - <version>1.0.2</version> + <version>1.0.4-SNAPSHOT</version> </dependency> <dependency> <groupId>org.opengroup.osdu.core.aws</groupId> <artifactId>aws-osdu-util</artifactId> - <version>0.0.4</version> + <version>0.0.8</version> </dependency> <!-- AWS managed packages --> diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/IndexerAwsApplication.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/IndexerAwsApplication.java index 501bdddb2cf77765a701fb3651cfff5e5340713c..8d550c871e75408fa2a9e2fc2c90f32dc8dd4124 100644 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/IndexerAwsApplication.java +++ b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/IndexerAwsApplication.java @@ -22,7 +22,7 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @SpringBootApplication(exclude = { SecurityAutoConfiguration.class, ManagementWebSecurityAutoConfiguration.class }) -@ComponentScan({"org.opengroup.osdu.core.common", "org.opengroup.osdu.indexer"}) +@ComponentScan({"org.opengroup.osdu"}) public class IndexerAwsApplication { public static void main(String[] args) { diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/cache/ElasticCredentialsCacheImpl.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/cache/ElasticCredentialsCacheImpl.java index db363d92d87c633e3acc37278e4d1c69fdec1acf..63b65bac319cfb8ae9f93bb3bd73d1646a2c087f 100644 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/cache/ElasticCredentialsCacheImpl.java +++ b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/cache/ElasticCredentialsCacheImpl.java @@ -14,7 +14,7 @@ package org.opengroup.osdu.indexer.aws.cache; -import org.opengroup.osdu.core.common.spi.coreis.IElasticCredentialsCache; +import org.opengroup.osdu.core.common.provider.interfaces.IElasticCredentialsCache; import org.springframework.stereotype.Component; @Component diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/cache/IndexCacheImpl.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/cache/IndexCacheImpl.java index 2e5976c76da15079fd330b53d038b2528fdfd85e..b8953ba2d6cc3aaee5e99565bbc2417413f5d153 100644 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/cache/IndexCacheImpl.java +++ b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/cache/IndexCacheImpl.java @@ -14,8 +14,8 @@ package org.opengroup.osdu.indexer.aws.cache; -import org.opengroup.osdu.core.common.model.core.cache.RedisCache; -import org.opengroup.osdu.core.common.spi.coreis.IIndexCache; +import org.opengroup.osdu.core.common.cache.RedisCache; +import org.opengroup.osdu.core.common.provider.interfaces.IIndexCache; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/cache/SchemaCacheImpl.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/cache/SchemaCacheImpl.java index 9434ed3b67731f362a827631ac62794fcafe694c..112b3b2f8b1a591f785edb675b7a84cfe2cf5198 100644 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/cache/SchemaCacheImpl.java +++ b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/cache/SchemaCacheImpl.java @@ -14,8 +14,8 @@ package org.opengroup.osdu.indexer.aws.cache; -import org.opengroup.osdu.core.common.model.core.cache.RedisCache; -import org.opengroup.osdu.core.common.spi.indexer.ISchemaCache; +import org.opengroup.osdu.core.common.cache.RedisCache; +import org.opengroup.osdu.indexer.provider.interfaces.ISchemaCache; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/di/DpsLogFactory.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/di/DpsLogFactory.java deleted file mode 100644 index b3bde6b2e7a4cc68f92fd2edfc0788acda9fea21..0000000000000000000000000000000000000000 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/di/DpsLogFactory.java +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright © Amazon Web Services -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.opengroup.osdu.indexer.aws.di; - -import org.opengroup.osdu.core.common.model.core.DpsLog; -import org.opengroup.osdu.core.common.service.core.Log; -import org.springframework.beans.factory.config.AbstractFactoryBean; -import org.springframework.stereotype.Component; - -@Component -public class DpsLogFactory extends AbstractFactoryBean<DpsLog> { - - @Override - protected DpsLog createInstance() throws Exception { - return new Log(); - } - - @Override - public Class<?> getObjectType() { - return DpsLog.class; - } -} \ No newline at end of file diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/di/EntitlementsFactoryImpl.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/di/EntitlementsFactoryImpl.java index 92522a9e9a4de7a73bbf7347c53807bd08425f14..85517a87d6873f420b325e2201612e17181f3e1e 100644 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/di/EntitlementsFactoryImpl.java +++ b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/di/EntitlementsFactoryImpl.java @@ -14,9 +14,9 @@ package org.opengroup.osdu.indexer.aws.di; -import org.opengroup.osdu.core.common.model.core.DpsHeaders; -import org.opengroup.osdu.core.common.service.core.entitlements.IEntitlementsFactory; -import org.opengroup.osdu.core.common.service.core.entitlements.IEntitlementsService; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.entitlements.IEntitlementsFactory; +import org.opengroup.osdu.core.common.entitlements.IEntitlementsService; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Component; diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/di/EntitlementsServiceImpl.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/di/EntitlementsServiceImpl.java index e4cb22e094c14a3d3aca41a9853d01f2721a831c..3dd657c6699407a4557f4d149fcf2a241d39e762 100644 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/di/EntitlementsServiceImpl.java +++ b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/di/EntitlementsServiceImpl.java @@ -20,16 +20,15 @@ import com.amazonaws.services.lambda.invoke.LambdaSerializationException; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import org.opengroup.osdu.core.common.model.core.DpsHeaders; -import org.opengroup.osdu.core.common.model.core.entitlements.EntitlementsException; -import org.opengroup.osdu.core.common.model.core.entitlements.MemberInfo; -import org.opengroup.osdu.core.common.model.core.entitlements.Members; -import org.opengroup.osdu.core.common.service.core.entitlements.IEntitlementsService; -import org.opengroup.osdu.core.common.model.core.entitlements.*; +import org.opengroup.osdu.core.common.model.entitlements.*; +import org.opengroup.osdu.core.common.model.entitlements.MemberInfo; +import org.opengroup.osdu.core.common.model.entitlements.Members; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.entitlements.IEntitlementsService; import org.opengroup.osdu.core.aws.entitlements.*; -import org.opengroup.osdu.core.common.service.core.HttpResponse; -import org.opengroup.osdu.core.common.service.coreis.JaxRsDpsLog; -import org.opengroup.osdu.core.common.model.coreis.AppException; +import org.opengroup.osdu.core.common.http.HttpResponse; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.springframework.context.annotation.Lazy; import org.springframework.http.HttpStatus; import sun.reflect.generics.reflectiveObjects.NotImplementedException; diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/di/TenantFactoryImpl.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/di/TenantFactoryImpl.java deleted file mode 100644 index 15f07588070366c556c574b590c18db4e516e59e..0000000000000000000000000000000000000000 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/di/TenantFactoryImpl.java +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright © Amazon Web Services -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.opengroup.osdu.indexer.aws.di; - -import org.opengroup.osdu.core.common.model.core.ICache; -import org.opengroup.osdu.core.common.model.core.ITenantFactory; -import org.opengroup.osdu.core.common.model.core.TenantInfo; -import org.springframework.stereotype.Component; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -@Component -public class TenantFactoryImpl implements ITenantFactory { - public static final String[] REGISTERED_TENANTS = new String[] {"common", "opendes"}; - private Map<String, TenantInfo> tenants; - - public TenantFactoryImpl() - { - this.tenants = new HashMap<>(); - for (String tenantName : REGISTERED_TENANTS) { - TenantInfo ti = new TenantInfo(); - ti.setName(tenantName); - this.tenants.put(tenantName, ti); - } - } - @Override - public boolean exists(String tenantName) { - return this.tenants.containsKey(tenantName); - } - - @Override - public TenantInfo getTenantInfo(String tenantName) { - return this.tenants.get(tenantName); } - - @Override - public Collection<TenantInfo> listTenantInfo() { - return this.tenants.values(); - } - - @Override - public <V> ICache<String, V> createCache(String s, String s1, int i, int i1, Class<V> aClass) { - return null; - } - - @Override - public void flushCache() { - - } -} diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/di/TenantInfoFactory.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/di/TenantInfoFactory.java deleted file mode 100644 index f6767fa96d53daf18e6268763444348baa4c4182..0000000000000000000000000000000000000000 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/di/TenantInfoFactory.java +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright © Amazon Web Services -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.opengroup.osdu.indexer.aws.di; - -import lombok.extern.java.Log; -import org.opengroup.osdu.core.common.model.core.DpsHeaders; -import org.opengroup.osdu.core.common.model.core.ITenantFactory; -import org.opengroup.osdu.core.common.model.core.TenantInfo; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.beans.factory.config.AbstractFactoryBean; -import org.springframework.stereotype.Component; -import org.springframework.web.context.annotation.RequestScope; - -@Log -@Component -@RequestScope -public class TenantInfoFactory extends AbstractFactoryBean<TenantInfo> { - @Autowired - private ITenantFactory tenantFactory; - @Autowired - @Qualifier("dpsHeaderFactorySearch") - private DpsHeaders headers; - @Override - protected TenantInfo createInstance() throws Exception { - String id = this.headers.getPartitionIdWithFallbackToAccountId(); - return this.tenantFactory.getTenantInfo(id); - } - @Override - public Class<?> getObjectType() { - return TenantInfo.class; - } -} diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/persistence/ElasticRepositoryImpl.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/persistence/ElasticRepositoryImpl.java index 97f727d2e1995ee558a66a807767ac0d4166f4c9..22b0d8f5c5ca21fc079d1409889d9c5f2673f269 100644 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/persistence/ElasticRepositoryImpl.java +++ b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/persistence/ElasticRepositoryImpl.java @@ -14,14 +14,14 @@ package org.opengroup.osdu.indexer.aws.persistence; -import org.opengroup.osdu.core.common.model.core.ClusterSettings; -import org.opengroup.osdu.core.common.model.core.TenantInfo; -import org.opengroup.osdu.core.common.spi.coreis.ElasticRepository; +import org.opengroup.osdu.core.common.model.search.ClusterSettings; +import org.opengroup.osdu.core.common.model.tenant.TenantInfo; +import org.opengroup.osdu.core.common.provider.interfaces.IElasticRepository; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component -public class ElasticRepositoryImpl implements ElasticRepository { +public class ElasticRepositoryImpl implements IElasticRepository { // TODO: Will need to be implemented later diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/publish/PublisherImpl.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/publish/PublisherImpl.java index 273fb5d19a1c0988f891bafd2bd92671095e3492..c2efd5c7e235efec8719edabd21ccf64d7bd7613 100644 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/publish/PublisherImpl.java +++ b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/publish/PublisherImpl.java @@ -17,10 +17,10 @@ package org.opengroup.osdu.indexer.aws.publish; import com.amazonaws.services.sns.model.MessageAttributeValue; import com.amazonaws.services.sns.model.PublishRequest; import com.amazonaws.services.sns.AmazonSNS; -import org.opengroup.osdu.core.common.model.core.DpsHeaders; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.aws.sns.AmazonSNSConfig; import org.opengroup.osdu.core.aws.sns.PublishRequestBuilder; -import org.opengroup.osdu.core.common.spi.indexer.IPublisher; +import org.opengroup.osdu.indexer.provider.interfaces.IPublisher; import org.opengroup.osdu.core.common.model.indexer.JobStatus; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/service/ElasticClientHandlerAws.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/service/ElasticClientHandlerAws.java index c84bfe61798c7be957769f4a347040fb0eedc0ab..6a2498d0b89e2e85d9dd676039284605cf177fa4 100644 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/service/ElasticClientHandlerAws.java +++ b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/service/ElasticClientHandlerAws.java @@ -22,7 +22,7 @@ import org.apache.http.HttpRequestInterceptor; import org.elasticsearch.client.RestClient; import org.elasticsearch.client.RestHighLevelClient; import org.opengroup.osdu.core.aws.iam.IAMConfig; -import org.opengroup.osdu.is.core.util.ElasticClientHandler; +import org.opengroup.osdu.indexer.util.ElasticClientHandler; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Component; diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/HeadersInfoAwsImpl.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/HeadersInfoAwsImpl.java deleted file mode 100644 index 6ee989889f040a03d9371e87597c46429b88e1d9..0000000000000000000000000000000000000000 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/HeadersInfoAwsImpl.java +++ /dev/null @@ -1,124 +0,0 @@ -// Copyright © Amazon Web Services -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.opengroup.osdu.indexer.aws.util; - -import lombok.extern.java.Log; -import org.apache.http.HttpStatus; -import org.opengroup.osdu.core.common.model.core.DpsHeaders; -import org.opengroup.osdu.core.common.model.coreis.AppException; -import org.opengroup.osdu.core.common.model.coreis.SlbHeaders; -import org.opengroup.osdu.core.common.spi.coreis.IHeadersInfo; -import org.opengroup.osdu.core.common.service.coreis.Preconditions; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.context.annotation.Primary; -import org.springframework.stereotype.Component; - -import javax.inject.Inject; -import java.util.HashSet; -import java.util.Map; -import java.util.stream.Collectors; - -@Primary -@Log -@Component -public class HeadersInfoAwsImpl implements IHeadersInfo { - - @Inject - @Qualifier("dpsHeaderFactorySearch") - private DpsHeaders headersMap; - - - private static final HashSet<String> FORBIDDEN_FROM_LOGGING = new HashSet<>(); - static { - FORBIDDEN_FROM_LOGGING.add(DpsHeaders.AUTHORIZATION); - FORBIDDEN_FROM_LOGGING.add(DpsHeaders.ON_BEHALF_OF); - } - - /** - * Get list of current headers - * @return DpsHeaders headers - */ - @Override - public DpsHeaders getHeaders() { - if (headersMap == null) { - log.warning("Headers Map DpsHeaders is null"); - // throw to prevent null reference exception below - throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Invalid Headers", "Headers Map DpsHeaders is null"); - } - DpsHeaders headers = this.getCoreServiceHeaders(headersMap.getHeaders()); - return headers; - } - - /** - * get current logged in user - * @return userEmail - */ - @Override - public String getUser() { - // TODO: This class is going to be deprecated soon so this whole class will go away. Additionally there shouldn't be a user email attached to the request because this is a message from storage. - return "user"; - } - - /** - * get partition id and fallback to account id - * @return Partition ID - */ - @Override - public String getPartitionId() { - return getHeaders().getPartitionIdWithFallbackToAccountId(); - } - - /** - * get the primary partition id - * @return primaryPartitionID - */ - @Override - public String getPrimaryPartitionId() { - return getHeadersMap().get(SlbHeaders.PRIMARY_PARTITION_ID); - } - - /** - * get map of the current headers - * @return Map<String, String> headers - */ - @Override - public Map<String, String> getHeadersMap() { - return getHeaders().getHeaders(); - } - - /** - * supplement the DPSHeaders with any specific core service headers - * @param input Map<String, String> of core headers - * @return DpsHeaders dpsHeaders - */ - @Override - public DpsHeaders getCoreServiceHeaders(Map<String, String> input) { - Preconditions.checkNotNull(input, "input headers cannot be null"); - - DpsHeaders output = DpsHeaders.createFromMap(input); - - return output; - } - - /** - * create string representing a comma delimited list of the current headers - * @return - */ - @Override - public String toString() { - return this.getHeadersMap().entrySet().stream().filter(map -> !FORBIDDEN_FROM_LOGGING.contains(map.getKey().toLowerCase())).map(Map.Entry::toString).collect(Collectors.joining(" | ")); - } - -} \ No newline at end of file diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/IndexerQueueTaskBuilderAws.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/IndexerQueueTaskBuilderAws.java index c7f0eb4edf857339b2872bee6c52b832d0ee92aa..76607c97a21bd574e3f4f59d0b1f477c1543e799 100644 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/IndexerQueueTaskBuilderAws.java +++ b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/IndexerQueueTaskBuilderAws.java @@ -16,7 +16,7 @@ package org.opengroup.osdu.indexer.aws.util; import com.amazonaws.services.sqs.AmazonSQS; import com.amazonaws.services.sqs.model.SendMessageRequest; -import org.opengroup.osdu.core.common.model.core.DpsHeaders; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.aws.sqs.AmazonSQSConfig; import org.opengroup.osdu.indexer.util.IndexerQueueTaskBuilder; import org.springframework.beans.factory.annotation.Value; diff --git a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/RequestInfoImpl.java b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/RequestInfoImpl.java index 9baf2c4a4845cf8ecfc1f6a042b83eed40914028..8471336a90549dd5c0d74af9b0603f39507bf0bb 100644 --- a/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/RequestInfoImpl.java +++ b/provider/indexer-aws/src/main/java/org/opengroup/osdu/indexer/aws/util/RequestInfoImpl.java @@ -16,11 +16,10 @@ package org.opengroup.osdu.indexer.aws.util; import lombok.extern.java.Log; import org.apache.http.HttpStatus; -import org.opengroup.osdu.core.common.model.core.DpsHeaders; -import org.opengroup.osdu.core.common.model.coreis.AppException; -import org.opengroup.osdu.core.common.spi.coreis.IRequestInfo; -import org.opengroup.osdu.core.common.service.coreis.Preconditions; -import org.springframework.beans.factory.annotation.Qualifier; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; +import org.opengroup.osdu.core.common.search.Preconditions; import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Component; @@ -35,7 +34,6 @@ import java.util.Map; public class RequestInfoImpl implements IRequestInfo { @Inject - @Qualifier("dpsHeaderFactorySearch") private DpsHeaders headersMap; diff --git a/provider/indexer-aws/src/main/resources/application.properties b/provider/indexer-aws/src/main/resources/application.properties index 7d9bfebe0d61ac3aa6cb31d7c1d751de156b5022..44abedf4c31cc3779ea932d5ccb02c6047ba277b 100644 --- a/provider/indexer-aws/src/main/resources/application.properties +++ b/provider/indexer-aws/src/main/resources/application.properties @@ -1,3 +1,5 @@ +LOG_PREFIX=indexer + server.servlet.contextPath=/api/indexer/v2/ logging.level.org.springframework.web=DEBUG server.port=${APPLICATION_PORT} @@ -37,7 +39,8 @@ spring.security.user.roles=service.storage.admin # AWS ES configuration -aws.es.host=https://search-${ENVIRONMENT}-osdu-indexer-i5bpf2gv4iv6ha2xi7rook2rga.${AWS_REGION}.es.amazonaws.com +#aws.es.host=https://search-${ENVIRONMENT}-osdu-indexer-i5bpf2gv4iv6ha2xi7rook2rga.${AWS_REGION}.es.amazonaws.com +aws.es.host=https://search-dev-ado-test-y5m2xdyqha2npp36kh42vl3n7m.us-east-1.es.amazonaws.com aws.es.port=-1 aws.es.userNameAndPassword=notused aws.region=${AWS_REGION} @@ -49,9 +52,12 @@ aws.es.serviceName=es GAE_SERVICE=indexer -STORAGE_SCHEMA_HOST=http://ECSALB-os-storage-1575155422.${AWS_REGION}.elb.amazonaws.com/api/storage/v2/schemas -STORAGE_QUERY_RECORD_HOST=http://ECSALB-os-storage-1575155422.${AWS_REGION}.elb.amazonaws.com/api/storage/v2/query/records -STORAGE_QUERY_RECORD_FOR_CONVERSION_HOST=http://ECSALB-os-storage-1575155422.${AWS_REGION}.elb.amazonaws.com/api/storage/v2/query/records:batch +#STORAGE_SCHEMA_HOST=http://ECSALB-os-storage-1575155422.${AWS_REGION}.elb.amazonaws.com/api/storage/v2/schemas +STORAGE_SCHEMA_HOST=http://localhost:8080/api/storage/v2/schemas +#STORAGE_QUERY_RECORD_HOST=http://ECSALB-os-storage-1575155422.${AWS_REGION}.elb.amazonaws.com/api/storage/v2/query/records +STORAGE_QUERY_RECORD_HOST=http://localhost:8080/api/storage/v2/query/records +#STORAGE_QUERY_RECORD_FOR_CONVERSION_HOST=http://ECSALB-os-storage-1575155422.${AWS_REGION}.elb.amazonaws.com/api/storage/v2/query/records:batch +STORAGE_QUERY_RECORD_FOR_CONVERSION_HOST=http://localhost:8080/api/storage/v2/query/records:batch STORAGE_RECORDS_BATCH_SIZE=20 INDEXER_QUEUE_HOST=http://sqs.${AWS_REGION}.amazonaws.com/${AWS_ACCOUNT_ID}/${ENVIRONMENT}-osdu-indexer-queue diff --git a/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/publish/PublisherImplTest.java b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/publish/PublisherImplTest.java index 08fb01e57ade05e967943db33bf92a32c1648908..79ef1356aa94e2462eeb189578589a7bfbbfd69b 100644 --- a/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/publish/PublisherImplTest.java +++ b/provider/indexer-aws/src/test/java/org/opengroup/osdu/indexer/aws/publish/PublisherImplTest.java @@ -23,7 +23,7 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.opengroup.osdu.core.common.model.core.DpsHeaders; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.core.aws.sns.PublishRequestBuilder; import org.opengroup.osdu.indexer.aws.IndexerAwsApplication; import org.opengroup.osdu.core.common.model.indexer.JobStatus; diff --git a/provider/indexer-azure/README.md b/provider/indexer-azure/README.md new file mode 100644 index 0000000000000000000000000000000000000000..ad4d4624a06a940142e6950e047321ed87508e04 --- /dev/null +++ b/provider/indexer-azure/README.md @@ -0,0 +1,22 @@ +# Indexer-azure + +This document is a WIP, but it is intended to describe the steps needed to run this service both locally and in Azure. + +## Environment Configuration + +TODO: + +## Environment Configuration - Local Execution + +Due to the usage of [Managed Identity](https://docs.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/overview), you will need the following environment variables defined for running the azure implementation locally: + +| variable name | value | +| --- | --- | +| `AZURE_CLIENT_ID` | service principal's app id | +| `AZURE_TENANT_ID` | id of the principal's Azure Active Directory tenant | +| `AZURE_CLIENT_SECRET` | one of the service principal's client secrets | + +## Deploying service to Azure + +Service deployments into Azure are standardized to make the process the same for all services. The steps to deploy into +Azure can be [found here](https://dev.azure.com/slb-des-ext-collaboration/open-data-ecosystem/_git/infrastructure-templates?path=%2Fdocs%2Fosdu%2FSERVICE_DEPLOYMENTS.md&_a=preview) diff --git a/provider/indexer-azure/azure-build.yml b/provider/indexer-azure/azure-build.yml index 705d5f2168a7f1c6a077d21d9c69066ed673f303..cd450529e24fa04c77f2134580f25a8153d66d06 100644 --- a/provider/indexer-azure/azure-build.yml +++ b/provider/indexer-azure/azure-build.yml @@ -13,7 +13,7 @@ trigger: - .gitignore pool: - name: Hosted Ubuntu 1604 + name: dps-build demands: maven steps: @@ -21,7 +21,7 @@ steps: displayName: 'build, test, code coverage' inputs: mavenPomFile: 'pom.xml' - options: '--settings ./indexer-core/maven/settings.xml -DVSTS_FEED_TOKEN=$(VSTS_FEED_TOKEN)' + options: '--settings ./indexer-core/maven/settings.xml -DVSTS_FEED_TOKEN=$(VSTS_FEED_TOKEN) -U' testResultsFiles: '**/*/TEST-*.xml' codeCoverageToolOption: JaCoCo goals: 'install' @@ -30,7 +30,7 @@ steps: displayName: 'build, test, code coverage' inputs: mavenPomFile: 'pom.xml' - options: '--settings ./provider/indexer-azure/maven/settings.xml -DVSTS_FEED_TOKEN=$(VSTS_FEED_TOKEN) -P indexer-azure' + options: '--settings ./provider/indexer-azure/maven/settings.xml -DVSTS_FEED_TOKEN=$(VSTS_FEED_TOKEN) -U -P indexer-azure' testResultsFiles: '**/*/TEST-*.xml' codeCoverageToolOption: JaCoCo goals: 'package' @@ -45,7 +45,15 @@ steps: provider/indexer-azure/pom.xml provider/indexer-azure/target/*-spring-boot.jar TargetFolder: '$(build.artifactstagingdirectory)' - + +- task: ArchiveFiles@2 + inputs: + rootFolderOrFile: 'testing' + includeRootFolder: true + archiveType: 'zip' + archiveFile: '$(Build.ArtifactStagingDirectory)/indexer-integration-tests.zip' + replaceExistingArchive: true + - task: PublishBuildArtifacts@1 displayName: 'Publish Artifact: drop' inputs: diff --git a/provider/indexer-azure/maven/settings.xml b/provider/indexer-azure/maven/settings.xml index 85547897876a71f8b963ec61a0a051345c923a6a..d1af8b94a57f11b702675b23a2e5c8555bd73aed 100644 --- a/provider/indexer-azure/maven/settings.xml +++ b/provider/indexer-azure/maven/settings.xml @@ -19,6 +19,13 @@ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd"> <servers> + <server> + <id>os-core</id> + <username>slb-des-ext-collaboration</username> + <!-- Treat this auth token like a password. Do not share it with anyone, including Microsoft support. --> + <!-- The generated token expires on or before 11/14/2019 --> + <password>${VSTS_FEED_TOKEN}</password> + </server> <server> <id>azure-auth</id> <configuration> diff --git a/provider/indexer-azure/pom.xml b/provider/indexer-azure/pom.xml index 0b772197c89968a512b4235b3efce1c6113174f9..28e85745f44368b3246f81683e73f217a1c99640 100644 --- a/provider/indexer-azure/pom.xml +++ b/provider/indexer-azure/pom.xml @@ -23,12 +23,12 @@ <parent> <groupId>org.opengroup.osdu.indexer</groupId> <artifactId>indexer-service</artifactId> - <version>1.0.0</version> - <relativePath>../../pom.xml</relativePath> + <version>1.0.4-SNAPSHOT</version> + <relativePath>../..</relativePath> </parent> <artifactId>indexer-azure</artifactId> - <version>1.0.0-SNAPSHOT</version> + <version>1.0.4-SNAPSHOT</version> <name>indexer-azure</name> <description>Indexer Service Azure</description> <packaging>jar</packaging> @@ -71,18 +71,13 @@ <artifactId>spring-security-oauth2-jose</artifactId> </dependency> <dependency> - <groupId>com.microsoft.azure</groupId> - <artifactId>azure-cosmosdb-spring-boot-starter</artifactId> - <version>${azure.version}</version> - </dependency> - <dependency> - <groupId>com.microsoft.azure</groupId> - <artifactId>azure-storage-spring-boot-starter</artifactId> - <version>${azure.version}</version> + <groupId>org.springframework.boot</groupId> + <artifactId>spring-boot-configuration-processor</artifactId> + <optional>true</optional> </dependency> <dependency> <groupId>com.microsoft.azure</groupId> - <artifactId>azure-servicebus-spring-boot-starter</artifactId> + <artifactId>azure-cosmosdb-spring-boot-starter</artifactId> <version>${azure.version}</version> </dependency> <dependency> @@ -90,11 +85,21 @@ <artifactId>applicationinsights-logging-logback</artifactId> <version>[2.0,)</version> </dependency> - + <dependency> + <groupId>org.opengroup.osdu</groupId> + <artifactId>os-core-common</artifactId> + <version>0.0.12</version> + </dependency> <dependency> <groupId>org.opengroup.osdu.indexer</groupId> <artifactId>indexer-core</artifactId> - <version>1.0.0</version> + <version>1.0.4-SNAPSHOT</version> + </dependency> + + <dependency> + <groupId>org.opengroup.osdu</groupId> + <artifactId>core-lib-azure</artifactId> + <version>0.0.8</version> </dependency> <dependency> @@ -225,7 +230,7 @@ <useSystemClassLoader>false</useSystemClassLoader> <threadCount>1</threadCount> </configuration> - </plugin> + </plugin> </plugins> </build> diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/IndexerAzureApplication.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/IndexerAzureApplication.java index 487568dec3f716ae3e765252a63a14ec8b54875c..51886b1357c66e14699d82955c757203da00eba0 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/IndexerAzureApplication.java +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/IndexerAzureApplication.java @@ -14,13 +14,24 @@ package org.opengroup.osdu.indexer.azure; +import org.opengroup.osdu.indexer.IndexerApplication; +import org.opengroup.osdu.indexer.ServerletInitializer; +import org.opengroup.osdu.indexer.service.ElasticSettingServiceImpl; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.FilterType; + @SpringBootApplication -@ComponentScan({"org.opengroup.osdu.is.core", "org.opengroup.osdu.indexer"}) +@ComponentScan( + basePackages = {"org.opengroup.osdu"}, + excludeFilters = { + @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value=IndexerApplication.class), + @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value=ServerletInitializer.class), + @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value=ElasticSettingServiceImpl.class), + } +) public class IndexerAzureApplication { public static void main(String[] args) { diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/api/AADController.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/api/AADController.java deleted file mode 100644 index 22e44cef3531af417ba2b9084f87bdf09e9ad691..0000000000000000000000000000000000000000 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/api/AADController.java +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright © Microsoft Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.opengroup.osdu.indexer.azure.api; - -import org.opengroup.osdu.indexer.azure.util.ServiceAccountJwtClientImpl; - -import org.springframework.http.*; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; - -import javax.inject.Inject; - -@Controller -public class AADController { - - @Inject - ServiceAccountJwtClientImpl service; - - - @RequestMapping("/obo_api") - @PostMapping - public ResponseEntity<String> callOboApi() throws Throwable { - - String token = service.getIdToken("common"); - - return new ResponseEntity<String>(token, HttpStatus.OK); - } -} - diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/AttributesCache.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/AttributesCache.java index e6c987b6879d9cf1f46f555f5c7e1105be45cb36..056f48bcb284395f07796960f5237176e01ae0dd 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/AttributesCache.java +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/AttributesCache.java @@ -14,8 +14,8 @@ package org.opengroup.osdu.indexer.azure.cache; -import org.opengroup.osdu.core.cache.VmCache; -import org.opengroup.osdu.is.core.provider.interfaces.cache.IAttributesCache; +import org.opengroup.osdu.core.common.cache.VmCache; +import org.opengroup.osdu.core.common.provider.interfaces.IAttributesCache; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -52,4 +52,4 @@ public class AttributesCache implements IAttributesCache<String,Set> { this.cache.clearAll(); } -} \ No newline at end of file +} diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/CosmosDBSchemaCache.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/CosmosDBSchemaCache.java index 39415f12ed48758d2ecf29b08c429bfb1112711d..29e46611e868819a57913736a1c62f1def6de353 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/CosmosDBSchemaCache.java +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/CosmosDBSchemaCache.java @@ -15,8 +15,8 @@ package org.opengroup.osdu.indexer.azure.cache; -import org.opengroup.osdu.core.api.storage.models.Schema; -import org.opengroup.osdu.core.cache.VmCache; +import org.opengroup.osdu.core.common.cache.VmCache; +import org.opengroup.osdu.core.common.model.storage.Schema; import org.springframework.stereotype.Component; @Component diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/IndexCache.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/IndexCache.java index cefbe0e85ddc0515c538e888201bfac973404c14..dd33ae348a9566b2bc977a3fa99dfefd046268f2 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/IndexCache.java +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/IndexCache.java @@ -1,7 +1,7 @@ package org.opengroup.osdu.indexer.azure.cache; -import org.opengroup.osdu.core.cache.VmCache; -import org.opengroup.osdu.is.core.provider.interfaces.cache.IIndexCache; +import org.opengroup.osdu.core.common.cache.VmCache; +import org.opengroup.osdu.core.common.provider.interfaces.IIndexCache; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/JwtCache.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/JwtCache.java index 2fb2b0bfb42e9cf887bd8afcdf8d731dd4139ae8..cf807c8b250597516a32b5f2a997fc493e01dea7 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/JwtCache.java +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/JwtCache.java @@ -1,8 +1,8 @@ package org.opengroup.osdu.indexer.azure.cache; -import org.opengroup.osdu.core.cache.VmCache; -import org.opengroup.osdu.is.core.model.IdToken; -import org.opengroup.osdu.is.core.provider.interfaces.cache.IJwtCache; +import org.opengroup.osdu.core.common.cache.VmCache; +import org.opengroup.osdu.core.common.model.search.IdToken; +import org.opengroup.osdu.core.common.provider.interfaces.IJwtCache; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/KindsCache.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/KindsCache.java index a8ec2f8e395033ccd749d072889de7f3f2d1f3d0..8cd6c3a9342bfddcf70bafb815230613bfa40dfa 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/KindsCache.java +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/KindsCache.java @@ -1,7 +1,7 @@ package org.opengroup.osdu.indexer.azure.cache; -import org.opengroup.osdu.core.cache.VmCache; -import org.opengroup.osdu.is.core.provider.interfaces.cache.IKindsCache; +import org.opengroup.osdu.core.common.cache.VmCache; +import org.opengroup.osdu.core.common.provider.interfaces.IKindsCache; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/SchemaCache.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/SchemaCache.java index f662ccec3ec3f4ef61cae82561cdebbe2453576d..99d5f3f1fe36b3d2f591db677564dbf8da041f94 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/SchemaCache.java +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/cache/SchemaCache.java @@ -1,6 +1,6 @@ package org.opengroup.osdu.indexer.azure.cache; -import org.opengroup.osdu.core.cache.VmCache; +import org.opengroup.osdu.core.common.cache.VmCache; import org.opengroup.osdu.indexer.provider.interfaces.ISchemaCache; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/config/AzureBootstrapConfig.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/config/AzureBootstrapConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..cf4c6f56562704ba92531f4cce07cd2f8a0ffb48 --- /dev/null +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/config/AzureBootstrapConfig.java @@ -0,0 +1,90 @@ +package org.opengroup.osdu.indexer.azure.config; + +import com.azure.security.keyvault.secrets.SecretClient; +import org.opengroup.osdu.azure.KeyVaultFacade; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.stereotype.Component; + +import javax.inject.Named; + +@Component +public class AzureBootstrapConfig { + + @Value("${aad.oboApi}") + private String aadOboAPI; + + @Value("${azure.keyvault.url}") + private String keyVaultURL; + + @Value("${azure.servicebus.topic-name}") + private String serviceBusTopicName; + + @Value("${azure.servicebus.namespace-name}") + private String serviceBusNamespaceName; + + @Value("${ELASTIC_CACHE_EXPIRATION}") + private Integer elasticCacheExpiration; + + @Value("${MAX_CACHE_VALUE_SIZE}") + private Integer maxCacheValueSize; + + @Bean + @Named("KEY_VAULT_URL") + public String getKeyVaultURL(){ + return keyVaultURL; + } + + @Bean + @Named("SERVICE_BUS_NAMESPACE") + public String serviceBusNamespaceName() { + return serviceBusNamespaceName; + } + + @Bean + @Named("SERVICE_BUS_TOPIC") + public String serviceBusTopicName() { + return serviceBusTopicName; + } + + @Bean + @Named("ELASTIC_CACHE_EXPIRATION") + public Integer getElasticCacheExpiration() { + return elasticCacheExpiration; + } + + @Bean + @Named("MAX_CACHE_VALUE_SIZE") + public Integer getMaxCacheValueSize() { + return maxCacheValueSize; + } + + private String authority; + private String secretKey; + + @Bean + @Named("AAD_OBO_API") + public String aadClientID() { + return aadOboAPI; + } + + @Bean + @Named("AUTH_CLIENT_ID") + public String authClientID(final SecretClient sc) { + return KeyVaultFacade.getSecretWithValidation(sc, "app-dev-sp-username"); + } + + @Bean + @Named("AUTH_CLIENT_SECRET") + public String authClientSecret(final SecretClient sc) { + return KeyVaultFacade.getSecretWithValidation(sc, "app-dev-sp-password"); + } + + @Bean + @Named("AUTH_URL") + public String authURL(final SecretClient sc) { + String urlFormat = "https://login.microsoftonline.com/%s/oauth2/token/"; + String tenant = KeyVaultFacade.getSecretWithValidation(sc, "app-dev-sp-tenant-id"); + return String.format(urlFormat, tenant); + } +} diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/EntitlementsFactoryAzure.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/EntitlementsFactoryAzure.java index 0613ab8d8c59bbf3488ce090880881cdcc0ba956..63e268a87015d69021db40de5daac634c027bdea 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/EntitlementsFactoryAzure.java +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/EntitlementsFactoryAzure.java @@ -14,9 +14,9 @@ package org.opengroup.osdu.indexer.azure.di; -import org.opengroup.osdu.core.api.DpsHeaders; -import org.opengroup.osdu.core.api.entitlements.IEntitlementsFactory; -import org.opengroup.osdu.core.api.entitlements.IEntitlementsService; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.entitlements.IEntitlementsFactory; +import org.opengroup.osdu.core.common.entitlements.IEntitlementsService; import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Component; diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/EntitlementsServiceAzure.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/EntitlementsServiceAzure.java index 240dd0c915be69ae23538c5059dc626f84aebab8..05370bd83eed7eba1c519ad48570149fb06cab6b 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/EntitlementsServiceAzure.java +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/EntitlementsServiceAzure.java @@ -17,11 +17,10 @@ package org.opengroup.osdu.indexer.azure.di; import com.microsoft.azure.spring.autoconfigure.aad.UserPrincipal; import org.apache.http.HttpStatus; -import org.opengroup.osdu.core.api.DpsHeaders; -import org.opengroup.osdu.core.api.entitlements.EntitlementsException; -import org.opengroup.osdu.core.api.entitlements.IEntitlementsService; -import org.opengroup.osdu.core.api.entitlements.models.*; -import org.opengroup.osdu.core.httpclient.HttpResponse; +import org.opengroup.osdu.core.common.model.entitlements.*; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.entitlements.IEntitlementsService; +import org.opengroup.osdu.core.common.http.HttpResponse; import org.springframework.security.core.Authentication; import org.springframework.security.core.GrantedAuthority; import org.springframework.security.core.context.SecurityContextHolder; diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/TenantFactoryImpl.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/TenantFactoryImpl.java index 5c612fcd9b3ea64aab3119d653290a954e0adeb9..df488c799062c5590d025ee7913cf15ef9334551 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/TenantFactoryImpl.java +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/TenantFactoryImpl.java @@ -14,9 +14,9 @@ package org.opengroup.osdu.indexer.azure.di; -import org.opengroup.osdu.core.cache.ICache; -import org.opengroup.osdu.core.multitenancy.ITenantFactory; -import org.opengroup.osdu.core.multitenancy.TenantInfo; +import org.opengroup.osdu.core.common.cache.ICache; +import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory; +import org.opengroup.osdu.core.common.model.tenant.TenantInfo; import org.springframework.stereotype.Component; import org.springframework.web.context.annotation.RequestScope; diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/TenantInfoService.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/TenantInfoService.java new file mode 100644 index 0000000000000000000000000000000000000000..0cf37ded10b836dbc2824c9bef824d5e7c03b31b --- /dev/null +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/di/TenantInfoService.java @@ -0,0 +1,25 @@ +package org.opengroup.osdu.indexer.azure.di; + +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.tenant.TenantInfo; +import org.opengroup.osdu.core.common.multitenancy.ITenantInfoService; +import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory; +import org.springframework.stereotype.Component; +import org.springframework.web.context.annotation.RequestScope; + +import javax.inject.Inject; + +@RequestScope +@Component +public class TenantInfoService implements ITenantInfoService { + @Inject + private ITenantFactory tenantFactory; + + @Inject + private DpsHeaders headers; + + @Override + public TenantInfo getTenantInfo() { + return tenantFactory.getTenantInfo(headers.getPartitionId()); + } +} diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/model/ElasticSettingSchema.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/model/ElasticSettingSchema.java deleted file mode 100644 index 0351c0846a0f0addee7ee377ed2fe91dcfb2f867..0000000000000000000000000000000000000000 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/model/ElasticSettingSchema.java +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright © Microsoft Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.opengroup.osdu.indexer.azure.model; - -import javax.validation.constraints.NotEmpty; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@AllArgsConstructor -@NoArgsConstructor -public class ElasticSettingSchema { - - @NotEmpty - private String host; - - @NotEmpty - private String port; - - @NotEmpty - private String usernameAndPassword; - - @NotEmpty - private boolean isHttps; - -} diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/persistence/ElasticSettingSchemaRepositoryImpl.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/persistence/ElasticSettingSchemaRepositoryImpl.java deleted file mode 100644 index c826cb80029af30e247e1a3352fc928fb7e6bf3d..0000000000000000000000000000000000000000 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/persistence/ElasticSettingSchemaRepositoryImpl.java +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright © Microsoft Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.opengroup.osdu.indexer.azure.persistence; - -import org.opengroup.osdu.indexer.azure.model.ElasticSettingSchema; -import org.springframework.stereotype.Repository; - -import javax.inject.Inject; -import java.util.Optional; - -@Repository -public class ElasticSettingSchemaRepositoryImpl implements ISchemaRepository { - - @Inject - private CosmosDBElasticSettings db; - - @Override - public void add(ElasticSettingSchema schema, String id) { - ElasticSettingsDoc sd = new ElasticSettingsDoc(); - sd.setId(id); - sd.setSettingSchema(schema); - db.save(sd); - } - - @Override - public ElasticSettingSchema get(String id) { - Optional<ElasticSettingsDoc> sd = db.findById(id); - if (!sd.isPresent()) - return null; - - ElasticSettingSchema newSchema = new ElasticSettingSchema(); - newSchema.setPort(sd.get().getSettingSchema().getPort()); - newSchema.setHost(sd.get().getSettingSchema().getHost()); - newSchema.setUsernameAndPassword(sd.get().getSettingSchema().getUsernameAndPassword()); - newSchema.setHttps(sd.get().getSettingSchema().isHttps()); - return newSchema; - } -} diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/persistence/ElasticSettingsDoc.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/persistence/ElasticSettingsDoc.java deleted file mode 100644 index 991384daca31c8bb3220c655ae8bbf0a583abed9..0000000000000000000000000000000000000000 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/persistence/ElasticSettingsDoc.java +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright © Microsoft Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.opengroup.osdu.indexer.azure.persistence; - -import com.microsoft.azure.spring.data.cosmosdb.core.mapping.Document; -import com.microsoft.azure.spring.data.cosmosdb.core.mapping.PartitionKey; -import com.microsoft.azure.spring.data.cosmosdb.repository.DocumentDbRepository; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.opengroup.osdu.indexer.azure.model.ElasticSettingSchema; -import org.springframework.data.annotation.Id; - -@Data -@AllArgsConstructor -@NoArgsConstructor -@Document(collection = "SearchSettings") //collection name -public class ElasticSettingsDoc { - @PartitionKey - @Id - private String id; - private ElasticSettingSchema settingSchema; -} - -interface CosmosDBElasticSettings extends DocumentDbRepository<ElasticSettingsDoc, String> {} diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/persistence/ISchemaRepository.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/persistence/ISchemaRepository.java deleted file mode 100644 index 92f62ec357ea74deb4b79bdadc37ed6550e2cd21..0000000000000000000000000000000000000000 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/persistence/ISchemaRepository.java +++ /dev/null @@ -1,30 +0,0 @@ - -// Copyright © Microsoft Corporation -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.opengroup.osdu.indexer.azure.persistence; - -import org.opengroup.osdu.indexer.azure.model.ElasticSettingSchema; - -public interface ISchemaRepository { - String SCHEMA_KIND = "IndexerSchema"; - - String SCHEMA = "schema"; - String KIND = "KIND"; - - void add(ElasticSettingSchema schema, String id); - - ElasticSettingSchema get(String id); -} - diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/publish/PublisherImpl.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/publish/PublisherImpl.java index 8ee551f0c4bff4f63146c6dea89f1a448789c4ef..df62b28e50ef387ded9edcff3af72ace3a727470 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/publish/PublisherImpl.java +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/publish/PublisherImpl.java @@ -24,12 +24,12 @@ import com.microsoft.azure.servicebus.Message; import com.microsoft.azure.servicebus.TopicClient; import org.elasticsearch.common.Strings; -import org.opengroup.osdu.core.api.DpsHeaders; -import org.opengroup.osdu.indexer.model.RecordStatus; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.indexer.JobStatus; +import org.opengroup.osdu.core.common.model.indexer.RecordStatus; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.indexer.provider.interfaces.IPublisher; -import org.opengroup.osdu.indexer.util.JobStatus; -import org.opengroup.osdu.is.core.logging.JaxRsDpsLog; -import org.opengroup.osdu.is.core.model.RecordChangedMessages; +import org.opengroup.osdu.core.common.model.search.RecordChangedMessages; import org.springframework.stereotype.Component; import org.springframework.web.context.annotation.RequestScope; diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/security/BasicAuthSecurityConfig.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/security/AADSecurityConfig.java similarity index 94% rename from provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/security/BasicAuthSecurityConfig.java rename to provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/security/AADSecurityConfig.java index 6cc8d7cab61185cde1abfeb649ef22ff2e54de92..d5eaffce1490db1093fa9668b24b546a7da94cd3 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/security/BasicAuthSecurityConfig.java +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/security/AADSecurityConfig.java @@ -26,7 +26,7 @@ import javax.inject.Inject; @EnableWebSecurity @EnableGlobalMethodSecurity(prePostEnabled = true) -public class BasicAuthSecurityConfig extends WebSecurityConfigurerAdapter { +public class AADSecurityConfig extends WebSecurityConfigurerAdapter { @Inject private AADAppRoleStatelessAuthenticationFilter appRoleAuthFilter; @@ -35,7 +35,7 @@ public class BasicAuthSecurityConfig extends WebSecurityConfigurerAdapter { http.csrf().disable().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.NEVER) .and() .authorizeRequests() - .antMatchers("/", "/index.html","/obo_api", + .antMatchers("/", "/index.html", "/index-worker", "/_dps/task-handlers", "/_dps/task-handlers/**", "/reindex", "/v2/api-docs", diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/util/DpsHeadersAzureQueue.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/util/DpsHeadersAzureQueue.java new file mode 100644 index 0000000000000000000000000000000000000000..9bab4cec8aaf529b9039fb2beb9e0ecbaee6c0e6 --- /dev/null +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/util/DpsHeadersAzureQueue.java @@ -0,0 +1,43 @@ +package org.opengroup.osdu.indexer.azure.util; + +import java.util.Collections; +import java.util.Map; +import java.util.stream.Collectors; + +import javax.servlet.http.HttpServletRequest; +import javax.inject.Inject; + +import org.opengroup.osdu.core.common.model.http.DpsHeaders; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Component; +import org.springframework.web.context.annotation.RequestScope; + +@Component +@RequestScope +@Primary +public class DpsHeadersAzureQueue extends DpsHeaders { + + @Value("${indexer.queue.key}") + private String queueKey; + + //ToDo this should be moved to Azure client-lib + public static final String INDEXER_QUEUE_KEY = "x-functions-key"; + + @Inject + public DpsHeadersAzureQueue(HttpServletRequest request) { + + Map<String, String> headers = Collections + .list(request.getHeaderNames()) + .stream() + .collect(Collectors.toMap(h -> h, request::getHeader)); + + headers.put(INDEXER_QUEUE_KEY,queueKey); + + this.addFromMap(headers); + + // Add Correlation ID if missing + this.addCorrelationIdIfMissing(); + } +} diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/util/RequestInfoImpl.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/util/RequestInfoImpl.java index 9888e5f570d0526343f74aa4ca317421df196672..11dc1340220e413f32d8af2e7d6e28dfa322dd57 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/util/RequestInfoImpl.java +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/util/RequestInfoImpl.java @@ -16,13 +16,12 @@ package org.opengroup.osdu.indexer.azure.util; import com.google.common.base.Strings; import org.apache.http.HttpStatus; -import org.opengroup.osdu.core.api.DpsHeaders; -import org.opengroup.osdu.core.multitenancy.TenantInfo; -import org.opengroup.osdu.is.core.model.DeploymentEnvironment; -import org.opengroup.osdu.is.core.provider.interfaces.util.IHeadersInfo; -import org.opengroup.osdu.is.core.provider.interfaces.util.IRequestInfo; -import org.opengroup.osdu.is.core.provider.interfaces.util.IServiceAccountJwtClient; -import org.opengroup.osdu.is.core.util.AppException; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.tenant.TenantInfo; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.model.search.DeploymentEnvironment; +import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; +import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.web.context.annotation.RequestScope; @@ -30,8 +29,8 @@ import org.springframework.web.context.annotation.RequestScope; import javax.inject.Inject; import java.util.Map; -import static org.opengroup.osdu.core.api.DpsHeaders.AUTHORIZATION; -import static org.opengroup.osdu.indexer.azure.util.HeadersInfoAzureImpl.INDEXER_QUEUE_KEY; +import static org.opengroup.osdu.core.common.model.http.DpsHeaders.AUTHORIZATION; +import static org.opengroup.osdu.indexer.azure.util.DpsHeadersAzureQueue.INDEXER_QUEUE_KEY; @Component @@ -41,8 +40,6 @@ public class RequestInfoImpl implements IRequestInfo { @Inject private DpsHeaders dpsHeaders; - @Inject - private IHeadersInfo headersInfo; @Inject private IServiceAccountJwtClient serviceAccountJwtClient; @@ -56,17 +53,17 @@ public class RequestInfoImpl implements IRequestInfo { @Override public DpsHeaders getHeaders() { - return this.headersInfo.getHeaders(); + return this.dpsHeaders; } @Override public String getPartitionId() { - return this.headersInfo.getPartitionId(); + return this.dpsHeaders.getPartitionId(); } @Override public Map<String, String> getHeadersMap() { - return this.headersInfo.getHeadersMap(); + return this.dpsHeaders.getHeaders(); } @Override @@ -77,7 +74,7 @@ public class RequestInfoImpl implements IRequestInfo { @Override public DpsHeaders getHeadersWithDwdAuthZ() { this.dpsHeaders.put(AUTHORIZATION, this.checkOrGetAuthorizationHeader()); - return this.headersInfo.getHeaders(); + return this.dpsHeaders; } @Override @@ -85,7 +82,7 @@ public class RequestInfoImpl implements IRequestInfo { @Override public boolean isTaskQueueRequest() { - if (!this.headersInfo.getHeadersMap().containsKey(INDEXER_QUEUE_KEY)) return false; + if (!this.dpsHeaders.getHeaders().containsKey(INDEXER_QUEUE_KEY)) return false; // String queueId = this.headersInfo.getHeadersMap().get(AppEngineHeaders.TASK_QUEUE_NAME); // return queueId.endsWith(Constants.INDEXER_QUEUE_IDENTIFIER); @@ -94,7 +91,7 @@ public class RequestInfoImpl implements IRequestInfo { public String checkOrGetAuthorizationHeader() { if (DeploymentEnvironment.valueOf(DEPLOYMENT_ENVIRONMENT) == DeploymentEnvironment.LOCAL) { - String authHeader = this.headersInfo.getHeaders().getAuthorization(); + String authHeader = this.dpsHeaders.getAuthorization(); if (Strings.isNullOrEmpty(authHeader)) { throw new AppException(HttpStatus.SC_UNAUTHORIZED, "Invalid authorization header", "Authorization token cannot be empty"); } diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/util/ServiceAccountJwtClientImpl.java b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/util/ServiceAccountJwtClientImpl.java index 0930596b5cbb14ab2069c9c3d9de4c2539580353..202dd483b059254566f8cc3b971e678934f6db94 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/util/ServiceAccountJwtClientImpl.java +++ b/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/util/ServiceAccountJwtClientImpl.java @@ -20,23 +20,20 @@ import com.microsoft.aad.adal4j.AuthenticationContext; import com.microsoft.aad.adal4j.AuthenticationResult; import com.microsoft.aad.adal4j.ClientCredential; import org.apache.http.HttpStatus; -import org.opengroup.osdu.core.api.DpsHeaders; -import org.opengroup.osdu.core.multitenancy.ITenantFactory; -import org.opengroup.osdu.core.multitenancy.TenantInfo; -import org.opengroup.osdu.indexer.azure.model.AADConfiguration; - -import org.opengroup.osdu.is.core.logging.JaxRsDpsLog; -import org.opengroup.osdu.is.core.model.IdToken; -import org.opengroup.osdu.is.core.provider.interfaces.cache.IJwtCache; -import org.opengroup.osdu.is.core.provider.interfaces.util.IHeadersInfo; -import org.opengroup.osdu.is.core.provider.interfaces.util.IServiceAccountJwtClient; -import org.opengroup.osdu.is.core.util.AppException; + +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.search.IdToken; +import org.opengroup.osdu.core.common.model.tenant.TenantInfo; +import org.opengroup.osdu.core.common.provider.interfaces.IJwtCache; +import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory; +import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient; import org.springframework.stereotype.Component; import org.springframework.web.context.annotation.RequestScope; import javax.inject.Inject; -import java.net.MalformedURLException; -import java.util.concurrent.ExecutionException; +import javax.inject.Named; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; @@ -47,17 +44,31 @@ public class ServiceAccountJwtClientImpl implements IServiceAccountJwtClient { @Inject private ITenantFactory tenantInfoServiceProvider; - @Inject - private IHeadersInfo headersInfoAzure; + @Inject private DpsHeaders dpsHeaders; + @Inject private IJwtCache cacheService; + @Inject private JaxRsDpsLog log; @Inject - private AADConfiguration configuration; + @Named("AAD_OBO_API") + private String authAPI; + + @Inject + @Named("AUTH_CLIENT_ID") + private String authClientID; + + @Inject + @Named("AUTH_CLIENT_SECRET") + private String authClientSecret; + + @Inject + @Named("AUTH_URL") + private String authURL; public String getIdToken(String tenantName) { this.log.info("Tenant name received for auth token is: " + tenantName); @@ -70,7 +81,6 @@ public class ServiceAccountJwtClientImpl implements IServiceAccountJwtClient { try { IdToken cachedToken = (IdToken) this.cacheService.get(tenant.getServiceAccount()); - this.headersInfoAzure.getHeaders().put(DpsHeaders.USER_EMAIL, tenant.getServiceAccount()); this.dpsHeaders.put(DpsHeaders.USER_EMAIL, tenant.getServiceAccount()); if (!IdToken.refreshToken(cachedToken)) { @@ -81,9 +91,9 @@ public class ServiceAccountJwtClientImpl implements IServiceAccountJwtClient { AuthenticationContext context = null; try { - context = new AuthenticationContext(configuration.getAuthority(), false, service); - ClientCredential credential = new ClientCredential(configuration.getClientId(), configuration.getSecretKey()); - Future<AuthenticationResult> future = context.acquireToken(configuration.getOboApi(), credential, null); + context = new AuthenticationContext(authURL, false, service); + ClientCredential credential = new ClientCredential(authClientID, authClientSecret); + Future<AuthenticationResult> future = context.acquireToken(authAPI, credential, null); ACCESS_TOKEN = future.get().getAccessToken(); @@ -97,10 +107,6 @@ public class ServiceAccountJwtClientImpl implements IServiceAccountJwtClient { } catch (InterruptedException e) { e.printStackTrace(); - } catch (ExecutionException e) { - e.printStackTrace(); - } catch (MalformedURLException e) { - e.printStackTrace(); } finally { service.shutdown(); } diff --git a/provider/indexer-azure/src/main/resources/application.properties b/provider/indexer-azure/src/main/resources/application.properties index a79e32ddcde40517593b25bcef9d90b778ce2c65..071854026a8258d18e035c26db2b3281ade72a48 100644 --- a/provider/indexer-azure/src/main/resources/application.properties +++ b/provider/indexer-azure/src/main/resources/application.properties @@ -1,86 +1,53 @@ -#server.servlet.contextPath=/api/indexer/v2/ -logging.level.org.springframework.web=DEBUG -server.port=8080 -JAVA_HEAP_OPTS=-Xms4096M -Xmx4096M -JAVA_GC_OPTS=-XX:+UseG1GC -XX:+UseStringDeduplication -XX:InitiatingHeapOccupancyPercent=45 - +LOG_PREFIX=indexer +REGION=centralus +logging.level.org.opendes.osdu=DEBUG +JAVA_OPTS=-Dserver.port=80 DEFAULT_DATA_COUNTRY=US -AUTHORIZE_API=https://opendesproxy.azurewebsites.net/entitlements/v1 -AUTHORIZE_API_KEY=dummy -LEGALTAG_API=https://opendesproxy.azurewebsites.net/legal/v1 -LEGALTAG_API_KEY=dummy -CRS_API=https://opendesproxy.azurewebsites.net/crs/v1 -CRS_API_KEY=dummy +AUTHORIZE_API=${entitlements_service_endpoint} +AUTHORIZE_API_KEY=${entitlements_service_api_key} +LEGALTAG_API=${legal_service_endpoint} + -#Default Cache Settings SCHEMA_CACHE_EXPIRATION=60 INDEX_CACHE_EXPIRATION=60 ELASTIC_CACHE_EXPIRATION=1440 CURSOR_CACHE_EXPIRATION=60 -# Kinds Cache expiration 2*24*60 KINDS_CACHE_EXPIRATION=2880 -# Attributes Cache expiration 2*24*60 ATTRIBUTES_CACHE_EXPIRATION=2880 -# Maximum size of cache value MAX_CACHE_VALUE_SIZE=1000 - KINDS_REDIS_DATABASE=1 CRON_INDEX_CLEANUP_THRESHOLD_DAYS=3 CRON_EMPTY_INDEX_CLEANUP_THRESHOLD_DAYS=7 -STORAGE_SCHEMA_HOST=https://opendesmvp.azurewebsites.net/schemas -STORAGE_QUERY_RECORD_HOST=https://opendesmvp.azurewebsites.net/query/records -STORAGE_QUERY_RECORD_FOR_CONVERSION_HOST=https://opendesmvp.azurewebsites.net/query/records:batch +storage_service_url=${storage_service_endpoint} +STORAGE_SCHEMA_HOST=${storage_service_url}/schemas +STORAGE_QUERY_RECORD_HOST=${storage_service_url}/query/records +STORAGE_QUERY_RECORD_FOR_CONVERSION_HOST=${storage_service_url}/query/records:batch STORAGE_RECORDS_BATCH_SIZE=20 -INDEXER_QUEUE_HOST=https://requeuefunction-cd1.azurewebsites.net/api/re-enqueue - -#MSAL AAD -aad.authority=https://login.microsoftonline.com/1668106e-2ae0-456a-bb7d-64b52104db99/oauth2/token -aad.clientId=b70451c6-936f-4430-8680-0985817ac751 -aad.secretKey=b5GZtbS.bB7iSzLTb+Nb-AOb9G@1@LZo -aad.oboApi=api://ffb32b1a-c6fe-4ed0-819b-6ca483de3640 - -spring.security.oauth2.client.registration.azure.client-id=b70451c6-936f-4430-8680-0985817ac751 -spring.security.oauth2.client.registration.azure.client-secret=b5GZtbS.bB7iSzLTb+Nb-AOb9G@1@LZo -spring.security.oauth2.client.registration.azure.client-name=Azure - +INDEXER_QUEUE_HOST=http://127.0.0.1:9000 -#spring.security.user.name=opendes@byoc.local -#spring.security.user.password=123 -#spring.security.user.roles=service.indexer.admin - - -# Azure AD configuration -azure.activedirectory.client-id=ffb32b1a-c6fe-4ed0-819b-6ca483de3640 -azure.activedirectory.tenant-id=1668106e-2ae0-456a-bb7d-64b52104db99 -azure.activedirectory.AppIdUri=api://${azure.activedirectory.client-id} +#AzureADconfiguration azure.activedirectory.session-stateless=true +azure.activedirectory.client-id=${aad_client_id} -#azure.activedirectory.active-directory-groups=ADMIN, VIEWER - -# Azure CosmosDB configuration -azure.cosmosdb.uri=https://opendescosmosdb.documents.azure.com:443/ -azure.cosmosdb.key=AQK0VbnMGn76h9Ypw5aoirKMwoAYJBRY2XENn1dAYypoea83weVyjYcGaRDeEX7HqXIVggaDuFAhQ4Y1Y9lKDQ== -azure.cosmosdb.database=opendesdb +azure.cosmosdb.uri=${cosmosdb_account} +azure.cosmosdb.key=${cosmosdb_key} +azure.cosmosdb.database=${cosmosdb_database} - -# Azure Service Bus configuration -azure.servicebus.connection-string=Endpoint=sb://pliuopendes.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=km8Nscc0gf299Ck6npmM3D14VU5Tx1lJYRdlHcExIvY= -azure.servicebus.topic-name=recordstopic +#AzureServiceBusconfiguration +azure.servicebus.namespace-name=${servicebus_namespace_name} +azure.servicebus.topic-name=${servicebus_topic_name} #Indexer-Queue-header indexer.queue.key=abcd - -REDIS_GROUP_HOST=127.0.0.1 -REDIS_GROUP_PORT=6379 REDIS_SEARCH_HOST=localhost REDIS_SEARCH_PORT=6379 -ELASTIC_DATASTORE_KIND=SearchSettings -ELASTIC_DATASTORE_ID=indexer-service - -GAE_SERVICE=indexer +azure.keyvault.url=${KEYVAULT_URI} +azure.application-insights.instrumentation-key=${appinsights_key} +spring.application.name=indexer-azure -DEPLOYMENT_ENVIRONMENT=CLOUD \ No newline at end of file +DEPLOYMENT_ENVIRONMENT=CLOUD +aad.oboApi=${aad_client_id} diff --git a/provider/indexer-azure/src/main/resources/logback-spring.xml b/provider/indexer-azure/src/main/resources/logback-spring.xml deleted file mode 100644 index b6cddae16a051d94a1813eff31295b33f9eefd1d..0000000000000000000000000000000000000000 --- a/provider/indexer-azure/src/main/resources/logback-spring.xml +++ /dev/null @@ -1,42 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<!-- - Copyright © Microsoft Corporation - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. - --> - -<configuration> - - <appender name="Console" - class="ch.qos.logback.core.ConsoleAppender"> - <layout class="ch.qos.logback.classic.PatternLayout"> - <Pattern> - %black(%d{ISO8601}) %highlight(%-5level) [%blue(%t)] %yellow(%C{1.}): %msg%n%throwable - </Pattern> - </layout> - </appender> - - <appender name="aiAppender" - class="com.microsoft.applicationinsights.logback.ApplicationInsightsAppender"> - <instrumentationKey>${appinsights_key}</instrumentationKey> - </appender> - - <!-- servicebus throws exceptions when idle --> - <logger name="com.microsoft.azure.servicebus.primitives.RequestResponseLink" level="error" /> - - <root level="warn"> - <appender-ref ref="Console" /> - <appender-ref ref="aiAppender" /> - </root> - -</configuration> \ No newline at end of file diff --git a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/CronServiceImplTest.java b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/CronServiceImplTest.java index aa4d4ef1eace8733d2d309490cdf8d16a2d89c78..5adda93b22a3f00d30f12d7b4617a6776342615b 100644 --- a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/CronServiceImplTest.java +++ b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/CronServiceImplTest.java @@ -22,14 +22,14 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.opengroup.osdu.core.api.DpsHeaders; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.indexer.service.CronServiceImpl; -import org.opengroup.osdu.is.core.logging.JaxRsDpsLog; -import org.opengroup.osdu.is.core.model.IndexInfo; -import org.opengroup.osdu.is.core.provider.interfaces.util.IRequestInfo; -import org.opengroup.osdu.is.core.service.IndicesService; -import org.opengroup.osdu.is.core.util.Config; -import org.opengroup.osdu.is.core.util.ElasticClientHandler; +import org.opengroup.osdu.core.common.model.search.IndexInfo; +import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; +import org.opengroup.osdu.core.common.search.IndicesService; +import org.opengroup.osdu.core.common.search.Config; +import org.opengroup.osdu.indexer.util.ElasticClientHandler; import org.powermock.core.classloader.annotations.PrepareForTest; import org.springframework.test.context.junit4.SpringRunner; @@ -138,4 +138,4 @@ public class CronServiceImplTest { verify(this.indicesService, times(0)).deleteIndex(any(), any()); } -} \ No newline at end of file +} diff --git a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/IndexCopyServiceImplTest.java b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/IndexCopyServiceImplTest.java index 9a6e46baad5957a2db5141ebf17e4465029b27c3..e03a77601ca1297aa4cf73cd6022da094ef5c6e2 100644 --- a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/IndexCopyServiceImplTest.java +++ b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/IndexCopyServiceImplTest.java @@ -30,18 +30,17 @@ import org.junit.runner.RunWith; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.opengroup.osdu.core.api.DpsHeaders; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; import org.opengroup.osdu.indexer.logging.AuditLogger; import org.opengroup.osdu.indexer.service.IndexCopyServiceImpl; import org.opengroup.osdu.indexer.service.IndexerMappingService; -import org.opengroup.osdu.is.core.model.ClusterSettings; -import org.opengroup.osdu.is.core.provider.interfaces.util.IHeadersInfo; -import org.opengroup.osdu.is.core.provider.interfaces.util.IRequestInfo; -import org.opengroup.osdu.is.core.service.ElasticSettingService; -import org.opengroup.osdu.is.core.service.IndicesService; -import org.opengroup.osdu.is.core.util.AppException; -import org.opengroup.osdu.is.core.util.ElasticClientHandler; -import org.opengroup.osdu.is.core.util.ElasticIndexNameResolver; +import org.opengroup.osdu.core.common.model.search.ClusterSettings; +import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; +import org.opengroup.osdu.core.common.model.indexer.IElasticSettingService; +import org.opengroup.osdu.core.common.search.IndicesService; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.indexer.util.ElasticClientHandler; +import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; import org.powermock.core.classloader.annotations.PrepareForTest; import org.springframework.test.context.junit4.SpringRunner; @@ -67,7 +66,7 @@ public class IndexCopyServiceImplTest { @Mock private IRequestInfo requestInfo; @Mock - private IHeadersInfo headersInfo; + private DpsHeaders dpsHeaders; @Mock private RestClient restClient; @Mock @@ -83,7 +82,7 @@ public class IndexCopyServiceImplTest { @Mock private Response response; @Mock - private ElasticSettingService elasticSettingService; + private IElasticSettingService elasticSettingService; @Mock private AuditLogger auditLogger; @Mock @@ -103,8 +102,6 @@ public class IndexCopyServiceImplTest { httpHeaders = new HashMap<>(); httpHeaders.put(DpsHeaders.AUTHORIZATION, "testAuth"); httpHeaders.put(DpsHeaders.CORRELATION_ID, correlationId); - DpsHeaders standardHeaders = DpsHeaders.createFromMap(httpHeaders); - when(headersInfo.getHeaders()).thenReturn(standardHeaders); when(requestInfo.getHeadersMapWithDwdAuthZ()).thenReturn(httpHeaders); when(response.getEntity()).thenReturn(httpEntity); diff --git a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/IndexerMappingServiceTest.java b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/IndexerMappingServiceTest.java index b2febfb7fbc8c3e46cfe98ddc079a370fd1e5d04..1d73eff3283c3f53684852cb189423116dc06709 100644 --- a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/IndexerMappingServiceTest.java +++ b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/IndexerMappingServiceTest.java @@ -34,9 +34,9 @@ import org.mockito.InjectMocks; import org.mockito.Mock; import org.opengroup.osdu.indexer.model.IndexSchema; import org.opengroup.osdu.indexer.service.IndexerMappingServiceImpl; -import org.opengroup.osdu.is.core.model.RecordMetaAttribute; -import org.opengroup.osdu.is.core.util.AppException; -import org.opengroup.osdu.is.core.util.ElasticClientHandler; +import org.opengroup.osdu.core.common.model.search.RecordMetaAttribute; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.indexer.util.ElasticClientHandler; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.springframework.test.context.junit4.SpringRunner; @@ -168,7 +168,7 @@ public class IndexerMappingServiceTest { doReturn(response).when(this.restHighLevelClient).updateByQuery(ArgumentMatchers.any(), ArgumentMatchers.any(RequestOptions.class)); when(response.getBulkFailures()).thenReturn(new ArrayList<Failure>()); when(elasticClientHandler.createRestClient()).thenReturn(restHighLevelClient); - + this.sut.updateIndexMappingForIndicesOfSameType( indices,"any field"); } catch (Exception e) { fail("Should not throw this exception" + e.getMessage()); @@ -202,8 +202,8 @@ public class IndexerMappingServiceTest { doReturn(response).when(this.restHighLevelClient).updateByQuery(ArgumentMatchers.any(), ArgumentMatchers.any(RequestOptions.class)); when(response.getBulkFailures()).thenReturn(new ArrayList<Failure>()); when(elasticClientHandler.createRestClient()).thenReturn(restHighLevelClient); - - this.sut.updateIndexMappingForIndicesOfSameType(indices,"any field"); + + this.sut.updateIndexMappingForIndicesOfSameType(indices,"any field"); } catch (Exception e) { throw e; } @@ -213,7 +213,7 @@ public class IndexerMappingServiceTest { public void should_throw_exception_if_type_of_index_is_invalid_andWeIndexfield_with_keyword() throws Exception { try { Set<String> indices = new HashSet<String>(); - indices.add("indices 1"); + indices.add("indices 1"); GetFieldMappingsResponse getFieldMappingsResponse = mock(GetFieldMappingsResponse.class); doReturn(this.indicesClient).when(this.restHighLevelClient).indices(); when(this.indicesClient.getFieldMapping(ArgumentMatchers.any(), ArgumentMatchers.any())).thenReturn(getFieldMappingsResponse); diff --git a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/IndexerSchemaServiceTest.java b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/IndexerSchemaServiceTest.java index d006594c690548f26e89e36e0c51b84dd4215e4a..9961c312f01e4ab7695546afc5f881fd3e15624b 100644 --- a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/IndexerSchemaServiceTest.java +++ b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/IndexerSchemaServiceTest.java @@ -23,18 +23,18 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.opengroup.osdu.indexer.model.IndexSchema; -import org.opengroup.osdu.indexer.model.OperationType; +import org.opengroup.osdu.core.common.model.indexer.IndexSchema; +import org.opengroup.osdu.core.common.model.indexer.OperationType; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.indexer.provider.interfaces.ISchemaCache; import org.opengroup.osdu.indexer.service.IndexSchemaServiceImpl; import org.opengroup.osdu.indexer.service.IndexerMappingService; import org.opengroup.osdu.indexer.service.StorageService; -import org.opengroup.osdu.is.core.httpclient.RequestStatus; -import org.opengroup.osdu.is.core.logging.JaxRsDpsLog; -import org.opengroup.osdu.is.core.service.IndicesService; -import org.opengroup.osdu.is.core.util.AppException; -import org.opengroup.osdu.is.core.util.ElasticClientHandler; -import org.opengroup.osdu.is.core.util.ElasticIndexNameResolver; +import org.opengroup.osdu.core.common.model.http.RequestStatus; +import org.opengroup.osdu.core.common.search.IndicesService; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.indexer.util.ElasticClientHandler; +import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; import org.powermock.core.classloader.annotations.PrepareForTest; import org.springframework.test.context.junit4.SpringRunner; diff --git a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/ReindexServiceTest.java b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/ReindexServiceTest.java index 41fe0ab3414625bb684bf76044e2dc7d480d0f90..711a3e19ed996ffccb30631702f618f53da4210e 100644 --- a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/ReindexServiceTest.java +++ b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/ReindexServiceTest.java @@ -23,14 +23,14 @@ import org.junit.runner.RunWith; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.opengroup.osdu.core.api.DpsHeaders; -import org.opengroup.osdu.indexer.model.RecordQueryResponse; -import org.opengroup.osdu.indexer.model.RecordReindexRequest; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.indexer.RecordQueryResponse; +import org.opengroup.osdu.core.common.model.indexer.RecordReindexRequest; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.indexer.service.ReindexServiceImpl; import org.opengroup.osdu.indexer.service.StorageService; import org.opengroup.osdu.indexer.util.IndexerQueueTaskBuilder; -import org.opengroup.osdu.is.core.logging.JaxRsDpsLog; -import org.opengroup.osdu.is.core.provider.interfaces.util.IRequestInfo; +import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; import org.springframework.test.context.junit4.SpringRunner; import java.util.*; diff --git a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/StorageServiceTest.java b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/StorageServiceTest.java index 59ef0dacebccb21c96e1f17ac8d824fc5a34e2bb..aedf8960acca1ecf4d3807234d6c048dcaa8ff55 100644 --- a/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/StorageServiceTest.java +++ b/provider/indexer-azure/src/test/java/org/opengroup/osdu/indexer/azure/service/StorageServiceTest.java @@ -24,17 +24,17 @@ import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.opengroup.osdu.indexer.model.RecordQueryResponse; -import org.opengroup.osdu.indexer.model.RecordReindexRequest; -import org.opengroup.osdu.indexer.model.Records; +import org.opengroup.osdu.core.common.model.indexer.RecordInfo; +import org.opengroup.osdu.core.common.model.indexer.RecordQueryResponse; +import org.opengroup.osdu.core.common.model.indexer.RecordReindexRequest; +import org.opengroup.osdu.core.common.model.indexer.Records; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.indexer.service.StorageServiceImpl; -import org.opengroup.osdu.indexer.util.JobStatus; -import org.opengroup.osdu.indexer.util.RecordInfo; -import org.opengroup.osdu.is.core.httpclient.HttpResponse; -import org.opengroup.osdu.is.core.logging.JaxRsDpsLog; -import org.opengroup.osdu.is.core.provider.interfaces.util.IRequestInfo; -import org.opengroup.osdu.is.core.service.UrlFetchService; -import org.opengroup.osdu.is.core.util.AppException; +import org.opengroup.osdu.core.common.model.indexer.JobStatus; +import org.opengroup.osdu.core.common.model.http.HttpResponse; +import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; +import org.opengroup.osdu.core.common.http.IUrlFetchService; +import org.opengroup.osdu.core.common.model.http.AppException; import org.springframework.http.HttpStatus; import org.springframework.test.context.junit4.SpringRunner; @@ -54,7 +54,7 @@ import static org.powermock.api.mockito.PowerMockito.when; public class StorageServiceTest { @Mock - private UrlFetchService urlFetchService; + private IUrlFetchService urlFetchService; @Mock private JobStatus jobStatus; @Mock diff --git a/provider/indexer-gcp/azure-build.yml b/provider/indexer-gcp/azure-build.yml index d100317636cdb97d8fabdf458c40dd6f88d0e096..5e9afc90215791c3178ddecdbb3bec7d8be4f216 100644 --- a/provider/indexer-gcp/azure-build.yml +++ b/provider/indexer-gcp/azure-build.yml @@ -21,7 +21,7 @@ steps: displayName: 'build, test, code coverage' inputs: mavenPomFile: 'pom.xml' - options: '--settings ./indexer-core/maven/settings.xml -DVSTS_FEED_TOKEN=$(VSTS_FEED_TOKEN)' + options: '--settings ./indexer-core/maven/settings.xml -DVSTS_FEED_TOKEN=$(VSTS_FEED_TOKEN) -U' testResultsFiles: '**/*/TEST-*.xml' codeCoverageToolOption: JaCoCo goals: 'install' diff --git a/provider/indexer-gcp/pom.xml b/provider/indexer-gcp/pom.xml index 36ee494de4213a7d8bfde980a576a36c1cbdfffe..ca0533b05535fd6ca4a46f836fa1a8ba1d2ab4c8 100644 --- a/provider/indexer-gcp/pom.xml +++ b/provider/indexer-gcp/pom.xml @@ -7,11 +7,12 @@ <parent> <groupId>org.opengroup.osdu.indexer</groupId> <artifactId>indexer-service</artifactId> - <version>1.0.0</version> + <version>1.0.4-SNAPSHOT</version> + <relativePath>../../pom.xml</relativePath> </parent> <artifactId>indexer-gcp</artifactId> - <version>1.0.0</version> + <version>1.0.4-SNAPSHOT</version> <name>indexer-gcp</name> <description>Indexer Service GCP App Engine</description> <packaging>jar</packaging> @@ -31,19 +32,19 @@ <dependency> <groupId>org.opengroup.osdu.indexer</groupId> <artifactId>indexer-core</artifactId> - <version>1.0.0</version> + <version>1.0.4-SNAPSHOT</version> </dependency> <dependency> <groupId>org.opengroup.osdu</groupId> <artifactId>core-lib-gcp</artifactId> - <version>0.1.1</version> - <exclusions> - <exclusion> - <groupId>org.opengroup.osdu</groupId> - <artifactId>core-lib</artifactId> - </exclusion> - </exclusions> + <version>0.1.16</version> + </dependency> + + <dependency> + <groupId>org.opengroup.osdu</groupId> + <artifactId>os-core-common</artifactId> + <version>0.0.12</version> </dependency> <dependency> @@ -196,9 +197,9 @@ <useSystemClassLoader>false</useSystemClassLoader> <threadCount>1</threadCount> </configuration> - </plugin> + </plugin> </plugins> </build> -</project> \ No newline at end of file +</project> diff --git a/provider/indexer-gcp/scripts/deploy2gcp.sh.tmpl b/provider/indexer-gcp/scripts/deploy2gcp.sh.tmpl index e556aa11dd0dc02461cd2666fb7bb77cb2638b64..b3f5589121c6763544d3a2528b479a157bf5fd94 100644 --- a/provider/indexer-gcp/scripts/deploy2gcp.sh.tmpl +++ b/provider/indexer-gcp/scripts/deploy2gcp.sh.tmpl @@ -66,6 +66,11 @@ then echo "Replacing GOOGLE_CLOUD_PROJECT_PLACE_HOLDER with $PROJECT_ID" sed -i "s|GOOGLE_CLOUD_PROJECT_PLACE_HOLDER|$PROJECT_ID|g" app.yaml + sed -i -e "s|AUTHORIZE_API_VAR|$AUTHORIZE_API|g" app.yaml + sed -i -e "s|CRON_JOB_IP_VAR|$CRON_JOB_IP|g" app.yaml + sed -i -e "s|LEGAL_HOSTNAME_VAR|$LEGAL_HOSTNAME|g" app.yaml + sed -i -e "s|REGION_VAR|$REGION|g" app.yaml + sed -i -e "s|ENVIRONMENT|$ENVIRONMENT|g" app.yaml echo "Content of app.yaml:" cat app.yaml diff --git a/provider/indexer-gcp/src/main/appengine/app.yaml b/provider/indexer-gcp/src/main/appengine/app.yaml index 730fb9b3a7f858a87ea128206d7d48c434d3d078..dee4515740c38e195f4afeada8a4b66471a32833 100644 --- a/provider/indexer-gcp/src/main/appengine/app.yaml +++ b/provider/indexer-gcp/src/main/appengine/app.yaml @@ -34,3 +34,8 @@ handlers: env_variables: GOOGLE_CLOUD_PROJECT: "GOOGLE_CLOUD_PROJECT_PLACE_HOLDER" + AUTHORIZE_API: "AUTHORIZE_API_VAR" + CRON_JOB_IP: "CRON_JOB_IP_VAR" + LEGAL_HOSTNAME: "LEGAL_HOSTNAME_VAR" + REGION: "REGION_VAR" + SPRING_PROFILES_ACTIVE: 'ENVIRONMENT' diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/IndexerGcpApplication.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/IndexerGcpApplication.java index 7a3f9c21007c16a1b92e9cecac7bd0b108031996..f72e93440739667f6f7ad9a5694a39e32eedf4aa 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/IndexerGcpApplication.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/IndexerGcpApplication.java @@ -9,7 +9,7 @@ import org.springframework.context.annotation.Configuration; @SpringBootApplication(exclude = { SecurityAutoConfiguration.class, ManagementWebSecurityAutoConfiguration.class }) @Configuration -@ComponentScan({"org.opengroup.osdu.is.core", "org.opengroup.osdu.indexer"}) +@ComponentScan({"org.opengroup.osdu"}) public class IndexerGcpApplication { public static void main(String[] args) { diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/AttributesCache.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/AttributesCache.java index bebf28bdfd6b90d98137e3878f1f350ba5195f81..4f0383bd9ec812e6cf307353d07b1b8beedd79c4 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/AttributesCache.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/AttributesCache.java @@ -14,8 +14,8 @@ package org.opengroup.osdu.indexer.cache; -import org.opengroup.osdu.core.cache.RedisCache; -import org.opengroup.osdu.is.core.provider.interfaces.cache.IAttributesCache; +import org.opengroup.osdu.core.common.cache.RedisCache; +import org.opengroup.osdu.core.common.provider.interfaces.IAttributesCache; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import java.util.Set; @@ -57,4 +57,4 @@ public class AttributesCache implements IAttributesCache<String,Set>, AutoClosea public void close() { this.cache.close(); } -} \ No newline at end of file +} diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/DatastoreCredentialCache.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/DatastoreCredentialCache.java index 50a59a97ed8763bae9329bbf5c7a9c62d47fc9c1..5f780afbbaf2c1ab87b19c0c4812a63318c718ab 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/DatastoreCredentialCache.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/DatastoreCredentialCache.java @@ -15,7 +15,7 @@ package org.opengroup.osdu.indexer.cache; import com.google.auth.oauth2.AccessToken; -import org.opengroup.osdu.core.cache.RedisCache; +import org.opengroup.osdu.core.common.cache.RedisCache; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -26,4 +26,4 @@ public class DatastoreCredentialCache extends RedisCache<String, AccessToken> { public DatastoreCredentialCache(@Value("${REDIS_SEARCH_HOST}") final String REDIS_SEARCH_HOST, @Value("${REDIS_SEARCH_PORT}") final String REDIS_SEARCH_PORT) { super(REDIS_SEARCH_HOST, Integer.parseInt(REDIS_SEARCH_PORT), 58 * 60, String.class, AccessToken.class); } -} \ No newline at end of file +} diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/ElasticCredentialsCache.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/ElasticCredentialsCache.java index 9f517b8eed551bb989d001cdaa6e50ac8d6d7597..045b555c438d48bb44a700cda72c4f43df6332e0 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/ElasticCredentialsCache.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/ElasticCredentialsCache.java @@ -1,8 +1,8 @@ package org.opengroup.osdu.indexer.cache; -import org.opengroup.osdu.core.cache.RedisCache; -import org.opengroup.osdu.is.core.model.ClusterSettings; -import org.opengroup.osdu.is.core.provider.interfaces.cache.IElasticCredentialsCache; +import org.opengroup.osdu.core.common.cache.RedisCache; +import org.opengroup.osdu.core.common.model.search.ClusterSettings; +import org.opengroup.osdu.core.common.provider.interfaces.IElasticCredentialsCache; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/IndexCache.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/IndexCache.java index dbe09db285b3a00733c462e2383393e1bcbc0fbb..c923ecc42ffcb1ea34d9fd0b06fe835b5e478168 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/IndexCache.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/IndexCache.java @@ -1,7 +1,7 @@ package org.opengroup.osdu.indexer.cache; -import org.opengroup.osdu.core.cache.RedisCache; -import org.opengroup.osdu.is.core.provider.interfaces.cache.IIndexCache; +import org.opengroup.osdu.core.common.cache.RedisCache; +import org.opengroup.osdu.core.common.provider.interfaces.IIndexCache; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/JwtCache.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/JwtCache.java index 29b3b5e49b09398d2f082d984f2173964b20e464..3ae398125b9e5ffbbc859fdc319fbfa4faa0abed 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/JwtCache.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/JwtCache.java @@ -1,8 +1,8 @@ package org.opengroup.osdu.indexer.cache; -import org.opengroup.osdu.core.cache.RedisCache; -import org.opengroup.osdu.is.core.model.IdToken; -import org.opengroup.osdu.is.core.provider.interfaces.cache.IJwtCache; +import org.opengroup.osdu.core.common.cache.RedisCache; +import org.opengroup.osdu.core.common.model.search.IdToken; +import org.opengroup.osdu.core.common.provider.interfaces.IJwtCache; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/KindsCache.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/KindsCache.java index eacd8a8a7365d9c0bc0a88b62ce0a32bd90b8f08..68eb86f4afe07f05d478e43ad6cc78abb8386eba 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/KindsCache.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/KindsCache.java @@ -1,7 +1,7 @@ package org.opengroup.osdu.indexer.cache; -import org.opengroup.osdu.core.cache.RedisCache; -import org.opengroup.osdu.is.core.provider.interfaces.cache.IKindsCache; +import org.opengroup.osdu.core.common.cache.RedisCache; +import org.opengroup.osdu.core.common.provider.interfaces.IKindsCache; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/SchemaCache.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/SchemaCache.java index 396f70ae3c01215d2f7f34b7de567c1dd6343154..ef7ba72ab5cdcf0ead81c0d66bf1b5d39fcdad7f 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/SchemaCache.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/cache/SchemaCache.java @@ -1,6 +1,6 @@ package org.opengroup.osdu.indexer.cache; -import org.opengroup.osdu.core.cache.RedisCache; +import org.opengroup.osdu.core.common.cache.RedisCache; import org.opengroup.osdu.indexer.provider.interfaces.ISchemaCache; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/di/AppengineLogFactory.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/di/AppengineLogFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..00c9332200ec28900c968436483072d2e1d9725e --- /dev/null +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/di/AppengineLogFactory.java @@ -0,0 +1,27 @@ +package org.opengroup.osdu.indexer.di; + +import org.opengroup.osdu.core.common.logging.ILogger; +import org.opengroup.osdu.core.gcp.logging.logger.AppEngineLoggingProvider; + +import org.springframework.beans.factory.FactoryBean; +import org.springframework.context.annotation.Lazy; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Component; + +@Component +@Primary +@Lazy +public class AppengineLogFactory implements FactoryBean<ILogger> { + + private AppEngineLoggingProvider appEngineLoggingProvider = new AppEngineLoggingProvider(); + + @Override + public ILogger getObject() throws Exception { + return appEngineLoggingProvider.getLogger(); + } + + @Override + public Class<?> getObjectType() { + return ILogger.class; + } +} \ No newline at end of file diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/di/EntitlementsClientFactory.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/di/EntitlementsClientFactory.java new file mode 100644 index 0000000000000000000000000000000000000000..6630705facc5810952f23f2e29eca5eb3c6acfb0 --- /dev/null +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/di/EntitlementsClientFactory.java @@ -0,0 +1,51 @@ +// Copyright 2017-2019, Schlumberger +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.opengroup.osdu.indexer.di; + +import org.opengroup.osdu.core.common.entitlements.EntitlementsAPIConfig; +import org.opengroup.osdu.core.common.entitlements.EntitlementsFactory; +import org.opengroup.osdu.core.common.entitlements.IEntitlementsFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.beans.factory.config.AbstractFactoryBean; +import org.springframework.context.annotation.Lazy; +import org.springframework.stereotype.Component; +import org.springframework.web.context.annotation.RequestScope; + +@Component +@RequestScope +@Lazy +public class EntitlementsClientFactory extends AbstractFactoryBean<IEntitlementsFactory> { + + @Value("${AUTHORIZE_API}") + private String AUTHORIZE_API; + + @Value("${AUTHORIZE_API_KEY:}") + private String AUTHORIZE_API_KEY; + + @Override + protected IEntitlementsFactory createInstance() throws Exception { + + return new EntitlementsFactory(EntitlementsAPIConfig + .builder() + .rootUrl(AUTHORIZE_API) + .apiKey(AUTHORIZE_API_KEY) + .build()); + } + + @Override + public Class<?> getObjectType() { + return IEntitlementsFactory.class; + } +} \ No newline at end of file diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/di/TenantFactoryService.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/di/TenantFactoryService.java index 8fd00807fc5894810102b809efb041108364b6bf..cd27070db5fecde803d50e8aff083d5502573a9d 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/di/TenantFactoryService.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/di/TenantFactoryService.java @@ -15,6 +15,7 @@ package org.opengroup.osdu.indexer.di; import lombok.extern.java.Log; +import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory; import org.opengroup.osdu.core.gcp.multitenancy.TenantFactory; import org.opengroup.osdu.core.multitenancy.ITenantFactory; import org.springframework.beans.factory.config.AbstractFactoryBean; @@ -35,4 +36,4 @@ public class TenantFactoryService extends AbstractFactoryBean<ITenantFactory> { public Class<?> getObjectType() { return ITenantFactory.class; } -} \ No newline at end of file +} diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/kms/KmsClient.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/kms/KmsClient.java index 3bd6aaf103d69cf7bd78cccdffa9fc1b27845b1c..9e83a5df918e7625a09d6768a00d00f994980395 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/kms/KmsClient.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/kms/KmsClient.java @@ -25,8 +25,8 @@ import com.google.api.services.cloudkms.v1.model.DecryptRequest; import com.google.api.services.cloudkms.v1.model.DecryptResponse; import com.google.api.services.cloudkms.v1.model.EncryptRequest; import com.google.api.services.cloudkms.v1.model.EncryptResponse; -import org.opengroup.osdu.is.core.provider.interfaces.kms.IKmsClient; -import org.opengroup.osdu.is.core.util.Preconditions; +import org.opengroup.osdu.core.common.provider.interfaces.IKmsClient; +import org.opengroup.osdu.core.common.search.Preconditions; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.web.context.annotation.RequestScope; @@ -99,4 +99,4 @@ public class KmsClient implements IKmsClient { .setApplicationName("CloudKMS snippets") .build(); } -} \ No newline at end of file +} diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/middleware/IndexFilter.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/middleware/IndexFilter.java index 89ba9cc67345b53668da3cd78763b4ec667b59b6..1eeb928ff5e8888a0053df66a2e451e7880fabad 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/middleware/IndexFilter.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/middleware/IndexFilter.java @@ -3,11 +3,11 @@ package org.opengroup.osdu.indexer.middleware; import com.google.common.base.Strings; import lombok.extern.java.Log; import org.apache.http.HttpStatus; -import org.opengroup.osdu.core.api.DpsHeaders; -import org.opengroup.osdu.core.headers.ResponseHeaders; -import org.opengroup.osdu.is.core.model.DeploymentEnvironment; -import org.opengroup.osdu.is.core.provider.interfaces.util.IRequestInfo; -import org.opengroup.osdu.is.core.util.AppException; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.http.ResponseHeaders; +import org.opengroup.osdu.core.common.model.search.DeploymentEnvironment; +import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpMethod; import org.springframework.stereotype.Component; diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/persistence/DatastoreCredential.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/persistence/DatastoreCredential.java index d8e77402049c23c309d5e1fc2e383ca13e8319f9..0f41a697534a87a22476257265dad685377f41a1 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/persistence/DatastoreCredential.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/persistence/DatastoreCredential.java @@ -26,6 +26,8 @@ import com.google.auth.oauth2.AccessToken; import com.google.auth.oauth2.GoogleCredentials; import com.google.gson.JsonObject; import org.apache.commons.lang3.time.DateUtils; +import org.opengroup.osdu.core.common.model.tenant.TenantInfo; +import org.opengroup.osdu.core.common.util.Crc32c; import org.opengroup.osdu.indexer.cache.DatastoreCredentialCache; import org.opengroup.osdu.core.cryptographic.Crc32c; import org.opengroup.osdu.core.multitenancy.TenantInfo; @@ -106,4 +108,4 @@ public class DatastoreCredential extends GoogleCredentials { private String getCacheKey() { return Crc32c.hashToBase64EncodedString(String.format("datastoreCredential:%s", this.tenant.getName())); } -} \ No newline at end of file +} diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/persistence/DatastoreFactory.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/persistence/DatastoreFactory.java index 5cb5a9fdeee7fda7ca981179590e8a60cae783a2..6af2b84bce1fb2c35efa90feffa06479d2b5a186 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/persistence/DatastoreFactory.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/persistence/DatastoreFactory.java @@ -19,6 +19,7 @@ import com.google.cloud.TransportOptions; import com.google.cloud.datastore.Datastore; import com.google.cloud.datastore.DatastoreOptions; import com.google.cloud.http.HttpTransportOptions; +import org.opengroup.osdu.core.common.model.tenant.TenantInfo; import org.opengroup.osdu.indexer.cache.DatastoreCredentialCache; import org.opengroup.osdu.core.multitenancy.TenantInfo; import org.springframework.stereotype.Component; diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/persistence/ElasticRepositoryDatastore.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/persistence/ElasticRepositoryDatastore.java index acfbfb4c12065c6377628369b18e807028938627..eb40bb0c43e29cc8590d8ac38fd1b819372d51a7 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/persistence/ElasticRepositoryDatastore.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/persistence/ElasticRepositoryDatastore.java @@ -20,19 +20,19 @@ import com.google.cloud.datastore.Entity; import com.google.cloud.datastore.Key; import lombok.extern.java.Log; import org.apache.http.HttpStatus; -import org.opengroup.osdu.core.multitenancy.TenantInfo; -import org.opengroup.osdu.is.core.model.ClusterSettings; -import org.opengroup.osdu.is.core.provider.interfaces.kms.IKmsClient; -import org.opengroup.osdu.is.core.provider.interfaces.persistence.ElasticRepository; -import org.opengroup.osdu.is.core.util.AppException; -import org.opengroup.osdu.is.core.util.Preconditions; +import org.opengroup.osdu.core.common.model.search.ClusterSettings; +import org.opengroup.osdu.core.common.model.tenant.TenantInfo; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.provider.interfaces.IKmsClient; +import org.opengroup.osdu.core.common.provider.interfaces.IElasticRepository; +import org.opengroup.osdu.core.common.search.Preconditions; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import javax.inject.Inject; @Log @Component -public class ElasticRepositoryDatastore implements ElasticRepository { +public class ElasticRepositoryDatastore implements IElasticRepository { static final String HOST = "host"; static final String PORT = "port"; @@ -87,4 +87,4 @@ public class ElasticRepositoryDatastore implements ElasticRepository { throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Cluster setting fetch error", "An error has occurred fetching cluster settings from the datastore.", e); } } -} \ No newline at end of file +} diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/publish/PublisherImpl.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/publish/PublisherImpl.java index e66424a5d43db1d5beaec9a2aa54cbce2e616927..68dafca259fb3590d0747f1722839132c99335dc 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/publish/PublisherImpl.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/publish/PublisherImpl.java @@ -27,15 +27,15 @@ import lombok.extern.java.Log; import org.apache.http.HttpStatus; import org.elasticsearch.common.Strings; -import org.opengroup.osdu.indexer.model.RecordStatus; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory; +import org.opengroup.osdu.core.common.model.tenant.TenantInfo; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.model.indexer.JobStatus; +import org.opengroup.osdu.core.common.model.indexer.RecordStatus; import org.opengroup.osdu.indexer.provider.interfaces.IPublisher; -import org.opengroup.osdu.indexer.util.JobStatus; -import org.opengroup.osdu.core.api.DpsHeaders; import org.opengroup.osdu.core.gcp.PubSub.PubSubExtensions; -import org.opengroup.osdu.core.multitenancy.ITenantFactory; -import org.opengroup.osdu.core.multitenancy.TenantInfo; -import org.opengroup.osdu.is.core.model.DeploymentEnvironment; -import org.opengroup.osdu.is.core.util.AppException; +import org.opengroup.osdu.core.common.model.search.DeploymentEnvironment; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.web.context.annotation.RequestScope; @@ -140,4 +140,4 @@ public class PublisherImpl implements IPublisher { return publisher; } } -} \ No newline at end of file +} diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/util/DpsHeaderFactoryGcp.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/util/DpsHeaderFactoryGcp.java new file mode 100644 index 0000000000000000000000000000000000000000..28884453076f6ee465f876c9a014bdeda0da935b --- /dev/null +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/util/DpsHeaderFactoryGcp.java @@ -0,0 +1,57 @@ +// Copyright 2017-2019, Schlumberger +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.opengroup.osdu.indexer.util; + +import java.util.Collections; +import java.util.Map; +import java.util.stream.Collectors; + +import javax.servlet.http.HttpServletRequest; +import javax.inject.Inject; + +import com.google.common.base.Strings; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; + +import org.opengroup.osdu.core.gcp.model.AppEngineHeaders; +import org.opengroup.osdu.core.gcp.util.TraceIdExtractor; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Component; +import org.springframework.web.context.annotation.RequestScope; + +@Component +@RequestScope +@Primary +public class DpsHeaderFactoryGcp extends DpsHeaders { + + @Inject + public DpsHeaderFactoryGcp(HttpServletRequest request) { + + Map<String, String> headers = Collections + .list(request.getHeaderNames()) + .stream() + .collect(Collectors.toMap(h -> h, request::getHeader)); + + String traceContext = headers.get(AppEngineHeaders.CLOUD_TRACE_CONTEXT); + + if(!Strings.isNullOrEmpty(traceContext)){ + headers.put(AppEngineHeaders.TRACE_ID, TraceIdExtractor.getTraceId(traceContext)); + } + + this.addFromMap(headers); + + // Add Correlation ID if missing + this.addCorrelationIdIfMissing(); + } +} \ No newline at end of file diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/util/RequestInfoImpl.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/util/RequestInfoImpl.java index ca75dd2f72237c2a99d165d5b646fed5c9f8ff5d..2ad14667d9aa2e47876989d98ab124c79cc2c618 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/util/RequestInfoImpl.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/util/RequestInfoImpl.java @@ -3,15 +3,14 @@ package org.opengroup.osdu.indexer.util; import com.google.common.base.Strings; import lombok.extern.java.Log; import org.apache.http.HttpStatus; -import org.opengroup.osdu.core.api.DpsHeaders; +import org.opengroup.osdu.core.common.Constants; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.tenant.TenantInfo; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.model.search.DeploymentEnvironment; +import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient; import org.opengroup.osdu.core.gcp.model.AppEngineHeaders; -import org.opengroup.osdu.core.multitenancy.TenantInfo; -import org.opengroup.osdu.is.core.model.DeploymentEnvironment; -import org.opengroup.osdu.is.core.provider.interfaces.util.IHeadersInfo; -import org.opengroup.osdu.is.core.provider.interfaces.util.IRequestInfo; -import org.opengroup.osdu.is.core.provider.interfaces.util.IServiceAccountJwtClient; -import org.opengroup.osdu.is.core.util.AppException; -import org.opengroup.osdu.is.core.util.Constants; +import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.web.context.annotation.RequestScope; @@ -19,7 +18,7 @@ import org.springframework.web.context.annotation.RequestScope; import javax.inject.Inject; import java.util.Map; -import static org.opengroup.osdu.core.api.DpsHeaders.AUTHORIZATION; +import static org.opengroup.osdu.core.common.model.http.DpsHeaders.AUTHORIZATION; @Log @@ -30,8 +29,6 @@ public class RequestInfoImpl implements IRequestInfo { @Inject private DpsHeaders dpsHeaders; - @Inject - private IHeadersInfo headersInfo; @Inject private IServiceAccountJwtClient serviceAccountJwtClient; @@ -46,17 +43,17 @@ public class RequestInfoImpl implements IRequestInfo { @Override public DpsHeaders getHeaders() { - return this.headersInfo.getHeaders(); + return this.dpsHeaders; } @Override public String getPartitionId() { - return this.headersInfo.getPartitionId(); + return this.dpsHeaders.getPartitionId(); } @Override public Map<String, String> getHeadersMap() { - return this.headersInfo.getHeadersMap(); + return this.dpsHeaders.getHeaders(); } @Override @@ -68,20 +65,20 @@ public class RequestInfoImpl implements IRequestInfo { public DpsHeaders getHeadersWithDwdAuthZ() { // Update DpsHeaders so that service account creds are passed down this.dpsHeaders.put(AUTHORIZATION, this.checkOrGetAuthorizationHeader()); - return this.headersInfo.getHeaders(); + return this.dpsHeaders; } @Override public boolean isCronRequest() { - String appEngineCronHeader = this.headersInfo.getHeadersMap().getOrDefault(AppEngineHeaders.CRON_SERVICE, null); + String appEngineCronHeader = this.dpsHeaders.getHeaders().getOrDefault(AppEngineHeaders.CRON_SERVICE, null); return expectedCronHeaderValue.equalsIgnoreCase(appEngineCronHeader); } @Override public boolean isTaskQueueRequest() { - if (!this.headersInfo.getHeadersMap().containsKey(AppEngineHeaders.TASK_QUEUE_NAME)) return false; + if (!this.dpsHeaders.getHeaders().containsKey(AppEngineHeaders.TASK_QUEUE_NAME)) return false; - String queueId = this.headersInfo.getHeadersMap().get(AppEngineHeaders.TASK_QUEUE_NAME); + String queueId = this.dpsHeaders.getHeaders().get(AppEngineHeaders.TASK_QUEUE_NAME); return queueId.endsWith(Constants.INDEXER_QUEUE_IDENTIFIER); } diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/util/ServiceAccountJwtGcpClientImpl.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/util/ServiceAccountJwtGcpClientImpl.java index a953e6ce9a4ad069b379bbe916244cf432bbac67..fff6e78d0ec930ca03a4e2d6ec2326f7c84bb5ed 100644 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/util/ServiceAccountJwtGcpClientImpl.java +++ b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/util/ServiceAccountJwtGcpClientImpl.java @@ -38,14 +38,14 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils; -import org.opengroup.osdu.core.api.DpsHeaders; -import org.opengroup.osdu.core.multitenancy.ITenantFactory; -import org.opengroup.osdu.core.multitenancy.TenantInfo; -import org.opengroup.osdu.is.core.logging.JaxRsDpsLog; -import org.opengroup.osdu.is.core.model.IdToken; -import org.opengroup.osdu.is.core.provider.interfaces.cache.IJwtCache; -import org.opengroup.osdu.is.core.provider.interfaces.util.IServiceAccountJwtClient; -import org.opengroup.osdu.is.core.util.AppException; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.provider.interfaces.ITenantFactory; +import org.opengroup.osdu.core.common.model.tenant.TenantInfo; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.model.search.IdToken; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.provider.interfaces.IJwtCache; +import org.opengroup.osdu.core.common.util.IServiceAccountJwtClient; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import org.springframework.web.context.annotation.RequestScope; @@ -70,8 +70,6 @@ public class ServiceAccountJwtGcpClientImpl implements IServiceAccountJwtClient @Inject private ITenantFactory tenantInfoServiceProvider; @Inject - private HeadersInfoGcpImpl headersInfoGcp; - @Inject private IJwtCache cacheService; @Inject private JaxRsDpsLog log; @@ -94,7 +92,6 @@ public class ServiceAccountJwtGcpClientImpl implements IServiceAccountJwtClient try { IdToken cachedToken = (IdToken) this.cacheService.get(tenant.getServiceAccount()); - this.headersInfoGcp.getHeaders().put(DpsHeaders.USER_EMAIL, tenant.getServiceAccount()); // Add the user to DpsHeaders directly this.dpsHeaders.put(DpsHeaders.USER_EMAIL, tenant.getServiceAccount()); diff --git a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/util/TraceIdExtractor.java b/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/util/TraceIdExtractor.java deleted file mode 100644 index 64143bb2947c5d48b80d1d56976392d9810b6ed8..0000000000000000000000000000000000000000 --- a/provider/indexer-gcp/src/main/java/org/opengroup/osdu/indexer/util/TraceIdExtractor.java +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2017-2019, Schlumberger -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package org.opengroup.osdu.indexer.util; - -import com.google.common.base.Strings; -import org.opengroup.osdu.core.gcp.model.AppEngineHeaders; -import org.springframework.util.MultiValueMap; - -import java.util.Random; -import java.util.UUID; - -public class TraceIdExtractor { - - /* - * "X-Cloud-Trace-Context: TRACE_ID/SPAN_ID;o=TRACE_TRUE" e.g. 105445aa7843bc8bf206b120001000/0;o=1" - * https://cloud.google.com/trace/docs/support - * */ - public static String getTraceableCloudContext(MultiValueMap<String, String> requestHeaders) { - String traceContextHeader = requestHeaders.getFirst(AppEngineHeaders.CLOUD_TRACE_CONTEXT); - - // get new if not found - if (Strings.isNullOrEmpty(traceContextHeader)) return getNewTraceContext(); - // return as is - if (traceContextHeader.endsWith(";o=1")) return traceContextHeader; - - String[] traceParts = traceContextHeader.split("[/;]"); - // if there is only trace-id - if (traceParts.length == 1) return String.format("%s/%s;o=1", traceContextHeader, getNewSpanId()); - // if trace-id and span-id - if (traceParts.length == 2) return String.format("%s;o=1", traceContextHeader); - // trace flag is turned off - return String.format("%s/%s;o=1", traceParts[0], traceParts[1]); - } - - public static String getTraceId(String traceContextHeader) { - String[] traceParts = traceContextHeader.split("[/;]"); - return traceParts.length > 0 ? traceParts[0] : getNewTraceId(); - } - - private static String getNewTraceContext() { - return String.format("%s/%s;o=1", getNewTraceId(), getNewSpanId()); - } - - private static String getNewTraceId() { - return UUID.randomUUID().toString().replaceAll("-", ""); - } - - private static String getNewSpanId() { - return Integer.toUnsignedString(new Random().nextInt()); - } -} diff --git a/provider/indexer-gcp/src/main/resources/application-dev.properties b/provider/indexer-gcp/src/main/resources/application-dev.properties new file mode 100644 index 0000000000000000000000000000000000000000..61da3c7139e0f8e834b2ec5b90173b2c517d075d --- /dev/null +++ b/provider/indexer-gcp/src/main/resources/application-dev.properties @@ -0,0 +1,21 @@ +GOOGLE_CLOUD_PROJECT=opendes + +INDEXER_HOST=os-indexer-dot-opendes.appspot.com +STORAGE_HOSTNAME=os-storage-dot-opendes.appspot.com + +STORAGE_SCHEMA_HOST=https://os-storage-dot-opendes.appspot.com/api/storage/v2/schemas +STORAGE_QUERY_RECORD_HOST=https://os-storage-dot-opendes.appspot.com/api/storage/v2/query/records +STORAGE_QUERY_RECORD_FOR_CONVERSION_HOST=https://os-storage-dot-opendes.appspot.com/api/storage/v2/query/records:batch +STORAGE_RECORDS_BATCH_SIZE=20 + +INDEXER_QUEUE_HOST=https://os-indexer-queue-dot-opendes.appspot.com/_dps/task-handlers/enqueue + +AUTHORIZE_API=https://entitlements-dot-opendes.appspot.com/entitlements/v1 +LEGALTAG_API=https://os-legal-dot-opendes.appspot.com/api/legal/v1 +CRS_API=https://crs-converter-gae-dot-opendes.appspot.com/api/crs/v1 + +## use below values for gcp: opendes +REDIS_GROUP_HOST=10.0.16.28 +REDIS_SEARCH_HOST=10.0.16.20 + +GOOGLE_AUDIENCES=245464679631-ktfdfpl147m1mjpbutl00b3cmffissgq.apps.googleusercontent.com \ No newline at end of file diff --git a/provider/indexer-gcp/src/main/resources/application-testing.properties b/provider/indexer-gcp/src/main/resources/application-testing.properties new file mode 100644 index 0000000000000000000000000000000000000000..5368d291c5653bcf9bd31bfbc9c31af3765e9b1f --- /dev/null +++ b/provider/indexer-gcp/src/main/resources/application-testing.properties @@ -0,0 +1,21 @@ +GOOGLE_CLOUD_PROJECT=opendes-evt + +INDEXER_HOST=os-indexer-dot-opendes-evt.appspot.com +STORAGE_HOSTNAME=os-storage-dot-opendes-evt.appspot.com + +STORAGE_SCHEMA_HOST=https://os-storage-dot-opendes-evt.appspot.com/api/storage/v2/schemas +STORAGE_QUERY_RECORD_HOST=https://os-storage-dot-opendes-evt.appspot.com/api/storage/v2/query/records +STORAGE_QUERY_RECORD_FOR_CONVERSION_HOST=https://os-storage-dot-opendes-evt.appspot.com/api/storage/v2/query/records:batch +STORAGE_RECORDS_BATCH_SIZE=20 + +INDEXER_QUEUE_HOST=https://os-indexer-queue-dot-opendes-evt.appspot.com/_dps/task-handlers/enqueue + +AUTHORIZE_API=https://entitlements-dot-opendes-evt.appspot.com/entitlements/v1 +LEGALTAG_API=https://os-legal-dot-opendes-evt.appspot.com/api/legal/v1 +CRS_API=https://crs-converter-gae-dot-opendes-evt.appspot.com/api/crs/v1 + +## use below values for gcp: opendes +REDIS_GROUP_HOST=10.253.209.196 +REDIS_SEARCH_HOST=10.118.2.140 + +GOOGLE_AUDIENCES=833591776864-oobhqvmtdg9rpreubjvn44m5f8revglk.apps.googleusercontent.com diff --git a/provider/indexer-gcp/src/main/resources/application.properties b/provider/indexer-gcp/src/main/resources/application.properties index e1b58c9466f562fd6cc171031e1bfa756ccdac8a..1ccde084878626a19f762e0fd8abb6a650450447 100644 --- a/provider/indexer-gcp/src/main/resources/application.properties +++ b/provider/indexer-gcp/src/main/resources/application.properties @@ -1,32 +1,17 @@ +LOG_PREFIX=indexer + server.servlet.contextPath=/api/indexer/v2 logging.level.org.springframework.web=DEBUG server.port=8080 -#spring.cloud.gcp.project-id=opendes -#spring.security.user.roles=service.search.admin JAVA_OPTS=-Xms3072m -Xmx3072m JAVA_GC_OPTS=-XX:+UseG1GC -XX:+UseStringDeduplication -XX:InitiatingHeapOccupancyPercent=45 -GOOGLE_AUDIENCES=245464679631-ktfdfpl147m1mjpbutl00b3cmffissgq.apps.googleusercontent.com - -## use below values for gcp: local -#REDIS_GROUP_HOST=127.0.0.1 -#REDIS_SEARCH_HOST=localhost -#DEPLOYMENT_ENVIRONMENT=LOCAL - -## use below values for gcp: opendes -REDIS_GROUP_HOST=10.0.16.28 -REDIS_SEARCH_HOST=10.0.16.20 DEPLOYMENT_ENVIRONMENT=CLOUD REDIS_GROUP_PORT=6379 REDIS_SEARCH_PORT=6379 DEFAULT_DATA_COUNTRY=US -AUTHORIZE_API=https://entitlements-dot-opendes.appspot.com/entitlements/v1 -LEGALTAG_API=https://legal-dot-opendes.appspot.com/api/legal/v1 -CRS_API=https://crs-converter-dot-opendes.appspot.com/api/crs/v1 - - #Default Cache Settings SCHEMA_CACHE_EXPIRATION=60 INDEX_CACHE_EXPIRATION=60 @@ -41,21 +26,9 @@ KINDS_REDIS_DATABASE=1 CRON_INDEX_CLEANUP_THRESHOLD_DAYS=3 CRON_EMPTY_INDEX_CLEANUP_THRESHOLD_DAYS=7 -GOOGLE_CLOUD_PROJECT=opendes GAE_SERVICE=indexer - -#INDEXER_HOST=os-indexer-dot-opendes.appspot.com -#STORAGE_HOSTNAME=os-storage-dot-opendes.appspot.com - KEY_RING=csqp KMS_KEY=searchService ELASTIC_DATASTORE_KIND=SearchSettings ELASTIC_DATASTORE_ID=indexer-service - -STORAGE_SCHEMA_HOST=https://os-storage-dot-opendes.appspot.com/api/storage/v2/schemas -STORAGE_QUERY_RECORD_HOST=https://os-storage-dot-opendes.appspot.com/api/storage/v2/query/records -STORAGE_QUERY_RECORD_FOR_CONVERSION_HOST=https://os-storage-dot-opendes.appspot.com/api/storage/v2/query/records:batch -STORAGE_RECORDS_BATCH_SIZE=20 - -INDEXER_QUEUE_HOST=https://os-indexer-queue-dot-opendes.appspot.com/_dps/task-handlers/enqueue diff --git a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/CronServiceImplTest.java b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/CronServiceImplTest.java index 64ff9dce72c21188a79e7b58d644034b87d2d8a3..7d9e84f5643682f361207f89687da991f4c686bf 100644 --- a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/CronServiceImplTest.java +++ b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/CronServiceImplTest.java @@ -21,12 +21,12 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.opengroup.osdu.core.api.DpsHeaders; -import org.opengroup.osdu.is.core.logging.JaxRsDpsLog; -import org.opengroup.osdu.is.core.model.IndexInfo; -import org.opengroup.osdu.is.core.provider.interfaces.util.IRequestInfo; -import org.opengroup.osdu.is.core.service.IndicesService; -import org.opengroup.osdu.is.core.util.ElasticClientHandler; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.search.IndexInfo; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; +import org.opengroup.osdu.core.common.search.IndicesService; +import org.opengroup.osdu.indexer.util.ElasticClientHandler; import org.powermock.core.classloader.annotations.PrepareForTest; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.util.ReflectionTestUtils; @@ -132,4 +132,4 @@ public class CronServiceImplTest { verify(this.indicesService, times(0)).deleteIndex(any(), any()); } -} \ No newline at end of file +} diff --git a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/ElasticSettingServiceTest.java b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/ElasticSettingServiceTest.java index 5b1537be663b540d2e022a6061b725f243d4d7e3..44bade56c4d25dc98dfe95bd6e844d6ea9d09fe1 100644 --- a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/ElasticSettingServiceTest.java +++ b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/ElasticSettingServiceTest.java @@ -19,14 +19,14 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.opengroup.osdu.core.multitenancy.TenantInfo; -import org.opengroup.osdu.is.core.logging.JaxRsDpsLog; -import org.opengroup.osdu.is.core.model.ClusterSettings; -import org.opengroup.osdu.is.core.provider.interfaces.cache.IElasticCredentialsCache; -import org.opengroup.osdu.is.core.provider.interfaces.persistence.ElasticRepository; -import org.opengroup.osdu.is.core.provider.interfaces.util.IHeadersInfo; -import org.opengroup.osdu.is.core.service.TenantInfoService; -import org.opengroup.osdu.is.core.util.AppException; +import org.opengroup.osdu.core.common.model.search.ClusterSettings; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.tenant.TenantInfo; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.provider.interfaces.IElasticCredentialsCache; +import org.opengroup.osdu.core.common.provider.interfaces.IElasticRepository; +import org.opengroup.osdu.core.common.multitenancy.ITenantInfoService; import org.springframework.test.context.junit4.SpringRunner; import static org.junit.Assert.assertEquals; @@ -37,9 +37,9 @@ import static org.mockito.Mockito.when; public class ElasticSettingServiceTest { @Mock - private TenantInfoService tenantInfoService; + private ITenantInfoService tenantInfoService; @Mock - private ElasticRepository elasticRepository; + private IElasticRepository elasticRepository; @Mock private IElasticCredentialsCache elasticCredentialCache; @Mock @@ -49,7 +49,7 @@ public class ElasticSettingServiceTest { @Mock private ClusterSettings clusterSettings; @Mock - private IHeadersInfo headersInfo; + private DpsHeaders headersInfo; @Mock private JaxRsDpsLog log; diff --git a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/IndexCopyServiceImplTest.java b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/IndexCopyServiceImplTest.java index e668eb9b3638ac78be4915a86fd7eb4e0fb90843..c689c04d3c4fa8d0a4f4c40ead41db09a25df4b7 100644 --- a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/IndexCopyServiceImplTest.java +++ b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/IndexCopyServiceImplTest.java @@ -31,16 +31,15 @@ import org.junit.runner.RunWith; import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.opengroup.osdu.core.api.DpsHeaders; +import org.opengroup.osdu.core.common.model.search.ClusterSettings; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.http.AppException; import org.opengroup.osdu.indexer.logging.AuditLogger; -import org.opengroup.osdu.is.core.model.ClusterSettings; -import org.opengroup.osdu.is.core.provider.interfaces.util.IHeadersInfo; -import org.opengroup.osdu.is.core.provider.interfaces.util.IRequestInfo; -import org.opengroup.osdu.is.core.service.ElasticSettingService; -import org.opengroup.osdu.is.core.service.IndicesService; -import org.opengroup.osdu.is.core.util.AppException; -import org.opengroup.osdu.is.core.util.ElasticClientHandler; -import org.opengroup.osdu.is.core.util.ElasticIndexNameResolver; +import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; +import org.opengroup.osdu.core.common.model.indexer.IElasticSettingService; +import org.opengroup.osdu.core.common.search.IndicesService; +import org.opengroup.osdu.indexer.util.ElasticClientHandler; +import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; import org.powermock.core.classloader.annotations.PrepareForTest; import org.springframework.test.context.junit4.SpringRunner; @@ -66,7 +65,7 @@ public class IndexCopyServiceImplTest { @Mock private IRequestInfo requestInfo; @Mock - private IHeadersInfo headersInfo; + private DpsHeaders headersInfo; @Mock private RestClient restClient; @Mock @@ -82,7 +81,7 @@ public class IndexCopyServiceImplTest { @Mock private Response response; @Mock - private ElasticSettingService elasticSettingService; + private IElasticSettingService elasticSettingService; @Mock private AuditLogger auditLogger; @Mock @@ -102,8 +101,6 @@ public class IndexCopyServiceImplTest { httpHeaders = new HashMap<>(); httpHeaders.put(DpsHeaders.AUTHORIZATION, "testAuth"); httpHeaders.put(DpsHeaders.CORRELATION_ID, correlationId); - DpsHeaders standardHeaders = DpsHeaders.createFromMap(httpHeaders); - when(headersInfo.getHeaders()).thenReturn(standardHeaders); when(requestInfo.getHeadersMapWithDwdAuthZ()).thenReturn(httpHeaders); when(response.getEntity()).thenReturn(httpEntity); diff --git a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceTest.java b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceTest.java index b04435d54ac5b92d76bd5c0bfcf7b113af4751b7..19feb615eb7be7ab8075ab49e820de9808aee211 100644 --- a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceTest.java +++ b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/IndexerMappingServiceTest.java @@ -31,10 +31,10 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.opengroup.osdu.indexer.model.IndexSchema; -import org.opengroup.osdu.is.core.model.RecordMetaAttribute; -import org.opengroup.osdu.is.core.util.AppException; -import org.opengroup.osdu.is.core.util.ElasticClientHandler; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.model.indexer.IndexSchema; +import org.opengroup.osdu.core.common.model.search.RecordMetaAttribute; +import org.opengroup.osdu.indexer.util.ElasticClientHandler; import org.powermock.api.mockito.PowerMockito; import org.powermock.core.classloader.annotations.PrepareForTest; import org.springframework.test.context.junit4.SpringRunner; @@ -166,7 +166,7 @@ public class IndexerMappingServiceTest { doReturn(response).when(this.restHighLevelClient).updateByQuery(any(), any(RequestOptions.class)); when(response.getBulkFailures()).thenReturn(new ArrayList<Failure>()); when(elasticClientHandler.createRestClient()).thenReturn(restHighLevelClient); - + this.sut.updateIndexMappingForIndicesOfSameType( indices,"any field"); } catch (Exception e) { fail("Should not throw this exception" + e.getMessage()); @@ -200,8 +200,8 @@ public class IndexerMappingServiceTest { doReturn(response).when(this.restHighLevelClient).updateByQuery(any(), any(RequestOptions.class)); when(response.getBulkFailures()).thenReturn(new ArrayList<Failure>()); when(elasticClientHandler.createRestClient()).thenReturn(restHighLevelClient); - - this.sut.updateIndexMappingForIndicesOfSameType(indices,"any field"); + + this.sut.updateIndexMappingForIndicesOfSameType(indices,"any field"); } catch (Exception e) { throw e; } @@ -211,7 +211,7 @@ public class IndexerMappingServiceTest { public void should_throw_exception_if_type_of_index_is_invalid_andWeIndexfield_with_keyword() throws Exception { try { Set<String> indices = new HashSet<String>(); - indices.add("indices 1"); + indices.add("indices 1"); GetFieldMappingsResponse getFieldMappingsResponse = mock(GetFieldMappingsResponse.class); doReturn(this.indicesClient).when(this.restHighLevelClient).indices(); when(this.indicesClient.getFieldMapping(any(), any())).thenReturn(getFieldMappingsResponse); diff --git a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java index d58a9663db68d5f55d12ab407bdc39f4a8395240..a1b47530ee22f7f3a5ed5f51cd4fbc3cc8c8006a 100644 --- a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java +++ b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/IndexerSchemaServiceTest.java @@ -22,15 +22,15 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.opengroup.osdu.indexer.model.IndexSchema; -import org.opengroup.osdu.indexer.model.OperationType; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.model.indexer.OperationType; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.indexer.provider.interfaces.ISchemaCache; -import org.opengroup.osdu.is.core.httpclient.RequestStatus; -import org.opengroup.osdu.is.core.logging.JaxRsDpsLog; -import org.opengroup.osdu.is.core.service.IndicesService; -import org.opengroup.osdu.is.core.util.AppException; -import org.opengroup.osdu.is.core.util.ElasticClientHandler; -import org.opengroup.osdu.is.core.util.ElasticIndexNameResolver; +import org.opengroup.osdu.core.common.model.indexer.IndexSchema; +import org.opengroup.osdu.core.common.model.http.RequestStatus; +import org.opengroup.osdu.core.common.search.IndicesService; +import org.opengroup.osdu.indexer.util.ElasticClientHandler; +import org.opengroup.osdu.core.common.search.ElasticIndexNameResolver; import org.powermock.core.classloader.annotations.PrepareForTest; import org.springframework.test.context.junit4.SpringRunner; diff --git a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/ReindexServiceTest.java b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/ReindexServiceTest.java index 5c4d48b457f711325cab87903458463b399532be..cec115db0944b7d8280250904c89344207a5724c 100644 --- a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/ReindexServiceTest.java +++ b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/ReindexServiceTest.java @@ -21,12 +21,12 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.opengroup.osdu.core.api.DpsHeaders; -import org.opengroup.osdu.indexer.model.RecordQueryResponse; -import org.opengroup.osdu.indexer.model.RecordReindexRequest; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.indexer.RecordQueryResponse; +import org.opengroup.osdu.core.common.model.indexer.RecordReindexRequest; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; import org.opengroup.osdu.indexer.util.IndexerQueueTaskBuilder; -import org.opengroup.osdu.is.core.logging.JaxRsDpsLog; -import org.opengroup.osdu.is.core.provider.interfaces.util.IRequestInfo; +import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; import org.springframework.test.context.junit4.SpringRunner; import java.util.*; diff --git a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/StorageServiceTest.java b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/StorageServiceTest.java index 0fbac108721ee2f27d8e7f197cb0c16ca0fff432..fb5461bb31f90ec9ed85ee23fa305399adac66d4 100644 --- a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/StorageServiceTest.java +++ b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/service/StorageServiceTest.java @@ -23,17 +23,17 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; -import org.opengroup.osdu.core.api.DpsHeaders; -import org.opengroup.osdu.is.core.httpclient.HttpResponse; -import org.opengroup.osdu.is.core.logging.JaxRsDpsLog; -import org.opengroup.osdu.is.core.provider.interfaces.util.IRequestInfo; -import org.opengroup.osdu.is.core.service.UrlFetchService; -import org.opengroup.osdu.is.core.util.AppException; -import org.opengroup.osdu.indexer.model.RecordQueryResponse; -import org.opengroup.osdu.indexer.model.RecordReindexRequest; -import org.opengroup.osdu.indexer.model.Records; -import org.opengroup.osdu.indexer.util.JobStatus; -import org.opengroup.osdu.indexer.util.RecordInfo; +import org.opengroup.osdu.core.common.model.http.DpsHeaders; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.model.indexer.JobStatus; +import org.opengroup.osdu.core.common.model.indexer.RecordInfo; +import org.opengroup.osdu.core.common.model.http.HttpResponse; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.provider.interfaces.IRequestInfo; +import org.opengroup.osdu.core.common.http.IUrlFetchService; +import org.opengroup.osdu.core.common.model.indexer.RecordQueryResponse; +import org.opengroup.osdu.core.common.model.indexer.RecordReindexRequest; +import org.opengroup.osdu.core.common.model.indexer.Records; import org.springframework.http.HttpStatus; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.util.ReflectionTestUtils; @@ -53,7 +53,7 @@ import static org.powermock.api.mockito.PowerMockito.when; public class StorageServiceTest { @Mock - private UrlFetchService urlFetchService; + private IUrlFetchService urlFetchService; @Mock private JobStatus jobStatus; @Mock diff --git a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/util/ServiceAccountJwtGcpClientImplTest.java b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/util/ServiceAccountJwtGcpClientImplTest.java index fe8e4a6cf4efe7d88dcf8ac0e944f16beb977803..2fdd61dfd50a85de220e4fa808fce032e2539495 100644 --- a/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/util/ServiceAccountJwtGcpClientImplTest.java +++ b/provider/indexer-gcp/src/test/java/org/opengroup/osdu/indexer/util/ServiceAccountJwtGcpClientImplTest.java @@ -32,21 +32,16 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; -import org.opengroup.osdu.indexer.service.TenantInfoServiceImpl; -import org.opengroup.osdu.core.api.DpsHeaders; -import org.opengroup.osdu.core.multitenancy.TenantInfo; -import org.opengroup.osdu.is.core.logging.JaxRsDpsLog; -import org.opengroup.osdu.is.core.model.DeploymentEnvironment; -import org.opengroup.osdu.is.core.model.IdToken; -import org.opengroup.osdu.is.core.provider.interfaces.cache.IJwtCache; -import org.opengroup.osdu.is.core.util.AppException; -import org.opengroup.osdu.is.core.util.Config; +import org.opengroup.osdu.core.common.model.tenant.TenantInfo; +import org.opengroup.osdu.core.common.model.http.AppException; +import org.opengroup.osdu.core.common.logging.JaxRsDpsLog; +import org.opengroup.osdu.core.common.model.search.DeploymentEnvironment; +import org.opengroup.osdu.core.common.model.search.IdToken; +import org.opengroup.osdu.core.common.provider.interfaces.IJwtCache; +import org.opengroup.osdu.core.common.search.Config; import org.powermock.core.classloader.annotations.PrepareForTest; import org.springframework.test.context.junit4.SpringRunner; -import java.util.HashMap; -import java.util.Map; - import static org.junit.Assert.fail; import static org.mockito.Matchers.any; import static org.mockito.MockitoAnnotations.initMocks; @@ -79,14 +74,12 @@ public class ServiceAccountJwtGcpClientImplTest { private CloseableHttpClient httpClient; @Mock private CloseableHttpResponse httpResponse; - @InjectMocks - private TenantInfoServiceImpl tenantInfoServiceProvider; - @Mock - private TenantInfoServiceImpl tenantInfoService; +// @InjectMocks +// private TenantInfoServiceImpl tenantInfoServiceProvider; +// @Mock +// private TenantInfoServiceImpl tenantInfoService; @Mock private IJwtCache cacheService; - @Mock - private HeadersInfoGcpImpl headersInfoGcp; @InjectMocks @Spy private ServiceAccountJwtGcpClientImpl sut; @Before @@ -108,11 +101,11 @@ public class ServiceAccountJwtGcpClientImplTest { when(Config.getDeploymentEnvironment()).thenReturn(DeploymentEnvironment.LOCAL); when(Config.getGoogleAudiences()).thenReturn("aud"); - when(this.tenantInfoServiceProvider).thenReturn(this.tenantInfoService); - +// when(this.tenantInfoServiceProvider).thenReturn(this.tenantInfoService); + TenantInfo tenantInfo = new TenantInfo(); tenantInfo.setServiceAccount("tenant"); - when(this.tenantInfoService.getTenantInfo()).thenReturn(tenantInfo); +// when(this.tenantInfoService.getTenantInfo()).thenReturn(tenantInfo); when(this.sut.getIam()).thenReturn(iam); when(this.iam.projects()).thenReturn(iamProject); @@ -121,9 +114,6 @@ public class ServiceAccountJwtGcpClientImplTest { when(this.signJwt.execute()).thenReturn(signJwtResponse); when(this.signJwtResponse.getSignedJwt()).thenReturn("testJwt"); - Map<String, String> headers = new HashMap<>(); - DpsHeaders dpsHeaders = DpsHeaders.createFromMap(headers); - when(this.headersInfoGcp.getHeaders()).thenReturn(dpsHeaders); } @Test diff --git a/testing/indexer-test-aws/pom.xml b/testing/indexer-test-aws/pom.xml index 805e9c8cf2b72c2b003404203b66a26ecb4f58c9..f0e554ab57e326b001ddc4c3df66df3cec5ad697 100644 --- a/testing/indexer-test-aws/pom.xml +++ b/testing/indexer-test-aws/pom.xml @@ -22,7 +22,7 @@ <groupId>org.opengroup.osdu.indexer</groupId> <artifactId>indexer-test-aws</artifactId> - <version>0.0.1</version> + <version>0.0.2-SNAPSHOT</version> <packaging>jar</packaging> <properties> @@ -37,14 +37,14 @@ <dependency> <groupId>org.opengroup.osdu.indexer</groupId> <artifactId>indexer-test-core</artifactId> - <version>0.0.1</version> + <version>0.0.2-SNAPSHOT</version> </dependency> <!-- AWS specific packages --> <dependency> <groupId>org.opengroup.osdu.core.aws</groupId> <artifactId>aws-osdu-util</artifactId> - <version>0.0.4</version> + <version>0.0.8</version> </dependency> <!-- AWS managed packages --> diff --git a/testing/indexer-test-azure/pom.xml b/testing/indexer-test-azure/pom.xml new file mode 100644 index 0000000000000000000000000000000000000000..41312647e8aec6bf5591ec96d1505cd11575c0cb --- /dev/null +++ b/testing/indexer-test-azure/pom.xml @@ -0,0 +1,177 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + Copyright © Amazon Web Services + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <groupId>org.opengroup.osdu.indexer</groupId> + <artifactId>indexer-test-azure</artifactId> + <version>0.0.1-SNAPSHOT</version> + <packaging>jar</packaging> + + <properties> + <maven.compiler.target>1.8</maven.compiler.target> + <maven.compiler.source>1.8</maven.compiler.source> + <cucumber.version>1.2.5</cucumber.version> + <azure.keyvault.version>4.1.0</azure.keyvault.version> + <junit.jupiter.version>5.6.0</junit.jupiter.version> + </properties> + <!-- indexer test core depends on core libraries in OSDU, so the repository needs to be configured --> + <repositories> + <repository> + <id>os-core</id> + <url>https://pkgs.dev.azure.com/slb-des-ext-collaboration/_packaging/os-core/maven/v1</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>true</enabled> + </snapshots> + </repository> + </repositories> + <dependencies> + + <!-- Internal packages --> + <dependency> + <groupId>org.opengroup.osdu.indexer</groupId> + <artifactId>indexer-test-core</artifactId> + <version>0.0.2-SNAPSHOT</version> + </dependency> + + <!-- Azure dependencies --> + <dependency> + <groupId>org.opengroup.osdu</groupId> + <artifactId>core-lib-azure</artifactId> + <version>0.0.8</version> + </dependency> + + <dependency> + <groupId>com.azure</groupId> + <artifactId>azure-security-keyvault-secrets</artifactId> + <version>${azure.keyvault.version}</version> + </dependency> + + <!-- Testing --> + <dependency> + <groupId>junit</groupId> + <artifactId>junit</artifactId> + <version>4.12</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>info.cukes</groupId> + <artifactId>cucumber-java</artifactId> + <version>${cucumber.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>info.cukes</groupId> + <artifactId>cucumber-junit</artifactId> + <version>${cucumber.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter</artifactId> + <version>${junit.jupiter.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-junit-jupiter</artifactId> + <version>2.23.0</version> + <scope>test</scope> + </dependency> + + <!-- third party Apache 2.0 license packages --> + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <version>2.8.5</version> + <scope>compile</scope> + </dependency> + <dependency> + <groupId>com.fasterxml.jackson.jaxrs</groupId> + <artifactId>jackson-jaxrs-json-provider</artifactId> + <version>2.9.9</version> + </dependency> + <dependency> + <groupId>org.glassfish</groupId> + <artifactId>javax.json</artifactId> + <version>1.1.4</version> + </dependency> + <dependency> + <groupId>com.sun.jersey</groupId> + <artifactId>jersey-client</artifactId> + <version>1.19.4</version> + </dependency> + <dependency> + <groupId>org.projectlombok</groupId> + <artifactId>lombok</artifactId> + <version>1.18.2</version> + <scope>provided</scope> + </dependency> + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + <version>2.6</version> + </dependency> + <dependency> + <groupId>com.google.guava</groupId> + <artifactId>guava</artifactId> + <version>27.1-jre</version> + </dependency> + + <!--Elasticsearch--> + <dependency> + <groupId>org.elasticsearch</groupId> + <artifactId>elasticsearch</artifactId> + <version>6.6.2</version> + </dependency> + <dependency> + <groupId>org.elasticsearch.client</groupId> + <artifactId>elasticsearch-rest-client</artifactId> + <version>6.6.2</version> + </dependency> + <dependency> + <groupId>org.elasticsearch.client</groupId> + <artifactId>elasticsearch-rest-high-level-client</artifactId> + <version>6.6.2</version> + </dependency> + + <!--Logging--> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-to-slf4j</artifactId> + <version>2.13.0</version> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-api</artifactId> + <version>2.13.0</version> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <version>3.0.0</version> + <scope>test</scope> + </dependency> + + </dependencies> +</project> \ No newline at end of file diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/ServletInitializer.java b/testing/indexer-test-azure/src/test/java/org/opengroup/osdu/step_definitions/index/record/RunTest.java similarity index 56% rename from provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/ServletInitializer.java rename to testing/indexer-test-azure/src/test/java/org/opengroup/osdu/step_definitions/index/record/RunTest.java index 0a6086fb6dcccd82d097e69489435d8a474d9f36..ac4cc160e9b77c8bd38cd73824e4d9957cd4a939 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/ServletInitializer.java +++ b/testing/indexer-test-azure/src/test/java/org/opengroup/osdu/step_definitions/index/record/RunTest.java @@ -12,15 +12,16 @@ // See the License for the specific language governing permissions and // limitations under the License. -package org.opengroup.osdu.indexer.azure; +package org.opengroup.osdu.step_definitions.index.record; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; - -public class ServletInitializer extends SpringBootServletInitializer { - @Override - protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { - return application.sources(IndexerAzureApplication.class); - } -} +import cucumber.api.CucumberOptions; +import cucumber.api.junit.Cucumber; +import org.junit.runner.RunWith; +@RunWith(Cucumber.class) +@CucumberOptions( + features = "classpath:features/indexrecord/IndexRecord.feature", + glue = {"classpath:org.opengroup.osdu.step_definitions/index/record"}, + plugin = {"pretty", "junit:target/cucumber-reports/TEST-indexrecord.xml"}) +public class RunTest { +} \ No newline at end of file diff --git a/testing/indexer-test-azure/src/test/java/org/opengroup/osdu/step_definitions/index/record/Steps.java b/testing/indexer-test-azure/src/test/java/org/opengroup/osdu/step_definitions/index/record/Steps.java new file mode 100644 index 0000000000000000000000000000000000000000..dfff25eca03a6821678144595fb589418f5d7ae1 --- /dev/null +++ b/testing/indexer-test-azure/src/test/java/org/opengroup/osdu/step_definitions/index/record/Steps.java @@ -0,0 +1,67 @@ +// Copyright © Microsoft Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.opengroup.osdu.step_definitions.index.record; + +import lombok.extern.java.Log; + +import cucumber.api.Scenario; +import cucumber.api.java.Before; +import cucumber.api.DataTable; +import cucumber.api.java.en.Given; +import cucumber.api.java.en.Then; +import cucumber.api.java.en.When; +import org.opengroup.osdu.common.RecordSteps; +import org.opengroup.osdu.util.AzureHTTPClient; +import org.opengroup.osdu.util.ElasticUtils; + +@Log +public class Steps extends RecordSteps { + + public Steps() { + super(new AzureHTTPClient(), new ElasticUtils()); + } + + @Before + public void before(Scenario scenario) { + this.scenario = scenario; + this.httpClient = new AzureHTTPClient(); + } + + @Given("^the schema is created with the following kind$") + public void the_schema_is_created_with_the_following_kind(DataTable dataTable) { + super.the_schema_is_created_with_the_following_kind(dataTable); + } + + @When("^I ingest records with the \"(.*?)\" with \"(.*?)\" for a given \"(.*?)\"$") + public void i_ingest_records_with_the_for_a_given(String record, String dataGroup, String kind) { + super.i_ingest_records_with_the_for_a_given(record, dataGroup, kind); + } + + @Then("^I should get the (\\d+) documents for the \"([^\"]*)\" in the Elastic Search$") + public void i_should_get_the_documents_for_the_in_the_Elastic_Search(int expectedCount, String index) throws Throwable { + super.i_should_get_the_documents_for_the_in_the_Elastic_Search(expectedCount, index); + } + + @Then("^I should get the elastic \"(.*?)\" for the \"([^\"]*)\" and \"([^\"]*)\" in the Elastic Search$") + public void i_should_get_the_elastic_for_the_tenant_testindex_timestamp_well_in_the_Elastic_Search(String expectedMapping, String type, String index) throws Throwable { + super.i_should_get_the_elastic_for_the_tenant_testindex_timestamp_well_in_the_Elastic_Search(expectedMapping, type, index); + } + + @Then("^I should get the (\\d+) documents for the \"([^\"]*)\" in the Elastic Search with out \"(.*?)\"$") + public void iShouldGetTheNumberDocumentsForTheIndexInTheElasticSearchWithOutSkippedAttribute(int expectedCount, String index, String skippedAttributes) throws Throwable { + super.iShouldGetTheNumberDocumentsForTheIndexInTheElasticSearchWithOutSkippedAttribute(expectedCount, index, skippedAttributes); + } + +} \ No newline at end of file diff --git a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/model/AADConfiguration.java b/testing/indexer-test-azure/src/test/java/org/opengroup/osdu/util/AzureHTTPClient.java similarity index 54% rename from provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/model/AADConfiguration.java rename to testing/indexer-test-azure/src/test/java/org/opengroup/osdu/util/AzureHTTPClient.java index 3b311a933a2fc0ff7756ec317d5838d4464a29c1..d6c57ae848c583e0a90d33bac7f9794da665aaf1 100644 --- a/provider/indexer-azure/src/main/java/org/opengroup/osdu/indexer/azure/model/AADConfiguration.java +++ b/testing/indexer-test-azure/src/test/java/org/opengroup/osdu/util/AzureHTTPClient.java @@ -12,27 +12,28 @@ // See the License for the specific language governing permissions and // limitations under the License. -package org.opengroup.osdu.indexer.azure.model; +package org.opengroup.osdu.util; -import lombok.Getter; -import lombok.Setter; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; +import lombok.ToString; +import lombok.extern.java.Log; -@Getter -@Setter -@Component -@ConfigurationProperties("aad") -public class AADConfiguration { - String clientId; - String authority; - String secretKey; - String oboApi; +import java.io.IOException; - public String getAuthority(){ - if (!authority.endsWith("/")) { - authority += "/"; +@Log +@ToString +public class AzureHTTPClient extends HTTPClient { + + private static String token = null; + + @Override + public synchronized String getAccessToken() { + if(token == null) { + try { + token = "Bearer " + JwtTokenUtil.getAccessToken(); + } catch (Exception e) { + e.printStackTrace(); + } } - return authority; + return token; } } \ No newline at end of file diff --git a/testing/indexer-test-azure/src/test/java/org/opengroup/osdu/util/AzureServicePrincipal.java b/testing/indexer-test-azure/src/test/java/org/opengroup/osdu/util/AzureServicePrincipal.java new file mode 100644 index 0000000000000000000000000000000000000000..57ef5389cbf43c415dd5d75e26d6411ad5a1f117 --- /dev/null +++ b/testing/indexer-test-azure/src/test/java/org/opengroup/osdu/util/AzureServicePrincipal.java @@ -0,0 +1,83 @@ +// Copyright © Microsoft Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.opengroup.osdu.util; + +import com.google.gson.Gson; +import com.google.gson.JsonObject; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.net.HttpURLConnection; +import java.net.URL; +import java.net.URLEncoder; +import java.util.HashMap; +import java.util.Map; + +public class AzureServicePrincipal { + public static String getIdToken(String sp_id, String sp_secret, String tenant_id, String app_resource_id) throws Exception { + String aad_endpoint = String.format("https://login.microsoftonline.com/%s/oauth2/token", tenant_id); + URL url = new URL(aad_endpoint); + HttpURLConnection con = (HttpURLConnection) url.openConnection(); + con.setRequestMethod("POST"); + con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); + + Map<String, String> parameters = new HashMap<>(); + parameters.put("grant_type", "client_credentials"); + parameters.put("client_id", sp_id); + parameters.put("client_secret", sp_secret); + parameters.put("resource", app_resource_id); + + con.setDoOutput(true); + DataOutputStream out = new DataOutputStream(con.getOutputStream()); + out.writeBytes(getParamsString(parameters)); + out.flush(); + out.close(); + + BufferedReader in = new BufferedReader( + new InputStreamReader(con.getInputStream())); + String inputLine; + StringBuffer content = new StringBuffer(); + while ((inputLine = in.readLine()) != null) { + content.append(inputLine); + } + in.close(); + + con.disconnect(); + + Gson gson = new Gson(); + JsonObject jobj = gson.fromJson(content.toString(), JsonObject.class); + String token = jobj.get("access_token").getAsString(); + return token; + } + + private static String getParamsString(Map<String, String> params) + throws UnsupportedEncodingException { + StringBuilder result = new StringBuilder(); + + for (Map.Entry<String, String> entry : params.entrySet()) { + result.append(URLEncoder.encode(entry.getKey(), "UTF-8")); + result.append("="); + result.append(URLEncoder.encode(entry.getValue(), "UTF-8")); + result.append("&"); + } + + String resultString = result.toString(); + return resultString.length() > 0 + ? resultString.substring(0, resultString.length() - 1) + : resultString; + } +} \ No newline at end of file diff --git a/testing/indexer-test-azure/src/test/java/org/opengroup/osdu/util/JwtTokenUtil.java b/testing/indexer-test-azure/src/test/java/org/opengroup/osdu/util/JwtTokenUtil.java new file mode 100644 index 0000000000000000000000000000000000000000..b1a799920c452c1f5096a146e7129ade22d22560 --- /dev/null +++ b/testing/indexer-test-azure/src/test/java/org/opengroup/osdu/util/JwtTokenUtil.java @@ -0,0 +1,30 @@ +// Copyright © Microsoft Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package org.opengroup.osdu.util; + +class JwtTokenUtil { + static public String getAccessToken() throws Exception { + + String token = new String(); + + String sp_id = System.getProperty("INTEGRATION_TESTER", System.getenv("INTEGRATION_TESTER")); + String sp_secret = System.getProperty("AZURE_TESTER_SERVICEPRINCIPAL_SECRET", System.getenv("AZURE_TESTER_SERVICEPRINCIPAL_SECRET")); + String tenant_id = System.getProperty("AZURE_AD_TENANT_ID", System.getenv("AZURE_AD_TENANT_ID")); + String app_resource_id = System.getProperty("AZURE_AD_APP_RESOURCE_ID", System.getenv("AZURE_AD_APP_RESOURCE_ID")); + token = AzureServicePrincipal.getIdToken(sp_id, sp_secret, tenant_id, app_resource_id); + + return token; + } +} diff --git a/testing/indexer-test-azure/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/testing/indexer-test-azure/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker new file mode 100644 index 0000000000000000000000000000000000000000..ca6ee9cea8ec189a088d50559325d4e84ff8ad09 --- /dev/null +++ b/testing/indexer-test-azure/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker @@ -0,0 +1 @@ +mock-maker-inline \ No newline at end of file diff --git a/testing/indexer-test-core/pom.xml b/testing/indexer-test-core/pom.xml index 3e3821f726bd738cf0f6475c1c8f04da14512b3d..4a08809967950ef8f180cd9d63b8e88fdcc2a88a 100644 --- a/testing/indexer-test-core/pom.xml +++ b/testing/indexer-test-core/pom.xml @@ -6,7 +6,7 @@ <groupId>org.opengroup.osdu.indexer</groupId> <artifactId>indexer-test-core</artifactId> - <version>0.0.1</version> + <version>0.0.2-SNAPSHOT</version> <properties> <maven.compiler.target>1.8</maven.compiler.target> @@ -14,7 +14,26 @@ <cucumber.version>1.2.5</cucumber.version> </properties> + <!-- testing core depends on core libraries in OSDU, so the repository needs to be configured --> + <repositories> + <repository> + <id>os-core</id> + <url>https://pkgs.dev.azure.com/slb-des-ext-collaboration/_packaging/os-core/maven/v1</url> + <releases> + <enabled>true</enabled> + </releases> + <snapshots> + <enabled>true</enabled> + </snapshots> + </repository> + </repositories> <dependencies> + <dependency> + <groupId>org.opengroup.osdu</groupId> + <artifactId>os-core-common</artifactId> + <version>0.0.12</version> + </dependency> + <dependency> <groupId>com.google.api-client</groupId> <artifactId>google-api-client</artifactId> @@ -116,4 +135,4 @@ <version>27.1-jre</version> </dependency> </dependencies> -</project> \ No newline at end of file +</project> diff --git a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/RecordSteps.java b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/RecordSteps.java index fe57b8cc49e8566c72ed28e4194fe666a4f886d7..a58c18461e0008ba32fa2622f48995fcfc9eee9e 100644 --- a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/RecordSteps.java +++ b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/RecordSteps.java @@ -9,7 +9,7 @@ import cucumber.api.DataTable; import lombok.extern.java.Log; import org.elasticsearch.cluster.metadata.MappingMetaData; import org.elasticsearch.common.collect.ImmutableOpenMap; -import org.opengroup.osdu.models.Acl; +import org.opengroup.osdu.core.common.model.entitlements.Acl; import org.opengroup.osdu.models.Setup; import org.opengroup.osdu.models.TestIndex; import org.opengroup.osdu.util.ElasticUtils; @@ -17,7 +17,6 @@ import org.opengroup.osdu.util.FileHandler; import org.opengroup.osdu.util.HTTPClient; import javax.ws.rs.HttpMethod; -import java.io.File; import java.io.IOException; import java.lang.reflect.Type; import java.util.HashMap; diff --git a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/TestsBase.java b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/TestsBase.java index 43cd1b4d429d69acd6486d418fb93795d03b3319..e24a19da82531608b8609f3543013bf2576e0e17 100644 --- a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/TestsBase.java +++ b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/common/TestsBase.java @@ -2,7 +2,7 @@ package org.opengroup.osdu.common; import com.google.gson.Gson; -import org.opengroup.osdu.models.Legal; +import org.opengroup.osdu.core.common.model.legal.Legal; import org.opengroup.osdu.models.Setup; import org.opengroup.osdu.models.TestIndex; import org.opengroup.osdu.response.ResponseBase; @@ -15,10 +15,7 @@ import lombok.extern.java.Log; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.MultivaluedMap; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; import static org.junit.Assert.assertEquals; import static org.opengroup.osdu.util.Config.*; @@ -142,9 +139,11 @@ public abstract class TestsBase { protected Legal generateLegalTag() { Legal legal = new Legal(); - String[] legalTags = {getLegalTag()}; + Set<String> legalTags = new HashSet<>(); + legalTags.add(getLegalTag()); legal.setLegaltags(legalTags); - String[] otherRelevantCountries = {getOtherRelevantDataCountries()}; + Set<String> otherRelevantCountries = new HashSet<>(); + otherRelevantCountries.add(getOtherRelevantDataCountries()); legal.setOtherRelevantDataCountries(otherRelevantCountries); return legal; } diff --git a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/models/Acl.java b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/models/Acl.java deleted file mode 100644 index a4c1f737f3223edd65c41b320dcfa2cbb3a2d19c..0000000000000000000000000000000000000000 --- a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/models/Acl.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.opengroup.osdu.models; - -import lombok.Builder; -import lombok.Data; - -@Data -@Builder -public class Acl { - - private String[] viewers; - - private String[] owners; - -} \ No newline at end of file diff --git a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/models/Legal.java b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/models/Legal.java deleted file mode 100644 index 57595ffeadede472b86d9ffa3ee5dd37d769d165..0000000000000000000000000000000000000000 --- a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/models/Legal.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.opengroup.osdu.models; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; - -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class Legal { - - private String[] legaltags; - - private String[] otherRelevantDataCountries; - - @lombok.Builder.Default - private String status = "compliant"; -} diff --git a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/models/TestIndex.java b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/models/TestIndex.java index d8c611d8b5a3aff19a5ab23606f45476d9f57609..efd8d1960362fabd2b7ee3da55903816f49c3e20 100644 --- a/testing/indexer-test-core/src/main/java/org/opengroup/osdu/models/TestIndex.java +++ b/testing/indexer-test-core/src/main/java/org/opengroup/osdu/models/TestIndex.java @@ -5,16 +5,19 @@ import com.google.gson.JsonElement; import com.google.gson.reflect.TypeToken; import com.sun.jersey.api.client.ClientResponse; import lombok.Data; -import lombok.NoArgsConstructor; import javax.ws.rs.HttpMethod; +import org.opengroup.osdu.core.common.model.entitlements.Acl; +import org.opengroup.osdu.core.common.model.legal.Legal; import org.opengroup.osdu.util.ElasticUtils; import org.opengroup.osdu.util.FileHandler; import org.opengroup.osdu.util.HTTPClient; +import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Set; import java.util.logging.Logger; import static org.junit.Assert.assertEquals; @@ -127,9 +130,11 @@ public class TestIndex { private Legal generateLegalTag() { Legal legal = new Legal(); - String[] legalTags = {getLegalTag()}; + Set<String> legalTags = new HashSet<>(); + legalTags.add(getLegalTag()); legal.setLegaltags(legalTags); - String[] otherRelevantCountries = {getOtherRelevantDataCountries()}; + Set<String> otherRelevantCountries = new HashSet<>(); + otherRelevantCountries.add(getOtherRelevantDataCountries()); legal.setOtherRelevantDataCountries(otherRelevantCountries); return legal; } diff --git a/testing/indexer-test-gcp/pom.xml b/testing/indexer-test-gcp/pom.xml index e51248f384e278556dabffb8f4757541d458c12c..12ac773f9139cf5d22c230264255652f74d75f4a 100644 --- a/testing/indexer-test-gcp/pom.xml +++ b/testing/indexer-test-gcp/pom.xml @@ -7,7 +7,7 @@ <groupId>org.opengroup.osdu.indexer</groupId> <artifactId>indexer-test-gcp</artifactId> - <version>0.0.1</version> + <version>0.0.2-SNAPSHOT</version> <packaging>jar</packaging> <properties> @@ -32,7 +32,7 @@ <dependency> <groupId>org.opengroup.osdu.indexer</groupId> <artifactId>indexer-test-core</artifactId> - <version>0.0.1</version> + <version>0.0.2-SNAPSHOT</version> </dependency> <!-- Cucumber -->