Added JobRetryCount server configuration parameter
[public/netxms.git] / src / server / core / ap_jobs.cpp
CommitLineData
a2871ffc 1/*
45d84f8a 2** NetXMS - Network Management System
21c9acce 3** Copyright (C) 2003-2013 Victor Kirhenshtein
45d84f8a
VK
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: ap_jobs.cpp
20**
21**/
22
23#include "nxcore.h"
24
21c9acce
VK
25/**
26 * Constructor
27 */
967893bb 28PolicyDeploymentJob::PolicyDeploymentJob(Node *node, AgentPolicy *policy, UINT32 userId)
c42b4551 29 : ServerJob(_T("DEPLOY_AGENT_POLICY"), _T("Deploy agent policy"), node->getId(), userId, false)
45d84f8a
VK
30{
31 m_node = node;
32 m_policy = policy;
21c9acce
VK
33 node->incRefCount();
34 policy->incRefCount();
45d84f8a
VK
35
36 TCHAR buffer[1024];
c42b4551 37 _sntprintf(buffer, 1024, _T("Deploy policy %s"), policy->getName());
45d84f8a
VK
38 setDescription(buffer);
39}
40
21c9acce
VK
41/**
42 * Destructor
43 */
45d84f8a
VK
44PolicyDeploymentJob::~PolicyDeploymentJob()
45{
21c9acce
VK
46 m_node->decRefCount();
47 m_policy->decRefCount();
45d84f8a
VK
48}
49
21c9acce
VK
50/**
51 * Run job
52 */
45d84f8a
VK
53bool PolicyDeploymentJob::run()
54{
693ac985 55 bool success = false;
45d84f8a 56
693ac985 57 TCHAR jobName[1024];
c42b4551 58 _sntprintf(jobName, 1024, _T("Deploy policy %s"), m_policy->getName());
693ac985
AK
59
60 do
61 {
62 setDescription(jobName);
63 AgentConnectionEx *conn = m_node->createAgentConnection();
64 if (conn != NULL)
65 {
66 UINT32 rcc = conn->deployPolicy(m_policy);
1693f955 67 conn->decRefCount();
693ac985
AK
68 if (rcc == ERR_SUCCESS)
69 {
70 m_policy->linkNode(m_node);
71 success = true;
72 break;
73 }
74 else
75 {
76 setFailureMessage(AgentErrorCodeToText(rcc));
77 }
78 }
79 else
80 {
81 setFailureMessage(_T("Agent connection not available"));
82 }
83
a2871ffc 84 setDescription(_T("Policy deploy failed. Wainting 10 minutes to restart job."));
693ac985 85 success = SleepAndCheckForShutdown(600);
400e55c4 86 } while(!success);
693ac985 87
93599cfd
VK
88 return success;
89}
90
21c9acce
VK
91/**
92 * Constructor
93 */
967893bb 94PolicyUninstallJob::PolicyUninstallJob(Node *node, AgentPolicy *policy, UINT32 userId)
c42b4551 95 : ServerJob(_T("UNINSTALL_AGENT_POLICY"), _T("Uninstall agent policy"), node->getId(), userId, false)
93599cfd
VK
96{
97 m_node = node;
98 m_policy = policy;
21c9acce
VK
99 node->incRefCount();
100 policy->incRefCount();
93599cfd
VK
101
102 TCHAR buffer[1024];
c42b4551 103 _sntprintf(buffer, 1024, _T("Uninstall policy %s"), policy->getName());
93599cfd
VK
104 setDescription(buffer);
105}
106
21c9acce
VK
107/**
108 * Destructor
109 */
93599cfd
VK
110PolicyUninstallJob::~PolicyUninstallJob()
111{
21c9acce
VK
112 m_node->decRefCount();
113 m_policy->decRefCount();
93599cfd
VK
114}
115
21c9acce
VK
116/**
117 * Run job
118 */
93599cfd
VK
119bool PolicyUninstallJob::run()
120{
121 bool success = false;
122
cd9f247e 123 AgentConnectionEx *conn = m_node->createAgentConnection();
93599cfd
VK
124 if (conn != NULL)
125 {
967893bb 126 UINT32 rcc = conn->uninstallPolicy(m_policy);
1693f955 127 conn->decRefCount();
93599cfd
VK
128 if (rcc == ERR_SUCCESS)
129 {
130 m_policy->unlinkNode(m_node);
45d84f8a
VK
131 success = true;
132 }
133 else
134 {
135 setFailureMessage(AgentErrorCodeToText(rcc));
136 }
137 }
138 else
139 {
140 setFailureMessage(_T("Agent connection not available"));
141 }
142 return success;
143}