Skip to content

Commit

Permalink
Merge pull request #6 from takipi/feature/INTG-199
Browse files Browse the repository at this point in the history
[INTG-199] Bamboo - CI/CD UX Redesign
  • Loading branch information
daverted authored Apr 24, 2020
2 parents 110f381 + aee94c8 commit ba40d2b
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 306 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@
<version>${takipi.version}</version>
</dependency>

<dependency>
<groupId>com.takipi</groupId>
<artifactId>report-service</artifactId>
<version>${takipi.version}</version>
</dependency>


<!-- WIRED TEST RUNNER DEPENDENCIES -->
<dependency>
<groupId>com.atlassian.plugins</groupId>
Expand Down
81 changes: 61 additions & 20 deletions src/main/java/com/overops/plugins/bamboo/TaskType.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package com.overops.plugins.bamboo;

import java.io.PrintWriter;
import java.io.PrintStream;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;


import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.math.NumberUtils;
import com.atlassian.bamboo.build.logger.BuildLogger;
import com.atlassian.bamboo.configuration.ConfigurationMap;
import com.atlassian.bamboo.process.ProcessService;
import com.atlassian.bamboo.task.TaskContext;
import com.atlassian.bamboo.task.TaskException;
Expand All @@ -16,14 +21,17 @@
import com.atlassian.sal.api.pluginsettings.PluginSettings;
import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory;
import com.overops.plugins.bamboo.configuration.Const;
import com.overops.plugins.bamboo.model.OverOpsReportModel;
import com.overops.plugins.bamboo.model.QueryOverOps;
import com.overops.plugins.bamboo.service.OverOpsService;
import com.overops.plugins.bamboo.service.impl.OverOpsServiceImpl;
import com.overops.plugins.bamboo.service.impl.ReportBuilder;
import com.overops.plugins.bamboo.utils.ReportUtils;

import com.fasterxml.jackson.databind.ObjectMapper;

import com.overops.plugins.bamboo.configuration.Const;
import com.overops.plugins.bamboo.service.impl.BambooPrintWriter;
import com.overops.report.service.QualityReportParams;
import com.overops.report.service.ReportService;
import com.overops.report.service.ReportService.Requestor;
import com.overops.report.service.model.QualityReport;
import com.overops.report.service.model.QualityReport.ReportStatus;

import org.jetbrains.annotations.NotNull;

@Scanned
Expand All @@ -32,11 +40,11 @@ public class TaskType implements com.atlassian.bamboo.task.TaskType {
@ComponentImport
private PluginSettingsFactory pluginSettingsFactory;

private OverOpsService overOpsService;
private ReportService overOpsService;
private ObjectMapper objectMapper;

public TaskType(PluginSettingsFactory pluginSettingsFactory) {
this.overOpsService = new OverOpsServiceImpl();
this.overOpsService = new ReportService();
this.objectMapper = new ObjectMapper();
this.pluginSettingsFactory = pluginSettingsFactory;
}
Expand All @@ -49,28 +57,31 @@ public TaskResult execute(@NotNull TaskContext context) throws TaskException {

logger.addBuildLogEntry("Generating OverOps Quality Report");

// get global plugin settings
PluginSettings pluginSettings = pluginSettingsFactory.createGlobalSettings();
PluginSettings globalSettings = pluginSettingsFactory.createGlobalSettings();

Map<String, String> globalSettings = new HashMap<>(3);
globalSettings.put(Const.GLOBAL_API_URL, (String) pluginSettings.get(Const.GLOBAL_API_URL));
globalSettings.put(Const.GLOBAL_API_TOKEN, (String) pluginSettings.get(Const.GLOBAL_API_TOKEN));
globalSettings.put(Const.GLOBAL_ENV_ID, (String) pluginSettings.get(Const.GLOBAL_ENV_ID));

QueryOverOps query = QueryOverOps.mapToObject(context.getConfigurationMap(), globalSettings);
String endPoint = (String)globalSettings.get(Const.GLOBAL_API_URL);
String apiKey = (String)globalSettings.get(Const.GLOBAL_API_TOKEN);

QualityReportParams query = getQualityReportParams(context.getConfigurationMap());
String envId = query.getServiceId();
if (StringUtils.isBlank(envId)) {
query.setServiceId((String)globalSettings.get(Const.GLOBAL_ENV_ID));
}

TaskResultBuilder resultBuilder = TaskResultBuilder.newBuilder(context);

try {
logger.addBuildLogEntry("[" + Utils.getArtifactId() + " v" + Utils.getVersion() + "]");

ReportBuilder.QualityReport report = overOpsService.perform(query, logger);
OverOpsReportModel overOpsReport = ReportUtils.copyResult(report);
boolean isDebug = Boolean.parseBoolean(context.getConfigurationMap().get(Const.DEBUG));
PrintStream printStream = isDebug ? new BambooPrintWriter(System.out, logger) : null;

context.getBuildContext().getBuildResult().getCustomBuildData().put("overOpsReport", objectMapper.writeValueAsString(overOpsReport));
QualityReport reportModel = overOpsService.runQualityReport(endPoint, apiKey, query, Requestor.BAMBOO, printStream, isDebug);

context.getBuildContext().getBuildResult().getCustomBuildData().put("overOpsReport", objectMapper.writeValueAsString(reportModel.getHtmlParts()));
context.getBuildContext().getBuildResult().getCustomBuildData().put("isOverOpsStep", "true");

if (overOpsReport.isMarkedUnstable() && overOpsReport.isUnstable()) {
if (reportModel.getStatusCode() == ReportStatus.FAILED) {
return resultBuilder.failed().build();
} else {
return resultBuilder.success().build();
Expand All @@ -89,4 +100,34 @@ public TaskResult execute(@NotNull TaskContext context) throws TaskException {
}
}

private QualityReportParams getQualityReportParams(ConfigurationMap params) {
QualityReportParams qrp = new QualityReportParams();

qrp.setServiceId((String)params.get(Const.ENV_ID));
qrp.setApplicationName(params.get(Const.APP_NAME));
qrp.setDeploymentName(params.get(Const.DEP_NAME));

qrp.setRegexFilter(params.get(Const.REGEX_FILTER));
qrp.setMarkUnstable(Boolean.parseBoolean(params.get(Const.MARK_UNSTABLE)));
qrp.setPrintTopIssues(NumberUtils.toInt(params.get(Const.TOP_ERROR_COUNT), 0));

qrp.setNewEvents(Boolean.parseBoolean(params.get(Const.CHECK_NEW_ERRORS)));
qrp.setResurfacedErrors(Boolean.parseBoolean(params.get(Const.CHECK_RESURFACED_ERRORS)));

qrp.setMaxErrorVolume(NumberUtils.toInt(params.get(Const.MAX_ERROR_VOLUME), 0));
qrp.setMaxUniqueErrors(NumberUtils.toInt(params.get(Const.MAX_UNIQUE_ERRORS), 0));

qrp.setCriticalExceptionTypes(params.getOrDefault(Const.CRITICAL_EXCEPTION_TYPES, ""));

qrp.setActiveTimespan(params.get(Const.ACTIVE_TIMESPAN));
qrp.setBaselineTimespan(params.get(Const.BASELINE_TIMESPAN));
qrp.setMinVolumeThreshold(NumberUtils.toInt(params.get(Const.MIN_VOLUME_THRESHOLD), 0));
qrp.setMinErrorRateThreshold(NumberUtils.toDouble(params.get(Const.MIN_RATE_THRESHOLD), 0));
qrp.setRegressionDelta(NumberUtils.toDouble(params.get(Const.REGRESSION_DELTA), 0));
qrp.setCriticalRegressionDelta(NumberUtils.toDouble(params.get(Const.CRITICAL_REGRESSION_THRESHOLD), 0));
qrp.setApplySeasonality(Boolean.parseBoolean(params.get(Const.APPLY_SEASONALITY)));

qrp.setDebug(Boolean.parseBoolean(params.get(Const.DEBUG)));
return qrp;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,10 @@ public void validate(ActionParametersMap params, ErrorCollection errorCollection
errorCollection.addError(Const.ENV_ID, "Invalid environment ID");
}

if ((params.getString(Const.APP_NAME).trim().length() == 0) && (params.getString(Const.DEP_NAME).trim().length() == 0)) {
errorCollection.addError(Const.APP_NAME, "Must provide an Application Name, or a Deployment Name, or both.");
}

// validate total errors
validNumber(Const.TOP_ERROR_COUNT);
validNumber(Const.MAX_ERROR_VOLUME, Const.CHECK_VOLUME_ERRORS);
Expand Down
38 changes: 0 additions & 38 deletions src/main/java/com/overops/plugins/bamboo/model/QueryOverOps.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,44 +202,6 @@ public void setDebug(boolean debug) {
this.debug = debug;
}

public static QueryOverOps mapToObject(ConfigurationMap params, Map<String, String> globalSettings) {

QueryOverOps queryOverOps = new QueryOverOps();

// api info always comes from global settings page
queryOverOps.apiUrl = globalSettings.get(GLOBAL_API_URL);
queryOverOps.apiToken = globalSettings.get(GLOBAL_API_TOKEN);

// use default env ID from global settings page if missing in the task settings
queryOverOps.envId = (StringUtils.isBlank(params.get(ENV_ID)) ? globalSettings.get(GLOBAL_ENV_ID) : params.get(ENV_ID));

queryOverOps.applicationName = params.get(APP_NAME);
queryOverOps.deploymentName = params.get(DEP_NAME);

queryOverOps.regexFilter = params.get(REGEX_FILTER);
queryOverOps.markUnstable = Boolean.parseBoolean(params.get(MARK_UNSTABLE));
queryOverOps.topErrorCount = NumberUtils.toInt(params.get(TOP_ERROR_COUNT), 0);

queryOverOps.newEvents = Boolean.parseBoolean(params.get(CHECK_NEW_ERRORS));
queryOverOps.resurfacedErrors = Boolean.parseBoolean(params.get(CHECK_RESURFACED_ERRORS));

queryOverOps.maxErrorVolume = NumberUtils.toInt(params.get(MAX_ERROR_VOLUME), 0);
queryOverOps.maxUniqueErrors = NumberUtils.toInt(params.get(MAX_UNIQUE_ERRORS), 0);

queryOverOps.criticalExceptionTypes = params.getOrDefault(CRITICAL_EXCEPTION_TYPES, "");

queryOverOps.activeTimespan = params.get(ACTIVE_TIMESPAN);
queryOverOps.baselineTimespan = params.get(BASELINE_TIMESPAN);
queryOverOps.minVolumeThreshold = NumberUtils.toInt(params.get(MIN_VOLUME_THRESHOLD), 0);
queryOverOps.minRateThreshold = NumberUtils.toDouble(params.get(MIN_RATE_THRESHOLD), 0);
queryOverOps.regressionDelta = NumberUtils.toDouble(params.get(REGRESSION_DELTA), 0);
queryOverOps.criticalRegressionThreshold = NumberUtils.toDouble(params.get(CRITICAL_REGRESSION_THRESHOLD), 0);
queryOverOps.applySeasonality = Boolean.parseBoolean(params.get(APPLY_SEASONALITY));

queryOverOps.debug = Boolean.parseBoolean(params.get(DEBUG));
return queryOverOps;
}

@Override
public String toString() {
return "QueryOverOps{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.atlassian.bamboo.resultsummary.BuildResultsSummary;
import com.atlassian.bamboo.resultsummary.BuildResultsSummaryImpl;
import com.atlassian.bamboo.resultsummary.ResultsSummary;
import com.overops.plugins.bamboo.model.OverOpsReportModel;
import com.overops.report.service.model.HtmlParts;
import com.overops.plugins.bamboo.utils.Util;
import org.apache.log4j.Logger;

Expand All @@ -21,7 +21,7 @@ public class ViewOverOpsReport extends PlanResultsAction {
private static final long serialVersionUID = 1L;
private static final Logger log = Logger.getLogger(ViewOverOpsReport.class);

private OverOpsReportModel report;
private HtmlParts report;

public String execute() throws Exception {
String result = super.execute();
Expand All @@ -37,7 +37,7 @@ public String execute() throws Exception {
for (String key : customBuildData.keySet()) {
if (key.startsWith("overOpsReport")) {
log.debug("Found report link for master =" + key);
report = Util.stringToObject(customBuildData.get(key), OverOpsReportModel.class);
report = Util.stringToObject(customBuildData.get(key), HtmlParts.class);
}
}
}
Expand All @@ -49,19 +49,19 @@ public String execute() throws Exception {
for (String key : customBuildData.keySet()) {
if (key.startsWith("overOpsReport")) {
log.debug("Found report link for master =" + key);
report = Util.stringToObject(customBuildData.get(key), OverOpsReportModel.class);
report = Util.stringToObject(customBuildData.get(key), HtmlParts.class);
}
}
}

return result;
}

public OverOpsReportModel getReport() {
public HtmlParts getReport() {
return report;
}

public void setReport(OverOpsReportModel report) {
public void setReport(HtmlParts report) {
this.report = report;
}
}
4 changes: 2 additions & 2 deletions src/main/resources/templates/editTaskConfig.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@

<h3>General settings</h3>
[@ww.textfield labelKey="com.overops.plugins.bamboo.task.config.envId" name="envId" required="false" description="The OverOps environment identifier (e.g S12345). If blank, the <a href=\"/plugins/servlet/overops/admin\">default value</a> is used."/]
[@ww.textfield labelKey="com.overops.plugins.bamboo.task.config.applicationName" name="applicationName" required="false" description="<em>(Optional)</em> Application Name as specified in OverOps."/]
[@ww.textfield labelKey="com.overops.plugins.bamboo.task.config.deploymentName" name="deploymentName" required="false" description="<em>(Optional)</em> Deployment Name as specified in OverOps. See: <a href='https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html' target='_blank' rel='nofollow'>Bamboo variables</a>"/]
[@ww.textfield labelKey="com.overops.plugins.bamboo.task.config.applicationName" name="applicationName" required="false" description="<em>(Optional)</em> Application Name as specified in OverOps. If blank, a Deplyment Name must be provided."/]
[@ww.textfield labelKey="com.overops.plugins.bamboo.task.config.deploymentName" name="deploymentName" required="false" description="<em>(Optional)</em> Deployment Name as specified in OverOps. If blank, an Application Name must be provided. See: <a href='https://confluence.atlassian.com/bamboo/bamboo-variables-289277087.html' target='_blank' rel='nofollow'>Bamboo variables</a>"/]
<hr class="divider"/>
[@ww.textfield labelKey="com.overops.plugins.bamboo.task.config.regexFilter" name="regexFilter" required="false" description="<em>(Optional)</em> Ignore specific event types when generating the OverOps Reliability report. Event types include: <em>Uncaught Exception, Caught Exception, Swallowed Exception, Logged Error, Logged Warning, Timer</em>. For example: <code class='inline'>\"type\":\"s*(Logged Error|Logged Warning|Timer)\"</code>" /]
<hr class="divider"/>
Expand Down
Loading

0 comments on commit ba40d2b

Please sign in to comment.