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;
}
Aggregations