Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • osdu/platform/system/indexer-service
  • schundu/indexer-service
2 results
Show changes
Commits on Source (6)
...@@ -56,7 +56,7 @@ spec: ...@@ -56,7 +56,7 @@ spec:
readOnly: true readOnly: true
env: env:
- name: spring_application_name - name: spring_application_name
value: indexer value: {{ .Chart.Name }}
- name: server.servlet.contextPath - name: server.servlet.contextPath
value: /api/indexer/v2/ value: /api/indexer/v2/
- name: server_port - name: server_port
......
...@@ -24,7 +24,7 @@ spec: ...@@ -24,7 +24,7 @@ spec:
kind: Deployment kind: Deployment
name: {{ .Chart.Name }} name: {{ .Chart.Name }}
minReplicas: {{ .Values.global.replicaCount }} minReplicas: {{ .Values.global.replicaCount }}
maxReplicas: 5 maxReplicas: 10
metrics: metrics:
- type: Resource - type: Resource
resource: resource:
......
// 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.error;
import javax.validation.ValidationException;
import javassist.NotFoundException;
import org.opengroup.osdu.core.common.logging.JaxRsDpsLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.mvc.method.annotation.ResponseEntityExceptionHandler;
import org.opengroup.osdu.core.common.model.http.AppException;
@Order(Ordered.HIGHEST_PRECEDENCE - 1)
@ControllerAdvice
public class GlobalExceptionMapperCore extends ResponseEntityExceptionHandler {
@Autowired
private JaxRsDpsLog logger;
@ExceptionHandler(AppException.class)
protected ResponseEntity<Object> handleAppException(AppException e) {
return this.getErrorResponse(e);
}
@ExceptionHandler(ValidationException.class)
protected ResponseEntity<Object> handleValidationException(ValidationException e) {
return this.getErrorResponse(
new AppException(HttpStatus.BAD_REQUEST.value(), "Validation error.", e.getMessage(), e));
}
@ExceptionHandler(NotFoundException.class)
protected ResponseEntity<Object> handleNotFoundException(NotFoundException e) {
return this.getErrorResponse(
new AppException(HttpStatus.NOT_FOUND.value(), "Resource not found.", e.getMessage(), e));
}
@ExceptionHandler(AccessDeniedException.class)
protected ResponseEntity<Object> handleAccessDeniedException(AccessDeniedException e) {
return this.getErrorResponse(
new AppException(HttpStatus.FORBIDDEN.value(), "Access denied", e.getMessage(), e));
}
@ExceptionHandler(Exception.class)
protected ResponseEntity<Object> handleGeneralException(Exception e) {
return this.getErrorResponse(
new AppException(HttpStatus.INTERNAL_SERVER_ERROR.value(), "Server error.",
"An unknown error has occurred.", e));
}
private ResponseEntity<Object> getErrorResponse(AppException e) {
String exceptionMsg = e.getOriginalException() != null
? e.getOriginalException().getMessage()
: e.getError().getMessage();
if( e.getCause() instanceof Exception) {
Exception original = (Exception) e.getCause();
this.logger.error(original.getMessage(), original);
}
if (e.getError().getCode() > 499) {
this.logger.error(exceptionMsg, e);
} else {
this.logger.warning(exceptionMsg, e);
}
return new ResponseEntity<Object>(e.getError(), HttpStatus.resolve(e.getError().getCode()));
}
}
\ No newline at end of file
...@@ -16,7 +16,10 @@ package org.opengroup.osdu.indexer.service; ...@@ -16,7 +16,10 @@ package org.opengroup.osdu.indexer.service;
import com.google.common.base.Strings; import com.google.common.base.Strings;
import com.google.gson.Gson; import com.google.gson.Gson;
import java.util.Objects; import java.util.Objects;
import lombok.SneakyThrows;
import org.apache.http.HttpStatus; import org.apache.http.HttpStatus;
import org.opengroup.osdu.core.common.model.http.DpsHeaders; 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.AppException;
...@@ -53,74 +56,70 @@ public class ReindexServiceImpl implements ReindexService { ...@@ -53,74 +56,70 @@ public class ReindexServiceImpl implements ReindexService {
@Inject @Inject
private JaxRsDpsLog jaxRsDpsLog; private JaxRsDpsLog jaxRsDpsLog;
@SneakyThrows
@Override @Override
public String reindexRecords(RecordReindexRequest recordReindexRequest, boolean forceClean) { public String reindexRecords(RecordReindexRequest recordReindexRequest, boolean forceClean) {
Long initialDelayMillis = 0l; Long initialDelayMillis = 0l;
try {
DpsHeaders headers = this.requestInfo.getHeadersWithDwdAuthZ();
if (forceClean) { DpsHeaders headers = this.requestInfo.getHeadersWithDwdAuthZ();
this.indexSchemaService.syncIndexMappingWithStorageSchema(recordReindexRequest.getKind());
initialDelayMillis = 30000l;
}
RecordQueryResponse recordQueryResponse = this.storageService.getRecordsByKind(recordReindexRequest); if (forceClean) {
this.indexSchemaService.syncIndexMappingWithStorageSchema(recordReindexRequest.getKind());
initialDelayMillis = 30000l;
}
if (recordQueryResponse.getResults() != null && recordQueryResponse.getResults().size() != 0) { RecordQueryResponse recordQueryResponse = this.storageService.getRecordsByKind(recordReindexRequest);
List<RecordInfo> msgs = recordQueryResponse.getResults().stream() if (recordQueryResponse.getResults() != null && recordQueryResponse.getResults().size() != 0) {
.map(record -> RecordInfo.builder().id(record).kind(recordReindexRequest.getKind()).op(OperationType.create.name()).build()).collect(Collectors.toList());
Map<String, String> attributes = new HashMap<>(); List<RecordInfo> msgs = recordQueryResponse.getResults().stream()
attributes.put(DpsHeaders.ACCOUNT_ID, headers.getAccountId()); .map(record -> RecordInfo.builder().id(record).kind(recordReindexRequest.getKind()).op(OperationType.create.name()).build()).collect(Collectors.toList());
attributes.put(DpsHeaders.DATA_PARTITION_ID, headers.getPartitionIdWithFallbackToAccountId());
attributes.put(DpsHeaders.CORRELATION_ID, headers.getCorrelationId());
Gson gson = new Gson(); Map<String, String> attributes = new HashMap<>();
RecordChangedMessages recordChangedMessages = RecordChangedMessages.builder().data(gson.toJson(msgs)).attributes(attributes).build(); attributes.put(DpsHeaders.ACCOUNT_ID, headers.getAccountId());
String recordChangedMessagePayload = gson.toJson(recordChangedMessages); attributes.put(DpsHeaders.DATA_PARTITION_ID, headers.getPartitionIdWithFallbackToAccountId());
this.indexerQueueTaskBuilder.createWorkerTask(recordChangedMessagePayload, initialDelayMillis, headers); attributes.put(DpsHeaders.CORRELATION_ID, headers.getCorrelationId());
// don't call reindex-worker endpoint if it's the last batch Gson gson = new Gson();
// previous storage query result size will be less then requested (limit param) RecordChangedMessages recordChangedMessages = RecordChangedMessages.builder().data(gson.toJson(msgs)).attributes(attributes).build();
if (!Strings.isNullOrEmpty(recordQueryResponse.getCursor()) && recordQueryResponse.getResults().size() == configurationProperties.getStorageRecordsBatchSize()) { String recordChangedMessagePayload = gson.toJson(recordChangedMessages);
String newPayLoad = gson.toJson(RecordReindexRequest.builder().cursor(recordQueryResponse.getCursor()).kind(recordReindexRequest.getKind()).build()); this.indexerQueueTaskBuilder.createWorkerTask(recordChangedMessagePayload, initialDelayMillis, headers);
this.indexerQueueTaskBuilder.createReIndexTask(newPayLoad, initialDelayMillis, headers);
return newPayLoad;
}
return recordChangedMessagePayload; // don't call reindex-worker endpoint if it's the last batch
} else { // previous storage query result size will be less then requested (limit param)
jaxRsDpsLog.info(String.format("kind: %s cannot be re-indexed, storage service cannot locate valid records", recordReindexRequest.getKind())); if (!Strings.isNullOrEmpty(recordQueryResponse.getCursor()) && recordQueryResponse.getResults().size() == configurationProperties.getStorageRecordsBatchSize()) {
String newPayLoad = gson.toJson(RecordReindexRequest.builder().cursor(recordQueryResponse.getCursor()).kind(recordReindexRequest.getKind()).build());
this.indexerQueueTaskBuilder.createReIndexTask(newPayLoad, initialDelayMillis, headers);
return newPayLoad;
} }
return null;
} catch (AppException e) { return recordChangedMessagePayload;
throw e; } else {
} catch (Exception e) { jaxRsDpsLog.info(String.format("kind: %s cannot be re-indexed, storage service cannot locate valid records", recordReindexRequest.getKind()));
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "Unknown error", "An unknown error has occurred.", e);
} }
return null;
} }
@Override @Override
public void fullReindex(boolean forceClean) { public void fullReindex(boolean forceClean) {
List<String> allKinds = null; List<String> allKinds = null;
try { try {
allKinds = storageService.getAllKinds(); allKinds = storageService.getAllKinds();
} catch (Exception e) { } catch (Exception e) {
jaxRsDpsLog.error("storage service all kinds request failed",e); jaxRsDpsLog.error("storage service all kinds request failed", e);
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "storage service cannot respond with all kinds", "an unknown error has occurred.", e); throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "storage service cannot respond with all kinds", "an unknown error has occurred.", e);
} }
if (Objects.isNull(allKinds)){ if (Objects.isNull(allKinds)) {
throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "storage service cannot respond with all kinds", "full reindex failed"); throw new AppException(HttpStatus.SC_INTERNAL_SERVER_ERROR, "storage service cannot respond with all kinds", "full reindex failed");
} }
for (String kind : allKinds) { for (String kind : allKinds) {
try { try {
reindexRecords(new RecordReindexRequest(kind, ""), forceClean); reindexRecords(new RecordReindexRequest(kind, ""), forceClean);
} catch (Exception e) { } catch (Exception e) {
jaxRsDpsLog.warning(String.format("kind: %s cannot be re-indexed", kind)); jaxRsDpsLog.warning(String.format("kind: %s cannot be re-indexed", kind));
continue; continue;
} }
} }
} }
} }
\ No newline at end of file