001    /**
002     * 
003     */
004    package de.jw.cloud42.webapp;
005    
006    import java.util.logging.Logger;
007    
008    import de.jw.cloud42.core.domain.AwsCredentials;
009    import de.jw.cloud42.core.domain.RemoteResult;
010    import de.jw.cloud42.core.remoting.RemoteControl;
011    
012    /**
013     * Thread class, handles bundling a new AMI as background task.
014     * 
015     * @author fbitzer
016     * 
017     */
018    public class BundlingThread extends Thread {
019    
020            // member variables containing the required information for bundling an AMI
021            private String dnsName;
022            private String privateKey;
023            private AwsCredentials credentials;
024            private String bucket;
025            private String imageName;
026            private boolean use64Bit;
027            private boolean doNotify;
028            private String messageTopic;
029            private String messageText;
030            private String messageInfo;
031            private byte[] privateKeyFile;
032            private byte[] certFile;
033    
034            /**
035             * Holds the result of the bundling process
036             */
037            private RemoteResult result;
038    
039            /**
040             * Construktor, gathers required information at startup.
041             * @param dnsName
042             * @param privateKey
043             * @param credentials
044             * @param bucket
045             * @param imageName
046             * @param use64Bit
047             * @param doNotify
048             * @param messageTopic
049             * @param messageText
050             * @param messageInfo
051             * @param privateKeyFile
052             * @param certFile
053             */
054            public BundlingThread(String dnsName, String privateKey,
055                            AwsCredentials credentials, String bucket, String imageName,
056                            boolean use64Bit, boolean doNotify, String messageTopic,
057                            String messageText, String messageInfo, byte[] privateKeyFile,
058                            byte[] certFile) {
059    
060                    this.dnsName = dnsName;
061                    this.privateKey = privateKey;
062                    this.credentials = credentials;
063    
064                    this.bucket = bucket;
065                    this.imageName = imageName;
066    
067                    this.use64Bit = use64Bit;
068                    this.doNotify = doNotify;
069    
070                    this.messageTopic = messageTopic;
071                    this.messageText = messageText;
072                    this.messageInfo = messageInfo;
073    
074                    this.privateKeyFile = privateKeyFile;
075    
076                    this.certFile = certFile;
077    
078            }
079    
080            /**
081             * This is the thread function that is invoked with Thread.start().
082             * It starts bundling by invoking the <code>RemoteControl</code> class.
083             */
084            public void run() {
085    
086                    Logger.getAnonymousLogger().info(
087                                    "Bundling thread started for AMI at " + dnsName);
088    
089                    RemoteControl c = new RemoteControl();
090    
091                    result = c.bundleImage(dnsName, privateKey, credentials, bucket,
092                                    imageName, use64Bit, doNotify, messageTopic, messageText,
093                                    messageInfo, privateKeyFile, certFile);
094    
095                    Logger.getAnonymousLogger().info(
096                                    "Bundling thread completed for AMI at " + dnsName);
097    
098            }
099    
100            /**
101             * Getter for the result of the bundling process.
102             * @return
103             */
104            public RemoteResult getResult() {
105                    return result;
106            }
107    
108    }