Search in sources :

Example 56 with ProjectName

use of com.google.storage.v2.ProjectName in project java-recaptchaenterprise by googleapis.

the class RecaptchaEnterpriseServiceClientTest method listRelatedAccountGroupsExceptionTest.

@Test
public void listRelatedAccountGroupsExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockRecaptchaEnterpriseService.addException(exception);
    try {
        ProjectName parent = ProjectName.of("[PROJECT]");
        client.listRelatedAccountGroups(parent);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) ProjectName(com.google.recaptchaenterprise.v1.ProjectName) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 57 with ProjectName

use of com.google.storage.v2.ProjectName in project java-recaptchaenterprise by googleapis.

the class RecaptchaEnterpriseServiceClientTest method createAssessmentExceptionTest.

@Test
public void createAssessmentExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockRecaptchaEnterpriseService.addException(exception);
    try {
        ProjectName parent = ProjectName.of("[PROJECT]");
        Assessment assessment = Assessment.newBuilder().build();
        client.createAssessment(parent, assessment);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) ProjectName(com.google.recaptchaenterprise.v1.ProjectName) Assessment(com.google.recaptchaenterprise.v1.Assessment) AccountDefenderAssessment(com.google.recaptchaenterprise.v1.AccountDefenderAssessment) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Example 58 with ProjectName

use of com.google.storage.v2.ProjectName in project java-asset by googleapis.

the class ExportAssetsExample method exportAssets.

// Export assets for a project.
// @param exportPath where the results will be exported to.
public static void exportAssets(String exportPath, ContentType contentType) throws IOException, IllegalArgumentException, InterruptedException, ExecutionException {
    try (AssetServiceClient client = AssetServiceClient.create()) {
        ProjectName parent = ProjectName.of(projectId);
        OutputConfig outputConfig = OutputConfig.newBuilder().setGcsDestination(GcsDestination.newBuilder().setUri(exportPath).build()).build();
        ExportAssetsRequest request = ExportAssetsRequest.newBuilder().setParent(parent.toString()).setOutputConfig(outputConfig).setContentType(contentType).build();
        ExportAssetsResponse response = client.exportAssetsAsync(request).get();
        System.out.println(response);
    }
}
Also used : OutputConfig(com.google.cloud.asset.v1.OutputConfig) ExportAssetsRequest(com.google.cloud.asset.v1.ExportAssetsRequest) ProjectName(com.google.cloud.asset.v1.ProjectName) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) ExportAssetsResponse(com.google.cloud.asset.v1.ExportAssetsResponse)

Example 59 with ProjectName

use of com.google.storage.v2.ProjectName in project java-asset by googleapis.

the class ListAssetsExample method listAssets.

public static void listAssets(String projectId, String[] assetTypes, ContentType contentType) throws IOException, IllegalArgumentException {
    try (AssetServiceClient client = AssetServiceClient.create()) {
        ProjectName parent = ProjectName.of(projectId);
        // Build initial ListAssetsRequest without setting page token.
        ListAssetsRequest request = ListAssetsRequest.newBuilder().setParent(parent.toString()).addAllAssetTypes(Arrays.asList(assetTypes)).setContentType(contentType).build();
        // Repeatedly call ListAssets until page token is empty.
        ListAssetsPagedResponse response = client.listAssets(request);
        System.out.println(response);
        while (!response.getNextPageToken().isEmpty()) {
            request = request.toBuilder().setPageToken(response.getNextPageToken()).build();
            response = client.listAssets(request);
            System.out.println(response);
        }
    }
}
Also used : ListAssetsRequest(com.google.cloud.asset.v1.ListAssetsRequest) ProjectName(com.google.cloud.asset.v1.ProjectName) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) ListAssetsPagedResponse(com.google.cloud.asset.v1.AssetServiceClient.ListAssetsPagedResponse)

Example 60 with ProjectName

use of com.google.storage.v2.ProjectName in project grpc-gcp-java by GoogleCloudPlatform.

the class StackdriverUtils method reportError.

/**
 * Report the error to the stackdriver errorlog.
 */
public void reportError(String error, String funcName, int line) {
    // Report to the std error.
    System.err.println(error);
    // Report to the stackdriver.
    if (errClient != null) {
        String projectId = ServiceOptions.getDefaultProjectId();
        ProjectName projectName = ProjectName.of(projectId);
        // Custom error events require an error reporting location as well.
        ErrorContext errorContext = ErrorContext.newBuilder().setReportLocation(SourceLocation.newBuilder().setFilePath("Prober.java").setLineNumber(line).setFunctionName(funcName).build()).build();
        // Report a custom error event
        ReportedErrorEvent customErrorEvent = ReportedErrorEvent.getDefaultInstance().toBuilder().setMessage(error).setContext(errorContext).build();
        // Report an event synchronously, use .reportErrorEventCallable for asynchronous reporting.
        errClient.reportErrorEvent(projectName, customErrorEvent);
    }
}
Also used : ProjectName(com.google.devtools.clouderrorreporting.v1beta1.ProjectName) ErrorContext(com.google.devtools.clouderrorreporting.v1beta1.ErrorContext) ReportedErrorEvent(com.google.devtools.clouderrorreporting.v1beta1.ReportedErrorEvent)

Aggregations

Test (org.junit.Test)186 StatusRuntimeException (io.grpc.StatusRuntimeException)89 AbstractMessage (com.google.protobuf.AbstractMessage)84 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)74 ProjectName (com.google.monitoring.v3.ProjectName)62 ProjectName (com.google.pubsub.v1.ProjectName)44 ProjectName (com.google.logging.v2.ProjectName)31 ArrayList (java.util.ArrayList)31 ProjectName (com.google.privacy.dlp.v2.ProjectName)22 ByteString (com.google.protobuf.ByteString)20 DataTransferServiceClient (com.google.cloud.bigquery.datatransfer.v1.DataTransferServiceClient)17 ProjectName (com.google.cloud.bigquery.datatransfer.v1.ProjectName)17 IOException (java.io.IOException)17 CreateTransferConfigRequest (com.google.cloud.bigquery.datatransfer.v1.CreateTransferConfigRequest)16 TransferConfig (com.google.cloud.bigquery.datatransfer.v1.TransferConfig)16 ProjectName (com.google.cloud.secretmanager.v1.ProjectName)16 ProjectName (com.google.containeranalysis.v1beta1.ProjectName)16 ApiException (com.google.api.gax.rpc.ApiException)15 MetricServiceClient (com.google.cloud.monitoring.v3.MetricServiceClient)15 TimeSeries (com.google.monitoring.v3.TimeSeries)15