#include <iostream>
#include <string>
#include "example_shared.h"
class Default_child_process_resolver
{
public:
const mi::IString* resolve_process(
const char* program_name,
const char* )
{
return result;
}
private:
};
int main( int argc, char* argv[])
{
if( argc < 4 || (strcmp( argv[1], "UDP") != 0 && strcmp( argv[1], "TCP") != 0)) {
std::cerr << "Usage: example_node_manager_worker UDP|TCP <nm_address> <base_address> \\\n"
" [<key=value> ...]" << std::endl;
keep_console_open();
return EXIT_FAILURE;
}
const char* mode = argv[1];
const char* node_manager_address = argv[2];
const char* multicast_base_address = argv[3];
check_success( neuray.is_valid_interface());
node_manager_factory->create_worker());
node_manager_factory = 0;
new Default_child_process_resolver( factory.get()));
worker->set_child_process_resolver( child_process_resolver.get());
child_process_resolver = 0;
factory = 0;
for( int i = 4; i < argc; i++) {
const char* equal = strchr( argv[i], '=');
check_success( equal);
std::string key( argv[i],
static_cast<mi::Size>( equal-argv[i]));
std::string value( equal+1);
worker->set_property( key.c_str(), value.c_str());
}
worker->set_multicast_base_address( multicast_base_address);
mi::Sint32 result = worker->start( node_manager_address, strcmp( mode,
"TCP") == 0);
check_success( result == 0);
std::cerr << "Worker node successfully started." << std::endl;
sleep_seconds( 30);
worker->shutdown();
worker = 0;
neuray = 0;
check_success( unload());
keep_console_open();
return EXIT_SUCCESS;
}
A simple string class.
Definition: istring.h:22
virtual void set_c_str(const char *str)=0
Sets the content via a C-style string.
Handle class template for interfaces, automatizing the lifetime control via reference counting.
Definition: handle.h:113
Mixin class template for deriving interface implementations.
Definition: interface_implement.h:41
This API component allows the creation, assignment, and cloning of instances of types.
Definition: ifactory.h:35
Factory to create node manager client and worker instances.
Definition: inode_manager.h:1090
Handle<Interface> make_handle_dup(Interface *iptr)
Converts passed-in interface pointer to a handle, without taking interface over.
Definition: handle.h:439
Uint64 Size
Unsigned integral type that is large enough to hold the size of all types.
Definition: types.h:112
signed int Sint32
32-bit signed integer.
Definition: types.h:46
#include <iostream>
#include <string>
#include "example_shared.h"
#include "example_fragmented_job.h"
void dump_properties(
const mi::IMap* properties)
{
for(
mi::Size j = 0; j < n_properties; ++j) {
const char* key = properties->
get_key( j);
std::cerr << " " << key << "=" << value->get_c_str() << std::endl;
}
}
class Accept_all_worker_nodes
{
public:
};
class Accept_all_clusters
{
public:
};
class Worker_node_property_callback
{
public:
void property_callback(
const char* changed_property_name)
{
if( changed_property_name) {
std::cerr << "Worker node " << address->get_c_str() << " changed property \""
<< changed_property_name << "\" to \"" << property->get_c_str() << "\"."
<< std::endl;
} else {
std::cerr << "Worker node " << address->get_c_str() << " communicated its properties:"
<< std::endl;
dump_properties( properties.get());
}
}
};
class Cluster_property_callback
{
public:
void property_callback(
const char* changed_property_name)
{
if( changed_property_name) {
std::cerr << "Cluster " << address->get_c_str() << " changed property \""
<< changed_property_name << "\" to \"" << property->get_c_str() << "\"."
<< std::endl;
} else {
std::cerr << "Cluster " << address->get_c_str() << " communicated its properties:"
<< std::endl;
dump_properties( properties.get());
}
}
};
class Client_node_callback
{
public:
void membership_callback( const char* address, bool flag)
{
std::cerr << "Client node " << address << (flag ? "joined" : "left")
<< " the cluster." << std::endl;
}
};
class Worker_node_callback
{
public:
{
std::cerr << "Worker node " << address->get_c_str() << (flag ? " joined" : " left")
<< " the cluster." << std::endl;
}
};
{
check_success( network_configuration->set_mode(
check_success( network_configuration->set_multicast_address( address) == 0);
check_success( dice_configuration.is_valid_interface());
check_success( dice_configuration->register_serializable_class<My_fragmented_job>());
}
{
check_success( database.is_valid_interface());
check_success( transaction.is_valid_interface());
My_fragmented_job fragmented_job;
mi::Size n = My_fragmented_job:
:N_FRAGMENTS;
transaction->execute_fragmented( &fragmented_job, n);
check_success( fragmented_job.sum_results() == expected_result);
transaction->commit();
}
int main( int argc, char* argv[])
{
if( argc != 4 || (strcmp( argv[1], "UDP") != 0 && strcmp( argv[1], "TCP") != 0)) {
std::cerr << "Usage: example_node_manager_client UDP|TCP <nm_address> <base_address>"
<< std::endl;
keep_console_open();
return EXIT_FAILURE;
}
const char* mode = argv[1];
const char* node_manager_address = argv[2];
const char* multicast_base_address = argv[3];
check_success( neuray.is_valid_interface());
node_manager_factory->create_client());
node_manager_factory = 0;
mi::Sint32 result = client->start( node_manager_address, strcmp( mode,
"TCP") == 0);
check_success( result == 0);
std::cerr << "Client node successfully started." << std::endl;
client->set_multicast_base_address( multicast_base_address);
std::cerr << "Currently known worker nodes:" << std::endl;
mi::Size n_workers = client->get_number_of_worker_nodes();
for(
mi::Size i = 0; i < n_workers; ++i) {
client->get_worker_node( i));
if( !desc.is_valid_interface())
continue;
std::cerr << "Address: " << address->get_c_str()
<< ", in cluster: " << (desc->is_in_cluster() ? "yes": "no")
<< ", properties:" << std::endl;
dump_properties( properties.get());
}
Accept_all_clusters accept_all_clusters;
Accept_all_worker_nodes accept_all_worker_nodes;
client->join_or_create_cluster( 1, 1, &accept_all_clusters, &accept_all_worker_nodes,
"./example_fragmented_job_networking", "worker %m"));
check_success( cluster.is_valid_interface());
check_success( cluster->get_cluster_status()
new Worker_node_callback);
cluster->add_worker_node_callback( worker_node_callback.get());
new Client_node_callback);
cluster->add_client_node_callback( client_node_callback.get());
new Worker_node_property_callback);
cluster->add_worker_property_callback( worker_node_property_callback.get());
new Cluster_property_callback);
cluster->add_cluster_property_callback( cluster_property_callback.get());
{
cluster->get_cluster_descriptor());
configuration( neuray.get(), address->get_c_str());
g_logger = logging_configuration->get_forwarding_logger();
logging_configuration = 0;
check_start_success( result);
run( neuray.get());
check_success( neuray->
shutdown() == 0);
g_logger = 0;
}
cluster->shutdown();
cluster = 0;
client->shutdown();
client = 0;
neuray = 0;
check_success( unload());
keep_console_open();
return EXIT_SUCCESS;
}
virtual const char * get_key(Size index) const =0
Returns the key corresponding to index.
virtual const base::IInterface * get_value(const char *key) const =0
Returns the value for key key.
This interface represents maps, i.e., a key-value based data structure.
Definition: imap.h:41
virtual Size get_length() const =0
Returns the size of the map.
This interface describes a cluster and its properties.
Definition: inode_manager.h:118
virtual const IString * get_multicast_address() const =0
Returns the multicast address reserved for the cluster.
virtual const IMap * get_properties() const =0
Returns the properties of the cluster.
This interface is used to interact with the distributed database.
Definition: idatabase.h:293
This interface allows configuration of DiCE.
Definition: dice.h:82
A transaction provides a consistent view on the database.
Definition: dice.h:272
This interface is used for configuring the logging for the DiCE library.
Definition: ilogging_configuration.h:68
This interface is used to query and change the networking configuration.
Definition: inetwork_configuration.h:33
@ MODE_UDP
Networking is switched to UDP mode with multicast.
Definition: inetwork_configuration.h:53
This is an object representing the DiCE library.
Definition: ineuray.h:44
virtual Sint32 shutdown(bool blocking=true)=0
Shuts down the library.
virtual base::IInterface * get_api_component(const base::Uuid &uuid) const =0
Returns an API component from the DiCE API.
virtual Sint32 start(bool blocking=true)=0
Starts the operation of the DiCE library.
@ CLUSTER_ESTABLISHED
The cluster has been successfully established.
Definition: inode_manager.h:367
This interface describes a worker node and its properties.
Definition: inode_manager.h:87
virtual const IString * get_address() const =0
Returns the IP address of the worker node.
virtual const IMap * get_properties() const =0
Returns the properties of the worker node.
virtual void message(Message_severity level, const char *module_category, const char *message)
Emits a message to the application's log.
Definition: ilogger.h:215
@ MESSAGE_SEVERITY_INFO
This is a normal operational message.
Definition: enums.h:39
unsigned long long Uint64
64-bit unsigned integer.
Definition: types.h:62