summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZi Li <li.zi30@zte.com.cn>2018-08-20 09:11:48 +0000
committerZi Li <li.zi30@zte.com.cn>2018-08-20 09:20:39 +0000
commit15dd5f02e728d546e6ba8c4d460b5f1a1e57d2b7 (patch)
tree43f39d03d5c2d4146de0c12bdd5836ff2700168f
parent572c36a74c648dd4ccbe44cd8c1184e18dbea751 (diff)
Realize the PNF registration API
Issue-ID: AAI-1496 Change-Id: Iece0706db599990131fef2fa1b6b9159e8f967e4 Signed-off-by: Zi Li <li.zi30@zte.com.cn>
-rw-r--r--esr-mgr/src/main/java/org/onap/aai/esr/common/MsbConfig.java10
-rw-r--r--esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/Pnf.java (renamed from esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/EsrPnf.java)2
-rw-r--r--esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/PnfList.java (renamed from esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/EsrPnfList.java)8
-rw-r--r--esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/INetwork.java37
-rw-r--r--esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/NetworkProxy.java46
-rw-r--r--esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/PnfRegisterProvider.java20
-rw-r--r--esr-mgr/src/main/java/org/onap/aai/esr/util/PnfManagerUtil.java42
-rw-r--r--esr-mgr/src/main/java/org/onap/aai/esr/wrapper/PnfManagerWrapper.java27
-rw-r--r--esr-mgr/src/test/java/org/onap/aai/esr/wrapper/PnfManagerWrapperTest.java55
9 files changed, 234 insertions, 13 deletions
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/common/MsbConfig.java b/esr-mgr/src/main/java/org/onap/aai/esr/common/MsbConfig.java
index b378b22..3d827a8 100644
--- a/esr-mgr/src/main/java/org/onap/aai/esr/common/MsbConfig.java
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/common/MsbConfig.java
@@ -26,6 +26,8 @@ public class MsbConfig {
protected static String cloudInfrastructureAddr;
protected static String externalSystemAddr;
+
+ protected static String networkAddr;
protected static String multiCloudAddr;
@@ -49,6 +51,14 @@ public class MsbConfig {
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;
}
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/EsrPnf.java b/esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/Pnf.java
index cb382a9..aeb5244 100644
--- a/esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/EsrPnf.java
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/Pnf.java
@@ -18,7 +18,7 @@ package org.onap.aai.esr.entity.aai;
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;
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/EsrPnfList.java b/esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/PnfList.java
index 9af8e9e..d452c35 100644
--- a/esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/EsrPnfList.java
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/PnfList.java
@@ -19,18 +19,18 @@ import java.io.Serializable;
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")
- private List<EsrPnf> pnf;
+ private List<Pnf> pnf;
- public List<EsrPnf> getPnf() {
+ public List<Pnf> getPnf() {
return pnf;
}
- public void setPnf(List<EsrPnf> pnf) {
+ public void setPnf(List<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
index 0000000..c159da7
--- /dev/null
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/INetwork.java
@@ -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
index 0000000..933ecea
--- /dev/null
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/NetworkProxy.java
@@ -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
index 0000000..596f062
--- /dev/null
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/PnfRegisterProvider.java
@@ -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
index 0000000..f159cd2
--- /dev/null
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/util/PnfManagerUtil.java
@@ -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;
+ }
+
+}
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/PnfManagerWrapper.java b/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/PnfManagerWrapper.java
index b363c04..eb694d0 100644
--- a/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/PnfManagerWrapper.java
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/PnfManagerWrapper.java
@@ -16,8 +16,12 @@
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.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;
@@ -26,7 +30,7 @@ public class PnfManagerWrapper {
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.
@@ -35,13 +39,13 @@ public class PnfManagerWrapper {
*/
public static PnfManagerWrapper getInstance() {
if (pnfManagerWrapper == null) {
- pnfManagerWrapper = new PnfManagerWrapper(externalSystemProxy);
+ pnfManagerWrapper = new PnfManagerWrapper(networkProxy);
}
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
*/
- 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
index 0000000..ec65cba
--- /dev/null
+++ b/esr-mgr/src/test/java/org/onap/aai/esr/wrapper/PnfManagerWrapperTest.java
@@ -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);
+ }
+ }
+}