use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.
the class MastershipWebResource method getNodesFor.
/**
* Returns controllers connected to a given device, in order of
* preference. The first entry in the list is the current master.
*
* @param deviceId device identifier
* @return 200 OK with a list of controller identifiers
* @onos.rsModel RoleInfo
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/role")
public Response getNodesFor(@PathParam("deviceId") String deviceId) {
MastershipService mastershipService = get(MastershipService.class);
RoleInfo info = nullIsNotFound(mastershipService.getNodesFor(DeviceId.deviceId(deviceId)), ROLE_INFO_NOT_FOUND);
ObjectNode root = codec(RoleInfo.class).encode(info, this);
return ok(root).build();
}
use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.
the class MastershipWebResource method getDeviceOf.
/**
* Returns the devices for which a controller is master.
*
* @param nodeId controller identifier
* @return 200 OK with a set of device identifiers
* @onos.rsModel DeviceIds
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{nodeId}/device")
public Response getDeviceOf(@PathParam("nodeId") String nodeId) {
MastershipService mastershipService = get(MastershipService.class);
ObjectNode root = mapper().createObjectNode();
ArrayNode devicesNode = root.putArray(DEVICE_IDS);
Set<DeviceId> devices = mastershipService.getDevicesOf(NodeId.nodeId(nodeId));
if (devices != null) {
devices.forEach(id -> devicesNode.add(id.toString()));
}
return ok(root).build();
}
use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.
the class MastershipWebResource method requestRoleFor.
/**
* Returns the mastership status of the local controller for a given
* device forcing master selection if necessary.
*
* @param deviceId device identifier
* @return 200 OK with the role of this controller instance
* @onos.rsModel MastershipRole
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/request")
public Response requestRoleFor(@PathParam("deviceId") String deviceId) {
MastershipService mastershipService = get(MastershipService.class);
DeviceService deviceService = get(DeviceService.class);
DeviceId id = DeviceId.deviceId(deviceId);
nullIsNotFound(deviceService.getDevice(id), DEVICE_ID_NOT_FOUND);
MastershipRole role = nullIsNotFound(mastershipService.requestRoleForSync(id), MASTERSHIP_ROLE_NOT_FOUND);
ObjectNode root = codec(MastershipRole.class).encode(role, this);
return ok(root).build();
}
use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.
the class MastershipWebResource method getLocalRole.
/**
* Returns the role of the local node for the specified device.
*
* @param deviceId device identifier
* @return 200 OK with role of the current node
* @onos.rsModel MastershipRole
*/
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("{deviceId}/local")
public Response getLocalRole(@PathParam("deviceId") String deviceId) {
MastershipService mastershipService = get(MastershipService.class);
MastershipRole role = mastershipService.getLocalRole(DeviceId.deviceId(deviceId));
ObjectNode root = codec(MastershipRole.class).encode(role, this);
return ok(root).build();
}
use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.
the class OpenstackEastWestProbeCommand method doExecute.
@Override
protected void doExecute() {
OpenstackTroubleshootService tsService = get(OpenstackTroubleshootService.class);
InstancePortService instPortService = get(InstancePortService.class);
MastershipService mastershipService = get(MastershipService.class);
ClusterService clusterService = get(ClusterService.class);
OpenstackNodeService osNodeService = get(OpenstackNodeService.class);
if (tsService == null) {
error("Failed to troubleshoot openstack networking.");
return;
}
if ((!isAll && vmIps == null) || (isAll && vmIps != null)) {
print("Please specify one of VM IP address or -a option.");
return;
}
NodeId localNodeId = clusterService.getLocalNode().id();
for (OpenstackNode node : osNodeService.completeNodes(COMPUTE)) {
if (!localNodeId.equals(mastershipService.getMasterFor(node.intgBridge()))) {
error("Current node is not the master for all compute nodes. " + "Please enforce mastership first using openstack-reset-mastership -c !");
return;
}
}
if (isAll) {
printHeader();
// send ICMP PACKET_OUT to all connect VMs whose instance port state is ACTIVE
Set<InstancePort> activePorts = instPortService.instancePorts().stream().filter(p -> p.state() == ACTIVE).collect(Collectors.toSet());
activePorts.forEach(srcPort -> activePorts.forEach(dstPort -> printReachability(tsService.probeEastWest(srcPort, dstPort))));
} else {
if (vmIps.length > 2) {
print("Too many VM IPs. The number of IP should be limited to 2.");
return;
}
IpAddress srcIp = getIpAddress(vmIps[0]);
if (srcIp == null) {
return;
}
InstancePort srcPort = instPort(instPortService, srcIp);
if (srcPort == null) {
print("Specified source IP is not existing.");
return;
}
final Set<IpAddress> dstIps = Sets.newConcurrentHashSet();
if (vmIps.length == 2) {
IpAddress dstIp = getIpAddress(vmIps[1]);
if (dstIp == null) {
return;
}
dstIps.add(dstIp);
}
if (vmIps.length == 1) {
dstIps.addAll(instPortService.instancePorts().stream().filter(p -> !p.ipAddress().equals(srcIp)).filter(p -> p.state().equals(InstancePort.State.ACTIVE)).map(InstancePort::ipAddress).collect(Collectors.toSet()));
}
printHeader();
dstIps.stream().filter(ip -> instPort(instPortService, ip) != null).map(ip -> instPort(instPortService, ip)).forEach(port -> probeExecutor.execute(() -> printReachability(tsService.probeEastWest(srcPort, port))));
}
}
Aggregations