I will removed the added traces, please ignore them.

Thanks
-Nagu

> -----Original Message-----
> From: Nagendra Kumar
> Sent: 15 July 2014 18:40
> To: [email protected]; [email protected]; Praveen Malviya
> Cc: [email protected]
> Subject: [devel] [PATCH 1 of 1] amfd: instantiate su as per
> saAmfSGNumPrefInserviceSUs [#445]
> 
>  osaf/services/saf/amf/amfd/include/db_template.h |    3 +
>  osaf/services/saf/amf/amfd/include/su.h          |    1 +
>  osaf/services/saf/amf/amfd/sg.cc                 |   11 +-
>  osaf/services/saf/amf/amfd/sgproc.cc             |  110
> +++++++++++++++++++++-
>  osaf/services/saf/amf/amfd/su.cc                 |   22 ++++
>  5 files changed, 136 insertions(+), 11 deletions(-)
> 
> 
> As of now, Amf is not considering in-service su to instantiate as per
> saAmfSGNumPrefInserviceSUs.
> This patch instantiates su if it is eligible.
> It also terminates the out of service sus if any other su gets unlocked and
> becomes eligible for getting assignment.
> 
> diff --git a/osaf/services/saf/amf/amfd/include/db_template.h
> b/osaf/services/saf/amf/amfd/include/db_template.h
> --- a/osaf/services/saf/amf/amfd/include/db_template.h
> +++ b/osaf/services/saf/amf/amfd/include/db_template.h
> @@ -38,9 +38,12 @@ class AmfDb {
> 
>     typedef std::map<Key, T*> AmfDbMap;
>     typedef typename AmfDbMap::const_iterator const_iterator;
> +   typedef typename AmfDbMap::const_reverse_iterator
> + const_reverse_iterator;
> 
>     const_iterator begin() const {return db.begin();}
>     const_iterator end() const {return db.end();}
> +   const_reverse_iterator rbegin() const {return db.rbegin();}
> +   const_reverse_iterator rend() const {return db.rend();}
> 
>    private:
>     AmfDbMap db;
> diff --git a/osaf/services/saf/amf/amfd/include/su.h
> b/osaf/services/saf/amf/amfd/include/su.h
> --- a/osaf/services/saf/amf/amfd/include/su.h
> +++ b/osaf/services/saf/amf/amfd/include/su.h
> @@ -119,6 +119,7 @@ class AVD_SU {
>       void set_su_switch(SaToggleState state);
>       avd_avnd_tag *get_node_ptr(void);
>       bool is_in_service(void);
> +     bool is_instantiable(void);
>       void reset_all_comps_assign_flag();
>       AVD_COMP *find_unassigned_comp_that_provides_cstype(const
> SaNameT *cstype);
>       void disable_comps(SaAisErrorT result); diff --git
> a/osaf/services/saf/amf/amfd/sg.cc b/osaf/services/saf/amf/amfd/sg.cc
> --- a/osaf/services/saf/amf/amfd/sg.cc
> +++ b/osaf/services/saf/amf/amfd/sg.cc
> @@ -1713,14 +1713,15 @@ uint32_t sg_instantiated_su_count(const
>       AVD_SU *su;
> 
>       for (su = sg->list_of_su, inst_su_count = 0; su != NULL; su = su-
> >sg_list_su_next) {
> -             TRACE_1("su'%s', pres state'%u'", su->name.value, su-
> >saAmfSUPresenceState);
> -             if ((su->saAmfSUPresenceState ==
> SA_AMF_PRESENCE_INSTANTIATED) ||
> -                             (su->saAmfSUPresenceState ==
> SA_AMF_PRESENCE_INSTANTIATING) ||
> -                             (su->saAmfSUPresenceState ==
> SA_AMF_PRESENCE_RESTARTING)) {
> +             TRACE_1("su'%s', pres state'%u', in_serv'%u', PrefIn'%u'", su-
> >name.value,
> +                             su->saAmfSUPresenceState, su-
> >saAmfSuReadinessState, sg->saAmfSGNumPrefInserviceSUs);
> +             if (((su->saAmfSUPresenceState ==
> SA_AMF_PRESENCE_INSTANTIATED) ||
> +                                     (su->saAmfSUPresenceState ==
> SA_AMF_PRESENCE_INSTANTIATING) ||
> +                                     (su->saAmfSUPresenceState ==
> SA_AMF_PRESENCE_RESTARTING))) {
>                       inst_su_count ++;
>               }
>       }
> -
> +     TRACE_LEAVE2("%u", inst_su_count);
>       return inst_su_count;
>  }
> 
> diff --git a/osaf/services/saf/amf/amfd/sgproc.cc
> b/osaf/services/saf/amf/amfd/sgproc.cc
> --- a/osaf/services/saf/amf/amfd/sgproc.cc
> +++ b/osaf/services/saf/amf/amfd/sgproc.cc
> @@ -28,6 +28,7 @@
> 
>  #include <immutil.h>
>  #include <logtrace.h>
> +#include <set>
> 
>  #include <amfd.h>
>  #include <imm.h>
> @@ -1332,6 +1333,77 @@ done:
>       TRACE_LEAVE();
>  }
> 
> +/**
> + * @brief    This function finds higher rank unlocked, uninstantiated su.
> + * @param    ptr to sg
> + * @param    pointer to su
> + *
> + */
> +AVD_SU* su_to_instantiate(AVD_SG *sg)
> +{
> +     for (AVD_SU* i_su = sg->list_of_su; i_su != NULL; i_su = i_su-
> >sg_list_su_next) {
> +             TRACE("%s", i_su->name.value);
> +             if (i_su->is_instantiable())
> +                     return i_su;
> +     }
> +     return NULL;
> +}
> +
> +/**
> + * @brief    This function finds lower rank unassigned, locked, intantiated
> su.
> + * @param    ptr to sg
> + * @param    pointer to su
> + *
> + */
> +AVD_SU* su_to_terminate(AVD_SG *sg)
> +{
> +     AmfDb<std::string, AVD_SU> *su_rank = NULL;
> +     su_rank = new  AmfDb<std::string, AVD_SU>;
> +     for (AVD_SU* i_su = sg->list_of_su; i_su != NULL; i_su = i_su-
> >sg_list_su_next) {
> +             TRACE("In Seq %s, %u", i_su->name.value, i_su-
> >saAmfSURank);
> +             su_rank->insert(Amf::to_string(&i_su->name), i_su);
> +     }
> +     for (std::map<std::string, AVD_SU*>::const_reverse_iterator rit =
> su_rank->rbegin();
> +                     rit != su_rank->rend(); ++rit) {
> +             AVD_SU *su = rit->second;
> +             TRACE("Rev %s, %u, %u, %u", su->name.value, su-
> >saAmfSURank,
> +                             su->saAmfSuReadinessState, su-
> >saAmfSUPresenceState);
> +     }
> +     for (std::map<std::string, AVD_SU*>::const_reverse_iterator rit =
> su_rank->rbegin();
> +                     rit != su_rank->rend(); ++rit) {
> +             AVD_SU *su = rit->second;
> +             TRACE("Rev 2 %s, %u, %u, %u", su->name.value, su-
> >saAmfSURank,
> +                             su->saAmfSuReadinessState, su-
> >saAmfSUPresenceState);
> +             if ((su->saAmfSuReadinessState ==
> SA_AMF_READINESS_OUT_OF_SERVICE) &&
> +                             (su->saAmfSUPresenceState ==
> SA_AMF_PRESENCE_INSTANTIATED) &&
> +                             (su->list_of_susi == NULL)) {
> +                     return su;
> +             }
> +     }
> +     return NULL;
> +}
> +
> +/**
> + * @brief    This function finds higher rank unlocked, uninstantiated su.
> + * @param    ptr to sg
> + * @param    pointer to su
> + *
> + */
> +uint32_t in_serv_su(AVD_SG *sg)
> +{
> +     TRACE_ENTER();
> +     uint32_t in_serv = 0;
> +     for (AVD_SU* i_su = sg->list_of_su; i_su != NULL; i_su = i_su-
> >sg_list_su_next) {
> +             TRACE_ENTER2("%s", i_su->name.value);
> +             if (i_su->is_in_service()) {
> +                     TRACE_ENTER2(" in_serv_su %s", i_su->name.value);
> +                     in_serv ++;
> +             }
> +     }
> +     TRACE_LEAVE2("%u", in_serv);
> +     return in_serv;
> +}
> +
> 
> /************************************************************
> *****************
>   * Function: avd_sg_app_su_inst_func
>   *
> @@ -1397,8 +1469,6 @@ uint32_t avd_sg_app_su_inst_func(AVD_CL_
>                               }
> 
>                       } else if ((i_su->saAmfSUPreInstantiable == true) &&
> -                                     (sg->saAmfSGNumPrefInserviceSUs >
> (sg_instantiated_su_count(i_su->sg_of_su) +
> -
> num_try_insvc_su)) &&
>                                       (i_su->saAmfSUPresenceState ==
> SA_AMF_PRESENCE_UNINSTANTIATED) &&
>                                       ((i_su->saAmfSUAdminState ==
> SA_AMF_ADMIN_UNLOCKED) ||
>                                        (i_su->saAmfSUAdminState ==
> SA_AMF_ADMIN_LOCKED)) && @@ -1408,10 +1478,38 @@ uint32_t
> avd_sg_app_su_inst_func(AVD_CL_
>                                       (su_node_ptr->node_info.member ==
> true) &&
>                                       (i_su->saAmfSUOperState ==
> SA_AMF_OPERATIONAL_ENABLED) &&
>                                       (i_su->term_state == false)) {
> -
> -                             /* Try to Instantiate this SU */
> -                             if (avd_snd_presence_msg(cb, i_su, false) ==
> NCSCC_RC_SUCCESS) {
> -                                     num_try_insvc_su++;
> +                             TRACE("%u, %u", sg-
> >saAmfSGNumPrefInserviceSUs, num_try_insvc_su);
> +                             if (sg->saAmfSGNumPrefInserviceSUs >
> (sg_instantiated_su_count(i_su->sg_of_su) +
> +                                                     num_try_insvc_su)){
> +                                     /* Try to Instantiate this SU */
> +                                     if (avd_snd_presence_msg(cb, i_su,
> false) == NCSCC_RC_SUCCESS) {
> +                                             num_try_insvc_su++;
> +                                     }
> +                             } else {
> +                                     /* Check whether in-serv su are
> sufficient. */
> +                                     if (sg->saAmfSGNumPrefInserviceSUs
> > in_serv_su(sg)) {
> +                                             /* Find most eligible
> SU(Higher Rank, Unlocked) to instantiate. */
> +                                             AVD_SU* su_inst =
> su_to_instantiate(sg);
> +                                             /* Find lower rank
> unassigned, locked, intantiated su to terminate. */
> +                                             AVD_SU* su_term =
> su_to_terminate(sg);
> +                                             TRACE("%p, %p", su_inst,
> su_term);
> +                                             if (su_inst && su_term) {
> +                                                     TRACE("%s, %s",
> su_inst->name.value, su_term->name.value);
> +                                                     /* Try to Instantiate
> this SU */
> +                                                     if
> (avd_snd_presence_msg(cb, su_inst, false) == NCSCC_RC_SUCCESS) {
> +                                                             /* Don't
> increment num_try_insvc_su as we are any way
> +                                                                going to
> terminate one SU. */;
> +                                                             if
> (avd_snd_presence_msg(cb, su_term, true) ==
> +
>       NCSCC_RC_SUCCESS) {
> +
>       su_term-
> >set_readiness_state(SA_AMF_READINESS_OUT_OF_SERVICE);
> +
>       num_insvc_su --;
> +                                                             }
> +                                                     }
> +                                             } else {
> +                                                     /* No action to take if
> any su can't be instantiated or
> +                                                        if any su can't be
> terminated. */
> +                                             }
> +                                     }
>                               }
>                       } else
>                               TRACE("nop for %s", i_su->name.value); diff --
> git a/osaf/services/saf/amf/amfd/su.cc b/osaf/services/saf/amf/amfd/su.cc
> --- a/osaf/services/saf/amf/amfd/su.cc
> +++ b/osaf/services/saf/amf/amfd/su.cc
> @@ -852,6 +852,7 @@ void AVD_SU::unlock(SaImmOiHandleT immoi
>               avd_sg_app_su_inst_func(avd_cb, sg_of_su);
>       } else
>               LOG_IN("SU '%s' is not in service", name.value);
> +     avd_sg_app_su_inst_func(avd_cb, sg_of_su);
> 
>       if (is_oper_successful == true) {
>               if (sg_of_su->sg_fsm_state == AVD_SG_FSM_SG_REALIGN ) {
> @@ -1943,6 +1944,27 @@ bool AVD_SU::is_in_service(void) {
>      }
>  }
> 
> +
> +/**
> + * Checks if the SU can be made instantiated.
> + * @param su
> + * @return true if SU can be made in-service  */ bool
> +AVD_SU::is_instantiable(void) {
> +        struct avd_avnd_tag *node = get_node_ptr();
> +        const AVD_SG *sg = sg_of_su;
> +        const AVD_APP *app = sg->app;
> +
> +        return (avd_cluster->saAmfClusterAdminState ==
> SA_AMF_ADMIN_UNLOCKED) &&
> +                        (app->saAmfApplicationAdminState ==
> SA_AMF_ADMIN_UNLOCKED) &&
> +                        (saAmfSUAdminState == SA_AMF_ADMIN_UNLOCKED) &&
> +                        (sg->saAmfSGAdminState == SA_AMF_ADMIN_UNLOCKED) &&
> +                        (node->saAmfNodeAdminState == SA_AMF_ADMIN_UNLOCKED)
> &&
> +                        (node->saAmfNodeOperState ==
> SA_AMF_OPERATIONAL_ENABLED) &&
> +                        (saAmfSUOperState == SA_AMF_OPERATIONAL_ENABLED) &&
> +                     (saAmfSUPresenceState ==
> SA_AMF_PRESENCE_UNINSTANTIATED); }
> +
>  void AVD_SU::set_saAmfSUPreInstantiable(bool value) {
>       saAmfSUPreInstantiable = static_cast<SaBoolT>(value);
>       avd_saImmOiRtObjectUpdate(&name, "saAmfSUPreInstantiable",
> 
> ------------------------------------------------------------------------------
> Want fast and easy access to all the code in your enterprise? Index and search
> up to 200,000 lines of code with a free copy of Black Duck Code Sight - the 
> same
> software that powers the world's largest code search on Ohloh, the Black Duck
> Open Hub! Try it now.
> http://p.sf.net/sfu/bds
> _______________________________________________
> Opensaf-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/opensaf-devel

------------------------------------------------------------------------------
Want fast and easy access to all the code in your enterprise? Index and
search up to 200,000 lines of code with a free copy of Black Duck
Code Sight - the same software that powers the world's largest code
search on Ohloh, the Black Duck Open Hub! Try it now.
http://p.sf.net/sfu/bds
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel

Reply via email to