001    /**
002     * 
003     */
004    package de.jw.cloud42.core.domain;
005    
006    import java.util.Calendar;
007    
008    
009    
010    /**
011     * 
012     * Combines information contained in a ReservatioDescription and in a ReservatioDescription.Instance
013     * within one class.
014     * 
015     * Wrapper around ReservationDescription.Instance of the Typica library since Axis2 does not recognize
016     * nested types.
017     * Only for use within the web service and the web application layer.
018     * 
019     * @author fbitzer
020     *
021     */
022    public class Instance {
023            
024            
025    
026            private String imageId;
027        private String instanceId;
028        private String privateDnsName;
029        private String dnsName;
030        private String reason;
031        private String keyName;
032        //private InstanceType instanceType;
033        
034        /**
035         * use String representation because of problems with Axis
036         */
037        private String instanceType;
038        private Calendar launchTime;
039        private String availabilityZone;
040        private String kernelId;
041        private String ramdiskId;
042        /**
043         * An EC2 instance may be in one of four states:
044         * <ol>
045         * <li><b>pending</b> - the instance is in the process of being
046         * launched.</li>
047         * <li><b>running</b> - the has been launched. It may be in the
048         * process of booting and is not yet guaranteed to be reachable.</li>
049         * <li><b>shutting-down</b> - the instance is in the process of
050         * shutting down.</li>
051         * <li><b>terminated</b> - the instance is no longer running.</li>
052         * </ol>
053         */
054        private String state;
055        private int stateCode;
056        
057        
058        //properties from ReservationDescription
059        //the groups of this instance
060        private String[] groups;
061        
062        private String reservationId;
063        private String owner;
064    
065        public String getReservationId() {
066                    return reservationId;
067            }
068    
069            public String getOwner() {
070                    return owner;
071            }
072    
073            public String[] getGroups() {
074                    return groups;
075            }
076    
077            /**
078         * Set member variables in constructur.
079         * @param resDescr The "original" ReservationDescription of the instance that is wrapped.
080         * @param instanceIndex index of the instance within the ReservationDescription (usually 0,
081         * but may be >0 if more than one instances are contained within one ReservationDescription)
082         */
083        public Instance(com.xerox.amazonws.ec2.ReservationDescription resDescr, int instanceIndex) {
084            com.xerox.amazonws.ec2.ReservationDescription.Instance instance =
085                    resDescr.getInstances().get(instanceIndex);    
086            
087            this.groups = resDescr.getGroups().toArray(new String[0]);
088            
089            this.owner = resDescr.getOwner();
090            this.reservationId=resDescr.getReservationId();
091            
092            this.imageId = instance.getImageId();
093            this.instanceId = instance.getInstanceId();
094            this.privateDnsName = instance.getPrivateDnsName();
095            this.dnsName = instance.getDnsName();
096            this.state = instance.getState();
097            this.stateCode = instance.getStateCode();
098            this.reason = instance.getReason();
099            this.keyName = instance.getKeyName();
100            this.instanceType = instance.getInstanceType().getTypeId();
101            this.launchTime = instance.getLaunchTime();
102            this.availabilityZone = instance.getAvailabilityZone();
103            this.kernelId = instance.getKernelId();
104            this.ramdiskId = instance.getRamdiskId();
105                
106                
107        }
108    
109        public String getImageId() {
110                return imageId;
111        }
112    
113        public String getInstanceId() {
114                return instanceId;
115        }
116    
117        public String getPrivateDnsName() {
118                return privateDnsName;
119        }
120    
121        public String getDnsName() {
122                return dnsName;
123        }
124    
125        public String getReason() {
126                return reason;
127        }
128    
129        public String getKeyName() {
130                return keyName;
131        }
132    
133        public String getState() {
134                return state;
135        }
136    
137        public boolean isRunning() {
138                return this.state.equals("running");
139        }
140    
141        public boolean isPending() {
142                return this.state.equals("pending");
143        }
144    
145        public boolean isShuttingDown() {
146                return this.state.equals("shutting-down");
147        }
148    
149        public boolean isTerminated() {
150                return this.state.equals("terminated");
151        }
152    
153        public int getStateCode() {
154                return stateCode;
155        }
156    
157        public String getInstanceType() {
158                return this.instanceType;
159        }
160    
161        public Calendar getLaunchTime() {
162                return this.launchTime;
163        }
164    
165        public String getAvailabilityZone() {
166                return availabilityZone;
167        }
168    
169        public String getKernelId() {
170                return kernelId;
171        }
172    
173        public String getRamdiskId() {
174                return ramdiskId;
175        }
176    
177        public String toString() {
178                return "[img=" + this.imageId + ", instance=" + this.instanceId
179                                + ", privateDns=" + this.privateDnsName
180                                + ", dns=" + this.dnsName + ", loc=" + ", state="
181                                + this.state + "(" + this.stateCode + ") reason="
182                                + this.reason + "]";
183        }
184    
185    //    public Instance getInstance(){
186    //      return instance;
187    //    }
188            
189            
190    }