]> rtime.felk.cvut.cz Git - frescor/frsh.git/commitdiff
frsh_transaction_alloc_vres works
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 25 Jun 2010 21:05:10 +0000 (23:05 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 25 Jun 2010 21:05:10 +0000 (23:05 +0200)
fres/cbroker/fcb.c
fres/cbroker/fcb.idl
frsh_api/frsh_transaction.c
frsh_api/tests/trans_nego.c
frsh_api/tests/trans_nego.h
frsh_api/tests/trans_nego.sh
frsh_api/tests/trans_nego2.c

index bd0f5cba892ac6ee48d80df7f49241ba7540370e..bbc8690084eee2c2b26e9283b1b4f93a4adccd96 100644 (file)
@@ -846,8 +846,7 @@ err:
  * reference. Canceled contracts are removed below. */
 int
 fcb_remember_contracts(struct fcb *fcb,
-                      struct fcb_contract **fcb_contracts, int num,
-                      fres_contract_ptr_seq *schedulable_contracts)
+                      struct fcb_contract **fcb_contracts, int num)
 {
        struct fcb_contract *fc;
        int i;
@@ -873,17 +872,27 @@ fcb_remember_contracts(struct fcb *fcb,
                        /* See the note above. */
                }
        }
+       return 0;
+}
+
+int
+fcb_remember_schedulable_contracts(struct fcb *fcb,
+                                  fres_contract_ptr_seq *schedulable_contracts)
+{
+       struct fcb_contract *fc;
+       int i;
        for (i=0; i<schedulable_contracts->_length; i++) {
                struct fres_contract *sc = schedulable_contracts->_buffer[i];
                fc = fcb_contract_find(fcb, &sc->id);
                assert(fc != NULL);
                fres_contract_destroy(fc->schedulable_contract);
                fc->schedulable_contract = fres_contract_duplicate(sc);
+               assert(fc->schedulable_contract);
        }
-
        return 0;
 }
 
+
 CORBA_long
 negotiate_contracts(fres_contract_broker obj,
                    const fres_contract_ptr_seq* contracts,
@@ -946,8 +955,8 @@ negotiate_contracts(fres_contract_broker obj,
        if (ret)
                goto err_cancel_reservation;
 
-       fcb_remember_contracts(fcb, fcb_contracts, num,
-                              schedulable_contracts);
+       fcb_remember_contracts(fcb, fcb_contracts, num);
+       fcb_remember_schedulable_contracts(fcb, schedulable_contracts);
 
        ret = change_vreses(fcb, schedulable_contracts);
        if (ret)
@@ -1198,7 +1207,7 @@ negotiate_transaction(fres_contract_broker _obj,
        fres_contract_ptr_seq *schedulable_contracts;
        struct fcb_transaction *ft;
 
-       ul_logmsg("Negotiating transaction with %d contracts\n", num);
+       ul_logmsg("Negotiating transaction '%s' with %d contracts\n", transaction->name, num);
        if (transaction_has_spare_capacity(transaction)) {
                ret =  FRES_ERR_SPARE_CAPACITY_NOT_SUPPORTED;
                goto err;
@@ -1238,16 +1247,16 @@ negotiate_transaction(fres_contract_broker _obj,
                        goto err_cancel_reservation;
                }
        }
+       fcb_remember_contracts(fcb, fcb_contracts, num);
        gsa_cust_for_each(res_array, &res_array, resource) {
                ret = commit_resource(resource, &schedulable_contracts);
                if (ret) {
                        ul_logerr("Commit failed\n");
                        goto err_cancel_reservation;
                }
+               fcb_remember_schedulable_contracts(fcb, schedulable_contracts);
+               forb_sequence_free(schedulable_contracts, fres_contract_ptr_destroy);
        }
-       fcb_remember_contracts(fcb, fcb_contracts, num,
-                              schedulable_contracts);
-       forb_sequence_free(schedulable_contracts, fres_contract_ptr_destroy);
 
        ft = fcb_transaction_new(transaction->name);
        if (!ft) {
@@ -1310,20 +1319,66 @@ wait_transaction(fres_contract_broker _obj,
 CORBA_long
 allocate_transaction_vres(fres_contract_broker _obj,
                          const CORBA_char * name,
-                         const CORBA_long id,
+                         const CORBA_long index,
+                         fres_contract_id_t *id,
                          CORBA_Environment *ev)
 {
        struct fcb *fcb = o2fcb(_obj);
        struct fcb_transaction *ft;
+       struct fcb_contract *fc;
        int ret;
-       char * const n = (char * const)&name;
+       struct res_alloc *ra;
+       char * const *n = (char * const *)&name;
+       struct res_key key;
+       struct resource *resource;
+       fres_contract_ptr_seq vreses;
+       CORBA_Environment ev2;
+       forb_server_id app;
+#define GOTO(label, error) do { ret = (error); goto label; } while(0)
 
-       ft = fcb_transaction_find(fcb, &n);
-       if (!ft) {
-               ret = FRES_ERR_TRANSACTION_NOT_FOUND;
-               goto err;
+       ul_logmsg("Allocate transaction VRES '%s'[%d]\n", name, index);
+       
+       ft = fcb_transaction_find(fcb, n);
+       if (!ft) GOTO(err, FRES_ERR_TRANSACTION_NOT_FOUND);
+
+       fc = tran_contract_indx2item(ft, index);
+       if (!fc) GOTO(err, FRSH_ERR_TOO_LARGE);
+
+       if (!get_fc_res_key(fc, &key))
+               GOTO(err, FRSH_ERR_RESOURCE_ID_INVALID);
+       resource = fcb_resource_find(fcb, &key);
+       if (!resource)
+               GOTO(err, FRES_ERR_NO_RESOURCE_MANAGER);
+
+       forb_get_req_source(_obj, &app);
+       /* Find allocator for the requested VRES */
+       ra = fcb_alloc_find(resource, &app);
+       if (!ra) {
+               char str[60];
+               forb_server_id_to_string(str, &app, sizeof(str));
+               ul_logerr("No resource allocator found for %d.%d and %s\n",
+                         resource->key.type, resource->key.id, str);
+               GOTO(err, FRES_ERR_NO_RESOURCE_ALLOCATOR);
        }
+       fc->ra = ra;
+
+       if (!forb_sequence_alloc_buf(&vreses, 1))
+               GOTO(err, errno);
+
+       assert(fc->schedulable_contract);
+       forb_sequence_elem(&vreses, 0) = fc->schedulable_contract;
+       forb_sequence_length(&vreses) = 1;
+       ret = fres_resource_allocator_change_vreses(ra->ra, &vreses, &ev2);
+       ul_logerr("Err = %d\n", ret);
+       if (forb_exception_occurred(&ev2))
+               GOTO(err_free, fres_forbex2err(&ev2));
+       if (ret)
+               goto err_free;
+       *id = fc->id;
+       
        ret = 0;
+err_free:
+       forb_sequence_free_buf(&vreses, forb_no_destructor);
 err:
        return ret;
 }
index 34cda1a9c9a63875fe318c4be41fd2d9ae14a938..583a5ae2fe510dd08ba2d2a15569e431c09edc73 100644 (file)
@@ -158,7 +158,8 @@ module fres {
                long negotiate_transaction(in transaction_t transaction);
                long wait_transaction(in string name,
                                      out transaction_t transaction);
-               long allocate_transaction_vres(in string name, in long id);
+               long allocate_transaction_vres(in string name, in long index,
+                                              out contract::id_t cid);
        };
 };
 
index e1be8add87977dcbd5e1a0c4fe9827064b11ca95..94a4a77a035a191dcd66a6a7289f64af9f20cacd 100644 (file)
@@ -35,6 +35,7 @@
 #include <fres_transaction.h>
 #include <fcb.h>
 #include "frsh_forb.h"
+#include <fra_generic.h>
 
 int
 frsh_transaction_init(frsh_transaction_t *transaction,
@@ -119,12 +120,18 @@ frsh_transaction_alloc_vres(frsh_transaction_t *t,
 {
        int ret;
        struct forb_env env;
+       fres_contract_id_t id;
        ret = fres_contract_broker_allocate_transaction_vres(
-               frsh_forb_global.fcb, (*t)->name, index, &env);
+               frsh_forb_global.fcb, (*t)->name, index, &id, &env);
        if (forb_exception_occurred(&env)) {
                ret = fres_forbex2err(&env);
                goto err;
        }
+       if (ret)
+               goto err;
+       *vres = fra_get_vres(&id);
+       assert(*vres != NULL);
+
 err:
        return ret;
 }
index b5a1a75317468e88a9e389a994bd1858737008b9..789cec376790b311ec039673f8fab788b41fb998 100644 (file)
@@ -6,24 +6,22 @@
 WVTEST_MAIN("transaction negotiation")
 {
        frsh_contract_t contract[3];
-       const frsh_resource_id_t id[3] = { 0, 1, 255 };
        frsh_contract_label_t label[3];
        frsh_rel_time_t budget, period;
        int i;
        frsh_transaction_t t;
-       frsh_vres_id_t vres1, vres2;
+       frsh_vres_id_t vres0, vres1;
        
        WVFRSH(frsh_init());
-       WVFRSH(fra_dummy_init_and_activate_id(1));
 
        WVFRSH(frsh_transaction_init(&t, "test"));
 
-       for (i = TEST_CONTRACT_1; i <= TEST_CONTRACT_3; i++) {
+       for (i = TEST_CONTRACT_0; i <= TEST_CONTRACT_2; i++) {
                WVFRSH(frsh_contract_init(&contract[i]));
                sprintf(label[i], "contract%d", i);
                WVFRSH(frsh_contract_set_resource_and_label(
                               &contract[i],
-                              DUMMY_RESOURCE_TYPE, id[i],
+                              DUMMY_RESOURCE_TYPE, i,
                               label[i]));
 
                budget = fosa_msec_to_rel_time(10);
@@ -36,14 +34,18 @@ WVTEST_MAIN("transaction negotiation")
 
                WVFRSH(frsh_transaction_add_contract(&t, &contract[i], i));
        }
-       //WVPASS(frsh_transaction_alloc_vres(&t, TEST_CONTRACT_1, &vres1) == FRES_ERR_TRANSACTION_NOT_FOUND);
+       WVPASS(frsh_transaction_alloc_vres(&t, TEST_CONTRACT_0, &vres0) == FRES_ERR_TRANSACTION_NOT_FOUND);
        WVFRSH(frsh_transaction_negotiate(&t));
 
-#if 0  
+       WVFRSH(fra_dummy_init_and_activate_id(0));
+       WVFRSH(frsh_transaction_alloc_vres(&t, TEST_CONTRACT_0, &vres0));
+       
+       WVPASS(frsh_transaction_alloc_vres(&t, TEST_CONTRACT_1, &vres1) == FRES_ERR_NO_RESOURCE_ALLOCATOR);
+       WVFRSH(fra_dummy_init_and_activate_id(1));
        WVFRSH(frsh_transaction_alloc_vres(&t, TEST_CONTRACT_1, &vres1));
-       WVFRSH(frsh_transaction_alloc_vres(&t, TEST_CONTRACT_2, &vres2));
-       /* TEST_CONTRACT_3 is allocated in trans_nego2.c */
-
+       WVPASS(frsh_transaction_alloc_vres(&t, TEST_CONTRACT_2+1, &vres1) == FRSH_ERR_TOO_LARGE);
+       /* TEST_CONTRACT_2 is allocated in trans_nego2.c */
+#if 0
        WVPASS(frsh_contract_cancel(vres2) == FRES_ERR_VRES_PART_OF_TRANSACTION);
 #endif 
        frsh_destroy();
index 6875903b26b877c45306bf07dd09268c28ea7967..14907815f9e416b36073b3e7f96e79558a88f530 100644 (file)
@@ -2,9 +2,9 @@
 #define TRANS_NEGO_H
 
 enum {
-       TEST_CONTRACT_1 = 0,
-       TEST_CONTRACT_2 = 1,
-       TEST_CONTRACT_3 = 2,
+       TEST_CONTRACT_0 = 0,
+       TEST_CONTRACT_1 = 1,
+       TEST_CONTRACT_2 = 2,
 };
 
 #endif
index a37cfc0a46247daa4dafd4341c4664b05c7e117b..b20d0bb7ade9f83f70529b0fea5f1ddd52c50efc 100755 (executable)
@@ -4,20 +4,20 @@
 
 WVSTART Setup
 WVPASS fcb -dfcb.pid
-WVPASS frm_dummy -dfrm.pid
 WVPASS frm_dummy -dfrm0.pid -i0
 WVPASS frm_dummy -dfrm1.pid -i1
+WVPASS frm_dummy -dfrm2.pid -i2
 
 trap '
 WVSTART Kill
 WVPASS kill `cat fcb.pid`
 WVPASS rm fcb.pid
-WVPASS kill `cat frm.pid`
-WVPASS rm frm.pid
 WVPASS kill `cat frm0.pid`
 WVPASS rm frm0.pid
 WVPASS kill `cat frm1.pid`
 WVPASS rm frm1.pid
+WVPASS kill `cat frm2.pid`
+WVPASS rm frm2.pid
 ' 0
 
 WVPASS trans_nego
index 93ac5d980bf32ee1031ccb48e0d5f839389d0db3..e89372707d1ae5a7fc9cea7f0285f77d945c13a1 100644 (file)
@@ -6,7 +6,7 @@
 WVTEST_MAIN("transaction negotiation - remote part")
 {
        frsh_transaction_t t;
-       frsh_vres_id_t vres3;
+       frsh_vres_id_t vres;
        
        WVFRSH(frsh_init());
        WVFRSH(fra_dummy_init_and_activate_id(1));