diff options
Diffstat (limited to 'plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers')
4 files changed, 232 insertions, 30 deletions
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProvider.java index 6facac82..e4d6cb73 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProvider.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProvider.java @@ -23,6 +23,7 @@ import java.util.Optional; import org.onap.aai.domain.yang.CloudRegion; import org.onap.aai.domain.yang.EsrSystemInfo; import org.onap.aai.domain.yang.EsrSystemInfoList; +import org.onap.aai.domain.yang.K8SResource; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.Tenant; import org.onap.aai.domain.yang.Vserver; @@ -63,7 +64,20 @@ public interface CloudRegionCacheServiceProvider extends Clearable { Optional<Relationship> addvServerRelationShip(final CloudRegionKey key, final String tenantId, final String vServerId, final Relationship relationship, final String requestUri); - boolean addVServerRelationShip(final HttpHeaders incomingHeader, final String targetBaseUrl, final String requestURI, final CloudRegionKey key, - final String tenantId, final String vServerId, final Relationship relationship); + boolean addVServerRelationShip(final HttpHeaders incomingHeader, final String targetBaseUrl, + final String requestURI, final CloudRegionKey key, final String tenantId, final String vServerId, + final Relationship relationship); + + boolean putK8sResource(final CloudRegionKey key, final String tenantId, final String id, + final K8SResource k8sResource); + + Optional<K8SResource> getK8sResource(final CloudRegionKey key, final String tenantId, final String id); + + boolean addK8sResourceRelationShip(final HttpHeaders incomingHeader, final String targetBaseUrl, + final String requestURI, final CloudRegionKey key, final String tenantId, final String id, + final Relationship relationship); + + boolean deleteK8sResource(final CloudRegionKey key, final String tenantId, final String id, + final String resourceVersion); } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProviderImpl.java index f1f782a0..f15b389c 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProviderImpl.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/CloudRegionCacheServiceProviderImpl.java @@ -26,10 +26,14 @@ import static org.onap.so.aaisimulator.utils.Constants.CLOUD_REGION_CLOUD_OWNER; import static org.onap.so.aaisimulator.utils.Constants.CLOUD_REGION_CLOUD_REGION_ID; import static org.onap.so.aaisimulator.utils.Constants.CLOUD_REGION_OWNER_DEFINED_TYPE; import static org.onap.so.aaisimulator.utils.Constants.HOSTED_ON; +import static org.onap.so.aaisimulator.utils.Constants.K8S_RESOURCE; +import static org.onap.so.aaisimulator.utils.Constants.K8S_RESOURCE_ID; +import static org.onap.so.aaisimulator.utils.Constants.K8S_RESOURCE_NAME; import static org.onap.so.aaisimulator.utils.Constants.LOCATED_IN; import static org.onap.so.aaisimulator.utils.Constants.TENANT; import static org.onap.so.aaisimulator.utils.Constants.TENANT_TENANT_ID; import static org.onap.so.aaisimulator.utils.Constants.TENANT_TENANT_NAME; +import static org.onap.so.aaisimulator.utils.Constants.USES; import static org.onap.so.aaisimulator.utils.Constants.VSERVER; import static org.onap.so.aaisimulator.utils.Constants.VSERVER_VSERVER_ID; import static org.onap.so.aaisimulator.utils.Constants.VSERVER_VSERVER_NAME; @@ -41,6 +45,8 @@ import java.util.Optional; import org.onap.aai.domain.yang.CloudRegion; import org.onap.aai.domain.yang.EsrSystemInfo; import org.onap.aai.domain.yang.EsrSystemInfoList; +import org.onap.aai.domain.yang.K8SResource; +import org.onap.aai.domain.yang.K8SResources; import org.onap.aai.domain.yang.RelatedToProperty; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.RelationshipData; @@ -67,8 +73,6 @@ import org.springframework.stereotype.Service; public class CloudRegionCacheServiceProviderImpl extends AbstractCacheServiceProvider implements CloudRegionCacheServiceProvider { - - private static final Logger LOGGER = LoggerFactory.getLogger(CloudRegionCacheServiceProviderImpl.class); private final HttpRestServiceProvider httpRestServiceProvider; @@ -332,6 +336,112 @@ public class CloudRegionCacheServiceProviderImpl extends AbstractCacheServicePro } @Override + public boolean putK8sResource(final CloudRegionKey key, final String tenantId, final String id, + final K8SResource k8sResource) { + final Optional<Tenant> optional = getTenant(key, tenantId); + if (optional.isPresent()) { + final Tenant tenant = optional.get(); + K8SResources k8sResources = tenant.getK8SResources(); + if (k8sResources == null) { + k8sResources = new K8SResources(); + tenant.setK8SResources(k8sResources); + } + + + final Optional<K8SResource> existingK8sResource = k8sResources.getK8SResource().stream() + .filter(entry -> entry.getId() != null && entry.getId().equalsIgnoreCase(id)).findFirst(); + + if (existingK8sResource.isEmpty()) { + LOGGER.info("Adding k8sResources to cache..."); + return k8sResources.getK8SResource().add(k8sResource); + } + + LOGGER.warn("K8SResource already exists existingK8sResource: {}...", existingK8sResource.get()); + return false; + } + + LOGGER.error("Unable to add K8s Resource using key: {}, tenantId: {} and id: {}...", key, tenantId, id); + return false; + } + + @Override + public Optional<K8SResource> getK8sResource(final CloudRegionKey key, final String tenantId, final String id) { + final Optional<Tenant> optional = getTenant(key, tenantId); + + if (optional.isPresent()) { + + final Tenant tenant = optional.get(); + final K8SResources k8sResources = tenant.getK8SResources(); + if (k8sResources != null) { + return k8sResources.getK8SResource().stream() + .filter(entry -> entry.getId() != null && entry.getId().equalsIgnoreCase(id)).findFirst(); + } + + } + LOGGER.error("Unable to find K8sResource using key: {}, tenantId: {} and id: {}...", key, tenantId, id); + return Optional.empty(); + } + + @Override + public boolean addK8sResourceRelationShip(final HttpHeaders incomingHeader, final String targetBaseUrl, + final String requestUriString, final CloudRegionKey key, final String tenantId, final String id, + final Relationship relationship) { + try { + final Optional<K8SResource> optional = getK8sResource(key, tenantId, id); + if (optional.isPresent()) { + final K8SResource k8sResource = optional.get(); + final String targetUrl = getTargetUrl(targetBaseUrl, relationship.getRelatedLink()); + final Relationship outGoingRelationShip = + getRelationship(key, tenantId, k8sResource, getRelationShipListRelatedLink(requestUriString)); + final Optional<Relationship> optionalRelationship = httpRestServiceProvider.put(incomingHeader, + outGoingRelationShip, targetUrl, Relationship.class); + + if (optionalRelationship.isPresent()) { + final Relationship resultantRelationship = optionalRelationship.get(); + + RelationshipList relationshipList = k8sResource.getRelationshipList(); + if (relationshipList == null) { + relationshipList = new RelationshipList(); + k8sResource.setRelationshipList(relationshipList); + } + if (relationshipList.getRelationship().add(resultantRelationship)) { + LOGGER.info("added relationship {} in cache successfully", resultantRelationship); + return true; + } + } + + } + } catch (final Exception exception) { + LOGGER.error("Unable to add two-way relationship for key: {}, tenantId: {} and id: {}", key, tenantId, id, + exception); + } + LOGGER.error("Unable to add K8sResource relationship for key: {}, tenantId: {} and id: {}...", key, tenantId, + id); + return false; + } + + private Relationship getRelationship(final CloudRegionKey key, final String tenantId, final K8SResource k8sResource, + final String relatedLink) { + final Relationship relationShip = new Relationship(); + relationShip.setRelatedTo(K8S_RESOURCE); + relationShip.setRelationshipLabel(USES); + relationShip.setRelatedLink(relatedLink); + + final List<RelationshipData> relationshipDataList = relationShip.getRelationshipData(); + relationshipDataList.add(getRelationshipData(CLOUD_REGION_CLOUD_OWNER, key.getCloudOwner())); + relationshipDataList.add(getRelationshipData(CLOUD_REGION_CLOUD_REGION_ID, key.getCloudRegionId())); + relationshipDataList.add(getRelationshipData(TENANT_TENANT_ID, tenantId)); + relationshipDataList.add(getRelationshipData(K8S_RESOURCE_ID, k8sResource.getId())); + + final RelatedToProperty relatedToProperty = new RelatedToProperty(); + relatedToProperty.setPropertyKey(K8S_RESOURCE_NAME); + relatedToProperty.setPropertyValue(k8sResource.getName()); + relationShip.getRelatedToProperty().add(relatedToProperty); + + return relationShip; + } + + @Override public Optional<Relationship> addvServerRelationShip(final CloudRegionKey key, final String tenantId, final String vServerId, final Relationship relationship, final String requestUri) { final Optional<Vserver> optional = getVserver(key, tenantId, vServerId); @@ -468,4 +578,29 @@ public class CloudRegionCacheServiceProviderImpl extends AbstractCacheServicePro } + @Override + public boolean deleteK8sResource(final CloudRegionKey key, final String tenantId, final String id, + final String resourceVersion) { + final Optional<Tenant> optional = getTenant(key, tenantId); + if (optional.isPresent()) { + final Tenant tenant = optional.get(); + K8SResources k8sResources = tenant.getK8SResources(); + if (k8sResources != null) { + final Optional<K8SResource> existingK8sResource = k8sResources.getK8SResource().stream() + .filter(entry -> entry.getId() != null && entry.getId().equalsIgnoreCase(id)).findFirst(); + + if (existingK8sResource.isPresent() + && existingK8sResource.get().getResourceVersion().equals(resourceVersion)) { + LOGGER.info("k8sResources found in cache and removing the same."); + return k8sResources.getK8SResource().remove(existingK8sResource.get()); + } + } + else { + return true; + } + } + + LOGGER.error("Unable to add K8s Resource using key: {}, tenantId: {} and id: {}...", key, tenantId, id); + return false; + } } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProvider.java index 5570381b..14b823c2 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProvider.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aaisimulator/service/providers/GenericVnfCacheServiceProvider.java @@ -46,7 +46,7 @@ public interface GenericVnfCacheServiceProvider extends Clearable { boolean patchGenericVnf(final String vnfId, final GenericVnf genericVnf); - List<GenericVnf> getGenericVnfs(final String selflink); + List<GenericVnf> getGenericVnfs(); boolean deleteGenericVnf(final String vnfId, final String resourceVersion); @@ -55,4 +55,9 @@ public interface GenericVnfCacheServiceProvider extends Clearable { Optional<VfModule> getVfModule(final String vnfId, final String vfModuleId); boolean patchVfModule(final String vnfId, final String vfModuleId, final VfModule vfModule); + + Optional<Relationship> addRelationShip(String vnfId, String vfModuleId, Relationship relationship, + String requestURI); + + boolean deleteVfModule(final String vnfId, final String vfModuleId, final String resourceVersion); } 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 24544a6c..0a266489 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 @@ -24,6 +24,9 @@ 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.USES; +import static org.onap.so.aaisimulator.utils.Constants.VF_MODULE; +import static org.onap.so.aaisimulator.utils.Constants.VF_MODULE_VF_MODULE_ID; 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; @@ -186,34 +189,27 @@ public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProv } @Override - public List<GenericVnf> getGenericVnfs(final String selflink) { + public List<GenericVnf> getGenericVnfs() { final Cache cache = getCache(GENERIC_VNF_CACHE.getName()); if (cache != null) { final Object nativeCache = cache.getNativeCache(); if (nativeCache instanceof ConcurrentHashMap) { @SuppressWarnings("unchecked") final ConcurrentHashMap<Object, Object> concurrentHashMap = - (ConcurrentHashMap<Object, Object>) nativeCache; + (ConcurrentHashMap<Object, Object>) nativeCache; final List<GenericVnf> result = new ArrayList<>(); - concurrentHashMap.keySet().stream().forEach(key -> { + concurrentHashMap.keySet().forEach(key -> { final Optional<GenericVnf> optional = getGenericVnf(key.toString()); if (optional.isPresent()) { final GenericVnf genericVnf = optional.get(); - final String genericVnfSelfLink = genericVnf.getSelflink(); - final String genericVnfId = genericVnf.getSelflink(); - - if (genericVnfSelfLink != null && genericVnfSelfLink.equals(selflink)) { - LOGGER.info("Found matching vnf for selflink: {}, vnf-id: {}", genericVnfSelfLink, - genericVnfId); - result.add(genericVnf); - } + result.add(genericVnf); } }); return result; } } - LOGGER.error("No match found for selflink: {}", selflink); + LOGGER.error("No match found"); return Collections.emptyList(); } @@ -259,14 +255,13 @@ public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProv @Override public Optional<VfModule> getVfModule(final String vnfId, final String vfModuleId) { - LOGGER.info("Getting vfModule from cache for vnfId: {} and vfModuleId: {}", - vnfId, vfModuleId); + LOGGER.info("Getting vfModule from cache for vnfId: {} and vfModuleId: {}", vnfId, vfModuleId); final Optional<GenericVnf> 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)){ + for (final VfModule vfModule : vfmodules.getVfModule()) { + if (vfModule.getVfModuleId().equalsIgnoreCase(vfModuleId)) { return Optional.of(vfModule); } } @@ -277,14 +272,13 @@ public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProv @Override public void putVfModule(final String vnfId, final String vfModuleId, final VfModule vfModule) { - LOGGER.info("Adding vfModule for vnfId: {} and vfModuleId: {}", - vnfId, vfModuleId); + LOGGER.info("Adding vfModule 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 vfModules = null; - if(genericVnf.getVfModules()==null){ + if (genericVnf.getVfModules() == null) { vfModules = new VfModules(); genericVnf.setVfModules(vfModules); } else { @@ -299,16 +293,15 @@ public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProv @Override public boolean patchVfModule(final String vnfId, final String vfModuleId, final VfModule vfModule) { final Optional<GenericVnf> genericVnfOptional = getGenericVnf(vnfId); - LOGGER.info("Create vfModule for vnfId: {} and vfModuleId: {}", - vnfId, vfModuleId); + 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())); + 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); @@ -317,4 +310,59 @@ public class GenericVnfCacheServiceProviderImpl extends AbstractCacheServiceProv LOGGER.error("Unable to find VfModule ..."); return false; } -}
\ No newline at end of file + + @Override + public Optional<Relationship> addRelationShip(final String vnfId, final String vfModuleId, + final Relationship relationship, final String requestURI) { + final Optional<VfModule> optional = getVfModule(vnfId, vfModuleId); + if (optional.isPresent()) { + final VfModule vfModule = optional.get(); + + RelationshipList relationshipList = vfModule.getRelationshipList(); + if (relationshipList == null) { + relationshipList = new RelationshipList(); + vfModule.setRelationshipList(relationshipList); + } + relationshipList.getRelationship().add(relationship); + LOGGER.info("Successfully added relation to VfModule for vnfId: {} and vfModuleId: {}", vnfId, vfModuleId); + + final String relatedLink = getBiDirectionalRelationShipListRelatedLink(requestURI); + + final Relationship resultantRelationship = new Relationship(); + resultantRelationship.setRelatedTo(VF_MODULE); + resultantRelationship.setRelationshipLabel(USES); + resultantRelationship.setRelatedLink(relatedLink); + + final RelationshipData genericVnfRelationshipData = new RelationshipData(); + genericVnfRelationshipData.setRelationshipKey(GENERIC_VNF_VNF_ID); + genericVnfRelationshipData.setRelationshipValue(vnfId); + resultantRelationship.getRelationshipData().add(genericVnfRelationshipData); + + final RelationshipData vfModuleRelationshipData = new RelationshipData(); + vfModuleRelationshipData.setRelationshipKey(VF_MODULE_VF_MODULE_ID); + vfModuleRelationshipData.setRelationshipValue(vfModuleId); + resultantRelationship.getRelationshipData().add(vfModuleRelationshipData); + return Optional.of(resultantRelationship); + } + + LOGGER.error("Unable to find VfModule ..."); + return Optional.empty(); + } + + @Override + public boolean deleteVfModule(final String vnfId, final String vfModuleId, final String resourceVersion) { + final Optional<GenericVnf> genericVnfOptional = getGenericVnf(vnfId); + final Optional<VfModule> vfModuleOptional = getVfModule(vnfId, vfModuleId); + if (genericVnfOptional.isPresent() && vfModuleOptional.isPresent()) { + final GenericVnf genericVnf = genericVnfOptional.get(); + final VfModule vfModule = vfModuleOptional.get(); + if (genericVnf.getVfModules() != null && vfModule.getResourceVersion().equals(resourceVersion)) { + LOGGER.info("VfModule: {} deleted from the Generic VNF: {}",vfModuleId, vnfId); + return genericVnf.getVfModules().getVfModule().remove(vfModule); + } + } + LOGGER.error("There are no VfModules associated to vnf ID: {}", vnfId); + return false; + } + +} |