Search in sources :

Example 1 with CreateCampaignRequest

use of com.amazonaws.services.personalize.model.CreateCampaignRequest in project knime-cloud by knime.

the class AmazonPersonalizeCreateCampaignNodeModel method execute.

/**
 * {@inheritDoc}
 */
@Override
protected PortObject[] execute(final PortObject[] inObjects, final ExecutionContext exec) throws Exception {
    final CloudConnectionInformation cxnInfo = ((AmazonConnectionInformationPortObject) inObjects[0]).getConnectionInformation();
    try (final AmazonPersonalizeConnection personalizeConnection = new AmazonPersonalizeConnection(cxnInfo)) {
        final AmazonPersonalize personalizeClient = personalizeConnection.getClient();
        final CreateCampaignRequest createCampaignRequest = new CreateCampaignRequest();
        final CreateCampaignResult campaign = personalizeClient.createCampaign(createCampaignRequest.withName(m_settings.getCampaignName()).withSolutionVersionArn(m_settings.getSolutionVersion().getARN()).withMinProvisionedTPS(m_settings.getMinProvisionedTPS()));
        // TODO Test update of existing campaign
        try {
            final DescribeCampaignRequest describeCampaignRequest = new DescribeCampaignRequest().withCampaignArn(campaign.getCampaignArn());
            AmazonPersonalizeUtils.waitUntilActive(() -> {
                final DescribeCampaignResult campaignDescription = personalizeClient.describeCampaign(describeCampaignRequest);
                final String status = campaignDescription.getCampaign().getStatus();
                exec.setMessage("Creating campaign (Status: " + status + ")");
                if (status.equals(Status.CREATED_FAILED.getStatus())) {
                    personalizeClient.deleteCampaign(new DeleteCampaignRequest().withCampaignArn(campaignDescription.getCampaign().getCampaignArn()));
                    throw new IllegalStateException("No campaign has been created. Reason: " + campaignDescription.getCampaign().getFailureReason());
                }
                return status.equals(Status.ACTIVE.getStatus());
            }, 1000);
        } catch (InterruptedException e) {
            // TODO
            throw e;
        }
        if (m_settings.isOutputCampaignArnAsVar()) {
            pushFlowVariableString("campaign-ARN", campaign.getCampaignArn());
        }
    }
    return null;
}
Also used : AmazonPersonalizeConnection(org.knime.cloud.aws.mlservices.nodes.personalize.AmazonPersonalizeConnection) DescribeCampaignRequest(com.amazonaws.services.personalize.model.DescribeCampaignRequest) DeleteCampaignRequest(com.amazonaws.services.personalize.model.DeleteCampaignRequest) AmazonConnectionInformationPortObject(org.knime.cloud.aws.util.AmazonConnectionInformationPortObject) CreateCampaignResult(com.amazonaws.services.personalize.model.CreateCampaignResult) DescribeCampaignResult(com.amazonaws.services.personalize.model.DescribeCampaignResult) AmazonPersonalize(com.amazonaws.services.personalize.AmazonPersonalize) CloudConnectionInformation(org.knime.cloud.core.util.port.CloudConnectionInformation) CreateCampaignRequest(com.amazonaws.services.personalize.model.CreateCampaignRequest)

Aggregations

AmazonPersonalize (com.amazonaws.services.personalize.AmazonPersonalize)1 CreateCampaignRequest (com.amazonaws.services.personalize.model.CreateCampaignRequest)1 CreateCampaignResult (com.amazonaws.services.personalize.model.CreateCampaignResult)1 DeleteCampaignRequest (com.amazonaws.services.personalize.model.DeleteCampaignRequest)1 DescribeCampaignRequest (com.amazonaws.services.personalize.model.DescribeCampaignRequest)1 DescribeCampaignResult (com.amazonaws.services.personalize.model.DescribeCampaignResult)1 AmazonPersonalizeConnection (org.knime.cloud.aws.mlservices.nodes.personalize.AmazonPersonalizeConnection)1 AmazonConnectionInformationPortObject (org.knime.cloud.aws.util.AmazonConnectionInformationPortObject)1 CloudConnectionInformation (org.knime.cloud.core.util.port.CloudConnectionInformation)1