aboutsummaryrefslogtreecommitdiffstats
path: root/svc/svcbase/src/main/java/com
diff options
context:
space:
mode:
authorMufaddal Makati <mmakati@mmakatimbpr15.cablelabs.com>2015-08-07 13:09:49 -0700
committerMufaddal Makati <mmakati@mmakatimbpr15.cablelabs.com>2015-08-07 13:09:49 -0700
commited73dbf357aff41edcbab401a94e5fbc266d9391 (patch)
treee3561a9290e4bd0de19704228867ec91910e68ed /svc/svcbase/src/main/java/com
parentf44f4aa8b5eb244fc7603c17e875eebf0f3b0b67 (diff)
First Commit
Diffstat (limited to 'svc/svcbase/src/main/java/com')
-rw-r--r--svc/svcbase/src/main/java/com/cablelabs/vcpe/svc/svcbase/client/EplClient.java149
-rw-r--r--svc/svcbase/src/main/java/com/cablelabs/vcpe/svc/svcbase/model/Epl.java104
-rw-r--r--svc/svcbase/src/main/java/com/cablelabs/vcpe/svc/svcbase/repository/EplRespository.java21
-rw-r--r--svc/svcbase/src/main/java/com/cablelabs/vcpe/svc/svcbase/repository/EplRespositoryInMem.java91
4 files changed, 365 insertions, 0 deletions
diff --git a/svc/svcbase/src/main/java/com/cablelabs/vcpe/svc/svcbase/client/EplClient.java b/svc/svcbase/src/main/java/com/cablelabs/vcpe/svc/svcbase/client/EplClient.java
new file mode 100644
index 0000000..9bc7368
--- /dev/null
+++ b/svc/svcbase/src/main/java/com/cablelabs/vcpe/svc/svcbase/client/EplClient.java
@@ -0,0 +1,149 @@
+package com.cablelabs.vcpe.svc.svcbase.client;
+
+import com.cablelabs.vcpe.svc.svcbase.model.Epl;
+
+import javax.ws.rs.client.Client;
+import javax.ws.rs.client.ClientBuilder;
+import javax.ws.rs.client.Entity;
+import javax.ws.rs.client.WebTarget;
+import javax.ws.rs.core.GenericType;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.util.List;
+
+/**
+ * Created by steve on 6/8/15.
+ */
+public class EplClient {
+
+ private Client client; // provided by Jersey
+
+ public EplClient() {
+ client = ClientBuilder.newClient();
+ }
+
+ //--------------------------------------------------------
+ public Epl create(Epl epl)
+ //--------------------------------------------------------
+ {
+ WebTarget target =client.target("http://localhost:9090/svcmgr/webapi/svc/");
+ Response response = target.path("epl")
+ .request(MediaType.APPLICATION_JSON)
+ .post(Entity.entity(epl, MediaType.APPLICATION_JSON));
+
+ if (response.getStatus() != 200 ) // figure out how to use Status.OK
+ {
+ // in production you can be more specific based on reponse code, id, etc
+ throw new RuntimeException(response.getStatus() + ": there was an error on the server.");
+ }
+ return response.readEntity(Epl.class);
+ }
+
+ //--------------------------------------------------------
+ public Epl update(Epl epl)
+ //--------------------------------------------------------
+ {
+ WebTarget target =client.target("http://localhost:9090/svcmgr/webapi/svc/");
+ Response response = target.path("epl/"+ epl.getId())
+ .request(MediaType.APPLICATION_JSON)
+ .put(Entity.entity(epl, MediaType.APPLICATION_JSON));
+
+ if (response.getStatus() != 200 ) // figure out how to use Status.OK
+ {
+ // in production you can be more specific based on reponse code, id, etc
+ throw new RuntimeException(response.getStatus() + ": there was an error on the server.");
+ }
+ return response.readEntity(Epl.class);
+ }
+
+ //--------------------------------------------------------
+ public Epl get(String eplId)
+ //--------------------------------------------------------
+ // get Epl of specified ID
+
+ {
+ WebTarget target = client.target("http://localhost:9090/svcmgr/webapi/svc");
+
+ Response response = target.path("epl/"+eplId).request(MediaType.APPLICATION_JSON).get(Response.class);
+ if (response.getStatus() != 200) // figure out how to use Status.OK
+ {
+ // in production you can be more specific based on reponse code, id, etc
+ throw new RuntimeException(response.getStatus() + ": there was an error on the server.");
+ }
+
+ //return response;
+ return response.readEntity(Epl.class);
+ }
+
+ //--------------------------------------------------------
+ public List<Epl> getAll()
+ //--------------------------------------------------------
+ // get a list of all Epl instances
+ {
+
+ WebTarget target = client.target("http://localhost:9090/svcmgr/webapi/svc/");
+
+ // Can I do this with a Response, so that I can check for errors
+ List<Epl> response = target.path("epl/list")
+ .request(MediaType.APPLICATION_JSON)
+ .get(new GenericType<List<Epl>>() {
+ });
+ if (response == null) // figure out how to use Status.OK
+ {
+ // in production you can be more specific based on reponse code, id, etc
+ throw new RuntimeException("there was an error on the server.");
+ }
+ return response;
+ }
+
+ //--------------------------------------------------------
+ public void delete(String eplId)
+ //--------------------------------------------------------
+ // delete Epl of specified ID
+ {
+ WebTarget target = client.target("http://localhost:9090/svcmgr/webapi/svc/");
+ Response response = target.path("epl/"+eplId).request(MediaType.APPLICATION_JSON).delete();
+ if (response.getStatus() != 200) // figure out how to use Status.OK
+ {
+ // in production you can be more specific based on reponse code, id, etc
+ throw new RuntimeException(response.getStatus() + ": there was an error on the server.");
+ }
+ }
+
+ //--------------------------------------------------------
+ public Epl testGet()
+ //--------------------------------------------------------
+ // test marshaling of Epl class from server json
+
+ {
+ WebTarget target = client.target("http://localhost:9090/svcmgr/webapi/svc/");
+
+ Response response = target.path("epl").request(MediaType.APPLICATION_JSON).get(Response.class);
+ if (response.getStatus() != 200) // figure out how to use Status.OK
+ {
+ // in production you can be more specific based on reponse code, id, etc
+ throw new RuntimeException(response.getStatus() + ": there was an error on the server.");
+ }
+
+ //return response;
+ return response.readEntity(Epl.class);
+ }
+
+ //--------------------------------------------------------
+ public String ping()
+ //--------------------------------------------------------
+ // test connectivity
+ {
+
+ WebTarget target = client.target("http://localhost:9090/svcmgr/webapi/svc/");
+
+ Response response = target.path("epl").request(MediaType.TEXT_PLAIN).get();
+ if (response.getStatus() != 200) // figure out how to use Status.OK
+ {
+ // in production you can be more specific based on reponse code, id, etc
+ throw new RuntimeException(response.getStatus() + ": there was an error on the server.");
+ }
+
+ return response.readEntity(String.class);
+ }
+}
diff --git a/svc/svcbase/src/main/java/com/cablelabs/vcpe/svc/svcbase/model/Epl.java b/svc/svcbase/src/main/java/com/cablelabs/vcpe/svc/svcbase/model/Epl.java
new file mode 100644
index 0000000..254fb11
--- /dev/null
+++ b/svc/svcbase/src/main/java/com/cablelabs/vcpe/svc/svcbase/model/Epl.java
@@ -0,0 +1,104 @@
+package com.cablelabs.vcpe.svc.svcbase.model;
+
+import com.cablelabs.vcpe.common.Dbg;
+import com.cablelabs.vcpe.evc.evcbase.model.Evc;
+import com.cablelabs.vcpe.evc.evcbase.client.EvcClient;
+
+import javax.xml.bind.annotation.XmlRootElement;
+import java.util.List;
+
+/**
+ * Created by steve on 5/24/15.
+ */
+
+@XmlRootElement
+public class Epl
+{
+ private String id;
+ private long numCustLocations;
+ private List<String> custAddressList = null;
+ private List<String> uniHostMacList = null;
+ private List<String> uniHostIpList = null;
+ private String cos;
+ private String evcId;
+
+ // zero argument constructor required for JAX-RS
+ public Epl() {
+ id = "unset";
+ this.numCustLocations = -1;
+ this.custAddressList = null;
+ this.uniHostMacList = null;
+ this.uniHostIpList = null;
+ this.cos = "unset";
+ this.evcId = "unset";
+ }
+
+ public void setAllProps (String id, long numCustLocations,
+ List<String> custAddressList,
+ List<String> uniHostMacList, List<String> uniHostIpList, String cos, String evcId) {
+ this.id = id;
+ this.numCustLocations = numCustLocations;
+ this.custAddressList = custAddressList;
+ this.uniHostMacList = uniHostMacList;
+ this.uniHostIpList = uniHostIpList;
+ this.cos = cos;
+ this.evcId = evcId;
+ }
+
+ public void dump() { dump(0); }
+ public void dump(int tab) {
+
+ Dbg.p(tab, "id: " + this.id);
+ Dbg.p(tab, "numCustLocations: " + this.numCustLocations);
+ Dbg.p(tab, "Address List:");
+ for (String addr : custAddressList)
+ Dbg.p(tab+1, addr);
+ Dbg.p(tab, "UNI Mac List:");
+ for (String mac : uniHostMacList)
+ Dbg.p(tab+1, mac);
+ Dbg.p(tab, "UNI IP List:");
+ for (String ip : uniHostIpList)
+ Dbg.p(tab+1, ip);
+ Dbg.p(tab, "cos: " + this.cos);
+ Dbg.p(tab, "Evc:" + this.evcId);
+// if ( this.evcId != "unset") { // hacky
+// EvcClient evcClient = new EvcClient();
+// Evc evc = evcClient.get(this.evcId);
+// evc.dump(tab + 2);
+// }
+ }
+
+ public static void dumpList(List<Epl> eplList) { dumpList(0, eplList); }
+ public static void dumpList(int tab, List<Epl> eplList) {
+ int numSvc = 0;
+ Dbg.p("----- Epl List : [" + eplList.size() + "] elements");
+ for (Epl curEpl : eplList) {
+ numSvc++;
+ Dbg.p(tab+1, "<Entry " + numSvc+">");
+ curEpl.dump(tab+2);
+ }
+ }
+
+ // Getters & Setters
+ public String getId() { return id; }
+ public void setId(String id) { this.id = id; }
+
+ public long getNumCustLocations() { return numCustLocations; }
+ public void setNumCustLocations(long numCustLocations) { this.numCustLocations = numCustLocations; }
+
+ public List<String> getCustAddressList() { return custAddressList; }
+ public void setCustAddressList(List<String> custAddressList) { this.custAddressList = custAddressList; }
+
+ public List<String> getUniHostMacList() { return uniHostMacList; }
+ public void setUniHostMacList(List<String> uniHostMacList) { this.uniHostMacList = uniHostMacList; }
+
+
+ public List<String> getUniHostIpList() { return uniHostIpList; }
+ public void setUniHostIpList(List<String> uniHostIpList) { this.uniHostIpList = uniHostIpList; }
+
+ public String getCos() { return cos; }
+ public void setCos(String cos) { this.cos = cos; }
+
+ public String getEvcId() { return evcId; }
+ public void setEvcId(String evcId) { this.evcId = evcId; }
+}
diff --git a/svc/svcbase/src/main/java/com/cablelabs/vcpe/svc/svcbase/repository/EplRespository.java b/svc/svcbase/src/main/java/com/cablelabs/vcpe/svc/svcbase/repository/EplRespository.java
new file mode 100644
index 0000000..1142963
--- /dev/null
+++ b/svc/svcbase/src/main/java/com/cablelabs/vcpe/svc/svcbase/repository/EplRespository.java
@@ -0,0 +1,21 @@
+package com.cablelabs.vcpe.svc.svcbase.repository;
+
+import com.cablelabs.vcpe.svc.svcbase.model.Epl;
+
+import java.util.List;
+
+/**
+ * Created by steve on 5/25/15.
+ */
+public interface EplRespository
+{
+ // TODO add exceptions
+
+ Epl add(Epl epl); // returns null if already exists, otherwise returns stored epl
+ Epl get(String svcId); // returns null if not found, otherwise stored svc
+ Epl update(Epl epl); // returns null if did not exit, otherwise epl as it was previous to update (put in any case)
+ Epl delete(String svcId); // returns null if not found, otherwise svc as it was previous to delete
+ int count(); // number of Epl stored in the repo
+ public void dump(int tab); // print out contents of the repo
+ List<Epl> getAll();
+}
diff --git a/svc/svcbase/src/main/java/com/cablelabs/vcpe/svc/svcbase/repository/EplRespositoryInMem.java b/svc/svcbase/src/main/java/com/cablelabs/vcpe/svc/svcbase/repository/EplRespositoryInMem.java
new file mode 100644
index 0000000..af82c21
--- /dev/null
+++ b/svc/svcbase/src/main/java/com/cablelabs/vcpe/svc/svcbase/repository/EplRespositoryInMem.java
@@ -0,0 +1,91 @@
+package com.cablelabs.vcpe.svc.svcbase.repository;
+
+import com.cablelabs.vcpe.common.Dbg;
+import com.cablelabs.vcpe.svc.svcbase.model.Epl;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
+
+/**
+ * Created by steve on 5/24/15.
+ */
+
+
+/*
+ Singleton that contains a hashmap which holds instances of Epl objects, indexed by CiS ID
+ */
+
+public enum EplRespositoryInMem implements EplRespository {
+ INSTANCE; // Singleton
+
+ private Map<String, Epl> svcDB = new ConcurrentHashMap<>();
+
+ @Override
+ //--------------------------------------------------------
+ public Epl add(Epl epl)
+ //--------------------------------------------------------
+ {
+ if ( this.get(epl.getId()) != null ) {
+ return null;
+ }
+ svcDB.put(epl.getId(), epl);
+ return epl;
+ }
+
+ @Override
+ //--------------------------------------------------------
+ public Epl get(String svcId) {
+ return svcDB.get(svcId);
+ }
+ //--------------------------------------------------------
+
+ @Override
+ //--------------------------------------------------------
+ public Epl update(Epl epl)
+ //--------------------------------------------------------
+ {
+ // put returns null if epl did not exist, other returns epl as it stood prior to put
+ return svcDB.put(epl.getId(), epl);
+ }
+
+ @Override
+ //--------------------------------------------------------
+ public Epl delete(String svcId)
+ //--------------------------------------------------------
+ {
+ // remove returns null if svc did not exist, other returns svc as it stood prior to remove
+ return svcDB.remove(svcId);
+ }
+
+ @Override
+ //--------------------------------------------------------
+ public int count() {
+ return svcDB.size();
+ }
+ //--------------------------------------------------------
+
+ @Override
+ //--------------------------------------------------------
+ public List<Epl> getAll()
+ //--------------------------------------------------------
+ {
+ List<Epl> eplList = new ArrayList<Epl>(svcDB.values());
+ return eplList;
+ }
+
+ @Override
+ //--------------------------------------------------------
+ public void dump(int tab)
+ //--------------------------------------------------------
+ {
+ Dbg.p(tab, "Epl Repo: " + svcDB.size() + " entrie(s)");
+ int numSvc = 0;
+ for (Epl curEpl : svcDB.values()) {
+ numSvc++;
+ Dbg.p(tab+1, "<Entry " + numSvc+">");
+ curEpl.dump(tab+2);
+ }
+ }
+}