Search in sources :

Example 1 with ExecutionServiceInput

use of org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput in project so by onap.

the class CDSProcessingHandler method process.

CountDownLatch process(ExecutionServiceInput request, ManagedChannel channel) {
    ActionIdentifiers header = request.getActionIdentifiers();
    log.info("Processing blueprint({}:{}) for action({})", header.getBlueprintVersion(), header.getBlueprintName(), header.getActionName());
    final CountDownLatch finishLatch = new CountDownLatch(1);
    final BluePrintProcessingServiceStub asyncStub = BluePrintProcessingServiceGrpc.newStub(channel);
    final StreamObserver<ExecutionServiceOutput> responseObserver = new StreamObserver<ExecutionServiceOutput>() {

        @Override
        public void onNext(ExecutionServiceOutput output) {
            listener.onMessage(output);
        }

        @Override
        public void onError(Throwable t) {
            listener.onError(t);
            finishLatch.countDown();
        }

        @Override
        public void onCompleted() {
            log.info("Completed blueprint({}:{}) for action({})", header.getBlueprintVersion(), header.getBlueprintName(), header.getBlueprintVersion());
            finishLatch.countDown();
        }
    };
    final StreamObserver<ExecutionServiceInput> requestObserver = asyncStub.process(responseObserver);
    try {
        // Send our message to CDS backend for processing
        requestObserver.onNext(request);
        // Mark the end of requests
        requestObserver.onCompleted();
    } catch (RuntimeException e) {
        requestObserver.onError(e);
    }
    return finishLatch;
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) ExecutionServiceOutput(org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput) CountDownLatch(java.util.concurrent.CountDownLatch) ActionIdentifiers(org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers) BluePrintProcessingServiceStub(org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc.BluePrintProcessingServiceStub) ExecutionServiceInput(org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput)

Example 2 with ExecutionServiceInput

use of org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput in project so by onap.

the class GrpcNettyServer method start.

@PostConstruct
public void start() throws IOException {
    final BluePrintProcessingServiceImplBase blueprintPrcessorImpl = new BluePrintProcessingServiceImplBase() {

        @Override
        public StreamObserver<ExecutionServiceInput> process(StreamObserver<ExecutionServiceOutput> responseObserver) {
            responseObserverRef.set(responseObserver);
            StreamObserver<ExecutionServiceInput> requestObserver = new StreamObserver<ExecutionServiceInput>() {

                @Override
                public void onNext(ExecutionServiceInput message) {
                    detailedMessages.add(message);
                    logger.info("Message received: {}", message);
                    ExecutionServiceOutput executionServiceOutput = ExecutionServiceOutput.newBuilder().setActionIdentifiers(message.getActionIdentifiers()).setStatus(Status.newBuilder().setEventType(EventType.EVENT_COMPONENT_EXECUTED).build()).build();
                    responseObserverRef.get().onNext(executionServiceOutput);
                    logger.info("Message sent: {}", executionServiceOutput);
                }

                @Override
                public void onError(Throwable t) {
                    responseObserverRef.get().onError(t);
                }

                @Override
                public void onCompleted() {
                    allRequestsDelivered.countDown();
                    responseObserverRef.get().onCompleted();
                }
            };
            return requestObserver;
        }
    };
    grpcCleanup.register(ServerBuilder.forPort(Integer.valueOf(port)).directExecutor().addService(blueprintPrcessorImpl).build().start());
}
Also used : StreamObserver(io.grpc.stub.StreamObserver) ExecutionServiceOutput(org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput) BluePrintProcessingServiceImplBase(org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase) ExecutionServiceInput(org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput) PostConstruct(javax.annotation.PostConstruct)

Example 3 with ExecutionServiceInput

use of org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput in project so by onap.

the class AbstractCDSProcessingBBUtils method sendRequestToCDSClientBB.

/**
 * get the executionServiceInput object from execution and send a request to CDS Client and wait for TIMEOUT period
 *
 * @param execution BuildingBlockExecution object
 */
public void sendRequestToCDSClientBB(BuildingBlockExecution execution) {
    logger.trace("Start AbstractCDSProcessingBBUtils.sendRequestToCDSClient for BuildingBlockExecution object.");
    try {
        ExecutionServiceInput executionServiceInput = execution.getVariable(EXEC_INPUT);
        CDSResponse cdsResponse = getCdsResponse(executionServiceInput);
        execution.setVariable(CDS_STATUS, cdsResponse.status);
        if (cdsResponse.payload != null) {
            String payload = JsonFormat.printer().print(cdsResponse.payload);
            execution.setVariable(RESPONSE_PAYLOAD, payload);
        }
    } catch (Exception ex) {
        exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
    }
}
Also used : ExecutionServiceInput(org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) BadResponseException(org.onap.so.client.exception.BadResponseException) PreconditionFailedException(org.onap.so.client.PreconditionFailedException)

Example 4 with ExecutionServiceInput

use of org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput in project so by onap.

the class GenericPnfSWUPDownloadTest method workflow_validInput_expectedOutput.

@Test
public void workflow_validInput_expectedOutput() throws InterruptedException {
    mockCatalogDb();
    mockAai();
    grpcNettyServer.resetList();
    final String msoRequestId = UUID.randomUUID().toString();
    executionVariables.put(ExecutionVariableNames.MSO_REQUEST_ID, msoRequestId);
    final String testBusinessKey = UUID.randomUUID().toString();
    logger.info("Test the process instance: {} with business key: {}", TEST_PROCESSINSTANCE_KEY, testBusinessKey);
    ProcessInstance pi = runtimeService.startProcessInstanceByKey(TEST_PROCESSINSTANCE_KEY, testBusinessKey, executionVariables);
    int waitCount = 10;
    while (!isProcessInstanceEnded() && waitCount >= 0) {
        Thread.sleep(WORKFLOW_WAIT_TIME);
        waitCount--;
    }
    // Layout is to reflect the bpmn visual layout
    assertThat(pi).isStarted().hasPassedInOrder("download_StartEvent", "ServiceTask_1mpt2eq", "ServiceTask_1nl90ao", "ExclusiveGateway_1rj84ne", "ServiceTask_0yavde3", "ExclusiveGateway_1ja7grm", "ServiceTask_1wxo7xz", "ExclusiveGateway_08lusga", "download_EndEvent");
    List<ExecutionServiceInput> detailedMessages = grpcNettyServer.getDetailedMessages();
    assertEquals(3, detailedMessages.size());
    int count = 0;
    try {
        for (ExecutionServiceInput eSI : detailedMessages) {
            for (String action : actionNames) {
                if (action.equals(eSI.getActionIdentifiers().getActionName()) && eSI.getCommonHeader().getRequestId().equals(msoRequestId)) {
                    checkWithActionName(eSI, action, msoRequestId);
                    count++;
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("GenericPnfSWUPDownload request exception", e);
    }
    assertTrue(count == actionNames.length);
}
Also used : ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ExecutionServiceInput(org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput) IOException(java.io.IOException) BaseBPMNTest(org.onap.so.BaseBPMNTest) Test(org.junit.Test)

Example 5 with ExecutionServiceInput

use of org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput in project so by onap.

the class PnfHealthCheckTest method workflow_validInput_expectedOutput.

@Test
public void workflow_validInput_expectedOutput() throws InterruptedException {
    mockCatalogDb();
    mockRequestDb();
    mockAai();
    final String msoRequestId = UUID.randomUUID().toString();
    executionVariables.put(ExecutionVariableNames.MSO_REQUEST_ID, msoRequestId);
    final String testBusinessKey = UUID.randomUUID().toString();
    logger.info("Test the process instance: {} with business key: {}", TEST_PROCESSINSTANCE_KEY, testBusinessKey);
    ProcessInstance pi = runtimeService.startProcessInstanceByKey(TEST_PROCESSINSTANCE_KEY, testBusinessKey, executionVariables);
    int waitCount = 10;
    while (!isProcessInstanceEnded() && waitCount >= 0) {
        Thread.sleep(WORKFLOW_WAIT_TIME);
        waitCount--;
    }
    // Layout is to reflect the bpmn visual layout
    assertThat(pi).isEnded().hasPassedInOrder("pnfHealthCheck_startEvent", "ServiceTask_042uz7m", "ScriptTask_10klpg9", "ServiceTask_0slpaht", "ExclusiveGateway_0x6h0yi", "ScriptTask_1igtc83", "CallActivity_0o1mi8u", "pnfHealthCheck_endEvent");
    List<ExecutionServiceInput> detailedMessages = grpcNettyServer.getDetailedMessages();
    logger.debug("Size of detailedMessage is {}", detailedMessages.size());
    assertTrue(detailedMessages.size() == 1);
    int count = 0;
    try {
        for (ExecutionServiceInput eSI : detailedMessages) {
            if (ACTION_NAME.equals(eSI.getActionIdentifiers().getActionName()) && eSI.getCommonHeader().getRequestId().equals(msoRequestId)) {
                checkWithActionName(eSI, ACTION_NAME);
                count++;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        fail("PNFHealthCheck request exception", e);
    }
    assertTrue(count == 1);
}
Also used : ProcessInstance(org.camunda.bpm.engine.runtime.ProcessInstance) ExecutionServiceInput(org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput) BaseBPMNTest(org.onap.so.BaseBPMNTest) Test(org.junit.Test)

Aggregations

ExecutionServiceInput (org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput)14 Test (org.junit.Test)7 ProcessInstance (org.camunda.bpm.engine.runtime.ProcessInstance)5 BaseBPMNTest (org.onap.so.BaseBPMNTest)5 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)4 IOException (java.io.IOException)4 PreconditionFailedException (org.onap.so.client.PreconditionFailedException)4 BadResponseException (org.onap.so.client.exception.BadResponseException)4 StreamObserver (io.grpc.stub.StreamObserver)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ExecutionServiceOutput (org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput)3 BluePrintProcessingServiceImplBase (org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc.BluePrintProcessingServiceImplBase)2 AbstractCDSPropertiesBean (org.onap.so.client.cds.beans.AbstractCDSPropertiesBean)2 PostConstruct (javax.annotation.PostConstruct)1 Before (org.junit.Before)1 ActionIdentifiers (org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers)1 BluePrintProcessingServiceStub (org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc.BluePrintProcessingServiceStub)1