Search in sources :

Example 16 with Pnf

use of org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf in project so by onap.

the class OofHomingV2 method setSolution.

/**
 * Creates and sets necessary pojos with placement solution data for a given demand
 */
private ServiceInstance setSolution(SolutionInfo solutionInfo, JSONObject placement) {
    logger.debug("Mapping placement solution");
    String invalidMessage = "Oof Response contains invalid: ";
    JSONObject solution = placement.getJSONObject("solution");
    String identifierType = solution.getString(IDENTIFIER_TYPE);
    List<String> identifiersList = jsonUtils.StringArrayToList(solution.getJSONArray("identifiers").toString());
    String identifierValue = identifiersList.get(0);
    JSONArray assignments = placement.getJSONArray("assignmentInfo");
    Map<String, String> assignmentsMap = jsonUtils.entryArrayToMap(assignments.toString(), "key", "value");
    solutionInfo.setRehome(Boolean.parseBoolean(assignmentsMap.get("isRehome")));
    String type = identifierType;
    ServiceInstance si = new ServiceInstance();
    CloudRegion cloud = setCloud(assignmentsMap);
    if (type.equals("serviceInstanceId")) {
        if (identifierType.equals(CandidateType.SERVICE_INSTANCE_ID.toString())) {
            solutionInfo.setHomed(true);
            si.setServiceInstanceId(identifierValue);
            si.setOrchestrationStatus(OrchestrationStatus.CREATED);
            cloud.setLcpCloudRegionId(assignmentsMap.get("cloudRegionId"));
            if (assignmentsMap.containsKey("vnfHostName")) {
                logger.debug("Resources has been homed to a vnf");
                GenericVnf vnf = setVnf(assignmentsMap);
                vnf.setCloudRegion(cloud);
                si.getVnfs().add(vnf);
            } else if (assignmentsMap.containsKey("primaryPnfName")) {
                logger.debug("Resources has been homed to a pnf");
                Pnf priPnf = setPnf(assignmentsMap, "primary");
                priPnf.setCloudRegion(cloud);
                si.getPnfs().add(priPnf);
                if (assignmentsMap.containsKey("secondaryPnfName")) {
                    Pnf secPnf = setPnf(assignmentsMap, "secondary");
                    secPnf.setCloudRegion(cloud);
                    si.getPnfs().add(secPnf);
                }
            }
        } else {
            logger.debug(invalidMessage + IDENTIFIER_TYPE);
            throw new BpmnError(UNPROCESSABLE, invalidMessage + IDENTIFIER_TYPE);
        }
    } else if (type.equals("cloudRegionId")) {
        if (identifierType.equals(CandidateType.CLOUD_REGION_ID.toString())) {
            logger.debug("Resources has been homed to a cloud region");
            cloud.setLcpCloudRegionId(identifierValue);
            solutionInfo.setHomed(false);
            solutionInfo.setTargetedCloudRegion(cloud);
            si.setOrchestrationStatus(OrchestrationStatus.PRECREATED);
        } else {
            logger.debug(invalidMessage + IDENTIFIER_TYPE);
            throw new BpmnError(UNPROCESSABLE, invalidMessage + IDENTIFIER_TYPE);
        }
    }
    si.setSolutionInfo(solutionInfo);
    return si;
}
Also used : CloudRegion(org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion) JSONObject(org.json.JSONObject) GenericVnf(org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf) JSONArray(org.json.JSONArray) ServiceInstance(org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance) ModelInfoServiceInstance(org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoServiceInstance) Pnf(org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf) BpmnError(org.camunda.bpm.engine.delegate.BpmnError)

Example 17 with Pnf

use of org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf in project so by onap.

the class OofHomingV2 method setPnf.

/**
 * Sets the pnf data to a pnf object
 */
private Pnf setPnf(Map<String, String> assignmentsMap, String role) {
    Pnf pnf = new Pnf();
    pnf.setRole(role);
    pnf.setOrchestrationStatus(OrchestrationStatus.CREATED);
    pnf.setPnfName(assignmentsMap.get(role + "PnfName"));
    return pnf;
}
Also used : Pnf(org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf)

Example 18 with Pnf

use of org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf in project so by onap.

the class RegisterForPnfReadyEventTest method pnfEventNotificationTimeoutNotSet_WorkflowExIsThrown.

@Test
public void pnfEventNotificationTimeoutNotSet_WorkflowExIsThrown() throws BBObjectNotFoundException {
    // given
    testedObject = new RegisterForPnfReadyEvent(dmaapClientTest, extractPojosForBBMock, exceptionBuilderMock, null);
    when(extractPojosForBBMock.extractByKey(buildingBlockExecution, ResourceKey.PNF)).thenReturn(new Pnf());
    // when
    testedObject.execute(delegateExecution);
    // then
    verify(exceptionBuilderMock).buildAndThrowWorkflowException(delegateExecution, 7000, "pnfEntryNotificationTimeout value not defined");
}
Also used : Pnf(org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf) Test(org.junit.Test)

Example 19 with Pnf

use of org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf in project so by onap.

the class RegisterForPnfReadyEventTest method pnfNameIsNull_WorkflowExIsThrown.

@Test
public void pnfNameIsNull_WorkflowExIsThrown() throws BBObjectNotFoundException {
    // given
    testedObject = new RegisterForPnfReadyEvent(dmaapClientTest, extractPojosForBBMock, exceptionBuilderMock, PNF_ENTRY_NOTIFICATION_TIMEOUT);
    when(extractPojosForBBMock.extractByKey(buildingBlockExecution, ResourceKey.PNF)).thenReturn(new Pnf());
    // when
    testedObject.execute(delegateExecution);
    // then
    verify(exceptionBuilderMock).buildAndThrowWorkflowException(delegateExecution, 7000, "pnf name is not set");
}
Also used : Pnf(org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf) Test(org.junit.Test)

Example 20 with Pnf

use of org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf in project so by onap.

the class RegisterForPnfReadyEventTest method shouldRegisterForDmaapClient.

@Test
public void shouldRegisterForDmaapClient() throws BBObjectNotFoundException {
    // given
    testedObject = new RegisterForPnfReadyEvent(dmaapClientTest, extractPojosForBBMock, exceptionBuilderMock, PNF_ENTRY_NOTIFICATION_TIMEOUT);
    Pnf pnf = new Pnf();
    pnf.setPnfName(PNF_NAME);
    when(extractPojosForBBMock.extractByKey(buildingBlockExecution, ResourceKey.PNF)).thenReturn(pnf);
    // when
    testedObject.execute(delegateExecution);
    // then
    verify(delegateExecution).setVariable(ExecutionVariableNames.PNF_CORRELATION_ID, PNF_NAME);
    verify(delegateExecution).setVariable(ExecutionVariableNames.TIMEOUT_FOR_NOTIFICATION, PNF_ENTRY_NOTIFICATION_TIMEOUT);
    checkIfInformConsumerThreadIsRunProperly(dmaapClientTest);
}
Also used : Pnf(org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf) Test(org.junit.Test)

Aggregations

Pnf (org.onap.so.bpmn.servicedecomposition.bbobjects.Pnf)42 Test (org.junit.Test)22 ModelInfoPnf (org.onap.so.bpmn.servicedecomposition.modelinfo.ModelInfoPnf)11 ServiceInstance (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance)8 AAIResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri)5 GenericVnf (org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf)5 CloudRegion (org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion)4 ServiceProxy (org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceProxy)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 AAICommonObjectMapperProvider (org.onap.aaiclient.client.aai.AAICommonObjectMapperProvider)3 AAIResultWrapper (org.onap.aaiclient.client.aai.entities.AAIResultWrapper)3 BuildingBlockExecution (org.onap.so.bpmn.common.BuildingBlockExecution)3 OrchestrationStatus (org.onap.so.db.catalog.beans.OrchestrationStatus)3 SerializationFeature (com.fasterxml.jackson.databind.SerializationFeature)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Objects (java.util.Objects)2