Search in sources :

Example 1 with SchedulerHelper

use of nl.nn.adapterframework.scheduler.SchedulerHelper in project iaf by ibissource.

the class ShowScheduler method trigger.

@PUT
@RolesAllowed({ "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/schedules/{groupName}/{jobName}")
@Relation("schedules")
@Produces(MediaType.APPLICATION_JSON)
public Response trigger(@PathParam("jobName") String jobName, @PathParam("groupName") String groupName) throws ApiException {
    initBase(servletConfig);
    DefaultIbisManager manager = (DefaultIbisManager) ibisManager;
    SchedulerHelper sh = manager.getSchedulerHelper();
    Scheduler scheduler;
    try {
        scheduler = sh.getScheduler();
    } catch (SchedulerException e) {
        throw new ApiException("Cannot find scheduler");
    }
    try {
        String commandIssuedBy = servletConfig.getInitParameter("remoteHost");
        commandIssuedBy += servletConfig.getInitParameter("remoteAddress");
        commandIssuedBy += servletConfig.getInitParameter("remoteUser");
        log.info("trigger job jobName [" + jobName + "] groupName [" + groupName + "] " + commandIssuedBy);
        scheduler.triggerJob(jobName, groupName);
    } catch (Exception e) {
        throw new ApiException("Failed to trigger job");
    }
    return Response.status(Response.Status.OK).build();
}
Also used : SchedulerHelper(nl.nn.adapterframework.scheduler.SchedulerHelper) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler) DefaultIbisManager(nl.nn.adapterframework.unmanaged.DefaultIbisManager) SchedulerException(org.quartz.SchedulerException) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 2 with SchedulerHelper

use of nl.nn.adapterframework.scheduler.SchedulerHelper in project iaf by ibissource.

the class ShowScheduler method PutSchedules.

@DELETE
@RolesAllowed({ "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/schedules/{groupName}/{jobName}")
@Relation("schedules")
@Produces(MediaType.APPLICATION_JSON)
public Response PutSchedules(@PathParam("jobName") String jobName, @QueryParam("groupName") String groupName) throws ApiException {
    initBase(servletConfig);
    DefaultIbisManager manager = (DefaultIbisManager) ibisManager;
    SchedulerHelper sh = manager.getSchedulerHelper();
    Scheduler scheduler;
    try {
        scheduler = sh.getScheduler();
    } catch (SchedulerException e) {
        throw new ApiException("Cannot find scheduler");
    }
    try {
        String commandIssuedBy = servletConfig.getInitParameter("remoteHost");
        commandIssuedBy += servletConfig.getInitParameter("remoteAddress");
        commandIssuedBy += servletConfig.getInitParameter("remoteUser");
        log.info("delete job jobName [" + jobName + "] groupName [" + groupName + "] " + commandIssuedBy);
        scheduler.deleteJob(jobName, groupName);
    } catch (Exception e) {
        throw new ApiException("Failed to delete job");
    }
    return Response.status(Response.Status.OK).build();
}
Also used : SchedulerHelper(nl.nn.adapterframework.scheduler.SchedulerHelper) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler) DefaultIbisManager(nl.nn.adapterframework.unmanaged.DefaultIbisManager) SchedulerException(org.quartz.SchedulerException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces)

Example 3 with SchedulerHelper

use of nl.nn.adapterframework.scheduler.SchedulerHelper in project iaf by ibissource.

the class SchedulerHandler method executeSub.

public ActionForward executeSub(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    // Extract attributes we will need
    initAction(request);
    String action = request.getParameter("action");
    if (null == action)
        action = mapping.getParameter();
    String jobName = request.getParameter("jobName");
    String groupName = request.getParameter("groupName");
    if (ibisManager == null) {
        error("Cannot find ibismanager", null);
        return null;
    }
    // TODO Dit moet natuurlijk netter...
    DefaultIbisManager manager = (DefaultIbisManager) ibisManager;
    SchedulerHelper sh = manager.getSchedulerHelper();
    SchedulerAdapter schedulerAdapter = new SchedulerAdapter();
    Scheduler scheduler;
    try {
        scheduler = sh.getScheduler();
    } catch (SchedulerException e) {
        error("Cannot find scheduler", e);
        return null;
    }
    try {
        String msg = null;
        if (action.equalsIgnoreCase("startScheduler")) {
            msg = "start scheduler:" + new Date() + HttpUtils.getCommandIssuedBy(request);
            log.info(msg);
            secLog.info(msg);
            scheduler.start();
        } else if (action.equalsIgnoreCase("pauseScheduler")) {
            msg = "pause scheduler:" + new Date() + HttpUtils.getCommandIssuedBy(request);
            log.info(msg);
            secLog.info(msg);
            scheduler.standby();
        } else if (action.equalsIgnoreCase("deleteJob")) {
            msg = "delete job jobName [" + jobName + "] groupName [" + groupName + "] " + HttpUtils.getCommandIssuedBy(request);
            log.info(msg);
            secLog.info(msg);
            scheduler.deleteJob(jobName, groupName);
        } else if (action.equalsIgnoreCase("triggerJob")) {
            msg = "trigger job jobName [" + jobName + "] groupName [" + groupName + "] " + HttpUtils.getCommandIssuedBy(request);
            log.info(msg);
            secLog.info(msg);
            scheduler.triggerJob(jobName, groupName);
        } else {
            log.error("no valid argument for SchedulerHandler:" + action);
        }
    } catch (Exception e) {
        error("", e);
    }
    // Report any errors
    if (!errors.isEmpty()) {
        saveErrors(request, errors);
    }
    // Remove the obsolete form bean
    if (mapping.getAttribute() != null) {
        if ("request".equals(mapping.getScope()))
            request.removeAttribute(mapping.getAttribute());
        else
            session.removeAttribute(mapping.getAttribute());
    }
    // Forward control to the specified success URI
    return (mapping.findForward("success"));
}
Also used : SchedulerHelper(nl.nn.adapterframework.scheduler.SchedulerHelper) SchedulerException(org.quartz.SchedulerException) SchedulerAdapter(nl.nn.adapterframework.scheduler.SchedulerAdapter) Scheduler(org.quartz.Scheduler) DefaultIbisManager(nl.nn.adapterframework.unmanaged.DefaultIbisManager) Date(java.util.Date) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) SchedulerException(org.quartz.SchedulerException)

Example 4 with SchedulerHelper

use of nl.nn.adapterframework.scheduler.SchedulerHelper in project iaf by ibissource.

the class ShowScheduler method putSchedules.

@PUT
@RolesAllowed({ "IbisDataAdmin", "IbisAdmin", "IbisTester" })
@Path("/schedules/")
@Relation("schedules")
@Produces(MediaType.APPLICATION_JSON)
public Response putSchedules(LinkedHashMap<String, Object> json) throws ApiException {
    initBase(servletConfig);
    DefaultIbisManager manager = (DefaultIbisManager) ibisManager;
    SchedulerHelper sh = manager.getSchedulerHelper();
    Scheduler scheduler;
    try {
        scheduler = sh.getScheduler();
    } catch (SchedulerException e) {
        throw new ApiException("Cannot find scheduler");
    }
    String action = null;
    for (Entry<String, Object> entry : json.entrySet()) {
        String key = entry.getKey();
        if (key.equalsIgnoreCase("action")) {
            action = entry.getValue().toString();
        }
    }
    try {
        String commandIssuedBy = servletConfig.getInitParameter("remoteHost");
        commandIssuedBy += servletConfig.getInitParameter("remoteAddress");
        commandIssuedBy += servletConfig.getInitParameter("remoteUser");
        if (action.equalsIgnoreCase("start")) {
            if (scheduler.isInStandbyMode() || scheduler.isShutdown()) {
                scheduler.start();
                log.info("start scheduler:" + new Date() + commandIssuedBy);
            } else {
                throw new ApiException("Failed to start scheduler");
            }
        } else if (action.equalsIgnoreCase("pause")) {
            if (scheduler.isStarted()) {
                scheduler.standby();
                log.info("pause scheduler:" + new Date() + commandIssuedBy);
            } else {
                throw new ApiException("Failed to pause scheduler");
            }
        } else if (action.equalsIgnoreCase("stop")) {
            if (scheduler.isStarted() || scheduler.isInStandbyMode()) {
                scheduler.shutdown();
                log.info("shutdown scheduler:" + new Date() + commandIssuedBy);
            } else {
                throw new ApiException("Failed to stop scheduler");
            }
        } else {
            return Response.status(Response.Status.BAD_REQUEST).build();
        }
    } catch (Exception e) {
        log.error("", e);
    }
    return Response.status(Response.Status.OK).build();
}
Also used : SchedulerHelper(nl.nn.adapterframework.scheduler.SchedulerHelper) SchedulerException(org.quartz.SchedulerException) Scheduler(org.quartz.Scheduler) DefaultIbisManager(nl.nn.adapterframework.unmanaged.DefaultIbisManager) Date(java.util.Date) SchedulerException(org.quartz.SchedulerException) Path(javax.ws.rs.Path) RolesAllowed(javax.annotation.security.RolesAllowed) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT)

Example 5 with SchedulerHelper

use of nl.nn.adapterframework.scheduler.SchedulerHelper in project iaf by ibissource.

the class ShowSchedulerStatus method executeSub.

public ActionForward executeSub(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    // Initialize action
    initAction(request);
    if (ibisManager == null)
        return (mapping.findForward("noIbisContext"));
    if (ibisManager == null) {
        error("Cannot find ibismanager", null);
        return null;
    }
    // TODO Dit moet natuurlijk netter...
    DefaultIbisManager manager = (DefaultIbisManager) ibisManager;
    SchedulerHelper sh = manager.getSchedulerHelper();
    SchedulerAdapter schedulerAdapter = new SchedulerAdapter();
    Scheduler scheduler;
    try {
        scheduler = sh.getScheduler();
    } catch (SchedulerException e) {
        error("Cannot find scheduler", e);
        return null;
    }
    SchedulerAdapter sa = new SchedulerAdapter();
    if (log.isDebugEnabled()) {
        log.debug("set metadata [" + sa.getSchedulerMetaDataToXml(scheduler).toXML() + "]");
        log.debug("set jobdata [" + sa.getJobGroupNamesWithJobsToXml(scheduler, ibisManager).toXML() + "]");
    }
    request.setAttribute("metadata", sa.getSchedulerMetaDataToXml(scheduler).toXML());
    request.setAttribute("jobdata", sa.getJobGroupNamesWithJobsToXml(scheduler, ibisManager).toXML());
    // Forward control to the specified success URI
    log.debug("forward to success");
    return (mapping.findForward("success"));
}
Also used : SchedulerHelper(nl.nn.adapterframework.scheduler.SchedulerHelper) SchedulerException(org.quartz.SchedulerException) SchedulerAdapter(nl.nn.adapterframework.scheduler.SchedulerAdapter) Scheduler(org.quartz.Scheduler) DefaultIbisManager(nl.nn.adapterframework.unmanaged.DefaultIbisManager)

Aggregations

SchedulerHelper (nl.nn.adapterframework.scheduler.SchedulerHelper)8 SchedulerException (org.quartz.SchedulerException)8 Scheduler (org.quartz.Scheduler)7 DefaultIbisManager (nl.nn.adapterframework.unmanaged.DefaultIbisManager)6 RolesAllowed (javax.annotation.security.RolesAllowed)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 PUT (javax.ws.rs.PUT)3 Connection (java.sql.Connection)2 PreparedStatement (java.sql.PreparedStatement)2 Date (java.util.Date)2 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)2 FixedQuerySender (nl.nn.adapterframework.jdbc.FixedQuerySender)2 IbisJobDetail (nl.nn.adapterframework.scheduler.IbisJobDetail)2 SchedulerAdapter (nl.nn.adapterframework.scheduler.SchedulerAdapter)2 Locker (nl.nn.adapterframework.util.Locker)2 JobKey (org.quartz.JobKey)2 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 ResultSet (java.sql.ResultSet)1