summaryrefslogtreecommitdiff
path: root/cpp/src/IcePack/ServiceDeployer.cpp
blob: 38ac5917678b3f7852aef957da6125e297bb3098 (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
// **********************************************************************
//
// 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 kind = getAttributeValue(attrs, "kind");
	if(kind == "standard")
	{
	    _deployer.setKind(ServiceDeployer::ServiceKindStandard);
	}
	else if(kind == "freeze")
	{
	    _deployer.setKind(ServiceDeployer::ServiceKindFreeze);
	    _deployer.setDBEnv(getAttributeValueWithDefault(attrs, "dbenv", "${name}"));
	}

	_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)
{
    assert(!dir.empty());

    if(_kind != ServiceKindFreeze)
    {
	cerr << "Database environment is only allowed for Freeze services." << endl;
	_error++;
	return;
    }

    createDirectory("/dbs" + (dir[0] == '/' ? dir : "/" + dir));
    addProperty("IceBox.DBEnvName." + _variables["name"], 
		_variables["datadir"] + "/dbs" + (dir[0] == '/' ? dir : "/" + dir));
}