Move code to agent.
This commit is contained in:
parent
68a688c4ce
commit
19968ab73e
2 changed files with 34 additions and 37 deletions
|
|
@ -20,6 +20,7 @@ package org.jdrupes.vmoperator.runner.qemu;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
import java.util.List;
|
||||||
import org.jdrupes.vmoperator.runner.qemu.events.VserportChangeEvent;
|
import org.jdrupes.vmoperator.runner.qemu.events.VserportChangeEvent;
|
||||||
import org.jgrapes.core.Channel;
|
import org.jgrapes.core.Channel;
|
||||||
import org.jgrapes.core.annotation.Handler;
|
import org.jgrapes.core.annotation.Handler;
|
||||||
|
|
@ -52,12 +53,36 @@ public abstract class AgentConnector extends QemuConnector {
|
||||||
* for the {@link ConfigurationUpdate} event. The values are
|
* for the {@link ConfigurationUpdate} event. The values are
|
||||||
* forwarded from the {@link Runner} instead.
|
* forwarded from the {@link Runner} instead.
|
||||||
*
|
*
|
||||||
* @param channelId the channel id
|
* @param command the command
|
||||||
* @param socketPath the socket path
|
* @param chardev the chardev
|
||||||
*/
|
*/
|
||||||
/* default */ void configure(String channelId, Path socketPath) {
|
@SuppressWarnings("PMD.CognitiveComplexity")
|
||||||
|
protected void configure(List<String> command, String chardev) {
|
||||||
|
Path socketPath = null;
|
||||||
|
for (var arg : command) {
|
||||||
|
if (arg.startsWith("virtserialport,")
|
||||||
|
&& arg.contains("chardev=" + chardev)) {
|
||||||
|
for (var prop : arg.split(",")) {
|
||||||
|
if (prop.startsWith("id=")) {
|
||||||
|
channelId = prop.substring(3);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (arg.startsWith("socket,")
|
||||||
|
&& arg.contains("id=" + chardev)) {
|
||||||
|
for (var prop : arg.split(",")) {
|
||||||
|
if (prop.startsWith("path=")) {
|
||||||
|
socketPath = Path.of(prop.substring(5));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (channelId == null || socketPath == null) {
|
||||||
|
logger.warning(() -> "Definition of chardev " + chardev
|
||||||
|
+ " missing in runner template.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
super.configure(socketPath);
|
super.configure(socketPath);
|
||||||
this.channelId = channelId;
|
|
||||||
logger.fine(() -> getClass().getSimpleName() + " configured with"
|
logger.fine(() -> getClass().getSimpleName() + " configured with"
|
||||||
+ " channelId=" + channelId);
|
+ " channelId=" + channelId);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -192,7 +192,7 @@ import org.jgrapes.util.events.WatchFile;
|
||||||
*/
|
*/
|
||||||
@SuppressWarnings({ "PMD.ExcessiveImports", "PMD.AvoidPrintStackTrace",
|
@SuppressWarnings({ "PMD.ExcessiveImports", "PMD.AvoidPrintStackTrace",
|
||||||
"PMD.DataflowAnomalyAnalysis", "PMD.TooManyMethods",
|
"PMD.DataflowAnomalyAnalysis", "PMD.TooManyMethods",
|
||||||
"PMD.CouplingBetweenObjects", "PMD.TooManyFields", "PMD.GodClass" })
|
"PMD.CouplingBetweenObjects", "PMD.TooManyFields" })
|
||||||
public class Runner extends Component {
|
public class Runner extends Component {
|
||||||
|
|
||||||
private static final String QEMU = "qemu";
|
private static final String QEMU = "qemu";
|
||||||
|
|
@ -362,8 +362,10 @@ public class Runner extends Component {
|
||||||
// Forward some values to child components
|
// Forward some values to child components
|
||||||
qemuMonitor.configure(initialConfig.monitorSocket,
|
qemuMonitor.configure(initialConfig.monitorSocket,
|
||||||
initialConfig.vm.powerdownTimeout);
|
initialConfig.vm.powerdownTimeout);
|
||||||
configureAgentClient(guestAgentClient, "guest-agent-socket");
|
guestAgentClient.configure(qemuDefinition.command,
|
||||||
configureAgentClient(vmopAgentClient, "vmop-agent-socket");
|
"guest-agent-socket");
|
||||||
|
vmopAgentClient.configure(qemuDefinition.command,
|
||||||
|
"vmop-agent-socket");
|
||||||
} catch (IllegalArgumentException | IOException | TemplateException e) {
|
} catch (IllegalArgumentException | IOException | TemplateException e) {
|
||||||
logger.log(Level.SEVERE, e, () -> "Invalid configuration: "
|
logger.log(Level.SEVERE, e, () -> "Invalid configuration: "
|
||||||
+ e.getMessage());
|
+ e.getMessage());
|
||||||
|
|
@ -486,36 +488,6 @@ public class Runner extends Component {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("PMD.CognitiveComplexity")
|
|
||||||
private void configureAgentClient(AgentConnector client, String chardev) {
|
|
||||||
String id = null;
|
|
||||||
Path path = null;
|
|
||||||
for (var arg : qemuDefinition.command) {
|
|
||||||
if (arg.startsWith("virtserialport,")
|
|
||||||
&& arg.contains("chardev=" + chardev)) {
|
|
||||||
for (var prop : arg.split(",")) {
|
|
||||||
if (prop.startsWith("id=")) {
|
|
||||||
id = prop.substring(3);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (arg.startsWith("socket,")
|
|
||||||
&& arg.contains("id=" + chardev)) {
|
|
||||||
for (var prop : arg.split(",")) {
|
|
||||||
if (prop.startsWith("path=")) {
|
|
||||||
path = Path.of(prop.substring(5));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (id == null || path == null) {
|
|
||||||
logger.warning(() -> "Definition of chardev " + chardev
|
|
||||||
+ " missing in runner template.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
client.configure(id, path);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle the started event.
|
* Handle the started event.
|
||||||
*
|
*
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue