Search in sources :

Example 71 with LocationName

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);
}
Also used : PrintStream(java.io.PrintStream) ListOperationsRequest(com.google.longrunning.ListOperationsRequest) Operation(com.google.longrunning.Operation) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient) LocationName(com.google.cloud.automl.v1beta1.LocationName) Before(org.junit.Before)

Example 72 with LocationName

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();
        }
    }
}
Also used : PrintStream(java.io.PrintStream) ArrayList(java.util.ArrayList) OperationsClient(com.google.longrunning.OperationsClient) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Operation(com.google.longrunning.Operation) ExponentialBackOff(com.google.api.client.util.ExponentialBackOff) IOException(java.io.IOException) ResourceExhaustedException(com.google.api.gax.rpc.ResourceExhaustedException) LocationName(com.google.cloud.automl.v1.LocationName) ResourceExhaustedException(com.google.api.gax.rpc.ResourceExhaustedException) ListOperationsRequest(com.google.longrunning.ListOperationsRequest) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient) Before(org.junit.Before)

Example 73 with LocationName

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());
    }
}
Also used : KeyRing(com.google.cloud.kms.v1.KeyRing) KeyManagementServiceClient(com.google.cloud.kms.v1.KeyManagementServiceClient) LocationName(com.google.cloud.kms.v1.LocationName)

Example 74 with LocationName

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());
        }
    }
}
Also used : CertificateAuthorityServiceClient(com.google.cloud.security.privateca.v1.CertificateAuthorityServiceClient) CaPool(com.google.cloud.security.privateca.v1.CaPool) LocationName(com.google.cloud.security.privateca.v1.LocationName)

Example 75 with LocationName

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()));
}
Also used : ListConnectionsRequest(com.google.cloud.bigquery.connection.v1.ListConnectionsRequest) ListConnectionsResponse(com.google.cloud.bigquery.connection.v1.ListConnectionsResponse) AbstractMessage(com.google.protobuf.AbstractMessage) Connection(com.google.cloud.bigquery.connection.v1.Connection) ListConnectionsPagedResponse(com.google.cloud.bigqueryconnection.v1.ConnectionServiceClient.ListConnectionsPagedResponse) LocationName(com.google.cloud.bigquery.connection.v1.LocationName) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)40 LocationName (com.google.cloud.aiplatform.v1.LocationName)36 AbstractMessage (com.google.protobuf.AbstractMessage)23 LocationName (com.google.privacy.dlp.v2.LocationName)22 OrganizationLocationName (com.google.privacy.dlp.v2.OrganizationLocationName)22 LocationName (com.google.cloud.translate.v3beta1.LocationName)18 TranslationServiceClient (com.google.cloud.translate.v3beta1.TranslationServiceClient)18 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)17 LocationName (com.google.cloud.automl.v1.LocationName)17 JobServiceClient (com.google.cloud.aiplatform.v1.JobServiceClient)15 JobServiceSettings (com.google.cloud.aiplatform.v1.JobServiceSettings)15 Value (com.google.protobuf.Value)15 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)14 Model (com.google.cloud.aiplatform.v1.Model)14 StatusRuntimeException (io.grpc.StatusRuntimeException)14 PipelineServiceClient (com.google.cloud.aiplatform.v1.PipelineServiceClient)13 PipelineServiceSettings (com.google.cloud.aiplatform.v1.PipelineServiceSettings)13 TrainingPipeline (com.google.cloud.aiplatform.v1.TrainingPipeline)13 LocationName (com.google.cloud.translate.v3.LocationName)13 TranslationServiceClient (com.google.cloud.translate.v3.TranslationServiceClient)13