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;
}
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;
}
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");
}
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");
}
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);
}
Aggregations