Search in sources :

Example 1 with Vnfc

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

the class WorkflowAction method getConfigBuildingBlocks.

protected List<ExecuteBuildingBlock> getConfigBuildingBlocks(ConfigBuildingBlocksDataObject dataObj) throws AAIEntityNotFoundException, VnfcMultipleRelationshipException {
    List<ExecuteBuildingBlock> flowsToExecuteConfigs = new ArrayList<>();
    List<OrchestrationFlow> result = dataObj.getOrchFlows().stream().filter(item -> item.getFlowName().contains(FABRIC_CONFIGURATION)).collect(Collectors.toList());
    String vnfId = dataObj.getWorkflowResourceIds().getVnfId();
    String vfModuleId = dataObj.getWorkflowResourceIds().getVfModuleId();
    String vnfCustomizationUUID = bbInputSetupUtils.getAAIGenericVnf(vnfId).getModelCustomizationId();
    String vfModuleCustomizationUUID;
    org.onap.aai.domain.yang.VfModule aaiVfModule = bbInputSetupUtils.getAAIVfModule(vnfId, vfModuleId);
    if (aaiVfModule == null) {
        logger.error("No matching VfModule is found in Generic-Vnf in AAI for vnfId: {} and vfModuleId : {}", vnfId, vfModuleId);
        throw new AAIEntityNotFoundException("No matching VfModule is found in Generic-Vnf in AAI for vnfId: " + vnfId + " and vfModuleId : " + vfModuleId);
    } else {
        vfModuleCustomizationUUID = aaiVfModule.getModelCustomizationId();
    }
    String replaceVfModuleCustomizationUUID = "";
    String replaceVnfModuleCustomizationUUID = "";
    boolean isReplace = false;
    if (dataObj.getRequestAction().equalsIgnoreCase("replaceInstance") || dataObj.getRequestAction().equalsIgnoreCase("replaceInstanceRetainAssignments")) {
        for (RelatedInstanceList relatedInstList : dataObj.getRequestDetails().getRelatedInstanceList()) {
            RelatedInstance relatedInstance = relatedInstList.getRelatedInstance();
            if (relatedInstance.getModelInfo().getModelType().equals(ModelType.vnf)) {
                replaceVnfModuleCustomizationUUID = relatedInstance.getModelInfo().getModelCustomizationId();
            }
        }
        replaceVfModuleCustomizationUUID = dataObj.getRequestDetails().getModelInfo().getModelCustomizationId();
        isReplace = true;
    }
    List<org.onap.aai.domain.yang.Vnfc> vnfcs = getRelatedResourcesInVfModule(vnfId, vfModuleId, org.onap.aai.domain.yang.Vnfc.class, Types.VNFC);
    for (org.onap.aai.domain.yang.Vnfc vnfc : vnfcs) {
        WorkflowResourceIds workflowIdsCopy = SerializationUtils.clone(dataObj.getWorkflowResourceIds());
        org.onap.aai.domain.yang.Configuration configuration = getRelatedResourcesInVnfc(vnfc, org.onap.aai.domain.yang.Configuration.class, Types.CONFIGURATION);
        if (configuration == null) {
            logger.warn(String.format("No configuration found for VNFC %s in AAI", vnfc.getVnfcName()));
            continue;
        }
        workflowIdsCopy.setConfigurationId(configuration.getConfigurationId());
        for (OrchestrationFlow orchFlow : result) {
            if (!isReplace || (isReplace && (orchFlow.getFlowName().contains("Delete")))) {
                if (!isReplace) {
                    dataObj.getResourceKey().setVfModuleCustomizationId(vfModuleCustomizationUUID);
                    dataObj.getResourceKey().setVnfCustomizationId(vnfCustomizationUUID);
                } else {
                    if (orchFlow.getFlowName().contains("Delete")) {
                        dataObj.getResourceKey().setVfModuleCustomizationId(vfModuleCustomizationUUID);
                        dataObj.getResourceKey().setVnfCustomizationId(vnfCustomizationUUID);
                    } else {
                        dataObj.getResourceKey().setVfModuleCustomizationId(replaceVfModuleCustomizationUUID);
                        dataObj.getResourceKey().setVnfCustomizationId(replaceVnfModuleCustomizationUUID);
                    }
                }
                dataObj.getResourceKey().setCvnfModuleCustomizationId(vnfc.getModelCustomizationId());
                String vnfcName = vnfc.getVnfcName();
                if (vnfcName == null || vnfcName.isEmpty()) {
                    buildAndThrowException(dataObj.getExecution(), "Exception in create execution list " + ": VnfcName does not exist or is null while there is a configuration for the vfModule", new Exception("Vnfc and Configuration do not match"));
                }
                ExecuteBuildingBlock ebb = executeBuildingBlockBuilder.buildExecuteBuildingBlock(orchFlow, dataObj.getRequestId(), dataObj.getResourceKey(), dataObj.getApiVersion(), dataObj.getResourceId(), dataObj.getRequestAction(), dataObj.isaLaCarte(), dataObj.getVnfType(), workflowIdsCopy, dataObj.getRequestDetails(), false, null, vnfcName, true, null);
                flowsToExecuteConfigs.add(ebb);
            }
        }
    }
    return flowsToExecuteConfigs;
}
Also used : WorkflowResourceIds(org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds) Arrays(java.util.Arrays) BBConstants(org.onap.so.bpmn.common.BBConstants) AAIUriFactory(org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) Vnfc(org.onap.aai.domain.yang.Vnfc) ServiceEBBLoader(org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader.ServiceEBBLoader) CREATE_INSTANCE(org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.CREATE_INSTANCE) StringUtils(org.apache.commons.lang3.StringUtils) Matcher(java.util.regex.Matcher) ModelInfo(org.onap.so.serviceinstancebeans.ModelInfo) Map(java.util.Map) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) VnfEBBLoader(org.onap.so.bpmn.infrastructure.workflow.tasks.ebb.loader.VnfEBBLoader) UPGRADE_CNF(org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.UPGRADE_CNF) BBInputSetupUtils(org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetupUtils) VnfcMultipleRelationshipException(org.onap.so.bpmn.infrastructure.workflow.tasks.excpetion.VnfcMultipleRelationshipException) WORKFLOW_ACTION_ERROR_MESSAGE(org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.WORKFLOW_ACTION_ERROR_MESSAGE) DelegateExecution(org.camunda.bpm.engine.delegate.DelegateExecution) FABRIC_CONFIGURATION(org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.FABRIC_CONFIGURATION) BBInputSetup(org.onap.so.bpmn.servicedecomposition.tasks.BBInputSetup) Set(java.util.Set) UUID(java.util.UUID) ASSIGN_INSTANCE(org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.ASSIGN_INSTANCE) Collectors(java.util.stream.Collectors) Pair(org.javatuples.Pair) CatalogDbClient(org.onap.so.db.catalog.client.CatalogDbClient) RelatedInstance(org.onap.so.serviceinstancebeans.RelatedInstance) HEALTH_CHECK(org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.HEALTH_CHECK) List(java.util.List) RelatedInstanceList(org.onap.so.serviceinstancebeans.RelatedInstanceList) RECREATE_INSTANCE(org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.RECREATE_INSTANCE) AAIObjectName(org.onap.aaiclient.client.aai.AAIObjectName) Environment(org.springframework.core.env.Environment) CollectionUtils(org.springframework.util.CollectionUtils) ModelType(org.onap.so.serviceinstancebeans.ModelType) Optional(java.util.Optional) Relationships(org.onap.aaiclient.client.aai.entities.Relationships) Pattern(java.util.regex.Pattern) WorkflowResourceIdsUtils(org.onap.so.bpmn.infrastructure.workflow.tasks.utils.WorkflowResourceIdsUtils) VolumeGroup(org.onap.aai.domain.yang.VolumeGroup) Types(org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder.Types) CloudConfiguration(org.onap.so.serviceinstancebeans.CloudConfiguration) DELETE_INSTANCE(org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.DELETE_INSTANCE) HashMap(java.util.HashMap) SerializationUtils(org.apache.commons.lang3.SerializationUtils) UPDATE_INSTANCE(org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.UPDATE_INSTANCE) ArrayList(java.util.ArrayList) ExceptionBuilder(org.onap.so.client.exception.ExceptionBuilder) ServiceInstancesRequest(org.onap.so.serviceinstancebeans.ServiceInstancesRequest) AAIResultWrapper(org.onap.aaiclient.client.aai.entities.AAIResultWrapper) LinkedHashSet(java.util.LinkedHashSet) VfModuleCustomization(org.onap.so.db.catalog.beans.VfModuleCustomization) REPLACEINSTANCE(org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.REPLACEINSTANCE) Logger(org.slf4j.Logger) AAIFluentTypeBuilder(org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder) AAIEntityNotFoundException(org.onap.so.client.orchestration.AAIEntityNotFoundException) AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) REPLACEINSTANCERETAINASSIGNMENTS(org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.REPLACEINSTANCERETAINASSIGNMENTS) SERVICE(org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.SERVICE) Component(org.springframework.stereotype.Component) NorthBoundRequest(org.onap.so.db.catalog.beans.macro.NorthBoundRequest) RequestDetails(org.onap.so.serviceinstancebeans.RequestDetails) OrchestrationFlow(org.onap.so.db.catalog.beans.macro.OrchestrationFlow) Comparator(java.util.Comparator) CONTROLLER(org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowActionConstants.CONTROLLER) RelatedInstanceList(org.onap.so.serviceinstancebeans.RelatedInstanceList) RelatedInstance(org.onap.so.serviceinstancebeans.RelatedInstance) ArrayList(java.util.ArrayList) OrchestrationFlow(org.onap.so.db.catalog.beans.macro.OrchestrationFlow) Vnfc(org.onap.aai.domain.yang.Vnfc) AAIEntityNotFoundException(org.onap.so.client.orchestration.AAIEntityNotFoundException) VnfcMultipleRelationshipException(org.onap.so.bpmn.infrastructure.workflow.tasks.excpetion.VnfcMultipleRelationshipException) AAIEntityNotFoundException(org.onap.so.client.orchestration.AAIEntityNotFoundException) IOException(java.io.IOException) WorkflowResourceIds(org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds) ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) Vnfc(org.onap.aai.domain.yang.Vnfc)

Example 2 with Vnfc

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

the class WorkflowActionBBTasks method postProcessingExecuteBBActivateVfModule.

protected void postProcessingExecuteBBActivateVfModule(DelegateExecution execution, ExecuteBuildingBlock ebb, List<ExecuteBuildingBlock> flowsToExecute) {
    try {
        String requestAction = (String) execution.getVariable(BBConstants.G_ACTION);
        String serviceInstanceId = ebb.getWorkflowResourceIds().getServiceInstanceId();
        String vnfId = ebb.getWorkflowResourceIds().getVnfId();
        String vfModuleId = ebb.getResourceId();
        ebb.getWorkflowResourceIds().setVfModuleId(vfModuleId);
        String serviceModelUUID = "";
        String vnfCustomizationUUID = "";
        String vfModuleCustomizationUUID = "";
        if (requestAction.equalsIgnoreCase("replaceInstance") || requestAction.equalsIgnoreCase("replaceInstanceRetainAssignments")) {
            for (RelatedInstanceList relatedInstList : ebb.getRequestDetails().getRelatedInstanceList()) {
                RelatedInstance relatedInstance = relatedInstList.getRelatedInstance();
                if (relatedInstance.getModelInfo().getModelType().equals(ModelType.vnf)) {
                    vnfCustomizationUUID = relatedInstance.getModelInfo().getModelCustomizationId();
                }
                if (relatedInstance.getModelInfo().getModelType().equals(ModelType.service)) {
                    serviceModelUUID = relatedInstance.getModelInfo().getModelVersionId();
                }
            }
            vfModuleCustomizationUUID = ebb.getRequestDetails().getModelInfo().getModelCustomizationId();
        } else {
            serviceModelUUID = bbInputSetupUtils.getAAIServiceInstanceById(serviceInstanceId).getModelVersionId();
            vnfCustomizationUUID = bbInputSetupUtils.getAAIGenericVnf(vnfId).getModelCustomizationId();
            vfModuleCustomizationUUID = bbInputSetupUtils.getAAIVfModule(vnfId, vfModuleId).getModelCustomizationId();
        }
        List<Vnfc> vnfcs = workflowAction.getRelatedResourcesInVfModule(vnfId, vfModuleId, Vnfc.class, Types.VNFC);
        logger.debug("Vnfc Size: {}", vnfcs.size());
        for (Vnfc vnfc : vnfcs) {
            String modelCustomizationId = vnfc.getModelCustomizationId();
            logger.debug("Processing Vnfc: {}", modelCustomizationId);
            CvnfcConfigurationCustomization fabricConfig = catalogDbClient.getCvnfcCustomization(serviceModelUUID, vnfCustomizationUUID, vfModuleCustomizationUUID, modelCustomizationId);
            if (fabricConfig != null && fabricConfig.getConfigurationResource() != null && fabricConfig.getConfigurationResource().getToscaNodeType() != null && fabricConfig.getConfigurationResource().getToscaNodeType().contains(FABRIC_CONFIGURATION)) {
                String configurationId = getConfigurationId(vnfc);
                ConfigurationResourceKeys configurationResourceKeys = new ConfigurationResourceKeys();
                configurationResourceKeys.setCvnfcCustomizationUUID(modelCustomizationId);
                configurationResourceKeys.setVfModuleCustomizationUUID(vfModuleCustomizationUUID);
                configurationResourceKeys.setVnfResourceCustomizationUUID(vnfCustomizationUUID);
                configurationResourceKeys.setVnfcName(vnfc.getVnfcName());
                ExecuteBuildingBlock addConfigBB = getExecuteBBForConfig(ADD_FABRIC_CONFIGURATION_BB, ebb, configurationId, configurationResourceKeys);
                flowsToExecute.add(addConfigBB);
                flowsToExecute.stream().forEach(executeBB -> logger.info("Flows to Execute After Post Processing: {}", executeBB.getBuildingBlock().getBpmnFlowName()));
                execution.setVariable("flowsToExecute", flowsToExecute);
                execution.setVariable(COMPLETED, false);
            } else {
                logger.debug("No cvnfcCustomization found for customizationId: {}", modelCustomizationId);
            }
        }
    } catch (EntityNotFoundException e) {
        logger.debug("Will not be running Fabric Config Building Blocks", e);
    } catch (Exception e) {
        String errorMessage = "Error occurred in post processing of Vf Module create";
        execution.setVariable(HANDLINGCODE, ROLLBACKTOCREATED);
        execution.setVariable("WorkflowActionErrorMessage", errorMessage);
        logger.error(errorMessage, e);
    }
}
Also used : ExecuteBuildingBlock(org.onap.so.bpmn.servicedecomposition.entities.ExecuteBuildingBlock) RelatedInstanceList(org.onap.so.serviceinstancebeans.RelatedInstanceList) RelatedInstance(org.onap.so.serviceinstancebeans.RelatedInstance) ConfigurationResourceKeys(org.onap.so.bpmn.servicedecomposition.entities.ConfigurationResourceKeys) CvnfcConfigurationCustomization(org.onap.so.db.catalog.beans.CvnfcConfigurationCustomization) EntityNotFoundException(javax.persistence.EntityNotFoundException) Vnfc(org.onap.aai.domain.yang.Vnfc) EntityNotFoundException(javax.persistence.EntityNotFoundException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 3 with Vnfc

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

the class ProcessVnfc method doExecute.

@Override
public void doExecute(TestContext context) {
    final Logger logger = LoggerFactory.getLogger(ProcessVnfc.class);
    try {
        logger.debug("running ProcessVnfc scenario");
        logger.debug("requestAction: {}", context.getVariable("requestAction"));
        logger.debug("serviceAction: {}", context.getVariable("serviceAction"));
        logger.debug("cloudOwner: {}", context.getVariable("cloudOwner"));
        logger.debug("cloundRegion: {}", context.getVariable("cloudRegion"));
        logger.debug("tenant: {}", context.getVariable("tenant"));
        logger.debug("vfModuleId: {}", context.getVariable("vfModuleId"));
        logger.debug("vnfId: {}", context.getVariable("vnfId"));
        AAIResourcesClient aaiResourceClient = new AAIResourcesClient();
        if (context.getVariable("requestAction").equals("CreateVfModuleInstance") && context.getVariable("serviceAction").equals("assign")) {
            AAIResourceUri vnfcURI = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().vnfc(VNF_SERVER_1_NAME));
            Vnfc vnfc = new Vnfc();
            vnfc.setVnfcName(VNF_SERVER_1_NAME);
            vnfc.setNfcNamingCode("oamfw");
            vnfc.setNfcFunction("EPC-OAM-FIREWALL");
            vnfc.setProvStatus("PREPROV");
            vnfc.setOrchestrationStatus("Active");
            vnfc.setInMaint(false);
            vnfc.setIsClosedLoopDisabled(false);
            vnfc.setModelInvariantId("b214d2e9-73d9-49d7-b7c4-a9ae7f06e244");
            vnfc.setModelVersionId("9e314c37-2258-4572-a399-c0dd7d5f1aec");
            vnfc.setModelCustomizationId("2bd95cd4-d7ff-4af0-985d-2adea0339921");
            AAIResourceUri vfModuleURI = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().genericVnf(context.getVariable("vnfId")).vfModule(context.getVariable("vfModuleId")));
            if (aaiResourceClient.exists(vnfcURI)) {
                Optional<VfModule> vfModule = aaiResourceClient.get(vfModuleURI).asBean(VfModule.class);
                if (vfModule.isPresent() && vfModule.get().getVfModuleName().contains("macro")) {
                    String vnfcName = VNF_SERVER_1_NAME + vfModule.get().getVfModuleName().substring(vfModule.get().getVfModuleName().length() - 1);
                    vnfc.setVnfcName(vnfcName);
                    vnfcURI = AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().vnfc(vnfcName));
                } else {
                    logger.debug("cleaning up VNFC");
                    aaiResourceClient.delete(vnfcURI);
                }
            }
            logger.debug("creating new VNFC");
            aaiResourceClient.create(vnfcURI, vnfc);
            logger.debug("creating VNFC edge to vf module");
            aaiResourceClient.connect(vfModuleURI, vnfcURI);
        }
    } catch (Exception e) {
        logger.debug("Exception in ProcessVnfc.doExecute", e);
    }
}
Also used : AAIResourceUri(org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri) Logger(org.slf4j.Logger) AAIResourcesClient(org.onap.aaiclient.client.aai.AAIResourcesClient) Vnfc(org.onap.aai.domain.yang.Vnfc) VfModule(org.onap.aai.domain.yang.VfModule)

Aggregations

Vnfc (org.onap.aai.domain.yang.Vnfc)3 AAIResourceUri (org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1 UUID (java.util.UUID)1 Matcher (java.util.regex.Matcher)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1 EntityNotFoundException (javax.persistence.EntityNotFoundException)1 SerializationUtils (org.apache.commons.lang3.SerializationUtils)1