bug #255 fixed; minor changes in Java UI
[public/netxms.git] / src / server / include / nxcore_jobs.h
CommitLineData
ab621f39
VK
1/*
2** NetXMS - Network Management System
3** Copyright (C) 2003-2009 Victor Kirhenshtein
4**
5** This program is free software; you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation; either version 2 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program; if not, write to the Free Software
17** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18**
19** File: nxcore_jobs.h
20**
21**/
22
23#ifndef _nxcore_jobs_h_
24#define _nxcore_jobs_h_
25
26
27//
28// Job status
29//
30
31enum ServerJobStatus
32{
33 JOB_PENDING = 0,
34 JOB_ACTIVE,
35 JOB_ON_HOLD,
36 JOB_COMPLETED,
f40831eb 37 JOB_FAILED,
f2665675
VK
38 JOB_CANCELLED,
39 JOB_CANCEL_PENDING
ab621f39
VK
40};
41
42
43//
44// Job class
45//
46
47class ServerJobQueue;
3929b1ca 48class NetObj;
ab621f39
VK
49
50class NXCORE_EXPORTABLE ServerJob
51{
52private:
53 DWORD m_id;
54 TCHAR *m_type;
55 DWORD m_remoteNode;
56 TCHAR *m_description;
57 ServerJobStatus m_status;
58 int m_progress;
59 TCHAR *m_failureMessage;
60 THREAD m_workerThread;
61 ServerJobQueue *m_owningQueue;
3929b1ca
VK
62 time_t m_lastStatusChange;
63 int m_autoCancelDelay; // Interval in seconds to cancel failed job automatically (0 = disabled)
64 time_t m_lastNotification;
65 NetObj *m_resolvedObject;
66 MUTEX m_notificationLock;
67 CSCPMessage m_notificationMessage;
8134d3a3 68 bool m_blockNextJobsOnFailure;
ab621f39
VK
69
70 static DWORD s_freeId;
71 static THREAD_RESULT THREAD_CALL WorkerThreadStarter(void *);
3929b1ca 72 static void sendNotification(ClientSession *session, void *arg);
ab621f39
VK
73
74protected:
75 virtual bool run();
76 virtual bool onCancel();
77
3929b1ca
VK
78 void notifyClients(bool isStatusChange);
79 void changeStatus(ServerJobStatus newStatus);
ab621f39
VK
80 void markProgress(int pctCompleted);
81 void setFailureMessage(const TCHAR *msg);
82
3929b1ca
VK
83 void setDescription(const TCHAR *description);
84
ab621f39
VK
85public:
86 ServerJob(const TCHAR *type, const TCHAR *description, DWORD node);
87 virtual ~ServerJob();
88
89 void start();
90 bool cancel();
91
3929b1ca
VK
92 void setAutoCancelDelay(int delay) { m_autoCancelDelay = delay; }
93 int getAutoCancelDelay() { return m_autoCancelDelay; }
94
8134d3a3
VK
95 void setBlockNextJobsOnFailure(bool flag) { m_blockNextJobsOnFailure = flag; }
96 bool isBlockNextJobsOnFailure() { return m_blockNextJobsOnFailure; }
97
ab621f39
VK
98 DWORD getId() { return m_id; }
99 const TCHAR *getType() { return m_type; }
100 const TCHAR *getDescription() { return m_description; }
101 ServerJobStatus getStatus() { return m_status; }
102 int getProgress() { return m_progress; }
103 DWORD getRemoteNode() { return m_remoteNode; }
104 const TCHAR *getFailureMessage() { return CHECK_NULL(m_failureMessage); }
3929b1ca 105 time_t getLastStatusChange() { return m_lastStatusChange; }
ab621f39
VK
106
107 void setOwningQueue(ServerJobQueue *queue);
3929b1ca
VK
108
109 void fillMessage(CSCPMessage *msg);
ab621f39
VK
110};
111
112
113//
114// Job queue class
115//
116
117class ServerJobQueue
118{
119private:
120 int m_jobCount;
121 ServerJob **m_jobList;
122 MUTEX m_accessMutex;
123
124public:
125 ServerJobQueue();
126 ~ServerJobQueue();
127
128 void add(ServerJob *job);
f40831eb 129 bool cancel(DWORD jobId);
ab621f39 130 void runNext();
8134d3a3 131 void cleanup();
ab621f39 132
f40831eb
VK
133 ServerJob *findJob(DWORD jobId);
134
ab621f39
VK
135 void jobCompleted(ServerJob *job);
136
137 DWORD fillMessage(CSCPMessage *msg, DWORD *varIdBase);
138};
139
140
141//
142// Job manager API
143//
144
145bool NXCORE_EXPORTABLE AddJob(ServerJob *job);
146void GetJobList(CSCPMessage *msg);
f40831eb 147DWORD CancelJob(DWORD userId, CSCPMessage *msg);
ab621f39 148
45d84f8a
VK
149
150//
151// Agent policy deployment job
152//
153
154class AgentPolicy;
155
156class PolicyDeploymentJob : public ServerJob
157{
158protected:
159 Node *m_node;
160 AgentPolicy *m_policy;
161
162 virtual bool run();
163
164public:
165 PolicyDeploymentJob(Node *node, AgentPolicy *policy);
166 virtual ~PolicyDeploymentJob();
167};
168
ab621f39 169#endif /* _nxcore_jobs_h_ */