protected void startWithKnifeAsync() { DynamicTasks.queue( ChefServerTasks.knifeConvergeTask() .knifeRunList(Strings.join(Preconditions.checkNotNull(entity().getConfig(ChefConfig.CHEF_RUN_LIST), "%s must be supplied for %s", ChefConfig.CHEF_RUN_LIST, entity()), ",")) .knifeAddAttributes(entity().getConfig(CHEF_LAUNCH_ATTRIBUTES)) .knifeRunTwice(entity().getConfig(CHEF_RUN_CONVERGE_TWICE)) ); }
/** default pre-start hooks, can be extended by subclasses if needed*/ protected void preStartCustom(MachineLocation machine) { ConfigToAttributes.apply(entity()); // Opportunity to block startup until other dependent components are available Object val = entity().getConfig(SoftwareProcess.START_LATCH); if (val != null) log.debug("{} finished waiting for start-latch; continuing...", entity(), val); }
@Override protected String startProcessesAtMachine(Supplier<MachineLocation> machineS) { ChefModes mode = entity().getConfig(ChefConfig.CHEF_MODE); if (mode == ChefModes.AUTODETECT) { ProcessTaskWrapper<Boolean> installCheck = DynamicTasks.queue( ChefServerTasks.isKnifeInstalled()); mode = installCheck.get() ? ChefModes.KNIFE : ChefModes.SOLO; log.debug("Using Chef in "+mode+" mode due to autodetect exit code "+installCheck.getExitCode()); } switch (mode) { case KNIFE: startWithKnifeAsync(); break; case SOLO: startWithChefSoloAsync(); break; default: throw new IllegalStateException("Unknown Chef mode "+mode+" when starting processes for "+entity()); } return "chef start tasks submitted ("+mode+")"; }
protected void postStartCustom() { super.postStartCustom(); // now run the creation script String creationScript; String creationScriptUrl = entity().getConfig(PostgreSqlNode.CREATION_SCRIPT_URL); if (creationScriptUrl != null) creationScript = ResourceUtils.create(entity()).getResourceAsString(creationScriptUrl); else creationScript = entity().getConfig(PostgreSqlNode.CREATION_SCRIPT_CONTENTS); entity().invoke(PostgreSqlNodeChefImpl.EXECUTE_SCRIPT, ConfigBag.newInstance().configure(ExecuteScriptEffectorBody.SCRIPT, creationScript).getAllConfig()).getUnchecked(); // and finally connect sensors ((PostgreSqlNodeChefImpl)entity()).connectSensors(); } protected void preStopCustom() {
protected void startWithChefSoloAsync() { // TODO make directories more configurable (both for ssh-drivers and for this) String installDir = Urls.mergePaths(AbstractSoftwareProcessSshDriver.BROOKLYN_HOME_DIR, "chef-install"); String runDir = Urls.mergePaths(AbstractSoftwareProcessSshDriver.BROOKLYN_HOME_DIR, "apps/"+entity().getApplicationId()+"/chef-entities/"+entity().getId()); DynamicTasks.queue( ChefSoloTasks.installChef(installDir, false), ChefSoloTasks.installCookbooks(installDir, ChefConfigs.getRequiredConfig(entity(), CHEF_COOKBOOKS), false)); DynamicTasks.queue(ChefSoloTasks.buildChefFile(runDir, installDir, "launch", ChefConfigs.getRequiredConfig(entity(), CHEF_RUN_LIST), entity().getConfig(CHEF_LAUNCH_ATTRIBUTES))); DynamicTasks.queue(ChefSoloTasks.runChef(runDir, "launch", entity().getConfig(CHEF_RUN_CONVERGE_TWICE))); }