use of com.google.api.services.dataplex.v1.CloudDataplex in project DataflowTemplates by GoogleCloudPlatform.
the class DefaultDataplexClient method withDefaultClient.
/**
* Returns an instance of {@link DefaultDataplexClient} that will utilize the default {@link
* CloudDataplex}.
*
* @return a new instance of {@link DefaultDataplexClient}
*/
public static DefaultDataplexClient withDefaultClient(Credentials credential) throws IOException {
HttpTransport transport = Utils.getDefaultTransport();
JsonFactory jsonFactory = Utils.getDefaultJsonFactory();
HttpRequestInitializer httpInitializer = new HttpCredentialsAdapter(credential);
CloudDataplex client = new CloudDataplex.Builder(transport, jsonFactory, httpInitializer).setApplicationName(DEFAULT_CLIENT_NAME).setRootUrl(DEFAULT_ROOT_URL).build();
return new DefaultDataplexClient(client);
}
use of com.google.api.services.dataplex.v1.CloudDataplex in project DataflowTemplates by GoogleCloudPlatform.
the class DefaultDataplexClientTest method testGetPartitionsByEntityName.
@Test
public void testGetPartitionsByEntityName() throws IOException {
CloudDataplex cloudDataplexClient = mock(CloudDataplex.class, Answers.RETURNS_DEEP_STUBS);
Partitions partitions = mock(Partitions.class, Answers.RETURNS_DEEP_STUBS);
when(cloudDataplexClient.projects().locations().lakes().zones().entities().partitions()).thenReturn(partitions);
GoogleCloudDataplexV1Partition partition1 = new GoogleCloudDataplexV1Partition().setName("partition1");
GoogleCloudDataplexV1Partition partition2 = new GoogleCloudDataplexV1Partition().setName("partition2");
GoogleCloudDataplexV1Partition partition3 = new GoogleCloudDataplexV1Partition().setName("partition2");
GoogleCloudDataplexV1ListPartitionsResponse response1 = new GoogleCloudDataplexV1ListPartitionsResponse().setPartitions(ImmutableList.of(partition1, partition2)).setNextPageToken(PAGE_TOKEN);
GoogleCloudDataplexV1ListPartitionsResponse response2 = new GoogleCloudDataplexV1ListPartitionsResponse().setPartitions(ImmutableList.of(partition3));
when(partitions.list("entity0").execute()).thenReturn(response1);
when(partitions.list("entity0").setPageToken(eq(PAGE_TOKEN)).execute()).thenReturn(response2);
assertEquals(ImmutableList.of(partition1, partition2, partition3), DefaultDataplexClient.withClient(cloudDataplexClient).getPartitions("entity0"));
}
use of com.google.api.services.dataplex.v1.CloudDataplex 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));
}
use of com.google.api.services.dataplex.v1.CloudDataplex in project DataflowTemplates by GoogleCloudPlatform.
the class DefaultDataplexClientTest method testCreateEntitiesWhenDiscoveryEnabled.
@Test
public void testCreateEntitiesWhenDiscoveryEnabled() throws IOException {
CloudDataplex dataplex = mock(CloudDataplex.class, Answers.RETURNS_DEEP_STUBS);
Zones zones = getZones(dataplex);
Assets assets = getAssets(dataplex);
// Don't care about the order they're checked, so set up for two calls.
when(assets.get(any()).execute()).thenReturn(createAsset(ENABLED_ASSET_DISCOVERY_SPEC)).thenReturn(createAsset(DISABLED_ASSET_DISCOVERY_SPEC));
when(zones.get(any()).execute()).thenReturn(createZone(ENABLED_ZONE_DISCOVERY_SPEC)).thenReturn(createZone(DISABLED_ZONE_DISCOVERY_SPEC));
DataplexClient client = DefaultDataplexClient.withClient(dataplex);
client.createMetadata(ASSET_NAME1, ImmutableList.of(UNUSED_METADATA), CreateBehavior.UPDATE_IF_EXISTS);
client.createMetadata(ASSET_NAME1, ImmutableList.of(UNUSED_METADATA), CreateBehavior.UPDATE_IF_EXISTS);
verify(assets, atLeastOnce()).get(ASSET_NAME1);
verify(zones, atLeastOnce()).get(ZONE_NAME);
// Enough to know nothing was done with partitions
verify(zones, never()).entities();
}
use of com.google.api.services.dataplex.v1.CloudDataplex in project DataflowTemplates by GoogleCloudPlatform.
the class DefaultDataplexClientTest method testGetEntitiesByEntityNames.
@Test
public void testGetEntitiesByEntityNames() throws IOException {
CloudDataplex cloudDataplexClient = mock(CloudDataplex.class, Answers.RETURNS_DEEP_STUBS);
GoogleCloudDataplexV1Entity entity1 = new GoogleCloudDataplexV1Entity().setName("entity1").setAsset(ASSET_NAME1).setSystem(StorageSystem.CLOUD_STORAGE.name());
GoogleCloudDataplexV1Entity entity2 = new GoogleCloudDataplexV1Entity().setName("entity2").setAsset(ASSET_NAME1).setSystem(StorageSystem.CLOUD_STORAGE.name());
GoogleCloudDataplexV1Entity entity3 = new GoogleCloudDataplexV1Entity().setName("entity3").setAsset(ASSET_NAME1).setSystem(StorageSystem.CLOUD_STORAGE.name());
when(cloudDataplexClient.projects().locations().lakes().zones().entities().get("entity1").setView(GetEntityRequestEntityView.FULL.name()).execute()).thenReturn(entity1);
when(cloudDataplexClient.projects().locations().lakes().zones().entities().get("entity2").setView(GetEntityRequestEntityView.FULL.name()).execute()).thenReturn(entity2);
when(cloudDataplexClient.projects().locations().lakes().zones().entities().get("entity3").setView(GetEntityRequestEntityView.FULL.name()).execute()).thenReturn(entity3);
assertEquals(ImmutableList.of(entity1, entity2, entity3), DefaultDataplexClient.withClient(cloudDataplexClient).getEntities(ImmutableList.of("entity1", "entity2", "entity3")));
}
Aggregations