Search in sources :

Example 1 with Step

use of io.kaoto.backend.model.step.Step in project kaoto-backend by KaotoIO.

the class KameletParseCatalogTest method getSteps.

@Test
void getSteps() {
    ParseCatalog<Step> kameletParser = parseCatalog.getParser("https://github.com/apache/camel-kamelets.git", "v0.5.0");
    InMemoryCatalog<Step> catalog = new InMemoryCatalog<>();
    List<Step> steps = kameletParser.parse().join();
    assertTrue(catalog.store(steps));
    assertEquals(catalog.getAll().size(), steps.size());
    String name = "ftp-source";
    String[] required = new String[] { "connectionHost", "connectionPort", "username", "password", "directoryName" };
    Step step = catalog.searchStepByName(name);
    assertEquals(step.getRequired().size(), required.length);
    assertTrue(Arrays.stream(required).allMatch(property -> step.getRequired().contains(property)));
    Assertions.assertNotNull(step);
    assertEquals(name, step.getId());
    assertEquals(name, step.getName());
    assertEquals("Kamelet", step.getKind());
    assertEquals("START", step.getType());
    Assertions.assertNotNull(step.getParameters());
    assertEquals(8, step.getParameters().size());
    for (var p : step.getParameters()) {
        Assertions.assertNotNull(p.getType());
        Assertions.assertNotNull(p.getTitle());
        Assertions.assertNotNull(p.getId());
        Assertions.assertNotNull(p.getType());
        Assertions.assertNotNull(p.getDescription());
    }
}
Also used : Metadata(io.kaoto.backend.model.Metadata) Arrays(java.util.Arrays) InMemoryCatalog(io.kaoto.backend.metadata.catalog.InMemoryCatalog) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test) Inject(javax.inject.Inject) List(java.util.List) ParseCatalog(io.kaoto.backend.metadata.ParseCatalog) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Assertions(org.junit.jupiter.api.Assertions) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Comparator(java.util.Comparator) Step(io.kaoto.backend.model.step.Step) InMemoryCatalog(io.kaoto.backend.metadata.catalog.InMemoryCatalog) Step(io.kaoto.backend.model.step.Step) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 2 with Step

use of io.kaoto.backend.model.step.Step in project kaoto-backend by KaotoIO.

the class DeploymentService method crd.

/*
     * 🐱method yaml: String
     * 🐱param steps: List[Step]
     * 🐱param name: String
     *
     * Based on the provided steps, return a valid yaml string to deploy
     */
public Map<String, String> crd(final String name, final Step[] stepArray) {
    List<Step> steps = Arrays.asList(stepArray);
    Map<String, String> strings = new HashMap<>();
    Map<String, Object> metadata = new HashMap<>();
    metadata.put("name", name);
    for (DeploymentGeneratorService parser : getParsers()) {
        try {
            if (parser.appliesTo(steps)) {
                strings.put(parser.identifier(), parser.parse(steps, metadata));
            }
        } catch (Exception e) {
            log.warn("Parser " + parser.getClass() + "threw an unexpected" + " error. ", e);
        }
    }
    return strings;
}
Also used : HashMap(java.util.HashMap) DeploymentGeneratorService(io.kaoto.backend.api.service.deployment.generator.DeploymentGeneratorService) Step(io.kaoto.backend.model.step.Step)

Example 3 with Step

use of io.kaoto.backend.model.step.Step in project kaoto-backend by KaotoIO.

the class KameletBindingDeploymentGeneratorService method parse.

@Override
public String parse(final List<Step> steps, final Map<String, Object> metadata) {
    if (!appliesTo(steps)) {
        return "";
    }
    KameletBindingSpec spec = new KameletBindingSpec();
    int i = 0;
    if (!steps.isEmpty()) {
        Step step = steps.get(i);
        if ("START".equalsIgnoreCase(step.getType())) {
            spec.setSource(createKameletBindingStep(steps.get(i++)));
        }
    }
    for (; i < steps.size() - 1; i++) {
        spec.getSteps().add(createKameletBindingStep(steps.get(i)));
    }
    if (spec.getSteps().isEmpty()) {
        spec.setSteps(null);
    }
    if (steps.size() > 1) {
        spec.setSink(createKameletBindingStep(steps.get(steps.size() - 1)));
    }
    KameletBinding binding = new KameletBinding(String.valueOf(metadata.getOrDefault("name", "")), spec);
    Yaml yaml = new Yaml(new Constructor(KameletBinding.class), new KameletRepresenter());
    return yaml.dumpAsMap(binding);
}
Also used : KameletBindingSpec(io.kaoto.backend.model.deployment.kamelet.KameletBindingSpec) Constructor(org.yaml.snakeyaml.constructor.Constructor) KameletBindingStep(io.kaoto.backend.model.deployment.kamelet.KameletBindingStep) Step(io.kaoto.backend.model.step.Step) KameletBinding(io.kaoto.backend.model.deployment.kamelet.KameletBinding) Yaml(org.yaml.snakeyaml.Yaml)

Example 4 with Step

use of io.kaoto.backend.model.step.Step in project kaoto-backend by KaotoIO.

the class CatalogCollectionTest method before.

@BeforeAll
static void before() {
    List<Step> steps = new ArrayList<>();
    InMemoryCatalog<Step> ic = new InMemoryCatalog<>();
    steps.add(new Step("id-1", "connector-1", "icon", Collections.emptyList()));
    steps.add(new Step("id-2", CONNECTOR_2, "icon", Collections.emptyList()));
    ic.store(steps);
    catalogCollection.addCatalog(ic);
    ic = new InMemoryCatalog<>();
    steps.clear();
    steps.add(new Step("id-2", CONNECTOR_2, "icon", Collections.emptyList()));
    steps.add(new Step("id-3", CONNECTOR_2, "icon", Collections.emptyList()));
    ic.store(steps);
    catalogCollection.addCatalog(ic);
}
Also used : ArrayList(java.util.ArrayList) Step(io.kaoto.backend.model.step.Step) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 5 with Step

use of io.kaoto.backend.model.step.Step in project kaoto-backend by KaotoIO.

the class CatalogCollectionTest method searchStepByName.

@Test
void searchStepByName() {
    Step step = catalogCollection.searchStepByName(CONNECTOR_2);
    Assertions.assertNotNull(step);
    Assertions.assertEquals(CONNECTOR_2, step.getName());
}
Also used : Step(io.kaoto.backend.model.step.Step) Test(org.junit.jupiter.api.Test) QuarkusTest(io.quarkus.test.junit.QuarkusTest)

Aggregations

Step (io.kaoto.backend.model.step.Step)25 QuarkusTest (io.quarkus.test.junit.QuarkusTest)15 Test (org.junit.jupiter.api.Test)15 ArrayList (java.util.ArrayList)9 ViewDefinition (io.kaoto.backend.model.view.ViewDefinition)5 KameletBindingStep (io.kaoto.backend.model.deployment.kamelet.KameletBindingStep)3 LinkedList (java.util.LinkedList)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 FlowStep (io.kaoto.backend.model.deployment.kamelet.FlowStep)2 KameletBinding (io.kaoto.backend.model.deployment.kamelet.KameletBinding)2 ChoiceFlowStep (io.kaoto.backend.model.deployment.kamelet.step.ChoiceFlowStep)2 SetBodyFlowStep (io.kaoto.backend.model.deployment.kamelet.step.SetBodyFlowStep)2 SetHeaderFlowStep (io.kaoto.backend.model.deployment.kamelet.step.SetHeaderFlowStep)2 ToFlowStep (io.kaoto.backend.model.deployment.kamelet.step.ToFlowStep)2 UriFlowStep (io.kaoto.backend.model.deployment.kamelet.step.UriFlowStep)2 ViewDefinitionConstraint (io.kaoto.backend.model.view.ViewDefinitionConstraint)2 HashMap (java.util.HashMap)2 Yaml (org.yaml.snakeyaml.Yaml)2 Constructor (org.yaml.snakeyaml.constructor.Constructor)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1