Skip to content
Permalink
Browse files
TC config refactoring: removal of unused values
  • Loading branch information
dspavlov committed Apr 12, 2019
1 parent 0b3bbee commit 67dcd11f2aed46c93c4eefb338c63eb65db52606
Showing 8 changed files with 42 additions and 84 deletions.
@@ -42,7 +42,6 @@
* https://confluence.jetbrains.com/display/TCD10/REST+API
*/
public interface ITeamcity extends ITeamcityConn {

public String DEFAULT = "<default>";
public String REFS_HEADS_MASTER = "refs/heads/master";

@@ -63,7 +63,6 @@
import java.io.*;
import java.util.SortedSet;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Supplier;
@@ -89,12 +88,6 @@ public class IgniteTeamcityConnection implements ITeamcity {
/** Executor. */
private Executor executor;

/** Logs directory. */
private File logsDir;

/** Normalized Host address, ends with '/'. */
private String host;

/** TeamCity authorization token. */
private String basicAuthTok;

@@ -103,7 +96,7 @@ public class IgniteTeamcityConnection implements ITeamcity {

@Inject private ITcBotConfig config;

private String tcName;
private String srvCode;

/** Build logger processing running. */
private ConcurrentHashMap<Integer, CompletableFuture<LogCheckTask>> buildLogProcessingRunning = new ConcurrentHashMap<>();
@@ -113,35 +106,16 @@ public Executor getExecutor() {
}

/** {@inheritDoc} */
@Override public void init(@Nullable String tcName) {
this.tcName = tcName;

ITcServerConfig tcCfg = this.config.getTeamcityConfig(tcName);
final Properties props = tcCfg.properties();

this.host = tcCfg.host();

if (props != null) {
try {
if (!Strings.isNullOrEmpty(props.getProperty(HelperConfig.USERNAME))
&& props.getProperty(HelperConfig.ENCODED_PASSWORD) != null)
setAuthToken(HelperConfig.prepareBasicHttpAuthToken(props, "TC Config"));
}
catch (Exception e) {
e.printStackTrace();
logger.error("Failed to set credentials", e);
}
}

final File logsDirFile = HelperConfig.resolveLogs(
HelperConfig.resolveWorkDir(),
tcCfg.logsDirectory());

logsDir = ensureDirExist(logsDirFile);
@Override public void init(@Nullable String srvCode) {
this.srvCode = srvCode;

this.executor = MoreExecutors.directExecutor();
}

public ITcServerConfig config() {
return this.config.getTeamcityConfig(this.srvCode );
}

/** {@inheritDoc} */
@Override public void setAuthToken(String tok) {
basicAuthTok = tok;
@@ -170,7 +144,7 @@ public CompletableFuture<File> downloadBuildLogZip(int buildId) {
boolean archive = true;
Supplier<File> supplier = () -> {
String buildIdStr = Integer.toString(buildId);
final File buildDir = ensureDirExist(new File(logsDir, "buildId" + buildIdStr));
final File buildDir = ensureDirExist(new File(logsDir(), "buildId" + buildIdStr));
final File file = new File(buildDir,
"build.log" + (archive ? ".zip" : ""));
if (file.exists() && file.canRead() && file.length() > 0) {
@@ -192,6 +166,14 @@ public CompletableFuture<File> downloadBuildLogZip(int buildId) {
return supplyAsync(supplier, executor);
}

private File logsDir() {
File logsDirFile = HelperConfig.resolveLogs(
HelperConfig.resolveWorkDir(),
config().logsDirectory());

return ensureDirExist(logsDirFile);
}

@AutoProfiling
@Override public CompletableFuture<LogCheckResult> analyzeBuildLog(Integer buildId, SingleBuildRunCtx ctx) {
final Stopwatch started = Stopwatch.createStarted();
@@ -313,7 +295,7 @@ public CompletableFuture<File> unzipFirstFile(CompletableFuture<File> fut) {
* @return Normalized Host address, ends with '/'.
*/
@Override public String host() {
return host;
return config().host();
}

/** {@inheritDoc} */
@@ -372,7 +354,7 @@ private <T> T getJaxbUsingHref(String href, Class<T> elem) {

/** {@inheritDoc} */
@Override public String serverId() {
return tcName;
return srvCode;
}

private CompletableFuture<LogCheckTask> checkBuildLogNoCache(int buildId, ISuiteResults ctx) {
@@ -24,14 +24,14 @@
* Teamcity Server configuration.
*/
public interface ITcServerConfig {
@Deprecated
public Properties properties();

/**
* @return Another TC Server (service) config name to use settings from. Filled only for server aliases.
*/
@Nullable public String reference();

/**
* @return Normalized Host address, ends with '/'.
*/
@NotNull public String host();

@NotNull public String logsDirectory();
@@ -61,14 +61,6 @@ public String getCode() {
return code;
}

/** {@inheritDoc} */
@Override public Properties properties() {
if (props == null)
return new Properties();

return props;
}

/** {@inheritDoc} */
@Override public String reference() {
return reference;
@@ -75,14 +75,15 @@ class TcIgnitedCachingProvider implements ITeamcityIgnitedProvider {
ITeamcity tcRealConn = srvFactory.server(realSrvCode, prov);

if (prov != null) {
final String user = prov.getUser(realSrvCode);
final String pwd = prov.getPassword(realSrvCode);
String user = prov.getUser(realSrvCode);
String pwd = prov.getPassword(realSrvCode);

tcRealConn.setAuthData(user, pwd);
}

TeamcityIgnitedImpl impl = provider.get();

impl.init(realSrvCode, tcRealConn);
impl.init(tcRealConn);

return impl;
});
@@ -89,8 +89,8 @@ public class TeamcityIgnitedImpl implements ITeamcityIgnited {
/** Max build id diff to enforce reload during incremental refresh. */
public static final int MAX_ID_DIFF_TO_ENFORCE_CONTINUE_SCAN = 3000;

/** Server id. */
private String srvName;
/** Server (service) code. */
private String srvCode;

/** Pure HTTP Connection API. */
private ITeamcityConn conn;
@@ -146,11 +146,13 @@ public class TeamcityIgnitedImpl implements ITeamcityIgnited {
/** Server ID mask for cache Entries. */
private int srvIdMaskHigh;

public void init(String srvId, ITeamcityConn conn) {
this.srvName = srvId;
public void init(ITeamcityConn conn) {
String srvCode = conn.serverId();

this.srvCode = srvCode;
this.conn = conn;

srvIdMaskHigh = ITeamcityIgnited.serverIdToInt(srvId);
srvIdMaskHigh = ITeamcityIgnited.serverIdToInt(srvCode);
buildRefDao.init(); //todo init somehow in auto
buildConditionDao.init();
fatBuildDao.init();
@@ -165,12 +167,12 @@ public void init(String srvId, ITeamcityConn conn) {
*/
@NotNull
private String taskName(String taskName) {
return ITeamcityIgnited.class.getSimpleName() +"." + taskName + "." + srvName;
return ITeamcityIgnited.class.getSimpleName() +"." + taskName + "." + srvCode;
}

/** {@inheritDoc} */
@Override public String serverId() {
return srvName;
return srvCode;
}

/** {@inheritDoc} */
@@ -456,22 +458,22 @@ public List<String> branchForQuery(@Nullable String branchName) {
* Enables scheduleing for build refs/builds/history sync
*/
public void ensureActualizeRequested() {
scheduler.sheduleNamed(taskName("actualizeRecentBuildRefs"), () -> actualizeRecentBuildRefs(srvName), 2, TimeUnit.MINUTES);
scheduler.sheduleNamed(taskName("actualizeRecentBuildRefs"), () -> actualizeRecentBuildRefs(srvCode), 2, TimeUnit.MINUTES);

buildRefSync.ensureActualizeRequested();

// schedule find missing later
fatBuildSync.ensureActualizationRequested(srvName, conn);
fatBuildSync.ensureActualizationRequested(srvCode, conn);

runHistSync.invokeLaterFindMissingHistory(srvName);
runHistSync.invokeLaterFindMissingHistory(srvCode);
}

/** {@inheritDoc} */
@Override public Build triggerBuild(String buildTypeId, String branchName, boolean cleanRebuild, boolean queueAtTop) {
Build build = conn.triggerBuild(buildTypeId, branchName, cleanRebuild, queueAtTop);

//todo may add additional parameter: load builds into DB in sync/async fashion
buildRefSync.runActualizeBuildRefs(srvName, false, Sets.newHashSet(build.getId()), conn);
buildRefSync.runActualizeBuildRefs(srvCode, false, Sets.newHashSet(build.getId()), conn);

return build;
}
@@ -565,7 +567,7 @@ protected FatBuildCompacted getFatBuildFromIgnite(int buildId) {
}

String actualizeRecentBuildRefs() {
return actualizeRecentBuildRefs(srvName);
return actualizeRecentBuildRefs(srvCode);
}

/**
@@ -595,12 +597,12 @@ String actualizeRecentBuildRefs(String srvNme) {
//schedule direct reload for Fat Builds for all queued too-old builds
fatBuildSync.scheduleBuildsLoad(conn, directUpload);

buildRefSync.runActualizeBuildRefs(srvName, false, paginateUntil, conn);
buildRefSync.runActualizeBuildRefs(srvCode, false, paginateUntil, conn);

int freshButNotFoundByBuildsRefsScan = paginateUntil.size();
if (!paginateUntil.isEmpty()) {
//some builds may stuck in the queued or running, enforce loading now
fatBuildSync.doLoadBuilds(-1, srvName, conn, paginateUntil);
fatBuildSync.doLoadBuilds(-1, srvCode, conn, paginateUntil);
}

// schedule full resync later
@@ -622,6 +624,6 @@ private void sheduleResyncBuildRefs() {
*
*/
void fullReindex() {
buildRefSync.runActualizeBuildRefs(srvName, true, null, conn);
buildRefSync.runActualizeBuildRefs(srvCode, true, null, conn);
}
}
@@ -46,15 +46,6 @@ class TcLoginImpl implements ITcLogin {

final User tcUser = tcConn.getUserByUsername(username);

/*
final List<UserRef> usersRefs = users.getUsersRefs();
for (UserRef next : usersRefs) {
if (next.username.equals(username)) {
System.err.println("Found ");
}
}*/

if (tcUser != null)
logger.info("TC user returned: " + tcUser);

@@ -37,13 +37,4 @@ public static String escape(@Nullable final String val) {
return val;
}
}

public static String escapeOrB64(String val) {
if (Strings.nullToEmpty(val).contains("/")) {
String idForRestEncoded = Base64Util.encodeUtf8String(val);
return "($base64:" + idForRestEncoded + ")";
}
else
return escape(val);
}
}

0 comments on commit 67dcd11

Please sign in to comment.