🎨 Format
This commit is contained in:
parent
16a5627b39
commit
e165df6076
18
pom.xml
18
pom.xml
@ -163,6 +163,24 @@
|
|||||||
</systemPropertyVariables>
|
</systemPropertyVariables>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>net.revelc.code.formatter</groupId>
|
||||||
|
<artifactId>formatter-maven-plugin</artifactId>
|
||||||
|
<version>2.29.0</version>
|
||||||
|
<configuration>
|
||||||
|
<configFile>https://git.dinauer.dev/andreas.dinauer/formatter/raw/branch/main/format.xml</configFile>
|
||||||
|
<lineEnding>LF</lineEnding>
|
||||||
|
<encoding>UTF-8</encoding>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<phase>validate</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>validate</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>net.revelc.code</groupId>
|
<groupId>net.revelc.code</groupId>
|
||||||
<artifactId>impsort-maven-plugin</artifactId>
|
<artifactId>impsort-maven-plugin</artifactId>
|
||||||
|
|||||||
@ -101,44 +101,34 @@ public class ResourceResource
|
|||||||
{
|
{
|
||||||
switch (resourceType)
|
switch (resourceType)
|
||||||
{
|
{
|
||||||
case ResourceType.STATEFUL_SET ->
|
case ResourceType.STATEFUL_SET -> {
|
||||||
{
|
|
||||||
return statefulSetService;
|
return statefulSetService;
|
||||||
}
|
}
|
||||||
case ResourceType.DEPLOYMENT ->
|
case ResourceType.DEPLOYMENT -> {
|
||||||
{
|
|
||||||
return deploymentService;
|
return deploymentService;
|
||||||
}
|
}
|
||||||
case ResourceType.SERVICE ->
|
case ResourceType.SERVICE -> {
|
||||||
{
|
|
||||||
return serviceService;
|
return serviceService;
|
||||||
}
|
}
|
||||||
case ResourceType.INGRESS ->
|
case ResourceType.INGRESS -> {
|
||||||
{
|
|
||||||
return ingressService;
|
return ingressService;
|
||||||
}
|
}
|
||||||
case ResourceType.POD ->
|
case ResourceType.POD -> {
|
||||||
{
|
|
||||||
return podService;
|
return podService;
|
||||||
}
|
}
|
||||||
case ResourceType.CUSTOM_RESOURCE_DEFINITION ->
|
case ResourceType.CUSTOM_RESOURCE_DEFINITION -> {
|
||||||
{
|
|
||||||
return customResourceDefinitionService;
|
return customResourceDefinitionService;
|
||||||
}
|
}
|
||||||
case ResourceType.NODE ->
|
case ResourceType.NODE -> {
|
||||||
{
|
|
||||||
return nodeService;
|
return nodeService;
|
||||||
}
|
}
|
||||||
case ResourceType.SECRET ->
|
case ResourceType.SECRET -> {
|
||||||
{
|
|
||||||
return secretService;
|
return secretService;
|
||||||
}
|
}
|
||||||
case ResourceType.CONFIG_MAP ->
|
case ResourceType.CONFIG_MAP -> {
|
||||||
{
|
|
||||||
return configMapService;
|
return configMapService;
|
||||||
}
|
}
|
||||||
default ->
|
default -> {
|
||||||
{
|
|
||||||
LOG.errorf("Invalid resource type %s.", resourceType);
|
LOG.errorf("Invalid resource type %s.", resourceType);
|
||||||
throw new BadRequestException();
|
throw new BadRequestException();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,36 +3,33 @@ package dev.dinauer;
|
|||||||
public enum ResourceType
|
public enum ResourceType
|
||||||
{
|
{
|
||||||
// Cluster Resources
|
// Cluster Resources
|
||||||
NODE("nodes"),
|
NODE("nodes"), NAMESPACE("namespaces"), CUSTOM_RESOURCE_DEFINITION("custom-resource-definitions"),
|
||||||
NAMESPACE("namespaces"),
|
|
||||||
CUSTOM_RESOURCE_DEFINITION("custom-resource-definitions"),
|
|
||||||
|
|
||||||
// Workloads
|
// Workloads
|
||||||
STATEFUL_SET("stateful-sets"),
|
STATEFUL_SET("stateful-sets"), DEPLOYMENT("deployments"), POD("pods"),
|
||||||
DEPLOYMENT("deployments"),
|
|
||||||
POD("pods"),
|
|
||||||
|
|
||||||
// Networking
|
// Networking
|
||||||
SERVICE("services"),
|
SERVICE("services"), INGRESS("ingresses"),
|
||||||
INGRESS("ingresses"),
|
|
||||||
|
|
||||||
// Config
|
// Config
|
||||||
SECRET("secrets"),
|
SECRET("secrets"), CONFIG_MAP("config-maps"),
|
||||||
CONFIG_MAP("config-maps"),
|
|
||||||
|
|
||||||
// Storage
|
// Storage
|
||||||
PVC("pvcs"),
|
PVC("pvcs"), PV("pvs");
|
||||||
PV("pvs");
|
|
||||||
|
|
||||||
private final String value;
|
private final String value;
|
||||||
|
|
||||||
ResourceType(String value) {
|
ResourceType(String value)
|
||||||
|
{
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ResourceType fromString(String text) {
|
public static ResourceType fromString(String text)
|
||||||
for (ResourceType type : ResourceType.values()) {
|
{
|
||||||
if (type.value.equalsIgnoreCase(text)) {
|
for (ResourceType type : ResourceType.values())
|
||||||
|
{
|
||||||
|
if (type.value.equalsIgnoreCase(text))
|
||||||
|
{
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -40,7 +37,8 @@ public enum ResourceType
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString()
|
||||||
|
{
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -49,8 +49,7 @@ public class ResourceWebsocket
|
|||||||
ResourceType resourceType = ResourceType.fromString(rawResourceType);
|
ResourceType resourceType = ResourceType.fromString(rawResourceType);
|
||||||
if (tokenService.validateTokenByQueryString(session.getQueryString()))
|
if (tokenService.validateTokenByQueryString(session.getQueryString()))
|
||||||
{
|
{
|
||||||
executor.submit(() ->
|
executor.submit(() -> {
|
||||||
{
|
|
||||||
ResourceService<?> service = serviceFactory.getService(resourceType);
|
ResourceService<?> service = serviceFactory.getService(resourceType);
|
||||||
send(session, EventType.INIT, service.findByNamespace(namespace));
|
send(session, EventType.INIT, service.findByNamespace(namespace));
|
||||||
sessions.put(session, service.watch(namespace, getWatcher(session)));
|
sessions.put(session, service.watch(namespace, getWatcher(session)));
|
||||||
|
|||||||
@ -55,55 +55,55 @@ public class ServiceFactory
|
|||||||
{
|
{
|
||||||
switch (resourceType)
|
switch (resourceType)
|
||||||
{
|
{
|
||||||
case ResourceType.STATEFUL_SET ->
|
case ResourceType.STATEFUL_SET:
|
||||||
{
|
{
|
||||||
return statefulSetService;
|
return statefulSetService;
|
||||||
}
|
}
|
||||||
case ResourceType.DEPLOYMENT ->
|
case ResourceType.DEPLOYMENT:
|
||||||
{
|
{
|
||||||
return deploymentService;
|
return deploymentService;
|
||||||
}
|
}
|
||||||
case ResourceType.SERVICE ->
|
case ResourceType.SERVICE:
|
||||||
{
|
{
|
||||||
return serviceService;
|
return serviceService;
|
||||||
}
|
}
|
||||||
case ResourceType.INGRESS ->
|
case ResourceType.INGRESS:
|
||||||
{
|
{
|
||||||
return ingressService;
|
return ingressService;
|
||||||
}
|
}
|
||||||
case ResourceType.POD ->
|
case ResourceType.POD:
|
||||||
{
|
{
|
||||||
return podService;
|
return podService;
|
||||||
}
|
}
|
||||||
case ResourceType.CUSTOM_RESOURCE_DEFINITION ->
|
case ResourceType.CUSTOM_RESOURCE_DEFINITION:
|
||||||
{
|
{
|
||||||
return customResourceDefinitionService;
|
return customResourceDefinitionService;
|
||||||
}
|
}
|
||||||
case ResourceType.NODE ->
|
case ResourceType.NODE:
|
||||||
{
|
{
|
||||||
return nodeService;
|
return nodeService;
|
||||||
}
|
}
|
||||||
case ResourceType.SECRET ->
|
case ResourceType.SECRET:
|
||||||
{
|
{
|
||||||
return secretService;
|
return secretService;
|
||||||
}
|
}
|
||||||
case ResourceType.CONFIG_MAP ->
|
case ResourceType.CONFIG_MAP:
|
||||||
{
|
{
|
||||||
return configMapService;
|
return configMapService;
|
||||||
}
|
}
|
||||||
case ResourceType.PVC ->
|
case ResourceType.PVC:
|
||||||
{
|
{
|
||||||
return pvcService;
|
return pvcService;
|
||||||
}
|
}
|
||||||
case ResourceType.PV ->
|
case ResourceType.PV:
|
||||||
{
|
{
|
||||||
return pvService;
|
return pvService;
|
||||||
}
|
}
|
||||||
case ResourceType.NAMESPACE ->
|
case ResourceType.NAMESPACE:
|
||||||
{
|
{
|
||||||
return namespaceService;
|
return namespaceService;
|
||||||
}
|
}
|
||||||
default ->
|
default :
|
||||||
{
|
{
|
||||||
LOG.errorf("Invalid resource type %s.", resourceType);
|
LOG.errorf("Invalid resource type %s.", resourceType);
|
||||||
throw new BadRequestException();
|
throw new BadRequestException();
|
||||||
|
|||||||
@ -35,11 +35,7 @@ public class LoginResource
|
|||||||
UserEntity user = userOptional.get();
|
UserEntity user = userOptional.get();
|
||||||
if (BcryptUtil.matches(login.password(), user.getPassword()))
|
if (BcryptUtil.matches(login.password(), user.getPassword()))
|
||||||
{
|
{
|
||||||
return Jwt
|
return Jwt.upn(user.getId()).expiresAt(ZonedDateTime.now().plusDays(15).toInstant()).groups(user.getRoles()).sign();
|
||||||
.upn(user.getId())
|
|
||||||
.expiresAt(ZonedDateTime.now().plusDays(15).toInstant())
|
|
||||||
.groups(user.getRoles())
|
|
||||||
.sign();
|
|
||||||
}
|
}
|
||||||
LOG.info("Cannot access user. Forbidden");
|
LOG.info("Cannot access user. Forbidden");
|
||||||
throw new ForbiddenException(Response.status(403).type(MediaType.TEXT_PLAIN).entity("wrong_password").build());
|
throw new ForbiddenException(Response.status(403).type(MediaType.TEXT_PLAIN).entity("wrong_password").build());
|
||||||
|
|||||||
@ -52,7 +52,8 @@ public class UserResource
|
|||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@Transactional
|
@Transactional
|
||||||
@RolesAllowed({"ADMIN", "OWNER"})
|
@RolesAllowed(
|
||||||
|
{"ADMIN", "OWNER"})
|
||||||
public void createUser(UserCreation user)
|
public void createUser(UserCreation user)
|
||||||
{
|
{
|
||||||
if (List.of("ADMIN", "USER").contains(user.role()))
|
if (List.of("ADMIN", "USER").contains(user.role()))
|
||||||
|
|||||||
@ -91,14 +91,17 @@ public class MonitoringJobRunner
|
|||||||
LOG.infof("Running %s %s monitoring.", config.getConfigName(), config.getType().toString().toLowerCase());
|
LOG.infof("Running %s %s monitoring.", config.getConfigName(), config.getType().toString().toLowerCase());
|
||||||
switch (config.getType())
|
switch (config.getType())
|
||||||
{
|
{
|
||||||
case VOLUME ->
|
case VOLUME:
|
||||||
{
|
{
|
||||||
volumeMonitoringJobRunner.run(config);
|
volumeMonitoringJobRunner.run(config);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
case WORKLOAD ->
|
case WORKLOAD:
|
||||||
{
|
{
|
||||||
memoryMonitoringJobRunner.run(config);
|
memoryMonitoringJobRunner.run(config);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
throw new RuntimeException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -55,7 +55,7 @@ public class MonitoringResource
|
|||||||
|
|
||||||
switch (configCreation.type())
|
switch (configCreation.type())
|
||||||
{
|
{
|
||||||
case MonitoringType.VOLUME ->
|
case MonitoringType.VOLUME:
|
||||||
{
|
{
|
||||||
VolumeConfig volumeConfig = new VolumeConfig();
|
VolumeConfig volumeConfig = new VolumeConfig();
|
||||||
volumeConfig.setId(UUID.randomUUID().toString());
|
volumeConfig.setId(UUID.randomUUID().toString());
|
||||||
|
|||||||
@ -24,12 +24,10 @@ public class MonitoringService
|
|||||||
TargetConfig targetConfig = config.getTargetConfig();
|
TargetConfig targetConfig = config.getTargetConfig();
|
||||||
switch (targetConfig.getType())
|
switch (targetConfig.getType())
|
||||||
{
|
{
|
||||||
case LABEL ->
|
case LABEL -> {
|
||||||
{
|
|
||||||
return podService.findByNamespaceAndLabels(targetConfig.getNamespace(), targetConfig.getLabels()).stream().filter(pod -> pod.getStatus().getPhase().equals("Running")).toList();
|
return podService.findByNamespaceAndLabels(targetConfig.getNamespace(), targetConfig.getLabels()).stream().filter(pod -> pod.getStatus().getPhase().equals("Running")).toList();
|
||||||
}
|
}
|
||||||
case DEPLOYMENT, STATEFUL_SET ->
|
case DEPLOYMENT, STATEFUL_SET -> {
|
||||||
{
|
|
||||||
throw new NotImplementedYet();
|
throw new NotImplementedYet();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,5 @@ package dev.dinauer.monitoring.entity;
|
|||||||
|
|
||||||
public enum MonitoringTargetType
|
public enum MonitoringTargetType
|
||||||
{
|
{
|
||||||
DEPLOYMENT,
|
DEPLOYMENT, STATEFUL_SET, LABEL
|
||||||
STATEFUL_SET,
|
|
||||||
LABEL
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -97,7 +97,9 @@ public class TargetConfig
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
return OBJECT_MAPPER.readValue(labels, new TypeReference<Map<String, String>>() {});
|
return OBJECT_MAPPER.readValue(labels, new TypeReference<Map<String, String>>()
|
||||||
|
{
|
||||||
|
});
|
||||||
}
|
}
|
||||||
catch (JsonProcessingException e)
|
catch (JsonProcessingException e)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -2,10 +2,6 @@ package dev.dinauer.monitoring.entity.creation;
|
|||||||
|
|
||||||
import dev.dinauer.monitoring.entity.MonitoringType;
|
import dev.dinauer.monitoring.entity.MonitoringType;
|
||||||
|
|
||||||
public record MonitoringConfigCreation(
|
public record MonitoringConfigCreation(String configName, MonitoringType type, String interval, VolumeConfigCreation volumeConfig, MonitoringTargetConfigCreation targetConfig)
|
||||||
String configName,
|
{
|
||||||
MonitoringType type,
|
}
|
||||||
String interval,
|
|
||||||
VolumeConfigCreation volumeConfig,
|
|
||||||
MonitoringTargetConfigCreation targetConfig
|
|
||||||
) {}
|
|
||||||
@ -2,11 +2,6 @@ package dev.dinauer.monitoring.entity.creation;
|
|||||||
|
|
||||||
import dev.dinauer.monitoring.entity.MonitoringTargetType;
|
import dev.dinauer.monitoring.entity.MonitoringTargetType;
|
||||||
|
|
||||||
public record MonitoringTargetConfigCreation(
|
public record MonitoringTargetConfigCreation(MonitoringTargetType type, String namespace, String deploymentName, String statefulSetName, String labelKey, String labelValue)
|
||||||
MonitoringTargetType type,
|
{
|
||||||
String namespace,
|
}
|
||||||
String deploymentName,
|
|
||||||
String statefulSetName,
|
|
||||||
String labelKey,
|
|
||||||
String labelValue
|
|
||||||
) {}
|
|
||||||
@ -1,6 +1,5 @@
|
|||||||
package dev.dinauer.monitoring.entity.creation;
|
package dev.dinauer.monitoring.entity.creation;
|
||||||
|
|
||||||
public record VolumeConfigCreation(
|
public record VolumeConfigCreation(String mountPath, String containerName)
|
||||||
String mountPath,
|
{
|
||||||
String containerName
|
}
|
||||||
) {}
|
|
||||||
|
|||||||
@ -28,15 +28,7 @@ public class NodeMonitoringService
|
|||||||
for (MonitoredNode node : nodes)
|
for (MonitoredNode node : nodes)
|
||||||
{
|
{
|
||||||
NodeMetrics nodeMetrics = node.getMetrics();
|
NodeMetrics nodeMetrics = node.getMetrics();
|
||||||
Map<String, Number> metrics = Stream.of(
|
Map<String, Number> metrics = Stream.of(new AbstractMap.SimpleEntry<>("RELATIVE_CPU", nodeMetrics.relativeCpuUsage()), new AbstractMap.SimpleEntry<>("RELATIVE_MEMORY", nodeMetrics.relativeMemory()), new AbstractMap.SimpleEntry<>("ABSOLUTE_MEMORY", nodeMetrics.absoluteMemory()), new AbstractMap.SimpleEntry<>("ABSOLUTE_CPU", nodeMetrics.absoluteCpuUsage()), new AbstractMap.SimpleEntry<>("RELATIVE_DISK_SPACE", nodeMetrics.relativeDiskUsage()), new AbstractMap.SimpleEntry<>("TOTAL_DISK_SPACE", nodeMetrics.totalDiskSpace())).filter(entry -> entry.getValue() != null).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
||||||
new AbstractMap.SimpleEntry<>("RELATIVE_CPU", nodeMetrics.relativeCpuUsage()),
|
|
||||||
new AbstractMap.SimpleEntry<>("RELATIVE_MEMORY", nodeMetrics.relativeMemory()),
|
|
||||||
new AbstractMap.SimpleEntry<>("ABSOLUTE_MEMORY", nodeMetrics.absoluteMemory()),
|
|
||||||
new AbstractMap.SimpleEntry<>("ABSOLUTE_CPU", nodeMetrics.absoluteCpuUsage()),
|
|
||||||
new AbstractMap.SimpleEntry<>("RELATIVE_DISK_SPACE", nodeMetrics.relativeDiskUsage()),
|
|
||||||
new AbstractMap.SimpleEntry<>("TOTAL_DISK_SPACE", nodeMetrics.totalDiskSpace()))
|
|
||||||
.filter(entry -> entry.getValue() != null)
|
|
||||||
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
|
|
||||||
|
|
||||||
bigBucketService.index(String.format("NODE-%s", node.getMetadata().getUid()), "NODE_METRICS", metrics);
|
bigBucketService.index(String.format("NODE-%s", node.getMetadata().getUid()), "NODE_METRICS", metrics);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -10,20 +10,16 @@ public class Duration
|
|||||||
long value = Long.parseLong(input.substring(0, input.length() - 1));
|
long value = Long.parseLong(input.substring(0, input.length() - 1));
|
||||||
switch (unit)
|
switch (unit)
|
||||||
{
|
{
|
||||||
case 's' ->
|
case 's' -> {
|
||||||
{
|
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
case 'm' ->
|
case 'm' -> {
|
||||||
{
|
|
||||||
return value * 60;
|
return value * 60;
|
||||||
}
|
}
|
||||||
case 'h' ->
|
case 'h' -> {
|
||||||
{
|
|
||||||
return value * 60 * 60;
|
return value * 60 * 60;
|
||||||
}
|
}
|
||||||
default ->
|
default -> {
|
||||||
{
|
|
||||||
throw new IllegalArgumentException(String.format("Invalid unit %s", unit));
|
throw new IllegalArgumentException(String.format("Invalid unit %s", unit));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -63,7 +63,8 @@ public class DeploymentService implements ResourceService<Deployment>
|
|||||||
@Override
|
@Override
|
||||||
public Watch watch(String namespace, Watcher<Deployment> watcher)
|
public Watch watch(String namespace, Watcher<Deployment> watcher)
|
||||||
{
|
{
|
||||||
try (AppsAPIGroupDSL dsl = clientProvider.getClient().apps()) {
|
try (AppsAPIGroupDSL dsl = clientProvider.getClient().apps())
|
||||||
|
{
|
||||||
String version = dsl.deployments().inAnyNamespace().list().getMetadata().getResourceVersion();
|
String version = dsl.deployments().inAnyNamespace().list().getMetadata().getResourceVersion();
|
||||||
if (namespace.equals("_all"))
|
if (namespace.equals("_all"))
|
||||||
{
|
{
|
||||||
|
|||||||
@ -28,11 +28,7 @@ public class PodService implements ResourceService<Pod>
|
|||||||
if (podOptional.isPresent())
|
if (podOptional.isPresent())
|
||||||
{
|
{
|
||||||
Pod pod = podOptional.get();
|
Pod pod = podOptional.get();
|
||||||
clientProvider.getClient()
|
clientProvider.getClient().pods().inNamespace(pod.getMetadata().getNamespace()).withName(pod.getMetadata().getName()).delete();
|
||||||
.pods()
|
|
||||||
.inNamespace(pod.getMetadata().getNamespace())
|
|
||||||
.withName(pod.getMetadata().getName())
|
|
||||||
.delete();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -62,7 +62,8 @@ public class StatefulSetService implements ResourceService<StatefulSet>
|
|||||||
@Override
|
@Override
|
||||||
public Watch watch(String namespace, Watcher<StatefulSet> watcher)
|
public Watch watch(String namespace, Watcher<StatefulSet> watcher)
|
||||||
{
|
{
|
||||||
try (AppsAPIGroupDSL dsl = clientProvider.getClient().apps()) {
|
try (AppsAPIGroupDSL dsl = clientProvider.getClient().apps())
|
||||||
|
{
|
||||||
String version = dsl.statefulSets().inAnyNamespace().list().getMetadata().getResourceVersion();
|
String version = dsl.statefulSets().inAnyNamespace().list().getMetadata().getResourceVersion();
|
||||||
if (namespace.equals("_all"))
|
if (namespace.equals("_all"))
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user