Search in sources :

Example 1 with ISdcCsarHelper

use of org.onap.sdc.tosca.parser.api.ISdcCsarHelper in project so by onap.

the class ToscaResourceInstaller method getServiceInput.

private String getServiceInput(ToscaResourceStructure toscaResourceStructure) {
    String serviceInput = null;
    List<Object> serviceInputList;
    ISdcCsarHelper sdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
    List<Input> serviceInputs = sdcCsarHelper.getServiceInputs();
    if (!serviceInputs.isEmpty()) {
        serviceInputList = new ArrayList<>();
        List<Input> filterList;
        filterList = serviceInputs.stream().filter(input -> !SKIP_POST_INST_CONF.equals(input.getName()) && !CDS_MODEL_NAME.equalsIgnoreCase(input.getName()) && !CDS_MODEL_VERSION.equalsIgnoreCase(input.getName()) && !CONTROLLER_ACTOR.equalsIgnoreCase(input.getName())).collect(Collectors.toList());
        filterList.forEach(input -> {
            Map<String, Object> serviceInputMap = new HashMap<>();
            serviceInputMap.put("name", input.getName());
            serviceInputMap.put("type", input.getType());
            serviceInputMap.put("default", input.getDefault() == null ? "" : input.getDefault());
            serviceInputMap.put("required", input.isRequired());
            serviceInputList.add(serviceInputMap);
        });
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            serviceInput = objectMapper.writeValueAsString(serviceInputList);
            serviceInput = serviceInput.replace("\"", "\\\"");
        } catch (JsonProcessingException e) {
            logger.error("service input could not be deserialized for service uuid:  " + sdcCsarHelper.getServiceMetadata().getValue(SdcPropertyNames.PROPERTY_NAME_UUID));
        }
    } else {
        logger.debug("serviceInput is null");
    }
    return serviceInput;
}
Also used : Input(org.onap.sdc.toscaparser.api.parameters.Input) GetInput(org.onap.sdc.toscaparser.api.functions.GetInput) ISdcCsarHelper(org.onap.sdc.tosca.parser.api.ISdcCsarHelper) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 2 with ISdcCsarHelper

use of org.onap.sdc.tosca.parser.api.ISdcCsarHelper in project so by onap.

the class ToscaResourceInstaller method getServiceProperties.

private String getServiceProperties(ToscaResourceStructure toscaResourceStruct) {
    String propertiesJson = null;
    ObjectMapper objectMapper = new ObjectMapper();
    ISdcCsarHelper helper = toscaResourceStruct.getSdcCsarHelper();
    String typeName = helper.getServiceSubstitutionMappingsTypeName();
    Optional<NodeTemplate> nodeTemplate = helper.getServiceNodeTemplates().stream().findAny();
    if (nodeTemplate.isPresent()) {
        String serviceUUID = nodeTemplate.get().getMetaData().getValue(SdcPropertyNames.PROPERTY_NAME_UUID);
        LinkedHashMap<String, Object> customDef = nodeTemplate.get().getCustomDef();
        List<Object> serviceProperties = getPropertiesFromCustomDef(customDef, typeName);
        try {
            propertiesJson = objectMapper.writeValueAsString(serviceProperties);
            propertiesJson = propertiesJson.replace("\"", "\\\"");
        } catch (JsonProcessingException e) {
            logger.error("serviceProperties could not be deserialized for service uuid:  " + serviceUUID);
        } catch (Exception ex) {
            logger.error("service properties parsing failed. service uuid:" + serviceUUID);
        }
    } else {
        logger.debug("ServiceNodeTemplates is null");
    }
    return propertiesJson;
}
Also used : NodeTemplate(org.onap.sdc.toscaparser.api.NodeTemplate) ISdcCsarHelper(org.onap.sdc.tosca.parser.api.ISdcCsarHelper) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ObjectOptimisticLockingFailureException(org.springframework.orm.ObjectOptimisticLockingFailureException) LockAcquisitionException(org.hibernate.exception.LockAcquisitionException) ArtifactInstallerException(org.onap.so.asdc.client.exceptions.ArtifactInstallerException) ConstraintViolationException(org.hibernate.exception.ConstraintViolationException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 3 with ISdcCsarHelper

use of org.onap.sdc.tosca.parser.api.ISdcCsarHelper in project so by onap.

the class ToscaResourceInstaller method processPnfResources.

/**
 * This is used to process the PNF specific resource, including resource and resource_customization.
 * {@link IEntityDetails} based API is used to retrieve information. Please check {@link ISdcCsarHelper} for
 * details.
 */
protected void processPnfResources(ToscaResourceStructure toscaResourceStruct, Service service, PnfResourceStructure resourceStructure) throws Exception {
    logger.info("Processing PNF resource: {}", resourceStructure.getResourceInstance().getResourceUUID());
    ISdcCsarHelper sdcCsarHelper = toscaResourceStruct.getSdcCsarHelper();
    EntityQuery entityQuery = EntityQuery.newBuilder(SdcTypes.PNF).build();
    TopologyTemplateQuery topologyTemplateQuery = TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE).build();
    List<IEntityDetails> entityDetailsList = sdcCsarHelper.getEntity(entityQuery, topologyTemplateQuery, false);
    for (IEntityDetails entityDetails : entityDetailsList) {
        Metadata metadata = entityDetails.getMetadata();
        String customizationUUID = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
        String modelUuid = metadata.getValue(SdcPropertyNames.PROPERTY_NAME_UUID);
        String notifCustomizationUUID = resourceStructure.getResourceInstance().getResourceCustomizationUUID();
        if (customizationUUID != null && customizationUUID.equals(notifCustomizationUUID)) {
            logger.info("Resource customization UUID: {} is the same as notified resource customizationUUID: {}", customizationUUID, notifCustomizationUUID);
            if (checkExistingPnfResourceCutomization(customizationUUID)) {
                logger.info("Resource customization UUID: {} already deployed", customizationUUID);
            } else {
                PnfResource pnfResource = findExistingPnfResource(service, modelUuid);
                if (pnfResource == null) {
                    pnfResource = createPnfResource(entityDetails);
                }
                PnfResourceCustomization pnfResourceCustomization = createPnfResourceCustomization(entityDetails, pnfResource);
                pnfResource.getPnfResourceCustomizations().add(pnfResourceCustomization);
                toscaResourceStruct.setPnfResourceCustomization(pnfResourceCustomization);
                service.getPnfCustomizations().add(pnfResourceCustomization);
            }
        } else {
            logger.warn("Resource customization UUID: {} is NOT the same as notified resource customizationUUID: {}", customizationUUID, notifCustomizationUUID);
        }
    }
}
Also used : IEntityDetails(org.onap.sdc.tosca.parser.api.IEntityDetails) PnfResourceCustomization(org.onap.so.db.catalog.beans.PnfResourceCustomization) TopologyTemplateQuery(org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery) ISdcCsarHelper(org.onap.sdc.tosca.parser.api.ISdcCsarHelper) PnfResource(org.onap.so.db.catalog.beans.PnfResource) Metadata(org.onap.sdc.toscaparser.api.elements.Metadata) EntityQuery(org.onap.sdc.tosca.parser.elements.queries.EntityQuery)

Example 4 with ISdcCsarHelper

use of org.onap.sdc.tosca.parser.api.ISdcCsarHelper in project so by onap.

the class ToscaResourceInstaller method processResourceSequence.

// This method retrieve resource sequence from csar file
void processResourceSequence(ToscaResourceStructure toscaResourceStructure, Service service) {
    List<String> resouceSequence = new ArrayList<>();
    List<IEntityDetails> resultList = new ArrayList<>();
    ISdcCsarHelper iSdcCsarHelper = toscaResourceStructure.getSdcCsarHelper();
    List<IEntityDetails> vfEntityList = getEntityDetails(toscaResourceStructure, EntityQuery.newBuilder(EntityTemplateType.NODE_TEMPLATE), TopologyTemplateQuery.newBuilder(SdcTypes.SERVICE), false);
    List<IEntityDetails> entities = new ArrayList<>();
    entities.addAll(vfEntityList);
    for (IEntityDetails entityDetails : vfEntityList) {
        List<RequirementAssignment> requirements = entityDetails.getRequirements();
        if (requirements == null || requirements.isEmpty()) {
            resultList.add(entityDetails);
            entities.remove(entityDetails);
        }
    }
    resultList = getRequirementList(resultList, entities, iSdcCsarHelper);
    for (IEntityDetails entity : resultList) {
        String templateName = entity.getMetadata().getValue("name");
        if (!resouceSequence.contains(templateName)) {
            resouceSequence.add(templateName);
        }
    }
    String resourceSeqStr = resouceSequence.stream().collect(Collectors.joining(","));
    service.setResourceOrder(resourceSeqStr);
    logger.debug(" resourceSeq for service uuid {}: {}", service.getModelUUID(), resourceSeqStr);
}
Also used : IEntityDetails(org.onap.sdc.tosca.parser.api.IEntityDetails) ISdcCsarHelper(org.onap.sdc.tosca.parser.api.ISdcCsarHelper) ArrayList(java.util.ArrayList) RequirementAssignment(org.onap.sdc.toscaparser.api.RequirementAssignment)

Example 5 with ISdcCsarHelper

use of org.onap.sdc.tosca.parser.api.ISdcCsarHelper in project so by onap.

the class ToscaResourceInstallerTest method prepareToscaResourceStructure.

private ToscaResourceStructure prepareToscaResourceStructure(boolean prepareVFModuleStructures, ToscaResourceInstaller toscaInstaller) throws ArtifactInstallerException {
    Metadata metadata = mock(Metadata.class);
    IResourceInstance resourceInstance = mock(ResourceInstance.class);
    NodeTemplate nodeTemplate = mock(NodeTemplate.class);
    ISdcCsarHelper csarHelper = mock(SdcCsarHelperImpl.class);
    IArtifactInfo inputCsar = mock(IArtifactInfo.class);
    String artifactUuid = "0122c05e-e13a-4c63-b5d2-475ccf23aa74";
    String checkSum = "MGUzNjJjMzk3OTBkYzExYzQ0MDg2ZDc2M2E3ZjZiZmY=";
    doReturn(checkSum).when(inputCsar).getArtifactChecksum();
    doReturn(artifactUuid).when(inputCsar).getArtifactUUID();
    doReturn("1.0").when(inputCsar).getArtifactVersion();
    doReturn("TestCsarWithGroupAndVFModule").when(inputCsar).getArtifactName();
    doReturn("Test Csar data with Group and VF module inputs").when(inputCsar).getArtifactDescription();
    doReturn("http://localhost/dummy/url/test.csar").when(inputCsar).getArtifactURL();
    ToscaResourceStructure toscaResourceStructObj = new ToscaResourceStructure();
    toscaResourceStructObj.setToscaArtifact(inputCsar);
    ToscaCsarRepository toscaCsarRepo = spy(ToscaCsarRepository.class);
    ToscaCsar toscaCsar = mock(ToscaCsar.class);
    Optional<ToscaCsar> returnValue = Optional.of(toscaCsar);
    doReturn(artifactUuid).when(toscaCsar).getArtifactUUID();
    doReturn(checkSum).when(toscaCsar).getArtifactChecksum();
    doReturn(returnValue).when(toscaCsarRepo).findById(artifactUuid);
    ReflectionTestUtils.setField(toscaInstaller, "toscaCsarRepo", toscaCsarRepo);
    NotificationDataImpl notificationData = new NotificationDataImpl();
    notificationData.setDistributionID("testStatusSuccessfulTosca");
    notificationData.setServiceVersion("1234567");
    notificationData.setServiceUUID("serviceUUID1");
    notificationData.setWorkloadContext("workloadContext1");
    String serviceType = "test-type1";
    String serviceRole = "test-role1";
    String category = "Network L3+";
    String description = "Customer Orderable service description";
    String name = "Customer_Orderable_Service";
    String uuid = "72db5868-4575-4804-b546-0b0d3c3b5ac6";
    String invariantUUID = "6f30bbe3-4590-4185-a7e0-4f9610926c6f";
    String namingPolicy = "naming Policy1";
    String ecompGeneratedNaming = "true";
    String environmentContext = "General_Revenue-Bearing1";
    String resourceCustomizationUUID = "0177ba22-5547-4e4e-bcf8-178f7f71de3a";
    doReturn(serviceType).when(metadata).getValue("serviceType");
    doReturn(serviceRole).when(metadata).getValue("serviceRole");
    doReturn(category).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY);
    doReturn(description).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_DESCRIPTION);
    doReturn("1.0").when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_VERSION);
    doReturn(name).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_NAME);
    doReturn(uuid).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_UUID);
    doReturn(environmentContext).when(metadata).getValue(metadata.getValue("environmentContext"));
    doReturn(invariantUUID).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID);
    doReturn(namingPolicy).when(metadata).getValue("namingPolicy");
    doReturn(ecompGeneratedNaming).when(metadata).getValue("ecompGeneratedNaming");
    doReturn(resourceCustomizationUUID).when(metadata).getValue("vfModuleModelCustomizationUUID");
    ServiceRepository serviceRepo = spy(ServiceRepository.class);
    VnfResourceRepository vnfRepo = spy(VnfResourceRepository.class);
    doReturn(null).when(vnfRepo).findResourceByModelUUID(uuid);
    VFModuleRepository vfModuleRepo = spy(VFModuleRepository.class);
    InstanceGroupRepository instanceGroupRepo = spy(InstanceGroupRepository.class);
    WorkflowResource workflowResource = spy(WorkflowResource.class);
    ReflectionTestUtils.setField(toscaInstaller, "serviceRepo", serviceRepo);
    ReflectionTestUtils.setField(toscaInstaller, "vnfRepo", vnfRepo);
    ReflectionTestUtils.setField(toscaInstaller, "vfModuleRepo", vfModuleRepo);
    ReflectionTestUtils.setField(toscaInstaller, "instanceGroupRepo", instanceGroupRepo);
    ReflectionTestUtils.setField(toscaInstaller, "workflowResource", workflowResource);
    // doReturn(csarHelper).when(toscaResourceStructure).getSdcCsarHelper();
    toscaResourceStructObj.setSdcCsarHelper(csarHelper);
    doReturn(resourceCustomizationUUID).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_CUSTOMIZATIONUUID);
    doReturn(uuid).when(metadata).getValue(SdcPropertyNames.PROPERTY_NAME_VFMODULEMODELUUID);
    // vnfc instance group list
    List<Group> vnfcInstanceGroupList = new ArrayList<>();
    Group vnfcG1 = mock(Group.class);
    Map<String, Object> metaProperties = new HashMap<>();
    metaProperties.put(SdcPropertyNames.PROPERTY_NAME_UUID, "vnfc_group1_uuid");
    metaProperties.put(SdcPropertyNames.PROPERTY_NAME_NAME, "vnfc_group1_uuid");
    metaProperties.put(SdcPropertyNames.PROPERTY_NAME_INVARIANTUUID, "vnfc_group1_invariantid");
    metaProperties.put(SdcPropertyNames.PROPERTY_NAME_VERSION, "1.0");
    Metadata vnfcmetadata = new Metadata(metaProperties);
    doReturn(vnfcmetadata).when(vnfcG1).getMetadata();
    ArrayList<NodeTemplate> memberList = new ArrayList();
    doReturn(memberList).when(vnfcG1).getMemberNodes();
    vnfcInstanceGroupList.add(vnfcG1);
    SubstitutionMappings submappings = mock(SubstitutionMappings.class);
    doReturn(new ArrayList<Input>()).when(submappings).getInputs();
    doReturn(submappings).when(nodeTemplate).getSubMappingToscaTemplate();
    doReturn(notificationData).when(vfResourceStruct).getNotification();
    doReturn(resourceInstance).when(vfResourceStruct).getResourceInstance();
    if (prepareVFModuleStructures) {
        // VfModule list
        List<Group> vfModuleGroups = new ArrayList<>();
        Group g1 = mock(Group.class);
        doReturn(metadata).when(g1).getMetadata();
        vfModuleGroups.add(g1);
        doReturn(metadata).when(nodeTemplate).getMetaData();
        List<NodeTemplate> nodeList = new ArrayList<>();
        nodeList.add(nodeTemplate);
        IVfModuleData moduleMetadata = mock(IVfModuleData.class);
        doReturn(name).when(moduleMetadata).getVfModuleModelName();
        doReturn(invariantUUID).when(moduleMetadata).getVfModuleModelInvariantUUID();
        doReturn(Collections.<String>emptyList()).when(moduleMetadata).getArtifacts();
        doReturn(resourceCustomizationUUID).when(moduleMetadata).getVfModuleModelCustomizationUUID();
        doReturn(uuid).when(moduleMetadata).getVfModuleModelUUID();
        doReturn("1.0").when(moduleMetadata).getVfModuleModelVersion();
        VfModuleStructure moduleStructure = new VfModuleStructure(vfResourceStruct, moduleMetadata);
        List<VfModuleStructure> moduleStructures = new ArrayList<>();
        moduleStructures.add(moduleStructure);
        doReturn(moduleStructures).when(vfResourceStruct).getVfModuleStructure();
    }
    toscaResourceStructObj.setServiceMetadata(metadata);
    doReturn("resourceInstanceName1").when(resourceInstance).getResourceInstanceName();
    doReturn(resourceCustomizationUUID).when(resourceInstance).getResourceCustomizationUUID();
    doReturn("resourceName1").when(resourceInstance).getResourceName();
    Service service = toscaInstaller.createService(toscaResourceStructObj, vfResourceStruct);
    assertNotNull(service);
    service.setModelVersion("1.0");
    doReturn(service).when(serviceRepo).save(service);
    WatchdogComponentDistributionStatusRepository watchdogCDStatusRepository = spy(WatchdogComponentDistributionStatusRepository.class);
    ReflectionTestUtils.setField(toscaInstaller, "watchdogCDStatusRepository", watchdogCDStatusRepository);
    doReturn(null).when(watchdogCDStatusRepository).save(any(WatchdogComponentDistributionStatus.class));
    VnfcInstanceGroupCustomizationRepository vnfcInstanceGroupCustomizationRepo = spy(VnfcInstanceGroupCustomizationRepository.class);
    ReflectionTestUtils.setField(toscaInstaller, "vnfcInstanceGroupCustomizationRepo", vnfcInstanceGroupCustomizationRepo);
    doReturn(null).when(vnfcInstanceGroupCustomizationRepo).save(any(VnfcInstanceGroupCustomization.class));
    return toscaResourceStructObj;
}
Also used : Group(org.onap.sdc.toscaparser.api.Group) ISdcCsarHelper(org.onap.sdc.tosca.parser.api.ISdcCsarHelper) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Metadata(org.onap.sdc.toscaparser.api.elements.Metadata) ArrayList(java.util.ArrayList) WatchdogComponentDistributionStatusRepository(org.onap.so.db.request.data.repository.WatchdogComponentDistributionStatusRepository) VfModuleStructure(org.onap.so.asdc.installer.VfModuleStructure) Input(org.onap.sdc.toscaparser.api.parameters.Input) NotificationDataImpl(org.onap.so.asdc.client.test.emulators.NotificationDataImpl) SubstitutionMappings(org.onap.sdc.toscaparser.api.SubstitutionMappings) IArtifactInfo(org.onap.sdc.api.notification.IArtifactInfo) WorkflowResource(org.onap.so.asdc.installer.bpmn.WorkflowResource) WatchdogComponentDistributionStatus(org.onap.so.db.request.beans.WatchdogComponentDistributionStatus) IResourceInstance(org.onap.sdc.api.notification.IResourceInstance) NodeTemplate(org.onap.sdc.toscaparser.api.NodeTemplate) ToscaResourceStructure(org.onap.so.asdc.installer.ToscaResourceStructure) IVfModuleData(org.onap.so.asdc.installer.IVfModuleData)

Aggregations

ISdcCsarHelper (org.onap.sdc.tosca.parser.api.ISdcCsarHelper)9 ArrayList (java.util.ArrayList)5 IEntityDetails (org.onap.sdc.tosca.parser.api.IEntityDetails)5 Metadata (org.onap.sdc.toscaparser.api.elements.Metadata)5 LinkedHashMap (java.util.LinkedHashMap)4 Input (org.onap.sdc.toscaparser.api.parameters.Input)4 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)3 HashMap (java.util.HashMap)3 NodeTemplate (org.onap.sdc.toscaparser.api.NodeTemplate)3 RequirementAssignment (org.onap.sdc.toscaparser.api.RequirementAssignment)3 ConstraintViolationException (org.hibernate.exception.ConstraintViolationException)2 LockAcquisitionException (org.hibernate.exception.LockAcquisitionException)2 IArtifactInfo (org.onap.sdc.api.notification.IArtifactInfo)2 IResourceInstance (org.onap.sdc.api.notification.IResourceInstance)2 EntityQuery (org.onap.sdc.tosca.parser.elements.queries.EntityQuery)2 TopologyTemplateQuery (org.onap.sdc.tosca.parser.elements.queries.TopologyTemplateQuery)2 GetInput (org.onap.sdc.toscaparser.api.functions.GetInput)2 ToscaResourceStructure (org.onap.so.asdc.installer.ToscaResourceStructure)2 Timestamp (java.sql.Timestamp)1