1818 */
1919package org .apache .cloudstack .storage .datastore .lifecycle ;
2020
21- import java .io .UnsupportedEncodingException ;
2221import java .net .URI ;
2322import java .net .URISyntaxException ;
2423import java .net .URLDecoder ;
3029
3130import javax .inject .Inject ;
3231
32+ import com .cloud .utils .StringUtils ;
3333import org .apache .cloudstack .engine .subsystem .api .storage .ClusterScope ;
3434import org .apache .cloudstack .engine .subsystem .api .storage .DataStore ;
3535import org .apache .cloudstack .engine .subsystem .api .storage .HostScope ;
4848import org .apache .commons .collections .CollectionUtils ;
4949
5050import com .cloud .agent .AgentManager ;
51- import com .cloud .agent .api .Answer ;
52- import com .cloud .agent .api .DeleteStoragePoolCommand ;
5351import com .cloud .agent .api .StoragePoolInfo ;
5452import com .cloud .capacity .CapacityManager ;
5553import com .cloud .dc .ClusterVO ;
6361import com .cloud .storage .StorageManager ;
6462import com .cloud .storage .StoragePool ;
6563import com .cloud .storage .StoragePoolAutomation ;
66- import com .cloud .storage .StoragePoolHostVO ;
67- import com .cloud .storage .VMTemplateStoragePoolVO ;
68- import com .cloud .storage .VMTemplateStorageResourceAssoc ;
6964import com .cloud .storage .dao .StoragePoolHostDao ;
7065import com .cloud .template .TemplateManager ;
7166import com .cloud .utils .UriUtils ;
@@ -111,7 +106,7 @@ private org.apache.cloudstack.storage.datastore.api.StoragePool findStoragePool(
111106 List <org .apache .cloudstack .storage .datastore .api .StoragePool > storagePools = client .listStoragePools ();
112107 for (org .apache .cloudstack .storage .datastore .api .StoragePool pool : storagePools ) {
113108 if (pool .getName ().equals (storagePoolName )) {
114- logger .info ("Found PowerFlex storage pool: " + storagePoolName );
109+ logger .info ("Found PowerFlex storage pool: {}" , storagePoolName );
115110 final org .apache .cloudstack .storage .datastore .api .StoragePoolStatistics poolStatistics = client .getStoragePoolStatistics (pool .getId ());
116111 pool .setStatistics (poolStatistics );
117112
@@ -164,7 +159,7 @@ public DataStore initialize(Map<String, Object> dsInfos) {
164159 throw new CloudRuntimeException ("Cluster Id must also be specified when the Pod Id is specified for Cluster-wide primary storage." );
165160 }
166161
167- URI uri = null ;
162+ URI uri ;
168163 try {
169164 uri = new URI (UriUtils .encodeURIComponent (url ));
170165 if (uri .getScheme () == null || !uri .getScheme ().equalsIgnoreCase ("powerflex" )) {
@@ -174,20 +169,16 @@ public DataStore initialize(Map<String, Object> dsInfos) {
174169 throw new InvalidParameterValueException (url + " is not a valid uri" );
175170 }
176171
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 ());
183174 if (storagePoolName == null ) { // if decoding fails, use getPath() anyway
184175 storagePoolName = uri .getPath ();
185176 }
186177 storagePoolName = storagePoolName .replaceFirst ("/" , "" );
187178
188179 final String storageHost = uri .getHost ();
189180 final int port = uri .getPort ();
190- String gatewayApiURL = null ;
181+ String gatewayApiURL ;
191182 if (port == -1 ) {
192183 gatewayApiURL = String .format ("https://%s/api" , storageHost );
193184 } else {
@@ -321,37 +312,11 @@ public void disableStoragePool(DataStore dataStore) {
321312
322313 @ Override
323314 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 );
328318 }
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 ;
355320 }
356321
357322 @ Override
0 commit comments