use of com.google.logging.v2.LocationName in project java-docs-samples by GoogleCloudPlatform.
the class Quickstart method quickstart.
public void quickstart(String projectId, String locationId) throws IOException {
// safely clean up any remaining background resources.
try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) {
// Build the parent from the project and location.
LocationName parent = LocationName.of(projectId, locationId);
// Call the API.
ListKeyRingsPagedResponse response = client.listKeyRings(parent);
// Iterate over each key ring and print its name.
System.out.println("key rings:");
for (KeyRing keyRing : response.iterateAll()) {
System.out.printf("%s%n", keyRing.getName());
}
}
}
use of com.google.logging.v2.LocationName in project java-docs-samples by GoogleCloudPlatform.
the class WorkflowsQuickstartTest method deployWorkflow.
private static void deployWorkflow(String projectId, String location, String workflowId) throws IOException, InterruptedException, ExecutionException {
if (workflowsClient == null) {
workflowsClient = WorkflowsClient.create();
}
LocationName parent = LocationName.of(projectId, location);
String source = new String(Files.readAllBytes(Paths.get("src/test/java/com/example/workflows/resources/source.yaml")));
Workflow workflow = Workflow.newBuilder().setSourceContents(source).build();
// Deploy workflow
workflowsClient.createWorkflowAsync(parent, workflow, workflowId).get();
}
use of com.google.logging.v2.LocationName in project java-automl by googleapis.
the class LanguageTextClassificationCreateDataset method createDataset.
// Create a dataset
static void createDataset(String projectId, String displayName) throws IOException, ExecutionException, InterruptedException {
// the "close" method on the client to safely clean up any remaining background resources.
try (AutoMlClient client = AutoMlClient.create()) {
// A resource that represents Google Cloud Platform location.
LocationName projectLocation = LocationName.of(projectId, "us-central1");
// Specify the classification type
// Types:
// MultiLabel: Multiple labels are allowed for one example.
// MultiClass: At most one label is allowed per example.
ClassificationType classificationType = ClassificationType.MULTILABEL;
// Specify the text classification type for the dataset.
TextClassificationDatasetMetadata metadata = TextClassificationDatasetMetadata.newBuilder().setClassificationType(classificationType).build();
Dataset dataset = Dataset.newBuilder().setDisplayName(displayName).setTextClassificationDatasetMetadata(metadata).build();
OperationFuture<Dataset, OperationMetadata> future = client.createDatasetAsync(projectLocation, dataset);
Dataset createdDataset = future.get();
// Display the dataset information.
System.out.format("Dataset name: %s\n", createdDataset.getName());
// To get the dataset id, you have to parse it out of the `name` field. As dataset Ids are
// required for other methods.
// Name Form: `projects/{project_id}/locations/{location_id}/datasets/{dataset_id}`
String[] names = createdDataset.getName().split("/");
String datasetId = names[names.length - 1];
System.out.format("Dataset id: %s\n", datasetId);
}
}
use of com.google.logging.v2.LocationName in project java-automl by googleapis.
the class ListOperationStatus method listOperationStatus.
// Get the status of an operation
static void listOperationStatus(String projectId) throws IOException {
// the "close" method on the client to safely clean up any remaining background resources.
try (AutoMlClient client = AutoMlClient.create()) {
// A resource that represents Google Cloud Platform location.
LocationName projectLocation = LocationName.of(projectId, "us-central1");
// Create list operations request.
ListOperationsRequest listrequest = ListOperationsRequest.newBuilder().setName(projectLocation.toString()).build();
// List all the operations names available in the region by applying filter.
for (Operation operation : client.getOperationsClient().listOperations(listrequest).iterateAll()) {
System.out.println("Operation details:");
System.out.format("\tName: %s\n", operation.getName());
System.out.format("\tMetadata Type Url: %s\n", operation.getMetadata().getTypeUrl());
System.out.format("\tDone: %s\n", operation.getDone());
if (operation.hasResponse()) {
System.out.format("\tResponse Type Url: %s\n", operation.getResponse().getTypeUrl());
}
if (operation.hasError()) {
System.out.println("\tResponse:");
System.out.format("\t\tError code: %s\n", operation.getError().getCode());
System.out.format("\t\tError message: %s\n\n", operation.getError().getMessage());
}
}
}
}
use of com.google.logging.v2.LocationName in project java-automl by googleapis.
the class VisionClassificationCreateModel method createModel.
// Create a model
static void createModel(String projectId, String datasetId, String displayName) throws IOException, ExecutionException, InterruptedException {
// the "close" method on the client to safely clean up any remaining background resources.
try (AutoMlClient client = AutoMlClient.create()) {
// A resource that represents Google Cloud Platform location.
LocationName projectLocation = LocationName.of(projectId, "us-central1");
// Set model metadata.
ImageClassificationModelMetadata metadata = ImageClassificationModelMetadata.newBuilder().setTrainBudgetMilliNodeHours(24000).build();
Model model = Model.newBuilder().setDisplayName(displayName).setDatasetId(datasetId).setImageClassificationModelMetadata(metadata).build();
// Create a model with the model metadata in the region.
OperationFuture<Model, OperationMetadata> future = client.createModelAsync(projectLocation, model);
// OperationFuture.get() will block until the model is created, which may take several hours.
// You can use OperationFuture.getInitialFuture to get a future representing the initial
// response to the request, which contains information while the operation is in progress.
System.out.format("Training operation name: %s\n", future.getInitialFuture().get().getName());
System.out.println("Training started...");
}
}
Aggregations