"Fossies" - the Fresh Open Source Software Archive

Member "opensaf-5.21.09/src/osaf/immtools/imm_modify_config/add_operation_to_ccb.cc" (1 Jun 2021, 10467 Bytes) of package /linux/misc/opensaf-5.21.09.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "add_operation_to_ccb.cc" see the Fossies "Dox" file reference documentation.

    1 /*      -*- OpenSAF  -*-
    2  *
    3  * (C) Copyright 2008 The OpenSAF Foundation
    4  * Copyright Ericsson AB 2018 - All Rights Reserved.
    5  *
    6  * This program is distributed in the hope that it will be useful, but
    7  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    8  * or FITNESS FOR A PARTICULAR PURPOSE. This file and program are licensed
    9  * under the GNU Lesser General Public License Version 2.1, February 1999.
   10  * The complete license can be accessed from the following location:
   11  * http://opensource.org/licenses/lgpl-license.php
   12  * See the Copying file included with the OpenSAF distribution for full
   13  * licensing terms.
   14  *
   15  * Author(s): Ericsson AB
   16  *
   17  */
   18 
   19 #include "osaf/immtools/imm_modify_config/add_operation_to_ccb.h"
   20 
   21 #include <limits.h>
   22 
   23 #include <string>
   24 #include <vector>
   25 #include <memory>
   26 #include <utility>
   27 #include <stdexcept>
   28 
   29 #include "base/logtrace.h"
   30 #include "base/time.h"
   31 #include "ais/include/saImm.h"
   32 #include "ais/include/saAis.h"
   33 
   34 #include "osaf/immtools/imm_modify_config/immccb.h"
   35 #include "osaf/immtools/imm_modify_config/attribute.h"
   36 
   37 #include "osaf/immtools/imm_om_ccapi/common/common.h"
   38 #include "osaf/immtools/imm_om_ccapi/om_ccb_object_create.h"
   39 #include "osaf/immtools/imm_om_ccapi/om_ccb_object_delete.h"
   40 #include "osaf/immtools/imm_om_ccapi/om_ccb_object_modify.h"
   41 
   42 namespace modelmodify {
   43 
   44 // Error information. See immccb.h
   45 std::string api_name_;
   46 static SaAisErrorT ais_error_ = SA_AIS_OK;
   47 
   48 void GetAddToCbbErrorInfo(ErrorInformation *error_info) {
   49   error_info->api_name = api_name_;
   50   error_info->ais_error = ais_error_;
   51 }
   52 
   53 bool IsResorceAbort(const SaImmCcbHandleT& ccbHandle) {
   54   bool rc = false;
   55 
   56   const SaStringT *errString = nullptr;
   57   SaAisErrorT ais_rc = saImmOmCcbGetErrorStrings(ccbHandle, &errString);
   58   if ((ais_rc == SA_AIS_OK) && (errString != nullptr)) {
   59     LOG_NO("%s: Error string: '%s'", __FUNCTION__, errString[0]);
   60     std::string err_str(errString[0]);
   61     if (err_str.find("IMM: Resource abort: ") != std::string::npos) {
   62       // Is Resource Abort
   63       rc = true;
   64     }
   65   }
   66 
   67   return rc;
   68 }
   69 
   70 int AddCreateToCcb(const SaImmCcbHandleT& ccb_handle,
   71                        const CreateDescriptor& create_descriptor) {
   72   TRACE_ENTER2("Parent '%s', Class '%s'",
   73                create_descriptor.parent_name.c_str(),
   74                create_descriptor.class_name.c_str());
   75 
   76   int recovery_info = kNotSet;
   77 
   78   // Setup a creator with class name and parent name
   79   // -----------------------------------------------
   80   immom::ImmOmCcbObjectCreate creator(ccb_handle);
   81   if (create_descriptor.parent_name.empty() != true) {
   82     // Do not call this method if no parent name is given. The object will be
   83     // created as a root object
   84     creator.SetParentName(create_descriptor.parent_name);
   85   }
   86   creator.SetClassName(create_descriptor.class_name);
   87 
   88   // Add all values for all attributes that shall be set at creation time
   89   // including the object name to the creator
   90   // Note:  For each attribute the creator needs a vector of pointers to the
   91   //        attribute values. This vector  must have the same scope as the
   92   //        creator.
   93   AttributeHandler attributes(&creator);
   94   if (attributes.AddAttributesForObjectCreate(create_descriptor) == false) {
   95     LOG_NO("%s: SetAttributeValues() Fail", __FUNCTION__);
   96     recovery_info = kFail;
   97     api_name_.clear();
   98     ais_error_ = SA_AIS_OK;
   99   }
  100 
  101   // Add the create operation to the CCB
  102   if (recovery_info != kFail) {
  103     if (creator.AddObjectCreateToCcb() == false) {
  104       // Add create Fail
  105       SaAisErrorT ais_rc = creator.ais_error();
  106       api_name_ = "saImmOmCcbObjectCreate_2";
  107       ais_error_ = ais_rc;
  108       if (ais_rc == SA_AIS_ERR_BAD_HANDLE) {
  109         recovery_info = kRestartOm;
  110         TRACE("%s: AddObjectCreateToCcb(), %s, kRestartOm",
  111               __FUNCTION__, saf_error(ais_rc));
  112       } else if (ais_rc == SA_AIS_ERR_FAILED_OPERATION) {
  113         if (IsResorceAbort(ccb_handle)) {
  114           TRACE("%s: AddObjectCreateToCcb(), %s, kRestartOm",
  115                 __FUNCTION__, saf_error(ais_rc));
  116           recovery_info = kRestartOm;
  117         } else {
  118           LOG_NO("%s: AddObjectCreateToCcb() Fail, %s", __FUNCTION__,
  119                  saf_error(ais_rc));
  120           recovery_info = kFail;
  121         }
  122       } else if (ais_rc == SA_AIS_ERR_EXIST) {
  123         if (create_descriptor.ignore_ais_err_exist == true) {
  124           recovery_info = kContinue;
  125         } else {
  126           recovery_info = kFail;
  127         }
  128       } else {
  129         // Unrecoverable Fail
  130         LOG_NO("%s: ObjectCreateCcbAdd(), %s, kFail",
  131                __FUNCTION__, saf_error(ais_rc));
  132         recovery_info = kFail;
  133       }
  134     } else {
  135       // Add create success
  136       recovery_info = kContinue;
  137     }
  138   }
  139 
  140   TRACE_LEAVE2("recovery_info = %s", RecoveryTxt(recovery_info));
  141   return recovery_info;
  142 }
  143 
  144 int AddDeleteToCcb(const SaImmCcbHandleT& ccb_handle,
  145                          const DeleteDescriptor&
  146                          delete_descriptor) {
  147   TRACE_ENTER();
  148   int recovery_info = kNotSet;
  149 
  150   // Setup an object deleter
  151   immom::ImmOmCcbObjectDelete deletor(ccb_handle);
  152 
  153   // Add the delete operation to the CCB. Try again if BUSY
  154   base::Timer busy_timer(kBusyTimeout);
  155   while (busy_timer.is_timeout() != true) {
  156     if (deletor.AddObjectDeleteToCcb(delete_descriptor.object_name) == false) {
  157       // Add delete Fail
  158       SaAisErrorT ais_rc = deletor.ais_error();
  159       api_name_ = "saImmOmCcbObjectDelete";
  160       ais_error_ = ais_rc;
  161       if (ais_rc == SA_AIS_ERR_BUSY) {
  162         base::Sleep(base::MillisToTimespec(kBusyWait));
  163         continue;
  164       } else if (ais_rc == SA_AIS_ERR_BAD_HANDLE) {
  165         TRACE("%s: AddObjectDeleteToCcb() RestartOm, %s", __FUNCTION__,
  166               saf_error(ais_rc));
  167         recovery_info = kRestartOm;
  168         break;
  169       } else if (ais_rc == SA_AIS_ERR_FAILED_OPERATION) {
  170         if (IsResorceAbort(ccb_handle)) {
  171           TRACE("%s: AddObjectDeleteToCcb(), %s, RestartOm",
  172                 __FUNCTION__, saf_error(ais_rc));
  173           recovery_info = kRestartOm;
  174           break;
  175         } else {
  176           // Unrecoverable Fail
  177           LOG_NO("%s: AddObjectDeleteToCcb() Fail, %s", __FUNCTION__,
  178                  saf_error(ais_rc));
  179           recovery_info = kFail;
  180           break;
  181         }
  182       } else if (ais_rc == SA_AIS_ERR_NOT_EXIST) {
  183         if (delete_descriptor.ignore_ais_err_not_exist == true) {
  184           recovery_info = kContinue;
  185         } else {
  186           LOG_NO("%s: AddObjectDeleteToCcb() Fail, %s", __FUNCTION__,
  187                  saf_error(ais_rc));
  188           recovery_info = kFail;
  189         }
  190       }  else {
  191         // Other unrecoverable Fail
  192         LOG_NO("%s: AddObjectDeleteToCcb() Fail, %s", __FUNCTION__,
  193                saf_error(ais_rc));
  194         recovery_info = kFail;
  195         break;
  196       }
  197     }
  198 
  199     // AddObjectDeleteToCcb() Success
  200     recovery_info = kContinue;
  201     break;
  202   }
  203   if ((busy_timer.is_timeout() == true) &&
  204       (recovery_info == kNotSet)) {
  205     LOG_NO("%s: AddObjectDeleteToCcb() Fail, BUSY timeout",
  206            __FUNCTION__);
  207     recovery_info = kFail;
  208     api_name_ = "";
  209     ais_error_ = SA_AIS_OK;
  210   }
  211 
  212   TRACE_LEAVE();
  213   return recovery_info;
  214 }
  215 
  216 // Add one modify operation to a CCB
  217 // Recovery:  BAD HANDLE; kRestartOm
  218 //            FAILED OPERATION; kRestartOm or kFail
  219 //            BUSY; An admin operation is ongoing on an object to be modified
  220 //                  We can try again to add the modify
  221 // return: Recovery information. See immccb.h
  222 int AddModifyToCcb(const SaImmCcbHandleT& ccb_handle,
  223                          const ModifyDescriptor&
  224                          modify_descriptor) {
  225   TRACE_ENTER();
  226   int recovery_info = kNotSet;
  227 
  228   // Setup an object modifier
  229   immom::ImmOmCcbObjectModify modifier(ccb_handle,
  230                                        modify_descriptor.object_name);
  231 
  232   // One modify operation does only modify one object but may modify several
  233   // attributes in that object.
  234   // Add all values for all attributes that shall be modified
  235   // including the object name to the modifier
  236   // Note:  For each attribute the modifier needs a vector of pointers to the
  237   //        modify descriptors. This vector  must have the same scope as the
  238   //        modifier. Each modify descriptor contains a value and a
  239   //        modification type
  240   AttributeHandler modifications(&modifier);
  241   if (modifications.AddAttributesForModification(modify_descriptor) == false) {
  242     LOG_NO("%s: SetAttributeValues() Fail", __FUNCTION__);
  243     recovery_info = kFail;
  244     api_name_ = "";
  245     ais_error_ = SA_AIS_OK;
  246   }
  247 
  248   if (recovery_info == kNotSet) {
  249     // Add the modification request to the CCB. Try gain if BUSY
  250     SaAisErrorT ais_rc = SA_AIS_OK;
  251     base::Timer busy_timer(kBusyTimeout);
  252     while (busy_timer.is_timeout() != true) {
  253       if (modifier.AddObjectModifyToCcb() == false) {
  254         ais_rc = modifier.ais_error();
  255         api_name_ = "saImmOmCcbObjectModify_2";
  256         ais_error_ = ais_rc;
  257         if (ais_rc == SA_AIS_ERR_BUSY) {
  258           base::Sleep(base::MillisToTimespec(kBusyWait));
  259           continue;
  260         } else if (ais_rc == SA_AIS_ERR_BAD_HANDLE) {
  261           TRACE("%s: AddObjectModifyToCcb() RestartOm, %s", __FUNCTION__,
  262                 saf_error(ais_rc));
  263           recovery_info = kRestartOm;
  264           break;
  265         } else if (ais_rc == SA_AIS_ERR_FAILED_OPERATION) {
  266           if (IsResorceAbort(ccb_handle)) {
  267             TRACE("%s: AddObjectModifyToCcb(), %s, RestartOm",
  268                   __FUNCTION__, saf_error(ais_rc));
  269             recovery_info = kRestartOm;
  270             break;
  271           } else {
  272             // Unrecoverable Fail
  273             LOG_NO("%s: AddObjectModifyToCcb() Fail, %s", __FUNCTION__,
  274                    saf_error(ais_rc));
  275             recovery_info = kFail;
  276             break;
  277           }
  278         } else {
  279             // Unrecoverable Fail
  280             LOG_NO("%s: AddObjectModifyToCcb() Fail, %s", __FUNCTION__,
  281                    saf_error(ais_rc));
  282             recovery_info = kFail;
  283             break;
  284         }
  285       }
  286 
  287       // Add Modify to CCB Success
  288       recovery_info = kContinue;
  289       break;
  290     }
  291     if ((busy_timer.is_timeout() == true) &&
  292         (recovery_info == kNotSet)) {
  293       LOG_NO("%s: AddObjectModifyToCcb() Fail, BUSY timeout",
  294              __FUNCTION__);
  295       recovery_info = kFail;
  296       api_name_ = "";
  297       ais_error_ = SA_AIS_OK;
  298     }
  299   }
  300 
  301   TRACE_LEAVE();
  302   return recovery_info;
  303 }
  304 
  305 }  // namespace modelmodify