001 /**
002 *
003 */
004 package de.jw.cloud42.webapp;
005
006 import java.io.File;
007 import java.io.FileInputStream;
008 import java.io.IOException;
009 import java.io.InputStream;
010 import java.util.List;
011 import java.util.logging.Logger;
012
013 import org.jboss.seam.ScopeType;
014 import org.jboss.seam.annotations.Name;
015 import org.jboss.seam.annotations.Scope;
016 import org.richfaces.event.UploadEvent;
017
018 import de.jw.cloud42.webapp.utils.FileUtils;
019
020
021
022 /**
023 *
024 * Backing bean for instance configuration dialog. Holds values entered in the UI and is
025 * injected into the BaseFunctionsManager when a new instance is launched.
026 *
027 * @author fbitzer
028 *
029 */
030 @Name("instanceConfiguration")
031 @Scope(ScopeType.SESSION)
032 public class InstanceConfiguration{
033
034 private String imageId;
035
036 private String type;
037
038 private String name;
039
040 private String keypairName;
041
042
043 private String userData;
044
045 private byte[] attachedFile;
046
047 private List<String> groupNames;
048
049
050 private String availabilityZone;
051 private String kernelId;
052 private String ramdiskId;
053
054
055 private String imageLocation;
056
057
058 /**
059 * @return the imageLocation
060 */
061 public String getImageLocation() {
062 return imageLocation;
063 }
064
065 /**
066 * @param imageLocation the imageLocation to set
067 */
068 public void setImageLocation(String imageLocation) {
069 this.imageLocation = imageLocation;
070 }
071
072 /**
073 * @return the userData
074 */
075 public String getUserData() {
076 return userData;
077 }
078
079 /**
080 * @param userData the userData to set
081 */
082 public void setUserData(String userData) {
083 this.userData = userData;
084 }
085
086 /**
087 * @return the groupNames
088 */
089 public List<String> getGroupNames() {
090 return groupNames;
091 }
092
093 /**
094 * @param groupNames the groupNames to set
095 */
096 public void setGroupNames(List<String> groupNames) {
097 this.groupNames = groupNames;
098 }
099
100 /**
101 * @param keypairName the keypairName to set
102 */
103 public void setKeypairName(String keypairName) {
104 this.keypairName = keypairName;
105 }
106
107 /**
108 * @return the instanceType
109 */
110 public String getType() {
111 return type;
112 }
113
114 /**
115 * @param instanceType the instanceType to set
116 */
117 public void setType(String instanceType) {
118 this.type = instanceType;
119 }
120
121 /**
122 * @return the instanceName
123 */
124 public String getName() {
125 return name;
126 }
127
128 /**
129 * @param instanceName the instanceName to set
130 */
131 public void setName(String instanceName) {
132 this.name = instanceName;
133 }
134
135 /**
136 * @return the imageId
137 */
138 public String getImageId() {
139 return imageId;
140 }
141
142 /**
143 * @param imageId the imageId to set
144 */
145 public void setImageId(String imageId) {
146 this.imageId = imageId;
147 }
148
149 /**
150 * @return the keypair
151 */
152 public String getKeypairName() {
153 return keypairName;
154 }
155
156 /**
157 * @return the availabilityZone
158 */
159 public String getAvailabilityZone() {
160 return availabilityZone;
161 }
162
163 /**
164 * @param availabilityZone the availabilityZone to set
165 */
166 public void setAvailabilityZone(String availabilityZone) {
167 this.availabilityZone = availabilityZone;
168 }
169
170 /**
171 * @return the kernelId
172 */
173 public String getKernelId() {
174 return kernelId;
175 }
176
177 /**
178 * @param kernelId the kernelId to set
179 */
180 public void setKernelId(String kernelId) {
181 this.kernelId = kernelId;
182 }
183
184 /**
185 * @return the ramdiskId
186 */
187 public String getRamdiskId() {
188 return ramdiskId;
189 }
190
191 /**
192 * @param ramdiskId the ramdiskId to set
193 */
194 public void setRamdiskId(String ramdiskId) {
195 this.ramdiskId = ramdiskId;
196 }
197
198 /**
199 * @return the attachedFile
200 */
201 public byte[] getAttachedFile() {
202 return attachedFile;
203 }
204
205 /**
206 * @param attachedFile the attachedFile to set
207 */
208 public void setAttachedFile(byte[] attachedFile) {
209 this.attachedFile = attachedFile;
210 }
211
212
213
214
215
216 /**
217 * fileUploadListener function for RichFaces fileupload component.
218 * Reads the content of the uploaded file into a byte array and stores it in the
219 * <code>attachedFile</code> property.
220 * @param e
221 */
222 public void fileUploadListener(UploadEvent e){
223
224
225 try {
226
227 File f = e.getUploadItem().getFile();
228
229 this.attachedFile = FileUtils.getBytesFromFile(f);
230
231
232 e.getUploadItem().getFile().delete();
233 }
234 catch (Exception ex) {
235 Logger.getAnonymousLogger().warning("Attaching file failed: " + ex.getMessage());
236 }
237 }
238
239 }