Add the EMS data transformation function. 93/11893/1
authorlizi00164331 <li.zi30@zte.com.cn>
Tue, 12 Sep 2017 08:30:44 +0000 (16:30 +0800)
committerlizi00164331 <li.zi30@zte.com.cn>
Tue, 12 Sep 2017 08:30:44 +0000 (16:30 +0800)
Change-Id: I2d48645da9eaf5aeff4142e56d61ccc70bcce04c
Issue-ID: AAI-287
Signed-off-by: lizi00164331 <li.zi30@zte.com.cn>
esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/AuthInfo.java
esr-mgr/src/main/java/org/onap/aai/esr/entity/aai/EsrEms.java
esr-mgr/src/main/java/org/onap/aai/esr/entity/rest/FtpAddr.java
esr-mgr/src/main/java/org/onap/aai/esr/util/EmsManagerUtil.java [new file with mode: 0644]
esr-mgr/src/main/java/org/onap/aai/esr/util/ExtsysUtil.java
esr-mgr/src/main/java/org/onap/aai/esr/util/VimManagerUtil.java

index 56d76cb..1fbca12 100644 (file)
@@ -49,6 +49,10 @@ public class AuthInfo {
   
   private String defaultTenant;
   
+  private Boolean passive;
+  
+  private String remotePath;
+  
   private String systemStatus;
   
   private String resouceVersion;
@@ -197,4 +201,20 @@ public class AuthInfo {
     this.resouceVersion = resouceVersion;
   }
 
+  public Boolean getPassive() {
+    return passive;
+  }
+
+  public void setPassive(Boolean passive) {
+    this.passive = passive;
+  }
+
+  public String getRemotePath() {
+    return remotePath;
+  }
+
+  public void setRemotePath(String remotePath) {
+    this.remotePath = remotePath;
+  }
+  
 }
index 3bff6a0..e8c402e 100644 (file)
@@ -20,10 +20,6 @@ public class EsrEms {
 
   private String emsId;
   
-  private Boolean passive;
-  
-  private String remotePath;
-  
   private String resouceVersion;
   
   private EsrSystemInfoList esrSystemInfoList;
@@ -36,22 +32,6 @@ public class EsrEms {
     this.emsId = emsId;
   }
 
-  public Boolean getPassive() {
-    return passive;
-  }
-
-  public void setPassive(Boolean passive) {
-    this.passive = passive;
-  }
-
-  public String getRemotePath() {
-    return remotePath;
-  }
-
-  public void setRemotePath(String remotePath) {
-    this.remotePath = remotePath;
-  }
-
   public EsrSystemInfoList getEsrSystemInfoList() {
     return esrSystemInfoList;
   }
index fe60469..598d6ed 100644 (file)
@@ -29,7 +29,7 @@ public class FtpAddr {
   
   private String remotepath;
   
-  private String passive;
+  private Boolean passive;
 
   public String getFtptype() {
     return ftptype;
@@ -79,11 +79,11 @@ public class FtpAddr {
     this.remotepath = remotepath;
   }
 
-  public String getPassive() {
+  public Boolean getPassive() {
     return passive;
   }
 
-  public void setPassive(String passive) {
+  public void setPassive(Boolean passive) {
     this.passive = passive;
   }
 }
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
new file mode 100644 (file)
index 0000000..decd2da
--- /dev/null
@@ -0,0 +1,139 @@
+/**
+ * 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.util;
+
+import java.util.ArrayList;
+
+import org.onap.aai.esr.common.SystemType;
+import org.onap.aai.esr.entity.aai.AuthInfo;
+import org.onap.aai.esr.entity.aai.EsrEms;
+import org.onap.aai.esr.entity.rest.AlarmAddr;
+import org.onap.aai.esr.entity.rest.EmsRegisterInfo;
+import org.onap.aai.esr.entity.rest.FtpAddr;
+
+public class EmsManagerUtil {
+  
+  public static EsrEms emsRegisterInfo2EsrEms(EmsRegisterInfo emsRegisterInfo) {
+    EsrEms esrEms = new EsrEms();
+    esrEms.setEmsId(ExtsysUtil.generateId());
+    ArrayList<AuthInfo> authInfos = new ArrayList<AuthInfo>();
+    authInfos = getAuthInfosFromRegisterData(emsRegisterInfo);
+    esrEms.setEsrSystemInfoList(ExtsysUtil.getEsrSystemInfoListFromAuthInfoList(authInfos));
+    return esrEms;
+  }
+
+  private static ArrayList<AuthInfo> getAuthInfosFromRegisterData(EmsRegisterInfo emsRegisterInfo) {
+    ArrayList<AuthInfo> authInfos = new ArrayList<AuthInfo>();
+    AuthInfo resouceAuthInfo = new AuthInfo();
+    AuthInfo performanceAuthInfo = new AuthInfo();
+    AuthInfo alarmAuthInfo = new AuthInfo();
+    resouceAuthInfo = getAuthInfoFromFtpAddr(emsRegisterInfo, SystemType.EMS_RESOUCE.toString());
+    performanceAuthInfo = getAuthInfoFromFtpAddr(emsRegisterInfo, SystemType.EMS_PERFORMANCE.toString());
+    alarmAuthInfo = getAuthInfoFromAlarmAddr(emsRegisterInfo);
+    authInfos.add(resouceAuthInfo);
+    authInfos.add(performanceAuthInfo);
+    authInfos.add(alarmAuthInfo);
+    return authInfos;
+  }
+  
+  private static AuthInfo getAuthInfoFromFtpAddr(EmsRegisterInfo emsRegisterInfo, String systemType) {
+    AuthInfo authInfo = new AuthInfo();
+    FtpAddr ftpAddr = new FtpAddr();
+    if(systemType.equals(SystemType.EMS_RESOUCE.toString())) {
+      ftpAddr = emsRegisterInfo.getResourceAddr();
+    } else if(systemType.equals(SystemType.EMS_PERFORMANCE.toString())) {
+      ftpAddr = emsRegisterInfo.getPerformanceAddr();
+    }
+    authInfo.setType(ftpAddr.getFtptype());
+    authInfo.setIpAddress(ftpAddr.getIp());
+    authInfo.setPort(ftpAddr.getPort());
+    authInfo.setUserName(ftpAddr.getUser());
+    authInfo.setPassword(ftpAddr.getPassword());
+    authInfo.setRemotePath(ftpAddr.getRemotepath());
+    authInfo.setPassive(ftpAddr.getPassive());
+    authInfo.setEsrSystemInfoId(ExtsysUtil.generateId());
+    authInfo.setSystemType(systemType);
+    authInfo.setSystemName(emsRegisterInfo.getName());
+    authInfo.setVendor(emsRegisterInfo.getVendor());
+    authInfo.setVersion(emsRegisterInfo.getVersion());
+    return authInfo;
+  }
+  
+  private static AuthInfo getAuthInfoFromAlarmAddr(EmsRegisterInfo emsRegisterInfo) {
+    AuthInfo authInfo = new AuthInfo();
+    AlarmAddr alarmAddr = new AlarmAddr();
+    alarmAddr = emsRegisterInfo.getAlarmAddr();
+    authInfo.setIpAddress(alarmAddr.getIp());
+    authInfo.setPort(alarmAddr.getPort());
+    authInfo.setUserName(alarmAddr.getUser());
+    authInfo.setPassword(alarmAddr.getPassword());
+    authInfo.setSystemType(SystemType.EMS_ALARM.toString());
+    authInfo.setSystemName(emsRegisterInfo.getName());
+    authInfo.setVendor(emsRegisterInfo.getVendor());
+    authInfo.setVersion(emsRegisterInfo.getVersion());
+    return authInfo;
+  }
+  
+  public static EmsRegisterInfo EsrEms2EmsRegisterInfo(EsrEms esrEms) {
+    EmsRegisterInfo emsRegisterInfo = new EmsRegisterInfo();
+    ArrayList<AuthInfo> authInfos = new ArrayList<AuthInfo>();
+    AuthInfo authInfo = new AuthInfo();
+    authInfos = esrEms.getEsrSystemInfoList().getEsrSystemInfo().getEsrSystemInfo();
+    emsRegisterInfo.setEmsId(esrEms.getEmsId());
+    
+    for(int i=0; i<authInfos.size(); i++) {
+      authInfo = authInfos.get(i);
+      if(authInfo.getSystemType().equals(SystemType.EMS_RESOUCE.toString())){
+        FtpAddr resourceAddr = new FtpAddr();
+        resourceAddr = getFtpAddrFromAuthInfo(authInfo);
+        emsRegisterInfo.setResourceAddr(resourceAddr);
+      } else if(authInfo.getSystemType().equals(SystemType.EMS_PERFORMANCE.toString())) {
+        FtpAddr performanceAddr = new FtpAddr();
+        performanceAddr = getFtpAddrFromAuthInfo(authInfo);
+        emsRegisterInfo.setResourceAddr(performanceAddr);
+      } else if(authInfo.getSystemType().equals(SystemType.EMS_ALARM.toString())) {
+        AlarmAddr alarmAddr = new AlarmAddr();
+        alarmAddr = getAlarmAddrFromAuthInfo(authInfo);
+        emsRegisterInfo.setAlarmAddr(alarmAddr);
+      }
+    }
+    emsRegisterInfo.setName(authInfo.getSystemName());
+    emsRegisterInfo.setVendor(authInfo.getVendor());
+    emsRegisterInfo.setVersion(authInfo.getVersion());
+    return emsRegisterInfo;
+  }
+  
+  private static FtpAddr getFtpAddrFromAuthInfo(AuthInfo authInfo) {
+    FtpAddr ftpAddr = new FtpAddr();
+    ftpAddr.setFtptype(authInfo.getType());
+    ftpAddr.setIp(authInfo.getIpAddress());
+    ftpAddr.setPassive(authInfo.getPassive());
+    ftpAddr.setPassword(authInfo.getPassword());
+    ftpAddr.setPort(authInfo.getPort());
+    ftpAddr.setRemotepath(authInfo.getRemotePath());
+    ftpAddr.setUser(authInfo.getUserName());
+    return ftpAddr;
+  }
+  
+  private static AlarmAddr getAlarmAddrFromAuthInfo(AuthInfo authInfo) {
+    AlarmAddr alarmAddr = new AlarmAddr();
+    alarmAddr.setIp(authInfo.getIpAddress());
+    alarmAddr.setPassword(authInfo.getPassword());
+    alarmAddr.setPort(authInfo.getPort());
+    alarmAddr.setUser(authInfo.getUserName());
+    return alarmAddr;
+  }
+}
index 8127053..b8a120c 100644 (file)
@@ -57,7 +57,7 @@ public class ExtsysUtil {
     return sdf.format(new Date());
   }
   
-  public static EsrSystemInfoList getEsrSystemInfoList(AuthInfo authInfo) {
+  public static EsrSystemInfoList getEsrSystemInfoListFromAuthInfo(AuthInfo authInfo) {
     EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList();
     EsrSystemInfo esrSystemInfo = new EsrSystemInfo();
     ArrayList<AuthInfo> authInfos = new ArrayList<AuthInfo>();
@@ -66,4 +66,12 @@ public class ExtsysUtil {
     esrSystemInfoList.setEsrSystemInfo(esrSystemInfo);
     return esrSystemInfoList;
   }
+  
+  public static EsrSystemInfoList getEsrSystemInfoListFromAuthInfoList(ArrayList<AuthInfo> authInfos) {
+    EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList();
+    EsrSystemInfo esrSystemInfo = new EsrSystemInfo();
+    esrSystemInfo.setEsrSystemInfo(authInfos);
+    esrSystemInfoList.setEsrSystemInfo(esrSystemInfo);
+    return esrSystemInfoList;
+  }
 }
index caad565..54720ce 100644 (file)
@@ -44,7 +44,7 @@ public class VimManagerUtil {
     cloudRegion.setCloudExtraInfo(vimRegisterInfo.getCloudExtraInfo());
     
     authInfo = vimAuthInfo2AuthInfo(vimRegisterInfo.getVimAuthInfo());
-    esrSystemInfo = ExtsysUtil.getEsrSystemInfoList(authInfo);
+    esrSystemInfo = ExtsysUtil.getEsrSystemInfoListFromAuthInfo(authInfo);
     cloudRegion.setEsrSystemInfoList(esrSystemInfo);
     return cloudRegion;
   }