Search in sources :

Example 6 with CompletionCallback

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);
    }
}
Also used : Packet(oracle.kubernetes.operator.work.Packet) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CompletionCallback(oracle.kubernetes.operator.work.Fiber.CompletionCallback) MainTuning(oracle.kubernetes.operator.TuningParameters.MainTuning) Step(oracle.kubernetes.operator.work.Step) ResponseStep(oracle.kubernetes.operator.helpers.ResponseStep) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ScheduledFuture(java.util.concurrent.ScheduledFuture)

Example 7 with CompletionCallback

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);
}
Also used : Packet(oracle.kubernetes.operator.work.Packet) CompletionCallback(oracle.kubernetes.operator.work.Fiber.CompletionCallback) Step(oracle.kubernetes.operator.work.Step) Semaphore(java.util.concurrent.Semaphore) DomainList(oracle.kubernetes.weblogic.domain.v1.DomainList) Test(org.junit.Test)

Example 8 with CompletionCallback

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());
}
Also used : Packet(oracle.kubernetes.operator.work.Packet) Fiber(oracle.kubernetes.operator.work.Fiber) V1beta1IngressBackend(io.kubernetes.client.models.V1beta1IngressBackend) AtomicReference(java.util.concurrent.atomic.AtomicReference) Step(oracle.kubernetes.operator.work.Step) V1beta1HTTPIngressPath(io.kubernetes.client.models.V1beta1HTTPIngressPath) V1beta1Ingress(io.kubernetes.client.models.V1beta1Ingress) CompletionCallback(oracle.kubernetes.operator.work.Fiber.CompletionCallback) Test(org.junit.Test)

Example 9 with CompletionCallback

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();
}
Also used : Packet(oracle.kubernetes.operator.work.Packet) DomainSpec(oracle.kubernetes.weblogic.domain.v1.DomainSpec) CompletionCallback(oracle.kubernetes.operator.work.Fiber.CompletionCallback) Step(oracle.kubernetes.operator.work.Step) ResponseStep(oracle.kubernetes.operator.helpers.ResponseStep) Domain(oracle.kubernetes.weblogic.domain.v1.Domain) DomainPresenceInfo(oracle.kubernetes.operator.helpers.DomainPresenceInfo)

Example 10 with CompletionCallback

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();
}
Also used : Packet(oracle.kubernetes.operator.work.Packet) CompletionCallback(oracle.kubernetes.operator.work.Fiber.CompletionCallback) DomainPresenceInfo(oracle.kubernetes.operator.helpers.DomainPresenceInfo)

Aggregations

CompletionCallback (oracle.kubernetes.operator.work.Fiber.CompletionCallback)14 Test (org.junit.Test)9 ArrayList (java.util.ArrayList)8 List (java.util.List)8 Semaphore (java.util.concurrent.Semaphore)7 Packet (oracle.kubernetes.operator.work.Packet)6 HashMap (java.util.HashMap)5 Step (oracle.kubernetes.operator.work.Step)5 ResponseStep (oracle.kubernetes.operator.helpers.ResponseStep)3 V1beta1Ingress (io.kubernetes.client.models.V1beta1Ingress)2 ScheduledFuture (java.util.concurrent.ScheduledFuture)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 MainTuning (oracle.kubernetes.operator.TuningParameters.MainTuning)2 DomainPresenceInfo (oracle.kubernetes.operator.helpers.DomainPresenceInfo)2 Fiber (oracle.kubernetes.operator.work.Fiber)2 DomainList (oracle.kubernetes.weblogic.domain.v1.DomainList)2 ApiException (io.kubernetes.client.ApiException)1 JSON (io.kubernetes.client.JSON)1