コード例 #1
0
/*---------------------------------------------------------------------------------
 
 ---------------------------------------------------------------------------------*/
CDataWrapper *AttributeValue::getValueAsCDatawrapperPtr(bool from_json) {
    CDataWrapper *result = NULL;
    if(!from_json) {
        result = new CDataWrapper((const char *)value_buffer);
    } else {
        result = new CDataWrapper();
        result->setSerializedJsonData((const char *)value_buffer);
    }
    return result;
}
コード例 #2
0
int initialize_from_old_mds(std::string conf){
    std::stringstream stringa;
    std::ifstream f(conf.c_str());
    if(f.fail()){
       throw CException(-3,__FUNCTION__,"Cannot open file:"+ conf);
    }
    std::cout<<"* reading:"<<conf<<std::endl;
    stringa << f.rdbuf();
    //std::cout<<"read:"<<stringa.str()<<std::endl;
   // BSONObj bson(" \"data_servers\" : [ { \"hostname\" : \"192.168.150.21:1672:30175|0\" , \"id_server\" : 5 , \"is_live\" : true} , { \"hostname\" : \"192.168.150.22:1672:30175|0\" , \"id_server\" : 6 , \"is_live\" : true} , { \"hostname\" : \"192.168.150.23:1672:30175|0\" , \"id_server\" : 7 , \"is_live\" : true}]");
    //BSONObj bson(strdup(stringa.str().c_str()));
    //std::cout<<"BJSON:"<<bson.jsonString();
    CDataWrapper mdsconf;
    
    mdsconf.setSerializedJsonData(stringa.str().c_str());

    //! rest ALL
  //  std::cout<<"json:"<<data.getJSONString()<<std::endl;
    std::auto_ptr<CMultiTypeDataArrayWrapper> data_servers(mdsconf.getVectorValue("data_servers"));
    if(data_servers.get()){
         for(int cnt=0;cnt<data_servers->size();cnt++){
             std::basic_string<char>::iterator  pnt;
             int chan=0;
            std::stringstream ss;
            ss<<"data_server"<<cnt;
            std::auto_ptr<CDataWrapper> ele(data_servers->getCDataWrapperElementAtIndex(cnt));
            GET_CONFIG_STRING(ele.get(),hostname);
          //  GET_CONFIG_INT(data_servers->getCDataWrapperElementAtIndex(cnt),id_server);
            pnt=hostname.begin()+hostname.rfind('|');
            if(pnt!=hostname.end()){
                std::string schan;
                schan.assign(pnt+1,hostname.end());
                chan=atoi(schan.c_str());
                hostname.erase(pnt,hostname.end());
            }

            std::cout<<"* found dataserver["<<cnt<<"]:"<<hostname<<" channel:"<<chan<<std::endl;
            EXECUTE_CHAOS_API(api_proxy::data_service::DeleteDS,3000,ss.str());
            EXECUTE_CHAOS_API(api_proxy::data_service::NewDS,3000,ss.str(),hostname,chan);

        }
    }

    CMultiTypeDataArrayWrapper* us=mdsconf.getVectorValue("us");
    if(us){
        for(int cnt=0;(us!=NULL)&&(cnt<us->size());cnt++){
            std::auto_ptr<CDataWrapper> usw(us->getCDataWrapperElementAtIndex(cnt));
            GET_CONFIG_STRING(usw,unit_server_alias);
            std::cout<<"* found us["<<cnt<<"]:"<<unit_server_alias<<std::endl;
            //GET_CHAOS_API_PTR(api_proxy::unit_server::NewUS)->execute(usname.c_str());
           //  EXECUTE_CHAOS_API(api_proxy::unit_server::DeleteUS,3000,unit_server_alias);
            try {
             EXECUTE_CHAOS_API(api_proxy::unit_server::NewUS,3000,unit_server_alias);
            } catch(CException e){
            	std::cout<<" warning:"<<" cannot create a new US:"<<unit_server_alias<<std::endl;
            }
             CMultiTypeDataArrayWrapper* cu_l=usw->getVectorValue("cu_desc");
             for(int cui=0;(cu_l !=NULL) && (cui<cu_l->size());cui++){
                 api_proxy::control_unit::SetInstanceDescriptionHelper cud;
                 std::auto_ptr<CDataWrapper> cuw(cu_l->getCDataWrapperElementAtIndex(cui));
                 GET_CONFIG_STRING(cuw,cu_id);
                 GET_CONFIG_STRING(cuw,cu_type);
                 GET_CONFIG_STRING(cuw,cu_param);
                 GET_CONFIG_DEFAULT_BOOL(cuw,auto_load,true);
                 GET_CONFIG_DEFAULT_BOOL(cuw,auto_init,true);
                 GET_CONFIG_DEFAULT_BOOL(cuw,auto_start,true);
		 GET_CONFIG_DEFAULT_INT(cuw,storage_type,1);
		 GET_CONFIG_DEFAULT_INT(cuw,storage_ageing,3600*24);
                 std::cout<<"\t"<<cu_id<<","<<cu_type<<std::endl;
                 cud.auto_load=auto_load;
                 cud.auto_init=auto_init;
                 cud.auto_start=auto_start;
                 cud.load_parameter = cu_param;
                 cud.control_unit_uid=cu_id;
                 cud.unit_server_uid=unit_server_alias;
                 cud.control_unit_implementation=cu_type;
		 cud.history_ageing=storage_ageing;
		 cud.storage_type=(chaos::DataServiceNodeDefinitionType::DSStorageType)storage_type;
                 //EXECUTE_CHAOS_API(api_proxy::unit_server::ManageCUType,3000,unit_server_alias,cu_type,1);
                 EXECUTE_CHAOS_API(api_proxy::control_unit::DeleteInstance,3000,unit_server_alias,cu_id);
                 EXECUTE_CHAOS_API(api_proxy::control_unit::Delete,3000,cu_id);
                 EXECUTE_CHAOS_API(api_proxy::unit_server::ManageCUType,3000,unit_server_alias,cu_type,0);

                 // drivers
                 std::auto_ptr<CMultiTypeDataArrayWrapper> drv_l(cuw->getVectorValue("DriverDescription"));
                 for(int drv=0;(drv_l.get() !=NULL) && (drv<drv_l->size());drv++){
                     std::auto_ptr<CDataWrapper> drv_w(drv_l->getCDataWrapperElementAtIndex(drv));

                    GET_CONFIG_STRING(drv_w,DriverDescriptionName);
                    GET_CONFIG_STRING(drv_w,DriverDescriptionVersion);
                    GET_CONFIG_STRING(drv_w,DriverDescriptionInitParam);
                    cud.addDriverDescription(DriverDescriptionName,DriverDescriptionVersion,DriverDescriptionInitParam);
                 }
                 //attributes
                 std::auto_ptr<CMultiTypeDataArrayWrapper> attr_l(cuw->getVectorValue("AttrDesc"));
                 for(int attr=0;(attr_l.get() !=NULL) && (attr<attr_l->size());attr++){
                     std::auto_ptr<CDataWrapper> attr_w(attr_l->getCDataWrapperElementAtIndex(attr));

                    GET_CONFIG_STRING(attr_w,ds_attr_name);
                    GET_CONFIG_STRING(attr_w,ds_default_value);
                    GET_CONFIG_STRING(attr_w,ds_max_range);
                    GET_CONFIG_STRING(attr_w,ds_min_range);

                    cud.addAttributeConfig(ds_attr_name,ds_default_value,ds_max_range,ds_min_range);
                 }

                 EXECUTE_CHAOS_API(api_proxy::control_unit::SetInstanceDescription,3000,cud);
             }
        }
    }


    return 0;
}