Search in sources :

Example 21 with Feed

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

the class SyncGetFeed method syncGetFeed.

public static void syncGetFeed() throws Exception {
    // It may require modifications to work in your environment.
    try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
        GetFeedRequest request = GetFeedRequest.newBuilder().setName(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()).build();
        Feed response = assetServiceClient.getFeed(request);
    }
}
Also used : AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) GetFeedRequest(com.google.cloud.asset.v1.GetFeedRequest) Feed(com.google.cloud.asset.v1.Feed)

Example 22 with Feed

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

the class AsyncListAssets method asyncListAssets.

public static void asyncListAssets() throws Exception {
    // It may require modifications to work in your environment.
    try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
        ListAssetsRequest request = ListAssetsRequest.newBuilder().setParent(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()).setReadTime(Timestamp.newBuilder().build()).addAllAssetTypes(new ArrayList<String>()).setContentType(ContentType.forNumber(0)).setPageSize(883849137).setPageToken("pageToken873572522").addAllRelationshipTypes(new ArrayList<String>()).build();
        ApiFuture<Asset> future = assetServiceClient.listAssetsPagedCallable().futureCall(request);
        // Do something.
        for (Asset element : future.get().iterateAll()) {
        // doThingsWith(element);
        }
    }
}
Also used : ListAssetsRequest(com.google.cloud.asset.v1.ListAssetsRequest) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) ArrayList(java.util.ArrayList) Asset(com.google.cloud.asset.v1.Asset)

Example 23 with Feed

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

the class AssetServiceClientTest method listAssetsTest.

@Test
public void listAssetsTest() throws Exception {
    Asset responsesElement = Asset.newBuilder().build();
    ListAssetsResponse expectedResponse = ListAssetsResponse.newBuilder().setNextPageToken("").addAllAssets(Arrays.asList(responsesElement)).build();
    mockAssetService.addResponse(expectedResponse);
    ResourceName parent = FeedName.ofProjectFeedName("[PROJECT]", "[FEED]");
    ListAssetsPagedResponse pagedListResponse = client.listAssets(parent);
    List<Asset> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getAssetsList().get(0), resources.get(0));
    List<AbstractMessage> actualRequests = mockAssetService.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListAssetsRequest actualRequest = ((ListAssetsRequest) actualRequests.get(0));
    Assert.assertEquals(parent.toString(), actualRequest.getParent());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : AbstractMessage(com.google.protobuf.AbstractMessage) ResourceName(com.google.api.resourcenames.ResourceName) ListAssetsPagedResponse(com.google.cloud.asset.v1.AssetServiceClient.ListAssetsPagedResponse) Test(org.junit.Test)

Example 24 with Feed

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

the class SyncUpdateFeed method syncUpdateFeed.

public static void syncUpdateFeed() throws Exception {
    // It may require modifications to work in your environment.
    try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
        UpdateFeedRequest request = UpdateFeedRequest.newBuilder().setFeed(Feed.newBuilder().build()).setUpdateMask(FieldMask.newBuilder().build()).build();
        Feed response = assetServiceClient.updateFeed(request);
    }
}
Also used : UpdateFeedRequest(com.google.cloud.asset.v1.UpdateFeedRequest) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) Feed(com.google.cloud.asset.v1.Feed)

Example 25 with Feed

use of com.google.cloud.asset.v1.Feed 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());
    }
}
Also used : UpdateFeedRequest(com.google.cloud.asset.v1.UpdateFeedRequest) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) Feed(com.google.cloud.asset.v1.Feed)

Aggregations

AssetServiceClient (com.google.cloud.asset.v1.AssetServiceClient)24 Feed (com.google.cloud.asset.v1.Feed)13 ArrayList (java.util.ArrayList)6 CreateFeedRequest (com.google.cloud.asset.v1.CreateFeedRequest)3 ExportAssetsRequest (com.google.cloud.asset.v1.ExportAssetsRequest)3 UpdateFeedRequest (com.google.cloud.asset.v1.UpdateFeedRequest)3 Asset (com.google.cloud.asset.v1.Asset)2 DeleteFeedRequest (com.google.cloud.asset.v1.DeleteFeedRequest)2 ExportAssetsResponse (com.google.cloud.asset.v1.ExportAssetsResponse)2 FeedName (com.google.cloud.asset.v1.FeedName)2 GetFeedRequest (com.google.cloud.asset.v1.GetFeedRequest)2 ListAssetsRequest (com.google.cloud.asset.v1.ListAssetsRequest)2 ResourceName (com.google.api.resourcenames.ResourceName)1 ListAssetsPagedResponse (com.google.cloud.asset.v1.AssetServiceClient.ListAssetsPagedResponse)1 BatchGetAssetsHistoryRequest (com.google.cloud.asset.v1.BatchGetAssetsHistoryRequest)1 BatchGetAssetsHistoryResponse (com.google.cloud.asset.v1.BatchGetAssetsHistoryResponse)1 ListAssetsResponse (com.google.cloud.asset.v1.ListAssetsResponse)1 Operation (com.google.longrunning.Operation)1 AbstractMessage (com.google.protobuf.AbstractMessage)1 Empty (com.google.protobuf.Empty)1