Search in sources :

Example 1 with Task

use of org.bf2.srs.fleetmanager.execution.manager.Task in project kas-fleetshard by bf2fc6cc711aee1a0c2a.

the class DrainCleanerTest method testKafkaAvailabilityDuringClusterUpgrade.

@Test
@Tag(TestTags.PERF)
void testKafkaAvailabilityDuringClusterUpgrade(TestInfo info) throws Exception {
    long throughput = 41943040;
    int numWorkers = 12;
    int topics = 10;
    int messageSize = 1024;
    int partitionsPerTopic = 205;
    int workerProducerRate = 40000;
    ensureClientClusterCapacityForWorkers(omb.getOmbCluster(), numWorkers, WORKER_SIZE, CPU_SIZE);
    workers = omb.deployWorkers(numWorkers);
    ManagedKafkaCapacity capacity = kafkaProvisioner.defaultCapacity(throughput);
    ManagedKafkaDeployment deployCluster = kafkaProvisioner.deployCluster("cluster1", capacity, AdopterProfile.VALUE_PROD);
    String bootstrapHosts = deployCluster.waitUntilReady();
    final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(2);
    Future<Integer> nodeDrain;
    Future<File> resultDone;
    try {
        nodeDrain = scheduler.schedule(() -> {
            // this thread simulates the OpenShift cluster upgrade
            LOGGER.info("PERFORMING SCHEDULED NODES DRAIN");
            kafkaProvisioner.getKubernetesCluster().kubeClient().getClusterWorkers().forEach(node -> {
                TestUtils.drainNode(kafkaProvisioner.getKubernetesCluster(), node.getMetadata().getName());
                TestUtils.waitUntilAllPodsReady(kafkaProvisioner.getKubernetesCluster(), deployCluster.getManagedKafka().getMetadata().getNamespace());
                TestUtils.setNodeSchedule(kafkaProvisioner.getKubernetesCluster(), node.getMetadata().getName(), true);
            });
            return 0;
        }, 2, TimeUnit.MINUTES);
        resultDone = scheduler.submit(() -> {
            OMBDriver driver = new OMBDriver().setReplicationFactor(3).setTopicConfig("min.insync.replicas=2\n").setCommonConfigWithBootstrapUrl(bootstrapHosts).setProducerConfig("acks=all\n").setConsumerConfig("auto.offset.reset=earliest\nenable.auto.commit=false\n");
            int producerConsumer = numWorkers / 2;
            LOGGER.info("PERFORMING OMB WORKLOAD");
            OMBWorkloadResult result = omb.runWorkload(instanceDir, driver, workers, new OMBWorkload().setName(info.getDisplayName()).setTopics(topics).setPartitionsPerTopic(partitionsPerTopic).setMessageSize(messageSize).setPayloadFile("src/test/resources/payload/payload-1Kb.data").setSubscriptionsPerTopic(1).setConsumerPerSubscription(producerConsumer).setProducersPerTopic(producerConsumer).setProducerRate(workerProducerRate).setConsumerBacklogSizeGB(0).setTestDurationMinutes(15));
            LOGGER.info("{}: results {}", info.getDisplayName(), result.getResultFile());
            LOGGER.info("COMPLETED OMB WORKLOAD");
            return result.getResultFile();
        });
        Integer podTaskRetVal = nodeDrain.get(25, TimeUnit.MINUTES);
        LOGGER.info("Node drain task return value: {}", podTaskRetVal.toString());
        File resultFile = resultDone.get(25, TimeUnit.MINUTES);
        LOGGER.info("Result file: {}", resultFile);
    } finally {
        scheduler.shutdown();
        scheduler.awaitTermination(1, TimeUnit.MINUTES);
    }
}
Also used : Quantity(io.fabric8.kubernetes.api.model.Quantity) KubeClusterResource(org.bf2.performance.framework.KubeClusterResource) TestTags(org.bf2.performance.framework.TestTags) BeforeEach(org.junit.jupiter.api.BeforeEach) ManagedKafkaCapacity(org.bf2.operator.resources.v1alpha1.ManagedKafkaCapacity) TestInfo(org.junit.jupiter.api.TestInfo) File(java.io.File) Executors(java.util.concurrent.Executors) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) TimeUnit(java.util.concurrent.TimeUnit) AfterEach(org.junit.jupiter.api.AfterEach) List(java.util.List) Future(java.util.concurrent.Future) Logger(org.apache.logging.log4j.Logger) BeforeAll(org.junit.jupiter.api.BeforeAll) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Tag(org.junit.jupiter.api.Tag) LogManager(org.apache.logging.log4j.LogManager) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ManagedKafkaCapacity(org.bf2.operator.resources.v1alpha1.ManagedKafkaCapacity) File(java.io.File) Test(org.junit.jupiter.api.Test) Tag(org.junit.jupiter.api.Tag)

Example 2 with Task

use of org.bf2.srs.fleetmanager.execution.manager.Task in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.

the class DeprovisionRegistryWorker method finallyExecute.

@Transactional
@Override
public void finallyExecute(Task aTask, WorkerContext ctl, Optional<Exception> error) throws RegistryNotFoundException, RegistryStorageConflictException {
    DeprovisionRegistryTask task = (DeprovisionRegistryTask) aTask;
    Optional<RegistryData> registry = storage.getRegistryById(task.getRegistryId());
    if (registry.isPresent()) {
        var reg = registry.get();
        // Failure - Could not delete tenant or update status
        // Try updating status to failed, otherwise user can retry.
        reg.setStatus(RegistryStatusValueDto.FAILED.value());
        // TODO Add failed_reason
        storage.createOrUpdateRegistry(reg);
        log.warn("Failed to deprovision Registry: {}", registry);
    } else {
        // SUCCESS
        log.debug("Registry (ID = {}) has been deleted.", task.getRegistryId());
    }
}
Also used : DeprovisionRegistryTask(org.bf2.srs.fleetmanager.execution.impl.tasks.deprovision.DeprovisionRegistryTask) RegistryData(org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData) Transactional(javax.transaction.Transactional)

Example 3 with Task

use of org.bf2.srs.fleetmanager.execution.manager.Task in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.

the class DeprovisionRegistryWorker method execute.

@Transactional
@Override
public void execute(Task aTask, WorkerContext ctl) throws RegistryStorageConflictException, RegistryNotFoundException, AccountManagementServiceException, TenantManagerServiceException {
    var task = (DeprovisionRegistryTask) aTask;
    var registryOptional = storage.getRegistryById(task.getRegistryId());
    if (registryOptional.isPresent()) {
        // FAILURE POINT 1
        var registry = registryOptional.get();
        RegistryDeploymentData registryDeployment = registry.getRegistryDeployment();
        // FAILURE POINT 2
        if (task.getRegistryTenantId() == null) {
            final var tenantId = registry.getId();
            TenantManagerConfig tenantManagerConfig = Utils.createTenantManagerConfig(registryDeployment);
            try {
                tms.deleteTenant(tenantManagerConfig, tenantId);
                log.debug("Tenant id='{}' delete request send.", tenantId);
            } catch (TenantNotFoundServiceException ex) {
                log.info("Tenant id='{}' does not exist (already deleted?).", tenantId);
            }
            task.setRegistryTenantId(tenantId);
        }
        /* Return AMS entitlement
             * FAILURE POINT 3
             * Recovery: We recover by setting the registry status to failed so we don't lose information
             *   and the process can be initiated again.
             * Reentrancy: If the registry was already returned, (i.e. failed in #3)
             *   we need to continue without raising an error, otherwise we will keep retrying.
             */
        if (!task.isAmsSuccess()) {
            final String subscriptionId = registry.getSubscriptionId();
            // TODO Workaround: Remove this once we have RHOSRTrial working.
            if (subscriptionId != null && RegistryInstanceTypeValueDto.of(registry.getInstanceType()) != RegistryInstanceTypeValueDto.EVAL) {
                try {
                    ams.deleteSubscription(subscriptionId);
                } catch (SubscriptionNotFoundServiceException ex) {
                    log.info("Subscription ID '{}' for tenant ID '{}' does not exist (already deleted?).", subscriptionId, task.getRegistryTenantId());
                }
            } else {
                log.debug("Deleting an eval instance {} without calling AMS.", registry.getId());
            }
            task.setAmsSuccess(true);
            log.debug("Subscription (id='{}') for Registry (id='{}') deleted.", subscriptionId, registry.getId());
        }
        /* Delete the registry from DB
             * FAILURE POINT 4
             * Recovery: We set the status to failed so it can be retried.
             * Reentrancy: This is the last step, so nothing to do.
             */
        storage.deleteRegistry(registry.getId());
    } else {
        log.warn("Registry id='{}' not found. Stopping.", task.getRegistryId());
        ctl.stop();
    }
}
Also used : DeprovisionRegistryTask(org.bf2.srs.fleetmanager.execution.impl.tasks.deprovision.DeprovisionRegistryTask) TenantNotFoundServiceException(org.bf2.srs.fleetmanager.spi.tenants.TenantNotFoundServiceException) SubscriptionNotFoundServiceException(org.bf2.srs.fleetmanager.spi.ams.SubscriptionNotFoundServiceException) RegistryDeploymentData(org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryDeploymentData) TenantManagerConfig(org.bf2.srs.fleetmanager.spi.tenants.model.TenantManagerConfig) Transactional(javax.transaction.Transactional)

Example 4 with Task

use of org.bf2.srs.fleetmanager.execution.manager.Task in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.

the class EvalInstanceExpirationRegistryWorker method execute.

@Transactional
@Override
public void execute(Task aTask, WorkerContext ctx) {
    EvalInstanceExpirationRegistryTask task = (EvalInstanceExpirationRegistryTask) aTask;
    // Nothing to do, the heavy lifting is done by the deprovisioning task.
    log.debug("Initiating deprovisioning of an eval instance, registry id = '{}'", task.getRegistryId());
    ctx.delay(() -> tasks.submit(DeprovisionRegistryTask.builder().registryId(task.getRegistryId()).build()));
}
Also used : EvalInstanceExpirationRegistryTask(org.bf2.srs.fleetmanager.execution.impl.tasks.deprovision.EvalInstanceExpirationRegistryTask) Transactional(javax.transaction.Transactional)

Example 5 with Task

use of org.bf2.srs.fleetmanager.execution.manager.Task in project srs-fleet-manager by bf2fc6cc711aee1a0c2a.

the class StartDeprovisionRegistryWorker method finallyExecute.

@Transactional
@Override
public void finallyExecute(Task aTask, WorkerContext ctl, Optional<Exception> error) throws RegistryNotFoundException, RegistryStorageConflictException {
    StartDeprovisionRegistryTask task = (StartDeprovisionRegistryTask) aTask;
    Optional<RegistryData> registryOptional = storage.getRegistryById(task.getRegistryId());
    if (registryOptional.isPresent()) {
        var registry = registryOptional.get();
        // SUCCESS STATE
        if (RegistryStatusValueDto.DEPROVISIONING_DELETING.value().equals(registry.getStatus()))
            return;
        // FAILURE
        // Nothing to do, user can retry
        log.warn("Failed to start deprovisioning of Registry '{}'. Check the status to see if the instance is stuck.", registry);
    } else {
        log.warn("Could not find Registry (ID = {}).", task.getRegistryId());
    }
}
Also used : StartDeprovisionRegistryTask(org.bf2.srs.fleetmanager.execution.impl.tasks.deprovision.StartDeprovisionRegistryTask) RegistryData(org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData) Transactional(javax.transaction.Transactional)

Aggregations

TestTask (org.bf2.srs.fleetmanager.execution.impl.tasks.TestTask)10 Test (org.junit.jupiter.api.Test)9 QuarkusTest (io.quarkus.test.junit.QuarkusTest)8 Transactional (javax.transaction.Transactional)8 RegistryData (org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryData)7 RegistryDeploymentData (org.bf2.srs.fleetmanager.storage.sqlPanacheImpl.model.RegistryDeploymentData)4 List (java.util.List)3 ProvisionRegistryTenantTask (org.bf2.srs.fleetmanager.execution.impl.tasks.ProvisionRegistryTenantTask)3 Duration (java.time.Duration)2 Instant (java.time.Instant)2 Collectors.toList (java.util.stream.Collectors.toList)2 ApplicationScoped (javax.enterprise.context.ApplicationScoped)2 Inject (javax.inject.Inject)2 DeprovisionRegistryTask (org.bf2.srs.fleetmanager.execution.impl.tasks.deprovision.DeprovisionRegistryTask)2 Task (org.bf2.srs.fleetmanager.execution.manager.Task)2 WorkerContext (org.bf2.srs.fleetmanager.execution.manager.WorkerContext)2 TenantNotFoundServiceException (org.bf2.srs.fleetmanager.spi.tenants.TenantNotFoundServiceException)2 TenantManagerConfig (org.bf2.srs.fleetmanager.spi.tenants.model.TenantManagerConfig)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2