(→Find All Agents Online And Offline)
|
(→AHPSCRIPTS-33)
|
Line 2314: | |||
BuildRequest br = new BuildRequest(bl, wflow, sg, usr, rse, req); | BuildRequest br = new BuildRequest(bl, wflow, sg, usr, rse, req); | ||
BuildService.getInstance().runWorkflow(br);</pre> | BuildService.getInstance().runWorkflow(br);</pre> | ||
+ | = Add a Debugger to Log System Events = | ||
+ | * '''Please note this event listener stays in the System until the next restart. Running the script more than once will create duplicate listeners and logging.''' | ||
+ | ==== AHPSCRIPTS-121 ==== | ||
+ | <pre>import com.urbancode.anthill3.domain.buildrequest.BuildRequestEvent; | ||
+ | import com.urbancode.anthill3.domain.security.UserFactory; | ||
+ | import com.urbancode.anthill3.domain.workflow.WorkflowEvent; | ||
+ | import com.urbancode.anthill3.persistence.UnitOfWork; | ||
+ | import com.urbancode.anthill3.services.event.EventListener; | ||
+ | import com.urbancode.anthill3.services.event.EventService; | ||
+ | import com.urbancode.anthill3.services.event.criteria.Criteria; | ||
+ | import java.util.EventObject; | ||
+ | import org.apache.log4j.Logger; | ||
+ | public class LoggingEventListener implements EventListener { | ||
+ | Logger log = Logger.getLogger("LoggingEventListener"); | ||
+ | public void handleEvent(EventObject event) { | ||
+ | if (event instanceof BuildRequestEvent) { | ||
+ | UnitOfWork uow = UnitOfWork.create(UserFactory.getSystemUser()); | ||
+ | try { | ||
+ | requestEvent = (BuildRequestEvent) event; | ||
+ | request = requestEvent.getSource(); | ||
+ | log.warn("Received " + event.getClass().getSimpleName() + " for request " + request.getId() + " with status " + request.getStatus()); | ||
+ | } | ||
+ | finally { | ||
+ | uow.close(); | ||
+ | } | ||
+ | } | ||
+ | else if (event instanceof WorkflowEvent) { | ||
+ | UnitOfWork uow = UnitOfWork.create(UserFactory.getSystemUser()); | ||
+ | try { | ||
+ | workflowEvent = (WorkflowEvent) event; | ||
+ | workflow = workflowEvent.getSource(); | ||
+ | log.warn("Received " + event.getClass().getSimpleName() + " for workflow " + workflow.getId() + " with status " + workflow.getStatus()); | ||
+ | } | ||
+ | finally { | ||
+ | uow.close(); | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | public Class getEventClass() { | ||
+ | // get all events | ||
+ | return EventObject.class; | ||
+ | } | ||
+ | public Criteria[] getCriteria() { | ||
+ | return null; | ||
+ | } | ||
+ | } | ||
+ | EventService.getInstance().registerEventListener(new LoggingEventListener());</pre> |