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();
}
}
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;
}
}
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());
}
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());
}
Aggregations