Search in sources :

Example 1 with Operation

use of com.google.api.services.notebooks.v1.model.Operation in project google-cloud-intellij by GoogleCloudPlatform.

the class GoogleApiClientAppEngineAdminService method createApplication.

@Override
public Application createApplication(@NotNull String locationId, @NotNull final String projectId, @NotNull final Credential credential) throws IOException, GoogleApiException {
    Application arg = new Application();
    arg.setId(projectId);
    arg.setLocationId(locationId);
    Apps.Create createRequest = GoogleApiClientFactory.getInstance().getAppEngineApiClient(credential).apps().create(arg);
    Operation operation;
    try {
        // make the initial request to create the application
        operation = createRequest.execute();
        // poll for updates while the application is being created
        boolean done = false;
        while (!done) {
            try {
                Thread.sleep(CREATE_APPLICATION_POLLING_INTERVAL_MS);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            operation = getOperation(projectId, operation.getName(), credential);
            if (operation.getDone() != null) {
                done = operation.getDone();
            }
        }
    } catch (GoogleJsonResponseException e) {
        throw GoogleApiException.from(e);
    }
    if (operation.getError() != null) {
        Status status = operation.getError();
        throw new GoogleApiException(status.getMessage(), status.getCode());
    } else {
        Application result = new Application();
        result.putAll(operation.getResponse());
        return result;
    }
}
Also used : Status(com.google.api.services.appengine.v1.model.Status) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) Operation(com.google.api.services.appengine.v1.model.Operation) Application(com.google.api.services.appengine.v1.model.Application) Apps(com.google.api.services.appengine.v1.Appengine.Apps)

Example 2 with Operation

use of com.google.api.services.notebooks.v1.model.Operation in project google-cloud-intellij by GoogleCloudPlatform.

the class GoogleApiClientAppEngineAdminServiceTest method testCreateApplication_operationFailed.

@Test
public void testCreateApplication_operationFailed() throws IOException, GoogleApiException {
    String operationName = "apps/-/operations/12345";
    Operation inProgressOperation = buildInProgressOperation(operationName);
    when(appengineClientMock.getAppsCreateQuery().execute()).thenReturn(inProgressOperation);
    String errorMessage = "The operation failed.";
    int errorCode = 400;
    Status status = new Status();
    status.setMessage(errorMessage);
    status.setCode(errorCode);
    Operation failedOperation = new Operation();
    failedOperation.setError(status);
    failedOperation.setDone(true);
    failedOperation.setName(operationName);
    when(appengineClientMock.getAppsCreateQuery().execute()).thenReturn(inProgressOperation);
    when(appengineClientMock.getAppsOperationsGetQuery().execute()).thenReturn(failedOperation);
    try {
        service.createApplication("us-east", "my-project-id", mock(Credential.class));
    } catch (GoogleApiException expected) {
        assertEquals(errorCode, expected.getStatusCode());
        assertEquals(errorMessage, expected.getMessage());
        return;
    }
    fail();
}
Also used : Status(com.google.api.services.appengine.v1.model.Status) Credential(com.google.api.client.auth.oauth2.Credential) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Operation(com.google.api.services.appengine.v1.model.Operation) Test(org.junit.Test)

Example 3 with Operation

use of com.google.api.services.notebooks.v1.model.Operation in project java-docs-samples by GoogleCloudPlatform.

the class CheckLatestTransferOperationApiary method checkLatestTransferOperationApiary.

// Gets the requested transfer job and checks its latest operation
public static void checkLatestTransferOperationApiary(String projectId, String jobName) throws IOException {
    // Your Google Cloud Project ID
    // String projectId = "your-project-id";
    // The name of the job to check
    // String jobName = "myJob/1234567890";
    // Create Storage Transfer client
    GoogleCredentials credential = GoogleCredentials.getApplicationDefault();
    if (credential.createScopedRequired()) {
        credential = credential.createScoped(StoragetransferScopes.all());
    }
    Storagetransfer storageTransfer = new Storagetransfer.Builder(Utils.getDefaultTransport(), Utils.getDefaultJsonFactory(), new HttpCredentialsAdapter(credential)).build();
    // Get transfer job and check latest operation
    TransferJob transferJob = storageTransfer.transferJobs().get(jobName, projectId).execute();
    String latestOperationName = transferJob.getLatestOperationName();
    if (latestOperationName != null) {
        Operation latestOperation = storageTransfer.transferOperations().get(latestOperationName).execute();
        System.out.println("The latest operation for transfer job " + jobName + " is:");
        System.out.println(latestOperation.toPrettyString());
    } else {
        System.out.println("Transfer job " + jobName + " does not have an operation scheduled yet," + " try again once the job starts running.");
    }
}
Also used : HttpCredentialsAdapter(com.google.auth.http.HttpCredentialsAdapter) GoogleCredentials(com.google.auth.oauth2.GoogleCredentials) Operation(com.google.api.services.storagetransfer.v1.model.Operation) Storagetransfer(com.google.api.services.storagetransfer.v1.Storagetransfer) TransferJob(com.google.api.services.storagetransfer.v1.model.TransferJob)

Example 4 with Operation

use of com.google.api.services.notebooks.v1.model.Operation in project java-docs-samples by GoogleCloudPlatform.

the class DicomStoreImport method dicomStoreImport.

public static void dicomStoreImport(String dicomStoreName, String gcsUri) throws IOException {
    // String dicomStoreName =
    // String.format(
    // DICOM_NAME, "your-project-id", "your-region-id", "your-dataset-id", "your-dicom-id");
    // String gcsUri = "gs://your-bucket-id/path/to/destination/dir"
    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();
    // Configure where the store should be imported from.
    GoogleCloudHealthcareV1DicomGcsSource gcsSource = new GoogleCloudHealthcareV1DicomGcsSource().setUri(gcsUri);
    ImportDicomDataRequest importRequest = new ImportDicomDataRequest().setGcsSource(gcsSource);
    // Create request and configure any parameters.
    DicomStores.CloudHealthcareImport request = client.projects().locations().datasets().dicomStores().healthcareImport(dicomStoreName, importRequest);
    // Execute the request, wait for the operation to complete, and process the results.
    try {
        Operation operation = request.execute();
        while (operation.getDone() == null || !operation.getDone()) {
            // Update the status of the operation with another request.
            // Pause for 500ms between requests.
            Thread.sleep(500);
            operation = client.projects().locations().datasets().operations().get(operation.getName()).execute();
        }
        System.out.println("DICOM store import complete." + operation.getResponse());
    } catch (Exception ex) {
        System.out.printf("Error during request execution: %s", ex.toString());
        ex.printStackTrace(System.out);
    }
}
Also used : GoogleCloudHealthcareV1DicomGcsSource(com.google.api.services.healthcare.v1.model.GoogleCloudHealthcareV1DicomGcsSource) DicomStores(com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets.DicomStores) CloudHealthcare(com.google.api.services.healthcare.v1.CloudHealthcare) ImportDicomDataRequest(com.google.api.services.healthcare.v1.model.ImportDicomDataRequest) Operation(com.google.api.services.healthcare.v1.model.Operation) IOException(java.io.IOException)

Example 5 with Operation

use of com.google.api.services.notebooks.v1.model.Operation in project java-docs-samples by GoogleCloudPlatform.

the class DatasetCreate method datasetCreate.

public static void datasetCreate(String projectId, String regionId, String datasetId) throws IOException {
    // String projectId = "your-project-id";
    // String regionId = "us-central1";
    // String datasetId = "your-dataset-id";
    // Initialize the client, which will be used to interact with the service.
    CloudHealthcare client = createClient();
    // Configure the dataset to be created.
    Dataset dataset = new Dataset();
    dataset.setTimeZone("America/Chicago");
    // Create request and configure any parameters.
    String parentName = String.format("projects/%s/locations/%s", projectId, regionId);
    Datasets.Create request = client.projects().locations().datasets().create(parentName, dataset);
    request.setDatasetId(datasetId);
    // Execute the request, wait for the operation to complete, and process the results.
    try {
        Operation operation = request.execute();
        System.out.println(operation.toPrettyString());
        while (operation.getDone() == null || !operation.getDone()) {
            // Update the status of the operation with another request.
            // Pause for 500ms between requests.
            Thread.sleep(500);
            operation = client.projects().locations().datasets().operations().get(operation.getName()).execute();
        }
        System.out.println("Dataset created. Response content: " + operation.getResponse());
    } catch (Exception ex) {
        System.out.printf("Error during request execution: %s\n", ex.toString());
        ex.printStackTrace(System.out);
    }
}
Also used : Datasets(com.google.api.services.healthcare.v1.CloudHealthcare.Projects.Locations.Datasets) Dataset(com.google.api.services.healthcare.v1.model.Dataset) CloudHealthcare(com.google.api.services.healthcare.v1.CloudHealthcare) Operation(com.google.api.services.healthcare.v1.model.Operation) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)14 Operation (io.adminshell.aas.v3.model.Operation)8 Test (org.junit.Test)7 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)6 CloudHealthcare (com.google.api.services.healthcare.v1.CloudHealthcare)6 Operation (com.google.api.services.healthcare.v1.model.Operation)6 Operation (com.google.api.services.notebooks.v1.model.Operation)5 Reference (io.adminshell.aas.v3.model.Reference)5 List (java.util.List)5 StepResult (bio.terra.stairway.StepResult)4 Operation (com.google.api.services.appengine.v1.model.Operation)4 Create (com.google.api.services.container.v1beta1.Container.Projects.Locations.Clusters.Create)4 Operation (com.google.api.services.container.v1beta1.model.Operation)4 ResourceNotFoundException (de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)4 MessageBus (de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus)4 OperationResult (de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult)4 AIPlatformNotebooksCow (bio.terra.cloudres.google.notebooks.AIPlatformNotebooksCow)3 InstanceName (bio.terra.cloudres.google.notebooks.InstanceName)3 GcpCloudContext (bio.terra.workspace.service.workspace.model.GcpCloudContext)3 Status (com.google.api.services.appengine.v1.model.Status)3