package ietf-network 2015-06-08 yang models
[transportpce.git] / tests / stubpce / src / main / java / org / opendaylight / transportpce / stubpce / impl / StubpceImpl.java
1 /*
2  * Copyright © 2017 Orange, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.transportpce.stubpce.impl;
10
11 import com.google.common.base.Optional;
12 import com.google.common.util.concurrent.FutureCallback;
13 import com.google.common.util.concurrent.Futures;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import com.google.common.util.concurrent.ListeningExecutorService;
16 import com.google.common.util.concurrent.MoreExecutors;
17 import java.util.Iterator;
18 import java.util.SortedSet;
19 import java.util.concurrent.ExecutionException;
20 import java.util.concurrent.Executors;
21 import java.util.concurrent.Future;
22 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
23 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
24 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
25 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
26 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
27 import org.opendaylight.transportpce.stubpce.CheckCoherencyHardSoft;
28 import org.opendaylight.transportpce.stubpce.SendingPceRPCs;
29 import org.opendaylight.transportpce.stubpce.StubpceCompliancyCheck;
30 import org.opendaylight.transportpce.stubpce.StubpceTxRxCheck;
31 import org.opendaylight.transportpce.stubpce.topology.PathDescriptionsOrdered;
32 import org.opendaylight.transportpce.stubpce.topology.SuperNodePath;
33 import org.opendaylight.transportpce.stubpce.topology.Topology;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.CancelResourceReserveInput;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.CancelResourceReserveOutput;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.CancelResourceReserveOutputBuilder;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.PathComputationRequestInput;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.PathComputationRequestOutput;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.PathComputationRequestOutputBuilder;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.PathDescriptionList;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.PathDescriptionListBuilder;
42 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.ServicePathList;
43 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.ServicePathListBuilder;
44 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.ServicePathRpcResult;
45 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.ServicePathRpcResultBuilder;
46 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.StubpceService;
47 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.path.description.list.PathDescriptions;
48 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.path.description.list.PathDescriptionsBuilder;
49 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.path.description.list.PathDescriptionsKey;
50 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.service.path.list.ServicePaths;
51 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.service.path.list.ServicePathsBuilder;
52 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.service.path.list.ServicePathsKey;
53 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.service.path.rpc.result.PathDescriptionBuilder;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceList;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.Services;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.ServicesBuilder;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.ServicesKey;
59 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.RpcStatusEx;
60 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.ServicePathNotificationTypes;
61 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.service.path.rpc.result.PathDescription;
62 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
63 import org.opendaylight.yangtools.yang.common.RpcResult;
64 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
65 import org.slf4j.Logger;
66 import org.slf4j.LoggerFactory;
67
68 /**
69  * Class to implement StubpceService StubpceListener.
70  * @author <a href="mailto:martial.coulibaly@gfi.com">Martial Coulibaly</a> on
71  *         behalf of Orange
72  */
73
74 public class StubpceImpl implements StubpceService {
75     /** Logging. */
76     private static final Logger LOG = LoggerFactory.getLogger(StubpceImpl.class);
77     /** Permit to access database. */
78     private DataBroker db;
79     /** check service sdnc-request-header compliancy. */
80     private StubpceCompliancyCheck compliancyCheck;
81     /** check missing info on Tx/Rx for A/Z end. */
82     private StubpceTxRxCheck txrxCheck;
83     /** check coherency between hard and soft constraints. */
84     private CheckCoherencyHardSoft checkCoherencyHardSoft;
85     private NotificationPublishService notificationPublishService;
86     private ServicePathRpcResult notification;
87     private PathDescriptionBuilder pathDescriptionBuilder;
88     private SendingPceRPCs sendingPCE;
89     private final ListeningExecutorService executor = MoreExecutors
90             .listeningDecorator(Executors.newFixedThreadPool(10));
91
92     public StubpceImpl(NotificationPublishService notificationPublishService, DataBroker databroker) {
93         this.notificationPublishService = notificationPublishService;
94         this.db = databroker;
95         this.pathDescriptionBuilder = null;
96         if (initializePathDescriptionList(databroker)) {
97             fillPathDesciptionList();
98         }
99         initializeServicePathList(databroker);
100         /*if (initializeServicePathList(databroker)) {
101             fillServicePathList();
102         }*/
103     }
104
105     @Override
106     public ListenableFuture<RpcResult<CancelResourceReserveOutput>> cancelResourceReserve(CancelResourceReserveInput input) {
107         LOG.info("RPC cancelResourceReserve  request received");
108         String message = "";
109         String responseCode = "";
110         ConfigurationResponseCommonBuilder configurationResponseCommon = null;
111         String serviceName = input.getServiceName();
112         LOG.info("serviceName : {}", serviceName);
113         if (serviceName != null) {
114             this.sendingPCE = new SendingPceRPCs(input,this.db,this.executor);
115             FutureCallback<Boolean> pceCallback = new FutureCallback<Boolean>() {
116                 String message = "";
117                 ServicePathRpcResult notification = null;
118
119                 @Override
120                 public void onFailure(Throwable arg0) {
121                     LOG.error("Cancel resource failed : {}", arg0);
122                     this.notification = new ServicePathRpcResultBuilder()
123                             .setNotificationType(ServicePathNotificationTypes.CancelResourceReserve)
124                             .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
125                             .setStatusMessage("Cancel resource request failed  : " + arg0.getMessage()).build();
126                     try {
127                         StubpceImpl.this.notificationPublishService.putNotification(this.notification);
128                     } catch (InterruptedException e) {
129                         LOG.info("notification offer rejected : {}", e);
130                     }
131                 }
132
133                 @Override
134                 public void onSuccess(Boolean response) {
135                     LOG.info("response : {}", response);
136                     if (response) {
137                         this.message = "Resource cancelled !";
138                         this.notification = new ServicePathRpcResultBuilder()
139                                 .setNotificationType(ServicePathNotificationTypes.CancelResourceReserve)
140                                 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Successful)
141                                 .setStatusMessage(this.message)
142                                 .build();
143                     } else {
144                         this.message = StubpceImpl.this.sendingPCE.getError();
145                         this.notification = new ServicePathRpcResultBuilder()
146                                 .setNotificationType(ServicePathNotificationTypes.CancelResourceReserve)
147                                 .setServiceName("")
148                                 .setStatus(RpcStatusEx.Failed).setStatusMessage(this.message)
149                                 .build();
150                         this.message = "Cancel request failed !";
151                     }
152                     LOG.info(this.notification.toString());
153                     try {
154                         StubpceImpl.this.notificationPublishService.putNotification(this.notification);
155                     } catch (InterruptedException e) {
156                         LOG.info("notification offer rejected : {}", e);
157                     }
158                     LOG.info(this.message);
159                 }
160             };
161             ListenableFuture<Boolean> pce = this.sendingPCE.cancelResourceReserve();
162             Futures.addCallback(pce, pceCallback, this.executor);
163             LOG.info("Cancel Resource Request in progress ...");
164             configurationResponseCommon = new ConfigurationResponseCommonBuilder()
165                     .setAckFinalIndicator("No")
166                     .setRequestId(input.getServiceHandlerHeader().getRequestId())
167                     .setResponseMessage("Service compliant, Cancel resource request in progress...")
168                     .setResponseCode("200");
169
170             CancelResourceReserveOutputBuilder output = new CancelResourceReserveOutputBuilder()
171                     .setConfigurationResponseCommon(configurationResponseCommon.build());
172             return RpcResultBuilder.success(output.build()).buildFuture();
173         } else {
174             message = "serviceName / requestId is not correct !";
175             responseCode = "500";
176             this.notification = new ServicePathRpcResultBuilder()
177                     .setNotificationType(ServicePathNotificationTypes.CancelResourceReserve)
178                     .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
179                     .setStatusMessage(message).build();
180             try {
181                 this.notificationPublishService.putNotification(this.notification);
182             } catch (InterruptedException e) {
183                 LOG.info("notification offer rejected : {}", e);
184             }
185         }
186         configurationResponseCommon = new ConfigurationResponseCommonBuilder();
187         configurationResponseCommon.setAckFinalIndicator("Yes")
188         .setRequestId(input.getServiceHandlerHeader().getRequestId())
189         .setResponseMessage(message)
190         .setResponseCode(responseCode).build();
191         CancelResourceReserveOutputBuilder output = new CancelResourceReserveOutputBuilder();
192         output.setConfigurationResponseCommon(configurationResponseCommon.build());
193         return RpcResultBuilder.success(output.build()).buildFuture();
194     }
195
196     @Override
197     public ListenableFuture<RpcResult<PathComputationRequestOutput>> pathComputationRequest(PathComputationRequestInput input) {
198         LOG.info("RPC pathcomputation request received");
199         String message = "";
200         String responseCode = "";
201         boolean coherencyHardSoft = false;
202         boolean commonId = true;
203         ConfigurationResponseCommonBuilder configurationResponseCommon = null;
204         this.compliancyCheck = new StubpceCompliancyCheck(input.getServiceName(), input.getServiceHandlerHeader());
205         if (this.compliancyCheck.check(false, true)) {
206             LOG.info("Service compliant !");
207             /**
208              * If compliant, service-request parameters are verified in order to
209              * check if there is no missing parameter that prevents calculating
210              * a path and implement a service.
211              */
212             LOG.info("checking Tx/Rx Info for AEnd ...");
213             this.txrxCheck = new StubpceTxRxCheck(input.getServiceAEnd(), 1);
214             if (this.txrxCheck.check()) {
215                 LOG.info("Tx/Rx Info for AEnd checked !");
216                 LOG.info("checking Tx/Rx Info for ZEnd ...");
217                 this.txrxCheck = new StubpceTxRxCheck(input.getServiceZEnd(), 2);
218                 if (this.txrxCheck.check()) {
219                     LOG.info("Tx/Rx Info for ZEnd checked !");
220                     /**
221                      * If OK, common-id is verified in order to see if there is
222                      * no routing policy provided. If yes, the routing
223                      * constraints of the policy are recovered and coherency
224                      * with hard/soft constraints provided in the input of the
225                      * RPC.
226                      */
227                     if ((input.getHardConstraints() != null) || (input.getSoftConstraints() != null)) {
228                         LOG.info("Constraints specified !");
229                         this.checkCoherencyHardSoft = new CheckCoherencyHardSoft(input.getHardConstraints(),
230                                 input.getSoftConstraints());
231                         if (this.checkCoherencyHardSoft.check()) {
232                             LOG.info("hard/soft constraints coherent !");
233                             coherencyHardSoft = true;
234                         } else {
235                             LOG.info("hard/soft constraints are not coherent !");
236                             message = "hard/soft constraints are not coherent !";
237                             responseCode = "500";
238                         }
239                     } else {
240                         commonId = false;
241                     }
242                     if (!commonId || (commonId && coherencyHardSoft)) {
243                         this.notification = new ServicePathRpcResultBuilder()
244                                 .setNotificationType(ServicePathNotificationTypes.PathComputationRequest)
245                                 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
246                                 .setStatusMessage("Service compliant, submitting pathComputation Request ...").build();
247                         try {
248                             this.notificationPublishService.putNotification(this.notification);
249                         } catch (InterruptedException e) {
250                             LOG.info("notification offer rejected : {}", e);
251                         }
252                         this.sendingPCE = new SendingPceRPCs(input,this.db,this.executor);
253                         FutureCallback<Boolean> pceCallback = new FutureCallback<Boolean>() {
254                             String message = "";
255                             ServicePathRpcResult notification = null;
256
257                             @Override
258                             public void onFailure(Throwable arg0) {
259                                 LOG.error("Failure message : {}", arg0.toString());
260                                 LOG.error("Path calculation failed !");
261                                 this.notification = new ServicePathRpcResultBuilder()
262                                         .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
263                                         .setStatusMessage("PCR Request failed  : " + arg0.getMessage()).build();
264                                 try {
265                                     StubpceImpl.this.notificationPublishService.putNotification(this.notification);
266                                 } catch (InterruptedException e) {
267                                     LOG.info("notification offer rejected : {}", e);
268                                 }
269                             }
270
271                             @Override
272                             public void onSuccess(Boolean response) {
273                                 LOG.info("response : {}", response);
274                                 if (response) {
275                                     this.message = "Path Computated !";
276                                     ServicePathRpcResultBuilder tmp = new ServicePathRpcResultBuilder()
277                                             .setNotificationType(ServicePathNotificationTypes.PathComputationRequest)
278                                             .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Successful)
279                                             .setStatusMessage(this.message);
280                                     StubpceImpl.this.pathDescriptionBuilder = StubpceImpl.this.sendingPCE.getPathDescription();
281                                     if (StubpceImpl.this.pathDescriptionBuilder != null) {
282                                         PathDescription pathDescription = new org.opendaylight.yang.gen.v1.http.org
283                                                 .transportpce.b.c._interface.servicepath.rev170426.service.path
284                                                 .rpc.result.PathDescriptionBuilder()
285                                                 .setAToZDirection(StubpceImpl.this.pathDescriptionBuilder.getAToZDirection())
286                                                 .setZToADirection(StubpceImpl.this.pathDescriptionBuilder.getZToADirection())
287                                                 .build();
288                                         tmp.setPathDescription(new PathDescriptionBuilder()
289                                                 .setAToZDirection(pathDescription.getAToZDirection())
290                                                 .setZToADirection(pathDescription.getZToADirection())
291                                                 .build());
292                                     }
293                                     this.notification = tmp.build();
294                                 } else {
295                                     this.message = StubpceImpl.this.sendingPCE.getError();
296                                     this.notification = new ServicePathRpcResultBuilder()
297                                             .setNotificationType(ServicePathNotificationTypes.PathComputationRequest)
298                                             .setServiceName("")
299                                             .setStatus(RpcStatusEx.Failed).setStatusMessage(this.message)
300                                             .build();
301                                     this.message = "Path not calculated!";
302                                 }
303                                 try {
304                                     StubpceImpl.this.notificationPublishService.putNotification(this.notification);
305                                 } catch (InterruptedException e) {
306                                     LOG.info("notification offer rejected : {}", e);
307                                 }
308                                 LOG.info(this.message);
309                             }
310                         };
311                         ListenableFuture<Boolean> pce = this.sendingPCE.pathComputation();
312                         Futures.addCallback(pce, pceCallback, this.executor);
313                         LOG.info("PathComputation Request in progress ...");
314                         configurationResponseCommon = new ConfigurationResponseCommonBuilder()
315                                 .setAckFinalIndicator("No")
316                                 .setRequestId(input.getServiceHandlerHeader().getRequestId())
317                                 .setResponseMessage("Service compliant, Path calculating in progress...")
318                                 .setResponseCode("200");
319
320                         PathComputationRequestOutputBuilder output = new PathComputationRequestOutputBuilder()
321                                 .setConfigurationResponseCommon(configurationResponseCommon.build());
322                         return RpcResultBuilder.success(output.build()).buildFuture();
323                     }
324
325                 } else {
326                     message = this.txrxCheck.getMessage();
327                     responseCode = "500";
328                 }
329             } else {
330                 message = this.txrxCheck.getMessage();
331                 responseCode = "500";
332             }
333         } else {
334             message = this.compliancyCheck.getMessage();
335             responseCode = "500";
336             this.notification = new ServicePathRpcResultBuilder()
337                     .setNotificationType(ServicePathNotificationTypes.PathComputationRequest)
338                     .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
339                     .setStatusMessage("Service not compliant : " + message).build();
340             try {
341                 this.notificationPublishService.putNotification(this.notification);
342             } catch (InterruptedException e) {
343                 LOG.info("notification offer rejected : {}", e);
344             }
345         }
346         configurationResponseCommon = new ConfigurationResponseCommonBuilder();
347         configurationResponseCommon.setAckFinalIndicator("Yes")
348         .setRequestId(input.getServiceHandlerHeader().getRequestId())
349         .setResponseMessage(message)
350         .setResponseCode(responseCode).build();
351         PathComputationRequestOutputBuilder output = new PathComputationRequestOutputBuilder();
352         output.setConfigurationResponseCommon(configurationResponseCommon.build());
353         return RpcResultBuilder.success(output.build()).buildFuture();
354
355     }
356
357     /**
358      * Initialize PathDescriptionList Structure on DataStore.
359      *
360      * @param DataBroker
361      *            Access DataStore
362      */
363     private boolean initializePathDescriptionList(DataBroker db) {
364         Boolean result = true;
365         LOG.info("Preparing to initialize the PathDescription List");
366         WriteTransaction transaction = db.newWriteOnlyTransaction();
367         InstanceIdentifier<PathDescriptionList> iid = InstanceIdentifier.create(PathDescriptionList.class);
368         PathDescriptionList pathDescriptionList = new PathDescriptionListBuilder().build();
369         transaction.put(LogicalDatastoreType.OPERATIONAL, iid, pathDescriptionList);
370         Future<Void> future = transaction.submit();
371         try {
372             Futures.getChecked(future, ExecutionException.class);
373         } catch (ExecutionException e) {
374             LOG.error("Failed to create PathDescription List");
375             result = false;
376         }
377         return result;
378     }
379
380     /**
381      * Initialize ServicePathList Structure on DataStore.
382      *
383      * @param DataBroker
384      *            Access DataStore
385      * @return <code>true</code> if ok, <code>false</code> else
386      */
387     private boolean initializeServicePathList(DataBroker db) {
388         Boolean result = true;
389         LOG.info("Preparing to initialize the ServicePathList registry");
390         WriteTransaction transaction = db.newWriteOnlyTransaction();
391         InstanceIdentifier<ServicePathList> iid = InstanceIdentifier.create(ServicePathList.class);
392         ServicePathList servicePathList = new ServicePathListBuilder().build();
393         transaction.put(LogicalDatastoreType.OPERATIONAL, iid, servicePathList);
394         Future<Void> future = transaction.submit();
395         try {
396             Futures.getChecked(future, ExecutionException.class);
397         } catch (ExecutionException e) {
398             LOG.error("Failed to create ServicePathList List : {}", e.toString());
399             result = false;
400         }
401         return result;
402     }
403
404     /**
405      * fill PathDescriptionList
406      * with direct paths and
407      * indirect paths.
408      */
409     private void fillPathDesciptionList() {
410         LOG.info("filling PathDescription List...");
411         Topology topo = new Topology();
412         topo.start();
413         LOG.info("Network : {}", topo.getNetwork());
414         SuperNodePath superNodePath = new SuperNodePath(topo.getNetwork());
415         String aend = "NodeA";
416         String zend = "NodeZ";
417         superNodePath.run(aend, zend);
418         fill(superNodePath.getDirectPathDesc(aend, zend, superNodePath.getPaths()));
419         fill(superNodePath.getIndirectPathDesc(aend, zend, superNodePath.getPaths()));
420     }
421
422     /**
423      * fill datastore with
424      * Pathdescriptions List.
425      *
426      * @param sortedSet PathDescriptionsOrdered List
427      */
428     private void fill(SortedSet<PathDescriptionsOrdered> sortedSet) {
429         InstanceIdentifier<PathDescriptions> iid;
430         WriteTransaction writeTx;
431         Future<Void> future;
432         if (!sortedSet.isEmpty()) {
433             Iterator<PathDescriptionsOrdered> it = sortedSet.iterator();
434             while (it.hasNext()) {
435                 PathDescriptions pathDesc = it.next().getPathDescriptions();
436                 if (pathDesc != null) {
437                     iid = InstanceIdentifier.create(PathDescriptionList.class)
438                             .child(PathDescriptions.class, new PathDescriptionsKey(pathDesc.getPathName()));
439                     writeTx = this.db.newWriteOnlyTransaction();
440                     writeTx.put(LogicalDatastoreType.OPERATIONAL, iid, pathDesc);
441                     future = writeTx.submit();
442                     try {
443                         Futures.getChecked(future, ExecutionException.class);
444                     } catch (ExecutionException e) {
445                         LOG.error("Failed to write PathDescriptions to PathDescriptionsList : {}", e.toString());
446                     }
447                 } else {
448                     LOG.error("PathDescriptions gets is null !");
449                 }
450             }
451         } else {
452             LOG.info("PathDescriptions List is empty !");
453         }
454     }
455
456     /**
457      * read Service from ServiceList DataStore.
458      *
459      * @param serviceName
460      *            Name of Service
461      *
462      * @return <code>Services</code>
463      */
464     @SuppressWarnings("unused")
465     private Services readServiceList(String serviceName) {
466         Services result = null;
467         ReadOnlyTransaction readTx = this.db.newReadOnlyTransaction();
468         InstanceIdentifier<Services> iid = InstanceIdentifier.create(ServiceList.class).child(Services.class,
469                 new ServicesKey(serviceName));
470         Future<Optional<Services>> future = readTx.read(LogicalDatastoreType.OPERATIONAL,iid);
471         Optional<Services> optional = Optional.absent();
472         try {
473             optional = Futures.getChecked(future, ExecutionException.class);
474         } catch (ExecutionException e) {
475             LOG.error("Reading service failed:", e);
476         }
477         if (optional.isPresent()) {
478             LOG.debug("Service '{}' present !", serviceName);
479             result = new ServicesBuilder(optional.get()).build();
480         }
481         return result;
482     }
483
484     /**
485      * read ServicePath Service from ServicePathList DataStore.
486      *
487      * @param serviceName
488      *            Name of ServicePath
489      *
490      * @return <code>Services</code>
491      */
492     @SuppressWarnings("unused")
493     private ServicePaths readServicePathList(String serviceName) {
494         ServicePaths result = null;
495         ReadOnlyTransaction readTx = this.db.newReadOnlyTransaction();
496         InstanceIdentifier<ServicePaths> iid = InstanceIdentifier.create(ServicePathList.class)
497                 .child(ServicePaths.class, new ServicePathsKey(serviceName));
498         Future<Optional<ServicePaths>> future = readTx.read(LogicalDatastoreType.OPERATIONAL,iid);
499         Optional<ServicePaths> optional = Optional.absent();
500         try {
501             optional = Futures.getChecked(future, ExecutionException.class);
502         } catch (ExecutionException e) {
503             LOG.error("Reading service failed:", e);
504         }
505         if (optional.isPresent()) {
506             LOG.debug("Service '{}' present !", serviceName);
507             result = new ServicePathsBuilder(optional.get()).build();
508         }
509         return result;
510     }
511
512     /**
513      * read PathDescription information from PathDescriptionList.
514      *
515      * @param pathName
516      *            Name of PathDescription
517      *
518      * @return <code>PathDescriptions</code>
519      */
520     @SuppressWarnings("unused")
521     private PathDescriptions readPathDescriptionList(String pathName) {
522         PathDescriptions result = null;
523         ReadOnlyTransaction readTx = this.db.newReadOnlyTransaction();
524         InstanceIdentifier<PathDescriptions> iid = InstanceIdentifier.create(PathDescriptionList.class)
525                 .child(PathDescriptions.class, new PathDescriptionsKey(pathName));
526         Future<Optional<PathDescriptions>> future = readTx.read(LogicalDatastoreType.OPERATIONAL,iid);
527         Optional<PathDescriptions> optional = Optional.absent();
528         try {
529             optional = Futures.getChecked(future, ExecutionException.class);
530         } catch (ExecutionException e) {
531             LOG.error("Reading service failed:", e);
532         }
533         if (optional.isPresent()) {
534             LOG.debug("PathDescritions '{}' present !", pathName);
535             result = new PathDescriptionsBuilder(optional.get()).build();
536         }
537         return result;
538     }
539
540     /**
541      * register ServicePath Service to ServicePathList with PathDescription
542      * information.
543      *
544      * @param input
545      *            PathComputationRequestInput
546      * @return String operations result, null if ok or not otherwise
547      */
548     @SuppressWarnings("unused")
549     private String writeServicePathList(PathComputationRequestInput input) {
550         String serviceName = input.getServiceName();
551         LOG.debug("Write ServicePath '{}' Service", serviceName);
552         String result = null;
553         LOG.debug("Writing '{}' ServicePath", serviceName);
554         InstanceIdentifier<ServicePaths> iid = InstanceIdentifier.create(ServicePathList.class)
555                 .child(ServicePaths.class, new ServicePathsKey(serviceName));
556
557         org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.service
558             .path.PathDescriptionBuilder path = new org.opendaylight.yang.gen.v1.http.org.transportpce
559             .b.c._interface.service.types.rev170426.service.path.PathDescriptionBuilder();
560         path.setAToZDirection(this.pathDescriptionBuilder.getAToZDirection());
561         path.setZToADirection(this.pathDescriptionBuilder.getZToADirection());
562         ServicePaths service = new ServicePathsBuilder().setServicePathName(input.getServiceName())
563                 .setSoftConstraints(input.getSoftConstraints()).setHardConstraints(input.getHardConstraints())
564                 .setPathDescription(path.build()).build();
565         WriteTransaction writeTx = this.db.newWriteOnlyTransaction();
566         writeTx.put(LogicalDatastoreType.OPERATIONAL, iid, service);
567         Future<Void> future = writeTx.submit();
568         try {
569             Futures.getChecked(future, ExecutionException.class);
570             result = null;
571         } catch (ExecutionException e) {
572             LOG.error("Failed to write service to Service List");
573             result = "Failed to write service to Service List";
574         }
575         return result;
576     }
577
578     public PathDescriptionBuilder getPathDescriptionBuilder() {
579         return this.pathDescriptionBuilder;
580     }
581
582     public void setPathDescriptionBuilder(PathDescriptionBuilder pathDescriptionBuilder) {
583         this.pathDescriptionBuilder = pathDescriptionBuilder;
584     }
585 }