]> rtime.felk.cvut.cz Git - frescor/frsh.git/commitdiff
Add fcb_remember_contracts() to simplify the code
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 25 Jun 2010 08:47:01 +0000 (10:47 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 25 Jun 2010 12:39:26 +0000 (14:39 +0200)
fres/cbroker/fcb.c
frsh_api/tests/trans_nego.c

index a1d6014bde8297bf0d219e624740104e0c39458f..26aea51cfb8e1e3aa838171780a902e2fc90d6da 100644 (file)
@@ -760,6 +760,7 @@ int cancel_reservations(struct resource *resource)
                ret = fres_forbex2err(&ev);
                goto err_free;
        }
+       
        return 0;
 err_free:
        forb_sequence_free_buf(&commit_ids, forb_no_destructor);
@@ -767,6 +768,39 @@ err:
        return ret;
 }
 
+/* Add new contracts to our fcb database for later
+ * reference. Canceled contracts are removed below. */
+int
+fcb_remember_contracts(struct fcb *fcb,
+                      struct fcb_contract **fcb_contracts,
+                      int num)
+{
+       struct fcb_contract *fc;
+       int i;
+       
+       for (i=0; i<num; i++) {
+               fc =  fcb_contracts[i];
+
+               if (fc->user_contract) {
+                       if (fres_contract_get_num_blocks(fc->requested_contract) > 0) {
+                               /* Renegotiation */
+                               fres_contract_destroy(fc->user_contract);
+                               fc->user_contract = fres_contract_duplicate(fc->requested_contract);
+                               /* Note: requested_contract is also
+                                * pointed by contracts parameter and
+                                * will be freed by FORB. */
+                               fc->requested_contract = NULL;
+                       }
+               } else {
+                       /* Insert new contracts */
+                       fcb_contract_insert(fcb, fcb_contracts[i]);
+                       fc->user_contract = fres_contract_duplicate(fc->requested_contract);
+                       fc->requested_contract = NULL;
+                       /* See the note above. */
+               }
+       }
+       return 0;
+}
 
 CORBA_long
 negotiate_contracts(fres_contract_broker obj,
@@ -779,7 +813,7 @@ negotiate_contracts(fres_contract_broker obj,
        int ret = 0;
        forb_server_id app;
        fres_contract_ptr_seq *schedulable_contracts;
-       struct fcb_contract **fcb_contracts, *fc;
+       struct fcb_contract **fcb_contracts;
        unsigned i;
        int num = contracts->_length;
 
@@ -830,29 +864,7 @@ negotiate_contracts(fres_contract_broker obj,
        if (ret)
                goto err_cancel_reservation;
 
-       /* Add new contracts to our fcb database for later
-        * reference. Canceled contracts are removed below. */
-       for (i=0; i<num; i++) {
-               fc =  fcb_contracts[i];
-
-               if (fc->user_contract) {
-                       if (fres_contract_get_num_blocks(fc->requested_contract) > 0) {
-                               /* Renegotiation */
-                               fres_contract_destroy(fc->user_contract);
-                               fc->user_contract = fres_contract_duplicate(fc->requested_contract);
-                               /* Note: requested_contract is also
-                                * pointed by contracts parameter and
-                                * will be freed by FORB. */
-                               fc->requested_contract = NULL;
-                       }
-               } else {
-                       /* Insert new contracts */
-                       fcb_contract_insert(fcb, fcb_contracts[i]);
-                       fc->user_contract = fres_contract_duplicate(fc->requested_contract);
-                       fc->requested_contract = NULL;
-                       /* See the note above. */
-               }
-       }
+       fcb_remember_contracts(fcb, fcb_contracts, num);
 
        ret = change_vreses(fcb, schedulable_contracts);
        if (ret)
@@ -1100,8 +1112,9 @@ negotiate_transaction(fres_contract_broker _obj,
        struct res_array res_array;
        struct res_key key;
        struct resource *resource;
+       fres_contract_ptr_seq *schedulable_contracts;
 
-       ul_logmsg("Negotiating transaction of %d contracts\n", num);
+       ul_logmsg("Negotiating transaction with %d contracts\n", num);
        if (transaction_has_spare_capacity(transaction)) {
                ret =  FRES_ERR_SPARE_CAPACITY_NOT_SUPPORTED;
                goto err;
@@ -1142,12 +1155,14 @@ negotiate_transaction(fres_contract_broker _obj,
                }
        }
        gsa_cust_for_each(res_array, &res_array, resource) {
-               ret = commit_resource(resource);
+               ret = commit_resource(resource, &schedulable_contracts);
                if (ret) {
                        ul_logerr("Commit failed\n");
                        goto err_cancel_reservation;
                }
        }
+       fcb_remember_contracts(fcb, fcb_contracts, num);
+       forb_sequence_free(schedulable_contracts, fres_contract_ptr_destroy);
        
        res_array_delete_all(&res_array);
        return 0;
index f34ad396b04341d518eeba676c964450577b40ad..1fba70875a1b9a6daf2bb3b7f558aeed2ead3294 100644 (file)
@@ -36,8 +36,8 @@ WVTEST_MAIN("transaction negotiation")
 
                WVFRSH(frsh_transaction_add_contract(&t, &contract[i], i));
        }
-#if 0  
        WVFRSH(frsh_transaction_negotiate(&t));
+#if 0  
 
        WVFRSH(frsh_transaction_alloc_vres(&t, TEST_CONTRACT_1, &vres1));
        WVFRSH(frsh_transaction_alloc_vres(&t, TEST_CONTRACT_2, &vres2));