Search in sources :

Example 56 with GoogleJsonResponseException

use of com.google.api.client.googleapis.json.GoogleJsonResponseException in project halyard by spinnaker.

the class GoogleKms method ensureKeyRingExists.

private static KeyRing ensureKeyRingExists(CloudKMS cloudKms, String locationId, String keyRingId) {
    KeyRing keyRing;
    try {
        keyRing = cloudKms.projects().locations().keyRings().get(keyRingId).execute();
    } catch (GoogleJsonResponseException e) {
        if (e.getStatusCode() == 404) {
            keyRing = null;
        } else {
            throw new HalException(Problem.Severity.FATAL, "Unexpected error retrieving key ring: " + e.getMessage(), e);
        }
    } catch (IOException e) {
        throw new HalException(Problem.Severity.FATAL, "Unexpected error retrieving key ring: " + e.getMessage(), e);
    }
    if (keyRing == null) {
        String keyRingName = keyRingId.substring(keyRingId.lastIndexOf('/') + 1);
        log.info("Creating a new key ring " + keyRingName);
        keyRing = createKeyRing(cloudKms, locationId, keyRingName);
    }
    return keyRing;
}
Also used : GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) HalException(com.netflix.spinnaker.halyard.core.error.v1.HalException) IOException(java.io.IOException)

Example 57 with GoogleJsonResponseException

use of com.google.api.client.googleapis.json.GoogleJsonResponseException in project beam by apache.

the class PubsubHelper method createTopic.

/**
 * Create a topic from short name. Delete it if it already exists. Ensure the topic will be
 * deleted on cleanup. Return full topic name.
 */
public TopicPath createTopic(String shortTopic) throws IOException {
    TopicPath topic = PubsubClient.topicPathFromName(project, shortTopic);
    while (true) {
        try {
            NexmarkUtils.console("create topic %s", topic);
            pubsubClient.createTopic(topic);
            createdTopics.add(topic);
            return topic;
        } catch (GoogleJsonResponseException ex) {
            NexmarkUtils.console("attempting to cleanup topic %s", topic);
            pubsubClient.deleteTopic(topic);
            try {
                if (!BackOffUtils.next(sleeper, backOff)) {
                    NexmarkUtils.console("too many retries for creating topic %s", topic);
                    throw ex;
                }
            } catch (InterruptedException in) {
                throw new IOException(in);
            }
        }
    }
}
Also used : GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) TopicPath(org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.TopicPath) IOException(java.io.IOException)

Example 58 with GoogleJsonResponseException

use of com.google.api.client.googleapis.json.GoogleJsonResponseException in project beam by apache.

the class PubsubHelper method createSubscription.

/**
 * Create subscription from short name. Ensure the subscription will be deleted on cleanup. Return
 * full subscription name.
 */
public SubscriptionPath createSubscription(String shortTopic, String shortSubscription) throws IOException {
    TopicPath topic = PubsubClient.topicPathFromName(project, shortTopic);
    SubscriptionPath subscription = PubsubClient.subscriptionPathFromName(project, shortSubscription);
    while (true) {
        try {
            NexmarkUtils.console("create subscription %s", subscription);
            pubsubClient.createSubscription(topic, subscription, 60);
            createdSubscriptions.add(subscription);
            return subscription;
        } catch (GoogleJsonResponseException ex) {
            NexmarkUtils.console("attempting to cleanup subscription %s", subscription);
            pubsubClient.deleteSubscription(subscription);
            try {
                if (!BackOffUtils.next(sleeper, backOff)) {
                    NexmarkUtils.console("too many retries for creating subscription %s", subscription);
                    throw ex;
                }
            } catch (InterruptedException in) {
                throw new IOException(in);
            }
        }
    }
}
Also used : GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) TopicPath(org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.TopicPath) SubscriptionPath(org.apache.beam.sdk.io.gcp.pubsub.PubsubClient.SubscriptionPath) IOException(java.io.IOException)

Example 59 with GoogleJsonResponseException

use of com.google.api.client.googleapis.json.GoogleJsonResponseException in project pentaho-kettle by pentaho.

the class GaInputStepDialog method getFields.

// Visible for testing
void getFields() {
    Analytics.Data.Ga.Get query = getPreviewQuery();
    if (query == null) {
        return;
    }
    query.setMaxResults(1);
    try {
        GaData dataFeed = query.execute();
        if (dataFeed == null || dataFeed.getRows() == null || dataFeed.getRows().size() < 1) {
            MessageBox mb = new MessageBox(shell, SWT.OK | SWT.ICON_ERROR);
            mb.setText("Query yields empty feed");
            mb.setMessage("The feed did not give any results. Please specify a query that returns data.");
            mb.open();
            return;
        }
        int i = 0;
        List<GaData.ColumnHeaders> colHeaders = dataFeed.getColumnHeaders();
        getTableView().table.setItemCount(colHeaders.size() + dataFeed.getProfileInfo().size());
        for (GaData.ColumnHeaders colHeader : colHeaders) {
            String name = colHeader.getName();
            String dataType = colHeader.getDataType();
            String columnType = colHeader.getColumnType();
            TableItem item = getTableView().table.getItem(i);
            if (columnType.equals("DIMENSION")) {
                item.setText(1, GaInputStepMeta.FIELD_TYPE_DIMENSION);
                item.setText(2, name);
                item.setText(3, name);
                // recognize date dimension
                if (name.equalsIgnoreCase("ga:date")) {
                    item.setText(4, ValueMetaBase.getTypeDesc(ValueMetaInterface.TYPE_DATE));
                    item.setText(5, "yyyyMMdd");
                } else if (name.equalsIgnoreCase("ga:daysSinceLastVisit") || name.equalsIgnoreCase("ga:visitLength") || name.equalsIgnoreCase("ga:visitCount")) {
                    item.setText(4, ValueMetaBase.getTypeDesc(ValueMetaInterface.TYPE_INTEGER));
                    item.setText(5, "#;-#");
                } else if (name.equalsIgnoreCase("ga:latitude") || name.equalsIgnoreCase("ga:longitude")) {
                    item.setText(4, ValueMetaBase.getTypeDesc(ValueMetaInterface.TYPE_NUMBER));
                    item.setText(5, "#.#;-#.#");
                } else {
                    item.setText(4, ValueMetaBase.getTypeDesc(ValueMetaInterface.TYPE_STRING));
                    item.setText(5, "");
                }
                i++;
            } else if (columnType.equals("METRIC")) {
                item.setText(1, GaInputStepMeta.FIELD_TYPE_METRIC);
                item.setText(2, name);
                item.setText(3, name);
                // depending on type
                if (dataType.compareToIgnoreCase("currency") == 0 || dataType.compareToIgnoreCase("float") == 0 || dataType.compareToIgnoreCase("percent") == 0 || dataType.compareToIgnoreCase("us_currency") == 0) {
                    item.setText(4, ValueMetaBase.getTypeDesc(ValueMetaInterface.TYPE_NUMBER));
                    item.setText(5, "#.#;-#.#");
                } else if (dataType.compareToIgnoreCase("time") == 0 || dataType.compareToIgnoreCase("integer") == 0) {
                    item.setText(4, ValueMetaBase.getTypeDesc(ValueMetaInterface.TYPE_INTEGER));
                    item.setText(5, "#;-#");
                } else {
                    item.setText(4, ValueMetaBase.getTypeDesc(ValueMetaInterface.TYPE_STRING));
                    item.setText(5, "");
                }
                i++;
            }
        }
        // Fill ds property and ds fields
        TableItem item = getTableView().table.getItem(i);
        item.setText(1, GaInputStepMeta.FIELD_TYPE_DATA_SOURCE_PROPERTY);
        item.setText(2, GaInputStepMeta.PROPERTY_DATA_SOURCE_PROFILE_ID);
        item.setText(3, GaInputStepMeta.PROPERTY_DATA_SOURCE_PROFILE_ID);
        item.setText(4, ValueMetaBase.getTypeDesc(ValueMetaInterface.TYPE_STRING));
        item.setText(5, "");
        i++;
        item = getTableView().table.getItem(i);
        item.setText(1, GaInputStepMeta.FIELD_TYPE_DATA_SOURCE_PROPERTY);
        item.setText(2, GaInputStepMeta.PROPERTY_DATA_SOURCE_WEBPROP_ID);
        item.setText(3, GaInputStepMeta.PROPERTY_DATA_SOURCE_WEBPROP_ID);
        item.setText(4, ValueMetaBase.getTypeDesc(ValueMetaInterface.TYPE_STRING));
        item.setText(5, "");
        i++;
        item = getTableView().table.getItem(i);
        item.setText(1, GaInputStepMeta.FIELD_TYPE_DATA_SOURCE_PROPERTY);
        item.setText(2, GaInputStepMeta.PROPERTY_DATA_SOURCE_ACCOUNT_NAME);
        item.setText(3, GaInputStepMeta.PROPERTY_DATA_SOURCE_ACCOUNT_NAME);
        item.setText(4, ValueMetaBase.getTypeDesc(ValueMetaInterface.TYPE_STRING));
        item.setText(5, "");
        i++;
        item = getTableView().table.getItem(i);
        item.setText(1, GaInputStepMeta.FIELD_TYPE_DATA_SOURCE_FIELD);
        item.setText(2, GaInputStepMeta.FIELD_DATA_SOURCE_TABLE_ID);
        item.setText(3, GaInputStepMeta.FIELD_DATA_SOURCE_TABLE_ID);
        item.setText(4, ValueMetaBase.getTypeDesc(ValueMetaInterface.TYPE_STRING));
        item.setText(5, "");
        i++;
        item = getTableView().table.getItem(i);
        item.setText(1, GaInputStepMeta.FIELD_TYPE_DATA_SOURCE_FIELD);
        item.setText(2, GaInputStepMeta.FIELD_DATA_SOURCE_TABLE_NAME);
        item.setText(3, GaInputStepMeta.FIELD_DATA_SOURCE_TABLE_NAME);
        item.setText(4, ValueMetaBase.getTypeDesc(ValueMetaInterface.TYPE_STRING));
        item.setText(5, "");
        getTableView().removeEmptyRows();
        getTableView().setRowNums();
        getTableView().optWidth(true);
        getInput().setChanged();
    } catch (IOException ioe) {
        Exception exceptionToDisplay = ioe;
        // Try to display something more user friendly than plain JSON
        if (ioe instanceof GoogleJsonResponseException) {
            GoogleJsonResponseException gjre = (GoogleJsonResponseException) ioe;
            if (gjre.getDetails() != null && gjre.getDetails().getMessage() != null) {
                exceptionToDisplay = new IOException(gjre.getDetails().getMessage(), gjre);
            }
        }
        new ErrorDialog(shell, BaseMessages.getString(PKG, "GoogleAnalyticsDialog.RequestError.DialogTitle"), BaseMessages.getString(PKG, "GoogleAnalyticsDialog.RequestError.DialogMessage"), exceptionToDisplay);
    }
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) IOException(java.io.IOException) Analytics(com.google.api.services.analytics.Analytics) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) IOException(java.io.IOException) MessageBox(org.eclipse.swt.widgets.MessageBox) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException) GaData(com.google.api.services.analytics.model.GaData)

Example 60 with GoogleJsonResponseException

use of com.google.api.client.googleapis.json.GoogleJsonResponseException in project drbookings by DrBookings.

the class GoogleCalendarSync method clearEvent.

private static void clearEvent(final String calendarId, final BookingBean b) throws IOException {
    for (final Iterator<String> it = b.getCalendarIds().iterator(); it.hasNext(); ) {
        final String id = it.next();
        final Delete d = client.events().delete(calendarId, id);
        if (logger.isDebugEnabled()) {
            logger.debug("Deleting " + d.getEventId());
        }
        try {
            d.execute();
        } catch (final GoogleJsonResponseException e) {
            if (logger.isErrorEnabled()) {
                logger.error(e.toString());
            }
        }
        it.remove();
    }
}
Also used : Delete(com.google.api.services.calendar.Calendar.Events.Delete) GoogleJsonResponseException(com.google.api.client.googleapis.json.GoogleJsonResponseException)

Aggregations

GoogleJsonResponseException (com.google.api.client.googleapis.json.GoogleJsonResponseException)94 IOException (java.io.IOException)48 YouTube (com.google.api.services.youtube.YouTube)26 Credential (com.google.api.client.auth.oauth2.Credential)25 ArrayList (java.util.ArrayList)13 Operation (com.google.api.services.compute.model.Operation)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