@Test public void succeedUpdateWhenNoConfigWasRetrieved() throws InvalidRequestException { Request inputESRequest = new Request(HttpPut.METHOD_NAME, String.format("%s/%s", TestConstants.DUMMY_ENDPOINT, Constants.UPDATE_REQUEST)); inputESRequest.setJsonEntity(TestConstants.NEW_CONFIG); when(RequestIdentifier.isMutationRequest(inputESRequest)).thenReturn(true); when(HTTPTransformer.transformHttpEntityToString(any(HttpEntity.class))).thenReturn(TestConstants.NEW_CONFIG); when(mockConfigSerializer.deserialize(anyString())).thenReturn(TestConstants.getNewConfigRequest()); when(ConfigSerializer.transformConfigRequestToConfigMap(any(PreprocessingConfigRequest.class))) .thenReturn(TestConstants.getConfigMap()); when(RequestIdentifier.isConfigUpdateRequest(inputESRequest)).thenReturn(true); when(mockConfigRetriever.retrieveStoredConfig()).thenReturn(Collections.emptyMap()); when(mockStatusLine.getStatusCode()).thenReturn(HttpStatus.SC_OK); test.processRequest(inputESRequest, mockLogger); verify(mockConfigSerializer, times(0)).serialize(any()); }
@Override public Response processRequest(@NonNull final Request request, @NonNull final LambdaLogger logger) { logger.log("Comprehend Configuration request detected"); 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(); kibanaUploader.uploadMapping( newConfigMap.entrySet().stream().filter(entry -> !oldConfigMap.containsKey(entry.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)), logger); if (!oldConfigMap.isEmpty() && RequestIdentifier.isConfigUpdateRequest(request)) { oldConfigMap.putAll(newConfigMap); newConfigMap = oldConfigMap; PreprocessingConfigRequest newConfigRequest = ConfigSerializer .transformConfigMapToConfigRequest(newConfigMap); inputConfig = configSerializer.serialize(newConfigRequest); } kibanaUploader.uploadKibanaDashboard(newConfigMap, logger); return esClient.performRequest(request.getMethod(), Constants.CONFIG_PATH, inputConfig); }
PreprocessingConfigProcessor implements ElasticsearchProcessor { @Override public Response processRequest(@NonNull final Request request, @NonNull final LambdaLogger logger) { logger.log("Comprehend Configuration request detected"); 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(); kibanaUploader.uploadMapping( newConfigMap.entrySet().stream().filter(entry -> !oldConfigMap.containsKey(entry.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)), logger); if (!oldConfigMap.isEmpty() && RequestIdentifier.isConfigUpdateRequest(request)) { oldConfigMap.putAll(newConfigMap); newConfigMap = oldConfigMap; PreprocessingConfigRequest newConfigRequest = ConfigSerializer .transformConfigMapToConfigRequest(newConfigMap); inputConfig = configSerializer.serialize(newConfigRequest); } kibanaUploader.uploadKibanaDashboard(newConfigMap, logger); return esClient.performRequest(request.getMethod(), Constants.CONFIG_PATH, inputConfig); } }
PreprocessingConfigProcessor implements ElasticsearchProcessor { @Override public Response processRequest(@NonNull final Request request, @NonNull final LambdaLogger logger) { logger.log("Comprehend Configuration request detected"); 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(); kibanaUploader.uploadMapping( newConfigMap.entrySet().stream().filter(entry -> !oldConfigMap.containsKey(entry.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)), logger); if (!oldConfigMap.isEmpty() && RequestIdentifier.isConfigUpdateRequest(request)) { oldConfigMap.putAll(newConfigMap); newConfigMap = oldConfigMap; PreprocessingConfigRequest newConfigRequest = ConfigSerializer .transformConfigMapToConfigRequest(newConfigMap); inputConfig = configSerializer.serialize(newConfigRequest); } kibanaUploader.uploadKibanaDashboard(newConfigMap, logger); return esClient.performRequest(request.getMethod(), Constants.CONFIG_PATH, inputConfig); }  }
PreprocessingConfigProcessor implements ElasticsearchProcessor { @Override public Response processRequest(@NonNull final Request request, @NonNull final LambdaLogger logger) { logger.log("Comprehend Configuration request detected"); 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(); kibanaUploader.uploadMapping( newConfigMap.entrySet().stream().filter(entry -> !oldConfigMap.containsKey(entry.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)), logger); if (!oldConfigMap.isEmpty() && RequestIdentifier.isConfigUpdateRequest(request)) { oldConfigMap.putAll(newConfigMap); newConfigMap = oldConfigMap; PreprocessingConfigRequest newConfigRequest = ConfigSerializer .transformConfigMapToConfigRequest(newConfigMap); inputConfig = configSerializer.serialize(newConfigRequest); } kibanaUploader.uploadKibanaDashboard(newConfigMap, logger); return esClient.performRequest(request.getMethod(), Constants.CONFIG_PATH, inputConfig); }  @Override Response processRequest(@NonNull final Request request, @NonNull final LambdaLogger logger); }
PreprocessingConfigProcessor implements ElasticsearchProcessor { @Override public Response processRequest(@NonNull final Request request, @NonNull final LambdaLogger logger) { logger.log("Comprehend Configuration request detected"); 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(); kibanaUploader.uploadMapping( newConfigMap.entrySet().stream().filter(entry -> !oldConfigMap.containsKey(entry.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)), logger); if (!oldConfigMap.isEmpty() && RequestIdentifier.isConfigUpdateRequest(request)) { oldConfigMap.putAll(newConfigMap); newConfigMap = oldConfigMap; PreprocessingConfigRequest newConfigRequest = ConfigSerializer .transformConfigMapToConfigRequest(newConfigMap); inputConfig = configSerializer.serialize(newConfigRequest); } kibanaUploader.uploadKibanaDashboard(newConfigMap, logger); return esClient.performRequest(request.getMethod(), Constants.CONFIG_PATH, inputConfig); }  @Override Response processRequest(@NonNull final Request request, @NonNull final LambdaLogger logger);  }