Feature/web gui2 (#16)
Some checks failed
Java CI with Gradle / build (push) Has been cancelled
Some checks failed
Java CI with Gradle / build (push) Has been cancelled
Add oveview and enhance.
This commit is contained in:
parent
8567a2f052
commit
6f45e7982a
32 changed files with 1382 additions and 250 deletions
|
|
@ -39,7 +39,7 @@ dependencies {
|
|||
|
||||
application {
|
||||
applicationName = 'vm-manager'
|
||||
applicationDefaultJvmArgs = ['-Xmx128m', '-XX:+UseParallelGC',
|
||||
applicationDefaultJvmArgs = ['-Xmx64m', '-XX:+UseParallelGC',
|
||||
'-Djava.util.logging.manager=org.jdrupes.vmoperator.util.LongLoggingManager'
|
||||
]
|
||||
// Define the main class for the application.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,3 @@
|
|||
<footer>
|
||||
Copyright © Michael N. Lipp 2023
|
||||
</footer>
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* VM-Operator
|
||||
* Copyright (C) 2023 Michael N. Lipp
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* 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
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.jdrupes.vmoperator.manager;
|
||||
|
||||
import java.io.IOException;
|
||||
import org.jgrapes.core.Channel;
|
||||
import org.jgrapes.core.Component;
|
||||
import org.jgrapes.core.annotation.Handler;
|
||||
import org.jgrapes.webconsole.base.Conlet;
|
||||
import org.jgrapes.webconsole.base.ConsoleConnection;
|
||||
import org.jgrapes.webconsole.base.events.AddConletRequest;
|
||||
import org.jgrapes.webconsole.base.events.ConsoleConfigured;
|
||||
import org.jgrapes.webconsole.base.events.ConsoleReady;
|
||||
import org.jgrapes.webconsole.base.events.RenderConlet;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public class AvoidEmptyPolicy extends Component {
|
||||
|
||||
private final String renderedFlagName = getClass().getName() + ".rendered";
|
||||
|
||||
/**
|
||||
* Creates a new component with its channel set to the given channel.
|
||||
*
|
||||
* @param componentChannel
|
||||
*/
|
||||
public AvoidEmptyPolicy(Channel componentChannel) {
|
||||
super(componentChannel);
|
||||
}
|
||||
|
||||
/**
|
||||
* On console ready.
|
||||
*
|
||||
* @param event the event
|
||||
* @param connection the connection
|
||||
*/
|
||||
@Handler
|
||||
public void onConsoleReady(ConsoleReady event,
|
||||
ConsoleConnection connection) {
|
||||
connection.session().put(renderedFlagName, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* On render conlet.
|
||||
*
|
||||
* @param event the event
|
||||
* @param connection the connection
|
||||
*/
|
||||
@Handler
|
||||
public void onRenderConlet(RenderConlet event,
|
||||
ConsoleConnection connection) {
|
||||
connection.session().put(renderedFlagName, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* On console configured.
|
||||
*
|
||||
* @param event the event
|
||||
* @param connection the console connection
|
||||
* @throws InterruptedException the interrupted exception
|
||||
*/
|
||||
@Handler
|
||||
public void onConsoleConfigured(ConsoleConfigured event,
|
||||
ConsoleConnection connection) throws InterruptedException,
|
||||
IOException {
|
||||
if ((Boolean) connection.session().getOrDefault(
|
||||
renderedFlagName, false)) {
|
||||
return;
|
||||
}
|
||||
fire(new AddConletRequest(event.event().event().renderSupport(),
|
||||
"org.jdrupes.vmoperator.vmconlet.VmConlet",
|
||||
Conlet.RenderMode
|
||||
.asSet(Conlet.RenderMode.Preview, Conlet.RenderMode.View)),
|
||||
connection);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -30,8 +30,7 @@ import java.util.logging.Level;
|
|||
import static org.jdrupes.vmoperator.common.Constants.VM_OP_GROUP;
|
||||
import static org.jdrupes.vmoperator.common.Constants.VM_OP_KIND_VM;
|
||||
import org.jdrupes.vmoperator.common.K8s;
|
||||
import org.jdrupes.vmoperator.manager.events.StartVm;
|
||||
import org.jdrupes.vmoperator.manager.events.StopVm;
|
||||
import org.jdrupes.vmoperator.manager.events.ModifyVm;
|
||||
import org.jdrupes.vmoperator.manager.events.VmDefChanged;
|
||||
import org.jgrapes.core.Channel;
|
||||
import org.jgrapes.core.Component;
|
||||
|
|
@ -152,30 +151,18 @@ public class Controller extends Component {
|
|||
}
|
||||
|
||||
/**
|
||||
* On start vm.
|
||||
* On modify vm.
|
||||
*
|
||||
* @param event the event
|
||||
* @throws ApiException the api exception
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
@Handler
|
||||
public void onStartVm(StartVm event) throws ApiException, IOException {
|
||||
patchRunning(event.name(), true);
|
||||
public void onModigyVm(ModifyVm event) throws ApiException, IOException {
|
||||
patchVmSpec(event.name(), event.path(), event.value());
|
||||
}
|
||||
|
||||
/**
|
||||
* On stop vm.
|
||||
*
|
||||
* @param event the event
|
||||
* @throws ApiException the api exception
|
||||
* @throws IOException Signals that an I/O exception has occurred.
|
||||
*/
|
||||
@Handler
|
||||
public void onStopVm(StopVm event) throws ApiException, IOException {
|
||||
patchRunning(event.name(), false);
|
||||
}
|
||||
|
||||
private void patchRunning(String name, boolean running)
|
||||
private void patchVmSpec(String name, String path, Object value)
|
||||
throws ApiException, IOException {
|
||||
var crApi = K8s.crApi(Config.defaultClient(), VM_OP_GROUP,
|
||||
VM_OP_KIND_VM, namespace, name);
|
||||
|
|
@ -188,12 +175,13 @@ public class Controller extends Component {
|
|||
// Patch running
|
||||
PatchOptions patchOpts = new PatchOptions();
|
||||
patchOpts.setFieldManager("kubernetes-java-kubectl-apply");
|
||||
String valueAsText = value instanceof String
|
||||
? "\"" + value + "\""
|
||||
: value.toString();
|
||||
var res = crApi.get().patch(namespace, name,
|
||||
V1Patch.PATCH_FORMAT_JSON_PATCH,
|
||||
new V1Patch("[{\"op\": \"replace\", \"path\": "
|
||||
+ "\"/spec/vm/state\", "
|
||||
+ "\"value\": \"" + (running ? "Running" : "Stopped")
|
||||
+ "\"}]"),
|
||||
new V1Patch("[{\"op\": \"replace\", \"path\": \"/spec/vm/"
|
||||
+ path + "\", \"value\": " + valueAsText + "}]"),
|
||||
patchOpts);
|
||||
if (!res.isSuccess()) {
|
||||
logger.warning(
|
||||
|
|
|
|||
|
|
@ -135,6 +135,7 @@ public class Manager extends Component {
|
|||
console.attach(new BrowserLocalBackedKVStore(
|
||||
console.channel(), consoleWeblet.prefix().getPath()));
|
||||
console.attach(new KVStoreBasedConsolePolicy(console.channel()));
|
||||
console.attach(new AvoidEmptyPolicy(console.channel()));
|
||||
console.attach(new RoleConfigurator(console.channel()));
|
||||
console.attach(new RoleConletFilter(console.channel()));
|
||||
console.attach(new LoginConlet(console.channel()));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue