Skip to content
Permalink
Browse files
IGNITE-10989: TC Helper god object was removed
  • Loading branch information
dspavlov committed Jan 23, 2019
1 parent 3820111 commit 11bfe4d067d0a80f0475c628a46911bbd22bdb4f
Show file tree
Hide file tree
Showing 24 changed files with 90 additions and 114 deletions.
@@ -20,7 +20,7 @@ Should you have any questions please contact Ignite Developers at dev@ignite.apa
Locally code can be set up using IntelliJ idea and gradle project import.
Locally it can be run using org.apache.ignite.ci.web.Launcher.main() method.
The bot will create necessary configs in ~/.ignite-teamcity-helper - it is bot Home directory.
In can be changed with org.apache.ignite.ci.ITcHelper.TEAMCITY_HELPER_HOME system property.
In can be changed with org.apache.ignite.ci.tcbot.TcBotSystemProperties.TEAMCITY_HELPER_HOME system property.

Examples of configs can be found in [conf](conf) directory.

@@ -28,6 +28,7 @@
import javax.ws.rs.QueryParam;
import org.apache.ignite.ci.conf.BranchesTracked;
import org.apache.ignite.ci.conf.PasswordEncoder;
import org.apache.ignite.ci.tcbot.TcBotSystemProperties;
import org.apache.ignite.ci.util.Base64Util;
import org.apache.ignite.ci.util.ExceptionUtil;
import org.jetbrains.annotations.NotNull;
@@ -126,7 +127,7 @@ public static File ensureDirExist(File workDir) {

public static File resolveWorkDir() {
File workDir = null;
String property = System.getProperty(ITcHelper.TEAMCITY_HELPER_HOME);
String property = System.getProperty(TcBotSystemProperties.TEAMCITY_HELPER_HOME);
if (isNullOrEmpty(property)) {
String conf = ".ignite-teamcity-helper";
String prop = System.getProperty("user.home");

This file was deleted.

@@ -23,7 +23,7 @@
import ch.qos.logback.core.rolling.RollingFileAppender;
import ch.qos.logback.core.rolling.TimeBasedRollingPolicy;
import org.apache.ignite.ci.HelperConfig;
import org.apache.ignite.ci.ITcHelper;
import org.apache.ignite.ci.tcbot.TcBotSystemProperties;
import org.apache.ignite.configuration.DataRegionConfiguration;
import org.apache.ignite.configuration.DataStorageConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
@@ -95,7 +95,7 @@ public static DataRegionConfiguration getDataRegionConfiguration() {
final DataRegionConfiguration regConf = new DataRegionConfiguration()
.setPersistenceEnabled(true);

String regSzGb = System.getProperty(ITcHelper.TEAMCITY_BOT_REGIONSIZE);
String regSzGb = System.getProperty(TcBotSystemProperties.TEAMCITY_BOT_REGIONSIZE);

if (regSzGb != null) {
try {
@@ -26,8 +26,6 @@
import java.util.concurrent.TimeoutException;
import javax.inject.Provider;
import org.apache.ignite.Ignite;
import org.apache.ignite.ci.ITcHelper;
import org.apache.ignite.ci.TcHelper;
import org.apache.ignite.ci.db.Ignite1Init;
import org.apache.ignite.ci.di.cache.GuavaCachedModule;
import org.apache.ignite.ci.di.scheduler.SchedulerModule;
@@ -76,7 +74,6 @@ public class IgniteTcBotModule extends AbstractModule {
bind(ObserverTask.class).in(new SingletonScope());
bind(BuildObserver.class).in(new SingletonScope());
bind(VisasHistoryStorage.class).in(new SingletonScope());
bind(ITcHelper.class).to(TcHelper.class).in(new SingletonScope());
bind(BackgroundUpdater.class).in(new SingletonScope());

install(new TeamcityIgnitedModule());
@@ -20,7 +20,7 @@
import java.util.Objects;
import java.util.Timer;
import javax.inject.Inject;
import org.apache.ignite.ci.ITcHelper;
import org.apache.ignite.ci.tcbot.ITcBotBgAuth;
import org.apache.ignite.ci.tcmodel.result.Build;
import org.apache.ignite.ci.teamcity.ignited.IStringCompactor;
import org.apache.ignite.ci.teamcity.ignited.ITeamcityIgnited;
@@ -47,8 +47,7 @@ public class BuildObserver {
/** Task, which should be done periodically. */
private ObserverTask observerTask;

/** Helper. */
@Inject private ITcHelper tcHelper;
@Inject private ITcBotBgAuth tcBotBgAuth;

/** */
@Inject private ITeamcityIgnitedProvider teamcityIgnitedProvider;
@@ -115,7 +114,7 @@ public String getObservationStatus(ContributionKey key) {

BuildsInfo buildsInfo = observerTask.getInfo(key);

ICredentialsProv creds = tcHelper.getServerAuthorizerCreds();
ICredentialsProv creds = tcBotBgAuth.getServerAuthorizerCreds();

ITeamcityIgnited teamcity = teamcityIgnitedProvider.server(key.srvId, creds);

@@ -27,11 +27,9 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.locks.ReentrantLock;
import javax.inject.Inject;
import org.apache.ignite.ci.ITcHelper;
import org.apache.ignite.ci.di.AutoProfiling;
import org.apache.ignite.ci.di.MonitoredTask;
import org.apache.ignite.ci.jira.pure.IJiraIntegration;
import org.apache.ignite.ci.jira.pure.IJiraIntegrationProvider;
import org.apache.ignite.ci.tcbot.ITcBotBgAuth;
import org.apache.ignite.ci.tcbot.visa.TcBotTriggerAndSignOffService;
import org.apache.ignite.ci.teamcity.ignited.IStringCompactor;
import org.apache.ignite.ci.teamcity.ignited.ITeamcityIgnited;
@@ -57,7 +55,7 @@ public class ObserverTask extends TimerTask {
private static final Logger logger = LoggerFactory.getLogger(ObserverTask.class);

/** Helper. */
@Inject private ITcHelper tcHelper;
@Inject private ITcBotBgAuth tcBotBgAuth;

/** */
@Inject private ITeamcityIgnitedProvider teamcityIgnitedProvider;
@@ -154,9 +152,11 @@ protected String runObserverTask() {
observationLock.lock();

try {
if (!tcHelper.isServerAuthorized())
if (!tcBotBgAuth.isServerAuthorized())
return "Server authorization required.";

ICredentialsProv creds = tcBotBgAuth.getServerAuthorizerCreds();

int checkedBuilds = 0;
int notFinishedBuilds = 0;
Set<String> ticketsNotified = new HashSet<>();
@@ -166,8 +166,7 @@ protected String runObserverTask() {
for (ContributionKey key : infos.keySet()) {
BuildsInfo info = infos.get(key);

ITeamcityIgnited teamcity = teamcityIgnitedProvider.server(info.srvId,
tcHelper.getServerAuthorizerCreds());
ITeamcityIgnited teamcity = teamcityIgnitedProvider.server(info.srvId, creds);

checkedBuilds += info.buildsCount();

@@ -190,8 +189,6 @@ protected String runObserverTask() {
Visa visa = visasHistStorage.getLastVisaRequest(info.getContributionKey()).getResult();

if (!visa.isSuccess()) {
ICredentialsProv creds = tcHelper.getServerAuthorizerCreds();

Visa updatedVisa = visaIssuer.notifyJira(info.srvId, creds, info.buildTypeId,
info.branchForTc, info.ticket);

@@ -22,7 +22,7 @@
import org.apache.ignite.ci.db.TcHelperDb;
import org.apache.ignite.ci.issue.Issue;
import org.apache.ignite.ci.issue.IssuesStorage;
import org.apache.ignite.ci.user.UserAndSessionsStorage;
import org.apache.ignite.ci.tcbot.user.UserAndSessionsStorage;

/**
* Utility class for local connection to TC helper DB (server) and any manipulations with data needed.
@@ -38,7 +38,7 @@
import org.apache.ignite.ci.teamcity.ignited.fatbuild.FatBuildCompacted;
import org.apache.ignite.ci.teamcity.ignited.fatbuild.FatBuildDao;
import org.apache.ignite.ci.user.TcHelperUser;
import org.apache.ignite.ci.user.UserAndSessionsStorage;
import org.apache.ignite.ci.tcbot.user.UserAndSessionsStorage;
import org.apache.ignite.ci.util.XmlUtil;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.logger.slf4j.Slf4jLogger;
@@ -14,35 +14,23 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

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

import org.apache.ignite.ci.user.ICredentialsProv;
import org.jetbrains.annotations.Nullable;

/**
* Teamcity Bot main interface. This inteface became too huge.
* Server authorization data holder. Saves credentials provided by user in Authorize server.
*/
@Deprecated
public interface ITcHelper {
/** System property to specify: Teamcity helper home. Ignite home will be set to same dir. */
public String TEAMCITY_HELPER_HOME = "teamcity.helper.home";

/**
* Teamcity bot data storage configuration region size in gigabytes. Default is 20% of physical RAM.
*/
public String TEAMCITY_BOT_REGIONSIZE = "teamcity.bot.regionsize";

String primaryServerId();

@Deprecated
public interface ITcBotBgAuth {
/** */
void setServerAuthorizerCreds(ICredentialsProv creds);
public void setServerAuthorizerCreds(ICredentialsProv creds);

@Deprecated
/** */
ICredentialsProv getServerAuthorizerCreds();
@Nullable public ICredentialsProv getServerAuthorizerCreds();

/** */
boolean isServerAuthorized();

public default boolean isServerAuthorized() {
return getServerAuthorizerCreds() != null;
}
}
@@ -0,0 +1,22 @@
package org.apache.ignite.ci.tcbot;

import org.apache.ignite.ci.user.ICredentialsProv;
import org.jetbrains.annotations.Nullable;

/**
*
*/
class TcBotBgAuthImpl implements ITcBotBgAuth {
/** Server authorizer credentials. */
private ICredentialsProv srvAuthorizerCreds;

/** {@inheritDoc} */
@Override public void setServerAuthorizerCreds(ICredentialsProv creds) {
this.srvAuthorizerCreds = creds;
}

/** {@inheritDoc} */
@Nullable @Override public ICredentialsProv getServerAuthorizerCreds() {
return srvAuthorizerCreds;
}
}
@@ -24,7 +24,7 @@
import org.apache.ignite.ci.tcbot.issue.IIssuesStorage;
import org.apache.ignite.ci.tcbot.trends.MasterTrendsService;
import org.apache.ignite.ci.tcbot.user.IUserStorage;
import org.apache.ignite.ci.user.UserAndSessionsStorage;
import org.apache.ignite.ci.tcbot.user.UserAndSessionsStorage;

/**
* TC Bot self services mapping (without 3rd party integrations configuration.
@@ -36,5 +36,6 @@ public class TcBotBusinessServicesModule extends AbstractModule {
bind(IUserStorage.class).to(UserAndSessionsStorage.class).in(new SingletonScope());
bind(IIssuesStorage.class).to(IssuesStorage.class).in(new SingletonScope());
bind(MasterTrendsService.class).in(new SingletonScope());
bind(ITcBotBgAuth.class).to(TcBotBgAuthImpl.class).in(new SingletonScope());
}
}
@@ -21,7 +21,17 @@
* Apache Ignite Teamcity Bot properties.
*/
public class TcBotSystemProperties {
/** Dev mode. */
public static final String DEV_MODE = "DEV_MODE";

/** Teamcity bot recorder. */
public static final String TEAMCITY_BOT_RECORDER = "teamcity.bot.recorder";

/**
* Teamcity bot data storage configuration region size in gigabytes. Default is 20% of physical RAM.
*/
public static final String TEAMCITY_BOT_REGIONSIZE = "teamcity.bot.regionsize";

/** System property to specify: Teamcity helper home. Ignite home will be set to same dir. */
public static final String TEAMCITY_HELPER_HOME = "teamcity.helper.home";
}
@@ -27,6 +27,9 @@ public interface ITcBotConfig {
/** Default server id. */
String DEFAULT_SERVER_ID = "apache";


public String primaryServerId();

/**
* @return Tracked branches configuration for TC Bot.
*/
@@ -45,4 +48,6 @@ public default List<String> getTrackedBranchesIds() {
public default Collection<String> getServerIds() {
return getTrackedBranches().getServerIds();
}


}
@@ -29,4 +29,8 @@ public class LocalFilesBasedConfig implements ITcBotConfig {
@Override public BranchesTracked getTrackedBranches() {
return HelperConfig.getTrackedBranches();
}

@Override public String primaryServerId() {
return ITcBotConfig.DEFAULT_SERVER_ID;
}
}
@@ -15,12 +15,14 @@
* limitations under the License.
*/

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

import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.ci.db.TcHelperDb;
import org.apache.ignite.ci.tcbot.user.IUserStorage;
import org.apache.ignite.ci.user.TcHelperUser;
import org.apache.ignite.ci.user.UserSession;
import org.jetbrains.annotations.Nullable;

import javax.cache.Cache;
@@ -18,7 +18,6 @@
package org.apache.ignite.ci.tcbot.visa;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.inject.Provider;
import java.text.DateFormat;
@@ -37,7 +36,6 @@
import javax.inject.Inject;
import javax.ws.rs.QueryParam;
import org.apache.ignite.ci.HelperConfig;
import org.apache.ignite.ci.ITcHelper;
import org.apache.ignite.ci.ITeamcity;
import org.apache.ignite.ci.github.GitHubBranch;
import org.apache.ignite.ci.github.GitHubUser;
@@ -51,6 +49,7 @@
import org.apache.ignite.ci.jira.pure.IJiraIntegrationProvider;
import org.apache.ignite.ci.observer.BuildObserver;
import org.apache.ignite.ci.observer.BuildsInfo;
import org.apache.ignite.ci.tcbot.ITcBotBgAuth;
import org.apache.ignite.ci.tcbot.chain.PrChainsProcessor;
import org.apache.ignite.ci.tcmodel.mute.MuteInfo;
import org.apache.ignite.ci.tcmodel.result.Build;
@@ -126,7 +125,7 @@ public class TcBotTriggerAndSignOffService {
@Inject IStringCompactor compactor;

/** Helper. */
@Inject ITcHelper tcHelper;
@Inject ITcBotBgAuth tcBotBgAuth;

@Inject PrChainsProcessor prChainsProcessor;

@@ -342,7 +341,7 @@ private String observeJira(

buildObserverProvider.get().observe(srvId, prov, ticketFullName, branchForTc, parentSuiteId, builds);

if (!tcHelper.isServerAuthorized())
if (!tcBotBgAuth.isServerAuthorized())
return "Ask server administrator to authorize the Bot to enable JIRA notifications.";

return "JIRA ticket " + ticketFullName + " will be notified after the tests are completed.";

0 comments on commit 11bfe4d

Please sign in to comment.