@Override public List<OnmsNode> doInTransaction(TransactionStatus transactionStatus) { CriteriaBuilder criteriaBuilder = new CriteriaBuilder(OnmsNode.class); List<String> parameters = new ArrayList<>(rowCategories.stream().map(OnmsCategory::getName).collect(Collectors.toList())); parameters.addAll(colCategories.stream().map(OnmsCategory::getName).collect(Collectors.toList())); Type[] types = new Type[parameters.size()]; Arrays.fill(types, Type.STRING); // Restrict on OnmsNode.nodeId criteriaBuilder.sql( createQuery("{alias}.nodeId", rowCategories, colCategories), parameters.toArray(new String[parameters.size()]), types ); return m_nodeDao.findMatching(criteriaBuilder.toCriteria()); } });
@Override public List<OnmsNode> doInTransaction(TransactionStatus transactionStatus) { CriteriaBuilder criteriaBuilder = new CriteriaBuilder(OnmsNode.class); List<String> parameters = new ArrayList<>(rowCategories.stream().map(OnmsCategory::getName).collect(Collectors.toList())); parameters.addAll(colCategories.stream().map(OnmsCategory::getName).collect(Collectors.toList())); Type[] types = new Type[parameters.size()]; Arrays.fill(types, Type.STRING); // Restrict on OnmsNode.nodeId criteriaBuilder.sql( createQuery("{alias}.nodeId", rowCategories, colCategories), parameters.toArray(new String[parameters.size()]), types ); return m_nodeDao.findMatching(criteriaBuilder.toCriteria()); } });
private List<OnmsNode> getNodes(List<Integer> ids) { if (ids == null || ids.isEmpty()) { return new ArrayList<>(); } final List<OnmsNode> nodes = nodeDao.findMatching(new CriteriaBuilder(OnmsNode.class).in("id", ids).toCriteria()); return nodes; }
private List<OnmsNode> getNodes(List<Integer> ids) { if (ids == null || ids.isEmpty()) { return new ArrayList<>(); } final List<OnmsNode> nodes = nodeDao.findMatching(new CriteriaBuilder(OnmsNode.class).in("id", ids).toCriteria()); return nodes; }
@Override public Map<Integer, Coordinates> resolve(Collection<Integer> nodeIds) { if (nodeIds == null || nodeIds.isEmpty()) { return new HashMap<>(); // nothing to do } // Lookup all nodes and gather the address string final Criteria criteria = new CriteriaBuilder(OnmsNode.class).in("id", nodeIds).toCriteria(); final Map<Integer, String> nodeIdAddressMap = nodeDao.findMatching(criteria).stream() .filter(n -> getGeoLocation(n) != null) .filter(n -> getGeoLocation(n).getLatitude() == null && getGeoLocation(n).getLongitude() == null) .filter(n -> !Strings.isNullOrEmpty(getGeoLocation(n).asAddressString())) .collect(Collectors.toMap(OnmsNode::getId, n -> n.getAssetRecord().getGeolocation().asAddressString())); return resolve(nodeIdAddressMap); }
@Override public Map<Integer, Coordinates> resolve(Collection<Integer> nodeIds) { if (nodeIds == null || nodeIds.isEmpty()) { return new HashMap<>(); // nothing to do } // Lookup all nodes and gather the address string final Criteria criteria = new CriteriaBuilder(OnmsNode.class).in("id", nodeIds).toCriteria(); final Map<Integer, String> nodeIdAddressMap = nodeDao.findMatching(criteria).stream() .filter(n -> getGeoLocation(n) != null) .filter(n -> getGeoLocation(n).getLatitude() == null && getGeoLocation(n).getLongitude() == null) .filter(n -> !Strings.isNullOrEmpty(getGeoLocation(n).asAddressString())) .collect(Collectors.toMap(OnmsNode::getId, n -> n.getAssetRecord().getGeolocation().asAddressString())); return resolve(nodeIdAddressMap); }
.distinct() .toCriteria(); final List<OnmsNode> nodes = m_nodeDao.findMatching(c); for (final OnmsNode node : nodes) { m_nodeDao.initialize(node.getLocation());
nodeCb.eq("id", onmsAlarm.getNodeId()); List<OnmsNode> nodes = m_nodeDao.findMatching(nodeCb.toCriteria());
private void dataSourceSyncWithinTransaction() { m_lock.writeLock().lock(); try { /* * Make a new list with which we'll replace the existing one, that way * if something goes wrong with the DB we won't lose whatever was already * in there */ final SortedSetMultimap<Key, Value> newAlreadyDiscovered = Multimaps.newSortedSetMultimap(Maps.newHashMap(), TreeSet::new); // Fetch all non-deleted nodes final CriteriaBuilder builder = new CriteriaBuilder(OnmsNode.class); builder.ne("type", String.valueOf(NodeType.DELETED.value())); for (OnmsNode node : m_nodeDao.findMatching(builder.toCriteria())) { for (final OnmsIpInterface iface : node.getIpInterfaces()) { // Skip deleted interfaces // TODO: Refactor the 'D' value with an enumeration if ("D".equals(iface.getIsManaged())) { continue; } LOG.debug("Adding entry: {}:{} -> {}", node.getLocation().getLocationName(), iface.getIpAddress(), node.getId()); newAlreadyDiscovered.put(new Key(node.getLocation().getLocationName(), iface.getIpAddress()), new Value(node.getId(), iface.getIsSnmpPrimary())); } } m_managedAddresses.clear(); m_managedAddresses.putAll(newAlreadyDiscovered); LOG.info("dataSourceSync: initialized list of managed IP addresses with {} members", m_managedAddresses.size()); } finally { m_lock.writeLock().unlock(); } }
/** * Adds the alarms components to a {@link com.vaadin.ui.AbstractOrderedLayout} * * @param component the component to add alarms to * @param alarms the alarms list */ private void addComponents(AbstractOrderedLayout component, List<OnmsAlarm> alarms) { if (alarms.size() == 0) { Label label = new Label("No alarms found!"); label.addStyleName("alerts-noalarms-font"); component.addComponent(label); } else { for (OnmsAlarm onmsAlarm : alarms) { OnmsNode onmsNode = null; if (onmsAlarm.getNodeId() != null) { CriteriaBuilder nodeCb = new CriteriaBuilder(OnmsNode.class); nodeCb.eq("id", onmsAlarm.getNodeId()); List<OnmsNode> nodes = m_nodeDao.findMatching(nodeCb.toCriteria()); if (nodes.size() == 1) { onmsNode = nodes.get(0); } } component.addComponent(createAlarmComponent(onmsAlarm, onmsNode)); OnmsSeverity boostSeverity = OnmsSeverity.valueOf(getDashletSpec().getParameters().get("boostSeverity")); if (onmsAlarm.getSeverity().isGreaterThanOrEqual(boostSeverity)) { boosted = true; } } } }
@Override public List<Node> findAllSnmpNode() { final List<Node> nodes = new ArrayList<Node>(); final Criteria criteria = new Criteria(OnmsNode.class); criteria.setAliases(Arrays.asList(new Alias[] { new Alias( "ipInterfaces", "iface", JoinType.LEFT_JOIN) })); criteria.addRestriction(new EqRestriction("type", NodeType.ACTIVE)); criteria.addRestriction(new EqRestriction("iface.isSnmpPrimary", PrimaryType.PRIMARY)); for (final OnmsNode node : m_nodeDao.findMatching(criteria)) { nodes.add(new Node(node.getId(), node.getLabel(), node.getPrimaryInterface().getIpAddress(), node.getSysObjectId(), node.getSysName(),node.getLocation() == null ? null : node.getLocation().getLocationName())); } return nodes; }
@Override public Node getSnmpNode(final int nodeid) { final Criteria criteria = new Criteria(OnmsNode.class); criteria.setAliases(Arrays.asList(new Alias[] { new Alias( "ipInterfaces", "iface", JoinType.LEFT_JOIN) })); criteria.addRestriction(new EqRestriction("type", NodeType.ACTIVE)); criteria.addRestriction(new EqRestriction("iface.isSnmpPrimary", PrimaryType.PRIMARY)); criteria.addRestriction(new EqRestriction("id", nodeid)); final List<OnmsNode> nodes = m_nodeDao.findMatching(criteria); if (nodes.size() > 0) { final OnmsNode node = nodes.get(0); return new Node(node.getId(), node.getLabel(), node.getPrimaryInterface().getIpAddress(), node.getSysObjectId(), node.getSysName(),node.getLocation() == null ? null : node.getLocation().getLocationName()); } else { return null; } }
onmsNodes = m_nodeDao.findMatching(criteria);
onmsNodes = m_nodeDao.findMatching(criteria);