@@ -41,45 +41,58 @@ public final class LibvirtDeleteStoragePoolCommandWrapper extends CommandWrapper
4141 @ Override
4242 public Answer execute (final DeleteStoragePoolCommand command , final LibvirtComputingResource libvirtComputingResource ) {
4343 try {
44- // if getRemoveDatastore() is true, then we are dealing with managed storage and can skip the delete logic here
4544 if (!command .getRemoveDatastore ()) {
46- final StorageFilerTO pool = command .getPool ();
47- final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource .getStoragePoolMgr ();
45+ handleStoragePoolDeletion (command , libvirtComputingResource );
46+ }
47+ return new Answer (command );
48+ } catch (final CloudRuntimeException e ) {
49+ return new Answer (command , false , e .toString ());
50+ }
51+ }
4852
49- storagePoolMgr . deleteStoragePool ( pool . getType (), pool . getUuid ());
50- if ( Storage . StoragePoolType . Filesystem . equals ( pool . getType ()) && ! libvirtComputingResource . DEFAULT_LOCAL_STORAGE_PATH . equals ( pool . getPath ())) {
51- String localStoragePath = AgentPropertiesFileHandler . getPropertyValue ( AgentProperties . LOCAL_STORAGE_PATH );
52- String localStorageUuid = AgentPropertiesFileHandler . getPropertyValue ( AgentProperties . LOCAL_STORAGE_UUID );
53+ private void handleStoragePoolDeletion ( final DeleteStoragePoolCommand command , final LibvirtComputingResource libvirtComputingResource ) {
54+ final StorageFilerTO pool = command . getPool ();
55+ final KVMStoragePoolManager storagePoolMgr = libvirtComputingResource . getStoragePoolMgr ( );
56+ storagePoolMgr . deleteStoragePool ( pool . getType (), pool . getUuid () );
5357
54- String uuidToRemove = pool .getUuid ();
55- String pathToRemove = pool .getPath ();
58+ if (isLocalStorageAndNotHavingDefaultPath (pool , libvirtComputingResource )) {
59+ updateLocalStorageProperties (pool );
60+ }
61+ }
5662
57- if (localStorageUuid != null && uuidToRemove != null ) {
58- localStorageUuid = Arrays .stream (localStorageUuid .split ("," ))
59- .filter (uuid -> !uuid .equals (uuidToRemove ))
60- .collect (Collectors .joining ("," ));
61- }
63+ private boolean isLocalStorageAndNotHavingDefaultPath (final StorageFilerTO pool , final LibvirtComputingResource libvirtComputingResource ) {
64+ return Storage .StoragePoolType .Filesystem .equals (pool .getType ())
65+ && !libvirtComputingResource .DEFAULT_LOCAL_STORAGE_PATH .equals (pool .getPath ());
66+ }
6267
63- if (localStoragePath != null && pathToRemove != null ) {
64- localStoragePath = Arrays .stream (localStoragePath .split ("," ))
65- .filter (path -> !path .equals (pathToRemove ))
66- .collect (Collectors .joining ("," ));
67- }
68+ private void updateLocalStorageProperties (final StorageFilerTO pool ) {
69+ String localStoragePath = AgentPropertiesFileHandler .getPropertyValue (AgentProperties .LOCAL_STORAGE_PATH );
70+ String localStorageUuid = AgentPropertiesFileHandler .getPropertyValue (AgentProperties .LOCAL_STORAGE_UUID );
6871
69- PropertiesStorage agentProperties = new PropertiesStorage ();
70- agentProperties .configure ("AgentProperties" , new HashMap <String , Object >());
71- if (localStorageUuid != null ) {
72- agentProperties .persist (AgentProperties .LOCAL_STORAGE_UUID .getName (), localStorageUuid );
73- }
74- if (localStoragePath != null ) {
75- agentProperties .persist (AgentProperties .LOCAL_STORAGE_PATH .getName (), localStoragePath );
76- }
77- }
78- }
72+ String uuidToRemove = pool .getUuid ();
73+ String pathToRemove = pool .getPath ();
7974
80- return new Answer (command );
81- } catch (final CloudRuntimeException e ) {
82- return new Answer (command , false , e .toString ());
75+ if (localStorageUuid != null && uuidToRemove != null ) {
76+ localStorageUuid = Arrays .stream (localStorageUuid .split ("," ))
77+ .filter (uuid -> !uuid .equals (uuidToRemove ))
78+ .collect (Collectors .joining ("," ));
79+ }
80+
81+ if (localStoragePath != null && pathToRemove != null ) {
82+ localStoragePath = Arrays .stream (localStoragePath .split ("," ))
83+ .filter (path -> !path .equals (pathToRemove ))
84+ .collect (Collectors .joining ("," ));
85+ }
86+
87+ PropertiesStorage agentProperties = new PropertiesStorage ();
88+ agentProperties .configure ("AgentProperties" , new HashMap <String , Object >());
89+
90+ if (localStorageUuid != null ) {
91+ agentProperties .persist (AgentProperties .LOCAL_STORAGE_UUID .getName (), localStorageUuid );
92+ }
93+
94+ if (localStoragePath != null ) {
95+ agentProperties .persist (AgentProperties .LOCAL_STORAGE_PATH .getName (), localStoragePath );
8396 }
8497 }
8598}
0 commit comments