18
18
*/
19
19
package org .apache .cloudstack .storage .datastore .lifecycle ;
20
20
21
- import java .io .UnsupportedEncodingException ;
22
21
import java .net .URI ;
23
22
import java .net .URISyntaxException ;
24
23
import java .net .URLDecoder ;
30
29
31
30
import javax .inject .Inject ;
32
31
32
+ import com .cloud .utils .StringUtils ;
33
33
import org .apache .cloudstack .engine .subsystem .api .storage .ClusterScope ;
34
34
import org .apache .cloudstack .engine .subsystem .api .storage .DataStore ;
35
35
import org .apache .cloudstack .engine .subsystem .api .storage .HostScope ;
48
48
import org .apache .commons .collections .CollectionUtils ;
49
49
50
50
import com .cloud .agent .AgentManager ;
51
- import com .cloud .agent .api .Answer ;
52
- import com .cloud .agent .api .DeleteStoragePoolCommand ;
53
51
import com .cloud .agent .api .StoragePoolInfo ;
54
52
import com .cloud .capacity .CapacityManager ;
55
53
import com .cloud .dc .ClusterVO ;
63
61
import com .cloud .storage .StorageManager ;
64
62
import com .cloud .storage .StoragePool ;
65
63
import com .cloud .storage .StoragePoolAutomation ;
66
- import com .cloud .storage .StoragePoolHostVO ;
67
- import com .cloud .storage .VMTemplateStoragePoolVO ;
68
- import com .cloud .storage .VMTemplateStorageResourceAssoc ;
69
64
import com .cloud .storage .dao .StoragePoolHostDao ;
70
65
import com .cloud .template .TemplateManager ;
71
66
import com .cloud .utils .UriUtils ;
@@ -111,7 +106,7 @@ private org.apache.cloudstack.storage.datastore.api.StoragePool findStoragePool(
111
106
List <org .apache .cloudstack .storage .datastore .api .StoragePool > storagePools = client .listStoragePools ();
112
107
for (org .apache .cloudstack .storage .datastore .api .StoragePool pool : storagePools ) {
113
108
if (pool .getName ().equals (storagePoolName )) {
114
- logger .info ("Found PowerFlex storage pool: " + storagePoolName );
109
+ logger .info ("Found PowerFlex storage pool: {}" , storagePoolName );
115
110
final org .apache .cloudstack .storage .datastore .api .StoragePoolStatistics poolStatistics = client .getStoragePoolStatistics (pool .getId ());
116
111
pool .setStatistics (poolStatistics );
117
112
@@ -164,7 +159,7 @@ public DataStore initialize(Map<String, Object> dsInfos) {
164
159
throw new CloudRuntimeException ("Cluster Id must also be specified when the Pod Id is specified for Cluster-wide primary storage." );
165
160
}
166
161
167
- URI uri = null ;
162
+ URI uri ;
168
163
try {
169
164
uri = new URI (UriUtils .encodeURIComponent (url ));
170
165
if (uri .getScheme () == null || !uri .getScheme ().equalsIgnoreCase ("powerflex" )) {
@@ -174,20 +169,16 @@ public DataStore initialize(Map<String, Object> dsInfos) {
174
169
throw new InvalidParameterValueException (url + " is not a valid uri" );
175
170
}
176
171
177
- String storagePoolName = null ;
178
- try {
179
- storagePoolName = URLDecoder .decode (uri .getPath (), "UTF-8" );
180
- } catch (UnsupportedEncodingException e ) {
181
- logger .error ("[ignored] we are on a platform not supporting \" UTF-8\" !?!" , e );
182
- }
172
+ String storagePoolName ;
173
+ storagePoolName = URLDecoder .decode (uri .getPath (), StringUtils .getPreferredCharset ());
183
174
if (storagePoolName == null ) { // if decoding fails, use getPath() anyway
184
175
storagePoolName = uri .getPath ();
185
176
}
186
177
storagePoolName = storagePoolName .replaceFirst ("/" , "" );
187
178
188
179
final String storageHost = uri .getHost ();
189
180
final int port = uri .getPort ();
190
- String gatewayApiURL = null ;
181
+ String gatewayApiURL ;
191
182
if (port == -1 ) {
192
183
gatewayApiURL = String .format ("https://%s/api" , storageHost );
193
184
} else {
@@ -321,37 +312,11 @@ public void disableStoragePool(DataStore dataStore) {
321
312
322
313
@ Override
323
314
public boolean deleteDataStore (DataStore dataStore ) {
324
- StoragePool storagePool = (StoragePool )dataStore ;
325
- StoragePoolVO storagePoolVO = primaryDataStoreDao .findById (storagePool .getId ());
326
- if (storagePoolVO == null ) {
327
- return false ;
315
+ if (cleanupDatastore (dataStore )) {
316
+ ScaleIOGatewayClientConnectionPool .getInstance ().removeClient (dataStore );
317
+ return dataStoreHelper .deletePrimaryDataStore (dataStore );
328
318
}
329
-
330
- List <VMTemplateStoragePoolVO > unusedTemplatesInPool = templateMgr .getUnusedTemplatesInPool (storagePoolVO );
331
- for (VMTemplateStoragePoolVO templatePoolVO : unusedTemplatesInPool ) {
332
- if (templatePoolVO .getDownloadState () == VMTemplateStorageResourceAssoc .Status .DOWNLOADED ) {
333
- templateMgr .evictTemplateFromStoragePool (templatePoolVO );
334
- }
335
- }
336
-
337
- List <StoragePoolHostVO > poolHostVOs = storagePoolHostDao .listByPoolId (dataStore .getId ());
338
- for (StoragePoolHostVO poolHostVO : poolHostVOs ) {
339
- DeleteStoragePoolCommand deleteStoragePoolCommand = new DeleteStoragePoolCommand (storagePool );
340
- final Answer answer = agentMgr .easySend (poolHostVO .getHostId (), deleteStoragePoolCommand );
341
- if (answer != null && answer .getResult ()) {
342
- logger .info ("Successfully deleted storage pool: {} from host: {}" , storagePool , poolHostVO .getHostId ());
343
- } else {
344
- if (answer != null ) {
345
- logger .error ("Failed to delete storage pool: {} from host: {} , result: {}" , storagePool , poolHostVO .getHostId (), answer .getResult ());
346
- } else {
347
- logger .error ("Failed to delete storage pool: {} from host: {}" , storagePool , poolHostVO .getHostId ());
348
- }
349
- }
350
- }
351
-
352
- ScaleIOGatewayClientConnectionPool .getInstance ().removeClient (dataStore );
353
-
354
- return dataStoreHelper .deletePrimaryDataStore (dataStore );
319
+ return false ;
355
320
}
356
321
357
322
@ Override
0 commit comments