Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,14 @@ public void buildEnvVars(Map<String, String> env) {
env.put(BrowserStackEnvVars.BROWSERSTACK_RERUN, reRun);
logEnvVar(BrowserStackEnvVars.BROWSERSTACK_RERUN, reRun);
}

String host = env.get(BrowserStackEnvVars.QEI_URL);
if ( host != null ) {
logEnvVar(BrowserStackEnvVars.QEI_URL, host);
Constants.QualityDashboardAPI.setHost(host);
} else {
Constants.QualityDashboardAPI.setHost(Constants.QualityDashboardAPI.QEI_DEFAULT_URL);
}
}

public void logEnvVar(String key, String value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ public interface BrowserStackEnvVars {
String GRR_JENKINS_KEY = "BROWSERSTACK_GRR_REGION";
String AUTOMATE_API_ENV_KEY = "browserstack.automate.api";
String APP_AUTOMATE_API_ENV_KEY = "browserstack.app-automate.api";
String QEI_URL = "QEI_URL";
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,26 +63,71 @@ public static final class SessionStatus {
}

public static final class QualityDashboardAPI {
public static final String URL_BASE = "https://quality-engineering-insights.browserstack.com/api/v1/jenkins";

public static final String LOG_MESSAGE = URL_BASE + "/log-message";
public static final String IS_INIT_SETUP_REQUIRED = URL_BASE + "/init-setup-required";

public static final String HISTORY_FOR_DAYS = URL_BASE + "/history-for-days";

public static final String SAVE_PIPELINES = URL_BASE + "/save-pipelines";

public static final String SAVE_PIPELINE_RESULTS = URL_BASE + "/save-pipeline-results";

public static final String ITEM_CRUD = URL_BASE + "/item";
public static final String IS_QD_ENABLED = URL_BASE + "/qd-enabled";
public static final String IS_PIPELINE_ENABLED = URL_BASE + "/pipeline-enabled";
public static final String GET_RESULT_DIRECTORY = URL_BASE + "/get-result-directory";

public static final String UPLOAD_RESULT_ZIP = URL_BASE + "/upload-result";
public static final String STORE_PIPELINE_RESULTS = URL_BASE + "/save-results";

public static final String PROJECTS_PAGE_SIZE = URL_BASE + "/projects-page-size";
public static final String RESULTS_PAGE_SIZE = URL_BASE + "/results-page-size";
public static final String QEI_DEFAULT_URL = "https://quality-engineering-insights.browserstack.com";
public static String host = QEI_DEFAULT_URL;

public static String getHost() {
return host;
}

public static void setHost(String newHost) {
host = newHost;
}

public static final String getURLBase() {
return getHost() + "/api/v1/jenkins";
}

public static final String getLogMessageEndpoint() {
return getURLBase() + "/log-message";
}

public static final String getIsInitSetupRequiredEndpoint() {
return getURLBase() + "/init-setup-required";
}

public static final String getHistoryForDaysEndpoint() {
return getURLBase() + "/history-for-days";
}

public static final String getSavePipelinesEndpoint() {
return getURLBase() + "/save-pipelines";
}

public static final String getSavePipelineResultsEndpoint() {
return getURLBase() + "/save-pipeline-results";
}

public static final String getItemCrudEndpoint() {
return getURLBase() + "/item";
}

public static final String getIsQdEnabledEndpoint() {
return getURLBase() + "/qd-enabled";
}

public static final String getIsPipelineEnabledEndpoint() {
return getURLBase() + "/pipeline-enabled";
}

public static final String getResultDirectoryEndpoint() {
return getURLBase() + "/get-result-directory";
}

public static final String getUploadResultZipEndpoint() {
return getURLBase() + "/upload-result";
}

public static final String getStorePipelineResultsEndpoint() {
return getURLBase() + "/save-results";
}

public static final String getProjectsPageSizeEndpoint() {
return getURLBase() + "/projects-page-size";
}

public static final String getResultsPageSizeEndpoint() {
return getURLBase() + "/results-page-size";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ public boolean start() throws Exception {
EnvVars overrides = run.getEnvironment(taskListener);
HashMap<String, String> overridesMap = new HashMap<String, String>();
overridesMap.put(Constants.JENKINS_BUILD_TAG, overrides.get(Constants.JENKINS_BUILD_TAG));

if ( overrides.containsKey(BrowserStackEnvVars.QEI_URL) ) {
overridesMap.put(BrowserStackEnvVars.QEI_URL, overrides.get(BrowserStackEnvVars.QEI_URL));
}
if ( parentContextEnvVars.containsKey(BrowserStackEnvVars.GRR_JENKINS_KEY) ) {
overridesMap.put(BrowserStackEnvVars.GRR_JENKINS_KEY, parentContextEnvVars.get(BrowserStackEnvVars.GRR_JENKINS_KEY));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void logToQD(BrowserStackCredentials browserStackCredentials, String logM
ObjectMapper objectMapper = new ObjectMapper();
String jsonBody = objectMapper.writeValueAsString(logMessageObj);
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonBody);
makePostRequestToQd(Constants.QualityDashboardAPI.LOG_MESSAGE, browserStackCredentials, requestBody);
makePostRequestToQd(Constants.QualityDashboardAPI.getLogMessageEndpoint(), browserStackCredentials, requestBody);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ private static void checkQDIntegrationAndDumpMetaData(BrowserStackCredentials br

private static boolean initialQDSetupRequired(BrowserStackCredentials browserStackCredentials) throws JsonProcessingException {
try {
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.IS_INIT_SETUP_REQUIRED, browserStackCredentials);
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.getIsInitSetupRequiredEndpoint(), browserStackCredentials);
if (response != null && response.code() == HttpURLConnection.HTTP_OK) {
ResponseBody responseBody = response.body();
if(responseBody != null && responseBody.string().equals("REQUIRED")) {
Expand All @@ -105,19 +105,54 @@ private static boolean initialQDSetupRequired(BrowserStackCredentials browserSta
return false;
}

private static List<String> getAllPipelines(BrowserStackCredentials browserStackCredentials) throws JsonProcessingException {
private static List<String> getAllPipelines(BrowserStackCredentials browserStackCredentials) {
List<String> allPipelines = new ArrayList<>();
Jenkins jenkins = Jenkins.getInstanceOrNull();
Integer totalPipelines = 0;

if (jenkins != null) {
totalPipelines = jenkins.getAllItems().size();
jenkins.getAllItems().forEach(job -> {
if(job instanceof WorkflowJob) {
String pipelineName = job.getFullName();
try {
// Logging job details
apiUtil.logToQD(
browserStackCredentials,
String.format(
"Job name: %s, instance type: %s, and is_workflow_job: %s",
job.getName(),
job.getClass().getSimpleName(),
(job instanceof WorkflowJob) ? "yes" : "no"
)
);
} catch (JsonProcessingException e) {
// Handling the exception and logging an error
System.err.println("Error processing JSON for job: " + job.getName());
e.printStackTrace();
}

if (job instanceof WorkflowJob) {
String pipelineName = job.getFullName(); // Getting pipeline name
allPipelines.add(pipelineName);
}
});
} else {
apiUtil.logToQD(browserStackCredentials,"Issue getting Jenkins Instance");
try {
apiUtil.logToQD(browserStackCredentials, "Issue getting Jenkins Instance");
} catch (JsonProcessingException e) {
System.err.println("Error logging issue with Jenkins instance.");
e.printStackTrace();
}
}

try {
apiUtil.logToQD(browserStackCredentials,"Total Pipelines on the jenkins side : " + totalPipelines);
apiUtil.logToQD(browserStackCredentials,"Total Pipelines detected : " + allPipelines.size());
} catch (JsonProcessingException e) {
// Handling the exception and logging an error
System.err.println("Error processing JSON for total pipelines: ");
e.printStackTrace();
}
// Returning the list of filtered pipelines
return allPipelines;
}

Expand All @@ -134,7 +169,8 @@ private static boolean sendPipelinesPaginated(BrowserStackCredentials browserSta
PipelinesPaginated pipelinesPaginated = new PipelinesPaginated(page, totalPages, singlePagePipelineList);
String jsonBody = objectMapper.writeValueAsString(pipelinesPaginated);
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonBody);
Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.SAVE_PIPELINES, browserStackCredentials, requestBody);
Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.getSavePipelinesEndpoint(), browserStackCredentials, requestBody);
apiUtil.logToQD(browserStackCredentials, "Sending page " + page + " with " + singlePagePipelineList.size() + " pipelines");
if (response == null || response.code() != HttpURLConnection.HTTP_OK) {
apiUtil.logToQD(browserStackCredentials,"Got Non 200 response while saving projects");
isSuccess = false;
Expand Down Expand Up @@ -188,7 +224,7 @@ private static void sendBuildsPaginated(BrowserStackCredentials browserStackCred
BuildResultsPaginated buildResultsPaginated = new BuildResultsPaginated(page, totalPages, buildResultList);
String jsonBody = objectMapper.writeValueAsString(buildResultsPaginated);
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json"), jsonBody);
Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.SAVE_PIPELINE_RESULTS, browserStackCredentials, requestBody);
Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.getSavePipelineResultsEndpoint(), browserStackCredentials, requestBody);
if (response == null || response.code() != HttpURLConnection.HTTP_OK) {
apiUtil.logToQD(browserStackCredentials,"Got Non 200 response while saving projects");
break;
Expand All @@ -202,7 +238,7 @@ private static void sendBuildsPaginated(BrowserStackCredentials browserStackCred
private static int getHistoryForDays(BrowserStackCredentials browserStackCredentials) {
int no_of_days = 90;
try {
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.HISTORY_FOR_DAYS, browserStackCredentials);
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.getHistoryForDaysEndpoint(), browserStackCredentials);
if (response != null && response.code() == HttpURLConnection.HTTP_OK) {
ResponseBody responseBody = response.body();
if(responseBody != null) {
Expand All @@ -221,7 +257,7 @@ private static int getHistoryForDays(BrowserStackCredentials browserStackCredent
private static int getProjectPageSize(BrowserStackCredentials browserStackCredentials) {
int projectPageSize = 2000;
try {
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.PROJECTS_PAGE_SIZE, browserStackCredentials);
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.getProjectsPageSizeEndpoint(), browserStackCredentials);
if (response != null && response.code() == HttpURLConnection.HTTP_OK) {
ResponseBody responseBody = response.body();
if(responseBody != null) {
Expand All @@ -240,7 +276,7 @@ private static int getProjectPageSize(BrowserStackCredentials browserStackCreden
private static int getResultPageSize(BrowserStackCredentials browserStackCredentials) {
int resultPageSize = 1000;
try {
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.RESULTS_PAGE_SIZE, browserStackCredentials);
Response response = apiUtil.makeGetRequestToQd(Constants.QualityDashboardAPI.getResultsPageSizeEndpoint(), browserStackCredentials);
if (response != null && response.code() == HttpURLConnection.HTTP_OK) {
ResponseBody responseBody = response.body();
if(responseBody != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,27 @@ public class QualityDashboardInitItemListener extends ItemListener {

@Override
public void onCreated(Item job) {
String itemName = job.getFullName();
String itemType = getItemTypeModified(job);
if(itemType != null && itemType.equals("PIPELINE")) {
try {
String jsonBody = getJsonReqBody(new ItemUpdate(itemName, itemType));
syncItemListToQD(jsonBody, Constants.QualityDashboardAPI.ITEM_CRUD, "POST");
} catch(IOException e) {
e.printStackTrace();
try {
BrowserStackCredentials browserStackCredentials = QualityDashboardUtil.getBrowserStackCreds();
QualityDashboardAPIUtil apiUtil = new QualityDashboardAPIUtil();
apiUtil.logToQD(browserStackCredentials, "Item Created : " + job.getClass().getName()) ;

String itemName = job.getFullName();
String itemType = getItemTypeModified(job);

apiUtil.logToQD(browserStackCredentials, "Item Type : " + itemType + " : " + itemName + " : " + itemType.equals("PIPELINE"));
if(itemType != null && itemType.equals("PIPELINE")) {
try {
apiUtil.logToQD(browserStackCredentials, "Item Type inside the Folder : " + itemType + " : " + itemName + " : " + itemType.equals("PIPELINE"));
String jsonBody = getJsonReqBody(new ItemUpdate(itemName, itemType));
syncItemListToQD(jsonBody, Constants.QualityDashboardAPI.getItemCrudEndpoint(), "POST");

} catch(IOException e) {
e.printStackTrace();
}
}
} catch(Exception e) {
e.printStackTrace();
}
}

Expand All @@ -39,7 +51,7 @@ public void onDeleted(Item job) {
if(itemType != null) {
try {
String jsonBody = getJsonReqBody(new ItemUpdate(itemName, itemType));
syncItemListToQD(jsonBody, Constants.QualityDashboardAPI.ITEM_CRUD, "DELETE");
syncItemListToQD(jsonBody, Constants.QualityDashboardAPI.getItemCrudEndpoint(), "DELETE");
} catch(IOException e) {
e.printStackTrace();
}
Expand All @@ -54,7 +66,7 @@ public void onRenamed(Item job, String oldName, String newName) {
oldName = job.getParent().getFullName() + "/" + oldName;
newName = job.getParent().getFullName() + "/" + newName;
String jsonBody = getJsonReqBody(new ItemRename(oldName, newName, itemType));
syncItemListToQD(jsonBody, Constants.QualityDashboardAPI.ITEM_CRUD, "PUT");
syncItemListToQD(jsonBody, Constants.QualityDashboardAPI.getItemCrudEndpoint(), "PUT");
} catch(IOException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ private void sendBuildDataToQD(Run run, Result overallResult, String finalZipPat

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

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

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

Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.UPLOAD_RESULT_ZIP, browserStackCredentials, requestBody);
Response response = apiUtil.makePostRequestToQd(Constants.QualityDashboardAPI.getUploadResultZipEndpoint(), browserStackCredentials, requestBody);
if (response != null && response.code() == HttpURLConnection.HTTP_OK) {
qdS3Url = response.body() !=null ? response.body().string() : null;
}
Expand Down