@Component
public class AppcRunTasks {
- private static final Logger logger = LoggerFactory.getLogger(AppcRunTasks.class);
- @Autowired
- private ExceptionBuilder exceptionUtil;
- @Autowired
- private ExtractPojosForBB extractPojosForBB;
- @Autowired
- private CatalogDbClient catalogDbClient;
- @Autowired
- private ApplicationControllerAction appCClient;
-
- public void preProcessActivity(BuildingBlockExecution execution) {
- execution.setVariable("actionSnapshot", Action.Snapshot);
- execution.setVariable("actionLock", Action.Lock);
- execution.setVariable("actionUnlock", Action.Unlock);
- execution.setVariable("actionUpgradePreCheck", Action.UpgradePreCheck);
- execution.setVariable("actionUpgradePostCheck", Action.UpgradePostCheck);
- execution.setVariable("actionQuiesceTraffic", Action.QuiesceTraffic);
- execution.setVariable("actionUpgradeBackup", Action.UpgradeBackup);
- execution.setVariable("actionUpgradeSoftware", Action.UpgradeSoftware);
- execution.setVariable("actionResumeTraffic", Action.ResumeTraffic);
- execution.setVariable("actionStop", Action.Stop);
- execution.setVariable("actionStart", Action.Start);
- execution.setVariable("actionHealthCheck", Action.HealthCheck);
- execution.setVariable("actionDistributeTraffic", Action.DistributeTraffic);
- execution.setVariable("actionDistributeTrafficCheck", Action.DistributeTrafficCheck);
- execution.setVariable("rollbackVnfStop", false);
- execution.setVariable("rollbackVnfLock", false);
- execution.setVariable("rollbackQuiesceTraffic", false);
- }
-
- public void runAppcCommand(BuildingBlockExecution execution, Action action) {
- logger.trace("Start runAppcCommand ");
- String appcCode = "1002";
- String appcMessage = "";
- try {
- 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;
+ private static final Logger logger = LoggerFactory.getLogger(AppcRunTasks.class);
+ @Autowired
+ private ExceptionBuilder exceptionUtil;
+ @Autowired
+ private ExtractPojosForBB extractPojosForBB;
+ @Autowired
+ private CatalogDbClient catalogDbClient;
+ @Autowired
+ private ApplicationControllerAction appCClient;
- if (vnf != null) {
- vnfId = vnf.getVnfId();
- vnfName = vnf.getVnfName();
- vnfType = vnf.getVnfType();
- vnfHostIpAddress = vnf.getIpv4OamAddress();
+ public void preProcessActivity(BuildingBlockExecution execution) {
+ execution.setVariable("actionSnapshot", Action.Snapshot);
+ execution.setVariable("actionLock", Action.Lock);
+ execution.setVariable("actionUnlock", Action.Unlock);
+ execution.setVariable("actionUpgradePreCheck", Action.UpgradePreCheck);
+ execution.setVariable("actionUpgradePostCheck", Action.UpgradePostCheck);
+ execution.setVariable("actionQuiesceTraffic", Action.QuiesceTraffic);
+ execution.setVariable("actionUpgradeBackup", Action.UpgradeBackup);
+ execution.setVariable("actionUpgradeSoftware", Action.UpgradeSoftware);
+ execution.setVariable("actionResumeTraffic", Action.ResumeTraffic);
+ execution.setVariable("actionStop", Action.Stop);
+ execution.setVariable("actionStart", Action.Start);
+ execution.setVariable("actionHealthCheck", Action.HealthCheck);
+ execution.setVariable("actionDistributeTraffic", Action.DistributeTraffic);
+ execution.setVariable("actionDistributeTrafficCheck", Action.DistributeTrafficCheck);
+ execution.setVariable("rollbackVnfStop", false);
+ execution.setVariable("rollbackVnfLock", false);
+ execution.setVariable("rollbackQuiesceTraffic", false);
+ }
+
+ public void runAppcCommand(BuildingBlockExecution execution, Action action) {
+ logger.trace("Start runAppcCommand ");
+ String appcCode = "1002";
+ String appcMessage = "";
+ try {
+ 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 vmIdList = execution.getVariable("vmIdList");
+ String vserverIdList = execution.getVariable("vserverIdList");
+ String identityUrl = execution.getVariable("identityUrl");
+
+ ControllerSelectionReference controllerSelectionReference = catalogDbClient
+ .getControllerSelectionReferenceByVnfTypeAndActionCategory(vnfType, action.toString());
+ String controllerType = controllerSelectionReference.getControllerName();
+
+ String vfModuleId = null;
+ VfModule vfModule = null;
+ try {
+ vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
+ } catch (BBObjectNotFoundException e) {
+ }
+ if (vfModule != null) {
+ vfModuleId = vfModule.getVfModuleId();
+ }
+
+ HashMap<String, String> payloadInfo = buildPayloadInfo(vnfName, aicIdentity, vnfHostIpAddress, vmIdList,
+ vserverIdList, identityUrl, vfModuleId);
+ Optional<String> payload = null;
+ RequestParameters requestParameters = gBBInput.getRequestContext().getRequestParameters();
+ if (requestParameters != null) {
+ String pay = requestParameters.getPayload();
+ if (pay != null) {
+ payload = Optional.of(pay);
+ }
+ }
+ logger.debug("Running APP-C action: {}", action.toString());
+ logger.debug("VNFID: {}", vnfId);
+ appCClient.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType);
+ appcCode = appCClient.getErrorCode();
+ appcMessage = appCClient.getErrorMessage();
+ mapRollbackVariables(execution, action, appcCode);
+ } catch (Exception e) {
+ logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION.toString(),
+ "Caught exception in runAppcCommand", "BPMN", ErrorCode.UnknownError.getValue(), "APPC Error", e);
+ appcMessage = e.getMessage();
+ }
+
+ logger.error("Error Message: {}", appcMessage);
+ logger.error("ERROR CODE: {}", appcCode);
+ logger.trace("End of runAppCommand ");
+ if (appcCode != null && !appcCode.equals("0")) {
+ exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(appcCode), appcMessage);
+ }
+ }
+
+ protected void mapRollbackVariables(BuildingBlockExecution execution, Action action, String appcCode) {
+ if (appcCode.equals("0") && action != null) {
+ if (action.equals(Action.Lock)) {
+ execution.setVariable("rollbackVnfLock", true);
+ } else if (action.equals(Action.Unlock)) {
+ execution.setVariable("rollbackVnfLock", false);
+ } else if (action.equals(Action.Start)) {
+ execution.setVariable("rollbackVnfStop", false);
+ } else if (action.equals(Action.Stop)) {
+ execution.setVariable("rollbackVnfStop", true);
+ } else if (action.equals(Action.QuiesceTraffic)) {
+ execution.setVariable("rollbackQuiesceTraffic", true);
+ } else if (action.equals(Action.ResumeTraffic)) {
+ execution.setVariable("rollbackQuiesceTraffic", false);
+ }
}
- String msoRequestId = gBBInput.getRequestContext().getMsoRequestId();
+ }
- String aicIdentity = execution.getVariable("aicIdentity");
- String vmIdList = execution.getVariable("vmIdList");
- String vserverIdList = execution.getVariable("vserverIdList");
- String identityUrl = execution.getVariable("identityUrl");
-
- ControllerSelectionReference controllerSelectionReference = catalogDbClient.getControllerSelectionReferenceByVnfTypeAndActionCategory(vnfType, action.toString());
- String controllerType = controllerSelectionReference.getControllerName();
-
- String vfModuleId = null;
- VfModule vfModule = null;
- try {
- vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
- } catch (BBObjectNotFoundException e) {
- }
- if (vfModule != null) {
- vfModuleId = vfModule.getVfModuleId();
- }
-
- HashMap<String, String> payloadInfo = buildPayloadInfo(vnfName, aicIdentity, vnfHostIpAddress, vmIdList, vserverIdList,
- identityUrl, vfModuleId);
- Optional<String> payload = null;
- RequestParameters requestParameters = gBBInput.getRequestContext().getRequestParameters();
- if(requestParameters != null){
- String pay = requestParameters.getPayload();
- if (pay != null) {
- payload = Optional.of(pay);
- }
- }
- logger.debug("Running APP-C action: {}", action.toString());
- logger.debug("VNFID: {}", vnfId);
- appCClient.runAppCCommand(action, msoRequestId, vnfId, payload, payloadInfo, controllerType);
- appcCode = appCClient.getErrorCode();
- appcMessage = appCClient.getErrorMessage();
- mapRollbackVariables(execution, action, appcCode);
- }
- catch (Exception e) {
- logger.error("{} {} {} {} {}", MessageEnum.BPMN_GENERAL_EXCEPTION.toString(),
- "Caught exception in runAppcCommand", "BPMN",
- ErrorCode.UnknownError.getValue(), "APPC Error", e);
- appcMessage = e.getMessage();
- }
-
- logger.error("Error Message: {}", appcMessage);
- logger.error("ERROR CODE: {}", appcCode);
- logger.trace("End of runAppCommand ");
- if (appcCode != null && !appcCode.equals("0")) {
- exceptionUtil.buildAndThrowWorkflowException(execution, Integer.parseInt(appcCode), appcMessage);
- }
- }
-
- protected void mapRollbackVariables(BuildingBlockExecution execution, Action action, String appcCode) {
- if (appcCode.equals("0") && action != null) {
- if (action.equals(Action.Lock)) {
- execution.setVariable("rollbackVnfLock", true);
- } else if (action.equals(Action.Unlock)) {
- execution.setVariable("rollbackVnfLock", false);
- } else if (action.equals(Action.Start)) {
- execution.setVariable("rollbackVnfStop", false);
- } else if (action.equals(Action.Stop)) {
- execution.setVariable("rollbackVnfStop", true);
- } else if (action.equals(Action.QuiesceTraffic)) {
- execution.setVariable("rollbackQuiesceTraffic", true);
- } else if (action.equals(Action.ResumeTraffic)) {
- execution.setVariable("rollbackQuiesceTraffic", false);
- }
- }
- }
-
- private HashMap<String,String> buildPayloadInfo(String vnfName, String aicIdentity, String vnfHostIpAddress,
- String vmIdList, String vserverIdList, String identityUrl, String vfModuleId) {
- HashMap<String, String> payloadInfo = new HashMap<String, String>();
- payloadInfo.put("vnfName", vnfName);
- payloadInfo.put("aicIdentity", aicIdentity);
- payloadInfo.put("vnfHostIpAddress", vnfHostIpAddress);
- payloadInfo.put("vmIdList", vmIdList);
- payloadInfo.put("vserverIdList", vserverIdList);
- payloadInfo.put("identityUrl", identityUrl);
- payloadInfo.put("vfModuleId",vfModuleId);
- return payloadInfo;
- }
+ private HashMap<String, String> buildPayloadInfo(String vnfName, String aicIdentity, String vnfHostIpAddress,
+ String vmIdList, String vserverIdList, String identityUrl, String vfModuleId) {
+ HashMap<String, String> payloadInfo = new HashMap<String, String>();
+ payloadInfo.put("vnfName", vnfName);
+ payloadInfo.put("aicIdentity", aicIdentity);
+ payloadInfo.put("vnfHostIpAddress", vnfHostIpAddress);
+ payloadInfo.put("vmIdList", vmIdList);
+ payloadInfo.put("vserverIdList", vserverIdList);
+ payloadInfo.put("identityUrl", identityUrl);
+ payloadInfo.put("vfModuleId", vfModuleId);
+ return payloadInfo;
+ }
}