OSAM-26 Implementation of Abstract OLT Interfaces PreProvisionOnt, ProvisionOntFull and DeleteOnt

Change-Id: I7dce313ef9ecba79a05261f2ef7c858b51ed3d35
diff --git a/osam-core/api/src/main/java/org/onap/osam/api/service/DeviceService.java b/osam-core/api/src/main/java/org/onap/osam/api/service/DeviceService.java
index dd49993..921bf66 100644
--- a/osam-core/api/src/main/java/org/onap/osam/api/service/DeviceService.java
+++ b/osam-core/api/src/main/java/org/onap/osam/api/service/DeviceService.java
@@ -34,6 +34,12 @@
  */

 public interface DeviceService {

 

+     enum OntProvisioningType {

+        PREPROVISION,

+        FULL,

+        PROVISION

+    }

+

 

 /*

 Chassis Related Functionality

@@ -147,12 +153,10 @@
 

     /**

      *

-     * @param clli

-     * @param slotNumber

-     * @param portNumber

-     * @param serialNumber

+     * @param ontDevice

+     * @param provisioningType

      */

-    ONTDevice addONTDevice(String clli, int slotNumber, int portNumber, String serialNumber);

+    ONTDevice provisionONTDevice(ONTDevice ontDevice, OntProvisioningType provisioningType);

 

     /**

      *

diff --git a/osam-core/async-jobs/pom.xml b/osam-core/async-jobs/pom.xml
index 1cc2ec6..1fc4cca 100644
--- a/osam-core/async-jobs/pom.xml
+++ b/osam-core/async-jobs/pom.xml
@@ -34,7 +34,7 @@
             <groupId>org.springframework.boot</groupId>

             <artifactId>spring-boot-starter-quartz</artifactId>

         </dependency>

-        <dependency>

+      <!--  <dependency>

             <groupId>org.onap.osam</groupId>

             <artifactId>common</artifactId>

             <version>${project.version}</version>

@@ -43,6 +43,11 @@
             <groupId>org.onap.osam</groupId>

             <artifactId>model</artifactId>

             <version>${project.version}</version>

+        </dependency>-->

+        <dependency>

+            <groupId>org.onap.osam</groupId>

+            <artifactId>core</artifactId>

+            <version>${project.version}</version>

         </dependency>

     </dependencies>

 

diff --git a/osam-core/common/src/main/java/org/onap/osam/common/exception/AbstractOLTException.java b/osam-core/common/src/main/java/org/onap/osam/common/exception/AbstractOLTException.java
new file mode 100644
index 0000000..001198a
--- /dev/null
+++ b/osam-core/common/src/main/java/org/onap/osam/common/exception/AbstractOLTException.java
@@ -0,0 +1,29 @@
+/*-

+ * ============LICENSE_START=======================================================

+ * OSAM Core

+ * ================================================================================

+ * Copyright (C) 2018 AT&T

+ * ================================================================================

+ * Licensed under the Apache License, Version 2.0 (the "License");

+ * you may not use this file except in compliance with the License.

+ * You may obtain a copy of the License at

+ *

+ *      http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing, software

+ * distributed under the License is distributed on an "AS IS" BASIS,

+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

+ * See the License for the specific language governing permissions and

+ * limitations under the License.

+ * ============LICENSE_END=========================================================

+ */

+package org.onap.osam.common.exception;

+

+public class AbstractOLTException extends GenericUncheckedException {

+    public AbstractOLTException(String message) {

+        super(message);

+    }

+    public AbstractOLTException(String format, Object... arguments) {

+        super(format,arguments);

+    }

+}

diff --git a/osam-core/common/src/main/java/org/onap/osam/common/exception/BadFormatException.java b/osam-core/common/src/main/java/org/onap/osam/common/exception/BadFormatException.java
index 3bab403..c7ef4df 100644
--- a/osam-core/common/src/main/java/org/onap/osam/common/exception/BadFormatException.java
+++ b/osam-core/common/src/main/java/org/onap/osam/common/exception/BadFormatException.java
@@ -26,8 +26,11 @@
 /**

  * Created by cemturker on 19.09.2018.

  */

-public class BadFormatException extends RuntimeException {

+public class BadFormatException extends GenericUncheckedException {

     public BadFormatException(String message) {

         super(message);

     }

+    public BadFormatException(String format, Object... arguments) {

+        super(format,arguments);

+    }

 }

diff --git a/osam-core/common/src/main/java/org/onap/osam/common/exception/GenericUncheckedException.java b/osam-core/common/src/main/java/org/onap/osam/common/exception/GenericUncheckedException.java
index 4db0147..60183a2 100644
--- a/osam-core/common/src/main/java/org/onap/osam/common/exception/GenericUncheckedException.java
+++ b/osam-core/common/src/main/java/org/onap/osam/common/exception/GenericUncheckedException.java
@@ -31,4 +31,8 @@
     public GenericUncheckedException(Throwable cause) {

         super(cause);

     }

+

+    public GenericUncheckedException(String format, Object... arguments) {

+        super(String.format(format, arguments));

+    }

 }

diff --git a/osam-core/common/src/main/java/org/onap/osam/common/exception/InvalidOperationException.java b/osam-core/common/src/main/java/org/onap/osam/common/exception/InvalidOperationException.java
index 7ac9547..75447a4 100644
--- a/osam-core/common/src/main/java/org/onap/osam/common/exception/InvalidOperationException.java
+++ b/osam-core/common/src/main/java/org/onap/osam/common/exception/InvalidOperationException.java
@@ -25,8 +25,11 @@
 /**

  * Created by Zafer Kaban on 18.09.2018.

  */

-public class InvalidOperationException extends RuntimeException {

+public class InvalidOperationException extends GenericUncheckedException {

     public InvalidOperationException(String message) {

         super(message);

     }

+    public InvalidOperationException(String format, Object... arguments) {

+        super(format,arguments);

+    }

 }

diff --git a/osam-core/common/src/main/java/org/onap/osam/common/exception/NotFoundException.java b/osam-core/common/src/main/java/org/onap/osam/common/exception/NotFoundException.java
index e850c43..10be17a 100644
--- a/osam-core/common/src/main/java/org/onap/osam/common/exception/NotFoundException.java
+++ b/osam-core/common/src/main/java/org/onap/osam/common/exception/NotFoundException.java
@@ -26,8 +26,11 @@
 /**

  * Created by cemturker on 18.09.2018.

  */

-public class NotFoundException extends RuntimeException {

+public class NotFoundException extends GenericUncheckedException {

     public NotFoundException(String message) {

         super(message);

     }

+    public NotFoundException(String format, Object... arguments) {

+        super(format,arguments);

+    }

 }

diff --git a/osam-core/common/src/main/java/org/onap/osam/common/exception/ServerException.java b/osam-core/common/src/main/java/org/onap/osam/common/exception/ServerException.java
new file mode 100644
index 0000000..07bf68c
--- /dev/null
+++ b/osam-core/common/src/main/java/org/onap/osam/common/exception/ServerException.java
@@ -0,0 +1,36 @@
+/*-

+ * ============LICENSE_START=======================================================

+ * OSAM Core

+ * ================================================================================

+ * Copyright (C) 2018 Netsia

+ * ================================================================================

+ * Licensed under the Apache License, Version 2.0 (the "License");

+ * you may not use this file except in compliance with the License.

+ * You may obtain a copy of the License at

+ * 

+ *      http://www.apache.org/licenses/LICENSE-2.0

+ * 

+ * Unless required by applicable law or agreed to in writing, software

+ * distributed under the License is distributed on an "AS IS" BASIS,

+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

+ * See the License for the specific language governing permissions and

+ * limitations under the License.

+ * ============LICENSE_END=========================================================

+ */

+

+

+

+package org.onap.osam.common.exception;

+

+

+/**

+ * Created by Zafer Kaban on 07.12.2018.

+ */

+public class ServerException extends GenericUncheckedException {

+    public ServerException(String message) {

+        super(message);

+    }

+    public ServerException(String format, Object... arguments) {

+        super(format,arguments);

+    }

+}

diff --git a/osam-core/common/src/main/java/org/onap/osam/common/exception/UnknownTypeException.java b/osam-core/common/src/main/java/org/onap/osam/common/exception/UnknownTypeException.java
index 7b13329..4781a72 100644
--- a/osam-core/common/src/main/java/org/onap/osam/common/exception/UnknownTypeException.java
+++ b/osam-core/common/src/main/java/org/onap/osam/common/exception/UnknownTypeException.java
@@ -26,8 +26,11 @@
 /**

  * Created by cemturker on 18.09.2018.

  */

-public class UnknownTypeException extends RuntimeException {

+public class UnknownTypeException extends GenericUncheckedException {

     public UnknownTypeException(String message) {

         super(message);

     }

+    public UnknownTypeException(String format, Object... arguments) {

+        super(format,arguments);

+    }

 }

diff --git a/osam-core/core/pom.xml b/osam-core/core/pom.xml
index 1db7193..3c5b21c 100644
--- a/osam-core/core/pom.xml
+++ b/osam-core/core/pom.xml
@@ -35,5 +35,10 @@
             <artifactId>external</artifactId>

             <version>${project.version}</version>

         </dependency>

+        <dependency>

+            <groupId>org.onap.osam</groupId>

+            <artifactId>api</artifactId>

+            <version>${project.version}</version>

+        </dependency>

     </dependencies>

 </project>
\ No newline at end of file
diff --git a/osam-core/core/src/main/java/org/onap/osam/core/AccessPodServiceImpl.java b/osam-core/core/src/main/java/org/onap/osam/core/AccessPodServiceImpl.java
index b3e00c5..1ba8bad 100644
--- a/osam-core/core/src/main/java/org/onap/osam/core/AccessPodServiceImpl.java
+++ b/osam-core/core/src/main/java/org/onap/osam/core/AccessPodServiceImpl.java
@@ -83,7 +83,8 @@
     public AccessPod findByPnfId(String pnfId) {

         Optional<AccessPod> accessPodOp = accessPodRepository.findByPnfId(pnfId);

         if (!accessPodOp.isPresent()) {

-            throw new NotFoundException("pnfId:"+pnfId+ " is not found");

+            log.error("Access POD with pnfId : {} is not found", pnfId);

+            throw new NotFoundException("Access POD with pnfId : {} is not found", pnfId);

         }

         return accessPodOp.get();

     }

diff --git a/osam-core/core/src/main/java/org/onap/osam/core/DeviceServiceImpl.java b/osam-core/core/src/main/java/org/onap/osam/core/DeviceServiceImpl.java
index 610e217..0d6828f 100644
--- a/osam-core/core/src/main/java/org/onap/osam/core/DeviceServiceImpl.java
+++ b/osam-core/core/src/main/java/org/onap/osam/core/DeviceServiceImpl.java
@@ -24,9 +24,11 @@
 

 import com.google.common.collect.Lists;

 import org.onap.osam.api.service.AccessPodService;

+import org.onap.osam.common.exception.AbstractOLTException;

 import org.onap.osam.common.exception.InvalidOperationException;

 import org.onap.osam.common.exception.NotFoundException;

 import org.onap.osam.api.service.DeviceService;

+import org.onap.osam.common.exception.ServerException;

 import org.onap.osam.external.grpc.AbstractOLTClient;

 import org.onap.osam.model.dao.*;

 import org.onap.osam.model.repository.ChassisRepository;

@@ -76,15 +78,13 @@
     public Chassis addChassis(Chassis chassis) {

         AccessPod accessPod = accessPodService.findByPnfId(chassis.getAccessPod().getPnfId());

         chassis.setAccessPod(accessPod);

-        String deviceId = abstractOLTClient.createChassis(chassis);

-        if (deviceId != null) {

-            return add(chassis, chassisRepository);

-        }

-        return null;

+        abstractOLTClient.createChassis(chassis);

+        return add(chassis, chassisRepository);

     }

 

     @Override

     public void deleteChassis(Long id) {

+        log.info("Deleting chassis, id: {}", id);

         remove(id, chassisRepository,Chassis.class);

     }

 

@@ -92,26 +92,32 @@
         Optional<Chassis> chassis = chassisRepository.findByClli(clli);

         if (chassis.isPresent()){

             Long id = chassis.get().getId();

+            log.trace("Deleting chassis, clli: {}", clli);

             remove(id, chassisRepository,Chassis.class);

+        } else {

+            log.error("Chassis not found for clli {}, nothing to delete", clli);

+            throw new NotFoundException("Chassis not found for clli {}",clli);

         }

     }

 

     @Override

     public Chassis getChassisById(Long id) {

         Optional<Chassis> chassis = chassisRepository.findById(id);

-        if (chassis.isPresent()) {

-            return chassis.get();

+        if (!chassis.isPresent()) {

+            log.error("Chassis not found for id {}", id);

+            throw new NotFoundException("Chassis not found for id {}",id);

         }

-        return null;

+        return chassis.get();

     }

 

     @Override

     public Chassis getChassisByClli(String clli) {

         Optional<Chassis> chassis = chassisRepository.findByClli(clli);

-        if (chassis.isPresent()) {

-            return chassis.get();

+        if (!chassis.isPresent()) {

+            log.error("Chassis not found for clli {}", clli);

+            throw new NotFoundException("Chassis not found for clli {}",clli);

         }

-        return null;

+        return chassis.get();

     }

 

     @Override

@@ -123,7 +129,8 @@
     public List<Chassis> getByPnfId(String pnfId) {

         Optional<List<Chassis>> chassisList = chassisRepository.findByAccessPodPnfId(pnfId);

         if (!chassisList.isPresent()) {

-            throw new NotFoundException("Chassis is not found with "+pnfId + ":pnfId");

+            log.error("Chassis is not found with pnfId {}", pnfId);

+            throw new NotFoundException("Chassis is not found with pnfId : {}",pnfId);

         }

         return chassisList.get();

     }

@@ -135,58 +142,61 @@
 

     @Override

     public OLTSlot addOLTSlot(OLTSlot oltSlot, Chassis chassis) {

-        Set<OLTSlot> oltSlots = chassis.getOltSlots();

+        Set<OLTSlot> oltSlots = Optional.ofNullable(chassis.getOltSlots()).orElse(new HashSet<>());

         int size = oltSlots.size();

         if (size == NUMBER_OF_OLT_PORTS) {

+            log.error("Maximum number of OLTs exceeded, max size per chassis: {}", NUMBER_OF_OLT_PORTS);

             throw new InvalidOperationException("Maximum number of OLTs exceeded");

         }

         oltSlot.setNumber(size+1);

         oltSlot.setAdminState(AdminState.ENABLED);

         oltSlot.setOperationalState(ActivityState.ACTIVE);

         oltSlot.setPortAuthState(ActivityState.ACTIVE);

-        String deviceId = abstractOLTClient.createOLTChassis(oltSlot);

-        if (deviceId != null) {

-            oltSlot.setChassis(chassis);

-            add(oltSlot, oltSlotRepository);

-            for (int j = 0; j < 16 ; j++) {

-                OLTPort oltPort = new OLTPort();

-                oltPort.setOltSlot(oltSlot);

-                oltPort.setPortNumber(j+1);

-                oltPort.setAdminState(AdminState.ENABLED);

-                oltPort.setPortAuthState(ActivityState.ACTIVE);

-                add(oltPort, oltPortRepository);

-            }

-            if (oltSlots.isEmpty()) {

-                oltSlots = new HashSet<>();

-            }

-            oltSlots.add(oltSlot);

-            chassis.setOltSlots(oltSlots);

-            chassisRepository.save(chassis);

+        abstractOLTClient.createOLTChassis(oltSlot);

+

+        oltSlot.setChassis(chassis);

+        log.trace("Adding OLT Slot, OLT slot: {}", oltSlot);

+        add(oltSlot, oltSlotRepository);

+        for (int j = 0; j < 16 ; j++) {

+            OLTPort oltPort = new OLTPort();

+            oltPort.setOltSlot(oltSlot);

+            oltPort.setPortNumber(j+1);

+            oltPort.setAdminState(AdminState.ENABLED);

+            oltPort.setPortAuthState(ActivityState.ACTIVE);

+            log.trace("Adding OLT Port on this slot, OLT port: {}", oltPort);

+            add(oltPort, oltPortRepository);

         }

+        oltSlots.add(oltSlot);

+        chassis.setOltSlots(oltSlots);

+        log.trace("Adding this OLT slot to chassis {}", chassis);

+        chassisRepository.save(chassis);

         return oltSlot;

     }

 

     @Override

     public void deleteOLTSlot(Long id) {

+        log.info("Deleting OLT slot, id: {}", id);

         oltSlotRepository.deleteById(id);

     }

 

     @Override

     public OLTSlot getOLTSlotById(Long id) {

         Optional<OLTSlot> oltSlot = oltSlotRepository.findById(id);

-        if (oltSlot.isPresent()) {

-            return oltSlot.get();

+        if (!oltSlot.isPresent()) {

+            log.error("OLT Slot not found with id {}", id);

+            throw new NotFoundException("OLT Slot not found with id "+id);

         }

-        return null;

+        return oltSlot.get();

     }

 

     @Override

     public OLTSlot getOLTSlotBySerialNumber(String serialNumber) {

         Optional<OLTSlot> oltSlot = oltSlotRepository.findBySerialNumber(serialNumber);

-        if (oltSlot.isPresent()) {

-            return oltSlot.get();

+        if (!oltSlot.isPresent()) {

+            log.error("OLT Slot not found with serial number {}", serialNumber);

+            throw new NotFoundException("OLT Slot not found with serialNumber {}",serialNumber);

         }

-        return null;

+        return oltSlot.get();

     }

 

     @Override

@@ -196,75 +206,103 @@
 

     @Override

     public void deleteOLTPort(Long id) {

+        log.info("Deleting OLT port, id: {}", id);

         oltPortRepository.deleteById(id);

     }

 

     @Override

     public OLTPort getOLTPortById(Long id) {

         Optional<OLTPort> oltPort = oltPortRepository.findById(id);

-        if (oltPort.isPresent()) {

-            return oltPort.get();

+        if (!oltPort.isPresent()) {

+            log.error("OLT Port not found, id: {}", id);

+            throw new NotFoundException("OLT Port not found, id {}",id);

         }

-        return null;

+        return oltPort.get();

     }

 

     @Override

-    public ONTDevice addONTDevice(String clli, int slotNumber, int portNumber, String serialNumber){

-        ONTDevice ont = null;

+    public ONTDevice provisionONTDevice(ONTDevice ont, OntProvisioningType provisioningType){

+        log.trace("ONT Device provisioning, ONT Device: {}, provisioning type: ");

+        OLTPort oltPort = ont.getOLTPort();

+        int portNumber = oltPort.getPortNumber();

+        OLTSlot oltSlot = oltPort.getOltSlot();

+        int slotNumber = oltSlot.getNumber();

+        Chassis chassis = oltSlot.getChassis();

+        String clli = chassis.getClli();

+        int ontNumber = ont.getNumber();

+        String serialNumber = ont.getSerialNumber();

         Optional<OLTPort> thePort = oltPortRepository.findByPortNumberAndOltSlot_NumberAndOltSlot_ChassisClli(portNumber,slotNumber,clli);

         if (thePort.isPresent()) {

             OLTPort port = thePort.get();

-            log.info("Port found : {}", thePort);

-            Set<ONTDevice> ontDevices = port.getOntDevices();

-            int size = ontDevices.size();

-            if (size == NUMBER_OF_ONT_DEVICES) {

-                throw new InvalidOperationException("Maximum number of ONTs exceeded");

+            log.trace("Port found : {}", thePort);

+            Set<ONTDevice> ontDevices = Optional.ofNullable(port.getOntDevices()).orElse(new HashSet<>());

+

+            ONTDevice ontDevice = new ONTDevice();

+            ontDevice.setSerialNumber(serialNumber);

+            ontDevice.setNumber(ontNumber);

+            ontDevice.setOLTPort(port);

+            ontDevice.setAdminState(AdminState.ENABLED);

+            ontDevice.setOperationalState(ActivityState.ACTIVE);

+            ontDevice.setPortAuthState(ActivityState.ACTIVE);

+            ontDevice.setCTag(ont.getCTag());

+            ontDevice.setSTag(ont.getSTag());

+            ontDevice.setCircuitId(ont.getCircuitId());

+            ontDevice.setNasPortId(ont.getNasPortId());

+

+            //TODO Handle technology and speed profiles later

+            ontDevice.setSpeedProfile(null);

+            ontDevice.setTechProfile(null);

+

+            boolean success =  false;

+            if (provisioningType == OntProvisioningType.FULL) {

+                success = abstractOLTClient.provisionOntFull(ont);

+            } else if (provisioningType == OntProvisioningType.PREPROVISION) {

+                success = abstractOLTClient.preProvisionOnt(ont);

+            } else {

+                success = abstractOLTClient.provisionONT(ont);

             }

-            int ontNumber = size+1;

-            boolean result =  abstractOLTClient.provisionONT(clli, slotNumber, portNumber,ontNumber,serialNumber);

-            if (result){

-                ont = new ONTDevice();

-                ont.setSerialNumber(serialNumber);

-                ont.setNumber(ontNumber);

-                ont.setOLTPort(port);

-                ont.setAdminState(AdminState.ENABLED);

-                ont.setOperationalState(ActivityState.ACTIVE);

-                ont.setPortAuthState(ActivityState.ACTIVE);

-                add(ont,ontDeviceRepository);

-                ontDevices.add(ont);

+

+            if (success){

+                ontDevice = add(ontDevice, ontDeviceRepository);

+                ontDevices.add(ontDevice);

+                port.setOntDevices(ontDevices);

                 oltPortRepository.save(port);

             } else {

-                log.error("Error rpc failed");

-                throw new NotFoundException("Operation failed");

+                log.error("Failed to process ONTDevice at Abstract OLT, ONTDevice: {}", ont);

+                throw new ServerException("Failed to provision ONTDevice with serial number " + ont.getSerialNumber());

             }

+

         } else {

-            log.error("Port not found");

-            throw new NotFoundException("Operation failed");

+            log.error("Port not found, port number: {}", portNumber);

+            throw new NotFoundException("Port not found, port number {}",portNumber);

         }

         return ont;

     }

 

     @Override

     public void deleteONTDevice(Long id) {

+        log.info("Deleting ONT device port, id: {}", id);

         ontDeviceRepository.deleteById(id);

     }

 

     @Override

     public ONTDevice getONTDeviceById(Long id) {

         Optional<ONTDevice> ontDevice = ontDeviceRepository.findById(id);

-        if (ontDevice.isPresent()) {

-            ontDevice.get();

+        if (!ontDevice.isPresent()) {

+            log.error("Couldn't find ONT Device with ID {}", id);

+            throw new NotFoundException("Couldn't find ONT Device with ID {}",id);

         }

-        return null;

+        return ontDevice.get();

     }

 

     @Override

     public ONTDevice getONTDeviceBySerialNumber(String serialNumber) {

         Optional<ONTDevice> ontDevice = ontDeviceRepository.findBySerialNumber(serialNumber);

-        if (ontDevice.isPresent()) {

-            ontDevice.get();

+        if (!ontDevice.isPresent()) {

+            log.error("Couldn't find ONT Device with serialNumber {}", serialNumber);

+            throw new NotFoundException("Couldn't find ONT Device with serialNumber {}",serialNumber);

         }

-        return null;

+        return ontDevice.get();

     }

 

     @Override

diff --git a/osam-core/core/src/test/java/org/onap/osam/core/DeviceServiceImplTest.java b/osam-core/core/src/test/java/org/onap/osam/core/DeviceServiceImplTest.java
new file mode 100644
index 0000000..5abeb8f
--- /dev/null
+++ b/osam-core/core/src/test/java/org/onap/osam/core/DeviceServiceImplTest.java
@@ -0,0 +1,439 @@
+/*-

+ * ============LICENSE_START=======================================================

+ * OSAM Core

+ * ================================================================================

+ * Copyright (C) 2018 Netsia

+ * ================================================================================

+ * Licensed under the Apache License, Version 2.0 (the "License");

+ * you may not use this file except in compliance with the License.

+ * You may obtain a copy of the License at

+ * 

+ *      http://www.apache.org/licenses/LICENSE-2.0

+ * 

+ * Unless required by applicable law or agreed to in writing, software

+ * distributed under the License is distributed on an "AS IS" BASIS,

+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

+ * See the License for the specific language governing permissions and

+ * limitations under the License.

+ * ============LICENSE_END=========================================================

+ */

+

+package org.onap.osam.core;

+

+import junitparams.JUnitParamsRunner;

+import junitparams.Parameters;

+import org.junit.Before;

+import org.junit.Test;

+import org.junit.runner.RunWith;

+import org.mockito.ArgumentCaptor;

+import org.mockito.Captor;

+import org.mockito.InjectMocks;

+import org.mockito.Mock;

+import org.mockito.MockitoAnnotations;

+import org.onap.osam.api.service.AccessPodService;

+import org.onap.osam.api.service.DeviceService;

+import org.onap.osam.common.exception.AbstractOLTException;

+import org.onap.osam.common.exception.InvalidOperationException;

+import org.onap.osam.common.exception.NotFoundException;

+import org.onap.osam.external.grpc.AbstractOLTClient;

+import org.onap.osam.model.dao.*;

+import org.onap.osam.model.repository.ChassisRepository;

+import org.onap.osam.model.repository.OLTPortRepository;

+import org.onap.osam.model.repository.OLTSlotRepository;

+import org.onap.osam.model.repository.ONTDeviceRepository;

+

+import java.util.ArrayList;

+import java.util.HashSet;

+import java.util.List;

+import java.util.Optional;

+import java.util.Set;

+

+import static org.assertj.core.api.Assertions.assertThat;

+import static org.assertj.core.api.Assertions.assertThatThrownBy;

+import static org.mockito.ArgumentMatchers.any;

+import static org.mockito.Mockito.*;

+

+/**

+ * Created by Zafer Kaban on 26.11.2018.

+ */

+

+@RunWith(JUnitParamsRunner.class)

+public class DeviceServiceImplTest {

+

+    private static String TEST_PNF_ID = "TEST_PNF_ID";

+    private static String TEST_CLLI   = "TEST_CLLI";

+    private static String TEST_SERIAL = "SERIAL_NUMBER";

+

+    @Mock

+    private ChassisRepository chassisRepository;

+    @Mock

+    private OLTPortRepository oltPortRepository;

+    @Mock

+    private OLTSlotRepository oltSlotRepository;

+    @Mock

+    private ONTDeviceRepository ontDeviceRepository;

+

+    @Mock

+    private AbstractOLTClient abstractOLTClient;

+

+    @Mock

+    private AccessPodService accessPodService;

+

+    @Captor

+    private ArgumentCaptor<ONTDevice> ontDeviceCaptor;

+

+    @Captor

+    private ArgumentCaptor<OLTPort> portCaptor;

+

+

+    private Chassis chassis;

+

+    private AccessPod accessPod;

+

+    private OLTSlot oltSlot;

+

+    private OLTPort oltPort;

+

+    private ONTDevice ontDevice;

+

+    @InjectMocks

+    private DeviceServiceImpl deviceService;

+

+    @Before

+    public void initMocks() {

+        MockitoAnnotations.initMocks(this);

+        accessPod = new AccessPod();

+        accessPod.setPnfId(TEST_PNF_ID);

+        chassis = new Chassis();

+        chassis.setClli(TEST_CLLI);

+        chassis.setAccessPod(accessPod);

+        chassis.setId(1L);

+        oltSlot = new OLTSlot();

+        oltSlot.setId(1L);

+        oltSlot.setNumber(1);

+        oltPort = new OLTPort();

+        oltPort.setId(1L);

+        oltPort.setPortNumber(1);

+        ontDevice = new ONTDevice();

+        ontDevice.setId(1L);

+        ontDevice.setOLTPort(oltPort);

+        oltPort.setOltSlot(oltSlot);

+        oltSlot.setChassis(chassis);

+

+        when(chassisRepository.findByClli(TEST_CLLI)).thenReturn(Optional.ofNullable(chassis));

+        when(chassisRepository.findById(1L)).thenReturn(Optional.ofNullable(chassis));

+    }

+

+    @Test

+    public void whenAddChassis_sunnyFlow(){

+

+        // TEST Sunshine scenario

+        when(accessPodService.findByPnfId(TEST_PNF_ID)).thenReturn(accessPod);

+        when(chassisRepository.save(chassis)).thenReturn(chassis);

+

+        Chassis chassisResult = deviceService.addChassis(chassis);

+        assertThat(chassisResult).isSameAs(chassis);

+    }

+

+

+    @Test

+    public void whenAddChassisPnfNotFound_shouldThrowException() {

+        // TEST when PNF registration does not exist so that Access POD does not exist in OSAM DB

+

+        when(accessPodService.findByPnfId(TEST_PNF_ID)).thenThrow(NotFoundException.class);

+        assertThatThrownBy(() -> deviceService.addChassis(chassis)).isInstanceOf(NotFoundException.class);

+        //verify we save nothing to DB

+        verifyZeroInteractions(chassisRepository);

+    }

+

+    @Test

+    public void whenAddChassisAbstractOltReturnsNull_shouldThrowException() {

+        // TEST grpc failure case

+

+        when(accessPodService.findByPnfId(TEST_PNF_ID)).thenReturn(accessPod);

+        doThrow(AbstractOLTException.class).when(abstractOLTClient).createChassis(chassis);

+        assertThatThrownBy(() -> deviceService.addChassis(chassis)).isInstanceOf(AbstractOLTException.class);

+        //verify we save nothing to DB

+        verifyZeroInteractions(chassisRepository);

+    }

+

+

+    @Test

+    public void whenDeleteChassisById_sunnyFlow() {

+        deviceService.deleteChassis(1L);

+        verify(chassisRepository, times(1)).deleteById(1L);

+    }

+

+    @Test

+    public void whenDeleteChassisByClli_sunnyFlow () {

+        deviceService.deleteChassisByClli(TEST_CLLI);

+        //Test chassis has clli TEST_CLLI and id 1L, thus the verify

+        verify(chassisRepository, times(1)).deleteById(1L);

+    }

+

+

+

+    @Test

+    public void whenGetChassisById_sunnyFlow(){

+        Chassis testChassis = deviceService.getChassisById(1L);

+        assertThat(testChassis).isSameAs(chassis);

+    }

+

+    @Test

+    public void whenGetChassisByNotExistingId_throwNotFoundException(){

+        assertThatThrownBy(() -> deviceService.getChassisById(100L)).isInstanceOf(NotFoundException.class);

+    }

+

+    @Test

+    public void whenGetChassisByTestClli_sunnyFlow(){

+        Chassis testChassis = deviceService.getChassisByClli(TEST_CLLI);

+        assertThat(testChassis).isSameAs(chassis);

+    }

+

+    @Test

+    public void whenGetChassisByNotExistingClli_throwNotFoundException(){

+        assertThatThrownBy(() -> deviceService.getChassisByClli("SOME_FAKE_CLLI")).isInstanceOf(NotFoundException.class);

+    }

+

+    @Test

+    public void whenCountChassis_sunnyFlow(){

+        when(chassisRepository.count()).thenReturn(1L);

+        long count = deviceService.getChassisCount();

+        assertThat(count).isEqualTo(1L);

+    }

+

+    @Test

+    public void whenGetByPnfId_sunnyFlow(){

+        when(chassisRepository.findByAccessPodPnfId(TEST_PNF_ID)).thenReturn(Optional.of(new ArrayList<Chassis>()));

+        ArrayList<Chassis> chassisResult = (ArrayList<Chassis>) deviceService.getByPnfId(TEST_PNF_ID);

+        assertThat(chassisResult).isNotNull();

+    }

+

+

+    @Test

+    public void whenGetByPnfIdNotExisting_shouldThrowException(){

+        assertThatThrownBy(() -> deviceService.getByPnfId("SOME_FAKE_PNFID")).isInstanceOf(NotFoundException.class);

+    }

+

+

+    @Test

+    public void whenGetAllChassis_sunnyFlow() {

+        when(chassisRepository.findAll()).thenReturn(new ArrayList<Chassis>());

+        ArrayList<Chassis> chassisResult = (ArrayList<Chassis>) deviceService.getAllChassis();

+        assertThat(chassisResult).isNotNull();

+    }

+

+

+    @Test

+    public void whenAddOLTSlot_sunnyFlow() {

+

+        Set<OLTSlot> oltSlots = new HashSet<OLTSlot>();

+        chassis.setOltSlots(oltSlots);

+        when(oltSlotRepository.save(oltSlot)).thenReturn(oltSlot);

+        when(abstractOLTClient.createOLTChassis(oltSlot)).thenReturn(TEST_CLLI);

+

+        OLTSlot oltResult = deviceService.addOLTSlot(oltSlot, chassis);

+

+        //verify creation of 16 ports

+        verify(oltPortRepository, times(16)).save(portCaptor.capture());

+        final List<OLTPort> allOltPortsValues = portCaptor.getAllValues();

+        allOltPortsValues.forEach(x -> {

+            assertThat(x.getOltSlot()).isSameAs(oltSlot);

+            assertThat(x.getAdminState()).isEqualTo(AdminState.ENABLED);

+            assertThat(x.getPortAuthState()).isEqualTo(ActivityState.ACTIVE);

+        });

+

+        //verify added to chassis

+        assertThat(chassis.getOltSlots()).hasSize(1);

+

+        //verify oltSlot logic

+        assertThat(oltResult).isSameAs(oltSlot);

+        assertThat(oltResult.getAdminState()).isEqualTo(AdminState.ENABLED);

+        assertThat(oltResult.getOperationalState()).isEqualTo(ActivityState.ACTIVE);

+        assertThat(oltResult.getPortAuthState()).isEqualTo(ActivityState.ACTIVE);

+

+    }

+

+    public void whenAddOLTSlotTooManySlotsOnChassis_shouldThrowException() {

+        //already add 16 slots, cannot add another one

+        Set<OLTSlot> oltSlots = new HashSet<OLTSlot>();

+        for (int i = 0; i < 16; i++) {

+            oltSlots.add(new OLTSlot());

+        }

+        chassis.setOltSlots(oltSlots);

+        assertThatThrownBy(()-> deviceService.addOLTSlot(oltSlot, chassis)).isInstanceOf(InvalidOperationException.class);

+        //verify no DB interactions

+        verifyZeroInteractions(oltSlotRepository, oltPortRepository, chassisRepository);

+    }

+

+    public void whenAddOLTSlotAbstractOLTReturnsNull_shouldThrowException() {

+        when(abstractOLTClient.createOLTChassis(oltSlot)).thenReturn(null);

+        assertThatThrownBy(()-> deviceService.addOLTSlot(oltSlot, chassis)).isInstanceOf(AbstractOLTException.class);

+        //verify no DB interactions

+        verifyZeroInteractions(oltSlotRepository, oltPortRepository, chassisRepository);

+    }

+

+    @Test

+    public void whenDeleteOLTSlot_repositoryMethodCalledOnce() {

+        deviceService.deleteOLTSlot(1L);

+        verify(oltSlotRepository, times(1)).deleteById(1L);

+    }

+

+

+    @Test

+    public void whenGetOLTSlotById_sunnyFlow(){

+        when(oltSlotRepository.findById(1L)).thenReturn(Optional.of(oltSlot));

+        OLTSlot oltActualSlot = deviceService.getOLTSlotById(1L);

+        assertThat(oltActualSlot).isSameAs(oltSlot);

+    }

+

+    @Test

+    public void whenGetOLTSlotByIdNotExisting_shouldThrowException(){

+        assertThatThrownBy(()-> deviceService.getOLTSlotById(100L)).isInstanceOf(NotFoundException.class);

+    }

+

+    @Test

+    public void whenGetOLTSlotBySerialId_sunnyFlow() {

+        when(oltSlotRepository.findBySerialNumber(TEST_SERIAL)).thenReturn(Optional.of(oltSlot));

+        OLTSlot oltActualSlot = deviceService.getOLTSlotBySerialNumber(TEST_SERIAL);

+        assertThat(oltActualSlot).isSameAs(oltSlot);

+    }

+

+    @Test

+    public void whenGetOLTSlotBySerialIdNotExisting_shouldThrowException(){

+        assertThatThrownBy(()-> deviceService.getOLTSlotBySerialNumber("SOME_FAKE_SERIAL")).isInstanceOf(NotFoundException.class);

+    }

+

+    @Test

+    public void whenGetAllOLTSlot_sunnyFlow() {

+        final ArrayList<OLTSlot> slotArrayList = new ArrayList<>();

+        when(oltSlotRepository.findAll()).thenReturn(slotArrayList);

+        ArrayList<OLTSlot> oltSlots = (ArrayList<OLTSlot>) deviceService.getAllOLTSlots();

+        assertThat(oltSlots).isEqualTo(slotArrayList);

+    }

+

+    @Test

+    public void whenDeleteOLTPort_sunnyFlow() {

+        deviceService.deleteOLTPort(1L);

+        verify(oltPortRepository, times(1)).deleteById(1L);

+    }

+

+    @Test

+    public void whenGetOLTPort_sunnyFlow() {

+        when(oltPortRepository.findById(1L)).thenReturn(Optional.of(oltPort));

+        final OLTPort actualPort = deviceService.getOLTPortById(1L);

+        assertThat(actualPort).isSameAs(oltPort);

+    }

+

+    @Test

+    public void whenGetOLTPortByIdNotExisting_shouldThrowException(){

+        assertThatThrownBy(()-> deviceService.getOLTPortById(100L)).isInstanceOf(NotFoundException.class);

+    }

+

+    @Test

+    @Parameters(method = "provTypeToTestForOnt")

+    public void whenProvisionONTDevice_sunnyFlow(DeviceService.OntProvisioningType provType) {

+

+

+        //setting up ontDevice

+        ontDevice.setSerialNumber("SOME_SERIAL_NUMBER");

+        ontDevice.setNumber(23);

+        ontDevice.setCTag(111);

+        ontDevice.setSTag(222);

+        ontDevice.setCircuitId("CIRCUIT_ID");

+        ontDevice.setNasPortId("NAS_PORT_ID");

+        ontDevice.setAdminState(AdminState.ENABLED);

+        ontDevice.setOperationalState(ActivityState.ACTIVE);

+        ontDevice.setPortAuthState(ActivityState.ACTIVE);

+

+        when(oltPortRepository.findByPortNumberAndOltSlot_NumberAndOltSlot_ChassisClli(1,1,TEST_CLLI)).thenReturn(Optional.ofNullable(oltPort));

+        when(abstractOLTClient.provisionONT(ontDevice)).thenReturn(true);

+        when(abstractOLTClient.preProvisionOnt(ontDevice)).thenReturn(true);

+        when(abstractOLTClient.provisionOntFull(ontDevice)).thenReturn(true);

+

+        //This is because in order to be inserted to hashset of oltSlots at the next command of tested function,

+        //the ONTDevice has to have ID

+        when(ontDeviceRepository.save(any())).thenReturn(ontDevice);

+

+       deviceService.provisionONTDevice(ontDevice, provType);

+

+       //checking that the copy to persisted object was as expected

+        verify(ontDeviceRepository, times(1)).save(ontDeviceCaptor.capture());

+        final ONTDevice capturedONTDevice = ontDeviceCaptor.getValue();

+

+        //TODO Pavel fix after discussion with Netsia regarding the returned object.

+        //Currently the assert will fail because internal object has no ID.

+        //I didn't want to use isEqualUsingSpecificFields, to catch set operations we might miss in the future

+        //assertThat(capturedONTDevice).isEqualToComparingFieldByField(ontDevice);

+

+        verify(oltPortRepository, times(1)).save(oltPort);

+    }

+

+    private Object[] provTypeToTestForOnt() {

+        return new Object[] {

+                new Object[] { DeviceService.OntProvisioningType.PROVISION },

+                new Object[] { DeviceService.OntProvisioningType.PREPROVISION },

+                new Object[] { DeviceService.OntProvisioningType.FULL }

+        };

+    }

+

+    @Test

+    @Parameters(method = "provTypeToTestForOnt")

+    public void whenAddONTDeviceNoPortFound_shouldThrowException(DeviceService.OntProvisioningType provType) {

+        when(oltPortRepository.findByPortNumberAndOltSlot_NumberAndOltSlot_ChassisClli(1,1,TEST_CLLI)).thenReturn(Optional.ofNullable(null));

+        assertThatThrownBy(()-> deviceService.provisionONTDevice(ontDevice, provType)).isInstanceOf(NotFoundException.class);

+

+    }

+

+    @Test

+    @Parameters(method = "provTypeToTestForOnt")

+    public void whenAddONTDeviceAbstractOLTError_shouldThrowException(DeviceService.OntProvisioningType provType) {

+        when(oltPortRepository.findByPortNumberAndOltSlot_NumberAndOltSlot_ChassisClli(1,1,TEST_CLLI)).thenReturn(Optional.ofNullable(oltPort));

+        when(abstractOLTClient.provisionONT(ontDevice)).thenReturn(false);

+        when(abstractOLTClient.preProvisionOnt(ontDevice)).thenReturn(false);

+        when(abstractOLTClient.provisionOntFull(ontDevice)).thenReturn(false);

+        assertThatThrownBy(()-> deviceService.provisionONTDevice(ontDevice, provType)).isInstanceOf(AbstractOLTException.class);

+

+    }

+

+    @Test

+    public void whenDeleteONTDevice_sunnyFlow() {

+        deviceService.deleteONTDevice(1L);

+        verify(ontDeviceRepository, times(1)).deleteById(1L);

+    }

+

+    @Test

+    public void whenGetONTDeviceById_sunnyFlow() {

+        when(ontDeviceRepository.findById(1L)).thenReturn(Optional.of(ontDevice));

+        ONTDevice actualOntDevice = deviceService.getONTDeviceById(1L);

+        assertThat(actualOntDevice).isSameAs(ontDevice);

+    }

+

+    @Test

+    public void whenGetONTDeviceNoId_shouldThrowException() {

+        assertThatThrownBy(()-> deviceService.getONTDeviceById(100L)).isInstanceOf(NotFoundException.class);

+

+    }

+

+    @Test

+    public void whenGetONTDeviceBySerialNumber_sunnyFlow() {

+        when(ontDeviceRepository.findBySerialNumber(TEST_SERIAL)).thenReturn(Optional.of(ontDevice));

+        ONTDevice actualOntDevice = deviceService.getONTDeviceBySerialNumber(TEST_SERIAL);

+        assertThat(actualOntDevice).isSameAs(ontDevice);

+    }

+

+    @Test

+    public void whenGetONTDeviceNoSerialNumber_shouldThrowException() {

+        assertThatThrownBy(()-> deviceService.getONTDeviceBySerialNumber(TEST_SERIAL)).isInstanceOf(NotFoundException.class);

+

+    }

+

+    @Test

+    public void whenGetAllONTDevices_sunnyFlow() {

+        final ArrayList<ONTDevice> devices = new ArrayList<>();

+        devices.add(ontDevice);

+        when(ontDeviceRepository.findAll()).thenReturn(devices);

+        ArrayList<ONTDevice> ontDevices = (ArrayList<ONTDevice>) deviceService.getAllONTDevices();

+        assertThat(ontDevices).isEqualTo(devices);

+    }

+}

diff --git a/osam-core/external/pom.xml b/osam-core/external/pom.xml
index 13724aa..9f1c4f1 100644
--- a/osam-core/external/pom.xml
+++ b/osam-core/external/pom.xml
@@ -53,7 +53,12 @@
         </dependency>

         <dependency>

             <groupId>org.onap.osam</groupId>

-            <artifactId>api</artifactId>

+            <artifactId>model</artifactId>

+            <version>${project.version}</version>

+        </dependency>

+        <dependency>

+            <groupId>org.onap.osam</groupId>

+            <artifactId>common</artifactId>

             <version>${project.version}</version>

         </dependency>

     </dependencies>

diff --git a/osam-core/external/src/main/java/org/onap/osam/external/grpc/AbstractOLTClient.java b/osam-core/external/src/main/java/org/onap/osam/external/grpc/AbstractOLTClient.java
index 688f00a..27c697d 100644
--- a/osam-core/external/src/main/java/org/onap/osam/external/grpc/AbstractOLTClient.java
+++ b/osam-core/external/src/main/java/org/onap/osam/external/grpc/AbstractOLTClient.java
@@ -56,13 +56,17 @@
 import io.grpc.ManagedChannel;

 import io.grpc.ManagedChannelBuilder;

 import lombok.extern.slf4j.Slf4j;

+import org.onap.osam.common.exception.AbstractOLTException;

 import org.onap.osam.common.exception.NotFoundException;

 import org.onap.osam.grpc.*;

 import org.onap.osam.model.dao.Chassis;

+import org.onap.osam.model.dao.OLTPort;

 import org.onap.osam.model.dao.OLTSlot;

+import org.onap.osam.model.dao.ONTDevice;

 import org.springframework.beans.factory.annotation.Value;

 import org.springframework.context.annotation.PropertySource;

 import org.springframework.stereotype.Component;

+import org.springframework.util.StringUtils;

 

 import javax.annotation.PostConstruct;

 

@@ -91,18 +95,13 @@
   }

 

   /** create chassis */

-  public String createChassis(Chassis chassis) {

-

-      String deviceID = null;

+  public void createChassis(Chassis chassis) {

 

       log.info("createChassis begin, chassis: {}", chassis);

 

       String clli = chassis.getClli();

       int rack = chassis.getRack();

       int shelf = chassis.getShelf();

-      if (chassis.getAccessPod() == null) {

-          throw new NotFoundException("Access pod not found");

-      }

       String xosIP = chassis.getAccessPod().getCoreIp();

       int port = Integer.parseInt(chassis.getAccessPod().getCorePort());

       String user = chassis.getAccessPod().getUsername();

@@ -119,9 +118,12 @@
               .build();

 

       AddChassisReturn response = blockingStub.createChassis(request);

-      deviceID = response.getDeviceID();

-      log.info("createChassis with device id : " + deviceID);

-      return deviceID;

+      if(!StringUtils.isEmpty(response.getDeviceID())) {

+          log.info("Chassis created in AbstractOLT with clli : {}",clli);

+      } else {

+          log.error("DeviceId of created chassis in AbstractOLT is empty or null, chassis: {}", chassis);

+          throw new AbstractOLTException("DeviceId of created chassis in AbstractOLT is empty or null");

+      }

   }

 

     public String createOLTChassis(OLTSlot olt) {

@@ -147,35 +149,69 @@
             AddOLTChassisReturn response = blockingStub.createOLTChassis(request);

             deviceID = response.getDeviceID();

             chassisDeviceId = response.getChassisDeviceID();

-            log.info("createOLTChassis with device id : {} chassisDeviceId : {}",chassisDeviceId,deviceID);

+            if(!StringUtils.isEmpty(response.getDeviceID()) && !StringUtils.isEmpty(response.getChassisDeviceID())) {

+                log.info("OLT Chassis created in AbstractOLT deviceId : {} chassisDeviceId : {}",deviceID,chassisDeviceId);

+            } else {

+                log.error("Invalid return argument from AbstractOLT, deviceId : {} chassisDeviceId : {}",deviceID,chassisDeviceId);

+                throw new AbstractOLTException("DeviceId of created chassis in AbstractOLT is empty or null");

+            }

 

         } catch (RuntimeException e) {

-            log.error("createOLTChassis RPC failed", e);

+            log.error("OLT Chassis creation failed", e);

+            throw new AbstractOLTException("OLT Chassis creation failed for olt : {}", olt);

         }

 

         return deviceID;

     }

 

-    public boolean provisionONT(String clli, int slotNumber, int portNumber, int ontNumber, String serialNumber) {

+    public boolean preProvisionOnt(ONTDevice ontDevice) {

+

+      boolean result = false;

+

+        try {

+            PreProvisionOntMessage preProvisionOntMessage = OntMessageFactory.getPreProvisionOntMessage(ontDevice);

+            AddOntReturn response = blockingStub.preProvisionOnt(preProvisionOntMessage);

+            result = response.getSuccess();

+            log.info("preProvisionOnt with device id : {} success : {}" ,ontDevice.getSerialNumber(), result);

+        } catch (RuntimeException e) {

+            log.error("preProvisionOnt RPC failed", e);

+            throw new AbstractOLTException("preProvisionOnt failed for ont : {}", ontDevice);

+        }

+

+      return result;

+    }

+

+    public boolean provisionONT(ONTDevice ontDevice) {

 

         boolean result = false;

 

         try {

-            log.info("provisionONT begin, clli: {}, slotNumber: {}, portNumber:{}, ontNumber:{}, serialNumber:{}", clli, slotNumber, portNumber, ontNumber, serialNumber);

-            AddOntMessage request = AddOntMessage.newBuilder()

-                    .setCLLI(clli)

-                    .setPortNumber(portNumber)

-                    .setSlotNumber(slotNumber)

-                    .setOntNumber(ontNumber)

-                    .setSerialNumber(serialNumber)

-                    .build();

-

+            AddOntMessage request = OntMessageFactory.getOntMessage(ontDevice);

             AddOntReturn response = blockingStub.provisionOnt(request);

             result = response.getSuccess();

-            log.info("provisionONT with device id : {} success : {}" + serialNumber, result);

+            log.info("provisionONT with device id : {} success : {}",ontDevice.getSerialNumber(), result);

 

         } catch (RuntimeException e) {

             log.error("provisionONT RPC failed", e);

+            throw new AbstractOLTException("provisionONT failed for ont : {}", ontDevice);

+        }

+

+        return result;

+    }

+

+    public boolean provisionOntFull(ONTDevice ontDevice) {

+

+        boolean result = false;

+

+        try {

+            AddOntFullMessage addOntFullMessage = OntMessageFactory.getOntFullMessage(ontDevice);

+            AddOntReturn response = blockingStub.provisionOntFull(addOntFullMessage);

+            result = response.getSuccess();

+            log.info("provisionOntFull with device id : {} success : {}",ontDevice.getSerialNumber(), result);

+

+        } catch (RuntimeException e) {

+            log.error("provisionOntFull RPC failed", e);

+            throw new AbstractOLTException("provisionOntFull failed for ont : {}", ontDevice);

         }

 

         return result;

diff --git a/osam-core/external/src/main/java/org/onap/osam/external/grpc/OntMessageFactory.java b/osam-core/external/src/main/java/org/onap/osam/external/grpc/OntMessageFactory.java
new file mode 100644
index 0000000..ff89f0b
--- /dev/null
+++ b/osam-core/external/src/main/java/org/onap/osam/external/grpc/OntMessageFactory.java
@@ -0,0 +1,123 @@
+/*-

+ * ============LICENSE_START=======================================================

+ * OSAM Core

+ * ================================================================================

+ * Copyright (C) 2018 Netsia

+ * ================================================================================

+ * Licensed under the Apache License, Version 2.0 (the "License");

+ * you may not use this file except in compliance with the License.

+ * You may obtain a copy of the License at

+ *

+ *      http://www.apache.org/licenses/LICENSE-2.0

+ *

+ * Unless required by applicable law or agreed to in writing, software

+ * distributed under the License is distributed on an "AS IS" BASIS,

+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

+ * See the License for the specific language governing permissions and

+ * limitations under the License.

+ * ============LICENSE_END=========================================================

+ */

+

+package org.onap.osam.external.grpc;

+

+import lombok.extern.slf4j.Slf4j;

+import org.onap.osam.grpc.AddOntFullMessage;

+import org.onap.osam.grpc.AddOntMessage;

+import org.onap.osam.grpc.PreProvisionOntMessage;

+import org.onap.osam.model.dao.Chassis;

+import org.onap.osam.model.dao.OLTPort;

+import org.onap.osam.model.dao.OLTSlot;

+import org.onap.osam.model.dao.ONTDevice;

+

+@Slf4j

+public class OntMessageFactory {

+

+    public static PreProvisionOntMessage getPreProvisionOntMessage (ONTDevice ontDevice) {

+

+        OLTPort oltPort = ontDevice.getOLTPort();

+            OLTSlot oltSlot = oltPort.getOltSlot();

+            Chassis chassis = oltSlot.getChassis();

+            String clli = chassis.getClli();

+            String serialNumber = ontDevice.getSerialNumber();

+            int slotNumber = oltSlot.getNumber();

+            int portNumber = oltPort.getPortNumber();

+            int ontNumber = ontDevice.getNumber();

+            int stag = ontDevice.getSTag();

+            int ctag = ontDevice.getCTag();

+            String nasPortID = ontDevice.getNasPortId();

+            String circuitId = ontDevice.getCircuitId();

+            log.info("getPreProvisionOntMessage, clli: {}, serialNumber: {}, slotNumber: {}, portNumber:{}, ontNumber:{}, sTag:{}, cTag:{}, nasPortId:{}, circuitId:{}", clli, serialNumber, slotNumber, portNumber, ontNumber, stag, ctag,nasPortID, circuitId);

+

+            PreProvisionOntMessage preProvisionOntMessage = PreProvisionOntMessage.newBuilder()

+                    .setCLLI(clli)

+                    .setSlotNumber(slotNumber)

+                    .setPortNumber(portNumber)

+                    .setOntNumber(ontNumber)

+                    .setSTag(stag)

+                    .setCTag(ctag)

+                    .setNasPortID(nasPortID)

+                    .setCircuitID(circuitId)

+                    .build();

+            //TODO Handle technology and speed profiles later

+            log.info("PreProvisionOntMessage is {}", preProvisionOntMessage);

+            return  preProvisionOntMessage;

+

+    }

+

+

+    public static AddOntFullMessage getOntFullMessage (ONTDevice ontDevice) {

+

+        OLTPort oltPort = ontDevice.getOLTPort();

+        OLTSlot oltSlot = oltPort.getOltSlot();

+        Chassis chassis = oltSlot.getChassis();

+        String clli = chassis.getClli();

+        String serialNumber = ontDevice.getSerialNumber();

+        int slotNumber = oltSlot.getNumber();

+        int portNumber = oltPort.getPortNumber();

+        int ontNumber = ontDevice.getNumber();

+        int stag = ontDevice.getSTag();

+        int ctag = ontDevice.getCTag();

+        String nasPortID = ontDevice.getNasPortId();

+        String circuitId = ontDevice.getCircuitId();

+        log.info("getOntFullMessage, clli: {}, serialNumber: {}, slotNumber: {}, portNumber:{}, ontNumber:{}, sTag:{}, cTag:{}, nasPortId:{}, circuitId:{}", clli, serialNumber, slotNumber, portNumber, ontNumber, stag, ctag,nasPortID, circuitId);

+

+        AddOntFullMessage addOntFullMessage = AddOntFullMessage.newBuilder()

+                .setCLLI(clli)

+                .setSerialNumber(serialNumber)

+                .setSlotNumber(slotNumber)

+                .setPortNumber(portNumber)

+                .setOntNumber(ontNumber)

+                .setSTag(stag)

+                .setCTag(ctag)

+                .setNasPortID(nasPortID)

+                .setCircuitID(circuitId)

+                .build();

+        log.info("AddOntFullMessage is {}", addOntFullMessage);

+        return  addOntFullMessage;

+

+    }

+

+    public static AddOntMessage getOntMessage (ONTDevice ontDevice) {

+

+        OLTPort oltPort = ontDevice.getOLTPort();

+        OLTSlot oltSlot = oltPort.getOltSlot();

+        Chassis chassis = oltSlot.getChassis();

+        String clli = chassis.getClli();

+        String serialNumber = ontDevice.getSerialNumber();

+        int slotNumber = oltSlot.getNumber();

+        int portNumber = oltPort.getPortNumber();

+        int ontNumber = ontDevice.getNumber();

+        log.info("getOntFullMessage, clli: {}, serialNumber: {}, slotNumber: {}, portNumber:{}, ontNumber:{}", clli, serialNumber, slotNumber, portNumber, ontNumber);

+

+        AddOntMessage addOntMessage = AddOntMessage.newBuilder()

+                .setCLLI(clli)

+                .setSerialNumber(serialNumber)

+                .setSlotNumber(slotNumber)

+                .setPortNumber(portNumber)

+                .setOntNumber(ontNumber)

+                .build();

+        log.info("AddOntMessage is {}", addOntMessage);

+        return  addOntMessage;

+

+    }

+}

diff --git a/osam-core/external/src/main/proto/abstract_olt_api.proto b/osam-core/external/src/main/proto/abstract_olt_api.proto
index ce9a322..055acd9 100644
--- a/osam-core/external/src/main/proto/abstract_olt_api.proto
+++ b/osam-core/external/src/main/proto/abstract_olt_api.proto
@@ -1,149 +1,222 @@
-//Copyright 2017 the original author or authors.

-//

-//  Licensed under the Apache License, Version 2.0 (the "License");

-//  you may not use this file except in compliance with the License.

-//  You may obtain a copy of the License at

-

-//       http://www.apache.org/licenses/LICENSE-2.0

-

-//  Unless required by applicable law or agreed to in writing, software

-//  distributed under the License is distributed on an "AS IS" BASIS,

-//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

-//  See the License for the specific language governing permissions and

-//  limitations under the License.

-

-syntax = "proto3";

-package api;

-import "google/api/annotations.proto";

-

-option java_multiple_files = true;

-option java_package = "org.onap.osam.grpc";

-option java_outer_classname = "AbstractOLTProto";

-

-message EchoMessage{

-   string Ping =1;

-}

-message EchoReplyMessage{

-   string Pong =1;

-}

-

-message AddChassisMessage{

-   string CLLI =1;

-   string XOSIP =2;

-   int32 XOSPort=3;

-   string XOSUser=4;

-   string XOSPassword=5;

-   int32 Rack=6;

-   int32 Shelf=7;

-}

-message AddChassisReturn{

-   string DeviceID = 1;

-}

-message ChangeXOSUserPasswordMessage{

-   string CLLI =1;

-   string XOSUser=2;

-   string XOSPassword=3;

-}

-message ChangeXOSUserPasswordReturn{

-   bool Success=1;

-}

-

-message AddOLTChassisMessage{

-   string CLLI=1;

-   string SlotIP=2;

-   fixed32 SlotPort=3;

-   string Hostname=4;

-   fixed32 NumPorts = 5;

-   bool Activate = 6;

-   enum OltDriver {

-      openoltDriver= 0;

-      asfvolt16Driver=1;

-      adtranDriver=2;

-      tibitsDriver=3;

-   }

-   OltDriver Driver=7;

-   enum OltType{

-      edgecore=0;

-      adtran=1;

-      tibit=2;

-   }

-   OltType Type=8;

-

-}

-message AddOLTChassisReturn {

-   string DeviceID =1;

-   string ChassisDeviceID =2;

-}

-

-message AddOntMessage{

-   string CLLI=1;

-   int32 SlotNumber=2;

-   int32 PortNumber=3;

-   int32 OntNumber=4;

-   string SerialNumber=5;

-}

-message AddOntReturn{

-   bool Success=1;

-}

-

-message DeleteOntMessage{

-   string CLLI=1;

-   int32 SlotNumber=2;

-   int32 PortNumber=3;

-   int32 OntNumber=4;

-   string SerialNumber=5;

-}

-message DeleteOntReturn{

-   bool Success=1;

-}

-message OutputMessage{

-   string Something=1;

-}

-message OutputReturn{

-   bool Success=1;

-}

-service AbstractOLT{

-   rpc Echo(EchoMessage) returns (EchoReplyMessage){

-      option(google.api.http)={

-        post:"/v1/Echo"

-	body:"*"

-      };

-   }

-   rpc CreateChassis(AddChassisMessage) returns (AddChassisReturn) {

-      option(google.api.http) = {

-         post: "/v1/CreateAbstractChassis"

-	 body:"*"

-      };

-   }

-   rpc ChangeXOSUserPassword(ChangeXOSUserPasswordMessage) returns(ChangeXOSUserPasswordReturn){

-      option(google.api.http)={

-        post:"/v1/ChangeXOSUserPassword"

-	body:"*"

-      };

-   }

-   rpc CreateOLTChassis(AddOLTChassisMessage) returns (AddOLTChassisReturn) {

-      option(google.api.http) = {

-         post: "/v1/CreateOLTChassis"

-	 body:"*"

-      };

-   }

-   rpc ProvisionOnt(AddOntMessage) returns (AddOntReturn) {

-      option(google.api.http) = {

-         post:"/v1/ProvsionOnt"

-	 body:"*"

-      };

-   }

-   rpc DeleteOnt(DeleteOntMessage) returns (DeleteOntReturn){

-      option(google.api.http)={

-        post:"/v1/DeleteOnt"

-	body:"*"

-      };

-   }

-   rpc Output(OutputMessage)returns(OutputReturn){

-      option(google.api.http)={

-        post:"/v1/Output"

-	body:"*"

-      };

-   }

-}

-

+//Copyright 2017 the original author or authors.
+//
+//  Licensed under the Apache License, Version 2.0 (the "License");
+//  you may not use this file except in compliance with the License.
+//  You may obtain a copy of the License at
+
+//       http://www.apache.org/licenses/LICENSE-2.0
+
+//  Unless required by applicable law or agreed to in writing, software
+//  distributed under the License is distributed on an "AS IS" BASIS,
+//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+//  See the License for the specific language governing permissions and
+//  limitations under the License.
+
+syntax = "proto3";
+package api;
+import "google/api/annotations.proto";
+
+option java_multiple_files = true;
+option java_package = "org.onap.osam.grpc";
+option java_outer_classname = "AbstractOLTProto";
+
+message EchoMessage{
+   string Ping =1;
+}
+message EchoReplyMessage{
+   string Pong =1;
+}
+
+message AddChassisMessage{
+   string CLLI =1;
+   string XOSIP =2;
+   int32 XOSPort=3;
+   string XOSUser=4;
+   string XOSPassword=5;
+   int32 Rack=6;
+   int32 Shelf=7;
+}
+message AddChassisReturn{
+   string DeviceID = 1;
+}
+message ChangeXOSUserPasswordMessage{
+   string CLLI =1;
+   string XOSUser=2;
+   string XOSPassword=3;
+}
+message ChangeXOSUserPasswordReturn{
+   bool Success=1;
+}
+
+message AddOLTChassisMessage{
+   string CLLI=1;
+   string SlotIP=2;
+   fixed32 SlotPort=3;
+   string Hostname=4;
+   fixed32 NumPorts = 5;
+   bool Activate = 6;
+   enum OltDriver {
+      openoltDriver= 0;
+      asfvolt16Driver=1;
+      adtranDriver=2;
+      tibitsDriver=3;
+   }
+   OltDriver Driver=7;
+   enum OltType{
+      edgecore=0;
+      adtran=1;
+      tibit=2;
+   }
+   OltType Type=8;
+
+}
+message AddOLTChassisReturn {
+   string DeviceID =1;
+   string ChassisDeviceID =2;
+}
+
+message AddOntMessage{
+   string CLLI=1;
+   int32 SlotNumber=2;
+   int32 PortNumber=3;
+   int32 OntNumber=4;
+   string SerialNumber=5;
+}
+message PreProvisionOntMessage{
+   string CLLI=1;
+   int32 SlotNumber=2;
+   int32 PortNumber=3;
+   int32 OntNumber=4;
+   uint32 STag=5;
+   uint32 CTag=6;
+   string NasPortID=7;
+   string CircuitID=8;
+   string TechProfile=9;
+   string SpeedProfile=10;
+}
+message AddOntFullMessage{
+   string CLLI=1;
+   int32 SlotNumber=2;
+   int32 PortNumber=3;
+   int32 OntNumber=4;
+   string SerialNumber=5;
+   uint32 STag=6;
+   uint32 CTag=7;
+   string NasPortID=8;
+   string CircuitID=9;
+}
+message AddOntReturn{
+   bool Success=1;
+}
+
+message DeleteOntMessage{
+   string CLLI=1;
+   int32 SlotNumber=2;
+   int32 PortNumber=3;
+   int32 OntNumber=4;
+   string SerialNumber=5;
+}
+message DeleteOntReturn{
+   bool Success=1;
+}
+message ReflowMessage{
+}
+message ReflowReturn{
+    bool Success=1;
+}
+message OutputMessage{
+   string Something=1;
+}
+message OutputReturn{
+   bool Success=1;
+}
+message FullInventoryMessage{
+}
+message InventoryMessage{
+   string Clli=1;
+}
+message InventoryReturn{
+   string JsonDump=1;
+}
+service AbstractOLT{
+   rpc Echo(EchoMessage) returns (EchoReplyMessage){
+      option(google.api.http)={
+        post:"/v1/Echo"
+	body:"*"
+      };
+   }
+   rpc CreateChassis(AddChassisMessage) returns (AddChassisReturn) {
+      option(google.api.http) = {
+         post: "/v1/CreateAbstractChassis"
+	 body:"*"
+      };
+   }
+   rpc ChangeXOSUserPassword(ChangeXOSUserPasswordMessage) returns(ChangeXOSUserPasswordReturn){
+      option(google.api.http)={
+        post:"/v1/ChangeXOSUserPassword"
+	body:"*"
+      };
+   }
+   rpc CreateOLTChassis(AddOLTChassisMessage) returns (AddOLTChassisReturn) {
+      option(google.api.http) = {
+         post: "/v1/CreateOLTChassis"
+	 body:"*"
+      };
+   }
+   rpc PreProvisionOnt(PreProvisionOntMessage) returns (AddOntReturn) {
+      option(google.api.http) = {
+         post:"/v1/PreProvsionOnt"
+	 body:"*"
+      };
+   }
+   rpc ActivateSerial(AddOntMessage) returns (AddOntReturn) {
+      option(google.api.http) = {
+         post:"/v1/ActivateSerial"
+	 body:"*"
+      };
+   }
+   rpc ProvisionOnt(AddOntMessage) returns (AddOntReturn) {
+      option(google.api.http) = {
+         post:"/v1/ProvsionOnt"
+	 body:"*"
+      };
+   }
+   rpc ProvisionOntFull(AddOntFullMessage) returns (AddOntReturn) {
+      option(google.api.http) = {
+         post:"/v1/ProvsionOtFull"
+	 body:"*"
+      };
+   }
+   rpc DeleteOnt(DeleteOntMessage) returns (DeleteOntReturn){
+      option(google.api.http)={
+        post:"/v1/DeleteOnt"
+	body:"*"
+      };
+   }
+   rpc Reflow(ReflowMessage)returns (ReflowReturn){
+       option(google.api.http)={
+           post:"/v1/Reflow"
+           body:"*"
+
+       };
+   }
+   rpc Output(OutputMessage)returns(OutputReturn){
+      option(google.api.http)={
+        post:"/v1/Output"
+	    body:"*"
+      };
+   }
+   rpc GetFullInventory(FullInventoryMessage)returns(InventoryReturn){
+      option(google.api.http)={
+        post:"/v1/FullInventory"
+	    body:"*"
+      };
+   }
+   rpc GetInventory(InventoryMessage)returns(InventoryReturn){
+      option(google.api.http)={
+        post:"/v1/Inventory"
+	    body:"*"
+      };
+   }
+}
+
diff --git a/osam-core/model/src/main/java/org/onap/osam/model/dao/ONTDevice.java b/osam-core/model/src/main/java/org/onap/osam/model/dao/ONTDevice.java
index 17666a6..804627f 100644
--- a/osam-core/model/src/main/java/org/onap/osam/model/dao/ONTDevice.java
+++ b/osam-core/model/src/main/java/org/onap/osam/model/dao/ONTDevice.java
@@ -45,6 +45,12 @@
     private String ipAddress;

     private String macAddress;

     private int number;

+    private int sTag;

+    private int cTag;

+    private String nasPortId;

+    private String circuitId;

+    private TechnologyProfile techProfile;

+    private SpeedProfile speedProfile;

     @ManyToOne

     @JoinColumn(name="OLTPort_id", nullable=false)

     private OLTPort OLTPort;

@@ -60,7 +66,13 @@
         sb.append(", macAddress='").append(macAddress).append('\'');

         sb.append(", number='").append(number).append('\'');

         sb.append(", ipAddress=").append(ipAddress);

+        sb.append(", sTag=").append(ipAddress);

+        sb.append(", cTag=").append(cTag);

+        sb.append(", nasPortId=").append(nasPortId);

+        sb.append(", circuitId=").append(circuitId);

+        sb.append(", techProfile=").append(techProfile);

+        sb.append(", speedProfile=").append(speedProfile);

         sb.append('}');

         return sb.toString();

     }

-}

+}
\ No newline at end of file
diff --git a/osam-core/model/src/main/java/org/onap/osam/model/dao/SpeedProfile.java b/osam-core/model/src/main/java/org/onap/osam/model/dao/SpeedProfile.java
index d4bf1c1..a3994da 100644
--- a/osam-core/model/src/main/java/org/onap/osam/model/dao/SpeedProfile.java
+++ b/osam-core/model/src/main/java/org/onap/osam/model/dao/SpeedProfile.java
@@ -39,13 +39,14 @@
 

     @Enumerated(value = EnumType.STRING)

     private StreamDirection streamDirection;

-

+    private String name;

     private String data;

 

     @Override

     public String toString() {

         final StringBuilder sb = new StringBuilder("SpeedProfile{");

         sb.append("streamDirection=").append(streamDirection);

+        sb.append(", name='").append(name).append('\'');

         sb.append(", data='").append(data).append('\'');

         sb.append(", id=").append(id);

         sb.append('}');

diff --git a/osam-core/model/src/main/java/org/onap/osam/model/dao/TechnologyProfile.java b/osam-core/model/src/main/java/org/onap/osam/model/dao/TechnologyProfile.java
index f352bd4..e13b245 100644
--- a/osam-core/model/src/main/java/org/onap/osam/model/dao/TechnologyProfile.java
+++ b/osam-core/model/src/main/java/org/onap/osam/model/dao/TechnologyProfile.java
@@ -35,13 +35,15 @@
 @Setter

 public class TechnologyProfile extends BaseEntity {

 

+    private String name;

     private String data;

 

     @Override

     public String toString() {

         final StringBuilder sb = new StringBuilder("TechnologyProfile{");

-        sb.append("data='").append(data).append('\'');

-        sb.append(", id=").append(id);

+        sb.append("id='").append(id).append('\'');

+        sb.append(", name=").append(name);

+        sb.append(", data=").append(data);

         sb.append('}');

         return sb.toString();

     }

diff --git a/osam-core/pom.xml b/osam-core/pom.xml
index c207ad8..90b8377 100644
--- a/osam-core/pom.xml
+++ b/osam-core/pom.xml
@@ -37,6 +37,7 @@
 		<guava.version>20.0</guava.version>

 		<msb.sdk.version>1.2.0-SNAPSHOT</msb.sdk.version>

 		<swagger.version>2.8.0</swagger.version>

+        <junitparams.version>1.1.1</junitparams.version>

 	</properties>

 

 	<dependencies>

@@ -64,6 +65,12 @@
 			<scope>test</scope>

 		</dependency>

         <dependency>

+            <groupId>pl.pragmatists</groupId>

+            <artifactId>JUnitParams</artifactId>

+            <version>${junitparams.version}</version>

+            <scope>test</scope>

+        </dependency>

+        <dependency>

             <groupId>org.testng</groupId>

             <artifactId>testng</artifactId>

             <version>6.14.3</version>

diff --git a/osam-core/web/src/main/java/org/onap/osam/controller/AbstractController.java b/osam-core/web/src/main/java/org/onap/osam/controller/AbstractController.java
index 97bfa7c..474c2c9 100644
--- a/osam-core/web/src/main/java/org/onap/osam/controller/AbstractController.java
+++ b/osam-core/web/src/main/java/org/onap/osam/controller/AbstractController.java
@@ -24,6 +24,7 @@
 

 import org.onap.osam.common.exception.BadFormatException;

 import org.onap.osam.common.exception.NotFoundException;

+import org.onap.osam.common.exception.ServerException;

 import org.onap.osam.common.exception.UnknownTypeException;

 import org.slf4j.Logger;

 import org.springframework.http.HttpStatus;

@@ -45,6 +46,8 @@
             return ResponseEntity.status(HttpStatus.BAD_REQUEST).build();

         } else if(e instanceof NotFoundException) {

             return ResponseEntity.status(HttpStatus.NOT_FOUND).build();

+        } else if(e instanceof ServerException) {

+            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();

         } else {

             logger.error("",e);

             return ResponseEntity.status(HttpStatus.SERVICE_UNAVAILABLE).build();

diff --git a/osam-core/web/src/main/java/org/onap/osam/controller/AccessPodRestController.java b/osam-core/web/src/main/java/org/onap/osam/controller/AccessPodRestController.java
index b4fbec0..ad901c5 100644
--- a/osam-core/web/src/main/java/org/onap/osam/controller/AccessPodRestController.java
+++ b/osam-core/web/src/main/java/org/onap/osam/controller/AccessPodRestController.java
@@ -65,9 +65,9 @@
     public ResponseEntity<AccessPodDTO> postAccessPod(@RequestBody AccessPodDTO accessPodDTO){

         try {

             log.info("Post request for {} is received",accessPodDTO);

-            AccessPod accessPod = DTOMapper.covertDtoToAccessPod(accessPodDTO);

+            AccessPod accessPod = DTOMapper.convertDtoToAccessPod(accessPodDTO);

             accessPod = accessPodService.addOrUpdate(accessPod);

-            return new ResponseEntity<>(DTOMapper.covertAccessPodToDto(accessPod),HttpStatus.CREATED);

+            return new ResponseEntity<>(DTOMapper.convertAccessPodToDto(accessPod),HttpStatus.CREATED);

         }catch (Exception e){

             return super.proceedException(e);

         }

diff --git a/osam-core/web/src/main/java/org/onap/osam/controller/DeviceController.java b/osam-core/web/src/main/java/org/onap/osam/controller/DeviceController.java
index 026ec17..b5b0103 100644
--- a/osam-core/web/src/main/java/org/onap/osam/controller/DeviceController.java
+++ b/osam-core/web/src/main/java/org/onap/osam/controller/DeviceController.java
@@ -93,13 +93,10 @@
 

     }

 

-    @PostMapping("/chassis/olt/ont")

-    public ResponseEntity<ONTDTO> postONTDevice(@RequestBody ONTDTO ontDTO){

+    @PostMapping("/chassis/olt/ont-provision")

+    public ResponseEntity<ONTDTO> provisionONTDevice(@RequestBody ONTDTO ontDTO){

         try {

-            ONTDevice ont = deviceService.addONTDevice(ontDTO.getClli()

-                    ,ontDTO.getSlotNumber()

-                    ,ontDTO.getPortNumber()

-                    ,ontDTO.getSerialNumber());

+            ONTDevice ont = deviceService.provisionONTDevice(DTOMapper.convertToONTDevice(ontDTO), DeviceService.OntProvisioningType.PROVISION);

             return new ResponseEntity<> (DTOMapper.convertFromONTDevice(ont),HttpStatus.CREATED);

         }catch (Exception e){

             return super.proceedException(e);

@@ -107,6 +104,39 @@
 

     }

 

+    @PostMapping("/chassis/olt/ont-full")

+    public ResponseEntity<ONTDTO> provisionONTDeviceFull(@RequestBody ONTDTO ontDTO){

+        try {

+            ONTDevice ont = deviceService.provisionONTDevice(DTOMapper.convertToONTDevice(ontDTO), DeviceService.OntProvisioningType.FULL);

+            return new ResponseEntity<> (DTOMapper.convertFromONTDevice(ont),HttpStatus.CREATED);

+        }catch (Exception e){

+            return super.proceedException(e);

+        }

+

+    }

+

+    @PostMapping("/chassis/olt/ont-preprovision")

+    public ResponseEntity<ONTDTO> preprovisionONTDevice(@RequestBody ONTDTO ontDTO){

+        try {

+            ONTDevice ont = deviceService.provisionONTDevice(DTOMapper.convertToONTDevice(ontDTO), DeviceService.OntProvisioningType.PREPROVISION);

+            return new ResponseEntity<> (DTOMapper.convertFromONTDevice(ont),HttpStatus.CREATED);

+        }catch (Exception e){

+            return super.proceedException(e);

+        }

+

+    }

+

+    @DeleteMapping("chassis/olt/ont/{ontid}")

+    public ResponseEntity deleteOntById(@PathVariable("ontid") String ontid) {

+        try{

+            this.deviceService.deleteONTDevice(new Long(ontid));

+            return ResponseEntity.ok().build();

+        }catch (Exception e) {

+            return super.proceedException(e);

+        }

+

+    }

+

     @GetMapping("/chassis")

     public ResponseEntity<List<ChassisDTO>> getAllChassis(){

         try {

diff --git a/osam-core/web/src/main/java/org/onap/osam/dto/ONTDTO.java b/osam-core/web/src/main/java/org/onap/osam/dto/ONTDTO.java
index d21d9e3..d6fd982 100644
--- a/osam-core/web/src/main/java/org/onap/osam/dto/ONTDTO.java
+++ b/osam-core/web/src/main/java/org/onap/osam/dto/ONTDTO.java
@@ -39,5 +39,12 @@
     private String serialNumber;

     private int slotNumber;

     private int portNumber;

+    private int ontNumber;

     private Long id;

+    private int stag;

+    private int ctag;

+    private String nasPortId;

+    private String circuitId;

+    private String technologyProfile;

+    private String speedProfile;

 }

diff --git a/osam-core/web/src/main/java/org/onap/osam/helper/DTOMapper.java b/osam-core/web/src/main/java/org/onap/osam/helper/DTOMapper.java
index 3a8784f..81d14f5 100644
--- a/osam-core/web/src/main/java/org/onap/osam/helper/DTOMapper.java
+++ b/osam-core/web/src/main/java/org/onap/osam/helper/DTOMapper.java
@@ -28,19 +28,11 @@
 import org.onap.osam.dto.OLTChassisDTO;

 import org.onap.osam.dto.OLTPortDTO;

 import org.onap.osam.dto.ONTDTO;

-import org.onap.osam.model.dao.AccessPod;

-import org.onap.osam.model.dao.ActivityState;

-import org.onap.osam.model.dao.Chassis;

-import org.onap.osam.model.dao.OLTPort;

-import org.onap.osam.model.dao.OLTSlot;

-import org.onap.osam.model.dao.ONTDevice;

-import org.onap.osam.model.dao.OltDriver;

-import org.onap.osam.model.dao.OltType;

+import org.onap.osam.model.dao.*;

 

 import java.util.ArrayList;

 import java.util.List;

 import java.util.Map;

-import java.util.function.Function;

 import java.util.stream.Collectors;

 

 

@@ -112,14 +104,49 @@
         ontdto.setId(ontDevice.getId());

         ontdto.setSlotNumber(ontDevice.getOLTPort().getOltSlot().getNumber());

         ontdto.setClli(ontDevice.getOLTPort().getOltSlot().getChassis().getClli());

+        ontdto.setCtag(ontDevice.getCTag());

+        ontdto.setStag(ontDevice.getSTag());

+        ontdto.setCircuitId(ontDevice.getCircuitId());

+        ontdto.setNasPortId(ontDevice.getNasPortId());

+        if (ontDevice.getTechProfile() != null) {

+            ontdto.setTechnologyProfile(ontDevice.getTechProfile().getName());

+        }

+        if (ontDevice.getSpeedProfile() != null) {

+            ontdto.setSpeedProfile(ontDevice.getSpeedProfile().getName());

+        }

         return ontdto;

     }

 

+    public static ONTDevice convertToONTDevice (ONTDTO ontdto) {

+        ONTDevice ontDevice = new ONTDevice();

+        ontDevice.setNumber(ontdto.getOntNumber());

+        ontDevice.setSerialNumber(ontdto.getSerialNumber());

+        ontDevice.setCTag(ontdto.getCtag());

+        ontDevice.setSTag(ontdto.getStag());

+        ontDevice.setCircuitId(ontdto.getCircuitId());

+        ontDevice.setNasPortId(ontdto.getNasPortId());

+        TechnologyProfile technologyProfile = new TechnologyProfile();

+        technologyProfile.setName(ontdto.getTechnologyProfile());

+        ontDevice.setTechProfile(technologyProfile);

+        SpeedProfile speedProfile = new SpeedProfile();

+        speedProfile.setName(ontdto.getSpeedProfile());

+        ontDevice.setSpeedProfile(speedProfile);

+        Chassis chassis = new Chassis();

+        chassis.setClli(ontdto.getClli());

+        OLTSlot oltSlot = new OLTSlot();

+        oltSlot.setChassis(chassis);

+        OLTPort oltPort = new OLTPort();

+        oltPort.setPortNumber(ontdto.getPortNumber());

+        oltPort.setOltSlot(oltSlot);

+        ontDevice.setOLTPort(oltPort);

+        return ontDevice;

+    }

+

     public static Map<String, List<ONTDTO>> convertFromONTDevice(List<ONTDevice> ontDevices){

         return ontDevices.stream().map(x -> convertFromONTDevice(x)).collect(Collectors.toList()).stream().collect(Collectors.groupingBy(ONTDTO::getClli));

     }

 

-    public static AccessPod covertDtoToAccessPod(AccessPodDTO dto) {

+    public static AccessPod convertDtoToAccessPod(AccessPodDTO dto) {

         //TODO validate..

         AccessPod accessPod = new AccessPod();

         accessPod.setPnfId(dto.getPnfId());

@@ -133,7 +160,7 @@
         return accessPod;

     }

 

-    public static AccessPodDTO covertAccessPodToDto(AccessPod accessPod) {

+    public static AccessPodDTO convertAccessPodToDto(AccessPod accessPod) {

         //TODO validate..

         AccessPodDTO dto = new AccessPodDTO();

         dto.setPnfId(accessPod.getPnfId());

@@ -160,7 +187,7 @@
         //TODO validate..

         List<AccessPodDTO> dtos = new ArrayList<>();

         for (AccessPod accessPod : accessPodList) {

-            dtos.add(covertAccessPodToDto(accessPod));

+            dtos.add(convertAccessPodToDto(accessPod));

         }

         return dtos;

     }

@@ -169,7 +196,7 @@
         if (accessPod == null) {

             return null;

         }

-        AccessPodDTO accessPodDTO = covertAccessPodToDto(accessPod);

+        AccessPodDTO accessPodDTO = convertAccessPodToDto(accessPod);

         if (chassisList == null || chassisList.isEmpty()) {

             return accessPodDTO;

         }