From bbd77f32c29fa424a3786edbe434f132a5d9da2a Mon Sep 17 00:00:00 2001
From: lizi00164331
Date: Mon, 18 Sep 2017 16:45:09 +0800
Subject: Realize register EMS API.
Change-Id: I985715bfe84c001cbedc2d0337d752372e0719ab
Issue-ID: AAI-320
Signed-off-by: lizi00164331
---
.../externalservice/aai/EmsRegisterProvider.java | 58 ++++++++++++++++++++++
.../externalservice/aai/ExternalSystemProxy.java | 13 ++++-
.../externalservice/aai/VnfmRegisterProvider.java | 2 +-
.../java/org/onap/aai/esr/resource/EmsManager.java | 1 -
.../java/org/onap/aai/esr/util/EmsManagerUtil.java | 1 +
.../onap/aai/esr/wrapper/EmsManagerWrapper.java | 27 +++++++---
6 files changed, 91 insertions(+), 11 deletions(-)
create mode 100644 esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/EmsRegisterProvider.java
(limited to 'esr-mgr/src/main/java/org')
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/EmsRegisterProvider.java b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/EmsRegisterProvider.java
new file mode 100644
index 0000000..61ad8a5
--- /dev/null
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/EmsRegisterProvider.java
@@ -0,0 +1,58 @@
+/**
+ * Copyright 2017 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 java.io.IOException;
+import java.io.OutputStream;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Type;
+
+import javax.ws.rs.WebApplicationException;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.MultivaluedMap;
+import javax.ws.rs.ext.MessageBodyWriter;
+
+import org.onap.aai.esr.entity.aai.EsrEmsDetail;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.Gson;
+
+public class EmsRegisterProvider implements MessageBodyWriter{
+
+ private static final Logger logger = LoggerFactory.getLogger(EmsRegisterProvider.class);
+
+ @Override
+ public boolean isWriteable(Class> type, Type genericType, Annotation[] annotations,
+ MediaType mediaType) {
+ return EsrEmsDetail.class.isAssignableFrom(type);
+ }
+
+ @Override
+ public long getSize(EsrEmsDetail t, Class> type, Type genericType,
+ Annotation[] annotations, MediaType mediaType) {
+ return -1;
+ }
+
+ @Override
+ public void writeTo(EsrEmsDetail t, Class> type, Type genericType,
+ Annotation[] annotations, MediaType mediaType, MultivaluedMap httpHeaders,
+ OutputStream entityStream) throws IOException, WebApplicationException {
+ String json = new Gson().toJson(t, EsrEmsDetail.class);
+ logger.info("the param to register EMS input is:" + json);
+ entityStream.write(json.getBytes("UTF-8"));
+ }
+}
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/ExternalSystemProxy.java b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/ExternalSystemProxy.java
index e7f5d4b..6472308 100644
--- a/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/ExternalSystemProxy.java
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/ExternalSystemProxy.java
@@ -16,6 +16,7 @@
package org.onap.aai.esr.externalservice.aai;
import org.glassfish.jersey.client.ClientConfig;
+import org.onap.aai.esr.entity.aai.EsrEmsDetail;
import org.onap.aai.esr.entity.aai.EsrThirdpartySdncDetail;
import org.onap.aai.esr.entity.aai.EsrVnfmDetail;
@@ -56,9 +57,9 @@ public class ExternalSystemProxy {
public static void registerSdnc(String thirdpartySdncId, EsrThirdpartySdncDetail esrSdncDetail) throws Exception {
ClientConfig config = new ClientConfig(new ThirdpartySdncRegisterProvider());
- IExternalSystem registerVnfmServiceproxy = ConsumerFactory
+ IExternalSystem registerSdncServiceproxy = ConsumerFactory
.createConsumer(AaiAdapterConfig.getExternalSystemAddr(), config, IExternalSystem.class);
- registerVnfmServiceproxy.registerThirdpartySdnc(transactionId, fromAppId, authorization, thirdpartySdncId,
+ registerSdncServiceproxy.registerThirdpartySdnc(transactionId, fromAppId, authorization, thirdpartySdncId,
esrSdncDetail);
}
@@ -73,4 +74,12 @@ public class ExternalSystemProxy {
public static void deleteThirdpartySdnc(String sdncId, String resourceVersion) throws Exception {
externalSystemproxy.deleteThirdpartySdnc(transactionId, fromAppId, authorization, sdncId, resourceVersion);
}
+
+ public static void registerEms(String emsId, EsrEmsDetail emsDetail) throws Exception {
+ ClientConfig config = new ClientConfig(new EmsRegisterProvider());
+ IExternalSystem registerEmsServiceproxy = ConsumerFactory
+ .createConsumer(AaiAdapterConfig.getExternalSystemAddr(), config, IExternalSystem.class);
+ registerEmsServiceproxy.registerEMS(transactionId, fromAppId, authorization, emsId,
+ emsDetail);
+ }
}
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/VnfmRegisterProvider.java b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/VnfmRegisterProvider.java
index 00ed0c5..d72b073 100644
--- a/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/VnfmRegisterProvider.java
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/VnfmRegisterProvider.java
@@ -31,7 +31,7 @@ import org.slf4j.LoggerFactory;
import com.google.gson.Gson;
-public class VnfmRegisterProvider implements MessageBodyWriter{
+public class VnfmRegisterProvider implements MessageBodyWriter{
private static final Logger logger = LoggerFactory.getLogger(VnfmRegisterProvider.class);
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/resource/EmsManager.java b/esr-mgr/src/main/java/org/onap/aai/esr/resource/EmsManager.java
index f38304d..7897eb2 100644
--- a/esr-mgr/src/main/java/org/onap/aai/esr/resource/EmsManager.java
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/resource/EmsManager.java
@@ -131,7 +131,6 @@ public class EmsManager {
* register ems.
*/
@POST
- @Path("")
@Consumes(MediaType.APPLICATION_JSON)
@Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
@ApiOperation(value = "create a ems")
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/util/EmsManagerUtil.java b/esr-mgr/src/main/java/org/onap/aai/esr/util/EmsManagerUtil.java
index 1a861f5..bba610e 100644
--- a/esr-mgr/src/main/java/org/onap/aai/esr/util/EmsManagerUtil.java
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/util/EmsManagerUtil.java
@@ -76,6 +76,7 @@ public class EmsManagerUtil {
EsrSystemInfo authInfo = new EsrSystemInfo();
AlarmAddr alarmAddr = new AlarmAddr();
alarmAddr = emsRegisterInfo.getAlarmAddr();
+ authInfo.setEsrSystemInfoId(ExtsysUtil.generateId());
authInfo.setIpAddress(alarmAddr.getIp());
authInfo.setPort(alarmAddr.getPort());
authInfo.setUserName(alarmAddr.getUser());
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/EmsManagerWrapper.java b/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/EmsManagerWrapper.java
index 4467eae..b1373ca 100644
--- a/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/EmsManagerWrapper.java
+++ b/esr-mgr/src/main/java/org/onap/aai/esr/wrapper/EmsManagerWrapper.java
@@ -20,13 +20,16 @@ import java.util.ArrayList;
import javax.ws.rs.core.Response;
import org.onap.aai.esr.entity.rest.EmsRegisterInfo;
+import org.onap.aai.esr.externalservice.aai.ExternalSystemProxy;
+import org.onap.aai.esr.util.EmsManagerUtil;
+import org.onap.aai.esr.entity.aai.EsrEmsDetail;
import org.onap.aai.esr.entity.rest.CommonRegisterResponse;
-//import org.slf4j.Logger;
-//import org.slf4j.LoggerFactory;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class EmsManagerWrapper {
private static EmsManagerWrapper emsManagerWrapper;
-// private static final Logger LOG = LoggerFactory.getLogger(EmsManagerWrapper.class);
+ private static final Logger LOG = LoggerFactory.getLogger(EmsManagerWrapper.class);
/**
* get VnfmManagerWrapper instance.
@@ -39,10 +42,20 @@ public class EmsManagerWrapper {
return emsManagerWrapper;
}
- public Response registerEms(EmsRegisterInfo ems) {
- //TODO
- CommonRegisterResponse result = null;
- return Response.ok(result).build();
+ public Response registerEms(EmsRegisterInfo emsRegisterInfo) {
+ CommonRegisterResponse result = new CommonRegisterResponse();
+ EsrEmsDetail esrEmsDetail = new EsrEmsDetail();
+ esrEmsDetail = EmsManagerUtil.emsRegisterInfo2EsrEms(emsRegisterInfo);
+ String emsId = esrEmsDetail.getEmsId();
+ try {
+ ExternalSystemProxy.registerEms(emsId, esrEmsDetail);
+ result.setId(emsId);
+ return Response.ok(result).build();
+ } catch (Exception e) {
+ e.printStackTrace();
+ LOG.error("Register EMS failed !" + e.getMessage());
+ return Response.serverError().build();
+ }
}
public Response updateEms(EmsRegisterInfo ems) {
--
cgit 1.2.3-korg