void Processer::DoHost(const std::string& grid,const std::string& cluster,mongo::BSONObj& host) { std::string host_id; std::cout << host << std::endl; if(host.hasField("host_ID") && host.hasField("heartbeat")) { //deal the record with host level //do not need to cut it off DBModules::iterator iter = db_modules_.begin(); for(;iter!=db_modules_.end();++iter) { iter->handler(host.objdata(),host.objsize(),NULL); } // host_id = host.getStringField("host_ID"); // std::vector<mongo::BSONElement> ele; // host.elems(ele); // for(int i=0;i<ele.size();i++) // { // if((!strcmp(ele[i].fieldName(),"host_ID")) || // (!strcmp(ele[i].fieldName(),"heartbeat"))) // { // continue; // } // else // { // std::string ds_name = ele[i].fieldName(); // std::string path; // if(grid!="") // path = grid + '/' + cluster + '/' + host_id; // else // path = cluster + '/' + host_id; // mongo::BSONObj obj = ele[i].wrap(); // std::cout << obj << std::endl; // std::list<void(*)(const char*,int,const char*)>::iterator iter; // iter = callback_[ds_name].begin(); // for(;iter!=callback_[ds_name].end();++iter) // { // (*iter)(obj.objdata(),obj.objsize(),path.c_str()); // } // } // } } else { std::stringstream oss; oss << "This data is illegal! Drop!!"; LOG4CXX_WARN(log_,oss.str()); } }
RepoBSON::RepoBSON( const mongo::BSONObj &obj, const std::unordered_map<std::string, std::pair<std::string, std::vector<uint8_t>>> &binMapping) : mongo::BSONObj(obj), bigFiles(binMapping) { std::vector<std::pair<std::string, std::string>> existingFiles; if (bigFiles.size() > 0) { mongo::BSONObjBuilder builder, arrbuilder; for (const auto & pair : bigFiles) { //append field name :file name arrbuilder << pair.first << pair.second.first; } if (obj.hasField(REPO_LABEL_OVERSIZED_FILES)) { arrbuilder.appendElementsUnique(obj.getObjectField(REPO_LABEL_OVERSIZED_FILES)); } builder.append(REPO_LABEL_OVERSIZED_FILES, arrbuilder.obj()); builder.appendElementsUnique(obj); *this = builder.obj(); bigFiles = binMapping; } }
repo::core::RepoNodeTexture::RepoNodeTexture(const mongo::BSONObj &obj) : RepoNodeAbstract(obj) , data(NULL) { // // Width // if (obj.hasField(REPO_LABEL_WIDTH)) width = obj.getField(REPO_LABEL_WIDTH).numberInt(); // // Height // if (obj.hasField(REPO_LABEL_HEIGHT)) height = obj.getField(REPO_LABEL_HEIGHT).numberInt(); // // Format // if (obj.hasField(REPO_NODE_LABEL_EXTENSION)) { extension = obj.getField(REPO_NODE_LABEL_EXTENSION).str(); name += "." + extension; // assimp needs full names with extension } // // Bit depth // //if (obj.hasField(REPO_NODE_LABEL_BIT_DEPTH)) // bitDepth = obj.getField(REPO_NODE_LABEL_BIT_DEPTH).numberInt(); // // Data // if (obj.hasField(REPO_LABEL_DATA) && obj.hasField(REPO_NODE_LABEL_DATA_BYTE_COUNT)) { std::cerr << "Texture" << std::endl; data = new std::vector<char>(); RepoTranscoderBSON::retrieve( obj.getField(REPO_LABEL_DATA), obj.getField(REPO_NODE_LABEL_DATA_BYTE_COUNT).numberInt(), data); } }
void Processer::Handle(mongo::BSONObj& bson) { //handle the bson //maybe grid-bosn;maybe cluster-bson std::string grid_id; if(bson.hasField("grid_ID") && bson.hasField("cluster_data")) { grid_id = bson.getStringField("grid_ID"); std::vector<mongo::BSONElement> c_ele = bson["cluster_data"].Array(); for(int i=0;i<c_ele.size();i++) { mongo::BSONObj obj = c_ele[i].Obj(); DoCluster(grid_id,obj); } } else { grid_id = ""; DoCluster(grid_id,bson); } }
void Processer::DoCluster(const std::string& grid,mongo::BSONObj& cluster) { std::string cluster_id; if(cluster.hasField("cluster_ID") && cluster.hasField("host_data")) { cluster_id = cluster.getStringField("cluster_ID"); std::vector<mongo::BSONElement> h_ele = cluster["host_data"].Array(); for(int i=0;i<h_ele.size();i++) { mongo::BSONObj obj = h_ele[i].Obj(); DoHost(grid,cluster_id,obj); } } else { std::stringstream oss; oss << "This data is illegal! Drop!!"; LOG4CXX_WARN(log_,oss.str()); std::cout << cluster << std::endl; } }
repo::core::RepoNodeCamera::RepoNodeCamera(const mongo::BSONObj &obj) : RepoNodeAbstract(obj) { //-------------------------------------------------------------------------- // Aspect ratio if (obj.hasField(REPO_NODE_LABEL_ASPECT_RATIO)) aspectRatio = (float) obj.getField(REPO_NODE_LABEL_ASPECT_RATIO).numberDouble(); //-------------------------------------------------------------------------- // Far clipping plane if (obj.hasField(REPO_NODE_LABEL_FAR)) farClippingPlane = (float) obj.getField(REPO_NODE_LABEL_FAR).numberDouble(); //-------------------------------------------------------------------------- // Near clipping plane if (obj.hasField(REPO_NODE_LABEL_NEAR)) nearClippingPlane = (float) obj.getField(REPO_NODE_LABEL_NEAR).numberDouble(); //-------------------------------------------------------------------------- // Field of view if (obj.hasField(REPO_NODE_LABEL_FOV)) fieldOfView = (float) obj.getField(REPO_NODE_LABEL_FOV).numberDouble(); //-------------------------------------------------------------------------- // Look at vector if (obj.hasField(REPO_NODE_LABEL_LOOK_AT)) lookAt = RepoTranscoderBSON::retrieveVector3D( obj.getField(REPO_NODE_LABEL_LOOK_AT)); //-------------------------------------------------------------------------- // Position vector if (obj.hasField(REPO_NODE_LABEL_POSITION)) position = RepoTranscoderBSON::retrieveVector3D( obj.getField(REPO_NODE_LABEL_POSITION)); //-------------------------------------------------------------------------- // Up vector if (obj.hasField(REPO_NODE_LABEL_UP)) up = RepoTranscoderBSON::retrieveVector3D( obj.getField(REPO_NODE_LABEL_UP)); }
/* **************************************************************************** * * ContextElementResponse::ContextElementResponse - * * This constructor builds the CER object based in a BSON object taken from the * entities collection at DB. * * Note that statusCode is not touched by this constructor. */ ContextElementResponse::ContextElementResponse ( const mongo::BSONObj& entityDoc, const AttributeList& attrL, bool includeEmpty, const std::string& apiVersion ) { prune = false; // Entity BSONObj id = getFieldF(entityDoc, "_id").embeddedObject(); std::string entityId = getStringFieldF(id, ENT_ENTITY_ID); std::string entityType = id.hasField(ENT_ENTITY_TYPE) ? getStringFieldF(id, ENT_ENTITY_TYPE) : ""; contextElement.entityId.fill(entityId, entityType, "false"); contextElement.entityId.servicePath = id.hasField(ENT_SERVICE_PATH) ? getStringFieldF(id, ENT_SERVICE_PATH) : ""; /* Get the location attribute (if it exists) */ std::string locAttr; if (entityDoc.hasElement(ENT_LOCATION)) { locAttr = getStringFieldF(getObjectFieldF(entityDoc, ENT_LOCATION), ENT_LOCATION_ATTRNAME); } // // Attribute vector // FIXME P5: constructor for BSONObj could be added to ContextAttributeVector/ContextAttribute classes, to make building more modular // BSONObj attrs = getObjectFieldF(entityDoc, ENT_ATTRS); std::set<std::string> attrNames; attrs.getFieldNames(attrNames); for (std::set<std::string>::iterator i = attrNames.begin(); i != attrNames.end(); ++i) { std::string attrName = *i; BSONObj attr = getObjectFieldF(attrs, attrName); ContextAttribute* caP = NULL; ContextAttribute ca; // Name and type ca.name = dbDotDecode(basePart(attrName)); std::string mdId = idPart(attrName); ca.type = getStringFieldF(attr, ENT_ATTRS_TYPE); // Skip attribute if the attribute is in the list (or attrL is empty or includes "*") if (!includedAttribute(ca, attrL)) { continue; } /* It could happen (although very rarely) that the value field is missing in the * DB for the attribute. The following is a safety check measure to protect against that */ if (!attr.hasField(ENT_ATTRS_VALUE)) { caP = new ContextAttribute(ca.name, ca.type, ""); } else { switch(getFieldF(attr, ENT_ATTRS_VALUE).type()) { case String: ca.stringValue = getStringFieldF(attr, ENT_ATTRS_VALUE); if (!includeEmpty && ca.stringValue.length() == 0) { continue; } caP = new ContextAttribute(ca.name, ca.type, ca.stringValue); break; case NumberDouble: ca.numberValue = getNumberFieldF(attr, ENT_ATTRS_VALUE); caP = new ContextAttribute(ca.name, ca.type, ca.numberValue); break; case NumberInt: ca.numberValue = (double) getIntFieldF(attr, ENT_ATTRS_VALUE); caP = new ContextAttribute(ca.name, ca.type, ca.numberValue); break; case Bool: ca.boolValue = getBoolFieldF(attr, ENT_ATTRS_VALUE); caP = new ContextAttribute(ca.name, ca.type, ca.boolValue); break; case jstNULL: caP = new ContextAttribute(ca.name, ca.type, ""); caP->valueType = orion::ValueTypeNone; break; case Object: caP = new ContextAttribute(ca.name, ca.type, ""); caP->compoundValueP = new orion::CompoundValueNode(orion::ValueTypeObject); caP->valueType = orion::ValueTypeObject; compoundObjectResponse(caP->compoundValueP, getFieldF(attr, ENT_ATTRS_VALUE)); break; case Array: caP = new ContextAttribute(ca.name, ca.type, ""); caP->compoundValueP = new orion::CompoundValueNode(orion::ValueTypeVector); // FIXME P7: next line is counterintuitive. If the object is a vector, why // we need to use ValueTypeObject here? Because otherwise Metadata::toJson() // method doesn't work. A littely crazy... it should be fixed. caP->valueType = orion::ValueTypeObject; compoundVectorResponse(caP->compoundValueP, getFieldF(attr, ENT_ATTRS_VALUE)); break; default: LM_E(("Runtime Error (unknown attribute value type in DB: %d)", getFieldF(attr, ENT_ATTRS_VALUE).type())); } } /* Setting ID (if found) */ if (mdId != "") { Metadata* md = new Metadata(NGSI_MD_ID, "string", mdId); caP->metadataVector.push_back(md); } if (apiVersion == "v1") { /* Setting location metadata (if found) */ if ((locAttr == ca.name) && (ca.type != GEO_POINT)) { /* Note that if attribute type is geo:point then the user is using the "new way" * of locating entities in NGSIv1, thus location metadata is not rendered */ Metadata* md = new Metadata(NGSI_MD_LOCATION, "string", LOCATION_WGS84); caP->metadataVector.push_back(md); } } /* Setting custom metadata (if any) */ if (attr.hasField(ENT_ATTRS_MD)) { BSONObj mds = getObjectFieldF(attr, ENT_ATTRS_MD); std::set<std::string> mdsSet; mds.getFieldNames(mdsSet); for (std::set<std::string>::iterator i = mdsSet.begin(); i != mdsSet.end(); ++i) { std::string currentMd = *i; Metadata* md = new Metadata(dbDotDecode(currentMd), getObjectFieldF(mds, currentMd)); caP->metadataVector.push_back(md); } } /* Set creDate and modDate at attribute level */ if (attr.hasField(ENT_ATTRS_CREATION_DATE)) { caP->creDate = (double) getIntOrLongFieldAsLongF(attr, ENT_ATTRS_CREATION_DATE); } if (attr.hasField(ENT_ATTRS_MODIFICATION_DATE)) { caP->modDate = (double) getIntOrLongFieldAsLongF(attr, ENT_ATTRS_MODIFICATION_DATE); } contextElement.contextAttributeVector.push_back(caP); } /* Set creDate and modDate at entity level */ if (entityDoc.hasField(ENT_CREATION_DATE)) { contextElement.entityId.creDate = (double) getIntOrLongFieldAsLongF(entityDoc, ENT_CREATION_DATE); } if (entityDoc.hasField(ENT_MODIFICATION_DATE)) { contextElement.entityId.modDate = (double) getIntOrLongFieldAsLongF(entityDoc, ENT_MODIFICATION_DATE); } }
void CRackController::UpdateRackPDU(const mongo::BSONObj &boOldCIInfo, const mongo::BSONObj &boNewCIInfo, const mongo::BSONObj &boChangedFields) { CRackPDUModel objPDUModel; CRackModel objRackModel; BSONObj boRackPDUInfo; BSONObj boPushPDU; BSONObj boPullPDU; string strOldRack, strOldSite, strNewRack, strNewSite; string strOldName, strOldPMM; Query qCond; try { if (boChangedFields.hasField("rack") || boChangedFields.hasField("site") || boChangedFields.hasField("current") || boChangedFields.hasField("pmm") || boChangedFields.hasField("unit") || boChangedFields.hasField("name")) { strOldRack = CMongodbModel::GetStringFieldValue(boOldCIInfo, "rack", ""); strOldSite = CMongodbModel::GetStringFieldValue(boOldCIInfo, "site", ""); strOldName = CMongodbModel::GetStringFieldValue(boOldCIInfo, "name", ""); strOldPMM = CMongodbModel::GetStringFieldValue(boOldCIInfo, "pmm", ""); strNewRack = CMongodbModel::GetStringFieldValue(boNewCIInfo, "rack", ""); strNewSite = CMongodbModel::GetStringFieldValue(boNewCIInfo, "site", ""); // Load PDU info into CRackPDUModel objPDUModel.Load(boNewCIInfo); objPDUModel.Save(boRackPDUInfo); if (strOldRack != "" && strOldSite != "") { boPullPDU = objRackModel.GetDeletePDURecord(strOldName, strOldPMM); qCond = objRackModel.IsExistsRackQuery(strOldRack, strOldSite); cout << "query:" << qCond.toString() << endl; cout << "pull:" << boPullPDU.toString() << endl; //Pull old Switch serial in rack Update(boPullPDU, qCond); } if (strNewRack != "" && strNewRack != "") { boPushPDU = objRackModel.GetAddPDURecord(boRackPDUInfo); qCond = objRackModel.IsExistsRackQuery(strNewRack, strNewSite); cout << "query:" << qCond.toString() << endl; cout << "push:" << boPushPDU.toString() << endl; Update(boPushPDU, qCond); } } } catch(exception& ex) { stringstream strErrorMess; string strLog; strErrorMess << ex.what() << "][" << __FILE__ << "|" << __LINE__ ; strLog = CUtilities::FormatLog(ERROR_MSG, "CRackController", "UpdateRackPDU","Exception:" + strErrorMess.str()); CUtilities::WriteErrorLog(ERROR_MSG, strLog); } }
repo::core::RepoNodeMesh::RepoNodeMesh( const mongo::BSONObj &obj) : RepoNodeAbstract(obj), vertices(NULL), faces(NULL), normals(NULL), outline(NULL), uvChannels(NULL), colors(NULL) { //-------------------------------------------------------------------------- // Vertices if (obj.hasField(REPO_NODE_LABEL_VERTICES) && obj.hasField(REPO_NODE_LABEL_VERTICES_COUNT)) { vertices = new std::vector<aiVector3t<float>>(); RepoTranscoderBSON::retrieve( obj.getField(REPO_NODE_LABEL_VERTICES), obj.getField(REPO_NODE_LABEL_VERTICES_COUNT).numberInt(), vertices); } //-------------------------------------------------------------------------- // Faces if (obj.hasField(REPO_NODE_LABEL_FACES) && obj.hasField(REPO_NODE_LABEL_FACES_COUNT) && obj.hasField(REPO_NODE_LABEL_FACES_BYTE_COUNT)) { faces = new std::vector<aiFace>(); retrieveFacesArray( obj.getField(REPO_NODE_LABEL_FACES), api, obj.getField(REPO_NODE_LABEL_FACES_BYTE_COUNT).numberInt(), obj.getField(REPO_NODE_LABEL_FACES_COUNT).numberInt(), faces); } //-------------------------------------------------------------------------- // Normals if (obj.hasField(REPO_NODE_LABEL_NORMALS) && obj.hasField(REPO_NODE_LABEL_VERTICES_COUNT)) { normals = new std::vector<aiVector3t<float> >(); RepoTranscoderBSON::retrieve( obj.getField(REPO_NODE_LABEL_NORMALS), obj.getField(REPO_NODE_LABEL_VERTICES_COUNT).numberInt(), normals); } //-------------------------------------------------------------------------- // Polygon mesh outline (2D bounding rectangle in XY for the moment) // if (obj.hasField(REPO_NODE_LABEL_OUTLINE)) { //outline = new std::vector<aiVector2D>(); // TODO: fill in } //-------------------------------------------------------------------------- // Bounding box if (obj.hasField(REPO_NODE_LABEL_BOUNDING_BOX)) { std::pair<aiVector3D, aiVector3D> min_max = RepoTranscoderBSON::retrieveBBox( obj.getField(REPO_NODE_LABEL_BOUNDING_BOX)); this->boundingBox.setMin(min_max.first); this->boundingBox.setMax(min_max.second); } //-------------------------------------------------------------------------- // SHA-256 hash if (obj.hasField(REPO_NODE_LABEL_SHA256)) { vertexHash = obj.getField(REPO_NODE_LABEL_SHA256).numberInt(); } //-------------------------------------------------------------------------- // UV channels if (obj.hasField(REPO_NODE_LABEL_UV_CHANNELS) && obj.hasField(REPO_NODE_LABEL_UV_CHANNELS_BYTE_COUNT) && obj.hasField(REPO_NODE_LABEL_UV_CHANNELS_COUNT)) { unsigned int numberOfConcatenatedEntries = obj.getField(REPO_NODE_LABEL_UV_CHANNELS_COUNT).numberInt() * obj.getField(REPO_NODE_LABEL_VERTICES_COUNT).numberInt(); std::vector<aiVector2t<float>> concatenated; RepoTranscoderBSON::retrieve( obj.getField(REPO_NODE_LABEL_UV_CHANNELS), numberOfConcatenatedEntries, &concatenated); unsigned int channelsCount = obj.getField(REPO_NODE_LABEL_UV_CHANNELS_COUNT).numberInt(); unsigned int channelSize = (unsigned int) concatenated.size()/channelsCount; uvChannels = new std::vector<std::vector<aiVector3t<float>> *>(channelsCount); // For every uv channel present (usually only one) for (unsigned int i = 0; i < channelsCount; ++i) { uvChannels->at(i) = new std::vector<aiVector3t<float>>(); uvChannels->at(i)->reserve(channelSize); // Copy over all per vertex UV values for (unsigned int j = 0; j < channelSize; ++j) { aiVector2t<float> uv = concatenated[(i * channelSize) + j]; uvChannels->at(i)->push_back(aiVector3t<float>(uv.x, uv.y, 0)); } } } }