public ProgressEvent handleRequest()

in aws-timestream-database/src/main/java/software/amazon/timestream/database/CreateHandler.java [47:106]


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

        timestreamClient = TimestreamClientFactory.get(proxy, logger);
        this.proxy = proxy;

        final ResourceModel model = request.getDesiredResourceState();

        // resource can auto-generate a name if not supplied by caller
        // this logic should move up into the CloudFormation engine, but
        // currently exists here for backwards-compatibility with existing models
        if (StringUtils.isNullOrEmpty(model.getDatabaseName())) {
            model.setDatabaseName(
                    IdentifierUtils.generateResourceIdentifier(
                            request.getLogicalResourceIdentifier(),
                            request.getClientRequestToken(),
                            DATABASE_NAME_MAX_LENGTH
                    ));
        }

        final CreateDatabaseRequest createDatabaseRequest = new CreateDatabaseRequest()
                .withDatabaseName(model.getDatabaseName())
                .withKmsKeyId(model.getKmsKeyId());

        final Set<Tag> tags = TagHelper.convertToSet(
                TagHelper.generateTagsForCreate(model, request));
        if (tags != null & !tags.isEmpty()) {
            createDatabaseRequest.withTags(tags.stream().map(
                    tag -> new com.amazonaws.services.timestreamwrite.model.Tag()
                            .withKey(tag.getKey())
                            .withValue(tag.getValue()))
                    .collect(Collectors.toList()));
        }

        try {
            final CreateDatabaseResult result =
                    this.proxy.injectCredentialsAndInvoke(createDatabaseRequest, timestreamClient::createDatabase);
            model.setArn(result.getDatabase().getArn());
        } catch (ConflictException ex) {
            throw new CfnAlreadyExistsException(ResourceModel.TYPE_NAME, model.getDatabaseName(), ex);
        } catch (ValidationException | InvalidEndpointException ex) {
            throw new CfnInvalidRequestException(request.toString(), ex);
        } catch (AccessDeniedException ex) {
            throw new CfnAccessDeniedException(CREATE_DATABASE, ex);
        } catch (ServiceQuotaExceededException ex) {
            throw new CfnServiceLimitExceededException(ResourceModel.TYPE_NAME, QUOTE_MESSAGE, ex);
        } catch(ThrottlingException ex) {
            throw new CfnThrottlingException(CREATE_DATABASE, ex);
        } catch(InternalServerException ex) {
            throw new CfnInternalFailureException(ex);
        }

        return ProgressEvent.<ResourceModel, CallbackContext>builder()
                .resourceModel(model)
                .status(OperationStatus.SUCCESS)
                .build();
    }