diff options
author | waqas.ikram <waqas.ikram@est.tech> | 2019-07-31 14:30:55 +0000 |
---|---|---|
committer | Waqas Ikram <waqas.ikram@est.tech> | 2019-07-31 14:31:34 +0000 |
commit | bf6e301bdedc4285cdd05826e29bdcbd68f8a699 (patch) | |
tree | 861616d982431272cd1b6d70485d89bd4f0fe5eb /plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap | |
parent | 50e113e064e31aed7435ac814e4776b72f842c8f (diff) |
Adding owning-entity endpoint
Change-Id: I2d0e05bc8563d86be38440dcbed7b2abcfe6411c
Issue-ID: SO-1953
Signed-off-by: waqas.ikram <waqas.ikram@est.tech>
Diffstat (limited to 'plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap')
13 files changed, 471 insertions, 53 deletions
diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/configration/ApplicationConfigration.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/configration/ApplicationConfigration.java index af00ba78..b1f17796 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/configration/ApplicationConfigration.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/configration/ApplicationConfigration.java @@ -21,8 +21,10 @@ package org.onap.so.aai.simulator.configration; import static org.onap.so.aai.simulator.utils.Constants.CUSTOMER_CACHE; import static org.onap.so.aai.simulator.utils.Constants.NODES_CACHE; +import static org.onap.so.aai.simulator.utils.Constants.OWNING_ENTITY_CACHE; import static org.onap.so.aai.simulator.utils.Constants.PROJECT_CACHE; import java.util.Arrays; +import java.util.List; import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; @@ -47,7 +49,9 @@ public class ApplicationConfigration { @Bean public CacheManager cacheManager() { final SimpleCacheManager manager = new SimpleCacheManager(); - manager.setCaches(Arrays.asList(getCache(CUSTOMER_CACHE), getCache(PROJECT_CACHE), getCache(NODES_CACHE))); + final List<Cache> caches = Arrays.asList(getCache(CUSTOMER_CACHE), getCache(PROJECT_CACHE), + getCache(NODES_CACHE), getCache(OWNING_ENTITY_CACHE)); + manager.setCaches(caches); return manager; } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/BusinessController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/BusinessController.java index e7fd00de..0189a427 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/BusinessController.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/BusinessController.java @@ -20,9 +20,9 @@ package org.onap.so.aai.simulator.controller; import static org.onap.so.aai.simulator.utils.Constants.CUSTOMER_URL; -import static org.onap.so.aai.simulator.utils.Constants.ERROR_MESSAGE; -import static org.onap.so.aai.simulator.utils.Constants.ERROR_MESSAGE_ID; import static org.onap.so.aai.simulator.utils.Constants.SERVICE_RESOURCE_TYPE; +import static org.onap.so.aai.simulator.utils.Constants.X_HTTP_METHOD_OVERRIDE; +import static org.onap.so.aai.simulator.utils.Utils.getRequestErrorResponseEntity; import static org.onap.so.aai.simulator.utils.Utils.getResourceVersion; import java.util.Optional; import javax.servlet.http.HttpServletRequest; @@ -34,17 +34,18 @@ import org.onap.aai.domain.yang.ServiceSubscription; import org.onap.so.aai.simulator.models.NodeServiceInstance; import org.onap.so.aai.simulator.service.providers.CustomerCacheServiceProvider; import org.onap.so.aai.simulator.service.providers.NodesCacheServiceProvider; -import org.onap.so.aai.simulator.utils.RequestErrorBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.http.HttpStatus; +import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestHeader; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestParam; @@ -56,6 +57,8 @@ import org.springframework.web.bind.annotation.RequestParam; @RequestMapping(path = CUSTOMER_URL) public class BusinessController { + private static final String SERVICE_SUBSCRIPTION = "service-subscription"; + private static final String CUSTOMER_TYPE = "Customer"; private static final Logger LOGGER = LoggerFactory.getLogger(BusinessController.class); private final CustomerCacheServiceProvider cacheServiceProvider; private final NodesCacheServiceProvider nodesCacheServiceProvider; @@ -80,7 +83,7 @@ public class BusinessController { } LOGGER.error("Couldn't find {} in cache", globalCustomerId); - return getRequestErrorResponseEntity(request); + return getRequestErrorResponseEntity(request, CUSTOMER_TYPE); } @PutMapping(value = "/{global-customer-id}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, @@ -115,9 +118,27 @@ public class BusinessController { LOGGER.error("Couldn't find 'global customer id': {} and 'service type': {} in cache", globalCustomerId, serviceType); - return getRequestErrorResponseEntity(request); + return getRequestErrorResponseEntity(request, SERVICE_SUBSCRIPTION); } + @PutMapping(value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}", + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity<?> putServiceSubscription(@PathVariable("global-customer-id") final String globalCustomerId, + @PathVariable("service-type") final String serviceType, + @RequestBody final ServiceSubscription serviceSubscription, final HttpServletRequest request) { + LOGGER.info("Will add service subscription for 'global customer id': {} and 'service type': {} ...", + globalCustomerId, serviceType); + + if (cacheServiceProvider.putServiceSubscription(globalCustomerId, serviceType, serviceSubscription)) { + LOGGER.info("Successfully add service subscription in cache ..."); + return ResponseEntity.accepted().build(); + } + + LOGGER.error("Couldn't add service subscription using 'global customer id': {} and 'service type': {}", + globalCustomerId, serviceType); + return getRequestErrorResponseEntity(request, SERVICE_SUBSCRIPTION); + } + @GetMapping( value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @@ -177,6 +198,7 @@ public class BusinessController { public ResponseEntity<?> putSericeInstance(@PathVariable("global-customer-id") final String globalCustomerId, @PathVariable("service-type") final String serviceType, @PathVariable(name = "service-instance-id") final String serviceInstanceId, + @RequestHeader(value = X_HTTP_METHOD_OVERRIDE, required = false) final String invocationId, @RequestBody final ServiceInstance serviceInstance, final HttpServletRequest request) { LOGGER.info( @@ -199,12 +221,28 @@ public class BusinessController { return getRequestErrorResponseEntity(request); } - private ResponseEntity<?> getRequestErrorResponseEntity(final HttpServletRequest request) { - return new ResponseEntity<>(new RequestErrorBuilder().messageId(ERROR_MESSAGE_ID).text(ERROR_MESSAGE) - .variables(request.getMethod(), request.getRequestURI(), - "Node Not Found:No Node of type service-instance found at: " + request.getRequestURI(), - "ERR.5.4.6114") - .build(), HttpStatus.NOT_FOUND); + @PostMapping( + value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}", + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity<?> patchSericeInstance(@PathVariable("global-customer-id") final String globalCustomerId, + @PathVariable("service-type") final String serviceType, + @PathVariable(name = "service-instance-id") final String serviceInstanceId, + @RequestHeader(value = X_HTTP_METHOD_OVERRIDE, required = false) final String xHttpHeaderOverride, + @RequestBody final ServiceInstance serviceInstance, final HttpServletRequest request) { + + LOGGER.info( + "Will post service instance for 'global customer id': {}, 'service type': {}, 'service instance id: '{} and '{}': {}...", + globalCustomerId, serviceType, serviceInstanceId, X_HTTP_METHOD_OVERRIDE, xHttpHeaderOverride); + + if (HttpMethod.PATCH.toString().equalsIgnoreCase(xHttpHeaderOverride)) { + cacheServiceProvider.patchServiceInstance(globalCustomerId, serviceType, serviceInstanceId, + serviceInstance); + return ResponseEntity.accepted().build(); + } + LOGGER.error("{} not supported ... ", xHttpHeaderOverride); + + return getRequestErrorResponseEntity(request); } + } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/OwningEntityController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/OwningEntityController.java new file mode 100644 index 00000000..e3d6b4f7 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/OwningEntityController.java @@ -0,0 +1,127 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.aai.simulator.controller; + +import static org.onap.so.aai.simulator.utils.Constants.OWNING_ENTITY; +import static org.onap.so.aai.simulator.utils.Constants.OWNING_ENTITY_URL; +import static org.onap.so.aai.simulator.utils.Utils.getRequestErrorResponseEntity; +import static org.onap.so.aai.simulator.utils.Utils.getResourceVersion; +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; +import javax.servlet.http.HttpServletRequest; +import javax.ws.rs.core.MediaType; +import org.onap.aai.domain.yang.OwningEntity; +import org.onap.aai.domain.yang.Relationship; +import org.onap.so.aai.simulator.models.Format; +import org.onap.so.aai.simulator.models.Result; +import org.onap.so.aai.simulator.service.providers.OwnEntityCacheServiceProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.ResponseEntity; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@Controller +@RequestMapping(path = OWNING_ENTITY_URL) +public class OwningEntityController { + + private static final Logger LOGGER = LoggerFactory.getLogger(OwningEntityController.class); + + private final OwnEntityCacheServiceProvider cacheServiceProvider; + + @Autowired + public OwningEntityController(final OwnEntityCacheServiceProvider cacheServiceProvider) { + this.cacheServiceProvider = cacheServiceProvider; + } + + + @PutMapping(value = "{owning-entity-id}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity<?> putOwningEntity(@RequestBody final OwningEntity owningEntity, + @PathVariable("owning-entity-id") final String owningEntityId, final HttpServletRequest request) { + LOGGER.info("Will add OwningEntity to cache with key 'owning-entity-id': {} ...", + owningEntity.getOwningEntityId()); + + if (owningEntity.getResourceVersion() == null || owningEntity.getResourceVersion().isEmpty()) { + owningEntity.setResourceVersion(getResourceVersion()); + + } + cacheServiceProvider.putOwningEntity(owningEntityId, owningEntity); + return ResponseEntity.accepted().build(); + } + + @GetMapping(value = "{owning-entity-id}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity<?> getOwningEntity(@PathVariable("owning-entity-id") final String owningEntityId, + @RequestParam(name = "resultIndex", required = false) final Integer resultIndex, + @RequestParam(name = "resultSize", required = false) final Integer resultSize, + @RequestParam(name = "format", required = false) final String format, final HttpServletRequest request) { + LOGGER.info("retrieving owning entity for 'owning-entity-id': {} ...", owningEntityId); + + final Optional<OwningEntity> optional = cacheServiceProvider.getOwningEntity(owningEntityId); + if (!optional.isPresent()) { + LOGGER.error("Couldn't find {} in cache", owningEntityId); + return getRequestErrorResponseEntity(request); + } + + final Format value = Format.forValue(format); + switch (value) { + case RAW: + final OwningEntity owningEntity = optional.get(); + LOGGER.info("found OwningEntity {} in cache", owningEntity); + return ResponseEntity.ok(owningEntity); + case COUNT: + final Map<String, Object> map = new HashMap<>(); + map.put(OWNING_ENTITY, 1); + return ResponseEntity.ok(new Result(map)); + default: + break; + } + LOGGER.error("invalid format type :{}", format); + return getRequestErrorResponseEntity(request); + } + + @PutMapping(value = "/{owning-entity-id}/relationship-list/relationship", + consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity<?> putOwningEntityRelationShip(@RequestBody final Relationship relationship, + @PathVariable("owning-entity-id") final String owningEntityId, final HttpServletRequest request) { + + LOGGER.info("adding relationship for owning-entity-id: {} ...", owningEntityId); + if (cacheServiceProvider.putOwningEntityRelationShip(owningEntityId, relationship)) { + LOGGER.info("added OwningEntity relationship {} in cache", relationship); + return ResponseEntity.accepted().build(); + } + LOGGER.error("Couldn't add relationship for {} in cache", owningEntityId); + return getRequestErrorResponseEntity(request); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/ProjectController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/ProjectController.java index 5f63494d..0c3b3b7b 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/ProjectController.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/ProjectController.java @@ -19,6 +19,7 @@ */ package org.onap.so.aai.simulator.controller; +import static org.onap.so.aai.simulator.utils.Constants.PROJECT; import static org.onap.so.aai.simulator.utils.Constants.PROJECT_URL; import static org.onap.so.aai.simulator.utils.Utils.getRequestErrorResponseEntity; import static org.onap.so.aai.simulator.utils.Utils.getResourceVersion; @@ -97,15 +98,13 @@ public class ProjectController { return ResponseEntity.ok(project); case COUNT: final Map<String, Object> map = new HashMap<>(); - map.put(projectName, 1); + map.put(PROJECT, 1); return ResponseEntity.ok(new Result(map)); default: break; } LOGGER.error("invalid format type :{}", format); return getRequestErrorResponseEntity(request); - - } @PutMapping(value = "/{project-name}/relationship-list/relationship", diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/AbstractCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/AbstractCacheServiceProvider.java new file mode 100644 index 00000000..4a45e81e --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/AbstractCacheServiceProvider.java @@ -0,0 +1,55 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.aai.simulator.service.providers; + +import java.util.concurrent.ConcurrentHashMap; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.cache.Cache; +import org.springframework.cache.CacheManager; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public abstract class AbstractCacheServiceProvider { + + private final Logger LOGGER = LoggerFactory.getLogger(this.getClass()); + + private final CacheManager cacheManager; + + public AbstractCacheServiceProvider(final CacheManager cacheManager) { + this.cacheManager = cacheManager; + } + + protected void clearCahce(final String name) { + final Cache cache = cacheManager.getCache(name); + if (cache != null) { + final ConcurrentHashMap<?, ?> nativeCache = (ConcurrentHashMap<?, ?>) cache.getNativeCache(); + LOGGER.info("Clear all entries from cahce: {}", cache.getName()); + nativeCache.clear(); + } + } + + protected Cache getCache(final String name) { + return cacheManager.getCache(name); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CustomerCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CustomerCacheServiceProvider.java index 51fc5546..713da545 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CustomerCacheServiceProvider.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CustomerCacheServiceProvider.java @@ -37,6 +37,9 @@ public interface CustomerCacheServiceProvider { Optional<ServiceSubscription> getServiceSubscription(final String globalCustomerId, final String serviceType); + boolean putServiceSubscription(final String globalCustomerId, final String serviceType, + final ServiceSubscription serviceSubscription); + Optional<ServiceInstances> getServiceInstances(final String globalCustomerId, final String serviceType, final String serviceInstanceName); @@ -46,6 +49,9 @@ public interface CustomerCacheServiceProvider { boolean putServiceInstance(final String globalCustomerId, final String serviceType, final String serviceInstanceId, final ServiceInstance serviceInstance); + boolean patchServiceInstance(final String globalCustomerId, final String serviceType, + final String serviceInstanceId, final ServiceInstance serviceInstance); + void clearAll(); } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CustomerCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CustomerCacheServiceProviderImpl.java index 11a82be8..c3b5a47d 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CustomerCacheServiceProviderImpl.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CustomerCacheServiceProviderImpl.java @@ -21,12 +21,12 @@ package org.onap.so.aai.simulator.service.providers; import java.util.List; import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; import java.util.stream.Collectors; import org.onap.aai.domain.yang.Customer; import org.onap.aai.domain.yang.ServiceInstance; import org.onap.aai.domain.yang.ServiceInstances; import org.onap.aai.domain.yang.ServiceSubscription; +import org.onap.aai.domain.yang.ServiceSubscriptions; import org.onap.so.aai.simulator.utils.Constants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,20 +40,20 @@ import org.springframework.stereotype.Service; * */ @Service -public class CustomerCacheServiceProviderImpl implements CustomerCacheServiceProvider { +public class CustomerCacheServiceProviderImpl extends AbstractCacheServiceProvider + implements CustomerCacheServiceProvider { private static final Logger LOGGER = LoggerFactory.getLogger(CustomerCacheServiceProviderImpl.class); - public final CacheManager cacheManager; @Autowired public CustomerCacheServiceProviderImpl(final CacheManager cacheManager) { - this.cacheManager = cacheManager; + super(cacheManager); } @Override public Optional<Customer> getCustomer(final String globalCustomerId) { LOGGER.info("getting customer from cache using key: {}", globalCustomerId); - final Cache cache = cacheManager.getCache(Constants.CUSTOMER_CACHE); + final Cache cache = getCache(Constants.CUSTOMER_CACHE); final Customer value = cache.get(globalCustomerId, Customer.class); if (value != null) { return Optional.of(value); @@ -64,7 +64,7 @@ public class CustomerCacheServiceProviderImpl implements CustomerCacheServicePro @Override public void putCustomer(final String globalCustomerId, final Customer customer) { LOGGER.info("Adding customer: {} with key: {} in cache ...", customer, globalCustomerId); - final Cache cache = cacheManager.getCache(Constants.CUSTOMER_CACHE); + final Cache cache = getCache(Constants.CUSTOMER_CACHE); cache.put(globalCustomerId, customer); } @@ -75,7 +75,7 @@ public class CustomerCacheServiceProviderImpl implements CustomerCacheServicePro LOGGER.info("getting service subscription from cache for globalCustomerId: {} and serviceType: {}", globalCustomerId, serviceType); - final Cache cache = cacheManager.getCache(Constants.CUSTOMER_CACHE); + final Cache cache = getCache(Constants.CUSTOMER_CACHE); final Customer value = cache.get(globalCustomerId, Customer.class); @@ -91,7 +91,7 @@ public class CustomerCacheServiceProviderImpl implements CustomerCacheServicePro public Optional<ServiceInstances> getServiceInstances(final String globalCustomerId, final String serviceType, final String serviceInstanceName) { - final Cache cache = cacheManager.getCache(Constants.CUSTOMER_CACHE); + final Cache cache = getCache(Constants.CUSTOMER_CACHE); final Customer value = cache.get(globalCustomerId, Customer.class); if (value != null) { @@ -119,7 +119,7 @@ public class CustomerCacheServiceProviderImpl implements CustomerCacheServicePro @Override public Optional<ServiceInstance> getServiceInstance(final String globalCustomerId, final String serviceType, final String serviceInstanceId) { - final Cache cache = cacheManager.getCache(Constants.CUSTOMER_CACHE); + final Cache cache = getCache(Constants.CUSTOMER_CACHE); final Customer value = cache.get(globalCustomerId, Customer.class); if (value != null) { @@ -145,7 +145,7 @@ public class CustomerCacheServiceProviderImpl implements CustomerCacheServicePro final String serviceInstanceId, final ServiceInstance serviceInstance) { LOGGER.info("Adding serviceInstance: {} in cache ...", serviceInstance, globalCustomerId); - final Cache cache = cacheManager.getCache(Constants.CUSTOMER_CACHE); + final Cache cache = getCache(Constants.CUSTOMER_CACHE); final Customer value = cache.get(globalCustomerId, Customer.class); if (value != null) { @@ -171,6 +171,48 @@ public class CustomerCacheServiceProviderImpl implements CustomerCacheServicePro return false; } + @Override + public boolean putServiceSubscription(final String globalCustomerId, final String serviceType, + final ServiceSubscription serviceSubscription) { + + final Optional<Customer> customerOptional = getCustomer(globalCustomerId); + + if (customerOptional.isPresent()) { + final Customer customer = customerOptional.get(); + if (customer.getServiceSubscriptions() == null) { + final ServiceSubscriptions serviceSubscriptions = new ServiceSubscriptions(); + customer.setServiceSubscriptions(serviceSubscriptions); + return serviceSubscriptions.getServiceSubscription().add(serviceSubscription); + } + + final Optional<ServiceSubscription> serviceSubscriptionOptional = customer.getServiceSubscriptions() + .getServiceSubscription().stream().filter(s -> serviceType.equals(s.getServiceType())).findFirst(); + + if (!serviceSubscriptionOptional.isPresent()) { + return customer.getServiceSubscriptions().getServiceSubscription().add(serviceSubscription); + } + LOGGER.error("ServiceSubscription already exists {}", serviceSubscriptionOptional.get().getServiceType()); + return false; + } + LOGGER.error("Unable to add ServiceSubscription to cache becuase customer does not exits ..."); + return false; + } + + @Override + public boolean patchServiceInstance(final String globalCustomerId, final String serviceType, + final String serviceInstanceId, final ServiceInstance serviceInstance) { + final Optional<ServiceInstance> instance = getServiceInstance(globalCustomerId, serviceType, serviceInstanceId); + if (instance.isPresent()) { + final ServiceInstance cachedServiceInstance = instance.get(); + LOGGER.info("Changing OrchestrationStatus from {} to {} ", cachedServiceInstance.getOrchestrationStatus(), + serviceInstance.getOrchestrationStatus()); + cachedServiceInstance.setOrchestrationStatus(serviceInstance.getOrchestrationStatus()); + return true; + } + LOGGER.error("Unable to find ServiceInstance ..."); + return false; + } + private ServiceInstances getServiceInstances(final Optional<ServiceSubscription> optional) { final ServiceSubscription serviceSubscription = optional.get(); final ServiceInstances serviceInstances = serviceSubscription.getServiceInstances(); @@ -184,10 +226,7 @@ public class CustomerCacheServiceProviderImpl implements CustomerCacheServicePro @Override public void clearAll() { - final Cache cache = cacheManager.getCache(Constants.CUSTOMER_CACHE); - final ConcurrentHashMap<?, ?> nativeCache = (ConcurrentHashMap<?, ?>) cache.getNativeCache(); - LOGGER.info("Clear all entries from cahce: {}", cache.getName()); - nativeCache.clear(); + clearCahce(Constants.CUSTOMER_CACHE); } } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/NodesCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/NodesCacheServiceProviderImpl.java index 61cb35a2..0f0ac114 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/NodesCacheServiceProviderImpl.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/NodesCacheServiceProviderImpl.java @@ -35,26 +35,25 @@ import org.springframework.stereotype.Service; * */ @Service -public class NodesCacheServiceProviderImpl implements NodesCacheServiceProvider { +public class NodesCacheServiceProviderImpl extends AbstractCacheServiceProvider implements NodesCacheServiceProvider { private static final Logger LOGGER = LoggerFactory.getLogger(NodesCacheServiceProviderImpl.class); - public final CacheManager cacheManager; @Autowired public NodesCacheServiceProviderImpl(final CacheManager cacheManager) { - this.cacheManager = cacheManager; + super(cacheManager); } @Override public void putNodeServiceInstance(final String serviceInstanceId, final NodeServiceInstance nodeServiceInstance) { - final Cache cache = cacheManager.getCache(NODES_CACHE); + final Cache cache = getCache(NODES_CACHE); LOGGER.info("Adding {} to cache with key: {}...", nodeServiceInstance, serviceInstanceId); cache.put(serviceInstanceId, nodeServiceInstance); } @Override public Optional<NodeServiceInstance> getNodeServiceInstance(final String serviceInstanceId) { - final Cache cache = cacheManager.getCache(NODES_CACHE); + final Cache cache = getCache(NODES_CACHE); final NodeServiceInstance value = cache.get(serviceInstanceId, NodeServiceInstance.class); if (value != null) { return Optional.of(value); @@ -65,7 +64,7 @@ public class NodesCacheServiceProviderImpl implements NodesCacheServiceProvider @Override public void clearAll() { - final Cache cache = cacheManager.getCache(NODES_CACHE); + final Cache cache = getCache(NODES_CACHE); final ConcurrentHashMap<?, ?> nativeCache = (ConcurrentHashMap<?, ?>) cache.getNativeCache(); LOGGER.info("Clear all entries from cahce: {}", cache.getName()); nativeCache.clear(); diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/OwnEntityCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/OwnEntityCacheServiceProvider.java new file mode 100644 index 00000000..a7b6409c --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/OwnEntityCacheServiceProvider.java @@ -0,0 +1,39 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.aai.simulator.service.providers; + +import java.util.Optional; +import org.onap.aai.domain.yang.OwningEntity; +import org.onap.aai.domain.yang.Relationship; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public interface OwnEntityCacheServiceProvider { + + void putOwningEntity(final String owningEntityId, final OwningEntity owningEntity); + + Optional<OwningEntity> getOwningEntity(final String owningEntityId); + + boolean putOwningEntityRelationShip(String owningEntityId, Relationship relationship); + + void clearAll(); +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/OwnEntityCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/OwnEntityCacheServiceProviderImpl.java new file mode 100644 index 00000000..6b7af022 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/OwnEntityCacheServiceProviderImpl.java @@ -0,0 +1,98 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ +package org.onap.so.aai.simulator.service.providers; + +import static org.onap.so.aai.simulator.utils.Constants.OWNING_ENTITY_CACHE; +import static org.onap.so.aai.simulator.utils.Constants.SERVICE_RESOURCE_TYPE; +import java.util.Optional; +import org.onap.aai.domain.yang.OwningEntity; +import org.onap.aai.domain.yang.Relationship; +import org.onap.aai.domain.yang.RelationshipList; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.cache.Cache; +import org.springframework.cache.CacheManager; +import org.springframework.stereotype.Service; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@Service +public class OwnEntityCacheServiceProviderImpl extends AbstractCacheServiceProvider + implements OwnEntityCacheServiceProvider { + + private static final Logger LOGGER = LoggerFactory.getLogger(OwnEntityCacheServiceProviderImpl.class); + private static final String RELATIONSHIPS_LABEL = "org.onap.relationships.inventory.BelongsTo"; + + @Autowired + public OwnEntityCacheServiceProviderImpl(final CacheManager cacheManager) { + super(cacheManager); + } + + @Override + public void putOwningEntity(final String owningEntityId, final OwningEntity owningEntity) { + LOGGER.info("Adding OwningEntity: {} with name to cache", owningEntityId, owningEntity); + final Cache cache = getCache(OWNING_ENTITY_CACHE); + cache.put(owningEntityId, owningEntity); + } + + @Override + public Optional<OwningEntity> getOwningEntity(final String owningEntityId) { + LOGGER.info("getting OwningEntity from cache using key: {}", owningEntityId); + final Cache cache = getCache(OWNING_ENTITY_CACHE); + final OwningEntity value = cache.get(owningEntityId, OwningEntity.class); + if (value != null) { + return Optional.of(value); + } + return Optional.empty(); + } + + @Override + public boolean putOwningEntityRelationShip(final String owningEntityId, final Relationship relationship) { + final Cache cache = getCache(OWNING_ENTITY_CACHE); + final OwningEntity value = cache.get(owningEntityId, OwningEntity.class); + if (value != null) { + RelationshipList relationshipList = value.getRelationshipList(); + if (relationshipList == null) { + relationshipList = new RelationshipList(); + value.setRelationshipList(relationshipList); + } + + if (relationship.getRelatedTo() == null) { + relationship.setRelatedTo(SERVICE_RESOURCE_TYPE); + } + if (relationship.getRelationshipLabel() == null) { + relationship.setRelationshipLabel(RELATIONSHIPS_LABEL); + } + + return relationshipList.getRelationship().add(relationship); + } + LOGGER.error("OwningEntity not found in cache for {}", owningEntityId); + return false; + } + + @Override + public void clearAll() { + clearCahce(OWNING_ENTITY_CACHE); + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/ProjectCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/ProjectCacheServiceProviderImpl.java index a1047887..4fca3119 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/ProjectCacheServiceProviderImpl.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/ProjectCacheServiceProviderImpl.java @@ -22,7 +22,6 @@ package org.onap.so.aai.simulator.service.providers; import static org.onap.so.aai.simulator.utils.Constants.PROJECT_CACHE; import static org.onap.so.aai.simulator.utils.Constants.SERVICE_RESOURCE_TYPE; import java.util.Optional; -import java.util.concurrent.ConcurrentHashMap; import org.onap.aai.domain.yang.Project; import org.onap.aai.domain.yang.Relationship; import org.onap.aai.domain.yang.RelationshipList; @@ -38,23 +37,23 @@ import org.springframework.stereotype.Service; * */ @Service -public class ProjectCacheServiceProviderImpl implements ProjectCacheServiceProvider { +public class ProjectCacheServiceProviderImpl extends AbstractCacheServiceProvider + implements ProjectCacheServiceProvider { private static final String RELATIONSHIPS_LABEL = "org.onap.relationships.inventory.Uses"; private static final Logger LOGGER = LoggerFactory.getLogger(ProjectCacheServiceProviderImpl.class); - public final CacheManager cacheManager; @Autowired public ProjectCacheServiceProviderImpl(final CacheManager cacheManager) { - this.cacheManager = cacheManager; + super(cacheManager); } @Override public void putProject(final String projectName, final Project project) { LOGGER.info("Adding project: {} with name to cache", project, projectName); - final Cache cache = cacheManager.getCache(PROJECT_CACHE); + final Cache cache = getCache(PROJECT_CACHE); cache.put(projectName, project); } @@ -62,7 +61,7 @@ public class ProjectCacheServiceProviderImpl implements ProjectCacheServiceProvi @Override public Optional<Project> getProject(final String projectName) { LOGGER.info("getting project from cache using key: {}", projectName); - final Cache cache = cacheManager.getCache(PROJECT_CACHE); + final Cache cache = getCache(PROJECT_CACHE); final Project value = cache.get(projectName, Project.class); if (value != null) { return Optional.of(value); @@ -72,7 +71,7 @@ public class ProjectCacheServiceProviderImpl implements ProjectCacheServiceProvi @Override public boolean putProjectRelationShip(final String projectName, final Relationship relationship) { - final Cache cache = cacheManager.getCache(PROJECT_CACHE); + final Cache cache = getCache(PROJECT_CACHE); final Project value = cache.get(projectName, Project.class); if (value != null) { RelationshipList relationshipList = value.getRelationshipList(); @@ -90,15 +89,13 @@ public class ProjectCacheServiceProviderImpl implements ProjectCacheServiceProvi return relationshipList.getRelationship().add(relationship); } + LOGGER.error("Project not found in cache for {}", projectName); return false; } @Override public void clearAll() { - final Cache cache = cacheManager.getCache(PROJECT_CACHE); - final ConcurrentHashMap<?, ?> nativeCache = (ConcurrentHashMap<?, ?>) cache.getNativeCache(); - LOGGER.info("Clear all entries from cahce: {}", cache.getName()); - nativeCache.clear(); + clearCahce(PROJECT_CACHE); } } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/Constants.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/Constants.java index 1cb63360..3d1f85df 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/Constants.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/Constants.java @@ -35,6 +35,8 @@ public class Constants { public static final String PROJECT_URL = BUSINESS_URL + "/projects/project/"; + public static final String OWNING_ENTITY_URL = BUSINESS_URL + "/owning-entities/owning-entity"; + public static final String HEALTHY = "healthy"; public static final String CUSTOMER_CACHE = "customer-cache"; @@ -43,12 +45,20 @@ public class Constants { public static final String NODES_CACHE = "nodes-cache"; + public static final String OWNING_ENTITY_CACHE = "owning-entity-cache"; + + public static final String PROJECT = "project"; + + public static final String OWNING_ENTITY = "owning-entity"; + + public static final String X_HTTP_METHOD_OVERRIDE = "X-HTTP-Method-Override"; + public static final String ERROR_MESSAGE_ID = "SVC3001"; public static final String ERROR_MESSAGE = "Resource not found for %1 using id %2 (msg=%3) (ec=%4)"; public static final String SERVICE_RESOURCE_TYPE = "service-instance"; - + public static final String RESOURCE_LINK = "resource-link"; public static final String RESOURCE_TYPE = "resource-type"; diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/Utils.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/Utils.java index db90a235..81deb86b 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/Utils.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/Utils.java @@ -37,12 +37,19 @@ public class Utils { return System.currentTimeMillis() + EMPTY_STRING; } + public static ResponseEntity<?> getRequestErrorResponseEntity(final HttpServletRequest request, + final String nodeType) { + return new ResponseEntity<>( + new RequestErrorBuilder().messageId(ERROR_MESSAGE_ID).text(ERROR_MESSAGE) + .variables(request.getMethod(), request.getRequestURI(), "Node Not Found:No Node of " + nodeType + + " service-instance found at: " + request.getRequestURI(), "ERR.5.4.6114") + .build(), + HttpStatus.NOT_FOUND); + } + + public static ResponseEntity<?> getRequestErrorResponseEntity(final HttpServletRequest request) { - return new ResponseEntity<>(new RequestErrorBuilder().messageId(ERROR_MESSAGE_ID).text(ERROR_MESSAGE) - .variables(request.getMethod(), request.getRequestURI(), - "Node Not Found:No Node of type service-instance found at: " + request.getRequestURI(), - "ERR.5.4.6114") - .build(), HttpStatus.NOT_FOUND); + return getRequestErrorResponseEntity(request, Constants.SERVICE_RESOURCE_TYPE); } |