Search in sources :

Example 16 with ProjectName

use of com.google.spanner.admin.instance.v1.ProjectName in project spring-cloud-gcp by spring-cloud.

the class SecretManagerTemplate method createSecretInternal.

/**
 * Creates a new secret for the GCP Project.
 *
 * <p>
 * Note that the {@link Secret} object does not contain the secret payload. You must
 * create versions of the secret which stores the payload of the secret.
 */
private void createSecretInternal(String secretId, String projectId) {
    ProjectName projectName = ProjectName.of(projectId);
    Secret secret = Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.getDefaultInstance())).build();
    CreateSecretRequest request = CreateSecretRequest.newBuilder().setParent(projectName.toString()).setSecretId(secretId).setSecret(secret).build();
    this.secretManagerServiceClient.createSecret(request);
}
Also used : Secret(com.google.cloud.secretmanager.v1.Secret) ProjectName(com.google.cloud.secretmanager.v1.ProjectName) CreateSecretRequest(com.google.cloud.secretmanager.v1.CreateSecretRequest)

Example 17 with ProjectName

use of com.google.spanner.admin.instance.v1.ProjectName in project java-docs-samples by GoogleCloudPlatform.

the class WorkloadGeneratorTest method testPipeline.

@Test
public void testPipeline() throws IOException, InterruptedException {
    String workloadJobName = "bigtable-workload-generator-test-" + new Date().getTime();
    final int WORKLOAD_DURATION = 10;
    final int WAIT_DURATION = WORKLOAD_DURATION * 60 * 1000;
    int rate = 1000;
    BigtableWorkloadOptions options = PipelineOptionsFactory.create().as(BigtableWorkloadOptions.class);
    options.setBigtableInstanceId(instanceId);
    options.setBigtableTableId(TABLE_ID);
    options.setWorkloadRate(rate);
    options.setRegion(REGION_ID);
    options.setWorkloadDurationMinutes(WORKLOAD_DURATION);
    options.setRunner(DataflowRunner.class);
    options.setJobName(workloadJobName);
    final PipelineResult pipelineResult = WorkloadGenerator.generateWorkload(options);
    MetricServiceClient metricServiceClient = MetricServiceClient.create();
    ProjectName name = ProjectName.of(projectId);
    // Wait X minutes and then get metrics for the X minute period.
    Thread.sleep(WAIT_DURATION);
    long startMillis = System.currentTimeMillis() - WAIT_DURATION;
    TimeInterval interval = TimeInterval.newBuilder().setStartTime(Timestamps.fromMillis(startMillis)).setEndTime(Timestamps.fromMillis(System.currentTimeMillis())).build();
    ListTimeSeriesRequest request = ListTimeSeriesRequest.newBuilder().setName(name.toString()).setFilter("metric.type=\"bigtable.googleapis.com/server/request_count\"").setInterval(interval).build();
    ListTimeSeriesPagedResponse response = metricServiceClient.listTimeSeries(request);
    long startRequestCount = 0;
    long endRequestCount = 0;
    for (TimeSeries ts : response.iterateAll()) {
        startRequestCount = ts.getPoints(0).getValue().getInt64Value();
        endRequestCount = ts.getPoints(ts.getPointsCount() - 1).getValue().getInt64Value();
    }
    assertThat(endRequestCount - startRequestCount > rate);
    // Stop the running job.
    String jobId = ((DataflowPipelineJob) pipelineResult).getJobId();
    DataflowClient client = DataflowClient.create(options);
    Job job = client.getJob(jobId);
    assertThat(job.getCurrentState().equals("JOB_STATE_CANCELLED"));
}
Also used : TimeSeries(com.google.bigtable.repackaged.com.google.monitoring.v3.TimeSeries) MetricServiceClient(com.google.bigtable.repackaged.com.google.cloud.monitoring.v3.MetricServiceClient) TimeInterval(com.google.bigtable.repackaged.com.google.monitoring.v3.TimeInterval) ProjectName(com.google.bigtable.repackaged.com.google.monitoring.v3.ProjectName) PipelineResult(org.apache.beam.sdk.PipelineResult) ListTimeSeriesPagedResponse(com.google.bigtable.repackaged.com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse) Date(java.util.Date) ListTimeSeriesRequest(com.google.bigtable.repackaged.com.google.monitoring.v3.ListTimeSeriesRequest) BigtableWorkloadOptions(bigtable.WorkloadGenerator.BigtableWorkloadOptions) DataflowPipelineJob(org.apache.beam.runners.dataflow.DataflowPipelineJob) DataflowClient(org.apache.beam.runners.dataflow.DataflowClient) Job(com.google.api.services.dataflow.model.Job) DataflowPipelineJob(org.apache.beam.runners.dataflow.DataflowPipelineJob) Test(org.junit.Test)

Example 18 with ProjectName

use of com.google.spanner.admin.instance.v1.ProjectName in project java-docs-samples by GoogleCloudPlatform.

the class Snippets method listTimeSeriesAggregrate.

/**
 * Demonstrates listing time series and aggregating them.
 */
void listTimeSeriesAggregrate() throws IOException {
    // [START monitoring_read_timeseries_align]
    MetricServiceClient metricServiceClient = MetricServiceClient.create();
    String projectId = System.getProperty("projectId");
    ProjectName name = ProjectName.of(projectId);
    // Restrict time to last 20 minutes
    long startMillis = System.currentTimeMillis() - ((60 * 20) * 1000);
    TimeInterval interval = TimeInterval.newBuilder().setStartTime(Timestamps.fromMillis(startMillis)).setEndTime(Timestamps.fromMillis(System.currentTimeMillis())).build();
    Aggregation aggregation = Aggregation.newBuilder().setAlignmentPeriod(Duration.newBuilder().setSeconds(600).build()).setPerSeriesAligner(Aggregation.Aligner.ALIGN_MEAN).build();
    ListTimeSeriesRequest.Builder requestBuilder = ListTimeSeriesRequest.newBuilder().setName(name.toString()).setFilter("metric.type=\"compute.googleapis.com/instance/cpu/utilization\"").setInterval(interval).setAggregation(aggregation);
    ListTimeSeriesRequest request = requestBuilder.build();
    ListTimeSeriesPagedResponse response = metricServiceClient.listTimeSeries(request);
    System.out.println("Got timeseries: ");
    for (TimeSeries ts : response.iterateAll()) {
        System.out.println(ts);
    }
// [END monitoring_read_timeseries_align]
}
Also used : Aggregation(com.google.monitoring.v3.Aggregation) TimeSeries(com.google.monitoring.v3.TimeSeries) MetricServiceClient(com.google.cloud.monitoring.v3.MetricServiceClient) TimeInterval(com.google.monitoring.v3.TimeInterval) ProjectName(com.google.monitoring.v3.ProjectName) ListTimeSeriesPagedResponse(com.google.cloud.monitoring.v3.MetricServiceClient.ListTimeSeriesPagedResponse) ListTimeSeriesRequest(com.google.monitoring.v3.ListTimeSeriesRequest)

Example 19 with ProjectName

use of com.google.spanner.admin.instance.v1.ProjectName in project java-docs-samples by GoogleCloudPlatform.

the class Snippets method listMonitoredResources.

/**
 * Gets all monitored resource descriptors.
 */
void listMonitoredResources() throws IOException {
    // [START monitoring_list_resources]
    // Your Google Cloud Platform project ID
    String projectId = System.getProperty("projectId");
    final MetricServiceClient client = MetricServiceClient.create();
    ProjectName name = ProjectName.of(projectId);
    ListMonitoredResourceDescriptorsRequest request = ListMonitoredResourceDescriptorsRequest.newBuilder().setName(name.toString()).build();
    System.out.println("Listing monitored resource descriptors: ");
    ListMonitoredResourceDescriptorsPagedResponse response = client.listMonitoredResourceDescriptors(request);
    for (MonitoredResourceDescriptor d : response.iterateAll()) {
        System.out.println(d.getType());
    }
// [END monitoring_list_resources]
}
Also used : MetricServiceClient(com.google.cloud.monitoring.v3.MetricServiceClient) ProjectName(com.google.monitoring.v3.ProjectName) ListMonitoredResourceDescriptorsRequest(com.google.monitoring.v3.ListMonitoredResourceDescriptorsRequest) MonitoredResourceDescriptor(com.google.api.MonitoredResourceDescriptor) ListMonitoredResourceDescriptorsPagedResponse(com.google.cloud.monitoring.v3.MetricServiceClient.ListMonitoredResourceDescriptorsPagedResponse)

Example 20 with ProjectName

use of com.google.spanner.admin.instance.v1.ProjectName in project java-docs-samples by GoogleCloudPlatform.

the class Snippets method createMetricDescriptor.

/**
 * Creates a metric descriptor.
 *
 * <p>See:
 * https://cloud.google.com/monitoring/api/ref_v3/rest/v3/projects.metricDescriptors/create
 *
 * @param type The metric type
 */
void createMetricDescriptor(String type) throws IOException {
    // [START monitoring_create_metric]
    // Your Google Cloud Platform project ID
    String projectId = System.getProperty("projectId");
    String metricType = CUSTOM_METRIC_DOMAIN + "/" + type;
    final MetricServiceClient client = MetricServiceClient.create();
    ProjectName name = ProjectName.of(projectId);
    MetricDescriptor descriptor = MetricDescriptor.newBuilder().setType(metricType).addLabels(LabelDescriptor.newBuilder().setKey("store_id").setValueType(LabelDescriptor.ValueType.STRING)).setDescription("This is a simple example of a custom metric.").setMetricKind(MetricDescriptor.MetricKind.GAUGE).setValueType(MetricDescriptor.ValueType.DOUBLE).build();
    CreateMetricDescriptorRequest request = CreateMetricDescriptorRequest.newBuilder().setName(name.toString()).setMetricDescriptor(descriptor).build();
    client.createMetricDescriptor(request);
// [END monitoring_create_metric]
}
Also used : MetricDescriptor(com.google.api.MetricDescriptor) MetricServiceClient(com.google.cloud.monitoring.v3.MetricServiceClient) ProjectName(com.google.monitoring.v3.ProjectName) CreateMetricDescriptorRequest(com.google.monitoring.v3.CreateMetricDescriptorRequest)

Aggregations

Test (org.junit.Test)146 StatusRuntimeException (io.grpc.StatusRuntimeException)73 ProjectName (com.google.monitoring.v3.ProjectName)62 AbstractMessage (com.google.protobuf.AbstractMessage)60 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)58 ProjectName (com.google.pubsub.v1.ProjectName)30 ArrayList (java.util.ArrayList)29 ProjectName (com.google.privacy.dlp.v2.ProjectName)22 ByteString (com.google.protobuf.ByteString)18 DataTransferServiceClient (com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient)17 ProjectName (com.google.cloud.bigquery.datatransfer.v1.ProjectName)17 IOException (java.io.IOException)17 CreateTransferConfigRequest (com.google.cloud.bigquery.datatransfer.v1.CreateTransferConfigRequest)16 TransferConfig (com.google.cloud.bigquery.datatransfer.v1.TransferConfig)16 ProjectName (com.google.cloud.secretmanager.v1.ProjectName)16 ProjectName (com.google.containeranalysis.v1beta1.ProjectName)16 ApiException (com.google.api.gax.rpc.ApiException)15 MetricServiceClient (com.google.cloud.monitoring.v3.MetricServiceClient)15 TimeSeries (com.google.monitoring.v3.TimeSeries)15 ProjectName (com.google.logging.v2.ProjectName)14