Exemplo n.º 1
0
Aws::S3::Model::GetObjectOutcomeCallable s3be::get_one(const libbruce::nodeid_t &id)
{
    GetObjectRequest request;
    request.SetBucket(m_bucket);
    request.SetKey(m_prefix + boost::lexical_cast<std::string>(id));

    return m_s3->GetObjectCallable(request);
}
Exemplo n.º 2
0
int main() {
	SDKOptions options;
	options.loggingOptions.logLevel = Aws::Utils::Logging::LogLevel::Info;
	Aws::InitAPI(options);

	ClientConfiguration conf = ClientConfiguration();
	conf.endpointOverride = "IPADDRESS";
	conf.verifySSL = false;
	AWSCredentials creds = AWSCredentials("ACCESS_KEY_ID", "ACCESS_KEY_SECRET");

    S3Client client = S3Client(creds, conf);

	// Put an object
	PutObjectRequest putObjectRequest;
	putObjectRequest.WithKey(KEY).WithBucket(BUCKET).WithContentEncoding("text");

	auto requestStream = Aws::MakeShared<Aws::StringStream>("s3-sample");
	*requestStream << CONTENT;
	putObjectRequest.SetBody(requestStream);
	auto putObjectOutcome = client.PutObject(putObjectRequest);
	if(putObjectOutcome.IsSuccess()) {
		std::cout << "Putting to '" << BUCKET << "/" << KEY << "' succeeded" << std::endl;
	} else {
		std::cout << "Error while putting Object " << putObjectOutcome.GetError().GetExceptionName() << 
			" " << putObjectOutcome.GetError().GetMessage() << std::endl;
		return 1;
	}

	// Retrieve the object
	GetObjectRequest getObjectRequest;
	getObjectRequest = getObjectRequest.WithBucket(BUCKET).WithKey(KEY);
	auto getObjectOutcome = client.GetObject(getObjectRequest);
	if(getObjectOutcome.IsSuccess()) {
		Aws::StringStream contents;
		contents << getObjectOutcome.GetResult().GetBody().rdbuf();

		std::cout << "Successfully retrieved '" << BUCKET << "/" << KEY << "' ";
		std::cout << "with contents: '" << contents.str() << "'" << std::endl;
		if (contents.str().compare(CONTENT) != 0 ){
			std::cout << "Retrieved content is not as expected" << std::endl;
			return 1;
		} else {
			std::cout << "Retrieved content is as expected" << std::endl;
		}
	} else {
		std::cout << "Error while getting object " << getObjectOutcome.GetError().GetExceptionName() <<
			" " << getObjectOutcome.GetError().GetMessage() << std::endl;
		return 1;
	}

	return 0;
}
Exemplo n.º 3
0
mempage s3be::get(const nodeid_t &id)
{
    //std::cerr << "GET " << id << std::endl;

    // Look in the cache
    {
        mempage ret;
        if (m_cache.get(id, &ret))
            return ret;
    }

    GetObjectRequest request;
    request.SetBucket(m_bucket);
    request.SetKey(m_prefix + boost::lexical_cast<std::string>(id));

    GetObjectOutcome response = m_s3->GetObject(request);
    return readGetOutcome(id, response);
}
bool ossim::S3StreamBuffer::loadBlock(ossim_int64 absolutePosition)
{
   bool result = false;
   m_bufferPtr = 0;
   GetObjectRequest getObjectRequest;
   std::stringstream stringStream;
   ossim_int64 startRange, endRange;
   ossim_int64 blockIndex = getBlockIndex(absolutePosition);
   if((absolutePosition < 0) || (absolutePosition > (ossim_int64)m_fileSize)) return false;
   //std::cout << "CURRENT BYTE LOCATION = " << absoluteLocation << std::endl;
   if(getBlockRangeInBytes(blockIndex, startRange, endRange))
   {
      stringStream << "bytes=" << startRange << "-" << endRange;
      getObjectRequest.WithBucket(m_bucket.c_str())
         .WithKey(m_key.c_str()).WithRange(stringStream.str().c_str());
      auto getObjectOutcome = m_client.GetObject(getObjectRequest);

      if(getObjectOutcome.IsSuccess())
      {
//        std::cout << "GOOD CALL!!!!!!!!!!!!\n";
         Aws::IOStream& bodyStream = getObjectOutcome.GetResult().GetBody();
         ossim_int64 bufSize = getObjectOutcome.GetResult().GetContentLength();
//        std::cout << "SIZE OF RESULT ======== " << bufSize << std::endl;
         m_bufferActualDataSize = bufSize;
         bodyStream.read(&m_buffer.front(), bufSize);
         m_bufferPtr = &m_buffer.front();

         ossim_int64 delta = absolutePosition-startRange;
         setg(m_bufferPtr, m_bufferPtr + delta, m_bufferPtr+m_bufferActualDataSize);
         m_currentBlockPosition = startRange;
         result = true;
         //std::cout << "Successfully retrieved object from s3 with value: " << std::endl;
         //std::cout << getObjectOutcome.GetResult().GetBody().rdbuf() << std::endl << std::endl;;  
      }
      else
      {
         m_bufferActualDataSize = 0;
      }
   }

   return result;
}
Exemplo n.º 5
0
bool GetObjectRequestSerializer::WriteObject(std::string& serializedData, GetObjectRequest& objectGraph)
{
  tinyxml2::XMLElement* rootElement = PrepareXmlDocumentForObjectSerialization("object_requester"); 

  rootElement->InsertEndChild(Util::CreateXmlElementWithText(&GetXmlDocument(), "object_id", objectGraph.GetObjectID()));

  if ( objectGraph.ObjectType != OBJECT_TYPE_UNKNOWN)
  {
	  rootElement->InsertEndChild(Util::CreateXmlElementWithText(&GetXmlDocument(), "object_type", objectGraph.ObjectType));
  }
  if (objectGraph.ItemType != ITEM_TYPE_UNKNOWN)
  {
	  rootElement->InsertEndChild(Util::CreateXmlElementWithText(&GetXmlDocument(), "item_type", objectGraph.ItemType));
  }
  if (objectGraph.StartPosition != 0)
  {
	  rootElement->InsertEndChild(Util::CreateXmlElementWithText(&GetXmlDocument(), "start_position", objectGraph.StartPosition));
  }
  if ( objectGraph.RequestCount != -1)
  {
	  rootElement->InsertEndChild(Util::CreateXmlElementWithText(&GetXmlDocument(), "requested_count", objectGraph.RequestCount));
  }

  if (objectGraph.ChildrenRequest)
  {
	  rootElement->InsertEndChild(Util::CreateXmlElementWithText(&GetXmlDocument(), "children_request", objectGraph.ChildrenRequest));

  }
rootElement->InsertEndChild(Util::CreateXmlElementWithText(&GetXmlDocument(), "server_address", objectGraph.GetServerAddress()));
  tinyxml2::XMLPrinter* printer = new tinyxml2::XMLPrinter();    
  GetXmlDocument().Accept(printer);
  serializedData = std::string(printer->CStr());
  
  return true;
}