summaryrefslogtreecommitdiff
path: root/cpp/src/IcePack/ServiceDeployer.cpp
blob: 6c39de8f07daf3f22deb14fb78882e3eb5cd6bfd (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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
// **********************************************************************
//
// Copyright (c) 2001
// Mutable Realms, Inc.
// Huntsville, AL, USA
//
// All Rights Reserved
//
// **********************************************************************

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

using namespace std;
using namespace IcePack;

namespace IcePack
{

class ServiceDeployHandler : public ComponentDeployHandler
{
public:

    ServiceDeployHandler(ServiceDeployer&);

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

private:

    ServiceDeployer& _deployer;
};

}

IcePack::ServiceDeployHandler::ServiceDeployHandler(ServiceDeployer& deployer) :
    ComponentDeployHandler(deployer),
    _deployer(deployer)
{
}

void
IcePack::ServiceDeployHandler::startDocument()
{
}

void 
IcePack::ServiceDeployHandler::startElement(const XMLCh *const name, AttributeList &attrs)
{
    ComponentDeployHandler::startElement(name, attrs);

    string str = toString(name);

    if(str == "service")
    {
	string basedir = getAttributeValueWithDefault(attrs, "basedir", "");
	if(!basedir.empty())
	{
	    _deployer.overrideBaseDir(basedir);
	}

	string kind = getAttributeValue(attrs, "kind");
	if(kind == "standard")
	{
	    _deployer.setKind(ServiceDeployer::ServiceKindStandard);
	}
	else if(kind == "freeze")
	{
	    _deployer.setKind(ServiceDeployer::ServiceKindFreeze);
	    _deployer.setDBEnv(getAttributeValueWithDefault(attrs, "dbenv", ""));
	}

	_deployer.createConfigFile("/config/config_" + _deployer.substitute("${name}"));
	_deployer.setEntryPoint(getAttributeValue(attrs, "entry"));
    }
    else if(str == "adapter")
    {
	_deployer.getServerDeployer().addAdapter(getAttributeValue(attrs, "name"), 
						 getAttributeValueWithDefault(attrs, "endpoints", ""));
    }
}

void
IcePack::ServiceDeployHandler::endElement(const XMLCh *const name)
{
    string str = toString(name);

    ComponentDeployHandler::endElement(name);
}

IcePack::ServiceDeployer::ServiceDeployer(const Ice::CommunicatorPtr& communicator,
					  ServerDeployer& serverDeployer,
					  const map<string, string>& variables) :
    ComponentDeployer(communicator),
    _serverDeployer(serverDeployer)
{
    _variables = variables;
}

void
IcePack::ServiceDeployer::parse(const string& descriptor)
{
    ServiceDeployHandler handler(*this);
    
    ComponentDeployer::parse(descriptor, handler);
}

ServerDeployer&
IcePack::ServiceDeployer::getServerDeployer() const
{
    return _serverDeployer;
}

void
IcePack::ServiceDeployer::setKind(ServiceKind kind)
{
    _kind = kind;
}

void
IcePack::ServiceDeployer::setEntryPoint(const string& entry)
{
    assert(!_configFile.empty());
    _serverDeployer.addProperty("IceBox.Service." + _variables["name"], entry + " --Ice.Config=" + _configFile);
}

void
IcePack::ServiceDeployer::setDBEnv(const string& dir)
{
    if(_kind != ServiceKindFreeze)
    {
	throw DeploySAXParseException("database environment is only allowed for Freeze services", _locator);
    }

    string path;

    if(dir.empty())
    {
	//
	// Provides database environment directory only if the
	// database environment attribute is not specified. If it's
	// specified, it's most likely because we share database
	// environments and then it's the responsabilility of the user
	// to manage the database environment directory.
	//
	createDirectory("/dbs/" + _variables["name"], true);
	path = _variables["datadir"] + "/dbs/" + _variables["name"];
    }
    else
    {
	path = dir[0] == '/' ? dir : _variables["basedir"] + "/" + dir;
    }
    _serverDeployer.addProperty("IceBox.DBEnvName." + _variables["name"], path);
}