summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Petretti2014-06-19 17:26:19 +0200
committerMichael Petretti2014-06-19 17:26:19 +0200
commit4eadd87af796b9b670fc69cad792579202bc48c5 (patch)
tree727827080cf77edb5ba4d6afcf4752b00193f96a
parentFinished Debug for Uploads. (diff)
downloadsatellite-daemon-4eadd87af796b9b670fc69cad792579202bc48c5.tar.gz
satellite-daemon-4eadd87af796b9b670fc69cad792579202bc48c5.tar.xz
satellite-daemon-4eadd87af796b9b670fc69cad792579202bc48c5.zip
More debugging plus FtpDownloadWorker added.
-rw-r--r--src/main/java/org/openslx/imagemaster/thrift/iface/FtpCredentials.java108
-rw-r--r--src/main/java/org/openslx/imagemaster/thrift/iface/ImageServer.java192
-rw-r--r--src/main/java/org/openslx/satellitedaemon/App.java3
-rw-r--r--src/main/java/org/openslx/satellitedaemon/db/DbImage.java11
-rw-r--r--src/main/java/org/openslx/satellitedaemon/ftp/FtpDownloadWorker.java93
-rw-r--r--src/main/java/org/openslx/satellitedaemon/ftp/ThriftConnection.java62
6 files changed, 368 insertions, 101 deletions
diff --git a/src/main/java/org/openslx/imagemaster/thrift/iface/FtpCredentials.java b/src/main/java/org/openslx/imagemaster/thrift/iface/FtpCredentials.java
index fccb7b3..7b74425 100644
--- a/src/main/java/org/openslx/imagemaster/thrift/iface/FtpCredentials.java
+++ b/src/main/java/org/openslx/imagemaster/thrift/iface/FtpCredentials.java
@@ -37,6 +37,7 @@ public class FtpCredentials implements org.apache.thrift.TBase<FtpCredentials, F
private static final org.apache.thrift.protocol.TField USERNAME_FIELD_DESC = new org.apache.thrift.protocol.TField("username", org.apache.thrift.protocol.TType.STRING, (short)1);
private static final org.apache.thrift.protocol.TField PASSWORD_FIELD_DESC = new org.apache.thrift.protocol.TField("password", org.apache.thrift.protocol.TType.STRING, (short)2);
+ private static final org.apache.thrift.protocol.TField FILENAME_FIELD_DESC = new org.apache.thrift.protocol.TField("filename", org.apache.thrift.protocol.TType.STRING, (short)3);
private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
static {
@@ -46,11 +47,13 @@ public class FtpCredentials implements org.apache.thrift.TBase<FtpCredentials, F
public String username; // required
public String password; // required
+ public String filename; // required
/** The set of fields this struct contains, along with convenience methods for finding and manipulating them. */
public enum _Fields implements org.apache.thrift.TFieldIdEnum {
USERNAME((short)1, "username"),
- PASSWORD((short)2, "password");
+ PASSWORD((short)2, "password"),
+ FILENAME((short)3, "filename");
private static final Map<String, _Fields> byName = new HashMap<String, _Fields>();
@@ -69,6 +72,8 @@ public class FtpCredentials implements org.apache.thrift.TBase<FtpCredentials, F
return USERNAME;
case 2: // PASSWORD
return PASSWORD;
+ case 3: // FILENAME
+ return FILENAME;
default:
return null;
}
@@ -116,6 +121,8 @@ public class FtpCredentials implements org.apache.thrift.TBase<FtpCredentials, F
new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
tmpMap.put(_Fields.PASSWORD, new org.apache.thrift.meta_data.FieldMetaData("password", org.apache.thrift.TFieldRequirementType.DEFAULT,
new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
+ tmpMap.put(_Fields.FILENAME, new org.apache.thrift.meta_data.FieldMetaData("filename", org.apache.thrift.TFieldRequirementType.DEFAULT,
+ new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRING)));
metaDataMap = Collections.unmodifiableMap(tmpMap);
org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(FtpCredentials.class, metaDataMap);
}
@@ -125,11 +132,13 @@ public class FtpCredentials implements org.apache.thrift.TBase<FtpCredentials, F
public FtpCredentials(
String username,
- String password)
+ String password,
+ String filename)
{
this();
this.username = username;
this.password = password;
+ this.filename = filename;
}
/**
@@ -142,6 +151,9 @@ public class FtpCredentials implements org.apache.thrift.TBase<FtpCredentials, F
if (other.isSetPassword()) {
this.password = other.password;
}
+ if (other.isSetFilename()) {
+ this.filename = other.filename;
+ }
}
public FtpCredentials deepCopy() {
@@ -152,6 +164,7 @@ public class FtpCredentials implements org.apache.thrift.TBase<FtpCredentials, F
public void clear() {
this.username = null;
this.password = null;
+ this.filename = null;
}
public String getUsername() {
@@ -202,6 +215,30 @@ public class FtpCredentials implements org.apache.thrift.TBase<FtpCredentials, F
}
}
+ public String getFilename() {
+ return this.filename;
+ }
+
+ public FtpCredentials setFilename(String filename) {
+ this.filename = filename;
+ return this;
+ }
+
+ public void unsetFilename() {
+ this.filename = null;
+ }
+
+ /** Returns true if field filename is set (has been assigned a value) and false otherwise */
+ public boolean isSetFilename() {
+ return this.filename != null;
+ }
+
+ public void setFilenameIsSet(boolean value) {
+ if (!value) {
+ this.filename = null;
+ }
+ }
+
public void setFieldValue(_Fields field, Object value) {
switch (field) {
case USERNAME:
@@ -220,6 +257,14 @@ public class FtpCredentials implements org.apache.thrift.TBase<FtpCredentials, F
}
break;
+ case FILENAME:
+ if (value == null) {
+ unsetFilename();
+ } else {
+ setFilename((String)value);
+ }
+ break;
+
}
}
@@ -231,6 +276,9 @@ public class FtpCredentials implements org.apache.thrift.TBase<FtpCredentials, F
case PASSWORD:
return getPassword();
+ case FILENAME:
+ return getFilename();
+
}
throw new IllegalStateException();
}
@@ -246,6 +294,8 @@ public class FtpCredentials implements org.apache.thrift.TBase<FtpCredentials, F
return isSetUsername();
case PASSWORD:
return isSetPassword();
+ case FILENAME:
+ return isSetFilename();
}
throw new IllegalStateException();
}
@@ -281,6 +331,15 @@ public class FtpCredentials implements org.apache.thrift.TBase<FtpCredentials, F
return false;
}
+ boolean this_present_filename = true && this.isSetFilename();
+ boolean that_present_filename = true && that.isSetFilename();
+ if (this_present_filename || that_present_filename) {
+ if (!(this_present_filename && that_present_filename))
+ return false;
+ if (!this.filename.equals(that.filename))
+ return false;
+ }
+
return true;
}
@@ -317,6 +376,16 @@ public class FtpCredentials implements org.apache.thrift.TBase<FtpCredentials, F
return lastComparison;
}
}
+ lastComparison = Boolean.valueOf(isSetFilename()).compareTo(other.isSetFilename());
+ if (lastComparison != 0) {
+ return lastComparison;
+ }
+ if (isSetFilename()) {
+ lastComparison = org.apache.thrift.TBaseHelper.compareTo(this.filename, other.filename);
+ if (lastComparison != 0) {
+ return lastComparison;
+ }
+ }
return 0;
}
@@ -352,6 +421,14 @@ public class FtpCredentials implements org.apache.thrift.TBase<FtpCredentials, F
sb.append(this.password);
}
first = false;
+ if (!first) sb.append(", ");
+ sb.append("filename:");
+ if (this.filename == null) {
+ sb.append("null");
+ } else {
+ sb.append(this.filename);
+ }
+ first = false;
sb.append(")");
return sb.toString();
}
@@ -411,6 +488,14 @@ public class FtpCredentials implements org.apache.thrift.TBase<FtpCredentials, F
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
}
break;
+ case 3: // FILENAME
+ if (schemeField.type == org.apache.thrift.protocol.TType.STRING) {
+ struct.filename = iprot.readString();
+ struct.setFilenameIsSet(true);
+ } else {
+ org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
+ }
+ break;
default:
org.apache.thrift.protocol.TProtocolUtil.skip(iprot, schemeField.type);
}
@@ -436,6 +521,11 @@ public class FtpCredentials implements org.apache.thrift.TBase<FtpCredentials, F
oprot.writeString(struct.password);
oprot.writeFieldEnd();
}
+ if (struct.filename != null) {
+ oprot.writeFieldBegin(FILENAME_FIELD_DESC);
+ oprot.writeString(struct.filename);
+ oprot.writeFieldEnd();
+ }
oprot.writeFieldStop();
oprot.writeStructEnd();
}
@@ -460,19 +550,25 @@ public class FtpCredentials implements org.apache.thrift.TBase<FtpCredentials, F
if (struct.isSetPassword()) {
optionals.set(1);
}
- oprot.writeBitSet(optionals, 2);
+ if (struct.isSetFilename()) {
+ optionals.set(2);
+ }
+ oprot.writeBitSet(optionals, 3);
if (struct.isSetUsername()) {
oprot.writeString(struct.username);
}
if (struct.isSetPassword()) {
oprot.writeString(struct.password);
}
+ if (struct.isSetFilename()) {
+ oprot.writeString(struct.filename);
+ }
}
@Override
public void read(org.apache.thrift.protocol.TProtocol prot, FtpCredentials struct) throws org.apache.thrift.TException {
TTupleProtocol iprot = (TTupleProtocol) prot;
- BitSet incoming = iprot.readBitSet(2);
+ BitSet incoming = iprot.readBitSet(3);
if (incoming.get(0)) {
struct.username = iprot.readString();
struct.setUsernameIsSet(true);
@@ -481,6 +577,10 @@ public class FtpCredentials implements org.apache.thrift.TBase<FtpCredentials, F
struct.password = iprot.readString();
struct.setPasswordIsSet(true);
}
+ if (incoming.get(2)) {
+ struct.filename = iprot.readString();
+ struct.setFilenameIsSet(true);
+ }
}
}
diff --git a/src/main/java/org/openslx/imagemaster/thrift/iface/ImageServer.java b/src/main/java/org/openslx/imagemaster/thrift/iface/ImageServer.java
index 6b863c3..004e8ae 100644
--- a/src/main/java/org/openslx/imagemaster/thrift/iface/ImageServer.java
+++ b/src/main/java/org/openslx/imagemaster/thrift/iface/ImageServer.java
@@ -48,7 +48,7 @@ public class ImageServer {
public FtpCredentials submitImage(String serverSessionId, ImageData imageDescription) throws AuthorizationException, ImageDataException, org.apache.thrift.TException;
- public boolean finshedUpload(String ftpUser, ImageData imageDescription) throws ImageDataException, org.apache.thrift.TException;
+ public boolean finishedUpload(String ftpUser, ImageData imageDescription) throws ImageDataException, org.apache.thrift.TException;
public FtpCredentials getImage(String uuid, String serverSessionId) throws AuthorizationException, ImageDataException, org.apache.thrift.TException;
@@ -70,7 +70,7 @@ public class ImageServer {
public void submitImage(String serverSessionId, ImageData imageDescription, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException;
- public void finshedUpload(String ftpUser, ImageData imageDescription, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException;
+ public void finishedUpload(String ftpUser, ImageData imageDescription, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException;
public void getImage(String uuid, String serverSessionId, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException;
@@ -256,31 +256,31 @@ public class ImageServer {
throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "submitImage failed: unknown result");
}
- public boolean finshedUpload(String ftpUser, ImageData imageDescription) throws ImageDataException, org.apache.thrift.TException
+ public boolean finishedUpload(String ftpUser, ImageData imageDescription) throws ImageDataException, org.apache.thrift.TException
{
- send_finshedUpload(ftpUser, imageDescription);
- return recv_finshedUpload();
+ send_finishedUpload(ftpUser, imageDescription);
+ return recv_finishedUpload();
}
- public void send_finshedUpload(String ftpUser, ImageData imageDescription) throws org.apache.thrift.TException
+ public void send_finishedUpload(String ftpUser, ImageData imageDescription) throws org.apache.thrift.TException
{
- finshedUpload_args args = new finshedUpload_args();
+ finishedUpload_args args = new finishedUpload_args();
args.setFtpUser(ftpUser);
args.setImageDescription(imageDescription);
- sendBase("finshedUpload", args);
+ sendBase("finishedUpload", args);
}
- public boolean recv_finshedUpload() throws ImageDataException, org.apache.thrift.TException
+ public boolean recv_finishedUpload() throws ImageDataException, org.apache.thrift.TException
{
- finshedUpload_result result = new finshedUpload_result();
- receiveBase(result, "finshedUpload");
+ finishedUpload_result result = new finishedUpload_result();
+ receiveBase(result, "finishedUpload");
if (result.isSetSuccess()) {
return result.success;
}
if (result.failure != null) {
throw result.failure;
}
- throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "finshedUpload failed: unknown result");
+ throw new org.apache.thrift.TApplicationException(org.apache.thrift.TApplicationException.MISSING_RESULT, "finishedUpload failed: unknown result");
}
public FtpCredentials getImage(String uuid, String serverSessionId) throws AuthorizationException, ImageDataException, org.apache.thrift.TException
@@ -552,25 +552,25 @@ public class ImageServer {
}
}
- public void finshedUpload(String ftpUser, ImageData imageDescription, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException {
+ public void finishedUpload(String ftpUser, ImageData imageDescription, org.apache.thrift.async.AsyncMethodCallback resultHandler) throws org.apache.thrift.TException {
checkReady();
- finshedUpload_call method_call = new finshedUpload_call(ftpUser, imageDescription, resultHandler, this, ___protocolFactory, ___transport);
+ finishedUpload_call method_call = new finishedUpload_call(ftpUser, imageDescription, resultHandler, this, ___protocolFactory, ___transport);
this.___currentMethod = method_call;
___manager.call(method_call);
}
- public static class finshedUpload_call extends org.apache.thrift.async.TAsyncMethodCall {
+ public static class finishedUpload_call extends org.apache.thrift.async.TAsyncMethodCall {
private String ftpUser;
private ImageData imageDescription;
- public finshedUpload_call(String ftpUser, ImageData imageDescription, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException {
+ public finishedUpload_call(String ftpUser, ImageData imageDescription, org.apache.thrift.async.AsyncMethodCallback resultHandler, org.apache.thrift.async.TAsyncClient client, org.apache.thrift.protocol.TProtocolFactory protocolFactory, org.apache.thrift.transport.TNonblockingTransport transport) throws org.apache.thrift.TException {
super(client, protocolFactory, transport, resultHandler, false);
this.ftpUser = ftpUser;
this.imageDescription = imageDescription;
}
public void write_args(org.apache.thrift.protocol.TProtocol prot) throws org.apache.thrift.TException {
- prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("finshedUpload", org.apache.thrift.protocol.TMessageType.CALL, 0));
- finshedUpload_args args = new finshedUpload_args();
+ prot.writeMessageBegin(new org.apache.thrift.protocol.TMessage("finishedUpload", org.apache.thrift.protocol.TMessageType.CALL, 0));
+ finishedUpload_args args = new finishedUpload_args();
args.setFtpUser(ftpUser);
args.setImageDescription(imageDescription);
args.write(prot);
@@ -583,7 +583,7 @@ public class ImageServer {
}
org.apache.thrift.transport.TMemoryInputTransport memoryTransport = new org.apache.thrift.transport.TMemoryInputTransport(getFrameBuffer().array());
org.apache.thrift.protocol.TProtocol prot = client.getProtocolFactory().getProtocol(memoryTransport);
- return (new Client(prot)).recv_finshedUpload();
+ return (new Client(prot)).recv_finishedUpload();
}
}
@@ -673,7 +673,7 @@ public class ImageServer {
processMap.put("startServerAuthentication", new startServerAuthentication());
processMap.put("serverAuthenticate", new serverAuthenticate());
processMap.put("submitImage", new submitImage());
- processMap.put("finshedUpload", new finshedUpload());
+ processMap.put("finishedUpload", new finishedUpload());
processMap.put("getImage", new getImage());
processMap.put("finishedDownload", new finishedDownload());
return processMap;
@@ -822,23 +822,23 @@ public class ImageServer {
}
}
- public static class finshedUpload<I extends Iface> extends org.apache.thrift.ProcessFunction<I, finshedUpload_args> {
- public finshedUpload() {
- super("finshedUpload");
+ public static class finishedUpload<I extends Iface> extends org.apache.thrift.ProcessFunction<I, finishedUpload_args> {
+ public finishedUpload() {
+ super("finishedUpload");
}
- public finshedUpload_args getEmptyArgsInstance() {
- return new finshedUpload_args();
+ public finishedUpload_args getEmptyArgsInstance() {
+ return new finishedUpload_args();
}
protected boolean isOneway() {
return false;
}
- public finshedUpload_result getResult(I iface, finshedUpload_args args) throws org.apache.thrift.TException {
- finshedUpload_result result = new finshedUpload_result();
+ public finishedUpload_result getResult(I iface, finishedUpload_args args) throws org.apache.thrift.TException {
+ finishedUpload_result result = new finishedUpload_result();
try {
- result.success = iface.finshedUpload(args.ftpUser, args.imageDescription);
+ result.success = iface.finishedUpload(args.ftpUser, args.imageDescription);
result.setSuccessIsSet(true);
} catch (ImageDataException failure) {
result.failure = failure;
@@ -913,7 +913,7 @@ public class ImageServer {
processMap.put("startServerAuthentication", new startServerAuthentication());
processMap.put("serverAuthenticate", new serverAuthenticate());
processMap.put("submitImage", new submitImage());
- processMap.put("finshedUpload", new finshedUpload());
+ processMap.put("finishedUpload", new finishedUpload());
processMap.put("getImage", new getImage());
processMap.put("finishedDownload", new finishedDownload());
return processMap;
@@ -1261,20 +1261,20 @@ public class ImageServer {
}
}
- public static class finshedUpload<I extends AsyncIface> extends org.apache.thrift.AsyncProcessFunction<I, finshedUpload_args, Boolean> {
- public finshedUpload() {
- super("finshedUpload");
+ public static class finishedUpload<I extends AsyncIface> extends org.apache.thrift.AsyncProcessFunction<I, finishedUpload_args, Boolean> {
+ public finishedUpload() {
+ super("finishedUpload");
}
- public finshedUpload_args getEmptyArgsInstance() {
- return new finshedUpload_args();
+ public finishedUpload_args getEmptyArgsInstance() {
+ return new finishedUpload_args();
}
public AsyncMethodCallback<Boolean> getResultHandler(final AsyncFrameBuffer fb, final int seqid) {
final org.apache.thrift.AsyncProcessFunction fcall = this;
return new AsyncMethodCallback<Boolean>() {
public void onComplete(Boolean o) {
- finshedUpload_result result = new finshedUpload_result();
+ finishedUpload_result result = new finishedUpload_result();
result.success = o;
result.setSuccessIsSet(true);
try {
@@ -1288,7 +1288,7 @@ public class ImageServer {
public void onError(Exception e) {
byte msgType = org.apache.thrift.protocol.TMessageType.REPLY;
org.apache.thrift.TBase msg;
- finshedUpload_result result = new finshedUpload_result();
+ finishedUpload_result result = new finishedUpload_result();
if (e instanceof ImageDataException) {
result.failure = (ImageDataException) e;
result.setFailureIsSet(true);
@@ -1314,8 +1314,8 @@ public class ImageServer {
return false;
}
- public void start(I iface, finshedUpload_args args, org.apache.thrift.async.AsyncMethodCallback<Boolean> resultHandler) throws TException {
- iface.finshedUpload(args.ftpUser, args.imageDescription,resultHandler);
+ public void start(I iface, finishedUpload_args args, org.apache.thrift.async.AsyncMethodCallback<Boolean> resultHandler) throws TException {
+ iface.finishedUpload(args.ftpUser, args.imageDescription,resultHandler);
}
}
@@ -6523,16 +6523,16 @@ public class ImageServer {
}
- public static class finshedUpload_args implements org.apache.thrift.TBase<finshedUpload_args, finshedUpload_args._Fields>, java.io.Serializable, Cloneable, Comparable<finshedUpload_args> {
- private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("finshedUpload_args");
+ public static class finishedUpload_args implements org.apache.thrift.TBase<finishedUpload_args, finishedUpload_args._Fields>, java.io.Serializable, Cloneable, Comparable<finishedUpload_args> {
+ private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("finishedUpload_args");
private static final org.apache.thrift.protocol.TField FTP_USER_FIELD_DESC = new org.apache.thrift.protocol.TField("ftpUser", org.apache.thrift.protocol.TType.STRING, (short)1);
private static final org.apache.thrift.protocol.TField IMAGE_DESCRIPTION_FIELD_DESC = new org.apache.thrift.protocol.TField("imageDescription", org.apache.thrift.protocol.TType.STRUCT, (short)2);
private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
static {
- schemes.put(StandardScheme.class, new finshedUpload_argsStandardSchemeFactory());
- schemes.put(TupleScheme.class, new finshedUpload_argsTupleSchemeFactory());
+ schemes.put(StandardScheme.class, new finishedUpload_argsStandardSchemeFactory());
+ schemes.put(TupleScheme.class, new finishedUpload_argsTupleSchemeFactory());
}
public String ftpUser; // required
@@ -6608,13 +6608,13 @@ public class ImageServer {
tmpMap.put(_Fields.IMAGE_DESCRIPTION, new org.apache.thrift.meta_data.FieldMetaData("imageDescription", org.apache.thrift.TFieldRequirementType.DEFAULT,
new org.apache.thrift.meta_data.StructMetaData(org.apache.thrift.protocol.TType.STRUCT, ImageData.class)));
metaDataMap = Collections.unmodifiableMap(tmpMap);
- org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(finshedUpload_args.class, metaDataMap);
+ org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(finishedUpload_args.class, metaDataMap);
}
- public finshedUpload_args() {
+ public finishedUpload_args() {
}
- public finshedUpload_args(
+ public finishedUpload_args(
String ftpUser,
ImageData imageDescription)
{
@@ -6626,7 +6626,7 @@ public class ImageServer {
/**
* Performs a deep copy on <i>other</i>.
*/
- public finshedUpload_args(finshedUpload_args other) {
+ public finishedUpload_args(finishedUpload_args other) {
if (other.isSetFtpUser()) {
this.ftpUser = other.ftpUser;
}
@@ -6635,8 +6635,8 @@ public class ImageServer {
}
}
- public finshedUpload_args deepCopy() {
- return new finshedUpload_args(this);
+ public finishedUpload_args deepCopy() {
+ return new finishedUpload_args(this);
}
@Override
@@ -6649,7 +6649,7 @@ public class ImageServer {
return this.ftpUser;
}
- public finshedUpload_args setFtpUser(String ftpUser) {
+ public finishedUpload_args setFtpUser(String ftpUser) {
this.ftpUser = ftpUser;
return this;
}
@@ -6673,7 +6673,7 @@ public class ImageServer {
return this.imageDescription;
}
- public finshedUpload_args setImageDescription(ImageData imageDescription) {
+ public finishedUpload_args setImageDescription(ImageData imageDescription) {
this.imageDescription = imageDescription;
return this;
}
@@ -6745,12 +6745,12 @@ public class ImageServer {
public boolean equals(Object that) {
if (that == null)
return false;
- if (that instanceof finshedUpload_args)
- return this.equals((finshedUpload_args)that);
+ if (that instanceof finishedUpload_args)
+ return this.equals((finishedUpload_args)that);
return false;
}
- public boolean equals(finshedUpload_args that) {
+ public boolean equals(finishedUpload_args that) {
if (that == null)
return false;
@@ -6781,7 +6781,7 @@ public class ImageServer {
}
@Override
- public int compareTo(finshedUpload_args other) {
+ public int compareTo(finishedUpload_args other) {
if (!getClass().equals(other.getClass())) {
return getClass().getName().compareTo(other.getClass().getName());
}
@@ -6825,7 +6825,7 @@ public class ImageServer {
@Override
public String toString() {
- StringBuilder sb = new StringBuilder("finshedUpload_args(");
+ StringBuilder sb = new StringBuilder("finishedUpload_args(");
boolean first = true;
sb.append("ftpUser:");
@@ -6871,15 +6871,15 @@ public class ImageServer {
}
}
- private static class finshedUpload_argsStandardSchemeFactory implements SchemeFactory {
- public finshedUpload_argsStandardScheme getScheme() {
- return new finshedUpload_argsStandardScheme();
+ private static class finishedUpload_argsStandardSchemeFactory implements SchemeFactory {
+ public finishedUpload_argsStandardScheme getScheme() {
+ return new finishedUpload_argsStandardScheme();
}
}
- private static class finshedUpload_argsStandardScheme extends StandardScheme<finshedUpload_args> {
+ private static class finishedUpload_argsStandardScheme extends StandardScheme<finishedUpload_args> {
- public void read(org.apache.thrift.protocol.TProtocol iprot, finshedUpload_args struct) throws org.apache.thrift.TException {
+ public void read(org.apache.thrift.protocol.TProtocol iprot, finishedUpload_args struct) throws org.apache.thrift.TException {
org.apache.thrift.protocol.TField schemeField;
iprot.readStructBegin();
while (true)
@@ -6917,7 +6917,7 @@ public class ImageServer {
struct.validate();
}
- public void write(org.apache.thrift.protocol.TProtocol oprot, finshedUpload_args struct) throws org.apache.thrift.TException {
+ public void write(org.apache.thrift.protocol.TProtocol oprot, finishedUpload_args struct) throws org.apache.thrift.TException {
struct.validate();
oprot.writeStructBegin(STRUCT_DESC);
@@ -6937,16 +6937,16 @@ public class ImageServer {
}
- private static class finshedUpload_argsTupleSchemeFactory implements SchemeFactory {
- public finshedUpload_argsTupleScheme getScheme() {
- return new finshedUpload_argsTupleScheme();
+ private static class finishedUpload_argsTupleSchemeFactory implements SchemeFactory {
+ public finishedUpload_argsTupleScheme getScheme() {
+ return new finishedUpload_argsTupleScheme();
}
}
- private static class finshedUpload_argsTupleScheme extends TupleScheme<finshedUpload_args> {
+ private static class finishedUpload_argsTupleScheme extends TupleScheme<finishedUpload_args> {
@Override
- public void write(org.apache.thrift.protocol.TProtocol prot, finshedUpload_args struct) throws org.apache.thrift.TException {
+ public void write(org.apache.thrift.protocol.TProtocol prot, finishedUpload_args struct) throws org.apache.thrift.TException {
TTupleProtocol oprot = (TTupleProtocol) prot;
BitSet optionals = new BitSet();
if (struct.isSetFtpUser()) {
@@ -6965,7 +6965,7 @@ public class ImageServer {
}
@Override
- public void read(org.apache.thrift.protocol.TProtocol prot, finshedUpload_args struct) throws org.apache.thrift.TException {
+ public void read(org.apache.thrift.protocol.TProtocol prot, finishedUpload_args struct) throws org.apache.thrift.TException {
TTupleProtocol iprot = (TTupleProtocol) prot;
BitSet incoming = iprot.readBitSet(2);
if (incoming.get(0)) {
@@ -6982,16 +6982,16 @@ public class ImageServer {
}
- public static class finshedUpload_result implements org.apache.thrift.TBase<finshedUpload_result, finshedUpload_result._Fields>, java.io.Serializable, Cloneable, Comparable<finshedUpload_result> {
- private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("finshedUpload_result");
+ public static class finishedUpload_result implements org.apache.thrift.TBase<finishedUpload_result, finishedUpload_result._Fields>, java.io.Serializable, Cloneable, Comparable<finishedUpload_result> {
+ private static final org.apache.thrift.protocol.TStruct STRUCT_DESC = new org.apache.thrift.protocol.TStruct("finishedUpload_result");
private static final org.apache.thrift.protocol.TField SUCCESS_FIELD_DESC = new org.apache.thrift.protocol.TField("success", org.apache.thrift.protocol.TType.BOOL, (short)0);
private static final org.apache.thrift.protocol.TField FAILURE_FIELD_DESC = new org.apache.thrift.protocol.TField("failure", org.apache.thrift.protocol.TType.STRUCT, (short)1);
private static final Map<Class<? extends IScheme>, SchemeFactory> schemes = new HashMap<Class<? extends IScheme>, SchemeFactory>();
static {
- schemes.put(StandardScheme.class, new finshedUpload_resultStandardSchemeFactory());
- schemes.put(TupleScheme.class, new finshedUpload_resultTupleSchemeFactory());
+ schemes.put(StandardScheme.class, new finishedUpload_resultStandardSchemeFactory());
+ schemes.put(TupleScheme.class, new finishedUpload_resultTupleSchemeFactory());
}
public boolean success; // required
@@ -7069,13 +7069,13 @@ public class ImageServer {
tmpMap.put(_Fields.FAILURE, new org.apache.thrift.meta_data.FieldMetaData("failure", org.apache.thrift.TFieldRequirementType.DEFAULT,
new org.apache.thrift.meta_data.FieldValueMetaData(org.apache.thrift.protocol.TType.STRUCT)));
metaDataMap = Collections.unmodifiableMap(tmpMap);
- org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(finshedUpload_result.class, metaDataMap);
+ org.apache.thrift.meta_data.FieldMetaData.addStructMetaDataMap(finishedUpload_result.class, metaDataMap);
}
- public finshedUpload_result() {
+ public finishedUpload_result() {
}
- public finshedUpload_result(
+ public finishedUpload_result(
boolean success,
ImageDataException failure)
{
@@ -7088,7 +7088,7 @@ public class ImageServer {
/**
* Performs a deep copy on <i>other</i>.
*/
- public finshedUpload_result(finshedUpload_result other) {
+ public finishedUpload_result(finishedUpload_result other) {
__isset_bitfield = other.__isset_bitfield;
this.success = other.success;
if (other.isSetFailure()) {
@@ -7096,8 +7096,8 @@ public class ImageServer {
}
}
- public finshedUpload_result deepCopy() {
- return new finshedUpload_result(this);
+ public finishedUpload_result deepCopy() {
+ return new finishedUpload_result(this);
}
@Override
@@ -7111,7 +7111,7 @@ public class ImageServer {
return this.success;
}
- public finshedUpload_result setSuccess(boolean success) {
+ public finishedUpload_result setSuccess(boolean success) {
this.success = success;
setSuccessIsSet(true);
return this;
@@ -7134,7 +7134,7 @@ public class ImageServer {
return this.failure;
}
- public finshedUpload_result setFailure(ImageDataException failure) {
+ public finishedUpload_result setFailure(ImageDataException failure) {
this.failure = failure;
return this;
}
@@ -7206,12 +7206,12 @@ public class ImageServer {
public boolean equals(Object that) {
if (that == null)
return false;
- if (that instanceof finshedUpload_result)
- return this.equals((finshedUpload_result)that);
+ if (that instanceof finishedUpload_result)
+ return this.equals((finishedUpload_result)that);
return false;
}
- public boolean equals(finshedUpload_result that) {
+ public boolean equals(finishedUpload_result that) {
if (that == null)
return false;
@@ -7242,7 +7242,7 @@ public class ImageServer {
}
@Override
- public int compareTo(finshedUpload_result other) {
+ public int compareTo(finishedUpload_result other) {
if (!getClass().equals(other.getClass())) {
return getClass().getName().compareTo(other.getClass().getName());
}
@@ -7286,7 +7286,7 @@ public class ImageServer {
@Override
public String toString() {
- StringBuilder sb = new StringBuilder("finshedUpload_result(");
+ StringBuilder sb = new StringBuilder("finishedUpload_result(");
boolean first = true;
sb.append("success:");
@@ -7327,15 +7327,15 @@ public class ImageServer {
}
}
- private static class finshedUpload_resultStandardSchemeFactory implements SchemeFactory {
- public finshedUpload_resultStandardScheme getScheme() {
- return new finshedUpload_resultStandardScheme();
+ private static class finishedUpload_resultStandardSchemeFactory implements SchemeFactory {
+ public finishedUpload_resultStandardScheme getScheme() {
+ return new finishedUpload_resultStandardScheme();
}
}
- private static class finshedUpload_resultStandardScheme extends StandardScheme<finshedUpload_result> {
+ private static class finishedUpload_resultStandardScheme extends StandardScheme<finishedUpload_result> {
- public void read(org.apache.thrift.protocol.TProtocol iprot, finshedUpload_result struct) throws org.apache.thrift.TException {
+ public void read(org.apache.thrift.protocol.TProtocol iprot, finishedUpload_result struct) throws org.apache.thrift.TException {
org.apache.thrift.protocol.TField schemeField;
iprot.readStructBegin();
while (true)
@@ -7373,7 +7373,7 @@ public class ImageServer {
struct.validate();
}
- public void write(org.apache.thrift.protocol.TProtocol oprot, finshedUpload_result struct) throws org.apache.thrift.TException {
+ public void write(org.apache.thrift.protocol.TProtocol oprot, finishedUpload_result struct) throws org.apache.thrift.TException {
struct.validate();
oprot.writeStructBegin(STRUCT_DESC);
@@ -7393,16 +7393,16 @@ public class ImageServer {
}
- private static class finshedUpload_resultTupleSchemeFactory implements SchemeFactory {
- public finshedUpload_resultTupleScheme getScheme() {
- return new finshedUpload_resultTupleScheme();
+ private static class finishedUpload_resultTupleSchemeFactory implements SchemeFactory {
+ public finishedUpload_resultTupleScheme getScheme() {
+ return new finishedUpload_resultTupleScheme();
}
}
- private static class finshedUpload_resultTupleScheme extends TupleScheme<finshedUpload_result> {
+ private static class finishedUpload_resultTupleScheme extends TupleScheme<finishedUpload_result> {
@Override
- public void write(org.apache.thrift.protocol.TProtocol prot, finshedUpload_result struct) throws org.apache.thrift.TException {
+ public void write(org.apache.thrift.protocol.TProtocol prot, finishedUpload_result struct) throws org.apache.thrift.TException {
TTupleProtocol oprot = (TTupleProtocol) prot;
BitSet optionals = new BitSet();
if (struct.isSetSuccess()) {
@@ -7421,7 +7421,7 @@ public class ImageServer {
}
@Override
- public void read(org.apache.thrift.protocol.TProtocol prot, finshedUpload_result struct) throws org.apache.thrift.TException {
+ public void read(org.apache.thrift.protocol.TProtocol prot, finishedUpload_result struct) throws org.apache.thrift.TException {
TTupleProtocol iprot = (TTupleProtocol) prot;
BitSet incoming = iprot.readBitSet(2);
if (incoming.get(0)) {
diff --git a/src/main/java/org/openslx/satellitedaemon/App.java b/src/main/java/org/openslx/satellitedaemon/App.java
index 30382db..7210c47 100644
--- a/src/main/java/org/openslx/satellitedaemon/App.java
+++ b/src/main/java/org/openslx/satellitedaemon/App.java
@@ -12,6 +12,7 @@ import java.security.cert.CertificateException;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Logger;
import org.openslx.imagemaster.thrift.iface.ServerAuthenticationException;
+import org.openslx.satellitedaemon.ftp.FtpDownloadWorker;
import org.openslx.satellitedaemon.ftp.FtpUploadWorker;
/**
@@ -39,5 +40,7 @@ public class App
}
Thread uploadWorker = new Thread( new FtpUploadWorker() );
uploadWorker.start();
+ Thread downloadWorker = new Thread( new FtpDownloadWorker() );
+ downloadWorker.start();
}
}
diff --git a/src/main/java/org/openslx/satellitedaemon/db/DbImage.java b/src/main/java/org/openslx/satellitedaemon/db/DbImage.java
index 0ed8efd..5169173 100644
--- a/src/main/java/org/openslx/satellitedaemon/db/DbImage.java
+++ b/src/main/java/org/openslx/satellitedaemon/db/DbImage.java
@@ -44,5 +44,16 @@ public class DbImage
" INNER JOIN m_institution institution ON (institution.institutionID = user.institution)" +
" WHERE image_syncMode = 'to_be_published'" );
}
+
+
+ public static List<DbImage> getAllMarkedForDownload()
+ {
+ return MySQL.findAll( DbImage.class, "SELECT image.GUID_imageID, image.image_name, image.imageVersion, image.image_path," +
+ " Concat(user.loginName, '@', institution.name) AS userID, image.image_filesize" +
+ " FROM m_VLData_imageInfo image" +
+ " INNER JOIN m_user user ON (image.image_owner = user.userID)" +
+ " INNER JOIN m_institution institution ON (institution.institutionID = user.institution)" +
+ " WHERE image_syncMode = 'to_be_decentralized'" );
+ }
}
diff --git a/src/main/java/org/openslx/satellitedaemon/ftp/FtpDownloadWorker.java b/src/main/java/org/openslx/satellitedaemon/ftp/FtpDownloadWorker.java
new file mode 100644
index 0000000..bcf217f
--- /dev/null
+++ b/src/main/java/org/openslx/satellitedaemon/ftp/FtpDownloadWorker.java
@@ -0,0 +1,93 @@
+package org.openslx.satellitedaemon.ftp;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.KeyStore;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.cert.CertificateException;
+import java.util.List;
+
+import javax.net.ssl.KeyManagerFactory;
+import javax.net.ssl.TrustManager;
+import javax.net.ssl.TrustManagerFactory;
+
+import org.apache.commons.net.ftp.FTP;
+import org.apache.commons.net.ftp.FTPSClient;
+import org.apache.log4j.Logger;
+import org.openslx.imagemaster.thrift.iface.FtpCredentials;
+import org.openslx.satellitedaemon.Globals;
+import org.openslx.satellitedaemon.Globals.PropInt;
+import org.openslx.satellitedaemon.Globals.PropString;
+import org.openslx.satellitedaemon.db.DbImage;
+
+public class FtpDownloadWorker implements Runnable
+{
+ private static Logger log = Logger.getLogger( FtpUploadWorker.class );
+
+ @Override
+ public void run()
+ {
+ while ( true ) {
+ List<DbImage> imageList = DbImage.getAllMarkedForDownload();
+ log.info( "FtpDownloadWorker: imageList Contains " + imageList.size() + " items." );
+ for ( DbImage image : imageList ) {
+
+ FtpCredentials ftpc = ThriftConnection.getFtpCredentials( image.guid );
+ if ( ftpc == null ) {
+ log.error( "The FtpCredentials are null" );
+ }
+
+ try {
+ TrustManagerFactory trustManagerFactory = TrustManagerFactory
+ .getInstance( KeyManagerFactory.getDefaultAlgorithm() );
+ KeyStore keystore = KeyStore.getInstance( Globals.getPropertyString( PropString.KEYSTORETYPE ) );
+ keystore.load( new FileInputStream( new File(
+ Globals.getPropertyString( PropString.FTPSKEYSTOREPATH ) ) ),
+ Globals.getPropertyString( PropString.FTPSKEYSTOREPWD ).toCharArray() );
+ trustManagerFactory.init( keystore );
+ TrustManager trustManager = trustManagerFactory.getTrustManagers()[0];
+ FTPSClient ftpClient = new FTPSClient( "SSL", true );
+ ftpClient.setTrustManager( trustManager );
+ try {
+ ftpClient.connect( Globals.getPropertyString( PropString.FTPSERVERIP ), Globals.getPropertyInt( PropInt.FTPPORT ) );
+ if ( !ftpClient.login( ftpc.username, ftpc.password ) ) {
+ log.error( "FTP problem. Coundn't log in!" );
+ }
+ File file = new File( "/tmp/" + image.guid + ".vmdk");
+ ftpClient.setFileType( FTP.BINARY_FILE_TYPE );
+ log.info( "FtpDownloadWorker: ftpc.filename: " + ftpc.filename );
+ InputStream is = ftpClient.retrieveFileStream( ftpc.filename );
+ FileOutputStream fos = new FileOutputStream( file );
+ int b;
+ while ((b = is.read()) != -1) {
+ fos.write( b );
+ }
+ is.close();
+ fos.close();
+ ThriftConnection.finishedDownload( ftpc.username);
+
+ } catch (IOException e) {
+ log.error("FtpDownloadWorker: Error creating the FileInputStream");
+ }
+ finally {
+ ftpClient.disconnect();
+ log.info( "FtpDownloadWorker: ftpClient disconnected" );
+ }
+ } catch ( NoSuchAlgorithmException | KeyStoreException | CertificateException | IOException e ) {
+ log.debug( "FtpDownloadWorker: Problem with Keystore ore FtpsClient creation." );
+ }
+ }
+ try {
+ Thread.sleep( 5 * 60 * 1000 );
+ } catch ( InterruptedException e ) {
+ log.error( "FtpUploadWorker: Sleep interrupted" );
+ e.printStackTrace();
+ }
+ }
+
+ }
+}
diff --git a/src/main/java/org/openslx/satellitedaemon/ftp/ThriftConnection.java b/src/main/java/org/openslx/satellitedaemon/ftp/ThriftConnection.java
index a2c990f..251e2b3 100644
--- a/src/main/java/org/openslx/satellitedaemon/ftp/ThriftConnection.java
+++ b/src/main/java/org/openslx/satellitedaemon/ftp/ThriftConnection.java
@@ -84,6 +84,54 @@ public class ThriftConnection
}
return null;
}
+
+ /**
+ * The method calls getConnection() to check if the connection is ok
+ * and to get the ServerSessionData. If connection is ok, it returns ftpCredential.
+ *
+ * @return returns 'null' if there is a problem.
+ */
+ public static FtpCredentials getFtpCredentials( String uUID )
+ {
+ ImageServer.Client theClient = null;
+ try {
+ theClient = getConnection();
+ if ( theClient == null ) {
+ log.error( "Client was null!" );
+ return null;
+ }
+
+ return theClient.getImage( uUID, sSD.sessionId );
+ } catch ( TException e ) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch ( UnrecoverableKeyException e ) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch ( InvalidKeyException e ) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch ( NoSuchAlgorithmException e ) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch ( CertificateException e ) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch ( FileNotFoundException e ) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch ( KeyStoreException e ) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch ( SignatureException e ) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch ( IOException e ) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return null;
+ }
/**
* This method checks if there is already a working connection. If not,
@@ -170,7 +218,19 @@ public class ThriftConnection
public static void finishedUpload(String ftpUser, ImageData imageDescription) {
try {
- client.finshedUpload( ftpUser, imageDescription );
+ client.finishedUpload( ftpUser, imageDescription );
+ } catch ( ImageDataException e ) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } catch ( TException e ) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+
+ public static void finishedDownload(String ftpUser) {
+ try {
+ client.finishedDownload( ftpUser );
} catch ( ImageDataException e ) {
// TODO Auto-generated catch block
e.printStackTrace();