Search in sources :

Example 1 with Zones

use of com.google.api.services.dataplex.v1.CloudDataplex.Projects.Locations.Lakes.Zones in project DataflowTemplates by GoogleCloudPlatform.

the class DefaultDataplexClient method getEntities.

@Override
public ImmutableList<GoogleCloudDataplexV1Entity> getEntities(List<String> entityNames) throws IOException {
    Entities entities = client.projects().locations().lakes().zones().entities();
    ImmutableList.Builder<GoogleCloudDataplexV1Entity> result = ImmutableList.builder();
    for (String entityName : entityNames) {
        result.add(entities.get(entityName).setView(GetEntityRequestEntityView.FULL.name()).execute());
    }
    return result.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) 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 Zones

use of com.google.api.services.dataplex.v1.CloudDataplex.Projects.Locations.Lakes.Zones 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 3 with Zones

use of com.google.api.services.dataplex.v1.CloudDataplex.Projects.Locations.Lakes.Zones in project DataflowTemplates by GoogleCloudPlatform.

the class DefaultDataplexClient method createPartitions.

/**
 * Handles creation of partitions. Each partition is logged after being created.
 */
private void createPartitions(ImmutableMap<String, ImmutableList<PartitionMetadata>> entityNameToPartition) throws IOException {
    for (Map.Entry<String, ImmutableList<PartitionMetadata>> entry : entityNameToPartition.entrySet()) {
        ImmutableList<GoogleCloudDataplexV1Partition> partitions = entry.getValue().stream().map(PartitionMetadata::toDataplexPartition).collect(toImmutableList());
        for (GoogleCloudDataplexV1Partition partition : partitions) {
            GoogleCloudDataplexV1Partition result = client.projects().locations().lakes().zones().entities().partitions().create(entry.getKey(), partition).execute();
            LOG.info("Created partition '{}' under entity '{}'", result.getName(), entry.getKey());
        }
    }
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) GoogleCloudDataplexV1Partition(com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1Partition) HashMap(java.util.HashMap) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 4 with Zones

use of com.google.api.services.dataplex.v1.CloudDataplex.Projects.Locations.Lakes.Zones in project DataflowTemplates by GoogleCloudPlatform.

the class DefaultDataplexClient method getPartitions.

@Override
public ImmutableList<GoogleCloudDataplexV1Partition> getPartitions(String entityName) throws IOException {
    ImmutableList.Builder<GoogleCloudDataplexV1Partition> result = ImmutableList.builder();
    Partitions partitions = client.projects().locations().lakes().zones().entities().partitions();
    GoogleCloudDataplexV1ListPartitionsResponse response = partitions.list(entityName).execute();
    if (response.getPartitions() == null) {
        return ImmutableList.of();
    }
    result.addAll(response.getPartitions());
    // the result of the list is paginated with the default page size being 10
    while (response.getNextPageToken() != null) {
        response = partitions.list(entityName).setPageToken(response.getNextPageToken()).execute();
        result.addAll(response.getPartitions());
    }
    return result.build();
}
Also used : Partitions(com.google.api.services.dataplex.v1.CloudDataplex.Projects.Locations.Lakes.Zones.Entities.Partitions) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) GoogleCloudDataplexV1ListPartitionsResponse(com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1ListPartitionsResponse) GoogleCloudDataplexV1Partition(com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1Partition)

Example 5 with Zones

use of com.google.api.services.dataplex.v1.CloudDataplex.Projects.Locations.Lakes.Zones in project DataflowTemplates by GoogleCloudPlatform.

the class DefaultDataplexClient method updateEntitiesUnderAsset.

/**
 * Handles just updating of entities. Each entity is logged after updating.
 */
private Map<EntityMetadata, GoogleCloudDataplexV1Entity> updateEntitiesUnderAsset(String assetName, Map<EntityMetadata, GoogleCloudDataplexV1Entity> metadataToEntity) throws IOException {
    Map<EntityMetadata, GoogleCloudDataplexV1Entity> updatedMetadataToEntity = new HashMap<>();
    for (Map.Entry<EntityMetadata, GoogleCloudDataplexV1Entity> entry : metadataToEntity.entrySet()) {
        EntityMetadata metadata = entry.getKey();
        GoogleCloudDataplexV1Entity existing = entry.getValue();
        metadata.updateDataplexEntity(existing);
        GoogleCloudDataplexV1Entity updated = client.projects().locations().lakes().zones().entities().update(existing.getName(), existing.setAsset(assetName)).execute();
        LOG.info("Updated entity with name '{}' that points to data path '{}'", updated.getName(), metadata.dataPath());
        updatedMetadataToEntity.put(metadata, updated);
    }
    return updatedMetadataToEntity;
}
Also used : EntityMetadata(com.google.cloud.teleport.v2.values.EntityMetadata) HashMap(java.util.HashMap) GoogleCloudDataplexV1Entity(com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1Entity) HashMap(java.util.HashMap) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Aggregations

GoogleCloudDataplexV1Entity (com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1Entity)6 CloudDataplex (com.google.api.services.dataplex.v1.CloudDataplex)4 Test (org.junit.Test)4 Entities (com.google.api.services.dataplex.v1.CloudDataplex.Projects.Locations.Lakes.Zones.Entities)3 GoogleCloudDataplexV1Partition (com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1Partition)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)3 HashMap (java.util.HashMap)3 Partitions (com.google.api.services.dataplex.v1.CloudDataplex.Projects.Locations.Lakes.Zones.Entities.Partitions)2 GoogleCloudDataplexV1ListEntitiesResponse (com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1ListEntitiesResponse)2 GoogleCloudDataplexV1ListPartitionsResponse (com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1ListPartitionsResponse)2 EntityMetadata (com.google.cloud.teleport.v2.values.EntityMetadata)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 Map (java.util.Map)2 Collectors.toMap (java.util.stream.Collectors.toMap)2 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 GoogleCloudDataplexV1Asset (com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1Asset)1 GoogleCloudDataplexV1AssetResourceSpec (com.google.api.services.dataplex.v1.model.GoogleCloudDataplexV1AssetResourceSpec)1 Before (org.junit.Before)1