本文整理汇总了Java中org.opennms.netmgt.model.OnmsNode类的典型用法代码示例。如果您正苦于以下问题:Java OnmsNode类的具体用法?Java OnmsNode怎么用?Java OnmsNode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
OnmsNode类属于org.opennms.netmgt.model包,在下文中一共展示了OnmsNode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setUp
import org.opennms.netmgt.model.OnmsNode; //导入依赖的package包/类
@Before
public void setUp() {
m_databasePopulator.populateDatabase();
// Set the primary address of Node2 as the test address.
m_testAddress = m_databasePopulator.getNode2().getPrimaryInterface().getIpAddress();
// Adding the test address as a secondary address (unmanaged) to Node1
OnmsNode n1 = m_databasePopulator.getNode1();
OnmsIpInterface iface = new OnmsIpInterface(m_testAddress.getHostAddress(), n1);
iface.setIsManaged("U");
iface.setIsSnmpPrimary(PrimaryType.SECONDARY);
OnmsSnmpInterface snmpIf = new OnmsSnmpInterface(n1, 1001);
iface.setSnmpInterface(snmpIf);
snmpIf.getIpInterfaces().add(iface);
n1.addIpInterface(iface);
m_databasePopulator.getNodeDao().save(n1);
}
示例2: getResourcesForNode
import org.opennms.netmgt.model.OnmsNode; //导入依赖的package包/类
/** {@inheritDoc} */
public List<OnmsResource> getResourcesForNode(final int nodeId) {
final LinkedList<OnmsResource> resources = new LinkedList<OnmsResource>();
final OnmsNode node = m_nodeDao.get(nodeId);
if (node == null) {
throw new ObjectRetrievalFailureException(OnmsNode.class, nodeId, "Could not find node for node Id " + nodeId, null);
}
for (final OnmsIpInterface i : node.getIpInterfaces()) {
String ipAddr = InetAddressUtils.str(i.getIpAddress());
final File iface = getInterfaceDirectory(ipAddr, false);
if (iface.isDirectory()) {
resources.add(createResource(i));
}
}
return resources;
}
示例3: testAddAutoenable
import org.opennms.netmgt.model.OnmsNode; //导入依赖的package包/类
@Test
@Transactional
public void testAddAutoenable() {
OnmsNode onmsNode = new OnmsNode(m_distPollerDao.load("localhost"));
onmsNode.setLabel("myNode");
m_nodeDao.save(onmsNode);
OnmsAssetRecord assetRecord = onmsNode.getAssetRecord();
assetRecord.setAssetNumber("imported-id: 7");
assetRecord.setUsername("antonio");
assetRecord.setPassword("password");
assetRecord.setAutoenable(OnmsAssetRecord.AUTOENABLED);
assetRecord.setConnection(OnmsAssetRecord.TELNET_CONNECTION);
m_assetRecordDao.update(assetRecord);
m_assetRecordDao.flush();
//Test findAll method
int id = assetRecord.getId();
OnmsAssetRecord assetRecordFromDb = m_assetRecordDao.get(id);
assertEquals(assetRecord.getUsername(), assetRecordFromDb.getUsername());
assertEquals(assetRecord.getPassword(), assetRecordFromDb.getPassword());
assertEquals(assetRecord.getAutoenable(), assetRecordFromDb.getAutoenable());
assertEquals(assetRecord.getConnection(), assetRecordFromDb.getConnection());
}
示例4: getForeignSourceNodeEntityResource
import org.opennms.netmgt.model.OnmsNode; //导入依赖的package包/类
/**
* <p>getForeignSourceNodeEntityResource</p>
*
* @param resource a {@link java.lang.String} object.
* @return a {@link org.opennms.netmgt.model.OnmsResource} object.
*/
protected OnmsResource getForeignSourceNodeEntityResource(String resource) {
File idDir = new File(getRrdDirectory(), SNMP_DIRECTORY + File.separator + ResourceTypeUtils.getRelativeNodeSourceDirectory(resource).toString());
if (idDir.isDirectory() && RrdFileConstants.NODESOURCE_DIRECTORY_FILTER.accept(idDir)) {
return m_nodeSourceResourceType.createChildResource(resource);
} else {
log().debug("resource " + resource + " not found by foreign source/foreignId. Trying as a node resource instead...");
String[] ident = resource.split(":");
OnmsNode node = m_nodeDao.findByForeignId(ident[0], ident[1]);
if (node == null) {
throw new ObjectRetrievalFailureException(OnmsNode.class, resource, "Top-level resource of resource type node could not be found: " + resource, null);
}
OnmsResource onmsResource = getResourceForNode(node);
return onmsResource;
}
}
示例5: matchPolicy
import org.opennms.netmgt.model.OnmsNode; //导入依赖的package包/类
private List<OnmsNode> matchPolicy(NodeCategorySettingPolicy p, String matchingId) {
OnmsNode o;
List<OnmsNode> populatedNodes = new ArrayList<OnmsNode>();
List<OnmsNode> matchedNodes = new ArrayList<OnmsNode>();
for (OnmsNode node : m_nodes) {
System.err.println(node);
o = p.apply(node);
if (o != null && o.getCategories().contains(new OnmsCategory(p.getCategory()))) {
matchedNodes.add(o);
}
if (node.getNodeId().equals(matchingId)) {
populatedNodes.add(node);
}
}
assertEquals(populatedNodes, matchedNodes);
return matchedNodes;
}
示例6: getParticipants
import org.opennms.netmgt.model.OnmsNode; //导入依赖的package包/类
/**
* Currently only here for world IPv6 day, returns all nodelabels.
* @return
*/
@GET
@Produces({MediaType.APPLICATION_JSON})
@Path("participants")
public String getParticipants(){
readLock();
try {
List<OnmsNode> nodes = m_nodeDao.findAll();
StringBuffer retVal = new StringBuffer();
retVal.append("{\"participants\":[");
for(int i = 0; i < nodes.size(); i++) {
OnmsNode node = nodes.get(i);
if(i == 0) {
retVal.append("{\"name\":\"" + node.getLabel() + "\"}");
}else {
retVal.append(",{\"name\":\"" + node.getLabel() + "\"}");
}
}
retVal.append("]}");
return retVal.toString();
} finally {
readUnlock();
}
}
示例7: testProvisionerAddNodeToSchedule
import org.opennms.netmgt.model.OnmsNode; //导入依赖的package包/类
@Test(timeout=300000)
@JUnitTemporaryDatabase // Relies on records created in @Before so we need a fresh database
public void testProvisionerAddNodeToSchedule() throws Exception{
m_provisioner.scheduleRescanForExistingNodes();
assertEquals(0, m_provisioner.getScheduleLength());
final OnmsNode node = createNode();
assertEquals(1, node.getId().intValue());
assertNotNull(m_nodeDao.get(1));
final EventBuilder bldr = new EventBuilder(EventConstants.NODE_ADDED_EVENT_UEI, "Tests");
bldr.setNodeid(1);
m_mockEventIpcManager.broadcastNow(bldr.getEvent());
assertEquals(1, m_provisioner.getScheduleLength());
}
示例8: saveOrUpdate
import org.opennms.netmgt.model.OnmsNode; //导入依赖的package包/类
@Transactional
private OnmsNode saveOrUpdate(final OnmsNode node) {
final Set<OnmsCategory> updatedCategories = new HashSet<OnmsCategory>();
for(final Iterator<OnmsCategory> it = node.getCategories().iterator(); it.hasNext(); ) {
final OnmsCategory category = it.next();
if (category.getId() == null) {
it.remove();
updatedCategories.add(createCategoryIfNecessary(category.getName()));
}
}
node.getCategories().addAll(updatedCategories);
m_nodeDao.saveOrUpdate(node);
m_nodeDao.flush();
return node;
}
示例9: testImportLegacyAssetNameRequisition
import org.opennms.netmgt.model.OnmsNode; //导入依赖的package包/类
/**
* @see http://issues.opennms.org/browse/NMS-5191
*/
@Test
@JUnitTemporaryDatabase
public void testImportLegacyAssetNameRequisition() throws Exception {
assertEquals(0, m_nodeDao.countAll());
final Resource resource = getResource("classpath:/import_legacyAssetFieldName.xml");
m_anticipator.anticipateEvent(getStarted(resource));
m_anticipator.anticipateEvent(getSuccessful(resource));
m_anticipator.anticipateEvent(getNodeAdded());
m_anticipator.anticipateEvent(getNodeGainedInterface());
m_anticipator.anticipateEvent(getNodeGainedService());
// This requisition has an asset called "maintContractNumber" which was changed in
// OpenNMS 1.10. We want to preserve backwards compatibility so make sure that the
// field still works.
m_provisioner.doImport(resource.getURL().toString(), true);
// should still import the node, just skip the asset field
assertEquals(1, m_nodeDao.countAll());
OnmsNode node = m_nodeDao.get(m_nodeDao.getNodeIds().iterator().next());
assertEquals("yellow human", node.getAssetRecord().getDescription());
assertEquals("123456", node.getAssetRecord().getMaintcontract());
}
示例10: getIpForNode
import org.opennms.netmgt.model.OnmsNode; //导入依赖的package包/类
private InetAddress getIpForNode(final OnmsNode node) {
LogUtils.debugf(this, "getIpForNode: node: %s Foreign Source: %s", node.getNodeId(), node.getForeignSource());
final OnmsIpInterface primaryInterface = node.getPrimaryInterface();
InetAddress ipaddr = InetAddressUtils.getLocalHostAddress();
if (primaryInterface == null) {
log().debug("getIpForNode: found null SNMP Primary Interface, getting interfaces");
final Set<OnmsIpInterface> ipInterfaces = node.getIpInterfaces();
for (final OnmsIpInterface onmsIpInterface : ipInterfaces) {
log().debug("getIpForNode: trying Interface with id: " + onmsIpInterface.getId());
if (InetAddressUtils.str(onmsIpInterface.getIpAddress()) != null)
ipaddr = onmsIpInterface.getIpAddress();
else
log().debug("getIpForNode: found null ip address on Interface with id: " + onmsIpInterface.getId());
}
} else {
log().debug("getIpForNode: found SNMP Primary Interface");
if (InetAddressUtils.str(primaryInterface.getIpAddress()) != null )
ipaddr = primaryInterface.getIpAddress();
else
log().debug("getIpForNode: found null ip address on Primary Interface");
}
return ipaddr;
}
示例11: getNode
import org.opennms.netmgt.model.OnmsNode; //导入依赖的package包/类
public OnmsNode getNode(Integer id) {
OnmsNode node= null;
switch (id) {
case 1: node = getNode1();
break;
case 2: node = getNode2();
break;
case 3: node = getNode3();
break;
case 4: node = getNode4();
break;
case 5: node = getNode5();
break;
case 6: node = getNode6();
break;
case 7: node = getNode7();
break;
case 8: node = getNode8();
break;
}
return node;
}
示例12: getNodesWithIpLike
import org.opennms.netmgt.model.OnmsNode; //导入依赖的package包/类
@Override
public List<OnmsNode> getNodesWithIpLike(String iplike, int serviceId) {
if (iplike == null) {
throw new IllegalArgumentException("Cannot take null parameters.");
}
OnmsCriteria nodeCrit = new OnmsCriteria(OnmsNode.class);
nodeCrit.createAlias("assetRecord", "assetRecord");
nodeCrit.createCriteria("ipInterfaces", "iface")
.createAlias("monitoredServices", "monSvcs")
.createAlias("monSvcs.serviceType", "serviceType")
.add(OnmsRestrictions.ipLike(iplike))
.add(Restrictions.eq("serviceType.id", serviceId));
nodeCrit.add(Restrictions.ne("type", "D"));
nodeCrit.addOrder(Order.asc("label"));
nodeCrit.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
return m_nodeDao.findMatching(nodeCrit);
}
示例13: addNode
import org.opennms.netmgt.model.OnmsNode; //导入依赖的package包/类
/**
* <p>addNode</p>
*
* @param node a {@link org.opennms.netmgt.model.OnmsNode} object.
* @return a {@link javax.ws.rs.core.Response} object.
*/
@POST
@Consumes(MediaType.APPLICATION_XML)
public Response addNode(final OnmsNode node) {
writeLock();
try {
LogUtils.debugf(this, "addNode: Adding node %s", node);
m_nodeDao.save(node);
try {
sendEvent(EventConstants.NODE_ADDED_EVENT_UEI, node.getId(), node.getLabel());
} catch (EventProxyException ex) {
throw getException(Status.BAD_REQUEST, ex.getMessage());
}
return Response.seeOther(m_uriInfo.getRequestUriBuilder().path(node.getNodeId()).build()).build();
} finally {
writeUnlock();
}
}
示例14: updateSnmpInterfaceData
import org.opennms.netmgt.model.OnmsNode; //导入依赖的package包/类
/**
* <p>updateSnmpInterfaceData</p>
*
* @param node a {@link org.opennms.netmgt.model.OnmsNode} object.
* @param ifIndex a {@link java.lang.Integer} object.
*/
public void updateSnmpInterfaceData(OnmsNode node, Integer ifIndex) {
// first look to see if an snmpIf was created already
OnmsSnmpInterface snmpIf = node.getSnmpInterfaceWithIfIndex(ifIndex);
if (snmpIf == null) {
// if not then create one
snmpIf = new OnmsSnmpInterface(node, ifIndex);
}
// IfTable Attributes
snmpIf.setIfType(getIfType(ifIndex));
snmpIf.setIfAdminStatus(getAdminStatus(ifIndex));
snmpIf.setIfDescr(getIfDescr(ifIndex));
snmpIf.setIfSpeed(getIfSpeed(ifIndex));
snmpIf.setPhysAddr(getPhysAddr(ifIndex));
}
示例15: addSnmpInterface
import org.opennms.netmgt.model.OnmsNode; //导入依赖的package包/类
/**
* <p>addSnmpInterface</p>
*
* @param nodeCriteria a {@link java.lang.String} object.
* @param snmpInterface a {@link org.opennms.netmgt.model.OnmsSnmpInterface} object.
* @return a {@link javax.ws.rs.core.Response} object.
*/
@POST
@Consumes(MediaType.APPLICATION_XML)
public Response addSnmpInterface(@PathParam("nodeCriteria") final String nodeCriteria, final OnmsSnmpInterface snmpInterface) {
writeLock();
try {
final OnmsNode node = m_nodeDao.get(nodeCriteria);
if (node == null) throw getException(Status.BAD_REQUEST, "addSnmpInterface: can't find node " + nodeCriteria);
if (snmpInterface == null) throw getException(Status.BAD_REQUEST, "addSnmpInterface: SNMP interface object cannot be null");
LogUtils.debugf(this, "addSnmpInterface: adding interface %s", snmpInterface);
node.addSnmpInterface(snmpInterface);
if (snmpInterface.getPrimaryIpInterface() != null) {
final OnmsIpInterface iface = snmpInterface.getPrimaryIpInterface();
iface.setSnmpInterface(snmpInterface);
// TODO Add important events here
}
m_snmpInterfaceDao.save(snmpInterface);
final Integer ifIndex = snmpInterface.getIfIndex();
return Response.seeOther(getRedirectUri(m_uriInfo, ifIndex)).build();
} finally {
writeUnlock();
}
}