Search in sources :

Example 1 with DataAddress

use of org.eclipse.dataspaceconnector.spi.types.domain.DataAddress in project DataSpaceConnector by eclipse-dataspaceconnector.

the class ObjectStorageDefinitionConsumerGenerator method generate.

@Override
@Nullable
public ResourceDefinition generate(TransferProcess process) {
    var request = process.getDataRequest();
    if (request.getDataDestination() == null || request.getDestinationType() == null || !AzureBlobStoreSchema.TYPE.equals(request.getDestinationType())) {
        return null;
    }
    DataAddress destination = request.getDataDestination();
    String id = randomUUID().toString();
    var account = destination.getProperty(AzureBlobStoreSchema.ACCOUNT_NAME);
    var container = destination.getProperty(AzureBlobStoreSchema.CONTAINER_NAME);
    if (container == null) {
        container = randomUUID().toString();
    }
    return ObjectStorageResourceDefinition.Builder.newInstance().id(id).accountName(account).containerName(container).build();
}
Also used : DataAddress(org.eclipse.dataspaceconnector.spi.types.domain.DataAddress) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with DataAddress

use of org.eclipse.dataspaceconnector.spi.types.domain.DataAddress in project DataSpaceConnector by eclipse-dataspaceconnector.

the class S3ResourceDefinitionConsumerGenerator method generate.

@Override
public ResourceDefinition generate(TransferProcess process) {
    var request = process.getDataRequest();
    if (request.getDestinationType() != null) {
        if (!S3BucketSchema.TYPE.equals(request.getDestinationType())) {
            return null;
        }
        // FIXME generate region from policy engine
        return S3BucketResourceDefinition.Builder.newInstance().id(randomUUID().toString()).bucketName(process.getId()).regionId(Region.US_EAST_1.id()).build();
    } else if (request.getDataDestination() == null || !(request.getDataDestination().getType().equals(S3BucketSchema.TYPE))) {
        return null;
    }
    DataAddress destination = request.getDataDestination();
    String id = randomUUID().toString();
    return S3BucketResourceDefinition.Builder.newInstance().id(id).bucketName(destination.getProperty(S3BucketSchema.BUCKET_NAME)).regionId(destination.getProperty(S3BucketSchema.REGION)).build();
}
Also used : DataAddress(org.eclipse.dataspaceconnector.spi.types.domain.DataAddress)

Example 3 with DataAddress

use of org.eclipse.dataspaceconnector.spi.types.domain.DataAddress in project DataSpaceConnector by eclipse-dataspaceconnector.

the class ObjectStorageDefinitionConsumerGeneratorTest method generate.

@Test
void generate() {
    DataAddress destination = DataAddress.Builder.newInstance().type(AzureBlobStoreSchema.TYPE).property(AzureBlobStoreSchema.CONTAINER_NAME, "test-container").property(AzureBlobStoreSchema.ACCOUNT_NAME, "test-account").build();
    var asset = Asset.Builder.newInstance().build();
    var dr = DataRequest.Builder.newInstance().dataDestination(destination).assetId(asset.getId()).build();
    var tp = TransferProcess.Builder.newInstance().dataRequest(dr).id(randomUUID().toString()).build();
    ResourceDefinition def = generator.generate(tp);
    assertThat(def).isInstanceOf(ObjectStorageResourceDefinition.class);
    var objectDef = (ObjectStorageResourceDefinition) def;
    assertThat(objectDef.getAccountName()).isEqualTo("test-account");
    assertThat(objectDef.getContainerName()).isEqualTo("test-container");
    assertThat(objectDef.getId()).matches(regexPattern);
}
Also used : ResourceDefinition(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ResourceDefinition) DataAddress(org.eclipse.dataspaceconnector.spi.types.domain.DataAddress) Test(org.junit.jupiter.api.Test)

Example 4 with DataAddress

use of org.eclipse.dataspaceconnector.spi.types.domain.DataAddress in project DataSpaceConnector by eclipse-dataspaceconnector.

the class ObjectStorageConsumerResourceDefinitionGeneratorTest method generate_containerIsNull.

@Test
void generate_containerIsNull() {
    DataAddress destination = DataAddress.Builder.newInstance().type(AzureBlobStoreSchema.TYPE).property(AzureBlobStoreSchema.ACCOUNT_NAME, "test-account").build();
    var asset = Asset.Builder.newInstance().build();
    var dataRequest = DataRequest.Builder.newInstance().dataDestination(destination).assetId(asset.getId()).build();
    var policy = Policy.Builder.newInstance().build();
    var definition = generator.generate(dataRequest, policy);
    assertThat(definition).isNotNull();
    assertThat(((ObjectStorageResourceDefinition) definition).getContainerName()).matches(regexPattern);
}
Also used : DataAddress(org.eclipse.dataspaceconnector.spi.types.domain.DataAddress) Test(org.junit.jupiter.api.Test)

Example 5 with DataAddress

use of org.eclipse.dataspaceconnector.spi.types.domain.DataAddress in project DataSpaceConnector by eclipse-dataspaceconnector.

the class CosmosAssetIndexIntegrationTest method queryAssets_selectAll.

@Test
void queryAssets_selectAll() {
    Asset asset1 = createAsset("123", "hello", "world");
    Asset asset2 = createAsset("456", "foo", "bar");
    container.createItem(new AssetDocument(asset1, TEST_PARTITION_KEY, dataAddress));
    container.createItem(new AssetDocument(asset2, TEST_PARTITION_KEY, dataAddress));
    List<Asset> assets = assetIndex.queryAssets(AssetSelectorExpression.SELECT_ALL).collect(Collectors.toList());
    assertThat(assets).hasSize(2).anyMatch(asset -> asset.getProperties().equals(asset1.getProperties())).anyMatch(asset -> asset.getProperties().equals(asset2.getProperties()));
}
Also used : SortOrder(org.eclipse.dataspaceconnector.spi.query.SortOrder) IntStream(java.util.stream.IntStream) BeforeEach(org.junit.jupiter.api.BeforeEach) CosmosTestClient(org.eclipse.dataspaceconnector.azure.testfixtures.CosmosTestClient) TypeManager(org.eclipse.dataspaceconnector.spi.types.TypeManager) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) CosmosDatabase(com.azure.cosmos.CosmosDatabase) PartitionKey(com.azure.cosmos.models.PartitionKey) AfterAll(org.junit.jupiter.api.AfterAll) AssetDocument(org.eclipse.dataspaceconnector.assetindex.azure.model.AssetDocument) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) BeforeAll(org.junit.jupiter.api.BeforeAll) AzureCosmosDbIntegrationTest(org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest) Asset(org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset) CosmosDbApiImpl(org.eclipse.dataspaceconnector.azure.cosmos.CosmosDbApiImpl) RetryPolicy(net.jodah.failsafe.RetryPolicy) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) QuerySpec(org.eclipse.dataspaceconnector.spi.query.QuerySpec) String.format(java.lang.String.format) DataAddress(org.eclipse.dataspaceconnector.spi.types.domain.DataAddress) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) AssetSelectorExpression(org.eclipse.dataspaceconnector.spi.asset.AssetSelectorExpression) CosmosContainer(com.azure.cosmos.CosmosContainer) CosmosDatabaseResponse(com.azure.cosmos.models.CosmosDatabaseResponse) Monitor(org.eclipse.dataspaceconnector.spi.monitor.Monitor) Mockito.mock(org.mockito.Mockito.mock) Asset(org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset) AssetDocument(org.eclipse.dataspaceconnector.assetindex.azure.model.AssetDocument) AzureCosmosDbIntegrationTest(org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest) Test(org.junit.jupiter.api.Test)

Aggregations

DataAddress (org.eclipse.dataspaceconnector.spi.types.domain.DataAddress)20 Test (org.junit.jupiter.api.Test)14 Asset (org.eclipse.dataspaceconnector.spi.types.domain.asset.Asset)6 CosmosContainer (com.azure.cosmos.CosmosContainer)2 CosmosDatabase (com.azure.cosmos.CosmosDatabase)2 CosmosDatabaseResponse (com.azure.cosmos.models.CosmosDatabaseResponse)2 PartitionKey (com.azure.cosmos.models.PartitionKey)2 String.format (java.lang.String.format)2 List (java.util.List)2 UUID (java.util.UUID)2 Collectors (java.util.stream.Collectors)2 IntStream (java.util.stream.IntStream)2 RetryPolicy (net.jodah.failsafe.RetryPolicy)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 Assertions.assertThatThrownBy (org.assertj.core.api.Assertions.assertThatThrownBy)2 AssetDocument (org.eclipse.dataspaceconnector.assetindex.azure.model.AssetDocument)2 CosmosDbApiImpl (org.eclipse.dataspaceconnector.azure.cosmos.CosmosDbApiImpl)2 CosmosTestClient (org.eclipse.dataspaceconnector.azure.testfixtures.CosmosTestClient)2 AzureCosmosDbIntegrationTest (org.eclipse.dataspaceconnector.azure.testfixtures.annotations.AzureCosmosDbIntegrationTest)2 AssetSelectorExpression (org.eclipse.dataspaceconnector.spi.asset.AssetSelectorExpression)2