blob: b9506d2d0ee35eb8178cca5264c6f16309ac84ac [file] [log] [blame]
Jimmy Yanda878fc2016-09-02 16:32:01 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2016-present Open Networking Foundation
Jimmy Yanda878fc2016-09-02 16:32:01 -07003 *
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 */
16package org.onosproject.roadm;
17
18import com.fasterxml.jackson.databind.node.ObjectNode;
19import com.google.common.collect.ImmutableSet;
MaoLu937cf422017-03-03 23:31:46 -080020import org.onlab.osgi.ServiceDirectory;
Jimmy Yanda878fc2016-09-02 16:32:01 -070021import org.onosproject.mastership.MastershipService;
22import org.onosproject.net.AnnotationKeys;
23import org.onosproject.net.Device;
MaoLu937cf422017-03-03 23:31:46 -080024import org.onosproject.net.DeviceId;
Jimmy Yanda878fc2016-09-02 16:32:01 -070025import org.onosproject.net.device.DeviceService;
26import org.onosproject.ui.RequestHandler;
MaoLu937cf422017-03-03 23:31:46 -080027import org.onosproject.ui.UiConnection;
Jimmy Yanda878fc2016-09-02 16:32:01 -070028import org.onosproject.ui.UiMessageHandler;
29import org.onosproject.ui.table.TableModel;
30import org.onosproject.ui.table.TableRequestHandler;
31
32import java.util.Collection;
33
MaoLu937cf422017-03-03 23:31:46 -080034import static org.onosproject.net.Device.Type;
Jimmy Yanda878fc2016-09-02 16:32:01 -070035
36/**
37 * Table-View message handler for ROADM device view.
38 */
39public class RoadmDeviceViewMessageHandler extends UiMessageHandler {
40
Boyuan Yan6b23b382019-06-04 11:59:35 -070041 private static final String ROADM_DEVICE_DATA_REQ = "roadmDataRequest";
42 private static final String ROADM_DEVICE_DATA_RESP = "roadmDataResponse";
43 private static final String ROADM_DEVICES = "roadms";
Jimmy Yanda878fc2016-09-02 16:32:01 -070044
Jimmy Yanda878fc2016-09-02 16:32:01 -070045 private static final String ID = "id";
MaoLu937cf422017-03-03 23:31:46 -080046 private static final String NAME = "name";
47 private static final String TYPE = "type";
Jimmy Yanda878fc2016-09-02 16:32:01 -070048 private static final String MASTER = "master";
49 private static final String PORTS = "ports";
50 private static final String VENDOR = "vendor";
51 private static final String HW_VERSION = "hwVersion";
52 private static final String SW_VERSION = "swVersion";
53 private static final String PROTOCOL = "protocol";
54
55 private static final String[] COLUMN_IDS = {
MaoLu937cf422017-03-03 23:31:46 -080056 ID, NAME, TYPE, MASTER, PORTS, VENDOR, HW_VERSION, SW_VERSION, PROTOCOL
Jimmy Yanda878fc2016-09-02 16:32:01 -070057 };
58
MaoLu937cf422017-03-03 23:31:46 -080059 private DeviceService deviceService;
60 private MastershipService mastershipService;
61
62 @Override
63 public void init(UiConnection connection, ServiceDirectory directory) {
64 super.init(connection, directory);
65 deviceService = get(DeviceService.class);
66 mastershipService = get(MastershipService.class);
67 }
68
Jimmy Yanda878fc2016-09-02 16:32:01 -070069 @Override
70 protected Collection<RequestHandler> createRequestHandlers() {
MaoLu937cf422017-03-03 23:31:46 -080071 return ImmutableSet.of(new DeviceTableDataRequestHandler());
Jimmy Yanda878fc2016-09-02 16:32:01 -070072 }
73
74 // Handler for sample table requests
75 private final class DeviceTableDataRequestHandler extends TableRequestHandler {
76
77 private DeviceTableDataRequestHandler() {
78 super(ROADM_DEVICE_DATA_REQ, ROADM_DEVICE_DATA_RESP, ROADM_DEVICES);
79 }
80
81 @Override
82 protected String[] getColumnIds() {
83 return COLUMN_IDS;
84 }
85
86 @Override
87 protected String noRowsMessage(ObjectNode payload) {
MaoLu937cf422017-03-03 23:31:46 -080088 return RoadmUtil.NO_ROWS_MESSAGE;
Jimmy Yanda878fc2016-09-02 16:32:01 -070089 }
90
91 @Override
92 protected void populateTable(TableModel tm, ObjectNode payload) {
MaoLu937cf422017-03-03 23:31:46 -080093 for (Device device : deviceService.getDevices()) {
94 Type type = device.type();
alessiod4a2b842019-04-30 18:43:17 +020095 if (type == Type.ROADM || type == Type.TERMINAL_DEVICE
Boyuan Yan6b23b382019-06-04 11:59:35 -070096 || type == Type.OPTICAL_AMPLIFIER || type == Type.FIBER_SWITCH
97 || type == Type.OLS) {
MaoLu937cf422017-03-03 23:31:46 -080098 populateRow(tm.addRow(), device);
99 }
Jimmy Yanda878fc2016-09-02 16:32:01 -0700100 }
101 }
102
MaoLu937cf422017-03-03 23:31:46 -0800103 private void populateRow(TableModel.Row row, Device device) {
104 DeviceId devId = device.id();
105 String id = devId.toString();
106 row.cell(ID, id)
Laszlo Pappd4aaa352017-10-10 23:55:52 +0100107 .cell(NAME, RoadmUtil.getAnnotation(device.annotations(), AnnotationKeys.NAME, id))
MaoLu937cf422017-03-03 23:31:46 -0800108 .cell(TYPE, RoadmUtil.objectToString(device.type(), RoadmUtil.UNKNOWN))
109 .cell(MASTER, mastershipService.getMasterFor(devId))
110 .cell(PORTS, deviceService.getPorts(devId).size())
Jimmy Yanda878fc2016-09-02 16:32:01 -0700111 .cell(VENDOR, device.manufacturer())
112 .cell(HW_VERSION, device.hwVersion())
113 .cell(SW_VERSION, device.swVersion())
MaoLu937cf422017-03-03 23:31:46 -0800114 .cell(PROTOCOL, RoadmUtil.getAnnotation(device.annotations(), PROTOCOL));
Jimmy Yanda878fc2016-09-02 16:32:01 -0700115 }
116 }
117}