--- /dev/null
+/**
+ * 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<EsrEmsDetail>{
+
+ 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<String, Object> 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"));
+ }
+}
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;
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);
}
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);
+ }
}
import com.google.gson.Gson;
-public class VnfmRegisterProvider implements MessageBodyWriter<EsrVnfmDetail>{
+public class VnfmRegisterProvider implements MessageBodyWriter<EsrVnfmDetail>{
private static final Logger logger = LoggerFactory.getLogger(VnfmRegisterProvider.class);
* register ems.
*/
@POST
- @Path("")
@Consumes(MediaType.APPLICATION_JSON)
@Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
@ApiOperation(value = "create a ems")
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());
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.
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) {