Search in sources :

Example 1 with BatchPredictionJobName

use of com.google.cloud.aiplatform.v1.BatchPredictionJobName in project java-aiplatform by googleapis.

the class GetBatchPredictionJobSample method getBatchPredictionJobSample.

static void getBatchPredictionJobSample(String project, String batchPredictionJobId) throws IOException {
    JobServiceSettings jobServiceSettings = JobServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (JobServiceClient jobServiceClient = JobServiceClient.create(jobServiceSettings)) {
        String location = "us-central1";
        BatchPredictionJobName batchPredictionJobName = BatchPredictionJobName.of(project, location, batchPredictionJobId);
        BatchPredictionJob batchPredictionJob = jobServiceClient.getBatchPredictionJob(batchPredictionJobName);
        System.out.println("Get Batch Prediction Job Response");
        System.out.format("\tName: %s\n", batchPredictionJob.getName());
        System.out.format("\tDisplay Name: %s\n", batchPredictionJob.getDisplayName());
        System.out.format("\tModel: %s\n", batchPredictionJob.getModel());
        System.out.format("\tModel Parameters: %s\n", batchPredictionJob.getModelParameters());
        System.out.format("\tState: %s\n", batchPredictionJob.getState());
        System.out.format("\tCreate Time: %s\n", batchPredictionJob.getCreateTime());
        System.out.format("\tStart Time: %s\n", batchPredictionJob.getStartTime());
        System.out.format("\tEnd Time: %s\n", batchPredictionJob.getEndTime());
        System.out.format("\tUpdate Time: %s\n", batchPredictionJob.getUpdateTime());
        System.out.format("\tLabels: %s\n", batchPredictionJob.getLabelsMap());
        InputConfig inputConfig = batchPredictionJob.getInputConfig();
        System.out.println("\tInput Config");
        System.out.format("\t\tInstances Format: %s\n", inputConfig.getInstancesFormat());
        GcsSource gcsSource = inputConfig.getGcsSource();
        System.out.println("\t\tGcs Source");
        System.out.format("\t\t\tUris: %s\n", gcsSource.getUrisList());
        BigQuerySource bigquerySource = inputConfig.getBigquerySource();
        System.out.println("\t\tBigquery Source");
        System.out.format("\t\t\tInput Uri: %s\n", bigquerySource.getInputUri());
        OutputConfig outputConfig = batchPredictionJob.getOutputConfig();
        System.out.println("\tOutput Config");
        System.out.format("\t\tPredictions Format: %s\n", outputConfig.getPredictionsFormat());
        GcsDestination gcsDestination = outputConfig.getGcsDestination();
        System.out.println("\t\tGcs Destination");
        System.out.format("\t\t\tOutput Uri Prefix: %s\n", gcsDestination.getOutputUriPrefix());
        BigQueryDestination bigqueryDestination = outputConfig.getBigqueryDestination();
        System.out.println("\t\tBigquery Destination");
        System.out.format("\t\t\tOutput Uri: %s\n", bigqueryDestination.getOutputUri());
        OutputInfo outputInfo = batchPredictionJob.getOutputInfo();
        System.out.println("\tOutput Info");
        System.out.format("\t\tGcs Output Directory: %s\n", outputInfo.getGcsOutputDirectory());
        System.out.format("\t\tBigquery Output Dataset: %s\n", outputInfo.getBigqueryOutputDataset());
        Status status = batchPredictionJob.getError();
        System.out.println("\tError");
        System.out.format("\t\tCode: %s\n", status.getCode());
        System.out.format("\t\tMessage: %s\n", status.getMessage());
        List<Any> detailsList = status.getDetailsList();
        for (Status partialFailure : batchPredictionJob.getPartialFailuresList()) {
            System.out.println("\tPartial Failure");
            System.out.format("\t\tCode: %s\n", partialFailure.getCode());
            System.out.format("\t\tMessage: %s\n", partialFailure.getMessage());
            List<Any> details = partialFailure.getDetailsList();
        }
        ResourcesConsumed resourcesConsumed = batchPredictionJob.getResourcesConsumed();
        System.out.println("\tResources Consumed");
        System.out.format("\t\tReplica Hours: %s\n", resourcesConsumed.getReplicaHours());
        CompletionStats completionStats = batchPredictionJob.getCompletionStats();
        System.out.println("\tCompletion Stats");
        System.out.format("\t\tSuccessful Count: %s\n", completionStats.getSuccessfulCount());
        System.out.format("\t\tFailed Count: %s\n", completionStats.getFailedCount());
        System.out.format("\t\tIncomplete Count: %s\n", completionStats.getIncompleteCount());
    }
}
Also used : Status(com.google.rpc.Status) JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) GcsSource(com.google.cloud.aiplatform.v1.GcsSource) BatchPredictionJob(com.google.cloud.aiplatform.v1.BatchPredictionJob) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient) BigQueryDestination(com.google.cloud.aiplatform.v1.BigQueryDestination) Any(com.google.protobuf.Any) OutputInfo(com.google.cloud.aiplatform.v1.BatchPredictionJob.OutputInfo) OutputConfig(com.google.cloud.aiplatform.v1.BatchPredictionJob.OutputConfig) ResourcesConsumed(com.google.cloud.aiplatform.v1.ResourcesConsumed) BatchPredictionJobName(com.google.cloud.aiplatform.v1.BatchPredictionJobName) InputConfig(com.google.cloud.aiplatform.v1.BatchPredictionJob.InputConfig) BigQuerySource(com.google.cloud.aiplatform.v1.BigQuerySource) GcsDestination(com.google.cloud.aiplatform.v1.GcsDestination) CompletionStats(com.google.cloud.aiplatform.v1.CompletionStats)

Example 2 with BatchPredictionJobName

use of com.google.cloud.aiplatform.v1.BatchPredictionJobName in project java-aiplatform by googleapis.

the class DeleteBatchPredictionJobSample method deleteBatchPredictionJobSample.

static void deleteBatchPredictionJobSample(String project, String batchPredictionJobId) throws IOException, InterruptedException, ExecutionException, TimeoutException {
    JobServiceSettings jobServiceSettings = JobServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (JobServiceClient jobServiceClient = JobServiceClient.create(jobServiceSettings)) {
        String location = "us-central1";
        BatchPredictionJobName batchPredictionJobName = BatchPredictionJobName.of(project, location, batchPredictionJobId);
        OperationFuture<Empty, DeleteOperationMetadata> operationFuture = jobServiceClient.deleteBatchPredictionJobAsync(batchPredictionJobName);
        System.out.format("Operation name: %s\n", operationFuture.getInitialFuture().get().getName());
        System.out.println("Waiting for operation to finish...");
        operationFuture.get(300, TimeUnit.SECONDS);
        System.out.println("Deleted Batch Prediction Job.");
    }
}
Also used : JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) Empty(com.google.protobuf.Empty) BatchPredictionJobName(com.google.cloud.aiplatform.v1.BatchPredictionJobName) DeleteOperationMetadata(com.google.cloud.aiplatform.v1.DeleteOperationMetadata) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient)

Example 3 with BatchPredictionJobName

use of com.google.cloud.aiplatform.v1.BatchPredictionJobName in project java-aiplatform by googleapis.

the class CancelBatchPredictionJobSample method cancelBatchPredictionJobSample.

static void cancelBatchPredictionJobSample(String project, String batchPredictionJobId) throws IOException {
    JobServiceSettings jobServiceSettings = JobServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (JobServiceClient jobServiceClient = JobServiceClient.create(jobServiceSettings)) {
        String location = "us-central1";
        BatchPredictionJobName batchPredictionJobName = BatchPredictionJobName.of(project, location, batchPredictionJobId);
        jobServiceClient.cancelBatchPredictionJob(batchPredictionJobName);
        System.out.println("Cancelled the Batch Prediction Job");
    }
}
Also used : JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) BatchPredictionJobName(com.google.cloud.aiplatform.v1.BatchPredictionJobName) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient)

Aggregations

BatchPredictionJobName (com.google.cloud.aiplatform.v1.BatchPredictionJobName)3 JobServiceClient (com.google.cloud.aiplatform.v1.JobServiceClient)3 JobServiceSettings (com.google.cloud.aiplatform.v1.JobServiceSettings)3 BatchPredictionJob (com.google.cloud.aiplatform.v1.BatchPredictionJob)1 InputConfig (com.google.cloud.aiplatform.v1.BatchPredictionJob.InputConfig)1 OutputConfig (com.google.cloud.aiplatform.v1.BatchPredictionJob.OutputConfig)1 OutputInfo (com.google.cloud.aiplatform.v1.BatchPredictionJob.OutputInfo)1 BigQueryDestination (com.google.cloud.aiplatform.v1.BigQueryDestination)1 BigQuerySource (com.google.cloud.aiplatform.v1.BigQuerySource)1 CompletionStats (com.google.cloud.aiplatform.v1.CompletionStats)1 DeleteOperationMetadata (com.google.cloud.aiplatform.v1.DeleteOperationMetadata)1 GcsDestination (com.google.cloud.aiplatform.v1.GcsDestination)1 GcsSource (com.google.cloud.aiplatform.v1.GcsSource)1 ResourcesConsumed (com.google.cloud.aiplatform.v1.ResourcesConsumed)1 Any (com.google.protobuf.Any)1 Empty (com.google.protobuf.Empty)1 Status (com.google.rpc.Status)1