use of com.amazonaws.services.personalize.model.CreateSolutionVersionRequest in project knime-cloud by knime.
the class AmazonPersonalizeCreateSolutionVersionNodeModel 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();
// Create solution configuration or use existing one
final String solutionArn;
if (m_settings.isCreateNewSolution()) {
solutionArn = createSolution(personalizeClient);
} else {
solutionArn = m_settings.getExistingSolution().getARN();
}
// Wait until the solution is active
final DescribeSolutionRequest describeSolutionRequest = new DescribeSolutionRequest().withSolutionArn(solutionArn);
AmazonPersonalizeUtils.waitUntilActive(() -> {
DescribeSolutionResult describeSolution = personalizeClient.describeSolution(describeSolutionRequest);
final String status = describeSolution.getSolution().getStatus();
exec.setMessage("Creating solution configuration (Status: " + status + ")");
return status.equals(Status.ACTIVE.getStatus());
}, 100);
exec.setProgress(0.5);
// Create solution version
final String solutionVersionArn = personalizeClient.createSolutionVersion(new CreateSolutionVersionRequest().withSolutionArn(solutionArn)).getSolutionVersionArn();
// Wait until solution version is active (or failed)
final DescribeSolutionVersionRequest describeSolutionVersionRequest = new DescribeSolutionVersionRequest().withSolutionVersionArn(solutionVersionArn);
AmazonPersonalizeUtils.waitUntilActive(() -> {
final DescribeSolutionVersionResult solutionVersionDescription = personalizeClient.describeSolutionVersion(describeSolutionVersionRequest);
final String status = solutionVersionDescription.getSolutionVersion().getStatus();
exec.setMessage("Creating solution version (Status: " + status + ")");
if (status.equals(Status.CREATED_FAILED.getStatus())) {
throw new IllegalStateException("No solution version has been created. Reason: " + solutionVersionDescription.getSolutionVersion().getFailureReason());
}
return status.equals(Status.ACTIVE.getStatus());
}, 2000);
// Retrieve the recipe type to put it into the output
final DescribeSolutionVersionResult solutionVersionDescription = personalizeClient.describeSolutionVersion(describeSolutionVersionRequest);
final String recipeType = personalizeClient.describeRecipe(new DescribeRecipeRequest().withRecipeArn(solutionVersionDescription.getSolutionVersion().getRecipeArn())).getRecipe().getRecipeType();
// final String recipeType = personalizeClient.describeRecipe(new DescribeRecipeRequest().withRecipeArn(
// personalizeClient.describeSolution(new DescribeSolutionRequest().withSolutionArn(solutionArn))
// .getSolution().getRecipeArn()))
// .getRecipe().getRecipeType();
// Create output
final Map<String, Double> metrics = personalizeClient.getSolutionMetrics(new GetSolutionMetricsRequest().withSolutionVersionArn(solutionVersionArn)).getMetrics();
if (m_settings.isOutputSolutionVersionArnAsVar()) {
pushFlowVariableString("solution-version-ARN", solutionVersionArn);
}
return new PortObject[] { createOutput(exec, solutionVersionArn, recipeType, metrics) };
}
}
Aggregations