Skip to content

Commit d637cb2

Browse files
committed
Move constants to separate class.
1 parent f493a2c commit d637cb2

File tree

3 files changed

+56
-11
lines changed

3 files changed

+56
-11
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*
2+
* VM-Operator
3+
* Copyright (C) 2023 Michael N. Lipp
4+
*
5+
* This program is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU Affero General Public License as
7+
* published by the Free Software Foundation, either version 3 of the
8+
* License, or (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU Affero General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Affero General Public License
16+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
package org.jdrupes.vmoperator.runner.qemu;
20+
21+
/**
22+
* Some constants.
23+
*/
24+
@SuppressWarnings("PMD.DataClass")
25+
public class Constants extends org.jdrupes.vmoperator.common.Constants {
26+
27+
/**
28+
* Process names.
29+
*/
30+
public static class ProcessName {
31+
32+
/** The Constant QEMU. */
33+
public static final String QEMU = "qemu";
34+
35+
/** The Constant SWTPM. */
36+
public static final String SWTPM = "swtpm";
37+
38+
/** The Constant CLOUD_INIT_IMG. */
39+
public static final String CLOUD_INIT_IMG = "cloudInitImg";
40+
}
41+
42+
}

org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/QemuMonitor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.LinkedList;
2828
import java.util.Queue;
2929
import java.util.logging.Level;
30+
import org.jdrupes.vmoperator.runner.qemu.Constants.ProcessName;
3031
import org.jdrupes.vmoperator.runner.qemu.commands.QmpCapabilities;
3132
import org.jdrupes.vmoperator.runner.qemu.commands.QmpCommand;
3233
import org.jdrupes.vmoperator.runner.qemu.commands.QmpPowerdown;
@@ -259,7 +260,7 @@ public void onPowerdownEvent(PowerdownEvent event) {
259260
@SuppressWarnings("PMD.AvoidSynchronizedStatement")
260261
public void onProcessExited(ProcessExited event) {
261262
if (!event.startedBy().associated(CommandDefinition.class)
262-
.map(cd -> Runner.QEMU.equals(cd.name())).orElse(false)) {
263+
.map(cd -> ProcessName.QEMU.equals(cd.name())).orElse(false)) {
263264
return;
264265
}
265266
synchronized (this) {

org.jdrupes.vmoperator.runner.qemu/src/org/jdrupes/vmoperator/runner/qemu/Runner.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* VM-Operator
3-
* Copyright (C) 2023,2024 Michael N. Lipp
3+
* Copyright (C) 2023,2025 Michael N. Lipp
44
*
55
* This program is free software: you can redistribute it and/or modify
66
* it under the terms of the GNU Affero General Public License as
@@ -57,6 +57,7 @@
5757
import org.apache.commons.cli.Options;
5858
import static org.jdrupes.vmoperator.common.Constants.APP_NAME;
5959
import org.jdrupes.vmoperator.common.Constants.DisplaySecret;
60+
import org.jdrupes.vmoperator.runner.qemu.Constants.ProcessName;
6061
import org.jdrupes.vmoperator.runner.qemu.commands.QmpCont;
6162
import org.jdrupes.vmoperator.runner.qemu.commands.QmpReset;
6263
import org.jdrupes.vmoperator.runner.qemu.events.ConfigureQemu;
@@ -195,9 +196,6 @@
195196
"PMD.CouplingBetweenObjects", "PMD.TooManyFields" })
196197
public class Runner extends Component {
197198

198-
public static final String QEMU = "qemu";
199-
public static final String SWTPM = "swtpm";
200-
public static final String CLOUD_INIT_IMG = "cloudInitImg";
201199
private static final String TEMPLATE_DIR
202200
= "/opt/" + APP_NAME.replace("-", "") + "/templates";
203201
private static final String DEFAULT_TEMPLATE
@@ -350,15 +348,19 @@ private void processInitialConfiguration(Configuration newConfig) {
350348
initialConfig = newConfig;
351349

352350
// Configure
353-
swtpmDefinition = Optional.ofNullable(tplData.get(SWTPM))
354-
.map(d -> new CommandDefinition(SWTPM, d)).orElse(null);
351+
swtpmDefinition
352+
= Optional.ofNullable(tplData.get(ProcessName.SWTPM))
353+
.map(d -> new CommandDefinition(ProcessName.SWTPM, d))
354+
.orElse(null);
355355
logger.finest(() -> swtpmDefinition.toString());
356-
qemuDefinition = Optional.ofNullable(tplData.get(QEMU))
357-
.map(d -> new CommandDefinition(QEMU, d)).orElse(null);
356+
qemuDefinition = Optional.ofNullable(tplData.get(ProcessName.QEMU))
357+
.map(d -> new CommandDefinition(ProcessName.QEMU, d))
358+
.orElse(null);
358359
logger.finest(() -> qemuDefinition.toString());
359360
cloudInitImgDefinition
360-
= Optional.ofNullable(tplData.get(CLOUD_INIT_IMG))
361-
.map(d -> new CommandDefinition(CLOUD_INIT_IMG, d))
361+
= Optional.ofNullable(tplData.get(ProcessName.CLOUD_INIT_IMG))
362+
.map(d -> new CommandDefinition(ProcessName.CLOUD_INIT_IMG,
363+
d))
362364
.orElse(null);
363365
logger.finest(() -> cloudInitImgDefinition.toString());
364366

0 commit comments

Comments
 (0)