Support for display secrets (#21)
Some checks failed
Java CI with Gradle / build (push) Has been cancelled
Some checks failed
Java CI with Gradle / build (push) Has been cancelled
This commit is contained in:
parent
85b0a160f3
commit
3103452170
38 changed files with 2081 additions and 658 deletions
|
|
@ -31,17 +31,16 @@ import java.math.BigInteger;
|
|||
import java.time.Duration;
|
||||
import java.time.Instant;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.jdrupes.json.JsonBeanDecoder;
|
||||
import org.jdrupes.json.JsonDecodeException;
|
||||
import org.jdrupes.vmoperator.common.K8sDynamicModel;
|
||||
import org.jdrupes.vmoperator.common.K8sObserver;
|
||||
import org.jdrupes.vmoperator.manager.events.ChannelCache;
|
||||
import org.jdrupes.vmoperator.manager.events.ModifyVm;
|
||||
import org.jdrupes.vmoperator.manager.events.VmChannel;
|
||||
import org.jdrupes.vmoperator.manager.events.VmDefChanged;
|
||||
import org.jdrupes.vmoperator.manager.events.VmDefChanged.Type;
|
||||
import org.jdrupes.vmoperator.util.GsonPtr;
|
||||
import org.jgrapes.core.Channel;
|
||||
import org.jgrapes.core.Event;
|
||||
|
|
@ -69,10 +68,8 @@ public class VmConlet extends FreeMarkerConlet<VmConlet.VmsModel> {
|
|||
|
||||
private static final Set<RenderMode> MODES = RenderMode.asSet(
|
||||
RenderMode.Preview, RenderMode.View);
|
||||
private final Map<String, K8sDynamicModel> vmInfos
|
||||
= new ConcurrentHashMap<>();
|
||||
private final Map<String, VmChannel> vmChannels
|
||||
= new ConcurrentHashMap<>();
|
||||
private final ChannelCache<String, VmChannel,
|
||||
K8sDynamicModel> channelManager = new ChannelCache<>();
|
||||
private final TimeSeries summarySeries = new TimeSeries(Duration.ofDays(1));
|
||||
private Summary cachedSummary;
|
||||
|
||||
|
|
@ -162,9 +159,10 @@ public class VmConlet extends FreeMarkerConlet<VmConlet.VmsModel> {
|
|||
sendVmInfos = true;
|
||||
}
|
||||
if (sendVmInfos) {
|
||||
for (var vmInfo : vmInfos.values()) {
|
||||
var def = JsonBeanDecoder.create(vmInfo.data().toString())
|
||||
.readObject();
|
||||
for (var vmDef : channelManager.associated()) {
|
||||
var def
|
||||
= JsonBeanDecoder.create(vmDef.data().toString())
|
||||
.readObject();
|
||||
channel.respond(new NotifyConletView(type(),
|
||||
conletId, "updateVm", def));
|
||||
}
|
||||
|
|
@ -187,9 +185,8 @@ public class VmConlet extends FreeMarkerConlet<VmConlet.VmsModel> {
|
|||
public void onVmDefChanged(VmDefChanged event, VmChannel channel)
|
||||
throws JsonDecodeException, IOException {
|
||||
var vmName = event.vmDefinition().getMetadata().getName();
|
||||
if (event.type() == Type.DELETED) {
|
||||
vmInfos.remove(vmName);
|
||||
vmChannels.remove(vmName);
|
||||
if (event.type() == K8sObserver.ResponseType.DELETED) {
|
||||
channelManager.remove(vmName);
|
||||
for (var entry : conletIdsByConsoleConnection().entrySet()) {
|
||||
for (String conletId : entry.getValue()) {
|
||||
entry.getKey().respond(new NotifyConletView(type(),
|
||||
|
|
@ -199,8 +196,7 @@ public class VmConlet extends FreeMarkerConlet<VmConlet.VmsModel> {
|
|||
} else {
|
||||
var vmDef = new K8sDynamicModel(channel.client().getJSON()
|
||||
.getGson(), convertQuantities(event.vmDefinition().data()));
|
||||
vmInfos.put(vmName, vmDef);
|
||||
vmChannels.put(vmName, channel);
|
||||
channelManager.put(vmName, channel, vmDef);
|
||||
var def = JsonBeanDecoder.create(vmDef.data().toString())
|
||||
.readObject();
|
||||
for (var entry : conletIdsByConsoleConnection().entrySet()) {
|
||||
|
|
@ -323,7 +319,7 @@ public class VmConlet extends FreeMarkerConlet<VmConlet.VmsModel> {
|
|||
return cachedSummary;
|
||||
}
|
||||
Summary summary = new Summary();
|
||||
for (var vmDef : vmInfos.values()) {
|
||||
for (var vmDef : channelManager.associated()) {
|
||||
summary.totalVms += 1;
|
||||
var status = GsonPtr.to(vmDef.data()).to("status");
|
||||
summary.usedCpus += status.getAsInt("cpus").orElse(0);
|
||||
|
|
@ -349,7 +345,7 @@ public class VmConlet extends FreeMarkerConlet<VmConlet.VmsModel> {
|
|||
throws Exception {
|
||||
event.stop();
|
||||
var vmName = event.params().asString(0);
|
||||
var vmChannel = vmChannels.get(vmName);
|
||||
var vmChannel = channelManager.channel(vmName).orElse(null);
|
||||
if (vmChannel == null) {
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue