X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=plans%2Fso%2Fintegration-etsi-testing%2Fso-simulators%2Faai-simulator%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fso%2Faaisimulator%2Fservice%2Fproviders%2FGenericVnfCacheServiceProviderImpl.java;h=42b2d8720d1772904ff59b584632c7f70ad0a06f;hb=03a107d9254ca0e1fbbf63f2ab5b7f14f1af63f3;hp=3a12dfdc1aed1f4e3e35fa9d48fa7721b95622fa;hpb=2b836af18120fc02c2407dade84c24763b2388d7;p=integration%2Fcsit.git diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProviderImpl.java index 3a12dfdc..42b2d872 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProviderImpl.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProviderImpl.java @@ -37,6 +37,8 @@ import org.onap.aai.domain.yang.RelatedToProperty; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.RelationshipData; import org.onap.aai.domain.yang.RelationshipList; +import org.onap.aai.domain.yang.VfModule; +import org.onap.aai.domain.yang.VfModules; import org.onap.so.aaisimulator.utils.ShallowBeanCopy; import org.onap.so.simulator.cache.provider.AbstractCacheServiceProvider; import org.slf4j.Logger; @@ -58,6 +60,7 @@ public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProv private static final Logger LOGGER = LoggerFactory.getLogger(GenericVnfCacheServiceProviderImpl.class); private final HttpRestServiceProvider httpRestServiceProvider; + //final VfModules vfModules = new VfModules(); @Autowired public GenericVnfCacheServiceProviderImpl(final CacheManager cacheManager, @@ -121,7 +124,7 @@ public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProv final GenericVnf genericVnf = optional.get(); final String targetUrl = getTargetUrl(targetBaseUrl, relationship.getRelatedLink()); final Relationship outGoingRelationShip = - getRelationship(getRelationShipListRelatedLink(requestUriString), genericVnf); + getRelationship(getRelationShipListRelatedLink(requestUriString), genericVnf, COMPOSED_OF); final Optional optionalRelationship = httpRestServiceProvider.put(incomingHeader, outGoingRelationShip, targetUrl, Relationship.class); if (optionalRelationship.isPresent()) { @@ -160,7 +163,8 @@ public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProv LOGGER.info("Successfully added relation to GenericVnf for vnfId: {}", vnfId); final String relatedLink = getBiDirectionalRelationShipListRelatedLink(requestURI); - final Relationship resultantRelationship = getRelationship(relatedLink, genericVnf); + final Relationship resultantRelationship = + getRelationship(relatedLink, genericVnf, relationship.getRelationshipLabel()); return Optional.of(resultantRelationship); } return Optional.empty(); @@ -230,10 +234,11 @@ public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProv return false; } - private Relationship getRelationship(final String relatedLink, final GenericVnf genericVnf) { + private Relationship getRelationship(final String relatedLink, final GenericVnf genericVnf, + final String relationshipLabel) { final Relationship relationShip = new Relationship(); relationShip.setRelatedTo(GENERIC_VNF); - relationShip.setRelationshipLabel(COMPOSED_OF); + relationShip.setRelationshipLabel(relationshipLabel); relationShip.setRelatedLink(relatedLink); final RelationshipData relationshipData = new RelationshipData(); @@ -253,4 +258,64 @@ public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProv clearCache(GENERIC_VNF_CACHE.getName()); } + @Override + public Optional getVfModule(final String vnfId, final String vfModuleId) { + LOGGER.info("Getting vfModule from cache for vnfId: {} and vfModuleId: {}", + vnfId, vfModuleId); + final Optional genericVnfOptional = getGenericVnf(vnfId); + final GenericVnf value = genericVnfOptional.get(); + final VfModules vfmodules = value.getVfModules(); + if (vfmodules != null) { + for (VfModule vfModule : vfmodules.getVfModule()) { + if (vfModule.getVfModuleId().equalsIgnoreCase(vfModuleId)){ + return Optional.of(vfModule); + } + } + } + return Optional.empty(); + } + + + @Override + public void putVfModule(final String vnfId, final String vfModuleId, final VfModule vfModule) { + LOGGER.info("Adding vfModule for vnfId: {} and vfModuleId: {}", + vnfId, vfModuleId); + final Optional genericVnfOptional = getGenericVnf(vnfId); + final Cache cache = getCache(GENERIC_VNF_CACHE.getName()); + if (genericVnfOptional.isPresent()) { + final GenericVnf genericVnf = genericVnfOptional.get(); + VfModules vfModules = null; + if(genericVnf.getVfModules()==null){ + vfModules = new VfModules(); + genericVnf.setVfModules(vfModules); + } else { + vfModules = genericVnf.getVfModules(); + } + + vfModules.getVfModule().add(vfModule); + cache.put(vfModuleId, vfModule); + } + } + + @Override + public boolean patchVfModule(final String vnfId, final String vfModuleId, final VfModule vfModule) { + final Optional genericVnfOptional = getGenericVnf(vnfId); + LOGGER.info("Create vfModule for vnfId: {} and vfModuleId: {}", + vnfId, vfModuleId); + if (genericVnfOptional.isPresent()) { + final GenericVnf cachedGenericVnf = genericVnfOptional.get(); + final VfModules vfmodules = cachedGenericVnf.getVfModules(); + LOGGER.info("vfModuleId is Matched"); + try { + vfmodules.getVfModule().stream().filter(tempVfModule -> + tempVfModule.getVfModuleId().equalsIgnoreCase(vfModuleId)).forEach(tempVfModule -> + tempVfModule.setOrchestrationStatus(vfModule.getOrchestrationStatus())); + return true; + } catch (final Exception exception) { + LOGGER.error("Unable to update VfModule for vfModuleId: {}", vfModule, exception); + } + } + LOGGER.error("Unable to find VfModule ..."); + return false; + } }