Search in sources :

Example 1 with KameletBinding

use of io.kaoto.backend.model.deployment.kamelet.KameletBinding in project kaoto-backend by KaotoIO.

the class ClusterService method start.

public boolean start(final String input) {
    try {
        Yaml yaml = new Yaml(new Constructor(KameletBinding.class));
        KameletBinding binding = yaml.load(input);
        if (binding.getMetadata() == null) {
            binding.setMetadata(new ObjectMeta());
        }
        final var name = binding.getMetadata().getName();
        if (name == null || name.isEmpty()) {
            binding.getMetadata().setName("integration-" + System.currentTimeMillis());
        }
        return start(binding);
    } catch (ConstructorException e) {
        log.warn("Error starting the integration.", e);
        return false;
    }
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) Constructor(org.yaml.snakeyaml.constructor.Constructor) ConstructorException(org.yaml.snakeyaml.constructor.ConstructorException) Yaml(org.yaml.snakeyaml.Yaml) KameletBinding(io.kaoto.backend.model.deployment.kamelet.KameletBinding)

Example 2 with KameletBinding

use of io.kaoto.backend.model.deployment.kamelet.KameletBinding in project kaoto-backend by KaotoIO.

the class ClusterService method getIntegrations.

public List<Integration> getIntegrations() {
    List<Integration> res = new ArrayList<>();
    try {
        final var resources = kubernetesClient.resources(KameletBinding.class).list().getItems();
        for (KameletBinding integration : resources) {
            Integration i = new Integration();
            i.setName(integration.getMetadata().getName());
            i.setRunning(true);
            i.setResource(integration);
            res.add(i);
        }
    } catch (Exception e) {
        log.warn("Error extracting the list of integrations.", e);
    }
    return res;
}
Also used : Integration(io.kaoto.backend.model.deployment.Integration) ArrayList(java.util.ArrayList) KameletBinding(io.kaoto.backend.model.deployment.kamelet.KameletBinding) ConstructorException(org.yaml.snakeyaml.constructor.ConstructorException)

Example 3 with KameletBinding

use of io.kaoto.backend.model.deployment.kamelet.KameletBinding 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 KameletBinding

use of io.kaoto.backend.model.deployment.kamelet.KameletBinding in project kaoto-backend by KaotoIO.

the class KameletBindingStepParserService method deepParse.

@Override
public ParseResult<Step> deepParse(final String input) {
    if (!appliesTo(input)) {
        throw new IllegalArgumentException("Wrong format provided. This is not parseable by us");
    }
    ParseResult<Step> res = new ParseResult<>();
    List<Step> steps = new ArrayList<>();
    try {
        ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory()).configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        KameletBinding binding = yamlMapper.readValue(input, KameletBinding.class);
        processMetadata(binding.getMetadata());
        processSpec(steps, binding.getSpec());
    } catch (JsonProcessingException e) {
        throw new IllegalArgumentException("Wrong format provided. This is not parseable by us");
    }
    res.setSteps(steps.stream().filter(Objects::nonNull).toList());
    return res;
}
Also used : ArrayList(java.util.ArrayList) Objects(java.util.Objects) YAMLFactory(com.fasterxml.jackson.dataformat.yaml.YAMLFactory) KameletBindingStep(io.kaoto.backend.model.deployment.kamelet.KameletBindingStep) Step(io.kaoto.backend.model.step.Step) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) KameletBinding(io.kaoto.backend.model.deployment.kamelet.KameletBinding)

Aggregations

KameletBinding (io.kaoto.backend.model.deployment.kamelet.KameletBinding)4 KameletBindingStep (io.kaoto.backend.model.deployment.kamelet.KameletBindingStep)2 Step (io.kaoto.backend.model.step.Step)2 ArrayList (java.util.ArrayList)2 Yaml (org.yaml.snakeyaml.Yaml)2 Constructor (org.yaml.snakeyaml.constructor.Constructor)2 ConstructorException (org.yaml.snakeyaml.constructor.ConstructorException)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 YAMLFactory (com.fasterxml.jackson.dataformat.yaml.YAMLFactory)1 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)1 Integration (io.kaoto.backend.model.deployment.Integration)1 KameletBindingSpec (io.kaoto.backend.model.deployment.kamelet.KameletBindingSpec)1 Objects (java.util.Objects)1