org.onosproject.mastership.MastershipService Java Examples

The following examples show how to use org.onosproject.mastership.MastershipService. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MeterDriverProvider.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the provider with the necessary device service, meter provider service,
 * mastership service and poll frequency.
 *
 * @param deviceService        device service
 * @param meterProviderService meter provider service
 * @param mastershipService    mastership service
 * @param pollFrequency        meter entry poll frequency
 */
void init(DeviceService deviceService, MeterProviderService meterProviderService,
          MastershipService mastershipService, int pollFrequency) {
    this.deviceService = deviceService;
    this.meterProviderService = meterProviderService;
    this.mastershipService = mastershipService;
    this.pollFrequency = pollFrequency;

    deviceService.addListener(deviceListener);

    if (poller != null && !poller.isCancelled()) {
        poller.cancel(false);
    }

    poller = executor.scheduleAtFixedRate(this::pollMeters, pollFrequency,
            pollFrequency, TimeUnit.SECONDS);

}
 
Example #2
Source File: NetconfControllerConfig.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public List<ControllerInfo> getControllers() {
    DriverHandler handler = handler();
    NetconfController controller = handler.get(NetconfController.class);
    MastershipService mastershipService = handler.get(MastershipService.class);
    DeviceId deviceId = handler.data().deviceId();
    Preconditions.checkNotNull(controller, "Netconf controller is null");
    List<ControllerInfo> controllers = new ArrayList<>();
    if (mastershipService.isLocalMaster(deviceId)) {
        try {
            String reply = controller.getNetconfDevice(deviceId).getSession().
                    getConfig(DatastoreId.RUNNING);
            log.debug("Reply XML {}", reply);
            controllers.addAll(XmlConfigParser.parseStreamControllers(XmlConfigParser.
                    loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8)))));
        } catch (NetconfException e) {
            log.error("Cannot communicate with device {} ", deviceId, e);
        }
    } else {
        log.warn("I'm not master for {} please use master, {} to execute command",
                 deviceId,
                 mastershipService.getMasterFor(deviceId));
    }
    return controllers;
}
 
Example #3
Source File: FujitsuVoltControllerConfig.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public void setControllers(List<ControllerInfo> controllers) {
    DriverHandler handler = handler();
    NetconfController controller = handler.get(NetconfController.class);
    MastershipService mastershipService = handler.get(MastershipService.class);
    DeviceId ncdeviceId = handler.data().deviceId();
    checkNotNull(controller, "Netconf controller is null");
    if (mastershipService.isLocalMaster(ncdeviceId)) {
        try {
            NetconfDevice device = controller.getNetconfDevice(ncdeviceId);
            String config = createVoltControllersConfig(
                    XmlConfigParser.loadXml(getClass().
                            getResourceAsStream(RESOURCE_XML)),
                    RUNNING, MERGE, controllers);
            device.getSession().editConfig(config.substring(
                    config.indexOf(END_LICENSE_HEADER) + END_LICENSE_HEADER.length()));
        } catch (NetconfException e) {
            log.error("Cannot communicate to device {} , exception {}", ncdeviceId, e);
        }
    } else {
        log.warn("I'm not master for {} please use master, {} to execute command",
                 ncdeviceId,
                 mastershipService.getMasterFor(ncdeviceId));
    }
}
 
Example #4
Source File: Topo2Jsonifier.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Creates an instance with a reference to the services directory, so that
 * additional information about network elements may be looked up on
 * on the fly.
 *
 * @param directory service directory
 * @param userName  logged in user name
 */
public Topo2Jsonifier(ServiceDirectory directory, String userName) {
    this.directory = checkNotNull(directory, "Directory cannot be null");
    this.userName = checkNotNull(userName, "User name cannot be null");

    clusterService = directory.get(ClusterService.class);
    deviceService = directory.get(DeviceService.class);
    linkService = directory.get(LinkService.class);
    hostService = directory.get(HostService.class);
    mastershipService = directory.get(MastershipService.class);
    intentService = directory.get(IntentService.class);
    flowService = directory.get(FlowRuleService.class);
    flowStatsService = directory.get(StatisticService.class);
    portStatsService = directory.get(PortStatisticsService.class);
    topologyService = directory.get(TopologyService.class);
    uiextService = directory.get(UiExtensionService.class);
    prefService = directory.get(UiPreferencesService.class);
}
 
Example #5
Source File: MastersListCommand.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
protected void doExecute() {
    ClusterService service = get(ClusterService.class);
    MastershipService mastershipService = get(MastershipService.class);
    DeviceService deviceService = get(DeviceService.class);
    List<ControllerNode> nodes = newArrayList(service.getNodes());
    Collections.sort(nodes, Comparators.NODE_COMPARATOR);

    if (outputJson()) {
        print("%s", json(service, mastershipService, nodes));
    } else {
        for (ControllerNode node : nodes) {
            List<DeviceId> ids = Lists.newArrayList(mastershipService.getDevicesOf(node.id()));
            ids.removeIf(did -> deviceService.getDevice(did) == null);
            Collections.sort(ids, Comparators.ELEMENT_ID_COMPARATOR);
            print("%s: %d devices", node.id(), ids.size());
            for (DeviceId deviceId : ids) {
                print("  %s", deviceId);
            }
        }
    }
}
 
Example #6
Source File: ServicesBundle.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the services bundle, from the given directly.
 *
 * @param directory service directory
 */
public ServicesBundle(ServiceDirectory directory) {
    checkNotNull(directory, "Directory cannot be null");

    clusterService = directory.get(ClusterService.class);

    topologyService = directory.get(TopologyService.class);
    deviceService = directory.get(DeviceService.class);
    driverService = directory.get(DriverService.class);
    hostService = directory.get(HostService.class);
    linkService = directory.get(LinkService.class);

    mastershipService = directory.get(MastershipService.class);
    mastershipAdminService = directory.get(MastershipAdminService.class);
    intentService = directory.get(IntentService.class);
    flowService = directory.get(FlowRuleService.class);
    flowStatsService = directory.get(StatisticService.class);
    portStatsService = directory.get(PortStatisticsService.class);
}
 
Example #7
Source File: DistributedVirtualFlowRuleStore.java    From onos with Apache License 2.0 6 votes vote down vote up
@Override
public Iterable<TableStatisticsEntry> getTableStatistics(NetworkId networkId, DeviceId deviceId) {
    MastershipService mastershipService =
            vnaService.get(networkId, MastershipService.class);
    NodeId master = mastershipService.getMasterFor(deviceId);

    if (master == null) {
        log.debug("Failed to getTableStats: No master for {}", deviceId);
        return Collections.emptyList();
    }

    if (deviceTableStats.get(networkId) == null) {
        deviceTableStats.put(networkId, Maps.newConcurrentMap());
    }

    List<TableStatisticsEntry> tableStats = deviceTableStats.get(networkId).get(deviceId);
    if (tableStats == null) {
        return Collections.emptyList();
    }
    return ImmutableList.copyOf(tableStats);
}
 
Example #8
Source File: TopologySimulator.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes a new topology simulator with access to the specified service
 * directory and various provider services.
 *
 * @param topoShape             topology shape specifier
 * @param deviceCount           number of devices in the topology
 * @param hostCount             number of hosts per device
 * @param directory             service directory
 * @param deviceProviderService device provider service
 * @param hostProviderService   host provider service
 * @param linkProviderService   link provider service
 */
protected void init(String topoShape, int deviceCount, int hostCount,
                    ServiceDirectory directory,
                    DeviceProviderService deviceProviderService,
                    HostProviderService hostProviderService,
                    LinkProviderService linkProviderService) {
    this.deviceCount = deviceCount;
    this.hostCount = hostCount;
    this.directory = directory;

    this.clusterService = directory.get(ClusterService.class);
    this.mastershipService = directory.get(MastershipService.class);
    this.mastershipAdminService = directory.get(MastershipAdminService.class);

    this.deviceService = directory.get(DeviceAdminService.class);
    this.hostService = directory.get(HostService.class);
    this.linkService = directory.get(LinkService.class);
    this.deviceProviderService = deviceProviderService;
    this.hostProviderService = hostProviderService;
    this.linkProviderService = linkProviderService;

    localNode = clusterService.getLocalNode().id();

    processTopoShape(topoShape);
}
 
Example #9
Source File: FlowRuleDriverProvider.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the provider with necessary supporting services.
 *
 * @param providerService   flow rule provider service
 * @param deviceService     device service
 * @param mastershipService mastership service
 * @param pollFrequency     flow entry poll frequency
 */
void init(FlowRuleProviderService providerService,
          DeviceService deviceService, MastershipService mastershipService,
          int pollFrequency) {
    this.providerService = providerService;
    this.deviceService = deviceService;
    this.mastershipService = mastershipService;

    deviceService.addListener(deviceListener);

    if (poller != null && !poller.isCancelled()) {
        poller.cancel(false);
    }

    poller = executor.scheduleAtFixedRate(this::pollFlowEntries, pollFrequency,
                                          pollFrequency, TimeUnit.SECONDS);
}
 
Example #10
Source File: MastershipWebResource.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
}
 
Example #11
Source File: GroupDriverProvider.java    From onos with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the provider with the necessary device service, group provider service,
 * mastership service and poll frequency.
 *
 * @param deviceService        device service
 * @param groupProviderService group provider service
 * @param mastershipService    mastership service
 * @param pollFrequency        group entry poll frequency
 */
void init(DeviceService deviceService, GroupProviderService groupProviderService,
          MastershipService mastershipService, int pollFrequency) {
    this.deviceService = deviceService;
    this.groupProviderService = groupProviderService;
    this.mastershipService = mastershipService;

    deviceService.addListener(deviceListener);

    if (poller != null && !poller.isCancelled()) {
        poller.cancel(false);
    }

    poller = executor.scheduleAtFixedRate(this::pollGroups, pollFrequency,
            pollFrequency, TimeUnit.SECONDS);

}
 
Example #12
Source File: DeviceViewMessageHandler.java    From onos with Apache License 2.0 6 votes vote down vote up
private void populateRow(TableModel.Row row, Device dev,
                         DeviceService ds, MastershipService ms) {
    DeviceId id = dev.id();
    boolean available = ds.isAvailable(id);
    String iconId = available ? ICON_ID_ONLINE : ICON_ID_OFFLINE;

    row.cell(ID, id)
        .cell(NAME, deviceName(dev))
        .cell(AVAILABLE, available)
        .cell(AVAILABLE_IID, iconId)
        .cell(TYPE_IID, getTypeIconId(dev))
        .cell(MFR, dev.manufacturer())
        .cell(HW, dev.hwVersion())
        .cell(SW, dev.swVersion())
        .cell(PROTOCOL, deviceProtocol(dev))
        .cell(NUM_PORTS, ds.getPorts(id).size())
        .cell(MASTER_ID, ms.getMasterFor(id));
}
 
Example #13
Source File: RolesCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #14
Source File: RolesCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Prints the role information for a device.
 *
 * @param service  mastership service
 * @param deviceId the ID of the device
 */
protected void printRoles(MastershipService service, DeviceId deviceId) {
    RoleInfo nodes = service.getNodesFor(deviceId);
    StringBuilder builder = new StringBuilder();
    for (NodeId nid : nodes.backups()) {
        builder.append(nid).append(" ");
    }

    print(FMT_HDR, deviceId,
          nodes.master() == null ? "NONE" : nodes.master(),
          builder.toString());
}
 
Example #15
Source File: DistributedVirtualFlowRuleStore.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public FlowEntry getFlowEntry(NetworkId networkId, FlowRule rule) {
    MastershipService mastershipService =
            vnaService.get(networkId, MastershipService.class);
    NodeId master = mastershipService.getMasterFor(rule.deviceId());

    if (master == null) {
        log.debug("Failed to getFlowEntry: No master for {}, vnet {}",
                  rule.deviceId(), networkId);
        return null;
    }

    if (Objects.equals(local, master)) {
        return flowTable.getFlowEntry(networkId, rule);
    }

    log.trace("Forwarding getFlowEntry to {}, which is the primary (master) " +
                      "for device {}, vnet {}",
              master, rule.deviceId(), networkId);

    VirtualFlowRule vRule = new VirtualFlowRule(networkId, rule);

    return Tools.futureGetOrElse(clusterCommunicator.sendAndReceive(vRule,
                                                                    GET_FLOW_ENTRY,
                                                                    serializer::encode,
                                                                    serializer::decode,
                                                                    master),
                                 FLOW_RULE_STORE_TIMEOUT_MILLIS,
                                 TimeUnit.MILLISECONDS,
                                 null);
}
 
Example #16
Source File: VirtualNetworkManager.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new vnet service instance.
 *
 * @param serviceKey service key
 * @return vnet service
 */
private VnetService create(ServiceKey serviceKey) {
    VirtualNetwork network = getVirtualNetwork(serviceKey.networkId());
    checkNotNull(network, NETWORK_NULL);

    VnetService service;
    if (serviceKey.serviceClass.equals(DeviceService.class)) {
        service = new VirtualNetworkDeviceManager(this, network.id());
    } else if (serviceKey.serviceClass.equals(LinkService.class)) {
        service = new VirtualNetworkLinkManager(this, network.id());
    } else if (serviceKey.serviceClass.equals(TopologyService.class)) {
        service = new VirtualNetworkTopologyManager(this, network.id());
    } else if (serviceKey.serviceClass.equals(IntentService.class)) {
        service = new VirtualNetworkIntentManager(this, network.id());
    } else if (serviceKey.serviceClass.equals(HostService.class)) {
        service = new VirtualNetworkHostManager(this, network.id());
    } else if (serviceKey.serviceClass.equals(PathService.class)) {
        service = new VirtualNetworkPathManager(this, network.id());
    } else if (serviceKey.serviceClass.equals(FlowRuleService.class)) {
        service = new VirtualNetworkFlowRuleManager(this, network.id());
    } else if (serviceKey.serviceClass.equals(PacketService.class)) {
        service = new VirtualNetworkPacketManager(this, network.id());
    } else if (serviceKey.serviceClass.equals(GroupService.class)) {
        service = new VirtualNetworkGroupManager(this, network.id());
    } else if (serviceKey.serviceClass.equals(MeterService.class)) {
        service = new VirtualNetworkMeterManager(this, network.id());
    } else if (serviceKey.serviceClass.equals(FlowObjectiveService.class)) {
        service = new VirtualNetworkFlowObjectiveManager(this, network.id());
    } else if (serviceKey.serviceClass.equals(MastershipService.class) ||
            serviceKey.serviceClass.equals(MastershipAdminService.class) ||
            serviceKey.serviceClass.equals(MastershipTermService.class)) {
        service = new VirtualNetworkMastershipManager(this, network.id());
    } else {
        return null;
    }
    networkServices.put(serviceKey, service);
    return service;
}
 
Example #17
Source File: DistributedVirtualFlowRuleStore.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public Iterable<FlowEntry> getFlowEntries(NetworkId networkId, DeviceId deviceId) {
    MastershipService mastershipService =
            vnaService.get(networkId, MastershipService.class);
    NodeId master = mastershipService.getMasterFor(deviceId);

    if (master == null) {
        log.debug("Failed to getFlowEntries: No master for {}, vnet {}", deviceId, networkId);
        return Collections.emptyList();
    }

    if (Objects.equals(local, master)) {
        return flowTable.getFlowEntries(networkId, deviceId);
    }

    log.trace("Forwarding getFlowEntries to {}, which is the primary (master) for device {}",
              master, deviceId);

    return Tools.futureGetOrElse(
            clusterCommunicator.sendAndReceive(deviceId,
                                               GET_DEVICE_FLOW_ENTRIES,
                                               serializer::encode,
                                               serializer::decode,
                                               master),
            FLOW_RULE_STORE_TIMEOUT_MILLIS,
            TimeUnit.MILLISECONDS,
            Collections.emptyList());
}
 
Example #18
Source File: DistributedVirtualFlowRuleStore.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public FlowRuleEvent pendingFlowRule(NetworkId networkId, FlowEntry rule) {
    MastershipService mastershipService =
            vnaService.get(networkId, MastershipService.class);
    if (mastershipService.isLocalMaster(rule.deviceId())) {
        StoredFlowEntry stored = flowTable.getFlowEntry(networkId, rule);
        if (stored != null &&
                stored.state() != FlowEntry.FlowEntryState.PENDING_ADD) {
            stored.setState(FlowEntry.FlowEntryState.PENDING_ADD);
            return new FlowRuleEvent(FlowRuleEvent.Type.RULE_UPDATED, rule);
        }
    }
    return null;
}
 
Example #19
Source File: DistributedVirtualFlowRuleStore.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void handle(final ClusterMessage message) {
    VirtualFlowRuleBatchOperation vOperation = serializer.decode(message.payload());
    log.debug("received batch request {}", vOperation);

    FlowRuleBatchOperation operation = vOperation.operation();

    final DeviceId deviceId = operation.deviceId();
    MastershipService mastershipService =
            vnaService.get(vOperation.networkId(), MastershipService.class);
    NodeId master = mastershipService.getMasterFor(deviceId);
    if (!Objects.equals(local, master)) {
        Set<FlowRule> failures = new HashSet<>(operation.size());
        for (FlowRuleBatchEntry op : operation.getOperations()) {
            failures.add(op.target());
        }
        CompletedBatchOperation allFailed = new CompletedBatchOperation(false, failures, deviceId);
        // This node is no longer the master, respond as all failed.
        // TODO: we might want to wrap response in envelope
        // to distinguish sw programming failure and hand over
        // it make sense in the latter case to retry immediately.
        message.respond(serializer.encode(allFailed));
        return;
    }

    pendingResponses.put(operation.id(), message.sender());
    storeBatchInternal(vOperation.networkId(), operation);
}
 
Example #20
Source File: TroubleshootLoadSnapshotCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void loadMastershipNib() {
    MastershipService mastershipService = get(MastershipService.class);
    DeviceService deviceService = get(DeviceService.class);
    Map<DeviceId, NodeId> deviceMasterMap = new HashMap<>();

    Lists.newArrayList(deviceService.getDevices().iterator())
            .forEach(device -> deviceMasterMap.put(device.id(), mastershipService.getMasterFor(device.id())));

    MastershipNib mastershipNib = MastershipNib.getInstance();
    mastershipNib.setDeviceMasterMap(deviceMasterMap);
}
 
Example #21
Source File: DefaultRoutingHandlerTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
    srManager = createMock(SegmentRoutingManager.class);
    srManager.storageService = createMock(StorageService.class);
    expect(srManager.storageService.consistentMapBuilder()).andReturn(new TestConsistentMap.Builder<>()).anyTimes();
    expect(srManager.storageService.consistentMultimapBuilder()).andReturn(
            new TestConsistentMultimap.Builder<>()).anyTimes();
    replay(srManager.storageService);
    srManager.routingRulePopulator = createMock(RoutingRulePopulator.class);
    srManager.deviceService = createMock(DeviceService.class);
    srManager.deviceConfiguration = createMock(DeviceConfiguration.class);
    srManager.mastershipService = createMock(MastershipService.class);
    srManager.clusterService = createMock(ClusterService.class);
    dfh = new DefaultRoutingHandler(srManager);
}
 
Example #22
Source File: ResourceDeviceListener.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * Creates an instance with the specified ResourceAdminService and ExecutorService.
 *
 * @param adminService instance invoked to register resources
 * @param resourceService {@link ResourceQueryService} to be used
 * @param deviceService {@link DeviceService} to be used
 * @param mastershipService {@link MastershipService} to be used
 * @param driverService {@link DriverService} to be used
 * @param netcfgService {@link NetworkConfigService} to be used.
 * @param executor executor used for processing resource registration
 */
ResourceDeviceListener(ResourceAdminService adminService, ResourceQueryService resourceService,
                       DeviceService deviceService, MastershipService mastershipService,
                       DriverService driverService, NetworkConfigService netcfgService,
                       ExecutorService executor) {
    this.adminService = checkNotNull(adminService);
    this.resourceService = checkNotNull(resourceService);
    this.deviceService = checkNotNull(deviceService);
    this.mastershipService = checkNotNull(mastershipService);
    this.driverService = checkNotNull(driverService);
    this.netcfgService = checkNotNull(netcfgService);
    this.executor = checkNotNull(executor);
}
 
Example #23
Source File: DistributedVirtualFlowRuleStore.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public FlowRuleEvent removeFlowRule(NetworkId networkId, FlowEntry rule) {
    final DeviceId deviceId = rule.deviceId();

    MastershipService mastershipService =
            vnaService.get(networkId, MastershipService.class);
    NodeId master = mastershipService.getMasterFor(deviceId);

    if (Objects.equals(local, master)) {
        // bypass and handle it locally
        return removeFlowRuleInternal(new VirtualFlowEntry(networkId, rule));
    }

    if (master == null) {
        log.warn("Failed to removeFlowRule: No master for {}", deviceId);
        // TODO: revisit if this should be null (="no-op") or Exception
        return null;
    }

    log.trace("Forwarding removeFlowRule to {}, which is the master for device {}",
              master, deviceId);

    return Futures.getUnchecked(clusterCommunicator.sendAndReceive(
            new VirtualFlowEntry(networkId, rule),
            REMOVE_FLOW_ENTRY,
            serializer::encode,
            serializer::decode,
            master));
}
 
Example #24
Source File: RolesCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #25
Source File: RolesCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
protected void doExecute() {
    DeviceService deviceService = get(DeviceService.class);
    MastershipService roleService = get(MastershipService.class);

    if (outputJson()) {
        print("%s", json(roleService, getSortedDevices(deviceService)));
    } else {
        for (Device d : getSortedDevices(deviceService)) {
            DeviceId did = d.id();
            printRoles(roleService, did);
        }
    }
}
 
Example #26
Source File: ServerControllerConfig.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
public void removeControllers(List<ControllerInfo> controllers) {
    DeviceId deviceId = getDeviceId();
    checkNotNull(deviceId, MSG_DEVICE_ID_NULL);

    MastershipService mastershipService = getHandler().get(MastershipService.class);
    checkNotNull(deviceId, MSG_MASTERSHIP_NULL);

    if (!mastershipService.isLocalMaster(deviceId)) {
        log.warn(
            "I am not master for {}. " +
            "Please use master {} to remove controllers from this device",
            deviceId, mastershipService.getMasterFor(deviceId));
        return;
    }

    for (ControllerInfo ctrl : controllers) {
        log.info("Remove controller with {}:{}:{}",
            ctrl.type(), ctrl.ip().toString(), ctrl.port());

        String remCtrlUrl = URL_CONTROLLERS_DEL + SLASH + ctrl.ip().toString();

        // Remove this controller
        int response = getController().delete(deviceId, remCtrlUrl, null, JSON);

        if (!checkStatusCode(response)) {
            log.error("Failed to remove controller {}:{}:{} from device {}",
                ctrl.type(), ctrl.ip().toString(), ctrl.port(), deviceId);
        }
    }

    return;
}
 
Example #27
Source File: MastersListCommand.java    From onos with Apache License 2.0 5 votes vote down vote up
private JsonNode json(ClusterService service, MastershipService mastershipService,
                      List<ControllerNode> nodes) {
    ObjectMapper mapper = new ObjectMapper();
    ArrayNode result = mapper.createArrayNode();
    for (ControllerNode node : nodes) {
        List<DeviceId> ids = Lists.newArrayList(mastershipService.getDevicesOf(node.id()));
        result.add(mapper.createObjectNode()
                           .put("id", node.id().toString())
                           .put("size", ids.size())
                           .set("devices", json(mapper, ids)));
    }
    return result;
}
 
Example #28
Source File: ServerControllerConfigTest.java    From onos with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <T> T get(Class<T> serviceClass) {
    if (serviceClass == MastershipService.class) {
        return (T) mastershipService;
    } else if (serviceClass == RestSBController.class) {
        return (T) controller;
    }
    return null;
}
 
Example #29
Source File: MastershipWebResource.java    From onos with Apache License 2.0 5 votes vote down vote up
/**
 * 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();
}
 
Example #30
Source File: GnmiDeviceStateSubscriber.java    From onos with Apache License 2.0 5 votes vote down vote up
GnmiDeviceStateSubscriber(GnmiController gnmiController, DeviceService deviceService,
                          MastershipService mastershipService,
                          DeviceProviderService providerService) {
    this.gnmiController = gnmiController;
    this.deviceService = deviceService;
    this.mastershipService = mastershipService;
    this.providerService = providerService;
}