package io.cattle.platform.process.mount;

import io.cattle.platform.core.constants.CommonStatesConstants;
import io.cattle.platform.core.constants.VolumeConstants;
import io.cattle.platform.core.dao.GenericMapDao;
import io.cattle.platform.core.model.Mount;
import io.cattle.platform.core.model.Volume;
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.lock.LockManager;
import io.cattle.platform.object.process.StandardProcess;
import io.cattle.platform.process.base.AbstractDefaultProcessHandler;
import io.cattle.platform.process.common.util.ProcessUtils;

import javax.inject.Inject;
import javax.inject.Named;

@Named
public class MountCreate extends AbstractDefaultProcessHandler {

    @Inject
    GenericMapDao mapDao;
    @Inject
    LockManager lockManager;

    @Override
    public HandlerResult handle(final ProcessState state, ProcessInstance process) {
        Mount mount = (Mount)state.getResource();
        Volume volume = objectManager.loadResource(Volume.class, mount.getVolumeId());
        if (!CommonStatesConstants.ACTIVE.equals(volume.getState()) && !CommonStatesConstants.ACTIVATING.equals(volume.getState())
                && !CommonStatesConstants.RESTORING.equals(volume.getState())) {
            if (CommonStatesConstants.REQUESTED.equals(volume.getState()) || CommonStatesConstants.REGISTERING.equals(volume.getState())) {
                objectProcessManager.scheduleStandardProcess(StandardProcess.CREATE, volume,
                        ProcessUtils.chainInData(state.getData(), VolumeConstants.PROCESS_CREATE, VolumeConstants.PROCESS_ACTIVATE));
            } else {
                objectProcessManager.scheduleStandardProcess(StandardProcess.ACTIVATE, volume, state.getData());
            }
        }
        return null;
    }
}

@@ -1140,24 +1140,169 @@
 olumeId());%0A
+        /* This is an upgrade issue with old data from %3C= 1.1.x */%0A        if (volume.getRemoved() != null) %7B%0A            return null;%0A        %7D%0A
         if (

Deal with data inconsistency