Skip to content

Commit

Permalink
test if query is initialized before building full-status that might c… (
Browse files Browse the repository at this point in the history
#3586)

* test if query is initialized before building full-status to avoid issues
* Cleanup query overview in admin-ui
* Shorten toString of MultiSelect FilterValue
  • Loading branch information
awildturtok authored Oct 7, 2024
1 parent f58dd0e commit 720fb46
Show file tree
Hide file tree
Showing 5 changed files with 301 additions and 259 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public Stream<ExecutionStatus> getQueriesFiltered(DatasetId datasetId, UriBuilde
)
.filter(q -> subject.isPermitted(q, Ability.READ))
.map(mq -> {
final OverviewExecutionStatus status = mq.buildStatusOverview(uriBuilder.clone(), subject);
final OverviewExecutionStatus status = mq.buildStatusOverview(subject);

if (mq.isReadyToDownload()) {
status.setResultUrls(getResultAssets(config.getResultProviders(), mq, uriBuilder, allProviders));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,45 @@ public Condition convertForTableExport(SqlIdColumns ids, ConversionContext conte

@NoArgsConstructor
@CPSType(id = FrontendFilterType.Fields.MULTI_SELECT, base = FilterValue.class)
@ToString(callSuper = true)
public static class CQMultiSelectFilter extends FilterValue<Set<String>> {
public CQMultiSelectFilter(@NsIdRef Filter<Set<String>> filter, Set<String> value) {
super(filter, value);
}

@Override
public String toString() {
final String valueString;
if (getValue().size() > 20) {
valueString = getValue().size() + " values";
}
else {
valueString = getValue().toString();
}

return "%s(value=%s)".formatted(FrontendFilterType.Fields.BIG_MULTI_SELECT, valueString);
}

}

@NoArgsConstructor
@CPSType(id = FrontendFilterType.Fields.BIG_MULTI_SELECT, base = FilterValue.class)
@ToString(callSuper = true)
public static class CQBigMultiSelectFilter extends FilterValue<Set<String>> {
public CQBigMultiSelectFilter(@NsIdRef Filter<Set<String>> filter, Set<String> value) {
super(filter, value);
}

@Override
public String toString() {
final String valueString;
if (getValue().size() > 20) {
valueString = getValue().size() + " values";
}
else {
valueString = getValue().toString();
}

return "%s(value=%s)".formatted(FrontendFilterType.Fields.BIG_MULTI_SELECT, valueString);
}
}

@NoArgsConstructor
Expand Down Expand Up @@ -219,11 +242,10 @@ public GroupFilterValue deserialize(JsonParser p, DeserializationContext ctxt) t
final Filter<?> filter = nsIdDeserializer.deserialize(filterTraverse, ctxt);

if (!(filter instanceof GroupFilter)) {
throw InvalidTypeIdException.from(filterNode.traverse(), GroupFilter.class, String.format("Expected filter of type %s but was: %s", GroupFilter.class,
filter != null
? filter.getClass()
: null
));
throw InvalidTypeIdException.from(filterNode.traverse(),
GroupFilter.class,
String.format("Expected filter of type %s but was: %s", GroupFilter.class, filter != null ? filter.getClass() : null)
);
}
GroupFilter groupFilter = (GroupFilter) filter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
import com.fasterxml.jackson.annotation.OptBoolean;
import com.google.common.base.Preconditions;
import jakarta.validation.constraints.NotNull;
import jakarta.ws.rs.core.UriBuilder;
import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.Getter;
Expand Down Expand Up @@ -289,7 +288,7 @@ public void start() {
/**
* Renders a lightweight status with meta information about this query. Computation an size should be small for this.
*/
public OverviewExecutionStatus buildStatusOverview(UriBuilder url, Subject subject) {
public OverviewExecutionStatus buildStatusOverview(Subject subject) {
OverviewExecutionStatus status = new OverviewExecutionStatus();
setStatusBase(subject, status);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.Optional;
import java.util.OptionalLong;
import java.util.UUID;
import java.util.stream.Stream;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
Expand All @@ -21,6 +22,7 @@
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriBuilder;

import com.bakdata.conquery.apiv1.execution.ExecutionStatus;
import com.bakdata.conquery.apiv1.execution.FullExecutionStatus;
import com.bakdata.conquery.io.jersey.ExtraMimeTypes;
import com.bakdata.conquery.io.storage.MetaStorage;
Expand Down Expand Up @@ -78,9 +80,7 @@ public Response cancelJob(@PathParam(JOB_ID) UUID jobId) {
info.send(new CancelJobMessage(jobId));
}

return Response
.seeOther(UriBuilder.fromPath("/admin/").path(AdminUIResource.class, "getJobs").build())
.build();
return Response.seeOther(UriBuilder.fromPath("/admin/").path(AdminUIResource.class, "getJobs").build()).build();
}

@GET
Expand All @@ -97,21 +97,26 @@ public boolean isBusy() {

@GET
@Path("/queries")
public FullExecutionStatus[] getQueries(@Auth Subject currentUser, @QueryParam("limit") OptionalLong maybeLimit, @QueryParam("since") Optional<String> maybeSince) {
public Stream<ExecutionStatus> getQueries(@Auth Subject currentUser, @QueryParam("limit") OptionalLong maybeLimit, @QueryParam("since") Optional<String> maybeSince) {

final LocalDate since = maybeSince.map(LocalDate::parse).orElse(LocalDate.now());
final long limit = maybeLimit.orElse(100);

final MetaStorage storage = processor.getStorage();


return storage.getAllExecutions().stream()
return storage.getAllExecutions()
.stream()
.filter(t -> t.getCreationTime().toLocalDate().isAfter(since) || t.getCreationTime().toLocalDate().isEqual(since))
.limit(limit)
.map(t -> {
Namespace namespace = processor.getDatasetRegistry().get(t.getDataset().getId());
try {
return t.buildStatusFull(currentUser, namespace);
if (t.isInitialized()) {
final Namespace namespace = processor.getDatasetRegistry().get(t.getDataset().getId());
return t.buildStatusFull(currentUser, namespace);
}

return t.buildStatusOverview(currentUser);
}
catch (ConqueryError e) {
// Initialization of execution probably failed, so we construct a status based on the overview status
Expand All @@ -121,8 +126,7 @@ public FullExecutionStatus[] getQueries(@Auth Subject currentUser, @QueryParam("
fullExecutionStatus.setError(e);
return fullExecutionStatus;
}
})
.toArray(FullExecutionStatus[]::new);
});
}

@POST
Expand Down
Loading

0 comments on commit 720fb46

Please sign in to comment.