Search in sources :

Example 1 with CloudDataplex

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);
}
Also used : HttpTransport(com.google.api.client.http.HttpTransport) HttpCredentialsAdapter(com.google.auth.http.HttpCredentialsAdapter) CloudDataplex(com.google.api.services.dataplex.v1.CloudDataplex) JsonFactory(com.google.api.client.json.JsonFactory) HttpRequestInitializer(com.google.api.client.http.HttpRequestInitializer)

Example 2 with CloudDataplex

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"));
}
Also used : CloudDataplex(com.google.api.services.dataplex.v1.CloudDataplex) Partitions(com.google.api.services.dataplex.v1.CloudDataplex.Projects.Locations.Lakes.Zones.Entities.Partitions) GoogleCloudDataplexV1ListPartitionsResponse(com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1ListPartitionsResponse) GoogleCloudDataplexV1Partition(com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1Partition) Test(org.junit.Test)

Example 3 with CloudDataplex

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));
}
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)

Example 4 with CloudDataplex

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();
}
Also used : CloudDataplex(com.google.api.services.dataplex.v1.CloudDataplex) Assets(com.google.api.services.dataplex.v1.CloudDataplex.Projects.Locations.Lakes.Zones.Assets) Zones(com.google.api.services.dataplex.v1.CloudDataplex.Projects.Locations.Lakes.Zones) Test(org.junit.Test)

Example 5 with CloudDataplex

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")));
}
Also used : CloudDataplex(com.google.api.services.dataplex.v1.CloudDataplex) GoogleCloudDataplexV1Entity(com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1Entity) Test(org.junit.Test)

Aggregations

CloudDataplex (com.google.api.services.dataplex.v1.CloudDataplex)5 Test (org.junit.Test)4 GoogleCloudDataplexV1Entity (com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1Entity)2 HttpRequestInitializer (com.google.api.client.http.HttpRequestInitializer)1 HttpTransport (com.google.api.client.http.HttpTransport)1 JsonFactory (com.google.api.client.json.JsonFactory)1 Zones (com.google.api.services.dataplex.v1.CloudDataplex.Projects.Locations.Lakes.Zones)1 Assets (com.google.api.services.dataplex.v1.CloudDataplex.Projects.Locations.Lakes.Zones.Assets)1 Entities (com.google.api.services.dataplex.v1.CloudDataplex.Projects.Locations.Lakes.Zones.Entities)1 Partitions (com.google.api.services.dataplex.v1.CloudDataplex.Projects.Locations.Lakes.Zones.Entities.Partitions)1 GoogleCloudDataplexV1ListEntitiesResponse (com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1ListEntitiesResponse)1 GoogleCloudDataplexV1ListPartitionsResponse (com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1ListPartitionsResponse)1 GoogleCloudDataplexV1Partition (com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1Partition)1 HttpCredentialsAdapter (com.google.auth.http.HttpCredentialsAdapter)1