本文整理汇总了Java中org.onosproject.mastership.MastershipService.isLocalMaster方法的典型用法代码示例。如果您正苦于以下问题:Java MastershipService.isLocalMaster方法的具体用法?Java MastershipService.isLocalMaster怎么用?Java MastershipService.isLocalMaster使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.onosproject.mastership.MastershipService
的用法示例。
在下文中一共展示了MastershipService.isLocalMaster方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getControllers
import org.onosproject.mastership.MastershipService; //导入方法依赖的package包/类
@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("running");
log.debug("Reply XML {}", reply);
controllers.addAll(XmlConfigParser.parseStreamControllers(XmlConfigParser.
loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8)))));
} catch (IOException 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;
}
示例2: getControllers
import org.onosproject.mastership.MastershipService; //导入方法依赖的package包/类
@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;
}
示例3: setControllers
import org.onosproject.mastership.MastershipService; //导入方法依赖的package包/类
@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));
}
}
示例4: getAlertFilter
import org.onosproject.mastership.MastershipService; //导入方法依赖的package包/类
@Override
public String getAlertFilter() {
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");
String reply = null;
if (!mastershipService.isLocalMaster(ncDeviceId)) {
log.warn("Not master for {} Use {} to execute command",
ncDeviceId,
mastershipService.getMasterFor(ncDeviceId));
return null;
}
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(buildEmptyTag(ALERT_FILTER))
.append(buildEndTag(VOLT_ALERTS))
.append(VOLT_NE_CLOSE);
reply = controller
.getDevicesMap()
.get(ncDeviceId)
.getSession()
.get(request.toString(), REPORT_ALL);
} catch (NetconfException e) {
log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
}
return reply;
}
示例5: setAlertFilter
import org.onosproject.mastership.MastershipService; //导入方法依赖的package包/类
@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;
}
示例6: subscribe
import org.onosproject.mastership.MastershipService; //导入方法依赖的package包/类
@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;
}
示例7: getAll
import org.onosproject.mastership.MastershipService; //导入方法依赖的package包/类
@Override
public String getAll() {
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");
String reply = null;
if (!mastershipService.isLocalMaster(ncDeviceId)) {
log.warn("Not master for {} Use {} to execute command",
ncDeviceId,
mastershipService.getMasterFor(ncDeviceId));
return null;
}
try {
StringBuilder request = new StringBuilder();
request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE);
request.append(ANGLE_RIGHT + NEW_LINE);
request.append(VOLT_NE_CLOSE);
reply = controller
.getDevicesMap()
.get(ncDeviceId)
.getSession()
.get(request.toString(), REPORT_ALL);
} catch (NetconfException e) {
log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
}
return reply;
}
示例8: getControllers
import org.onosproject.mastership.MastershipService; //导入方法依赖的package包/类
@Override
public List<ControllerInfo> getControllers() {
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");
List<ControllerInfo> controllers = new ArrayList<>();
if (mastershipService.isLocalMaster(ncDeviceId)) {
try {
StringBuilder request = new StringBuilder();
request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE + ">\n");
request.append(buildEmptyTag(VOLT_OFCONFIG));
request.append(VOLT_NE_CLOSE);
String reply;
reply = controller
.getDevicesMap()
.get(ncDeviceId)
.getSession()
.get(request.toString(), REPORT_ALL);
log.debug("Reply XML {}", reply);
controllers.addAll(parseStreamVoltControllers(XmlConfigParser.
loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8)))));
} catch (NetconfException e) {
log.error("Cannot communicate to device {} ", ncDeviceId);
}
} else {
log.warn("I'm not master for {} please use master, {} to execute command",
ncDeviceId,
mastershipService.getMasterFor(ncDeviceId));
}
return ImmutableList.copyOf(controllers);
}
示例9: consumeAlarms
import org.onosproject.mastership.MastershipService; //导入方法依赖的package包/类
@Override
public List<Alarm> consumeAlarms() {
DriverHandler handler = handler();
NetconfController controller = handler.get(NetconfController.class);
MastershipService mastershipService = handler.get(MastershipService.class);
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 null;
}
dateFormat.setTimeZone(ZONE);
List<Alarm> alarms = new ArrayList<>();
try {
StringBuilder request = new StringBuilder();
request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE)
.append(ANGLE_RIGHT + NEW_LINE)
.append(buildStartTag(VOLT_ALERTS))
.append(buildEmptyTag(OLT_ACTIVE_ALERTS))
.append(buildEndTag(VOLT_ALERTS))
.append(VOLT_NE_CLOSE);
String reply = controller.getDevicesMap()
.get(ncDeviceId)
.getSession()
.get(request.toString(), null);
if (reply != null) {
alarms = parseVoltActiveAlerts(XmlConfigParser.
loadXml(new ByteArrayInputStream(reply.getBytes(StandardCharsets.UTF_8))));
}
} catch (NetconfException e) {
log.error("Error reading alarms for device {} exception {}", ncDeviceId, e);
}
return ImmutableList.copyOf(alarms);
}
示例10: pendingFlowRule
import org.onosproject.mastership.MastershipService; //导入方法依赖的package包/类
@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;
}
示例11: rebootOnu
import org.onosproject.mastership.MastershipService; //导入方法依赖的package包/类
@Override
public String rebootOnu(String target) {
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");
String reply = null;
String[] onuId = null;
if (!mastershipService.isLocalMaster(ncDeviceId)) {
log.warn("Not master for {} Use {} to execute command",
ncDeviceId,
mastershipService.getMasterFor(ncDeviceId));
return null;
}
onuId = checkIdString(target, TWO);
if (onuId == null) {
log.error("Invalid ONU identifier {}", target);
return null;
}
try {
StringBuilder request = new StringBuilder();
request.append(ANGLE_LEFT + ONU_REBOOT + SPACE);
request.append(VOLT_NE_NAMESPACE + ANGLE_RIGHT + NEW_LINE);
request.append(buildStartTag(PONLINK_ID, false))
.append(onuId[FIRST_PART])
.append(buildEndTag(PONLINK_ID))
.append(buildStartTag(ONU_ID, false))
.append(onuId[SECOND_PART])
.append(buildEndTag(ONU_ID))
.append(buildEndTag(ONU_REBOOT));
reply = controller
.getDevicesMap()
.get(ncDeviceId)
.getSession()
.doWrappedRpc(request.toString());
} catch (NetconfException e) {
log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
}
return reply;
}
示例12: getOnus
import org.onosproject.mastership.MastershipService; //导入方法依赖的package包/类
@Override
public String getOnus(String target) {
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");
String reply = null;
String[] onuId = null;
if (!mastershipService.isLocalMaster(ncDeviceId)) {
log.warn("Not master for {} Use {} to execute command",
ncDeviceId,
mastershipService.getMasterFor(ncDeviceId));
return null;
}
if (target != null) {
onuId = checkIdString(target);
if (onuId == null) {
log.error("Invalid ONU identifier {}", target);
return null;
}
}
try {
StringBuilder request = new StringBuilder();
request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE);
request.append(ANGLE_RIGHT + NEW_LINE);
if (onuId != null) {
request.append(buildStartTag(VOLT_ONUS))
.append(buildStartTag(ONUS_PERLINK))
.append(buildStartTag(PONLINK_ID, false))
.append(onuId[FIRST_PART])
.append(buildEndTag(PONLINK_ID));
if (onuId.length > ONE) {
request.append(buildStartTag(ONUS_LIST))
.append(buildStartTag(ONU_INFO))
.append(buildStartTag(ONU_ID, false))
.append(onuId[SECOND_PART])
.append(buildEndTag(ONU_ID))
.append(buildEndTag(ONU_INFO))
.append(buildEndTag(ONUS_LIST));
}
request.append(buildEndTag(ONUS_PERLINK))
.append(buildEndTag(VOLT_ONUS));
} else {
request.append(buildEmptyTag(VOLT_ONUS));
}
request.append(VOLT_NE_CLOSE);
reply = controller
.getDevicesMap()
.get(ncDeviceId)
.getSession()
.get(request.toString(), REPORT_ALL);
} catch (NetconfException e) {
log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
}
return reply;
}
示例13: getOnuStatistics
import org.onosproject.mastership.MastershipService; //导入方法依赖的package包/类
@Override
public String getOnuStatistics(String target) {
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");
String reply = null;
String[] onuId = null;
if (!mastershipService.isLocalMaster(ncDeviceId)) {
log.warn("Not master for {} Use {} to execute command",
ncDeviceId,
mastershipService.getMasterFor(ncDeviceId));
return null;
}
if (target != null) {
onuId = checkIdString(target);
if (onuId == null) {
log.error("Failed to check ID: {}", target);
return null;
}
}
try {
StringBuilder request = new StringBuilder();
request.append(VOLT_NE_OPEN + VOLT_NE_NAMESPACE);
request.append(ANGLE_RIGHT + NEW_LINE);
request.append(buildStartTag(VOLT_STATISTICS));
if (onuId != null) {
request.append(buildStartTag(ONU_STATISTICS))
.append(buildStartTag(ONU_GEM_STATS))
.append(buildStartTag(GEM_STATS))
.append(buildStartTag(PONLINK_ID, false))
.append(onuId[FIRST_PART])
.append(buildEndTag(PONLINK_ID));
if (onuId.length > ONE) {
request.append(buildStartTag(ONU_ID, false))
.append(onuId[SECOND_PART])
.append(buildEndTag(ONU_ID));
}
request.append(buildEndTag(GEM_STATS))
.append(buildEndTag(ONU_GEM_STATS));
request.append(buildStartTag(ONU_ETH_STATS))
.append(buildStartTag(ETH_STATS))
.append(buildStartTag(PONLINK_ID, false))
.append(onuId[FIRST_PART])
.append(buildEndTag(PONLINK_ID));
if (onuId.length > ONE) {
request.append(buildStartTag(ONU_ID, false))
.append(onuId[SECOND_PART])
.append(buildEndTag(ONU_ID));
}
request.append(buildEndTag(ETH_STATS))
.append(buildEndTag(ONU_ETH_STATS))
.append(buildEndTag(ONU_STATISTICS));
} else {
request.append(buildEmptyTag(ONU_STATISTICS));
}
request.append(buildEndTag(VOLT_STATISTICS))
.append(VOLT_NE_CLOSE);
reply = controller
.getDevicesMap()
.get(ncDeviceId)
.getSession()
.get(request.toString(), REPORT_ALL);
} catch (NetconfException e) {
log.error("Cannot communicate to device {} exception {}", ncDeviceId, e);
}
return reply;
}