blob: 073c69f95702960041b5c68a26606ba29c77f404 [file] [log] [blame]
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +03001/*-
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
54package org.onap.osam.external.grpc;
55
56import io.grpc.ManagedChannel;
57import io.grpc.ManagedChannelBuilder;
58import lombok.extern.slf4j.Slf4j;
Zafer Kabanb0a16682018-12-04 11:16:24 +030059import org.onap.osam.common.exception.AbstractOLTException;
Aharoni, Pavel (pa0916)d2946182018-12-17 11:21:02 +020060import org.onap.osam.common.exception.ServerException;
61import org.onap.osam.grpc.AbstractOLTGrpc;
62import org.onap.osam.grpc.AddChassisMessage;
63import org.onap.osam.grpc.AddChassisReturn;
64import org.onap.osam.grpc.AddOLTChassisMessage;
65import org.onap.osam.grpc.AddOLTChassisReturn;
66import org.onap.osam.grpc.AddOntFullMessage;
67import org.onap.osam.grpc.AddOntMessage;
68import org.onap.osam.grpc.AddOntReturn;
69import org.onap.osam.grpc.PreProvisionOntMessage;
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +030070import org.onap.osam.model.dao.Chassis;
71import org.onap.osam.model.dao.OLTSlot;
Zafer Kabanb0a16682018-12-04 11:16:24 +030072import org.onap.osam.model.dao.ONTDevice;
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +030073import org.springframework.beans.factory.annotation.Value;
74import org.springframework.context.annotation.PropertySource;
75import org.springframework.stereotype.Component;
Zafer Kabanb0a16682018-12-04 11:16:24 +030076import org.springframework.util.StringUtils;
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +030077
78import javax.annotation.PostConstruct;
79
80@Component
81@PropertySource("classpath:abstractolt.properties")
82@Slf4j
83public 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)0a8080c2018-11-22 15:45:19 +020098 log.info("Abstract OLT connection properties - host: {}, port: {}", host, port);
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +030099 ManagedChannel managedChannel = ManagedChannelBuilder
100 .forAddress(host, port).usePlaintext().build();
101
102 blockingStub = AbstractOLTGrpc.newBlockingStub(managedChannel);
103 }
104
105 /** create chassis */
Zafer Kabanb0a16682018-12-04 11:16:24 +0300106 public void createChassis(Chassis chassis) {
Aharoni, Pavel (pa0916)d2946182018-12-17 11:21:02 +0200107 try {
108 log.info("createChassis begin, chassis: {}", chassis);
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +0300109
Aharoni, Pavel (pa0916)d2946182018-12-17 11:21:02 +0200110 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)ca3cb012018-10-22 15:29:57 +0300117
Aharoni, Pavel (pa0916)d2946182018-12-17 11:21:02 +0200118 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)ca3cb012018-10-22 15:29:57 +0300127
Aharoni, Pavel (pa0916)d2946182018-12-17 11:21:02 +0200128 log.info("AddChassisMessage message: {}", request);
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +0300129
Aharoni, Pavel (pa0916)d2946182018-12-17 11:21:02 +0200130 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 Kabanb0a16682018-12-04 11:16:24 +0300140 }
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +0300141 }
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)0a8080c2018-11-22 15:45:19 +0200163 log.info("AddOLTChassisMessage message: {}", request);
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +0300164 AddOLTChassisReturn response = blockingStub.createOLTChassis(request);
165 deviceID = response.getDeviceID();
166 chassisDeviceId = response.getChassisDeviceID();
Zafer Kabanb0a16682018-12-04 11:16:24 +0300167 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)d2946182018-12-17 11:21:02 +0200171 throw new ServerException("DeviceId of created chassis in AbstractOLT is empty or null");
Zafer Kabanb0a16682018-12-04 11:16:24 +0300172 }
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +0300173
174 } catch (RuntimeException e) {
Zafer Kabanb0a16682018-12-04 11:16:24 +0300175 log.error("OLT Chassis creation failed", e);
176 throw new AbstractOLTException("OLT Chassis creation failed for olt : {}", olt);
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +0300177 }
178
179 return deviceID;
180 }
181
Zafer Kabanb0a16682018-12-04 11:16:24 +0300182 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 Kabanb0a16682018-12-04 11:16:24 +0300195 return result;
196 }
197
198 public boolean provisionONT(ONTDevice ontDevice) {
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +0300199
200 boolean result = false;
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +0300201 try {
Zafer Kabanb0a16682018-12-04 11:16:24 +0300202 AddOntMessage request = OntMessageFactory.getOntMessage(ontDevice);
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +0300203 AddOntReturn response = blockingStub.provisionOnt(request);
204 result = response.getSuccess();
Zafer Kabanb0a16682018-12-04 11:16:24 +0300205 log.info("provisionONT with device id : {} success : {}",ontDevice.getSerialNumber(), result);
Aharoni, Pavel (pa0916)ca3cb012018-10-22 15:29:57 +0300206
207 } catch (RuntimeException e) {
208 log.error("provisionONT RPC failed", e);
Zafer Kabanb0a16682018-12-04 11:16:24 +0300209 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)ca3cb012018-10-22 15:29:57 +0300228 }
229
230 return result;
231 }
232
233}