use of it.fvaleri.integ.model.v1alpha1.Cake in project Lectures by FER-OOP.
the class UniMasterChef method main.
public static void main(String[] args) {
Dessert genericDessert = new Dessert("Chocolate Mousse", 120, 300);
Cake cake = new Cake("Raspberry chocolate cake #3", 350.5, 400, false, "birthday");
Teacher t1 = new Teacher("Dario", "Tušek", 42, "dario.tusek@fer.hr", "OOP", 10000);
Teacher t2 = new Teacher("Doris", "Bezmalinović", 43, "doris.bezmalinovic@fer.hr", "OOP", 10000);
Student s1 = new Student("Janko", "Horvat", 18, "0036312123", (short) 1);
Student s2 = new Student("Ana", "Kovač", 19, "0036387656", (short) 2);
Student s3 = new Student("Ivana", "Stanić", 19, "0036392357", (short) 1);
UniMasterChef competition = new UniMasterChef(2);
CompetitionEntry e1 = new CompetitionEntry(t1, genericDessert);
competition.addEntry(e1);
System.out.println("Entry 1 rating: " + e1.getRating());
e1.addRating(s1, 4);
e1.addRating(s2, 5);
System.out.println("Entry 1 rating: " + e1.getRating());
CompetitionEntry e2 = new CompetitionEntry(t2, cake);
e2.addRating(s1, 4);
e2.addRating(s3, 5);
e2.addRating(s2, 5);
competition.addEntry(e2);
System.out.println("Entry 2 rating: " + e2.getRating());
System.out.println("Best dessert is: " + competition.getBestDessert().getName());
Person[] e2persons = UniMasterChef.getInvolvedPeople(e2);
for (Person p : e2persons) System.out.println(p);
}
use of it.fvaleri.integ.model.v1alpha1.Cake in project integ-examples by fvaleri.
the class CakeOperator method main.
public static void main(String[] args) {
try (KubernetesClient client = new DefaultKubernetesClient()) {
String namespace = client.getNamespace();
if (namespace == null) {
LOG.warn("No namespace found via config, assuming default");
namespace = "default";
}
LOG.info("Using namespace {}", namespace);
OperationContext namespaced = new OperationContext().withNamespace(namespace);
// an infomer creates a watcher for a specific resource type and caches related events
// you can subscribe to these events by registering a resource event handler
SharedInformerFactory informerFactory = client.informers();
SharedIndexInformer<Pod> podSharedIndexInformer = informerFactory.sharedIndexInformerFor(Pod.class, namespaced, RESYNC_PERIOD_MS);
SharedIndexInformer<Cake> cakeSharedIndexInformer = informerFactory.sharedIndexInformerForCustomResource(Cake.class, namespaced, RESYNC_PERIOD_MS);
LOG.debug("Informer factories initialized");
MixedOperation<Cake, CakeList, Resource<Cake>> cakeClient = client.customResources(Cake.class, CakeList.class);
CakeController cakeController = new CakeController(client, cakeClient, podSharedIndexInformer, cakeSharedIndexInformer, namespace);
LOG.debug("Controller initialized");
cakeController.create();
informerFactory.startAllRegisteredInformers();
informerFactory.addSharedInformerEventListener(e -> LOG.error("Exception occurred", e));
cakeController.run();
} catch (KubernetesClientException e) {
LOG.error("Kubernetes client exception: {}", e.getMessage());
}
}
use of it.fvaleri.integ.model.v1alpha1.Cake in project integ-examples by fvaleri.
the class CakeController method handlePodObject.
private void handlePodObject(Pod pod) {
LOG.debug("Handling pod {}", pod.getMetadata().getName());
OwnerReference ownerReference = getControllerOf(pod);
if (ownerReference == null || !ownerReference.getKind().equalsIgnoreCase(API_KIND)) {
return;
}
Cake cake = cakeLister.get(ownerReference.getName());
if (cake != null) {
enqueueCake(cake);
}
}
use of it.fvaleri.integ.model.v1alpha1.Cake in project integ-examples by fvaleri.
the class CakeController method run.
/**
* Control/reconciliation loop.
*/
public void run() {
LOG.info("Starting controller");
while (!podInformer.hasSynced() || !cakeInformer.hasSynced()) {
// wait till Informer syncs
}
while (true) {
try {
LOG.info("Trying to fetch resource from work queue");
if (workQueue.isEmpty()) {
LOG.info("Work queue is empty");
}
String key = workQueue.take();
Objects.requireNonNull(key, "Key can't be null");
LOG.info("Reconciling resource with key {}", key);
if (key.isEmpty() || (!key.contains("/"))) {
LOG.warn("Invalid resource with key {}", key);
}
// get the Cake resource's name from key which is in format namespace/name
String name = key.split("/")[1];
Cake cake = cakeLister.get(name);
if (cake == null) {
LOG.error("Resource {} no longer exists", name);
return;
}
reconcile(cake);
} catch (InterruptedException interruptedException) {
Thread.currentThread().interrupt();
LOG.error("Controller interrupted");
}
}
}
use of it.fvaleri.integ.model.v1alpha1.Cake in project integ-examples by fvaleri.
the class CakeControllerTest method testReconcile.
@Test
@DisplayName("Should create requested number of pods")
void testReconcile() throws InterruptedException {
String namespace = "test";
Cake testCake = buildTestCake("apple-pie", namespace, "0800cff3-9d80-11ea-8973-0e13a02d8ebd");
server.expect().post().withPath(String.format("/api/v1/namespaces/%s/pods", namespace)).andReturn(HttpURLConnection.HTTP_CREATED, new PodBuilder().withNewMetadata().withName("foo").endMetadata().build()).times(testCake.getSpec().getReplicas());
SharedInformerFactory informerFactory = client.informers();
MixedOperation<Cake, CakeList, Resource<Cake>> cakeClient = client.customResources(Cake.class, CakeList.class);
SharedIndexInformer<Pod> podSharedIndexInformer = informerFactory.sharedIndexInformerFor(Pod.class, RESYNC_PERIOD_MILLIS);
SharedIndexInformer<Cake> cakeSharedIndexInformer = informerFactory.sharedIndexInformerForCustomResource(Cake.class, RESYNC_PERIOD_MILLIS);
CakeController cakeController = new CakeController(client, cakeClient, podSharedIndexInformer, cakeSharedIndexInformer, namespace);
cakeController.reconcile(testCake);
RecordedRequest recordedRequest = server.takeRequest();
assertEquals("POST", recordedRequest.getMethod());
assertTrue(recordedRequest.getBody().readUtf8().contains(testCake.getMetadata().getName()));
}
Aggregations