Realize the PNF registration API 37/61237/3
authorZi Li <li.zi30@zte.com.cn>
Mon, 20 Aug 2018 09:11:48 +0000 (09:11 +0000)
committerZi Li <li.zi30@zte.com.cn>
Mon, 20 Aug 2018 09:20:39 +0000 (09:20 +0000)
Issue-ID: AAI-1496

Change-Id: Iece0706db599990131fef2fa1b6b9159e8f967e4
Signed-off-by: Zi Li <li.zi30@zte.com.cn>
esr-mgr/src/main/java/org/onap/aai/esr/common/MsbConfig.java
esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/Pnf.java [moved from esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/EsrPnf.java with 98% similarity]
esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/PnfList.java [moved from esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/EsrPnfList.java with 84% similarity]
esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/INetwork.java [new file with mode: 0644]
esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/NetworkProxy.java [new file with mode: 0644]
esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/PnfRegisterProvider.java [new file with mode: 0644]
esr-mgr/src/main/java/org/onap/aai/esr/util/PnfManagerUtil.java [new file with mode: 0644]
esr-mgr/src/main/java/org/onap/aai/esr/wrapper/PnfManagerWrapper.java
esr-mgr/src/test/java/org/onap/aai/esr/wrapper/PnfManagerWrapperTest.java [new file with mode: 0644]

index b378b22..3d827a8 100644 (file)
@@ -26,6 +26,8 @@ public class MsbConfig {
     protected static String cloudInfrastructureAddr;
 
     protected static String externalSystemAddr;
     protected static String cloudInfrastructureAddr;
 
     protected static String externalSystemAddr;
+    
+    protected static String networkAddr;
 
     protected static String multiCloudAddr;
 
 
     protected static String multiCloudAddr;
 
@@ -49,6 +51,14 @@ public class MsbConfig {
         externalSystemAddr = Addr;
     }
 
         externalSystemAddr = Addr;
     }
 
+    public static String getNetworkAddr() {
+        return msbServerAddr + "/api/aai-network/v11";
+    }
+    
+    public static void setNetworkAddr(String address) {
+        networkAddr = address;
+    }
+    
     public static void setMultiCloudAddr(String address) {
         multiCloudAddr = address;
     }
     public static void setMultiCloudAddr(String address) {
         multiCloudAddr = address;
     }
@@ -18,7 +18,7 @@ package org.onap.aai.esr.entity.aai;
 import java.io.Serializable;
 import com.google.gson.annotations.SerializedName;
 
 import java.io.Serializable;
 import com.google.gson.annotations.SerializedName;
 
-public class EsrPnf implements Serializable{
+public class Pnf implements Serializable{
 
     public static final long serialVersionUID = 1L;
 
 
     public static final long serialVersionUID = 1L;
 
@@ -19,18 +19,18 @@ import java.io.Serializable;
 import java.util.List;
 import com.google.gson.annotations.SerializedName;
 
 import java.util.List;
 import com.google.gson.annotations.SerializedName;
 
-public class EsrPnfList implements Serializable{
+public class PnfList implements Serializable{
 
     public static final long serialVersionUID = 1L;
 
     @SerializedName("pnf")
 
     public static final long serialVersionUID = 1L;
 
     @SerializedName("pnf")
-    private List<EsrPnf> pnf;
+    private List<Pnf> pnf;
 
 
-    public List<EsrPnf> getPnf() {
+    public List<Pnf> getPnf() {
         return pnf;
     }
 
         return pnf;
     }
 
-    public void setPnf(List<EsrPnf> pnf) {
+    public void setPnf(List<Pnf> pnf) {
         this.pnf = pnf;
     }
 }
         this.pnf = pnf;
     }
 }
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/INetwork.java b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/INetwork.java
new file mode 100644 (file)
index 0000000..c159da7
--- /dev/null
@@ -0,0 +1,37 @@
+/**
+ * Copyright 2018 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.onap.aai.esr.externalservice.aai;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.HeaderParam;
+import javax.ws.rs.PUT;
+import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import org.onap.aai.esr.entity.aai.Pnf;
+import org.onap.aai.esr.exception.ExtsysException;
+
+@Path("/")
+public interface INetwork {
+    @PUT
+    @Path("/pnfs/pnf/{pnfName}")
+    @Consumes(MediaType.APPLICATION_JSON)
+    @Produces(MediaType.APPLICATION_JSON)
+    public void registerPnfService(@HeaderParam("X-TransactionId") String transactionId,
+            @HeaderParam("X-FromAppId") String fromApp, @HeaderParam("Authorization") String authorization,
+            @PathParam("pnfName") String pnfName, Pnf pnf) throws ExtsysException;
+}
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/NetworkProxy.java b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/NetworkProxy.java
new file mode 100644 (file)
index 0000000..933ecea
--- /dev/null
@@ -0,0 +1,46 @@
+/**
+ * Copyright 2018 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.onap.aai.esr.externalservice.aai;
+
+import org.glassfish.jersey.client.ClientConfig;
+import org.onap.aai.esr.common.MsbConfig;
+import org.onap.aai.esr.entity.aai.Pnf;
+import org.onap.aai.esr.exception.ExtsysException;
+import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
+
+public class NetworkProxy {
+
+    private static INetwork network;
+    private static String transactionId = "9999";
+    private static String fromAppId = "esr-server";
+    private static String authorization = AaiCommon.getAuthenticationCredentials();
+    static {
+        ClientConfig config = new ClientConfig();
+        network =
+                ConsumerFactory.createConsumer(MsbConfig.getNetworkAddr(), config, INetwork.class);
+    }
+
+    public void registerPnf(String pnfName, Pnf pnf) throws ExtsysException {
+        ClientConfig config = new ClientConfig(new PnfRegisterProvider());
+        INetwork registerPnfServiceproxy =
+                ConsumerFactory.createConsumer(MsbConfig.getNetworkAddr(), config, INetwork.class);
+        try {
+            registerPnfServiceproxy.registerPnfService(transactionId, fromAppId, authorization, pnfName, pnf);
+        } catch (Exception e) {
+            throw new ExtsysException("PUT PNF to A&AI failed.", e);
+        }
+    }
+}
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/PnfRegisterProvider.java b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/PnfRegisterProvider.java
new file mode 100644 (file)
index 0000000..596f062
--- /dev/null
@@ -0,0 +1,20 @@
+/**
+ * Copyright 2018 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.onap.aai.esr.externalservice.aai;
+
+public class PnfRegisterProvider {
+
+}
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/util/PnfManagerUtil.java b/esr-mgr/src/main/java/org/onap/aai/esr/util/PnfManagerUtil.java
new file mode 100644 (file)
index 0000000..f159cd2
--- /dev/null
@@ -0,0 +1,42 @@
+/**
+ * Copyright 2018 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.onap.aai.esr.util;
+
+import org.onap.aai.esr.entity.aai.Pnf;
+import org.onap.aai.esr.entity.rest.PnfRegisterInfo;
+
+public class PnfManagerUtil {
+
+    /**
+     * @param pnfRegisterInfo
+     * @return
+     */
+    public static Pnf pnfRegisterInfo2pnf(PnfRegisterInfo pnfRegisterInfo) {
+        Pnf pnf = new Pnf();
+        pnf.setPnfName(pnfRegisterInfo.getPnfId());
+        pnf.setPnfName2(pnfRegisterInfo.getUserLabel());
+        String pnfId = pnfRegisterInfo.getSubnetId() + "-" +pnfRegisterInfo.getNeId();
+        pnf.setPnfId(pnfId);
+        pnf.setEquipType(pnfRegisterInfo.getManagementType());
+        pnf.setEquipVendor(pnfRegisterInfo.getVendor());
+        pnf.setEquipModel(pnfRegisterInfo.getPnfdId());
+        pnf.setManagementOption(pnfRegisterInfo.getEmsId());
+        String frameId = pnfRegisterInfo.getLattitude() + "-" + pnfRegisterInfo.getLongitude();
+        pnf.setFrameId(frameId);
+        return pnf;
+    }
+
+}
index b363c04..eb694d0 100644 (file)
 package org.onap.aai.esr.wrapper;
 
 import javax.ws.rs.core.Response;
 package org.onap.aai.esr.wrapper;
 
 import javax.ws.rs.core.Response;
+import org.onap.aai.esr.entity.aai.Pnf;
 import org.onap.aai.esr.entity.rest.PnfRegisterInfo;
 import org.onap.aai.esr.entity.rest.PnfRegisterInfo;
-import org.onap.aai.esr.externalservice.aai.ExternalSystemProxy;
+import org.onap.aai.esr.exception.ExceptionUtil;
+import org.onap.aai.esr.exception.ExtsysException;
+import org.onap.aai.esr.externalservice.aai.NetworkProxy;
+import org.onap.aai.esr.util.PnfManagerUtil;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -26,7 +30,7 @@ public class PnfManagerWrapper {
     private static final Logger LOG = LoggerFactory.getLogger(PnfManagerWrapper.class);
 
 //    private static PnfManagerUtil pnfManagerUtil = new PnfManagerUtil();
     private static final Logger LOG = LoggerFactory.getLogger(PnfManagerWrapper.class);
 
 //    private static PnfManagerUtil pnfManagerUtil = new PnfManagerUtil();
-    private static ExternalSystemProxy externalSystemProxy = new ExternalSystemProxy();
+    private static NetworkProxy networkProxy = new NetworkProxy();
 
     /**
      * get PnfManagerWrapper instance.
 
     /**
      * get PnfManagerWrapper instance.
@@ -35,13 +39,13 @@ public class PnfManagerWrapper {
      */
     public static PnfManagerWrapper getInstance() {
         if (pnfManagerWrapper == null) {
      */
     public static PnfManagerWrapper getInstance() {
         if (pnfManagerWrapper == null) {
-            pnfManagerWrapper = new PnfManagerWrapper(externalSystemProxy);
+            pnfManagerWrapper = new PnfManagerWrapper(networkProxy);
         }
         return pnfManagerWrapper;
     }
     
         }
         return pnfManagerWrapper;
     }
     
-    public PnfManagerWrapper(ExternalSystemProxy externalSystemProxy){
-        PnfManagerWrapper.externalSystemProxy = externalSystemProxy;
+    public PnfManagerWrapper(NetworkProxy networkProxy){
+        PnfManagerWrapper.networkProxy = networkProxy;
     }
 
     /**
     }
 
     /**
@@ -84,8 +88,15 @@ public class PnfManagerWrapper {
      * @param pnf
      * @return
      */
      * @param pnf
      * @return
      */
-    public Response registerPnf(PnfRegisterInfo pnf) {
-        // TODO Auto-generated method stub
-        return null;
+    public Response registerPnf(PnfRegisterInfo pnfRegisterInfo) {
+        Pnf pnf = PnfManagerUtil.pnfRegisterInfo2pnf(pnfRegisterInfo);
+        String pnfName = pnf.getPnfName();
+        try {
+            networkProxy.registerPnf(pnfName, pnf);
+            return Response.ok().build();
+        } catch (ExtsysException e) {
+            LOG.error("Register PNF failed !", e);
+            throw ExceptionUtil.buildExceptionResponse(e.getMessage());
+        }
     }
 }
     }
 }
diff --git a/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/PnfManagerWrapperTest.java b/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/PnfManagerWrapperTest.java
new file mode 100644 (file)
index 0000000..ec65cba
--- /dev/null
@@ -0,0 +1,55 @@
+/**
+ * Copyright 2018 ZTE Corporation.
+ *
+ * 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.
+ */
+package org.onap.aai.esr.wrapper;
+
+import javax.ws.rs.core.Response;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.aai.esr.common.MsbConfig;
+import org.onap.aai.esr.entity.aai.Pnf;
+import org.onap.aai.esr.entity.rest.PnfRegisterInfo;
+import org.onap.aai.esr.exception.ExtsysException;
+import org.onap.aai.esr.externalservice.aai.NetworkProxy;
+
+public class PnfManagerWrapperTest {
+
+    static {
+        MsbConfig.setMsbServerAddr("http://127.0.0.1:80");
+    }
+
+    @Test
+    public void test_registerPnf() throws ExtsysException {
+        PnfRegisterInfo pnfRegisterInfo = new PnfRegisterInfo();
+        pnfRegisterInfo.setPnfId("pnf1");
+        pnfRegisterInfo.setUserLabel("PNF-test");
+        pnfRegisterInfo.setSubnetId("subnetId1");
+        pnfRegisterInfo.setNeId("neId1");
+        pnfRegisterInfo.setManagementType("Test");
+        pnfRegisterInfo.setVendor("ZTE");
+        pnfRegisterInfo.setPnfdId("pnfdId1");
+        pnfRegisterInfo.setEmsId("emsId1");
+        pnfRegisterInfo.setLattitude("121.546");
+        pnfRegisterInfo.setLongitude("14.22");
+        NetworkProxy mockNetworkProxy = Mockito.mock(NetworkProxy.class);
+        Mockito.doNothing().when(mockNetworkProxy).registerPnf(Mockito.anyString(), (Pnf)Mockito.anyObject());
+        PnfManagerWrapper pnfManagerWrapper = new PnfManagerWrapper(mockNetworkProxy);
+        Response response = pnfManagerWrapper.registerPnf(pnfRegisterInfo);
+        if (response != null) {
+            Assert.assertTrue(response.getStatus() == 200);
+        }
+    }
+}