/** Lists all slaves used by the master USAGE: SITE SLAVES */ public CommandResponse doSITE_SLAVES(CommandRequest request) { boolean showMore = request.hasArgument() && (request.getArgument().equalsIgnoreCase("more")); Collection<RemoteSlave> slaves = GlobalContext.getGlobalContext().getSlaveManager().getSlaves(); CommandResponse response = new CommandResponse(200, "OK, " + slaves.size() + " slaves listed."); int slavesFound = 0; String type; if (request.hasArgument()) { type = request.getArgument().toLowerCase(); } else { type = "r"; } for (RemoteSlave rslave : GlobalContext.getGlobalContext().getSlaveManager().getSlaves()) { String name = rslave.getName().toLowerCase(); if ((!name.contains(type)) && (!type.equals("all"))) continue; response = addSlaveStatus(request, response, showMore, rslave); slavesFound = slavesFound + 1; } if (slavesFound == 0) { response.addComment( request .getSession() .jprintf(_bundle, _keyPrefix + "slave.none", null, request.getUser())); } return response; }
public CommandResponse doRemergeque(CommandRequest request) throws ImproperUsageException { String slave; if (request.hasArgument()) { slave = request.getArgument().toLowerCase(); } else { slave = "all"; } ArrayList<String> arr = new ArrayList<String>(); for (RemoteSlave rslave : GlobalContext.getGlobalContext().getSlaveManager().getSlaves()) { if (!rslave.getName().contains(slave) && !slave.equals("all")) { continue; } int size = rslave.doRemergequeue(); if (!rslave.isOnline()) { arr.add(rslave.getName() + " is offline"); } else if (!rslave.isRemerging()) { arr.add(rslave.getName() + " remergeque is complete"); } else if (size > 0) { arr.add(rslave.getName() + " remergeque size is " + size); } else { arr.add(rslave.getName() + " remergeque size is 0 but remerge is ongoing"); } } arr.add("Total commit:" + CommitManager.getCommitManager().getQueueSize()); CommandResponse response = StandardCommandManager.genericResponse("RESPONSE_200_COMMAND_OK"); for (String str : arr) { response.addComment(str); } return response; }
/* * Prehook method for SLAVE ADDIP * Gets the ip, and preforms checks. */ public CommandRequestInterface doIpSecuritySLAVEPreCheck(CommandRequest request) { if (!request.hasArgument()) { return request; } String argument = request.getArgument(); StringTokenizer arguments = new StringTokenizer(argument); if (!arguments.hasMoreTokens()) { return request; } String slavename = arguments.nextToken(); RemoteSlave rslave = null; try { rslave = GlobalContext.getGlobalContext().getSlaveManager().getRemoteSlave(slavename); } catch (ObjectNotFoundException e) { request.setDeniedResponse(new CommandResponse(200, "Slave Not Found: " + slavename)); request.setAllowed(false); return request; } if (arguments.hasMoreTokens()) { String command = arguments.nextToken(); if (command.equalsIgnoreCase("addmask")) { if (arguments.countTokens() != 1) { return request; } HostMask newMask = new HostMask(arguments.nextToken().replace(",", "")); String _maskident = newMask.getIdentMask(); String _maskHostMask = newMask.getHostMask(); boolean _allowed = IpSecurityManager.getIpSecurity() .checkIP(_maskident, _maskHostMask, rslave.getMasks().size(), null); if ((!_allowed) && (!_maskHostMask.equals("127.0.0.1"))) { request.setAllowed(false); CommandResponse response = StandardCommandManager.genericResponse("RESPONSE_200_COMMAND_OK"); response.addComment(IpSecurityManager.getIpSecurity().outputConfs(null)); request.setDeniedResponse(response); return request; } } } return request; }
public CommandResponse doSITE_REMERGE(CommandRequest request) { if (!request.hasArgument()) { return StandardCommandManager.genericResponse("RESPONSE_501_SYNTAX_ERROR"); } RemoteSlave rslave; try { rslave = GlobalContext.getGlobalContext().getSlaveManager().getRemoteSlave(request.getArgument()); } catch (ObjectNotFoundException e) { return new CommandResponse(200, "No such slave"); } if (!rslave.isAvailable()) { return new CommandResponse(200, "Slave is still merging from initial connect"); } if (rslave.isRemerging()) { return new CommandResponse(200, "Slave is still remerging by a previous remerge command"); } boolean CRCRemerge = GlobalContext.getConfig() .getMainProperties() .getProperty("crc.remerge.mode", "true") .equals("true"); rslave.setRemerging(true); try { rslave.fetchResponse( SlaveManager.getBasicIssuer() .issueRemergeToSlave( rslave, request.getCurrentDirectory().getPath(), false, 0L, 0L, false, CRCRemerge), 0); } catch (RemoteIOException e) { rslave.setOffline("IOException during remerge()"); return new CommandResponse(200, "IOException during remerge()"); } catch (SlaveUnavailableException e) { rslave.setOffline("Slave Unavailable during remerge()"); return new CommandResponse(200, "Slave Unavailable during remerge()"); } finally { String message = ("Remerge queueprocess finished"); GlobalContext.getEventService().publishAsync(new SlaveEvent("MSGSLAVE", message, rslave)); rslave.setRemerging(false); } return StandardCommandManager.genericResponse("RESPONSE_200_COMMAND_OK"); }
public CommandResponse doSITE_KICKSLAVE(CommandRequest request) { Session session = request.getSession(); if (!request.hasArgument()) { return StandardCommandManager.genericResponse("RESPONSE_501_SYNTAX_ERROR"); } RemoteSlave rslave; try { rslave = GlobalContext.getGlobalContext().getSlaveManager().getRemoteSlave(request.getArgument()); } catch (ObjectNotFoundException e) { return new CommandResponse(200, "No such slave"); } if (!rslave.isOnline()) { return new CommandResponse(200, "Slave is already offline"); } rslave.setOffline("Slave kicked by " + session.getUserNull(request.getUser()).getName()); return StandardCommandManager.genericResponse("RESPONSE_200_COMMAND_OK"); }
private CommandResponse addSlaveStatus( CommandRequest request, CommandResponse response, boolean showMore, RemoteSlave rslave) { Session session = request.getSession(); if (showMore) { response.addComment(rslave.moreInfo()); } ReplacerEnvironment env = new ReplacerEnvironment(); env.add("slavename", rslave.getName()); try { env.add("slaveip", rslave.getPASVIP()); } catch (SlaveUnavailableException e) { env.add("slaveip", "OFFLINE"); } if (rslave.isOnline()) { if (!rslave.isAvailable()) { response.addComment( session.jprintf(_bundle, _keyPrefix + "slave.remerging", env, request.getUser())); } else { try { SlaveStatus status = rslave.getSlaveStatus(); fillEnvWithSlaveStatus(env, status); env.add("status", rslave.isRemerging() ? "REMERGING" : "ONLINE"); response.addComment( session.jprintf(_bundle, _keyPrefix + "slave.online", env, request.getUser())); } catch (SlaveUnavailableException e) { // should never happen since we tested slave status w/ isOnline and isAvaiable. throw new RuntimeException( "There's a bug somewhere in the code, the slave was available now it isn't.", e); } } } else { response.addComment( session.jprintf(_bundle, _keyPrefix + "slave.offline", env, request.getUser())); } return response; }
/** * Usage: site slave slavename [set,addmask,delmask] * * @throws ImproperUsageException */ public CommandResponse doSITE_SLAVE(CommandRequest request) throws ImproperUsageException { Session session = request.getSession(); CommandResponse response = StandardCommandManager.genericResponse("RESPONSE_200_COMMAND_OK"); ReplacerEnvironment env = new ReplacerEnvironment(); if (!request.hasArgument()) { throw new ImproperUsageException(); } String argument = request.getArgument(); StringTokenizer arguments = new StringTokenizer(argument); if (!arguments.hasMoreTokens()) { throw new ImproperUsageException(); } String slavename = arguments.nextToken(); env.add("slavename", slavename); RemoteSlave rslave = null; try { rslave = GlobalContext.getGlobalContext().getSlaveManager().getRemoteSlave(slavename); } catch (ObjectNotFoundException e) { response.addComment( session.jprintf(_bundle, _keyPrefix + "slave.notfound", env, request.getUser())); return response; } if (!arguments.hasMoreTokens()) { if (!rslave.getMasks().isEmpty()) { env.add("masks", rslave.getMasks()); response.addComment( session.jprintf(_bundle, _keyPrefix + "slave.masks", env, request.getUser())); } response.addComment( session.jprintf(_bundle, _keyPrefix + "slave.data.header", request.getUser())); Map<Object, Object> props = rslave.getProperties(); for (Entry<Object, Object> entry : props.entrySet()) { env.add("key", entry.getKey()); env.add("value", entry.getValue()); response.addComment( session.jprintf(_bundle, _keyPrefix + "slave.data", env, request.getUser())); } return response; } String command = arguments.nextToken(); if (command.equalsIgnoreCase("set")) { if (arguments.countTokens() != 2) { throw new ImproperUsageException(); } String key = arguments.nextToken(); String value = arguments.nextToken(); rslave.setProperty(key, value); env.add("key", key); env.add("value", value); response.addComment( session.jprintf(_bundle, _keyPrefix + "slave.set.success", env, request.getUser())); return response; } else if (command.equalsIgnoreCase("unset")) { if (arguments.countTokens() != 1) { throw new ImproperUsageException(); } String key = arguments.nextToken(); env.add("key", key); String value; try { value = rslave.removeProperty(key); } catch (KeyNotFoundException e) { response.addComment( session.jprintf(_bundle, _keyPrefix + "slave.unset.failure", env, request.getUser())); return response; } env.add("value", value); response.addComment( session.jprintf(_bundle, _keyPrefix + "slave.unset.success", env, request.getUser())); return response; } else if (command.equalsIgnoreCase("addmask")) { if (arguments.countTokens() != 1) { throw new ImproperUsageException(); } String mask = arguments.nextToken(); env.add("mask", mask); try { rslave.addMask(mask); response.addComment( session.jprintf(_bundle, _keyPrefix + "slave.addmask.success", env, request.getUser())); return response; } catch (DuplicateElementException e) { response = new CommandResponse( 501, session.jprintf( _bundle, _keyPrefix + "slave.addmask.dupe", env, request.getUser())); return response; } } else if (command.equalsIgnoreCase("delmask")) { if (arguments.countTokens() != 1) { throw new ImproperUsageException(); } String mask = arguments.nextToken(); env.add("mask", mask); if (rslave.removeMask(mask)) { return new CommandResponse( 200, session.jprintf(_bundle, _keyPrefix + "slave.delmask.success", env, request.getUser())); } return new CommandResponse( 501, session.jprintf(_bundle, _keyPrefix + "slave.delmask.failed", env, request.getUser())); } else if (command.equalsIgnoreCase("shutdown")) { rslave.shutdown(); return StandardCommandManager.genericResponse("RESPONSE_200_COMMAND_OK"); } throw new ImproperUsageException(); }