Realize thirdparty sdnc register API. 85/12985/1
authorlizi00164331 <li.zi30@zte.com.cn>
Mon, 18 Sep 2017 06:11:29 +0000 (14:11 +0800)
committerlizi00164331 <li.zi30@zte.com.cn>
Mon, 18 Sep 2017 06:11:29 +0000 (14:11 +0800)
Change-Id: I65ddaa9cc96eacd21234425d33efe4ebe19211ea
Issue-ID: AAI-315
Signed-off-by: lizi00164331 <li.zi30@zte.com.cn>
esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/CloudRegionProxy.java
esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/ExternalSystemProxy.java
esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/ThirdpartySdncRegisterProvider.java [new file with mode: 0644]
esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/VimRegisterProvider.java [moved from esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/RegisterVimProvider.java with 92% similarity]
esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/VnfmRegisterProvider.java [moved from esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/RegisterVnfmProvider.java with 92% similarity]
esr-mgr/src/main/java/org/onap/aai/esr/util/ThirdpartySdncManagerUtil.java
esr-mgr/src/main/java/org/onap/aai/esr/wrapper/ThirdpatySdncWrapper.java

index 53e5fef..f21510e 100644 (file)
@@ -35,7 +35,7 @@ public class CloudRegionProxy {
 
   public static void registerVim(String cloudOwner, String cloudRegionId, CloudRegionDetail cloudRegion)
       throws Exception {
-    ClientConfig config = new ClientConfig(new RegisterVimProvider());
+    ClientConfig config = new ClientConfig(new VimRegisterProvider());
     ICloudRegion registerVimServiceproxy = ConsumerFactory
         .createConsumer(AaiAdapterConfig.getCloudInfrastructureAddr(), config, ICloudRegion.class);
     registerVimServiceproxy.registerVIMService(transactionId, fromAppId, authorization, cloudOwner,
index 7328f97..cebab2c 100644 (file)
@@ -16,6 +16,7 @@
 package org.onap.aai.esr.externalservice.aai;
 
 import org.glassfish.jersey.client.ClientConfig;
+import org.onap.aai.esr.entity.aai.EsrThirdpartySdncDetail;
 import org.onap.aai.esr.entity.aai.EsrVnfmDetail;
 
 import com.eclipsesource.jaxrs.consumer.ConsumerFactory;
@@ -34,7 +35,7 @@ public class ExternalSystemProxy {
   }
 
   public static void registerVnfm(String vnfmId, EsrVnfmDetail esrVnfmDetail) throws Exception {
-    ClientConfig config = new ClientConfig(new RegisterVnfmProvider());
+    ClientConfig config = new ClientConfig(new VnfmRegisterProvider());
     IExternalSystem registerVnfmServiceproxy = ConsumerFactory
         .createConsumer(AaiAdapterConfig.getExternalSystemAddr(), config, IExternalSystem.class);
     registerVnfmServiceproxy.registerVNFM(transactionId, fromAppId, authorization, vnfmId,
@@ -52,4 +53,12 @@ public class ExternalSystemProxy {
   public static void deleteVnfm(String vnfmId, String resourceVersion) throws Exception {
     externalSystemproxy.deleteVNFM(transactionId, fromAppId, authorization, vnfmId, resourceVersion);
   }
+  
+  public static void registerSdnc(String thirdpartySdncId, EsrThirdpartySdncDetail esrSdncDetail) throws Exception {
+    ClientConfig config = new ClientConfig(new ThirdpartySdncRegisterProvider());
+    IExternalSystem registerVnfmServiceproxy = ConsumerFactory
+        .createConsumer(AaiAdapterConfig.getExternalSystemAddr(), config, IExternalSystem.class);
+    registerVnfmServiceproxy.registerThirdpartySdnc(transactionId, fromAppId, authorization, thirdpartySdncId,
+        esrSdncDetail);
+  }
 }
diff --git a/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/ThirdpartySdncRegisterProvider.java b/esr-mgr/src/main/java/org/onap/aai/esr/externalservice/aai/ThirdpartySdncRegisterProvider.java
new file mode 100644 (file)
index 0000000..61964fc
--- /dev/null
@@ -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.EsrThirdpartySdncDetail;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import com.google.gson.Gson;
+
+public class ThirdpartySdncRegisterProvider implements MessageBodyWriter<EsrThirdpartySdncDetail>{
+
+  private static final Logger logger = LoggerFactory.getLogger(VimRegisterProvider.class);
+
+  @Override
+  public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations,
+      MediaType mediaType) {
+    return EsrThirdpartySdncDetail.class.isAssignableFrom(type);
+  }
+
+  @Override
+  public long getSize(EsrThirdpartySdncDetail t, Class<?> type, Type genericType,
+      Annotation[] annotations, MediaType mediaType) {
+    return -1;
+  }
+
+  @Override
+  public void writeTo(EsrThirdpartySdncDetail t, Class<?> type, Type genericType,
+      Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders,
+      OutputStream entityStream) throws IOException, WebApplicationException {
+    String json = new Gson().toJson(t, EsrThirdpartySdncDetail.class);
+    logger.info("the param to register VIM input is:" + json);
+    entityStream.write(json.getBytes("UTF-8"));
+  }
+}
@@ -31,8 +31,8 @@ import org.slf4j.LoggerFactory;
 
 import com.google.gson.Gson;
 
-public class RegisterVimProvider implements MessageBodyWriter<CloudRegionDetail>{
-  private static final Logger logger = LoggerFactory.getLogger(RegisterVimProvider.class);
+public class VimRegisterProvider implements MessageBodyWriter<CloudRegionDetail>{
+  private static final Logger logger = LoggerFactory.getLogger(VimRegisterProvider.class);
 
   @Override
   public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations,
@@ -31,9 +31,9 @@ import org.slf4j.LoggerFactory;
 
 import com.google.gson.Gson;
 
-public class RegisterVnfmProvider  implements MessageBodyWriter<EsrVnfmDetail>{
+public class VnfmRegisterProvider  implements MessageBodyWriter<EsrVnfmDetail>{
 
-  private static final Logger logger = LoggerFactory.getLogger(RegisterVnfmProvider.class);
+  private static final Logger logger = LoggerFactory.getLogger(VnfmRegisterProvider.class);
 
   @Override
   public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations,
index b361527..2cf4a0a 100644 (file)
@@ -25,7 +25,7 @@ import org.onap.aai.esr.entity.rest.ThirdpartySdncRegisterInfo;
 
 public class ThirdpartySdncManagerUtil {
   
-  public EsrThirdpartySdncDetail sdncRegisterInfo2EsrSdnc(ThirdpartySdncRegisterInfo sdncRegisterInfo) {
+  public static EsrThirdpartySdncDetail sdncRegisterInfo2EsrSdnc(ThirdpartySdncRegisterInfo sdncRegisterInfo) {
     EsrThirdpartySdncDetail esrThirdpartySdnc = new EsrThirdpartySdncDetail();
     sdncRegisterInfo.setThirdpartySdncId(ExtsysUtil.generateId());
     esrThirdpartySdnc.setThirdpartySdncId(sdncRegisterInfo.getThirdpartySdncId());
@@ -35,11 +35,12 @@ public class ThirdpartySdncManagerUtil {
     return esrThirdpartySdnc;
   }
   
-  private EsrSystemInfoList getEsrSystemInfoList(ThirdpartySdncRegisterInfo sdncRegisterInfo) {
+  private static EsrSystemInfoList getEsrSystemInfoList(ThirdpartySdncRegisterInfo sdncRegisterInfo) {
     EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList();
     ArrayList<EsrSystemInfo> esrSystemInfo = new ArrayList<EsrSystemInfo>();
     EsrSystemInfo authInfo = new EsrSystemInfo();
-    authInfo.setResouceVersion(sdncRegisterInfo.getVersion());
+    authInfo.setEsrSystemInfoId(ExtsysUtil.generateId());
+    authInfo.setVersion(sdncRegisterInfo.getVersion());
     authInfo.setSystemName(sdncRegisterInfo.getName());
     authInfo.setServiceUrl(sdncRegisterInfo.getUrl());
     authInfo.setVendor(sdncRegisterInfo.getVendor());
@@ -53,7 +54,7 @@ public class ThirdpartySdncManagerUtil {
     return esrSystemInfoList;
   }
 
-  public ThirdpartySdncRegisterInfo esrSdnc2SdncRegisterInfo(EsrThirdpartySdncDetail esrSdnc) {
+  public static ThirdpartySdncRegisterInfo esrSdnc2SdncRegisterInfo(EsrThirdpartySdncDetail esrSdnc) {
     ThirdpartySdncRegisterInfo registerSdncInfo = new ThirdpartySdncRegisterInfo();
     EsrSystemInfo esrSystemInfo = esrSdnc.getEsrSystemInfoList().getEsrSystemInfo().get(0);
     registerSdncInfo.setThirdpartySdncId(esrSdnc.getThirdpartySdncId());
index b06b1f7..9bc61ad 100644 (file)
@@ -19,15 +19,18 @@ import java.util.ArrayList;
 
 import javax.ws.rs.core.Response;
 
+import org.onap.aai.esr.entity.aai.EsrThirdpartySdncDetail;
 import org.onap.aai.esr.entity.rest.CommonRegisterResponse;
 import org.onap.aai.esr.entity.rest.ThirdpartySdncRegisterInfo;
-//import org.slf4j.Logger;
-//import org.slf4j.LoggerFactory;
+import org.onap.aai.esr.externalservice.aai.ExternalSystemProxy;
+import org.onap.aai.esr.util.ThirdpartySdncManagerUtil;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 public class ThirdpatySdncWrapper {
 
   private static ThirdpatySdncWrapper thirdpatySdncWrapper;
-//  private static final Logger LOG = LoggerFactory.getLogger(ThirdpatySdncWrapper.class);
+  private static final Logger LOG = LoggerFactory.getLogger(ThirdpatySdncWrapper.class);
 
   /**
    * get ThirdpatySdncWrapper instance.
@@ -41,9 +44,20 @@ public class ThirdpatySdncWrapper {
   }
   
   public Response registerThirdpartySdnc(ThirdpartySdncRegisterInfo thirdpartySdnc) {
-    //TODO
-    CommonRegisterResponse result = null;
-    return Response.ok(result).build();
+    CommonRegisterResponse result = new CommonRegisterResponse();
+    EsrThirdpartySdncDetail esrSdncDetail = new EsrThirdpartySdncDetail();
+    esrSdncDetail = ThirdpartySdncManagerUtil.sdncRegisterInfo2EsrSdnc(thirdpartySdnc);
+    String sdncId = esrSdncDetail.getThirdpartySdncId();
+    try {
+      ExternalSystemProxy.registerSdnc(sdncId, esrSdncDetail);
+      result.setId(sdncId);
+      return Response.ok(result).build();
+    } catch (Exception e) {
+      e.printStackTrace();
+      LOG.error("Register thirdParty SDNC failed !" + e.getMessage());
+      return Response.serverError().build();
+    }
+    
   }
 
   public Response updateThirdpartySdnc(ThirdpartySdncRegisterInfo thirdpartySdnc) {