Search in sources :

Example 6 with Kamelet

use of io.fabric8.camelk.v1alpha1.Kamelet in project kubernetes-client by fabric8io.

the class KameletModelTest method shouldDeserializeValidYamlIntoObject.

@Test
void shouldDeserializeValidYamlIntoObject() throws JsonProcessingException {
    final ObjectMapper mapper = new ObjectMapper();
    // Given
    String originalJson = new Scanner(getClass().getResourceAsStream("/valid-kamelet.json")).useDelimiter("\\A").next();
    // When
    final Kamelet kamelet = mapper.readValue(originalJson, Kamelet.class);
    final String serializedJson = mapper.writeValueAsString(kamelet);
    final Kamelet kameletFromSerializedJson = mapper.readValue(serializedJson, Kamelet.class);
    // Then
    assertNotNull(kamelet);
    assertNotNull(serializedJson);
    assertNotNull(kameletFromSerializedJson);
    assertEquals(kamelet.getMetadata().getName(), kameletFromSerializedJson.getMetadata().getName());
    assertNotNull(kamelet.getSpec().getTemplate());
    assertFalse(kamelet.getSpec().getTemplate().isEmpty());
    assertTrue(kamelet.getSpec().getTemplate().containsKey("beans"));
    assertTrue(kamelet.getSpec().getTemplate().containsKey("from"));
}
Also used : Scanner(java.util.Scanner) Kamelet(io.fabric8.camelk.v1alpha1.Kamelet) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.jupiter.api.Test)

Example 7 with Kamelet

use of io.fabric8.camelk.v1alpha1.Kamelet in project kaoto-backend by KaotoIO.

the class KamelPopulator method populateKamelet.

public void populateKamelet(final Kamelet kamelet, final Map<String, Object> metadata, final List<Step> steps) {
    kamelet.setSpec(new KameletSpec());
    kamelet.getSpec().setTemplate(new Template());
    kamelet.getSpec().getTemplate().setFrom(getFlow(steps));
    kamelet.setMetadata(new ObjectMeta());
    populateLabels(kamelet, (Map<String, String>) metadata.getOrDefault("labels", Collections.emptyMap()));
    populateAdditionalProperties(kamelet, (Map<String, String>) metadata.getOrDefault("additionalProperties", Collections.emptyMap()));
    populateAnnotations(kamelet, (Map<String, String>) metadata.getOrDefault("annotations", Collections.emptyMap()));
    // override in case this is outdated from the graphic side
    Type type = defineType(steps);
    kamelet.getMetadata().getLabels().put(group + "/kamelet.type", type.name());
    // consistent naming for kamelets
    String name = metadata.getOrDefault(NAME, "").toString();
    if (!name.endsWith(type.name())) {
        name = name + "-" + type.name();
    }
    kamelet.getMetadata().setName(name);
    // do we have an icon?
    if (kamelet.getMetadata().getAnnotations().getOrDefault(CAMEL_APACHE_ORG_KAMELET_ICON, "").isBlank()) {
        kamelet.getMetadata().getAnnotations().put(CAMEL_APACHE_ORG_KAMELET_ICON, metadata.getOrDefault("icon", "").toString());
    }
}
Also used : ObjectMeta(io.fabric8.kubernetes.api.model.ObjectMeta) KameletSpec(io.kaoto.backend.model.deployment.kamelet.KameletSpec) Template(io.kaoto.backend.model.deployment.kamelet.Template)

Aggregations

Kamelet (io.fabric8.camelk.v1alpha1.Kamelet)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 CustomResourceDefinitionContext (io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext)2 IOException (java.io.IOException)2 CitrusRuntimeException (com.consol.citrus.exceptions.CitrusRuntimeException)1 ValidationException (com.consol.citrus.exceptions.ValidationException)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 KameletBuilder (io.fabric8.camelk.v1alpha1.KameletBuilder)1 Condition (io.fabric8.kubernetes.api.model.Condition)1 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)1 JSONSchemaPropsBuilder (io.fabric8.kubernetes.api.model.apiextensions.v1.JSONSchemaPropsBuilder)1 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)1 Serialization (io.fabric8.kubernetes.client.utils.Serialization)1 ClassGraph (io.github.classgraph.ClassGraph)1 Resource (io.github.classgraph.Resource)1 ScanResult (io.github.classgraph.ScanResult)1 KameletSpec (io.kaoto.backend.model.deployment.kamelet.KameletSpec)1