use of com.amazonaws.services.personalize.model.CreateCampaignResult 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;
}
Aggregations