Search in sources :

Example 1 with DataRequest

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

the class TransferProcessManagerImpl method sendConsumerRequest.

@WithSpan
private void sendConsumerRequest(TransferProcess process, DataRequest dataRequest) {
    process.transitionRequested();
    // update before sending to accommodate synchronous transports; reliability will be managed by retry and idempotency
    transferProcessStore.update(process);
    observable.invokeForEach(l -> l.requested(process));
    dispatcherRegistry.send(Object.class, dataRequest, process::getId).thenApply(o -> {
        // TODO: what's the point of this state transition?
        transitionToRequestAck(process.getId());
        return o;
    }).whenComplete((o, throwable) -> {
        if (o != null) {
            monitor.info("Object received: " + o);
            TransferProcess transferProcess = transferProcessStore.find(process.getId());
            if (transferProcess == null) {
                monitor.severe(format("TransferProcessManager: no TransferProcess found with id %s", process.getId()));
                return;
            }
            transferProcess.transitionInProgressOrStreaming();
            transferProcessStore.update(transferProcess);
            observable.invokeForEach(l -> l.inProgress(transferProcess));
        }
    });
}
Also used : ProvisionedResource(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionedResource) TypeManager(org.eclipse.dataspaceconnector.spi.types.TypeManager) CommandRunner(org.eclipse.dataspaceconnector.spi.command.CommandRunner) TransferProcess(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess) PROVISIONED(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.PROVISIONED) Function(java.util.function.Function) ProvisionManager(org.eclipse.dataspaceconnector.spi.transfer.provision.ProvisionManager) Telemetry(org.eclipse.dataspaceconnector.spi.telemetry.Telemetry) DataFlowManager(org.eclipse.dataspaceconnector.spi.transfer.flow.DataFlowManager) REQUESTED_ACK(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.REQUESTED_ACK) TransferProcessObservable(org.eclipse.dataspaceconnector.spi.transfer.observe.TransferProcessObservable) IN_PROGRESS(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.IN_PROGRESS) CONSUMER(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess.Type.CONSUMER) WaitStrategy(org.eclipse.dataspaceconnector.spi.retry.WaitStrategy) StatusCheckerRegistry(org.eclipse.dataspaceconnector.spi.types.domain.transfer.StatusCheckerRegistry) ResponseStatus(org.eclipse.dataspaceconnector.spi.response.ResponseStatus) TransferInitiateResult(org.eclipse.dataspaceconnector.spi.transfer.TransferInitiateResult) ResourceManifestGenerator(org.eclipse.dataspaceconnector.spi.transfer.provision.ResourceManifestGenerator) ERROR(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.ERROR) Collections.emptyList(java.util.Collections.emptyList) DataRequest(org.eclipse.dataspaceconnector.spi.types.domain.transfer.DataRequest) TransferProcessCommand(org.eclipse.dataspaceconnector.spi.types.domain.transfer.command.TransferProcessCommand) PROVIDER(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess.Type.PROVIDER) DEPROVISIONED(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.DEPROVISIONED) Vault(org.eclipse.dataspaceconnector.spi.security.Vault) String.format(java.lang.String.format) TransferProcessStore(org.eclipse.dataspaceconnector.spi.transfer.store.TransferProcessStore) DataAddress(org.eclipse.dataspaceconnector.spi.types.domain.DataAddress) Objects(java.util.Objects) List(java.util.List) UUID.randomUUID(java.util.UUID.randomUUID) COMPLETED(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.COMPLETED) TransferProcessManager(org.eclipse.dataspaceconnector.spi.transfer.TransferProcessManager) StateMachine(org.eclipse.dataspaceconnector.common.statemachine.StateMachine) CommandProcessor(org.eclipse.dataspaceconnector.spi.command.CommandProcessor) WithSpan(io.opentelemetry.extension.annotations.WithSpan) StateProcessorImpl(org.eclipse.dataspaceconnector.common.statemachine.StateProcessorImpl) ProvisionResponse(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionResponse) RemoteMessageDispatcherRegistry(org.eclipse.dataspaceconnector.spi.message.RemoteMessageDispatcherRegistry) CommandQueue(org.eclipse.dataspaceconnector.spi.command.CommandQueue) INITIAL(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.INITIAL) ProvisionedDataDestinationResource(org.eclipse.dataspaceconnector.spi.types.domain.transfer.ProvisionedDataDestinationResource) TransferProcessStates(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates) Monitor(org.eclipse.dataspaceconnector.spi.monitor.Monitor) DEPROVISIONING_REQ(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcessStates.DEPROVISIONING_REQ) TransferProcess(org.eclipse.dataspaceconnector.spi.types.domain.transfer.TransferProcess) WithSpan(io.opentelemetry.extension.annotations.WithSpan)

Example 2 with DataRequest

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

the class HttpDataFlowControllerTest method verifyRetryErrorResponse.

@Test
void verifyRetryErrorResponse() {
    Interceptor delegate = chain -> new Response.Builder().request(chain.request()).protocol(HTTP_1_1).code(500).body(ResponseBody.create("", MediaType.get("application/json"))).message("ok").build();
    httpClient = testOkHttpClient().newBuilder().addInterceptor(delegate).build();
    var dataRequest = createDataRequest();
    var contentAddress = DataAddress.Builder.newInstance().type("test").build();
    var policy = Policy.Builder.newInstance().build();
    assertEquals(ERROR_RETRY, flowController.initiateFlow(dataRequest, contentAddress, policy).getFailure().status());
}
Also used : Interceptor(okhttp3.Interceptor) BeforeEach(org.junit.jupiter.api.BeforeEach) Policy(org.eclipse.dataspaceconnector.policy.model.Policy) HTTP_1_1(okhttp3.Protocol.HTTP_1_1) FATAL_ERROR(org.eclipse.dataspaceconnector.spi.response.ResponseStatus.FATAL_ERROR) TypeManager(org.eclipse.dataspaceconnector.spi.types.TypeManager) DataRequest(org.eclipse.dataspaceconnector.spi.types.domain.transfer.DataRequest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UUID(java.util.UUID) DataAddress(org.eclipse.dataspaceconnector.spi.types.domain.DataAddress) Test(org.junit.jupiter.api.Test) OkHttpClient(okhttp3.OkHttpClient) Response(okhttp3.Response) ERROR_RETRY(org.eclipse.dataspaceconnector.spi.response.ResponseStatus.ERROR_RETRY) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TestUtils.testOkHttpClient(org.eclipse.dataspaceconnector.common.testfixtures.TestUtils.testOkHttpClient) MediaType(okhttp3.MediaType) ResponseBody(okhttp3.ResponseBody) Monitor(org.eclipse.dataspaceconnector.spi.monitor.Monitor) Mockito.mock(org.mockito.Mockito.mock) Interceptor(okhttp3.Interceptor) Test(org.junit.jupiter.api.Test)

Example 3 with DataRequest

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

the class TransferProcessApiControllerTest method initiateTransfer.

@Test
void initiateTransfer() {
    var transferReq = transferRequestDto();
    String processId = "processId";
    DataRequest request = dataRequest(transferReq);
    when(transformerRegistry.transform(isA(TransferRequestDto.class), eq(DataRequest.class))).thenReturn(Result.success(request));
    when(service.initiateTransfer(any())).thenReturn(ServiceResult.success(processId));
    String result = controller.initiateTransfer(transferReq).getId();
    var dataRequestCaptor = ArgumentCaptor.forClass(DataRequest.class);
    verify(service).initiateTransfer(dataRequestCaptor.capture());
    DataRequest dataRequest = dataRequestCaptor.getValue();
    assertThat(dataRequest.getAssetId()).isEqualTo(request.getAssetId());
    assertThat(dataRequest.getConnectorAddress()).isEqualTo(request.getConnectorAddress());
    assertThat(dataRequest.getConnectorId()).isEqualTo(request.getConnectorId());
    assertThat(dataRequest.getDataDestination()).isEqualTo(request.getDataDestination());
    assertThat(dataRequest.getDestinationType()).isEqualTo(request.getDataDestination().getType());
    assertThat(dataRequest.getContractId()).isEqualTo(request.getContractId());
    assertThat(dataRequest.getProtocol()).isEqualTo(request.getProtocol());
    assertThat(dataRequest.getProperties()).isEqualTo(request.getProperties());
    assertThat(dataRequest.getTransferType()).isEqualTo(request.getTransferType());
    assertThat(dataRequest.isManagedResources()).isEqualTo(request.isManagedResources());
    assertThat(result).isEqualTo(processId);
}
Also used : TransferRequestDto(org.eclipse.dataspaceconnector.api.datamanagement.transferprocess.model.TransferRequestDto) DataRequest(org.eclipse.dataspaceconnector.spi.types.domain.transfer.DataRequest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 4 with DataRequest

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

the class HttpDataFlowControllerTest method verifyOkResponse.

@Test
void verifyOkResponse() {
    Interceptor delegate = chain -> new Response.Builder().request(chain.request()).protocol(HTTP_1_1).code(200).body(ResponseBody.create("", MediaType.get("application/json"))).message("ok").build();
    httpClient = testOkHttpClient().newBuilder().addInterceptor(delegate).build();
    var dataRequest = createDataRequest();
    var contentAddress = DataAddress.Builder.newInstance().type("test").build();
    var policy = Policy.Builder.newInstance().build();
    assertThat(flowController.initiateFlow(dataRequest, contentAddress, policy).succeeded()).isTrue();
}
Also used : Interceptor(okhttp3.Interceptor) BeforeEach(org.junit.jupiter.api.BeforeEach) Policy(org.eclipse.dataspaceconnector.policy.model.Policy) HTTP_1_1(okhttp3.Protocol.HTTP_1_1) FATAL_ERROR(org.eclipse.dataspaceconnector.spi.response.ResponseStatus.FATAL_ERROR) TypeManager(org.eclipse.dataspaceconnector.spi.types.TypeManager) DataRequest(org.eclipse.dataspaceconnector.spi.types.domain.transfer.DataRequest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UUID(java.util.UUID) DataAddress(org.eclipse.dataspaceconnector.spi.types.domain.DataAddress) Test(org.junit.jupiter.api.Test) OkHttpClient(okhttp3.OkHttpClient) Response(okhttp3.Response) ERROR_RETRY(org.eclipse.dataspaceconnector.spi.response.ResponseStatus.ERROR_RETRY) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TestUtils.testOkHttpClient(org.eclipse.dataspaceconnector.common.testfixtures.TestUtils.testOkHttpClient) MediaType(okhttp3.MediaType) ResponseBody(okhttp3.ResponseBody) Monitor(org.eclipse.dataspaceconnector.spi.monitor.Monitor) Mockito.mock(org.mockito.Mockito.mock) Interceptor(okhttp3.Interceptor) Test(org.junit.jupiter.api.Test)

Example 5 with DataRequest

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

the class HttpDataFlowControllerTest method verifyFatalErrorResponse.

@Test
void verifyFatalErrorResponse() {
    Interceptor delegate = chain -> new Response.Builder().request(chain.request()).protocol(HTTP_1_1).code(400).body(ResponseBody.create("", MediaType.get("application/json"))).message("ok").build();
    httpClient = testOkHttpClient().newBuilder().addInterceptor(delegate).build();
    var dataRequest = createDataRequest();
    var contentAddress = DataAddress.Builder.newInstance().type("test").build();
    var policy = Policy.Builder.newInstance().build();
    assertEquals(FATAL_ERROR, flowController.initiateFlow(dataRequest, contentAddress, policy).getFailure().status());
}
Also used : Interceptor(okhttp3.Interceptor) BeforeEach(org.junit.jupiter.api.BeforeEach) Policy(org.eclipse.dataspaceconnector.policy.model.Policy) HTTP_1_1(okhttp3.Protocol.HTTP_1_1) FATAL_ERROR(org.eclipse.dataspaceconnector.spi.response.ResponseStatus.FATAL_ERROR) TypeManager(org.eclipse.dataspaceconnector.spi.types.TypeManager) DataRequest(org.eclipse.dataspaceconnector.spi.types.domain.transfer.DataRequest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UUID(java.util.UUID) DataAddress(org.eclipse.dataspaceconnector.spi.types.domain.DataAddress) Test(org.junit.jupiter.api.Test) OkHttpClient(okhttp3.OkHttpClient) Response(okhttp3.Response) ERROR_RETRY(org.eclipse.dataspaceconnector.spi.response.ResponseStatus.ERROR_RETRY) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) TestUtils.testOkHttpClient(org.eclipse.dataspaceconnector.common.testfixtures.TestUtils.testOkHttpClient) MediaType(okhttp3.MediaType) ResponseBody(okhttp3.ResponseBody) Monitor(org.eclipse.dataspaceconnector.spi.monitor.Monitor) Mockito.mock(org.mockito.Mockito.mock) Interceptor(okhttp3.Interceptor) Test(org.junit.jupiter.api.Test)

Aggregations

DataRequest (org.eclipse.dataspaceconnector.spi.types.domain.transfer.DataRequest)7 Test (org.junit.jupiter.api.Test)6 Monitor (org.eclipse.dataspaceconnector.spi.monitor.Monitor)5 TypeManager (org.eclipse.dataspaceconnector.spi.types.TypeManager)5 DataAddress (org.eclipse.dataspaceconnector.spi.types.domain.DataAddress)5 UUID (java.util.UUID)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4 Policy (org.eclipse.dataspaceconnector.policy.model.Policy)4 Interceptor (okhttp3.Interceptor)3 MediaType (okhttp3.MediaType)3 OkHttpClient (okhttp3.OkHttpClient)3 HTTP_1_1 (okhttp3.Protocol.HTTP_1_1)3 Response (okhttp3.Response)3 ResponseBody (okhttp3.ResponseBody)3 TestUtils.testOkHttpClient (org.eclipse.dataspaceconnector.common.testfixtures.TestUtils.testOkHttpClient)3 ERROR_RETRY (org.eclipse.dataspaceconnector.spi.response.ResponseStatus.ERROR_RETRY)3 FATAL_ERROR (org.eclipse.dataspaceconnector.spi.response.ResponseStatus.FATAL_ERROR)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 Mockito.mock (org.mockito.Mockito.mock)3 Collections.emptyList (java.util.Collections.emptyList)2