Search in sources :

Example 1 with CreateDatasetImportJobRequest

use of com.amazonaws.services.personalize.model.CreateDatasetImportJobRequest 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);
}
Also used : InvalidInputException(com.amazonaws.services.personalize.model.InvalidInputException) CreateDatasetImportJobRequest(com.amazonaws.services.personalize.model.CreateDatasetImportJobRequest) DescribeDatasetImportJobResult(com.amazonaws.services.personalize.model.DescribeDatasetImportJobResult) DataSource(com.amazonaws.services.personalize.model.DataSource) DescribeDatasetImportJobRequest(com.amazonaws.services.personalize.model.DescribeDatasetImportJobRequest)

Aggregations

CreateDatasetImportJobRequest (com.amazonaws.services.personalize.model.CreateDatasetImportJobRequest)1 DataSource (com.amazonaws.services.personalize.model.DataSource)1 DescribeDatasetImportJobRequest (com.amazonaws.services.personalize.model.DescribeDatasetImportJobRequest)1 DescribeDatasetImportJobResult (com.amazonaws.services.personalize.model.DescribeDatasetImportJobResult)1 InvalidInputException (com.amazonaws.services.personalize.model.InvalidInputException)1