void AbstractClientRemoteIODriver::driverInit(const chaos::common::data::CDataWrapper& init_parameter) { int err = 0; unsigned int iteration = 0; std::string content_type = "application/json"; CHECK_MANDATORY_KEY(const_cast<const CDataWrapper *>(&init_parameter) , "url", ERR, -2); CHECK_TYPE_OF_KEY(const_cast<const CDataWrapper *>(&init_parameter), "url", String, ERR, -3); const std::string url = init_parameter.getStringValue("url"); CHECK_ASSERTION_THROW_AND_LOG(url.size() != 0, ERR, -3, "The url parameter can't be empty string"); //! end point identifier & authorization key if(init_parameter.hasKey("endpoint_name")){ ExternalUnitClientEndpoint::endpoint_identifier = init_parameter.getStringValue("endpoint_name"); } else { ExternalUnitClientEndpoint::endpoint_identifier = init_parameter.getStringValue("uri"); } //check if a driver uri has been set if(init_parameter.hasKey("uri") && init_parameter.isStringValue("uri")) { setDriverUri(init_parameter.getStringValue("uri")); } if(init_parameter.hasKey("content_type") && init_parameter.isStringValue("content_type")) { content_type = init_parameter.getStringValue("content_type"); } CHECK_ASSERTION_THROW_AND_LOG((ExternalUnitClientEndpoint::endpoint_identifier.size() > 0), ERR, -4, "The endpoint name is empty"); //initilize subclass ClientARIODriver::driverInit(init_parameter); DBG <<"Initialize connection..."; //register this driver as external endpoint err = chaos::common::external_unit::ExternalUnitManager::getInstance()->initilizeConnection(*this, "http", content_type, url); DBG <<"Connection initialized with error:"<<err; CHECK_ASSERTION_THROW_AND_LOG(err == 0, ERR, -4, "Error creating connection"); //waith at least 3 seconds for connection while(conn_phase == RDConnectionPhaseConnected && iteration < 3) { sleep(1); iteration++; } //try anyway to send data if((err = _sendAuthenticationRequest())) {LOG_AND_TROW(AbstractRemoteIODriver_ERR, -1, "Error sending autorization request");} if((err = _sendInitRequest())) {LOG_AND_TROW(AbstractRemoteIODriver_ERR, -2, "Error sending initilization request");} }
void GetSnapshotDatasetForNode::getAsMap(chaos::common::data::CDataWrapper& api_result, VectorStrCDWShrdPtr& dataset_in_snapshot) { //now we have the result //SnapshotInformationPtr if(!api_result.hasKey("dataset_list")) return; if(!api_result.isVectorValue("dataset_list")) return; CMultiTypeDataArrayWrapperSPtr snapshot_list = api_result.getVectorValue("dataset_list"); for(int idx = 0; idx < snapshot_list->size(); idx++) { CDWUniquePtr snapshot_dataset_element(snapshot_list->getCDataWrapperElementAtIndex(idx)); const std::string dataset_name = snapshot_dataset_element->getStringValue(ControlUnitNodeDefinitionKey::CONTROL_UNIT_DATASET_NAME); CDWShrdPtr saved_dataset(snapshot_dataset_element->getCSDataValue("dataset_value")); dataset_in_snapshot.push_back(PairStrCDWShrdPtr(dataset_name, saved_dataset)); } }
/* Return the description of all action into a CDataWrapper */ void DeclareAction::getActionDescrionsInDataWrapper(chaos_data::CDataWrapper& actionsDescription, bool close) { boost::shared_ptr<chaos_data::CDataWrapper> actionDescription; vector<AbstActionDescShrPtr>::iterator actionIter; //cycle all actions for construct the vector of param action for (actionIter = actionDescriptionVector.begin(); actionIter != actionDescriptionVector.end(); actionIter++) { //decode action into CDataWrapper chaos_data::CDataWrapper actionDescription; //fill description with action value decodeAction(*actionIter, actionDescription); //add description to array of action for this declaring class actionsDescription.appendCDataWrapperToArray(actionDescription); } //finalize the vector with the appropiate key if(close)actionsDescription.finalizeArrayForKey(RpcActionDefinitionKey::CS_CMDM_ACTION_DESC); }
int AbstractApi::setValueFromString(chaos::common::data::CDataWrapper& dataset, const std::string& type, const std::string& attribute_name, const std::string& value) { int err = 0; if(type.compare("int32") == 0) { dataset.addInt32Value(attribute_name.c_str(), boost::lexical_cast<int32_t>(value)); }else if(type.compare("int64") == 0) { dataset.addInt64Value(attribute_name.c_str(), boost::lexical_cast<int64_t>(value)); }else if(type.compare("double") == 0) { dataset.addDoubleValue(attribute_name.c_str(), boost::lexical_cast<double>(value)); }else if(type.compare("string") == 0) { dataset.addStringValue(attribute_name.c_str(), value); }else if(type.compare("binary") == 0) { std::string decoded_binary = bson::base64::decode(value); dataset.addBinaryValue(attribute_name.c_str(), decoded_binary.c_str(), (uint32_t)decoded_binary.size()); }else if(type.compare("boolean") == 0) { dataset.addBoolValue(attribute_name.c_str(), boost::lexical_cast<bool>(value)); }else{ return -1; } return err; }
/* Return the description of all action into a CDataWrapper */ void DeclareAction::decodeAction(AbstActionDescShrPtr& actionDesc, chaos_data::CDataWrapper& actionDescription) { //add domain for the action actionDescription.addStringValue(RpcActionDefinitionKey::CS_CMDM_ACTION_DOMAIN, actionDesc->getTypeValue(AbstractActionDescriptor::ActionDomain)); //add name for the action actionDescription.addStringValue(RpcActionDefinitionKey::CS_CMDM_ACTION_NAME, actionDesc->getTypeValue(AbstractActionDescriptor::ActionName)); //add the information for the action actionDescription.addStringValue(RpcActionDefinitionKey::CS_CMDM_ACTION_DESCRIPTION, actionDesc->getTypeValue(AbstractActionDescriptor::ActionDescription)); //now i must describe the param for this action vector< boost::shared_ptr<ActionParamDescription> >& paramDescriptionVector = actionDesc->getParamDescriptions(); if(paramDescriptionVector.size()){ //there are some parameter for this action, need to be added to rapresentation boost::shared_ptr<chaos_data::CDataWrapper> paramDescRepresentation(new chaos_data::CDataWrapper()); for (vector< boost::shared_ptr<ActionParamDescription> >::iterator paramIter = paramDescriptionVector.begin(); paramIter !=paramDescriptionVector.end(); paramIter++) { //add thename of the parameter paramDescRepresentation->addStringValue(RpcActionDefinitionKey::CS_CMDM_ACTION_DESC_PAR_NAME, (*paramIter)->paramName); //add the information about the parameter paramDescRepresentation->addStringValue(RpcActionDefinitionKey::CS_CMDM_ACTION_DESC_PAR_INFO, (*paramIter)->paramDescription); //add the parameter type paramDescRepresentation->addInt32Value(RpcActionDefinitionKey::CS_CMDM_ACTION_DESC_PAR_TYPE, (*paramIter)->paramType); // add parametere representation object to main action representation actionDescription.appendCDataWrapperToArray(*paramDescRepresentation.get()); } //cloese the array actionDescription.finalizeArrayForKey(RpcActionDefinitionKey::CS_CMDM_ACTION_DESC_PARAM); } }