use of com.google.cloud.asset.v1.AssetServiceClient in project java-asset by googleapis.
the class UpdateFeedExample method updateFeed.
// Update a feed
public static void updateFeed(String feedName, String topic) throws Exception {
// String feedName = "MY_FEED_NAME"
// String topic = "projects/[PROJECT_ID]/topics/[TOPIC_NAME]"
Feed feed = Feed.newBuilder().setName(feedName).setFeedOutputConfig(FeedOutputConfig.newBuilder().setPubsubDestination(PubsubDestination.newBuilder().setTopic(topic).build()).build()).build();
UpdateFeedRequest request = UpdateFeedRequest.newBuilder().setFeed(feed).setUpdateMask(FieldMask.newBuilder().addPaths("feed_output_config.pubsub_destination.topic").build()).build();
// the "close" method on the client to safely clean up any remaining background resources.
try (AssetServiceClient client = AssetServiceClient.create()) {
Feed response = client.updateFeed(request);
System.out.println("Feed updated successfully: " + response.getName());
} catch (Exception e) {
System.out.println("Error during UpdateFeed: \n" + e.toString());
}
}
use of com.google.cloud.asset.v1.AssetServiceClient in project java-asset by googleapis.
the class BatchGetAssetsHistoryExample method main.
// Export assets for a project.
// @param args path where the results will be exported to.
public static void main(String... args) throws Exception {
// Asset names, e.g.: "//storage.googleapis.com/[BUCKET_NAME]"
String[] assetNames = args[0].split(",");
try (AssetServiceClient client = AssetServiceClient.create()) {
ProjectName parent = ProjectName.of(projectId);
ContentType contentType = ContentType.CONTENT_TYPE_UNSPECIFIED;
TimeWindow readTimeWindow = TimeWindow.newBuilder().build();
BatchGetAssetsHistoryRequest request = BatchGetAssetsHistoryRequest.newBuilder().setParent(parent.toString()).addAllAssetNames(Arrays.asList(assetNames)).setContentType(contentType).setReadTimeWindow(readTimeWindow).build();
BatchGetAssetsHistoryResponse response = client.batchGetAssetsHistory(request);
System.out.println(response);
}
}
Aggregations