use of com.google.api.client.googleapis.json.GoogleJsonResponseException 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.client.googleapis.json.GoogleJsonResponseException in project google-cloud-intellij by GoogleCloudPlatform.
the class GoogleApiClientAppEngineAdminService method fetchAllAppEngineLocations.
private List<Location> fetchAllAppEngineLocations(Credential credential) throws GoogleApiException, IOException {
try {
ListLocationsResponse response = fetchAppEngineLocationPage(credential, null);
List<Location> locations = new ArrayList<>(response.getLocations());
while (response.getNextPageToken() != null) {
response = fetchAppEngineLocationPage(credential, response.getNextPageToken());
locations.addAll(response.getLocations());
}
return locations;
} catch (GoogleJsonResponseException e) {
throw GoogleApiException.from(e);
}
}
use of com.google.api.client.googleapis.json.GoogleJsonResponseException in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugGlobalPoller method handleBreakpointQueryError.
private void handleBreakpointQueryError(@NotNull CloudDebugProcessState state, @NotNull Exception ex) {
String message;
String projectName = state.getProject().getName();
if (ex instanceof GoogleJsonResponseException) {
GoogleJsonResponseException jsonResponseException = (GoogleJsonResponseException) ex;
if (jsonResponseException.getStatusCode() == HttpURLConnection.HTTP_FORBIDDEN || jsonResponseException.getStatusCode() == HttpURLConnection.HTTP_UNAUTHORIZED) {
message = GctBundle.message("clouddebug.background.listener.access.error.message", projectName);
} else {
message = GctBundle.message("clouddebug.background.listener.general.error.message", projectName, jsonResponseException.getDetails().getMessage());
}
} else {
message = GctBundle.message("clouddebug.background.listener.general.error.message", projectName, ex.getLocalizedMessage());
}
handleBreakpointQueryError(state, message);
}
use of com.google.api.client.googleapis.json.GoogleJsonResponseException in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugGlobalPoller method pollForChanges.
/**
* pollForChanges sends a synchronous, hanging query to the server and compares the result to see
* if there are changes from the current state. Explanation of <a
* href="https://en.wikipedia.org/wiki/Push_technology#Long_polling">hanging query (a.k.a. long
* poll)</a>
*
* @param state represents the target debuggee to query
*/
void pollForChanges(@NotNull final CloudDebugProcessState state) {
final Debugger client = CloudDebuggerClient.getShortTimeoutClient(state);
if (client == null) {
if (state.isListenInBackground()) {
// state is supposed to listen, but does not have access to the backend
LOG.warn("CloudDebugProcessState is listening in the background but no debugger client " + "could be retrieved => stop listening");
handleBreakpointQueryError(state, GctBundle.message("clouddebug.background.listener.access.error.message", state.getProject().getName()));
return;
} else {
// We should poll only states that listen in the background, reaching this branch is
// unexpected
LOG.error("Polling changes for a debug state that is not set to listen in the background");
return;
}
}
boolean changed = false;
try {
String oldToken = state.getWaitToken();
queryServerForBreakpoints(state, client);
String responseWaitToken = state.getWaitToken();
if (!Strings.isNullOrEmpty(responseWaitToken)) {
changed = oldToken == null || !responseWaitToken.equals(oldToken);
} else {
changed = !Strings.isNullOrEmpty(oldToken);
}
} catch (SocketTimeoutException ex) {
// noop, this is expected behavior.
} catch (GoogleJsonResponseException ex) {
// a result is available (which will be retrieved via the subsequent query)
if (ex.getStatusCode() != HttpURLConnection.HTTP_CONFLICT) {
handleBreakpointQueryError(state, ex);
}
} catch (IOException ex) {
LOG.warn("exception listing breakpoints", ex);
handleBreakpointQueryError(state, ex);
return;
} catch (Exception ex) {
LOG.error("exception listing breakpoints", ex);
handleBreakpointQueryError(state, ex);
return;
}
if (changed) {
fireBreakpointsChanged(state);
}
}
use of com.google.api.client.googleapis.json.GoogleJsonResponseException in project google-cloud-intellij by GoogleCloudPlatform.
the class CloudDebugProcessStateController method waitForChanges.
/**
* Package protected for test purposes only.
*/
void waitForChanges() {
if (state == null) {
LOG.error("no state available attempting to checkForChanges");
return;
}
final Debugger client = CloudDebuggerClient.getLongTimeoutClient(state);
if (client == null) {
LOG.info("no client available attempting to checkForChanges");
return;
}
String tokenToSend = state.getWaitToken();
List<Breakpoint> currentList;
try {
currentList = queryServerForBreakpoints(state, client, tokenToSend);
} catch (SocketTimeoutException ex) {
// Timeout is expected on a hanging get.
return;
} catch (GoogleJsonResponseException ex) {
// we need to requery.
if (ex.getDetails().getCode() == 409) {
try {
currentList = queryServerForBreakpoints(state, client, tokenToSend);
} catch (IOException ioException) {
LOG.warn("exception listing breakpoints", ioException);
return;
}
} else {
LOG.warn("exception listing breakpoints", ex);
return;
}
} catch (IOException ex) {
LOG.warn("exception listing breakpoints", ex);
return;
}
if (!isBackgroundListening()) {
return;
}
// to do pruning.
if (!Strings.isNullOrEmpty(tokenToSend)) {
pruneBreakpointCache(currentList);
fireBreakpointsChanged();
}
}
Aggregations