1fa5d4e04a287f7018fe41cb8efa19780736257c
[transportpce.git] / servicehandler / src / main / java / org / opendaylight / transportpce / servicehandler / impl / ServicehandlerImpl.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.servicehandler.impl;
10
11 import com.google.common.base.Optional;
12
13 import com.google.common.util.concurrent.FutureCallback;
14 import com.google.common.util.concurrent.Futures;
15 import com.google.common.util.concurrent.ListenableFuture;
16 import com.google.common.util.concurrent.ListeningExecutorService;
17 import com.google.common.util.concurrent.MoreExecutors;
18
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.concurrent.ExecutionException;
22 import java.util.concurrent.Executors;
23 import java.util.concurrent.Future;
24
25 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
26 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
27 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
28 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
29 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
30 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
31 import org.opendaylight.transportpce.servicehandler.CheckCoherencyHardSoft;
32 import org.opendaylight.transportpce.servicehandler.MappingAndSendingPCRequest;
33 import org.opendaylight.transportpce.servicehandler.MappingAndSendingSIRequest;
34 import org.opendaylight.transportpce.servicehandler.ServicehandlerCompliancyCheck;
35 import org.opendaylight.transportpce.servicehandler.ServicehandlerTxRxCheck;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev170930.ServiceRpcResultSh;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev170930.ServiceRpcResultShBuilder;
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.ServicePathRpcResult;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.StubpceListener;
42 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceRpcResultSp;
43 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.StubrendererListener;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ConnectionType;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.RpcActions;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ServiceEndpoint;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ServiceNotificationTypes;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommon;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.sdnc.request.header.SdncRequestHeader;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.ServiceAEnd;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.ServiceAEndBuilder;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.ServiceZEnd;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.ServiceZEndBuilder;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.Topology;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.TopologyBuilder;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.LifecycleState;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RpcStatus;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.State;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.HardConstraints;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.SoftConstraints;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.EquipmentNotificationInput;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.EquipmentNotificationOutput;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.NetworkReOptimizationInput;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.NetworkReOptimizationOutput;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.OrgOpenroadmServiceService;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInput;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateOutput;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateOutputBuilder;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteInput;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteOutput;
72 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteOutputBuilder;
73 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceFeasibilityCheckInput;
74 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceFeasibilityCheckOutput;
75 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceFeasibilityCheckOutputBuilder;
76 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceList;
77 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceListBuilder;
78 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureInput;
79 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureOutput;
80 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureOutputBuilder;
81 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteConfirmInput;
82 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteConfirmOutput;
83 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteInput;
84 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteOutput;
85 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationInput;
86 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationOutput;
87 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationOutputBuilder;
88 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReversionInput;
89 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReversionOutput;
90 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRollInput;
91 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRollOutput;
92 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInput;
93 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateOutput;
94 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceDeleteInput;
95 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceDeleteOutput;
96 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.Services;
97 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.ServicesBuilder;
98 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.ServicesKey;
99 import org.opendaylight.yang.gen.v1.http.org.openroadm.topology.rev161014.topology.AToZ;
100 import org.opendaylight.yang.gen.v1.http.org.openroadm.topology.rev161014.topology.AToZBuilder;
101 import org.opendaylight.yang.gen.v1.http.org.openroadm.topology.rev161014.topology.AToZKey;
102 import org.opendaylight.yang.gen.v1.http.org.openroadm.topology.rev161014.topology.ZToA;
103 import org.opendaylight.yang.gen.v1.http.org.openroadm.topology.rev161014.topology.ZToABuilder;
104 import org.opendaylight.yang.gen.v1.http.org.openroadm.topology.rev161014.topology.ZToAKey;
105 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.RpcStatusEx;
106 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.response.parameters.sp.response.parameters.PathDescription;
107 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.response.parameters.sp.response.parameters.PathDescriptionBuilder;
108 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.service.rpc.result.sp.PathTopology;
109 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.service.rpc.result.sp.PathTopologyBuilder;
110 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
111 import org.opendaylight.yangtools.yang.common.RpcResult;
112 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
113 import org.slf4j.Logger;
114 import org.slf4j.LoggerFactory;
115
116
117 /**
118  * Class to implement ServicehandlerService and ServicehandlerListener.
119  *
120  * @author <a href="mailto:martial.coulibaly@gfi.com">Martial Coulibaly</a> on behalf of Orange
121  */
122 public class ServicehandlerImpl implements OrgOpenroadmServiceService,StubpceListener,
123     StubrendererListener,AutoCloseable {
124     /** Logging. */
125     private static final Logger LOG = LoggerFactory.getLogger(ServicehandlerImpl.class);
126     /** Permit to access database. */
127     private DataBroker db;
128     /** check service sdnc-request-header compliancy. */
129     private ServicehandlerCompliancyCheck compliancyCheck;
130     /** check missing info on Tx/Rx for A/Z end. */
131     private ServicehandlerTxRxCheck txrxCheck;
132     /** check coherency between hard and soft constraints. */
133     private CheckCoherencyHardSoft checkCoherencyHardSoft;
134     /**
135      * Map and Send PCE requests : -
136      * path-computation-request/cancel-resource-reserve.
137      */
138     private MappingAndSendingPCRequest mappingAndSendingPCRequest;
139     /**
140      * Map and Send Service Implemention requests : - service
141      * implementation/service delete.
142      */
143     private MappingAndSendingSIRequest mappingAndSendingSIRequest;
144
145     private RpcProviderRegistry rpcRegistry;
146     private NotificationPublishService notificationPublishService;
147     private final ListeningExecutorService executor;
148
149     private ServicePathRpcResult servicePathRpcResult = null;
150     private ServiceRpcResultSp serviceRpcResultSp = null;
151
152     private String notificationUrl = "";
153     private RpcActions action;
154
155     private PathDescription pathDescription;
156     private PathTopology pathTopology;
157     private ServiceCreateInput serviceCreateInput;
158     private ServiceDeleteInput serviceDeleteInput;
159     private ServiceReconfigureInput serviceReconfigureInput;
160     private Services service;
161     private ServiceFeasibilityCheckInput serviceFeasibilityCheckInput;
162
163     public ServicehandlerImpl(DataBroker databroker, RpcProviderRegistry rpcRegistry,
164             NotificationPublishService notificationPublishService) {
165         this.db = databroker;
166         this.rpcRegistry = rpcRegistry;
167         this.notificationPublishService = notificationPublishService;
168         executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(5));
169         serviceCreateInput = null;
170         setServiceDeleteInput(null);
171         setServiceReconfigureInput(null);
172         initializeDataTree(db);
173     }
174
175     /**
176      * delete service from
177      * datastore after receiving
178      * Stubrenderer notification.
179      *
180      */
181     private void deleteServiceFromDatastore() {
182         String serviceName = null;
183         if (serviceDeleteInput != null) {
184             LOG.info("deleteServiceFromDatastore came from RPC serviceDelete");
185             serviceName = serviceDeleteInput.getServiceDeleteReqInfo().getServiceName();
186         } else if (service != null) {
187             LOG.info("deleteServiceFromDatastore came from RPC serviceRestoration");
188             serviceName = service.getServiceName();
189         }
190         if (serviceName != null) {
191             LOG.info("deleting service '" + serviceName + "'from datastore ...");
192             ServiceRpcResultSh notification = null;
193             String message = "";
194             /**
195              * Service delete confirmed deleting service from
196              * database
197              */
198             if (writeOrModifyOrDeleteServiceList(serviceName, null,
199                     null,1) == null) {
200                 /** Service delete. */
201                 message = "Service deleted from database";
202             } else {
203                 message = "deleting service from database failed !";
204             }
205             LOG.info(message);
206             notification = new ServiceRpcResultShBuilder()
207                     .setNotificationType(ServiceNotificationTypes.ServiceDeleteResult)
208                     .setServiceName(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName())
209                     .setStatus(RpcStatusEx.Successful).setStatusMessage(message).build();
210             try {
211                 notificationPublishService.putNotification(notification);
212             } catch (InterruptedException e) {
213                 LOG.info("notification offer rejected : " + e);
214             }
215         } else {
216             LOG.error("Parameter 'ServiceName' fro deleteServiceFromDatastore is null !");
217         }
218     }
219
220
221     /**
222      *Put Service status to up
223      *and add topology information
224      *after receiving Stubrenderer
225      *service implementation
226      *notification.
227      *
228      * @param input ServiceCreateInput or
229      */
230     private <T> void updateServiceStatus(T input) {
231         LOG.info("Updating Service Status ...");
232         ServiceRpcResultSh notification = null;
233         String message = "";
234         String serviceName = null;
235         ServiceNotificationTypes notif = null;
236         if (input instanceof ServiceCreateInput) {
237             LOG.info("Updating Service Status came from RPC serviceCreateInput ...");
238             serviceName = serviceCreateInput.getServiceName();
239             notif = ServiceNotificationTypes.ServiceCreateResult;
240         } else if (input instanceof ServiceReconfigureInput) {
241             LOG.info("Updating Service Status came from RPC serviceReconfigure ...");
242             serviceName = serviceReconfigureInput.getNewServiceName();
243             notif = ServiceNotificationTypes.ServiceReconfigureResult;
244         } else if (input instanceof Services) {
245             LOG.info("Updating Service Status came from RPC serviceRestoration ...");
246             serviceName = service.getServiceName();
247             notif = ServiceNotificationTypes.ServiceRestorationResult;
248         }
249         if (serviceName != null && notif != null) {
250             if (pathTopology != null) {
251                 LOG.info("PathTopology contains in Stubrenderer notification received !");
252                 Topology topo = new TopologyBuilder()
253                         .setAToZ(pathTopology.getAToZ())
254                         .setZToA(pathTopology.getZToA())
255                         .build();
256
257                 /**
258                  * Service implemented setting
259                  * Service op status to up.
260                  */
261                 if (writeOrModifyOrDeleteServiceList(serviceName, null,topo,0) == null) {
262                     /**
263                      * Service modified.
264                      */
265                     StringBuilder build = new StringBuilder();
266                     build.append(message);
267                     build.append(" : Service Op Status changed to Up !");
268                     message = build.toString();
269                 } else {
270                     StringBuilder build = new StringBuilder();
271                     build.append(message);
272                     build.append(" but Failed to modify service from Service List !");
273                     message = build.toString();
274                 }
275                 notification = new ServiceRpcResultShBuilder()
276                         .setNotificationType(notif)
277                         .setServiceName(serviceCreateInput.getServiceName())
278                         .setStatus(RpcStatusEx.Successful).setStatusMessage(message)
279                         .build();
280                 try {
281                     notificationPublishService.putNotification(notification);
282                 } catch (InterruptedException e) {
283                     LOG.info("notification offer rejected : " + e);
284                 }
285             } else {
286                 message = "pathTopology not in stubrenderer notification, cancelling pce resource reserve ...";
287                 LOG.info(message);
288                 notification = new ServiceRpcResultShBuilder()
289                         .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
290                         .setServiceName(serviceCreateInput.getServiceName())
291                         .setStatus(RpcStatusEx.Failed)
292                         .setStatusMessage("message")
293                         .build();
294                 try {
295                     notificationPublishService.putNotification(notification);
296                 } catch (InterruptedException e) {
297                     LOG.info("notification offer rejected : " + e);
298                 }
299                 pceCancelResResource();
300             }
301         } else {
302             LOG.info("Parameters 'serviceName' or/ and 'notiftype' is null");
303         }
304     }
305
306     /**
307      * Send pathComputation
308      * request to PCE.
309      *
310      * @param input ServiceCreate or ServiceReconfigure or Services
311      */
312     private <T> void  pcePathComputation(T input) {
313         LOG.info("sending pathcomputation request to pce ...");
314         ServiceRpcResultSh notification = null;
315         String serviceName = null;
316         ServiceNotificationTypes type = null;
317         /**
318          * Before sending the PCE request, input data need to be
319          * formatted according to the Service Handler PCE
320          * interface data model.
321          */
322         if (input instanceof ServiceReconfigureInput) {
323             LOG.info("PCR came from RPC serviceReconfigure ...");
324             ServiceReconfigureInput tmp = (ServiceReconfigureInput)input;
325             serviceName = tmp.getNewServiceName();
326             type = ServiceNotificationTypes.ServiceReconfigureResult;
327             mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, tmp, true);
328         } else if (input instanceof ServiceCreateInput) {
329             LOG.info("PCR came from RPC serviceCreate ...");
330             ServiceCreateInput tmp = (ServiceCreateInput)input;
331             serviceName = tmp.getServiceName();
332             type = ServiceNotificationTypes.ServiceCreateResult;
333             mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, tmp, true);
334         } else if (input instanceof Services) {
335             LOG.info("PCR came from RPC serviceRestoration ...");
336             Services tmp = (Services)input;
337             serviceName = tmp.getServiceName();
338             type = ServiceNotificationTypes.ServiceRestorationResult;
339             mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, tmp, true);
340         } else if (input instanceof ServiceFeasibilityCheckInput) {
341             LOG.info("PCR came from RPC ServiceFeasibilityCheck ...");
342             ServiceFeasibilityCheckInput tmp = (ServiceFeasibilityCheckInput)input;
343             serviceName = "no name";
344             type = ServiceNotificationTypes.ServiceCreateResult;
345             mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, tmp, false);
346         }
347         final String name = serviceName;
348         final ServiceNotificationTypes notifType = type;
349
350         /**
351          * Once PCE request is being sent to the PCE on
352          * interface B, PCE reply is expected until a timer
353          * expires.
354          */
355         notification = new ServiceRpcResultShBuilder()
356                 .setNotificationType(notifType)
357                 .setServiceName(serviceName).setStatus(RpcStatusEx.Pending)
358                 .setStatusMessage("Service compliant, submitting PathComputation Request ...").build();
359         try {
360             notificationPublishService.putNotification(notification);
361         } catch (InterruptedException e) {
362             LOG.info("notification offer rejected : " + e);
363         }
364         FutureCallback<Boolean> pceCallback =  new FutureCallback<Boolean>() {
365             String message = "";
366             ServiceRpcResultSh notification = null;
367
368             @Override
369             public void onSuccess(Boolean response) {
370                 if (response) {
371                     /**
372                      * If PCE reply is received before timer
373                      * expiration with a positive result, a
374                      * service is created with admin and
375                      * operational status 'down'.
376                      */
377                     message = "PCE replied to PCR Request !";
378                     LOG.info(message);
379                     notification = new ServiceRpcResultShBuilder()
380                             .setNotificationType(notifType)
381                             .setServiceName(name).setStatus(RpcStatusEx.Pending)
382                             .setStatusMessage(message).build();
383                     try {
384                         notificationPublishService.putNotification(notification);
385                     } catch (InterruptedException e) {
386                         LOG.info("notification offer rejected : " + e);
387                     }
388                 } else {
389                     message = mappingAndSendingPCRequest.getError();
390                     notification = new ServiceRpcResultShBuilder()
391                             .setNotificationType(notifType)
392                             .setServiceName("").setStatus(RpcStatusEx.Failed).setStatusMessage(message)
393                             .build();
394                     try {
395                         notificationPublishService.putNotification(notification);
396                     } catch (InterruptedException e) {
397                         LOG.info("notification offer rejected : " + e);
398                     }
399                 }
400             }
401
402             @Override
403             public void onFailure(Throwable arg0) {
404                 LOG.error("Path not calculated..");
405                 notification = new ServiceRpcResultShBuilder()
406                         .setNotificationType(notifType)
407                         .setServiceName(name).setStatus(RpcStatusEx.Failed)
408                         .setStatusMessage("PCR Request failed  : " + arg0.getMessage()).build();
409                 try {
410                     notificationPublishService.putNotification(notification);
411                 } catch (InterruptedException e) {
412                     LOG.info("notification offer rejected : " + e);
413                 }
414
415             }
416         };
417         ListenableFuture<Boolean> pce = mappingAndSendingPCRequest.pathComputationRequest();
418         Futures.addCallback(pce, pceCallback, executor);
419     }
420
421     /**
422      * Send RPC cancel reserve
423      * resource to PCE.
424      */
425     private void pceCancelResResource() {
426         LOG.info("sending RPC cancel reserve resource to PCE ...");
427         Services pceService = null;
428         ServiceNotificationTypes notif = null;
429         if (serviceDeleteInput != null) {
430             LOG.info("pceCancelResResource came from RPC serviceDelete");
431             notif = ServiceNotificationTypes.ServiceDeleteResult;
432             String serviceName = serviceDeleteInput.getServiceDeleteReqInfo().getServiceName();
433             if (serviceName != null) {
434                 pceService = readServiceList(serviceName);
435             } else {
436                 LOG.info("Parameter 'serviceName' for pceCancelResResource is null");
437             }
438         } else if (service != null) {
439             notif = ServiceNotificationTypes.ServiceRestorationResult;
440             LOG.info("pceCancelResResource came from RPC serviceRestoration");
441             pceService = service;
442         } else if (serviceReconfigureInput != null) {
443             notif = ServiceNotificationTypes.ServiceReconfigureResult;
444             LOG.info("pceCancelResResource came from RPC serviceReconfigure");
445             String serviceName = serviceReconfigureInput.getServiceName();
446             if (serviceName != null) {
447                 pceService = readServiceList(serviceName);
448             } else {
449                 LOG.info("Parameter 'serviceName' for pceCancelResResource is null");
450             }
451         } else if (serviceCreateInput != null) {
452             notif = ServiceNotificationTypes.ServiceCreateResult;
453             LOG.info("pceCancelResResource came from RPC serviceCreate");
454             String serviceName = serviceCreateInput.getServiceName();
455             if (serviceName != null) {
456                 pceService = readServiceList(serviceName);
457             } else {
458                 LOG.info("Parameter 'serviceName' for pceCancelResResource is null");
459             }
460         }
461         if (pceService != null && notif != null) {
462             final Services cancelService = pceService;
463             final ServiceNotificationTypes type = notif;
464             mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, pceService, false);
465             FutureCallback<Boolean> pceCallback =  new FutureCallback<Boolean>() {
466                 String message = "";
467                 ServiceRpcResultSh notification = null;
468                 @Override
469                 public void onSuccess(Boolean response) {
470                     if (response) {
471                         /**
472                          * If PCE reply is received before timer
473                          * expiration with a positive result, a
474                          * service is created with admin and
475                          * operational status 'down'.
476                          */
477                         message = "PCE replied to cancel resource Request !";
478                         LOG.info(message);
479                         notification = new ServiceRpcResultShBuilder()
480                                 .setNotificationType(type)
481                                 .setServiceName(cancelService.getServiceName()).setStatus(RpcStatusEx.Pending)
482                                 .setStatusMessage(message).build();
483                         try {
484                             notificationPublishService.putNotification(notification);
485                         } catch (InterruptedException e) {
486                             LOG.info("notification offer rejected : " + e);
487                         }
488                     } else {
489                         message = mappingAndSendingPCRequest.getError();
490                         notification = new ServiceRpcResultShBuilder()
491                                 .setNotificationType(type)
492                                 .setServiceName("").setStatus(RpcStatusEx.Failed).setStatusMessage(message)
493                                 .build();
494                         try {
495                             notificationPublishService.putNotification(notification);
496                         } catch (InterruptedException e) {
497                             LOG.info("notification offer rejected : " + e);
498                         }
499                     }
500                 }
501
502                 @Override
503                 public void onFailure(Throwable arg0) {
504                     message = "Cancel resource request failed !";
505                     LOG.error(message);
506                     notification = new ServiceRpcResultShBuilder()
507                             .setNotificationType(type)
508                             .setServiceName(cancelService.getServiceName()).setStatus(RpcStatusEx.Failed)
509                             .setStatusMessage(message + " : " + arg0.getMessage()).build();
510                     try {
511                         notificationPublishService.putNotification(notification);
512                     } catch (InterruptedException e) {
513                         LOG.info("notification offer rejected : " + e);
514                     }
515
516                 }
517             };
518             ListenableFuture<Boolean> pce = mappingAndSendingPCRequest.cancelResourceReserve();
519             Futures.addCallback(pce, pceCallback, executor);
520         }
521     }
522
523     private void stubrendererDelete() {
524         LOG.info("sending RPC service delete to stubrenderer ...");
525         String tmp = null;
526         String id = null;
527         if (service != null) {
528             LOG.info("RPC service delete came from RPC serviceRestoration !");
529             tmp = service.getServiceName();
530             id = service.getCommonId();
531         } else if (serviceDeleteInput != null) {
532             LOG.info("RPC service delete came from ServiceDelete !");
533             tmp = serviceDeleteInput.getServiceDeleteReqInfo().getServiceName();
534             id = serviceDeleteInput.getSdncRequestHeader().getRequestId();
535         }
536
537         if (tmp != null && id != null) {
538             final String serviceName = tmp;
539             LOG.info("stubrendererDelete service '" + serviceName + "'");
540             mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry, id, serviceName);
541             ListenableFuture<Boolean> renderer = mappingAndSendingSIRequest.serviceDelete();
542             FutureCallback<Boolean> rendererCallback = new FutureCallback<Boolean>() {
543                 String message = "";
544                 ServiceRpcResultSh notification = null;
545
546                 @Override
547                 public void onFailure(Throwable arg0) {
548                     message = "ServiceDelete Request failed : " + arg0;
549                     LOG.error("ServiceDelete Request failed !");
550                     notification = new ServiceRpcResultShBuilder()
551                             .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
552                             .setServiceName(serviceName).setStatus(RpcStatusEx.Failed)
553                             .setStatusMessage(message).build();
554                     try {
555                         notificationPublishService.putNotification(notification);
556                     } catch (InterruptedException e) {
557                         LOG.info("notification offer rejected : " + e);
558                     }
559
560                 }
561
562                 @Override
563                 public void onSuccess(Boolean response) {
564                     if (response) {
565                         message = "Service deleted !";
566                         notification = new ServiceRpcResultShBuilder()
567                                 .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
568                                 .setServiceName(serviceName).setStatus(RpcStatusEx.Pending)
569                                 .setStatusMessage(message).build();
570                         try {
571                             notificationPublishService.putNotification(notification);
572                         } catch (InterruptedException e) {
573                             LOG.info("notification offer rejected : " + e);
574                         }
575                     } else {
576                         message = "deleting service failed !";
577                         notification = new ServiceRpcResultShBuilder()
578                                 .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
579                                 .setServiceName(serviceName).setStatus(RpcStatusEx.Failed)
580                                 .setStatusMessage(message)
581                                 .build();
582                         try {
583                             notificationPublishService.putNotification(notification);
584                         } catch (InterruptedException e) {
585                             LOG.info("notification offer rejected : " + e);
586                         }
587                     }
588                 }
589             };
590             Futures.addCallback(renderer, rendererCallback, executor);
591         } else {
592             LOG.info("Parameter 'serviceName' and / or 'id' is null");
593         }
594     }
595
596     /**
597      * send a RPC serviceImplementation
598      * to stubrenderer after
599      * receiving a stubpce notification.
600      *
601      * @param input ServiceCreate or ServiceReconfigure
602      */
603     private <T> void stubrendererImplementation(T input) {
604         ServiceRpcResultSh notification = null;
605         String serviceName = null;
606         String message = "";
607         String newServiceName = null;
608         ServiceNotificationTypes type = null;
609         Boolean create = false;
610         Boolean delete = true;
611         if (pathDescription != null) {
612             LOG.info("Pathdescription conatins in Stubpce notification received !");
613             String result = null;
614             PathComputationRequestOutput pathComputationResponse =
615                     new PathComputationRequestOutputBuilder()
616                     .setResponseParameters(new org.opendaylight.yang.gen.v1.http.org
617                             .transportpce.b.c._interface.service.types.rev170426.response
618                             .parameters.sp.ResponseParametersBuilder()
619                             .setPathDescription(pathDescription)
620                             .build())
621                     .build();
622             if (input instanceof ServiceReconfigureInput) {
623                 /** delete and write . */
624                 LOG.info("RPC serviceImplementation came from RPC serviceReconfigure ...");
625                 ServiceReconfigureInput tmp = (ServiceReconfigureInput)input;
626                 serviceName = tmp.getServiceName();
627                 newServiceName = tmp.getNewServiceName();
628                 type = ServiceNotificationTypes.ServiceReconfigureResult;
629                 delete = false;
630                 mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry, tmp,pathComputationResponse);
631             } else if (input instanceof ServiceCreateInput) {
632                 /** create. */
633                 LOG.info("RPC serviceImplementation came from RPC serviceCreate ...");
634                 ServiceCreateInput tmp = (ServiceCreateInput)input;
635                 serviceName = tmp.getServiceName();
636                 type = ServiceNotificationTypes.ServiceCreateResult;
637                 mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry, tmp,pathComputationResponse);
638                 delete = true;
639                 create = true;
640             } else if (input instanceof Services) {
641                 /** update. */
642                 LOG.info("RPC serviceImplementation came from RPC ServiceRestoration ...");
643                 Services tmp = new ServicesBuilder((Services)input)
644                         .setAdministrativeState(State.OutOfService)
645                         .setOperationalState(State.OutOfService)
646                         .setLifecycleState(LifecycleState.Planned)
647                         .build();
648                 serviceName = tmp.getServiceName();
649                 type = ServiceNotificationTypes.ServiceRestorationResult;
650                 mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry, tmp, pathComputationResponse);
651                 delete = true;
652                 create = true;
653             }
654             final String name = serviceName;
655             final ServiceNotificationTypes notifType = type;
656             if (!create) { /** ServiceReconfigure. */
657                 if ((result = writeOrModifyOrDeleteServiceList(serviceName, pathComputationResponse,null, 1)) == null) {
658                     LOG.info("Service '" + serviceName + "' deleted from datastore");
659                     serviceName = newServiceName;
660                     delete = true;
661                 } else {
662                     LOG.info("deleting Service '" + serviceName + "' failed !");
663                 }
664             }
665             if (delete) {
666                 if ((result = writeOrModifyOrDeleteServiceList(serviceName,pathComputationResponse,null, 2)) != null) {
667                     LOG.info("writting Service failed !");
668                     StringBuilder build = new StringBuilder();
669                     build.append(message);
670                     build.append(" " + result);
671                     message = build.toString();
672                 } else {
673                     /**
674                      * Send Implementation order to renderer
675                      */
676                     notification = new ServiceRpcResultShBuilder()
677                             .setNotificationType(notifType)
678                             .setServiceName(name)
679                             .setStatus(RpcStatusEx.Pending)
680                             .setStatusMessage("Submitting ServiceImplementation Request ...")
681                             .build();
682                     try {
683                         notificationPublishService.putNotification(notification);
684                     } catch (InterruptedException e) {
685                         LOG.info("notification offer rejected : " + e);
686                     }
687
688                     FutureCallback<Boolean> rendererCallback = new FutureCallback<Boolean>() {
689                         String message = "";
690                         ServiceRpcResultSh notification = null;
691
692                         @Override
693                         public void onSuccess(Boolean response) {
694                             if (response) {
695                                 /**
696                                  * If stubrenderer reply is received before timer
697                                  * expiration with a positive result, a
698                                  * service is created with admin and
699                                  * operational status 'down'.
700                                  */
701                                 message = "StubRenderer replied to Request !";
702                                 LOG.info(message);
703                                 notification = new ServiceRpcResultShBuilder()
704                                         .setNotificationType(notifType)
705                                         .setServiceName(name).setStatus(RpcStatusEx.Pending)
706                                         .setStatusMessage(message).build();
707                                 try {
708                                     notificationPublishService.putNotification(notification);
709                                 } catch (InterruptedException e) {
710                                     LOG.info("notification offer rejected : " + e);
711                                 }
712                             } else {
713                                 message = mappingAndSendingSIRequest.getError();
714                                 notification = new ServiceRpcResultShBuilder()
715                                         .setNotificationType(notifType)
716                                         .setServiceName(name).setStatus(RpcStatusEx.Failed).setStatusMessage(message)
717                                         .build();
718                                 try {
719                                     notificationPublishService.putNotification(notification);
720                                 } catch (InterruptedException e) {
721                                     LOG.info("notification offer rejected : " + e);
722                                 }
723                             }
724                         }
725
726                         @Override
727                         public void onFailure(Throwable arg0) {
728                             LOG.error("Service not implemented ...");
729                             notification = new ServiceRpcResultShBuilder()
730                                     .setNotificationType(notifType)
731                                     .setServiceName(name).setStatus(RpcStatusEx.Failed)
732                                     .setStatusMessage("Service implementation failed  : " + arg0.getMessage()).build();
733                             try {
734                                 notificationPublishService.putNotification(notification);
735                             } catch (InterruptedException e) {
736                                 LOG.info("notification offer rejected : " + e);
737                             }
738                         }
739                     };
740                     ListenableFuture<Boolean> renderer = mappingAndSendingSIRequest.serviceImplementation();
741                     Futures.addCallback(renderer, rendererCallback, executor);
742                 }
743             } else {
744                 LOG.info("deleting Service failed");
745             }
746         } else {
747             message = "PathDescription contains in Stubpce notification "
748                     + "not recieved !";
749             LOG.info(message);
750         }
751     }
752
753     /**
754      * Checking Service Compliancy.
755      *
756      * @return String if not compliant, null else
757      */
758     private String serviceCompliancy(SdncRequestHeader sdncRequestHeader, String serviceName,
759             ConnectionType connectionType, RpcActions rpcActions, ServiceEndpoint aend, ServiceEndpoint zend,
760             String commonIdValue, HardConstraints hard, SoftConstraints soft) {
761         String message = null;
762         Boolean contype = false;
763         Boolean sdncRequest = false;
764         Boolean commonId = true;
765         Boolean coherencyHardSoft = false;
766
767         if (sdncRequestHeader != null) {
768             sdncRequest = true;
769         }
770         if (connectionType != null) {
771             contype = true;
772         }
773         compliancyCheck = new ServicehandlerCompliancyCheck(sdncRequestHeader, serviceName,
774                 connectionType, rpcActions);
775         if (compliancyCheck.check(contype, sdncRequest)) {
776             LOG.info("Service compliant !");
777             /**
778              * If compliant, service-request parameters are verified in order to
779              * check if there is no missing parameter that prevents calculating
780              * a path and implement a service.
781              */
782             LOG.info("checking Tx/Rx Info for AEnd ...");
783             txrxCheck = new ServicehandlerTxRxCheck(aend, 1);
784             if (txrxCheck.check()) {
785                 LOG.info("Tx/Rx Info for AEnd checked !");
786                 LOG.info("checking Tx/Rx Info for ZEnd ...");
787                 txrxCheck = new ServicehandlerTxRxCheck(zend, 2);
788                 if (txrxCheck.check()) {
789                     LOG.info("Tx/Rx Info for ZEnd checked");
790                     /**
791                      * If OK, common-id is verified in order to see if there is
792                      * no routing policy provided. If yes, the routing
793                      * constraints of the policy are recovered and coherency
794                      * with hard/soft constraints provided in the input of the
795                      * RPC.
796                      */
797                     if (commonIdValue != null) {
798                         LOG.info("Common-id specified");
799                         /**
800                          * Check coherency with hard/soft constraints.
801                          */
802                         checkCoherencyHardSoft = new CheckCoherencyHardSoft(hard,soft);
803                         if (checkCoherencyHardSoft.check()) {
804                             LOG.info("hard/soft constraints coherent !");
805                             coherencyHardSoft = true;
806                         } else {
807                             LOG.info("hard/soft constraints are not coherent !");
808                             message = "hard/soft constraints are not coherent !";
809                         }
810                     } else {
811                         commonId = false;
812                     }
813                     if (!commonId || (commonId && coherencyHardSoft)) {
814                         message = null;
815                     }
816                 } else {
817                     message = txrxCheck.getMessage();
818                 }
819             } else {
820                 message = txrxCheck.getMessage();
821             }
822         } else {
823             message = compliancyCheck.getMessage();
824         }
825         return message;
826     }
827
828
829     @Override
830     public Future<RpcResult<ServiceCreateOutput>> serviceCreate(ServiceCreateInput input) {
831         LOG.info("RPC service creation received");
832         pathDescription = null;
833         pathTopology = null;
834         action = RpcActions.ServiceCreate;
835         notificationUrl = null;
836         LOG.info("notificationUrl : " + notificationUrl);
837         setPathDescription(null);
838         serviceCreateInput = input;
839         setServiceDeleteInput(null);
840         setServiceReconfigureInput(null);
841         service = null;
842         String message = "";
843         String responseCode = "";
844         ConfigurationResponseCommon configurationResponseCommon;
845         LOG.info("checking Service Compliancy ...");
846         /**
847          * Upon receipt of service-create RPC, service header and sdnc-request
848          * header compliancy are verified.
849          */
850         String serviceCompliancy = null;
851         if ((serviceCompliancy = serviceCompliancy(input.getSdncRequestHeader(), input.getServiceName(),
852                 input.getConnectionType(), RpcActions.ServiceCreate, input.getServiceAEnd(), input.getServiceZEnd(),
853                 input.getCommonId(), input.getHardConstraints(), input.getSoftConstraints())) != null) {
854             message = "Service not compliant : " + serviceCompliancy;
855             LOG.info(message);
856         } else {
857             LOG.info("Service compliant !");
858             pcePathComputation(input);
859             LOG.info("PCR Request in progress ");
860             configurationResponseCommon = new ConfigurationResponseCommonBuilder()
861                     .setAckFinalIndicator("No").setRequestId(input.getSdncRequestHeader().getRequestId())
862                     .setResponseMessage("Service compliant, serviceCreate in progress...")
863                     .setResponseCode("200").build();
864
865             ServiceCreateOutputBuilder output = new ServiceCreateOutputBuilder()
866                     .setConfigurationResponseCommon(configurationResponseCommon);
867
868             return RpcResultBuilder.success(output.build()).buildFuture();
869
870         }
871         /*compliancyCheck = new ServicehandlerCompliancyCheck(input.getSdncRequestHeader(), input.getServiceName(),
872                 input.getConnectionType(), RpcActions.ServiceCreate);
873         if (compliancyCheck.check(true, true)) {
874             LOG.info("Service compliant !");
875             LOG.info("checking Tx/Rx Info for AEnd ...");
876             txrxCheck = new ServicehandlerTxRxCheck(input.getServiceAEnd(), 1);
877             if (txrxCheck.check()) {
878                 LOG.info("Tx/Rx Info for AEnd checked !");
879                 LOG.info("checking Tx/Rx Info for ZEnd ...");
880                 txrxCheck = new ServicehandlerTxRxCheck(input.getServiceZEnd(), 2);
881                 if (txrxCheck.check()) {
882                     LOG.info("Tx/Rx Info for ZEnd checked");
883                     if (input.getCommonId() != null) {
884                         LOG.info("Common-id specified");
885                         checkCoherencyHardSoft = new CheckCoherencyHardSoft(input.getHardConstraints(),
886                                 input.getSoftConstraints());
887                         if (checkCoherencyHardSoft.check()) {
888                             LOG.info("hard/soft constraints coherent !");
889                             coherencyHardSoft = true;
890                         } else {
891                             LOG.info("hard/soft constraints are not coherent !");
892                             message = "hard/soft constraints are not coherent !";
893                             responseCode = "500";
894                         }
895                     } else {
896                         commonId = false;
897                     }
898                     if (!commonId || (commonId && coherencyHardSoft)) {
899                         pcePathComputation(input);
900                         LOG.info("PCR Request in progress ");
901                         configurationResponseCommon = new ConfigurationResponseCommonBuilder()
902                                 .setAckFinalIndicator("No").setRequestId(input.getSdncRequestHeader().getRequestId())
903                                 .setResponseMessage("Service compliant, serviceCreate in progress...")
904                                 .setResponseCode("200").build();
905
906                         ServiceCreateOutputBuilder output = new ServiceCreateOutputBuilder()
907                                 .setConfigurationResponseCommon(configurationResponseCommon);
908
909                         return RpcResultBuilder.success(output.build()).buildFuture();
910                     }
911                 } else {
912                     message = txrxCheck.getMessage();
913                     responseCode = "500";
914                 }
915             } else {
916                 message = txrxCheck.getMessage();
917                 responseCode = "500";
918             }
919         } else {
920             message = compliancyCheck.getMessage();
921             responseCode = "500";
922         }*/
923
924         configurationResponseCommon = new ConfigurationResponseCommonBuilder()
925                 .setAckFinalIndicator("Yes")
926                 .setRequestId(input.getSdncRequestHeader().getRequestId()).setResponseMessage(message)
927                 .setResponseCode(responseCode).build();
928
929         ServiceCreateOutputBuilder output = new ServiceCreateOutputBuilder()
930                 .setConfigurationResponseCommon(configurationResponseCommon);
931
932         return RpcResultBuilder.success(output.build()).buildFuture();
933
934     }
935
936     @Override
937     public Future<RpcResult<ServiceDeleteOutput>> serviceDelete(ServiceDeleteInput input) {
938         LOG.info("RPC serviceDelete request received for Service '" + input.getServiceDeleteReqInfo().getServiceName()
939                 + "'");
940         setServiceDeleteInput(input);
941         setServiceReconfigureInput(null);
942         serviceCreateInput = null;
943         service = null;
944         String message = "";
945         String responseCode = "";
946         LOG.info("checking Service Compliancy ...");
947         /**
948          * Upon receipt of service-delete RPC, service header and sdnc-request
949          * header compliancy are verified.
950          */
951         compliancyCheck = new ServicehandlerCompliancyCheck(input.getSdncRequestHeader(),
952                 input.getServiceDeleteReqInfo().getServiceName(), RpcActions.ServiceDelete);
953         if (compliancyCheck.check(false, true)) {
954             LOG.info("Service compliant !");
955             String serviceName = input.getServiceDeleteReqInfo().getServiceName();
956             Services service = readServiceList(serviceName);
957             if (service != null) {
958                 LOG.debug("Service '" + serviceName + "' present in datastore !");
959                 stubrendererDelete();
960                 LOG.info("ServiceDelete Request in progress ... ");
961                 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
962                         .setAckFinalIndicator("No").setRequestId(input.getSdncRequestHeader().getRequestId())
963                         .setResponseMessage("ServiceDelete Request in progress ...").setResponseCode("200").build();
964                 ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
965                         .setConfigurationResponseCommon(configurationResponseCommon).build();
966                 return RpcResultBuilder.success(output).buildFuture();
967             } else {
968                 message = "Service '" + serviceName + "' not exists in datastore";
969                 LOG.info(message);
970             }
971
972         } else {
973             message = "Service not compliant !";
974             responseCode = "500";
975             LOG.info(message);
976         }
977         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
978                 .setAckFinalIndicator("Yes").setRequestId(input.getSdncRequestHeader().getRequestId())
979                 .setResponseMessage(message).setResponseCode(responseCode).build();
980         ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
981                 .setConfigurationResponseCommon(configurationResponseCommon).build();
982         return RpcResultBuilder.success(output).buildFuture();
983     }
984
985     @Override
986     public Future<RpcResult<ServiceFeasibilityCheckOutput>> serviceFeasibilityCheck(
987             ServiceFeasibilityCheckInput input) {
988         action = RpcActions.ServiceFeasibilityCheck;
989         LOG.info("RPC service feasibilityCheck received");
990         mappingAndSendingPCRequest = null;
991         serviceFeasibilityCheckInput = input;
992         serviceCreateInput = null;
993         serviceDeleteInput = null;
994         service = null;
995         serviceReconfigureInput = null;
996
997         ConfigurationResponseCommon configurationResponseCommon = null;
998         String message = "";
999         String responseCode = "";
1000         LOG.info("checking Service Compliancy ...");
1001         /**
1002          * Upon receipt of service-create RPC, service header and sdnc-request
1003          * header compliancy are verified.
1004          */
1005         String name = "no name";
1006         String serviceCompliancy = null;
1007         if ((serviceCompliancy = serviceCompliancy(input.getSdncRequestHeader(), name, input.getConnectionType(),
1008                 RpcActions.ServiceFeasibilityCheck, input.getServiceAEnd(), input.getServiceZEnd(), input.getCommonId(),
1009                 input.getHardConstraints(), input.getSoftConstraints())) != null) {
1010             message = "Service not compliant : " + serviceCompliancy;
1011             LOG.info(message);
1012         } else {
1013             LOG.info("Service compliant !");
1014             pcePathComputation(input);
1015             LOG.info("PCR Request in progress ");
1016             configurationResponseCommon = new ConfigurationResponseCommonBuilder()
1017                     .setAckFinalIndicator("No").setRequestId(input.getSdncRequestHeader().getRequestId())
1018                     .setResponseMessage("Service compliant, ServiceFeasibilityCheck in progress...")
1019                     .setResponseCode("200").build();
1020
1021             ServiceFeasibilityCheckOutput output = new ServiceFeasibilityCheckOutputBuilder()
1022                     .setConfigurationResponseCommon(configurationResponseCommon).build();
1023             return RpcResultBuilder.success(output).buildFuture();
1024         }
1025         /*compliancyCheck = new ServicehandlerCompliancyCheck(input.getSdncRequestHeader(), name,
1026                 input.getConnectionType(), RpcActions.ServiceFeasibilityCheck);
1027         if (compliancyCheck.check(true, true)) {
1028             LOG.info("Service compliant !");
1029             LOG.info("checking Tx/Rx Info for AEnd ...");
1030             txrxCheck = new ServicehandlerTxRxCheck(input.getServiceAEnd(), 1);
1031             if (txrxCheck.check()) {
1032                 LOG.info("Tx/Rx Info for AEnd checked !");
1033                 LOG.info("checking Tx/Rx Info for ZEnd ...");
1034                 txrxCheck = new ServicehandlerTxRxCheck(input.getServiceZEnd(), 2);
1035                 if (txrxCheck.check()) {
1036                     LOG.info("Tx/Rx Info for ZEnd checked");
1037                     if (input.getCommonId() != null) {
1038                         LOG.info("Common-id specified");
1039                         checkCoherencyHardSoft = new CheckCoherencyHardSoft(input.getHardConstraints(),
1040                                 input.getSoftConstraints());
1041                         if (checkCoherencyHardSoft.check()) {
1042                             LOG.info("hard/soft constraints coherent !");
1043                             coherencyHardSoft = true;
1044                         } else {
1045                             LOG.info("hard/soft constraints are not coherent !");
1046                             message = "hard/soft constraints are not coherent !";
1047                             responseCode = "500";
1048                         }
1049                     } else {
1050                         commonId = false;
1051                     }
1052
1053                     if (!commonId || (commonId && coherencyHardSoft)) {
1054                         pcePathComputation(input);
1055                         LOG.info("PCR Request in progress ");
1056                         configurationResponseCommon = new ConfigurationResponseCommonBuilder()
1057                                 .setAckFinalIndicator("No").setRequestId(input.getSdncRequestHeader().getRequestId())
1058                                 .setResponseMessage("Service compliant, ServiceFeasibilityCheck in progress...")
1059                                 .setResponseCode("200").build();
1060
1061                         ServiceFeasibilityCheckOutput output = new ServiceFeasibilityCheckOutputBuilder()
1062                                 .setConfigurationResponseCommon(configurationResponseCommon).build();
1063                         return RpcResultBuilder.success(output).buildFuture();
1064                     }
1065                 } else {
1066                     message = txrxCheck.getMessage();
1067                     responseCode = "500";
1068                 }
1069             } else {
1070                 message = txrxCheck.getMessage();
1071                 responseCode = "500";
1072             }
1073         } else {
1074             message = compliancyCheck.getMessage();
1075             responseCode = "500";
1076         }*/
1077         configurationResponseCommon = new ConfigurationResponseCommonBuilder().setAckFinalIndicator("Yes")
1078                 .setRequestId(input.getSdncRequestHeader().getRequestId()).setResponseMessage(message)
1079                 .setResponseCode(responseCode).build();
1080         ServiceFeasibilityCheckOutput output = new ServiceFeasibilityCheckOutputBuilder()
1081                 .setConfigurationResponseCommon(configurationResponseCommon).build();
1082
1083         return RpcResultBuilder.success(output).buildFuture();
1084     }
1085
1086     @Override
1087     public Future<RpcResult<ServiceReconfigureOutput>> serviceReconfigure(ServiceReconfigureInput input) {
1088         LOG.info("RPC service reconfigure received");
1089         setServiceReconfigureInput(input);
1090         setServiceDeleteInput(null);
1091         serviceCreateInput = null;
1092         service = null;
1093         String message = "";
1094         LOG.info("checking Service Compliancy ...");
1095         /**
1096          * Upon receipt of service-create RPC, service header and sdnc-request
1097          * header compliancy are verified.
1098          */
1099         String serviceCompliancy = null;
1100         if ((serviceCompliancy = serviceCompliancy(null, input.getServiceName(), input.getConnectionType(),
1101                 RpcActions.ServiceReconfigure, input.getServiceAEnd(), input.getServiceZEnd(), input.getCommonId(),
1102                 input.getHardConstraints(), input.getSoftConstraints())) != null) {
1103             message = "Service not compliant : " + serviceCompliancy;
1104             LOG.info(message);
1105         } else {
1106             LOG.info("Service compliant !");
1107             /**
1108              * Retrieving initial service topology.
1109              */
1110             String serviceName = input.getServiceName();
1111             Services service = readServiceList(serviceName);
1112             if (service != null) {
1113                 LOG.debug("Service '" + serviceName + "' present in datastore !");
1114                 /**
1115                  * Sending cancel resource reserve request to PCE.
1116                  */
1117                 pceCancelResResource();
1118                 ServiceReconfigureOutput output = new ServiceReconfigureOutputBuilder()
1119                         .setStatus(RpcStatus.Successful)
1120                         .setStatusMessage("ServiceReconfigure in progress ...").build();
1121                 return RpcResultBuilder.success(output).buildFuture();
1122             } else {
1123                 message = "Service '" + serviceName + "' not exists in datastore";
1124                 LOG.info(message);
1125             }
1126         }
1127         /*compliancyCheck = new ServicehandlerCompliancyCheck(input.getServiceName(), input.getConnectionType(),
1128                 RpcActions.ServiceReconfigure);
1129         if (compliancyCheck.check(true, false)) {
1130             LOG.info("Service compliant !");
1131             LOG.info("checking Tx/Rx Info for AEnd ...");
1132             txrxCheck = new ServicehandlerTxRxCheck(input.getServiceAEnd(), 1);
1133             if (txrxCheck.check()) {
1134                 LOG.info("Tx/Rx Info for AEnd checked !");
1135                 LOG.info("checking Tx/Rx Info for ZEnd ...");
1136                 txrxCheck = new ServicehandlerTxRxCheck(input.getServiceZEnd(), 2);
1137                 if (txrxCheck.check()) {
1138                     LOG.info("Tx/Rx Info for ZEnd checked");
1139                     if (input.getCommonId() != null) {
1140                         LOG.info("Common-id specified");
1141                         checkCoherencyHardSoft = new CheckCoherencyHardSoft(input.getHardConstraints(),
1142                                 input.getSoftConstraints());
1143                         if (checkCoherencyHardSoft.check()) {
1144                             LOG.info("hard/soft constraints coherent !");
1145                             coherencyHardSoft = true;
1146                         } else {
1147                             LOG.info("hard/soft constraints are not coherent !");
1148                             message = "hard/soft constraints are not coherent !";
1149                         }
1150                     } else {
1151                         commonId = false;
1152                     }
1153
1154                     if (!commonId || (commonId && coherencyHardSoft)) {
1155                         String serviceName = input.getServiceName();
1156                         Services service = readServiceList(serviceName);
1157                         if (service != null) {
1158                             LOG.debug("Service '" + serviceName + "' present in datastore !");
1159                             pceCancelResResource();
1160                             ServiceReconfigureOutput output = new ServiceReconfigureOutputBuilder()
1161                                     .setStatus(RpcStatusEx.Pending)
1162                                     .setStatusMessage("ServiceReconfigure in progress ...").build();
1163                             return RpcResultBuilder.success(output).buildFuture();
1164                         } else {
1165                             message = "Service '" + serviceName + "' not exists in datastore";
1166                             LOG.error(message);
1167                         }
1168                     }
1169                 } else {
1170                     message = txrxCheck.getMessage();
1171                 }
1172             } else {
1173                 message = txrxCheck.getMessage();
1174             }
1175         } else {
1176             message = compliancyCheck.getMessage();
1177         }*/
1178
1179         ServiceReconfigureOutput output = new ServiceReconfigureOutputBuilder().setStatus(RpcStatus.Successful)
1180                 .setStatusMessage(message).build();
1181         return RpcResultBuilder.success(output).buildFuture();
1182     }
1183
1184     @Override
1185     public Future<RpcResult<ServiceRestorationOutput>> serviceRestoration(ServiceRestorationInput input) {
1186         LOG.info("RPC service restoration received");
1187         ServiceRpcResultSh notification = null;
1188         setServiceDeleteInput(null);
1189         setServiceReconfigureInput(null);
1190         notificationUrl = null;
1191         String message = "";
1192         LOG.info("checking Service Compliancy ...");
1193         compliancyCheck = new ServicehandlerCompliancyCheck(input.getServiceName(), RpcActions.ServiceRestoration);
1194         if (compliancyCheck.check(false, false)) {
1195             LOG.info("Service compliant !");
1196             /**
1197              * If compliant, Getting path from service DB.
1198              */
1199             String serviceName = input.getServiceName();
1200             Services service = readServiceList(serviceName);
1201             if (service != null) {
1202                 this.service = service;
1203                 LOG.debug("Service '" + serviceName + "' present in datastore !");
1204                 notification = new ServiceRpcResultShBuilder()
1205                         .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1206                         .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1207                         .setStatusMessage("Service '" + serviceName + "' present in datastore, deleting service ...")
1208                         .build();
1209                 try {
1210                     notificationPublishService.putNotification(notification);
1211                 } catch (InterruptedException e) {
1212                     LOG.info("notification offer rejected : " + e);
1213                 }
1214                 stubrendererDelete();
1215                 LOG.info("PCR Request in progress ");
1216                 ServiceRestorationOutput output = new ServiceRestorationOutputBuilder()
1217                         .setStatus(RpcStatus.Successful)
1218                         .setStatusMessage("ServiceRestoration in progress...").build();
1219                 return RpcResultBuilder.success(output).buildFuture();
1220             } else {
1221                 message = "Service '" + serviceName + "' not exists in datastore";
1222                 LOG.error(message);
1223             }
1224         } else {
1225             message = compliancyCheck.getMessage();
1226             LOG.error(message);
1227         }
1228
1229         ServiceRestorationOutput output = new ServiceRestorationOutputBuilder().setStatus(RpcStatus.Successful)
1230                 .setStatusMessage(message).build();
1231
1232         return RpcResultBuilder.success(output).buildFuture();
1233     }
1234
1235     @Override
1236     public Future<RpcResult<TempServiceDeleteOutput>> tempServiceDelete(TempServiceDeleteInput input) {
1237         // TODO Auto-generated method stub
1238         return null;
1239     }
1240
1241     @Override
1242     public Future<RpcResult<TempServiceCreateOutput>> tempServiceCreate(TempServiceCreateInput input) {
1243         // TODO Auto-generated method stub
1244         return null;
1245     }
1246
1247     /**
1248      * Initialize ServiceList Structure on Datastore.
1249      *
1250      * @param DataBroker
1251      *            Access Datastore
1252      */
1253     private void initializeDataTree(DataBroker db) {
1254         LOG.info("Preparing to initialize the greeting registry");
1255         WriteTransaction transaction = db.newWriteOnlyTransaction();
1256         InstanceIdentifier<ServiceList> iid = InstanceIdentifier.create(ServiceList.class);
1257         ServiceList greetingRegistry = new ServiceListBuilder().build();
1258         transaction.put(LogicalDatastoreType.OPERATIONAL, iid, greetingRegistry);
1259         Future<Void> future = transaction.submit();
1260         try {
1261             Futures.getChecked(future, ExecutionException.class);
1262         } catch (ExecutionException e) {
1263             LOG.error("Failed to create Service List");
1264         }
1265     }
1266
1267     /**
1268      * Map Input (ServiceCreateInmput, ServiceReconfigureInput) and output
1269      * (PathComputationRequestOutput) to Service.
1270      *
1271      * @param serviceCreateInput
1272      *            ServiceCreateInput parameter
1273      * @param serviceReconfigureInput
1274      *            serviceReconfigureInput parameter
1275      * @param output
1276      *            PathComputationRequestOutput parameter
1277      *
1278      * @return Services Service data
1279      */
1280     private Services mappingServices(ServiceCreateInput serviceCreateInput,
1281             ServiceReconfigureInput serviceReconfigureInput, PathComputationRequestOutput output) {
1282         LOG.info("Mapping informations to Services");
1283         ServiceAEnd aend = null;
1284         ServiceZEnd zend = null;
1285         ServicesBuilder service = new ServicesBuilder();
1286         if (serviceCreateInput != null) {
1287             aend = new ServiceAEndBuilder(serviceCreateInput.getServiceAEnd()).build();
1288             zend = new ServiceZEndBuilder(serviceCreateInput.getServiceZEnd()).build();
1289             service.setServiceName(serviceCreateInput.getServiceName()).setAdministrativeState(State.OutOfService)
1290             .setOperationalState(State.OutOfService).setCommonId(serviceCreateInput.getCommonId())
1291             .setConnectionType(serviceCreateInput.getConnectionType())
1292             .setCustomer(serviceCreateInput.getCustomer())
1293             .setCustomerContact(serviceCreateInput.getCustomerContact())
1294             .setHardConstraints(serviceCreateInput.getHardConstraints())
1295             .setSoftConstraints(serviceCreateInput.getSoftConstraints())
1296             .setLifecycleState(LifecycleState.Planned).setServiceAEnd(aend).setServiceZEnd(zend)
1297             .setSdncRequestHeader(serviceCreateInput.getSdncRequestHeader());
1298
1299         } else if (serviceReconfigureInput != null) {
1300             aend = new ServiceAEndBuilder(serviceReconfigureInput.getServiceAEnd()).build();
1301             zend = new ServiceZEndBuilder(serviceReconfigureInput.getServiceZEnd()).build();
1302             service.setServiceName(serviceReconfigureInput.getNewServiceName())
1303             .setAdministrativeState(State.OutOfService).setOperationalState(State.OutOfService)
1304             .setCommonId(serviceReconfigureInput.getCommonId())
1305             .setConnectionType(serviceReconfigureInput.getConnectionType())
1306             .setCustomer(serviceReconfigureInput.getCustomer())
1307             .setCustomerContact(serviceReconfigureInput.getCustomerContact())
1308             .setHardConstraints(serviceReconfigureInput.getHardConstraints())
1309             .setSoftConstraints(serviceReconfigureInput.getSoftConstraints())
1310             .setLifecycleState(LifecycleState.Planned).setServiceAEnd(aend).setServiceZEnd(zend);
1311         }
1312
1313         org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.response
1314             .parameters.sp.ResponseParameters responseParameters = output.getResponseParameters();
1315         if (responseParameters != null) {
1316             // service.setPceMetric(responseParameters.getPceMetric());
1317             org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426
1318                 .response.parameters.sp.response.parameters.PathDescription pathDescription =
1319                 responseParameters.getPathDescription();
1320             if (pathDescription != null) {
1321                 List<AToZ> atozList = new ArrayList<AToZ>();
1322                 List<ZToA> ztoaList = new ArrayList<ZToA>();
1323
1324                 for (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426
1325                         .path.description.atoz.direction.AToZ
1326                         tmp : pathDescription.getAToZDirection().getAToZ()) {
1327
1328                     AToZKey key = new AToZKey(tmp.getKey().getId());
1329                     AToZ atoz = new AToZBuilder().setId(tmp.getId()).setKey(key)
1330                             // .setResource(tmp.getResource())
1331                             .build();
1332                     atozList.add(atoz);
1333                 }
1334
1335                 for (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426
1336                         .path.description.ztoa.direction.ZToA
1337                         tmp : pathDescription.getZToADirection().getZToA()) {
1338                     ZToAKey key = new ZToAKey(tmp.getKey().getId());
1339                     ZToA ztoa = new ZToABuilder().setId(tmp.getId()).setKey(key)
1340                             // .setResource(tmp.getResource())
1341                             .build();
1342                     ztoaList.add(ztoa);
1343                 }
1344
1345                 Topology topology = new TopologyBuilder().setAToZ(atozList).setZToA(ztoaList).build();
1346                 service.setTopology(topology);
1347             }
1348         }
1349         return service.build();
1350     }
1351
1352     /**
1353      * read Service from ServiceList DataStore.
1354      *
1355      * @param serviceName
1356      *            Name of Service
1357      *
1358      * @return <code>Services</code>
1359      */
1360     private Services readServiceList(String serviceName) {
1361         Services result = null;
1362         ReadOnlyTransaction readTx = db.newReadOnlyTransaction();
1363         InstanceIdentifier<Services> iid = InstanceIdentifier.create(ServiceList.class).child(Services.class,
1364                 new ServicesKey(serviceName));
1365         Future<Optional<Services>> future = readTx.read(LogicalDatastoreType.OPERATIONAL,iid);
1366         Optional<Services> optional = Optional.absent();
1367         try {
1368             optional = Futures.getChecked(future, ExecutionException.class);
1369         } catch (ExecutionException e) {
1370             LOG.error("Reading service failed:", e);
1371         }
1372         if (optional.isPresent()) {
1373             LOG.debug("Service '" + serviceName + "' present !");
1374             result = new ServicesBuilder(optional.get()).build();
1375         }
1376         return result;
1377     }
1378
1379     /**
1380      * Write or Modify or Delete Service from/to ServiceList.
1381      *
1382      * @param serviceName
1383      *            Name of service
1384      * @param output
1385      *            PathComputationRequestOutput
1386      * @param topo
1387      *            Topology
1388      * @param choice
1389      *            0 - Modify 1 - Delete 2 - Write
1390      * @return String operations result, null if ok or not otherwise
1391      */
1392     private String writeOrModifyOrDeleteServiceList(String serviceName, PathComputationRequestOutput output,
1393             Topology topo, int choice) {
1394         LOG.info("WriteOrModifyOrDeleting '" + serviceName + "' Service");
1395         WriteTransaction writeTx = db.newWriteOnlyTransaction();
1396         String result = null;
1397         Services readService = readServiceList(serviceName);
1398         Future<Void> future = null;
1399         if (readService != null) {
1400             /**
1401              * Modify / Delete Service.
1402              */
1403             InstanceIdentifier<Services> iid = InstanceIdentifier.create(ServiceList.class).child(Services.class,
1404                     new ServicesKey(serviceName));
1405             ServicesBuilder service = new ServicesBuilder(readService);
1406
1407             String action = null;
1408             switch (choice) {
1409                 case 0: /** Modify. */
1410                     LOG.info("Modifying '" + serviceName + "' Service");
1411                     service.setOperationalState(State.InService).setAdministrativeState(State.InService);
1412                     service.setTopology(topo);
1413                     writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, service.build());
1414                     action = "modify";
1415                     break;
1416
1417                 case 1: /** Delete. */
1418                     LOG.info("Deleting '" + serviceName + "' Service");
1419                     writeTx.delete(LogicalDatastoreType.OPERATIONAL, iid);
1420                     action = "delete";
1421                     break;
1422
1423                 default:
1424                     LOG.info("No choice found");
1425                     break;
1426             }
1427             future = writeTx.submit();
1428             try {
1429                 Futures.getChecked(future, ExecutionException.class);
1430             } catch (ExecutionException e) {
1431                 LOG.info("Failed to " + action + " service from Service List");
1432                 result = "Failed to " + action + " service from Service List";
1433             }
1434         } else if (choice == 2) { /** Write Service. */
1435             LOG.info("Writing '" + serviceName + "' Service");
1436             InstanceIdentifier<Services> iid = InstanceIdentifier.create(ServiceList.class).child(Services.class,
1437                     new ServicesKey(serviceName));
1438             Services writeService = null;
1439             if (this.service != null) {
1440                 writeService = service;
1441             } else {
1442                 writeService = mappingServices(serviceCreateInput, serviceReconfigureInput, output);
1443             }
1444             writeTx.put(LogicalDatastoreType.OPERATIONAL, iid, writeService);
1445             future = writeTx.submit();
1446             try {
1447                 Futures.getChecked(future, ExecutionException.class);
1448                 result = null;
1449             } catch (ExecutionException e) {
1450                 LOG.error("Failed to write service to Service List");
1451                 result = "Failed to write service to Service List";
1452             }
1453         } else {
1454             LOG.info("Service is not present  in datastore ! ");
1455             result = "Service is not present  in datastore ! ";
1456         }
1457         return result;
1458     }
1459
1460     @Override
1461     public void close() throws Exception {
1462         executor.shutdown();
1463     }
1464
1465     @Override
1466     public Future<RpcResult<EquipmentNotificationOutput>> equipmentNotification(EquipmentNotificationInput input) {
1467         // TODO Auto-generated method stub
1468         return null;
1469     }
1470
1471     @Override
1472     public Future<RpcResult<ServiceRerouteConfirmOutput>> serviceRerouteConfirm(ServiceRerouteConfirmInput input) {
1473         // TODO Auto-generated method stub
1474         return null;
1475     }
1476
1477     @Override
1478     public Future<RpcResult<ServiceRerouteOutput>> serviceReroute(ServiceRerouteInput input) {
1479         // TODO Auto-generated method stub
1480         return null;
1481     }
1482
1483     @Override
1484     public Future<RpcResult<ServiceReversionOutput>> serviceReversion(ServiceReversionInput input) {
1485         // TODO Auto-generated method stub
1486         return null;
1487     }
1488
1489     @Override
1490     public Future<RpcResult<ServiceRollOutput>> serviceRoll(ServiceRollInput input) {
1491         // TODO Auto-generated method stub
1492         return null;
1493     }
1494
1495     @Override
1496     public Future<RpcResult<NetworkReOptimizationOutput>> networkReOptimization(NetworkReOptimizationInput input) {
1497         // TODO Auto-generated method stub
1498         return null;
1499     }
1500
1501     @Override
1502     public void onServiceRpcResultSp(ServiceRpcResultSp notification) {
1503         if (notification != null && !compareServiceRpcResultSp(notification)) {
1504             serviceRpcResultSp = notification;
1505             StringBuilder build = new StringBuilder();
1506             build.append(
1507                     "Received '" + notification.getNotificationType() + "' StubRenderer notification" + "from service '"
1508                             + notification.getServiceName() + "' " + "with status '" + notification.getStatus() + "'");
1509             build.append(" with StatusMessage '" + notification.getStatusMessage() + "'");
1510             LOG.info(build.toString());
1511             switch (serviceRpcResultSp.getNotificationType().getIntValue()) {
1512                 case 3 : /** service-implementation-request. */
1513                     if (serviceRpcResultSp.getStatus() == RpcStatusEx.Successful) {
1514                         if (serviceRpcResultSp.getPathTopology() != null) {
1515                             pathTopology = new PathTopologyBuilder()
1516                                     .setAToZ(serviceRpcResultSp.getPathTopology().getAToZ())
1517                                     .setZToA(serviceRpcResultSp.getPathTopology().getZToA())
1518                                     .build();
1519                             LOG.info("PathTopology gets !");
1520                         } else {
1521                             LOG.info("'serviceRpcResultSp.getPathTopology()' parameter is null ");
1522                         }
1523                         if (serviceCreateInput != null) {
1524                             updateServiceStatus(serviceCreateInput);
1525                         } else if (serviceReconfigureInput != null) {
1526                             updateServiceStatus(serviceReconfigureInput);
1527                         } else if (service != null) {
1528                             updateServiceStatus(service);
1529                         }
1530                     } else if (serviceRpcResultSp.getStatus() == RpcStatusEx.Failed) {
1531                         LOG.info("Stubrenderer computation failed !");
1532                         pceCancelResResource();
1533                     }
1534                     break;
1535
1536                 case 4 : /** service-delete. */
1537                     if (serviceRpcResultSp.getStatus() == RpcStatusEx.Successful) {
1538                         if (service != null) { //serviceRestoration
1539                             LOG.info("RPC service delete came from serviceRestoration");
1540                             pcePathComputation(service);
1541                         } else {
1542                             pceCancelResResource();
1543                         }
1544                     } else if (serviceRpcResultSp.getStatus() == RpcStatusEx.Failed) {
1545                         LOG.info("Stubrenderer computation failed !");
1546                     }
1547                     break;
1548
1549                 default:
1550                     break;
1551             }
1552         } else {
1553             LOG.info("ServiceRpcResultSp already wired !");
1554         }
1555     }
1556
1557     @Override
1558     public void onServicePathRpcResult(ServicePathRpcResult notification) {
1559         if (notification != null && !compareServicePathRpcResult(notification)) {
1560             servicePathRpcResult = notification;
1561             StringBuilder build = new StringBuilder();
1562             build.append(
1563                     "Received '" + notification.getNotificationType() + "' Stubpce notification" + "from service '"
1564                             + notification.getServiceName() + "' " + "with status '" + notification.getStatus() + "'");
1565             build.append(" with StatusMessage '" + notification.getStatusMessage() + "'");
1566             LOG.info(build.toString());
1567             switch (servicePathRpcResult.getNotificationType().getIntValue()) {
1568                 case 1 : /** path-computation-request. */
1569                     if (servicePathRpcResult.getStatus() == RpcStatusEx.Successful) {
1570                         if (servicePathRpcResult.getPathDescription() != null) {
1571                             pathDescription = new PathDescriptionBuilder()
1572                                     .setAToZDirection(servicePathRpcResult.getPathDescription().getAToZDirection())
1573                                     .setZToADirection(servicePathRpcResult.getPathDescription().getZToADirection())
1574                                     .build();
1575                             LOG.info("PathDescription gets !");
1576                             if (serviceReconfigureInput != null) {
1577                                 stubrendererImplementation(serviceReconfigureInput);
1578                             } else if (serviceCreateInput != null) {
1579                                 stubrendererImplementation(serviceCreateInput);
1580                             } else if (service != null) {
1581                                 stubrendererImplementation(service);
1582                             }
1583                         } else {
1584                             LOG.info("'servicePathRpcResult.getPathDescription()'parameter is null ");
1585                         }
1586                     } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
1587                         LOG.info("Stupce computation failed !");
1588                     }
1589                     break;
1590
1591                 case 2 : /** cancel-resource-reserve. */
1592                     if (servicePathRpcResult.getStatus() == RpcStatusEx.Successful) {
1593                         /**if it was an RPC serviceReconfigure, relaunch
1594                          * PCR else delete the service.
1595                          */
1596                         if (serviceReconfigureInput != null) {
1597                             LOG.info("cancel reserve resource request came from RPC serviceReconfigure !");
1598                             pcePathComputation(serviceReconfigureInput);
1599                         } else {
1600                             deleteServiceFromDatastore();
1601                         }
1602                     } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
1603                         LOG.info("Stupce computation failed !");
1604                     }
1605                     break;
1606
1607                 default:
1608                     break;
1609             }
1610         } else {
1611             LOG.info("ServicePathRpcResult already wired !");
1612         }
1613     }
1614
1615     public RpcActions getAction() {
1616         return action;
1617     }
1618
1619     public void setAction(RpcActions action) {
1620         this.action = action;
1621     }
1622
1623     /**
1624      * Compare ServicePathRpcResult.
1625      *
1626      * @param notification ServicePathRpcResult
1627      * @return <code>Boolean</code> true if idem, false else
1628      */
1629     public Boolean compareServicePathRpcResult(ServicePathRpcResult notification) {
1630         Boolean result = true;
1631         if (servicePathRpcResult == null) {
1632             result = false;
1633         } else {
1634             if (servicePathRpcResult.getNotificationType() != notification.getNotificationType()) {
1635                 result = false;
1636             }
1637             if (servicePathRpcResult.getServiceName() != notification.getServiceName()) {
1638                 result = false;
1639             }
1640             if (servicePathRpcResult.getStatus() != notification.getStatus()) {
1641                 result = false;
1642             }
1643             if (servicePathRpcResult.getStatusMessage() != notification.getStatusMessage()) {
1644                 result = false;
1645             }
1646         }
1647         return result;
1648     }
1649
1650     /**
1651      * Compare ServiceRpcResultSp.
1652      *
1653      * @param notification ServiceRpcResultSp
1654      * @return <code>Boolean</code> true if idem, false else
1655      */
1656     public Boolean compareServiceRpcResultSp(ServiceRpcResultSp notification) {
1657         Boolean result = true;
1658         if (serviceRpcResultSp == null) {
1659             result = false;
1660         } else {
1661             if (serviceRpcResultSp.getNotificationType() != notification.getNotificationType()) {
1662                 result = false;
1663             }
1664             if (serviceRpcResultSp.getServiceName() != notification.getServiceName()) {
1665                 result = false;
1666             }
1667             if (serviceRpcResultSp.getStatus() != notification.getStatus()) {
1668                 result = false;
1669             }
1670             if (serviceRpcResultSp.getStatusMessage() != notification.getStatusMessage()) {
1671                 result = false;
1672             }
1673         }
1674         return result;
1675     }
1676
1677     public PathDescription getPathDescription() {
1678         return pathDescription;
1679     }
1680
1681     public void setPathDescription(PathDescription pathDescription) {
1682         this.pathDescription = pathDescription;
1683     }
1684
1685     public ServiceDeleteInput getServiceDeleteInput() {
1686         return serviceDeleteInput;
1687     }
1688
1689     public void setServiceDeleteInput(ServiceDeleteInput serviceDeleteInput) {
1690         this.serviceDeleteInput = serviceDeleteInput;
1691     }
1692
1693     public ServiceReconfigureInput getServiceReconfigureInput() {
1694         return serviceReconfigureInput;
1695     }
1696
1697     public void setServiceReconfigureInput(ServiceReconfigureInput serviceReconfigureInput) {
1698         this.serviceReconfigureInput = serviceReconfigureInput;
1699     }
1700
1701     public ServiceFeasibilityCheckInput getServiceFeasibilityCheckInput() {
1702         return serviceFeasibilityCheckInput;
1703     }
1704
1705     public void setServiceFeasibilityCheckInput(ServiceFeasibilityCheckInput serviceFeasibilityCheckInput) {
1706         this.serviceFeasibilityCheckInput = serviceFeasibilityCheckInput;
1707     }
1708 }