Search in sources :

Example 1 with NoRunningBuildException

use of jetbrains.buildServer.agent.NoRunningBuildException in project teamcity-torrent-plugin by JetBrains.

the class TorrentArtifactCacheListener method onAfterAddOrUpdate.

public void onAfterAddOrUpdate(@NotNull File file) {
    if (isTorrentFile(file))
        return;
    if (isTeamcityIVYFile(file))
        return;
    final String absolutePath = file.getAbsolutePath();
    if (!myTorrentsManager.isTransportEnabled()) {
        LOG.debug("Torrent plugin disabled. Won't seed " + absolutePath);
        return;
    }
    if (!TorrentUtil.shouldCreateTorrentFor(file.length(), myConfiguration)) {
        LOG.debug("Won't create torrent for " + absolutePath + ". Artifact is too small: " + file.length());
        return;
    }
    String announceUrl = myConfiguration.getAnnounceUrl();
    if (announceUrl == null)
        return;
    TorrentMetadata metadata;
    try {
        metadata = TorrentCreator.create(file, URI.create(announceUrl), "TeamCity Torrent Plugin");
    } catch (Exception e) {
        return;
    }
    if (myTorrentsSeeder.getClient().isSeeding(metadata)) {
        LOG.debug("Already seeding " + absolutePath);
        return;
    }
    File cacheCurrentBuildDir;
    try {
        cacheCurrentBuildDir = getCurrentBuildFolderCache();
    } catch (NoRunningBuildException e) {
        logWarningThatCacheCurrentBuildNotFound(absolutePath);
        return;
    }
    if (cacheCurrentBuildDir == null) {
        logWarningThatCacheCurrentBuildNotFound(absolutePath);
        return;
    }
    if (!isChildFile(cacheCurrentBuildDir, file)) {
        // reference to parent in relative path means that it is artifact from other build. We can skip it
        return;
    }
    File createdTorrentFile = publishTorrentFileAndStartSeeding(file);
    if (createdTorrentFile == null) {
        return;
    }
    createTorrentFileCopyAndAddAsArtifact(createdTorrentFile, file, cacheCurrentBuildDir);
}
Also used : NoRunningBuildException(jetbrains.buildServer.agent.NoRunningBuildException) File(java.io.File) TorrentMetadata(com.turn.ttorrent.common.TorrentMetadata) IOException(java.io.IOException) NoRunningBuildException(jetbrains.buildServer.agent.NoRunningBuildException)

Example 2 with NoRunningBuildException

use of jetbrains.buildServer.agent.NoRunningBuildException in project teamcity-git by JetBrains.

the class SSHAgentServiceTest method check_classpath_is_correct.

public void check_classpath_is_correct() throws IOException {
    File tempDir = createTempDir();
    Mockery m = new Mockery();
    BuildAgent agent = m.mock(BuildAgent.class);
    BuildAgentConfiguration agentConf = m.mock(BuildAgentConfiguration.class);
    CurrentBuildTracker buildTracker = m.mock(CurrentBuildTracker.class);
    m.checking(new Expectations() {

        {
            allowing(agentConf).getConfigurationParameters();
            will(returnValue(Collections.emptyMap()));
            allowing(agentConf).getTempDirectory();
            will(returnValue(tempDir));
            allowing(buildTracker).getCurrentBuild();
            will(throwException(new NoRunningBuildException()));
        }
    });
    GitAgentSSHService agentSSHService = new GitAgentSSHService(agent, agentConf, new MockGitPluginDescriptor(), new MockVcsRootSshKeyManagerProvider(), buildTracker);
    String scriptPath = agentSSHService.getScriptPath();
    GeneralCommandLine commandLine = new GeneralCommandLine();
    commandLine.setExePath(scriptPath);
    commandLine.addParameter("localhost");
    Map<String, String> env = new HashMap<>();
    env.put(GitSSHHandler.TEAMCITY_DEBUG_SSH, "true");
    commandLine.setEnvParams(env);
    ExecResult res = SimpleCommandLineProcessRunner.runCommand(commandLine, new byte[0]);
    then(res.getStderr()).doesNotContain("NoClassDefFoundError").doesNotContain("ClassNotFoundError");
}
Also used : Expectations(org.jmock.Expectations) GitAgentSSHService(jetbrains.buildServer.buildTriggers.vcs.git.agent.GitAgentSSHService) HashMap(java.util.HashMap) BuildAgent(jetbrains.buildServer.agent.BuildAgent) Mockery(org.jmock.Mockery) NoRunningBuildException(jetbrains.buildServer.agent.NoRunningBuildException) MockVcsRootSshKeyManagerProvider(jetbrains.buildServer.buildTriggers.vcs.git.tests.MockVcsRootSshKeyManagerProvider) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) CurrentBuildTracker(jetbrains.buildServer.agent.CurrentBuildTracker) File(java.io.File) BuildAgentConfiguration(jetbrains.buildServer.agent.BuildAgentConfiguration) MockGitPluginDescriptor(jetbrains.buildServer.buildTriggers.vcs.git.tests.MockGitPluginDescriptor) ExecResult(jetbrains.buildServer.ExecResult)

Aggregations

File (java.io.File)2 NoRunningBuildException (jetbrains.buildServer.agent.NoRunningBuildException)2 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 TorrentMetadata (com.turn.ttorrent.common.TorrentMetadata)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 ExecResult (jetbrains.buildServer.ExecResult)1 BuildAgent (jetbrains.buildServer.agent.BuildAgent)1 BuildAgentConfiguration (jetbrains.buildServer.agent.BuildAgentConfiguration)1 CurrentBuildTracker (jetbrains.buildServer.agent.CurrentBuildTracker)1 GitAgentSSHService (jetbrains.buildServer.buildTriggers.vcs.git.agent.GitAgentSSHService)1 MockGitPluginDescriptor (jetbrains.buildServer.buildTriggers.vcs.git.tests.MockGitPluginDescriptor)1 MockVcsRootSshKeyManagerProvider (jetbrains.buildServer.buildTriggers.vcs.git.tests.MockVcsRootSshKeyManagerProvider)1 Expectations (org.jmock.Expectations)1 Mockery (org.jmock.Mockery)1