Skip to content

Commit 5523311

Browse files
committed
chore: Fix CI jobs
Make sure to load JBang and initialize Camel CLI before running commands
1 parent 9eef8ad commit 5523311

File tree

10 files changed

+83
-33
lines changed

10 files changed

+83
-33
lines changed

java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/actions/kamelet/VerifyKameletBindingAction.java

+54-9
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,18 @@ public class VerifyKameletBindingAction extends AbstractKameletAction {
4040

4141
private final String bindingName;
4242

43+
private final int maxAttempts;
44+
private final long delayBetweenAttempts;
45+
4346
/**
4447
* Constructor using given builder.
4548
* @param builder
4649
*/
4750
public VerifyKameletBindingAction(Builder builder) {
4851
super("verify-kamelet-binding", builder);
4952
this.bindingName = builder.bindingName;
53+
this.maxAttempts = builder.maxAttempts;
54+
this.delayBetweenAttempts = builder.delayBetweenAttempts;
5055
}
5156

5257
@Override
@@ -66,20 +71,46 @@ public void doExecute(TestContext context) {
6671

6772
private void verifyLocalKameletBinding(String name, TestContext context) {
6873
Long pid = context.getVariable(name + ":pid", Long.class);
69-
Map<String, String> properties = camel().get(pid);
70-
if ((!properties.isEmpty() && properties.get("STATUS").equals("Running"))) {
71-
LOG.info(String.format("Verified Kamelet binding '%s' state 'Running' - All values OK!", name));
72-
} else {
73-
throw new ValidationException(String.format("Failed to retrieve Kamelet binding '%s' in state 'Running'", name));
74+
75+
for (int i = 0; i < maxAttempts; i++) {
76+
Map<String, String> properties = camel().get(pid);
77+
if ((!properties.isEmpty() && properties.get("STATUS").equals("Running"))) {
78+
LOG.info(String.format("Verified Kamelet binding '%s' state 'Running' - All values OK!", name));
79+
return;
80+
}
81+
82+
LOG.info(String.format("Waiting for Kamelet binding '%s' to be in state 'Running'- retry in %s ms", name, delayBetweenAttempts));
83+
try {
84+
Thread.sleep(delayBetweenAttempts);
85+
} catch (InterruptedException e) {
86+
LOG.warn("Interrupted while waiting for Kamelet binding", e);
87+
}
7488
}
89+
90+
throw new ValidationException(String.format("Failed to retrieve Kamelet binding '%s' in state 'Running'", name));
7591
}
7692

7793
private void verifyKameletBinding(String namespace, String name) {
7894
CustomResourceDefinitionContext ctx = CamelKSupport.kameletBindingCRDContext(CamelKSettings.getKameletApiVersion());
79-
KameletBinding binding = getKubernetesClient().customResources(ctx, KameletBinding.class, KameletBindingList.class)
80-
.inNamespace(namespace)
81-
.withName(name)
82-
.get();
95+
96+
KameletBinding binding = null;
97+
for (int i = 0; i < maxAttempts; i++) {
98+
binding = getKubernetesClient().customResources(ctx, KameletBinding.class, KameletBindingList.class)
99+
.inNamespace(namespace)
100+
.withName(name)
101+
.get();
102+
103+
if (binding == null) {
104+
LOG.info(String.format("Waiting for Kamelet binding '%s' - retry in %s ms", name, delayBetweenAttempts));
105+
try {
106+
Thread.sleep(delayBetweenAttempts);
107+
} catch (InterruptedException e) {
108+
LOG.warn("Interrupted while waiting for Kamelet binding", e);
109+
}
110+
} else {
111+
break;
112+
}
113+
}
83114

84115
if (binding == null) {
85116
throw new ValidationException(String.format("Failed to retrieve Kamelet binding '%s' in namespace '%s'", name, namespace));
@@ -97,6 +128,10 @@ public static final class Builder extends AbstractKameletAction.Builder<VerifyKa
97128

98129
private String bindingName;
99130

131+
private int maxAttempts = CamelKSettings.getMaxAttempts();
132+
private long delayBetweenAttempts = CamelKSettings.getDelayBetweenAttempts();
133+
134+
100135
public Builder isAvailable() {
101136
return this;
102137
}
@@ -106,6 +141,16 @@ public Builder isAvailable(String name) {
106141
return this;
107142
}
108143

144+
public Builder maxAttempts(int maxAttempts) {
145+
this.maxAttempts = maxAttempts;
146+
return this;
147+
}
148+
149+
public Builder delayBetweenAttempts(long delayBetweenAttempts) {
150+
this.delayBetweenAttempts = delayBetweenAttempts;
151+
return this;
152+
}
153+
109154
@Override
110155
public VerifyKameletBindingAction build() {
111156
return new VerifyKameletBindingAction(this);

java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/jbang/CamelJBang.java

+11-3
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,14 @@ public String ps() {
136136
return p.getOutput();
137137
}
138138

139+
/**
140+
* Get Camel JBang version.
141+
*/
142+
public String version() {
143+
ProcessAndOutput p = execute(camel("--version"));
144+
return p.getOutput();
145+
}
146+
139147
/**
140148
* Get details for integration previously run via JBang Camel app. Integration is identified by its process id.
141149
* @param pid
@@ -210,13 +218,13 @@ public List<Map<String, String>> getAll() {
210218
}
211219

212220
private static void detectJBang() {
213-
ProcessAndOutput result = version();
221+
ProcessAndOutput result = getVersion();
214222
if (result.getProcess().exitValue() == OK_EXIT_CODE) {
215223
LOG.info("Found JBang v" + result.getOutput());
216224
} else {
217225
LOG.warn("JBang not found. Downloading ...");
218226
download();
219-
result = version();
227+
result = getVersion();
220228
if (result.getProcess().exitValue() == OK_EXIT_CODE) {
221229
LOG.info("Using JBang v" + result.getOutput());
222230
}
@@ -264,7 +272,7 @@ private static void download() {
264272
installDir = installPath.resolve(homePath);
265273
}
266274

267-
private static ProcessAndOutput version() {
275+
private static ProcessAndOutput getVersion() {
268276
return execute(jBang("version"));
269277
}
270278

java/steps/yaks-camel-k/src/main/java/org/citrusframework/yaks/camelk/jbang/ProcessAndOutput.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public Long getCamelProcessId() {
144144
try {
145145
if (isUnix()) {
146146
// wait for descendant process to be available
147-
await().atMost(5000L, TimeUnit.MILLISECONDS)
147+
await().atMost(15000L, TimeUnit.MILLISECONDS)
148148
.until(() -> process.descendants().findAny().isPresent());
149149
return process.descendants()
150150
.filter(p -> p.info().commandLine().orElse("").contains(CamelJBangSettings.getCamelApp()))

java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/integration/CreateIntegrationActionTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ public void shouldCreateIntegrationWithConfigModeline() {
172172

173173
@Test
174174
public void shouldCreateLocalJBangIntegration() {
175+
camel().version();
175176
CreateIntegrationAction action = new CreateIntegrationAction.Builder()
176177
.client(kubernetesClient)
177178
.integration("foo")

java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/integration/DeleteIntegrationActionTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class DeleteIntegrationActionTest {
5252
@BeforeClass
5353
public static void setup() throws IOException {
5454
sampleIntegration = new ClassPathResource("simple.groovy").getFile().toPath();
55+
camel().version();
5556
}
5657

5758
@Test

java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/integration/VerifyIntegrationActionTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class VerifyIntegrationActionTest {
5252
@BeforeClass
5353
public static void setup() throws IOException {
5454
sampleIntegration = new ClassPathResource("simple.groovy").getFile().toPath();
55+
camel().version();
5556
}
5657

5758
@Test

java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/kamelet/CreateKameletBindingActionTest.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import org.citrusframework.yaks.YaksClusterType;
3333
import org.citrusframework.yaks.camelk.actions.integration.CreateIntegrationActionTest;
3434
import org.junit.Assert;
35+
import org.junit.BeforeClass;
3536
import org.junit.Test;
3637
import org.slf4j.Logger;
3738
import org.slf4j.LoggerFactory;
@@ -52,9 +53,13 @@ public class CreateKameletBindingActionTest {
5253

5354
private final TestContext context = TestContextFactory.newInstance().getObject();
5455

56+
@BeforeClass
57+
public static void setup() throws IOException {
58+
camel().version();
59+
}
60+
5561
@Test
5662
public void shouldCreateLocalJBangKameletBinding() throws IOException {
57-
System.setProperty("yaks.jbang.camel.dump.integration.output", "true");
5863
CreateKameletBindingAction action = new CreateKameletBindingAction.Builder()
5964
.client(kubernetesClient)
6065
.binding("timer-to-log-binding")

java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/kamelet/DeleteKameletBindingActionTest.java

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public class DeleteKameletBindingActionTest {
5252
@BeforeClass
5353
public static void setup() throws IOException {
5454
sampleBinding = new ClassPathResource("timer-to-log-binding.yaml").getFile().toPath();
55+
camel().version();
5556
}
5657

5758
@Test

java/steps/yaks-camel-k/src/test/java/org/citrusframework/yaks/camelk/actions/kamelet/VerifyKameletBindingActionTest.java

+6-13
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import java.io.IOException;
2121
import java.nio.file.Path;
2222
import java.util.HashMap;
23-
import java.util.concurrent.TimeUnit;
2423

2524
import com.consol.citrus.context.TestContext;
2625
import com.consol.citrus.context.TestContextFactory;
@@ -33,18 +32,12 @@
3332
import org.citrusframework.yaks.camelk.jbang.ProcessAndOutput;
3433
import org.junit.BeforeClass;
3534
import org.junit.Test;
36-
import org.slf4j.Logger;
37-
import org.slf4j.LoggerFactory;
3835
import org.springframework.core.io.ClassPathResource;
3936

40-
import static org.awaitility.Awaitility.await;
4137
import static org.citrusframework.yaks.camelk.jbang.CamelJBang.camel;
4238

4339
public class VerifyKameletBindingActionTest {
4440

45-
/** Logger */
46-
private static final Logger LOG = LoggerFactory.getLogger(VerifyKameletBindingActionTest.class);
47-
4841
private final KubernetesMockServer k8sServer = new KubernetesMockServer(new Context(), new MockWebServer(),
4942
new HashMap<>(), new KubernetesCrudDispatcher(), false);
5043

@@ -57,24 +50,24 @@ public class VerifyKameletBindingActionTest {
5750
@BeforeClass
5851
public static void setup() throws IOException {
5952
sampleBinding = new ClassPathResource("timer-to-log-binding.yaml").getFile().toPath();
53+
camel().version();
6054
}
6155

6256
@Test
6357
public void shouldVerifyLocalJBangIntegration() {
64-
ProcessAndOutput pao = camel().run("timer-to-log-binding.yaml", sampleBinding);
58+
ProcessAndOutput pao = camel().run("timer-to-log-binding", sampleBinding);
6559
Long pid = pao.getCamelProcessId();
6660

6761
try {
6862
VerifyKameletBindingAction action = new VerifyKameletBindingAction.Builder()
6963
.client(kubernetesClient)
70-
.isAvailable("timer-to-log-binding.yaml")
64+
.isAvailable("timer-to-log-binding")
7165
.clusterType(YaksClusterType.LOCAL)
66+
.maxAttempts(10)
7267
.build();
7368

74-
context.setVariable("timer-to-log-binding.yaml:pid", pid);
75-
context.setVariable("timer-to-log-binding.yaml:process:" + pid, pao);
76-
77-
await().atMost(30000L, TimeUnit.MILLISECONDS).until(() -> !camel().get(pid).isEmpty());
69+
context.setVariable("timer-to-log-binding:pid", pid);
70+
context.setVariable("timer-to-log-binding:process:" + pid, pao);
7871

7972
action.execute(context);
8073
} finally {

java/steps/yaks-camel-k/src/test/resources/timer-to-log-binding.yaml

+1-6
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,4 @@ spec:
2828
properties:
2929
message: "Hello world!"
3030
sink:
31-
ref:
32-
kind: Kamelet
33-
apiVersion: camel.apache.org/v1alpha1
34-
name: log-sink
35-
properties:
36-
showHeaders: true
31+
uri: log:info

0 commit comments

Comments
 (0)