Added CSIT for Macroflow with HEAT
[integration/csit.git] / plans / so / integration-etsi-testing / so-simulators / aai-simulator / src / main / java / org / onap / so / aaisimulator / service / providers / GenericVnfCacheServiceProviderImpl.java
index 81a74f2..5a0423b 100644 (file)
@@ -24,6 +24,7 @@ import static org.onap.so.aaisimulator.utils.Constants.COMPOSED_OF;
 import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF;
 import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF_VNF_ID;
 import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF_VNF_NAME;
+import static org.onap.so.aaisimulator.utils.Constants.X_HTTP_METHOD_OVERRIDE;
 import static org.onap.so.aaisimulator.utils.HttpServiceUtils.getBiDirectionalRelationShipListRelatedLink;
 import static org.onap.so.aaisimulator.utils.HttpServiceUtils.getRelationShipListRelatedLink;
 import static org.onap.so.aaisimulator.utils.HttpServiceUtils.getTargetUrl;
@@ -37,6 +38,10 @@ 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.v10.VfModules;
+import org.onap.aai.domain.yang.VolumeGroup;
+import org.onap.aai.domain.yang.v10.VolumeGroups;
 import org.onap.so.aaisimulator.utils.ShallowBeanCopy;
 import org.onap.so.simulator.cache.provider.AbstractCacheServiceProvider;
 import org.slf4j.Logger;
@@ -58,6 +63,7 @@ public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProv
     private static final Logger LOGGER = LoggerFactory.getLogger(GenericVnfCacheServiceProviderImpl.class);
 
     private final HttpRestServiceProvider httpRestServiceProvider;
+    final org.onap.aai.domain.yang.VfModules vfModules = new org.onap.aai.domain.yang.VfModules();
 
     @Autowired
     public GenericVnfCacheServiceProviderImpl(final CacheManager cacheManager,
@@ -121,7 +127,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<Relationship> optionalRelationship = httpRestServiceProvider.put(incomingHeader,
                         outGoingRelationShip, targetUrl, Relationship.class);
                 if (optionalRelationship.isPresent()) {
@@ -160,7 +166,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();
@@ -214,10 +221,27 @@ public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProv
         return Collections.emptyList();
     }
 
-    private Relationship getRelationship(final String relatedLink, final GenericVnf genericVnf) {
+    @Override
+    public boolean deleteGenericVnf(final String vnfId, final String resourceVersion) {
+        final Optional<GenericVnf> optional = getGenericVnf(vnfId);
+        if (optional.isPresent()) {
+            final GenericVnf genericVnf = optional.get();
+            if (genericVnf.getResourceVersion() != null && genericVnf.getResourceVersion().equals(resourceVersion)) {
+                final Cache cache = getCache(GENERIC_VNF_CACHE.getName());
+                LOGGER.info("Will evict GenericVnf from cache with vnfId: {}", genericVnf.getVnfId());
+                cache.evict(vnfId);
+                return true;
+            }
+        }
+        LOGGER.error("Unable to find GenericVnf for vnfId: {} and resourceVersion: {} ...", vnfId, resourceVersion);
+        return false;
+    }
+
+    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();
@@ -237,4 +261,61 @@ public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProv
         clearCache(GENERIC_VNF_CACHE.getName());
     }
 
-}
+       @Override
+       public Optional<org.onap.aai.domain.yang.VfModule> getVfModule(final String vnfId, final String vfModuleId) {
+               LOGGER.info("Getting vfModule from cache for vnfId: {} and vfModuleId: {}",
+                               vnfId, vfModuleId);
+        final Cache cache = getCache(GENERIC_VNF_CACHE.getName());
+        final GenericVnf value = cache.get(vnfId, GenericVnf.class);
+        LOGGER.info("Getting vfModule from cache for vnfId: {} and vfModuleId: {}",
+                vnfId, vfModuleId);
+        if (value.getVfModules() != null) {
+            for (int i=0; i<value.getVfModules().getVfModule().size(); i++)
+            {
+                if(value.getVfModules().getVfModule().get(i).getVfModuleId().equalsIgnoreCase(vfModuleId)){
+                    return Optional.of(value.getVfModules().getVfModule().get(i));
+                }
+            }
+        }
+               return Optional.empty();
+       }
+
+       @Override
+       public void putVfModule(String vnfId, String vfModuleId, VfModule vfModule) {
+        LOGGER.info("Adding vfModule from cache for vnfId: {} and vfModuleId: {}",
+                vnfId, vfModuleId);
+        final Optional<GenericVnf> genericVnfOptional = getGenericVnf(vnfId);
+        final Cache cache = getCache(GENERIC_VNF_CACHE.getName());
+        if (genericVnfOptional.isPresent()) {
+            final GenericVnf genericVnf = genericVnfOptional.get();
+
+            vfModules.getVfModule().add(vfModule);
+            genericVnf.setVfModules(vfModules);
+            cache.put(vfModuleId, vfModule);
+        }
+       }
+
+       @Override
+       public boolean patchVfModule(String vnfId, String vfModuleId, VfModule vfModule) {
+               final Optional<GenericVnf> genericVnfOptional = getGenericVnf(vnfId);
+        LOGGER.info("Create vfModule for vnfId: {} and vfModuleId: {}",
+                vnfId, vfModuleId);
+        if (genericVnfOptional.isPresent()) {
+               final GenericVnf cachedGenericVnf = genericVnfOptional.get();
+            LOGGER.info("vfModuleId is Matched");
+            try {
+                for (int i=0; i<cachedGenericVnf.getVfModules().getVfModule().size(); i++)
+                {
+                          if(cachedGenericVnf.getVfModules().getVfModule().get(i).getVfModuleId().equalsIgnoreCase(vfModuleId)){
+                              cachedGenericVnf.getVfModules().getVfModule().get(i).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;
+       }
+}
\ No newline at end of file