package be.iminds.ilabt.jfed.highlevel.jobs;

import be.iminds.ilabt.jfed.experiment.Experiment;
import be.iminds.ilabt.jfed.highlevel.controller.TaskExecution;
import be.iminds.ilabt.jfed.highlevel.controller.TaskThread;
import be.iminds.ilabt.jfed.highlevel.tasks.HighLevelTaskFactory;
import be.iminds.ilabt.jfed.highlevel.tasks.SliceMembersSshKeysTask;
import be.iminds.ilabt.jfed.lowlevel.api.user_spec.UserSpec;

import javax.annotation.Nullable;
import java.util.Collection;

/**
 * User: twalcari
 * Date: 12/2/2015
 * Time: 11:33
 */
public class FetchSliceMemberSshKeysJob extends SingleTaskJob<SliceMembersSshKeysTask, Collection<UserSpec>> {
    private Collection<UserSpec> result = null;

    public FetchSliceMemberSshKeysJob(Experiment experiment, HighLevelTaskFactory hltf, TaskThread tt) {
        super("Fetching SSH Keys from slice members", experiment, hltf, tt);
    }

    @Override
    public SliceMembersSshKeysTask createTask() {
        return hltf.getSliceMembersSSHKeys(experiment.getSlice());
    }


    @Override
    protected void onFinished(SliceMembersSshKeysTask task, TaskExecution<SliceMembersSshKeysTask> taskExecution) {
        if (taskExecution.getState() == TaskExecution.TaskState.SUCCESS) {
            result = task.getUserSpecs();
        }
    }

    @Override
    @Nullable
    public Collection<UserSpec> getResult() {
        return result;
    }
}
