blob: 21023fa2c9de036bbcfa914d6be89929b484be72 [file] [log] [blame]
Simon Huntd5b96732016-07-08 13:22:27 -07001/*
2 * Copyright 2016-present Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package org.onosproject.ui.impl.topo;
18
19import com.fasterxml.jackson.databind.node.ObjectNode;
20import com.google.common.collect.ImmutableSet;
21import org.onlab.osgi.ServiceDirectory;
22import org.onosproject.ui.RequestHandler;
23import org.onosproject.ui.UiConnection;
24import org.onosproject.ui.UiMessageHandler;
25import org.onosproject.ui.impl.UiWebSocket;
26import org.onosproject.ui.model.topo.UiClusterMember;
27import org.onosproject.ui.model.topo.UiRegion;
28import org.onosproject.ui.model.topo.UiTopoLayout;
29import org.slf4j.Logger;
30import org.slf4j.LoggerFactory;
31
32import java.util.Collection;
33import java.util.List;
34
35/*
36 NOTES:
37
38 The original topology view message handler was broken into two classes
39 TopologyViewMessageHandler, and TopologyViewMessageHandlerBase.
40 We do not need to follow that model necessarily. Starting with a
41 single class, and breaking it apart later if necessary.
42
43 Need to figure out the connection between this message handler and the
44 new way of doing things with UiTopoSession...
45
46 */
47
48/**
49 * Server-side component for interacting with the new "Region aware" topology
50 * view in the Web UI.
51 */
52public class Topo2ViewMessageHandler extends UiMessageHandler {
53
54 private final Logger log = LoggerFactory.getLogger(getClass());
55
56 // === Inbound event identifiers
57 private static final String TOPO2_START = "topo2Start";
58 private static final String TOPO2_STOP = "topo2Stop";
59
60 // === Outbound event identifiers
61 private static final String CURRENT_LAYOUT = "topo2CurrentLayout";
62 private static final String CURRENT_REGION = "topo2CurrentRegion";
63 private static final String ALL_INSTANCES = "topo2AllInstances";
64 private static final String TOPO_START_DONE = "topo2StartDone";
65
66 private UiTopoSession topoSession;
67 private Topo2Jsonifier t2json;
68
69
70 @Override
71 public void init(UiConnection connection, ServiceDirectory directory) {
72 super.init(connection, directory);
73
74 // get the topo session from the UiWebSocket
75 topoSession = ((UiWebSocket) connection).topoSession();
76 t2json = new Topo2Jsonifier(directory);
77 }
78
79 @Override
80 protected Collection<RequestHandler> createRequestHandlers() {
81 return ImmutableSet.of(
82 new Topo2Start(),
83 new Topo2Stop()
84 );
85 }
86
87 // ==================================================================
88
89
90 private final class Topo2Start extends RequestHandler {
91 private Topo2Start() {
92 super(TOPO2_START);
93 }
94
95 @Override
96 public void process(long sid, ObjectNode payload) {
97 // client view is ready to receive data to display; so start up
98 // server-side processing, and send over initial state
99
100 log.debug("topo2Start: {}", payload);
101
102 List<UiClusterMember> instances = topoSession.getAllInstances();
103 sendMessage(ALL_INSTANCES, t2json.instances(instances));
104
105 UiTopoLayout currentLayout = topoSession.currentLayout();
106 sendMessage(CURRENT_LAYOUT, t2json.layout(currentLayout));
107
108 UiRegion region = topoSession.getRegion(currentLayout);
109 sendMessage(CURRENT_REGION, t2json.region(region));
110
111 // TODO: send information about devices/hosts/links in non-region
112 // TODO: send information about "linked, peer" regions
113
114 sendMessage(TOPO_START_DONE, null);
115
116
117 // OLD CODE DID THE FOLLOWING...
118// addListeners();
119// sendAllInstances(null);
120// sendAllDevices();
121// sendAllLinks();
122// sendAllHosts();
123// sendTopoStartDone();
124 }
125 }
126
127 private final class Topo2Stop extends RequestHandler {
128 private Topo2Stop() {
129 super(TOPO2_STOP);
130 }
131
132 @Override
133 public void process(long sid, ObjectNode payload) {
134 // client view has gone away; so shut down server-side processing
135 // TODO: implement...
136
137 log.debug("topo2Stop: {}", payload);
138
139 // OLD CODE DID THE FOLLOWING...
140// removeListeners();
141// stopSummaryMonitoring();
142// traffic.stopMonitoring();
143 }
144 }
145
146}