in source/src/main/java/com/amazonaws/comprehend/esproxy/lambda/processor/PreprocessingConfigProcessor.java [61:95]
public Response processRequest(@NonNull final Request request, @NonNull final LambdaLogger logger) {
logger.log("Comprehend Configuration request detected");
// If the request is a non create nor update config, replace the customer config path with the real config path
if (!RequestIdentifier.isMutationRequest(request)) {
return esClient.performRequest(request, Constants.CONFIG_PATH);
}
HttpEntity receivedEntity = request.getEntity();
String inputConfig = HTTPTransformer.transformHttpEntityToString(receivedEntity);
PreprocessingConfigRequest configRequest = configSerializer.deserialize(inputConfig);
Map<String, ComprehendConfiguration> newConfigMap = ConfigSerializer
.transformConfigRequestToConfigMap(configRequest);
Map<String, ComprehendConfiguration> oldConfigMap = configRetriever.retrieveStoredConfig();
// Find the difference between the two configs, and upload the mapping
kibanaUploader.uploadMapping(
newConfigMap.entrySet().stream().filter(entry -> !oldConfigMap.containsKey(entry.getKey()))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)), logger);
// If it is a update request, retrieve the old config, and attach the new config to it
if (!oldConfigMap.isEmpty() && RequestIdentifier.isConfigUpdateRequest(request)) {
oldConfigMap.putAll(newConfigMap);
newConfigMap = oldConfigMap;
PreprocessingConfigRequest newConfigRequest = ConfigSerializer
.transformConfigMapToConfigRequest(newConfigMap);
inputConfig = configSerializer.serialize(newConfigRequest);
}
// Best effort to upload the dashboard
kibanaUploader.uploadKibanaDashboard(newConfigMap, logger);
// Save config
return esClient.performRequest(request.getMethod(), Constants.CONFIG_PATH, inputConfig);
}