Formatting fixes for datagrid - WHITESPACE ONLY
Change-Id: I39c99795fcfef974b5b8c95cb7493e12322f6f74
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())) {