本文整理汇总了Java中net.neoremind.sshxcute.core.SSHExec.exec方法的典型用法代码示例。如果您正苦于以下问题:Java SSHExec.exec方法的具体用法?Java SSHExec.exec怎么用?Java SSHExec.exec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.neoremind.sshxcute.core.SSHExec
的用法示例。
在下文中一共展示了SSHExec.exec方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: validateDownloadUrl
import net.neoremind.sshxcute.core.SSHExec; //导入方法依赖的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);
}
示例2: extractNewAgent
import net.neoremind.sshxcute.core.SSHExec; //导入方法依赖的package包/类
private void extractNewAgent(SSHExec connection) throws AnkushException {
try {
AnkushTask ankushTask = new MakeDirectory(NEW_AGENT_FOLDER);
if (connection.exec(ankushTask).rc != 0) {
throw new AnkushException(
"Could not create directory for new agent bundle.");
}
ankushTask = new Untar(NEW_AGENT_TAR, NEW_AGENT_FOLDER, false);
if (connection.exec(ankushTask).rc != 0) {
throw new AnkushException("Could not extract agent bundle.");
}
} catch (TaskExecFailException e) {
throw new AnkushException(
"Could not execute task for extracting agent bundle.");
}
}
示例3: action
import net.neoremind.sshxcute.core.SSHExec; //导入方法依赖的package包/类
/**
* Action.
*
* @param connection
* the connection
* @param commands
* the commands
* @return true, if successful
* @author hokam chauhan
*/
public static boolean action(SSHExec connection, String... commands) {
CustomTask execTask = new ExecCommand(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;
}
示例4: executeTasks
import net.neoremind.sshxcute.core.SSHExec; //导入方法依赖的package包/类
/**
* Method to execute list of tasks. If any one fails it return backs the
* result of failed task otherwise the last task result.
*
* @param tasks
* @return
*/
public static Result executeTasks(List<AnkushTask> tasks, SSHExec connection) {
Result result = null;
try {
// iterating over the tasks.
for (AnkushTask task : tasks) {
// executing command
result = connection.exec(task);
// if command execution failed break the for loop
if (result.rc != 0) {
break;
}
}
} catch (Exception e) {
logger.error("Could not execute the tasks.", e);
}
// returning result.
return result;
}
示例5: addTaskables
import net.neoremind.sshxcute.core.SSHExec; //导入方法依赖的package包/类
/**
* Method to add the taskable class names in taskable conf file.
*
* @param connection
* @param className
* @return
*/
public static boolean addTaskables(SSHExec connection, List<String> classes)
throws AnkushException {
try {
// empty buffer string for taskable.
StringBuffer taskFileContent = new StringBuffer();
// appending the line separator.
taskFileContent.append(Constant.Strings.LINE_SEPERATOR);
for (String className : classes) {
// appending class name and line separator.
taskFileContent.append(className)
.append(Constant.Strings.LINE_SEPERATOR);
}
// add task information in taskable conf.
AnkushTask task = new AppendFileUsingEcho(
taskFileContent.toString(),
Constant.Agent.AGENT_TASKABLE_FILE_PATH);
return connection.exec(task).rc == 0;
} catch (Exception e) {
throw new AnkushException("Could not add taskable classes to "
+ Constant.Agent.AGENT_TASKABLE_FILE_PATH);
}
}
示例6: getFileContents
import net.neoremind.sshxcute.core.SSHExec; //导入方法依赖的package包/类
public static String getFileContents(String filePath, SSHExec connection) {
String output = null;
try {
if (connection == null) {
logger.error("Invalid connection");
return null;
}
CustomTask task = new ExecCommand("cat " + filePath);
Result res = connection.exec(task);
/* Executing the command. */
if (res.rc != 0) {
logger.error("Unable to read file " + filePath + ".");
return null;
} else {
output = res.sysout;
}
return output;
} catch (Exception e) {
logger.error("Unable to read file " + filePath + ".");
return null;
}
}
示例7: execCustomtask
import net.neoremind.sshxcute.core.SSHExec; //导入方法依赖的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;
}
示例8: rollBack
import net.neoremind.sshxcute.core.SSHExec; //导入方法依赖的package包/类
private void rollBack(SSHExec connection) {
try {
// Removing Agent upgrade directory, agent.zip, .newAgent folder and
// agnet installation path
List<String> dirs = new ArrayList<String>(Arrays.asList(
NODE_ANKUSH_HOME + "upgrade/", NODE_ANKUSH_HOME
+ AgentDeployer.AGENT_BUNDLE_NAME,
NEW_AGENT_FOLDER, clusterConfig.getAgentHomeDir()));
Remove remove;
for (String dir : dirs) {
remove = new Remove(dir);
connection.exec(remove);
}
// backup old existing agent folder.
Copy copyAgentBackup = new Copy(AGENT_BACKUP_FOLDER,
clusterConfig.getAgentHomeDir(), true);
if (connection.exec(copyAgentBackup).rc != 0) {
LOGGER.error("Could not copy Agent backup folder.");
}
} catch (TaskExecFailException e) {
LOGGER.error("Could not execute Agent rollback task.",
Constant.Component.Name.AGENT, nodeConfig.getHost(), e);
}
}
示例9: createRRDDirectories
import net.neoremind.sshxcute.core.SSHExec; //导入方法依赖的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);
}
}
示例10: stopJmxTrans
import net.neoremind.sshxcute.core.SSHExec; //导入方法依赖的package包/类
public boolean stopJmxTrans(ClusterConfig clusterConfig,
SSHExec connection, String host) throws AnkushException {
try {
final String command = JmxMonitoringUtil.getJmxTransCommand(
getJmxTransScriptFilePath(clusterConfig), null,
Constant.JmxTransServiceAction.STOP);
final AnkushTask task = new RunInBackground(command);
if (!connection.exec(task).isSuccess) {
logger.warn(
"Could not stop jmxtrans service for JMX monitoring.",
Constant.Component.Name.AGENT, host);
}
} catch (Exception e) {
logger.error("Could not stop Jmxtrans",
Constant.Component.Name.AGENT, host, e);
}
return true;
}
示例11: manageGmond
import net.neoremind.sshxcute.core.SSHExec; //导入方法依赖的package包/类
public boolean manageGmond(ClusterConfig clusterConfig, SSHExec connection,
Constant.ServiceAction action, String service) {
String errMsg = "Could not " + action.toString().toLowerCase() + " "
+ service;
String command;
if (action.equals(Constant.ServiceAction.START)) {
logger.info("Starting " + service, getComponentName());
command = GangliaConstants.GangliaExecutables.GMOND
+ " --conf="
+ advanceConf
.get(GangliaConstants.ClusterProperties.GMOND_CONF_PATH);
} else {
logger.info("Stopping " + service, getComponentName());
command = "killall -9 " + GangliaConstants.GangliaExecutables.GMOND;
}
CustomTask task = new ExecCommand(command);
try {
if (connection.exec(task).rc != 0) {
logger.error(errMsg, getComponentName());
return false;
}
} catch (TaskExecFailException e) {
logger.error(errMsg, getComponentName());
return false;
}
return true;
}
示例12: createServiceXML
import net.neoremind.sshxcute.core.SSHExec; //导入方法依赖的package包/类
private static boolean createServiceXML(SSHExec connection,
ServiceConfiguration serviceConfiguration, String technology,
String agentHomeDir) {
try {
String outputFile = agentHomeDir
+ AgentConstant.Relative_Path.SERVICE_CONF_DIR
+ technology.replace(" ", "\\ ") + ".xml";
// java XML context object.
JAXBContext jc = JAXBContext
.newInstance(ServiceConfiguration.class);
// Creating marshaller
Marshaller marshaller = jc.createMarshaller();
// Setting output format
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
// Creating string writer for getting XML object string to write.
StringWriter stringWriter = new StringWriter();
// Marshalling object.
marshaller.marshal(serviceConfiguration, stringWriter);
// XML content.
String xmlString = stringWriter.getBuffer().toString();
// clear file task.
AnkushTask clearFile = new ClearFile(outputFile);
// Creating technology XML file at services conf folder.
AnkushTask task = new AppendFileUsingEcho(xmlString.replaceAll(
"\\\"", "\\\\\""), outputFile);
// return execution status.
return (connection.exec(clearFile).rc == 0 && connection.exec(task).rc == 0);
} catch (Exception e) {
return false;
}
}
示例13: getFileContents
import net.neoremind.sshxcute.core.SSHExec; //导入方法依赖的package包/类
public static String getFileContents(SSHExec connection, String filePath)
throws Exception {
String output = null;
Result res = connection.exec(new ExecCommand("cat " + filePath));
output = res.sysout;
return output;
}
示例14: addConfigurationProperties
import net.neoremind.sshxcute.core.SSHExec; //导入方法依赖的package包/类
/**
* Adds the configuration properties.
*
* @param nameValuePair
* the name value pair
* @param filePath
* the file path
* @param connection
* the connection
* @return true, if successful
*/
public static boolean addConfigurationProperties(
Map<String, Object> nameValuePair, String filePath,
SSHExec connection) {
AnkushTask configureXml = null;
Result result = null;
// iterating over map
for (Map.Entry<String, Object> entry : nameValuePair.entrySet()) {
LOG.debug("Key = " + entry.getKey() + ", Value = "
+ entry.getValue());
// configuring xml
configureXml = new AddConfProperty(entry.getKey(),
(String) entry.getValue(), filePath,
Constant.File_Extension.XML);
try {
result = connection.exec(configureXml);
if (!result.isSuccess) {
return false;
}
} catch (TaskExecFailException e) {
LOG.error(e.getMessage());
return false;
}
}
return true;
}
示例15: downloadFile
import net.neoremind.sshxcute.core.SSHExec; //导入方法依赖的package包/类
/**
* Method to Get the path of log file for Downloading.
*
* @param clusterName
* Name of the cluster.
* @param filePath
* Path of the file on remote machine.
* @return Path of the log file for Download.
* @throws Exception
* the exception
*/
public String downloadFile(String clusterName, String filePath,
String agentInstallDir) throws AnkushException, Exception {
// Getting the log file content with total read count value.
SSHExec conn = SSHUtils.connectToNode(hostname, username, authInfo,
privateKey);
// String command = "java -cp $HOME/.ankush/agent/libs/*:$HOME/.ankush/agent/libs/agent-0.1.jar"
// + " com.impetus.ankush.agent.action.ActionHandler upload "
// + filePath;
StringBuilder command = new StringBuilder().append(AgentUtils
.getActionHandlerCommand(agentInstallDir));
command.append("upload").append(" ").append(filePath);
ExecCommand task = new ExecCommand(command.toString());
if (conn != null) {
Result rs = conn.exec(task);
if (rs.rc != 0) {
conn.disconnect();
throw new AnkushException(rs.error_msg);
} else {
conn.disconnect();
// Getting the file name for file path.
String fileName = FilenameUtils.getName(filePath);
// Getting the cluster folder path.
String downloadPath = "/public/clusters/logs/" + fileName
+ ".zip";
// return the down-load path
return downloadPath;
}
}
// return the down-load path
throw new Exception("Unable to connect to node.");
}