Skip to content

Commit

Permalink
Merge pull request #1142 from OpenNMS/jira/NMS-8510
Browse files Browse the repository at this point in the history
NMS-8510: Introduce TopologyLinkBuilder to relieably create links
  • Loading branch information
Jesse White committed Nov 22, 2016
2 parents 90cb2b5 + 85c7134 commit 2c45ccc
Show file tree
Hide file tree
Showing 24 changed files with 410 additions and 121 deletions.
5 changes: 5 additions & 0 deletions features/bsm/vaadin-adminpage/pom.xml
Expand Up @@ -53,6 +53,11 @@
<artifactId>core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.opennms.features.topology</groupId>
<artifactId>org.opennms.features.topology.link</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.opennms.features.bsm</groupId>
<artifactId>org.opennms.features.bsm.service.api</artifactId>
Expand Down
Expand Up @@ -28,15 +28,15 @@

package org.opennms.netmgt.bsm.vaadin.adminpage;

import java.nio.charset.Charset;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.message.BasicNameValuePair;
import org.opennms.features.topology.link.Layout;
import org.opennms.features.topology.link.TopologyLinkBuilder;
import org.opennms.features.topology.link.TopologyProvider;
import org.opennms.netmgt.bsm.service.BusinessServiceManager;
import org.opennms.netmgt.bsm.service.BusinessServiceStateMachine;
import org.opennms.netmgt.bsm.service.model.BusinessService;
Expand All @@ -46,7 +46,6 @@
import org.opennms.netmgt.vaadin.core.UIHelper;

import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Lists;
import com.vaadin.data.util.BeanItem;
import com.vaadin.data.util.ContainerHierarchicalWrapper;
import com.vaadin.server.ExternalResource;
Expand Down Expand Up @@ -83,18 +82,17 @@ public Object generateCell(Table source, Object itemId, Object columnId) {
final BusinessService businessService = getItem(itemId).getBean().getBusinessService();
final Status status = stateMachine.getOperationalStatus(businessService);
if (status != null) {
// Build the query string
final List<BasicNameValuePair> urlParms = Lists.newArrayList(
new BasicNameValuePair("focus-vertices", businessService.getId().toString()),
new BasicNameValuePair("szl", "1"),
new BasicNameValuePair("layout", "Hierarchy Layout"),
new BasicNameValuePair("provider", "Business Services")
);
final String queryString = URLEncodedUtils.format(urlParms, Charset.forName("UTF-8"));
final String topologyLink = new TopologyLinkBuilder()
.focus(businessService.getId().toString())
.szl(1)
.layout(Layout.HIERARCHY)
.provider(TopologyProvider.BUSINESS_SERVICE)
.getLink();

// Generate the link
final Link link = new Link("View in Topology UI", new ExternalResource(String.format("/opennms/topology?%s", queryString)));
final Link link = new Link("View in Topology UI", new ExternalResource(topologyLink));
link.setIcon(FontAwesome.EXTERNAL_LINK_SQUARE);

// This app is typically access in an iframe, so we open the URL in a new window/tab
link.setTargetName("_blank");
layout.addComponent(link);
Expand Down
6 changes: 6 additions & 0 deletions features/topology-map/features/runtime-base/pom.xml
Expand Up @@ -66,6 +66,12 @@
<artifactId>org.opennms.features.topology.plugins.topo.history</artifactId>
<version>${project.version}</version>
</dependency>
<!-- is required to build topology links -->
<dependency>
<groupId>org.opennms.features.topology</groupId>
<artifactId>org.opennms.features.topology.link</artifactId>
<version>${project.version}</version>
</dependency>

<!-- plugins -->
<dependency>
Expand Down
Expand Up @@ -59,6 +59,11 @@
<artifactId>graph</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.opennms.features.topology</groupId>
<artifactId>org.opennms.features.topology.link</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.opennms.features.topology</groupId>
<artifactId>org.opennms.features.topology.api</artifactId>
Expand Down
Expand Up @@ -30,13 +30,14 @@

import javax.servlet.http.HttpServletRequest;

import org.opennms.features.topology.link.TopologyLinkBuilder;
import org.opennms.features.topology.link.TopologyProvider;
import org.opennms.netmgt.model.OnmsNode;
import org.opennms.web.navigate.ConditionalPageNavEntry;
import org.opennms.web.navigate.DisplayStatus;

public class TopoMapNavEntry implements ConditionalPageNavEntry {
private String m_name;
private String m_url;

@Override
public String getName() {
Expand All @@ -49,11 +50,10 @@ public void setName(final String name) {

@Override
public String getUrl() {
return m_url;
}

public void setUrl(final String url) {
m_url = url;
return new TopologyLinkBuilder()
.provider(TopologyProvider.ENLINKD)
.focus("%nodeid%")
.szl(1).getLink();
}

@Override
Expand All @@ -67,7 +67,8 @@ public DisplayStatus evaluate(final HttpServletRequest request, final Object tar
return DisplayStatus.NO_DISPLAY;
}

@Override public String toString() {
return "TopoMapNavEntry[url=" + m_url + ",name=" + m_name +"]";
@Override
public String toString() {
return "TopoMapNavEntry[url=" + getUrl() + ",name=" + m_name +"]";
}
}
Expand Up @@ -92,6 +92,7 @@
import org.opennms.features.topology.app.internal.ui.ToolbarPanel;
import org.opennms.features.topology.app.internal.ui.ToolbarPanelController;
import org.opennms.features.topology.app.internal.ui.breadcrumbs.BreadcrumbComponent;
import org.opennms.features.topology.link.TopologyLinkBuilder;
import org.opennms.osgi.EventConsumer;
import org.opennms.osgi.OnmsServiceManager;
import org.opennms.osgi.VaadinApplicationContext;
Expand Down Expand Up @@ -199,11 +200,8 @@ public class TopologyUIRequestHandler implements RequestHandler {

private final List<RequestParameterHandler> requestHandlerList;

private static final String PARAMETER_LAYOUT = "layout";
private static final String PARAMETER_FOCUS_NODES = "focusNodes";
private static final String PARAMETER_FOCUS_VERTICES = "focus-vertices";
private static final String PARAMETER_SEMANTIC_ZOOM_LEVEL = "szl";
private static final String PARAMETER_GRAPH_PROVIDER = "provider";

public static final String PARAMETER_HISTORY_FRAGMENT = "ui-fragment";

private TopologyUIRequestHandler() {
Expand Down Expand Up @@ -255,12 +253,12 @@ public void handleRequestParameter(VaadinRequest request) {
}

private boolean loadLayout(VaadinRequest request) {
String layoutName = request.getParameter(PARAMETER_LAYOUT);
String layoutName = request.getParameter(TopologyLinkBuilder.PARAMETER_LAYOUT);
return executeOperationWithLabel(layoutName);
}

private boolean loadGraphProvider(VaadinRequest request) {
String graphProviderName = request.getParameter(PARAMETER_GRAPH_PROVIDER);
String graphProviderName = request.getParameter(TopologyLinkBuilder.PARAMETER_GRAPH_PROVIDER);
return executeOperationWithLabel(graphProviderName);
}

Expand Down Expand Up @@ -289,26 +287,26 @@ private boolean loadHistoryFragment(VaadinRequest request) {
}

private boolean loadSemanticZoomLevel(VaadinRequest request) {
String szl = request.getParameter(PARAMETER_SEMANTIC_ZOOM_LEVEL);
String szl = request.getParameter(TopologyLinkBuilder.PARAMETER_SEMANTIC_ZOOM_LEVEL);
if (szl != null) {
try {
m_graphContainer.setSemanticZoomLevel(Integer.parseInt(szl));
return true;
} catch (NumberFormatException e) {
LOG.warn("Invalid SZL found in {} parameter: {}", PARAMETER_SEMANTIC_ZOOM_LEVEL, szl);
LOG.warn("Invalid SZL found in {} parameter: {}", TopologyLinkBuilder.PARAMETER_SEMANTIC_ZOOM_LEVEL, szl);
}
}
return false;
}

private boolean loadVertexHopCriteria(VaadinRequest request) {
final String nodeIds = request.getParameter(PARAMETER_FOCUS_NODES);
String vertexIdInFocus = request.getParameter(PARAMETER_FOCUS_VERTICES);
String vertexIdInFocus = request.getParameter(TopologyLinkBuilder.PARAMETER_FOCUS_VERTICES);
if (nodeIds != null && vertexIdInFocus != null) {
LOG.warn("Usage of parameter '{1}' and '{2}'. This is not supported. Skipping parameter '{2}'", PARAMETER_FOCUS_NODES, PARAMETER_FOCUS_VERTICES);
LOG.warn("Usage of parameter '{1}' and '{2}'. This is not supported. Skipping parameter '{2}'", PARAMETER_FOCUS_NODES, TopologyLinkBuilder.PARAMETER_FOCUS_VERTICES);
}
if (nodeIds != null) {
LOG.warn("Usage of deprecated parameter '{}'. Please use '{}' instead.", PARAMETER_FOCUS_NODES, PARAMETER_FOCUS_VERTICES);
LOG.warn("Usage of deprecated parameter '{}'. Please use '{}' instead.", PARAMETER_FOCUS_NODES, TopologyLinkBuilder.PARAMETER_FOCUS_VERTICES);
vertexIdInFocus = nodeIds;
}
if (vertexIdInFocus != null) {
Expand Down
Expand Up @@ -28,6 +28,7 @@

package org.opennms.features.topology.app.internal.ui;

import static org.opennms.features.topology.app.internal.TopologyUI.TopologyUIRequestHandler.PARAMETER_HISTORY_FRAGMENT;
import static org.opennms.features.topology.app.internal.ui.ToolbarPanelController.ActiveTool;

import org.opennms.features.topology.api.Callbacks;
Expand All @@ -37,7 +38,6 @@
import org.opennms.features.topology.api.SelectionListener;
import org.opennms.features.topology.api.topo.TopologyProviderInfo;
import org.opennms.features.topology.app.internal.ManualLayoutAlgorithm;
import org.opennms.features.topology.app.internal.TopologyUI;
import org.opennms.features.topology.app.internal.support.IonicIcons;
import org.opennms.features.topology.app.internal.support.LayoutManager;

Expand Down Expand Up @@ -196,10 +196,10 @@ public void buttonClick(Button.ClickEvent event) {
Button shareButton = new Button("", FontAwesome.SHARE_SQUARE_O);
shareButton.setDescription("Share");
shareButton.addClickListener((x) -> {
// create the share link
// Create the share link
String fragment = getUI().getPage().getLocation().getFragment();
String url = getUI().getPage().getLocation().toString().replace("#" + getUI().getPage().getLocation().getFragment(), "");
String shareLink = String.format("%s?%s=%s", url, TopologyUI.TopologyUIRequestHandler.PARAMETER_HISTORY_FRAGMENT, fragment);
String url = getUI().getPage().getLocation().toString().replace("#" + fragment, "");
String shareLink = String.format("%s?%s=%s", url, PARAMETER_HISTORY_FRAGMENT, fragment);

// Create the Window
Window shareWindow = new Window();
Expand Down
Expand Up @@ -426,7 +426,6 @@ http://www.osgi.org/xmlns/blueprint-ext/v1.1.0 http://aries.apache.org/schemas/b
</reference>

<bean id="topoMapsLink" class="org.opennms.features.topology.app.internal.TopoMapNavEntry">
<property name="url" value="topology?focusNodes=%nodeid%&amp;szl=1" />
<property name="name" value="View in Topology" />
</bean>

Expand Down
34 changes: 34 additions & 0 deletions features/topology-map/org.opennms.features.topology.link/pom.xml
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<parent>
<relativePath>../poms/compiled/</relativePath>
<groupId>org.opennms.features.topology.build</groupId>
<artifactId>compiled-bundle-settings</artifactId>
<version>19.0.0-SNAPSHOT</version>
</parent>
<properties>
<bundle.symbolicName>org.opennms.features.topology.link</bundle.symbolicName>
<bundle.namespace>org.opennms.features.topology.link</bundle.namespace>
</properties>
<modelVersion>4.0.0</modelVersion>
<groupId>org.opennms.features.topology</groupId>
<artifactId>org.opennms.features.topology.link</artifactId>
<name>${bundle.symbolicName}</name>
<packaging>bundle</packaging>
<dependencies>
<!--
| uncomment to add all imported (non-local) bundles to your compilation classpath
<dependency>
<type>pom</type>
<groupId>${parent.groupId}</groupId>
<artifactId>provision</artifactId>
<optional>true</optional>
</dependency>
-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
@@ -0,0 +1,66 @@
/*******************************************************************************
* This file is part of OpenNMS(R).
*
* Copyright (C) 2016 The OpenNMS Group, Inc.
* OpenNMS(R) is Copyright (C) 1999-2016 The OpenNMS Group, Inc.
*
* OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
*
* OpenNMS(R) is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* OpenNMS(R) is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with OpenNMS(R). If not, see:
* http://www.gnu.org/licenses/
*
* For more information contact:
* OpenNMS(R) Licensing <license@opennms.org>
* http://www.opennms.org/
* http://www.opennms.com/
*******************************************************************************/

package org.opennms.features.topology.link;

import java.util.Objects;

/**
* All known layout algorithms.
*/
public enum Layout {

CIRCLE("Circle Layout"),
D3("D3 Layout"),
FR("FR Layout"),
HIERARCHY("Hierarchy Layout"),
ISOM("ISOM Layout"),
KK("KK Layout"),
REAL("Real Ultimate Layout"),
SPRING("Spring Layout"),
MANUAL("Manual Layout");

private final String label;

Layout(String label) {
this.label = Objects.requireNonNull(label);
}

public String getLabel() {
return label;
}

public static Layout createFromLabel(String label) {
for (Layout eachLayout : values()) {
if (eachLayout.getLabel().equals(label)) {
return eachLayout;
}
}
return null;
}
}

0 comments on commit 2c45ccc

Please sign in to comment.