use of org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance in project so by onap.
the class OofHomingV2 method callOof.
/**
* Generates the request payload then sends to Oof to perform homing and licensing for the provided demands
*
* @param execution
*/
public void callOof(BuildingBlockExecution execution) {
logger.trace("Started Oof Homing Call Oof");
try {
GeneralBuildingBlock bb = execution.getGeneralBuildingBlock();
RequestContext requestContext = bb.getRequestContext();
String requestId = requestContext.getMsoRequestId();
ServiceInstance serviceInstance = bb.getCustomer().getServiceSubscription().getServiceInstances().get(0);
Customer customer = bb.getCustomer();
String timeout = execution.getVariable("timeout");
if (isBlank(timeout)) {
timeout = env.getProperty("oof.timeout", "PT30M");
}
OofRequest oofRequest = new OofRequest();
RequestInfo requestInfo = buildRequestInfo(requestId, timeout);
oofRequest.setRequestInformation(requestInfo);
ServiceInfo serviceInfo = buildServiceInfo(serviceInstance);
oofRequest.setServiceInformation(serviceInfo);
PlacementInfo placementInfo = buildPlacementInfo(customer);
placementInfo = buildPlacementDemands(serviceInstance, placementInfo);
oofRequest.setPlacementInformation(placementInfo);
LicenseInfo licenseInfo = buildLicenseInfo(serviceInstance);
oofRequest.setLicenseInformation(licenseInfo);
if (!placementInfo.getPlacementDemands().isEmpty() || !licenseInfo.getLicenseDemands().isEmpty()) {
oofClient.postDemands(oofRequest);
} else {
logger.debug(SERVICE_MISSING_DATA + " resources eligible for homing or licensing");
throw new BpmnError(UNPROCESSABLE, SERVICE_MISSING_DATA + " resources eligible for homing or licensing");
}
// Variables for ReceiveWorkflowMessage subflow
execution.setVariable("asyncCorrelator", requestId);
execution.setVariable("asyncMessageType", "OofResponse");
execution.setVariable("asyncTimeout", timeout);
logger.trace("Completed Oof Homing Call Oof");
} catch (BpmnError e) {
logger.debug(ERROR_WHILE_PREPARING_OOF_REQUEST + e.getStackTrace());
exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(e.getErrorCode()), e.getMessage());
} catch (BadResponseException e) {
logger.debug(ERROR_WHILE_PREPARING_OOF_REQUEST + e.getStackTrace());
exceptionUtil.buildAndThrowWorkflowException(execution, 400, e.getMessage());
} catch (Exception e) {
logger.debug(ERROR_WHILE_PREPARING_OOF_REQUEST + e.getStackTrace());
exceptionUtil.buildAndThrowWorkflowException(execution, INTERNAL, "Internal Error - occurred while " + "preparing oof request: " + e + " Stack:" + ExceptionUtils.getFullStackTrace(e));
}
}
use of org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance in project so by onap.
the class OofHomingV2 method processPlacementSolution.
/**
* Processes a placement solution list then correlates and sets each placement solution to its corresponding
* resource
*/
private void processPlacementSolution(ServiceInstance serviceInstance, JSONArray placements, int i) {
List<VpnBondingLink> links = serviceInstance.getVpnBondingLinks();
List<AllottedResource> allottes = serviceInstance.getAllottedResources();
List<GenericVnf> vnfs = serviceInstance.getVnfs();
logger.debug("Processing placement solution " + i + 1);
for (int p = 0; p < placements.length(); p++) {
JSONObject placement = placements.getJSONObject(p);
SolutionInfo solutionInfo = new SolutionInfo();
solutionInfo.setSolutionId(i + 1);
search: {
for (VpnBondingLink vbl : links) {
List<ServiceProxy> proxies = vbl.getServiceProxies();
for (ServiceProxy sp : proxies) {
if (placement.getString(SERVICE_RESOURCE_ID).equals(sp.getId())) {
if (i > 0) {
if (p % 2 == 0) {
VpnBondingLink vblNew = (VpnBondingLink) SerializationUtils.clone(vbl);
vblNew.setVpnBondingLinkId(UUID.randomUUID().toString());
links.add(vblNew);
}
links.get(links.size() - 1).getServiceProxy(sp.getId()).setServiceInstance(setSolution(solutionInfo, placement));
} else {
sp.setServiceInstance(setSolution(solutionInfo, placement));
}
break search;
}
}
}
for (AllottedResource ar : allottes) {
if (placement.getString(SERVICE_RESOURCE_ID).equals(ar.getId())) {
ar.setParentServiceInstance(setSolution(solutionInfo, placement));
break search;
}
}
for (GenericVnf vnf : vnfs) {
if (placement.getString(SERVICE_RESOURCE_ID).equals(vnf.getVnfId())) {
ServiceInstance si = setSolution(solutionInfo, placement);
serviceInstance.setSolutionInfo(si.getSolutionInfo());
serviceInstance.getVnfs().add(si.getVnfs().get(0));
break search;
}
}
}
}
}
use of org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance 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.ServiceInstance in project so by onap.
the class SniroHomingV2 method processSolution.
/**
* Validates, processes, and sets the homing and licensing solutions that are returned by sniro manager
*
* @param execution
* @param asyncResponse
*/
public void processSolution(BuildingBlockExecution execution, String asyncResponse) {
logger.trace("Started Sniro Homing Process Solution");
try {
// TODO improve handling multiple solutions but is dependent on sniro enhancing api + work with sniro
validateSolution(asyncResponse);
ServiceInstance serviceInstance = execution.getGeneralBuildingBlock().getCustomer().getServiceSubscription().getServiceInstances().get(0);
logger.debug("Processing sniro manager asyncronous response");
JSONObject response = new JSONObject(asyncResponse);
if (response.has(SOLUTIONS)) {
JSONObject allSolutions = response.getJSONObject(SOLUTIONS);
if (allSolutions.has("placementSolutions")) {
JSONArray placementSolutions = allSolutions.getJSONArray("placementSolutions");
for (int i = 0; i < placementSolutions.length(); i++) {
JSONArray placements = placementSolutions.getJSONArray(i);
processPlacementSolution(serviceInstance, placements, i);
}
}
if (allSolutions.has("licenseSolutions")) {
JSONArray licenseSolutions = allSolutions.getJSONArray("licenseSolutions");
if (licenseSolutions.length() > 0) {
processLicenseSolution(serviceInstance, licenseSolutions);
}
}
} else {
throw new BpmnError(UNPROCESSABLE, "Sniro Managers response does not contain: " + SOLUTIONS);
}
execution.setVariable("generalBuildingBlock", execution.getGeneralBuildingBlock());
logger.trace("Completed Sniro Homing Process Solution");
} catch (BpmnError e) {
logger.error(EXCEPTION_OCCURRED, e);
exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(e.getErrorCode()), e.getMessage(), ONAPComponents.SNIRO);
} catch (BadResponseException e) {
logger.error(EXCEPTION_OCCURRED, e);
exceptionUtil.buildAndThrowWorkflowException(execution, 400, e.getMessage(), ONAPComponents.SNIRO);
} catch (Exception e) {
logger.error(EXCEPTION_OCCURRED, e);
exceptionUtil.buildAndThrowWorkflowException(execution, INTERNAL, "Internal Error - occurred while processing sniro asynchronous response: " + e.getMessage(), ONAPComponents.SO);
}
}
use of org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance in project so by onap.
the class BBInputSetup method getGBBALaCarteService.
protected GeneralBuildingBlock getGBBALaCarteService(ExecuteBuildingBlock executeBB, RequestDetails requestDetails, Map<ResourceKey, String> lookupKeyMap, String requestAction, String resourceId) throws Exception {
Customer customer = getCustomerAndServiceSubscription(requestDetails, resourceId);
if (customer != null) {
Project project = null;
OwningEntity owningEntity = null;
if (requestDetails.getProject() != null)
project = mapperLayer.mapRequestProject(requestDetails.getProject());
if (requestDetails.getOwningEntity() != null)
owningEntity = mapperLayer.mapRequestOwningEntity(requestDetails.getOwningEntity());
String modelVersionId = requestDetails.getModelInfo().getModelVersionId();
if (ModelType.vnf == requestDetails.getModelInfo().getModelType()) {
for (RelatedInstanceList relatedInstanceList : requestDetails.getRelatedInstanceList()) {
if (ModelType.service == relatedInstanceList.getRelatedInstance().getModelInfo().getModelType()) {
modelVersionId = relatedInstanceList.getRelatedInstance().getModelInfo().getModelVersionId();
break;
}
}
}
Service service = bbInputSetupUtils.getCatalogServiceByModelUUID(modelVersionId);
if (service == null) {
service = bbInputSetupUtils.getCatalogServiceByModelVersionAndModelInvariantUUID(requestDetails.getModelInfo().getModelVersion(), requestDetails.getModelInfo().getModelInvariantId());
if (service == null) {
throw new Exception("Could not find service for model version Id: " + requestDetails.getModelInfo().getModelVersionId() + " and for model invariant Id: " + requestDetails.getModelInfo().getModelInvariantId());
}
}
ServiceInstance serviceInstance = this.getALaCarteServiceInstance(service, requestDetails, customer, project, owningEntity, lookupKeyMap, resourceId, Boolean.TRUE.equals(executeBB.isaLaCarte()), executeBB.getBuildingBlock().getBpmnFlowName());
BBInputSetupParameter parameter = new BBInputSetupParameter.Builder().setRequestDetails(requestDetails).setServiceInstance(serviceInstance).setExecuteBB(executeBB).setRequestAction(requestAction).setCustomer(customer).build();
return this.populateGBBWithSIAndAdditionalInfo(parameter);
} else {
throw new Exception("Could not find customer");
}
}
Aggregations