/** * Construct a Mesos URI. */ public static Protos.CommandInfo.URI uri(MesosArtifactResolver resolver, ContainerSpecification.Artifact artifact) { checkNotNull(resolver); checkNotNull(artifact); Option<URL> url = resolver.resolve(artifact.dest); if (url.isEmpty()) { throw new IllegalArgumentException("Unresolvable artifact: " + artifact.dest); } return Protos.CommandInfo.URI.newBuilder() .setValue(url.get().toExternalForm()) .setOutputFile(artifact.dest.toString()) .setExtract(artifact.extract) .setCache(artifact.cachable) .setExecutable(artifact.executable) .build(); }
/** * Construct a Mesos URI. */ public static Protos.CommandInfo.URI uri(URL url, boolean cacheable) { checkNotNull(url); return Protos.CommandInfo.URI.newBuilder() .setValue(url.toExternalForm()) .setExtract(false) .setCache(cacheable) .build(); }
@Override public Protos.CommandInfo create(Map<String, String> additionalEnvironmentVariables) { Protos.CommandInfo.Builder builder = Protos.CommandInfo.newBuilder(); Optional<String> command = Optional.ofNullable(mesosConfig.getCommand()); builder.setShell(command.isPresent()); command.ifPresent(builder::setValue); builder.addAllUris(mesosConfig.getUri().stream().map(uri -> Protos.CommandInfo.URI.newBuilder().setValue(uri).build()).collect(Collectors.toList())); Map<String, String> environmentVariables = new LinkedHashMap<>(); environmentVariables.putAll(additionalEnvironmentVariables); environmentVariables.putAll(mesosConfig.getEnvironment()); //todo: migrate to foreach environmentVariables.entrySet().stream() .map(kv -> Protos.Environment.Variable.newBuilder().setName(kv.getKey()).setValue(kv.getValue()).build()) .collect(Collectors.collectingAndThen( Collectors.toList(), variables -> builder.setEnvironment(Protos.Environment.newBuilder().addAllVariables(variables)))); return builder.build(); } }
public static Collection<CommandInfo.URI> createURIs( final Set<String> uris, boolean cacheFetchedUris) { return uris.stream() .map(uri -> CommandInfo.URI.newBuilder() .setCache(cacheFetchedUris) .setExecutable(false) .setExtract(true) .setValue(uri).build()) .collect(Collectors.toList()); }
private Protos.CommandInfo.URI buildURI(final CloudAppConfiguration appConfig, final boolean isCommandExecutor) { Protos.CommandInfo.URI.Builder result = Protos.CommandInfo.URI.newBuilder().setValue(appConfig.getAppURL()).setCache(appConfig.isAppCacheEnable()); if (isCommandExecutor && !SupportedExtractionType.isExtraction(appConfig.getAppURL())) { result.setExecutable(true); } else { result.setExtract(true); } return result.build(); }