use of io.stackgres.apiweb.dto.cluster.ClusterDto in project stackgres by ongres.
the class ClusterResourceQuarkusTest method givenACreationWithSecretAndConfigMapScripts_shouldNotFail.
@Test
void givenACreationWithSecretAndConfigMapScripts_shouldNotFail() {
ClusterDto cluster = getClusterInlineScripts();
ClusterScriptEntry secretScriptEntry = getSecretScriptEntry();
ClusterScriptEntry configMapScriptEntry = getConfigMapScriptEntry();
cluster.getSpec().getInitData().setScripts(ImmutableList.of(secretScriptEntry, configMapScriptEntry));
final Metadata metadata = cluster.getMetadata();
metadata.setNamespace("test");
given().header(AUTHENTICATION_HEADER).body(cluster).contentType(ContentType.JSON).accept(ContentType.JSON).post("/stackgres/sgclusters").then().statusCode(204);
try (KubernetesClient client = factory.create()) {
final ClusterScriptFrom secretScriptFrom = secretScriptEntry.getScriptFrom();
final SecretKeySelector secretKeyRef = secretScriptFrom.getSecretKeyRef();
Secret secret = client.secrets().inNamespace("test").withName(secretKeyRef.getName()).get();
assertNotNull(secret);
byte[] actualScript = Base64.getDecoder().decode(secret.getData().get(secretKeyRef.getKey()));
assertEquals(secretScriptFrom.getSecretScript(), new String(actualScript, StandardCharsets.UTF_8));
final ClusterScriptFrom configMapScriptFrom = configMapScriptEntry.getScriptFrom();
final ConfigMapKeySelector configMapKeyRef = configMapScriptFrom.getConfigMapKeyRef();
ConfigMap configMap = client.configMaps().inNamespace("test").withName(configMapKeyRef.getName()).get();
assertNotNull(configMap);
assertEquals(configMapScriptFrom.getConfigMapScript(), configMap.getData().get(configMapKeyRef.getKey()));
}
}
use of io.stackgres.apiweb.dto.cluster.ClusterDto in project stackgres by ongres.
the class ClusterResourceQuarkusTest method givenACreationWithInlineScripts_shouldNotFail.
@Test
void givenACreationWithInlineScripts_shouldNotFail() {
ClusterDto cluster = getClusterInlineScripts();
final Metadata metadata = cluster.getMetadata();
metadata.setNamespace("test");
given().header(AUTHENTICATION_HEADER).body(cluster).contentType(ContentType.JSON).accept(ContentType.JSON).post("/stackgres/sgclusters").then().statusCode(204);
}
use of io.stackgres.apiweb.dto.cluster.ClusterDto in project stackgres by ongres.
the class NamespacedClusterLogsResource method logs.
/**
* Query distributed logs and return a list of {@code ClusterLogEntry}.
*/
@Operation(responses = { @ApiResponse(responseCode = "200", description = "OK", content = { @Content(mediaType = "application/json", array = @ArraySchema(schema = @Schema(implementation = ClusterLogEntryDto.class))) }) })
@CommonApiResponses
@GET
@Path("{name}/logs")
public List<ClusterLogEntryDto> logs(@PathParam("namespace") String namespace, @PathParam("name") String name, @QueryParam("records") Integer records, @QueryParam("from") String from, @QueryParam("to") String to, @QueryParam("sort") String sort, @QueryParam("text") String text, @QueryParam("logType") List<String> logType, @QueryParam("podName") List<String> podName, @QueryParam("role") List<String> role, @QueryParam("errorLevel") List<String> errorLevel, @QueryParam("userName") List<String> userName, @QueryParam("databaseName") List<String> databaseName, @QueryParam("fromInclusive") Boolean fromInclusive) {
final ClusterDto cluster = clusterFinder.findByNameAndNamespace(name, namespace).orElseThrow(NotFoundException::new);
final int calculatedRecords = records != null ? records : 50;
if (calculatedRecords <= 0) {
throw new BadRequestException("records should be a positive number");
}
final Optional<Tuple2<Instant, Integer>> fromTuple;
final Optional<Tuple2<Instant, Integer>> toTuple;
if (!Optional.ofNullable(cluster.getSpec()).map(ClusterSpec::getDistributedLogs).map(ClusterDistributedLogs::getDistributedLogs).isPresent()) {
throw new BadRequestException("Distributed logs are not configured for specified cluster");
}
final var filters = ImmutableMap.<String, ImmutableList<String>>builder();
addFilter("logType", logType, filters);
addFilter("podName", podName, filters);
addFilter("role", role, filters);
addFilter("errorLevel", errorLevel, filters);
addFilter("userName", userName, filters);
addFilter("databaseName", databaseName, filters);
try {
fromTuple = Optional.ofNullable(from).map(s -> s.split(",")).map(ss -> Tuple.tuple(ss[0], ss.length > 1 ? ss[1] : String.valueOf(Integer.valueOf(0)))).map(t -> t.map1(Instant::parse)).map(t -> t.map2(Integer::valueOf));
} catch (Exception ex) {
throw new BadRequestException("from should be a timestamp" + " or a timestamp and an index separated by character ','", ex);
}
try {
toTuple = Optional.ofNullable(to).map(s -> s.split(",")).map(ss -> Tuple.tuple(ss[0], ss.length > 1 ? ss[1] : String.valueOf(Integer.MAX_VALUE))).map(t -> t.map1(Instant::parse)).map(t -> t.map2(Integer::valueOf));
} catch (Exception ex) {
throw new BadRequestException("to should be a timestamp" + " or a timestamp and an index separated by character ','", ex);
}
if (sort != null && !sort.equals("asc") && !sort.equals("desc")) {
throw new BadRequestException("sort only accept asc or desc values");
}
DistributedLogsQueryParameters logs = ImmutableDistributedLogsQueryParameters.builder().cluster(cluster).records(calculatedRecords).fromTimeAndIndex(fromTuple).toTimeAndIndex(toTuple).filters(filters.build()).isSortAsc(Objects.equals("asc", sort)).fullTextSearchQuery(Optional.ofNullable(text).map(FullTextSearchQuery::new)).isFromInclusive(fromInclusive != null && fromInclusive).build();
return distributedLogsFetcher.logs(logs);
}
use of io.stackgres.apiweb.dto.cluster.ClusterDto in project stackgres by ongres.
the class ClusterResourceQuarkusTest method givenACreationWithConfigMapsScripts_shouldNotFail.
@Test
void givenACreationWithConfigMapsScripts_shouldNotFail() {
ClusterDto cluster = getClusterInlineScripts();
ClusterScriptEntry entry = getConfigMapScriptEntry();
cluster.getSpec().getInitData().setScripts(Collections.singletonList(entry));
final Metadata metadata = cluster.getMetadata();
metadata.setNamespace("test");
given().header(AUTHENTICATION_HEADER).body(cluster).contentType(ContentType.JSON).accept(ContentType.JSON).post("/stackgres/sgclusters").then().statusCode(204);
try (KubernetesClient client = factory.create()) {
ConfigMap configMap = client.configMaps().inNamespace("test").withName(entry.getScriptFrom().getConfigMapKeyRef().getName()).get();
assertNotNull(configMap);
String actualConfigScript = configMap.getData().get(entry.getScriptFrom().getConfigMapKeyRef().getKey());
assertEquals(entry.getScriptFrom().getConfigMapScript(), actualConfigScript);
}
}
use of io.stackgres.apiweb.dto.cluster.ClusterDto in project stackgres by ongres.
the class ClusterResourceQuarkusTest method givenACreationWithSecretScripts_shouldNotFail.
@Test
void givenACreationWithSecretScripts_shouldNotFail() {
ClusterDto cluster = getClusterInlineScripts();
ClusterScriptEntry entry = getSecretScriptEntry();
cluster.getSpec().getInitData().setScripts(Collections.singletonList(entry));
final Metadata metadata = cluster.getMetadata();
metadata.setNamespace("test");
given().header(AUTHENTICATION_HEADER).body(cluster).contentType(ContentType.JSON).accept(ContentType.JSON).post("/stackgres/sgclusters").then().statusCode(204);
try (KubernetesClient client = factory.create()) {
final ClusterScriptFrom scriptFrom = entry.getScriptFrom();
final SecretKeySelector secretKeyRef = scriptFrom.getSecretKeyRef();
Secret secret = client.secrets().inNamespace("test").withName(secretKeyRef.getName()).get();
assertNotNull(secret);
byte[] actualScript = Base64.getDecoder().decode(secret.getData().get(secretKeyRef.getKey()));
assertEquals(scriptFrom.getSecretScript(), new String(actualScript, StandardCharsets.UTF_8));
}
}
Aggregations