package io.cattle.platform.process.volume;

import io.cattle.platform.core.model.Volume;
import io.cattle.platform.core.model.VolumeStoragePoolMap;
import io.cattle.platform.engine.handler.HandlerResult;
import io.cattle.platform.engine.process.ProcessInstance;
import io.cattle.platform.engine.process.ProcessState;
import io.cattle.platform.process.base.AbstractDefaultProcessHandler;

import java.util.HashSet;
import java.util.Set;

import javax.inject.Named;

@Named
public class VolumeDeactivate extends AbstractDefaultProcessHandler {

    @Override
    public HandlerResult handle(ProcessState state, ProcessInstance process) {
        Volume volume = (Volume) state.getResource();

        Set<Long> pools = new HashSet<Long>();
        for (VolumeStoragePoolMap map : getObjectManager().children(volume, VolumeStoragePoolMap.class)) {
            if (map.getRemoved() == null) {
                deactivate(map, state.getData());
                pools.add(map.getStoragePoolId());
            }
        }

        return new HandlerResult("_deactivatedPools", pools);
    }

}
@@ -310,16 +310,86 @@
 sState;%0A
+import io.cattle.platform.engine.process.impl.ProcessCancelException;%0A
 import i
@@ -948,24 +948,50 @@
  == null) %7B%0A
+                try %7B%0A    
             
@@ -1024,24 +1024,145 @@
 getData());%0A
+                %7D catch (ProcessCancelException e) %7B%0A                    remove(map, state.getData());%0A                %7D%0A
             

remove volumeStoragePoolMap if deac fails