Search in sources :

Example 1 with OS

use of org.infinispan.commons.util.OS in project infinispan by infinispan.

the class Server method getServerReport.

@Override
public CompletionStage<Path> getServerReport() {
    SecurityActions.checkPermission(cacheManager.withSubject(Security.getSubject()), AuthorizationPermission.ADMIN);
    OS os = OS.getCurrentOs();
    String reportFile = "bin/%s";
    switch(os) {
        case LINUX:
            reportFile = String.format(reportFile, "report.sh");
            break;
        case MAC_OS:
            reportFile = String.format(reportFile, "report-osx.sh");
            break;
        default:
            return CompletableFutures.completedExceptionFuture(log.serverReportUnavailable(os));
    }
    long pid = ProcessInfo.getInstance().getPid();
    Path home = serverHome.toPath();
    Path root = serverRoot.toPath();
    ProcessBuilder builder = new ProcessBuilder();
    builder.command("sh", "-c", home.resolve(reportFile).toString(), Long.toString(pid), root.toString());
    return blockingManager.supplyBlocking(() -> {
        try {
            Process process = builder.start();
            BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
            Path path = Paths.get(reader.readLine());
            process.waitFor(1, TimeUnit.MINUTES);
            return path;
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new RuntimeException(e);
        }
    }, "report");
}
Also used : Path(java.nio.file.Path) OS(org.infinispan.commons.util.OS) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException)

Aggregations

BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 Path (java.nio.file.Path)1 OS (org.infinispan.commons.util.OS)1