Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SetEnv added for plugin Config as well #1764

Merged
merged 6 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 2 additions & 60 deletions Source/Thunder/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,64 +114,6 @@ namespace PluginHost {
// Configuration to get a server (PluginHost server) up and running.
class JSONConfig : public Core::JSON::Container {
public:
class Environment : public Core::JSON::Container {
public:
Environment()
: Core::JSON::Container()
, Key()
, Value()
, Override(false)
{
Add(_T("key"), &Key);
Add(_T("value"), &Value);
Add(_T("override"), &Override);
}
Environment(const Environment& copy)
: Core::JSON::Container()
, Key(copy.Key)
, Value(copy.Value)
, Override(copy.Override)
{
Add(_T("key"), &Key);
Add(_T("value"), &Value);
Add(_T("override"), &Override);
}
Environment(Environment&& move) noexcept
: Core::JSON::Container()
, Key(std::move(move.Key))
, Value(std::move(move.Value))
, Override(std::move(move.Override))
{
Add(_T("key"), &Key);
Add(_T("value"), &Value);
Add(_T("override"), &Override);
}
~Environment() override = default;
Environment& operator=(const Environment& RHS)
{
Key = RHS.Key;
Value = RHS.Value;
Override = RHS.Override;

return (*this);
}
Environment& operator=(Environment&& move) noexcept
{
if (this != &move) {
Key = std::move(move.Key);
Value = std::move(move.Value);
Override = std::move(move.Override);
}

return (*this);
}

public:
Core::JSON::String Key;
Core::JSON::String Value;
Core::JSON::Boolean Override;
};

class ProcessSet : public Core::JSON::Container {
public:
ProcessSet()
Expand Down Expand Up @@ -526,7 +468,7 @@ namespace PluginHost {
Core::JSON::String Configs;
Core::JSON::String EthernetCard;
Core::JSON::ArrayType<Plugin::Config> Plugins;
Core::JSON::ArrayType<Environment> Environments;
Core::JSON::ArrayType<Plugin::Config::Environment> Environments;
Core::JSON::ArrayType<Core::JSON::EnumType<PluginHost::IShell::reason>> ExitReasons;
Core::JSON::DecSInt32 Latitude;
Core::JSON::DecSInt32 Longitude;
Expand Down Expand Up @@ -773,7 +715,7 @@ namespace PluginHost {
}

bool status = true;
Core::JSON::ArrayType<JSONConfig::Environment>::ConstIterator index(static_cast<const JSONConfig&>(config).Environments.Elements());
Core::JSON::ArrayType<Plugin::Config::Environment>::ConstIterator index(static_cast<const JSONConfig&>(config).Environments.Elements());
while (index.Next() == true) {
if ((index.Current().Key.IsSet() == true) && (index.Current().Value.IsSet() == true)) {
string value = _substituter.Substitute(index.Current().Value.Value(), nullptr);
Expand Down
3 changes: 2 additions & 1 deletion Source/Thunder/IRemoteInstantiation.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ namespace PluginHost {
const string& systemRootPath,
const uint8_t threads,
const int8_t priority,
const string configuration) = 0;
const string configuration,
const std::vector<string>& environments) = 0;
HaseenaSainul marked this conversation as resolved.
Show resolved Hide resolved
};
}
}
38 changes: 32 additions & 6 deletions Source/Thunder/PluginServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -1277,7 +1277,28 @@ namespace PluginHost {
string Substitute(const string& input) const override {
return (_administrator.Configuration().Substitute(input, PluginHost::Service::Configuration()));
}
Core::hresult Metadata(string& info /* @out */) const override {
std::vector<string> SubstituteList(const string& envs) const override {

std::vector<string> environmentList;;
Plugin::Config::EnvironmentList environments;
environments.FromString(envs);
if (environments.IsSet() == true) {
Core::JSON::ArrayType<Plugin::Config::Environment>::Iterator index(environments.Elements());
while (index.Next() == true) {
if ((index.Current().Key.IsSet() == true) && (index.Current().Value.IsSet() == true)) {
index.Current().Value = Substitute(index.Current().Value.Value());
string env = index.Current().Key.Value() + Plugin::Config::EnvFieldSeparator +
index.Current().Value.Value() + Plugin::Config::EnvFieldSeparator +
((index.Current().Override.Value() == true) ? "1" : "0");
environmentList.push_back(env);
} else {
SYSLOG(Logging::Startup, (_T("Failure in Substituting Value of Key:Value:[%s]:[%s]\n"), index.Current().Key.Value().c_str(), index.Current().Value.Value().c_str()));
}
}
}
return environmentList;
}
Core::hresult Metadata(string& info /* @out */) const override {
Metadata::Service result;
GetMetadata(result);
result.ToString(info);
Expand Down Expand Up @@ -1499,7 +1520,9 @@ namespace PluginHost {
else {
uint32_t pid;
Core::ServiceAdministrator::Instance().ReleaseLibrary(std::move(_library));

string environments;
PluginHost::Service::Configuration().Root.Environments.ToString(environments);

RPC::Object definition(locator,
classNameString,
Callsign(),
Expand All @@ -1512,7 +1535,8 @@ namespace PluginHost {
PluginHost::Service::Configuration().Root.HostType(),
SystemRootPath(),
PluginHost::Service::Configuration().Root.RemoteAddress.Value(),
PluginHost::Service::Configuration().Root.Configuration.Value());
PluginHost::Service::Configuration().Root.Configuration.Value(),
SubstituteList(environments));

newIF = reinterpret_cast<IPlugin*>(Instantiate(definition, _administrator.Configuration().OutOfProcessWaitTime(), pid));
if (newIF == nullptr) {
Expand Down Expand Up @@ -2019,7 +2043,8 @@ namespace PluginHost {
_object.SystemRootPath(),
_object.Threads(),
_object.Priority(),
_object.Configuration());
_object.Configuration(),
_object.Environments());

instantiation->Release();
}
Expand Down Expand Up @@ -2399,7 +2424,8 @@ namespace PluginHost {
const string& systemRootPath,
const uint8_t threads,
const int8_t priority,
const string configuration) override
const string configuration,
const std::vector<string>& environments) override
{
string persistentPath(_comms.PersistentPath());
string dataPath(_comms.DataPath());
Expand All @@ -2413,7 +2439,7 @@ namespace PluginHost {

uint32_t id;
RPC::Config config(_connector, _comms.Application(), persistentPath, _comms.SystemPath(), dataPath, volatilePath, _comms.AppPath(), _comms.ProxyStubPath(), _comms.PostMortemPath(), _comms.LinkerPaths());
RPC::Object instance(libraryName, className, callsign, interfaceId, version, user, group, threads, priority, RPC::Object::HostType::LOCAL, systemRootPath, _T(""), configuration);
RPC::Object instance(libraryName, className, callsign, interfaceId, version, user, group, threads, priority, RPC::Object::HostType::LOCAL, systemRootPath, _T(""), configuration, environments);

RPC::Communicator::Process process(requestId, config, instance);

Expand Down
30 changes: 30 additions & 0 deletions Source/ThunderPlugin/Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ POP_WARNING()
string ProxyStubPath;
string PostMortemPath;
string SystemRootPath;
std::vector<string> Environments;
const TCHAR* User;
const TCHAR* Group;
uint8_t Threads;
Expand Down Expand Up @@ -250,6 +251,9 @@ POP_WARNING()
case 'S':
SystemRootPath = Core::Directory::Normalize(Strip(argument));
break;
case 'e':
Environments.push_back(Strip(argument));
break;
case 'v':
VolatilePath = Core::Directory::Normalize(Strip(argument));
break;
Expand Down Expand Up @@ -588,6 +592,7 @@ int main(int argc, char** argv)
printf(" [-d <data path>]\n");
printf(" [-v <volatile path>]\n");
printf(" [-f <linker_path>...\n");
printf(" [-e <environment values>...]\n\n");
printf(" [-a <app path>]\n");
printf(" [-m <proxy stub library path>]\n");
printf(" [-P <post mortem path>]\n\n");
Expand Down Expand Up @@ -664,6 +669,31 @@ int main(int argc, char** argv)
Core::ProcessCurrent().User(string(options.User));
}

for (const string& env : options.Environments) {
size_t start = env.find_first_of(Plugin::Config::EnvFieldSeparator);
if ((start != string::npos) && (start < env.length())) {
size_t end = env.find_last_of(Plugin::Config::EnvFieldSeparator);
if ((end != string::npos) && (start != end)) {
string key = env.substr(0, start);
string value = env.substr(start + 1, end - (start + 1));
string overrideStr = env.substr(end + 1);

bool toOverride = ((overrideStr.size() == 1) && (overrideStr == "1")) ? true: false;

if ((key.empty() != true) && (value.empty() != true)) {
uint32_t status = Core::SystemInfo::SetEnvironment(key, value.c_str(), toOverride);
if (status != true) {
SYSLOG(Logging::Startup, (_T("Failure in setting Key:Value:[%s]:[%s]\n"), key.c_str(), value.c_str()));
}
} else {
SYSLOG(Logging::Startup, (_T("Environment key:value fromat is invalid :[%s]:[%s]\n"), key.c_str(), value.c_str()));
}
} else {
SYSLOG(Logging::Startup, (_T("Invalid Enviroment value :[%s]\n"), env.c_str()));
}
}
}

process.Startup(options.Threads, remoteNode, callsign);

// Register an interface to handle incoming requests for interfaces.
Expand Down
19 changes: 17 additions & 2 deletions Source/com/Communicator.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ namespace RPC {
, _systemRootPath()
, _remoteAddress()
, _configuration()
, _environments()
{
}
Object(const Object& copy)
Expand All @@ -81,6 +82,7 @@ namespace RPC {
, _systemRootPath(copy._systemRootPath)
, _remoteAddress(copy._remoteAddress)
, _configuration(copy._configuration)
, _environments(copy._environments)
{
}
Object(Object&& move) noexcept
Expand All @@ -97,6 +99,7 @@ namespace RPC {
, _systemRootPath(std::move(move._systemRootPath))
, _remoteAddress(std::move(move._remoteAddress))
, _configuration(std::move(move._configuration))
, _environments(std::move(move._environments))
{
}
Object(const string& locator,
Expand All @@ -111,7 +114,8 @@ namespace RPC {
const HostType type,
const string& systemRootPath,
const string& remoteAddress,
const string& configuration)
const string& configuration,
const std::vector<string>& environments)
: _locator(locator)
, _className(className)
, _callsign(callsign)
Expand All @@ -125,6 +129,7 @@ namespace RPC {
, _systemRootPath(systemRootPath)
, _remoteAddress(remoteAddress)
, _configuration(configuration)
, _environments(environments)
{
}
~Object()
Expand All @@ -146,6 +151,7 @@ namespace RPC {
_type = RHS._type;
_remoteAddress = RHS._remoteAddress;
_configuration = RHS._configuration;
_environments = RHS._environments;

return (*this);
}
Expand All @@ -166,6 +172,7 @@ namespace RPC {
_systemRootPath = std::move(move._systemRootPath);
_remoteAddress = std::move(move._remoteAddress);
_configuration = std::move(move._configuration);
_environments = std::move(move._environments);

move._interface = ~0;
move._version = ~0;
Expand Down Expand Up @@ -228,6 +235,10 @@ namespace RPC {
{
return (_configuration);
}
inline const std::vector<string>& Environments() const
{
return (_environments);
}

private:
string _locator;
Expand All @@ -243,6 +254,7 @@ namespace RPC {
string _systemRootPath;
string _remoteAddress;
string _configuration;
std::vector<string> _environments;
};

class EXTERNAL Config {
Expand Down Expand Up @@ -300,7 +312,7 @@ namespace RPC {
, _linker(copy._linker)
{
}
Config(Config&& move) noexcept
Config(Config&& move) noexcept
: _connector(std::move(move._connector))
, _hostApplication(std::move(move._hostApplication))
, _persistent(std::move(move._persistent))
Expand Down Expand Up @@ -515,6 +527,9 @@ namespace RPC {
if (instance.Threads() > 1) {
_options.Add(_T("-t")).Add(Core::NumberType<uint8_t>(instance.Threads()).Text());
}
for (auto const& env : instance.Environments()) {
_options.Add(_T("-e")).Add('"' + env + '"');
}
_priority = instance.Priority();
}
const string& Command() const
Expand Down
Loading
Loading