public static void createComponentConfiguration()

in aws-applicationinsights-application/src/main/java/software/amazon/applicationinsights/application/HandlerHelper.java [198:271]


    public static void createComponentConfiguration(
            ComponentMonitoringSetting componentMonitoringSetting,
            ResourceModel model,
            AmazonWebServicesClientProxy proxy,
            ApplicationInsightsClient applicationInsightsClient,
            Logger logger) throws IOException {
        String mode = componentMonitoringSetting.getComponentConfigurationMode();
        String componentNameOrArn = getComponentNameOrARNFromComponentMonitoringSetting(componentMonitoringSetting);

        if (mode.equals(CUSTOM_COMPONENT_CONFIG_MODE)) {
            InputComponentConfiguration inputConfig =
                    new InputComponentConfiguration(componentMonitoringSetting.getCustomComponentConfiguration());

            ObjectMapper mapper = new ObjectMapper();
            mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
            String componentConfiguration = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(inputConfig);

            logger.log("Component name or ARN: " + componentNameOrArn);
            logger.log("Component Configuration String (CUSTOM mode): " + componentConfiguration);

            proxy.injectCredentialsAndInvokeV2(UpdateComponentConfigurationRequest.builder()
                            .resourceGroupName(model.getResourceGroupName())
                            .componentName(componentNameOrArn)
                            .monitor(true)
                            .tier(componentMonitoringSetting.getTier())
                            .componentConfiguration(componentConfiguration)
                            .build(),
                    applicationInsightsClient::updateComponentConfiguration);
        } else if (mode.equals(DEFAULT_COMPONENT_CONFIG_MODE)) {

            createDefaultComponentConfiguration(
                    componentNameOrArn, componentMonitoringSetting.getTier(), model, proxy, applicationInsightsClient, logger);

        } else if (mode.equals(DEFAULT_WITH_OVERWRITE_COMPONENT_CONFIG_MODE)) {
            DescribeComponentConfigurationRecommendationResponse describeComponentConfigurationRecommendationResponse =
                    proxy.injectCredentialsAndInvokeV2(DescribeComponentConfigurationRecommendationRequest.builder()
                                    .resourceGroupName(model.getResourceGroupName())
                                    .componentName(componentNameOrArn)
                                    .tier(componentMonitoringSetting.getTier())
                                    .build(),
                            applicationInsightsClient::describeComponentConfigurationRecommendation);

            logger.log("Component name or ARN: " + componentNameOrArn);
            String recomendedComponentConfigurationString =
                    describeComponentConfigurationRecommendationResponse.componentConfiguration();
            logger.log("Recommended Component Configuration String (DEFAULT_WITH_OVERWRITE mode): " + recomendedComponentConfigurationString);

            ObjectMapper mapper = new ObjectMapper()
                    .configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true)
                    .setSerializationInclusion(JsonInclude.Include.NON_NULL);
            InputComponentConfiguration recommendedInputConfig = mapper.readValue(
                    recomendedComponentConfigurationString, InputComponentConfiguration.class);

            logger.log("Recommended Component Configuration String transformed (DEFAULT_WITH_OVERWRITE mode): " +
                    mapper.writerWithDefaultPrettyPrinter().writeValueAsString(recommendedInputConfig));

            InputComponentConfiguration recommendedInputConfigWithOverwrite =
                    new InputComponentConfiguration(recommendedInputConfig, componentMonitoringSetting.getDefaultOverwriteComponentConfiguration());

            // Same as CUSTOM flow
            String componentConfiguration = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(recommendedInputConfigWithOverwrite);

            logger.log("Component Configuration String (DEFAULT_WITH_OVERWRITE mode): " + componentConfiguration);

            proxy.injectCredentialsAndInvokeV2(UpdateComponentConfigurationRequest.builder()
                            .resourceGroupName(model.getResourceGroupName())
                            .componentName(componentNameOrArn)
                            .monitor(true)
                            .tier(componentMonitoringSetting.getTier())
                            .componentConfiguration(componentConfiguration)
                            .build(),
                    applicationInsightsClient::updateComponentConfiguration);
        }
    }