public ProgressEvent handleRequest()

in aws-iot-fleetmetric/src/main/java/com/amazonaws/iot/fleetmetric/ReadHandler.java [26:74]


    public ProgressEvent<ResourceModel, CallbackContext> handleRequest(
            AmazonWebServicesClientProxy proxy,
            ResourceHandlerRequest<ResourceModel> request,
            CallbackContext callbackContext,
            Logger logger) {

        ResourceModel model = request.getDesiredResourceState();

        DescribeFleetMetricRequest describeFleetMetricRequest = DescribeFleetMetricRequest.builder()
                .metricName(model.getMetricName())
                .build();

        DescribeFleetMetricResponse describeFleetMetricResponse;
        try {
            describeFleetMetricResponse = proxy.injectCredentialsAndInvokeV2(
                    describeFleetMetricRequest, iotClient::describeFleetMetric);
        } catch (RuntimeException e) {
            return Translator.translateExceptionToProgressEvent(model, e, logger);
        }

        String metricArn = describeFleetMetricResponse.metricArn();
        logger.log(String.format("Called Describe for %s.", metricArn));

        // Now call ListTagsForResource, because describe API doesn't provide the tags.
        List<software.amazon.awssdk.services.iot.model.Tag> iotTags = listTags(proxy, metricArn, logger);
        logger.log(String.format("Called ListTags for %s.", metricArn));

        Set<Tag> responseTags = Translator.translateTagsToCfn(iotTags);

        logger.log(String.format("Successfully described %s.", metricArn));

        return ProgressEvent.defaultSuccessHandler(
                ResourceModel.builder()
                        .metricName(describeFleetMetricResponse.metricName())
                        .metricArn(describeFleetMetricResponse.metricArn())
                        .description(describeFleetMetricResponse.description())
                        .queryString(describeFleetMetricResponse.queryString())
                        .period(describeFleetMetricResponse.period())
                        .aggregationField(describeFleetMetricResponse.aggregationField())
                        .queryVersion(describeFleetMetricResponse.queryVersion())
                        .indexName(describeFleetMetricResponse.indexName())
                        .unit(describeFleetMetricResponse.unitAsString())
                        .aggregationType(AggregationType.builder()
                                .name(describeFleetMetricResponse.aggregationType().nameAsString())
                                .values(describeFleetMetricResponse.aggregationType().values())
                                .build())
                        .tags(responseTags)
                        .build());
    }