Akihiro Yamanouchi | 237ca36 | 2016-07-29 17:34:38 +0900 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package org.onosproject.drivers.fujitsu; |
| 18 | |
| 19 | import org.onosproject.drivers.fujitsu.behaviour.VoltNeConfig; |
| 20 | import org.onosproject.mastership.MastershipService; |
| 21 | import org.onosproject.net.DeviceId; |
| 22 | import org.onosproject.net.driver.AbstractHandlerBehaviour; |
| 23 | import org.onosproject.net.driver.DriverHandler; |
| 24 | import org.onosproject.netconf.NetconfController; |
| 25 | import org.slf4j.Logger; |
| 26 | |
| 27 | import java.io.IOException; |
| 28 | |
| 29 | import static com.google.common.base.Preconditions.checkNotNull; |
| 30 | import static org.onosproject.drivers.fujitsu.FujitsuVoltXmlUtility.*; |
| 31 | import static org.slf4j.LoggerFactory.getLogger; |
| 32 | |
| 33 | /** |
| 34 | * Implementation to get all available data in vOLT |
| 35 | * through the Netconf protocol. |
| 36 | */ |
| 37 | public class FujitsuVoltNeConfig extends AbstractHandlerBehaviour |
| 38 | implements VoltNeConfig { |
| 39 | |
| 40 | private final Logger log = getLogger(FujitsuVoltNeConfig.class); |
| 41 | |
| 42 | |
| 43 | @Override |
| 44 | public String getAll() { |
| 45 | DriverHandler handler = handler(); |
| 46 | NetconfController controller = handler.get(NetconfController.class); |
| 47 | MastershipService mastershipService = handler.get(MastershipService.class); |
| 48 | DeviceId ncDeviceId = handler.data().deviceId(); |
| 49 | checkNotNull(controller, "Netconf controller is null"); |
| 50 | String reply = null; |
| 51 | |
| 52 | if (!mastershipService.isLocalMaster(ncDeviceId)) { |
| 53 | log.warn("Not master for {} Use {} to execute command", |
| 54 | ncDeviceId, |
| 55 | mastershipService.getMasterFor(ncDeviceId)); |
| 56 | return reply; |
| 57 | } |
| 58 | |
| 59 | try { |
| 60 | StringBuilder request = new StringBuilder(); |
| 61 | request.append(VOLT_NE_OPEN).append(VOLT_NE_NAMESPACE); |
| 62 | request.append(ANGLE_RIGHT).append(NEW_LINE); |
| 63 | request.append(VOLT_NE_CLOSE); |
| 64 | |
| 65 | reply = controller. |
| 66 | getDevicesMap().get(ncDeviceId).getSession(). |
| 67 | get(request.toString(), REPORT_ALL); |
| 68 | } catch (IOException e) { |
| 69 | log.error("Cannot communicate to device {} exception ", ncDeviceId, e); |
| 70 | } |
| 71 | return reply; |
| 72 | } |
| 73 | |
| 74 | } |