~ubuntu-branches/ubuntu/raring/eucalyptus/raring

« back to all changes in this revision

Viewing changes to clc/modules/core/src/main/java/edu/ucsb/eucalyptus/cloud/entities/StorageInfo.java

  • Committer: Package Import Robot
  • Author(s): Brian Thomason
  • Date: 2011-11-29 13:17:52 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 185.
  • Revision ID: package-import@ubuntu.com-20111129131752-rq31al3ntutv2vvl
Tags: upstream-3.0.999beta1
Import upstream version 3.0.999beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
 *    SOFTWARE, AND IF ANY SUCH MATERIAL IS DISCOVERED THE PARTY DISCOVERING
54
54
 *    IT MAY INFORM DR. RICH WOLSKI AT THE UNIVERSITY OF CALIFORNIA, SANTA
55
55
 *    BARBARA WHO WILL THEN ASCERTAIN THE MOST APPROPRIATE REMEDY, WHICH IN
56
 
 *    THE REGENTS’ DISCRETION MAY INCLUDE, WITHOUT LIMITATION, REPLACEMENT
 
56
 *    THE REGENTS' DISCRETION MAY INCLUDE, WITHOUT LIMITATION, REPLACEMENT
57
57
 *    OF THE CODE SO IDENTIFIED, LICENSING OF THE CODE SO IDENTIFIED, OR
58
58
 *    WITHDRAWAL OF THE CODE CAPABILITY TO THE EXTENT NEEDED TO COMPLY WITH
59
59
 *    ANY SUCH LICENSES OR RIGHTS.
63
63
 */
64
64
package edu.ucsb.eucalyptus.cloud.entities;
65
65
 
 
66
import javax.persistence.Column;
 
67
import org.hibernate.annotations.Entity;
 
68
import javax.persistence.GeneratedValue;
 
69
import javax.persistence.Id;
 
70
import javax.persistence.PersistenceContext;
 
71
import javax.persistence.Table;
66
72
import org.apache.log4j.Logger;
67
73
import org.hibernate.annotations.Cache;
68
74
import org.hibernate.annotations.CacheConcurrencyStrategy;
69
 
 
70
75
import com.eucalyptus.configurable.ConfigurableClass;
71
76
import com.eucalyptus.configurable.ConfigurableField;
72
77
import com.eucalyptus.configurable.ConfigurableFieldType;
73
78
import com.eucalyptus.configurable.ConfigurableIdentifier;
 
79
import com.eucalyptus.entities.AbstractPersistent;
74
80
import com.eucalyptus.entities.EntityWrapper;
75
81
import com.eucalyptus.util.EucalyptusCloudException;
76
82
import com.eucalyptus.util.StorageProperties;
77
83
 
78
 
import javax.persistence.*;
79
 
 
80
 
@Entity
 
84
@Entity @javax.persistence.Entity
81
85
@PersistenceContext(name="eucalyptus_storage")
82
86
@Table( name = "storage_info" )
83
 
@Cache( usage = CacheConcurrencyStrategy.READ_WRITE )
 
87
@Cache( usage = CacheConcurrencyStrategy.TRANSACTIONAL )
84
88
@ConfigurableClass(root = "storage", alias="basic", description = "Basic storage controller configuration.", singleton=false, deferred = true)
85
 
public class
86
 
StorageInfo {
 
89
public class StorageInfo extends AbstractPersistent {
87
90
        private static Logger LOG = Logger.getLogger( StorageInfo.class );
88
91
 
89
 
        @Id
90
 
        @GeneratedValue
91
 
        @Column( name = "storage_id" )
92
 
        private Long id = -1l;
93
92
        @ConfigurableIdentifier
94
93
        @Column( name = "storage_name", unique=true)
95
94
        private String name;
99
98
        @ConfigurableField( description = "Max volume size", displayName = "Max volume size" )
100
99
        @Column( name = "system_storage_max_volume_size_gb")
101
100
        private Integer maxVolumeSizeInGB;
 
101
        @ConfigurableField( description = "Should transfer snapshots", displayName = "Transfer snapshots to Walrus", type = ConfigurableFieldType.BOOLEAN )
 
102
        @Column( name = "system_storage_transfer_snapshots")
 
103
        private Boolean shouldTransferSnapshots;
102
104
 
103
 
        public StorageInfo(){
 
105
        public StorageInfo() {
104
106
                this.name = StorageProperties.NAME;
105
107
        }
106
108
 
111
113
 
112
114
        public StorageInfo(final String name, 
113
115
                        final Integer maxTotalVolumeSizeInGb,
114
 
                        final Integer maxVolumeSizeInGB) {
 
116
                        final Integer maxVolumeSizeInGB,
 
117
                        final Boolean shouldTransferSnapshots) {
115
118
                this.name = name;
116
119
                this.maxTotalVolumeSizeInGb = maxTotalVolumeSizeInGb;
117
120
                this.maxVolumeSizeInGB = maxVolumeSizeInGB;
118
 
        }
119
 
 
120
 
        public Long getId()
121
 
        {
122
 
                return id;
 
121
                this.shouldTransferSnapshots = shouldTransferSnapshots;
123
122
        }
124
123
 
125
124
        public String getName() {
146
145
                this.maxVolumeSizeInGB = maxVolumeSizeInGB;
147
146
        }
148
147
 
 
148
        public Boolean getShouldTransferSnapshots() {
 
149
                return shouldTransferSnapshots;
 
150
        }
 
151
 
 
152
        public void setShouldTransferSnapshots(Boolean shouldTransferSnapshots) {
 
153
                this.shouldTransferSnapshots = shouldTransferSnapshots;
 
154
        }
 
155
 
149
156
        @Override
150
157
        public boolean equals(Object obj) {
151
158
                if (this == obj)
178
185
        }
179
186
 
180
187
        public static StorageInfo getStorageInfo() {
181
 
                EntityWrapper<StorageInfo> storageDb = new EntityWrapper<StorageInfo>(StorageProperties.DB_NAME);
 
188
                EntityWrapper<StorageInfo> storageDb = EntityWrapper.get(StorageInfo.class);
182
189
                StorageInfo conf = null;
183
190
                try {
184
191
                        conf = storageDb.getUnique(new StorageInfo(StorageProperties.NAME));
188
195
                        LOG.warn("Failed to get storage info for: " + StorageProperties.NAME + ". Loading defaults.");
189
196
                        conf =  new StorageInfo(StorageProperties.NAME, 
190
197
                                        StorageProperties.MAX_TOTAL_VOLUME_SIZE, 
191
 
                                        StorageProperties.MAX_VOLUME_SIZE);
 
198
                                        StorageProperties.MAX_VOLUME_SIZE,
 
199
                                        true);
192
200
                        storageDb.add(conf);
193
201
                        storageDb.commit();
194
202
                }
195
 
                catch (Throwable t) {
 
203
                catch (Exception t) {
196
204
                        LOG.error("Unable to get storage info for: " + StorageProperties.NAME);
197
205
                        storageDb.rollback();
198
206
                        return new StorageInfo(StorageProperties.NAME, 
199
207
                                        StorageProperties.MAX_TOTAL_VOLUME_SIZE, 
200
 
                                        StorageProperties.MAX_VOLUME_SIZE);
 
208
                                        StorageProperties.MAX_VOLUME_SIZE,
 
209
                                        true);
201
210
                }
202
211
                return conf;
203
212
        }