Search in sources :

Example 6 with ToscaResourceStructure

use of org.onap.so.asdc.installer.ToscaResourceStructure in project so by onap.

the class ToscaResourceInstallerTest method installTheResourceGroupWithoutVFModulesTest.

@Test
public void installTheResourceGroupWithoutVFModulesTest() throws Exception {
    ToscaResourceInstaller toscaInstaller = new ToscaResourceInstaller();
    ToscaResourceStructure toscaResourceStructObj = prepareToscaResourceStructure(false, toscaInstaller);
    toscaInstaller.installTheResource(toscaResourceStructObj, vfResourceStruct);
    assertEquals(true, toscaResourceStructObj.isDeployedSuccessfully());
}
Also used : ToscaResourceStructure(org.onap.so.asdc.installer.ToscaResourceStructure) BaseTest(org.onap.so.asdc.BaseTest) Test(org.junit.Test)

Example 7 with ToscaResourceStructure

use of org.onap.so.asdc.installer.ToscaResourceStructure 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)

Example 8 with ToscaResourceStructure

use of org.onap.so.asdc.installer.ToscaResourceStructure in project so by onap.

the class ToscaResourceInstallerTest method createServiceTest.

@Test
public void createServiceTest() {
    ToscaResourceStructure toscaResourceStructure = mock(ToscaResourceStructure.class);
    ResourceStructure resourceStructure = mock(ResourceStructure.class);
    Metadata metadata = mock(Metadata.class);
    INotificationData notification = mock(INotificationData.class);
    doReturn("e2899e5c-ae35-434c-bada-0fabb7c1b44d").when(toscaResourceStructure).getServiceVersion();
    doReturn(metadata).when(toscaResourceStructure).getServiceMetadata();
    doReturn("production").when(notification).getWorkloadContext();
    doReturn(notification).when(resourceStructure).getNotification();
    String serviceType = "test-type";
    String serviceRole = "test-role";
    String category = "Network L4+";
    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 Policy";
    String ecompGeneratedNaming = "true";
    String environmentContext = "General_Revenue-Bearing";
    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(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");
    ISdcCsarHelper iSdcCsarHelper = mock(ISdcCsarHelper.class);
    List<Input> serviceInputs = new ArrayList<Input>();
    LinkedHashMap<String, Object> value = new LinkedHashMap<String, Object>();
    value.put("controller_actor", "SO-REF-DATA");
    value.put("type", "string");
    Input input = new Input("controller_actor", value, null);
    serviceInputs.add(0, input);
    value = new LinkedHashMap<String, Object>();
    value.put("cds_model_version", "v1.4.0");
    value.put("type", "string");
    input = new Input("cds_model_version", value, null);
    serviceInputs.add(1, input);
    value = new LinkedHashMap<String, Object>();
    value.put("cds_model_name", "Blueprint140");
    value.put("type", "string");
    input = new Input("cds_model_name", value, null);
    serviceInputs.add(2, input);
    value = new LinkedHashMap<String, Object>();
    value.put("skip_post_instantiation_configuration", "false");
    value.put("type", "boolean");
    input = new Input("skip_post_instantiation_configuration", value, null);
    serviceInputs.add(3, input);
    doReturn(iSdcCsarHelper).when(toscaResourceStructure).getSdcCsarHelper();
    doReturn(serviceInputs).when(iSdcCsarHelper).getServiceInputs();
    Service service = toscaInstaller.createService(toscaResourceStructure, resourceStructure);
    assertNotNull(service);
    verify(toscaResourceStructure, times(2)).getServiceVersion();
    assertNotNull(service.getNamingPolicy());
    assertEquals(serviceType, service.getServiceType());
    assertEquals(serviceRole, service.getServiceRole());
    assertEquals(category, service.getCategory());
    assertEquals(description, service.getDescription());
    assertEquals(uuid, service.getModelUUID());
    assertEquals(invariantUUID, service.getModelInvariantUUID());
    assertEquals(namingPolicy, service.getNamingPolicy());
    assertTrue(service.getOnapGeneratedNaming());
}
Also used : INotificationData(org.onap.sdc.api.notification.INotificationData) ISdcCsarHelper(org.onap.sdc.tosca.parser.api.ISdcCsarHelper) Metadata(org.onap.sdc.toscaparser.api.elements.Metadata) ArrayList(java.util.ArrayList) ResourceStructure(org.onap.so.asdc.installer.ResourceStructure) VfResourceStructure(org.onap.so.asdc.installer.VfResourceStructure) ToscaResourceStructure(org.onap.so.asdc.installer.ToscaResourceStructure) LinkedHashMap(java.util.LinkedHashMap) Input(org.onap.sdc.toscaparser.api.parameters.Input) ToscaResourceStructure(org.onap.so.asdc.installer.ToscaResourceStructure) BaseTest(org.onap.so.asdc.BaseTest) Test(org.junit.Test)

Example 9 with ToscaResourceStructure

use of org.onap.so.asdc.installer.ToscaResourceStructure in project so by onap.

the class ASDCController method processNsstNotification.

private void processNsstNotification(INotificationData iNotif, ToscaResourceStructure toscaResourceStructure) {
    Metadata serviceMetadata = toscaResourceStructure.getServiceMetadata();
    try {
        String category = serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY);
        boolean isNeedInital = (category.contains("NSST") || category.equalsIgnoreCase("TN Network Requirement")) && iNotif.getResources().isEmpty();
        if (isNeedInital) {
            String artifactContent = null;
            List<IArtifactInfo> serviceArtifacts = iNotif.getServiceArtifacts();
            Optional<IArtifactInfo> artifactOpt = serviceArtifacts.stream().filter(e -> e.getArtifactType().equalsIgnoreCase("WORKFLOW")).findFirst();
            if (artifactOpt.isPresent()) {
                IArtifactInfo artifactInfo = artifactOpt.get();
                logger.debug("Ready to parse this serviceArtifactUUID:  " + artifactInfo.getArtifactUUID());
                String filePath = Paths.get(getMsoConfigPath(), "ASDC", artifactInfo.getArtifactVersion(), artifactInfo.getArtifactName()).normalize().toString();
                ZipParser zipParserInstance = ZipParser.getInstance();
                artifactContent = zipParserInstance.parseJsonForZip(filePath);
                logger.debug("serviceArtifact parsing success! serviceArtifactUUID: " + artifactInfo.getArtifactUUID());
                ResourceStructure resourceStructure = new VfResourceStructure(iNotif, new ResourceInstance());
                resourceStructure.setResourceType(ResourceType.OTHER);
                toscaInstaller.installNsstService(toscaResourceStructure, (VfResourceStructure) resourceStructure, artifactContent);
            } else {
                logger.debug("serviceArtifact is null");
                toscaInstaller.installNsstService(toscaResourceStructure, null, null);
            }
        }
    } catch (IOException e) {
        logger.error("serviceArtifact parse failure for service uuid:  " + serviceMetadata.getValue(SdcPropertyNames.PROPERTY_NAME_CATEGORY));
    } catch (Exception e) {
        logger.error("error NSST process resource failure ", e);
    }
}
Also used : ObjectOptimisticLockingFailureException(org.springframework.orm.ObjectOptimisticLockingFailureException) ONAPLogConstants(org.onap.logging.ref.slf4j.ONAPLogConstants) IFinalDistrStatusMessage(org.onap.sdc.api.consumer.IFinalDistrStatusMessage) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) INotificationData(org.onap.sdc.api.notification.INotificationData) ASDCDownloadException(org.onap.so.asdc.client.exceptions.ASDCDownloadException) PnfResourceStructure(org.onap.so.asdc.installer.PnfResourceStructure) WatchdogComponentDistributionStatusRepository(org.onap.so.db.request.data.repository.WatchdogComponentDistributionStatusRepository) DeserializationFeature(com.fasterxml.jackson.databind.DeserializationFeature) ResourceType(org.onap.so.asdc.installer.ResourceType) ASDCNotificationLogging(org.onap.so.asdc.util.ASDCNotificationLogging) MessageEnum(org.onap.so.logger.MessageEnum) ResourceStructure(org.onap.so.asdc.installer.ResourceStructure) WatchdogDistribution(org.onap.so.asdc.tenantIsolation.WatchdogDistribution) IDistributionClientDownloadResult(org.onap.sdc.api.results.IDistributionClientDownloadResult) VfResourceStructure(org.onap.so.asdc.installer.VfResourceStructure) WatchdogDistributionStatus(org.onap.so.db.request.beans.WatchdogDistributionStatus) ASDCParametersException(org.onap.so.asdc.client.exceptions.ASDCParametersException) DistributionStatus(org.onap.so.asdc.tenantIsolation.DistributionStatus) StandardCharsets(java.nio.charset.StandardCharsets) IDistributionClient(org.onap.sdc.api.IDistributionClient) List(java.util.List) IArtifactInfo(org.onap.sdc.api.notification.IArtifactInfo) DistributionActionResultEnum(org.onap.sdc.utils.DistributionActionResultEnum) Optional(java.util.Optional) LoggingAnchor(org.onap.so.logger.LoggingAnchor) UnsupportedEncodingException(java.io.UnsupportedEncodingException) WatchdogDistributionStatusRepository(org.onap.so.db.request.data.repository.WatchdogDistributionStatusRepository) ZipParser(org.onap.so.asdc.util.ZipParser) MapperFeature(com.fasterxml.jackson.databind.MapperFeature) IResourceInstance(org.onap.sdc.api.notification.IResourceInstance) ErrorCode(org.onap.logging.filter.base.ErrorCode) IDistributionStatusMessage(org.onap.sdc.api.consumer.IDistributionStatusMessage) IDistributionClientResult(org.onap.sdc.api.results.IDistributionClientResult) DistributionStatusEnum(org.onap.sdc.utils.DistributionStatusEnum) WatchdogComponentDistributionStatus(org.onap.so.db.request.beans.WatchdogComponentDistributionStatus) Logger(org.slf4j.Logger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) FileOutputStream(java.io.FileOutputStream) IVfResourceInstaller(org.onap.so.asdc.installer.IVfResourceInstaller) Include(com.fasterxml.jackson.annotation.JsonInclude.Include) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) File(java.io.File) Metadata(org.onap.sdc.toscaparser.api.elements.Metadata) ASDCControllerException(org.onap.so.asdc.client.exceptions.ASDCControllerException) ToscaResourceInstaller(org.onap.so.asdc.installer.heat.ToscaResourceInstaller) ArtifactInstallerException(org.onap.so.asdc.client.exceptions.ArtifactInstallerException) ToscaResourceStructure(org.onap.so.asdc.installer.ToscaResourceStructure) Component(org.springframework.stereotype.Component) Paths(java.nio.file.Paths) MDC(org.slf4j.MDC) SdcPropertyNames(org.onap.sdc.tosca.parser.impl.SdcPropertyNames) DeployActivitySpecs(org.onap.so.asdc.activity.DeployActivitySpecs) DistributionClientFactory(org.onap.sdc.impl.DistributionClientFactory) Metadata(org.onap.sdc.toscaparser.api.elements.Metadata) IOException(java.io.IOException) PnfResourceStructure(org.onap.so.asdc.installer.PnfResourceStructure) ResourceStructure(org.onap.so.asdc.installer.ResourceStructure) VfResourceStructure(org.onap.so.asdc.installer.VfResourceStructure) ToscaResourceStructure(org.onap.so.asdc.installer.ToscaResourceStructure) ObjectOptimisticLockingFailureException(org.springframework.orm.ObjectOptimisticLockingFailureException) ASDCDownloadException(org.onap.so.asdc.client.exceptions.ASDCDownloadException) ASDCParametersException(org.onap.so.asdc.client.exceptions.ASDCParametersException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) IOException(java.io.IOException) ASDCControllerException(org.onap.so.asdc.client.exceptions.ASDCControllerException) ArtifactInstallerException(org.onap.so.asdc.client.exceptions.ArtifactInstallerException) VfResourceStructure(org.onap.so.asdc.installer.VfResourceStructure) ZipParser(org.onap.so.asdc.util.ZipParser) IArtifactInfo(org.onap.sdc.api.notification.IArtifactInfo) IResourceInstance(org.onap.sdc.api.notification.IResourceInstance)

Example 10 with ToscaResourceStructure

use of org.onap.so.asdc.installer.ToscaResourceStructure in project so by onap.

the class ASDCController method processResourceNotification.

protected void processResourceNotification(INotificationData iNotif) {
    // For each artifact, create a structure describing the VFModule in a ordered flat level
    ResourceStructure resourceStructure = null;
    String msoConfigPath = getMsoConfigPath();
    ToscaResourceStructure toscaResourceStructure = new ToscaResourceStructure(msoConfigPath);
    DistributionStatusEnum deployStatus = DistributionStatusEnum.DEPLOY_OK;
    String errorMessage = null;
    boolean serviceDeployed = false;
    try {
        this.processCsarServiceArtifacts(iNotif, toscaResourceStructure);
        if (isCsarAlreadyDeployed(iNotif, toscaResourceStructure)) {
            return;
        }
        // process NsstResource
        this.processNsstNotification(iNotif, toscaResourceStructure);
        if (iNotif.getResources().isEmpty()) {
            logger.error("Service Model contains no resources.");
            return;
        }
        for (IResourceInstance resource : iNotif.getResources()) {
            String resourceType = resource.getResourceType();
            boolean hasVFResource = false;
            logger.info("Processing Resource Type: {}, Model UUID: {}", resourceType, resource.getResourceUUID());
            resourceStructure = getResourceStructure(iNotif, resource, resourceType);
            try {
                if (!this.checkResourceAlreadyDeployed(resourceStructure, serviceDeployed)) {
                    logger.debug("Processing Resource Type: " + resourceType + " and Model UUID: " + resourceStructure.getResourceInstance().getResourceUUID());
                    if ("VF".equals(resourceType)) {
                        hasVFResource = true;
                        for (IArtifactInfo artifact : resource.getArtifacts()) {
                            IDistributionClientDownloadResult resultArtifact = this.downloadTheArtifact(artifact, iNotif.getDistributionID());
                            if (resultArtifact == null) {
                                continue;
                            }
                            if (ASDCConfiguration.VF_MODULES_METADATA.equals(artifact.getArtifactType())) {
                                logger.debug("VF_MODULE_ARTIFACT: " + new String(resultArtifact.getArtifactPayload(), StandardCharsets.UTF_8));
                                logger.debug(ASDCNotificationLogging.dumpVfModuleMetaDataList(((VfResourceStructure) resourceStructure).decodeVfModuleArtifact(resultArtifact.getArtifactPayload())));
                            }
                            if (!ASDCConfiguration.WORKFLOW.equals(artifact.getArtifactType())) {
                                resourceStructure.addArtifactToStructure(distributionClient, artifact, resultArtifact);
                            } else {
                                writeArtifactToFile(artifact, resultArtifact);
                                logger.debug("Adding workflow artifact to structure: " + artifact.getArtifactName());
                                resourceStructure.addWorkflowArtifactToStructure(artifact, resultArtifact);
                            }
                        }
                        // Deploy VF resource and artifacts
                        logger.debug("Preparing to deploy Service: {}", iNotif.getServiceUUID());
                        this.deployResourceStructure(resourceStructure, toscaResourceStructure);
                        serviceDeployed = true;
                    }
                }
            } catch (ArtifactInstallerException e) {
                deployStatus = DistributionStatusEnum.DEPLOY_ERROR;
                errorMessage = e.getMessage();
                logger.error("Exception occurred", e);
            }
            if (!hasVFResource) {
                logger.debug("No resources found for Service: " + iNotif.getServiceUUID());
                logger.debug("Preparing to deploy Service: {}", iNotif.getServiceUUID());
                try {
                    this.deployResourceStructure(resourceStructure, toscaResourceStructure);
                    serviceDeployed = true;
                } catch (ArtifactInstallerException e) {
                    deployStatus = DistributionStatusEnum.DEPLOY_ERROR;
                    errorMessage = e.getMessage();
                    logger.error("Exception occurred", e);
                }
            }
        }
        this.sendCsarDeployNotification(resourceStructure, toscaResourceStructure, deployStatus, errorMessage);
    } catch (ASDCDownloadException | UnsupportedEncodingException e) {
        logger.error(LoggingAnchor.SIX, MessageEnum.ASDC_GENERAL_EXCEPTION_ARG.toString(), "Exception caught during Installation of artifact", "ASDC", "processResourceNotification", ErrorCode.BusinessProcessError.getValue(), "Exception in processResourceNotification", e);
    }
}
Also used : IResourceInstance(org.onap.sdc.api.notification.IResourceInstance) UnsupportedEncodingException(java.io.UnsupportedEncodingException) PnfResourceStructure(org.onap.so.asdc.installer.PnfResourceStructure) ResourceStructure(org.onap.so.asdc.installer.ResourceStructure) VfResourceStructure(org.onap.so.asdc.installer.VfResourceStructure) ToscaResourceStructure(org.onap.so.asdc.installer.ToscaResourceStructure) DistributionStatusEnum(org.onap.sdc.utils.DistributionStatusEnum) VfResourceStructure(org.onap.so.asdc.installer.VfResourceStructure) IDistributionClientDownloadResult(org.onap.sdc.api.results.IDistributionClientDownloadResult) ToscaResourceStructure(org.onap.so.asdc.installer.ToscaResourceStructure) IArtifactInfo(org.onap.sdc.api.notification.IArtifactInfo) ArtifactInstallerException(org.onap.so.asdc.client.exceptions.ArtifactInstallerException) ASDCDownloadException(org.onap.so.asdc.client.exceptions.ASDCDownloadException)

Aggregations

ToscaResourceStructure (org.onap.so.asdc.installer.ToscaResourceStructure)15 Metadata (org.onap.sdc.toscaparser.api.elements.Metadata)12 IArtifactInfo (org.onap.sdc.api.notification.IArtifactInfo)7 IResourceInstance (org.onap.sdc.api.notification.IResourceInstance)7 Property (org.onap.sdc.toscaparser.api.Property)7 ResourceStructure (org.onap.so.asdc.installer.ResourceStructure)7 VfResourceStructure (org.onap.so.asdc.installer.VfResourceStructure)7 ArrayList (java.util.ArrayList)6 LinkedHashMap (java.util.LinkedHashMap)6 Test (org.junit.Test)6 ISdcCsarHelper (org.onap.sdc.tosca.parser.api.ISdcCsarHelper)6 DistributionStatusEnum (org.onap.sdc.utils.DistributionStatusEnum)6 ArtifactInstallerException (org.onap.so.asdc.client.exceptions.ArtifactInstallerException)6 PnfResourceStructure (org.onap.so.asdc.installer.PnfResourceStructure)6 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)5 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 HashMap (java.util.HashMap)5 List (java.util.List)5 Optional (java.util.Optional)5 ErrorCode (org.onap.logging.filter.base.ErrorCode)5