From e644d6b1f217e8152ac134a44c745704e3ce123e Mon Sep 17 00:00:00 2001 From: labancap Date: Tue, 26 Feb 2013 16:56:03 +0000 Subject: Modify nsgroup command line interface to only support round robin policy strategy --- .../Naming/FaultTolerant/FT_Naming_Manager.cpp | 9 +++- .../Naming/FaultTolerant/FT_Naming_Manager.h | 7 +-- .../orbsvcs/Naming/FaultTolerant/nsgroup_svc.cpp | 59 +++++++++++++--------- .../orbsvcs/Naming/FaultTolerant/nsgroup_svc.h | 18 ++++--- 4 files changed, 60 insertions(+), 33 deletions(-) (limited to 'TAO/orbsvcs/orbsvcs/Naming/FaultTolerant') diff --git a/TAO/orbsvcs/orbsvcs/Naming/FaultTolerant/FT_Naming_Manager.cpp b/TAO/orbsvcs/orbsvcs/Naming/FaultTolerant/FT_Naming_Manager.cpp index d2aaabc01b2..5dfa2302077 100644 --- a/TAO/orbsvcs/orbsvcs/Naming/FaultTolerant/FT_Naming_Manager.cpp +++ b/TAO/orbsvcs/orbsvcs/Naming/FaultTolerant/FT_Naming_Manager.cpp @@ -99,6 +99,12 @@ TAO_FT_Naming_Manager::create_object_group ( throw PortableGroup::ObjectNotCreated (); } + /// Currently only FT_Naming::ROUND_ROBIN is supported + if (lb_strategy != FT_Naming::ROUND_ROBIN) + { + throw PortableGroup::ObjectNotCreated (); + } + // When creating the object group, it starts as a generic // CORBA Object. It will become the type of the first added // member. @@ -177,7 +183,8 @@ TAO_FT_Naming_Manager::groups (::FT_Naming::LoadBalancingStrategyValue target_st // Extract the group's Load Balancing property PortableGroup::Name lb_strat_property_name (1); lb_strat_property_name.length (1); - lb_strat_property_name[0].id = CORBA::string_dup (::FT_Naming::TAO_FT_LOAD_BALANCING_STRATEGY); + lb_strat_property_name[0].id = + CORBA::string_dup (::FT_Naming::TAO_FT_LOAD_BALANCING_STRATEGY); PortableGroup::Properties_var props = this->get_properties (obj_group); PortableGroup::Value value; if (!TAO_PG::get_property_value (lb_strat_property_name, props.in (), value)) diff --git a/TAO/orbsvcs/orbsvcs/Naming/FaultTolerant/FT_Naming_Manager.h b/TAO/orbsvcs/orbsvcs/Naming/FaultTolerant/FT_Naming_Manager.h index 58a5cadde44..453a2826831 100644 --- a/TAO/orbsvcs/orbsvcs/Naming/FaultTolerant/FT_Naming_Manager.h +++ b/TAO/orbsvcs/orbsvcs/Naming/FaultTolerant/FT_Naming_Manager.h @@ -71,7 +71,8 @@ public: /// @param[in] group_name The symbolic name of the group that can /// be used to refer to the group in other operations. /// @param[in] lb_strategy The strategy to be used by the Naming - /// Service when this object group is resolved. + /// Service when this object group is resolved. Currently only + /// FT_Naming::ROUND_ROBIN is supported. ///@param[in] the_criteria Properties to be used by the object group. virtual PortableGroup::ObjectGroup_ptr create_object_group ( const char * group_name, @@ -82,7 +83,7 @@ public: virtual void delete_object_group ( const char * group_name); - /// Retreives a reference to a group with the specified name + /// Retrieves a reference to a group with the specified name virtual PortableGroup::ObjectGroup_ptr get_object_group_ref_from_name ( const char * group_name); @@ -92,7 +93,7 @@ public: const char * group_name, ::FT_Naming::LoadBalancingStrategyValue lb_strategy); - /// Retreive the names of the groups with the specified load balanacing + /// Retrieve the names of the groups with the specified load balancing /// strategy that have been created in this Naming Manager. virtual ::FT_Naming::GroupNames * groups ( ::FT_Naming::LoadBalancingStrategyValue target_strategy); diff --git a/TAO/orbsvcs/orbsvcs/Naming/FaultTolerant/nsgroup_svc.cpp b/TAO/orbsvcs/orbsvcs/Naming/FaultTolerant/nsgroup_svc.cpp index b6af4741772..2d933ac6541 100644 --- a/TAO/orbsvcs/orbsvcs/Naming/FaultTolerant/nsgroup_svc.cpp +++ b/TAO/orbsvcs/orbsvcs/Naming/FaultTolerant/nsgroup_svc.cpp @@ -18,18 +18,20 @@ NS_group_svc::NS_group_svc (void) { } -FT_Naming::LoadBalancingStrategyValue -NS_group_svc::determine_policy_string (const ACE_TCHAR *policy) +bool +NS_group_svc::determine_policy_string ( + const ACE_TCHAR *policy, + FT_Naming::LoadBalancingStrategyValue& value) { - if (ACE_OS::strcasecmp (policy, - ACE_TEXT_CHAR_TO_TCHAR ("rand")) == 0) { - return FT_Naming::RANDOM; - } else if (ACE_OS::strcasecmp (policy, - ACE_TEXT_CHAR_TO_TCHAR ("least")) == 0) { - return FT_Naming::LEAST; - } else { - return FT_Naming::ROUND_ROBIN; // Default case + bool rc = false; + + if (ACE_OS::strcasecmp (policy, ACE_TEXT_CHAR_TO_TCHAR ("round")) == 0) + { + value = FT_Naming::ROUND_ROBIN; + rc = true; } + + return rc; } int @@ -118,9 +120,18 @@ NS_group_svc::group_create ( -2); } - try + /// Validate load balancing strategy policy string + FT_Naming::LoadBalancingStrategyValue strategy; + if (false == determine_policy_string (policy, strategy)) { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%s is not a valid policy.\n"), + policy), + -2); + } + try + { /// Verify that the group does not already exist /// Group names must be unique if ( true == group_exist (group_name)) @@ -146,7 +157,7 @@ NS_group_svc::group_create ( CORBA::Object_var obj = this->naming_manager_->create_object_group ( ACE_TEXT_ALWAYS_CHAR (group_name), - determine_policy_string(policy), + strategy, criteria); if (CORBA::is_nil (obj.in ())) @@ -317,22 +328,14 @@ NS_group_svc::group_list (void) // naming manager IDL to support requesting the group list - which is a list of names /// Display object group list for each load balancing strategy + /// Currently only support FT_Naming::ROUND_ROBIN int rc = 0; if( display_load_policy_group (FT_Naming::ROUND_ROBIN, ACE_TEXT ("Round Robin")) < 0 ) { rc = -1; } - if( display_load_policy_group (FT_Naming::RANDOM, - ACE_TEXT ("Random")) < 0 ) - { - rc = -1; - } - if( display_load_policy_group (FT_Naming::LEAST, - ACE_TEXT ("Least")) < 0 ) - { - rc = -1; - } + return rc; } @@ -405,11 +408,21 @@ NS_group_svc::group_modify ( -2); } + /// Validate load balancing strategy policy string + FT_Naming::LoadBalancingStrategyValue strategy; + if (false == determine_policy_string (policy, strategy)) + { + ACE_ERROR_RETURN ((LM_ERROR, + ACE_TEXT ("%s is not a valid policy.\n"), + policy), + -2); + } + try { this->naming_manager_->set_load_balancing_strategy ( ACE_TEXT_ALWAYS_CHAR (group_name), - determine_policy_string(policy) ); + strategy ); } catch (const PortableGroup::ObjectGroupNotFound&) { diff --git a/TAO/orbsvcs/orbsvcs/Naming/FaultTolerant/nsgroup_svc.h b/TAO/orbsvcs/orbsvcs/Naming/FaultTolerant/nsgroup_svc.h index 6139157e90b..e452fda3356 100644 --- a/TAO/orbsvcs/orbsvcs/Naming/FaultTolerant/nsgroup_svc.h +++ b/TAO/orbsvcs/orbsvcs/Naming/FaultTolerant/nsgroup_svc.h @@ -37,7 +37,7 @@ public: * object groups. * * @param group group name - * @param policy round | rand | least + * @param policy round * * @return 0 on success, -1 on failure, -2 on bad argument. */ @@ -75,7 +75,7 @@ public: * balancing strategy for a specified object group. * * @param group group name - * @param policy round | rand | least + * @param policy round * * @return 0 on success, -1 on failure, -2 on bad argument. */ @@ -162,16 +162,22 @@ public: private: /** - * determine stategy based on policy string value default to ROUND_ROBIN + * determine stategy based on policy string * - * @param policy round | rand | least + * @param const ACE_TCHAR *policy ["round"] + * @param FT_Naming::LoadBalancingStrategyValue& value + * @return true on success, false on failure. */ - FT_Naming::LoadBalancingStrategyValue determine_policy_string (const ACE_TCHAR *policy); + bool determine_policy_string ( + const ACE_TCHAR *policy, + FT_Naming::LoadBalancingStrategyValue& value); /** * @return 0 on success, -1 on failure. */ - int display_load_policy_group( FT_Naming::LoadBalancingStrategyValue strategy, const ACE_TCHAR *display_label); + int display_load_policy_group ( + FT_Naming::LoadBalancingStrategyValue strategy, + const ACE_TCHAR *display_label); private: -- cgit v1.2.1