Speed up SouthboundIT through multi-threading test cases
[ovsdb.git] / northbound / src / main / java / org / opendaylight / ovsdb / northbound / NodeResource.java
index 3cdf0f126d5fe6a455231cda71547ceb7b01e259..5ccdf4f41f3cda1f641c2e7077416ef95713f5d1 100644 (file)
@@ -1,7 +1,16 @@
+/*
+ * Copyright (c) 2014, 2015 Red Hat, Inc. 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
+ */
+
 package org.opendaylight.ovsdb.northbound;
 
 import com.fasterxml.jackson.databind.SerializationFeature;
 import java.io.InputStream;
+import java.util.Collections;
 import java.util.List;
 
 import javax.ws.rs.Consumes;
@@ -18,11 +27,11 @@ import javax.ws.rs.core.Response;
 import org.opendaylight.controller.northbound.commons.RestMessages;
 import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException;
 import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException;
-import org.opendaylight.controller.sal.core.Node;
-import org.opendaylight.controller.sal.utils.ServiceHelper;
 import org.opendaylight.ovsdb.lib.OvsdbClient;
 import org.opendaylight.ovsdb.plugin.api.Connection;
 import org.opendaylight.ovsdb.plugin.api.OvsdbConnectionService;
+import org.opendaylight.ovsdb.utils.servicehelper.ServiceHelper;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.DeserializationFeature;
@@ -93,12 +102,15 @@ public class NodeResource {
     public Response getNodes() throws JsonProcessingException {
         OvsdbConnectionService connectionService = (OvsdbConnectionService)ServiceHelper.getGlobalInstance(OvsdbConnectionService.class, this);
         List<Node> nodes = connectionService.getNodes();
-        if (nodes == null) return Response.noContent().build();
+        if (nodes == null) {
+            return Response.noContent().build();
+        }
 
         List<String> nodeIds = Lists.newArrayList();
         for (Node node : nodes) {
-            nodeIds.add(node.toString());
+            nodeIds.add(node.getId().getValue());
         }
+        Collections.sort(nodeIds);
 
         String response = objectMapper.writeValueAsString(nodeIds);
         return Response.status(Response.Status.OK)