Search in sources :

Example 1 with Application

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

the class AppEngineApplicationCreateDialog method doOKAction.

@Override
protected void doOKAction() {
    final Location selectedLocation = ((AppEngineLocationSelectorItem) regionComboBox.getSelectedItem()).getLocation();
    // show loading state
    disable();
    try {
        UsageTrackerProvider.getInstance().trackEvent(GctTracking.APP_ENGINE_APPLICATION_CREATE).ping();
        // attempt to create the application, and close the dialog if successful
        ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> AppEngineAdminService.getInstance().createApplication(selectedLocation.getLocationId(), gcpProjectId, userCredential), GctBundle.message("appengine.application.create.loading", selectedLocation.getLocationId()), true, /* cancellable */
        ProjectManager.getInstance().getDefaultProject());
        UsageTrackerProvider.getInstance().trackEvent(GctTracking.APP_ENGINE_APPLICATION_CREATE_SUCCESS).ping();
        close(OK_EXIT_CODE);
    } catch (IOException e) {
        trackApplicationCreateFailure();
        setStatusMessage(GctBundle.message("appengine.application.create.error.transient"), true);
    } catch (GoogleApiException e) {
        trackApplicationCreateFailure();
        setStatusMessage(e.getMessage(), true);
    } catch (Exception e) {
        trackApplicationCreateFailure();
        throw new RuntimeException(e);
    } finally {
        enable();
    }
}
Also used : IOException(java.io.IOException) IOException(java.io.IOException) Location(com.google.api.services.appengine.v1.model.Location)

Example 2 with Application

use of com.google.api.services.appengine.v1.model.Application 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 3 with Application

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

the class GoogleApiClientAppEngineAdminServiceTest method testGetApplicationForProjectId_success.

@Test
public void testGetApplicationForProjectId_success() throws IOException, GoogleApiException {
    Application result = new Application();
    when(appengineClientMock.getAppsGetQuery().execute()).thenReturn(result);
    String projectId = "my-project";
    assertEquals(result, service.getApplicationForProjectId(projectId, mock(Credential.class)));
    verify(appengineClientMock.apps()).get(eq(projectId));
    verify(appengineClientMock.getAppsGetQuery()).execute();
    // make the call again, and assert that the cached result is returned without calling the API
    service.getApplicationForProjectId(projectId, mock(Credential.class));
    verifyNoMoreInteractions(appengineClientMock.apps());
    verifyNoMoreInteractions(appengineClientMock.getAppsGetQuery());
}
Also used : Credential(com.google.api.client.auth.oauth2.Credential) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Application(com.google.api.services.appengine.v1.model.Application) Test(org.junit.Test)

Example 4 with Application

use of com.google.api.services.appengine.v1.model.Application 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)

Aggregations

Application (com.google.api.services.appengine.v1.model.Application)3 Credential (com.google.api.client.auth.oauth2.Credential)2 GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)2 Location (com.google.api.services.appengine.v1.model.Location)2 Operation (com.google.api.services.appengine.v1.model.Operation)2 Status (com.google.api.services.appengine.v1.model.Status)2 IOException (java.io.IOException)2 Test (org.junit.Test)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 HttpRequestInitializer (com.google.api.client.http.HttpRequestInitializer)1 HttpTransport (com.google.api.client.http.HttpTransport)1 JsonFactory (com.google.api.client.json.JsonFactory)1 Appengine (com.google.api.services.appengine.v1.Appengine)1 Apps (com.google.api.services.appengine.v1.Appengine.Apps)1 ListLocationsResponse (com.google.api.services.appengine.v1.model.ListLocationsResponse)1 AppEngineApplicationNotFoundException (com.google.cloud.tools.intellij.appengine.application.GoogleApiClientAppEngineAdminService.AppEngineApplicationNotFoundException)1 GoogleApiClientFactory (com.google.cloud.tools.intellij.resources.GoogleApiClientFactory)1 BasePluginTestCase (com.google.cloud.tools.intellij.testing.BasePluginTestCase)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1