Search in sources :

Example 1 with CreateImportJobResult

use of com.amazonaws.services.pinpoint.model.CreateImportJobResult in project aws-doc-sdk-examples by awsdocs.

the class ImportSegment method createImportSegment.

public static ImportJobResponse createImportSegment(AmazonPinpoint client, String appId, String bucket, String key, String roleArn) {
    // Create the job.
    ImportJobRequest importRequest = new ImportJobRequest().withDefineSegment(true).withRegisterEndpoints(true).withRoleArn(roleArn).withFormat(Format.JSON).withS3Url("s3://" + bucket + "/" + key);
    CreateImportJobRequest jobRequest = new CreateImportJobRequest().withImportJobRequest(importRequest).withApplicationId(appId);
    CreateImportJobResult jobResponse = client.createImportJob(jobRequest);
    return jobResponse.getImportJobResponse();
}
Also used : CreateImportJobRequest(com.amazonaws.services.pinpoint.model.CreateImportJobRequest) ImportJobRequest(com.amazonaws.services.pinpoint.model.ImportJobRequest) CreateImportJobRequest(com.amazonaws.services.pinpoint.model.CreateImportJobRequest) CreateImportJobResult(com.amazonaws.services.pinpoint.model.CreateImportJobResult)

Example 2 with CreateImportJobResult

use of com.amazonaws.services.pinpoint.model.CreateImportJobResult in project aws-doc-sdk-examples by awsdocs.

the class ImportEndpoints method importToPinpoint.

private static void importToPinpoint(String endpointsFileName, String s3BucketName, String iamImportRoleArn, String applicationId) {
    // The S3 URL that Amazon Pinpoint requires to find the endpoints file.
    String s3Url = "s3://" + s3BucketName + "/imports/" + endpointsFileName;
    // Defines the import job that Amazon Pinpoint runs.
    ImportJobRequest importJobRequest = new ImportJobRequest().withS3Url(s3Url).withRegisterEndpoints(true).withRoleArn(iamImportRoleArn).withFormat(Format.JSON);
    CreateImportJobRequest createImportJobRequest = new CreateImportJobRequest().withApplicationId(applicationId).withImportJobRequest(importJobRequest);
    // Initializes the Amazon Pinpoint client.
    AmazonPinpoint pinpointClient = AmazonPinpointClientBuilder.standard().withRegion(Regions.US_EAST_1).build();
    System.out.format("Importing endpoints in %s to Amazon Pinpoint application %s . . .\n", endpointsFileName, applicationId);
    try {
        // Runs the import job with Amazon Pinpoint.
        CreateImportJobResult importResult = pinpointClient.createImportJob(createImportJobRequest);
        String jobId = importResult.getImportJobResponse().getId();
        GetImportJobResult getImportJobResult = null;
        String jobStatus = null;
        // Checks the job status until the job completes or fails.
        do {
            getImportJobResult = pinpointClient.getImportJob(new GetImportJobRequest().withJobId(jobId).withApplicationId(applicationId));
            jobStatus = getImportJobResult.getImportJobResponse().getJobStatus();
            System.out.format("Import job %s . . .\n", jobStatus.toLowerCase());
            TimeUnit.SECONDS.sleep(3);
        } while (!jobStatus.equals("COMPLETED") && !jobStatus.equals("FAILED"));
        if (jobStatus.equals("COMPLETED")) {
            System.out.println("Finished importing endpoints.");
        } else {
            System.err.println("Failed to import endpoints.");
            System.exit(1);
        }
        // Checks for entries that failed to import.
        // getFailures provides up to 100 of the first failed entries for the job, if any exist.
        List<String> failedEndpoints = getImportJobResult.getImportJobResponse().getFailures();
        if (failedEndpoints != null) {
            System.out.println("Failed to import the following entries:");
            for (String failedEndpoint : failedEndpoints) {
                System.out.println(failedEndpoint);
            }
        }
    } catch (AmazonServiceException | InterruptedException e) {
        System.err.println(e.getMessage());
        System.exit(1);
    }
}
Also used : GetImportJobResult(com.amazonaws.services.pinpoint.model.GetImportJobResult) AmazonServiceException(com.amazonaws.AmazonServiceException) AmazonPinpoint(com.amazonaws.services.pinpoint.AmazonPinpoint) CreateImportJobRequest(com.amazonaws.services.pinpoint.model.CreateImportJobRequest) ImportJobRequest(com.amazonaws.services.pinpoint.model.ImportJobRequest) GetImportJobRequest(com.amazonaws.services.pinpoint.model.GetImportJobRequest) CreateImportJobRequest(com.amazonaws.services.pinpoint.model.CreateImportJobRequest) CreateImportJobResult(com.amazonaws.services.pinpoint.model.CreateImportJobResult) GetImportJobRequest(com.amazonaws.services.pinpoint.model.GetImportJobRequest)

Aggregations

CreateImportJobRequest (com.amazonaws.services.pinpoint.model.CreateImportJobRequest)2 CreateImportJobResult (com.amazonaws.services.pinpoint.model.CreateImportJobResult)2 ImportJobRequest (com.amazonaws.services.pinpoint.model.ImportJobRequest)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 AmazonPinpoint (com.amazonaws.services.pinpoint.AmazonPinpoint)1 GetImportJobRequest (com.amazonaws.services.pinpoint.model.GetImportJobRequest)1 GetImportJobResult (com.amazonaws.services.pinpoint.model.GetImportJobResult)1