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 | package org.onap.osam.core;
|
| 24 |
|
| 25 | import com.google.common.collect.Lists;
|
| 26 | import org.onap.osam.api.service.AccessPodService;
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 27 | import org.onap.osam.common.exception.AbstractOLTException;
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 28 | import org.onap.osam.common.exception.InvalidOperationException;
|
| 29 | import org.onap.osam.common.exception.NotFoundException;
|
| 30 | import org.onap.osam.api.service.DeviceService;
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 31 | import org.onap.osam.common.exception.ServerException;
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 32 | import org.onap.osam.external.grpc.AbstractOLTClient;
|
| 33 | import org.onap.osam.model.dao.*;
|
| 34 | import org.onap.osam.model.repository.ChassisRepository;
|
| 35 | import org.onap.osam.model.repository.OLTPortRepository;
|
| 36 | import org.onap.osam.model.repository.OLTSlotRepository;
|
| 37 | import org.onap.osam.model.repository.ONTDeviceRepository;
|
| 38 | import org.springframework.beans.factory.annotation.Autowired;
|
| 39 | import org.springframework.stereotype.Service;
|
| 40 |
|
| 41 | import java.util.HashSet;
|
| 42 | import java.util.List;
|
| 43 | import java.util.Optional;
|
| 44 | import java.util.Set;
|
| 45 |
|
| 46 | /**
|
| 47 | * Created by Zafer Kaban on 18.09.2018.
|
| 48 | */
|
| 49 | @Service
|
| 50 | public class DeviceServiceImpl extends AbstractBaseServiceImpl implements DeviceService {
|
| 51 |
|
| 52 | private ChassisRepository chassisRepository;
|
| 53 | private OLTPortRepository oltPortRepository;
|
| 54 | private OLTSlotRepository oltSlotRepository;
|
| 55 | private ONTDeviceRepository ontDeviceRepository;
|
| 56 | private AbstractOLTClient abstractOLTClient;
|
| 57 | private AccessPodService accessPodService;
|
| 58 |
|
| 59 | public static int NUMBER_OF_OLT_PORTS = 16;
|
| 60 | public static int NUMBER_OF_ONT_DEVICES = 64;
|
| 61 |
|
| 62 | @Autowired
|
| 63 | public DeviceServiceImpl(ChassisRepository chassisRepository,
|
| 64 | OLTPortRepository oltPortRepository,
|
| 65 | OLTSlotRepository oltSlotRepository,
|
| 66 | ONTDeviceRepository ontDeviceRepository,
|
| 67 | AbstractOLTClient abstractOLTClient,
|
| 68 | AccessPodService accessPodService) {
|
| 69 | this.chassisRepository = chassisRepository;
|
| 70 | this.oltPortRepository = oltPortRepository;
|
| 71 | this.oltSlotRepository = oltSlotRepository;
|
| 72 | this.ontDeviceRepository = ontDeviceRepository;
|
| 73 | this.abstractOLTClient = abstractOLTClient;
|
| 74 | this.accessPodService = accessPodService;
|
| 75 | }
|
| 76 |
|
| 77 | @Override
|
| 78 | public Chassis addChassis(Chassis chassis) {
|
| 79 | AccessPod accessPod = accessPodService.findByPnfId(chassis.getAccessPod().getPnfId());
|
| 80 | chassis.setAccessPod(accessPod);
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 81 | abstractOLTClient.createChassis(chassis);
|
| 82 | return add(chassis, chassisRepository);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 83 | }
|
| 84 |
|
| 85 | @Override
|
| 86 | public void deleteChassis(Long id) {
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 87 | log.info("Deleting chassis, id: {}", id);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 88 | remove(id, chassisRepository,Chassis.class);
|
| 89 | }
|
| 90 |
|
| 91 | public void deleteChassisByClli(String clli) {
|
| 92 | Optional<Chassis> chassis = chassisRepository.findByClli(clli);
|
| 93 | if (chassis.isPresent()){
|
| 94 | Long id = chassis.get().getId();
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 95 | log.trace("Deleting chassis, clli: {}", clli);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 96 | remove(id, chassisRepository,Chassis.class);
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 97 | } else {
|
| 98 | log.error("Chassis not found for clli {}, nothing to delete", clli);
|
| 99 | throw new NotFoundException("Chassis not found for clli {}",clli);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 100 | }
|
| 101 | }
|
| 102 |
|
| 103 | @Override
|
| 104 | public Chassis getChassisById(Long id) {
|
| 105 | Optional<Chassis> chassis = chassisRepository.findById(id);
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 106 | if (!chassis.isPresent()) {
|
| 107 | log.error("Chassis not found for id {}", id);
|
| 108 | throw new NotFoundException("Chassis not found for id {}",id);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 109 | }
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 110 | return chassis.get();
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 111 | }
|
| 112 |
|
| 113 | @Override
|
| 114 | public Chassis getChassisByClli(String clli) {
|
| 115 | Optional<Chassis> chassis = chassisRepository.findByClli(clli);
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 116 | if (!chassis.isPresent()) {
|
| 117 | log.error("Chassis not found for clli {}", clli);
|
| 118 | throw new NotFoundException("Chassis not found for clli {}",clli);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 119 | }
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 120 | return chassis.get();
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 121 | }
|
| 122 |
|
| 123 | @Override
|
| 124 | public Long getChassisCount() {
|
| 125 | return chassisRepository.count();
|
| 126 | }
|
| 127 |
|
| 128 | @Override
|
| 129 | public List<Chassis> getByPnfId(String pnfId) {
|
| 130 | Optional<List<Chassis>> chassisList = chassisRepository.findByAccessPodPnfId(pnfId);
|
| 131 | if (!chassisList.isPresent()) {
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 132 | log.error("Chassis is not found with pnfId {}", pnfId);
|
| 133 | throw new NotFoundException("Chassis is not found with pnfId : {}",pnfId);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 134 | }
|
| 135 | return chassisList.get();
|
| 136 | }
|
| 137 |
|
| 138 | @Override
|
| 139 | public List<Chassis> getAllChassis() {
|
| 140 | return Lists.newArrayList(chassisRepository.findAll());
|
| 141 | }
|
| 142 |
|
| 143 | @Override
|
| 144 | public OLTSlot addOLTSlot(OLTSlot oltSlot, Chassis chassis) {
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 145 | Set<OLTSlot> oltSlots = Optional.ofNullable(chassis.getOltSlots()).orElse(new HashSet<>());
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 146 | int size = oltSlots.size();
|
| 147 | if (size == NUMBER_OF_OLT_PORTS) {
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 148 | log.error("Maximum number of OLTs exceeded, max size per chassis: {}", NUMBER_OF_OLT_PORTS);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 149 | throw new InvalidOperationException("Maximum number of OLTs exceeded");
|
| 150 | }
|
| 151 | oltSlot.setNumber(size+1);
|
| 152 | oltSlot.setAdminState(AdminState.ENABLED);
|
| 153 | oltSlot.setOperationalState(ActivityState.ACTIVE);
|
| 154 | oltSlot.setPortAuthState(ActivityState.ACTIVE);
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 155 | abstractOLTClient.createOLTChassis(oltSlot);
|
| 156 |
|
| 157 | oltSlot.setChassis(chassis);
|
| 158 | log.trace("Adding OLT Slot, OLT slot: {}", oltSlot);
|
| 159 | add(oltSlot, oltSlotRepository);
|
| 160 | for (int j = 0; j < 16 ; j++) {
|
| 161 | OLTPort oltPort = new OLTPort();
|
| 162 | oltPort.setOltSlot(oltSlot);
|
| 163 | oltPort.setPortNumber(j+1);
|
| 164 | oltPort.setAdminState(AdminState.ENABLED);
|
| 165 | oltPort.setPortAuthState(ActivityState.ACTIVE);
|
| 166 | log.trace("Adding OLT Port on this slot, OLT port: {}", oltPort);
|
| 167 | add(oltPort, oltPortRepository);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 168 | }
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 169 | oltSlots.add(oltSlot);
|
| 170 | chassis.setOltSlots(oltSlots);
|
| 171 | log.trace("Adding this OLT slot to chassis {}", chassis);
|
| 172 | chassisRepository.save(chassis);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 173 | return oltSlot;
|
| 174 | }
|
| 175 |
|
| 176 | @Override
|
| 177 | public void deleteOLTSlot(Long id) {
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 178 | log.info("Deleting OLT slot, id: {}", id);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 179 | oltSlotRepository.deleteById(id);
|
| 180 | }
|
| 181 |
|
| 182 | @Override
|
| 183 | public OLTSlot getOLTSlotById(Long id) {
|
| 184 | Optional<OLTSlot> oltSlot = oltSlotRepository.findById(id);
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 185 | if (!oltSlot.isPresent()) {
|
| 186 | log.error("OLT Slot not found with id {}", id);
|
| 187 | throw new NotFoundException("OLT Slot not found with id "+id);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 188 | }
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 189 | return oltSlot.get();
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 190 | }
|
| 191 |
|
| 192 | @Override
|
| 193 | public OLTSlot getOLTSlotBySerialNumber(String serialNumber) {
|
| 194 | Optional<OLTSlot> oltSlot = oltSlotRepository.findBySerialNumber(serialNumber);
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 195 | if (!oltSlot.isPresent()) {
|
| 196 | log.error("OLT Slot not found with serial number {}", serialNumber);
|
| 197 | throw new NotFoundException("OLT Slot not found with serialNumber {}",serialNumber);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 198 | }
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 199 | return oltSlot.get();
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 200 | }
|
| 201 |
|
| 202 | @Override
|
| 203 | public List<OLTSlot> getAllOLTSlots() {
|
| 204 | return Lists.newArrayList(oltSlotRepository.findAll());
|
| 205 | }
|
| 206 |
|
| 207 | @Override
|
| 208 | public void deleteOLTPort(Long id) {
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 209 | log.info("Deleting OLT port, id: {}", id);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 210 | oltPortRepository.deleteById(id);
|
| 211 | }
|
| 212 |
|
| 213 | @Override
|
| 214 | public OLTPort getOLTPortById(Long id) {
|
| 215 | Optional<OLTPort> oltPort = oltPortRepository.findById(id);
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 216 | if (!oltPort.isPresent()) {
|
| 217 | log.error("OLT Port not found, id: {}", id);
|
| 218 | throw new NotFoundException("OLT Port not found, id {}",id);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 219 | }
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 220 | return oltPort.get();
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 221 | }
|
| 222 |
|
| 223 | @Override
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 224 | public ONTDevice provisionONTDevice(ONTDevice ont, OntProvisioningType provisioningType){
|
| 225 | log.trace("ONT Device provisioning, ONT Device: {}, provisioning type: ");
|
| 226 | OLTPort oltPort = ont.getOLTPort();
|
| 227 | int portNumber = oltPort.getPortNumber();
|
| 228 | OLTSlot oltSlot = oltPort.getOltSlot();
|
| 229 | int slotNumber = oltSlot.getNumber();
|
| 230 | Chassis chassis = oltSlot.getChassis();
|
| 231 | String clli = chassis.getClli();
|
| 232 | int ontNumber = ont.getNumber();
|
| 233 | String serialNumber = ont.getSerialNumber();
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 234 | Optional<OLTPort> thePort = oltPortRepository.findByPortNumberAndOltSlot_NumberAndOltSlot_ChassisClli(portNumber,slotNumber,clli);
|
| 235 | if (thePort.isPresent()) {
|
| 236 | OLTPort port = thePort.get();
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 237 | log.trace("Port found : {}", thePort);
|
| 238 | Set<ONTDevice> ontDevices = Optional.ofNullable(port.getOntDevices()).orElse(new HashSet<>());
|
| 239 |
|
| 240 | ONTDevice ontDevice = new ONTDevice();
|
| 241 | ontDevice.setSerialNumber(serialNumber);
|
| 242 | ontDevice.setNumber(ontNumber);
|
| 243 | ontDevice.setOLTPort(port);
|
| 244 | ontDevice.setAdminState(AdminState.ENABLED);
|
| 245 | ontDevice.setOperationalState(ActivityState.ACTIVE);
|
| 246 | ontDevice.setPortAuthState(ActivityState.ACTIVE);
|
| 247 | ontDevice.setCTag(ont.getCTag());
|
| 248 | ontDevice.setSTag(ont.getSTag());
|
| 249 | ontDevice.setCircuitId(ont.getCircuitId());
|
| 250 | ontDevice.setNasPortId(ont.getNasPortId());
|
| 251 |
|
| 252 | //TODO Handle technology and speed profiles later
|
| 253 | ontDevice.setSpeedProfile(null);
|
| 254 | ontDevice.setTechProfile(null);
|
| 255 |
|
| 256 | boolean success = false;
|
| 257 | if (provisioningType == OntProvisioningType.FULL) {
|
| 258 | success = abstractOLTClient.provisionOntFull(ont);
|
| 259 | } else if (provisioningType == OntProvisioningType.PREPROVISION) {
|
| 260 | success = abstractOLTClient.preProvisionOnt(ont);
|
| 261 | } else {
|
| 262 | success = abstractOLTClient.provisionONT(ont);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 263 | }
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 264 |
|
| 265 | if (success){
|
| 266 | ontDevice = add(ontDevice, ontDeviceRepository);
|
| 267 | ontDevices.add(ontDevice);
|
| 268 | port.setOntDevices(ontDevices);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 269 | oltPortRepository.save(port);
|
| 270 | } else {
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 271 | log.error("Failed to process ONTDevice at Abstract OLT, ONTDevice: {}", ont);
|
| 272 | throw new ServerException("Failed to provision ONTDevice with serial number " + ont.getSerialNumber());
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 273 | }
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 274 |
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 275 | } else {
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 276 | log.error("Port not found, port number: {}", portNumber);
|
| 277 | throw new NotFoundException("Port not found, port number {}",portNumber);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 278 | }
|
| 279 | return ont;
|
| 280 | }
|
| 281 |
|
| 282 | @Override
|
| 283 | public void deleteONTDevice(Long id) {
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 284 | log.info("Deleting ONT device port, id: {}", id);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 285 | ontDeviceRepository.deleteById(id);
|
| 286 | }
|
| 287 |
|
| 288 | @Override
|
| 289 | public ONTDevice getONTDeviceById(Long id) {
|
| 290 | Optional<ONTDevice> ontDevice = ontDeviceRepository.findById(id);
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 291 | if (!ontDevice.isPresent()) {
|
| 292 | log.error("Couldn't find ONT Device with ID {}", id);
|
| 293 | throw new NotFoundException("Couldn't find ONT Device with ID {}",id);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 294 | }
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 295 | return ontDevice.get();
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 296 | }
|
| 297 |
|
| 298 | @Override
|
| 299 | public ONTDevice getONTDeviceBySerialNumber(String serialNumber) {
|
| 300 | Optional<ONTDevice> ontDevice = ontDeviceRepository.findBySerialNumber(serialNumber);
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 301 | if (!ontDevice.isPresent()) {
|
| 302 | log.error("Couldn't find ONT Device with serialNumber {}", serialNumber);
|
| 303 | throw new NotFoundException("Couldn't find ONT Device with serialNumber {}",serialNumber);
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 304 | }
|
Zafer Kaban | b0a1668 | 2018-12-04 11:16:24 +0300 | [diff] [blame^] | 305 | return ontDevice.get();
|
Aharoni, Pavel (pa0916) | ca3cb01 | 2018-10-22 15:29:57 +0300 | [diff] [blame] | 306 | }
|
| 307 |
|
| 308 | @Override
|
| 309 | public List<ONTDevice> getAllONTDevices() {
|
| 310 | return Lists.newArrayList(ontDeviceRepository.findAll());
|
| 311 | }
|
| 312 | }
|