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
10 package org.opendaylight.transportpce.stubpce;
12 import com.google.common.base.Optional;
13 import com.google.common.util.concurrent.Futures;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import com.google.common.util.concurrent.ListeningExecutorService;
17 import java.util.ArrayList;
18 import java.util.Iterator;
19 import java.util.List;
20 import java.util.ListIterator;
21 import java.util.SortedSet;
22 import java.util.TreeSet;
23 import java.util.concurrent.Callable;
24 import java.util.concurrent.ExecutionException;
25 import java.util.concurrent.Future;
26 import java.util.concurrent.TimeUnit;
28 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
29 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
30 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
31 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
32 import org.opendaylight.transportpce.stubpce.topology.PathDescriptionsOrdered;
33 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.CancelResourceReserveInput;
34 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.PathComputationRequestInput;
35 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.PathDescriptionList;
36 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.ServicePathList;
37 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.path.description.list.PathDescriptions;
38 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.service.path.list.ServicePaths;
39 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.service.path.list.ServicePathsBuilder;
40 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.service.path.list.ServicePathsKey;
41 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.stubpce.rev170426.service.path.rpc.result.PathDescriptionBuilder;
42 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.AToZDirection;
43 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.ZToADirection;
44 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.path.description.atoz.direction.AToZ;
45 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.Resource;
46 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.Link;
47 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.Node;
48 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.pathdescription.rev170426.pce.resource.resource.resource.TerminationPoint;
49 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.constraints.sp.co.routing.or.general.General;
50 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.constraints.sp.co.routing.or.general.general.Diversity;
51 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.constraints.sp.co.routing.or.general.general.Exclude;
52 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.routing.constraints.sp.HardConstraints;
53 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.routing.constraints.rev170426.routing.constraints.sp.SoftConstraints;
54 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.service.handler.header.ServiceHandlerHeaderBuilder;
55 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.service.path.ServiceAEnd;
56 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.service.path.ServiceZEnd;
57 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
58 import org.slf4j.Logger;
59 import org.slf4j.LoggerFactory;
64 * - path-computation-request
65 * - cancel-resource-reserve.
66 * @author <a href="mailto:martial.coulibaly@gfi.com">Martial Coulibaly</a> on behalf of Orange
69 public class SendingPceRPCs {
71 private static final Logger LOG = LoggerFactory.getLogger(SendingPceRPCs.class);
72 private Boolean success;
73 private PathComputationRequestInput input;
74 private CancelResourceReserveInput cancelInput;
75 private PathDescriptionBuilder pathDescription;
76 private DataBroker db;
78 private final ListeningExecutorService executor;
79 private List<ServicePaths> servicePathList;
81 public SendingPceRPCs() {
83 setPathDescription(null);
86 setServicePathList(new ArrayList<ServicePaths>());
89 public SendingPceRPCs(PathComputationRequestInput input,DataBroker databroker,ListeningExecutorService executor) {
91 setPathDescription(null);
96 servicePathList = readServicePathList();
97 this.executor = executor;
100 public SendingPceRPCs(CancelResourceReserveInput input,DataBroker databroker,ListeningExecutorService executor) {
102 setPathDescription(null);
104 setCancelInput(input);
107 servicePathList = readServicePathList();
108 this.executor = executor;
112 * Compare AEnd and ZEnd resource Node to
113 * AEnd and ZEnd String.
115 * @param pathAend AEnd resource Node
116 * @param pathZend ZEnd resource Node
117 * @param inputAend AEnd String Node
118 * @param inputZend ZEnd String Node
119 * @return Boolean result true if equal, false if not
121 private Boolean comp(Resource pathAend, Resource pathZend, String inputAend, String inputZend) {
122 Boolean result = false;
123 if (pathAend != null && pathZend != null && inputAend != null && inputZend != null) {
124 if (pathAend instanceof Node && pathZend instanceof Node) {
125 Node aend = (Node) pathAend;
126 Node zend = (Node) pathZend;
127 if (aend.getNodeId().compareToIgnoreCase(inputAend) == 0) {
128 if (zend.getNodeId().compareToIgnoreCase(inputZend) == 0) {
138 * Compare two resource.
140 * @param res1 first resource
141 * @param res2 second resource
142 * @return Boolean result true if equal, false if not
144 private Boolean egalResource(Resource res1, Resource res2) {
145 LOG.info("comparing resource ...");
146 Boolean result = false;
147 LOG.info("{} - {}", res1.getClass().getName(), res2.getClass().getName());
148 if (res1.getClass().getName().compareToIgnoreCase(res2.getClass().getName()) == 0) {
149 if (res1 instanceof Node && res2 instanceof Node) {
150 Node node1 = (Node)res1;
151 Node node2 = (Node)res2;
152 if (node1.getNodeId().compareTo(node2.getNodeId()) == 0) {
156 if (res1 instanceof TerminationPoint && res2 instanceof TerminationPoint) {
157 TerminationPoint tp1 = (TerminationPoint)res1;
158 TerminationPoint tp2 = (TerminationPoint)res2;
159 if (tp1.getTpNodeId().compareTo(tp2.getTpNodeId()) == 0) {
160 if (tp1.getTpId().compareTo(tp2.getTpId()) == 0) {
165 if (res1 instanceof Link && res2 instanceof Link) {
166 Link link1 = (Link)res1;
167 Link link2 = (Link)res2;
168 if (link1.getLinkId().compareTo(link2.getLinkId()) == 0) {
178 * compare two AtoZDirection.
180 * @param atoz1 first AToZDirection
181 * @param atoz2 second AToZDirection
182 * @return Boolean result true if equal, false if not
184 private Boolean egalAtoZDirection(AToZDirection atoz1, AToZDirection atoz2) {
185 LOG.info("comparing AtoZDirection ...");
186 Boolean result = true;
187 if (atoz1.getAToZ().size() == atoz2.getAToZ().size()) {
189 int size = atoz1.getAToZ().size();
190 LOG.info("size : {}", size);
193 while (index < size) {
194 id1 = atoz1.getAToZ().get(index).getId();
195 LOG.info("id : {}", id1);
196 Resource res1 = atoz1.getAToZ().get(index).getResource().getResource();
197 LOG.info("res1 : {}", res1.toString());
198 Resource res2 = null;
200 Boolean trouve = false;
201 for (int loop = 0;loop < size;loop++) {
202 id2 = atoz2.getAToZ().get(loop).getId();
203 if (id2 != null && id2.compareTo(id1) == 0) {
204 res2 = atoz2.getAToZ().get(loop).getResource().getResource();
205 LOG.info("res2 : {}", res2.toString());
211 if (!egalResource(res1, res2)) {
223 LOG.info("AToZDirection size is not equal !");
230 * compare two ZtoZDirection.
232 * @param ztoa1 first ZToZDirection
233 * @param ztoa2 second ZToZDirection
234 * @return Boolean result true if equal, false if not
236 private Boolean egalZtoADirection(ZToADirection ztoa1, ZToADirection ztoa2) {
237 LOG.info("comparing ZtoADirection ...");
238 Boolean result = true;
239 if (ztoa1.getZToA().size() == ztoa2.getZToA().size()) {
241 int size = ztoa1.getZToA().size();
242 LOG.info("size : {}", size);
245 while (index < size) {
246 id1 = ztoa1.getZToA().get(index).getId();
247 LOG.info("id : {}", id1);
248 Resource res1 = ztoa1.getZToA().get(index).getResource().getResource();
249 LOG.info("res1 : {}", res1.toString());
250 Resource res2 = null;
252 Boolean trouve = false;
253 for (int loop = 0;loop < size;loop++) {
254 id2 = ztoa2.getZToA().get(loop).getId();
255 if (id2 != null && id2.compareTo(id1) == 0) {
256 res2 = ztoa2.getZToA().get(loop).getResource().getResource();
257 LOG.info("res2 : {}", res2.toString());
263 if (!egalResource(res1, res2)) {
281 * Test if resources Nodes
282 * not include in PathDescriptions.
284 * @param path PathDescriptions
285 * @param nodes Nodes List
286 * @return Boolean result true if found, false if not
288 private Boolean excludeNode(PathDescriptions path, List<String> nodes) {
289 LOG.info("Testing exclude Nodes ...");
290 Boolean result = false;
291 if (path != null && !nodes.isEmpty()) {
292 List<AToZ> list = path.getAToZDirection().getAToZ();
293 if (!list.isEmpty()) {
295 boolean found = false;
296 while (index < list.size() && !found) {
297 Resource res = list.get(index).getResource().getResource();
298 if (res != null && res instanceof Node) {
299 Node node = (Node) res;
300 for (String exclude : nodes) {
301 if (exclude.compareToIgnoreCase(node.getNodeId()) == 0) {
302 LOG.info("Node not excluded !");
315 LOG.info("exclude parameters not corrrect !");
321 * check if existing services not
322 * in pathDescriptions.
325 * @param existingService existing service list
326 * @param path PathDescriptions
327 * @param choice 0:Nodes, 1:Clli, 2:Srlg
328 * @return Boolean result true if found, false if not
330 private Boolean diversityService(List<String> existingService, PathDescriptions path, int choice) {
331 LOG.info("Testing diversity ...");
332 Boolean result = false;
333 if (path != null && choice >= 0 && !existingService.isEmpty()) {
335 while (index < existingService.size()) {
336 String tmp = existingService.get(index);
338 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service
339 .types.rev170426.service.path.PathDescription pathDesc = null;
340 if (servicePathList != null && !servicePathList.isEmpty()) {
341 for (ServicePaths service : servicePathList) {
342 if (service.getServicePathName().compareTo(tmp) == 0) {
343 LOG.info("Existing Service '{}' found in ServicePathList ...", tmp);
344 pathDesc = service.getPathDescription();
348 if (pathDesc != null) {
351 LOG.info("Checking Node existing-service-applicability ...");
352 if (!egalAtoZDirection(path.getAToZDirection(), pathDesc.getAToZDirection())) {
358 LOG.info("Checking clli existing-service-applicability ...");
362 LOG.info("Checking srlg existing-service-applicability ...");
369 LOG.info("Existing Service '{}' not found in ServicePathList !", tmp);
379 LOG.info("Diversity parameters not coherent !");
385 * test if pathDescription
386 * already exists in ServicePathList.
388 * @param path PathDescriptions
389 * @return <code>Boolean</code> result
391 private Boolean testPathDescription(PathDescriptions path) {
392 LOG.info("Testing pathDescription ...");
393 Boolean result = false;
395 LOG.info("retrieving path from servicePath List ...");
397 if (!servicePathList.isEmpty()) {
398 LOG.info("ServicePathList not empty, contains {} paths.", servicePathList.size());
399 for (ServicePaths service : servicePathList) {
400 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service
401 .types.rev170426.service.path.PathDescription tmp = service.getPathDescription();
403 if (path.getAToZDirection() != null && tmp.getAToZDirection() != null
404 && egalAtoZDirection(path.getAToZDirection(), tmp.getAToZDirection())) {
405 if (path.getZToADirection() != null && tmp.getZToADirection() != null
406 && egalZtoADirection(path.getZToADirection(), tmp.getZToADirection())) {
408 LOG.info("Path already present in servicePath List");
411 LOG.info("ZtoADirection not equal or one of ZtoADirection is null!");
415 LOG.info("AtoZDirection not equal !");
422 LOG.info("ServicePathList is empty");
424 } catch (NullPointerException e) {
425 LOG.error("ServicePathList is empty");
428 LOG.info("PathDescriptions is null !");
431 LOG.info("testPathDescription result : {}", result);
436 * function to retrieve Paths based on
439 * @param aendNodeId Aend Node Id
440 * @param zendNodeId Zend Node Id
441 * @return result PathDescriptions List
443 private List<PathDescriptions> retrievePath(String aendNodeId, String zendNodeId) {
444 List<PathDescriptions> result = new ArrayList<PathDescriptions>();
445 List<PathDescriptions> paths = readPathDescriptionList();
446 if (!paths.isEmpty() && aendNodeId != null && zendNodeId != null) {
447 LOG.info("retrieving paths from pathDescription List for {} / {}", aendNodeId, zendNodeId);
448 for (PathDescriptions tmp : paths) {
449 Resource pathAend = null;
450 Resource pathZend = null;
453 LOG.info("Getting Aend & ZEnd from path '{}'...",tmp.getPathName());
455 int size = tmp.getAToZDirection().getAToZ().size();
456 while (index < size) {
457 id = tmp.getAToZDirection().getAToZ().get(index).getId();
458 if (id.compareToIgnoreCase("1") == 0) {
459 Resource resource = tmp.getAToZDirection().getAToZ().get(index).getResource()
461 LOG.info("{} : {}", resource.getClass().toString(), resource.toString());
468 while (index < size) {
469 id = tmp.getZToADirection().getZToA().get(index).getId();
470 if (id.compareToIgnoreCase("1") == 0) {
471 Resource resource = tmp.getZToADirection().getZToA().get(index).getResource()
473 LOG.info(resource.toString());
479 if (pathAend != null && pathZend != null) {
480 LOG.info("pathAend : {} - pathZend: {}",pathAend, pathZend);
481 LOG.info("aendNodeId : {} - zendNodeId : {}", aendNodeId, zendNodeId);
482 if (comp(pathAend, pathZend, aendNodeId, zendNodeId)) {
483 LOG.info("PathDescription found !");
495 * found Pathdescriptions with
496 * name containing an expression.
498 * @param pathdescr PathDescriptions List
499 * @param contain String expression
500 * @return PathDescriptionsOrdered List
502 private SortedSet<PathDescriptionsOrdered> foundpath(List<PathDescriptions> pathdescr, String contain) {
503 SortedSet<PathDescriptionsOrdered> result = new TreeSet<PathDescriptionsOrdered>();
504 ListIterator<PathDescriptions> it = pathdescr.listIterator();
506 while (it.hasNext()) {
507 PathDescriptions path = it.next();
508 String name = path.getPathName();
509 LOG.info("path : {}", name);
510 if (name != null && name.contains(contain)) {
511 LOG.info(" path gets : {}", name);
512 String [] split = name.split("_");
513 if (split.length == 3) {
514 odr = Integer.parseInt(split[2]);
515 result.add(new PathDescriptionsOrdered(path, odr));
523 * order PathDescriptions List
524 * with first, ordered direct links
525 * and secondly ordered indirect
528 * @param pathdescr PathDescriptions List
529 * @return PathDescriptions List ordered
531 private List<PathDescriptions> orderPathdescriptionsList(List<PathDescriptions> pathdescr) {
532 SortedSet<PathDescriptionsOrdered> direct = new TreeSet<PathDescriptionsOrdered>();
533 SortedSet<PathDescriptionsOrdered> indirect = new TreeSet<PathDescriptionsOrdered>();
534 List<PathDescriptions> result = new ArrayList<PathDescriptions>();
535 int size = pathdescr.size();
537 LOG.info("getting direct path first ...");
538 direct = foundpath(pathdescr, "_direct_");
539 LOG.info("getting indirect path first ...");
540 indirect = foundpath(pathdescr, "_indirect_");
542 if (direct.size() > 0) {
543 Iterator<PathDescriptionsOrdered> itset = direct.iterator();
544 while (itset.hasNext()) {
545 result.add(itset.next().getPathDescriptions());
547 if (indirect.size() > 0) {
548 Iterator<PathDescriptionsOrdered> itset2 = indirect.iterator();
549 while (itset2.hasNext()) {
550 result.add(itset2.next().getPathDescriptions());
554 } else if (indirect.size() > 0) {
555 Iterator<PathDescriptionsOrdered> itset2 = indirect.iterator();
556 while (itset2.hasNext()) {
557 result.add(itset2.next().getPathDescriptions());
560 if (result.size() == pathdescr.size()) {
567 public ListenableFuture<Boolean> cancelResourceReserve() {
568 LOG.info("In cancelResourceReserve request ...");
570 return executor.submit(new Callable<Boolean>() {
572 public Boolean call() throws Exception {
573 Boolean output = false;
574 if (cancelInput != null) {
575 Boolean found = false;
576 String name = cancelInput.getServiceName();
577 if (name != null && !servicePathList.isEmpty()) {
578 for (ServicePaths service : servicePathList) {
579 if (name.compareTo(service.getServicePathName()) == 0) {
580 LOG.info("ServicePaths found in ServicePathList !!!");
586 LOG.info("removing servicePaths from datastore ...");
587 if (writeOrDeleteServicePathList(name,1)) {
588 LOG.info("Service deleted !");
592 LOG.info("service deletion failed !");
596 LOG.info("serviceName is null or servicePathList is empty !");
599 LOG.info("cancelresourcereserveinput parameter not valid !");
606 public ListenableFuture<Boolean> pathComputation() {
607 LOG.info("In pathComputation request ...");
609 return executor.submit(new Callable<Boolean>() {
611 public Boolean call() throws Exception {
612 Boolean output = false;
613 List<PathDescriptions> pathsList = new ArrayList<PathDescriptions>();
614 PathDescriptions path = null;
616 Boolean constraints = false;
618 HardConstraints inputHard = input.getHardConstraints();
619 SoftConstraints inputSoft = input.getSoftConstraints();
620 if (inputHard != null || inputSoft != null) {
624 pathsList = retrievePath(input.getServiceAEnd().getNodeId(), input.getServiceZEnd()
628 /** get pathList ordered. */
629 pathsList = orderPathdescriptionsList(pathsList);
630 if (!pathsList.isEmpty()) {
631 LOG.info("{} Paths get from Pathdescription List", pathsList.size());
634 while (index < pathsList.size()) {
635 path = pathsList.get(index);
636 LOG.info("path n°{} gets : '{}'!", index, path.getPathName());
638 LOG.info("Calculating path with constraints ...");
639 if (inputHard.getCoRoutingOrGeneral() instanceof General) {
640 General general = (General)inputHard.getCoRoutingOrGeneral();
641 if (general != null) {
642 Diversity diversity = general.getDiversity();
643 if (diversity != null) {
644 LOG.info("Getting diversity ...");
645 List<String> existingService = diversity.getExistingService();
646 if (existingService.size() > 0) {
647 LOG.info("Getting existing service applicability ...");
650 && diversity.getExistingServiceApplicability().isNode()) {
651 LOG.info("existing-service-applicability : Node");
655 && diversity.getExistingServiceApplicability().isClli()) {
656 LOG.info("existing-service-applicability : Clli");
660 && diversity.getExistingServiceApplicability().isSrlg()) {
661 LOG.info("existing-service-applicability : Srlg");
664 if (!diversityService(existingService, path, choice)) {
665 error = "existing service applicability not satisfied";
671 Exclude exclude = general.getExclude();
672 if (exclude != null) {
673 LOG.info("Getting exclude ...");
674 if (!excludeNode(path, exclude.getNodeId())) {
675 error = "Exclude node constraints not satisfied !";
683 if (!testPathDescription(path)) {
684 LOG.info("Process finish !");
691 LOG.info("failed to retrieve path from PathDescription List !");
694 LOG.info("pathComputationRequestInput parameter not valid !");
697 LOG.info("Path ok !");
698 pathDescription = new PathDescriptionBuilder()
699 .setAToZDirection(path.getAToZDirection())
700 .setZToADirection(path.getZToADirection());
701 if (input.isResourceReserve()) {
702 LOG.info("reserving pce resource ...");
703 setPathDescription(pathDescription);
704 if (writeOrDeleteServicePathList(input.getServiceName(), 0)) {
705 LOG.info("write ServicePaths to datastore");
708 LOG.error("writing ServicePaths to datastore failed ! ");
711 LOG.info("no pce resource reserve !");
722 * get all ServicePaths in ServicePathlist.
724 * @return <code>ServicePaths List</code>
726 private List<ServicePaths> readServicePathList() {
727 LOG.info("Reading ServicePathList ...");
728 List<ServicePaths> result = null;
729 ReadOnlyTransaction readTx = db.newReadOnlyTransaction();
730 InstanceIdentifier<ServicePathList> iid = InstanceIdentifier.create(ServicePathList.class);
731 Future<Optional<ServicePathList>> future = readTx.read(LogicalDatastoreType.OPERATIONAL,iid);
732 Optional<ServicePathList> optional = Optional.absent();
734 optional = Futures.getChecked(future, ExecutionException.class, 60, TimeUnit.SECONDS);
735 } catch (ExecutionException e) {
736 LOG.error("Reading service failed:", e);
738 if (optional.isPresent()) {
739 LOG.info("ServicePath List present !");
740 result = optional.get().getServicePaths();
746 private List<PathDescriptions> readPathDescriptionList() {
747 LOG.info("Reading PathDescriptionsList ...");
748 List<PathDescriptions> result = null;
749 ReadOnlyTransaction readTx = db.newReadOnlyTransaction();
750 InstanceIdentifier<PathDescriptionList> iid = InstanceIdentifier.create(PathDescriptionList.class);
751 Future<Optional<PathDescriptionList>> future = readTx.read(LogicalDatastoreType.OPERATIONAL,iid);
752 Optional<PathDescriptionList> optional = Optional.absent();
754 optional = Futures.getChecked(future, ExecutionException.class, 60, TimeUnit.SECONDS);
755 } catch (ExecutionException e) {
756 LOG.error("Reading service failed:", e);
758 if (optional.isPresent()) {
759 LOG.info("ServicePath List present !");
760 result = optional.get().getPathDescriptions();
767 * Write or Delete ServicePaths
768 * for ServicePathList.
770 * @param serviceName Service Name
771 * @param choice 0 : write or 1 : delete
772 * @return Boolean result true if deleted, false if not
774 private Boolean writeOrDeleteServicePathList(String serviceName, int choice) {
775 Boolean result = null;
776 if (serviceName != null && serviceName.compareTo(" ") != 0 && choice >= 0 && choice < 2) {
777 LOG.info("WriteOrDeleting '{}' ServicePaths", serviceName);
778 WriteTransaction writeTx = db.newWriteOnlyTransaction();
780 String action = null;
781 InstanceIdentifier<ServicePaths> iid = InstanceIdentifier.create(ServicePathList.class)
782 .child(ServicePaths.class,new ServicePathsKey(serviceName));
783 Future<Void> future = null;
785 case 0: /** Write. */
786 LOG.info("Writing '{}' Service", serviceName);
787 org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.service
788 .path.PathDescriptionBuilder path = new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c
789 ._interface.service.types.rev170426.service.path.PathDescriptionBuilder();
790 if (pathDescription != null) {
791 if (pathDescription.getAToZDirection() != null) {
792 path.setAToZDirection(pathDescription.getAToZDirection());
794 if (pathDescription.getZToADirection() != null) {
795 path.setZToADirection(pathDescription.getZToADirection());
797 LOG.info("pathdescription gets");
799 ServiceAEnd aend = new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c
800 ._interface.service.types.rev170426.service.path.ServiceAEndBuilder(input.getServiceAEnd())
802 ServiceZEnd zend = new org.opendaylight.yang.gen.v1.http.org.transportpce.b.c
803 ._interface.service.types.rev170426.service.path.ServiceZEndBuilder(input.getServiceZEnd())
805 ServicePaths service = new ServicePathsBuilder()
806 .setServicePathName(serviceName)
807 .setServiceHandlerHeader(new ServiceHandlerHeaderBuilder()
808 .setRequestId(input.getServiceHandlerHeader().getRequestId()).build())
809 .setServiceAEnd(aend)
810 .setServiceZEnd(zend)
811 .setHardConstraints(input.getHardConstraints())
812 .setSoftConstraints(input.getSoftConstraints())
813 .setPathDescription(path.build())
815 LOG.info("Servicepath build");
816 writeTx.put(LogicalDatastoreType.OPERATIONAL, iid, service);
818 //CheckedFuture<Void, OperationFailedException> future = transaction.submit();
819 future = writeTx.submit();
821 LOG.info("Sending '{}' command to datastore !", action);
822 Futures.getChecked(future, ExecutionException.class);
823 } catch (ExecutionException e) {
824 LOG.error("Failed to {} service from Service List", action);
829 case 1: /** Delete */
830 LOG.info("Deleting '{}' Service", serviceName);
831 writeTx.delete(LogicalDatastoreType.OPERATIONAL, iid);
833 future = writeTx.submit();
835 LOG.info("Sending '{}' command to datastore !", serviceName);
836 Futures.getChecked(future, ExecutionException.class);
837 } catch (ExecutionException e) {
838 LOG.error("Failed to {} service from Service List", serviceName);
844 LOG.info("No choice found");
850 LOG.info("Parameters not correct !");
855 public PathDescriptionBuilder getPathDescription() {
856 return pathDescription;
859 public void setPathDescription(PathDescriptionBuilder pathDescription) {
860 this.pathDescription = pathDescription;
863 public Boolean getSuccess() {
867 public void setSuccess(Boolean success) {
868 this.success = success;
871 public PathComputationRequestInput getInput() {
875 public void setInput(PathComputationRequestInput input) {
879 public CancelResourceReserveInput getCancelInput() {
883 public void setCancelInput(CancelResourceReserveInput input) {
884 this.cancelInput = input;
887 public DataBroker getDb() {
891 public void setDb(DataBroker db) {
895 public String getError() {
899 public void setError(String error) {
903 public List<ServicePaths> getServicePathList() {
904 return servicePathList;
907 public void setServicePathList(List<ServicePaths> servicePathList) {
908 this.servicePathList = servicePathList;