Search in sources :

Example 1 with ExportAssetsRequest

use of com.google.cloud.asset.v1.ExportAssetsRequest in project gapic-generator-java by googleapis.

the class AsyncExportAssets method asyncExportAssets.

public static void asyncExportAssets() throws Exception {
    // It may require modifications to work in your environment.
    try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
        ExportAssetsRequest request = ExportAssetsRequest.newBuilder().setParent(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()).setReadTime(Timestamp.newBuilder().build()).addAllAssetTypes(new ArrayList<String>()).setContentType(ContentType.forNumber(0)).setOutputConfig(OutputConfig.newBuilder().build()).addAllRelationshipTypes(new ArrayList<String>()).build();
        ApiFuture<Operation> future = assetServiceClient.exportAssetsCallable().futureCall(request);
        // Do something.
        Operation response = future.get();
    }
}
Also used : ExportAssetsRequest(com.google.cloud.asset.v1.ExportAssetsRequest) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) ArrayList(java.util.ArrayList) Operation(com.google.longrunning.Operation)

Example 2 with ExportAssetsRequest

use of com.google.cloud.asset.v1.ExportAssetsRequest 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 3 with ExportAssetsRequest

use of com.google.cloud.asset.v1.ExportAssetsRequest in project gapic-generator-java by googleapis.

the class AsyncExportAssetsLRO method asyncExportAssetsLRO.

public static void asyncExportAssetsLRO() throws Exception {
    // It may require modifications to work in your environment.
    try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
        ExportAssetsRequest request = ExportAssetsRequest.newBuilder().setParent(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()).setReadTime(Timestamp.newBuilder().build()).addAllAssetTypes(new ArrayList<String>()).setContentType(ContentType.forNumber(0)).setOutputConfig(OutputConfig.newBuilder().build()).addAllRelationshipTypes(new ArrayList<String>()).build();
        OperationFuture<ExportAssetsResponse, ExportAssetsRequest> future = assetServiceClient.exportAssetsOperationCallable().futureCall(request);
        // Do something.
        ExportAssetsResponse response = future.get();
    }
}
Also used : ExportAssetsRequest(com.google.cloud.asset.v1.ExportAssetsRequest) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) ArrayList(java.util.ArrayList) ExportAssetsResponse(com.google.cloud.asset.v1.ExportAssetsResponse)

Example 4 with ExportAssetsRequest

use of com.google.cloud.asset.v1.ExportAssetsRequest in project gapic-generator-java by googleapis.

the class SyncExportAssets method syncExportAssets.

public static void syncExportAssets() throws Exception {
    // It may require modifications to work in your environment.
    try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
        ExportAssetsRequest request = ExportAssetsRequest.newBuilder().setParent(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()).setReadTime(Timestamp.newBuilder().build()).addAllAssetTypes(new ArrayList<String>()).setContentType(ContentType.forNumber(0)).setOutputConfig(OutputConfig.newBuilder().build()).addAllRelationshipTypes(new ArrayList<String>()).build();
        ExportAssetsResponse response = assetServiceClient.exportAssetsAsync(request).get();
    }
}
Also used : ExportAssetsRequest(com.google.cloud.asset.v1.ExportAssetsRequest) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) ArrayList(java.util.ArrayList) ExportAssetsResponse(com.google.cloud.asset.v1.ExportAssetsResponse)

Example 5 with ExportAssetsRequest

use of com.google.cloud.asset.v1.ExportAssetsRequest in project java-asset by googleapis.

the class ExportAssetsBigqueryExample method exportBigQuery.

// Export assets to BigQuery for a project.
public static void exportBigQuery(String bigqueryDataset, String bigqueryTable, ContentType contentType, boolean isPerType) throws IOException, IllegalArgumentException, InterruptedException, ExecutionException {
    try (AssetServiceClient client = AssetServiceClient.create()) {
        ProjectName parent = ProjectName.of(projectId);
        OutputConfig outputConfig;
        // Outputs to per-type BigQuery table.
        if (isPerType) {
            outputConfig = OutputConfig.newBuilder().setBigqueryDestination(BigQueryDestination.newBuilder().setDataset(bigqueryDataset).setTable(bigqueryTable).setForce(true).setSeparateTablesPerAssetType(true).setPartitionSpec(PartitionSpec.newBuilder().setPartitionKey(PartitionSpec.PartitionKey.READ_TIME).build()).build()).build();
        } else {
            outputConfig = OutputConfig.newBuilder().setBigqueryDestination(BigQueryDestination.newBuilder().setDataset(bigqueryDataset).setTable(bigqueryTable).setForce(true).build()).build();
        }
        ExportAssetsRequest request = ExportAssetsRequest.newBuilder().setParent(parent.toString()).setContentType(contentType).setOutputConfig(outputConfig).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)

Aggregations

AssetServiceClient (com.google.cloud.asset.v1.AssetServiceClient)5 ExportAssetsRequest (com.google.cloud.asset.v1.ExportAssetsRequest)5 ExportAssetsResponse (com.google.cloud.asset.v1.ExportAssetsResponse)4 ArrayList (java.util.ArrayList)3 OutputConfig (com.google.cloud.asset.v1.OutputConfig)2 ProjectName (com.google.cloud.asset.v1.ProjectName)2 Operation (com.google.longrunning.Operation)1