use of org.opennms.netmgt.dao.api.NodeDao in project opennms by OpenNMS.
the class MinionHeartBeatIT method minionHeartBeatTestForLastUpdated.
@Test
public void minionHeartBeatTestForLastUpdated() {
Date startOfTest = new Date();
InetSocketAddress pgsql = m_testEnvironment.getServiceAddress(ContainerAlias.POSTGRES, 5432);
HibernateDaoFactory daoFactory = new HibernateDaoFactory(pgsql);
MinionDao minionDao = daoFactory.getDao(MinionDaoHibernate.class);
NodeDao nodeDao = daoFactory.getDao(NodeDaoHibernate.class);
// The heartbeat runs every minute so if we miss the first one, poll long enough
// to catch the next one
await().atMost(90, SECONDS).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(minionDao, new CriteriaBuilder(OnmsMinion.class).ge("lastUpdated", startOfTest).toCriteria()), greaterThan(0));
await().atMost(180, SECONDS).pollInterval(5, SECONDS).until(DaoUtils.countMatchingCallable(nodeDao, new CriteriaBuilder(OnmsNode.class).eq("foreignSource", "Minions").eq("foreignId", "00000000-0000-0000-0000-000000ddba11").toCriteria()), equalTo(1));
Assert.assertEquals("MINION", nodeDao.get("Minions:00000000-0000-0000-0000-000000ddba11").getLocation().getLocationName());
}
use of org.opennms.netmgt.dao.api.NodeDao in project opennms by OpenNMS.
the class AbstractVmwareMonitor method getRuntimeAttributes.
@Override
public Map<String, Object> getRuntimeAttributes(MonitoredService svc, Map<String, Object> parameters) {
if (m_nodeDao == null) {
m_nodeDao = BeanUtils.getBean("daoContext", "nodeDao", NodeDao.class);
}
if (m_vmwareConfigDao == null) {
m_vmwareConfigDao = BeanUtils.getBean("daoContext", "vmwareConfigDao", VmwareConfigDao.class);
}
final OnmsNode onmsNode = m_nodeDao.get(svc.getNodeId());
if (onmsNode == null) {
throw new IllegalArgumentException("No node found with ID: " + svc.getNodeId());
}
// retrieve the assets
final String vmwareManagementServer = onmsNode.getAssetRecord().getVmwareManagementServer();
final String vmwareManagedEntityType = onmsNode.getAssetRecord().getVmwareManagedEntityType();
final String vmwareManagedObjectId = onmsNode.getForeignId();
String vmwareMangementServerUsername = null;
String vmwareMangementServerPassword = null;
final Map<String, VmwareServer> serverMap = m_vmwareConfigDao.getServerMap();
if (serverMap == null) {
logger.error("Error getting vmware-config.xml's server map.");
} else {
final VmwareServer vmwareServer = serverMap.get(vmwareManagementServer);
if (vmwareServer == null) {
logger.error("Error getting credentials for VMware management server '{}'.", vmwareManagementServer);
} else {
vmwareMangementServerUsername = vmwareServer.getUsername();
vmwareMangementServerPassword = vmwareServer.getPassword();
}
}
return new ImmutableMap.Builder<String, Object>().put(VMWARE_MANAGEMENT_SERVER_KEY, vmwareManagementServer).put(VMWARE_MANAGED_ENTITY_TYPE_KEY, vmwareManagedEntityType).put(VMWARE_MANAGED_OBJECT_ID_KEY, vmwareManagedObjectId).put(VMWARE_MANAGEMENT_SERVER_USERNAME_KEY, vmwareMangementServerUsername).put(VMWARE_MANAGEMENT_SERVER_PASSWORD_KEY, vmwareMangementServerPassword).build();
}
use of org.opennms.netmgt.dao.api.NodeDao in project opennms by OpenNMS.
the class VmwareCimCollectorComplianceTest method getRequiredBeans.
@Override
public Map<String, Object> getRequiredBeans() {
OnmsNode node = mock(OnmsNode.class, RETURNS_DEEP_STUBS);
NodeDao nodeDao = mock(NodeDao.class);
when(nodeDao.get(anyInt())).thenReturn(node);
when(node.getAssetRecord().getVmwareManagementServer()).thenReturn("mdx");
when(node.getAssetRecord().getVmwareManagedEntityType()).thenReturn("tsx");
when(node.getForeignId()).thenReturn("rsx");
VmwareCimCollection collection = new VmwareCimCollection();
VmwareCimDatacollectionConfigDao vmwareCimDatacollectionConfigDao = mock(VmwareCimDatacollectionConfigDao.class);
when(vmwareCimDatacollectionConfigDao.getVmwareCimCollection(COLLECTION)).thenReturn(collection);
when(vmwareCimDatacollectionConfigDao.getRrdRepository(COLLECTION)).thenReturn(new RrdRepository());
VmwareServer vmwareServer = new VmwareServer();
vmwareServer.setHostname(InetAddrUtils.getLocalHostAddress().getCanonicalHostName());
Map<String, VmwareServer> serverMap = new ImmutableMap.Builder<String, VmwareServer>().put("mdx", vmwareServer).build();
VmwareConfigDao vmwareConfigDao = mock(VmwareConfigDao.class);
when(vmwareConfigDao.getServerMap()).thenReturn(serverMap);
return new ImmutableMap.Builder<String, Object>().put("nodeDao", nodeDao).put("vmwareCimDatacollectionConfigDao", vmwareCimDatacollectionConfigDao).put("vmwareConfigDao", vmwareConfigDao).build();
}
use of org.opennms.netmgt.dao.api.NodeDao in project opennms by OpenNMS.
the class AclUtils method getNodeAccessChecker.
/**
* <p>getNodeAccessChecker</p>
*
* @param sc a {@link javax.servlet.ServletContext} object.
* @return a {@link org.opennms.web.springframework.security.AclUtils.NodeAccessChecker} object.
*/
public static NodeAccessChecker getNodeAccessChecker(ServletContext sc) {
if (!shouldFilter(SecurityContextHolder.getContext().getAuthentication().getAuthorities()))
return new NonFilteringNodeAccessChecker();
ApplicationContext ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(sc);
NodeDao dao = ctx.getBean("nodeDao", NodeDao.class);
return new SetBasedNodeAccessChecker(dao.getNodeIds());
}
use of org.opennms.netmgt.dao.api.NodeDao in project opennms by OpenNMS.
the class WSManCollectorComplianceTest method getRequiredBeans.
public Map<String, Object> getRequiredBeans() {
OnmsNode node = mock(OnmsNode.class, RETURNS_DEEP_STUBS);
NodeDao nodeDao = mock(NodeDao.class);
when(nodeDao.get(anyInt())).thenReturn(node);
Definition agentConfig = new Definition();
WSManConfigDao wsManConfigDao = mock(WSManConfigDao.class);
when(wsManConfigDao.getAgentConfig(InetAddrUtils.getLocalHostAddress())).thenReturn(agentConfig);
WsmanDatacollectionConfig config = new WsmanDatacollectionConfig();
config.setRrdRepository("target");
Collection collection = new Collection();
collection.setRrd(new Rrd());
WSManDataCollectionConfigDao wsManDataCollectionConfigDao = mock(WSManDataCollectionConfigDao.class);
when(wsManDataCollectionConfigDao.getCollectionByName(COLLECTION)).thenReturn(collection);
when(wsManDataCollectionConfigDao.getConfig()).thenReturn(config);
return new ImmutableMap.Builder<String, Object>().put("nodeDao", nodeDao).put("wsManConfigDao", wsManConfigDao).put("wsManDataCollectionConfigDao", wsManDataCollectionConfigDao).build();
}
Aggregations