Code cleanup around opensearch process info (#15709)

* Code cleanup around opensearch process info

* Code cleanup

* fixed naming and test

* fixed test

* fixed test

* code cleanup

* code cleanup
This commit is contained in:
Tomas Dvorak
2023-06-19 06:36:32 +02:00
committed by GitHub
parent 8dd21cc4f4
commit 9105655645
15 changed files with 118 additions and 108 deletions

View File

@@ -16,6 +16,5 @@
*/
package org.graylog.datanode.process;
public record ProcessInfo(long pid, String nodeName, ProcessState status, boolean isLeaderNode, java.time.Instant started, java.time.Duration totalCpuDuration, String user,
String restBaseUrl) {
public record OpensearchInfo(String nodeName, ProcessState state, boolean isLeaderNode, String restBaseUrl, ProcessInformation process) {
}

View File

@@ -0,0 +1,30 @@
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/
package org.graylog.datanode.process;
import java.time.Instant;
public record ProcessInformation(long pid, boolean alive, Instant started) {
public static ProcessInformation empty() {
return new ProcessInformation(-1, false, null);
}
public static ProcessInformation create(Process p) {
return new ProcessInformation(p.pid(), p.isAlive(), p.info().startInstant().orElse(null));
}
}

View File

@@ -0,0 +1,45 @@
/*
* Copyright (C) 2020 Graylog, Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Server Side Public License, version 1,
* as published by MongoDB, Inc.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Server Side Public License for more details.
*
* You should have received a copy of the Server Side Public License
* along with this program. If not, see
* <http://www.mongodb.com/licensing/server-side-public-license>.
*/
package org.graylog.datanode.process;
import org.apache.commons.exec.ExecuteWatchdog;
import javax.validation.constraints.NotNull;
import java.util.Optional;
public class WatchdogWithProcessInfo extends ExecuteWatchdog {
private Process process;
public WatchdogWithProcessInfo(long timeout) {
super(timeout);
}
@Override
public synchronized void start(Process processToMonitor) {
super.start(processToMonitor);
this.process = processToMonitor;
}
@NotNull
public ProcessInformation processInfo() {
return Optional.ofNullable(process)
.map(ProcessInformation::create)
.orElse(ProcessInformation.empty());
}
}