use of org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionResponse in project DataSpaceConnector by eclipse-dataspaceconnector.
the class ObjectStorageProvisioner method provision.
@Override
public CompletableFuture<ProvisionResponse> provision(ObjectStorageResourceDefinition resourceDefinition) {
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 -> {
var resource = ObjectContainerProvisionedResource.Builder.newInstance().id(containerName).accountName(accountName).containerName(containerName).resourceDefinitionId(resourceDefinition.getId()).transferProcessId(resourceDefinition.getTransferProcessId()).build();
var secretToken = new AzureSasToken("?" + writeOnlySas, expiryTime.toInstant().toEpochMilli());
return ProvisionResponse.Builder.newInstance().resource(resource).secretToken(secretToken).build();
});
}
use of org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionResponse 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.types.domain.transfer.ProvisionResponse 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.types.domain.transfer.ProvisionResponse in project DataSpaceConnector by eclipse-dataspaceconnector.
the class HttpProviderProvisioner method provision.
@Override
public CompletableFuture<StatusResult<ProvisionResponse>> provision(HttpProviderResourceDefinition resourceDefinition, Policy policy) {
var scopedPolicy = policyEngine.filter(policy, policyScope);
Request request;
try {
request = createRequest(PROVISION, resourceDefinition.getTransferProcessId(), resourceDefinition.getAssetId(), scopedPolicy);
} catch (JsonProcessingException e) {
monitor.severe("Error serializing provision request for provisioner: " + name, e);
return completedFuture(StatusResult.failure(ResponseStatus.FATAL_ERROR, "Fatal error serializing request: " + e.getMessage()));
}
try (var response = httpClient.newCall(request).execute()) {
if (response.isSuccessful()) {
// in-process
return completedFuture(StatusResult.success(new ProvisionResponse()));
} else if (response.code() >= 500 && response.code() <= 504) {
// retry
return completedFuture(StatusResult.failure(ResponseStatus.ERROR_RETRY, "Received error code: " + response.code()));
} else {
// fatal error
return completedFuture(StatusResult.failure(ResponseStatus.FATAL_ERROR, "Received fatal error code: " + response.code()));
}
} catch (IOException e) {
monitor.severe("Error invoking provisioner: " + name, e);
return completedFuture(StatusResult.failure(ResponseStatus.ERROR_RETRY, "Received error: " + e.getMessage()));
}
}
use of org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionResponse 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);
});
}
Aggregations