use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class NodeMapQueryLink method execute.
@Override
public void execute(final List<VertexRef> targets, final OperationContext operationContext) {
final Collection<VertexRef> availableNodes = m_geoAssetProvider.getNodesWithCoordinates();
final StringBuilder sb = new StringBuilder();
sb.append(VaadinServlet.getCurrent().getServletContext().getContextPath());
sb.append("/node-maps#search/nodeId%20in%20");
final List<String> nodeIds = new ArrayList<>();
for (final VertexRef ref : targets) {
if (availableNodes.contains(ref)) {
nodeIds.add(ref.getId());
}
}
final Iterator<String> i = nodeIds.iterator();
while (i.hasNext()) {
sb.append(i.next());
if (i.hasNext()) {
sb.append(",");
}
}
final String redirectUrl = sb.toString();
LOG.info("redirecting to: " + redirectUrl);
final UI ui = operationContext.getMainWindow();
ui.getPage().getJavaScript().execute("window.location = '" + redirectUrl + "';");
}
use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class NodeMapsApplication method init.
@Override
protected void init(final VaadinRequest vaadinRequest) {
m_request = vaadinRequest;
LOG.debug("initializing");
final VaadinApplicationContextImpl context = new VaadinApplicationContextImpl();
final UI currentUI = UI.getCurrent();
context.setSessionId(currentUI.getSession().getSession().getId());
context.setUiId(currentUI.getUIId());
context.setUsername(vaadinRequest.getRemoteUser());
Assert.notNull(m_alarmTable);
Assert.notNull(m_nodeTable);
final String searchString = vaadinRequest.getParameter("search");
final Integer maxClusterRadius = Integer.getInteger("gwt.maxClusterRadius", 350);
LOG.info("Starting search string: {}, max cluster radius: {}", searchString, maxClusterRadius);
m_alarmTable.setVaadinApplicationContext(context);
final EventProxy eventProxy = new EventProxy() {
@Override
public <T> void fireEvent(final T eventObject) {
LOG.debug("got event: {}", eventObject);
if (eventObject instanceof VerticesUpdateEvent) {
final VerticesUpdateEvent event = (VerticesUpdateEvent) eventObject;
final List<Integer> nodeIds = new ArrayList<>();
for (final VertexRef ref : event.getVertexRefs()) {
if ("nodes".equals(ref.getNamespace()) && ref.getId() != null) {
nodeIds.add(Integer.valueOf(ref.getId()));
}
}
m_nodeMapComponent.setSelectedNodes(nodeIds);
return;
}
LOG.warn("Unsure how to deal with event: {}", eventObject);
}
@Override
public <T> void addPossibleEventConsumer(final T possibleEventConsumer) {
LOG.debug("(ignoring) add consumer: {}", possibleEventConsumer);
/* throw new UnsupportedOperationException("Not yet implemented!"); */
}
};
m_alarmTable.setEventProxy(eventProxy);
m_nodeTable.setEventProxy(eventProxy);
createMapPanel(searchString, maxClusterRadius);
createRootLayout();
addRefresher();
// Notify the user if no tileserver url or options are set
if (!configuration.isValid()) {
new InvalidConfigurationWindow(configuration).open();
}
}
use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class GraphMLMetaTopologyProvider method reload.
public void reload() throws IOException, InvalidGraphException {
graphsByNamespace.clear();
oppositeVertices.clear();
rawGraphsByNamespace.clear();
if (graphMLFile == null) {
LOG.warn("No graph defined");
return;
}
if (!graphMLFile.exists()) {
LOG.warn("No graph found at location " + graphMLFile.toString());
return;
}
try (InputStream input = new FileInputStream(graphMLFile)) {
final GraphML graphML = GraphMLReader.read(input);
validate(graphML);
for (GraphMLGraph eachGraph : graphML.getGraphs()) {
final GraphMLTopologyProvider topoProvider = new GraphMLTopologyProvider(this, eachGraph, m_serviceAccessor);
final VertexHopGraphProvider vertexHopGraphProvider = new VertexHopGraphProvider(topoProvider);
graphsByNamespace.put(topoProvider.getNamespace(), vertexHopGraphProvider);
rawGraphsByNamespace.put(topoProvider.getNamespace(), topoProvider);
}
for (GraphMLGraph eachGraph : graphML.getGraphs()) {
for (org.opennms.features.graphml.model.GraphMLEdge eachEdge : eachGraph.getEdges()) {
final VertexRef sourceVertex = getVertex(eachEdge.getSource());
final VertexRef targetVertex = getVertex(eachEdge.getTarget());
if (!sourceVertex.getNamespace().equals(targetVertex.getNamespace())) {
List<VertexRef> opposites = oppositeVertices.get(sourceVertex);
if (opposites == null) {
opposites = Lists.newArrayList();
oppositeVertices.put(sourceVertex, opposites);
}
opposites.add(targetVertex);
}
}
}
this.breadcrumbStrategy = getBreadcrumbStrategy(graphML);
}
}
use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class GraphMLPropagateVertexStatusProvider method getStatusForVertices.
@Override
public Map<? extends VertexRef, ? extends Status> getStatusForVertices(final VertexProvider vertexProvider, final Collection<VertexRef> vertices, final Criteria[] criteria) {
final List<Criteria> criteriaList = Lists.newArrayList(criteria);
final LoopDetectionCriteria loopDetectionCriteria = Iterables.tryFind(criteriaList, c -> c instanceof LoopDetectionCriteria).transform(c -> (LoopDetectionCriteria) c).or(LoopDetectionCriteria::new);
// Build map from namespace to opposite vertices
final Multimap<String, VertexRef> oppositeVertices = HashMultimap.create();
for (final VertexRef sourceVertex : vertices) {
// Filter out loops
if (loopDetectionCriteria.contains(sourceVertex)) {
LOG.error("Loop detected with: {}:{}", sourceVertex.getNamespace(), sourceVertex.getId());
continue;
}
for (VertexRef targetVertex : this.provider.getOppositeVertices(sourceVertex)) {
oppositeVertices.put(targetVertex.getNamespace(), targetVertex);
}
}
// Replace loop detection criteria with extended one
criteriaList.remove(loopDetectionCriteria);
criteriaList.add(loopDetectionCriteria.with(vertices));
// Find and call status provider for each namespace and get result per opposite vertex
final Map<VertexRef, Status> targetStatuses = Maps.newHashMap();
try {
final Collection<ServiceReference<StatusProvider>> statusProviderReferences = this.bundleContext.getServiceReferences(StatusProvider.class, null);
for (final ServiceReference<StatusProvider> statusProviderReference : statusProviderReferences) {
try {
final StatusProvider statusProvider = bundleContext.getService(statusProviderReference);
for (final Map.Entry<String, Collection<VertexRef>> e : oppositeVertices.asMap().entrySet()) {
if (statusProvider.contributesTo(e.getKey())) {
targetStatuses.putAll(statusProvider.getStatusForVertices(this.provider.getGraphProviderBy(e.getKey()), e.getValue(), criteriaList.toArray(new Criteria[0])));
}
}
} finally {
bundleContext.ungetService(statusProviderReference);
}
}
} catch (final InvalidSyntaxException e) {
}
// Merge statuses from targets to sources
final Map<VertexRef, GraphMLVertexStatus> statuses = Maps.newHashMap();
for (final VertexRef sourceVertex : vertices) {
GraphMLVertexStatus mergedStatus = new GraphMLVertexStatus();
for (VertexRef targetVertex : this.provider.getOppositeVertices(sourceVertex)) {
if (targetStatuses.containsKey(targetVertex)) {
mergedStatus = GraphMLVertexStatus.merge(mergedStatus, (GraphMLVertexStatus) targetStatuses.get(targetVertex));
}
}
statuses.put(sourceVertex, mergedStatus);
}
return statuses;
}
use of org.opennms.features.topology.api.topo.VertexRef in project opennms by OpenNMS.
the class GraphMLScriptVertexStatusProvider method getStatusForVertices.
@Override
public Map<? extends VertexRef, ? extends Status> getStatusForVertices(final VertexProvider vertexProvider, final Collection<VertexRef> vertices, final Criteria[] criteria) {
// All vertices for the current vertexProvider
final List<GraphMLVertex> graphMLVertices = vertices.stream().filter(eachVertex -> contributesTo(eachVertex.getNamespace()) && eachVertex instanceof GraphMLVertex).map(eachVertex -> (GraphMLVertex) eachVertex).collect(Collectors.toList());
// Alarm summary for each node id
final Map<Integer, AlarmSummary> nodeIdToAlarmSummaryMap = alarmSummaryWrapper.getAlarmSummaries(Lists.transform(graphMLVertices, AbstractVertex::getNodeID)).stream().collect(Collectors.toMap(AlarmSummary::getNodeId, Function.identity()));
// Calculate status via scripts
return serviceAccessor.getTransactionOperations().execute(t -> this.scripting.compute(graphMLVertices.stream(), (vertex) -> {
final SimpleBindings bindings = new SimpleBindings();
bindings.put("vertex", vertex);
if (vertex.getNodeID() != null) {
bindings.put("node", serviceAccessor.getNodeDao().get(vertex.getNodeID()));
bindings.put("alarmSummary", nodeIdToAlarmSummaryMap.get(vertex.getNodeID()));
}
bindings.put("measurements", new MeasurementsWrapper(serviceAccessor.getMeasurementsService()));
bindings.put("nodeDao", serviceAccessor.getNodeDao());
bindings.put("snmpInterfaceDao", serviceAccessor.getSnmpInterfaceDao());
return bindings;
}));
}
Aggregations