Skip to content
Permalink
Browse files
IGNITE-11880: Configurable tags by build parameters/suite IDS & names (
  • Loading branch information
dspavlov committed May 30, 2019
1 parent 55ea567 commit ce0fbcf28d9b5ef33192d8c2baf2fb1aabbca652
Showing 9 changed files with 90 additions and 45 deletions.
@@ -49,6 +49,12 @@ public interface ITeamcity extends ITeamcityConn {
/** Default list of properties to be skipped in saving in FAT builds. */
public Set<String> AVOID_SAVE_PROPERTIES = Sets.newHashSet(TCBOT_TRIGGER_TIME, "build.query.loginTs");

/** Fake property for addressing 'Suite id'. */
public String SUITE_ID_PROPERTY = "_suiteId";

/** Fake property for addressing 'Suite Name'. */
public String SUITE_NAME_PROPERTY = "_suiteName";

CompletableFuture<File> unzipFirstFile(CompletableFuture<File> fut);

CompletableFuture<File> downloadBuildLogZip(int id);
@@ -29,11 +29,12 @@
import java.util.Set;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Future;
import java.util.regex.Pattern;
import java.util.stream.Stream;
import javax.annotation.Nonnull;
import org.apache.ignite.ci.ITeamcity;
import org.apache.ignite.ci.tcbot.conf.BuildParameterSpec;
import org.apache.ignite.ci.tcbot.conf.ITcServerConfig;
import org.apache.ignite.ci.tcbot.conf.ParameterValueSpec;
import org.apache.ignite.ci.tcmodel.result.tests.TestOccurrenceFull;
import org.apache.ignite.ci.teamcity.ignited.IStringCompactor;
import org.apache.ignite.ci.teamcity.ignited.buildtype.ParametersCompacted;
@@ -261,8 +262,11 @@ public long testsDuration() {
}).sum();
}

public void addTag(String label) {
this.tags.add(label);
public void addTag(@Nullable String lb) {
if(Strings.isNullOrEmpty(lb))
return;

this.tags.add(lb);
}

public Set<String> tags() {
@@ -275,16 +279,47 @@ public void addTagsFromParameters(ParametersCompacted parameters, ITcServerConfi
if (!parm.isFilled())
continue;

String propVal = parameters.getProperty(compactor, parm.name());
String propVal = getPropertyOrSpecialValue(parameters, compactor, parm.name());

if (Strings.isNullOrEmpty(propVal))
continue;

parm.selection().stream()
.filter(v -> Objects.equals(v.value(), propVal))
.filter(pvs -> {
String valRegExp = pvs.valueRegExp();

if(!Strings.isNullOrEmpty(valRegExp))
return Pattern.compile(valRegExp).matcher(propVal).find();

String exactVal = pvs.value();

if(!Strings.isNullOrEmpty(exactVal))
return Objects.equals(exactVal, propVal);

return false;
})
.findAny()
.ifPresent(v -> addTag(v.label()));

}
}

/**
* @param parameters Parameters from build.
* @param compactor Compactor.
* @param parmKey Parmeters key.
*/
public String getPropertyOrSpecialValue(ParametersCompacted parameters, IStringCompactor compactor,
String parmKey) {

String propVal;
if (ITeamcity.SUITE_ID_PROPERTY.equals(parmKey))
propVal = suiteId();
else if (ITeamcity.SUITE_NAME_PROPERTY.equals(parmKey))
propVal = suiteName();
else
propVal = parameters.getProperty(compactor, parmKey);

return propVal;
}
}
@@ -45,12 +45,9 @@ public interface ITcServerConfig {
@NotNull public String defaultTrackedBranch();

/**
* @return set of build parameters codes, which could be used for filtering builds in RunHist/Invocations.
*/
@NotNull public Collection<String> filteringParametersKeys();

/**
* @return set of build parameters, which could be used for filtering builds in RunHist/Invocations.
* Provides build parameters, whichi could be used for filtering builds in RunHist/Invocations and tagging in UI.
*
* @return set of build parameters specifications.
*/
@NotNull public Collection<BuildParameterSpec> filteringParameters();

@@ -24,7 +24,7 @@
*
*/
public class NotificationChannel implements INotificationChannel {
/** Email. */
/** (Destionation) Email. */
private String email;

/** Slack. */
@@ -34,7 +34,7 @@
* Notifications Config
*/
public class NotificationsConfig {
/** Email. */
/** (Source) Email. */
private EmailSettings email = new EmailSettings();

/** Slack auth token. Not encoded using Password encoder */
@@ -17,34 +17,51 @@

package org.apache.ignite.ci.tcbot.conf;

import com.google.common.base.Objects;
import java.util.Objects;

/**
* Some parameter value, which label may be used in UI.
*/
public class ParameterValueSpec {
private String value;
private String label;
private String valueRegExp;

/**
* Exact value, which can be present in a build.
*/
public String value() {
return value;
}

/**
* @return label/tag to be associated with build or shown in selection.
*/
public String label() {
return label;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
ParameterValueSpec that = (ParameterValueSpec) o;
return Objects.equal(value, that.value) &&
Objects.equal(label, that.label);
/** {@inheritDoc} */
@Override public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || getClass() != o.getClass())
return false;
ParameterValueSpec spec = (ParameterValueSpec)o;
return Objects.equals(value, spec.value) &&
Objects.equals(label, spec.label) &&
Objects.equals(valueRegExp, spec.valueRegExp);
}

@Override
public int hashCode() {
return Objects.hashCode(value, label);
/** {@inheritDoc} */
@Override public int hashCode() {
return Objects.hash(value, label, valueRegExp);
}

/**
*
*/
public String valueRegExp() {
return this.valueRegExp;
}
}
@@ -22,7 +22,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Properties;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;
import org.apache.ignite.ci.HelperConfig;
import org.jetbrains.annotations.NotNull;
@@ -114,14 +113,6 @@ private String hostConfigured() {
return DEFAULT_TRACKED_BRANCH_NAME;
}

/** {@inheritDoc} */
@Override public Collection<String> filteringParametersKeys() {
if (filteringParameters == null || filteringParameters.isEmpty())
return Collections.emptySet();

return filteringParameters.stream().map(BuildParameterSpec::name).collect(Collectors.toSet());
}

/** {@inheritDoc} */
@NotNull @Override public Collection<BuildParameterSpec> filteringParameters() {
if (filteringParameters == null || filteringParameters.isEmpty())
@@ -18,7 +18,6 @@
package org.apache.ignite.ci.teamcity.ignited.runhist;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -38,9 +37,9 @@
import org.apache.ignite.ci.di.MonitoredTask;
import org.apache.ignite.ci.di.scheduler.IScheduler;
import org.apache.ignite.ci.tcbot.TcBotSystemProperties;
import org.apache.ignite.ci.tcbot.conf.BuildParameterSpec;
import org.apache.ignite.ci.tcbot.conf.ChainAtServerTracked;
import org.apache.ignite.ci.tcbot.conf.ITcBotConfig;
import org.apache.ignite.ci.tcbot.conf.ITcServerConfig;
import org.apache.ignite.ci.teamcity.ignited.IStringCompactor;
import org.apache.ignite.ci.teamcity.ignited.ITeamcityIgnited;
import org.apache.ignite.ci.teamcity.ignited.buildref.BuildRefDao;
@@ -109,9 +108,9 @@ public void saveToHistoryLater(String srvCode, FatBuildCompacted build) {
if (histDao.buildWasProcessed(srvId, build.id()))
return;

Set<Integer> allTriggeringBuildParameters = getFilteringParameters(srvCode);
Set<Integer> allImportantBuildParameters = getFilteringParameters(srvCode);

BiPredicate<Integer, Integer> parmFilter = (k, v) -> allTriggeringBuildParameters.contains(k);
BiPredicate<Integer, Integer> parmFilter = (k, v) -> allImportantBuildParameters.contains(k);
boolean saveNow = false;

int branchNameNormalized = compactor.getStringId(normalizeBranch(build.branchName(compactor)));
@@ -156,20 +155,20 @@ public void saveToHistoryLater(String srvCode, FatBuildCompacted build) {
}

@NotNull public Set<Integer> getFilteringParameters(String srvCode) {
Set<String> triggerParameters = cfg.getTrackedBranches().getBranches().stream().flatMap(
Set<String> importantParameters = cfg.getTrackedBranches().getBranches().stream().flatMap(
b -> b.getChainsStream()
.filter(ChainAtServerTracked::isTriggerBuild)
.filter(chain -> Objects.equals(chain.getServerId(), srvCode))
.flatMap(ChainAtServerTracked::buildParametersKeys)
).collect(Collectors.toSet());

ITcServerConfig tcCfg = cfg.getTeamcityConfig(srvCode);
cfg.getTeamcityConfig(srvCode)
.filteringParameters()
.stream()
.map(BuildParameterSpec::name)
.forEach(importantParameters::add);

Collection<String> filtering = tcCfg.filteringParametersKeys();

triggerParameters.addAll(filtering);

return triggerParameters.stream().map(k -> compactor.getStringId(k)).collect(Collectors.toSet());
return importantParameters.stream().map(k -> compactor.getStringId(k)).collect(Collectors.toSet());
}

@MonitoredTask(name = "Save Builds To History(srv, runner)", nameExtArgsIndexes = {0, 1})
@@ -28,7 +28,7 @@
public static final String GITHUB_REF = "https://github.com/apache/ignite-teamcity-bot";

/** TC Bot Version. */
public static final String VERSION = "20190529";
public static final String VERSION = "20190530";

/** Java version, where Web App is running. */
public String javaVer;

0 comments on commit ce0fbcf

Please sign in to comment.