use of com.google.cloud.dialogflow.v2.LocationName in project java-automl by googleapis.
the class GetOperationStatusTest method setUp.
@Before
public void setUp() throws IOException {
// Use list operations to get a single operation id for the get call.
try (AutoMlClient client = AutoMlClient.create()) {
LocationName projectLocation = LocationName.of(PROJECT_ID, "us-central1");
ListOperationsRequest request = ListOperationsRequest.newBuilder().setName(projectLocation.toString()).build();
Operation operation = client.getOperationsClient().listOperations(request).iterateAll().iterator().next();
operationId = operation.getName();
}
bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
originalPrintStream = System.out;
System.setOut(out);
}
use of com.google.cloud.dialogflow.v2.LocationName in project java-automl by googleapis.
the class ListOperationStatusTest method setUp.
@Before
public void setUp() throws IOException, InterruptedException {
bout = new ByteArrayOutputStream();
out = new PrintStream(bout);
originalPrintStream = System.out;
System.setOut(out);
// if the LRO status count more than 300, delete half of operations.
try (AutoMlClient client = AutoMlClient.create()) {
OperationsClient operationsClient = client.getOperationsClient();
LocationName projectLocation = LocationName.of(PROJECT_ID, "us-central1");
ListOperationsRequest listRequest = ListOperationsRequest.newBuilder().setName(projectLocation.toString()).build();
List<String> operationFullPathsToBeDeleted = new ArrayList<>();
for (Operation operation : operationsClient.listOperations(listRequest).iterateAll()) {
// Filter: deleting already done operations.
if (operation.getDone() && !operation.hasError()) {
operationFullPathsToBeDeleted.add(operation.getName());
}
}
if (operationFullPathsToBeDeleted.size() > 300) {
System.out.println("Cleaning up...");
for (String operationFullPath : operationFullPathsToBeDeleted.subList(0, operationFullPathsToBeDeleted.size() / 2)) {
// retry_interval * (random value in range [1 - rand_factor, 1 + rand_factor])
ExponentialBackOff exponentialBackOff = new ExponentialBackOff.Builder().setInitialIntervalMillis(60000).setMaxElapsedTimeMillis(300000).setRandomizationFactor(0.5).setMultiplier(1.1).setMaxIntervalMillis(80000).build();
// delete unused operations.
try {
operationsClient.deleteOperation(operationFullPath);
} catch (ResourceExhaustedException ex) {
// exponential back off and retry.
long backOffInMillis = exponentialBackOff.nextBackOffMillis();
System.out.printf("Backing off for %d milliseconds " + "due to Resource exhaustion.\n", backOffInMillis);
if (backOffInMillis < 0) {
break;
}
System.out.println("Backing off" + backOffInMillis);
TimeUnit.MILLISECONDS.sleep(backOffInMillis);
} catch (Exception ex) {
throw ex;
}
}
} else {
// Clear the list since we wont anything with the list.
operationFullPathsToBeDeleted.clear();
}
}
}
use of com.google.cloud.dialogflow.v2.LocationName in project java-kms by googleapis.
the class CreateKeyRing method createKeyRing.
// Create a new key ring.
public void createKeyRing(String projectId, String locationId, String id) throws IOException {
// safely clean up any remaining background resources.
try (KeyManagementServiceClient client = KeyManagementServiceClient.create()) {
// Build the parent name from the project and location.
LocationName locationName = LocationName.of(projectId, locationId);
// Build the key ring to create.
KeyRing keyRing = KeyRing.newBuilder().build();
// Create the key ring.
KeyRing createdKeyRing = client.createKeyRing(locationName, id, keyRing);
System.out.printf("Created key ring %s%n", createdKeyRing.getName());
}
}
use of com.google.cloud.dialogflow.v2.LocationName in project java-security-private-ca by googleapis.
the class ListCaPools method listCaPools.
// List all CA pools present in the given project and location.
public static void listCaPools(String project, String location) throws IOException {
// clean up any remaining background resources.
try (CertificateAuthorityServiceClient certificateAuthorityServiceClient = CertificateAuthorityServiceClient.create()) {
// Set the Location Name which contains project and location of the pool.
LocationName locationName = LocationName.newBuilder().setProject(project).setLocation(location).build();
String caPoolName = "";
System.out.println("Available CA pools: ");
// List the CA pools.
for (CaPool caPool : certificateAuthorityServiceClient.listCaPools(locationName).iterateAll()) {
caPoolName = caPool.getName();
// caPoolName represents the full resource name of the
// format 'projects/{project-id}/locations/{location}/ca-pools/{ca-pool-id}'.
// Hence stripping it down to just CA pool id.
System.out.println(caPoolName.substring(caPoolName.lastIndexOf("/") + 1) + " " + caPool.isInitialized());
}
}
}
use of com.google.cloud.dialogflow.v2.LocationName in project java-bigqueryconnection by googleapis.
the class ConnectionServiceClientTest method listConnectionsTest.
@Test
public void listConnectionsTest() throws Exception {
Connection responsesElement = Connection.newBuilder().build();
ListConnectionsResponse expectedResponse = ListConnectionsResponse.newBuilder().setNextPageToken("").addAllConnections(Arrays.asList(responsesElement)).build();
mockConnectionService.addResponse(expectedResponse);
LocationName parent = LocationName.of("[PROJECT]", "[LOCATION]");
ListConnectionsPagedResponse pagedListResponse = client.listConnections(parent);
List<Connection> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getConnectionsList().get(0), resources.get(0));
List<AbstractMessage> actualRequests = mockConnectionService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListConnectionsRequest actualRequest = ((ListConnectionsRequest) actualRequests.get(0));
Assert.assertEquals(parent.toString(), actualRequest.getParent());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Aggregations