Feature/web gui (#12)

Basic GUI functions (start/stop).
This commit is contained in:
Michael N. Lipp 2023-10-21 22:16:10 +02:00 committed by GitHub
parent 6491742eb0
commit ae3941707a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
86 changed files with 12225 additions and 514 deletions

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<fileset-config file-format-version="1.2.0" simple-config="false" sync-formatter="false">
<local-check-config name="Project Checks" location="/VM-Operator/checkstyle.xml" type="project" description="">
<additional-data name="protect-config-file" value="false"/>
</local-check-config>
<fileset name="all" enabled="true" check-config-name="Project Checks" local="true">
<file-match-pattern match-pattern="." include-pattern="true"/>
</fileset>
</fileset-config>

View file

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<eclipse-pmd xmlns="http://acanda.ch/eclipse-pmd/0.8" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://acanda.ch/eclipse-pmd/0.8 http://acanda.ch/eclipse-pmd/eclipse-pmd-0.8.xsd">
<analysis enabled="true" />
<rulesets>
<ruleset name="Custom Rules" ref="moodle-tools-console/ruleset.xml" refcontext="workspace" />
</rulesets>
</eclipse-pmd>

View file

@ -0,0 +1,13 @@
arguments=
auto.sync=false
build.scans.enabled=false
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER)
connection.project.dir=..
eclipse.preferences.version=1
gradle.user.home=
java.home=
jvm.arguments=
offline.mode=false
override.workspace.settings=false
show.console.view=false
show.executions.view=false

View file

@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

View file

@ -0,0 +1,2 @@
eclipse.preferences.version=1
line.separator=\n

View file

@ -0,0 +1,14 @@
/*
* This file was generated by the Gradle 'init' task.
*
* This project uses @Incubating APIs which are subject to change.
*/
plugins {
id 'org.jdrupes.vmoperator.java-library-conventions'
}
dependencies {
api 'org.jgrapes:org.jgrapes.core:[1.19.0,2)'
api project(':org.jdrupes.vmoperator.common')
}

View file

@ -0,0 +1,52 @@
/*
* 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.events;
import org.jgrapes.core.Channel;
import org.jgrapes.core.Event;
/**
* Starts a VM.
*/
@SuppressWarnings("PMD.DataClass")
public class StartVm extends Event<Void> {
private final String name;
/**
* Instantiates a new start vm event.
*
* @param channels the channels
* @param name the name
*/
public StartVm(String name, Channel... channels) {
super(channels);
this.name = name;
}
/**
* Gets the name.
*
* @return the name
*/
public String name() {
return name;
}
}

View file

@ -0,0 +1,52 @@
/*
* 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.events;
import org.jgrapes.core.Channel;
import org.jgrapes.core.Event;
/**
* Stops a VM.
*/
@SuppressWarnings("PMD.DataClass")
public class StopVm extends Event<Void> {
private final String name;
/**
* Instantiates a new start vm event.
*
* @param channels the channels
* @param name the name
*/
public StopVm(String name, Channel... channels) {
super(channels);
this.name = name;
}
/**
* Gets the name.
*
* @return the name
*/
public String name() {
return name;
}
}

View file

@ -0,0 +1,115 @@
/*
* 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.events;
import io.kubernetes.client.openapi.ApiClient;
import io.kubernetes.client.util.generic.dynamic.DynamicKubernetesObject;
import org.jgrapes.core.Channel;
import org.jgrapes.core.EventPipeline;
import org.jgrapes.core.Subchannel.DefaultSubchannel;
/**
* A subchannel used to send the events related to a specific VM.
*/
@SuppressWarnings("PMD.DataClass")
public class VmChannel extends DefaultSubchannel {
private final EventPipeline pipeline;
private final ApiClient client;
private DynamicKubernetesObject vmDefinition;
private long generation = -1;
/**
* Instantiates a new watch channel.
*
* @param mainChannel the main channel
* @param pipeline the pipeline
* @param client the client
*/
public VmChannel(Channel mainChannel, EventPipeline pipeline,
ApiClient client) {
super(mainChannel);
this.pipeline = pipeline;
this.client = client;
}
/**
* Sets the last known definition of the resource.
*
* @param definition the definition
* @return the watch channel
*/
@SuppressWarnings("PMD.LinguisticNaming")
public VmChannel setVmDefinition(DynamicKubernetesObject definition) {
this.vmDefinition = definition;
return this;
}
/**
* Returns the last known definition of the VM.
*
* @return the json object
*/
public DynamicKubernetesObject vmDefinition() {
return vmDefinition;
}
/**
* Gets the last processed generation. Returns -1 if no
* definition has been processed yet.
*
* @return the generation
*/
public long generation() {
return generation;
}
/**
* Sets the last processed generation.
*
* @param generation the generation to set
* @return true if value has changed
*/
@SuppressWarnings("PMD.LinguisticNaming")
public boolean setGeneration(long generation) {
if (this.generation == generation) {
return false;
}
this.generation = generation;
return true;
}
/**
* Returns the pipeline.
*
* @return the event pipeline
*/
public EventPipeline pipeline() {
return pipeline;
}
/**
* Returns the API client.
*
* @return the API client
*/
public ApiClient client() {
return client;
}
}

View file

@ -0,0 +1,111 @@
/*
* 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.events;
import io.kubernetes.client.openapi.models.V1APIResource;
import io.kubernetes.client.util.generic.dynamic.DynamicKubernetesObject;
import org.jgrapes.core.Channel;
import org.jgrapes.core.Components;
import org.jgrapes.core.Event;
/**
* Indicates a change in a VM definition. Note that the definition
* consists of the metadata (mostly immutable), the "spec" and the
* "status" parts. Consumers that are only interested in "spec"
* changes should check {@link #specChanged()} before processing
* the event any further.
*/
@SuppressWarnings("PMD.DataClass")
public class VmDefChanged extends Event<Void> {
/**
* The type of change.
*/
public enum Type {
ADDED, MODIFIED, DELETED
}
private final Type type;
private final boolean specChanged;
private final V1APIResource crd;
private final DynamicKubernetesObject vmDef;
/**
* Instantiates a new VM changed event.
*
* @param type the type
* @param specChanged the spec part changed
* @param crd the crd
* @param vmDefinition the VM definition
*/
public VmDefChanged(Type type, boolean specChanged, V1APIResource crd,
DynamicKubernetesObject vmDefinition) {
this.type = type;
this.specChanged = specChanged;
this.crd = crd;
this.vmDef = vmDefinition;
}
/**
* Returns the type.
*
* @return the type
*/
public Type type() {
return type;
}
/**
* Indicates if the "spec" part changed.
*/
public boolean specChanged() {
return specChanged;
}
/**
* Returns the Crd.
*
* @return the v 1 API resource
*/
public V1APIResource crd() {
return crd;
}
/**
* Returns the object.
*
* @return the object.
*/
public DynamicKubernetesObject vmDefinition() {
return vmDef;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append(Components.objectName(this)).append(" [")
.append(vmDef.getMetadata().getName()).append(' ').append(type);
if (channels() != null) {
builder.append(", channels=");
builder.append(Channel.toString(channels()));
}
builder.append(']');
return builder.toString();
}
}

View file

@ -0,0 +1,25 @@
/*
* 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/>.
*/
/**
* Domain specific {@link org.jgrapes.core.Event}s (and
* {@link org.jgrapes.core.Channel}s) used to communicate between
* the core components of the {@link org.jgrapes.core.Manager} and
* "plugin" components such as the conlets.
*/
package org.jdrupes.vmoperator.manager.events;