06a8ef09b4fac88dcdcdfb2edf1dfd3e878c7f1b
[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
19 import java.util.ArrayList;
20
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.CloudRegionDetail;
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 CloudRegionDetail vimRegisterInfo2CloudRegion(VimRegisterInfo vimRegisterInfo) {
32     CloudRegionDetail cloudRegion = new CloudRegionDetail();
33     EsrSystemInfoList esrSystemInfoList = new EsrSystemInfoList();
34     EsrSystemInfo esrSystemInfoObj = new EsrSystemInfo();
35     
36     cloudRegion.setCloudOwner(vimRegisterInfo.getCloudOwner());
37     cloudRegion.setCloudRegionId(vimRegisterInfo.getCloudRegionId());
38     cloudRegion.setCloudType(vimRegisterInfo.getCloudType());
39     cloudRegion.setCloudRegionVersion(vimRegisterInfo.getCloudRegionVersion());
40     cloudRegion.setCloudZone(vimRegisterInfo.getCloudZone());
41     cloudRegion.setComplexName(vimRegisterInfo.getComplexName());
42     cloudRegion.setOwnerDefinedType(vimRegisterInfo.getOwnerDefinedType());
43     cloudRegion.setCloudExtraInfo(vimRegisterInfo.getCloudExtraInfo());
44     
45     esrSystemInfoObj = vimAuthInfo2EsrSystemInfoObj(vimRegisterInfo.getVimAuthInfos());
46     esrSystemInfoObj.setSystemStatus(vimRegisterInfo.getStatus());
47     esrSystemInfoList = ExtsysUtil.getEsrSystemInfoListFromAuthInfo(esrSystemInfoObj);
48     cloudRegion.setEsrSystemInfoList(esrSystemInfoList);
49     return cloudRegion;
50   }
51
52   private static EsrSystemInfo vimAuthInfo2EsrSystemInfoObj(ArrayList<VimAuthInfo> vimAuthInfos) {
53     EsrSystemInfo esrSystemInfoObj = new EsrSystemInfo();
54     VimAuthInfo vimAuthInfo = new VimAuthInfo();
55     vimAuthInfo = vimAuthInfos.get(0);
56     esrSystemInfoObj.setCloudDomain(vimAuthInfo.getCloudDomain());
57     esrSystemInfoObj.setUserName(vimAuthInfo.getUserName());
58     esrSystemInfoObj.setPassword(vimAuthInfo.getPassword());
59     esrSystemInfoObj.setServiceUrl(vimAuthInfo.getAuthUrl());
60     esrSystemInfoObj.setSslCassert(vimAuthInfo.getSslCacert());
61     esrSystemInfoObj.setSslInsecure(vimAuthInfo.getSslInsecure());
62     esrSystemInfoObj.setEsrSystemInfoId(ExtsysUtil.generateId());
63     esrSystemInfoObj.setSystemType(SystemType.VIM.toString());
64 //    esrSystemInfoObj.setSystemStatus(SystemStatus.normal.toString());
65     return esrSystemInfoObj;
66   }
67   
68   private static VimAuthInfo authInfo2VimAuthInfo(EsrSystemInfo authInfo) {
69     VimAuthInfo vimAuthInfo = new VimAuthInfo();
70     vimAuthInfo.setAuthUrl(authInfo.getServiceUrl());
71     vimAuthInfo.setCloudDomain(authInfo.getCloudDomain());
72     vimAuthInfo.setPassword(authInfo.getPassword());
73     vimAuthInfo.setSslCacert(authInfo.getSslCassert());
74     vimAuthInfo.setSslInsecure(authInfo.getSslInsecure());
75     vimAuthInfo.setUserName(authInfo.getUserName());
76     return vimAuthInfo;
77   }
78   
79   public static VimRegisterInfo cloudRegion2VimRegisterInfo(CloudRegionDetail cloudRegion) {
80     VimRegisterInfo vimRegisterInfo = new VimRegisterInfo();
81     VimAuthInfo vimAuthInfo = new VimAuthInfo();
82     ArrayList<VimAuthInfo> vimAuthInfos = new ArrayList<VimAuthInfo>();
83     vimAuthInfo = authInfo2VimAuthInfo(cloudRegion.getEsrSystemInfoList().getEsrSystemInfo().get(0));
84     vimAuthInfos.add(vimAuthInfo);
85     vimRegisterInfo.setVimAuthInfos(vimAuthInfos);
86     vimRegisterInfo.setCloudExtraInfo(cloudRegion.getCloudExtraInfo());
87     vimRegisterInfo.setCloudOwner(cloudRegion.getCloudOwner());
88     vimRegisterInfo.setCloudRegionId(cloudRegion.getCloudRegionId());
89     vimRegisterInfo.setCloudType(cloudRegion.getCloudType());
90     vimRegisterInfo.setCloudZone(cloudRegion.getCloudZone());
91     vimRegisterInfo.setComplexName(cloudRegion.getComplexName());
92     vimRegisterInfo.setCloudRegionVersion(cloudRegion.getCloudRegionVersion());
93     vimRegisterInfo.setOwnerDefinedType(cloudRegion.getOwnerDefinedType());
94     vimRegisterInfo.setStatus(cloudRegion.getEsrSystemInfoList().getEsrSystemInfo().get(0).getSystemStatus());
95     return vimRegisterInfo;
96   }
97 }