use of io.adminshell.aas.v3.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;
}
}
use of io.adminshell.aas.v3.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();
}
use of io.adminshell.aas.v3.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.");
}
}
use of io.adminshell.aas.v3.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);
}
}
use of io.adminshell.aas.v3.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);
}
}
Aggregations