Roll versions for Frankfurt
[sdnc/northbound.git] / vnfapi / provider / src / main / java / org / onap / sdnc / vnfapi / vnfapiProvider.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * openECOMP : SDN-C
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                                                      reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *      http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.sdnc.vnfapi;
23
24 import com.google.common.base.Optional;
25 import com.google.common.util.concurrent.CheckedFuture;
26 import com.google.common.util.concurrent.FutureCallback;
27 import com.google.common.util.concurrent.Futures;
28 import com.google.common.util.concurrent.SettableFuture;
29 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
30 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
31 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
32 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
33 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
34 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
35 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
36 import org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException;
37 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
38 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
39 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
40 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.NetworkTopologyOperationInput;
41 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.NetworkTopologyOperationInputBuilder;
42 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.NetworkTopologyOperationOutput;
43 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.NetworkTopologyOperationOutputBuilder;
44 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.PreloadNetworkTopologyOperationInput;
45 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.PreloadNetworkTopologyOperationInputBuilder;
46 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.PreloadNetworkTopologyOperationOutput;
47 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.PreloadNetworkTopologyOperationOutputBuilder;
48 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.PreloadVfModuleTopologyOperationInput;
49 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.PreloadVfModuleTopologyOperationInputBuilder;
50 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.PreloadVfModuleTopologyOperationOutput;
51 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.PreloadVfModuleTopologyOperationOutputBuilder;
52 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.PreloadVfModules;
53 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.PreloadVfModulesBuilder;
54 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.PreloadVnfInstanceTopologyOperationInput;
55 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.PreloadVnfInstanceTopologyOperationInputBuilder;
56 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.PreloadVnfInstanceTopologyOperationOutput;
57 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.PreloadVnfInstanceTopologyOperationOutputBuilder;
58 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.PreloadVnfInstances;
59 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.PreloadVnfInstancesBuilder;
60 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.PreloadVnfTopologyOperationInput;
61 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.PreloadVnfTopologyOperationInputBuilder;
62 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.PreloadVnfTopologyOperationOutput;
63 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.PreloadVnfTopologyOperationOutputBuilder;
64 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.PreloadVnfs;
65 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.PreloadVnfsBuilder;
66 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VNFAPIService;
67 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VfModuleTopologyOperationInput;
68 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VfModuleTopologyOperationInputBuilder;
69 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VfModuleTopologyOperationOutput;
70 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VfModuleTopologyOperationOutputBuilder;
71 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VfModules;
72 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VfModulesBuilder;
73 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VnfInstanceTopologyOperationInput;
74 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VnfInstanceTopologyOperationInputBuilder;
75 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VnfInstanceTopologyOperationOutput;
76 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VnfInstanceTopologyOperationOutputBuilder;
77 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VnfInstances;
78 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VnfInstancesBuilder;
79 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VnfTopologyOperationInput;
80 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VnfTopologyOperationInputBuilder;
81 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VnfTopologyOperationOutput;
82 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VnfTopologyOperationOutputBuilder;
83 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.Vnfs;
84 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.VnfsBuilder;
85 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.network.information.NetworkInformationBuilder;
86 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.preload.data.PreloadData;
87 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.preload.data.PreloadDataBuilder;
88 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.preload.model.information.VnfPreloadList;
89 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.preload.model.information.VnfPreloadListBuilder;
90 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.preload.model.information.VnfPreloadListKey;
91 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.preload.vf.module.model.information.VfModulePreloadList;
92 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.preload.vf.module.model.information.VfModulePreloadListBuilder;
93 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.preload.vf.module.model.information.VfModulePreloadListKey;
94 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.preload.vnf.instance.model.information.VnfInstancePreloadList;
95 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.preload.vnf.instance.model.information.VnfInstancePreloadListBuilder;
96 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.preload.vnf.instance.model.information.VnfInstancePreloadListKey;
97 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.request.information.RequestInformation;
98 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.sdnc.request.header.SdncRequestHeader;
99 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.sdnc.request.header.SdncRequestHeader.SvcAction;
100 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.service.data.ServiceData;
101 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.service.data.ServiceDataBuilder;
102 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.service.status.ServiceStatus;
103 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.service.status.ServiceStatus.RequestStatus;
104 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.service.status.ServiceStatus.RpcAction;
105 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.service.status.ServiceStatus.RpcName;
106 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.service.status.ServiceStatus.VnfsdnAction;
107 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.service.status.ServiceStatus.VnfsdnSubaction;
108 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.service.status.ServiceStatusBuilder;
109 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vf.module.information.VfModuleInformationBuilder;
110 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vf.module.model.infrastructure.VfModuleList;
111 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vf.module.model.infrastructure.VfModuleListBuilder;
112 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vf.module.model.infrastructure.VfModuleListKey;
113 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vf.module.preload.data.VfModulePreloadData;
114 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vf.module.preload.data.VfModulePreloadDataBuilder;
115 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vf.module.service.data.VfModuleServiceData;
116 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vf.module.service.data.VfModuleServiceDataBuilder;
117 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.information.VnfInformationBuilder;
118 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.instance.information.VnfInstanceInformationBuilder;
119 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.instance.model.infrastructure.VnfInstanceList;
120 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.instance.model.infrastructure.VnfInstanceListBuilder;
121 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.instance.model.infrastructure.VnfInstanceListKey;
122 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.instance.preload.data.VnfInstancePreloadData;
123 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.instance.preload.data.VnfInstancePreloadDataBuilder;
124 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.instance.service.data.VnfInstanceServiceData;
125 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.instance.service.data.VnfInstanceServiceDataBuilder;
126 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.model.infrastructure.VnfList;
127 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.model.infrastructure.VnfListBuilder;
128 import org.opendaylight.yang.gen.v1.org.onap.sdnctl.vnf.rev150720.vnf.model.infrastructure.VnfListKey;
129 import org.opendaylight.yangtools.concepts.ListenerRegistration;
130 import org.opendaylight.yangtools.yang.binding.DataObject;
131 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
132 import org.opendaylight.yangtools.yang.common.RpcResult;
133 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
134 import org.opendaylight.yangtools.yang.data.api.schema.tree.ModifiedNodeDoesNotExistException;
135 import org.slf4j.Logger;
136 import org.slf4j.LoggerFactory;
137 import org.slf4j.MDC;
138
139 import java.text.DateFormat;
140 import java.text.SimpleDateFormat;
141 import java.util.ArrayList;
142 import java.util.Date;
143 import java.util.Properties;
144 import java.util.TimeZone;
145 import java.util.concurrent.ExecutionException;
146 import java.util.concurrent.ExecutorService;
147 import java.util.concurrent.Executors;
148 import java.util.concurrent.Future;
149
150 /**
151  * Defines a base implementation for your provider. This class extends from a helper class
152  * which provides storage for the most commonly used components of the MD-SAL. Additionally the
153  * base class provides some basic logging and initialization / clean up methods.
154  */
155 public class vnfapiProvider implements AutoCloseable, VNFAPIService, DataChangeListener {
156     protected DataBroker dataBroker;
157     protected NotificationPublishService notificationService;
158     protected RpcProviderRegistry rpcRegistry;
159     protected BindingAwareBroker.RpcRegistration<VNFAPIService> rpcRegistration;
160
161     private final Logger log = LoggerFactory.getLogger(vnfapiProvider.class);
162     private final String appName = "vnfapi";
163     private final ExecutorService executor;
164
165     private VNFSDNSvcLogicServiceClient svcLogicClient;
166     private ListenerRegistration<DataChangeListener> dclServices;
167
168     public vnfapiProvider(DataBroker dataBroker2, NotificationPublishService notificationPublishService,
169         RpcProviderRegistry rpcProviderRegistry, VNFSDNSvcLogicServiceClient client) {
170         this.log.info("Creating provider for " + appName);
171         executor = Executors.newFixedThreadPool(1);
172         dataBroker = dataBroker2;
173         notificationService = notificationPublishService;
174         rpcRegistry = rpcProviderRegistry;
175         this.svcLogicClient = client;
176         initialize();
177     }
178
179     public void initialize() {
180         log.info("Initializing provider for " + appName);
181         // Create the top level containers
182         createContainers();
183         try {
184             VnfSdnUtil.loadProperties();
185         } catch (Exception e) {
186             log.error("Caught Exception while trying to load properties file: ", e);
187         }
188
189         log.info("Initialization complete for " + appName);
190     }
191
192     private void createContainers() {
193         final WriteTransaction t = dataBroker.newReadWriteTransaction();
194
195         // Create the Vnfs container
196         t.merge(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(Vnfs.class), new VnfsBuilder().build());
197         t.merge(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(Vnfs.class), new VnfsBuilder().build());
198
199         // Create the PreloadVnfs container
200         t.merge(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(PreloadVnfs.class),
201             new PreloadVnfsBuilder().build());
202         t.merge(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(PreloadVnfs.class),
203             new PreloadVnfsBuilder().build());
204
205         // 1610 Create the PreloadVnfInstances container
206         t.merge(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(PreloadVnfInstances.class),
207             new PreloadVnfInstancesBuilder().build());
208         t.merge(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(PreloadVnfInstances.class),
209             new PreloadVnfInstancesBuilder().build());
210
211         // 1610 Create the VnfInstances container
212         t.merge(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(VnfInstances.class),
213             new VnfInstancesBuilder().build());
214         t.merge(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(VnfInstances.class),
215             new VnfInstancesBuilder().build());
216
217         // 1610 Create the PreloadVfModules container
218         t.merge(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(PreloadVfModules.class),
219             new PreloadVfModulesBuilder().build());
220         t.merge(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(PreloadVfModules.class),
221             new PreloadVfModulesBuilder().build());
222
223         // 1610 Create the VfModules container
224         t.merge(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.create(VfModules.class),
225             new VfModulesBuilder().build());
226         t.merge(LogicalDatastoreType.OPERATIONAL, InstanceIdentifier.create(VfModules.class),
227             new VfModulesBuilder().build());
228
229         try {
230             CheckedFuture<Void, TransactionCommitFailedException> checkedFuture = t.submit();
231             checkedFuture.get();
232             log.info("Create Containers succeeded!: ");
233
234         } catch (InterruptedException | ExecutionException e) {
235             log.error("Create Containers Failed: " + e);
236         }
237     }
238
239     @Override public void close() throws Exception {
240         log.info("Closing provider for " + appName);
241         executor.shutdown();
242         rpcRegistration.close();
243         log.info("Successfully closed provider for " + appName);
244     }
245
246     // On data change not used
247     @Override public void onDataChanged(AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
248         boolean changed = false;
249         log.info("   IN ON DATA CHANGE: ");
250         WriteTransaction writeTransaction = dataBroker.newWriteOnlyTransaction();
251
252         DataObject updatedSubTree = change.getUpdatedSubtree();
253
254         if (updatedSubTree != null) {
255             if (log.isDebugEnabled()) {
256                 log.debug("updatedSubTree was non-null:" + updatedSubTree);
257             }
258             if (updatedSubTree instanceof Vnfs) {
259                 ArrayList<VnfList> vnfList = (ArrayList<VnfList>) ((Vnfs) updatedSubTree).getVnfList();
260                 if (vnfList != null) {
261                     for (VnfList entry : vnfList) {
262                         ServiceData serviceData = entry.getServiceData();
263                         ServiceStatus serviceStatus = entry.getServiceStatus();
264                         if (serviceData != null && serviceStatus != null) {
265                             //
266                             // ServiceData change detected, check the AckFinal indicator and request-status to see if we need to proceed.
267                             //
268                             if ((!"Y".equals(serviceStatus.getFinalIndicator())) && (RequestStatus.Synccomplete
269                                 .equals(serviceStatus.getRequestStatus()))) {
270                                 if (log.isDebugEnabled()) {
271                                     log.debug("Final Indicator is not Y, calling handleServiceDataUpdated");
272                                 }
273                                 //handleServiceDataUpdated(serviceData, serviceStatus, writeTransaction);
274                                 changed = true;
275                             }
276                         }
277                     }
278                 }
279             }
280             if (updatedSubTree instanceof PreloadVnfs) {
281                 ArrayList<VnfPreloadList> vnfList =
282                     (ArrayList<VnfPreloadList>) ((PreloadVnfs) updatedSubTree).getVnfPreloadList();
283                 if (vnfList != null) {
284                     for (VnfPreloadList entry : vnfList) {
285                         PreloadData preloadData = entry.getPreloadData();
286                         if (preloadData != null) {
287                             changed = true;
288                         }
289                     }
290                 }
291             }
292             //1610
293             if (updatedSubTree instanceof PreloadVnfInstances) {
294                 ArrayList<VnfInstancePreloadList> vnfInstanceList =
295                     (ArrayList<VnfInstancePreloadList>) ((PreloadVnfInstances) updatedSubTree)
296                         .getVnfInstancePreloadList();
297                 if (vnfInstanceList != null) {
298                     for (VnfInstancePreloadList entry : vnfInstanceList) {
299                         VnfInstancePreloadData vnfInstancePreloadData = entry.getVnfInstancePreloadData();
300                         if (vnfInstancePreloadData != null) {
301                             changed = true;
302                         }
303                     }
304                 }
305             }
306             //1610
307             if (updatedSubTree instanceof VnfInstances) {
308                 ArrayList<VnfInstanceList> vnfInstanceList =
309                     (ArrayList<VnfInstanceList>) ((VnfInstances) updatedSubTree).getVnfInstanceList();
310                 if (vnfInstanceList != null) {
311                     for (VnfInstanceList entry : vnfInstanceList) {
312                         VnfInstanceServiceData vnfInstanceServiceData = entry.getVnfInstanceServiceData();
313                         ServiceStatus serviceStatus = entry.getServiceStatus();
314                         if (vnfInstanceServiceData != null && serviceStatus != null) {
315                             // VnfInstanceServiceData change detected, check the AckFinal indicator and request-status
316                             // to see if we need to proceed.
317                             if ((!"Y".equals(serviceStatus.getFinalIndicator())) && (RequestStatus.Synccomplete
318                                 .equals(serviceStatus.getRequestStatus()))) {
319                                 if (log.isDebugEnabled()) {
320                                     log.debug("Final Indicator is not Y, calling handleServiceDataUpdated");
321                                 }
322                                 changed = true;
323                             }
324                         }
325                     }
326                 }
327             }
328             //1610
329             if (updatedSubTree instanceof PreloadVfModules) {
330                 ArrayList<VfModulePreloadList> vnfInstanceList =
331                     (ArrayList<VfModulePreloadList>) ((PreloadVfModules) updatedSubTree).getVfModulePreloadList();
332                 if (vnfInstanceList != null) {
333                     for (VfModulePreloadList entry : vnfInstanceList) {
334                         VfModulePreloadData vnfInstancePreloadData = entry.getVfModulePreloadData();
335                         if (vnfInstancePreloadData != null) {
336                             changed = true;
337                         }
338                     }
339                 }
340             }
341             //1610
342             if (updatedSubTree instanceof VfModules) {
343                 ArrayList<VfModuleList> vfModuleList =
344                     (ArrayList<VfModuleList>) ((VfModules) updatedSubTree).getVfModuleList();
345                 if (vfModuleList != null) {
346                     for (VfModuleList entry : vfModuleList) {
347                         VfModuleServiceData vfModuleServiceData = entry.getVfModuleServiceData();
348                         ServiceStatus serviceStatus = entry.getServiceStatus();
349                         if (vfModuleServiceData != null && serviceStatus != null) {
350                             // VfModuleServiceData change detected, check the AckFinal indicator and request-status to
351                             // see if we need to proceed.
352                             if ((!"Y".equals(serviceStatus.getFinalIndicator())) && (RequestStatus.Synccomplete
353                                 .equals(serviceStatus.getRequestStatus()))) {
354                                 if (log.isDebugEnabled()) {
355                                     log.debug("Final Indicator is not Y, calling handleServiceDataUpdated");
356                                 }
357                                 changed = true;
358                             }
359                         }
360                     }
361                 }
362             }
363         }
364         // Do the write transaction only if something changed.
365         if (changed) {
366             CheckedFuture<Void, TransactionCommitFailedException> checkedFuture = writeTransaction.submit();
367             Futures.addCallback(checkedFuture, new FutureCallback<Void>() {
368
369                 @Override public void onSuccess(Void arg0) {
370                     log.debug("Successfully updated Service Status");
371                 }
372
373                 @Override public void onFailure(Throwable ex) {
374                     log.debug("Failed updating Service Status", ex);
375                 }
376             }, executor);
377         }
378     }
379
380     private static class Iso8601Util {
381         private static TimeZone tz = TimeZone.getTimeZone("UTC");
382         private static DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
383
384         static {
385             df.setTimeZone(tz);
386         }
387
388         private static String now() {
389             return df.format(new Date());
390         }
391     }
392
393     private void setServiceStatus(ServiceStatusBuilder serviceStatusBuilder, String errorCode, String errorMessage,
394         String ackFinal) {
395         serviceStatusBuilder.setResponseCode(errorCode);
396         serviceStatusBuilder.setResponseMessage(errorMessage);
397         serviceStatusBuilder.setFinalIndicator(ackFinal);
398         serviceStatusBuilder.setResponseTimestamp(Iso8601Util.now());
399     }
400
401     private void setServiceStatus(ServiceStatusBuilder serviceStatusBuilder, RequestInformation requestInformation) {
402         if (requestInformation != null && requestInformation.getRequestAction() != null) {
403             switch (requestInformation.getRequestAction()) {
404                 case VNFActivateRequest:
405                     serviceStatusBuilder.setVnfsdnAction(VnfsdnAction.VNFActivateRequest);
406                     break;
407                 case ChangeVNFActivateRequest:
408                     serviceStatusBuilder.setVnfsdnAction(VnfsdnAction.ChangeVNFActivateRequest);
409                     break;
410                 case DisconnectVNFRequest:
411                     serviceStatusBuilder.setVnfsdnAction(VnfsdnAction.DisconnectVNFRequest);
412                     break;
413                 case PreloadVNFRequest:
414                     serviceStatusBuilder.setVnfsdnAction(VnfsdnAction.PreloadVNFRequest);
415                     break;
416                 case DeletePreloadVNFRequest:
417                     serviceStatusBuilder.setVnfsdnAction(VnfsdnAction.DeletePreloadVNFRequest);
418                     break;
419                 // 1610 vnf-instance Requests
420                 case VnfInstanceActivateRequest:
421                     serviceStatusBuilder.setVnfsdnAction(VnfsdnAction.VnfInstanceActivateRequest);
422                     break;
423                 case ChangeVnfInstanceActivateRequest:
424                     serviceStatusBuilder.setVnfsdnAction(VnfsdnAction.ChangeVnfInstanceActivateRequest);
425                     break;
426                 case DisconnectVnfInstanceRequest:
427                     serviceStatusBuilder.setVnfsdnAction(VnfsdnAction.DisconnectVnfInstanceRequest);
428                     break;
429                 case PreloadVnfInstanceRequest:
430                     serviceStatusBuilder.setVnfsdnAction(VnfsdnAction.PreloadVnfInstanceRequest);
431                     break;
432                 // 1610 vf-module Requests
433                 case VfModuleActivateRequest:
434                     serviceStatusBuilder.setVnfsdnAction(VnfsdnAction.VfModuleActivateRequest);
435                     break;
436                 case ChangeVfModuleActivateRequest:
437                     serviceStatusBuilder.setVnfsdnAction(VnfsdnAction.ChangeVfModuleActivateRequest);
438                     break;
439                 case DisconnectVfModuleRequest:
440                     serviceStatusBuilder.setVnfsdnAction(VnfsdnAction.DisconnectVfModuleRequest);
441                     break;
442                 case PreloadVfModuleRequest:
443                     serviceStatusBuilder.setVnfsdnAction(VnfsdnAction.PreloadVfModuleRequest);
444                     break;
445                 default:
446                     log.error("Unknown RequestAction: " + requestInformation.getRequestAction());
447                     break;
448             }
449         }
450         if (requestInformation != null && requestInformation.getRequestSubAction() != null) {
451             switch (requestInformation.getRequestSubAction()) {
452                 case SUPP:
453                     serviceStatusBuilder.setVnfsdnSubaction(VnfsdnSubaction.SUPP);
454                     break;
455                 case CANCEL:
456                     serviceStatusBuilder.setVnfsdnSubaction(VnfsdnSubaction.CANCEL);
457                     break;
458                 default:
459                     log.error("Unknown RequestSubAction: " + requestInformation.getRequestSubAction());
460                     break;
461             }
462         }
463     }
464
465     private void setServiceStatus(ServiceStatusBuilder serviceStatusBuilder, SdncRequestHeader requestHeader) {
466         if (requestHeader != null && requestHeader.getSvcAction() != null) {
467             switch (requestHeader.getSvcAction()) {
468                 case Reserve:
469                     serviceStatusBuilder.setRpcAction(RpcAction.Reserve);
470                     break;
471                 case Activate:
472                     serviceStatusBuilder.setRpcAction(RpcAction.Activate);
473                     break;
474                 case Assign:
475                     serviceStatusBuilder.setRpcAction(RpcAction.Assign);
476                     break;
477                 case Delete:
478                     serviceStatusBuilder.setRpcAction(RpcAction.Delete);
479                     break;
480                 case Changeassign:
481                     serviceStatusBuilder.setRpcAction(RpcAction.Changeassign);
482                     break;
483                 case Changedelete:
484                     serviceStatusBuilder.setRpcAction(RpcAction.Changedelete);
485                     break;
486                 case Rollback:
487                     serviceStatusBuilder.setRpcAction(RpcAction.Rollback);
488                     break;
489                 default:
490                     log.error("Unknown SvcAction: " + requestHeader.getSvcAction());
491                     break;
492             }
493         }
494     }
495
496     private void getServiceData(String siid, ServiceDataBuilder serviceDataBuilder) {
497         // default to config
498         getServiceData(siid, serviceDataBuilder, LogicalDatastoreType.CONFIGURATION);
499     }
500
501
502     private void getServiceData(String siid, ServiceDataBuilder serviceDataBuilder, LogicalDatastoreType type) {
503         // See if any data exists yet for this siid, if so grab it.
504         InstanceIdentifier serviceInstanceIdentifier =
505             InstanceIdentifier.<Vnfs>builder(Vnfs.class).child(VnfList.class, new VnfListKey(siid)).build();
506         ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
507         Optional<VnfList> data = null;
508         try {
509             data = (Optional<VnfList>) readTx.read(type, serviceInstanceIdentifier).get();
510         } catch (InterruptedException | ExecutionException e) {
511             log.error("Caught Exception reading MD-SAL (" + type + ") for [" + siid + "] ", e);
512         }
513
514         if (data != null && data.isPresent()) {
515             ServiceData serviceData = (ServiceData) data.get().getServiceData();
516             if (serviceData != null) {
517                 log.info("Read MD-SAL (" + type + ") data for [" + siid + "] ServiceData: " + serviceData);
518                 serviceDataBuilder.setSdncRequestHeader(serviceData.getSdncRequestHeader());
519                 serviceDataBuilder.setRequestInformation(serviceData.getRequestInformation());
520                 serviceDataBuilder.setServiceInformation(serviceData.getServiceInformation());
521                 serviceDataBuilder.setVnfRequestInformation(serviceData.getVnfRequestInformation());
522                 serviceDataBuilder.setVnfId(serviceData.getVnfId());
523                 serviceDataBuilder.setVnfTopologyInformation(serviceData.getVnfTopologyInformation());
524                 serviceDataBuilder.setOperStatus(serviceData.getOperStatus());
525             } else {
526                 log.info("No service-data found in MD-SAL (" + type + ") for [" + siid + "] ");
527             }
528         } else {
529             log.info("No data found in MD-SAL (" + type + ") for [" + siid + "] ");
530         }
531     }
532
533     //1610 vnf-instance
534     private void getVnfInstanceServiceData(String siid, VnfInstanceServiceDataBuilder vnfInstanceServiceDataBuilder) {
535         // default to config
536         getVnfInstanceServiceData(siid, vnfInstanceServiceDataBuilder, LogicalDatastoreType.CONFIGURATION);
537     }
538
539     //1610 vnf-instance
540     private void getVnfInstanceServiceData(String siid, VnfInstanceServiceDataBuilder vnfInstanceServiceDataBuilder,
541         LogicalDatastoreType type) {
542         // See if any data exists yet for this siid, if so grab it.
543         InstanceIdentifier vnfInstanceIdentifier = InstanceIdentifier.<VnfInstances>builder(VnfInstances.class)
544             .child(VnfInstanceList.class, new VnfInstanceListKey(siid)).build();
545         ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
546         Optional<VnfInstanceList> data = null;
547         try {
548             data = (Optional<VnfInstanceList>) readTx.read(type, vnfInstanceIdentifier).get();
549         } catch (InterruptedException | ExecutionException e) {
550             log.error("Caught Exception reading MD-SAL (" + type + ") for [" + siid + "] ", e);
551         }
552
553         if (data != null && data.isPresent()) {
554             VnfInstanceServiceData vnfInstanceServiceData =
555                 (VnfInstanceServiceData) data.get().getVnfInstanceServiceData();
556             if (vnfInstanceServiceData != null) {
557                 log.info("Read MD-SAL (" + type + ") data for [" + siid + "] VnfInstanceServiceData: "
558                     + vnfInstanceServiceData);
559                 vnfInstanceServiceDataBuilder.setSdncRequestHeader(vnfInstanceServiceData.getSdncRequestHeader());
560                 vnfInstanceServiceDataBuilder.setRequestInformation(vnfInstanceServiceData.getRequestInformation());
561                 vnfInstanceServiceDataBuilder.setServiceInformation(vnfInstanceServiceData.getServiceInformation());
562                 vnfInstanceServiceDataBuilder
563                     .setVnfInstanceRequestInformation(vnfInstanceServiceData.getVnfInstanceRequestInformation());
564                 vnfInstanceServiceDataBuilder.setVnfInstanceId(vnfInstanceServiceData.getVnfInstanceId());
565                 vnfInstanceServiceDataBuilder
566                     .setVnfInstanceTopologyInformation(vnfInstanceServiceData.getVnfInstanceTopologyInformation());
567                 vnfInstanceServiceDataBuilder.setOperStatus(vnfInstanceServiceData.getOperStatus());
568             } else {
569                 log.info("No vnf-instance-service-data found in MD-SAL (" + type + ") for [" + siid + "] ");
570             }
571         } else {
572             log.info("No data found in MD-SAL (" + type + ") for [" + siid + "] ");
573         }
574     }
575
576     //1610 vf-module
577     private void getVfModuleServiceData(String siid, VfModuleServiceDataBuilder vfModuleServiceDataBuilder) {
578         // default to config
579         getVfModuleServiceData(siid, vfModuleServiceDataBuilder, LogicalDatastoreType.CONFIGURATION);
580     }
581
582     //1610 vf-module
583     private void getVfModuleServiceData(String siid, VfModuleServiceDataBuilder vfModuleServiceDataBuilder,
584         LogicalDatastoreType type) {
585         // See if any data exists yet for this siid, if so grab it.
586         InstanceIdentifier vfModuleIdentifier =
587             InstanceIdentifier.<VfModules>builder(VfModules.class).child(VfModuleList.class, new VfModuleListKey(siid))
588                 .build();
589         ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
590         Optional<VfModuleList> data = null;
591         try {
592             data = (Optional<VfModuleList>) readTx.read(type, vfModuleIdentifier).get();
593         } catch (InterruptedException | ExecutionException e) {
594             log.error("Caught Exception reading MD-SAL (" + type + ") for [" + siid + "] ", e);
595         }
596
597         if (data != null && data.isPresent()) {
598             VfModuleServiceData vfModuleServiceData = data.get().getVfModuleServiceData();
599             if (vfModuleServiceData != null) {
600                 log.info(
601                     "Read MD-SAL (" + type + ") data for [" + siid + "] VfModuleServiceData: " + vfModuleServiceData);
602                 vfModuleServiceDataBuilder.setSdncRequestHeader(vfModuleServiceData.getSdncRequestHeader());
603                 vfModuleServiceDataBuilder.setRequestInformation(vfModuleServiceData.getRequestInformation());
604                 vfModuleServiceDataBuilder.setServiceInformation(vfModuleServiceData.getServiceInformation());
605                 vfModuleServiceDataBuilder
606                     .setVfModuleRequestInformation(vfModuleServiceData.getVfModuleRequestInformation());
607                 vfModuleServiceDataBuilder.setVfModuleId(vfModuleServiceData.getVfModuleId());
608                 vfModuleServiceDataBuilder
609                     .setVfModuleTopologyInformation(vfModuleServiceData.getVfModuleTopologyInformation());
610                 vfModuleServiceDataBuilder.setOperStatus(vfModuleServiceData.getOperStatus());
611             } else {
612                 log.info("No vf-module-service-data found in MD-SAL (" + type + ") for [" + siid + "] ");
613             }
614         } else {
615             log.info("No data found in MD-SAL (" + type + ") for [" + siid + "] ");
616         }
617     }
618
619
620     private void getPreloadData(String vnf_name, String vnf_type, PreloadDataBuilder preloadDataBuilder) {
621         // default to config
622         getPreloadData(vnf_name, vnf_type, preloadDataBuilder, LogicalDatastoreType.CONFIGURATION);
623     }
624
625     private void getPreloadData(String preload_name, String preload_type, PreloadDataBuilder preloadDataBuilder,
626         LogicalDatastoreType type) {
627         // See if any data exists yet for this name/type, if so grab it.
628         InstanceIdentifier preloadInstanceIdentifier = InstanceIdentifier.<PreloadVnfs>builder(PreloadVnfs.class)
629             .child(VnfPreloadList.class, new VnfPreloadListKey(preload_name, preload_type)).build();
630         ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
631         Optional<VnfPreloadList> data = null;
632         try {
633             data = (Optional<VnfPreloadList>) readTx.read(type, preloadInstanceIdentifier).get();
634         } catch (InterruptedException | ExecutionException e) {
635             log.error("Caught Exception reading MD-SAL (" + type + ") for [" + preload_name + "," + preload_type + "] ",
636                 e);
637         }
638
639         if (data != null && data.isPresent()) {
640             PreloadData preloadData = (PreloadData) data.get().getPreloadData();
641             if (preloadData != null) {
642                 log.info("Read MD-SAL (" + type + ") data for [" + preload_name + "," + preload_type + "] PreloadData: "
643                     + preloadData);
644                 preloadDataBuilder.setVnfTopologyInformation(preloadData.getVnfTopologyInformation());
645                 preloadDataBuilder.setNetworkTopologyInformation(preloadData.getNetworkTopologyInformation());
646                 preloadDataBuilder.setOperStatus(preloadData.getOperStatus());
647             } else {
648                 log.info(
649                     "No preload-data found in MD-SAL (" + type + ") for [" + preload_name + "," + preload_type + "] ");
650             }
651         } else {
652             log.info("No data found in MD-SAL (" + type + ") for [" + preload_name + "," + preload_type + "] ");
653         }
654     }
655
656     //1610 preload-vnf-instance
657     private void getVnfInstancePreloadData(String vnf_name, String vnf_type,
658         VnfInstancePreloadDataBuilder preloadDataBuilder) {
659         // default to config
660         getVnfInstancePreloadData(vnf_name, vnf_type, preloadDataBuilder, LogicalDatastoreType.CONFIGURATION);
661     }
662
663     //1610 preload-vnf-instance
664     private void getVnfInstancePreloadData(String preload_name, String preload_type,
665         VnfInstancePreloadDataBuilder preloadDataBuilder, LogicalDatastoreType type) {
666         // See if any data exists yet for this name/type, if so grab it.
667         InstanceIdentifier preloadInstanceIdentifier =
668             InstanceIdentifier.<PreloadVnfInstances>builder(PreloadVnfInstances.class)
669                 .child(VnfInstancePreloadList.class, new VnfInstancePreloadListKey(preload_name, preload_type)).build();
670         ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
671         Optional<VnfInstancePreloadList> data = null;
672         try {
673             data = (Optional<VnfInstancePreloadList>) readTx.read(type, preloadInstanceIdentifier).get();
674         } catch (InterruptedException | ExecutionException e) {
675             log.error("Caught Exception reading MD-SAL (" + type + ") for [" + preload_name + "," + preload_type + "] ",
676                 e);
677         }
678
679         if (data != null && data.isPresent()) {
680             VnfInstancePreloadData preloadData = (VnfInstancePreloadData) data.get().getVnfInstancePreloadData();
681             if (preloadData != null) {
682                 log.info("Read MD-SAL (" + type + ") data for [" + preload_name + "," + preload_type
683                     + "] VnfInstancePreloadData: " + preloadData);
684                 preloadDataBuilder.setVnfInstanceTopologyInformation(preloadData.getVnfInstanceTopologyInformation());
685                 preloadDataBuilder.setOperStatus(preloadData.getOperStatus());
686             } else {
687                 log.info("No vnf-instance-preload-data found in MD-SAL (" + type + ") for [" + preload_name + ","
688                     + preload_type + "] ");
689             }
690         } else {
691             log.info("No data found in MD-SAL (" + type + ") for [" + preload_name + "," + preload_type + "] ");
692         }
693     }
694
695     // 1610 preload-vf-module
696     private void getVfModulePreloadData(String vnf_name, String vnf_type,
697         VfModulePreloadDataBuilder preloadDataBuilder) {
698         // default to config
699         getVfModulePreloadData(vnf_name, vnf_type, preloadDataBuilder, LogicalDatastoreType.CONFIGURATION);
700     }
701
702     private void getVfModulePreloadData(String preload_name, String preload_type,
703         VfModulePreloadDataBuilder preloadDataBuilder, LogicalDatastoreType type) {
704         // See if any data exists yet for this name/type, if so grab it.
705         InstanceIdentifier preloadInstanceIdentifier =
706             InstanceIdentifier.<PreloadVfModules>builder(PreloadVfModules.class)
707                 .child(VfModulePreloadList.class, new VfModulePreloadListKey(preload_name, preload_type)).build();
708         ReadOnlyTransaction readTx = dataBroker.newReadOnlyTransaction();
709         Optional<VfModulePreloadList> data = null;
710         try {
711             data = (Optional<VfModulePreloadList>) readTx.read(type, preloadInstanceIdentifier).get();
712         } catch (InterruptedException | ExecutionException e) {
713             log.error("Caught Exception reading MD-SAL (" + type + ") for [" + preload_name + "," + preload_type + "] ",
714                 e);
715         }
716
717         if (data != null && data.isPresent()) {
718             VfModulePreloadData preloadData = (VfModulePreloadData) data.get().getVfModulePreloadData();
719             if (preloadData != null) {
720                 log.info("Read MD-SAL (" + type + ") data for [" + preload_name + "," + preload_type
721                     + "] VfModulePreloadData: " + preloadData);
722                 preloadDataBuilder.setVfModuleTopologyInformation(preloadData.getVfModuleTopologyInformation());
723                 preloadDataBuilder.setOperStatus(preloadData.getOperStatus());
724             } else {
725                 log.info(
726                     "No preload-data found in MD-SAL (" + type + ") for [" + preload_name + "," + preload_type + "] ");
727             }
728         } else {
729             log.info("No data found in MD-SAL (" + type + ") for [" + preload_name + "," + preload_type + "] ");
730         }
731     }
732
733     private void SaveVnfList(final VnfList entry, boolean merge, LogicalDatastoreType storeType)
734         throws IllegalStateException {
735         // Each entry will be identifiable by a unique key, we have to create that identifier
736         InstanceIdentifier.InstanceIdentifierBuilder<VnfList> vnfListIdBuilder =
737             InstanceIdentifier.<Vnfs>builder(Vnfs.class).child(VnfList.class, entry.getKey());
738         InstanceIdentifier<VnfList> path = vnfListIdBuilder.build();
739
740         int tries = 2;
741         while (true) {
742             try {
743                 WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
744                 if (merge) {
745                     tx.merge(storeType, path, entry);
746                 } else {
747                     tx.put(storeType, path, entry);
748                 }
749                 tx.submit().checkedGet();
750                 log.debug("Update DataStore succeeded");
751                 break;
752             } catch (final TransactionCommitFailedException e) {
753                 if (e instanceof OptimisticLockFailedException) {
754                     if (--tries <= 0) {
755                         log.debug("Got OptimisticLockFailedException on last try - failing ");
756                         throw new IllegalStateException(e);
757                     }
758                     log.debug("Got OptimisticLockFailedException - trying again ");
759                 } else {
760                     log.debug("Update DataStore failed");
761                     throw new IllegalStateException(e);
762                 }
763             }
764         }
765
766     }
767
768     private void DeleteVnfList(final VnfList entry, LogicalDatastoreType storeType) throws IllegalStateException {
769         // Each entry will be identifiable by a unique key, we have to create that identifier
770         InstanceIdentifier.InstanceIdentifierBuilder<VnfList> vnfListIdBuilder =
771             InstanceIdentifier.<Vnfs>builder(Vnfs.class).child(VnfList.class, entry.getKey());
772         InstanceIdentifier<VnfList> path = vnfListIdBuilder.build();
773
774         int tries = 2;
775         while (true) {
776             try {
777                 WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
778                 tx.delete(storeType, path);
779                 tx.submit().checkedGet();
780                 log.debug("DataStore delete succeeded");
781                 break;
782             } catch (final TransactionCommitFailedException  e) {
783                 if (e instanceof OptimisticLockFailedException) {
784                     if (--tries <= 0) {
785                         log.debug("Got OptimisticLockFailedException on last try - failing ");
786                         throw new IllegalStateException(e);
787                     }
788                     log.debug("Got OptimisticLockFailedException - trying again ");
789                 }
790                 else {
791                                 if (e.getCause() instanceof ModifiedNodeDoesNotExistException) {
792                                         log.debug("Ignoring MpdifiedNodeDoesNotExistException");
793                                 } else {
794                                         log.debug("Delete DataStore failed");
795                                         throw new IllegalStateException(e);
796                                 }
797                 }
798             }
799         }
800     }
801
802     //1610 vnf-instance
803     private void SaveVnfInstanceList(final VnfInstanceList entry, boolean merge, LogicalDatastoreType storeType)
804         throws IllegalStateException {
805         // Each entry will be identifiable by a unique key, we have to create that identifier
806         InstanceIdentifier.InstanceIdentifierBuilder<VnfInstanceList> vnfInstanceListIdBuilder =
807             InstanceIdentifier.<VnfInstances>builder(VnfInstances.class).child(VnfInstanceList.class, entry.getKey());
808         InstanceIdentifier<VnfInstanceList> path = vnfInstanceListIdBuilder.build();
809
810         int tries = 2;
811         while (true) {
812             try {
813                 WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
814                 if (merge) {
815                     tx.merge(storeType, path, entry);
816                 } else {
817                     tx.put(storeType, path, entry);
818                 }
819                 tx.submit().checkedGet();
820                 log.debug("Update DataStore succeeded");
821                 break;
822             } catch (final TransactionCommitFailedException e) {
823                 if (e instanceof OptimisticLockFailedException) {
824                     if (--tries <= 0) {
825                         log.debug("Got OptimisticLockFailedException on last try - failing ");
826                         throw new IllegalStateException(e);
827                     }
828                     log.debug("Got OptimisticLockFailedException - trying again ");
829                 } else {
830                     log.debug("Update DataStore failed");
831                     throw new IllegalStateException(e);
832                 }
833             }
834         }
835     }
836
837     //1610 vf-module
838     private void SaveVfModuleList(final VfModuleList entry, boolean merge, LogicalDatastoreType storeType)
839         throws IllegalStateException {
840         // Each entry will be identifiable by a unique key, we have to create that identifier
841         InstanceIdentifier.InstanceIdentifierBuilder<VfModuleList> vfModuleListIdBuilder =
842             InstanceIdentifier.<VfModules>builder(VfModules.class).child(VfModuleList.class, entry.getKey());
843         InstanceIdentifier<VfModuleList> path = vfModuleListIdBuilder.build();
844
845         int tries = 2;
846         while (true) {
847             try {
848                 WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
849                 if (merge) {
850                     tx.merge(storeType, path, entry);
851                 } else {
852                     tx.put(storeType, path, entry);
853                 }
854                 tx.submit().checkedGet();
855                 log.debug("Update DataStore succeeded");
856                 break;
857             } catch (final TransactionCommitFailedException e) {
858                 if (e instanceof OptimisticLockFailedException) {
859                     if (--tries <= 0) {
860                         log.debug("Got OptimisticLockFailedException on last try - failing ");
861                         throw new IllegalStateException(e);
862                     }
863                     log.debug("Got OptimisticLockFailedException - trying again ");
864                 } else {
865                     log.debug("Update DataStore failed");
866                     throw new IllegalStateException(e);
867                 }
868             }
869         }
870     }
871
872     private void SavePreloadList(final VnfPreloadList entry, boolean merge, LogicalDatastoreType storeType)
873         throws IllegalStateException {
874
875         // Each entry will be identifiable by a unique key, we have to create that identifier
876         InstanceIdentifier.InstanceIdentifierBuilder<VnfPreloadList> vnfListIdBuilder =
877             InstanceIdentifier.<PreloadVnfs>builder(PreloadVnfs.class).child(VnfPreloadList.class, entry.getKey());
878         InstanceIdentifier<VnfPreloadList> path = vnfListIdBuilder.build();
879         int tries = 2;
880         while (true) {
881             try {
882                 WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
883                 if (merge) {
884                     tx.merge(storeType, path, entry);
885                 } else {
886                     tx.put(storeType, path, entry);
887                 }
888                 tx.submit().checkedGet();
889                 log.debug("Update DataStore succeeded");
890                 break;
891             } catch (final TransactionCommitFailedException e) {
892                 if (e instanceof OptimisticLockFailedException) {
893                     if (--tries <= 0) {
894                         log.debug("Got OptimisticLockFailedException on last try - failing ");
895                         throw new IllegalStateException(e);
896                     }
897                     log.debug("Got OptimisticLockFailedException - trying again ");
898                 } else {
899                     log.debug("Update DataStore failed");
900                     throw new IllegalStateException(e);
901                 }
902             }
903         }
904     }
905
906     //1610 preload vnf-instance
907     private void SaveVnfInstancePreloadList(final VnfInstancePreloadList entry, boolean merge,
908         LogicalDatastoreType storeType) throws IllegalStateException {
909
910         // Each entry will be identifiable by a unique key, we have to create that identifier
911         InstanceIdentifier.InstanceIdentifierBuilder<VnfInstancePreloadList> vnfInstanceListIdBuilder =
912             InstanceIdentifier.<PreloadVnfInstances>builder(PreloadVnfInstances.class)
913                 .child(VnfInstancePreloadList.class, entry.getKey());
914         InstanceIdentifier<VnfInstancePreloadList> path = vnfInstanceListIdBuilder.build();
915         int tries = 2;
916         while (true) {
917             try {
918                 WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
919                 if (merge) {
920                     tx.merge(storeType, path, entry);
921                 } else {
922                     tx.put(storeType, path, entry);
923                 }
924                 tx.submit().checkedGet();
925                 log.debug("Update DataStore succeeded");
926                 break;
927             } catch (final TransactionCommitFailedException e) {
928                 if (e instanceof OptimisticLockFailedException) {
929                     if (--tries <= 0) {
930                         log.debug("Got OptimisticLockFailedException on last try - failing ");
931                         throw new IllegalStateException(e);
932                     }
933                     log.debug("Got OptimisticLockFailedException - trying again ");
934                 } else {
935                     log.debug("Update DataStore failed");
936                     throw new IllegalStateException(e);
937                 }
938             }
939         }
940     }
941
942     //1610 preload vf-module
943     private void SaveVfModulePreloadList(final VfModulePreloadList entry, boolean merge, LogicalDatastoreType storeType)
944         throws IllegalStateException {
945
946         // Each entry will be identifiable by a unique key, we have to create that identifier
947         InstanceIdentifier.InstanceIdentifierBuilder<VfModulePreloadList> vfModuleListIdBuilder =
948             InstanceIdentifier.<PreloadVfModules>builder(PreloadVfModules.class)
949                 .child(VfModulePreloadList.class, entry.getKey());
950         InstanceIdentifier<VfModulePreloadList> path = vfModuleListIdBuilder.build();
951         int tries = 2;
952         while (true) {
953             try {
954                 WriteTransaction tx = dataBroker.newWriteOnlyTransaction();
955                 if (merge) {
956                     tx.merge(storeType, path, entry);
957                 } else {
958                     tx.put(storeType, path, entry);
959                 }
960                 tx.submit().checkedGet();
961                 log.debug("Update DataStore succeeded");
962                 break;
963             } catch (final TransactionCommitFailedException e) {
964                 if (e instanceof OptimisticLockFailedException) {
965                     if (--tries <= 0) {
966                         log.debug("Got OptimisticLockFailedException on last try - failing ");
967                         throw new IllegalStateException(e);
968                     }
969                     log.debug("Got OptimisticLockFailedException - trying again ");
970                 } else {
971                     log.debug("Update DataStore failed");
972                     throw new IllegalStateException(e);
973                 }
974             }
975         }
976     }
977
978     //Save the requestId into MDC
979     private void setRequestIdAsMDC(String requestId) {
980         MDC.put("RequestId", requestId);
981     }
982
983     //1610 vnf-instance-topology-operation
984     @Override public Future<RpcResult<VnfInstanceTopologyOperationOutput>> vnfInstanceTopologyOperation(
985         VnfInstanceTopologyOperationInput input) {
986
987         final String SVC_OPERATION = "vnf-instance-topology-operation";
988         VnfInstanceServiceData vnfInstanceServiceData = null;
989         ServiceStatusBuilder serviceStatusBuilder = new ServiceStatusBuilder();
990         Properties parms = new Properties();
991
992         log.info(SVC_OPERATION + " called.");
993         // create a new response object
994         VnfInstanceTopologyOperationOutputBuilder responseBuilder = new VnfInstanceTopologyOperationOutputBuilder();
995
996         //if(input == null || input.getVnfInstanceRequestInformation().getVnfInstanceTopologyIdentifier().getVnfInstanceId() == null )
997         if (input == null || input.getVnfInstanceRequestInformation() == null
998             || input.getVnfInstanceRequestInformation().getVnfInstanceId() == null) {
999             log.debug("exiting " + SVC_OPERATION + " because of invalid input, null or empty vnf-instance-id");
1000             responseBuilder.setResponseCode("403");
1001             responseBuilder.setResponseMessage("invalid input, null or empty vnf-instance-id");
1002             responseBuilder.setAckFinalIndicator("Y");
1003             RpcResult<VnfInstanceTopologyOperationOutput> rpcResult =
1004                 RpcResultBuilder.<VnfInstanceTopologyOperationOutput>status(true).withResult(responseBuilder.build())
1005                     .build();
1006             // return error
1007             return Futures.immediateFuture(rpcResult);
1008         }
1009
1010         // Grab the service instance ID from the input buffer
1011         String viid = input.getVnfInstanceRequestInformation().getVnfInstanceId();
1012         String preload_name = input.getVnfInstanceRequestInformation().getVnfInstanceName();
1013         String preload_type = input.getVnfInstanceRequestInformation().getVnfModelId();
1014
1015         // Make sure we have a valid viid
1016         if (viid == null || viid.length() == 0) {
1017             log.debug("exiting " + SVC_OPERATION + " because of invalid vnf-instance-id");
1018             responseBuilder.setResponseCode("403");
1019             responseBuilder.setResponseMessage("invalid input, null or empty vnf-instance-id");
1020             responseBuilder.setAckFinalIndicator("Y");
1021             RpcResult<VnfInstanceTopologyOperationOutput> rpcResult =
1022                 RpcResultBuilder.<VnfInstanceTopologyOperationOutput>status(true).withResult(responseBuilder.build())
1023                     .build();
1024             // return error
1025             return Futures.immediateFuture(rpcResult);
1026         }
1027
1028         if (input.getSdncRequestHeader() != null) {
1029             responseBuilder.setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId());
1030             setRequestIdAsMDC(input.getSdncRequestHeader().getSvcRequestId());
1031         }
1032
1033         // Get vnf-instance-preload-data
1034         VnfInstancePreloadDataBuilder vnfInstancePreloadDataBuilder = new VnfInstancePreloadDataBuilder();
1035         getVnfInstancePreloadData(preload_name, preload_type, vnfInstancePreloadDataBuilder);
1036
1037         // Get service-data
1038         VnfInstanceServiceDataBuilder vnfInstanceServiceDataBuilder = new VnfInstanceServiceDataBuilder();
1039         getVnfInstanceServiceData(viid, vnfInstanceServiceDataBuilder);
1040
1041         // Get operational-data
1042         VnfInstanceServiceDataBuilder operDataBuilder = new VnfInstanceServiceDataBuilder();
1043         getVnfInstanceServiceData(viid, operDataBuilder, LogicalDatastoreType.OPERATIONAL);
1044
1045         // Set the serviceStatus based on input
1046         setServiceStatus(serviceStatusBuilder, input.getSdncRequestHeader());
1047         setServiceStatus(serviceStatusBuilder, input.getRequestInformation());
1048
1049         //
1050         // setup a service-data object builder
1051         // ACTION vnf-topology-operation
1052         // INPUT:
1053         //  USES sdnc-request-header;
1054         //  USES request-information;
1055         //  USES service-information;
1056         //  USES vnf-request-information
1057         // OUTPUT:
1058         //  USES vnf-topology-response-body;
1059         //  USES vnf-information
1060         //  USES service-information
1061         //
1062         // container service-data
1063         //   uses vnf-configuration-information;
1064         //   uses oper-status;
1065
1066         log.info("Adding INPUT data for " + SVC_OPERATION + " [" + viid + "] input: " + input);
1067         VnfInstanceTopologyOperationInputBuilder inputBuilder = new VnfInstanceTopologyOperationInputBuilder(input);
1068         VnfSdnUtil.toProperties(parms, inputBuilder.build());
1069
1070         log.info("Adding OPERATIONAL data for " + SVC_OPERATION + " [" + viid + "] operational-data: " + operDataBuilder
1071             .build());
1072         VnfSdnUtil.toProperties(parms, "operational-data", operDataBuilder);
1073
1074         log.info(
1075             "Adding CONFIG data for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] preload-data: "
1076                 + vnfInstancePreloadDataBuilder.build());
1077         VnfSdnUtil.toProperties(parms, "vnf-instance-preload-data", vnfInstancePreloadDataBuilder);
1078
1079         // Call SLI sync method
1080         // Get SvcLogicService reference
1081         Properties respProps = null;
1082         String errorCode = "200";
1083         String errorMessage = null;
1084         String ackFinal = "Y";
1085
1086         try {
1087             if (svcLogicClient.hasGraph("VNF-API", SVC_OPERATION, null, "sync")) {
1088
1089                 try {
1090                     respProps = svcLogicClient
1091                         .execute("VNF-API", SVC_OPERATION, null, "sync", vnfInstanceServiceDataBuilder, parms);
1092                 } catch (Exception e) {
1093                     log.error("Caught exception executing service logic for " + SVC_OPERATION, e);
1094                     errorMessage = e.getMessage();
1095                     errorCode = "500";
1096                 }
1097             } else {
1098                 errorMessage = "No service logic active for VNF-API: '" + SVC_OPERATION + "'";
1099                 errorCode = "503";
1100             }
1101         } catch (Exception e) {
1102             errorCode = "500";
1103             errorMessage = e.getMessage();
1104             log.error("Caught exception looking for service logic", e);
1105         }
1106
1107         if (respProps != null) {
1108             errorCode = respProps.getProperty("error-code");
1109             errorMessage = respProps.getProperty("error-message");
1110             ackFinal = respProps.getProperty("ack-final", "Y");
1111         }
1112
1113         setServiceStatus(serviceStatusBuilder, errorCode, errorMessage, ackFinal);
1114         serviceStatusBuilder.setRequestStatus(RequestStatus.Synccomplete);
1115         serviceStatusBuilder.setRpcName(RpcName.VnfInstanceTopologyOperation);
1116
1117         if (errorCode != null && errorCode.length() != 0 && !(errorCode.equals("0") || errorCode.equals("200"))) {
1118             responseBuilder.setResponseCode(errorCode);
1119             responseBuilder.setResponseMessage(errorMessage);
1120             responseBuilder.setAckFinalIndicator(ackFinal);
1121             VnfInstanceListBuilder vnfInstanceListBuilder = new VnfInstanceListBuilder();
1122             vnfInstanceListBuilder.setVnfInstanceId(viid);
1123             vnfInstanceListBuilder.setServiceStatus(serviceStatusBuilder.build());
1124             try {
1125                 SaveVnfInstanceList(vnfInstanceListBuilder.build(), true, LogicalDatastoreType.CONFIGURATION);
1126             } catch (Exception e) {
1127                 log.error("Caught Exception updating MD-SAL for " + SVC_OPERATION + " [" + viid + "] \n", e);
1128             }
1129             log.error("Returned FAILED for " + SVC_OPERATION + " [" + viid + "] " + responseBuilder.build());
1130             RpcResult<VnfInstanceTopologyOperationOutput> rpcResult =
1131                 RpcResultBuilder.<VnfInstanceTopologyOperationOutput>status(true).withResult(responseBuilder.build())
1132                     .build();
1133             // return error
1134             return Futures.immediateFuture(rpcResult);
1135         }
1136
1137         // Got success from SLI
1138         try {
1139             vnfInstanceServiceData = vnfInstanceServiceDataBuilder.build();
1140             log.info("Updating MD-SAL for " + SVC_OPERATION + " [" + viid + "] VnfInstanceServiceData: "
1141                 + vnfInstanceServiceData);
1142             // svc-configuration-list
1143             VnfInstanceListBuilder vnfInstanceListBuilder = new VnfInstanceListBuilder();
1144             vnfInstanceListBuilder.setVnfInstanceServiceData(vnfInstanceServiceData);
1145             vnfInstanceListBuilder.setVnfInstanceId(vnfInstanceServiceData.getVnfInstanceId());
1146             //siid = vnfInstanceServiceData.getVnfInstanceId();
1147             vnfInstanceListBuilder.setServiceStatus(serviceStatusBuilder.build());
1148             SaveVnfInstanceList(vnfInstanceListBuilder.build(), false, LogicalDatastoreType.CONFIGURATION);
1149             if (input.getSdncRequestHeader() != null && input.getSdncRequestHeader().getSvcAction() != null) {
1150                 // Only update operational tree on Delete or Activate
1151                 if (input.getSdncRequestHeader().getSvcAction().equals(SvcAction.Delete) || input.getSdncRequestHeader()
1152                     .getSvcAction().equals(SvcAction.Activate)) {
1153                     log.info("Updating OPERATIONAL tree.");
1154                     SaveVnfInstanceList(vnfInstanceListBuilder.build(), false, LogicalDatastoreType.OPERATIONAL);
1155                 }
1156             }
1157             VnfInstanceInformationBuilder vnfInstanceInformationBuilder = new VnfInstanceInformationBuilder();
1158             vnfInstanceInformationBuilder.setVnfInstanceId(viid);
1159             responseBuilder.setVnfInstanceInformation(vnfInstanceInformationBuilder.build());
1160             responseBuilder.setServiceInformation(vnfInstanceServiceData.getServiceInformation());
1161         } catch (Exception e) {
1162             log.error("Caught Exception updating MD-SAL for " + SVC_OPERATION + " [" + viid + "] \n", e);
1163             responseBuilder.setResponseCode("500");
1164             responseBuilder.setResponseMessage(e.toString());
1165             responseBuilder.setAckFinalIndicator("Y");
1166             log.error("Returned FAILED for " + SVC_OPERATION + " [" + viid + "] " + responseBuilder.build());
1167             RpcResult<VnfInstanceTopologyOperationOutput> rpcResult =
1168                 RpcResultBuilder.<VnfInstanceTopologyOperationOutput>status(true).withResult(responseBuilder.build())
1169                     .build();
1170             // return error
1171             return Futures.immediateFuture(rpcResult);
1172         }
1173
1174         // Update succeeded
1175         responseBuilder.setResponseCode(errorCode);
1176         responseBuilder.setAckFinalIndicator(ackFinal);
1177         if (errorMessage != null) {
1178             responseBuilder.setResponseMessage(errorMessage);
1179         }
1180         log.info("Updated MD-SAL for " + SVC_OPERATION + " [" + viid + "] ");
1181         log.info("Returned SUCCESS for " + SVC_OPERATION + " [" + viid + "] " + responseBuilder.build());
1182
1183         RpcResult<VnfInstanceTopologyOperationOutput> rpcResult =
1184             RpcResultBuilder.<VnfInstanceTopologyOperationOutput>status(true).withResult(responseBuilder.build())
1185                 .build();
1186         // return success
1187         return Futures.immediateFuture(rpcResult);
1188     }
1189
1190     //1610 vf-module-topology-operation
1191     @Override public Future<RpcResult<VfModuleTopologyOperationOutput>> vfModuleTopologyOperation(
1192         VfModuleTopologyOperationInput input) {
1193
1194         final String SVC_OPERATION = "vf-module-topology-operation";
1195         VfModuleServiceData vfModuleServiceData = null;
1196         VnfInstanceServiceData vnfInstanceServiceData = null;
1197         ServiceStatusBuilder serviceStatusBuilder = new ServiceStatusBuilder();
1198         Properties parms = new Properties();
1199
1200         log.info(SVC_OPERATION + " called.");
1201         // create a new response object
1202         VfModuleTopologyOperationOutputBuilder responseBuilder = new VfModuleTopologyOperationOutputBuilder();
1203
1204         // Validate vf-module-id from vf-module-request-information
1205         if (input == null || input.getVfModuleRequestInformation() == null
1206             || input.getVfModuleRequestInformation().getVfModuleId() == null) {
1207             log.debug("exiting " + SVC_OPERATION + " because of invalid input, null or empty vf-module-id");
1208             responseBuilder.setResponseCode("403");
1209             responseBuilder.setResponseMessage("invalid input, null or empty vf-module-id");
1210             responseBuilder.setAckFinalIndicator("Y");
1211             RpcResult<VfModuleTopologyOperationOutput> rpcResult =
1212                 RpcResultBuilder.<VfModuleTopologyOperationOutput>status(true).withResult(responseBuilder.build())
1213                     .build();
1214             // return error
1215             return Futures.immediateFuture(rpcResult);
1216         }
1217
1218         // Grab the vf-module-request-information.vf-module-id from the input buffer
1219         String vfid = input.getVfModuleRequestInformation().getVfModuleId();
1220         String preload_name = input.getVfModuleRequestInformation().getVfModuleName();
1221         String preload_type = input.getVfModuleRequestInformation().getVfModuleModelId();
1222
1223         // Make sure we have a valid siid
1224         if (vfid == null || vfid.length() == 0) {
1225             log.debug("exiting " + SVC_OPERATION + " because of invalid vf-module-id");
1226             responseBuilder.setResponseCode("403");
1227             responseBuilder.setResponseMessage("invalid input, null or empty vf-module-id");
1228             responseBuilder.setAckFinalIndicator("Y");
1229             RpcResult<VfModuleTopologyOperationOutput> rpcResult =
1230                 RpcResultBuilder.<VfModuleTopologyOperationOutput>status(true).withResult(responseBuilder.build())
1231                     .build();
1232             // return error
1233             return Futures.immediateFuture(rpcResult);
1234         }
1235
1236         // 1610 add vf-module-id to vnf-instance-list.vf-module-relationship-list
1237         String viid = input.getVfModuleRequestInformation().getVnfInstanceId();
1238
1239         if (viid == null || viid.length() == 0) {
1240             log.debug("exiting " + SVC_OPERATION + " because of invalid vnf-instance-id");
1241             responseBuilder.setResponseCode("403");
1242             responseBuilder.setResponseMessage("invalid input, null or empty vnf-instance-id");
1243             responseBuilder.setAckFinalIndicator("Y");
1244             RpcResult<VfModuleTopologyOperationOutput> rpcResult =
1245                 RpcResultBuilder.<VfModuleTopologyOperationOutput>status(true).withResult(responseBuilder.build())
1246                     .build();
1247             // return error
1248             return Futures.immediateFuture(rpcResult);
1249         }
1250
1251         if (input.getSdncRequestHeader() != null) {
1252             responseBuilder.setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId());
1253             setRequestIdAsMDC(input.getSdncRequestHeader().getSvcRequestId());
1254         }
1255
1256         // Get vf-module-preload-data
1257         VfModulePreloadDataBuilder vfModulePreloadDataBuilder = new VfModulePreloadDataBuilder();
1258         getVfModulePreloadData(preload_name, preload_type, vfModulePreloadDataBuilder);
1259
1260         // Get vf-module-service-data
1261         VfModuleServiceDataBuilder vfModuleServiceDataBuilder = new VfModuleServiceDataBuilder();
1262         getVfModuleServiceData(vfid, vfModuleServiceDataBuilder);
1263
1264         // Get vf-module operation-data
1265         VfModuleServiceDataBuilder operDataBuilder = new VfModuleServiceDataBuilder();
1266         getVfModuleServiceData(vfid, operDataBuilder, LogicalDatastoreType.OPERATIONAL);
1267
1268         // save service-data builder object for rollback
1269         VfModuleServiceDataBuilder rb_vfModuleServiceDataBuilder = vfModuleServiceDataBuilder;
1270         VfModuleServiceDataBuilder rb_operDataBuilder = operDataBuilder;
1271
1272         // 1610 Need to pull vnf-instance-list.vf-module-relationship-list from MD-SAL
1273         VnfInstanceServiceDataBuilder vnfInstanceServiceDataBuilder = new VnfInstanceServiceDataBuilder();
1274         getVnfInstanceServiceData(viid, vnfInstanceServiceDataBuilder);
1275
1276         // vnf-instance operational-data
1277         VnfInstanceServiceDataBuilder vnfInstanceOperDataBuilder = new VnfInstanceServiceDataBuilder();
1278         getVnfInstanceServiceData(viid, vnfInstanceOperDataBuilder, LogicalDatastoreType.OPERATIONAL);
1279
1280         // save operational builder object for rollback
1281         VnfInstanceServiceDataBuilder rb_vnfInstanceServiceDataBuilder = vnfInstanceServiceDataBuilder;
1282         VnfInstanceServiceDataBuilder rb_vnfInstanceOperDataBuilder = vnfInstanceOperDataBuilder;
1283
1284         // Set the serviceStatus based on input
1285         setServiceStatus(serviceStatusBuilder, input.getSdncRequestHeader());
1286         setServiceStatus(serviceStatusBuilder, input.getRequestInformation());
1287
1288         //
1289         // setup a service-data object builder
1290         // ACTION vnf-topology-operation
1291         // INPUT:
1292         //  USES sdnc-request-header;
1293         //  USES request-information;
1294         //  USES service-information;
1295         //  USES vnf-request-information
1296         // OUTPUT:
1297         //  USES vnf-topology-response-body;
1298         //  USES vnf-information
1299         //  USES service-information
1300         //
1301         // container service-data
1302         //   uses vnf-configuration-information;
1303         //   uses oper-status;
1304
1305         log.info("Adding INPUT data for " + SVC_OPERATION + " [" + vfid + "] input: " + input);
1306         VfModuleTopologyOperationInputBuilder inputBuilder = new VfModuleTopologyOperationInputBuilder(input);
1307         VnfSdnUtil.toProperties(parms, inputBuilder.build());
1308
1309         log.info("Adding OPERATIONAL data for " + SVC_OPERATION + " [" + vfid + "] vf-module operational-data: "
1310             + operDataBuilder.build());
1311         VnfSdnUtil.toProperties(parms, "operational-data", operDataBuilder);
1312
1313         log.info("Adding CONFIG data for " + SVC_OPERATION + " [" + preload_name + "," + preload_type
1314             + "] vf-module-preload-data: " + vfModulePreloadDataBuilder.build());
1315         VnfSdnUtil.toProperties(parms, "vf-module-preload-data", vfModulePreloadDataBuilder);
1316
1317         log.info("Adding vnf-instance CONFIG data for " + SVC_OPERATION + " [" + viid + "] vnf-instance-service-data: "
1318             + vnfInstanceServiceDataBuilder.build());
1319         VnfSdnUtil.toProperties(parms, "vnf-instance-service-data", vnfInstanceServiceDataBuilder);
1320
1321         log.info("Adding vnf-instance OPERATIONAL data for " + SVC_OPERATION + " [" + viid
1322             + "] vnf-instance operational-data: " + vnfInstanceOperDataBuilder.build());
1323         VnfSdnUtil.toProperties(parms, "vnf-instance-operational-data", vnfInstanceOperDataBuilder);
1324
1325         // Call SLI sync method
1326         // Get SvcLogicService reference
1327
1328         Properties respProps = null;
1329         String errorCode = "200";
1330         String errorMessage = null;
1331         String ackFinal = "Y";
1332
1333         try {
1334             if (svcLogicClient.hasGraph("VNF-API", SVC_OPERATION, null, "sync")) {
1335
1336                 try {
1337                     respProps = svcLogicClient
1338                         .execute("VNF-API", SVC_OPERATION, null, "sync", vfModuleServiceDataBuilder, parms);
1339                 } catch (Exception e) {
1340                     log.error("Caught exception executing service logic on vf-module for " + SVC_OPERATION, e);
1341                     errorMessage = e.getMessage();
1342                     errorCode = "500";
1343                 }
1344
1345             } else {
1346                 errorMessage = "No service logic active for VNF-API: '" + SVC_OPERATION + "'";
1347                 errorCode = "503";
1348             }
1349         } catch (Exception e) {
1350             errorCode = "500";
1351             errorMessage = e.getMessage();
1352             log.error("Caught exception looking for service logic", e);
1353         }
1354
1355
1356         if (respProps != null) {
1357             errorCode = respProps.getProperty("error-code");
1358             errorMessage = respProps.getProperty("error-message");
1359             ackFinal = respProps.getProperty("ack-final", "Y");
1360         }
1361
1362         setServiceStatus(serviceStatusBuilder, errorCode, errorMessage, ackFinal);
1363         serviceStatusBuilder.setRequestStatus(RequestStatus.Synccomplete);
1364         serviceStatusBuilder.setRpcName(RpcName.VfModuleTopologyOperation);
1365
1366         if (errorCode != null && errorCode.length() != 0 && !(errorCode.equals("0") || errorCode.equals("200"))) {
1367             responseBuilder.setResponseCode(errorCode);
1368             responseBuilder.setResponseMessage(errorMessage);
1369             responseBuilder.setAckFinalIndicator(ackFinal);
1370             VfModuleListBuilder vfModuleListBuilder = new VfModuleListBuilder();
1371             vfModuleListBuilder.setVfModuleId(vfid);
1372             vfModuleListBuilder.setServiceStatus(serviceStatusBuilder.build());
1373             try {
1374                 SaveVfModuleList(vfModuleListBuilder.build(), true, LogicalDatastoreType.CONFIGURATION);
1375             } catch (Exception e) {
1376                 log.error("Caught Exception updating MD-SAL for " + SVC_OPERATION + " [" + vfid + "] \n", e);
1377             }
1378             log.error("Returned FAILED for " + SVC_OPERATION + " [" + vfid + "] " + responseBuilder.build());
1379             RpcResult<VfModuleTopologyOperationOutput> rpcResult =
1380                 RpcResultBuilder.<VfModuleTopologyOperationOutput>status(true).withResult(responseBuilder.build())
1381                     .build();
1382             // return error
1383             return Futures.immediateFuture(rpcResult);
1384         }
1385
1386         // Got success from SLI
1387         // save vf-module-service-data in MD-SAL
1388         try {
1389             vfModuleServiceData = vfModuleServiceDataBuilder.build();
1390             log.info(
1391                 "Updating MD-SAL for " + SVC_OPERATION + " [" + vfid + "] VfModuleServiceData: " + vfModuleServiceData);
1392             // vf-module-list
1393             VfModuleListBuilder vfModuleListBuilder = new VfModuleListBuilder();
1394             vfModuleListBuilder.setVfModuleServiceData(vfModuleServiceData);
1395             vfModuleListBuilder.setVfModuleId(vfModuleServiceData.getVfModuleId());
1396             //vfid = vfModuleServiceData.getVfModuleId();
1397             vfModuleListBuilder.setServiceStatus(serviceStatusBuilder.build());
1398             SaveVfModuleList(vfModuleListBuilder.build(), false, LogicalDatastoreType.CONFIGURATION);
1399             if (input.getSdncRequestHeader() != null && input.getSdncRequestHeader().getSvcAction() != null) {
1400                 // Only update operational tree on Delete or Activate
1401                 if (input.getSdncRequestHeader().getSvcAction().equals(SvcAction.Delete) || input.getSdncRequestHeader()
1402                     .getSvcAction().equals(SvcAction.Activate)) {
1403                     log.info("Updating OPERATIONAL tree.");
1404                     SaveVfModuleList(vfModuleListBuilder.build(), false, LogicalDatastoreType.OPERATIONAL);
1405                 }
1406             }
1407             VfModuleInformationBuilder vfModuleInformationBuilder = new VfModuleInformationBuilder();
1408             vfModuleInformationBuilder.setVfModuleId(vfid);
1409             responseBuilder.setVfModuleInformation(vfModuleInformationBuilder.build());
1410             responseBuilder.setServiceInformation(vfModuleServiceData.getServiceInformation());
1411         } catch (Exception e) {
1412             log.error("Caught Exception updating MD-SAL for " + SVC_OPERATION + " [" + vfid + "] \n", e);
1413             responseBuilder.setResponseCode("500");
1414             responseBuilder.setResponseMessage(e.toString());
1415             responseBuilder.setAckFinalIndicator("Y");
1416             log.error("Returned FAILED for " + SVC_OPERATION + " [" + vfid + "] " + responseBuilder.build());
1417             RpcResult<VfModuleTopologyOperationOutput> rpcResult =
1418                 RpcResultBuilder.<VfModuleTopologyOperationOutput>status(true).withResult(responseBuilder.build())
1419                     .build();
1420             // return error
1421             return Futures.immediateFuture(rpcResult);
1422         }
1423
1424         // Update succeeded
1425         responseBuilder.setResponseCode(errorCode);
1426         responseBuilder.setAckFinalIndicator(ackFinal);
1427         if (errorMessage != null) {
1428             responseBuilder.setResponseMessage(errorMessage);
1429         }
1430         log.info("Updated vf-module in MD-SAL for " + SVC_OPERATION + " [" + vfid + "] ");
1431         log.info("Returned SUCCESS for " + SVC_OPERATION + " [" + vfid + "] " + responseBuilder.build());
1432
1433         RpcResult<VfModuleTopologyOperationOutput> rpcResult =
1434             RpcResultBuilder.<VfModuleTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1435         // return success
1436         return Futures.immediateFuture(rpcResult);
1437     }
1438
1439
1440     @Override
1441     public Future<RpcResult<VnfTopologyOperationOutput>> vnfTopologyOperation(VnfTopologyOperationInput input) {
1442         final String SVC_OPERATION = "vnf-topology-operation";
1443         ServiceData serviceData = null;
1444         ServiceStatusBuilder serviceStatusBuilder = new ServiceStatusBuilder();
1445         Properties parms = new Properties();
1446
1447         log.info(SVC_OPERATION + " called.");
1448         // create a new response object
1449         VnfTopologyOperationOutputBuilder responseBuilder = new VnfTopologyOperationOutputBuilder();
1450
1451         if (input == null || input.getServiceInformation() == null
1452             || input.getServiceInformation().getServiceInstanceId() == null
1453             || input.getServiceInformation().getServiceInstanceId().length() == 0) {
1454             log.debug("exiting " + SVC_OPERATION + " because of invalid input, null or empty service-instance-id");
1455             responseBuilder.setResponseCode("403");
1456             responseBuilder.setResponseMessage("invalid input, null or empty service-instance-id");
1457             responseBuilder.setAckFinalIndicator("Y");
1458             RpcResult<VnfTopologyOperationOutput> rpcResult =
1459                 RpcResultBuilder.<VnfTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1460             // return error
1461             return Futures.immediateFuture(rpcResult);
1462         }
1463
1464         if (input.getVnfRequestInformation() == null || input.getVnfRequestInformation().getVnfId() == null
1465             || input.getVnfRequestInformation().getVnfId().length() == 0) {
1466             log.debug("exiting " + SVC_OPERATION + " because of invalid input, null or empty vf-module-id");
1467             responseBuilder.setResponseCode("403");
1468             responseBuilder.setResponseMessage("invalid input, null or empty vf-module-id");
1469             responseBuilder.setAckFinalIndicator("Y");
1470             RpcResult<VnfTopologyOperationOutput> rpcResult =
1471                 RpcResultBuilder.<VnfTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1472             // return error
1473             return Futures.immediateFuture(rpcResult);
1474         }
1475
1476         // Grab the service instance ID from the input buffer
1477         String siid = input.getVnfRequestInformation().getVnfId();
1478         String preload_name = input.getVnfRequestInformation().getVnfName();
1479         String preload_type = input.getVnfRequestInformation().getVnfType();
1480
1481         if (input.getSdncRequestHeader() != null) {
1482             responseBuilder.setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId());
1483             setRequestIdAsMDC(input.getSdncRequestHeader().getSvcRequestId());
1484         }
1485
1486         PreloadDataBuilder preloadDataBuilder = new PreloadDataBuilder();
1487         getPreloadData(preload_name, preload_type, preloadDataBuilder);
1488
1489         ServiceDataBuilder serviceDataBuilder = new ServiceDataBuilder();
1490         getServiceData(siid, serviceDataBuilder);
1491
1492         ServiceDataBuilder operDataBuilder = new ServiceDataBuilder();
1493         getServiceData(siid, operDataBuilder, LogicalDatastoreType.OPERATIONAL);
1494
1495         // Set the serviceStatus based on input
1496         setServiceStatus(serviceStatusBuilder, input.getSdncRequestHeader());
1497         setServiceStatus(serviceStatusBuilder, input.getRequestInformation());
1498
1499         //
1500         // setup a service-data object builder
1501         // ACTION vnf-topology-operation
1502         // INPUT:
1503         //  USES sdnc-request-header;
1504         //  USES request-information;
1505         //  USES service-information;
1506         //  USES vnf-request-information
1507         // OUTPUT:
1508         //  USES vnf-topology-response-body;
1509         //  USES vnf-information
1510         //  USES service-information
1511         //
1512         // container service-data
1513         //   uses vnf-configuration-information;
1514         //   uses oper-status;
1515
1516         log.info("Adding INPUT data for " + SVC_OPERATION + " [" + siid + "] input: " + input);
1517         VnfTopologyOperationInputBuilder inputBuilder = new VnfTopologyOperationInputBuilder(input);
1518         VnfSdnUtil.toProperties(parms, inputBuilder.build());
1519
1520         log.info("Adding OPERATIONAL data for " + SVC_OPERATION + " [" + siid + "] operational-data: " + operDataBuilder
1521             .build());
1522         VnfSdnUtil.toProperties(parms, "operational-data", operDataBuilder);
1523
1524         log.info(
1525             "Adding CONFIG data for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] preload-data: "
1526                 + preloadDataBuilder.build());
1527         VnfSdnUtil.toProperties(parms, "preload-data", preloadDataBuilder);
1528
1529         // Call SLI sync method
1530         // Get SvcLogicService reference
1531         Properties respProps = null;
1532         String errorCode = "200";
1533         String errorMessage = null;
1534         String ackFinal = "Y";
1535
1536         try {
1537             if (svcLogicClient.hasGraph("VNF-API", SVC_OPERATION, null, "sync")) {
1538
1539                 try {
1540                     respProps =
1541                         svcLogicClient.execute("VNF-API", SVC_OPERATION, null, "sync", serviceDataBuilder, parms);
1542                 } catch (Exception e) {
1543                     log.error("Caught exception executing service logic for " + SVC_OPERATION, e);
1544                     errorMessage = e.getMessage();
1545                     errorCode = "500";
1546                 }
1547             } else {
1548                 errorMessage = "No service logic active for VNF-API: '" + SVC_OPERATION + "'";
1549                 errorCode = "503";
1550             }
1551         } catch (Exception e) {
1552             errorCode = "500";
1553             errorMessage = e.getMessage();
1554             log.error("Caught exception looking for service logic", e);
1555         }
1556
1557         if (respProps != null) {
1558             errorCode = respProps.getProperty("error-code");
1559             errorMessage = respProps.getProperty("error-message");
1560             ackFinal = respProps.getProperty("ack-final", "Y");
1561         }
1562
1563         setServiceStatus(serviceStatusBuilder, errorCode, errorMessage, ackFinal);
1564         serviceStatusBuilder.setRequestStatus(RequestStatus.Synccomplete);
1565         serviceStatusBuilder.setRpcName(RpcName.VnfTopologyOperation);
1566
1567         if (errorCode != null && errorCode.length() != 0 && !(errorCode.equals("0") || errorCode.equals("200"))) {
1568             responseBuilder.setResponseCode(errorCode);
1569             responseBuilder.setResponseMessage(errorMessage);
1570             responseBuilder.setAckFinalIndicator(ackFinal);
1571             VnfListBuilder vnfListBuilder = new VnfListBuilder();
1572             vnfListBuilder.setVnfId(siid);
1573             vnfListBuilder.setServiceStatus(serviceStatusBuilder.build());
1574             try {
1575                 SaveVnfList(vnfListBuilder.build(), true, LogicalDatastoreType.CONFIGURATION);
1576             } catch (Exception e) {
1577                 log.error("Caught Exception updating MD-SAL for " + SVC_OPERATION + " [" + siid + "] \n", e);
1578             }
1579             log.error("Returned FAILED for " + SVC_OPERATION + " [" + siid + "] " + responseBuilder.build());
1580             RpcResult<VnfTopologyOperationOutput> rpcResult =
1581                 RpcResultBuilder.<VnfTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1582             // return error
1583             return Futures.immediateFuture(rpcResult);
1584         }
1585
1586         // Got success from SLI
1587         try {
1588             serviceData = serviceDataBuilder.build();
1589             log.info("Updating MD-SAL for " + SVC_OPERATION + " [" + siid + "] ServiceData: " + serviceData);
1590             // svc-configuration-list
1591             VnfListBuilder vnfListBuilder = new VnfListBuilder();
1592             vnfListBuilder.setServiceData(serviceData);
1593             vnfListBuilder.setVnfId(serviceData.getVnfId());
1594             siid = serviceData.getVnfId();
1595             vnfListBuilder.setServiceStatus(serviceStatusBuilder.build());
1596             SaveVnfList(vnfListBuilder.build(), false, LogicalDatastoreType.CONFIGURATION);
1597             if (input.getSdncRequestHeader() != null && input.getSdncRequestHeader().getSvcAction() != null) {
1598                 // Only update operational tree on Delete or Activate
1599                 if (input.getSdncRequestHeader().getSvcAction().equals(SvcAction.Activate)) {
1600                     log.info("Updating OPERATIONAL tree.");
1601                     SaveVnfList(vnfListBuilder.build(), false, LogicalDatastoreType.OPERATIONAL);
1602                 } else if (input.getSdncRequestHeader().getSvcAction().equals(SvcAction.Delete) || input
1603                     .getSdncRequestHeader().getSvcAction().equals(SvcAction.Rollback)) {
1604                     log.info("Delete OPERATIONAL tree.");
1605                     DeleteVnfList(vnfListBuilder.build(), LogicalDatastoreType.CONFIGURATION);
1606                     DeleteVnfList(vnfListBuilder.build(), LogicalDatastoreType.OPERATIONAL);
1607                 }
1608             }
1609             VnfInformationBuilder vnfInformationBuilder = new VnfInformationBuilder();
1610             vnfInformationBuilder.setVnfId(siid);
1611             responseBuilder.setVnfInformation(vnfInformationBuilder.build());
1612             responseBuilder.setServiceInformation(serviceData.getServiceInformation());
1613         } catch (Exception e) {
1614             log.error("Caught Exception updating MD-SAL for " + SVC_OPERATION + " [" + siid + "] \n", e);
1615             responseBuilder.setResponseCode("500");
1616             responseBuilder.setResponseMessage(e.toString());
1617             responseBuilder.setAckFinalIndicator("Y");
1618             log.error("Returned FAILED for " + SVC_OPERATION + " [" + siid + "] " + responseBuilder.build());
1619             RpcResult<VnfTopologyOperationOutput> rpcResult =
1620                 RpcResultBuilder.<VnfTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1621             // return error
1622             return Futures.immediateFuture(rpcResult);
1623         }
1624
1625         // Update succeeded
1626         responseBuilder.setResponseCode(errorCode);
1627         responseBuilder.setAckFinalIndicator(ackFinal);
1628         if (errorMessage != null) {
1629             responseBuilder.setResponseMessage(errorMessage);
1630         }
1631         log.info("Updated MD-SAL for " + SVC_OPERATION + " [" + siid + "] ");
1632         log.info("Returned SUCCESS for " + SVC_OPERATION + " [" + siid + "] " + responseBuilder.build());
1633
1634         RpcResult<VnfTopologyOperationOutput> rpcResult =
1635             RpcResultBuilder.<VnfTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1636         // return success
1637         return Futures.immediateFuture(rpcResult);
1638     }
1639
1640     @Override public Future<RpcResult<NetworkTopologyOperationOutput>> networkTopologyOperation(
1641         NetworkTopologyOperationInput input) {
1642
1643         final String SVC_OPERATION = "network-topology-operation";
1644         ServiceData serviceData = null;
1645         ServiceStatusBuilder serviceStatusBuilder = new ServiceStatusBuilder();
1646         Properties parms = new Properties();
1647
1648         log.info(SVC_OPERATION + " called.");
1649         // create a new response object
1650         NetworkTopologyOperationOutputBuilder responseBuilder = new NetworkTopologyOperationOutputBuilder();
1651
1652         if (input == null || input.getServiceInformation() == null
1653             || input.getServiceInformation().getServiceInstanceId() == null
1654             || input.getServiceInformation().getServiceInstanceId().length() == 0) {
1655             log.debug("exiting " + SVC_OPERATION + " because of invalid input, null or empty service-instance-id");
1656             responseBuilder.setResponseCode("403");
1657             responseBuilder.setResponseMessage("invalid input, null or empty service-instance-id");
1658             responseBuilder.setAckFinalIndicator("Y");
1659             RpcResult<NetworkTopologyOperationOutput> rpcResult =
1660                 RpcResultBuilder.<NetworkTopologyOperationOutput>status(true).withResult(responseBuilder.build())
1661                     .build();
1662             // return error
1663             return Futures.immediateFuture(rpcResult);
1664         }
1665
1666         if (input.getNetworkRequestInformation() == null
1667             || input.getNetworkRequestInformation().getNetworkName() == null) {
1668             log.debug("exiting " + SVC_OPERATION + " because of invalid input, null or empty service-instance-id");
1669             responseBuilder.setResponseCode("403");
1670             responseBuilder.setResponseMessage("invalid input, null or empty service-instance-id");
1671             responseBuilder.setAckFinalIndicator("Y");
1672             RpcResult<NetworkTopologyOperationOutput> rpcResult =
1673                 RpcResultBuilder.<NetworkTopologyOperationOutput>status(true).withResult(responseBuilder.build())
1674                     .build();
1675             // return error
1676             return Futures.immediateFuture(rpcResult);
1677         }
1678
1679         // Grab the service instance ID from the input buffer
1680         String siid = null;
1681         if (input.getSdncRequestHeader().getSvcAction().equals(SvcAction.Assign)) {
1682             siid = input.getNetworkRequestInformation().getNetworkName();
1683         } else {
1684             siid = input.getNetworkRequestInformation().getNetworkId();
1685         }
1686         String preload_name = input.getNetworkRequestInformation().getNetworkName();
1687         String preload_type = input.getNetworkRequestInformation().getNetworkType();
1688
1689         if (input.getSdncRequestHeader() != null) {
1690             responseBuilder.setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId());
1691             setRequestIdAsMDC(input.getSdncRequestHeader().getSvcRequestId());
1692         }
1693
1694         PreloadDataBuilder preloadDataBuilder = new PreloadDataBuilder();
1695         getPreloadData(preload_name, preload_type, preloadDataBuilder);
1696
1697         log.info("Adding INPUT data for " + SVC_OPERATION + " [" + siid + "] input: " + input);
1698         NetworkTopologyOperationInputBuilder inputBuilder = new NetworkTopologyOperationInputBuilder(input);
1699         VnfSdnUtil.toProperties(parms, inputBuilder.build());
1700
1701         // Call SLI sync method
1702         // Get SvcLogicService reference
1703         Properties respProps = null;
1704         String errorCode = "200";
1705         String errorMessage = null;
1706         String ackFinal = "Y";
1707         String networkId = "error";
1708
1709         try {
1710             if (svcLogicClient.hasGraph("VNF-API", SVC_OPERATION, null, "sync")) {
1711
1712                 try {
1713                     respProps =
1714                         svcLogicClient.execute("VNF-API", SVC_OPERATION, null, "sync", preloadDataBuilder, parms);
1715                 } catch (Exception e) {
1716                     log.error("Caught exception executing service logic for " + SVC_OPERATION, e);
1717                     errorMessage = e.getMessage();
1718                     errorCode = "500";
1719                 }
1720             } else {
1721                 errorMessage = "No service logic active for VNF-API: '" + SVC_OPERATION + "'";
1722                 errorCode = "503";
1723             }
1724         } catch (Exception e) {
1725             errorCode = "500";
1726             errorMessage = e.getMessage();
1727             log.error("Caught exception looking for service logic", e);
1728         }
1729
1730         if (respProps != null) {
1731             errorCode = respProps.getProperty("error-code");
1732             errorMessage = respProps.getProperty("error-message");
1733             ackFinal = respProps.getProperty("ack-final", "Y");
1734             networkId = respProps.getProperty("networkId", "0");
1735         }
1736
1737         if (errorCode != null && errorCode.length() != 0 && !(errorCode.equals("0") || errorCode.equals("200"))) {
1738             responseBuilder.setResponseCode(errorCode);
1739             responseBuilder.setResponseMessage(errorMessage);
1740             responseBuilder.setAckFinalIndicator(ackFinal);
1741
1742             log.error("Returned FAILED for " + SVC_OPERATION + " [" + siid + "] " + responseBuilder.build());
1743
1744             RpcResult<NetworkTopologyOperationOutput> rpcResult =
1745                 RpcResultBuilder.<NetworkTopologyOperationOutput>status(true).withResult(responseBuilder.build())
1746                     .build();
1747             // return error
1748             return Futures.immediateFuture(rpcResult);
1749         }
1750
1751         // Got success from SLI
1752         try {
1753             NetworkInformationBuilder networkInformationBuilder = new NetworkInformationBuilder();
1754             networkInformationBuilder.setNetworkId(networkId);
1755             responseBuilder.setNetworkInformation(networkInformationBuilder.build());
1756             responseBuilder.setServiceInformation(input.getServiceInformation());
1757         } catch (IllegalStateException e) {
1758             log.error("Caught Exception updating MD-SAL for " + SVC_OPERATION + " [" + siid + "] \n", e);
1759             responseBuilder.setResponseCode("500");
1760             responseBuilder.setResponseMessage(e.toString());
1761             responseBuilder.setAckFinalIndicator("Y");
1762             log.error("Returned FAILED for " + SVC_OPERATION + " [" + siid + "] " + responseBuilder.build());
1763             RpcResult<NetworkTopologyOperationOutput> rpcResult =
1764                 RpcResultBuilder.<NetworkTopologyOperationOutput>status(true).withResult(responseBuilder.build())
1765                     .build();
1766             // return error
1767             return Futures.immediateFuture(rpcResult);
1768         }
1769
1770         // Update succeeded
1771         responseBuilder.setResponseCode(errorCode);
1772         responseBuilder.setAckFinalIndicator(ackFinal);
1773         if (errorMessage != null) {
1774             responseBuilder.setResponseMessage(errorMessage);
1775         }
1776         log.info("Updated MD-SAL for " + SVC_OPERATION + " [" + siid + "] ");
1777         log.info("Returned SUCCESS for " + SVC_OPERATION + " [" + siid + "] " + responseBuilder.build());
1778
1779         RpcResult<NetworkTopologyOperationOutput> rpcResult =
1780             RpcResultBuilder.<NetworkTopologyOperationOutput>status(true).withResult(responseBuilder.build()).build();
1781         // return success
1782         return Futures.immediateFuture(rpcResult);
1783     }
1784
1785     @Override public Future<RpcResult<PreloadVnfTopologyOperationOutput>> preloadVnfTopologyOperation(
1786         PreloadVnfTopologyOperationInput input) {
1787
1788         final String SVC_OPERATION = "preload-vnf-topology-operation";
1789         PreloadData preloadData = null;
1790         Properties parms = new Properties();
1791
1792         log.info(SVC_OPERATION + " called.");
1793         // create a new response object
1794         PreloadVnfTopologyOperationOutputBuilder responseBuilder = new PreloadVnfTopologyOperationOutputBuilder();
1795
1796         // Result from savePreloadData
1797         final SettableFuture<RpcResult<Void>> futureResult = SettableFuture.create();
1798
1799         if (input == null || input.getVnfTopologyInformation() == null
1800             || input.getVnfTopologyInformation().getVnfTopologyIdentifier() == null
1801             || input.getVnfTopologyInformation().getVnfTopologyIdentifier().getVnfName() == null
1802             || input.getVnfTopologyInformation().getVnfTopologyIdentifier().getVnfType() == null) {
1803             log.debug("exiting " + SVC_OPERATION + " because of invalid input, null or empty vnf-name and vnf-type");
1804             responseBuilder.setResponseCode("403");
1805             responseBuilder.setResponseMessage("invalid input, null or empty vnf-name and vnf-type");
1806             responseBuilder.setAckFinalIndicator("Y");
1807             RpcResult<PreloadVnfTopologyOperationOutput> rpcResult =
1808                 RpcResultBuilder.<PreloadVnfTopologyOperationOutput>status(true).withResult(responseBuilder.build())
1809                     .build();
1810             return Futures.immediateFuture(rpcResult);
1811         }
1812
1813         // Grab the name and type from the input buffer
1814         String preload_name = input.getVnfTopologyInformation().getVnfTopologyIdentifier().getVnfName();
1815         String preload_type = input.getVnfTopologyInformation().getVnfTopologyIdentifier().getVnfType();
1816
1817         // Make sure we have a preload_name and preload_type
1818         if (preload_name == null || preload_name.length() == 0) {
1819             log.debug("exiting " + SVC_OPERATION + " because of invalid preload-name");
1820             responseBuilder.setResponseCode("403");
1821             responseBuilder.setResponseMessage("invalid input, invalid preload-name");
1822             responseBuilder.setAckFinalIndicator("Y");
1823             RpcResult<PreloadVnfTopologyOperationOutput> rpcResult =
1824                 RpcResultBuilder.<PreloadVnfTopologyOperationOutput>status(true).withResult(responseBuilder.build())
1825                     .build();
1826             return Futures.immediateFuture(rpcResult);
1827         }
1828         if (preload_type == null || preload_type.length() == 0) {
1829             log.debug("exiting " + SVC_OPERATION + " because of invalid preload-type");
1830             responseBuilder.setResponseCode("403");
1831             responseBuilder.setResponseMessage("invalid input, invalid preload-type");
1832             responseBuilder.setAckFinalIndicator("Y");
1833             RpcResult<PreloadVnfTopologyOperationOutput> rpcResult =
1834                 RpcResultBuilder.<PreloadVnfTopologyOperationOutput>status(true).withResult(responseBuilder.build())
1835                     .build();
1836             return Futures.immediateFuture(rpcResult);
1837         }
1838
1839         if (input.getSdncRequestHeader() != null) {
1840             responseBuilder.setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId());
1841             setRequestIdAsMDC(input.getSdncRequestHeader().getSvcRequestId());
1842         }
1843
1844         PreloadDataBuilder preloadDataBuilder = new PreloadDataBuilder();
1845         getPreloadData(preload_name, preload_type, preloadDataBuilder);
1846         //preloadData = preloadDataBuilder.build();
1847
1848         PreloadDataBuilder operDataBuilder = new PreloadDataBuilder();
1849         getPreloadData(preload_name, preload_type, operDataBuilder, LogicalDatastoreType.OPERATIONAL);
1850
1851         //
1852         // setup a preload-data object builder
1853         // ACTION vnf-topology-operation
1854         // INPUT:
1855         //  USES sdnc-request-header;
1856         //  USES request-information;
1857         //  uses vnf-topology-information;
1858         // OUTPUT:
1859         //  USES vnf-topology-response-body;
1860         //
1861         // container preload-data
1862         //   uses vnf-configuration-information;
1863         log.info(
1864             "Adding INPUT data for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] input: " + input);
1865         PreloadVnfTopologyOperationInputBuilder inputBuilder = new PreloadVnfTopologyOperationInputBuilder(input);
1866         VnfSdnUtil.toProperties(parms, inputBuilder.build());
1867         log.info("Adding OPERATIONAL data for " + SVC_OPERATION + " [" + preload_name + "," + preload_type
1868             + "] operational-data: " + operDataBuilder.build());
1869         VnfSdnUtil.toProperties(parms, "operational-data", operDataBuilder);
1870
1871         // Call SLI sync method
1872         // Get SvcLogicService reference
1873         Properties respProps = null;
1874         String errorCode = "200";
1875         String errorMessage = null;
1876         String ackFinal = "Y";
1877
1878         try {
1879             if (svcLogicClient.hasGraph("VNF-API", SVC_OPERATION, null, "sync")) {
1880
1881                 try {
1882                     respProps =
1883                         svcLogicClient.execute("VNF-API", SVC_OPERATION, null, "sync", preloadDataBuilder, parms);
1884                 } catch (Exception e) {
1885                     log.error("Caught exception executing service logic for " + SVC_OPERATION, e);
1886                     errorMessage = e.getMessage();
1887                     errorCode = "500";
1888                 }
1889             } else {
1890                 errorMessage = "No service logic active for VNF-API: '" + SVC_OPERATION + "'";
1891                 errorCode = "503";
1892             }
1893         } catch (Exception e) {
1894             errorCode = "500";
1895             errorMessage = e.getMessage();
1896             log.error("Caught exception looking for service logic", e);
1897         }
1898
1899         if (respProps != null) {
1900             errorCode = respProps.getProperty("error-code");
1901             errorMessage = respProps.getProperty("error-message");
1902             ackFinal = respProps.getProperty("ack-final", "Y");
1903             // internalError = respProps.getProperty("internal-error", "false");
1904         }
1905
1906         if (errorCode != null && errorCode.length() != 0 && !(errorCode.equals("0") || errorCode.equals("200"))) {
1907
1908             responseBuilder.setResponseCode(errorCode);
1909             responseBuilder.setResponseMessage(errorMessage);
1910             responseBuilder.setAckFinalIndicator(ackFinal);
1911
1912             VnfPreloadListBuilder preloadVnfListBuilder = new VnfPreloadListBuilder();
1913             preloadVnfListBuilder.setVnfName(preload_name);
1914             preloadVnfListBuilder.setVnfType(preload_type);
1915             preloadVnfListBuilder.setPreloadData(preloadDataBuilder.build());
1916             log.error(
1917                 "Returned FAILED for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] error code: '"
1918                     + errorCode + "', Reason: '" + errorMessage + "'");
1919             try {
1920                 SavePreloadList(preloadVnfListBuilder.build(), true, LogicalDatastoreType.CONFIGURATION);
1921             } catch (Exception e) {
1922                 log.error(
1923                     "Caught Exception updating MD-SAL for " + SVC_OPERATION + " [" + preload_name + "," + preload_type
1924                         + "] \n", e);
1925             }
1926             log.debug("Sending Success rpc result due to external error");
1927             RpcResult<PreloadVnfTopologyOperationOutput> rpcResult =
1928                 RpcResultBuilder.<PreloadVnfTopologyOperationOutput>status(true).withResult(responseBuilder.build())
1929                     .build();
1930             return Futures.immediateFuture(rpcResult);
1931         }
1932
1933         // Got success from SLI
1934         try {
1935             preloadData = preloadDataBuilder.build();
1936             log.info(
1937                 "Updating MD-SAL for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] preloadData: "
1938                     + preloadData);
1939             // svc-configuration-list
1940             VnfPreloadListBuilder preloadVnfListBuilder = new VnfPreloadListBuilder();
1941             preloadVnfListBuilder.setVnfName(preload_name);
1942             preloadVnfListBuilder.setVnfType(preload_type);
1943             preloadVnfListBuilder.setPreloadData(preloadData);
1944
1945             // SDNGC-989 set merge flag to false
1946             SavePreloadList(preloadVnfListBuilder.build(), false, LogicalDatastoreType.CONFIGURATION);
1947             log.info("Updating OPERATIONAL tree.");
1948             SavePreloadList(preloadVnfListBuilder.build(), false, LogicalDatastoreType.OPERATIONAL);
1949         } catch (Exception e) {
1950             log.error("Caught Exception updating MD-SAL for " + SVC_OPERATION + " [" + preload_name + "," + preload_type
1951                 + "] \n", e);
1952             responseBuilder.setResponseCode("500");
1953             responseBuilder.setResponseMessage(e.toString());
1954             responseBuilder.setAckFinalIndicator("Y");
1955             log.error("Returned FAILED for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] "
1956                 + responseBuilder.build());
1957             RpcResult<PreloadVnfTopologyOperationOutput> rpcResult =
1958                 RpcResultBuilder.<PreloadVnfTopologyOperationOutput>status(false).withResult(responseBuilder.build())
1959                     .build();
1960             return Futures.immediateFuture(rpcResult);
1961         }
1962
1963         // Update succeeded
1964         responseBuilder.setResponseCode(errorCode);
1965         responseBuilder.setAckFinalIndicator(ackFinal);
1966         if (errorMessage != null) {
1967             responseBuilder.setResponseMessage(errorMessage);
1968         }
1969         log.info("Updated MD-SAL for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] ");
1970         log.info(
1971             "Returned SUCCESS for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] " + responseBuilder
1972                 .build());
1973
1974         RpcResult<PreloadVnfTopologyOperationOutput> rpcResult =
1975             RpcResultBuilder.<PreloadVnfTopologyOperationOutput>status(true).withResult(responseBuilder.build())
1976                 .build();
1977         return Futures.immediateFuture(rpcResult);
1978     }
1979
1980     //1610 preload-vnf-instance-topology-operation
1981     @Override public Future<RpcResult<PreloadVnfInstanceTopologyOperationOutput>> preloadVnfInstanceTopologyOperation(
1982         PreloadVnfInstanceTopologyOperationInput input) {
1983
1984         final String SVC_OPERATION = "preload-vnf-instance-topology-operation";
1985         VnfInstancePreloadData vnfInstancePreloadData = null;
1986         Properties parms = new Properties();
1987
1988         log.info(SVC_OPERATION + " called.");
1989         // create a new response object
1990         PreloadVnfInstanceTopologyOperationOutputBuilder responseBuilder =
1991             new PreloadVnfInstanceTopologyOperationOutputBuilder();
1992
1993         // Result from savePreloadData
1994         final SettableFuture<RpcResult<Void>> futureResult = SettableFuture.create();
1995
1996         if (input == null || input.getVnfInstanceTopologyInformation() == null
1997             || input.getVnfInstanceTopologyInformation().getVnfInstanceIdentifiers().getVnfInstanceName() == null
1998             || input.getVnfInstanceTopologyInformation().getVnfInstanceIdentifiers().getVnfModelId() == null) {
1999             log.debug("exiting " + SVC_OPERATION
2000                 + " because of invalid input, null or empty vnf-instance-name and vnf-model-id");
2001             responseBuilder.setResponseCode("403");
2002             responseBuilder.setResponseMessage("invalid input, null or empty vnf-instance-name and vnf-model-id");
2003             responseBuilder.setAckFinalIndicator("Y");
2004             RpcResult<PreloadVnfInstanceTopologyOperationOutput> rpcResult =
2005                 RpcResultBuilder.<PreloadVnfInstanceTopologyOperationOutput>status(true)
2006                     .withResult(responseBuilder.build()).build();
2007             return Futures.immediateFuture(rpcResult);
2008         }
2009
2010         // Grab the name and type from the input buffer
2011         String preload_name =
2012             input.getVnfInstanceTopologyInformation().getVnfInstanceIdentifiers().getVnfInstanceName();
2013         String preload_type = input.getVnfInstanceTopologyInformation().getVnfInstanceIdentifiers().getVnfModelId();
2014
2015         // Make sure we have a preload_name and preload_type
2016         if (preload_name == null || preload_name.length() == 0) {
2017             log.debug("exiting " + SVC_OPERATION + " because of invalid preload-name");
2018             responseBuilder.setResponseCode("403");
2019             responseBuilder.setResponseMessage("invalid input, invalid preload-name");
2020             responseBuilder.setAckFinalIndicator("Y");
2021             RpcResult<PreloadVnfInstanceTopologyOperationOutput> rpcResult =
2022                 RpcResultBuilder.<PreloadVnfInstanceTopologyOperationOutput>status(true)
2023                     .withResult(responseBuilder.build()).build();
2024             return Futures.immediateFuture(rpcResult);
2025         }
2026         if (preload_type == null || preload_type.length() == 0) {
2027             log.debug("exiting " + SVC_OPERATION + " because of invalid preload-type");
2028             responseBuilder.setResponseCode("403");
2029             responseBuilder.setResponseMessage("invalid input, invalid preload-type");
2030             responseBuilder.setAckFinalIndicator("Y");
2031             RpcResult<PreloadVnfInstanceTopologyOperationOutput> rpcResult =
2032                 RpcResultBuilder.<PreloadVnfInstanceTopologyOperationOutput>status(true)
2033                     .withResult(responseBuilder.build()).build();
2034             return Futures.immediateFuture(rpcResult);
2035         }
2036
2037         if (input.getSdncRequestHeader() != null) {
2038             responseBuilder.setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId());
2039             setRequestIdAsMDC(input.getSdncRequestHeader().getSvcRequestId());
2040         }
2041
2042         VnfInstancePreloadDataBuilder vnfInstancePreloadDataBuilder = new VnfInstancePreloadDataBuilder();
2043         getVnfInstancePreloadData(preload_name, preload_type, vnfInstancePreloadDataBuilder);
2044         //preloadData = preloadDataBuilder.build();
2045
2046         VnfInstancePreloadDataBuilder operDataBuilder = new VnfInstancePreloadDataBuilder();
2047         getVnfInstancePreloadData(preload_name, preload_type, operDataBuilder, LogicalDatastoreType.OPERATIONAL);
2048
2049         //
2050         // setup a preload-data object builder
2051         // ACTION vnf-topology-operation
2052         // INPUT:
2053         //  USES sdnc-request-header;
2054         //  USES request-information;
2055         //  uses vnf-topology-information;
2056         // OUTPUT:
2057         //  USES vnf-topology-response-body;
2058         //
2059         // container preload-data
2060         //   uses vnf-configuration-information;
2061         log.info(
2062             "Adding INPUT data for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] input: " + input);
2063         PreloadVnfInstanceTopologyOperationInputBuilder inputBuilder =
2064             new PreloadVnfInstanceTopologyOperationInputBuilder(input);
2065         VnfSdnUtil.toProperties(parms, inputBuilder.build());
2066         log.info("Adding OPERATIONAL data for " + SVC_OPERATION + " [" + preload_name + "," + preload_type
2067             + "] operational-data: " + operDataBuilder.build());
2068         VnfSdnUtil.toProperties(parms, "operational-data", operDataBuilder);
2069
2070         // Call SLI sync method
2071         // Get SvcLogicService reference
2072         Properties respProps = null;
2073         String errorCode = "200";
2074         String errorMessage = null;
2075         String ackFinal = "Y";
2076
2077         try {
2078             if (svcLogicClient.hasGraph("VNF-API", SVC_OPERATION, null, "sync")) {
2079
2080                 try {
2081                     respProps = svcLogicClient
2082                         .execute("VNF-API", SVC_OPERATION, null, "sync", vnfInstancePreloadDataBuilder, parms);
2083                 } catch (Exception e) {
2084                     log.error("Caught exception executing service logic for " + SVC_OPERATION, e);
2085                     errorMessage = e.getMessage();
2086                     errorCode = "500";
2087                 }
2088             } else {
2089                 errorMessage = "No service logic active for VNF-API: '" + SVC_OPERATION + "'";
2090                 errorCode = "503";
2091             }
2092         } catch (Exception e) {
2093             errorCode = "500";
2094             errorMessage = e.getMessage();
2095             log.error("Caught exception looking for service logic", e);
2096         }
2097
2098         if (respProps != null) {
2099             errorCode = respProps.getProperty("error-code");
2100             errorMessage = respProps.getProperty("error-message");
2101             ackFinal = respProps.getProperty("ack-final", "Y");
2102             // internalError = respProps.getProperty("internal-error", "false");
2103         }
2104
2105         if (errorCode != null && errorCode.length() != 0 && !(errorCode.equals("0") || errorCode.equals("200"))) {
2106
2107             responseBuilder.setResponseCode(errorCode);
2108             responseBuilder.setResponseMessage(errorMessage);
2109             responseBuilder.setAckFinalIndicator(ackFinal);
2110
2111             VnfInstancePreloadListBuilder vnfInstancePreloadListBuilder = new VnfInstancePreloadListBuilder();
2112             vnfInstancePreloadListBuilder.setVnfInstanceName(preload_name);
2113             vnfInstancePreloadListBuilder.setVnfModelId(preload_type);
2114             vnfInstancePreloadListBuilder.setVnfInstancePreloadData(vnfInstancePreloadDataBuilder.build());
2115             log.error(
2116                 "Returned FAILED for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] error code: '"
2117                     + errorCode + "', Reason: '" + errorMessage + "'");
2118             try {
2119                 SaveVnfInstancePreloadList(vnfInstancePreloadListBuilder.build(), true,
2120                     LogicalDatastoreType.CONFIGURATION);
2121             } catch (Exception e) {
2122                 log.error(
2123                     "Caught Exception updating MD-SAL for " + SVC_OPERATION + " [" + preload_name + "," + preload_type
2124                         + "] \n", e);
2125             }
2126             log.debug("Sending Success rpc result due to external error");
2127             RpcResult<PreloadVnfInstanceTopologyOperationOutput> rpcResult =
2128                 RpcResultBuilder.<PreloadVnfInstanceTopologyOperationOutput>status(true)
2129                     .withResult(responseBuilder.build()).build();
2130             return Futures.immediateFuture(rpcResult);
2131         }
2132
2133         // Got success from SLI
2134         try {
2135             vnfInstancePreloadData = vnfInstancePreloadDataBuilder.build();
2136             log.info(
2137                 "Updating MD-SAL for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] preloadData: "
2138                     + vnfInstancePreloadData);
2139             // svc-configuration-list
2140             VnfInstancePreloadListBuilder vnfInstancePreloadListBuilder = new VnfInstancePreloadListBuilder();
2141             vnfInstancePreloadListBuilder.setVnfInstanceName(preload_name);
2142             vnfInstancePreloadListBuilder.setVnfModelId(preload_type);
2143             vnfInstancePreloadListBuilder.setVnfInstancePreloadData(vnfInstancePreloadData);
2144
2145             // SDNGC-989 set merge flag to false
2146             SaveVnfInstancePreloadList(vnfInstancePreloadListBuilder.build(), false,
2147                 LogicalDatastoreType.CONFIGURATION);
2148             log.info("Updating OPERATIONAL tree.");
2149             SaveVnfInstancePreloadList(vnfInstancePreloadListBuilder.build(), false, LogicalDatastoreType.OPERATIONAL);
2150         } catch (Exception e) {
2151             log.error("Caught Exception updating MD-SAL for " + SVC_OPERATION + " [" + preload_name + "," + preload_type
2152                 + "] \n", e);
2153             responseBuilder.setResponseCode("500");
2154             responseBuilder.setResponseMessage(e.toString());
2155             responseBuilder.setAckFinalIndicator("Y");
2156             log.error("Returned FAILED for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] "
2157                 + responseBuilder.build());
2158             RpcResult<PreloadVnfInstanceTopologyOperationOutput> rpcResult =
2159                 RpcResultBuilder.<PreloadVnfInstanceTopologyOperationOutput>status(false)
2160                     .withResult(responseBuilder.build()).build();
2161             return Futures.immediateFuture(rpcResult);
2162         }
2163
2164         // Update succeeded
2165         responseBuilder.setResponseCode(errorCode);
2166         responseBuilder.setAckFinalIndicator(ackFinal);
2167         if (errorMessage != null) {
2168             responseBuilder.setResponseMessage(errorMessage);
2169         }
2170         log.info("Updated MD-SAL for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] ");
2171         log.info(
2172             "Returned SUCCESS for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] " + responseBuilder
2173                 .build());
2174
2175         RpcResult<PreloadVnfInstanceTopologyOperationOutput> rpcResult =
2176             RpcResultBuilder.<PreloadVnfInstanceTopologyOperationOutput>status(true).withResult(responseBuilder.build())
2177                 .build();
2178         return Futures.immediateFuture(rpcResult);
2179     }
2180
2181
2182     //1610 preload-vf-module-topology-operation
2183     @Override public Future<RpcResult<PreloadVfModuleTopologyOperationOutput>> preloadVfModuleTopologyOperation(
2184         PreloadVfModuleTopologyOperationInput input) {
2185
2186         final String SVC_OPERATION = "preload-vf-module-topology-operation";
2187         VfModulePreloadData vfModulePreloadData = null;
2188         Properties parms = new Properties();
2189
2190         log.info(SVC_OPERATION + " called.");
2191         // create a new response object
2192         PreloadVfModuleTopologyOperationOutputBuilder responseBuilder =
2193             new PreloadVfModuleTopologyOperationOutputBuilder();
2194
2195         // Result from savePreloadData
2196         final SettableFuture<RpcResult<Void>> futureResult = SettableFuture.create();
2197
2198         if (input == null || input.getVfModuleTopologyInformation() == null
2199             || input.getVfModuleTopologyInformation().getVfModuleIdentifiers().getVfModuleName() == null
2200             || input.getVfModuleTopologyInformation().getVfModuleIdentifiers().getVfModuleModelId() == null) {
2201             log.debug("exiting " + SVC_OPERATION
2202                 + " because of invalid input, null or empty vnf-instance-name and vnf-model-id");
2203             responseBuilder.setResponseCode("403");
2204             responseBuilder.setResponseMessage("invalid input, null or empty vnf-instance-name and vnf-model-id");
2205             responseBuilder.setAckFinalIndicator("Y");
2206             RpcResult<PreloadVfModuleTopologyOperationOutput> rpcResult =
2207                 RpcResultBuilder.<PreloadVfModuleTopologyOperationOutput>status(true)
2208                     .withResult(responseBuilder.build()).build();
2209             return Futures.immediateFuture(rpcResult);
2210         }
2211
2212         // Grab the name and type from the input buffer
2213         String preload_name = input.getVfModuleTopologyInformation().getVfModuleIdentifiers().getVfModuleName();
2214         String preload_type = input.getVfModuleTopologyInformation().getVfModuleIdentifiers().getVfModuleModelId();
2215
2216         // Make sure we have a preload_name and preload_type
2217         if (preload_name == null || preload_name.length() == 0) {
2218             log.debug("exiting " + SVC_OPERATION + " because of invalid preload-name");
2219             responseBuilder.setResponseCode("403");
2220             responseBuilder.setResponseMessage("invalid input, invalid preload-name");
2221             responseBuilder.setAckFinalIndicator("Y");
2222             RpcResult<PreloadVfModuleTopologyOperationOutput> rpcResult =
2223                 RpcResultBuilder.<PreloadVfModuleTopologyOperationOutput>status(true)
2224                     .withResult(responseBuilder.build()).build();
2225             return Futures.immediateFuture(rpcResult);
2226         }
2227         if (preload_type == null || preload_type.length() == 0) {
2228             log.debug("exiting " + SVC_OPERATION + " because of invalid preload-type");
2229             responseBuilder.setResponseCode("403");
2230             responseBuilder.setResponseMessage("invalid input, invalid preload-type");
2231             responseBuilder.setAckFinalIndicator("Y");
2232             RpcResult<PreloadVfModuleTopologyOperationOutput> rpcResult =
2233                 RpcResultBuilder.<PreloadVfModuleTopologyOperationOutput>status(true)
2234                     .withResult(responseBuilder.build()).build();
2235             return Futures.immediateFuture(rpcResult);
2236         }
2237
2238         if (input.getSdncRequestHeader() != null) {
2239             responseBuilder.setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId());
2240             setRequestIdAsMDC(input.getSdncRequestHeader().getSvcRequestId());
2241         }
2242
2243         VfModulePreloadDataBuilder vfModulePreloadDataBuilder = new VfModulePreloadDataBuilder();
2244         getVfModulePreloadData(preload_name, preload_type, vfModulePreloadDataBuilder);
2245         //preloadData = preloadDataBuilder.build();
2246
2247         VfModulePreloadDataBuilder operDataBuilder = new VfModulePreloadDataBuilder();
2248         getVfModulePreloadData(preload_name, preload_type, operDataBuilder, LogicalDatastoreType.OPERATIONAL);
2249
2250         //
2251         // setup a preload-data object builder
2252         // ACTION vnf-topology-operation
2253         // INPUT:
2254         //  USES sdnc-request-header;
2255         //  USES request-information;
2256         //  uses vnf-topology-information;
2257         // OUTPUT:
2258         //  USES vnf-topology-response-body;
2259         //
2260         // container preload-data
2261         //   uses vnf-configuration-information;
2262
2263         log.info(
2264             "Adding INPUT data for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] input: " + input);
2265         PreloadVfModuleTopologyOperationInputBuilder inputBuilder =
2266             new PreloadVfModuleTopologyOperationInputBuilder(input);
2267         VnfSdnUtil.toProperties(parms, inputBuilder.build());
2268         log.info("Adding OPERATIONAL data for " + SVC_OPERATION + " [" + preload_name + "," + preload_type
2269             + "] operational-data: " + operDataBuilder.build());
2270         VnfSdnUtil.toProperties(parms, "operational-data", operDataBuilder);
2271
2272         // Call SLI sync method
2273         // Get SvcLogicService reference
2274         Properties respProps = null;
2275         String errorCode = "200";
2276         String errorMessage = null;
2277         String ackFinal = "Y";
2278
2279         try {
2280             if (svcLogicClient.hasGraph("VNF-API", SVC_OPERATION, null, "sync")) {
2281                 try {
2282                     respProps = svcLogicClient
2283                         .execute("VNF-API", SVC_OPERATION, null, "sync", vfModulePreloadDataBuilder, parms);
2284                 } catch (Exception e) {
2285                     log.error("Caught exception executing service logic for " + SVC_OPERATION, e);
2286                     errorMessage = e.getMessage();
2287                     errorCode = "500";
2288                 }
2289             } else {
2290                 errorMessage = "No service logic active for VNF-API: '" + SVC_OPERATION + "'";
2291                 errorCode = "503";
2292             }
2293         } catch (Exception e) {
2294             errorCode = "500";
2295             errorMessage = e.getMessage();
2296             log.error("Caught exception looking for service logic", e);
2297         }
2298
2299         if (respProps != null) {
2300             errorCode = respProps.getProperty("error-code");
2301             errorMessage = respProps.getProperty("error-message");
2302             ackFinal = respProps.getProperty("ack-final", "Y");
2303             // internalError = respProps.getProperty("internal-error", "false");
2304         }
2305
2306         if (errorCode != null && errorCode.length() != 0 && !(errorCode.equals("0") || errorCode.equals("200"))) {
2307
2308             responseBuilder.setResponseCode(errorCode);
2309             responseBuilder.setResponseMessage(errorMessage);
2310             responseBuilder.setAckFinalIndicator(ackFinal);
2311
2312             VfModulePreloadListBuilder vfModulePreloadListBuilder = new VfModulePreloadListBuilder();
2313             vfModulePreloadListBuilder.setVfModuleName(preload_name);
2314             vfModulePreloadListBuilder.setVfModuleModelId(preload_type);
2315             vfModulePreloadListBuilder.setVfModulePreloadData(vfModulePreloadDataBuilder.build());
2316             log.error(
2317                 "Returned FAILED for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] error code: '"
2318                     + errorCode + "', Reason: '" + errorMessage + "'");
2319             try {
2320                 SaveVfModulePreloadList(vfModulePreloadListBuilder.build(), true, LogicalDatastoreType.CONFIGURATION);
2321             } catch (Exception e) {
2322                 log.error(
2323                     "Caught Exception updating MD-SAL for " + SVC_OPERATION + " [" + preload_name + "," + preload_type
2324                         + "] \n", e);
2325             }
2326             log.debug("Sending Success rpc result due to external error");
2327             RpcResult<PreloadVfModuleTopologyOperationOutput> rpcResult =
2328                 RpcResultBuilder.<PreloadVfModuleTopologyOperationOutput>status(true)
2329                     .withResult(responseBuilder.build()).build();
2330             return Futures.immediateFuture(rpcResult);
2331         }
2332
2333         // Got success from SLI
2334         try {
2335             vfModulePreloadData = vfModulePreloadDataBuilder.build();
2336             log.info(
2337                 "Updating MD-SAL for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] preloadData: "
2338                     + vfModulePreloadData);
2339             // svc-configuration-list
2340             VfModulePreloadListBuilder vfModulePreloadListBuilder = new VfModulePreloadListBuilder();
2341             vfModulePreloadListBuilder.setVfModuleName(preload_name);
2342             vfModulePreloadListBuilder.setVfModuleModelId(preload_type);
2343             vfModulePreloadListBuilder.setVfModulePreloadData(vfModulePreloadData);
2344
2345             // SDNGC-989 set merge flag to false
2346             SaveVfModulePreloadList(vfModulePreloadListBuilder.build(), false, LogicalDatastoreType.CONFIGURATION);
2347             log.info("Updating OPERATIONAL tree.");
2348             SaveVfModulePreloadList(vfModulePreloadListBuilder.build(), false, LogicalDatastoreType.OPERATIONAL);
2349         } catch (Exception e) {
2350             log.error("Caught Exception updating MD-SAL for " + SVC_OPERATION + " [" + preload_name + "," + preload_type
2351                 + "] \n", e);
2352             responseBuilder.setResponseCode("500");
2353             responseBuilder.setResponseMessage(e.toString());
2354             responseBuilder.setAckFinalIndicator("Y");
2355             log.error("Returned FAILED for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] "
2356                 + responseBuilder.build());
2357             RpcResult<PreloadVfModuleTopologyOperationOutput> rpcResult =
2358                 RpcResultBuilder.<PreloadVfModuleTopologyOperationOutput>status(false)
2359                     .withResult(responseBuilder.build()).build();
2360             return Futures.immediateFuture(rpcResult);
2361         }
2362
2363         // Update succeeded
2364         responseBuilder.setResponseCode(errorCode);
2365         responseBuilder.setAckFinalIndicator(ackFinal);
2366         if (errorMessage != null) {
2367             responseBuilder.setResponseMessage(errorMessage);
2368         }
2369         log.info("Updated MD-SAL for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] ");
2370         log.info(
2371             "Returned SUCCESS for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] " + responseBuilder
2372                 .build());
2373
2374         RpcResult<PreloadVfModuleTopologyOperationOutput> rpcResult =
2375             RpcResultBuilder.<PreloadVfModuleTopologyOperationOutput>status(true).withResult(responseBuilder.build())
2376                 .build();
2377         return Futures.immediateFuture(rpcResult);
2378     }
2379
2380
2381     @Override public Future<RpcResult<PreloadNetworkTopologyOperationOutput>> preloadNetworkTopologyOperation(
2382         PreloadNetworkTopologyOperationInput input) {
2383
2384         final String SVC_OPERATION = "preload-network-topology-operation";
2385         PreloadData preloadData = null;
2386         Properties parms = new Properties();
2387
2388         log.info(SVC_OPERATION + " called.");
2389         // create a new response object
2390         PreloadNetworkTopologyOperationOutputBuilder responseBuilder =
2391             new PreloadNetworkTopologyOperationOutputBuilder();
2392
2393         // Result from savePreloadData
2394         final SettableFuture<RpcResult<Void>> futureResult = SettableFuture.create();
2395
2396         if (input == null || input.getNetworkTopologyInformation() == null
2397             || input.getNetworkTopologyInformation().getNetworkTopologyIdentifier() == null
2398             || input.getNetworkTopologyInformation().getNetworkTopologyIdentifier().getNetworkName() == null
2399             || input.getNetworkTopologyInformation().getNetworkTopologyIdentifier().getNetworkType() == null) {
2400             log.debug("exiting " + SVC_OPERATION + " because of invalid input, null or empty vnf-name and vnf-type");
2401             responseBuilder.setResponseCode("403");
2402             responseBuilder.setResponseMessage("input, null or empty vnf-name and vnf-type");
2403             responseBuilder.setAckFinalIndicator("Y");
2404             RpcResult<PreloadNetworkTopologyOperationOutput> rpcResult =
2405                 RpcResultBuilder.<PreloadNetworkTopologyOperationOutput>status(true).withResult(responseBuilder.build())
2406                     .build();
2407             return Futures.immediateFuture(rpcResult);
2408         }
2409
2410         // Grab the name and type from the input buffer
2411         String preload_name = input.getNetworkTopologyInformation().getNetworkTopologyIdentifier().getNetworkName();
2412         String preload_type = input.getNetworkTopologyInformation().getNetworkTopologyIdentifier().getNetworkType();
2413
2414         // Make sure we have a preload_name and preload_type
2415         if (preload_name == null || preload_name.length() == 0) {
2416             log.debug("exiting " + SVC_OPERATION + " because of invalid preload-name");
2417             responseBuilder.setResponseCode("403");
2418             responseBuilder.setResponseMessage("input, invalid preload-name");
2419             responseBuilder.setAckFinalIndicator("Y");
2420             RpcResult<PreloadNetworkTopologyOperationOutput> rpcResult =
2421                 RpcResultBuilder.<PreloadNetworkTopologyOperationOutput>status(true).withResult(responseBuilder.build())
2422                     .build();
2423             return Futures.immediateFuture(rpcResult);
2424         }
2425
2426         if (preload_type == null || preload_type.length() == 0) {
2427             log.debug("exiting " + SVC_OPERATION + " because of invalid preload-type");
2428             responseBuilder.setResponseCode("403");
2429             responseBuilder.setResponseMessage("input, invalid preload-type");
2430             responseBuilder.setAckFinalIndicator("Y");
2431             RpcResult<PreloadNetworkTopologyOperationOutput> rpcResult =
2432                 RpcResultBuilder.<PreloadNetworkTopologyOperationOutput>status(true).withResult(responseBuilder.build())
2433                     .build();
2434             return Futures.immediateFuture(rpcResult);
2435         }
2436
2437         if (input.getSdncRequestHeader() != null) {
2438             responseBuilder.setSvcRequestId(input.getSdncRequestHeader().getSvcRequestId());
2439             setRequestIdAsMDC(input.getSdncRequestHeader().getSvcRequestId());
2440         }
2441
2442         PreloadDataBuilder preloadDataBuilder = new PreloadDataBuilder();
2443         getPreloadData(preload_name, preload_type, preloadDataBuilder);
2444
2445         PreloadDataBuilder operDataBuilder = new PreloadDataBuilder();
2446         getPreloadData(preload_name, preload_type, operDataBuilder, LogicalDatastoreType.OPERATIONAL);
2447
2448         //
2449         // setup a preload-data object builder
2450         // ACTION vnf-topology-operation
2451         // INPUT:
2452         //  USES sdnc-request-header;
2453         //  USES request-information;
2454         //  uses vnf-topology-information;
2455         // OUTPUT:
2456         //  USES vnf-topology-response-body;
2457         //
2458         // container preload-data
2459         //   uses vnf-configuration-information;
2460         log.info(
2461             "Adding INPUT data for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] input: " + input);
2462         PreloadNetworkTopologyOperationInputBuilder inputBuilder =
2463             new PreloadNetworkTopologyOperationInputBuilder(input);
2464         VnfSdnUtil.toProperties(parms, inputBuilder.build());
2465         log.info("Adding OPERATIONAL data for " + SVC_OPERATION + " [" + preload_name + "," + preload_type
2466             + "] operational-data: " + operDataBuilder.build());
2467         VnfSdnUtil.toProperties(parms, "operational-data", operDataBuilder);
2468
2469         // Call SLI sync method
2470         // Get SvcLogicService reference
2471         Properties respProps = null;
2472         String errorCode = "200";
2473         String errorMessage = null;
2474         String ackFinal = "Y";
2475
2476         try {
2477             if (svcLogicClient.hasGraph("VNF-API", SVC_OPERATION, null, "sync")) {
2478                 try {
2479                     respProps =
2480                         svcLogicClient.execute("VNF-API", SVC_OPERATION, null, "sync", preloadDataBuilder, parms);
2481                 } catch (Exception e) {
2482                     log.error("Caught exception executing service logic for " + SVC_OPERATION, e);
2483                     errorMessage = e.getMessage();
2484                     errorCode = "500";
2485                 }
2486             } else {
2487                 errorMessage = "No service logic active for VNF-API: '" + SVC_OPERATION + "'";
2488                 errorCode = "503";
2489             }
2490         } catch (Exception e) {
2491             errorCode = "500";
2492             errorMessage = e.getMessage();
2493             log.error("Caught exception looking for service logic", e);
2494         }
2495
2496
2497         if (respProps != null) {
2498             errorCode = respProps.getProperty("error-code");
2499             errorMessage = respProps.getProperty("error-message");
2500             ackFinal = respProps.getProperty("ack-final", "Y");
2501             // internalError = respProps.getProperty("internal-error", "false");
2502         }
2503
2504         if (errorCode != null && errorCode.length() != 0 && !(errorCode.equals("0") || errorCode.equals("200"))) {
2505             responseBuilder.setResponseCode(errorCode);
2506             responseBuilder.setResponseMessage(errorMessage);
2507             responseBuilder.setAckFinalIndicator(ackFinal);
2508
2509             VnfPreloadListBuilder preloadVnfListBuilder = new VnfPreloadListBuilder();
2510             preloadVnfListBuilder.setVnfName(preload_name);
2511             preloadVnfListBuilder.setVnfType(preload_type);
2512             preloadVnfListBuilder.setPreloadData(preloadDataBuilder.build());
2513             log.error(
2514                 "Returned FAILED for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] error code: '"
2515                     + errorCode + "', Reason: '" + errorMessage + "'");
2516             try {
2517                 SavePreloadList(preloadVnfListBuilder.build(), true, LogicalDatastoreType.CONFIGURATION);
2518             } catch (Exception e) {
2519                 log.error(
2520                     "Caught Exception updating MD-SAL for " + SVC_OPERATION + " [" + preload_name + "," + preload_type
2521                         + "] \n", e);
2522
2523             }
2524             log.debug("Sending Success rpc result due to external error");
2525             RpcResult<PreloadNetworkTopologyOperationOutput> rpcResult =
2526                 RpcResultBuilder.<PreloadNetworkTopologyOperationOutput>status(true).withResult(responseBuilder.build())
2527                     .build();
2528             return Futures.immediateFuture(rpcResult);
2529         }
2530
2531         // Got success from SLI
2532         try {
2533             preloadData = preloadDataBuilder.build();
2534             log.info(
2535                 "Updating MD-SAL for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] preloadData: "
2536                     + preloadData);
2537             // svc-configuration-list
2538             VnfPreloadListBuilder preloadVnfListBuilder = new VnfPreloadListBuilder();
2539             preloadVnfListBuilder.setVnfName(preload_name);
2540             preloadVnfListBuilder.setVnfType(preload_type);
2541             preloadVnfListBuilder.setPreloadData(preloadData);
2542
2543             // SDNGC-989 set merge flag to false
2544             SavePreloadList(preloadVnfListBuilder.build(), false, LogicalDatastoreType.CONFIGURATION);
2545             log.info("Updating OPERATIONAL tree.");
2546             SavePreloadList(preloadVnfListBuilder.build(), false, LogicalDatastoreType.OPERATIONAL);
2547         } catch (Exception e) {
2548             log.error("Caught Exception updating MD-SAL for " + SVC_OPERATION + " [" + preload_name + "," + preload_type
2549                 + "] \n", e);
2550             responseBuilder.setResponseCode("500");
2551             responseBuilder.setResponseMessage(e.toString());
2552             responseBuilder.setAckFinalIndicator("Y");
2553             log.error("Returned FAILED for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] "
2554                 + responseBuilder.build());
2555             RpcResult<PreloadNetworkTopologyOperationOutput> rpcResult =
2556                 RpcResultBuilder.<PreloadNetworkTopologyOperationOutput>status(false)
2557                     .withResult(responseBuilder.build()).build();
2558             return Futures.immediateFuture(rpcResult);
2559         }
2560
2561         // Update succeeded
2562         responseBuilder.setResponseCode(errorCode);
2563         responseBuilder.setAckFinalIndicator(ackFinal);
2564         if (errorMessage != null) {
2565             responseBuilder.setResponseMessage(errorMessage);
2566         }
2567         log.info("Updated MD-SAL for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] ");
2568         log.info(
2569             "Returned SUCCESS for " + SVC_OPERATION + " [" + preload_name + "," + preload_type + "] " + responseBuilder
2570                 .build());
2571
2572         RpcResult<PreloadNetworkTopologyOperationOutput> rpcResult =
2573             RpcResultBuilder.<PreloadNetworkTopologyOperationOutput>status(true).withResult(responseBuilder.build())
2574                 .build();
2575         return Futures.immediateFuture(rpcResult);
2576     }
2577 }

© 2017 ONAP. Copyright © The Linux Foundation ®. All Rights Reserved.
The Linux Foundation has registered trademarks and uses trademarks.
For a list of trademarks of The Linux Foundation, please see our Trademark Usage page.
Linux is a registered trademark of Linus Torvalds.
Privacy Policy and Terms of Use