Search in sources :

Example 1 with AgentOption

use of de.cinovo.cloudconductor.api.model.AgentOption in project cloudconductor-agent-redhat by cinovo.

the class HeartBeatJob method run.

@Override
public void run() {
    HeartBeatJob.LOGGER.debug("Starting HeartBeatJob");
    AgentOption newOptions;
    try {
        newOptions = ServerCom.heartBeat();
    } catch (CloudConductorException e) {
        HeartBeatJob.LOGGER.error("Error getting options from server: ", e);
        return;
    }
    new OptionHandler(newOptions).run();
    try {
        if (AgentState.repoExecutionLock.tryLock()) {
            new RepoHandler().run();
        }
    } catch (ExecutionError e) {
        HeartBeatJob.LOGGER.error("Error updating repos: ", e);
    } finally {
        AgentState.repoExecutionLock.unlock();
    }
    HeartBeatJob.LOGGER.debug("Finished HeartBeatJob");
}
Also used : CloudConductorException(de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException) ExecutionError(de.cinovo.cloudconductor.agent.exceptions.ExecutionError) RepoHandler(de.cinovo.cloudconductor.agent.jobs.handler.RepoHandler) AgentOption(de.cinovo.cloudconductor.api.model.AgentOption) OptionHandler(de.cinovo.cloudconductor.agent.jobs.handler.OptionHandler)

Example 2 with AgentOption

use of de.cinovo.cloudconductor.api.model.AgentOption in project cloudconductor-agent-redhat by cinovo.

the class OptionHandler method run.

/**
 */
public void run() {
    OptionHandler.LOGGER.debug("Starting OptionHandler");
    AgentOption oldOptions = AgentState.getOptions();
    AgentState.setOptions(this.newOptions);
    // option timer
    if (// 
    (oldOptions == null) || (this.newOptions.getAliveTimer() != oldOptions.getAliveTimer()) || (this.newOptions.getAliveTimerUnit() != oldOptions.getAliveTimerUnit())) {
        OptionHandler.LOGGER.debug("Reseting OPTIONTIMER TO " + this.newOptions.getAliveTimer() + ":" + this.newOptions.getAliveTimerUnit());
        SchedulerService.instance.resetTask(HeartBeatJob.JOB_NAME, this.newOptions.getAliveTimer(), this.newOptions.getAliveTimerUnit());
    }
    // SSH KEYS
    switch(this.newOptions.getDoSshKeys()) {
        case OFF:
            OptionHandler.LOGGER.debug("OptionHandler: STOP SHH KEY");
            SchedulerService.instance.stop(AuthorizedKeysJob.JOB_NAME);
            break;
        case ONCE:
            OptionHandler.LOGGER.debug("OptionHandler: ONCE SHH KEY");
            SchedulerService.instance.stop(AuthorizedKeysJob.JOB_NAME);
            SchedulerService.instance.executeOnce(AuthorizedKeysJob.JOB_NAME);
            break;
        case REPEAT:
            if ((oldOptions == null) || (this.newOptions.getSshKeysTimer() != oldOptions.getSshKeysTimer()) || (this.newOptions.getSshKeysTimerUnit() != oldOptions.getSshKeysTimerUnit())) {
                OptionHandler.LOGGER.debug("OptionHandler: REPEAT SHH KEY");
                SchedulerService.instance.resetTask(AuthorizedKeysJob.JOB_NAME, this.newOptions.getSshKeysTimer(), this.newOptions.getSshKeysTimerUnit());
            } else if (!SchedulerService.instance.taskRunning(AuthorizedKeysJob.JOB_NAME)) {
                OptionHandler.LOGGER.debug("OptionHandler: STARTING TASK SHH KEY BECAUSE NOT RUNNING");
                SchedulerService.instance.resetTask(AuthorizedKeysJob.JOB_NAME, this.newOptions.getSshKeysTimer(), this.newOptions.getSshKeysTimerUnit());
            }
            break;
    }
    // FILE MANAGEMENT
    switch(this.newOptions.getDoFileManagement()) {
        case OFF:
            OptionHandler.LOGGER.debug("OptionHandler: STOP FILE MANAGEMENT");
            SchedulerService.instance.stop(FilesJob.JOB_NAME);
            break;
        case ONCE:
            OptionHandler.LOGGER.debug("OptionHandler: ONCE FILE MANAGEMENT");
            SchedulerService.instance.stop(FilesJob.JOB_NAME);
            SchedulerService.instance.executeOnce(FilesJob.JOB_NAME);
            break;
        case REPEAT:
            if ((oldOptions == null) || (this.newOptions.getFileManagementTimer() != oldOptions.getFileManagementTimer()) || (this.newOptions.getFileManagementTimerUnit() != oldOptions.getFileManagementTimerUnit())) {
                OptionHandler.LOGGER.debug("OptionHandler: REPEAT FILE MANAGEMENT");
            } else if (!SchedulerService.instance.taskRunning(FilesJob.JOB_NAME)) {
                OptionHandler.LOGGER.debug("OptionHandler: STARTING TASK FILE MANAGEMENT BECAUSE NOT RUNNING");
                SchedulerService.instance.resetTask(FilesJob.JOB_NAME, this.newOptions.getFileManagementTimer(), this.newOptions.getFileManagementTimerUnit());
            }
            break;
    }
    // PACKAGE MANAGEMENT
    switch(this.newOptions.getDoPackageManagement()) {
        case OFF:
            OptionHandler.LOGGER.debug("OptionHandler: STOP PKG MANAGEMENT");
            SchedulerService.instance.stop(DefaultJob.JOB_NAME);
            break;
        case ONCE:
            OptionHandler.LOGGER.debug("OptionHandler: ONCE PKG MANAGEMENT");
            SchedulerService.instance.stop(DefaultJob.JOB_NAME);
            SchedulerService.instance.executeOnce(DefaultJob.JOB_NAME);
            break;
        case REPEAT:
            if ((oldOptions == null) || (this.newOptions.getPackageManagementTimer() != oldOptions.getPackageManagementTimer()) || (this.newOptions.getPackageManagementTimerUnit() != oldOptions.getPackageManagementTimerUnit())) {
                OptionHandler.LOGGER.debug("OptionHandler: REPEAT PKG MANAGEMENT");
                SchedulerService.instance.resetTask(DefaultJob.JOB_NAME, this.newOptions.getPackageManagementTimer(), this.newOptions.getPackageManagementTimerUnit());
            } else if (!SchedulerService.instance.taskRunning(DefaultJob.JOB_NAME)) {
                OptionHandler.LOGGER.debug("OptionHandler: STARTING TASK PKG MANAGEMENT BECAUSE NOT RUNNING");
                SchedulerService.instance.resetTask(DefaultJob.JOB_NAME, this.newOptions.getPackageManagementTimer(), this.newOptions.getPackageManagementTimerUnit());
            }
            break;
    }
    OptionHandler.LOGGER.debug("Finished OptionHandler");
}
Also used : AgentOption(de.cinovo.cloudconductor.api.model.AgentOption)

Aggregations

AgentOption (de.cinovo.cloudconductor.api.model.AgentOption)2 ExecutionError (de.cinovo.cloudconductor.agent.exceptions.ExecutionError)1 OptionHandler (de.cinovo.cloudconductor.agent.jobs.handler.OptionHandler)1 RepoHandler (de.cinovo.cloudconductor.agent.jobs.handler.RepoHandler)1 CloudConductorException (de.cinovo.cloudconductor.api.lib.exceptions.CloudConductorException)1