当前位置: 首页>>代码示例>>Java>>正文


Java SSHExec类代码示例

本文整理汇总了Java中net.neoremind.sshxcute.core.SSHExec的典型用法代码示例。如果您正苦于以下问题:Java SSHExec类的具体用法?Java SSHExec怎么用?Java SSHExec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SSHExec类属于net.neoremind.sshxcute.core包,在下文中一共展示了SSHExec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: SSHCommands

import net.neoremind.sshxcute.core.SSHExec; //导入依赖的package包/类
public SSHCommands()
{
	// Steps To Do
	// 1. create instance of ConnBean using ---> ConnBean conn=new ConnBean(ip,username,password) 
	// 2. Put the conn object to the static method getInstance() ---> SSHExec ssh=SSHExec.getInstance(conn)
	// 3. Connect to ssh server using ---> ssh.connect()
	// 4. Execute commands
	// 5. ssh.disconnect()
	
	Properties prop=new Properties();
	try {
		prop.load(SSHCommands.class.getResourceAsStream("/SSHinfo.properties"));
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	String ip=prop.getProperty("ip");
	String user=prop.getProperty("username");
	String password=prop.getProperty("password");
	conn = new ConnBean(ip,user,password);
	ssh=SSHExec.getInstance(conn);
	ssh.connect();
	SSHExec.setOption(IOptionName.INTEVAL_TIME_BETWEEN_TASKS, 0l);
}
 
开发者ID:jtatia,项目名称:Course-Management-System,代码行数:25,代码来源:SSHCommands.java

示例2: 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);
}
 
开发者ID:Impetus,项目名称:ankush,代码行数:27,代码来源:ValidationUtility.java

示例3: validatePathExistence

import net.neoremind.sshxcute.core.SSHExec; //导入依赖的package包/类
/**
 * Validate directory existence.
 * 
 * @param connection
 *            the connection
 * @param directoryPath
 *            the directory path
 * @return the validation result
 */
public static ValidationResult validatePathExistence(SSHExec connection,
		String directoryPath) {
	String errMsg = null;
	boolean status = true;
	try {

		// Check if directory already exist
		Result result = connection.exec(new ExecCommand("[ -a \""
				+ directoryPath + "\" ]"));
		// if not success set error message
		if (!result.isSuccess) {
			status = false;
			errMsg = directoryPath + " doesn't exist.";
		}
	} catch (Exception e) {
		errMsg = e.getMessage();
	}
	return getResultMap(errMsg, status);
}
 
开发者ID:Impetus,项目名称:ankush,代码行数:29,代码来源:ValidationUtility.java

示例4: generateRSAKeyFiles

import net.neoremind.sshxcute.core.SSHExec; //导入依赖的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;
}
 
开发者ID:Impetus,项目名称:ankush,代码行数:17,代码来源:SSHUtils.java

示例5: action

import net.neoremind.sshxcute.core.SSHExec; //导入依赖的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;
}
 
开发者ID:Impetus,项目名称:ankush,代码行数:30,代码来源:SSHUtils.java

示例6: 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;
}
 
开发者ID:Impetus,项目名称:ankush,代码行数:27,代码来源:SSHUtils.java

示例7: configureJmxPort

import net.neoremind.sshxcute.core.SSHExec; //导入依赖的package包/类
/**
 * Configure jmx port.
 * 
 * @param processName
 *            the process name
 * @param connection
 *            the connection
 * @param filePath
 *            the file path
 * @param jmxPort
 *            the jmx port
 * @param password
 *            the password
 * @return true, if successful
 */
public static boolean configureJmxPort(String processName,
		SSHExec connection, String filePath, int jmxPort, String password) {
	try {
		final String portText = "JMX_PORT_" + processName.toUpperCase();
		final String targetText = JmxMonitoringUtil.ankushConf
				.getStringValue("jmx." + processName.toLowerCase()
						+ ".targetText");
		String replacementText = JmxMonitoringUtil.ankushConf
				.getStringValue("jmx." + processName.toLowerCase()
						+ ".replacementText");
		replacementText = replacementText.replaceAll(portText,
				String.valueOf(jmxPort));
		Result res = null;
		final AnkushTask updateFile = new ReplaceText(targetText,
				replacementText, filePath, true, password);
		res = connection.exec(updateFile);
		if (!res.isSuccess) {
			return false;
		}
	} catch (final Exception e) {
		return false;
	}
	return true;
}
 
开发者ID:Impetus,项目名称:ankush,代码行数:40,代码来源:JmxMonitoringUtil.java

示例8: createConfiguratonXml

import net.neoremind.sshxcute.core.SSHExec; //导入依赖的package包/类
/**
 * Creates the configuraton xml.
 * 
 * @param filePath
 *            the file path
 * @param connection
 *            the connection
 * @return true, if successful
 */
public static boolean createConfiguratonXml(String filePath,
		SSHExec connection) {

	StringBuilder fileContents = new StringBuilder();
	fileContents.append("<configuration>").append("\n")
			.append("</configuration>");

	AnkushTask createConfFile = new AppendFileUsingEcho(
			fileContents.toString(), filePath);

	try {
		return connection.exec(createConfFile).isSuccess;
	} catch (TaskExecFailException e) {
		LOG.error(e.getMessage());
		return false;
	}
}
 
开发者ID:Impetus,项目名称:ankush,代码行数:27,代码来源:XmlUtil.java

示例9: 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;
}
 
开发者ID:Impetus,项目名称:ankush,代码行数:20,代码来源:AgentServiceManager.java

示例10: addProperties

import net.neoremind.sshxcute.core.SSHExec; //导入依赖的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;
	}
}
 
开发者ID:Impetus,项目名称:ankush,代码行数:23,代码来源:AgentUtils.java

示例11: 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);
	}
}
 
开发者ID:Impetus,项目名称:ankush,代码行数:30,代码来源:AgentUtils.java

示例12: 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.");
	}
}
 
开发者ID:Impetus,项目名称:ankush,代码行数:18,代码来源:AgentNodeUpgrader.java

示例13: 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);
	}
}
 
开发者ID:Impetus,项目名称:ankush,代码行数:27,代码来源:AgentNodeUpgrader.java

示例14: removeUpgradeAndBackupDir

import net.neoremind.sshxcute.core.SSHExec; //导入依赖的package包/类
private void removeUpgradeAndBackupDir(SSHExec connection,
		String upgradeScriptDirectory) {
	LOGGER.info("Removing agent upgrade script folder...",
			Constant.Component.Name.AGENT, nodeConfig.getHost());
	// remove agent upgrade script folder.
	Remove remove = new Remove(upgradeScriptDirectory);
	try {
		connection.exec(remove);

		// remove Agnet backup directory
		remove = new Remove(AGENT_BACKUP_FOLDER);
		connection.exec(remove);
	} catch (TaskExecFailException e) {
		LOGGER.error(
				"Could not execute task for removing Agent upgrade and backup directory.",
				Constant.Component.Name.AGENT, nodeConfig.getHost(), e);
	}
}
 
开发者ID:Impetus,项目名称:ankush,代码行数:19,代码来源:AgentNodeUpgrader.java

示例15: 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;
	}
}
 
开发者ID:Impetus,项目名称:ankush,代码行数:24,代码来源:SSHUtils.java


注:本文中的net.neoremind.sshxcute.core.SSHExec类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。