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.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;
22 import java.io.DataOutputStream;
23 import java.io.IOException;
24 import java.net.HttpURLConnection;
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;
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;
134 * Class to implement ServicehandlerService and ServicehandlerListener.
136 * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
139 public class ServicehandlerImpl implements ServicehandlerService, StubpceListener, StubrendererListener, AutoCloseable {
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;
151 * Map and Send PCE requests : -
152 * path-computation-request/cancel-resource-reserve.
154 private MappingAndSendingPCRequest mappingAndSendingPCRequest;
156 * Map and Send Service Implemention requests : - service
157 * implementation/service delete.
159 private MappingAndSendingSIRequest mappingAndSendingSIRequest;
161 private RpcProviderRegistry rpcRegistry;
162 private NotificationPublishService notificationPublishService;
163 private final ListeningExecutorService executor;
165 private ServicePathRpcResult servicePathRpcResult = null;
166 private ServiceRpcResultSp serviceRpcResultSp = null;
168 private String notificationUrl = "";
169 private RpcActions action;
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);
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);
190 ResponseParametersBuilder responseParameters = new ResponseParametersBuilder();
191 ConfigurationResponseCommon configurationResponseCommon;
193 String responseCode = "";
195 LOG.info("checking Service Compliancy ...");
197 * Upon receipt of service
198 * -create RPC, service header and sdnc
199 * -request header compliancy are verified.
201 compliancyCheck = new ServicehandlerCompliancyCheck(input.getSdncRequestHeader(), input.getServiceName(),
202 input.getConnectionType(), RpcActions.ServiceCreate);
203 if (compliancyCheck.check(true, true)) {
204 LOG.info("Service compliant !");
206 * If compliant, service-request parameters are verified in order to
207 * check if there is no missing parameter that prevents calculating
208 * a path and implement a service.
210 LOG.info("checking Tx/Rx Info for AEnd ...");
211 txrxCheck = new ServicehandlerTxRxCheck(input.getServiceAEnd(), 1);
212 if (txrxCheck.check()) {
213 LOG.info("Tx/Rx Info for AEnd checked !");
214 LOG.info("checking Tx/Rx Info for ZEnd ...");
215 txrxCheck = new ServicehandlerTxRxCheck(input.getServiceZEnd(), 2);
216 if (txrxCheck.check()) {
217 LOG.info("Tx/Rx Info for ZEnd checked");
219 * If OK, common-id is verified in order to see if there is
220 * no routing policy provided. If yes, the routing
221 * constraints of the policy are recovered and coherency
222 * with hard/soft constraints provided in the input of the
225 if (input.getCommonId() != null) {
226 LOG.info("Common-id specified");
228 * Check coherency with hard/soft constraints
231 checkCoherencyHardSoft = new CheckCoherencyHardSoft(input.getHardConstraints(),
232 input.getSoftConstraints());
233 if (checkCoherencyHardSoft.check()) {
234 LOG.info("hard/soft constraints coherent !");
235 coherencyHardSoft = true;
237 LOG.info("hard/soft constraints are not coherent !");
238 message = "hard/soft constraints are not coherent !";
239 responseCode = "500";
245 if (!commonId || (commonId && coherencyHardSoft)) {
247 * Before sending the PCE request, input data need to be
248 * formatted according to the Service Handler PCE
249 * interface data model.
251 mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, input, true);
253 * Once PCE request is being sent to the PCE on
254 * interface B, PCE reply is expected until a timer
257 notification = new ServiceRpcResultBuilder()
258 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
259 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
260 .setStatusMessage("Service compliant, submitting PathComputation Request ...").build();
262 notificationPublishService.putNotification(notification);
263 } catch (InterruptedException e) {
264 LOG.info("notification offer rejected : " + e);
266 sendNotifToUrl(notification, notificationUrl);
267 FutureCallback<PathComputationRequestOutput> pceCallback =
268 new FutureCallback<PathComputationRequestOutput>() {
270 String responseCode = "";
271 ServiceRpcResult notification = null;
274 public void onSuccess(PathComputationRequestOutput response) {
275 if (mappingAndSendingPCRequest.getSuccess() && response != null) {
277 * If PCE reply is received before timer
278 * expiration with a positive result, a
279 * service is created with admin and
280 * operational status 'down'.
282 LOG.info("PCE replied to PCR Request !");
284 message = response.getConfigurationResponseCommon().getResponseMessage();
285 notification = new ServiceRpcResultBuilder()
286 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
287 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
288 .setStatusMessage("PCE replied to PCR Request !").build();
290 notificationPublishService.putNotification(notification);
291 } catch (InterruptedException e) {
292 LOG.info("notification offer rejected : " + e);
294 sendNotifToUrl(notification, notificationUrl);
295 String result = null;
296 if ((result = writeOrModifyOrDeleteServiceList(input.getServiceName(), input,
297 response, 2)) != null) {
298 StringBuilder build = new StringBuilder();
299 build.append(message);
300 build.append(" " + result);
301 message = build.toString();
304 * Send Implementation order to renderer
306 mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry, input,
309 notification = new ServiceRpcResultBuilder()
310 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
311 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
312 .setStatusMessage("Submitting ServiceImplementation Request ...")
315 notificationPublishService.putNotification(notification);
316 } catch (InterruptedException e) {
317 LOG.info("notification offer rejected : " + e);
319 sendNotifToUrl(notification, notificationUrl);
322 * Once PCE request is being sent to the
323 * PCE on interface B, PCE reply is
324 * expected until a timer expires.
326 ServiceImplementationRequestOutput siOutput = null;
328 siOutput = mappingAndSendingSIRequest.serviceImplementation().get();
329 } catch (InterruptedException | ExecutionException e2) {
330 LOG.error("mappingAndSendingSIRequest.serviceImplementation().get() : "
333 if (siOutput == null) {
334 LOG.info("siOutput is null ");
335 LOG.info("Success : " + mappingAndSendingPCRequest.getSuccess());
337 if (mappingAndSendingSIRequest.getSuccess() && siOutput != null) {
338 ConfigurationResponseCommon siCommon = siOutput
339 .getConfigurationResponseCommon();
341 // siCommon.getResponseMessage();
342 responseCode = siCommon.getResponseCode();
343 message = "Service implemented !";
345 notification = new ServiceRpcResultBuilder()
346 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
347 .setServiceName(input.getServiceName())
348 .setStatus(RpcStatusEx.Successful).setStatusMessage(message)
351 notificationPublishService.putNotification(notification);
352 } catch (InterruptedException e) {
353 LOG.info("notification offer rejected : " + e);
355 sendNotifToUrl(notification, notificationUrl);
357 * Service implemented setting
358 * Service op status to up
360 if (writeOrModifyOrDeleteServiceList(input.getServiceName(), null, null,
365 StringBuilder build = new StringBuilder();
366 build.append(message);
367 build.append(" : Service Op Status changed to Up !");
368 message = build.toString();
370 StringBuilder build = new StringBuilder();
371 build.append(message);
372 build.append(" but Failed to modify service from Service List !");
373 message = build.toString();
375 notification = new ServiceRpcResultBuilder()
376 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
377 .setServiceName(input.getServiceName())
378 .setStatus(RpcStatusEx.Successful).setStatusMessage(message)
381 notificationPublishService.putNotification(notification);
382 } catch (InterruptedException e) {
383 LOG.info("notification offer rejected : " + e);
385 sendNotifToUrl(notification, notificationUrl);
387 LOG.info("Service not implemented !");
388 message = response.getConfigurationResponseCommon().getResponseMessage();
389 notification = new ServiceRpcResultBuilder()
390 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
391 .setServiceName(input.getServiceName())
392 .setStatus(RpcStatusEx.Failed)
394 "Service not implemented, cancelling ResourceResv ...")
397 notificationPublishService.putNotification(notification);
398 } catch (InterruptedException e) {
399 LOG.info("notification offer rejected : " + e);
401 sendNotifToUrl(notification, notificationUrl);
402 mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry,
405 * Send Cancel resource Request to
408 CancelResourceReserveOutput cancelOuptut = null;
410 cancelOuptut = mappingAndSendingPCRequest.cancelResourceReserve().get();
411 } catch (InterruptedException | ExecutionException e1) {
412 LOG.error(e1.getMessage());
414 if (mappingAndSendingPCRequest.getSuccess() && cancelOuptut != null) {
415 LOG.info("Service ResourceResv cancelled !");
416 message = response.getConfigurationResponseCommon()
417 .getResponseMessage();
418 notification = new ServiceRpcResultBuilder()
419 .setNotificationType(
420 ServiceNotificationTypes.ServiceCreateResult)
421 .setServiceName(input.getServiceName())
422 .setStatus(RpcStatusEx.Failed)
423 .setStatusMessage("Service ResourceResv cancelled").build();
425 notificationPublishService.putNotification(notification);
426 } catch (InterruptedException e) {
427 LOG.info("notification offer rejected : " + e);
429 sendNotifToUrl(notification, notificationUrl);
431 message = cancelOuptut.getConfigurationResponseCommon()
432 .getResponseMessage();
433 responseCode = cancelOuptut.getConfigurationResponseCommon()
436 StringBuilder build = new StringBuilder();
437 build.append("Service not implemented - ");
438 build.append(message);
439 message = build.toString();
441 LOG.info("PCE replied to CancelResourceResv Request !");
443 message = "Cancelling Resource reserved failed ";
445 responseCode = "500";
446 StringBuilder build = new StringBuilder();
447 build.append("Service not implemented - ");
448 build.append(message);
449 message = build.toString();
451 message = response.getConfigurationResponseCommon()
452 .getResponseMessage();
453 notification = new ServiceRpcResultBuilder()
454 .setNotificationType(
455 ServiceNotificationTypes.ServiceCreateResult)
456 .setServiceName(input.getServiceName())
457 .setStatus(RpcStatusEx.Failed)
458 .setStatusMessage("Cancelling Resource reserved failed")
461 notificationPublishService.putNotification(notification);
462 } catch (InterruptedException e) {
463 LOG.info("notification offer rejected : " + e);
465 sendNotifToUrl(notification, notificationUrl);
471 message = mappingAndSendingPCRequest.getError();// "Path
474 responseCode = "500";
475 notification = new ServiceRpcResultBuilder()
476 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
477 .setServiceName("").setStatus(RpcStatusEx.Failed).setStatusMessage(message)
480 notificationPublishService.putNotification(notification);
481 } catch (InterruptedException e) {
482 LOG.info("notification offer rejected : " + e);
484 sendNotifToUrl(notification, notificationUrl);
490 public void onFailure(Throwable arg0) {
491 LOG.error("Path not calculated..");
492 notification = new ServiceRpcResultBuilder()
493 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
494 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
495 .setStatusMessage("PCR Request failed : " + arg0.getMessage()).build();
497 notificationPublishService.putNotification(notification);
498 } catch (InterruptedException e) {
499 LOG.info("notification offer rejected : " + e);
501 sendNotifToUrl(notification, notificationUrl);
504 ListenableFuture<PathComputationRequestOutput> pce = mappingAndSendingPCRequest
505 .pathComputationRequest();
506 Futures.addCallback(pce, pceCallback);
507 LOG.info("PCR Request in progress ");
508 configurationResponseCommon = new ConfigurationResponseCommonBuilder()
509 .setAckFinalIndicator("No").setRequestId(input.getSdncRequestHeader().getRequestId())
510 .setResponseMessage("Service compliant, serviceCreate in progress...")
511 .setResponseCode("200").build();
513 ServiceCreateOutputBuilder output = new ServiceCreateOutputBuilder()
514 .setConfigurationResponseCommon(configurationResponseCommon)
515 .setResponseParameters(responseParameters.build());
517 return RpcResultBuilder.success(output.build()).buildFuture();
520 message = txrxCheck.getMessage();
521 responseCode = "500";
524 message = txrxCheck.getMessage();
525 responseCode = "500";
528 message = compliancyCheck.getMessage();
529 responseCode = "500";
532 configurationResponseCommon = new ConfigurationResponseCommonBuilder().setAckFinalIndicator("Yes")
533 .setRequestId(input.getSdncRequestHeader().getRequestId()).setResponseMessage(message)
534 .setResponseCode(responseCode).build();
536 ServiceCreateOutputBuilder output = new ServiceCreateOutputBuilder()
537 .setConfigurationResponseCommon(configurationResponseCommon)
538 .setResponseParameters(responseParameters.build());
540 return RpcResultBuilder.success(output.build()).buildFuture();
545 public Future<RpcResult<ServiceDeleteOutput>> serviceDelete(ServiceDeleteInput input) {
546 LOG.info("RPC serviceDelete request received for Service '" + input.getServiceDeleteReqInfo().getServiceName()
548 notificationUrl = null;// input.getSdncRequestHeader().getnotificationUrl();
550 String responseCode = "";
551 ServiceRpcResult notification = null;
552 ResponseParametersBuilder responseParameters = new ResponseParametersBuilder();
553 LOG.info("checking Service Compliancy ...");
555 * Upon receipt of service-delete RPC, service header and sdnc-request
556 * header compliancy are verified.
558 compliancyCheck = new ServicehandlerCompliancyCheck(input.getSdncRequestHeader(),
559 input.getServiceDeleteReqInfo().getServiceName(), RpcActions.ServiceDelete);
560 if (compliancyCheck.check(false, true)) {
561 LOG.info("Service compliant !");
562 String serviceName = input.getServiceDeleteReqInfo().getServiceName();
563 Services service = readServiceList(serviceName);
564 if (service != null) {
565 LOG.debug("Service '" + serviceName + "' present in datastore !");
567 * If compliant, service-delete order is send to renderer.
569 mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry,
570 input.getSdncRequestHeader().getRequestId(), input.getServiceDeleteReqInfo().getServiceName());
572 notification = new ServiceRpcResultBuilder()
573 .setNotificationType(ServiceNotificationTypes.ServiceDeleteResult).setServiceName(serviceName)
574 .setStatus(RpcStatusEx.Pending)
575 .setStatusMessage("Service compliant, submitting serviceDelete Request ...").build();
577 notificationPublishService.putNotification(notification);
578 } catch (InterruptedException e) {
579 LOG.info("notification offer rejected : " + e);
581 sendNotifToUrl(notification, notificationUrl);
582 FutureCallback<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce
583 .stubrenderer.rev170426.ServiceDeleteOutput> rendererCallback =
584 new FutureCallback<org.opendaylight.yang.gen.v1.http.org.opendaylight
585 .transportpce.stubrenderer.rev170426.ServiceDeleteOutput>() {
587 String responseCode = "";
588 ServiceRpcResult notification = null;
591 public void onFailure(Throwable arg0) {
592 LOG.error("ServiceDelete Request failed !");
593 notification = new ServiceRpcResultBuilder()
594 .setNotificationType(ServiceNotificationTypes.ServiceDeleteResult)
595 .setServiceName(serviceName).setStatus(RpcStatusEx.Failed)
596 .setStatusMessage("ServiceDelete Request failed !").build();
598 notificationPublishService.putNotification(notification);
599 } catch (InterruptedException e) {
600 LOG.info("notification offer rejected : " + e);
602 sendNotifToUrl(notification, notificationUrl);
606 public void onSuccess(org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce
607 .stubrenderer.rev170426.ServiceDeleteOutput arg0) {
609 if (mappingAndSendingPCRequest.getSuccess() && arg0 != null) {
610 message = "Service deleted !";
612 notification = new ServiceRpcResultBuilder()
613 .setNotificationType(ServiceNotificationTypes.ServiceDeleteResult)
614 .setServiceName(input.getServiceDeleteReqInfo().getServiceName())
615 .setStatus(RpcStatusEx.Successful).setStatusMessage("Service deleted !").build();
617 notificationPublishService.putNotification(notification);
618 } catch (InterruptedException e) {
619 LOG.info("notification offer rejected : " + e);
621 sendNotifToUrl(notification, notificationUrl);
624 // result.getConfigurationResponseCommon().getResponseMessage();
625 responseCode = arg0.getConfigurationResponseCommon().getResponseCode();
627 * Service delete confirmed deleting service from
630 if (writeOrModifyOrDeleteServiceList(input.getServiceDeleteReqInfo().getServiceName(), null,
632 /* Service delete. */
633 StringBuilder build = new StringBuilder();
634 build.append(message);
635 build.append(" : Service deleted from database");
636 message = build.toString();
638 StringBuilder build = new StringBuilder();
639 build.append(message);
640 build.append(" but Failed to delete service from database !");
641 message = build.toString();
644 notification = new ServiceRpcResultBuilder()
645 .setNotificationType(ServiceNotificationTypes.ServiceDeleteResult)
646 .setServiceName(input.getServiceDeleteReqInfo().getServiceName())
647 .setStatus(RpcStatusEx.Successful).setStatusMessage(message).build();
649 notificationPublishService.putNotification(notification);
650 } catch (InterruptedException e) {
651 LOG.info("notification offer rejected : " + e);
653 sendNotifToUrl(notification, notificationUrl);
655 message = "deleting service failed";
656 responseCode = "500";
657 notification = new ServiceRpcResultBuilder()
658 .setNotificationType(ServiceNotificationTypes.ServiceDeleteResult)
659 .setServiceName(input.getServiceDeleteReqInfo().getServiceName())
660 .setStatus(RpcStatusEx.Failed).setStatusMessage(message).build();
662 notificationPublishService.putNotification(notification);
663 } catch (InterruptedException e) {
664 LOG.info("notification offer rejected : " + e);
666 sendNotifToUrl(notification, notificationUrl);
670 ListenableFuture<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce
671 .stubrenderer.rev170426.ServiceDeleteOutput> renderer =
672 mappingAndSendingSIRequest.serviceDelete();
673 Futures.addCallback(renderer, rendererCallback);
674 LOG.info("ServiceDelete Request in progress ... ");
675 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
676 .setAckFinalIndicator("No").setRequestId(input.getSdncRequestHeader().getRequestId())
677 .setResponseMessage("ServiceDelete Request in progress ...").setResponseCode("200").build();
678 ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
679 .setConfigurationResponseCommon(configurationResponseCommon).build();
680 return RpcResultBuilder.success(output).buildFuture();
682 message = "Service '" + serviceName + "' not exists in datastore";
687 message = "Service not compliant !";
688 responseCode = "500";
692 * Building output response.
695 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
696 .setAckFinalIndicator("Yes").setRequestId(input.getSdncRequestHeader().getRequestId())
697 .setResponseMessage(message).setResponseCode(responseCode).build();
698 ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
699 .setConfigurationResponseCommon(configurationResponseCommon).build();
700 return RpcResultBuilder.success(output).buildFuture();
704 public Future<RpcResult<ServiceFeasibilityCheckOutput>> serviceFeasibilityCheck(
705 ServiceFeasibilityCheckInput input) {
706 notificationUrl = null;// input.getSdncRequestHeader().getnotificationUrl();
707 action = RpcActions.ServiceFeasibilityCheck;
708 LOG.info("RPC service feasibilityCheck received");
709 boolean commonId = true;
710 boolean coherencyHardSoft = false;
711 ServiceRpcResult notification = null;
712 String name = "no name";
713 mappingAndSendingPCRequest = null;
715 ConfigurationResponseCommon configurationResponseCommon = null;
717 String responseCode = "";
718 LOG.info("checking Service Compliancy ...");
720 * Upon receipt of service-create RPC, service header and sdnc-request
721 * header compliancy are verified.
723 compliancyCheck = new ServicehandlerCompliancyCheck(input.getSdncRequestHeader(), name,
724 input.getConnectionType(), RpcActions.ServiceFeasibilityCheck);
725 if (compliancyCheck.check(true, true)) {
726 LOG.info("Service compliant !");
728 * If compliant, service-request parameters are verified in order to
729 * check if there is no missing parameter that prevents calculating
730 * a path and implement a service.
732 LOG.info("checking Tx/Rx Info for AEnd ...");
733 txrxCheck = new ServicehandlerTxRxCheck(input.getServiceAEnd(), 1);
734 if (txrxCheck.check()) {
735 LOG.info("Tx/Rx Info for AEnd checked !");
736 LOG.info("checking Tx/Rx Info for ZEnd ...");
737 txrxCheck = new ServicehandlerTxRxCheck(input.getServiceZEnd(), 2);
738 if (txrxCheck.check()) {
739 LOG.info("Tx/Rx Info for ZEnd checked");
741 * If OK, common-id is verified in order to see if there is
742 * no routing policy provided. If yes, the routing
743 * constraints of the policy are recovered and coherency
744 * with hard/soft constraints provided in the input of the
747 if (input.getCommonId() != null) {
748 LOG.info("Common-id specified");
750 * Check coherency with hard/soft constraints
753 checkCoherencyHardSoft = new CheckCoherencyHardSoft(input.getHardConstraints(),
754 input.getSoftConstraints());
755 if (checkCoherencyHardSoft.check()) {
756 LOG.info("hard/soft constraints coherent !");
757 coherencyHardSoft = true;
759 LOG.info("hard/soft constraints are not coherent !");
760 message = "hard/soft constraints are not coherent !";
761 responseCode = "500";
767 if (!commonId || (commonId && coherencyHardSoft)) {
769 * Before sending the PCE request, input data need to be
770 * formatted according to the Service Handler - PCE
771 * interface data model.
773 mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, input, false);
775 * Once PCE request is being sent to the PCE on
776 * interface B, PCE reply is expected until a timer
779 notification = new ServiceRpcResultBuilder()
780 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult).setServiceName(name)
781 .setStatus(RpcStatusEx.Pending)
782 .setStatusMessage("Service compliant, Submitting PathComputation Request ...").build();
784 notificationPublishService.putNotification(notification);
785 } catch (InterruptedException e) {
786 LOG.info("notification offer rejected : " + e);
788 sendNotifToUrl(notification, notificationUrl);
790 FutureCallback<PathComputationRequestOutput> pceCallback =
791 new FutureCallback<PathComputationRequestOutput>() {
793 String responseCode = "";
794 ServiceRpcResult notification = null;
797 public void onFailure(Throwable arg0) {
798 LOG.error("Path not calculated..");
799 notification = new ServiceRpcResultBuilder()
800 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
801 .setServiceName(name).setStatus(RpcStatusEx.Failed)
802 .setStatusMessage("PCR Request failed !").build();
804 notificationPublishService.putNotification(notification);
805 } catch (InterruptedException e) {
806 LOG.info("notification offer rejected : " + e);
808 sendNotifToUrl(notification, notificationUrl);
813 public void onSuccess(PathComputationRequestOutput response) {
815 if (mappingAndSendingPCRequest.getSuccess() && response != null) {
817 * If PCE reply is received before timer
818 * expiration with a positive result, a
819 * service is created with admin and
820 * operational status 'down'.
822 LOG.info("PCE replied to PCR Request !");
823 notification = new ServiceRpcResultBuilder()
824 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
825 .setServiceName("").setStatus(RpcStatusEx.Successful)
826 .setStatusMessage("Service Feasility Checked").build();
828 notificationPublishService.putNotification(notification);
829 } catch (InterruptedException e) {
830 LOG.info("notification offer rejected : " + e);
832 message = response.getConfigurationResponseCommon().getResponseMessage();
833 sendNotifToUrl(notification, notificationUrl);
835 message = mappingAndSendingPCRequest.getError();// "Path
838 responseCode = "500";
839 notification = new ServiceRpcResultBuilder()
840 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
841 .setServiceName("").setStatus(RpcStatusEx.Failed).setStatusMessage(message)
844 notificationPublishService.putNotification(notification);
845 } catch (InterruptedException e) {
846 LOG.info("notification offer rejected : " + e);
848 sendNotifToUrl(notification, notificationUrl);
853 ListenableFuture<PathComputationRequestOutput> pce = mappingAndSendingPCRequest
854 .pathComputationRequest();
855 Futures.addCallback(pce, pceCallback);
856 LOG.info("PCR Request in progress ");
857 configurationResponseCommon = new ConfigurationResponseCommonBuilder()
858 .setAckFinalIndicator("No").setRequestId(input.getSdncRequestHeader().getRequestId())
859 .setResponseMessage("Service compliant, ServiceFeasibilityCheck in progress...")
860 .setResponseCode("200").build();
862 ServiceFeasibilityCheckOutput output = new ServiceFeasibilityCheckOutputBuilder()
863 .setConfigurationResponseCommon(configurationResponseCommon).build();
865 return RpcResultBuilder.success(output).buildFuture();
869 message = txrxCheck.getMessage();
870 responseCode = "500";
873 message = txrxCheck.getMessage();
874 responseCode = "500";
877 message = compliancyCheck.getMessage();
878 responseCode = "500";
881 configurationResponseCommon = new ConfigurationResponseCommonBuilder().setAckFinalIndicator("Yes")
882 .setRequestId(input.getSdncRequestHeader().getRequestId()).setResponseMessage(message)
883 .setResponseCode(responseCode).build();
885 ResponseParameters responseParameters = new ResponseParametersBuilder()
886 .setHardConstraints(input.getHardConstraints())
887 // .setPceMetric(input.getPceMetric())
888 .setSoftConstraints(input.getSoftConstraints())
889 // .setLocallyProtectedLinks(input.isLocallyProtectedLinks())
892 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.service.feasibility
893 .check.output.ServiceAEnd serviceAEnd = new org.opendaylight.yang.gen.v1.http.org.opendaylight
894 .transportpce.servicehandler.rev161014.service.feasibility
895 .check.output.ServiceAEndBuilder(input.getServiceAEnd()).build();
897 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.service.feasibility
898 .check.output.ServiceZEnd serviceZEnd = new org.opendaylight.yang.gen.v1.http.org.opendaylight
899 .transportpce.servicehandler.rev161014.service.feasibility
900 .check.output.ServiceZEndBuilder(input.getServiceZEnd()).build();
903 Port txPort = new PortBuilder().setPortDeviceName("ROUTER_SNJSCAMCJW1_000000.00_00").setPortType("router")
904 .setPortName("Gigabit Ethernet_Tx.ge-1/0/0.0").setPortRack("000000.00").setPortShelf("00").build();
905 Lgx txLgx = new LgxBuilder().setLgxDeviceName("LGX Panel_SNJSCAMCJW1_000000.00_00")
906 .setLgxPortName("LGX_Back.23").setLgxPortRack("000000.00").setLgxPortShelf("00").build();
907 TxDirection txDirection = new TxDirectionBuilder().setPort(txPort).setLgx(txLgx).build();
910 Port rxPort = new PortBuilder().setPortDeviceName("ROUTER_SNJSCAMCJW1_000000.00_00").setPortType("router")
911 .setPortName("Gigabit Ethernet_Rx.ge-1/0/0.0").setPortRack("000000.00").setPortShelf("00").build();
912 Lgx rxLgx = new LgxBuilder().setLgxDeviceName("LGX Panel_SNJSCAMCJW1_000000.00_00").setLgxPortName("LGX_Back.6")
913 .setLgxPortRack("000000.00").setLgxPortShelf("00").build();
914 RxDirection rxDirection = new RxDirectionBuilder().setPort(rxPort).setLgx(rxLgx).build();
916 IntermediateSites inter = new IntermediateSitesBuilder().setClli("SNJSCAMCJW1").setServiceRate((long) 100)
917 .setServiceFormat(ServiceFormat.Ethernet).setOpticType(OpticTypes.Gray).setTxDirection(txDirection)
918 .setRxDirection(rxDirection).build();
920 List<IntermediateSites> intersites = new ArrayList<IntermediateSites>();
921 intersites.add(inter);
922 ServiceFeasibilityCheckOutput output = new ServiceFeasibilityCheckOutputBuilder()
923 .setIntermediateSites(intersites).setResponseParameters(responseParameters)
924 .setConfigurationResponseCommon(configurationResponseCommon).setServiceAEnd(serviceAEnd)
925 .setServiceZEnd(serviceZEnd).build();
927 return RpcResultBuilder.success(output).buildFuture();
931 public Future<RpcResult<ServiceReconfigureOutput>> serviceReconfigure(ServiceReconfigureInput input) {
933 LOG.info("RPC service reconfigure received");
934 notificationUrl = null;// input.getnotificationUrl();
935 boolean commonId = true;
936 boolean coherencyHardSoft = false;
937 ServiceRpcResult notification = null;
940 LOG.info("checking Service Compliancy ...");
942 * Upon receipt of service-create RPC, service header and sdnc-request
943 * header compliancy are verified.
945 compliancyCheck = new ServicehandlerCompliancyCheck(input.getServiceName(), input.getConnectionType(),
946 RpcActions.ServiceReconfigure);
947 if (compliancyCheck.check(true, false)) {
948 LOG.info("Service compliant !");
950 * If compliant, service-request parameters are verified in order to
951 * check if there is no missing parameter that prevents calculating
952 * a path and implement a service.
954 LOG.info("checking Tx/Rx Info for AEnd ...");
955 txrxCheck = new ServicehandlerTxRxCheck(input.getServiceAEnd(), 1);
956 if (txrxCheck.check()) {
957 LOG.info("Tx/Rx Info for AEnd checked !");
958 LOG.info("checking Tx/Rx Info for ZEnd ...");
959 txrxCheck = new ServicehandlerTxRxCheck(input.getServiceZEnd(), 2);
960 if (txrxCheck.check()) {
961 LOG.info("Tx/Rx Info for ZEnd checked");
963 * If OK, common-id is verified in order to see if there is
964 * no routing policy provided. If yes, the routing
965 * constraints of the policy are recovered and coherency
966 * with hard/soft constraints provided in the input of the
969 if (input.getCommonId() != null) {
970 LOG.info("Common-id specified");
972 * Check coherency with hard/soft constraints
975 checkCoherencyHardSoft = new CheckCoherencyHardSoft(input.getHardConstraints(),
976 input.getSoftConstraints());
977 if (checkCoherencyHardSoft.check()) {
978 LOG.info("hard/soft constraints coherent !");
979 coherencyHardSoft = true;
981 LOG.info("hard/soft constraints are not coherent !");
982 message = "hard/soft constraints are not coherent !";
988 if (!commonId || (commonId && coherencyHardSoft)) {
990 * Retrieving initial service topology.
992 String serviceName = input.getServiceName();
993 Services service = readServiceList(serviceName);
994 if (service != null) {
995 LOG.debug("Service '" + serviceName + "' present in datastore !");
997 * Sending cancel resource resv request to PCE
1000 mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, input, false);
1001 notification = new ServiceRpcResultBuilder()
1002 .setNotificationType(ServiceNotificationTypes.ServiceReconfigureResult)
1003 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1004 .setStatusMessage("Cancelling ResourceResv ...").build();
1006 notificationPublishService.putNotification(notification);
1007 } catch (InterruptedException e) {
1008 LOG.info("notification offer rejected : " + e);
1010 sendNotifToUrl(notification, notificationUrl);
1011 FutureCallback<CancelResourceReserveOutput> pceCallback =
1012 new FutureCallback<CancelResourceReserveOutput>() {
1013 String message = "";
1014 String responseCode = "";
1015 ServiceRpcResult notification = null;
1018 public void onFailure(Throwable arg0) {
1019 LOG.error("Failed to cancel ResourceResv ! ");
1020 notification = new ServiceRpcResultBuilder()
1021 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
1022 .setServiceName(serviceName).setStatus(RpcStatusEx.Failed)
1023 .setStatusMessage("PCR Request failed !").build();
1025 notificationPublishService.putNotification(notification);
1026 } catch (InterruptedException e) {
1027 LOG.info("notification offer rejected : " + e);
1033 public void onSuccess(CancelResourceReserveOutput arg0) {
1034 if (mappingAndSendingPCRequest.getSuccess() && arg0 != null) {
1035 LOG.info("Service ResourceResv cancelled !");
1036 notification = new ServiceRpcResultBuilder()
1037 .setNotificationType(ServiceNotificationTypes.ServiceReconfigureResult)
1038 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1040 "Service '" + serviceName + "' ResourceResv cancelled")
1043 notificationPublishService.putNotification(notification);
1044 } catch (InterruptedException e) {
1045 LOG.info("notification offer rejected : " + e);
1047 sendNotifToUrl(notification, notificationUrl);
1049 message = "Service '" + serviceName + "' ResourceResv cancelled";
1051 LOG.info("PCE replied to CancelResourceResv Request !");
1053 * Before sending the PCE request, input
1054 * data need to be formatted according
1055 * to the Service Handler - PCE
1056 * interface data model.
1058 mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, input,
1061 * Once PCE request is being sent to the
1062 * PCE on interface B, PCE reply is
1063 * expected until a timer expires.
1065 notification = new ServiceRpcResultBuilder()
1066 .setNotificationType(ServiceNotificationTypes.ServiceReconfigureResult)
1067 .setServiceName(serviceName).setStatus(RpcStatusEx.Pending)
1068 .setStatusMessage(message + ", submitting PathComputation Request ...")
1071 notificationPublishService.putNotification(notification);
1072 } catch (InterruptedException e) {
1073 LOG.info("notification offer rejected : " + e);
1075 sendNotifToUrl(notification, notificationUrl);
1076 PathComputationRequestOutput response = null;
1078 response = mappingAndSendingPCRequest.pathComputationRequest().get();
1079 } catch (InterruptedException | ExecutionException e2) {
1080 LOG.error(e2.getMessage());
1083 if (mappingAndSendingPCRequest.getSuccess() && response != null) {
1085 * If PCE reply is received before
1086 * timer expiration with a positive
1087 * result, a service is created with
1088 * admin and operational status
1091 LOG.info("PCE replied to PCR Request !");
1092 message = response.getConfigurationResponseCommon().getResponseMessage();
1093 notification = new ServiceRpcResultBuilder()
1094 .setNotificationType(
1095 ServiceNotificationTypes.ServiceReconfigureResult)
1096 .setServiceName(serviceName).setStatus(RpcStatusEx.Pending)
1097 .setStatusMessage("PCE replied to PCR Request !").build();
1099 notificationPublishService.putNotification(notification);
1100 } catch (InterruptedException e) {
1101 LOG.info("notification offer rejected : " + e);
1103 sendNotifToUrl(notification, notificationUrl);
1105 * Send Implementation order to
1108 mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry,
1111 notification = new ServiceRpcResultBuilder()
1112 .setNotificationType(
1113 ServiceNotificationTypes.ServiceReconfigureResult)
1114 .setServiceName(input.getServiceName())
1115 .setStatus(RpcStatusEx.Pending)
1116 .setStatusMessage("Submitting ServiceImplementation Request ...")
1119 notificationPublishService.putNotification(notification);
1120 } catch (InterruptedException e) {
1121 LOG.info("notification offer rejected : " + e);
1123 sendNotifToUrl(notification, notificationUrl);
1125 ServiceImplementationRequestOutput siOutput = null;
1127 siOutput = mappingAndSendingSIRequest.serviceImplementation().get();
1128 } catch (InterruptedException | ExecutionException e2) {
1129 LOG.error(e2.getMessage());
1131 ConfigurationResponseCommon siCommon = siOutput
1132 .getConfigurationResponseCommon();
1133 message = siCommon.getResponseMessage();
1135 if (mappingAndSendingSIRequest.getSuccess() && siOutput != null) {
1136 message = "Service reconfigured ";
1137 LOG.info("Service reconfigured !");
1138 notification = new ServiceRpcResultBuilder()
1139 .setNotificationType(
1140 ServiceNotificationTypes.ServiceReconfigureResult)
1141 .setServiceName(input.getServiceName())
1142 .setStatus(RpcStatusEx.Pending)
1143 .setStatusMessage("Service reconfigure !").build();
1145 notificationPublishService.putNotification(notification);
1146 } catch (InterruptedException e) {
1147 LOG.info("notification offer rejected : " + e);
1149 sendNotifToUrl(notification, notificationUrl);
1151 * Service implemented Update in
1154 Boolean update = false;
1155 Boolean delete = false;
1156 Services modifService = mappingServices(null, input, response);
1157 InstanceIdentifier<Services> iid = InstanceIdentifier
1158 .create(ServiceList.class)
1159 .child(Services.class, new ServicesKey(serviceName));
1160 WriteTransaction writeTx = db.newWriteOnlyTransaction();
1161 writeTx.delete(LogicalDatastoreType.OPERATIONAL, iid);
1163 LOG.info("Deleting service info ...");
1164 writeTx.submit().checkedGet();
1166 } catch (TransactionCommitFailedException e) {
1167 LOG.error("Failed to delete service from Service List");
1170 iid = InstanceIdentifier.create(ServiceList.class).child(
1171 Services.class, new ServicesKey(input.getNewServiceName()));
1172 writeTx = db.newWriteOnlyTransaction();
1173 writeTx.put(LogicalDatastoreType.OPERATIONAL, iid, modifService);
1175 LOG.info("Updating service info ...");
1176 writeTx.submit().checkedGet();
1178 } catch (TransactionCommitFailedException e) {
1179 LOG.error("Failed to modify service from Service List");
1183 LOG.info("Service '" + serviceName + "' updated with new name '"
1184 + input.getNewServiceName() + "' ! ");
1185 StringBuilder build = new StringBuilder();
1186 build.append(message);
1187 build.append(" : Service updated on DataBase !");
1188 message = build.toString();
1190 LOG.info("Service '" + serviceName + "' update failed ! ");
1191 StringBuilder build = new StringBuilder();
1192 build.append(message);
1193 build.append(" : Failed to modify service from Service List ");
1194 message = build.toString();
1197 LOG.info("Service not implemented !");
1198 message = response.getConfigurationResponseCommon()
1199 .getResponseMessage();
1200 notification = new ServiceRpcResultBuilder()
1201 .setNotificationType(
1202 ServiceNotificationTypes.ServiceReconfigureResult)
1203 .setServiceName(input.getServiceName())
1204 .setStatus(RpcStatusEx.Failed)
1206 "Service not implemented, cancelling ResourceResv")
1209 notificationPublishService.putNotification(notification);
1210 } catch (InterruptedException e) {
1211 LOG.info("notification offer rejected : " + e);
1213 sendNotifToUrl(notification, notificationUrl);
1214 mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry,
1217 * Send Cancel resource Request
1220 CancelResourceReserveOutput cancelOuptut = null;
1222 cancelOuptut = mappingAndSendingPCRequest.cancelResourceReserve()
1224 } catch (InterruptedException | ExecutionException e1) {
1225 LOG.error(e1.getMessage());
1227 if (mappingAndSendingPCRequest.getSuccess() && cancelOuptut != null) {
1228 LOG.info("Service ResourceResv cancelled !");
1229 message = response.getConfigurationResponseCommon()
1230 .getResponseMessage();
1231 notification = new ServiceRpcResultBuilder()
1232 .setNotificationType(
1233 ServiceNotificationTypes.ServiceReconfigureResult)
1234 .setServiceName(input.getServiceName())
1235 .setStatus(RpcStatusEx.Failed)
1236 .setStatusMessage("Service ResourceResv cancelled").build();
1238 notificationPublishService.putNotification(notification);
1239 } catch (InterruptedException e) {
1240 LOG.info("notification offer rejected : " + e);
1242 sendNotifToUrl(notification, notificationUrl);
1244 message = cancelOuptut.getConfigurationResponseCommon()
1245 .getResponseMessage();
1247 StringBuilder build = new StringBuilder();
1248 build.append("Service not implemented - ");
1249 build.append(message);
1250 message = build.toString();
1252 LOG.info("PCE replied to CancelResourceResv Request !");
1254 message = "Cancelling Resource reserved failed ";
1256 StringBuilder build = new StringBuilder();
1257 build.append("Service not implemented - ");
1258 build.append(message);
1259 message = build.toString();
1261 message = response.getConfigurationResponseCommon()
1262 .getResponseMessage();
1263 notification = new ServiceRpcResultBuilder()
1264 .setNotificationType(
1265 ServiceNotificationTypes.ServiceReconfigureResult)
1266 .setServiceName(input.getServiceName())
1267 .setStatus(RpcStatusEx.Failed)
1268 .setStatusMessage("Cancelling Resource reserved failed")
1271 notificationPublishService.putNotification(notification);
1272 } catch (InterruptedException e) {
1273 LOG.info("notification offer rejected : " + e);
1275 sendNotifToUrl(notification, notificationUrl);
1280 LOG.error("PCE pathcomputation request failed !");
1281 message = "PCE pathcomputation request failed : "
1282 + mappingAndSendingPCRequest.getError();// "Path
1287 message = "Cancelling Resource reserved failed ";
1289 StringBuilder build = new StringBuilder();
1290 build.append("Service not implemented - ");
1291 build.append(message);
1292 message = build.toString();
1294 notification = new ServiceRpcResultBuilder()
1295 .setNotificationType(ServiceNotificationTypes.ServiceReconfigureResult)
1296 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
1297 .setStatusMessage("Cancelling Resource reserved failed").build();
1299 notificationPublishService.putNotification(notification);
1300 } catch (InterruptedException e) {
1301 LOG.info("notification offer rejected : " + e);
1303 sendNotifToUrl(notification, notificationUrl);
1308 ListenableFuture<CancelResourceReserveOutput> pce = mappingAndSendingPCRequest
1309 .cancelResourceReserve();
1310 Futures.addCallback(pce, pceCallback);
1311 LOG.info("CancelResRev Request in progress ");
1312 ServiceReconfigureOutput output = new ServiceReconfigureOutputBuilder()
1313 .setStatus(RpcStatusEx.Pending).setStatusMessage(message).build();
1315 return RpcResultBuilder.success(output).buildFuture();
1318 message = "Service '" + serviceName + "' not exists in datastore";
1323 message = txrxCheck.getMessage();
1326 message = txrxCheck.getMessage();
1329 message = compliancyCheck.getMessage();
1332 ServiceReconfigureOutput output = new ServiceReconfigureOutputBuilder().setStatus(RpcStatusEx.Successful)
1333 .setStatusMessage(message).build();
1335 return RpcResultBuilder.success(output).buildFuture();
1339 public Future<RpcResult<ServiceRestorationOutput>> serviceRestoration(ServiceRestorationInput input) {
1340 LOG.info("RPC service restoration received");
1341 ServiceRpcResult notification = null;
1342 notificationUrl = null;// input.getnotificationUrl();
1343 String message = "";
1344 LOG.info("checking Service Compliancy ...");
1345 compliancyCheck = new ServicehandlerCompliancyCheck(input.getServiceName(), RpcActions.ServiceRestoration);
1346 if (compliancyCheck.check(false, false)) {
1347 LOG.info("Service compliant !");
1349 * If compliant, Getting path from service DB.
1352 String serviceName = input.getServiceName();
1353 Services service = readServiceList(serviceName);
1354 if (service != null) {
1355 LOG.debug("Service '" + serviceName + "' present in datastore !");
1356 notification = new ServiceRpcResultBuilder()
1357 .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1358 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1359 .setStatusMessage("Service '" + serviceName + "' present in datastore, deleting service ...")
1362 notificationPublishService.putNotification(notification);
1363 } catch (InterruptedException e) {
1364 LOG.info("notification offer rejected : " + e);
1366 sendNotifToUrl(notification, notificationUrl);
1368 * Sending delete order to renderer
1370 mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry, null, input.getServiceName());
1372 ListenableFuture<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce
1373 .stubrenderer.rev170426.ServiceDeleteOutput> renderer =
1374 mappingAndSendingSIRequest.serviceDelete();
1375 FutureCallback<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce
1376 .stubrenderer.rev170426.ServiceDeleteOutput> rendererCallback =
1377 new FutureCallback<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce
1378 .stubrenderer.rev170426.ServiceDeleteOutput>() {
1379 String message = "";
1380 String responseCode = "";
1381 ServiceRpcResult notification = null;
1384 public void onFailure(Throwable arg0) {
1385 LOG.error("ServiceDelete Request failed !");
1386 notification = new ServiceRpcResultBuilder()
1387 .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1388 .setServiceName(serviceName).setStatus(RpcStatusEx.Failed)
1389 .setStatusMessage("ServiceDelete Request failed !").build();
1391 notificationPublishService.putNotification(notification);
1392 } catch (InterruptedException e) {
1393 LOG.info("notification offer rejected : " + e);
1395 sendNotifToUrl(notification, notificationUrl);
1399 public void onSuccess(org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce
1400 .stubrenderer.rev170426.ServiceDeleteOutput arg0) {
1402 message = arg0.getConfigurationResponseCommon().getResponseMessage();
1403 notification = new ServiceRpcResultBuilder()
1404 .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1405 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1406 .setStatusMessage("Service deleted !").build();
1408 notificationPublishService.putNotification(notification);
1409 } catch (InterruptedException e) {
1410 LOG.info("notification offer rejected : " + e);
1412 sendNotifToUrl(notification, notificationUrl);
1413 mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, service, true);
1415 * Once PCE request is being sent to the PCE on
1416 * interface B, PCE reply is expected until a timer
1419 notification = new ServiceRpcResultBuilder()
1420 .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1421 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1422 .setStatusMessage("Service deleted, submitting PathComputation Request ...")
1425 notificationPublishService.putNotification(notification);
1426 } catch (InterruptedException e) {
1427 LOG.info("notification offer rejected : " + e);
1429 sendNotifToUrl(notification, notificationUrl);
1430 PathComputationRequestOutput response = null;
1432 response = mappingAndSendingPCRequest.pathComputationRequest().get();
1433 } catch (InterruptedException | ExecutionException e2) {
1434 LOG.error(e2.getMessage());
1437 if (mappingAndSendingPCRequest.getSuccess() && response != null) {
1439 * If PCE reply is received before timer
1440 * expiration with a positive result, a service
1441 * is created with admin and operational status
1444 LOG.info("Path calculated !");
1445 message = response.getConfigurationResponseCommon().getResponseMessage();
1446 notification = new ServiceRpcResultBuilder()
1447 .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1448 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1449 .setStatusMessage("Path calculated, modifying Service Admin / Op ...").build();
1451 notificationPublishService.putNotification(notification);
1452 } catch (InterruptedException e) {
1453 LOG.info("notification offer rejected : " + e);
1455 sendNotifToUrl(notification, notificationUrl);
1458 * creating Service with Admin / Op to down.
1462 ServicesBuilder serviceRestoration = new ServicesBuilder(service)
1463 .setAdministrativeState(State.OutOfService)
1464 .setOperationalState(State.OutOfService)
1465 .setLifecycleState(LifecycleState.Planned);
1467 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
1468 .service.types.rev170426.response
1469 .parameters.sp.ResponseParameters responseParameters =
1470 response.getResponseParameters();
1471 if (responseParameters != null) {
1472 // serviceRestoration.setPceMetric(responseParameters.getPceMetric());
1473 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
1474 .service.types.rev170426.response.parameters.sp.response
1475 .parameters.PathDescription pathDescription =
1476 responseParameters.getPathDescription();
1477 if (pathDescription != null) {
1478 List<AToZ> atozList = new ArrayList<AToZ>();
1479 List<ZToA> ztoaList = new ArrayList<ZToA>();
1481 for (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
1482 .pathdescription.rev170426.path.description.atoz.direction.AToZ
1483 tmp : pathDescription.getAToZDirection().getAToZ()) {
1485 AToZKey key = new AToZKey(tmp.getKey().getId());
1486 tmp.getResource().getResource();
1487 AToZ atoz = new AToZBuilder().setId(tmp.getId()).setKey(key)
1488 // .setResource(tmp.getResource())
1493 for (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
1494 .pathdescription.rev170426.path.description.ztoa.direction.ZToA
1495 tmp : pathDescription.getZToADirection().getZToA()) {
1496 ZToAKey key = new ZToAKey(tmp.getKey().getId());
1497 ZToA ztoa = new ZToABuilder().setId(tmp.getId()).setKey(key)
1498 // .setResource(tmp.getResource())
1502 Topology topology = new TopologyBuilder().setAToZ(atozList).setZToA(ztoaList)
1504 serviceRestoration.setTopology(topology);
1507 Boolean update = false;
1508 InstanceIdentifier<Services> iid = InstanceIdentifier.create(ServiceList.class)
1509 .child(Services.class, new ServicesKey(serviceName));
1510 WriteTransaction writeTx = db.newWriteOnlyTransaction();
1511 writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, service);
1514 writeTx.submit().checkedGet();
1516 } catch (TransactionCommitFailedException e) {
1517 LOG.error("Failed to modify service from Service List");
1520 LOG.info("Service modified !");
1522 * Send Implementation order to renderer
1524 mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry, service);
1526 notification = new ServiceRpcResultBuilder()
1527 .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1528 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1530 "Service modified, submitting ServiceImplementation Request")
1533 notificationPublishService.putNotification(notification);
1534 } catch (InterruptedException e) {
1535 LOG.info("notification offer rejected : " + e);
1537 sendNotifToUrl(notification, notificationUrl);
1539 ServiceImplementationRequestOutput siOutput = null;
1541 siOutput = mappingAndSendingSIRequest.serviceImplementation().get();
1542 } catch (InterruptedException | ExecutionException e2) {
1543 LOG.error(e2.getMessage());
1545 if (mappingAndSendingSIRequest.getSuccess() && siOutput != null) {
1546 ConfigurationResponseCommon siCommon = siOutput
1547 .getConfigurationResponseCommon();
1548 message = siCommon.getResponseMessage();
1549 LOG.info("Service restored !");
1550 notification = new ServiceRpcResultBuilder()
1551 .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1552 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1553 .setStatusMessage("Service restored !").build();
1555 notificationPublishService.putNotification(notification);
1556 } catch (InterruptedException e) {
1557 LOG.info("notification offer rejected : " + e);
1559 sendNotifToUrl(notification, notificationUrl);
1561 * Service implemented setting Service
1564 if (writeOrModifyOrDeleteServiceList(serviceName, null, null, 0) == null) {
1565 message = "Service restored : Service Op Status changed to Up !";
1567 message = "Service restored : "
1568 + "but Failed to modify service from Service List !";
1571 LOG.info("Service not restored !");
1572 message = response.getConfigurationResponseCommon().getResponseMessage();
1573 notification = new ServiceRpcResultBuilder()
1574 .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1575 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
1576 .setStatusMessage("Service not restored, cancelling ResourceResv ...")
1579 notificationPublishService.putNotification(notification);
1580 } catch (InterruptedException e) {
1581 LOG.info("notification offer rejected : " + e);
1583 sendNotifToUrl(notification, notificationUrl);
1584 mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry,
1587 * Send Cancel resource Request to PCE.
1589 CancelResourceReserveOutput cancelOuptut = null;
1591 cancelOuptut = mappingAndSendingPCRequest.cancelResourceReserve().get();
1592 } catch (InterruptedException | ExecutionException e1) {
1593 LOG.error(e1.getMessage());
1595 if (mappingAndSendingPCRequest.getSuccess() && cancelOuptut != null) {
1596 LOG.info("Service ResourceResv cancelled !");
1597 message = response.getConfigurationResponseCommon().getResponseMessage();
1598 notification = new ServiceRpcResultBuilder()
1599 .setNotificationType(
1600 ServiceNotificationTypes.ServiceRestorationResult)
1601 .setServiceName(input.getServiceName())
1602 .setStatus(RpcStatusEx.Pending)
1603 .setStatusMessage("Service ResourceResv cancelled").build();
1605 notificationPublishService.putNotification(notification);
1606 } catch (InterruptedException e) {
1607 LOG.info("notification offer rejected : " + e);
1609 sendNotifToUrl(notification, notificationUrl);
1610 message = cancelOuptut.getConfigurationResponseCommon()
1611 .getResponseMessage();
1612 StringBuilder build = new StringBuilder();
1613 build.append("Service not implemented - ");
1614 build.append(message);
1615 message = build.toString();
1616 LOG.info("PCE replied to CancelResourceResv Request !");
1618 message = "Cancelling Resource reserved failed ";
1620 StringBuilder build = new StringBuilder();
1621 build.append("Service not implemented - ");
1622 build.append(message);
1623 message = build.toString();
1624 message = response.getConfigurationResponseCommon().getResponseMessage();
1625 notification = new ServiceRpcResultBuilder()
1626 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
1627 .setServiceName(input.getServiceName())
1628 .setStatus(RpcStatusEx.Failed)
1629 .setStatusMessage("Cancelling Resource reserved failed").build();
1631 notificationPublishService.putNotification(notification);
1632 } catch (InterruptedException e) {
1633 LOG.info("notification offer rejected : " + e);
1635 sendNotifToUrl(notification, notificationUrl);
1639 LOG.error("Failed to modify service from service list !");
1642 message = mappingAndSendingPCRequest.getError();
1643 /* Path not calculated. */
1644 LOG.error("Path Computation request failed : " + message);
1647 message = "deleting service failed";
1652 Futures.addCallback(renderer, rendererCallback);
1653 ServiceRestorationOutput output = new ServiceRestorationOutputBuilder().setStatus(RpcStatusEx.Pending)
1654 .setStatusMessage(message).build();
1656 return RpcResultBuilder.success(output).buildFuture();
1659 message = "Service '" + serviceName + "' not exists in datastore";
1664 message = compliancyCheck.getMessage();
1668 ServiceRestorationOutput output = new ServiceRestorationOutputBuilder().setStatus(RpcStatusEx.Successful)
1669 .setStatusMessage(message).build();
1671 return RpcResultBuilder.success(output).buildFuture();
1675 * Initialize ServiceList Structure on Datastore.
1680 private void initializeDataTree(DataBroker db) {
1681 LOG.info("Preparing to initialize the greeting registry");
1682 WriteTransaction transaction = db.newWriteOnlyTransaction();
1683 InstanceIdentifier<ServiceList> iid = InstanceIdentifier.create(ServiceList.class);
1684 ServiceList greetingRegistry = new ServiceListBuilder().build();
1685 transaction.put(LogicalDatastoreType.OPERATIONAL, iid, greetingRegistry);
1686 CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
1687 Futures.addCallback(future, new LoggingFuturesCallBack<>("Failed to create Service List", LOG));
1691 * Map Input (ServiceCreateInmput, ServiceReconfigureInput) & output
1692 * (PathComputationRequestOutput) to Service.
1694 * @param serviceCreateInput
1695 * ServiceCreateInput parameter
1696 * @param serviceReconfigureInput
1697 * serviceReconfigureInput parameter
1699 * PathComputationRequestOutput parameter
1701 * @return Services Service data
1703 private Services mappingServices(ServiceCreateInput serviceCreateInput,
1704 ServiceReconfigureInput serviceReconfigureInput, PathComputationRequestOutput output) {
1705 LOG.info("Mapping informations to Services");
1706 ServiceAEnd aend = null;
1707 ServiceZEnd zend = null;
1708 ServicesBuilder service = new ServicesBuilder();
1709 if (serviceCreateInput != null) {
1710 aend = new ServiceAEndBuilder(serviceCreateInput.getServiceAEnd()).build();
1711 zend = new ServiceZEndBuilder(serviceCreateInput.getServiceZEnd()).build();
1712 service.setServiceName(serviceCreateInput.getServiceName()).setAdministrativeState(State.OutOfService)
1713 .setOperationalState(State.OutOfService).setCommonId(serviceCreateInput.getCommonId())
1714 .setConnectionType(serviceCreateInput.getConnectionType())
1715 .setCustomer(serviceCreateInput.getCustomer())
1716 .setCustomerContact(serviceCreateInput.getCustomerContact())
1717 .setHardConstraints(serviceCreateInput.getHardConstraints())
1718 .setSoftConstraints(serviceCreateInput.getSoftConstraints())
1719 .setLifecycleState(LifecycleState.Planned).setServiceAEnd(aend).setServiceZEnd(zend);
1721 } else if (serviceReconfigureInput != null) {
1722 aend = new ServiceAEndBuilder(serviceReconfigureInput.getServiceAEnd()).build();
1723 zend = new ServiceZEndBuilder(serviceReconfigureInput.getServiceZEnd()).build();
1724 service.setServiceName(serviceReconfigureInput.getNewServiceName())
1725 .setAdministrativeState(State.OutOfService).setOperationalState(State.OutOfService)
1726 .setCommonId(serviceReconfigureInput.getCommonId())
1727 .setConnectionType(serviceReconfigureInput.getConnectionType())
1728 .setCustomer(serviceReconfigureInput.getCustomer())
1729 .setCustomerContact(serviceReconfigureInput.getCustomerContact())
1730 .setHardConstraints(serviceReconfigureInput.getHardConstraints())
1731 .setSoftConstraints(serviceReconfigureInput.getSoftConstraints())
1732 .setLifecycleState(LifecycleState.Planned).setServiceAEnd(aend).setServiceZEnd(zend);
1735 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.response
1736 .parameters.sp.ResponseParameters responseParameters = output.getResponseParameters();
1737 if (responseParameters != null) {
1738 // service.setPceMetric(responseParameters.getPceMetric());
1739 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426
1740 .response.parameters.sp.response.parameters.PathDescription pathDescription =
1741 responseParameters.getPathDescription();
1742 if (pathDescription != null) {
1743 List<AToZ> atozList = new ArrayList<AToZ>();
1744 List<ZToA> ztoaList = new ArrayList<ZToA>();
1746 for (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426
1747 .path.description.atoz.direction.AToZ
1748 tmp : pathDescription.getAToZDirection().getAToZ()) {
1750 AToZKey key = new AToZKey(tmp.getKey().getId());
1751 AToZ atoz = new AToZBuilder().setId(tmp.getId()).setKey(key)
1752 // .setResource(tmp.getResource())
1757 for (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426
1758 .path.description.ztoa.direction.ZToA
1759 tmp : pathDescription.getZToADirection().getZToA()) {
1760 ZToAKey key = new ZToAKey(tmp.getKey().getId());
1761 ZToA ztoa = new ZToABuilder().setId(tmp.getId()).setKey(key)
1762 // .setResource(tmp.getResource())
1767 Topology topology = new TopologyBuilder().setAToZ(atozList).setZToA(ztoaList).build();
1768 service.setTopology(topology);
1771 return service.build();
1775 * read Service from ServiceList DataStore.
1777 * @param serviceName
1780 * @return <code>Services</code>
1782 private Services readServiceList(String serviceName) {
1783 Services result = null;
1784 ReadOnlyTransaction readTx = db.newReadOnlyTransaction();
1785 InstanceIdentifier<Services> iid = InstanceIdentifier.create(ServiceList.class).child(Services.class,
1786 new ServicesKey(serviceName));
1787 CheckedFuture<Optional<Services>, ReadFailedException> future = readTx.read(LogicalDatastoreType.OPERATIONAL,
1789 Optional<Services> optional = Optional.absent();
1791 optional = future.checkedGet();
1792 } catch (ReadFailedException e) {
1793 LOG.error("Reading service failed:", e);
1795 if (optional.isPresent()) {
1796 LOG.debug("Service '" + serviceName + "' present !");
1797 result = new ServicesBuilder(optional.get()).build();
1803 * Write or Modify or Delete Service from/to SreviceList.
1805 * @param serviceName
1808 * ServiceCreateInput
1810 * PathComputationRequestOutput
1812 * 0 - Modify 1 - Delete 2 - Write
1813 * @return String operations result, null if ok or not otherwise
1815 private String writeOrModifyOrDeleteServiceList(String serviceName, ServiceCreateInput input,
1816 PathComputationRequestOutput output, int choice) {
1817 LOG.debug("WriteOrModifyOrDeleting '" + serviceName + "' Service");
1818 WriteTransaction writeTx = db.newWriteOnlyTransaction();
1819 String result = null;
1820 Services readService = readServiceList(serviceName);
1821 if (readService != null) {
1823 * Modify / Delete Service.
1825 InstanceIdentifier<Services> iid = InstanceIdentifier.create(ServiceList.class).child(Services.class,
1826 new ServicesKey(serviceName));
1827 ServicesBuilder service = new ServicesBuilder(readService);
1829 String action = null;
1831 case 0: /* Modify. */
1832 LOG.debug("Modifying '" + serviceName + "' Service");
1833 service.setOperationalState(State.InService).setAdministrativeState(State.InService);
1834 writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, service.build());
1838 case 1: /* Delete */
1839 LOG.debug("Deleting '" + serviceName + "' Service");
1840 writeTx.delete(LogicalDatastoreType.OPERATIONAL, iid);
1845 LOG.debug("No choice found");
1850 writeTx.submit().checkedGet();
1851 } catch (TransactionCommitFailedException e) {
1852 LOG.error("Failed to " + action + " service from Service List");
1853 result = "Failed to " + action + " service from Service List";
1856 if (choice == 2) { /* Write Service */
1857 LOG.debug("Writing '" + serviceName + "' Service");
1858 InstanceIdentifier<Services> iid = InstanceIdentifier.create(ServiceList.class).child(Services.class,
1859 new ServicesKey(serviceName));
1861 Services service = mappingServices(input, null, output);
1862 writeTx.put(LogicalDatastoreType.OPERATIONAL, iid, service);
1864 writeTx.submit().checkedGet();
1866 } catch (TransactionCommitFailedException e) {
1867 LOG.error("Failed to write service to Service List");
1868 result = "Failed to write service to Service List";
1871 LOG.info("Service is not present ! ");
1872 result = "Service is not present ! ";
1878 private void sendNotifToUrl(ServiceRpcResult notification, String url) {
1879 Gson gson = new GsonBuilder().setPrettyPrinting()
1880 // .serializeNulls()
1882 String data = gson.toJson(notification);
1886 HttpURLConnection con = (HttpURLConnection) obj.openConnection();
1888 // add request header
1889 con.setRequestMethod("POST");
1890 con.setRequestProperty("Content-Type", "application/json");
1891 con.setRequestProperty("Accept", "application/json");
1893 // Send post request
1894 con.setDoOutput(true);
1895 DataOutputStream wr = new DataOutputStream(con.getOutputStream());
1896 wr.writeBytes(data);
1899 int responseCode = con.getResponseCode();
1900 LOG.info("Response Code : " + responseCode);
1901 } catch (IOException e) {
1902 LOG.error("IOException : " + e.toString());
1908 public void close() throws Exception {
1909 executor.shutdown();
1913 public Future<RpcResult<EquipmentNotificationOutput>> equipmentNotification(EquipmentNotificationInput input) {
1914 // TODO Auto-generated method stub
1919 public Future<RpcResult<ServiceRerouteConfirmOutput>> serviceRerouteConfirm(ServiceRerouteConfirmInput input) {
1920 // TODO Auto-generated method stub
1925 public Future<RpcResult<ServiceRerouteOutput>> serviceReroute(ServiceRerouteInput input) {
1926 // TODO Auto-generated method stub
1931 public Future<RpcResult<ServiceReversionOutput>> serviceReversion(ServiceReversionInput input) {
1932 // TODO Auto-generated method stub
1937 public Future<RpcResult<ServiceRollOutput>> serviceRoll(ServiceRollInput input) {
1938 // TODO Auto-generated method stub
1943 public Future<RpcResult<NetworkReOptimizationOutput>> networkReOptimization(NetworkReOptimizationInput input) {
1944 // TODO Auto-generated method stub
1949 public Future<RpcResult<TempServiceDeleteOutput>> tempServiceDelete(TempServiceDeleteInput input) {
1950 // TODO Auto-generated method stub
1955 public Future<RpcResult<TempServiceCreateOutput>> tempServiceCreate(TempServiceCreateInput input) {
1956 // TODO Auto-generated method stub
1961 public void onServiceRpcResultSp(ServiceRpcResultSp notification) {
1962 if (!compareServiceRpcResultSp(notification)) {
1963 serviceRpcResultSp = notification;
1964 StringBuilder build = new StringBuilder();
1966 "Received '" + notification.getNotificationType() + "' StubRenderer notification" + "from service '"
1967 + notification.getServiceName() + "' " + "with status '" + notification.getStatus() + "'");
1968 build.append(" with StatusMessage '" + notification.getStatusMessage() + "'");
1969 if (notification.getStatus() == RpcStatusEx.Successful && notification.getNotificationType()
1970 .getIntValue() == ServicePathNotificationTypes.ServiceImplementationRequest.getIntValue()) {
1971 build.append(" PathTopology : " + notification.getPathTopology().toString());
1973 LOG.info(build.toString());
1975 LOG.info("ServicePathRpcResult already wired !");
1981 public void onServicePathRpcResult(ServicePathRpcResult notification) {
1982 if (!compareServicePathRpcResult(notification)) {
1983 servicePathRpcResult = notification;
1984 StringBuilder build = new StringBuilder();
1986 "Received '" + notification.getNotificationType() + "' StubPce notification " + "from service '"
1987 + notification.getServiceName() + "' " + "with status '" + notification.getStatus() + "'");
1988 build.append(" with StatusMessage '" + notification.getStatusMessage() + "'");
1989 if (notification.getStatus() == RpcStatusEx.Successful && notification.getNotificationType()
1990 .getIntValue() == ServicePathNotificationTypes.PathComputationRequest.getIntValue()) {
1991 build.append(" PathDescription : " + notification.getPathDescription().toString());
1993 * switch (action.getIntValue()) { case 1: //service-create case
1994 * 3: //service-delete case 8: //service-reconfigure case 9:
1995 * //service-restoration case 10://service-reversion case
1996 * 11://service-reroute break;
2002 LOG.info(build.toString());
2004 LOG.info("ServicePathRpcResult already wired !");
2008 public RpcActions getAction() {
2012 public void setAction(RpcActions action) {
2013 this.action = action;
2016 public Boolean compareServicePathRpcResult(ServicePathRpcResult notification) {
2017 Boolean result = true;
2018 if (servicePathRpcResult == null) {
2021 if (servicePathRpcResult.getNotificationType() != notification.getNotificationType()) {
2024 if (servicePathRpcResult.getServiceName() != notification.getServiceName()) {
2027 if (servicePathRpcResult.getStatus() != notification.getStatus()) {
2030 if (servicePathRpcResult.getStatusMessage() != notification.getStatusMessage()) {
2037 public Boolean compareServiceRpcResultSp(ServiceRpcResultSp notification) {
2038 Boolean result = true;
2039 if (serviceRpcResultSp == null) {
2042 if (serviceRpcResultSp.getNotificationType() != notification.getNotificationType()) {
2045 if (serviceRpcResultSp.getServiceName() != notification.getServiceName()) {
2048 if (serviceRpcResultSp.getStatus() != notification.getStatus()) {
2051 if (serviceRpcResultSp.getStatusMessage() != notification.getStatusMessage()) {