[ONOS-4160] PCE REST

Change-Id: Iec0554190876c7363114c03aa5d2b25b42ade071
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceDeletePathCommand.java b/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceDeletePathCommand.java
index 012fd28..2f0be92 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceDeletePathCommand.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceDeletePathCommand.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present Open Networking Laboratory
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@
 import org.apache.karaf.shell.commands.Command;
 
 import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.incubator.net.tunnel.TunnelId;
 import org.onosproject.pce.pceservice.api.PceService;
 
 import org.slf4j.Logger;
@@ -41,10 +42,9 @@
 
         PceService service = get(PceService.class);
 
-        //TODO: need to uncomment below lines once releasePath method is added to PceService
-        //if (!service.releasePath(PcePathId.of(id))) {
-        //    error("Path deletion failed.");
-        //    return;
-        //}
+        if (!service.releasePath(TunnelId.valueOf(id))) {
+            error("Path deletion failed.");
+            return;
+        }
     }
 }
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceQueryPathCommand.java b/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceQueryPathCommand.java
index b7dc3a9..32323fa 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceQueryPathCommand.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceQueryPathCommand.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present Open Networking Laboratory
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
 
 import org.onosproject.cli.AbstractShellCommand;
 import org.onosproject.incubator.net.tunnel.Tunnel;
+import org.onosproject.incubator.net.tunnel.TunnelId;
 import org.onosproject.net.AnnotationKeys;
 import org.onosproject.pce.pceservice.api.PceService;
 
@@ -45,8 +46,7 @@
 
         PceService service = get(PceService.class);
         if (null == id) {
-            //TODO: need to uncomment below line once queryAllPath method is added to PceService
-            Iterable<Tunnel> tunnels = null; // = service.queryAllPath();
+            Iterable<Tunnel> tunnels = service.queryAllPath();
             if (tunnels != null) {
                 for (final Tunnel tunnel : tunnels) {
                     display(tunnel);
@@ -56,8 +56,7 @@
                 return;
             }
         } else {
-            //TODO: need to uncomment below line once queryPath method is added to PceService
-            Tunnel tunnel = null; // = service.queryPath(PcePathId.of(id));
+            Tunnel tunnel = service.queryPath(TunnelId.valueOf(id));
             if (tunnel == null) {
                 print("Path doesnot exists.");
                 return;
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceSetupPathCommand.java b/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceSetupPathCommand.java
index 5bf13ff..497905f 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceSetupPathCommand.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceSetupPathCommand.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present Open Networking Laboratory
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -86,9 +86,8 @@
             //listConstrnt.add(LocalBandwidthConstraint.of(bandwidth, DataRateUnit.valueOf("BPS")));
         }
 
-        //TODO: need to uncomment below lines once setupPath method is modified in PceService
-        //if (null == service.setupPath(srcDevice, dstDevice, name, listConstrnt, lspType)) {
-        //    error("Path creation failed.");
-        //}
+        if (!service.setupPath(srcDevice, dstDevice, name, listConstrnt, lspType)) {
+            error("Path creation failed.");
+        }
     }
 }
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceUpdatePathCommand.java b/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceUpdatePathCommand.java
index e1dcd65..5ea8686 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceUpdatePathCommand.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/cli/PceUpdatePathCommand.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present Open Networking Laboratory
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/cli/package-info.java b/apps/pce/app/src/main/java/org/onosproject/pce/cli/package-info.java
index d5c85c4..2db38908 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/cli/package-info.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/cli/package-info.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present Open Networking Laboratory
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/DefaultPcePath.java b/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/DefaultPcePath.java
index 1331255..e9d3fec 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/DefaultPcePath.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/pceservice/DefaultPcePath.java
@@ -244,12 +244,14 @@
             this.id = TunnelId.valueOf(tunnel.tunnelId().id());
             this.source = tunnel.src().toString();
             this.destination = tunnel.dst().toString();
-            //TODO: need to uncomment below line once LSP_SIG_TYPE is added to AnnotationKeys
-            this.lspType = null; // = LspType.valueOf(tunnel.annotations().value(AnnotationKeys.LSP_SIG_TYPE));
+            //TODO: need to uncomment below line once LSP_SIG_TYPE is added to AnnotationKeys.
+            this.lspType = null; // = LspType.valueOf(tunnel.annotations()
+                                           //.value(AnnotationKeys.LSP_SIG_TYPE));
             this.name = tunnel.tunnelName().toString();
-            this.costConstraint = null; //CostConstraint.of(tunnel.path().cost());
-            this.bandwidthConstraint = null;
-                                    //LocalBandwidthConstraint.of(tunnel.annotations().value(AnnotationKeys.BANDWIDTH));
+            //TODO: uncomment below lines once CostConstraint and LocalBandwidthConstraint classes are ready
+            this.costConstraint = null; // = CostConstraint.of(tunnel.path().cost());
+            this.bandwidthConstraint = null; // = LocalBandwidthConstraint.of(tunnel.annotations()
+                                                                        //.value(AnnotationKeys.BANDWIDTH));
             return this;
         }
 
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/web/PceCodecRegistrator.java b/apps/pce/app/src/main/java/org/onosproject/pce/rest/PceCodecRegistrator.java
similarity index 94%
rename from apps/pce/app/src/main/java/org/onosproject/pce/web/PceCodecRegistrator.java
rename to apps/pce/app/src/main/java/org/onosproject/pce/rest/PceCodecRegistrator.java
index 5554e64..fb4f9ed 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/web/PceCodecRegistrator.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/rest/PceCodecRegistrator.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present Open Networking Laboratory
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onosproject.pce.web;
+package org.onosproject.pce.rest;
 
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/web/PcePathCodec.java b/apps/pce/app/src/main/java/org/onosproject/pce/rest/PcePathCodec.java
similarity index 97%
rename from apps/pce/app/src/main/java/org/onosproject/pce/web/PcePathCodec.java
rename to apps/pce/app/src/main/java/org/onosproject/pce/rest/PcePathCodec.java
index 9c16bd0..e0149e7 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/web/PcePathCodec.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/rest/PcePathCodec.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present Open Networking Laboratory
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onosproject.pce.web;
+package org.onosproject.pce.rest;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/web/PcePathWebResource.java b/apps/pce/app/src/main/java/org/onosproject/pce/rest/PcePathWebResource.java
similarity index 84%
rename from apps/pce/app/src/main/java/org/onosproject/pce/web/PcePathWebResource.java
rename to apps/pce/app/src/main/java/org/onosproject/pce/rest/PcePathWebResource.java
index 19244f7..abd7c88 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/web/PcePathWebResource.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/rest/PcePathWebResource.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present Open Networking Laboratory
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -13,9 +13,10 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onosproject.pce.web;
+package org.onosproject.pce.rest;
 
 import static javax.ws.rs.core.Response.Status.OK;
+import static org.onlab.util.Tools.nullIsNotFound;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -34,8 +35,10 @@
 import javax.ws.rs.core.Response;
 
 import org.onosproject.incubator.net.tunnel.Tunnel;
+import org.onosproject.incubator.net.tunnel.TunnelId;
 import org.onosproject.net.DeviceId;
 import org.onosproject.net.intent.Constraint;
+import org.onosproject.pce.pceservice.api.PceService;
 import org.onosproject.pce.pceservice.PcePath;
 import org.onosproject.pce.pceservice.DefaultPcePath;
 import org.onosproject.pce.pceservice.LspType;
@@ -58,6 +61,7 @@
     public static final String PCE_PATH_NOT_FOUND = "Path not found";
     public static final String PCE_PATH_ID_EXIST = "Path exists";
     public static final String PCE_PATH_ID_NOT_EXIST = "Path does not exist for the identifier";
+    public static final String PCE_SETUP_PATH_FAILED = "PCE Setup path has failed.";
 
     /**
      * Retrieve details of all paths created.
@@ -68,8 +72,7 @@
     @Produces(MediaType.APPLICATION_JSON)
     public Response queryAllPath() {
         log.debug("Query all paths.");
-        //TODO: need to uncomment below line once queryAllPath method is added to PceService
-        Iterable<Tunnel> tunnels = null; // = get(PceService.class).queryAllPath();
+        Iterable<Tunnel> tunnels = get(PceService.class).queryAllPath();
         ObjectNode result = mapper().createObjectNode();
         ArrayNode pathEntry = result.putArray("paths");
         if (tunnels != null) {
@@ -92,9 +95,8 @@
     @Produces(MediaType.APPLICATION_JSON)
     public Response queryPath(@PathParam("path_id") String id) {
         log.debug("Query path by identifier {}.", id);
-        //TODO: need to uncomment below lines once queryPath method is added to PceService
-        Tunnel tunnel = null; // = nullIsNotFound(get(PceService.class).queryPath(PcePathId.of(id)),
-                //PCE_PATH_NOT_FOUND);
+        Tunnel tunnel = nullIsNotFound(get(PceService.class).queryPath(TunnelId.valueOf(id)),
+                                       PCE_PATH_NOT_FOUND);
         PcePath path = DefaultPcePath.builder().of(tunnel).build();
         ObjectNode result = mapper().createObjectNode();
         result.set("path", codec(PcePath.class).encode(path, this));
@@ -131,9 +133,9 @@
             //listConstrnt.add(LocalBandwidthConstraint.of(Double.valueOf(path.constraint().bandwidth()), DataRateUnit
             //        .valueOf("BPS")));
 
-            //TODO: need to uncomment below lines once setupPath method is modified in PceService
-            Boolean issuccess = true; // = (null != get(PceService.class)
-                    //.setupPath(srcDevice, dstDevice, path.name(), listConstrnt, lspType)) ? true : false;
+            Boolean issuccess = nullIsNotFound(get(PceService.class)
+                                               .setupPath(srcDevice, dstDevice, path.name(), listConstrnt, lspType),
+                                               PCE_SETUP_PATH_FAILED);
             return Response.status(OK).entity(issuccess.toString()).build();
         } catch (IOException e) {
             log.error("Exception while creating path {}.", e.toString());
@@ -174,9 +176,8 @@
                 //        .of(path.constraint().bandwidth(), DataRateUnit.valueOf("BPS")));
             }
 
-            //TODO: need to uncomment below line once updatePath is added to PceService
-            Boolean result = true; // = (null != (get(PceService.class).updatePath(PcePathId.of(id), constrntList)))
-                                      //? true : false;
+            Boolean result = nullIsNotFound(get(PceService.class).updatePath(TunnelId.valueOf(id), constrntList),
+                                            PCE_PATH_NOT_FOUND);
             return Response.status(OK).entity(result.toString()).build();
         } catch (IOException e) {
             log.error("Update path failed because of exception {}.", e.toString());
@@ -195,9 +196,8 @@
     public Response releasePath(@PathParam("path_id") String id) {
         log.debug("Deletes path by identifier {}.", id);
 
-        //TODO: need to uncomment below lines once releasePath method is added to PceService
-        Boolean isSuccess = true; // = nullIsNotFound(get(PceService.class).releasePath(PcePathId.of(id)),
-                //PCE_PATH_NOT_FOUND);
+        Boolean isSuccess = nullIsNotFound(get(PceService.class).releasePath(TunnelId.valueOf(id)),
+                                           PCE_PATH_NOT_FOUND);
         if (!isSuccess) {
             log.debug("Path identifier {} does not exist", id);
         }
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/web/PceWebApplication.java b/apps/pce/app/src/main/java/org/onosproject/pce/rest/PceWebApplication.java
similarity index 90%
rename from apps/pce/app/src/main/java/org/onosproject/pce/web/PceWebApplication.java
rename to apps/pce/app/src/main/java/org/onosproject/pce/rest/PceWebApplication.java
index 9cae9b3..3ff2dc3 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/web/PceWebApplication.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/rest/PceWebApplication.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present Open Networking Laboratory
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -14,7 +14,7 @@
  * limitations under the License.
  */
 
-package org.onosproject.pce.web;
+package org.onosproject.pce.rest;
 
 import org.onlab.rest.AbstractWebApplication;
 
diff --git a/apps/pce/app/src/main/java/org/onosproject/pce/web/package-info.java b/apps/pce/app/src/main/java/org/onosproject/pce/rest/package-info.java
similarity index 87%
rename from apps/pce/app/src/main/java/org/onosproject/pce/web/package-info.java
rename to apps/pce/app/src/main/java/org/onosproject/pce/rest/package-info.java
index 08a1b6b..a56073c 100644
--- a/apps/pce/app/src/main/java/org/onosproject/pce/web/package-info.java
+++ b/apps/pce/app/src/main/java/org/onosproject/pce/rest/package-info.java
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Open Networking Laboratory
+ * Copyright 2016-present Open Networking Laboratory
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -17,4 +17,4 @@
 /**
  * PCE rest application.
  */
-package org.onosproject.pce.web;
+package org.onosproject.pce.rest;