use of io.kubernetes.client.common.KubernetesObject in project java by kubernetes-client.
the class DeltaFIFO method syncKeyLocked.
/**
* Add Sync delta. Caller must hold the lock.
*/
private void syncKeyLocked(String key) {
KubernetesObject obj = this.knownObjects.getByKey(key);
if (obj == null) {
return;
}
String id = this.keyOf(obj);
Deque<MutablePair<DeltaType, KubernetesObject>> deltas = this.items.get(id);
if (deltas != null && !(CollectionUtils.isEmpty(deltas))) {
return;
}
this.queueActionLocked(DeltaType.Sync, obj);
}
use of io.kubernetes.client.common.KubernetesObject in project java by kubernetes-client.
the class DeltaFIFOTest method testDeltaFIFOBasic.
@Test
public void testDeltaFIFOBasic() throws InterruptedException {
Deque<MutablePair<DeltaFIFO.DeltaType, KubernetesObject>> receivingDeltas = new LinkedList<>();
V1Pod foo1 = new V1Pod().metadata(new V1ObjectMeta().name("foo1").namespace("default"));
Cache cache = new Cache();
DeltaFIFO deltaFIFO = new DeltaFIFO(Caches::deletionHandlingMetaNamespaceKeyFunc, cache);
MutablePair<DeltaFIFO.DeltaType, KubernetesObject> receivingDelta;
// basic add operation
deltaFIFO.add(foo1);
cache.add(foo1);
deltaFIFO.pop((deltas) -> {
MutablePair<DeltaFIFO.DeltaType, KubernetesObject> delta = deltas.peekFirst();
receivingDeltas.add(delta);
});
receivingDelta = receivingDeltas.peekFirst();
receivingDeltas.removeFirst();
assertEquals(foo1, receivingDelta.getRight());
assertEquals(DeltaFIFO.DeltaType.Added, receivingDelta.getLeft());
// basic update operation
deltaFIFO.update(foo1);
cache.update(foo1);
deltaFIFO.pop((deltas) -> {
MutablePair<DeltaFIFO.DeltaType, KubernetesObject> delta = deltas.peekFirst();
receivingDeltas.add(delta);
});
receivingDelta = receivingDeltas.peekFirst();
receivingDeltas.removeFirst();
assertEquals(foo1, receivingDelta.getRight());
assertEquals(DeltaFIFO.DeltaType.Updated, receivingDelta.getLeft());
// basic delete operation
deltaFIFO.delete(foo1);
cache.delete(foo1);
deltaFIFO.pop((deltas) -> {
MutablePair<DeltaFIFO.DeltaType, KubernetesObject> delta = deltas.peekFirst();
receivingDeltas.add(delta);
});
receivingDelta = receivingDeltas.peekFirst();
receivingDeltas.removeFirst();
assertEquals(foo1, receivingDelta.getRight());
assertEquals(DeltaFIFO.DeltaType.Deleted, receivingDelta.getLeft());
// basic sync operation
deltaFIFO.replace(Arrays.asList(foo1), "0");
cache.replace(Arrays.asList(foo1), "0");
deltaFIFO.pop((deltas) -> {
MutablePair<DeltaFIFO.DeltaType, KubernetesObject> delta = deltas.peekFirst();
receivingDeltas.add(delta);
});
receivingDelta = receivingDeltas.peekFirst();
receivingDeltas.removeFirst();
assertEquals(foo1, receivingDelta.getRight());
assertEquals(DeltaFIFO.DeltaType.Sync, receivingDelta.getLeft());
}
use of io.kubernetes.client.common.KubernetesObject in project java by kubernetes-client.
the class DynamicKubernetesTypeAdaptorFactoryTest method testSingleDynamicObjectRoundTrip.
@Test
public void testSingleDynamicObjectRoundTrip() {
KubernetesObject dynamicObj = gson.fromJson(jsonContent, KubernetesObject.class);
assertTrue(dynamicObj instanceof DynamicKubernetesObject);
assertEquals("v1", dynamicObj.getApiVersion());
assertEquals("Namespace", dynamicObj.getKind());
assertEquals(new V1ObjectMeta().name("foo"), dynamicObj.getMetadata());
String dumped = gson.toJson(dynamicObj);
assertEquals(jsonContent, dumped);
}
use of io.kubernetes.client.common.KubernetesObject in project java by kubernetes-client.
the class KubernetesKubectlCreateProcessor method postProcessAfterInitialization.
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (!(bean instanceof KubernetesObject)) {
// no-op
return bean;
}
KubectlCreate create = beanFactory.findAnnotationOnBean(beanName, KubectlCreate.class);
if (create == null) {
return bean;
}
Class<? extends KubernetesObject> apiTypeClass = (Class<? extends KubernetesObject>) bean.getClass();
try {
log.info("@KubectlCreate ensuring resource upon bean {}", beanName);
return create(apiTypeClass, bean);
} catch (KubectlException e) {
if (e.getCause() instanceof ApiException) {
ApiException apiException = (ApiException) e.getCause();
if (HttpURLConnection.HTTP_CONFLICT == apiException.getCode()) {
// already exists
log.info("Skipped processing {} @KubectlCreate resource already exists", beanName);
return bean;
}
}
log.error("Failed ensuring resource from @KubectlCreate", e);
throw new BeanCreationException("Failed ensuring resource from @KubectlCreate", e);
}
}
use of io.kubernetes.client.common.KubernetesObject in project java by kubernetes-client.
the class KubernetesKubectlApplyProcessor method postProcessAfterInitialization.
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
if (!(bean instanceof KubernetesObject)) {
// no-op
return bean;
}
KubectlApply apply = beanFactory.findAnnotationOnBean(beanName, KubectlApply.class);
if (apply == null) {
return bean;
}
Class<? extends KubernetesObject> apiTypeClass = (Class<? extends KubernetesObject>) bean.getClass();
try {
log.info("@KubectlApply ensuring resource upon bean {}", beanName);
return apply(apiTypeClass, bean);
} catch (KubectlException e) {
log.error("Failed ensuring resource from @KubectlApply", e);
throw new BeanCreationException("Failed ensuring resource from @KubectlApply", e);
}
}
Aggregations