use of com.amazonaws.services.personalize.model.InvalidInputException in project knime-cloud by knime.
the class AbstractAmazonPersonalizeDataUploadNodeModel method importDataFromS3.
private void importDataFromS3(final AmazonPersonalize personalizeClient, final String s3FilePath, final String datasetArn, final ExecutionContext exec) throws InterruptedException {
// Start the job that imports the dataset from S3
final DataSource dataSource = new DataSource().withDataLocation(s3FilePath);
final String jobName = m_settings.getPrefixImportJobName() + "-" + System.currentTimeMillis();
final String datasetImportJobArn;
try {
datasetImportJobArn = personalizeClient.createDatasetImportJob(new CreateDatasetImportJobRequest().withDatasetArn(datasetArn).withRoleArn(m_settings.getIamServiceRoleArn()).withDataSource(dataSource).withJobName(jobName)).getDatasetImportJobArn();
} catch (InvalidInputException e) {
throw new IllegalArgumentException("The input is invalid. The reason could be too many missing values in one of the input columns. Error " + "message from Amazon: " + e.getErrorMessage(), e);
}
// Wait until status of dataset is ACTIVE
final DescribeDatasetImportJobRequest describeDatasetImportJobRequest = new DescribeDatasetImportJobRequest().withDatasetImportJobArn(datasetImportJobArn);
AmazonPersonalizeUtils.waitUntilActive(() -> {
final DescribeDatasetImportJobResult datasetImportJobDescription = personalizeClient.describeDatasetImportJob(describeDatasetImportJobRequest);
final String status = datasetImportJobDescription.getDatasetImportJob().getStatus();
exec.setMessage("Importing dataset from S3 (Status: " + status + ")");
if (status.equals(Status.CREATED_FAILED.getStatus())) {
throw new IllegalStateException("No dataset has been created. Reason: " + datasetImportJobDescription.getDatasetImportJob().getFailureReason());
}
return status.equals(Status.ACTIVE.getStatus());
}, 2000);
}
Aggregations