summaryrefslogtreecommitdiff
path: root/cpp/src/IcePack/ApplicationDeployer.cpp
blob: a3aa919da830337d72733e6a0d301cd7f51eb9e7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// **********************************************************************
//
// Copyright (c) 2001
// Mutable Realms, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************

#include <Ice/Ice.h>
#include <IcePack/ApplicationDeployer.h>
#include <IcePack/ServerDeployer.h>

using namespace std;
using namespace IcePack;

namespace IcePack
{

class AddServer : public Task
{
public:
    
    AddServer(const AdminPtr& admin, const string& name, const string& descriptor, const string& binpath, 
	      const string& libpath, const Targets& targets) :
	_admin(admin),
	_name(name),
	_descriptor(descriptor),
	_binpath(binpath),
	_libpath(libpath),
	_targets(targets)
    {
    }
    
    virtual void
    deploy()
    {
	_admin->addServer(_name, _binpath, _libpath, _descriptor, _targets);
    }

    virtual void
    undeploy()
    {
	try
	{
	    _admin->removeServer(_name);
	}
	catch(const ServerNotInactiveException&)
	{
	}
	catch(const ServerNotExistException&)
	{
	}
    }

private:

    AdminPtr _admin;
    string _name;
    string _descriptor;
    string _binpath;
    string _libpath;
    Targets _targets;
};

class ApplicationDeployHandler : public ComponentDeployHandler
{
public:

    ApplicationDeployHandler(ApplicationDeployer&);

    virtual void startElement(const XMLCh *const name, AttributeList &attrs); 

private:

    ApplicationDeployer& _deployer;
};

}

IcePack::ApplicationDeployHandler::ApplicationDeployHandler(ApplicationDeployer& deployer) :
    ComponentDeployHandler(deployer),
    _deployer(deployer)
{
}

void 
IcePack::ApplicationDeployHandler::startElement(const XMLCh *const name, AttributeList &attrs)
{
    ComponentDeployHandler::startElement(name, attrs);
    if(!isCurrentTargetDeployable())
    {
	return;
    }

    string str = toString(name);
    if(str == "server")
    {
	string name = getAttributeValue(attrs, "name");
	string descriptor = getAttributeValue(attrs, "descriptor");
	string binpath = getAttributeValueWithDefault(attrs, "binpath", "");
	string libpath = getAttributeValueWithDefault(attrs, "libpath", "");
	_deployer.addServer(name, descriptor, binpath, libpath);
    }
}

IcePack::ApplicationDeployer::ApplicationDeployer(const Ice::CommunicatorPtr& communicator,
						  const AdminPtr& admin,
						  const vector<string>& targets) :
    ComponentDeployer(communicator, "", targets),
    _admin(admin)
{
}

void
IcePack::ApplicationDeployer::parse(const string& descriptor)
{
    ApplicationDeployHandler handler(*this);    

    ComponentDeployer::parse(descriptor, handler);
}

void
IcePack::ApplicationDeployer::addServer(const string& name, 
					const string& descriptor, 
					const string& binpath,
					const string& libpath)
{
    if(name.empty())
    {
	throw DeploySAXParseException("name attribute value is empty", _locator);
    }
    if(descriptor.empty())
    {
	throw DeploySAXParseException("descriptor attribute value is empty", _locator);
    }

    _tasks.push_back(new AddServer(_admin, name, descriptor, binpath, libpath, _targets));
}