package be.iminds.jfed.gts_highlevel.jobs;

/**
 * User: twalcari
 * Date: 10/16/2015
 * Time: 15:10
 */
public class GtsStopTestbedJob {/*extends AbstractGtsJob<Boolean> {
    private static final Logger LOG = LoggerFactory.getLogger(GtsStopTestbedJob.class);

    private final GeantTestbedType gtt;
    private final GtsReservation reservation;
    private final GtsModel gtsModel;
    private final GtsTaskFactory gtsTaskFactory;

    public GtsStopTestbedJob(GeantTestbedType gtt, GtsReservation reservation, TaskThread tt, GtsModel gtsModel, GtsTaskFactory gtsTaskFactory) {
        super("Stop GTS testbed " + gtt.getName(), tt);
        this.gtt = gtt;
        this.reservation = reservation;
        this.gtsModel = gtsModel;
        this.gtsTaskFactory = gtsTaskFactory;
    }

    @Override
    public Boolean execute() throws Exception {
        LOG.info("Stopping GTS testbed {} with reservation {}", gtt.getName(), reservation.getId());

        GtsModel.TypeId typeId = gtsModel.getReservationsByTypeId().get(reservation.getId());
        if (typeId == null) {
            throw new GtsException("Could not find underlying type of reservation " + reservation.getId());
        }

        GtsType type = gtsModel.getTypes().get(typeId);

        if (type == null) {
            throw new GtsException("Could not find type with ID " + typeId);
        }

        GtsProject project = gtsModel.getProjects().get(typeId.getProjectName());

        if (project == null) {
            throw new GtsException("Could not find project with ID " + typeId.getProjectName());
        }

        submitTaskAndWait(gtsTaskFactory.createStopGtsResourcesTask(reservation, type, project));
        submitTaskAndWait(gtsTaskFactory.createDeleteGtsProjectTask(project));

        return true;
    }      */
}
