use of org.onap.so.serviceinstancebeans.ServiceInstancesRequest in project so by onap.
the class InstanceIdMapValidation method validate.
@Override
public ValidationInformation validate(ValidationInformation info) throws ValidationException {
Map<String, String> instanceIdMap = info.getInstanceIdMap();
ServiceInstancesRequest sir = info.getSir();
if (instanceIdMap != null) {
if (instanceIdMap.get(Service_InstanceId) != null) {
if (!UUIDChecker.isValidUUID(instanceIdMap.get(Service_InstanceId))) {
throw new ValidationException(Service_InstanceId);
}
sir.setServiceInstanceId(instanceIdMap.get(Service_InstanceId));
}
if (instanceIdMap.get(Vnf_InstanceId) != null) {
if (!UUIDChecker.isValidUUID(instanceIdMap.get(Vnf_InstanceId))) {
throw new ValidationException(Vnf_InstanceId);
}
sir.setVnfInstanceId(instanceIdMap.get(Vnf_InstanceId));
}
if (instanceIdMap.get(vfModule_InstanceId) != null) {
if (!UUIDChecker.isValidUUID(instanceIdMap.get(vfModule_InstanceId))) {
throw new ValidationException(vfModule_InstanceId);
}
sir.setVfModuleInstanceId(instanceIdMap.get(vfModule_InstanceId));
}
if (instanceIdMap.get(volume_Group_InstanceId) != null) {
if (!UUIDChecker.isValidUUID(instanceIdMap.get(volume_Group_InstanceId))) {
throw new ValidationException(volume_Group_InstanceId);
}
sir.setVolumeGroupInstanceId(instanceIdMap.get(volume_Group_InstanceId));
}
if (instanceIdMap.get(Network_Instance_Id) != null) {
if (!UUIDChecker.isValidUUID(instanceIdMap.get(Network_Instance_Id))) {
throw new ValidationException(Network_Instance_Id);
}
sir.setNetworkInstanceId(instanceIdMap.get(Network_Instance_Id));
}
if (instanceIdMap.get(Configuration_Instance_Id) != null) {
if (!UUIDChecker.isValidUUID(instanceIdMap.get(Configuration_Instance_Id))) {
throw new ValidationException(Configuration_Instance_Id);
}
sir.setConfigurationId(instanceIdMap.get(Configuration_Instance_Id));
}
if (instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID) != null) {
if (!UUIDChecker.isValidUUID(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID))) {
throw new ValidationException(CommonConstants.INSTANCE_GROUP_INSTANCE_ID, true);
}
sir.setInstanceGroupId(instanceIdMap.get(CommonConstants.INSTANCE_GROUP_INSTANCE_ID));
}
if (instanceIdMap.get(PNF_NAME) != null) {
sir.setPnfName(instanceIdMap.get(PNF_NAME));
}
}
return info;
}
use of org.onap.so.serviceinstancebeans.ServiceInstancesRequest in project so by onap.
the class WorkflowAction method selectExecutionList.
public void selectExecutionList(DelegateExecution execution) throws Exception {
try {
fillExecutionDefault(execution);
final String bpmnRequest = (String) execution.getVariable(BBConstants.G_BPMN_REQUEST);
ServiceInstancesRequest sIRequest = new ObjectMapper().readValue(bpmnRequest, ServiceInstancesRequest.class);
final String requestId = (String) execution.getVariable(BBConstants.G_REQUEST_ID);
String uri = (String) execution.getVariable(BBConstants.G_URI);
boolean isResume = isUriResume(uri);
final boolean isALaCarte = (boolean) execution.getVariable(BBConstants.G_ALACARTE);
Resource resource = getResource(bbInputSetupUtils, isResume, isALaCarte, uri, requestId);
WorkflowResourceIds workflowResourceIds = populateResourceIdsFromApiHandler(execution);
RequestDetails requestDetails = sIRequest.getRequestDetails();
String requestAction = (String) execution.getVariable(BBConstants.G_ACTION);
String resourceId = getResourceId(resource, requestAction, requestDetails, workflowResourceIds);
WorkflowType resourceType = resource.getResourceType();
String serviceInstanceId = getServiceInstanceId(execution, resourceId, resourceType);
fillExecution(execution, requestDetails.getRequestInfo().getSuppressRollback(), resourceId, resourceType);
List<ExecuteBuildingBlock> flowsToExecute;
if (isRequestMacroServiceResume(isALaCarte, resourceType, requestAction, serviceInstanceId)) {
String errorMessage = "Could not resume Macro flow. Error loading execution path.";
flowsToExecute = loadExecuteBuildingBlocks(execution, requestId, errorMessage);
} else if (isALaCarte && isResume) {
String errorMessage = "Could not resume request with request Id: " + requestId + ". No flowsToExecute was found";
flowsToExecute = loadExecuteBuildingBlocks(execution, requestId, errorMessage);
} else {
String vnfType = (String) execution.getVariable(VNF_TYPE);
String cloudOwner = getCloudOwner(requestDetails.getCloudConfiguration());
List<OrchestrationFlow> orchFlows = (List<OrchestrationFlow>) execution.getVariable(BBConstants.G_ORCHESTRATION_FLOW);
final String apiVersion = (String) execution.getVariable(BBConstants.G_APIVERSION);
final String serviceType = Optional.ofNullable((String) execution.getVariable(BBConstants.G_SERVICE_TYPE)).orElse("");
if (isALaCarte) {
flowsToExecute = loadExecuteBuildingBlocksForAlaCarte(orchFlows, execution, requestAction, resourceType, cloudOwner, serviceType, sIRequest, requestId, workflowResourceIds, requestDetails, resourceId, vnfType, apiVersion);
} else {
flowsToExecute = loadExecuteBuildingBlocksForMacro(sIRequest, resourceType, requestAction, execution, serviceInstanceId, resourceId, workflowResourceIds, orchFlows, cloudOwner, serviceType, requestId, apiVersion, vnfType, requestDetails);
}
}
// enable it.
if (sIRequest.getRequestDetails().getRequestParameters() != null && sIRequest.getRequestDetails().getRequestParameters().getUserParams() != null) {
List<Map<String, Object>> userParams = sIRequest.getRequestDetails().getRequestParameters().getUserParams();
for (Map<String, Object> params : userParams) {
if (params.containsKey(HOMINGSOLUTION)) {
execution.setVariable(HOMING, !"none".equals(params.get(HOMINGSOLUTION)));
}
}
}
if (CollectionUtils.isEmpty(flowsToExecute)) {
throw new IllegalStateException("Macro did not come up with a valid execution path.");
}
List<String> flowNames = new ArrayList<>();
logger.info("List of BuildingBlocks to execute:");
flowsToExecute.forEach(ebb -> {
logger.info(ebb.getBuildingBlock().getBpmnFlowName());
flowNames.add(ebb.getBuildingBlock().getBpmnFlowName());
});
if (!isResume) {
bbInputSetupUtils.persistFlowExecutionPath(requestId, flowsToExecute);
}
setExecutionVariables(execution, flowsToExecute, flowNames);
} catch (Exception ex) {
if (!(execution.hasVariable("WorkflowException") || execution.hasVariable("WorkflowExceptionExceptionMessage"))) {
buildAndThrowException(execution, "Exception while setting execution list. ", ex);
} else {
throw ex;
}
}
}
use of org.onap.so.serviceinstancebeans.ServiceInstancesRequest in project so by onap.
the class WorkflowAction method loadExecuteBuildingBlocksForMacro.
private List<ExecuteBuildingBlock> loadExecuteBuildingBlocksForMacro(ServiceInstancesRequest sIRequest, WorkflowType resourceType, String requestAction, DelegateExecution execution, String serviceInstanceId, String resourceId, WorkflowResourceIds workflowResourceIds, List<OrchestrationFlow> orchFlows, String cloudOwner, String serviceType, String requestId, String apiVersion, String vnfType, RequestDetails requestDetails) throws IOException, VrfBondingServiceException {
List<ExecuteBuildingBlock> flowsToExecute;
List<Resource> resourceList = new ArrayList<>();
List<Pair<WorkflowType, String>> aaiResourceIds = new ArrayList<>();
if (resourceType == WorkflowType.SERVICE || isVNFCreate(resourceType, requestAction)) {
resourceList = serviceEBBLoader.getResourceListForService(sIRequest, requestAction, execution, serviceInstanceId, resourceId, aaiResourceIds);
} else if (resourceType == WorkflowType.VNF && (DELETE_INSTANCE.equalsIgnoreCase(requestAction) || REPLACEINSTANCE.equalsIgnoreCase(requestAction) || (RECREATE_INSTANCE.equalsIgnoreCase(requestAction)))) {
vnfEBBLoader.traverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(), workflowResourceIds.getVnfId(), aaiResourceIds);
} else if (resourceType == WorkflowType.VNF && UPDATE_INSTANCE.equalsIgnoreCase(requestAction)) {
vnfEBBLoader.customTraverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(), workflowResourceIds.getVnfId(), aaiResourceIds);
} else if (resourceType == WorkflowType.VNF && HEALTH_CHECK.equalsIgnoreCase(requestAction)) {
vnfEBBLoader.customTraverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(), workflowResourceIds.getVnfId(), aaiResourceIds);
} else if (resourceType == WorkflowType.VNF && UPGRADE_CNF.equalsIgnoreCase(requestAction)) {
vnfEBBLoader.customTraverseAAIVnf(execution, resourceList, workflowResourceIds.getServiceInstanceId(), workflowResourceIds.getVnfId(), aaiResourceIds);
} else {
buildAndThrowException(execution, "Current Macro Request is not supported");
}
StringBuilder foundObjects = new StringBuilder();
for (WorkflowType type : WorkflowType.values()) {
foundObjects.append(type).append(" - ").append((int) resourceList.stream().filter(x -> type.equals(x.getResourceType())).count()).append(" ");
}
logger.info("Found {}", foundObjects);
if (orchFlows == null || orchFlows.isEmpty()) {
orchFlows = queryNorthBoundRequestCatalogDb(execution, requestAction, resourceType, false, cloudOwner, serviceType);
}
boolean vnfReplace = false;
if (resourceType.equals(WorkflowType.VNF) && (REPLACEINSTANCE.equalsIgnoreCase(requestAction) || REPLACEINSTANCERETAINASSIGNMENTS.equalsIgnoreCase(requestAction))) {
vnfReplace = true;
}
flowsToExecute = executeBuildingBlockBuilder.buildExecuteBuildingBlockList(orchFlows, resourceList, requestId, apiVersion, resourceId, requestAction, vnfType, workflowResourceIds, requestDetails, vnfReplace);
if (serviceEBBLoader.isNetworkCollectionInTheResourceList(resourceList)) {
logger.info("Sorting for Vlan Tagging");
flowsToExecute = sortExecutionPathByObjectForVlanTagging(flowsToExecute, requestAction);
}
logger.info("Building Block Execution Order");
for (ExecuteBuildingBlock block : flowsToExecute) {
Resource res = resourceList.stream().filter(resource -> resource.getResourceId() == block.getBuildingBlock().getKey()).findAny().orElse(null);
String log = "Block: " + block.getBuildingBlock().getBpmnFlowName();
if (res != null) {
log += ", Resource: " + res.getResourceType() + "[" + res.getResourceId() + "]";
log += ", Priority: " + res.getProcessingPriority();
if (res.getResourceType() == WorkflowType.VFMODULE)
log += ", Base: " + res.isBaseVfModule();
}
if (block.getBuildingBlock().getBpmnScope() != null)
log += ", Scope: " + block.getBuildingBlock().getBpmnScope();
if (block.getBuildingBlock().getBpmnAction() != null)
log += ", Action: " + block.getBuildingBlock().getBpmnAction();
logger.info(log);
}
// By default, enable homing at VNF level for CREATE_INSTANCE and ASSIGNINSTANCE
if (resourceType == WorkflowType.SERVICE && (requestAction.equals(CREATE_INSTANCE) || requestAction.equals(ASSIGN_INSTANCE)) && resourceList.stream().anyMatch(x -> WorkflowType.VNF.equals(x.getResourceType()))) {
execution.setVariable(HOMING, true);
execution.setVariable("calledHoming", false);
}
if (resourceType == WorkflowType.SERVICE && (requestAction.equalsIgnoreCase(ASSIGN_INSTANCE) || requestAction.equalsIgnoreCase(CREATE_INSTANCE))) {
generateResourceIds(flowsToExecute, resourceList, serviceInstanceId);
} else {
updateResourceIdsFromAAITraversal(flowsToExecute, resourceList, aaiResourceIds, serviceInstanceId);
}
execution.setVariable("resources", resourceList);
return flowsToExecute;
}
use of org.onap.so.serviceinstancebeans.ServiceInstancesRequest in project so by onap.
the class BpmnRequestBuilder method createServiceInstancesRequest.
protected ServiceInstancesRequest createServiceInstancesRequest(ServiceInstance serviceInstance) {
ServiceInstancesRequest request = new ServiceInstancesRequest();
RequestDetails requestDetails = mapServiceRequestDetails(serviceInstance);
request.setRequestDetails(requestDetails);
return request;
}
use of org.onap.so.serviceinstancebeans.ServiceInstancesRequest in project so by onap.
the class BpmnRequestBuilder method mapCloudConfigurationVnf.
public CloudConfiguration mapCloudConfigurationVnf(String vnfId) {
CloudConfiguration cloudConfig = new CloudConfiguration();
String tenantId = null;
String cloudOwner = null;
String lcpRegionId = null;
Map<String, String[]> filters = createQueryRequest("vnfId", vnfId);
Optional<ServiceInstancesRequest> request = findServiceInstanceRequest(filters);
if (request.isPresent()) {
if (request.get().getRequestDetails() != null && request.get().getRequestDetails().getCloudConfiguration() != null) {
if (request.get().getRequestDetails().getCloudConfiguration().getTenantId() != null) {
tenantId = request.get().getRequestDetails().getCloudConfiguration().getTenantId();
}
if (request.get().getRequestDetails().getCloudConfiguration().getCloudOwner() != null) {
cloudOwner = request.get().getRequestDetails().getCloudConfiguration().getCloudOwner();
}
if (request.get().getRequestDetails().getCloudConfiguration().getLcpCloudRegionId() != null) {
lcpRegionId = request.get().getRequestDetails().getCloudConfiguration().getLcpCloudRegionId();
}
}
} else {
throw new CloudConfigurationNotFoundException(CLOUD_CONFIGURATION_COULD_NOT_BE_FOUND);
}
cloudConfig.setTenantId(tenantId);
cloudConfig.setCloudOwner(cloudOwner);
cloudConfig.setLcpCloudRegionId(lcpRegionId);
return cloudConfig;
}
Aggregations