finalize alto-manager and add README.md file 88/19988/1
authordongshu <dongshu@factual.com>
Sun, 10 May 2015 16:01:59 +0000 (00:01 +0800)
committerdongshu <dongshu@factual.com>
Sun, 10 May 2015 16:01:59 +0000 (00:01 +0800)
Change-Id: I4560133eb1d9029e3e187e1fe0490978bd608765
Signed-off-by: dongshu <dongshu@factual.com>
26 files changed:
alto-commons/src/main/java/org/opendaylight/alto/commons/types/converter/RFC2ModelCostMapConverter.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/converter/RFC2ModelEndpointAddressGroupConverter.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/converter/RFC2ModelEndpointPropMapConverter.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/converter/RFC2ModelNetworkMapConverter.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/converter/RFC2ModelNetworkMapDataConverter.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/model150404/ModelCostMapMeta.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/model150404/ModelCostType.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/model150404/ModelDependentVtag.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/model150404/ModelEndpoint.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/model150404/ModelEndpointAddressGroup.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/model150404/ModelEndpointPropertyMap.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/model150404/ModelJSONMapper.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/model150404/ModelNetworkMap.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/rfc7285/RFC7285CostType.java
alto-commons/src/main/java/org/opendaylight/alto/commons/types/rfc7285/RFC7285JSONMapper.java
alto-karaf/pom.xml
alto-manager/README.md [new file with mode: 0644]
alto-manager/examples/cost_maps_rfc [new file with mode: 0644]
alto-manager/examples/endpoint_property_map_rfc [new file with mode: 0644]
alto-manager/examples/network_maps_rfc [new file with mode: 0644]
alto-manager/src/main/java/org/opendaylight/alto/manager/AltoCreate.java
alto-manager/src/main/java/org/opendaylight/alto/manager/AltoDelete.java
alto-manager/src/main/java/org/opendaylight/alto/manager/AltoManager.java
alto-manager/src/main/java/org/opendaylight/alto/manager/AltoManagerConstants.java
alto-manager/src/main/java/org/opendaylight/alto/manager/AltoSet.java
pom.xml

index bf66d89157ab4d91242d81759ca786f81c0c876f..62a278a4538c62da68c3060e4821a53dc078a196 100644 (file)
@@ -5,7 +5,6 @@ import org.opendaylight.alto.commons.helper.Converter;
 import org.opendaylight.alto.commons.types.model150404.ModelCostMap;
 import org.opendaylight.alto.commons.types.model150404.ModelCostMapData;
 import org.opendaylight.alto.commons.types.rfc7285.RFC7285CostMap;
-import org.opendaylight.alto.commons.types.rfc7285.RFC7285JSONMapper;
 
 public class RFC2ModelCostMapConverter 
     extends Converter<RFC7285CostMap, ModelCostMap>{
@@ -24,7 +23,8 @@ public class RFC2ModelCostMapConverter
   protected Object _convert() {
     ModelCostMap out = new ModelCostMap();
     out.rid = getCostMapResourceId(in());
-    out.tag = "";
+    //TODO: replace the dummy one in the future
+    out.tag = "da65eca2eb7a10ce8b059740b0b2e3f8eb1d4786";
     
     out.meta = metaConv.convert(in().meta);
     out.map = new LinkedList<ModelCostMapData>();
@@ -37,16 +37,6 @@ public class RFC2ModelCostMapConverter
     return out;
   }
   
-  public static void main(String[] args) {
-    String rfcCostMap = "{\"meta\":{\"dependent-vtags\":[{\"resource-id\":\"my-default-network-map\",\"tag\":\"3ee2cb7e8d63d9fab71b9b34cbf764436315542e\"}],\"cost-type\":{\"cost-mode\":\"numerical\",\"cost-metric\":\"routingcost\"}},\"cost-map\":{\"PID1\":{\"PID1\":1,\"PID2\":5,\"PID3\":10},\"PID2\":{\"PID1\":5,\"PID2\":1,\"PID3\":15},\"PID3\":{\"PID1\":20,\"PID2\":15}}}";
-    try {
-      RFC7285JSONMapper mapper = new RFC7285JSONMapper();
-      RFC7285CostMap costMap = mapper.asCostMap(rfcCostMap);
-    } catch (Exception e) {
-      e.printStackTrace();
-    }
-  }
-  
   private String getCostMapResourceId(RFC7285CostMap costMap) {
     String networkMapRID = costMap.meta.netmap_tags.get(0).rid;
     String costMetric = costMap.meta.costType.metric;
index cf80fa15f244826789f363debb36891dc4227279..29c214679f5105915afb76ce747f60114e0faa18 100644 (file)
@@ -22,14 +22,14 @@ public class RFC2ModelEndpointAddressGroupConverter
         List<ModelEndpointAddressGroup> out = new LinkedList<ModelEndpointAddressGroup>();
         if ((in().ipv4 != null) && (!in().ipv4.isEmpty())) {
             ModelEndpointAddressGroup v4 = new ModelEndpointAddressGroup();
-            v4.setJSONAddressType(ModelEndpointAddressGroup.IPV4);
-            v4.setJSONEndpointPrefix(in().ipv4);
+            v4.type = ModelEndpointAddressGroup.IPV4;
+            v4.prefixes = in().ipv4;
             out.add(v4);
         }
         if ((in().ipv6 != null) && (!in().ipv6.isEmpty())) {
             ModelEndpointAddressGroup v6 = new ModelEndpointAddressGroup();
-            v6.setJSONAddressType(ModelEndpointAddressGroup.IPV6);
-            v6.setJSONEndpointPrefix(in().ipv6);
+            v6.type = ModelEndpointAddressGroup.IPV6;
+            v6.prefixes = in().ipv6;
             out.add(v6);
         }
         return out;
index 362354d8a2d110d9f0b999cdadfdd84afc2c763b..5b81cadbffa56d14cf066a1633bb5b790445b581 100644 (file)
@@ -1,5 +1,9 @@
 package org.opendaylight.alto.commons.types.converter;
 
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.LinkedList;
 import java.util.Map;
 
@@ -18,15 +22,18 @@ public class RFC2ModelEndpointPropMapConverter
   protected Object _convert() {
     ModelEndpointPropertyMap out = new ModelEndpointPropertyMap();
     out.endpointPropertyMeta = convertMeta(in().meta);
-    
     out.properties = new LinkedList<ModelEndpointProperties>();
-    
     for (String endpoint : in().map.keySet()) {
       out.properties.add(convertEndpointProperty(endpoint, in().map.get(endpoint)));
     }
     return out;
   }
   
+  protected static String readFromFile(String path) throws IOException {
+    return new String(Files.readAllBytes(Paths.get(path)),
+        StandardCharsets.UTF_8);
+  }
+  
   private ModelEndpointPropertyMeta convertMeta(RFC7285EndpointPropertyMap.Meta meta) {
     ModelEndpointPropertyMeta endpointPropertyMeta = new ModelEndpointPropertyMeta();
     
index f8db666d3e16d83403de2e88aea02846454dcfe3..db4eccf83279cef136ee1f389fc1e8b1865db928 100644 (file)
@@ -1,8 +1,8 @@
 package org.opendaylight.alto.commons.types.converter;
 
 import org.opendaylight.alto.commons.helper.Converter;
-import org.opendaylight.alto.commons.types.rfc7285.RFC7285NetworkMap;
 import org.opendaylight.alto.commons.types.model150404.ModelNetworkMap;
+import org.opendaylight.alto.commons.types.rfc7285.RFC7285NetworkMap;
 
 public class RFC2ModelNetworkMapConverter
         extends Converter<RFC7285NetworkMap, ModelNetworkMap> {
@@ -15,7 +15,7 @@ public class RFC2ModelNetworkMapConverter
     public RFC2ModelNetworkMapConverter(RFC7285NetworkMap _in) {
         super(_in);
     }
-
+    
     @Override
     public Object _convert() {
         ModelNetworkMap out = new ModelNetworkMap();
index 2d5532e3e860df526173fc1a00b81b8652ff909f..697340182b3da984b3d37ccc3e256d5502e6a7ef 100644 (file)
@@ -26,8 +26,8 @@ public class RFC2ModelNetworkMapDataConverter
 
         for (Map.Entry<String, RFC7285Endpoint.AddressGroup> rep: in().entrySet()) {
             ModelEndpoint mep = new ModelEndpoint();
-            mep.setJSONPid(rep.getKey());
-            mep.setJSONEndpointAddressGroup(conv.convert(rep.getValue()));
+            mep.pid = rep.getKey();
+            mep.addressGroup = conv.convert(rep.getValue());
             out.add(mep);
         }
         return out;
index f657e36520c590d8eb77b90a40d73639e6ca9eeb..7f142a8f22a0034a594af8d720a0dc1fefbd32b5 100644 (file)
@@ -18,7 +18,7 @@ public class ModelCostMapMeta implements Meta  {
   public List<ModelDependentVtag> dependentVtags = new LinkedList<ModelDependentVtag>();
   
   @JsonProperty("alto-service:cost-type")
-  public ModelCostType costType = null;
+  public ModelCostType costType = new ModelCostType();
   
   @JsonIgnore
   @Override
index e184c5dae600079fadaaa5ecfceda895bcf19d3e..1a3af3685c42f99d1ae0f7f67f7b46e1de75af63 100644 (file)
@@ -12,8 +12,11 @@ import com.fasterxml.jackson.annotation.JsonProperty;
 
 public class ModelCostType implements CostType {
 
+  @JsonIgnore
   public static final String NUMERICAL = "Numerical";
-  public static final String Ordinal = "Ordinal";
+  
+  @JsonIgnore
+  public static final String ORDINAL = "Ordinal";
   
   @JsonProperty("alto-service:cost-mode")
   public String costMode = null;
@@ -24,6 +27,7 @@ public class ModelCostType implements CostType {
   @JsonProperty("alto-service:description")
   public String description = null;
   
+  @JsonIgnore
   @Override
   public Class<? extends DataContainer> getImplementedInterface() {
     return CostType.class;
@@ -41,7 +45,7 @@ public class ModelCostType implements CostType {
     switch(costMode) {
     case NUMERICAL:
       return CostMode.Numerical;
-    case Ordinal:
+    case ORDINAL:
       return CostMode.Ordinal;
     default:
       throw new RuntimeException("Non-Supported cost mode."); 
index 33abfc300c12f054a9548e789e1fe2f59705f091..32b0803b64756474a2ea8c66e0677c0e75fdcf7d 100644 (file)
@@ -13,10 +13,10 @@ import com.fasterxml.jackson.annotation.JsonProperty;
 public class ModelDependentVtag implements DependentVtags {
 
   @JsonProperty("alto-service:resource-id")
-  public String rid = null;
+  public String rid = "";
   
   @JsonProperty("alto-service:tag")
-  public String vTag = null;
+  public String vTag = "";
   
   @JsonIgnore
   @Override
index 277bfa2cc27844c4345c2f3c6970e91a31c213dc..8513ca296e885444b96b776ffd6b2d47bc57573c 100644 (file)
@@ -14,20 +14,12 @@ import com.fasterxml.jackson.annotation.JsonIgnore;
 
 public class ModelEndpoint implements Map {
 
-    @JsonIgnore
-    protected PidName pid = null;
-
-    @JsonIgnore
-    protected List<EndpointAddressGroup> data = new LinkedList<EndpointAddressGroup>();
-
-    public ModelEndpoint() {
-    }
-
-    public ModelEndpoint(Map model) {
-        this.pid = model.getPid();
-        this.setEndpointAddressGroup(model.getEndpointAddressGroup());
-    }
+    @JsonProperty("alto-service:pid")
+    public String pid = null;
 
+    @JsonProperty("alto-service:endpoint-address-group")
+    public List<ModelEndpointAddressGroup> addressGroup = new LinkedList<ModelEndpointAddressGroup>();
+    
     @JsonIgnore
     @Override
     public Class<Map> getImplementedInterface() {
@@ -43,43 +35,18 @@ public class ModelEndpoint implements Map {
     @JsonIgnore
     @Override
     public MapKey getKey() {
-        return new MapKey(pid);
+        return new MapKey(getPid());
     }
 
     @JsonIgnore
     @Override
     public PidName getPid() {
-        return pid;
-    }
-
-    @JsonProperty("alto-service:pid")
-    public String getJSONPid() {
-        return pid.getValue();
-    }
-
-    @JsonProperty("alto-service:pid")
-    public void setJSONPid(String pid) {
-        this.pid = new PidName(pid);
+        return new PidName(pid);
     }
 
     @JsonIgnore
     @Override
     public List<EndpointAddressGroup> getEndpointAddressGroup() {
-        return data;
-    }
-
-    @JsonIgnore
-    public void setEndpointAddressGroup(List<EndpointAddressGroup> rhs) {
-        data = new LinkedList<EndpointAddressGroup>(rhs);
-    }
-
-    @JsonProperty("alto-service:endpoint-address-group")
-    public List<EndpointAddressGroup> getJSONEndpointAddressGroup() {
-        return data;
-    }
-
-    @JsonProperty("alto-service:endpoint-address-group")
-    public void setJSONEndpointAddressGroup(List<ModelEndpointAddressGroup> rhs) {
-        data = new LinkedList<EndpointAddressGroup>(rhs);
+        return new LinkedList<EndpointAddressGroup>(addressGroup);
     }
 }
index bf70734a3bf38b52992d803d633cfbe221ab7c3e..375cf49641446bcdae0645e8622a33935ab4b755 100644 (file)
 package org.opendaylight.alto.commons.types.model150404;
 
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.endpoint.address.group.EndpointAddressGroup;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.EndpointAddressType;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.endpoint.address.group.EndpointAddressGroupKey;
+import java.util.LinkedList;
+import java.util.List;
+
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefix;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefixBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.EndpointAddressType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.endpoint.address.group.EndpointAddressGroup;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.alto.service.types.rev150404.endpoint.address.group.EndpointAddressGroupKey;
 import org.opendaylight.yangtools.yang.binding.Augmentation;
 
-import java.util.ArrayList;
-import java.util.List;
-import java.util.LinkedList;
-
-import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonProperty;
 
 public class ModelEndpointAddressGroup implements EndpointAddressGroup {
 
-    public static final String IPV4 = "ipv4";
-    public static final String IPV6 = "ipv6";
-
     @JsonIgnore
-    protected EndpointAddressType type;
-
-    @JsonIgnore
-    protected List<IpPrefix> data = new LinkedList<IpPrefix>();
-
+    public static final String IPV4 = "ipv4";
+    
     @JsonIgnore
-    protected List<String> prefixes = new LinkedList<String>();
+    public static final String IPV6 = "ipv6";
 
-    public ModelEndpointAddressGroup() {
-    }
+    @JsonProperty("alto-service:address-type")
+    public String type;
 
-    public ModelEndpointAddressGroup(EndpointAddressGroup model) {
-    }
+    @JsonProperty("alto-service:endpoint-prefix")
+    public List<String> prefixes = new LinkedList<String>();
 
     @JsonIgnore
     @Override
     public Class<EndpointAddressGroup> getImplementedInterface() {
-            return EndpointAddressGroup.class;
+      return EndpointAddressGroup.class;
     }
 
     @JsonIgnore
     @Override
     public EndpointAddressType getAddressType() {
-        return type;
-    }
-
-    @JsonProperty("alto-service:address-type")
-    public String getJSONAddressType() {
-        if (type == null)
-            return null;
-        if (EndpointAddressType.Enumeration.Ipv4.equals(type.getEnumeration()))
-            return IPV4;
-        if (EndpointAddressType.Enumeration.Ipv6.equals(type.getEnumeration()))
-            return IPV6;
-        return "unsupported";
-    }
-
-    @JsonProperty
-    public void setJSONAddressType(String type) {
-        if (IPV4.equals(type))
-            this.type = new EndpointAddressType(EndpointAddressType.Enumeration.Ipv4);
-        if (IPV6.equals(type))
-            this.type = new EndpointAddressType(EndpointAddressType.Enumeration.Ipv6);
-        this.type = null;
+      if (IPV4.equals(type))
+        return new EndpointAddressType(EndpointAddressType.Enumeration.Ipv4);
+      if (IPV6.equals(type))
+        return new EndpointAddressType(EndpointAddressType.Enumeration.Ipv6);
+      throw new java.lang.UnsupportedOperationException("Unsupported AddressType");
     }
 
     @JsonIgnore
     @Override
-    public List<IpPrefix> getEndpointPrefix() {
-        return data;
-    }
-
-    @JsonIgnore
-    public void setEndpointPrefix(List<IpPrefix> rhs) {
-        data = new LinkedList<IpPrefix>(rhs);
-        prefixes = new LinkedList<String>();
-        for (IpPrefix p: rhs) {
-            prefixes.add(p.getValue().toString());
-        }
-    }
-
-    @JsonProperty("alto-service:endpoint-prefix")
-    public List<String> getJSONEndpointPrefix() {
-        return prefixes;
-    }
-
-    @JsonProperty("alto-service:endpoint-prefix")
-    public void setJSONEndpointPrefix(List<String> rhs) {
-        prefixes = rhs;
-        data = new LinkedList<IpPrefix>();
-        for (String p: rhs) {
-            data.add(IpPrefixBuilder.getDefaultInstance(p));
-        }
+    public <E extends Augmentation<EndpointAddressGroup>> E getAugmentation(Class<E> augmentationType) {
+      return null;
     }
 
     @JsonIgnore
     @Override
-    public EndpointAddressGroupKey getKey() {
-        return new EndpointAddressGroupKey(type);
+    public List<IpPrefix> getEndpointPrefix() {
+      List<IpPrefix> ipPrefixes = new LinkedList<IpPrefix>();
+      for (String prefix : prefixes) {
+        ipPrefixes.add(IpPrefixBuilder.getDefaultInstance(prefix));
+      }
+      return ipPrefixes;
     }
 
     @JsonIgnore
     @Override
-    public <E extends Augmentation<EndpointAddressGroup>> E getAugmentation(Class<E> augmentationType) {
-        return null;
+    public EndpointAddressGroupKey getKey() {
+      return new EndpointAddressGroupKey(getAddressType());
     }
 }
index aa517819be39cec27fa2ce62933e34340ed99e51..dfe3f41ad590277b38fbb7f367b1ef04910f4672 100644 (file)
@@ -14,7 +14,7 @@ import com.fasterxml.jackson.annotation.JsonProperty;
 public class ModelEndpointPropertyMap implements EndpointPropertyMap {
 
   @JsonProperty("alto-service:meta")
-  public ModelEndpointPropertyMeta endpointPropertyMeta = null;
+  public ModelEndpointPropertyMeta endpointPropertyMeta = new ModelEndpointPropertyMeta();
   
   @JsonProperty("alto-service:endpoint-properties")
   public List<ModelEndpointProperties> properties = new LinkedList<ModelEndpointProperties>();
@@ -36,5 +36,4 @@ public class ModelEndpointPropertyMap implements EndpointPropertyMap {
   public Meta getMeta() {
     return endpointPropertyMeta;
   }
-
 }
index c8b2dff3537ccd676c990305eb68d36852c1c26f..84dc470f0e7b3b775493f4325eb6280bed603900 100644 (file)
@@ -1,6 +1,8 @@
 package org.opendaylight.alto.commons.types.model150404;
 
 import java.io.IOException;
+import java.util.Arrays;
+import java.util.List;
 
 import com.fasterxml.jackson.annotation.JsonInclude.Include;
 import com.fasterxml.jackson.databind.DeserializationFeature;
@@ -16,10 +18,18 @@ public class ModelJSONMapper {
       return mapper.readValue(json, ModelNetworkMap.class);
     }
     
+    public List<ModelNetworkMap> asNetworkMapList(String json) throws Exception {
+      return Arrays.asList(mapper.readValue(json, ModelNetworkMap[].class));
+    }
+    
     public ModelCostMap asCostMap(String json) throws Exception {
       return mapper.readValue(json, ModelCostMap.class);
     }
     
+    public List<ModelCostMap> asCostMapList(String json) throws Exception {
+      return Arrays.asList(mapper.readValue(json, ModelCostMap[].class));
+    }
+    
     public ModelEndpointPropertyMap asEndpointPropMap(String json) throws Exception {
       return mapper.readValue(json, ModelEndpointPropertyMap.class);
     }
index ffa3caced50aa79f041005dfef8138b1a58bb545..34cfcf8df39fbed819b6e6f3d21cf8de9f2891f7 100644 (file)
@@ -12,7 +12,6 @@ import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.annotation.JsonIgnore;
 
 public class ModelNetworkMap implements NetworkMap {
-
     
     @JsonProperty("alto-service:resource-id")
     public String rid = null;
index f2ebb63a02fba9c05a550328799057818611c4e4..a3aa92781c57e48707e8b5128064ff4e91195331 100644 (file)
@@ -6,13 +6,13 @@ import java.util.Arrays;
 public class RFC7285CostType {
 
     @JsonProperty("cost-mode")
-    public String mode = "";
+    public String mode = null;
 
     @JsonProperty("cost-metric")
-    public String metric = "";
+    public String metric = null;
 
     @JsonProperty("description")
-    public String description = "";
+    public String description = null;
 
     public RFC7285CostType() {
     }
index 2b4ec2d44e252180a7d9a30601d54e6c3d5f0075..eb118daddb3d2a7f902ab97a8cc18708dd7f8242 100644 (file)
@@ -1,5 +1,8 @@
 package org.opendaylight.alto.commons.types.rfc7285;
 
+import java.util.Arrays;
+import java.util.List;
+
 import com.fasterxml.jackson.annotation.JsonInclude.Include;
 import com.fasterxml.jackson.databind.DeserializationFeature;
 import com.fasterxml.jackson.databind.ObjectMapper;
@@ -33,6 +36,10 @@ public class RFC7285JSONMapper {
     public RFC7285CostMap asCostMap(String json) throws Exception {
         return mapper.readValue(json, RFC7285CostMap.class);
     }
+    
+    public List<RFC7285CostMap> asCostMapList(String json) throws Exception {
+      return Arrays.asList(mapper.readValue(json, RFC7285CostMap[].class));
+    }
 
     public RFC7285CostType asCostType(String json) throws Exception {
         return mapper.readValue(json, RFC7285CostType.class);
@@ -53,6 +60,10 @@ public class RFC7285JSONMapper {
     public RFC7285NetworkMap asNetworkMap(String json) throws Exception {
         return mapper.readValue(json, RFC7285NetworkMap.class);
     }
+    
+    public List<RFC7285NetworkMap> asNetworkMapList(String json) throws Exception {
+      return Arrays.asList(mapper.readValue(json, RFC7285NetworkMap[].class));
+    }
 
     public RFC7285NetworkMap.Filter asNetworkMapFilter(String json) throws Exception {
         return mapper.readValue(json, RFC7285NetworkMap.Filter.class);
index d17152709ddd62790930f1933c2ec742f0abc16e..5ee7ee073120efd9e42c19ef80501a7083ad27bd 100644 (file)
@@ -9,7 +9,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL
   <parent>
     <groupId>org.opendaylight.controller</groupId>
     <artifactId>karaf-parent</artifactId>
-    <version>1.5.0-SNAPSHOT</version>
+    <version>1.6.0-SNAPSHOT</version>
     <relativePath/>
   </parent>
   <modelVersion>4.0.0</modelVersion>
diff --git a/alto-manager/README.md b/alto-manager/README.md
new file mode 100644 (file)
index 0000000..bead868
--- /dev/null
@@ -0,0 +1,88 @@
+#Alto-Manager
+
+======
+
+Alto-manager provides extends karaf shell interface for you to create and delete maps and set properties for odl datastore. All functions are implemented by restconf in the backend.
+
+Alto-Manager supports three different commands.
+
+##alto:create
+Load maps from file and put them into odl datastore
+
+#####Command:
+
+```
+alto:create <map-type> <file-path>
+```
+alto:create command supports three different map types, `network-map, cost-map and endpoint-property-map`.
+
+#####File Format:
+* **network-map**: JSON Array of RFC formatted network maps.
+* **cost-map**: JSON Array of RFC formatted cost maps.
+* **endpoint-property-map**: Single RFC formatted endpoint property map
+
+File examples can be found at ./alto-manager/examples/.
+
+#####Note:
+Exceptions will be thrown if you try to:
+
+* Sepecify wrong map-type
+
+#####Example:
+```
+alto:create network-map ./examples/network-map-rfc
+alto:create cost-map ./examples/cost-map-rfc
+alto:create endpoint-property-map ./examples/cost-map-rfc
+```
+
+
+##alto:delete
+Delete map from odl datastore.
+
+#####Command:
+
+```
+alto:delete <map-type> <resource-id or null>
+```
+alto:delete command supports three different map types, `network-map, cost-map and endpoint-property-map`.
+
+If you are going to delete a network map or cost map, the second option should be set to resource id of the map. If you are going to delete endpoint-property-map, the second option should not be set.
+
+#####Note:
+Exceptions will be thrown if you try to:
+
+* Sepecify unsupported map type
+* Delete a map which does not exist
+* Delete the default network map
+* Delete a cost map or network map without specifying the resource id
+* Delete the endpoint propery map with a resource id
+
+#####Example:
+```
+alto:delete network-map my-default-network-map
+alto:create cost-map new-network-map-routingcost-numerical
+alto:create endpoint-property-map
+```
+
+##alto:set
+Set specific field for old datastore. **Currently only "default-network-map" field for IRD resource is supported.**
+
+#####Command:
+
+```
+alto:set <propety-name> <property-value>
+```
+
+#####Note:
+Exceptions will be thrown if you try to:
+
+* Sepecify unsupported map type
+* Network map specified by resource id does not exist
+
+#####Example:
+```
+alto:set default-network-map <network-map-resource-id>
+```
+
+##TODO
+* Support URI for alto:create
diff --git a/alto-manager/examples/cost_maps_rfc b/alto-manager/examples/cost_maps_rfc
new file mode 100644 (file)
index 0000000..9603227
--- /dev/null
@@ -0,0 +1,62 @@
+[
+  {
+    "meta": {
+      "dependent-vtags": [
+        {
+          "resource-id": "my-default-network-map",
+          "tag": "3ee2cb7e8d63d9fab71b9b34cbf764436315542e"
+        }
+      ],
+      "cost-type": {
+        "cost-mode": "numerical",
+        "cost-metric": "routingcost"
+      }
+    },
+    "cost-map": {
+      "PID1": {
+        "PID1": 1,
+        "PID2": 5,
+        "PID3": 10
+      },
+      "PID2": {
+        "PID1": 5,
+        "PID2": 1,
+        "PID3": 15
+      },
+      "PID3": {
+        "PID1": 20,
+        "PID2": 15
+      }
+    }
+  },
+  {
+    "meta": {
+      "dependent-vtags": [
+        {
+          "resource-id": "new-network-map",
+          "tag": "3ee2cb7e8d63d9fab71b9b34cbf764436315542F"
+        }
+      ],
+      "cost-type": {
+        "cost-mode": "numerical",
+        "cost-metric": "routingcost"
+      }
+    },
+    "cost-map": {
+      "PID1": {
+        "PID1": 1,
+        "PID2": 5,
+        "PID3": 10
+      },
+      "PID2": {
+        "PID1": 5,
+        "PID2": 1,
+        "PID3": 15
+      },
+      "PID3": {
+        "PID1": 20,
+        "PID2": 15
+      }
+    }
+  }
+]
diff --git a/alto-manager/examples/endpoint_property_map_rfc b/alto-manager/examples/endpoint_property_map_rfc
new file mode 100644 (file)
index 0000000..3b02351
--- /dev/null
@@ -0,0 +1,14 @@
+{
+  "meta" : {
+    "dependent-vtags" : [
+      {"resource-id": "my-default-network-map",
+       "tag": "7915dc0290c2705481c491a2b4ffbec482b3cf62"
+      }
+    ]
+  },
+  "endpoint-properties": {
+    "ipv4:192.0.2.34"    : { "my-default-network-map.pid": "PID1",
+                             "priv:ietf-example-prop": "1" },
+    "ipv4:203.0.113.129" : { "my-default-network-map.pid": "PID3" }
+  }
+}
diff --git a/alto-manager/examples/network_maps_rfc b/alto-manager/examples/network_maps_rfc
new file mode 100644 (file)
index 0000000..9c7506b
--- /dev/null
@@ -0,0 +1,60 @@
+[
+  {
+    "meta": {
+      "vtag": {
+        "resource-id": "my-default-network-map",
+        "tag": "da65eca2eb7a10ce8b059740b0b2e3f8eb1d4785"
+      }
+    },
+    "network-map": {
+      "PID1": {
+        "ipv4": [
+          "192.0.2.0/24",
+          "198.51.100.0/25"
+        ]
+      },
+      "PID2": {
+        "ipv4": [
+          "198.51.100.128/25"
+        ]
+      },
+      "PID3": {
+        "ipv4": [
+          "0.0.0.0/0"
+        ],
+        "ipv6": [
+          "::/0"
+        ]
+      }
+    }
+  },
+  {
+    "meta": {
+      "vtag": {
+        "resource-id": "new-network-map",
+        "tag": "da65eca2eb7a10ce8b059740b0b2e3f8eb1d4786"
+      }
+    },
+    "network-map": {
+      "PID1": {
+        "ipv4": [
+          "192.0.2.0/24",
+          "198.51.100.0/25"
+        ]
+      },
+      "PID2": {
+        "ipv4": [
+          "198.51.100.128/25"
+        ]
+      },
+      "PID3": {
+        "ipv4": [
+          "0.0.0.0/0"
+        ],
+        "ipv6": [
+          "::/0"
+        ]
+      }
+    }
+  }
+]
index 1d9b662d522469fa2e913ac8f51ca50c42de3197..9acbc631b7b3ccfd04d6ec795558a2c914e269c6 100644 (file)
@@ -1,5 +1,8 @@
 package org.opendaylight.alto.manager;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import org.apache.felix.gogo.commands.Argument;
 import org.apache.felix.gogo.commands.Command;
 import org.opendaylight.alto.commons.types.converter.RFC2ModelCostMapConverter;
@@ -9,7 +12,9 @@ import org.opendaylight.alto.commons.types.model150404.ModelCostMap;
 import org.opendaylight.alto.commons.types.model150404.ModelEndpointPropertyMap;
 import org.opendaylight.alto.commons.types.model150404.ModelJSONMapper;
 import org.opendaylight.alto.commons.types.model150404.ModelNetworkMap;
+import org.opendaylight.alto.commons.types.rfc7285.RFC7285CostMap;
 import org.opendaylight.alto.commons.types.rfc7285.RFC7285JSONMapper;
+import org.opendaylight.alto.commons.types.rfc7285.RFC7285NetworkMap;
 import org.opendaylight.alto.manager.AltoManagerConstants.MAP_FORMAT_TYPE;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -17,15 +22,12 @@ import org.slf4j.LoggerFactory;
 @Command(scope = "alto", name = "create", description = "Create resource by resource type and resource file")
 public class AltoCreate extends AltoManager {
   private static final Logger log = LoggerFactory.getLogger(AltoCreate.class);
-  
   private RFC7285JSONMapper rfcMapper = new RFC7285JSONMapper();
   private ModelJSONMapper modelMapper = new ModelJSONMapper();
   private RFC2ModelNetworkMapConverter networkMapConverter = new RFC2ModelNetworkMapConverter();
   private RFC2ModelCostMapConverter costMapConverter = new RFC2ModelCostMapConverter();
   private RFC2ModelEndpointPropMapConverter endpointPropConverter = new RFC2ModelEndpointPropMapConverter();
-
-  private String data;
-  private MAP_FORMAT_TYPE format = MAP_FORMAT_TYPE.YANG;
+  private MAP_FORMAT_TYPE format = MAP_FORMAT_TYPE.RFC;
   
   @Argument(index = 0, name = "resource-type", description = "Resource Type", required = true, multiValued = false)
   String resourceType = null;
@@ -40,72 +42,85 @@ public class AltoCreate extends AltoManager {
   @Override
   protected Object doExecute() throws Exception {
     if (networkMapType().equals(resourceType)) {
-      putNetworkMap();
+      putNetworkMaps();
     } else if (costMapType().equals(resourceType)) {
-      putCostMap();
+      putCostMaps();
     } else if (endpointPropertyMapType().equals(resourceType)) {
       putEndpointPropertyMap();
     } else {
-      log.warn("Not supported resource type " + resourceType + ". Aborting...");
+      throw new UnsupportedOperationException("Unsupported resource type \"" + resourceType + "\".");
     }
     return null;
   }
   
-  private void putNetworkMap() throws Exception {
-    log.info("Loading network map from " + this.resourceFile);
-    ModelNetworkMap networkMap = getYangNetworkMap(readFromFile(resourceFile));
-    data = modelMapper.asJSON(networkMap);
-    putMap(AltoManagerConstants.NETWORK_MAP_URL, networkMap.rid);
+  private void putNetworkMaps() throws Exception {
+    log.info("Loading network maps from " + this.resourceFile);
+    List<ModelNetworkMap> networkMaps = getYangNetworkMaps(readFromFile(resourceFile));
+    for (ModelNetworkMap map : networkMaps) {
+      log.info("Putting network map \"" + map.rid + "\"...");
+      String data = modelMapper.asJSON(map);
+      putMap(AltoManagerConstants.NETWORK_MAP_URL, map.rid, data);
+    }
   }
   
-  private ModelNetworkMap getYangNetworkMap(String data) throws Exception {
+  private List<ModelNetworkMap> getYangNetworkMaps(String data) throws Exception {
     if (MAP_FORMAT_TYPE.RFC.equals(format)) {
-      return networkMapConverter.convert(rfcMapper.asNetworkMap(data));
+      List<ModelNetworkMap> modelNetworkMaps = new ArrayList<ModelNetworkMap>();
+      for (RFC7285NetworkMap networkMap : rfcMapper.asNetworkMapList(data)) {
+        modelNetworkMaps.add(networkMapConverter.convert(networkMap));
+      }
+      return modelNetworkMaps;
     }
-    return modelMapper.asNetworkMap(data);
+    return modelMapper.asNetworkMapList(data);
   }
   
-  private void putCostMap() throws Exception {
+  private void putCostMaps() throws Exception {
     log.info("Loading cost map from " + this.resourceFile);
-    ModelCostMap costMap = getYangCostMap(data);
-    data = modelMapper.asJSON(costMap);
-    putMap(AltoManagerConstants.COST_MAP_URL, costMap.rid);
+    List<ModelCostMap> costMaps = getYangCostMaps(readFromFile(resourceFile));
+    for (ModelCostMap map : costMaps) {
+      log.info("Putting cost map " + map.rid + "...");
+      String data = modelMapper.asJSON(map);
+      putMap(AltoManagerConstants.COST_MAP_URL, map.rid, data);
+    }
   }
   
-  private ModelCostMap getYangCostMap(String data) throws Exception {
+  private List<ModelCostMap> getYangCostMaps(String data) throws Exception {
     if (MAP_FORMAT_TYPE.RFC.equals(format)) {
-      return costMapConverter.convert(rfcMapper.asCostMap(data));
+      List<ModelCostMap> modelCostMaps = new ArrayList<ModelCostMap>();
+      for (RFC7285CostMap costMap : rfcMapper.asCostMapList(data)) {
+        modelCostMaps.add(costMapConverter.convert(costMap));
+      }
+      return modelCostMaps;
     }
-    return modelMapper.asCostMap(data);
+    return modelMapper.asCostMapList(data);
   }
   
   private void putEndpointPropertyMap() throws Exception {
     log.info("Loading endpoint property map from " + this.resourceFile);
     ModelEndpointPropertyMap endpointPropMap = getYangEndpointPropMap(readFromFile(resourceFile));
-    data = modelMapper.asJSON(endpointPropMap);
-    putMap(AltoManagerConstants.RESOURCES_URL, AltoManagerConstants.ENDPOINT_PROPERTY_MAP_NODE);
+    String data = modelMapper.asJSON(endpointPropMap);
+    httpPut(AltoManagerConstants.ENDPOINT_PROP_MAP_URL, wrapdata(data));
   }
   
   private ModelEndpointPropertyMap getYangEndpointPropMap(String data) throws Exception {
     if (MAP_FORMAT_TYPE.RFC.equals(format)) {
-       endpointPropConverter.convert(rfcMapper.asEndpointPropMap(data));
+       return endpointPropConverter.convert(rfcMapper.asEndpointPropMap(data));
     }
     return modelMapper.asEndpointPropMap(data);
   }
   
-  private void putMap(String baseUrl, String resourceId) throws Exception {
+  private void putMap(String baseUrl, String resourceId, String data) throws Exception {
     if (resourceId == null) {
-      log.info("Cannot parse resourceId. Aborting");
-      return;
+      throw new RuntimeException("No ResourceId Specified.");
     }
-    httpPut(baseUrl + resourceId, wrapdata());
+    httpPut(baseUrl + resourceId, wrapdata(data));
   }
   
-  private String wrapdata() throws Exception {
+  private String wrapdata(String data) throws Exception {
     if (endpointPropertyMapType().equals(resourceType)) {
-      return "{\"alto-service:resourceType\":" + data + "}";
+      return "{\"alto-service:" + resourceType  + "\":" + data + "}";
     } else {
-      return "{\"alto-service:resourceType\":[" + data + "]}";
+      return "{\"alto-service:" + resourceType  + "\":[" + data + "]}";
     }
   }
 }
index 9352f703c693dc26a5ba35239f7a9b809feba4c6..22829a1ceb047888e3e0886dfcc47544a4ce535a 100644 (file)
@@ -14,7 +14,7 @@ public class AltoDelete extends AltoManager {
   @Argument(index = 0, name = "resource-type", description = "Resource Type", required = true, multiValued = false)
   String resourceType = null;
   
-  @Argument(index = 1, name = "resource-id", description = "Resource Id", required = true, multiValued = false)
+  @Argument(index = 1, name = "resource-id", description = "Resource Id", required = false, multiValued = false)
   String resourceId = null;
   
   public AltoDelete() {
@@ -23,10 +23,7 @@ public class AltoDelete extends AltoManager {
   
   @Override
   protected Object doExecute() throws Exception {
-    if (isDefaultNetworkMap(resourceId)) {
-      log.info("Cannot destroy default network map. Aborting");
-    }
-    
+    checkResourceID();
     if (networkMapType().equals(resourceType)) {
       deleteNetworkMap();
     } else if (costMapType().equals(resourceType)) {
@@ -34,11 +31,25 @@ public class AltoDelete extends AltoManager {
     } else if (endpointPropertyMapType().equals(resourceType)) {
       deleteEndpointPropertyMap();
     } else {
-      log.warn("Not supported resource type " + resourceType + ". Aborting...");
+      throw new UnsupportedOperationException("Unsupported resource type \"" + resourceType + "\".");
     }
     return null;
   }
   
+  private void checkResourceID() throws IOException {
+    if (networkMapType().equals(resourceType) && isDefaultNetworkMap(resourceId)) {
+      throw new RuntimeException("Cannot destroy default network map.");
+    }
+    
+    if (resourceId == null && !endpointPropertyMapType().equals(resourceType)) {
+      throw new RuntimeException("Please specify resource id for " + resourceType + ".");
+    }
+    
+    if (resourceId != null && endpointPropertyMapType().equals(resourceType)) {
+      throw new RuntimeException("Please do not specify resource id for " + resourceType + ".");
+    }
+  }
+  
   private boolean deleteEndpointPropertyMap() throws IOException {
     log.info("Deleting endpoint property map " + this.resourceId);
     return httpDelete(AltoManagerConstants.RESOURCES_URL + AltoManagerConstants.ENDPOINT_PROPERTY_MAP_NODE);
index d05b286a21042b8b941684d81d57a5f18d7cc02d..5e82b01b6233732421a66059711e662bc759f757 100644 (file)
@@ -4,6 +4,8 @@ import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Paths;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import org.apache.http.HttpEntity;
 import org.apache.http.HttpResponse;
@@ -58,7 +60,9 @@ public class AltoManager extends OsgiCommandSupport {
   
   protected String getDefaultNetworMapResourceId() throws IOException {
     HttpResponse response = httpGet(AltoManagerConstants.IRD_DEFAULT_NETWORK_MAP_URL);
-    return EntityUtils.toString(response.getEntity());
+    Pattern pattern = Pattern.compile(AltoManagerConstants.DEFAULT_NETWORK_MAP_REGEX);
+    Matcher matcher = pattern.matcher(EntityUtils.toString(response.getEntity()));
+    return matcher.find() ? matcher.group(1) : null;
   }
   
   protected HttpResponse httpGet(String url) throws IOException {
@@ -86,7 +90,7 @@ public class AltoManager extends OsgiCommandSupport {
   }
   
   private void logHttpRequest(String prefix, String url, String data) {
-    log.info(prefix + 
+    log.debug(prefix + 
         "\nUrl: " + url + 
         "\nHeader: " + HTTP.CONTENT_TYPE + ": " + AltoManagerConstants.JSON_CONTENT_TYPE +
         "\nData: " + data);
index d1a821524ce8835400a559b9b08d49cd49f9f269..8e1419173b46f8a48b3ecd6194cdf1034e0f96f8 100644 (file)
@@ -20,11 +20,14 @@ public class AltoManagerConstants {
   public static final String RESOURCES_URL = HOST + RESOURCES_NODE + "/";
   public static final String NETWORK_MAP_URL = RESOURCES_URL + NETWORK_MAPS_NODE + "/" + NETWORK_MAP_NODE + "/";
   public static final String COST_MAP_URL = RESOURCES_URL + COST_MAPS_NODE + "/" + COST_MAP_NODE + "/";
+  public static final String ENDPOINT_PROP_MAP_URL = RESOURCES_URL + ENDPOINT_PROPERTY_MAP_NODE;
   public static final String IRD_DEFAULT_NETWORK_MAP_URL = RESOURCES_URL + IRD_NODE + "/" + META_NODE + "/" + DEFAULT_NETWORK_MAP_NODE + "/";
   
   public static final String DEFAULT_NETWORK_MAP_PROPERTY = "default-network-map";
   public static final String DELIMETER = "-";
   
+  public static final String DEFAULT_NETWORK_MAP_REGEX = "^\\{\"default-alto-network-map\":\\{\"resource-id\":\"(.*)\"\\}}$";
+  
   public static enum COST_MODE {
     Numerical, Ordinal
   }
index 4e69fbd6b204d560362b52a6c63bd88439834bf8..c33d6985e57e487dce156bdc42a1803e3ec60574 100644 (file)
@@ -26,10 +26,11 @@ public class AltoSet extends AltoManager {
   protected Object doExecute() throws Exception {
     if (AltoManagerConstants.DEFAULT_NETWORK_MAP_PROPERTY.equals(property)) {
       if (!ifNetworkMapExist(value)) {
-        log.info("Network Map do not exist. Abort setting...");
-        return null;
+        throw new RuntimeException("Network map \"" + value + "\" does not exist.");
       }
       setDefaultNetworkMap();
+    } else {
+      throw new UnsupportedOperationException("Unsupported property \"" + property + "\".");
     }
     return null;
   }
diff --git a/pom.xml b/pom.xml
index 3476d54e6dc750a13434ff7844055709d8ec6420..a0b317e370e95761f15449752779d1951869774a 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -8,8 +8,8 @@
   <parent>
     <groupId>org.opendaylight.odlparent</groupId>
     <artifactId>odlparent</artifactId>
-    <version>1.5.0-SNAPSHOT</version>
-    <relativePath/>
+    <version>1.6.0-SNAPSHOT</version>
+    <relativePath></relativePath>
   </parent>
 
   <groupId>org.opendaylight.alto</groupId>
     </dependencies>
   </dependencyManagement>
 
+  <repositories>
+
+    <!-- OpenDayLight Repo Mirror -->
+    <!-- NOTE: URLs need to be hardcoded in the repository section because we have
+         parent poms that do NOT exist in this project and thus need to be pulled
+         down from the repository. To override these URLs you should use the
+         mirror section in your local settings.xml file. -->
+    <repository>
+      <releases>
+        <enabled>true</enabled>
+        <updatePolicy>never</updatePolicy>
+      </releases>
+      <snapshots>
+        <enabled>false</enabled>
+      </snapshots>
+      <id>opendaylight-mirror</id>
+      <name>opendaylight-mirror</name>
+      <url>http://nexus.opendaylight.org/content/groups/public/</url>
+    </repository>
+    <!-- OpenDayLight Snapshot artifact -->
+    <repository>
+      <releases>
+        <enabled>false</enabled>
+      </releases>
+      <snapshots>
+        <enabled>true</enabled>
+      </snapshots>
+      <id>opendaylight-snapshot</id>
+      <name>opendaylight-snapshot</name>
+      <url>http://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
+    </repository>
+  </repositories>
+
   <build>
     <pluginManagement>
       <plugins>