Search in sources :

Example 16 with Operation

use of com.google.api.services.storagetransfer.v1.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(GoogleApiServiceusageV1Service::getName).collect(Collectors.toList());
    assertThat(services2, Matchers.hasItem(storageServiceName));
}
Also used : Project(com.google.api.services.cloudresourcemanager.v3.model.Project) ListServicesResponse(com.google.api.services.serviceusage.v1.model.ListServicesResponse) Operation(com.google.api.services.serviceusage.v1.model.Operation) BatchEnableServicesRequest(com.google.api.services.serviceusage.v1.model.BatchEnableServicesRequest) Test(org.junit.jupiter.api.Test)

Example 17 with Operation

use of com.google.api.services.storagetransfer.v1.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);
    }
}
Also used : SystemException(bio.terra.cli.exception.SystemException) Operation(com.google.api.services.notebooks.v1.model.Operation) IOException(java.io.IOException)

Example 18 with Operation

use of com.google.api.services.storagetransfer.v1.model.Operation in project terra-resource-buffer by DataBiosphere.

the class CreateConsumerDefinedQuotaForBigQueryDailyUsageStep method doStep.

/**
 * Apply a Consumer Quota Override for the BigQuery Query Usage Quota.
 */
@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
    Optional<Long> overrideValue = GoogleProjectConfigUtils.bigQueryDailyUsageOverrideValueMebibytes(gcpProjectConfig);
    if (overrideValue.isEmpty()) {
        // Do not apply any quota override
        return StepResult.getStepResultSuccess();
    }
    long projectNumber = Optional.ofNullable(context.getWorkingMap().get(GOOGLE_PROJECT_NUMBER, Long.class)).orElseThrow();
    QuotaOverride overridePerProjectPerDay = buildQuotaOverride(projectNumber, overrideValue.get());
    // parent format and other details obtained by hitting the endpoint
    // https://serviceusage.googleapis.com/v1beta1/projects/${PROJECT_NUMBER}/services/bigquery.googleapis.com/consumerQuotaMetrics
    String parent = String.format("projects/%d/services/bigquery.googleapis.com/consumerQuotaMetrics/" + "bigquery.googleapis.com%%2Fquota%%2Fquery%%2Fusage/limits/%%2Fd%%2Fproject", projectNumber);
    try {
        // We are decreasing the quota by more than 10%, so we must tell Service Usage to bypass the
        // check with the force flag.
        Operation createOperation = serviceUsageCow.services().consumerQuotaMetrics().limits().consumerOverrides().create(parent, overridePerProjectPerDay).setForce(true).execute();
        OperationCow<Operation> operationCow = serviceUsageCow.operations().operationCow(createOperation);
        pollUntilSuccess(operationCow, Duration.ofSeconds(3), Duration.ofMinutes(5));
    } catch (IOException e) {
        throw new RetryException(e);
    }
    return StepResult.getStepResultSuccess();
}
Also used : QuotaOverride(com.google.api.services.serviceusage.v1beta1.model.QuotaOverride) Operation(com.google.api.services.serviceusage.v1beta1.model.Operation) IOException(java.io.IOException) RetryException(bio.terra.stairway.exception.RetryException) QuotaOverride(com.google.api.services.serviceusage.v1beta1.model.QuotaOverride)

Example 19 with Operation

use of com.google.api.services.storagetransfer.v1.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());
}
Also used : Assert.fail(junit.framework.Assert.fail) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Assert.assertEquals(junit.framework.Assert.assertEquals) Arrays(java.util.Arrays) Application(com.google.api.services.appengine.v1.model.Application) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) Mock(org.mockito.Mock) HashMap(java.util.HashMap) Mockito.spy(org.mockito.Mockito.spy) ArrayList(java.util.ArrayList) Location(com.google.api.services.appengine.v1.model.Location) Mockito.doThrow(org.mockito.Mockito.doThrow) MockitoAnnotations(org.mockito.MockitoAnnotations) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) HttpRequestInitializer(com.google.api.client.http.HttpRequestInitializer) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Map(java.util.Map) Credential(com.google.api.client.auth.oauth2.Credential) Before(org.junit.Before) AppEngineApplicationNotFoundException(com.google.cloud.tools.intellij.appengine.application.GoogleApiClientAppEngineAdminService.AppEngineApplicationNotFoundException) Mockito.atLeastOnce(org.mockito.Mockito.atLeastOnce) HttpTransport(com.google.api.client.http.HttpTransport) ListLocationsResponse(com.google.api.services.appengine.v1.model.ListLocationsResponse) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) GoogleApiClientFactory(com.google.cloud.tools.intellij.resources.GoogleApiClientFactory) Mockito.verify(org.mockito.Mockito.verify) Operation(com.google.api.services.appengine.v1.model.Operation) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) JsonFactory(com.google.api.client.json.JsonFactory) Appengine(com.google.api.services.appengine.v1.Appengine) Status(com.google.api.services.appengine.v1.model.Status) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.mock(org.mockito.Mockito.mock) BasePluginTestCase(com.google.cloud.tools.intellij.testing.BasePluginTestCase) Credential(com.google.api.client.auth.oauth2.Credential) HashMap(java.util.HashMap) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Operation(com.google.api.services.appengine.v1.model.Operation) Application(com.google.api.services.appengine.v1.model.Application) Test(org.junit.Test)

Example 20 with Operation

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

the class GoogleApiClientAppEngineAdminServiceTest method buildInProgressOperation.

private Operation buildInProgressOperation(String operationName) {
    Operation inProgressOperation = new Operation();
    inProgressOperation.setName(operationName);
    inProgressOperation.setDone(false);
    return inProgressOperation;
}
Also used : Operation(com.google.api.services.appengine.v1.model.Operation)

Aggregations

IOException (java.io.IOException)15 Operation (io.adminshell.aas.v3.model.Operation)8 StepResult (bio.terra.stairway.StepResult)6 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 Operation (com.google.api.services.appengine.v1.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 List (java.util.List)4 Test (org.junit.Test)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 Storagetransfer (com.google.api.services.storagetransfer.v1.Storagetransfer)3 SystemException (bio.terra.cli.exception.SystemException)2 RetryException (bio.terra.stairway.exception.RetryException)2