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-services/utils/hpc/service.c

    r839 r854  
    33 *
    44 * Copyright 2008-2009 GeoLabs SARL. All rights reserved.
     5 *
     6 * This work was supported by public funds received in the framework of GEOSUD,
     7 * a project (ANR-10-EQPX-20) of the program "Investissements d'Avenir" managed
     8 * by the French National Research Agency
    59 *
    610 * Permission is hereby granted, free of charge, to any person obtaining a copy
     
    2731#include "service_internal.h"
    2832#include "sshapi.h"
     33#include "server_internal.h"
    2934
    3035#include <sys/socket.h>
     
    5762    int fd,rc=NULL;
    5863    int i=0;
     64    map* usid=getMapFromMaps(conf,"lenv","usid");
     65    map* tmpPath=getMapFromMaps(conf,"main","tmpPath");
     66
     67    char *flenv =
     68      (char *) malloc ((strlen (tmpPath->value) +
     69                        strlen (jobid->value) + 12) * sizeof (char));
     70    sprintf (flenv, "%s/%s_lenv.cfg", tmpPath->value, jobid->value);
     71    maps* m = (maps *) malloc (MAPS_SIZE);
     72    m->child=NULL;
     73    m->next=NULL;
     74    map* configId=NULL;
     75
     76   
     77    if(conf_read(flenv, m) != 2){
     78      configId=getMapFromMaps(m,"lenv","configId");
     79      setMapInMaps(conf,"lenv","configId",configId->value);
     80    }else{
     81      setMapInMaps(conf,"lenv","message",_("Unable to read the lenv section file of the requested jobid"));
     82      return SERVICE_FAILED;
     83    }
     84    unlink(flenv);
     85    free(flenv);
     86
    5987    SSHCON *test=ssh_connect(conf);
    6088    if(test==NULL){
    61       return SERVICE_FAILED;
    62     }
    63     map* usid=getMapFromMaps(conf,"lenv","usid");
    64     map* tmpPath=getMapFromMaps(conf,"main","tmpPath");
     89      setMapInMaps(conf,"lenv","message",_("Unable to connect using through ssh."));
     90      return SERVICE_FAILED;
     91    }
     92
    6593    char *logPath=(char*)malloc((strlen(tmpPath->value)+strlen(jobid->value)+12)*sizeof(char));
    6694    sprintf(logPath,"%s/exec_out_%s",tmpPath->value,jobid->value);
     
    80108    }
    81109    free(logPath);
    82     // Run scontrol to see if the service execution ends
     110    // Run scontrol to check if the service execution ended.
    83111    // Store all the informations returned by scontrol command as a cfg file to
    84112    // be parsed back by the ZOO-Kernel waiting for the execution of the remote
     
    86114    maps* tmpMaps=createMaps("henv");
    87115    char* command=(char*)malloc((126)*sizeof(char));
    88     //memset(&command,0,34);
    89     sprintf(command,"scontrol show jobid | grep -A24 %s",fcontent);   
     116    sprintf(command,"scontrol show jobid | grep -A24 JobId=%s",fcontent);   
    90117    if(ssh_exec(conf,command,ssh_get_cnt(conf))==0){
    91118      free(command);
    92119      setMapInMaps(conf,"lenv","message",_("Failed to run scontrol remotely"));
     120      // TODO: check status in db and if available continue in other case return SERVICE_FAILED
    93121      return SERVICE_FAILED;
    94122    }else{
     
    98126      int ts=stat(logPath, &f_status);
    99127      if(ts==0) {
    100         fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1));
    101         FILE* f=fopen(logPath,"rb");
    102         fread(fcontent,f_status.st_size,1,f);
    103         int fsize=f_status.st_size;
    104         fcontent[fsize]=0;
    105         fclose(f);
    106         free(logPath);
    107         fprintf(stderr,"%s \n",fcontent);
    108         char *token, *saveptr;
    109         token = strtok_r (fcontent, " ", &saveptr);
    110         while (token != NULL)
    111           {
    112             //fprintf(stderr,"%s %d\n",token,__LINE__);
    113             char *token1, *saveptr1;
    114             char *tmpToken=strdup(token);
    115             token1 = strtok_r (tmpToken, "=", &saveptr1);
    116             int isNext=-1;
    117             int hasTwoElements=0;
    118             char *name=NULL;
    119             while (token1 != NULL)
    120               {
    121                 if(hasTwoElements==0)
    122                   name=strdup(token1);
    123                 if(hasTwoElements<1)
    124                   hasTwoElements+=1;
    125                 else{
    126                   char *value=strdup(token1);
    127                   if(value[strlen(value)-1]=='\n')
    128                     value[strlen(value)-1]=0;
    129                   if(strlen(name)>0 && strlen(value)>0){
    130                     if(tmpMaps->content==NULL)
    131                       tmpMaps->content=createMap(name,value);
    132                     else
    133                       addToMap(tmpMaps->content,name,value);
    134                     free(value);
    135                   }
    136                   free(name);
    137                   hasTwoElements=0;
    138                 }
    139                 token1 = strtok_r (NULL, "=", &saveptr1);
    140               }
    141             free(tmpToken);
    142             token = strtok_r (NULL, " ", &saveptr);
    143           }
     128        fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1));
     129        FILE* f=fopen(logPath,"rb");
     130        fread(fcontent,f_status.st_size,1,f);
     131        int fsize=f_status.st_size;
     132        fcontent[fsize]=0;
     133        fclose(f);
     134        free(logPath);
     135        char *token, *saveptr;
     136        token = strtok_r (fcontent, " ", &saveptr);
     137        while (token != NULL)
     138          {
     139            char *token1, *saveptr1;
     140            char *tmpToken=strdup(token);
     141            token1 = strtok_r (tmpToken, "=", &saveptr1);
     142            int isNext=-1;
     143            int hasTwoElements=0;
     144            char *name=NULL;
     145            while (token1 != NULL)
     146              {
     147                if(hasTwoElements==0)
     148                  name=strdup(token1);
     149                if(hasTwoElements<1)
     150                  hasTwoElements+=1;
     151                else{
     152                  char *value=strdup(token1);
     153                  if(value[strlen(value)-1]=='\n')
     154                    value[strlen(value)-1]=0;
     155                  if(strlen(name)>0 && strlen(value)>0){
     156                    if(tmpMaps->content==NULL)
     157                      tmpMaps->content=createMap(name,value);
     158                    else
     159                      addToMap(tmpMaps->content,name,value);
     160                    free(value);
     161                  }
     162                  free(name);
     163                  hasTwoElements=0;
     164                }
     165                token1 = strtok_r (NULL, "=", &saveptr1);
     166              }
     167            free(tmpToken);
     168            token = strtok_r (NULL, " ", &saveptr);
     169          }
    144170      }else{
    145         setMapInMaps(conf,"lenv","message",_("Unable to access the downloaded execution log file"));
    146         return SERVICE_FAILED;
     171        setMapInMaps(conf,"lenv","message",_("Unable to access the downloaded execution log file"));
     172        return SERVICE_FAILED;
    147173      }
    148174    }
    149     logPath=(char*)malloc((strlen(tmpPath->value)+strlen(usid->value)+15)*sizeof(char));
    150     sprintf(logPath,"%s/exec_status_%s",tmpPath->value,usid->value);
    151     dumpMapsToFile(tmpMaps,logPath,0);
    152 
    153     char *sname=(char*)malloc((strlen(tmpPath->value)+strlen(jobid->value)+21));
    154     sprintf(sname,"%s/.wait_socket_%s.sock",tmpPath->value,jobid->value);
    155     if ( (fd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1) {
    156       perror("socket error");
    157       setMapInMaps(conf,"lenv","message",_("Socket error"));
    158       return SERVICE_FAILED;
    159       }
    160     }
    161     logPath=(char*)malloc((strlen(tmpPath->value)+strlen(usid->value)+15)*sizeof(char));
    162     sprintf(logPath,"%s/exec_status_%s",tmpPath->value,usid->value);
     175    logPath=(char*)malloc((strlen(tmpPath->value)+strlen(jobid->value)+15)*sizeof(char));
     176    sprintf(logPath,"%s/exec_status_%s",tmpPath->value,jobid->value);
    163177    dumpMapsToFile(tmpMaps,logPath,0);
    164178    char *sname=(char*)malloc((strlen(tmpPath->value)+strlen(jobid->value)+21));
     
    179193    if (write(fd, "3", 1) != rc) {
    180194      if (rc < 0) {
    181         perror("write error");
    182         setMapInMaps(conf,"lenv","message",_("Unable to announce the successful execution of the HPC service"));
    183         close(fd);
    184         return SERVICE_FAILED;
     195        perror("write error");
     196        setMapInMaps(conf,"lenv","message",_("Unable to announce the successful execution of the HPC service"));
     197        close(fd);
     198        return SERVICE_FAILED;
    185199      }
    186200    }
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