*/
package org.onap.so.aaisimulator.controller;
+import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL;
+import static org.onap.so.aaisimulator.utils.Constants.CUSTOMER_TYPE;
import static org.onap.so.aaisimulator.utils.Constants.CUSTOMER_URL;
+import static org.onap.so.aaisimulator.utils.Constants.GENERIC_VNF;
import static org.onap.so.aaisimulator.utils.Constants.SERVICE_RESOURCE_TYPE;
+import static org.onap.so.aaisimulator.utils.Constants.SERVICE_SUBSCRIPTION;
import static org.onap.so.aaisimulator.utils.Constants.X_HTTP_METHOD_OVERRIDE;
-import static org.onap.so.aaisimulator.utils.Utils.getRequestErrorResponseEntity;
-import static org.onap.so.aaisimulator.utils.Utils.getResourceVersion;
+import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getRequestErrorResponseEntity;
+import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getResourceVersion;
+import java.util.List;
import java.util.Optional;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.MediaType;
import org.onap.aai.domain.yang.Customer;
+import org.onap.aai.domain.yang.GenericVnf;
+import org.onap.aai.domain.yang.GenericVnfs;
+import org.onap.aai.domain.yang.Relationship;
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.aaisimulator.models.NodeServiceInstance;
import org.onap.so.aaisimulator.service.providers.CustomerCacheServiceProvider;
+import org.onap.so.aaisimulator.service.providers.GenericVnfCacheServiceProvider;
import org.onap.so.aaisimulator.service.providers.NodesCacheServiceProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
@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;
+ private final GenericVnfCacheServiceProvider genericVnfCacheServiceProvider;
@Autowired
public BusinessController(final CustomerCacheServiceProvider cacheServiceProvider,
- final NodesCacheServiceProvider nodesCacheServiceProvider) {
+ final NodesCacheServiceProvider nodesCacheServiceProvider,
+ final GenericVnfCacheServiceProvider genericVnfCacheServiceProvider) {
this.cacheServiceProvider = cacheServiceProvider;
this.nodesCacheServiceProvider = nodesCacheServiceProvider;
+ this.genericVnfCacheServiceProvider = genericVnfCacheServiceProvider;
}
@GetMapping(value = "{global-customer-id}", produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
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})
}
+ @GetMapping(
+ value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}/related-to/generic-vnfs",
+ produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public ResponseEntity<?> getRelatedToGenericVnf(@PathVariable("global-customer-id") final String globalCustomerId,
+ @PathVariable("service-type") final String serviceType,
+ @PathVariable(name = "service-instance-id") final String serviceInstanceId,
+ @RequestParam(name = "vnf-name", required = false) final String vnfName, final HttpServletRequest request) {
+
+ LOGGER.info(
+ "Will retrieve generic vnf related to information for 'global customer id': {}, 'service type': {} and 'service instance id: '{} with vnfname: {}...",
+ globalCustomerId, serviceType, serviceInstanceId, vnfName);
+
+ final List<String> relatedToVnfIds =
+ getRelatedToVnfIds(globalCustomerId, serviceType, serviceInstanceId, vnfName);
+
+
+ if (!relatedToVnfIds.isEmpty()) {
+ final GenericVnfs genericVnfs = new GenericVnfs();
+ relatedToVnfIds.stream().forEach(vnfId -> {
+ final Optional<GenericVnf> genericVnfOptional = genericVnfCacheServiceProvider.getGenericVnf(vnfId);
+ if (genericVnfOptional.isPresent()) {
+ final GenericVnf genericVnf = genericVnfOptional.get();
+ LOGGER.info("found related-to generic-vnf {} in cache", genericVnf);
+ genericVnfs.getGenericVnf().add(genericVnf);
+ }
+ });
+ if (!genericVnfs.getGenericVnf().isEmpty()) {
+ LOGGER.info("Found {} related generic-vnfs", genericVnfs.getGenericVnf().size());
+ return ResponseEntity.ok(genericVnfs);
+ }
+ }
+
+ LOGGER.error(
+ "Couldn't find generic vnf related to information for 'global customer id': {}, 'service type': {} and 'service instance id: '{} with vnfname: {}...",
+ globalCustomerId, serviceType, serviceInstanceId, vnfName);
+ return getRequestErrorResponseEntity(request, GENERIC_VNF);
+ }
+
+ @PutMapping(
+ value = "/{global-customer-id}/service-subscriptions/service-subscription/{service-type}/service-instances/service-instance/{service-instance-id}"
+ + BI_DIRECTIONAL_RELATIONSHIP_LIST_URL,
+ consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
+ produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
+ public ResponseEntity<?> putSericeInstanceRelationShip(
+ @PathVariable("global-customer-id") final String globalCustomerId,
+ @PathVariable("service-type") final String serviceType,
+ @PathVariable(name = "service-instance-id") final String serviceInstanceId,
+ @RequestBody final Relationship relationship, final HttpServletRequest request) {
+
+ LOGGER.info(
+ "Will add {} relationship for 'global customer id': {}, 'service type': {} and 'service instance id: '{} ...",
+ relationship.getRelatedTo(), globalCustomerId, serviceType, serviceInstanceId);
+ final Optional<Relationship> optional = cacheServiceProvider.addRelationShip(globalCustomerId, serviceType,
+ serviceInstanceId, relationship, request.getRequestURI());
+
+ if (optional.isPresent()) {
+ final Relationship resultantRelationship = optional.get();
+ LOGGER.info("Relationship add, sending resultant relationship: {} in response ...", resultantRelationship);
+ return ResponseEntity.accepted().body(resultantRelationship);
+ }
+
+ LOGGER.error(
+ "Couldn't add {} relationship for 'global customer id': {}, 'service type': {} and 'service instance id: '{} ...",
+ relationship.getRelatedTo(), globalCustomerId, serviceType, serviceInstanceId);
+
+ return getRequestErrorResponseEntity(request);
+ }
+
+ @DeleteMapping(
+ 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<?> deleteSericeInstance(@PathVariable("global-customer-id") final String globalCustomerId,
+ @PathVariable("service-type") final String serviceType,
+ @PathVariable(name = "service-instance-id") final String serviceInstanceId,
+ @RequestParam(name = "resource-version") final String resourceVersion, final HttpServletRequest request) {
+
+ LOGGER.info(
+ "Will delete SericeInstance for 'global-customer-id': {}, 'service-type': {}, 'service-instance-id': {} and 'resource-version': {}",
+ globalCustomerId, serviceType, serviceInstanceId, resourceVersion);
+
+ if (cacheServiceProvider.deleteSericeInstance(globalCustomerId, serviceType, serviceInstanceId,
+ resourceVersion)) {
+ LOGGER.info(
+ "Successfully deleted SericeInstance from cache for 'global-customer-id': {}, 'service-type': {}, 'service-instance-id': {} and 'resource-version': {}",
+ globalCustomerId, serviceType, serviceInstanceId, resourceVersion);
+ return ResponseEntity.noContent().build();
+ }
+
+ LOGGER.error(
+ "Unable to delete SericeInstance from cache for 'global-customer-id': {}, 'service-type': {}, 'service-instance-id': {} and 'resource-version': {}",
+ globalCustomerId, serviceType, serviceInstanceId, resourceVersion);
+
+ return getRequestErrorResponseEntity(request);
+
+ }
+
+ private List<String> getRelatedToVnfIds(final String globalCustomerId, final String serviceType,
+ final String serviceInstanceId, final String vnfName) {
+ if (vnfName != null) {
+ return cacheServiceProvider.getRelatedToVnfIds(globalCustomerId, serviceType, serviceInstanceId, vnfName);
+ }
+ return cacheServiceProvider.getRelatedToVnfIds(globalCustomerId, serviceType, serviceInstanceId);
+ }
}