use of org.onap.so.appc.orchestrator.service.beans.ApplicationControllerTaskRequest in project so by onap.
the class AppcOrchestratorPreProcessor method buildAppcTaskRequest.
public void buildAppcTaskRequest(BuildingBlockExecution execution, String actionName) {
try {
Action action = Action.valueOf(actionName);
ApplicationControllerTaskRequest appcTaskRequest = new ApplicationControllerTaskRequest();
appcTaskRequest.setAction(action);
GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
GenericVnf vnf = null;
try {
vnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
} catch (BBObjectNotFoundException e) {
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, "No valid VNF exists");
}
String vnfId = null;
String vnfName = null;
String vnfType = null;
String vnfHostIpAddress = null;
if (vnf != null) {
vnfId = vnf.getVnfId();
vnfName = vnf.getVnfName();
vnfType = vnf.getVnfType();
vnfHostIpAddress = vnf.getIpv4OamAddress();
}
String msoRequestId = gBBInput.getRequestContext().getMsoRequestId();
String aicIdentity = execution.getVariable("aicIdentity");
String identityUrl = execution.getVariable("identityUrl");
appcTaskRequest.setIdentityUrl(identityUrl);
String requestorId = gBBInput.getRequestContext().getRequestorId();
appcTaskRequest.setRequestorId(requestorId);
if (gBBInput.getRequestContext().getRequestParameters() != null) {
String payload = gBBInput.getRequestContext().getRequestParameters().getPayload();
if (payload == null) {
payload = "";
}
String existingSoftwareVersion = JsonUtils.getJsonValue(payload, "existing_software_version");
appcTaskRequest.setExistingSoftwareVersion(existingSoftwareVersion);
String newSoftwareVersion = JsonUtils.getJsonValue(payload, "new_software_version");
appcTaskRequest.setNewSoftwareVersion(newSoftwareVersion);
String operationsTimeout = JsonUtils.getJsonValue(payload, "operations_timeout");
appcTaskRequest.setOperationsTimeout(operationsTimeout);
Map<String, String> configMap = new HashMap<>();
ObjectMapper objectMapper = new ObjectMapper();
String configParamsStr = JsonUtils.getJsonValue(payload, "configuration_parameters");
if (configParamsStr != null) {
configMap = objectMapper.readValue(configParamsStr, new TypeReference<HashMap<String, String>>() {
});
}
appcTaskRequest.setConfigParams(configMap);
}
ControllerSelectionReference controllerSelectionReference = catalogDbClient.getControllerSelectionReferenceByVnfTypeAndActionCategory(vnfType, action.toString());
String controllerType = null;
if (controllerSelectionReference != null) {
controllerType = controllerSelectionReference.getControllerName();
} else {
controllerType = CONTROLLER_TYPE_DEFAULT;
}
appcTaskRequest.setControllerType(controllerType);
execution.setVariable("vmIdList", null);
execution.setVariable("vserverIdList", null);
execution.setVariable("vmIndex", 0);
execution.setVariable("vmIdListSize", 0);
String vfModuleId = null;
VfModule vfModule = null;
try {
vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
} catch (BBObjectNotFoundException e) {
}
if (vfModule != null) {
vfModuleId = vfModule.getVfModuleId();
}
if (action.equals(Action.Snapshot)) {
try {
getVserversForAppc(execution, vnf);
} catch (Exception e) {
logger.warn("Unable to retrieve vservers for vnf: " + vnfId);
}
}
ApplicationControllerVnf applicationControllerVnf = new ApplicationControllerVnf();
applicationControllerVnf.setVnfHostIpAddress(vnfHostIpAddress);
applicationControllerVnf.setVnfId(vnfId);
applicationControllerVnf.setVnfName(vnfName);
appcTaskRequest.setApplicationControllerVnf(applicationControllerVnf);
verifyApplicationControllerTaskRequest(execution, appcTaskRequest);
execution.setVariable("appcOrchestratorRequest", appcTaskRequest);
logger.debug("SET APPC ORCHESTRATOR REQUEST");
} catch (Exception e) {
logger.error("Error building ApplicationControllerTaskRequest Object", e.getMessage());
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e);
}
}
use of org.onap.so.appc.orchestrator.service.beans.ApplicationControllerTaskRequest in project so by onap.
the class AppcOrchestratorPreProcessorTest method buildAppcTaskRequestTest.
@Test
public void buildAppcTaskRequestTest() throws Exception {
final String expectedRequestJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "appcTaskRequest.json")));
ApplicationControllerTaskRequest expectedTaskRequest = mapper.readValue(expectedRequestJson, ApplicationControllerTaskRequest.class);
execution.getLookupMap().put(ResourceKey.GENERIC_VNF_ID, "-TEST");
fillRequiredAppcExecutionFields();
GenericVnf genericVnf = getTestGenericVnf();
when(extractPojosForBB.extractByKey(eq(execution), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(genericVnf);
mockReferenceResponse();
execution.getLookupMap().put(ResourceKey.VF_MODULE_ID, "VF-MODULE-ID-TEST");
VfModule vfModule = new VfModule();
vfModule.setVfModuleId("VF-MODULE-ID");
when(extractPojosForBB.extractByKey(eq(execution), eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule);
appcOrchestratorPreProcessor.buildAppcTaskRequest(execution, "Lock");
ApplicationControllerTaskRequest actualTaskRequest = execution.getVariable("appcOrchestratorRequest");
assertThat(actualTaskRequest, sameBeanAs(expectedTaskRequest));
}
use of org.onap.so.appc.orchestrator.service.beans.ApplicationControllerTaskRequest in project so by onap.
the class ApplicationControllerTaskImplITTest method setup.
@Before
public void setup() {
request = new ApplicationControllerTaskRequest();
request.setRequestorId("testRequestorId");
request.setBookName("testBookName");
request.setControllerType("testControllerType");
request.setFileParameters("testFileParams");
request.setIdentityUrl("testIdentityUrl");
request.setNewSoftwareVersion("2.0");
request.setExistingSoftwareVersion("1.0");
request.setOperationsTimeout("30");
ApplicationControllerVnf applicationControllerVnf = new ApplicationControllerVnf();
applicationControllerVnf.setVnfHostIpAddress("100.100");
applicationControllerVnf.setVnfId("testVnfId");
applicationControllerVnf.setVnfName("testVnfName");
request.setApplicationControllerVnf(applicationControllerVnf);
listener = new ApplicationControllerCallback(null, externalTaskService, appCSupport);
}
use of org.onap.so.appc.orchestrator.service.beans.ApplicationControllerTaskRequest in project so by onap.
the class ApplicationControllerTask method executeExternalTask.
protected void executeExternalTask(ExternalTask externalTask, ExternalTaskService externalTaskService) {
mdcSetup.setupMDC(externalTask);
ApplicationControllerTaskRequest request = externalTask.getVariable("appcOrchestratorRequest");
String msoRequestId = externalTask.getVariable("mso-request-id");
logger.debug("Starting External Task for RequestId: {} ", msoRequestId);
Status status = null;
ApplicationControllerCallback listener = new ApplicationControllerCallback(externalTask, externalTaskService, applicationControllerSupport);
try {
status = applicationControllerTaskImpl.execute(msoRequestId, request, listener);
if (status != null && status.getCode() != 0 && !applicationControllerSupport.getCategoryOf(status).equals(StatusCategory.NORMAL)) {
logger.error("The External Task Id: {} Failed locally with status {}", externalTask.getId(), status.getMessage());
externalTaskService.handleBpmnError(externalTask, "MSOWorkflowException", status.getMessage());
}
} catch (Exception e) {
logger.error("The External Task Id: {} Failed while calling appc with exception", externalTask.getId(), e.getMessage());
externalTaskService.handleBpmnError(externalTask, "MSOWorkflowException", e.getMessage());
}
}
use of org.onap.so.appc.orchestrator.service.beans.ApplicationControllerTaskRequest in project so by onap.
the class AppcOrchestratorPreProcessor method addVmInfoToAppcTaskRequest.
public void addVmInfoToAppcTaskRequest(BuildingBlockExecution execution) {
try {
ApplicationControllerTaskRequest appcTaskRequest = (ApplicationControllerTaskRequest) execution.getVariable("appcOrchestratorRequest");
ArrayList<String> vmIdList = execution.getVariable("vmIdList");
ArrayList<String> vserverIdList = execution.getVariable("vserverIdList");
Integer vmIndex = (Integer) execution.getVariable("vmIndex");
if (vmIdList != null && !vmIdList.isEmpty() && vserverIdList != null && !vserverIdList.isEmpty()) {
execution.setVariable("vmIdListSize", vmIdList.size());
if (vmIndex < vmIdList.size()) {
ApplicationControllerVm applicationControllerVm = new ApplicationControllerVm();
applicationControllerVm.setVmId(vmIdList.get(vmIndex));
applicationControllerVm.setVserverId(vserverIdList.get(vmIndex));
if (appcTaskRequest.getApplicationControllerVnf() == null) {
ApplicationControllerVnf applicationControllerVnf = new ApplicationControllerVnf();
appcTaskRequest.setApplicationControllerVnf(applicationControllerVnf);
}
appcTaskRequest.getApplicationControllerVnf().setApplicationControllerVm(applicationControllerVm);
execution.setVariable("appcOrchestratorRequest", appcTaskRequest);
vmIndex++;
execution.setVariable("vmIndex", vmIndex);
}
}
} catch (Exception e) {
logger.error("Error adding VM info to ApplicationControllerTaskRequest Object", e);
exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e);
}
}
Aggregations