bug #255 fixed; minor changes in Java UI
[public/netxms.git] / src / server / core / ap_jobs.cpp
CommitLineData
45d84f8a
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: ap_jobs.cpp
20**
21**/
22
23#include "nxcore.h"
24
25
26//
27// Constructor
28//
29
30PolicyDeploymentJob::PolicyDeploymentJob(Node *node, AgentPolicy *policy)
31 : ServerJob(_T("DEPLOY_AGENT_POLICY"), _T("Deploy agent policy"), node->Id())
32{
33 m_node = node;
34 m_policy = policy;
35 node->IncRefCount();
36 policy->IncRefCount();
37
38 TCHAR buffer[1024];
39 _sntprintf(buffer, 1024, _T("Deploy policy %s"), policy->Name());
40 setDescription(buffer);
41}
42
43
44//
45// Destructor
46//
47
48PolicyDeploymentJob::~PolicyDeploymentJob()
49{
50 m_node->DecRefCount();
51 m_policy->DecRefCount();
52}
53
54
55//
56// Run job
57//
58
59bool PolicyDeploymentJob::run()
60{
61 bool success = false;
62
63 AgentConnectionEx *conn = m_node->CreateAgentConnection();
64 if (conn != NULL)
65 {
66 DWORD rcc = conn->deployPolicy(m_policy);
67 if (rcc == ERR_SUCCESS)
68 {
69 success = true;
70 }
71 else
72 {
73 setFailureMessage(AgentErrorCodeToText(rcc));
74 }
75 }
76 else
77 {
78 setFailureMessage(_T("Agent connection not available"));
79 }
80 return success;
81}