Compare commits
10 Commits
fix/releas
...
patch/7.3.
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
500e5757e4 | ||
|
|
1c8ba1f92f | ||
|
|
65ab868a8a | ||
|
|
4d0953bea3 | ||
|
|
09d7ba159c | ||
|
|
d52d8354e3 | ||
|
|
cc16102610 | ||
|
|
57ed6e900b | ||
|
|
a3eee5e4f6 | ||
|
|
cf011f2201 |
@@ -126,8 +126,16 @@
|
||||
|
||||
boolean exist_tSCP = false;
|
||||
List<INode> scpComponentsList = (List<INode>)process.getNodesOfType("tSCPConnection");
|
||||
if (scpComponentsList.size() > 0) {
|
||||
String parameterNames = "";
|
||||
int scpsize = scpComponentsList.size();
|
||||
if (scpsize > 0) {
|
||||
exist_tSCP = true;
|
||||
for (int i = 0; i < scpsize; i++) {
|
||||
parameterNames += "\"conn_" + scpComponentsList.get(i).getUniqueName() + "\"";
|
||||
if(i < scpsize-1){
|
||||
parameterNames += ",";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean exist_tCassandra = false;
|
||||
@@ -1190,9 +1198,12 @@ this.globalResumeTicket = true;//to run tPostJob
|
||||
closeJmsConnections();
|
||||
<% } %>
|
||||
|
||||
<% if (exist_tSCP) { %>
|
||||
closeScpConnections();
|
||||
<% } %>
|
||||
<% if (exist_tSCP) {
|
||||
%>
|
||||
closeCloseableConnections(<%=parameterNames%>);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
|
||||
<%
|
||||
if (stats) {
|
||||
@@ -1246,7 +1257,7 @@ if (execStat) {
|
||||
closeJmsConnections();
|
||||
<% } %>
|
||||
<% if(exist_tSCP) { %>
|
||||
closeScpConnections();
|
||||
closeCloseableConnections(<%=parameterNames%>);
|
||||
<% } %>
|
||||
<% if (exist_tSQLDB) { %>
|
||||
closeSqlDbConnections();
|
||||
@@ -1314,22 +1325,17 @@ if (execStat) {
|
||||
<%
|
||||
if(exist_tSCP) {
|
||||
%>
|
||||
private void closeScpConnections() {
|
||||
try {
|
||||
Object obj_conn;
|
||||
<%
|
||||
for (INode scpNode : scpComponentsList) {
|
||||
%>
|
||||
obj_conn = globalMap.remove("conn_<%=scpNode.getUniqueName() %>");
|
||||
if (null != obj_conn) {
|
||||
((ch.ethz.ssh2.Connection) obj_conn).close();
|
||||
private void closeCloseableConnections(String... names) {
|
||||
java.util.Arrays.stream(names).forEach(name-> {
|
||||
try {
|
||||
Object obj_conn = globalMap.remove(name);
|
||||
if(obj_conn != null){
|
||||
((java.io.Closeable)obj_conn).close();
|
||||
}
|
||||
} catch (IOException ioException) {
|
||||
}
|
||||
<%
|
||||
}
|
||||
%>
|
||||
} catch (java.lang.Exception e) {
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
<%
|
||||
}
|
||||
%>
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.talend.components</groupId>
|
||||
<artifactId>talend-scp-helper</artifactId>
|
||||
<version>1.0</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>8</maven.compiler.source>
|
||||
<maven.compiler.target>8</maven.compiler.target>
|
||||
<ssd.version>2.5.1</ssd.version>
|
||||
<talend.nexus.url>https://artifacts-oss.talend.com</talend.nexus.url>
|
||||
</properties>
|
||||
|
||||
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>talend_nexus_deployment</id>
|
||||
<url>${talend.nexus.url}/nexus/content/repositories/TalendOpenSourceSnapshot/</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>talend_nexus_deployment</id>
|
||||
<url>${talend.nexus.url}/nexus/content/repositories/TalendOpenSourceRelease/</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.sshd</groupId>
|
||||
<artifactId>sshd-scp</artifactId>
|
||||
<version>${ssd.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.sshd</groupId>
|
||||
<artifactId>sshd-common</artifactId>
|
||||
<version>${ssd.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.sshd</groupId>
|
||||
<artifactId>sshd-core</artifactId>
|
||||
<version>${ssd.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
@@ -0,0 +1,115 @@
|
||||
package org.talend.components.talendscp;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.FileSystem;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.attribute.PosixFilePermission;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
|
||||
import org.apache.sshd.client.channel.ChannelExec;
|
||||
import org.apache.sshd.client.scp.AbstractScpClient;
|
||||
import org.apache.sshd.client.scp.DefaultScpClient;
|
||||
import org.apache.sshd.client.scp.DefaultScpStreamResolver;
|
||||
import org.apache.sshd.client.scp.ScpClient;
|
||||
import org.apache.sshd.client.session.ClientSession;
|
||||
import org.apache.sshd.common.FactoryManager;
|
||||
import org.apache.sshd.common.file.FileSystemFactory;
|
||||
import org.apache.sshd.common.file.util.MockFileSystem;
|
||||
import org.apache.sshd.common.file.util.MockPath;
|
||||
import org.apache.sshd.common.scp.ScpFileOpener;
|
||||
import org.apache.sshd.common.scp.ScpHelper;
|
||||
import org.apache.sshd.common.scp.ScpTimestamp;
|
||||
import org.apache.sshd.common.scp.ScpTransferEventListener;
|
||||
import org.apache.sshd.common.util.ValidateUtils;
|
||||
|
||||
|
||||
/*
|
||||
What we do here is just overwrite the ScpHelper to throw Exception when scp return status 1
|
||||
to keep the old behavior
|
||||
*/
|
||||
|
||||
public class TalendScpClient extends DefaultScpClient {
|
||||
|
||||
public TalendScpClient(ClientSession clientSession, ScpFileOpener fileOpener,
|
||||
ScpTransferEventListener eventListener) {
|
||||
super(clientSession, fileOpener, eventListener);
|
||||
}
|
||||
|
||||
@Override public void upload(InputStream local, String remote, long size, Collection<PosixFilePermission> perms,
|
||||
ScpTimestamp time) throws IOException {
|
||||
int namePos = ValidateUtils.checkNotNullAndNotEmpty(remote, "No remote location specified").lastIndexOf('/');
|
||||
String name = (namePos < 0) ?
|
||||
remote :
|
||||
ValidateUtils.checkNotNullAndNotEmpty(remote.substring(namePos + 1), "No name value in remote=%s",
|
||||
remote);
|
||||
Collection<Option> options = (time != null) ? EnumSet.of(Option.PreserveAttributes) : Collections.emptySet();
|
||||
String cmd = ScpClient.createSendCommand(remote, options);
|
||||
ClientSession session = getClientSession();
|
||||
ChannelExec channel = openCommandChannel(session, cmd);
|
||||
try (InputStream invOut = channel.getInvertedOut(); OutputStream invIn = channel.getInvertedIn()) {
|
||||
// NOTE: we use a mock file system since we expect no invocations for it
|
||||
ScpHelper helper = new TalendScpHelper(session, invOut, invIn, new MockFileSystem(remote), opener, listener);
|
||||
Path mockPath = new MockPath(remote);
|
||||
helper.sendStream(new DefaultScpStreamResolver(name, mockPath, perms, time, size, local, cmd),
|
||||
options.contains(Option.PreserveAttributes), ScpHelper.DEFAULT_SEND_BUFFER_SIZE);
|
||||
handleCommandExitStatus(cmd, channel);
|
||||
} finally {
|
||||
channel.close(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected <T> void runUpload(String remote, Collection<Option> options, Collection<T> local,
|
||||
AbstractScpClient.ScpOperationExecutor<T> executor) throws IOException {
|
||||
local = ValidateUtils.checkNotNullAndNotEmpty(local, "Invalid argument local: %s", local);
|
||||
remote = ValidateUtils.checkNotNullAndNotEmpty(remote, "Invalid argument remote: %s", remote);
|
||||
if (local.size() > 1) {
|
||||
options = addTargetIsDirectory(options);
|
||||
}
|
||||
|
||||
String cmd = ScpClient.createSendCommand(remote, options);
|
||||
ClientSession session = getClientSession();
|
||||
ChannelExec channel = openCommandChannel(session, cmd);
|
||||
try {
|
||||
FactoryManager manager = session.getFactoryManager();
|
||||
FileSystemFactory factory = manager.getFileSystemFactory();
|
||||
FileSystem fs = factory.createFileSystem(session);
|
||||
|
||||
try (InputStream invOut = channel.getInvertedOut(); OutputStream invIn = channel.getInvertedIn()) {
|
||||
ScpHelper helper = new TalendScpHelper(session, invOut, invIn, fs, opener, listener);
|
||||
executor.execute(helper, local, options);
|
||||
} finally {
|
||||
try {
|
||||
fs.close();
|
||||
} catch (UnsupportedOperationException e) {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("runUpload({}) {} => {} - failed ({}) to close file system={}: {}", session, remote,
|
||||
local, e.getClass().getSimpleName(), fs, e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
handleCommandExitStatus(cmd, channel);
|
||||
} finally {
|
||||
channel.close(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override public void download(String remote, OutputStream local) throws IOException {
|
||||
String cmd = ScpClient.createReceiveCommand(remote, Collections.emptyList());
|
||||
ClientSession session = getClientSession();
|
||||
ChannelExec channel = openCommandChannel(session, cmd);
|
||||
try (InputStream invOut = channel.getInvertedOut(); OutputStream invIn = channel.getInvertedIn()) {
|
||||
// NOTE: we use a mock file system since we expect no invocations for it
|
||||
ScpHelper helper =
|
||||
new TalendScpHelper(session, invOut, invIn, new MockFileSystem(remote), opener, listener);
|
||||
helper.receiveFileStream(local, ScpHelper.DEFAULT_RECEIVE_BUFFER_SIZE);
|
||||
handleCommandExitStatus(cmd, channel);
|
||||
} finally {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package org.talend.components.talendscp;
|
||||
|
||||
import org.apache.sshd.client.scp.AbstractScpClientCreator;
|
||||
import org.apache.sshd.client.scp.ScpClient;
|
||||
import org.apache.sshd.client.scp.ScpClientCreator;
|
||||
import org.apache.sshd.client.session.ClientSession;
|
||||
import org.apache.sshd.common.scp.ScpFileOpener;
|
||||
import org.apache.sshd.common.scp.ScpTransferEventListener;
|
||||
|
||||
public class TalendScpClientCreator extends AbstractScpClientCreator implements ScpClientCreator {
|
||||
public static final TalendScpClientCreator INSTANCE = new TalendScpClientCreator();
|
||||
|
||||
@Override
|
||||
public ScpClient createScpClient(ClientSession session) {
|
||||
return this.createScpClient(session, this.getScpFileOpener(), this.getScpTransferEventListener());
|
||||
}
|
||||
|
||||
@Override public ScpClient createScpClient(ClientSession clientSession, ScpFileOpener scpFileOpener,
|
||||
ScpTransferEventListener scpTransferEventListener) {
|
||||
return new TalendScpClient(clientSession, scpFileOpener, scpTransferEventListener);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package org.talend.components.talendscp;
|
||||
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.nio.file.FileSystem;
|
||||
|
||||
import org.apache.sshd.common.scp.ScpException;
|
||||
import org.apache.sshd.common.scp.ScpFileOpener;
|
||||
import org.apache.sshd.common.scp.ScpHelper;
|
||||
import org.apache.sshd.common.scp.ScpTransferEventListener;
|
||||
import org.apache.sshd.common.session.Session;
|
||||
|
||||
public class TalendScpHelper extends ScpHelper {
|
||||
|
||||
public TalendScpHelper(Session session, InputStream in, OutputStream out, FileSystem fileSystem,
|
||||
ScpFileOpener opener, ScpTransferEventListener eventListener) {
|
||||
super(session, in, out, fileSystem, opener, eventListener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int readAck(boolean canEof) throws IOException {
|
||||
int c = in.read();
|
||||
switch (c) {
|
||||
case -1:
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("readAck({})[EOF={}] received EOF", this, canEof);
|
||||
}
|
||||
if (!canEof) {
|
||||
throw new EOFException("readAck - EOF before ACK");
|
||||
}
|
||||
break;
|
||||
case OK:
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("readAck({})[EOF={}] read OK", this, canEof);
|
||||
}
|
||||
break;
|
||||
case WARNING: {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("readAck({})[EOF={}] read warning message", this, canEof);
|
||||
}
|
||||
|
||||
String line = readLine();
|
||||
log.warn("readAck({})[EOF={}] - Received warning: {}", this, canEof, line);
|
||||
throw new ScpException("received error: " + line, c);
|
||||
}
|
||||
case ERROR: {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("readAck({})[EOF={}] read error message", this, canEof);
|
||||
}
|
||||
String line = readLine();
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("readAck({})[EOF={}] received error: {}", this, canEof, line);
|
||||
}
|
||||
throw new ScpException("Received nack: " + line, c);
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return c;
|
||||
}
|
||||
}
|
||||
@@ -313,8 +313,7 @@ if (sftp) {// *** sftp *** //
|
||||
currentFilePath_<%=cid%> += "/";
|
||||
}
|
||||
|
||||
for (int i = 0; i < fileListTemp_<%=cid %>.size(); i++) {
|
||||
org.apache.commons.net.ftp.FTPFile ftpFile_<%=cid %> = fileListTemp_<%=cid %>.get(i);
|
||||
for (org.apache.commons.net.ftp.FTPFile ftpFile_<%=cid %> : fileListTemp_<%=cid %>) {
|
||||
String currentFileName_<%=cid%> = null;
|
||||
<%
|
||||
if (dirFull) {
|
||||
|
||||
@@ -43,11 +43,7 @@
|
||||
/>
|
||||
</PARAMETERS>
|
||||
|
||||
<CODEGENERATION>
|
||||
<IMPORTS>
|
||||
<IMPORT NAME="Java_SCP" MODULE="ganymed-ssh2-261.jar" MVN="mvn:ch.ethz.ganymed/ganymed-ssh2/261" REQUIRED="true"/>
|
||||
</IMPORTS>
|
||||
</CODEGENERATION>
|
||||
<CODEGENERATION />
|
||||
|
||||
<RETURNS/>
|
||||
</COMPONENT>
|
||||
|
||||
@@ -14,13 +14,10 @@ imports="
|
||||
String conn = "conn_" + connection;
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
%>
|
||||
ch.ethz.ssh2.Connection conn_<%=cid%> = (ch.ethz.ssh2.Connection)globalMap.get("<%=conn%>");
|
||||
if(conn_<%=cid%> != null){
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Closing the connection '<%= connection %>' to the server.");
|
||||
<%}%>
|
||||
conn_<%=cid%>.close();
|
||||
closeCloseableConnections("<%=conn%>");
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connection '<%= connection %>' to the server closed.");
|
||||
<%}%>
|
||||
}
|
||||
|
||||
@@ -23,104 +23,134 @@ imports="
|
||||
%>
|
||||
String hostname_<%=cid%> = <%=host%>;
|
||||
String username_<%=cid%> = <%=user%>;
|
||||
/* Create a connection instance */
|
||||
<%
|
||||
if(("").equals(port)){
|
||||
%>
|
||||
ch.ethz.ssh2.Connection conn_<%=cid%> = new ch.ethz.ssh2.Connection(hostname_<%=cid%>);
|
||||
<%
|
||||
} else {
|
||||
%>
|
||||
ch.ethz.ssh2.Connection conn_<%=cid%> = new ch.ethz.ssh2.Connection(hostname_<%=cid%>,<%=port%>);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
/* Now connect */
|
||||
/* Create a connection instance */
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Attempt to connect to '" + hostname_<%=cid%> + "' with username '" + <%=user%> + "'.");
|
||||
log.info("<%=cid%> - Connection attempt to '" +hostname_<%=cid%> + "' on the port '"+<%=port%>+"' as '" + username_<%=cid%> + "'.");
|
||||
<%}%>
|
||||
conn_<%=cid%>.connect();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connect to '" + hostname_<%=cid%> + "' has succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
org.apache.sshd.client.SshClient client_<%=cid%> = org.apache.sshd.client.SshClient.setUpDefaultClient();
|
||||
client_<%=cid%>.getProperties().putIfAbsent(org.apache.sshd.common.FactoryManager.IDLE_TIMEOUT, 0L);
|
||||
client_<%=cid%>.getProperties().putIfAbsent(org.apache.sshd.common.FactoryManager.NIO2_READ_TIMEOUT, 0L);
|
||||
<%
|
||||
if (("PUBLICKEY").equals(authMethod)) {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using a public key");
|
||||
log.debug("<%=cid%> - Private key: '" + <%=privatekey%> + "'." );
|
||||
<%}%>
|
||||
java.io.File keyfile_<%=cid%> = new java.io.File(<%=privatekey%>);
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASSPHRASE__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
boolean isAuthenticated_<%=cid%> = conn_<%=cid%>.authenticateWithPublicKey(username_<%=cid%>, keyfile_<%=cid%>, decryptedPassword_<%=cid%>);
|
||||
if (isAuthenticated_<%=cid%> == false){
|
||||
throw new RuntimeException("Authentication failed.");
|
||||
}
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
if (("PASSWORD").equals(authMethod)) {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using a password");
|
||||
<%}%>
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
boolean isAuthenticated_<%=cid%> = conn_<%=cid%>.authenticateWithPassword(username_<%=cid%>, decryptedPassword_<%=cid%>);
|
||||
if (isAuthenticated_<%=cid%> == false){
|
||||
throw new RuntimeException("Authentication failed.");
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using a public key.");
|
||||
<%}%>
|
||||
client_<%=cid%>.setUserAuthFactories(java.util.Collections.singletonList(org.apache.sshd.client.auth.pubkey.UserAuthPublicKeyFactory.INSTANCE));
|
||||
java.nio.file.Path privateKey_<%=cid%> = java.nio.file.Paths.get(<%=privatekey%>);
|
||||
java.util.List<String> lines_<%=cid%> = java.nio.file.Files.readAllLines(privateKey_<%=cid%>);
|
||||
globalMap.put("privateKey_<%=cid%>",privateKey_<%=cid%>);
|
||||
globalMap.put("lines_<%=cid%>",lines_<%=cid%>);
|
||||
|
||||
org.apache.sshd.common.util.security.bouncycastle.BouncyCastleGeneratorHostKeyProvider keyProvider_<%=cid%> =
|
||||
new org.apache.sshd.common.util.security.bouncycastle.BouncyCastleGeneratorHostKeyProvider(privateKey_<%=cid%>)
|
||||
|
||||
{
|
||||
|
||||
@Override
|
||||
protected Iterable<java.security.KeyPair> doReadKeyPairs(org.apache.sshd.common.session.SessionContext session,
|
||||
org.apache.sshd.common.NamedResource resourceKey, java.io.InputStream inputStream)
|
||||
throws java.io.IOException, java.security.GeneralSecurityException {
|
||||
<%String passwordFieldName = "__PASSPHRASE__";%>
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
Iterable<java.security.KeyPair> keyPairs =
|
||||
org.apache.sshd.common.util.security.SecurityUtils.loadKeyPairIdentities(session, resourceKey, inputStream,
|
||||
(sessionContext, namedResource, i) -> decryptedPassword_<%=cid%>);
|
||||
return keyPairs;
|
||||
}
|
||||
};
|
||||
if (lines_<%=cid%>.size()>0) {
|
||||
String[] line_<%=cid%> = lines_<%=cid%>.get(0).split(" ");
|
||||
if ("-----BEGIN".equals(line_<%=cid%>[0])) {
|
||||
keyProvider_<%=cid%>.setAlgorithm(line_<%=cid%>[1]);
|
||||
}
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
client_<%=cid%>.setKeyIdentityProvider(keyProvider_<%=cid%>);
|
||||
|
||||
<%}%>
|
||||
<%
|
||||
if (("KEYBOARDINTERACTIVE").equals(authMethod)) {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using an interactive action");
|
||||
<%}%>
|
||||
boolean isAuthenticated_<%=cid%> = conn_<%=cid%>.authenticateWithKeyboardInteractive(username_<%=cid%>,
|
||||
new ch.ethz.ssh2.InteractiveCallback() {
|
||||
public String[] replyToChallenge(String name,
|
||||
String instruction, int numPrompts,
|
||||
String[] prompt, boolean[] echo)
|
||||
throws java.lang.Exception {
|
||||
String[] reply = new String[numPrompts];
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
for (int i = 0; i < reply.length; i++) {
|
||||
reply[i] = decryptedPassword_<%=cid%>;
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
}
|
||||
);
|
||||
if (isAuthenticated_<%=cid%> == false){
|
||||
throw new RuntimeException("Authentication failed.");
|
||||
%>
|
||||
|
||||
client_<%=cid%>.setUserAuthFactories(java.util.Collections.singletonList(org.apache.sshd.client.auth.keyboard.UserAuthKeyboardInteractiveFactory.INSTANCE));
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using an interactive action.");
|
||||
<%}%>
|
||||
|
||||
client_<%=cid%>.setUserInteraction(new org.apache.sshd.client.auth.keyboard.UserInteraction() {
|
||||
|
||||
@Override
|
||||
public String[] interactive(org.apache.sshd.client.session.ClientSession clientSession, String name, String instruction, String lang, String[] prompt,
|
||||
boolean[] echo) {
|
||||
|
||||
<% String passwordFieldName = "__PASSWORD__"; %>
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
String[] reply = new String[prompt.length];
|
||||
for (int i = 0; i < reply.length; i++) {
|
||||
reply[i] = decryptedPassword_<%=cid%>;
|
||||
}
|
||||
return reply;
|
||||
}
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication succeeded.");
|
||||
<%}%>
|
||||
|
||||
@Override public String getUpdatedPassword(org.apache.sshd.client.session.ClientSession clientSession, String prompt, String lang) {
|
||||
throw new IllegalStateException("getUpdatedPassword(" + clientSession + ")[" + prompt + "] unexpected call");
|
||||
}
|
||||
});
|
||||
|
||||
<%
|
||||
}%>
|
||||
globalMap.put("conn_<%=cid%>",conn_<%=cid %>);
|
||||
}
|
||||
%>
|
||||
|
||||
<%if (("PASSWORD").equals(authMethod)) {%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using a password.");
|
||||
<%}%>
|
||||
<%String passwordFieldName = "__PASSWORD__";%>
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
client_<%=cid%>.addPasswordIdentity(decryptedPassword_<%=cid%>);
|
||||
<%}%>
|
||||
|
||||
client_<%=cid%>.start();
|
||||
|
||||
/* Create a session */
|
||||
|
||||
org.apache.sshd.client.session.ClientSession session_<%=cid%> = null;
|
||||
|
||||
/* Now connect */
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connection to '" +hostname_<%=cid%> + "' has succeeded.");
|
||||
<%}%>
|
||||
|
||||
/* open a session */
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Open up a session.");
|
||||
<%}%>
|
||||
|
||||
session_<%=cid%> = client_<%=cid%>.connect(username_<%=cid%>, hostname_<%=cid%>, Integer.parseInt(<%=port %>+"")).verify().getClientSession();
|
||||
try {
|
||||
session_<%=cid%>.auth().verify();
|
||||
}catch (org.apache.sshd.common.SshException se_<%=cid%>){
|
||||
globalMap.put("<%=cid %>_EXIT_CODE",se_<%=cid%>.getDisconnectCode());
|
||||
<%
|
||||
if (("PUBLICKEY").equals(authMethod)) {
|
||||
%>
|
||||
java.nio.file.Files.write(privateKey_<%=cid%>,lines_<%=cid%>);
|
||||
<%}%>
|
||||
if(14 == se_<%=cid%>.getDisconnectCode()){
|
||||
throw new IllegalArgumentException("Authentication failed.");
|
||||
}else{
|
||||
throw se_<%=cid%>;
|
||||
}
|
||||
}finally{
|
||||
session_<%=cid%>.close();
|
||||
}
|
||||
|
||||
|
||||
|
||||
globalMap.put("conn_<%=cid%>",client_<%=cid%>);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -100,10 +100,11 @@
|
||||
</PARAMETERS>
|
||||
|
||||
<CODEGENERATION>
|
||||
<IMPORTS>
|
||||
<IMPORT NAME="Java_SCP" MODULE="ganymed-ssh2-261.jar" MVN="mvn:ch.ethz.ganymed/ganymed-ssh2/261" REQUIRED="true"/>
|
||||
</IMPORTS>
|
||||
</CODEGENERATION>
|
||||
<IMPORTS>
|
||||
<IMPORT NAME="SSHD_CORE" MODULE="sshd-core-2.5.1.jar" MVN="mvn:org.apache.sshd/sshd-core/2.5.1" REQUIRED="true"/>
|
||||
<IMPORT NAME="SSHD_COMMON" MODULE="sshd-common-2.5.1.jar" MVN="mvn:org.apache.sshd/sshd-common/2.5.1" REQUIRED="true"/>
|
||||
</IMPORTS>
|
||||
</CODEGENERATION>
|
||||
|
||||
<RETURNS/>
|
||||
</COMPONENT>
|
||||
|
||||
@@ -1,168 +1,2 @@
|
||||
<%@ jet
|
||||
imports="
|
||||
org.talend.core.model.process.INode
|
||||
org.talend.core.model.process.ElementParameterParser
|
||||
org.talend.designer.codegen.config.CodeGeneratorArgument
|
||||
org.talend.core.model.process.IElementParameter
|
||||
org.talend.core.model.utils.NodeUtil
|
||||
"
|
||||
%>
|
||||
<%@ include file="../templates/Log4j/Log4jFileUtil.javajet"%>
|
||||
<%
|
||||
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
|
||||
INode node = (INode)codeGenArgument.getArgument();
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
log4jFileUtil.componentStartInfo(node);
|
||||
String cid = node.getUniqueName();
|
||||
String host = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__HOST__"
|
||||
);
|
||||
String port = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__PORT__"
|
||||
);
|
||||
String user = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__USERNAME__"
|
||||
);
|
||||
String authMethod = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__AUTH_METHOD__"
|
||||
);
|
||||
String privatekey = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__PRIVATEKEY__"
|
||||
);
|
||||
String password = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__PASSWORD__"
|
||||
);
|
||||
String passphrase = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__PASSPHRASE__"
|
||||
);
|
||||
%>
|
||||
int nb_file_<%=cid%> = 0;
|
||||
/* Create a connection instance */
|
||||
ch.ethz.ssh2.Connection conn_<%=cid %>=null;
|
||||
<%
|
||||
String useExistingConn = ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__");
|
||||
if(("true").equals(useExistingConn)){
|
||||
String connection = ElementParameterParser.getValue(node, "__CONNECTION__");
|
||||
String conn= "conn_" + connection;
|
||||
%>
|
||||
conn_<%=cid %> = (ch.ethz.ssh2.Connection)globalMap.get("<%=conn %>");
|
||||
String hostname_<%=cid%> = <%=host%>;
|
||||
String username_<%=cid%> = <%=user%>;
|
||||
<%if(isLog4jEnabled){%>
|
||||
if(conn_<%=cid %>!=null) {
|
||||
log.info("<%=cid%> - Uses an existing connection. Connection hostname: " + conn_<%=cid %>.getHostname() + ". Connection port: " + conn_<%=cid %>.getPort() + ".");
|
||||
}
|
||||
<%}%>
|
||||
|
||||
<%}else{%>
|
||||
String hostname_<%=cid%> = <%=host%>;
|
||||
String username_<%=cid%> = <%=user%>;
|
||||
<%
|
||||
if(("").equals(port)){
|
||||
%>
|
||||
conn_<%=cid%> = new ch.ethz.ssh2.Connection(hostname_<%=cid%>);
|
||||
<%
|
||||
} else {
|
||||
%>
|
||||
conn_<%=cid%> = new ch.ethz.ssh2.Connection(hostname_<%=cid%>,<%=port%>);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
/* Now connect */
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Attempt to connect to '" + hostname_<%=cid%> + "' with the username '" + username_<%=cid%> + "'.");
|
||||
<%}%>
|
||||
conn_<%=cid%>.connect();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connect to '" + hostname_<%=cid%> + "' has succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
if (("PUBLICKEY").equals(authMethod)) {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using a public key");
|
||||
log.debug("<%=cid%> - Private key: '" + <%=privatekey%> + "'." );
|
||||
<%}%>
|
||||
java.io.File keyfile_<%=cid%> = new java.io.File(<%=privatekey%>);
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASSPHRASE__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
boolean isAuthenticated_<%=cid%> = conn_<%=cid%>.authenticateWithPublicKey(username_<%=cid%>, keyfile_<%=cid%>, decryptedPassword_<%=cid%>);
|
||||
if (isAuthenticated_<%=cid%> == false){
|
||||
throw new RuntimeException("Authentication failed.");
|
||||
}
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
if (("PASSWORD").equals(authMethod)) {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using a password");
|
||||
<%}%>
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
boolean isAuthenticated_<%=cid%> = conn_<%=cid%>.authenticateWithPassword(username_<%=cid%>, decryptedPassword_<%=cid%>);
|
||||
if (isAuthenticated_<%=cid%> == false){
|
||||
throw new RuntimeException("Authentication failed.");
|
||||
}
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
if (("KEYBOARDINTERACTIVE").equals(authMethod)) {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using an interactive action");
|
||||
<%}%>
|
||||
boolean isAuthenticated_<%=cid%> = conn_<%=cid%>.authenticateWithKeyboardInteractive(username_<%=cid%>,
|
||||
new ch.ethz.ssh2.InteractiveCallback() {
|
||||
|
||||
public String[] replyToChallenge(String name,
|
||||
String instruction, int numPrompts,
|
||||
String[] prompt, boolean[] echo)
|
||||
throws java.lang.Exception {
|
||||
String[] reply = new String[numPrompts];
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
for (int i = 0; i < reply.length; i++) {
|
||||
reply[i] = decryptedPassword_<%=cid%>;
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
}
|
||||
);
|
||||
if (isAuthenticated_<%=cid%> == false){
|
||||
throw new RuntimeException("Authentication failed.");
|
||||
}
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
}//if(isExistingConn)
|
||||
%>
|
||||
<%@ include file="../tSCPFileExists/tSCPFileExists_begin.javajet"%>
|
||||
int nb_file_<%=cid%> = 0;
|
||||
@@ -16,7 +16,7 @@ imports="
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Closing the connection to the server.");
|
||||
<%}%>
|
||||
conn_<%=cid%>.close();
|
||||
client_<%=cid%>.close();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connection to the server closed.");
|
||||
<%}%>
|
||||
|
||||
@@ -140,11 +140,12 @@
|
||||
</PARAMETER>
|
||||
</PARAMETERS>
|
||||
|
||||
<CODEGENERATION>
|
||||
<IMPORTS>
|
||||
<IMPORT NAME="Java_SCP" MODULE="ganymed-ssh2-261.jar" MVN="mvn:ch.ethz.ganymed/ganymed-ssh2/261" REQUIRED="true"/>
|
||||
</IMPORTS>
|
||||
</CODEGENERATION>
|
||||
<CODEGENERATION>
|
||||
<IMPORTS>
|
||||
<IMPORT NAME="SSHD_CORE" MODULE="sshd-core-2.5.1.jar" MVN="mvn:org.apache.sshd/sshd-core/2.5.1" REQUIRED="true"/>
|
||||
<IMPORT NAME="SSHD_COMMON" MODULE="sshd-common-2.5.1.jar" MVN="mvn:org.apache.sshd/sshd-common/2.5.1" REQUIRED="true"/>
|
||||
</IMPORTS>
|
||||
</CODEGENERATION>
|
||||
|
||||
<RETURNS>
|
||||
<RETURN NAME="STATUS" TYPE="id_String" AVAILABILITY="AFTER"/>
|
||||
|
||||
@@ -5,15 +5,25 @@ imports="
|
||||
org.talend.designer.codegen.config.CodeGeneratorArgument
|
||||
java.util.List
|
||||
java.util.Map
|
||||
org.talend.core.model.utils.NodeUtil
|
||||
"
|
||||
%>
|
||||
|
||||
<%
|
||||
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
|
||||
INode node = (INode)codeGenArgument.getArgument();
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
String authMethod = ElementParameterParser.getValue(node,"__AUTH_METHOD__");
|
||||
String cid = node.getUniqueName();
|
||||
List<Map<String, String>> filelist = (List<Map<String,String>>)ElementParameterParser.getObjectValue(node, "__FILELIST__");
|
||||
boolean dieOnError = "true".equals(ElementParameterParser.getValue(node, "__DIE_ON_ERROR__"));
|
||||
String useExistingConn = ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__");
|
||||
if(("true").equals(useExistingConn)){
|
||||
String connection = ElementParameterParser.getValue(node, "__CONNECTION__");
|
||||
INode connectionNode = NodeUtil.getNodeByUniqueName(node.getProcess(), connection);
|
||||
authMethod = ElementParameterParser.getValue(connectionNode,"__AUTH_METHOD__");
|
||||
}
|
||||
|
||||
if(dieOnError){
|
||||
%>
|
||||
boolean isCmdFailed_<%= cid %> = false;
|
||||
@@ -21,7 +31,32 @@ imports="
|
||||
}
|
||||
%>
|
||||
StringBuilder command_<%=cid %> = new StringBuilder("rm -f");
|
||||
ch.ethz.ssh2.Session sessNew_<%=cid%> = conn_<%=cid%>.openSession();
|
||||
/* open a session */
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Open up a session.");
|
||||
log.debug("<%=cid%> - execute the command: " + command_<%=cid %>.toString());
|
||||
<%}%>
|
||||
|
||||
session_<%=cid%> = client_<%=cid%>.connect(username_<%=cid%>, hostname_<%=cid%>, port_<%=cid%>).verify().getClientSession();
|
||||
try {
|
||||
session_<%=cid%>.auth().verify();
|
||||
}catch (org.apache.sshd.common.SshException se_<%=cid%>){
|
||||
globalMap.put("<%=cid %>_EXIT_CODE",se_<%=cid%>.getDisconnectCode());
|
||||
<%
|
||||
if (("PUBLICKEY").equals(authMethod)) {
|
||||
%>
|
||||
java.nio.file.Files.write(privateKey_<%=cid%>,lines_<%=cid%>);
|
||||
<%}%>
|
||||
if(14 == se_<%=cid%>.getDisconnectCode()){
|
||||
throw new IllegalArgumentException("Authentication failed.");
|
||||
}else{
|
||||
throw se_<%=cid%>;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
<%
|
||||
for(Map<String,String> map : filelist){
|
||||
%>
|
||||
@@ -36,21 +71,48 @@ imports="
|
||||
|
||||
String rmCmd_<%= cid %> = command_<%=cid %>.toString();
|
||||
if(!"rm -f".equals(rmCmd_<%= cid %>)){
|
||||
sessNew_<%=cid%>.execCommand(rmCmd_<%= cid %>);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("Execute command: "+ rmCmd_<%= cid %>);
|
||||
<%}%>
|
||||
org.apache.sshd.client.channel.ClientChannel channel_<%=cid %> = session_<%=cid %>.createExecChannel((command_<%=cid %>).toString());
|
||||
java.io.ByteArrayOutputStream stdout_<%=cid %> = new java.io.ByteArrayOutputStream();
|
||||
java.io.ByteArrayOutputStream stderr_<%=cid %> = new java.io.ByteArrayOutputStream();
|
||||
channel_<%=cid%>.setOut(stdout_<%=cid %>);
|
||||
channel_<%=cid%>.setErr(stderr_<%=cid %>);
|
||||
channel_<%=cid%>.open();
|
||||
java.util.Set<org.apache.sshd.client.channel.ClientChannelEvent> clientChannelEvents_<%=cid %> =
|
||||
channel_<%=cid%>.waitFor(java.util.EnumSet.of(
|
||||
org.apache.sshd.client.channel.ClientChannelEvent.CLOSED,org.apache.sshd.client.channel.ClientChannelEvent.EXIT_STATUS), 0L);
|
||||
exit_code_<%=cid%> = channel_<%=cid%>.getExitStatus();
|
||||
channel_<%=cid%>.close();
|
||||
session_<%=cid%>.close();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("Channel Events: "+ java.util.Arrays.toString(clientChannelEvents_<%=cid %>.toArray()));
|
||||
<%}%>
|
||||
stringStdout_<%=cid%>.append(stdout_<%=cid%>.toString());
|
||||
stringStderr_<%=cid%>.append(stderr_<%=cid%>.toString());
|
||||
|
||||
if(stringStdout_<%=cid%>.length() >0 && stringStdout_<%=cid%>.charAt(stringStdout_<%=cid%>.length()-1) == '\n'){
|
||||
stringStdout_<%=cid%>.deleteCharAt(stringStdout_<%=cid%>.length()-1);
|
||||
}
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - Command line standard result: " + stringStdout_<%=cid%>.toString());
|
||||
log.debug("<%=cid%> - Command line error result: " + stringStderr_<%=cid%>.toString());
|
||||
<%}%>
|
||||
|
||||
<% if(dieOnError){ %>
|
||||
StringBuilder errMsg_<%= cid %> = new StringBuilder("File(s) deleting failed.");
|
||||
int returnCondition_<%= cid %> = sessNew_<%=cid%>.waitForCondition(ch.ethz.ssh2.ChannelCondition.EXIT_STATUS,300L);
|
||||
Integer exitCode_<%= cid %> = sessNew_<%=cid%>.getExitStatus();
|
||||
if((returnCondition_<%= cid %> & ch.ethz.ssh2.ChannelCondition.EXIT_STATUS) == ch.ethz.ssh2.ChannelCondition.EXIT_STATUS){
|
||||
if (exitCode_<%= cid %> != 0) {
|
||||
if(clientChannelEvents_<%=cid %>.contains(org.apache.sshd.client.channel.ClientChannelEvent.EXIT_STATUS)){
|
||||
if (exit_code_<%= cid %> != 0) {
|
||||
isCmdFailed_<%= cid %> = true;
|
||||
errMsg_<%= cid %>.append("Exit code: ");
|
||||
errMsg_<%= cid %>.append(exitCode_<%= cid %>);
|
||||
errMsg_<%= cid %>.append(exit_code_<%= cid %>);
|
||||
}
|
||||
}else if((returnCondition_<%= cid %> & ch.ethz.ssh2.ChannelCondition.TIMEOUT) == ch.ethz.ssh2.ChannelCondition.TIMEOUT){
|
||||
}else if(clientChannelEvents_<%=cid %>.contains(org.apache.sshd.client.channel.ClientChannelEvent.TIMEOUT)){
|
||||
isCmdFailed_<%= cid %> = true;
|
||||
errMsg_<%= cid %>.append("The request timeout.");
|
||||
}else if((returnCondition_<%= cid %> & ch.ethz.ssh2.ChannelCondition.CLOSED) == ch.ethz.ssh2.ChannelCondition.CLOSED){
|
||||
}else if(clientChannelEvents_<%=cid %>.contains(org.apache.sshd.client.channel.ClientChannelEvent.CLOSED)){
|
||||
isCmdFailed_<%= cid %> = true;
|
||||
errMsg_<%= cid %>.append("Unexpected closed session.");
|
||||
}else{
|
||||
@@ -59,16 +121,8 @@ imports="
|
||||
}
|
||||
<% } %>
|
||||
|
||||
java.io.InputStream stderr_<%=cid%> = sessNew_<%=cid%>.getStderr();
|
||||
java.io.BufferedReader breer_<%=cid%>= new java.io.BufferedReader(new java.io.InputStreamReader(stderr_<%=cid%>));
|
||||
String line_err_<%=cid%> = "";
|
||||
StringBuilder stringStderr_<%=cid%> =new StringBuilder();
|
||||
while((line_err_<%=cid%> = breer_<%=cid%>.readLine()) != null) {
|
||||
String errInfo_<%= cid %> = new String(line_err_<%=cid%>.getBytes(),"UTF-8");
|
||||
System.err.println(errInfo_<%= cid %>);
|
||||
stringStderr_<%=cid%>.append(line_err_<%=cid%> + "\n");
|
||||
}
|
||||
String stderrString_<%=cid %> = stringStderr_<%=cid %>.toString();
|
||||
String stderrString_<%=cid %> = stringStderr_<%=cid%>.toString();
|
||||
System.err.println(stderrString_<%=cid %>);
|
||||
|
||||
<% if(dieOnError){
|
||||
%>
|
||||
@@ -88,9 +142,6 @@ imports="
|
||||
}
|
||||
<%}%>
|
||||
|
||||
breer_<%=cid%>.close();
|
||||
stderr_<%=cid%>.close();
|
||||
|
||||
if("".equals(stderrString_<%=cid %>) || (stderrString_<%=cid %> == null)){
|
||||
globalMap.put("<%=cid %>_STATUS","File(s) deleted OK");
|
||||
}else{
|
||||
@@ -100,4 +151,3 @@ imports="
|
||||
}else{
|
||||
globalMap.put("<%=cid %>_STATUS","No file to be deleted.");
|
||||
}
|
||||
sessNew_<%=cid%>.close();
|
||||
|
||||
@@ -1,164 +1,150 @@
|
||||
<%@ jet
|
||||
<%@ jet
|
||||
imports="
|
||||
org.talend.core.model.process.INode
|
||||
org.talend.core.model.process.INode
|
||||
org.talend.core.model.process.ElementParameterParser
|
||||
org.talend.designer.codegen.config.CodeGeneratorArgument
|
||||
org.talend.core.model.process.IElementParameter
|
||||
org.talend.core.model.utils.NodeUtil
|
||||
"
|
||||
org.talend.core.model.utils.NodeUtil
|
||||
"
|
||||
%>
|
||||
<%@ include file="../templates/Log4j/Log4jFileUtil.javajet"%>
|
||||
<%@ include file="../templates/Log4j/Log4jFileUtil.javajet"%>
|
||||
<%
|
||||
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
|
||||
INode node = (INode)codeGenArgument.getArgument();
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
log4jFileUtil.componentStartInfo(node);
|
||||
String cid = node.getUniqueName();
|
||||
String host = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__HOST__"
|
||||
);
|
||||
String port = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__PORT__"
|
||||
);
|
||||
String user = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__USERNAME__"
|
||||
);
|
||||
String authMethod = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__AUTH_METHOD__"
|
||||
);
|
||||
String privatekey = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__PRIVATEKEY__"
|
||||
);
|
||||
String password = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__PASSWORD__"
|
||||
);
|
||||
String passphrase = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__PASSPHRASE__"
|
||||
);
|
||||
String host = ElementParameterParser.getValue(node,"__HOST__");
|
||||
String port = ElementParameterParser.getValue(node,"__PORT__");
|
||||
String user = ElementParameterParser.getValue(node,"__USERNAME__");
|
||||
String authMethod = ElementParameterParser.getValue(node,"__AUTH_METHOD__");
|
||||
String privatekey = ElementParameterParser.getValue(node,"__PRIVATEKEY__");
|
||||
String password = ElementParameterParser.getValue(node,"__PASSWORD__");
|
||||
String passphrase = ElementParameterParser.getValue(node,"__PASSPHRASE__");
|
||||
%>
|
||||
/* Create a connection instance */
|
||||
<%
|
||||
String useExistingConn = ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__");
|
||||
if(("true").equals(useExistingConn)){
|
||||
String connection = ElementParameterParser.getValue(node, "__CONNECTION__");
|
||||
String conn= "conn_" + connection;
|
||||
/* Create a connection instance */
|
||||
<%
|
||||
String useExistingConn = ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__");
|
||||
if(("true").equals(useExistingConn)){
|
||||
String connection = ElementParameterParser.getValue(node, "__CONNECTION__");
|
||||
String conn= "conn_" + connection;
|
||||
INode connectionNode = NodeUtil.getNodeByUniqueName(node.getProcess(), connection);
|
||||
host = ElementParameterParser.getValue(connectionNode, "__HOST__");
|
||||
port = ElementParameterParser.getValue(connectionNode, "__PORT__");
|
||||
user = ElementParameterParser.getValue(connectionNode,"__USERNAME__");
|
||||
authMethod = ElementParameterParser.getValue(connectionNode,"__AUTH_METHOD__");
|
||||
%>
|
||||
ch.ethz.ssh2.Connection conn_<%=cid %> = (ch.ethz.ssh2.Connection)globalMap.get("<%=conn %>");
|
||||
<%if(isLog4jEnabled){%>
|
||||
if(conn_<%=cid %>!=null) {
|
||||
log.info("<%=cid%> - Uses an existing connection. Connection hostname: " + conn_<%=cid %>.getHostname() + ". Connection port: " + conn_<%=cid %>.getPort() + ".");
|
||||
}
|
||||
<%}%>
|
||||
|
||||
<%}else{%>
|
||||
String hostname_<%=cid %> = <%=host %>;
|
||||
String username_<%=cid %> = <%=user %>;
|
||||
<%
|
||||
if(("").equals(port)){
|
||||
%>
|
||||
ch.ethz.ssh2.Connection conn_<%=cid%> = new ch.ethz.ssh2.Connection(hostname_<%=cid%>);
|
||||
<%
|
||||
} else {
|
||||
%>
|
||||
ch.ethz.ssh2.Connection conn_<%=cid%> = new ch.ethz.ssh2.Connection(hostname_<%=cid%>,<%=port%>);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
/* Now connect */
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Attempt to connect to '" + hostname_<%=cid%> + "' with the username '" + <%=user%> + "'.");
|
||||
<%}%>
|
||||
conn_<%=cid%>.connect();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connect to '" + hostname_<%=cid%> + "' has succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
org.apache.sshd.client.SshClient client_<%=cid%> = (org.apache.sshd.client.SshClient)globalMap.get("conn_<%=connection%>");
|
||||
<%
|
||||
if (("PUBLICKEY").equals(authMethod)) {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using a public key");
|
||||
log.debug("<%=cid%> - Private key: '" + <%=privatekey%> + "'." );
|
||||
<%}%>
|
||||
java.io.File keyfile_<%=cid%> = new java.io.File(<%=privatekey%>);
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASSPHRASE__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
boolean isAuthenticated_<%=cid%> = conn_<%=cid%>.authenticateWithPublicKey(username_<%=cid%>, keyfile_<%=cid%>, decryptedPassword_<%=cid%>);
|
||||
if (isAuthenticated_<%=cid%> == false){
|
||||
throw new RuntimeException("Authentication failed.");
|
||||
}
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
if (("PASSWORD").equals(authMethod)) {
|
||||
%>
|
||||
%>
|
||||
java.nio.file.Path privateKey_<%=cid%> = (java.nio.file.Path)globalMap.get("privateKey_<%=connection%>");
|
||||
java.util.List<String> lines_<%=cid%> = (java.util.List<String>)globalMap.get("lines_<%=connection%>");
|
||||
<%}%>
|
||||
String hostname_<%=cid%> = <%=host%>;
|
||||
String username_<%=cid%> = <%=user%>;
|
||||
<%if(isLog4jEnabled){%>
|
||||
if(client_<%=cid %>!=null) {
|
||||
log.info("<%=cid%> - Uses an existing connection. Connection hostname: "+ <%=host %> + ". Connection port: <%=port %>.");
|
||||
}
|
||||
<%}%>
|
||||
<%}else{%>
|
||||
String hostname_<%=cid%> = <%=host%>;
|
||||
String username_<%=cid%> = <%=user%>;
|
||||
/* Create a connection instance */
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connection attempt to '" +hostname_<%=cid%> + "' on the port '"+<%=port%>+"' as '" + username_<%=cid%> + "'.");
|
||||
<%}%>
|
||||
org.apache.sshd.client.SshClient client_<%=cid%> = org.apache.sshd.client.SshClient.setUpDefaultClient();
|
||||
client_<%=cid%>.getProperties().putIfAbsent(org.apache.sshd.common.FactoryManager.IDLE_TIMEOUT, 0L);
|
||||
client_<%=cid%>.getProperties().putIfAbsent(org.apache.sshd.common.FactoryManager.NIO2_READ_TIMEOUT, 0L);
|
||||
<%
|
||||
if (("PUBLICKEY").equals(authMethod)) {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using a public key.");
|
||||
<%}%>
|
||||
client_<%=cid%>.setUserAuthFactories(java.util.Collections.singletonList(org.apache.sshd.client.auth.pubkey.UserAuthPublicKeyFactory.INSTANCE));
|
||||
java.nio.file.Path privateKey_<%=cid%> = java.nio.file.Paths.get(<%=privatekey%>);
|
||||
java.util.List<String> lines_<%=cid%> = java.nio.file.Files.readAllLines(privateKey_<%=cid%>);
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using a password");
|
||||
<%}%>
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
boolean isAuthenticated_<%=cid%> = conn_<%=cid%>.authenticateWithPassword(username_<%=cid%>, decryptedPassword_<%=cid%>);
|
||||
if (isAuthenticated_<%=cid%> == false){
|
||||
throw new RuntimeException("Authentication failed.");
|
||||
}
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
if (("KEYBOARDINTERACTIVE").equals(authMethod)) {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using an interactive action");
|
||||
<%}%>
|
||||
boolean isAuthenticated_<%=cid%> = conn_<%=cid%>.authenticateWithKeyboardInteractive(username_<%=cid%>,
|
||||
new ch.ethz.ssh2.InteractiveCallback() {
|
||||
|
||||
public String[] replyToChallenge(String name,
|
||||
String instruction, int numPrompts,
|
||||
String[] prompt, boolean[] echo)
|
||||
throws java.lang.Exception {
|
||||
String[] reply = new String[numPrompts];
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
for (int i = 0; i < reply.length; i++) {
|
||||
reply[i] = decryptedPassword_<%=cid%>;
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
}
|
||||
);
|
||||
if (isAuthenticated_<%=cid%> == false){
|
||||
throw new RuntimeException("Authentication failed.");
|
||||
}
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
}// if(existconn)
|
||||
%>
|
||||
org.apache.sshd.common.util.security.bouncycastle.BouncyCastleGeneratorHostKeyProvider keyProvider_<%=cid%> =
|
||||
new org.apache.sshd.common.util.security.bouncycastle.BouncyCastleGeneratorHostKeyProvider(privateKey_<%=cid%>)
|
||||
|
||||
{
|
||||
|
||||
@Override
|
||||
protected Iterable<java.security.KeyPair> doReadKeyPairs(org.apache.sshd.common.session.SessionContext session,
|
||||
org.apache.sshd.common.NamedResource resourceKey, java.io.InputStream inputStream)
|
||||
throws java.io.IOException, java.security.GeneralSecurityException {
|
||||
<%String passwordFieldName = "__PASSPHRASE__";%>
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
Iterable<java.security.KeyPair> keyPairs =
|
||||
org.apache.sshd.common.util.security.SecurityUtils.loadKeyPairIdentities(session, resourceKey, inputStream,
|
||||
(sessionContext, namedResource, i) -> decryptedPassword_<%=cid%>);
|
||||
return keyPairs;
|
||||
}
|
||||
};
|
||||
if (lines_<%=cid%>.size()>0) {
|
||||
String[] line_<%=cid%> = lines_<%=cid%>.get(0).split(" ");
|
||||
if ("-----BEGIN".equals(line_<%=cid%>[0])) {
|
||||
keyProvider_<%=cid%>.setAlgorithm(line_<%=cid%>[1]);
|
||||
}
|
||||
}
|
||||
client_<%=cid%>.setKeyIdentityProvider(keyProvider_<%=cid%>);
|
||||
|
||||
<%}%>
|
||||
<%
|
||||
if (("KEYBOARDINTERACTIVE").equals(authMethod)) {
|
||||
%>
|
||||
|
||||
client_<%=cid%>.setUserAuthFactories(java.util.Collections.singletonList(org.apache.sshd.client.auth.keyboard.UserAuthKeyboardInteractiveFactory.INSTANCE));
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using an interactive action.");
|
||||
<%}%>
|
||||
|
||||
client_<%=cid%>.setUserInteraction(new org.apache.sshd.client.auth.keyboard.UserInteraction() {
|
||||
|
||||
@Override
|
||||
public String[] interactive(org.apache.sshd.client.session.ClientSession clientSession, String name, String instruction, String lang, String[] prompt,
|
||||
boolean[] echo) {
|
||||
|
||||
<% String passwordFieldName = "__PASSWORD__"; %>
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
String[] reply = new String[prompt.length];
|
||||
for (int i = 0; i < reply.length; i++) {
|
||||
reply[i] = decryptedPassword_<%=cid%>;
|
||||
}
|
||||
return reply;
|
||||
}
|
||||
|
||||
@Override public String getUpdatedPassword(org.apache.sshd.client.session.ClientSession clientSession, String prompt, String lang) {
|
||||
throw new IllegalStateException("getUpdatedPassword(" + clientSession + ")[" + prompt + "] unexpected call");
|
||||
}
|
||||
});
|
||||
|
||||
<%
|
||||
}
|
||||
%>
|
||||
|
||||
<%if (("PASSWORD").equals(authMethod)) {%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using a password.");
|
||||
<%}%>
|
||||
<%String passwordFieldName = "__PASSWORD__";%>
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
client_<%=cid%>.addPasswordIdentity(decryptedPassword_<%=cid%>);
|
||||
<%}%>
|
||||
client_<%=cid%>.start();
|
||||
<%
|
||||
}//if(isExistingConn)
|
||||
%>
|
||||
|
||||
/* Create a session */
|
||||
|
||||
org.apache.sshd.client.session.ClientSession session_<%=cid%> = null;
|
||||
int port_<%=cid%> = Integer.parseInt(<%=port %>+"");
|
||||
StringBuilder stringStdout_<%=cid%> =new StringBuilder();
|
||||
StringBuilder stringStderr_<%=cid%> =new StringBuilder();
|
||||
Integer exit_code_<%=cid%> = null;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<%@ jet
|
||||
<%@ jet
|
||||
imports="
|
||||
org.talend.core.model.process.INode
|
||||
org.talend.core.model.process.INode
|
||||
org.talend.designer.codegen.config.CodeGeneratorArgument
|
||||
org.talend.core.model.process.ElementParameterParser
|
||||
"
|
||||
@@ -11,14 +11,14 @@ imports="
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
String cid = node.getUniqueName();
|
||||
String useExistingConn = ElementParameterParser.getValue(node,"__USE_EXISTING_CONNECTION__");
|
||||
if(!("true").equals(useExistingConn)){
|
||||
%>
|
||||
if(!("true").equals(useExistingConn)){
|
||||
%>
|
||||
/* Close the connection */
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Closing the connection to the server.");
|
||||
<%}%>
|
||||
conn_<%=cid%>.close();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connection to the server closed.");
|
||||
<%}%>
|
||||
<% }%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Closing the connection to the server.");
|
||||
<%}%>
|
||||
client_<%=cid%>.close();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connection to the server closed.");
|
||||
<%}%>
|
||||
<% }%>
|
||||
|
||||
@@ -140,7 +140,8 @@
|
||||
|
||||
<CODEGENERATION>
|
||||
<IMPORTS>
|
||||
<IMPORT NAME="Java_SCP" MODULE="ganymed-ssh2-261.jar" MVN="mvn:ch.ethz.ganymed/ganymed-ssh2/261" REQUIRED="true"/>
|
||||
<IMPORT NAME="SSHD_CORE" MODULE="sshd-core-2.5.1.jar" MVN="mvn:org.apache.sshd/sshd-core/2.5.1" REQUIRED="true"/>
|
||||
<IMPORT NAME="SSHD_COMMON" MODULE="sshd-common-2.5.1.jar" MVN="mvn:org.apache.sshd/sshd-common/2.5.1" REQUIRED="true"/>
|
||||
</IMPORTS>
|
||||
</CODEGENERATION>
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ imports="
|
||||
org.talend.core.model.process.INode
|
||||
org.talend.core.model.process.ElementParameterParser
|
||||
org.talend.designer.codegen.config.CodeGeneratorArgument
|
||||
org.talend.core.model.utils.NodeUtil
|
||||
"
|
||||
%>
|
||||
<%
|
||||
@@ -11,66 +12,97 @@ imports="
|
||||
String cid = node.getUniqueName();
|
||||
String remoteDir = ElementParameterParser.getValue(node,"__REMOTEDIR__");
|
||||
String fileExists = ElementParameterParser.getValue(node,"__EXISTFILE__");
|
||||
String authMethod = ElementParameterParser.getValue(node,"__AUTH_METHOD__");
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
String useExistingConn = ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__");
|
||||
if(("true").equals(useExistingConn)){
|
||||
String connection = ElementParameterParser.getValue(node, "__CONNECTION__");
|
||||
INode connectionNode = NodeUtil.getNodeByUniqueName(node.getProcess(), connection);
|
||||
authMethod = ElementParameterParser.getValue(connectionNode,"__AUTH_METHOD__");
|
||||
}
|
||||
%>
|
||||
|
||||
//initial the command
|
||||
StringBuilder command_<%=cid%> = new StringBuilder();
|
||||
|
||||
final String dir_<%=cid%> = String.valueOf(<%=remoteDir %>);
|
||||
final String file_<%=cid%> = String.valueOf(<%=fileExists %>);
|
||||
|
||||
command_<%=cid%>.append("ls ");
|
||||
|
||||
if(dir_<%=cid%>.contains("*") || dir_<%=cid%>.contains("?") || dir_<%=cid%>.contains("[") || dir_<%=cid%>.contains("]")) {
|
||||
command_<%=cid%>.append(dir_<%=cid%>);
|
||||
|
||||
//initial the command
|
||||
StringBuilder command_<%=cid%> = new StringBuilder();
|
||||
|
||||
final String dir_<%=cid%> = String.valueOf(<%=remoteDir %>);
|
||||
final String file_<%=cid%> = String.valueOf(<%=fileExists %>);
|
||||
|
||||
command_<%=cid%>.append("ls ");
|
||||
|
||||
if(dir_<%=cid%>.contains("*") || dir_<%=cid%>.contains("?") || dir_<%=cid%>.contains("[") || dir_<%=cid%>.contains("]")) {
|
||||
command_<%=cid%>.append(dir_<%=cid%>);
|
||||
} else {
|
||||
command_<%=cid%>.append("\"").append(dir_<%=cid%>).append("\"");
|
||||
command_<%=cid%>.append("\"").append(dir_<%=cid%>).append("\"");
|
||||
}
|
||||
|
||||
|
||||
command_<%=cid%>.append("/");
|
||||
|
||||
if(file_<%=cid%>.contains("*") || file_<%=cid%>.contains("?") || file_<%=cid%>.contains("[") || file_<%=cid%>.contains("]")) {
|
||||
command_<%=cid%>.append(file_<%=cid%>);
|
||||
|
||||
if(file_<%=cid%>.contains("*") || file_<%=cid%>.contains("?") || file_<%=cid%>.contains("[") || file_<%=cid%>.contains("]")) {
|
||||
command_<%=cid%>.append(file_<%=cid%>);
|
||||
} else {
|
||||
command_<%=cid%>.append("\"").append(file_<%=cid%>).append("\"");
|
||||
command_<%=cid%>.append("\"").append(file_<%=cid%>).append("\"");
|
||||
}
|
||||
|
||||
globalMap.put("<%=cid %>_FILENAME", <%=fileExists %>);
|
||||
/* Create a session */
|
||||
ch.ethz.ssh2.Session sess_<%=cid%> = conn_<%=cid%>.openSession();
|
||||
//execute the command
|
||||
sess_<%=cid%>.execCommand((command_<%=cid%>).toString());
|
||||
|
||||
//get the return info
|
||||
java.io.InputStream stdout_<%=cid%> = sess_<%=cid%>.getStdout();
|
||||
java.io.BufferedReader brout_<%=cid%>= new java.io.BufferedReader(new java.io.InputStreamReader(stdout_<%=cid%>));
|
||||
String line_out_<%=cid%> = "";
|
||||
StringBuilder stringStdout_<%=cid%> =new StringBuilder();
|
||||
while((line_out_<%=cid%> = brout_<%=cid%>.readLine()) != null) {
|
||||
stringStdout_<%=cid%>.append(line_out_<%=cid%> + "\n");
|
||||
}
|
||||
brout_<%=cid%>.close();
|
||||
stdout_<%=cid%>.close();
|
||||
java.io.InputStream stderr_<%=cid%> = sess_<%=cid%>.getStderr();
|
||||
java.io.BufferedReader breer_<%=cid%>= new java.io.BufferedReader(new java.io.InputStreamReader(stderr_<%=cid%>));
|
||||
String line_err_<%=cid%> = "";
|
||||
StringBuilder stringStderr_<%=cid%> =new StringBuilder();
|
||||
while((line_err_<%=cid%> = breer_<%=cid%>.readLine()) != null) {
|
||||
stringStderr_<%=cid%>.append(line_err_<%=cid%> + "\n");
|
||||
}
|
||||
breer_<%=cid%>.close();
|
||||
stderr_<%=cid%>.close();
|
||||
/* Close this session */
|
||||
sess_<%=cid%>.close();
|
||||
if(("").equals(stringStderr_<%=cid %>.toString()) || stringStderr_<%=cid %>.toString() == null){
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - The file '" + <%=fileExists %> + "' exists in the remote directory '"+ <%=remoteDir %> + "'.");
|
||||
<%}%>
|
||||
globalMap.put("<%=cid %>_STATUS", "File exists.");
|
||||
}else{
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - The file '" + <%=fileExists %> + "' doesn't exist in the remote directory '"+ <%=remoteDir %> + "'.");
|
||||
<%}%>
|
||||
globalMap.put("<%=cid %>_STATUS", stringStderr_<%=cid %>.toString());
|
||||
|
||||
globalMap.put("<%=cid %>_FILENAME", <%=fileExists %>);
|
||||
/* open a session */
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Open up a session.");
|
||||
log.debug("<%=cid%> - execute the command: " + command_<%=cid %>.toString());
|
||||
<%}%>
|
||||
|
||||
session_<%=cid%> = client_<%=cid%>.connect(username_<%=cid%>, hostname_<%=cid%>, port_<%=cid%>).verify().getClientSession();
|
||||
try {
|
||||
session_<%=cid%>.auth().verify();
|
||||
}catch (org.apache.sshd.common.SshException se_<%=cid%>){
|
||||
globalMap.put("<%=cid %>_EXIT_CODE",se_<%=cid%>.getDisconnectCode());
|
||||
<%
|
||||
if (("PUBLICKEY").equals(authMethod)) {
|
||||
%>
|
||||
java.nio.file.Files.write(privateKey_<%=cid%>,lines_<%=cid%>);
|
||||
<%}%>
|
||||
if(14 == se_<%=cid%>.getDisconnectCode()){
|
||||
throw new IllegalArgumentException("Authentication failed.");
|
||||
}else{
|
||||
throw se_<%=cid%>;
|
||||
}
|
||||
}
|
||||
org.apache.sshd.client.channel.ClientChannel channel_<%=cid %> = session_<%=cid %>.createExecChannel((command_<%=cid %>).toString());
|
||||
java.io.ByteArrayOutputStream stdout_<%=cid %> = new java.io.ByteArrayOutputStream();
|
||||
java.io.ByteArrayOutputStream stderr_<%=cid %> = new java.io.ByteArrayOutputStream();
|
||||
channel_<%=cid%>.setOut(stdout_<%=cid %>);
|
||||
channel_<%=cid%>.setErr(stderr_<%=cid %>);
|
||||
channel_<%=cid%>.open();
|
||||
java.util.Set<org.apache.sshd.client.channel.ClientChannelEvent> clientChannelEvents_<%=cid %> =
|
||||
channel_<%=cid%>.waitFor(java.util.EnumSet.of(
|
||||
org.apache.sshd.client.channel.ClientChannelEvent.CLOSED,org.apache.sshd.client.channel.ClientChannelEvent.EXIT_STATUS), 0L);
|
||||
exit_code_<%=cid%> = channel_<%=cid%>.getExitStatus();
|
||||
channel_<%=cid%>.close();
|
||||
session_<%=cid%>.close();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("Channel Events: "+ java.util.Arrays.toString(clientChannelEvents_<%=cid %>.toArray()));
|
||||
<%}%>
|
||||
stringStdout_<%=cid%>.append(stdout_<%=cid%>.toString());
|
||||
stringStderr_<%=cid%>.append(stderr_<%=cid%>.toString());
|
||||
|
||||
if(stringStdout_<%=cid%>.length() >0 && stringStdout_<%=cid%>.charAt(stringStdout_<%=cid%>.length()-1) == '\n'){
|
||||
stringStdout_<%=cid%>.deleteCharAt(stringStdout_<%=cid%>.length()-1);
|
||||
}
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - Command line standard result: " + stringStdout_<%=cid%>.toString());
|
||||
log.debug("<%=cid%> - Command line error result: " + stringStderr_<%=cid%>.toString());
|
||||
<%}%>
|
||||
|
||||
if(("").equals(stringStderr_<%=cid %>.toString()) || stringStderr_<%=cid %>.toString() == null){
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - The file '" + <%=fileExists %> + "' exists in the remote directory '"+ <%=remoteDir %> + "'.");
|
||||
<%}%>
|
||||
globalMap.put("<%=cid %>_STATUS", "File exists.");
|
||||
}else{
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - The file '" + <%=fileExists %> + "' doesn't exist in the remote directory '"+ <%=remoteDir %> + "'.");
|
||||
<%}%>
|
||||
globalMap.put("<%=cid %>_STATUS", stringStderr_<%=cid %>.toString());
|
||||
}
|
||||
|
||||
@@ -15,34 +15,13 @@ imports="
|
||||
INode node = (INode)codeGenArgument.getArgument();
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
String cid = node.getUniqueName();
|
||||
String host = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__HOST__"
|
||||
);
|
||||
String port = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__PORT__"
|
||||
);
|
||||
String user = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__USERNAME__"
|
||||
);
|
||||
String authMethod = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__AUTH_METHOD__"
|
||||
);
|
||||
String privatekey = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__PRIVATEKEY__"
|
||||
);
|
||||
String password = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__PASSWORD__"
|
||||
);
|
||||
String passphrase = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__PASSPHRASE__"
|
||||
);
|
||||
String host = ElementParameterParser.getValue(node,"__HOST__");
|
||||
String port = ElementParameterParser.getValue(node,"__PORT__");
|
||||
String user = ElementParameterParser.getValue(node,"__USERNAME__");
|
||||
String authMethod = ElementParameterParser.getValue(node,"__AUTH_METHOD__");
|
||||
String privatekey = ElementParameterParser.getValue(node,"__PRIVATEKEY__");
|
||||
String password = ElementParameterParser.getValue(node,"__PASSWORD__");
|
||||
String passphrase = ElementParameterParser.getValue(node,"__PASSPHRASE__");
|
||||
String commandSeparator = ElementParameterParser.getValue(node, "__COMMANDSEPARATOR__");
|
||||
List<Map<String, String>> filelist = (List<Map<String,String>>)ElementParameterParser.getObjectValue(node, "__FILELIST__");
|
||||
%>
|
||||
@@ -51,139 +30,205 @@ imports="
|
||||
String useExistingConn = ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__");
|
||||
if(("true").equals(useExistingConn)){
|
||||
String connection = ElementParameterParser.getValue(node, "__CONNECTION__");
|
||||
String conn= "conn_" + connection;
|
||||
INode connectionNode = NodeUtil.getNodeByUniqueName(node.getProcess(), connection);
|
||||
host = ElementParameterParser.getValue(connectionNode, "__HOST__");
|
||||
port = ElementParameterParser.getValue(connectionNode, "__PORT__");
|
||||
user = ElementParameterParser.getValue(connectionNode,"__USERNAME__");
|
||||
authMethod = ElementParameterParser.getValue(connectionNode,"__AUTH_METHOD__");
|
||||
%>
|
||||
ch.ethz.ssh2.Connection conn_<%=cid %> = (ch.ethz.ssh2.Connection)globalMap.get("<%=conn %>");
|
||||
org.apache.sshd.client.SshClient client_<%=cid%> = (org.apache.sshd.client.SshClient)globalMap.get("conn_<%=connection%>");
|
||||
<%
|
||||
if (("PUBLICKEY").equals(authMethod)) {
|
||||
%>
|
||||
java.nio.file.Path privateKey_<%=cid%> = (java.nio.file.Path)globalMap.get("privateKey_<%=connection%>");
|
||||
java.util.List<String> lines_<%=cid%> = (java.util.List<String>)globalMap.get("lines_<%=connection%>");
|
||||
<%}%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
if(conn_<%=cid %>!=null) {
|
||||
log.info("<%=cid%> - Uses an existing connection. Connection hostname: " + conn_<%=cid %>.getHostname() + ". Connection port: " + conn_<%=cid %>.getPort() + ".");
|
||||
if(client_<%=cid %>!=null) {
|
||||
log.info("<%=cid%> - Uses an existing connection. Connection hostname: "+ <%=host %> + ". Connection port: <%=port %>.");
|
||||
}
|
||||
<%}%>
|
||||
<%}else{%>
|
||||
String hostname_<%=cid%> = <%=host%>;
|
||||
String username_<%=cid%> = <%=user%>;
|
||||
String hostname_<%=cid%> = <%=host%>;
|
||||
String username_<%=cid%> = <%=user%>;
|
||||
/* Create a connection instance */
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connection attempt to '" +hostname_<%=cid%> + "' on the port '"+<%=port%>+"' as '" + username_<%=cid%> + "'.");
|
||||
<%}%>
|
||||
org.apache.sshd.client.SshClient client_<%=cid%> = org.apache.sshd.client.SshClient.setUpDefaultClient();
|
||||
client_<%=cid%>.getProperties().putIfAbsent(org.apache.sshd.common.FactoryManager.IDLE_TIMEOUT, 0L);
|
||||
client_<%=cid%>.getProperties().putIfAbsent(org.apache.sshd.common.FactoryManager.NIO2_READ_TIMEOUT, 0L);
|
||||
<%
|
||||
if (("PUBLICKEY").equals(authMethod)) {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using a public key.");
|
||||
<%}%>
|
||||
client_<%=cid%>.setUserAuthFactories(java.util.Collections.singletonList(org.apache.sshd.client.auth.pubkey.UserAuthPublicKeyFactory.INSTANCE));
|
||||
java.nio.file.Path privateKey_<%=cid%> = java.nio.file.Paths.get(<%=privatekey%>);
|
||||
java.util.List<String> lines_<%=cid%> = java.nio.file.Files.readAllLines(privateKey_<%=cid%>);
|
||||
|
||||
org.apache.sshd.common.util.security.bouncycastle.BouncyCastleGeneratorHostKeyProvider keyProvider_<%=cid%> =
|
||||
new org.apache.sshd.common.util.security.bouncycastle.BouncyCastleGeneratorHostKeyProvider(privateKey_<%=cid%>)
|
||||
|
||||
{
|
||||
|
||||
@Override
|
||||
protected Iterable<java.security.KeyPair> doReadKeyPairs(org.apache.sshd.common.session.SessionContext session,
|
||||
org.apache.sshd.common.NamedResource resourceKey, java.io.InputStream inputStream)
|
||||
throws java.io.IOException, java.security.GeneralSecurityException {
|
||||
<%String passwordFieldName = "__PASSPHRASE__";%>
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
Iterable<java.security.KeyPair> keyPairs =
|
||||
org.apache.sshd.common.util.security.SecurityUtils.loadKeyPairIdentities(session, resourceKey, inputStream,
|
||||
(sessionContext, namedResource, i) -> decryptedPassword_<%=cid%>);
|
||||
return keyPairs;
|
||||
}
|
||||
};
|
||||
if (lines_<%=cid%>.size()>0) {
|
||||
String[] line_<%=cid%> = lines_<%=cid%>.get(0).split(" ");
|
||||
if ("-----BEGIN".equals(line_<%=cid%>[0])) {
|
||||
keyProvider_<%=cid%>.setAlgorithm(line_<%=cid%>[1]);
|
||||
}
|
||||
}
|
||||
client_<%=cid%>.setKeyIdentityProvider(keyProvider_<%=cid%>);
|
||||
|
||||
<%}%>
|
||||
<%
|
||||
if (("KEYBOARDINTERACTIVE").equals(authMethod)) {
|
||||
%>
|
||||
|
||||
client_<%=cid%>.setUserAuthFactories(java.util.Collections.singletonList(org.apache.sshd.client.auth.keyboard.UserAuthKeyboardInteractiveFactory.INSTANCE));
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using an interactive action.");
|
||||
<%}%>
|
||||
|
||||
client_<%=cid%>.setUserInteraction(new org.apache.sshd.client.auth.keyboard.UserInteraction() {
|
||||
|
||||
@Override
|
||||
public String[] interactive(org.apache.sshd.client.session.ClientSession clientSession, String name, String instruction, String lang, String[] prompt,
|
||||
boolean[] echo) {
|
||||
|
||||
<% String passwordFieldName = "__PASSWORD__"; %>
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
String[] reply = new String[prompt.length];
|
||||
for (int i = 0; i < reply.length; i++) {
|
||||
reply[i] = decryptedPassword_<%=cid%>;
|
||||
}
|
||||
return reply;
|
||||
}
|
||||
|
||||
@Override public String getUpdatedPassword(org.apache.sshd.client.session.ClientSession clientSession, String prompt, String lang) {
|
||||
throw new IllegalStateException("getUpdatedPassword(" + clientSession + ")[" + prompt + "] unexpected call");
|
||||
}
|
||||
});
|
||||
|
||||
<%
|
||||
}
|
||||
%>
|
||||
|
||||
<%if (("PASSWORD").equals(authMethod)) {%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using a password.");
|
||||
<%}%>
|
||||
<%String passwordFieldName = "__PASSWORD__";%>
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
client_<%=cid%>.addPasswordIdentity(decryptedPassword_<%=cid%>);
|
||||
<%}%>
|
||||
<%
|
||||
if(("").equals(port)){
|
||||
}//if(isExistingConn)
|
||||
%>
|
||||
ch.ethz.ssh2.Connection conn_<%=cid%> = new ch.ethz.ssh2.Connection(hostname_<%=cid%>);
|
||||
<%
|
||||
} else {
|
||||
%>
|
||||
ch.ethz.ssh2.Connection conn_<%=cid%> = new ch.ethz.ssh2.Connection(hostname_<%=cid%>,<%=port%>);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
/* Now connect */
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Attempt to connect to '" + hostname_<%=cid%> + "' with the username '" + username_<%=cid%> + "'.");
|
||||
<%}%>
|
||||
conn_<%=cid%>.connect();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connect to '" + hostname_<%=cid%> + "' has succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
if (("PUBLICKEY").equals(authMethod)) {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using a public key");
|
||||
log.debug("<%=cid%> - Private key: '" + <%=privatekey%> + "'." );
|
||||
<%}%>
|
||||
java.io.File keyfile_<%=cid%> = new java.io.File(<%=privatekey%>);
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASSPHRASE__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
boolean isAuthenticated_<%=cid%> = conn_<%=cid%>.authenticateWithPublicKey(username_<%=cid%>, keyfile_<%=cid%>, decryptedPassword_<%=cid%>);
|
||||
if (isAuthenticated_<%=cid%> == false){
|
||||
throw new RuntimeException("Authentication failed.");
|
||||
}
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
if (("PASSWORD").equals(authMethod)) {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using a password");
|
||||
<%}%>
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
boolean isAuthenticated_<%=cid%> = conn_<%=cid%>.authenticateWithPassword(username_<%=cid%>, decryptedPassword_<%=cid%>);
|
||||
if (isAuthenticated_<%=cid%> == false){
|
||||
throw new RuntimeException("Authentication failed.");
|
||||
}
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
if (("KEYBOARDINTERACTIVE").equals(authMethod)) {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using an interactive action");
|
||||
<%}%>
|
||||
boolean isAuthenticated_<%=cid%> = conn_<%=cid%>.authenticateWithKeyboardInteractive(username_<%=cid%>,
|
||||
new ch.ethz.ssh2.InteractiveCallback() {
|
||||
|
||||
public String[] replyToChallenge(String name,
|
||||
String instruction, int numPrompts,
|
||||
String[] prompt, boolean[] echo)
|
||||
throws java.lang.Exception {
|
||||
String[] reply = new String[numPrompts];
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASSWORD__";
|
||||
|
||||
client_<%=cid%>.start();
|
||||
|
||||
/* Create a session */
|
||||
|
||||
org.apache.sshd.client.session.ClientSession session_<%=cid%> = null;
|
||||
|
||||
/* Now connect */
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connection to '" +<%=host%> + "' has succeeded.");
|
||||
<%}%>
|
||||
|
||||
/* open a session */
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using a password.");
|
||||
<%}%>
|
||||
|
||||
session_<%=cid%> = client_<%=cid%>.connect(<%=user%>, <%=host%>, Integer.parseInt(<%=port %>+"")).verify().getClientSession();
|
||||
try {
|
||||
session_<%=cid%>.auth().verify();
|
||||
}catch (org.apache.sshd.common.SshException se_<%=cid%>){
|
||||
globalMap.put("<%=cid %>_EXIT_CODE",se_<%=cid%>.getDisconnectCode());
|
||||
<%
|
||||
if (("PUBLICKEY").equals(authMethod)) {
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
for (int i = 0; i < reply.length; i++) {
|
||||
reply[i] = decryptedPassword_<%=cid%>;
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
}
|
||||
);
|
||||
if (isAuthenticated_<%=cid%> == false){
|
||||
throw new RuntimeException("Authentication failed.");
|
||||
}
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
}//if(useExistingConn)
|
||||
%>
|
||||
//initial the command
|
||||
java.nio.file.Files.write(privateKey_<%=cid%>,lines_<%=cid%>);
|
||||
<%}%>
|
||||
if(14 == se_<%=cid%>.getDisconnectCode()){
|
||||
throw new IllegalArgumentException("Authentication failed.");
|
||||
}else{
|
||||
throw se_<%=cid%>;
|
||||
}
|
||||
}
|
||||
//execute the command
|
||||
|
||||
//initial the command
|
||||
StringBuilder command_<%=cid %> = new StringBuilder();
|
||||
<%
|
||||
for (Map<String, String> file : filelist) {
|
||||
%>
|
||||
if(command_<%=cid %>.length() > 0){
|
||||
command_<%=cid %>.append(<%=commandSeparator %>);
|
||||
}
|
||||
}
|
||||
command_<%=cid %>.append(<%=file.get("SOURCE")%>);
|
||||
<%
|
||||
<%
|
||||
}
|
||||
%>
|
||||
/* Create a session */
|
||||
ch.ethz.ssh2.Session sess_<%=cid%> = conn_<%=cid%>.openSession();
|
||||
/* Create a Channel */
|
||||
org.apache.sshd.client.channel.ClientChannel channel_<%=cid %> = session_<%=cid %>.createExecChannel((command_<%=cid %>).toString());
|
||||
|
||||
StringBuilder stringStdout_<%=cid%> =new StringBuilder();
|
||||
StringBuilder stringStderr_<%=cid%> =new StringBuilder();
|
||||
Integer exit_code_<%=cid%> = null;
|
||||
|
||||
java.io.ByteArrayOutputStream stdout_<%=cid %> = new java.io.ByteArrayOutputStream();
|
||||
java.io.ByteArrayOutputStream stderr_<%=cid %> = new java.io.ByteArrayOutputStream();
|
||||
channel_<%=cid%>.setOut(stdout_<%=cid %>);
|
||||
channel_<%=cid%>.setErr(stderr_<%=cid %>);
|
||||
channel_<%=cid%>.open();
|
||||
java.util.Set<org.apache.sshd.client.channel.ClientChannelEvent> clientChannelEvents_<%=cid %> =
|
||||
channel_<%=cid%>.waitFor(java.util.EnumSet.of(
|
||||
org.apache.sshd.client.channel.ClientChannelEvent.CLOSED,org.apache.sshd.client.channel.ClientChannelEvent.EXIT_STATUS), 0L);
|
||||
exit_code_<%=cid%> = channel_<%=cid%>.getExitStatus();
|
||||
channel_<%=cid%>.close();
|
||||
session_<%=cid%>.close();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("Channel Events: "+ java.util.Arrays.toString(clientChannelEvents_<%=cid %>.toArray()));
|
||||
<%}%>
|
||||
stringStdout_<%=cid%>.append(stdout_<%=cid%>.toString());
|
||||
stringStderr_<%=cid%>.append(stderr_<%=cid%>.toString());
|
||||
|
||||
if(stringStdout_<%=cid%>.length() >0 && stringStdout_<%=cid%>.charAt(stringStdout_<%=cid%>.length()-1) == '\n'){
|
||||
stringStdout_<%=cid%>.deleteCharAt(stringStdout_<%=cid%>.length()-1);
|
||||
}
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - Command line standard result: " + stringStdout_<%=cid%>.toString());
|
||||
log.debug("<%=cid%> - Command line error result: " + stringStderr_<%=cid%>.toString());
|
||||
<%}%>
|
||||
|
||||
|
||||
//execute the command
|
||||
sess_<%=cid%>.execCommand((command_<%=cid %>).toString());
|
||||
int nb_line_<%=cid %> = 0;
|
||||
//get the return info
|
||||
java.io.InputStream stdout_<%=cid%> = sess_<%=cid%>.getStdout();
|
||||
java.io.BufferedReader brout_<%=cid%>= new java.io.BufferedReader(new java.io.InputStreamReader(stdout_<%=cid%>));
|
||||
String line_out_<%=cid%> = "";
|
||||
StringBuilder stringStdout_<%=cid%> =new StringBuilder();
|
||||
while((line_out_<%=cid%> = brout_<%=cid%>.readLine()) != null) {
|
||||
String[] split_<%=cid %> = stringStdout_<%=cid%>.toString().split("\n");
|
||||
String line_out_<%=cid%> = "";
|
||||
for (int i_<%=cid %> = 0; i_<%=cid %> < split_<%=cid %>.length; i_<%=cid %>++) {
|
||||
line_out_<%=cid%> = split_<%=cid %>[i_<%=cid %>];
|
||||
if( line_out_<%=cid%>==null || line_out_<%=cid%>.isEmpty() ){
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -14,19 +14,6 @@ imports="
|
||||
%>
|
||||
|
||||
}
|
||||
brout_<%=cid%>.close();
|
||||
stdout_<%=cid%>.close();
|
||||
java.io.InputStream stderr_<%=cid%> = sess_<%=cid%>.getStderr();
|
||||
java.io.BufferedReader breer_<%=cid%>= new java.io.BufferedReader(new java.io.InputStreamReader(stderr_<%=cid%>));
|
||||
String line_err_<%=cid%> = "";
|
||||
StringBuilder stringStderr_<%=cid%> =new StringBuilder();
|
||||
while((line_err_<%=cid%> = breer_<%=cid%>.readLine()) != null) {
|
||||
stringStderr_<%=cid%>.append(line_err_<%=cid%> + "\n");
|
||||
}
|
||||
breer_<%=cid%>.close();
|
||||
stderr_<%=cid%>.close();
|
||||
/* Close this session */
|
||||
sess_<%=cid%>.close();
|
||||
<%
|
||||
if(!("true").equals(useExistingConn)){
|
||||
%>
|
||||
@@ -34,7 +21,7 @@ imports="
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Closing the connection to the server.");
|
||||
<%}%>
|
||||
conn_<%=cid%>.close();
|
||||
client_<%=cid%>.close();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connection to the server closed.");
|
||||
<%}%>
|
||||
|
||||
@@ -142,7 +142,8 @@
|
||||
|
||||
<CODEGENERATION>
|
||||
<IMPORTS>
|
||||
<IMPORT NAME="Java_SCP" MODULE="ganymed-ssh2-261.jar" MVN="mvn:ch.ethz.ganymed/ganymed-ssh2/261" REQUIRED="true"/>
|
||||
<IMPORT NAME="SSHD_CORE" MODULE="sshd-core-2.5.1.jar" MVN="mvn:org.apache.sshd/sshd-core/2.5.1" REQUIRED="true"/>
|
||||
<IMPORT NAME="SSHD_COMMON" MODULE="sshd-common-2.5.1.jar" MVN="mvn:org.apache.sshd/sshd-common/2.5.1" REQUIRED="true"/>
|
||||
</IMPORTS>
|
||||
</CODEGENERATION>
|
||||
|
||||
|
||||
@@ -10,6 +10,5 @@ imports="
|
||||
String cid = node.getUniqueName();
|
||||
%>
|
||||
nb_line_<%=cid %>++;
|
||||
stringStdout_<%=cid%>.append(line_out_<%=cid%> + "\n");
|
||||
globalMap.put("<%=cid %>_NB_LINE", nb_line_<%=cid %>);
|
||||
globalMap.put("<%=cid %>_CURRENT_LINE", line_out_<%=cid%>);
|
||||
@@ -1,162 +1,3 @@
|
||||
<%@ jet
|
||||
imports="
|
||||
org.talend.core.model.process.INode
|
||||
org.talend.core.model.process.ElementParameterParser
|
||||
org.talend.designer.codegen.config.CodeGeneratorArgument
|
||||
org.talend.core.model.process.IElementParameter
|
||||
org.talend.core.model.utils.NodeUtil
|
||||
"
|
||||
%>
|
||||
<%@ include file="../templates/Log4j/Log4jFileUtil.javajet"%>
|
||||
<%
|
||||
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
|
||||
INode node = (INode)codeGenArgument.getArgument();
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
String cid = node.getUniqueName();
|
||||
String host = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__HOST__"
|
||||
);
|
||||
String port = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__PORT__"
|
||||
);
|
||||
String user = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__USERNAME__"
|
||||
);
|
||||
String authMethod = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__AUTH_METHOD__"
|
||||
);
|
||||
String privatekey = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__PRIVATEKEY__"
|
||||
);
|
||||
String password = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__PASSWORD__"
|
||||
);
|
||||
String passphrase = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__PASSPHRASE__"
|
||||
);
|
||||
%>
|
||||
<%@ include file="../tSCPFileExists/tSCPFileExists_begin.javajet"%>
|
||||
int nb_file_<%=cid%> = 0;
|
||||
/* Create a connection instance */
|
||||
<%
|
||||
String useExistingConn = ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__");
|
||||
if(("true").equals(useExistingConn)){
|
||||
String connection = ElementParameterParser.getValue(node, "__CONNECTION__");
|
||||
String conn= "conn_" + connection;
|
||||
%>
|
||||
ch.ethz.ssh2.Connection conn_<%=cid %> = (ch.ethz.ssh2.Connection)globalMap.get("<%=conn %>");
|
||||
<%if(isLog4jEnabled){%>
|
||||
if(conn_<%=cid %>!=null) {
|
||||
log.info("<%=cid%> - Uses an existing connection. Connection hostname: " + conn_<%=cid %>.getHostname() + ". Connection port: " + conn_<%=cid %>.getPort() + ".");
|
||||
}
|
||||
<%}%>
|
||||
<%}else{%>
|
||||
String hostname_<%=cid%> = <%=host%>;
|
||||
String username_<%=cid%> = <%=user%>;
|
||||
<%
|
||||
if(("").equals(port)){
|
||||
%>
|
||||
ch.ethz.ssh2.Connection conn_<%=cid%> = new ch.ethz.ssh2.Connection(hostname_<%=cid%>);
|
||||
<%
|
||||
} else {
|
||||
%>
|
||||
ch.ethz.ssh2.Connection conn_<%=cid%> = new ch.ethz.ssh2.Connection(hostname_<%=cid%>,<%=port%>);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
/* Now connect */
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Attempt to connect to '" + hostname_<%=cid%> + "' with the username '" + <%=user%> + "'.");
|
||||
<%}%>
|
||||
conn_<%=cid%>.connect();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connect to '" + hostname_<%=cid%> + "' has succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
if (("PUBLICKEY").equals(authMethod)) {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using a public key");
|
||||
log.debug("<%=cid%> - Private key: '" + <%=privatekey%> + "'." );
|
||||
<%}%>
|
||||
java.io.File keyfile_<%=cid%> = new java.io.File(<%=privatekey%>);
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASSPHRASE__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
boolean isAuthenticated_<%=cid%> = conn_<%=cid%>.authenticateWithPublicKey(username_<%=cid%>, keyfile_<%=cid%>, decryptedPassword_<%=cid%>);
|
||||
if (isAuthenticated_<%=cid%> == false){
|
||||
throw new RuntimeException("Authentication failed.");
|
||||
}
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
if (("PASSWORD").equals(authMethod)) {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using a password");
|
||||
<%}%>
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
boolean isAuthenticated_<%=cid%> = conn_<%=cid%>.authenticateWithPassword(username_<%=cid%>, decryptedPassword_<%=cid%>);
|
||||
if (isAuthenticated_<%=cid%> == false){
|
||||
throw new RuntimeException("Authentication failed.");
|
||||
}
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
if (("KEYBOARDINTERACTIVE").equals(authMethod)) {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using an interactive action");
|
||||
<%}%>
|
||||
boolean isAuthenticated_<%=cid%> = conn_<%=cid%>.authenticateWithKeyboardInteractive(username_<%=cid%>,
|
||||
new ch.ethz.ssh2.InteractiveCallback() {
|
||||
public String[] replyToChallenge(String name,
|
||||
String instruction, int numPrompts,
|
||||
String[] prompt, boolean[] echo)
|
||||
throws java.lang.Exception {
|
||||
String[] reply = new String[numPrompts];
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
for (int i = 0; i < reply.length; i++) {
|
||||
reply[i] = decryptedPassword_<%=cid%>;
|
||||
}
|
||||
return reply;
|
||||
}
|
||||
}
|
||||
);
|
||||
if (isAuthenticated_<%=cid%> == false){
|
||||
throw new RuntimeException("Authentication failed.");
|
||||
}
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
}//if(useExistingConn)
|
||||
%>
|
||||
ch.ethz.ssh2.SCPClient scp_<%=cid%> = new ch.ethz.ssh2.SCPClient(conn_<%=cid%>);
|
||||
globalMap.put("<%=cid %>_STATUS", "");
|
||||
@@ -17,7 +17,7 @@ imports="
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Closing the connection to the server.");
|
||||
<%}%>
|
||||
conn_<%=cid%>.close();
|
||||
client_<%=cid%>.close();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connection to the server closed.");
|
||||
<%}%>
|
||||
|
||||
@@ -160,9 +160,13 @@
|
||||
|
||||
<CODEGENERATION>
|
||||
<IMPORTS>
|
||||
<IMPORT NAME="Java_SCP" MODULE="ganymed-ssh2-261.jar" MVN="mvn:ch.ethz.ganymed/ganymed-ssh2/261" REQUIRED="true"/>
|
||||
<IMPORT NAME="SSHD_CORE" MODULE="sshd-core-2.5.1.jar" MVN="mvn:org.apache.sshd/sshd-core/2.5.1" REQUIRED="true"/>
|
||||
<IMPORT NAME="SSHD_COMMON" MODULE="sshd-common-2.5.1.jar" MVN="mvn:org.apache.sshd/sshd-common/2.5.1" REQUIRED="true"/>
|
||||
<IMPORT NAME="SSHD_SCP" MODULE="sshd-scp-2.5.1.jar" MVN="mvn:org.apache.sshd/sshd-scp/2.5.1" REQUIRED="true"/>
|
||||
<IMPORT NAME="talend-scp-helper" MODULE="talend-scp-helper-1.0.jar" MVN="mvn:org.talend.components/talend-scp-helper/1.0" REQUIRED="true"/>
|
||||
</IMPORTS>
|
||||
</CODEGENERATION>
|
||||
|
||||
<RETURNS>
|
||||
<RETURN NAME="NB_FILE" TYPE="id_Integer" AVAILABILITY="AFTER"/>
|
||||
<RETURN NAME="STATUS" TYPE="id_String" AVAILABILITY="AFTER"/>
|
||||
|
||||
@@ -5,6 +5,7 @@ imports="
|
||||
org.talend.designer.codegen.config.CodeGeneratorArgument
|
||||
java.util.List
|
||||
java.util.Map
|
||||
org.talend.core.model.utils.NodeUtil
|
||||
"
|
||||
%>
|
||||
<%
|
||||
@@ -16,7 +17,40 @@ imports="
|
||||
List<Map<String, String>> filelist = (List<Map<String,String>>)ElementParameterParser.getObjectValue(node,"__FILELIST__");
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
boolean enforceUnixPath = ("true").equals(ElementParameterParser.getValue(node,"__FORCE_UNIX_PATH__"));
|
||||
String authMethod = ElementParameterParser.getValue(node,"__AUTH_METHOD__");
|
||||
String useExistingConn = ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__");
|
||||
if(("true").equals(useExistingConn)){
|
||||
String connection = ElementParameterParser.getValue(node, "__CONNECTION__");
|
||||
INode connectionNode = NodeUtil.getNodeByUniqueName(node.getProcess(), connection);
|
||||
authMethod = ElementParameterParser.getValue(connectionNode,"__AUTH_METHOD__");
|
||||
}
|
||||
%>
|
||||
/* open a session */
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Open up a session.");
|
||||
<%}%>
|
||||
|
||||
session_<%=cid%> = client_<%=cid%>.connect(username_<%=cid%>, hostname_<%=cid%>, port_<%=cid%>).verify().getClientSession();
|
||||
try {
|
||||
session_<%=cid%>.auth().verify();
|
||||
}catch (org.apache.sshd.common.SshException se_<%=cid%>){
|
||||
globalMap.put("<%=cid %>_EXIT_CODE",se_<%=cid%>.getDisconnectCode());
|
||||
<%
|
||||
if (("PUBLICKEY").equals(authMethod)) {
|
||||
%>
|
||||
java.nio.file.Files.write(privateKey_<%=cid%>,lines_<%=cid%>);
|
||||
<%}%>
|
||||
if(14 == se_<%=cid%>.getDisconnectCode()){
|
||||
throw new IllegalArgumentException("Authentication failed.");
|
||||
}else{
|
||||
throw se_<%=cid%>;
|
||||
}
|
||||
}
|
||||
org.apache.sshd.client.scp.ScpClientCreator instance_<%=cid%> = org.talend.components.talendscp.TalendScpClientCreator.INSTANCE;
|
||||
org.apache.sshd.client.scp.ScpClient scp_<%=cid%> = instance_<%=cid%>.createScpClient(session_<%=cid%>);
|
||||
|
||||
|
||||
String[] sourceFileNames_<%=cid%> = new String[]{
|
||||
<%
|
||||
for (Map<String, String> file : filelist) {
|
||||
@@ -36,10 +70,12 @@ imports="
|
||||
<%
|
||||
if (!enforceUnixPath) {
|
||||
%>
|
||||
sourceFile_<%=cid %> = sourceFile_<%=cid %>.replaceAll("\\\\","/");
|
||||
sourceFile_<%=cid %> = sourceFile_<%=cid %>.replaceAll("\\\\","/");
|
||||
<%
|
||||
}
|
||||
}
|
||||
%>
|
||||
|
||||
|
||||
int index_<%=cid %>=sourceFile_<%=cid %>.lastIndexOf("/");
|
||||
if(index_<%=cid %> >0){
|
||||
dir_<%=cid %> = new java.io.File(<%=localdir %>);
|
||||
@@ -51,16 +87,11 @@ imports="
|
||||
java.io.FileOutputStream out_<%=cid %> = null;
|
||||
|
||||
//copy action
|
||||
java.io.InputStream is_<%=cid%> = null;
|
||||
byte[] buffer_<%=cid%> = new byte[8192];
|
||||
int receive_<%=cid%> = -1;
|
||||
try {
|
||||
out_<%=cid %> = new java.io.FileOutputStream(file_<%=cid %>, true);
|
||||
is_<%=cid%> = scp_<%=cid %>.get(sourceFile_<%=cid %>);
|
||||
|
||||
while((receive_<%=cid%> = is_<%=cid%>.read(buffer_<%=cid%>))!=-1) {
|
||||
out_<%=cid %>.write(buffer_<%=cid%>, 0, receive_<%=cid%>);
|
||||
}
|
||||
scp_<%=cid%>.download("\""+sourceFile_<%=cid %>+"\"",out_<%=cid %>);
|
||||
|
||||
} catch(java.lang.Exception e_<%=cid%>) {
|
||||
if(out_<%=cid %> != null){
|
||||
out_<%=cid %>.close();
|
||||
@@ -75,9 +106,7 @@ imports="
|
||||
out_<%=cid %>.close();
|
||||
}
|
||||
|
||||
if(is_<%=cid%> != null) {
|
||||
is_<%=cid%>.close();
|
||||
}
|
||||
|
||||
}
|
||||
nb_file_<%=cid%> ++ ;
|
||||
<%if(isLog4jEnabled){%>
|
||||
@@ -129,16 +158,12 @@ imports="
|
||||
}
|
||||
java.io.FileOutputStream out_<%=cid %> = null;
|
||||
//copy action
|
||||
java.io.InputStream is_<%=cid%> = null;
|
||||
byte[] buffer_<%=cid%> = new byte[8192];
|
||||
int receive_<%=cid%> = -1;
|
||||
try {
|
||||
out_<%=cid %> = new java.io.FileOutputStream(file_<%=cid %>, false);
|
||||
is_<%=cid%> = scp_<%=cid %>.get(sourceFile_<%=cid %>);
|
||||
|
||||
while((receive_<%=cid%> = is_<%=cid%>.read(buffer_<%=cid%>))!=-1) {
|
||||
out_<%=cid %>.write(buffer_<%=cid%>, 0, receive_<%=cid%>);
|
||||
}
|
||||
scp_<%=cid%>.download("\""+sourceFile_<%=cid %>+"\"",out_<%=cid %>);
|
||||
|
||||
} catch(java.lang.Exception e_<%=cid%>) {
|
||||
if(out_<%=cid %> != null){
|
||||
out_<%=cid %>.close();
|
||||
@@ -151,9 +176,6 @@ imports="
|
||||
} finally {
|
||||
if(out_<%=cid %> != null){
|
||||
out_<%=cid %>.close();
|
||||
}
|
||||
if(is_<%=cid%> != null) {
|
||||
is_<%=cid%>.close();
|
||||
}
|
||||
}
|
||||
nb_file_<%=cid%> ++ ;
|
||||
@@ -182,5 +204,7 @@ imports="
|
||||
%>
|
||||
}catch(java.lang.Exception e_<%=cid%>){
|
||||
globalMap.put("<%=cid %>_STATUS", "File get fail.");
|
||||
globalMap.put("<%=cid %>_NB_FILE",nb_file_<%=cid%>);
|
||||
globalMap.put("<%=cid %>_ERROR_MESSAGE",e_<%=cid%>.getMessage());
|
||||
throw e_<%=cid%>;
|
||||
}
|
||||
|
||||
@@ -1,170 +1,6 @@
|
||||
<%@ jet
|
||||
imports="
|
||||
org.talend.core.model.process.INode
|
||||
org.talend.core.model.process.ElementParameterParser
|
||||
org.talend.designer.codegen.config.CodeGeneratorArgument
|
||||
java.util.List
|
||||
java.util.Map
|
||||
org.talend.core.model.process.IElementParameter
|
||||
org.talend.core.model.utils.NodeUtil
|
||||
"
|
||||
%>
|
||||
<%@ include file="../templates/Log4j/Log4jFileUtil.javajet"%>
|
||||
<%
|
||||
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
|
||||
INode node = (INode)codeGenArgument.getArgument();
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
String cid = node.getUniqueName();
|
||||
List<Map<String, String>> filelist =(List<Map<String,String>>)ElementParameterParser.getObjectValue(node,"__FILELIST__");
|
||||
%>
|
||||
|
||||
<%@ include file="../tSCPFileExists/tSCPFileExists_begin.javajet"%>
|
||||
int nb_file_<%=cid%> = 0;
|
||||
globalMap.put("<%=cid %>_STATUS", "");
|
||||
/* Create a connection instance */
|
||||
<%
|
||||
String useExistingConn = ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__");
|
||||
if(("true").equals(useExistingConn)){
|
||||
String connection = ElementParameterParser.getValue(node, "__CONNECTION__");
|
||||
String conn= "conn_" + connection;
|
||||
%>
|
||||
ch.ethz.ssh2.Connection conn_<%=cid %> = (ch.ethz.ssh2.Connection)globalMap.get("<%=conn %>");
|
||||
<%if(isLog4jEnabled){%>
|
||||
if(conn_<%=cid %>!=null) {
|
||||
log.info("<%=cid%> - Uses an existing connection. Connection hostname: " + conn_<%=cid %>.getHostname() + ". Connection port: " + conn_<%=cid %>.getPort() + ".");
|
||||
}
|
||||
<%}%>
|
||||
|
||||
<%}else{%>
|
||||
<%
|
||||
String host = ElementParameterParser.getValue(node,"__HOST__");
|
||||
String port = ElementParameterParser.getValue(node,"__PORT__");
|
||||
String user = ElementParameterParser.getValue(node,"__USERNAME__");
|
||||
String authMethod = ElementParameterParser.getValue(node,"__AUTH_METHOD__");
|
||||
String privatekey = ElementParameterParser.getValue(node,"__PRIVATEKEY__");
|
||||
String password = ElementParameterParser.getValue(node,"__PASSWORD__");
|
||||
String passphrase = ElementParameterParser.getValue(node,"__PASSPHRASE__");
|
||||
%>
|
||||
String hostname_<%=cid%> = <%=host%>;
|
||||
String username_<%=cid%> = <%=user%>;
|
||||
<%
|
||||
if(("").equals(port)){
|
||||
%>
|
||||
ch.ethz.ssh2.Connection conn_<%=cid%> = new ch.ethz.ssh2.Connection(hostname_<%=cid%>);
|
||||
<%
|
||||
} else {
|
||||
%>
|
||||
ch.ethz.ssh2.Connection conn_<%=cid%> = new ch.ethz.ssh2.Connection(hostname_<%=cid%>,<%=port%>);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
/* Now connect */
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Attempt to connect to '" + hostname_<%=cid%> + "' with the username '" + <%=user%> + "'.");
|
||||
<%}%>
|
||||
conn_<%=cid%>.connect();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connect to '" + hostname_<%=cid%> + "' has succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
if (("PUBLICKEY").equals(authMethod)) {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using a public key");
|
||||
log.debug("<%=cid%> - Private key: '" + <%=privatekey%> + "'." );
|
||||
<%}%>
|
||||
java.io.File keyfile_<%=cid%> = new java.io.File(<%=privatekey%>);
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASSPHRASE__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
boolean isAuthenticated_<%=cid%> = conn_<%=cid%>.authenticateWithPublicKey(username_<%=cid%>, keyfile_<%=cid%>, decryptedPassword_<%=cid%>);
|
||||
if (isAuthenticated_<%=cid%> == false){
|
||||
throw new RuntimeException("Authentication failed.");
|
||||
}
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
if (("PASSWORD").equals(authMethod)) {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using a password");
|
||||
<%}%>
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
boolean isAuthenticated_<%=cid%> = conn_<%=cid%>.authenticateWithPassword(username_<%=cid%>, decryptedPassword_<%=cid%>);
|
||||
if (isAuthenticated_<%=cid%> == false){
|
||||
throw new RuntimeException("Authentication failed.");
|
||||
}
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
if (("KEYBOARDINTERACTIVE").equals(authMethod)) {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using an interactive action");
|
||||
<%}%>
|
||||
boolean isAuthenticated_<%=cid%> = conn_<%=cid%>.authenticateWithKeyboardInteractive(username_<%=cid%>,
|
||||
new ch.ethz.ssh2.InteractiveCallback() {
|
||||
|
||||
public String[] replyToChallenge(String name,
|
||||
String instruction, int numPrompts,
|
||||
String[] prompt, boolean[] echo)
|
||||
throws java.lang.Exception {
|
||||
String[] reply = new String[numPrompts];
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
for (int i = 0; i < reply.length; i++) {
|
||||
reply[i] = decryptedPassword_<%=cid%>;
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
}
|
||||
);
|
||||
if (isAuthenticated_<%=cid%> == false){
|
||||
throw new RuntimeException("Authentication failed.");
|
||||
}
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
}//if(isExistConnection)
|
||||
%>
|
||||
ch.ethz.ssh2.SCPClient scp_<%=cid%> = new ch.ethz.ssh2.SCPClient(conn_<%=cid%>);
|
||||
|
||||
java.util.List<String> sourceList_<%=cid %> = new java.util.ArrayList<String>();
|
||||
<%
|
||||
for (Map<String, String> file : filelist) {
|
||||
%>
|
||||
if((new java.io.File(<%=file.get("SOURCE") %>).exists())
|
||||
&& (new java.io.File(<%=file.get("SOURCE") %>).isFile())){
|
||||
sourceList_<%=cid %>.add(<%=file.get("SOURCE") %>);
|
||||
}else{
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.warn("<%=cid%> - "+<%= file.get("SOURCE") %>+" doesn't exist or it isn't a file.");
|
||||
<%}%>
|
||||
}
|
||||
<%
|
||||
}
|
||||
%>
|
||||
String[] sourceFileNames_<%=cid%> = new String[sourceList_<%=cid %>.size()];
|
||||
for(int i_<%=cid %> = 0;i_<%=cid %> < sourceList_<%=cid %>.size(); i_<%=cid %>++){
|
||||
sourceFileNames_<%=cid%>[i_<%=cid %>] = sourceList_<%=cid %>.get(i_<%=cid %>);
|
||||
}
|
||||
java.util.Set<java.nio.file.Path> uploadedSet_<%=cid %> = new java.util.HashSet<>();
|
||||
|
||||
|
||||
@@ -17,13 +17,13 @@ imports="
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Closing the connection to the server.");
|
||||
<%}%>
|
||||
conn_<%=cid%>.close();
|
||||
client_<%=cid%>.close();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connection to the server closed.");
|
||||
<%}%>
|
||||
<%}%>
|
||||
globalMap.put("<%=cid %>_NB_FILE",nb_file_<%=cid%>);
|
||||
globalMap.put("<%=cid %>_NB_FILE",uploadedSet_<%=cid %>.size());
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Uploaded files count: " + nb_file_<%=cid%> + ".");
|
||||
log.info("<%=cid%> - Uploaded files count: " + uploadedSet_<%=cid %>.size() + ".");
|
||||
<%}%>
|
||||
|
||||
@@ -138,9 +138,13 @@
|
||||
|
||||
<CODEGENERATION>
|
||||
<IMPORTS>
|
||||
<IMPORT NAME="Java_SCP" MODULE="ganymed-ssh2-261.jar" MVN="mvn:ch.ethz.ganymed/ganymed-ssh2/261" REQUIRED="true"/>
|
||||
<IMPORT NAME="SSHD_CORE" MODULE="sshd-core-2.5.1.jar" MVN="mvn:org.apache.sshd/sshd-core/2.5.1" REQUIRED="true"/>
|
||||
<IMPORT NAME="SSHD_COMMON" MODULE="sshd-common-2.5.1.jar" MVN="mvn:org.apache.sshd/sshd-common/2.5.1" REQUIRED="true"/>
|
||||
<IMPORT NAME="SSHD_SCP" MODULE="sshd-scp-2.5.1.jar" MVN="mvn:org.apache.sshd/sshd-scp/2.5.1" REQUIRED="true"/>
|
||||
<IMPORT NAME="talend-scp-helper" MODULE="talend-scp-helper-1.0.jar" MVN="mvn:org.talend.components/talend-scp-helper/1.0" REQUIRED="true"/>
|
||||
</IMPORTS>
|
||||
</CODEGENERATION>
|
||||
|
||||
<RETURNS>
|
||||
<RETURN NAME="STATUS" TYPE="id_String" AVAILABILITY="AFTER"/>
|
||||
<RETURN NAME="NB_FILE" TYPE="id_Integer" AVAILABILITY="AFTER"/>
|
||||
|
||||
@@ -1,57 +1,94 @@
|
||||
<%@ jet
|
||||
imports="
|
||||
org.talend.core.model.process.INode
|
||||
org.talend.core.model.process.INode
|
||||
org.talend.core.model.process.ElementParameterParser
|
||||
org.talend.designer.codegen.config.CodeGeneratorArgument
|
||||
java.util.List
|
||||
java.util.Map
|
||||
org.talend.core.model.utils.NodeUtil
|
||||
"
|
||||
%>
|
||||
|
||||
<%
|
||||
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
|
||||
INode node = (INode)codeGenArgument.getArgument();
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
String cid = node.getUniqueName();
|
||||
String cid = node.getUniqueName();
|
||||
String remotedir = ElementParameterParser.getValue(node, "__REMOTEDIR__");
|
||||
List<Map<String, String>> filelist =(List<Map<String,String>>)ElementParameterParser.getObjectValue(node,"__FILELIST__");
|
||||
String authMethod = ElementParameterParser.getValue(node,"__AUTH_METHOD__");
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
String useExistingConn = ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__");
|
||||
if(("true").equals(useExistingConn)){
|
||||
String connection = ElementParameterParser.getValue(node, "__CONNECTION__");
|
||||
INode connectionNode = NodeUtil.getNodeByUniqueName(node.getProcess(), connection);
|
||||
authMethod = ElementParameterParser.getValue(connectionNode,"__AUTH_METHOD__");
|
||||
}
|
||||
%>
|
||||
try{
|
||||
if(sourceFileNames_<%=cid%>!=null && sourceFileNames_<%=cid%>.length!=0){
|
||||
for (int i_<%=cid%> = 0; i_<%=cid%> < sourceFileNames_<%=cid%>.length; i_<%=cid%>++) {
|
||||
java.io.File file_<%=cid%> = new java.io.File(sourceFileNames_<%=cid%>[i_<%=cid%>]);
|
||||
long sendSize_<%=cid%> = file_<%=cid%>.length();
|
||||
String remoteName_<%=cid%> = file_<%=cid%>.getName();
|
||||
java.io.OutputStream out_<%=cid%> = null;
|
||||
java.io.InputStream is_<%=cid%> = null;
|
||||
byte[] buffer_<%=cid%> = new byte[8192];
|
||||
int receive_<%=cid%> = -1;
|
||||
try {
|
||||
out_<%=cid%> = scp_<%=cid%>.put(remoteName_<%=cid%>, sendSize_<%=cid%>, <%=remotedir %>, "0644");
|
||||
is_<%=cid%> = new java.io.FileInputStream(file_<%=cid%>);
|
||||
|
||||
while((receive_<%=cid%> = is_<%=cid%>.read(buffer_<%=cid%>))!=-1) {
|
||||
out_<%=cid %>.write(buffer_<%=cid%>, 0, receive_<%=cid%>);
|
||||
}
|
||||
} finally {
|
||||
if(out_<%=cid %> != null){
|
||||
out_<%=cid %>.close();
|
||||
}
|
||||
|
||||
if(is_<%=cid%> != null) {
|
||||
is_<%=cid%>.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - Uploaded file '" + sourceList_<%=cid %>.toString() + "' to remote directory '" + <%=remotedir %>+ "' successfully.");
|
||||
<%}%>
|
||||
nb_file_<%=cid %> = sourceFileNames_<%=cid %>.length;
|
||||
globalMap.put("<%=cid %>_STATUS", "File put OK.");
|
||||
}else{
|
||||
globalMap.put("<%=cid %>_STATUS", "No file transfered.");
|
||||
java.util.List<java.nio.file.Path> sourceList_<%=cid %> = new java.util.ArrayList<java.nio.file.Path>();
|
||||
|
||||
java.io.File[] files_<%=cid%> = new java.io.File[]{
|
||||
|
||||
<%
|
||||
for (Map<String, String> file : filelist) {
|
||||
%>
|
||||
new java.io.File(<%=file.get("SOURCE") %>),
|
||||
<%
|
||||
}
|
||||
}catch(java.lang.Exception e){
|
||||
e.printStackTrace();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.error(e.getMessage());
|
||||
<%}%>
|
||||
globalMap.put("<%=cid %>_STATUS", "File put fail.");
|
||||
}
|
||||
%>
|
||||
};
|
||||
for (java.io.File file_<%=cid%>:files_<%=cid%>) {
|
||||
if((file_<%=cid%>.exists())
|
||||
&& (file_<%=cid%>.isFile()) && (!uploadedSet_<%=cid %>.contains(file_<%=cid%>.toPath()))){
|
||||
sourceList_<%=cid %>.add(file_<%=cid%>.toPath());
|
||||
}else{
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.warn("<%=cid%> - "+file_<%=cid%>.getPath()+" doesn't exist or it isn't a file.");
|
||||
<%}%>
|
||||
}
|
||||
}
|
||||
|
||||
java.nio.file.Path[] sourceFileNames_<%=cid%> = sourceList_<%=cid %>.toArray(new java.nio.file.Path[0]);
|
||||
|
||||
|
||||
/* open a session */
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Open up a session.");
|
||||
<%}%>
|
||||
|
||||
session_<%=cid%> = client_<%=cid%>.connect(username_<%=cid%>, hostname_<%=cid%>, port_<%=cid%>).verify().getClientSession();
|
||||
try {
|
||||
session_<%=cid%>.auth().verify();
|
||||
}catch (org.apache.sshd.common.SshException se_<%=cid%>){
|
||||
globalMap.put("<%=cid %>_EXIT_CODE",se_<%=cid%>.getDisconnectCode());
|
||||
<%
|
||||
if (("PUBLICKEY").equals(authMethod)) {
|
||||
%>
|
||||
java.nio.file.Files.write(privateKey_<%=cid%>,lines_<%=cid%>);
|
||||
<%}%>
|
||||
if(14 == se_<%=cid%>.getDisconnectCode()){
|
||||
throw new IllegalArgumentException("Authentication failed.");
|
||||
}else{
|
||||
throw se_<%=cid%>;
|
||||
}
|
||||
}
|
||||
org.apache.sshd.client.scp.ScpClientCreator instance_<%=cid%> = org.talend.components.talendscp.TalendScpClientCreator.INSTANCE;
|
||||
org.apache.sshd.client.scp.ScpClient scp_<%=cid%> = instance_<%=cid%>.createScpClient(session_<%=cid%>);
|
||||
try{
|
||||
if(sourceFileNames_<%=cid%>.length > 0){
|
||||
String remotedir_<%=cid%> = String.valueOf(<%=remotedir %>);
|
||||
remotedir_<%=cid%> = remotedir_<%=cid%>.endsWith("/")?("\""+remotedir_<%=cid%>+"\""):("\""+remotedir_<%=cid%>+"/\"");
|
||||
scp_<%=cid%>.upload(sourceFileNames_<%=cid%>,remotedir_<%=cid%>);
|
||||
uploadedSet_<%=cid %>.addAll(java.util.Arrays.asList(sourceFileNames_<%=cid%>));
|
||||
globalMap.put("<%=cid %>_STATUS", "File put OK.");
|
||||
}else{
|
||||
globalMap.put("<%=cid %>_STATUS", "No file transfered.");
|
||||
}
|
||||
}catch(java.lang.Exception e){
|
||||
e.printStackTrace();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.error(e.getMessage());
|
||||
<%}%>
|
||||
globalMap.put("<%=cid %>_STATUS", "File put fail.");
|
||||
}
|
||||
session_<%=cid%>.close();
|
||||
@@ -1,164 +1 @@
|
||||
<%@ jet
|
||||
imports="
|
||||
org.talend.core.model.process.INode
|
||||
org.talend.core.model.process.ElementParameterParser
|
||||
org.talend.designer.codegen.config.CodeGeneratorArgument
|
||||
org.talend.core.model.process.IElementParameter
|
||||
org.talend.core.model.utils.NodeUtil
|
||||
"
|
||||
%>
|
||||
<%@ include file="../templates/Log4j/Log4jFileUtil.javajet"%>
|
||||
<%
|
||||
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
|
||||
INode node = (INode)codeGenArgument.getArgument();
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
String cid = node.getUniqueName();
|
||||
String host = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__HOST__"
|
||||
);
|
||||
String port = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__PORT__"
|
||||
);
|
||||
String user = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__USERNAME__"
|
||||
);
|
||||
String authMethod = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__AUTH_METHOD__"
|
||||
);
|
||||
String privatekey = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__PRIVATEKEY__"
|
||||
);
|
||||
String password = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__PASSWORD__"
|
||||
);
|
||||
String passphrase = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__PASSPHRASE__"
|
||||
);
|
||||
%>
|
||||
/* Create a connection instance */
|
||||
<%
|
||||
String useExistingConn = ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__");
|
||||
if(("true").equals(useExistingConn)){
|
||||
String connection = ElementParameterParser.getValue(node, "__CONNECTION__");
|
||||
String conn= "conn_" + connection;
|
||||
%>
|
||||
ch.ethz.ssh2.Connection conn_<%=cid %> = (ch.ethz.ssh2.Connection)globalMap.get("<%=conn %>");
|
||||
<%if(isLog4jEnabled){%>
|
||||
if(conn_<%=cid %>!=null) {
|
||||
log.info("<%=cid%> - Uses an existing connection. Connection hostname: " + conn_<%=cid %>.getHostname() + ". Connection port: " + conn_<%=cid %>.getPort() + ".");
|
||||
}
|
||||
<%}%>
|
||||
<%}else{%>
|
||||
|
||||
String hostname_<%=cid%> = <%=host%>;
|
||||
String username_<%=cid%> = <%=user%>;
|
||||
<%
|
||||
if(("").equals(port)){
|
||||
%>
|
||||
ch.ethz.ssh2.Connection conn_<%=cid%> = new ch.ethz.ssh2.Connection(hostname_<%=cid%>);
|
||||
<%
|
||||
} else {
|
||||
%>
|
||||
ch.ethz.ssh2.Connection conn_<%=cid%> = new ch.ethz.ssh2.Connection(hostname_<%=cid%>,<%=port%>);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
/* Now connect */
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Attempt to connect to '" + hostname_<%=cid%> + "' with the username '" + username_<%=cid%> + "'.");
|
||||
<%}%>
|
||||
conn_<%=cid%>.connect();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connect to '" + hostname_<%=cid%> + "' has succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
if (("PUBLICKEY").equals(authMethod)) {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using a public key");
|
||||
log.debug("<%=cid%> - Private key: '" + <%=privatekey%> + "'." );
|
||||
<%}%>
|
||||
java.io.File keyfile_<%=cid%> = new java.io.File(<%=privatekey%>);
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASSPHRASE__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
boolean isAuthenticated_<%=cid%> = conn_<%=cid%>.authenticateWithPublicKey(username_<%=cid%>, keyfile_<%=cid%>, decryptedPassword_<%=cid%>);
|
||||
if (isAuthenticated_<%=cid%> == false){
|
||||
throw new RuntimeException("Authentication failed.");
|
||||
}
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
if (("PASSWORD").equals(authMethod)) {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using a password");
|
||||
<%}%>
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
boolean isAuthenticated_<%=cid%> = conn_<%=cid%>.authenticateWithPassword(username_<%=cid%>, decryptedPassword_<%=cid%>);
|
||||
if (isAuthenticated_<%=cid%> == false){
|
||||
throw new RuntimeException("Authentication failed.");
|
||||
}
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
if (("KEYBOARDINTERACTIVE").equals(authMethod)) {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using an interactive action");
|
||||
<%}%>
|
||||
boolean isAuthenticated_<%=cid%> = conn_<%=cid%>.authenticateWithKeyboardInteractive(username_<%=cid%>,
|
||||
new ch.ethz.ssh2.InteractiveCallback() {
|
||||
|
||||
public String[] replyToChallenge(String name,
|
||||
String instruction, int numPrompts,
|
||||
String[] prompt, boolean[] echo)
|
||||
throws java.lang.Exception {
|
||||
String[] reply = new String[numPrompts];
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
for (int i = 0; i < reply.length; i++) {
|
||||
reply[i] = decryptedPassword_<%=cid%>;
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
}
|
||||
);
|
||||
if (isAuthenticated_<%=cid%> == false){
|
||||
throw new RuntimeException("Authentication failed.");
|
||||
}
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
|
||||
}//if(useExistingConn)
|
||||
%>
|
||||
<%@ include file="../tSCPFileExists/tSCPFileExists_begin.javajet"%>
|
||||
@@ -18,7 +18,7 @@ imports="
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Closing the connection to the server.");
|
||||
<%}%>
|
||||
conn_<%=cid%>.close();
|
||||
client_<%=cid%>.close();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connection to the server closed.");
|
||||
<%}%>
|
||||
|
||||
@@ -140,7 +140,8 @@
|
||||
|
||||
<CODEGENERATION>
|
||||
<IMPORTS>
|
||||
<IMPORT NAME="Java_SCP" MODULE="ganymed-ssh2-261.jar" MVN="mvn:ch.ethz.ganymed/ganymed-ssh2/261" REQUIRED="true"/>
|
||||
<IMPORT NAME="SSHD_CORE" MODULE="sshd-core-2.5.1.jar" MVN="mvn:org.apache.sshd/sshd-core/2.5.1" REQUIRED="true"/>
|
||||
<IMPORT NAME="SSHD_COMMON" MODULE="sshd-common-2.5.1.jar" MVN="mvn:org.apache.sshd/sshd-common/2.5.1" REQUIRED="true"/>
|
||||
</IMPORTS>
|
||||
</CODEGENERATION>
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ imports="
|
||||
org.talend.core.model.process.INode
|
||||
org.talend.core.model.process.ElementParameterParser
|
||||
org.talend.designer.codegen.config.CodeGeneratorArgument
|
||||
org.talend.core.model.utils.NodeUtil
|
||||
"
|
||||
%>
|
||||
|
||||
@@ -12,32 +13,69 @@ imports="
|
||||
String cid = node.getUniqueName();
|
||||
String fromName = ElementParameterParser.getValue(node, "__FROMNAME__");
|
||||
String toName = ElementParameterParser.getValue(node,"__TONAME__");
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
String fileExists = ElementParameterParser.getValue(node,"__EXISTFILE__");
|
||||
String authMethod = ElementParameterParser.getValue(node,"__AUTH_METHOD__");
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
String useExistingConn = ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__");
|
||||
if(("true").equals(useExistingConn)){
|
||||
String connection = ElementParameterParser.getValue(node, "__CONNECTION__");
|
||||
INode connectionNode = NodeUtil.getNodeByUniqueName(node.getProcess(), connection);
|
||||
authMethod = ElementParameterParser.getValue(connectionNode,"__AUTH_METHOD__");
|
||||
}
|
||||
%>
|
||||
|
||||
//initial the command
|
||||
StringBuilder command_<%=cid %> = new StringBuilder();
|
||||
command_<%=cid %>.append("mv \"").append(<%=fromName%>).append("\" \"").append(<%=toName%>).append("\"");
|
||||
/* Create a session */
|
||||
ch.ethz.ssh2.Session sess_<%=cid%> = conn_<%=cid%>.openSession();
|
||||
|
||||
//execute the command
|
||||
sess_<%=cid%>.execCommand((command_<%=cid %>).toString());
|
||||
|
||||
//get the return info
|
||||
|
||||
java.io.InputStream stderr_<%=cid%> = sess_<%=cid%>.getStderr();
|
||||
java.io.BufferedReader breer_<%=cid%>= new java.io.BufferedReader(new java.io.InputStreamReader(stderr_<%=cid%>));
|
||||
String line_err_<%=cid%> = "";
|
||||
StringBuilder stringStderr_<%=cid%> =new StringBuilder();
|
||||
while((line_err_<%=cid%> = breer_<%=cid%>.readLine()) != null) {
|
||||
stringStderr_<%=cid%>.append(line_err_<%=cid%> + "\n");
|
||||
}
|
||||
breer_<%=cid%>.close();
|
||||
stderr_<%=cid%>.close();
|
||||
|
||||
/* Close this session */
|
||||
sess_<%=cid%>.close();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Open up a session.");
|
||||
log.debug("<%=cid%> - execute the command: " + command_<%=cid %>.toString());
|
||||
<%}%>
|
||||
|
||||
session_<%=cid%> = client_<%=cid%>.connect(username_<%=cid%>, hostname_<%=cid%>, port_<%=cid%>).verify().getClientSession();
|
||||
try {
|
||||
session_<%=cid%>.auth().verify();
|
||||
}catch (org.apache.sshd.common.SshException se_<%=cid%>){
|
||||
globalMap.put("<%=cid %>_EXIT_CODE",se_<%=cid%>.getDisconnectCode());
|
||||
<%
|
||||
if (("PUBLICKEY").equals(authMethod)) {
|
||||
%>
|
||||
java.nio.file.Files.write(privateKey_<%=cid%>,lines_<%=cid%>);
|
||||
<%}%>
|
||||
if(14 == se_<%=cid%>.getDisconnectCode()){
|
||||
throw new IllegalArgumentException("Authentication failed.");
|
||||
}else{
|
||||
throw se_<%=cid%>;
|
||||
}
|
||||
}
|
||||
org.apache.sshd.client.channel.ClientChannel channel_<%=cid %> = session_<%=cid %>.createExecChannel((command_<%=cid %>).toString());
|
||||
java.io.ByteArrayOutputStream stdout_<%=cid %> = new java.io.ByteArrayOutputStream();
|
||||
java.io.ByteArrayOutputStream stderr_<%=cid %> = new java.io.ByteArrayOutputStream();
|
||||
channel_<%=cid%>.setOut(stdout_<%=cid %>);
|
||||
channel_<%=cid%>.setErr(stderr_<%=cid %>);
|
||||
channel_<%=cid%>.open();
|
||||
java.util.Set<org.apache.sshd.client.channel.ClientChannelEvent> clientChannelEvents_<%=cid %> =
|
||||
channel_<%=cid%>.waitFor(java.util.EnumSet.of(
|
||||
org.apache.sshd.client.channel.ClientChannelEvent.CLOSED,org.apache.sshd.client.channel.ClientChannelEvent.EXIT_STATUS), 0L);
|
||||
exit_code_<%=cid%> = channel_<%=cid%>.getExitStatus();
|
||||
channel_<%=cid%>.close();
|
||||
session_<%=cid%>.close();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("Channel Events: "+ java.util.Arrays.toString(clientChannelEvents_<%=cid %>.toArray()));
|
||||
<%}%>
|
||||
stringStdout_<%=cid%>.append(stdout_<%=cid%>.toString());
|
||||
stringStderr_<%=cid%>.append(stderr_<%=cid%>.toString());
|
||||
|
||||
if(stringStdout_<%=cid%>.length() >0 && stringStdout_<%=cid%>.charAt(stringStdout_<%=cid%>.length()-1) == '\n'){
|
||||
stringStdout_<%=cid%>.deleteCharAt(stringStdout_<%=cid%>.length()-1);
|
||||
}
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - Command line standard result: " + stringStdout_<%=cid%>.toString());
|
||||
log.debug("<%=cid%> - Command line error result: " + stringStderr_<%=cid%>.toString());
|
||||
<%}%>
|
||||
|
||||
if(("").equals(stringStderr_<%=cid %>.toString()) || (stringStderr_<%=cid %>.toString() == null)){
|
||||
<%if(isLog4jEnabled){%>
|
||||
|
||||
@@ -1,187 +1,4 @@
|
||||
<%@ jet
|
||||
imports="
|
||||
org.talend.core.model.process.INode
|
||||
org.talend.core.model.process.ElementParameterParser
|
||||
org.talend.designer.codegen.config.CodeGeneratorArgument
|
||||
java.util.List
|
||||
java.util.Map
|
||||
org.talend.core.model.process.IElementParameter
|
||||
org.talend.core.model.utils.NodeUtil
|
||||
"
|
||||
%>
|
||||
<%@ include file="../templates/Log4j/Log4jFileUtil.javajet"%>
|
||||
<%
|
||||
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
|
||||
INode node = (INode)codeGenArgument.getArgument();
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
String cid = node.getUniqueName();
|
||||
String host = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__HOST__"
|
||||
);
|
||||
String port = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__PORT__"
|
||||
);
|
||||
String user = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__USERNAME__"
|
||||
);
|
||||
String authMethod = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__AUTH_METHOD__"
|
||||
);
|
||||
String privatekey = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__PRIVATEKEY__"
|
||||
);
|
||||
String password = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__PASSWORD__"
|
||||
);
|
||||
String passphrase = ElementParameterParser.getValue(
|
||||
node,
|
||||
"__PASSPHRASE__"
|
||||
);
|
||||
List<Map<String, String>> filelist =
|
||||
(List<Map<String,String>>)ElementParameterParser.getObjectValue(
|
||||
node,
|
||||
"__FILELIST__"
|
||||
);
|
||||
%>
|
||||
<%@ include file="../tSCPFileExists/tSCPFileExists_begin.javajet"%>
|
||||
int nb_file_<%=cid%> = 0;
|
||||
globalMap.put("<%=cid %>_STATUS", "");
|
||||
/* Create a connection instance */
|
||||
<%
|
||||
String useExistingConn = ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__");
|
||||
if(("true").equals(useExistingConn)){
|
||||
String connection = ElementParameterParser.getValue(node, "__CONNECTION__");
|
||||
String conn= "conn_" + connection;
|
||||
%>
|
||||
ch.ethz.ssh2.Connection conn_<%=cid %> = (ch.ethz.ssh2.Connection)globalMap.get("<%=conn %>");
|
||||
<%if(isLog4jEnabled){%>
|
||||
if(conn_<%=cid %>!=null) {
|
||||
log.info("<%=cid%> - Uses an existing connection. Connection hostname: " + conn_<%=cid %>.getHostname() + ". Connection port: " + conn_<%=cid %>.getPort() + ".");
|
||||
}
|
||||
<%}%>
|
||||
<%}else{%>
|
||||
String hostname_<%=cid%> = <%=host%>;
|
||||
String username_<%=cid%> = <%=user%>;
|
||||
<%
|
||||
if(("").equals(port)){
|
||||
%>
|
||||
ch.ethz.ssh2.Connection conn_<%=cid%> = new ch.ethz.ssh2.Connection(hostname_<%=cid%>);
|
||||
<%
|
||||
} else {
|
||||
%>
|
||||
ch.ethz.ssh2.Connection conn_<%=cid%> = new ch.ethz.ssh2.Connection(hostname_<%=cid%>,<%=port%>);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
/* Now connect */
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Attempt to connect to '" + hostname_<%=cid%> + "' with the username '" + username_<%=cid%> + "'.");
|
||||
<%}%>
|
||||
conn_<%=cid%>.connect();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connect to '" + hostname_<%=cid%> + "' has succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
if (("PUBLICKEY").equals(authMethod)) {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using a public key");
|
||||
log.debug("<%=cid%> - Private key: '" + <%=privatekey%> + "'." );
|
||||
<%}%>
|
||||
java.io.File keyfile_<%=cid%> = new java.io.File(<%=privatekey%>);
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASSPHRASE__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
boolean isAuthenticated_<%=cid%> = conn_<%=cid%>.authenticateWithPublicKey(username_<%=cid%>, keyfile_<%=cid%>, decryptedPassword_<%=cid%>);
|
||||
if (isAuthenticated_<%=cid%> == false){
|
||||
throw new RuntimeException("Authentication failed.");
|
||||
}
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
if (("PASSWORD").equals(authMethod)) {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using a password");
|
||||
<%}%>
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
boolean isAuthenticated_<%=cid%> = conn_<%=cid%>.authenticateWithPassword(username_<%=cid%>, decryptedPassword_<%=cid%>);
|
||||
if (isAuthenticated_<%=cid%> == false){
|
||||
throw new RuntimeException("Authentication failed.");
|
||||
}
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
if (("KEYBOARDINTERACTIVE").equals(authMethod)) {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using an interactive action");
|
||||
<%}%>
|
||||
boolean isAuthenticated_<%=cid%> = conn_<%=cid%>.authenticateWithKeyboardInteractive(username_<%=cid%>,
|
||||
new ch.ethz.ssh2.InteractiveCallback() {
|
||||
|
||||
public String[] replyToChallenge(String name,
|
||||
String instruction, int numPrompts,
|
||||
String[] prompt, boolean[] echo)
|
||||
throws java.lang.Exception {
|
||||
String[] reply = new String[numPrompts];
|
||||
|
||||
<%
|
||||
String passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
for (int i = 0; i < reply.length; i++) {
|
||||
reply[i] = decryptedPassword_<%=cid%>;
|
||||
}
|
||||
|
||||
return reply;
|
||||
}
|
||||
}
|
||||
);
|
||||
if (isAuthenticated_<%=cid%> == false){
|
||||
throw new RuntimeException("Authentication failed.");
|
||||
}
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
}//if(useExistingConn)
|
||||
%>
|
||||
|
||||
ch.ethz.ssh2.SCPClient scp_<%=cid%> = new ch.ethz.ssh2.SCPClient(conn_<%=cid%>);
|
||||
|
||||
String[] destFileNames_<%=cid%> = new String[]{
|
||||
<%
|
||||
for (Map<String, String> file : filelist) {
|
||||
%>
|
||||
<%=file.get("DESTINATION")%>,
|
||||
<%
|
||||
}
|
||||
%>
|
||||
};
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Truncating file from the server.");
|
||||
<%}%>
|
||||
for(String destFile_<%=cid %> : destFileNames_<%=cid%>){
|
||||
java.util.Set<java.nio.file.Path> uploadedSet_<%=cid %> = new java.util.HashSet<>();
|
||||
@@ -12,7 +12,7 @@ imports="
|
||||
String useExistingConn = ElementParameterParser.getValue(node,"__USE_EXISTING_CONNECTION__");
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
%>
|
||||
}
|
||||
|
||||
<%
|
||||
if(!("true").equals(useExistingConn)){
|
||||
%>
|
||||
@@ -20,7 +20,7 @@ imports="
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Closing the connection to the server.");
|
||||
<%}%>
|
||||
conn_<%=cid%>.close();
|
||||
client_<%=cid%>.close();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connection to the server closed.");
|
||||
<%}%>
|
||||
|
||||
@@ -139,9 +139,13 @@
|
||||
|
||||
<CODEGENERATION>
|
||||
<IMPORTS>
|
||||
<IMPORT NAME="Java_SCP" MODULE="ganymed-ssh2-261.jar" MVN="mvn:ch.ethz.ganymed/ganymed-ssh2/261" REQUIRED="true"/>
|
||||
<IMPORT NAME="SSHD_CORE" MODULE="sshd-core-2.5.1.jar" MVN="mvn:org.apache.sshd/sshd-core/2.5.1" REQUIRED="true"/>
|
||||
<IMPORT NAME="SSHD_COMMON" MODULE="sshd-common-2.5.1.jar" MVN="mvn:org.apache.sshd/sshd-common/2.5.1" REQUIRED="true"/>
|
||||
<IMPORT NAME="SSHD_SCP" MODULE="sshd-scp-2.5.1.jar" MVN="mvn:org.apache.sshd/sshd-scp/2.5.1" REQUIRED="true"/>
|
||||
<IMPORT NAME="talend-scp-helper" MODULE="talend-scp-helper-1.0.jar" MVN="mvn:org.talend.components/talend-scp-helper/1.0" REQUIRED="true"/>
|
||||
</IMPORTS>
|
||||
</CODEGENERATION>
|
||||
|
||||
<RETURNS>
|
||||
<RETURN NAME="STATUS" TYPE="id_String" AVAILABILITY="AFTER"/>
|
||||
<RETURN NAME="NB_FILE" TYPE="id_Integer" AVAILABILITY="AFTER"/>
|
||||
|
||||
@@ -1,38 +1,80 @@
|
||||
<%@ jet
|
||||
imports="
|
||||
org.talend.core.model.process.INode
|
||||
org.talend.core.model.process.INode
|
||||
org.talend.core.model.process.ElementParameterParser
|
||||
org.talend.designer.codegen.config.CodeGeneratorArgument
|
||||
java.util.List
|
||||
java.util.Map
|
||||
org.talend.core.model.utils.NodeUtil
|
||||
"
|
||||
%>
|
||||
|
||||
<%
|
||||
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
|
||||
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
|
||||
INode node = (INode)codeGenArgument.getArgument();
|
||||
String cid = node.getUniqueName();
|
||||
String remotedir = ElementParameterParser.getValue(node, "__REMOTEDIR__");
|
||||
List<Map<String, String>> filelist =(List<Map<String,String>>)ElementParameterParser.getObjectValue(node,"__FILELIST__");
|
||||
String authMethod = ElementParameterParser.getValue(node,"__AUTH_METHOD__");
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
String cid = node.getUniqueName();
|
||||
String remotedir = ElementParameterParser.getValue(node, "__REMOTEDIR__");
|
||||
%>
|
||||
try{
|
||||
if(destFile_<%=cid %>!=null && destFile_<%=cid %>.length()!=0){
|
||||
java.io.OutputStream out_<%=cid%> = null;
|
||||
try {
|
||||
out_<%=cid%> = scp_<%=cid%>.put(destFile_<%=cid%>, 0, <%=remotedir %>, "0644");
|
||||
out_<%=cid %>.write(new byte[]{});
|
||||
} finally {
|
||||
if(out_<%=cid %> != null){
|
||||
out_<%=cid %>.close();
|
||||
}
|
||||
}
|
||||
|
||||
nb_file_<%=cid%> ++;
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - '" + destFile_<%=cid %> + "' truncate OK.");
|
||||
<%}%>
|
||||
globalMap.put("<%=cid %>_STATUS", "File truncate OK.");
|
||||
}
|
||||
}catch(java.lang.Exception e_<%=cid%>){
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.error("<%=cid%> - " + e_<%=cid%>.getMessage());
|
||||
<%}%>
|
||||
globalMap.put("<%=cid %>_STATUS", "File truncate fail.");
|
||||
String useExistingConn = ElementParameterParser.getValue(node, "__USE_EXISTING_CONNECTION__");
|
||||
if(("true").equals(useExistingConn)){
|
||||
String connection = ElementParameterParser.getValue(node, "__CONNECTION__");
|
||||
INode connectionNode = NodeUtil.getNodeByUniqueName(node.getProcess(), connection);
|
||||
authMethod = ElementParameterParser.getValue(connectionNode,"__AUTH_METHOD__");
|
||||
}
|
||||
%>
|
||||
|
||||
/* open a session */
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Open up a session.");
|
||||
<%}%>
|
||||
|
||||
session_<%=cid%> = client_<%=cid%>.connect(username_<%=cid%>, hostname_<%=cid%>, port_<%=cid%>).verify().getClientSession();
|
||||
try {
|
||||
session_<%=cid%>.auth().verify();
|
||||
}catch (org.apache.sshd.common.SshException se_<%=cid%>){
|
||||
globalMap.put("<%=cid %>_EXIT_CODE",se_<%=cid%>.getDisconnectCode());
|
||||
<%
|
||||
if (("PUBLICKEY").equals(authMethod)) {
|
||||
%>
|
||||
java.nio.file.Files.write(privateKey_<%=cid%>,lines_<%=cid%>);
|
||||
<%}%>
|
||||
if(14 == se_<%=cid%>.getDisconnectCode()){
|
||||
throw new IllegalArgumentException("Authentication failed.");
|
||||
}else{
|
||||
throw se_<%=cid%>;
|
||||
}
|
||||
}
|
||||
org.apache.sshd.client.scp.ScpClientCreator instance_<%=cid%> = org.talend.components.talendscp.TalendScpClientCreator.INSTANCE;
|
||||
org.apache.sshd.client.scp.ScpClient scp_<%=cid%> = instance_<%=cid%>.createScpClient(session_<%=cid%>);
|
||||
|
||||
String[] destFileNames_<%=cid%> = new String[]{
|
||||
<%
|
||||
for (Map<String, String> file : filelist) {
|
||||
%>
|
||||
<%=file.get("DESTINATION")%>,
|
||||
<%
|
||||
}
|
||||
%>
|
||||
};
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Truncating file from the server.");
|
||||
<%}%>
|
||||
for(String destFile_<%=cid %> : destFileNames_<%=cid%>){
|
||||
try{
|
||||
if(destFile_<%=cid %>!=null && destFile_<%=cid %>.length()!=0){
|
||||
java.util.List<java.nio.file.attribute.PosixFilePermission> posixFilePermissions = java.util.Arrays.asList(java.nio.file.attribute.PosixFilePermission.OWNER_READ,
|
||||
java.nio.file.attribute.PosixFilePermission.OWNER_WRITE,
|
||||
java.nio.file.attribute.PosixFilePermission.GROUP_READ,
|
||||
java.nio.file.attribute.PosixFilePermission.OTHERS_READ);
|
||||
scp_<%=cid%>.upload(new byte[0],<%=remotedir%>+"/"+destFile_<%=cid %>,posixFilePermissions,new org.apache.sshd.common.scp.ScpTimestamp(System.nanoTime(),System.nanoTime()));
|
||||
nb_file_<%=cid%> ++;
|
||||
globalMap.put("<%=cid %>_STATUS", "File truncate OK.");
|
||||
}
|
||||
}catch(java.lang.Exception e){
|
||||
globalMap.put("<%=cid %>_STATUS", "File truncate fail.");
|
||||
}
|
||||
}
|
||||
session_<%=cid%>.close();
|
||||
@@ -39,7 +39,7 @@ if ((metadatas!=null)&&(metadatas.size()>0)) {
|
||||
/* open a session */
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Authentication using a password.");
|
||||
log.info("<%=cid%> - Open up a session.");
|
||||
<%}%>
|
||||
|
||||
session_<%=cid%> = client_<%=cid%>.connect(username_<%=cid%>, hostname_<%=cid%>, Integer.parseInt(<%=port %>+"")).verify(<%=("true").equals(useTimeout)?timeout+"L * 1000":""%>).getClientSession();
|
||||
|
||||
@@ -38,26 +38,12 @@
|
||||
name="talend-bigdata-launcher-1.0.0-20150922.jar"
|
||||
mvn_uri="mvn:org.talend.libraries/talend-bigdata-launcher-1.0.0-20150922/6.0.0">
|
||||
</libraryNeeded>
|
||||
<libraryNeeded
|
||||
context="plugin:org.talend.libraries.apache.cxf"
|
||||
id="cxf-api-2.7.7.jar"
|
||||
name="cxf-api-2.7.7.jar"
|
||||
mvn_uri="mvn:org.talend.libraries/cxf-api-2.7.7/6.0.0"
|
||||
uripath="platform:/plugin/org.talend.libraries.apache.cxf/lib/cxf-api-2.7.7.jar">
|
||||
</libraryNeeded>
|
||||
<libraryNeeded
|
||||
context="plugin:org.talend.libraries.apache.cxf"
|
||||
id="cxf-rt-bindings-xml-3.3.10.jar"
|
||||
name="cxf-rt-bindings-xml-3.3.10.jar"
|
||||
mvn_uri="mvn:org.apache.cxf/cxf-rt-bindings-xml/3.3.10">
|
||||
</libraryNeeded>
|
||||
<libraryNeeded
|
||||
context="plugin:org.talend.libraries.apache.cxf"
|
||||
id="cxf-rt-core-2.7.7.jar"
|
||||
name="cxf-rt-core-2.7.7.jar"
|
||||
mvn_uri="mvn:org.talend.libraries/cxf-rt-core-2.7.7/6.0.0"
|
||||
uripath="platform:/plugin/org.talend.libraries.apache.cxf/lib/cxf-rt-core-2.7.7.jar">
|
||||
</libraryNeeded>
|
||||
<libraryNeeded
|
||||
context="plugin:org.talend.libraries.apache.cxf"
|
||||
id="cxf-rt-frontend-jaxrs-3.3.10.jar"
|
||||
@@ -7735,9 +7721,7 @@
|
||||
id="HD_INSIGHT_COMMON_LIBRARIES_LATEST"
|
||||
name="HD_INSIGHT_COMMON_LIBRARIES_LATEST">
|
||||
<library id="talend-bigdata-launcher-1.1.0-20160405.jar" />
|
||||
<library id="cxf-api-2.7.7.jar" />
|
||||
<library id="cxf-rt-bindings-xml-3.3.10.jar" />
|
||||
<library id="cxf-rt-core-2.7.7.jar" />
|
||||
<library id="cxf-rt-frontend-jaxrs-3.3.10.jar" />
|
||||
<library id="cxf-rt-transports-http-3.3.10.jar" />
|
||||
<library id="json_simple-1.1.jar" />
|
||||
|
||||
@@ -5363,6 +5363,13 @@ public class Node extends Element implements IGraphicalNode {
|
||||
return isJoblet;
|
||||
}
|
||||
|
||||
public boolean isProcessNode() {
|
||||
if ("tRunJob".equals(getComponent().getName()) || isJoblet()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isJoblet() {
|
||||
boolean isJoblet = false;
|
||||
if (PluginChecker.isJobLetPluginLoaded()) {
|
||||
|
||||
@@ -213,6 +213,8 @@ public class Process extends Element implements IProcess2, IGEFProcess, ILastVer
|
||||
|
||||
protected List<INode> nodes = new ArrayList<INode>();
|
||||
|
||||
protected List<INode> processNodes = new ArrayList<INode>();
|
||||
|
||||
protected List<Element> elem = new ArrayList<Element>();
|
||||
|
||||
protected List<SubjobContainer> subjobContainers = new ArrayList<SubjobContainer>();
|
||||
@@ -712,8 +714,11 @@ public class Process extends Element implements IProcess2, IGEFProcess, ILastVer
|
||||
*/
|
||||
public void addNodeContainer(final NodeContainer nodeContainer) {
|
||||
elem.add(nodeContainer);
|
||||
nodes.add(nodeContainer.getNode());
|
||||
|
||||
Node node = nodeContainer.getNode();
|
||||
nodes.add(node);
|
||||
if (node.isProcessNode()) {
|
||||
processNodes.add(node);
|
||||
}
|
||||
// fireStructureChange(NEED_UPDATE_JOB, elem);
|
||||
}
|
||||
|
||||
@@ -731,6 +736,16 @@ public class Process extends Element implements IProcess2, IGEFProcess, ILastVer
|
||||
removeUniqueNodeNamesInJoblet((AbstractJobletContainer) nodeContainer, readedContainers);
|
||||
}
|
||||
removeNode(uniqueName);
|
||||
if (nodeContainer.getNode().isProcessNode() && uniqueName != null) {
|
||||
Iterator<INode> nodeIter = processNodes.iterator();
|
||||
while (nodeIter.hasNext()) {
|
||||
INode processNode = nodeIter.next();
|
||||
if (uniqueName.equals(processNode.getUniqueName())) {
|
||||
nodeIter.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Element toRemove = nodeContainer;
|
||||
List<Element> toAdd = new ArrayList<Element>();
|
||||
for (Object o : elem) {
|
||||
@@ -807,6 +822,11 @@ public class Process extends Element implements IProcess2, IGEFProcess, ILastVer
|
||||
return this.nodes;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends INode> getProcessNodes() {
|
||||
return this.processNodes;
|
||||
}
|
||||
|
||||
protected IGeneratingProcess generatingProcess = null;
|
||||
|
||||
boolean isBuilding;
|
||||
@@ -4639,6 +4659,7 @@ public class Process extends Element implements IProcess2, IGEFProcess, ILastVer
|
||||
|
||||
elem.clear();
|
||||
nodes.clear();
|
||||
processNodes.clear();
|
||||
notes.clear();
|
||||
subjobContainers.clear();
|
||||
setGeneratingProcess(null);
|
||||
|
||||
@@ -67,6 +67,11 @@
|
||||
<artifactId>commons-collections</artifactId>
|
||||
<version>3.2.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.shared</groupId>
|
||||
<artifactId>maven-shared-utils</artifactId>
|
||||
<version>3.3.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<configuration>
|
||||
<archive>
|
||||
|
||||
@@ -859,9 +859,13 @@ public class DefaultRunProcessService implements IRunProcessService {
|
||||
*/
|
||||
@Override
|
||||
public void initializeRootPoms(IProgressMonitor monitor) {
|
||||
if (isCIMode()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// skipping of root pom generation and updating code projects
|
||||
// leads to compilation errors and incorrect manifest generation
|
||||
// for routes and OSGi jobs (APPINT-32995)
|
||||
// if (isCIMode()) {
|
||||
// return;
|
||||
// }
|
||||
try {
|
||||
AggregatorPomsHelper helper = new AggregatorPomsHelper();
|
||||
helper.installRootPom(false);
|
||||
|
||||
@@ -389,7 +389,10 @@ public class MavenJavaProcessor extends JavaProcessor {
|
||||
boolean isGoalPackage = TalendMavenConstants.GOAL_PACKAGE.equals(goal);
|
||||
boolean isGoalInstall = TalendMavenConstants.GOAL_INSTALL.equals(goal);
|
||||
boolean isMainJob = LastGenerationInfo.getInstance().isCurrentMainJob();
|
||||
if (!isMainJob && isGoalInstall) {
|
||||
boolean isRoutelet =
|
||||
ERepositoryObjectType.PROCESS_ROUTELET != null && getProperty() != null && getProperty().getItem() != null
|
||||
&& ERepositoryObjectType.PROCESS_ROUTELET.equals(ERepositoryObjectType.getType(getProperty()));
|
||||
if ((!isMainJob && isGoalInstall) || isRoutelet) {
|
||||
if (!buildCacheManager.isJobBuild(getProperty())) {
|
||||
deleteExistedJobJarFile(talendJavaProject);
|
||||
String buildType = getBuildType(getProperty());
|
||||
|
||||
Reference in New Issue
Block a user