Create relationship while register VIM.
[aai/esr-server.git] / esr-mgr / src / main / java / org / onap / aai / esr / util / VimManagerUtil.java
1 /**
2  * Copyright 2017-2018 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 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
34         cloudRegion.setCloudOwner(vimRegisterInfo.getCloudOwner());
35         cloudRegion.setCloudRegionId(vimRegisterInfo.getCloudRegionId());
36         cloudRegion.setCloudType(vimRegisterInfo.getCloudType());
37         cloudRegion.setCloudRegionVersion(vimRegisterInfo.getCloudRegionVersion());
38         cloudRegion.setCloudZone(vimRegisterInfo.getCloudZone());
39         cloudRegion.setComplexName(vimRegisterInfo.getComplexName());
40         cloudRegion.setOwnerDefinedType(vimRegisterInfo.getOwnerDefinedType());
41         cloudRegion.setCloudExtraInfo(vimRegisterInfo.getCloudExtraInfo());
42
43         EsrSystemInfo esrSystemInfoObj = vimAuthInfo2EsrSystemInfoObj(vimRegisterInfo.getVimAuthInfos());
44         esrSystemInfoObj.setSystemStatus(vimRegisterInfo.getStatus());
45         EsrSystemInfoList esrSystemInfoList = extsysUtil.getEsrSystemInfoListFromAuthInfo(esrSystemInfoObj);
46         cloudRegion.setEsrSystemInfoList(esrSystemInfoList);
47         return cloudRegion;
48     }
49
50     private EsrSystemInfo vimAuthInfo2EsrSystemInfoObj(List<VimAuthInfo> vimAuthInfos) {
51         EsrSystemInfo esrSystemInfoObj = new EsrSystemInfo();
52         VimAuthInfo vimAuthInfo = vimAuthInfos.get(0);
53         esrSystemInfoObj.setCloudDomain(vimAuthInfo.getCloudDomain());
54         esrSystemInfoObj.setUserName(vimAuthInfo.getUserName());
55         esrSystemInfoObj.setPassword(vimAuthInfo.getPassword());
56         esrSystemInfoObj.setServiceUrl(vimAuthInfo.getAuthUrl());
57         esrSystemInfoObj.setSslCassert(vimAuthInfo.getSslCacert());
58         esrSystemInfoObj.setSslInsecure(vimAuthInfo.getSslInsecure());
59         esrSystemInfoObj.setDefaultTenant(vimAuthInfo.getDefaultTenant());
60         esrSystemInfoObj.setEsrSystemInfoId(extsysUtil.generateId());
61         esrSystemInfoObj.setSystemType(SystemType.VIM.toString());
62         // esrSystemInfoObj.setSystemStatus(SystemStatus.normal.toString());
63         return esrSystemInfoObj;
64     }
65
66     private 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         vimAuthInfo.setDefaultTenant(authInfo.getDefaultTenant());
75         return vimAuthInfo;
76     }
77
78     public VimRegisterInfo cloudRegion2VimRegisterInfo(CloudRegionDetail cloudRegion) {
79         VimRegisterInfo vimRegisterInfo = new VimRegisterInfo();
80         List<VimAuthInfo> vimAuthInfos = new ArrayList<>();
81         if (cloudRegion.getEsrSystemInfoList() != null) {
82             VimAuthInfo vimAuthInfo =
83                     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 }