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