use of org.eclipse.dataspaceconnector.spi.response.StatusResult in project DataSpaceConnector by eclipse-dataspaceconnector.
the class ProvisionManagerImplTest method provision_should_provision_all_the_transfer_process_definitions.
@Test
void provision_should_provision_all_the_transfer_process_definitions() {
when(provisioner.canProvision(isA(TestResourceDefinition.class))).thenReturn(true);
var provisionResult = StatusResult.success(ProvisionResponse.Builder.newInstance().resource(new TestProvisionedDataDestinationResource("test-resource", "1")).build());
when(provisioner.provision(isA(TestResourceDefinition.class), isA(Policy.class))).thenReturn(completedFuture(provisionResult));
var result = provisionManager.provision(List.of(new TestResourceDefinition()), policy);
assertThat(result).succeedsWithin(1, SECONDS).extracting(responses -> responses.get(0)).extracting(StatusResult::getContent).extracting(ProvisionResponse::getResource).extracting(ProvisionedDataDestinationResource.class::cast).extracting(ProvisionedDataDestinationResource::getResourceName).isEqualTo("test-resource");
}
use of org.eclipse.dataspaceconnector.spi.response.StatusResult in project DataSpaceConnector by eclipse-dataspaceconnector.
the class TransferProcessManagerImplTest method provisioning_shouldContinueOnRetryProvisionError.
@Test
void provisioning_shouldContinueOnRetryProvisionError() throws InterruptedException {
var process = createTransferProcess(PROVISIONING).toBuilder().resourceManifest(ResourceManifest.Builder.newInstance().definitions(List.of(new TestResourceDefinition())).build()).build();
var provisionResult = StatusResult.<ProvisionResponse>failure(ResponseStatus.ERROR_RETRY, "test error");
when(policyArchive.findPolicyForContract(anyString())).thenReturn(Policy.Builder.newInstance().build());
when(provisionManager.provision(any(), isA(Policy.class))).thenReturn(completedFuture(List.of(provisionResult)));
when(transferProcessStore.nextForState(eq(PROVISIONING.code()), anyInt())).thenReturn(List.of(process)).thenReturn(emptyList());
when(transferProcessStore.find(process.getId())).thenReturn(process);
var latch = countDownOnUpdateLatch();
manager.start();
assertThat(latch.await(TIMEOUT, TimeUnit.SECONDS)).isTrue();
verify(policyArchive, atLeastOnce()).findPolicyForContract(anyString());
verify(transferProcessStore).update(argThat(p -> p.getState() == PROVISIONING.code()));
}
use of org.eclipse.dataspaceconnector.spi.response.StatusResult in project DataSpaceConnector by eclipse-dataspaceconnector.
the class ObjectStorageProvisioner method provision.
@Override
public CompletableFuture<StatusResult<ProvisionResponse>> provision(ObjectStorageResourceDefinition resourceDefinition, Policy policy) {
String containerName = resourceDefinition.getContainerName();
String accountName = resourceDefinition.getAccountName();
monitor.info("Azure Storage Container request submitted: " + containerName);
OffsetDateTime expiryTime = OffsetDateTime.now().plusHours(1);
return with(retryPolicy).getAsync(() -> blobStoreApi.exists(accountName, containerName)).thenCompose(exists -> {
if (exists) {
return reusingExistingContainer(containerName);
} else {
return createContainer(containerName, accountName);
}
}).thenCompose(empty -> createContainerSasToken(containerName, accountName, expiryTime)).thenApply(writeOnlySas -> {
// Ensure resource name is unique to avoid key collisions in local and remote vaults
String resourceName = resourceDefinition.getId() + "-container";
var resource = ObjectContainerProvisionedResource.Builder.newInstance().id(containerName).accountName(accountName).containerName(containerName).resourceDefinitionId(resourceDefinition.getId()).transferProcessId(resourceDefinition.getTransferProcessId()).resourceName(resourceName).hasToken(true).build();
var secretToken = new AzureSasToken("?" + writeOnlySas, expiryTime.toInstant().toEpochMilli());
var response = ProvisionResponse.Builder.newInstance().resource(resource).secretToken(secretToken).build();
return StatusResult.success(response);
});
}
use of org.eclipse.dataspaceconnector.spi.response.StatusResult in project DataSpaceConnector by eclipse-dataspaceconnector.
the class AzureDataFactoryTransferManager method transfer.
/**
* Transfers data from source to destination.
*
* @param request the data flow request.
* @return a {@link CompletableFuture} that completes when the data transfer completes.
*/
public CompletableFuture<StatusResult<Void>> transfer(DataFlowRequest request) {
PipelineResource pipeline = pipelineFactory.createPipeline(request);
// Destination
var dataAddress = request.getDestinationDataAddress();
var secret = keyVaultClient.getSecret(dataAddress.getKeyName());
var token = typeManager.readValue(secret.getValue(), AzureSasToken.class);
var accountName = dataAddress.getProperty(AzureBlobStoreSchema.ACCOUNT_NAME);
var containerName = dataAddress.getProperty(AzureBlobStoreSchema.CONTAINER_NAME);
var runId = client.runPipeline(pipeline).runId();
monitor.info("Created ADF pipeline for " + request.getProcessId() + ". Run id is " + runId);
return awaitRunCompletion(runId).thenApply(result -> {
if (result.succeeded()) {
return complete(accountName, containerName, token.getSas());
}
return result;
}).exceptionally(throwable -> {
var error = "Unhandled exception raised when transferring data";
monitor.severe(error, throwable);
return StatusResult.failure(ERROR_RETRY, error + ":" + throwable.getMessage());
});
}
use of org.eclipse.dataspaceconnector.spi.response.StatusResult in project DataSpaceConnector by eclipse-dataspaceconnector.
the class TransferProcessManagerImplTest method deprovisioning_shouldTransitionToErrorOnFatalDeprovisionError.
@Test
void deprovisioning_shouldTransitionToErrorOnFatalDeprovisionError() throws InterruptedException {
var manifest = ResourceManifest.Builder.newInstance().definitions(List.of(new TestResourceDefinition())).build();
var resourceSet = ProvisionedResourceSet.Builder.newInstance().resources(List.of(new TestProvisionedDataDestinationResource("test", PROVISIONED_RESOURCE_ID))).build();
var process = createTransferProcess(DEPROVISIONING).toBuilder().resourceManifest(manifest).provisionedResourceSet(resourceSet).build();
var deprovisionResult = StatusResult.<DeprovisionedResource>failure(ResponseStatus.FATAL_ERROR, "test error");
when(policyArchive.findPolicyForContract(anyString())).thenReturn(Policy.Builder.newInstance().build());
when(provisionManager.deprovision(any(), isA(Policy.class))).thenReturn(completedFuture(List.of(deprovisionResult)));
when(transferProcessStore.nextForState(eq(DEPROVISIONING.code()), anyInt())).thenReturn(List.of(process)).thenReturn(emptyList());
when(transferProcessStore.find(process.getId())).thenReturn(process);
var latch = countDownOnUpdateLatch();
manager.start();
assertThat(latch.await(TIMEOUT, TimeUnit.SECONDS)).isTrue();
verify(policyArchive, atLeastOnce()).findPolicyForContract(anyString());
verify(transferProcessStore).update(argThat(p -> p.getState() == ERROR.code()));
}
Aggregations