-
Notifications
You must be signed in to change notification settings - Fork 2
/
SensorExample.java
49 lines (41 loc) · 1.87 KB
/
SensorExample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package io.argoproj.events.client.examples;
import io.argoproj.events.models.sensor.*;
import io.kubernetes.client.openapi.models.V1ObjectMeta;
import io.kubernetes.client.util.ClientBuilder;
import io.kubernetes.client.util.generic.GenericKubernetesApi;
import io.kubernetes.client.util.generic.KubernetesApiResponse;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;
public class SensorExample {
public static void main(String[] args) throws Exception {
GenericKubernetesApi<Sensor, SensorList> sensorApi = new GenericKubernetesApi<>(
Sensor.class,
SensorList.class,
"argoproj.io",
"v1alpha1",
"sensors",
ClientBuilder.defaultClient());
// Create
EventDependency dep = new EventDependency().name("test-dep").eventSourceName("eventsource-name").eventName("example");
Trigger trigger = new Trigger().template(new TriggerTemplate().http(new HTTPTrigger().url("https://github.com").method("GET")));
sensorApi.create(
new Sensor().metadata(new V1ObjectMeta().namespace("argo-events").name("test-sensor"))
.kind("Sensor")
.apiVersion("argoproj.io/v1alpha1")
.spec(new SensorSpec().addDependenciesItem(dep).addTriggersItem(trigger))
);
// List
KubernetesApiResponse<SensorList> listRep = sensorApi.list("argo-events");
SensorList sensorList = listRep.getObject();
for (Sensor item : sensorList.getItems()) {
System.out.println(item.getMetadata().getName());
}
// Get
KubernetesApiResponse<Sensor> sensorRep = sensorApi.get("argo-events", "test-sensor");
Sensor s = sensorRep.getObject();
System.out.println(s.getSpec());
// Delete
sensorApi.delete("argo-events", "test-sensor");
}
}