diff options
Diffstat (limited to 'plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator')
11 files changed, 339 insertions, 47 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 2e19f01f..a2f47ade 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 @@ -19,8 +19,9 @@ */ 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.PROJECT_CACHE; import java.util.Arrays; -import org.onap.so.aai.simulator.utils.Constant; import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; @@ -44,9 +45,12 @@ public class ApplicationConfigration { @Bean public CacheManager cacheManager() { - final Cache inlineResponse201 = new ConcurrentMapCache(Constant.CUSTOMER_CACHE); final SimpleCacheManager manager = new SimpleCacheManager(); - manager.setCaches(Arrays.asList(inlineResponse201)); + manager.setCaches(Arrays.asList(getCache(CUSTOMER_CACHE), getCache(PROJECT_CACHE))); return manager; } + + private Cache getCache(final String name) { + return new ConcurrentMapCache(name); + } } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/configration/WebSecurityConfigImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/configration/WebSecurityConfigImpl.java index 2e96b9fd..a4a1fb11 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/configration/WebSecurityConfigImpl.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/configration/WebSecurityConfigImpl.java @@ -19,7 +19,7 @@ */ package org.onap.so.aai.simulator.configration; -import org.onap.so.aai.simulator.utils.Constant; +import org.onap.so.aai.simulator.utils.Constants; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; @@ -53,7 +53,7 @@ public class WebSecurityConfigImpl extends WebSecurityConfigurerAdapter { @Override protected void configure(final HttpSecurity http) throws Exception { - http.csrf().disable().authorizeRequests().antMatchers(Constant.BUSINESS_URL + "/**/**").authenticated().and() + http.csrf().disable().authorizeRequests().antMatchers(Constants.BUSINESS_URL + "/**/**").authenticated().and() .httpBasic(); } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/AaiSimulatorController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/AaiSimulatorController.java index 67cc34ff..af0a0150 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/AaiSimulatorController.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/AaiSimulatorController.java @@ -19,10 +19,9 @@ */ package org.onap.so.aai.simulator.controller; -import static org.onap.so.aai.simulator.utils.Constant.HEALTHY; -import javax.ws.rs.PathParam; +import static org.onap.so.aai.simulator.utils.Constants.HEALTHY; import javax.ws.rs.core.MediaType; -import org.onap.so.aai.simulator.utils.Constant; +import org.onap.so.aai.simulator.utils.Constants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.http.HttpStatus; @@ -37,7 +36,7 @@ import org.springframework.web.bind.annotation.ResponseStatus; * */ @Controller -@RequestMapping(path = Constant.BASE_URL) +@RequestMapping(path = Constants.BASE_URL) public class AaiSimulatorController { private static final Logger LOGGER = LoggerFactory.getLogger(AaiSimulatorController.class); 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 8f55d644..b5682f02 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 @@ -19,9 +19,10 @@ */ package org.onap.so.aai.simulator.controller; -import static org.onap.so.aai.simulator.utils.Constant.BUSINESS_URL; -import static org.onap.so.aai.simulator.utils.Constant.ERROR_MESSAGE; -import static org.onap.so.aai.simulator.utils.Constant.ERROR_MESSAGE_ID; +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.Utils.getResourceVersion; import java.util.Optional; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.MediaType; @@ -29,7 +30,7 @@ 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.so.aai.simulator.service.providers.CacheServiceProvider; +import org.onap.so.aai.simulator.service.providers.CustomerCacheServiceProvider; import org.onap.so.aai.simulator.utils.RequestErrorBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,19 +50,18 @@ import org.springframework.web.bind.annotation.RequestParam; * */ @Controller -@RequestMapping(path = BUSINESS_URL) +@RequestMapping(path = CUSTOMER_URL) public class BusinessController { private static final Logger LOGGER = LoggerFactory.getLogger(BusinessController.class); - private final CacheServiceProvider cacheServiceProvider; + private final CustomerCacheServiceProvider cacheServiceProvider; @Autowired - public BusinessController(final CacheServiceProvider cacheServiceProvider) { + public BusinessController(final CustomerCacheServiceProvider cacheServiceProvider) { this.cacheServiceProvider = cacheServiceProvider; } - @GetMapping(value = "/customers/customer/{global-customer-id}", - produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + @GetMapping(value = "{global-customer-id}", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public ResponseEntity<?> getCustomer(@PathVariable("global-customer-id") final String globalCustomerId, final HttpServletRequest request) { LOGGER.info("Will retrieve customer for 'global customer id': {} ...", globalCustomerId); @@ -77,8 +77,7 @@ public class BusinessController { return getRequestErrorResponseEntity(request); } - @PutMapping(value = "/customers/customer/{global-customer-id}", - consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, + @PutMapping(value = "/{global-customer-id}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public ResponseEntity<?> putCustomer(@RequestBody final Customer customer, @PathVariable("global-customer-id") final String globalCustomerId, final HttpServletRequest request) { @@ -93,8 +92,7 @@ public class BusinessController { } - @GetMapping( - value = "/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}", + @GetMapping(value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public ResponseEntity<?> getCustomer(@PathVariable("global-customer-id") final String globalCustomerId, @PathVariable("service-type") final String serviceType, final HttpServletRequest request) { @@ -115,7 +113,7 @@ public class BusinessController { } @GetMapping( - value = "/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances", + value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) public ResponseEntity<?> getSericeInstances(@PathVariable("global-customer-id") final String globalCustomerId, @PathVariable("service-type") final String serviceType, @@ -140,7 +138,7 @@ public class BusinessController { } @GetMapping( - value = "/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}", + 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<?> getSericeInstance(@PathVariable("global-customer-id") final String globalCustomerId, @PathVariable("service-type") final String serviceType, @@ -168,7 +166,7 @@ public class BusinessController { } @PutMapping( - value = "/customers/customer/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}", + 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<?> putSericeInstance(@PathVariable("global-customer-id") final String globalCustomerId, @PathVariable("service-type") final String serviceType, @@ -185,19 +183,14 @@ public class BusinessController { if (cacheServiceProvider.putServiceInstance(globalCustomerId, serviceType, serviceInstanceId, serviceInstance)) { - ResponseEntity.accepted().build(); + return ResponseEntity.accepted().build(); } - LOGGER.error( - "Couldn't add 'global customer id': {}, 'service type': {} and 'service instance id': {} with depth: {}, resultIndex:{}, resultSize: {} and format: {} to cache", + LOGGER.error("Couldn't add 'global customer id': {}, 'service type': {} and 'service instance id': {} to cache", globalCustomerId, serviceType, serviceInstanceId); return getRequestErrorResponseEntity(request); } - private String getResourceVersion() { - return System.currentTimeMillis() + ""; - } - private ResponseEntity<?> getRequestErrorResponseEntity(final HttpServletRequest request) { return new ResponseEntity<>(new RequestErrorBuilder().messageId(ERROR_MESSAGE_ID).text(ERROR_MESSAGE) .variables(request.getMethod(), request.getRequestURI(), 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 new file mode 100644 index 00000000..e88bf22a --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/ProjectController.java @@ -0,0 +1,107 @@ +/*- + * ============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.PROJECT_URL; +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; +import javax.ws.rs.core.MediaType; +import org.onap.aai.domain.yang.Project; +import org.onap.aai.domain.yang.Relationship; +import org.onap.so.aai.simulator.service.providers.ProjectCacheServiceProvider; +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; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@Controller +@RequestMapping(path = PROJECT_URL) +public class ProjectController { + private static final Logger LOGGER = LoggerFactory.getLogger(ProjectController.class); + + private final ProjectCacheServiceProvider cacheServiceProvider; + + @Autowired + public ProjectController(final ProjectCacheServiceProvider cacheServiceProvider) { + this.cacheServiceProvider = cacheServiceProvider; + } + + @PutMapping(value = "/{project-name}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity<?> putProject(@RequestBody final Project project, + @PathVariable("project-name") final String projectName, final HttpServletRequest request) { + LOGGER.info("Will put project for 'project-name': {} ...", project.getProjectName()); + + if (project.getResourceVersion() == null || project.getResourceVersion().isEmpty()) { + project.setResourceVersion(getResourceVersion()); + + } + cacheServiceProvider.putProject(projectName, project); + return ResponseEntity.accepted().build(); + + } + + @GetMapping(value = "/{project-name}", consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity<?> getProject(@PathVariable("project-name") final String projectName, + final HttpServletRequest request) { + LOGGER.info("retrieving project for 'project-name': {} ...", projectName); + + final Optional<Project> optional = cacheServiceProvider.getProject(projectName); + if (optional.isPresent()) { + final Project project = optional.get(); + LOGGER.info("found project {} in cache", project); + return ResponseEntity.ok(project); + } + + LOGGER.error("Couldn't find {} in cache", projectName); + return getRequestErrorResponseEntity(request); + } + + @PutMapping(value = "/{project-name}/relationship-list/relationship", + consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity<?> putProjectRelationShip(@RequestBody final Relationship relationship, + @PathVariable("project-name") final String projectName, final HttpServletRequest request) { + + LOGGER.info("adding relationship for project-name: {} ...", projectName); + final boolean result = cacheServiceProvider.putProjectRelationShip(projectName, relationship); + if (result) { + LOGGER.info("added project relationship {} in cache", relationship); + return ResponseEntity.accepted().build(); + } + LOGGER.error("Couldn't find {} in cache", projectName); + return getRequestErrorResponseEntity(request); + + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CustomerCacheServiceProvider.java index ca0340c6..51fc5546 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CacheServiceProvider.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CustomerCacheServiceProvider.java @@ -29,7 +29,7 @@ import org.onap.aai.domain.yang.ServiceSubscription; * @author waqas.ikram@ericsson.com * */ -public interface CacheServiceProvider { +public interface CustomerCacheServiceProvider { Optional<Customer> getCustomer(final String globalCustomerId); diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CustomerCacheServiceProviderImpl.java index 5c55824d..11a82be8 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CacheServiceProviderImpl.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/CustomerCacheServiceProviderImpl.java @@ -27,7 +27,7 @@ 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.so.aai.simulator.utils.Constant; +import org.onap.so.aai.simulator.utils.Constants; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -40,20 +40,20 @@ import org.springframework.stereotype.Service; * */ @Service -public class CacheServiceProviderImpl implements CacheServiceProvider { - private static final Logger LOGGER = LoggerFactory.getLogger(CacheServiceProviderImpl.class); +public class CustomerCacheServiceProviderImpl implements CustomerCacheServiceProvider { + private static final Logger LOGGER = LoggerFactory.getLogger(CustomerCacheServiceProviderImpl.class); public final CacheManager cacheManager; @Autowired - public CacheServiceProviderImpl(final CacheManager cacheManager) { + public CustomerCacheServiceProviderImpl(final CacheManager cacheManager) { this.cacheManager = cacheManager; } @Override public Optional<Customer> getCustomer(final String globalCustomerId) { LOGGER.info("getting customer from cache using key: {}", globalCustomerId); - final Cache cache = cacheManager.getCache(Constant.CUSTOMER_CACHE); + final Cache cache = cacheManager.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 CacheServiceProviderImpl implements CacheServiceProvider { @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(Constant.CUSTOMER_CACHE); + final Cache cache = cacheManager.getCache(Constants.CUSTOMER_CACHE); cache.put(globalCustomerId, customer); } @@ -75,7 +75,7 @@ public class CacheServiceProviderImpl implements CacheServiceProvider { LOGGER.info("getting service subscription from cache for globalCustomerId: {} and serviceType: {}", globalCustomerId, serviceType); - final Cache cache = cacheManager.getCache(Constant.CUSTOMER_CACHE); + final Cache cache = cacheManager.getCache(Constants.CUSTOMER_CACHE); final Customer value = cache.get(globalCustomerId, Customer.class); @@ -91,7 +91,7 @@ public class CacheServiceProviderImpl implements CacheServiceProvider { public Optional<ServiceInstances> getServiceInstances(final String globalCustomerId, final String serviceType, final String serviceInstanceName) { - final Cache cache = cacheManager.getCache(Constant.CUSTOMER_CACHE); + final Cache cache = cacheManager.getCache(Constants.CUSTOMER_CACHE); final Customer value = cache.get(globalCustomerId, Customer.class); if (value != null) { @@ -119,7 +119,7 @@ public class CacheServiceProviderImpl implements CacheServiceProvider { @Override public Optional<ServiceInstance> getServiceInstance(final String globalCustomerId, final String serviceType, final String serviceInstanceId) { - final Cache cache = cacheManager.getCache(Constant.CUSTOMER_CACHE); + final Cache cache = cacheManager.getCache(Constants.CUSTOMER_CACHE); final Customer value = cache.get(globalCustomerId, Customer.class); if (value != null) { @@ -145,7 +145,7 @@ public class CacheServiceProviderImpl implements CacheServiceProvider { final String serviceInstanceId, final ServiceInstance serviceInstance) { LOGGER.info("Adding serviceInstance: {} in cache ...", serviceInstance, globalCustomerId); - final Cache cache = cacheManager.getCache(Constant.CUSTOMER_CACHE); + final Cache cache = cacheManager.getCache(Constants.CUSTOMER_CACHE); final Customer value = cache.get(globalCustomerId, Customer.class); if (value != null) { @@ -184,7 +184,7 @@ public class CacheServiceProviderImpl implements CacheServiceProvider { @Override public void clearAll() { - final Cache cache = cacheManager.getCache(Constant.CUSTOMER_CACHE); + 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(); diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/ProjectCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/ProjectCacheServiceProvider.java new file mode 100644 index 00000000..ec9e4e5d --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/ProjectCacheServiceProvider.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.Project; +import org.onap.aai.domain.yang.Relationship; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public interface ProjectCacheServiceProvider { + + void putProject(final String projectName, final Project project); + + Optional<Project> getProject(final String projectName); + + boolean putProjectRelationShip(final String projectName, final 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/ProjectCacheServiceProviderImpl.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/ProjectCacheServiceProviderImpl.java new file mode 100644 index 00000000..c1148d2f --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/ProjectCacheServiceProviderImpl.java @@ -0,0 +1,93 @@ +/*- + * ============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.PROJECT_CACHE; +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; +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 ProjectCacheServiceProviderImpl implements ProjectCacheServiceProvider { + + private static final Logger LOGGER = LoggerFactory.getLogger(ProjectCacheServiceProviderImpl.class); + + public final CacheManager cacheManager; + + @Autowired + public ProjectCacheServiceProviderImpl(final CacheManager cacheManager) { + this.cacheManager = 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); + cache.put(projectName, project); + } + + + @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 Project value = cache.get(projectName, Project.class); + if (value != null) { + return Optional.of(value); + } + return Optional.empty(); + } + + @Override + public boolean putProjectRelationShip(final String projectName, final Relationship relationship) { + final Cache cache = cacheManager.getCache(PROJECT_CACHE); + final Project value = cache.get(projectName, Project.class); + if (value != null) { + RelationshipList relationshipList = value.getRelationshipList(); + if (relationshipList == null) { + relationshipList = new RelationshipList(); + value.setRelationshipList(relationshipList); + } + return relationshipList.getRelationship().add(relationship); + } + 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(); + } +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/Constant.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/Constants.java index 5a85be16..54e5323d 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/Constant.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/Constants.java @@ -23,20 +23,26 @@ package org.onap.so.aai.simulator.utils; * @author waqas.ikram@ericsson.com * */ -public class Constant { +public class Constants { public static final String BASE_URL = "/simulator/aai/v15/"; - public static final String BUSINESS_URL = BASE_URL + "/business/"; + public static final String BUSINESS_URL = BASE_URL + "/business"; + + public static final String CUSTOMER_URL = BUSINESS_URL + "/customers/customer/"; + + public static final String PROJECT_URL = BUSINESS_URL + "/projects/project/"; public static final String HEALTHY = "healthy"; public static final String CUSTOMER_CACHE = "customer-cache"; + public static final String PROJECT_CACHE = "project-cache"; + 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)"; - private Constant() {} + private Constants() {} } 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 new file mode 100644 index 00000000..db90a235 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/utils/Utils.java @@ -0,0 +1,51 @@ +/*- + * ============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.utils; + +import static org.onap.so.aai.simulator.utils.Constants.ERROR_MESSAGE; +import static org.onap.so.aai.simulator.utils.Constants.ERROR_MESSAGE_ID; +import javax.servlet.http.HttpServletRequest; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public class Utils { + + private static final String EMPTY_STRING = ""; + + public static final String getResourceVersion() { + return System.currentTimeMillis() + EMPTY_STRING; + } + + 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); + } + + + private Utils() {} + +} |