示例#1
0
文件: sdb.cpp 项目: uberlabs/libaws
bool listAll(SDBConnectionPtr aSDB){
  try {
    ListDomainsResponsePtr lRes = aSDB->listDomains();
    std::cout << "list domains successfully" << std::endl;
    lRes->open();
    std::string lDomain;
    while (lRes->next (lDomain)) {
      std::cout << "  Domain: " << lDomain  << std::endl;
      SDBQueryResponsePtr lRes = aSDB->query (lDomain, "");
      int lCounter = 0;
      lRes->open();
      std::string lItem;
      while (lRes->next (lItem)) {
        std::cout << "    " << ++lCounter << ". Item: " << lItem;
        GetAttributesResponsePtr lRes = aSDB->getAttributes (lDomain, lItem);
        lRes->open();
        std::pair<std::string, std::string> lAttr;
        while (lRes->next (lAttr)) {
          std::cout << " " << lAttr.first << ":" <<  lAttr.second ;
        }
        lRes->close();
        std::cout << std::endl;
      }
      lRes->close();
    }
    lRes->close();
  } catch (ListDomainsException &e) {
    std::cerr << e.what() << std::endl;
    return false;
  }
  return true;
  
}
示例#2
0
int sdbtest(int argc, char* argv[]) {
    AWSConnectionFactory* lFactory = AWSConnectionFactory::getInstance();

    std::cout << "Testing libaws version " << lFactory->getVersion() << std::endl;

    char* lAccessKeyId = getenv("AWS_ACCESS_KEY");
    char* lSecretAccessKey = getenv("AWS_SECRET_ACCESS_KEY");
    if (lAccessKeyId == 0 || lSecretAccessKey == 0) {
        std::cerr
                << "Environment variables (i.e. AWS_ACCESS_KEY or AWS_SECRET_ACCESS_KEY) not set"
                << std::endl;
        return 1;
    }

    SDBConnectionPtr lConSmart = lFactory->createSDBConnection(lAccessKeyId,
                                 lSecretAccessKey);
    SDBConnection* lCon = lConSmart.get();

    try {
        if (createDomain(lCon) != 0) {
            return 1;
        }
        if (listDomains(lCon) != 0) {
            return 1;
        }
        if (putAttributes(lCon) != 0) {
            return 1;
        }
        if (getAttributes(lCon) != 0) {
            return 1;
        }
        if (deleteAttributes(lCon) != 0) {
            return 1;
        }
        if (getAttributes(lCon) != 0) {
            return 1;
        }
        if (query(lCon) != 0) {
            return 1;
        }
        if (queryWithAttributes(lCon) != 0) {
            return 1;
        }
        if (deleteDomain(lCon) != 0) {
            return 1;
        }
    }
    catch (AWSConnectionException& e) {
        std::cerr << e.what() << std::endl;
        return 2;
    }

    lFactory->shutdown();

    return 0;
}
示例#3
0
文件: sdb.cpp 项目: uberlabs/libaws
bool deleteAllDomains (SDBConnectionPtr aSDB, std::string aPrefix) {
  try {
      ListDomainsResponsePtr lRes = aSDB->listDomains();
      std::cout << "start deleting" << std::endl;
      lRes->open();
      std::string lDomain;
      while (lRes->next (lDomain)) {
        if(aPrefix.length() == 0 || lDomain.compare(0, aPrefix.length(),aPrefix) == 0){
            std::cout << "   " << lDomain  << std::endl;
            aSDB->deleteDomain (lDomain);
          }
        }
      lRes->close();
    } catch (PutAttributesException &e) {
      std::cerr << e.what() << std::endl;
      return false;
    }
  return true;
}
示例#4
0
文件: sdb.cpp 项目: uberlabs/libaws
bool deleteDomain (SDBConnectionPtr aSDB, const std::string &aDomainName) {
  try {
      DeleteDomainResponsePtr lRes = aSDB->deleteDomain (aDomainName);
      std::cout << "delete domain successfully" << std::endl;
    } catch (DeleteDomainException &e) {
      std::cerr << e.what() << std::endl;
      return false;
    }
  return true;
}
示例#5
0
int
CVDB::upload(ImageScanner *scanner,
		const int id,
		const std::string& s3prefix)
{
	SDBConnectionPtr sdbconn = sdbconnect();
	// initialize table meta data
	ImageTableMetadata tablemeta(id);
	std::string domain;
	serial_image_table_meta(&tablemeta, IMAGE_TABLE_ITEM_ID, domain);
	std::string imgdomain(domain);
	imgdomain += IMAGE_CATALOG_SUFFIX;
	tablemeta.bucket = CVDB::BUCKET;
	tablemeta.prefix = s3prefix;
	tablemeta.imagedomain = imgdomain;
	tablemeta.nextimageid = 1;

	std::cout << "Creating: " << imgdomain << std::endl;
	CreateDomainResponsePtr res = sdbconn->createDomain(imgdomain);

	// initialize all image meta data
	scanner->open();
	ImageMetadata meta;
	meta.imagetable = &tablemeta;
	while (scanner->next(meta)) {
		meta.id = tablemeta.nextimageid;
		tablemeta.nextimageid++;
		std::cout << "Uploading image: " << meta.id << ", " << meta.name
				<< ", " << meta.subjectid << ", " << meta.poseid << ", "
				<< meta.format << ", " << meta.dimensions.width << ", "
				<< meta.dimensions.height << ", " << meta.dimensions.depth
				<< std::endl;
		upload_image_meta(sdbconn, &meta);
	}
	scanner->close();

	std::cout << "Uploading table: " << tablemeta.id << ", "
			<< tablemeta.bucket << ", " << tablemeta.prefix << ", "
			<< tablemeta.nextimageid << std::endl;
	upload_image_table_meta(sdbconn, &tablemeta);

	return EXIT_SUCCESS;
}
示例#6
0
文件: sdb.cpp 项目: uberlabs/libaws
bool deleteAttribute (SDBConnectionPtr aSDB, const std::string& aDomainName, const std::string& aItemName,
                      const std::string& aKey, std::string aValue) {
  try {
      std::vector<aws::Attribute> lAttrs;
      aws::Attribute lAttr (aKey, aValue, false);
      lAttrs.push_back (lAttr);
      DeleteAttributesResponsePtr lRes = aSDB->deleteAttributes (aDomainName, aItemName, lAttrs);
      std::cout << "delete attribute successfully" << std::endl;
    } catch (PutAttributesException &e) {
      std::cerr << e.what()  << std::endl;
      return false;
    }
  return true;
}
示例#7
0
static void
load_image_table_meta(SDBConnectionPtr sdbconn, ImageTableMetadata *meta)
{
	std::string value;
	serial_image_table_meta(meta, IMAGE_TABLE_ITEM_ID, value);
    GetAttributesResponsePtr res = sdbconn->getAttributes(CVDB::CATALOG,
    		value, "");
    res->open();
    AttributePair attr;
    while (res->next(attr)) {
    	deserial_image_table_meta(meta, attr.first.c_str(), attr.second);
    }
    res->close();
}
示例#8
0
文件: sdb.cpp 项目: uberlabs/libaws
bool listDomains (SDBConnectionPtr aSDB, int aMaxNumberOfDomains, const std::string& aNextToken) {
  try {
    ListDomainsResponsePtr lRes = aSDB->listDomains(aMaxNumberOfDomains, aNextToken);
      std::cout << "list domains successfully" << std::endl;
      lRes->open();
      std::string lDomain;
      while (lRes->next (lDomain)) {
          std::cout << "   Domain: " << lDomain  << std::endl;
        }
      lRes->close();
    } catch (ListDomainsException &e) {
      std::cerr << e.what() << std::endl;
      return false;
    }
  return true;
}
示例#9
0
文件: sdb.cpp 项目: uberlabs/libaws
bool domainMetadata (SDBConnectionPtr aSDB, const std::string &aDomainName) {
  try {
      DomainMetadataResponsePtr lRes = aSDB->domainMetadata (aDomainName);
      std::cout << "domain metadata retrieved successfully" << std::endl;
      std::cout << "  ItemCount " << lRes->getItemCount() << std::endl;
      std::cout << "  ItemNamesSizeBytes " << lRes->getItemNamesSizeBytes() << std::endl;
      std::cout << "  AttributeNameCount  " << lRes->getAttributeNameCount() << std::endl;
      std::cout << "  AttributeNamesSizeBytes " << lRes->getAttributeNamesSizeBytes() << std::endl;
      std::cout << "  AttributeValueCount " << lRes->getAttributeValueCount() << std::endl;
      std::cout << "  AttributeValuesSizeBytes " << lRes->getAttributeValuesSizeBytes() << std::endl;
      std::cout << "  Timestamp " << lRes->getTimestamp() << std::endl;
    } catch (DomainMetadataException &e) {
      std::cerr << e.what() << std::endl;
      return false;
    }
  return true;
}
示例#10
0
文件: sdb.cpp 项目: uberlabs/libaws
bool query (SDBConnectionPtr aSDB, const std::string& aDomainName, const std::string& aQueryExpression, int aMaxNumberOfItems = 0,
            const std::string & aNextToken = "") {
  try {
    SDBQueryResponsePtr lRes = aSDB->query (aDomainName, aQueryExpression, aMaxNumberOfItems, aNextToken);
    std::cout << "query successfully" << std::endl;
    lRes->open();
    std::string lItem;
    while (lRes->next (lItem)) {
        std::cout << "   Item: " << lItem << std::endl;
    }
    lRes->close();
  } catch (PutAttributesException &e) {
    std::cerr << e.what() << std::endl;
    return false;
  }
  return true;
}
示例#11
0
文件: sdb.cpp 项目: uberlabs/libaws
bool getAttribute (SDBConnectionPtr aSDB, const std::string& aDomainName, const std::string& aItemName,
                   const std::string attributeName = "") {
  try {
      GetAttributesResponsePtr lRes = aSDB->getAttributes (aDomainName, aItemName, attributeName);
      std::cout << "get attribute successfully" << std::endl;
      lRes->open();
      std::pair<std::string, std::string> lAttr;
      while (lRes->next (lAttr)) {
          std::cout << "   Attr-Name: " << lAttr.first << "-> " <<  lAttr.second  << std::endl;
        }
      lRes->close();
    } catch (PutAttributesException &e) {
      std::cerr << e.what() << std::endl;
      return false;
    }
  return true;
}
示例#12
0
static void
upload_image_meta(SDBConnectionPtr sdbconn, ImageMetadata *meta, const char **attrs)
{
	assert(meta->imagetable != NULL);
	if (attrs == NULL) {
		attrs = IMAGE_ATTRS;
	}
	const char **attr = attrs;
    std::vector<Attribute> awsattrs;
	while (*attr != NULL) {
		std::string key(*attr);
		std::string value;
		serial_image_meta(meta, *attr, value);
	    Attribute awsattr(key, value, true);
	    awsattrs.push_back (awsattr);
		attr++;
	}
	std::string item;
	serial_image_meta(meta, IMAGE_ITEM_ID, item);
	    PutAttributesResponsePtr res = sdbconn->putAttributes(meta->imagetable->imagedomain,
	item, awsattrs);
}
示例#13
0
static void
upload_image_table_meta(SDBConnectionPtr sdbconn,
		ImageTableMetadata *meta,
			const char **attrs)
{
	if (attrs == NULL) {
		attrs = IMAGE_TABLE_ATTRS;
	}
	const char **attr = attrs;
    std::vector<Attribute> awsattrs;
	while (*attr != NULL) {
		std::string key(*attr);
		std::string value;
		serial_image_table_meta(meta, *attr, value);
  aws::Attribute awsattr(key, value, true);
	    awsattrs.push_back(awsattr);
		attr++;
	}
	std::string value;
	serial_image_table_meta(meta, IMAGE_TABLE_ITEM_ID, value);
	    PutAttributesResponsePtr res = sdbconn->putAttributes(CVDB::CATALOG,
	value, awsattrs);
}