diff --git a/.travis.yml b/.travis.yml index dbc1508cb12..fedce4fa4b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,6 +20,6 @@ env: before_install: - openssl aes-256-cbc -K $encrypted_37a4f399de75_key -iv $encrypted_37a4f399de75_iv -in service-account.json.enc -out service-account.json -d -script: mvn verify +script: mvn verify -DskipTests=false after_success: - mvn clean cobertura:cobertura coveralls:report diff --git a/monitoring/v3/README.md b/monitoring/v3/README.md index 4004f4fc494..b7ea5622ec6 100644 --- a/monitoring/v3/README.md +++ b/monitoring/v3/README.md @@ -9,6 +9,8 @@ write a TimeSeries value to it. ## Prerequisites to run locally: * [Maven 3](https://maven.apache.org) + * [GCloud CLI](https://cloud.google.com/sdk/gcloud/) + * Create a Cloud project # Set Up Your Local Dev Environment @@ -17,6 +19,7 @@ Create local credentials by running the following command and following the oaut gcloud beta auth application-default login To run: + * `mvn clean install` * `./list_resources_example.sh * `./run_custom_metrics.sh @@ -57,13 +60,3 @@ to the appropriate project ID that matches the Service Account pointed to by `GOOGLE_APPLICATION_CREDENTIALS`, then run: mvn test -DskipTests=false - -## Contributing changes - -See [CONTRIBUTING.md](../../CONTRIBUTING.md). - -## Licensing - -See [LICENSE](../../LICENSE). - - diff --git a/monitoring/v3/src/main/java/CreateCustomMetric.java b/monitoring/v3/src/main/java/CreateCustomMetric.java index 18cdc4b5073..d33124aacb5 100644 --- a/monitoring/v3/src/main/java/CreateCustomMetric.java +++ b/monitoring/v3/src/main/java/CreateCustomMetric.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2015 Google Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - *

+/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ import com.google.api.services.monitoring.v3.Monitoring; @@ -40,12 +40,12 @@ import java.util.TimeZone; - - /** - * Class to demonstrate creating a custom metric with Cloud Monitoring. This class provides a few - * functions that create a custom GAUGE metric, writes a timeseries value to it, then reads that - * metric's value back within the last 5 minutes to see the value written. + * Class to demonstrate creating a custom metric with Cloud Monitoring. + *

+ *

This class provides a few functions that create a custom GAUGE metric, writes a timeseries + * value to it, then reads that metric's value back within the last 5 minutes to see the value + * written. */ public class CreateCustomMetric { @@ -111,7 +111,8 @@ public CreateCustomMetric(Monitoring monitoringService, String projectResource) /** * Constructs an instance of the class using the default metric name, and takes in a random * number generaotr (used for test purposes). - * Package-private to be accessible to tests. + *

+ *

Package-private to be accessible to tests. */ CreateCustomMetric(Monitoring monitoringService, String projectResource, String metricName, int bound) { @@ -162,7 +163,8 @@ private long getRandomPoint() { /** * This method creates a custom metric with arbitrary names, description, * and units. - * Package-private to be accessible to tests. + *

+ *

Package-private to be accessible to tests. */ MetricDescriptor createCustomMetric() throws IOException { MetricDescriptor metricDescriptor = new MetricDescriptor(); @@ -196,8 +198,10 @@ MetricDescriptor createCustomMetric() throws IOException { } /** - * Retrieve the custom metric created by createCustomMetric. It can sometimes take a few moments - * before a new custom metric is ready to have TimeSeries written to it, so this method is used + * Retrieve the custom metric created by createCustomMetric. + *

+ *

It can sometimes take a few moments before a new custom metric is ready to have + * TimeSeries written to it, so this method is used * to check when it is ready. */ public MetricDescriptor getCustomMetric() throws IOException { @@ -218,8 +222,8 @@ public MetricDescriptor getCustomMetric() throws IOException { } /** - * Writes a timeseries value for the custom metric created. The value written - * is a random integer value for demonstration purposes. It's a GAUGE metric, + * Writes a timeseries value for the custom metric created. + *

The value written is a random integer value for demonstration purposes. It's a GAUGE metric, * which means its a measure of a value at a point in time, and thus the start * window and end window times are the same. * @@ -264,21 +268,21 @@ void writeCustomMetricTimeseriesValue() throws IOException { } /** - * Read the TimeSeries value for the custom metrics created within a window of the + *

Read the TimeSeries value for the custom metrics created within a window of the * last 5 minutes. * * @return The TimeSeries response object reflecting the Timeseries of the custom metrics - * for the last 5 minutes. + * for the last 5 minutes. * @throws IOException On network error. */ ListTimeSeriesResponse readTimeseriesValue() throws IOException { ListTimeSeriesResponse response = monitoringService.projects().timeSeries().list(projectResource) - .setFilter("metric.type=\"" + metricType + "\"") - .setPageSize(3) - .setIntervalStartTime(getStartTime()) - .setIntervalEndTime(getNow()) - .execute(); + .setFilter("metric.type=\"" + metricType + "\"") + .setPageSize(3) + .setIntervalStartTime(getStartTime()) + .setIntervalEndTime(getNow()) + .execute(); return response; } @@ -302,8 +306,8 @@ public static void main(final String[] args) throws Exception { // Create an authorized API client Monitoring monitoringService = ListResources.authenticate(); - CreateCustomMetric metricWriter = new CreateCustomMetric( - monitoringService, projectResource); + CreateCustomMetric metricWriter = + new CreateCustomMetric(monitoringService, projectResource); MetricDescriptor metricDescriptor = metricWriter.createCustomMetric(); diff --git a/monitoring/v3/src/main/java/ListResources.java b/monitoring/v3/src/main/java/ListResources.java index 1eeeec28ffa..859e635f7c9 100644 --- a/monitoring/v3/src/main/java/ListResources.java +++ b/monitoring/v3/src/main/java/ListResources.java @@ -1,17 +1,17 @@ -/** - * Copyright (c) 2015 Google Inc. - *

- * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - *

+/* + * Copyright 2016 Google Inc. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * * http://www.apache.org/licenses/LICENSE-2.0 - *

+ * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ // [START all] @@ -35,7 +35,6 @@ import java.util.TimeZone; - /** * Simple command-line program to demonstrate connecting to and retrieving data * from the Google Cloud Monitoring API v3 using application default credentials. @@ -91,9 +90,10 @@ private ListResources(Monitoring monitoringService, String projectResource) { /** * Query the projects.monitoredResourceDescriptors.list API method. - * This lists all the resources available to be monitored in the API. *

- * Package-private to be accessible to tests. + *

This lists all the resources available to be monitored in the API. + *

+ *

Package-private to be accessible to tests. */ void listMonitoredResourceDescriptors() throws IOException { ListMonitoredResourceDescriptorsResponse monitoredResources = @@ -105,14 +105,12 @@ void listMonitoredResourceDescriptors() throws IOException { /** * Query to MetricDescriptors.list - * This lists all the current metrics. - *

- * Package-private to be accessible to tests. + *

This lists all the current metrics. Package-private to be accessible to tests. */ void listMetricDescriptors() throws IOException { ListMetricDescriptorsResponse metricsResponse = this.monitoringService.projects().metricDescriptors() - .list(this.projectResource).execute(); + .list(this.projectResource).execute(); this.outputStream.println("listMetricDescriptors response"); this.outputStream.println(metricsResponse.toPrettyString()); } @@ -143,7 +141,8 @@ private static String getEndTime() { /** * Query to MetricDescriptors.list - * This lists all the current metrics. + * + *

This lists all the current metrics. */ void listTimeseries() throws IOException { ListTimeSeriesResponse timeSeriesList = this.monitoringService.projects().timeSeries() diff --git a/monitoring/v3/src/test/java/CreateCustomMetricTest.java b/monitoring/v3/src/test/java/CreateCustomMetricTest.java index f4c2aae8fe9..301d08ed741 100644 --- a/monitoring/v3/src/test/java/CreateCustomMetricTest.java +++ b/monitoring/v3/src/test/java/CreateCustomMetricTest.java @@ -1,17 +1,17 @@ /* - * Copyright (c) 2015 Google Inc. + * Copyright 2016 Google Inc. All Rights Reserved. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ import static com.google.common.truth.Truth.assertThat; @@ -21,31 +21,21 @@ import com.google.common.collect.ImmutableList; import org.apache.commons.lang3.RandomStringUtils; - import org.junit.Before; import org.junit.Test; import java.util.List; -import java.util.Random; + /** - * Integration tests for the basic Cloud Monitoring v3 examples. Running - * these tests requires that GOOGLE_APPLICATION_CREDENTIALS points to a + * Integration tests for the basic Cloud Monitoring v3 examples. + * + *

Running these tests requires that GOOGLE_APPLICATION_CREDENTIALS points to a * valid JSON Service Account downloaded from a project with the Cloud * Monitoring API enabled. */ public class CreateCustomMetricTest { - /** - * Overrides the Random number generator so our tests get a predictable result. - */ - private static class MockRandom extends Random { - - public int nextInt(int bound) { - return 4; - } - } - /** * Google Cloud Monitoring client to integration test. */ diff --git a/monitoring/v3/src/test/java/ListResourcesTest.java b/monitoring/v3/src/test/java/ListResourcesTest.java index 234ee858a54..e8415d76ad4 100644 --- a/monitoring/v3/src/test/java/ListResourcesTest.java +++ b/monitoring/v3/src/test/java/ListResourcesTest.java @@ -1,17 +1,17 @@ /* - * Copyright (c) 2015 Google Inc. + * Copyright 2016 Google Inc. All Rights Reserved. * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ import static com.google.common.truth.Truth.assertThat; @@ -24,9 +24,11 @@ import java.io.ByteArrayOutputStream; import java.io.PrintStream; + /** - * Integration tests for the basic Cloud Monitoring v3 examples. Running - * these tests requires that GOOGLE_APPLICATION_CREDENTIALS points to a + * Integration tests for the basic Cloud Monitoring v3 examples. + * + *

Running these tests requires that GOOGLE_APPLICATION_CREDENTIALS points to a * valid JSON Service Account downloaded from a project with the Cloud * Monitoring API enabled. */