Search in sources :

Example 1 with ServerUrlGenerator

use of com.thoughtworks.go.agent.ServerUrlGenerator in project gocd by gocd.

the class DownloadableFileTest method shouldThrowExceptionIfUrlIsInvalid.

@Test
public void shouldThrowExceptionIfUrlIsInvalid() throws Exception {
    ServerUrlGenerator serverUrlGenerator = mock(ServerUrlGenerator.class);
    when(serverUrlGenerator.serverUrlFor("admin/agent")).thenReturn("invalidUrl");
    exception.expect(RuntimeException.class);
    exception.expectMessage("URL you provided to access Go Server: " + "invalidUrl" + " is not valid");
    DownloadableFile.AGENT.validatedUrl(serverUrlGenerator);
}
Also used : ServerUrlGenerator(com.thoughtworks.go.agent.ServerUrlGenerator) Test(org.junit.Test)

Example 2 with ServerUrlGenerator

use of com.thoughtworks.go.agent.ServerUrlGenerator in project gocd by gocd.

the class DownloadableFileTest method shouldValidateTheUrl.

@Test
public void shouldValidateTheUrl() throws Exception {
    ServerUrlGenerator serverUrlGenerator = ServerUrlGeneratorMother.generatorFor("localhost", 9090);
    assertThat(DownloadableFile.AGENT.validatedUrl(serverUrlGenerator), is("http://localhost:9090/go/admin/agent"));
}
Also used : ServerUrlGenerator(com.thoughtworks.go.agent.ServerUrlGenerator) Test(org.junit.Test)

Example 3 with ServerUrlGenerator

use of com.thoughtworks.go.agent.ServerUrlGenerator in project gocd by gocd.

the class AgentLauncherImpl method doLaunch.

private Integer doLaunch(AgentLaunchDescriptor descriptor) {
    Thread shutdownHook = null;
    try {
        int returnValue;
        if (!lockFile.tryLock()) {
            return IRRECOVERABLE_ERROR;
        }
        shutdownHook = registerShutdownHook();
        Map context = descriptor.context();
        AgentBootstrapperBackwardCompatibility backwardCompatibility = backwardCompatibility(context);
        ServerUrlGenerator urlGenerator = backwardCompatibility.getUrlGenerator();
        File rootCertFile = backwardCompatibility.rootCertFile();
        SslVerificationMode sslVerificationMode = backwardCompatibility.sslVerificationMode();
        ServerBinaryDownloader launcherDownloader = new ServerBinaryDownloader(urlGenerator, rootCertFile, sslVerificationMode);
        if (launcherDownloader.downloadIfNecessary(DownloadableFile.LAUNCHER)) {
            return LAUNCHER_NOT_UP_TO_DATE;
        }
        ServerBinaryDownloader agentDownloader = new ServerBinaryDownloader(urlGenerator, rootCertFile, sslVerificationMode);
        agentDownloader.downloadIfNecessary(DownloadableFile.AGENT);
        returnValue = agentProcessParentRunner.run(getLauncherVersion(), launcherDownloader.getMd5(), urlGenerator, System.getenv(), context);
        try {
            // Sleep a bit so that if there are problems we don't spin
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            return returnValue;
        }
        return returnValue;
    } catch (Exception e) {
        LOG.error("Launch encountered an unknown exception", e);
        return UNKNOWN_EXCEPTION_OCCURRED;
    } finally {
        removeShutDownHook(shutdownHook);
        lockFile.delete();
    }
}
Also used : AgentBootstrapperBackwardCompatibility(com.thoughtworks.go.agent.common.AgentBootstrapperBackwardCompatibility) ServerUrlGenerator(com.thoughtworks.go.agent.ServerUrlGenerator) SslVerificationMode(com.thoughtworks.go.util.SslVerificationMode) Map(java.util.Map) File(java.io.File) IOException(java.io.IOException)

Example 4 with ServerUrlGenerator

use of com.thoughtworks.go.agent.ServerUrlGenerator in project gocd by gocd.

the class AgentLauncherImpl method launch.

public int launch(AgentLaunchDescriptor descriptor) {
    Thread shutdownHook = null;
    try {
        LoggingHelper.configureLoggerIfNoneExists("go-agent-launcher.log", "go-agent-launcher-log4j.properties");
        int returnValue;
        if (!lockFile.tryLock()) {
            return IRRECOVERABLE_ERROR;
        }
        shutdownHook = registerShutdownHook();
        Map context = descriptor.context();
        AgentBootstrapperBackwardCompatibility backwardCompatibility = backwardCompatibility(context);
        ServerUrlGenerator urlGenerator = backwardCompatibility.getUrlGenerator();
        File rootCertFile = backwardCompatibility.rootCertFile();
        SslVerificationMode sslVerificationMode = backwardCompatibility.sslVerificationMode();
        ServerBinaryDownloader launcherDownloader = new ServerBinaryDownloader(urlGenerator, rootCertFile, sslVerificationMode);
        if (launcherDownloader.downloadIfNecessary(DownloadableFile.LAUNCHER)) {
            return LAUNCHER_NOT_UP_TO_DATE;
        }
        ServerBinaryDownloader agentDownloader = new ServerBinaryDownloader(urlGenerator, rootCertFile, sslVerificationMode);
        agentDownloader.downloadIfNecessary(DownloadableFile.AGENT);
        returnValue = agentProcessParentRunner.run(getLauncherVersion(), launcherDownloader.getMd5(), urlGenerator, System.getenv(), context);
        try {
            // Sleep a bit so that if there are problems we don't spin
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            return returnValue;
        }
        return returnValue;
    } catch (Exception e) {
        LOG.error("Launch encountered an unknown exception", e);
        return UNKNOWN_EXCEPTION_OCCURRED;
    } finally {
        removeShutDownHook(shutdownHook);
        lockFile.delete();
    }
}
Also used : AgentBootstrapperBackwardCompatibility(com.thoughtworks.go.agent.common.AgentBootstrapperBackwardCompatibility) ServerUrlGenerator(com.thoughtworks.go.agent.ServerUrlGenerator) SslVerificationMode(com.thoughtworks.go.util.SslVerificationMode) Map(java.util.Map) File(java.io.File) IOException(java.io.IOException)

Example 5 with ServerUrlGenerator

use of com.thoughtworks.go.agent.ServerUrlGenerator in project gocd by gocd.

the class AgentLauncherImplTest method shouldPassLauncherVersionToAgent.

@Test
public void shouldPassLauncherVersionToAgent() throws InterruptedException, IOException {
    final List<String> actualVersion = new ArrayList<>();
    final AgentLauncher launcher = new AgentLauncherImpl(new AgentLauncherImpl.AgentProcessParentRunner() {

        public int run(String launcherVersion, String launcherMd5, ServerUrlGenerator urlConstructor, Map<String, String> environmentVariables, Map context) {
            actualVersion.add(launcherVersion);
            return 0;
        }
    });
    TEST_AGENT_LAUNCHER.copyTo(AGENT_LAUNCHER_JAR);
    launcher.launch(launchDescriptor());
    assertThat(actualVersion.size(), is(1));
    assertThat(actualVersion.get(0), is(CurrentGoCDVersion.getInstance().fullVersion()));
}
Also used : AgentLauncher(com.thoughtworks.cruise.agent.common.launcher.AgentLauncher) ArrayList(java.util.ArrayList) ServerUrlGenerator(com.thoughtworks.go.agent.ServerUrlGenerator) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Test(org.junit.Test)

Aggregations

ServerUrlGenerator (com.thoughtworks.go.agent.ServerUrlGenerator)5 Map (java.util.Map)3 Test (org.junit.Test)3 AgentBootstrapperBackwardCompatibility (com.thoughtworks.go.agent.common.AgentBootstrapperBackwardCompatibility)2 SslVerificationMode (com.thoughtworks.go.util.SslVerificationMode)2 File (java.io.File)2 IOException (java.io.IOException)2 AgentLauncher (com.thoughtworks.cruise.agent.common.launcher.AgentLauncher)1 ArrayList (java.util.ArrayList)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1