public ProgressEvent handleRequest()

in aws-timestream-table/src/main/java/software/amazon/timestream/table/CreateHandler.java [48:114]


    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.getTableName())) {
            model.setTableName(
                    IdentifierUtils.generateResourceIdentifier(
                            request.getLogicalResourceIdentifier(),
                            request.getClientRequestToken(),
                            TABLE_NAME_MAX_LENGTH
                    ));
        }

        final MagneticStoreWriteProperties magneticStoreWriteProperties = MagneticStoreWritePropertiesModelConverter.convert(model.getMagneticStoreWriteProperties());

        final CreateTableRequest createTableRequest =
                new CreateTableRequest()
                        .withDatabaseName(model.getDatabaseName())
                        .withTableName(model.getTableName())
                        .withRetentionProperties(RetentionPropertiesModelConverter.convert(model.getRetentionProperties()))
                        .withMagneticStoreWriteProperties(magneticStoreWriteProperties);

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

        try {
            final CreateTableResult result =
                    this.proxy.injectCredentialsAndInvoke(createTableRequest, timestreamClient::createTable);
            model.setArn(result.getTable().getArn());
        } catch (ConflictException ex) {
            throw new CfnAlreadyExistsException(ResourceModel.TYPE_NAME, model.getTableName(), ex);
        } catch (ValidationException | InvalidEndpointException ex) {
            throw new CfnInvalidRequestException(request.toString(), ex);
        } catch (AccessDeniedException ex) {
            throw new CfnAccessDeniedException(CREATE_TABLE, ex);
        } catch (ResourceNotFoundException ex) {
            throw new CfnNotFoundException("AWS::Timestream::Database", model.getDatabaseName(), ex);
        } catch (ServiceQuotaExceededException ex) {
            throw new CfnServiceLimitExceededException(ResourceModel.TYPE_NAME, QUOTE_MESSAGE, ex);
        } catch (ThrottlingException ex) {
            throw new CfnThrottlingException(CREATE_TABLE, ex);
        } catch (InternalServerException ex) {
            throw new CfnInternalFailureException(ex);
        }

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