예제 #1
0
/*
 * Copy a file from the local filesystem to Sector.
 *
 * src is the path to the local file.
 * dest is the path to the new Sector file.
 *
 * Returns: on success a non-negative value. A negative value on failure.
 */
static PyObject* upload( PyObject* self, PyObject* args )
{
    SectorFile f;

    const char* src;
    const char* dest;
    
    if( !PyArg_ParseTuple( args, "ss", &src, &dest ) ) {
        return( NULL );
    }

    int status = f.open( dest, SF_MODE::WRITE );
    if( status < 0 ) {
        PyErr_SetString( PyExc_IOError, "failed to open destination, status=" +
                         status );
        return( NULL );
    }

    status = f.upload( src, false );
    if( status < 0 ) {
        PyErr_SetString( PyExc_IOError, "upload failed, status=" + status );
    }
    
    f.close();

    return( Py_BuildValue( "i", status ) );
}
예제 #2
0
  int job_service::upload ( std::string const &dir, std::vector<std::string> &files ) 
  {
     
      int rc = saga_sectorsphere::error::SAGA_SECSP_E_SUCCESS ; 

      SNode attr ; 
      rc = Sector::stat( dir, attr ) ; 
      if( rc < saga_sectorsphere::error::SAGA_SECSP_E_SUCCESS || !attr.m_bIsDir ) {
        if( rc = Sector::mkdir( dir ) < saga_sectorsphere::error::SAGA_SECSP_E_SUCCESS ) {
	   return rc ; 
	}
      }
      
      std::string to_create ; 
      std::string to_upload ; 
      to_create = dir ; 

      size_t pos = dir.rfind("/") ; 
      if( pos == std::string::npos ){
         to_create = dir ; 
      }
      else if( pos == to_create.size()) {
         size_t p = to_create.find_last_of( "/", to_create.size() - 1 ) ; 
	 if ( p != std::string::npos ) {
            to_create = dir.substr( p, dir.size() - 1 ) ; 
	 }
      }
      else{
	 to_create = dir.substr( pos + 1, std::string::npos ) ; 
      }

      to_upload = dir ; 

      for( std::vector<std::string>::iterator it = files.begin() ; it !=files.end()  ; ++it ){
      
         SectorFile f ;

	 std::string cr = to_create ; 
	 cr += "/" ; 
	 cr += *it ; 

	 std::string up = to_upload ; 
	 up += "/" ; 
	 up += *it ; 

         rc = f.open( cr, SF_MODE::WRITE ) ; 
         if( rc < saga_sectorsphere::error::SAGA_SECSP_E_SUCCESS ) {
            return rc ; 
         }
      
         if( rc = f.upload( up.c_str() ) < saga_sectorsphere::error::SAGA_SECSP_E_SUCCESS ){
	    return rc ; 
	 }

	 input_fileset.push_back( cr ) ; 
	 f.close() ; 
      }

      return rc ; 
  }
예제 #3
0
파일: upload.cpp 프로젝트: norouzi4d/sector
int upload(const char* file, const char* dst, Sector& client)
{
   CTimer timer;
   uint64_t t1 = timer.getTime();  // returns time in microseconds (usecs)

   struct stat s;
   stat(file, &s);
   cout << "uploading " << file << " of " << s.st_size << " bytes" << endl;

   SectorFile* f = client.createSectorFile();

   if (f->open(dst, SF_MODE::WRITE) < 0)
   {
      cout << "ERROR: unable to connect to server or file already exists." << endl;
      return -1;
   }

   bool finish = true;
   if (f->upload(file) < 0LL)
      finish = false;

   f->close();
   client.releaseSectorFile(f);

   if (finish)
   {
      float throughput = s.st_size * 8.0f / 1000000.0f / ((timer.getTime() - t1) / 1000000.0f);

      cout << "Uploading accomplished! " << "AVG speed " << throughput << " Mb/s." << endl << endl ;
   }
   else
      cout << "Uploading failed! Please retry. " << endl << endl;

   return 1;
}
예제 #4
0
int upload(const char* file, const char* dst, Sector& client)
{
   timeval t1, t2;
   gettimeofday(&t1, 0);

   struct stat64 s;
   stat64(file, &s);
   cout << "uploading " << file << " of " << s.st_size << " bytes" << endl;

   SectorFile* f = client.createSectorFile();

   if (f->open(dst, SF_MODE::WRITE) < 0)
   {
      cout << "ERROR: unable to connect to server or file already exists." << endl;
      return -1;
   }

   bool finish = true;
   if (f->upload(file) < 0LL)
      finish = false;

   f->close();
   client.releaseSectorFile(f);

   if (finish)
   {
      gettimeofday(&t2, 0);
      float throughput = s.st_size * 8.0 / 1000000.0 / ((t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) / 1000000.0);

      cout << "Uploading accomplished! " << "AVG speed " << throughput << " Mb/s." << endl << endl ;
   }
   else
      cout << "Uploading failed! Please retry. " << endl << endl;

   return 1;
}
예제 #5
0
int upload(const char* file, const char* dst, Sector& client, const int rep_num, const string& ip, const string& cid, const bool secure, const bool smart)
{
   //check if file already exists

   SNode s;
   if (LocalFS::stat(file, s) < 0)
   {
      cout << "cannot locate source file " << file << endl;
      return -1;
   }

   SNode attr;
   if (client.stat(dst, attr) >= 0)
   {
      if (attr.m_llSize == s.m_llSize && smart)
      {
         cout << "destination file " << dst << " exists on Sector FS. skip.\n";
         return 0;
      }
   }

   cout << "uploading " << file << " of " << s.m_llSize << " bytes" << endl;

   timeval t1, t2;
   gettimeofday(&t1, 0);

   SectorFile* f = client.createSectorFile();

   SF_OPT option;
   option.m_llReservedSize = s.m_llSize;
   if (option.m_llReservedSize <= 0)
      option.m_llReservedSize = 1;
   option.m_iReplicaNum = rep_num;
   option.m_strHintIP = ip;
   option.m_strCluster = cid;

   int mode = SF_MODE::WRITE | SF_MODE::TRUNC;
   if (secure)
      mode |= SF_MODE::SECURE;

   int r = f->open(dst, mode, &option);
   if (r < 0)
   {
      cerr << "unable to open file " << dst << endl;
      Utility::print_error(r);
      return -1;
   }

   int64_t result = f->upload(file);

   f->close();
   client.releaseSectorFile(f);

   if (result >= 0)
   {
      gettimeofday(&t2, 0);
      float throughput = s.m_llSize * 8.0 / 1000000.0 / ((t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) / 1000000.0);

      cout << "Uploading accomplished! " << "AVG speed " << throughput << " Mb/s." << endl << endl ;
   }
   else
   {
      cout << "Uploading failed! Please retry. " << endl << endl;
      Utility::print_error(result);
      return result;
   }

   return 0;
}
예제 #6
0
파일: upload.cpp 프로젝트: norouzi4d/sector
int upload(const char* file, const char* dst, Sector& client)
{
   //check if file already exists

   struct stat st;
   if (stat(file, &st) < 0)
   {
      cout << "cannot locate source file " << file << endl;
      return -1;
   }

   SNode attr;
   if (client.stat(dst, attr) >= 0)
   {
      if (attr.m_llSize == st.st_size)
      {
         cout << "destination file " << dst << " exists on Sector FS. skip.\n";
         return 0;
      }
   }

   CTimer timer;
   uint64_t t1 = timer.getTime();  // returns time in microseconds (usecs)

   struct stat s;
   stat(file, &s);
   cout << "uploading " << file << " of " << s.st_size << " bytes" << endl;

   SectorFile* f = client.createSectorFile();

   int64_t reserve = s.st_size;
   if (reserve <= 0)
      reserve = 1;

   int r = f->open(dst, SF_MODE::WRITE, "", reserve);
   if (r < 0)
   {
      cerr << "unable to open file " << dst << endl;
      Utility::print_error(r);
      return -1;
   }

   int64_t result = f->upload(file);

   f->close();
   client.releaseSectorFile(f);

   if (result >= 0)
   {
      float throughput = s.st_size * 8.0f / 1000000.0f / ((timer.getTime() - t1) / 1000000.0f);

      cout << "Uploading accomplished! " << "AVG speed " << throughput << " Mb/s." << endl << endl ;
   }
   else
   {
      cout << "Uploading failed! Please retry. " << endl << endl;
      Utility::print_error(result);
      return -1;
   }

   return 0;
}