88cceea6715484cffde8661657f2468ac4defb13
[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 public class VimManagerUtil {
29   private static ExtsysUtil extsysUtil = new ExtsysUtil();
30   
31   public 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 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.setDefaultTenant(vimAuthInfo.getDefaultTenant());
63     esrSystemInfoObj.setEsrSystemInfoId(extsysUtil.generateId());
64     esrSystemInfoObj.setSystemType(SystemType.VIM.toString());
65 //    esrSystemInfoObj.setSystemStatus(SystemStatus.normal.toString());
66     return esrSystemInfoObj;
67   }
68   
69   private VimAuthInfo authInfo2VimAuthInfo(EsrSystemInfo authInfo) {
70     VimAuthInfo vimAuthInfo = new VimAuthInfo();
71     vimAuthInfo.setAuthUrl(authInfo.getServiceUrl());
72     vimAuthInfo.setCloudDomain(authInfo.getCloudDomain());
73     vimAuthInfo.setPassword(authInfo.getPassword());
74     vimAuthInfo.setSslCacert(authInfo.getSslCassert());
75     vimAuthInfo.setSslInsecure(authInfo.getSslInsecure());
76     vimAuthInfo.setUserName(authInfo.getUserName());
77     vimAuthInfo.setDefaultTenant(authInfo.getDefaultTenant());
78     return vimAuthInfo;
79   }
80   
81   public VimRegisterInfo cloudRegion2VimRegisterInfo(CloudRegionDetail cloudRegion) {
82     VimRegisterInfo vimRegisterInfo = new VimRegisterInfo();
83     VimAuthInfo vimAuthInfo = new VimAuthInfo();
84     ArrayList<VimAuthInfo> vimAuthInfos = new ArrayList<VimAuthInfo>();
85     if(cloudRegion.getEsrSystemInfoList()!=null){
86       vimAuthInfo = authInfo2VimAuthInfo(cloudRegion.getEsrSystemInfoList().getEsrSystemInfo().get(0));
87       vimRegisterInfo.setStatus(cloudRegion.getEsrSystemInfoList().getEsrSystemInfo().get(0).getSystemStatus());
88     }
89     vimAuthInfos.add(vimAuthInfo);
90     vimRegisterInfo.setVimAuthInfos(vimAuthInfos);
91     vimRegisterInfo.setCloudExtraInfo(cloudRegion.getCloudExtraInfo());
92     vimRegisterInfo.setCloudOwner(cloudRegion.getCloudOwner());
93     vimRegisterInfo.setCloudRegionId(cloudRegion.getCloudRegionId());
94     vimRegisterInfo.setCloudType(cloudRegion.getCloudType());
95     vimRegisterInfo.setCloudZone(cloudRegion.getCloudZone());
96     vimRegisterInfo.setComplexName(cloudRegion.getComplexName());
97     vimRegisterInfo.setCloudRegionVersion(cloudRegion.getCloudRegionVersion());
98     vimRegisterInfo.setOwnerDefinedType(cloudRegion.getOwnerDefinedType());
99     return vimRegisterInfo;
100   }
101 }