Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

feature: Add previous and following step for context on mini-catalog endpoint #459

Merged
merged 1 commit into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ public Collection<Step> all(
final @Parameter(description = "Maximum number of elements to return.")
@QueryParam("limit") Long limit,
final @Parameter(description = "Start returning from the nth element (combine with limit).")
@QueryParam("start") Long start) {
@QueryParam("start") Long start,
final @Parameter(description = "Provides context: previous step, if exists.")
@QueryParam("previous-step") String previousStep,
final @Parameter(description = "Provides context: following step, if exists.")
@QueryParam("following-step") String followingStep) {
final var allSteps = stepService.allSteps();
var steps = allSteps.stream().sorted(Comparator.comparing(Metadata::getId));
Span span = Span.current();
Expand All @@ -130,18 +134,22 @@ public Collection<Step> all(

//DSL first because it is usually the parameter we will use
if (dsl != null && !dsl.isEmpty()) {
final var dgsStream = deploymentService.getParsers().stream().parallel()
.filter(s ->
Arrays.stream(dsl.split(",")).anyMatch(it -> it.equalsIgnoreCase(s.identifier())))
.toList();

//First take all the kinds from the parameter list given
List<String> kinds =
deploymentService.getParsers().stream().parallel()
.filter(s -> Arrays.stream(dsl.split(","))
.anyMatch(it -> it.equalsIgnoreCase(
s.identifier())))
.map(DeploymentGeneratorService::getKinds)
.flatMap(Collection::stream)
.toList();
dgsStream.parallelStream()
.map(DeploymentGeneratorService::getKinds).flatMap(Collection::stream).toList();
//And now we can filter by the kinds
steps = steps.filter(step -> kinds.stream()
.anyMatch(s -> s.equalsIgnoreCase(step.getKind())));
steps = steps.filter(step -> kinds.stream().anyMatch(s -> s.equalsIgnoreCase(step.getKind())));

//And give context based on previous and following step, depending on the DSL
for (var dgs : dgsStream) {
steps = dgs.filterCatalog(previousStep, followingStep, steps);
}
}

//This may remove one third of the options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,38 +58,38 @@ void stepsByName() {
@Test
@Timeout(100)
void speedKamelet() {
stepResource.all("KameletBinding", null, null, null, null);
stepResource.all("KameletBinding", null, null, null, null, null, null);
}

@Test
@Timeout(100)
void speedKameletAndBinding() {
stepResource.all("KameletBinding,Kamelet", null, null, null, null);
stepResource.all("KameletBinding,Kamelet", null, null, null, null, null, null);
}
@Test
@Timeout(100)
void speedKameletAndBindingEnd() {
stepResource.all("KameletBinding,Kamelet", Step.END, null, null, null);
stepResource.all("KameletBinding,Kamelet", Step.END, null, null, null, null, null);
}
@Test
@Timeout(100)
void speedKameletBindingMiddle() {
stepResource.all("KameletBinding", Step.MIDDLE, null, null, null);
stepResource.all("KameletBinding", Step.MIDDLE, null, null, null, null, null);
}

@ParameterizedTest
@ValueSource(longs = {10l, 25l, 42l})
@Timeout(100)
void limitAndStart(long limitParameter) {
Assertions.assertTrue(stepResource.all(null, null, null, null, null).size() > limitParameter);
List<Step> limit = stepResource.all(null, null, null, limitParameter, null).stream().toList();
Assertions.assertTrue(stepResource.all(null, null, null, null, null, null, null).size() > limitParameter);
List<Step> limit = stepResource.all(null, null, null, limitParameter, null, null, null).stream().toList();
Assertions.assertEquals(limitParameter, limit.size());

Long[] startParameters = new Long[]{0l, 3l, 5l};

for (Long startParameter : startParameters) {
List<Step> start =
stepResource.all(null, null, null, limitParameter, startParameter).stream().toList();
stepResource.all(null, null, null, limitParameter, startParameter, null, null).stream().toList();
Assertions.assertEquals(limitParameter, start.size());

for (int i = 0; i < startParameter; i++) {
Expand All @@ -100,7 +100,7 @@ void limitAndStart(long limitParameter) {

@Test
void allSteps() {
Collection<Step> steps = stepResource.all(null, null, null, null, null);
Collection<Step> steps = stepResource.all(null, null, null, null, null, null, null);
Assertions.assertNotNull(steps);
Assertions.assertEquals(
catalog.getReadOnlyCatalog().getAll().size(),
Expand All @@ -109,26 +109,26 @@ void allSteps() {
var integrationType = "KameletBinding";
Assertions.assertNotNull(steps);
Assertions.assertTrue(
stepResource.all(null, integrationType, null, null, null)
stepResource.all(null, integrationType, null, null, null, null, null)
.stream().allMatch(s ->
integrationType.equalsIgnoreCase(s.getType())));

var kind = "Kamelet";
Assertions.assertNotNull(steps);
Assertions.assertTrue(
stepResource.all(null, null, kind, null, null)
stepResource.all(null, null, kind, null, null, null, null)
.stream().allMatch(s ->
kind.equalsIgnoreCase(s.getKind())));
var type = Step.START;
Assertions.assertNotNull(steps);
Assertions.assertTrue(
stepResource.all(type, null, null, null, null)
stepResource.all(type, null, null, null, null, null, null)
.stream().allMatch(s ->
type.equalsIgnoreCase(s.getType())));

Assertions.assertNotNull(steps);
Assertions.assertTrue(
stepResource.all(type, integrationType, kind, null, null)
stepResource.all(type, integrationType, kind, null, null, null, null)
.stream().allMatch(s ->
type.equalsIgnoreCase(s.getType())
&& kind.equalsIgnoreCase(s.getKind())));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Stream;

@ApplicationScoped
@RegisterForReflection
Expand Down Expand Up @@ -111,4 +112,9 @@ public Pod getPod(final String namespace, final String name, final KubernetesCli
//We are not handling deployments here
return null;
}

@Override
public Stream<Step> filterCatalog(String previousStep, String followingStep, Stream<Step> steps) {
return steps;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Stream;

@ApplicationScoped
@RegisterForReflection
Expand Down Expand Up @@ -182,4 +183,9 @@ public Pod getPod(final String namespace, final String name, final KubernetesCli

return null;
}

@Override
public Stream<Step> filterCatalog(String previousStep, String followingStep, Stream<Step> steps) {
return steps;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Stream;

@ApplicationScoped
public class KameletBindingDeploymentGeneratorService
Expand Down Expand Up @@ -282,4 +283,9 @@ public Pod getPod(final String namespace, final String name, final KubernetesCli

return null;
}

@Override
public Stream<Step> filterCatalog(String previousStep, String followingStep, Stream<Step> steps) {
return steps;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.Map;
import java.util.Objects;
import java.util.function.Predicate;
import java.util.stream.Stream;

@ApplicationScoped
public class KameletDeploymentGeneratorService implements DeploymentGeneratorService {
Expand Down Expand Up @@ -162,4 +163,9 @@ public Pod getPod(final String namespace, final String name, final KubernetesCli
//There is no pod associated to Kamelets
return null;
}

@Override
public Stream<Step> filterCatalog(String previousStep, String followingStep, Stream<Step> steps) {
return steps;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

/**
* 🐱miniclass DeploymentGeneratorService (StepResource)
Expand Down Expand Up @@ -121,6 +122,18 @@ String parse(List<Step> steps, Map<String, Object> metadata,
@WithSpan
Pod getPod(String namespace, String name, KubernetesClient kclient);

/*
* 🐱method filterCatalog: List[Step]
* 🐱param previousStep: String
* 🐱param followingStep: String
*
* Filters a list of steps. previousStep and followingStep gives context to the catalog,
* potentially restricting the response.
*/
@WithSpan
Stream<Step> filterCatalog(String previousStep, String followingStep, Stream<Step> steps);


enum Status {
Stopped, Building, Ready, Running, Invalid
}
Expand Down