use of com.oracle.bedrock.runtime.options.Console in project oracle-bedrock by coherence-community.
the class DockerMachine method environmentFor.
/**
* Obtain the {@link EnvironmentVariable}s that can be applied to a Docker command
* to make it execute against the specified Docker Machine.
*
* @param machineName the name of the Docker Machine
*
* @return the {@link EnvironmentVariable}s required to use the Docker Machine
*/
public List<EnvironmentVariable> environmentFor(String machineName) {
CapturingApplicationConsole console = new CapturingApplicationConsole();
try (Application application = launch("env", Argument.of(machineName), Console.of(console))) {
if (application.waitFor() == 0) {
return console.getCapturedOutputLines().stream().filter((line) -> line.startsWith("export")).map((line) -> line.substring(7)).map((line -> {
int index = line.indexOf('=');
if (index >= 0) {
String name = line.substring(0, index);
String value = StringHelper.unquote(line.substring(index + 1));
return EnvironmentVariable.of(name, value);
}
return EnvironmentVariable.of(line);
})).collect(Collectors.toList());
}
String msg = "Error obtaining environment for docker-machine " + machineName;
logError(msg, console);
throw new RuntimeException(msg);
}
}
use of com.oracle.bedrock.runtime.options.Console in project oracle-bedrock by coherence-community.
the class Pod method getContainers.
/**
* Obtain the containers for this Pod.
*
* @return a {@link Map} of containers for this Pod keyed by container name
*/
public Map<String, PodContainer> getContainers() {
if (containers == null) {
synchronized (this) {
if (containers == null) {
CapturingApplicationConsole console = new CapturingApplicationConsole();
List<String> args = getArgs("get");
args.add("pod");
args.add(podName);
args.add("-o");
args.add("jsonpath={range .spec.containers[*]}{.name}{\"\\n\"}{end}");
int exitCode = k8s.kubectlAndWait(Arguments.of(args), Console.of(console), LaunchLogging.disabled());
if (exitCode == 0) {
containers = console.getCapturedOutputLines().stream().filter(s -> !"(terminated)".equals(s)).filter(s -> !s.trim().isEmpty()).map(name -> new PodContainer(k8s, podName, name, namespace)).collect(Collectors.toMap(PodContainer::getContainerName, container -> container));
} else {
String msg = String.join("\n", console.getCapturedErrorLines());
throw new RuntimeException("Error obtaining Pod containers\n" + msg);
}
}
}
}
return Collections.unmodifiableMap(containers);
}
Aggregations