Ignore:
Timestamp:
Nov 21, 2017, 10:24:14 AM (6 years ago)
Author:
djay
Message:

HPC support update. Add inputs for create options in Gdal_Dem.

File:
1 edited

Legend:

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

    r851 r854  
    2929
    3030#include "sshapi.h"
     31#include "service_internal.h"
    3132
    3233SSHCON *sessions[MAX_PARALLEL_SSH_CON];
     
    9495  int port=22;
    9596
    96   fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
    97   fflush(stderr);
    98 
    99   map* hpc_host=getMapFromMaps(conf,"HPC","host");
    100   map* hpc_port=getMapFromMaps(conf,"HPC","port");
    101   map* hpc_user=getMapFromMaps(conf,"HPC","user");
    102   map* hpc_password=getMapFromMaps(conf,"HPC","password");
    103   map* hpc_public_key=getMapFromMaps(conf,"HPC","key");
    104 
    105   fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
    106   fflush(stderr);
     97  map* hpc_config=getMapFromMaps(conf,"lenv","configId");
     98 
     99  map* hpc_host=getMapFromMaps(conf,hpc_config->value,"ssh_host");
     100  map* hpc_port=getMapFromMaps(conf,hpc_config->value,"ssh_port");
     101  map* hpc_user=getMapFromMaps(conf,hpc_config->value,"ssh_user");
     102  map* hpc_password=getMapFromMaps(conf,hpc_config->value,"ssh_password");
     103  map* hpc_public_key=getMapFromMaps(conf,hpc_config->value,"ssh_key");
     104
     105  char ip[100];
     106  struct hostent *my_hostent;
     107  struct in_addr **addrs;
     108 
     109  if (hpc_host != NULL) {
     110    // Fetch ip address for the hostname
     111    if ( (my_hostent = gethostbyname( hpc_host->value ) ) == NULL){
     112      herror("gethostbyname");
     113      setMapInMaps(conf,"lenv","message",_("Issue when invoking gethostbyname!"));
     114      return NULL;
     115    }
     116 
     117    addrs = (struct in_addr **) my_hostent->h_addr_list;
     118 
     119    for(i = 0; addrs[i] != NULL; i++) {
     120      strcpy(ip , inet_ntoa(*addrs[i]) );
     121      break;
     122    }
     123  }
    107124
    108125#ifdef WIN32
     
    117134#endif
    118135
    119   // TODO: fetch ip address for the hostname
    120136  if (hpc_host != NULL) {
    121     hostaddr = inet_addr(hpc_host->value);
     137    hostaddr = inet_addr(ip);
    122138  } else {
    123139    setMapInMaps(conf,"lenv","message","No host parameter found in your main.cfg file!\n");
     
    235251int ssh_get_cnt(maps* conf){
    236252  int result=0;
    237   map* myMap=getMapFromMaps(conf,"lenv","cnt_session");
     253  map* myMap=getMapFromMaps(conf,"lenv","nb_sessions");
    238254  if(myMap!=NULL){
    239255    result=atoi(myMap->value);
     
    323339    return false;
    324340  }
    325 
     341 
    326342  do {
    327343    sessions[cnt]->sftp_session = libssh2_sftp_init(sessions[cnt]->session);
     
    391407 * @param targetPath const char* defining the path for accessing the file on the
    392408 * remote host
    393  * @return true in case of success, false if failure occured
     409 * @return 0 in case of success, -1 if failure occured
    394410 */
    395411int ssh_fetch(maps* conf,const char* localPath,const char* targetPath,int cnt){
     
    414430     
    415431      fprintf(stderr, "Unable to init SFTP session\n");
    416       return false;
     432      return -1;
    417433    }
    418434  } while (!sessions[cnt]->sftp_session);
     435  do {
     436    sftp_handle = libssh2_sftp_open(sessions[cnt]->sftp_session, targetPath,   
     437                                    LIBSSH2_FXF_READ, 0);
     438    if (!sftp_handle) {
     439      if (libssh2_session_last_errno(sessions[cnt]->session) != LIBSSH2_ERROR_EAGAIN) {
     440        fprintf(stderr, " ** Unable to open file with SFTP\n");
     441        return -1;
     442      }
     443      else {
     444        //non-blocking open
     445        waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session);
     446      }
     447    }
     448  } while (!sftp_handle);
     449 
     450  int result=0;
     451  do {
    419452    do {
    420         sftp_handle = libssh2_sftp_open(sessions[cnt]->sftp_session, targetPath,
    421 
    422                                         LIBSSH2_FXF_READ, 0);
    423  
    424         if (!sftp_handle) {
    425             if (libssh2_session_last_errno(sessions[cnt]->session) != LIBSSH2_ERROR_EAGAIN) {
    426                 fprintf(stderr, "Unable to open file with SFTP\n");
    427                 return -1;
    428             }
    429             else {
    430                 fprintf(stderr, "non-blocking open\n");
    431                 waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session);
    432             }
    433         }
    434     } while (!sftp_handle);
    435  
    436     int result=1;
    437     do {
    438         do {
    439             rc = libssh2_sftp_read(sftp_handle, mem, sizeof(mem));
    440             /*fprintf(stderr, "libssh2_sftp_read returned %d\n",
    441               rc);*/
    442             if(rc > 0) {
    443               //write(2, mem, rc);
    444                 fwrite(mem, rc, 1, local);
    445             }
    446         } while (rc > 0);
    447  
    448         if(rc != LIBSSH2_ERROR_EAGAIN) {
    449           result=-1;
    450           break;
    451         }
    452 
    453         struct timeval timeout;
    454         fd_set fd;
    455         timeout.tv_sec = 10;
    456         timeout.tv_usec = 0;
    457  
    458         FD_ZERO(&fd);
    459  
    460         FD_SET(sessions[cnt]->sock_id, &fd);
    461  
    462         rc = select(sessions[cnt]->sock_id+1, &fd, &fd, NULL, &timeout);
    463         if(rc <= 0) {
    464           if(rc==0)
    465             fprintf(stderr, "SFTP download timed out: %d\n", rc);
    466           else
    467             fprintf(stderr, "SFTP download error: %d\n", rc);
    468           result=-1;
    469           break;
    470         }
    471  
    472     } while (1);
     453      rc = libssh2_sftp_read(sftp_handle, mem, sizeof(mem));
     454      /*fprintf(stderr, "libssh2_sftp_read returned %d\n",
     455        rc);*/
     456      if(rc > 0) {
     457        //write(2, mem, rc);
     458        fwrite(mem, rc, 1, local);
     459      }
     460    } while (rc > 0);
     461   
     462    if(rc != LIBSSH2_ERROR_EAGAIN) {
     463      result=-1;
     464      break;
     465    }
     466   
     467    struct timeval timeout;
     468    fd_set fd;
     469    timeout.tv_sec = 10;
     470    timeout.tv_usec = 0;
     471 
     472    FD_ZERO(&fd);
     473 
     474    FD_SET(sessions[cnt]->sock_id, &fd);
     475 
     476    rc = select(sessions[cnt]->sock_id+1, &fd, &fd, NULL, &timeout);
     477    if(rc <= 0) {
     478      if(rc==0)
     479        fprintf(stderr, "SFTP download timed out: %d\n", rc);
     480      else
     481        fprintf(stderr, "SFTP download error: %d\n", rc);
     482      return -1;
     483    }
     484 
     485  } while (1);
    473486  duration = (int)(time(NULL)-start);
    474487  fclose(local);
    475488  libssh2_sftp_close_handle(sftp_handle);
    476 
    477489  libssh2_sftp_shutdown(sessions[cnt]->sftp_session);
    478490  return 0;
     
    491503  int exitcode;
    492504  char *exitsignal=(char *)"none";
     505  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     506  fflush(stderr);
    493507  while( (channel = libssh2_channel_open_session(sessions[cnt]->session)) == NULL &&
    494508         libssh2_session_last_error(sessions[cnt]->session,NULL,NULL,0) == LIBSSH2_ERROR_EAGAIN ) {
     509    fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     510    fflush(stderr);
    495511      waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session);
    496512  }
     513  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     514  fflush(stderr);
    497515  if( channel == NULL ){
    498516    fprintf(stderr,"Error\n");
    499     return 1;
    500   }
     517    return -1;
     518  }
     519  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     520  fflush(stderr);
    501521  while( (rc = libssh2_channel_exec(channel, command)) == LIBSSH2_ERROR_EAGAIN ) {
     522    fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     523    fflush(stderr);
    502524    waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session);
    503525  }
     526  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     527  fflush(stderr);
    504528  if( rc != 0 ) {
    505529    fprintf(stderr,"Error\n");
    506530    return -1;
    507531  }
     532  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     533  fflush(stderr);
    508534
    509535  map* tmpPath=getMapFromMaps(conf,"main","tmpPath");
     
    513539  FILE* logFile=fopen(logPath,"wb");
    514540  free(logPath);
     541  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     542  fflush(stderr);
    515543  while(true){
    516544    int rc;
     
    535563      break;
    536564  }
     565  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     566  fflush(stderr);
    537567  fclose(logFile);
     568  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     569  fflush(stderr);
    538570  exitcode = 127;
     571  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     572  fflush(stderr);
    539573  while( (rc = libssh2_channel_close(channel)) == LIBSSH2_ERROR_EAGAIN )
    540574    waitsocket(sessions[cnt]->sock_id, sessions[cnt]->session);
     575  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     576  fflush(stderr);
    541577 
    542578  if( rc == 0 ) {
     
    545581                                    NULL, NULL, NULL, NULL, NULL);
    546582  }
     583  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     584  fflush(stderr);
    547585 
    548586  if (exitsignal)
     
    550588  else
    551589    fprintf(stderr, "\nEXIT: %d bytecount: %d\n", exitcode, bytecount);
     590  fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     591  fflush(stderr);
    552592 
    553593  libssh2_channel_free(channel);
     
    643683  }
    644684#ifdef DEBUG
    645   fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     685  fprintf(stderr,"*** %s %d\n",__FILE__,__LINE__);
    646686  fflush(stderr);
    647687  dumpMaps(getMaps(*conf,"uploadQueue"));
    648   fprintf(stderr,"%s %d\n",__FILE__,__LINE__);
     688  fprintf(stderr,"*** %s %d\n",__FILE__,__LINE__);
    649689  fflush(stderr);
    650690#endif
     
    660700        getMapArray(queueMaps->content,"targetPath",i)
    661701      };
    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));
     702      fprintf(stderr,"*** %s %d %s %s\n",__FILE__,__LINE__,argv[1]->value,argv[2]->value);
     703      /**/zooLock* lck;
     704      if((lck=lockFile(*conf,argv[1]->value,'w'))!=NULL){/**/
     705        if(ssh_copy(*conf,argv[1]->value,argv[2]->value,ssh_get_cnt(*conf))!=true){
     706          char* templateStr=_("Unable to copy over SSH the file requested for setting the value of %s.");
     707          char *tmpMessage=(char*)malloc((strlen(templateStr)+strlen(argv[0]->value)+1)*sizeof(char));
     708          sprintf(tmpMessage,templateStr,argv[0]->value);
     709          setMapInMaps(*conf,"lenv","message",tmpMessage);
     710          free(tmpMessage);
     711          unlockFile(*conf,lck);
     712          return false;
     713        }
     714        /**/unlockFile(*conf,lck);
     715      }else{
     716        setMapInMaps(*conf,"lenv","message",_("Unable to lock the file for upload!"));
     717        return false;
     718      }/**/
    664719    }   
    665720  }
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