Add back alto-karaf to test alto-features.
Change-Id: Idfc97c7fa9bd398d60317f4efbf27a586237aa23
Signed-off-by: Gao Kai <gaok12@mails.tsinghua.edu.cn>
<extensions>true</extensions>
<configuration>
<instructions>
- <Import-Package>
- com.fasterxml.jackson.annotation,
- com.fasterxml.jackson.databind,
- org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924,
- </Import-Package>
+ <Import-Package>*</Import-Package>
<Export-Package>
org.opendaylight.alto.commons.*;
org.opendaylight.alto.commons.types.*;
ModelNetworkMap out = new ModelNetworkMap();
out.setJSONResourceId(in().meta.vtag.rid);
out.setJSONTag(in().meta.vtag.tag);
- out.setJSONMap(conv.reset(in().map).out());
-
+ out.setJSONMap(conv.convert(in().map));
return out;
}
}
for (Map.Entry<String, RFC7285Endpoint.AddressGroup> rep: in().entrySet()) {
ModelEndpoint mep = new ModelEndpoint();
mep.setJSONPid(rep.getKey());
- mep.setJSONEndpointAddressGroup(conv.reset(rep.getValue()).out());
+ mep.setJSONEndpointAddressGroup(conv.convert(rep.getValue()));
out.add(mep);
}
return out;
* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
-package org.opendaylight.alto.commons.types.alto.model.rev150404;
+package org.opendaylight.alto.commons.types.model150404;
class MediaType {
import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev100924.IpPrefixBuilder;
import org.opendaylight.yangtools.yang.binding.Augmentation;
+import java.util.ArrayList;
import java.util.List;
import java.util.LinkedList;
public static final String IPV4 = "ipv4";
public static final String IPV6 = "ipv6";
-
@JsonIgnore
protected EndpointAddressType type;
}
@JsonProperty("alto-service:endpoint-prefix")
- public List<String> getJSONEndpointAddressGroup() {
+ public List<String> getJSONEndpointPrefix() {
return prefixes;
}
package org.opendaylight.alto.commons.types.model150404;
+import java.io.IOException;
+
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
return mapper.readValue(json, ModelNetworkMap.class);
}
+ public ModelEndpoint asModelEndpoint(String json) throws IOException {
+ return mapper.readValue(json, ModelEndpoint.class);
+ }
+
public String asJSON(Object obj) throws Exception {
- return mapper.writeValueAsString(obj);
+ return mapper.writeValueAsString(obj);
}
}
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Open Daylight ALTO group and others. All rights reserved.
+This program and the accompanying materials are made available under the
+terms of the Eclipse Public License v1.0 which accompanies this distribution,
+and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>karaf-parent</artifactId>
+ <version>1.5.0-SNAPSHOT</version>
+ <relativePath/>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.opendaylight.alto</groupId>
+ <artifactId>alto-karaf</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <name>${project.artifactId}</name>
+ <prerequisites>
+ <maven>3.1.1</maven>
+ </prerequisites>
+ <properties>
+ <karaf.localFeature>odl-alto-integration-test</karaf.localFeature>
+ </properties>
+ <dependencyManagement>
+ <dependencies>
+ </dependencies>
+ </dependencyManagement>
+ <dependencies>
+ <dependency>
+ <!-- scope is compile so all features (there is only one) are installed
+ into startup.properties and the feature repo itself is not installed -->
+ <groupId>org.apache.karaf.features</groupId>
+ <artifactId>framework</artifactId>
+ <type>kar</type>
+ </dependency>
+
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>features-alto</artifactId>
+ <version>${project.version}</version>
+ <classifier>features</classifier>
+ <type>xml</type>
+ <scope>runtime</scope>
+ </dependency>
+ </dependencies>
+ <!-- DO NOT install or deploy the karaf artifact -->
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <configuration>
+ <skip>true</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+</project>
<packaging>bundle</packaging>
<name>${project.artifactId}</name>
- <properties>
- <configfile>default.networkmap</configfile>
- </properties>
-
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
- <artifactId>alto-model</artifactId>
+ <artifactId>alto-commons</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore-osgi</artifactId>
</dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-core</artifactId>
- </dependency>
</dependencies>
<build>
org.apache.felix.service.command,
org.apache.felix.gogo.commands,
org.apache.karaf.shell.console,
- org.apache.http.*
+ org.apache.http.*,
+ org.opendaylight.alto.commons.*,
+ org.slf4j
</Import-Package>
<Bundle-Name>${project.groupId}.${project.artifactId}</Bundle-Name>
</instructions>
<source>1.7</source>
</configuration>
</plugin>
- <plugin>
- <groupId>org.codehaus.mojo</groupId>
- <artifactId>build-helper-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>attach-artifacts</id>
- <goals>
- <goal>attach-artifact</goal>
- </goals>
- <phase>package</phase>
- <configuration>
- <artifacts>
- <artifact>
- <file>${project.build.directory}/classes/${configfile}</file>
- <type>xml</type>
- <classifier>config</classifier>
- </artifact>
- </artifacts>
- </configuration>
- </execution>
- </executions>
- </plugin>
</plugins>
</build>
</project>
--- /dev/null
+package org.opendaylight.alto.manager;
+
+import java.io.IOException;
+
+import org.apache.felix.gogo.commands.Argument;
+import org.apache.felix.gogo.commands.Command;
+import org.opendaylight.alto.commons.types.converter.RFC2ModelNetworkMapConverter;
+import org.opendaylight.alto.commons.types.model150404.ModelJSONMapper;
+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.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 converter = new RFC2ModelNetworkMapConverter();
+ private String data;
+
+ @Argument(index = 0, name = "resource-type", description = "Resource Type", required = true, multiValued = false)
+ String resourceType = null;
+
+ @Argument(index = 1, name = "resource-file", description = "Resource File", required = true, multiValued = false)
+ String resourceFile = null;
+
+ public AltoCreate() {
+ super();
+ }
+
+ @Override
+ protected Object doExecute() throws Exception {
+ if (networkMapType().equals(resourceType)) {
+ putNetworkMap();
+ } else if (costMapType().equals(resourceType)) {
+ putCostMap();
+ } else if (endpointPropertyMapType().equals(resourceType)) {
+ putEndpointPropertyMap();
+ } else {
+ log.warn("Not supported resource type " + resourceType + ". Aborting...");
+ }
+ return null;
+ }
+
+ private void putNetworkMap() throws Exception {
+ log.info("Loading network map from " + this.resourceFile);
+ RFC7285NetworkMap rfcNetworkMap = rfcMapper.asNetworkMap(readFromFile(resourceFile));
+ data = createNetworkMapData(rfcNetworkMap);
+ putMap(AltoManagerConstants.NETWORK_MAP_URL, rfcNetworkMap.meta.vtag.rid);
+ }
+
+ private String createNetworkMapData(RFC7285NetworkMap rfcNetworkMap) throws Exception {
+ String networkMapJson = modelMapper.asJSON(converter.convert(rfcNetworkMap));
+ return "{\"alto-service:network-map\":[" + networkMapJson + "]}";
+ }
+
+ private void putCostMap() throws Exception {
+ log.info("Loading cost map from " + this.resourceFile);
+ RFC7285CostMap costMap = rfcMapper.asCostMap(readFromFile(resourceFile));
+ String resourceId = getCostMapResourceId(costMap);
+ //TODO: transform it to yang format json
+ data = "";
+ putMap(AltoManagerConstants.COST_MAP_URL, resourceId);
+ }
+
+ private void putEndpointPropertyMap() throws IOException {
+ log.info("Loading endpoint property map from " + this.resourceFile);
+ //TODO: get RFC7285EndpointPropertyMap object and transform it to yang format json
+ data = "";
+ putMap(AltoManagerConstants.ENDPOINT_PROPERTY_MAP_URL, AltoManagerConstants.ENDPOINT_PROPERTY_MAP_NAME);
+ }
+
+ private void putMap(String baseUrl, String resourceId) throws IOException {
+ if (resourceId == null) {
+ log.info("Cannot parse resourceId. Aborting");
+ return;
+ }
+ httpPut(baseUrl + resourceId, data);
+ }
+
+ private String getCostMapResourceId(RFC7285CostMap costMap) throws Exception {
+ String networkMapRID = costMap.meta.netmap_tags.get(0).rid;
+ String costMetric = costMap.meta.costType.metric;
+ String costMode = costMap.meta.costType.mode;
+ return networkMapRID + AltoManagerConstants.DELIMETER + costMetric
+ + AltoManagerConstants.DELIMETER + costMode;
+ }
+}
--- /dev/null
+package org.opendaylight.alto.manager;
+
+import java.io.IOException;
+
+import org.apache.felix.gogo.commands.Argument;
+import org.apache.felix.gogo.commands.Command;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Command(scope = "alto", name = "delete", description = "Destroy a map by resourceId")
+public class AltoDelete extends AltoManager {
+ private static final Logger log = LoggerFactory.getLogger(AltoDelete.class);
+
+ @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)
+ String resourceId = null;
+
+ public AltoDelete() {
+ super();
+ }
+
+ @Override
+ protected Object doExecute() throws Exception {
+ if (isDefaultNetworkMap(resourceId)) {
+ log.info("Cannot destroy default network map. Aborting");
+ }
+
+ if (networkMapType().equals(resourceType)) {
+ deleteNetworkMap();
+ } else if (costMapType().equals(resourceType)) {
+ deleteCostMap();
+ } else if (endpointPropertyMapType().equals(resourceType)) {
+ deleteEndpointPropertyMap();
+ } else {
+ log.warn("Not supported resource type " + resourceType + ". Aborting...");
+ }
+ return null;
+ }
+
+ private boolean deleteEndpointPropertyMap() throws IOException {
+ log.info("Deleting endpoint property map " + this.resourceId);
+ return httpDelete(AltoManagerConstants.ENDPOINT_PROPERTY_MAP_URL + resourceId);
+ }
+
+ private boolean deleteCostMap() throws IOException {
+ log.info("Deleting endpoint property map " + this.resourceId);
+ return httpDelete(AltoManagerConstants.COST_MAP_URL + resourceId);
+ }
+
+ private boolean deleteNetworkMap() throws IOException {
+ log.info("Deleting endpoint property map " + this.resourceId);
+ return httpDelete(AltoManagerConstants.NETWORK_MAP_URL + resourceId);
+ }
+}
import java.nio.file.Files;
import java.nio.file.Paths;
-import org.apache.felix.gogo.commands.Argument;
-import org.apache.felix.gogo.commands.Command;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.ParseException;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CredentialsProvider;
import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.BasicCredentialsProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.core.JsonParser;
-import com.fasterxml.jackson.core.JsonToken;
-
-@Command(scope = "alto", name = "load", description = "Alto Manager")
public class AltoManager extends OsgiCommandSupport {
-
private static final Logger log = LoggerFactory.getLogger(AltoManager.class);
- private JsonFactory jsonF = new JsonFactory();
- private HttpClient httpClient;
+
+ protected HttpClient httpClient;
public AltoManager () {
httpClient = initiateHttpClient();
log.info(this.getClass().getName() + " Initiated");
}
- private HttpClient initiateHttpClient() {
+ protected HttpClient initiateHttpClient() {
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials("admin:admin"));
return HttpClientBuilder.create().setDefaultCredentialsProvider(credentialsProvider).build();
}
-
- @Argument(index = 0, name = "map type", description = "Map Type", required = true, multiValued = false)
- String type = null;
-
- @Argument(index = 1, name = "map path", description = "Map Path", required = true, multiValued = false)
- String path = null;
-
+
@Override
protected Object doExecute() throws Exception {
- if (AltoManagerConstants.SERVICE_TYPE.NETWORK.toString().toLowerCase().equals(type)) {
- putNetworkMap();
- } else if (AltoManagerConstants.SERVICE_TYPE.RESOURCE.toString().toLowerCase().equals(type)) {
- putResources();
- }
return null;
}
- private void putResources() throws IOException {
- log.info("Loading Resources From " + path);
- String data = readFromFile(path);
- httpPut(AltoManagerConstants.HOST, data);
+ protected String readFromFile(String path) throws IOException {
+ return new String(Files.readAllBytes(Paths.get(path)),
+ StandardCharsets.UTF_8);
}
-
- private void putNetworkMap() throws IOException {
- log.info("Loading Network Map From " + this.path);
- String data = readFromFile(path);
- String resourceId = resourceIdFromNetworkMap(data);
- if (resourceId == null) {
- log.info("Cannot parse resourceId, abort loading");
- return;
- }
- String url = AltoManagerConstants.NETWORK_MAP_HOST + resourceId;
- log.info("Url: " + url);
- httpPut(url, data);
+
+ protected boolean isDefaultNetworkMap(String resourceId) throws IOException {
+ String defaultNetworkResourceId = getDefaultNetworMapResourceId();
+ return (defaultNetworkResourceId != null) && defaultNetworkResourceId.equals(resourceId);
}
-
- private void httpPut(String url, String data) throws IOException {
- HttpPut httpput = new HttpPut(url);
- httpput.setHeader(HTTP.CONTENT_TYPE, AltoManagerConstants.JSON_CONTENT_TYPE);
- httpput.setEntity(new StringEntity(data));
- HttpResponse response = httpClient.execute(httpput);
- handleResponse(response);
+
+ protected String getDefaultNetworMapResourceId() throws IOException {
+ HttpResponse response = httpGet(AltoManagerConstants.IRD_DEFAULT_NETWORK_MAP_URL);
+ return EntityUtils.toString(response.getEntity());
}
-
- private String readFromFile(String path) throws IOException {
- return new String(Files.readAllBytes(Paths.get(path)),
- StandardCharsets.UTF_8);
+
+ protected HttpResponse httpGet(String url) throws IOException {
+ HttpGet httpGet = new HttpGet(url);
+ logHttpRequest("HTTP GET:", url, "");
+ httpGet.setHeader(HTTP.CONTENT_TYPE, AltoManagerConstants.JSON_CONTENT_TYPE);
+ return httpClient.execute(httpGet);
}
-
- private void handleResponse(HttpResponse response) throws ParseException, IOException {
- HttpEntity entity = response.getEntity();
- if (entity != null) {
- String body = EntityUtils.toString(entity);
- if (response.getStatusLine().getStatusCode()== 200) {
- log.info("Loading Succesfully.");
- } else {
- log.error("Failed to load file \n" + body);
- }
- }
+
+ protected boolean httpPut(String url, String data) throws IOException {
+ HttpPut httpPut = new HttpPut(url);
+ httpPut.setHeader(HTTP.CONTENT_TYPE, AltoManagerConstants.JSON_CONTENT_TYPE);
+ httpPut.setEntity(new StringEntity(data));
+ logHttpRequest("HTTP PUT:", url, data);
+ HttpResponse response = httpClient.execute(httpPut);
+ return handleResponse(response);
}
-
- private String resourceIdFromNetworkMap(String jsonString) throws JsonParseException, IOException {
- JsonParser jParser = jsonF.createParser(jsonString);
- while (jParser.nextToken() != JsonToken.END_OBJECT) {
- String fieldname = jParser.getCurrentName();
- if (AltoManagerConstants.RESOURCE_ID_LABEL.equals(fieldname)) {
- jParser.nextToken();
- String resourceId = jParser.getText();
- return resourceId;
- }
+
+ protected boolean httpDelete(String url) throws IOException {
+ HttpDelete httpDelete = new HttpDelete(url);
+ httpDelete.setHeader(HTTP.CONTENT_TYPE, AltoManagerConstants.JSON_CONTENT_TYPE);
+ logHttpRequest("HTTP DELETE:", url, "");
+ HttpResponse response = httpClient.execute(httpDelete);
+ return handleResponse(response);
+ }
+
+ private void logHttpRequest(String prefix, String url, String data) {
+ log.info(prefix +
+ "\nUrl: " + url +
+ "\nHeader: " + HTTP.CONTENT_TYPE + ": " + AltoManagerConstants.JSON_CONTENT_TYPE +
+ "\nData: " + data);
+ }
+
+ protected boolean handleResponse(HttpResponse response) throws ParseException, IOException {
+ int statusCode = response.getStatusLine().getStatusCode();
+ logResponse(response);
+ if (statusCode == 200) {
+ log.info("Operation Succesfully");
+ return true;
+ } else {
+ log.error("Operation Failed");
+ return false;
}
- return null;
}
-
- private void postResources(String path) throws IOException {
- log.info("Loading Resources From " + path);
- String content = readFromFile(path);
-
- HttpPost httppost = new HttpPost(AltoManagerConstants.HOST);
- httppost.setHeader(HTTP.CONTENT_TYPE, AltoManagerConstants.JSON_CONTENT_TYPE);
- httppost.setEntity(new StringEntity(content));
- HttpResponse response = httpClient.execute(httppost);
- handleResponse(response);
+
+ protected void logResponse(HttpResponse response) throws IOException {
+ HttpEntity entity = response.getEntity();
+ int statusCode = response.getStatusLine().getStatusCode();
+ String body = entity != null ? EntityUtils.toString(entity) : "";
+ log.info("Response: "
+ + "\nStatus Code: " + statusCode
+ + "\nBody: " + body);
+ }
+
+ protected String networkMapType() {
+ return AltoManagerConstants.SERVICE_TYPE.NETWORK_MAP.toString()
+ .toLowerCase().replace("_", "-");
+ }
+
+ protected String costMapType() {
+ return AltoManagerConstants.SERVICE_TYPE.COST_MAP.toString()
+ .toLowerCase().replace("_", "-");
+ }
+
+ protected String endpointPropertyMapType() {
+ return AltoManagerConstants.SERVICE_TYPE.ENDPOINT_PROPERTY_MAP.toString()
+ .toLowerCase().replace("_", "-");
}
}
public static final String HOST = "http://127.0.0.1:8181/restconf/config/";
public static final String MODULE = "alto-service";
public static final String JSON_CONTENT_TYPE = "application/yang.data+json";
+
+ public static final String RESOURCES_NODE = MODULE + ":resources";
+ public static final String IRD_NODE = MODULE + ":IRD";
+ public static final String META_NODE = MODULE + ":meta";
+ public static final String DEFAULT_NETWORK_MAP_NODE = MODULE + ":default-alto-network-map";
+
+ public static final String NETWORK_MAPS_NODE = MODULE + ":network-maps";
+ public static final String NETWORK_MAP_NODE = MODULE + ":network-map";
+ public static final String COST_MAPS_NODE = MODULE + ":cost-maps";
+ public static final String COST_MAP_NODE = MODULE + ":cost-map";
+ public static final String ENDPOINT_PROPERTY_MAP_NODE = MODULE + ":endpoint-property-map";
+ public static final String RESOURCE_ID_NODE = MODULE + ":resource-id";
- public static final String RESOURCES_LABEL = MODULE + ":resources";
- public static final String NETWORK_MAPS_LABEL = MODULE + ":network-maps";
- public static final String NETWORK_MAP_LABEL = MODULE + ":network-map";
-
- public static final String RESOURCE_ID_LABEL = MODULE + ":resource-id";
-
- public static final String RESOURCES_HOST = HOST + RESOURCES_LABEL + "/";
- public static final String NETWORK_MAPS_HOST = RESOURCES_HOST + NETWORK_MAPS_LABEL + "/";
- public static final String NETWORK_MAP_HOST = NETWORK_MAPS_HOST + NETWORK_MAP_LABEL + "/";
-
- public static final String DEFAULT_RESOURCES_PATH = "configuration/default.networkmap";
-
+ 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_PROPERTY_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 ENDPOINT_PROPERTY_MAP_NAME = "endpoint-property-map";
+ public static final String DEFAULT_NETWORK_MAP_PROPERTY = "default-network-map";
+ public static final String DELIMETER = "-";
+
+ public static enum COST_MODE {
+ Numerical, Ordinal
+ }
+
public static enum SERVICE_TYPE{
- RESOURCE, NETWORK, COST
+ NETWORK_MAP, COST_MAP, ENDPOINT_PROPERTY_MAP
}
-}
+}
\ No newline at end of file
--- /dev/null
+package org.opendaylight.alto.manager;
+
+import java.io.IOException;
+
+import org.apache.felix.gogo.commands.Argument;
+import org.apache.felix.gogo.commands.Command;
+import org.apache.http.HttpResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+@Command(scope = "alto", name = "set", description = "Set property")
+public class AltoSet extends AltoManager {
+ private static final Logger log = LoggerFactory.getLogger(AltoSet.class);
+
+ @Argument(index = 0, name = "property-name", description = "Property Name", required = true, multiValued = false)
+ String property = null;
+
+ @Argument(index = 1, name = "property-value", description = "Property Value", required = true, multiValued = false)
+ String value = null;
+
+ public AltoSet() {
+ super();
+ }
+
+ @Override
+ 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;
+ }
+ setDefaultNetworkMap();
+ }
+ return null;
+ }
+
+ private boolean ifNetworkMapExist(String resourceId) throws IOException {
+ HttpResponse response = httpGet(AltoManagerConstants.NETWORK_MAP_URL + resourceId);
+ logResponse(response);
+ int statusCode = response.getStatusLine().getStatusCode();
+ return (statusCode == 200);
+ }
+
+ private void setDefaultNetworkMap() throws IOException {
+ log.info("Setting default network map");
+ httpPut(AltoManagerConstants.IRD_DEFAULT_NETWORK_MAP_URL, queryData(value));
+ }
+
+ private String queryData(String resourceId) {
+ return "{\"alto-service:default-alto-network-map\":{\"alto-service:resource-id\":\"" + resourceId + "\"}}";
+ }
+}
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
<command-bundle xmlns="http://karaf.apache.org/xmlns/shell/v1.0.0">
- <command name="alto/load">
- <action class="org.opendaylight.alto.manager.AltoManager"/>
+ <command name="alto/create">
+ <action class="org.opendaylight.alto.manager.AltoCreate"/>
+ </command>
+
+ <command name="alto/delete">
+ <action class="org.opendaylight.alto.manager.AltoDelete"/>
+ </command>
+
+ <command name="alto/set">
+ <action class="org.opendaylight.alto.manager.AltoSet"/>
</command>
</command-bundle>
</blueprint>
+++ /dev/null
-{"alto-service:resources":{"alto-service:network-maps":{"alto-service:network-map":[{"alto-service:resource-id":"my-default-network-map","alto-service:tag":"da65eca2eb7a10ce8b059740b0b2e3f8eb1d4785","alto-service:map":[{"alto-service:pid":"PID1","alto-service:endpoint-address-group":[{"alto-service:address-type":"ipv4","alto-service:endpoint-prefix":["192.0.2.0/24","198.51.100.0/25"]}]},{"alto-service:pid":"PID2","alto-service:endpoint-address-group":[{"alto-service:address-type":"ipv4","alto-service:endpoint-prefix":["198.51.100.128/25"]}]},{"alto-service:pid":"PID3","alto-service:endpoint-address-group":[{"alto-service:address-type":"ipv4","alto-service:endpoint-prefix":["0.0.0.0/0"]},{"alto-service:address-type":"ipv6","alto-service:endpoint-prefix":["::/0"]}]}]}]}}}
/* meta */
grouping IRD-meta {
uses cost-types;
- leaf default-alto-network-map {
- type resource-id;
- mandatory true;
+ container default-alto-network-map {
+ leaf resource-id {
+ type resource-id;
+ mandatory true;
+ }
}
}
<type>xml</type>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.controller</groupId>
+ <artifactId>features-base</artifactId>
+ <version>${odl.version}</version>
+ <classifier>features</classifier>
+ <type>xml</type>
+ <scope>runtime</scope>
+ </dependency>
+
<dependency>
<groupId>org.opendaylight.controller</groupId>
<artifactId>features-mdsal</artifactId>
<version>${project.version}</version>
</dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>alto-manager</artifactId>
- <version>${project.version}</version>
- <type>xml</type>
- <classifier>config</classifier>
- </dependency>
-
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient-osgi</artifactId>
<repository>mvn:org.opendaylight.yangtools/features-yangtools/${yangtools.version}/xml/features</repository>
<repository>mvn:org.opendaylight.controller/features-mdsal/${mdsal.version}/xml/features</repository>
<repository>mvn:org.opendaylight.controller/features-restconf/${mdsal.version}/xml/features</repository>
+ <repository>mvn:org.opendaylight.controller/features-base/${odl.version}/xml/features</repository>
<feature name='odl-alto-all' version='${project.version}' description='OpenDaylight :: alto :: All '>
<feature version='${project.version}'>odl-alto-provider</feature>
</feature>
<feature name='odl-alto-jackson-dependency' version='${project.version}' description='Opendaylight :: alto :: jackson_dependency'>
- <bundle>mvn:com.fasterxml.jackson.core/jackson-annotations/${jackson.version}</bundle>
- <bundle>mvn:com.fasterxml.jackson.core/jackson-core/${jackson.version}</bundle>
- <bundle>mvn:com.fasterxml.jackson.core/jackson-databind/${jackson.version}</bundle>
+ <bundle>mvn:com.fasterxml.jackson.core/jackson-annotations/${jackson.version}</bundle>
+ <bundle>mvn:com.fasterxml.jackson.core/jackson-core/${jackson.version}</bundle>
+ <bundle>mvn:com.fasterxml.jackson.core/jackson-databind/${jackson.version}</bundle>
</feature>
<feature name='odl-alto-commons' version='${project.version}' description='OpenDaylight :: alto :: utils'>
</feature>
<feature name='odl-alto-manager' version='${project.version}' description='OpenDaylight :: alto :: Provider'>
- <feature version='${jackson.version}'>odl-base-jackson</feature>
- <configfile finalname="configuration/default.networkmap">mvn:org.opendaylight.alto/alto-manager/${project.version}/xml/config</configfile>
+ <feature version='${project.version}'>odl-alto-commons</feature>
<bundle>mvn:org.apache.httpcomponents/httpclient-osgi/${httpclient.version}</bundle>
<bundle>mvn:org.apache.httpcomponents/httpcore-osgi/${httpclient.version}</bundle>
<bundle>mvn:org.opendaylight.alto/alto-manager/${project.version}</bundle>
<feature name='odl-alto-northbound' version='${project.version}' description='Opendaylight :: alto :: Northbound'>
<feature version='${jersey.version}'>odl-base-jersey</feature>
<feature>war</feature>
- <feature version='${controller.commons.northbound.version}'>odl-adsal-northbound</feature>
<feature version='${project.version}'>odl-alto-commons</feature>
<bundle>mvn:org.opendaylight.alto/service-api-rfc7285/${project.version}</bundle>
<bundle>mvn:org.opendaylight.alto/services.ext.fake/${project.version}</bundle>
</feature>
<feature name='odl-alto-integration-test' version='${project.version}' description='Opendaylight :: alto :: IntegrationTest'>
+ <feature>odl-restconf-all</feature>
<feature version='${project.version}'>odl-alto-northbound</feature>
<feature version='${project.version}'>odl-alto-manager</feature>
</feature>
<module>alto-extensions</module>
<!-- <module>alto-karaf</module> -->
<module>alto-northbound</module>
+ <module>alto-karaf</module>
</modules>
<properties>
+ <odl.version>1.5.0-SNAPSHOT</odl.version>
<karaf.shell.version>2.2.11</karaf.shell.version>
+ <checkstyle.skip>true</checkstyle.skip>
<!-- required by alto command line -->
<httpclient.version>4.4.1</httpclient.version>