@java.lang.Override public Builder newBuilderForType() { return newBuilder(); }
/** * Creates a logs-based metric. * * <p>Sample code: * * <pre><code> * try (MetricsClient metricsClient = MetricsClient.create()) { * ParentName parent = ProjectName.of("[PROJECT]"); * LogMetric metric = LogMetric.newBuilder().build(); * LogMetric response = metricsClient.createLogMetric(parent, metric); * } * </code></pre> * * @param parent The resource name of the project in which to create the metric: * <p>"projects/[PROJECT_ID]" * <p>The new metric must be provided in the request. * @param metric The new logs-based metric, which must not have an identifier that already exists. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final LogMetric createLogMetric(ParentName parent, LogMetric metric) { CreateLogMetricRequest request = CreateLogMetricRequest.newBuilder() .setParent(parent == null ? null : parent.toString()) .setMetric(metric) .build(); return createLogMetric(request); }
/** * Creates a logs-based metric. * * <p>Sample code: * * <pre><code> * try (MetricsClient metricsClient = MetricsClient.create()) { * ParentName parent = ProjectName.of("[PROJECT]"); * LogMetric metric = LogMetric.newBuilder().build(); * LogMetric response = metricsClient.createLogMetric(parent.toString(), metric); * } * </code></pre> * * @param parent The resource name of the project in which to create the metric: * <p>"projects/[PROJECT_ID]" * <p>The new metric must be provided in the request. * @param metric The new logs-based metric, which must not have an identifier that already exists. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final LogMetric createLogMetric(String parent, LogMetric metric) { CreateLogMetricRequest request = CreateLogMetricRequest.newBuilder().setParent(parent).setMetric(metric).build(); return createLogMetric(request); }
@Override public ApiFuture<Metric> createAsync(MetricInfo metric) { CreateLogMetricRequest request = CreateLogMetricRequest.newBuilder() .setParent(ProjectName.of(getOptions().getProjectId()).toString()) .setMetric(metric.toPb()) .build(); return transform(rpc.create(request), Metric.fromPbFunction(this)); }
@Test public void testCreateMetric() { LogMetric metricPb = METRIC_INFO.toPb(); ApiFuture<LogMetric> response = ApiFutures.immediateFuture(metricPb); CreateLogMetricRequest request = CreateLogMetricRequest.newBuilder().setParent(PROJECT_PB).setMetric(metricPb).build(); EasyMock.expect(loggingRpcMock.create(request)).andReturn(response); EasyMock.replay(rpcFactoryMock, loggingRpcMock); logging = options.getService(); Metric metric = logging.create(METRIC_INFO); assertEquals(new Metric(logging, new MetricInfo.BuilderImpl(METRIC_INFO)), metric); }
@Test public void testCreateMetricAsync() throws ExecutionException, InterruptedException { LogMetric metricPb = METRIC_INFO.toPb(); ApiFuture<LogMetric> response = ApiFutures.immediateFuture(metricPb); CreateLogMetricRequest request = CreateLogMetricRequest.newBuilder().setParent(PROJECT_PB).setMetric(metricPb).build(); EasyMock.expect(loggingRpcMock.create(request)).andReturn(response); EasyMock.replay(rpcFactoryMock, loggingRpcMock); logging = options.getService(); Metric metric = logging.createAsync(METRIC_INFO).get(); assertEquals(new Metric(logging, new MetricInfo.BuilderImpl(METRIC_INFO)), metric); }
/** * Creates a logs-based metric. * * <p>Sample code: * * <pre><code> * try (MetricsClient metricsClient = MetricsClient.create()) { * ParentName parent = ProjectName.of("[PROJECT]"); * LogMetric metric = LogMetric.newBuilder().build(); * LogMetric response = metricsClient.createLogMetric(parent, metric); * } * </code></pre> * * @param parent The resource name of the project in which to create the metric: * <p>"projects/[PROJECT_ID]" * <p>The new metric must be provided in the request. * @param metric The new logs-based metric, which must not have an identifier that already exists. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final LogMetric createLogMetric(ParentName parent, LogMetric metric) { CreateLogMetricRequest request = CreateLogMetricRequest.newBuilder() .setParent(parent == null ? null : parent.toString()) .setMetric(metric) .build(); return createLogMetric(request); }
/** * Creates a logs-based metric. * * <p>Sample code: * * <pre><code> * try (MetricsClient metricsClient = MetricsClient.create()) { * ParentName parent = ProjectName.of("[PROJECT]"); * LogMetric metric = LogMetric.newBuilder().build(); * LogMetric response = metricsClient.createLogMetric(parent.toString(), metric); * } * </code></pre> * * @param parent The resource name of the project in which to create the metric: * <p>"projects/[PROJECT_ID]" * <p>The new metric must be provided in the request. * @param metric The new logs-based metric, which must not have an identifier that already exists. * @throws com.google.api.gax.rpc.ApiException if the remote call fails */ public final LogMetric createLogMetric(String parent, LogMetric metric) { CreateLogMetricRequest request = CreateLogMetricRequest.newBuilder().setParent(parent).setMetric(metric).build(); return createLogMetric(request); }
@Override public ApiFuture<Metric> createAsync(MetricInfo metric) { CreateLogMetricRequest request = CreateLogMetricRequest.newBuilder() .setParent(ProjectName.of(getOptions().getProjectId()).toString()) .setMetric(metric.toPb()) .build(); return transform(rpc.create(request), Metric.fromPbFunction(this)); }