Removed the old Intent REST API (from January 2014)
  /wm/onos/datagrid/add/intents/json
  /wm/onos/datagrid/get/intent/{intent_id}/json
  /wm/onos/datagrid/get/intents/{category}/json
  /wm/onos/datagrid/get/intent/{category}/{intent_id}/json
  /wm/onos/delete/intents/json

Those have been superseded by the existing REST API
that was added few months ago (May-June 2014)
  /wm/onos/intent/high
  /wm/onos/intent/high/{intent-id}
  /wm/onos/intent/low
  /wm/onos/intent/low/{intent-id}

Also, removed script "scripts/intent-installer.rb" that was using
the old REST API.

Change-Id: Ib7f0480671f860215719e5796dd6b7e7ec3a9029
diff --git a/scripts/intent-installer.rb b/scripts/intent-installer.rb
deleted file mode 100755
index ad7e34e..0000000
--- a/scripts/intent-installer.rb
+++ /dev/null
@@ -1,233 +0,0 @@
-#!/usr/bin/env ruby
-
-begin
-require "rest-client"
-rescue LoadError => e
-  puts "This scripts requires rubygems rest-client."
-  puts "Please install them using gem command. You may need to add sudo."
-  puts " $ gem install rest-client"
-  puts
-  exit -1
-end
-require "optparse"
-
-options = { 
-  :rest_op => "add",
-  :intent_id => 1, 
-  :intent_category => "high",
-  :intent_type => "shortest_intent_type", 
-  :max_switches => 4,
-  :intent_op => "add"
-}
-
-parser = OptionParser.new do |opts|
-  opts.banner = "Usage [get-options] [post-options]"
-
-  opts.separator  ""
-  opts.separator  "Get options:"
-
-  opts.on('-G', '--get_intents', 'get intents state') do
-    options[:get_intents] = true
-    options[:rest_op] = "get"
-  end
-  opts.on('-g', '--get_intent intent_id', 'get intent state') do |intent_id|
-    options[:rest_op] = "get"
-    options[:get_intent] = intent_id
-  end
-
-  opts.separator ""
-  opts.separator "Purge options"
-  opts.on('-d', '--purge', 'purge all intents') do
-    options[:rest_op] = "delete"
-  end
-
-  opts.separator  ""
-  opts.separator  "Post options:"
-
-  opts.on('-t', '--max_intents max_intents', 'max. number of intents') do |max_intents|
-    options[:max_intents] = max_intents
-  end
-  opts.on('-e', '--intent_category intent_category', 'intent category high|low') do |intent_category|
-    options[:intent_category] = intent_category
-  end
-  opts.on('-i', '--intent_id intent_id', 'global intent id') do |id|
-    options[:intent_id] = id.to_i
-  end
-  # optional argument
-  opts.on('-s', '--shortest', 'create a shortest path intent') do
-    options[:intent_type] = "shortest_intent_type"
-  end
-  # optional argument
-  opts.on('-c', '--constrained', 'create a constrained shortest path intent') do
-    options[:intent_type] = "constrained_shortest_intent_type"
-  end
-  # optional argument
-  opts.on('-r', '--random_intent', 'create minimum no. of random intents') do
-    options[:random_intent] = true
-  end
-  opts.on('-m', '--max_switches max_switches', 'max. number of switches') do |max_switches|
-    options[:max_switches] = max_switches.to_i
-  end
-  opts.on('-o', '--intent_op add|remove', 'an operation to post an intent') do |operation|
-    options[:intent_op] = operation
-  end
-  opts.on('-w', '--server server', 'server to post intents') do |server|
-    options[:server] = server
-  end
-  opts.on('-p','--port port', 'server port') do |port|
-    options[:port] = port
-  end
-  opts.on('b', '--bulk_limit bulk_limit', 'bulk request upto this limit') do |bulk_limit|
-    options[:bulk_limit] = bulk_limit
-  end
-  opts.on('f', '--freeze_intents', 'freeze dont reroute intents') do
-    options[:freeze] = "F"
-  end
-  opts.on('-h', '--help', 'Display help') do
-    puts opts
-    exit
-  end
-end
-parser.parse!
-
-
-class Intent
-  attr_reader :switches, :ports, :intent_id
-  attr_reader :intent_type, :intent_op
-  attr_reader :random_intent, :server, :port
-  attr_reader :bulk_limit, :max_switches
-
-  def initialize options
-    parse_options options
-  end
-
-  def post_intent 
-    create_specific_intent
-  end
-
-  def get_intent options
-    if options[:get_intents] == true
-      request = RestClient.get "http://#{@server}:#{@port}/wm/onos/datagrid/get/intents/#{options[:intent_category]}/json"
-    else
-      url = "http://#{@server}:#{@port}/wm/onos/datagrid/get/intent/#{options[:intent_category]}/#{options[:get_intent]}/json"
-      request = RestClient.get url
-    end
-    puts request
-  end
-
-  def purge_intents
-    response = RestClient.delete "http://#{@server}:#{@port}/wm/onos/datagrid/delete/intents/json"
-    puts response
-  end
-
-  private 
-
-  def create_specific_intent
-    if @random_intent == true
-      create_random_intent
-    else
-      create_many_intents
-    end
-  end
-
-  # create as many intents as the number of switches
-  def create_many_intents
-      intents = []
-      intents = _create_intent intents
-      post intents
-  end
-
-
-  # pick a random src switch and create intents to all other switches
-  def create_random_intent
-    intents = []
-    sw = @switches.shuffle[0]
-    rest = @switches - [sw]
-    intents = _create_intent sw, rest, intents
-    post_slice intents, true
-  end
-
-  def post_slice intents, last=false
-    @bulk_limit = @bulk_limit.to_i
-    if intents.size >= @bulk_limit
-      post intents.slice!(0..(@bulk_limit - 1))
-    end
-    if last == true
-      loop do
-        new_bulk_limit = intents.size > @bulk_limit ? @bulk_limit : intents.size
-        post intents.slice!(0..(new_bulk_limit - 1))
-        break if new_bulk_limit < @bulk_limit
-      end
-    end
-  end
-
-  def post intents
-    json_data = intents.to_json
-    response = RestClient.post "http://#{@server}:#{@port}/wm/onos/datagrid/add/intents/json", json_data, :content_type => :json, :accept => :json
-    puts response
-  end
-
-  def parse_options options
-    @max_switches = options[:max_switches].to_i || 4
-    @switches = (1..max_switches).to_a
-    @ports = (1..max_switches).to_a
-    @intent_id = options[:intent_id]
-    @intent_id ||= 1
-    @intent_type = options[:intent_type]
-    @intent_op = options[:intent_op]
-    @intent_op ||= "add"
-    @random_intent = options[:random_intent]
-    @random_intent ||= false
-    @server = options[:server]
-    @server ||= "127.0.0.1"
-    @port = options[:port]
-    @port ||= 8080
-    @bulk_limit = options[:bulk_limit]
-    @bulk_limit ||= 10000
-    @freeze = options[:freeze]
-    @freeze ||= ""
-  end
-
-
-  def _create_intent json_intents
-    (0...@max_switches).each do |idx|
-      intent = {
-        :intent_id => "#{@freeze}#{@intent_id}",
-        :intent_type => @intent_type,
-        :intent_op => @intent_op,
-        :srcSwitch => "00:00:00:00:00:00:02:02".to_s,
-        :srcPort => 1,
-        :srcMac => "00:00:c0:#{mac_format(idx)}",
-        :dstSwitch => "00:00:00:00:00:00:04:02".to_s,
-        :dstPort => 1,
-        :dstMac => "00:00:c1:#{mac_format(idx)}"
-      }
-puts intent.inspect
-      @intent_id = @intent_id + 1
-      json_intents << intent
-puts
-    end
-    json_intents
-  end
-
-  def mac_format number
-    if number > 255
-      divisor1 = number / 256
-      remainder1 = number % 256
-      divisor2 = divisor1 / 256
-      remainder2 = divisor1 % 256 
-      return sprintf("%02x:%02x:%02x",divisor2 ,remainder2, remainder1)
-    end
-    "00:00:%02x" % number
-  end
-end
-
-intent = Intent.new options
-if options[:rest_op] == "get"
-  intent.get_intent options
-elsif options[:rest_op] == "delete"
-  intent.purge_intents
-else
-  json_data = intent.post_intent
-end
-
diff --git a/src/main/java/net/onrc/onos/core/datagrid/web/DatagridWebRoutable.java b/src/main/java/net/onrc/onos/core/datagrid/web/DatagridWebRoutable.java
index 8637d3b..46d3cab 100644
--- a/src/main/java/net/onrc/onos/core/datagrid/web/DatagridWebRoutable.java
+++ b/src/main/java/net/onrc/onos/core/datagrid/web/DatagridWebRoutable.java
@@ -16,12 +16,7 @@
     @Override
     public Restlet getRestlet(Context context) {
         Router router = new Router(context);
-        router.attach("/add/intents/json", IntentResource.class);
-        router.attach("/get/intent/{intent_id}/json", IntentResource.class);
         router.attach("/get/ng-events/json", GetNGEventsResource.class);
-        router.attach("/get/intents/{category}/json", IntentResource.class);
-        router.attach("/get/intent/{category}/{intent_id}/json", IntentResource.class);
-        router.attach("/delete/intents/json", IntentResource.class);
         return router;
     }
 
diff --git a/src/main/java/net/onrc/onos/core/datagrid/web/IntentResource.java b/src/main/java/net/onrc/onos/core/datagrid/web/IntentResource.java
deleted file mode 100644
index 1dc05a2..0000000
--- a/src/main/java/net/onrc/onos/core/datagrid/web/IntentResource.java
+++ /dev/null
@@ -1,229 +0,0 @@
-package net.onrc.onos.core.datagrid.web;
-
-import java.io.IOException;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
-import java.util.Map;
-
-import net.floodlightcontroller.util.MACAddress;
-import net.onrc.onos.core.intent.ConstrainedShortestPathIntent;
-import net.onrc.onos.core.intent.Intent;
-import net.onrc.onos.core.intent.IntentMap;
-import net.onrc.onos.core.intent.IntentOperation;
-import net.onrc.onos.core.intent.IntentOperationList;
-import net.onrc.onos.core.intent.ShortestPathIntent;
-import net.onrc.onos.core.intent.runtime.IPathCalcRuntimeService;
-import net.onrc.onos.core.util.Dpid;
-
-import org.codehaus.jackson.JsonGenerationException;
-import org.codehaus.jackson.JsonNode;
-import org.codehaus.jackson.map.JsonMappingException;
-import org.codehaus.jackson.map.ObjectMapper;
-import org.codehaus.jackson.node.ArrayNode;
-import org.codehaus.jackson.node.ObjectNode;
-import org.restlet.resource.Delete;
-import org.restlet.resource.Get;
-import org.restlet.resource.Post;
-import org.restlet.resource.ServerResource;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-/**
- * old REST API implementation for the Intents.
- */
-public class IntentResource extends ServerResource {
-    private static final Logger log = LoggerFactory.getLogger(IntentResource.class);
-    // TODO need to assign proper application id.
-    private static final String APPLN_ID = "1";
-
-    @Post("json")
-    public String store(String jsonIntent) throws IOException {
-        IPathCalcRuntimeService pathRuntime = (IPathCalcRuntimeService) getContext()
-                .getAttributes().get(IPathCalcRuntimeService.class.getCanonicalName());
-        if (pathRuntime == null) {
-            log.warn("Failed to get path calc runtime");
-            return "";
-        }
-        String reply = "";
-        ObjectMapper mapper = new ObjectMapper();
-        JsonNode jNode = null;
-        try {
-            jNode = mapper.readValue(jsonIntent, JsonNode.class);
-        } catch (JsonGenerationException ex) {
-            log.error("JsonGeneration exception ", ex);
-        } catch (JsonMappingException ex) {
-            log.error("JsonMappingException occurred", ex);
-        } catch (IOException ex) {
-            log.error("IOException occurred", ex);
-        }
-
-        if (jNode != null) {
-            reply = parseJsonNode(jNode.getElements(), pathRuntime);
-        }
-        return reply;
-    }
-
-    @Delete("json")
-    public String store() {
-        IPathCalcRuntimeService pathRuntime = (IPathCalcRuntimeService) getContext().
-                getAttributes().get(IPathCalcRuntimeService.class.getCanonicalName());
-        pathRuntime.purgeIntents();
-        // TODO no reply yet from the purge intents call
-        return "";
-
-    }
-
-    @Get("json")
-    public String retrieve() throws IOException {
-        IPathCalcRuntimeService pathRuntime = (IPathCalcRuntimeService) getContext().
-                getAttributes().get(IPathCalcRuntimeService.class.getCanonicalName());
-
-        String intentCategory = (String) getRequestAttributes().get("category");
-        IntentMap intentMap = null;
-        if (intentCategory.equals("high")) {
-            intentMap = pathRuntime.getHighLevelIntents();
-        } else {
-            intentMap = pathRuntime.getPathIntents();
-        }
-        ObjectMapper mapper = new ObjectMapper();
-        String restStr = "";
-
-        String intentId = (String) getRequestAttributes().get("intent_id");
-        ArrayNode arrayNode = mapper.createArrayNode();
-        Collection<Intent> intents = intentMap.getAllIntents();
-        if (!intents.isEmpty()) {
-            if ((intentId != null)) {
-                String applnIntentId = APPLN_ID + ":" + intentId;
-                Intent intent = intentMap.getIntent(applnIntentId);
-                if (intent != null) {
-                    ObjectNode node = mapper.createObjectNode();
-                    // TODO refactor/remove duplicate code.
-                    node.put("intent_id", intentId);
-                    node.put("status", intent.getState().toString());
-                    LinkedList<String> logs = intent.getLogs();
-                    ArrayNode logNode = mapper.createArrayNode();
-                    for (String intentLog : logs) {
-                        logNode.add(intentLog);
-                    }
-                    node.put("log", logNode);
-                    arrayNode.add(node);
-                }
-            } else {
-                for (Intent intent : intents) {
-                    ObjectNode node = mapper.createObjectNode();
-                    String applnIntentId = intent.getId();
-                    intentId = applnIntentId.split(":")[1];
-                    node.put("intent_id", intentId);
-                    node.put("status", intent.getState().toString());
-                    LinkedList<String> logs = intent.getLogs();
-                    ArrayNode logNode = mapper.createArrayNode();
-                    for (String intentLog : logs) {
-                        logNode.add(intentLog);
-                    }
-                    node.put("log", logNode);
-                    arrayNode.add(node);
-                }
-            }
-            restStr = mapper.writeValueAsString(arrayNode);
-        }
-        return restStr;
-    }
-
-    private String parseJsonNode(Iterator<JsonNode> nodes,
-                                 IPathCalcRuntimeService pathRuntime) throws IOException {
-        IntentOperationList operations = new IntentOperationList();
-        ObjectMapper mapper = new ObjectMapper();
-        ArrayNode arrayNode = mapper.createArrayNode();
-        while (nodes.hasNext()) {
-            JsonNode node = nodes.next();
-            if (node.isObject()) {
-                JsonNode data;
-                Iterator<String> fieldNames = node.getFieldNames();
-                Map<String, Object> fields = new HashMap<>();
-                while (fieldNames.hasNext()) {
-                    String fieldName = fieldNames.next();
-                    data = node.get(fieldName);
-                    parseFields(data, fieldName, fields);
-                }
-                Intent intent = processIntent(fields, operations);
-                appendIntentStatus(intent, (String) fields.get("intent_id"), mapper, arrayNode);
-            }
-        }
-        pathRuntime.executeIntentOperations(operations);
-        return mapper.writeValueAsString(arrayNode);
-    }
-
-    private void appendIntentStatus(Intent intent, final String intentId,
-                                    ObjectMapper mapper, ArrayNode arrayNode) throws IOException {
-        ObjectNode node = mapper.createObjectNode();
-        node.put("intent_id", intentId);
-        node.put("status", intent.getState().toString());
-        LinkedList<String> logs = intent.getLogs();
-        ArrayNode logNode = mapper.createArrayNode();
-        for (String intentLog : logs) {
-            logNode.add(intentLog);
-        }
-        node.put("log", logNode);
-        arrayNode.add(node);
-    }
-
-    private Intent processIntent(Map<String, Object> fields, IntentOperationList operations) {
-        String intentType = (String) fields.get("intent_type");
-        String intentOp = (String) fields.get("intent_op");
-        Intent intent;
-        String intentId = (String) fields.get("intent_id");
-        boolean pathFrozen = false;
-        if (intentId.startsWith("F")) { // TODO define REST API for frozen intents
-            pathFrozen = true;
-            intentId = intentId.substring(1);
-        }
-        String applnIntentId = APPLN_ID + ":" + intentId;
-
-        IntentOperation.Operator operation = IntentOperation.Operator.ADD;
-        if ((intentOp.equals("remove"))) {
-            operation = IntentOperation.Operator.REMOVE;
-        }
-        Dpid srcSwitchDpid = new Dpid((String) fields.get("srcSwitch"));
-        Dpid dstSwitchDpid = new Dpid((String) fields.get("dstSwitch"));
-
-        if (intentType.equals("shortest_intent_type")) {
-            ShortestPathIntent spi = new ShortestPathIntent(applnIntentId,
-                    srcSwitchDpid.value(),
-                    (long) fields.get("srcPort"),
-                    MACAddress.valueOf((String) fields.get("srcMac")).toLong(),
-                    dstSwitchDpid.value(),
-                    (long) fields.get("dstPort"),
-                    MACAddress.valueOf((String) fields.get("dstMac")).toLong());
-            spi.setPathFrozen(pathFrozen);
-            operations.add(operation, spi);
-            intent = spi;
-        } else {
-            ConstrainedShortestPathIntent cspi = new ConstrainedShortestPathIntent(applnIntentId,
-                    Long.decode((String) fields.get("srcSwitch")),
-                    (long) fields.get("srcPort"),
-                    MACAddress.valueOf((String) fields.get("srcMac")).toLong(),
-                    Long.decode((String) fields.get("dstSwitch")),
-                    (long) fields.get("dstPort"),
-                    MACAddress.valueOf((String) fields.get("dstMac")).toLong(),
-                    (double) fields.get("bandwidth"));
-            cspi.setPathFrozen(pathFrozen);
-            operations.add(operation, cspi);
-            intent = cspi;
-        }
-        return intent;
-    }
-
-    private void parseFields(JsonNode node, String fieldName, Map<String, Object> fields) {
-        if ((node.isTextual())) {
-            fields.put(fieldName, node.getTextValue());
-        } else if ((node.isInt())) {
-            fields.put(fieldName, (long) node.getIntValue());
-        } else if (node.isDouble()) {
-            fields.put(fieldName, node.getDoubleValue());
-        } else if ((node.isLong())) {
-            fields.put(fieldName, node.getLongValue());
-        }
-    }
-}