use of oracle.kubernetes.operator.work.Fiber.CompletionCallback in project weblogic-kubernetes-operator by oracle.
the class Main method scheduleDomainStatusUpdating.
private static void scheduleDomainStatusUpdating(DomainPresenceInfo info) {
AtomicInteger unchangedCount = new AtomicInteger(0);
AtomicReference<ScheduledFuture<?>> statusUpdater = info.getStatusUpdater();
Runnable command = new Runnable() {
public void run() {
// resolve visibility
Runnable r = this;
Packet packet = new Packet();
packet.getComponents().put(ProcessingConstants.DOMAIN_COMPONENT_NAME, Component.createFor(info, version));
MainTuning main = tuningAndConfig.getMainTuning();
Step strategy = DomainStatusUpdater.createStatusStep(main.statusUpdateTimeoutSeconds, null);
engine.createFiber().start(strategy, packet, new CompletionCallback() {
@Override
public void onCompletion(Packet packet) {
Boolean isStatusUnchanged = (Boolean) packet.get(ProcessingConstants.STATUS_UNCHANGED);
ScheduledFuture<?> existing = null;
if (Boolean.TRUE.equals(isStatusUnchanged)) {
if (unchangedCount.incrementAndGet() == main.unchangedCountToDelayStatusRecheck) {
// slow down retries because of sufficient unchanged statuses
existing = statusUpdater.getAndSet(engine.getExecutor().scheduleWithFixedDelay(r, main.eventualLongDelay, main.eventualLongDelay, TimeUnit.SECONDS));
}
} else {
// reset to trying after shorter delay because of changed status
unchangedCount.set(0);
existing = statusUpdater.getAndSet(engine.getExecutor().scheduleWithFixedDelay(r, main.initialShortDelay, main.initialShortDelay, TimeUnit.SECONDS));
if (existing != null) {
existing.cancel(false);
}
}
if (existing != null) {
existing.cancel(false);
}
}
@Override
public void onThrowable(Packet packet, Throwable throwable) {
LOGGER.severe(MessageKeys.EXCEPTION, throwable);
// retry to trying after shorter delay because of exception
unchangedCount.set(0);
ScheduledFuture<?> existing = statusUpdater.getAndSet(engine.getExecutor().scheduleWithFixedDelay(r, main.initialShortDelay, main.initialShortDelay, TimeUnit.SECONDS));
if (existing != null) {
existing.cancel(false);
}
}
});
}
};
MainTuning main = tuningAndConfig.getMainTuning();
ScheduledFuture<?> existing = statusUpdater.getAndSet(engine.getExecutor().scheduleWithFixedDelay(command, main.initialShortDelay, main.initialShortDelay, TimeUnit.SECONDS));
if (existing != null) {
existing.cancel(false);
}
}
use of oracle.kubernetes.operator.work.Fiber.CompletionCallback in project weblogic-kubernetes-operator by oracle.
the class CallBuilderTest method testListDomains.
@Test
public void testListDomains() throws InterruptedException {
Step stepline = new SetupStep(null);
Packet p = new Packet();
Semaphore signal = new Semaphore(0);
List<Throwable> throwables = Collections.synchronizedList(new ArrayList<Throwable>());
p.put(THROW, throwables);
engine.createFiber().start(stepline, p, new CompletionCallback() {
@Override
public void onCompletion(Packet packet) {
signal.release();
}
@Override
public void onThrowable(Packet packet, Throwable throwable) {
throwables.add(throwable);
signal.release();
}
});
boolean result = signal.tryAcquire(20, TimeUnit.MINUTES);
assertTrue(result);
assertTrue(throwables.isEmpty());
DomainList list = (DomainList) p.get(KEY);
assertNotNull(list);
}
use of oracle.kubernetes.operator.work.Fiber.CompletionCallback in project weblogic-kubernetes-operator by oracle.
the class IngressHelperTest method testAddThenRemoveServer.
@Test
public void testAddThenRemoveServer() throws Throwable {
Packet p = new Packet();
p.getComponents().put(ProcessingConstants.DOMAIN_COMPONENT_NAME, Component.createFor(info));
p.put(ProcessingConstants.SERVER_SCAN, info.getScan().getServerConfig(server1Name));
p.put(ProcessingConstants.CLUSTER_SCAN, info.getScan().getClusterConfig(clusterName));
p.put(ProcessingConstants.SERVER_NAME, server1Name);
Fiber f = engine.createFiber();
Step s = IngressHelper.createClusterStep(null);
AtomicReference<Throwable> t = new AtomicReference<>();
f.start(s, p, new CompletionCallback() {
@Override
public void onCompletion(Packet packet) {
// no-op
}
@Override
public void onThrowable(Packet packet, Throwable throwable) {
t.set(throwable);
}
});
f.get(30, TimeUnit.SECONDS);
if (t.get() != null) {
throw t.get();
}
// Now check
CallBuilderFactory factory = new CallBuilderFactory(null);
V1beta1Ingress v1beta1Ingress = factory.create().readIngress(ingressName, namespace);
List<V1beta1HTTPIngressPath> v1beta1HTTPIngressPaths = getPathArray(v1beta1Ingress);
Assert.assertEquals("IngressPaths should have one instance of IngressPath", 1, v1beta1HTTPIngressPaths.size());
V1beta1HTTPIngressPath v1beta1HTTPIngressPath = v1beta1HTTPIngressPaths.get(0);
Assert.assertEquals("/", v1beta1HTTPIngressPath.getPath());
V1beta1IngressBackend v1beta1IngressBackend = v1beta1HTTPIngressPath.getBackend();
Assert.assertNotNull("IngressBackend Object should not be null", v1beta1IngressBackend);
Assert.assertEquals("Service name should be " + clusterServiceName, clusterServiceName, v1beta1IngressBackend.getServiceName());
Assert.assertEquals("Service port should be " + server1Port, server1Port, v1beta1IngressBackend.getServicePort().getIntValue());
}
use of oracle.kubernetes.operator.work.Fiber.CompletionCallback in project weblogic-kubernetes-operator by oracle.
the class Main method doCheckAndCreateDomainPresence.
private static void doCheckAndCreateDomainPresence(Domain dom, boolean explicitRecheck, boolean explicitRestartAdmin, List<String> explicitRestartServers, List<String> explicitRestartClusters) {
LOGGER.entering();
boolean hasExplicitRestarts = explicitRestartAdmin || explicitRestartServers != null || explicitRestartClusters != null;
DomainSpec spec = dom.getSpec();
normalizeDomainSpec(spec);
String domainUID = spec.getDomainUID();
DomainPresenceInfo created = new DomainPresenceInfo(dom);
DomainPresenceInfo info = domains.putIfAbsent(domainUID, created);
if (info == null) {
info = created;
} else {
// Has the spec actually changed? We will get watch events for status updates
Domain current = info.getDomain();
if (current != null) {
if (!explicitRecheck && !hasExplicitRestarts && spec.equals(current.getSpec())) {
// nothing in the spec has changed
LOGGER.fine(MessageKeys.NOT_STARTING_DOMAINUID_THREAD, domainUID);
return;
}
}
info.setDomain(dom);
}
String ns = dom.getMetadata().getNamespace();
if (initialized.getOrDefault(ns, Boolean.FALSE) && !stopping.get()) {
LOGGER.info(MessageKeys.PROCESSING_DOMAIN, domainUID);
Step managedServerStrategy = bringManagedServersUp(DomainStatusUpdater.createEndProgressingStep(null));
Step adminServerStrategy = bringAdminServerUp(connectToAdminAndInspectDomain(managedServerStrategy));
Step strategy = DomainStatusUpdater.createProgressingStep(DomainStatusUpdater.INSPECTING_DOMAIN_PROGRESS_REASON, true, new DomainPrescenceStep(adminServerStrategy, managedServerStrategy));
Packet p = new Packet();
PodWatcher pw = podWatchers.get(ns);
p.getComponents().put(ProcessingConstants.DOMAIN_COMPONENT_NAME, Component.createFor(info, version, pw));
p.put(ProcessingConstants.PRINCIPAL, principal);
if (explicitRestartAdmin) {
p.put(ProcessingConstants.EXPLICIT_RESTART_ADMIN, Boolean.TRUE);
}
p.put(ProcessingConstants.EXPLICIT_RESTART_SERVERS, explicitRestartServers);
p.put(ProcessingConstants.EXPLICIT_RESTART_CLUSTERS, explicitRestartClusters);
if (explicitRestartAdmin) {
LOGGER.info(MessageKeys.RESTART_ADMIN_STARTING, domainUID);
}
if (explicitRestartServers != null) {
LOGGER.info(MessageKeys.RESTART_SERVERS_STARTING, domainUID, explicitRestartServers);
}
if (explicitRestartClusters != null) {
LOGGER.info(MessageKeys.ROLLING_CLUSTERS_STARTING, domainUID, explicitRestartClusters);
}
domainUpdaters.startFiber(domainUID, strategy, p, new CompletionCallback() {
@Override
public void onCompletion(Packet packet) {
if (explicitRestartAdmin) {
LOGGER.info(MessageKeys.RESTART_ADMIN_COMPLETE, domainUID);
}
if (explicitRestartServers != null) {
LOGGER.info(MessageKeys.RESTART_SERVERS_COMPLETE, domainUID, explicitRestartServers);
}
if (explicitRestartClusters != null) {
LOGGER.info(MessageKeys.ROLLING_CLUSTERS_COMPLETE, domainUID, explicitRestartClusters);
}
}
@Override
public void onThrowable(Packet packet, Throwable throwable) {
LOGGER.severe(MessageKeys.EXCEPTION, throwable);
domainUpdaters.startFiberIfLastFiberMatches(domainUID, Fiber.getCurrentIfSet(), DomainStatusUpdater.createFailedStep(throwable, null), p, new CompletionCallback() {
@Override
public void onCompletion(Packet packet) {
// no-op
}
@Override
public void onThrowable(Packet packet, Throwable throwable) {
LOGGER.severe(MessageKeys.EXCEPTION, throwable);
}
});
// TODO: consider retrying domain update after a delay
}
});
scheduleDomainStatusUpdating(info);
}
LOGGER.exiting();
}
use of oracle.kubernetes.operator.work.Fiber.CompletionCallback in project weblogic-kubernetes-operator by oracle.
the class Main method deleteDomainPresence.
private static void deleteDomainPresence(String namespace, String domainUID) {
LOGGER.entering();
DomainPresenceInfo info = domains.remove(domainUID);
if (info != null) {
cancelDomainStatusUpdating(info);
}
domainUpdaters.startFiber(domainUID, new DeleteDomainStep(namespace, domainUID), new Packet(), new CompletionCallback() {
@Override
public void onCompletion(Packet packet) {
// no-op
}
@Override
public void onThrowable(Packet packet, Throwable throwable) {
LOGGER.severe(MessageKeys.EXCEPTION, throwable);
}
});
LOGGER.exiting();
}
Aggregations