samples/amf/sa_aware/amf_demo.c | 186 +++++++++++++++++++++++++++++----------
tools/cluster_sim_uml/build_uml | 2 +-
2 files changed, 139 insertions(+), 49 deletions(-)
diff --git a/samples/amf/sa_aware/amf_demo.c b/samples/amf/sa_aware/amf_demo.c
--- a/samples/amf/sa_aware/amf_demo.c
+++ b/samples/amf/sa_aware/amf_demo.c
@@ -27,7 +27,8 @@
******************************************************************************
*/
-
+#include <map>
+#include <string>
#include <stdio.h>
#include <string.h>
#include <errno.h>
@@ -77,6 +78,70 @@ static const char *ha_state_name[] =
"Quiescing" /* SA_AMF_HA_QUIESCING */
};
+/* csi's life cycle handling */
+typedef std::map<std::string, int> csiList;
+csiList my_csi_list;
+
+SaAisErrorT update_csi_list(std::string csi, int ha_state) {
+ SaAisErrorT err = SA_AIS_OK;
+ int found = false;
+ // Add new one
+ if ((csi != "all") && (my_csi_list.find(csi) == my_csi_list.end())) {
+
my_csi_list.insert(std::make_pair<std::string,int>(csi,(int)ha_state));
+ } else {
+ // Update existing one
+ for( std::map<std::string,int>::iterator iter =
my_csi_list.begin();
+ iter != my_csi_list.end() ;
++iter ) {
+ if (csi == "all" || csi == iter->first) {
+ // Some basic rules to check
HA transition
+ if (iter->second ==
ha_state) {
+ syslog(LOG_ERR,
"FAILURE: Update the same csi '%s' with same ha_state'%d'", csi.c_str(),
ha_state);
+ err =
SA_AIS_ERR_BAD_OPERATION;
+ break;
+ }
+ if (iter->second ==
(int)SA_AMF_HA_ACTIVE && ha_state == int(SA_AMF_HA_STANDBY)) {
+ syslog(LOG_ERR,
"FAILURE: csi '%s' directly moves from ACTIVE to STANDBY'", csi.c_str());
+ err =
SA_AIS_ERR_BAD_OPERATION;
+ break;
+ }
+ if (iter->second ==
(int)SA_AMF_HA_STANDBY &&
+
(ha_state == int(SA_AMF_HA_QUIESCED) || ha_state ==
int(SA_AMF_HA_QUIESCING))) {
+ syslog(LOG_ERR,
"FAILURE: csi '%s' incorrectly moves from STANDBY to QUIESCED/QUIESCING'",
csi.c_str());
+ err =
SA_AIS_ERR_BAD_OPERATION;
+ break;
+ }
+ // Update the successful
ha_state
+ iter->second = (int)ha_state;
+ found = true;
+ }
+ }
+ if (found == false && err == SA_AIS_OK) {
+ syslog(LOG_ERR, "FAILURE: Update unknown csi '%s'",
csi.c_str());
+ err = SA_AIS_ERR_BAD_OPERATION;
+ }
+ }
+ return err;
+}
+
+SaAisErrorT remove_csi(std::string csi) {
+ SaAisErrorT err = SA_AIS_OK;
+ int found = false;
+ for( std::map<std::string,int>::iterator iter = my_csi_list.begin() ;
+ iter != my_csi_list.end() ; ++iter ) {
+ if (csi == "all" || csi == iter->first) {
+ my_csi_list.erase(iter);
+ found = true;
+ }
+ }
+ if (found == false) {
+ syslog(LOG_ERR, "FAILURE: Remove unknown csi '%s'",
csi.c_str());
+ err = SA_AIS_ERR_BAD_OPERATION;
+ }
+
+ return err;
+}
+
+
/**
* AMF invokes this callback to assign a new workload (ADD_ONE) or
* to change state of an already assigned workload (TARGET_ALL).
@@ -97,8 +162,10 @@ static void amf_csi_set_callback(SaInvoc
{
SaAisErrorT rc, error;
SaAmfCSIAttributeT *attr;
- int i, status;
-
+ unsigned int i;
+ int status;
+ std::string csi;
+ error = SA_AIS_ERR_BAD_OPERATION;
if (csi_desc.csiFlags == SA_AMF_CSI_ADD_ONE) {
syslog(LOG_INFO, "CSI Set - add '%s' HAState %s",
@@ -111,47 +178,57 @@ static void amf_csi_set_callback(SaInvoc
syslog(LOG_DEBUG, "\tname: %s, value: %s",
attr->attrName, attr->attrValue);
}
+ csi = std::string((char*)csi_desc.csiName.value,
csi_desc.csiName.length);
} else if (csi_desc.csiFlags == SA_AMF_CSI_TARGET_ALL) {
syslog(LOG_INFO, "CSI Set - HAState %s for all assigned CSIs",
ha_state_name[ha_state]);
- } else {
+ csi = "all";
+ } else if (csi_desc.csiFlags == SA_AMF_CSI_TARGET_ONE){
syslog(LOG_INFO, "CSI Set - HAState %s for '%s'",
ha_state_name[ha_state], csi_desc.csiName.value);
+ csi = std::string((char*)csi_desc.csiName.value,
csi_desc.csiName.length);
}
+ error = update_csi_list(csi, ha_state);
+ /* If update csi(s) state successfully,
+ * take actions on ha state changes
+ */
+ if (error == SA_AIS_OK) {
+ switch (ha_state) {
+ case SA_AMF_HA_ACTIVE:
+ status = foo_activate();
- switch (ha_state) {
- case SA_AMF_HA_ACTIVE:
- status = foo_activate();
- break;
- case SA_AMF_HA_STANDBY:
- /*
- * Not much to do in this simple example code
- * For real one could open a checkpoint for reads
- * Open a communication channel for listening
- * etc.
- */
- status = 0;
- break;
- case SA_AMF_HA_QUIESCED:
- /* the effect of admin op lock on SU or node or ... */
- status = foo_deactivate();
- break;
- case SA_AMF_HA_QUIESCING:
- /* the effect of admin op lock on SU or node or ... */
- status = 0;
- break;
- default:
- syslog(LOG_ERR, "unmanaged HA state %u", ha_state);
- status = -1;
- break;
+ break;
+ case SA_AMF_HA_STANDBY:
+ /*
+ * Not much to do in this simple example code
+ * For real one could open a checkpoint for reads
+ * Open a communication channel for listening
+ * etc.
+ */
+
+ status = 0;
+ break;
+ case SA_AMF_HA_QUIESCED:
+ /* the effect of admin op lock on SU or node or ... */
+ status = foo_deactivate();
+ break;
+ case SA_AMF_HA_QUIESCING:
+ /* the effect of admin op lock on SU or node or ... */
+ status = 0;
+ break;
+ default:
+ syslog(LOG_ERR, "unmanaged HA state %u", ha_state);
+ status = -1;
+ break;
+ }
+
+ if (status == 0)
+ error = SA_AIS_OK;
+ else
+ error = SA_AIS_ERR_FAILED_OPERATION;
}
- if (status == 0)
- error = SA_AIS_OK;
- else
- error = SA_AIS_ERR_FAILED_OPERATION;
-
rc = saAmfResponse(my_amf_hdl, invocation, error);
if (rc != SA_AIS_OK) {
syslog(LOG_ERR, "saAmfResponse FAILED - %u", rc);
@@ -166,21 +243,31 @@ static void amf_csi_set_callback(SaInvoc
syslog(LOG_ERR, "saAmfCSIQuiescingComplete FAILED -
%u", rc);
exit(1);
}
+
if (csi_desc.csiFlags == SA_AMF_CSI_TARGET_ONE) {
rc = saAmfHAStateGet(my_amf_hdl, comp_name,
&csi_desc.csiName, &my_ha_state);
if (rc != SA_AIS_OK) {
- syslog(LOG_ERR, "saAmfHAStateGet FAILED - %u",
rc);
+ syslog(LOG_ERR, "saAmfHAStateGet FAILED for
'%s'- rc:%u", csi_desc.csiName.value, rc);
exit(1);
}
} else if (csi_desc.csiFlags == SA_AMF_CSI_TARGET_ALL) {
- // Application could iterate saAmfHAStateGet() for
every csi
- // which had been assigned to this component to ensure
- // all csi(s) are QUIESCED
+ for( std::map<std::string,int>::iterator iter =
my_csi_list.begin() ;
+ iter != my_csi_list.end() ; ++iter ) {
+ SaNameT one_csi;
+ strcpy((char*)&one_csi.value,
iter->first.c_str());
+ one_csi.length = strlen(iter->first.c_str());
- // temporary set to QUIESCED
- my_ha_state = SA_AMF_HA_QUIESCED;
+ rc = saAmfHAStateGet(my_amf_hdl, comp_name,
&one_csi, &my_ha_state);
+ if (rc != SA_AIS_OK) {
+ syslog(LOG_ERR, "saAmfHAStateGet FAILED
for '%s'- rc:%u", one_csi.value, rc);
+ exit(1);
+ }
+ if (my_ha_state != SA_AMF_HA_QUIESCED)
+ break;
+ }
}
+ error = update_csi_list(csi, my_ha_state);
syslog(LOG_INFO, "My HA state is %s",
ha_state_name[my_ha_state]);
}
}
@@ -201,20 +288,23 @@ static void amf_csi_remove_callback(SaIn
const
SaNameT *csi_name,
SaAmfCSIFlagsT csi_flags)
{
- SaAisErrorT rc;
-
- if (csi_flags == SA_AMF_CSI_TARGET_ALL)
+ SaAisErrorT rc, error;
+ std::string csi;
+ if (csi_flags == SA_AMF_CSI_TARGET_ALL) {
syslog(LOG_INFO, "CSI Remove for all CSIs");
- else if (csi_flags == SA_AMF_CSI_TARGET_ONE)
+ csi = "all";
+ } else if (csi_flags == SA_AMF_CSI_TARGET_ONE) {
syslog(LOG_INFO, "CSI Remove for '%s'", csi_name->value);
- else
+ csi = std::string((char*)csi_name->value, csi_name->length);
+ } else
// A non valid case, see 7.9.3
abort();
/* Reset the HA state */
- my_ha_state = 0;
-
- rc = saAmfResponse(my_amf_hdl, invocation, SA_AIS_OK);
+ my_ha_state = (SaAmfHAStateT)0;
+ // remove csi
+ error = remove_csi(csi);
+ rc = saAmfResponse(my_amf_hdl, invocation, error);
if (rc != SA_AIS_OK) {
syslog(LOG_ERR, "saAmfResponse FAILED - %u", rc);
exit(1);
diff --git a/tools/cluster_sim_uml/build_uml b/tools/cluster_sim_uml/build_uml
--- a/tools/cluster_sim_uml/build_uml
+++ b/tools/cluster_sim_uml/build_uml
@@ -74,7 +74,7 @@ cmd_build_testprog() {
mkdir -p $installd
cp $src/amf_demo_script $installd
- gcc -g -O2 -Wall -fPIC -I$opensaf_home/osaf/libs/saf/include \
+ g++ -g -O2 -Wall -fPIC -I$opensaf_home/osaf/libs/saf/include \
-o $installd/amf_demo $src/amf_demo.c \
-L$libd -lSaAmf -L$libd/opensaf -lopensaf_core
------------------------------------------------------------------------------
Monitor Your Dynamic Infrastructure at Any Scale With Datadog!
Get real-time metrics from all of your servers, apps and tools
in one place.
SourceForge users - Click here to start your Free Trial of Datadog now!
http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140
_______________________________________________
Opensaf-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/opensaf-devel