本文整理汇总了Java中net.neoremind.sshxcute.task.CustomTask类的典型用法代码示例。如果您正苦于以下问题:Java CustomTask类的具体用法?Java CustomTask怎么用?Java CustomTask使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CustomTask类属于net.neoremind.sshxcute.task包,在下文中一共展示了CustomTask类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: runMultipleCommand
import net.neoremind.sshxcute.task.CustomTask; //导入依赖的package包/类
public static String runMultipleCommand(String cmd[]) throws TaskExecFailException
{
CustomTask task = new ExecCommand(cmd);
Result res = ssh.exec(task);
if (res.isSuccess)
{
System.out.println("Return code: " + res.rc);
System.out.println("sysout: " + res.sysout);
}
else
{
System.out.println("Return code: " + res.rc);
System.out.println("error message: " + res.error_msg);
return "error "+res.error_msg;
}
return res.sysout;
}
示例2: runSingleCommand
import net.neoremind.sshxcute.task.CustomTask; //导入依赖的package包/类
public static String runSingleCommand(String cmd) throws TaskExecFailException
{
CustomTask task = new ExecCommand(cmd);
Result res = ssh.exec(task);
if (res.isSuccess)
{
System.out.println("Return code: " + res.rc);
System.out.println("sysout: " + res.sysout);
}
else
{
System.out.println("Return code: " + res.rc);
System.out.println("error message: " + res.error_msg);
return "error "+res.error_msg;
}
return res.sysout;
}
示例3: executeRemoteCommand
import net.neoremind.sshxcute.task.CustomTask; //导入依赖的package包/类
/**
* Execute some remote tasks ...
*
* @param cmd
*/
public void executeRemoteCommand(String cmd) {
try {
// https://code.google.com/p/sshxcute/
System.out.println("\n[CMD]: " + cmd + "\n");
CustomTask ct1 = new ExecCommand( cmd );
ssh.exec(ct1);
System.out.println("\n[DONE]\n");
}
catch (Exception ex) {
Logger.getLogger(SOLRTool.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例4: getCommand
import net.neoremind.sshxcute.task.CustomTask; //导入依赖的package包/类
@Override
public String getCommand() {
String cmdList = new String();
for (final String command : this.commands) {
if (this.flagUseSudoOption) {
if(this.password != null) {
cmdList = cmdList + "echo \"" + this.password + "\" | sudo -S "
+ command;
} else {
cmdList = "sudo -S " + command;
}
} else {
cmdList = cmdList + command;
}
if (this.flagRunInBackGround) {
cmdList += " &";
}
cmdList += CustomTask.DELIMETER;
}
cmdList = (cmdList.length() == 0 ? "" : cmdList.substring(0,
cmdList.length() - 1));
return cmdList;
}
示例5: validateDownloadUrl
import net.neoremind.sshxcute.task.CustomTask; //导入依赖的package包/类
/**
* Method isValidPort.
*
* @param connection
* the connection
* @param url
* the url
* @return Map
*/
public static ValidationResult validateDownloadUrl(SSHExec connection,
String url) {
String errMsg = null;
boolean status = false;
CustomTask task = new UrlExists(url);
try {
Result rs = connection.exec(task);
if (rs.rc == 0) {
status = true;
} else {
errMsg = "Unable to access the download URL " + url;
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
return getResultMap(errMsg, status);
}
示例6: generateRSAKeyFiles
import net.neoremind.sshxcute.task.CustomTask; //导入依赖的package包/类
private static boolean generateRSAKeyFiles(String publicIp,
String username, String password, String privateKey)
throws TaskExecFailException {
CustomTask task = new ExecCommand(
"[[ -f ~/.ssh/id_rsa ]] || ssh-keygen -q -t rsa -P '' -f ~/.ssh/id_rsa; ");
SSHExec connection = SSHUtils.connectToNode(publicIp, username,
password, privateKey);
if (connection.exec(task).rc != 0) {
return false;
}
if (connection != null) {
connection.disconnect();
}
return true;
}
示例7: action
import net.neoremind.sshxcute.task.CustomTask; //导入依赖的package包/类
/**
* Action.
*
* @param passwword
* the passwword
* @param connection
* the connection
* @param commands
* the commands
* @return true, if successful
* @author hokam chauhan
*/
public static boolean action(String passwword, SSHExec connection,
String... commands) {
CustomTask execTask = new ExecSudoCommand(passwword, commands);
boolean done = false;
try {
if (connection != null) {
Result rs = connection.exec(execTask);
if (rs.rc == 0) {
done = true;
}
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
return done;
}
示例8: addProperties
import net.neoremind.sshxcute.task.CustomTask; //导入依赖的package包/类
public static boolean addProperties(SSHExec connection,
String agentHomeDir, Properties props) {
try {
// string buffer for configuration string.
StringBuffer fileContent = new StringBuffer();
// iterating over the props for creating configuration string.
for (String key : props.stringPropertyNames()) {
// appending key and value in string buffer.
fileContent.append(key).append("=")
.append(props.getProperty(key))
.append(Constant.Strings.LINE_SEPERATOR);
}
// creating append file task.
CustomTask task = new AppendFileUsingEcho(fileContent.toString()
.trim(), agentHomeDir
+ AgentConstant.Relative_Path.AGENT_CONF_FILE);
// executing task and returning status.
return connection.exec(task).rc == 0;
} catch (Exception e) {
return false;
}
}
示例9: getFileContents
import net.neoremind.sshxcute.task.CustomTask; //导入依赖的package包/类
public static String getFileContents(String filePath, NodeConfig host) {
String output = null;
try {
if (host.getConnection() == null) {
logger.error("Invalid connection for host - " + host.getHost());
return null;
}
CustomTask task = new ExecCommand("cat " + filePath);
Result res = host.getConnection().exec(task);
/* Executing the command. */
if (res.rc != 0) {
logger.error("Unable to read file " + filePath + " for host - "
+ host.getHost());
return null;
} else {
output = res.sysout;
}
return output;
} catch (Exception e) {
logger.error("Unable to read file " + filePath + " for host - "
+ host.getHost());
return null;
}
}
示例10: generateRSAKeyFiles
import net.neoremind.sshxcute.task.CustomTask; //导入依赖的package包/类
public static boolean generateRSAKeyFiles(NodeConfig host) {
try {
CustomTask task = new ExecCommand(
HadoopConstants.Command.GENERATE_RSA_KEYS);
if (host.getConnection().exec(task).rc != 0) {
logger.error("Unable to generate RSA Keys for host - "
+ host.getHost());
return false;
}
} catch (Exception e) {
logger.error("Unable to generate RSA Keys for host - "
+ host.getHost());
return false;
}
return true;
}
示例11: listFilesInDir
import net.neoremind.sshxcute.task.CustomTask; //导入依赖的package包/类
public static List<String> listFilesInDir(SSHExec connection, String host,
String dirPath, String regex) throws Exception {
dirPath = FileUtils.getSeparatorTerminatedPathEntry(dirPath);
String command = "cd " + dirPath + ";ls -p " + regex + " | grep -v /";
CustomTask listFiles = new ExecCommand(command);
Result res = connection.exec(listFiles);
if (res.rc != 0) {
throw new AnkushException(
"Could not get file list for directory - " + dirPath
+ " on host - " + host);
}
List<String> logFilesList = new ArrayList<String>();
logFilesList.addAll(Arrays.asList(res.sysout
.split(Constant.Strings.LINE_SEPERATOR)));
return logFilesList;
}
示例12: createRRDDirectories
import net.neoremind.sshxcute.task.CustomTask; //导入依赖的package包/类
/**
* Used to create RRD directory
*/
private boolean createRRDDirectories(String host, SSHExec connection,
boolean isGmetad) throws AnkushException {
try {
logger.info("Creating rrd directory.", getComponentName(), host);
// logging startup message.
String message = "Creating ganglia directories";
logger.info(message, getComponentName(), host);
CustomTask mkdirRRd = new MakeDirectory(
(String) advanceConf
.get(GangliaConstants.ClusterProperties.RRD_FILE_PATH));
return (connection.exec(mkdirRRd).rc == 0);
} catch (TaskExecFailException e) {
throw new AnkushException(
"Could not create RRD directory on $TYPE node: " + host);
}
}
示例13: execCustomtask
import net.neoremind.sshxcute.task.CustomTask; //导入依赖的package包/类
/**
* function to execute Custom Tasks and setting error if it fails
*
* @return <code>true</code>, if successful
*/
private boolean execCustomtask(String command, SSHExec connection,
String publicIp, String errMsg) {
// set clusterName in cassandra.yaml
try {
CustomTask task = new ExecCommand(command);
if (connection.exec(task).rc == 0) {
return true;
}
logger.warn(errMsg, getComponentName(), publicIp);
// addClusterError(errMsg, publicIp);
} catch (TaskExecFailException e) {
logger.warn(errMsg, getComponentName(), publicIp, e);
// addClusterError(errMsg, publicIp, e);
}
return false;
}
示例14: validate
import net.neoremind.sshxcute.task.CustomTask; //导入依赖的package包/类
@Override
public boolean validate() {
try {
if (!compConfig.getSource().isEmpty()) {
if (compConfig.getSourceType() == ComponentConfig.SourceType.LOCAL) {
logger.info("Validating local bundle existence-"
+ compConfig.getSource(), compName,
this.nodeConfig.getHost());
AnkushTask fileExist = new FileExists(
compConfig.getSource());
if (nodeConfig.getConnection().exec(fileExist).rc != 0) {
errMessage = "Could not find file "
+ compConfig.getSource()
+ ". Please specify the correct path.";
return false;
}
} else if (compConfig.getSourceType() == ComponentConfig.SourceType.DOWNLOAD) {
logger.info("Validating download url existence-"
+ compConfig.getSource(), compName,
this.nodeConfig.getHost());
CustomTask task = new UrlExists(compConfig.getSource());
Result rs = nodeConfig.getConnection().exec(task);
if (rs.rc != 0) {
errMessage = "Unable to access the download URL "
+ compConfig.getSource();
return false;
}
}
}else{
errMessage = "Please provide a valid source for the component.";
}
} catch (Exception e) {
errMessage = Constant.Strings.ExceptionsMessage.GENERIC_EXCEPTION_MSG;
logger.error(
Constant.Strings.ExceptionsMessage.GENERIC_EXCEPTION_MSG
+ e.getMessage(), e);
return false;
}
return true;
}
示例15: checkSudoers
import net.neoremind.sshxcute.task.CustomTask; //导入依赖的package包/类
protected boolean checkSudoers(String host) {
Result res = null;
// requires tty check by executing a sudo command
boolean status = false;
// String message =
// "Requiretty is enabled. Unable to get tty session on machine.";
// CustomTask ttyTask = new ExecSudoCommand(password,
// "grep 'requiretty' /etc/sudoers");
try {
SSHExec conn = null;
if (isAuthTypePass) {
conn = SSHUtils.connectToNode(host, userName, password, null);
} else {
conn = SSHUtils.connectToNode(host, userName, null, password);
}
// if (conn != null) {
// res = conn.exec(ttyTask);
// if(res.rc == 0){
// //check sudo command
// }
// }
CustomTask ttyTask = new ExecSudoCommand(password, "ls");
// if connected.
if (conn != null) {
Result rs;
rs = conn.exec(ttyTask);
status = (rs.rc == 0);
}
} catch (Exception e) {
logger.error(e.getMessage(), e);
status = false;
}
return status;
}