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>{
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>();
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;
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;
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;
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();
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> {
public RFC2ModelNetworkMapConverter(RFC7285NetworkMap _in) {
super(_in);
}
-
+
@Override
public Object _convert() {
ModelNetworkMap out = new ModelNetworkMap();
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;
public List<ModelDependentVtag> dependentVtags = new LinkedList<ModelDependentVtag>();
@JsonProperty("alto-service:cost-type")
- public ModelCostType costType = null;
+ public ModelCostType costType = new ModelCostType();
@JsonIgnore
@Override
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;
@JsonProperty("alto-service:description")
public String description = null;
+ @JsonIgnore
@Override
public Class<? extends DataContainer> getImplementedInterface() {
return CostType.class;
switch(costMode) {
case NUMERICAL:
return CostMode.Numerical;
- case Ordinal:
+ case ORDINAL:
return CostMode.Ordinal;
default:
throw new RuntimeException("Non-Supported cost mode.");
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
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() {
@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);
}
}
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());
}
}
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>();
public Meta getMeta() {
return endpointPropertyMeta;
}
-
}
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;
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);
}
import com.fasterxml.jackson.annotation.JsonIgnore;
public class ModelNetworkMap implements NetworkMap {
-
@JsonProperty("alto-service:resource-id")
public String rid = null;
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() {
}
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;
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);
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);
<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>
--- /dev/null
+#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
--- /dev/null
+[
+ {
+ "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
+ }
+ }
+ }
+]
--- /dev/null
+{
+ "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" }
+ }
+}
--- /dev/null
+[
+ {
+ "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"
+ ]
+ }
+ }
+ }
+]
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;
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;
@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;
@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 + "]}";
}
}
}
@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() {
@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)) {
} 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);
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;
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 {
}
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);
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
}
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;
}
<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>