0a69f40f0048d6761997ea3ff45ec2f90726c905
[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 import java.util.List;
21
22 import org.onap.aai.esr.common.SystemType;
23 import org.onap.aai.esr.entity.aai.EsrSystemInfo;
24 import org.onap.aai.esr.entity.aai.CloudRegionDetail;
25 import org.onap.aai.esr.entity.aai.EsrSystemInfoList;
26 import org.onap.aai.esr.entity.rest.VimAuthInfo;
27 import org.onap.aai.esr.entity.rest.VimRegisterInfo;
28
29 public class VimManagerUtil {
30   private static ExtsysUtil extsysUtil = new ExtsysUtil();
31   
32   public CloudRegionDetail vimRegisterInfo2CloudRegion(VimRegisterInfo vimRegisterInfo) {
33     CloudRegionDetail cloudRegion = new CloudRegionDetail();
34     
35     cloudRegion.setCloudOwner(vimRegisterInfo.getCloudOwner());
36     cloudRegion.setCloudRegionId(vimRegisterInfo.getCloudRegionId());
37     cloudRegion.setCloudType(vimRegisterInfo.getCloudType());
38     cloudRegion.setCloudRegionVersion(vimRegisterInfo.getCloudRegionVersion());
39     cloudRegion.setCloudZone(vimRegisterInfo.getCloudZone());
40     cloudRegion.setComplexName(vimRegisterInfo.getComplexName());
41     cloudRegion.setOwnerDefinedType(vimRegisterInfo.getOwnerDefinedType());
42     cloudRegion.setCloudExtraInfo(vimRegisterInfo.getCloudExtraInfo());
43     
44     EsrSystemInfo esrSystemInfoObj = vimAuthInfo2EsrSystemInfoObj(vimRegisterInfo.getVimAuthInfos());
45     esrSystemInfoObj.setSystemStatus(vimRegisterInfo.getStatus());
46     EsrSystemInfoList esrSystemInfoList = extsysUtil.getEsrSystemInfoListFromAuthInfo(esrSystemInfoObj);
47     cloudRegion.setEsrSystemInfoList(esrSystemInfoList);
48     return cloudRegion;
49   }
50
51   private EsrSystemInfo vimAuthInfo2EsrSystemInfoObj(List<VimAuthInfo> vimAuthInfos) {
52     EsrSystemInfo esrSystemInfoObj = new EsrSystemInfo();
53     VimAuthInfo vimAuthInfo = vimAuthInfos.get(0);
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.setDefaultTenant(vimAuthInfo.getDefaultTenant());
61     esrSystemInfoObj.setEsrSystemInfoId(extsysUtil.generateId());
62     esrSystemInfoObj.setSystemType(SystemType.VIM.toString());
63 //    esrSystemInfoObj.setSystemStatus(SystemStatus.normal.toString());
64     return esrSystemInfoObj;
65   }
66   
67   private VimAuthInfo authInfo2VimAuthInfo(EsrSystemInfo authInfo) {
68     VimAuthInfo vimAuthInfo = new VimAuthInfo();
69     vimAuthInfo.setAuthUrl(authInfo.getServiceUrl());
70     vimAuthInfo.setCloudDomain(authInfo.getCloudDomain());
71     vimAuthInfo.setPassword(authInfo.getPassword());
72     vimAuthInfo.setSslCacert(authInfo.getSslCassert());
73     vimAuthInfo.setSslInsecure(authInfo.getSslInsecure());
74     vimAuthInfo.setUserName(authInfo.getUserName());
75     vimAuthInfo.setDefaultTenant(authInfo.getDefaultTenant());
76     return vimAuthInfo;
77   }
78   
79   public VimRegisterInfo cloudRegion2VimRegisterInfo(CloudRegionDetail cloudRegion) {
80     VimRegisterInfo vimRegisterInfo = new VimRegisterInfo();
81     List<VimAuthInfo> vimAuthInfos = new ArrayList<>();
82     if(cloudRegion.getEsrSystemInfoList()!=null){
83       VimAuthInfo vimAuthInfo = authInfo2VimAuthInfo(cloudRegion.getEsrSystemInfoList().getEsrSystemInfo().get(0));
84       vimAuthInfos.add(vimAuthInfo);
85       vimRegisterInfo.setStatus(cloudRegion.getEsrSystemInfoList().getEsrSystemInfo().get(0).getSystemStatus());
86     }
87     vimRegisterInfo.setVimAuthInfos(vimAuthInfos);
88     vimRegisterInfo.setCloudExtraInfo(cloudRegion.getCloudExtraInfo());
89     vimRegisterInfo.setCloudOwner(cloudRegion.getCloudOwner());
90     vimRegisterInfo.setCloudRegionId(cloudRegion.getCloudRegionId());
91     vimRegisterInfo.setCloudType(cloudRegion.getCloudType());
92     vimRegisterInfo.setCloudZone(cloudRegion.getCloudZone());
93     vimRegisterInfo.setComplexName(cloudRegion.getComplexName());
94     vimRegisterInfo.setCloudRegionVersion(cloudRegion.getCloudRegionVersion());
95     vimRegisterInfo.setOwnerDefinedType(cloudRegion.getOwnerDefinedType());
96     return vimRegisterInfo;
97   }
98 }