use of com.google.cloud.talent.v4beta1.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"));
}
use of com.google.cloud.talent.v4beta1.ProjectName in project java-docs-samples by GoogleCloudPlatform.
the class ListSecrets method listSecrets.
// List all secrets for a project
public static void listSecrets(String projectId) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
// Build the parent name.
ProjectName projectName = ProjectName.of(projectId);
// Get all secrets.
ListSecretsPagedResponse pagedResponse = client.listSecrets(projectName);
// List all secrets.
pagedResponse.iterateAll().forEach(secret -> {
System.out.printf("Secret %s\n", secret.getName());
});
}
}
use of com.google.cloud.talent.v4beta1.ProjectName in project java-docs-samples by GoogleCloudPlatform.
the class Quickstart method quickstart.
public void quickstart(String projectId, String secretId) throws Exception {
// the "close" method on the client to safely clean up any remaining background resources.
try (SecretManagerServiceClient client = SecretManagerServiceClient.create()) {
// Build the parent name from the project.
ProjectName projectName = ProjectName.of(projectId);
// Create the parent secret.
Secret secret = Secret.newBuilder().setReplication(Replication.newBuilder().setAutomatic(Replication.Automatic.newBuilder().build()).build()).build();
Secret createdSecret = client.createSecret(projectName, secretId, secret);
// Add a secret version.
SecretPayload payload = SecretPayload.newBuilder().setData(ByteString.copyFromUtf8("hello world!")).build();
SecretVersion addedVersion = client.addSecretVersion(createdSecret.getName(), payload);
// Access the secret version.
AccessSecretVersionResponse response = client.accessSecretVersion(addedVersion.getName());
// Print the secret payload.
//
// WARNING: Do not print the secret in a production environment - this
// snippet is showing how to access the secret material.
String data = response.getPayload().getData().toStringUtf8();
System.out.printf("Plaintext: %s\n", data);
}
}
use of com.google.cloud.talent.v4beta1.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]
}
use of com.google.cloud.talent.v4beta1.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]
}
Aggregations