Merge commit 1c13d97c001c2830d6534ef96b9cb6111c181c49 71/19371/1
authorGao Kai <gaok12@mails.tsinghua.edu.cn>
Thu, 30 Apr 2015 09:33:21 +0000 (17:33 +0800)
committerGao Kai <gaok12@mails.tsinghua.edu.cn>
Thu, 30 Apr 2015 09:33:21 +0000 (17:33 +0800)
Add back alto-karaf to test alto-features.

Change-Id: Idfc97c7fa9bd398d60317f4efbf27a586237aa23
Signed-off-by: Gao Kai <gaok12@mails.tsinghua.edu.cn>
19 files changed:
alto-commons/pom.xml
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/MediaType.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/ModelJSONMapper.java
alto-karaf/pom.xml [new file with mode: 0644]
alto-manager/pom.xml
alto-manager/src/main/java/org/opendaylight/alto/manager/AltoCreate.java [new file with mode: 0644]
alto-manager/src/main/java/org/opendaylight/alto/manager/AltoDelete.java [new file with mode: 0644]
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 [new file with mode: 0644]
alto-manager/src/main/resources/OSGI-INF/blueprint/config.xml
alto-manager/src/main/resources/default.networkmap [deleted file]
alto-model/src/main/yang/alto-service-types.yang
features/pom.xml
features/src/main/resources/features.xml
pom.xml

index d600db4f5c85b79dd4d74db08d052d71adfdc771..64069b919b77f89015cd9f086535c14915c320cc 100644 (file)
         <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.*;
index cc5def81be76b11c34bdcf1899e9132ba140acf8..ab050412ac92a230b42fe7e395e1fd6812a08b04 100644 (file)
@@ -21,8 +21,7 @@ public class RFC2ModelNetworkMapConverter
         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;
     }
 }
index 48a3fd1b60ed329289d98ba6695247eab0220983..2d5532e3e860df526173fc1a00b81b8652ff909f 100644 (file)
@@ -27,7 +27,7 @@ public class RFC2ModelNetworkMapDataConverter
         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;
index b8cf48e1ffebff29408fbd4a39b54f1140db1c71..92231b73a921282819ddb158b08f5240187824df 100644 (file)
@@ -5,7 +5,7 @@
  * 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 {
 
index 16739b9ce3ad5e5c58edbec21e4ef30ce2c961b7..bf70734a3bf38b52992d803d633cfbe221ab7c3e 100644 (file)
@@ -7,6 +7,7 @@ import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.
 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;
 
@@ -18,7 +19,6 @@ public class ModelEndpointAddressGroup implements EndpointAddressGroup {
     public static final String IPV4 = "ipv4";
     public static final String IPV6 = "ipv6";
 
-
     @JsonIgnore
     protected EndpointAddressType type;
 
@@ -82,7 +82,7 @@ public class ModelEndpointAddressGroup implements EndpointAddressGroup {
     }
 
     @JsonProperty("alto-service:endpoint-prefix")
-    public List<String> getJSONEndpointAddressGroup() {
+    public List<String> getJSONEndpointPrefix() {
         return prefixes;
     }
 
index 5eaeedfa7ed6cf47ad1c8d9f6033a8f9c5ca53b0..2365ceaa0acefcfd8f7dd1b7c7c6ef8a22f93e11 100644 (file)
@@ -1,5 +1,7 @@
 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;
@@ -14,7 +16,11 @@ public class ModelJSONMapper {
         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);
     }
 }
diff --git a/alto-karaf/pom.xml b/alto-karaf/pom.xml
new file mode 100644 (file)
index 0000000..d171527
--- /dev/null
@@ -0,0 +1,67 @@
+<?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>
index 2414dcc6b7ae115290f52a687c78ed50cebccfce..e991dedd83b1aee805ff299b9d2fa8f75a815c45 100644 (file)
   <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>
@@ -57,7 +49,9 @@
               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>
diff --git a/alto-manager/src/main/java/org/opendaylight/alto/manager/AltoCreate.java b/alto-manager/src/main/java/org/opendaylight/alto/manager/AltoCreate.java
new file mode 100644 (file)
index 0000000..ca2d84c
--- /dev/null
@@ -0,0 +1,91 @@
+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;
+  }
+}
diff --git a/alto-manager/src/main/java/org/opendaylight/alto/manager/AltoDelete.java b/alto-manager/src/main/java/org/opendaylight/alto/manager/AltoDelete.java
new file mode 100644 (file)
index 0000000..71a0b55
--- /dev/null
@@ -0,0 +1,56 @@
+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);
+  }
+}
index dd6cbb4da58362e8680d77223c7f71e016070acb..d05b286a21042b8b941684d81d57a5f18d7cc02d 100644 (file)
@@ -5,8 +5,6 @@ import java.nio.charset.StandardCharsets;
 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;
@@ -14,7 +12,8 @@ import org.apache.http.auth.AuthScope;
 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;
@@ -25,111 +24,107 @@ import org.apache.karaf.shell.console.OsgiCommandSupport;
 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("_", "-");
   }
 }
index 9c77eafcf125af8b934c2c8a92d8d132d8cc5983..0cdaeb280c9c79c8fdf209c6e5b204323aa1cfd3 100644 (file)
@@ -4,20 +4,34 @@ public class AltoManagerConstants {
   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
diff --git a/alto-manager/src/main/java/org/opendaylight/alto/manager/AltoSet.java b/alto-manager/src/main/java/org/opendaylight/alto/manager/AltoSet.java
new file mode 100644 (file)
index 0000000..4e69fbd
--- /dev/null
@@ -0,0 +1,52 @@
+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 + "\"}}";
+  }
+}
index 27f90d841448f2f3b00b64dc616d22a9a279fc46..dd47e19803fc36d2174dc4eac35902c807fbc37a 100644 (file)
@@ -1,7 +1,15 @@
 <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>
diff --git a/alto-manager/src/main/resources/default.networkmap b/alto-manager/src/main/resources/default.networkmap
deleted file mode 100644 (file)
index 40f6a9b..0000000
+++ /dev/null
@@ -1 +0,0 @@
-{"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"]}]}]}]}}}
index 8b38a8fe599ae1800e8f39637d08165aa34c4c0e..0427d2d544011a4adad368139f0f6ef2e6121427 100755 (executable)
@@ -455,9 +455,11 @@ module alto-service-types {
   /* 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;
+      }
     }
   }
 
index 10fef6bf4b146aff808fe8d06acf64bf726d0b0f..d40df36eb4f6d8bef27101ae99ee42f026af1c5d 100644 (file)
@@ -52,6 +52,15 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL
       <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>
@@ -104,14 +113,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html INTERNAL
       <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>
index d801951066a54a7bde5bc1204c63e5b1a33ec1ed..578e5b4fc94812ac5e1b79407661e77a4c1bd966 100644 (file)
@@ -12,6 +12,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
   <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>
@@ -26,9 +27,9 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
   </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'>
@@ -50,8 +51,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
   </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>
@@ -69,7 +69,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
   <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>
@@ -77,6 +76,7 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
   </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>
diff --git a/pom.xml b/pom.xml
index 069f19e7d23d9eb71bdd888f55aec6a3cfa424fc..3476d54e6dc750a13434ff7844055709d8ec6420 100644 (file)
--- a/pom.xml
+++ b/pom.xml
     <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>