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 & 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-create RPC, service header and sdnc-request
198 * header compliancy are verified.
200 compliancyCheck = new ServicehandlerCompliancyCheck(input.getSdncRequestHeader(), input.getServiceName(),
201 input.getConnectionType(), RpcActions.ServiceCreate);
202 if (compliancyCheck.check(true, true)) {
203 LOG.info("Service compliant !");
205 * If compliant, service-request parameters are verified in order to
206 * check if there is no missing parameter that prevents calculating
207 * a path and implement a service.
209 LOG.info("checking Tx/Rx Info for AEnd ...");
210 txrxCheck = new ServicehandlerTxRxCheck(input.getServiceAEnd(), 1);
211 if (txrxCheck.check()) {
212 LOG.info("Tx/Rx Info for AEnd checked !");
213 LOG.info("checking Tx/Rx Info for ZEnd ...");
214 txrxCheck = new ServicehandlerTxRxCheck(input.getServiceZEnd(), 2);
215 if (txrxCheck.check()) {
216 LOG.info("Tx/Rx Info for ZEnd checked");
218 * If OK, common-id is verified in order to see if there is
219 * no routing policy provided. If yes, the routing
220 * constraints of the policy are recovered and coherency
221 * with hard/soft constraints provided in the input of the
224 if (input.getCommonId() != null) {
225 LOG.info("Common-id specified");
227 * Check coherency with hard/soft constraints
230 checkCoherencyHardSoft = new CheckCoherencyHardSoft(input.getHardConstraints(),
231 input.getSoftConstraints());
232 if (checkCoherencyHardSoft.check()) {
233 LOG.info("hard/soft constraints coherent !");
234 coherencyHardSoft = true;
236 LOG.info("hard/soft constraints are not coherent !");
237 message = "hard/soft constraints are not coherent !";
238 responseCode = "500";
244 if (!commonId || (commonId && coherencyHardSoft)) {
246 * Before sending the PCE request, input data need to be
247 * formatted according to the Service Handler PCE
248 * interface data model.
250 mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, input, true);
252 * Once PCE request is being sent to the PCE on
253 * interface B, PCE reply is expected until a timer
256 notification = new ServiceRpcResultBuilder()
257 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
258 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
259 .setStatusMessage("Service compliant, submitting PathComputation Request ...").build();
261 notificationPublishService.putNotification(notification);
262 } catch (InterruptedException e) {
263 LOG.info("notification offer rejected : " + e);
265 sendNotifToUrl(notification, notificationUrl);
266 FutureCallback<PathComputationRequestOutput> pceCallback =
267 new FutureCallback<PathComputationRequestOutput>() {
269 String responseCode = "";
270 ServiceRpcResult notification = null;
273 public void onSuccess(PathComputationRequestOutput response) {
274 if (mappingAndSendingPCRequest.getSuccess() && response != null) {
276 * If PCE reply is received before timer
277 * expiration with a positive result, a
278 * service is created with admin and
279 * operational status 'down'.
281 LOG.info("PCE replied to PCR Request !");
283 message = response.getConfigurationResponseCommon().getResponseMessage();
284 notification = new ServiceRpcResultBuilder()
285 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
286 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
287 .setStatusMessage("PCE replied to PCR Request !").build();
289 notificationPublishService.putNotification(notification);
290 } catch (InterruptedException e) {
291 LOG.info("notification offer rejected : " + e);
293 sendNotifToUrl(notification, notificationUrl);
294 String result = null;
295 if ((result = writeOrModifyOrDeleteServiceList(input.getServiceName(), input,
296 response, 2)) != null) {
297 StringBuilder build = new StringBuilder();
298 build.append(message);
299 build.append(" " + result);
300 message = build.toString();
303 * Send Implementation order to renderer
305 mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry, input,
308 notification = new ServiceRpcResultBuilder()
309 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
310 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
311 .setStatusMessage("Submitting ServiceImplementation Request ...")
314 notificationPublishService.putNotification(notification);
315 } catch (InterruptedException e) {
316 LOG.info("notification offer rejected : " + e);
318 sendNotifToUrl(notification, notificationUrl);
321 * Once PCE request is being sent to the
322 * PCE on interface B, PCE reply is
323 * expected until a timer expires.
325 ServiceImplementationRequestOutput siOutput = null;
327 siOutput = mappingAndSendingSIRequest.serviceImplementation().get();
328 } catch (InterruptedException | ExecutionException e2) {
329 LOG.error("mappingAndSendingSIRequest.serviceImplementation().get() : "
332 if (siOutput == null) {
333 LOG.info("siOutput is null ");
334 LOG.info("Success : " + mappingAndSendingPCRequest.getSuccess());
336 if (mappingAndSendingSIRequest.getSuccess() && siOutput != null) {
337 ConfigurationResponseCommon siCommon = siOutput
338 .getConfigurationResponseCommon();
340 // siCommon.getResponseMessage();
341 responseCode = siCommon.getResponseCode();
342 message = "Service implemented !";
344 notification = new ServiceRpcResultBuilder()
345 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
346 .setServiceName(input.getServiceName())
347 .setStatus(RpcStatusEx.Successful).setStatusMessage(message)
350 notificationPublishService.putNotification(notification);
351 } catch (InterruptedException e) {
352 LOG.info("notification offer rejected : " + e);
354 sendNotifToUrl(notification, notificationUrl);
356 * Service implemented setting
357 * Service op status to up
359 if (writeOrModifyOrDeleteServiceList(input.getServiceName(), null, null,
364 StringBuilder build = new StringBuilder();
365 build.append(message);
366 build.append(" : Service Op Status changed to Up !");
367 message = build.toString();
369 StringBuilder build = new StringBuilder();
370 build.append(message);
371 build.append(" but Failed to modify service from Service List !");
372 message = build.toString();
374 notification = new ServiceRpcResultBuilder()
375 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
376 .setServiceName(input.getServiceName())
377 .setStatus(RpcStatusEx.Successful).setStatusMessage(message)
380 notificationPublishService.putNotification(notification);
381 } catch (InterruptedException e) {
382 LOG.info("notification offer rejected : " + e);
384 sendNotifToUrl(notification, notificationUrl);
386 LOG.info("Service not implemented !");
387 message = response.getConfigurationResponseCommon().getResponseMessage();
388 notification = new ServiceRpcResultBuilder()
389 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
390 .setServiceName(input.getServiceName())
391 .setStatus(RpcStatusEx.Failed)
393 "Service not implemented, cancelling ResourceResv ...")
396 notificationPublishService.putNotification(notification);
397 } catch (InterruptedException e) {
398 LOG.info("notification offer rejected : " + e);
400 sendNotifToUrl(notification, notificationUrl);
401 mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry,
404 * Send Cancel resource Request to
407 CancelResourceReserveOutput cancelOuptut = null;
409 cancelOuptut = mappingAndSendingPCRequest.cancelResourceReserve().get();
410 } catch (InterruptedException | ExecutionException e1) {
411 LOG.error(e1.getMessage());
413 if (mappingAndSendingPCRequest.getSuccess() && cancelOuptut != null) {
414 LOG.info("Service ResourceResv cancelled !");
415 message = response.getConfigurationResponseCommon()
416 .getResponseMessage();
417 notification = new ServiceRpcResultBuilder()
418 .setNotificationType(
419 ServiceNotificationTypes.ServiceCreateResult)
420 .setServiceName(input.getServiceName())
421 .setStatus(RpcStatusEx.Failed)
422 .setStatusMessage("Service ResourceResv cancelled").build();
424 notificationPublishService.putNotification(notification);
425 } catch (InterruptedException e) {
426 LOG.info("notification offer rejected : " + e);
428 sendNotifToUrl(notification, notificationUrl);
430 message = cancelOuptut.getConfigurationResponseCommon()
431 .getResponseMessage();
432 responseCode = cancelOuptut.getConfigurationResponseCommon()
435 StringBuilder build = new StringBuilder();
436 build.append("Service not implemented - ");
437 build.append(message);
438 message = build.toString();
440 LOG.info("PCE replied to CancelResourceResv Request !");
442 message = "Cancelling Resource reserved failed ";
444 responseCode = "500";
445 StringBuilder build = new StringBuilder();
446 build.append("Service not implemented - ");
447 build.append(message);
448 message = build.toString();
450 message = response.getConfigurationResponseCommon()
451 .getResponseMessage();
452 notification = new ServiceRpcResultBuilder()
453 .setNotificationType(
454 ServiceNotificationTypes.ServiceCreateResult)
455 .setServiceName(input.getServiceName())
456 .setStatus(RpcStatusEx.Failed)
457 .setStatusMessage("Cancelling Resource reserved failed")
460 notificationPublishService.putNotification(notification);
461 } catch (InterruptedException e) {
462 LOG.info("notification offer rejected : " + e);
464 sendNotifToUrl(notification, notificationUrl);
470 message = mappingAndSendingPCRequest.getError();// "Path
473 responseCode = "500";
474 notification = new ServiceRpcResultBuilder()
475 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
476 .setServiceName("").setStatus(RpcStatusEx.Failed).setStatusMessage(message)
479 notificationPublishService.putNotification(notification);
480 } catch (InterruptedException e) {
481 LOG.info("notification offer rejected : " + e);
483 sendNotifToUrl(notification, notificationUrl);
489 public void onFailure(Throwable arg0) {
490 LOG.error("Path not calculated..");
491 notification = new ServiceRpcResultBuilder()
492 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
493 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
494 .setStatusMessage("PCR Request failed : " + arg0.getMessage()).build();
496 notificationPublishService.putNotification(notification);
497 } catch (InterruptedException e) {
498 LOG.info("notification offer rejected : " + e);
500 sendNotifToUrl(notification, notificationUrl);
503 ListenableFuture<PathComputationRequestOutput> pce = mappingAndSendingPCRequest
504 .pathComputationRequest();
505 Futures.addCallback(pce, pceCallback);
506 LOG.info("PCR Request in progress ");
507 configurationResponseCommon = new ConfigurationResponseCommonBuilder()
508 .setAckFinalIndicator("No").setRequestId(input.getSdncRequestHeader().getRequestId())
509 .setResponseMessage("Service compliant, serviceCreate in progress...")
510 .setResponseCode("200").build();
512 ServiceCreateOutputBuilder output = new ServiceCreateOutputBuilder()
513 .setConfigurationResponseCommon(configurationResponseCommon)
514 .setResponseParameters(responseParameters.build());
516 return RpcResultBuilder.success(output.build()).buildFuture();
519 message = txrxCheck.getMessage();
520 responseCode = "500";
523 message = txrxCheck.getMessage();
524 responseCode = "500";
527 message = compliancyCheck.getMessage();
528 responseCode = "500";
531 configurationResponseCommon = new ConfigurationResponseCommonBuilder().setAckFinalIndicator("Yes")
532 .setRequestId(input.getSdncRequestHeader().getRequestId()).setResponseMessage(message)
533 .setResponseCode(responseCode).build();
535 ServiceCreateOutputBuilder output = new ServiceCreateOutputBuilder()
536 .setConfigurationResponseCommon(configurationResponseCommon)
537 .setResponseParameters(responseParameters.build());
539 return RpcResultBuilder.success(output.build()).buildFuture();
544 public Future<RpcResult<ServiceDeleteOutput>> serviceDelete(ServiceDeleteInput input) {
545 LOG.info("RPC serviceDelete request received for Service '" + input.getServiceDeleteReqInfo().getServiceName()
547 notificationUrl = null;// input.getSdncRequestHeader().getnotificationUrl();
549 String responseCode = "";
550 ServiceRpcResult notification = null;
551 ResponseParametersBuilder responseParameters = new ResponseParametersBuilder();
552 LOG.info("checking Service Compliancy ...");
554 * Upon receipt of service-delete RPC, service header and sdnc-request
555 * header compliancy are verified.
557 compliancyCheck = new ServicehandlerCompliancyCheck(input.getSdncRequestHeader(),
558 input.getServiceDeleteReqInfo().getServiceName(), RpcActions.ServiceDelete);
559 if (compliancyCheck.check(false, true)) {
560 LOG.info("Service compliant !");
561 String serviceName = input.getServiceDeleteReqInfo().getServiceName();
562 Services service = readServiceList(serviceName);
563 if (service != null) {
564 LOG.debug("Service '" + serviceName + "' present in datastore !");
566 * If compliant, service-delete order is send to renderer.
568 mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry,
569 input.getSdncRequestHeader().getRequestId(), input.getServiceDeleteReqInfo().getServiceName());
571 notification = new ServiceRpcResultBuilder()
572 .setNotificationType(ServiceNotificationTypes.ServiceDeleteResult).setServiceName(serviceName)
573 .setStatus(RpcStatusEx.Pending)
574 .setStatusMessage("Service compliant, submitting serviceDelete Request ...").build();
576 notificationPublishService.putNotification(notification);
577 } catch (InterruptedException e) {
578 LOG.info("notification offer rejected : " + e);
580 sendNotifToUrl(notification, notificationUrl);
581 FutureCallback<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce
582 .stubrenderer.rev170426.ServiceDeleteOutput> rendererCallback =
583 new FutureCallback<org.opendaylight.yang.gen.v1.http.org.opendaylight
584 .transportpce.stubrenderer.rev170426.ServiceDeleteOutput>() {
586 String responseCode = "";
587 ServiceRpcResult notification = null;
590 public void onFailure(Throwable arg0) {
591 LOG.error("ServiceDelete Request failed !");
592 notification = new ServiceRpcResultBuilder()
593 .setNotificationType(ServiceNotificationTypes.ServiceDeleteResult)
594 .setServiceName(serviceName).setStatus(RpcStatusEx.Failed)
595 .setStatusMessage("ServiceDelete Request failed !").build();
597 notificationPublishService.putNotification(notification);
598 } catch (InterruptedException e) {
599 LOG.info("notification offer rejected : " + e);
601 sendNotifToUrl(notification, notificationUrl);
605 public void onSuccess(org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce
606 .stubrenderer.rev170426.ServiceDeleteOutput arg0) {
608 if (mappingAndSendingPCRequest.getSuccess() && arg0 != null) {
609 message = "Service deleted !";
611 notification = new ServiceRpcResultBuilder()
612 .setNotificationType(ServiceNotificationTypes.ServiceDeleteResult)
613 .setServiceName(input.getServiceDeleteReqInfo().getServiceName())
614 .setStatus(RpcStatusEx.Successful).setStatusMessage("Service deleted !").build();
616 notificationPublishService.putNotification(notification);
617 } catch (InterruptedException e) {
618 LOG.info("notification offer rejected : " + e);
620 sendNotifToUrl(notification, notificationUrl);
623 // result.getConfigurationResponseCommon().getResponseMessage();
624 responseCode = arg0.getConfigurationResponseCommon().getResponseCode();
626 * Service delete confirmed deleting service from
629 if (writeOrModifyOrDeleteServiceList(input.getServiceDeleteReqInfo().getServiceName(), null,
631 /* Service delete. */
632 StringBuilder build = new StringBuilder();
633 build.append(message);
634 build.append(" : Service deleted from database");
635 message = build.toString();
637 StringBuilder build = new StringBuilder();
638 build.append(message);
639 build.append(" but Failed to delete service from database !");
640 message = build.toString();
643 notification = new ServiceRpcResultBuilder()
644 .setNotificationType(ServiceNotificationTypes.ServiceDeleteResult)
645 .setServiceName(input.getServiceDeleteReqInfo().getServiceName())
646 .setStatus(RpcStatusEx.Successful).setStatusMessage(message).build();
648 notificationPublishService.putNotification(notification);
649 } catch (InterruptedException e) {
650 LOG.info("notification offer rejected : " + e);
652 sendNotifToUrl(notification, notificationUrl);
654 message = "deleting service failed";
655 responseCode = "500";
656 notification = new ServiceRpcResultBuilder()
657 .setNotificationType(ServiceNotificationTypes.ServiceDeleteResult)
658 .setServiceName(input.getServiceDeleteReqInfo().getServiceName())
659 .setStatus(RpcStatusEx.Failed).setStatusMessage(message).build();
661 notificationPublishService.putNotification(notification);
662 } catch (InterruptedException e) {
663 LOG.info("notification offer rejected : " + e);
665 sendNotifToUrl(notification, notificationUrl);
669 ListenableFuture<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce
670 .stubrenderer.rev170426.ServiceDeleteOutput> renderer =
671 mappingAndSendingSIRequest.serviceDelete();
672 Futures.addCallback(renderer, rendererCallback);
673 LOG.info("ServiceDelete Request in progress ... ");
674 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
675 .setAckFinalIndicator("No").setRequestId(input.getSdncRequestHeader().getRequestId())
676 .setResponseMessage("ServiceDelete Request in progress ...").setResponseCode("200").build();
677 ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
678 .setConfigurationResponseCommon(configurationResponseCommon).build();
679 return RpcResultBuilder.success(output).buildFuture();
681 message = "Service '" + serviceName + "' not exists in datastore";
686 message = "Service not compliant !";
687 responseCode = "500";
691 * Building output response.
694 ConfigurationResponseCommon configurationResponseCommon = new ConfigurationResponseCommonBuilder()
695 .setAckFinalIndicator("Yes").setRequestId(input.getSdncRequestHeader().getRequestId())
696 .setResponseMessage(message).setResponseCode(responseCode).build();
697 ServiceDeleteOutput output = new ServiceDeleteOutputBuilder()
698 .setConfigurationResponseCommon(configurationResponseCommon).build();
699 return RpcResultBuilder.success(output).buildFuture();
703 public Future<RpcResult<ServiceFeasibilityCheckOutput>> serviceFeasibilityCheck(
704 ServiceFeasibilityCheckInput input) {
705 notificationUrl = null;// input.getSdncRequestHeader().getnotificationUrl();
706 action = RpcActions.ServiceFeasibilityCheck;
707 LOG.info("RPC service feasibilityCheck received");
708 boolean commonId = true;
709 boolean coherencyHardSoft = false;
710 ServiceRpcResult notification = null;
711 String name = "no name";
712 mappingAndSendingPCRequest = null;
714 ConfigurationResponseCommon configurationResponseCommon = null;
716 String responseCode = "";
717 LOG.info("checking Service Compliancy ...");
719 * Upon receipt of service-create RPC, service header and sdnc-request
720 * header compliancy are verified.
722 compliancyCheck = new ServicehandlerCompliancyCheck(input.getSdncRequestHeader(), name,
723 input.getConnectionType(), RpcActions.ServiceFeasibilityCheck);
724 if (compliancyCheck.check(true, true)) {
725 LOG.info("Service compliant !");
727 * If compliant, service-request parameters are verified in order to
728 * check if there is no missing parameter that prevents calculating
729 * a path and implement a service.
731 LOG.info("checking Tx/Rx Info for AEnd ...");
732 txrxCheck = new ServicehandlerTxRxCheck(input.getServiceAEnd(), 1);
733 if (txrxCheck.check()) {
734 LOG.info("Tx/Rx Info for AEnd checked !");
735 LOG.info("checking Tx/Rx Info for ZEnd ...");
736 txrxCheck = new ServicehandlerTxRxCheck(input.getServiceZEnd(), 2);
737 if (txrxCheck.check()) {
738 LOG.info("Tx/Rx Info for ZEnd checked");
740 * If OK, common-id is verified in order to see if there is
741 * no routing policy provided. If yes, the routing
742 * constraints of the policy are recovered and coherency
743 * with hard/soft constraints provided in the input of the
746 if (input.getCommonId() != null) {
747 LOG.info("Common-id specified");
749 * Check coherency with hard/soft constraints
752 checkCoherencyHardSoft = new CheckCoherencyHardSoft(input.getHardConstraints(),
753 input.getSoftConstraints());
754 if (checkCoherencyHardSoft.check()) {
755 LOG.info("hard/soft constraints coherent !");
756 coherencyHardSoft = true;
758 LOG.info("hard/soft constraints are not coherent !");
759 message = "hard/soft constraints are not coherent !";
760 responseCode = "500";
766 if (!commonId || (commonId && coherencyHardSoft)) {
768 * Before sending the PCE request, input data need to be
769 * formatted according to the Service Handler - PCE
770 * interface data model.
772 mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, input, false);
774 * Once PCE request is being sent to the PCE on
775 * interface B, PCE reply is expected until a timer
778 notification = new ServiceRpcResultBuilder()
779 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult).setServiceName(name)
780 .setStatus(RpcStatusEx.Pending)
781 .setStatusMessage("Service compliant, Submitting PathComputation Request ...").build();
783 notificationPublishService.putNotification(notification);
784 } catch (InterruptedException e) {
785 LOG.info("notification offer rejected : " + e);
787 sendNotifToUrl(notification, notificationUrl);
789 FutureCallback<PathComputationRequestOutput> pceCallback =
790 new FutureCallback<PathComputationRequestOutput>() {
792 String responseCode = "";
793 ServiceRpcResult notification = null;
796 public void onFailure(Throwable arg0) {
797 LOG.error("Path not calculated..");
798 notification = new ServiceRpcResultBuilder()
799 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
800 .setServiceName(name).setStatus(RpcStatusEx.Failed)
801 .setStatusMessage("PCR Request failed !").build();
803 notificationPublishService.putNotification(notification);
804 } catch (InterruptedException e) {
805 LOG.info("notification offer rejected : " + e);
807 sendNotifToUrl(notification, notificationUrl);
812 public void onSuccess(PathComputationRequestOutput response) {
814 if (mappingAndSendingPCRequest.getSuccess() && response != null) {
816 * If PCE reply is received before timer
817 * expiration with a positive result, a
818 * service is created with admin and
819 * operational status 'down'.
821 LOG.info("PCE replied to PCR Request !");
822 notification = new ServiceRpcResultBuilder()
823 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
824 .setServiceName("").setStatus(RpcStatusEx.Successful)
825 .setStatusMessage("Service Feasility Checked").build();
827 notificationPublishService.putNotification(notification);
828 } catch (InterruptedException e) {
829 LOG.info("notification offer rejected : " + e);
831 message = response.getConfigurationResponseCommon().getResponseMessage();
832 sendNotifToUrl(notification, notificationUrl);
834 message = mappingAndSendingPCRequest.getError();// "Path
837 responseCode = "500";
838 notification = new ServiceRpcResultBuilder()
839 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
840 .setServiceName("").setStatus(RpcStatusEx.Failed).setStatusMessage(message)
843 notificationPublishService.putNotification(notification);
844 } catch (InterruptedException e) {
845 LOG.info("notification offer rejected : " + e);
847 sendNotifToUrl(notification, notificationUrl);
852 ListenableFuture<PathComputationRequestOutput> pce = mappingAndSendingPCRequest
853 .pathComputationRequest();
854 Futures.addCallback(pce, pceCallback);
855 LOG.info("PCR Request in progress ");
856 configurationResponseCommon = new ConfigurationResponseCommonBuilder()
857 .setAckFinalIndicator("No").setRequestId(input.getSdncRequestHeader().getRequestId())
858 .setResponseMessage("Service compliant, ServiceFeasibilityCheck in progress...")
859 .setResponseCode("200").build();
861 ServiceFeasibilityCheckOutput output = new ServiceFeasibilityCheckOutputBuilder()
862 .setConfigurationResponseCommon(configurationResponseCommon).build();
864 return RpcResultBuilder.success(output).buildFuture();
868 message = txrxCheck.getMessage();
869 responseCode = "500";
872 message = txrxCheck.getMessage();
873 responseCode = "500";
876 message = compliancyCheck.getMessage();
877 responseCode = "500";
880 configurationResponseCommon = new ConfigurationResponseCommonBuilder().setAckFinalIndicator("Yes")
881 .setRequestId(input.getSdncRequestHeader().getRequestId()).setResponseMessage(message)
882 .setResponseCode(responseCode).build();
884 ResponseParameters responseParameters = new ResponseParametersBuilder()
885 .setHardConstraints(input.getHardConstraints())
886 // .setPceMetric(input.getPceMetric())
887 .setSoftConstraints(input.getSoftConstraints())
888 // .setLocallyProtectedLinks(input.isLocallyProtectedLinks())
891 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.service.feasibility
892 .check.output.ServiceAEnd serviceAEnd = new org.opendaylight.yang.gen.v1.http.org.opendaylight
893 .transportpce.servicehandler.rev161014.service.feasibility
894 .check.output.ServiceAEndBuilder(input.getServiceAEnd()).build();
896 org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.servicehandler.rev161014.service.feasibility
897 .check.output.ServiceZEnd serviceZEnd = new org.opendaylight.yang.gen.v1.http.org.opendaylight
898 .transportpce.servicehandler.rev161014.service.feasibility
899 .check.output.ServiceZEndBuilder(input.getServiceZEnd()).build();
902 Port txPort = new PortBuilder().setPortDeviceName("ROUTER_SNJSCAMCJW1_000000.00_00").setPortType("router")
903 .setPortName("Gigabit Ethernet_Tx.ge-1/0/0.0").setPortRack("000000.00").setPortShelf("00").build();
904 Lgx txLgx = new LgxBuilder().setLgxDeviceName("LGX Panel_SNJSCAMCJW1_000000.00_00")
905 .setLgxPortName("LGX_Back.23").setLgxPortRack("000000.00").setLgxPortShelf("00").build();
906 TxDirection txDirection = new TxDirectionBuilder().setPort(txPort).setLgx(txLgx).build();
909 Port rxPort = new PortBuilder().setPortDeviceName("ROUTER_SNJSCAMCJW1_000000.00_00").setPortType("router")
910 .setPortName("Gigabit Ethernet_Rx.ge-1/0/0.0").setPortRack("000000.00").setPortShelf("00").build();
911 Lgx rxLgx = new LgxBuilder().setLgxDeviceName("LGX Panel_SNJSCAMCJW1_000000.00_00").setLgxPortName("LGX_Back.6")
912 .setLgxPortRack("000000.00").setLgxPortShelf("00").build();
913 RxDirection rxDirection = new RxDirectionBuilder().setPort(rxPort).setLgx(rxLgx).build();
915 IntermediateSites inter = new IntermediateSitesBuilder().setClli("SNJSCAMCJW1").setServiceRate((long) 100)
916 .setServiceFormat(ServiceFormat.Ethernet).setOpticType(OpticTypes.Gray).setTxDirection(txDirection)
917 .setRxDirection(rxDirection).build();
919 List<IntermediateSites> intersites = new ArrayList<IntermediateSites>();
920 intersites.add(inter);
921 ServiceFeasibilityCheckOutput output = new ServiceFeasibilityCheckOutputBuilder()
922 .setIntermediateSites(intersites).setResponseParameters(responseParameters)
923 .setConfigurationResponseCommon(configurationResponseCommon).setServiceAEnd(serviceAEnd)
924 .setServiceZEnd(serviceZEnd).build();
926 return RpcResultBuilder.success(output).buildFuture();
930 public Future<RpcResult<ServiceReconfigureOutput>> serviceReconfigure(ServiceReconfigureInput input) {
932 LOG.info("RPC service reconfigure received");
933 notificationUrl = null;// input.getnotificationUrl();
934 boolean commonId = true;
935 boolean coherencyHardSoft = false;
936 ServiceRpcResult notification = null;
939 LOG.info("checking Service Compliancy ...");
941 * Upon receipt of service-create RPC, service header and sdnc-request
942 * header compliancy are verified.
944 compliancyCheck = new ServicehandlerCompliancyCheck(input.getServiceName(), input.getConnectionType(),
945 RpcActions.ServiceReconfigure);
946 if (compliancyCheck.check(true, false)) {
947 LOG.info("Service compliant !");
949 * If compliant, service-request parameters are verified in order to
950 * check if there is no missing parameter that prevents calculating
951 * a path and implement a service.
953 LOG.info("checking Tx/Rx Info for AEnd ...");
954 txrxCheck = new ServicehandlerTxRxCheck(input.getServiceAEnd(), 1);
955 if (txrxCheck.check()) {
956 LOG.info("Tx/Rx Info for AEnd checked !");
957 LOG.info("checking Tx/Rx Info for ZEnd ...");
958 txrxCheck = new ServicehandlerTxRxCheck(input.getServiceZEnd(), 2);
959 if (txrxCheck.check()) {
960 LOG.info("Tx/Rx Info for ZEnd checked");
962 * If OK, common-id is verified in order to see if there is
963 * no routing policy provided. If yes, the routing
964 * constraints of the policy are recovered and coherency
965 * with hard/soft constraints provided in the input of the
968 if (input.getCommonId() != null) {
969 LOG.info("Common-id specified");
971 * Check coherency with hard/soft constraints
974 checkCoherencyHardSoft = new CheckCoherencyHardSoft(input.getHardConstraints(),
975 input.getSoftConstraints());
976 if (checkCoherencyHardSoft.check()) {
977 LOG.info("hard/soft constraints coherent !");
978 coherencyHardSoft = true;
980 LOG.info("hard/soft constraints are not coherent !");
981 message = "hard/soft constraints are not coherent !";
987 if (!commonId || (commonId && coherencyHardSoft)) {
989 * Retrieving initial service topology.
991 String serviceName = input.getServiceName();
992 Services service = readServiceList(serviceName);
993 if (service != null) {
994 LOG.debug("Service '" + serviceName + "' present in datastore !");
996 * Sending cancel resource resv request to PCE
999 mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, input, false);
1000 notification = new ServiceRpcResultBuilder()
1001 .setNotificationType(ServiceNotificationTypes.ServiceReconfigureResult)
1002 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1003 .setStatusMessage("Cancelling ResourceResv ...").build();
1005 notificationPublishService.putNotification(notification);
1006 } catch (InterruptedException e) {
1007 LOG.info("notification offer rejected : " + e);
1009 sendNotifToUrl(notification, notificationUrl);
1010 FutureCallback<CancelResourceReserveOutput> pceCallback =
1011 new FutureCallback<CancelResourceReserveOutput>() {
1012 String message = "";
1013 String responseCode = "";
1014 ServiceRpcResult notification = null;
1017 public void onFailure(Throwable arg0) {
1018 LOG.error("Failed to cancel ResourceResv ! ");
1019 notification = new ServiceRpcResultBuilder()
1020 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
1021 .setServiceName(serviceName).setStatus(RpcStatusEx.Failed)
1022 .setStatusMessage("PCR Request failed !").build();
1024 notificationPublishService.putNotification(notification);
1025 } catch (InterruptedException e) {
1026 LOG.info("notification offer rejected : " + e);
1032 public void onSuccess(CancelResourceReserveOutput arg0) {
1033 if (mappingAndSendingPCRequest.getSuccess() && arg0 != null) {
1034 LOG.info("Service ResourceResv cancelled !");
1035 notification = new ServiceRpcResultBuilder()
1036 .setNotificationType(ServiceNotificationTypes.ServiceReconfigureResult)
1037 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1039 "Service '" + serviceName + "' ResourceResv cancelled")
1042 notificationPublishService.putNotification(notification);
1043 } catch (InterruptedException e) {
1044 LOG.info("notification offer rejected : " + e);
1046 sendNotifToUrl(notification, notificationUrl);
1048 message = "Service '" + serviceName + "' ResourceResv cancelled";
1050 LOG.info("PCE replied to CancelResourceResv Request !");
1052 * Before sending the PCE request, input
1053 * data need to be formatted according
1054 * to the Service Handler - PCE
1055 * interface data model.
1057 mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, input,
1060 * Once PCE request is being sent to the
1061 * PCE on interface B, PCE reply is
1062 * expected until a timer expires.
1064 notification = new ServiceRpcResultBuilder()
1065 .setNotificationType(ServiceNotificationTypes.ServiceReconfigureResult)
1066 .setServiceName(serviceName).setStatus(RpcStatusEx.Pending)
1067 .setStatusMessage(message + ", submitting PathComputation Request ...")
1070 notificationPublishService.putNotification(notification);
1071 } catch (InterruptedException e) {
1072 LOG.info("notification offer rejected : " + e);
1074 sendNotifToUrl(notification, notificationUrl);
1075 PathComputationRequestOutput response = null;
1077 response = mappingAndSendingPCRequest.pathComputationRequest().get();
1078 } catch (InterruptedException | ExecutionException e2) {
1079 LOG.error(e2.getMessage());
1082 if (mappingAndSendingPCRequest.getSuccess() && response != null) {
1084 * If PCE reply is received before
1085 * timer expiration with a positive
1086 * result, a service is created with
1087 * admin and operational status
1090 LOG.info("PCE replied to PCR Request !");
1091 message = response.getConfigurationResponseCommon().getResponseMessage();
1092 notification = new ServiceRpcResultBuilder()
1093 .setNotificationType(
1094 ServiceNotificationTypes.ServiceReconfigureResult)
1095 .setServiceName(serviceName).setStatus(RpcStatusEx.Pending)
1096 .setStatusMessage("PCE replied to PCR Request !").build();
1098 notificationPublishService.putNotification(notification);
1099 } catch (InterruptedException e) {
1100 LOG.info("notification offer rejected : " + e);
1102 sendNotifToUrl(notification, notificationUrl);
1104 * Send Implementation order to
1107 mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry,
1110 notification = new ServiceRpcResultBuilder()
1111 .setNotificationType(
1112 ServiceNotificationTypes.ServiceReconfigureResult)
1113 .setServiceName(input.getServiceName())
1114 .setStatus(RpcStatusEx.Pending)
1115 .setStatusMessage("Submitting ServiceImplementation Request ...")
1118 notificationPublishService.putNotification(notification);
1119 } catch (InterruptedException e) {
1120 LOG.info("notification offer rejected : " + e);
1122 sendNotifToUrl(notification, notificationUrl);
1124 ServiceImplementationRequestOutput siOutput = null;
1126 siOutput = mappingAndSendingSIRequest.serviceImplementation().get();
1127 } catch (InterruptedException | ExecutionException e2) {
1128 LOG.error(e2.getMessage());
1130 ConfigurationResponseCommon siCommon = siOutput
1131 .getConfigurationResponseCommon();
1132 message = siCommon.getResponseMessage();
1134 if (mappingAndSendingSIRequest.getSuccess() && siOutput != null) {
1135 message = "Service reconfigured ";
1136 LOG.info("Service reconfigured !");
1137 notification = new ServiceRpcResultBuilder()
1138 .setNotificationType(
1139 ServiceNotificationTypes.ServiceReconfigureResult)
1140 .setServiceName(input.getServiceName())
1141 .setStatus(RpcStatusEx.Pending)
1142 .setStatusMessage("Service reconfigure !").build();
1144 notificationPublishService.putNotification(notification);
1145 } catch (InterruptedException e) {
1146 LOG.info("notification offer rejected : " + e);
1148 sendNotifToUrl(notification, notificationUrl);
1150 * Service implemented Update in
1153 Boolean update = false;
1154 Boolean delete = false;
1155 Services modifService = mappingServices(null, input, response);
1156 InstanceIdentifier<Services> iid = InstanceIdentifier
1157 .create(ServiceList.class)
1158 .child(Services.class, new ServicesKey(serviceName));
1159 WriteTransaction writeTx = db.newWriteOnlyTransaction();
1160 writeTx.delete(LogicalDatastoreType.OPERATIONAL, iid);
1162 LOG.info("Deleting service info ...");
1163 writeTx.submit().checkedGet();
1165 } catch (TransactionCommitFailedException e) {
1166 LOG.error("Failed to delete service from Service List");
1169 iid = InstanceIdentifier.create(ServiceList.class).child(
1170 Services.class, new ServicesKey(input.getNewServiceName()));
1171 writeTx = db.newWriteOnlyTransaction();
1172 writeTx.put(LogicalDatastoreType.OPERATIONAL, iid, modifService);
1174 LOG.info("Updating service info ...");
1175 writeTx.submit().checkedGet();
1177 } catch (TransactionCommitFailedException e) {
1178 LOG.error("Failed to modify service from Service List");
1182 LOG.info("Service '" + serviceName + "' updated with new name '"
1183 + input.getNewServiceName() + "' ! ");
1184 StringBuilder build = new StringBuilder();
1185 build.append(message);
1186 build.append(" : Service updated on DataBase !");
1187 message = build.toString();
1189 LOG.info("Service '" + serviceName + "' update failed ! ");
1190 StringBuilder build = new StringBuilder();
1191 build.append(message);
1192 build.append(" : Failed to modify service from Service List ");
1193 message = build.toString();
1196 LOG.info("Service not implemented !");
1197 message = response.getConfigurationResponseCommon()
1198 .getResponseMessage();
1199 notification = new ServiceRpcResultBuilder()
1200 .setNotificationType(
1201 ServiceNotificationTypes.ServiceReconfigureResult)
1202 .setServiceName(input.getServiceName())
1203 .setStatus(RpcStatusEx.Failed)
1205 "Service not implemented, cancelling ResourceResv")
1208 notificationPublishService.putNotification(notification);
1209 } catch (InterruptedException e) {
1210 LOG.info("notification offer rejected : " + e);
1212 sendNotifToUrl(notification, notificationUrl);
1213 mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry,
1216 * Send Cancel resource Request
1219 CancelResourceReserveOutput cancelOuptut = null;
1221 cancelOuptut = mappingAndSendingPCRequest.cancelResourceReserve()
1223 } catch (InterruptedException | ExecutionException e1) {
1224 LOG.error(e1.getMessage());
1226 if (mappingAndSendingPCRequest.getSuccess() && cancelOuptut != null) {
1227 LOG.info("Service ResourceResv cancelled !");
1228 message = response.getConfigurationResponseCommon()
1229 .getResponseMessage();
1230 notification = new ServiceRpcResultBuilder()
1231 .setNotificationType(
1232 ServiceNotificationTypes.ServiceReconfigureResult)
1233 .setServiceName(input.getServiceName())
1234 .setStatus(RpcStatusEx.Failed)
1235 .setStatusMessage("Service ResourceResv cancelled").build();
1237 notificationPublishService.putNotification(notification);
1238 } catch (InterruptedException e) {
1239 LOG.info("notification offer rejected : " + e);
1241 sendNotifToUrl(notification, notificationUrl);
1243 message = cancelOuptut.getConfigurationResponseCommon()
1244 .getResponseMessage();
1246 StringBuilder build = new StringBuilder();
1247 build.append("Service not implemented - ");
1248 build.append(message);
1249 message = build.toString();
1251 LOG.info("PCE replied to CancelResourceResv Request !");
1253 message = "Cancelling Resource reserved failed ";
1255 StringBuilder build = new StringBuilder();
1256 build.append("Service not implemented - ");
1257 build.append(message);
1258 message = build.toString();
1260 message = response.getConfigurationResponseCommon()
1261 .getResponseMessage();
1262 notification = new ServiceRpcResultBuilder()
1263 .setNotificationType(
1264 ServiceNotificationTypes.ServiceReconfigureResult)
1265 .setServiceName(input.getServiceName())
1266 .setStatus(RpcStatusEx.Failed)
1267 .setStatusMessage("Cancelling Resource reserved failed")
1270 notificationPublishService.putNotification(notification);
1271 } catch (InterruptedException e) {
1272 LOG.info("notification offer rejected : " + e);
1274 sendNotifToUrl(notification, notificationUrl);
1279 LOG.error("PCE pathcomputation request failed !");
1280 message = "PCE pathcomputation request failed : "
1281 + mappingAndSendingPCRequest.getError();// "Path
1286 message = "Cancelling Resource reserved failed ";
1288 StringBuilder build = new StringBuilder();
1289 build.append("Service not implemented - ");
1290 build.append(message);
1291 message = build.toString();
1293 notification = new ServiceRpcResultBuilder()
1294 .setNotificationType(ServiceNotificationTypes.ServiceReconfigureResult)
1295 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
1296 .setStatusMessage("Cancelling Resource reserved failed").build();
1298 notificationPublishService.putNotification(notification);
1299 } catch (InterruptedException e) {
1300 LOG.info("notification offer rejected : " + e);
1302 sendNotifToUrl(notification, notificationUrl);
1307 ListenableFuture<CancelResourceReserveOutput> pce = mappingAndSendingPCRequest
1308 .cancelResourceReserve();
1309 Futures.addCallback(pce, pceCallback);
1310 LOG.info("CancelResRev Request in progress ");
1311 ServiceReconfigureOutput output = new ServiceReconfigureOutputBuilder()
1312 .setStatus(RpcStatusEx.Pending).setStatusMessage(message).build();
1314 return RpcResultBuilder.success(output).buildFuture();
1317 message = "Service '" + serviceName + "' not exists in datastore";
1322 message = txrxCheck.getMessage();
1325 message = txrxCheck.getMessage();
1328 message = compliancyCheck.getMessage();
1331 ServiceReconfigureOutput output = new ServiceReconfigureOutputBuilder().setStatus(RpcStatusEx.Successful)
1332 .setStatusMessage(message).build();
1334 return RpcResultBuilder.success(output).buildFuture();
1338 public Future<RpcResult<ServiceRestorationOutput>> serviceRestoration(ServiceRestorationInput input) {
1339 LOG.info("RPC service restoration received");
1340 ServiceRpcResult notification = null;
1341 notificationUrl = null;// input.getnotificationUrl();
1342 String message = "";
1343 LOG.info("checking Service Compliancy ...");
1344 compliancyCheck = new ServicehandlerCompliancyCheck(input.getServiceName(), RpcActions.ServiceRestoration);
1345 if (compliancyCheck.check(false, false)) {
1346 LOG.info("Service compliant !");
1348 * If compliant, Getting path from service DB.
1351 String serviceName = input.getServiceName();
1352 Services service = readServiceList(serviceName);
1353 if (service != null) {
1354 LOG.debug("Service '" + serviceName + "' present in datastore !");
1355 notification = new ServiceRpcResultBuilder()
1356 .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1357 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1358 .setStatusMessage("Service '" + serviceName + "' present in datastore, deleting service ...")
1361 notificationPublishService.putNotification(notification);
1362 } catch (InterruptedException e) {
1363 LOG.info("notification offer rejected : " + e);
1365 sendNotifToUrl(notification, notificationUrl);
1367 * Sending delete order to renderer
1369 mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry, null, input.getServiceName());
1371 ListenableFuture<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce
1372 .stubrenderer.rev170426.ServiceDeleteOutput> renderer =
1373 mappingAndSendingSIRequest.serviceDelete();
1374 FutureCallback<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce
1375 .stubrenderer.rev170426.ServiceDeleteOutput> rendererCallback =
1376 new FutureCallback<org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce
1377 .stubrenderer.rev170426.ServiceDeleteOutput>() {
1378 String message = "";
1379 String responseCode = "";
1380 ServiceRpcResult notification = null;
1383 public void onFailure(Throwable arg0) {
1384 LOG.error("ServiceDelete Request failed !");
1385 notification = new ServiceRpcResultBuilder()
1386 .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1387 .setServiceName(serviceName).setStatus(RpcStatusEx.Failed)
1388 .setStatusMessage("ServiceDelete Request failed !").build();
1390 notificationPublishService.putNotification(notification);
1391 } catch (InterruptedException e) {
1392 LOG.info("notification offer rejected : " + e);
1394 sendNotifToUrl(notification, notificationUrl);
1398 public void onSuccess(org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce
1399 .stubrenderer.rev170426.ServiceDeleteOutput arg0) {
1401 message = arg0.getConfigurationResponseCommon().getResponseMessage();
1402 notification = new ServiceRpcResultBuilder()
1403 .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1404 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1405 .setStatusMessage("Service deleted !").build();
1407 notificationPublishService.putNotification(notification);
1408 } catch (InterruptedException e) {
1409 LOG.info("notification offer rejected : " + e);
1411 sendNotifToUrl(notification, notificationUrl);
1412 mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry, service, true);
1414 * Once PCE request is being sent to the PCE on
1415 * interface B, PCE reply is expected until a timer
1418 notification = new ServiceRpcResultBuilder()
1419 .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1420 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1421 .setStatusMessage("Service deleted, submitting PathComputation Request ...")
1424 notificationPublishService.putNotification(notification);
1425 } catch (InterruptedException e) {
1426 LOG.info("notification offer rejected : " + e);
1428 sendNotifToUrl(notification, notificationUrl);
1429 PathComputationRequestOutput response = null;
1431 response = mappingAndSendingPCRequest.pathComputationRequest().get();
1432 } catch (InterruptedException | ExecutionException e2) {
1433 LOG.error(e2.getMessage());
1436 if (mappingAndSendingPCRequest.getSuccess() && response != null) {
1438 * If PCE reply is received before timer
1439 * expiration with a positive result, a service
1440 * is created with admin and operational status
1443 LOG.info("Path calculated !");
1444 message = response.getConfigurationResponseCommon().getResponseMessage();
1445 notification = new ServiceRpcResultBuilder()
1446 .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1447 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1448 .setStatusMessage("Path calculated, modifying Service Admin / Op ...").build();
1450 notificationPublishService.putNotification(notification);
1451 } catch (InterruptedException e) {
1452 LOG.info("notification offer rejected : " + e);
1454 sendNotifToUrl(notification, notificationUrl);
1457 * creating Service with Admin / Op to down.
1461 ServicesBuilder serviceRestoration = new ServicesBuilder(service)
1462 .setAdministrativeState(State.OutOfService)
1463 .setOperationalState(State.OutOfService)
1464 .setLifecycleState(LifecycleState.Planned);
1466 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
1467 .service.types.rev170426.response
1468 .parameters.sp.ResponseParameters responseParameters =
1469 response.getResponseParameters();
1470 if (responseParameters != null) {
1471 // serviceRestoration.setPceMetric(responseParameters.getPceMetric());
1472 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
1473 .service.types.rev170426.response.parameters.sp.response
1474 .parameters.PathDescription pathDescription =
1475 responseParameters.getPathDescription();
1476 if (pathDescription != null) {
1477 List<AToZ> atozList = new ArrayList<AToZ>();
1478 List<ZToA> ztoaList = new ArrayList<ZToA>();
1480 for (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
1481 .pathdescription.rev170426.path.description.atoz.direction.AToZ
1482 tmp : pathDescription.getAToZDirection().getAToZ()) {
1484 AToZKey key = new AToZKey(tmp.getKey().getId());
1485 tmp.getResource().getResource();
1486 AToZ atoz = new AToZBuilder().setId(tmp.getId()).setKey(key)
1487 // .setResource(tmp.getResource())
1492 for (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface
1493 .pathdescription.rev170426.path.description.ztoa.direction.ZToA
1494 tmp : pathDescription.getZToADirection().getZToA()) {
1495 ZToAKey key = new ZToAKey(tmp.getKey().getId());
1496 ZToA ztoa = new ZToABuilder().setId(tmp.getId()).setKey(key)
1497 // .setResource(tmp.getResource())
1501 Topology topology = new TopologyBuilder().setAToZ(atozList).setZToA(ztoaList)
1503 serviceRestoration.setTopology(topology);
1506 Boolean update = false;
1507 InstanceIdentifier<Services> iid = InstanceIdentifier.create(ServiceList.class)
1508 .child(Services.class, new ServicesKey(serviceName));
1509 WriteTransaction writeTx = db.newWriteOnlyTransaction();
1510 writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, service);
1513 writeTx.submit().checkedGet();
1515 } catch (TransactionCommitFailedException e) {
1516 LOG.error("Failed to modify service from Service List");
1519 LOG.info("Service modified !");
1521 * Send Implementation order to renderer
1523 mappingAndSendingSIRequest = new MappingAndSendingSIRequest(rpcRegistry, service);
1525 notification = new ServiceRpcResultBuilder()
1526 .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1527 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1529 "Service modified, submitting ServiceImplementation Request")
1532 notificationPublishService.putNotification(notification);
1533 } catch (InterruptedException e) {
1534 LOG.info("notification offer rejected : " + e);
1536 sendNotifToUrl(notification, notificationUrl);
1538 ServiceImplementationRequestOutput siOutput = null;
1540 siOutput = mappingAndSendingSIRequest.serviceImplementation().get();
1541 } catch (InterruptedException | ExecutionException e2) {
1542 LOG.error(e2.getMessage());
1544 if (mappingAndSendingSIRequest.getSuccess() && siOutput != null) {
1545 ConfigurationResponseCommon siCommon = siOutput
1546 .getConfigurationResponseCommon();
1547 message = siCommon.getResponseMessage();
1548 LOG.info("Service restored !");
1549 notification = new ServiceRpcResultBuilder()
1550 .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1551 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Pending)
1552 .setStatusMessage("Service restored !").build();
1554 notificationPublishService.putNotification(notification);
1555 } catch (InterruptedException e) {
1556 LOG.info("notification offer rejected : " + e);
1558 sendNotifToUrl(notification, notificationUrl);
1560 * Service implemented setting Service
1563 if (writeOrModifyOrDeleteServiceList(serviceName, null, null, 0) == null) {
1564 message = "Service restored : Service Op Status changed to Up !";
1566 message = "Service restored : "
1567 + "but Failed to modify service from Service List !";
1570 LOG.info("Service not restored !");
1571 message = response.getConfigurationResponseCommon().getResponseMessage();
1572 notification = new ServiceRpcResultBuilder()
1573 .setNotificationType(ServiceNotificationTypes.ServiceRestorationResult)
1574 .setServiceName(input.getServiceName()).setStatus(RpcStatusEx.Failed)
1575 .setStatusMessage("Service not restored, cancelling ResourceResv ...")
1578 notificationPublishService.putNotification(notification);
1579 } catch (InterruptedException e) {
1580 LOG.info("notification offer rejected : " + e);
1582 sendNotifToUrl(notification, notificationUrl);
1583 mappingAndSendingPCRequest = new MappingAndSendingPCRequest(rpcRegistry,
1586 * Send Cancel resource Request to PCE.
1588 CancelResourceReserveOutput cancelOuptut = null;
1590 cancelOuptut = mappingAndSendingPCRequest.cancelResourceReserve().get();
1591 } catch (InterruptedException | ExecutionException e1) {
1592 LOG.error(e1.getMessage());
1594 if (mappingAndSendingPCRequest.getSuccess() && cancelOuptut != null) {
1595 LOG.info("Service ResourceResv cancelled !");
1596 message = response.getConfigurationResponseCommon().getResponseMessage();
1597 notification = new ServiceRpcResultBuilder()
1598 .setNotificationType(
1599 ServiceNotificationTypes.ServiceRestorationResult)
1600 .setServiceName(input.getServiceName())
1601 .setStatus(RpcStatusEx.Pending)
1602 .setStatusMessage("Service ResourceResv cancelled").build();
1604 notificationPublishService.putNotification(notification);
1605 } catch (InterruptedException e) {
1606 LOG.info("notification offer rejected : " + e);
1608 sendNotifToUrl(notification, notificationUrl);
1609 message = cancelOuptut.getConfigurationResponseCommon()
1610 .getResponseMessage();
1611 StringBuilder build = new StringBuilder();
1612 build.append("Service not implemented - ");
1613 build.append(message);
1614 message = build.toString();
1615 LOG.info("PCE replied to CancelResourceResv Request !");
1617 message = "Cancelling Resource reserved failed ";
1619 StringBuilder build = new StringBuilder();
1620 build.append("Service not implemented - ");
1621 build.append(message);
1622 message = build.toString();
1623 message = response.getConfigurationResponseCommon().getResponseMessage();
1624 notification = new ServiceRpcResultBuilder()
1625 .setNotificationType(ServiceNotificationTypes.ServiceCreateResult)
1626 .setServiceName(input.getServiceName())
1627 .setStatus(RpcStatusEx.Failed)
1628 .setStatusMessage("Cancelling Resource reserved failed").build();
1630 notificationPublishService.putNotification(notification);
1631 } catch (InterruptedException e) {
1632 LOG.info("notification offer rejected : " + e);
1634 sendNotifToUrl(notification, notificationUrl);
1638 LOG.error("Failed to modify service from service list !");
1641 message = mappingAndSendingPCRequest.getError();
1642 /* Path not calculated. */
1643 LOG.error("Path Computation request failed : " + message);
1646 message = "deleting service failed";
1651 Futures.addCallback(renderer, rendererCallback);
1652 ServiceRestorationOutput output = new ServiceRestorationOutputBuilder().setStatus(RpcStatusEx.Pending)
1653 .setStatusMessage(message).build();
1655 return RpcResultBuilder.success(output).buildFuture();
1658 message = "Service '" + serviceName + "' not exists in datastore";
1663 message = compliancyCheck.getMessage();
1667 ServiceRestorationOutput output = new ServiceRestorationOutputBuilder().setStatus(RpcStatusEx.Successful)
1668 .setStatusMessage(message).build();
1670 return RpcResultBuilder.success(output).buildFuture();
1674 * Initialize ServiceList Structure on Datastore.
1679 private void initializeDataTree(DataBroker db) {
1680 LOG.info("Preparing to initialize the greeting registry");
1681 WriteTransaction transaction = db.newWriteOnlyTransaction();
1682 InstanceIdentifier<ServiceList> iid = InstanceIdentifier.create(ServiceList.class);
1683 ServiceList greetingRegistry = new ServiceListBuilder().build();
1684 transaction.put(LogicalDatastoreType.OPERATIONAL, iid, greetingRegistry);
1685 CheckedFuture<Void, TransactionCommitFailedException> future = transaction.submit();
1686 Futures.addCallback(future, new LoggingFuturesCallBack<>("Failed to create Service List", LOG));
1690 * Map Input (ServiceCreateInmput, ServiceReconfigureInput) & output
1691 * (PathComputationRequestOutput) to Service.
1693 * @param serviceCreateInput
1694 * ServiceCreateInput parameter
1695 * @param serviceReconfigureInput
1696 * serviceReconfigureInput parameter
1698 * PathComputationRequestOutput parameter
1700 * @return Services Service data
1702 private Services mappingServices(ServiceCreateInput serviceCreateInput,
1703 ServiceReconfigureInput serviceReconfigureInput, PathComputationRequestOutput output) {
1704 LOG.info("Mapping informations to Services");
1705 ServiceAEnd aend = null;
1706 ServiceZEnd zend = null;
1707 ServicesBuilder service = new ServicesBuilder();
1708 if (serviceCreateInput != null) {
1709 aend = new ServiceAEndBuilder(serviceCreateInput.getServiceAEnd()).build();
1710 zend = new ServiceZEndBuilder(serviceCreateInput.getServiceZEnd()).build();
1711 service.setServiceName(serviceCreateInput.getServiceName()).setAdministrativeState(State.OutOfService)
1712 .setOperationalState(State.OutOfService).setCommonId(serviceCreateInput.getCommonId())
1713 .setConnectionType(serviceCreateInput.getConnectionType())
1714 .setCustomer(serviceCreateInput.getCustomer())
1715 .setCustomerContact(serviceCreateInput.getCustomerContact())
1716 .setHardConstraints(serviceCreateInput.getHardConstraints())
1717 .setSoftConstraints(serviceCreateInput.getSoftConstraints())
1718 .setLifecycleState(LifecycleState.Planned).setServiceAEnd(aend).setServiceZEnd(zend);
1720 } else if (serviceReconfigureInput != null) {
1721 aend = new ServiceAEndBuilder(serviceReconfigureInput.getServiceAEnd()).build();
1722 zend = new ServiceZEndBuilder(serviceReconfigureInput.getServiceZEnd()).build();
1723 service.setServiceName(serviceReconfigureInput.getNewServiceName())
1724 .setAdministrativeState(State.OutOfService).setOperationalState(State.OutOfService)
1725 .setCommonId(serviceReconfigureInput.getCommonId())
1726 .setConnectionType(serviceReconfigureInput.getConnectionType())
1727 .setCustomer(serviceReconfigureInput.getCustomer())
1728 .setCustomerContact(serviceReconfigureInput.getCustomerContact())
1729 .setHardConstraints(serviceReconfigureInput.getHardConstraints())
1730 .setSoftConstraints(serviceReconfigureInput.getSoftConstraints())
1731 .setLifecycleState(LifecycleState.Planned).setServiceAEnd(aend).setServiceZEnd(zend);
1734 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.response
1735 .parameters.sp.ResponseParameters responseParameters = output.getResponseParameters();
1736 if (responseParameters != null) {
1737 // service.setPceMetric(responseParameters.getPceMetric());
1738 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426
1739 .response.parameters.sp.response.parameters.PathDescription pathDescription =
1740 responseParameters.getPathDescription();
1741 if (pathDescription != null) {
1742 List<AToZ> atozList = new ArrayList<AToZ>();
1743 List<ZToA> ztoaList = new ArrayList<ZToA>();
1745 for (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426
1746 .path.description.atoz.direction.AToZ
1747 tmp : pathDescription.getAToZDirection().getAToZ()) {
1749 AToZKey key = new AToZKey(tmp.getKey().getId());
1750 AToZ atoz = new AToZBuilder().setId(tmp.getId()).setKey(key)
1751 // .setResource(tmp.getResource())
1756 for (org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426
1757 .path.description.ztoa.direction.ZToA
1758 tmp : pathDescription.getZToADirection().getZToA()) {
1759 ZToAKey key = new ZToAKey(tmp.getKey().getId());
1760 ZToA ztoa = new ZToABuilder().setId(tmp.getId()).setKey(key)
1761 // .setResource(tmp.getResource())
1766 Topology topology = new TopologyBuilder().setAToZ(atozList).setZToA(ztoaList).build();
1767 service.setTopology(topology);
1770 return service.build();
1774 * read Service from ServiceList DataStore.
1776 * @param serviceName
1779 * @return <code>Services</code>
1781 private Services readServiceList(String serviceName) {
1782 Services result = null;
1783 ReadOnlyTransaction readTx = db.newReadOnlyTransaction();
1784 InstanceIdentifier<Services> iid = InstanceIdentifier.create(ServiceList.class).child(Services.class,
1785 new ServicesKey(serviceName));
1786 CheckedFuture<Optional<Services>, ReadFailedException> future = readTx.read(LogicalDatastoreType.OPERATIONAL,
1788 Optional<Services> optional = Optional.absent();
1790 optional = future.checkedGet();
1791 } catch (ReadFailedException e) {
1792 LOG.error("Reading service failed:", e);
1794 if (optional.isPresent()) {
1795 LOG.debug("Service '" + serviceName + "' present !");
1796 result = new ServicesBuilder(optional.get()).build();
1802 * Write or Modify or Delete Service from/to SreviceList.
1804 * @param serviceName
1807 * ServiceCreateInput
1809 * PathComputationRequestOutput
1811 * 0 - Modify 1 - Delete 2 - Write
1812 * @return String operations result, null if ok or not otherwise
1814 private String writeOrModifyOrDeleteServiceList(String serviceName, ServiceCreateInput input,
1815 PathComputationRequestOutput output, int choice) {
1816 LOG.debug("WriteOrModifyOrDeleting '" + serviceName + "' Service");
1817 WriteTransaction writeTx = db.newWriteOnlyTransaction();
1818 String result = null;
1819 Services readService = readServiceList(serviceName);
1820 if (readService != null) {
1822 * Modify / Delete Service.
1824 InstanceIdentifier<Services> iid = InstanceIdentifier.create(ServiceList.class).child(Services.class,
1825 new ServicesKey(serviceName));
1826 ServicesBuilder service = new ServicesBuilder(readService);
1828 String action = null;
1830 case 0: /* Modify. */
1831 LOG.debug("Modifying '" + serviceName + "' Service");
1832 service.setOperationalState(State.InService).setAdministrativeState(State.InService);
1833 writeTx.merge(LogicalDatastoreType.OPERATIONAL, iid, service.build());
1837 case 1: /* Delete */
1838 LOG.debug("Deleting '" + serviceName + "' Service");
1839 writeTx.delete(LogicalDatastoreType.OPERATIONAL, iid);
1844 LOG.debug("No choice found");
1849 writeTx.submit().checkedGet();
1850 } catch (TransactionCommitFailedException e) {
1851 LOG.error("Failed to " + action + " service from Service List");
1852 result = "Failed to " + action + " service from Service List";
1855 if (choice == 2) { /* Write Service */
1856 LOG.debug("Writing '" + serviceName + "' Service");
1857 InstanceIdentifier<Services> iid = InstanceIdentifier.create(ServiceList.class).child(Services.class,
1858 new ServicesKey(serviceName));
1860 Services service = mappingServices(input, null, output);
1861 writeTx.put(LogicalDatastoreType.OPERATIONAL, iid, service);
1863 writeTx.submit().checkedGet();
1865 } catch (TransactionCommitFailedException e) {
1866 LOG.error("Failed to write service to Service List");
1867 result = "Failed to write service to Service List";
1870 LOG.info("Service is not present ! ");
1871 result = "Service is not present ! ";
1877 private void sendNotifToUrl(ServiceRpcResult notification, String url) {
1878 Gson gson = new GsonBuilder().setPrettyPrinting()
1879 // .serializeNulls()
1881 String data = gson.toJson(notification);
1885 HttpURLConnection con = (HttpURLConnection) obj.openConnection();
1887 // add request header
1888 con.setRequestMethod("POST");
1889 con.setRequestProperty("Content-Type", "application/json");
1890 con.setRequestProperty("Accept", "application/json");
1892 // Send post request
1893 con.setDoOutput(true);
1894 DataOutputStream wr = new DataOutputStream(con.getOutputStream());
1895 wr.writeBytes(data);
1898 int responseCode = con.getResponseCode();
1899 LOG.info("Response Code : " + responseCode);
1900 } catch (IOException e) {
1901 LOG.error("IOException : " + e.toString());
1907 public void close() throws Exception {
1908 executor.shutdown();
1912 public Future<RpcResult<EquipmentNotificationOutput>> equipmentNotification(EquipmentNotificationInput input) {
1913 // TODO Auto-generated method stub
1918 public Future<RpcResult<ServiceRerouteConfirmOutput>> serviceRerouteConfirm(ServiceRerouteConfirmInput input) {
1919 // TODO Auto-generated method stub
1924 public Future<RpcResult<ServiceRerouteOutput>> serviceReroute(ServiceRerouteInput input) {
1925 // TODO Auto-generated method stub
1930 public Future<RpcResult<ServiceReversionOutput>> serviceReversion(ServiceReversionInput input) {
1931 // TODO Auto-generated method stub
1936 public Future<RpcResult<ServiceRollOutput>> serviceRoll(ServiceRollInput input) {
1937 // TODO Auto-generated method stub
1942 public Future<RpcResult<NetworkReOptimizationOutput>> networkReOptimization(NetworkReOptimizationInput input) {
1943 // TODO Auto-generated method stub
1948 public Future<RpcResult<TempServiceDeleteOutput>> tempServiceDelete(TempServiceDeleteInput input) {
1949 // TODO Auto-generated method stub
1954 public Future<RpcResult<TempServiceCreateOutput>> tempServiceCreate(TempServiceCreateInput input) {
1955 // TODO Auto-generated method stub
1960 public void onServiceRpcResultSp(ServiceRpcResultSp notification) {
1961 if (!compareServiceRpcResultSp(notification)) {
1962 serviceRpcResultSp = notification;
1963 StringBuilder build = new StringBuilder();
1965 "Received '" + notification.getNotificationType() + "' StubRenderer notification" + "from service '"
1966 + notification.getServiceName() + "' " + "with status '" + notification.getStatus() + "'");
1967 build.append(" with StatusMessage '" + notification.getStatusMessage() + "'");
1968 if (notification.getStatus() == RpcStatusEx.Successful && notification.getNotificationType()
1969 .getIntValue() == ServicePathNotificationTypes.ServiceImplementationRequest.getIntValue()) {
1970 build.append(" PathTopology : " + notification.getPathTopology().toString());
1972 LOG.info(build.toString());
1974 LOG.info("ServicePathRpcResult already wired !");
1980 public void onServicePathRpcResult(ServicePathRpcResult notification) {
1981 if (!compareServicePathRpcResult(notification)) {
1982 servicePathRpcResult = notification;
1983 StringBuilder build = new StringBuilder();
1985 "Received '" + notification.getNotificationType() + "' StubPce notification " + "from service '"
1986 + notification.getServiceName() + "' " + "with status '" + notification.getStatus() + "'");
1987 build.append(" with StatusMessage '" + notification.getStatusMessage() + "'");
1988 if (notification.getStatus() == RpcStatusEx.Successful && notification.getNotificationType()
1989 .getIntValue() == ServicePathNotificationTypes.PathComputationRequest.getIntValue()) {
1990 build.append(" PathDescription : " + notification.getPathDescription().toString());
1992 * switch (action.getIntValue()) { case 1: //service-create case
1993 * 3: //service-delete case 8: //service-reconfigure case 9:
1994 * //service-restoration case 10://service-reversion case
1995 * 11://service-reroute break;
2001 LOG.info(build.toString());
2003 LOG.info("ServicePathRpcResult already wired !");
2007 public RpcActions getAction() {
2011 public void setAction(RpcActions action) {
2012 this.action = action;
2015 public Boolean compareServicePathRpcResult(ServicePathRpcResult notification) {
2016 Boolean result = true;
2017 if (servicePathRpcResult == null) {
2020 if (servicePathRpcResult.getNotificationType() != notification.getNotificationType()) {
2023 if (servicePathRpcResult.getServiceName() != notification.getServiceName()) {
2026 if (servicePathRpcResult.getStatus() != notification.getStatus()) {
2029 if (servicePathRpcResult.getStatusMessage() != notification.getStatusMessage()) {
2036 public Boolean compareServiceRpcResultSp(ServiceRpcResultSp notification) {
2037 Boolean result = true;
2038 if (serviceRpcResultSp == null) {
2041 if (serviceRpcResultSp.getNotificationType() != notification.getNotificationType()) {
2044 if (serviceRpcResultSp.getServiceName() != notification.getServiceName()) {
2047 if (serviceRpcResultSp.getStatus() != notification.getStatus()) {
2050 if (serviceRpcResultSp.getStatusMessage() != notification.getStatusMessage()) {