Jian Li
Committed by Gerrit Code Review

Clean up source code of REST API

- Add missing @Produces annotation
- Correct comments
- Restrict variable access level

Change-Id: I7f75650b83651248370e7781b1e8aec7eac2314c
Showing 22 changed files with 228 additions and 199 deletions
......@@ -28,6 +28,8 @@ import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.IOException;
import java.io.InputStream;
......@@ -42,16 +44,17 @@ import static org.onlab.util.Tools.nullIsNotFound;
@Path("cluster")
public class ClusterWebResource extends AbstractWebResource {
public static final String NODE_NOT_FOUND = "Node is not found";
private static final String NODE_NOT_FOUND = "Node is not found";
/**
* Get all cluster nodes.
* Returns array of all cluster nodes.
*
* @return 200 OK
* @return 200 OK with a collection of cluster nodes
* @onos.rsModel Cluster
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getClusterNodes() {
Iterable<ControllerNode> nodes = get(ClusterService.class).getNodes();
return ok(encodeArray(ControllerNode.class, "nodes", nodes)).build();
......@@ -62,11 +65,12 @@ public class ClusterWebResource extends AbstractWebResource {
* Returns details of the specified cluster node.
*
* @param id cluster node identifier
* @return 200 OK
* @return 200 OK with a cluster node
* @onos.rsModel ClusterNode
*/
@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response getClusterNode(@PathParam("id") String id) {
ControllerNode node = nullIsNotFound(get(ClusterService.class).getNode(new NodeId(id)),
NODE_NOT_FOUND);
......@@ -84,6 +88,7 @@ public class ClusterWebResource extends AbstractWebResource {
*/
@POST
@Path("configuration")
@Produces(MediaType.APPLICATION_JSON)
public Response formCluster(InputStream config) throws IOException {
JsonCodec<ControllerNode> codec = codec(ControllerNode.class);
ObjectNode root = (ObjectNode) mapper().readTree(config);
......@@ -93,5 +98,4 @@ public class ClusterWebResource extends AbstractWebResource {
return Response.ok().build();
}
}
......
......@@ -26,6 +26,7 @@ import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.IOException;
......@@ -41,12 +42,13 @@ import static org.onlab.util.Tools.nullIsNotFound;
public class ComponentConfigWebResource extends AbstractWebResource {
/**
* Get all component configurations.
* Gets all component configurations.
* Returns collection of all registered component configurations.
*
* @return 200 OK
* @return 200 OK with a collection of component configurations
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getComponentConfigs() {
ComponentConfigService service = get(ComponentConfigService.class);
Set<String> components = service.getComponentNames();
......@@ -56,13 +58,14 @@ public class ComponentConfigWebResource extends AbstractWebResource {
}
/**
* Get configuration of the specified component.
* Gets configuration of the specified component.
*
* @param component component name
* @return 200 OK
* @return 200 OK with a collection of component configurations
*/
@GET
@Path("{component}")
@Produces(MediaType.APPLICATION_JSON)
public Response getComponentConfigs(@PathParam("component") String component) {
ComponentConfigService service = get(ComponentConfigService.class);
ObjectNode root = mapper().createObjectNode();
......@@ -80,7 +83,7 @@ public class ComponentConfigWebResource extends AbstractWebResource {
}
/**
* Selectively set configuration properties.
* Selectively sets configuration properties.
* Sets only the properties present in the JSON request.
*
* @param component component name
......@@ -97,11 +100,11 @@ public class ComponentConfigWebResource extends AbstractWebResource {
ObjectNode props = (ObjectNode) mapper().readTree(request);
props.fieldNames().forEachRemaining(k -> service.setProperty(component, k,
props.path(k).asText()));
return Response.noContent().build();
return Response.ok().build();
}
/**
* Selectively clear configuration properties.
* Selectively clears configuration properties.
* Clears only the properties present in the JSON request.
*
* @param component component name
......
......@@ -15,15 +15,8 @@
*/
package org.onosproject.rest.resources;
import java.io.InputStream;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.onlab.rest.BaseResource;
import org.onosproject.net.device.DeviceProviderRegistry;
import org.onosproject.net.device.DeviceService;
......@@ -32,8 +25,12 @@ import org.onosproject.net.link.LinkProviderRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.InputStream;
import static javax.ws.rs.core.Response.Status.INTERNAL_SERVER_ERROR;
......@@ -54,7 +51,6 @@ public class ConfigWebResource extends BaseResource {
@POST
@Path("topology")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response topology(InputStream input) {
try {
ObjectMapper mapper = new ObjectMapper();
......
......@@ -47,7 +47,7 @@ import static org.onlab.util.Tools.nullIsNotFound;
public class DeviceKeyWebResource extends AbstractWebResource {
@Context
UriInfo uriInfo;
private UriInfo uriInfo;
private static final String DEVICE_KEY_NOT_FOUND = "Device key was not found";
......@@ -55,25 +55,27 @@ public class DeviceKeyWebResource extends AbstractWebResource {
* Gets all device keys.
* Returns array of all device keys.
*
* @return 200 OK
* @return 200 OK with a collection of device keys
* @onos.rsModel Devicekeys
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getDeviceKeys() {
Iterable<DeviceKey> deviceKeys = get(DeviceKeyService.class).getDeviceKeys();
return ok(encodeArray(DeviceKey.class, "keys", deviceKeys)).build();
}
/**
* Get a single device key by device key unique identifier.
* Gets a single device key by device key unique identifier.
* Returns the specified device key.
*
* @param id device key identifier
* @return 200 OK, 404 not found
* @return 200 OK with a device key, 404 not found
* @onos.rsModel Devicekey
*/
@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response getDeviceKey(@PathParam("id") String id) {
DeviceKey deviceKey = nullIsNotFound(get(DeviceKeyService.class).getDeviceKey(DeviceKeyId.deviceKeyId(id)),
DEVICE_KEY_NOT_FOUND);
......@@ -115,10 +117,11 @@ public class DeviceKeyWebResource extends AbstractWebResource {
* Removes a device key by device key identifier.
*
* @param id device key identifier
* @return 200 OK, 404 not found
* @return 200 OK with a removed device key, 404 not found
*/
@DELETE
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response removeDeviceKey(@PathParam("id") String id) {
DeviceKey deviceKey = nullIsNotFound(get(DeviceKeyService.class).getDeviceKey(DeviceKeyId.deviceKeyId(id)),
DEVICE_KEY_NOT_FOUND);
......
......@@ -26,6 +26,8 @@ import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
......@@ -39,31 +41,33 @@ import static org.onosproject.net.DeviceId.deviceId;
@Path("devices")
public class DevicesWebResource extends AbstractWebResource {
public static final String DEVICE_NOT_FOUND = "Device is not found";
private static final String DEVICE_NOT_FOUND = "Device is not found";
/**
* Get all infrastructure devices.
* Gets all infrastructure devices.
* Returns array of all discovered infrastructure devices.
*
* @return 200 OK
* @return 200 OK with a collection of devices
* @onos.rsModel DevicesGet
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getDevices() {
Iterable<Device> devices = get(DeviceService.class).getDevices();
return ok(encodeArray(Device.class, "devices", devices)).build();
}
/**
* Get details of infrastructure device.
* Gets details of infrastructure device.
* Returns details of the specified infrastructure device.
*
* @param id device identifier
* @return 200 OK
* @return 200 OK with a device
* @onos.rsModel DeviceGet
*/
@GET
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response getDevice(@PathParam("id") String id) {
Device device = nullIsNotFound(get(DeviceService.class).getDevice(deviceId(id)),
DEVICE_NOT_FOUND);
......@@ -71,15 +75,16 @@ public class DevicesWebResource extends AbstractWebResource {
}
/**
* Remove infrastructure device.
* Removes infrastructure device.
* Administratively deletes the specified device from the inventory of
* known devices.
*
* @param id device identifier
* @return 200 OK
* @return 200 OK with the removed device
*/
@DELETE
@Path("{id}")
@Produces(MediaType.APPLICATION_JSON)
public Response removeDevice(@PathParam("id") String id) {
Device device = nullIsNotFound(get(DeviceService.class).getDevice(deviceId(id)),
DEVICE_NOT_FOUND);
......@@ -88,15 +93,16 @@ public class DevicesWebResource extends AbstractWebResource {
}
/**
* Get ports of infrastructure device.
* Gets ports of infrastructure device.
* Returns details of the specified infrastructure device.
*
* @onos.rsModel DeviceGetPorts
* @param id device identifier
* @return 200 OK
* @return 200 OK with a collection of ports of the given device
*/
@GET
@Path("{id}/ports")
@Produces(MediaType.APPLICATION_JSON)
public Response getDevicePorts(@PathParam("id") String id) {
DeviceService service = get(DeviceService.class);
Device device = nullIsNotFound(service.getDevice(deviceId(id)), DEVICE_NOT_FOUND);
......
......@@ -45,14 +45,14 @@ import java.io.InputStream;
public class FlowObjectiveWebResource extends AbstractWebResource {
@Context
UriInfo uriInfo;
private UriInfo uriInfo;
public static final String DEVICE_INVALID =
private static final String DEVICE_INVALID =
"Invalid deviceId in objective creation request";
public static final String POLICY_INVALID = "Invalid policy";
private static final String POLICY_INVALID = "Invalid policy";
final FlowObjectiveService flowObjectiveService = get(FlowObjectiveService.class);
final ObjectNode root = mapper().createObjectNode();
private final FlowObjectiveService flowObjectiveService = get(FlowObjectiveService.class);
private final ObjectNode root = mapper().createObjectNode();
/**
* Creates and installs a new filtering objective for the specified device.
......@@ -168,7 +168,7 @@ public class FlowObjectiveWebResource extends AbstractWebResource {
/**
* Returns the globally unique nextId.
*
* @return nextId
* @return 200 OK with next identifier
* @onos.rsModel NextId
*/
@GET
......@@ -183,13 +183,13 @@ public class FlowObjectiveWebResource extends AbstractWebResource {
* Installs the filtering rules onto the specified device.
*
* @param stream filtering rule JSON
* @return 200 OK
* @onos.rsModel ObjectivePolicy
*/
@POST
@Path("policy")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public void initPolicy(InputStream stream) {
public Response initPolicy(InputStream stream) {
try {
ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
......@@ -200,13 +200,14 @@ public class FlowObjectiveWebResource extends AbstractWebResource {
}
flowObjectiveService.initPolicy(policyJson.asText());
return Response.ok().build();
} catch (IOException e) {
throw new IllegalArgumentException(e);
}
}
/**
* Validate the deviceId that is contained in json string against the
* Validates the deviceId that is contained in json string against the
* input deviceId.
*
* @param deviceId device identifier
......
......@@ -57,22 +57,23 @@ import static org.onlab.util.Tools.nullIsNotFound;
public class FlowsWebResource extends AbstractWebResource {
@Context
UriInfo uriInfo;
private UriInfo uriInfo;
public static final String DEVICE_NOT_FOUND = "Device is not found";
public static final String FLOW_NOT_FOUND = "Flow is not found";
public static final String FLOWS = "flows";
public static final String DEVICE_ID = "deviceId";
public static final String FLOW_ID = "flowId";
private static final String DEVICE_NOT_FOUND = "Device is not found";
private static final String FLOW_NOT_FOUND = "Flow is not found";
private static final String FLOWS = "flows";
private static final String DEVICE_ID = "deviceId";
private static final String FLOW_ID = "flowId";
final FlowRuleService service = get(FlowRuleService.class);
final ObjectNode root = mapper().createObjectNode();
final ArrayNode flowsNode = root.putArray(FLOWS);
private final FlowRuleService service = get(FlowRuleService.class);
private final ObjectNode root = mapper().createObjectNode();
private final ArrayNode flowsNode = root.putArray(FLOWS);
/**
* Get all flow entries. Returns array of all flow rules in the system.
* Gets all flow entries. Returns array of all flow rules in the system.
*
* @return 200 OK with a collection of flows
* @onos.rsModel Flows
* @return array of all the intents in the system
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
......@@ -91,17 +92,17 @@ public class FlowsWebResource extends AbstractWebResource {
}
/**
* Create new flow rules. Creates and installs a new flow rules.<br>
* Creates new flow rules. Creates and installs a new flow rules.<br>
* Instructions description:
* https://wiki.onosproject.org/display/ONOS/Flow+Rule+Instructions
* <br>
* Criteria description:
* https://wiki.onosproject.org/display/ONOS/Flow+Rule+Criteria
*
* @onos.rsModel FlowsBatchPost
* @param stream flow rules JSON
* @param stream flow rules JSON
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel FlowsBatchPost
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
......@@ -125,11 +126,12 @@ public class FlowsWebResource extends AbstractWebResource {
}
/**
* Get flow entries of a device. Returns array of all flow rules for the
* Gets flow entries of a device. Returns array of all flow rules for the
* specified device.
* @onos.rsModel Flows
*
* @param deviceId device identifier
* @return flow data as an array
* @return 200 OK with a collection of flows of given device
* @onos.rsModel Flows
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
......@@ -148,12 +150,13 @@ public class FlowsWebResource extends AbstractWebResource {
}
/**
* Get flow rule. Returns the flow entry specified by the device id and
* Gets flow rule. Returns the flow entry specified by the device id and
* flow rule id.
* @onos.rsModel Flows
*
* @param deviceId device identifier
* @param flowId flow rule identifier
* @return flow data as an array
* @return 200 OK with a flows of given device and flow
* @onos.rsModel Flows
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
......@@ -175,7 +178,7 @@ public class FlowsWebResource extends AbstractWebResource {
}
/**
* Create new flow rule. Creates and installs a new flow rule for the
* Creates new flow rule. Creates and installs a new flow rule for the
* specified device. <br>
* Instructions description:
* https://wiki.onosproject.org/display/ONOS/Flow+Rule+Instructions
......@@ -183,11 +186,11 @@ public class FlowsWebResource extends AbstractWebResource {
* Criteria description:
* https://wiki.onosproject.org/display/ONOS/Flow+Rule+Criteria
*
* @onos.rsModel FlowsPost
* @param deviceId device identifier
* @param stream flow rule JSON
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel FlowsPost
*/
@POST
@Path("{deviceId}")
......@@ -227,10 +230,9 @@ public class FlowsWebResource extends AbstractWebResource {
* @return 204 NO CONTENT
*/
@DELETE
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/{flowId}")
public Response deleteFlowByDeviceIdAndFlowId(@PathParam("deviceId") String deviceId,
@PathParam("flowId") long flowId) {
@PathParam("flowId") long flowId) {
final Iterable<FlowEntry> flowEntries =
service.getFlowEntries(DeviceId.deviceId(deviceId));
......@@ -248,10 +250,9 @@ public class FlowsWebResource extends AbstractWebResource {
* Removes a batch of flow rules.
*
* @param stream stream for posted JSON
* @return NO CONTENT
* @return 204 NO CONTENT
*/
@DELETE
@Produces(MediaType.APPLICATION_JSON)
public Response deleteFlows(InputStream stream) {
ListMultimap<DeviceId, Long> deviceMap = ArrayListMultimap.create();
List<FlowEntry> rulesToRemove = new ArrayList<>();
......@@ -265,9 +266,9 @@ public class FlowsWebResource extends AbstractWebResource {
DeviceId deviceId =
DeviceId.deviceId(
nullIsNotFound(node.get(DEVICE_ID),
DEVICE_NOT_FOUND).asText());
DEVICE_NOT_FOUND).asText());
long flowId = nullIsNotFound(node.get(FLOW_ID),
FLOW_NOT_FOUND).asLong();
FLOW_NOT_FOUND).asLong();
deviceMap.put(deviceId, flowId);
});
......@@ -288,5 +289,4 @@ public class FlowsWebResource extends AbstractWebResource {
service.removeFlowRules(rulesToRemove.toArray(new FlowEntry[0]));
return Response.noContent().build();
}
}
......
......@@ -54,19 +54,19 @@ import static org.onlab.util.Tools.nullIsNotFound;
public class GroupsWebResource extends AbstractWebResource {
@Context
UriInfo uriInfo;
private UriInfo uriInfo;
public static final String DEVICE_INVALID = "Invalid deviceId in group creation request";
public static final String GROUP_NOT_FOUND = "Group was not found";
private static final String DEVICE_INVALID = "Invalid deviceId in group creation request";
private static final String GROUP_NOT_FOUND = "Group was not found";
final GroupService groupService = get(GroupService.class);
final ObjectNode root = mapper().createObjectNode();
final ArrayNode groupsNode = root.putArray("groups");
private final GroupService groupService = get(GroupService.class);
private final ObjectNode root = mapper().createObjectNode();
private final ArrayNode groupsNode = root.putArray("groups");
/**
* Returns all groups of all devices.
*
* @return array of all the groups in the system
* @return 200 OK with array of all the groups in the system
* @onos.rsModel Groups
*/
@GET
......@@ -87,7 +87,7 @@ public class GroupsWebResource extends AbstractWebResource {
* Returns all groups associated with the given device.
*
* @param deviceId device identifier
* @return array of all the groups in the system
* @return 200 OK with array of all the groups in the system
* @onos.rsModel Groups
*/
@GET
......@@ -106,7 +106,7 @@ public class GroupsWebResource extends AbstractWebResource {
*
* @param deviceId device identifier
* @param appCookie group key
* @return a group entry in the system
* @return 200 OK with a group entry in the system
* @onos.rsModel Group
*/
@GET
......@@ -175,7 +175,6 @@ public class GroupsWebResource extends AbstractWebResource {
* @return 204 NO CONTENT
*/
@DELETE
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/{appCookie}")
public Response deleteGroupByDeviceIdAndAppCookie(@PathParam("deviceId") String deviceId,
@PathParam("appCookie") String appCookie) {
......
......@@ -64,15 +64,15 @@ import static org.onosproject.net.HostId.hostId;
public class HostsWebResource extends AbstractWebResource {
@Context
UriInfo uriInfo;
public static final String HOST_NOT_FOUND = "Host is not found";
private UriInfo uriInfo;
private static final String HOST_NOT_FOUND = "Host is not found";
private static final String[] REMOVAL_KEYS = {"mac", "vlan", "location", "ipAddresses"};
/**
* Get all end-station hosts.
* Returns array of all known end-station hosts.
*
* @return 200 OK
* @return 200 OK with array of all known end-station hosts.
* @onos.rsModel Hosts
*/
@GET
......@@ -88,7 +88,7 @@ public class HostsWebResource extends AbstractWebResource {
* Returns detailed properties of the specified end-station host.
*
* @param id host identifier
* @return 200 OK
* @return 200 OK with detailed properties of the specified end-station host
* @onos.rsModel Host
*/
@GET
......@@ -107,7 +107,7 @@ public class HostsWebResource extends AbstractWebResource {
*
* @param mac host MAC address
* @param vlan host VLAN identifier
* @return 200 OK
* @return 200 OK with detailed properties of the specified end-station host
* @onos.rsModel Host
*/
@GET
......@@ -160,11 +160,17 @@ public class HostsWebResource extends AbstractWebResource {
.build();
}
/**
* Internal host provider that provides host events.
*/
private final class InternalHostProvider implements HostProvider {
private final ProviderId providerId =
new ProviderId("host", "org.onosproject.rest", true);
private HostProviderService hostProviderService;
/**
* Prevents from instantiation.
*/
private InternalHostProvider() {
}
......
......@@ -58,18 +58,19 @@ import static org.slf4j.LoggerFactory.getLogger;
@Path("intents")
public class IntentsWebResource extends AbstractWebResource {
@Context
UriInfo uriInfo;
private UriInfo uriInfo;
private static final Logger log = getLogger(IntentsWebResource.class);
private static final int WITHDRAW_EVENT_TIMEOUT_SECONDS = 5;
public static final String INTENT_NOT_FOUND = "Intent is not found";
private static final String INTENT_NOT_FOUND = "Intent is not found";
/**
* Get all intents.
* Gets all intents.
* Returns array containing all the intents in the system.
*
* @return 200 OK with array of all the intents in the system
* @onos.rsModel Intents
* @return array of all the intents in the system
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
......@@ -80,12 +81,13 @@ public class IntentsWebResource extends AbstractWebResource {
}
/**
* Get intent by application and key.
* Gets intent by application and key.
* Returns details of the specified intent.
* @onos.rsModel Intents
*
* @param appId application identifier
* @param key intent key
* @return intent data
* @return 200 OK with intent data
* @onos.rsModel Intents
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
......@@ -112,10 +114,19 @@ public class IntentsWebResource extends AbstractWebResource {
return ok(root).build();
}
class DeleteListener implements IntentListener {
/**
* Internal listener for tracking the intent deletion events.
*/
private class DeleteListener implements IntentListener {
final Key key;
final CountDownLatch latch;
/**
* Default constructor.
*
* @param key key
* @param latch count down latch
*/
DeleteListener(Key key, CountDownLatch latch) {
this.key = key;
this.latch = latch;
......@@ -132,12 +143,13 @@ public class IntentsWebResource extends AbstractWebResource {
}
/**
* Submit a new intent.
* Submits a new intent.
* Creates and submits intent from the JSON request.
* @onos.rsModel IntentHost
*
* @param stream input JSON
* @return status of the request - CREATED if the JSON is correct,
* BAD_REQUEST if the JSON is invalid
* @onos.rsModel IntentHost
*/
@POST
@Consumes(MediaType.APPLICATION_JSON)
......@@ -161,7 +173,7 @@ public class IntentsWebResource extends AbstractWebResource {
}
/**
* Withdraw intent.
* Withdraws intent.
* Withdraws the specified intent from the system.
*
* @param appId application identifier
......@@ -171,7 +183,7 @@ public class IntentsWebResource extends AbstractWebResource {
@DELETE
@Path("{appId}/{key}")
public Response deleteIntentById(@PathParam("appId") String appId,
@PathParam("key") String key) {
@PathParam("key") String key) {
final ApplicationId app = get(CoreService.class).getAppId(appId);
Intent intent = get(IntentService.class).getIntent(Key.of(key, app));
......@@ -216,5 +228,4 @@ public class IntentsWebResource extends AbstractWebResource {
}
return Response.noContent().build();
}
}
......
......@@ -24,7 +24,9 @@ import org.onosproject.rest.AbstractWebResource;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import static org.onosproject.net.DeviceId.deviceId;
......@@ -37,15 +39,16 @@ import static org.onosproject.net.PortNumber.portNumber;
public class LinksWebResource extends AbstractWebResource {
/**
* Get infrastructure links.
* Gets infrastructure links.
* Returns array of all links, or links for the specified device or port.
* @onos.rsModel LinksGet
* @param deviceId (optional) device identifier
* @param port (optional) port number
* @param direction (optional) direction qualifier
* @return 200 OK
* @return 200 OK with array of all links, or links for the specified device or port
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
public Response getLinks(@QueryParam("device") String deviceId,
@QueryParam("port") String port,
@QueryParam("direction") String direction) {
......
......@@ -65,7 +65,7 @@ public final class MastershipWebResource extends AbstractWebResource {
* Returns the role of the local node for the specified device.
*
* @param deviceId device identifier
* @return role of the current node
* @return 200 OK with role of the current node
* @onos.rsModel MastershipRole
*/
@GET
......@@ -81,7 +81,7 @@ public final class MastershipWebResource extends AbstractWebResource {
* Returns the current master for a given device.
*
* @param deviceId device identifier
* @return the identifier of the master controller for the device
* @return 200 OK with the identifier of the master controller for the device
* @onos.rsModel NodeId
*/
@GET
......@@ -101,7 +101,7 @@ public final class MastershipWebResource extends AbstractWebResource {
* preference. The first entry in the list is the current master.
*
* @param deviceId device identifier
* @return a list of controller identifiers
* @return 200 OK with a list of controller identifiers
* @onos.rsModel RoleInfo
*/
@GET
......@@ -118,7 +118,7 @@ public final class MastershipWebResource extends AbstractWebResource {
* Returns the devices for which a controller is master.
*
* @param nodeId controller identifier
* @return a set of device identifiers
* @return 200 OK with a set of device identifiers
* @onos.rsModel DeviceIds
*/
@GET
......@@ -141,7 +141,7 @@ public final class MastershipWebResource extends AbstractWebResource {
* device forcing master selection if necessary.
*
* @param deviceId device identifier
* @return the role of this controller instance
* @return 200 OK with the role of this controller instance
* @onos.rsModel MastershipRole
*/
@GET
......@@ -160,7 +160,7 @@ public final class MastershipWebResource extends AbstractWebResource {
* for this device, no master selection will occur.
*
* @param deviceId device identifier
* @return status of the request
* @return status of the request - CREATED if the JSON is correct
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
......@@ -181,7 +181,6 @@ public final class MastershipWebResource extends AbstractWebResource {
*/
@PUT
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response setRole(InputStream stream) {
try {
......
......@@ -52,20 +52,20 @@ import static org.slf4j.LoggerFactory.getLogger;
public class MetersWebResource extends AbstractWebResource {
@Context
UriInfo uriInfo;
private UriInfo uriInfo;
private final Logger log = getLogger(getClass());
public static final String DEVICE_INVALID = "Invalid deviceId in meter creation request";
public static final String METER_NOT_FOUND = "Meter is not found for ";
private static final String DEVICE_INVALID = "Invalid deviceId in meter creation request";
private static final String METER_NOT_FOUND = "Meter is not found for ";
final MeterService meterService = get(MeterService.class);
final ObjectNode root = mapper().createObjectNode();
final ArrayNode metersNode = root.putArray("meters");
private final MeterService meterService = get(MeterService.class);
private final ObjectNode root = mapper().createObjectNode();
private final ArrayNode metersNode = root.putArray("meters");
/**
* Returns all meters of all devices.
*
* @return array of all the meters in the system
* @return 200 OK with array of all the meters in the system
* @onos.rsModel Meters
*/
@GET
......@@ -82,7 +82,7 @@ public class MetersWebResource extends AbstractWebResource {
* Returns a collection of meters by the device id.
*
* @param deviceId device identifier
* @return array of meters which belongs to specified device
* @return 200 OK with array of meters which belongs to specified device
* @onos.rsModel Meters
*/
@GET
......@@ -102,7 +102,7 @@ public class MetersWebResource extends AbstractWebResource {
*
* @param deviceId device identifier
* @param meterId meter identifier
* @return a meter, return 404 if no entry has been found
* @return 200 OK with a meter, return 404 if no entry has been found
* @onos.rsModel Meter
*/
@GET
......@@ -121,7 +121,7 @@ public class MetersWebResource extends AbstractWebResource {
}
/**
* Create new meter rule. Creates and installs a new meter rule for the
* Creates new meter rule. Creates and installs a new meter rule for the
* specified device.
*
* @param deviceId device identifier
......@@ -182,7 +182,7 @@ public class MetersWebResource extends AbstractWebResource {
}
/**
* Convert a meter instance to meterRequest instance with a certain operation.
* Converts a meter instance to meterRequest instance with a certain operation.
*
* @param meter meter instance
* @param operation operation
......
......@@ -44,14 +44,14 @@ import java.util.Map;
@Path("metrics")
public class MetricsWebResource extends AbstractWebResource {
final MetricsService service = get(MetricsService.class);
final ObjectNode root = mapper().createObjectNode();
private final MetricsService service = get(MetricsService.class);
private final ObjectNode root = mapper().createObjectNode();
/**
* Get stats information of all metrics. Returns array of all information for
* Gets stats information of all metrics. Returns array of all information for
* all metrics.
*
* @return metric information as array
* @return 200 OK with metric information as array
* @onos.rsModel Metrics
*/
@GET
......@@ -69,11 +69,11 @@ public class MetricsWebResource extends AbstractWebResource {
}
/**
* Get stats information of a metric. Returns array of all information for the
* Gets stats information of a metric. Returns array of all information for the
* specified metric.
*
* @param metricName metric name
* @return metric information as array
* @return 200 OK with metric information as array
* @onos.rsModel Metric
*/
@GET
......
......@@ -44,7 +44,7 @@ public class MulticastRouteWebResource extends AbstractWebResource {
* Get all multicast routes.
* Returns array of all known multicast routes.
*
* @return 200 OK
* @return 200 OK with array of all known multicast routes
* @onos.rsModel McastRoutesGet
*/
@GET
......
......@@ -64,9 +64,9 @@ public class NetworkConfigWebResource extends AbstractWebResource {
}
/**
* Get entire network configuration base.
* Gets entire network configuration base.
*
* @return network configuration JSON
* @return 200 OK with network configuration JSON
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
......@@ -83,10 +83,10 @@ public class NetworkConfigWebResource extends AbstractWebResource {
}
/**
* Get all network configuration for a subject class.
* Gets all network configuration for a subject class.
*
* @param subjectClassKey subject class key
* @return network configuration JSON
* @return 200 OK with network configuration JSON
*/
@GET
@Path("{subjectClassKey}")
......@@ -103,11 +103,11 @@ public class NetworkConfigWebResource extends AbstractWebResource {
}
/**
* Get all network configuration for a subjectKey.
* Gets all network configuration for a subjectKey.
*
* @param subjectClassKey subjectKey class key
* @param subjectKey subjectKey key
* @return network configuration JSON
* @return 200 OK with network configuration JSON
*/
@GET
@Path("{subjectClassKey}/{subjectKey}")
......@@ -127,12 +127,12 @@ public class NetworkConfigWebResource extends AbstractWebResource {
}
/**
* Get specific network configuration for a subjectKey.
* Gets specific network configuration for a subjectKey.
*
* @param subjectClassKey subjectKey class key
* @param subjectKey subjectKey key
* @param configKey configuration class key
* @return network configuration JSON
* @return 200 OK with network configuration JSON
*/
@GET
@Path("{subjectClassKey}/{subjectKey}/{configKey}")
......@@ -180,10 +180,10 @@ public class NetworkConfigWebResource extends AbstractWebResource {
/**
* Upload bulk network configuration.
* Uploads bulk network configuration.
*
* @param request network configuration JSON rooted at the top node
* @return empty response
* @return 200 OK
* @throws IOException if unable to parse the request
*/
@POST
......@@ -203,7 +203,7 @@ public class NetworkConfigWebResource extends AbstractWebResource {
*
* @param subjectClassKey subject class key
* @param request network configuration JSON rooted at the top node
* @return empty response
* @return 200 OK
* @throws IOException if unable to parse the request
*/
@POST
......@@ -224,7 +224,7 @@ public class NetworkConfigWebResource extends AbstractWebResource {
* @param subjectClassKey subjectKey class key
* @param subjectKey subjectKey key
* @param request network configuration JSON rooted at the top node
* @return empty response
* @return 200 OK
* @throws IOException if unable to parse the request
*/
@POST
......@@ -249,7 +249,7 @@ public class NetworkConfigWebResource extends AbstractWebResource {
* @param subjectKey subjectKey key
* @param configKey configuration class key
* @param request network configuration JSON rooted at the top node
* @return empty response
* @return 200 OK
* @throws IOException if unable to parse the request
*/
@POST
......
......@@ -58,12 +58,12 @@ public class PathsWebResource extends AbstractWebResource {
}
/**
* Get all shortest paths between any two hosts or devices.
* Gets all shortest paths between any two hosts or devices.
* Returns array of all shortest paths between any two elements.
* @onos.rsModel Paths
* @param src source identifier
* @param dst destination identifier
* @return path data
* @return 200 OK with array of all shortest paths between any two elements
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
......@@ -77,12 +77,12 @@ public class PathsWebResource extends AbstractWebResource {
}
/**
* Get all shortest disjoint paths between any two hosts or devices.
* Gets all shortest disjoint paths between any two hosts or devices.
* Returns array of all shortest disjoint paths between any two elements.
* @onos.rsModel Paths
* @param src source identifier
* @param dst destination identifier
* @return path data
* @return 200 OK with array of all shortest disjoint paths between any two elements
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
......
......@@ -59,7 +59,7 @@ public class RegionsWebResource extends AbstractWebResource {
/**
* Returns set of all regions.
*
* @return 200 OK
* @return 200 OK with set of all regions
* @onos.rsModel Regions
*/
@GET
......@@ -73,7 +73,7 @@ public class RegionsWebResource extends AbstractWebResource {
* Returns the region with the specified identifier.
*
* @param regionId region identifier
* @return 200 OK, 404 not found
* @return 200 OK with a region, 404 not found
* @onos.rsModel Region
*/
@GET
......@@ -90,7 +90,7 @@ public class RegionsWebResource extends AbstractWebResource {
* Returns the set of devices that belong to the specified region.
*
* @param regionId region identifier
* @return 200 OK
* @return 200 OK with set of devices that belong to the specified region
* @onos.rsModel RegionDeviceIds
*/
@GET
......@@ -143,7 +143,6 @@ public class RegionsWebResource extends AbstractWebResource {
@PUT
@Path("{regionId}")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response updateRegion(@PathParam("regionId") String regionId,
InputStream stream) {
try {
......@@ -169,7 +168,7 @@ public class RegionsWebResource extends AbstractWebResource {
* Removes the specified region using the given region identifier.
*
* @param regionId region identifier
* @return 200 OK, 404 not found
* @return 204 NO CONTENT
*/
@DELETE
@Path("{regionId}")
......
......@@ -56,14 +56,15 @@ import static org.onosproject.net.PortNumber.portNumber;
@Path("statistics")
public class StatisticsWebResource extends AbstractWebResource {
@Context
UriInfo uriInfo;
private UriInfo uriInfo;
/**
* Get load statistics for all links or for a specific link.
* Gets load statistics for all links or for a specific link.
*
* @onos.rsModel StatisticsFlowsLink
* @param deviceId (optional) device ID for a specific link
* @param port (optional) port number for a specified link
* @return JSON encoded array lof Load objects
* @return 200 OK with JSON encoded array of Load objects
*/
@GET
@Path("flows/link")
......@@ -101,9 +102,10 @@ public class StatisticsWebResource extends AbstractWebResource {
}
/**
* Get table statistics for all tables of all devices.
* Gets table statistics for all tables of all devices.
*
* @onos.rsModel StatisticsFlowsTables
* @return JSON encoded array of table statistics
* @return 200 OK with JSON encoded array of table statistics
*/
@GET
@Path("flows/tables")
......@@ -130,10 +132,11 @@ public class StatisticsWebResource extends AbstractWebResource {
}
/**
* Get table statistics for all tables of a specified device.
* Gets table statistics for all tables of a specified device.
*
* @onos.rsModel StatisticsFlowsTables
* @param deviceId device ID
* @return JSON encoded array of table statistics
* @return 200 OK with JSON encoded array of table statistics
*/
@GET
@Path("flows/tables/{deviceId}")
......@@ -156,9 +159,9 @@ public class StatisticsWebResource extends AbstractWebResource {
}
/**
* Get port statistics of all devices.
* Gets port statistics of all devices.
* @onos.rsModel StatisticsPorts
* @return JSON encoded array of port statistics
* @return 200 OK with JSON encoded array of port statistics
*/
@GET
@Path("ports")
......@@ -185,10 +188,10 @@ public class StatisticsWebResource extends AbstractWebResource {
}
/**
* Get port statistics of a specified devices.
* Gets port statistics of a specified devices.
* @onos.rsModel StatisticsPorts
* @param deviceId device ID
* @return JSON encoded array of port statistics
* @return 200 OK with JSON encoded array of port statistics
*/
@GET
@Path("ports/{deviceId}")
......
......@@ -49,14 +49,14 @@ public class TenantWebResource extends AbstractWebResource {
private static final String INVALID_TENANTID = "Invalid tenant identifier ";
@Context
UriInfo uriInfo;
private UriInfo uriInfo;
private final VirtualNetworkAdminService vnetAdminService = get(VirtualNetworkAdminService.class);
/**
* Returns all tenants.
* Returns all tenant identifiers.
*
* @return 200 OK
* @return 200 OK with set of tenant identifiers
* @onos.rsModel TenantIds
*/
@GET
......@@ -109,7 +109,7 @@ public class TenantWebResource extends AbstractWebResource {
}
/**
* Get the tenant identifier from the JSON stream.
* Gets the tenant identifier from the JSON stream.
*
* @param stream TenantId JSON stream
* @return TenantId
......@@ -129,17 +129,16 @@ public class TenantWebResource extends AbstractWebResource {
* Get the matching tenant identifier from existing tenant identifiers in system.
*
* @param vnetAdminSvc virtual network administration service
* @param tidIn tenant identifier
* @param tidIn tenant identifier
* @return TenantId
*/
static TenantId getExistingTenantId(VirtualNetworkAdminService vnetAdminSvc,
TenantId tidIn) {
final TenantId resultTid = vnetAdminSvc
protected static TenantId getExistingTenantId(VirtualNetworkAdminService vnetAdminSvc,
TenantId tidIn) {
return vnetAdminSvc
.getTenantIds()
.stream()
.filter(tenantId -> tenantId.equals(tidIn))
.findFirst()
.orElseThrow(() -> new ItemNotFoundException(TENANTID_NOT_FOUND));
return resultTid;
}
}
......
......@@ -44,12 +44,12 @@ import static org.onlab.util.Tools.nullIsNotFound;
@Path("topology")
public class TopologyWebResource extends AbstractWebResource {
public static final String CLUSTER_NOT_FOUND = "Cluster is not found";
private static final String CLUSTER_NOT_FOUND = "Cluster is not found";
/**
* Get overview of current topology.
* Gets overview of current topology.
*
* @return topology overview
* @return 200 OK with topology overview
* @onos.rsModel Topology
*/
@GET
......@@ -61,9 +61,9 @@ public class TopologyWebResource extends AbstractWebResource {
}
/**
* Get overview of topology SCCs.
* Gets overview of topology SCCs.
*
* @return topology clusters overview
* @return 200 OK with topology clusters overview
* @onos.rsModel TopologyClusters
*/
@GET
......@@ -78,10 +78,10 @@ public class TopologyWebResource extends AbstractWebResource {
}
/**
* Get details of a specific SCC.
* Gets details of a specific SCC.
*
* @param clusterId id of the cluster to query
* @return topology cluster details
* @return 200 OK with topology cluster details
* @onos.rsModel TopologyCluster
*/
@GET
......@@ -102,10 +102,10 @@ public class TopologyWebResource extends AbstractWebResource {
}
/**
* Get devices in a specific SCC.
* Gets devices in a specific SCC.
*
* @param clusterId id of the cluster to query
* @return topology cluster devices
* @return 200 OK with topology cluster devices
* @onos.rsModel TopologyClustersDevices
*/
@GET
......@@ -126,10 +126,10 @@ public class TopologyWebResource extends AbstractWebResource {
}
/**
* Get links in specific SCC.
* Gets links in specific SCC.
*
* @param clusterId id of the cluster to query
* @return topology cluster links
* @return 200 OK with topology cluster links
* @onos.rsModel LinksGet
*/
@GET
......@@ -175,11 +175,11 @@ public class TopologyWebResource extends AbstractWebResource {
}
/**
* Test if a connect point is in broadcast set.
* Tests if a connect point is in broadcast set.
*
* @param connectPointString deviceid:portnumber
* @return JSON representation of true if the connect point is broadcast,
* false otherwise
* @return 200 OK with JSON representation of true if the connect point is
* broadcast, false otherwise
* @onos.rsModel TopologyBroadcast
*/
@GET
......@@ -193,17 +193,16 @@ public class TopologyWebResource extends AbstractWebResource {
ConnectPoint connectPoint = new ConnectPoint(deviceId, portNumber);
boolean isBroadcast = get(TopologyService.class).isBroadcastPoint(topology, connectPoint);
return ok(mapper()
.createObjectNode()
return ok(mapper().createObjectNode()
.put("broadcast", isBroadcast))
.build();
}
/**
* Test if a connect point is infrastructure or edge.
* Tests if a connect point is infrastructure or edge.
*
* @param connectPointString deviceid:portnumber
* @return JSON representation of true if the connect point is broadcast,
* @return 200 OK with JSON representation of true if the connect point is broadcast,
* false otherwise
* @onos.rsModel TopologyInfrastructure
*/
......@@ -218,10 +217,8 @@ public class TopologyWebResource extends AbstractWebResource {
ConnectPoint connectPoint = new ConnectPoint(deviceId, portNumber);
boolean isInfrastructure = get(TopologyService.class).isInfrastructure(topology, connectPoint);
return ok(mapper()
.createObjectNode()
return ok(mapper().createObjectNode()
.put("infrastructure", isInfrastructure))
.build();
}
}
......
......@@ -67,14 +67,14 @@ public class VirtualNetworkWebResource extends AbstractWebResource {
private final VirtualNetworkService vnetService = get(VirtualNetworkService.class);
@Context
UriInfo uriInfo;
private UriInfo uriInfo;
// VirtualNetwork
/**
* Returns all virtual networks.
*
* @return 200 OK
* @return 200 OK with set of virtual networks
* @onos.rsModel VirtualNetworks
*/
@GET
......@@ -92,7 +92,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource {
* Returns the virtual networks with the specified tenant identifier.
*
* @param tenantId tenant identifier
* @return 200 OK, 404 not found
* @return 200 OK with a virtual network, 404 not found
* @onos.rsModel VirtualNetworks
*/
@GET
......@@ -151,7 +151,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource {
* Returns all virtual network devices in a virtual network.
*
* @param networkId network identifier
* @return 200 OK
* @return 200 OK with set of virtual devices, 404 not found
* @onos.rsModel VirtualDevices
*/
@GET
......@@ -222,7 +222,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource {
*
* @param networkId network identifier
* @param deviceId virtual device identifier
* @return 200 OK
* @return 200 OK with set of virtual ports, 404 not found
* @onos.rsModel VirtualPorts
*/
@GET
......@@ -312,7 +312,7 @@ public class VirtualNetworkWebResource extends AbstractWebResource {
* Returns all virtual network links in a virtual network.
*
* @param networkId network identifier
* @return 200 OK
* @return 200 OK with set of virtual network links
* @onos.rsModel VirtualLinks
*/
@GET
......