use of org.citrusframework.yaks.camelk.model.Kamelet in project yaks by citrusframework.
the class KameletBuilderTest method buildComplexKamelet.
@Test
public void buildComplexKamelet() throws IOException {
Map<String, KameletSpec.TypeSpec> types = new HashMap<>();
types.put("out", new KameletSpec.TypeSpec("text/plain"));
KameletSpec.Definition definition = new KameletSpec.Definition();
definition.setTitle("Timer Source");
definition.getProperties().put("period", new KameletSpec.Definition.PropertyConfig("Period", "integer", 1000, null));
definition.getProperties().put("message", new KameletSpec.Definition.PropertyConfig("Message", "string", null, "hello world"));
definition.getRequired().add("message");
Kamelet kamelet = new Kamelet.Builder().name("time-source").definition(definition).types(types).dependencies(Collections.singletonList("mvn:fake.dependency:id:version-1")).template("from:\n" + " uri: timer:tick\n" + " parameters:\n" + " period: \"#property:period\"\n" + " steps:\n" + " - set-body:\n" + " constant: \"{{message}}\"\n" + " - to: \"kamelet:sink\"").build();
final String json = KubernetesSupport.json().writeValueAsString(kamelet);
Assert.assertEquals(StringUtils.trimAllWhitespace(FileUtils.readToString(new ClassPathResource("kamelet.json", KameletBuilderTest.class))), StringUtils.trimAllWhitespace(json));
}
use of org.citrusframework.yaks.camelk.model.Kamelet in project yaks by citrusframework.
the class CreateKameletAction method createKamelet.
private void createKamelet(TestContext context) {
final Kamelet kamelet;
if (resource != null) {
try {
String resolvedSource;
if (supportVariables) {
resolvedSource = context.replaceDynamicContentInString(FileUtils.readToString(resource));
} else {
resolvedSource = FileUtils.readToString(resource);
}
kamelet = KubernetesSupport.yaml().loadAs(resolvedSource, Kamelet.class);
} catch (IOException e) {
throw new CitrusRuntimeException(String.format("Failed to load Kamelet from resource %s", name + ".kamelet.yaml"));
}
} else {
if (definition.getTitle() != null) {
definition.setTitle(context.replaceDynamicContentInString(definition.getTitle()));
}
if (definition.getDescription() != null) {
definition.setDescription(context.replaceDynamicContentInString(definition.getDescription()));
}
definition.setProperties(context.resolveDynamicValuesInMap(definition.getProperties()));
definition.setRequired(context.resolveDynamicValuesInList(definition.getRequired()));
final Kamelet.Builder builder = new Kamelet.Builder().name(context.replaceDynamicContentInString(name)).definition(definition);
if (template != null) {
builder.template(context.replaceDynamicContentInString(template));
}
if (source != null) {
builder.source(source.getName(), context.replaceDynamicContentInString(source.getContent()));
}
if (dependencies != null && !dependencies.isEmpty()) {
builder.dependencies(context.resolveDynamicValuesInList(dependencies));
}
if (types != null && !types.isEmpty()) {
builder.types(context.resolveDynamicValuesInMap(types));
}
kamelet = builder.build();
}
if (LOG.isDebugEnabled()) {
try {
LOG.debug(KubernetesSupport.json().writeValueAsString(kamelet));
} catch (JsonProcessingException e) {
LOG.warn("Unable to dump Kamelet data", e);
}
}
CustomResourceDefinitionContext ctx = CamelKSupport.kameletCRDContext(CamelKSettings.getKameletApiVersion());
getKubernetesClient().customResources(ctx, Kamelet.class, KameletList.class).inNamespace(namespace(context)).createOrReplace(kamelet);
LOG.info(String.format("Successfully created Kamelet '%s'", kamelet.getMetadata().getName()));
}
use of org.citrusframework.yaks.camelk.model.Kamelet in project yaks by citrusframework.
the class KameletBuilderTest method shouldDeserializeKamelet.
@Test
public void shouldDeserializeKamelet() throws IOException {
Kamelet deserialized = new ObjectMapper().readValue(FileUtils.readToString(new ClassPathResource("timer-source.kamelet.json")), Kamelet.class);
Assert.assertNull(deserialized.getSpec().getFlow());
Assert.assertNotNull(deserialized.getSpec().getTemplate());
Assert.assertEquals(1L, deserialized.getSpec().getTemplate().size());
}
use of org.citrusframework.yaks.camelk.model.Kamelet in project yaks by citrusframework.
the class VerifyKameletAction method doExecute.
@Override
public void doExecute(TestContext context) {
String kameletName = context.replaceDynamicContentInString(name);
CustomResourceDefinitionContext ctx = CamelKSupport.kameletCRDContext(CamelKSettings.getKameletApiVersion());
Kamelet kamelet = getKubernetesClient().customResources(ctx, Kamelet.class, KameletList.class).inNamespace(namespace(context)).withName(kameletName).get();
if (kamelet == null) {
throw new ValidationException(String.format("Failed to retrieve Kamelet '%s' in namespace '%s'", name, namespace(context)));
}
LOG.info("Kamlet validation successful - All values OK!");
if (LOG.isDebugEnabled()) {
try {
LOG.debug(KubernetesSupport.json().writeValueAsString(kamelet));
} catch (JsonProcessingException e) {
LOG.warn("Unable to dump Kamelet data", e);
}
}
}
Aggregations