Toggle navigation
Toggle navigation
This project
Loading...
Sign in
홍길동
/
onos
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Thomas Vachuska
2015-04-08 19:40:12 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
f8cac48255e195917784ce15798858e29c6c5707
f8cac482
1 parent
ca88bb74
Mild REST API refactoring.
Change-Id: Ieddbbd02328043118ad64077f8eda746eb2b3a9f
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
40 additions
and
63 deletions
web/api/src/main/java/org/onosproject/rest/AbstractWebResource.java
web/api/src/main/java/org/onosproject/rest/ClusterWebResource.java
web/api/src/main/java/org/onosproject/rest/ComponentConfigWebResource.java
web/api/src/main/java/org/onosproject/rest/DevicesWebResource.java
web/api/src/main/java/org/onosproject/rest/HostsWebResource.java
web/api/src/main/java/org/onosproject/rest/IntentsWebResource.java
web/api/src/main/java/org/onosproject/rest/TopologyWebResource.java
web/api/src/main/java/org/onosproject/rest/AbstractWebResource.java
View file @
f8cac48
...
...
@@ -17,11 +17,10 @@ package org.onosproject.rest;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
org.onlab.
util.ItemNotFoundException
;
import
org.onlab.
rest.BaseResource
;
import
org.onosproject.codec.CodecContext
;
import
org.onosproject.codec.CodecService
;
import
org.onosproject.codec.JsonCodec
;
import
org.onlab.rest.BaseResource
;
/**
* Abstract REST resource.
...
...
@@ -61,21 +60,4 @@ public class AbstractWebResource extends BaseResource implements CodecContext {
return
result
;
}
/**
* Returns the specified item if that items is null; otherwise throws
* not found exception.
*
* @param item item to check
* @param message not found message
* @param <T> item type
* @return item if not null
* @throws org.onlab.util.ItemNotFoundException if item is null
*/
protected
<
T
>
T
nullIsNotFound
(
T
item
,
String
message
)
{
if
(
item
==
null
)
{
throw
new
ItemNotFoundException
(
message
);
}
return
item
;
}
}
...
...
web/api/src/main/java/org/onosproject/rest/ClusterWebResource.java
View file @
f8cac48
...
...
@@ -33,6 +33,8 @@ import java.io.InputStream;
import
java.util.HashSet
;
import
java.util.List
;
import
static
org
.
onlab
.
util
.
Tools
.
nullIsNotFound
;
/**
* REST resource for interacting with the ONOS cluster subsystem.
*/
...
...
web/api/src/main/java/org/onosproject/rest/ComponentConfigWebResource.java
View file @
f8cac48
...
...
@@ -29,6 +29,8 @@ import java.io.IOException;
import
java.io.InputStream
;
import
java.util.Set
;
import
static
org
.
onlab
.
util
.
Tools
.
nullIsNotFound
;
/**
* REST resource for cluster-wide component configuration.
*/
...
...
web/api/src/main/java/org/onosproject/rest/DevicesWebResource.java
View file @
f8cac48
...
...
@@ -27,6 +27,7 @@ import javax.ws.rs.core.Response;
import
java.util.List
;
import
static
com
.
google
.
common
.
base
.
Preconditions
.
checkNotNull
;
import
static
org
.
onlab
.
util
.
Tools
.
nullIsNotFound
;
import
static
org
.
onosproject
.
net
.
DeviceId
.
deviceId
;
/**
...
...
web/api/src/main/java/org/onosproject/rest/HostsWebResource.java
View file @
f8cac48
...
...
@@ -27,6 +27,7 @@ import org.onosproject.net.host.HostService;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
static
org
.
onlab
.
util
.
Tools
.
nullIsNotFound
;
import
static
org
.
onosproject
.
net
.
HostId
.
hostId
;
/**
...
...
web/api/src/main/java/org/onosproject/rest/IntentsWebResource.java
View file @
f8cac48
...
...
@@ -41,6 +41,7 @@ import org.slf4j.Logger;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
static
org
.
onlab
.
util
.
Tools
.
nullIsNotFound
;
import
static
org
.
onosproject
.
net
.
intent
.
IntentState
.
FAILED
;
import
static
org
.
onosproject
.
net
.
intent
.
IntentState
.
WITHDRAWN
;
import
static
org
.
slf4j
.
LoggerFactory
.
getLogger
;
...
...
web/api/src/main/java/org/onosproject/rest/TopologyWebResource.java
View file @
f8cac48
...
...
@@ -15,15 +15,9 @@
*/
package
org
.
onosproject
.
rest
;
import
java.util.List
;
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
com.fasterxml.jackson.databind.node.ArrayNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
com.google.common.collect.Lists
;
import
org.onosproject.net.ConnectPoint
;
import
org.onosproject.net.DeviceId
;
import
org.onosproject.net.Link
;
...
...
@@ -33,9 +27,15 @@ import org.onosproject.net.topology.Topology;
import
org.onosproject.net.topology.TopologyCluster
;
import
org.onosproject.net.topology.TopologyService
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
com.google.common.collect.Lists
;
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
;
import
static
org
.
onlab
.
util
.
Tools
.
nullIsNotFound
;
/**
* REST resource for interacting with the inventory of clusters.
...
...
@@ -55,8 +55,7 @@ public class TopologyWebResource extends AbstractWebResource {
@Produces
(
MediaType
.
APPLICATION_JSON
)
public
Response
getTopology
()
{
Topology
topology
=
get
(
TopologyService
.
class
).
currentTopology
();
ObjectNode
root
=
codec
(
Topology
.
class
).
encode
(
topology
,
this
);
ObjectNode
root
=
codec
(
Topology
.
class
).
encode
(
topology
,
this
);
return
ok
(
root
).
build
();
}
...
...
@@ -69,11 +68,10 @@ public class TopologyWebResource extends AbstractWebResource {
@Produces
(
MediaType
.
APPLICATION_JSON
)
@Path
(
"clusters"
)
public
Response
getClusters
()
{
Topology
topology
=
get
(
TopologyService
.
class
).
currentTopology
();
Iterable
<
TopologyCluster
>
clusters
=
get
(
TopologyService
.
class
).
getClusters
(
topology
);
ObjectNode
root
=
encodeArray
(
TopologyCluster
.
class
,
"clusters"
,
clusters
);
TopologyService
service
=
get
(
TopologyService
.
class
);
Topology
topology
=
service
.
currentTopology
();
Iterable
<
TopologyCluster
>
clusters
=
service
.
getClusters
(
topology
);
ObjectNode
root
=
encodeArray
(
TopologyCluster
.
class
,
"clusters"
,
clusters
);
return
ok
(
root
).
build
();
}
...
...
@@ -88,17 +86,18 @@ public class TopologyWebResource extends AbstractWebResource {
@Path
(
"clusters/{id}"
)
public
Response
getCluster
(
@PathParam
(
"id"
)
int
clusterId
)
{
Topology
topology
=
get
(
TopologyService
.
class
).
currentTopology
();
TopologyCluster
cluster
=
nullIsNotFound
(
get
(
TopologyService
.
class
)
.
getCluster
(
topology
,
ClusterId
.
clusterId
(
clusterId
)),
CLUSTER_NOT_FOUND
);
ObjectNode
root
=
codec
(
TopologyCluster
.
class
).
encode
(
cluster
,
this
);
TopologyCluster
cluster
=
getTopologyCluster
(
clusterId
,
topology
);
ObjectNode
root
=
codec
(
TopologyCluster
.
class
).
encode
(
cluster
,
this
);
return
ok
(
root
).
build
();
}
private
TopologyCluster
getTopologyCluster
(
int
clusterId
,
Topology
topology
)
{
return
nullIsNotFound
(
get
(
TopologyService
.
class
)
.
getCluster
(
topology
,
ClusterId
.
clusterId
(
clusterId
)),
CLUSTER_NOT_FOUND
);
}
/**
* Gets devices for a topology cluster for a REST GET operation.
*
...
...
@@ -109,24 +108,16 @@ public class TopologyWebResource extends AbstractWebResource {
@Produces
(
MediaType
.
APPLICATION_JSON
)
@Path
(
"clusters/{id}/devices"
)
public
Response
getClusterDevices
(
@PathParam
(
"id"
)
int
clusterId
)
{
Topology
topology
=
get
(
TopologyService
.
class
).
currentTopology
();
TopologyCluster
cluster
=
nullIsNotFound
(
get
(
TopologyService
.
class
)
.
getCluster
(
topology
,
ClusterId
.
clusterId
(
clusterId
)),
CLUSTER_NOT_FOUND
);
TopologyService
service
=
get
(
TopologyService
.
class
);
Topology
topology
=
service
.
currentTopology
();
TopologyCluster
cluster
=
getTopologyCluster
(
clusterId
,
topology
);
List
<
DeviceId
>
deviceIds
=
Lists
.
newArrayList
(
get
(
TopologyService
.
class
)
.
getClusterDevices
(
topology
,
cluster
));
Lists
.
newArrayList
(
service
.
getClusterDevices
(
topology
,
cluster
));
ObjectNode
root
=
mapper
().
createObjectNode
();
ArrayNode
devicesNode
=
root
.
putArray
(
"devices"
);
for
(
DeviceId
deviceId
:
deviceIds
)
{
devicesNode
.
add
(
deviceId
.
toString
());
}
deviceIds
.
forEach
(
id
->
devicesNode
.
add
(
id
.
toString
()));
return
ok
(
root
).
build
();
}
...
...
@@ -141,10 +132,7 @@ public class TopologyWebResource extends AbstractWebResource {
@Path
(
"clusters/{id}/links"
)
public
Response
getClusterLinks
(
@PathParam
(
"id"
)
int
clusterId
)
{
Topology
topology
=
get
(
TopologyService
.
class
).
currentTopology
();
TopologyCluster
cluster
=
nullIsNotFound
(
get
(
TopologyService
.
class
).
getCluster
(
topology
,
ClusterId
.
clusterId
(
clusterId
)),
CLUSTER_NOT_FOUND
);
TopologyCluster
cluster
=
getTopologyCluster
(
clusterId
,
topology
);
List
<
Link
>
links
=
Lists
.
newArrayList
(
get
(
TopologyService
.
class
)
...
...
Please
register
or
login
to post a comment