2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
20 package org.onap.so.sdncsimulator.providers;
22 import static org.onap.sdnc.northbound.client.model.GenericResourceApiOrderStatusEnumeration.CREATED;
23 import static org.onap.sdnc.northbound.client.model.GenericResourceApiOrderStatusEnumeration.PENDINGCREATE;
24 import static org.onap.sdnc.northbound.client.model.GenericResourceApiRequestStatusEnumeration.SYNCCOMPLETE;
25 import static org.onap.so.sdncsimulator.utils.Constants.RESTCONF_CONFIG_END_POINT;
26 import static org.onap.so.sdncsimulator.utils.Constants.SERVICE_DATA_VNFS_VNF;
27 import static org.onap.so.sdncsimulator.utils.Constants.SERVICE_TOPOLOGY_OPERATION;
28 import static org.onap.so.sdncsimulator.utils.Constants.SERVICE_TOPOLOGY_OPERATION_CACHE;
29 import static org.onap.so.sdncsimulator.utils.Constants.VNF_DATA_VNF_TOPOLOGY;
30 import static org.onap.so.sdncsimulator.utils.Constants.YES;
31 import static org.onap.so.sdncsimulator.utils.ObjectUtils.getString;
32 import static org.onap.so.sdncsimulator.utils.ObjectUtils.getStringOrNull;
33 import static org.onap.so.sdncsimulator.utils.ObjectUtils.isValid;
34 import java.time.LocalDateTime;
35 import java.util.ArrayList;
36 import java.util.List;
37 import java.util.Optional;
38 import javax.validation.Valid;
39 import org.onap.sdnc.northbound.client.model.GenericResourceApiInstanceReference;
40 import org.onap.sdnc.northbound.client.model.GenericResourceApiLastActionEnumeration;
41 import org.onap.sdnc.northbound.client.model.GenericResourceApiLastRpcActionEnumeration;
42 import org.onap.sdnc.northbound.client.model.GenericResourceApiOnapmodelinformationOnapModelInformation;
43 import org.onap.sdnc.northbound.client.model.GenericResourceApiOperStatusData;
44 import org.onap.sdnc.northbound.client.model.GenericResourceApiOrderStatusEnumeration;
45 import org.onap.sdnc.northbound.client.model.GenericResourceApiRequestinformationRequestInformation;
46 import org.onap.sdnc.northbound.client.model.GenericResourceApiRpcActionEnumeration;
47 import org.onap.sdnc.northbound.client.model.GenericResourceApiSdncrequestheaderSdncRequestHeader;
48 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceOperationInformation;
49 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServiceData;
50 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServicedataVnfs;
51 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServicedataVnfsVnf;
52 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicedataServicedataVnfsVnfVnfData;
53 import org.onap.sdnc.northbound.client.model.GenericResourceApiServiceinformationServiceInformation;
54 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicemodelinfrastructureService;
55 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicestatusServiceStatus;
56 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicetopologyServiceTopology;
57 import org.onap.sdnc.northbound.client.model.GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier;
58 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfOperationInformation;
59 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfinformationVnfInformation;
60 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnfrequestinputVnfRequestInput;
61 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnftopologyVnfTopology;
62 import org.onap.sdnc.northbound.client.model.GenericResourceApiVnftopologyidentifierstructureVnfTopologyIdentifierStructure;
63 import org.onap.so.sdncsimulator.models.Output;
64 import org.onap.so.simulator.cache.provider.AbstractCacheServiceProvider;
65 import org.slf4j.Logger;
66 import org.slf4j.LoggerFactory;
67 import org.springframework.beans.factory.annotation.Autowired;
68 import org.springframework.cache.Cache;
69 import org.springframework.cache.CacheManager;
70 import org.springframework.http.HttpStatus;
71 import org.springframework.stereotype.Service;
74 * @author Waqas Ikram (waqas.ikram@est.tech)
78 public class ServiceOperationsCacheServiceProviderimpl extends AbstractCacheServiceProvider
79 implements ServiceOperationsCacheServiceProvider {
81 private static final String HTTP_STATUS_BAD_REQUEST = Integer.toString(HttpStatus.BAD_REQUEST.value());
82 private static final String HTTP_STATUS_OK = Integer.toString(HttpStatus.OK.value());
83 private static final String EMPTY_STRING = "";
84 private static final Logger LOGGER = LoggerFactory.getLogger(ServiceOperationsCacheServiceProviderimpl.class);
87 public ServiceOperationsCacheServiceProviderimpl(final CacheManager cacheManager) {
92 public Output putServiceOperationInformation(final GenericResourceApiServiceOperationInformation input) {
94 final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader();
95 final String svcRequestId = getSvcRequestId(requestHeader);
97 final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation();
98 if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId())) {
99 final String serviceInstanceId = serviceInformation.getServiceInstanceId();
101 if (isServiceOperationInformationNotExists(serviceInstanceId, input)) {
102 final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
103 LOGGER.info("Adding GenericResourceApiServiceOperationInformation to cache with key: {}",
106 final GenericResourceApiServicemodelinfrastructureService service =
107 getServiceItem(input, serviceInstanceId);
108 cache.put(serviceInstanceId, service);
110 final GenericResourceApiServicestatusServiceStatus serviceStatus = service.getServiceStatus();
112 return new Output().ackFinalIndicator(serviceStatus.getFinalIndicator())
113 .responseCode(serviceStatus.getResponseCode())
114 .responseMessage(serviceStatus.getResponseMessage()).svcRequestId(svcRequestId)
115 .serviceResponseInformation(new GenericResourceApiInstanceReference()
116 .instanceId(serviceInstanceId).objectPath(getObjectPath(serviceInstanceId)));
118 LOGGER.error("serviceInstanceId: {} already exists", serviceInstanceId);
119 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST)
120 .responseMessage("serviceInstanceId: " + serviceInstanceId + " already exists")
121 .svcRequestId(svcRequestId);
125 "Unable to add GenericResourceApiServiceOperationInformation in cache due to invalid input: {}... ",
127 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST)
128 .responseMessage("Service instance not found").svcRequestId(svcRequestId);
133 public Output deleteServiceOperationInformation(final GenericResourceApiServiceOperationInformation input) {
134 final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation();
135 final String svcRequestId = getSvcRequestId(input.getSdncRequestHeader());
137 if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId())) {
138 final String serviceInstanceId = serviceInformation.getServiceInstanceId();
139 final Optional<GenericResourceApiServicemodelinfrastructureService> optional =
140 getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId);
141 if (optional.isPresent()) {
142 final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
143 LOGGER.info("Deleting GenericResourceApiServiceOperationInformation from cache using key: {}",
145 cache.evict(serviceInstanceId);
146 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_OK)
147 .responseMessage(EMPTY_STRING).svcRequestId(svcRequestId).serviceResponseInformation(
148 new GenericResourceApiInstanceReference().instanceId(serviceInstanceId));
151 "Unable to find existing GenericResourceApiServiceModelInfrastructure in cache using service instance id: {}",
155 LOGGER.error("Unable to remove service instance from cache due to invalid input: {}... ", input);
156 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST)
157 .responseMessage("Unable to remove service").svcRequestId(svcRequestId);
161 public Optional<GenericResourceApiServicemodelinfrastructureService> getGenericResourceApiServicemodelinfrastructureService(
162 final String serviceInstanceId) {
163 final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
165 final GenericResourceApiServicemodelinfrastructureService value =
166 cache.get(serviceInstanceId, GenericResourceApiServicemodelinfrastructureService.class);
168 LOGGER.info("Found {} in cahce for service instance id: {}", value, serviceInstanceId);
169 return Optional.of(value);
171 LOGGER.error("Unable to find GenericResourceApiServiceModelInfrastructure in cache for service instance id: {}",
173 return Optional.empty();
177 public Output putVnfOperationInformation(final GenericResourceApiVnfOperationInformation input) {
179 final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation();
180 final GenericResourceApiVnfinformationVnfInformation vnfInformation = input.getVnfInformation();
182 final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader();
183 final String svcRequestId = getSvcRequestId(requestHeader);
185 if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId()) && vnfInformation != null
186 && isValid(vnfInformation.getVnfId())) {
187 final String serviceInstanceId = serviceInformation.getServiceInstanceId();
188 final String vnfId = vnfInformation.getVnfId();
189 final Optional<GenericResourceApiServicemodelinfrastructureService> optional =
190 getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId);
191 if (optional.isPresent()) {
192 final GenericResourceApiServicemodelinfrastructureService service = optional.get();
193 final GenericResourceApiServicedataServiceData serviceData = service.getServiceData();
194 if (serviceData != null) {
195 final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList = getVnfs(serviceData);
196 final GenericResourceApiLastRpcActionEnumeration svcAction =
197 GenericResourceApiLastRpcActionEnumeration.fromValue(getSvcAction(requestHeader));
199 if (ifVnfNotExists(vnfId, svcAction, vnfsList)) {
200 vnfsList.add(getGenericResourceApiServicedataVnf(serviceInstanceId, vnfId, input));
202 final GenericResourceApiServicestatusServiceStatus serviceStatus = service.getServiceStatus();
204 return new Output().ackFinalIndicator(serviceStatus.getFinalIndicator())
205 .responseCode(serviceStatus.getResponseCode())
206 .responseMessage(serviceStatus.getResponseMessage()).svcRequestId(svcRequestId)
207 .serviceResponseInformation(new GenericResourceApiInstanceReference()
208 .instanceId(serviceInstanceId).objectPath(getObjectPath(serviceInstanceId)))
209 .vnfResponseInformation(new GenericResourceApiInstanceReference().instanceId(vnfId)
210 .objectPath(getObjectPath(serviceInstanceId, vnfId)));
212 LOGGER.error("vnfId: {} already exists with SVC Action: {}", vnfId, svcAction);
213 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST)
214 .responseMessage("vnfId: " + vnfId + " already exists").svcRequestId(svcRequestId);
218 "Unable to find existing GenericResourceApiServiceModelInfrastructure in cache using service instance id: {}",
223 "Unable to add GenericResourceApiServiceOperationInformation in cache due to invalid input: {}... ",
225 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST)
226 .responseMessage("Unable to add vnf").svcRequestId(svcRequestId);
230 public Output deleteVnfOperationInformation(final GenericResourceApiVnfOperationInformation input) {
231 final GenericResourceApiServiceinformationServiceInformation serviceInformation = input.getServiceInformation();
232 final GenericResourceApiVnfinformationVnfInformation vnfInformation = input.getVnfInformation();
234 final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader();
235 final String svcRequestId = getSvcRequestId(requestHeader);
237 if (serviceInformation != null && isValid(serviceInformation.getServiceInstanceId()) && vnfInformation != null
238 && isValid(vnfInformation.getVnfId())) {
239 final String serviceInstanceId = serviceInformation.getServiceInstanceId();
240 final String vnfId = vnfInformation.getVnfId();
241 final Optional<GenericResourceApiServicemodelinfrastructureService> optional =
242 getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId);
243 if (optional.isPresent()) {
244 final GenericResourceApiServicemodelinfrastructureService service = optional.get();
245 final GenericResourceApiServicedataServiceData serviceData = service.getServiceData();
246 if (serviceData != null) {
247 final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList = getVnfs(serviceData);
248 final Optional<GenericResourceApiServicedataServicedataVnfsVnf> vnfInstanceOptional =
249 getExistingVnf(vnfId, vnfsList);
251 if (vnfInstanceOptional.isPresent()) {
252 vnfsList.removeIf(vnf -> {
253 final String existingVnfId = vnf.getVnfId();
254 if (existingVnfId != null && existingVnfId.equals(vnfId)) {
255 LOGGER.info("Remove vnf with id: {} ... ", existingVnfId);
261 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_OK)
262 .responseMessage(EMPTY_STRING).svcRequestId(svcRequestId)
263 .serviceResponseInformation(
264 new GenericResourceApiInstanceReference().instanceId(serviceInstanceId))
265 .vnfResponseInformation(new GenericResourceApiInstanceReference().instanceId(vnfId));
271 "Unable to find existing GenericResourceApiServiceModelInfrastructure in cache using service instance id: {}",
275 LOGGER.error("Unable to remove vnf instance from cache due to invalid input: {}... ", input);
276 return new Output().ackFinalIndicator(YES).responseCode(HTTP_STATUS_BAD_REQUEST)
277 .responseMessage("Unable to remove vnf").svcRequestId(svcRequestId);
281 private String getSvcRequestId(final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader) {
282 return requestHeader != null ? requestHeader.getSvcRequestId() : null;
286 public void clearAll() {
287 clearCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
290 private String getObjectPath(final String serviceInstanceId, final String vnfId) {
291 return getObjectPath(serviceInstanceId) + SERVICE_DATA_VNFS_VNF + vnfId + VNF_DATA_VNF_TOPOLOGY;
294 private String getObjectPath(final String serviceInstanceId) {
295 return RESTCONF_CONFIG_END_POINT + serviceInstanceId;
299 private boolean ifVnfNotExists(final String vnfId, final GenericResourceApiLastRpcActionEnumeration svcAction,
300 final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList) {
301 final Optional<GenericResourceApiServicedataServicedataVnfsVnf> optional = getExistingVnf(vnfId, vnfsList);
302 if (optional.isPresent()) {
303 final GenericResourceApiServicedataServicedataVnfsVnf existingVnf = optional.get();
304 final GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData = existingVnf.getVnfData();
306 if (vnfData != null && vnfData.getVnfLevelOperStatus() != null
307 && vnfData.getVnfLevelOperStatus().getLastRpcAction() != null) {
308 final GenericResourceApiLastRpcActionEnumeration existingVnflastRpcAction =
309 vnfData.getVnfLevelOperStatus().getLastRpcAction();
310 if (existingVnflastRpcAction.equals(svcAction)) {
311 LOGGER.error("Found vnf with id: {} and LastRpcAction: {} same as SvcAction: {}", vnfId,
312 existingVnflastRpcAction, svcAction);
315 LOGGER.warn("Will remove and replace existing vnf with id: {} as SvcAction is changed from {} to {}",
316 vnfId, existingVnflastRpcAction, svcAction);
317 vnfsList.removeIf(vnf -> vnf.getVnfId() != null && vnf.getVnfId().equals(vnfId));
325 private Optional<GenericResourceApiServicedataServicedataVnfsVnf> getExistingVnf(final String vnfId,
326 final List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList) {
327 return vnfsList.stream().filter(vnf -> vnf.getVnfId() != null && vnf.getVnfId().equals(vnfId)).findFirst();
330 private List<GenericResourceApiServicedataServicedataVnfsVnf> getVnfs(
331 final GenericResourceApiServicedataServiceData serviceData) {
332 GenericResourceApiServicedataServicedataVnfs vnfs = serviceData.getVnfs();
334 vnfs = new GenericResourceApiServicedataServicedataVnfs();
335 serviceData.setVnfs(vnfs);
338 List<GenericResourceApiServicedataServicedataVnfsVnf> vnfsList = vnfs.getVnf();
339 if (vnfsList == null) {
340 vnfsList = new ArrayList<>();
341 vnfs.setVnf(vnfsList);
346 private GenericResourceApiServicedataServicedataVnfsVnf getGenericResourceApiServicedataVnf(
347 final String serviceInstanceId, final String vnfId, final GenericResourceApiVnfOperationInformation input) {
348 return new GenericResourceApiServicedataServicedataVnfsVnf().vnfId(vnfId).vnfData(getVnfData(input));
351 private GenericResourceApiServicedataServicedataVnfsVnfVnfData getVnfData(
352 final GenericResourceApiVnfOperationInformation input) {
354 final GenericResourceApiServicedataServicedataVnfsVnfVnfData vnfData =
355 new GenericResourceApiServicedataServicedataVnfsVnfVnfData();
357 vnfData.vnfLevelOperStatus(
358 getServiceLevelOperStatus(PENDINGCREATE, input.getRequestInformation(), input.getSdncRequestHeader()));
359 vnfData.serviceInformation(input.getServiceInformation());
360 vnfData.sdncRequestHeader(input.getSdncRequestHeader());
361 vnfData.vnfInformation(input.getVnfInformation());
362 vnfData.requestInformation(input.getRequestInformation());
363 vnfData.vnfRequestInput(input.getVnfRequestInput());
365 vnfData.vnfTopology(getVnfTopology(input.getVnfInformation(), input.getVnfRequestInput()));
370 private GenericResourceApiVnftopologyVnfTopology getVnfTopology(
371 final GenericResourceApiVnfinformationVnfInformation vnfInformation,
372 final GenericResourceApiVnfrequestinputVnfRequestInput vnfRequestInput) {
374 final GenericResourceApiVnftopologyVnfTopology apiVnftopologyVnfTopology =
375 new GenericResourceApiVnftopologyVnfTopology();
377 if (vnfInformation != null) {
378 apiVnftopologyVnfTopology.onapModelInformation(vnfInformation.getOnapModelInformation());
379 apiVnftopologyVnfTopology.vnfTopologyIdentifierStructure(getTopologyIdentifierStructure(vnfInformation));
381 if (vnfRequestInput != null) {
382 apiVnftopologyVnfTopology.tenant(vnfRequestInput.getTenant());
383 apiVnftopologyVnfTopology.aicClli(vnfRequestInput.getAicClli());
384 apiVnftopologyVnfTopology.aicCloudRegion(vnfRequestInput.getAicCloudRegion());
386 return apiVnftopologyVnfTopology;
389 private GenericResourceApiVnftopologyidentifierstructureVnfTopologyIdentifierStructure getTopologyIdentifierStructure(
390 @Valid final GenericResourceApiVnfinformationVnfInformation vnfInformation) {
391 return new GenericResourceApiVnftopologyidentifierstructureVnfTopologyIdentifierStructure()
392 .vnfId(vnfInformation.getVnfId()).vnfName(vnfInformation.getVnfName())
393 .vnfType(vnfInformation.getVnfType());
396 private GenericResourceApiServicemodelinfrastructureService getServiceItem(
397 final GenericResourceApiServiceOperationInformation input, final String serviceInstanceId) {
399 final GenericResourceApiServicedataServiceData apiServicedataServiceData =
400 new GenericResourceApiServicedataServiceData();
402 apiServicedataServiceData.requestInformation(input.getRequestInformation());
403 apiServicedataServiceData.serviceRequestInput(input.getServiceRequestInput());
404 apiServicedataServiceData.serviceInformation(input.getServiceInformation());
405 apiServicedataServiceData.serviceTopology(getServiceTopology(input));
406 apiServicedataServiceData.sdncRequestHeader(input.getSdncRequestHeader());
407 apiServicedataServiceData.serviceLevelOperStatus(getServiceLevelOperStatus(input));
409 final GenericResourceApiServicestatusServiceStatus serviceStatus =
410 getServiceStatus(getSvcAction(input.getSdncRequestHeader()),
411 getRequestAction(input.getRequestInformation()), HTTP_STATUS_OK);
413 return new GenericResourceApiServicemodelinfrastructureService().serviceData(apiServicedataServiceData)
414 .serviceStatus(serviceStatus).serviceInstanceId(serviceInstanceId);
417 private String getSvcAction(final GenericResourceApiSdncrequestheaderSdncRequestHeader input) {
418 return input != null ? getStringOrNull(input.getSvcAction()) : null;
421 private GenericResourceApiServicestatusServiceStatus getServiceStatus(final String rpcAction, final String action,
422 final String responseCode) {
423 return new GenericResourceApiServicestatusServiceStatus().finalIndicator(YES)
424 .rpcAction(GenericResourceApiRpcActionEnumeration.fromValue(rpcAction))
425 .rpcName(SERVICE_TOPOLOGY_OPERATION).responseTimestamp(LocalDateTime.now().toString())
426 .responseCode(responseCode).requestStatus(SYNCCOMPLETE).responseMessage(EMPTY_STRING).action(action);
429 private GenericResourceApiOperStatusData getServiceLevelOperStatus(
430 final GenericResourceApiServiceOperationInformation input) {
431 return getServiceLevelOperStatus(CREATED, input.getRequestInformation(), input.getSdncRequestHeader());
434 private GenericResourceApiOperStatusData getServiceLevelOperStatus(
435 final GenericResourceApiOrderStatusEnumeration statusEnumeration,
436 final GenericResourceApiRequestinformationRequestInformation requestInformation,
437 final GenericResourceApiSdncrequestheaderSdncRequestHeader sdncRequestHeader) {
438 return new GenericResourceApiOperStatusData().orderStatus(statusEnumeration)
439 .lastAction(GenericResourceApiLastActionEnumeration.fromValue(getRequestAction(requestInformation)))
440 .lastRpcAction(GenericResourceApiLastRpcActionEnumeration.fromValue(getSvcAction(sdncRequestHeader)));
443 private String getRequestAction(final GenericResourceApiRequestinformationRequestInformation input) {
444 return getRequestAction(input, EMPTY_STRING);
447 private String getRequestAction(final GenericResourceApiRequestinformationRequestInformation input,
448 final String defaultValue) {
449 return input != null ? getString(input.getRequestAction(), defaultValue) : defaultValue;
452 private GenericResourceApiServicetopologyServiceTopology getServiceTopology(
453 final GenericResourceApiServiceOperationInformation input) {
454 final GenericResourceApiOnapmodelinformationOnapModelInformation modelInformation =
455 input.getServiceInformation() != null ? input.getServiceInformation().getOnapModelInformation() : null;
456 return new GenericResourceApiServicetopologyServiceTopology().onapModelInformation(modelInformation)
457 .serviceTopologyIdentifier(getServiceTopologyIdentifier(input));
460 private GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier getServiceTopologyIdentifier(
461 final GenericResourceApiServiceOperationInformation input) {
462 final GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier identifier =
463 new GenericResourceApiServicetopologyidentifierServiceTopologyIdentifier();
465 if (input.getServiceInformation() != null) {
466 final GenericResourceApiServiceinformationServiceInformation serviceInformation =
467 input.getServiceInformation();
468 identifier.globalCustomerId(serviceInformation.getGlobalCustomerId())
469 .serviceType(input.getServiceInformation().getSubscriptionServiceType())
470 .serviceInstanceId(input.getServiceInformation().getServiceInstanceId());;
473 if (input.getServiceRequestInput() != null) {
474 identifier.serviceInstanceName(input.getServiceRequestInput().getServiceInstanceName());
481 private boolean isServiceOperationInformationNotExists(final String serviceInstanceId,
482 final GenericResourceApiServiceOperationInformation input) {
483 final GenericResourceApiSdncrequestheaderSdncRequestHeader requestHeader = input.getSdncRequestHeader();
484 final Optional<GenericResourceApiServicemodelinfrastructureService> optional =
485 getGenericResourceApiServicemodelinfrastructureService(serviceInstanceId);
487 if (optional.isPresent()) {
488 final GenericResourceApiServicemodelinfrastructureService existingService = optional.get();
489 final GenericResourceApiServicestatusServiceStatus serviceStatus = existingService.getServiceStatus();
490 if (serviceStatus != null) {
491 final GenericResourceApiRpcActionEnumeration rpcAction = serviceStatus.getRpcAction();
492 final String svcAction = getSvcAction(requestHeader);
493 if (rpcAction != null && rpcAction.toString().equals(svcAction)) {
494 LOGGER.error("Found Service with id: {} and RpcAction: {} same as SvcAction: {}",
495 serviceInstanceId, rpcAction, svcAction);
499 final Cache cache = getCache(SERVICE_TOPOLOGY_OPERATION_CACHE);
501 "Deleting existing GenericResourceApiServiceOperationInformation from cache using key: {} as SvcAction is changed from {} to {}",
502 serviceInstanceId, rpcAction, svcAction);
503 cache.evict(serviceInstanceId);