/** convenience for subclasses to specify that an app should run, * throwing the right (caught) error if another app has already been specified */ protected void setAppToLaunch(String className) { if (app!=null) { if (app.equals(className)) return; throw new FatalConfigurationRuntimeException("Cannot specify app '"+className+"' when '"+app+"' is already specified; " + "remove one or more conflicting CLI arguments."); } app = className; }
protected void execCli(Cli<Callable<?>> parser, String ...args) { try { log.debug("Parsing command line arguments: {}", Arrays.asList(args)); Callable<?> command = parser.parse(args); log.debug("Executing command: {}", command); command.call(); System.exit(SUCCESS); } catch (ParseException pe) { // looks like the user typed it wrong System.err.println("Parse error: " + pe.getMessage()); // display // error System.err.println(getUsageInfo(parser)); // display cli help System.exit(PARSE_ERROR); } catch (FatalConfigurationRuntimeException e) { log.error("Configuration error: "+e.getMessage(), e.getCause()); System.err.println("Configuration error: " + e.getMessage()); System.exit(CONFIGURATION_ERROR); } catch (FatalRuntimeException e) { // anticipated non-configuration error log.error("Startup error: "+e.getMessage(), e.getCause()); System.err.println("Startup error: "+e.getMessage()); System.exit(EXECUTION_ERROR); } catch (Exception e) { // unexpected error during command execution log.error("Execution error: " + e.getMessage(), e); System.err.println("Execution error: " + e.getMessage()); if (!(e instanceof UserFacingException)) e.printStackTrace(); System.exit(EXECUTION_ERROR); } }
protected void runRebindFails(PersistMode persistMode, String dir, String errmsg) throws Exception { try { newLauncherDefault(persistMode) .persistenceDir(dir) .start(); } catch (FatalConfigurationRuntimeException e) { if (!e.toString().contains(errmsg)) { throw e; } } }
private void checkCanReadPassword() { if (useStdin) { // yes; always } else { Console console = System.console(); if (console == null) { throw new FatalConfigurationRuntimeException("No console; cannot get password securely; aborting"); } } }
protected void execCli(Cli<BrooklynCommand> parser, String ...args) { try { log.debug("Parsing command line arguments: {}", Arrays.asList(args)); BrooklynCommand command = parser.parse(args); log.debug("Executing command: {}", command); command.call(); System.exit(SUCCESS); } catch (ParseException pe) { // looks like the user typed it wrong System.err.println("Parse error: " + pe.getMessage()); // display // error System.err.println(getUsageInfo(parser)); // display cli help System.exit(PARSE_ERROR); } catch (FatalConfigurationRuntimeException e) { log.error("Configuration error: "+e.getMessage(), e.getCause()); System.err.println("Configuration error: " + e.getMessage()); System.exit(CONFIGURATION_ERROR); } catch (FatalRuntimeException e) { // anticipated non-configuration error log.error("Startup error: "+e.getMessage(), e.getCause()); System.err.println("Startup error: "+e.getMessage()); System.exit(EXECUTION_ERROR); } catch (Exception e) { // unexpected error during command execution log.error("Execution error: " + e.getMessage(), e); System.err.println("Execution error: " + e.getMessage()); if (!(e instanceof UserFacingException)) e.printStackTrace(); System.exit(EXECUTION_ERROR); } }
protected File checkPersistenceDirPlausible(File dir) { checkNotNull(dir, "directory"); if (!dir.exists()) return dir; if (dir.isFile()) throw new FatalConfigurationRuntimeException("Invalid persistence directory" + dir + ": must not be a file"); if (!(dir.canRead() && dir.canWrite())) throw new FatalConfigurationRuntimeException("Invalid persistence directory" + dir + ": " + (!dir.canRead() ? "not readable" : (!dir.canWrite() ? "not writable" : "unknown reason"))); return dir; }
protected void checkPersistenceDirNonEmpty(File persistenceDir) { FatalConfigurationRuntimeException problem; if (!persistenceDir.exists()) { problem = new FatalConfigurationRuntimeException("Invalid persistence directory "+persistenceDir+" because directory does not exist"); log.debug("Invalid persistence directory "+persistenceDir+" (rethrowing): "+problem, problem); throw problem; } if (isMementoDirExistButEmpty(persistenceDir)) { problem = new FatalConfigurationRuntimeException("Invalid persistence directory "+persistenceDir+" because directory is empty"); log.debug("Invalid persistence directory "+persistenceDir+" (rethrowing): "+problem, problem); throw problem; } }
protected void checkPersistenceDirAccessible(File dir) { if (!(dir.exists() && dir.isDirectory() && dir.canRead() && dir.canWrite())) { FatalConfigurationRuntimeException problem = new FatalConfigurationRuntimeException("Invalid persistence directory " + dir + ": " + (!dir.exists() ? "does not exist" : (!dir.isDirectory() ? "not a directory" : (!dir.canRead() ? "not readable" : (!dir.canWrite() ? "not writable" : "unknown reason"))))); log.debug("Invalid persistence directory "+dir+" (rethrowing): "+problem, problem); } else { log.debug("Created dir {} for {}", dir, this); } }
protected PersistMode computePersistMode() { Maybe<PersistMode> persistMode = Enums.valueOfIgnoreCase(PersistMode.class, persist); if (!persistMode.isPresent()) { if (Strings.isBlank(persist)) { throw new FatalConfigurationRuntimeException("Persist mode must not be blank"); } else { throw new FatalConfigurationRuntimeException("Illegal persist setting: "+persist); } } if (persistMode.get() == PersistMode.DISABLED) { if (Strings.isNonBlank(persistenceDir)) throw new FatalConfigurationRuntimeException("Cannot specify persistenceDir when persist is disabled"); if (Strings.isNonBlank(persistenceLocation)) throw new FatalConfigurationRuntimeException("Cannot specify persistenceLocation when persist is disabled"); } return persistMode.get(); }
protected List<URL> getJarUrls() throws MalformedURLException, IOException { List<URL> urls = Lists.newArrayList(); if (!getJars().isEmpty()) { for (String jar : getJars()) { List<URL> expanded = ClassFinder.toJarUrls(jar); if (expanded.isEmpty()) LOG.warn("No jars found at: "+jar); urls.addAll(expanded); } } else if (yamlToScan.isEmpty()) { // NB: there is a better way; see comments on getTypes String classpath = System.getenv("INITIAL_CLASSPATH"); if (Strings.isNonBlank(classpath)) { List<String> entries = Splitter.on(":").omitEmptyStrings().trimResults().splitToList(classpath); for (String entry : entries) { if (entry.endsWith(".jar") || entry.endsWith("/*")) { urls.addAll(ClassFinder.toJarUrls(entry.replace("/*", ""))); } } } else { throw new FatalConfigurationRuntimeException("No JARs to process and could not infer from INITIAL_CLASSPATH env var."); } } return urls; } protected List<URL> getYamlUrls() throws MalformedURLException, IOException {
protected HighAvailabilityMode computeHighAvailabilityMode(PersistMode persistMode) { Maybe<HighAvailabilityMode> highAvailabilityMode = Enums.valueOfIgnoreCase(HighAvailabilityMode.class, highAvailability); if (!highAvailabilityMode.isPresent()) { if (Strings.isBlank(highAvailability)) { throw new FatalConfigurationRuntimeException("High availability mode must not be blank"); } else { throw new FatalConfigurationRuntimeException("Illegal highAvailability setting: "+highAvailability); } } if (highAvailabilityMode.get() != HighAvailabilityMode.DISABLED) { if (persistMode == PersistMode.DISABLED) { if (highAvailabilityMode.get() == HighAvailabilityMode.AUTO) return HighAvailabilityMode.DISABLED; throw new FatalConfigurationRuntimeException("Cannot specify highAvailability when persistence is disabled"); } else if (persistMode == PersistMode.CLEAN && (highAvailabilityMode.get() == HighAvailabilityMode.STANDBY || highAvailabilityMode.get() == HighAvailabilityMode.HOT_STANDBY || highAvailabilityMode.get() == HighAvailabilityMode.HOT_BACKUP)) { throw new FatalConfigurationRuntimeException("Cannot specify highAvailability "+highAvailabilityMode.get()+" when persistence is CLEAN"); } } return highAvailabilityMode.get(); }
throw new FatalConfigurationRuntimeException("Error using existing persistence directory "+dir.getAbsolutePath(), e); throw new FatalConfigurationRuntimeException("Error backing up persistence directory "+dir.getAbsolutePath(), e); throw new FatalConfigurationRuntimeException("Error backing up persistence directory "+dir.getAbsolutePath(), e); throw new FatalConfigurationRuntimeException("Unexpected persist mode "+persistMode+"; modified during initialization?!"); }; FileUtil.setFilePermissionsTo700(dir); } else { throw new FatalConfigurationRuntimeException("Failed to create persistence directory "+dir);
List<JcloudsLocation> locs = Lists.newArrayList(); if (location != null && allLocations) { throw new FatalConfigurationRuntimeException("Must not specify --location and --all-locations"); } else if (location != null) { JcloudsLocation loc = (JcloudsLocation) managementContext.getLocationRegistry().getLocationManaged(location); throw new FatalConfigurationRuntimeException("Must specify one of --location or --all-locations");
protected static List<Map<String, Object>> getAsListOfMaps(Entity entity, ConfigKey<Object> key) { Object config = entity.getConfig(key); Maybe<Map<String, Object>> maybeMap = TypeCoercions.tryCoerce(config, new TypeToken<Map<String, Object>>() {}); if (maybeMap.isPresent()) { return Collections.singletonList(maybeMap.get()); } Maybe<List<Map<String, Object>>> maybeList = TypeCoercions.tryCoerce(config, new TypeToken<List<Map<String, Object>>>() {}); if (maybeList.isPresent()) { return maybeList.get(); } throw new FatalConfigurationRuntimeException(key.getDescription() + " is not a map or list of maps"); }
throw e; } catch (Exception e) { throw new FatalConfigurationRuntimeException("Fatal error configuring Brooklyn launch: "+e.getMessage(), e);
throw new FatalConfigurationRuntimeException("Application class "+clazz+" must be an Application or Entity");
throw e; } catch (Exception e) { throw new FatalConfigurationRuntimeException("Fatal error configuring Brooklyn launch: "+e.getMessage(), e);
throw e; } catch (Exception e) { throw new FatalConfigurationRuntimeException("Fatal error configuring Brooklyn launch: "+e.getMessage(), e);
} else { if (objectStore==null) throw new FatalConfigurationRuntimeException("Cannot run in HA mode when no persistence configured.");