generated from mochi-hpc/thallium-microservice-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* updated bedrock module * added test * fixed configuration space
- Loading branch information
Showing
14 changed files
with
132 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,54 @@ | ||
/* | ||
* (C) 2020 The University of Chicago | ||
* (C) 2024 The University of Chicago | ||
* | ||
* See COPYRIGHT in top-level directory. | ||
*/ | ||
#include "mofka/Client.hpp" | ||
#include "mofka/Provider.hpp" | ||
#include "mofka/ProviderHandle.hpp" | ||
#include <bedrock/AbstractServiceFactory.hpp> | ||
|
||
namespace tl = thallium; | ||
|
||
class MofkaFactory : public bedrock::AbstractServiceFactory { | ||
|
||
public: | ||
|
||
MofkaFactory() {} | ||
#include <bedrock/AbstractComponent.hpp> | ||
|
||
void *registerProvider(const bedrock::FactoryArgs &args) override { | ||
mofka::Metadata config; | ||
try { | ||
config = mofka::Metadata{args.config.c_str(), true}; | ||
} catch(const mofka::Exception& ex) { | ||
spdlog::error("Error parsing configuration for Mofka provider: {}", ex.what()); | ||
return nullptr; | ||
} | ||
auto provider = new mofka::Provider( | ||
args.mid, args.provider_id, | ||
config, tl::pool(args.pool), | ||
args.dependencies); | ||
return static_cast<void *>(provider); | ||
} | ||
namespace tl = thallium; | ||
|
||
void deregisterProvider(void *p) override { | ||
auto provider = static_cast<mofka::Provider *>(p); | ||
delete provider; | ||
} | ||
class MofkaComponent : public bedrock::AbstractComponent { | ||
|
||
std::string getProviderConfig(void *p) override { | ||
auto provider = static_cast<mofka::Provider *>(p); | ||
return provider->getConfig().string(); | ||
} | ||
std::unique_ptr<mofka::Provider> m_provider; | ||
|
||
void *initClient(const bedrock::FactoryArgs& args) override { | ||
return static_cast<void *>(new mofka::Client(args.mid)); | ||
} | ||
|
||
void finalizeClient(void *client) override { | ||
delete static_cast<mofka::Client *>(client); | ||
} | ||
public: | ||
|
||
std::string getClientConfig(void* c) override { | ||
auto client = static_cast<mofka::Client*>(c); | ||
return client->getConfig().string(); | ||
} | ||
MofkaComponent(const tl::engine& engine, | ||
uint16_t provider_id, | ||
const mofka::Metadata& config, | ||
const bedrock::ResolvedDependencyMap& dependencies) | ||
: m_provider{std::make_unique<mofka::Provider>(engine, provider_id, config, dependencies)} | ||
{} | ||
|
||
void *createProviderHandle(void *c, hg_addr_t address, | ||
uint16_t provider_id) override { | ||
auto client = static_cast<mofka::Client *>(c); | ||
auto ph = new mofka::ProviderHandle( | ||
client->engine(), | ||
address, | ||
provider_id, | ||
false); | ||
return static_cast<void *>(ph); | ||
void* getHandle() override { | ||
return static_cast<void*>(m_provider.get()); | ||
} | ||
|
||
void destroyProviderHandle(void *providerHandle) override { | ||
auto ph = static_cast<mofka::ProviderHandle *>(providerHandle); | ||
delete ph; | ||
std::string getConfig() override { | ||
return m_provider->getConfig().string(); | ||
} | ||
|
||
std::vector<bedrock::Dependency> getProviderDependencies(const char* config) override { | ||
auto config_metadata = mofka::Metadata{config, true}; | ||
return mofka::Provider::getDependencies(config_metadata); | ||
} | ||
static std::shared_ptr<bedrock::AbstractComponent> | ||
Register(const bedrock::ComponentArgs& args) { | ||
tl::pool pool; | ||
auto it = args.dependencies.find("pool"); | ||
if(it != args.dependencies.end() && !it->second.empty()) { | ||
pool = it->second[0]->getHandle<tl::pool>(); | ||
} | ||
auto config = mofka::Metadata{args.config, true}; | ||
return std::make_shared<MofkaComponent>( | ||
args.engine, args.provider_id, config, args.dependencies); | ||
} | ||
|
||
const std::vector<bedrock::Dependency> &getClientDependencies() override { | ||
static const std::vector<bedrock::Dependency> no_dependency; | ||
return no_dependency; | ||
} | ||
static std::vector<bedrock::Dependency> | ||
GetDependencies(const bedrock::ComponentArgs& args) { | ||
auto config_metadata = mofka::Metadata{args.config, true}; | ||
return mofka::Provider::getDependencies(config_metadata); | ||
} | ||
}; | ||
|
||
BEDROCK_REGISTER_MODULE_FACTORY(mofka, MofkaFactory) | ||
BEDROCK_REGISTER_COMPONENT_TYPE(mofka, MofkaComponent) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.