Add new libcynara-admin return code 18/28018/4
authorPawel Wieczorek <p.wieczorek2@samsung.com>
Wed, 24 Sep 2014 10:11:12 +0000 (12:11 +0200)
committerPawel Wieczorek <p.wieczorek2@samsung.com>
Thu, 16 Oct 2014 15:09:17 +0000 (17:09 +0200)
Added code is:
        CYNARA_ADMIN_API_OPERATION_FAILED

It is used to indicate failures during saving database to storage. This
patch also adds handling such situations.

Change-Id: I35b7d3334def8e688a180ddec6861c0f3bdd70d6

src/admin/logic/Logic.cpp
src/common/response/CodeResponse.h
src/include/cynara-error.h
src/service/logic/Logic.cpp

index 72c40bf..0deccb9 100644 (file)
@@ -96,6 +96,9 @@ int Logic::askCynaraAndInterpreteCodeResponse(Args... args) {
         case CodeResponse::Code::NO_BUCKET:
             LOGE("Trying to use unexisting bucket.");
             return CYNARA_API_BUCKET_NOT_FOUND;
+        case CodeResponse::Code::FAILED:
+            LOGC("Cynara service answered: Operation failed.");
+            return CYNARA_API_OPERATION_FAILED;
         default:
             LOGE("Unexpected response code from server: [%d]",
                  static_cast<int>(codeResponse->m_code));
index 8544310..7a6020f 100644 (file)
@@ -34,7 +34,8 @@ public:
     enum Code {
         OK,
         NO_BUCKET,
-        NOT_ALLOWED
+        NOT_ALLOWED,
+        FAILED
     };
 
     const Code m_code;
index e8900b8..728fc2a 100644 (file)
 /*! \brief   cynara service does not allow to perform requested operation */
 #define CYNARA_API_OPERATION_NOT_ALLOWED -7
 
+/*! \brief   cynara service failed to perform requested operation */
+#define CYNARA_API_OPERATION_FAILED      -8
+
 /*! \brief   cynara service hasn't found requested bucket */
-#define CYNARA_API_BUCKET_NOT_FOUND      -8
+#define CYNARA_API_BUCKET_NOT_FOUND      -9
 
 /*! \brief   indicating an unknown error */
-#define CYNARA_API_UNKNOWN_ERROR         -9
+#define CYNARA_API_UNKNOWN_ERROR         -10
 
 /** @}*/
 
index 1787575..eeed387 100644 (file)
@@ -23,6 +23,7 @@
 #include <log/log.h>
 #include <common.h>
 #include <exceptions/BucketNotExistsException.h>
+#include <exceptions/DatabaseException.h>
 #include <exceptions/DefaultBucketDeletionException.h>
 #include <exceptions/DefaultBucketSetNoneException.h>
 #include <exceptions/PluginErrorException.h>
@@ -129,6 +130,8 @@ void Logic::execute(RequestContextPtr context, InsertOrUpdateBucketRequestPtr re
     try {
         m_storage->addOrUpdateBucket(request->bucketId(), request->result());
         onPoliciesChanged();
+    } catch (const DatabaseException &ex) {
+        code = CodeResponse::Code::FAILED;
     } catch (const DefaultBucketSetNoneException &ex) {
         code = CodeResponse::Code::NOT_ALLOWED;
     }
@@ -142,6 +145,8 @@ void Logic::execute(RequestContextPtr context, RemoveBucketRequestPtr request) {
     try {
         m_storage->deleteBucket(request->bucketId());
         onPoliciesChanged();
+    } catch (const DatabaseException &ex) {
+        code = CodeResponse::Code::FAILED;
     } catch (const BucketNotExistsException &ex) {
         code = CodeResponse::Code::NO_BUCKET;
     } catch (const DefaultBucketDeletionException &ex) {
@@ -157,6 +162,8 @@ void Logic::execute(RequestContextPtr context, SetPoliciesRequestPtr request) {
         m_storage->insertPolicies(request->policiesToBeInsertedOrUpdated());
         m_storage->deletePolicies(request->policiesToBeRemoved());
         onPoliciesChanged();
+    } catch (const DatabaseException &ex) {
+        code = CodeResponse::Code::FAILED;
     } catch (const BucketNotExistsException &ex) {
         code = CodeResponse::Code::NO_BUCKET;
     }