Search in sources :

Example 1 with DeploymentStage

use of com.aws.greengrass.deployment.model.Deployment.DeploymentStage in project aws-greengrass-nucleus by aws-greengrass.

the class Kernel method parseArgs.

/**
 * Parse kernel arguments and initialized configuration.
 *
 * @param args CLI args
 * @return Kernel instance
 */
@SuppressWarnings("PMD.MissingBreakInSwitch")
public Kernel parseArgs(String... args) {
    kernelCommandLine.parseArgs(args);
    config.lookupTopics(SERVICES_NAMESPACE_TOPIC, MAIN_SERVICE_NAME, SERVICE_LIFECYCLE_NAMESPACE_TOPIC);
    BootstrapManager bootstrapManager = kernelCommandLine.getBootstrapManager();
    DeploymentDirectoryManager deploymentDirectoryManager = kernelCommandLine.getDeploymentDirectoryManager();
    KernelAlternatives kernelAlts = context.get(KernelAlternatives.class);
    DeploymentStage stage = kernelAlts.determineDeploymentStage(bootstrapManager, deploymentDirectoryManager);
    String configFileName = "";
    switch(stage) {
        case KERNEL_ACTIVATION:
        case BOOTSTRAP:
            try {
                Path configPath = deploymentDirectoryManager.getTargetConfigFilePath();
                if (!Files.exists(configPath)) {
                    logger.atError().kv(DEPLOYMENT_STAGE_LOG_KEY, stage).kv("targetConfigFile", configPath).log("Detected ongoing deployment, but target configuration file not found");
                    break;
                }
                configFileName = configPath.toString();
                deploymentStageAtLaunch = stage;
            } catch (IOException e) {
                logger.atError().kv(DEPLOYMENT_STAGE_LOG_KEY, stage).log("Detected ongoing deployment, but failed to load target configuration file", e);
            }
            break;
        case KERNEL_ROLLBACK:
            try {
                Path configPath = deploymentDirectoryManager.getSnapshotFilePath();
                if (!Files.exists(configPath)) {
                    logger.atError().kv(DEPLOYMENT_STAGE_LOG_KEY, stage).kv("rollbackConfigFile", configPath).log("Detected ongoing deployment, but rollback configuration not found");
                    break;
                }
                configFileName = configPath.toString();
                deploymentStageAtLaunch = stage;
            } catch (IOException e) {
                logger.atError().kv(DEPLOYMENT_STAGE_LOG_KEY, stage).log("Detected ongoing deployment, but failed to load rollback configuration file", e);
            }
            break;
        default:
            logger.atInfo().log("No ongoing deployment detected. Proceed as default");
    }
    if (Utils.isEmpty(configFileName)) {
        kernelLifecycle.initConfigAndTlog();
    } else {
        kernelLifecycle.initConfigAndTlog(configFileName);
    }
    // Update device configuration from commandline arguments after loading config files
    DeviceConfiguration deviceConfiguration = getContext().get(DeviceConfiguration.class);
    kernelCommandLine.updateDeviceConfiguration(deviceConfiguration);
    // After configuration is fully loaded, initialize Nucleus service config
    deviceConfiguration.initializeNucleusFromRecipe(kernelAlts);
    setupProxy();
    return this;
}
Also used : Path(java.nio.file.Path) BootstrapManager(com.aws.greengrass.deployment.bootstrap.BootstrapManager) DeploymentStage(com.aws.greengrass.deployment.model.Deployment.DeploymentStage) DeploymentDirectoryManager(com.aws.greengrass.deployment.DeploymentDirectoryManager) IOException(java.io.IOException) DeviceConfiguration(com.aws.greengrass.deployment.DeviceConfiguration)

Aggregations

DeploymentDirectoryManager (com.aws.greengrass.deployment.DeploymentDirectoryManager)1 DeviceConfiguration (com.aws.greengrass.deployment.DeviceConfiguration)1 BootstrapManager (com.aws.greengrass.deployment.bootstrap.BootstrapManager)1 DeploymentStage (com.aws.greengrass.deployment.model.Deployment.DeploymentStage)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1