/** * Find a free (on localhost) random port in the range [49152, 65535] after 100 attempts. * * @return a random port where a server socket can be bound to */ public static int getFreeRandomPort() { // 100 attempts should be enough return getFreeRandomPort(49152, 65535, 100); }
private void downloadRemotes(final File outputDirectory, List<String> remotes) { if (!outputDirectory.exists()) { try { Files.createDirectories(outputDirectory.toPath()); } catch (IOException e) { throw new IllegalArgumentException(e); } } remotes.stream() .map(remote -> { try { return new URL(remote); } catch (MalformedURLException e) { throw new IllegalArgumentException(e); } }) .forEach(url -> { try { IoUtil.download(this.log, url, new File(outputDirectory, getOutputName(url))); } catch (MojoExecutionException e) { throw new IllegalArgumentException(e); } }); }
int len = in.read(buffer); readBytes += len; log.progressUpdate(target.getName(), "Downloading", getProgressBar(readBytes, length)); if (len <= 0) { out.flush();
private ArchiverCustomizer getS2ICustomizer(ImageConfiguration imageConfiguration) throws Fabric8ServiceException { try { if (imageConfiguration.getBuildConfiguration() != null && imageConfiguration.getBuildConfiguration().getEnv() != null) { String fileName = IoUtil.sanitizeFileName("s2i-env-" + imageConfiguration.getName()); final File environmentFile = new File(config.getBuildDirectory(), fileName); try (PrintWriter out = new PrintWriter(new FileWriter(environmentFile))) { for (Map.Entry<String, String> e : imageConfiguration.getBuildConfiguration().getEnv().entrySet()) { out.println(e.getKey() + "=" + e.getValue()); } } return new ArchiverCustomizer() { @Override public TarArchiver customize(TarArchiver tarArchiver) throws IOException { tarArchiver.addFile(environmentFile, ".s2i/environment"); return tarArchiver; } }; } else { return null; } } catch (IOException e) { throw new Fabric8ServiceException("Unable to add environment variables to the S2I build archive", e); } }
private String getPortForwardUrl(final Set<HasMetadata> resources) throws Exception { LabelSelector selector = KubernetesResourceUtil.getPodLabelSelector(resources); if (selector == null) { log.warn("Unable to determine a selector for application pods"); return null; } Properties properties = SpringBootUtil.getSpringBootApplicationProperties(MavenUtil.getCompileClassLoader(getContext().getProject())); SpringBootConfigurationHelper propertyHelper = new SpringBootConfigurationHelper(SpringBootUtil.getSpringBootVersion(getContext().getProject())); int port = IoUtil.getFreeRandomPort(); int containerPort = propertyHelper.getServerPort(properties); portForwardService.forwardPortAsync(getContext().getLogger(), selector, containerPort, port); return createForwardUrl(propertyHelper, properties, port); }