- Timestamp:
- Feb 1, 2018, 11:27:28 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/prototype-v0/zoo-project/zoo-kernel/service_internal_hpc.c
r860 r862 60 60 while(cur!=NULL && cur->defaults!=NULL){ 61 61 map* mimeType=getMap(cur->defaults->content,"mimeType"); 62 if(mimeType!=NULL){ 62 map* useMS=getMap(cur->defaults->content,"useMapserver"); 63 if(mimeType!=NULL && useMS!=NULL && strncasecmp(useMS->value,"true",4)==0){ 63 64 int geo=isGeographic(mimeType->value); 64 65 if(geo>0){ … … 159 160 free(tmp[0]); 160 161 //addToMap(cur->content,"internal","true"); 161 } 162 } 162 163 } 163 164 cur=cur->next; … … 332 333 int parameters_cnt=0; 333 334 while(input!=NULL && input->content!=NULL){ 334 if(getMaps(*real_outputs,input->name)==NULL){ 335 map* isInRequest=getMap(input->content,"inRequest"); 336 map* minNb=getMap(input->content,"minoccurs"); 337 if(getMaps(*real_outputs,input->name)==NULL && 338 ( (isInRequest!=NULL && strncasecmp(isInRequest->value,"true",4)==0) 339 || (minNb!=NULL && atoi(minNb->value)>0) ) ){ 335 340 parameters_cnt+=1; 336 341 if(parameters_cnt==1) … … 345 350 dumpMapsValuesToFiles(main_conf,&input); 346 351 addToMap(input->content,"toPublish","true"); 347 addToMap(input->content,"useMapserver","true");352 //addToMap(input->content,"useMapserver","true"); 348 353 } 349 354 if(getMap(input->content,"cache_file")!=NULL){ … … 362 367 setMapArray(input->content,"targetPath",i,targetPath); 363 368 setMapArray(input->content,"localPath",i,tmp->value); 364 addToUploadQueue(main_conf,input); 369 map* tmp1=getMapArray(input->content,"value",i); 370 if(tmp1!=NULL){ 371 free(tmp1->value); 372 tmp1->value=strdup("empty"); 373 } 365 374 if(i==0){ 366 375 parameters[parameters_cnt-1]=(char*)malloc((strlen(input->name)+strlen(targetPath)+3)*sizeof(char)); 367 376 sprintf(parameters[parameters_cnt-1],"-%s %s",input->name,targetPath); 368 377 }else{ 378 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 379 fflush(stderr); 369 380 char *tmpStr=zStrdup(parameters[parameters_cnt-1]); 370 381 parameters[parameters_cnt-1]=(char*)realloc(parameters[parameters_cnt-1],(strlen(tmpStr)+strlen(targetPath)+2)*sizeof(char)); 371 382 sprintf(parameters[parameters_cnt-1],"%s %s",tmpStr,targetPath); 372 383 free(tmpStr); 384 fprintf(stderr,"%s %d\n",__FILE__,__LINE__); 385 fflush(stderr); 373 386 } 374 387 free(targetPath); 375 388 } 389 addToUploadQueue(main_conf,input); 376 390 }else{ 377 391 // ??? … … 396 410 #endif 397 411 invokeCallback(m,inputs,NULL,1,1); 412 invokeCallback(m,inputs,NULL,2,0); 398 413 if(getMapFromMaps(m,"lenv","mapError")!=NULL){ 399 invokeCallback( m,inputs,NULL,7,0);414 invokeCallback(*main_conf,inputs,NULL,7,0); 400 415 return -1; 401 416 } 402 invokeCallback(m,inputs,NULL,2,0);403 417 #ifdef HPC_DEBUG 404 418 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); … … 408 422 // Upload data on HPC 409 423 if(runUpload(main_conf)==false){ 410 errorException ( m, _("Unable to lock the file for upload!"),424 errorException (*main_conf, _("Unable to lock the file for upload!"), 411 425 "InternalError", NULL); 412 426 #ifdef HPC_DEBUG 413 427 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); 414 428 #endif 415 invokeCallback( m,inputs,NULL,7,0);429 invokeCallback(*main_conf,inputs,NULL,7,0); 416 430 #ifdef HPC_DEBUG 417 431 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); … … 429 443 // Add the filename to generate for every output to parameters 430 444 input=*real_outputs; 431 // TODO: fix appendOutputParameters432 //appendOutputParameters(input,parameters,¶meters_cnt,s,uuid,targetPathMap);433 445 #ifdef HPC_DEBUG 434 446 dumpMaps(input); 435 447 #endif 436 448 while(input!=NULL){ 437 // TODO: parse all outputs including inner outputs if required.449 // Parse all outputs including inner outputs if required. 438 450 if(input->child==NULL){ 439 451 // Name every files that should be produced by the service execution … … 453 465 char *targetPath=(char*)malloc((strlen(targetPathMap->value)+strlen(targetName)+2)*sizeof(char)); 454 466 sprintf(targetPath,"%s/%s",targetPathMap->value,targetName); 467 map *tmpUrl=getMapFromMaps(*main_conf,"main","tmpUrl"); 468 char *targetUrl=(char*)malloc((strlen(tmpUrl->value)+strlen(targetName)+2)*sizeof(char)); 469 sprintf(targetUrl,"%s/%s",tmpUrl->value,targetName); 455 470 free(targetName); 456 471 setMapInMaps(*real_outputs,input->name,"generated_file",targetPath); 457 if(strcasecmp(input->name,"wms_link")!=0&&458 strcasecmp(input->name,"wcs_link")!=0 && 459 strcasecmp(input->name,"wfs_link")!=0){472 addToMap(input->content,"generated_url",targetUrl); 473 free(targetUrl); 474 { 460 475 parameters_cnt+=1; 461 476 if(parameters_cnt==1) … … 494 509 char *targetPath=(char*)malloc((strlen(targetPathMap->value)+strlen(targetName)+2)*sizeof(char)); 495 510 sprintf(targetPath,"%s/%s",targetPathMap->value,targetName); 511 map *tmpUrl=getMapFromMaps(*main_conf,"main","tmpUrl"); 512 char *targetUrl=(char*)malloc((strlen(tmpUrl->value)+strlen(targetName)+2)*sizeof(char)); 513 sprintf(targetUrl,"%s/%s",tmpUrl->value,targetName); 496 514 free(targetName); 497 515 addToMap(input->content,"generated_file",targetPath); 498 516 addToMap(input->content,"storage",targetPath); 517 addToMap(input->content,"generated_url",targetUrl); 518 free(targetUrl); 499 519 if(strcasecmp(input->name,"wms_link")!=0&& 500 520 strcasecmp(input->name,"wcs_link")!=0 && … … 623 643 setMapInMaps(*main_conf,"lenv","message",_("There is no remote_work_path defined in your section!")); 624 644 setMapInMaps(*main_conf,"lenv","status","failed"); 625 errorException ( m, _("There is no remote_work_path defined in your section!"),645 errorException (*main_conf, _("There is no remote_work_path defined in your section!"), 626 646 "InternalError", NULL); 627 647 #ifdef HPC_DEBUG … … 629 649 fflush(stderr); 630 650 #endif 631 invokeCallback( m,NULL,NULL,7,0);651 invokeCallback(*main_conf,NULL,NULL,7,0); 632 652 #ifdef HPC_DEBUG 633 653 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); … … 645 665 free(scriptPath); 646 666 if(copy0!=true){ 647 setMapInMaps( m,"lenv","message",_("Unable to upload the script"));648 invokeCallback( m,NULL,NULL,7,0);649 errorException( m,_("Unable to upload the script"),"NoApplicableCode",NULL);667 setMapInMaps(*main_conf,"lenv","message",_("Unable to upload the script")); 668 invokeCallback(*main_conf,NULL,NULL,7,0); 669 errorException(*main_conf,_("Unable to upload the script"),"NoApplicableCode",NULL); 650 670 return -1; 651 671 } … … 688 708 fflush(stderr); 689 709 #endif 690 invokeCallback( m,NULL,NULL,7,0);710 invokeCallback(*main_conf,NULL,NULL,7,0); 691 711 #ifdef HPC_DEBUG 692 712 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); … … 694 714 #endif 695 715 sprintf(tmpS, "Cannot execute the HPC ZOO-Service %s using %s: %s", s->name, configurationId, tmpPath->value); 696 errorException( m,tmpS,"NoApplicableCode",NULL);716 errorException(*main_conf,tmpS,"NoApplicableCode",NULL); 697 717 free(command); 698 718 free(targetPath); 699 719 ssh_close(*main_conf); 700 720 removeReadLocks(main_conf); 701 sleep(1);702 721 return -1; 703 722 } … … 728 747 if (bind(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) { 729 748 perror("bind error"); 730 setMapInMaps( m,"lenv","message",_("Unable to bind socket!"));731 errorException ( m, _("Unable to bind socket!"),749 setMapInMaps(*main_conf,"lenv","message",_("Unable to bind socket!")); 750 errorException (*main_conf, _("Unable to bind socket!"), 732 751 "InternalError", NULL); 733 752 #ifdef HPC_DEBUG … … 735 754 fflush(stderr); 736 755 #endif 737 invokeCallback( m,NULL,NULL,7,0);756 invokeCallback(*main_conf,NULL,NULL,7,0); 738 757 removeReadLocks(main_conf); 739 758 #ifdef HPC_DEBUG … … 749 768 if (listen(fd, 5) == -1) { 750 769 setMapInMaps(*main_conf,"lenv","message",_("Listen error")); 751 errorException ( m, _("Listen error"),770 errorException (*main_conf, _("Listen error"), 752 771 "InternalError", NULL); 753 772 #ifdef HPC_DEBUG … … 755 774 fflush(stderr); 756 775 #endif 757 invokeCallback( m,NULL,NULL,7,0);776 invokeCallback(*main_conf,NULL,NULL,7,0); 758 777 removeReadLocks(main_conf); 759 778 #ifdef HPC_DEBUG … … 765 784 if ( (cl = accept(fd, NULL, NULL)) == -1) { 766 785 setMapInMaps(*main_conf,"lenv","message",_("Accept error")); 767 errorException ( m, _("Accept error"),786 errorException (*main_conf, _("Accept error"), 768 787 "InternalError", NULL); 769 788 #ifdef HPC_DEBUG … … 771 790 fflush(stderr); 772 791 #endif 773 invokeCallback( m,NULL,NULL,7,0);792 invokeCallback(*main_conf,NULL,NULL,7,0); 774 793 removeReadLocks(main_conf); 775 794 #ifdef HPC_DEBUG … … 788 807 while ( (rc=read(cl,buf,10)) ) { 789 808 if(rc==0){ 790 sleep(1);791 809 setMapInMaps(*main_conf,"lenv","message",_("Read closed")); 792 errorException ( m, _("Read closed"),810 errorException (*main_conf, _("Read closed"), 793 811 "InternalError", NULL); 794 812 #ifdef HPC_DEBUG … … 796 814 fflush(stderr); 797 815 #endif 798 invokeCallback( m,NULL,NULL,7,0);816 invokeCallback(*main_conf,NULL,NULL,7,0); 799 817 removeReadLocks(main_conf); 800 818 #ifdef HPC_DEBUG … … 806 824 if(rc<0){ 807 825 setMapInMaps(*main_conf,"lenv","message",_("Read error")); 808 errorException ( m, _("Read error"),826 errorException (*main_conf, _("Read error"), 809 827 "InternalError", NULL); 810 828 #ifdef HPC_DEBUG … … 812 830 fflush(stderr); 813 831 #endif 814 invokeCallback( m,NULL,NULL,7,0);832 invokeCallback(*main_conf,NULL,NULL,7,0); 815 833 removeReadLocks(main_conf); 816 834 #ifdef HPC_DEBUG … … 872 890 free(targetPath); 873 891 }else{ 874 char *tmpStr=(char*)malloc((strlen(filename)+strlen(_("Unable to fetch the remote file for %s"))+1)*sizeof(char)); 875 sprintf(tmpStr,_("Unable to fetch the remote file for %s"),filename); 876 setMapInMaps(m,"lenv","message",tmpStr); 877 free(tmpStr); 878 invokeCallback(m,NULL,NULL,7,0); 892 map* hpcStdErr=getMapFromMaps(*main_conf,"henv","StdErr"); 893 if(hpcStdErr!=NULL && ssh_fetch(*main_conf,targetPath,hpcStdErr->value,ssh_get_cnt(m))==0){ 894 struct stat f_status; 895 int ts=stat(targetPath, &f_status); 896 if(ts==0) { 897 char* fcontent = NULL; 898 fcontent=(char*)malloc(sizeof(char)*(f_status.st_size+1)); 899 FILE* f=fopen(targetPath,"rb"); 900 fread(fcontent,f_status.st_size,1,f); 901 int fsize=f_status.st_size; 902 fcontent[fsize]=0; 903 fclose(f); 904 setMapInMaps(*main_conf,"lenv","message",fcontent); 905 free(fcontent); 906 }else{ 907 char *tmpStr=(char*)malloc((strlen(filename)+strlen(_("Unable to fetch the remote file for %s"))+1)*sizeof(char)); 908 sprintf(tmpStr,_("Unable to fetch the remote file for %s"),filename); 909 setMapInMaps(*main_conf,"lenv","message",tmpStr); 910 free(tmpStr); 911 } 912 }else{ 913 char *tmpStr=(char*)malloc((strlen(filename)+strlen(_("Unable to fetch the remote file for %s"))+1)*sizeof(char)); 914 sprintf(tmpStr,_("Unable to fetch the remote file for %s"),filename); 915 setMapInMaps(*main_conf,"lenv","message",tmpStr); 916 free(tmpStr); 917 } 918 invokeCallback(*main_conf,NULL,NULL,7,0); 879 919 return SERVICE_FAILED; 880 920 } … … 882 922 }else{ 883 923 map* generatedFile=getMap(input->content,"generated_file"); 924 map* generatedUrl=getMap(input->content,"generated_url"); 884 925 if(generatedFile!=NULL){ 885 926 char* filename=strrchr(generatedFile->value,'/'); … … 895 936 maps* output=getMaps(*real_outputs,input->name); 896 937 setMapInMaps(output->child,"download_link","generated_file",targetPath); 938 setMapInMaps(output->child,"download_link","generated_url",generatedUrl->value); 897 939 setMapInMaps(output->child,"download_link","storage",targetPath); 898 940 setMapInMaps(output->child,"download_link","useMapserver","false"); … … 908 950 if(getMaps(output->child,"wcs_link")!=NULL){ 909 951 sprintf(serviceName,"wcs_link"); 910 setMapInMaps(output->child,serviceName,"msOgc","WCS"); 911 setMapInMaps(output->child,serviceName,"requestedMimeType","image/tiff"); 912 } 913 else{ 952 setMapInMaps(output->child,"wcs_link","msOgc","WCS"); 953 }else{ 914 954 sprintf(serviceName,"wfs_link"); 915 setMapInMaps(output->child,serviceName,"msOgc","WFS"); 916 setMapInMaps(output->child,serviceName,"requestedMimeType","text/xml"); 917 } 955 setMapInMaps(output->child,"wfs_link","msOgc","WFS"); 956 } 918 957 setMapInMaps(output->child,serviceName,"storage",targetPath); 919 958 setMapInMaps(output->child,serviceName,"generated_file",targetPath); … … 958 997 }else{ 959 998 // Try to access remotely to the log file and return a more relevant error message 960 setMapInMaps( m,"lenv","message",_("HPC Execution failed!"));961 errorException ( m, _("HPC Execution failed!"),999 setMapInMaps(*main_conf,"lenv","message",_("HPC Execution failed!")); 1000 errorException (*main_conf, _("HPC Execution failed!"), 962 1001 "InternalError", NULL); 963 1002 #ifdef HPC_DEBUG … … 965 1004 fflush(stderr); 966 1005 #endif 967 invokeCallback( m,NULL,NULL,7,0);1006 invokeCallback(*main_conf,NULL,NULL,7,0); 968 1007 #ifdef HPC_DEBUG 969 1008 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__); … … 971 1010 #endif 972 1011 } 973 //free(buf);974 1012 } 975 1013 if(hasPassed<0){ 976 1014 perror("Failed to read"); 977 1015 setMapInMaps(*main_conf,"lenv","message",_("Unable to parse the value returned by remote execution")); 978 errorException ( m, _("Unable to parse the value returned by remote execution"),1016 errorException (*main_conf, _("Unable to parse the value returned by remote execution"), 979 1017 "InternalError", NULL); 980 1018 #ifdef HPC_DEBUG … … 982 1020 fflush(stderr); 983 1021 #endif 984 invokeCallback( m,NULL,NULL,7,0);1022 invokeCallback(*main_conf,NULL,NULL,7,0); 985 1023 #ifdef HPC_DEBUG 986 1024 fprintf(stderr,"************************* %s %d \n\n",__FILE__,__LINE__);
Note: See TracChangeset
for help on using the changeset viewer.