🧑💻 Improve Formatter
This commit is contained in:
parent
c8ecdce0e0
commit
3799cf822f
@ -8,23 +8,23 @@ import jakarta.enterprise.context.ApplicationScoped;
|
|||||||
import io.quarkus.hibernate.orm.panache.PanacheRepositoryBase;
|
import io.quarkus.hibernate.orm.panache.PanacheRepositoryBase;
|
||||||
import io.quarkus.panache.common.Parameters;
|
import io.quarkus.panache.common.Parameters;
|
||||||
|
|
||||||
|
import dev.dinauer.metrics.service.model.Bucket;
|
||||||
import dev.dinauer.metrics.service.model.BucketUnit;
|
import dev.dinauer.metrics.service.model.BucketUnit;
|
||||||
import dev.dinauer.metrics.service.model.Collection;
|
|
||||||
|
|
||||||
@ApplicationScoped
|
@ApplicationScoped
|
||||||
public class Repo implements PanacheRepositoryBase<Collection, String>
|
public class Repo implements PanacheRepositoryBase<Bucket, String>
|
||||||
{
|
{
|
||||||
public Optional<Collection> findByProperties(String resource, String name, String timestamp, BucketUnit bucketUnit)
|
public Optional<Bucket> findByProperties(String resource, String name, String timestamp, BucketUnit bucketUnit)
|
||||||
{
|
{
|
||||||
return find("resource = :resource AND name = :name AND timestamp = :timestamp AND bucketUnit = :bucketUnit", Parameters.with("resource", resource).and("name", name).and("timestamp", timestamp).and("bucketUnit", bucketUnit)).firstResultOptional();
|
return find("resource = :resource AND name = :name AND timestamp = :timestamp AND bucketUnit = :bucketUnit", Parameters.with("resource", resource).and("name", name).and("timestamp", timestamp).and("bucketUnit", bucketUnit)).firstResultOptional();
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Collection> findByResourceAndMetricAndTimeUnit(String resource, String name, BucketUnit bucketUnit)
|
public List<Bucket> findByResourceAndMetricAndTimeUnit(String resource, String name, BucketUnit bucketUnit)
|
||||||
{
|
{
|
||||||
return list("resource = :resource AND name = :name AND bucketUnit = :bucketUnit ORDER BY timestamp ASC", Parameters.with("resource", resource).and("name", name).and("bucketUnit", bucketUnit));
|
return list("resource = :resource AND name = :name AND bucketUnit = :bucketUnit ORDER BY timestamp ASC", Parameters.with("resource", resource).and("name", name).and("bucketUnit", bucketUnit));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Collection> findByResourceAndMetricAndTimeUnitAndPeriod(String resource, String name, BucketUnit bucketUnit, Long from, Long to)
|
public List<Bucket> findByResourceAndMetricAndTimeUnitAndPeriod(String resource, String name, BucketUnit bucketUnit, Long from, Long to)
|
||||||
{
|
{
|
||||||
return list("resource = :resource AND name = :name AND bucketUnit = :bucketUnit AND (unix >= :from AND unix <= :to) ORDER BY timestamp ASC", Parameters.with("resource", resource).and("name", name).and("bucketUnit", bucketUnit).and("from", from).and("to", to));
|
return list("resource = :resource AND name = :name AND bucketUnit = :bucketUnit AND (unix >= :from AND unix <= :to) ORDER BY timestamp ASC", Parameters.with("resource", resource).and("name", name).and("bucketUnit", bucketUnit).and("from", from).and("to", to));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,8 +8,8 @@ import jakarta.inject.Inject;
|
|||||||
import jakarta.ws.rs.*;
|
import jakarta.ws.rs.*;
|
||||||
|
|
||||||
import dev.dinauer.metrics.service.client.auth.AuthenticationService;
|
import dev.dinauer.metrics.service.client.auth.AuthenticationService;
|
||||||
|
import dev.dinauer.metrics.service.model.Bucket;
|
||||||
import dev.dinauer.metrics.service.model.BucketUnit;
|
import dev.dinauer.metrics.service.model.BucketUnit;
|
||||||
import dev.dinauer.metrics.service.model.Collection;
|
|
||||||
|
|
||||||
@Path("/{resource}/{metric}")
|
@Path("/{resource}/{metric}")
|
||||||
public class Resource
|
public class Resource
|
||||||
@ -34,7 +34,7 @@ public class Resource
|
|||||||
}
|
}
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
public List<Collection> get(@PathParam("resource") String resource, @PathParam("metric") String metric, @QueryParam("bucket-unit") Optional<BucketUnit> bucketUnit)
|
public List<Bucket> get(@PathParam("resource") String resource, @PathParam("metric") String metric, @QueryParam("bucket-unit") Optional<BucketUnit> bucketUnit)
|
||||||
{
|
{
|
||||||
if (authenticationService.canRead())
|
if (authenticationService.canRead())
|
||||||
{
|
{
|
||||||
|
|||||||
@ -9,8 +9,8 @@ import jakarta.enterprise.context.ApplicationScoped;
|
|||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
import jakarta.transaction.Transactional;
|
import jakarta.transaction.Transactional;
|
||||||
|
|
||||||
|
import dev.dinauer.metrics.service.model.Bucket;
|
||||||
import dev.dinauer.metrics.service.model.BucketUnit;
|
import dev.dinauer.metrics.service.model.BucketUnit;
|
||||||
import dev.dinauer.metrics.service.model.Collection;
|
|
||||||
import dev.dinauer.metrics.service.utils.BucketConfigProvider;
|
import dev.dinauer.metrics.service.utils.BucketConfigProvider;
|
||||||
import dev.dinauer.metrics.service.utils.TimestampGenerator;
|
import dev.dinauer.metrics.service.utils.TimestampGenerator;
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ public class Service
|
|||||||
for (BucketUnit unit : bucketConfigProvider.get())
|
for (BucketUnit unit : bucketConfigProvider.get())
|
||||||
{
|
{
|
||||||
String timestamp = TimestampGenerator.generateTimestamp(now, unit);
|
String timestamp = TimestampGenerator.generateTimestamp(now, unit);
|
||||||
Collection metrics = repo.findByProperties(resource, metric, timestamp, unit).orElse(new Collection(resource, metric, timestamp, now.toEpochSecond(), unit));
|
Bucket metrics = repo.findByProperties(resource, metric, timestamp, unit).orElse(new Bucket(resource, metric, timestamp, now.toEpochSecond(), unit));
|
||||||
for (Map.Entry<String, Double> entry : values.entrySet())
|
for (Map.Entry<String, Double> entry : values.entrySet())
|
||||||
{
|
{
|
||||||
Double value = entry.getValue();
|
Double value = entry.getValue();
|
||||||
@ -47,7 +47,7 @@ public class Service
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Collection> get(String resource, String metric, BucketUnit unit)
|
public List<Bucket> get(String resource, String metric, BucketUnit unit)
|
||||||
{
|
{
|
||||||
return repo.findByResourceAndMetricAndTimeUnit(resource, metric, unit);
|
return repo.findByResourceAndMetricAndTimeUnit(resource, metric, unit);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,8 @@ package dev.dinauer.metrics.service.client;
|
|||||||
|
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
public record Client(String id, String password, Permission permission) {
|
public record Client(String id, String password, Permission permission)
|
||||||
|
{
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object object)
|
public boolean equals(Object object)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -44,10 +44,12 @@ public class AuthenticationService
|
|||||||
AuthHeader header = getAuthHeader();
|
AuthHeader header = getAuthHeader();
|
||||||
switch (header.type())
|
switch (header.type())
|
||||||
{
|
{
|
||||||
case BASIC -> {
|
case BASIC:
|
||||||
|
{
|
||||||
return basicAuthClientProvider.get(header.credentials());
|
return basicAuthClientProvider.get(header.credentials());
|
||||||
}
|
}
|
||||||
case BEARER -> {
|
case BEARER:
|
||||||
|
{
|
||||||
return bearerAuthClientProvider.get(header.credentials());
|
return bearerAuthClientProvider.get(header.credentials());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -65,7 +67,8 @@ public class AuthenticationService
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
return new AuthHeader(AuthType.valueOf(sections[0].toUpperCase()), sections[1]);
|
return new AuthHeader(AuthType.valueOf(sections[0].toUpperCase()), sections[1]);
|
||||||
} catch (IllegalArgumentException e)
|
}
|
||||||
|
catch (IllegalArgumentException e)
|
||||||
{
|
{
|
||||||
throw new UnauthorizedException();
|
throw new UnauthorizedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import java.util.Optional;
|
|||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
|
|
||||||
|
import jakarta.ws.rs.NotFoundException;
|
||||||
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||||
import org.eclipse.microprofile.jwt.JsonWebToken;
|
import org.eclipse.microprofile.jwt.JsonWebToken;
|
||||||
|
|
||||||
@ -36,9 +37,11 @@ public class BearerAuthClientProvider
|
|||||||
{
|
{
|
||||||
return new Client(user.get(), null, Permission.RO);
|
return new Client(user.get(), null, Permission.RO);
|
||||||
}
|
}
|
||||||
|
throw new NotFoundException();
|
||||||
}
|
}
|
||||||
throw new UnauthorizedException();
|
throw new UnauthorizedException();
|
||||||
} catch (ParseException e)
|
}
|
||||||
|
catch (ParseException e)
|
||||||
{
|
{
|
||||||
throw new UnauthorizedException();
|
throw new UnauthorizedException();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
package dev.dinauer.metrics.service.client.auth.utils;
|
package dev.dinauer.metrics.service.client.auth.utils;
|
||||||
|
|
||||||
public record AuthHeader(AuthType type, String credentials) {
|
public record AuthHeader(AuthType type, String credentials)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
@ -1,4 +1,5 @@
|
|||||||
package dev.dinauer.metrics.service.client.auth.utils;
|
package dev.dinauer.metrics.service.client.auth.utils;
|
||||||
|
|
||||||
public record BasicAuthCredentials(String clientId, String password) {
|
public record BasicAuthCredentials(String clientId, String password)
|
||||||
|
{
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,8 +14,8 @@ import com.fasterxml.jackson.core.type.TypeReference;
|
|||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "collection")
|
@Table(name = "bucket")
|
||||||
public class Collection
|
public class Bucket
|
||||||
{
|
{
|
||||||
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
|
||||||
|
|
||||||
@ -41,6 +41,8 @@ public class Collection
|
|||||||
@Column(columnDefinition = "text", nullable = false)
|
@Column(columnDefinition = "text", nullable = false)
|
||||||
private String metrics;
|
private String metrics;
|
||||||
|
|
||||||
|
private String owner;
|
||||||
|
|
||||||
@CreationTimestamp
|
@CreationTimestamp
|
||||||
@Column(name = "created_at", updatable = false)
|
@Column(name = "created_at", updatable = false)
|
||||||
private ZonedDateTime createdAt;
|
private ZonedDateTime createdAt;
|
||||||
@ -49,11 +51,11 @@ public class Collection
|
|||||||
@Column(name = "updated_at")
|
@Column(name = "updated_at")
|
||||||
private ZonedDateTime updatedAt;
|
private ZonedDateTime updatedAt;
|
||||||
|
|
||||||
public Collection()
|
public Bucket()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection(String resource, String name, String timestamp, long unixTimestamp, BucketUnit bucketUnit)
|
public Bucket(String resource, String name, String timestamp, long unixTimestamp, BucketUnit bucketUnit)
|
||||||
{
|
{
|
||||||
this.id = UUID.randomUUID().toString();
|
this.id = UUID.randomUUID().toString();
|
||||||
this.resource = resource;
|
this.resource = resource;
|
||||||
@ -86,7 +88,8 @@ public class Collection
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
this.metrics = OBJECT_MAPPER.writeValueAsString(metrics);
|
this.metrics = OBJECT_MAPPER.writeValueAsString(metrics);
|
||||||
} catch (JsonProcessingException e)
|
}
|
||||||
|
catch (JsonProcessingException e)
|
||||||
{
|
{
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -128,7 +131,8 @@ public class Collection
|
|||||||
return OBJECT_MAPPER.readValue(metrics, new TypeReference<Map<String, Metric>>()
|
return OBJECT_MAPPER.readValue(metrics, new TypeReference<Map<String, Metric>>()
|
||||||
{
|
{
|
||||||
});
|
});
|
||||||
} catch (JsonProcessingException e)
|
}
|
||||||
|
catch (JsonProcessingException e)
|
||||||
{
|
{
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@ -144,7 +148,7 @@ public class Collection
|
|||||||
return createdAt;
|
return createdAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection setCreatedAt(ZonedDateTime createdAt)
|
public Bucket setCreatedAt(ZonedDateTime createdAt)
|
||||||
{
|
{
|
||||||
this.createdAt = createdAt;
|
this.createdAt = createdAt;
|
||||||
return this;
|
return this;
|
||||||
@ -155,7 +159,7 @@ public class Collection
|
|||||||
return updatedAt;
|
return updatedAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Collection setUpdatedAt(ZonedDateTime updatedAt)
|
public Bucket setUpdatedAt(ZonedDateTime updatedAt)
|
||||||
{
|
{
|
||||||
this.updatedAt = updatedAt;
|
this.updatedAt = updatedAt;
|
||||||
return this;
|
return this;
|
||||||
Loading…
x
Reference in New Issue
Block a user