use of org.onap.aai.domain.yang.LInterface in project so by onap.
the class ExceptionBuilder method processAuditException.
public void processAuditException(DelegateExecutionImpl execution, boolean flowShouldContinue) {
logger.debug("Processing Audit Results");
String auditListString = execution.getVariable("auditInventoryResult");
String processKey = getProcessKey(execution.getDelegateExecution());
if (auditListString != null) {
StringBuilder errorMessage = new StringBuilder();
try {
ExtractPojosForBB extractPojosForBB = getExtractPojosForBB();
VfModule module = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
String cloudRegionId = execution.getGeneralBuildingBlock().getCloudRegion().getLcpCloudRegionId();
GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
AAIObjectAuditList auditList = objectMapper.getMapper().readValue(auditListString, AAIObjectAuditList.class);
errorMessage = errorMessage.append(auditList.getAuditType() + " VF-Module " + module.getVfModuleId() + " failed due to incomplete AAI vserver inventory population after stack " + auditList.getHeatStackName() + " was successfully " + auditList.getAuditType() + "d in cloud region " + cloudRegionId + ". MSO Audit indicates that the following was not " + auditList.getAuditType() + "d in AAI: ");
Stream<AAIObjectAudit> vServerLInterfaceAuditStream = auditList.getAuditList().stream().filter(auditObject -> auditObject.getAaiObjectType().equals(Types.VSERVER.typeName()) || auditObject.getAaiObjectType().equals(Types.L_INTERFACE.typeName()));
List<AAIObjectAudit> filteredAuditStream = vServerLInterfaceAuditStream.filter(a -> !a.isDoesObjectExist()).collect(Collectors.toList());
for (AAIObjectAudit object : filteredAuditStream) {
if (object.getAaiObjectType().equals(Types.L_INTERFACE.typeName())) {
LInterface li = objectMapper.getMapper().convertValue(object.getAaiObject(), LInterface.class);
errorMessage = errorMessage.append(Types.L_INTERFACE.typeName() + " " + li.getInterfaceId() + ", ");
} else {
Vserver vs = objectMapper.getMapper().convertValue(object.getAaiObject(), Vserver.class);
errorMessage = errorMessage.append(Types.VSERVER.typeName() + " " + vs.getVserverId() + ", ");
}
}
if (errorMessage.length() > 0) {
errorMessage.setLength(errorMessage.length() - 2);
errorMessage = errorMessage.append(".");
}
} catch (IOException | BBObjectNotFoundException e) {
errorMessage = errorMessage.append("process objects in AAI. ");
logger.error("Exception occurred in processAuditException", e);
}
if (flowShouldContinue) {
execution.setVariable("StatusMessage", errorMessage.toString());
} else {
WorkflowException exception = new WorkflowException(processKey, 400, errorMessage.toString(), ONAPComponents.SO);
execution.setVariable("WorkflowException", exception);
execution.setVariable("WorkflowExceptionErrorMessage", errorMessage.toString());
logger.info("Outgoing WorkflowException is {}", exception);
logger.info("Throwing AAIInventoryFailure");
throw new BpmnError("AAIInventoryFailure");
}
} else {
String errorMessage = "Unable to process audit results due to auditInventoryResult being null";
WorkflowException exception = new WorkflowException(processKey, 400, errorMessage, ONAPComponents.SO);
execution.setVariable("WorkflowException", exception);
execution.setVariable("WorkflowExceptionErrorMessage", errorMessage);
logger.info("Outgoing WorkflowException is {}", exception);
logger.info("Throwing AAIInventoryFailure");
throw new BpmnError("AAIInventoryFailure");
}
}
Aggregations