Topology Overlay Archetype (uitopo) - first pass.

Change-Id: I483aca5d12f7e5bd4daf5577be5329c78e780efc
diff --git a/tools/package/archetypes/pom.xml b/tools/package/archetypes/pom.xml
index 3d99e6c..12a2322 100644
--- a/tools/package/archetypes/pom.xml
+++ b/tools/package/archetypes/pom.xml
@@ -39,6 +39,7 @@
         <module>cli</module>
         <module>ui</module>
         <module>uitab</module>
+        <module>uitopo</module>
     </modules>
 
     <build>
diff --git a/tools/package/archetypes/ui/src/main/resources/archetype-resources/src/main/resources/app/view/sampleCustom/sampleCustom.html b/tools/package/archetypes/ui/src/main/resources/archetype-resources/src/main/resources/app/view/sampleCustom/sampleCustom.html
index a0ccfb3..d3d79a1 100644
--- a/tools/package/archetypes/ui/src/main/resources/archetype-resources/src/main/resources/app/view/sampleCustom/sampleCustom.html
+++ b/tools/package/archetypes/ui/src/main/resources/archetype-resources/src/main/resources/app/view/sampleCustom/sampleCustom.html
@@ -26,7 +26,7 @@
             A message from our sponsors:
         </p>
         <p>
-            <span class="quote">{{data.message}} </span>
+            <span class="quote"> {{data.message}} </span>
         </p>
     </div>
 </div>
diff --git a/tools/package/archetypes/uitopo/pom.xml b/tools/package/archetypes/uitopo/pom.xml
new file mode 100644
index 0000000..6ed7c87
--- /dev/null
+++ b/tools/package/archetypes/uitopo/pom.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Copyright 2015 Open Networking Laboratory
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+  <modelVersion>4.0.0</modelVersion>
+
+  <parent>
+    <groupId>org.onosproject</groupId>
+    <artifactId>onos-archetypes</artifactId>
+    <version>1.4.0-SNAPSHOT</version>
+  </parent>
+
+  <artifactId>onos-uitopo-archetype</artifactId>
+  <packaging>maven-archetype</packaging>
+
+  <description>ONOS UI Topology-Overlay overlay archetype</description>
+
+</project>
diff --git a/tools/package/archetypes/uitopo/src/main/resources/META-INF/maven/archetype-metadata.xml b/tools/package/archetypes/uitopo/src/main/resources/META-INF/maven/archetype-metadata.xml
new file mode 100644
index 0000000..26a9082
--- /dev/null
+++ b/tools/package/archetypes/uitopo/src/main/resources/META-INF/maven/archetype-metadata.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  ~ Copyright 2015 Open Networking Laboratory
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+<archetype-descriptor
+        xsi:schemaLocation="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0 http://maven.apache.org/xsd/archetype-descriptor-1.0.0.xsd"
+        name="onos-uitopo" partial="true"
+        xmlns="http://maven.apache.org/plugins/maven-archetype-plugin/archetype-descriptor/1.0.0"
+        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+    <fileSets>
+        <fileSet filtered="true" packaged="true" encoding="UTF-8">
+            <directory>src/main/java</directory>
+            <includes>
+                <include>**/*.java</include>
+            </includes>
+        </fileSet>
+        <fileSet filtered="true" packaged="false" encoding="UTF-8">
+            <directory>src/main/resources</directory>
+            <includes>
+                <include>**/*.html</include>
+                <include>**/*.js</include>
+                <include>**/*.css</include>
+            </includes>
+        </fileSet>
+    </fileSets>
+</archetype-descriptor>
diff --git a/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/pom.xml b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/pom.xml
new file mode 100644
index 0000000..f0688ec
--- /dev/null
+++ b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/pom.xml
@@ -0,0 +1,140 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+  ~ Copyright 2015 Open Networking Laboratory
+  ~
+  ~ Licensed under the Apache License, Version 2.0 (the "License");
+  ~ you may not use this file except in compliance with the License.
+  ~ You may obtain a copy of the License at
+  ~
+  ~     http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing, software
+  ~ distributed under the License is distributed on an "AS IS" BASIS,
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  ~ See the License for the specific language governing permissions and
+  ~ limitations under the License.
+  -->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>${groupId}</groupId>
+    <artifactId>${artifactId}</artifactId>
+    <version>${version}</version>
+    <packaging>bundle</packaging>
+
+    <description>ONOS OSGi UI Topology-Overlay bundle archetype</description>
+    <url>http://onosproject.org</url>
+
+    <properties>
+        <onos.version>1.4.0-SNAPSHOT</onos.version>
+        <!-- Uncomment to generate ONOS app from this module.
+        <onos.app.name>org.foo.app</onos.app.name>
+        <onos.app.origin>Foo, Inc.</onos.app.origin>
+        -->
+    </properties>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-api</artifactId>
+            <version>${onos.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onlab-osgi</artifactId>
+            <version>${onos.version}</version>
+        </dependency>
+
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <version>4.11</version>
+            <scope>test</scope>
+        </dependency>
+
+        <dependency>
+            <groupId>org.onosproject</groupId>
+            <artifactId>onos-api</artifactId>
+            <version>${onos.version}</version>
+            <scope>test</scope>
+            <classifier>tests</classifier>
+        </dependency>
+
+        <dependency>
+            <groupId>org.apache.felix</groupId>
+            <artifactId>org.apache.felix.scr.annotations</artifactId>
+            <version>1.9.8</version>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+
+    <build>
+        <plugins>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-bundle-plugin</artifactId>
+                <version>2.5.3</version>
+                <extensions>true</extensions>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-compiler-plugin</artifactId>
+                <version>2.5.1</version>
+                <configuration>
+                    <source>1.8</source>
+                    <target>1.8</target>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.apache.felix</groupId>
+                <artifactId>maven-scr-plugin</artifactId>
+                <version>1.20.0</version>
+                <executions>
+                    <execution>
+                        <id>generate-scr-srcdescriptor</id>
+                        <goals>
+                            <goal>scr</goal>
+                        </goals>
+                    </execution>
+                </executions>
+                <configuration>
+                    <supportedProjectTypes>
+                        <supportedProjectType>bundle</supportedProjectType>
+                        <supportedProjectType>war</supportedProjectType>
+                    </supportedProjectTypes>
+                </configuration>
+            </plugin>
+            <plugin>
+                <groupId>org.onosproject</groupId>
+                <artifactId>onos-maven-plugin</artifactId>
+                <version>1.5</version>
+                <executions>
+                    <execution>
+                        <id>cfg</id>
+                        <phase>generate-resources</phase>
+                        <goals>
+                            <goal>cfg</goal>
+                        </goals>
+                    </execution>
+                    <execution>
+                        <id>swagger</id>
+                        <phase>generate-sources</phase>
+                        <goals>
+                            <goal>swagger</goal>
+                        </goals>
+                    </execution>
+                    <execution>
+                        <id>app</id>
+                        <phase>package</phase>
+                        <goals>
+                            <goal>app</goal>
+                        </goals>
+                    </execution>
+                </executions>
+            </plugin>
+        </plugins>
+    </build>
+
+</project>
diff --git a/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/java/AppUiTopovComponent.java b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/java/AppUiTopovComponent.java
new file mode 100644
index 0000000..5724536
--- /dev/null
+++ b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/java/AppUiTopovComponent.java
@@ -0,0 +1,88 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/*
+ * Copyright 2014,2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ${package};
+
+import com.google.common.collect.ImmutableList;
+import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
+import org.apache.felix.scr.annotations.Deactivate;
+import org.apache.felix.scr.annotations.Reference;
+import org.apache.felix.scr.annotations.ReferenceCardinality;
+import org.onosproject.ui.UiExtension;
+import org.onosproject.ui.UiExtensionService;
+import org.onosproject.ui.UiMessageHandlerFactory;
+import org.onosproject.ui.UiTopoOverlayFactory;
+import org.onosproject.ui.UiView;
+import org.onosproject.ui.UiViewHidden;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+/**
+ * Skeletal ONOS UI Topology-Overlay application component.
+ */
+@Component(immediate = true)
+public class AppUiTopovComponent {
+
+    private static final ClassLoader CL = AppUiTopovComponent.class.getClassLoader();
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
+    protected UiExtensionService uiExtensionService;
+
+    // List of application views
+    private final List<UiView> uiViews = ImmutableList.of(
+            new UiViewHidden("sampleTopov")
+    );
+
+    // Factory for UI message handlers
+    private final UiMessageHandlerFactory messageHandlerFactory =
+            () -> ImmutableList.of(
+                    new AppUiTopovMessageHandler()
+            );
+
+    // Factory for UI topology overlays
+    private final UiTopoOverlayFactory topoOverlayFactory =
+            () -> ImmutableList.of(
+                    new AppUiTopovOverlay()
+            );
+
+    // Application UI extension
+    protected UiExtension extension =
+            new UiExtension.Builder(CL, uiViews)
+                    .resourcePath("sampleTopov")
+                    .messageHandlerFactory(messageHandlerFactory)
+                    .topoOverlayFactory(topoOverlayFactory)
+                    .build();
+
+    @Activate
+    protected void activate() {
+        uiExtensionService.register(extension);
+        log.info("Started");
+    }
+
+    @Deactivate
+    protected void deactivate() {
+        uiExtensionService.unregister(extension);
+        log.info("Stopped");
+    }
+
+}
diff --git a/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/java/AppUiTopovMessageHandler.java b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/java/AppUiTopovMessageHandler.java
new file mode 100644
index 0000000..fe28186
--- /dev/null
+++ b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/java/AppUiTopovMessageHandler.java
@@ -0,0 +1,319 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/*
+ * Copyright 2014,2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ${package};
+
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import com.google.common.base.Strings;
+import com.google.common.collect.ImmutableSet;
+import org.onlab.osgi.ServiceDirectory;
+import org.onosproject.net.Device;
+import org.onosproject.net.DeviceId;
+import org.onosproject.net.Element;
+import org.onosproject.net.HostId;
+import org.onosproject.net.Link;
+import org.onosproject.net.device.DeviceService;
+import org.onosproject.net.host.HostService;
+import org.onosproject.net.link.LinkService;
+import org.onosproject.ui.RequestHandler;
+import org.onosproject.ui.UiConnection;
+import org.onosproject.ui.UiMessageHandler;
+import org.onosproject.ui.topo.Highlights;
+import org.onosproject.ui.topo.TopoJson;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.Timer;
+import java.util.TimerTask;
+
+/**
+ * Skeletal ONOS UI Topology-Overlay message handler.
+ */
+public class AppUiTopovMessageHandler extends UiMessageHandler {
+
+    private static final String SAMPLE_DISPLAY_START = "sampleDisplayStart";
+    private static final String SAMPLE_DISPLAY_UPDATE = "sampleDisplayUpdate";
+    private static final String SAMPLE_DISPLAY_STOP = "sampleDisplayStop";
+
+    private static final String ID = "id";
+    private static final String MODE = "mode";
+
+    private static final long UPDATE_PERIOD_MS = 1000;
+
+    private static final Link[] EMPTY_LINK_SET = new Link[0];
+
+    private enum Mode { IDLE, MOUSE, LINK }
+
+    private final Logger log = LoggerFactory.getLogger(getClass());
+
+    private DeviceService deviceService;
+    private HostService hostService;
+    private LinkService linkService;
+
+    private final Timer timer = new Timer("sample-overlay");
+    private TimerTask demoTask = null;
+    private Mode currentMode = Mode.IDLE;
+    private Element elementOfNote;
+    private Link[] linkSet = EMPTY_LINK_SET;
+    private int linkIndex;
+
+
+    // ===============-=-=-=-=-=-======================-=-=-=-=-=-=-================================
+
+
+    @Override
+    public void init(UiConnection connection, ServiceDirectory directory) {
+        super.init(connection, directory);
+        deviceService = directory.get(DeviceService.class);
+        hostService = directory.get(HostService.class);
+        linkService = directory.get(LinkService.class);
+    }
+
+    @Override
+    protected Collection<RequestHandler> createRequestHandlers() {
+        return ImmutableSet.of(
+                new DisplayStartHandler(),
+                new DisplayUpdateHandler(),
+                new DisplayStopHandler()
+        );
+    }
+
+    // === -------------------------
+    // === Handler classes
+
+    private final class DisplayStartHandler extends RequestHandler {
+        public DisplayStartHandler() {
+            super(SAMPLE_DISPLAY_START);
+        }
+
+        @Override
+        public void process(long sid, ObjectNode payload) {
+            String mode = string(payload, MODE);
+
+            log.debug("Start Display: mode [{}]", mode);
+            clearState();
+            clearForMode();
+
+            switch (mode) {
+                case "mouse":
+                    currentMode = Mode.MOUSE;
+                    cancelTask();
+                    sendMouseData();
+                    break;
+
+                case "link":
+                    currentMode = Mode.LINK;
+                    scheduleTask();
+                    initLinkSet();
+                    sendLinkData();
+                    break;
+
+                default:
+                    currentMode = Mode.IDLE;
+                    cancelTask();
+                    break;
+            }
+        }
+    }
+
+    private final class DisplayUpdateHandler extends RequestHandler {
+        public DisplayUpdateHandler() {
+            super(SAMPLE_DISPLAY_UPDATE);
+        }
+
+        @Override
+        public void process(long sid, ObjectNode payload) {
+            String id = string(payload, ID);
+            log.debug("Update Display: id [{}]", id);
+            if (!Strings.isNullOrEmpty(id)) {
+                updateForMode(id);
+            } else {
+                clearForMode();
+            }
+        }
+    }
+
+    private final class DisplayStopHandler extends RequestHandler {
+        public DisplayStopHandler() {
+            super(SAMPLE_DISPLAY_STOP);
+        }
+
+        @Override
+        public void process(long sid, ObjectNode payload) {
+            log.debug("Stop Display");
+            cancelTask();
+            clearState();
+            clearForMode();
+        }
+    }
+
+    // === ------------
+
+    private void clearState() {
+        currentMode = Mode.IDLE;
+        elementOfNote = null;
+        linkSet = EMPTY_LINK_SET;
+    }
+
+    private void updateForMode(String id) {
+        log.debug("host service: {}", hostService);
+        log.debug("device service: {}", deviceService);
+
+        try {
+            HostId hid = HostId.hostId(id);
+            log.debug("host id {}", hid);
+            elementOfNote = hostService.getHost(hid);
+            log.debug("host element {}", elementOfNote);
+
+        } catch (Exception e) {
+            try {
+                DeviceId did = DeviceId.deviceId(id);
+                log.debug("device id {}", did);
+                elementOfNote = deviceService.getDevice(did);
+                log.debug("device element {}", elementOfNote);
+
+            } catch (Exception e2) {
+                log.debug("Unable to process ID [{}]", id);
+                elementOfNote = null;
+            }
+        }
+
+        switch (currentMode) {
+            case MOUSE:
+                sendMouseData();
+                break;
+
+            case LINK:
+                sendLinkData();
+                break;
+
+            default:
+                break;
+        }
+
+    }
+
+    private void clearForMode() {
+        sendHighlights(new Highlights());
+    }
+
+    private void sendHighlights(Highlights highlights) {
+        sendMessage(TopoJson.highlightsMessage(highlights));
+    }
+
+
+    private void sendMouseData() {
+        if (elementOfNote != null && elementOfNote instanceof Device) {
+            DeviceId devId = (DeviceId) elementOfNote.id();
+            Set<Link> links = linkService.getDeviceEgressLinks(devId);
+            sendHighlights(fromLinks(links, devId));
+        }
+        // Note: could also process Host, if available
+    }
+
+    private Highlights fromLinks(Set<Link> links, DeviceId devId) {
+        DemoLinkMap linkMap = new DemoLinkMap();
+        if (links != null) {
+            log.debug("Processing {} links", links.size());
+            links.forEach(linkMap::add);
+        } else {
+            log.debug("No egress links found for device {}", devId);
+        }
+
+        Highlights highlights = new Highlights();
+
+        for (DemoLink dlink : linkMap.biLinks()) {
+            dlink.makeImportant().setLabel("Yo!");
+            highlights.add(dlink.highlight(null));
+        }
+        return highlights;
+    }
+
+    private void initLinkSet() {
+        Set<Link> links = new HashSet<>();
+        for (Link link : linkService.getActiveLinks()) {
+            links.add(link);
+        }
+        linkSet = links.toArray(new Link[links.size()]);
+        linkIndex = 0;
+        log.debug("initialized link set to {}", linkSet.length);
+    }
+
+    private void sendLinkData() {
+        DemoLinkMap linkMap = new DemoLinkMap();
+        for (Link link : linkSet) {
+            linkMap.add(link);
+        }
+        DemoLink dl = linkMap.add(linkSet[linkIndex]);
+        dl.makeImportant().setLabel(Integer.toString(linkIndex));
+        log.debug("sending link data (index {})", linkIndex);
+
+        linkIndex += 1;
+        if (linkIndex >= linkSet.length) {
+            linkIndex = 0;
+        }
+
+        Highlights highlights = new Highlights();
+        for (DemoLink dlink : linkMap.biLinks()) {
+            highlights.add(dlink.highlight(null));
+        }
+
+        sendHighlights(highlights);
+    }
+
+    private synchronized void scheduleTask() {
+        if (demoTask == null) {
+            log.debug("Starting up demo task...");
+            demoTask = new DisplayUpdateTask();
+            timer.schedule(demoTask, UPDATE_PERIOD_MS, UPDATE_PERIOD_MS);
+        } else {
+            log.debug("(demo task already running");
+        }
+    }
+
+    private synchronized void cancelTask() {
+        if (demoTask != null) {
+            demoTask.cancel();
+            demoTask = null;
+        }
+    }
+
+
+    private class DisplayUpdateTask extends TimerTask {
+        @Override
+        public void run() {
+            try {
+                switch (currentMode) {
+                    case LINK:
+                        sendLinkData();
+                        break;
+
+                    default:
+                        break;
+                }
+            } catch (Exception e) {
+                log.warn("Unable to process demo task: {}", e.getMessage());
+                log.debug("Oops", e);
+            }
+        }
+    }
+
+}
\ No newline at end of file
diff --git a/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/java/AppUiTopovOverlay.java b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/java/AppUiTopovOverlay.java
new file mode 100644
index 0000000..9899982
--- /dev/null
+++ b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/java/AppUiTopovOverlay.java
@@ -0,0 +1,75 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/*
+ * Copyright 2014,2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ${package};
+
+import org.onosproject.ui.UiTopoOverlay;
+import org.onosproject.ui.topo.ButtonId;
+import org.onosproject.ui.topo.PropertyPanel;
+import org.onosproject.ui.topo.TopoConstants.CoreButtons;
+import org.onosproject.ui.topo.TopoConstants.Glyphs;
+
+import static org.onosproject.ui.topo.TopoConstants.Properties.*;
+
+/**
+ * Our topology overlay.
+ */
+public class AppUiTopovOverlay extends UiTopoOverlay {
+
+    // NOTE: this must match the ID defined in sampleTopov.js
+    private static final String OVERLAY_ID = "meowster-overlay";
+
+    private static final String MY_TITLE = "My App Rocks!";
+    private static final String MY_VERSION = "Beta-1.0.0042";
+    private static final String MY_DEVICE_TITLE = "I changed the title";
+
+    private static final ButtonId FOO_BUTTON = new ButtonId("foo");
+    private static final ButtonId BAR_BUTTON = new ButtonId("bar");
+
+    public AppUiTopovOverlay() {
+        super(OVERLAY_ID);
+    }
+
+
+    @Override
+    public void modifySummary(PropertyPanel pp) {
+        pp.title(MY_TITLE)
+                .typeId(Glyphs.CROWN)
+                .removeProps(
+                        TOPOLOGY_SSCS,
+                        INTENTS,
+                        TUNNELS,
+                        FLOWS,
+                        VERSION
+                )
+                .addProp(VERSION, MY_VERSION);
+    }
+
+    @Override
+    public void modifyDeviceDetails(PropertyPanel pp) {
+        pp.title(MY_DEVICE_TITLE);
+        pp.removeProps(LATITUDE, LONGITUDE);
+
+        pp.addButton(FOO_BUTTON)
+                .addButton(BAR_BUTTON);
+
+        pp.removeButtons(CoreButtons.SHOW_PORT_VIEW)
+                .removeButtons(CoreButtons.SHOW_GROUP_VIEW);
+    }
+
+}
diff --git a/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/java/DemoLink.java b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/java/DemoLink.java
new file mode 100644
index 0000000..4a97f7b
--- /dev/null
+++ b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/java/DemoLink.java
@@ -0,0 +1,57 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/*
+ * Copyright 2014,2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ${package};
+
+import org.onosproject.net.Link;
+import org.onosproject.net.LinkKey;
+import org.onosproject.ui.topo.BiLink;
+import org.onosproject.ui.topo.LinkHighlight;
+import org.onosproject.ui.topo.LinkHighlight.Flavor;
+
+/**
+ * Our demo concrete class of a bi-link. We give it state so we can decide
+ * how to create link highlights.
+ */
+public class DemoLink extends BiLink {
+
+    private boolean important = false;
+    private String label = null;
+
+    public DemoLink(LinkKey key, Link link) {
+        super(key, link);
+    }
+
+    public DemoLink makeImportant() {
+        important = true;
+        return this;
+    }
+
+    public DemoLink setLabel(String label) {
+        this.label = label;
+        return this;
+    }
+
+    @Override
+    public LinkHighlight highlight(Enum<?> anEnum) {
+        Flavor flavor = important ? Flavor.PRIMARY_HIGHLIGHT
+                : Flavor.SECONDARY_HIGHLIGHT;
+        return new LinkHighlight(this.linkId(), flavor)
+                .setLabel(label);
+    }
+}
diff --git a/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/java/DemoLinkMap.java b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/java/DemoLinkMap.java
new file mode 100644
index 0000000..cc13d99
--- /dev/null
+++ b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/java/DemoLinkMap.java
@@ -0,0 +1,33 @@
+#set( $symbol_pound = '#' )
+#set( $symbol_dollar = '$' )
+#set( $symbol_escape = '\' )
+/*
+ * Copyright 2014,2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package ${package};
+
+import org.onosproject.net.Link;
+import org.onosproject.net.LinkKey;
+import org.onosproject.ui.topo.BiLinkMap;
+
+/**
+ * Our concrete link map.
+ */
+public class DemoLinkMap extends BiLinkMap<DemoLink> {
+    @Override
+    protected DemoLink create(LinkKey linkKey, Link link) {
+        return new DemoLink(linkKey, link);
+    }
+}
diff --git a/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/resources/app/view/sampleTopov/sampleTopov.css b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/resources/app/view/sampleTopov/sampleTopov.css
new file mode 100644
index 0000000..cbf460f
--- /dev/null
+++ b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/resources/app/view/sampleTopov/sampleTopov.css
@@ -0,0 +1,2 @@
+/* css for sample app topology overlay  */
+
diff --git a/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/resources/app/view/sampleTopov/sampleTopov.html b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/resources/app/view/sampleTopov/sampleTopov.html
new file mode 100644
index 0000000..b1c9acb
--- /dev/null
+++ b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/resources/app/view/sampleTopov/sampleTopov.html
@@ -0,0 +1,4 @@
+<!-- partial HTML -->
+<div id="ov-sample-topov">
+    <p>This is a hidden view .. just a placeholder to house the javascript</p>
+</div>
diff --git a/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/resources/app/view/sampleTopov/sampleTopovDemo.js b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/resources/app/view/sampleTopov/sampleTopovDemo.js
new file mode 100644
index 0000000..0b82d81
--- /dev/null
+++ b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/resources/app/view/sampleTopov/sampleTopovDemo.js
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2015 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/*
+ Sample Demo module. This contains the "business logic" for the topology
+ overlay that we are implementing.
+ */
+
+(function () {
+    'use strict';
+
+    // injected refs
+    var $log, fs, flash, wss;
+
+    // constants
+    var displayStart = 'sampleDisplayStart',
+        displayUpdate = 'sampleDisplayUpdate',
+        displayStop = 'sampleDisplayStop';
+
+    // internal state
+    var currentMode = null;
+
+
+    // === ---------------------------
+    // === Helper functions
+
+    function sendDisplayStart(mode) {
+        wss.sendEvent(displayStart, {
+            mode: mode
+        });
+    }
+
+    function sendDisplayUpdate(what) {
+        wss.sendEvent(displayUpdate, {
+            id: what ? what.id : ''
+        });
+    }
+
+    function sendDisplayStop() {
+        wss.sendEvent(displayStop);
+    }
+
+    // === ---------------------------
+    // === Main API functions
+
+    function startDisplay(mode) {
+        if (currentMode === mode) {
+            $log.debug('(in mode', mode, 'already)');
+        } else {
+            currentMode = mode;
+            sendDisplayStart(mode);
+            flash.flash('Starting display mode: ' + mode);
+        }
+    }
+
+    function updateDisplay(m) {
+        if (currentMode) {
+            sendDisplayUpdate(m);
+        }
+    }
+
+    function stopDisplay() {
+        if (currentMode) {
+            currentMode = null;
+            sendDisplayStop();
+            flash.flash('Canceling display mode');
+            return true;
+        }
+        return false;
+    }
+
+    // === ---------------------------
+    // === Module Factory Definition
+
+    angular.module('ovSampleTopov', [])
+        .factory('SampleTopovDemoService',
+        ['$log', 'FnService', 'FlashService', 'WebSocketService',
+
+        function (_$log_, _fs_, _flash_, _wss_) {
+            $log = _$log_;
+            fs = _fs_;
+            flash = _flash_;
+            wss = _wss_;
+
+            return {
+                startDisplay: startDisplay,
+                updateDisplay: updateDisplay,
+                stopDisplay: stopDisplay
+            };
+        }]);
+}());
diff --git a/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/resources/app/view/sampleTopov/sampleTopovOverlay.js b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/resources/app/view/sampleTopov/sampleTopovOverlay.js
new file mode 100644
index 0000000..44a1e23
--- /dev/null
+++ b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/resources/app/view/sampleTopov/sampleTopovOverlay.js
@@ -0,0 +1,157 @@
+// sample topology overlay - client side
+//
+// This is the glue that binds our business logic (in sampleTopovDemo.js)
+// to the overlay framework.
+
+(function () {
+    'use strict';
+
+    // injected refs
+    var $log, tov, stds;
+
+    // internal state should be kept in the service module (not here)
+
+    // our overlay definition
+    var overlay = {
+        // NOTE: this must match the ID defined in AppUiTopoOverlay
+        overlayId: 'meowster-overlay',
+        glyphId: '*star4',
+        tooltip: 'Sample Meowster Topo Overlay',
+
+        // These glyphs get installed using the overlayId as a prefix.
+        // e.g. 'star4' is installed as 'meowster-overlay-star4'
+        // They can be referenced (from this overlay) as '*star4'
+        // That is, the '*' prefix stands in for 'meowster-overlay-'
+        glyphs: {
+            star4: {
+                vb: '0 0 8 8',
+                d: 'M1,4l2,-1l1,-2l1,2l2,1l-2,1l-1,2l-1,-2z'
+            },
+            banner: {
+                vb: '0 0 6 6',
+                d: 'M1,1v4l2,-2l2,2v-4z'
+            }
+        },
+
+        activate: function () {
+            $log.debug("Sample topology overlay ACTIVATED");
+        },
+        deactivate: function () {
+            stds.stopDisplay();
+            $log.debug("Sample topology overlay DEACTIVATED");
+        },
+
+        // detail panel button definitions
+        buttons: {
+            foo: {
+                gid: 'chain',
+                tt: 'A FOO action',
+                cb: function (data) {
+                    $log.debug('FOO action invoked with data:', data);
+                }
+            },
+            bar: {
+                gid: '*banner',
+                tt: 'A BAR action',
+                cb: function (data) {
+                    $log.debug('BAR action invoked with data:', data);
+                }
+            }
+        },
+
+        // Key bindings for traffic overlay buttons
+        // NOTE: fully qual. button ID is derived from overlay-id and key-name
+        keyBindings: {
+            0: {
+                cb: function () { stds.stopDisplay(); },
+                tt: 'Cancel Display Mode',
+                gid: 'xMark'
+            },
+            V: {
+                cb: function () { stds.startDisplay('mouse'); },
+                tt: 'Start Mouse Mode',
+                gid: '*banner'
+            },
+            F: {
+                cb: function () { stds.startDisplay('link'); },
+                tt: 'Start Link Mode',
+                gid: 'chain'
+            },
+            G: {
+                cb: buttonCallback,
+                tt: 'Uses the G key',
+                gid: 'crown'
+            },
+            T: {
+                cb: buttonCallback,
+                tt: 'Uses the T key',
+                gid: 'switch'
+            },
+            R: {
+                cb: buttonCallback,
+                tt: 'Uses the R key',
+                gid: 'endstation'
+            },
+
+            _keyOrder: [
+                '0', 'V', 'F', 'G', 'T', 'R'
+            ]
+
+            // NOTE: T and R should be rejected (not installed)
+            //       T is reserved for 'toggle Theme'
+            //       R is reserved for 'Reset pan and zoom'
+        },
+
+        hooks: {
+            // hook for handling escape key
+            // Must return true to consume ESC, false otherwise.
+            escape: function () {
+                // Must return true to consume ESC, false otherwise.
+                return stds.stopDisplay();
+            },
+
+            // hooks for when the selection changes...
+            empty: function () {
+                selectionCallback('empty');
+            },
+            single: function (data) {
+                selectionCallback('single', data);
+            },
+            multi: function (selectOrder) {
+                selectionCallback('multi', selectOrder);
+                tov.addDetailButton('foo');
+                tov.addDetailButton('bar');
+            },
+            mouseover: function (m) {
+                // m has id, class, and type properties
+                $log.debug('mouseover:', m);
+                stds.updateDisplay(m);
+            },
+            mouseout: function () {
+                $log.debug('mouseout');
+                stds.updateDisplay();
+            }
+        }
+    };
+
+
+    function buttonCallback(x) {
+        $log.debug('Toolbar-button callback', x);
+    }
+
+    function selectionCallback(x, d) {
+        $log.debug('Selection callback', x, d);
+    }
+
+    // invoke code to register with the overlay service
+    angular.module('ovSampleTopov')
+        .run(['$log', 'TopoOverlayService', 'SampleTopovDemoService',
+
+        function (_$log_, _tov_, _stds_) {
+            $log = _$log_;
+            tov = _tov_;
+            stds = _stds_;
+            tov.register(overlay);
+        }]);
+
+}());
diff --git a/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/resources/sampleTopov/css.html b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/resources/sampleTopov/css.html
new file mode 100644
index 0000000..0ed6f53
--- /dev/null
+++ b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/resources/sampleTopov/css.html
@@ -0,0 +1 @@
+<link rel="stylesheet" href="app/view/sampleTopov/sampleTopov.css">
\ No newline at end of file
diff --git a/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/resources/sampleTopov/js.html b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/resources/sampleTopov/js.html
new file mode 100644
index 0000000..4fed1f0
--- /dev/null
+++ b/tools/package/archetypes/uitopo/src/main/resources/archetype-resources/src/main/resources/sampleTopov/js.html
@@ -0,0 +1,2 @@
+<script src="app/view/sampleTopov/sampleTopovDemo.js"></script>
+<script src="app/view/sampleTopov/sampleTopovOverlay.js"></script>
\ No newline at end of file
diff --git a/tools/package/archetypes/uitopo/src/test/resources/projects/basic/archetype.properties b/tools/package/archetypes/uitopo/src/test/resources/projects/basic/archetype.properties
new file mode 100644
index 0000000..a1213b4
--- /dev/null
+++ b/tools/package/archetypes/uitopo/src/test/resources/projects/basic/archetype.properties
@@ -0,0 +1,21 @@
+#
+# Copyright 2014 Open Networking Laboratory
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+#Thu Dec 04 09:24:50 PST 2014
+package=it.pkg
+version=0.1-SNAPSHOT
+groupId=archetype.it
+artifactId=basic
diff --git a/tools/package/archetypes/uitopo/src/test/resources/projects/basic/goal.txt b/tools/package/archetypes/uitopo/src/test/resources/projects/basic/goal.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/tools/package/archetypes/uitopo/src/test/resources/projects/basic/goal.txt