Search in sources :

Example 21 with BuildingBlockExecution

use of org.onap.so.bpmn.common.BuildingBlockExecution in project so by onap.

the class GenericCDSProcessingBBTest method testExecutionObjectCreationForVnf.

@Test
public void testExecutionObjectCreationForVnf() throws Exception {
    // given
    ControllerContext<BuildingBlockExecution> controllerContext = new ControllerContext<>();
    controllerContext.setExecution(buildingBlockExecution);
    controllerContext.setControllerActor("CDS");
    controllerContext.setControllerScope("vnf");
    setScopeAndAction(VNF_SCOPE, DEPLOY_ACTION_FOR_CDS);
    AbstractCDSPropertiesBean cdsBean = prepareCDSBean();
    doReturn(cdsBean).when(generatePayloadForCds).buildCdsPropertiesBean(buildingBlockExecution);
    doNothing().when(cdsDispather).constructExecutionServiceInputObjectBB(buildingBlockExecution);
    doNothing().when(cdsDispather).sendRequestToCDSClientBB(buildingBlockExecution);
    // when
    Boolean isUnderstandable = controllerRunnable.understand(controllerContext);
    Boolean isReady = controllerRunnable.ready(controllerContext);
    controllerRunnable.prepare(controllerContext);
    controllerRunnable.run(controllerContext);
    // verify
    assertEquals(isUnderstandable, true);
    assertEquals(isReady, true);
    AbstractCDSPropertiesBean executionObject = buildingBlockExecution.getVariable(EXECUTION_OBJECT);
    assertNotNull(executionObject);
    assertThat(executionObject).isInstanceOf(AbstractCDSPropertiesBean.class);
    assertEquals(BLUEPRINT_NAME, executionObject.getBlueprintName());
    assertEquals(BLUEPRINT_VERSION, executionObject.getBlueprintVersion());
    assertEquals(TEST_MSO_REQUEST_ID, executionObject.getRequestId());
    assertNotNull(executionObject.getRequestObject());
}
Also used : BuildingBlockExecution(org.onap.so.bpmn.common.BuildingBlockExecution) ControllerContext(org.onap.so.bpmn.infrastructure.decisionpoint.api.ControllerContext) AbstractCDSPropertiesBean(org.onap.so.client.cds.beans.AbstractCDSPropertiesBean) BaseTaskTest(org.onap.so.bpmn.BaseTaskTest) Test(org.junit.Test)

Example 22 with BuildingBlockExecution

use of org.onap.so.bpmn.common.BuildingBlockExecution in project so by onap.

the class CnfHealthCheckTasks method prepareCnfAdaperRequest.

public void prepareCnfAdaperRequest(BuildingBlockExecution execution) {
    GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
    ServiceInstance serviceInstance = gBBInput.getCustomer().getServiceSubscription().getServiceInstances().get(0);
    GenericVnf genericVnf = serviceInstance.getVnfs().get(0);
    List<VfModule> listOfVfModules = genericVnf.getVfModules();
    List<String> listOfHeatStackIds = listOfVfModules.stream().map(x -> x.getHeatStackId()).collect(Collectors.toList());
    LOGGER.debug("listOfHeatStackIds from prepareCnfAdaperRequest: {}", listOfHeatStackIds);
    // Prepare values to pass in execution variable for CNF Adapter async Handling
    String requestId = execution.getVariable("mso-request-id");
    execution.setVariable("messageType", CNF_ADAPTER_MESSAGE_TYPE);
    execution.setVariable("correlator", requestId);
    execution.setVariable("timeout", "PT30M");
    // Replace with environment values
    String callBackUrl = "http://so-bpmn-infra.onap:8081/mso/WorkflowMessage/" + CNF_ADAPTER_MESSAGE_TYPE + "/" + requestId;
    HealthcheckInstanceRequest request = new HealthcheckInstanceRequest();
    try {
        request = createStatusCheckRequest(listOfHeatStackIds, callBackUrl);
    } catch (JsonProcessingException e) {
        exceptionUtil.buildAndThrowWorkflowException(execution, 6822, e);
    }
    LOGGER.debug("request: {}", request);
    String requestPayload = "";
    try {
        requestPayload = mapper.writeValueAsString(request);
    } catch (JsonProcessingException e) {
        LOGGER.error("Error in JSON");
    }
    execution.setVariable("cnfRequestPayload", requestPayload);
    ExecuteBuildingBlock executeBuildingBlock = execution.getVariable(BUILDING_BLOCK);
    BuildingBlock buildingBlock = executeBuildingBlock.getBuildingBlock();
    String action = Optional.ofNullable(buildingBlock.getBpmnAction()).orElseThrow(() -> new NullPointerException("BPMN Action is NULL in the orchestration_flow_reference table "));
    // Replace values with environment values
    String uri = "http://so-cnf-adapter:8090";
    String apiPath = "";
    if (STATUS_CHECK_SCOPE.equals(action)) {
        apiPath = uri + "/api/cnf-adapter/v1/statuscheck/";
    } else if (HEALTH_CHECK_SCOPE.equals(action)) {
        apiPath = uri + "/api/cnf-adapter/v1/healthcheck/";
    }
    LOGGER.debug("apiPath: {}", apiPath);
    execution.setVariable("apiPath", apiPath);
}
Also used : ONAPComponents(org.onap.logging.filter.base.ONAPComponents) HealthcheckInstanceResponse(org.onap.so.client.adapter.cnf.entities.HealthcheckInstanceResponse) StatusCheckInstanceResponse(org.onap.so.client.adapter.cnf.entities.StatusCheckInstanceResponse) HealthcheckInstanceRequest(org.onap.so.client.adapter.cnf.entities.HealthcheckInstanceRequest) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) StatusCheckResponse(org.onap.so.client.adapter.cnf.entities.StatusCheckResponse) ArrayList(java.util.ArrayList) ExceptionBuilder(org.onap.so.client.exception.ExceptionBuilder) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) Logger(org.slf4j.Logger) VfModule(org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule) HealthcheckResponse(org.onap.so.client.adapter.cnf.entities.HealthcheckResponse) BuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Collectors(java.util.stream.Collectors) HealthcheckInstance(org.onap.so.client.adapter.cnf.entities.HealthcheckInstance) List(java.util.List) Component(org.springframework.stereotype.Component) BuildingBlockExecution(org.onap.so.bpmn.common.BuildingBlockExecution) Optional(java.util.Optional) GenericVnf(org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf) GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) GenericVnf(org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) GeneralBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock) BuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.BuildingBlock) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) VfModule(org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) HealthcheckInstanceRequest(org.onap.so.client.adapter.cnf.entities.HealthcheckInstanceRequest) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 23 with BuildingBlockExecution

use of org.onap.so.bpmn.common.BuildingBlockExecution in project so by onap.

the class HomingListenerTest method runWithHoming.

@Test
public void runWithHoming() {
    // given
    DelegateExecution execution = new DelegateExecutionFake();
    execution.setVariable("homing", true);
    execution.setVariable(CALLED_HOMING, false);
    BuildingBlockExecution buildingBlockExecution = new DelegateExecutionImpl(execution);
    ExecuteBuildingBlock executeBuildingBlock = new ExecuteBuildingBlock();
    // when
    new HomingListener().run(null, executeBuildingBlock, buildingBlockExecution);
    // then
    assertThat(executeBuildingBlock.isHoming()).isTrue();
    assertThat((boolean) buildingBlockExecution.getVariable(CALLED_HOMING)).isTrue();
}
Also used : BuildingBlockExecution(org.onap.so.bpmn.common.BuildingBlockExecution) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) DelegateExecutionImpl(org.onap.so.bpmn.common.DelegateExecutionImpl) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) DelegateExecutionFake(org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake) Test(org.junit.Test)

Example 24 with BuildingBlockExecution

use of org.onap.so.bpmn.common.BuildingBlockExecution in project so by onap.

the class OrchestrationStatusValidatorUnitTest method skipValidationTest.

@Test
public void skipValidationTest() {
    BuildingBlockDetail bbDetail = new BuildingBlockDetail();
    bbDetail.setBuildingBlockName("customBB");
    bbDetail.setResourceType(ResourceType.NO_VALIDATE);
    bbDetail.setTargetAction(OrchestrationAction.CUSTOM);
    when(catalogDbClient.getBuildingBlockDetail("customBB")).thenReturn(bbDetail);
    BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake());
    execution.setVariable("flowToBeCalled", "customBB");
    execution.setVariable("aLaCarte", false);
    validator.validateOrchestrationStatus(execution);
    assertThat(execution.getVariable("orchestrationStatusValidationResult"), equalTo(OrchestrationStatusValidationDirective.VALIDATION_SKIPPED));
}
Also used : BuildingBlockDetail(org.onap.so.db.catalog.beans.BuildingBlockDetail) BuildingBlockExecution(org.onap.so.bpmn.common.BuildingBlockExecution) DelegateExecutionImpl(org.onap.so.bpmn.common.DelegateExecutionImpl) DelegateExecutionFake(org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake) Test(org.junit.Test)

Example 25 with BuildingBlockExecution

use of org.onap.so.bpmn.common.BuildingBlockExecution in project so by onap.

the class MultiStageSkipListenerTest method testTrigger.

@Test
public void testTrigger() {
    BuildingBlockExecution execution = new DelegateExecutionImpl(new DelegateExecutionFake());
    execution.setVariable(BBConstants.G_ALACARTE, true);
    assertTrue("should be triggered", multiStageSkipListener.shouldRunFor("AssignVfModuleBB", true, execution));
    execution.setVariable(BBConstants.G_ALACARTE, false);
    assertFalse("should not be triggered", multiStageSkipListener.shouldRunFor("AssignVfModuleBB", true, execution));
    execution.setVariable(BBConstants.G_ALACARTE, true);
    assertFalse("should not be triggered", multiStageSkipListener.shouldRunFor("AssignVfModuleBB2", true, execution));
    execution.setVariable("multiStageDesign", true);
    assertTrue("should be triggered", multiStageSkipListener.shouldRunFor(execution));
    execution.setVariable("multiStageDesign", false);
    assertFalse("should not be triggered", multiStageSkipListener.shouldRunFor(execution));
    execution.setVariable("multiStageDesign", null);
    assertFalse("should not be triggered", multiStageSkipListener.shouldRunFor(execution));
}
Also used : BuildingBlockExecution(org.onap.so.bpmn.common.BuildingBlockExecution) DelegateExecutionImpl(org.onap.so.bpmn.common.DelegateExecutionImpl) DelegateExecutionFake(org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake) Test(org.junit.Test)

Aggregations

BuildingBlockExecution (org.onap.so.bpmn.common.BuildingBlockExecution)39 Test (org.junit.Test)27 HashMap (java.util.HashMap)10 DelegateExecutionImpl (org.onap.so.bpmn.common.DelegateExecutionImpl)10 DelegateExecutionFake (org.camunda.bpm.extension.mockito.delegate.DelegateExecutionFake)7 ExecuteBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock)6 ArrayList (java.util.ArrayList)5 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)5 Resource (org.onap.so.bpmn.infrastructure.workflow.tasks.Resource)4 GeneralBuildingBlock (org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock)4 ModelInfo (org.onap.so.serviceinstancebeans.ModelInfo)4 RequestDetails (org.onap.so.serviceinstancebeans.RequestDetails)4 ServiceInstancesRequest (org.onap.so.serviceinstancebeans.ServiceInstancesRequest)4 List (java.util.List)3 Optional (java.util.Optional)3 Collectors (java.util.stream.Collectors)3 DelegateExecution (org.camunda.bpm.engine.delegate.DelegateExecution)3 AbstractCDSPropertiesBean (org.onap.so.client.cds.beans.AbstractCDSPropertiesBean)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3