private int parseConfiggedPort(String portStr) throws BadFencingConfigurationException { try { return Integer.parseInt(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 }
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)); } } }
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 { throw new BadFencingConfigurationException("Fencer not configured"); }
@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"); }
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"); } } }
@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 }
@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 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 }
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 }
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 + "'"); } }
/** * Test that the ZKFC won't run if fencing is not configured for the * local service. */ @Test(timeout=15000) public void testFencingMustBeConfigured() throws Exception { DummyHAService svc = Mockito.spy(cluster.getService(0)); Mockito.doThrow(new BadFencingConfigurationException("no fencing")) .when(svc).checkFencingConfigured(); // Format the base dir, should succeed assertEquals(0, runFC(svc, "-formatZK")); // Try to run the actual FC, should fail without a fencer assertEquals(ZKFailoverController.ERR_CODE_NO_FENCER, runFC(svc)); }