Search in sources :

Example 16 with GoogleJsonResponseException

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;
    }
}
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 17 with GoogleJsonResponseException

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);
    }
}
Also used : GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) ListLocationsResponse(com.google.api.services.appengine.v1.model.ListLocationsResponse) ArrayList(java.util.ArrayList) Location(com.google.api.services.appengine.v1.model.Location)

Example 18 with GoogleJsonResponseException

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);
}
Also used : GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException)

Example 19 with GoogleJsonResponseException

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);
    }
}
Also used : Debugger(com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException)

Example 20 with GoogleJsonResponseException

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();
    }
}
Also used : Debugger(com.google.api.services.clouddebugger.v2.Clouddebugger.Debugger) Breakpoint(com.google.api.services.clouddebugger.v2.model.Breakpoint) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) SocketTimeoutException(java.net.SocketTimeoutException) IOException(java.io.IOException)

Aggregations

GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)90 IOException (java.io.IOException)45 YouTube (com.google.api.services.youtube.YouTube)26 Credential (com.google.api.client.auth.oauth2.Credential)25 Operation (com.google.api.services.compute.model.Operation)12 ArrayList (java.util.ArrayList)12 Test (org.junit.Test)12 Compute (com.google.api.services.compute.Compute)11 Storage (com.google.api.services.storage.Storage)10 GcpResourceException (com.sequenceiq.cloudbreak.cloud.gcp.GcpResourceException)8 GcsOptions (org.apache.beam.sdk.extensions.gcp.options.GcsOptions)7 GoogleJsonError (com.google.api.client.googleapis.json.GoogleJsonError)5 InputStreamContent (com.google.api.client.http.InputStreamContent)5 BackOff (com.google.api.client.util.BackOff)5 HashMap (java.util.HashMap)5 Objects (com.google.api.services.storage.model.Objects)4 GoogleCloudStorage (com.google.cloud.hadoop.gcsio.GoogleCloudStorage)4 HalException (com.netflix.spinnaker.halyard.core.error.v1.HalException)4 MediaHttpUploader (com.google.api.client.googleapis.media.MediaHttpUploader)3 MediaHttpUploaderProgressListener (com.google.api.client.googleapis.media.MediaHttpUploaderProgressListener)3