use of com.google.cloud.bigquery.datatransfer.v1.ProjectName in project java-docs-samples by GoogleCloudPlatform.
the class QuickStart method main.
public static void main(String[] args) throws Exception {
// Google Cloud Platform Project ID
String projectId = (args.length > 0) ? args[0] : ServiceOptions.getDefaultProjectId();
ProjectName projectName = ProjectName.of(projectId);
// Instantiate an Error Reporting Client
try (ReportErrorsServiceClient reportErrorsServiceClient = ReportErrorsServiceClient.create()) {
// Custom error events require an error reporting location as well.
ErrorContext errorContext = ErrorContext.newBuilder().setReportLocation(SourceLocation.newBuilder().setFilePath("Test.java").setLineNumber(10).setFunctionName("myMethod").build()).build();
// Report a custom error event
ReportedErrorEvent customErrorEvent = ReportedErrorEvent.getDefaultInstance().toBuilder().setMessage("custom error event").setContext(errorContext).build();
// Report an event synchronously, use .reportErrorEventCallable for asynchronous reporting.
reportErrorsServiceClient.reportErrorEvent(projectName, customErrorEvent);
}
}
use of com.google.cloud.bigquery.datatransfer.v1.ProjectName in project spring-cloud-gcp by spring-cloud.
the class PubSubSampleApplicationTests method getMessagesFromSubscription.
private List<String> getMessagesFromSubscription(String subscriptionName) {
String projectSubscriptionName = ProjectSubscriptionName.format(projectName, subscriptionName);
PullRequest pullRequest = PullRequest.newBuilder().setReturnImmediately(true).setMaxMessages(10).setSubscription(projectSubscriptionName).build();
PullResponse pullResponse = subscriptionAdminClient.getStub().pullCallable().call(pullRequest);
return pullResponse.getReceivedMessagesList().stream().map((message) -> message.getMessage().getData().toStringUtf8()).collect(Collectors.toList());
}
use of com.google.cloud.bigquery.datatransfer.v1.ProjectName in project java-docs-samples by GoogleCloudPlatform.
the class JobSearchListTenants method listTenants.
// List Tenants.
public static void listTenants(String projectId) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (TenantServiceClient tenantServiceClient = TenantServiceClient.create()) {
ProjectName parent = ProjectName.of(projectId);
ListTenantsRequest request = ListTenantsRequest.newBuilder().setParent(parent.toString()).build();
for (Tenant responseItem : tenantServiceClient.listTenants(request).iterateAll()) {
System.out.format("Tenant Name: %s%n", responseItem.getName());
System.out.format("External ID: %s%n", responseItem.getExternalId());
}
}
}
use of com.google.cloud.bigquery.datatransfer.v1.ProjectName in project java-docs-samples by GoogleCloudPlatform.
the class QuickstartSample method main.
public static void main(String... args) throws Exception {
// Your Google Cloud Platform project ID
String projectId = System.getProperty("projectId");
if (projectId == null) {
System.err.println("Usage: QuickstartSample -DprojectId=YOUR_PROJECT_ID");
return;
}
// Instantiates a client
MetricServiceClient metricServiceClient = MetricServiceClient.create();
// Prepares an individual data point
TimeInterval interval = TimeInterval.newBuilder().setEndTime(Timestamps.fromMillis(System.currentTimeMillis())).build();
TypedValue value = TypedValue.newBuilder().setDoubleValue(3.14).build();
Point point = Point.newBuilder().setInterval(interval).setValue(value).build();
List<Point> pointList = new ArrayList<>();
pointList.add(point);
ProjectName name = ProjectName.of(projectId);
// Prepares the metric descriptor
Map<String, String> metricLabels = new HashMap<String, String>();
metricLabels.put("store_id", "Pittsburg");
Metric metric = Metric.newBuilder().setType("custom.googleapis.com/my_metric").putAllLabels(metricLabels).build();
// Prepares the monitored resource descriptor
Map<String, String> resourceLabels = new HashMap<String, String>();
resourceLabels.put("instance_id", "1234567890123456789");
resourceLabels.put("zone", "us-central1-f");
MonitoredResource resource = MonitoredResource.newBuilder().setType("gce_instance").putAllLabels(resourceLabels).build();
// Prepares the time series request
TimeSeries timeSeries = TimeSeries.newBuilder().setMetric(metric).setResource(resource).addAllPoints(pointList).build();
List<TimeSeries> timeSeriesList = new ArrayList<>();
timeSeriesList.add(timeSeries);
CreateTimeSeriesRequest request = CreateTimeSeriesRequest.newBuilder().setName(name.toString()).addAllTimeSeries(timeSeriesList).build();
// Writes time series data
metricServiceClient.createTimeSeries(request);
System.out.printf("Done writing time series data.%n");
metricServiceClient.close();
}
use of com.google.cloud.bigquery.datatransfer.v1.ProjectName in project java-docs-samples by GoogleCloudPlatform.
the class Snippets method listMetricDescriptors.
/**
* Returns the first page of all metric descriptors.
*/
void listMetricDescriptors() throws IOException {
// [START monitoring_list_descriptors]
// Your Google Cloud Platform project ID
String projectId = System.getProperty("projectId");
final MetricServiceClient client = MetricServiceClient.create();
ProjectName name = ProjectName.of(projectId);
ListMetricDescriptorsRequest request = ListMetricDescriptorsRequest.newBuilder().setName(name.toString()).build();
ListMetricDescriptorsPagedResponse response = client.listMetricDescriptors(request);
System.out.println("Listing descriptors: ");
for (MetricDescriptor d : response.iterateAll()) {
System.out.println(d.getName() + " " + d.getDisplayName());
}
// [END monitoring_list_descriptors]
}
Aggregations