diff options
Diffstat (limited to 'apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao')
15 files changed, 727 insertions, 0 deletions
diff --git a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/DAOConstants.java b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/DAOConstants.java new file mode 100644 index 0000000..ab3b3f1 --- /dev/null +++ b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/DAOConstants.java @@ -0,0 +1,6 @@ +package org.onap.msb.apiroute.wrapper.dao; + +public class DAOConstants { + public static final String ROUTE_KIND = "route"; + public static final String SERVICE_KIND = "service"; +} diff --git a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/DAOFactory.java b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/DAOFactory.java new file mode 100644 index 0000000..0fb3e14 --- /dev/null +++ b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/DAOFactory.java @@ -0,0 +1,18 @@ +package org.onap.msb.apiroute.wrapper.dao; + +import org.onap.msb.apiroute.wrapper.dao.route.IRouteDAO; +import org.onap.msb.apiroute.wrapper.dao.route.RouteDAOImpl; +import org.onap.msb.apiroute.wrapper.dao.service.IServiceDAO; +import org.onap.msb.apiroute.wrapper.dao.service.ServiceDAOImpl; + +public class DAOFactory { + private static final IRouteDAO routeDAO = new RouteDAOImpl(); + private static final IServiceDAO serviceDAO = new ServiceDAOImpl(); + + public static IRouteDAO getRouteDAO(){ + return routeDAO; + } + public static IServiceDAO getServiceDAO(){ + return serviceDAO; + } +}
\ No newline at end of file diff --git a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/RedisAccessWrapper.java b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/RedisAccessWrapper.java new file mode 100644 index 0000000..06799b1 --- /dev/null +++ b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/RedisAccessWrapper.java @@ -0,0 +1,133 @@ +package org.onap.msb.apiroute.wrapper.dao; + +import org.onap.msb.apiroute.wrapper.util.JedisUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import redis.clients.jedis.Jedis; +import redis.clients.jedis.ScanParams; +import redis.clients.jedis.ScanResult; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +public class RedisAccessWrapper { + private static final Logger LOGGER = LoggerFactory.getLogger(RedisAccessWrapper.class); + //An iteration starts when the cursor is set to 0 + private static final String REDIS_SCAN_POINTER_NEW_ITERATION = "0"; + //An iteration terminated when the cursor returned by the server is 0 + private static final String REDIS_SCAN_POINTER_ITERATION_END = "0"; + private static final int REDIS_SCAN_COUNT = 50; + + + public static void save(String key,String value) throws Exception { + Jedis jedis = null; + try { + jedis = JedisUtil.borrowJedisInstance(); + jedis.set(key,value); + } finally { + JedisUtil.returnJedisInstance(jedis); + } + } + + public static String query(String key) throws Exception { + Jedis jedis = null; + String value = null; + try { + jedis = JedisUtil.borrowJedisInstance(); + value = jedis.get(key); + }finally { + JedisUtil.returnJedisInstance(jedis); + } + return value; + } + + public static long delete(String key) throws Exception { + Jedis jedis = null; + long reply = 0L; + try { + jedis = JedisUtil.borrowJedisInstance(); + reply = jedis.del(key); + } finally { + JedisUtil.returnJedisInstance(jedis); + } + return reply; + } + + public static boolean isExist(String key) throws Exception { + boolean isExist = false; + Jedis jedis = null; + try { + jedis = JedisUtil.borrowJedisInstance(); + isExist = jedis.exists(key); + } finally { + JedisUtil.returnJedisInstance(jedis); + } + return isExist; + } + + public static List<String> queryMultiKeys(String keyPattern) throws Exception { + Set<String> keySet = filterKeys(keyPattern); + List<String> valueList = new ArrayList<>(); + Jedis jedis = null; + try { + jedis = JedisUtil.borrowJedisInstance(); + for(String key : keySet){ + String value = jedis.get(key); + if(value !=null && !"".equals(value)){ + valueList.add(value); + } + } + } finally { + JedisUtil.returnJedisInstance(jedis); + } + return valueList; + } + + public static long deleteMultiKeys(String keyPattern) throws Exception { + Set<String> keySet = filterKeys(keyPattern); + long replySum = 0L; + Jedis jedis = null; + try { + jedis = JedisUtil.borrowJedisInstance(); + for(String key : keySet){ + long reply = jedis.del(key); + replySum = replySum + reply; + } + } finally { + JedisUtil.returnJedisInstance(jedis); + } + return replySum; + } + + /** + * filter the keys according to the given pattern + * using "scan" instead of using "keys", incrementally iterate the keys space + * @param pattern the input filter pattern + * @return the matched keys set + */ + public static Set<String> filterKeys(String pattern) throws Exception{ + long start = System.currentTimeMillis(); + Jedis jedis = null; + Set<String> filteredKeys = new HashSet<>(); + ScanParams scanParams = new ScanParams(); + scanParams.match(pattern); + scanParams.count(REDIS_SCAN_COUNT); + try { + jedis = JedisUtil.borrowJedisInstance(); + ScanResult<String> scanResult = jedis.scan(REDIS_SCAN_POINTER_NEW_ITERATION,scanParams); + filteredKeys.addAll(scanResult.getResult()); + while(!scanResult.getStringCursor().equals(REDIS_SCAN_POINTER_ITERATION_END)){ + scanResult = jedis.scan(scanResult.getStringCursor(),scanParams); + filteredKeys.addAll(scanResult.getResult()); + } + } finally { + JedisUtil.returnJedisInstance(jedis); + } + long end = System.currentTimeMillis(); + long costTime = end-start; + LOGGER.info("filterKeys " + pattern + " count:" + filteredKeys.size() + " cost: " + costTime); + return filteredKeys; + } +} diff --git a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/route/IRouteDAO.java b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/route/IRouteDAO.java new file mode 100644 index 0000000..f2f51c1 --- /dev/null +++ b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/route/IRouteDAO.java @@ -0,0 +1,18 @@ +package org.onap.msb.apiroute.wrapper.dao.route; + +import java.util.List; + +import org.onap.msb.apiroute.wrapper.dao.route.bean.RouteInfo; + +public interface IRouteDAO { + public void saveRoute(String key, RouteInfo routeInfo) throws Exception; + + public RouteInfo queryRoute(String key) throws Exception; + + public List<RouteInfo> queryMultiRoute(String keyPattern) throws Exception; + + public long deleteRoute(String key) throws Exception; + + public long deleteMultiRoute(String keyPattern) throws Exception; + +} diff --git a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/route/RouteDAOImpl.java b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/route/RouteDAOImpl.java new file mode 100644 index 0000000..83e868b --- /dev/null +++ b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/route/RouteDAOImpl.java @@ -0,0 +1,63 @@ +package org.onap.msb.apiroute.wrapper.dao.route; + +import com.fasterxml.jackson.core.JsonProcessingException; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.onap.msb.apiroute.wrapper.dao.RedisAccessWrapper; +import org.onap.msb.apiroute.wrapper.dao.route.bean.RouteInfo; +import org.onap.msb.apiroute.wrapper.util.Jackson; + +public class RouteDAOImpl implements IRouteDAO{ + public void saveRoute(String key, RouteInfo routeInfo) throws Exception { + String routeInfoStr = null; + // change orginal url from “/” to empty string accord to the rewrite rule while forwarding + if("/".equals(routeInfo.getSpec().getUrl())){ + routeInfo.getSpec().setUrl(""); + } + try { + routeInfoStr = Jackson.MAPPER.writeValueAsString(routeInfo); + } catch (JsonProcessingException e) { + throw new Exception("error occurred while parsing RouteInfo to json data",e); + } + RedisAccessWrapper.save(key, routeInfoStr); + } + + public RouteInfo queryRoute(String key) throws Exception { + RouteInfo routeInfo = null; + String routeInfoStr = RedisAccessWrapper.query(key); + if (null == routeInfoStr || "".equals(routeInfoStr)) + return null; + try { + routeInfo = Jackson.MAPPER.readValue(routeInfoStr, RouteInfo.class); + } catch (IOException e) { + throw new Exception("error occurred while parsing the redis json data to RouteInfo",e); + } + return routeInfo; + } + + public List<RouteInfo> queryMultiRoute(String keyPattern) throws Exception { + List<String> routeInfoStrList = RedisAccessWrapper.queryMultiKeys(keyPattern); + List<RouteInfo> routeInfoList = new ArrayList<>(); + for (String routeInfoStr : routeInfoStrList) { + RouteInfo routeInfo = null; + try { + routeInfo = Jackson.MAPPER.readValue(routeInfoStr, RouteInfo.class); + routeInfoList.add(routeInfo); + } catch (IOException e) { + throw new Exception("error occurred while parsing the redis json data to RouteInfo",e); + } + } + return routeInfoList; + } + + public long deleteRoute(String key) throws Exception { + return RedisAccessWrapper.delete(key); + } + + public long deleteMultiRoute(String keyPattern) throws Exception{ + return RedisAccessWrapper.deleteMultiKeys(keyPattern); + } +}
\ No newline at end of file diff --git a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/route/bean/Metadata.java b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/route/bean/Metadata.java new file mode 100644 index 0000000..3e11fcc --- /dev/null +++ b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/route/bean/Metadata.java @@ -0,0 +1,48 @@ +package org.onap.msb.apiroute.wrapper.dao.route.bean; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +@AllArgsConstructor +@NoArgsConstructor +@Getter @Setter +public class Metadata { + private String name; + private String namespace; + private String uid = ""; + //@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") + //private Date creationTimestamp; + @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssXXX") + private Date updateTimestamp; + private Map labels = new HashMap(); + private String[] annotations = null; + + /* + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Metadata metadata = (Metadata) o; + return Objects.equals(name, metadata.name) && + Objects.equals(namespace, metadata.namespace) && + Objects.equals(uid, metadata.uid) && + //Objects.equals(creationTimestamp, metadata.creationTimestamp) && + Objects.equals(updateTimestamp, metadata.updateTimestamp) && + Objects.equals(labels, metadata.labels) && + Objects.equals(annotations, metadata.annotations); + } + + @Override + public int hashCode() { + //return Objects.hash(name, namespace, uid, creationTimestamp, updateTimestamp, labels, annotations); + return Objects.hash(name, namespace, uid, updateTimestamp, labels, annotations); + } + */ +} diff --git a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/route/bean/Node.java b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/route/bean/Node.java new file mode 100644 index 0000000..a328c3c --- /dev/null +++ b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/route/bean/Node.java @@ -0,0 +1,32 @@ +package org.onap.msb.apiroute.wrapper.dao.route.bean; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@AllArgsConstructor +@NoArgsConstructor +@Getter @Setter +public class Node { + private String ip; + private int port; + private int weight=0; + + /* + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Node node = (Node) o; + return Objects.equals(port, node.port) && + Objects.equals(weight, node.weight) && + Objects.equals(ip, node.ip); + } + + @Override + public int hashCode() { + return Objects.hash(ip, port, weight); + } + */ +}
\ No newline at end of file diff --git a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/route/bean/RouteInfo.java b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/route/bean/RouteInfo.java new file mode 100644 index 0000000..e5ab7bf --- /dev/null +++ b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/route/bean/RouteInfo.java @@ -0,0 +1,79 @@ +package org.onap.msb.apiroute.wrapper.dao.route.bean; + +import org.onap.msb.apiroute.wrapper.dao.DAOConstants; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@AllArgsConstructor +@NoArgsConstructor +@Getter +@Setter +public class RouteInfo { + private String kind = DAOConstants.ROUTE_KIND; + private String apiVersion = ""; + private String status = ""; + private Metadata metadata; + private Spec spec; + + /** + Example route: + { + "kind" : "route", + "apiVersion" : "v1", + "status" : "1" + "metadata" : { + "name" : "kubernetes", + "namespace" : "default", + "uid" : "0b6f198e-c6ab-11e6-86aa-fa163ee2118b", + "creationTimestamp" : "2016-12-20T11:54:21Z", + "updateTimestamp" : "", + "labels" : { + "component" : "apiserver", + "provider" : "kubernetes" + }, + "annotations" : {} + }, + "spec" : { + "visualRange" : 0, + "url" : "", + "publish_port" : "", + "host" : "", + "apijson" : "", + "apijsontype" : "" + "metricsUrl" : "" + "consulServiceName" : "" + "useOwnUpstream" : "" //是否使用该服务独立的upstream转发 + "publishProtocol" : "", //发布地址使用http还是http协议 + "enable_ssl" : "0|1", //转发时,使用http还是http转发。http:0/https:1 + "controll" : "", //是否可以修改 + "nodes" : [{ + "ip" : 10.10.10.2, + "port" : 8080, + "weight" : "" + } + ], + } +} + */ + /* + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + RouteInfo that = (RouteInfo) o; + return Objects.equals(kind, that.kind) && + Objects.equals(apiVersion, that.apiVersion) && + Objects.equals(status, that.status) && + Objects.equals(metadata, that.metadata) && + Objects.equals(spec, that.spec); + } + + @Override + public int hashCode() { + return Objects.hash(kind, apiVersion, status, metadata, spec); + } + */ +} diff --git a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/route/bean/Spec.java b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/route/bean/Spec.java new file mode 100644 index 0000000..8e9a54b --- /dev/null +++ b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/route/bean/Spec.java @@ -0,0 +1,52 @@ +package org.onap.msb.apiroute.wrapper.dao.route.bean; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@AllArgsConstructor +@NoArgsConstructor +@Getter @Setter +public class Spec { + private String visualRange = ""; + private String url = ""; + private String publish_port; + private String host = ""; + private String apijson = ""; + private String apijsontype = ""; + private String metricsUrl = ""; + private String consulServiceName = ""; + private String useOwnUpstream = ""; + private String publish_protocol = ""; + private boolean enable_ssl = false; + private String control = ""; + private Node[] nodes; + + /* + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Spec spec = (Spec) o; + return Objects.equals(enable_ssl, spec.enable_ssl) && + Objects.equals(visualRange, spec.visualRange) && + Objects.equals(url, spec.url) && + Objects.equals(publish_port, spec.publish_port) && + Objects.equals(host, spec.host) && + Objects.equals(apijson, spec.apijson) && + Objects.equals(apijsontype, spec.apijsontype) && + Objects.equals(metricsUrl, spec.metricsUrl) && + Objects.equals(consulServiceName, spec.consulServiceName) && + Objects.equals(useOwnUpstream, spec.useOwnUpstream) && + Objects.equals(publish_protocol, spec.publish_protocol) && + Objects.equals(control, spec.control) && + Arrays.equals(nodes, spec.nodes); + } + + @Override + public int hashCode() { + return Objects.hash(visualRange, url, publish_port, host, apijson, apijsontype, metricsUrl, consulServiceName, useOwnUpstream, publish_protocol, enable_ssl, control, nodes); + } + */ +} diff --git a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/service/IServiceDAO.java b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/service/IServiceDAO.java new file mode 100644 index 0000000..d63f656 --- /dev/null +++ b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/service/IServiceDAO.java @@ -0,0 +1,17 @@ +package org.onap.msb.apiroute.wrapper.dao.service; + +import java.util.List; + +import org.onap.msb.apiroute.wrapper.dao.service.bean.ServiceInfo; + +public interface IServiceDAO { + public void saveService(String key, ServiceInfo serviceInfo) throws Exception; + + public ServiceInfo queryService(String key) throws Exception; + + public List<ServiceInfo> queryMultiService(String keyPattern) throws Exception; + + public long deleteService(String key) throws Exception; + + public long deleteMultiService(String keyPattern) throws Exception; +} diff --git a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/service/ServiceDAOImpl.java b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/service/ServiceDAOImpl.java new file mode 100644 index 0000000..e9f4586 --- /dev/null +++ b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/service/ServiceDAOImpl.java @@ -0,0 +1,59 @@ +package org.onap.msb.apiroute.wrapper.dao.service; + +import com.fasterxml.jackson.core.JsonProcessingException; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.onap.msb.apiroute.wrapper.dao.RedisAccessWrapper; +import org.onap.msb.apiroute.wrapper.dao.service.bean.ServiceInfo; +import org.onap.msb.apiroute.wrapper.util.Jackson; + +public class ServiceDAOImpl implements IServiceDAO{ + public void saveService(String key, ServiceInfo serviceInfo) throws Exception { + String serviceInfoStr = null; + try { + serviceInfoStr = Jackson.MAPPER.writeValueAsString(serviceInfo); + } catch (JsonProcessingException e) { + throw new Exception("error occurred while parsing ServiceInfo to json data",e); + } + RedisAccessWrapper.save(key, serviceInfoStr); + } + + public ServiceInfo queryService(String key) throws Exception { + ServiceInfo serviceInfo = null; + String serviceInfoStr = RedisAccessWrapper.query(key); + if (null == serviceInfoStr || "".equals(serviceInfoStr)) + return null; + try { + serviceInfo = Jackson.MAPPER.readValue(serviceInfoStr, ServiceInfo.class); + } catch (IOException e) { + throw new Exception("error occurred while parsing the redis json data to ServiceInfo",e); + } + return serviceInfo; + } + + public List<ServiceInfo> queryMultiService(String keyPattern) throws Exception { + List<String> serviceInfoStrList = RedisAccessWrapper.queryMultiKeys(keyPattern); + List<ServiceInfo> routeInfoList = new ArrayList<>(); + for (String serviceInfoStr : serviceInfoStrList) { + ServiceInfo serviceInfo = null; + try { + serviceInfo = Jackson.MAPPER.readValue(serviceInfoStr, ServiceInfo.class); + routeInfoList.add(serviceInfo); + } catch (IOException e) { + throw new Exception("error occurred while parsing the redis json data to ServiceInfo",e); + } + } + return routeInfoList; + } + + public long deleteService(String key) throws Exception { + return RedisAccessWrapper.delete(key); + } + + public long deleteMultiService(String keyPattern) throws Exception{ + return RedisAccessWrapper.deleteMultiKeys(keyPattern); + } +}
\ No newline at end of file diff --git a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/service/bean/Metadata.java b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/service/bean/Metadata.java new file mode 100644 index 0000000..6ce6126 --- /dev/null +++ b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/service/bean/Metadata.java @@ -0,0 +1,50 @@ +package org.onap.msb.apiroute.wrapper.dao.service.bean; + +import com.fasterxml.jackson.annotation.JsonFormat; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.util.Date; +import java.util.HashMap; +import java.util.Map; + +@AllArgsConstructor +@NoArgsConstructor +@Getter @Setter +public class Metadata { + private String name; + private String namespace; + private String uid = ""; + //@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") + //private Date creationTimestamp; + // @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8") + @JsonFormat(pattern = "yyyy-MM-dd'T'HH:mm:ssXXX") + private Date updateTimestamp; + private Map labels = new HashMap(); + //private String[] annotations = new String[]{}; + private String[] annotations = null; + + /* + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Metadata metadata = (Metadata) o; + return Objects.equals(name, metadata.name) && + Objects.equals(namespace, metadata.namespace) && + Objects.equals(uid, metadata.uid) && + //Objects.equals(creationTimestamp, metadata.creationTimestamp) && + Objects.equals(updateTimestamp, metadata.updateTimestamp) && + Objects.equals(labels, metadata.labels) && + Objects.equals(annotations, metadata.annotations); + } + + @Override + public int hashCode() { + //return Objects.hash(name, namespace, uid, creationTimestamp, updateTimestamp, labels, annotations); + return Objects.hash(name, namespace, uid, updateTimestamp, labels, annotations); + } + */ +} diff --git a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/service/bean/Node.java b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/service/bean/Node.java new file mode 100644 index 0000000..fecf4bd --- /dev/null +++ b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/service/bean/Node.java @@ -0,0 +1,32 @@ +package org.onap.msb.apiroute.wrapper.dao.service.bean; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@AllArgsConstructor +@NoArgsConstructor +@Getter @Setter +public class Node { + private String ip; + private String port; + private int ttl=-1; + + /* + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Node node = (Node) o; + return Objects.equals(port, node.port) && + Objects.equals(ttl, node.ttl) && + Objects.equals(ip, node.ip); + } + + @Override + public int hashCode() { + return Objects.hash(ip, port, ttl); + } + */ +}
\ No newline at end of file diff --git a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/service/bean/ServiceInfo.java b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/service/bean/ServiceInfo.java new file mode 100644 index 0000000..01ab3a9 --- /dev/null +++ b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/service/bean/ServiceInfo.java @@ -0,0 +1,76 @@ +package org.onap.msb.apiroute.wrapper.dao.service.bean; + +import org.onap.msb.apiroute.wrapper.dao.DAOConstants; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@AllArgsConstructor +@NoArgsConstructor +@Getter +@Setter +public class ServiceInfo { + private String kind = DAOConstants.SERVICE_KIND; + private String apiVersion = ""; + private String status = ""; + private Metadata metadata; + private Spec spec; + + /** + Example Service: + { + "kind" : "service", + "apiVersion" : "v1", + "metadata" : { + "name" : "kubernetes", + "namespace" : "default", + "uid" : "0b6f198e-c6ab-11e6-86aa-fa163ee2118b", + "creationTimestamp" : "2016-12-20T11:54:21Z", + "labels" : { + "component" : "apiserver", + "provider" : "kubernetes" + }, + "annotations" : {} + }, + "spec" : { + "visualRange" : 0, + "url" : "", + "path" : "", + "publish_port" : "", + "host" : "", + "protocol" : "", + "lb_policy" : "", + "enable_ssl" : "0|1", //转发时,使用http还是http转发。http:0/https:1 + "nodes" : [{ + "ip" : 10.10.10.2, + "port" : 8080, + "ttl" : + } + ], + } + "status" : "" + } + + */ + + /* + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + ServiceInfo that = (ServiceInfo) o; + return Objects.equals(kind, that.kind) && + Objects.equals(apiVersion, that.apiVersion) && + Objects.equals(status, that.status) && + Objects.equals(metadata, that.metadata) && + Objects.equals(spec, that.spec); + } + + @Override + public int hashCode() { + return Objects.hash(kind, apiVersion, status, metadata, spec); + } + */ +} diff --git a/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/service/bean/Spec.java b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/service/bean/Spec.java new file mode 100644 index 0000000..65e769b --- /dev/null +++ b/apiroute/apiroute-service/src/main/java/org/onap/msb/apiroute/wrapper/dao/service/bean/Spec.java @@ -0,0 +1,44 @@ +package org.onap.msb.apiroute.wrapper.dao.service.bean; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@AllArgsConstructor +@NoArgsConstructor +@Getter @Setter +public class Spec { + private String visualRange = ""; + private String url = ""; + private String path = ""; + private String publish_port; + private String host = ""; + private String protocol = ""; + private String lb_policy = ""; + private boolean enable_ssl = false; + private Node[] nodes; + + /* + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Spec spec = (Spec) o; + return Objects.equals(enable_ssl, spec.enable_ssl) && + Objects.equals(visualRange, spec.visualRange) && + Objects.equals(url, spec.url) && + Objects.equals(path, spec.path) && + Objects.equals(publish_port, spec.publish_port) && + Objects.equals(host, spec.host) && + Objects.equals(protocol, spec.protocol) && + Objects.equals(lb_policy, spec.lb_policy) && + Arrays.equals(nodes, spec.nodes); + } + + @Override + public int hashCode() { + return Objects.hash(visualRange, url, path, publish_port, host, protocol, lb_policy, enable_ssl, nodes); + } + */ +} |