private int parseConfiggedPort(String portStr) throws BadFencingConfigurationException { try { return Integer.parseInt(portStr); } catch (NumberFormatException nfe) { throw new BadFencingConfigurationException( "Port number '" + portStr + "' invalid"); } } }
@Test public void testCheckNoArgs() { try { Configuration conf = new Configuration(); new NodeFencer(conf, "shell"); fail("Didn't throw when passing no args to shell"); } catch (BadFencingConfigurationException confe) { assertTrue( "Unexpected exception:" + StringUtils.stringifyException(confe), confe.getMessage().contains("No argument passed")); } }
@Test public void testCheckNoArgs() { try { Configuration conf = new Configuration(); new NodeFencer(conf, "shell"); fail("Didn't throw when passing no args to shell"); } catch (BadFencingConfigurationException confe) { assertTrue( "Unexpected exception:" + StringUtils.stringifyException(confe), confe.getMessage().contains("No argument passed")); } }
@Override public void checkArgs(String args) throws BadFencingConfigurationException { if (args == null || args.isEmpty()) { throw new BadFencingConfigurationException( "No argument passed to 'shell' fencing method"); } // Nothing else we can really check without actually running the command }
@Test public void testCheckParensNoArgs() { try { Configuration conf = new Configuration(); new NodeFencer(conf, "shell()"); fail("Didn't throw when passing no args to shell"); } catch (BadFencingConfigurationException confe) { assertTrue( "Unexpected exception:" + StringUtils.stringifyException(confe), confe.getMessage().contains("Unable to parse line: 'shell()'")); } }
public Args(String arg) throws BadFencingConfigurationException { user = System.getProperty("user.name"); sshPort = DEFAULT_SSH_PORT; // Parse optional user and ssh port if (arg != null && !arg.isEmpty()) { Matcher m = USER_PORT_RE.matcher(arg); if (!m.matches()) { throw new BadFencingConfigurationException( "Unable to parse user and SSH port: "+ arg); } if (m.group(1) != null) { user = m.group(1); } if (m.group(2) != null) { sshPort = parseConfiggedPort(m.group(2)); } } }
@Test public void testCheckParensNoArgs() { try { Configuration conf = new Configuration(); new NodeFencer(conf, "shell()"); fail("Didn't throw when passing no args to shell"); } catch (BadFencingConfigurationException confe) { assertTrue( "Unexpected exception:" + StringUtils.stringifyException(confe), confe.getMessage().contains("Unable to parse line: 'shell()'")); } }
private static FenceMethodWithArg parseMethod(Configuration conf, String line) throws BadFencingConfigurationException { Matcher m; if ((m = CLASS_WITH_ARGUMENT.matcher(line)).matches()) { String className = m.group(1); String arg = m.group(2); return createFenceMethod(conf, className, arg); } else if ((m = CLASS_WITHOUT_ARGUMENT.matcher(line)).matches()) { String className = m.group(1); return createFenceMethod(conf, className, null); } else { throw new BadFencingConfigurationException( "Unable to parse line: '" + line + "'"); } }
private static FenceMethodWithArg createFenceMethod( Configuration conf, String clazzName, String arg) throws BadFencingConfigurationException { Class<?> clazz; try { // See if it's a short name for one of the built-in methods clazz = STANDARD_METHODS.get(clazzName); if (clazz == null) { // Try to instantiate the user's custom method clazz = Class.forName(clazzName); } } catch (Exception e) { throw new BadFencingConfigurationException( "Could not find configured fencing method " + clazzName, e); } // Check that it implements the right interface if (!FenceMethod.class.isAssignableFrom(clazz)) { throw new BadFencingConfigurationException("Class " + clazzName + " does not implement FenceMethod"); } FenceMethod method = (FenceMethod)ReflectionUtils.newInstance( clazz, conf); method.checkArgs(arg); return new FenceMethodWithArg(method, arg); }
@Override public void checkFencingConfigured() throws BadFencingConfigurationException { if (fenceConfigError != null) { throw fenceConfigError; } if (fencer == null) { throw new BadFencingConfigurationException( "No fencer configured for " + this); } }
@Override public void checkFencingConfigured() throws BadFencingConfigurationException { if (fenceConfigError != null) { throw fenceConfigError; } if (fencer == null) { throw new BadFencingConfigurationException( "No fencer configured for " + this); } }
@Override public void checkFencingConfigured() throws BadFencingConfigurationException { if (fenceConfigError != null) { throw fenceConfigError; } if (fencer == null) { throw new BadFencingConfigurationException( "No fencer configured for " + this); } }
@Override public void checkFencingConfigured() throws BadFencingConfigurationException { throw new BadFencingConfigurationException("Fencer not configured"); }
@Override public void checkFencingConfigured() throws BadFencingConfigurationException { throw new BadFencingConfigurationException("Fencer not configured"); }
@Override public void checkFencingConfigured() throws BadFencingConfigurationException { throw new BadFencingConfigurationException("Fencer not configured"); }
@Override public void checkArgs(String args) throws BadFencingConfigurationException { if (args == null || args.isEmpty()) { throw new BadFencingConfigurationException( "No argument passed to 'shell' fencing method"); } // Nothing else we can really check without actually running the command }
private int parseConfiggedPort(String portStr) throws BadFencingConfigurationException { try { return Integer.parseInt(portStr); } catch (NumberFormatException nfe) { throw new BadFencingConfigurationException( "Port number '" + portStr + "' invalid"); } } }
private Integer parseConfiggedPort(String portStr) throws BadFencingConfigurationException { try { return Integer.valueOf(portStr); } catch (NumberFormatException nfe) { throw new BadFencingConfigurationException( "Port number '" + portStr + "' invalid"); } } }
private Integer parseConfiggedPort(String portStr) throws BadFencingConfigurationException { try { return Integer.valueOf(portStr); } catch (NumberFormatException nfe) { throw new BadFencingConfigurationException( "Port number '" + portStr + "' invalid"); } } }
@Override public void checkArgs(String args) throws BadFencingConfigurationException { if (args == null || args.isEmpty()) { throw new BadFencingConfigurationException( "No argument passed to 'shell' fencing method"); } // Nothing else we can really check without actually running the command }