Search in sources :

Example 1 with GoogleCloudDataplexV1ListEntitiesResponse

use of com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1ListEntitiesResponse in project DataflowTemplates by GoogleCloudPlatform.

the class DefaultDataplexClient method getEntitiesUnderAssetStream.

/**
 * Gets a stream of all entities under {@code assetName}.
 */
private Stream<GoogleCloudDataplexV1Entity> getEntitiesUnderAssetStream(String assetName) throws IOException {
    Entities entities = client.projects().locations().lakes().zones().entities();
    String zoneName = getZoneFromAsset(assetName);
    GoogleCloudDataplexV1ListEntitiesResponse response = entities.list(zoneName).execute();
    Stream<GoogleCloudDataplexV1Entity> result = getEntitiesUnderAssetForPage(response, assetName);
    // the result of the list is paginated with the default page size being 10
    while (response.getNextPageToken() != null) {
        response = entities.list(zoneName).setPageToken(response.getNextPageToken()).execute();
        result = Stream.concat(result, getEntitiesUnderAssetForPage(response, assetName));
    }
    return result;
}
Also used : GoogleCloudDataplexV1ListEntitiesResponse(com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1ListEntitiesResponse) GoogleCloudDataplexV1Entity(com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1Entity) Entities(com.google.api.services.dataplex.v1.CloudDataplex.Projects.Locations.Lakes.Zones.Entities)

Example 2 with GoogleCloudDataplexV1ListEntitiesResponse

use of com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1ListEntitiesResponse in project DataflowTemplates by GoogleCloudPlatform.

the class DefaultDataplexClientTest method testGetGetCloudStorageEntitiesByAssetName.

@Test
public void testGetGetCloudStorageEntitiesByAssetName() throws IOException {
    CloudDataplex cloudDataplexClient = mock(CloudDataplex.class, Answers.RETURNS_DEEP_STUBS);
    Entities.List entitiesListRequest = mock(Entities.List.class, Answers.RETURNS_DEEP_STUBS);
    when(cloudDataplexClient.projects().locations().lakes().zones().entities().list(ZONE_NAME)).thenReturn(entitiesListRequest);
    GoogleCloudDataplexV1Entity entity1 = new GoogleCloudDataplexV1Entity().setName("entity1").setAsset(ASSET_NAME1).setSystem(StorageSystem.CLOUD_STORAGE.name());
    GoogleCloudDataplexV1Entity entity2 = new GoogleCloudDataplexV1Entity().setName("entity2").setAsset(ASSET_NAME1).setSystem(// storage mismatch
    "BIGQUERY");
    GoogleCloudDataplexV1Entity entity3 = new GoogleCloudDataplexV1Entity().setName("entity3").setAsset(ASSET_NAME1).setSystem(StorageSystem.CLOUD_STORAGE.name());
    GoogleCloudDataplexV1Entity entity4 = new GoogleCloudDataplexV1Entity().setName("entity4").setAsset(ASSET_NAME2).setSystem(// asset mismatch
    StorageSystem.CLOUD_STORAGE.name());
    // an entity with a short asset name
    GoogleCloudDataplexV1Entity entity5 = new GoogleCloudDataplexV1Entity().setName("entity5").setAsset(SHORT_ASSET_NAME1).setSystem(StorageSystem.CLOUD_STORAGE.name());
    GoogleCloudDataplexV1ListEntitiesResponse response1 = new GoogleCloudDataplexV1ListEntitiesResponse();
    response1.setEntities(ImmutableList.of(entity1, entity2, entity3));
    response1.setNextPageToken(PAGE_TOKEN);
    GoogleCloudDataplexV1ListEntitiesResponse response2 = new GoogleCloudDataplexV1ListEntitiesResponse();
    response2.setEntities(ImmutableList.of(entity4, entity5));
    when(entitiesListRequest.setPageToken(any())).thenReturn(entitiesListRequest);
    when(entitiesListRequest.execute()).thenReturn(response1, response2);
    when(cloudDataplexClient.projects().locations().lakes().zones().entities().get("entity1").setView(GetEntityRequestEntityView.FULL.name()).execute()).thenReturn(entity1);
    when(cloudDataplexClient.projects().locations().lakes().zones().entities().get("entity3").setView(GetEntityRequestEntityView.FULL.name()).execute()).thenReturn(entity3);
    when(cloudDataplexClient.projects().locations().lakes().zones().entities().get("entity5").setView(GetEntityRequestEntityView.FULL.name()).execute()).thenReturn(entity5);
    assertEquals(ImmutableList.of(entity1, entity3, entity5), DefaultDataplexClient.withClient(cloudDataplexClient).getCloudStorageEntities(ASSET_NAME1));
}
Also used : CloudDataplex(com.google.api.services.dataplex.v1.CloudDataplex) GoogleCloudDataplexV1ListEntitiesResponse(com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1ListEntitiesResponse) GoogleCloudDataplexV1Entity(com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1Entity) Entities(com.google.api.services.dataplex.v1.CloudDataplex.Projects.Locations.Lakes.Zones.Entities) Test(org.junit.Test)

Aggregations

Entities (com.google.api.services.dataplex.v1.CloudDataplex.Projects.Locations.Lakes.Zones.Entities)2 GoogleCloudDataplexV1Entity (com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1Entity)2 GoogleCloudDataplexV1ListEntitiesResponse (com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1ListEntitiesResponse)2 CloudDataplex (com.google.api.services.dataplex.v1.CloudDataplex)1 Test (org.junit.Test)1