1616// under the License.
1717package com .cloud .storage ;
1818
19- import org .apache .commons .lang .NotImplementedException ;
20-
2119import java .util .ArrayList ;
20+ import java .util .LinkedHashMap ;
2221import java .util .List ;
22+ import java .util .Map ;
23+ import java .util .Objects ;
24+
25+ import org .apache .commons .lang .NotImplementedException ;
26+ import org .apache .commons .lang3 .StringUtils ;
2327
2428public class Storage {
2529 public static enum ImageFormat {
@@ -135,37 +139,72 @@ public static enum TemplateType {
135139 ISODISK /* Template corresponding to a iso (non root disk) present in an OVA */
136140 }
137141
138- public static enum StoragePoolType {
139- Filesystem (false , true , true ), // local directory
140- NetworkFilesystem (true , true , true ), // NFS
141- IscsiLUN (true , false , false ), // shared LUN, with a clusterfs overlay
142- Iscsi (true , false , false ), // for e.g., ZFS Comstar
143- ISO (false , false , false ), // for iso image
144- LVM (false , false , false ), // XenServer local LVM SR
145- CLVM (true , false , false ),
146- RBD (true , true , false ), // http://libvirt.org/storage.html#StorageBackendRBD
147- SharedMountPoint (true , false , true ),
148- VMFS (true , true , false ), // VMware VMFS storage
149- PreSetup (true , true , false ), // for XenServer, Storage Pool is set up by customers.
150- EXT (false , true , false ), // XenServer local EXT SR
151- OCFS2 (true , false , false ),
152- SMB (true , false , false ),
153- Gluster (true , false , false ),
154- PowerFlex (true , true , true ), // Dell EMC PowerFlex/ScaleIO (formerly VxFlexOS)
155- ManagedNFS (true , false , false ),
156- Linstor (true , true , false ),
157- DatastoreCluster (true , true , false ), // for VMware, to abstract pool of clusters
158- StorPool (true , true , true ),
159- FiberChannel (true , true , false ); // Fiber Channel Pool for KVM hypervisors is used to find the volume by WWN value (/dev/disk/by-id/wwn-<wwnvalue>)
160-
142+ /**
143+ * StoragePoolTypes carry some details about the format and capabilities of a storage pool. While not necessarily a
144+ * 1:1 with PrimaryDataStoreDriver (and for KVM agent, KVMStoragePool and StorageAdaptor) implementations, it is
145+ * often used to decide which storage plugin or storage command to call, so it may be necessary for new storage
146+ * plugins to add a StoragePoolType. This can be done by adding it below, or by creating a new public static final
147+ * instance of StoragePoolType in the plugin itself, which registers it with the map.
148+ *
149+ * Note that if the StoragePoolType is for KVM and defined in plugin code rather than below, care must be taken to
150+ * ensure this is available on the agent side as well. This is best done by defining the StoragePoolType in a common
151+ * package available on both management server and agent plugin jars.
152+ */
153+ public static class StoragePoolType {
154+ private static final Map <String , StoragePoolType > map = new LinkedHashMap <>();
155+
156+ public static final StoragePoolType Filesystem = new StoragePoolType ("Filesystem" , false , true , true );
157+ public static final StoragePoolType NetworkFilesystem = new StoragePoolType ("NetworkFilesystem" , true , true , true );
158+ public static final StoragePoolType IscsiLUN = new StoragePoolType ("IscsiLUN" , true , false , false );
159+ public static final StoragePoolType Iscsi = new StoragePoolType ("Iscsi" , true , false , false );
160+ public static final StoragePoolType ISO = new StoragePoolType ("ISO" , false , false , false );
161+ public static final StoragePoolType LVM = new StoragePoolType ("LVM" , false , false , false );
162+ public static final StoragePoolType CLVM = new StoragePoolType ("CLVM" , true , false , false );
163+ public static final StoragePoolType RBD = new StoragePoolType ("RBD" , true , true , false );
164+ public static final StoragePoolType SharedMountPoint = new StoragePoolType ("SharedMountPoint" , true , false , true );
165+ public static final StoragePoolType VMFS = new StoragePoolType ("VMFS" , true , true , false );
166+ public static final StoragePoolType PreSetup = new StoragePoolType ("PreSetup" , true , true , false );
167+ public static final StoragePoolType EXT = new StoragePoolType ("EXT" , false , true , false );
168+ public static final StoragePoolType OCFS2 = new StoragePoolType ("OCFS2" , true , false , false );
169+ public static final StoragePoolType SMB = new StoragePoolType ("SMB" , true , false , false );
170+ public static final StoragePoolType Gluster = new StoragePoolType ("Gluster" , true , false , false );
171+ public static final StoragePoolType PowerFlex = new StoragePoolType ("PowerFlex" , true , true , true );
172+ public static final StoragePoolType ManagedNFS = new StoragePoolType ("ManagedNFS" , true , false , false );
173+ public static final StoragePoolType Linstor = new StoragePoolType ("Linstor" , true , true , false );
174+ public static final StoragePoolType DatastoreCluster = new StoragePoolType ("DatastoreCluster" , true , true , false );
175+ public static final StoragePoolType StorPool = new StoragePoolType ("StorPool" , true ,true ,true );
176+ public static final StoragePoolType FiberChannel = new StoragePoolType ("FiberChannel" , true ,true ,false );
177+
178+
179+ private final String name ;
161180 private final boolean shared ;
162181 private final boolean overprovisioning ;
163182 private final boolean encryption ;
164183
165- StoragePoolType (boolean shared , boolean overprovisioning , boolean encryption ) {
184+ /**
185+ * New StoragePoolType, set the name to check with it in Dao (Note: Do not register it into the map of pool types).
186+ * @param name name of the StoragePoolType.
187+ */
188+ public StoragePoolType (String name ) {
189+ this .name = name ;
190+ this .shared = false ;
191+ this .overprovisioning = false ;
192+ this .encryption = false ;
193+ }
194+
195+ /**
196+ * Define a new StoragePoolType, and register it into the map of pool types known to the management server.
197+ * @param name Simple unique name of the StoragePoolType.
198+ * @param shared Storage pool is shared/accessible to multiple hypervisors
199+ * @param overprovisioning Storage pool supports overprovisioning
200+ * @param encryption Storage pool supports encrypted volumes
201+ */
202+ public StoragePoolType (String name , boolean shared , boolean overprovisioning , boolean encryption ) {
203+ this .name = name ;
166204 this .shared = shared ;
167205 this .overprovisioning = overprovisioning ;
168206 this .encryption = encryption ;
207+ addStoragePoolType (this );
169208 }
170209
171210 public boolean isShared () {
@@ -177,6 +216,48 @@ public boolean supportsOverProvisioning() {
177216 }
178217
179218 public boolean supportsEncryption () { return encryption ; }
219+
220+ private static void addStoragePoolType (StoragePoolType storagePoolType ) {
221+ map .putIfAbsent (storagePoolType .name , storagePoolType );
222+ }
223+
224+ public static StoragePoolType [] values () {
225+ return map .values ().toArray (StoragePoolType []::new ).clone ();
226+ }
227+
228+ public static StoragePoolType valueOf (String name ) {
229+ if (StringUtils .isBlank (name )) {
230+ return null ;
231+ }
232+
233+ StoragePoolType storage = map .get (name );
234+ if (storage == null ) {
235+ throw new IllegalArgumentException ("StoragePoolType '" + name + "' not found" );
236+ }
237+ return storage ;
238+ }
239+
240+ @ Override
241+ public String toString () {
242+ return name ;
243+ }
244+
245+ public String name () {
246+ return name ;
247+ }
248+
249+ @ Override
250+ public boolean equals (Object o ) {
251+ if (this == o ) return true ;
252+ if (o == null || getClass () != o .getClass ()) return false ;
253+ StoragePoolType that = (StoragePoolType ) o ;
254+ return Objects .equals (name , that .name );
255+ }
256+
257+ @ Override
258+ public int hashCode () {
259+ return Objects .hash (name );
260+ }
180261 }
181262
182263 public static List <StoragePoolType > getNonSharedStoragePoolTypes () {
0 commit comments