Search in sources :

Example 11 with Vserver

use of org.onap.aai.domain.yang.Vserver 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");
    }
}
Also used : ONAPComponents(org.onap.logging.filter.base.ONAPComponents) Types(org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types) LoggerFactory(org.slf4j.LoggerFactory) WorkflowException(org.onap.so.bpmn.core.WorkflowException) BpmnError(org.camunda.bpm.engine.delegate.BpmnError) MessageEnum(org.onap.so.logger.MessageEnum) DelegateExecutionImpl(org.onap.so.bpmn.common.DelegateExecutionImpl) ResourceKey(org.onap.so.bpmn.servicedecomposition.entities.ResourceKey) LInterface(org.onap.aai.domain.yang.LInterface) ExtractPojosForBB(org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB) ErrorCode(org.onap.logging.filter.base.ErrorCode) Logger(org.slf4j.Logger) VfModule(org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ONAPComponentsList(org.onap.logging.filter.base.ONAPComponentsList) AAIObjectAudit(org.onap.so.objects.audit.AAIObjectAudit) List(java.util.List) Component(org.springframework.stereotype.Component) Stream(java.util.stream.Stream) Vserver(org.onap.aai.domain.yang.Vserver) GraphInventoryCommonObjectMapperProvider(org.onap.aaiclient.client.graphinventory.GraphInventoryCommonObjectMapperProvider) BuildingBlockExecution(org.onap.so.bpmn.common.BuildingBlockExecution) LoggingAnchor(org.onap.so.logger.LoggingAnchor) AAIObjectAuditList(org.onap.so.objects.audit.AAIObjectAuditList) Components(org.onap.so.utils.Components) Vserver(org.onap.aai.domain.yang.Vserver) WorkflowException(org.onap.so.bpmn.core.WorkflowException) IOException(java.io.IOException) AAIObjectAudit(org.onap.so.objects.audit.AAIObjectAudit) VfModule(org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule) AAIObjectAuditList(org.onap.so.objects.audit.AAIObjectAuditList) ExtractPojosForBB(org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB) LInterface(org.onap.aai.domain.yang.LInterface) GraphInventoryCommonObjectMapperProvider(org.onap.aaiclient.client.graphinventory.GraphInventoryCommonObjectMapperProvider) BpmnError(org.camunda.bpm.engine.delegate.BpmnError)

Example 12 with Vserver

use of org.onap.aai.domain.yang.Vserver in project so by onap.

the class AppcOrchestratorPreProcessorTest method getVserversForAppcTest.

@Test
public void getVserversForAppcTest() throws Exception {
    GenericVnf genericVnf = getTestGenericVnf();
    final String aaiVnfJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiGenericVnfWithVservers.json")));
    final String aaiVserverJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiVserverQueryResponse.json")));
    AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(aaiVnfJson);
    ObjectMapper mapper = new ObjectMapper();
    Vserver vserver = mapper.readValue(aaiVserverJson, Vserver.class);
    doReturn(aaiResultWrapper).when(aaiVnfResources).queryVnfWrapperById(genericVnf);
    doReturn(Optional.of(vserver)).when(aaiVnfResources).getVserver(ArgumentMatchers.any(AAIResourceUri.class));
    appcOrchestratorPreProcessor.getVserversForAppc(execution, genericVnf);
    ArrayList<String> vserverIdList = execution.getVariable("vserverIdList");
    ArrayList<String> expectedVserverIdList = new ArrayList<String>();
    expectedVserverIdList.add("1b3f44e5-d96d-4aac-bd9a-310e8cfb0af5");
    expectedVserverIdList.add("14551849-1e70-45cd-bc5d-a256d49548a2");
    expectedVserverIdList.add("48bd7f11-408f-417c-b834-b41c1b98f7d7");
    ArrayList<String> vmIdList = execution.getVariable("vmIdList");
    ArrayList<String> expectedVmIdList = new ArrayList<String>();
    expectedVmIdList.add("http://VSERVER-link.com");
    expectedVmIdList.add("http://VSERVER-link.com");
    expectedVmIdList.add("http://VSERVER-link.com");
    assertEquals(vserverIdList, expectedVserverIdList);
    assertEquals(vmIdList, expectedVmIdList);
}
Also used : Vserver(org.onap.aai.domain.yang.Vserver) GenericVnf(org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf) ArrayList(java.util.ArrayList) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper) Test(org.junit.Test)

Example 13 with Vserver

use of org.onap.aai.domain.yang.Vserver in project so by onap.

the class AppcRunTasksTest method getVserversForAppcTest.

@Test
public void getVserversForAppcTest() throws Exception {
    GenericVnf genericVnf = getTestGenericVnf();
    final String aaiVnfJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiGenericVnfWithVservers.json")));
    final String aaiVserverJson = new String(Files.readAllBytes(Paths.get(JSON_FILE_LOCATION + "aaiVserverQueryResponse.json")));
    AAIResultWrapper aaiResultWrapper = new AAIResultWrapper(aaiVnfJson);
    ObjectMapper mapper = new ObjectMapper();
    Vserver vserver = mapper.readValue(aaiVserverJson, Vserver.class);
    doReturn(aaiResultWrapper).when(aaiVnfResources).queryVnfWrapperById(genericVnf);
    doReturn(Optional.of(vserver)).when(aaiVnfResources).getVserver(any(AAIResourceUri.class));
    appcRunTasks.getVserversForAppc(execution, genericVnf);
    String vserverIdList = execution.getVariable("vserverIdList");
    String expectedVserverIdList = "{\"vserverIds\":\"[\\\"1b3f44e5-d96d-4aac-bd9a-310e8cfb0af5\\\",\\\"14551849-1e70-45cd-bc5d-a256d49548a2\\\",\\\"48bd7f11-408f-417c-b834-b41c1b98f7d7\\\"]\"}";
    String vmIdList = execution.getVariable("vmIdList");
    String expectedVmIdList = "{\"vmIds\":\"[\\\"http://VSERVER-link.com\\\",\\\"http://VSERVER-link.com\\\",\\\"http://VSERVER-link.com\\\"]\"}";
    assertEquals(vserverIdList, expectedVserverIdList);
    assertEquals(vmIdList, expectedVmIdList);
}
Also used : Vserver(org.onap.aai.domain.yang.Vserver) GenericVnf(org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper) Test(org.junit.Test)

Example 14 with Vserver

use of org.onap.aai.domain.yang.Vserver in project so by onap.

the class AuditTasksTest method before.

@Before
public void before() throws BBObjectNotFoundException, JsonProcessingException {
    serviceInstance = setServiceInstance();
    genericVnf = setGenericVnf();
    vfModule = setVfModule();
    buildRequestContext();
    setCloudRegion();
    setRequestContext();
    when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.GENERIC_VNF_ID))).thenReturn(genericVnf);
    when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.VF_MODULE_ID))).thenReturn(vfModule);
    when(extractPojosForBB.extractByKey(any(), eq(ResourceKey.SERVICE_INSTANCE_ID))).thenReturn(serviceInstance);
    execution.setVariable("auditQuerySuccess", true);
    AAIObjectAuditList auditList = new AAIObjectAuditList();
    auditList.setHeatStackName("testHeatStackName");
    AAIObjectAudit audit = new AAIObjectAudit();
    Vserver vserver = new Vserver();
    vserver.setVserverId("testVserverId");
    audit.setAaiObject(vserver);
    auditList.getAuditList().add(audit);
    GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
    String auditListString = objectMapper.getMapper().writeValueAsString(audit);
    execution.setVariable("auditList", auditListString);
}
Also used : Vserver(org.onap.aai.domain.yang.Vserver) GraphInventoryCommonObjectMapperProvider(org.onap.aaiclient.client.graphinventory.GraphInventoryCommonObjectMapperProvider) AAIObjectAudit(org.onap.so.objects.audit.AAIObjectAudit) AAIObjectAuditList(org.onap.so.objects.audit.AAIObjectAuditList) Before(org.junit.Before)

Example 15 with Vserver

use of org.onap.aai.domain.yang.Vserver in project so by onap.

the class ExceptionBuilderTest method before.

@Before
public void before() throws BBObjectNotFoundException, JsonProcessingException {
    setCloudRegion();
    when(extractPojosForBB.extractByKey(any(), ArgumentMatchers.eq(ResourceKey.VF_MODULE_ID))).thenReturn(buildVfModule());
    AAIObjectAuditList auditList = new AAIObjectAuditList();
    auditList.setAuditType("create");
    auditList.setHeatStackName("testStackName");
    AAIObjectAudit vserver = new AAIObjectAudit();
    vserver.setAaiObjectType(Types.VSERVER.typeName());
    vserver.setDoesObjectExist(false);
    Vserver vs = new Vserver();
    vs.setVserverId("testVServerId");
    Vserver vServerShallow = new Vserver();
    BeanUtils.copyProperties(vs, vServerShallow, "LInterfaces");
    vserver.setAaiObject(vServerShallow);
    auditList.getAuditList().add(vserver);
    execution.setVariable("auditInventoryResult", objectMapper.getMapper().writeValueAsString(auditList));
}
Also used : Vserver(org.onap.aai.domain.yang.Vserver) AAIObjectAudit(org.onap.so.objects.audit.AAIObjectAudit) AAIObjectAuditList(org.onap.so.objects.audit.AAIObjectAuditList) Before(org.junit.Before)

Aggregations

Vserver (org.onap.aai.domain.yang.Vserver)16 AAIResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri)10 AAIResultWrapper (org.onap.aaiclient.client.aai.entities.AAIResultWrapper)8 ArrayList (java.util.ArrayList)7 List (java.util.List)6 Logger (org.slf4j.Logger)6 HashMap (java.util.HashMap)5 Collectors (java.util.stream.Collectors)5 RelationshipList (org.onap.aai.domain.yang.RelationshipList)5 AAIResourcesClient (org.onap.aaiclient.client.aai.AAIResourcesClient)5 Types (org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 Preconditions (com.google.common.base.Preconditions)4 Map (java.util.Map)4 Optional (java.util.Optional)4 CollectionUtils (org.apache.commons.collections.CollectionUtils)4 StringUtils (org.apache.commons.lang3.StringUtils)4 Flavor (org.onap.aai.domain.yang.Flavor)4 Image (org.onap.aai.domain.yang.Image)4 L3Network (org.onap.aai.domain.yang.L3Network)4