public boolean downloadIfNecessary(final DownloadableFile downloadableFile) { boolean updated = false; boolean downloaded = false; while (!updated) try { fetchUpdateCheckHeaders(downloadableFile); if (downloadableFile.doesNotExist() || !downloadableFile.isChecksumEquals(getMd5())) { PerfTimer timer = PerfTimer.start("Downloading new " + downloadableFile + " with md5 signature: " + md5); downloaded = download(downloadableFile); timer.stop(); } updated = true; } catch (Exception e) { LOG.error("Couldn't update {}. Sleeping for 1m. Error: ", downloadableFile, e); try { int period = Integer.parseInt(System.getProperty("sleep.for.download", "60000")); Thread.sleep(period); } catch (InterruptedException ie) { /* we don't care. Stupid checked exception.*/ } } return downloaded; }
@Test public void shouldSetMd5AndSSLPortHeaders() throws Exception { ServerBinaryDownloader downloader = new ServerBinaryDownloader(ServerUrlGeneratorMother.generatorFor("localhost", server.getPort()), null, SslVerificationMode.NONE); downloader.downloadIfNecessary(DownloadableFile.AGENT); MessageDigest digester = MessageDigest.getInstance("MD5"); try (BufferedInputStream stream = new BufferedInputStream(new FileInputStream(DownloadableFile.AGENT.getLocalFile()))) { try (DigestInputStream digest = new DigestInputStream(stream, digester)) { IOUtils.copy(digest, new NullOutputStream()); } assertThat(downloader.getMd5(), is(Hex.encodeHexString(digester.digest()).toLowerCase())); } assertThat(downloader.getSslPort(), is(String.valueOf(server.getSecurePort()))); }
tfsImplDownloader.downloadIfNecessary(DownloadableFile.TFS_IMPL); command = agentInvocationCommand(agentDownloader.getMd5(), launcherMd5, pluginZipDownloader.getMd5(), tfsImplDownloader.getMd5(), env, context, agentDownloader.getSslPort(), agentDownloader.getExtraProperties()); LOG.info("Launching Agent with command: {}", join(command, " "));
agentDownloader.downloadIfNecessary(DownloadableFile.AGENT); returnValue = agentProcessParentRunner.run(getLauncherVersion(), launcherDownloader.getMd5(), urlGenerator, System.getenv(), context);