diff options
17 files changed, 800 insertions, 40 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 a2f47ade..af00ba78 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 @@ -20,6 +20,7 @@ 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.PROJECT_CACHE; import java.util.Arrays; import org.springframework.boot.autoconfigure.jackson.Jackson2ObjectMapperBuilderCustomizer; @@ -46,7 +47,7 @@ public class ApplicationConfigration { @Bean public CacheManager cacheManager() { final SimpleCacheManager manager = new SimpleCacheManager(); - manager.setCaches(Arrays.asList(getCache(CUSTOMER_CACHE), getCache(PROJECT_CACHE))); + manager.setCaches(Arrays.asList(getCache(CUSTOMER_CACHE), getCache(PROJECT_CACHE), getCache(NODES_CACHE))); 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 b5682f02..e7fd00de 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 @@ -22,6 +22,7 @@ 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.Utils.getResourceVersion; import java.util.Optional; import javax.servlet.http.HttpServletRequest; @@ -30,7 +31,9 @@ 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.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; @@ -55,10 +58,13 @@ public class BusinessController { private static final Logger LOGGER = LoggerFactory.getLogger(BusinessController.class); private final CustomerCacheServiceProvider cacheServiceProvider; + private final NodesCacheServiceProvider nodesCacheServiceProvider; @Autowired - public BusinessController(final CustomerCacheServiceProvider cacheServiceProvider) { + public BusinessController(final CustomerCacheServiceProvider cacheServiceProvider, + final NodesCacheServiceProvider nodesCacheServiceProvider) { this.cacheServiceProvider = cacheServiceProvider; + this.nodesCacheServiceProvider = nodesCacheServiceProvider; } @GetMapping(value = "{global-customer-id}", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) @@ -183,6 +189,8 @@ public class BusinessController { if (cacheServiceProvider.putServiceInstance(globalCustomerId, serviceType, serviceInstanceId, serviceInstance)) { + nodesCacheServiceProvider.putNodeServiceInstance(serviceInstanceId, new NodeServiceInstance( + globalCustomerId, serviceType, serviceInstanceId, SERVICE_RESOURCE_TYPE, request.getRequestURI())); return ResponseEntity.accepted().build(); } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/NodesController.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/NodesController.java new file mode 100644 index 00000000..4fa4d408 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/controller/NodesController.java @@ -0,0 +1,110 @@ +/*- + * ============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.NODES_URL; +import static org.onap.so.aai.simulator.utils.Constants.RESOURCE_LINK; +import static org.onap.so.aai.simulator.utils.Constants.RESOURCE_TYPE; +import static org.onap.so.aai.simulator.utils.Utils.getRequestErrorResponseEntity; +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.ServiceInstance; +import org.onap.so.aai.simulator.models.Format; +import org.onap.so.aai.simulator.models.NodeServiceInstance; +import org.onap.so.aai.simulator.models.Result; +import org.onap.so.aai.simulator.service.providers.CustomerCacheServiceProvider; +import org.onap.so.aai.simulator.service.providers.NodesCacheServiceProvider; +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.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@Controller +@RequestMapping(path = NODES_URL) +public class NodesController { + + + private static final Logger LOGGER = LoggerFactory.getLogger(NodesController.class); + + private final NodesCacheServiceProvider cacheServiceProvider; + + private final CustomerCacheServiceProvider customerCacheServiceProvider; + + @Autowired + public NodesController(final CustomerCacheServiceProvider customerCacheServiceProvider, + final NodesCacheServiceProvider cacheServiceProvider) { + this.customerCacheServiceProvider = customerCacheServiceProvider; + this.cacheServiceProvider = cacheServiceProvider; + } + + @GetMapping(value = "/service-instances/service-instance/{service-instance-id}", + consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}, + produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML}) + public ResponseEntity<?> getProject(@PathVariable(name = "service-instance-id") final String serviceInstanceId, + @RequestParam(name = "format", required = false) final String format, final HttpServletRequest request) { + LOGGER.info("retrieving service instance using 'service-instance-id': {} and format: {}...", serviceInstanceId, + format); + + final Optional<NodeServiceInstance> optional = cacheServiceProvider.getNodeServiceInstance(serviceInstanceId); + if (!optional.isPresent()) { + LOGGER.error("Couldn't find {} in cache", serviceInstanceId); + return getRequestErrorResponseEntity(request); + } + + final Format value = Format.forValue(format); + final NodeServiceInstance nodeServiceInstance = optional.get(); + switch (value) { + case PATHED: + LOGGER.info("found project {} in cache", nodeServiceInstance); + final Map<String, Object> map = new HashMap<>(); + map.put(RESOURCE_TYPE, nodeServiceInstance.getResourceType()); + map.put(RESOURCE_LINK, nodeServiceInstance.getResourceLink()); + return ResponseEntity.ok(new Result(map)); + case RAW: + final Optional<ServiceInstance> serviceInstance = + customerCacheServiceProvider.getServiceInstance(nodeServiceInstance.getGlobalCustomerId(), + nodeServiceInstance.getServiceType(), nodeServiceInstance.getServiceInstanceId()); + if (serviceInstance.isPresent()) { + return ResponseEntity.ok(serviceInstance.get()); + } + LOGGER.info("Unable to find Service instance in cahce using {}", nodeServiceInstance); + return getRequestErrorResponseEntity(request); + default: + break; + } + LOGGER.error("invalid format type :{}", format); + 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 e88bf22a..5f63494d 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 @@ -22,11 +22,15 @@ 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.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.Project; 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.ProjectCacheServiceProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -38,6 +42,7 @@ 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 @@ -73,18 +78,34 @@ public class ProjectController { @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) { + @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 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); + if (!optional.isPresent()) { + LOGGER.error("Couldn't find {} in cache", projectName); + return getRequestErrorResponseEntity(request); } - LOGGER.error("Couldn't find {} in cache", projectName); + final Format value = Format.forValue(format); + switch (value) { + case RAW: + final Project project = optional.get(); + LOGGER.info("found project {} in cache", project); + return ResponseEntity.ok(project); + case COUNT: + final Map<String, Object> map = new HashMap<>(); + map.put(projectName, 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", @@ -94,14 +115,12 @@ public class ProjectController { @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) { + if (cacheServiceProvider.putProjectRelationShip(projectName, relationship)) { 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/models/Format.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/models/Format.java new file mode 100644 index 00000000..f6ff2403 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/models/Format.java @@ -0,0 +1,49 @@ +/*- + * ============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.models; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public enum Format { + + COUNT("count"), RAW("raw"), PATHED("pathed"); + + private final String value; + + private Format(final String value) { + this.value = value; + } + + public String getValue() { + return value; + } + + public static Format forValue(final String value) { + for (final Format format : Format.values()) { + if (format.getValue().equals(value)) { + return format; + } + } + return RAW; + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/models/NodeServiceInstance.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/models/NodeServiceInstance.java new file mode 100644 index 00000000..f549850d --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/models/NodeServiceInstance.java @@ -0,0 +1,139 @@ +/*- + * ============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.models; + +import java.io.Serializable; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public class NodeServiceInstance implements Serializable { + + private static final long serialVersionUID = -3314166327618070948L; + + private String globalCustomerId; + private String serviceType; + private String serviceInstanceId; + private String resourceType; + private String resourceLink; + + public NodeServiceInstance() {} + + + public NodeServiceInstance(final String globalCustomerId, final String serviceType, final String serviceInstanceId, + final String resourceType, final String resourceLink) { + this.globalCustomerId = globalCustomerId; + this.serviceType = serviceType; + this.serviceInstanceId = serviceInstanceId; + this.resourceType = resourceType; + this.resourceLink = resourceLink; + } + + + /** + * @return the globalCustomerId + */ + public String getGlobalCustomerId() { + return globalCustomerId; + } + + + /** + * @param globalCustomerId the globalCustomerId to set + */ + public void setGlobalCustomerId(final String globalCustomerId) { + this.globalCustomerId = globalCustomerId; + } + + + /** + * @return the serviceType + */ + public String getServiceType() { + return serviceType; + } + + + /** + * @param serviceType the serviceType to set + */ + public void setServiceType(final String serviceType) { + this.serviceType = serviceType; + } + + + /** + * @return the serviceInstanceId + */ + public String getServiceInstanceId() { + return serviceInstanceId; + } + + + /** + * @param serviceInstanceId the serviceInstanceId to set + */ + public void setServiceInstanceId(final String serviceInstanceId) { + this.serviceInstanceId = serviceInstanceId; + } + + + /** + * @return the resourceType + */ + public String getResourceType() { + return resourceType; + } + + + /** + * @param resourceType the resourceType to set + */ + public void setResourceType(final String resourceType) { + this.resourceType = resourceType; + } + + + /** + * @return the resourceLink + */ + public String getResourceLink() { + return resourceLink; + } + + + /** + * @param resourceLink the resourceLink to set + */ + public void setResourceLink(final String resourceLink) { + this.resourceLink = resourceLink; + } + + + @Override + public String toString() { + return "NodeServiceInstance [globalCustomerId=" + globalCustomerId + ", serviceType=" + serviceType + + ", serviceInstanceId=" + serviceInstanceId + ", resourceType=" + resourceType + ", resourceLink=" + + resourceLink + "]"; + } + + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/models/Result.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/models/Result.java new file mode 100644 index 00000000..6aa92562 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/models/Result.java @@ -0,0 +1,64 @@ +/*- + * ============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.models; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonRootName; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@JsonRootName(value = "result") +public class Result { + + private List<Map<String, Object>> values = new ArrayList<>(); + + public Result() {} + + public Result(final Map<String, Object> value) { + this.values.add(value); + } + + /** + * @return the values + */ + public List<Map<String, Object>> getValues() { + return values; + } + + /** + * @param values the values to set + */ + public void setValues(final List<Map<String, Object>> values) { + this.values = values; + } + + + @JsonIgnore + @Override + public String toString() { + return "Result [values=" + values + "]"; + } + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/NodesCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/NodesCacheServiceProvider.java new file mode 100644 index 00000000..bf444f2f --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/NodesCacheServiceProvider.java @@ -0,0 +1,37 @@ +/*- + * ============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.so.aai.simulator.models.NodeServiceInstance; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public interface NodesCacheServiceProvider { + + void putNodeServiceInstance(final String serviceInstanceId, final NodeServiceInstance nodeServiceInstance); + + Optional<NodeServiceInstance> getNodeServiceInstance(final String serviceInstanceId); + + void clearAll(); + +} 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 new file mode 100644 index 00000000..61cb35a2 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/NodesCacheServiceProviderImpl.java @@ -0,0 +1,74 @@ +/*- + * ============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.NODES_CACHE; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import org.onap.so.aai.simulator.models.NodeServiceInstance; +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 NodesCacheServiceProviderImpl implements NodesCacheServiceProvider { + private static final Logger LOGGER = LoggerFactory.getLogger(NodesCacheServiceProviderImpl.class); + + public final CacheManager cacheManager; + + @Autowired + public NodesCacheServiceProviderImpl(final CacheManager cacheManager) { + this.cacheManager = cacheManager; + } + + @Override + public void putNodeServiceInstance(final String serviceInstanceId, final NodeServiceInstance nodeServiceInstance) { + final Cache cache = cacheManager.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 NodeServiceInstance value = cache.get(serviceInstanceId, NodeServiceInstance.class); + if (value != null) { + return Optional.of(value); + } + LOGGER.error("Unable to find node service instance in cache using key:{} ", serviceInstanceId); + return Optional.empty(); + } + + @Override + public void clearAll() { + final Cache cache = cacheManager.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/ProjectCacheServiceProvider.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/main/java/org/onap/so/aai/simulator/service/providers/ProjectCacheServiceProvider.java index ec9e4e5d..59060f27 100644 --- 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 @@ -32,7 +32,7 @@ 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 index c1148d2f..a1047887 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 @@ -20,6 +20,7 @@ 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; @@ -39,6 +40,8 @@ import org.springframework.stereotype.Service; @Service public class ProjectCacheServiceProviderImpl 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; @@ -77,6 +80,14 @@ public class ProjectCacheServiceProviderImpl implements ProjectCacheServiceProvi 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); } return false; 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 54e5323d..1cb63360 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 @@ -25,7 +25,9 @@ package org.onap.so.aai.simulator.utils; */ public class Constants { - public static final String BASE_URL = "/simulator/aai/v15/"; + public static final String BASE_URL = "/aai/v15"; + + public static final String NODES_URL = BASE_URL + "/nodes"; public static final String BUSINESS_URL = BASE_URL + "/business"; @@ -39,10 +41,18 @@ public class Constants { public static final String PROJECT_CACHE = "project-cache"; + public static final String NODES_CACHE = "nodes-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)"; + 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"; + private Constants() {} } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/BusinessControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/BusinessControllerTest.java index 341c1b38..283a2a20 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/BusinessControllerTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/BusinessControllerTest.java @@ -23,12 +23,16 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.onap.so.aai.simulator.controller.TestUtils.getFile; -import static org.onap.so.aai.simulator.controller.TestUtils.getJsonString; -import static org.onap.so.aai.simulator.controller.TestUtils.getObjectFromFile; -import java.io.File; +import static org.onap.so.aai.simulator.utils.TestConstants.CUSTOMERS_URL; +import static org.onap.so.aai.simulator.utils.TestConstants.GLOBAL_CUSTOMER_ID; +import static org.onap.so.aai.simulator.utils.TestConstants.SERVICE_INSTANCES_URL; +import static org.onap.so.aai.simulator.utils.TestConstants.SERVICE_INSTANCE_ID; +import static org.onap.so.aai.simulator.utils.TestConstants.SERVICE_INSTANCE_URL; +import static org.onap.so.aai.simulator.utils.TestConstants.SERVICE_NAME; +import static org.onap.so.aai.simulator.utils.TestConstants.SERVICE_SUBSCRIPTIONS_URL; +import static org.onap.so.aai.simulator.utils.TestConstants.SERVICE_TYPE; +import static org.onap.so.aai.simulator.utils.TestUtils.getJsonString; import java.io.IOException; -import java.nio.file.Files; import java.util.Optional; import java.util.UUID; import org.junit.After; @@ -42,6 +46,7 @@ import org.onap.so.aai.simulator.service.providers.CustomerCacheServiceProvider; import org.onap.so.aai.simulator.utils.Constants; import org.onap.so.aai.simulator.utils.RequestError; import org.onap.so.aai.simulator.utils.ServiceException; +import org.onap.so.aai.simulator.utils.TestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; @@ -67,24 +72,6 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @Configuration public class BusinessControllerTest { - private static final String SERVICE_INSTANCES_URL = "/service-instances"; - - private static final String SERVICE_NAME = "ServiceTest"; - - private static final String SERVICE_INSTANCE_ID = "ccece8fe-13da-456a-baf6-41b3a4a2bc2b"; - - private static final String SERVICE_INSTANCE_URL = - SERVICE_INSTANCES_URL + "/service-instance/" + SERVICE_INSTANCE_ID; - - private static final String SERVICE_TYPE = "vCPE"; - - private static final String SERVICE_SUBSCRIPTIONS_URL = - "/service-subscriptions/service-subscription/" + SERVICE_TYPE; - - private static final String GLOBAL_CUSTOMER_ID = "DemoCustomer"; - - private static final String CUSTOMERS_URL = Constants.CUSTOMER_URL + GLOBAL_CUSTOMER_ID; - @LocalServerPort private int port; diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/NodesControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/NodesControllerTest.java new file mode 100644 index 00000000..5ea6dff0 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/NodesControllerTest.java @@ -0,0 +1,180 @@ +/*- + * ============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.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.onap.so.aai.simulator.utils.Constants.RESOURCE_LINK; +import static org.onap.so.aai.simulator.utils.Constants.RESOURCE_TYPE; +import static org.onap.so.aai.simulator.utils.Constants.SERVICE_RESOURCE_TYPE; +import static org.onap.so.aai.simulator.utils.TestConstants.CUSTOMERS_URL; +import static org.onap.so.aai.simulator.utils.TestConstants.SERVICE_INSTANCE_ID; +import static org.onap.so.aai.simulator.utils.TestConstants.SERVICE_INSTANCE_URL; +import static org.onap.so.aai.simulator.utils.TestConstants.SERVICE_NAME; +import static org.onap.so.aai.simulator.utils.TestConstants.SERVICE_SUBSCRIPTIONS_URL; +import static org.onap.so.aai.simulator.utils.TestUtils.getJsonString; +import java.io.IOException; +import java.util.Map; +import org.junit.After; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.aai.domain.yang.ServiceInstance; +import org.onap.so.aai.simulator.models.Format; +import org.onap.so.aai.simulator.models.Result; +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.Constants; +import org.onap.so.aai.simulator.utils.TestUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.web.server.LocalServerPort; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * @author waqas.ikram@ericsson.com + * + */ +@RunWith(SpringJUnit4ClassRunner.class) +@ActiveProfiles("test") +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) +@Configuration +public class NodesControllerTest { + + @LocalServerPort + private int port; + + @Autowired + private TestRestTemplate restTemplate; + + @Value("${spring.security.username}") + private String username; + + @Autowired + private NodesCacheServiceProvider nodesCacheServiceProvider; + + @Autowired + private CustomerCacheServiceProvider customerCacheServiceProvider; + + @After + public void after() { + nodesCacheServiceProvider.clearAll(); + customerCacheServiceProvider.clearAll(); + } + + @Test + public void test_getNodesSericeInstance_usingServiceInstanceId_ableToRetrieveServiceInstanceFromCache() + throws Exception { + + final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL; + + final ResponseEntity<Void> response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); + + assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); + + final ResponseEntity<Void> response2 = invokeHttpPut(url, getServiceInstance()); + assertEquals(HttpStatus.ACCEPTED, response2.getStatusCode()); + + final ResponseEntity<ServiceInstance> actual = + restTemplate.exchange(getNodesEndPointUrl() + SERVICE_INSTANCE_URL, HttpMethod.GET, + new HttpEntity<>(getHttpHeaders()), ServiceInstance.class); + + assertEquals(HttpStatus.OK, actual.getStatusCode()); + assertTrue(actual.hasBody()); + + final ServiceInstance actualServiceInstance = actual.getBody(); + + assertEquals(SERVICE_NAME, actualServiceInstance.getServiceInstanceName()); + assertEquals(SERVICE_INSTANCE_ID, actualServiceInstance.getServiceInstanceId()); + + } + + @Test + public void test_getNodesSericeInstance_usingServiceInstanceIdAndFormatPathed_ableToRetrieveServiceInstanceFromCache() + throws Exception { + + final String url = getCustomerEndPointUrl() + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL; + + final ResponseEntity<Void> response = invokeHttpPut(getCustomerEndPointUrl(), getCustomer()); + + assertEquals(HttpStatus.ACCEPTED, response.getStatusCode()); + + final ResponseEntity<Void> response2 = invokeHttpPut(url, getServiceInstance()); + assertEquals(HttpStatus.ACCEPTED, response2.getStatusCode()); + + final ResponseEntity<Result> actual = restTemplate.exchange( + getNodesEndPointUrl() + SERVICE_INSTANCE_URL + "?format=" + Format.PATHED.getValue(), HttpMethod.GET, + new HttpEntity<>(getHttpHeaders()), Result.class); + + assertEquals(HttpStatus.OK, actual.getStatusCode()); + assertTrue(actual.hasBody()); + + final Result result = actual.getBody(); + + assertNotNull(result.getValues()); + assertFalse(result.getValues().isEmpty()); + final Map<String, Object> actualMap = result.getValues().get(0); + + assertEquals(CUSTOMERS_URL + SERVICE_SUBSCRIPTIONS_URL + SERVICE_INSTANCE_URL, actualMap.get(RESOURCE_LINK)); + assertEquals(SERVICE_RESOURCE_TYPE, actualMap.get(RESOURCE_TYPE)); + + } + + private String getNodesEndPointUrl() { + return TestUtils.getBaseUrl(port) + Constants.NODES_URL; + } + + + private String getCustomerEndPointUrl() { + return TestUtils.getBaseUrl(port) + CUSTOMERS_URL; + } + + private String getCustomer() throws Exception, IOException { + return getJsonString("test-data/business-customer.json"); + } + + private String getServiceInstance() throws Exception, IOException { + return getJsonString("test-data/service-instance.json"); + } + + private ResponseEntity<Void> invokeHttpPut(final String url, final Object obj) { + final HttpEntity<?> httpEntity = getHttpEntity(obj); + return restTemplate.exchange(url, HttpMethod.PUT, httpEntity, Void.class); + } + + private HttpEntity<?> getHttpEntity(final Object obj) { + return new HttpEntity<>(obj, getHttpHeaders()); + } + + private HttpHeaders getHttpHeaders() { + return TestUtils.getHttpHeaders(username); + } +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/ProjectControllerTest.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/ProjectControllerTest.java index 73fdb2c5..b198e356 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/ProjectControllerTest.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/ProjectControllerTest.java @@ -23,17 +23,19 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; -import static org.onap.so.aai.simulator.controller.TestUtils.getFile; -import static org.onap.so.aai.simulator.controller.TestUtils.getHttpHeaders; -import static org.onap.so.aai.simulator.controller.TestUtils.getJsonString; +import static org.onap.so.aai.simulator.utils.TestUtils.getFile; +import static org.onap.so.aai.simulator.utils.TestUtils.getHttpHeaders; +import static org.onap.so.aai.simulator.utils.TestUtils.getJsonString; import java.io.IOException; import java.nio.file.Files; import org.junit.After; import org.junit.Test; import org.junit.runner.RunWith; import org.onap.aai.domain.yang.Project; +import org.onap.so.aai.simulator.models.Result; import org.onap.so.aai.simulator.service.providers.ProjectCacheServiceProvider; import org.onap.so.aai.simulator.utils.Constants; +import org.onap.so.aai.simulator.utils.TestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; @@ -125,6 +127,27 @@ public class ProjectControllerTest { } + @Test + public void test_getProjectCount_correctResult() throws Exception { + final String url = getProjectEndPointUrl() + "/" + PROJECT_NAME_VALUE; + final String body = new String(Files.readAllBytes(getFile(BUSINESS_PROJECT_JSON_FILE).toPath())); + final ResponseEntity<Void> actual = invokeHttpPut(url, body); + + assertEquals(HttpStatus.ACCEPTED, actual.getStatusCode()); + + final ResponseEntity<Result> actualResponse = + invokeHttpGet(url + "?resultIndex=0&resultSize=1&format=count", Result.class); + + assertEquals(HttpStatus.OK, actualResponse.getStatusCode()); + assertTrue(actualResponse.hasBody()); + final Result result = actualResponse.getBody(); + assertNotNull(result.getValues()); + assertFalse(result.getValues().isEmpty()); + assertEquals(1, result.getValues().get(0).get(PROJECT_NAME_VALUE)); + + + } + private <T> ResponseEntity<T> invokeHttpGet(final String url, final Class<T> clazz) { return restTemplate.exchange(url, HttpMethod.GET, new HttpEntity<>(getHttpHeaders(username)), clazz); } diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/utils/TestConstants.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/utils/TestConstants.java new file mode 100644 index 00000000..0bdf7a79 --- /dev/null +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/utils/TestConstants.java @@ -0,0 +1,48 @@ +/*- + * ============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; + +/** + * @author waqas.ikram@ericsson.com + * + */ +public class TestConstants { + + public static final String SERVICE_INSTANCES_URL = "/service-instances"; + + public static final String SERVICE_NAME = "ServiceTest"; + + public static final String SERVICE_INSTANCE_ID = "ccece8fe-13da-456a-baf6-41b3a4a2bc2b"; + + public static final String SERVICE_INSTANCE_URL = + SERVICE_INSTANCES_URL + "/service-instance/" + SERVICE_INSTANCE_ID; + + public static final String SERVICE_TYPE = "vCPE"; + + public static final String SERVICE_SUBSCRIPTIONS_URL = + "/service-subscriptions/service-subscription/" + SERVICE_TYPE; + + public static final String GLOBAL_CUSTOMER_ID = "DemoCustomer"; + + public static final String CUSTOMERS_URL = Constants.CUSTOMER_URL + GLOBAL_CUSTOMER_ID; + + private TestConstants() {} + +} diff --git a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/TestUtils.java b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/utils/TestUtils.java index c03f5ceb..73e43b10 100644 --- a/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/controller/TestUtils.java +++ b/plans/so/integration-etsi-testing/so-simulators/aai-simulator/src/test/java/org/onap/so/aai/simulator/utils/TestUtils.java @@ -17,7 +17,7 @@ * SPDX-License-Identifier: Apache-2.0 * ============LICENSE_END========================================================= */ -package org.onap.so.aai.simulator.controller; +package org.onap.so.aai.simulator.utils; import java.io.File; import java.io.IOException; |