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.
64
64
package edu.ucsb.eucalyptus.cloud.entities;
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;
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;
78
import javax.persistence.*;
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)
89
public class StorageInfo extends AbstractPersistent {
87
90
private static Logger LOG = Logger.getLogger( StorageInfo.class );
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;
103
public StorageInfo(){
105
public StorageInfo() {
104
106
this.name = StorageProperties.NAME;
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;
121
this.shouldTransferSnapshots = shouldTransferSnapshots;
125
124
public String getName() {
146
145
this.maxVolumeSizeInGB = maxVolumeSizeInGB;
148
public Boolean getShouldTransferSnapshots() {
149
return shouldTransferSnapshots;
152
public void setShouldTransferSnapshots(Boolean shouldTransferSnapshots) {
153
this.shouldTransferSnapshots = shouldTransferSnapshots;
150
157
public boolean equals(Object obj) {
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;
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,
192
200
storageDb.add(conf);
193
201
storageDb.commit();
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,