Ignore:
Timestamp:
Aug 7, 2017, 2:56:24 PM (7 years ago)
Author:
djay
Message:

Update the source code for HPC support. Automatically adding nested outputs for the HPC support (should this be available for every support?). Add capability to store the metadata in the Collection DataBase?. Addition of the zcfg2sql to import any existing ZCFG file into the Collection DB. Add the support to invoke a callback (for history purpose) in case a [callback] section contains at least one parameter defined (url). Add support to convert maps and map to JSON (for callback use only by now). Fix some memory leaks (some are still there).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/prototype-v0/zoo-project/zoo-kernel/sshapi.c

    r822 r839  
    99 * by the French National Research Agency
    1010 *
    11  * permission is hereby granted, free of charge, to any person obtaining a copy
     11 * Permission is hereby granted, free of charge, to any person obtaining a copy
    1212 * of this software and associated documentation files (the "Software"), to deal
    1313 * in the Software without restriction, including without limitation the rights
     
    249249 * @return true in case of success, false if failure occured
    250250 */
    251 size_t ssh_file_exists(maps* conf,const char* targetPath){
     251size_t ssh_file_exists(maps* conf,const char* targetPath,int cnt){
    252252  size_t result=-1;
    253   int cnt=ssh_get_cnt(conf);
    254253  if(cnt>0)
    255254    cnt-=1;
     
    303302 * @return true in case of success, false if failure occured
    304303 */
    305 bool ssh_copy(maps* conf,const char* localPath,const char* targetPath){
     304bool ssh_copy(maps* conf,const char* localPath,const char* targetPath,int cnt){
    306305  char mem[1024 * 1000];
    307306  size_t nread;
     
    310309  long total = 0;
    311310  int duration;
    312   int cnt=ssh_get_cnt(conf);
    313311  int rc;
    314312  LIBSSH2_SFTP_HANDLE *sftp_handle;
     
    323321  if (!local) {
    324322    fprintf(stderr, "Can't open local file %s\n", localPath);
    325     return -1;
     323    return false;
    326324  }
    327325
     
    382380  duration = (int)(time(NULL)-start);
    383381  fclose(local);
    384   libssh2_sftp_close(sftp_handle);
     382  libssh2_sftp_close_handle(sftp_handle);
    385383
    386384  libssh2_sftp_shutdown(sessions[cnt]->sftp_session);
     
    396394 * @return true in case of success, false if failure occured
    397395 */
    398 int ssh_fetch(maps* conf,const char* localPath,const char* targetPath){
     396int ssh_fetch(maps* conf,const char* localPath,const char* targetPath,int cnt){
    399397  char mem[1024];
    400398  size_t nread;
     
    403401  long total = 0;
    404402  int duration;
    405   int cnt=ssh_get_cnt(conf);
    406403  int rc;
    407404  LIBSSH2_SFTP_HANDLE *sftp_handle;
     
    428425        if (!sftp_handle) {
    429426            if (libssh2_session_last_errno(sessions[cnt]->session) != LIBSSH2_ERROR_EAGAIN) {
    430 
    431427                fprintf(stderr, "Unable to open file with SFTP\n");
    432428                return -1;
     
    443439        do {
    444440            rc = libssh2_sftp_read(sftp_handle, mem, sizeof(mem));
    445             fprintf(stderr, "libssh2_sftp_read returned %d\n",
    446                     rc);
    447  
     441            /*fprintf(stderr, "libssh2_sftp_read returned %d\n",
     442              rc);*/
    448443            if(rc > 0) {
    449                 write(2, mem, rc);
     444              //write(2, mem, rc);
    450445                fwrite(mem, rc, 1, local);
    451446            }
     
    479474  duration = (int)(time(NULL)-start);
    480475  fclose(local);
    481   libssh2_sftp_close(sftp_handle);
     476  libssh2_sftp_close_handle(sftp_handle);
    482477
    483478  libssh2_sftp_shutdown(sessions[cnt]->sftp_session);
     
    491486 * @return bytecount resulting from the execution of the command
    492487 */
    493 int ssh_exec(maps* conf,const char* command){
    494   int cnt=ssh_get_cnt(conf);
     488int ssh_exec(maps* conf,const char* command,int cnt){
    495489  LIBSSH2_CHANNEL *channel;
    496490  int rc;
     
    571565  while (libssh2_session_disconnect(con->session, "Normal Shutdown, Thank you for using the ZOO-Project sshapi")
    572566         == LIBSSH2_ERROR_EAGAIN);
    573   libssh2_session_free(con->session);
    574567#ifdef WIN32
    575568  closesocket(con->sock_id);
     
    577570  close(con->sock_id);
    578571#endif
     572  libssh2_session_free(con->session);
    579573  return true;
    580574}
     
    596590  return true;
    597591}
     592
     593bool addToUploadQueue(maps** conf,maps* input){
     594  map* queueMap=getMapFromMaps(*conf,"uploadQueue","length");
     595  if(queueMap==NULL){
     596    maps* queueMaps=createMaps("uploadQueue");
     597    queueMaps->content=createMap("length","0");
     598    addMapsToMaps(conf,queueMaps);
     599    freeMaps(&queueMaps);
     600    free(queueMaps);
     601    queueMap=getMapFromMaps(*conf,"uploadQueue","length");
     602  }
     603  maps* queueMaps=getMaps(*conf,"uploadQueue");
     604  int queueIndex=atoi(queueMap->value);
     605  if(input!=NULL){
     606    if(getMap(input->content,"cache_file")!=NULL){
     607      map* length=getMap(input->content,"length");
     608      if(length==NULL){
     609        addToMap(input->content,"length","1");
     610        length=getMap(input->content,"length");
     611      }
     612      int len=atoi(length->value);
     613      int i=0;
     614      for(i=0;i<len;i++){
     615       
     616        map* tmp[2]={getMapArray(input->content,"localPath",i),
     617                     getMapArray(input->content,"targetPath",i)};
     618
     619        setMapArray(queueMaps->content,"input",queueIndex,input->name);
     620        setMapArray(queueMaps->content,"localPath",queueIndex,tmp[0]->value);
     621        setMapArray(queueMaps->content,"targetPath",queueIndex,tmp[1]->value);
     622        queueIndex+=1;
     623      }
     624    }
     625  }
     626#ifdef DEBUG 
     627  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     628  fflush(stderr);
     629  dumpMaps(queueMaps);
     630  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     631  fflush(stderr);
     632  dumpMaps(*conf);
     633  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     634  fflush(stderr);
     635#endif
     636  return true;
     637}
     638
     639bool runUpload(maps** conf){
     640  SSHCON *test=ssh_connect(*conf);
     641  if(test==NULL){
     642    return false;
     643  }
     644#ifdef DEBUG
     645  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     646  fflush(stderr);
     647  dumpMaps(getMaps(*conf,"uploadQueue"));
     648  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     649  fflush(stderr);
     650#endif
     651  map* queueLengthMap=getMapFromMaps(*conf,"uploadQueue","length");
     652  maps* queueMaps=getMaps(*conf,"uploadQueue");
     653  if(queueLengthMap!=NULL){
     654    int cnt=atoi(queueLengthMap->value);
     655    int i=0;
     656    for(i=0;i<cnt;i++){
     657      map* argv[3]={
     658        getMapArray(queueMaps->content,"input",i),
     659        getMapArray(queueMaps->content,"localPath",i),
     660        getMapArray(queueMaps->content,"targetPath",i)
     661      };
     662      fprintf(stderr,"%s %d %s %s\n",__FILE__,__LINE__,argv[1]->value,argv[2]->value);
     663      ssh_copy(*conf,argv[1]->value,argv[2]->value,ssh_get_cnt(*conf));
     664    }   
     665  }
     666  return true;
     667}
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png