use of org.onap.so.serviceinstancebeans.RequestDetails in project so by onap.
the class OrchestrationRequests method mapInfraActiveRequestToRequest.
protected Request mapInfraActiveRequestToRequest(InfraActiveRequests iar, boolean includeCloudRequest, String format, String version) throws ApiException {
String requestBody = iar.getRequestBody();
Request request = new Request();
ObjectMapper mapper = new ObjectMapper();
request.setRequestId(iar.getRequestId());
request.setRequestScope(iar.getRequestScope());
request.setRequestType(iar.getRequestAction());
String originalRequestId = iar.getOriginalRequestId();
if (originalRequestId != null) {
request.setOriginalRequestId(originalRequestId);
}
if (!version.matches("v[1-7]")) {
String workflowName = iar.getWorkflowName();
if (workflowName == null) {
workflowName = iar.getRequestAction();
}
request.setWorkflowName(workflowName);
String operationName = iar.getOperationName();
if (operationName != null) {
request.setOperationName(operationName);
}
}
InstanceReferences ir = new InstanceReferences();
if (iar.getNetworkId() != null)
ir.setNetworkInstanceId(iar.getNetworkId());
if (iar.getNetworkName() != null)
ir.setNetworkInstanceName(iar.getNetworkName());
if (iar.getServiceInstanceId() != null)
ir.setServiceInstanceId(iar.getServiceInstanceId());
if (iar.getServiceInstanceName() != null)
ir.setServiceInstanceName(iar.getServiceInstanceName());
if (iar.getVfModuleId() != null)
ir.setVfModuleInstanceId(iar.getVfModuleId());
if (iar.getVfModuleName() != null)
ir.setVfModuleInstanceName(iar.getVfModuleName());
if (iar.getVnfId() != null)
ir.setVnfInstanceId(iar.getVnfId());
if (iar.getVnfName() != null)
ir.setVnfInstanceName(iar.getVnfName());
if (iar.getVolumeGroupId() != null)
ir.setVolumeGroupInstanceId(iar.getVolumeGroupId());
if (iar.getVolumeGroupName() != null)
ir.setVolumeGroupInstanceName(iar.getVolumeGroupName());
if (iar.getInstanceGroupId() != null)
ir.setInstanceGroupId(iar.getInstanceGroupId());
if (iar.getInstanceGroupName() != null)
ir.setInstanceGroupName(iar.getInstanceGroupName());
request.setInstanceReferences(ir);
RequestDetails requestDetails = null;
if (StringUtils.isNotBlank(requestBody)) {
try {
if (requestBody.contains("\"requestDetails\":")) {
ServiceInstancesRequest sir = mapper.readValue(requestBody, ServiceInstancesRequest.class);
requestDetails = sir.getRequestDetails();
} else {
requestDetails = mapper.readValue(requestBody, RequestDetails.class);
}
if (requestDetails.getRequestInfo() != null && iar.getProductFamilyName() != null) {
requestDetails.getRequestInfo().setProductFamilyName(iar.getProductFamilyName());
}
if (requestDetails.getCloudConfiguration() != null && iar.getTenantName() != null) {
requestDetails.getCloudConfiguration().setTenantName(iar.getTenantName());
}
} catch (IOException e) {
logger.error("Exception occurred", e);
ErrorLoggerInfo errorLoggerInfo = new ErrorLoggerInfo.Builder(MessageEnum.APIH_REQUEST_VALIDATION_ERROR, ErrorCode.SchemaError).build();
ValidateException validateException = new ValidateException.Builder("Mapping of request to JSON object failed : ", HttpStatus.SC_BAD_REQUEST, ErrorNumbers.SVC_BAD_PARAMETER).cause(e).errorInfo(errorLoggerInfo).build();
throw validateException;
}
}
request.setRequestDetails(requestDetails);
if (iar.getStartTime() != null) {
String startTimeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(iar.getStartTime()) + " GMT";
request.setStartTime(startTimeStamp);
}
if (iar.getEndTime() != null) {
String endTimeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(iar.getEndTime()) + " GMT";
request.setFinishTime(endTimeStamp);
}
RequestStatus status = new RequestStatus();
if (iar.getModifyTime() != null) {
String timeStamp = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss").format(iar.getModifyTime()) + " GMT";
status.setTimeStamp(timeStamp);
}
status.setRequestState(mapRequestStatusToRequest(iar, format));
if (iar.getProgress() != null) {
status.setPercentProgress(iar.getProgress().intValue());
}
if (iar.getCloudApiRequests() != null && !iar.getCloudApiRequests().isEmpty() && includeCloudRequest) {
iar.getCloudApiRequests().stream().forEach(cloudRequest -> {
try {
request.getCloudRequestData().add(new CloudRequestData(mapper.readValue(cloudRequest.getRequestBody(), Object.class), cloudRequest.getCloudIdentifier()));
} catch (Exception e) {
logger.error("Error reading Cloud Request", e);
}
});
}
mapRequestStatusAndExtSysErrSrcToRequest(iar, status, format, version);
request.setRequestStatus(status);
return request;
}
use of org.onap.so.serviceinstancebeans.RequestDetails in project so by onap.
the class RequestHandlerUtils method getServiceURI.
protected RecipeLookupResult getServiceURI(ServiceInstancesRequest servInstReq, Actions action, boolean alaCarteFlag) throws IOException {
// SERVICE REQUEST
// Construct the default service name
// TODO need to make this a configurable property
String defaultServiceModelName = getDefaultModel(servInstReq);
RequestDetails requestDetails = servInstReq.getRequestDetails();
ModelInfo modelInfo = requestDetails.getModelInfo();
org.onap.so.db.catalog.beans.Service serviceRecord;
List<org.onap.so.db.catalog.beans.Service> serviceRecordList;
ServiceRecipe recipe = null;
if (alaCarteFlag) {
serviceRecord = catalogDbClient.getFirstByModelNameOrderByModelVersionDesc(defaultServiceModelName);
if (serviceRecord != null) {
recipe = catalogDbClient.getFirstByServiceModelUUIDAndAction(serviceRecord.getModelUUID(), action.toString());
}
} else {
serviceRecord = catalogDbClient.getServiceByID(modelInfo.getModelVersionId());
recipe = catalogDbClient.getFirstByServiceModelUUIDAndAction(modelInfo.getModelVersionId(), action.toString());
if (recipe == null) {
serviceRecordList = catalogDbClient.getServiceByModelInvariantUUIDOrderByModelVersionDesc(modelInfo.getModelInvariantId());
if (!serviceRecordList.isEmpty()) {
for (org.onap.so.db.catalog.beans.Service record : serviceRecordList) {
recipe = catalogDbClient.getFirstByServiceModelUUIDAndAction(record.getModelUUID(), action.toString());
if (recipe != null) {
break;
}
}
}
}
}
// if an aLaCarte flag was sent in the request, throw an error if the recipe was not found
RequestParameters reqParam = requestDetails.getRequestParameters();
if (reqParam != null && alaCarteFlag && recipe == null) {
return null;
} else if (!alaCarteFlag && recipe != null && Action.createInstance.equals(action)) {
mapToLegacyRequest(requestDetails);
} else if (recipe == null) {
// aLaCarte wasn't sent, so we'll try the default
serviceRecord = catalogDbClient.getFirstByModelNameOrderByModelVersionDesc(defaultServiceModelName);
recipe = catalogDbClient.getFirstByServiceModelUUIDAndAction(serviceRecord.getModelUUID(), action.toString());
}
if (modelInfo.getModelVersionId() == null) {
modelInfo.setModelVersionId(serviceRecord.getModelUUID());
}
if (recipe == null) {
return null;
}
return new RecipeLookupResult(recipe.getOrchestrationUri(), recipe.getRecipeTimeout());
}
use of org.onap.so.serviceinstancebeans.RequestDetails in project so by onap.
the class NfSoftwareUpgradeDispatcherTest method mockMapper.
private void mockMapper() throws IOException {
RequestDetails bpmnRequestDetails = new RequestDetails();
RequestInfo requestInfo = new RequestInfo();
requestInfo.setInstanceName("demo");
bpmnRequestDetails.setRequestInfo(requestInfo);
RequestParameters requestParameters = new RequestParameters();
List<Map<String, Object>> userParams = new ArrayList<>();
Map<String, Object> map = new HashMap<>();
map.put("name", "targetSoftwareVersion");
map.put("value", TEST_TARGET_SOFTWARE_VERSION);
userParams.add(map);
map = new HashMap<>();
map.put("name", "pnfName");
map.put("value", "PNFDemo");
userParams.add(map);
requestParameters.setUserParams(userParams);
bpmnRequestDetails.setRequestParameters(requestParameters);
ModelInfo modelInfo = new ModelInfo();
modelInfo.setModelInvariantUuid("439b7a2f-9524-4dbf-9eee-f2e05521df3f");
modelInfo.setModelInvariantId("439b7a2f-9524-4dbf-9eee-f2e05521df3f");
modelInfo.setModelUuid("42daaac6-5017-4e1e-96c8-6a27dfbe1421");
modelInfo.setModelName("PNF_int_service_2");
modelInfo.setModelVersion("1.0");
bpmnRequestDetails.setModelInfo(modelInfo);
doReturn(bpmnRequestDetails).when(mapper).readValue(JsonUtils.getJsonValue(String.valueOf(execution.getVariable("bpmnRequest")), "requestDetails"), RequestDetails.class);
}
use of org.onap.so.serviceinstancebeans.RequestDetails in project so by onap.
the class WorkflowActionTest method getConfigBuildingBlocksTest.
@Test
public void getConfigBuildingBlocksTest() throws Exception {
String gAction = "deleteInstance";
ObjectMapper mapper = new ObjectMapper();
mapper.disable(DeserializationFeature.FAIL_ON_IGNORED_PROPERTIES);
WorkflowType resourceType = WorkflowType.VFMODULE;
execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688");
execution.setVariable("requestAction", gAction);
String bpmnRequest = new String(Files.readAllBytes(Paths.get("src/test/resources/__files/VfModuleCreateWithFabric.json")));
execution.setVariable("bpmnRequest", bpmnRequest);
execution.setVariable("vnfId", "1234");
execution.setVariable("vfModuleId", "vfModuleId1234");
execution.setVariable("requestUri", "v7/serviceInstances/f647e3ef-6d2e-4cd3-bff4-8df4634208de/vnfs/b80b16a5-f80d-4ffa-91c8-bd47c7438a3d/vfModules");
ServiceInstancesRequest sIRequest = mapper.readValue(bpmnRequest, ServiceInstancesRequest.class);
RequestDetails requestDetails = sIRequest.getRequestDetails();
String requestAction = "deleteInstance";
String requestId = "9c944122-d161-4280-8594-48c06a9d96d5";
boolean aLaCarte = true;
String apiVersion = "7";
String vnfType = "vnfType";
String key = "00d15ebb-c80e-43c1-80f0-90c40dde70b0";
String resourceId = "d1d35800-783d-42d3-82f6-d654c5054a6e";
Resource resourceKey = new Resource(resourceType, key, aLaCarte, null);
WorkflowResourceIds workflowResourceIds = SPY_workflowAction.populateResourceIdsFromApiHandler(execution);
List<OrchestrationFlow> orchFlows = createFlowList("DeactivateVfModuleBB", "DeleteVfModuleBB", "UnassignVfModuleBB", "DeleteFabricConfigurationBB");
ConfigBuildingBlocksDataObject dataObj = new ConfigBuildingBlocksDataObject().setsIRequest(sIRequest).setOrchFlows(orchFlows).setRequestId(requestId).setResourceKey(resourceKey).setApiVersion(apiVersion).setResourceId(resourceId).setRequestAction(requestAction).setaLaCarte(aLaCarte).setVnfType(vnfType).setWorkflowResourceIds(workflowResourceIds).setRequestDetails(requestDetails).setExecution(execution);
org.onap.aai.domain.yang.GenericVnf vnf = new org.onap.aai.domain.yang.GenericVnf();
vnf.setVnfId("vnf0");
vnf.setModelCustomizationId("modelCustomizationId");
when(bbSetupUtils.getAAIGenericVnf(any())).thenReturn(vnf);
org.onap.aai.domain.yang.VfModule vfModule = new org.onap.aai.domain.yang.VfModule();
vfModule.setModelCustomizationId("modelCustomizationId");
org.onap.aai.domain.yang.Configuration config1 = new org.onap.aai.domain.yang.Configuration();
config1.setConfigurationId("config1");
org.onap.aai.domain.yang.Configuration config2 = new org.onap.aai.domain.yang.Configuration();
config2.setConfigurationId("config2");
List<org.onap.aai.domain.yang.Vnfc> vnfcs = new ArrayList<org.onap.aai.domain.yang.Vnfc>();
org.onap.aai.domain.yang.Vnfc vnfc1 = new org.onap.aai.domain.yang.Vnfc();
vnfc1.setVnfcName("zauk53avetd02svm001");
org.onap.aai.domain.yang.Vnfc vnfc2 = new org.onap.aai.domain.yang.Vnfc();
vnfc2.setVnfcName("zauk53avetd02tvm001");
vnfcs.add(vnfc1);
vnfcs.add(vnfc2);
when(bbSetupUtils.getAAIVfModule(any(), any())).thenReturn(vfModule);
doReturn(vnfcs).when(SPY_workflowAction).getRelatedResourcesInVfModule(any(), any(), eq(org.onap.aai.domain.yang.Vnfc.class), eq(Types.VNFC));
doReturn(config1).when(SPY_workflowAction).getRelatedResourcesInVnfc(eq(vnfc1), eq(org.onap.aai.domain.yang.Configuration.class), eq(Types.CONFIGURATION));
doReturn(config2).when(SPY_workflowAction).getRelatedResourcesInVnfc(eq(vnfc2), eq(org.onap.aai.domain.yang.Configuration.class), eq(Types.CONFIGURATION));
List<ExecuteBuildingBlock> results = SPY_workflowAction.getConfigBuildingBlocks(dataObj);
assertFalse(results.isEmpty());
assertEquals(2, results.size());
assertEquals("config1", results.get(0).getWorkflowResourceIds().getConfigurationId());
assertEquals("config2", results.get(1).getWorkflowResourceIds().getConfigurationId());
assertEquals("zauk53avetd02svm001", results.get(0).getConfigurationResourceKeys().getVnfcName());
assertEquals("zauk53avetd02tvm001", results.get(1).getConfigurationResourceKeys().getVnfcName());
}
use of org.onap.so.serviceinstancebeans.RequestDetails in project so by onap.
the class WorkflowActionTest method getConfigBuildingBlocksNoVfModuleFabricDeleteTest.
@Test
public void getConfigBuildingBlocksNoVfModuleFabricDeleteTest() throws Exception {
String gAction = "deleteInstance";
ObjectMapper mapper = new ObjectMapper();
WorkflowType resourceType = WorkflowType.VFMODULE;
String bpmnRequest = readBpmnRequestFromFile(VF_MODULE_CREATE_WITH_FABRIC_JSON);
execution.setVariable("mso-request-id", "00f704ca-c5e5-4f95-a72c-6889db7b0688");
execution.setVariable("requestAction", gAction);
execution.setVariable("bpmnRequest", bpmnRequest);
execution.setVariable("vnfId", "1234");
execution.setVariable("vfModuleId", "vfModuleId1234");
execution.setVariable("requestUri", "v7/serviceInstances/f647e3ef-6d2e-4cd3-bff4-8df4634208de/vnfs/b80b16a5-f80d-4ffa-91c8-bd47c7438a3d/vfModules");
ServiceInstancesRequest sIRequest = mapper.readValue(bpmnRequest, ServiceInstancesRequest.class);
RequestDetails requestDetails = sIRequest.getRequestDetails();
String requestAction = "deleteInstance";
String requestId = "9c944122-d161-4280-8594-48c06a9d96d5";
boolean aLaCarte = true;
String apiVersion = "7";
String vnfType = "vnfType";
String key = "00d15ebb-c80e-43c1-80f0-90c40dde70b0";
String resourceId = "d1d35800-783d-42d3-82f6-d654c5054a6e";
Resource resourceKey = new Resource(resourceType, key, aLaCarte, null);
WorkflowResourceIds workflowResourceIds = SPY_workflowAction.populateResourceIdsFromApiHandler(execution);
thrown.expect(AAIEntityNotFoundException.class);
thrown.expectMessage(containsString("No matching VfModule is found in Generic-Vnf in AAI for vnfId: 1234 and vfModuleId : vfModuleId1234"));
List<OrchestrationFlow> orchFlows = createFlowList("DeactivateVfModuleBB", "DeleteVfModuleBB", "UnassignVfModuleBB", "DeactivateFabricConfigurationBB", "UnassignFabricConfigurationBB");
ConfigBuildingBlocksDataObject dataObj = new ConfigBuildingBlocksDataObject().setsIRequest(sIRequest).setOrchFlows(orchFlows).setRequestId(requestId).setResourceKey(resourceKey).setApiVersion(apiVersion).setResourceId(resourceId).setRequestAction(requestAction).setaLaCarte(aLaCarte).setVnfType(vnfType).setWorkflowResourceIds(workflowResourceIds).setRequestDetails(requestDetails).setExecution(execution);
org.onap.aai.domain.yang.GenericVnf vnf = new org.onap.aai.domain.yang.GenericVnf();
vnf.setVnfId("vnf0");
vnf.setModelCustomizationId("modelCustomizationId");
when(bbSetupUtils.getAAIGenericVnf(anyObject())).thenReturn(vnf);
org.onap.aai.domain.yang.VfModule vfModule = new org.onap.aai.domain.yang.VfModule();
vfModule.setModelCustomizationId("modelCustomizationId");
when(bbSetupUtils.getAAIVfModule(anyObject(), anyObject())).thenReturn(null);
SPY_workflowAction.getConfigBuildingBlocks(dataObj);
}
Aggregations