Search in sources :

Example 1 with Clusters

use of org.bf2.cos.fleetshard.support.resources.Clusters in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class ControlPlane method getKafkaClusters.

/**
 * Get the current list of ManagedKafka clusters from the control plane
 * as a blocking call.
 * Also updates the cache of desired state ManagedKafka instances.  May include
 * entries that have not yet been created locally.
 *
 * @see {@link #getDesiredStates()} to get the full cache, rather than making a
 * remote call
 */
public List<ManagedKafka> getKafkaClusters() {
    ManagedKafkaList result = controlPlaneClient.getKafkaClusters(id);
    result.getItems().forEach((mk) -> addDesiredState(mk));
    return result.getItems();
}
Also used : ManagedKafkaList(org.bf2.operator.resources.v1alpha1.ManagedKafkaList)

Example 2 with Clusters

use of org.bf2.cos.fleetshard.support.resources.Clusters in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class MockControlPlane method loop.

@Scheduled(every = "{poll.interval}")
void loop() {
    // only run simulation when needed
    if (!this.runSimulation) {
        return;
    }
    Random random = new Random(System.currentTimeMillis());
    log.info("control plane:: Running Simulation");
    // feed the start of clusters
    if (this.kafkas.size() == 0) {
        int max = Math.abs(random.nextInt(maxKafkas));
        for (int i = 0; i < max; i++) {
            ManagedKafka k = ManagedKafka.getDummyInstance(this.clusterIdGenerator.getAndIncrement());
            log.infof("control plane::marking %s for addition", k.getId());
            this.kafkas.put(k.getId(), k);
        }
    }
    // delete a instance by random
    if (this.kafkas.size() > 1 && random.nextBoolean()) {
        int idx = Math.abs(random.nextInt(this.kafkas.size()));
        int i = 0;
        for (ManagedKafka k : kafkas.values()) {
            if (i++ < idx) {
                continue;
            } else {
                markForDeletion(k.getId());
                break;
            }
        }
    }
    // selectively add
    if (this.kafkas.size() < maxKafkas && random.nextBoolean()) {
        ManagedKafka k = ManagedKafka.getDummyInstance(this.clusterIdGenerator.getAndIncrement());
        log.infof("control plane:: creating a new cluster %s ", k.getId());
        this.kafkas.put(k.getId(), k);
    }
    log.info("--------------------------------------------------");
    for (ManagedKafka mk : this.kafkas.values()) {
        log.infof("ManagedKafka: %s, delete requested: %s", mk.getId(), mk.getSpec().isDeleted());
    }
    log.info("--------------------------------------------------");
}
Also used : ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) Random(java.util.Random) Scheduled(io.quarkus.scheduler.Scheduled)

Example 3 with Clusters

use of org.bf2.cos.fleetshard.support.resources.Clusters in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class MockManagedKafkaFactory method loop.

@Scheduled(every = "{mock.factory.interval}")
void loop() {
    Random random = new Random(System.currentTimeMillis());
    log.info("Mock ManagedKafka Factory:: Running Simulation");
    // feed the start of clusters
    if (this.kafkas.size() == 0) {
        int max = Math.abs(random.nextInt(maxKafkas));
        for (int i = 0; i < max; i++) {
            ManagedKafka k = ManagedKafka.getDummyInstance(this.clusterIdGenerator.getAndIncrement());
            log.infof("Mock ManagedKafka Factory::marking %s for addition", k.getId());
            this.kafkas.put(k.getId(), k);
            mkClient.create(k);
        }
    }
    // delete a instance by random
    if (this.kafkas.size() > 1 && random.nextBoolean()) {
        int idx = Math.abs(random.nextInt(this.kafkas.size()));
        int i = 0;
        for (ManagedKafka k : kafkas.values()) {
            if (i++ < idx) {
                continue;
            } else {
                markForDeletion(k.getId());
                break;
            }
        }
    }
    // selectively add
    if (this.kafkas.size() < maxKafkas && random.nextBoolean()) {
        ManagedKafka k = ManagedKafka.getDummyInstance(this.clusterIdGenerator.getAndIncrement());
        log.infof("Mock ManagedKafka Factory:: creating a new cluster %s ", k.getId());
        this.kafkas.put(k.getId(), k);
        mkClient.create(k);
    }
    log.info("--------------------------------------------------");
    for (ManagedKafka mk : this.kafkas.values()) {
        log.infof("ManagedKafka: %s, delete requested: %s", mk.getId(), mk.getSpec().isDeleted());
    }
    log.info("--------------------------------------------------");
}
Also used : ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka) Random(java.util.Random) Scheduled(io.quarkus.scheduler.Scheduled)

Example 4 with Clusters

use of org.bf2.cos.fleetshard.support.resources.Clusters in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class ManagedKafkaProvisioner method removeClusters.

/**
 * Removes kafka cluster
 *
 * @throws IOException
 */
public void removeClusters(boolean all) throws IOException {
    var client = cluster.kubeClient().client().resources(ManagedKafka.class).inNamespace(Constants.KAFKA_NAMESPACE);
    List<ManagedKafka> kafkas = clusters;
    if (all) {
        kafkas = client.list().getItems();
    }
    Iterator<ManagedKafka> kafkaIterator = clusters.iterator();
    while (kafkaIterator.hasNext()) {
        ManagedKafka k = kafkaIterator.next();
        LOGGER.info("Removing cluster {}", k.getMetadata().getName());
        client.withName(k.getMetadata().getName()).withPropagationPolicy(DeletionPropagation.FOREGROUND).delete();
    }
    for (ManagedKafka k : kafkas) {
        org.bf2.test.TestUtils.waitFor("await delete deployment", 1_000, 600_000, () -> client.withName(k.getMetadata().getName()).get() == null);
    }
    clusters.clear();
}
Also used : ManagedKafka(org.bf2.operator.resources.v1alpha1.ManagedKafka)

Aggregations

ManagedKafka (org.bf2.operator.resources.v1alpha1.ManagedKafka)3 Scheduled (io.quarkus.scheduler.Scheduled)2 Random (java.util.Random)2 ManagedKafkaList (org.bf2.operator.resources.v1alpha1.ManagedKafkaList)1