use of com.orion.ops.consts.machine.ProxyType in project orion-ops by lijiahangmax.
the class MachineInfoServiceImpl method connectSessionStore.
/**
* 打开sessionStore
*
* @param machine machine
* @return SessionStore
*/
private SessionStore connectSessionStore(MachineInfoDO machine) {
Valid.notNull(machine, MessageConst.INVALID_MACHINE);
Long proxyId = machine.getProxyId();
SessionStore session;
try {
session = SessionHolder.getSession(machine.getMachineHost(), machine.getSshPort(), machine.getUsername());
String password = machine.getPassword();
if (Strings.isNotBlank(password)) {
session.setPassword(ValueMix.decrypt(password));
}
MachineProxyDO proxy = null;
if (proxyId != null) {
proxy = machineProxyDAO.selectById(proxyId);
}
if (proxy != null) {
ProxyType proxyType = ProxyType.of(proxy.getProxyType());
String proxyPassword = proxy.getProxyPassword();
if (!Strings.isBlank(proxyPassword)) {
proxyPassword = ValueMix.decrypt(proxyPassword);
}
if (ProxyType.HTTP.equals(proxyType)) {
session.setHttpProxy(proxy.getProxyHost(), proxy.getProxyPort(), proxy.getProxyUsername(), proxyPassword);
} else if (ProxyType.SOCKET4.equals(proxyType)) {
session.setSocket4Proxy(proxy.getProxyHost(), proxy.getProxyPort(), proxy.getProxyUsername(), proxyPassword);
} else if (ProxyType.SOCKET5.equals(proxyType)) {
session.setSocket5Proxy(proxy.getProxyHost(), proxy.getProxyPort(), proxy.getProxyUsername(), proxyPassword);
}
session.setHttpProxy(proxy.getProxyHost(), proxy.getProxyPort(), proxy.getProxyUsername(), proxyPassword);
}
session.connect(MachineConst.CONNECT_TIMEOUT);
log.info("远程机器建立连接-成功 {}@{}:{}", machine.getUsername(), machine.getMachineHost(), machine.getSshPort());
return session;
} catch (Exception e) {
log.error("远程机器建立连接-失败 {}@{}:{} {}", machine.getUsername(), machine.getMachineHost(), machine.getSshPort(), e);
throw e;
}
}
Aggregations