2 * Copyright © 2017 Orange, Inc. and others. All rights reserved.
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
9 package org.opendaylight.transportpce.servicehandler.impl;
11 import com.google.common.base.Optional;
13 import com.google.common.util.concurrent.FutureCallback;
14 import com.google.common.util.concurrent.Futures;
15 import com.google.common.util.concurrent.ListenableFuture;
16 import com.google.common.util.concurrent.ListeningExecutorService;
17 import com.google.common.util.concurrent.MoreExecutors;
19 import java.util.ArrayList;
20 import java.util.List;
21 import java.util.concurrent.ExecutionException;
22 import java.util.concurrent.Executors;
23 import java.util.concurrent.Future;
25 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
26 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
27 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
28 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
29 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
30 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
31 import org.opendaylight.transportpce.servicehandler.CheckCoherencyHardSoft;
32 import org.opendaylight.transportpce.servicehandler.MappingAndSendingPCRequest;
33 import org.opendaylight.transportpce.servicehandler.MappingAndSendingSIRequest;
34 import org.opendaylight.transportpce.servicehandler.ServicehandlerCompliancyCheck;
35 import org.opendaylight.transportpce.servicehandler.ServicehandlerTxRxCheck;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev170930.ServiceRpcResultSh;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev170930.ServiceRpcResultShBuilder;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.PathComputationRequestOutput;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.PathComputationRequestOutputBuilder;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.ServicePathRpcResult;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.StubpceListener;
42 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.ServiceRpcResultSp;
43 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubrenderer.rev170426.StubrendererListener;
44 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ConnectionType;
45 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.RpcActions;
46 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ServiceEndpoint;
47 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ServiceNotificationTypes;
48 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommon;
49 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.configuration.response.common.ConfigurationResponseCommonBuilder;
50 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.sdnc.request.header.SdncRequestHeader;
51 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.ServiceAEnd;
52 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.ServiceAEndBuilder;
53 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.ServiceZEnd;
54 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.ServiceZEndBuilder;
55 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.Topology;
56 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.service.TopologyBuilder;
57 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.LifecycleState;
58 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.RpcStatus;
59 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.types.rev161014.State;
60 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.HardConstraints;
61 import org.opendaylight.yang.gen.v1.http.org.openroadm.routing.constrains.rev161014.routing.constraints.SoftConstraints;
62 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.EquipmentNotificationInput;
63 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.EquipmentNotificationOutput;
64 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.NetworkReOptimizationInput;
65 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.NetworkReOptimizationOutput;
66 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.OrgOpenroadmServiceService;
67 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInput;
68 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateOutput;
69 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateOutputBuilder;
70 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteInput;
71 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteOutput;
72 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceDeleteOutputBuilder;
73 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceFeasibilityCheckInput;
74 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceFeasibilityCheckOutput;
75 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceFeasibilityCheckOutputBuilder;
76 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceList;
77 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceListBuilder;
78 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureInput;
79 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureOutput;
80 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReconfigureOutputBuilder;
81 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteConfirmInput;
82 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteConfirmOutput;
83 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteInput;
84 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRerouteOutput;
85 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationInput;
86 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationOutput;
87 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRestorationOutputBuilder;
88 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReversionInput;
89 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceReversionOutput;
90 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRollInput;
91 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceRollOutput;
92 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateInput;
93 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceCreateOutput;
94 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceDeleteInput;
95 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.TempServiceDeleteOutput;
96 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.Services;
97 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.ServicesBuilder;
98 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.service.list.ServicesKey;
99 import org.opendaylight.yang.gen.v1.http.org.openroadm.topology.rev161014.topology.AToZ;
100 import org.opendaylight.yang.gen.v1.http.org.openroadm.topology.rev161014.topology.AToZBuilder;
101 import org.opendaylight.yang.gen.v1.http.org.openroadm.topology.rev161014.topology.AToZKey;
102 import org.opendaylight.yang.gen.v1.http.org.openroadm.topology.rev161014.topology.ZToA;
103 import org.opendaylight.yang.gen.v1.http.org.openroadm.topology.rev161014.topology.ZToABuilder;
104 import org.opendaylight.yang.gen.v1.http.org.openroadm.topology.rev161014.topology.ZToAKey;
105 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.RpcStatusEx;
106 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.response.parameters.sp.response.parameters.PathDescription;
107 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.response.parameters.sp.response.parameters.PathDescriptionBuilder;
108 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.service.rpc.result.sp.PathTopology;
109 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.service.rpc.result.sp.PathTopologyBuilder;
110 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
111 import org.opendaylight.yangtools.yang.common.RpcResult;
112 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
113 import org.slf4j.Logger;
114 import org.slf4j.LoggerFactory;
118 * Class to implement ServicehandlerService and ServicehandlerListener.
120 * @author <a href="mailto:martial.coulibaly@gfi.com">Martial Coulibaly</a> on behalf of Orange
122 public class ServicehandlerImpl implements OrgOpenroadmServiceService,StubpceListener,
123 StubrendererListener,AutoCloseable {
125 private static final Logger LOG = LoggerFactory.getLogger(ServicehandlerImpl.class);
126 /** Permit to access database. */
127 private DataBroker db;
128 /** check service sdnc-request-header compliancy. */
129 private ServicehandlerCompliancyCheck compliancyCheck;
130 /** check missing info on Tx/Rx for A/Z end. */
131 private ServicehandlerTxRxCheck txrxCheck;
132 /** check coherency between hard and soft constraints. */
133 private CheckCoherencyHardSoft checkCoherencyHardSoft;
135 * Map and Send PCE requests : -
136 * path-computation-request/cancel-resource-reserve.
138 private MappingAndSendingPCRequest mappingAndSendingPCRequest;
140 * Map and Send Service Implemention requests : - service
141 * implementation/service delete.
143 private MappingAndSendingSIRequest mappingAndSendingSIRequest;
145 private RpcProviderRegistry rpcRegistry;
146 private NotificationPublishService notificationPublishService;
147 private final ListeningExecutorService executor;
149 private ServicePathRpcResult servicePathRpcResult = null;
150 private ServiceRpcResultSp serviceRpcResultSp = null;
152 private String notificationUrl = "";
153 private RpcActions action;
155 private PathDescription pathDescription;
156 private PathTopology pathTopology;
157 private ServiceCreateInput serviceCreateInput;
158 private ServiceDeleteInput serviceDeleteInput;
159 private ServiceReconfigureInput serviceReconfigureInput;
160 private Services service;
161 private ServiceFeasibilityCheckInput serviceFeasibilityCheckInput;
163 public ServicehandlerImpl(DataBroker databroker, RpcProviderRegistry rpcRegistry,
164 NotificationPublishService notificationPublishService) {
165 this.db = databroker;
166 this.rpcRegistry = rpcRegistry;
167 this.notificationPublishService = notificationPublishService;
168 executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(5));
169 serviceCreateInput = null;
170 setServiceDeleteInput(null);
171 setServiceReconfigureInput(null);
172 initializeDataTree(db);
176 * delete service from
177 * datastore after receiving
178 * Stubrenderer notification.
181 private void deleteServiceFromDatastore() {
182 String serviceName = null;
183 if (serviceDeleteInput != null) {
184 LOG.info("deleteServiceFromDatastore came from RPC serviceDelete");
185 serviceName = serviceDeleteInput.getServiceDeleteReqInfo().getServiceName();
186 } else if (service != null) {
187 LOG.info("deleteServiceFromDatastore came from RPC serviceRestoration");
188 serviceName = service.getServiceName();
190 if (serviceName != null) {
191 LOG.info("deleting service '" + serviceName + "'from datastore ...");
192 ServiceRpcResultSh notification = null;
195 * Service delete confirmed deleting service from
198 if (writeOrModifyOrDeleteServiceList(serviceName, null,
200 /** Service delete. */
201 message = "Service deleted from database";
203 message = "deleting service from database failed !";
206 notification = new ServiceRpcResultShBuilder()
207 .setNotificationType(ServiceNotificationTypes.ServiceDeleteResult)
208 .setServiceName(serviceDeleteInput.getServiceDeleteReqInfo().getServiceName())
209 .setStatus(RpcStatusEx.Successful).setStatusMessage(message).build();
211 notificationPublishService.putNotification(notification);
212 } catch (InterruptedException e) {
213 LOG.info("notification offer rejected : " + e);
216 LOG.error("Parameter 'ServiceName' fro deleteServiceFromDatastore is null !");
222 *Put Service status to up
223 *and add topology information
224 *after receiving Stubrenderer
225 *service implementation
228 * @param input ServiceCreateInput or
230 private <T> void updateServiceStatus(T input) {
231 LOG.info("Updating Service Status ...");
232 ServiceRpcResultSh notification = null;
234 String serviceName = null;
235 ServiceNotificationTypes notif = null;
236 if (input instanceof ServiceCreateInput) {
237 LOG.info("Updating Service Status came from RPC serviceCreateInput ...");
238 serviceName = serviceCreateInput.getServiceName();
239 notif = ServiceNotificationTypes.ServiceCreateResult;
240 } else if (input instanceof ServiceReconfigureInput) {
241 LOG.info("Updating Service Status came from RPC serviceReconfigure ...");
242 serviceName = serviceReconfigureInput.getNewServiceName();
243 notif = ServiceNotificationTypes.ServiceReconfigureResult;
244 } else if (input instanceof Services) {
245 LOG.info("Updating Service Status came from RPC serviceRestoration ...");
246 serviceName = service.getServiceName();
247 notif = ServiceNotificationTypes.ServiceRestorationResult;
249 if (serviceName != null && notif != null) {
250 if (pathTopology != null) {
251 LOG.info("PathTopology contains in Stubrenderer notification received !");
252 Topology topo = new TopologyBuilder()
253 .setAToZ(pathTopology.getAToZ())
254 .setZToA(pathTopology.getZToA())
258 * Service implemented setting
259 * Service op status to up.
261 if (writeOrModifyOrDeleteServiceList(serviceName, null,topo,0) == null) {
265 StringBuilder build = new StringBuilder();
266 build.append(message);
267 build.append(" : Service Op Status changed to Up !");
268 message = build.toString();
270 StringBuilder build = new StringBuilder();
271 build.append(message);
272 build.append(" but Failed to modify service from Service List !");
273 message = build.toString();
275 notification = new ServiceRpcResultShBuilder()
276 .setNotificationType(notif)
277 .setServiceName(serviceCreateInput.getServiceName())
278 .setStatus(RpcStatusEx.Successful).setStatusMessage(message)
281 notificationPublishService.putNotification(notification);
282 } catch (InterruptedException e) {
283 LOG.info("notification offer rejected : " + e);
286 message = "pathTopology not in stubrenderer notification, cancelling pce resource reserve ...";
288 notification = new ServiceRpcResultShBuilder()
289 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
290 .setServiceName(serviceCreateInput.getServiceName())
291 .setStatus(RpcStatusEx.Failed)
292 .setStatusMessage("message")
295 notificationPublishService.putNotification(notification);
296 } catch (InterruptedException e) {
297 LOG.info("notification offer rejected : " + e);
299 pceCancelResResource();
302 LOG.info("Parameters 'serviceName' or/ and 'notiftype' is null");
307 * Send pathComputation
310 * @param input ServiceCreate or ServiceReconfigure or Services
312 private <T> void pcePathComputation(T input) {
313 LOG.info("sending pathcomputation request to pce ...");
314 ServiceRpcResultSh notification = null;
315 String serviceName = null;
316 ServiceNotificationTypes type = null;
318 * Before sending the PCE request, input data need to be
319 * formatted according to the Service Handler PCE
320 * interface data model.
322 if (input instanceof ServiceReconfigureInput) {
323 LOG.info("PCR came from RPC serviceReconfigure ...");
324 ServiceReconfigureInput tmp = (ServiceReconfigureInput)input;
325 serviceName = tmp.getNewServiceName();
326 type = ServiceNotificationTypes.ServiceReconfigureResult;
327 mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, tmp, true);
328 } else if (input instanceof ServiceCreateInput) {
329 LOG.info("PCR came from RPC serviceCreate ...");
330 ServiceCreateInput tmp = (ServiceCreateInput)input;
331 serviceName = tmp.getServiceName();
332 type = ServiceNotificationTypes.ServiceCreateResult;
333 mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, tmp, true);
334 } else if (input instanceof Services) {
335 LOG.info("PCR came from RPC serviceRestoration ...");
336 Services tmp = (Services)input;
337 serviceName = tmp.getServiceName();
338 type = ServiceNotificationTypes.ServiceRestorationResult;
339 mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, tmp, true);
340 } else if (input instanceof ServiceFeasibilityCheckInput) {
341 LOG.info("PCR came from RPC ServiceFeasibilityCheck ...");
342 ServiceFeasibilityCheckInput tmp = (ServiceFeasibilityCheckInput)input;
343 serviceName = "no name";
344 type = ServiceNotificationTypes.ServiceCreateResult;
345 mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, tmp, false);
347 final String name = serviceName;
348 final ServiceNotificationTypes notifType = type;
351 * Once PCE request is being sent to the PCE on
352 * interface B, PCE reply is expected until a timer
355 notification = new ServiceRpcResultShBuilder()
356 .setNotificationType(notifType)
357 .setServiceName(serviceName).setStatus(RpcStatusEx.Pending)
358 .setStatusMessage("Service compliant, submitting PathComputation Request ...").build();
360 notificationPublishService.putNotification(notification);
361 } catch (InterruptedException e) {
362 LOG.info("notification offer rejected : " + e);
364 FutureCallback<Boolean> pceCallback = new FutureCallback<Boolean>() {
366 ServiceRpcResultSh notification = null;
369 public void onSuccess(Boolean response) {
372 * If PCE reply is received before timer
373 * expiration with a positive result, a
374 * service is created with admin and
375 * operational status 'down'.
377 message = "PCE replied to PCR Request !";
379 notification = new ServiceRpcResultShBuilder()
380 .setNotificationType(notifType)
381 .setServiceName(name).setStatus(RpcStatusEx.Pending)
382 .setStatusMessage(message).build();
384 notificationPublishService.putNotification(notification);
385 } catch (InterruptedException e) {
386 LOG.info("notification offer rejected : " + e);
389 message = mappingAndSendingPCRequest.getError();
390 notification = new ServiceRpcResultShBuilder()
391 .setNotificationType(notifType)
392 .setServiceName("").setStatus(RpcStatusEx.Failed).setStatusMessage(message)
395 notificationPublishService.putNotification(notification);
396 } catch (InterruptedException e) {
397 LOG.info("notification offer rejected : " + e);
403 public void onFailure(Throwable arg0) {
404 LOG.error("Path not calculated..");
405 notification = new ServiceRpcResultShBuilder()
406 .setNotificationType(notifType)
407 .setServiceName(name).setStatus(RpcStatusEx.Failed)
408 .setStatusMessage("PCR Request failed : " + arg0.getMessage()).build();
410 notificationPublishService.putNotification(notification);
411 } catch (InterruptedException e) {
412 LOG.info("notification offer rejected : " + e);
417 ListenableFuture<Boolean> pce = mappingAndSendingPCRequest.pathComputationRequest();
418 Futures.addCallback(pce, pceCallback, executor);
422 * Send RPC cancel reserve
425 private void pceCancelResResource() {
426 LOG.info("sending RPC cancel reserve resource to PCE ...");
427 Services pceService = null;
428 ServiceNotificationTypes notif = null;
429 if (serviceDeleteInput != null) {
430 LOG.info("pceCancelResResource came from RPC serviceDelete");
431 notif = ServiceNotificationTypes.ServiceDeleteResult;
432 String serviceName = serviceDeleteInput.getServiceDeleteReqInfo().getServiceName();
433 if (serviceName != null) {
434 pceService = readServiceList(serviceName);
436 LOG.info("Parameter 'serviceName' for pceCancelResResource is null");
438 } else if (service != null) {
439 notif = ServiceNotificationTypes.ServiceRestorationResult;
440 LOG.info("pceCancelResResource came from RPC serviceRestoration");
441 pceService = service;
442 } else if (serviceReconfigureInput != null) {
443 notif = ServiceNotificationTypes.ServiceReconfigureResult;
444 LOG.info("pceCancelResResource came from RPC serviceReconfigure");
445 String serviceName = serviceReconfigureInput.getServiceName();
446 if (serviceName != null) {
447 pceService = readServiceList(serviceName);
449 LOG.info("Parameter 'serviceName' for pceCancelResResource is null");
451 } else if (serviceCreateInput != null) {
452 notif = ServiceNotificationTypes.ServiceCreateResult;
453 LOG.info("pceCancelResResource came from RPC serviceCreate");
454 String serviceName = serviceCreateInput.getServiceName();
455 if (serviceName != null) {
456 pceService = readServiceList(serviceName);
458 LOG.info("Parameter 'serviceName' for pceCancelResResource is null");
461 if (pceService != null && notif != null) {
462 final Services cancelService = pceService;
463 final ServiceNotificationTypes type = notif;
464 mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, pceService, false);
465 FutureCallback<Boolean> pceCallback = new FutureCallback<Boolean>() {
467 ServiceRpcResultSh notification = null;
469 public void onSuccess(Boolean response) {
472 * If PCE reply is received before timer
473 * expiration with a positive result, a
474 * service is created with admin and
475 * operational status 'down'.
477 message = "PCE replied to cancel resource Request !";
479 notification = new ServiceRpcResultShBuilder()
480 .setNotificationType(type)
481 .setServiceName(cancelService.getServiceName()).setStatus(RpcStatusEx.Pending)
482 .setStatusMessage(message).build();
484 notificationPublishService.putNotification(notification);
485 } catch (InterruptedException e) {
486 LOG.info("notification offer rejected : " + e);
489 message = mappingAndSendingPCRequest.getError();
490 notification = new ServiceRpcResultShBuilder()
491 .setNotificationType(type)
492 .setServiceName("").setStatus(RpcStatusEx.Failed).setStatusMessage(message)
495 notificationPublishService.putNotification(notification);
496 } catch (InterruptedException e) {
497 LOG.info("notification offer rejected : " + e);
503 public void onFailure(Throwable arg0) {
504 message = "Cancel resource request failed !";
506 notification = new ServiceRpcResultShBuilder()
507 .setNotificationType(type)
508 .setServiceName(cancelService.getServiceName()).setStatus(RpcStatusEx.Failed)
509 .setStatusMessage(message + " : " + arg0.getMessage()).build();
511 notificationPublishService.putNotification(notification);
512 } catch (InterruptedException e) {
513 LOG.info("notification offer rejected : " + e);
518 ListenableFuture<Boolean> pce = mappingAndSendingPCRequest.cancelResourceReserve();
519 Futures.addCallback(pce, pceCallback, executor);
523 private void stubrendererDelete() {
524 LOG.info("sending RPC service delete to stubrenderer ...");
527 if (service != null) {
528 LOG.info("RPC service delete came from RPC serviceRestoration !");
529 tmp = service.getServiceName();
530 id = service.getCommonId();
531 } else if (serviceDeleteInput != null) {
532 LOG.info("RPC service delete came from ServiceDelete !");
533 tmp = serviceDeleteInput.getServiceDeleteReqInfo().getServiceName();
534 id = serviceDeleteInput.getSdncRequestHeader().getRequestId();
537 if (tmp != null && id != null) {
538 final String serviceName = tmp;
539 LOG.info("stubrendererDelete service '" + serviceName + "'");
540 mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry, id, serviceName);
541 ListenableFuture<Boolean> renderer = mappingAndSendingSIRequest.serviceDelete();
542 FutureCallback<Boolean> rendererCallback = new FutureCallback<Boolean>() {
544 ServiceRpcResultSh notification = null;
547 public void onFailure(Throwable arg0) {
548 message = "ServiceDelete Request failed : " + arg0;
549 LOG.error("ServiceDelete Request failed !");
550 notification = new ServiceRpcResultShBuilder()
551 .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
552 .setServiceName(serviceName).setStatus(RpcStatusEx.Failed)
553 .setStatusMessage(message).build();
555 notificationPublishService.putNotification(notification);
556 } catch (InterruptedException e) {
557 LOG.info("notification offer rejected : " + e);
563 public void onSuccess(Boolean response) {
565 message = "Service deleted !";
566 notification = new ServiceRpcResultShBuilder()
567 .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
568 .setServiceName(serviceName).setStatus(RpcStatusEx.Pending)
569 .setStatusMessage(message).build();
571 notificationPublishService.putNotification(notification);
572 } catch (InterruptedException e) {
573 LOG.info("notification offer rejected : " + e);
576 message = "deleting service failed !";
577 notification = new ServiceRpcResultShBuilder()
578 .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
579 .setServiceName(serviceName).setStatus(RpcStatusEx.Failed)
580 .setStatusMessage(message)
583 notificationPublishService.putNotification(notification);
584 } catch (InterruptedException e) {
585 LOG.info("notification offer rejected : " + e);
590 Futures.addCallback(renderer, rendererCallback, executor);
592 LOG.info("Parameter 'serviceName' and / or 'id' is null");
597 * send a RPC serviceImplementation
598 * to stubrenderer after
599 * receiving a stubpce notification.
601 * @param input ServiceCreate or ServiceReconfigure
603 private <T> void stubrendererImplementation(T input) {
604 ServiceRpcResultSh notification = null;
605 String serviceName = null;
607 String newServiceName = null;
608 ServiceNotificationTypes type = null;
609 Boolean create = false;
610 Boolean delete = true;
611 if (pathDescription != null) {
612 LOG.info("Pathdescription conatins in Stubpce notification received !");
613 String result = null;
614 PathComputationRequestOutput pathComputationResponse =
615 new PathComputationRequestOutputBuilder()
616 .setResponseParameters(new org.opendaylight.yang.gen.v1.http.org
617 .transportpce.b.c._interface.service.types.rev170426.response
618 .parameters.sp.ResponseParametersBuilder()
619 .setPathDescription(pathDescription)
622 if (input instanceof ServiceReconfigureInput) {
623 /** delete and write . */
624 LOG.info("RPC serviceImplementation came from RPC serviceReconfigure ...");
625 ServiceReconfigureInput tmp = (ServiceReconfigureInput)input;
626 serviceName = tmp.getServiceName();
627 newServiceName = tmp.getNewServiceName();
628 type = ServiceNotificationTypes.ServiceReconfigureResult;
630 mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry, tmp,pathComputationResponse);
631 } else if (input instanceof ServiceCreateInput) {
633 LOG.info("RPC serviceImplementation came from RPC serviceCreate ...");
634 ServiceCreateInput tmp = (ServiceCreateInput)input;
635 serviceName = tmp.getServiceName();
636 type = ServiceNotificationTypes.ServiceCreateResult;
637 mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry, tmp,pathComputationResponse);
640 } else if (input instanceof Services) {
642 LOG.info("RPC serviceImplementation came from RPC ServiceRestoration ...");
643 Services tmp = new ServicesBuilder((Services)input)
644 .setAdministrativeState(State.OutOfService)
645 .setOperationalState(State.OutOfService)
646 .setLifecycleState(LifecycleState.Planned)
648 serviceName = tmp.getServiceName();
649 type = ServiceNotificationTypes.ServiceRestorationResult;
650 mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry, tmp, pathComputationResponse);
654 final String name = serviceName;
655 final ServiceNotificationTypes notifType = type;
656 if (!create) { /** ServiceReconfigure. */
657 if ((result = writeOrModifyOrDeleteServiceList(serviceName, pathComputationResponse,null, 1)) == null) {
658 LOG.info("Service '" + serviceName + "' deleted from datastore");
659 serviceName = newServiceName;
662 LOG.info("deleting Service '" + serviceName + "' failed !");
666 if ((result = writeOrModifyOrDeleteServiceList(serviceName,pathComputationResponse,null, 2)) != null) {
667 LOG.info("writting Service failed !");
668 StringBuilder build = new StringBuilder();
669 build.append(message);
670 build.append(" " + result);
671 message = build.toString();
674 * Send Implementation order to renderer
676 notification = new ServiceRpcResultShBuilder()
677 .setNotificationType(notifType)
678 .setServiceName(name)
679 .setStatus(RpcStatusEx.Pending)
680 .setStatusMessage("Submitting ServiceImplementation Request ...")
683 notificationPublishService.putNotification(notification);
684 } catch (InterruptedException e) {
685 LOG.info("notification offer rejected : " + e);
688 FutureCallback<Boolean> rendererCallback = new FutureCallback<Boolean>() {
690 ServiceRpcResultSh notification = null;
693 public void onSuccess(Boolean response) {
696 * If stubrenderer reply is received before timer
697 * expiration with a positive result, a
698 * service is created with admin and
699 * operational status 'down'.
701 message = "StubRenderer replied to Request !";
703 notification = new ServiceRpcResultShBuilder()
704 .setNotificationType(notifType)
705 .setServiceName(name).setStatus(RpcStatusEx.Pending)
706 .setStatusMessage(message).build();
708 notificationPublishService.putNotification(notification);
709 } catch (InterruptedException e) {
710 LOG.info("notification offer rejected : " + e);
713 message = mappingAndSendingSIRequest.getError();
714 notification = new ServiceRpcResultShBuilder()
715 .setNotificationType(notifType)
716 .setServiceName(name).setStatus(RpcStatusEx.Failed).setStatusMessage(message)
719 notificationPublishService.putNotification(notification);
720 } catch (InterruptedException e) {
721 LOG.info("notification offer rejected : " + e);
727 public void onFailure(Throwable arg0) {
728 LOG.error("Service not implemented ...");
729 notification = new ServiceRpcResultShBuilder()
730 .setNotificationType(notifType)
731 .setServiceName(name).setStatus(RpcStatusEx.Failed)
732 .setStatusMessage("Service implementation failed : " + arg0.getMessage()).build();
734 notificationPublishService.putNotification(notification);
735 } catch (InterruptedException e) {
736 LOG.info("notification offer rejected : " + e);
740 ListenableFuture<Boolean> renderer = mappingAndSendingSIRequest.serviceImplementation();
741 Futures.addCallback(renderer, rendererCallback, executor);
744 LOG.info("deleting Service failed");
747 message = "PathDescription contains in Stubpce notification "
754 * Checking Service Compliancy.
756 * @return String if not compliant, null else
758 private String serviceCompliancy(SdncRequestHeader sdncRequestHeader, String serviceName,
759 ConnectionType connectionType, RpcActions rpcActions, ServiceEndpoint aend, ServiceEndpoint zend,
760 String commonIdValue, HardConstraints hard, SoftConstraints soft) {
761 String message = null;
762 Boolean contype = false;
763 Boolean sdncRequest = false;
764 Boolean commonId = true;
765 Boolean coherencyHardSoft = false;
767 if (sdncRequestHeader != null) {
770 if (connectionType != null) {
773 compliancyCheck = new ServicehandlerCompliancyCheck(sdncRequestHeader, serviceName,
774 connectionType, rpcActions);
775 if (compliancyCheck.check(contype, sdncRequest)) {
776 LOG.info("Service compliant !");
778 * If compliant, service-request parameters are verified in order to
779 * check if there is no missing parameter that prevents calculating
780 * a path and implement a service.
782 LOG.info("checking Tx/Rx Info for AEnd ...");
783 txrxCheck = new ServicehandlerTxRxCheck(aend, 1);
784 if (txrxCheck.check()) {
785 LOG.info("Tx/Rx Info for AEnd checked !");
786 LOG.info("checking Tx/Rx Info for ZEnd ...");
787 txrxCheck = new ServicehandlerTxRxCheck(zend, 2);
788 if (txrxCheck.check()) {
789 LOG.info("Tx/Rx Info for ZEnd checked");
791 * If OK, common-id is verified in order to see if there is
792 * no routing policy provided. If yes, the routing
793 * constraints of the policy are recovered and coherency
794 * with hard/soft constraints provided in the input of the
797 if (commonIdValue != null) {
798 LOG.info("Common-id specified");
800 * Check coherency with hard/soft constraints.
802 checkCoherencyHardSoft = new CheckCoherencyHardSoft(hard,soft);
803 if (checkCoherencyHardSoft.check()) {
804 LOG.info("hard/soft constraints coherent !");
805 coherencyHardSoft = true;
807 LOG.info("hard/soft constraints are not coherent !");
808 message = "hard/soft constraints are not coherent !";
813 if (!commonId || (commonId && coherencyHardSoft)) {
817 message = txrxCheck.getMessage();
820 message = txrxCheck.getMessage();
823 message = compliancyCheck.getMessage();
830 public Future<RpcResult<ServiceCreateOutput>> serviceCreate(ServiceCreateInput input) {
831 LOG.info("RPC service creation received");
832 pathDescription = null;
834 action = RpcActions.ServiceCreate;
835 notificationUrl = null;
836 LOG.info("notificationUrl : " + notificationUrl);
837 setPathDescription(null);
838 serviceCreateInput = input;
839 setServiceDeleteInput(null);
840 setServiceReconfigureInput(null);
843 String responseCode = "";
844 ConfigurationResponseCommon configurationResponseCommon;
845 LOG.info("checking Service Compliancy ...");
847 * Upon receipt of service-create RPC, service header and sdnc-request
848 * header compliancy are verified.
850 String serviceCompliancy = null;
851 if ((serviceCompliancy = serviceCompliancy(input.getSdncRequestHeader(), input.getServiceName(),
852 input.getConnectionType(), RpcActions.ServiceCreate, input.getServiceAEnd(), input.getServiceZEnd(),
853 input.getCommonId(), input.getHardConstraints(), input.getSoftConstraints())) != null) {
854 message = "Service not compliant : " + serviceCompliancy;
857 LOG.info("Service compliant !");
858 pcePathComputation(input);
859 LOG.info("PCR Request in progress ");
860 configurationResponseCommon = new ConfigurationResponseCommonBuilder()
861 .setAckFinalIndicator("No").setRequestId(input.getSdncRequestHeader().getRequestId())
862 .setResponseMessage("Service compliant, serviceCreate in progress...")
863 .setResponseCode("200").build();
865 ServiceCreateOutputBuilder output = new ServiceCreateOutputBuilder()
866 .setConfigurationResponseCommon(configurationResponseCommon);
868 return RpcResultBuilder.success(output.build()).buildFuture();
871 /*compliancyCheck = new ServicehandlerCompliancyCheck(input.getSdncRequestHeader(), input.getServiceName(),
872 input.getConnectionType(), RpcActions.ServiceCreate);
873 if (compliancyCheck.check(true, true)) {
874 LOG.info("Service compliant !");
875 LOG.info("checking Tx/Rx Info for AEnd ...");
876 txrxCheck = new ServicehandlerTxRxCheck(input.getServiceAEnd(), 1);
877 if (txrxCheck.check()) {
878 LOG.info("Tx/Rx Info for AEnd checked !");
879 LOG.info("checking Tx/Rx Info for ZEnd ...");
880 txrxCheck = new ServicehandlerTxRxCheck(input.getServiceZEnd(), 2);
881 if (txrxCheck.check()) {
882 LOG.info("Tx/Rx Info for ZEnd checked");
883 if (input.getCommonId() != null) {
884 LOG.info("Common-id specified");
885 checkCoherencyHardSoft = new CheckCoherencyHardSoft(input.getHardConstraints(),
886 input.getSoftConstraints());
887 if (checkCoherencyHardSoft.check()) {
888 LOG.info("hard/soft constraints coherent !");
889 coherencyHardSoft = true;
891 LOG.info("hard/soft constraints are not coherent !");
892 message = "hard/soft constraints are not coherent !";
893 responseCode = "500";
898 if (!commonId || (commonId && coherencyHardSoft)) {
899 pcePathComputation(input);
900 LOG.info("PCR Request in progress ");
901 configurationResponseCommon = new ConfigurationResponseCommonBuilder()
902 .setAckFinalIndicator("No").setRequestId(input.getSdncRequestHeader().getRequestId())
903 .setResponseMessage("Service compliant, serviceCreate in progress...")
904 .setResponseCode("200").build();
906 ServiceCreateOutputBuilder output = new ServiceCreateOutputBuilder()
907 .setConfigurationResponseCommon(configurationResponseCommon);
909 return RpcResultBuilder.success(output.build()).buildFuture();
912 message = txrxCheck.getMessage();
913 responseCode = "500";
916 message = txrxCheck.getMessage();
917 responseCode = "500";
920 message = compliancyCheck.getMessage();
921 responseCode = "500";
924 configurationResponseCommon = new ConfigurationResponseCommonBuilder()
925 .setAckFinalIndicator("Yes")
926 .setRequestId(input.getSdncRequestHeader().getRequestId()).setResponseMessage(message)
927 .setResponseCode(responseCode).build();
929 ServiceCreateOutputBuilder output = new ServiceCreateOutputBuilder()
930 .setConfigurationResponseCommon(configurationResponseCommon);
932 return RpcResultBuilder.success(output.build()).buildFuture();
937 public Future<RpcResult<ServiceDeleteOutput>> serviceDelete(ServiceDeleteInput input) {
938 LOG.info("RPC serviceDelete request received for Service '" + input.getServiceDeleteReqInfo().getServiceName()
940 setServiceDeleteInput(input);
941 setServiceReconfigureInput(null);
942 serviceCreateInput = null;
945 String responseCode = "";
946 LOG.info("checking Service Compliancy ...");
948 * Upon receipt of service-delete RPC, service header and sdnc-request
949 * header compliancy are verified.
951 compliancyCheck = new ServicehandlerCompliancyCheck(input.getSdncRequestHeader(),
952 input.getServiceDeleteReqInfo().getServiceName(), RpcActions.ServiceDelete);
953 if (compliancyCheck.check(false, true)) {
954 LOG.info("Service compliant !");
955 String serviceName = input.getServiceDeleteReqInfo().getServiceName();
956 Services service = readServiceList(serviceName);
957 if (service != null) {
958 LOG.debug("Service '" + serviceName + "' present in datastore !");
959 stubrendererDelete();
960 LOG.info("ServiceDelete Request in progress ... ");
961 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
962 .setAckFinalIndicator("No").setRequestId(input.getSdncRequestHeader().getRequestId())
963 .setResponseMessage("ServiceDelete Request in progress ...").setResponseCode("200").build();
964 ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
965 .setConfigurationResponseCommon(configurationResponseCommon).build();
966 return RpcResultBuilder.success(output).buildFuture();
968 message = "Service '" + serviceName + "' not exists in datastore";
973 message = "Service not compliant !";
974 responseCode = "500";
977 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
978 .setAckFinalIndicator("Yes").setRequestId(input.getSdncRequestHeader().getRequestId())
979 .setResponseMessage(message).setResponseCode(responseCode).build();
980 ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
981 .setConfigurationResponseCommon(configurationResponseCommon).build();
982 return RpcResultBuilder.success(output).buildFuture();
986 public Future<RpcResult<ServiceFeasibilityCheckOutput>> serviceFeasibilityCheck(
987 ServiceFeasibilityCheckInput input) {
988 action = RpcActions.ServiceFeasibilityCheck;
989 LOG.info("RPC service feasibilityCheck received");
990 mappingAndSendingPCRequest = null;
991 serviceFeasibilityCheckInput = input;
992 serviceCreateInput = null;
993 serviceDeleteInput = null;
995 serviceReconfigureInput = null;
997 ConfigurationResponseCommon configurationResponseCommon = null;
999 String responseCode = "";
1000 LOG.info("checking Service Compliancy ...");
1002 * Upon receipt of service-create RPC, service header and sdnc-request
1003 * header compliancy are verified.
1005 String name = "no name";
1006 String serviceCompliancy = null;
1007 if ((serviceCompliancy = serviceCompliancy(input.getSdncRequestHeader(), name, input.getConnectionType(),
1008 RpcActions.ServiceFeasibilityCheck, input.getServiceAEnd(), input.getServiceZEnd(), input.getCommonId(),
1009 input.getHardConstraints(), input.getSoftConstraints())) != null) {
1010 message = "Service not compliant : " + serviceCompliancy;
1013 LOG.info("Service compliant !");
1014 pcePathComputation(input);
1015 LOG.info("PCR Request in progress ");
1016 configurationResponseCommon = new ConfigurationResponseCommonBuilder()
1017 .setAckFinalIndicator("No").setRequestId(input.getSdncRequestHeader().getRequestId())
1018 .setResponseMessage("Service compliant, ServiceFeasibilityCheck in progress...")
1019 .setResponseCode("200").build();
1021 ServiceFeasibilityCheckOutput output = new ServiceFeasibilityCheckOutputBuilder()
1022 .setConfigurationResponseCommon(configurationResponseCommon).build();
1023 return RpcResultBuilder.success(output).buildFuture();
1025 /*compliancyCheck = new ServicehandlerCompliancyCheck(input.getSdncRequestHeader(), name,
1026 input.getConnectionType(), RpcActions.ServiceFeasibilityCheck);
1027 if (compliancyCheck.check(true, true)) {
1028 LOG.info("Service compliant !");
1029 LOG.info("checking Tx/Rx Info for AEnd ...");
1030 txrxCheck = new ServicehandlerTxRxCheck(input.getServiceAEnd(), 1);
1031 if (txrxCheck.check()) {
1032 LOG.info("Tx/Rx Info for AEnd checked !");
1033 LOG.info("checking Tx/Rx Info for ZEnd ...");
1034 txrxCheck = new ServicehandlerTxRxCheck(input.getServiceZEnd(), 2);
1035 if (txrxCheck.check()) {
1036 LOG.info("Tx/Rx Info for ZEnd checked");
1037 if (input.getCommonId() != null) {
1038 LOG.info("Common-id specified");
1039 checkCoherencyHardSoft = new CheckCoherencyHardSoft(input.getHardConstraints(),
1040 input.getSoftConstraints());
1041 if (checkCoherencyHardSoft.check()) {
1042 LOG.info("hard/soft constraints coherent !");
1043 coherencyHardSoft = true;
1045 LOG.info("hard/soft constraints are not coherent !");
1046 message = "hard/soft constraints are not coherent !";
1047 responseCode = "500";
1053 if (!commonId || (commonId && coherencyHardSoft)) {
1054 pcePathComputation(input);
1055 LOG.info("PCR Request in progress ");
1056 configurationResponseCommon = new ConfigurationResponseCommonBuilder()
1057 .setAckFinalIndicator("No").setRequestId(input.getSdncRequestHeader().getRequestId())
1058 .setResponseMessage("Service compliant, ServiceFeasibilityCheck in progress...")
1059 .setResponseCode("200").build();
1061 ServiceFeasibilityCheckOutput output = new ServiceFeasibilityCheckOutputBuilder()
1062 .setConfigurationResponseCommon(configurationResponseCommon).build();
1063 return RpcResultBuilder.success(output).buildFuture();
1066 message = txrxCheck.getMessage();
1067 responseCode = "500";
1070 message = txrxCheck.getMessage();
1071 responseCode = "500";
1074 message = compliancyCheck.getMessage();
1075 responseCode = "500";
1077 configurationResponseCommon = new ConfigurationResponseCommonBuilder().setAckFinalIndicator("Yes")
1078 .setRequestId(input.getSdncRequestHeader().getRequestId()).setResponseMessage(message)
1079 .setResponseCode(responseCode).build();
1080 ServiceFeasibilityCheckOutput output = new ServiceFeasibilityCheckOutputBuilder()
1081 .setConfigurationResponseCommon(configurationResponseCommon).build();
1083 return RpcResultBuilder.success(output).buildFuture();
1087 public Future<RpcResult<ServiceReconfigureOutput>> serviceReconfigure(ServiceReconfigureInput input) {
1088 LOG.info("RPC service reconfigure received");
1089 setServiceReconfigureInput(input);
1090 setServiceDeleteInput(null);
1091 serviceCreateInput = null;
1093 String message = "";
1094 LOG.info("checking Service Compliancy ...");
1096 * Upon receipt of service-create RPC, service header and sdnc-request
1097 * header compliancy are verified.
1099 String serviceCompliancy = null;
1100 if ((serviceCompliancy = serviceCompliancy(null, input.getServiceName(), input.getConnectionType(),
1101 RpcActions.ServiceReconfigure, input.getServiceAEnd(), input.getServiceZEnd(), input.getCommonId(),
1102 input.getHardConstraints(), input.getSoftConstraints())) != null) {
1103 message = "Service not compliant : " + serviceCompliancy;
1106 LOG.info("Service compliant !");
1108 * Retrieving initial service topology.
1110 String serviceName = input.getServiceName();
1111 Services service = readServiceList(serviceName);
1112 if (service != null) {
1113 LOG.debug("Service '" + serviceName + "' present in datastore !");
1115 * Sending cancel resource reserve request to PCE.
1117 pceCancelResResource();
1118 ServiceReconfigureOutput output = new ServiceReconfigureOutputBuilder()
1119 .setStatus(RpcStatus.Successful)
1120 .setStatusMessage("ServiceReconfigure in progress ...").build();
1121 return RpcResultBuilder.success(output).buildFuture();
1123 message = "Service '" + serviceName + "' not exists in datastore";
1127 /*compliancyCheck = new ServicehandlerCompliancyCheck(input.getServiceName(), input.getConnectionType(),
1128 RpcActions.ServiceReconfigure);
1129 if (compliancyCheck.check(true, false)) {
1130 LOG.info("Service compliant !");
1131 LOG.info("checking Tx/Rx Info for AEnd ...");
1132 txrxCheck = new ServicehandlerTxRxCheck(input.getServiceAEnd(), 1);
1133 if (txrxCheck.check()) {
1134 LOG.info("Tx/Rx Info for AEnd checked !");
1135 LOG.info("checking Tx/Rx Info for ZEnd ...");
1136 txrxCheck = new ServicehandlerTxRxCheck(input.getServiceZEnd(), 2);
1137 if (txrxCheck.check()) {
1138 LOG.info("Tx/Rx Info for ZEnd checked");
1139 if (input.getCommonId() != null) {
1140 LOG.info("Common-id specified");
1141 checkCoherencyHardSoft = new CheckCoherencyHardSoft(input.getHardConstraints(),
1142 input.getSoftConstraints());
1143 if (checkCoherencyHardSoft.check()) {
1144 LOG.info("hard/soft constraints coherent !");
1145 coherencyHardSoft = true;
1147 LOG.info("hard/soft constraints are not coherent !");
1148 message = "hard/soft constraints are not coherent !";
1154 if (!commonId || (commonId && coherencyHardSoft)) {
1155 String serviceName = input.getServiceName();
1156 Services service = readServiceList(serviceName);
1157 if (service != null) {
1158 LOG.debug("Service '" + serviceName + "' present in datastore !");
1159 pceCancelResResource();
1160 ServiceReconfigureOutput output = new ServiceReconfigureOutputBuilder()
1161 .setStatus(RpcStatusEx.Pending)
1162 .setStatusMessage("ServiceReconfigure in progress ...").build();
1163 return RpcResultBuilder.success(output).buildFuture();
1165 message = "Service '" + serviceName + "' not exists in datastore";
1170 message = txrxCheck.getMessage();
1173 message = txrxCheck.getMessage();
1176 message = compliancyCheck.getMessage();
1179 ServiceReconfigureOutput output = new ServiceReconfigureOutputBuilder().setStatus(RpcStatus.Successful)
1180 .setStatusMessage(message).build();
1181 return RpcResultBuilder.success(output).buildFuture();
1185 public Future<RpcResult<ServiceRestorationOutput>> serviceRestoration(ServiceRestorationInput input) {
1186 LOG.info("RPC service restoration received");
1187 ServiceRpcResultSh notification = null;
1188 setServiceDeleteInput(null);
1189 setServiceReconfigureInput(null);
1190 notificationUrl = null;
1191 String message = "";
1192 LOG.info("checking Service Compliancy ...");
1193 compliancyCheck = new ServicehandlerCompliancyCheck(input.getServiceName(), RpcActions.ServiceRestoration);
1194 if (compliancyCheck.check(false, false)) {
1195 LOG.info("Service compliant !");
1197 * If compliant, Getting path from service DB.
1199 String serviceName = input.getServiceName();
1200 Services service = readServiceList(serviceName);
1201 if (service != null) {
1202 this.service = service;
1203 LOG.debug("Service '" + serviceName + "' present in datastore !");
1204 notification = new ServiceRpcResultShBuilder()
1205 .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1206 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1207 .setStatusMessage("Service '" + serviceName + "' present in datastore, deleting service ...")
1210 notificationPublishService.putNotification(notification);
1211 } catch (InterruptedException e) {
1212 LOG.info("notification offer rejected : " + e);
1214 stubrendererDelete();
1215 LOG.info("PCR Request in progress ");
1216 ServiceRestorationOutput output = new ServiceRestorationOutputBuilder()
1217 .setStatus(RpcStatus.Successful)
1218 .setStatusMessage("ServiceRestoration in progress...").build();
1219 return RpcResultBuilder.success(output).buildFuture();
1221 message = "Service '" + serviceName + "' not exists in datastore";
1225 message = compliancyCheck.getMessage();
1229 ServiceRestorationOutput output = new ServiceRestorationOutputBuilder().setStatus(RpcStatus.Successful)
1230 .setStatusMessage(message).build();
1232 return RpcResultBuilder.success(output).buildFuture();
1236 public Future<RpcResult<TempServiceDeleteOutput>> tempServiceDelete(TempServiceDeleteInput input) {
1237 // TODO Auto-generated method stub
1242 public Future<RpcResult<TempServiceCreateOutput>> tempServiceCreate(TempServiceCreateInput input) {
1243 // TODO Auto-generated method stub
1248 * Initialize ServiceList Structure on Datastore.
1253 private void initializeDataTree(DataBroker db) {
1254 LOG.info("Preparing to initialize the greeting registry");
1255 WriteTransaction transaction = db.newWriteOnlyTransaction();
1256 InstanceIdentifier<ServiceList> iid = InstanceIdentifier.create(ServiceList.class);
1257 ServiceList greetingRegistry = new ServiceListBuilder().build();
1258 transaction.put(LogicalDatastoreType.OPERATIONAL, iid, greetingRegistry);
1259 Future<Void> future = transaction.submit();
1261 Futures.getChecked(future, ExecutionException.class);
1262 } catch (ExecutionException e) {
1263 LOG.error("Failed to create Service List");
1268 * Map Input (ServiceCreateInmput, ServiceReconfigureInput) and output
1269 * (PathComputationRequestOutput) to Service.
1271 * @param serviceCreateInput
1272 * ServiceCreateInput parameter
1273 * @param serviceReconfigureInput
1274 * serviceReconfigureInput parameter
1276 * PathComputationRequestOutput parameter
1278 * @return Services Service data
1280 private Services mappingServices(ServiceCreateInput serviceCreateInput,
1281 ServiceReconfigureInput serviceReconfigureInput, PathComputationRequestOutput output) {
1282 LOG.info("Mapping informations to Services");
1283 ServiceAEnd aend = null;
1284 ServiceZEnd zend = null;
1285 ServicesBuilder service = new ServicesBuilder();
1286 if (serviceCreateInput != null) {
1287 aend = new ServiceAEndBuilder(serviceCreateInput.getServiceAEnd()).build();
1288 zend = new ServiceZEndBuilder(serviceCreateInput.getServiceZEnd()).build();
1289 service.setServiceName(serviceCreateInput.getServiceName()).setAdministrativeState(State.OutOfService)
1290 .setOperationalState(State.OutOfService).setCommonId(serviceCreateInput.getCommonId())
1291 .setConnectionType(serviceCreateInput.getConnectionType())
1292 .setCustomer(serviceCreateInput.getCustomer())
1293 .setCustomerContact(serviceCreateInput.getCustomerContact())
1294 .setHardConstraints(serviceCreateInput.getHardConstraints())
1295 .setSoftConstraints(serviceCreateInput.getSoftConstraints())
1296 .setLifecycleState(LifecycleState.Planned).setServiceAEnd(aend).setServiceZEnd(zend)
1297 .setSdncRequestHeader(serviceCreateInput.getSdncRequestHeader());
1299 } else if (serviceReconfigureInput != null) {
1300 aend = new ServiceAEndBuilder(serviceReconfigureInput.getServiceAEnd()).build();
1301 zend = new ServiceZEndBuilder(serviceReconfigureInput.getServiceZEnd()).build();
1302 service.setServiceName(serviceReconfigureInput.getNewServiceName())
1303 .setAdministrativeState(State.OutOfService).setOperationalState(State.OutOfService)
1304 .setCommonId(serviceReconfigureInput.getCommonId())
1305 .setConnectionType(serviceReconfigureInput.getConnectionType())
1306 .setCustomer(serviceReconfigureInput.getCustomer())
1307 .setCustomerContact(serviceReconfigureInput.getCustomerContact())
1308 .setHardConstraints(serviceReconfigureInput.getHardConstraints())
1309 .setSoftConstraints(serviceReconfigureInput.getSoftConstraints())
1310 .setLifecycleState(LifecycleState.Planned).setServiceAEnd(aend).setServiceZEnd(zend);
1313 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.response
1314 .parameters.sp.ResponseParameters responseParameters = output.getResponseParameters();
1315 if (responseParameters != null) {
1316 // service.setPceMetric(responseParameters.getPceMetric());
1317 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426
1318 .response.parameters.sp.response.parameters.PathDescription pathDescription =
1319 responseParameters.getPathDescription();
1320 if (pathDescription != null) {
1321 List<AToZ> atozList = new ArrayList<AToZ>();
1322 List<ZToA> ztoaList = new ArrayList<ZToA>();
1324 for (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426
1325 .path.description.atoz.direction.AToZ
1326 tmp : pathDescription.getAToZDirection().getAToZ()) {
1328 AToZKey key = new AToZKey(tmp.getKey().getId());
1329 AToZ atoz = new AToZBuilder().setId(tmp.getId()).setKey(key)
1330 // .setResource(tmp.getResource())
1335 for (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426
1336 .path.description.ztoa.direction.ZToA
1337 tmp : pathDescription.getZToADirection().getZToA()) {
1338 ZToAKey key = new ZToAKey(tmp.getKey().getId());
1339 ZToA ztoa = new ZToABuilder().setId(tmp.getId()).setKey(key)
1340 // .setResource(tmp.getResource())
1345 Topology topology = new TopologyBuilder().setAToZ(atozList).setZToA(ztoaList).build();
1346 service.setTopology(topology);
1349 return service.build();
1353 * read Service from ServiceList DataStore.
1355 * @param serviceName
1358 * @return <code>Services</code>
1360 private Services readServiceList(String serviceName) {
1361 Services result = null;
1362 ReadOnlyTransaction readTx = db.newReadOnlyTransaction();
1363 InstanceIdentifier<Services> iid = InstanceIdentifier.create(ServiceList.class).child(Services.class,
1364 new ServicesKey(serviceName));
1365 Future<Optional<Services>> future = readTx.read(LogicalDatastoreType.OPERATIONAL,iid);
1366 Optional<Services> optional = Optional.absent();
1368 optional = Futures.getChecked(future, ExecutionException.class);
1369 } catch (ExecutionException e) {
1370 LOG.error("Reading service failed:", e);
1372 if (optional.isPresent()) {
1373 LOG.debug("Service '" + serviceName + "' present !");
1374 result = new ServicesBuilder(optional.get()).build();
1380 * Write or Modify or Delete Service from/to ServiceList.
1382 * @param serviceName
1385 * PathComputationRequestOutput
1389 * 0 - Modify 1 - Delete 2 - Write
1390 * @return String operations result, null if ok or not otherwise
1392 private String writeOrModifyOrDeleteServiceList(String serviceName, PathComputationRequestOutput output,
1393 Topology topo, int choice) {
1394 LOG.info("WriteOrModifyOrDeleting '" + serviceName + "' Service");
1395 WriteTransaction writeTx = db.newWriteOnlyTransaction();
1396 String result = null;
1397 Services readService = readServiceList(serviceName);
1398 Future<Void> future = null;
1399 if (readService != null) {
1401 * Modify / Delete Service.
1403 InstanceIdentifier<Services> iid = InstanceIdentifier.create(ServiceList.class).child(Services.class,
1404 new ServicesKey(serviceName));
1405 ServicesBuilder service = new ServicesBuilder(readService);
1407 String action = null;
1409 case 0: /** Modify. */
1410 LOG.info("Modifying '" + serviceName + "' Service");
1411 service.setOperationalState(State.InService).setAdministrativeState(State.InService);
1412 service.setTopology(topo);
1413 writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, service.build());
1417 case 1: /** Delete. */
1418 LOG.info("Deleting '" + serviceName + "' Service");
1419 writeTx.delete(LogicalDatastoreType.OPERATIONAL, iid);
1424 LOG.info("No choice found");
1427 future = writeTx.submit();
1429 Futures.getChecked(future, ExecutionException.class);
1430 } catch (ExecutionException e) {
1431 LOG.info("Failed to " + action + " service from Service List");
1432 result = "Failed to " + action + " service from Service List";
1434 } else if (choice == 2) { /** Write Service. */
1435 LOG.info("Writing '" + serviceName + "' Service");
1436 InstanceIdentifier<Services> iid = InstanceIdentifier.create(ServiceList.class).child(Services.class,
1437 new ServicesKey(serviceName));
1438 Services writeService = null;
1439 if (this.service != null) {
1440 writeService = service;
1442 writeService = mappingServices(serviceCreateInput, serviceReconfigureInput, output);
1444 writeTx.put(LogicalDatastoreType.OPERATIONAL, iid, writeService);
1445 future = writeTx.submit();
1447 Futures.getChecked(future, ExecutionException.class);
1449 } catch (ExecutionException e) {
1450 LOG.error("Failed to write service to Service List");
1451 result = "Failed to write service to Service List";
1454 LOG.info("Service is not present in datastore ! ");
1455 result = "Service is not present in datastore ! ";
1461 public void close() throws Exception {
1462 executor.shutdown();
1466 public Future<RpcResult<EquipmentNotificationOutput>> equipmentNotification(EquipmentNotificationInput input) {
1467 // TODO Auto-generated method stub
1472 public Future<RpcResult<ServiceRerouteConfirmOutput>> serviceRerouteConfirm(ServiceRerouteConfirmInput input) {
1473 // TODO Auto-generated method stub
1478 public Future<RpcResult<ServiceRerouteOutput>> serviceReroute(ServiceRerouteInput input) {
1479 // TODO Auto-generated method stub
1484 public Future<RpcResult<ServiceReversionOutput>> serviceReversion(ServiceReversionInput input) {
1485 // TODO Auto-generated method stub
1490 public Future<RpcResult<ServiceRollOutput>> serviceRoll(ServiceRollInput input) {
1491 // TODO Auto-generated method stub
1496 public Future<RpcResult<NetworkReOptimizationOutput>> networkReOptimization(NetworkReOptimizationInput input) {
1497 // TODO Auto-generated method stub
1502 public void onServiceRpcResultSp(ServiceRpcResultSp notification) {
1503 if (notification != null && !compareServiceRpcResultSp(notification)) {
1504 serviceRpcResultSp = notification;
1505 StringBuilder build = new StringBuilder();
1507 "Received '" + notification.getNotificationType() + "' StubRenderer notification" + "from service '"
1508 + notification.getServiceName() + "' " + "with status '" + notification.getStatus() + "'");
1509 build.append(" with StatusMessage '" + notification.getStatusMessage() + "'");
1510 LOG.info(build.toString());
1511 switch (serviceRpcResultSp.getNotificationType().getIntValue()) {
1512 case 3 : /** service-implementation-request. */
1513 if (serviceRpcResultSp.getStatus() == RpcStatusEx.Successful) {
1514 if (serviceRpcResultSp.getPathTopology() != null) {
1515 pathTopology = new PathTopologyBuilder()
1516 .setAToZ(serviceRpcResultSp.getPathTopology().getAToZ())
1517 .setZToA(serviceRpcResultSp.getPathTopology().getZToA())
1519 LOG.info("PathTopology gets !");
1521 LOG.info("'serviceRpcResultSp.getPathTopology()' parameter is null ");
1523 if (serviceCreateInput != null) {
1524 updateServiceStatus(serviceCreateInput);
1525 } else if (serviceReconfigureInput != null) {
1526 updateServiceStatus(serviceReconfigureInput);
1527 } else if (service != null) {
1528 updateServiceStatus(service);
1530 } else if (serviceRpcResultSp.getStatus() == RpcStatusEx.Failed) {
1531 LOG.info("Stubrenderer computation failed !");
1532 pceCancelResResource();
1536 case 4 : /** service-delete. */
1537 if (serviceRpcResultSp.getStatus() == RpcStatusEx.Successful) {
1538 if (service != null) { //serviceRestoration
1539 LOG.info("RPC service delete came from serviceRestoration");
1540 pcePathComputation(service);
1542 pceCancelResResource();
1544 } else if (serviceRpcResultSp.getStatus() == RpcStatusEx.Failed) {
1545 LOG.info("Stubrenderer computation failed !");
1553 LOG.info("ServiceRpcResultSp already wired !");
1558 public void onServicePathRpcResult(ServicePathRpcResult notification) {
1559 if (notification != null && !compareServicePathRpcResult(notification)) {
1560 servicePathRpcResult = notification;
1561 StringBuilder build = new StringBuilder();
1563 "Received '" + notification.getNotificationType() + "' Stubpce notification" + "from service '"
1564 + notification.getServiceName() + "' " + "with status '" + notification.getStatus() + "'");
1565 build.append(" with StatusMessage '" + notification.getStatusMessage() + "'");
1566 LOG.info(build.toString());
1567 switch (servicePathRpcResult.getNotificationType().getIntValue()) {
1568 case 1 : /** path-computation-request. */
1569 if (servicePathRpcResult.getStatus() == RpcStatusEx.Successful) {
1570 if (servicePathRpcResult.getPathDescription() != null) {
1571 pathDescription = new PathDescriptionBuilder()
1572 .setAToZDirection(servicePathRpcResult.getPathDescription().getAToZDirection())
1573 .setZToADirection(servicePathRpcResult.getPathDescription().getZToADirection())
1575 LOG.info("PathDescription gets !");
1576 if (serviceReconfigureInput != null) {
1577 stubrendererImplementation(serviceReconfigureInput);
1578 } else if (serviceCreateInput != null) {
1579 stubrendererImplementation(serviceCreateInput);
1580 } else if (service != null) {
1581 stubrendererImplementation(service);
1584 LOG.info("'servicePathRpcResult.getPathDescription()'parameter is null ");
1586 } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
1587 LOG.info("Stupce computation failed !");
1591 case 2 : /** cancel-resource-reserve. */
1592 if (servicePathRpcResult.getStatus() == RpcStatusEx.Successful) {
1593 /**if it was an RPC serviceReconfigure, relaunch
1594 * PCR else delete the service.
1596 if (serviceReconfigureInput != null) {
1597 LOG.info("cancel reserve resource request came from RPC serviceReconfigure !");
1598 pcePathComputation(serviceReconfigureInput);
1600 deleteServiceFromDatastore();
1602 } else if (servicePathRpcResult.getStatus() == RpcStatusEx.Failed) {
1603 LOG.info("Stupce computation failed !");
1611 LOG.info("ServicePathRpcResult already wired !");
1615 public RpcActions getAction() {
1619 public void setAction(RpcActions action) {
1620 this.action = action;
1624 * Compare ServicePathRpcResult.
1626 * @param notification ServicePathRpcResult
1627 * @return <code>Boolean</code> true if idem, false else
1629 public Boolean compareServicePathRpcResult(ServicePathRpcResult notification) {
1630 Boolean result = true;
1631 if (servicePathRpcResult == null) {
1634 if (servicePathRpcResult.getNotificationType() != notification.getNotificationType()) {
1637 if (servicePathRpcResult.getServiceName() != notification.getServiceName()) {
1640 if (servicePathRpcResult.getStatus() != notification.getStatus()) {
1643 if (servicePathRpcResult.getStatusMessage() != notification.getStatusMessage()) {
1651 * Compare ServiceRpcResultSp.
1653 * @param notification ServiceRpcResultSp
1654 * @return <code>Boolean</code> true if idem, false else
1656 public Boolean compareServiceRpcResultSp(ServiceRpcResultSp notification) {
1657 Boolean result = true;
1658 if (serviceRpcResultSp == null) {
1661 if (serviceRpcResultSp.getNotificationType() != notification.getNotificationType()) {
1664 if (serviceRpcResultSp.getServiceName() != notification.getServiceName()) {
1667 if (serviceRpcResultSp.getStatus() != notification.getStatus()) {
1670 if (serviceRpcResultSp.getStatusMessage() != notification.getStatusMessage()) {
1677 public PathDescription getPathDescription() {
1678 return pathDescription;
1681 public void setPathDescription(PathDescription pathDescription) {
1682 this.pathDescription = pathDescription;
1685 public ServiceDeleteInput getServiceDeleteInput() {
1686 return serviceDeleteInput;
1689 public void setServiceDeleteInput(ServiceDeleteInput serviceDeleteInput) {
1690 this.serviceDeleteInput = serviceDeleteInput;
1693 public ServiceReconfigureInput getServiceReconfigureInput() {
1694 return serviceReconfigureInput;
1697 public void setServiceReconfigureInput(ServiceReconfigureInput serviceReconfigureInput) {
1698 this.serviceReconfigureInput = serviceReconfigureInput;
1701 public ServiceFeasibilityCheckInput getServiceFeasibilityCheckInput() {
1702 return serviceFeasibilityCheckInput;
1705 public void setServiceFeasibilityCheckInput(ServiceFeasibilityCheckInput serviceFeasibilityCheckInput) {
1706 this.serviceFeasibilityCheckInput = serviceFeasibilityCheckInput;