2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.onap.so.aaisimulator.controller;
22 import static org.onap.so.aaisimulator.utils.Constants.BI_DIRECTIONAL_RELATIONSHIP_LIST_URL;
23 import static org.onap.so.aaisimulator.utils.Constants.CLOUD_REGION;
24 import static org.onap.so.aaisimulator.utils.Constants.CLOUD_REGIONS;
25 import static org.onap.so.aaisimulator.utils.Constants.ESR_SYSTEM_INFO_LIST;
26 import static org.onap.so.aaisimulator.utils.Constants.RELATIONSHIP_LIST_RELATIONSHIP_URL;
27 import static org.onap.so.aaisimulator.utils.Constants.VSERVER;
28 import static org.onap.so.aaisimulator.utils.HttpServiceUtils.getHeaders;
29 import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getRequestErrorResponseEntity;
30 import static org.onap.so.aaisimulator.utils.RequestErrorResponseUtils.getResourceVersion;
31 import java.util.Optional;
32 import javax.servlet.http.HttpServletRequest;
33 import javax.ws.rs.core.MediaType;
34 import org.onap.aai.domain.yang.CloudRegion;
35 import org.onap.aai.domain.yang.EsrSystemInfo;
36 import org.onap.aai.domain.yang.EsrSystemInfoList;
37 import org.onap.aai.domain.yang.K8SResource;
38 import org.onap.aai.domain.yang.Relationship;
39 import org.onap.aai.domain.yang.Tenant;
40 import org.onap.aai.domain.yang.Vserver;
41 import org.onap.so.aaisimulator.models.CloudRegionKey;
42 import org.onap.so.aaisimulator.service.providers.CloudRegionCacheServiceProvider;
43 import org.onap.so.aaisimulator.utils.HttpServiceUtils;
44 import org.slf4j.Logger;
45 import org.slf4j.LoggerFactory;
46 import org.springframework.beans.factory.annotation.Autowired;
47 import org.springframework.http.HttpHeaders;
48 import org.springframework.http.HttpStatus;
49 import org.springframework.http.ResponseEntity;
50 import org.springframework.stereotype.Controller;
51 import org.springframework.web.bind.annotation.DeleteMapping;
52 import org.springframework.web.bind.annotation.GetMapping;
53 import org.springframework.web.bind.annotation.PathVariable;
54 import org.springframework.web.bind.annotation.PutMapping;
55 import org.springframework.web.bind.annotation.RequestBody;
56 import org.springframework.web.bind.annotation.RequestMapping;
57 import org.springframework.web.bind.annotation.RequestParam;
60 * @author Waqas Ikram (waqas.ikram@est.tech)
64 @RequestMapping(path = CLOUD_REGIONS)
65 public class CloudRegionsController {
66 private static final Logger LOGGER = LoggerFactory.getLogger(CloudRegionsController.class);
68 private final CloudRegionCacheServiceProvider cacheServiceProvider;
71 public CloudRegionsController(final CloudRegionCacheServiceProvider cacheServiceProvider) {
72 this.cacheServiceProvider = cacheServiceProvider;
75 @PutMapping(value = "{cloud-owner}/{cloud-region-id}",
76 consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
77 produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
78 public ResponseEntity<?> putCloudRegion(@RequestBody final CloudRegion cloudRegion,
79 @PathVariable("cloud-owner") final String cloudOwner,
80 @PathVariable("cloud-region-id") final String cloudRegionId, final HttpServletRequest request) {
82 final CloudRegionKey key = new CloudRegionKey(cloudOwner, cloudRegionId);
85 LOGGER.info("Will add CloudRegion to cache with key 'key': {} ....", key);
86 if (cloudRegion.getResourceVersion() == null || cloudRegion.getResourceVersion().isEmpty()) {
87 cloudRegion.setResourceVersion(getResourceVersion());
89 cacheServiceProvider.putCloudRegion(key, cloudRegion);
90 return ResponseEntity.accepted().build();
93 LOGGER.error("Unable to add CloudRegion in cache because of invalid key {}", key);
94 return getRequestErrorResponseEntity(request, CLOUD_REGION);
97 @GetMapping(value = "{cloud-owner}/{cloud-region-id}",
98 produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
99 public ResponseEntity<?> getCloudRegion(@PathVariable("cloud-owner") final String cloudOwner,
100 @PathVariable("cloud-region-id") final String cloudRegionId,
101 @RequestParam(name = "depth", required = false) final Integer depth, final HttpServletRequest request) {
102 final CloudRegionKey key = new CloudRegionKey(cloudOwner, cloudRegionId);
103 LOGGER.info("Retrieving CloudRegion using key : {} with depth: {}...", key, depth);
105 final Optional<CloudRegion> optional = cacheServiceProvider.getCloudRegion(key);
106 if (optional.isPresent()) {
107 final CloudRegion cloudRegion = optional.get();
108 LOGGER.info("found CloudRegion {} in cache", cloudRegion);
109 return ResponseEntity.ok(cloudRegion);
112 LOGGER.error("Unable to find CloudRegion in cache using {}", key);
113 return getRequestErrorResponseEntity(request, CLOUD_REGION);
116 @PutMapping(value = "{cloud-owner}/{cloud-region-id}" + BI_DIRECTIONAL_RELATIONSHIP_LIST_URL,
117 consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
118 produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
119 public ResponseEntity<?> putRelationShip(@PathVariable("cloud-owner") final String cloudOwner,
120 @PathVariable("cloud-region-id") final String cloudRegionId, @RequestBody final Relationship relationship,
121 final HttpServletRequest request) {
122 LOGGER.info("Will add {} bi-directional relationship to : {} ...", relationship.getRelatedTo());
124 final CloudRegionKey key = new CloudRegionKey(cloudOwner, cloudRegionId);
126 final Optional<Relationship> optional =
127 cacheServiceProvider.addRelationShip(key, relationship, request.getRequestURI());
129 if (optional.isPresent()) {
130 final Relationship resultantRelationship = optional.get();
131 LOGGER.info("Relationship add, sending resultant relationship: {} in response ...", resultantRelationship);
132 return ResponseEntity.accepted().body(resultantRelationship);
135 LOGGER.error("Couldn't add {} relationship for 'key': {} ...", relationship.getRelatedTo(), key);
136 return getRequestErrorResponseEntity(request, VSERVER);
140 @PutMapping(value = "{cloud-owner}/{cloud-region-id}/tenants/tenant/{tenant-id}",
141 consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
142 produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
143 public ResponseEntity<?> putTenant(@RequestBody final Tenant tenant,
144 @PathVariable("cloud-owner") final String cloudOwner,
145 @PathVariable("cloud-region-id") final String cloudRegionId,
146 @PathVariable("tenant-id") final String tenantId, final HttpServletRequest request) {
148 final CloudRegionKey key = new CloudRegionKey(cloudOwner, cloudRegionId);
151 LOGGER.info("Will add Tenant to cache with key 'key': {} ....", key);
152 if (tenant.getResourceVersion() == null || tenant.getResourceVersion().isEmpty()) {
153 tenant.setResourceVersion(getResourceVersion());
155 if (cacheServiceProvider.putTenant(key, tenantId, tenant)) {
156 return ResponseEntity.accepted().build();
160 LOGGER.error("Unable to add Tenant in cache using key {}", key);
161 return getRequestErrorResponseEntity(request, CLOUD_REGION);
164 @GetMapping(value = "{cloud-owner}/{cloud-region-id}/tenants/tenant/{tenant-id}",
165 produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
166 public ResponseEntity<?> getTenant(@PathVariable("cloud-owner") final String cloudOwner,
167 @PathVariable("cloud-region-id") final String cloudRegionId,
168 @PathVariable("tenant-id") final String tenantId, final HttpServletRequest request) {
169 final CloudRegionKey key = new CloudRegionKey(cloudOwner, cloudRegionId);
170 LOGGER.info("Retrieving Tenant using key : {} and tenant-id:{} ...", key, tenantId);
172 final Optional<Tenant> optional = cacheServiceProvider.getTenant(key, tenantId);
173 if (optional.isPresent()) {
174 final Tenant tenant = optional.get();
175 LOGGER.info("found Tenant {} in cache", tenant);
176 return ResponseEntity.ok(tenant);
179 LOGGER.error("Unable to find Tenant in cache key : {} and tenant-id:{} ...", key, tenantId);
180 return getRequestErrorResponseEntity(request, CLOUD_REGION);
184 value = "{cloud-owner}/{cloud-region-id}/tenants/tenant/{tenant-id}" + RELATIONSHIP_LIST_RELATIONSHIP_URL,
185 consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
186 produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
187 public ResponseEntity<?> putRelationShip(@RequestBody final Relationship relationship,
188 @PathVariable("cloud-owner") final String cloudOwner,
189 @PathVariable("cloud-region-id") final String cloudRegionId,
190 @PathVariable("tenant-id") final String tenantId, final HttpServletRequest request) {
192 final CloudRegionKey key = new CloudRegionKey(cloudOwner, cloudRegionId);
193 LOGGER.info("Will add {} relationship for key : {} and tenant-id:{} ...", relationship.getRelatedLink(), key,
196 if (relationship.getRelatedLink() != null) {
198 final String targetBaseUrl = HttpServiceUtils.getBaseUrl(request).toString();
199 final HttpHeaders incomingHeader = getHeaders(request);
200 final boolean result = cacheServiceProvider.addRelationShip(incomingHeader, targetBaseUrl,
201 request.getRequestURI(), key, tenantId, relationship);
203 LOGGER.info("added created bi directional relationship with {}", relationship.getRelatedLink());
204 return ResponseEntity.accepted().build();
208 LOGGER.error("Unable to add relationship for related link: {}", relationship.getRelatedLink());
209 return getRequestErrorResponseEntity(request, CLOUD_REGION);
212 @PutMapping(value = "{cloud-owner}/{cloud-region-id}/esr-system-info-list/esr-system-info/{esr-system-info-id}",
213 consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
214 produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
215 public ResponseEntity<?> putEsrSystemInfo(@RequestBody final EsrSystemInfo esrSystemInfo,
216 @PathVariable("esr-system-info-id") final String esrSystemInfoId,
217 @PathVariable("cloud-owner") final String cloudOwner,
218 @PathVariable("cloud-region-id") final String cloudRegionId, final HttpServletRequest request) {
220 final CloudRegionKey key = new CloudRegionKey(cloudOwner, cloudRegionId);
222 LOGGER.info("Will put esrSystemInfo for 'key': {} ...", key);
224 if (esrSystemInfo.getResourceVersion() == null || esrSystemInfo.getResourceVersion().isEmpty()) {
225 esrSystemInfo.setResourceVersion(getResourceVersion());
229 if (cacheServiceProvider.putEsrSystemInfo(key, esrSystemInfoId, esrSystemInfo)) {
230 LOGGER.info("Successfully added EsrSystemInfo key : {} ...", key, esrSystemInfo);
231 return ResponseEntity.accepted().build();
233 LOGGER.error("Unable to add EsrSystemInfo in cache for key : {} ...", key);
235 return getRequestErrorResponseEntity(request, ESR_SYSTEM_INFO_LIST);
238 @GetMapping(value = "{cloud-owner}/{cloud-region-id}/esr-system-info-list",
239 produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
240 public ResponseEntity<?> getEsrSystemInfoList(@PathVariable("cloud-owner") final String cloudOwner,
241 @PathVariable("cloud-region-id") final String cloudRegionId, final HttpServletRequest request) {
242 final CloudRegionKey key = new CloudRegionKey(cloudOwner, cloudRegionId);
243 LOGGER.info("Retrieving EsrSystemInfoList using key : {} ...", key);
245 final Optional<EsrSystemInfoList> optional = cacheServiceProvider.getEsrSystemInfoList(key);
246 if (optional.isPresent()) {
247 final EsrSystemInfoList esrSystemInfoList = optional.get();
248 LOGGER.info("found EsrSystemInfoList {} in cache", esrSystemInfoList);
249 return ResponseEntity.ok(esrSystemInfoList);
252 LOGGER.error("Unable to find EsrSystemInfoList in cache using key : {} ...", key);
253 return getRequestErrorResponseEntity(request, CLOUD_REGION);
256 @PutMapping(value = "{cloud-owner}/{cloud-region-id}/tenants/tenant/{tenant-id}/vservers/vserver/{vserver-id}",
257 consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
258 produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
259 public ResponseEntity<?> putVserver(@RequestBody final Vserver vServer,
260 @PathVariable("cloud-owner") final String cloudOwner,
261 @PathVariable("cloud-region-id") final String cloudRegionId,
262 @PathVariable("tenant-id") final String tenantId, @PathVariable("vserver-id") final String vServerId,
263 final HttpServletRequest request) {
265 final CloudRegionKey key = new CloudRegionKey(cloudOwner, cloudRegionId);
266 if (vServer.getResourceVersion() == null || vServer.getResourceVersion().isEmpty()) {
267 vServer.setResourceVersion(getResourceVersion());
269 LOGGER.info("Will put Vserver in cache using using key: {}, tenantId: {}, vServerId: {} ...", key, tenantId,
272 if (cacheServiceProvider.putVserver(key, tenantId, vServerId, vServer)) {
274 if (vServer.getRelationshipList() != null) {
275 for (final Relationship relationship : vServer.getRelationshipList().getRelationship()) {
276 if (relationship.getRelatedLink() != null) {
277 final String requestUri = request.getRequestURI();
278 final String targetBaseUrl =
279 HttpServiceUtils.getBaseUrl(request.getRequestURL(), requestUri).toString();
280 final HttpHeaders incomingHeader = getHeaders(request);
281 final boolean result = cacheServiceProvider.addVServerRelationShip(incomingHeader,
282 targetBaseUrl, requestUri, key, tenantId, vServerId, relationship);
285 "Unable to add Vserver relationship in cache using key: {}, tenantId: {}, vServerId: {}",
286 key, tenantId, vServerId);
287 return getRequestErrorResponseEntity(request, CLOUD_REGION);
289 LOGGER.info("Successfully added relationship with {}", relationship.getRelatedLink());
294 LOGGER.info("Successfully added Vserver for key: {}, tenantId: {}, vServerId: {} ...", key, tenantId,
296 return ResponseEntity.accepted().build();
298 LOGGER.error("Unable to add Vserver in cache using key: {}, tenantId: {}, vServerId: {}", key, tenantId,
300 return getRequestErrorResponseEntity(request, CLOUD_REGION);
303 @GetMapping(value = "{cloud-owner}/{cloud-region-id}/tenants/tenant/{tenant-id}/vservers/vserver/{vserver-id}",
304 produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
305 public ResponseEntity<?> getVserver(@PathVariable("cloud-owner") final String cloudOwner,
306 @PathVariable("cloud-region-id") final String cloudRegionId,
307 @PathVariable("tenant-id") final String tenantId, @PathVariable("vserver-id") final String vServerId,
308 final HttpServletRequest request) {
310 final CloudRegionKey key = new CloudRegionKey(cloudOwner, cloudRegionId);
311 LOGGER.info("Retrieving Vserver using key: {}, tenant-id: {} and vserver-id: {}...", key, tenantId, vServerId);
312 final Optional<Vserver> optional = cacheServiceProvider.getVserver(key, tenantId, vServerId);
313 if (optional.isPresent()) {
314 final Vserver vServer = optional.get();
315 LOGGER.info("found Vserver {} in cache", vServer);
316 return ResponseEntity.ok(vServer);
318 LOGGER.error("Unable to find Vserver in cache using key: {}, tenant-id: {} and vserver-id: {}...", key,
319 tenantId, vServerId);
320 return getRequestErrorResponseEntity(request, CLOUD_REGION);
324 @DeleteMapping(value = "{cloud-owner}/{cloud-region-id}/tenants/tenant/{tenant-id}/vservers/vserver/{vserver-id}",
325 produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
326 public ResponseEntity<?> deleteVserver(@PathVariable("cloud-owner") final String cloudOwner,
327 @PathVariable("cloud-region-id") final String cloudRegionId,
328 @PathVariable("tenant-id") final String tenantId, @PathVariable("vserver-id") final String vServerId,
329 @RequestParam(name = "resource-version") final String resourceVersion, final HttpServletRequest request) {
331 final CloudRegionKey key = new CloudRegionKey(cloudOwner, cloudRegionId);
332 LOGGER.info("Will delete Vserver using key: {}, tenant-id: {}, vserver-id: {} and resource-version: {}...", key,
333 tenantId, vServerId, resourceVersion);
336 if (cacheServiceProvider.deleteVserver(key, tenantId, vServerId, resourceVersion)) {
338 "Successfully delete Vserver from cache for key: {}, tenant-id: {}, vserver-id: {} and resource-version: {}",
339 key, tenantId, vServerId, resourceVersion);
340 return ResponseEntity.noContent().build();
344 "Unable to delete Vserver from cache using key: {}, tenant-id: {}, vserver-id: {} and resource-version: {} ...",
345 key, tenantId, vServerId, resourceVersion);
346 return getRequestErrorResponseEntity(request, CLOUD_REGION);
350 value = "{cloud-owner}/{cloud-region-id}/tenants/tenant/{tenant-id}/vservers/vserver/{vserver-id}"
351 + RELATIONSHIP_LIST_RELATIONSHIP_URL,
352 consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
353 produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
354 public ResponseEntity<?> putVserverRelationShip(@PathVariable("cloud-owner") final String cloudOwner,
355 @PathVariable("cloud-region-id") final String cloudRegionId,
356 @PathVariable("tenant-id") final String tenantId, @PathVariable("vserver-id") final String vServerId,
357 @RequestBody final Relationship relationship, final HttpServletRequest request) {
358 final CloudRegionKey key = new CloudRegionKey(cloudOwner, cloudRegionId);
360 LOGGER.info("Will add {} relationship for key : {}, tenant-id: {} and vserver-id: {}...",
361 relationship.getRelatedLink(), key, tenantId, vServerId);
363 if (relationship.getRelatedLink() != null) {
364 final String targetBaseUrl = HttpServiceUtils.getBaseUrl(request).toString();
365 final HttpHeaders incomingHeader = getHeaders(request);
366 final boolean result = cacheServiceProvider.addVServerRelationShip(incomingHeader, targetBaseUrl,
367 request.getRequestURI(), key, tenantId, vServerId, relationship);
369 LOGGER.info("added created bi directional relationship with {}", relationship.getRelatedLink());
370 return ResponseEntity.accepted().build();
373 LOGGER.error("Couldn't add {} relationship for 'key': {} ...", relationship.getRelatedLink(), key);
374 return getRequestErrorResponseEntity(request, CLOUD_REGION);
379 value = "{cloud-owner}/{cloud-region-id}/tenants/tenant/{tenant-id}/vservers/vserver/{vserver-id}"
380 + BI_DIRECTIONAL_RELATIONSHIP_LIST_URL,
381 consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
382 produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
383 public ResponseEntity<?> putBiDirectionalVServerRelationShip(@PathVariable("cloud-owner") final String cloudOwner,
384 @PathVariable("cloud-region-id") final String cloudRegionId,
385 @PathVariable("tenant-id") final String tenantId, @PathVariable("vserver-id") final String vServerId,
386 @RequestBody final Relationship relationship, final HttpServletRequest request) {
387 final CloudRegionKey key = new CloudRegionKey(cloudOwner, cloudRegionId);
388 LOGGER.info("Will add {} bi-directional relationship to : {} ...", relationship.getRelatedTo());
390 final Optional<Relationship> optional = cacheServiceProvider.addvServerRelationShip(key, tenantId, vServerId,
391 relationship, request.getRequestURI());
393 if (optional.isPresent()) {
394 final Relationship resultantRelationship = optional.get();
395 LOGGER.info("Relationship add, sending resultant relationship: {} in response ...", resultantRelationship);
396 return ResponseEntity.accepted().body(resultantRelationship);
398 LOGGER.error("Couldn't add {} relationship for 'key': {} ...", relationship.getRelatedTo(), key);
399 return getRequestErrorResponseEntity(request, CLOUD_REGION);
404 @PutMapping(value = "{cloud-owner}/{cloud-region-id}/tenants/tenant/{tenant-id}/k8s-resources/k8s-resource/{id}",
405 consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
406 produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
407 public ResponseEntity<?> putK8sResource(@RequestBody final K8SResource k8sResource,
408 @PathVariable("cloud-owner") final String cloudOwner,
409 @PathVariable("cloud-region-id") final String cloudRegionId,
410 @PathVariable("tenant-id") final String tenantId, @PathVariable("id") final String id,
411 final HttpServletRequest request) {
413 final CloudRegionKey key = new CloudRegionKey(cloudOwner, cloudRegionId);
416 LOGGER.info("Will add K8s Resource to cache with key 'key': {} ....", key);
417 if (k8sResource.getResourceVersion() == null || k8sResource.getResourceVersion().isEmpty()) {
418 k8sResource.setResourceVersion(getResourceVersion());
420 if (cacheServiceProvider.putK8sResource(key, tenantId, id, k8sResource)) {
421 return ResponseEntity.accepted().build();
425 LOGGER.error("Unable to add K8s Resource in cache using key {}", key);
426 return getRequestErrorResponseEntity(request, CLOUD_REGION);
429 @GetMapping(value = "{cloud-owner}/{cloud-region-id}/tenants/tenant/{tenant-id}/k8s-resources/k8s-resource/{id}",
430 produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
431 public ResponseEntity<?> getK8sResource(@PathVariable("cloud-owner") final String cloudOwner,
432 @PathVariable("cloud-region-id") final String cloudRegionId,
433 @PathVariable("tenant-id") final String tenantId, @PathVariable("id") final String id,
434 final HttpServletRequest request) {
435 final CloudRegionKey key = new CloudRegionKey(cloudOwner, cloudRegionId);
436 LOGGER.info("Retrieving K8SResource using key : {}, tenant-id:{} and id: {}...", key, tenantId, id);
438 final Optional<K8SResource> optional = cacheServiceProvider.getK8sResource(key, tenantId, id);
439 if (optional.isPresent()) {
440 final K8SResource tenant = optional.get();
441 LOGGER.info("found K8SResource {} in cache", tenant);
442 return ResponseEntity.ok(tenant);
445 LOGGER.error("Unable to find K8SResource in cache key : {},tenant-id:{} and id: {}...", key, tenantId, id);
446 return getRequestErrorResponseEntity(request, CLOUD_REGION);
450 value = "{cloud-owner}/{cloud-region-id}/tenants/tenant/{tenant-id}/k8s-resources/k8s-resource/{id}"
451 + RELATIONSHIP_LIST_RELATIONSHIP_URL,
452 consumes = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML},
453 produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
454 public ResponseEntity<?> putK8sResourceRelationShip(@PathVariable("cloud-owner") final String cloudOwner,
455 @PathVariable("cloud-region-id") final String cloudRegionId,
456 @PathVariable("tenant-id") final String tenantId, @PathVariable("id") final String id,
457 @RequestBody final Relationship relationship, final HttpServletRequest request) {
458 final CloudRegionKey key = new CloudRegionKey(cloudOwner, cloudRegionId);
459 LOGGER.info("Will add {} relationship for key : {}, tenant-id: {} and id: {}...", relationship.getRelatedLink(),
462 if (relationship.getRelatedLink() != null) {
463 final String targetBaseUrl = HttpServiceUtils.getBaseUrl(request).toString();
464 final HttpHeaders incomingHeader = getHeaders(request);
465 final boolean result = cacheServiceProvider.addK8sResourceRelationShip(incomingHeader, targetBaseUrl,
466 request.getRequestURI(), key, tenantId, id, relationship);
468 LOGGER.info("added created bi directional relationship with {}", relationship.getRelatedLink());
469 return ResponseEntity.accepted().build();
472 LOGGER.error("Couldn't add {} relationship for 'key': {} ...", relationship.getRelatedLink(), key);
473 return getRequestErrorResponseEntity(request, CLOUD_REGION);
477 @DeleteMapping(value = "{cloud-owner}/{cloud-region-id}/tenants/tenant/{tenant-id}/k8s-resources/k8s-resource/{id}",
478 produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
479 public ResponseEntity<?> deleteK8sResource(@PathVariable("cloud-owner") final String cloudOwner,
480 @PathVariable("cloud-region-id") final String cloudRegionId,
481 @PathVariable("tenant-id") final String tenantId, @PathVariable("id") final String id,
482 @RequestParam(name = "resource-version") final String resourceVersion,
483 final HttpServletRequest request) {
484 final CloudRegionKey key = new CloudRegionKey(cloudOwner, cloudRegionId);
485 LOGGER.info("Removing K8SResource using key : {}, tenant-id:{} and id: {}...", key, tenantId, id);
487 final boolean result = cacheServiceProvider.deleteK8sResource(key, tenantId, id, resourceVersion);
489 LOGGER.info("Deleted K8SResource from cache related to tenant ID: {}", tenantId);
490 return ResponseEntity.status(HttpStatus.NO_CONTENT).build();
492 return ResponseEntity.status(HttpStatus.NOT_FOUND).build();
495 LOGGER.error("Unable to find K8SResource in cache key : {},tenant-id:{} and id: {}...", key, tenantId, id);
496 return getRequestErrorResponseEntity(request, CLOUD_REGION);