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);
}
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"));
}
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();
}
}
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();
}
}
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()));
}
Aggregations