use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.
the class DistributedVirtualFlowRuleStore method getTableStatistics.
@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);
}
use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.
the class DistributedVirtualFlowRuleStore method removeFlowRule.
@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));
}
use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.
the class DistributedVirtualFlowRuleStore method getFlowEntry.
@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);
}
use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.
the class FujitsuVoltAlertConfig method subscribe.
@Override
public boolean subscribe(String mode) {
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)) {
log.warn("Not master for {} Use {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
return false;
}
if (mode != null) {
if (!DISABLE.equals(mode)) {
log.error("Invalid mode: {}", mode);
return false;
}
}
try {
if (mode != null) {
controller.getDevicesMap().get(ncDeviceId).getSession().endSubscription();
} else {
StringBuilder request = new StringBuilder();
request.append(ANGLE_LEFT + NOTIFY_ALERT + SPACE);
request.append(VOLT_NE_NAMESPACE + SLASH + ANGLE_RIGHT);
controller.getDevicesMap().get(ncDeviceId).getSession().startSubscription(request.toString());
}
} catch (NetconfException e) {
log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
return false;
}
return true;
}
use of org.onosproject.mastership.MastershipService in project onos by opennetworkinglab.
the class FujitsuVoltAlertConfig method setAlertFilter.
@Override
public boolean setAlertFilter(String severity) {
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)) {
log.warn("Not master for {} Use {} to execute command", ncDeviceId, mastershipService.getMasterFor(ncDeviceId));
return false;
}
if (!SEVERITYLEVELS.contains(severity)) {
log.error("Invalid severity level: {}", severity);
return false;
}
try {
StringBuilder request = new StringBuilder();
request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE);
request.append(ANGLE_RIGHT + NEW_LINE);
request.append(buildStartTag(VOLT_ALERTS)).append(buildStartTag(ALERT_FILTER, false)).append(severity).append(buildEndTag(ALERT_FILTER)).append(buildEndTag(VOLT_ALERTS)).append(VOLT_NE_CLOSE);
controller.getDevicesMap().get(ncDeviceId).getSession().editConfig(RUNNING, null, request.toString());
} catch (NetconfException e) {
log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
return false;
}
return true;
}
Aggregations