use of com.google.api.services.container.v1beta1.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);
}
}
use of com.google.api.services.container.v1beta1.model.Operation in project terra-cloud-resource-lib by DataBiosphere.
the class ServiceUsageCowTest method listAndEnableServices.
@Test
public void listAndEnableServices() throws Exception {
ServiceUsageCow serviceUsage = defaultServiceUsage();
Project project = ProjectUtils.executeCreateProject();
String projectName = projectIdToName(project.getProjectId());
String storageServiceName = serviceName(project, STORAGE_SERVICE_ID);
ListServicesResponse response1 = serviceUsage.services().list(projectName).setFilter(ENABLED_FILTER).execute();
assertNull(response1.getServices());
Operation operation = serviceUsage.services().batchEnable(projectName, new BatchEnableServicesRequest().setServiceIds(ImmutableList.of(STORAGE_SERVICE_ID))).execute();
OperationTestUtils.pollAndAssertSuccess(serviceUsage.operations().operationCow(operation), Duration.ofSeconds(5), Duration.ofSeconds(60));
ListServicesResponse response2 = serviceUsage.services().list(projectName).setFilter(ENABLED_FILTER).execute();
List<String> services2 = response2.getServices().stream().map(Service::getName).collect(Collectors.toList());
assertThat(services2, Matchers.hasItem(storageServiceName));
}
use of com.google.api.services.container.v1beta1.model.Operation in project terra-cloud-resource-lib by DataBiosphere.
the class ServiceUsageUtils method enableServices.
/**
* Enables batch services for a project.
*
* @param projectId: The projectId to enable services on.
* @param services: Services to be enabled. See {@link BatchEnableServicesRequest}
*/
public static void enableServices(String projectId, List<String> services) throws Exception {
Operation operation = getServiceUsageCow().services().batchEnable(projectIdToName(projectId), new BatchEnableServicesRequest().setServiceIds(services)).execute();
OperationTestUtils.pollAndAssertSuccess(serviceUsageCow.operations().operationCow(operation), Duration.ofSeconds(5), Duration.ofSeconds(100));
}
use of com.google.api.services.container.v1beta1.model.Operation in project terra-cli by DataBiosphere.
the class GoogleNotebooks method stop.
public void stop(InstanceName instanceName) {
try {
Operation stopOperation = notebooks.instances().stop(instanceName).execute();
pollForSuccess(stopOperation, "Error stopping notebook instance: ");
} catch (InterruptedException | IOException e) {
checkFor409BadState(e);
throw new SystemException("Error stopping notebook instance", e);
}
}
use of com.google.api.services.container.v1beta1.model.Operation in project google-cloud-intellij by GoogleCloudPlatform.
the class GoogleApiClientAppEngineAdminServiceTest method testCreateApplication.
@Test
public void testCreateApplication() throws IOException, GoogleApiException {
String operationId = "my-operation-id";
String operationName = "apps/-/operations/" + operationId;
Operation inProgressOperation = buildInProgressOperation(operationName);
when(appengineClientMock.getAppsCreateQuery().execute()).thenReturn(inProgressOperation);
final String locationId = "us-east1";
final String projectId = "my-project";
Map<String, Object> response = new HashMap<>();
response.put("name", projectId);
response.put("locationId", locationId);
Operation doneOperation = new Operation();
doneOperation.setName(operationName);
doneOperation.setDone(true);
doneOperation.setResponse(response);
// require polling several times
when(appengineClientMock.getAppsOperationsGetQuery().execute()).thenReturn(inProgressOperation).thenReturn(inProgressOperation).thenReturn(doneOperation);
Application result = service.createApplication(locationId, projectId, mock(Credential.class));
// ensure the 'getOperation' API call(s) were made correctly
verify(appengineClientMock.apps().operations(), atLeastOnce()).get(eq(projectId), eq(operationId));
// ensure the 'createApplication' API call was made with the correct args
verify(appengineClientMock.apps(), times(1)).create(argThat(application -> application.getId().equals(projectId) && application.getLocationId().equals(locationId)));
// ensure the 'createApplication' API call was only made once
verify(appengineClientMock.getAppsCreateQuery(), times(1)).execute();
assertEquals(projectId, result.getName());
assertEquals(locationId, result.getLocationId());
}
Aggregations