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

Change-Id: I7dce313ef9ecba79a05261f2ef7c858b51ed3d35
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:"*"
+      };
+   }
+}
+