Realize the function of VIM API.
[aai/esr-server.git] / esr-mgr / src / main / java / org / onap / aai / esr / util / VimManagerUtil.java
1 /**
2  * Copyright 2017 ZTE Corporation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package org.onap.aai.esr.util;
17
18 import java.util.ArrayList;
19
20 import org.onap.aai.esr.common.SystemStatus;
21 import org.onap.aai.esr.common.SystemType;
22 import org.onap.aai.esr.entity.aai.EsrSystemInfo;
23 import org.onap.aai.esr.entity.aai.CloudRegion;
24 import org.onap.aai.esr.entity.aai.EsrSystemInfoList;
25 import org.onap.aai.esr.entity.rest.VimAuthInfo;
26 import org.onap.aai.esr.entity.rest.VimRegisterInfo;
27
28
29 public class VimManagerUtil {
30   
31   public static CloudRegion vimRegisterInfo2CloudRegion(VimRegisterInfo vimRegisterInfo) {
32     CloudRegion cloudRegion = new CloudRegion();
33     EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList();
34     ArrayList<EsrSystemInfo> esrSystemInfo = new ArrayList<EsrSystemInfo>();
35     EsrSystemInfo esrSystemInfoObj = new EsrSystemInfo();
36     
37     cloudRegion.setCloudOwner(vimRegisterInfo.getCloudOwner());
38     cloudRegion.setCloudRegionId(vimRegisterInfo.getCloudRegionId());
39     cloudRegion.setCloudType(vimRegisterInfo.getCloudType());
40     cloudRegion.setCloudRegionVersion(vimRegisterInfo.getCloudRegionVersion());
41     cloudRegion.setCloudZone(vimRegisterInfo.getCloudZone());
42     cloudRegion.setComplexName(vimRegisterInfo.getComplexName());
43     cloudRegion.setOwnerDefinedType(vimRegisterInfo.getOwnerDefinedType());
44     cloudRegion.setCloudExtraInfo(vimRegisterInfo.getCloudExtraInfo());
45     
46     esrSystemInfoObj = vimAuthInfo2EsrSystemInfoObj(vimRegisterInfo.getVimAuthInfo());
47     esrSystemInfoList = ExtsysUtil.getEsrSystemInfoListFromAuthInfo(esrSystemInfoObj);
48     cloudRegion.setEsrSystemInfoList(esrSystemInfoList);
49     return cloudRegion;
50   }
51
52   private static EsrSystemInfo vimAuthInfo2EsrSystemInfoObj(VimAuthInfo vimAuthInfo) {
53     EsrSystemInfo esrSystemInfoObj = new EsrSystemInfo();
54     esrSystemInfoObj.setCloudDomain(vimAuthInfo.getCloudDomain());
55     esrSystemInfoObj.setUserName(vimAuthInfo.getUserName());
56     esrSystemInfoObj.setPassword(vimAuthInfo.getPassword());
57     esrSystemInfoObj.setServiceUrl(vimAuthInfo.getAuthUrl());
58     esrSystemInfoObj.setSslCassert(vimAuthInfo.getSslCacert());
59     esrSystemInfoObj.setSslInsecure(vimAuthInfo.getSslInsecure());
60     esrSystemInfoObj.setEsrSystemInfoId(ExtsysUtil.generateId());
61     esrSystemInfoObj.setSystemType(SystemType.VIM.toString());
62     esrSystemInfoObj.setSystemStatus(SystemStatus.normal.toString());
63     return esrSystemInfoObj;
64   }
65   
66   private static VimAuthInfo authInfo2VimAuthInfo(EsrSystemInfo authInfo) {
67     VimAuthInfo vimAuthInfo = new VimAuthInfo();
68     vimAuthInfo.setAuthUrl(authInfo.getServiceUrl());
69     vimAuthInfo.setCloudDomain(authInfo.getCloudDomain());
70     vimAuthInfo.setPassword(authInfo.getPassword());
71     vimAuthInfo.setSslCacert(authInfo.getSslCassert());
72     vimAuthInfo.setSslInsecure(authInfo.getSslInsecure());
73     vimAuthInfo.setUserName(authInfo.getUserName());
74     return vimAuthInfo;
75   }
76   
77   public static VimRegisterInfo cloudRegion2VimRegisterInfo(CloudRegion cloudRegion) {
78     VimRegisterInfo vimRegisterInfo = new VimRegisterInfo();
79     VimAuthInfo vimAuthInfo = new VimAuthInfo();
80     vimAuthInfo = authInfo2VimAuthInfo(cloudRegion.getEsrSystemInfoList().getEsrSystemInfo().get(0));
81     vimRegisterInfo.setVimAuthInfo(vimAuthInfo);
82     vimRegisterInfo.setCloudExtraInfo(cloudRegion.getCloudExtraInfo());
83     vimRegisterInfo.setCloudOwner(cloudRegion.getCloudOwner());
84     vimRegisterInfo.setCloudRegionId(cloudRegion.getCloudRegionId());
85     vimRegisterInfo.setCloudType(cloudRegion.getCloudType());
86     vimRegisterInfo.setCloudZone(cloudRegion.getCloudZone());
87     vimRegisterInfo.setComplexName(cloudRegion.getComplexName());
88     vimRegisterInfo.setCloudRegionVersion(cloudRegion.getCloudRegionVersion());
89     vimRegisterInfo.setOwnerDefinedType(cloudRegion.getOwnerDefinedType());
90     return vimRegisterInfo;
91   }
92 }