Search in sources :

Example 1 with GraphInventoryCommonObjectMapperProvider

use of org.onap.aaiclient.client.graphinventory.GraphInventoryCommonObjectMapperProvider in project so by onap.

the class CreateInventoryTaskTest method testExecuteExternalTask_InventoryException.

@Test
public void testExecuteExternalTask_InventoryException() throws InventoryException, JsonProcessingException {
    AAIObjectAuditList object = new AAIObjectAuditList();
    AAIObjectAudit e = new AAIObjectAudit();
    e.setDoesObjectExist(true);
    object.getAuditList().add(e);
    GraphInventoryCommonObjectMapperProvider objectMapper = new GraphInventoryCommonObjectMapperProvider();
    doReturn(objectMapper.getMapper().writeValueAsString(e)).when(externalTask).getVariable("auditInventoryResult");
    inventoryTask.executeExternalTask(externalTask, externalTaskService);
    Mockito.verify(externalTaskService, times(1)).handleBpmnError(externalTask, "AAIInventoryFailure");
}
Also used : GraphInventoryCommonObjectMapperProvider(org.onap.aaiclient.client.graphinventory.GraphInventoryCommonObjectMapperProvider) AAIObjectAudit(org.onap.so.objects.audit.AAIObjectAudit) AAIObjectAuditList(org.onap.so.objects.audit.AAIObjectAuditList) Test(org.junit.Test)

Example 2 with GraphInventoryCommonObjectMapperProvider

use of org.onap.aaiclient.client.graphinventory.GraphInventoryCommonObjectMapperProvider in project so by onap.

the class ApplicationControllerTaskImpl method execute.

public Status execute(String msoRequestId, ApplicationControllerTaskRequest request, ApplicationControllerCallback listener) throws JsonProcessingException, ApplicationControllerOrchestratorException {
    Status status = null;
    GraphInventoryCommonObjectMapperProvider mapper = new GraphInventoryCommonObjectMapperProvider();
    Optional<String> payload = Optional.empty();
    String vmId = null;
    Optional<String> vserverId = Optional.empty();
    Parameters parameters = new Parameters();
    ConfigurationParameters configParams = new ConfigurationParameters();
    RequestParameters requestParams = new RequestParameters();
    switch(request.getAction()) {
        case HealthCheck:
            requestParams.setHostIpAddress(request.getApplicationControllerVnf().getVnfHostIpAddress());
            parameters.setRequestParameters(requestParams);
            payload = Optional.of((mapper.getMapper().writeValueAsString(parameters)));
            break;
        case ResumeTraffic:
            configParams.setVnfName(request.getApplicationControllerVnf().getVnfName());
            parameters.setConfigurationParameters(configParams);
            payload = Optional.of((mapper.getMapper().writeValueAsString(parameters)));
            break;
        case Start:
        case Stop:
            Identity identity = new Identity();
            identity.setIdentityUrl(request.getIdentityUrl());
            payload = Optional.of((mapper.getMapper().writeValueAsString(identity)));
            break;
        case Unlock:
        case Lock:
            break;
        case QuiesceTraffic:
            parameters.setOperationsTimeout(request.getOperationsTimeout());
            payload = Optional.of((mapper.getMapper().writeValueAsString(parameters)));
            break;
        case DistributeTraffic:
            configParams.setBookName(request.getBookName());
            configParams.setNodeList(request.getNodeList());
            configParams.setFileParameterContent(request.getFileParameters());
            configParams.setVnfName(request.getApplicationControllerVnf().getVnfName());
            parameters.setConfigurationParameters(configParams);
            payload = Optional.of((mapper.getMapper().writeValueAsString(parameters)));
            break;
        case DistributeTrafficCheck:
            configParams.setBookName(request.getBookName());
            configParams.setNodeList(request.getNodeList());
            configParams.setFileParameterContent(request.getFileParameters());
            configParams.setVnfName(request.getApplicationControllerVnf().getVnfName());
            parameters.setConfigurationParameters(configParams);
            payload = Optional.of((mapper.getMapper().writeValueAsString(parameters)));
            break;
        case ConfigModify:
            requestParams.setHostIpAddress(request.getApplicationControllerVnf().getVnfHostIpAddress());
            configParams.setAdditionalProperties(request.getConfigParams());
            parameters.setRequestParameters(requestParams);
            parameters.setConfigurationParameters(configParams);
            payload = Optional.of((mapper.getMapper().writeValueAsString(parameters)));
            break;
        case ConfigScaleOut:
            break;
        case UpgradePreCheck:
        case UpgradePostCheck:
        case UpgradeSoftware:
        case UpgradeBackup:
            parameters.setExistingSoftwareVersion(request.getExistingSoftwareVersion());
            parameters.setNewSoftwareVersion(request.getNewSoftwareVersion());
            payload = Optional.of((mapper.getMapper().writeValueAsString(parameters)));
            break;
        case ActionStatus:
            break;
        case Snapshot:
            ApplicationControllerVm applicationControllerVm = request.getApplicationControllerVnf().getApplicationControllerVm();
            if (applicationControllerVm != null) {
                vmId = request.getApplicationControllerVnf().getApplicationControllerVm().getVmId();
                parameters.setVmId(vmId);
                payload = Optional.of((mapper.getMapper().writeValueAsString(parameters)));
                vserverId = Optional.of(request.getApplicationControllerVnf().getApplicationControllerVm().getVserverId());
            }
            break;
        default:
            // errorMessage = "Unable to idenify Action request for AppCClient";
            break;
    }
    status = appcClient.vnfCommand(request.getAction(), msoRequestId, request.getApplicationControllerVnf().getVnfId(), vserverId, payload, request.getControllerType(), listener, request.getRequestorId());
    return status;
}
Also used : Status(org.onap.appc.client.lcm.model.Status) ApplicationControllerVm(org.onap.so.appc.orchestrator.service.beans.ApplicationControllerVm) Parameters(org.onap.so.adapters.appc.orchestrator.client.beans.Parameters) RequestParameters(org.onap.so.adapters.appc.orchestrator.client.beans.RequestParameters) ConfigurationParameters(org.onap.so.adapters.appc.orchestrator.client.beans.ConfigurationParameters) GraphInventoryCommonObjectMapperProvider(org.onap.aaiclient.client.graphinventory.GraphInventoryCommonObjectMapperProvider) ConfigurationParameters(org.onap.so.adapters.appc.orchestrator.client.beans.ConfigurationParameters) Identity(org.onap.so.adapters.appc.orchestrator.client.beans.Identity) RequestParameters(org.onap.so.adapters.appc.orchestrator.client.beans.RequestParameters)

Example 3 with GraphInventoryCommonObjectMapperProvider

use of org.onap.aaiclient.client.graphinventory.GraphInventoryCommonObjectMapperProvider 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 4 with GraphInventoryCommonObjectMapperProvider

use of org.onap.aaiclient.client.graphinventory.GraphInventoryCommonObjectMapperProvider 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)

Aggregations

GraphInventoryCommonObjectMapperProvider (org.onap.aaiclient.client.graphinventory.GraphInventoryCommonObjectMapperProvider)4 AAIObjectAudit (org.onap.so.objects.audit.AAIObjectAudit)3 AAIObjectAuditList (org.onap.so.objects.audit.AAIObjectAuditList)3 Vserver (org.onap.aai.domain.yang.Vserver)2 IOException (java.io.IOException)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Stream (java.util.stream.Stream)1 BpmnError (org.camunda.bpm.engine.delegate.BpmnError)1 DelegateExecution (org.camunda.bpm.engine.delegate.DelegateExecution)1 Before (org.junit.Before)1 Test (org.junit.Test)1 LInterface (org.onap.aai.domain.yang.LInterface)1 Types (org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types)1 Status (org.onap.appc.client.lcm.model.Status)1 ErrorCode (org.onap.logging.filter.base.ErrorCode)1 ONAPComponents (org.onap.logging.filter.base.ONAPComponents)1 ONAPComponentsList (org.onap.logging.filter.base.ONAPComponentsList)1 ConfigurationParameters (org.onap.so.adapters.appc.orchestrator.client.beans.ConfigurationParameters)1 Identity (org.onap.so.adapters.appc.orchestrator.client.beans.Identity)1