Skip to content

Commit c2335ee

Browse files
khushi-mehta-15francisf
authored andcommitted
making qei url configurable for testing
1 parent 3755963 commit c2335ee

File tree

8 files changed

+105
-37
lines changed

8 files changed

+105
-37
lines changed

src/main/java/com/browserstack/automate/ci/common/BrowserStackBuildWrapperOperations.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,13 @@ public void buildEnvVars(Map<String, String> env) {
186186
env.put(BrowserStackEnvVars.BROWSERSTACK_RERUN, reRun);
187187
logEnvVar(BrowserStackEnvVars.BROWSERSTACK_RERUN, reRun);
188188
}
189+
190+
// TODO
191+
String host = env.get(BrowserStackEnvVars.QEI_URL);
192+
if ( host != null ) {
193+
logEnvVar(BrowserStackEnvVars.QEI_URL, host);
194+
Constants.QualityDashboardAPI.setHost(host, logger);
195+
}
189196
}
190197

191198
public void logEnvVar(String key, String value) {

src/main/java/com/browserstack/automate/ci/common/BrowserStackEnvVars.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ public interface BrowserStackEnvVars {
1515
String GRR_JENKINS_KEY = "BROWSERSTACK_GRR_REGION";
1616
String AUTOMATE_API_ENV_KEY = "browserstack.automate.api";
1717
String APP_AUTOMATE_API_ENV_KEY = "browserstack.app-automate.api";
18+
String QEI_URL = "QEI_URL";
1819
}

src/main/java/com/browserstack/automate/ci/common/constants/Constants.java

Lines changed: 77 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.browserstack.automate.ci.common.constants;
22

3+
// TODO
4+
import java.io.PrintStream;
35
import java.util.Collections;
46
import java.util.HashMap;
57
import java.util.Map;
@@ -62,27 +64,80 @@ public static final class SessionStatus {
6264
public static final String PASSED = "passed";
6365
}
6466

65-
public static final class QualityDashboardAPI {
66-
public static final String URL_BASE = "https://quality-engineering-insights.browserstack.com/api/v1/jenkins";
67-
68-
public static final String LOG_MESSAGE = URL_BASE + "/log-message";
69-
public static final String IS_INIT_SETUP_REQUIRED = URL_BASE + "/init-setup-required";
70-
71-
public static final String HISTORY_FOR_DAYS = URL_BASE + "/history-for-days";
72-
73-
public static final String SAVE_PIPELINES = URL_BASE + "/save-pipelines";
74-
75-
public static final String SAVE_PIPELINE_RESULTS = URL_BASE + "/save-pipeline-results";
76-
77-
public static final String ITEM_CRUD = URL_BASE + "/item";
78-
public static final String IS_QD_ENABLED = URL_BASE + "/qd-enabled";
79-
public static final String IS_PIPELINE_ENABLED = URL_BASE + "/pipeline-enabled";
80-
public static final String GET_RESULT_DIRECTORY = URL_BASE + "/get-result-directory";
81-
82-
public static final String UPLOAD_RESULT_ZIP = URL_BASE + "/upload-result";
83-
public static final String STORE_PIPELINE_RESULTS = URL_BASE + "/save-results";
84-
85-
public static final String PROJECTS_PAGE_SIZE = URL_BASE + "/projects-page-size";
86-
public static final String RESULTS_PAGE_SIZE = URL_BASE + "/results-page-size";
67+
public static class QualityDashboardAPI {
68+
// TODO
69+
public static String host = "https://quality-engineering-insights.browserstack.com";
70+
public static String URL_BASE;
71+
// public static PrintStream newlogger = System.out; // Ensure logging to console
72+
73+
public static String getHost() {
74+
return host;
75+
}
76+
77+
public static void setHost(String newHost, PrintStream logger) {
78+
host = newHost;
79+
// newlogger = logger;
80+
81+
// log(logger, "QualityDashboardAPI newHost: " + getHost());
82+
// URL_BASE = host + "/api/v1/jenkins";
83+
// log(newlogger, "QualityDashboardAPI url base host: " + URL_BASE);
84+
// log(newlogger, "QualityDashboardAPI host1: " + getHost());
85+
}
86+
87+
public static String getURLBase() {
88+
return getHost() + "/api/v1/jenkins";
89+
}
90+
91+
public static String getLogMessageEndpoint() {
92+
return getURLBase() + "/log-message";
93+
}
94+
95+
public static String getIsInitSetupRequiredEndpoint() {
96+
return getURLBase() + "/init-setup-required";
97+
}
98+
99+
public static String getHistoryForDaysEndpoint() {
100+
return getURLBase() + "/history-for-days";
101+
}
102+
103+
public static String getSavePipelinesEndpoint() {
104+
return getURLBase() + "/save-pipelines";
105+
}
106+
107+
public static String getSavePipelineResultsEndpoint() {
108+
return getURLBase() + "/save-pipeline-results";
109+
}
110+
111+
public static String getItemCrudEndpoint() {
112+
return getURLBase() + "/item";
113+
}
114+
115+
public static String getIsQdEnabledEndpoint() {
116+
return getURLBase() + "/qd-enabled";
117+
}
118+
119+
public static String getIsPipelineEnabledEndpoint() {
120+
return getURLBase() + "/pipeline-enabled";
121+
}
122+
123+
public static String getResultDirectoryEndpoint() {
124+
return getURLBase() + "/get-result-directory";
125+
}
126+
127+
public static String getUploadResultZipEndpoint() {
128+
return getURLBase() + "/upload-result";
129+
}
130+
131+
public static String getStorePipelineResultsEndpoint() {
132+
return getURLBase() + "/save-results";
133+
}
134+
135+
public static String getProjectsPageSizeEndpoint() {
136+
return getURLBase() + "/projects-page-size";
137+
}
138+
139+
public static String getResultsPageSizeEndpoint() {
140+
return getURLBase() + "/results-page-size";
141+
}
87142
}
88143
}

src/main/java/com/browserstack/automate/ci/jenkins/pipeline/BrowserStackPipelineStepExecution.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ public boolean start() throws Exception {
100100
EnvVars overrides = run.getEnvironment(taskListener);
101101
HashMap<String, String> overridesMap = new HashMap<String, String>();
102102
overridesMap.put(Constants.JENKINS_BUILD_TAG, overrides.get(Constants.JENKINS_BUILD_TAG));
103+
// TODO
104+
log(logger, overrides.toString());
105+
if ( overrides.containsKey(BrowserStackEnvVars.QEI_URL) ) {
106+
overridesMap.put(BrowserStackEnvVars.QEI_URL, overrides.get(BrowserStackEnvVars.QEI_URL));
107+
}
103108
if ( parentContextEnvVars.containsKey(BrowserStackEnvVars.GRR_JENKINS_KEY) ) {
104109
overridesMap.put(BrowserStackEnvVars.GRR_JENKINS_KEY, parentContextEnvVars.get(BrowserStackEnvVars.GRR_JENKINS_KEY));
105110
}

src/main/java/com/browserstack/automate/ci/jenkins/qualityDashboard/QualityDashboardAPIUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void logToQD(BrowserStackCredentials browserStackCredentials, String logM
7777
ObjectMapper objectMapper = new ObjectMapper();
7878
String jsonBody = objectMapper.writeValueAsString(logMessageObj);
7979
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonBody);
80-
makePostRequestToQd(Constants.QualityDashboardAPI.LOG_MESSAGE, browserStackCredentials, requestBody);
80+
makePostRequestToQd(Constants.QualityDashboardAPI.getLogMessageEndpoint(), browserStackCredentials, requestBody);
8181
}
8282
}
8383

src/main/java/com/browserstack/automate/ci/jenkins/qualityDashboard/QualityDashboardInit.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ private static void checkQDIntegrationAndDumpMetaData(BrowserStackCredentials br
9090

9191
private static boolean initialQDSetupRequired(BrowserStackCredentials browserStackCredentials) throws JsonProcessingException {
9292
try {
93-
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.IS_INIT_SETUP_REQUIRED, browserStackCredentials);
93+
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.getIsInitSetupRequiredEndpoint(), browserStackCredentials);
9494
if (response != null && response.code() == HttpURLConnection.HTTP_OK) {
9595
ResponseBody responseBody = response.body();
9696
if(responseBody != null && responseBody.string().equals("REQUIRED")) {
@@ -134,7 +134,7 @@ private static boolean sendPipelinesPaginated(BrowserStackCredentials browserSta
134134
PipelinesPaginated pipelinesPaginated = new PipelinesPaginated(page, totalPages, singlePagePipelineList);
135135
String jsonBody = objectMapper.writeValueAsString(pipelinesPaginated);
136136
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonBody);
137-
Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.SAVE_PIPELINES, browserStackCredentials, requestBody);
137+
Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.getSavePipelinesEndpoint(), browserStackCredentials, requestBody);
138138
if (response == null || response.code() != HttpURLConnection.HTTP_OK) {
139139
apiUtil.logToQD(browserStackCredentials,"Got Non 200 response while saving projects");
140140
isSuccess = false;
@@ -188,7 +188,7 @@ private static void sendBuildsPaginated(BrowserStackCredentials browserStackCred
188188
BuildResultsPaginated buildResultsPaginated = new BuildResultsPaginated(page, totalPages, buildResultList);
189189
String jsonBody = objectMapper.writeValueAsString(buildResultsPaginated);
190190
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonBody);
191-
Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.SAVE_PIPELINE_RESULTS, browserStackCredentials, requestBody);
191+
Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.getSavePipelineResultsEndpoint(), browserStackCredentials, requestBody);
192192
if (response == null || response.code() != HttpURLConnection.HTTP_OK) {
193193
apiUtil.logToQD(browserStackCredentials,"Got Non 200 response while saving projects");
194194
break;
@@ -202,7 +202,7 @@ private static void sendBuildsPaginated(BrowserStackCredentials browserStackCred
202202
private static int getHistoryForDays(BrowserStackCredentials browserStackCredentials) {
203203
int no_of_days = 90;
204204
try {
205-
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.HISTORY_FOR_DAYS, browserStackCredentials);
205+
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.getHistoryForDaysEndpoint(), browserStackCredentials);
206206
if (response != null && response.code() == HttpURLConnection.HTTP_OK) {
207207
ResponseBody responseBody = response.body();
208208
if(responseBody != null) {
@@ -221,7 +221,7 @@ private static int getHistoryForDays(BrowserStackCredentials browserStackCredent
221221
private static int getProjectPageSize(BrowserStackCredentials browserStackCredentials) {
222222
int projectPageSize = 2000;
223223
try {
224-
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.PROJECTS_PAGE_SIZE, browserStackCredentials);
224+
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.getProjectsPageSizeEndpoint(), browserStackCredentials);
225225
if (response != null && response.code() == HttpURLConnection.HTTP_OK) {
226226
ResponseBody responseBody = response.body();
227227
if(responseBody != null) {
@@ -240,7 +240,7 @@ private static int getProjectPageSize(BrowserStackCredentials browserStackCreden
240240
private static int getResultPageSize(BrowserStackCredentials browserStackCredentials) {
241241
int resultPageSize = 1000;
242242
try {
243-
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.RESULTS_PAGE_SIZE, browserStackCredentials);
243+
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.getResultsPageSizeEndpoint(), browserStackCredentials);
244244
if (response != null && response.code() == HttpURLConnection.HTTP_OK) {
245245
ResponseBody responseBody = response.body();
246246
if(responseBody != null) {

src/main/java/com/browserstack/automate/ci/jenkins/qualityDashboard/QualityDashboardInitItemListener.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void onCreated(Item job) {
2525
if(itemType != null && itemType.equals("PIPELINE")) {
2626
try {
2727
String jsonBody = getJsonReqBody(new ItemUpdate(itemName, itemType));
28-
syncItemListToQD(jsonBody, Constants.QualityDashboardAPI.ITEM_CRUD, "POST");
28+
syncItemListToQD(jsonBody, Constants.QualityDashboardAPI.getItemCrudEndpoint(), "POST");
2929
} catch(IOException e) {
3030
e.printStackTrace();
3131
}
@@ -39,7 +39,7 @@ public void onDeleted(Item job) {
3939
if(itemType != null) {
4040
try {
4141
String jsonBody = getJsonReqBody(new ItemUpdate(itemName, itemType));
42-
syncItemListToQD(jsonBody, Constants.QualityDashboardAPI.ITEM_CRUD, "DELETE");
42+
syncItemListToQD(jsonBody, Constants.QualityDashboardAPI.getItemCrudEndpoint(), "DELETE");
4343
} catch(IOException e) {
4444
e.printStackTrace();
4545
}
@@ -54,7 +54,7 @@ public void onRenamed(Item job, String oldName, String newName) {
5454
oldName = job.getParent().getFullName() + "/" + oldName;
5555
newName = job.getParent().getFullName() + "/" + newName;
5656
String jsonBody = getJsonReqBody(new ItemRename(oldName, newName, itemType));
57-
syncItemListToQD(jsonBody, Constants.QualityDashboardAPI.ITEM_CRUD, "PUT");
57+
syncItemListToQD(jsonBody, Constants.QualityDashboardAPI.getItemCrudEndpoint(), "PUT");
5858
} catch(IOException e) {
5959
e.printStackTrace();
6060
}

src/main/java/com/browserstack/automate/ci/jenkins/qualityDashboard/QualityDashboardPipelineTracker.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private void sendBuildDataToQD(Run run, Result overallResult, String finalZipPat
109109

110110
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonBody);
111111
apiUtil.logToQD(browserStackCredentials, "Sending Final Results for jobName: " + jobName + " and buildNumber: " + buildNumber);
112-
apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.STORE_PIPELINE_RESULTS, browserStackCredentials, requestBody);
112+
apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.getStorePipelineResultsEndpoint(), browserStackCredentials, requestBody);
113113
} catch(IOException e) {
114114
e.printStackTrace();
115115
}
@@ -153,7 +153,7 @@ private String getUrlForPipeline(Run<?, ?> build) {
153153
}
154154

155155
private boolean isQDEnabled(BrowserStackCredentials browserStackCredentials) throws IOException {
156-
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.IS_QD_ENABLED, browserStackCredentials);
156+
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.getIsQdEnabledEndpoint(), browserStackCredentials);
157157
if (response != null && response.code() == HttpURLConnection.HTTP_OK) {
158158
ResponseBody responseBody = response.body();
159159
if(responseBody != null && Boolean.parseBoolean(response.body().string())) {
@@ -170,7 +170,7 @@ private boolean isPipelineEnabledForQD(BrowserStackCredentials browserStackCrede
170170
ObjectMapper objectMapper = new ObjectMapper();
171171
String jsonBody = objectMapper.writeValueAsString(getPipelineEnabledObj);
172172
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonBody);
173-
Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.IS_PIPELINE_ENABLED, browserStackCredentials, requestBody);
173+
Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.getIsPipelineEnabledEndpoint(), browserStackCredentials, requestBody);
174174
if (response != null && response.code() == HttpURLConnection.HTTP_OK) {
175175
ResponseBody responseBody = response.body();
176176
if(responseBody != null && Boolean.parseBoolean(response.body().string())) {
@@ -190,7 +190,7 @@ private String getResultDirForPipeline(String pipelineUrl, BrowserStackCredentia
190190
String jsonBody = objectMapper.writeValueAsString(getResultDirReqObj);
191191

192192
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonBody);
193-
Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.GET_RESULT_DIRECTORY, browserStackCredentials, requestBody);
193+
Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.getResultDirectoryEndpoint(), browserStackCredentials, requestBody);
194194
if (response != null && response.code() == HttpURLConnection.HTTP_OK) {
195195
String responseBody = response.body() !=null ? response.body().string() : null;
196196
resultDir = responseBody;
@@ -234,7 +234,7 @@ private String uploadZipToQd(String pathToZip, BrowserStackCredentials browserSt
234234
.addFormDataPart("buildNumber", String.valueOf(buildNumber))
235235
.build();
236236

237-
Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.UPLOAD_RESULT_ZIP, browserStackCredentials, requestBody);
237+
Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.getUploadResultZipEndpoint(), browserStackCredentials, requestBody);
238238
if (response != null && response.code() == HttpURLConnection.HTTP_OK) {
239239
qdS3Url = response.body() !=null ? response.body().string() : null;
240240
}

0 commit comments

Comments
 (0)