package org.ovirt.engine.core.common.asynctasks.gluster;

import org.ovirt.engine.core.common.job.JobExecutionStatus;

/**
 * This enum represents the gluster volume async task status values returned from VDSM
 */
public enum GlusterAsyncTaskStatus {
    COMPLETED("COMPLETED"),
    STARTED("STARTED"),
    STOPPED("STOPPED"),
    FAILED("FAILED"),
    UNKNOWN("UNKNOWN"),
    NOT_STARTED("NOT STARTED")
    ;

    private String statusMsg;

    private GlusterAsyncTaskStatus(String status) {
        statusMsg = status;
    }

    public String value() {
        return statusMsg;
    }

    public static GlusterAsyncTaskStatus from(String status) {
        for (GlusterAsyncTaskStatus taskStatus : values()) {
            if (taskStatus.value().equalsIgnoreCase(status)) {
                return taskStatus;
            }
        }

        return null;
    }

    public JobExecutionStatus getJobExecutionStatus() {
        switch (this) {
            case COMPLETED:
                return JobExecutionStatus.FINISHED;
            case STARTED:
                return JobExecutionStatus.STARTED;
            case STOPPED:
                return JobExecutionStatus.ABORTED;
            case FAILED:
                return JobExecutionStatus.FAILED;
            case UNKNOWN:
            case NOT_STARTED:
            default:
                return JobExecutionStatus.UNKNOWN;
        }
    }
}

package org.ovirt.engine.core.common.asynctasks.gluster;

import org.ovirt.engine.core.common.job.JobExecutionStatus;

/**
 * This enum represents the gluster volume async task status values returned from VDSM
 */
public enum GlusterAsyncTaskStatus {
    COMPLETED("COMPLETED"),
    STARTED("STARTED"),
    STOPPED("STOPPED"),
    FAILED("FAILED"),
    UNKNOWN("UNKNOWN"),
    NOT_STARTED("NOT STARTED")
    ;

    private String statusMsg;

    private GlusterAsyncTaskStatus(String status) {
        statusMsg = status;
    }

    public String value() {
        return statusMsg;
    }

    public static GlusterAsyncTaskStatus from(String status) {
        for (GlusterAsyncTaskStatus taskStatus : values()) {
            if (taskStatus.value().equalsIgnoreCase(status)) {
                return taskStatus;
            }
        }

        return GlusterAsyncTaskStatus.UNKNOWN;
    }

    public JobExecutionStatus getJobExecutionStatus() {
        switch (this) {
            case COMPLETED:
                return JobExecutionStatus.FINISHED;
            case STARTED:
                return JobExecutionStatus.STARTED;
            case STOPPED:
                return JobExecutionStatus.ABORTED;
            case FAILED:
                return JobExecutionStatus.FAILED;
            case UNKNOWN:
            case NOT_STARTED:
            default:
                return JobExecutionStatus.UNKNOWN;
        }
    }
}

Return UNKNOWN status for GlusterTaskStatus
gluster: Return UNKNOWN status for GlusterTaskStatus

If the string value passed to GlusterTaskStatus is not
one of the enum options return UNKNOWN as the option
value.
Fixes 2 issues reported by coverity scan when converting
vdsm return value
GlusterAsyncTaskStatus.from((String)map.get(STATUS)).getJobExecutionStatus()
-- possible NPE

Change-Id: If8cd725af21639827ba19c5589fe2889e1c98c19
Signed-off-by: Sahina Bose <e470779b356412d02748affb76951ba845275668@redhat.com>
