fea237842df999aa76994340254adb58df293d89
[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.CheckedFuture;
14 import com.google.common.util.concurrent.FutureCallback;
15 import com.google.common.util.concurrent.Futures;
16 import com.google.common.util.concurrent.ListenableFuture;
17 import com.google.common.util.concurrent.ListeningExecutorService;
18 import com.google.common.util.concurrent.MoreExecutors;
19 import com.google.gson.Gson;
20 import com.google.gson.GsonBuilder;
21
22 import java.io.DataOutputStream;
23 import java.io.IOException;
24 import java.net.HttpURLConnection;
25 import java.net.URL;
26 import java.util.ArrayList;
27 import java.util.List;
28 import java.util.concurrent.ExecutionException;
29 import java.util.concurrent.Executors;
30 import java.util.concurrent.Future;
31
32 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
33 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
34 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
35 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
36 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
37 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
38 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
39 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
40 import org.opendaylight.transportpce.servicehandler.CheckCoherencyHardSoft;
41 import org.opendaylight.transportpce.servicehandler.LoggingFuturesCallBack;
42 import org.opendaylight.transportpce.servicehandler.MappingAndSendingPCRequest;
43 import org.opendaylight.transportpce.servicehandler.MappingAndSendingSIRequest;
44 import org.opendaylight.transportpce.servicehandler.ServicehandlerCompliancyCheck;
45 import org.opendaylight.transportpce.servicehandler.ServicehandlerTxRxCheck;
46 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.EquipmentNotificationInput;
47 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.EquipmentNotificationOutput;
48 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.NetworkReOptimizationInput;
49 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.NetworkReOptimizationOutput;
50 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceCreateInput;
51 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceCreateOutput;
52 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceCreateOutputBuilder;
53 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceDeleteInput;
54 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceDeleteOutput;
55 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceDeleteOutputBuilder;
56 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceFeasibilityCheckInput;
57 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceFeasibilityCheckOutput;
58 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceFeasibilityCheckOutputBuilder;
59 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceList;
60 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceListBuilder;
61 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceReconfigureInput;
62 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceReconfigureOutput;
63 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceReconfigureOutputBuilder;
64 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceRerouteConfirmInput;
65 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceRerouteConfirmOutput;
66 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceRerouteInput;
67 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceRerouteOutput;
68 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceRestorationInput;
69 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceRestorationOutput;
70 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceRestorationOutputBuilder;
71 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceReversionInput;
72 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceReversionOutput;
73 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceRollInput;
74 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceRollOutput;
75 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceRpcResult;
76 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServiceRpcResultBuilder;
77 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.ServicehandlerService;
78 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.TempServiceCreateInput;
79 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.TempServiceCreateOutput;
80 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.TempServiceDeleteInput;
81 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.TempServiceDeleteOutput;
82 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.service.feasibility.check.output.IntermediateSites;
83 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.service.feasibility.check.output.IntermediateSitesBuilder;
84 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.service.list.Services;
85 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.service.list.ServicesBuilder;
86 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.service.list.ServicesKey;
87 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.CancelResourceReserveOutput;
88 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.PathComputationRequestOutput;
89 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.ServicePathRpcResult;
90 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.StubpceListener;
91 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceImplementationRequestOutput;
92 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceRpcResultSp;
93 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.StubrendererListener;
94 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.RpcActions;
95 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ServiceFormat;
96 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ServiceNotificationTypes;
97 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommon;
98 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder;
99 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.response.parameters.ResponseParameters;
100 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.response.parameters.ResponseParametersBuilder;
101 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.ServiceAEnd;
102 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.ServiceAEndBuilder;
103 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.ServiceZEnd;
104 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.ServiceZEndBuilder;
105 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.Topology;
106 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.TopologyBuilder;
107 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.endpoint.RxDirection;
108 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.endpoint.RxDirectionBuilder;
109 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.endpoint.TxDirection;
110 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.endpoint.TxDirectionBuilder;
111 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.lgx.Lgx;
112 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.lgx.LgxBuilder;
113 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.port.Port;
114 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.port.PortBuilder;
115 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.LifecycleState;
116 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.OpticTypes;
117 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.State;
118 import org.opendaylight.yang.gen.v1.http.org.openroadm.topology.rev161014.topology.AToZ;
119 import org.opendaylight.yang.gen.v1.http.org.openroadm.topology.rev161014.topology.AToZBuilder;
120 import org.opendaylight.yang.gen.v1.http.org.openroadm.topology.rev161014.topology.AToZKey;
121 import org.opendaylight.yang.gen.v1.http.org.openroadm.topology.rev161014.topology.ZToA;
122 import org.opendaylight.yang.gen.v1.http.org.openroadm.topology.rev161014.topology.ZToABuilder;
123 import org.opendaylight.yang.gen.v1.http.org.openroadm.topology.rev161014.topology.ZToAKey;
124 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.RpcStatusEx;
125 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.ServicePathNotificationTypes;
126 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
127 import org.opendaylight.yangtools.yang.common.RpcResult;
128 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
129 import org.slf4j.Logger;
130 import org.slf4j.LoggerFactory;
131
132
133 /**
134  * Class to implement ServicehandlerService and ServicehandlerListener.
135  *
136  * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
137  *
138  */
139 public class ServicehandlerImpl implements ServicehandlerService, StubpceListener, StubrendererListener, AutoCloseable {
140     /* Logging. */
141     private static final Logger LOG = LoggerFactory.getLogger(ServicehandlerImpl.class);
142     /* Permit to access database. */
143     private DataBroker db;
144     /* check service sdnc-request-header compliancy. */
145     private ServicehandlerCompliancyCheck compliancyCheck;
146     /* check missing info on Tx/Rx for A/Z end. */
147     private ServicehandlerTxRxCheck txrxCheck;
148     /* check coherency between hard & sof constraints. */
149     private CheckCoherencyHardSoft checkCoherencyHardSoft;
150     /*
151      * Map and Send PCE requests : -
152      * path-computation-request/cancel-resource-reserve.
153      */
154     private MappingAndSendingPCRequest mappingAndSendingPCRequest;
155     /*
156      * Map and Send Service Implemention requests : - service
157      * implementation/service delete.
158      */
159     private MappingAndSendingSIRequest mappingAndSendingSIRequest;
160
161     private RpcProviderRegistry rpcRegistry;
162     private NotificationPublishService notificationPublishService;
163     private final ListeningExecutorService executor;
164
165     private ServicePathRpcResult servicePathRpcResult = null;
166     private ServiceRpcResultSp serviceRpcResultSp = null;
167
168     private String notificationUrl = "";
169     private RpcActions action;
170
171     public ServicehandlerImpl(DataBroker databroker, RpcProviderRegistry rpcRegistry,
172             NotificationPublishService notificationPublishService) {
173         this.db = databroker;
174         this.rpcRegistry = rpcRegistry;
175         this.notificationPublishService = notificationPublishService;
176         executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(5));
177         initializeDataTree(db);
178     }
179
180     @Override
181     public Future<RpcResult<ServiceCreateOutput>> serviceCreate(ServiceCreateInput input) {
182         LOG.info("RPC service creation received");
183         action = RpcActions.ServiceCreate;
184         boolean commonId = true;
185         boolean coherencyHardSoft = false;
186         ServiceRpcResult notification = null;
187         notificationUrl = null;// input.getSdncRequestHeader().getnotificationUrl();
188         LOG.info("notificationUrl : " + notificationUrl);
189
190         ResponseParametersBuilder responseParameters = new ResponseParametersBuilder();
191         ConfigurationResponseCommon configurationResponseCommon;
192         String message = "";
193         String responseCode = "";
194
195         LOG.info("checking Service Compliancy ...");
196         /*
197          * Upon receipt of service
198          * -create RPC, service header and sdnc
199          * -request header compliancy are verified.
200          */
201         compliancyCheck = new ServicehandlerCompliancyCheck(input.getSdncRequestHeader(), input.getServiceName(),
202                 input.getConnectionType(), RpcActions.ServiceCreate);
203         if (compliancyCheck.check(true, true)) {
204             LOG.info("Service compliant !");
205             /*
206              * If compliant, service-request parameters are verified in order to
207              * check if there is no missing parameter that prevents calculating
208              * a path and implement a service.
209              */
210             LOG.info("checking Tx/Rx Info for AEnd ...");
211             txrxCheck = new ServicehandlerTxRxCheck(input.getServiceAEnd(), 1);
212             if (txrxCheck.check()) {
213                 LOG.info("Tx/Rx Info for AEnd checked !");
214                 LOG.info("checking Tx/Rx Info for ZEnd ...");
215                 txrxCheck = new ServicehandlerTxRxCheck(input.getServiceZEnd(), 2);
216                 if (txrxCheck.check()) {
217                     LOG.info("Tx/Rx Info for ZEnd checked");
218                     /*
219                      * If OK, common-id is verified in order to see if there is
220                      * no routing policy provided. If yes, the routing
221                      * constraints of the policy are recovered and coherency
222                      * with hard/soft constraints provided in the input of the
223                      * RPC.
224                      */
225                     if (input.getCommonId() != null) {
226                         LOG.info("Common-id specified");
227                         /*
228                          * Check coherency with hard/soft constraints
229                          */
230
231                         checkCoherencyHardSoft = new CheckCoherencyHardSoft(input.getHardConstraints(),
232                                 input.getSoftConstraints());
233                         if (checkCoherencyHardSoft.check()) {
234                             LOG.info("hard/soft constraints coherent !");
235                             coherencyHardSoft = true;
236                         } else {
237                             LOG.info("hard/soft constraints are not coherent !");
238                             message = "hard/soft constraints are not coherent !";
239                             responseCode = "500";
240                         }
241                     } else {
242                         commonId = false;
243                     }
244
245                     if (!commonId || (commonId && coherencyHardSoft)) {
246                         /*
247                          * Before sending the PCE request, input data need to be
248                          * formatted according to the Service Handler PCE
249                          * interface data model.
250                          */
251                         mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, input, true);
252                         /*
253                          * Once PCE request is being sent to the PCE on
254                          * interface B, PCE reply is expected until a timer
255                          * expires.
256                          */
257                         notification = new ServiceRpcResultBuilder()
258                                 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
259                                 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
260                                 .setStatusMessage("Service compliant, submitting PathComputation Request ...").build();
261                         try {
262                             notificationPublishService.putNotification(notification);
263                         } catch (InterruptedException e) {
264                             LOG.info("notification offer rejected : " + e);
265                         }
266                         sendNotifToUrl(notification, notificationUrl);
267                         FutureCallback<PathComputationRequestOutput> pceCallback =
268                                 new FutureCallback<PathComputationRequestOutput>() {
269                             String message = "";
270                             String responseCode = "";
271                             ServiceRpcResult notification = null;
272
273                             @Override
274                             public void onSuccess(PathComputationRequestOutput response) {
275                                 if (mappingAndSendingPCRequest.getSuccess() && response != null) {
276                                     /*
277                                      * If PCE reply is received before timer
278                                      * expiration with a positive result, a
279                                      * service is created with admin and
280                                      * operational status 'down'.
281                                      */
282                                     LOG.info("PCE replied to PCR Request !");
283
284                                     message = response.getConfigurationResponseCommon().getResponseMessage();
285                                     notification = new ServiceRpcResultBuilder()
286                                             .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
287                                             .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
288                                             .setStatusMessage("PCE replied to PCR Request !").build();
289                                     try {
290                                         notificationPublishService.putNotification(notification);
291                                     } catch (InterruptedException e) {
292                                         LOG.info("notification offer rejected : " + e);
293                                     }
294                                     sendNotifToUrl(notification, notificationUrl);
295                                     String result = null;
296                                     if ((result = writeOrModifyOrDeleteServiceList(input.getServiceName(), input,
297                                             response, 2)) != null) {
298                                         StringBuilder build = new StringBuilder();
299                                         build.append(message);
300                                         build.append(" " + result);
301                                         message = build.toString();
302                                     } else {
303                                         /*
304                                          * Send Implementation order to renderer
305                                          */
306                                         mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry, input,
307                                                 response);
308
309                                         notification = new ServiceRpcResultBuilder()
310                                                 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
311                                                 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
312                                                 .setStatusMessage("Submitting ServiceImplementation Request ...")
313                                                 .build();
314                                         try {
315                                             notificationPublishService.putNotification(notification);
316                                         } catch (InterruptedException e) {
317                                             LOG.info("notification offer rejected : " + e);
318                                         }
319                                         sendNotifToUrl(notification, notificationUrl);
320
321                                         /*
322                                          * Once PCE request is being sent to the
323                                          * PCE on interface B, PCE reply is
324                                          * expected until a timer expires.
325                                          */
326                                         ServiceImplementationRequestOutput siOutput = null;
327                                         try {
328                                             siOutput = mappingAndSendingSIRequest.serviceImplementation().get();
329                                         } catch (InterruptedException | ExecutionException e2) {
330                                             LOG.error("mappingAndSendingSIRequest.serviceImplementation().get() : "
331                                                     + e2.getMessage());
332                                         }
333                                         if (siOutput == null) {
334                                             LOG.info("siOutput is null ");
335                                             LOG.info("Success : " + mappingAndSendingPCRequest.getSuccess());
336                                         }
337                                         if (mappingAndSendingSIRequest.getSuccess() && siOutput != null) {
338                                             ConfigurationResponseCommon siCommon = siOutput
339                                                     .getConfigurationResponseCommon();
340                                             // message =
341                                             // siCommon.getResponseMessage();
342                                             responseCode = siCommon.getResponseCode();
343                                             message = "Service implemented !";
344                                             LOG.info(message);
345                                             notification = new ServiceRpcResultBuilder()
346                                                     .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
347                                                     .setServiceName(input.getServiceName())
348                                                     .setStatus(RpcStatusEx.Successful).setStatusMessage(message)
349                                                     .build();
350                                             try {
351                                                 notificationPublishService.putNotification(notification);
352                                             } catch (InterruptedException e) {
353                                                 LOG.info("notification offer rejected : " + e);
354                                             }
355                                             sendNotifToUrl(notification, notificationUrl);
356                                             /*
357                                              * Service implemented setting
358                                              * Service op status to up
359                                              */
360                                             if (writeOrModifyOrDeleteServiceList(input.getServiceName(), null, null,
361                                                     0) == null) {
362                                                 /*
363                                                  * Service modified.
364                                                  */
365                                                 StringBuilder build = new StringBuilder();
366                                                 build.append(message);
367                                                 build.append(" : Service Op Status changed to Up !");
368                                                 message = build.toString();
369                                             } else {
370                                                 StringBuilder build = new StringBuilder();
371                                                 build.append(message);
372                                                 build.append(" but Failed to modify service from Service List !");
373                                                 message = build.toString();
374                                             }
375                                             notification = new ServiceRpcResultBuilder()
376                                                     .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
377                                                     .setServiceName(input.getServiceName())
378                                                     .setStatus(RpcStatusEx.Successful).setStatusMessage(message)
379                                                     .build();
380                                             try {
381                                                 notificationPublishService.putNotification(notification);
382                                             } catch (InterruptedException e) {
383                                                 LOG.info("notification offer rejected : " + e);
384                                             }
385                                             sendNotifToUrl(notification, notificationUrl);
386                                         } else {
387                                             LOG.info("Service not implemented !");
388                                             message = response.getConfigurationResponseCommon().getResponseMessage();
389                                             notification = new ServiceRpcResultBuilder()
390                                                     .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
391                                                     .setServiceName(input.getServiceName())
392                                                     .setStatus(RpcStatusEx.Failed)
393                                                     .setStatusMessage(
394                                                             "Service not implemented, cancelling ResourceResv ...")
395                                                     .build();
396                                             try {
397                                                 notificationPublishService.putNotification(notification);
398                                             } catch (InterruptedException e) {
399                                                 LOG.info("notification offer rejected : " + e);
400                                             }
401                                             sendNotifToUrl(notification, notificationUrl);
402                                             mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry,
403                                                     input, false);
404                                             /*
405                                              * Send Cancel resource Request to
406                                              * PCE.
407                                              */
408                                             CancelResourceReserveOutput cancelOuptut = null;
409                                             try {
410                                                 cancelOuptut = mappingAndSendingPCRequest.cancelResourceReserve().get();
411                                             } catch (InterruptedException | ExecutionException e1) {
412                                                 LOG.error(e1.getMessage());
413                                             }
414                                             if (mappingAndSendingPCRequest.getSuccess() && cancelOuptut != null) {
415                                                 LOG.info("Service ResourceResv cancelled !");
416                                                 message = response.getConfigurationResponseCommon()
417                                                         .getResponseMessage();
418                                                 notification = new ServiceRpcResultBuilder()
419                                                         .setNotificationType(
420                                                                 ServiceNotificationTypes.ServiceCreateResult)
421                                                         .setServiceName(input.getServiceName())
422                                                         .setStatus(RpcStatusEx.Failed)
423                                                         .setStatusMessage("Service ResourceResv cancelled").build();
424                                                 try {
425                                                     notificationPublishService.putNotification(notification);
426                                                 } catch (InterruptedException e) {
427                                                     LOG.info("notification offer rejected : " + e);
428                                                 }
429                                                 sendNotifToUrl(notification, notificationUrl);
430
431                                                 message = cancelOuptut.getConfigurationResponseCommon()
432                                                         .getResponseMessage();
433                                                 responseCode = cancelOuptut.getConfigurationResponseCommon()
434                                                         .getResponseCode();
435
436                                                 StringBuilder build = new StringBuilder();
437                                                 build.append("Service not implemented - ");
438                                                 build.append(message);
439                                                 message = build.toString();
440
441                                                 LOG.info("PCE replied to CancelResourceResv Request !");
442                                             } else {
443                                                 message = "Cancelling Resource reserved failed ";
444                                                 LOG.info(message);
445                                                 responseCode = "500";
446                                                 StringBuilder build = new StringBuilder();
447                                                 build.append("Service not implemented - ");
448                                                 build.append(message);
449                                                 message = build.toString();
450
451                                                 message = response.getConfigurationResponseCommon()
452                                                         .getResponseMessage();
453                                                 notification = new ServiceRpcResultBuilder()
454                                                         .setNotificationType(
455                                                                 ServiceNotificationTypes.ServiceCreateResult)
456                                                         .setServiceName(input.getServiceName())
457                                                         .setStatus(RpcStatusEx.Failed)
458                                                         .setStatusMessage("Cancelling Resource reserved failed")
459                                                         .build();
460                                                 try {
461                                                     notificationPublishService.putNotification(notification);
462                                                 } catch (InterruptedException e) {
463                                                     LOG.info("notification offer rejected : " + e);
464                                                 }
465                                                 sendNotifToUrl(notification, notificationUrl);
466                                             }
467
468                                         }
469                                     }
470                                 } else {
471                                     message = mappingAndSendingPCRequest.getError();// "Path
472                                                                                     // not
473                                                                                     // calculated";
474                                     responseCode = "500";
475                                     notification = new ServiceRpcResultBuilder()
476                                             .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
477                                             .setServiceName("").setStatus(RpcStatusEx.Failed).setStatusMessage(message)
478                                             .build();
479                                     try {
480                                         notificationPublishService.putNotification(notification);
481                                     } catch (InterruptedException e) {
482                                         LOG.info("notification offer rejected : " + e);
483                                     }
484                                     sendNotifToUrl(notification, notificationUrl);
485                                 }
486
487                             }
488
489                             @Override
490                             public void onFailure(Throwable arg0) {
491                                 LOG.error("Path not calculated..");
492                                 notification = new ServiceRpcResultBuilder()
493                                         .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
494                                         .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
495                                         .setStatusMessage("PCR Request failed  : " + arg0.getMessage()).build();
496                                 try {
497                                     notificationPublishService.putNotification(notification);
498                                 } catch (InterruptedException e) {
499                                     LOG.info("notification offer rejected : " + e);
500                                 }
501                                 sendNotifToUrl(notification, notificationUrl);
502                             }
503                         };
504                         ListenableFuture<PathComputationRequestOutput> pce = mappingAndSendingPCRequest
505                                 .pathComputationRequest();
506                         Futures.addCallback(pce, pceCallback);
507                         LOG.info("PCR Request in progress ");
508                         configurationResponseCommon = new ConfigurationResponseCommonBuilder()
509                                 .setAckFinalIndicator("No").setRequestId(input.getSdncRequestHeader().getRequestId())
510                                 .setResponseMessage("Service compliant, serviceCreate in progress...")
511                                 .setResponseCode("200").build();
512
513                         ServiceCreateOutputBuilder output = new ServiceCreateOutputBuilder()
514                                 .setConfigurationResponseCommon(configurationResponseCommon)
515                                 .setResponseParameters(responseParameters.build());
516
517                         return RpcResultBuilder.success(output.build()).buildFuture();
518                     }
519                 } else {
520                     message = txrxCheck.getMessage();
521                     responseCode = "500";
522                 }
523             } else {
524                 message = txrxCheck.getMessage();
525                 responseCode = "500";
526             }
527         } else {
528             message = compliancyCheck.getMessage();
529             responseCode = "500";
530         }
531
532         configurationResponseCommon = new ConfigurationResponseCommonBuilder().setAckFinalIndicator("Yes")
533                 .setRequestId(input.getSdncRequestHeader().getRequestId()).setResponseMessage(message)
534                 .setResponseCode(responseCode).build();
535
536         ServiceCreateOutputBuilder output = new ServiceCreateOutputBuilder()
537                 .setConfigurationResponseCommon(configurationResponseCommon)
538                 .setResponseParameters(responseParameters.build());
539
540         return RpcResultBuilder.success(output.build()).buildFuture();
541
542     }
543
544     @Override
545     public Future<RpcResult<ServiceDeleteOutput>> serviceDelete(ServiceDeleteInput input) {
546         LOG.info("RPC serviceDelete request received for Service '" + input.getServiceDeleteReqInfo().getServiceName()
547                 + "'");
548         notificationUrl = null;// input.getSdncRequestHeader().getnotificationUrl();
549         String message = "";
550         String responseCode = "";
551         ServiceRpcResult notification = null;
552         ResponseParametersBuilder responseParameters = new ResponseParametersBuilder();
553         LOG.info("checking Service Compliancy ...");
554         /*
555          * Upon receipt of service-delete RPC, service header and sdnc-request
556          * header compliancy are verified.
557          */
558         compliancyCheck = new ServicehandlerCompliancyCheck(input.getSdncRequestHeader(),
559                 input.getServiceDeleteReqInfo().getServiceName(), RpcActions.ServiceDelete);
560         if (compliancyCheck.check(false, true)) {
561             LOG.info("Service compliant !");
562             String serviceName = input.getServiceDeleteReqInfo().getServiceName();
563             Services service = readServiceList(serviceName);
564             if (service != null) {
565                 LOG.debug("Service '" + serviceName + "' present in datastore !");
566                 /*
567                  * If compliant, service-delete order is send to renderer.
568                  */
569                 mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry,
570                         input.getSdncRequestHeader().getRequestId(), input.getServiceDeleteReqInfo().getServiceName());
571
572                 notification = new ServiceRpcResultBuilder()
573                         .setNotificationType(ServiceNotificationTypes.ServiceDeleteResult).setServiceName(serviceName)
574                         .setStatus(RpcStatusEx.Pending)
575                         .setStatusMessage("Service compliant, submitting serviceDelete Request ...").build();
576                 try {
577                     notificationPublishService.putNotification(notification);
578                 } catch (InterruptedException e) {
579                     LOG.info("notification offer rejected : " + e);
580                 }
581                 sendNotifToUrl(notification, notificationUrl);
582                 FutureCallback<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce
583                     .stubrenderer.rev170426.ServiceDeleteOutput> rendererCallback =
584                     new FutureCallback<org.opendaylight.yang.gen.v1.http.org.opendaylight
585                     .transportpce.stubrenderer.rev170426.ServiceDeleteOutput>() {
586                     String message = "";
587                     String responseCode = "";
588                     ServiceRpcResult notification = null;
589
590                     @Override
591                     public void onFailure(Throwable arg0) {
592                         LOG.error("ServiceDelete Request failed !");
593                         notification = new ServiceRpcResultBuilder()
594                                 .setNotificationType(ServiceNotificationTypes.ServiceDeleteResult)
595                                 .setServiceName(serviceName).setStatus(RpcStatusEx.Failed)
596                                 .setStatusMessage("ServiceDelete Request failed !").build();
597                         try {
598                             notificationPublishService.putNotification(notification);
599                         } catch (InterruptedException e) {
600                             LOG.info("notification offer rejected : " + e);
601                         }
602                         sendNotifToUrl(notification, notificationUrl);
603                     }
604
605                     @Override
606                     public void onSuccess(org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce
607                             .stubrenderer.rev170426.ServiceDeleteOutput arg0) {
608
609                         if (mappingAndSendingPCRequest.getSuccess() && arg0 != null) {
610                             message = "Service deleted !";
611                             LOG.info(message);
612                             notification = new ServiceRpcResultBuilder()
613                                     .setNotificationType(ServiceNotificationTypes.ServiceDeleteResult)
614                                     .setServiceName(input.getServiceDeleteReqInfo().getServiceName())
615                                     .setStatus(RpcStatusEx.Successful).setStatusMessage("Service deleted !").build();
616                             try {
617                                 notificationPublishService.putNotification(notification);
618                             } catch (InterruptedException e) {
619                                 LOG.info("notification offer rejected : " + e);
620                             }
621                             sendNotifToUrl(notification, notificationUrl);
622
623                             // message =
624                             // result.getConfigurationResponseCommon().getResponseMessage();
625                             responseCode = arg0.getConfigurationResponseCommon().getResponseCode();
626                             /*
627                              * Service delete confirmed deleting service from
628                              * database
629                              */
630                             if (writeOrModifyOrDeleteServiceList(input.getServiceDeleteReqInfo().getServiceName(), null,
631                                     null, 1) == null) {
632                                 /* Service delete. */
633                                 StringBuilder build = new StringBuilder();
634                                 build.append(message);
635                                 build.append(" : Service deleted from database");
636                                 message = build.toString();
637                             } else {
638                                 StringBuilder build = new StringBuilder();
639                                 build.append(message);
640                                 build.append(" but Failed to delete service from database !");
641                                 message = build.toString();
642                             }
643                             LOG.info(message);
644                             notification = new ServiceRpcResultBuilder()
645                                     .setNotificationType(ServiceNotificationTypes.ServiceDeleteResult)
646                                     .setServiceName(input.getServiceDeleteReqInfo().getServiceName())
647                                     .setStatus(RpcStatusEx.Successful).setStatusMessage(message).build();
648                             try {
649                                 notificationPublishService.putNotification(notification);
650                             } catch (InterruptedException e) {
651                                 LOG.info("notification offer rejected : " + e);
652                             }
653                             sendNotifToUrl(notification, notificationUrl);
654                         } else {
655                             message = "deleting service failed";
656                             responseCode = "500";
657                             notification = new ServiceRpcResultBuilder()
658                                     .setNotificationType(ServiceNotificationTypes.ServiceDeleteResult)
659                                     .setServiceName(input.getServiceDeleteReqInfo().getServiceName())
660                                     .setStatus(RpcStatusEx.Failed).setStatusMessage(message).build();
661                             try {
662                                 notificationPublishService.putNotification(notification);
663                             } catch (InterruptedException e) {
664                                 LOG.info("notification offer rejected : " + e);
665                             }
666                             sendNotifToUrl(notification, notificationUrl);
667                         }
668                     }
669                 };
670                 ListenableFuture<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce
671                     .stubrenderer.rev170426.ServiceDeleteOutput> renderer =
672                     mappingAndSendingSIRequest.serviceDelete();
673                 Futures.addCallback(renderer, rendererCallback);
674                 LOG.info("ServiceDelete Request in progress ... ");
675                 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
676                         .setAckFinalIndicator("No").setRequestId(input.getSdncRequestHeader().getRequestId())
677                         .setResponseMessage("ServiceDelete Request in progress ...").setResponseCode("200").build();
678                 ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
679                         .setConfigurationResponseCommon(configurationResponseCommon).build();
680                 return RpcResultBuilder.success(output).buildFuture();
681             } else {
682                 message = "Service '" + serviceName + "' not exists in datastore";
683                 LOG.error(message);
684             }
685
686         } else {
687             message = "Service not compliant !";
688             responseCode = "500";
689         }
690
691         /*
692          * Building output response.
693          */
694
695         ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
696                 .setAckFinalIndicator("Yes").setRequestId(input.getSdncRequestHeader().getRequestId())
697                 .setResponseMessage(message).setResponseCode(responseCode).build();
698         ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
699                 .setConfigurationResponseCommon(configurationResponseCommon).build();
700         return RpcResultBuilder.success(output).buildFuture();
701     }
702
703     @Override
704     public Future<RpcResult<ServiceFeasibilityCheckOutput>> serviceFeasibilityCheck(
705             ServiceFeasibilityCheckInput input) {
706         notificationUrl = null;// input.getSdncRequestHeader().getnotificationUrl();
707         action = RpcActions.ServiceFeasibilityCheck;
708         LOG.info("RPC service feasibilityCheck received");
709         boolean commonId = true;
710         boolean coherencyHardSoft = false;
711         ServiceRpcResult notification = null;
712         String name = "no name";
713         mappingAndSendingPCRequest = null;
714
715         ConfigurationResponseCommon configurationResponseCommon = null;
716         String message = "";
717         String responseCode = "";
718         LOG.info("checking Service Compliancy ...");
719         /*
720          * Upon receipt of service-create RPC, service header and sdnc-request
721          * header compliancy are verified.
722          */
723         compliancyCheck = new ServicehandlerCompliancyCheck(input.getSdncRequestHeader(), name,
724                 input.getConnectionType(), RpcActions.ServiceFeasibilityCheck);
725         if (compliancyCheck.check(true, true)) {
726             LOG.info("Service compliant !");
727             /*
728              * If compliant, service-request parameters are verified in order to
729              * check if there is no missing parameter that prevents calculating
730              * a path and implement a service.
731              */
732             LOG.info("checking Tx/Rx Info for AEnd ...");
733             txrxCheck = new ServicehandlerTxRxCheck(input.getServiceAEnd(), 1);
734             if (txrxCheck.check()) {
735                 LOG.info("Tx/Rx Info for AEnd checked !");
736                 LOG.info("checking Tx/Rx Info for ZEnd ...");
737                 txrxCheck = new ServicehandlerTxRxCheck(input.getServiceZEnd(), 2);
738                 if (txrxCheck.check()) {
739                     LOG.info("Tx/Rx Info for ZEnd checked");
740                     /*
741                      * If OK, common-id is verified in order to see if there is
742                      * no routing policy provided. If yes, the routing
743                      * constraints of the policy are recovered and coherency
744                      * with hard/soft constraints provided in the input of the
745                      * RPC.
746                      */
747                     if (input.getCommonId() != null) {
748                         LOG.info("Common-id specified");
749                         /*
750                          * Check coherency with hard/soft constraints
751                          */
752
753                         checkCoherencyHardSoft = new CheckCoherencyHardSoft(input.getHardConstraints(),
754                                 input.getSoftConstraints());
755                         if (checkCoherencyHardSoft.check()) {
756                             LOG.info("hard/soft constraints coherent !");
757                             coherencyHardSoft = true;
758                         } else {
759                             LOG.info("hard/soft constraints are not coherent !");
760                             message = "hard/soft constraints are not coherent !";
761                             responseCode = "500";
762                         }
763                     } else {
764                         commonId = false;
765                     }
766
767                     if (!commonId || (commonId && coherencyHardSoft)) {
768                         /*
769                          * Before sending the PCE request, input data need to be
770                          * formatted according to the Service Handler - PCE
771                          * interface data model.
772                          */
773                         mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, input, false);
774                         /*
775                          * Once PCE request is being sent to the PCE on
776                          * interface B, PCE reply is expected until a timer
777                          * expires.
778                          */
779                         notification = new ServiceRpcResultBuilder()
780                                 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult).setServiceName(name)
781                                 .setStatus(RpcStatusEx.Pending)
782                                 .setStatusMessage("Service compliant, Submitting PathComputation Request ...").build();
783                         try {
784                             notificationPublishService.putNotification(notification);
785                         } catch (InterruptedException e) {
786                             LOG.info("notification offer rejected : " + e);
787                         }
788                         sendNotifToUrl(notification, notificationUrl);
789
790                         FutureCallback<PathComputationRequestOutput> pceCallback =
791                                 new FutureCallback<PathComputationRequestOutput>() {
792                             String message = "";
793                             String responseCode = "";
794                             ServiceRpcResult notification = null;
795
796                             @Override
797                             public void onFailure(Throwable arg0) {
798                                 LOG.error("Path not calculated..");
799                                 notification = new ServiceRpcResultBuilder()
800                                         .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
801                                         .setServiceName(name).setStatus(RpcStatusEx.Failed)
802                                         .setStatusMessage("PCR Request failed !").build();
803                                 try {
804                                     notificationPublishService.putNotification(notification);
805                                 } catch (InterruptedException e) {
806                                     LOG.info("notification offer rejected : " + e);
807                                 }
808                                 sendNotifToUrl(notification, notificationUrl);
809
810                             }
811
812                             @Override
813                             public void onSuccess(PathComputationRequestOutput response) {
814
815                                 if (mappingAndSendingPCRequest.getSuccess() && response != null) {
816                                     /*
817                                      * If PCE reply is received before timer
818                                      * expiration with a positive result, a
819                                      * service is created with admin and
820                                      * operational status 'down'.
821                                      */
822                                     LOG.info("PCE replied to PCR Request !");
823                                     notification = new ServiceRpcResultBuilder()
824                                             .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
825                                             .setServiceName("").setStatus(RpcStatusEx.Successful)
826                                             .setStatusMessage("Service Feasility Checked").build();
827                                     try {
828                                         notificationPublishService.putNotification(notification);
829                                     } catch (InterruptedException e) {
830                                         LOG.info("notification offer rejected : " + e);
831                                     }
832                                     message = response.getConfigurationResponseCommon().getResponseMessage();
833                                     sendNotifToUrl(notification, notificationUrl);
834                                 } else {
835                                     message = mappingAndSendingPCRequest.getError();// "Path
836                                                                                     // not
837                                                                                     // calculated";
838                                     responseCode = "500";
839                                     notification = new ServiceRpcResultBuilder()
840                                             .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
841                                             .setServiceName("").setStatus(RpcStatusEx.Failed).setStatusMessage(message)
842                                             .build();
843                                     try {
844                                         notificationPublishService.putNotification(notification);
845                                     } catch (InterruptedException e) {
846                                         LOG.info("notification offer rejected : " + e);
847                                     }
848                                     sendNotifToUrl(notification, notificationUrl);
849                                 }
850                             }
851
852                         };
853                         ListenableFuture<PathComputationRequestOutput> pce = mappingAndSendingPCRequest
854                                 .pathComputationRequest();
855                         Futures.addCallback(pce, pceCallback);
856                         LOG.info("PCR Request in progress ");
857                         configurationResponseCommon = new ConfigurationResponseCommonBuilder()
858                                 .setAckFinalIndicator("No").setRequestId(input.getSdncRequestHeader().getRequestId())
859                                 .setResponseMessage("Service compliant, ServiceFeasibilityCheck in progress...")
860                                 .setResponseCode("200").build();
861
862                         ServiceFeasibilityCheckOutput output = new ServiceFeasibilityCheckOutputBuilder()
863                                 .setConfigurationResponseCommon(configurationResponseCommon).build();
864
865                         return RpcResultBuilder.success(output).buildFuture();
866
867                     }
868                 } else {
869                     message = txrxCheck.getMessage();
870                     responseCode = "500";
871                 }
872             } else {
873                 message = txrxCheck.getMessage();
874                 responseCode = "500";
875             }
876         } else {
877             message = compliancyCheck.getMessage();
878             responseCode = "500";
879         }
880
881         configurationResponseCommon = new ConfigurationResponseCommonBuilder().setAckFinalIndicator("Yes")
882                 .setRequestId(input.getSdncRequestHeader().getRequestId()).setResponseMessage(message)
883                 .setResponseCode(responseCode).build();
884
885         ResponseParameters responseParameters = new ResponseParametersBuilder()
886                 .setHardConstraints(input.getHardConstraints())
887                 // .setPceMetric(input.getPceMetric())
888                 .setSoftConstraints(input.getSoftConstraints())
889                 // .setLocallyProtectedLinks(input.isLocallyProtectedLinks())
890                 .build();
891
892         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.service.feasibility
893             .check.output.ServiceAEnd serviceAEnd = new org.opendaylight.yang.gen.v1.http.org.opendaylight
894                 .transportpce.servicehandler.rev161014.service.feasibility
895                 .check.output.ServiceAEndBuilder(input.getServiceAEnd()).build();
896
897         org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.service.feasibility
898             .check.output.ServiceZEnd serviceZEnd = new org.opendaylight.yang.gen.v1.http.org.opendaylight
899             .transportpce.servicehandler.rev161014.service.feasibility
900             .check.output.ServiceZEndBuilder(input.getServiceZEnd()).build();
901
902         /* TxDirection. */
903         Port txPort = new PortBuilder().setPortDeviceName("ROUTER_SNJSCAMCJW1_000000.00_00").setPortType("router")
904                 .setPortName("Gigabit Ethernet_Tx.ge-1/0/0.0").setPortRack("000000.00").setPortShelf("00").build();
905         Lgx txLgx = new LgxBuilder().setLgxDeviceName("LGX Panel_SNJSCAMCJW1_000000.00_00")
906                 .setLgxPortName("LGX_Back.23").setLgxPortRack("000000.00").setLgxPortShelf("00").build();
907         TxDirection txDirection = new TxDirectionBuilder().setPort(txPort).setLgx(txLgx).build();
908
909         /* RxDirection. */
910         Port rxPort = new PortBuilder().setPortDeviceName("ROUTER_SNJSCAMCJW1_000000.00_00").setPortType("router")
911                 .setPortName("Gigabit Ethernet_Rx.ge-1/0/0.0").setPortRack("000000.00").setPortShelf("00").build();
912         Lgx rxLgx = new LgxBuilder().setLgxDeviceName("LGX Panel_SNJSCAMCJW1_000000.00_00").setLgxPortName("LGX_Back.6")
913                 .setLgxPortRack("000000.00").setLgxPortShelf("00").build();
914         RxDirection rxDirection = new RxDirectionBuilder().setPort(rxPort).setLgx(rxLgx).build();
915
916         IntermediateSites inter = new IntermediateSitesBuilder().setClli("SNJSCAMCJW1").setServiceRate((long) 100)
917                 .setServiceFormat(ServiceFormat.Ethernet).setOpticType(OpticTypes.Gray).setTxDirection(txDirection)
918                 .setRxDirection(rxDirection).build();
919
920         List<IntermediateSites> intersites = new ArrayList<IntermediateSites>();
921         intersites.add(inter);
922         ServiceFeasibilityCheckOutput output = new ServiceFeasibilityCheckOutputBuilder()
923                 .setIntermediateSites(intersites).setResponseParameters(responseParameters)
924                 .setConfigurationResponseCommon(configurationResponseCommon).setServiceAEnd(serviceAEnd)
925                 .setServiceZEnd(serviceZEnd).build();
926
927         return RpcResultBuilder.success(output).buildFuture();
928     }
929
930     @Override
931     public Future<RpcResult<ServiceReconfigureOutput>> serviceReconfigure(ServiceReconfigureInput input) {
932
933         LOG.info("RPC service reconfigure received");
934         notificationUrl = null;// input.getnotificationUrl();
935         boolean commonId = true;
936         boolean coherencyHardSoft = false;
937         ServiceRpcResult notification = null;
938
939         String message = "";
940         LOG.info("checking Service Compliancy ...");
941         /*
942          * Upon receipt of service-create RPC, service header and sdnc-request
943          * header compliancy are verified.
944          */
945         compliancyCheck = new ServicehandlerCompliancyCheck(input.getServiceName(), input.getConnectionType(),
946                 RpcActions.ServiceReconfigure);
947         if (compliancyCheck.check(true, false)) {
948             LOG.info("Service compliant !");
949             /*
950              * If compliant, service-request parameters are verified in order to
951              * check if there is no missing parameter that prevents calculating
952              * a path and implement a service.
953              */
954             LOG.info("checking Tx/Rx Info for AEnd ...");
955             txrxCheck = new ServicehandlerTxRxCheck(input.getServiceAEnd(), 1);
956             if (txrxCheck.check()) {
957                 LOG.info("Tx/Rx Info for AEnd checked !");
958                 LOG.info("checking Tx/Rx Info for ZEnd ...");
959                 txrxCheck = new ServicehandlerTxRxCheck(input.getServiceZEnd(), 2);
960                 if (txrxCheck.check()) {
961                     LOG.info("Tx/Rx Info for ZEnd checked");
962                     /*
963                      * If OK, common-id is verified in order to see if there is
964                      * no routing policy provided. If yes, the routing
965                      * constraints of the policy are recovered and coherency
966                      * with hard/soft constraints provided in the input of the
967                      * RPC.
968                      */
969                     if (input.getCommonId() != null) {
970                         LOG.info("Common-id specified");
971                         /*
972                          * Check coherency with hard/soft constraints
973                          */
974
975                         checkCoherencyHardSoft = new CheckCoherencyHardSoft(input.getHardConstraints(),
976                                 input.getSoftConstraints());
977                         if (checkCoherencyHardSoft.check()) {
978                             LOG.info("hard/soft constraints coherent !");
979                             coherencyHardSoft = true;
980                         } else {
981                             LOG.info("hard/soft constraints are not coherent !");
982                             message = "hard/soft constraints are not coherent !";
983                         }
984                     } else {
985                         commonId = false;
986                     }
987
988                     if (!commonId || (commonId && coherencyHardSoft)) {
989                         /*
990                          * Retrieving initial service topology.
991                          */
992                         String serviceName = input.getServiceName();
993                         Services service = readServiceList(serviceName);
994                         if (service != null) {
995                             LOG.debug("Service '" + serviceName + "' present in datastore !");
996                             /*
997                              * Sending cancel resource resv request to PCE
998                              */
999
1000                             mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, input, false);
1001                             notification = new ServiceRpcResultBuilder()
1002                                     .setNotificationType(ServiceNotificationTypes.ServiceReconfigureResult)
1003                                     .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1004                                     .setStatusMessage("Cancelling ResourceResv ...").build();
1005                             try {
1006                                 notificationPublishService.putNotification(notification);
1007                             } catch (InterruptedException e) {
1008                                 LOG.info("notification offer rejected : " + e);
1009                             }
1010                             sendNotifToUrl(notification, notificationUrl);
1011                             FutureCallback<CancelResourceReserveOutput> pceCallback =
1012                                     new FutureCallback<CancelResourceReserveOutput>() {
1013                                 String message = "";
1014                                 String responseCode = "";
1015                                 ServiceRpcResult notification = null;
1016
1017                                 @Override
1018                                 public void onFailure(Throwable arg0) {
1019                                     LOG.error("Failed to cancel ResourceResv ! ");
1020                                     notification = new ServiceRpcResultBuilder()
1021                                             .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
1022                                             .setServiceName(serviceName).setStatus(RpcStatusEx.Failed)
1023                                             .setStatusMessage("PCR Request failed !").build();
1024                                     try {
1025                                         notificationPublishService.putNotification(notification);
1026                                     } catch (InterruptedException e) {
1027                                         LOG.info("notification offer rejected : " + e);
1028                                     }
1029
1030                                 }
1031
1032                                 @Override
1033                                 public void onSuccess(CancelResourceReserveOutput arg0) {
1034                                     if (mappingAndSendingPCRequest.getSuccess() && arg0 != null) {
1035                                         LOG.info("Service ResourceResv cancelled !");
1036                                         notification = new ServiceRpcResultBuilder()
1037                                                 .setNotificationType(ServiceNotificationTypes.ServiceReconfigureResult)
1038                                                 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1039                                                 .setStatusMessage(
1040                                                         "Service '" + serviceName + "' ResourceResv cancelled")
1041                                                 .build();
1042                                         try {
1043                                             notificationPublishService.putNotification(notification);
1044                                         } catch (InterruptedException e) {
1045                                             LOG.info("notification offer rejected : " + e);
1046                                         }
1047                                         sendNotifToUrl(notification, notificationUrl);
1048
1049                                         message = "Service '" + serviceName + "' ResourceResv cancelled";
1050
1051                                         LOG.info("PCE replied to CancelResourceResv Request !");
1052                                         /*
1053                                          * Before sending the PCE request, input
1054                                          * data need to be formatted according
1055                                          * to the Service Handler - PCE
1056                                          * interface data model.
1057                                          */
1058                                         mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, input,
1059                                                 true);
1060                                         /*
1061                                          * Once PCE request is being sent to the
1062                                          * PCE on interface B, PCE reply is
1063                                          * expected until a timer expires.
1064                                          */
1065                                         notification = new ServiceRpcResultBuilder()
1066                                                 .setNotificationType(ServiceNotificationTypes.ServiceReconfigureResult)
1067                                                 .setServiceName(serviceName).setStatus(RpcStatusEx.Pending)
1068                                                 .setStatusMessage(message + ", submitting PathComputation Request ...")
1069                                                 .build();
1070                                         try {
1071                                             notificationPublishService.putNotification(notification);
1072                                         } catch (InterruptedException e) {
1073                                             LOG.info("notification offer rejected : " + e);
1074                                         }
1075                                         sendNotifToUrl(notification, notificationUrl);
1076                                         PathComputationRequestOutput response = null;
1077                                         try {
1078                                             response = mappingAndSendingPCRequest.pathComputationRequest().get();
1079                                         } catch (InterruptedException | ExecutionException e2) {
1080                                             LOG.error(e2.getMessage());
1081                                         }
1082
1083                                         if (mappingAndSendingPCRequest.getSuccess() && response != null) {
1084                                             /*
1085                                              * If PCE reply is received before
1086                                              * timer expiration with a positive
1087                                              * result, a service is created with
1088                                              * admin and operational status
1089                                              * 'down'.
1090                                              */
1091                                             LOG.info("PCE replied to PCR Request !");
1092                                             message = response.getConfigurationResponseCommon().getResponseMessage();
1093                                             notification = new ServiceRpcResultBuilder()
1094                                                     .setNotificationType(
1095                                                             ServiceNotificationTypes.ServiceReconfigureResult)
1096                                                     .setServiceName(serviceName).setStatus(RpcStatusEx.Pending)
1097                                                     .setStatusMessage("PCE replied to PCR Request !").build();
1098                                             try {
1099                                                 notificationPublishService.putNotification(notification);
1100                                             } catch (InterruptedException e) {
1101                                                 LOG.info("notification offer rejected : " + e);
1102                                             }
1103                                             sendNotifToUrl(notification, notificationUrl);
1104                                             /*
1105                                              * Send Implementation order to
1106                                              * renderer
1107                                              */
1108                                             mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry,
1109                                                     input, response);
1110
1111                                             notification = new ServiceRpcResultBuilder()
1112                                                     .setNotificationType(
1113                                                             ServiceNotificationTypes.ServiceReconfigureResult)
1114                                                     .setServiceName(input.getServiceName())
1115                                                     .setStatus(RpcStatusEx.Pending)
1116                                                     .setStatusMessage("Submitting ServiceImplementation Request ...")
1117                                                     .build();
1118                                             try {
1119                                                 notificationPublishService.putNotification(notification);
1120                                             } catch (InterruptedException e) {
1121                                                 LOG.info("notification offer rejected : " + e);
1122                                             }
1123                                             sendNotifToUrl(notification, notificationUrl);
1124
1125                                             ServiceImplementationRequestOutput siOutput = null;
1126                                             try {
1127                                                 siOutput = mappingAndSendingSIRequest.serviceImplementation().get();
1128                                             } catch (InterruptedException | ExecutionException e2) {
1129                                                 LOG.error(e2.getMessage());
1130                                             }
1131                                             ConfigurationResponseCommon siCommon = siOutput
1132                                                     .getConfigurationResponseCommon();
1133                                             message = siCommon.getResponseMessage();
1134
1135                                             if (mappingAndSendingSIRequest.getSuccess() && siOutput != null) {
1136                                                 message = "Service reconfigured ";
1137                                                 LOG.info("Service reconfigured !");
1138                                                 notification = new ServiceRpcResultBuilder()
1139                                                         .setNotificationType(
1140                                                                 ServiceNotificationTypes.ServiceReconfigureResult)
1141                                                         .setServiceName(input.getServiceName())
1142                                                         .setStatus(RpcStatusEx.Pending)
1143                                                         .setStatusMessage("Service reconfigure !").build();
1144                                                 try {
1145                                                     notificationPublishService.putNotification(notification);
1146                                                 } catch (InterruptedException e) {
1147                                                     LOG.info("notification offer rejected : " + e);
1148                                                 }
1149                                                 sendNotifToUrl(notification, notificationUrl);
1150                                                 /*
1151                                                  * Service implemented Update in
1152                                                  * DB.
1153                                                  */
1154                                                 Boolean update = false;
1155                                                 Boolean delete = false;
1156                                                 Services modifService = mappingServices(null, input, response);
1157                                                 InstanceIdentifier<Services> iid = InstanceIdentifier
1158                                                         .create(ServiceList.class)
1159                                                         .child(Services.class, new ServicesKey(serviceName));
1160                                                 WriteTransaction writeTx = db.newWriteOnlyTransaction();
1161                                                 writeTx.delete(LogicalDatastoreType.OPERATIONAL, iid);
1162                                                 try {
1163                                                     LOG.info("Deleting service info ...");
1164                                                     writeTx.submit().checkedGet();
1165                                                     delete = true;
1166                                                 } catch (TransactionCommitFailedException e) {
1167                                                     LOG.error("Failed to delete service from Service List");
1168                                                 }
1169                                                 if (delete) {
1170                                                     iid = InstanceIdentifier.create(ServiceList.class).child(
1171                                                             Services.class, new ServicesKey(input.getNewServiceName()));
1172                                                     writeTx = db.newWriteOnlyTransaction();
1173                                                     writeTx.put(LogicalDatastoreType.OPERATIONAL, iid, modifService);
1174                                                     try {
1175                                                         LOG.info("Updating service info ...");
1176                                                         writeTx.submit().checkedGet();
1177                                                         update = true;
1178                                                     } catch (TransactionCommitFailedException e) {
1179                                                         LOG.error("Failed to modify service from Service List");
1180                                                     }
1181                                                 }
1182                                                 if (update) {
1183                                                     LOG.info("Service '" + serviceName + "' updated with new name '"
1184                                                             + input.getNewServiceName() + "' ! ");
1185                                                     StringBuilder build = new StringBuilder();
1186                                                     build.append(message);
1187                                                     build.append(" : Service updated on DataBase !");
1188                                                     message = build.toString();
1189                                                 } else {
1190                                                     LOG.info("Service '" + serviceName + "' update failed  ! ");
1191                                                     StringBuilder build = new StringBuilder();
1192                                                     build.append(message);
1193                                                     build.append(" : Failed to modify service from Service List ");
1194                                                     message = build.toString();
1195                                                 }
1196                                             } else {
1197                                                 LOG.info("Service not implemented !");
1198                                                 message = response.getConfigurationResponseCommon()
1199                                                         .getResponseMessage();
1200                                                 notification = new ServiceRpcResultBuilder()
1201                                                         .setNotificationType(
1202                                                                 ServiceNotificationTypes.ServiceReconfigureResult)
1203                                                         .setServiceName(input.getServiceName())
1204                                                         .setStatus(RpcStatusEx.Failed)
1205                                                         .setStatusMessage(
1206                                                                 "Service not implemented, cancelling ResourceResv")
1207                                                         .build();
1208                                                 try {
1209                                                     notificationPublishService.putNotification(notification);
1210                                                 } catch (InterruptedException e) {
1211                                                     LOG.info("notification offer rejected : " + e);
1212                                                 }
1213                                                 sendNotifToUrl(notification, notificationUrl);
1214                                                 mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry,
1215                                                         input, false);
1216                                                 /*
1217                                                  * Send Cancel resource Request
1218                                                  * to PCE.
1219                                                  */
1220                                                 CancelResourceReserveOutput cancelOuptut = null;
1221                                                 try {
1222                                                     cancelOuptut = mappingAndSendingPCRequest.cancelResourceReserve()
1223                                                             .get();
1224                                                 } catch (InterruptedException | ExecutionException e1) {
1225                                                     LOG.error(e1.getMessage());
1226                                                 }
1227                                                 if (mappingAndSendingPCRequest.getSuccess() && cancelOuptut != null) {
1228                                                     LOG.info("Service ResourceResv cancelled !");
1229                                                     message = response.getConfigurationResponseCommon()
1230                                                             .getResponseMessage();
1231                                                     notification = new ServiceRpcResultBuilder()
1232                                                             .setNotificationType(
1233                                                                     ServiceNotificationTypes.ServiceReconfigureResult)
1234                                                             .setServiceName(input.getServiceName())
1235                                                             .setStatus(RpcStatusEx.Failed)
1236                                                             .setStatusMessage("Service ResourceResv cancelled").build();
1237                                                     try {
1238                                                         notificationPublishService.putNotification(notification);
1239                                                     } catch (InterruptedException e) {
1240                                                         LOG.info("notification offer rejected : " + e);
1241                                                     }
1242                                                     sendNotifToUrl(notification, notificationUrl);
1243
1244                                                     message = cancelOuptut.getConfigurationResponseCommon()
1245                                                             .getResponseMessage();
1246
1247                                                     StringBuilder build = new StringBuilder();
1248                                                     build.append("Service not implemented - ");
1249                                                     build.append(message);
1250                                                     message = build.toString();
1251
1252                                                     LOG.info("PCE replied to CancelResourceResv Request !");
1253                                                 } else {
1254                                                     message = "Cancelling Resource reserved failed ";
1255                                                     LOG.info(message);
1256                                                     StringBuilder build = new StringBuilder();
1257                                                     build.append("Service not implemented - ");
1258                                                     build.append(message);
1259                                                     message = build.toString();
1260
1261                                                     message = response.getConfigurationResponseCommon()
1262                                                             .getResponseMessage();
1263                                                     notification = new ServiceRpcResultBuilder()
1264                                                             .setNotificationType(
1265                                                                     ServiceNotificationTypes.ServiceReconfigureResult)
1266                                                             .setServiceName(input.getServiceName())
1267                                                             .setStatus(RpcStatusEx.Failed)
1268                                                             .setStatusMessage("Cancelling Resource reserved failed")
1269                                                             .build();
1270                                                     try {
1271                                                         notificationPublishService.putNotification(notification);
1272                                                     } catch (InterruptedException e) {
1273                                                         LOG.info("notification offer rejected : " + e);
1274                                                     }
1275                                                     sendNotifToUrl(notification, notificationUrl);
1276                                                 }
1277                                             }
1278
1279                                         } else {
1280                                             LOG.error("PCE pathcomputation request failed !");
1281                                             message = "PCE pathcomputation request failed : "
1282                                                     + mappingAndSendingPCRequest.getError();// "Path
1283                                                                                             // not
1284                                                                                             // calculated";
1285                                         }
1286                                     } else {
1287                                         message = "Cancelling Resource reserved failed ";
1288                                         LOG.info(message);
1289                                         StringBuilder build = new StringBuilder();
1290                                         build.append("Service not implemented - ");
1291                                         build.append(message);
1292                                         message = build.toString();
1293
1294                                         notification = new ServiceRpcResultBuilder()
1295                                                 .setNotificationType(ServiceNotificationTypes.ServiceReconfigureResult)
1296                                                 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
1297                                                 .setStatusMessage("Cancelling Resource reserved failed").build();
1298                                         try {
1299                                             notificationPublishService.putNotification(notification);
1300                                         } catch (InterruptedException e) {
1301                                             LOG.info("notification offer rejected : " + e);
1302                                         }
1303                                         sendNotifToUrl(notification, notificationUrl);
1304                                     }
1305
1306                                 }
1307                             };
1308                             ListenableFuture<CancelResourceReserveOutput> pce = mappingAndSendingPCRequest
1309                                     .cancelResourceReserve();
1310                             Futures.addCallback(pce, pceCallback);
1311                             LOG.info("CancelResRev Request in progress ");
1312                             ServiceReconfigureOutput output = new ServiceReconfigureOutputBuilder()
1313                                     .setStatus(RpcStatusEx.Pending).setStatusMessage(message).build();
1314
1315                             return RpcResultBuilder.success(output).buildFuture();
1316
1317                         } else {
1318                             message = "Service '" + serviceName + "' not exists in datastore";
1319                             LOG.error(message);
1320                         }
1321                     }
1322                 } else {
1323                     message = txrxCheck.getMessage();
1324                 }
1325             } else {
1326                 message = txrxCheck.getMessage();
1327             }
1328         } else {
1329             message = compliancyCheck.getMessage();
1330         }
1331
1332         ServiceReconfigureOutput output = new ServiceReconfigureOutputBuilder().setStatus(RpcStatusEx.Successful)
1333                 .setStatusMessage(message).build();
1334
1335         return RpcResultBuilder.success(output).buildFuture();
1336     }
1337
1338     @Override
1339     public Future<RpcResult<ServiceRestorationOutput>> serviceRestoration(ServiceRestorationInput input) {
1340         LOG.info("RPC service restoration received");
1341         ServiceRpcResult notification = null;
1342         notificationUrl = null;// input.getnotificationUrl();
1343         String message = "";
1344         LOG.info("checking Service Compliancy ...");
1345         compliancyCheck = new ServicehandlerCompliancyCheck(input.getServiceName(), RpcActions.ServiceRestoration);
1346         if (compliancyCheck.check(false, false)) {
1347             LOG.info("Service compliant !");
1348             /*
1349              * If compliant, Getting path from service DB.
1350              */
1351
1352             String serviceName = input.getServiceName();
1353             Services service = readServiceList(serviceName);
1354             if (service != null) {
1355                 LOG.debug("Service '" + serviceName + "' present in datastore !");
1356                 notification = new ServiceRpcResultBuilder()
1357                         .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1358                         .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1359                         .setStatusMessage("Service '" + serviceName + "' present in datastore, deleting service ...")
1360                         .build();
1361                 try {
1362                     notificationPublishService.putNotification(notification);
1363                 } catch (InterruptedException e) {
1364                     LOG.info("notification offer rejected : " + e);
1365                 }
1366                 sendNotifToUrl(notification, notificationUrl);
1367                 /*
1368                  * Sending delete order to renderer
1369                  */
1370                 mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry, null, input.getServiceName());
1371
1372                 ListenableFuture<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce
1373                     .stubrenderer.rev170426.ServiceDeleteOutput> renderer =
1374                     mappingAndSendingSIRequest.serviceDelete();
1375                 FutureCallback<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce
1376                     .stubrenderer.rev170426.ServiceDeleteOutput> rendererCallback =
1377                     new FutureCallback<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce
1378                     .stubrenderer.rev170426.ServiceDeleteOutput>() {
1379                     String message = "";
1380                     String responseCode = "";
1381                     ServiceRpcResult notification = null;
1382
1383                     @Override
1384                     public void onFailure(Throwable arg0) {
1385                         LOG.error("ServiceDelete Request failed !");
1386                         notification = new ServiceRpcResultBuilder()
1387                                 .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1388                                 .setServiceName(serviceName).setStatus(RpcStatusEx.Failed)
1389                                 .setStatusMessage("ServiceDelete Request failed !").build();
1390                         try {
1391                             notificationPublishService.putNotification(notification);
1392                         } catch (InterruptedException e) {
1393                             LOG.info("notification offer rejected : " + e);
1394                         }
1395                         sendNotifToUrl(notification, notificationUrl);
1396                     }
1397
1398                     @Override
1399                     public void onSuccess(org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce
1400                             .stubrenderer.rev170426.ServiceDeleteOutput arg0) {
1401                         if (arg0 != null) {
1402                             message = arg0.getConfigurationResponseCommon().getResponseMessage();
1403                             notification = new ServiceRpcResultBuilder()
1404                                     .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1405                                     .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1406                                     .setStatusMessage("Service deleted !").build();
1407                             try {
1408                                 notificationPublishService.putNotification(notification);
1409                             } catch (InterruptedException e) {
1410                                 LOG.info("notification offer rejected : " + e);
1411                             }
1412                             sendNotifToUrl(notification, notificationUrl);
1413                             mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, service, true);
1414                             /*
1415                              * Once PCE request is being sent to the PCE on
1416                              * interface B, PCE reply is expected until a timer
1417                              * expires.
1418                              */
1419                             notification = new ServiceRpcResultBuilder()
1420                                     .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1421                                     .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1422                                     .setStatusMessage("Service deleted, submitting PathComputation Request ...")
1423                                     .build();
1424                             try {
1425                                 notificationPublishService.putNotification(notification);
1426                             } catch (InterruptedException e) {
1427                                 LOG.info("notification offer rejected : " + e);
1428                             }
1429                             sendNotifToUrl(notification, notificationUrl);
1430                             PathComputationRequestOutput response = null;
1431                             try {
1432                                 response = mappingAndSendingPCRequest.pathComputationRequest().get();
1433                             } catch (InterruptedException | ExecutionException e2) {
1434                                 LOG.error(e2.getMessage());
1435                             }
1436
1437                             if (mappingAndSendingPCRequest.getSuccess() && response != null) {
1438                                 /*
1439                                  * If PCE reply is received before timer
1440                                  * expiration with a positive result, a service
1441                                  * is created with admin and operational status
1442                                  * 'down'.
1443                                  */
1444                                 LOG.info("Path calculated !");
1445                                 message = response.getConfigurationResponseCommon().getResponseMessage();
1446                                 notification = new ServiceRpcResultBuilder()
1447                                         .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1448                                         .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1449                                         .setStatusMessage("Path calculated, modifying Service Admin / Op ...").build();
1450                                 try {
1451                                     notificationPublishService.putNotification(notification);
1452                                 } catch (InterruptedException e) {
1453                                     LOG.info("notification offer rejected : " + e);
1454                                 }
1455                                 sendNotifToUrl(notification, notificationUrl);
1456
1457                                 /*
1458                                  * creating Service with Admin / Op to down.
1459                                  *
1460                                  */
1461
1462                                 ServicesBuilder serviceRestoration = new ServicesBuilder(service)
1463                                         .setAdministrativeState(State.OutOfService)
1464                                         .setOperationalState(State.OutOfService)
1465                                         .setLifecycleState(LifecycleState.Planned);
1466
1467                                 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
1468                                     .service.types.rev170426.response
1469                                         .parameters.sp.ResponseParameters responseParameters =
1470                                         response.getResponseParameters();
1471                                 if (responseParameters != null) {
1472                                     // serviceRestoration.setPceMetric(responseParameters.getPceMetric());
1473                                     org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
1474                                         .service.types.rev170426.response.parameters.sp.response
1475                                             .parameters.PathDescription pathDescription =
1476                                             responseParameters.getPathDescription();
1477                                     if (pathDescription != null) {
1478                                         List<AToZ> atozList = new ArrayList<AToZ>();
1479                                         List<ZToA> ztoaList = new ArrayList<ZToA>();
1480
1481                                         for (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
1482                                                     .pathdescription.rev170426.path.description.atoz.direction.AToZ
1483                                                     tmp : pathDescription.getAToZDirection().getAToZ()) {
1484
1485                                             AToZKey key = new AToZKey(tmp.getKey().getId());
1486                                             tmp.getResource().getResource();
1487                                             AToZ atoz = new AToZBuilder().setId(tmp.getId()).setKey(key)
1488                                                     // .setResource(tmp.getResource())
1489                                                     .build();
1490                                             atozList.add(atoz);
1491                                         }
1492
1493                                         for (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
1494                                                     .pathdescription.rev170426.path.description.ztoa.direction.ZToA
1495                                                     tmp : pathDescription.getZToADirection().getZToA()) {
1496                                             ZToAKey key = new ZToAKey(tmp.getKey().getId());
1497                                             ZToA ztoa = new ZToABuilder().setId(tmp.getId()).setKey(key)
1498                                                     // .setResource(tmp.getResource())
1499                                                     .build();
1500                                             ztoaList.add(ztoa);
1501                                         }
1502                                         Topology topology = new TopologyBuilder().setAToZ(atozList).setZToA(ztoaList)
1503                                                 .build();
1504                                         serviceRestoration.setTopology(topology);
1505                                     }
1506                                 }
1507                                 Boolean update = false;
1508                                 InstanceIdentifier<Services> iid = InstanceIdentifier.create(ServiceList.class)
1509                                         .child(Services.class, new ServicesKey(serviceName));
1510                                 WriteTransaction writeTx = db.newWriteOnlyTransaction();
1511                                 writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, service);
1512
1513                                 try {
1514                                     writeTx.submit().checkedGet();
1515                                     update = true;
1516                                 } catch (TransactionCommitFailedException e) {
1517                                     LOG.error("Failed to modify service from Service List");
1518                                 }
1519                                 if (update) {
1520                                     LOG.info("Service modified !");
1521                                     /*
1522                                      * Send Implementation order to renderer
1523                                      */
1524                                     mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry, service);
1525
1526                                     notification = new ServiceRpcResultBuilder()
1527                                             .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1528                                             .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1529                                             .setStatusMessage(
1530                                                     "Service modified, submitting ServiceImplementation Request")
1531                                             .build();
1532                                     try {
1533                                         notificationPublishService.putNotification(notification);
1534                                     } catch (InterruptedException e) {
1535                                         LOG.info("notification offer rejected : " + e);
1536                                     }
1537                                     sendNotifToUrl(notification, notificationUrl);
1538
1539                                     ServiceImplementationRequestOutput siOutput = null;
1540                                     try {
1541                                         siOutput = mappingAndSendingSIRequest.serviceImplementation().get();
1542                                     } catch (InterruptedException | ExecutionException e2) {
1543                                         LOG.error(e2.getMessage());
1544                                     }
1545                                     if (mappingAndSendingSIRequest.getSuccess() && siOutput != null) {
1546                                         ConfigurationResponseCommon siCommon = siOutput
1547                                                 .getConfigurationResponseCommon();
1548                                         message = siCommon.getResponseMessage();
1549                                         LOG.info("Service restored !");
1550                                         notification = new ServiceRpcResultBuilder()
1551                                                 .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1552                                                 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1553                                                 .setStatusMessage("Service restored !").build();
1554                                         try {
1555                                             notificationPublishService.putNotification(notification);
1556                                         } catch (InterruptedException e) {
1557                                             LOG.info("notification offer rejected : " + e);
1558                                         }
1559                                         sendNotifToUrl(notification, notificationUrl);
1560                                         /*
1561                                          * Service implemented setting Service
1562                                          * op status to up
1563                                          */
1564                                         if (writeOrModifyOrDeleteServiceList(serviceName, null, null, 0) == null) {
1565                                             message = "Service restored : Service Op Status changed to Up !";
1566                                         } else {
1567                                             message = "Service restored : "
1568                                                     + "but Failed to modify service from Service List !";
1569                                         }
1570                                     } else {
1571                                         LOG.info("Service not restored !");
1572                                         message = response.getConfigurationResponseCommon().getResponseMessage();
1573                                         notification = new ServiceRpcResultBuilder()
1574                                                 .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1575                                                 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
1576                                                 .setStatusMessage("Service not restored, cancelling ResourceResv ...")
1577                                                 .build();
1578                                         try {
1579                                             notificationPublishService.putNotification(notification);
1580                                         } catch (InterruptedException e) {
1581                                             LOG.info("notification offer rejected : " + e);
1582                                         }
1583                                         sendNotifToUrl(notification, notificationUrl);
1584                                         mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry,
1585                                                 service, false);
1586                                         /*
1587                                          * Send Cancel resource Request to PCE.
1588                                          */
1589                                         CancelResourceReserveOutput cancelOuptut = null;
1590                                         try {
1591                                             cancelOuptut = mappingAndSendingPCRequest.cancelResourceReserve().get();
1592                                         } catch (InterruptedException | ExecutionException e1) {
1593                                             LOG.error(e1.getMessage());
1594                                         }
1595                                         if (mappingAndSendingPCRequest.getSuccess() && cancelOuptut != null) {
1596                                             LOG.info("Service ResourceResv cancelled !");
1597                                             message = response.getConfigurationResponseCommon().getResponseMessage();
1598                                             notification = new ServiceRpcResultBuilder()
1599                                                     .setNotificationType(
1600                                                             ServiceNotificationTypes.ServiceRestorationResult)
1601                                                     .setServiceName(input.getServiceName())
1602                                                     .setStatus(RpcStatusEx.Pending)
1603                                                     .setStatusMessage("Service ResourceResv cancelled").build();
1604                                             try {
1605                                                 notificationPublishService.putNotification(notification);
1606                                             } catch (InterruptedException e) {
1607                                                 LOG.info("notification offer rejected : " + e);
1608                                             }
1609                                             sendNotifToUrl(notification, notificationUrl);
1610                                             message = cancelOuptut.getConfigurationResponseCommon()
1611                                                     .getResponseMessage();
1612                                             StringBuilder build = new StringBuilder();
1613                                             build.append("Service not implemented - ");
1614                                             build.append(message);
1615                                             message = build.toString();
1616                                             LOG.info("PCE replied to CancelResourceResv Request !");
1617                                         } else {
1618                                             message = "Cancelling Resource reserved failed ";
1619                                             LOG.info(message);
1620                                             StringBuilder build = new StringBuilder();
1621                                             build.append("Service not implemented - ");
1622                                             build.append(message);
1623                                             message = build.toString();
1624                                             message = response.getConfigurationResponseCommon().getResponseMessage();
1625                                             notification = new ServiceRpcResultBuilder()
1626                                                     .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
1627                                                     .setServiceName(input.getServiceName())
1628                                                     .setStatus(RpcStatusEx.Failed)
1629                                                     .setStatusMessage("Cancelling Resource reserved failed").build();
1630                                             try {
1631                                                 notificationPublishService.putNotification(notification);
1632                                             } catch (InterruptedException e) {
1633                                                 LOG.info("notification offer rejected : " + e);
1634                                             }
1635                                             sendNotifToUrl(notification, notificationUrl);
1636                                         }
1637                                     }
1638                                 } else {
1639                                     LOG.error("Failed to modify service from service list !");
1640                                 }
1641                             } else {
1642                                 message = mappingAndSendingPCRequest.getError();
1643                                 /* Path not calculated. */
1644                                 LOG.error("Path Computation request failed : " + message);
1645                             }
1646                         } else {
1647                             message = "deleting service failed";
1648                             LOG.error(message);
1649                         }
1650                     }
1651                 };
1652                 Futures.addCallback(renderer, rendererCallback);
1653                 ServiceRestorationOutput output = new ServiceRestorationOutputBuilder().setStatus(RpcStatusEx.Pending)
1654                         .setStatusMessage(message).build();
1655
1656                 return RpcResultBuilder.success(output).buildFuture();
1657
1658             } else {
1659                 message = "Service '" + serviceName + "' not exists in datastore";
1660                 LOG.error(message);
1661             }
1662
1663         } else {
1664             message = compliancyCheck.getMessage();
1665             LOG.error(message);
1666         }
1667
1668         ServiceRestorationOutput output = new ServiceRestorationOutputBuilder().setStatus(RpcStatusEx.Successful)
1669                 .setStatusMessage(message).build();
1670
1671         return RpcResultBuilder.success(output).buildFuture();
1672     }
1673
1674     /*
1675      * Initialize ServiceList Structure on Datastore.
1676      *
1677      * @param DataBroker
1678      *            Access Datastore
1679      */
1680     private void initializeDataTree(DataBroker db) {
1681         LOG.info("Preparing to initialize the greeting registry");
1682         WriteTransaction transaction = db.newWriteOnlyTransaction();
1683         InstanceIdentifier<ServiceList> iid = InstanceIdentifier.create(ServiceList.class);
1684         ServiceList greetingRegistry = new ServiceListBuilder().build();
1685         transaction.put(LogicalDatastoreType.OPERATIONAL, iid, greetingRegistry);
1686         CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
1687         Futures.addCallback(future, new LoggingFuturesCallBack<>("Failed to create Service List", LOG));
1688     }
1689
1690     /*
1691      * Map Input (ServiceCreateInmput, ServiceReconfigureInput) & output
1692      * (PathComputationRequestOutput) to Service.
1693      *
1694      * @param serviceCreateInput
1695      *            ServiceCreateInput parameter
1696      * @param serviceReconfigureInput
1697      *            serviceReconfigureInput parameter
1698      * @param output
1699      *            PathComputationRequestOutput parameter
1700      *
1701      * @return Services Service data
1702      */
1703     private Services mappingServices(ServiceCreateInput serviceCreateInput,
1704             ServiceReconfigureInput serviceReconfigureInput, PathComputationRequestOutput output) {
1705         LOG.info("Mapping informations to Services");
1706         ServiceAEnd aend = null;
1707         ServiceZEnd zend = null;
1708         ServicesBuilder service = new ServicesBuilder();
1709         if (serviceCreateInput != null) {
1710             aend = new ServiceAEndBuilder(serviceCreateInput.getServiceAEnd()).build();
1711             zend = new ServiceZEndBuilder(serviceCreateInput.getServiceZEnd()).build();
1712             service.setServiceName(serviceCreateInput.getServiceName()).setAdministrativeState(State.OutOfService)
1713                     .setOperationalState(State.OutOfService).setCommonId(serviceCreateInput.getCommonId())
1714                     .setConnectionType(serviceCreateInput.getConnectionType())
1715                     .setCustomer(serviceCreateInput.getCustomer())
1716                     .setCustomerContact(serviceCreateInput.getCustomerContact())
1717                     .setHardConstraints(serviceCreateInput.getHardConstraints())
1718                     .setSoftConstraints(serviceCreateInput.getSoftConstraints())
1719                     .setLifecycleState(LifecycleState.Planned).setServiceAEnd(aend).setServiceZEnd(zend);
1720
1721         } else if (serviceReconfigureInput != null) {
1722             aend = new ServiceAEndBuilder(serviceReconfigureInput.getServiceAEnd()).build();
1723             zend = new ServiceZEndBuilder(serviceReconfigureInput.getServiceZEnd()).build();
1724             service.setServiceName(serviceReconfigureInput.getNewServiceName())
1725                     .setAdministrativeState(State.OutOfService).setOperationalState(State.OutOfService)
1726                     .setCommonId(serviceReconfigureInput.getCommonId())
1727                     .setConnectionType(serviceReconfigureInput.getConnectionType())
1728                     .setCustomer(serviceReconfigureInput.getCustomer())
1729                     .setCustomerContact(serviceReconfigureInput.getCustomerContact())
1730                     .setHardConstraints(serviceReconfigureInput.getHardConstraints())
1731                     .setSoftConstraints(serviceReconfigureInput.getSoftConstraints())
1732                     .setLifecycleState(LifecycleState.Planned).setServiceAEnd(aend).setServiceZEnd(zend);
1733         }
1734
1735         org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.response
1736             .parameters.sp.ResponseParameters responseParameters = output.getResponseParameters();
1737         if (responseParameters != null) {
1738             // service.setPceMetric(responseParameters.getPceMetric());
1739             org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426
1740                 .response.parameters.sp.response.parameters.PathDescription pathDescription =
1741                     responseParameters.getPathDescription();
1742             if (pathDescription != null) {
1743                 List<AToZ> atozList = new ArrayList<AToZ>();
1744                 List<ZToA> ztoaList = new ArrayList<ZToA>();
1745
1746                 for (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426
1747                             .path.description.atoz.direction.AToZ
1748                                 tmp : pathDescription.getAToZDirection().getAToZ()) {
1749
1750                     AToZKey key = new AToZKey(tmp.getKey().getId());
1751                     AToZ atoz = new AToZBuilder().setId(tmp.getId()).setKey(key)
1752                             // .setResource(tmp.getResource())
1753                             .build();
1754                     atozList.add(atoz);
1755                 }
1756
1757                 for (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426
1758                             .path.description.ztoa.direction.ZToA
1759                                 tmp : pathDescription.getZToADirection().getZToA()) {
1760                     ZToAKey key = new ZToAKey(tmp.getKey().getId());
1761                     ZToA ztoa = new ZToABuilder().setId(tmp.getId()).setKey(key)
1762                             // .setResource(tmp.getResource())
1763                             .build();
1764                     ztoaList.add(ztoa);
1765                 }
1766
1767                 Topology topology = new TopologyBuilder().setAToZ(atozList).setZToA(ztoaList).build();
1768                 service.setTopology(topology);
1769             }
1770         }
1771         return service.build();
1772     }
1773
1774     /*
1775      * read Service from ServiceList DataStore.
1776      *
1777      * @param serviceName
1778      *            Name of Service
1779      *
1780      * @return <code>Services</code>
1781      */
1782     private Services readServiceList(String serviceName) {
1783         Services result = null;
1784         ReadOnlyTransaction readTx = db.newReadOnlyTransaction();
1785         InstanceIdentifier<Services> iid = InstanceIdentifier.create(ServiceList.class).child(Services.class,
1786                 new ServicesKey(serviceName));
1787         CheckedFuture<Optional<Services>, ReadFailedException> future = readTx.read(LogicalDatastoreType.OPERATIONAL,
1788                 iid);
1789         Optional<Services> optional = Optional.absent();
1790         try {
1791             optional = future.checkedGet();
1792         } catch (ReadFailedException e) {
1793             LOG.error("Reading service failed:", e);
1794         }
1795         if (optional.isPresent()) {
1796             LOG.debug("Service '" + serviceName + "' present !");
1797             result = new ServicesBuilder(optional.get()).build();
1798         }
1799         return result;
1800     }
1801
1802     /*
1803      * Write or Modify or Delete Service from/to SreviceList.
1804      *
1805      * @param serviceName
1806      *            Name of service
1807      * @param input
1808      *            ServiceCreateInput
1809      * @param output
1810      *            PathComputationRequestOutput
1811      * @param choice
1812      *            0 - Modify 1 - Delete 2 - Write
1813      * @return String operations result, null if ok or not otherwise
1814      */
1815     private String writeOrModifyOrDeleteServiceList(String serviceName, ServiceCreateInput input,
1816             PathComputationRequestOutput output, int choice) {
1817         LOG.debug("WriteOrModifyOrDeleting '" + serviceName + "' Service");
1818         WriteTransaction writeTx = db.newWriteOnlyTransaction();
1819         String result = null;
1820         Services readService = readServiceList(serviceName);
1821         if (readService != null) {
1822             /*
1823              * Modify / Delete Service.
1824              */
1825             InstanceIdentifier<Services> iid = InstanceIdentifier.create(ServiceList.class).child(Services.class,
1826                     new ServicesKey(serviceName));
1827             ServicesBuilder service = new ServicesBuilder(readService);
1828
1829             String action = null;
1830             switch (choice) {
1831                 case 0: /* Modify. */
1832                     LOG.debug("Modifying '" + serviceName + "' Service");
1833                     service.setOperationalState(State.InService).setAdministrativeState(State.InService);
1834                     writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, service.build());
1835                     action = "modify";
1836                     break;
1837
1838                 case 1: /* Delete */
1839                     LOG.debug("Deleting '" + serviceName + "' Service");
1840                     writeTx.delete(LogicalDatastoreType.OPERATIONAL, iid);
1841                     action = "delete";
1842                     break;
1843
1844                 default:
1845                     LOG.debug("No choice found");
1846                     break;
1847
1848             }
1849             try {
1850                 writeTx.submit().checkedGet();
1851             } catch (TransactionCommitFailedException e) {
1852                 LOG.error("Failed to " + action + " service from Service List");
1853                 result = "Failed to " + action + " service from Service List";
1854             }
1855         } else {
1856             if (choice == 2) { /* Write Service */
1857                 LOG.debug("Writing '" + serviceName + "' Service");
1858                 InstanceIdentifier<Services> iid = InstanceIdentifier.create(ServiceList.class).child(Services.class,
1859                         new ServicesKey(serviceName));
1860
1861                 Services service = mappingServices(input, null, output);
1862                 writeTx.put(LogicalDatastoreType.OPERATIONAL, iid, service);
1863                 try {
1864                     writeTx.submit().checkedGet();
1865                     result = null;
1866                 } catch (TransactionCommitFailedException e) {
1867                     LOG.error("Failed to write service to Service List");
1868                     result = "Failed to write service to Service List";
1869                 }
1870             } else {
1871                 LOG.info("Service is not present ! ");
1872                 result = "Service is not present ! ";
1873             }
1874         }
1875         return result;
1876     }
1877
1878     private void sendNotifToUrl(ServiceRpcResult notification, String url) {
1879         Gson gson = new GsonBuilder().setPrettyPrinting()
1880                 // .serializeNulls()
1881                 .create();
1882         String data = gson.toJson(notification);
1883         URL obj;
1884         try {
1885             obj = new URL(url);
1886             HttpURLConnection con = (HttpURLConnection) obj.openConnection();
1887
1888             // add request header
1889             con.setRequestMethod("POST");
1890             con.setRequestProperty("Content-Type", "application/json");
1891             con.setRequestProperty("Accept", "application/json");
1892
1893             // Send post request
1894             con.setDoOutput(true);
1895             DataOutputStream wr = new DataOutputStream(con.getOutputStream());
1896             wr.writeBytes(data);
1897             wr.flush();
1898             wr.close();
1899             int responseCode = con.getResponseCode();
1900             LOG.info("Response Code : " + responseCode);
1901         } catch (IOException e) {
1902             LOG.error("IOException : " + e.toString());
1903         }
1904
1905     }
1906
1907     @Override
1908     public void close() throws Exception {
1909         executor.shutdown();
1910     }
1911
1912     @Override
1913     public Future<RpcResult<EquipmentNotificationOutput>> equipmentNotification(EquipmentNotificationInput input) {
1914         // TODO Auto-generated method stub
1915         return null;
1916     }
1917
1918     @Override
1919     public Future<RpcResult<ServiceRerouteConfirmOutput>> serviceRerouteConfirm(ServiceRerouteConfirmInput input) {
1920         // TODO Auto-generated method stub
1921         return null;
1922     }
1923
1924     @Override
1925     public Future<RpcResult<ServiceRerouteOutput>> serviceReroute(ServiceRerouteInput input) {
1926         // TODO Auto-generated method stub
1927         return null;
1928     }
1929
1930     @Override
1931     public Future<RpcResult<ServiceReversionOutput>> serviceReversion(ServiceReversionInput input) {
1932         // TODO Auto-generated method stub
1933         return null;
1934     }
1935
1936     @Override
1937     public Future<RpcResult<ServiceRollOutput>> serviceRoll(ServiceRollInput input) {
1938         // TODO Auto-generated method stub
1939         return null;
1940     }
1941
1942     @Override
1943     public Future<RpcResult<NetworkReOptimizationOutput>> networkReOptimization(NetworkReOptimizationInput input) {
1944         // TODO Auto-generated method stub
1945         return null;
1946     }
1947
1948     @Override
1949     public Future<RpcResult<TempServiceDeleteOutput>> tempServiceDelete(TempServiceDeleteInput input) {
1950         // TODO Auto-generated method stub
1951         return null;
1952     }
1953
1954     @Override
1955     public Future<RpcResult<TempServiceCreateOutput>> tempServiceCreate(TempServiceCreateInput input) {
1956         // TODO Auto-generated method stub
1957         return null;
1958     }
1959
1960     @Override
1961     public void onServiceRpcResultSp(ServiceRpcResultSp notification) {
1962         if (!compareServiceRpcResultSp(notification)) {
1963             serviceRpcResultSp = notification;
1964             StringBuilder build = new StringBuilder();
1965             build.append(
1966                     "Received '" + notification.getNotificationType() + "' StubRenderer notification" + "from service '"
1967                             + notification.getServiceName() + "' " + "with status '" + notification.getStatus() + "'");
1968             build.append(" with StatusMessage '" + notification.getStatusMessage() + "'");
1969             if (notification.getStatus() == RpcStatusEx.Successful && notification.getNotificationType()
1970                     .getIntValue() == ServicePathNotificationTypes.ServiceImplementationRequest.getIntValue()) {
1971                 build.append(" PathTopology : " + notification.getPathTopology().toString());
1972             }
1973             LOG.info(build.toString());
1974         } else {
1975             LOG.info("ServicePathRpcResult already wired !");
1976         }
1977
1978     }
1979
1980     @Override
1981     public void onServicePathRpcResult(ServicePathRpcResult notification) {
1982         if (!compareServicePathRpcResult(notification)) {
1983             servicePathRpcResult = notification;
1984             StringBuilder build = new StringBuilder();
1985             build.append(
1986                     "Received '" + notification.getNotificationType() + "' StubPce notification " + "from service '"
1987                             + notification.getServiceName() + "' " + "with status '" + notification.getStatus() + "'");
1988             build.append(" with StatusMessage '" + notification.getStatusMessage() + "'");
1989             if (notification.getStatus() == RpcStatusEx.Successful && notification.getNotificationType()
1990                     .getIntValue() == ServicePathNotificationTypes.PathComputationRequest.getIntValue()) {
1991                 build.append(" PathDescription : " + notification.getPathDescription().toString());
1992                 /*
1993                  * switch (action.getIntValue()) { case 1: //service-create case
1994                  * 3: //service-delete case 8: //service-reconfigure case 9:
1995                  * //service-restoration case 10://service-reversion case
1996                  * 11://service-reroute break;
1997                  *
1998                  * default: break; }
1999                  */
2000             }
2001
2002             LOG.info(build.toString());
2003         } else {
2004             LOG.info("ServicePathRpcResult already wired !");
2005         }
2006     }
2007
2008     public RpcActions getAction() {
2009         return action;
2010     }
2011
2012     public void setAction(RpcActions action) {
2013         this.action = action;
2014     }
2015
2016     public Boolean compareServicePathRpcResult(ServicePathRpcResult notification) {
2017         Boolean result = true;
2018         if (servicePathRpcResult == null) {
2019             result = false;
2020         } else {
2021             if (servicePathRpcResult.getNotificationType() != notification.getNotificationType()) {
2022                 result = false;
2023             }
2024             if (servicePathRpcResult.getServiceName() != notification.getServiceName()) {
2025                 result = false;
2026             }
2027             if (servicePathRpcResult.getStatus() != notification.getStatus()) {
2028                 result = false;
2029             }
2030             if (servicePathRpcResult.getStatusMessage() != notification.getStatusMessage()) {
2031                 result = false;
2032             }
2033         }
2034         return result;
2035     }
2036
2037     public Boolean compareServiceRpcResultSp(ServiceRpcResultSp notification) {
2038         Boolean result = true;
2039         if (serviceRpcResultSp == null) {
2040             result = false;
2041         } else {
2042             if (serviceRpcResultSp.getNotificationType() != notification.getNotificationType()) {
2043                 result = false;
2044             }
2045             if (serviceRpcResultSp.getServiceName() != notification.getServiceName()) {
2046                 result = false;
2047             }
2048             if (serviceRpcResultSp.getStatus() != notification.getStatus()) {
2049                 result = false;
2050             }
2051             if (serviceRpcResultSp.getStatusMessage() != notification.getStatusMessage()) {
2052                 result = false;
2053             }
2054         }
2055         return result;
2056     }
2057 }