Formatting fixes for datagrid - WHITESPACE ONLY
Change-Id: I39c99795fcfef974b5b8c95cb7493e12322f6f74
diff --git a/src/main/java/net/onrc/onos/datagrid/HazelcastDatagrid.java b/src/main/java/net/onrc/onos/datagrid/HazelcastDatagrid.java
index 563be33..31de685 100755
--- a/src/main/java/net/onrc/onos/datagrid/HazelcastDatagrid.java
+++ b/src/main/java/net/onrc/onos/datagrid/HazelcastDatagrid.java
@@ -178,10 +178,10 @@
Class<K> typeK, Class<V> typeV) {
synchronized (eventChannels) {
IEventChannel<K, V> eventChannel =
- createChannelImpl(channelName, typeK, typeV);
+ createChannelImpl(channelName, typeK, typeV);
eventChannel.startup();
return eventChannel;
- }
+ }
}
/**
@@ -208,8 +208,8 @@
// Add the channel if the first listener
if (genericEventChannel == null) {
IEventChannel<K, V> castedEventChannel =
- new HazelcastEventChannel<K, V>(hazelcastInstance,
- channelName, typeK, typeV);
+ new HazelcastEventChannel<K, V>(hazelcastInstance,
+ channelName, typeK, typeV);
eventChannels.put(channelName, castedEventChannel);
return castedEventChannel;
}
@@ -223,13 +223,13 @@
}
@SuppressWarnings("unchecked")
IEventChannel<K, V> castedEventChannel =
- (IEventChannel<K, V>) genericEventChannel;
+ (IEventChannel<K, V>) genericEventChannel;
return castedEventChannel;
}
/**
* Add event channel listener.
- *
+ * <p/>
* NOTE: The channel is started automatically right after the listener
* is added.
*
@@ -247,12 +247,12 @@
Class<K> typeK, Class<V> typeV) {
synchronized (eventChannels) {
IEventChannel<K, V> eventChannel =
- createChannelImpl(channelName, typeK, typeV);
+ createChannelImpl(channelName, typeK, typeV);
eventChannel.addListener(listener);
eventChannel.startup();
return eventChannel;
- }
+ }
}
/**
@@ -266,9 +266,9 @@
@Override
public <K, V> void removeListener(String channelName,
IEventChannelListener<K, V> listener) {
- synchronized (eventChannels) {
+ synchronized (eventChannels) {
IEventChannel<?, ?> genericEventChannel =
- eventChannels.get(channelName);
+ eventChannels.get(channelName);
if (genericEventChannel != null) {
//
@@ -279,7 +279,7 @@
//
@SuppressWarnings("unchecked")
IEventChannel<K, V> castedEventChannel =
- (IEventChannel<K, V>) genericEventChannel;
+ (IEventChannel<K, V>) genericEventChannel;
castedEventChannel.removeListener(listener);
}
}
diff --git a/src/main/java/net/onrc/onos/datagrid/HazelcastEventChannel.java b/src/main/java/net/onrc/onos/datagrid/HazelcastEventChannel.java
index 53d35c2..88fb544 100644
--- a/src/main/java/net/onrc/onos/datagrid/HazelcastEventChannel.java
+++ b/src/main/java/net/onrc/onos/datagrid/HazelcastEventChannel.java
@@ -45,10 +45,10 @@
/**
* Constructor for a given event channel name.
*
- * @param newHazelcastInstance the Hazelcast instance to use.
- * @param newChannelName the event channel name.
- * @param newTypeK the type of the Key in the Key-Value store.
- * @param newTypeV the type of the Value in the Key-Value store.
+ * @param newHazelcastInstance the Hazelcast instance to use.
+ * @param newChannelName the event channel name.
+ * @param newTypeK the type of the Key in the Key-Value store.
+ * @param newTypeV the type of the Value in the Key-Value store.
*/
public HazelcastEventChannel(HazelcastInstance newHazelcastInstance,
String newChannelName, Class<K> newTypeK,
@@ -147,7 +147,7 @@
/**
* Add a transient entry to the channel.
- *
+ * <p/>
* The added entry is transient and will automatically timeout after 1ms.
*
* @param key the key of the entry to add.
diff --git a/src/main/java/net/onrc/onos/datagrid/IDatagridService.java b/src/main/java/net/onrc/onos/datagrid/IDatagridService.java
index 1015bf2..7c067ae 100755
--- a/src/main/java/net/onrc/onos/datagrid/IDatagridService.java
+++ b/src/main/java/net/onrc/onos/datagrid/IDatagridService.java
@@ -8,40 +8,40 @@
public interface IDatagridService extends IFloodlightService {
/**
* Create an event channel.
- *
+ * <p/>
* If the channel already exists, just return it.
* NOTE: The channel is started automatically.
*
* @param channelName the event channel name.
- * @param typeK the type of the Key in the Key-Value store.
- * @param typeV the type of the Value in the Key-Value store.
+ * @param typeK the type of the Key in the Key-Value store.
+ * @param typeV the type of the Value in the Key-Value store.
* @return the event channel for the channel name.
*/
<K, V> IEventChannel<K, V> createChannel(String channelName,
- Class<K> typeK, Class<V> typeV);
+ Class<K> typeK, Class<V> typeV);
/**
* Add event channel listener.
- *
+ * <p/>
* NOTE: The channel is started automatically right after the listener
* is added.
*
* @param channelName the event channel name.
- * @param listener the listener to add.
- * @param typeK the type of the Key in the Key-Value store.
- * @param typeV the type of the Value in the Key-Value store.
+ * @param listener the listener to add.
+ * @param typeK the type of the Key in the Key-Value store.
+ * @param typeV the type of the Value in the Key-Value store.
* @return the event channel for the channel name.
*/
<K, V> IEventChannel<K, V> addListener(String channelName,
- IEventChannelListener<K, V> listener,
- Class<K> typeK, Class<V> typeV);
+ IEventChannelListener<K, V> listener,
+ Class<K> typeK, Class<V> typeV);
/**
* Remove event channel listener.
*
* @param channelName the event channel name.
- * @param listener the listener to remove.
+ * @param listener the listener to remove.
*/
<K, V> void removeListener(String channelName,
- IEventChannelListener<K, V> listener);
+ IEventChannelListener<K, V> listener);
}
diff --git a/src/main/java/net/onrc/onos/datagrid/IEventChannel.java b/src/main/java/net/onrc/onos/datagrid/IEventChannel.java
index 453f21d..c76c7a6 100644
--- a/src/main/java/net/onrc/onos/datagrid/IEventChannel.java
+++ b/src/main/java/net/onrc/onos/datagrid/IEventChannel.java
@@ -43,17 +43,17 @@
/**
* Add an entry to the channel.
*
- * @param key the key of the entry to add.
+ * @param key the key of the entry to add.
* @param value the value of the entry to add.
*/
void addEntry(K key, V value);
/**
* Add a transient entry to the channel.
- *
+ * <p/>
* The added entry is transient and will automatically timeout after 1ms.
*
- * @param key the key of the entry to add.
+ * @param key the key of the entry to add.
* @param value the value of the entry to add.
*/
void addTransientEntry(K key, V value);
@@ -68,7 +68,7 @@
/**
* Update an entry in the channel.
*
- * @param key the key of the entry to update.
+ * @param key the key of the entry to update.
* @param value the value of the entry to update.
*/
void updateEntry(K key, V value);
diff --git a/src/main/java/net/onrc/onos/datagrid/web/GetNGEventsResource.java b/src/main/java/net/onrc/onos/datagrid/web/GetNGEventsResource.java
index 20efa68..bbf03cb 100644
--- a/src/main/java/net/onrc/onos/datagrid/web/GetNGEventsResource.java
+++ b/src/main/java/net/onrc/onos/datagrid/web/GetNGEventsResource.java
@@ -14,28 +14,28 @@
public class GetNGEventsResource extends ServerResource {
- public static final Logger log = LoggerFactory.getLogger(GetNGEventsResource.class);
-
- @Get("json")
- public String retrieve() {
- IDatagridService datagridService =
- (IDatagridService) getContext().getAttributes().
- get(IDatagridService.class.getCanonicalName());
-
-
- log.debug("Get network graph events");
-
- IEventChannel<byte[], TopologyEvent> channel = datagridService.createChannel(TopologyManager.EVENT_CHANNEL_NAME,
- byte[].class, TopologyEvent.class);
-
- Collection<TopologyEvent> entries = channel.getAllEntries();
-
- String result = "";
- for (TopologyEvent event : entries) {
- result += event.toString() + "\n";
- }
-
- return result;
- }
+ public static final Logger log = LoggerFactory.getLogger(GetNGEventsResource.class);
+
+ @Get("json")
+ public String retrieve() {
+ IDatagridService datagridService =
+ (IDatagridService) getContext().getAttributes().
+ get(IDatagridService.class.getCanonicalName());
+
+
+ log.debug("Get network graph events");
+
+ IEventChannel<byte[], TopologyEvent> channel = datagridService.createChannel(TopologyManager.EVENT_CHANNEL_NAME,
+ byte[].class, TopologyEvent.class);
+
+ Collection<TopologyEvent> entries = channel.getAllEntries();
+
+ String result = "";
+ for (TopologyEvent event : entries) {
+ result += event.toString() + "\n";
+ }
+
+ return result;
+ }
}
diff --git a/src/main/java/net/onrc/onos/datagrid/web/GetNGFlowsSummaryResource.java b/src/main/java/net/onrc/onos/datagrid/web/GetNGFlowsSummaryResource.java
index 16f41ef..2b38caa 100644
--- a/src/main/java/net/onrc/onos/datagrid/web/GetNGFlowsSummaryResource.java
+++ b/src/main/java/net/onrc/onos/datagrid/web/GetNGFlowsSummaryResource.java
@@ -33,82 +33,82 @@
*
* NOTE: This REST API call is needed for the ONOS GUI.
*
- * GET /wm/onos/datagrid/get/ng-flows/summary/json
+ * GET /wm/onos/datagrid/get/ng-flows/summary/json
*/
public class GetNGFlowsSummaryResource extends ServerResource {
public static final Logger log = LoggerFactory.getLogger(GetNGFlowsSummaryResource.class);
-
+
@Get("json")
public ArrayList<FlowPath> retrieve() {
- ArrayList<FlowPath> result = new ArrayList<>();
- SortedMap<Long, FlowPath> sortedFlowPaths = new TreeMap<>();
+ ArrayList<FlowPath> result = new ArrayList<>();
+ SortedMap<Long, FlowPath> sortedFlowPaths = new TreeMap<>();
IPathCalcRuntimeService pathRuntime =
- (IPathCalcRuntimeService)getContext().
- getAttributes().get(IPathCalcRuntimeService.class.getCanonicalName());
- log.debug("Get NG Flows Summary");
+ (IPathCalcRuntimeService) getContext().
+ getAttributes().get(IPathCalcRuntimeService.class.getCanonicalName());
+ log.debug("Get NG Flows Summary");
- IntentMap parentIntentMap = pathRuntime.getHighLevelIntents();
- IntentMap intentMap = pathRuntime.getPathIntents();
- for (Intent parentIntent : parentIntentMap.getAllIntents()) {
- // Get only installed Shortest Paths
- if (parentIntent.getState() != IntentState.INST_ACK)
- continue;
- if (! (parentIntent instanceof ShortestPathIntent))
- continue;
- ShortestPathIntent spIntent = (ShortestPathIntent)parentIntent;
+ IntentMap parentIntentMap = pathRuntime.getHighLevelIntents();
+ IntentMap intentMap = pathRuntime.getPathIntents();
+ for (Intent parentIntent : parentIntentMap.getAllIntents()) {
+ // Get only installed Shortest Paths
+ if (parentIntent.getState() != IntentState.INST_ACK)
+ continue;
+ if (!(parentIntent instanceof ShortestPathIntent))
+ continue;
+ ShortestPathIntent spIntent = (ShortestPathIntent) parentIntent;
- // Get the Path Intent
- Intent intent = intentMap.getIntent(spIntent.getPathIntentId());
- if (! (intent instanceof PathIntent))
- continue;
- PathIntent pathIntent = (PathIntent)intent;
+ // Get the Path Intent
+ Intent intent = intentMap.getIntent(spIntent.getPathIntentId());
+ if (!(intent instanceof PathIntent))
+ continue;
+ PathIntent pathIntent = (PathIntent) intent;
- // Decode the Shortest Path ID
- String applnIntentId = parentIntent.getId();
- String intentId = applnIntentId.split(":")[1];
+ // Decode the Shortest Path ID
+ String applnIntentId = parentIntent.getId();
+ String intentId = applnIntentId.split(":")[1];
- // Create the Flow Path
- FlowId flowId = new FlowId(intentId);
- FlowPath flowPath = new FlowPath();
- flowPath.setFlowId(flowId);
- sortedFlowPaths.put(flowPath.flowId().value(), flowPath);
+ // Create the Flow Path
+ FlowId flowId = new FlowId(intentId);
+ FlowPath flowPath = new FlowPath();
+ flowPath.setFlowId(flowId);
+ sortedFlowPaths.put(flowPath.flowId().value(), flowPath);
- flowPath.setInstallerId(new CallerId("E"));
- flowPath.setFlowEntryActions(null);
- flowPath.setFlowPathType(FlowPathType.FP_TYPE_SHORTEST_PATH);
- flowPath.setFlowPathUserState(FlowPathUserState.FP_USER_ADD);
+ flowPath.setInstallerId(new CallerId("E"));
+ flowPath.setFlowEntryActions(null);
+ flowPath.setFlowPathType(FlowPathType.FP_TYPE_SHORTEST_PATH);
+ flowPath.setFlowPathUserState(FlowPathUserState.FP_USER_ADD);
- // Setup the Source and Destination DPID and Port
- SwitchPort srcPort = flowPath.dataPath().srcPort();
- SwitchPort dstPort = flowPath.dataPath().dstPort();
- srcPort.setDpid(new Dpid(spIntent.getSrcSwitchDpid()));
- srcPort.setPort(new Port((short)spIntent.getSrcPortNumber()));
- dstPort.setDpid(new Dpid(spIntent.getDstSwitchDpid()));
- dstPort.setPort(new Port((short)spIntent.getDstPortNumber()));
+ // Setup the Source and Destination DPID and Port
+ SwitchPort srcPort = flowPath.dataPath().srcPort();
+ SwitchPort dstPort = flowPath.dataPath().dstPort();
+ srcPort.setDpid(new Dpid(spIntent.getSrcSwitchDpid()));
+ srcPort.setPort(new Port((short) spIntent.getSrcPortNumber()));
+ dstPort.setDpid(new Dpid(spIntent.getDstSwitchDpid()));
+ dstPort.setPort(new Port((short) spIntent.getDstPortNumber()));
- // Extract the Flow Entries
- Path path = pathIntent.getPath();
- FlowEntry flowEntry;
- ArrayList<FlowEntry> flowEntries = new ArrayList<>();
- for (LinkEvent linkEvent : path) {
- Dpid dpid = new Dpid(linkEvent.getSrc().getDpid());
- flowEntry = new FlowEntry();
- flowEntry.setDpid(dpid);
- flowEntries.add(flowEntry);
- }
- // Add the final Flow Entry
- flowEntry = new FlowEntry();
- flowEntry.setDpid(new Dpid(spIntent.getDstSwitchDpid()));
- flowEntries.add(flowEntry);
- flowPath.dataPath().setFlowEntries(flowEntries);
- }
+ // Extract the Flow Entries
+ Path path = pathIntent.getPath();
+ FlowEntry flowEntry;
+ ArrayList<FlowEntry> flowEntries = new ArrayList<>();
+ for (LinkEvent linkEvent : path) {
+ Dpid dpid = new Dpid(linkEvent.getSrc().getDpid());
+ flowEntry = new FlowEntry();
+ flowEntry.setDpid(dpid);
+ flowEntries.add(flowEntry);
+ }
+ // Add the final Flow Entry
+ flowEntry = new FlowEntry();
+ flowEntry.setDpid(new Dpid(spIntent.getDstSwitchDpid()));
+ flowEntries.add(flowEntry);
+ flowPath.dataPath().setFlowEntries(flowEntries);
+ }
- // Prepare the return result
- for (FlowPath flowPath : sortedFlowPaths.values())
- result.add(flowPath);
+ // Prepare the return result
+ for (FlowPath flowPath : sortedFlowPaths.values())
+ result.add(flowPath);
- return result;
+ return result;
}
}
diff --git a/src/main/java/net/onrc/onos/datagrid/web/IntentResource.java b/src/main/java/net/onrc/onos/datagrid/web/IntentResource.java
index b07be6b..dd73704 100755
--- a/src/main/java/net/onrc/onos/datagrid/web/IntentResource.java
+++ b/src/main/java/net/onrc/onos/datagrid/web/IntentResource.java
@@ -7,6 +7,7 @@
import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
+
import net.onrc.onos.intent.ConstrainedShortestPathIntent;
import net.onrc.onos.intent.ShortestPathIntent;
import net.onrc.onos.intent.IntentOperation;
@@ -21,9 +22,11 @@
import org.restlet.resource.ServerResource;
import org.codehaus.jackson.map.ObjectMapper;
import net.floodlightcontroller.util.MACAddress;
+
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Map;
+
import org.codehaus.jackson.node.ArrayNode;
import org.codehaus.jackson.node.ObjectNode;
import org.restlet.resource.Delete;
@@ -32,56 +35,55 @@
import org.slf4j.LoggerFactory;
/**
- *
* @author nickkaranatsios
*/
public class IntentResource extends ServerResource {
private final static Logger log = LoggerFactory.getLogger(IntentResource.class);
// TODO need to assign proper application id.
private final String APPLN_ID = "1";
-
+
@Post("json")
public String store(String jsonIntent) throws IOException {
- IPathCalcRuntimeService pathRuntime = (IPathCalcRuntimeService)getContext()
+ 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);
- }
+ 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);
- }
+ if (jNode != null) {
+ reply = parseJsonNode(jNode.getElements(), pathRuntime);
+ }
return reply;
}
-
+
@Delete("json")
public String store() {
- IPathCalcRuntimeService pathRuntime = (IPathCalcRuntimeService)getContext().
+ 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().
+ IPathCalcRuntimeService pathRuntime = (IPathCalcRuntimeService) getContext().
getAttributes().get(IPathCalcRuntimeService.class.getCanonicalName());
-
+
String intentCategory = (String) getRequestAttributes().get("category");
IntentMap intentMap = null;
if (intentCategory.equals("high")) {
@@ -96,7 +98,7 @@
ArrayNode arrayNode = mapper.createArrayNode();
Collection<Intent> intents = intentMap.getAllIntents();
if (!intents.isEmpty()) {
- if ((intentId != null )) {
+ if ((intentId != null)) {
String applnIntentId = APPLN_ID + ":" + intentId;
Intent intent = intentMap.getIntent(applnIntentId);
if (intent != null) {
@@ -106,7 +108,7 @@
node.put("status", intent.getState().toString());
LinkedList<String> logs = intent.getLogs();
ArrayNode logNode = mapper.createArrayNode();
- for (String intentLog :logs) {
+ for (String intentLog : logs) {
logNode.add(intentLog);
}
node.put("log", logNode);
@@ -121,7 +123,7 @@
node.put("status", intent.getState().toString());
LinkedList<String> logs = intent.getLogs();
ArrayNode logNode = mapper.createArrayNode();
- for (String intentLog :logs) {
+ for (String intentLog : logs) {
logNode.add(intentLog);
}
node.put("log", logNode);
@@ -132,33 +134,33 @@
}
return restStr;
}
-
+
private String parseJsonNode(Iterator<JsonNode> nodes,
- IPathCalcRuntimeService pathRuntime) throws IOException {
+ 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();
+ 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);
+ 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);
- }
- }
+ 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 {
+ 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());
@@ -170,19 +172,19 @@
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");
+ String intentType = (String) fields.get("intent_type");
+ String intentOp = (String) fields.get("intent_op");
Intent intent;
- String intentId = (String)fields.get("intent_id");
+ 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;
@@ -218,7 +220,7 @@
if ((node.isTextual())) {
fields.put(fieldName, node.getTextValue());
} else if ((node.isInt())) {
- fields.put(fieldName, (long)node.getIntValue());
+ fields.put(fieldName, (long) node.getIntValue());
} else if (node.isDouble()) {
fields.put(fieldName, node.getDoubleValue());
} else if ((node.isLong())) {