+
+ /**
+ * Initialize PathDescriptionList Structure on DataStore.
+ *
+ * @param DataBroker
+ * Access DataStore
+ */
+ private boolean initializePathDescriptionList(DataBroker db) {
+ Boolean result = true;
+ LOG.info("Preparing to initialize the PathDescription List");
+ WriteTransaction transaction = db.newWriteOnlyTransaction();
+ InstanceIdentifier<PathDescriptionList> iid = InstanceIdentifier.create(PathDescriptionList.class);
+ PathDescriptionList pathDescriptionList = new PathDescriptionListBuilder().build();
+ transaction.put(LogicalDatastoreType.OPERATIONAL, iid, pathDescriptionList);
+ Future<Void> future = transaction.submit();
+ try {
+ Futures.getChecked(future, ExecutionException.class);
+ } catch (ExecutionException e) {
+ LOG.error("Failed to create PathDescription List");
+ result = false;
+ }
+ return result;
+ }
+
+ /**
+ * Initialize ServicePathList Structure on DataStore.
+ *
+ * @param DataBroker
+ * Access DataStore
+ * @return <code>true</code> if ok, <code>false</code> else
+ */
+ private boolean initializeServicePathList(DataBroker db) {
+ Boolean result = true;
+ LOG.info("Preparing to initialize the ServicePathList registry");
+ WriteTransaction transaction = db.newWriteOnlyTransaction();
+ InstanceIdentifier<ServicePathList> iid = InstanceIdentifier.create(ServicePathList.class);
+ ServicePathList servicePathList = new ServicePathListBuilder().build();
+ transaction.put(LogicalDatastoreType.OPERATIONAL, iid, servicePathList);
+ Future<Void> future = transaction.submit();
+ try {
+ Futures.getChecked(future, ExecutionException.class);
+ } catch (ExecutionException e) {
+ LOG.error("Failed to create ServicePathList List : " + e.toString());
+ result = false;
+ }
+ return result;
+ }
+
+ /**
+ * fill PathDescriptionList
+ * with direct paths and
+ * indirect paths.
+ */
+ private void fillPathDesciptionList() {
+ LOG.info("filling PathDescription List...");
+ Topology topo = new Topology();
+ topo.start();
+ LOG.info("Network : " + topo.getNetwork());
+ SuperNodePath superNodePath = new SuperNodePath(topo.getNetwork());
+ String aend = "NodeA";
+ String zend = "NodeZ";
+ superNodePath.run(aend, zend);
+ fill(superNodePath.getDirectPathDesc(aend, zend, superNodePath.getPaths()));
+ fill(superNodePath.getIndirectPathDesc(aend, zend, superNodePath.getPaths()));
+ }
+
+ /**
+ * fill datastore with
+ * Pathdescriptions List.
+ *
+ * @param sortedSet PathDescriptionsOrdered List
+ */
+ private void fill(SortedSet<PathDescriptionsOrdered> sortedSet) {
+ InstanceIdentifier<PathDescriptions> iid;
+ WriteTransaction writeTx;
+ Future<Void> future;
+ if (!sortedSet.isEmpty()) {
+ Iterator<PathDescriptionsOrdered> it = sortedSet.iterator();
+ while (it.hasNext()) {
+ PathDescriptions pathDesc = it.next().getPathDescriptions();
+ if (pathDesc != null) {
+ iid = InstanceIdentifier.create(PathDescriptionList.class)
+ .child(PathDescriptions.class, new PathDescriptionsKey(pathDesc.getPathName()));
+ writeTx = db.newWriteOnlyTransaction();
+ writeTx.put(LogicalDatastoreType.OPERATIONAL, iid, pathDesc);
+ future = writeTx.submit();
+ try {
+ Futures.getChecked(future, ExecutionException.class);
+ } catch (ExecutionException e) {
+ LOG.error("Failed to write PathDescriptions to PathDescriptionsList : " + e.toString());
+ }
+ } else {
+ LOG.error("PathDescriptions gets is null !");
+ }
+ }
+ } else {
+ LOG.info("PathDescriptions List is empty !");
+ }
+ }
+
+ /**
+ * read Service from ServiceList DataStore.
+ *
+ * @param serviceName
+ * Name of Service
+ *
+ * @return <code>Services</code>
+ */
+ @SuppressWarnings("unused")
+ private Services readServiceList(String serviceName) {
+ Services result = null;
+ ReadOnlyTransaction readTx = db.newReadOnlyTransaction();
+ InstanceIdentifier<Services> iid = InstanceIdentifier.create(ServiceList.class).child(Services.class,
+ new ServicesKey(serviceName));
+ Future<Optional<Services>> future = readTx.read(LogicalDatastoreType.OPERATIONAL,iid);
+ Optional<Services> optional = Optional.absent();
+ try {
+ optional = Futures.getChecked(future, ExecutionException.class);
+ } catch (ExecutionException e) {
+ LOG.error("Reading service failed:", e);
+ }
+ if (optional.isPresent()) {
+ LOG.debug("Service '" + serviceName + "' present !");
+ result = new ServicesBuilder(optional.get()).build();
+ }
+ return result;
+ }
+
+ /**
+ * read ServicePath Service from ServicePathList DataStore.
+ *
+ * @param serviceName
+ * Name of ServicePath
+ *
+ * @return <code>Services</code>
+ */
+ @SuppressWarnings("unused")
+ private ServicePaths readServicePathList(String serviceName) {
+ ServicePaths result = null;
+ ReadOnlyTransaction readTx = db.newReadOnlyTransaction();
+ InstanceIdentifier<ServicePaths> iid = InstanceIdentifier.create(ServicePathList.class)
+ .child(ServicePaths.class, new ServicePathsKey(serviceName));
+ Future<Optional<ServicePaths>> future = readTx.read(LogicalDatastoreType.OPERATIONAL,iid);
+ Optional<ServicePaths> optional = Optional.absent();
+ try {
+ optional = Futures.getChecked(future, ExecutionException.class);
+ } catch (ExecutionException e) {
+ LOG.error("Reading service failed:", e);
+ }
+ if (optional.isPresent()) {
+ LOG.debug("Service '" + serviceName + "' present !");
+ result = new ServicePathsBuilder(optional.get()).build();
+ }
+ return result;
+ }
+
+ /**
+ * read PathDescription information from PathDescriptionList.
+ *
+ * @param pathName
+ * Name of PathDescription
+ *
+ * @return <code>PathDescriptions</code>
+ */
+ @SuppressWarnings("unused")
+ private PathDescriptions readPathDescriptionList(String pathName) {
+ PathDescriptions result = null;
+ ReadOnlyTransaction readTx = db.newReadOnlyTransaction();
+ InstanceIdentifier<PathDescriptions> iid = InstanceIdentifier.create(PathDescriptionList.class)
+ .child(PathDescriptions.class, new PathDescriptionsKey(pathName));
+ Future<Optional<PathDescriptions>> future = readTx.read(LogicalDatastoreType.OPERATIONAL,iid);
+ Optional<PathDescriptions> optional = Optional.absent();
+ try {
+ optional = Futures.getChecked(future, ExecutionException.class);
+ } catch (ExecutionException e) {
+ LOG.error("Reading service failed:", e);
+ }
+ if (optional.isPresent()) {
+ LOG.debug("PathDescritions '" + pathName + "' present !");
+ result = new PathDescriptionsBuilder(optional.get()).build();
+ }
+ return result;
+ }
+
+ /**
+ * register ServicePath Service to ServicePathList with PathDescription
+ * information.
+ *
+ * @param input
+ * PathComputationRequestInput
+ * @return String operations result, null if ok or not otherwise
+ */
+ @SuppressWarnings("unused")
+ private String writeServicePathList(PathComputationRequestInput input) {
+ String serviceName = input.getServiceName();
+ LOG.debug("Write ServicePath '" + serviceName + "' Service");
+ String result = null;
+ LOG.debug("Writing '" + serviceName + "' ServicePath");
+ InstanceIdentifier<ServicePaths> iid = InstanceIdentifier.create(ServicePathList.class)
+ .child(ServicePaths.class, new ServicePathsKey(serviceName));
+
+ org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.service.types.rev170426.service
+ .path.PathDescriptionBuilder path = new org.opendaylight.yang.gen.v1.http.org.transportpce
+ .b.c._interface.service.types.rev170426.service.path.PathDescriptionBuilder();
+ path.setAToZDirection(pathDescriptionBuilder.getAToZDirection());
+ path.setZToADirection(pathDescriptionBuilder.getZToADirection());
+ ServicePaths service = new ServicePathsBuilder().setServicePathName(input.getServiceName())
+ .setSoftConstraints(input.getSoftConstraints()).setHardConstraints(input.getHardConstraints())
+ .setPathDescription(path.build()).build();
+ WriteTransaction writeTx = db.newWriteOnlyTransaction();
+ writeTx.put(LogicalDatastoreType.OPERATIONAL, iid, service);
+ Future<Void> future = writeTx.submit();
+ try {
+ Futures.getChecked(future, ExecutionException.class);
+ result = null;
+ } catch (ExecutionException e) {
+ LOG.error("Failed to write service to Service List");
+ result = "Failed to write service to Service List";
+ }
+ return result;
+ }
+
+ public PathDescriptionBuilder getPathDescriptionBuilder() {
+ return pathDescriptionBuilder;
+ }
+
+ public void setPathDescriptionBuilder(PathDescriptionBuilder pathDescriptionBuilder) {
+ this.pathDescriptionBuilder = pathDescriptionBuilder;
+ }
+
+ @Override
+ public Future<RpcResult<ServiceImplementationRequestOutput>> serviceImplementationRequest(
+ ServiceImplementationRequestInput input) {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ @Override
+ public Future<RpcResult<ServiceDeleteOutput>> serviceDelete(ServiceDeleteInput input) {
+ // TODO Auto-generated method stub
+ return null;
+ }