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) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 60 | import org.onap.osam.common.exception.NotFoundException;
|
| 61 | import org.onap.osam.grpc.*;
|
| 62 | import org.onap.osam.model.dao.Chassis;
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 63 | import org.onap.osam.model.dao.OLTPort;
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 64 | import org.onap.osam.model.dao.OLTSlot;
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 65 | import org.onap.osam.model.dao.ONTDevice;
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 66 | import org.springframework.beans.factory.annotation.Value;
|
| 67 | import org.springframework.context.annotation.PropertySource;
|
| 68 | import org.springframework.stereotype.Component;
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 69 | import org.springframework.util.StringUtils;
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 70 |
|
| 71 | import javax.annotation.PostConstruct;
|
| 72 |
|
| 73 | @Component
|
| 74 | @PropertySource("classpath:abstractolt.properties")
|
| 75 | @Slf4j
|
| 76 | public class AbstractOLTClient {
|
| 77 |
|
| 78 | private static final String ABSTRACTOLT_HOST = "${abstractolt.host}";
|
| 79 | private static final String ABSTRACTOLT_PORT = "${abstractolt.port}";
|
| 80 |
|
| 81 | public static int NUMBER_OF_OLT_PORTS = 16;
|
| 82 |
|
| 83 | private AbstractOLTGrpc.AbstractOLTBlockingStub blockingStub;
|
| 84 | @Value(ABSTRACTOLT_HOST)
|
| 85 | private String host;
|
| 86 | @Value(ABSTRACTOLT_PORT)
|
| 87 | private int port;
|
| 88 |
|
| 89 | @PostConstruct
|
| 90 | private void init() {
|
| 91 | ManagedChannel managedChannel = ManagedChannelBuilder
|
| 92 | .forAddress(host, port).usePlaintext().build();
|
| 93 |
|
| 94 | blockingStub = AbstractOLTGrpc.newBlockingStub(managedChannel);
|
| 95 | }
|
| 96 |
|
| 97 | /** create chassis */
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 98 | public void createChassis(Chassis chassis) {
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 99 |
|
| 100 | log.info("createChassis begin, chassis: {}", chassis);
|
| 101 |
|
| 102 | String clli = chassis.getClli();
|
| 103 | int rack = chassis.getRack();
|
| 104 | int shelf = chassis.getShelf();
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 105 | String xosIP = chassis.getAccessPod().getCoreIp();
|
| 106 | int port = Integer.parseInt(chassis.getAccessPod().getCorePort());
|
| 107 | String user = chassis.getAccessPod().getUsername();
|
| 108 | String pass = chassis.getAccessPod().getPassword();
|
| 109 |
|
| 110 | AddChassisMessage request = AddChassisMessage.newBuilder()
|
| 111 | .setCLLI(clli)
|
| 112 | .setRack(rack)
|
| 113 | .setShelf(shelf)
|
| 114 | .setXOSIP(xosIP)
|
| 115 | .setXOSPort(port)
|
| 116 | .setXOSUser(user)
|
| 117 | .setXOSPassword(pass)
|
| 118 | .build();
|
| 119 |
|
| 120 | AddChassisReturn response = blockingStub.createChassis(request);
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 121 | if(!StringUtils.isEmpty(response.getDeviceID())) {
|
| 122 | log.info("Chassis created in AbstractOLT with clli : {}",clli);
|
| 123 | } else {
|
| 124 | log.error("DeviceId of created chassis in AbstractOLT is empty or null, chassis: {}", chassis);
|
| 125 | throw new AbstractOLTException("DeviceId of created chassis in AbstractOLT is empty or null");
|
| 126 | }
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 127 | }
|
| 128 |
|
| 129 | public String createOLTChassis(OLTSlot olt) {
|
| 130 |
|
| 131 | String deviceID = null, chassisDeviceId = null;
|
| 132 |
|
| 133 | try {
|
| 134 | log.info("createOLTChassis begin, olt:{}", olt);
|
| 135 |
|
| 136 | String clli = olt.getChassis().getClli();
|
| 137 | AddOLTChassisMessage.OltDriver oltDriver = AddOLTChassisMessage.OltDriver.forNumber((olt.getOltDriver().ordinal()));
|
| 138 | AddOLTChassisMessage.OltType oltType = AddOLTChassisMessage.OltType.forNumber((olt.getOltType().ordinal()));
|
| 139 |
|
| 140 | AddOLTChassisMessage request = AddOLTChassisMessage.newBuilder()
|
| 141 | .setCLLI(clli)
|
| 142 | .setDriver(oltDriver)
|
| 143 | .setNumPorts(NUMBER_OF_OLT_PORTS)
|
| 144 | .setSlotPort(olt.getPort())
|
| 145 | .setSlotIP(olt.getIpAddress())
|
| 146 | .setType(oltType)
|
| 147 | .build();
|
| 148 |
|
| 149 | AddOLTChassisReturn response = blockingStub.createOLTChassis(request);
|
| 150 | deviceID = response.getDeviceID();
|
| 151 | chassisDeviceId = response.getChassisDeviceID();
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 152 | if(!StringUtils.isEmpty(response.getDeviceID()) && !StringUtils.isEmpty(response.getChassisDeviceID())) {
|
| 153 | log.info("OLT Chassis created in AbstractOLT deviceId : {} chassisDeviceId : {}",deviceID,chassisDeviceId);
|
| 154 | } else {
|
| 155 | log.error("Invalid return argument from AbstractOLT, deviceId : {} chassisDeviceId : {}",deviceID,chassisDeviceId);
|
| 156 | throw new AbstractOLTException("DeviceId of created chassis in AbstractOLT is empty or null");
|
| 157 | }
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 158 |
|
| 159 | } catch (RuntimeException e) {
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 160 | log.error("OLT Chassis creation failed", e);
|
| 161 | throw new AbstractOLTException("OLT Chassis creation failed for olt : {}", olt);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 162 | }
|
| 163 |
|
| 164 | return deviceID;
|
| 165 | }
|
| 166 |
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 167 | public boolean preProvisionOnt(ONTDevice ontDevice) {
|
| 168 |
|
| 169 | boolean result = false;
|
| 170 |
|
| 171 | try {
|
| 172 | PreProvisionOntMessage preProvisionOntMessage = OntMessageFactory.getPreProvisionOntMessage(ontDevice);
|
| 173 | AddOntReturn response = blockingStub.preProvisionOnt(preProvisionOntMessage);
|
| 174 | result = response.getSuccess();
|
| 175 | log.info("preProvisionOnt with device id : {} success : {}" ,ontDevice.getSerialNumber(), result);
|
| 176 | } catch (RuntimeException e) {
|
| 177 | log.error("preProvisionOnt RPC failed", e);
|
| 178 | throw new AbstractOLTException("preProvisionOnt failed for ont : {}", ontDevice);
|
| 179 | }
|
| 180 |
|
| 181 | return result;
|
| 182 | }
|
| 183 |
|
| 184 | public boolean provisionONT(ONTDevice ontDevice) {
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 185 |
|
| 186 | boolean result = false;
|
| 187 |
|
| 188 | try {
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 189 | AddOntMessage request = OntMessageFactory.getOntMessage(ontDevice);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 190 | AddOntReturn response = blockingStub.provisionOnt(request);
|
| 191 | result = response.getSuccess();
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 192 | log.info("provisionONT with device id : {} success : {}",ontDevice.getSerialNumber(), result);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 193 |
|
| 194 | } catch (RuntimeException e) {
|
| 195 | log.error("provisionONT RPC failed", e);
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 196 | throw new AbstractOLTException("provisionONT failed for ont : {}", ontDevice);
|
| 197 | }
|
| 198 |
|
| 199 | return result;
|
| 200 | }
|
| 201 |
|
| 202 | public boolean provisionOntFull(ONTDevice ontDevice) {
|
| 203 |
|
| 204 | boolean result = false;
|
| 205 |
|
| 206 | try {
|
| 207 | AddOntFullMessage addOntFullMessage = OntMessageFactory.getOntFullMessage(ontDevice);
|
| 208 | AddOntReturn response = blockingStub.provisionOntFull(addOntFullMessage);
|
| 209 | result = response.getSuccess();
|
| 210 | log.info("provisionOntFull with device id : {} success : {}",ontDevice.getSerialNumber(), result);
|
| 211 |
|
| 212 | } catch (RuntimeException e) {
|
| 213 | log.error("provisionOntFull RPC failed", e);
|
| 214 | throw new AbstractOLTException("provisionOntFull failed for ont : {}", ontDevice);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 215 | }
|
| 216 |
|
| 217 | return result;
|
| 218 | }
|
| 219 |
|
| 220 | }
|