Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 1 | /*-
|
| 2 | * ============LICENSE_START=======================================================
|
| 3 | * OSAM Core
|
| 4 | * ================================================================================
|
| 5 | * Copyright (C) 2018 Netsia
|
| 6 | * ================================================================================
|
| 7 | * Licensed under the Apache License, Version 2.0 (the "License");
|
| 8 | * you may not use this file except in compliance with the License.
|
| 9 | * You may obtain a copy of the License at
|
| 10 | *
|
| 11 | * http://www.apache.org/licenses/LICENSE-2.0
|
| 12 | *
|
| 13 | * Unless required by applicable law or agreed to in writing, software
|
| 14 | * distributed under the License is distributed on an "AS IS" BASIS,
|
| 15 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 16 | * See the License for the specific language governing permissions and
|
| 17 | * limitations under the License.
|
| 18 | * ============LICENSE_END=========================================================
|
| 19 | */
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 | /*
|
| 24 | * Copyright 2015, Google Inc. All rights reserved.
|
| 25 | *
|
| 26 | * Redistribution and use in source and binary forms, with or without
|
| 27 | * modification, are permitted provided that the following conditions are
|
| 28 | * met:
|
| 29 | *
|
| 30 | * * Redistributions of source code must retain the above copyright
|
| 31 | * notice, this list of conditions and the following disclaimer.
|
| 32 | * * Redistributions in binary form must reproduce the above
|
| 33 | * copyright notice, this list of conditions and the following disclaimer
|
| 34 | * in the documentation and/or other materials provided with the
|
| 35 | * distribution.
|
| 36 | *
|
| 37 | * * Neither the name of Google Inc. nor the names of its
|
| 38 | * contributors may be used to endorse or promote products derived from
|
| 39 | * this software without specific prior written permission.
|
| 40 | *
|
| 41 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| 42 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| 43 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| 44 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| 45 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| 46 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| 47 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| 48 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| 49 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| 50 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 51 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| 52 | */
|
| 53 |
|
| 54 | package org.onap.osam.external.grpc;
|
| 55 |
|
| 56 | import io.grpc.ManagedChannel;
|
| 57 | import io.grpc.ManagedChannelBuilder;
|
| 58 | import lombok.extern.slf4j.Slf4j;
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame] | 59 | import org.onap.osam.common.exception.AbstractOLTException;
|
Aharoni, Pavel (pa0916) | d294618 | 2018-12-17 11:21:02 +0200 | [diff] [blame^] | 60 | import org.onap.osam.common.exception.ServerException;
|
| 61 | import org.onap.osam.grpc.AbstractOLTGrpc;
|
| 62 | import org.onap.osam.grpc.AddChassisMessage;
|
| 63 | import org.onap.osam.grpc.AddChassisReturn;
|
| 64 | import org.onap.osam.grpc.AddOLTChassisMessage;
|
| 65 | import org.onap.osam.grpc.AddOLTChassisReturn;
|
| 66 | import org.onap.osam.grpc.AddOntFullMessage;
|
| 67 | import org.onap.osam.grpc.AddOntMessage;
|
| 68 | import org.onap.osam.grpc.AddOntReturn;
|
| 69 | import org.onap.osam.grpc.PreProvisionOntMessage;
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 70 | import org.onap.osam.model.dao.Chassis;
|
| 71 | import org.onap.osam.model.dao.OLTSlot;
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame] | 72 | import org.onap.osam.model.dao.ONTDevice;
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 73 | import org.springframework.beans.factory.annotation.Value;
|
| 74 | import org.springframework.context.annotation.PropertySource;
|
| 75 | import org.springframework.stereotype.Component;
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame] | 76 | import org.springframework.util.StringUtils;
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 77 |
|
| 78 | import javax.annotation.PostConstruct;
|
| 79 |
|
| 80 | @Component
|
| 81 | @PropertySource("classpath:abstractolt.properties")
|
| 82 | @Slf4j
|
| 83 | public class AbstractOLTClient {
|
| 84 |
|
| 85 | private static final String ABSTRACTOLT_HOST = "${abstractolt.host}";
|
| 86 | private static final String ABSTRACTOLT_PORT = "${abstractolt.port}";
|
| 87 |
|
| 88 | public static int NUMBER_OF_OLT_PORTS = 16;
|
| 89 |
|
| 90 | private AbstractOLTGrpc.AbstractOLTBlockingStub blockingStub;
|
| 91 | @Value(ABSTRACTOLT_HOST)
|
| 92 | private String host;
|
| 93 | @Value(ABSTRACTOLT_PORT)
|
| 94 | private int port;
|
| 95 |
|
| 96 | @PostConstruct
|
| 97 | private void init() {
|
Aharoni, Pavel (pa0916) | 0a8080c | 2018-11-22 15:45:19 +0200 | [diff] [blame] | 98 | log.info("Abstract OLT connection properties - host: {}, port: {}", host, port);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 99 | ManagedChannel managedChannel = ManagedChannelBuilder
|
| 100 | .forAddress(host, port).usePlaintext().build();
|
| 101 |
|
| 102 | blockingStub = AbstractOLTGrpc.newBlockingStub(managedChannel);
|
| 103 | }
|
| 104 |
|
| 105 | /** create chassis */
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame] | 106 | public void createChassis(Chassis chassis) {
|
Aharoni, Pavel (pa0916) | d294618 | 2018-12-17 11:21:02 +0200 | [diff] [blame^] | 107 | try {
|
| 108 | log.info("createChassis begin, chassis: {}", chassis);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 109 |
|
Aharoni, Pavel (pa0916) | d294618 | 2018-12-17 11:21:02 +0200 | [diff] [blame^] | 110 | String clli = chassis.getClli();
|
| 111 | int rack = chassis.getRack();
|
| 112 | int shelf = chassis.getShelf();
|
| 113 | String xosIP = chassis.getAccessPod().getCoreIp();
|
| 114 | int port = Integer.parseInt(chassis.getAccessPod().getCorePort());
|
| 115 | String user = chassis.getAccessPod().getUsername();
|
| 116 | String pass = chassis.getAccessPod().getPassword();
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 117 |
|
Aharoni, Pavel (pa0916) | d294618 | 2018-12-17 11:21:02 +0200 | [diff] [blame^] | 118 | AddChassisMessage request = AddChassisMessage.newBuilder()
|
| 119 | .setCLLI(clli)
|
| 120 | .setRack(rack)
|
| 121 | .setShelf(shelf)
|
| 122 | .setXOSIP(xosIP)
|
| 123 | .setXOSPort(port)
|
| 124 | .setXOSUser(user)
|
| 125 | .setXOSPassword(pass)
|
| 126 | .build();
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 127 |
|
Aharoni, Pavel (pa0916) | d294618 | 2018-12-17 11:21:02 +0200 | [diff] [blame^] | 128 | log.info("AddChassisMessage message: {}", request);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 129 |
|
Aharoni, Pavel (pa0916) | d294618 | 2018-12-17 11:21:02 +0200 | [diff] [blame^] | 130 | AddChassisReturn response = blockingStub.createChassis(request);
|
| 131 | if (!StringUtils.isEmpty(response.getDeviceID())) {
|
| 132 | log.info("Chassis created in AbstractOLT with clli : {}", clli);
|
| 133 | } else {
|
| 134 | log.error("DeviceId of created chassis in AbstractOLT is empty or null, chassis: {}", chassis);
|
| 135 | throw new ServerException("DeviceId of created chassis in AbstractOLT is empty or null");
|
| 136 | }
|
| 137 | } catch (RuntimeException e){
|
| 138 | log.error("Chassis creation failed", e);
|
| 139 | throw new AbstractOLTException("Chassis creation failed for chassis : {}", chassis);
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame] | 140 | }
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 141 | }
|
| 142 |
|
| 143 | public String createOLTChassis(OLTSlot olt) {
|
| 144 |
|
| 145 | String deviceID = null, chassisDeviceId = null;
|
| 146 |
|
| 147 | try {
|
| 148 | log.info("createOLTChassis begin, olt:{}", olt);
|
| 149 |
|
| 150 | String clli = olt.getChassis().getClli();
|
| 151 | AddOLTChassisMessage.OltDriver oltDriver = AddOLTChassisMessage.OltDriver.forNumber((olt.getOltDriver().ordinal()));
|
| 152 | AddOLTChassisMessage.OltType oltType = AddOLTChassisMessage.OltType.forNumber((olt.getOltType().ordinal()));
|
| 153 |
|
| 154 | AddOLTChassisMessage request = AddOLTChassisMessage.newBuilder()
|
| 155 | .setCLLI(clli)
|
| 156 | .setDriver(oltDriver)
|
| 157 | .setNumPorts(NUMBER_OF_OLT_PORTS)
|
| 158 | .setSlotPort(olt.getPort())
|
| 159 | .setSlotIP(olt.getIpAddress())
|
| 160 | .setType(oltType)
|
| 161 | .build();
|
| 162 |
|
Aharoni, Pavel (pa0916) | 0a8080c | 2018-11-22 15:45:19 +0200 | [diff] [blame] | 163 | log.info("AddOLTChassisMessage message: {}", request);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 164 | AddOLTChassisReturn response = blockingStub.createOLTChassis(request);
|
| 165 | deviceID = response.getDeviceID();
|
| 166 | chassisDeviceId = response.getChassisDeviceID();
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame] | 167 | if(!StringUtils.isEmpty(response.getDeviceID()) && !StringUtils.isEmpty(response.getChassisDeviceID())) {
|
| 168 | log.info("OLT Chassis created in AbstractOLT deviceId : {} chassisDeviceId : {}",deviceID,chassisDeviceId);
|
| 169 | } else {
|
| 170 | log.error("Invalid return argument from AbstractOLT, deviceId : {} chassisDeviceId : {}",deviceID,chassisDeviceId);
|
Aharoni, Pavel (pa0916) | d294618 | 2018-12-17 11:21:02 +0200 | [diff] [blame^] | 171 | throw new ServerException("DeviceId of created chassis in AbstractOLT is empty or null");
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame] | 172 | }
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 173 |
|
| 174 | } catch (RuntimeException e) {
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame] | 175 | log.error("OLT Chassis creation failed", e);
|
| 176 | throw new AbstractOLTException("OLT Chassis creation failed for olt : {}", olt);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 177 | }
|
| 178 |
|
| 179 | return deviceID;
|
| 180 | }
|
| 181 |
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame] | 182 | public boolean preProvisionOnt(ONTDevice ontDevice) {
|
| 183 |
|
| 184 | boolean result = false;
|
| 185 |
|
| 186 | try {
|
| 187 | PreProvisionOntMessage preProvisionOntMessage = OntMessageFactory.getPreProvisionOntMessage(ontDevice);
|
| 188 | AddOntReturn response = blockingStub.preProvisionOnt(preProvisionOntMessage);
|
| 189 | result = response.getSuccess();
|
| 190 | log.info("preProvisionOnt with device id : {} success : {}" ,ontDevice.getSerialNumber(), result);
|
| 191 | } catch (RuntimeException e) {
|
| 192 | log.error("preProvisionOnt RPC failed", e);
|
| 193 | throw new AbstractOLTException("preProvisionOnt failed for ont : {}", ontDevice);
|
| 194 | }
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame] | 195 | return result;
|
| 196 | }
|
| 197 |
|
| 198 | public boolean provisionONT(ONTDevice ontDevice) {
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 199 |
|
| 200 | boolean result = false;
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 201 | try {
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame] | 202 | AddOntMessage request = OntMessageFactory.getOntMessage(ontDevice);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 203 | AddOntReturn response = blockingStub.provisionOnt(request);
|
| 204 | result = response.getSuccess();
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame] | 205 | log.info("provisionONT with device id : {} success : {}",ontDevice.getSerialNumber(), result);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 206 |
|
| 207 | } catch (RuntimeException e) {
|
| 208 | log.error("provisionONT RPC failed", e);
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame] | 209 | throw new AbstractOLTException("provisionONT failed for ont : {}", ontDevice);
|
| 210 | }
|
| 211 |
|
| 212 | return result;
|
| 213 | }
|
| 214 |
|
| 215 | public boolean provisionOntFull(ONTDevice ontDevice) {
|
| 216 |
|
| 217 | boolean result = false;
|
| 218 |
|
| 219 | try {
|
| 220 | AddOntFullMessage addOntFullMessage = OntMessageFactory.getOntFullMessage(ontDevice);
|
| 221 | AddOntReturn response = blockingStub.provisionOntFull(addOntFullMessage);
|
| 222 | result = response.getSuccess();
|
| 223 | log.info("provisionOntFull with device id : {} success : {}",ontDevice.getSerialNumber(), result);
|
| 224 |
|
| 225 | } catch (RuntimeException e) {
|
| 226 | log.error("provisionOntFull RPC failed", e);
|
| 227 | throw new AbstractOLTException("provisionOntFull failed for ont : {}", ontDevice);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 228 | }
|
| 229 |
|
| 230 | return result;
|
| 231 | }
|
| 232 |
|
| 233 | }
|