private void checkFileReadable(File f) { if (!f.exists()) { throw new FatalRuntimeException("File " + f + " does not exist"); } if (!f.isFile()) { throw new FatalRuntimeException(f + " is not a file"); } if (!f.canRead()) { throw new FatalRuntimeException(f + " is not readable"); } }
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); } }
@Test(groups="UNIX") public void testChecksGlobalBrooklynPropertiesPermissionsX00() throws Exception { File propsFile = File.createTempFile("testChecksGlobalBrooklynPropertiesPermissionsX00", ".properties"); propsFile.setReadable(true, false); try { new BrooklynPropertiesFactoryHelper(propsFile.getAbsolutePath(), null) .createPropertiesBuilder(); Assert.fail("Should have thrown"); } catch (FatalRuntimeException e) { if (!e.toString().contains("Invalid permissions for file")) throw e; } finally { propsFile.delete(); } }
@Test(groups="UNIX") public void testChecksLocalBrooklynPropertiesPermissionsX00() throws Exception { File propsFile = File.createTempFile("testChecksLocalBrooklynPropertiesPermissionsX00", ".properties"); propsFile.setReadable(true, false); try { new BrooklynPropertiesFactoryHelper(propsFile.getAbsolutePath(), null) .createPropertiesBuilder(); Assert.fail("Should have thrown"); } catch (FatalRuntimeException e) { if (!e.toString().contains("Invalid permissions for file")) throw e; } finally { propsFile.delete(); } }
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); } }
private void checkFilePermissionsX00(File f) { Maybe<String> permission = FileUtil.getFilePermissions(f); if (permission.isAbsent()) { LOG.debug("Could not determine permissions of file; assuming ok: "+f); } else { if (!permission.get().subSequence(4, 10).equals("------")) { throw new FatalRuntimeException("Invalid permissions for file " + f + "; expected ?00 but was " + permission.get()); } } }
private void startPersistenceWithoutHA() { RebindManager rebindManager = managementContext.getRebindManager(); if (Strings.isNonBlank(persistenceLocation)) LOG.info("Management node (no HA) rebinding to entities at "+persistenceLocation+" in "+persistenceDir); else LOG.info("Management node (no HA) rebinding to entities on file system in "+persistenceDir); ClassLoader classLoader = managementContext.getCatalogClassLoader(); try { rebindManager.rebind(classLoader, null, ManagementNodeState.MASTER); } catch (Exception e) { Exceptions.propagateIfFatal(e); LOG.debug("Error rebinding to persisted state (rethrowing): "+e, e); throw new FatalRuntimeException("Error rebinding to persisted state: "+ Exceptions.collapseText(e), e); } rebindManager.startPersistence(); }
public void handleException(Throwable throwable, Object details) { if (throwable instanceof InterruptedException) throw new RuntimeInterruptedException((InterruptedException) throwable); if (throwable instanceof RuntimeInterruptedException) throw (RuntimeInterruptedException) throwable; if (details instanceof CatalogItem) { if (((CatalogItem<?,?>)details).getCatalogItemId() != null) { details = ((CatalogItem<?,?>)details).getCatalogItemId(); } } PropagatedRuntimeException wrap = new PropagatedRuntimeException("Error loading catalog item "+details, throwable); log.warn(Exceptions.collapseText(wrap)); log.debug("Trace for: "+wrap, wrap); ((ManagementContextInternal)getManagementContext()).errors().add(wrap); if (isStartingUp && failOnStartupErrors) { throw new FatalRuntimeException("Unable to load catalog item "+details, wrap); } }
throw new FatalRuntimeException("Error starting applications: "+Exceptions.collapseText(t), t);
Exceptions.propagateIfFatal(e); LOG.debug("Error copying persisted state (rethrowing): " + e, e); throw new FatalRuntimeException("Error copying persisted state: " + Exceptions.collapseText(e), e);
Exceptions.propagateIfFatal(e); LOG.debug("Error initializing persistence subsystem (rethrowing): "+e, e); throw new FatalRuntimeException("Error initializing persistence subsystem: "+ Exceptions.collapseText(e), e);