use of com.jcraft.jsch.Session in project quickstarts by jboss-switchyard.
the class CamelFtpBindingTest method startUp.
@BeforeClass
public static void startUp() throws Exception {
FtpServerFactory serverFactory = new FtpServerFactory();
ListenerFactory listenerFactory = new ListenerFactory();
listenerFactory.setPort(2222);
serverFactory.addListener("default", listenerFactory.createListener());
ListenerFactory sslListenerFactory = new ListenerFactory();
sslListenerFactory.setPort(2221);
SslConfigurationFactory ssl = new SslConfigurationFactory();
ssl.setKeystoreFile(new File("src/test/resources/ftpserver.jks"));
ssl.setKeystorePassword("password");
sslListenerFactory.setSslConfiguration(ssl.createSslConfiguration());
// Setting it to true will not read the file
sslListenerFactory.setImplicitSsl(false);
serverFactory.addListener("ftps", sslListenerFactory.createListener());
PropertiesUserManagerFactory managerFactory = new PropertiesUserManagerFactory();
managerFactory.setPasswordEncryptor(new ClearTextPasswordEncryptor());
managerFactory.setFile(new File("src/test/resources/users.properties"));
UserManager createUserManager = managerFactory.createUserManager();
serverFactory.setUserManager(createUserManager);
NativeFileSystemFactory fileSystemFactory = new NativeFileSystemFactory();
fileSystemFactory.setCreateHome(true);
serverFactory.setFileSystem(fileSystemFactory);
File file = new File("target/ftp/ftps");
file.mkdirs();
file = new File("target/ftp/sftp");
file.mkdirs();
ftpServer = serverFactory.createServer();
ftpServer.start();
SshServer sshd = SshServer.setUpDefaultServer();
sshd.setPort(2220);
sshd.setKeyPairProvider(createTestKeyPairProvider("src/test/resources/hostkey.pem"));
sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystem.Factory()));
sshd.setCommandFactory(new ScpCommandFactory());
sshd.setPasswordAuthenticator(new BogusPasswordAuthenticator());
sshd.start();
JSch sch = new JSch();
Session session = sch.getSession("camel", "localhost", 2220);
session.setUserInfo(new SimpleUserInfo("isMyFriend"));
session.connect();
ChannelSftp c = (ChannelSftp) session.openChannel("sftp");
c.connect();
System.out.println("Home: " + c.getHome());
c.chmod(777, ".");
c.chmod(777, "target");
c.chmod(777, "target/ftp");
c.chmod(777, "target/ftp/sftp");
c.disconnect();
session.disconnect();
}
use of com.jcraft.jsch.Session in project azure-tools-for-java by Microsoft.
the class AzureDockerUIResources method updateDockerHost.
public static void updateDockerHost(Project project, EditableDockerHost editableDockerHost, AzureDockerHostsManager dockerManager, boolean doReset) {
AppInsightsClient.createByType(AppInsightsClient.EventType.DockerHost, "", "Update");
AzureInputDockerLoginCredsDialog loginCredsDialog = new AzureInputDockerLoginCredsDialog(project, editableDockerHost, dockerManager, doReset);
loginCredsDialog.show();
if (loginCredsDialog.getExitCode() == DialogWrapper.OK_EXIT_CODE) {
// Update Docker host log in credentials
DockerHost updateHost = editableDockerHost.originalDockerHost;
updateHost.isUpdating = true;
DefaultLoader.getIdeHelper().runInBackground(project, String.format("Updating %s Log In Credentials", updateHost.name), false, true, String.format("Updating log in credentials for %s...", updateHost.name), new Runnable() {
@Override
public void run() {
try {
AzureDockerVMOps.updateDockerHostVM(dockerManager.getSubscriptionsMap().get(updateHost.sid).azureClient, editableDockerHost.updatedDockerHost);
updateHost.certVault = editableDockerHost.updatedDockerHost.certVault;
updateHost.hasPwdLogIn = editableDockerHost.updatedDockerHost.hasPwdLogIn;
updateHost.hasSSHLogIn = editableDockerHost.updatedDockerHost.hasSSHLogIn;
updateHost.hasKeyVault = false;
updateHost.certVault.uri = "";
updateHost.certVault.name = "";
Session session = AzureDockerSSHOps.createLoginInstance(updateHost);
AzureDockerVMOps.UpdateCurrentDockerUser(session);
updateHost.session = session;
} catch (Exception ee) {
if (AzureDockerUtils.DEBUG)
ee.printStackTrace();
LOGGER.error("onEditDockerHostAction", ee);
}
updateHost.isUpdating = false;
}
});
}
}
use of com.jcraft.jsch.Session in project azure-tools-for-java by Microsoft.
the class AzureSelectDockerWizard method deploy.
public String deploy() {
AzureDockerPreferredSettings dockerPreferredSettings = dockerManager.getDockerPreferredSettings();
if (dockerPreferredSettings == null) {
dockerPreferredSettings = new AzureDockerPreferredSettings();
}
dockerPreferredSettings.dockerApiName = dockerImageDescription.host.apiUrl;
dockerPreferredSettings.dockerfileOption = dockerImageDescription.predefinedDockerfile;
dockerPreferredSettings.region = dockerImageDescription.host.hostVM.region;
dockerPreferredSettings.vmSize = dockerImageDescription.host.hostVM.vmSize;
dockerPreferredSettings.vmOS = dockerImageDescription.host.hostOSType.name();
dockerManager.setDockerPreferredSettings(dockerPreferredSettings);
DefaultLoader.getIdeHelper().runInBackground(project, "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() {
if (!dockerImageDescription.hasNewDockerHost) {
Session session = null;
do {
try {
// check if the Docker host is accessible
session = AzureDockerSSHOps.createLoginInstance(dockerImageDescription.host);
} catch (Exception e) {
session = null;
}
if (session == null) {
EditableDockerHost editableDockerHost = new EditableDockerHost(dockerImageDescription.host);
AzureInputDockerLoginCredsDialog loginCredsDialog = new AzureInputDockerLoginCredsDialog(PluginUtil.getParentShell(), project, editableDockerHost, dockerManager, false);
if (loginCredsDialog.open() == Window.OK) {
// Update Docker host log in credentials
dockerImageDescription.host.certVault = editableDockerHost.updatedDockerHost.certVault;
dockerImageDescription.host.hasSSHLogIn = editableDockerHost.updatedDockerHost.hasSSHLogIn;
dockerImageDescription.host.hasPwdLogIn = editableDockerHost.updatedDockerHost.hasPwdLogIn;
// AzureDockerVMOps.updateDockerHostVM(dockerManager.getSubscriptionsMap().get(dockerImageDescription.sid).azureClient, editableDockerHost.updatedDockerHost);
} else {
return;
}
}
} while (session == null);
}
// Azure azureClient = dockerManager.getSubscriptionsMap().get(dockerImageDescription.sid).azureClient;
// DockerContainerDeployTask task = new DockerContainerDeployTask(project, azureClient, dockerImageDescription);
// task.queue();
createDockerContainerDeployTask(project, dockerImageDescription, dockerManager);
}
});
} catch (Exception e) {
String msg = "An error occurred while attempting to deploy to the selected Docker host." + "\n" + e.getMessage();
PluginUtil.displayErrorDialogWithAzureMsg(PluginUtil.getParentShell(), "Failed to Deploy Web App as Docker Container", msg, e);
}
}
});
return AzureDockerUtils.getUrl(dockerImageDescription);
}
use of com.jcraft.jsch.Session in project azure-tools-for-java by Microsoft.
the class AzureDockerUIResources method updateDockerHost.
public static void updateDockerHost(Shell shell, IProject project, EditableDockerHost editableDockerHost, AzureDockerHostsManager dockerManager, boolean doReset) {
DockerHost updateHost = editableDockerHost.originalDockerHost;
AzureInputDockerLoginCredsDialog loginCredsDialog = new AzureInputDockerLoginCredsDialog(PluginUtil.getParentShell(), project, editableDockerHost, dockerManager, doReset);
if (loginCredsDialog.open() == Window.OK) {
// Update Docker host log in credentials
updateHost.isUpdating = true;
DefaultLoader.getIdeHelper().runInBackground(project, String.format("Updating %s Log In Credentials", updateHost.name), false, true, String.format("Updating log in credentials for %s...", updateHost.name), new Runnable() {
@Override
public void run() {
try {
AzureDockerVMOps.updateDockerHostVM(dockerManager.getSubscriptionsMap().get(updateHost.sid).azureClient, editableDockerHost.updatedDockerHost);
updateHost.certVault = editableDockerHost.updatedDockerHost.certVault;
updateHost.hasPwdLogIn = editableDockerHost.updatedDockerHost.hasPwdLogIn;
updateHost.hasSSHLogIn = editableDockerHost.updatedDockerHost.hasSSHLogIn;
updateHost.hasKeyVault = false;
updateHost.certVault.uri = "";
updateHost.certVault.name = "";
Session session = AzureDockerSSHOps.createLoginInstance(updateHost);
AzureDockerVMOps.UpdateCurrentDockerUser(session);
updateHost.session = session;
} catch (Exception ee) {
if (AzureDockerUtils.DEBUG)
ee.printStackTrace();
log.log(Level.SEVERE, "dockerHostsEditButton.addSelectionListener", ee);
}
updateHost.isUpdating = false;
}
});
}
}
use of com.jcraft.jsch.Session in project azure-tools-for-java by Microsoft.
the class AzureDockerVMOps method waitForVirtualMachineStartup.
public static void waitForVirtualMachineStartup(Azure azureClient, DockerHost dockerHost) {
// vault is not immediately available so the next operation could fail
// add a retry policy to make sure it got created
boolean isRunning = false;
int sleepTime = 50000;
for (int sleepMs = 5000; sleepMs <= 200000; sleepMs += sleepTime) {
try {
if (!isRunning) {
VirtualMachine vm = getVM(azureClient, dockerHost.hostVM.resourceGroupName, dockerHost.hostVM.name);
if (vm != null && vm.powerState().toString().split("/")[1].toUpperCase().equals("RUNNING")) {
// "PowerState/running"
isRunning = true;
} else {
if (DEBUG)
System.out.format("Warning: can't connect to %s (%d sec have passed)\n", dockerHost.hostVM.dnsName, sleepMs / 1000);
try {
Thread.sleep(sleepTime);
} catch (Exception e2) {
}
}
} else {
// VM is running; try to SSH connect to it
Session session = AzureDockerSSHOps.createLoginInstance(dockerHost);
String result = AzureDockerSSHOps.executeCommand("ls -l /", session, true);
if (DEBUG)
System.out.println(result);
session.disconnect();
break;
}
} catch (Exception e) {
try {
if (DEBUG)
System.out.format("Warning: can't connect to %s (%d sec have passed)\n", dockerHost.hostVM.dnsName, sleepMs / 1000);
if (DEBUG)
System.out.println(e.getMessage());
Thread.sleep(sleepTime);
} catch (Exception e3) {
}
}
}
}
Aggregations