1 package org.onap.sdnc.northbound;
3 import java.text.DateFormat;
4 import java.text.SimpleDateFormat;
6 import java.util.Properties;
7 import java.util.TimeZone;
8 import java.util.concurrent.ExecutionException;
9 import java.util.concurrent.ExecutorService;
10 import java.util.concurrent.Executors;
11 import java.util.concurrent.Future;
13 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
14 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
15 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
16 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
17 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
18 import org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException;
19 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
20 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
21 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
22 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.BrgTopologyOperationInput;
23 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.BrgTopologyOperationInputBuilder;
24 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.BrgTopologyOperationOutput;
25 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.BrgTopologyOperationOutputBuilder;
26 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ContrailRouteTopologyOperationInput;
27 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ContrailRouteTopologyOperationInputBuilder;
28 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ContrailRouteTopologyOperationOutput;
29 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ContrailRouteTopologyOperationOutputBuilder;
30 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.GENERICRESOURCEAPIService;
31 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.NetworkTopologyOperationInput;
32 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.NetworkTopologyOperationInputBuilder;
33 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.NetworkTopologyOperationOutput;
34 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.NetworkTopologyOperationOutputBuilder;
35 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadNetworkTopologyOperationInput;
36 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadNetworkTopologyOperationInputBuilder;
37 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadNetworkTopologyOperationOutput;
38 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadNetworkTopologyOperationOutputBuilder;
39 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadVnfTopologyOperationInput;
40 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadVnfTopologyOperationInputBuilder;
41 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadVnfTopologyOperationOutput;
42 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadVnfTopologyOperationOutputBuilder;
43 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadVnfs;
44 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.PreloadVnfsBuilder;
45 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.SecurityZoneTopologyOperationInput;
46 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.SecurityZoneTopologyOperationInputBuilder;
47 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.SecurityZoneTopologyOperationOutput;
48 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.SecurityZoneTopologyOperationOutputBuilder;
49 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServiceTopologyOperationInput;
50 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServiceTopologyOperationInputBuilder;
51 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServiceTopologyOperationOutput;
52 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServiceTopologyOperationOutputBuilder;
53 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.Services;
54 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.ServicesBuilder;
55 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.TunnelxconnTopologyOperationInput;
56 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.TunnelxconnTopologyOperationInputBuilder;
57 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.TunnelxconnTopologyOperationOutput;
58 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.TunnelxconnTopologyOperationOutputBuilder;
59 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VfModuleTopologyOperationInput;
60 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VfModuleTopologyOperationInputBuilder;
61 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VfModuleTopologyOperationOutput;
62 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VfModuleTopologyOperationOutputBuilder;
63 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VnfTopologyOperationInput;
64 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VnfTopologyOperationInputBuilder;
65 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VnfTopologyOperationOutput;
66 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.VnfTopologyOperationOutputBuilder;
67 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.brg.response.information.BrgResponseInformationBuilder;
68 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.contrail.route.response.information.ContrailRouteResponseInformationBuilder;
69 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.network.response.information.NetworkResponseInformationBuilder;
70 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.preload.data.PreloadData;
71 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.preload.data.PreloadDataBuilder;
72 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.preload.model.information.VnfPreloadList;
73 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.preload.model.information.VnfPreloadListBuilder;
74 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.preload.model.information.VnfPreloadListKey;
75 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.request.information.RequestInformation;
76 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.sdnc.request.header.SdncRequestHeader;
77 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.sdnc.request.header.SdncRequestHeader.SvcAction;
78 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.security.zone.response.information.SecurityZoneResponseInformationBuilder;
79 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.data.ServiceData;
80 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.data.ServiceDataBuilder;
81 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.model.infrastructure.Service;
82 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.model.infrastructure.ServiceBuilder;
83 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.model.infrastructure.ServiceKey;
84 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.response.information.ServiceResponseInformationBuilder;
85 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.status.ServiceStatus.RequestStatus;
86 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.status.ServiceStatus.RpcAction;
87 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.service.status.ServiceStatusBuilder;
88 import org.opendaylight.yang.gen.v1.org.onap.sdnc.northbound.generic.resource.rev170824.tunnelxconn.response.information.TunnelxconnResponseInformationBuilder;
89 import org.opendaylight.yangtools.yang.binding.DataObject;
90 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
91 import org.opendaylight.yangtools.yang.common.RpcResult;
92 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
93 import org.slf4j.Logger;
94 import org.slf4j.LoggerFactory;
96 import com.google.common.base.Optional;
97 import com.google.common.util.concurrent.CheckedFuture;
98 import com.google.common.util.concurrent.Futures;
101 * Defines a base implementation for your provider. This class extends from a
102 * helper class which provides storage for the most commonly used components of
103 * the MD-SAL. Additionally the base class provides some basic logging and
104 * initialization / clean up methods.
106 * To use this, copy and paste (overwrite) the following method into the
107 * TestApplicationProviderModule class which is auto generated under
108 * src/main/java in this project (created only once during first compilation):
113 * public java.lang.AutoCloseable createInstance() {
115 * // final GENERIC-RESOURCE-APIProvider provider = new
116 * // GENERIC-RESOURCE-APIProvider();
117 * final GenericResourceApiProvider provider = new GenericResourceApiProvider();
118 * provider.setDataBroker(getDataBrokerDependency());
119 * provider.setNotificationService(getNotificationServiceDependency());
120 * provider.setRpcRegistry(getRpcRegistryDependency());
121 * provider.initialize();
122 * return new AutoCloseable() {
125 * public void close() throws Exception {
126 * // TODO: CLOSE ANY REGISTRATION OBJECTS CREATED USING ABOVE
127 * // BROKER/NOTIFICATION
128 * // SERVIE/RPC REGISTRY
137 public class GenericResourceApiProvider implements AutoCloseable, GENERICRESOURCEAPIService {
139 private static final String APP_NAME = "generic-resource-api";
140 private static final String CALLED_STR = "{} called.";
141 private static final String NULL_OR_EMPTY_ERROR_MESSAGE = "exiting {} because of null or empty service-instance-id";
142 private static final String NULL_OR_EMPTY_ERROR_PARAM = "invalid input, null or empty service-instance-id";
143 private static final String ADDING_INPUT_DATA_LOG = "Adding INPUT data for {} [{}] input: {}";
144 private static final String ADDING_OPERATIONAL_DATA_LOG = "Adding OPERATIONAL data for {} [{}] operational-data: {}";
145 private static final String OPERATIONAL_DATA_PARAM = "operational-data";
146 private static final String NO_SERVICE_LOGIC_ACTIVE = "No service logic active for ";
147 private static final String SERVICE_LOGIC_SEARCH_ERROR_MESSAGE = "Caught exception looking for service logic";
148 private static final String ERROR_CODE_PARAM = "error-code";
149 private static final String ERROR_MESSAGE_PARAM = "error-message";
150 private static final String ACK_FINAL_PARAM = "ack-final";
151 private static final String SERVICE_OBJECT_PATH_PARAM = "service-object-path";
152 private static final String UPDATING_MDSAL_ERROR_MESSAGE = "Caught Exception updating MD-SAL for {} [{}] \n";
153 private static final String UPDATING_MDSAL_ERROR_MESSAGE_2 = "Caught Exception updating MD-SAL for {} [{},{}] \n";
154 private static final String RETURNED_FAILED_MESSAGE = "Returned FAILED for {} [{}] {}";
155 private static final String UPDATING_MDSAL_INFO_MESSAGE = "Updating MD-SAL for {} [{}] ServiceData: {}";
156 private static final String UPDATED_MDSAL_INFO_MESSAGE = "Updated MD-SAL for {} [{}]";
157 private static final String RETURNED_SUCCESS_MESSAGE = "Returned SUCCESS for {} [{}] {}";
158 private static final String NON_NULL_PARAM = "non-null";
159 private static final String NULL_PARAM = "null";
160 private static final String SERVICE_LOGIC_EXECUTION_ERROR_MESSAGE = "Caught exception executing service logic for {} ";
161 private static final String UPDATING_TREE_INFO_MESSAGE = "Updating OPERATIONAL tree.";
162 private static final String EMPTY_SERVICE_INSTANCE_MESSAGE = "exiting {} because the service-instance does not have any service data in SDNC";
163 private static final String INVALID_INPUT_ERROR_MESSAGE = "invalid input: the service-instance does not have any service data in SDNC";
164 private static final String ALLOTTED_RESOURCE_ID_PARAM = "allotted-resource-id";
165 private static final String ERROR_NETWORK_ID = "error";
167 private final Logger log = LoggerFactory.getLogger(GenericResourceApiProvider.class);
168 private final ExecutorService executor;
169 private final GenericResourceApiSvcLogicServiceClient svcLogicClient;
171 protected DataBroker dataBroker;
172 protected NotificationPublishService notificationService;
173 protected RpcProviderRegistry rpcRegistry;
174 protected BindingAwareBroker.RpcRegistration<GENERICRESOURCEAPIService> rpcRegistration;
176 public GenericResourceApiProvider(
177 DataBroker dataBroker,
178 NotificationPublishService notificationPublishService,
179 RpcProviderRegistry rpcProviderRegistry,
180 GenericResourceApiSvcLogicServiceClient client
182 log.info("Creating provider for {}", APP_NAME);
183 executor = Executors.newFixedThreadPool(1);
184 setDataBroker(dataBroker);
185 setNotificationService(notificationPublishService);
186 setRpcRegistry(rpcProviderRegistry);
187 svcLogicClient = client;
192 public void initialize() {
193 log.info("Initializing provider for {}", APP_NAME);
194 // Create the top level containers
197 GenericResourceApiUtil.loadProperties();
198 } catch (Exception e) {
199 log.error("Caught Exception while trying to load properties file", e);
202 log.info("Initialization complete for {}", APP_NAME);
205 protected void initializeChild() {
206 // Override if you have custom initialization intelligence
210 public void close() throws Exception {
211 log.info("Closing provider for {}", APP_NAME);
213 rpcRegistration.close();
214 log.info("Successfully closed provider for {}", APP_NAME);
217 private static class Iso8601Util {
219 private static TimeZone timeZone = TimeZone.getTimeZone("UTC");
220 private static DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
222 private Iso8601Util() {}
225 dateFormat.setTimeZone(timeZone);
227 private static String now() {
228 return dateFormat.format(new Date());
232 public void setDataBroker(DataBroker dataBroker) {
233 this.dataBroker = dataBroker;
234 if (log.isDebugEnabled()) {
235 log.debug("DataBroker set to {}", dataBroker == null ? NULL_PARAM : NON_NULL_PARAM);
239 public void setNotificationService(NotificationPublishService notificationService) {
240 this.notificationService = notificationService;
241 if (log.isDebugEnabled()) {
242 log.debug("Notification Service set to {}", notificationService == null ? NULL_PARAM : NON_NULL_PARAM);
246 public void setRpcRegistry(RpcProviderRegistry rpcRegistry) {
247 this.rpcRegistry = rpcRegistry;
248 if (log.isDebugEnabled()) {
249 log.debug("RpcRegistry set to {}", rpcRegistry == null ? NULL_PARAM : NON_NULL_PARAM);
253 private void createContainers() {
255 final WriteTransaction t = dataBroker.newReadWriteTransaction();
257 // Create the service-instance container
258 t.merge(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(Services.class),
259 new ServicesBuilder().build());
260 t.merge(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(Services.class),
261 new ServicesBuilder().build());
263 // Create the PreloadVnfs container
264 t.merge(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(PreloadVnfs.class),
265 new PreloadVnfsBuilder().build());
266 t.merge(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(PreloadVnfs.class),
267 new PreloadVnfsBuilder().build());
270 CheckedFuture<Void, TransactionCommitFailedException> checkedFuture = t.submit();
272 log.info("Create containers succeeded!");
274 } catch (InterruptedException | ExecutionException e) {
275 log.error("Create containers failed: ", e);
279 private void setServiceStatus(ServiceStatusBuilder serviceStatusBuilder, String errorCode, String errorMessage,
281 serviceStatusBuilder.setResponseCode(errorCode);
282 serviceStatusBuilder.setResponseMessage(errorMessage);
283 serviceStatusBuilder.setFinalIndicator(ackFinal);
284 serviceStatusBuilder.setResponseTimestamp(Iso8601Util.now());
287 private void setServiceStatus(ServiceStatusBuilder serviceStatusBuilder, RequestInformation requestInformation) {
288 if (requestInformation != null && requestInformation.getRequestAction() != null) {
289 serviceStatusBuilder.setAction(requestInformation.getRequestAction().toString());
293 private void setServiceStatus(ServiceStatusBuilder serviceStatusBuilder, SdncRequestHeader requestHeader) {
294 if (requestHeader != null && requestHeader.getSvcAction() != null) {
295 switch (requestHeader.getSvcAction()) {
297 serviceStatusBuilder.setRpcAction(RpcAction.Assign);
300 serviceStatusBuilder.setRpcAction(RpcAction.Unassign);
303 serviceStatusBuilder.setRpcAction(RpcAction.Activate);
306 serviceStatusBuilder.setRpcAction(RpcAction.Deactivate);
309 serviceStatusBuilder.setRpcAction(RpcAction.Delete);
312 log.error("Unknown SvcAction: {}", requestHeader.getSvcAction());
318 private void getServiceData(String siid, ServiceDataBuilder serviceDataBuilder) {
320 getServiceData(siid, serviceDataBuilder, LogicalDatastoreType.CONFIGURATION);
323 private void getServiceData(String siid, ServiceDataBuilder serviceDataBuilder, LogicalDatastoreType type) {
324 // See if any data exists yet for this siid, if so grab it.
325 InstanceIdentifier<Service> serviceInstanceIdentifier = InstanceIdentifier
326 .builder(Services.class)
327 .child(Service.class, new ServiceKey(siid))
330 ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
331 Optional<Service> data = Optional.absent();
333 data = readTx.read(type, serviceInstanceIdentifier).get();
334 } catch (InterruptedException | ExecutionException e) {
335 log.error("Caught Exception reading MD-SAL ({}) data for [{}] ", type, siid, e);
338 if (data != null && data.isPresent()) {
339 ServiceData serviceData = data.get().getServiceData();
340 if (serviceData != null) {
341 log.info("Read MD-SAL ({}) data for [{}] ServiceData: {}", type, siid, serviceData);
342 serviceDataBuilder.setSdncRequestHeader(serviceData.getSdncRequestHeader());
343 serviceDataBuilder.setRequestInformation(serviceData.getRequestInformation());
344 serviceDataBuilder.setServiceInformation(serviceData.getServiceInformation());
345 serviceDataBuilder.setServiceRequestInput(serviceData.getServiceRequestInput());
346 serviceDataBuilder.setServiceTopology(serviceData.getServiceTopology());
347 serviceDataBuilder.setServiceLevelOperStatus(serviceData.getServiceLevelOperStatus());
348 serviceDataBuilder.setNetworks(serviceData.getNetworks());
349 serviceDataBuilder.setVnfs(serviceData.getVnfs());
350 serviceDataBuilder.setProvidedAllottedResources(serviceData.getProvidedAllottedResources());
351 serviceDataBuilder.setConsumedAllottedResources(serviceData.getConsumedAllottedResources());
352 // service-instance-id needs to be set
354 log.info("No service-data found in MD-SAL ({}) for [{}]", type, siid);
357 log.info("No data found in MD-SAL ({}) for [{}]", type, siid);
361 private void getPreloadData(String vnfName, String vnfType, PreloadDataBuilder preloadDataBuilder) {
363 getPreloadData(vnfName, vnfType, preloadDataBuilder, LogicalDatastoreType.CONFIGURATION);
366 private void getPreloadData(String preloadName, String preloadType, PreloadDataBuilder preloadDataBuilder,
367 LogicalDatastoreType type) {
368 // See if any data exists yet for this name/type, if so grab it.
369 InstanceIdentifier<VnfPreloadList> preloadInstanceIdentifier = InstanceIdentifier
370 .builder(PreloadVnfs.class)
371 .child(VnfPreloadList.class, new VnfPreloadListKey(preloadName, preloadType))
374 ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
375 Optional<VnfPreloadList> data = Optional.absent();
377 data = readTx.read(type, preloadInstanceIdentifier).get();
378 } catch (InterruptedException | ExecutionException e) {
379 log.error("Caught Exception reading MD-SAL ({}) for [{},{}] ", type, preloadName, preloadType, e);
382 if (data != null && data.isPresent()) {
383 PreloadData preloadData = data.get().getPreloadData();
384 if (preloadData != null) {
385 log.info("Read MD-SAL ({}) data for [{},{}] PreloadData: {}", type, preloadName, preloadType,
387 preloadDataBuilder.setVnfTopologyInformation(preloadData.getVnfTopologyInformation());
388 preloadDataBuilder.setNetworkTopologyInformation(preloadData.getNetworkTopologyInformation());
389 preloadDataBuilder.setOperStatus(preloadData.getOperStatus());
391 log.info("No preload-data found in MD-SAL ({}) for [{},{}] ", type, preloadName, preloadType);
394 log.info("No data found in MD-SAL ({}) for [{},{}] ", type, preloadName, preloadType);
398 private void saveService(final Service entry, boolean merge, LogicalDatastoreType storeType) {
399 // Each entry will be identifiable by a unique key, we have to create that
401 InstanceIdentifier<Service> path = InstanceIdentifier
402 .builder(Services.class)
403 .child(Service.class, entry.getKey())
406 trySaveEntry(entry, merge, storeType, path);
409 private void savePreloadList(final VnfPreloadList entry, boolean merge, LogicalDatastoreType storeType) {
411 // Each entry will be identifiable by a unique key, we have to create that
413 InstanceIdentifier<VnfPreloadList> path = InstanceIdentifier
414 .builder(PreloadVnfs.class)
415 .child(VnfPreloadList.class, entry.getKey())
418 trySaveEntry(entry, merge, storeType, path);
421 private <T extends DataObject> void trySaveEntry(T entry, boolean merge, LogicalDatastoreType storeType,
422 InstanceIdentifier<T> path) {
426 save(entry, merge, storeType, path);
428 } catch (OptimisticLockFailedException e) {
430 log.debug("Got OptimisticLockFailedException on last try - failing ");
431 throw new IllegalStateException(e);
433 log.debug("Got OptimisticLockFailedException - trying again ");
435 catch (TransactionCommitFailedException ex){
436 log.debug("Update DataStore failed");
437 throw new IllegalStateException(ex);
442 private <T extends DataObject> void save(T entry, boolean merge, LogicalDatastoreType storeType,
443 InstanceIdentifier<T> path)
444 throws TransactionCommitFailedException {
445 WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
447 tx.merge(storeType, path, entry);
449 tx.put(storeType, path, entry);
451 tx.submit().checkedGet();
452 log.debug("Update DataStore succeeded");
455 private void deleteService(final Service entry, LogicalDatastoreType storeType) {
456 // Each entry will be identifiable by a unique key, we have to create
458 InstanceIdentifier<Service> path = InstanceIdentifier
459 .builder(Services.class)
460 .child(Service.class, entry.getKey())
463 tryDeleteEntry(storeType, path);
466 private void tryDeleteEntry(LogicalDatastoreType storeType, InstanceIdentifier<Service> path) {
470 delete(storeType, path);
472 } catch (OptimisticLockFailedException e) {
474 log.debug("Got OptimisticLockFailedException on last try - failing ");
475 throw new IllegalStateException(e);
477 log.debug("Got OptimisticLockFailedException - trying again ");
479 catch (TransactionCommitFailedException ex){
480 log.debug("Update DataStore failed");
481 throw new IllegalStateException(ex);
486 private void delete(LogicalDatastoreType storeType, InstanceIdentifier<Service> path)
487 throws TransactionCommitFailedException {
488 WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
489 tx.delete(storeType, path);
490 tx.submit().checkedGet();
491 log.debug("DataStore delete succeeded");
495 public Future<RpcResult<ServiceTopologyOperationOutput>> serviceTopologyOperation(
496 ServiceTopologyOperationInput input) {
498 final String svcOperation = "service-topology-operation";
499 ServiceData serviceData;
500 ServiceStatusBuilder serviceStatusBuilder = new ServiceStatusBuilder();
501 Properties parms = new Properties();
503 log.info(CALLED_STR, svcOperation);
504 // create a new response object
505 ServiceTopologyOperationOutputBuilder responseBuilder = new ServiceTopologyOperationOutputBuilder();
507 if (input == null || input.getServiceInformation() == null
508 || input.getServiceInformation().getServiceInstanceId() == null
509 || input.getServiceInformation().getServiceInstanceId().length() == 0) {
510 log.debug(NULL_OR_EMPTY_ERROR_MESSAGE, svcOperation);
511 responseBuilder.setResponseCode("404");
512 responseBuilder.setResponseMessage(NULL_OR_EMPTY_ERROR_PARAM);
513 responseBuilder.setAckFinalIndicator("Y");
514 RpcResult<ServiceTopologyOperationOutput> rpcResult = RpcResultBuilder
515 .<ServiceTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
516 return Futures.immediateFuture(rpcResult);
519 // Grab the service instance ID from the input buffer
520 String siid = input.getServiceInformation().getServiceInstanceId();
522 if (input.getSdncRequestHeader() != null) {
523 responseBuilder.setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId());
526 ServiceDataBuilder serviceDataBuilder = new ServiceDataBuilder();
527 getServiceData(siid, serviceDataBuilder);
529 ServiceDataBuilder operDataBuilder = new ServiceDataBuilder();
530 getServiceData(siid, operDataBuilder, LogicalDatastoreType.OPERATIONAL);
532 // Set the serviceStatus based on input
533 setServiceStatus(serviceStatusBuilder, input.getSdncRequestHeader());
534 setServiceStatus(serviceStatusBuilder, input.getRequestInformation());
537 * // setup a service-data object builder // ACTION service-topology-operation
538 * // INPUT: // USES uses service-operation-information // OUTPUT: // uses
539 * topology-response-common; // uses service-response-information;
542 log.info(ADDING_INPUT_DATA_LOG, svcOperation, siid, input);
543 ServiceTopologyOperationInputBuilder inputBuilder = new ServiceTopologyOperationInputBuilder(input);
544 GenericResourceApiUtil.toProperties(parms, inputBuilder.build());
546 log.info(ADDING_OPERATIONAL_DATA_LOG, svcOperation, siid,
547 operDataBuilder.build());
548 GenericResourceApiUtil.toProperties(parms, OPERATIONAL_DATA_PARAM, operDataBuilder);
550 // Call SLI sync method
551 // Get SvcLogicService reference
553 ErrorObject error = new ErrorObject("200", "");
554 String ackFinal = "Y";
555 String serviceObjectPath = null;
556 Properties respProps = tryGetProperties(svcOperation, parms, serviceDataBuilder, error);
558 if (respProps != null) {
559 error.setStatusCode(respProps.getProperty(ERROR_CODE_PARAM));
560 error.setMessage(respProps.getProperty(ERROR_MESSAGE_PARAM));
561 ackFinal = respProps.getProperty(ACK_FINAL_PARAM, "Y");
562 serviceObjectPath = respProps.getProperty(SERVICE_OBJECT_PATH_PARAM);
565 setServiceStatus(serviceStatusBuilder, error.getStatusCode(), error.getMessage(), ackFinal);
566 serviceStatusBuilder.setRequestStatus(RequestStatus.Synccomplete);
567 serviceStatusBuilder.setRpcName(svcOperation);
569 if (validateErrorObject(error)) {
570 responseBuilder.setResponseCode(error.getStatusCode());
571 responseBuilder.setResponseMessage(error.getMessage());
572 responseBuilder.setAckFinalIndicator(ackFinal);
574 ServiceBuilder serviceBuilder = new ServiceBuilder();
575 serviceBuilder.setServiceInstanceId(siid);
576 serviceBuilder.setServiceStatus(serviceStatusBuilder.build());
578 saveService(serviceBuilder.build(), true, LogicalDatastoreType.CONFIGURATION);
579 } catch (Exception e) {
580 log.error(UPDATING_MDSAL_ERROR_MESSAGE, svcOperation, siid, e);
582 log.error(RETURNED_FAILED_MESSAGE, svcOperation, siid, responseBuilder.build());
583 RpcResult<ServiceTopologyOperationOutput> rpcResult = RpcResultBuilder
584 .<ServiceTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
585 return Futures.immediateFuture(rpcResult);
588 // Got success from SLI
590 serviceData = serviceDataBuilder.build();
591 log.info(UPDATING_MDSAL_INFO_MESSAGE, svcOperation, siid, serviceData);
594 ServiceBuilder serviceBuilder = new ServiceBuilder();
595 serviceBuilder.setServiceData(serviceData);
596 serviceBuilder.setServiceInstanceId(siid);
597 serviceBuilder.setServiceStatus(serviceStatusBuilder.build());
598 saveService(serviceBuilder.build(), false, LogicalDatastoreType.CONFIGURATION);
600 if (isValidRequest(input) && input.getSdncRequestHeader().getSvcAction().equals(SvcAction.Delete)) {
601 // Only update operational tree on delete
602 log.info("Delete from both CONFIGURATION and OPERATIONAL tree.");
603 deleteService(serviceBuilder.build(), LogicalDatastoreType.OPERATIONAL);
604 deleteService(serviceBuilder.build(), LogicalDatastoreType.CONFIGURATION);
607 ServiceResponseInformationBuilder serviceResponseInformationBuilder = new ServiceResponseInformationBuilder();
608 serviceResponseInformationBuilder.setInstanceId(siid);
609 serviceResponseInformationBuilder.setObjectPath(serviceObjectPath);
610 responseBuilder.setServiceResponseInformation(serviceResponseInformationBuilder.build());
612 } catch (Exception e) {
613 log.error(UPDATING_MDSAL_ERROR_MESSAGE, svcOperation, siid, e);
614 responseBuilder.setResponseCode("500");
615 responseBuilder.setResponseMessage(e.toString());
616 responseBuilder.setAckFinalIndicator("Y");
617 log.error(RETURNED_FAILED_MESSAGE, svcOperation, siid, responseBuilder.build());
618 RpcResult<ServiceTopologyOperationOutput> rpcResult = RpcResultBuilder
619 .<ServiceTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
620 return Futures.immediateFuture(rpcResult);
624 responseBuilder.setResponseCode(error.getStatusCode());
625 responseBuilder.setAckFinalIndicator(ackFinal);
626 if (!error.getMessage().isEmpty()) {
627 responseBuilder.setResponseMessage(error.getMessage());
629 log.info(UPDATED_MDSAL_INFO_MESSAGE, svcOperation, siid);
630 log.info(RETURNED_SUCCESS_MESSAGE, svcOperation, siid, responseBuilder.build());
632 RpcResult<ServiceTopologyOperationOutput> rpcResult = RpcResultBuilder
633 .<ServiceTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
634 return Futures.immediateFuture(rpcResult);
637 private Properties tryGetProperties(String svcOperation, Properties parms, ServiceDataBuilder serviceDataBuilder,
640 if (svcLogicClient.hasGraph(APP_NAME, svcOperation, null, "sync")) {
642 return svcLogicClient.execute(APP_NAME, svcOperation, null, "sync", serviceDataBuilder, parms);
643 } catch (Exception e) {
644 log.error(SERVICE_LOGIC_EXECUTION_ERROR_MESSAGE, svcOperation, e);
645 error.setMessage(e.getMessage());
646 error.setStatusCode("500");
649 error.setMessage(NO_SERVICE_LOGIC_ACTIVE + APP_NAME + ": '" + svcOperation + "'");
650 error.setStatusCode("503");
652 } catch (Exception e) {
653 error.setMessage(e.getMessage());
654 error.setStatusCode("500");
655 log.error(SERVICE_LOGIC_SEARCH_ERROR_MESSAGE, e);
661 private boolean validateErrorObject(ErrorObject error) {
663 !error.getStatusCode().isEmpty() && !("0".equals(error.getStatusCode()) || "200".equals(error.getStatusCode()));
666 private boolean isValidRequest(ServiceTopologyOperationInput input){
667 return input.getSdncRequestHeader() != null && input.getSdncRequestHeader().getSvcAction() != null;
671 public Future<RpcResult<VnfTopologyOperationOutput>> vnfTopologyOperation(VnfTopologyOperationInput input) {
673 final String svcOperation = "vnf-topology-operation";
674 ServiceData serviceData;
675 ServiceStatusBuilder serviceStatusBuilder = new ServiceStatusBuilder();
676 Properties parms = new Properties();
678 log.info(CALLED_STR, svcOperation);
679 // create a new response object
680 VnfTopologyOperationOutputBuilder responseBuilder = new VnfTopologyOperationOutputBuilder();
682 if (input == null || input.getServiceInformation() == null
683 || input.getServiceInformation().getServiceInstanceId() == null
684 || input.getServiceInformation().getServiceInstanceId().length() == 0) {
685 log.debug(NULL_OR_EMPTY_ERROR_MESSAGE, svcOperation);
686 responseBuilder.setResponseCode("404");
687 responseBuilder.setResponseMessage(NULL_OR_EMPTY_ERROR_PARAM);
688 responseBuilder.setAckFinalIndicator("Y");
689 RpcResult<VnfTopologyOperationOutput> rpcResult = RpcResultBuilder.<VnfTopologyOperationOutput>status(true)
690 .withResult(responseBuilder.build()).build();
692 return Futures.immediateFuture(rpcResult);
695 // Grab the service instance ID from the input buffer
696 String siid = input.getServiceInformation().getServiceInstanceId();
698 if (input.getSdncRequestHeader() != null) {
699 responseBuilder.setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId());
702 if (input.getVnfInformation() == null || input.getVnfInformation().getVnfId() == null
703 || input.getVnfInformation().getVnfId().length() == 0) {
704 log.debug("exiting {} because of null or empty vnf-id", svcOperation);
705 responseBuilder.setResponseCode("404");
706 responseBuilder.setResponseMessage("invalid input, null or empty vnf-id");
707 responseBuilder.setAckFinalIndicator("Y");
708 RpcResult<VnfTopologyOperationOutput> rpcResult = RpcResultBuilder.<VnfTopologyOperationOutput>status(true)
709 .withResult(responseBuilder.build()).build();
710 return Futures.immediateFuture(rpcResult);
713 ServiceDataBuilder serviceDataBuilder = new ServiceDataBuilder();
714 getServiceData(siid, serviceDataBuilder);
716 ServiceDataBuilder operDataBuilder = new ServiceDataBuilder();
717 getServiceData(siid, operDataBuilder, LogicalDatastoreType.OPERATIONAL);
719 // Set the serviceStatus based on input
720 setServiceStatus(serviceStatusBuilder, input.getSdncRequestHeader());
721 setServiceStatus(serviceStatusBuilder, input.getRequestInformation());
724 // setup a service-data object builder
725 // ACTION vnf-topology-operation
727 // USES sdnc-request-header;
728 // USES request-information;
729 // USES service-information;
730 // USES vnf-request-information
732 // USES vnf-topology-response-body;
733 // USES vnf-information
734 // USES service-information
736 // container service-data
737 // uses vnf-configuration-information;
740 log.info(ADDING_INPUT_DATA_LOG, svcOperation, siid, input);
741 VnfTopologyOperationInputBuilder inputBuilder = new VnfTopologyOperationInputBuilder(input);
742 GenericResourceApiUtil.toProperties(parms, inputBuilder.build());
744 log.info(ADDING_OPERATIONAL_DATA_LOG, svcOperation, siid,
745 operDataBuilder.build());
746 GenericResourceApiUtil.toProperties(parms, OPERATIONAL_DATA_PARAM, operDataBuilder);
748 // Call SLI sync method
749 // Get SvcLogicService reference
752 ErrorObject error = new ErrorObject("200", "");
753 String ackFinal = "Y";
754 String serviceObjectPath = null;
755 Properties respProps = tryGetProperties(svcOperation, parms, serviceDataBuilder, error);
757 if (respProps != null) {
758 error.setMessage(respProps.getProperty(ERROR_MESSAGE_PARAM));
759 error.setStatusCode(respProps.getProperty(ERROR_CODE_PARAM));
760 ackFinal = respProps.getProperty(ACK_FINAL_PARAM, "Y");
761 serviceObjectPath = respProps.getProperty("vnf-object-path");
764 setServiceStatus(serviceStatusBuilder, error.getStatusCode(), error.getMessage(), ackFinal);
765 serviceStatusBuilder.setRequestStatus(RequestStatus.Synccomplete);
766 serviceStatusBuilder.setRpcName(svcOperation);
768 if (validateErrorObject(error)) {
769 responseBuilder.setResponseCode(error.getStatusCode());
770 responseBuilder.setResponseMessage(error.getMessage());
771 responseBuilder.setAckFinalIndicator(ackFinal);
773 ServiceBuilder serviceBuilder = new ServiceBuilder();
774 serviceBuilder.setServiceInstanceId(siid);
775 serviceBuilder.setServiceStatus(serviceStatusBuilder.build());
777 saveService(serviceBuilder.build(), true, LogicalDatastoreType.CONFIGURATION);
778 if (isValidRequest(input) &&
779 (input.getSdncRequestHeader().getSvcAction().equals(SvcAction.Delete) ||
780 input.getSdncRequestHeader().getSvcAction().equals(SvcAction.Activate))) {
782 // Only update operational tree on activate or delete
783 log.info(UPDATING_TREE_INFO_MESSAGE);
784 saveService(serviceBuilder.build(), false, LogicalDatastoreType.OPERATIONAL);
786 } catch (Exception e) {
787 log.error(UPDATING_MDSAL_ERROR_MESSAGE, svcOperation, siid, e);
789 log.error(RETURNED_FAILED_MESSAGE, svcOperation, siid, responseBuilder.build());
790 RpcResult<VnfTopologyOperationOutput> rpcResult = RpcResultBuilder.<VnfTopologyOperationOutput>status(true)
791 .withResult(responseBuilder.build()).build();
793 return Futures.immediateFuture(rpcResult);
796 // Got success from SLI
798 serviceData = serviceDataBuilder.build();
799 log.info(UPDATING_MDSAL_INFO_MESSAGE, svcOperation, siid, serviceData);
802 ServiceBuilder serviceBuilder = new ServiceBuilder();
803 serviceBuilder.setServiceData(serviceData);
804 serviceBuilder.setServiceInstanceId(siid);
805 serviceBuilder.setServiceStatus(serviceStatusBuilder.build());
806 saveService(serviceBuilder.build(), false, LogicalDatastoreType.CONFIGURATION);
808 if (isValidRequest(input) && input.getSdncRequestHeader().getSvcAction().equals(SvcAction.Activate) ) {
809 // Only update operational tree on Assign
811 log.info(UPDATING_TREE_INFO_MESSAGE);
812 saveService(serviceBuilder.build(), false, LogicalDatastoreType.OPERATIONAL);
815 ServiceResponseInformationBuilder serviceResponseInformationBuilder = new ServiceResponseInformationBuilder();
816 serviceResponseInformationBuilder.setInstanceId(siid);
817 serviceResponseInformationBuilder.setObjectPath(serviceObjectPath);
818 responseBuilder.setServiceResponseInformation(serviceResponseInformationBuilder.build());
820 } catch (Exception e) {
821 log.error(UPDATING_MDSAL_ERROR_MESSAGE, svcOperation, siid, e);
822 responseBuilder.setResponseCode("500");
823 responseBuilder.setResponseMessage(e.toString());
824 responseBuilder.setAckFinalIndicator("Y");
825 log.error(RETURNED_FAILED_MESSAGE, svcOperation, siid, responseBuilder.build());
826 RpcResult<VnfTopologyOperationOutput> rpcResult = RpcResultBuilder.<VnfTopologyOperationOutput>status(true)
827 .withResult(responseBuilder.build()).build();
828 return Futures.immediateFuture(rpcResult);
832 responseBuilder.setResponseCode(error.getStatusCode());
833 responseBuilder.setAckFinalIndicator(ackFinal);
834 if (!error.getMessage().isEmpty()) {
835 responseBuilder.setResponseMessage(error.getMessage());
837 log.info(UPDATED_MDSAL_INFO_MESSAGE, svcOperation, siid);
838 log.info(RETURNED_SUCCESS_MESSAGE, svcOperation, siid, responseBuilder.build());
840 RpcResult<VnfTopologyOperationOutput> rpcResult = RpcResultBuilder.<VnfTopologyOperationOutput>status(true)
841 .withResult(responseBuilder.build()).build();
843 return Futures.immediateFuture(rpcResult);
846 private boolean isValidRequest(VnfTopologyOperationInput input){
847 return input.getSdncRequestHeader() != null && input.getSdncRequestHeader().getSvcAction() != null;
851 public Future<RpcResult<VfModuleTopologyOperationOutput>> vfModuleTopologyOperation(
852 VfModuleTopologyOperationInput input) {
854 final String svcOperation = "vf-module-topology-operation";
855 ServiceData serviceData;
856 ServiceStatusBuilder serviceStatusBuilder = new ServiceStatusBuilder();
857 Properties parms = new Properties();
859 log.info(CALLED_STR, svcOperation);
860 // create a new response object
861 VfModuleTopologyOperationOutputBuilder responseBuilder = new VfModuleTopologyOperationOutputBuilder();
863 if (input == null || input.getServiceInformation() == null
864 || input.getServiceInformation().getServiceInstanceId() == null
865 || input.getServiceInformation().getServiceInstanceId().length() == 0) {
866 log.debug(NULL_OR_EMPTY_ERROR_MESSAGE, svcOperation);
867 responseBuilder.setResponseCode("403");
868 responseBuilder.setResponseMessage(NULL_OR_EMPTY_ERROR_PARAM);
869 responseBuilder.setAckFinalIndicator("Y");
870 RpcResult<VfModuleTopologyOperationOutput> rpcResult = RpcResultBuilder
871 .<VfModuleTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
873 return Futures.immediateFuture(rpcResult);
876 if (input.getVnfInformation() == null || input.getVnfInformation().getVnfId() == null
877 || input.getVnfInformation().getVnfId().length() == 0) {
878 log.debug("exiting {} because of null or empty vnf-id", svcOperation);
879 responseBuilder.setResponseCode("403");
880 responseBuilder.setResponseMessage("invalid input, null or empty vnf-id");
881 responseBuilder.setAckFinalIndicator("Y");
882 RpcResult<VfModuleTopologyOperationOutput> rpcResult = RpcResultBuilder
883 .<VfModuleTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
884 return Futures.immediateFuture(rpcResult);
887 if (input.getVfModuleInformation() == null || input.getVfModuleInformation().getVfModuleId() == null
888 || input.getVfModuleInformation().getVfModuleId().length() == 0) {
889 log.debug("exiting {} because of null or empty vf-module-id", svcOperation);
890 responseBuilder.setResponseCode("403");
891 responseBuilder.setResponseMessage("invalid input, vf-module-id is null or empty");
892 responseBuilder.setAckFinalIndicator("Y");
893 RpcResult<VfModuleTopologyOperationOutput> rpcResult = RpcResultBuilder
894 .<VfModuleTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
895 return Futures.immediateFuture(rpcResult);
898 // Grab the service instance ID from the input buffer
899 String siid = input.getServiceInformation().getServiceInstanceId();
901 if (input.getSdncRequestHeader() != null) {
902 responseBuilder.setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId());
905 ServiceDataBuilder serviceDataBuilder = new ServiceDataBuilder();
906 getServiceData(siid, serviceDataBuilder);
908 ServiceDataBuilder operDataBuilder = new ServiceDataBuilder();
909 getServiceData(siid, operDataBuilder, LogicalDatastoreType.OPERATIONAL);
911 // Set the serviceStatus based on input
912 setServiceStatus(serviceStatusBuilder, input.getSdncRequestHeader());
913 setServiceStatus(serviceStatusBuilder, input.getRequestInformation());
916 // setup a service-data object builder
917 // ACTION vnf-topology-operation
919 // USES sdnc-request-header;
920 // USES request-information;
921 // USES service-information;
922 // USES vnf-request-information
924 // USES vnf-topology-response-body;
925 // USES vnf-information
926 // USES service-information
928 // container service-data
929 // uses vnf-configuration-information;
932 log.info(ADDING_INPUT_DATA_LOG, svcOperation, siid, input);
933 VfModuleTopologyOperationInputBuilder inputBuilder = new VfModuleTopologyOperationInputBuilder(input);
934 GenericResourceApiUtil.toProperties(parms, inputBuilder.build());
936 log.info(ADDING_OPERATIONAL_DATA_LOG, svcOperation, siid,
937 operDataBuilder.build());
938 GenericResourceApiUtil.toProperties(parms, OPERATIONAL_DATA_PARAM, operDataBuilder);
940 // Call SLI sync method
941 // Get SvcLogicService reference
943 ErrorObject error = new ErrorObject("200", "");
944 String ackFinal = "Y";
945 String serviceObjectPath = null;
946 Properties respProps = tryGetProperties(svcOperation, parms, serviceDataBuilder, error);
948 if (respProps != null) {
949 error.setStatusCode(respProps.getProperty(ERROR_CODE_PARAM));
950 error.setMessage(respProps.getProperty(ERROR_MESSAGE_PARAM));
951 ackFinal = respProps.getProperty(ACK_FINAL_PARAM, "Y");
952 serviceObjectPath = respProps.getProperty("vf-module-object-path");
955 setServiceStatus(serviceStatusBuilder, error.getStatusCode(), error.getMessage(), ackFinal);
956 serviceStatusBuilder.setRequestStatus(RequestStatus.Synccomplete);
957 serviceStatusBuilder.setRpcName(svcOperation);
959 if (validateErrorObject(error)) {
960 responseBuilder.setResponseCode(error.getStatusCode());
961 responseBuilder.setResponseMessage(error.getStatusCode());
962 responseBuilder.setAckFinalIndicator(ackFinal);
964 ServiceBuilder serviceBuilder = new ServiceBuilder();
965 serviceBuilder.setServiceInstanceId(siid);
966 serviceBuilder.setServiceStatus(serviceStatusBuilder.build());
968 saveService(serviceBuilder.build(), true, LogicalDatastoreType.CONFIGURATION);
969 } catch (Exception e) {
970 log.error(UPDATING_MDSAL_ERROR_MESSAGE, svcOperation, siid, e);
972 log.error(RETURNED_FAILED_MESSAGE, svcOperation, siid, responseBuilder.build());
973 RpcResult<VfModuleTopologyOperationOutput> rpcResult = RpcResultBuilder
974 .<VfModuleTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
976 return Futures.immediateFuture(rpcResult);
979 // Got success from SLI
981 serviceData = serviceDataBuilder.build();
982 log.info(UPDATING_MDSAL_INFO_MESSAGE, svcOperation, siid, serviceData);
985 ServiceBuilder serviceBuilder = new ServiceBuilder();
986 serviceBuilder.setServiceData(serviceData);
987 serviceBuilder.setServiceInstanceId(siid);
988 serviceBuilder.setServiceStatus(serviceStatusBuilder.build());
989 saveService(serviceBuilder.build(), false, LogicalDatastoreType.CONFIGURATION);
991 if (isValidRequest(input) &&
992 (input.getSdncRequestHeader().getSvcAction().equals(SvcAction.Unassign) ||
993 input.getSdncRequestHeader().getSvcAction().equals(SvcAction.Activate))) {
994 // Only update operational tree on activate or delete
996 log.info(UPDATING_TREE_INFO_MESSAGE);
997 saveService(serviceBuilder.build(), false, LogicalDatastoreType.OPERATIONAL);
1000 ServiceResponseInformationBuilder serviceResponseInformationBuilder = new ServiceResponseInformationBuilder();
1001 serviceResponseInformationBuilder.setInstanceId(siid);
1002 serviceResponseInformationBuilder.setObjectPath(serviceObjectPath);
1003 responseBuilder.setServiceResponseInformation(serviceResponseInformationBuilder.build());
1005 } catch (Exception e) {
1006 log.error(UPDATING_MDSAL_ERROR_MESSAGE, svcOperation, siid, e);
1007 responseBuilder.setResponseCode("500");
1008 responseBuilder.setResponseMessage(e.toString());
1009 responseBuilder.setAckFinalIndicator("Y");
1010 log.error(RETURNED_FAILED_MESSAGE, svcOperation, siid, responseBuilder.build());
1011 RpcResult<VfModuleTopologyOperationOutput> rpcResult = RpcResultBuilder
1012 .<VfModuleTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1013 return Futures.immediateFuture(rpcResult);
1017 responseBuilder.setResponseCode(error.getStatusCode());
1018 responseBuilder.setAckFinalIndicator(ackFinal);
1019 if (!error.getMessage().isEmpty()) {
1020 responseBuilder.setResponseMessage(error.getMessage());
1022 log.info(UPDATED_MDSAL_INFO_MESSAGE, svcOperation, siid);
1023 log.info(RETURNED_SUCCESS_MESSAGE, svcOperation, siid, responseBuilder.build());
1025 RpcResult<VfModuleTopologyOperationOutput> rpcResult = RpcResultBuilder
1026 .<VfModuleTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1028 return Futures.immediateFuture(rpcResult);
1031 private boolean isValidRequest(VfModuleTopologyOperationInput input) {
1032 return input.getSdncRequestHeader() != null && input.getSdncRequestHeader().getSvcAction() != null;
1036 public Future<RpcResult<NetworkTopologyOperationOutput>> networkTopologyOperation(
1037 NetworkTopologyOperationInput input) {
1039 final String svcOperation = "network-topology-operation";
1040 ServiceData serviceData;
1041 ServiceStatusBuilder serviceStatusBuilder = new ServiceStatusBuilder();
1042 Properties parms = new Properties();
1044 log.info(CALLED_STR, svcOperation);
1045 // create a new response object
1046 NetworkTopologyOperationOutputBuilder responseBuilder = new NetworkTopologyOperationOutputBuilder();
1048 if (input == null || input.getServiceInformation() == null
1049 || input.getServiceInformation().getServiceInstanceId() == null
1050 || input.getServiceInformation().getServiceInstanceId().length() == 0) {
1051 log.debug(NULL_OR_EMPTY_ERROR_MESSAGE, svcOperation);
1052 return buildRpcResultFuture(responseBuilder, NULL_OR_EMPTY_ERROR_PARAM);
1055 String siid = input.getServiceInformation().getServiceInstanceId();
1057 // Get the service-instance service data from MD-SAL
1058 ServiceDataBuilder serviceDataBuilder = new ServiceDataBuilder();
1059 getServiceData(siid, serviceDataBuilder);
1061 if (input.getSdncRequestHeader() != null) {
1062 responseBuilder.setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId());
1065 ServiceData sd = serviceDataBuilder.build();
1066 if (sd == null || sd.getServiceLevelOperStatus() == null) {
1067 log.debug(EMPTY_SERVICE_INSTANCE_MESSAGE, svcOperation);
1068 return buildRpcResultFuture(responseBuilder, INVALID_INPUT_ERROR_MESSAGE);
1071 log.info(ADDING_INPUT_DATA_LOG, svcOperation, siid, input);
1072 NetworkTopologyOperationInputBuilder inputBuilder = new NetworkTopologyOperationInputBuilder(input);
1073 GenericResourceApiUtil.toProperties(parms, inputBuilder.build());
1075 // Call SLI sync method
1076 // Get SvcLogicService reference
1079 ErrorObject error = new ErrorObject("200", "");
1080 String ackFinal = "Y";
1081 String networkId = ERROR_NETWORK_ID;
1082 String serviceObjectPath = null;
1083 String networkObjectPath = null;
1084 Properties respProps = tryGetProperties(svcOperation, parms, serviceDataBuilder, error);
1086 if (respProps != null) {
1087 error.setStatusCode(respProps.getProperty(ERROR_CODE_PARAM));
1088 error.setMessage(respProps.getProperty(ERROR_MESSAGE_PARAM));
1089 ackFinal = respProps.getProperty(ACK_FINAL_PARAM, "Y");
1090 networkId = respProps.getProperty("networkId");
1091 serviceObjectPath = respProps.getProperty(SERVICE_OBJECT_PATH_PARAM);
1092 networkObjectPath = respProps.getProperty("network-object-path");
1095 if (validateErrorObject(error)) {
1096 responseBuilder.setResponseCode(error.getStatusCode());
1097 responseBuilder.setResponseMessage(error.getMessage());
1098 responseBuilder.setAckFinalIndicator(ackFinal);
1100 log.error(RETURNED_FAILED_MESSAGE, svcOperation, siid, responseBuilder.build());
1102 RpcResult<NetworkTopologyOperationOutput> rpcResult = RpcResultBuilder
1103 .<NetworkTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1104 return Futures.immediateFuture(rpcResult);
1107 // Got success from SLI
1110 serviceData = serviceDataBuilder.build();
1111 log.info(UPDATING_MDSAL_INFO_MESSAGE, svcOperation, siid, serviceData);
1114 ServiceBuilder serviceBuilder = new ServiceBuilder();
1115 serviceBuilder.setServiceData(serviceData);
1116 serviceBuilder.setServiceInstanceId(siid);
1117 serviceBuilder.setServiceStatus(serviceStatusBuilder.build());
1118 saveService(serviceBuilder.build(), false, LogicalDatastoreType.CONFIGURATION);
1120 if (isValidRequest(input) &&
1121 (input.getSdncRequestHeader().getSvcAction().equals(SvcAction.Activate) ||
1122 input.getSdncRequestHeader().getSvcAction().equals(SvcAction.Create))) {
1123 // Only update operational tree on Activate
1124 log.info(UPDATING_TREE_INFO_MESSAGE);
1125 saveService(serviceBuilder.build(), false, LogicalDatastoreType.OPERATIONAL);
1128 NetworkResponseInformationBuilder networkResponseInformationBuilder = new NetworkResponseInformationBuilder();
1129 networkResponseInformationBuilder.setInstanceId(networkId);
1130 networkResponseInformationBuilder.setObjectPath(networkObjectPath);
1131 responseBuilder.setNetworkResponseInformation(networkResponseInformationBuilder.build());
1133 ServiceResponseInformationBuilder serviceResponseInformationBuilder = new ServiceResponseInformationBuilder();
1134 serviceResponseInformationBuilder.setInstanceId(siid);
1135 serviceResponseInformationBuilder.setObjectPath(serviceObjectPath);
1136 responseBuilder.setServiceResponseInformation(serviceResponseInformationBuilder.build());
1138 } catch (IllegalStateException e) {
1139 log.error(UPDATING_MDSAL_ERROR_MESSAGE, svcOperation, siid, e);
1140 responseBuilder.setResponseCode("500");
1141 responseBuilder.setResponseMessage(e.toString());
1142 responseBuilder.setAckFinalIndicator("Y");
1143 log.error(RETURNED_FAILED_MESSAGE, svcOperation, siid, responseBuilder.build());
1144 RpcResult<NetworkTopologyOperationOutput> rpcResult = RpcResultBuilder
1145 .<NetworkTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1146 return Futures.immediateFuture(rpcResult);
1150 responseBuilder.setResponseCode(error.getStatusCode());
1151 responseBuilder.setAckFinalIndicator(ackFinal);
1152 if (!error.getMessage().isEmpty()) {
1153 responseBuilder.setResponseMessage(error.getMessage());
1155 log.info(UPDATED_MDSAL_INFO_MESSAGE, svcOperation, siid);
1156 log.info(RETURNED_SUCCESS_MESSAGE, svcOperation, siid, responseBuilder.build());
1158 RpcResult<NetworkTopologyOperationOutput> rpcResult = RpcResultBuilder
1159 .<NetworkTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1160 return Futures.immediateFuture(rpcResult);
1163 private Future<RpcResult<NetworkTopologyOperationOutput>> buildRpcResultFuture(
1164 NetworkTopologyOperationOutputBuilder responseBuilder, String responseMessage) {
1166 responseBuilder.setResponseCode("404");
1168 .setResponseMessage(responseMessage);
1169 responseBuilder.setAckFinalIndicator("Y");
1170 RpcResult<NetworkTopologyOperationOutput> rpcResult = RpcResultBuilder
1171 .<NetworkTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1172 return Futures.immediateFuture(rpcResult);
1175 private boolean isValidRequest(NetworkTopologyOperationInput input) {
1176 return input.getSdncRequestHeader() != null && input.getSdncRequestHeader().getSvcAction() != null;
1180 public Future<RpcResult<ContrailRouteTopologyOperationOutput>> contrailRouteTopologyOperation(
1181 ContrailRouteTopologyOperationInput input) {
1183 final String svcOperation = "contrail-route-topology-operation";
1184 ServiceData serviceData;
1185 ServiceStatusBuilder serviceStatusBuilder = new ServiceStatusBuilder();
1186 Properties parms = new Properties();
1188 log.info(CALLED_STR, svcOperation);
1189 // create a new response object
1190 ContrailRouteTopologyOperationOutputBuilder responseBuilder = new ContrailRouteTopologyOperationOutputBuilder();
1192 if (input == null || input.getServiceInformation() == null
1193 || input.getServiceInformation().getServiceInstanceId() == null
1194 || input.getServiceInformation().getServiceInstanceId().length() == 0) {
1195 log.debug(NULL_OR_EMPTY_ERROR_MESSAGE, svcOperation);
1196 return buildRpcResultFuture(responseBuilder, NULL_OR_EMPTY_ERROR_PARAM);
1199 String siid = input.getServiceInformation().getServiceInstanceId();
1201 // Get the service-instance service data from MD-SAL
1202 ServiceDataBuilder serviceDataBuilder = new ServiceDataBuilder();
1203 getServiceData(siid, serviceDataBuilder);
1205 if (input.getSdncRequestHeader() != null) {
1206 responseBuilder.setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId());
1209 ServiceData sd = serviceDataBuilder.build();
1210 if (sd == null || sd.getServiceLevelOperStatus() == null) {
1211 log.debug(EMPTY_SERVICE_INSTANCE_MESSAGE, svcOperation);
1212 return buildRpcResultFuture(responseBuilder, INVALID_INPUT_ERROR_MESSAGE);
1215 log.info("Adding INPUT data for " + svcOperation + " [" + siid + "] input: " + input);
1216 ContrailRouteTopologyOperationInputBuilder inputBuilder = new ContrailRouteTopologyOperationInputBuilder(input);
1217 GenericResourceApiUtil.toProperties(parms, inputBuilder.build());
1219 // Call SLI sync method
1220 // Get SvcLogicService reference
1221 ErrorObject error = new ErrorObject("200", "");
1222 String ackFinal = "Y";
1223 String allottedResourceId = ERROR_NETWORK_ID;
1224 String serviceObjectPath = null;
1225 String contrailRouteObjectPath = null;
1226 Properties respProps = tryGetProperties(svcOperation, parms, serviceDataBuilder, error);
1228 if (respProps != null) {
1229 error.setStatusCode(respProps.getProperty(ERROR_CODE_PARAM));
1230 error.setMessage(respProps.getProperty(ERROR_MESSAGE_PARAM));
1231 ackFinal = respProps.getProperty(ACK_FINAL_PARAM, "Y");
1232 allottedResourceId = respProps.getProperty(ALLOTTED_RESOURCE_ID_PARAM);
1233 serviceObjectPath = respProps.getProperty(SERVICE_OBJECT_PATH_PARAM);
1234 contrailRouteObjectPath = respProps.getProperty("contrail-route-object-path");
1237 if (validateErrorObject(error)) {
1238 responseBuilder.setResponseCode(error.getStatusCode());
1239 responseBuilder.setResponseMessage(error.getMessage());
1240 responseBuilder.setAckFinalIndicator(ackFinal);
1242 log.error(RETURNED_FAILED_MESSAGE, svcOperation, siid, responseBuilder.build());
1244 RpcResult<ContrailRouteTopologyOperationOutput> rpcResult = RpcResultBuilder
1245 .<ContrailRouteTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1246 return Futures.immediateFuture(rpcResult);
1249 // Got success from SLI
1252 serviceData = serviceDataBuilder.build();
1253 log.info(UPDATING_MDSAL_INFO_MESSAGE, svcOperation, siid, serviceData);
1256 ServiceBuilder serviceBuilder = new ServiceBuilder();
1257 serviceBuilder.setServiceData(serviceData);
1258 serviceBuilder.setServiceInstanceId(siid);
1259 serviceBuilder.setServiceStatus(serviceStatusBuilder.build());
1260 saveService(serviceBuilder.build(), false, LogicalDatastoreType.CONFIGURATION);
1262 if (isValidRequest(input) &&
1263 (input.getSdncRequestHeader().getSvcAction().equals(SvcAction.Unassign) ||
1264 input.getSdncRequestHeader().getSvcAction().equals(SvcAction.Activate))) {
1265 // Only update operational tree on activate or delete
1266 log.info(UPDATING_TREE_INFO_MESSAGE);
1267 saveService(serviceBuilder.build(), false, LogicalDatastoreType.OPERATIONAL);
1270 ContrailRouteResponseInformationBuilder contrailRouteResponseInformationBuilder = new ContrailRouteResponseInformationBuilder();
1271 contrailRouteResponseInformationBuilder.setInstanceId(allottedResourceId);
1272 contrailRouteResponseInformationBuilder.setObjectPath(contrailRouteObjectPath);
1273 responseBuilder.setContrailRouteResponseInformation(contrailRouteResponseInformationBuilder.build());
1275 ServiceResponseInformationBuilder serviceResponseInformationBuilder = new ServiceResponseInformationBuilder();
1276 serviceResponseInformationBuilder.setInstanceId(siid);
1277 serviceResponseInformationBuilder.setObjectPath(serviceObjectPath);
1278 responseBuilder.setServiceResponseInformation(serviceResponseInformationBuilder.build());
1280 } catch (IllegalStateException e) {
1281 log.error(UPDATING_MDSAL_ERROR_MESSAGE, svcOperation, siid, e);
1282 responseBuilder.setResponseCode("500");
1283 responseBuilder.setResponseMessage(e.toString());
1284 responseBuilder.setAckFinalIndicator("Y");
1285 log.error(RETURNED_FAILED_MESSAGE, svcOperation, siid, responseBuilder.build());
1286 RpcResult<ContrailRouteTopologyOperationOutput> rpcResult = RpcResultBuilder
1287 .<ContrailRouteTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1288 return Futures.immediateFuture(rpcResult);
1292 responseBuilder.setResponseCode(error.getStatusCode());
1293 responseBuilder.setAckFinalIndicator(ackFinal);
1294 if (!error.getMessage().isEmpty()) {
1295 responseBuilder.setResponseMessage(error.getMessage());
1297 log.info(UPDATED_MDSAL_INFO_MESSAGE, svcOperation, siid);
1298 log.info(RETURNED_SUCCESS_MESSAGE, svcOperation, siid, responseBuilder.build());
1300 RpcResult<ContrailRouteTopologyOperationOutput> rpcResult = RpcResultBuilder
1301 .<ContrailRouteTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1302 return Futures.immediateFuture(rpcResult);
1305 private Future<RpcResult<ContrailRouteTopologyOperationOutput>>
1306 buildRpcResultFuture(ContrailRouteTopologyOperationOutputBuilder responseBuilder, String responseMessage) {
1308 responseBuilder.setResponseCode("404");
1309 responseBuilder.setResponseMessage(responseMessage);
1310 responseBuilder.setAckFinalIndicator("Y");
1312 RpcResult<ContrailRouteTopologyOperationOutput> rpcResult = RpcResultBuilder
1313 .<ContrailRouteTopologyOperationOutput>status(true)
1314 .withResult(responseBuilder.build())
1317 return Futures.immediateFuture(rpcResult);
1320 private boolean isValidRequest(ContrailRouteTopologyOperationInput input) {
1321 return input.getSdncRequestHeader() != null && input.getSdncRequestHeader().getSvcAction() != null;
1325 public Future<RpcResult<SecurityZoneTopologyOperationOutput>> securityZoneTopologyOperation(
1326 SecurityZoneTopologyOperationInput input) {
1328 final String svcOperation = "security-zone-topology-operation";
1329 ServiceData serviceData;
1330 ServiceStatusBuilder serviceStatusBuilder = new ServiceStatusBuilder();
1331 Properties parms = new Properties();
1333 log.info(CALLED_STR, svcOperation);
1334 // create a new response object
1335 SecurityZoneTopologyOperationOutputBuilder responseBuilder = new SecurityZoneTopologyOperationOutputBuilder();
1337 if (input == null || input.getServiceInformation() == null
1338 || input.getServiceInformation().getServiceInstanceId() == null
1339 || input.getServiceInformation().getServiceInstanceId().length() == 0) {
1340 log.debug(NULL_OR_EMPTY_ERROR_MESSAGE, svcOperation);
1341 return buildRpcResultFuture(responseBuilder, NULL_OR_EMPTY_ERROR_PARAM);
1344 String siid = input.getServiceInformation().getServiceInstanceId();
1346 // Get the service-instance service data from MD-SAL
1347 ServiceDataBuilder serviceDataBuilder = new ServiceDataBuilder();
1348 getServiceData(siid, serviceDataBuilder);
1350 if (input.getSdncRequestHeader() != null) {
1351 responseBuilder.setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId());
1354 ServiceData sd = serviceDataBuilder.build();
1355 if (sd == null || sd.getServiceLevelOperStatus() == null) {
1356 log.debug(EMPTY_SERVICE_INSTANCE_MESSAGE, svcOperation);
1357 return buildRpcResultFuture(responseBuilder, INVALID_INPUT_ERROR_MESSAGE);
1360 log.info(ADDING_INPUT_DATA_LOG, svcOperation, siid, input);
1361 SecurityZoneTopologyOperationInputBuilder inputBuilder = new SecurityZoneTopologyOperationInputBuilder(input);
1362 GenericResourceApiUtil.toProperties(parms, inputBuilder.build());
1364 // Call SLI sync method
1365 // Get SvcLogicService reference
1367 Properties respProps = null;
1369 ErrorObject error = new ErrorObject("200", "");
1370 String ackFinal = "Y";
1371 String allottedResourceId = ERROR_NETWORK_ID;
1372 String serviceObjectPath = null;
1373 String securityZoneObjectPath = null;
1376 if (svcLogicClient.hasGraph(APP_NAME, svcOperation, null, "sync")) {
1379 respProps = svcLogicClient.execute(APP_NAME, svcOperation, null, "sync", serviceDataBuilder, parms);
1380 } catch (Exception e) {
1381 log.error(SERVICE_LOGIC_EXECUTION_ERROR_MESSAGE, svcOperation, e);
1382 error.setMessage(e.getMessage());
1383 error.setStatusCode("500");
1386 error.setMessage(NO_SERVICE_LOGIC_ACTIVE + APP_NAME + ": '" + svcOperation + "'");
1387 error.setStatusCode("503");
1389 } catch (Exception e) {
1390 error.setStatusCode("500");
1391 error.setMessage(e.getMessage());
1392 log.error(SERVICE_LOGIC_SEARCH_ERROR_MESSAGE, e);
1395 if (respProps != null) {
1396 error.setStatusCode(respProps.getProperty(ERROR_CODE_PARAM));
1397 error.setMessage(respProps.getProperty(ERROR_MESSAGE_PARAM));
1398 ackFinal = respProps.getProperty(ACK_FINAL_PARAM, "Y");
1399 allottedResourceId = respProps.getProperty(ALLOTTED_RESOURCE_ID_PARAM);
1400 serviceObjectPath = respProps.getProperty(SERVICE_OBJECT_PATH_PARAM);
1401 securityZoneObjectPath = respProps.getProperty("security-zone-object-path");
1404 if (validateErrorObject(error)) {
1405 responseBuilder.setResponseCode(error.getStatusCode());
1406 responseBuilder.setResponseMessage(error.getMessage());
1407 responseBuilder.setAckFinalIndicator(ackFinal);
1409 log.error(RETURNED_FAILED_MESSAGE, svcOperation, siid, responseBuilder.build());
1411 RpcResult<SecurityZoneTopologyOperationOutput> rpcResult = RpcResultBuilder
1412 .<SecurityZoneTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1413 return Futures.immediateFuture(rpcResult);
1416 // Got success from SLI
1419 serviceData = serviceDataBuilder.build();
1420 log.info(UPDATING_MDSAL_INFO_MESSAGE, svcOperation, siid, serviceData);
1423 ServiceBuilder serviceBuilder = new ServiceBuilder();
1424 serviceBuilder.setServiceData(serviceData);
1425 serviceBuilder.setServiceInstanceId(siid);
1426 serviceBuilder.setServiceStatus(serviceStatusBuilder.build());
1427 saveService(serviceBuilder.build(), false, LogicalDatastoreType.CONFIGURATION);
1429 if (isValidRequest(input) &&
1430 (input.getSdncRequestHeader().getSvcAction().equals(SvcAction.Unassign) ||
1431 input.getSdncRequestHeader().getSvcAction().equals(SvcAction.Activate))) {
1432 // Only update operational tree on activate or delete
1433 log.info(UPDATING_TREE_INFO_MESSAGE);
1434 saveService(serviceBuilder.build(), false, LogicalDatastoreType.OPERATIONAL);
1437 SecurityZoneResponseInformationBuilder securityZoneResponseInformationBuilder = new SecurityZoneResponseInformationBuilder();
1438 securityZoneResponseInformationBuilder.setInstanceId(allottedResourceId);
1439 securityZoneResponseInformationBuilder.setObjectPath(securityZoneObjectPath);
1440 responseBuilder.setSecurityZoneResponseInformation(securityZoneResponseInformationBuilder.build());
1442 ServiceResponseInformationBuilder serviceResponseInformationBuilder = new ServiceResponseInformationBuilder();
1443 serviceResponseInformationBuilder.setInstanceId(siid);
1444 serviceResponseInformationBuilder.setObjectPath(serviceObjectPath);
1445 responseBuilder.setServiceResponseInformation(serviceResponseInformationBuilder.build());
1447 } catch (IllegalStateException e) {
1448 log.error(UPDATING_MDSAL_ERROR_MESSAGE, svcOperation, siid, e);
1449 responseBuilder.setResponseCode("500");
1450 responseBuilder.setResponseMessage(e.toString());
1451 responseBuilder.setAckFinalIndicator("Y");
1452 log.error(RETURNED_FAILED_MESSAGE, svcOperation, siid, responseBuilder.build());
1453 RpcResult<SecurityZoneTopologyOperationOutput> rpcResult = RpcResultBuilder
1454 .<SecurityZoneTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1455 return Futures.immediateFuture(rpcResult);
1459 responseBuilder.setResponseCode(error.getStatusCode());
1460 responseBuilder.setAckFinalIndicator(ackFinal);
1461 if (!error.getMessage().isEmpty()) {
1462 responseBuilder.setResponseMessage(error.getMessage());
1464 log.info(UPDATED_MDSAL_INFO_MESSAGE, svcOperation, siid);
1465 log.info(RETURNED_SUCCESS_MESSAGE, svcOperation, siid, responseBuilder.build());
1467 RpcResult<SecurityZoneTopologyOperationOutput> rpcResult = RpcResultBuilder
1468 .<SecurityZoneTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1469 return Futures.immediateFuture(rpcResult);
1472 private Future<RpcResult<SecurityZoneTopologyOperationOutput>>
1473 buildRpcResultFuture(SecurityZoneTopologyOperationOutputBuilder responseBuilder, String responseMessage) {
1475 responseBuilder.setResponseCode("404");
1476 responseBuilder.setResponseMessage(responseMessage);
1477 responseBuilder.setAckFinalIndicator("Y");
1479 RpcResult<SecurityZoneTopologyOperationOutput> rpcResult = RpcResultBuilder
1480 .<SecurityZoneTopologyOperationOutput>status(true)
1481 .withResult(responseBuilder.build())
1484 return Futures.immediateFuture(rpcResult);
1487 private boolean isValidRequest(SecurityZoneTopologyOperationInput input) {
1488 return input.getSdncRequestHeader() != null && input.getSdncRequestHeader().getSvcAction() != null;
1492 public Future<RpcResult<TunnelxconnTopologyOperationOutput>> tunnelxconnTopologyOperation(
1493 TunnelxconnTopologyOperationInput input) {
1495 final String svcOperation = "tunnelxconn-topology-operation";
1496 Properties parms = new Properties();
1498 log.info(CALLED_STR, svcOperation);
1499 // create a new response object
1500 TunnelxconnTopologyOperationOutputBuilder responseBuilder = new TunnelxconnTopologyOperationOutputBuilder();
1502 if (input == null || input.getServiceInformation() == null
1503 || input.getServiceInformation().getServiceInstanceId() == null
1504 || input.getServiceInformation().getServiceInstanceId().length() == 0) {
1505 log.debug(NULL_OR_EMPTY_ERROR_MESSAGE, svcOperation);
1506 responseBuilder.setResponseCode("404");
1507 responseBuilder.setResponseMessage(NULL_OR_EMPTY_ERROR_PARAM);
1508 responseBuilder.setAckFinalIndicator("Y");
1509 RpcResult<TunnelxconnTopologyOperationOutput> rpcResult = RpcResultBuilder
1510 .<TunnelxconnTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1511 return Futures.immediateFuture(rpcResult);
1514 String siid = input.getServiceInformation().getServiceInstanceId();
1516 log.info(ADDING_INPUT_DATA_LOG, svcOperation, siid, input);
1517 TunnelxconnTopologyOperationInputBuilder inputBuilder = new TunnelxconnTopologyOperationInputBuilder(input);
1518 GenericResourceApiUtil.toProperties(parms, inputBuilder.build());
1520 // Call SLI sync method
1521 // Get SvcLogicService reference
1525 ErrorObject error = new ErrorObject("200", "");
1526 String ackFinal = "Y";
1527 String allottedResourceId = ERROR_NETWORK_ID;
1528 String serviceObjectPath = null;
1529 String tunnelxconnObjectPath = null;
1530 Properties respProps = tryGetProperties(svcOperation, parms, error);
1532 if (respProps != null) {
1533 error.setStatusCode(respProps.getProperty(ERROR_CODE_PARAM));
1534 error.setMessage(respProps.getProperty(ERROR_MESSAGE_PARAM));
1535 ackFinal = respProps.getProperty(ACK_FINAL_PARAM, "Y");
1536 allottedResourceId = respProps.getProperty(ALLOTTED_RESOURCE_ID_PARAM);
1537 serviceObjectPath = respProps.getProperty(SERVICE_OBJECT_PATH_PARAM);
1538 tunnelxconnObjectPath = respProps.getProperty("tunnelxconn-object-path");
1541 if (validateErrorObject(error)) {
1542 responseBuilder.setResponseCode(error.getStatusCode());
1543 responseBuilder.setResponseMessage(error.getMessage());
1544 responseBuilder.setAckFinalIndicator(ackFinal);
1546 log.error(RETURNED_FAILED_MESSAGE, svcOperation, siid, responseBuilder.build());
1548 RpcResult<TunnelxconnTopologyOperationOutput> rpcResult = RpcResultBuilder
1549 .<TunnelxconnTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1550 return Futures.immediateFuture(rpcResult);
1553 // Got success from SLI
1558 TunnelxconnResponseInformationBuilder tunnelxconnResponseInformationBuilder = new TunnelxconnResponseInformationBuilder();
1559 tunnelxconnResponseInformationBuilder.setInstanceId(allottedResourceId);
1560 tunnelxconnResponseInformationBuilder.setObjectPath(tunnelxconnObjectPath);
1561 responseBuilder.setTunnelxconnResponseInformation(tunnelxconnResponseInformationBuilder.build());
1563 ServiceResponseInformationBuilder serviceResponseInformationBuilder = new ServiceResponseInformationBuilder();
1564 serviceResponseInformationBuilder.setInstanceId(siid);
1565 serviceResponseInformationBuilder.setObjectPath(serviceObjectPath);
1566 responseBuilder.setServiceResponseInformation(serviceResponseInformationBuilder.build());
1568 } catch (IllegalStateException e) {
1569 log.error(UPDATING_MDSAL_ERROR_MESSAGE, svcOperation, siid, e);
1570 responseBuilder.setResponseCode("500");
1571 responseBuilder.setResponseMessage(e.toString());
1572 responseBuilder.setAckFinalIndicator("Y");
1573 log.error(RETURNED_FAILED_MESSAGE, svcOperation, siid, responseBuilder.build());
1574 RpcResult<TunnelxconnTopologyOperationOutput> rpcResult = RpcResultBuilder
1575 .<TunnelxconnTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1576 return Futures.immediateFuture(rpcResult);
1580 responseBuilder.setResponseCode(error.getStatusCode());
1581 responseBuilder.setAckFinalIndicator(ackFinal);
1582 if (!error.getMessage().isEmpty()) {
1583 responseBuilder.setResponseMessage(error.getMessage());
1585 log.info(UPDATED_MDSAL_INFO_MESSAGE, svcOperation, siid);
1586 log.info(RETURNED_SUCCESS_MESSAGE, svcOperation, siid, responseBuilder.build());
1588 RpcResult<TunnelxconnTopologyOperationOutput> rpcResult = RpcResultBuilder
1589 .<TunnelxconnTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1590 return Futures.immediateFuture(rpcResult);
1593 private Properties tryGetProperties(String svcOperation, Properties parms, ErrorObject error) {
1595 if (svcLogicClient.hasGraph(APP_NAME, svcOperation, null, "sync")) {
1598 return svcLogicClient.execute(APP_NAME, svcOperation, null, "sync", parms);
1599 } catch (Exception e) {
1600 log.error(SERVICE_LOGIC_EXECUTION_ERROR_MESSAGE, svcOperation, e);
1601 error.setMessage(e.getMessage());
1602 error.setStatusCode("500");
1605 error.setMessage(NO_SERVICE_LOGIC_ACTIVE + APP_NAME + ": '" + svcOperation + "'");
1606 error.setStatusCode("503");
1608 } catch (Exception e) {
1609 error.setMessage(e.getMessage());
1610 error.setStatusCode("500");
1611 log.error(SERVICE_LOGIC_SEARCH_ERROR_MESSAGE, e);
1617 public Future<RpcResult<BrgTopologyOperationOutput>> brgTopologyOperation(BrgTopologyOperationInput input) {
1618 final String svcOperation = "brg-topology-operation";
1619 Properties parms = new Properties();
1621 log.info(CALLED_STR, svcOperation);
1622 // create a new response object
1623 BrgTopologyOperationOutputBuilder responseBuilder = new BrgTopologyOperationOutputBuilder();
1625 if (input == null || input.getServiceInformation() == null
1626 || input.getServiceInformation().getServiceInstanceId() == null
1627 || input.getServiceInformation().getServiceInstanceId().length() == 0) {
1628 log.debug(NULL_OR_EMPTY_ERROR_MESSAGE, svcOperation);
1629 responseBuilder.setResponseCode("404");
1630 responseBuilder.setResponseMessage(NULL_OR_EMPTY_ERROR_PARAM);
1631 responseBuilder.setAckFinalIndicator("Y");
1632 RpcResult<BrgTopologyOperationOutput> rpcResult = RpcResultBuilder.<BrgTopologyOperationOutput>status(true)
1633 .withResult(responseBuilder.build()).build();
1634 return Futures.immediateFuture(rpcResult);
1637 String siid = input.getServiceInformation().getServiceInstanceId();
1639 log.info(ADDING_INPUT_DATA_LOG, svcOperation, siid, input);
1640 BrgTopologyOperationInputBuilder inputBuilder = new BrgTopologyOperationInputBuilder(input);
1641 GenericResourceApiUtil.toProperties(parms, inputBuilder.build());
1643 // Call SLI sync method
1644 // Get SvcLogicService reference
1645 ErrorObject error = new ErrorObject("200", "");
1646 String ackFinal = "Y";
1647 String allottedResourceId = ERROR_NETWORK_ID;
1648 String serviceObjectPath = null;
1649 String brgObjectPath = null;
1650 Properties respProps = tryGetProperties(svcOperation, parms, error);
1652 if (respProps != null) {
1653 error.setStatusCode(respProps.getProperty(ERROR_CODE_PARAM));
1654 error.setMessage(respProps.getProperty(ERROR_MESSAGE_PARAM));
1655 ackFinal = respProps.getProperty(ACK_FINAL_PARAM, "Y");
1656 allottedResourceId = respProps.getProperty(ALLOTTED_RESOURCE_ID_PARAM);
1657 serviceObjectPath = respProps.getProperty(SERVICE_OBJECT_PATH_PARAM);
1658 brgObjectPath = respProps.getProperty("brg-object-path");
1661 if (validateErrorObject(error)) {
1662 responseBuilder.setResponseCode(error.getStatusCode());
1663 responseBuilder.setResponseMessage(error.getMessage());
1664 responseBuilder.setAckFinalIndicator(ackFinal);
1666 log.error(RETURNED_FAILED_MESSAGE, svcOperation, siid, responseBuilder.build());
1668 RpcResult<BrgTopologyOperationOutput> rpcResult = RpcResultBuilder.<BrgTopologyOperationOutput>status(true)
1669 .withResult(responseBuilder.build()).build();
1670 return Futures.immediateFuture(rpcResult);
1673 // Got success from SLI
1677 BrgResponseInformationBuilder brgResponseInformationBuilder = new BrgResponseInformationBuilder();
1678 brgResponseInformationBuilder.setInstanceId(allottedResourceId);
1679 brgResponseInformationBuilder.setObjectPath(brgObjectPath);
1680 responseBuilder.setBrgResponseInformation(brgResponseInformationBuilder.build());
1682 ServiceResponseInformationBuilder serviceResponseInformationBuilder = new ServiceResponseInformationBuilder();
1683 serviceResponseInformationBuilder.setInstanceId(siid);
1684 serviceResponseInformationBuilder.setObjectPath(serviceObjectPath);
1685 responseBuilder.setServiceResponseInformation(serviceResponseInformationBuilder.build());
1687 } catch (IllegalStateException e) {
1688 log.error(UPDATING_MDSAL_ERROR_MESSAGE, svcOperation, siid, e);
1689 responseBuilder.setResponseCode("500");
1690 responseBuilder.setResponseMessage(e.toString());
1691 responseBuilder.setAckFinalIndicator("Y");
1692 log.error(RETURNED_FAILED_MESSAGE, svcOperation, siid, responseBuilder.build());
1693 RpcResult<BrgTopologyOperationOutput> rpcResult = RpcResultBuilder.<BrgTopologyOperationOutput>status(true)
1694 .withResult(responseBuilder.build()).build();
1695 return Futures.immediateFuture(rpcResult);
1699 responseBuilder.setResponseCode(error.getStatusCode());
1700 responseBuilder.setAckFinalIndicator(ackFinal);
1701 if (!error.getMessage().isEmpty()) {
1702 responseBuilder.setResponseMessage(error.getMessage());
1704 log.info(UPDATED_MDSAL_INFO_MESSAGE, svcOperation, siid);
1705 log.info(RETURNED_SUCCESS_MESSAGE, svcOperation, siid, responseBuilder.build());
1707 RpcResult<BrgTopologyOperationOutput> rpcResult = RpcResultBuilder.<BrgTopologyOperationOutput>status(true)
1708 .withResult(responseBuilder.build()).build();
1709 return Futures.immediateFuture(rpcResult);
1713 public Future<RpcResult<PreloadVnfTopologyOperationOutput>> preloadVnfTopologyOperation(
1714 PreloadVnfTopologyOperationInput input) {
1716 final String svcOperation = "preload-vnf-topology-operation";
1717 PreloadData preloadData;
1718 Properties parms = new Properties();
1720 log.info(CALLED_STR, svcOperation);
1721 // create a new response object
1722 PreloadVnfTopologyOperationOutputBuilder responseBuilder = new PreloadVnfTopologyOperationOutputBuilder();
1724 if (input == null || input.getVnfTopologyInformation() == null
1725 || input.getVnfTopologyInformation().getVnfTopologyIdentifier() == null) {
1726 log.debug("exiting {} because of null input", svcOperation);
1727 responseBuilder.setResponseCode("403");
1728 responseBuilder.setResponseMessage("invalid input: input is null");
1729 responseBuilder.setAckFinalIndicator("Y");
1730 RpcResult<PreloadVnfTopologyOperationOutput> rpcResult = RpcResultBuilder
1731 .<PreloadVnfTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1732 return Futures.immediateFuture(rpcResult);
1735 // Grab the name and type from the input buffer
1736 String preloadName = input.getVnfTopologyInformation().getVnfTopologyIdentifier().getVnfName();
1737 String preloadType = input.getVnfTopologyInformation().getVnfTopologyIdentifier().getVnfType();
1739 // Make sure we have a preload_name and preload_type
1740 if (preloadName == null || preloadName.length() == 0 || preloadType == null || preloadType.length() == 0) {
1741 log.debug("exiting {} vnf-name or vnf-type is null or empty", svcOperation);
1742 responseBuilder.setResponseCode("403");
1743 responseBuilder.setResponseMessage("invalid input: vnf-name or vnf-type is null or empty");
1744 responseBuilder.setAckFinalIndicator("Y");
1745 RpcResult<PreloadVnfTopologyOperationOutput> rpcResult = RpcResultBuilder
1746 .<PreloadVnfTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1747 return Futures.immediateFuture(rpcResult);
1750 if (input.getSdncRequestHeader() != null) {
1751 responseBuilder.setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId());
1754 PreloadDataBuilder preloadDataBuilder = new PreloadDataBuilder();
1755 getPreloadData(preloadName, preloadType, preloadDataBuilder);
1757 PreloadDataBuilder operDataBuilder = new PreloadDataBuilder();
1758 getPreloadData(preloadName, preloadType, operDataBuilder, LogicalDatastoreType.OPERATIONAL);
1760 // setup a preload-data object builder
1761 // ACTION preload-vnf-topology-operation
1763 // USES sdnc-request-header;
1764 // USES request-information;
1765 // uses vnf-topology-information;
1767 // USES vnf-topology-response-body;
1769 // container preload-data
1770 // uses vnf-topology-information;
1771 // uses network-topology-information;
1772 // uses oper-status;
1774 log.info("Adding INPUT data for {} [{},{}] input: {}", svcOperation, preloadName, preloadType, input);
1775 PreloadVnfTopologyOperationInputBuilder inputBuilder = new PreloadVnfTopologyOperationInputBuilder(input);
1776 GenericResourceApiUtil.toProperties(parms, inputBuilder.build());
1777 log.info("Adding OPERATIONAL data for {} [{},{}] operational-data: {}", svcOperation, preloadName,
1778 preloadType, operDataBuilder.build());
1779 GenericResourceApiUtil.toProperties(parms, OPERATIONAL_DATA_PARAM, operDataBuilder);
1781 // Call SLI sync method
1782 // Get SvcLogicService reference
1783 ErrorObject error = new ErrorObject("200", "");
1784 String ackFinal = "Y";
1785 Properties respProps = tryGetProperties(svcOperation, parms, error);
1787 if (respProps != null) {
1788 error.setStatusCode(respProps.getProperty(ERROR_CODE_PARAM));
1789 error.setMessage(respProps.getProperty(ERROR_MESSAGE_PARAM));
1790 ackFinal = respProps.getProperty(ACK_FINAL_PARAM, "Y");
1793 if (validateErrorObject(error)) {
1795 responseBuilder.setResponseCode(error.getStatusCode());
1796 responseBuilder.setResponseMessage(error.getMessage());
1797 responseBuilder.setAckFinalIndicator(ackFinal);
1799 VnfPreloadListBuilder preloadVnfListBuilder = new VnfPreloadListBuilder();
1800 preloadVnfListBuilder.setVnfName(preloadName);
1801 preloadVnfListBuilder.setVnfType(preloadType);
1802 preloadVnfListBuilder.setPreloadData(preloadDataBuilder.build());
1803 log.error("Returned FAILED for {} [{},{}] error code: '{}', Reason: '{}'", svcOperation, preloadName,
1804 preloadType, error.getStatusCode(), error.getMessage());
1806 savePreloadList(preloadVnfListBuilder.build(), true, LogicalDatastoreType.CONFIGURATION);
1807 } catch (Exception e) {
1808 log.error(UPDATING_MDSAL_ERROR_MESSAGE_2, svcOperation, preloadName,
1811 log.debug("Sending Success rpc result due to external error");
1812 RpcResult<PreloadVnfTopologyOperationOutput> rpcResult = RpcResultBuilder
1813 .<PreloadVnfTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1814 return Futures.immediateFuture(rpcResult);
1817 // Got success from SLI
1819 updatePreloadData(svcOperation, preloadName, preloadType, preloadDataBuilder);
1820 } catch (Exception e) {
1821 log.error(UPDATING_MDSAL_ERROR_MESSAGE_2, svcOperation, preloadName, preloadType,
1823 responseBuilder.setResponseCode("500");
1824 responseBuilder.setResponseMessage(e.toString());
1825 responseBuilder.setAckFinalIndicator("Y");
1826 log.error("Returned FAILED for {} [{},{}] {}", svcOperation, preloadName, preloadType,
1827 responseBuilder.build());
1828 RpcResult<PreloadVnfTopologyOperationOutput> rpcResult = RpcResultBuilder
1829 .<PreloadVnfTopologyOperationOutput>status(false).withResult(responseBuilder.build()).build();
1830 return Futures.immediateFuture(rpcResult);
1834 responseBuilder.setResponseCode(error.getStatusCode());
1835 responseBuilder.setAckFinalIndicator(ackFinal);
1836 if (!error.getMessage().isEmpty()) {
1837 responseBuilder.setResponseMessage(error.getMessage());
1839 log.info("Updated MD-SAL for {} [{},{}]", svcOperation, preloadName, preloadType);
1840 log.info("Returned SUCCESS for {} [{},{}] {}", svcOperation, preloadName, preloadType,
1841 responseBuilder.build());
1843 RpcResult<PreloadVnfTopologyOperationOutput> rpcResult = RpcResultBuilder
1844 .<PreloadVnfTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1845 return Futures.immediateFuture(rpcResult);
1848 private void updatePreloadData(String svcOperation, String preloadName, String preloadType,
1849 PreloadDataBuilder preloadDataBuilder) {
1850 PreloadData preloadData;
1851 preloadData = preloadDataBuilder.build();
1852 log.info("Updating MD-SAL for {} [{},{}] preloadData: {}", svcOperation, preloadName, preloadType,
1854 // svc-configuration-list
1855 VnfPreloadListBuilder preloadVnfListBuilder = new VnfPreloadListBuilder();
1856 preloadVnfListBuilder.setVnfName(preloadName);
1857 preloadVnfListBuilder.setVnfType(preloadType);
1858 preloadVnfListBuilder.setPreloadData(preloadData);
1860 // merge flag sets to false to allow it to be overwritten (not appended)
1861 savePreloadList(preloadVnfListBuilder.build(), false, LogicalDatastoreType.CONFIGURATION);
1862 log.info(UPDATING_TREE_INFO_MESSAGE);
1863 savePreloadList(preloadVnfListBuilder.build(), false, LogicalDatastoreType.OPERATIONAL);
1867 public Future<RpcResult<PreloadNetworkTopologyOperationOutput>> preloadNetworkTopologyOperation(
1868 PreloadNetworkTopologyOperationInput input) {
1870 final String svcOperation = "preload-network-topology-operation";
1871 PreloadData preloadData;
1872 Properties parms = new Properties();
1874 log.info(CALLED_STR, svcOperation);
1875 // create a new response object
1876 PreloadNetworkTopologyOperationOutputBuilder responseBuilder = new PreloadNetworkTopologyOperationOutputBuilder();
1878 if (input == null || input.getNetworkTopologyInformation() == null
1879 || input.getNetworkTopologyInformation().getNetworkTopologyIdentifier() == null) {
1881 log.debug("exiting {} because of null input", svcOperation);
1882 responseBuilder.setResponseCode("403");
1883 responseBuilder.setResponseMessage("input is null");
1884 responseBuilder.setAckFinalIndicator("Y");
1885 RpcResult<PreloadNetworkTopologyOperationOutput> rpcResult = RpcResultBuilder
1886 .<PreloadNetworkTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1887 return Futures.immediateFuture(rpcResult);
1890 // Grab the name and type from the input buffer
1891 String preloadName = input.getNetworkTopologyInformation().getNetworkTopologyIdentifier().getNetworkName();
1892 String preloadType = input.getNetworkTopologyInformation().getNetworkTopologyIdentifier().getNetworkType();
1894 // Make sure we have a preload_name and preload_type
1895 if (preloadName == null || preloadName.length() == 0 || preloadType == null || preloadType.length() == 0) {
1896 log.debug("exiting {} because of invalid preload-name", svcOperation);
1897 responseBuilder.setResponseCode("403");
1898 responseBuilder.setResponseMessage("input, invalid preload-name");
1899 responseBuilder.setAckFinalIndicator("Y");
1900 RpcResult<PreloadNetworkTopologyOperationOutput> rpcResult = RpcResultBuilder
1901 .<PreloadNetworkTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1902 return Futures.immediateFuture(rpcResult);
1905 if (input.getSdncRequestHeader() != null) {
1906 responseBuilder.setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId());
1909 PreloadDataBuilder preloadDataBuilder = new PreloadDataBuilder();
1910 getPreloadData(preloadName, preloadType, preloadDataBuilder);
1912 PreloadDataBuilder operDataBuilder = new PreloadDataBuilder();
1913 getPreloadData(preloadName, preloadType, operDataBuilder, LogicalDatastoreType.OPERATIONAL);
1916 // setup a preload-data object builder
1917 // ACTION preload-network-topology-operation
1919 // USES sdnc-request-header;
1920 // USES request-information;
1921 // uses network-topology-information;
1923 // USES vnf-topology-response-body;
1925 // container preload-data
1926 // uses vnf-topology-information;
1927 // uses network-topology-information;
1928 // uses oper-status;
1930 log.info("Adding INPUT data for {} [{},{}] input: {}", svcOperation, preloadName, preloadType, input);
1931 PreloadNetworkTopologyOperationInputBuilder inputBuilder = new PreloadNetworkTopologyOperationInputBuilder(
1933 GenericResourceApiUtil.toProperties(parms, inputBuilder.build());
1934 log.info("Adding OPERATIONAL data for {} [{},{}] operational-data: {}", svcOperation, preloadName,
1935 preloadType, operDataBuilder.build());
1936 GenericResourceApiUtil.toProperties(parms, OPERATIONAL_DATA_PARAM, operDataBuilder);
1938 // Call SLI sync method
1939 // Get SvcLogicService reference
1940 ErrorObject error = new ErrorObject("200", "");
1941 String ackFinal = "Y";
1942 Properties respProps = tryGetProperties(svcOperation, parms, error);
1944 if (respProps != null) {
1945 error.setStatusCode(respProps.getProperty(ERROR_CODE_PARAM));
1946 error.setMessage(respProps.getProperty(ERROR_MESSAGE_PARAM));
1947 ackFinal = respProps.getProperty(ACK_FINAL_PARAM, "Y");
1950 if (validateErrorObject(error)) {
1952 responseBuilder.setResponseCode(error.getStatusCode());
1953 responseBuilder.setResponseMessage(error.getMessage());
1954 responseBuilder.setAckFinalIndicator(ackFinal);
1956 VnfPreloadListBuilder preloadVnfListBuilder = new VnfPreloadListBuilder();
1957 preloadVnfListBuilder.setVnfName(preloadName);
1958 preloadVnfListBuilder.setVnfType(preloadType);
1959 preloadVnfListBuilder.setPreloadData(preloadDataBuilder.build());
1960 log.error("Returned FAILED for {} [{},{}] error code: '{}', Reason: '{}'", svcOperation, preloadName,
1961 preloadType, error.getStatusCode(), error.getMessage());
1963 savePreloadList(preloadVnfListBuilder.build(), true, LogicalDatastoreType.CONFIGURATION);
1964 } catch (Exception e) {
1965 log.error(UPDATING_MDSAL_ERROR_MESSAGE_2, svcOperation, preloadName,
1969 log.debug("Sending Success rpc result due to external error");
1970 RpcResult<PreloadNetworkTopologyOperationOutput> rpcResult = RpcResultBuilder
1971 .<PreloadNetworkTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1972 return Futures.immediateFuture(rpcResult);
1975 // Got success from SLI
1977 updatePreloadData(svcOperation, preloadName, preloadType, preloadDataBuilder);
1978 } catch (Exception e) {
1979 log.error(UPDATING_MDSAL_ERROR_MESSAGE_2, svcOperation, preloadName, preloadType, e);
1980 responseBuilder.setResponseCode("500");
1981 responseBuilder.setResponseMessage(e.toString());
1982 responseBuilder.setAckFinalIndicator("Y");
1983 log.error("Returned FAILED for {} [{},{}] {}", svcOperation, preloadName, preloadType,
1984 responseBuilder.build());
1985 RpcResult<PreloadNetworkTopologyOperationOutput> rpcResult = RpcResultBuilder
1986 .<PreloadNetworkTopologyOperationOutput>status(false).withResult(responseBuilder.build()).build();
1987 return Futures.immediateFuture(rpcResult);
1991 responseBuilder.setResponseCode(error.getStatusCode());
1992 responseBuilder.setAckFinalIndicator(ackFinal);
1993 if (!error.getMessage().isEmpty()) {
1994 responseBuilder.setResponseMessage(error.getMessage());
1996 log.info("Updated MD-SAL for {} [{},{}]", svcOperation, preloadName, preloadType);
1997 log.info("Returned SUCCESS for {} [{},{}] {}", svcOperation, preloadName, preloadType,
1998 responseBuilder.build());
2000 RpcResult<PreloadNetworkTopologyOperationOutput> rpcResult = RpcResultBuilder
2001 .<PreloadNetworkTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
2002 return Futures.immediateFuture(rpcResult);