Search in sources :

Example 1 with WatchdogComponentDistributionStatus

use of org.onap.so.db.request.beans.WatchdogComponentDistributionStatus in project so by onap.

the class ToscaResourceInstaller method isResourceAlreadyDeployed.

public boolean isResourceAlreadyDeployed(ResourceStructure vfResourceStruct, boolean serviceDeployed) throws ArtifactInstallerException {
    boolean status = false;
    ResourceStructure vfResourceStructure = vfResourceStruct;
    try {
        status = vfResourceStructure.isDeployedSuccessfully();
    } catch (RuntimeException e) {
        status = false;
        logger.debug("Exception :", e);
    }
    try {
        Service existingService = serviceRepo.findOneByModelUUID(vfResourceStructure.getNotification().getServiceUUID());
        if (existingService != null && !serviceDeployed)
            status = true;
        if (status) {
            logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(), vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(), vfResourceStructure.getNotification().getServiceName(), BigDecimalVersion.castAndCheckNotificationVersionToString(vfResourceStructure.getNotification().getServiceVersion()), vfResourceStructure.getNotification().getServiceUUID(), vfResourceStructure.getResourceInstance().getResourceName(), "", "");
            WatchdogComponentDistributionStatus wdStatus = new WatchdogComponentDistributionStatus(vfResourceStruct.getNotification().getDistributionID(), MSO);
            wdStatus.setComponentDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK.name());
            watchdogCDStatusRepository.saveAndFlush(wdStatus);
        } else {
            logger.info(vfResourceStructure.getResourceInstance().getResourceInstanceName(), vfResourceStructure.getResourceInstance().getResourceCustomizationUUID(), vfResourceStructure.getNotification().getServiceName(), BigDecimalVersion.castAndCheckNotificationVersionToString(vfResourceStructure.getNotification().getServiceVersion()), vfResourceStructure.getNotification().getServiceUUID(), vfResourceStructure.getResourceInstance().getResourceName(), "", "");
        }
        return status;
    } catch (Exception e) {
        logger.error(LoggingAnchor.THREE, MessageEnum.ASDC_ARTIFACT_CHECK_EXC.toString(), ErrorCode.SchemaError.getValue(), "Exception - isResourceAlreadyDeployed");
        throw new ArtifactInstallerException("Exception caught during checking existence of the VNF Resource.", e);
    }
}
Also used : WatchdogComponentDistributionStatus(org.onap.so.db.request.beans.WatchdogComponentDistributionStatus) Service(org.onap.so.db.catalog.beans.Service) ArtifactInstallerException(org.onap.so.asdc.client.exceptions.ArtifactInstallerException) ResourceStructure(org.onap.so.asdc.installer.ResourceStructure) VfResourceStructure(org.onap.so.asdc.installer.VfResourceStructure) PnfResourceStructure(org.onap.so.asdc.installer.PnfResourceStructure) ToscaResourceStructure(org.onap.so.asdc.installer.ToscaResourceStructure) 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 2 with WatchdogComponentDistributionStatus

use of org.onap.so.db.request.beans.WatchdogComponentDistributionStatus in project so by onap.

the class ToscaResourceInstaller method installTheComponentStatus.

public void installTheComponentStatus(IStatusData iStatus) throws ArtifactInstallerException {
    logger.debug("Entering installTheComponentStatus for distributionId {} and ComponentName {}", iStatus.getDistributionID(), iStatus.getComponentName());
    try {
        WatchdogComponentDistributionStatus cdStatus = new WatchdogComponentDistributionStatus(iStatus.getDistributionID(), iStatus.getComponentName());
        cdStatus.setComponentDistributionStatus(iStatus.getStatus().toString());
        watchdogCDStatusRepository.save(cdStatus);
    } catch (Exception e) {
        logger.debug("Exception caught in installTheComponentStatus {}", e.getMessage());
        throw new ArtifactInstallerException("Exception caught in installTheComponentStatus " + e.getMessage());
    }
}
Also used : WatchdogComponentDistributionStatus(org.onap.so.db.request.beans.WatchdogComponentDistributionStatus) ArtifactInstallerException(org.onap.so.asdc.client.exceptions.ArtifactInstallerException) 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 WatchdogComponentDistributionStatus

use of org.onap.so.db.request.beans.WatchdogComponentDistributionStatus in project so by onap.

the class ASDCControllerITTest method treatNotification_ValidPnfResource_ExpectedOutput.

/**
 * Test with service-pnfservice.csar.
 */
@Test
public void treatNotification_ValidPnfResource_ExpectedOutput() {
    /**
     * service UUID/invariantUUID from global metadata in service-PnfServiceTestCds-template.yml.
     */
    String serviceUuid = "77cf276e-905c-43f6-8d54-dda474be2f2e";
    String serviceInvariantUuid = "913e6776-4bc3-49b9-b399-b5bb4690f0c7";
    initMockAaiServer(serviceUuid, serviceInvariantUuid);
    NotificationDataImpl notificationData = new NotificationDataImpl();
    notificationData.setServiceUUID(serviceUuid);
    notificationData.setDistributionID(distributionId);
    notificationData.setServiceInvariantUUID(serviceInvariantUuid);
    notificationData.setServiceVersion("1.0");
    ResourceInfoImpl resourceInfo = constructPnfResourceInfo();
    List<ResourceInfoImpl> resourceInfoList = new ArrayList<>();
    resourceInfoList.add(resourceInfo);
    notificationData.setResources(resourceInfoList);
    ArtifactInfoImpl artifactInfo = constructPnfServiceArtifact();
    List<ArtifactInfoImpl> artifactInfoList = new ArrayList<>();
    artifactInfoList.add(artifactInfo);
    notificationData.setServiceArtifacts(artifactInfoList);
    try {
        asdcController.treatNotification(notificationData);
        logger.info("Checking the database for PNF ingestion");
        /**
         * Check the tosca csar entity, it should be the same as provided from NotficationData.
         */
        ToscaCsar toscaCsar = toscaCsarRepository.findById(artifactUuid).orElseThrow(() -> new EntityNotFoundException("Tosca csar: " + artifactUuid + " not found"));
        assertEquals("tosca csar UUID", artifactUuid, toscaCsar.getArtifactUUID());
        assertEquals("tosca csar name", "service-pnfservice.csar", toscaCsar.getName());
        assertEquals("tosca csar version", "1.0", toscaCsar.getVersion());
        assertNull("tosca csar descrption", toscaCsar.getDescription());
        assertEquals("tosca csar checksum", "MANUAL_RECORD", toscaCsar.getArtifactChecksum());
        assertEquals("toscar csar URL", "/download/service-pnfservice.csar", toscaCsar.getUrl());
        /**
         * Check the service entity, it should be the same as global metadata information in
         * service-Testservice140-template.yml inside csar.
         */
        Service service = serviceRepository.findById(serviceUuid).orElseThrow(() -> new EntityNotFoundException("Service: " + serviceUuid + " not found"));
        assertEquals("model UUID", serviceUuid, service.getModelUUID());
        assertEquals("model name", "PNF Service Test CDS", service.getModelName());
        assertEquals("model invariantUUID", serviceInvariantUuid, service.getModelInvariantUUID());
        assertEquals("model version", "1.0", service.getModelVersion());
        assertEquals("description", "123123", service.getDescription().trim());
        assertEquals("tosca csar artifact UUID", artifactUuid, service.getCsar().getArtifactUUID());
        assertEquals("service type", "", service.getServiceType());
        assertEquals("service role", "", service.getServiceRole());
        assertEquals("environment context", "General_Revenue-Bearing", service.getEnvironmentContext());
        assertEquals("service category", "Network L1-3", service.getCategory());
        assertNull("workload context", service.getWorkloadContext());
        assertEquals("resource order", "PNF CDS Test", service.getResourceOrder());
        assertEquals("CDS blueprint name", "Blueprint140", service.getBlueprintName());
        assertEquals("CDS blueprint version", "v1.4.0", service.getBlueprintVersion());
        assertEquals("controller actor", "SO-REF-DATA", service.getControllerActor());
        /**
         * Check PNF resource, it should be the same as metadata in the topology template in
         * service-PnfServiceTestCds-template.yml OR global metadata in the resource-PnfServiceTestCds-template.yml
         */
        String pnfResourceKey = "aa5d0562-80e7-43e9-af74-3085e57ab09f";
        PnfResource pnfResource = pnfResourceRepository.findById(pnfResourceKey).orElseThrow(() -> new EntityNotFoundException("PNF resource:" + pnfResourceKey + " not found"));
        assertNull("orchestration mode", pnfResource.getOrchestrationMode());
        assertEquals("Description", "123123", pnfResource.getDescription().trim());
        assertEquals("model UUID", pnfResourceKey, pnfResource.getModelUUID());
        assertEquals("model invariant UUID", "17d9d183-cee5-4a46-b5c4-6d5203f7d2e8", pnfResource.getModelInvariantUUID());
        assertEquals("model version", "1.0", pnfResource.getModelVersion());
        assertEquals("model name", "PNF CDS Test", pnfResource.getModelName());
        assertEquals("tosca node type", "org.openecomp.resource.pnf.PnfCdsTest", pnfResource.getToscaNodeType());
        assertEquals("resource category", "Application L4+", pnfResource.getCategory());
        assertEquals("resource sub category", "Firewall", pnfResource.getSubCategory());
        /**
         * Check PNF resource customization, it should be the same as metadata in the topology template in
         * service-PnfServiceTestCds-template.yml OR global metadata in the resource-PnfServiceTestCds-template.yml
         */
        String pnfCustomizationKey = "9f01263a-eaf7-4d98-a37b-3785f751903e";
        PnfResourceCustomization pnfCustomization = pnfCustomizationRepository.findById(pnfCustomizationKey).orElseThrow(() -> new EntityNotFoundException("PNF resource customization: " + pnfCustomizationKey + " not found"));
        assertEquals("model customizationUUID", pnfCustomizationKey, pnfCustomization.getModelCustomizationUUID());
        assertEquals("model instance name", "PNF CDS Test 0", pnfCustomization.getModelInstanceName());
        assertEquals("NF type", "", pnfCustomization.getNfType());
        assertEquals("NF Role", "nf", pnfCustomization.getNfRole());
        assertEquals("NF function", "nf", pnfCustomization.getNfFunction());
        assertEquals("NF naming code", "", pnfCustomization.getNfNamingCode());
        assertEquals("PNF resource model UUID", pnfResourceKey, pnfCustomization.getPnfResources().getModelUUID());
        assertEquals("Multi stage design", "", pnfCustomization.getMultiStageDesign());
        assertNull("resource input", pnfCustomization.getResourceInput());
        assertEquals("cds blueprint name(sdnc_model_name property)", "Blueprint140", pnfCustomization.getBlueprintName());
        assertEquals("cds blueprint version(sdnc_model_version property)", "v1.4.0", pnfCustomization.getBlueprintVersion());
        assertTrue("skip post instantiation configuration", pnfCustomization.getSkipPostInstConf());
        assertEquals("controller actor", "SO-REF-DATA", pnfCustomization.getControllerActor());
        /**
         * Check the pnf resource customization with service mapping
         */
        List<PnfResourceCustomization> pnfCustList = service.getPnfCustomizations();
        assertEquals("PNF resource customization entity", 1, pnfCustList.size());
        assertEquals(pnfCustomizationKey, pnfCustList.get(0).getModelCustomizationUUID());
        /**
         * Check the watchdog for component distribution status
         */
        List<WatchdogComponentDistributionStatus> distributionList = watchdogCDStatusRepository.findByDistributionId(this.distributionId);
        assertNotNull(distributionList);
        assertEquals(1, distributionList.size());
        WatchdogComponentDistributionStatus distributionStatus = distributionList.get(0);
        assertEquals("COMPONENT_DONE_OK", distributionStatus.getComponentDistributionStatus());
        assertEquals("SO", distributionStatus.getComponentName());
    } catch (Exception e) {
        logger.info(e.getMessage(), e);
        fail(e.getMessage());
    }
}
Also used : PnfResourceCustomization(org.onap.so.db.catalog.beans.PnfResourceCustomization) ArtifactInfoImpl(org.onap.so.asdc.client.test.emulators.ArtifactInfoImpl) WatchdogComponentDistributionStatus(org.onap.so.db.request.beans.WatchdogComponentDistributionStatus) ResourceInfoImpl(org.onap.so.asdc.client.test.emulators.ResourceInfoImpl) PnfResource(org.onap.so.db.catalog.beans.PnfResource) ArrayList(java.util.ArrayList) Service(org.onap.so.db.catalog.beans.Service) EntityNotFoundException(javax.persistence.EntityNotFoundException) EntityNotFoundException(javax.persistence.EntityNotFoundException) ASDCControllerException(org.onap.so.asdc.client.exceptions.ASDCControllerException) NotificationDataImpl(org.onap.so.asdc.client.test.emulators.NotificationDataImpl) ToscaCsar(org.onap.so.db.catalog.beans.ToscaCsar) BaseTest(org.onap.so.asdc.BaseTest) Test(org.junit.Test)

Example 4 with WatchdogComponentDistributionStatus

use of org.onap.so.db.request.beans.WatchdogComponentDistributionStatus in project so by onap.

the class ToscaResourceInstallerTest method installTheComponentStatusTest.

@Test
public void installTheComponentStatusTest() throws Exception {
    String distributionId = "testStatusSuccessTosca";
    String componentName = "testComponentName";
    statusData = spy(JsonStatusData.class);
    doReturn(distributionId).when(statusData).getDistributionID();
    doReturn(componentName).when(statusData).getComponentName();
    WatchdogComponentDistributionStatus expectedWatchdogComponentDistributionStatus = new WatchdogComponentDistributionStatus(distributionId, componentName);
    expectedWatchdogComponentDistributionStatus.setComponentDistributionStatus(statusData.getStatus().toString());
    WatchdogComponentDistributionStatus cdStatus = new WatchdogComponentDistributionStatus(statusData.getDistributionID(), statusData.getComponentName());
    toscaInstaller.installTheComponentStatus(statusData);
    WatchdogComponentDistributionStatus actualWatchdogComponentDistributionStatus = getWatchdogCDStatusWithName(watchdogCDStatusRepository.findByDistributionId("testStatusSuccessTosca"), statusData.getComponentName());
    assertEquals(statusData.getDistributionID(), cdStatus.getDistributionId());
    assertEquals(statusData.getComponentName(), cdStatus.getComponentName());
    assertThat(actualWatchdogComponentDistributionStatus, sameBeanAs(expectedWatchdogComponentDistributionStatus).ignoring("createTime").ignoring("modifyTime"));
}
Also used : JsonStatusData(org.onap.so.asdc.client.test.emulators.JsonStatusData) WatchdogComponentDistributionStatus(org.onap.so.db.request.beans.WatchdogComponentDistributionStatus) BaseTest(org.onap.so.asdc.BaseTest) Test(org.junit.Test)

Example 5 with WatchdogComponentDistributionStatus

use of org.onap.so.db.request.beans.WatchdogComponentDistributionStatus in project so by onap.

the class WatchdogDistribution method getOverallDistributionStatus.

public String getOverallDistributionStatus(String distributionId) throws Exception {
    logger.debug("Entered getOverallDistributionStatus method for distrubutionId: {}", distributionId);
    String status = null;
    try {
        WatchdogDistributionStatus watchdogDistributionStatus = watchdogDistributionStatusRepository.findById(distributionId).orElseGet(() -> null);
        if (watchdogDistributionStatus == null) {
            watchdogDistributionStatus = new WatchdogDistributionStatus();
            watchdogDistributionStatus.setDistributionId(distributionId);
            watchdogDistributionStatusRepository.save(watchdogDistributionStatus);
        }
        String distributionStatus = watchdogDistributionStatus.getDistributionIdStatus();
        if (DistributionStatus.TIMEOUT.name().equalsIgnoreCase(distributionStatus)) {
            logger.debug("Ignoring to update WatchdogDistributionStatus as distributionId: {} status is set to: {}", distributionId, distributionStatus);
            return DistributionStatus.TIMEOUT.name();
        } else {
            List<WatchdogComponentDistributionStatus> results = watchdogCDStatusRepository.findByDistributionId(distributionId);
            logger.debug("Executed RequestDB getWatchdogComponentDistributionStatus for distrubutionId: {}", distributionId);
            // *************************************************************************************************************************************************
            // **** Compare config values verse DB watchdog component names to see if every component has reported
            // status before returning final result back to ASDC
            // **************************************************************************************************************************************************
            List<WatchdogComponentDistributionStatus> cdStatuses = watchdogCDStatusRepository.findByDistributionId(distributionId);
            boolean allComponentsComplete = true;
            for (String name : componentNames) {
                boolean match = false;
                for (WatchdogComponentDistributionStatus cdStatus : cdStatuses) {
                    if (name.equals(cdStatus.getComponentName())) {
                        logger.debug("Found componentName {} in the WatchDog Component DB", name);
                        match = true;
                        break;
                    }
                }
                if (!match) {
                    logger.debug("{} has not be updated in the the WatchDog Component DB yet, so ending the loop", name);
                    allComponentsComplete = false;
                    break;
                }
            }
            if (allComponentsComplete) {
                logger.debug("Components Size matched with the WatchdogComponentDistributionStatus results.");
                for (WatchdogComponentDistributionStatus componentDist : results) {
                    String componentDistributionStatus = componentDist.getComponentDistributionStatus();
                    logger.debug("Component status: {} on componentName: ", componentDistributionStatus, componentDist.getComponentName());
                    if (componentDistributionStatus.equalsIgnoreCase("COMPONENT_DONE_ERROR")) {
                        status = DistributionStatus.FAILURE.name();
                        break;
                    } else if (componentDistributionStatus.equalsIgnoreCase("COMPONENT_DONE_OK")) {
                        status = DistributionStatus.SUCCESS.name();
                    } else {
                        throw new Exception("Invalid Component distribution status: " + componentDistributionStatus);
                    }
                }
                logger.debug("Updating overall DistributionStatus to: {} for distributionId: ", status, distributionId);
                watchdogDistributionStatusRepository.save(watchdogDistributionStatus);
            } else {
                logger.debug("Components Size Didn't match with the WatchdogComponentDistributionStatus results.");
                status = DistributionStatus.INCOMPLETE.name();
                return status;
            }
        }
    } catch (Exception e) {
        logger.debug("Exception occurred on getOverallDistributionStatus : {}", e.getMessage());
        logger.error("Exception occurred", e);
        throw new Exception(e);
    }
    logger.debug("Exiting getOverallDistributionStatus method in WatchdogDistribution");
    return status;
}
Also used : WatchdogComponentDistributionStatus(org.onap.so.db.request.beans.WatchdogComponentDistributionStatus) WatchdogDistributionStatus(org.onap.so.db.request.beans.WatchdogDistributionStatus)

Aggregations

WatchdogComponentDistributionStatus (org.onap.so.db.request.beans.WatchdogComponentDistributionStatus)12 Service (org.onap.so.db.catalog.beans.Service)7 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 BaseTest (org.onap.so.asdc.BaseTest)6 ArtifactInstallerException (org.onap.so.asdc.client.exceptions.ArtifactInstallerException)5 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)4 EntityNotFoundException (javax.persistence.EntityNotFoundException)4 ConstraintViolationException (org.hibernate.exception.ConstraintViolationException)4 LockAcquisitionException (org.hibernate.exception.LockAcquisitionException)4 ASDCControllerException (org.onap.so.asdc.client.exceptions.ASDCControllerException)4 ArtifactInfoImpl (org.onap.so.asdc.client.test.emulators.ArtifactInfoImpl)4 NotificationDataImpl (org.onap.so.asdc.client.test.emulators.NotificationDataImpl)4 ResourceInfoImpl (org.onap.so.asdc.client.test.emulators.ResourceInfoImpl)4 ToscaCsar (org.onap.so.db.catalog.beans.ToscaCsar)4 ObjectOptimisticLockingFailureException (org.springframework.orm.ObjectOptimisticLockingFailureException)4 VfResourceStructure (org.onap.so.asdc.installer.VfResourceStructure)3 PnfResourceCustomization (org.onap.so.db.catalog.beans.PnfResourceCustomization)3 ASDCElementInfo (org.onap.so.asdc.installer.ASDCElementInfo)2 IEntityDetails (org.onap.sdc.tosca.parser.api.IEntityDetails)1