Create on boarding docker
[sdc.git] / test-apis-ci / src / main / java / org / openecomp / sdc / ci / tests / utils / general / OnboardingUtils.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.openecomp.sdc.ci.tests.utils.general;
22
23 import java.util.Arrays;
24 import java.util.Calendar;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28 import java.util.UUID;
29
30 import org.openecomp.sdc.be.model.User;
31 import org.openecomp.sdc.ci.tests.api.Urls;
32 import org.openecomp.sdc.ci.tests.config.Config;
33 import org.openecomp.sdc.ci.tests.datatypes.http.HttpHeaderEnum;
34 import org.openecomp.sdc.ci.tests.datatypes.http.HttpRequest;
35 import org.openecomp.sdc.ci.tests.datatypes.http.RestResponse;
36 import org.openecomp.sdc.ci.tests.utils.Utils;
37
38 import java.util.*;
39
40 public class OnboardingUtils {
41
42         /**
43          * excluded VNF file list
44          */
45         public static List<String> exludeVnfList =
46 //              new ArrayList<>();
47         Arrays.asList(
48 //              DUPLICATE_RESOURCE_ID_IN_DIFFERENT_FILES:
49                 "2017-376_vMOG_11_1.zip",
50                 "HeatCandidate_2017-09-20_15-06_66Name_2016-20-visbc1vf-v6.0-(VOIP).zip",
51                 "1 Apndns-1710-vf v3.0.zip",
52                 "1 AVPN_vRE_BV_volume-V2.zip",
53                 "1-Vf-zrdm5bpxtc02-092017-(MOBILITY)_v3.0.zip",
54                 "1-Mobility_vprobe_fe_11_2_1_vf_(MOBILITY)_v1.0.zip",
55 //              ORCHESTRATION_NOT_FOUND:
56                 "1-2017-491-4vshaken-HTTP-CM-vf-(VOIP)_v2.0.zip",
57 //              did not succeed to create package of new VSP  expected:<200> but was:<500>:
58                 "1-Riverbed-WANx1710VFv_v2.0.zip",
59                 "1-LMSP_v5-062317_v3.0.zip",
60                 "1-VF-Cisco-vCSR-1710_v2.0.zip",
61                 "1-mDNS-preload_1710-0914_v3.0.zip",
62                 "1-Firewall_170_Pala_Aloto_VF_v2.0.zip",
63                 "2-mDNS-preload-1710-0914_v3.1VF.zip",
64                 "1-2016-233_xsp_bfsa_nin2-vf-V1.0-VOIP-10-20.zip",
65 //              did not succeed to submit new VSP expected:<200> but was:<417>
66                 "1-VF_vEPDG_v4.0.zip",
67                 "1-VF-2017-491_9vShaken-F5-LB_v1.0.zip",
68                 "2-2016-73_Mow-AVPN-vpe-BV-L_v1.0.zip",
69                 "VF-2017389vTSBCDPA2-v4.0.zip",
70                 "1-vEPDG_V1.0(3).zip",
71                 "1-vHSS-EPC-RDM3-Lab-VF-0830_V3.0.zip",
72                 "2-2016-73_Mow-AVPN-vPE-BV-L_VF_V2.0_1027.zip",
73                 "1-ADIOD_base_vPE_BV_v9.0.zip",
74                 "Vhss-epc-rdm3-lab-vf-0921-v2.0-MOBILITY-10-20.zip",
75                 "1-Vhss-epc-rdm3-lab-vf-0921_VF00816v2.0-MOBILITY-10-20.zip",
76                 "1-VF-vUSP-CCF-DB-0620_v1.0base_vDB.zip",
77                 "1-Vusp_vhss-ims_cm-repo1_V1.zip",
78                 "1-base_vepdg_volume_v4.0.zip",
79                 "1-Vocg_1710-2017-509(2)_v1.0.zip",
80                 "1-2016-20-vISBC3VF_v3.0.zip",
81                 "Apndns-1710-vf-v3.0-10-20.zip",
82                 "1-VF-EFMC_DBE_Nin_v27.0.zip",
83                 "2-APNDNS_1710-VF_v4.0.zip",
84                 "1-Mow_adig_vpe_bv-V3.0.zip",
85                 "1-VF-2017-488_ADOID_vPE_v9.0.zip",
86                 "1-MOBT_Nimbus_3_Sprint-1.zip",
87                 "1-VF-2017-491_9vShaken-CM_v1.0.zip",
88                 "1-VF_zrdm5bpxtc02_092017_v2.0.zip",
89 //              Error: TOSCA yaml file %1 cannot be modeled to VF as it does not contain \u0027topology_template
90                 "1-VF-Checkpoint_vFW-1710_v1.0.zip"
91         );
92
93         /**
94          * additional files to exludeVnfList files for tosca parser tests
95          */
96         protected static List<String> exludeVnfListForToscaParser = //new ArrayList<String>();
97         Arrays.asList(
98                 "1-Vvig-062017-(MOBILITY)_v5.1.zip",
99                 "1-Mvm-sbc-1710-092017-(MOBILITY)_v7.0.zip",
100                 "1-2017-492-5vshaken-SIP-AS-vf-(VOIP)_v2.0.zip",
101                 "1-201712-488-adiod-vpe-(Layer-0-3)_v2.0.zip",
102                 "2017-502.zip",
103                 "1-2017-505-urlb-vhepe-(Layer-0-3)_v2.0.zip",
104                 "2017-376_vMOG_11_1.zip",
105                 "HeatCandidate_2017-09-22_01-30_60Name_Vdbe-vsp-15.1x49-d50.3-v3.0-(VOIP).zip",
106                 "HeatCandidate_2017-09-22_01-42_57Name_2017389vtsbc4vf-v10.0-(VOIP).zip",
107                 "HeatCandidate_2017-09-20_13-47_68Name_2017-492-5vshaken-SIP-AS-vf-v1.0-(VOIP)_10202017.zip",
108                 "1-2016-20-visbc3vf-(VOIP)_v2.1.zip",
109                 "1-2017-404_vUSP_vCCF_AIC3.0-(VOIP)_v6.0.zip",
110                 "1-2017389vtsbc4vf-(VOIP)_v11.0.zip"
111         );
112         
113         public static String handleFilename(String heatFileName) {
114                 final String namePrefix = String.format("%sVF%s", ElementFactory.getResourcePrefix(), "Onboarded-");
115                 final String nameSuffix = "-" + getShortUUID();
116
117                 String subHeatFileName = heatFileName.substring(0, heatFileName.lastIndexOf("."));
118
119                 if ((namePrefix + subHeatFileName + nameSuffix).length() >= 50) {
120                         subHeatFileName = subHeatFileName.substring(0, 50 - namePrefix.length() - nameSuffix.length());
121                 }
122
123                 if (subHeatFileName.contains("(") || subHeatFileName.contains(")")) {
124                         subHeatFileName = subHeatFileName.replace("(", "-");
125                         subHeatFileName = subHeatFileName.replace(")", "-");
126                 }
127
128                 String vnfName = namePrefix + subHeatFileName + nameSuffix;
129                 return vnfName;
130         }
131         
132
133         public static String getShortUUID() {
134                 return UUID.randomUUID().toString().split("-")[0];
135         }
136
137         private static RestResponse actionOnComponent(String vspid, String body, String onboardComponent, User user, String componentVersion) throws Exception {
138                 Config config = Utils.getConfig();
139                 String url = String.format(Urls.ACTION_ON_COMPONENT, config.getOnboardingBeHost(), config.getOnboardingBePort(), onboardComponent, vspid, componentVersion);
140                 String userId = user.getUserId();
141                 Map<String, String> headersMap = prepareHeadersMap(userId);
142
143                 HttpRequest http = new HttpRequest();
144                 RestResponse response = http.httpSendPut(url, body, headersMap);
145                 return response;
146         }
147
148         protected static Map<String, String> prepareHeadersMap(String userId) {
149                 Map<String, String> headersMap = new HashMap<String, String>();
150                 headersMap.put(HttpHeaderEnum.CONTENT_TYPE.getValue(), "application/json");
151                 headersMap.put(HttpHeaderEnum.ACCEPT.getValue(), "application/json");
152                 headersMap.put(HttpHeaderEnum.USER_ID.getValue(), userId);
153                 return headersMap;
154         }
155
156
157         /**
158          * @return
159          * The method returns VNF names list from Files directory under sdc-vnfs repository
160          */
161         public static List<String> getVnfNamesFileList() {
162                 String filepath = FileHandling.getVnfRepositoryPath();
163                 List<String> fileNamesFromFolder = FileHandling.getZipFileNamesFromFolder(filepath);
164                 //Please remove the hardcoded configuration ONAP Tal G!!!!!!
165                 fileNamesFromFolder.removeAll(exludeVnfList);
166                 //List<String> halfResourceListByDay = divideListByDayOfMonth(fileNamesFromFolder);
167                 //System.out.println(halfResourceListByDay.toString());
168                 return fileNamesFromFolder;
169         }
170
171         /**
172          * @param vnfNamesFileList
173          * @return divide List according to day of month, if day of month is even as get first half part of the List, else - second
174          */
175         public static List<String> divideListByDayOfMonth(List<String> vnfNamesFileList){
176
177                 Calendar cal = Calendar.getInstance();
178                 int dayOfMonth = cal.get(Calendar.DAY_OF_MONTH)+1;
179                 int filesCount = vnfNamesFileList.size();
180                 if(dayOfMonth%2 == 0){
181                         return vnfNamesFileList.subList(0,filesCount/2);
182                 }else{
183                         return vnfNamesFileList.subList(filesCount/2, filesCount);
184                 }
185         }
186         
187         /**
188          * @return
189          * The method returns VNF names list from Files directory under sdc-vnfs repository excluding zip files that known as failed in tosca parser
190          */
191         public static List<String> getVnfNamesFileListExcludeToscaParserFailure() {
192                 List<String> fileNamesFromFolder = getVnfNamesFileList();
193                 fileNamesFromFolder.removeAll(exludeVnfListForToscaParser);
194                 return fileNamesFromFolder;
195         }
196
197
198         public static Object[][] filterObjectArrWithExcludedVnfs(Object[][] objectArr)
199         {
200                 Object[][] filteredArObject = new Object[objectArr.length][];
201
202                 int index = 0;
203
204                 for (int i = 0; i < objectArr.length ; i++) {
205
206                         String vnfSourceFile = (String) objectArr[i][0];
207                         String vnfUpdateFile = (String) objectArr[i][1];
208
209                         if(!exludeVnfList.contains(vnfSourceFile) && !exludeVnfList.contains(vnfUpdateFile))
210                         {
211                                 filteredArObject[index] = new Object[]{vnfSourceFile , vnfUpdateFile };
212                                 index++;
213                         }
214                 }
215
216                 return filteredArObject;
217         }
218 }
219
220