diff options
Diffstat (limited to 'modules/CIAO/DAnCE/TargetManager')
20 files changed, 2703 insertions, 0 deletions
diff --git a/modules/CIAO/DAnCE/TargetManager/CmpClient.cpp b/modules/CIAO/DAnCE/TargetManager/CmpClient.cpp new file mode 100644 index 00000000000..8317cd05e97 --- /dev/null +++ b/modules/CIAO/DAnCE/TargetManager/CmpClient.cpp @@ -0,0 +1,305 @@ +// $Id$ +/** + * @file CmpClient.cpp + * + * @brief This file contains a client of TargetManager. + * + * It picks up the TM ior from the Targetmanager.ior file + * present in the current directory, and makes the calls on the + * TM to getAllResources and getAvailable resources + */ + +#include "DAnCE/Deployment/Deployment_DataC.h" +#include "DAnCE/Deployment/Deployment_ResourceCommitmentManagerC.h" +#include "DAnCE/TargetManager/TargetManagerC.h" +#include "ace/streams.h" +#include "ace/FILE_IO.h" +#include "ace/FILE_Connector.h" +#include "ace/FILE_Addr.h" +#include "ace/Get_Opt.h" +#include "tools/Config_Handlers/DnC_Dump.h" + +/** + * TM_Tester contains the code to test the TM Component + */ +namespace TM_Tester +{ + /** + * writes the extracted data to file + */ + void write_to_file (::Deployment::Domain domain); + + /// variable contains IOR of the TM + const ACE_TCHAR * stringified_TM_IOR; + + /// if add or delete from domain + bool add_to_domain = true; + + /// whether to test update domain or not + bool call_update = false; + + /// contains the host name + const ACE_TCHAR* host_name; + + /// parses the arguments and extracts the params + bool parse_args (int argc, ACE_TCHAR *argv[]) + { + ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("t:u:d")); + int c; + while ((c = get_opts ()) != -1) + switch (c) + { + case 't': + stringified_TM_IOR = get_opts.opt_arg (); + break; + case 'u': + host_name = get_opts.opt_arg (); + call_update = true; + break; + case 'd': + add_to_domain = false; + break; + case '?': // display help for use of the server. + default: + DANCE_ERROR_RETURN ((LM_ERROR, + "usage: %s\n" + "-t <TM_IOR>\n" + "-u <host_name in update>\n" + "-n <delete , default add>\n" + "\n", + argv [0]), + false); + } + + return true; + } +} + + /// The main function + int ACE_TMAIN (int argc, ACE_TCHAR* argv[]) + { + try { + // First initialize the ORB, that will remove some arguments... + CORBA::ORB_var orb = + CORBA::ORB_init (argc, argv); + + if (!TM_Tester::parse_args (argc, argv)) + return -1; + + // Use the first argument to create the factory object reference, + // in real applications we use the naming service, but let's do + // the easy part first! + CORBA::Object_var factory_object = + orb->string_to_object (TM_Tester::stringified_TM_IOR); + + // Now downcast the object reference to the appropriate type + CIAO::TargetManagerImpl_var targetCmp = + CIAO::TargetManagerImpl::_narrow (factory_object.in ()); + + // Now get the facet reference from the target Manager Component + Deployment::TargetManager_ptr targetI = targetCmp->provide_targetMgr (); + + // Now make calls on the Target Manager facet + + try + { + Deployment::Domain_var domainV = targetI->getAllResources (); + ::Deployment::DnC_Dump::dump (domainV); + } + catch(CORBA::NO_IMPLEMENT &) + { + DANCE_ERROR ((LM_ERROR ,"Error:TargetManager:CORBA::NO_IMPLEMENT thrown\n")); + } + catch(CORBA::Exception &) + { + DANCE_ERROR ((LM_ERROR ,"Error:TargetManager:CORBA Generic Exception\n")); + DANCE_ERROR ((LM_ERROR ,"Error:TargetManager:Exception in TargetManager call\n")); + } + + + // make a call to the commit resources ..... + + bool resource_available = true; + + ::Deployment::ResourceAllocations resource_seq; + + resource_seq.length (1); + + resource_seq[0].elementName = CORBA::string_dup ("TargetManagerNode_1"); + + resource_seq[0].resourceName = CORBA::string_dup ("Processor"); + + resource_seq[0].property.length (1); + resource_seq[0].property[0].name = + CORBA::string_dup ("LoadAverage"); + + CORBA::Long d = 20; + resource_seq[0].property[0].value <<= d; + + ::Deployment::ResourceCommitmentManager_ptr manager = + ::Deployment::ResourceCommitmentManager::_nil (); + + try + { + manager = targetI->commitResources (resource_seq); + } + catch(const CORBA::NO_IMPLEMENT &) + { + DANCE_ERROR ((LM_ERROR, "Error:TargetManager:CORBA::NO_IMPLEMENT thrown\n")); + } + catch (const ::Deployment::ResourceCommitmentFailure& e) + { + resource_available = 0; + DANCE_ERROR ((LM_ERROR, "TargetManager commitResources ResourceCommitmentFailure Exception\n")); + + DANCE_ERROR ((LM_ERROR , + "ResourceCommitmentFailure\n reason=[%C]\n elementName=[%C]\n resourceName=[%C]\n propertyName=[%C]\n", + e.reason.in (), + resource_seq[e.index].elementName.in (), + resource_seq[e.index].resourceName.in (), + e.propertyName.in ())); + } + catch(const CORBA::Exception &) + { + DANCE_ERROR ((LM_ERROR, "Error:TargetManager:commitResources Exception\n")); + DANCE_ERROR ((LM_ERROR, "Error:TargetManager:CORBA Generic Exception\n")); + DANCE_ERROR ((LM_ERROR, "Error:TargetManager:Exception in TargetManager call")); + } + + // Make a call to release resources , if resource < 0 + try + { + { + d = 10; + resource_seq[0].property[0].value <<= d; + manager->releaseResources (resource_seq); + } + } + catch(const CORBA::NO_IMPLEMENT &) + { + DANCE_ERROR ((LM_ERROR, "Error:TargetManager:CORBA::NO_IMPLEMENT thrown\n")); + } + catch (const Deployment::ResourceCommitmentFailure&) + { + DANCE_ERROR ((LM_ERROR, "Error:TargetManager releaseResources ResourceNotAvailable Exception\n")); + } + catch(const CORBA::Exception &) + { + DANCE_ERROR ((LM_ERROR, "Error:TargetManager:releaseResources Exception\n")); + DANCE_ERROR ((LM_ERROR, "Error:TargetManager:CORBA Generic Exception\n")); + DANCE_ERROR ((LM_ERROR, "Error:TargetManager:Exception in TargetManager call")); + } + + // Here make a call on the TM with update domain and node deletion + + ::Deployment::Domain updated; + updated.node.length (1); + updated.node[0].name = CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR (TM_Tester::host_name)); + + ::CORBA::StringSeq elements; + elements.length (0); + + + if (TM_Tester::call_update) + { + if (TM_Tester::add_to_domain) + { + try + { + targetI->updateDomain (elements , updated, ::Deployment::Add); + } + catch(CORBA::NO_IMPLEMENT &) + { + DANCE_ERROR ((LM_ERROR, "Error:TargetManager:CORBA::NO_IMPLEMENT thrown\n")); + } + catch(CORBA::Exception &) + { + DANCE_ERROR ((LM_ERROR, "Error:TargetManager:CORBA Generic Exception\n")); + DANCE_ERROR ((LM_ERROR, "Error:TargetManager:Exception in UpdateDomain call")); + } + } + else + { + try + { + targetI->updateDomain (elements , updated, ::Deployment::Delete); + } + catch(CORBA::NO_IMPLEMENT &) + { + DANCE_ERROR ((LM_ERROR, "Error:TargetManager:CORBA::NO_IMPLEMENT thrown\n")); + } + catch(CORBA::Exception &) + { + DANCE_ERROR ((LM_ERROR, "Error:TargetManager:CORBA Generic Exception\n")); + DANCE_ERROR ((LM_ERROR, "Error:TargetManager:Exception in UpdateDomain call")); + } + } + } + + // Now make a call of getAvailableResources on the TargetManager ... + try + { + Deployment::Domain_var domainV = targetI->getAvailableResources(); + + // here write things to file ... + TM_Tester::write_to_file (domainV.in()); + + ::Deployment::DnC_Dump::dump (domainV); + } + catch(CORBA::NO_IMPLEMENT &) + { + DANCE_ERROR ((LM_ERROR, "Error:TargetManager:CORBA::NO_IMPLEMENT thrown\n")); + } + catch(CORBA::Exception &) + { + DANCE_ERROR ((LM_ERROR ,"Error:TargetManager:CORBA Generic Exception\n")); + DANCE_ERROR ((LM_ERROR, "Error:TargetManager:Exception in TargetManager call\n")); + } + + // Finally destroy the ORB + orb->destroy (); + } + catch (CORBA::Exception &) + { + DANCE_ERROR ((LM_ERROR, "Error:TargetManager:CORBA exception raised!\n")); + } + return 0; + } + +namespace TM_Tester +{ + void write_to_file (::Deployment::Domain domain) + { + for (size_t i = 0;i < domain.node.length ();i++) + { + std::ofstream out (domain.node[i].name.in ()); + + // write in the node usage ... + for (CORBA::ULong j = 0;j < domain.node[i].resource.length ();j++) + { + + if (!ACE_OS::strcmp (domain.node[i].resource[j].name.in (), "Processor")) + { + CORBA::Double node_cpu; + domain.node[i].resource[j].property[0].value >>= node_cpu; + out << node_cpu << std::endl; + } + if (!ACE_OS::strcmp (domain.node[i].resource[j].name.in (), "NA_Monitor")) + { + std::string file_name = "NA_"; + file_name += domain.node[i].name.in (); + ACE_FILE_IO file_io; + ACE_FILE_Connector (file_io, ACE_FILE_Addr (ACE_TEXT_ALWAYS_CHAR (file_name.c_str ()))); + CORBA::Double na_node_cpu; + domain.node[i].resource[j].property[0].value >>= na_node_cpu; + char buf[BUFSIZ]; + ACE_OS::memset (buf , 0 , BUFSIZ); + ACE_OS::sprintf (buf , "%f", na_node_cpu); + file_io.send (buf, ACE_OS::strlen (buf)); + } + } + + out.close (); + } + } +} diff --git a/modules/CIAO/DAnCE/TargetManager/DAnCE_TargetManagerDaemon.idl b/modules/CIAO/DAnCE/TargetManager/DAnCE_TargetManagerDaemon.idl new file mode 100644 index 00000000000..fef488a487b --- /dev/null +++ b/modules/CIAO/DAnCE/TargetManager/DAnCE_TargetManagerDaemon.idl @@ -0,0 +1,12 @@ +// $Id$ + +#include "DAnCE/Deployment/Deployment_TargetManager.idl" + +module DAnCE +{ + interface TargetManagerDaemon : Deployment::TargetManager + { + oneway void shutdown (); + }; +}; + diff --git a/modules/CIAO/DAnCE/TargetManager/DomainDataManager.cpp b/modules/CIAO/DAnCE/TargetManager/DomainDataManager.cpp new file mode 100644 index 00000000000..e76f270106f --- /dev/null +++ b/modules/CIAO/DAnCE/TargetManager/DomainDataManager.cpp @@ -0,0 +1,688 @@ +// $Id$ +#include "DomainDataManager.h" + +#include "tools/Config_Handlers/DD_Handler.h" +#include "tools/Config_Handlers/DnC_Dump.h" +#include "DAnCE/Logger/Log_Macros.h" + +#ifdef GEN_OSTREAM_OPS +#include <iostream> +#include <sstream> +#endif /* GEN_OSTREAM_OPS */ + +void +DAnCE::DomainDataManager::init (CORBA::ORB_ptr orb, + ::Deployment::TargetManager_ptr target, + const ACE_TCHAR *domain_name) +{ + DANCE_TRACE ("DAnCE::DomainDataManager::init"); + + this->orb_ = CORBA::ORB::_duplicate (orb); + this->target_mgr_ = ::Deployment::TargetManager::_duplicate(target); + + DANCE_DEBUG ((LM_DEBUG, DLINFO "DAnCE::DomainDataManager::init - " + "Parsing initial domain from file %s\n", + domain_name)); + + CIAO::Config_Handlers::DD_Handler dd (domain_name); + ::Deployment::Domain* dmn = dd.domain_idl (); + + DANCE_DEBUG ((LM_TRACE, DLINFO "DAnCE::DomainDataManager::init - " + "Initial domain successfully parsed\n")); +#ifdef GEN_OSTREAM_OPS + std::ostringstream _stream; + _stream << *dmn << std::endl; + + DANCE_DEBUG ((LM_TRACE, DLINFO "DAnCE::DomainDataManager::init - " + "Contents of Domain:%s\n", + _stream.str ().c_str ())); +#endif + + current_domain_ = *dmn; + initial_domain_ = current_domain_; + + // initialize the provisioning domain + provisioned_data_ = initial_domain_; + + update_node_status (); + + call_all_node_managers (); +} + +int DAnCE::DomainDataManager::update_domain (const ::CORBA::StringSeq &, + const ::Deployment::Domain & domainSubset, + ::Deployment::DomainUpdateKind update_kind) +{ + DANCE_TRACE ("DAnCE::DomainDataManager::update_domain"); + + // Update the subset of the domain which the above + // parameter corresponds to + + + //check the type of update .. + + switch (update_kind) + { + case ::Deployment::UpdateAll: + case ::Deployment::UpdateDynamic: + break; + case ::Deployment::Add: + add_to_domain (domainSubset); + break; + case ::Deployment::Delete: + delete_from_domain (domainSubset); + break; + default: + break; + } + + CORBA::ULong const size = current_domain_.node.length (); + + CORBA::ULong i; + for (i=0;i < size;i++) + { + if (!ACE_OS::strcmp (domainSubset.node[0].name , + current_domain_.node[i].name)) + { + // found a match + // for now overwrite the entire Node info ... + // but later , this has to be changed to overwrite + // only the specific part ... + current_domain_.node[i] = domainSubset.node[0]; + break; // finished job ...break + } + } + + if (i == size) + { + // thus the node is new .. add it to current_domain_ + // later change it ... + current_domain_.node.length (size+1); + current_domain_.node[size]=domainSubset.node[0]; + } + return 0; +} + +::Deployment::Domain* DAnCE::DomainDataManager::get_current_domain () +{ + DANCE_TRACE ("DAnCE::DomainDataManager::get_current_domain"); + + return new ::Deployment::Domain (provisioned_data_); +} + +::Deployment::Domain* DAnCE::DomainDataManager::get_initial_domain () +{ + DANCE_TRACE ("DAnCE::DomainDataManager::get_initial_domain"); + + return new ::Deployment::Domain (initial_domain_); +} + +int DAnCE::DomainDataManager::readin_domain_data () +{ + DANCE_TRACE ("DAnCE::DomainDataManager::readin_domain_data"); + + // here read in Domain data ... + // + return 0; +} + +int DAnCE::DomainDataManager::call_all_node_managers () +{ + DANCE_TRACE ("DAnCE::DomainDataManager::call_all_node_managers"); + +/* if ( this->deployment_config_.init ("NodeDetails.dat") == -1 ) + { + DANCE_ERROR ((LM_ERROR, + "TargetM (%P|%t) DomainDataManager.cpp -" + "DAnCE::DomainDataManager::call_all_node_managers -" + "ERROR while trying to initialize after reading " + "node details DAT file\n")); + return 0; + } + + CORBA::ULong const length = initial_domain_.node.length (); + + for (CORBA::ULong i=0;i < length;i++) + { + + ::Deployment::NodeManager_var node_manager; + + try + { + node_manager = + deployment_config_.get_node_manager + (initial_domain_.node[i].name.in ()); + } + catch (CORBA::Exception&) + { + DANCE_ERROR ((LM_ERROR, "DANCE::TM (%P|%t) DomainDataManager.cpp: " + "Error trying to contact NodeManager %s\n", + initial_domain_.node[i].name.in ())); + continue; + } + + + if (!CORBA::is_nil (node_manager.in ())) + { + Deployment::Logger_ptr log = + Deployment::Logger::_nil (); + ::Deployment::Domain sub_domain; + sub_domain.UUID = CORBA::string_dup("Node-Level-domain"); + sub_domain.label = CORBA::string_dup("Node-level-domain"); + sub_domain.sharedResource.length(0); + sub_domain.interconnect.length(0); + sub_domain.bridge.length(0); + sub_domain.infoProperty.length(0); + sub_domain.node.length (1); + sub_domain.node[0] = initial_domain_.node[i]; + try + { + node_manager->joinDomain (sub_domain, + target_mgr_.in (), + log); + } + catch (CORBA::Exception& ex) + { + DANCE_ERROR ((LM_ERROR , "TM::Error in calling Join Domain==\n")); + ex._tao_print_exception ( + "Exception caught in ""DomainDataManager::joinDomain"); + } + } + } +*/ + return 0; + +} + + +::Deployment::ResourceCommitmentManager_ptr DAnCE::DomainDataManager +::commitResources (const ::Deployment::ResourceAllocations &) +{ + DANCE_TRACE ("DAnCE::DomainDataManager::commitResources"); + +/* + // commit the resources + // parse into the plan and commit resources ... + + // set the action value + current_action_ = commit; + + // temporary created to guard against exceptions + ::Deployment::Domain temp_provisioned_data = + provisioned_data_; + + for (CORBA::ULong i = 0;i < plan.instance.length ();i++) + { + for (CORBA::ULong j = 0;j < temp_provisioned_data.node.length ();j++) + { + if (!ACE_OS::strcmp (plan.instance[i].node.in () , + temp_provisioned_data.node[j].name.in ())) + { + try { + match_requirement_resource ( + plan.instance[i].deployedResource, + temp_provisioned_data.node[j].resource); + } + catch (::Deployment::ResourceCommitmentFailure& ex) + { + // catch the exception and add parameters + throw ex; + } + } + } + } + + // here commit the commitresources + provisioned_data_ = temp_provisioned_data; + */ + return 0; +} + + +void DAnCE::DomainDataManager:: +releaseResources (const ::Deployment::ResourceCommitmentManager_ptr) +{ + DANCE_TRACE ("DAnCE::DomainDataManager::releaseResources"); + + // release the resources +/* + + // set the action value + current_action_ = release; + + for (CORBA::ULong i = 0;i < plan.instance.length ();i++) + { + for (CORBA::ULong j = 0;j < provisioned_data_.node.length ();j++) + { + if (!ACE_OS::strcmp (plan.instance[i].node.in () , + provisioned_data_.node[j].name.in ())) + { + match_requirement_resource ( + plan.instance[i].deployedResource, + provisioned_data_.node[j].resource); + + } + } + } +*/ +} + + +void DAnCE::DomainDataManager::match_requirement_resource ( + ::Deployment::InstanceResourceDeploymentDescriptions deployed, + ::Deployment::Resources & available) +{ + DANCE_TRACE ("DAnCE::DomainDataManager::match_requirement_resource"); + + // here match the deployed to the available + + for (CORBA::ULong i = 0;i < deployed.length ();i++) + { + // for each deployed resource ....search the corresponding + // available resource + for (CORBA::ULong j = 0;j < available.length ();j++) + { + if (!ACE_OS::strcmp (deployed[i].requirementName, available[j].name)) + { + // search for the resourcename in the resourceType + for (CORBA::ULong k = 0;k < available[j].resourceType.length ();k++) + { + if (!ACE_OS::strcmp (deployed[i].resourceName, + available[j].resourceType[k])) + { + try { + match_properties (deployed[i].property, + available[j].property); + } + catch (::Deployment::ResourceCommitmentFailure& ex) + { + // catch the exception and add parameters + throw ex; + } + } + } + } + } + } + +} + +void DAnCE::DomainDataManager::match_properties ( + ::Deployment::Properties deployed, + ::Deployment::SatisfierProperties & available) +{ + DANCE_TRACE ("DAnCE::DomainDataManager::match_properties"); + + bool property_found; + + for (CORBA::ULong i = 0;i < deployed.length ();i++) + { + property_found = false; + + for (CORBA::ULong j = 0;j < available.length ();j++) + { + if (!ACE_OS::strcmp (deployed[i].name , available[j].name)) + { + // check kind here ....and then subtract .... + // accordingly , ..this is complex ... better to write + // some specialised algo + // for now assuming Capacity .... + // and tk_double .... + + commit_release_resource (deployed[i] , available[j]); + property_found = true; + } + } // internal for .... + + // check if property was found or not + if (property_found == false) + { + // throw an error since property was not found in the Resource + ::Deployment::ResourceCommitmentFailure failure; + + failure.reason = CORBA::string_dup ("Property Not Found\n"); + failure.propertyName = CORBA::string_dup (deployed[i].name); + failure.propertyValue.length (0); + + throw failure; + } + } // outside for ... +} + +void DAnCE::DomainDataManager::commit_release_resource ( + ::Deployment::Property & deployed, + ::Deployment::SatisfierProperty & available) +{ + DANCE_TRACE ("DAnCE::DomainDataManager::commit_release_resource"); + + if (current_action_ == commit) + { + + CORBA::Long required_d; + + if ((deployed.value >>= required_d) == false) + DANCE_ERROR ((LM_ERROR, "Failed to extract required amount\n")); + + CORBA::Long available_d; + + if ((available.value >>= available_d) == false) + DANCE_ERROR ((LM_ERROR, "failed to extract available amount\n")); + + if (available_d >= required_d) + { + available_d = available_d - required_d; + + available.value <<= available_d; + } + else + { + ::Deployment::ResourceCommitmentFailure failure; + + failure.reason = CORBA::string_dup ("Insufficient resources!"); + failure.propertyName = CORBA::string_dup (available.name); + failure.propertyValue.length (1); + failure.propertyValue[0] = available.value; + + throw failure; + } + } + else + { + //must be release + // @todo check return value of >>= + CORBA::Long required_d; + deployed.value >>= required_d; + CORBA::Long available_d; + available.value >>= available_d; + + available_d = available_d + required_d; + + // Should we check for bin > 100 ?????? + + available.value <<= available_d; + } +} + +void DAnCE::DomainDataManager::stop_monitors () +{ + DANCE_TRACE ("DAnCE::DomainDataManager::stop_monitors"); + + CORBA::ULong const length = initial_domain_.node.length (); + + for (CORBA::ULong i=0;i < length;i++) + { + ::Deployment::NodeManager_var node_manager; + + try + { +// node_manager = + //deployment_config_.get_node_manager +// (initial_domain_.node[i].name.in ()); + } + catch (const CORBA::Exception&) + { + DANCE_ERROR ((LM_ERROR, "DANCE::TM (%P|%t) DomainDataManager.cpp: " + "Error in get Node Manager from Deployment Config %s\n", + initial_domain_.node[i].name.in ())); + continue; + } + + if (!CORBA::is_nil (node_manager.in ())) + { + try + { + node_manager->leaveDomain (); + } + catch (CORBA::Exception& ex) + { + DANCE_ERROR ((LM_ERROR , "TM::Error in calling Leave Domain\n")); + ex._tao_print_exception ( + "Exception caught in ""DomainDataManager::leaveDomain"); + } + } + } + return; + +} + +int DAnCE::DomainDataManager::add_to_domain ( + const ::Deployment::Domain& domain) +{ + DANCE_TRACE ("DAnCE::DomainDataManager::add_to_domain"); + + // here add the domain to the Domain + // right now use only a node + + // got to take care of the fact , that a node can be added , + // while it is still in the domain + + //iterate through the supplied domain + //for each node + // find it in the pristine domain + // and copy it back to the provisioned_domain + + for (CORBA::ULong i = 0;i < domain.node.length ();i++) + { + //find in the pristine domain + ::Deployment::Node a_node; + + if (!this->find_in_initial_domain (domain.node[i].name.in (), + a_node)) + continue; // dont know this node + + //check if already present + if (!this->find_in_provisioned_domain (domain.node[i].name.in (), + a_node)) + { + // add the node to the domain ... + provisioned_data_.node.length (provisioned_data_.node.length () + 1); + provisioned_data_.node[provisioned_data_.node.length () - 1] = + a_node; + } + } + + return 0; +} + +bool DAnCE::DomainDataManager::find_in_initial_domain (const char* node_name, + ::Deployment::Node& node) +{ + DANCE_TRACE ("DAnCE::DomainDataManager::find_in_initial_domain"); + + for (CORBA::ULong i =0; + i < this->initial_domain_.node.length (); + i++) + { + if (ACE_OS::strcmp (node_name, this->initial_domain_.node[i].name.in ()) == 0) + { + node = this->initial_domain_.node[i]; + return true; + } + } + + // not found the node , return a node with an empty name + return false; +} + + +bool DAnCE::DomainDataManager::find_in_provisioned_domain (const char* node_name, + ::Deployment::Node& node) +{ + DANCE_TRACE ("DAnCE::DomainDataManager::find_in_provisioned_domain"); + + for (CORBA::ULong i =0; + i < this->provisioned_data_.node.length (); + i++) + { + if (ACE_OS::strcmp (node_name, this->provisioned_data_.node[i].name.in ()) == 0) + { + node = this->provisioned_data_.node[i]; + return true; + } + } + + // not found the node , return a node with an empty name + return false; +} + +int DAnCE::DomainDataManager::delete_from_domain ( + const ::Deployment::Domain& domain) +{ + DANCE_TRACE ("DAnCE::DomainDataManager::delete_from_domain"); + + // validate input + if (domain.node.length () == 0) + return 1; + + if (domain.node.length () > + this->provisioned_data_.node.length ()) + return 0; + + //algo : parse through the provisioned_data + // for each node , find in the deleted domain list + // if not found add it to the updated nodes list + + ::Deployment::Nodes updated_nodes; + bool found = false; + + for (CORBA::ULong j = 0; + j < this->provisioned_data_.node.length (); + j++) + { + found = false; + + for (CORBA::ULong i = 0;i < domain.node.length ();i++) + { + if (ACE_OS::strcmp (domain.node[i].name.in (), + this->provisioned_data_.node[j].name.in ()) == 0) + { + found = true; + break; // found the node + } + } + if (found) + continue; + + // not found in the deleted list + + // update the length of the list + updated_nodes.length (updated_nodes.length () + 1); + + // copy the node info + updated_nodes[updated_nodes.length () - 1] = + this->provisioned_data_.node[j]; + + } // for provisioned_data + + // here update the provisioned data + this->provisioned_data_.node = updated_nodes; + + return 1; +} + +int DAnCE::DomainDataManager::intimate_planner ( + const ::Deployment::Domain& domain) +{ + DANCE_TRACE ("DAnCE::DomainDataManager::intimate_planner"); + + // use the connection with the planner and get a reference to the planner + // make a call top the planner + Deployment::Domain d = domain; + return 0; + +} + +bool DAnCE::DomainDataManager::update_node_status () +{ + DANCE_TRACE ("DAnCE::DomainDataManager::update_node_status"); + + // update the node status here ... + return 0; +} + +void DAnCE::DomainDataManager::commitResourceAllocation ( + const ::Deployment::ResourceAllocations & resources) +{ + DANCE_TRACE ("DAnCE::DomainDataManager::commitResourceAllocation"); + + // commit the resources + // parse into the plan and commit resources ... + + // set the action value + current_action_ = commit; + + this->commit_release_RA (resources); +} + +void DAnCE::DomainDataManager::releaseResourceAllocation ( + const ::Deployment::ResourceAllocations & resources) +{ + DANCE_TRACE ("DAnCE::DomainDataManager::releaseResourceAllocation"); + + // set the action value + current_action_ = release; + + this->commit_release_RA (resources); +} + + +int DAnCE::DomainDataManager::commit_release_RA (const ::Deployment::ResourceAllocations& resources) +{ + DANCE_TRACE ("DAnCE::DomainDataManager::commit_release_RA"); + + // temporary used to guard against exceptions + temp_provisioned_data_ = provisioned_data_; + + + for (CORBA::ULong i = 0;i < resources.length ();i++) + { + try + { + ::Deployment::Resource& res = find_resource (resources[i]); + + match_properties (resources[i].property , res.property); + } + catch (::Deployment::ResourceCommitmentFailure& ex) + { + // catch the exception and add parameters + DANCE_ERROR ((LM_ERROR, "Caught the Exception in releaseResourceAllocation\n")); + ex.index = i; + throw ex; + } + } + + // here commit the commitresources + provisioned_data_ = temp_provisioned_data_; + + return 0; +} + +::Deployment::Resource& +DAnCE::DomainDataManager::find_resource ( + const ::Deployment::ResourceAllocation& resource) +{ + DANCE_TRACE ("DAnCE::DomainDataManager::find_resource"); + + // for now search the resource in the Node sequence; Later need + // to add it to the Bridges and Interconnects too according to the + // spec + for (CORBA::ULong j = 0;j < this->temp_provisioned_data_.node.length ();j++) + { + if (!ACE_OS::strcmp (resource.elementName.in () , + this->temp_provisioned_data_.node[j].name.in ())) + { + for (CORBA::ULong k =0; + k < this->temp_provisioned_data_.node[j].resource.length (); + k++) + { + if (!ACE_OS::strcmp (this->temp_provisioned_data_.node[j].resource[k].name.in (), + resource.resourceName.in ())) + return this->temp_provisioned_data_.node[j].resource[k];//resource found here, return + } + + // resource not found + throw ::Deployment::ResourceCommitmentFailure ().reason = CORBA::string_dup ("Resource Not Found\n"); + } + } + throw ::Deployment::ResourceCommitmentFailure ().reason = CORBA::string_dup ("Resource Not Found\n"); +} diff --git a/modules/CIAO/DAnCE/TargetManager/DomainDataManager.h b/modules/CIAO/DAnCE/TargetManager/DomainDataManager.h new file mode 100644 index 00000000000..de4170f6bbd --- /dev/null +++ b/modules/CIAO/DAnCE/TargetManager/DomainDataManager.h @@ -0,0 +1,258 @@ +// $Id$ +//=============================================================== +/** + * @file DomainDataManager.h + * + * @brief Maintains the Domain Information + * + * It contains the entire Domain information. Both the + * initial domain as well as the current available domain. + * + * @author Nilabja Roy nilabjar@dre.vanderbilt.edu + */ +//=============================================================== +#ifndef DOMAIN_DATA_MGRH +#define DOMAIN_DATA_MGRH + +//#include "TargetManagerC.h" +#include "Deployment/Deployment_TargetDataC.h" +#include "DAnCE/DomainApplicationManager/Node_Locator.h" + +namespace DAnCE +{ + /** + * @class DomainDataManager + * + * @brief Responsible for maintaining the Domain Information + * + * It maintains both the Current Domain Information as well + * as the Initial domain at full capacity. + */ + class DomainDataManager + { + + public : + /** + * @brief This function is called by the other classes to update + * current domain data. + * @param elements The string sequence of elements + * being updated + * @param domainSubset The subset of the actual Domain to be updated + * @param updateKind Specifies the update type eg. add, delete, update + * + */ + int update_domain (const ::CORBA::StringSeq & elements, + const ::Deployment::Domain & domainSubset, + ::Deployment::DomainUpdateKind updateKind); + /** + * @brief This function is called from the Executor code + * to get the Original Domain data. + * @return Domain* The Initial Domain + * + */ + ::Deployment::Domain* get_initial_domain (); + + /** + * @brief This function is called from the Executor code + * to get the Current Domain data. + * @return Domain* The Current Domain + */ + ::Deployment::Domain* get_current_domain (); + + /** + * @brief returns the sequence of node managers + * object reference + */ + ::Deployment::ResourceCommitmentManager_ptr + commitResources (const ::Deployment::ResourceAllocations & resources); + + /** + * @brief The function releases the resources held by a plan + * @param plan ::Deployment::DeploymentPlan the plan whose + * resources are to be released + */ + void releaseResources (const ::Deployment::ResourceCommitmentManager_ptr manager); + + /** + * The node manager in turn stops the monitor + * @brief The function makes a call on the leaveDomain on the + * NodeManager + */ + void stop_monitors (); + + /** + * @brief The function allocates resources specified in the + * parameter + * + * This function is for the ResourceCommitmentManager + * + */ + void commitResourceAllocation ( + const ::Deployment::ResourceAllocations & resources); + + /** + * @brief The function releases resources specified in the + * parameter + * + * This function is for the ResourceCommitmentManager + * + */ + void releaseResourceAllocation ( + const ::Deployment::ResourceAllocations & resources); + + /** + * @brief Initializing DomainDataManager + * + * This function inits the DomainDataManager + * + */ + void init (CORBA::ORB_ptr orb, + ::Deployment::TargetManager_ptr target, + const ACE_TCHAR *domain_name); + + private: + + /** + * @brief It will read the initial Domain data from + * XML files. + */ + int readin_domain_data (); + + /** + * @brief Match the deployed resources to the + * available resource + */ + void match_requirement_resource ( + ::Deployment::InstanceResourceDeploymentDescriptions deployed, + ::Deployment::Resources& available + ); + + /** + * @brief Match the properties of a Requirement to the + * properties of available resource + * @param deployed The deployed Properties + * @param available The available Properties + */ + void match_properties ( + ::Deployment::Properties deployed, + ::Deployment::SatisfierProperties& available); + + + /// The different actiona that can take place + enum Action {commit , release}; + + /** + * @brief Either commits or releases the given resource + * based on the current Action set. + * @param deployed ::Deployment::Property is the resource + * to be commited/released + * @param available ::Deployment::SatisfierProperty is the + * available resource from which committed/released. + * @exception ::Deployment::ResourceNotAvailable thrown + * when the deployed resources exceeds + * the available resource. + */ + void commit_release_resource ( ::Deployment::Property & deployed, + ::Deployment::SatisfierProperty & available); + + /** + * @brief This function calls all NM and gives them + * the sub-domain + */ + int call_all_node_managers (); + + /** + * @brief This function add new elements to the + * already existing domain + * + * @param domain Deployment::Domain contians the new + * elements + */ + int add_to_domain (const ::Deployment::Domain& domain); + + /** + * @brief This function deletes elements from the domain + * + * @param domain ::Deployment::Domain contains the new elements + * in the domain + */ + int delete_from_domain (const ::Deployment::Domain& domain); + + /** + * @brief This function intimates the planner about a domain + * change + * + * @param domain ::Deployment::Domain contains the new elements + * in the domain + */ + int intimate_planner (const ::Deployment::Domain& domain); + + /** + * @brief This function finds a new node in the initial_domain + * + * @param node The name of the node which is to be searched + */ + + bool find_in_initial_domain (const char* node_name, + ::Deployment::Node& node); + /** + * @brief This function finds a new node in the proviosiond_domain + * + * @param node The name of the node which is to be searched + */ + bool find_in_provisioned_domain (const char* node_name, + ::Deployment::Node& node); + + /** + * @brief updates the node status by reading it from a file + */ + bool update_node_status (); + + /** + * @function find_resource + * @brief It finds the Resource structure which is respresents the + * ResourceAllocation + */ + ::Deployment::Resource& find_resource ( + const ::Deployment::ResourceAllocation& resource); + + int commit_release_RA ( + const ::Deployment::ResourceAllocations& resources); + + /// The ORB pointer + CORBA::ORB_var orb_; + + /// The Deployment Configuration + // CIAO::Deployment_Configuration deployment_config_; + + /// The Initial Domain - contains resources + /// at total capacity + ::Deployment::Domain initial_domain_; + + + /// The Current Domain - contains resources + /// at current capacity + ::Deployment::Domain current_domain_; + + /// The Target Manager Context + ::Deployment::TargetManager_var target_mgr_; + + /** + * The static provisioned Domain data + */ + ::Deployment::Domain provisioned_data_; + + /// temporary domain used in commit/release to + /// guard against exceptions + ::Deployment::Domain temp_provisioned_data_; + + /// The current action + Action current_action_; + }; + + typedef ACE_Singleton <DomainDataManager, ACE_SYNCH_RECURSIVE_MUTEX> + DomainDataManager_Singleton; +#define DOMAIN_DATA_MANAGER DomainDataManager_Singleton::instance () +} // CIAO + +#endif /* DOMAIN_DATA_MGRH */ diff --git a/modules/CIAO/DAnCE/TargetManager/DomainEvents.idl b/modules/CIAO/DAnCE/TargetManager/DomainEvents.idl new file mode 100644 index 00000000000..77624dbbd23 --- /dev/null +++ b/modules/CIAO/DAnCE/TargetManager/DomainEvents.idl @@ -0,0 +1,25 @@ +/** + * @file DomainEvents.idl + * @brief Contains Events in the Domain + * + * @author Nilabja R <nilabjar@dre.vanderbilt.edu> + * + * $Id$ + */ + +#ifndef DOMAIN_CHANGE_IDL +#define DOMAIN_CHANGE_IDL + +#include "DAnCE/Deployment/Deployment_TargetManager.idl" +#include "ccm/CCM_Events.idl" + +module CIAO +{ + eventtype Domain_Changed_Event + { + public ::Deployment::Domain changes; + public ::Deployment::DomainUpdateKind change_kind; + }; +}; + +#endif diff --git a/modules/CIAO/DAnCE/TargetManager/ResourceCommitmentManager.cpp b/modules/CIAO/DAnCE/TargetManager/ResourceCommitmentManager.cpp new file mode 100644 index 00000000000..1b43b6e22bd --- /dev/null +++ b/modules/CIAO/DAnCE/TargetManager/ResourceCommitmentManager.cpp @@ -0,0 +1,61 @@ +// $Id$ +// +#include "DomainDataManager.h" +#include "ResourceCommitmentManager.h" +#include "DAnCE/Logger/Log_Macros.h" + +// Implementation skeleton constructor +DAnCE::ResourceCommitmentManager_i::ResourceCommitmentManager_i (void) +{ + DANCE_TRACE ("DAnCE::ResourceCommitmentManager_i"); +} + +// Implementation skeleton destructor +DAnCE::ResourceCommitmentManager_i::~ResourceCommitmentManager_i (void) +{ + DANCE_TRACE ("DAnCE::~ResourceCommitmentManager_i"); +} + +void DAnCE::ResourceCommitmentManager_i::commitResources ( + const ::Deployment::ResourceAllocations& resources) +{ + DANCE_TRACE ("DAnCE::ResourceCommitmentManager_i::commitResources"); + + DOMAIN_DATA_MANAGER->commitResourceAllocation (resources); + + // commit succesful .. add to commited resource + this->add_to_commited_resource (resources); + return; +} + +void DAnCE::ResourceCommitmentManager_i::releaseResources ( + const ::Deployment::ResourceAllocations & resources) +{ + DANCE_TRACE ("DAnCE::ResourceCommitmentManager_i::releaseResources"); + + ::Deployment::ResourceAllocations res; + + // if the resources set is null , use the already allocated resources .. + if (resources.length () == 0) + res = this->resources_; + else + res = resources; + + DOMAIN_DATA_MANAGER->releaseResourceAllocation (res); + return; +} + +int DAnCE::ResourceCommitmentManager_i::add_to_commited_resource ( + ::Deployment::ResourceAllocations res) +{ + DANCE_TRACE ("DAnCE::ResourceCommitmentManager_i::add_to_commited_resource"); + + CORBA::ULong const current_length = this->resources_.length (); + + this->resources_.length (current_length + res.length ()); + + for (CORBA::ULong i = 0;i < res.length ();i++) + this->resources_[current_length + i] = res[i]; + + return 0; +} diff --git a/modules/CIAO/DAnCE/TargetManager/ResourceCommitmentManager.h b/modules/CIAO/DAnCE/TargetManager/ResourceCommitmentManager.h new file mode 100644 index 00000000000..36065adfa5a --- /dev/null +++ b/modules/CIAO/DAnCE/TargetManager/ResourceCommitmentManager.h @@ -0,0 +1,64 @@ +// $Id$ +// +/** + * @file ResourceCommitmentManager.h + * + * @brief This file declares the ResourceCommitmentManager class + * + * This class acts as the servant of the interface + * ResourceCommitmentManager + */ +#ifndef DEPLOYMENT_RESOURCECOMMITMENTMANAGERI_H_ +#define DEPLOYMENT_RESOURCECOMMITMENTMANAGERI_H_ + +#include "DAnCE/Deployment/Deployment_ResourceCommitmentManagerS.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +#pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +namespace DAnCE +{ + + class ResourceCommitmentManager_i + : public virtual POA_Deployment::ResourceCommitmentManager + { + public: + // Constructor + ResourceCommitmentManager_i (void); + + // Destructor + virtual ~ResourceCommitmentManager_i (void); + + /** + * @function commitResources + * @brief Commits the resources + * + * @description This function makes a call to the DomainDataManager in order + * to commit the resources mentioned in the ResourceAllocation + * sequence. If the resource cannot be allocated throws a + * ResourceCommitmentFailed exception + */ + virtual + void commitResources ( + const ::Deployment::ResourceAllocations& resources); + + virtual + void releaseResources ( + const ::Deployment::ResourceAllocations & resources); + + private: + /** + * @function add_to_commited_resource + * @brief This function adds the res to already commited resources. + * This is to be called from within commitResources + */ + int add_to_commited_resource (::Deployment::ResourceAllocations res); + + /// The commited resource + ::Deployment::ResourceAllocations resources_; + }; + +} + +#endif /* DEPLOYMENT_RESOURCECOMMITMENTMANAGERI_H_ */ diff --git a/modules/CIAO/DAnCE/TargetManager/TM_Client.mpc b/modules/CIAO/DAnCE/TargetManager/TM_Client.mpc new file mode 100644 index 00000000000..97b3b760ce9 --- /dev/null +++ b/modules/CIAO/DAnCE/TargetManager/TM_Client.mpc @@ -0,0 +1,22 @@ +// $Id$ + +// Client.mpc,v 1.6 2005/02/18 09:07:06 jwillemsen Exp + +project(TMClient): ccm_stub, dance_deployment_stub, ciao_targetmanager_stub, ciao_config_handlers { + requires += dummy_label + IDL_Files { + } + + Source_Files { + CmpClient.cpp + } + + Header_Files { + } + + Inline_Files { + } + + Template_Files { + } +} diff --git a/modules/CIAO/DAnCE/TargetManager/TargetManager.idl b/modules/CIAO/DAnCE/TargetManager/TargetManager.idl new file mode 100644 index 00000000000..adc97215394 --- /dev/null +++ b/modules/CIAO/DAnCE/TargetManager/TargetManager.idl @@ -0,0 +1,32 @@ +// $Id$ + +/** + * @file TargetManager.idl + * @brief TargetManager interface defintion + * + * @author Nilabja R <nilabjar@dre.vanderbilt.edu> + */ + +#ifndef TARGETMGR_IDL +#define TARGETMGR_IDL + +#include "ccm/Components.idl" +#include "DAnCE/Deployment/Deployment_PlanError.idl" +#include "DAnCE/TargetManager/TargetManagerExt.idl" +#include "DAnCE/TargetManager/DomainEvents.idl" + +module CIAO +{ + component TargetManagerImpl + { + provides ::Deployment::TargetManager targetMgr; + + publishes Domain_Changed_Event changes; + }; + + home TargetManagerHome manages TargetManagerImpl + { + }; +}; + +#endif diff --git a/modules/CIAO/DAnCE/TargetManager/TargetManager.mpc b/modules/CIAO/DAnCE/TargetManager/TargetManager.mpc new file mode 100644 index 00000000000..d29e929670c --- /dev/null +++ b/modules/CIAO/DAnCE/TargetManager/TargetManager.mpc @@ -0,0 +1,71 @@ +// $Id$ + +project (DAnCE_TargetManagerDaemon_IDL) : ciaoidldefaults { + custom_only = 1 + + idlflags += -Gxhst -Gxhsk + idlflags += -Wb,stub_export_macro=TARGETMANAGERDAEMON_STUB_Export \ + -Wb,stub_export_include=TargetManagerDaemon_stub_export.h \ + -Wb,skel_export_macro=TARGETMANAGERDAEMON_SVNT_Export \ + -Wb,skel_export_include=TargetManagerDaemon_svnt_export.h + + IDL_Files { + DAnCE_TargetManagerDaemon.idl + } +} + +project(DAnCE_TargetManagerDaemon_stub) : dance_lib, dance_targetmanager_stub { + sharedname = DAnCE_TargetManagerDaemon_stub + dynamicflags = TARGETMANAGERDAEMON_STUB_BUILD_DLL + after += DAnCE_TargetManagerDaemon_IDL + IDL_Files { + } + + Source_Files { + DAnCE_TargetManagerDaemonC.cpp + } +} + +project(DAnCE_TargetManager_Impl) : dance_lib, ciao_config_handlers, naming, iortable, utils, dance_nodemanager_stub, dance_targetmanager_skel { + sharedname = DAnCE_TargetManager_Impl + libs += DAnCE_TargetManagerDaemon_stub DAnCE_TargetManagerDaemon_svnt + after += DAnCE_TargetManagerDaemon_stub DAnCE_TargetManagerDaemon_svnt + dynamicflags = DANCE_TARGETMANAGER_IMPL_BUILD_DLL TARGETMANAGER_MODULE_BUILD_DLL + + Source_Files { + DomainDataManager.cpp + ResourceCommitmentManager.cpp + TargetManager_Impl.cpp + Target_Manager_Module.cpp + } + + IDL_Files { + } +} + +project(DAnCE_TargetManagerDaemon_svnt) : dance_lib, dance_deployment_svnt, \ + dance_targetmanager_stub, dance_targetmanager_skel, ciao_config_handlers { + sharedname = DAnCE_TargetManagerDaemon_svnt + + libs += DAnCE_TargetManagerDaemon_stub + after += DAnCE_TargetManagerDaemon_stub + + dynamicflags = TARGETMANAGERDAEMON_SVNT_BUILD_DLL + + IDL_Files { + } + + Source_Files { + DAnCE_TargetManagerDaemonS.cpp + } +} + +project (DAnCE_TargetManager_Exec) : iortable, utils, naming, dance_logger, dance_tm_daemon, dance_nodemanager_stub, dance_targetmanager, dance_exe { + exename = dance_target_manager + IDL_Files { + } + + Source_Files { + Target_Manager_Exec.cpp + } +} diff --git a/modules/CIAO/DAnCE/TargetManager/TargetManagerExt.idl b/modules/CIAO/DAnCE/TargetManager/TargetManagerExt.idl new file mode 100644 index 00000000000..934314b4613 --- /dev/null +++ b/modules/CIAO/DAnCE/TargetManager/TargetManagerExt.idl @@ -0,0 +1,84 @@ +// $Id$ + +/** + * @file TargetManagerExt.idl + * + * @brief The Extensions to the TM interface for ARMS demo + * + * @author Nilabja R <nilabjar@dre.vanderbilt.edu> + * @author Nishanth Shankaran <nshankar@dre.vanderbilt.edu> + * + * This file declares a interface which will be implemented as + * a facet by the TargetManager component + */ + +#include "DAnCE/Interfaces/NodeManagerDaemon.idl" + +module CIAO +{ + /** + * @struct Cpu_Info + * @brief Consists of individual host-cpu info + */ + struct Host_Info + { + string hostname; + double cpu_util; + }; + + /// The sequence of CPU infos + typedef sequence<Host_Info> Host_Infos; + + /** + * @struct Component_Cpu_Util + * @brief Contains a component CPU Util + */ + struct Component_Info + { + string component_name; + double cpu_util; + }; + + /// The sequence of component cpu utilization + typedef sequence <Component_Info> Component_Infos; + + + /** + * @struct Host_NodeManager + * @brief Contains the node manager to host reference + */ + struct Host_NodeManager + { + /// host name + string host_; + + /// the node manager IOR + ::Deployment::NodeManager node_mgr_; + }; + + /// Sequence of NodeManager. + typedef sequence <Host_NodeManager> Host_NodeManager_seq; + + /** + * @interface TargetManagerExt + * @brief The Target Manager Extension + * + * Contains the interface used by the RACE + * controller. + */ + interface TargetManagerExt + { + /// Returns the pid in which a component runs + long get_pid (in string component_uuid); + + /// Returns the cpu usage for each host in the + /// last cycle + Host_Infos get_host_cpu (); + + /// Return the detail of the components + Component_Infos get_component_cpu (); + + /// Returns the OR of the Node managers + Host_NodeManager_seq get_all_node_managers (); + }; +}; diff --git a/modules/CIAO/DAnCE/TargetManager/TargetManager_Impl.cpp b/modules/CIAO/DAnCE/TargetManager/TargetManager_Impl.cpp new file mode 100644 index 00000000000..204c582be01 --- /dev/null +++ b/modules/CIAO/DAnCE/TargetManager/TargetManager_Impl.cpp @@ -0,0 +1,64 @@ +// -*- C++ -*- +// +// $Id$ + +#include "TargetManager_Impl.h" +#include "DomainDataManager.h" + +namespace DAnCE +{ +// Implementation skeleton constructor +TargetManagerDaemon_i::TargetManagerDaemon_i (CORBA::ORB_ptr orb) + : orb_ (::CORBA::ORB::_duplicate (orb)) +{ +} + +// Implementation skeleton destructor +TargetManagerDaemon_i::~TargetManagerDaemon_i (void) +{ +} + +void TargetManagerDaemon_i::init (const ACE_TCHAR *file) +{ + DAnCE::DOMAIN_DATA_MANAGER->init (this->orb_.in (), + this->_this (), + file); +} + +void TargetManagerDaemon_i::shutdown (void) +{ + // Add your implementation here +} + +::Deployment::Domain * TargetManagerDaemon_i::getAllResources (void) +{ + return DAnCE::DOMAIN_DATA_MANAGER->get_initial_domain (); +} + +::Deployment::Domain * TargetManagerDaemon_i::getAvailableResources (void) +{ + return DAnCE::DOMAIN_DATA_MANAGER->get_current_domain (); +} + +::Deployment::ResourceCommitmentManager_ptr TargetManagerDaemon_i::createResourceCommitment ( + const ::Deployment::ResourceAllocations & resources) +{ + return DAnCE::DOMAIN_DATA_MANAGER->commitResources (resources); +} + +void TargetManagerDaemon_i::destroyResourceCommitment ( + ::Deployment::ResourceCommitmentManager_ptr manager) +{ + return DAnCE::DOMAIN_DATA_MANAGER->releaseResources (manager); +} + +void TargetManagerDaemon_i::updateDomain ( + const ::CORBA::StringSeq & elements, + const ::Deployment::Domain & domainSubset, + ::Deployment::DomainUpdateKind updateKind) +{ + DAnCE::DOMAIN_DATA_MANAGER->update_domain (elements, domainSubset, updateKind); +} + + +} diff --git a/modules/CIAO/DAnCE/TargetManager/TargetManager_Impl.h b/modules/CIAO/DAnCE/TargetManager/TargetManager_Impl.h new file mode 100644 index 00000000000..9987f21509d --- /dev/null +++ b/modules/CIAO/DAnCE/TargetManager/TargetManager_Impl.h @@ -0,0 +1,61 @@ +// -*- C++ -*- +// +// $Id$ + + +#ifndef TARGETMANAGERDAEMONI_H_ +#define TARGETMANAGERDAEMONI_H_ + +#include "DAnCE_TargetManagerDaemonS.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +#pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "TargetManager_Impl_export.h" + +namespace DAnCE +{ +class DAnCE_TargetManager_Impl_Export TargetManagerDaemon_i + : public virtual POA_DAnCE::TargetManagerDaemon +{ +public: + // Constructor + TargetManagerDaemon_i (CORBA::ORB_ptr orb); + + // Destructor + virtual ~TargetManagerDaemon_i (void); + + void init (const ACE_TCHAR *file); + + virtual + void shutdown (void); + + virtual + ::Deployment::Domain * getAllResources (void); + + virtual + ::Deployment::Domain * getAvailableResources (void); + + virtual + ::Deployment::ResourceCommitmentManager_ptr createResourceCommitment ( + const ::Deployment::ResourceAllocations & resources); + + virtual + void destroyResourceCommitment ( + ::Deployment::ResourceCommitmentManager_ptr manager); + + virtual + void updateDomain ( + const ::CORBA::StringSeq & elements, + const ::Deployment::Domain & domainSubset, + ::Deployment::DomainUpdateKind updateKind); + + private: + CORBA::ORB_var orb_; +}; +} + + +#endif /* TARGETMANAGERDAEMONI_H_ */ + diff --git a/modules/CIAO/DAnCE/TargetManager/TargetManager_Impl_export.h b/modules/CIAO/DAnCE/TargetManager/TargetManager_Impl_export.h new file mode 100644 index 00000000000..ab728ccc8bd --- /dev/null +++ b/modules/CIAO/DAnCE/TargetManager/TargetManager_Impl_export.h @@ -0,0 +1,58 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl DAnCE_TargetManager_Impl +// ------------------------------ +#ifndef DANCE_TARGETMANAGER_IMPL_EXPORT_H +#define DANCE_TARGETMANAGER_IMPL_EXPORT_H + +#include "ace/config-all.h" + +#if defined (ACE_AS_STATIC_LIBS) && !defined (DANCE_TARGETMANAGER_IMPL_HAS_DLL) +# define DANCE_TARGETMANAGER_IMPL_HAS_DLL 0 +#endif /* ACE_AS_STATIC_LIBS && DANCE_TARGETMANAGER_IMPL_HAS_DLL */ + +#if !defined (DANCE_TARGETMANAGER_IMPL_HAS_DLL) +# define DANCE_TARGETMANAGER_IMPL_HAS_DLL 1 +#endif /* ! DANCE_TARGETMANAGER_IMPL_HAS_DLL */ + +#if defined (DANCE_TARGETMANAGER_IMPL_HAS_DLL) && (DANCE_TARGETMANAGER_IMPL_HAS_DLL == 1) +# if defined (DANCE_TARGETMANAGER_IMPL_BUILD_DLL) +# define DAnCE_TargetManager_Impl_Export ACE_Proper_Export_Flag +# define DANCE_TARGETMANAGER_IMPL_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define DANCE_TARGETMANAGER_IMPL_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* DANCE_TARGETMANAGER_IMPL_BUILD_DLL */ +# define DAnCE_TargetManager_Impl_Export ACE_Proper_Import_Flag +# define DANCE_TARGETMANAGER_IMPL_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define DANCE_TARGETMANAGER_IMPL_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* DANCE_TARGETMANAGER_IMPL_BUILD_DLL */ +#else /* DANCE_TARGETMANAGER_IMPL_HAS_DLL == 1 */ +# define DAnCE_TargetManager_Impl_Export +# define DANCE_TARGETMANAGER_IMPL_SINGLETON_DECLARATION(T) +# define DANCE_TARGETMANAGER_IMPL_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* DANCE_TARGETMANAGER_IMPL_HAS_DLL == 1 */ + +// Set DANCE_TARGETMANAGER_IMPL_NTRACE = 0 to turn on library specific tracing even if +// tracing is turned off for ACE. +#if !defined (DANCE_TARGETMANAGER_IMPL_NTRACE) +# if (ACE_NTRACE == 1) +# define DANCE_TARGETMANAGER_IMPL_NTRACE 1 +# else /* (ACE_NTRACE == 1) */ +# define DANCE_TARGETMANAGER_IMPL_NTRACE 0 +# endif /* (ACE_NTRACE == 1) */ +#endif /* !DANCE_TARGETMANAGER_IMPL_NTRACE */ + +#if (DANCE_TARGETMANAGER_IMPL_NTRACE == 1) +# define DANCE_TARGETMANAGER_IMPL_TRACE(X) +#else /* (DANCE_TARGETMANAGER_IMPL_NTRACE == 1) */ +# if !defined (ACE_HAS_TRACE) +# define ACE_HAS_TRACE +# endif /* ACE_HAS_TRACE */ +# define DANCE_TARGETMANAGER_IMPL_TRACE(X) ACE_TRACE_IMPL(X) +# include "ace/Trace.h" +#endif /* (DANCE_TARGETMANAGER_IMPL_NTRACE == 1) */ + +#endif /* DANCE_TARGETMANAGER_IMPL_EXPORT_H */ + +// End of auto generated file. diff --git a/modules/CIAO/DAnCE/TargetManager/TargetManager_exec.cpp b/modules/CIAO/DAnCE/TargetManager/TargetManager_exec.cpp new file mode 100644 index 00000000000..59b6e9453c2 --- /dev/null +++ b/modules/CIAO/DAnCE/TargetManager/TargetManager_exec.cpp @@ -0,0 +1,251 @@ +// $Id$ +#include "TargetManager_exec.h" +#include "tools/Config_Handlers/DD_Handler.h" +#include "tools/Config_Handlers/DnC_Dump.h" + +#include "DomainEventsC.h" + +#include "ResourceCommitmentManager.h" + +namespace CIAO_CIAO_TargetManagerImpl_Impl +{ + //================================================================== + // Facet Executor Implementation Class: TargetManager_exec_i + //================================================================== + + TargetManager_exec_i:: + TargetManager_exec_i (TargetManagerImpl_exec_i* exec , + CORBA::ORB_ptr orb) + : exec_ (exec), + orb_ (::CORBA::ORB::_duplicate (orb)) + { + // The DomainDataManager created here ... + + // get its own obj ref , then call + ::Deployment::TargetManager_var target = this->exec_->get_targetMgr (); + + // Create Domain Data here + + CIAO::DOMAIN_DATA_MANAGER->init (orb_.in (), target.in ()); + } + + TargetManager_exec_i::~TargetManager_exec_i (void) + { + } + + // Operations from ::Deployment::TargetManager + + ::Deployment::Domain * + TargetManager_exec_i::getAllResources () + { + return CIAO::DOMAIN_DATA_MANAGER->get_initial_domain (); + } + + ::Deployment::Domain * + TargetManager_exec_i::getAvailableResources () + { + return CIAO::DOMAIN_DATA_MANAGER->get_current_domain (); + } + + ::Deployment::ResourceCommitmentManager_ptr + TargetManager_exec_i::commitResources ( + const ::Deployment::ResourceAllocations & resources) + { + return CIAO::DOMAIN_DATA_MANAGER->commitResources (resources); + } + + void + TargetManager_exec_i::releaseResources ( + ::Deployment::ResourceCommitmentManager_ptr manager) + { + return CIAO::DOMAIN_DATA_MANAGER->releaseResources (manager); + } + + void + TargetManager_exec_i::updateDomain ( + const ::CORBA::StringSeq & elements , + const ::Deployment::Domain & domainSubset , + ::Deployment::DomainUpdateKind updateKind) + { + // Your code here. + CIAO::DOMAIN_DATA_MANAGER->update_domain ( + elements, + domainSubset, + updateKind); + + // here tell the planner about the changes + + // first get the node names which have failed ... + // assuming nodes to only fail , for now + + if (updateKind == ::Deployment::Delete || + updateKind == ::Deployment::Add) + { + CIAO::Domain_Changed_Event_var changed_event = + new OBV_CIAO::Domain_Changed_Event (); + + ::Deployment::Domain_var temp_domain = + new ::Deployment::Domain (domainSubset); + + changed_event->changes (temp_domain); + changed_event->change_kind (updateKind); + this->exec_->context_->push_changes (changed_event); + } + + } + + ::Deployment::ResourceCommitmentManager_ptr + TargetManager_exec_i::createResourceCommitment ( + const ::Deployment::ResourceAllocations& manager) + { + + CIAO::ResourceCommitmentManager_i *commit_servant = + new CIAO::ResourceCommitmentManager_i (); + + // Standard owner transfer mechanisms. + // + PortableServer::ServantBase_var safe_daemon (commit_servant); + + commit_servant->commitResources (manager); + + Deployment::ResourceCommitmentManager_var mgrv = + commit_servant->_this (); + + return mgrv._retn (); + } + + void + TargetManager_exec_i::destroyResourceCommitment ( + ::Deployment::ResourceCommitmentManager_ptr manager) + { + ::Deployment::ResourceAllocations res; + res.length (0); + manager->releaseResources (res); + return; + } + //================================================================== + // Component Executor Implementation Class: TargetManagerImpl_exec_i + //================================================================== + + TargetManagerImpl_exec_i::TargetManagerImpl_exec_i (void) + : exec_object_ (0) + { + } + + TargetManagerImpl_exec_i::~TargetManagerImpl_exec_i (void) + { + } + + // Supported or inherited operations. + + // Attribute operations. + + // Port operations. + + ::Deployment::CCM_TargetManager_ptr + TargetManagerImpl_exec_i::get_targetMgr () + { + // Your code here. + + if (CORBA::is_nil (this->exec_object_.in ())) + { + this->exec_object_ = new TargetManager_exec_i(this, + context_->_get_orb()); + } + + return ::Deployment::CCM_TargetManager::_duplicate (this->exec_object_.in ()); + } + + // Operations from Components::SessionComponent + + void + TargetManagerImpl_exec_i::set_session_context ( + ::Components::SessionContext_ptr ctx) + { + this->context_ = ::CIAO::CCM_TargetManagerImpl_Context::_narrow (ctx); + if (CORBA::is_nil (this->context_.in ())) + { + throw CORBA::INTERNAL (); + } + } + + void + TargetManagerImpl_exec_i::configuration_complete () + { + // Your code here. + } + + void + TargetManagerImpl_exec_i::ccm_activate () + { + // Your code here. + this->get_targetMgr (); + } + + void + TargetManagerImpl_exec_i::ccm_passivate () + { + // Your code here. + } + + void + TargetManagerImpl_exec_i::ccm_remove () + { + // Your code here. + + //CIAO::DomainDataManager::get_data_manager ()->stop_monitors (); + + return; + } + + + //================================================================== + // Home Executor Implementation Class: TargetManagerHome_exec_i + //================================================================== + + TargetManagerHome_exec_i::TargetManagerHome_exec_i (void) + { + } + + TargetManagerHome_exec_i::~TargetManagerHome_exec_i (void) + { + } + + // Supported or inherited operations. + + // Home operations. + + // Factory and finder operations. + + // Attribute operations. + + // Implicit operations. + + ::Components::EnterpriseComponent_ptr + TargetManagerHome_exec_i::create () + { + ::Components::EnterpriseComponent_ptr retval = + ::Components::EnterpriseComponent::_nil (); + + ACE_NEW_THROW_EX ( + retval, + TargetManagerImpl_exec_i, + CORBA::NO_MEMORY ()); + + return retval; + } + + extern "C" TARGETMANAGER_EXEC_Export ::Components::HomeExecutorBase_ptr + create_CIAO_TargetManagerHome_Impl (void) + { + ::Components::HomeExecutorBase_ptr retval = + ::Components::HomeExecutorBase::_nil (); + + ACE_NEW_RETURN ( + retval, + TargetManagerHome_exec_i, + ::Components::HomeExecutorBase::_nil ()); + + return retval; + } +} diff --git a/modules/CIAO/DAnCE/TargetManager/TargetManager_exec.h b/modules/CIAO/DAnCE/TargetManager/TargetManager_exec.h new file mode 100644 index 00000000000..cc3190d1427 --- /dev/null +++ b/modules/CIAO/DAnCE/TargetManager/TargetManager_exec.h @@ -0,0 +1,140 @@ +// $Id$ +//=============================================================== +/** + * @file TargetManager_exec.h + * + * @brief TargetManager Executor code + * + * @author Nilabja Roy nilabjar@dre.vanderbilt.edu + */ +//=============================================================== + +#ifndef CIAO_TARGETMANAGER_EXEC_H +#define CIAO_TARGETMANAGER_EXEC_H + +#include /**/ "ace/pre.h" + +#include "TargetManager_svnt.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "TargetManager_exec_export.h" +#include "tao/LocalObject.h" +#include "DomainDataManager.h" +#include "TargetManagerEC.h" + +/** + * TargetManager Executor namespace + */ +namespace CIAO_CIAO_TargetManagerImpl_Impl +{ + class TARGETMANAGER_EXEC_Export TargetManagerImpl_exec_i + : public virtual TargetManagerImpl_Exec, + public virtual ::CORBA::LocalObject + { + public: + TargetManagerImpl_exec_i (void); + virtual ~TargetManagerImpl_exec_i (void); + + // Supported or inherited operations. + + // Attribute operations. + + // Port operations. + + virtual ::Deployment::CCM_TargetManager_ptr + get_targetMgr (); + + // Operations from Components::SessionComponent + + virtual void + set_session_context ( + ::Components::SessionContext_ptr ctx); + + virtual void ccm_activate (); + + virtual void ccm_passivate (); + + virtual void ccm_remove (); + + virtual void configuration_complete (); + + public: + /// The service context pointer + ::CIAO::CCM_TargetManagerImpl_Context_var context_; + + /// The exec Object + ::Deployment::CCM_TargetManager_var exec_object_; + }; + + class TARGETMANAGER_EXEC_Export TargetManager_exec_i + : public virtual ::Deployment::CCM_TargetManager, + public virtual ::CORBA::LocalObject + { + public: + TargetManager_exec_i (TargetManagerImpl_exec_i* exec, + CORBA::ORB_ptr orb); + virtual ~TargetManager_exec_i (void); + + // Operations from ::Deployment::TargetManager + + virtual ::Deployment::Domain * getAllResources (); + + virtual ::Deployment::Domain * getAvailableResources (); + + virtual ::Deployment::ResourceCommitmentManager_ptr + commitResources (const ::Deployment::ResourceAllocations & resources); + + virtual void releaseResources (::Deployment::ResourceCommitmentManager_ptr manager); + + virtual void + updateDomain ( + const ::CORBA::StringSeq & elements, + const ::Deployment::Domain & domainSubset, + ::Deployment::DomainUpdateKind updateKind); + + virtual ::Deployment::ResourceCommitmentManager_ptr + createResourceCommitment (const ::Deployment::ResourceAllocations& manager); + + virtual void + destroyResourceCommitment ( + ::Deployment::ResourceCommitmentManager_ptr resources); + + private: + TargetManagerImpl_exec_i * exec_; + + /// The CORBA ORB ... + CORBA::ORB_var orb_; + }; + + class TARGETMANAGER_EXEC_Export TargetManagerHome_exec_i + : public virtual TargetManagerHome_Exec, + public virtual ::CORBA::LocalObject + { + public: + TargetManagerHome_exec_i (void); + virtual ~TargetManagerHome_exec_i (void); + + // Supported or inherited operations. + + // Home operations. + + // Factory and finder operations. + + // Attribute operations. + + // Implicit operations. + + virtual ::Components::EnterpriseComponent_ptr + create (); + }; + + extern "C" TARGETMANAGER_EXEC_Export ::Components::HomeExecutorBase_ptr + create_CIAO_TargetManagerHome_Impl (void); +} + +#include /**/ "ace/post.h" + +#endif /* CIAO_TARGETMANAGER_EXEC_H */ diff --git a/modules/CIAO/DAnCE/TargetManager/Target_Manager_Exec.cpp b/modules/CIAO/DAnCE/TargetManager/Target_Manager_Exec.cpp new file mode 100644 index 00000000000..347a0063483 --- /dev/null +++ b/modules/CIAO/DAnCE/TargetManager/Target_Manager_Exec.cpp @@ -0,0 +1,6 @@ +// $Id$ +#include "Target_Manager_Module.h" + +#define DANCE_MODULE_MAIN_CLASS_NAME DAnCE_TargetManager_Module +#include "Deployment/Module_Main.h" + diff --git a/modules/CIAO/DAnCE/TargetManager/Target_Manager_Module.cpp b/modules/CIAO/DAnCE/TargetManager/Target_Manager_Module.cpp new file mode 100644 index 00000000000..9cc34a94092 --- /dev/null +++ b/modules/CIAO/DAnCE/TargetManager/Target_Manager_Module.cpp @@ -0,0 +1,338 @@ +// -*- C++ -*- +// $Id$ + +#include "Target_Manager_Module.h" +#include "ace/Get_Opt.h" +#include "ace/OS_NS_stdio.h" +#include "ace/Task.h" +#include "ace/Atomic_Op.h" +#include "tao/IORTable/IORTable.h" +#include "tao/Utils/PolicyList_Destroyer.h" +#include "orbsvcs/CosNamingC.h" +#include "orbsvcs/orbsvcs/Naming/Naming_Loader.h" +#include "DAnCE/Logger/Log_Macros.h" +#include "DAnCE/Deployment/DAnCE_PropertiesC.h" + +#include "TargetManager_Impl.h" + +ACE_RCSID (DAnCE, + Repository_Manager_Module, + "$Id$") + +namespace DAnCE +{ + namespace Target_Manager + { + bool + write_IOR (const ACE_TCHAR * ior_file_name, const char* ior) + { + FILE* ior_output_file_ = + ACE_OS::fopen (ior_file_name, ACE_TEXT("w")); + + if (ior_output_file_) + { + ACE_OS::fprintf (ior_output_file_, + "%s", + ior); + ACE_OS::fclose (ior_output_file_); + return true; + } + return false; + } + } +} + +DAnCE_TargetManager_Module::DAnCE_TargetManager_Module (void) +{ + //DANCE_TRACE("DAnCE_TargetManager_Module::DAnCE_TargetManager_Module"); +} + +DAnCE_TargetManager_Module::~DAnCE_TargetManager_Module (void) +{ + DANCE_TRACE ("DAnCE_TargetManager_Module::~DAnCE_TargetManager_Module"); + + for (Servant_Map::iterator it = this->rm_map_.begin (); + it != this->rm_map_.end (); + ++it) + { + delete (*it).int_id_; + } +} + +const char * +DAnCE_TargetManager_Module::usage (void) +{ + DANCE_TRACE ("DAnCE_TargetManager_Module::usage"); + return "Repository Manager Options:\n" + //"\t-n|--name [name]\t Name to register in the naming service\n" + "\t-f|--file [name]\t Filename to output IOR.\n" + "\t-i|--init [name]\t Filename read initial domain descriptor.\n" + "\t-d|--domain-nc [NC]\t Default naming context for domain objects.\n" + "\t-h|help\t\t\t print this help message\n" + ; + +} + +bool +DAnCE_TargetManager_Module::parse_args (int argc, ACE_TCHAR * argv[]) +{ + DANCE_TRACE ("DAnCE_TargetManager_Module::parse_args"); + + ACE_Get_Opt get_opts (argc - 1, + argv + 1, + ACE_TEXT(":hd:f:i:"), + 0, + 0, + ACE_Get_Opt::RETURN_IN_ORDER, + 1); + + get_opts.long_option (ACE_TEXT("help"), 'h', ACE_Get_Opt::NO_ARG); + get_opts.long_option (ACE_TEXT("domain-nc"), 'd', ACE_Get_Opt::ARG_REQUIRED); + get_opts.long_option (ACE_TEXT("file"), 'f', ACE_Get_Opt::ARG_REQUIRED); + get_opts.long_option (ACE_TEXT("init"), 'i', ACE_Get_Opt::ARG_REQUIRED); + + int c; + while ( (c = get_opts ()) != -1) + { + switch (c) + { + case 'd': + DANCE_DEBUG ((LM_DEBUG, DLINFO "Repository_Manager_Module::parse_args - " + "Binding to provided Domain Naming Context: '%s'\n", + get_opts.opt_arg ())); + this->options_.domain_nc_ = get_opts.opt_arg (); + break; + + case 'f': + DANCE_DEBUG ((LM_DEBUG, DLINFO "Repository_Manager_Module::parse_args - " + "Output filename for IOR is %C\n", + get_opts.opt_arg ())); + this->options_.ior_file_ = get_opts.opt_arg (); + break; + + case 'i': + DANCE_DEBUG ((LM_DEBUG, DLINFO "Repository_Manager_Module::parse_args - " + "Initial domain file %s\n", + get_opts.opt_arg ())); + this->options_.domain_descr_ = get_opts.opt_arg (); + break; + + case 'h': + case '?': // Display help for use of the server. + DANCE_ERROR_RETURN ( (LM_ERROR, + this->usage (), + argv [0], c), + false); + break; + + case 0: + { + DANCE_ERROR ((LM_ERROR, DLINFO "Repository_Manager_Module::parse_args - " + "ERROR: unknown long option %C\n", + get_opts.long_option ())); + } + + break; + + default: + DANCE_DEBUG ((LM_TRACE, DLINFO "Repository_Manager_Module::parse_args - ignoring unknown option %c:%C\n", + c, get_opts.opt_arg ())); + } + + } + + return true; +} + +CORBA::Object_ptr +DAnCE_TargetManager_Module::create_object (CORBA::ORB_ptr orb, + int argc, + ACE_TCHAR *argv[]) +{ + DANCE_TRACE ("DAnCE_TargetManager_Module::create_object"); + + try + { + if (CORBA::is_nil(orb)) + { + DANCE_ERROR((LM_ERROR, DLINFO "DAnCE_TargetManager_Module::create_object - " + "Attempted to create Target Manager with a nil orb.\n")); + return CORBA::Object::_nil(); + } + else + { + this->orb_ = CORBA::ORB::_duplicate (orb); + } + + if (ACE_OS::strcmp(orb->id(), this->orb_->id()) != 0) + { + DANCE_DEBUG((LM_TRACE, DLINFO "DAnCE_TargetManager_Module::create_object - " + "Resetting TM's orb.\n")); + this->orb_ = CORBA::ORB::_duplicate (orb); + this->domain_nc_ = CosNaming::NamingContext::_nil(); + } + + if (!this->parse_args (argc, argv)) + { + return CORBA::Object::_nil (); + } + + this->create_poas (); + + if (this->options_.domain_nc_) + { + try + { + DANCE_DEBUG((LM_TRACE, DLINFO "DAnCE_TargetManager_Module::create_object - " + "Resolving DomainNC.\n")); + CORBA::Object_var domain_obj = this->orb_->string_to_object (this->options_.domain_nc_); + if (!CORBA::is_nil (domain_obj.in ())) + { + this->domain_nc_ = CosNaming::NamingContext::_narrow (domain_obj.in()); + if (CORBA::is_nil (this->domain_nc_.in ())) + { + DANCE_ERROR ((LM_ERROR,DLINFO "DAnCE_TargetManager_Module::create_object - " + "Narrow to NamingContext return nil for DomainNC.\n")); + return CORBA::Object::_nil (); + } + } + } + catch (CORBA::Exception&) + { + DANCE_DEBUG ((LM_WARNING, DLINFO "DAnCE_TargetManager_Module::create_object - " + "DomainNC context not found!\n")); + } + } + + + DANCE_DEBUG ((LM_TRACE, DLINFO "DAnCE_TargetManager_Module::create_object - " + "Initializing the IOR Table\n")); + // Initialize IOR table + CORBA::Object_var table_object = orb->resolve_initial_references ("IORTable"); + + IORTable::Table_var adapter = IORTable::Table::_narrow (table_object.in ()); + + if (CORBA::is_nil (adapter.in ())) + { + DANCE_ERROR ((LM_ERROR, DLINFO "DAnCE_TargetManager_Module::create_object - " + "Unable to RIR the IORTable.\n")); + return CORBA::Object::_nil (); + } + + + //Creating repository manager servant + DAnCE::TargetManagerDaemon_i * rm = new DAnCE::TargetManagerDaemon_i (orb); + + PortableServer::ServantBase_var safe_svt (rm); + + ACE_CString repository_manager_oid; + + if (this->options_.name_ == 0) + repository_manager_oid = "TargetManager"; + else + { + repository_manager_oid = ACE_TEXT_ALWAYS_CHAR (this->options_.name_); + repository_manager_oid += ".TargetManager"; + } + + // Registering servant in poa + PortableServer::ObjectId_var oid = + PortableServer::string_to_ObjectId (repository_manager_oid.c_str()); + this->rm_poa_->activate_object_with_id (oid, rm); + + // Getting repository manager ior + CORBA::Object_var nm_obj = this->rm_poa_->id_to_reference (oid.in ()); + CORBA::String_var ior = orb->object_to_string (nm_obj.in ()); + + // Binding ior to IOR Table + adapter->bind (repository_manager_oid.c_str (), ior.in ()); + + // Binding repository menager to DomainNC + if (!CORBA::is_nil (this->domain_nc_.in ())) + { + ACE_CString ns_name; + if (this->options_.name_ == 0) + ns_name = "TargetManager"; + else ns_name = ACE_TEXT_ALWAYS_CHAR (this->options_.name_); + + DANCE_DEBUG((LM_TRACE, DLINFO "DAnCE_TargetManager_Module::create_object - " + "Registering NM in NC as \"%C\".\n", ns_name.c_str ())); + CosNaming::Name name (1); + name.length (1); + name[0].id = CORBA::string_dup (ns_name.c_str ()); + name[0].kind = CORBA::string_dup ("TargetManager"); + this->domain_nc_->rebind (name, nm_obj.in ()); + } + + // Writing ior to file + if (0 != this->options_.ior_file_) + { + DANCE_DEBUG ((LM_TRACE, DLINFO "DAnCE_TargetManager_Module::create_object - " + "Writing RM IOR %C to file %C.\n", this->options_.ior_file_, ior.in ())); + if (!DAnCE::Target_Manager::write_IOR (this->options_.ior_file_, ior.in ())) + DANCE_ERROR ((LM_ERROR, DLINFO "DAnCE_TargetManager_Module::create_object - " + "Error: Unable to write IOR to file %C\n", + this->options_.ior_file_)); + } + + // Activate POA manager + PortableServer::POAManager_var mgr = this->root_poa_->the_POAManager (); + mgr->activate (); + + // Finishing Deployment part + DANCE_DEBUG ((LM_NOTICE, DLINFO "DAnCE_TargetManager_Module::create_object - " + "DAnCE_TargetManager is running...\n")); + + DANCE_DEBUG ((LM_DEBUG, DLINFO "DAnCE_TargetManager_Module::create_object - " + "TargetManager IOR: %s\n", ior.in ())); + + return nm_obj._retn (); + } + catch (const CORBA::Exception& ex) + { + ex._tao_print_exception ("DAnCE_TargetManager::main\t\n"); + return CORBA::Object::_nil (); + } +} + +void +DAnCE_TargetManager_Module::create_poas (void) +{ + DANCE_TRACE("DAnCE_Repository_Manager_Module::create_poas"); + // Get reference to Root POA. + DANCE_DEBUG ((LM_TRACE, DLINFO "DAnCE_TargetManager_Module::create_poas - " + "Resolving root POA\n")); + CORBA::Object_var obj = this->orb_->resolve_initial_references ("RootPOA"); + + this->root_poa_ = PortableServer::POA::_narrow (obj.in ()); + + DANCE_DEBUG ((LM_TRACE, DLINFO "DAnCE_TargetManager_Module::create_poas - " + "Obtaining the POAManager\n")); + PortableServer::POAManager_var mgr = this->root_poa_->the_POAManager (); + + TAO::Utils::PolicyList_Destroyer policies (2); + policies.length (2); + + try + { + DANCE_DEBUG ((LM_TRACE, DLINFO "DAnCE_TargetManager_Module::create_poas - " + "DAnCE_TargetManager_Module::create_poas - " + "Creating the \"Repository\" POA.\n")); + + policies[0] = this->root_poa_->create_id_assignment_policy (PortableServer::USER_ID); + policies[1] = this->root_poa_->create_lifespan_policy (PortableServer::PERSISTENT); + this->rm_poa_ = this->root_poa_->create_POA ("Repository", + mgr.in(), + policies); + } + catch (const PortableServer::POA::AdapterAlreadyExists &) + { + DANCE_DEBUG ((LM_INFO, DLINFO "DAnCE_TargetManager_Module::create_poas - " + "Using existing \"Repository\" POA\n")); + this->rm_poa_ = this->root_poa_->find_POA ("Repository", 0); + } +} + +#ifndef DANCE_TARGETMANAGER_IMPL_BUILD_DLL +ACE_FACTORY_DEFINE (DAnCE_TargetManager_Module, DAnCE_TargetManager_Module) +#endif /* DANCE_TARGETMANAGER_IMPL_BUILD_DLL */ diff --git a/modules/CIAO/DAnCE/TargetManager/Target_Manager_Module.h b/modules/CIAO/DAnCE/TargetManager/Target_Manager_Module.h new file mode 100644 index 00000000000..83a598c7934 --- /dev/null +++ b/modules/CIAO/DAnCE/TargetManager/Target_Manager_Module.h @@ -0,0 +1,105 @@ +// -*- C++ -*- + +//============================================================================= +/** + * @file Target_Manager_Module.h + * + * $Id$ + * + * @brief To start TargetManager by starter + * + * @author William R. Otte <wotte@dre.vanderbilt.edu> + */ +//============================================================================= + +#ifndef NODE_MANAGER_MODULE_H +#define NODE_MANAGER_MODULE_H + +#include /**/ "ace/pre.h" + +#include "Target_Manager_Module_export.h" + +#if !defined (ACE_LACKS_PRAGMA_ONCE) +# pragma once +#endif /* ACE_LACKS_PRAGMA_ONCE */ + +#include "ace/Service_Config.h" +#include "ace/Vector_T.h" +#include "ace/Map_Manager.h" +#include "ace/Null_Mutex.h" +#include "tao/ORB.h" +#include "tao/PortableServer/POAC.h" +#include "orbsvcs/CosNamingC.h" +#include "tao/Object_Loader.h" +#include "Deployment/DAnCE_Loader.h" +#include "DAnCE/Deployment/Deployment_common.h" +#include "TargetManager_Impl.h" + +/** + * @class Target_Manager_Module + * + * @brief The shared object that is instantiated when the target manager + * module/library is dynamically loaded. + * + * This class runs the node manager instance + */ +class DAnCE_TargetManager_Module_Export DAnCE_TargetManager_Module + : public DAnCE::DAnCE_Object_Loader +{ + public: + struct SOptions + { + const ACE_TCHAR * domain_nc_; + const ACE_TCHAR * ior_file_; + const ACE_TCHAR * domain_descr_; + const ACE_TCHAR * name_; + + SOptions() : + domain_nc_ (0), + ior_file_ (0), + domain_descr_ (0), + name_ (0) + { + } + }; + + /// Constructor. + DAnCE_TargetManager_Module (void); + + /// Destructor. + ~DAnCE_TargetManager_Module (void); + + /// Overload the base class method to create a new instance + /// of a DAnCE_RepositoryManager_Module object. + virtual CORBA::Object_ptr create_object (CORBA::ORB_ptr orb, + int argc, + ACE_TCHAR *argv []); + + virtual const char * usage (void); + + virtual bool parse_args (int argc, ACE_TCHAR *argv []); + + private: + void create_poas (void); + + /// Here we store the servants. + typedef ACE_Map_Manager < ACE_CString, + DAnCE::TargetManagerDaemon_i *, + ACE_Null_Mutex > Servant_Map; + + Servant_Map rm_map_; + + CORBA::ORB_var orb_; + CosNaming::NamingContext_var domain_nc_; + + SOptions options_; + + PortableServer::POA_var root_poa_; + PortableServer::POA_var rm_poa_; +}; + +ACE_FACTORY_DECLARE (DAnCE_TargetManager_Module, DAnCE_TargetManager_Module) + +#include /**/ "ace/post.h" + +#endif /* NODE_MANAGER_MODULE_H */ diff --git a/modules/CIAO/DAnCE/TargetManager/Target_Manager_Module_export.h b/modules/CIAO/DAnCE/TargetManager/Target_Manager_Module_export.h new file mode 100644 index 00000000000..65f45970d0b --- /dev/null +++ b/modules/CIAO/DAnCE/TargetManager/Target_Manager_Module_export.h @@ -0,0 +1,58 @@ + +// -*- C++ -*- +// $Id$ +// Definition for Win32 Export directives. +// This file is generated automatically by generate_export_file.pl TargetManager_Module +// ------------------------------ +#ifndef TARGETMANAGER_MODULE_EXPORT_H +#define TARGETMANAGER_MODULE_EXPORT_H + +#include "ace/config-all.h" + +#if defined (ACE_AS_STATIC_LIBS) && !defined (TARGETMANAGER_MODULE_HAS_DLL) +# define TARGETMANAGER_MODULE_HAS_DLL 0 +#endif /* ACE_AS_STATIC_LIBS && TARGETMANAGER_MODULE_HAS_DLL */ + +#if !defined (TARGETMANAGER_MODULE_HAS_DLL) +# define TARGETMANAGER_MODULE_HAS_DLL 1 +#endif /* ! TARGETMANAGER_MODULE_HAS_DLL */ + +#if defined (TARGETMANAGER_MODULE_HAS_DLL) && (TARGETMANAGER_MODULE_HAS_DLL == 1) +# if defined (TARGETMANAGER_MODULE_BUILD_DLL) +# define DAnCE_TargetManager_Module_Export ACE_Proper_Export_Flag +# define TARGETMANAGER_MODULE_SINGLETON_DECLARATION(T) ACE_EXPORT_SINGLETON_DECLARATION (T) +# define TARGETMANAGER_MODULE_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_EXPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# else /* TARGETMANAGER_MODULE_BUILD_DLL */ +# define DAnCE_TargetManager_Module_Export ACE_Proper_Import_Flag +# define TARGETMANAGER_MODULE_SINGLETON_DECLARATION(T) ACE_IMPORT_SINGLETON_DECLARATION (T) +# define TARGETMANAGER_MODULE_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) ACE_IMPORT_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +# endif /* TARGETMANAGER_MODULE_BUILD_DLL */ +#else /* TARGETMANAGER_MODULE_HAS_DLL == 1 */ +# define DAnCE_TargetManager_Module_Export +# define TARGETMANAGER_MODULE_SINGLETON_DECLARATION(T) +# define TARGETMANAGER_MODULE_SINGLETON_DECLARE(SINGLETON_TYPE, CLASS, LOCK) +#endif /* TARGETMANAGER_MODULE_HAS_DLL == 1 */ + +// Set TARGETMANAGER_MODULE_NTRACE = 0 to turn on library specific tracing even if +// tracing is turned off for ACE. +#if !defined (TARGETMANAGER_MODULE_NTRACE) +# if (ACE_NTRACE == 1) +# define TARGETMANAGER_MODULE_NTRACE 1 +# else /* (ACE_NTRACE == 1) */ +# define TARGETMANAGER_MODULE_NTRACE 0 +# endif /* (ACE_NTRACE == 1) */ +#endif /* !TARGETMANAGER_MODULE_NTRACE */ + +#if (TARGETMANAGER_MODULE_NTRACE == 1) +# define TARGETMANAGER_MODULE_TRACE(X) +#else /* (TARGETMANAGER_MODULE_NTRACE == 1) */ +# if !defined (ACE_HAS_TRACE) +# define ACE_HAS_TRACE +# endif /* ACE_HAS_TRACE */ +# define TARGETMANAGER_MODULE_TRACE(X) ACE_TRACE_IMPL(X) +# include "ace/Trace.h" +#endif /* (TARGETMANAGER_MODULE_NTRACE == 1) */ + +#endif /* TARGETMANAGER_MODULE_EXPORT_H */ + +// End of auto generated file. |