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