2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.sdnc.apps.ms.gra.controllers;
23 import com.fasterxml.jackson.annotation.JsonInclude;
24 import com.fasterxml.jackson.core.JsonProcessingException;
25 import com.fasterxml.jackson.databind.JsonMappingException;
26 import com.fasterxml.jackson.databind.ObjectMapper;
27 import org.onap.ccsdk.apps.services.RestApplicationException;
28 import org.onap.ccsdk.apps.services.RestException;
29 import org.onap.ccsdk.apps.services.RestProtocolError;
30 import org.onap.ccsdk.apps.services.RestProtocolException;
31 import org.onap.sdnc.apps.ms.gra.data.ConfigPreloadData;
32 import org.onap.sdnc.apps.ms.gra.data.ConfigPreloadDataRepository;
33 import org.onap.sdnc.apps.ms.gra.data.ConfigServices;
34 import org.onap.sdnc.apps.ms.gra.data.ConfigServicesRepository;
35 import org.onap.sdnc.apps.ms.gra.data.ConfigPortMirrorConfigurations;
36 import org.onap.sdnc.apps.ms.gra.data.ConfigPortMirrorConfigurationsRepository;
37 import org.onap.sdnc.apps.ms.gra.data.ConfigContrailRouteAllottedResources;
38 import org.onap.sdnc.apps.ms.gra.data.ConfigContrailRouteAllottedResourcesRepository;
39 import org.onap.sdnc.apps.ms.gra.swagger.ConfigApi;
40 import org.onap.sdnc.apps.ms.gra.swagger.model.*;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43 import org.springframework.beans.factory.annotation.Autowired;
44 import org.springframework.boot.autoconfigure.domain.EntityScan;
45 import org.springframework.context.annotation.ComponentScan;
46 import org.springframework.http.HttpStatus;
47 import org.springframework.http.ResponseEntity;
48 import org.springframework.stereotype.Controller;
50 import javax.servlet.http.HttpServletRequest;
51 import javax.validation.Valid;
52 import java.util.ArrayList;
53 import java.util.Iterator;
54 import java.util.LinkedList;
55 import java.util.List;
56 import java.util.Optional;
57 import java.util.concurrent.atomic.AtomicBoolean;
58 import java.util.stream.Collectors;
59 import java.util.stream.Stream;
62 @ComponentScan(basePackages = { "org.onap.sdnc.apps.ms.gra.*" })
63 @EntityScan("org.onap.sdnc.apps.ms.gra.springboot.*")
64 public class ConfigApiController implements ConfigApi {
65 private static final Logger log = LoggerFactory.getLogger(ConfigApiController.class);
67 private final ObjectMapper objectMapper;
69 private final HttpServletRequest request;
72 private ConfigPreloadDataRepository configPreloadDataRepository;
75 private ConfigServicesRepository configServicesRepository;
78 private ConfigPortMirrorConfigurationsRepository configPortMirrorConfigurationsRepository;
81 private ConfigContrailRouteAllottedResourcesRepository configContrailRouteAllottedResourcesRepository;
85 public ConfigApiController(ObjectMapper objectMapper, HttpServletRequest request) {
86 objectMapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
87 objectMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
88 this.objectMapper = objectMapper;
89 this.request = request;
93 public Optional<ObjectMapper> getObjectMapper() {
94 return Optional.ofNullable(objectMapper);
98 public Optional<HttpServletRequest> getRequest() {
99 return Optional.ofNullable(request);
103 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationDelete() {
104 configPreloadDataRepository.deleteAll();
105 return (new ResponseEntity<>(HttpStatus.NO_CONTENT));
109 * Extracts port-mirror configuration data from CONFIG_GRA_PORT_MIRROR_CONFIGURATIONS for a given, configuration-id
111 * Maps to /config/GENERIC-RESOURCE-API:port-mirror-configurations/port-mirror-configuration/{configuration-id}/
112 * @param configurationId the configuration ID for a port-mirror
113 * @return HttpStatus.OK (200) if the data is found.
114 * @throws RestException if the data does not exist.
116 public ResponseEntity<GenericResourceApiPortmirrorconfigurationsPortMirrorConfiguration>
117 configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdGet(
118 String configurationId) throws RestApplicationException {
119 GenericResourceApiPortmirrorconfigurationsPortMirrorConfiguration retval = null;
121 List<ConfigPortMirrorConfigurations> pmConfigurations = configPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
123 if (pmConfigurations.isEmpty()) {
124 log.info("No configuration data found with id [{}]",configurationId);
125 return new ResponseEntity<>(HttpStatus.NOT_FOUND);
127 ConfigPortMirrorConfigurations pmConfiguration = pmConfigurations.get(0);
128 retval = new GenericResourceApiPortmirrorconfigurationsPortMirrorConfiguration();
129 retval.setConfigurationId(configurationId);
130 retval.setConfigurationStatus(pmConfiguration.getPortMirrorConfigurationStatus());
132 retval.setConfigurationData(objectMapper.readValue(pmConfiguration.getPmcData(), GenericResourceApiPortmirrorconfigurationsPortmirrorconfigurationConfigurationData.class));
133 } catch (JsonProcessingException e) {
134 log.error("Could not deserialize service data for service instance id {}", configurationId, e);
135 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
138 return new ResponseEntity<>(retval, HttpStatus.OK);
142 public ResponseEntity<Void> configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdPut(
143 String configurationId, @Valid GenericResourceApiPortmirrorconfigurationsPortMirrorConfiguration newConfiguration)
144 throws RestApplicationException {
146 boolean dataExists = false;
148 String newConfigurationId = newConfiguration.getConfigurationId();
150 ConfigPortMirrorConfigurations portMirrorConfiguration = null;
151 List<ConfigPortMirrorConfigurations> existingConfiguration = configPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
152 if ((existingConfiguration != null) && !existingConfiguration.isEmpty()) {
154 portMirrorConfiguration = existingConfiguration.get(0);
156 portMirrorConfiguration = new ConfigPortMirrorConfigurations();
157 portMirrorConfiguration.setConfigureationId(configurationId);
161 portMirrorConfiguration.setPmcData(objectMapper.writeValueAsString(newConfiguration.getConfigurationData()));
162 } catch (JsonProcessingException e) {
163 log.error("Could not serialize porr-mirror configuration data for {}", portMirrorConfiguration.getConfigureationId(), e);
164 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
167 portMirrorConfiguration.setPortMirrorConfigurationStatus(newConfiguration.getConfigurationStatus());
168 configPortMirrorConfigurationsRepository.save(portMirrorConfiguration);
171 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
173 return new ResponseEntity<>(HttpStatus.CREATED);
178 public ResponseEntity<GenericResourceApiPortmirrorconfigurationtopologyPortMirrorConfigurationTopology>
179 configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdConfigurationDataPortMirrorConfigurationTopologyGet(
180 String configurationId) throws RestApplicationException, RestProtocolException {
181 @Valid GenericResourceApiPortmirrorconfigurationtopologyPortMirrorConfigurationTopology portMirrorConfigurationTopology = null;
182 GenericResourceApiPortmirrorconfigurationsPortmirrorconfigurationConfigurationData portMirrorConfigurationData = null;
184 List<ConfigPortMirrorConfigurations> configPortMirrorConfigurations = configPortMirrorConfigurationsRepository.findByConfigurationId(configurationId);
185 if ((configPortMirrorConfigurations == null) || (configPortMirrorConfigurations.isEmpty())) {
186 throw new RestProtocolException("data-missing", "No port-mirror-configuration entry found", HttpStatus.NOT_FOUND.value());
190 if ( configPortMirrorConfigurations.get(0).getPmcData().isEmpty()) {
191 throw new RestProtocolException("data-missing", "No configuration-data entry found", HttpStatus.NOT_FOUND.value());
193 portMirrorConfigurationData = objectMapper.readValue(configPortMirrorConfigurations.get(0).getPmcData(), GenericResourceApiPortmirrorconfigurationsPortmirrorconfigurationConfigurationData.class);
194 portMirrorConfigurationTopology = portMirrorConfigurationData.getPortMirrorConfigurationTopology();
196 if (portMirrorConfigurationTopology == null) {
197 throw new RestProtocolException("data-missing", "No service-topology entry found", HttpStatus.NOT_FOUND.value());
199 return new ResponseEntity<>(portMirrorConfigurationTopology, HttpStatus.OK);
200 } catch (JsonProcessingException e) {
201 log.error("Could not parse service data", e);
202 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
208 public ResponseEntity<Void> configGENERICRESOURCEAPIportMirrorConfigurationsPortMirrorConfigurationConfigurationIdDelete(String configurationId) {
209 configPortMirrorConfigurationsRepository.deleteByConfigurationId(configurationId);
210 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
214 * Extracts contrail-route-allotted-resource data from CONFIG_GRA_CONTRAIL_ROUTE_ALLOTTED_RESOURCES for a given allottedResourceId
216 * Maps to /config/GENERIC-RESOURCE-API:contrail-route-allotted-resources/contrail-route-allotted-resource/{allotted-resource-id}
217 * @param allottedResourceId the allotted-resource-id for a contrail-route
218 * @return HttpStatus.OK (200) if the data is found.
219 * @throws RestException if the data does not exist.
221 public ResponseEntity<GenericResourceApiContrailrouteallottedresourcesContrailRouteAllottedResource>
222 configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdGet(
223 String allottedResourceId) throws RestApplicationException {
224 GenericResourceApiContrailrouteallottedresourcesContrailRouteAllottedResource retval = null;
226 List<ConfigContrailRouteAllottedResources> allottedResources = configContrailRouteAllottedResourcesRepository.findByAllottedResourceId(allottedResourceId);
228 if (allottedResources.isEmpty()) {
229 return new ResponseEntity<>(HttpStatus.NOT_FOUND);
232 ConfigContrailRouteAllottedResources allottedResource = allottedResources.get(0);
233 retval = new GenericResourceApiContrailrouteallottedresourcesContrailRouteAllottedResource();
234 retval.setAllottedResourceId(allottedResourceId);
235 retval.setAllottedResourceStatus(allottedResource.getAllottedResourceStatus());
237 retval.setAllottedResourceData(objectMapper.readValue(allottedResource.getArData(),
238 GenericResourceApiContrailrouteallottedresourcesContrailrouteallottedresourceAllottedResourceData.class));
239 } catch (JsonProcessingException e) {
240 log.error("Could not deserialize service data for service instance id {}", allottedResourceId, e);
241 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
244 return new ResponseEntity<>(retval, HttpStatus.OK);
248 * PUT contrail-route-allotted-resource data from CONFIG_GRA_CONTRAIL_ROUTE_ALLOTTED_RESOURCES for a given allottedResourceId
250 * Maps to /config/GENERIC-RESOURCE-API:contrail-route-allotted-resources/contrail-route-allotted-resource/{allotted-resource-id}
251 * @param allottedResourceId the allotted-resource-id for a contrail-route
252 * @return HttpStatus.OK (200) if the data is found.
253 * @throws RestException if the data does not exist.
256 public ResponseEntity<Void> configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdPut(
257 String allottedResourceId, @Valid GenericResourceApiContrailrouteallottedresourcesContrailRouteAllottedResource newAllottedResource)
258 throws RestApplicationException {
260 boolean dataExists = false;
262 String newAllottedResourceId = newAllottedResource.getAllottedResourceId();
264 ConfigContrailRouteAllottedResources allottedResource = null;
265 List<ConfigContrailRouteAllottedResources> existingAllottedResource =
266 configContrailRouteAllottedResourcesRepository.findByAllottedResourceId(allottedResourceId);
268 if ((existingAllottedResource != null) && !existingAllottedResource.isEmpty()) {
270 allottedResource = existingAllottedResource.get(0);
272 allottedResource = new ConfigContrailRouteAllottedResources();
273 allottedResource.setAllottedResourceId(allottedResourceId);
277 allottedResource.setArData(objectMapper.writeValueAsString(newAllottedResource.getAllottedResourceData()));
278 } catch (JsonProcessingException e) {
279 log.error("Could not serialize porr-mirror configuration data for {}", allottedResource.getAllottedResourceId(), e);
280 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
283 allottedResource.setAllottedResourceStatus(newAllottedResource.getAllottedResourceStatus());
284 configContrailRouteAllottedResourcesRepository.save(allottedResource);
287 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
289 return new ResponseEntity<>(HttpStatus.CREATED);
294 * Extracts contrail-route-topology data from CONFIG_GRA_CONTRAIL_ROUTE_ALLOTTED_RESOURCES for a given allottedResourceId
296 * Maps to /config/GENERIC-RESOURCE-API:contrail-route-allotted-resources/contrail-route-allotted-resource/{allotted-resource-id}/allotted-resource-data/contrail-route-topology/
297 * @param allottedResourceId the allotted-resource-id for a contrail-route
298 * @return HttpStatus.OK (200) if the data is found.
299 * @throws RestException if the data does not exist.
302 public ResponseEntity<GenericResourceApiContrailroutetopologyContrailRouteTopology>
303 configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdAllottedResourceDataContrailRouteTopologyGet(
304 String allottedResourceId) throws RestApplicationException, RestProtocolException {
305 @Valid GenericResourceApiContrailroutetopologyContrailRouteTopology contrailRouteTopology = null;
306 GenericResourceApiContrailrouteallottedresourcesContrailrouteallottedresourceAllottedResourceData allottedResourceData = null;
308 List<ConfigContrailRouteAllottedResources> configContrailRouteAllottedResources =
309 configContrailRouteAllottedResourcesRepository.findByAllottedResourceId(allottedResourceId);
311 if ((configContrailRouteAllottedResources == null) || (configContrailRouteAllottedResources.isEmpty())) {
312 throw new RestProtocolException("data-missing", "No port-mirror-configuration entry found", HttpStatus.NOT_FOUND.value());
316 if ( configContrailRouteAllottedResources.get(0).getArData().isEmpty()) {
317 throw new RestProtocolException("data-missing", "No allotted-resource-data entry found", HttpStatus.NOT_FOUND.value());
319 allottedResourceData = objectMapper.readValue(configContrailRouteAllottedResources.get(0).getArData(),
320 GenericResourceApiContrailrouteallottedresourcesContrailrouteallottedresourceAllottedResourceData.class);
322 contrailRouteTopology = allottedResourceData.getContrailRouteTopology();
324 if (contrailRouteTopology == null) {
325 throw new RestProtocolException("data-missing", "No contrail-route-topology entry found", HttpStatus.NOT_FOUND.value());
327 return new ResponseEntity<>(contrailRouteTopology, HttpStatus.OK);
328 } catch (JsonProcessingException e) {
329 log.error("Could not parse port-mirror-configuration data", e);
330 throw new RestApplicationException("data-conversion", "Request could not be completed due to internal error", e, HttpStatus.INTERNAL_SERVER_ERROR.value());
336 * DELETE allotted-resource data from CONFIG_GRA_CONTRAIL_ROUTE_ALLOTTED_RESOURCES for a given allottedResourceId
338 * Maps to /config/GENERIC-RESOURCE-API:contrail-route-allotted-resources/contrail-route-allotted-resource/{allotted-resource-id}
339 * @param allottedResourceId the allotted-resource-id for a contrail-route
340 * @return HttpStatus.NO_CONTENT (204) if the data is found.
343 public ResponseEntity<Void> configGENERICRESOURCEAPIcontrailRouteAllottedResourcesContrailRouteAllottedResourceAllottedResourceIdDelete(
344 String allottedResourceId) {
345 configContrailRouteAllottedResourcesRepository.deleteByAllottedResourceId(allottedResourceId);
346 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
352 public ResponseEntity<GenericResourceApiPreloadModelInformation> configGENERICRESOURCEAPIpreloadInformationGet()
353 throws RestApplicationException {
354 GenericResourceApiPreloadModelInformation genericResourceApiPreloadModelInformation = new GenericResourceApiPreloadModelInformation();
356 if (configPreloadDataRepository.count() == 0) {
357 throw new RestApplicationException("data-missing",
358 "Request could not be completed because the relevant data model content does not exist",
359 HttpStatus.NOT_FOUND.value());
362 for (ConfigPreloadData configPreloadData : configPreloadDataRepository.findAll()) {
363 GenericResourceApiPreloadmodelinformationPreloadList preloadListItem = new GenericResourceApiPreloadmodelinformationPreloadList();
365 preloadListItem.setPreloadId(configPreloadData.getPreloadId());
366 preloadListItem.setPreloadType(configPreloadData.getPreloadType());
368 preloadListItem.setPreloadData(objectMapper.readValue(configPreloadData.getPreloadData(),
369 GenericResourceApiPreloaddataPreloadData.class));
370 } catch (JsonProcessingException e) {
371 log.error("Could not convert preload data", e);
372 throw new RestApplicationException("data-conversion",
373 "Request could not be completed due to internal error", e,
374 HttpStatus.INTERNAL_SERVER_ERROR.value());
376 genericResourceApiPreloadModelInformation.addPreloadListItem(preloadListItem);
379 return new ResponseEntity<>(genericResourceApiPreloadModelInformation, HttpStatus.OK);
383 public ResponseEntity<GenericResourceApiPreloadnetworktopologyinformationPreloadNetworkTopologyInformation> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataPreloadNetworkTopologyInformationGet(
384 String preloadId, String preloadType) throws RestException {
385 GenericResourceApiPreloadnetworktopologyinformationPreloadNetworkTopologyInformation netTopoInfo = null;
387 if (configPreloadDataRepository.count() == 0) {
388 throw new RestApplicationException("data-missing",
389 "Request could not be completed because the relevant data model content does not exist",
390 HttpStatus.NOT_FOUND.value());
393 for (ConfigPreloadData configPreloadData : configPreloadDataRepository.findAll()) {
396 GenericResourceApiPreloaddataPreloadData preloadDataItem = objectMapper
397 .readValue(configPreloadData.getPreloadData(), GenericResourceApiPreloaddataPreloadData.class);
398 netTopoInfo = preloadDataItem.getPreloadNetworkTopologyInformation();
399 } catch (JsonProcessingException e) {
400 log.error("Could not convert preload data", e);
401 throw new RestApplicationException("data-conversion",
402 "Request could not be completed due to internal error", e,
403 HttpStatus.INTERNAL_SERVER_ERROR.value());
407 return new ResponseEntity<>(netTopoInfo, HttpStatus.OK);
412 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPost(
413 @Valid GenericResourceApiPreloadModelInformation graPreloadModelInfo)
414 throws RestApplicationException, RestProtocolException {
416 List<GenericResourceApiPreloadmodelinformationPreloadList> preloadList = graPreloadModelInfo.getPreloadList();
417 List<ConfigPreloadData> newPreloadData = new LinkedList<>();
419 if (preloadList != null) {
420 // Verification pass - if any items already exist, return an error
421 for (GenericResourceApiPreloadmodelinformationPreloadList curItem : preloadList) {
423 List<ConfigPreloadData> curPreloadData = configPreloadDataRepository
424 .findByPreloadIdAndPreloadType(curItem.getPreloadId(), curItem.getPreloadType());
425 if ((curPreloadData != null) && (!curPreloadData.isEmpty())) {
426 log.error("Preload data already exists for {}:{}", curItem.getPreloadId(),
427 curItem.getPreloadType());
428 throw new RestProtocolException("data-exists",
429 "Data already exists for " + curItem.getPreloadId() + ":" + curItem.getPreloadType(),
430 HttpStatus.CONFLICT.value());
433 newPreloadData.add(new ConfigPreloadData(curItem.getPreloadId(), curItem.getPreloadType(),
434 objectMapper.writeValueAsString(curItem.getPreloadData())));
435 } catch (JsonProcessingException e) {
436 log.error("Cannot convert preload data");
437 throw new RestApplicationException("data-conversion",
438 "Request could not be completed due to internal error", e,
439 HttpStatus.INTERNAL_SERVER_ERROR.value());
446 for (ConfigPreloadData newDataItem : newPreloadData) {
447 log.info("Adding preload data for {}:{}", newDataItem.getPreloadId(), newDataItem.getPreloadType());
448 configPreloadDataRepository.save(newDataItem);
451 throw new RestProtocolException("data-missing", "No preload-list entries found to add",
452 HttpStatus.CONFLICT.value());
455 return new ResponseEntity<>(HttpStatus.CREATED);
459 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPut(
460 @Valid GenericResourceApiPreloadModelInformation graPreloadModelInfo) throws RestApplicationException {
462 boolean addedNew = false;
463 List<GenericResourceApiPreloadmodelinformationPreloadList> preloadList = graPreloadModelInfo.getPreloadList();
465 if (preloadList != null) {
466 Iterator<GenericResourceApiPreloadmodelinformationPreloadList> iter = preloadList.iterator();
467 while (iter.hasNext()) {
468 GenericResourceApiPreloadmodelinformationPreloadList curItem = iter.next();
469 List<ConfigPreloadData> curPreloadData = configPreloadDataRepository
470 .findByPreloadIdAndPreloadType(curItem.getPreloadId(), curItem.getPreloadType());
471 if ((curPreloadData == null) || curPreloadData.isEmpty()) {
476 configPreloadDataRepository.save(new ConfigPreloadData(curItem.getPreloadId(),
477 curItem.getPreloadType(), objectMapper.writeValueAsString(curItem.getPreloadData())));
478 } catch (JsonProcessingException e) {
479 log.error("Cannot convert preload data", e);
480 throw new RestApplicationException("data-conversion",
481 "Request could not be completed due to internal error", e,
482 HttpStatus.INTERNAL_SERVER_ERROR.value());
489 return new ResponseEntity<>(HttpStatus.CREATED);
491 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
497 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPost(
498 @Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem) throws RestProtocolException {
500 throw new RestProtocolException("data-missing", "Missing key for list \"preload-list\"",
501 HttpStatus.NOT_FOUND.value());
505 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypeDelete(
506 String preloadId, String preloadType) {
507 configPreloadDataRepository.deleteByPreloadIdAndPreloadType(preloadId, preloadType);
508 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
512 public ResponseEntity<GenericResourceApiPreloadmodelinformationPreloadList> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypeGet(
513 String preloadId, String preloadType) throws RestApplicationException {
514 List<ConfigPreloadData> preloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
516 if (preloadData != null) {
517 if (!preloadData.isEmpty()) {
518 ConfigPreloadData preloadDataItem = preloadData.get(0);
519 GenericResourceApiPreloadmodelinformationPreloadList preloadDataList = new GenericResourceApiPreloadmodelinformationPreloadList();
520 preloadDataList.setPreloadId(preloadDataItem.getPreloadId());
521 preloadDataList.setPreloadType(preloadDataItem.getPreloadType());
523 preloadDataList.setPreloadData(objectMapper.readValue(preloadDataItem.getPreloadData(),
524 GenericResourceApiPreloaddataPreloadData.class));
525 } catch (JsonProcessingException e) {
526 log.error("Cannot convert preload data", e);
527 throw new RestApplicationException("data-conversion",
528 "Request could not be completed due to internal error", e,
529 HttpStatus.INTERNAL_SERVER_ERROR.value());
531 return new ResponseEntity<>(preloadDataList, HttpStatus.OK);
534 return new ResponseEntity<>(HttpStatus.NOT_FOUND);
538 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePost(
539 String preloadId, String preloadType,
540 @Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem)
541 throws RestApplicationException, RestProtocolException {
542 List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
545 if ((preloadDataItems != null) && !preloadDataItems.isEmpty()) {
546 log.error("Preload data already exists for {}:{}", preloadId, preloadType);
547 throw new RestProtocolException("data-exists", "Data already exists for " + preloadId + ":" + preloadType,
548 HttpStatus.CONFLICT.value());
552 log.info("Adding preload data for {}:{}", preloadId, preloadType);
553 configPreloadDataRepository.save(new ConfigPreloadData(preloadId, preloadType,
554 objectMapper.writeValueAsString(preloadListItem.getPreloadData())));
555 } catch (JsonProcessingException e) {
556 log.error("Cannot convert preload data", e);
557 throw new RestApplicationException("data-conversion",
558 "Request could not be completed due to internal error", e,
559 HttpStatus.INTERNAL_SERVER_ERROR.value());
562 return new ResponseEntity<>(HttpStatus.CREATED);
566 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePut(
567 String preloadId, String preloadType,
568 @Valid GenericResourceApiPreloadmodelinformationPreloadList preloadListItem)
569 throws RestApplicationException, RestProtocolException {
570 List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
572 boolean dataExists = false;
573 if ((preloadDataItems != null) && !preloadDataItems.isEmpty()) {
577 if ((preloadListItem.getPreloadId() == null) || (preloadListItem.getPreloadType() == null)
578 || (preloadListItem.getPreloadData() == null)) {
579 log.error("Invalid list item received: {}", preloadListItem);
580 throw new RestProtocolException("bad-attribute", "Invalid data received", HttpStatus.BAD_REQUEST.value());
585 log.info("Updating preload data for {}:{} -> {}", preloadId, preloadType,
586 objectMapper.writeValueAsString(preloadListItem));
589 log.info("Adding preload data for {}:{}", preloadId, preloadType);
592 configPreloadDataRepository.save(new ConfigPreloadData(preloadId, preloadType,
593 objectMapper.writeValueAsString(preloadListItem.getPreloadData())));
594 } catch (JsonProcessingException e) {
595 log.error("Cannot convert preload data", e);
596 throw new RestApplicationException("data-conversion",
597 "Request could not be completed due to internal error", e,
598 HttpStatus.INTERNAL_SERVER_ERROR.value());
603 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
605 return new ResponseEntity<>(HttpStatus.CREATED);
610 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataDelete(
611 String preloadId, String preloadType) throws RestProtocolException {
612 List<ConfigPreloadData> preloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
615 if ((preloadData == null) || preloadData.isEmpty()) {
616 throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value());
619 ConfigPreloadData preloadDataItem = preloadData.get(0);
621 if (preloadDataItem.getPreloadData() == null) {
622 throw new RestProtocolException("data-missing", "No preload-data found", HttpStatus.NOT_FOUND.value());
624 preloadDataItem.setPreloadData(null);
625 configPreloadDataRepository.save(preloadDataItem);
627 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
631 public ResponseEntity<GenericResourceApiPreloaddataPreloadData> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataGet(
632 String preloadId, String preloadType) throws RestApplicationException, RestProtocolException {
633 List<ConfigPreloadData> preloadData = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
636 if ((preloadData == null) || preloadData.isEmpty()) {
637 throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value());
640 ConfigPreloadData preloadDataItem = preloadData.get(0);
642 if (preloadDataItem.getPreloadData() == null) {
643 throw new RestProtocolException("data-missing", "No preload-data found", HttpStatus.NOT_FOUND.value());
646 return new ResponseEntity<>(objectMapper.readValue(preloadDataItem.getPreloadData(),
647 GenericResourceApiPreloaddataPreloadData.class), HttpStatus.OK);
648 } catch (JsonProcessingException e) {
649 log.error("Cannot convert preload data", e);
650 throw new RestApplicationException("data-conversion",
651 "Request could not be completed due to internal error", e,
652 HttpStatus.INTERNAL_SERVER_ERROR.value());
657 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataPost(
658 String preloadId, String preloadType, @Valid GenericResourceApiPreloaddataPreloadData preloadData)
659 throws RestApplicationException, RestProtocolException {
660 List<ConfigPreloadData> preloadDataEntries = configPreloadDataRepository
661 .findByPreloadIdAndPreloadType(preloadId, preloadType);
663 List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
665 if ((preloadDataItems == null) || (preloadDataItems.isEmpty())) {
666 throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value());
669 if ((preloadData == null) || (preloadData.getPreloadNetworkTopologyInformation() == null)) {
670 throw new RestProtocolException("bad-attribute", "Invalid preloadData received",
671 HttpStatus.BAD_REQUEST.value());
674 ConfigPreloadData preloadDataItem = preloadDataItems.get(0);
676 if (preloadDataItem.getPreloadData() != null) {
677 log.error("Preload data already exists for {}:{} ", preloadId, preloadType);
678 throw new RestProtocolException("data-exists", "Data already exists for " + preloadId + ":" + preloadType,
679 HttpStatus.CONFLICT.value());
683 preloadDataItem.setPreloadData(objectMapper.writeValueAsString(preloadData));
684 configPreloadDataRepository.save(preloadDataItem);
685 } catch (JsonProcessingException e) {
686 log.error("Cannot convert preload data", e);
687 throw new RestApplicationException("data-conversion",
688 "Request could not be completed due to internal error", e,
689 HttpStatus.INTERNAL_SERVER_ERROR.value());
692 return new ResponseEntity<>(HttpStatus.CREATED);
696 public ResponseEntity<Void> configGENERICRESOURCEAPIpreloadInformationPreloadListPreloadIdPreloadTypePreloadDataPut(
697 String preloadId, String preloadType, @Valid GenericResourceApiPreloaddataPreloadData preloadData)
698 throws RestApplicationException, RestProtocolException {
699 boolean dataExists = false;
700 List<ConfigPreloadData> preloadDataItems = configPreloadDataRepository.findByPreloadIdAndPreloadType(preloadId,
702 if ((preloadDataItems == null) || (preloadDataItems.isEmpty())) {
703 throw new RestProtocolException("data-missing", "No preload entry found", HttpStatus.NOT_FOUND.value());
706 if ((preloadData == null) || (preloadData.getPreloadNetworkTopologyInformation() == null)) {
707 throw new RestProtocolException("bad-attribute", "Invalid preloadData received",
708 HttpStatus.BAD_REQUEST.value());
711 ConfigPreloadData preloadDataItem = preloadDataItems.get(0);
713 if (preloadDataItem.getPreloadData() != null) {
718 preloadDataItem.setPreloadData(objectMapper.writeValueAsString(preloadData));
719 configPreloadDataRepository.save(preloadDataItem);
720 } catch (JsonProcessingException e) {
721 log.error("Cannot convert preload data", e);
722 throw new RestApplicationException("data-conversion",
723 "Request could not be completed due to internal error", e,
724 HttpStatus.INTERNAL_SERVER_ERROR.value());
728 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
730 return new ResponseEntity<>(HttpStatus.CREATED);
735 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesDelete() {
736 configServicesRepository.deleteAll();
737 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
741 public ResponseEntity<GenericResourceApiServiceModelInfrastructure> configGENERICRESOURCEAPIservicesGet()
742 throws RestApplicationException {
743 GenericResourceApiServiceModelInfrastructure modelInfrastructure = new GenericResourceApiServiceModelInfrastructure();
745 if (configServicesRepository.count() == 0) {
746 throw new RestApplicationException("data-missing",
747 "Request could not be completed because the relevant data model content does not exist",
748 HttpStatus.NOT_FOUND.value());
751 for (ConfigServices service : configServicesRepository.findAll()) {
752 GenericResourceApiServicemodelinfrastructureService serviceItem = new GenericResourceApiServicemodelinfrastructureService();
753 serviceItem.setServiceInstanceId(service.getSvcInstanceId());
754 if (service.getSvcData() != null) {
756 serviceItem.setServiceData(objectMapper.readValue(service.getSvcData(),
757 GenericResourceApiServicedataServiceData.class));
758 } catch (JsonProcessingException e) {
759 log.error("Could not deserialize service data for {}", service.getSvcInstanceId(), e);
760 throw new RestApplicationException("data-conversion",
761 "Request could not be completed due to internal error", e,
762 HttpStatus.INTERNAL_SERVER_ERROR.value());
766 serviceItem.setServiceStatus(service.getServiceStatus());
767 modelInfrastructure.addServiceItem(serviceItem);
770 return new ResponseEntity<>(modelInfrastructure, HttpStatus.OK);
775 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesPost(
776 @Valid GenericResourceApiServiceModelInfrastructure modelInfrastructure)
777 throws RestApplicationException, RestProtocolException {
778 List<ConfigServices> newServices = new LinkedList<>();
780 for (GenericResourceApiServicemodelinfrastructureService serviceItem : modelInfrastructure.getService()) {
781 String svcInstanceId = serviceItem.getServiceInstanceId();
782 List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId);
783 if ((existingService != null) && !existingService.isEmpty()) {
784 log.error("Service data already exists for {}", svcInstanceId);
785 throw new RestProtocolException("data-exists",
786 "Data already exists for service-instance-id " + svcInstanceId, HttpStatus.CONFLICT.value());
788 ConfigServices service = new ConfigServices();
789 service.setSvcInstanceId(svcInstanceId);
791 service.setSvcData(objectMapper.writeValueAsString(serviceItem.getServiceData()));
792 } catch (JsonProcessingException e) {
793 log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e);
794 throw new RestApplicationException("data-conversion",
795 "Request could not be completed due to internal error", e,
796 HttpStatus.INTERNAL_SERVER_ERROR.value());
799 service.setServiceStatus(serviceItem.getServiceStatus());
800 newServices.add(service);
803 for (ConfigServices service : newServices) {
804 configServicesRepository.save(service);
807 return new ResponseEntity<>(HttpStatus.CREATED);
812 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesPut(
813 @Valid GenericResourceApiServiceModelInfrastructure modelInfrastructure) throws RestApplicationException {
815 List<ConfigServices> newServices = new LinkedList<>();
816 boolean dataExists = false;
818 for (GenericResourceApiServicemodelinfrastructureService serviceItem : modelInfrastructure.getService()) {
819 String svcInstanceId = serviceItem.getServiceInstanceId();
820 List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId);
821 if ((existingService != null) && !existingService.isEmpty()) {
824 ConfigServices service = new ConfigServices();
825 service.setSvcInstanceId(svcInstanceId);
827 service.setSvcData(objectMapper.writeValueAsString(serviceItem.getServiceData()));
828 } catch (JsonProcessingException e) {
829 log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e);
830 throw new RestApplicationException("data-conversion",
831 "Request could not be completed due to internal error", e,
832 HttpStatus.INTERNAL_SERVER_ERROR.value());
835 service.setServiceStatus(serviceItem.getServiceStatus());
836 newServices.add(service);
839 for (ConfigServices service : newServices) {
840 configServicesRepository.save(service);
844 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
846 return new ResponseEntity<>(HttpStatus.CREATED);
852 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServicePost(
853 @Valid GenericResourceApiServicemodelinfrastructureService servicesData) throws RestApplicationException {
854 String svcInstanceId = servicesData.getServiceInstanceId();
856 String svcData = objectMapper.writeValueAsString(servicesData.getServiceData());
857 ConfigServices configService = new ConfigServices(svcInstanceId, svcData, servicesData.getServiceStatus());
858 configServicesRepository.deleteBySvcInstanceId(svcInstanceId);
859 configServicesRepository.save(configService);
860 } catch (JsonProcessingException e) {
861 log.error("Cannot convert service data", e);
862 throw new RestApplicationException("data-conversion",
863 "Request could not be completed due to internal error", e,
864 HttpStatus.INTERNAL_SERVER_ERROR.value());
867 return new ResponseEntity<>(HttpStatus.OK);
871 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdDelete(
872 String serviceInstanceId) {
873 configServicesRepository.deleteBySvcInstanceId(serviceInstanceId);
874 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
878 public ResponseEntity<GenericResourceApiServicemodelinfrastructureService> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdGet(
879 String serviceInstanceId) throws RestApplicationException {
880 GenericResourceApiServicemodelinfrastructureService retval = null;
882 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
884 if (services.isEmpty()) {
885 return new ResponseEntity<>(HttpStatus.NOT_FOUND);
887 ConfigServices service = services.get(0);
888 retval = new GenericResourceApiServicemodelinfrastructureService();
889 retval.setServiceInstanceId(serviceInstanceId);
890 retval.setServiceStatus(service.getServiceStatus());
892 retval.setServiceData(
893 objectMapper.readValue(service.getSvcData(), GenericResourceApiServicedataServiceData.class));
894 } catch (JsonProcessingException e) {
895 log.error("Could not deserialize service data for service instance id {}", serviceInstanceId, e);
896 throw new RestApplicationException("data-conversion",
897 "Request could not be completed due to internal error", e,
898 HttpStatus.INTERNAL_SERVER_ERROR.value());
903 return new ResponseEntity<>(retval, HttpStatus.OK);
908 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdPost(String svcInstanceId,
909 @Valid GenericResourceApiServicemodelinfrastructureService newService)
910 throws RestApplicationException, RestProtocolException {
912 List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId);
913 if ((existingService != null) && !existingService.isEmpty()) {
914 log.error("Service data already exists for {}", svcInstanceId);
915 throw new RestProtocolException("data-exists",
916 "Data already exists for service-instance-id " + svcInstanceId, HttpStatus.CONFLICT.value());
918 ConfigServices service = new ConfigServices();
919 service.setSvcInstanceId(svcInstanceId);
921 service.setSvcData(objectMapper.writeValueAsString(newService.getServiceData()));
922 } catch (JsonProcessingException e) {
923 log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e);
924 throw new RestApplicationException("data-conversion",
925 "Request could not be completed due to internal error", e,
926 HttpStatus.INTERNAL_SERVER_ERROR.value());
929 service.setServiceStatus(newService.getServiceStatus());
930 configServicesRepository.save(service);
932 return new ResponseEntity<>(HttpStatus.CREATED);
936 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdPut(String serviceInstanceId,
937 @Valid GenericResourceApiServicemodelinfrastructureService newService) throws RestApplicationException {
939 boolean dataExists = false;
941 String svcInstanceId = newService.getServiceInstanceId();
943 ConfigServices service = null;
944 List<ConfigServices> existingService = configServicesRepository.findBySvcInstanceId(svcInstanceId);
945 if ((existingService != null) && !existingService.isEmpty()) {
947 service = existingService.get(0);
949 service = new ConfigServices();
950 service.setSvcInstanceId(svcInstanceId);
954 service.setSvcData(objectMapper.writeValueAsString(newService.getServiceData()));
955 } catch (JsonProcessingException e) {
956 log.error("Could not serialize service data for {}", service.getSvcInstanceId(), e);
957 throw new RestApplicationException("data-conversion",
958 "Request could not be completed due to internal error", e,
959 HttpStatus.INTERNAL_SERVER_ERROR.value());
962 service.setServiceStatus(newService.getServiceStatus());
963 configServicesRepository.save(service);
966 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
968 return new ResponseEntity<>(HttpStatus.CREATED);
973 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataDelete(
974 String serviceInstanceId) throws RestProtocolException {
975 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
977 if ((services == null) || (services.isEmpty())) {
978 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
981 ConfigServices service = services.get(0);
982 if (service.getSvcData() == null) {
983 throw new RestProtocolException("data-missing", "No service-data found", HttpStatus.NOT_FOUND.value());
985 service.setSvcData(null);
986 configServicesRepository.save(service);
988 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
992 public ResponseEntity<GenericResourceApiServicedataServiceData> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataGet(
993 String serviceInstanceId) throws RestApplicationException, RestProtocolException {
994 GenericResourceApiServicedataServiceData serviceData = null;
996 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
997 if ((services == null) || (services.isEmpty())) {
998 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1002 serviceData = objectMapper.readValue(services.get(0).getSvcData(),
1003 GenericResourceApiServicedataServiceData.class);
1004 return new ResponseEntity<>(serviceData, HttpStatus.OK);
1005 } catch (JsonProcessingException e) {
1006 log.error("Could not parse service data", e);
1007 throw new RestApplicationException("data-conversion",
1008 "Request could not be completed due to internal error", e,
1009 HttpStatus.INTERNAL_SERVER_ERROR.value());
1015 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataPost(
1016 String serviceInstanceId, @Valid GenericResourceApiServicedataServiceData serviceData)
1017 throws RestApplicationException, RestProtocolException {
1018 ConfigServices service;
1019 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1020 if ((services == null) || (services.isEmpty())) {
1021 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1024 if ((serviceData == null) || (serviceData.getServiceInformation() == null)) {
1025 throw new RestProtocolException("bad-attribute", "Invalid service-data received",
1026 HttpStatus.BAD_REQUEST.value());
1029 service = services.get(0);
1031 if ((service.getSvcData() != null) && (service.getSvcData().length() > 0)) {
1032 log.error("service-data already exists for svcInstanceId {}", serviceInstanceId);
1033 throw new RestProtocolException("data-exists", "Data already exists for " + serviceInstanceId,
1034 HttpStatus.CONFLICT.value());
1038 service.setSvcData(objectMapper.writeValueAsString(serviceData));
1039 configServicesRepository.save(service);
1040 } catch (JsonProcessingException e) {
1041 log.error("Could not serialize service data for svc instance id {}", serviceInstanceId, e);
1042 throw new RestApplicationException("data-conversion",
1043 "Request could not be completed due to internal error", e,
1044 HttpStatus.INTERNAL_SERVER_ERROR.value());
1047 return new ResponseEntity<>(HttpStatus.CREATED);
1052 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataPut(
1053 String serviceInstanceId, @Valid GenericResourceApiServicedataServiceData serviceData)
1054 throws RestApplicationException, RestProtocolException {
1055 ConfigServices service;
1056 boolean dataExists = false;
1058 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1059 if ((services == null) || (services.isEmpty())) {
1060 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1063 if ((serviceData == null) || (serviceData.getServiceInformation() == null)) {
1064 throw new RestProtocolException("bad-attribute", "Invalid service-data received",
1065 HttpStatus.BAD_REQUEST.value());
1068 service = services.get(0);
1070 if ((service.getSvcData() != null) && (service.getSvcData().length() > 0)) {
1075 service.setSvcData(objectMapper.writeValueAsString(serviceData));
1076 configServicesRepository.save(service);
1077 } catch (JsonProcessingException e) {
1078 log.error("Could not serialize service data for svc instance id {}", serviceInstanceId, e);
1079 throw new RestApplicationException("data-conversion",
1080 "Request could not be completed due to internal error", e,
1081 HttpStatus.INTERNAL_SERVER_ERROR.value());
1085 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
1087 return new ResponseEntity<>(HttpStatus.CREATED);
1092 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceStatusDelete(
1093 String serviceInstanceId) throws RestProtocolException {
1094 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1096 if ((services == null) || (services.isEmpty())) {
1097 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1100 ConfigServices service = services.get(0);
1101 if (service.getServiceStatus() == null) {
1102 throw new RestProtocolException("data-missing", "No service-status found", HttpStatus.NOT_FOUND.value());
1104 service.setServiceStatus(null);
1105 configServicesRepository.save(service);
1107 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
1112 public ResponseEntity<GenericResourceApiServicestatusServiceStatus> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceStatusGet(
1113 String serviceInstanceId) throws RestApplicationException, RestProtocolException {
1114 GenericResourceApiServicestatusServiceStatus serviceStatus = null;
1116 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1117 if ((services == null) || (services.isEmpty())) {
1118 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1121 serviceStatus = services.get(0).getServiceStatus();
1122 return new ResponseEntity<>(serviceStatus, HttpStatus.OK);
1126 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceStatusPost(
1127 String serviceInstanceId, @Valid GenericResourceApiServicestatusServiceStatus serviceStatus)
1128 throws RestProtocolException {
1129 ConfigServices service;
1130 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1131 if ((services == null) || (services.isEmpty())) {
1132 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1135 if ((serviceStatus == null) || (serviceStatus.getAction() == null)) {
1136 throw new RestProtocolException("bad-attribute", "Invalid service-status received",
1137 HttpStatus.BAD_REQUEST.value());
1140 service = services.get(0);
1142 if (service.getServiceStatus() != null) {
1143 log.error("service-status already exists for svcInstanceId {}", serviceInstanceId);
1144 throw new RestProtocolException("data-exists", "Data already exists for " + serviceInstanceId,
1145 HttpStatus.CONFLICT.value());
1148 service.setServiceStatus(serviceStatus);
1149 configServicesRepository.save(service);
1151 return new ResponseEntity<>(HttpStatus.CREATED);
1156 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceStatusPut(
1157 String serviceInstanceId, @Valid GenericResourceApiServicestatusServiceStatus serviceStatus)
1158 throws RestProtocolException {
1159 ConfigServices service;
1160 boolean dataExists = false;
1162 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1163 if ((services == null) || (services.isEmpty())) {
1164 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1167 if ((serviceStatus == null) || (serviceStatus.getAction() == null)) {
1168 throw new RestProtocolException("bad-attribute", "Invalid service-status received",
1169 HttpStatus.BAD_REQUEST.value());
1172 service = services.get(0);
1174 if (service.getServiceStatus() != null) {
1178 service.setServiceStatus(serviceStatus);
1179 configServicesRepository.save(service);
1182 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
1184 return new ResponseEntity<>(HttpStatus.CREATED);
1189 * Deletes VNF data from the Config table specified Service Instance.
1192 * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/
1194 * @param serviceInstanceId the Service Instance ID to perform the delete on
1195 * @param vnfId the VNF ID of the VNF to delete
1196 * @return HttpStatus.NO_CONTENT (204) on successful delete
1198 * HttpStatus.BAD_REQUEST (400) if unmarshalling Service Data from the
1199 * database fails, there is no VNF data for {@code vnfId}, or writing
1200 * Service Data back to the database fails.
1202 * HttpStatus.NOT_FOUND (404) if {@code serviceInstanceId} does not
1206 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdDelete(
1207 String serviceInstanceId, String vnfId) throws RestException {
1208 log.info("DELETE | VNF Data for ({})", vnfId);
1211 * The logic may need to be moved inside of this check or this check may need to
1214 if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
1215 log.info("Something with header.");
1218 "ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated");
1221 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1222 ConfigServices data;
1223 if ((services == null) || (services.isEmpty())) {
1224 log.info("Could not find data for ({}).", serviceInstanceId);
1225 // Or throw the data not found error?
1226 throw new RestProtocolException("data-missing", "Service Instance ID not found.",
1227 HttpStatus.NOT_FOUND.value());
1229 data = services.get(0);
1232 GenericResourceApiServicedataServiceData svcData;
1234 svcData = objectMapper.readValue(data.getSvcData(), GenericResourceApiServicedataServiceData.class);
1235 } catch (JsonProcessingException e) {
1236 // Or throw the data not found error?
1237 log.error("Could not map service data for ({})", serviceInstanceId);
1238 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1240 if (svcData == null) {
1241 // Or throw the data not found error?
1242 log.info("Could not find Service Data for ({}).", serviceInstanceId);
1243 throw new RestProtocolException("data-missing", "Service data not found.", HttpStatus.NOT_FOUND.value());
1246 GenericResourceApiServicedataServicedataVnfs vnfs = svcData.getVnfs();
1248 // Or throw the data not found error?
1249 log.info("VNF List not found for ({}).", serviceInstanceId);
1250 throw new RestProtocolException("data-missing", "VNFs not found.", HttpStatus.NOT_FOUND.value());
1253 Stream<GenericResourceApiServicedataServicedataVnfsVnf> vnfStream = svcData.getVnfs().getVnf().stream();
1254 if (vnfStream.noneMatch(targetVnf -> targetVnf.getVnfId().equals(vnfId))) {
1255 // Data was not found
1256 log.error("Did not find VNF ({}) in data.", vnfId);
1257 throw new RestProtocolException("data-missing", "VNF ID not found.", HttpStatus.NOT_FOUND.value());
1259 // Recreate the stream per Sonar?
1260 vnfStream = svcData.getVnfs().getVnf().stream();
1261 svcData.getVnfs().setVnf(
1262 vnfStream.filter(targetVnf -> !targetVnf.getVnfId().equals(vnfId)).collect(Collectors.toList()));
1264 // Map and save the new data
1266 data.setSvcData(objectMapper.writeValueAsString(svcData));
1267 configServicesRepository.save(data);
1268 return new ResponseEntity<>(HttpStatus.NO_CONTENT);
1269 } catch (JsonProcessingException e) {
1270 log.error("Error mapping object to JSON", e);
1271 // Should probably be a 500 INTERNAL_SERVICE_ERROR
1272 throw new RestProtocolException("internal-service-error", "Failed to save data.",
1273 HttpStatus.BAD_REQUEST.value());
1278 * Extracts VNF data from the Config table specified Service Instance.
1281 * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/
1283 * @param serviceInstanceId the Service Instance ID to lookup data for
1284 * @param vnfId the VNF ID of the VNF to return
1285 * @return HttpStatus.OK (200) if the data is found.
1286 * @throws RestException if the data does not exist.
1289 public ResponseEntity<GenericResourceApiServicedataServicedataVnfsVnf> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdGet(
1290 String serviceInstanceId, String vnfId) throws RestException {
1291 log.info("GET | VNF Data for ({})", vnfId);
1292 if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
1293 if (getAcceptHeader().get().contains("application/json")) {
1297 "ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated");
1299 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1300 if ((services == null) || (services.isEmpty())) {
1301 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1304 Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnf = getVnfObject(services.get(0), vnfId);
1305 if (vnf.isPresent()) {
1306 return new ResponseEntity<>(vnf.get(), HttpStatus.OK);
1308 log.info("No information found for {}", vnfId);
1309 throw new RestApplicationException("data-missing",
1310 "Request could not be completed because the relevant data model content does not exist",
1311 HttpStatus.NOT_FOUND.value());
1316 * Extracts a vf-module object from the database,
1317 * @param configServices A Config Services option created from a Service
1319 * @param vnfId the target VNF ID
1320 * @param vfModuleId the target vf-module ID
1321 * @return An empty Optional if the Service Data does not exist, an empty
1322 * Optional if the VNF is not found, or an optional containing the
1325 private Optional<GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule> getVfModuleObject (
1326 ConfigServices configServices, String vnfId, String vfModuleId) {
1327 // Map the Marshall the JSON String into a Java Object
1328 log.info("Getting vf-module Data for ({})", vfModuleId);
1330 Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnf = getVnfObject(configServices, vnfId);
1331 GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData = vnf.get().getVnfData();
1333 return vnfData.getVfModules().getVfModule()
1335 .filter(vf -> vf.getVfModuleId().equals(vfModuleId))
1340 * Creates or updates VNF data in the Config table for a specified Service
1341 * Instance. If it is a new Service Instance or a new VNF, creates all necessary
1342 * parent data containers, then performs the updates.
1344 * Maps to /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/
1345 * @param serviceInstanceId the Service Instance ID to perform the delete on
1346 * @param vnfId the VNF ID of the VNF to delete
1347 * @param genericResourceApiServicedataServicedataVnfsVnfBodyParam the playload
1348 * @return HttpStatus.CREATED (201) on successful create
1350 * HttpStatus.NO_CONTENT (204) on successful update
1352 * HttpStatus.BAD_REQUEST (400) if {@code vnfId} does not match what is specified in the
1353 * {@code genericResourceApiServicedataServicedataVnfsVnfBodyParam} , or if updating the database fails.
1354 * @throws RestException
1357 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdPut(
1358 String serviceInstanceId, String vnfId,
1359 GenericResourceApiServicedataServicedataVnfsVnf genericResourceApiServicedataServicedataVnfsVnfBodyParam)
1360 throws RestException {
1361 log.info("PUT | VNF Data for ({})", vnfId);
1362 if (!vnfId.equals(genericResourceApiServicedataServicedataVnfsVnfBodyParam.getVnfId())) {
1363 throw new RestProtocolException("bad-attribute", "vnf-id mismatch", HttpStatus.BAD_REQUEST.value());
1365 if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
1366 log.info("Something with header");
1369 "ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated");
1372 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1373 ConfigServices data;
1374 if ((services == null) || (services.isEmpty())) {
1375 log.info("Could not find data for ({}). Creating new Service Object.", serviceInstanceId);
1376 data = new ConfigServices();
1377 data.setSvcInstanceId(serviceInstanceId);
1379 data = services.get(0);
1382 GenericResourceApiServicedataServiceData svcData = null;
1384 svcData = objectMapper.readValue(data.getSvcData(), GenericResourceApiServicedataServiceData.class);
1385 } catch (JsonProcessingException e) {
1386 log.error("Could not map service data for ({})", serviceInstanceId);
1388 if (svcData == null) {
1389 log.info("Could not find Service Data for ({}). Creating new Service Data Container", serviceInstanceId);
1390 svcData = new GenericResourceApiServicedataServiceData();
1392 if (svcData.getVnfs() == null) {
1393 log.info("VNF List not found for ({}). Creating new VNF List Container.", serviceInstanceId);
1394 svcData.setVnfs(new GenericResourceApiServicedataServicedataVnfs());
1395 svcData.getVnfs().setVnf(new ArrayList<>());
1398 GenericResourceApiServicedataServicedataVnfs vnflist = new GenericResourceApiServicedataServicedataVnfs();
1399 HttpStatus responseStatus = HttpStatus.NO_CONTENT;
1400 if (svcData.getVnfs().getVnf().isEmpty()) {
1401 log.info("Creating VNF data for ({})", vnfId);
1402 vnflist.addVnfItem(genericResourceApiServicedataServicedataVnfsVnfBodyParam);
1403 responseStatus = HttpStatus.CREATED;
1405 log.info("Updating VNF data for ({})", vnfId);
1406 // Filter out all of the other vnf objects into a new VNF List
1407 // Replace if a delete method exists
1408 svcData.getVnfs().getVnf().stream().filter(targetVnf -> !targetVnf.getVnfId().equals(vnfId))
1409 .forEach(vnflist::addVnfItem);
1410 vnflist.addVnfItem(genericResourceApiServicedataServicedataVnfsVnfBodyParam);
1412 svcData.setVnfs(vnflist);
1413 // Map and save the new data
1415 data.setSvcData(objectMapper.writeValueAsString(svcData));
1416 configServicesRepository.save(data);
1417 return new ResponseEntity<>(responseStatus);
1418 } catch (JsonProcessingException e) {
1419 log.error("Error mapping object to JSON", e);
1420 // Should probably be a 500 INTERNAL_SERVICE_ERROR
1421 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1426 * Extracts VNF Topology data from the Config table specified Service Instance
1430 * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-topology/
1432 * @param serviceInstanceId the Service Instance ID to lookup data for
1433 * @param vnfId the VNF ID of the VNF to extract topology data from.
1434 * @return HttpStatus.OK (200) if the data is found.
1435 * @throws RestException if the data does not exist.
1438 public ResponseEntity<GenericResourceApiVnftopologyVnfTopology> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyGet(
1439 String serviceInstanceId, String vnfId) throws RestException {
1440 log.info("GET | VNF Topology for ({})", vnfId);
1441 if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
1442 if (getAcceptHeader().get().contains("application/json")) {
1447 "ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated");
1449 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1450 if ((services == null) || (services.isEmpty())) {
1451 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1454 Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnf = getVnfObject(services.get(0), vnfId);
1455 // Drill down to find the data
1456 if (vnf.isPresent() && vnf.get().getVnfData() != null && vnf.get().getVnfData().getVnfTopology() != null) {
1457 return new ResponseEntity<>(vnf.get().getVnfData().getVnfTopology(), HttpStatus.OK);
1459 log.info("No information found for {}", vnfId);
1460 throw new RestApplicationException("data-missing",
1461 "Request could not be completed because the relevant data model content does not exist",
1462 HttpStatus.NOT_FOUND.value());
1467 * Creates or updates VNF Level Operation Status data in the Config table for a
1468 * specified Service Instance. If it is a new Service Instance or a new VNF,
1469 * creates all necessary parent data containers, then performs the updates.
1472 * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-level-oper-status/
1474 * @param serviceInstanceId the Service Instance ID to
1475 * perform the delete on
1476 * @param vnfId the VNF ID of the VNF to
1478 * @param genericResourceApiOperStatusDataBodyParam the payload
1479 * @return HttpStatus.CREATED (201) on successful create.
1481 * HttpStatus.NO_CONTENT (204) on successful update.
1483 * HttpStatus.BAD_REQUEST (400) if updating the database fails.
1484 * @throws RestException
1487 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfLevelOperStatusPut(
1488 String serviceInstanceId, String vnfId,
1489 GenericResourceApiOperStatusData genericResourceApiOperStatusDataBodyParam) throws RestException {
1490 log.info("PUT | VNF Level Oper Status ({})", vnfId);
1491 if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
1494 "ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated");
1497 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1498 ConfigServices data;
1499 if ((services == null) || (services.isEmpty())) {
1500 log.info("Could not find data for ({}). Creating new Service Object.", serviceInstanceId);
1501 data = new ConfigServices();
1502 data.setSvcInstanceId(serviceInstanceId);
1504 data = services.get(0);
1507 GenericResourceApiServicedataServiceData svcData = null;
1509 svcData = objectMapper.readValue(data.getSvcData(), GenericResourceApiServicedataServiceData.class);
1510 } catch (JsonProcessingException e) {
1511 log.error("Could not map service data for ({})", serviceInstanceId);
1513 if (svcData == null) {
1514 log.info("Could not find Service Data for ({}). Creating new Service Data Container", serviceInstanceId);
1515 svcData = new GenericResourceApiServicedataServiceData();
1517 if (svcData.getVnfs() == null) {
1518 log.info("VNF List not found for ({}). Creating new VNF List Container.", serviceInstanceId);
1519 svcData.setVnfs(new GenericResourceApiServicedataServicedataVnfs());
1520 svcData.getVnfs().setVnf(new ArrayList<>());
1523 GenericResourceApiServicedataServicedataVnfs vnflist = new GenericResourceApiServicedataServicedataVnfs();
1524 HttpStatus responseStatus = HttpStatus.NO_CONTENT;
1525 if (svcData.getVnfs().getVnf().isEmpty()) {
1526 log.info("Creating VNF data for ({})", vnfId);
1527 GenericResourceApiServicedataServicedataVnfsVnf vnf = new GenericResourceApiServicedataServicedataVnfsVnf();
1528 vnf.setVnfId(vnfId);
1529 vnf.setVnfData(new GenericResourceApiServicedataServicedataVnfsVnfVnfData());
1530 vnf.getVnfData().setVnfLevelOperStatus(genericResourceApiOperStatusDataBodyParam);
1531 vnflist.addVnfItem(vnf);
1532 responseStatus = HttpStatus.CREATED;
1534 log.info("Updating VNF data for ({})", vnfId);
1535 // Filter out all of the other vnf objects into a new VNF List
1536 // Replace if a delete method exists
1537 svcData.getVnfs().getVnf().stream().filter(targetVnf -> !targetVnf.getVnfId().equals(vnfId))
1538 .forEach(vnflist::addVnfItem);
1539 GenericResourceApiServicedataServicedataVnfsVnf vnf = new GenericResourceApiServicedataServicedataVnfsVnf();
1540 // If the vnf exists, set it up with new data
1541 Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnfOptional = getVnfObject(data, vnfId);
1542 if (vnfOptional.isPresent()) {
1543 vnf = vnfOptional.get();
1545 if (vnf.getVnfData() == null) {
1546 vnf.setVnfData(new GenericResourceApiServicedataServicedataVnfsVnfVnfData());
1547 responseStatus = HttpStatus.CREATED;
1550 vnf.getVnfData().setVnfLevelOperStatus(genericResourceApiOperStatusDataBodyParam);
1551 vnflist.addVnfItem(vnf);
1554 svcData.setVnfs(vnflist);
1555 // Map and save the new data
1557 data.setSvcData(objectMapper.writeValueAsString(svcData));
1558 configServicesRepository.save(data);
1559 return new ResponseEntity<>(responseStatus);
1560 } catch (JsonProcessingException e) {
1561 log.error("Error mapping object to JSON", e);
1562 // Should probably be a 500 INTERNAL_SERVICE_ERROR
1563 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1568 * Creates or updates VNF Onap Model Information data in the Config table for a
1569 * specified Service Instance. If it is a new Service Instance or a new VNF,
1570 * creates all necessary parent data containers, then performs the updates.
1573 * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-topology/onap-model-information/
1575 * @param serviceInstanceId the
1592 * @param genericResourceApiOnapmodelinformationOnapModelInformationBodyParam the
1594 * @return HttpStatus.CREATED (201) on successful create.
1596 * HttpStatus.NO_CONTENT (204) on successful update.
1598 * HttpStatus.BAD_REQUEST (400) if updating the database fails.
1599 * @throws RestException
1602 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyOnapModelInformationPut(
1603 String serviceInstanceId, String vnfId,
1604 GenericResourceApiOnapmodelinformationOnapModelInformation genericResourceApiOnapmodelinformationOnapModelInformationBodyParam)
1605 throws RestException {
1606 log.info("PUT | VNF Topology Onap Model Information ({})", vnfId);
1607 if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
1610 "ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated");
1613 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1614 ConfigServices data;
1615 if ((services == null) || (services.isEmpty())) {
1616 log.info("Could not find data for ({}). Creating new Service Object.", serviceInstanceId);
1617 data = new ConfigServices();
1618 data.setSvcInstanceId(serviceInstanceId);
1620 data = services.get(0);
1623 GenericResourceApiServicedataServiceData svcData = null;
1625 svcData = objectMapper.readValue(data.getSvcData(), GenericResourceApiServicedataServiceData.class);
1626 } catch (JsonProcessingException e) {
1627 log.error("Could not map service data for ({})", serviceInstanceId);
1629 if (svcData == null) {
1630 log.info("Could not find Service Data for ({}). Creating new Service Data Container", serviceInstanceId);
1631 svcData = new GenericResourceApiServicedataServiceData();
1633 if (svcData.getVnfs() == null) {
1634 log.info("VNF List not found for ({}). Creating new VNF List Container.", serviceInstanceId);
1635 svcData.setVnfs(new GenericResourceApiServicedataServicedataVnfs());
1636 svcData.getVnfs().setVnf(new ArrayList<>());
1639 GenericResourceApiServicedataServicedataVnfs vnflist = new GenericResourceApiServicedataServicedataVnfs();
1640 HttpStatus responseStatus = HttpStatus.NO_CONTENT;
1641 if (svcData.getVnfs().getVnf().isEmpty()) {
1642 log.info("Creating VNF data for ({})", vnfId);
1643 GenericResourceApiServicedataServicedataVnfsVnf vnf = new GenericResourceApiServicedataServicedataVnfsVnf();
1644 vnf.setVnfId(vnfId);
1645 vnf.setVnfData(new GenericResourceApiServicedataServicedataVnfsVnfVnfData());
1646 vnf.getVnfData().setVnfTopology(new GenericResourceApiVnftopologyVnfTopology());
1647 vnf.getVnfData().getVnfTopology()
1648 .setOnapModelInformation(genericResourceApiOnapmodelinformationOnapModelInformationBodyParam);
1649 vnflist.addVnfItem(vnf);
1650 responseStatus = HttpStatus.CREATED;
1652 log.info("Updating VNF data for ({})", vnfId);
1653 // Filter out all of the other vnf objects into a new VNF List
1654 // Replace if a delete method exists
1655 svcData.getVnfs().getVnf().stream().filter(targetVnf -> !targetVnf.getVnfId().equals(vnfId))
1656 .forEach(vnflist::addVnfItem);
1657 GenericResourceApiServicedataServicedataVnfsVnf vnf = new GenericResourceApiServicedataServicedataVnfsVnf();
1658 // If the vnf exists, set it up with new data
1659 Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnfOptional = getVnfObject(data, vnfId);
1660 if (vnfOptional.isPresent()) {
1661 vnf = vnfOptional.get();
1663 if (vnf.getVnfData() == null) {
1664 vnf.setVnfData(new GenericResourceApiServicedataServicedataVnfsVnfVnfData());
1666 if (vnf.getVnfData().getVnfTopology() == null) {
1667 vnf.getVnfData().setVnfTopology(new GenericResourceApiVnftopologyVnfTopology());
1668 responseStatus = HttpStatus.CREATED;
1671 vnf.getVnfData().getVnfTopology()
1672 .setOnapModelInformation(genericResourceApiOnapmodelinformationOnapModelInformationBodyParam);
1673 vnflist.addVnfItem(vnf);
1676 svcData.setVnfs(vnflist);
1677 // Map and save the new data
1679 data.setSvcData(objectMapper.writeValueAsString(svcData));
1680 configServicesRepository.save(data);
1681 return new ResponseEntity<>(responseStatus);
1682 } catch (JsonProcessingException e) {
1683 log.error("Error mapping object to JSON", e);
1684 // Should probably be a 500 INTERNAL_SERVICE_ERROR
1685 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1690 * Creates or updates VNF Network data in the Config table for a specified
1691 * Service Instance. If it is a new Service Instance or a new VNF, creates all
1692 * necessary parent data containers, then performs the updates.
1694 * Maps to /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-topology/vnf-resource-assignments/vnf-networks/
1695 * @param serviceInstanceId the Service Instance ID to perform the delete on
1696 * @param vnfId the VNF ID of the VNF to delete
1697 * @param genericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworksBodyParam the * payload
1698 * @return HttpStatus.CREATED (201) on successful create.
1700 * HttpStatus.NO_CONTENT (204) on successful update.
1702 * HttpStatus.BAD_REQUEST (400) if updating the database fails.
1703 * @throws RestException
1706 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyVnfResourceAssignmentsVnfNetworksPut(
1707 String serviceInstanceId, String vnfId,
1708 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks genericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworksBodyParam)
1709 throws RestException {
1710 log.info("PUT | VNF Topology VNF Resource Assignments VNF Networks ({})", vnfId);
1711 if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
1714 "ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated");
1717 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1718 ConfigServices data;
1719 if ((services == null) || (services.isEmpty())) {
1720 log.info("Could not find data for ({}). Creating new Service Object.", serviceInstanceId);
1721 data = new ConfigServices();
1722 data.setSvcInstanceId(serviceInstanceId);
1724 data = services.get(0);
1727 GenericResourceApiServicedataServiceData svcData = null;
1729 svcData = objectMapper.readValue(data.getSvcData(), GenericResourceApiServicedataServiceData.class);
1730 } catch (JsonProcessingException e) {
1731 log.error("Could not map service data for ({})", serviceInstanceId);
1733 if (svcData == null) {
1734 log.info("Could not find Service Data for ({}). Creating new Service Data Container", serviceInstanceId);
1735 svcData = new GenericResourceApiServicedataServiceData();
1737 if (svcData.getVnfs() == null) {
1738 log.info("VNF List not found for ({}). Creating new VNF List Container.", serviceInstanceId);
1739 svcData.setVnfs(new GenericResourceApiServicedataServicedataVnfs());
1740 svcData.getVnfs().setVnf(new ArrayList<>());
1743 GenericResourceApiServicedataServicedataVnfs vnflist = new GenericResourceApiServicedataServicedataVnfs();
1744 HttpStatus responseStatus = HttpStatus.NO_CONTENT;
1745 if (svcData.getVnfs().getVnf().isEmpty()) {
1746 log.info("Creating VNF data for ({})", vnfId);
1747 GenericResourceApiServicedataServicedataVnfsVnf vnf = new GenericResourceApiServicedataServicedataVnfsVnf();
1748 vnf.setVnfId(vnfId);
1749 vnf.setVnfData(new GenericResourceApiServicedataServicedataVnfsVnfVnfData());
1750 vnf.getVnfData().setVnfTopology(new GenericResourceApiVnftopologyVnfTopology());
1751 vnf.getVnfData().getVnfTopology()
1752 .setVnfResourceAssignments(new GenericResourceApiVnfresourceassignmentsVnfResourceAssignments());
1753 vnf.getVnfData().getVnfTopology().getVnfResourceAssignments()
1754 .setVnfNetworks(genericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworksBodyParam);
1755 vnflist.addVnfItem(vnf);
1756 responseStatus = HttpStatus.CREATED;
1758 log.info("Updating VNF data for ({})", vnfId);
1759 // Filter out all of the other vnf objects into a new VNF List
1760 // Replace if a delete method exists
1761 svcData.getVnfs().getVnf().stream().filter(targetVnf -> !targetVnf.getVnfId().equals(vnfId))
1762 .forEach(vnflist::addVnfItem);
1763 GenericResourceApiServicedataServicedataVnfsVnf vnf = new GenericResourceApiServicedataServicedataVnfsVnf();
1764 // If the vnf exists, set it up with new data
1765 Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnfOptional = getVnfObject(data, vnfId);
1766 if (vnfOptional.isPresent()) {
1767 vnf = vnfOptional.get();
1769 if (vnf.getVnfData() == null) {
1770 vnf.setVnfData(new GenericResourceApiServicedataServicedataVnfsVnfVnfData());
1772 if (vnf.getVnfData().getVnfTopology() == null) {
1773 vnf.getVnfData().setVnfTopology(new GenericResourceApiVnftopologyVnfTopology());
1775 if (vnf.getVnfData().getVnfTopology().getVnfResourceAssignments() == null) {
1776 vnf.getVnfData().getVnfTopology().setVnfResourceAssignments(
1777 new GenericResourceApiVnfresourceassignmentsVnfResourceAssignments());
1778 responseStatus = HttpStatus.CREATED;
1781 vnf.getVnfData().getVnfTopology().getVnfResourceAssignments()
1782 .setVnfNetworks(genericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworksBodyParam);
1783 vnflist.addVnfItem(vnf);
1786 svcData.setVnfs(vnflist);
1787 // Map and save the new data
1789 data.setSvcData(objectMapper.writeValueAsString(svcData));
1790 configServicesRepository.save(data);
1791 return new ResponseEntity<>(responseStatus);
1792 } catch (JsonProcessingException e) {
1793 log.error("Error mapping object to JSON", e);
1794 // Should probably be a 500 INTERNAL_SERVICE_ERROR
1795 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1800 * Creates or updates VNF Network Role data in the Config table for a specified
1801 * Service Instance. If it is a new Service Instance or a new VNF, creates all
1802 * necessary parent data containers, then performs the updates.
1805 * /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vnf-topology/vnf-resource-assignments/vnf-networks/vnf-network/{network-role}/
1807 * @param serviceInstanceId the Service Instance ID to
1808 * perform the delete on
1809 * @param vnfId the VNF ID of the VNF to
1811 * @param genericResourceApiVnfNetworkDataBodyParam the payload
1812 * @return HttpStatus.CREATED (201) on successful create.
1814 * HttpStatus.NO_CONTENT (204) on successful update.
1816 * HttpStatus.BAD_REQUEST (400) if updating the database fails.
1817 * @throws RestException
1820 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVnfTopologyVnfResourceAssignmentsVnfNetworksVnfNetworkNetworkRolePut(
1821 String serviceInstanceId, String vnfId, String networkRole,
1822 GenericResourceApiVnfNetworkData genericResourceApiVnfNetworkDataBodyParam) throws RestException {
1823 log.info("PUT | VNF Network Network Role ({})", vnfId);
1824 if (!networkRole.equals(genericResourceApiVnfNetworkDataBodyParam.getNetworkRole())) {
1825 throw new RestProtocolException("bad-attribute", "network-role mismatch", HttpStatus.BAD_REQUEST.value());
1827 if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
1830 "ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated");
1833 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1834 ConfigServices data;
1835 if ((services == null) || (services.isEmpty())) {
1836 log.info("Could not find data for ({}). Creating new Service Object.", serviceInstanceId);
1837 data = new ConfigServices();
1838 data.setSvcInstanceId(serviceInstanceId);
1840 data = services.get(0);
1843 GenericResourceApiServicedataServiceData svcData = null;
1845 svcData = objectMapper.readValue(data.getSvcData(), GenericResourceApiServicedataServiceData.class);
1846 } catch (JsonProcessingException e) {
1847 log.error("Could not map service data for ({})", serviceInstanceId);
1849 if (svcData == null) {
1850 log.info("Could not find Service Data for ({}). Creating new Service Data Container", serviceInstanceId);
1851 svcData = new GenericResourceApiServicedataServiceData();
1853 if (svcData.getVnfs() == null) {
1854 log.info("VNF List not found for ({}). Creating new VNF List Container.", serviceInstanceId);
1855 svcData.setVnfs(new GenericResourceApiServicedataServicedataVnfs());
1856 svcData.getVnfs().setVnf(new ArrayList<>());
1859 GenericResourceApiServicedataServicedataVnfs vnflist = new GenericResourceApiServicedataServicedataVnfs();
1860 HttpStatus responseStatus = HttpStatus.NO_CONTENT;
1861 if (svcData.getVnfs().getVnf().isEmpty()) {
1862 log.info("Creating VNF data for ({})", vnfId);
1863 GenericResourceApiServicedataServicedataVnfsVnf vnf = new GenericResourceApiServicedataServicedataVnfsVnf();
1864 vnf.setVnfId(vnfId);
1865 vnf.setVnfData(new GenericResourceApiServicedataServicedataVnfsVnfVnfData());
1866 vnf.getVnfData().setVnfTopology(new GenericResourceApiVnftopologyVnfTopology());
1867 vnf.getVnfData().getVnfTopology()
1868 .setVnfResourceAssignments(new GenericResourceApiVnfresourceassignmentsVnfResourceAssignments());
1869 vnf.getVnfData().getVnfTopology().getVnfResourceAssignments()
1870 .setVnfNetworks(new GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks());
1871 vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().getVnfNetworks()
1872 .setVnfNetwork(new ArrayList<>());
1873 vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().getVnfNetworks()
1874 .addVnfNetworkItem(genericResourceApiVnfNetworkDataBodyParam);
1875 vnflist.addVnfItem(vnf);
1876 responseStatus = HttpStatus.CREATED;
1878 log.info("Updating VNF data for ({})", vnfId);
1879 // Filter out all of the other vnf objects into a new VNF List
1880 // Replace if a delete method exists
1881 svcData.getVnfs().getVnf().stream().filter(targetVnf -> !targetVnf.getVnfId().equals(vnfId))
1882 .forEach(vnflist::addVnfItem);
1883 GenericResourceApiServicedataServicedataVnfsVnf vnf = new GenericResourceApiServicedataServicedataVnfsVnf();
1884 // If the vnf exists, set it up with new data
1885 Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnfOptional = getVnfObject(data, vnfId);
1886 if (vnfOptional.isPresent()) {
1887 vnf = vnfOptional.get();
1889 if (vnf.getVnfData() == null) {
1890 vnf.setVnfData(new GenericResourceApiServicedataServicedataVnfsVnfVnfData());
1892 if (vnf.getVnfData().getVnfTopology() == null) {
1893 vnf.getVnfData().setVnfTopology(new GenericResourceApiVnftopologyVnfTopology());
1895 if (vnf.getVnfData().getVnfTopology().getVnfResourceAssignments() == null) {
1896 vnf.getVnfData().getVnfTopology().setVnfResourceAssignments(
1897 new GenericResourceApiVnfresourceassignmentsVnfResourceAssignments());
1899 if (vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().getVnfNetworks() == null) {
1900 log.info("Creating new VnfNetworks");
1901 vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().setVnfNetworks(
1902 new GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks());
1905 GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks networkList = new GenericResourceApiVnfresourceassignmentsVnfresourceassignmentsVnfNetworks();
1906 if (vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().getVnfNetworks().getVnfNetwork()
1908 log.info("First entry into network info.");
1909 vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().getVnfNetworks()
1910 .addVnfNetworkItem(genericResourceApiVnfNetworkDataBodyParam);
1911 responseStatus = HttpStatus.CREATED;
1913 log.info("Found networks. Filtering.");
1914 vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().getVnfNetworks().getVnfNetwork().stream()
1915 .filter(targetNetwork -> !targetNetwork.getNetworkRole().equals(networkRole))
1916 .forEach(networkList::addVnfNetworkItem);
1917 networkList.addVnfNetworkItem(genericResourceApiVnfNetworkDataBodyParam);
1919 if (networkList.getVnfNetwork().size() != vnf.getVnfData().getVnfTopology().getVnfResourceAssignments()
1920 .getVnfNetworks().getVnfNetwork().size()) {
1921 log.info("Added a new Item");
1922 responseStatus = HttpStatus.CREATED;
1924 vnf.getVnfData().getVnfTopology().getVnfResourceAssignments().setVnfNetworks(networkList);
1927 vnflist.addVnfItem(vnf);
1930 svcData.setVnfs(vnflist);
1931 // Map and save the new data
1933 data.setSvcData(objectMapper.writeValueAsString(svcData));
1934 configServicesRepository.save(data);
1935 return new ResponseEntity<>(responseStatus);
1936 } catch (JsonProcessingException e) {
1937 log.error("Error mapping object to JSON", e);
1938 // Should probably be a 500 INTERNAL_SERVICE_ERROR
1939 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
1944 * Extracts a VNF object from the database,
1946 * @param configServices A Config Services option created from a Service
1948 * @param vnfId the target VNF ID
1949 * @return An empty Optional if the Service Data does not exist, an empty
1950 * Optional if the VNF is not found, or an optional containing the found
1953 private Optional<GenericResourceApiServicedataServicedataVnfsVnf> getVnfObject(ConfigServices configServices,
1955 // Map the Marshall the JSON String into a Java Object
1956 log.info("Getting VNF Data for ({})", vnfId);
1957 GenericResourceApiServicedataServiceData svcData;
1959 svcData = objectMapper.readValue(configServices.getSvcData(),
1960 GenericResourceApiServicedataServiceData.class);
1961 } catch (JsonProcessingException e) {
1962 log.error("Error", e);
1963 return Optional.empty();
1967 * Get a stream of the VNF Objects and return the target if it's found, assuming
1968 * that each VNF ID is unique within a Service Instance Object
1970 return svcData.getVnfs().getVnf().stream().filter(targetVnf -> targetVnf.getVnfId().equals(vnfId)).findFirst();
1974 public ResponseEntity<GenericResourceApiServicetopologyServiceTopology> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataServiceTopologyGet(
1975 String serviceInstanceId) throws RestApplicationException, RestProtocolException {
1976 GenericResourceApiServicetopologyServiceTopology serviceTopology = null;
1977 GenericResourceApiServicedataServiceData serviceData = null;
1979 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
1980 if ((services == null) || (services.isEmpty())) {
1981 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
1985 if (services.get(0).getSvcData().isEmpty()) {
1986 throw new RestProtocolException("data-missing", "No service-data entry found",
1987 HttpStatus.NOT_FOUND.value());
1989 serviceData = objectMapper.readValue(services.get(0).getSvcData(),
1990 GenericResourceApiServicedataServiceData.class);
1991 serviceTopology = serviceData.getServiceTopology();
1993 if (serviceTopology == null) {
1994 throw new RestProtocolException("data-missing", "No service-topology entry found",
1995 HttpStatus.NOT_FOUND.value());
1997 return new ResponseEntity<>(serviceTopology, HttpStatus.OK);
1998 } catch (JsonProcessingException e) {
1999 log.error("Could not parse service data", e);
2000 throw new RestApplicationException("data-conversion",
2001 "Request could not be completed due to internal error", e,
2002 HttpStatus.INTERNAL_SERVER_ERROR.value());
2008 * Extracts VF MODULE data from CONFIG_GRA_SERVICES for a given, service-instance-id, vnf-id, and vf-module-id
2010 * Maps to /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vf-modules/vf-module/{vf-module-id}/
2011 * @param serviceInstanceId the Service Instance ID to lookup data for
2012 * @param vnfId the VNF ID of the VNF to return
2013 * @param vfModuleId the vf-moudle ID of a specific VNF to return
2014 * @return HttpStatus.OK (200) if the data is found.
2015 * @throws RestException if the data does not exist.
2018 public ResponseEntity<GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule>
2019 configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdGet(
2020 String serviceInstanceId, String vnfId, String vfModuleId) throws RestException {
2022 log.info("GET | Vf Module Data for ({})", vfModuleId);
2024 if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
2025 if(getAcceptHeader().get().contains("application/json")) {
2028 log.warn("ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated");
2030 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
2031 if((services == null) || (services.isEmpty())) {
2032 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
2035 Optional<GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule> vfModule =
2036 getVfModuleObject(services.get(0), vnfId, vfModuleId);
2037 if(vfModule.isPresent()) {
2038 return new ResponseEntity<>(vfModule.get(), HttpStatus.OK);
2040 log.info("No vf-module found for [{}]", vfModuleId);
2041 throw new RestApplicationException("data-missing", "Request could not be completed because the relevant data model content does not exist", HttpStatus.NOT_FOUND.value());
2046 * PUT VF MODULE data into CONFIG_GRA_SERVICES of a given, service-instance-id, vnf-id
2048 * Maps to /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vf-modules/vf-module/{vf-module-id}/
2049 * @param serviceInstanceId the Service Instance ID
2050 * @param vnfId the VNF ID as the parent of the specified vf-module-id and child of the specified service-instance
2051 * @param vfModuleId the vf-moudle ID as a child of the specified VNF
2052 * @return HttpStatus.OK (200) if the data is found.
2053 * @throws RestException if the data does not exist.
2056 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdPut(
2057 String serviceInstanceId, String vnfId, String vfModuleId,
2058 GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule genericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModuleBodyParam)
2059 throws RestException {
2060 log.info("PUT | vf-module Data of ({}) for vnf ({}) in service({})", vfModuleId, vnfId, serviceInstanceId);
2062 if(! vfModuleId.equals(genericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModuleBodyParam.getVfModuleId())) {
2063 throw new RestProtocolException("bad-attribute", "vf-module-id mismatch", HttpStatus.BAD_REQUEST.value());
2065 if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
2066 log.info("Something with header");
2068 log.warn("ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated");
2071 HttpStatus responseStatus = HttpStatus.NO_CONTENT;
2072 ConfigServices service;
2073 GenericResourceApiServicedataServiceData svcData;
2074 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
2076 if((services == null) || (services.isEmpty())) {
2077 log.error("service-instance-id ({}) not found in SDN.", serviceInstanceId);
2078 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
2080 service = services.get(0);
2084 svcData = objectMapper.readValue(service.getSvcData(), GenericResourceApiServicedataServiceData.class);
2085 } catch(JsonProcessingException e) {
2086 log.error("Error", e);
2087 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
2090 GenericResourceApiServicedataServicedataVnfs vnfs = svcData.getVnfs();
2091 Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnf =
2094 .filter(targetVnf -> targetVnf.getVnfId().equals(vnfId))
2097 if(! vnf.isPresent()) {
2098 log.error("vnf-id ({}) not found in SDN.", vnfId);
2099 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
2102 GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData = vnf.get().getVnfData();
2103 GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfModules existingVfModules = vnfData.getVfModules();
2104 GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfModules newVfModules = new GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfModules();
2106 if (existingVfModules == null || existingVfModules.getVfModule().isEmpty()) {
2107 log.info("No existing vf-module found. Creating the first vf-module for vnf [{}]", vnfId);
2108 newVfModules.addVfModuleItem(genericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModuleBodyParam);
2109 responseStatus = HttpStatus.CREATED;
2112 ArrayList<String> vfModuleIds = new ArrayList<>();
2113 for (GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule vf : existingVfModules.getVfModule()) {
2114 vfModuleIds.add(vf.getVfModuleId());
2116 log.info("[{}] vf-module(s) {} found in vnf [{}]", existingVfModules.getVfModule().size(), vfModuleIds, vnfId);
2117 if (!vfModuleIds.isEmpty() && vfModuleIds.contains(vfModuleId)) {
2118 log.info("Overwriting vf-module [{}] in vnf [{}]", vfModuleId, vnfId);
2120 log.info("Adding vf-module [{}] to vnf [{}]", vfModuleId, vnfId);
2122 existingVfModules.getVfModule()
2124 .filter(vf -> ! vf.getVfModuleId().equals(vfModuleId))
2125 .forEach(newVfModules::addVfModuleItem);
2126 newVfModules.addVfModuleItem(genericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModuleBodyParam);
2127 responseStatus = HttpStatus.OK;
2129 vnfData.setVfModules(newVfModules);
2130 // Map and save the new data
2132 service.setSvcData(objectMapper.writeValueAsString(svcData));
2133 configServicesRepository.save(service);
2134 return new ResponseEntity<>(responseStatus);
2135 } catch(JsonProcessingException e) {
2136 log.error("Error mapping object to JSON", e);
2137 // Should probably be a 500 INTERNAL_SERVICE_ERROR
2138 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
2143 * Extracts VF MODULE Topology data from the Config table specified Service
2144 * Instance and VNF ID.
2146 * Maps to /config/GENERIC-RESOURCE-API:services/service/{service-instance-id}/service-data/vnfs/vnf/{vnf-id}/vnf-data/vf-modules/vf-module/{vf-module-id}/vf-module-data/vf-module-topology/
2147 * @param serviceInstanceId the Service Instance ID to lookup data for
2148 * @param vnfId the VNF ID of the VNF to extract topology data from.
2149 * @param vfModuleId the vf-module-idof the vf-module to extract topology data from.
2150 * @return HttpStatus.OK (200) if the data is found.
2151 * @throws RestException if the data does not exist.
2154 public ResponseEntity<GenericResourceApiVfmoduletopologyVfModuleTopology>
2155 configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdVfModuleDataVfModuleTopologyGet(
2156 String serviceInstanceId, String vnfId, String vfModuleId) throws RestException {
2157 log.info("GET | vf-module-topology for ({})", vfModuleId);
2158 if(getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
2159 if (getAcceptHeader().get().contains("application/json")) {
2163 log.warn("ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated");
2165 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
2166 if((services == null) || (services.isEmpty())) {
2167 throw new RestProtocolException("data-missing", "No service entry found", HttpStatus.NOT_FOUND.value());
2170 Optional<GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule> vfModule =
2171 getVfModuleObject(services.get(0), vnfId, vfModuleId);
2172 if(vfModule.isPresent()
2173 && vfModule.get().getVfModuleData() != null
2174 && vfModule.get().getVfModuleData().getVfModuleTopology() != null) {
2175 return new ResponseEntity<>(vfModule.get().getVfModuleData().getVfModuleTopology(), HttpStatus.OK);
2177 log.info("No information found for {}", vfModuleId);
2178 throw new RestApplicationException("data-missing", "Request could not be completed because the relevant data model content does not exist", HttpStatus.NOT_FOUND.value());
2183 public ResponseEntity<Void> configGENERICRESOURCEAPIservicesServiceServiceInstanceIdServiceDataVnfsVnfVnfIdVnfDataVfModulesVfModuleVfModuleIdDelete(
2184 String serviceInstanceId, String vnfId, String vfModuleId) throws RestProtocolException {
2186 log.info("DELETE | vf-module Data for ({})", vfModuleId);
2188 if (getObjectMapper().isPresent() && getAcceptHeader().isPresent()) {
2189 log.info("Something with header.");
2191 log.warn("ObjectMapper or HttpServletRequest not configured in default ConfigApi interface so no example is generated");
2194 ConfigServices service;
2195 GenericResourceApiServicedataServiceData svcData;
2196 List<ConfigServices> services = configServicesRepository.findBySvcInstanceId(serviceInstanceId);
2198 if((services == null) || (services.isEmpty())) {
2199 log.error("service-instance-id ({}) not found in SDN.", serviceInstanceId);
2200 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
2202 service = services.get(0);
2206 svcData = objectMapper.readValue(service.getSvcData(), GenericResourceApiServicedataServiceData.class);
2207 } catch(JsonProcessingException e) {
2208 log.error("Error", e);
2209 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
2212 GenericResourceApiServicedataServicedataVnfs vnfs = svcData.getVnfs();
2213 Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnf =
2216 .filter(targetVnf -> targetVnf.getVnfId().equals(vnfId))
2219 if(! vnf.isPresent()) {
2220 log.error("vnf-id ({}) not found in SDN.", vnfId);
2221 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
2224 GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData = vnf.get().getVnfData();
2225 GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfModules existingVfModules = vnfData.getVfModules();
2226 GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfModules newVfModules = new GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfModules();
2228 if (existingVfModules == null || existingVfModules.getVfModule().isEmpty()) {
2229 log.info("No existing vf-module found. Creating the first vf-module for vnf [{}]", vnfId);
2230 return new ResponseEntity<>(HttpStatus.OK);
2233 ArrayList<String> vfModuleIds = new ArrayList<>();
2234 for (GenericResourceApiServicedataServicedataVnfsVnfVnfdataVfmodulesVfModule vf : existingVfModules.getVfModule()) {
2235 vfModuleIds.add(vf.getVfModuleId());
2237 log.info("[{}] vf-module(s) {} found in vnf [{}]", existingVfModules.getVfModule().size(), vfModuleIds, vnfId);
2238 if (!vfModuleIds.isEmpty() && vfModuleIds.contains(vfModuleId)) {
2239 log.info("Deleting vf-module [{}] from vnf [{}]", vfModuleId, vnfId);
2241 log.info("vf-module [{}] not found in vnf [{}]", vfModuleId, vnfId);
2242 return new ResponseEntity<>(HttpStatus.OK);
2244 existingVfModules.getVfModule()
2246 .filter(vf -> ! vf.getVfModuleId().equals(vfModuleId))
2247 .forEach(newVfModules::addVfModuleItem);
2248 vnfData.setVfModules(newVfModules);
2249 log.info("vf-module [{}] deleted from vnf [{}]", vfModuleId, vnfId);
2251 // Map and save the new data
2253 service.setSvcData(objectMapper.writeValueAsString(svcData));
2254 configServicesRepository.save(service);
2255 return new ResponseEntity<>(HttpStatus.OK);
2256 } catch(JsonProcessingException e) {
2257 log.error("Error mapping object to JSON", e);
2258 // Should probably be a 500 INTERNAL_SERVICE_ERROR
2259 return new ResponseEntity<>(HttpStatus.BAD_REQUEST);