use of com.jcraft.jsch.Session in project azure-tools-for-java by Microsoft.
the class SparkBatchDebugSession method factory.
/**
* Create a SparkBatchDebugSession instance for specified host and user
*
* @param host The SSH host
* @param user The SSH user
* @return an SparkBatchDebugSession instance
* @throws JSchException JSch operation exceptions
*/
public static SparkBatchDebugSession factory(String host, String user) throws JSchException {
JSch jsch = new JSch();
Session session = jsch.getSession(user, host);
java.util.Properties config = new java.util.Properties() {
{
put("StrictHostKeyChecking", "no");
}
};
session.setConfig(config);
return new SparkBatchDebugSession(jsch, session);
}
use of com.jcraft.jsch.Session in project azure-tools-for-java by Microsoft.
the class SparkSubmitHelper method sftpFileToEmulator.
public String sftpFileToEmulator(String localFile, String folderPath, IClusterDetail clusterDetail) throws IOException, HDIException, JSchException, SftpException {
EmulatorClusterDetail emulatorClusterDetail = (EmulatorClusterDetail) clusterDetail;
final File file = new File(localFile);
try (FileInputStream fileInputStream = new FileInputStream(file)) {
try (BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream)) {
String sshEndpoint = emulatorClusterDetail.getSSHEndpoint();
URL url = new URL(sshEndpoint);
String host = url.getHost();
int port = url.getPort();
JSch jsch = new JSch();
Session session = jsch.getSession(emulatorClusterDetail.getHttpUserName(), host, port);
session.setPassword(emulatorClusterDetail.getHttpPassword());
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
channel.connect();
String[] folders = folderPath.split("/");
for (String folder : folders) {
if (folder.length() > 0) {
try {
channel.cd(folder);
} catch (SftpException e) {
channel.mkdir(folder);
channel.cd(folder);
}
}
}
channel.put(bufferedInputStream, file.getName());
channel.disconnect();
session.disconnect();
return file.getName();
}
}
}
use of com.jcraft.jsch.Session in project azure-tools-for-java by Microsoft.
the class AzureSelectDockerWizardDialog method deploy.
public String deploy() {
AzureDockerImageInstance dockerImageInstance = model.getDockerImageDescription();
AzureDockerPreferredSettings dockerPreferredSettings = model.getDockerHostsManager().getDockerPreferredSettings();
if (dockerPreferredSettings == null) {
dockerPreferredSettings = new AzureDockerPreferredSettings();
}
dockerPreferredSettings.dockerApiName = dockerImageInstance.host.apiUrl;
dockerPreferredSettings.dockerfileOption = dockerImageInstance.predefinedDockerfile;
dockerPreferredSettings.region = dockerImageInstance.host.hostVM.region;
dockerPreferredSettings.vmSize = dockerImageInstance.host.hostVM.vmSize;
dockerPreferredSettings.vmOS = dockerImageInstance.host.hostOSType.name();
model.getDockerHostsManager().setDockerPreferredSettings(dockerPreferredSettings);
DefaultLoader.getIdeHelper().runInBackground(model.getProject(), "Deploying Docker Container on Azure", false, true, "Deploying Web app to a Docker host on Azure...", new Runnable() {
@Override
public void run() {
try {
DefaultLoader.getIdeHelper().invokeLater(new Runnable() {
@Override
public void run() {
AzureDockerImageInstance dockerImageInstance = model.getDockerImageDescription();
if (!dockerImageInstance.hasNewDockerHost) {
Session session = null;
do {
try {
// check if the Docker host is accessible
session = AzureDockerSSHOps.createLoginInstance(dockerImageInstance.host);
} catch (Exception e) {
session = null;
}
if (session == null) {
EditableDockerHost editableDockerHost = new EditableDockerHost(dockerImageInstance.host);
AzureInputDockerLoginCredsDialog loginCredsDialog = new AzureInputDockerLoginCredsDialog(model.getProject(), editableDockerHost, model.getDockerHostsManager(), false);
loginCredsDialog.show();
if (loginCredsDialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
// Update Docker host log in credentials
DockerHost dockerHost = model.getDockerHostsManager().getDockerHostForURL(dockerImageInstance.host.apiUrl);
dockerHost.certVault = editableDockerHost.updatedDockerHost.certVault;
dockerHost.hasPwdLogIn = editableDockerHost.updatedDockerHost.hasPwdLogIn;
dockerHost.hasSSHLogIn = editableDockerHost.updatedDockerHost.hasSSHLogIn;
dockerImageInstance.host = dockerHost;
// AzureDockerVMOps.updateDockerHostVM(model.getDockerHostsManager().getSubscriptionsMap().get(model.getDockerImageDescription().sid).azureClient, editableDockerHost.updatedDockerHost);
} else {
return;
}
}
} while (session == null);
}
Azure azureClient = model.getDockerHostsManager().getSubscriptionsMap().get(model.getDockerImageDescription().sid).azureClient;
DockerContainerDeployTask task = new DockerContainerDeployTask(model.getProject(), azureClient, model.getDockerImageDescription());
task.queue();
// Update caches here
if (onCreate != null) {
onCreate.run();
}
}
});
} catch (Exception e) {
String msg = "An error occurred while attempting to deploy to the selected Docker host." + "\n" + e.getMessage();
PluginUtil.displayErrorDialogInAWTAndLog("Failed to Deploy Web App as Docker Container", msg, e);
}
}
});
return AzureDockerUtils.getUrl(dockerImageInstance);
}
use of com.jcraft.jsch.Session in project azure-tools-for-java by Microsoft.
the class AzureDockerVMOps method installDockerOnUbuntuServer.
public static DockerHost installDockerOnUbuntuServer(DockerHost dockerHost) {
if (dockerHost == null) {
throw new AzureDockerException("Unexpected param values; dockerHost cannot be null");
}
try {
Session session = AzureDockerSSHOps.createLoginInstance(dockerHost);
switch(dockerHost.hostOSType) {
case UBUNTU_SERVER_14_04_LTS:
installDockerServiceOnUbuntuServer_14_04_LTS(session);
case UBUNTU_SERVER_16_04_LTS:
installDockerServiceOnUbuntuServer_16_04_LTS(session);
break;
default:
throw new AzureDockerException("Docker dockerHost OS type is not supported");
}
if (dockerHost.isTLSSecured) {
if (isValid(dockerHost.certVault.tlsServerCert)) {
// Docker certificates are passed in; copy them to the docker dockerHost
uploadDockerTlsCertsForUbuntuServer(dockerHost, session);
} else {
// Create new TLS certificates and upload them into the current machine representation
dockerHost = createDockerCertsForUbuntuServer(dockerHost, session);
dockerHost = downloadDockerTlsCertsForUbuntuServer(dockerHost, session);
}
setupDockerTlsCertsForUbuntuServer(session);
createDockerConfigWithTlsForUbuntuServer(dockerHost, session);
} else {
createDockerConfigNoTlsForUbuntuServer(dockerHost, session);
}
session.disconnect();
return dockerHost;
} catch (Exception e) {
throw new AzureDockerException(e.getMessage(), e);
}
}
use of com.jcraft.jsch.Session in project GNS by MobilityFirst.
the class UserAuthPubKey method main.
/**
*
* @param arg
*/
public static void main(String[] arg) {
try {
JSch jsch = new JSch();
JFileChooser chooser = new JFileChooser();
chooser.setDialogTitle("Choose your privatekey(ex. ~/.ssh/id_dsa)");
chooser.setFileHidingEnabled(false);
int returnVal = chooser.showOpenDialog(null);
if (returnVal == JFileChooser.APPROVE_OPTION) {
System.out.println("You chose " + chooser.getSelectedFile().getAbsolutePath() + ".");
// , "passphrase"
jsch.addIdentity(// , "passphrase"
chooser.getSelectedFile().getAbsolutePath());
}
String host = null;
if (arg.length > 0) {
host = arg[0];
} else {
host = JOptionPane.showInputDialog("Enter username@hostname", System.getProperty("user.name") + "@localhost");
}
String user = host.substring(0, host.indexOf('@'));
host = host.substring(host.indexOf('@') + 1);
Session session = jsch.getSession(user, host, 22);
// username and passphrase will be given via UserInfo interface.
UserInfo ui = new UserInfoPrompted();
session.setUserInfo(ui);
session.connect();
Channel channel = session.openChannel("shell");
channel.setInputStream(System.in);
channel.setOutputStream(System.out);
channel.connect();
} catch (HeadlessException | JSchException e) {
System.out.println(e);
}
}
Aggregations