Skip to content
Snippets Groups Projects
Commit 7ea09ce7 authored by Lukas Johannes Horn's avatar Lukas Johannes Horn
Browse files

Merge remote-tracking branch 'origin/master'

parents 20ae8974 00c03831
No related branches found
No related tags found
No related merge requests found
Showing
with 628 additions and 3 deletions
# SSH-Data-Transfer tool
## Development
### Import project
You can import the project as maven project in eclipse or IntelliJ.
### Local environment
For developing local you can use start a server local in with docker by executing the following command in this folder:
```
docker-compose up -d
```
and stop it with:
```
docker-compose stop
```
This will download the docker images for mysql, adminer (a mysql management tool) and a linux-system with a running ssh server.
The mysql server can be reached on localhost:3306, adminer on localhost:8080 and the ssh server on localhost:2222.
\ No newline at end of file
target/* target/*
settings/ settings/
.project .project
.classpath .classpath
\ No newline at end of file /target/
...@@ -10,6 +10,8 @@ services: ...@@ -10,6 +10,8 @@ services:
restart: always restart: always
environment: environment:
MYSQL_ROOT_PASSWORD: example MYSQL_ROOT_PASSWORD: example
ports:
- 3306:3306
adminer: adminer:
image: adminer image: adminer
......
target/* target/*
settings/ settings/
.project .project
.classpath .classpath
\ No newline at end of file /target/
target/* target/*
settings/ settings/
.project .project
.classpath .classpath
\ No newline at end of file /target/
package de.uniwue.swp.sshtool.management;
import java.io.File;
import java.util.List;
import de.uniwue.sshtool.database.FileTransfer;
import de.uniwue.swp.sshtool.management.listener.ConnectionListener;
import de.uniwue.swp.sshtool.management.listener.TransactionListener;
import de.uniwue.swp.sshtool.management.utils.ManagedFile;
/**
* Facade for the management module.
*
* @author lmnch
*
*/
public class ManagementFacade {
/**
* Establishes a connection to the ssh server and checks for files which failed
* to upload before.
*
* @param username
* @param password
* @param hostname
* @param port
*/
// TODO: Replace Object type with Transaction from database as soon as available
public List<FileTransfer> sshLogin(final String username, final String password, final String hostname, final int port) {
throw new UnsupportedOperationException();
}
/**
* Returns the managed file which is stored on the remote server.
*
* @param path Path on the remote system
* @return
*/
public ManagedFile getFile(final String path) {
throw new UnsupportedOperationException();
}
/**
* Uploads the list of files from the local filesystem to the the ManagedFile
* (which must be a directory) on the server.
*
* And creates a database entry for the transaction.
*
* @param localFiles
* @param remoteDirectory
*/
public void upload(final List<File> localFiles, final ManagedFile remoteDirectory) {
throw new UnsupportedOperationException();
}
/**
* Downloads the files in remote files to the localTarget directory.
*
* And creates a database entry for the transaction.
*
* @param localTarget
* @param remoteFiles
*/
public void download(final File localTarget, final List<ManagedFile> remoteFiles) {
throw new UnsupportedOperationException();
}
/**
* Restarts the upload procedure for the items in the list.
*
* @param paths
*/
// TODO: Replace Object type with Transaction from database as soon as available
public void reuploadFailedFiles(final List<FileTransfer> transactions) {
throw new UnsupportedOperationException();
}
/**
* Marks the failed FileTransfers as cancelled.
*
* @param transfers
*/
public void cancelFailedTransactions(final List<FileTransfer> transfers) {
throw new UnsupportedOperationException();
}
/**
* Registers a TransactionListener.
*
* @param listener
*/
public void registerTransactionListener(final TransactionListener listener) {
throw new UnsupportedOperationException();
}
/**
* Unregisters a TransactionListener.
*
* @param listener
*/
public void unregisterTransactionListener(final TransactionListener listener) {
throw new UnsupportedOperationException();
}
/**
* Registers a ConnectionListener.
*
* @param listener
*/
public void registerConnectionListener(final ConnectionListener listener) {
throw new UnsupportedOperationException();
}
/**
* Unregisters a ConnectionListener.
*
* @param listener
*/
public void unregisterTConnectionListener(final ConnectionListener listener) {
throw new UnsupportedOperationException();
}
}
package de.uniwue.swp.sshtool.management.command;
import de.uniwue.sshtool.database.DatabaseFacade;
import de.uniwue.swp.sshtool.management.command.result.AbstractCommandResult;
import de.uniwue.swp.sshtool.ssh.SSHFacade;
/**
* Abstract class from which all commands should inherit.<br/>
* Contains protected fields for db and ssh facades.
*
* @author lmnch
*
*/
public abstract class AbstractCommand {
// Facades of submodules
// TODO: replace with datatypes as soon as available
protected DatabaseFacade db;
protected SSHFacade ssh;
/**
* Creates a new command.
*
* @param db
* @param ssh
*/
// TODO: replace with datatypes as soon as available
public AbstractCommand(final DatabaseFacade db, final SSHFacade ssh) {
this.db = db;
this.ssh = ssh;
}
public abstract AbstractCommandResult execute();
}
package de.uniwue.swp.sshtool.management.command;
import java.util.List;
import de.uniwue.sshtool.database.DatabaseFacade;
import de.uniwue.swp.sshtool.management.command.result.AbstractCommandResult;
import de.uniwue.swp.sshtool.management.listener.TransactionListener;
import de.uniwue.swp.sshtool.management.utils.TransactionType;
import de.uniwue.swp.sshtool.ssh.SSHFacade;
/**
* Abstract command superclass for all transactions like Upload, Download or deletions.
*
* @author lmnch
*
*/
public abstract class AbstractTransactionCommand extends AbstractCommand {
protected List<TransactionListener> transactionListener;
public AbstractTransactionCommand(DatabaseFacade db, SSHFacade ssh, final List<TransactionListener> l) {
super(db, ssh);
this.transactionListener = l;
}
@Override
public abstract AbstractCommandResult execute();
protected abstract TransactionType getTransactionType();
}
package de.uniwue.swp.sshtool.management.command;
import java.util.List;
import de.uniwue.sshtool.database.DatabaseFacade;
import de.uniwue.sshtool.database.FileTransfer;
import de.uniwue.swp.sshtool.management.command.result.AbstractCommandResult;
import de.uniwue.swp.sshtool.ssh.SSHFacade;
/**
* Command to mark in the database that a failed transfer won't be retryed.
*
* @author lmnch
*
*/
public class CancelFailedTransferCommand extends AbstractCommand {
private List<FileTransfer> transfers;
public CancelFailedTransferCommand(DatabaseFacade db, SSHFacade ssh, List<FileTransfer> fileTransfer) {
super(db, ssh);
this.transfers = fileTransfer;
}
@Override
public AbstractCommandResult execute() {
throw new UnsupportedOperationException();
}
}
package de.uniwue.swp.sshtool.management.command;
import java.util.List;
import de.uniwue.sshtool.database.DatabaseFacade;
import de.uniwue.swp.sshtool.management.command.result.AbstractCommandResult;
import de.uniwue.swp.sshtool.management.listener.TransactionListener;
import de.uniwue.swp.sshtool.management.utils.TransactionType;
import de.uniwue.swp.sshtool.ssh.SSHFacade;
/**
* Command to delete a file on remote system and store deletion transaction in database.
*
* @author lmnch
*
*/
public class DeletionCommand extends AbstractTransactionCommand {
private String pathToDelete;
public DeletionCommand(DatabaseFacade db, SSHFacade ssh, List<TransactionListener> l, String pathToDelete) {
super(db, ssh, l);
this.pathToDelete = pathToDelete;
}
@Override
public AbstractCommandResult execute() {
throw new UnsupportedOperationException();
}
@Override
protected TransactionType getTransactionType() {
return TransactionType.DELETION;
}
}
package de.uniwue.swp.sshtool.management.command;
import java.util.List;
import de.uniwue.sshtool.database.DatabaseFacade;
import de.uniwue.swp.sshtool.management.command.result.AbstractCommandResult;
import de.uniwue.swp.sshtool.management.listener.TransactionListener;
import de.uniwue.swp.sshtool.management.utils.TransactionType;
import de.uniwue.swp.sshtool.ssh.SSHFacade;
/**
* Command to download files and store download transaction in db.
*
* @author lmnch
*
*/
public class DownloadCommand extends AbstractTransactionCommand {
protected String localPath;
protected List<String> remoteFiles;
public DownloadCommand(DatabaseFacade db, SSHFacade ssh, List<TransactionListener> l, String localTargetPath, List<String> remoteFiles) {
super(db, ssh, l);
this.localPath = localTargetPath;
this.remoteFiles = remoteFiles;
}
protected DownloadCommand(DatabaseFacade db, SSHFacade ssh, List<TransactionListener> l) {
super(db, ssh, l);
}
@Override
public AbstractCommandResult execute() {
sshDownload();
storeDownload();
return null;
}
protected void sshDownload() {
throw new UnsupportedOperationException();
}
protected void storeDownload() {
throw new UnsupportedOperationException();
}
@Override
protected TransactionType getTransactionType() {
return TransactionType.DOWNLOAD;
}
}
package de.uniwue.swp.sshtool.management.command;
import de.uniwue.sshtool.database.DatabaseFacade;
import de.uniwue.swp.sshtool.management.command.result.AbstractCommandResult;
import de.uniwue.swp.sshtool.management.command.result.ListDirectoryCommandResult;
import de.uniwue.swp.sshtool.ssh.SSHFacade;
/**
* Command which returns all subfolders and files in a folder which is
* identified by the path.
*
* @author lmnch
*
*/
public class ListDirectoryCommand extends AbstractCommand {
private String path;
public ListDirectoryCommand(DatabaseFacade db, SSHFacade ssh, String path) {
super(db, ssh);
this.path = path;
}
@Override
public AbstractCommandResult execute() {
return executeListDirectoryCommand();
}
public ListDirectoryCommandResult executeListDirectoryCommand() {
throw new UnsupportedOperationException();
}
}
package de.uniwue.swp.sshtool.management.command;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import de.uniwue.sshtool.database.DatabaseFacade;
import de.uniwue.sshtool.database.FileTransfer;
import de.uniwue.swp.sshtool.management.listener.TransactionListener;
import de.uniwue.swp.sshtool.ssh.SSHFacade;
/**
* Command to retry the download of elements.
*
* @author lmnch
*
*/
public class RetryDownloadCommand extends DownloadCommand {
/**
* Creates new retry download command.
*
* @param db
* @param ssh
* @param l
* @param fileTransfer must be a list of transfers with all the same target
*/
public RetryDownloadCommand(DatabaseFacade db, SSHFacade ssh, List<TransactionListener> l, List<FileTransfer> fileTransfer) {
super(db, ssh, l);
final Optional<String> localPath = fileTransfer.stream().findFirst().map(f -> f.getRemotePath());
if (localPath.isEmpty())
throw new IllegalArgumentException("fileTransfer must not be empty");
for (FileTransfer fileTransfer2 : fileTransfer) {
if (!fileTransfer2.getRemotePath().equals(localPath.get()))
throw new IllegalArgumentException("file transfers must have the same target!");
}
this.remoteFiles = fileTransfer.stream().map(ft -> ft.getSource()).collect(Collectors.toList());
this.localPath = localPath.get();
}
/**
* Overwritten from Download command. In case of retry the database entries must be
* changed and not created.
*/
@Override
protected void storeDownload() {
throw new UnsupportedOperationException();
}
}
package de.uniwue.swp.sshtool.management.command;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import de.uniwue.sshtool.database.DatabaseFacade;
import de.uniwue.sshtool.database.FileTransfer;
import de.uniwue.swp.sshtool.management.listener.TransactionListener;
import de.uniwue.swp.sshtool.ssh.SSHFacade;
public class RetryUploadCommand extends UploadCommand {
/**
* Creates new retry upload command.
*
* @param db
* @param ssh
* @param l
* @param fileTransfer must be a list of transfers with all the same target
*/
public RetryUploadCommand(DatabaseFacade db, SSHFacade ssh, List<TransactionListener> l,
List<FileTransfer> fileTransfer) {
super(db, ssh, l);
final Optional<String> remotePath = fileTransfer.stream().findFirst().map(f -> f.getRemotePath());
if (remotePath.isEmpty())
throw new IllegalArgumentException("fileTransfer must not be empty");
for (FileTransfer fileTransfer2 : fileTransfer) {
if (!fileTransfer2.getRemotePath().equals(remotePath.get()))
throw new IllegalArgumentException("file transfers must have the same target!");
}
this.localFiles = fileTransfer.stream().map(ft -> ft.getSource()).collect(Collectors.toList());
this.remotePath = remotePath.get();
}
/**
* Overwritten from Upload command. In case of retry the database entries must be
* changed and not created.
*/
@Override
protected void storeUpload() {
throw new UnsupportedOperationException();
}
}
package de.uniwue.swp.sshtool.management.command;
import de.uniwue.sshtool.database.DatabaseFacade;
import de.uniwue.swp.sshtool.management.command.result.AbstractCommandResult;
import de.uniwue.swp.sshtool.management.command.result.LoginCommandResult;
import de.uniwue.swp.sshtool.ssh.SSHFacade;
/**
* Command to log in on the SSH server.
*
* @author lmnch
*
*/
public class SSHLoginCommand extends AbstractCommand {
private String username, password;
private String hostname;
private int port;
public SSHLoginCommand(DatabaseFacade db, SSHFacade ssh, String user, String password, String hostname, int port) {
super(db, ssh);
this.username = user;
this.password = password;
this.hostname = hostname;
this.port = port;
}
@Override
public AbstractCommandResult execute() {
return executeSSHLogin();
}
public LoginCommandResult executeSSHLogin() {
throw new UnsupportedOperationException();
}
}
package de.uniwue.swp.sshtool.management.command;
import java.util.List;
import de.uniwue.sshtool.database.DatabaseFacade;
import de.uniwue.swp.sshtool.management.command.result.AbstractCommandResult;
import de.uniwue.swp.sshtool.management.listener.TransactionListener;
import de.uniwue.swp.sshtool.management.utils.TransactionType;
import de.uniwue.swp.sshtool.ssh.SSHFacade;
/**
* Command to upload a list of files to a directory on the server.
* Copies the files to the server and stores the transaction in the database.
*
* @author lmnch
*
*/
public class UploadCommand extends AbstractTransactionCommand {
protected List<String> localFiles;
protected String remotePath;
public UploadCommand(DatabaseFacade db, SSHFacade ssh, List<TransactionListener> l, List<String> localFiles,
String remotePath) {
super(db, ssh, l);
this.localFiles = localFiles;
this.remotePath = remotePath;
}
protected UploadCommand(DatabaseFacade db, SSHFacade ssh, List<TransactionListener> l) {
super(db, ssh, l);
}
@Override
public AbstractCommandResult execute() {
sshUpload();
storeUpload();
return null;
}
protected void sshUpload() {
throw new UnsupportedOperationException();
}
protected void storeUpload() {
throw new UnsupportedOperationException();
}
@Override
protected TransactionType getTransactionType() {
return TransactionType.UPLOAD;
}
}
package de.uniwue.swp.sshtool.management.command.result;
public abstract class AbstractCommandResult {
}
package de.uniwue.swp.sshtool.management.command.result;
public class EmptyCommandResult extends AbstractCommandResult{
}
package de.uniwue.swp.sshtool.management.command.result;
import java.util.List;
public class ListDirectoryCommandResult extends AbstractCommandResult {
private List<String> files;
private List<String> subfolder;
public ListDirectoryCommandResult(List<String> files, List<String> subfolder) {
super();
this.files = files;
this.subfolder = subfolder;
}
public List<String> getFiles() {
return files;
}
public List<String> getSubfolder() {
return subfolder;
}
}
package de.uniwue.swp.sshtool.management.command.result;
import java.util.List;
import de.uniwue.sshtool.database.FileTransfer;
/**
* Result of a login command. Contains all open transaction which were not completed or stopped the last time.
*
* @author lmnch
*
*/
public class LoginCommandResult extends AbstractCommandResult {
private List<FileTransfer> failedTransfers;
public LoginCommandResult(List<FileTransfer> failedTransfers) {
super();
this.failedTransfers = failedTransfers;
}
public List<FileTransfer> getFailedTransfers() {
return failedTransfers;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment