@Test public void successPassThroughConfig() throws InvalidRequestException { Request inputESRequest = new Request(HttpGet.METHOD_NAME, TestConstants.DUMMY_ENDPOINT); inputESRequest.setJsonEntity(TestConstants.CONFIG); when(RequestIdentifier.isMutationRequest(inputESRequest)).thenReturn(false); when(mockESClient.performRequest(any(Request.class))).thenReturn(mockESResponse); test.processRequest(inputESRequest, mockLogger); verify(mockConfigSerializer, times(0)).deserialize(any()); verify(mockConfigRetriever, times(0)).retrieveStoredConfig(); 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);  }