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
2014-10-28 13:09:42 -0700
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
444eda606664cb14ca19447d5245c2466802578b
444eda60
1 parent
9be539e0
Added JSON for role command.
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
45 additions
and
25 deletions
cli/src/main/java/org/onlab/onos/cli/RolesCommand.java
cli/src/main/java/org/onlab/onos/cli/net/DevicesListCommand.java
cli/src/main/javadoc/doc-files/intent-states.png
core/store/dist/src/main/java/org/onlab/onos/store/device/impl/GossipDeviceStore.java
cli/src/main/java/org/onlab/onos/cli/RolesCommand.java
View file @
444eda6
...
...
@@ -18,11 +18,10 @@
*/
package
org
.
onlab
.
onos
.
cli
;
import
static
com
.
google
.
common
.
collect
.
Lists
.
newArrayList
;
import
java.util.Collections
;
import
java.util.List
;
import
com.fasterxml.jackson.databind.JsonNode
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.node.ArrayNode
;
import
com.fasterxml.jackson.databind.node.ObjectNode
;
import
org.apache.karaf.shell.commands.Command
;
import
org.onlab.onos.cluster.NodeId
;
import
org.onlab.onos.cluster.RoleInfo
;
...
...
@@ -31,12 +30,15 @@ import org.onlab.onos.net.Device;
import
org.onlab.onos.net.DeviceId
;
import
org.onlab.onos.net.device.DeviceService
;
import
java.util.List
;
import
static
org
.
onlab
.
onos
.
cli
.
net
.
DevicesListCommand
.
getSortedDevices
;
/**
* Lists mastership roles of nodes for each device.
*/
@Command
(
scope
=
"onos"
,
name
=
"roles"
,
description
=
"Lists mastership roles of nodes for each device."
)
description
=
"Lists mastership roles of nodes for each device."
)
public
class
RolesCommand
extends
AbstractShellCommand
{
private
static
final
String
FMT_HDR
=
"%s: master=%s, standbys=[ %s]"
;
...
...
@@ -46,29 +48,47 @@ public class RolesCommand extends AbstractShellCommand {
DeviceService
deviceService
=
get
(
DeviceService
.
class
);
MastershipService
roleService
=
get
(
MastershipService
.
class
);
for
(
Device
d
:
getSortedDevices
(
deviceService
))
{
DeviceId
did
=
d
.
id
();
printRoles
(
roleService
,
did
);
if
(
outputJson
())
{
print
(
"%s"
,
json
(
roleService
,
getSortedDevices
(
deviceService
)));
}
else
{
for
(
Device
d
:
getSortedDevices
(
deviceService
))
{
DeviceId
did
=
d
.
id
();
printRoles
(
roleService
,
did
);
}
}
}
/**
* Returns the list of devices sorted using the device ID URIs.
*
* @param service device service
* @return sorted device list
*/
protected
static
List
<
Device
>
getSortedDevices
(
DeviceService
service
)
{
List
<
Device
>
devices
=
newArrayList
(
service
.
getDevices
());
Collections
.
sort
(
devices
,
Comparators
.
ELEMENT_COMPARATOR
);
return
devices
;
// Produces JSON structure with role information for the given devices.
private
JsonNode
json
(
MastershipService
service
,
List
<
Device
>
sortedDevices
)
{
ObjectMapper
mapper
=
new
ObjectMapper
();
ArrayNode
results
=
mapper
.
createArrayNode
();
for
(
Device
device
:
sortedDevices
)
{
results
.
add
(
json
(
service
,
mapper
,
device
));
}
return
results
;
}
// Produces JSON structure with role information for the given device.
private
JsonNode
json
(
MastershipService
service
,
ObjectMapper
mapper
,
Device
device
)
{
NodeId
master
=
service
.
getMasterFor
(
device
.
id
());
ObjectNode
result
=
mapper
.
createObjectNode
()
.
put
(
"id"
,
device
.
id
().
toString
())
.
put
(
"master"
,
master
!=
null
?
master
.
toString
()
:
"none"
);
RoleInfo
nodes
=
service
.
getNodesFor
(
device
.
id
());
ArrayNode
standbys
=
mapper
.
createArrayNode
();
for
(
NodeId
nid
:
nodes
.
backups
())
{
standbys
.
add
(
nid
.
toString
());
}
result
.
set
(
"standbys"
,
standbys
);
return
result
;
}
/**
* Prints the role information for a device.
*
* @param service mastership service
* @param deviceId the ID of the device
* @param master the current master
*/
protected
void
printRoles
(
MastershipService
service
,
DeviceId
deviceId
)
{
RoleInfo
nodes
=
service
.
getNodesFor
(
deviceId
);
...
...
@@ -78,7 +98,7 @@ public class RolesCommand extends AbstractShellCommand {
}
print
(
FMT_HDR
,
deviceId
,
nodes
.
master
()
==
null
?
"NONE"
:
nodes
.
master
(),
builder
.
toString
());
nodes
.
master
()
==
null
?
"NONE"
:
nodes
.
master
(),
builder
.
toString
());
}
}
...
...
cli/src/main/java/org/onlab/onos/cli/net/DevicesListCommand.java
View file @
444eda6
...
...
@@ -101,7 +101,7 @@ public class DevicesListCommand extends AbstractShellCommand {
* @param service device service
* @return sorted device list
*/
p
rotected
static
List
<
Device
>
getSortedDevices
(
DeviceService
service
)
{
p
ublic
static
List
<
Device
>
getSortedDevices
(
DeviceService
service
)
{
List
<
Device
>
devices
=
newArrayList
(
service
.
getDevices
());
Collections
.
sort
(
devices
,
Comparators
.
ELEMENT_COMPARATOR
);
return
devices
;
...
...
cli/src/main/javadoc/doc-files/intent-states.png
deleted
100644 → 0
View file @
9be539e
158 KB
core/store/dist/src/main/java/org/onlab/onos/store/device/impl/GossipDeviceStore.java
View file @
444eda6
...
...
@@ -701,7 +701,7 @@ public class GossipDeviceStore
public
synchronized
DeviceEvent
removeDevice
(
DeviceId
deviceId
)
{
final
NodeId
master
=
mastershipService
.
getMasterFor
(
deviceId
);
if
(!
clusterService
.
getLocalNode
().
id
().
equals
(
master
))
{
log
.
info
(
"
remove D
evice {} requested on non master node"
,
deviceId
);
log
.
info
(
"
Removal of d
evice {} requested on non master node"
,
deviceId
);
// FIXME silently ignoring. Should be forwarding or broadcasting to
// master.
return
null
;
...
...
@@ -778,7 +778,7 @@ public class GossipDeviceStore
private
Device
composeDevice
(
DeviceId
deviceId
,
Map
<
ProviderId
,
DeviceDescriptions
>
providerDescs
)
{
checkArgument
(!
providerDescs
.
isEmpty
(),
"No
D
evice descriptions supplied"
);
checkArgument
(!
providerDescs
.
isEmpty
(),
"No
d
evice descriptions supplied"
);
ProviderId
primary
=
pickPrimaryPID
(
providerDescs
);
...
...
Please
register
or
login
to post a comment