GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

resourcebroker.c

Go to the documentation of this file.
00001 /** @file resourcebroker.c
00002  *  Source file for the sample ResourceBroker CPI provider.
00003  *
00004  *  @date Thu Oct 23 2003
00005  *
00006  *  @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/adaptors/resourcebroker/resourcebroker.c,v 1.15 2004/04/26 15:45:00 hartmutkaiser Exp $
00007  *
00008  *  Copyright (C) Hartmut Kaiser
00009  *  This file is part of the GAT Engine.
00010  *  Contributed by Hartmut Kaiser <hartmutkaiser [at] t-online [dot] de>.
00011  *
00012  *  Use, modification and distribution is subject to the Gridlab Software
00013  *  License. (See accompanying file GLlicense.txt or copy at
00014  *  http://www.gridlab.org/GLlicense.txt)
00015  */
00016  
00017 static const char *rcsid = "$Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/adaptors/resourcebroker/resourcebroker.c,v 1.15 2004/04/26 15:45:00 hartmutkaiser Exp $";
00018  
00019 /* System Header Files */
00020 #include <stdio.h>
00021 #include <stdlib.h>
00022 #include <string.h>
00023 #include <sys/utsname.h>
00024 
00025 /* GAT Header Files */
00026 #include "GATCPI.h"
00027 
00028 #include "GATResourceCPIInstanceData.h"
00029 #include "GATJobCPIInstanceData.h"
00030 
00031 #include "resourcebroker.h"
00032 
00033 /* Macros */
00034 
00035 /* Structures, unions and enums */
00036 
00037 /* Static function prototypes */
00038 static void
00039 resourcebroker_adaptor_ResourceBrokerCPI_Destroy(void *data);
00040 
00041 /* instance specific functions */
00042 static GATResult
00043 resourcebroker_adaptor_GATResourceBrokerCPI_ServiceActions(void *data, 
00044   GATResourceBrokerCPI_Instance *instance_data, GATTimePeriod_const timeout);
00045 
00046 static GATResult 
00047   resourcebroker_adaptor_GATResourceBrokerCPI_CreateInstance(void *data, 
00048     GATResourceBrokerCPI_Instance *instance_data);
00049 
00050 static void 
00051   resourcebroker_adaptor_GATResourceBrokerCPI_DestroyInstance(void *data, 
00052     GATResourceBrokerCPI_Instance *instance_data);
00053 
00054 static GATResult 
00055   resourcebroker_adaptor_GATResourceBrokerCPI_CloneInstance(void *data, 
00056     GATResourceBrokerCPI_Instance const *instance_data, 
00057     GATResourceBrokerCPI_Instance *new_instance_data);
00058 
00059 static GATResult 
00060   resourcebroker_adaptor_GATResourceBrokerCPI_EqualsInstance(void *data, 
00061     GATResourceBrokerCPI_Instance const *lhs, 
00062     GATResourceBrokerCPI_Instance const *rhs, GATBool *isequal);
00063 
00064 
00065 /* CPI API functionality */
00066 static GATResult
00067   resourcebroker_adaptor_ResourceBrokerCPI_ReserveResource_Description(
00068     void *data, GATResourceBrokerCPI_Instance const *instance_data, 
00069     GATResourceDescription_const description, GATTime_const time, 
00070     GATTimePeriod_const duration, GATReservation *reservation);
00071 
00072 static GATResult
00073   resourcebroker_adaptor_ResourceBrokerCPI_ReserveResource(
00074     void *data, GATResourceBrokerCPI_Instance const *instance_data, 
00075     GATResource_const resource, GATTime_const time, 
00076     GATTimePeriod_const duration, GATReservation *reservation);
00077 
00078 static GATResult
00079   resourcebroker_adaptor_ResourceBrokerCPI_FindResources(void *data, 
00080     GATResourceBrokerCPI_Instance const *instance_data, 
00081     GATResourceDescription_const description, GATList_GATResource *resources);
00082   
00083 static GATResult
00084   resourcebroker_adaptor_ResourceBrokerCPI_SubmitJob(void *data, 
00085     GATResourceBrokerCPI_Instance const *instance_data, 
00086     GATJobDescription_const desription, GATJob *job);
00087 
00088 /* local helper functions */
00089 static GATResult
00090   resourcebroker_adaptor_SubmitJob(GATContext context, GATString_const vo_name,
00091     GATResource_const resource, GATJobDescription_const jd, GATJob *job);
00092 
00093 /* File scope variables */
00094 
00095 /* External functions */
00096 
00097 /* Register the ResourceBroker CPI */
00098 GATResult resourcebroker_adaptor_Register_GATResourceBrokerCPI(
00099   GATContext error_context, GATRegistry registry, 
00100   GATTable_const system_config, GATTable_const instance_config, void *token)
00101 {
00102   GAT_USES_STATUS(error_context, "resourcebroker_adaptor_Register_GATResourceBrokerCPI");
00103 
00104   GATResourceBrokerCPI cpi = NULL;
00105   GATResourceBrokerCPI_Data cpidata;
00106   
00107   memset(&cpidata, 0, sizeof(GATResourceBrokerCPI_Data));
00108     
00109   /*
00110    *  provide the appropriate callback functions
00111    */
00112   cpidata.data = NULL;
00113   cpidata.destroy = resourcebroker_adaptor_ResourceBrokerCPI_Destroy;
00114   
00115   /* instance data handling */
00116   cpidata.service_actions = resourcebroker_adaptor_GATResourceBrokerCPI_ServiceActions;
00117   cpidata.create_instance = resourcebroker_adaptor_GATResourceBrokerCPI_CreateInstance;
00118   cpidata.destroy_instance = resourcebroker_adaptor_GATResourceBrokerCPI_DestroyInstance;
00119   cpidata.clone_instance = resourcebroker_adaptor_GATResourceBrokerCPI_CloneInstance;
00120   cpidata.equals_instance = resourcebroker_adaptor_GATResourceBrokerCPI_EqualsInstance;
00121 
00122   cpidata.reserve_description = resourcebroker_adaptor_ResourceBrokerCPI_ReserveResource_Description;
00123   cpidata.reserve = resourcebroker_adaptor_ResourceBrokerCPI_ReserveResource;
00124   cpidata.find_resources = resourcebroker_adaptor_ResourceBrokerCPI_FindResources;
00125   cpidata.submit_job = resourcebroker_adaptor_ResourceBrokerCPI_SubmitJob;
00126   
00127   /* Create a GATLogicalFileCPI object. */
00128   cpi = GATResourceBrokerCPI_Create(GATRESOURCEBROKERCPI_VERSION, &cpidata);
00129   if(NULL != cpi)
00130   {
00131     /* Need to pass preferences to allow matching
00132       * of a user's preferences with what this adaptor does.
00133       */
00134     GATPreferences preferences = GATPreferences_Create();
00135     if(NULL != preferences)
00136     {
00137       GAT_CREATE_STATUS(GATPreferences_Add(preferences, "Name", 
00138         "resourcebroker_adaptor"));
00139       GAT_CREATE_STATUS(GATPreferences_Add(preferences, "Security", "none"));
00140       GAT_CREATE_STATUS(GATPreferences_Add(preferences, "Local", "true"));
00141       
00142      GAT_CREATE_STATUS(GATRegistry_AddGATResourceBrokerCPI(registry, cpi, token, 
00143         preferences));
00144 
00145       GATPreferences_Destroy(&preferences);
00146     }
00147     else
00148     {
00149       GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00150     }
00151   }
00152   else
00153   {
00154     GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00155   }
00156   
00157   if (GAT_FAILED(GAT_CURRENT_STATUS()))
00158   {
00159     GATResourceBrokerCPI_Destroy(&cpi);
00160   }
00161   
00162   return GAT_RETURN_STATUS();
00163 }
00164 
00165 /* Local functions */
00166 static void
00167 resourcebroker_adaptor_ResourceBrokerCPI_Destroy(void *data)
00168 {
00169   /* nothing to do here (no internal data allocated) */
00170 }
00171 
00172 
00173 /* instance specific functions */
00174 
00175 /** resourcebroker_adaptor_GATResourceBrokerCPI_ServiceActions
00176  *  
00177  *  The function resourcebroker_adaptor_GATResourceBrokerCPI_ServiceActions is called, whenever
00178  *  the client calls GATContext_ServiceActions. This function is called for 
00179  *  every created object.
00180  *  This function should be used to update all instance specific data, which 
00181  *  may have been changed asynchronously or to fire pending events.
00182  *
00183  *  @param data Adaptor-provided data object.
00184  *  @param instance_data The instance data of this CPI object
00185  *  @param timeout This may be a 0 timeout to indicate no timeout at all, or
00186  *        a specific time length.
00187  *
00188  *  @return An error code.
00189  */
00190 static GATResult
00191 resourcebroker_adaptor_GATResourceBrokerCPI_ServiceActions(void *data, 
00192   GATResourceBrokerCPI_Instance *instance_data, GATTimePeriod_const timeout)
00193 {
00194   return GAT_NOTIMPL;
00195 }
00196 
00197 /** resourcebroker_adaptor_GATResourceBrokerCPI_CreateInstance
00198  *  Create a new CPI object instance.
00199  *  Adaptor implementation of create instance capability.
00200  *
00201  * @param data Adaptor-provided data object.
00202  * @param context The GATContext for this CPI instance
00203  * @param target The location of the file in question.
00204  * @param new_instance_data The pointer to the variable, where the instance 
00205  *      data of this CPI object is to be returned to.
00206  * 
00207  * @return An error code.
00208  */
00209 GATResult 
00210 resourcebroker_adaptor_GATResourceBrokerCPI_CreateInstance(void *data, 
00211   GATResourceBrokerCPI_Instance *new_instance_data)
00212 {
00213   GATResult retval = GAT_INVALID_PARAMETER;
00214   if (NULL != new_instance_data)
00215   {
00216     new_instance_data->instance_data = NULL;     /* no instance data */
00217     retval = GAT_SUCCESS;
00218   }
00219   return retval;
00220 }
00221 
00222 /** resourcebroker_adaptor_GATResourceBrokerCPI_DestroyInstance
00223  *  Destroy a CPI object instance.
00224  *  Adaptor implementation of destroy instance capability.
00225  *
00226  * @param data Adaptor-provided data object.
00227  * @param instance_data The instance data of the CPI object to destroy.
00228  */
00229 void
00230 resourcebroker_adaptor_GATResourceBrokerCPI_DestroyInstance(void *data, 
00231   GATResourceBrokerCPI_Instance *instance_data)
00232 {
00233   assert(NULL == instance_data->instance_data);  /* no instance data */
00234 }
00235 
00236 /** resourcebroker_adaptor_GATResourceBrokerCPI_CloneInstance
00237  *  Clone a CPI object instance.
00238  *  Adaptor implementation of the clone instance capability.
00239  *
00240  * @param data Adaptor-provided data object.
00241  * @param instance_data The instance data of this CPI object
00242  * @param new_instance_data The pointer to the variable, where the instance 
00243  *      data of the cloned CPI object is to be returned to.
00244  * 
00245  * @return An error code.
00246  */
00247 GATResult 
00248 resourcebroker_adaptor_GATResourceBrokerCPI_CloneInstance(void *data, 
00249   GATResourceBrokerCPI_Instance const *instance_data, 
00250   GATResourceBrokerCPI_Instance *new_instance_data)
00251 {
00252   if (new_instance_data)
00253   {
00254     new_instance_data->instance_data = NULL;     /* no instance data */
00255   }
00256   return GAT_SUCCESS;
00257 }
00258 
00259 /** resourcebroker_adaptor_GATResourceBrokerCPI_EqualsInstance
00260  *  Clone a CPI object instance.
00261  *  Adaptor implementation of the clone instance capability.
00262  *
00263  * @param data Adaptor-provided data object.
00264  * @param lhs The instance data of the left CPI object.
00265  * @param lhs The instance data of the right CPI object.
00266  * @param isequal The pointer to the variable, where the result is to be 
00267  *        returned to.
00268  *
00269  * @return An error code.
00270  */
00271 GATResult 
00272 resourcebroker_adaptor_GATResourceBrokerCPI_EqualsInstance(void *data, 
00273   GATResourceBrokerCPI_Instance const *lhs, 
00274   GATResourceBrokerCPI_Instance const *rhs, GATBool *isequal)
00275 {
00276   GATResult retval = GAT_INVALID_PARAMETER;
00277   if (NULL != isequal)
00278   {
00279     *isequal = GATTrue;
00280     retval = GAT_SUCCESS;
00281   }
00282   return retval;
00283 }
00284 
00285 
00286 /* CPI specific API functions */
00287 static GATResult
00288 resourcebroker_adaptor_ResourceBrokerCPI_ReserveResource_Description(
00289   void *data, GATResourceBrokerCPI_Instance const *instance_data, 
00290   GATResourceDescription_const description, GATTime_const time, 
00291   GATTimePeriod_const duration, GATReservation *reservation)
00292 {
00293   GATResult retval = GAT_NOTIMPL;
00294   return retval;
00295 }
00296 
00297 static GATResult
00298 resourcebroker_adaptor_ResourceBrokerCPI_ReserveResource(
00299   void *data, GATResourceBrokerCPI_Instance const *instance_data, 
00300   GATResource_const resource, GATTime_const time, GATTimePeriod_const duration, 
00301   GATReservation *reservation)
00302 {
00303   GATResult retval = GAT_NOTIMPL;
00304   return retval;
00305 }
00306 
00307 /** resourcebroker_adaptor_ResourceBrokerCPI_FindResources
00308  *  @brief Find a list of matching resources.
00309  *
00310  *  The function resourcebroker_adaptor_ResourceBrokerCPI_FindResources should
00311  *  try to find all resources matching the given description and it should 
00312  *  return the found resources as a list.
00313  *
00314  *  @param adaptor_data Adaptor-provided data object.
00315  *  @param instance_data The instance data of this CPI object
00316  *  @param description The description to match while searching for resources.
00317  *  @param resources The pointer to a variable receiving the resulting list of
00318  *        matching resources.
00319  *
00320  *  @return An error value.
00321  */
00322 static GATResult
00323 resourcebroker_adaptor_ResourceBrokerCPI_FindResources(void *adaptor_data, 
00324   GATResourceBrokerCPI_Instance const *instance_data, 
00325   GATResourceDescription_const description, GATList_GATResource *resources)
00326 {
00327   if (NULL != instance_data)
00328   {
00329     GAT_USES_STATUS(instance_data->context, 
00330       "resourcebroker_adaptor_ResourceBrokerCPI_FindResources");
00331     
00332     /* This adaptor can only return the local (hardware) resource, and only 
00333        if it exactly matches the requested resource */  
00334     if (NULL == description || NULL == resources)
00335     {
00336       GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00337     }
00338     else
00339     {
00340       GATResourceDescription rd = 
00341         resourcebroker_adaptor_CreateHardwareResourceDescription();
00342 
00343       if (NULL == rd) 
00344       {
00345         GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00346       }
00347       else
00348       {
00349         GATBool isequal = GATFalse;
00350         
00351         GAT_CREATE_STATUS(GATResourceDescription_Equals(description, rd, 
00352           &isequal));
00353         if (GATFalse == isequal)
00354         {
00355           GAT_CREATE_STATUS(GAT_NO_MATCHING_RESOURCE);
00356         }
00357         else
00358         {
00359           GATObject obj = NULL;
00360           GATResource resource = NULL;
00361           GATList_GATResource list = GATList_GATResource_Create();
00362 
00363           GAT_CREATE_STATUS_IF(NULL == list, GAT_MEMORYFAILURE);
00364           
00365           GAT_CREATE_STATUS(resourcebroker_adaptor_CreateResource(
00366             instance_data->context, rd, &resource));
00367           GAT_CREATE_STATUS_IF(NULL == GATList_GATResource_Insert(list, 
00368             GATList_GATResource_End(list), resource), GAT_MEMORYFAILURE);
00369           
00370           obj = GATResource_ToGATObject(resource);
00371           GATObject_Destroy(&obj);
00372           
00373           if (GAT_SUCCESS == GAT_CURRENT_STATUS())
00374           {
00375             *resources = list;
00376           }
00377           else
00378           {
00379             GATList_GATResource_Destroy(&list);
00380           }
00381         }
00382         GATResourceDescription_Destroy(&rd);
00383       }
00384     }
00385     return GAT_RETURN_STATUS();
00386   }
00387   return GAT_INVALID_HANDLE;
00388 }
00389 
00390 /** resourcebroker_adaptor_ResourceBrokerCPI_SubmitJob
00391  *
00392  *  The function resourcebroker_adaptor_ResourceBrokerCPI_SubmitJob should 
00393  *  submit a new job to the resource described by the given job description.
00394  *
00395  *  @param adaptor_data Adaptor-provided data object.
00396  *  @param instance_data The instance data of this CPI object
00397  *  @param description The job description containing the information about the
00398  *        job iteslf and the resource to use.
00399  *  @param job The pointer to a variable receiving the resulting GATJob object
00400  *        handle.
00401  *
00402  *  @return An error value.
00403  */
00404 static GATResult
00405 resourcebroker_adaptor_ResourceBrokerCPI_SubmitJob(void *adaptor_data, 
00406   GATResourceBrokerCPI_Instance const *instance_data, 
00407   GATJobDescription_const jd, GATJob *job)
00408 {
00409   if (NULL != instance_data)
00410   {
00411     GAT_USES_STATUS(instance_data->context, 
00412       "resourcebroker_adaptor_ResourceBrokerCPI_SubmitJob");
00413     
00414     if (NULL != jd && NULL != job)
00415     {
00416       GATResourceDescription_const rd = 
00417         GATJobDescription_GetResourceDescription(jd);
00418       
00419       *job = NULL;
00420       if (NULL == rd)
00421       {
00422         /* the job description already contains the resource to use for job 
00423            submission */
00424         GATResource_const resource = GATJobDescription_GetResource(jd);
00425         if (NULL != resource)
00426         {
00427           /* submit job to the given resource */
00428           GAT_CREATE_STATUS(resourcebroker_adaptor_SubmitJob(
00429             instance_data->context, instance_data->vo_name, resource, jd, job));
00430         }
00431         else
00432         {
00433           /* invalid job description (no resource and no resource description) */
00434           GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00435         }
00436       }
00437       else 
00438       {
00439         /* find a matching resource */
00440         GATList_GATResource resources = NULL;
00441         
00442         GAT_CREATE_STATUS(
00443           resourcebroker_adaptor_ResourceBrokerCPI_FindResources(adaptor_data, 
00444             instance_data, rd, &resources));
00445           
00446         /* submit job to the first resource found */
00447         if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()))
00448         {
00449           /* use the first resource from the list */
00450           GATList_GATResource_Iterator first = 
00451             GATList_GATResource_Begin(resources);
00452           GATResource_const *resource = GATList_GATResource_Get(first);
00453 
00454           if (NULL != first && NULL != resource)
00455           {
00456             GAT_CREATE_STATUS(resourcebroker_adaptor_SubmitJob(
00457               instance_data->context, instance_data->vo_name, *resource, jd, 
00458               job));
00459           }
00460           else 
00461           {
00462             /* no matching resource found */
00463             GAT_CREATE_STATUS(GAT_NO_MATCHING_RESOURCE);
00464           }
00465           
00466           GATList_GATResource_Destroy(&resources);
00467         }      
00468       }
00469     }
00470     else
00471     {
00472       GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00473     }
00474     return GAT_RETURN_STATUS();
00475   }
00476   return GAT_INVALID_HANDLE;
00477 }
00478 
00479 
00480 /* local helper routines */
00481 
00482 /** resourcebroker_adaptor_CreateResource
00483  *
00484  *  The function resourcebroker_adaptor_CreateResource creates a new 
00485  *  GATResource for the given resource description (which should match the 
00486  *  local hardware).
00487  *
00488  *  @param context The GATContext to use for creation of the GATResource.
00489  *  @param rd The resource description matching the local hardware.
00490  *  @param resource The pointer to the variable, which receives the resulting 
00491  *        GATResource.
00492  *
00493  *  @return An error code.
00494  */
00495 GATResult
00496 resourcebroker_adaptor_CreateResource(GATContext context, 
00497   GATResourceDescription rd, GATResource *resource)
00498 {
00499   GAT_USES_STATUS(context, "resourcebroker_adaptor_CreateResource");
00500   
00501   if (NULL != resource)
00502   {
00503     GATHardwareResource new_resource = NULL;
00504     GATResourceCPIInstance_Data *instance_data =  
00505       GATResourceCPIInstance_Data_Create(rd);
00506     
00507     GAT_CREATE_STATUS_IF(NULL == instance_data, GAT_MEMORYFAILURE);
00508     if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()))
00509     {
00510       GATPreferences prefs = NULL;
00511       
00512       GAT_CREATE_STATUS(resourcebroker_adaptor_MyPreferences(context, &prefs));
00513 
00514       new_resource = GATHardwareResource_Create(context, prefs, instance_data);
00515       GAT_CREATE_STATUS_IF(NULL == new_resource, GAT_MEMORYFAILURE);
00516 
00517       GATPreferences_Destroy(&prefs);
00518     }
00519     GATResourceCPIInstance_Data_Destroy(&instance_data);    
00520     
00521     if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()))
00522     {
00523       *resource = GATHardwareResource_ToGATResource(new_resource);
00524     }
00525     else
00526     {
00527       *resource = NULL;
00528       GATHardwareResource_Destroy(&new_resource);
00529     }
00530   }
00531   else
00532   {
00533     GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00534   }
00535       
00536   return GAT_RETURN_STATUS();
00537 }
00538 
00539 /* submit a job to the given resource */
00540 static GATResult
00541 resourcebroker_adaptor_SubmitJob(GATContext context, GATString_const vo_name,
00542   GATResource_const resource, GATJobDescription_const jd, GATJob *job)
00543 {
00544   GAT_USES_STATUS(context, "resourcebroker_adaptor_SubmitJob");
00545   
00546   /* extract the host name, where to submit the job to */
00547   GATResourceDescription_const rd = NULL;
00548   GAT_CREATE_STATUS(GATResource_GetResourceDescription(
00549     GATResource_ToGATObject_const(resource), &rd));
00550   
00551   if (GATType_GATHardwareResourceDescription == 
00552       GATResourceDescription_GetType(rd))
00553   {
00554     GATHardwareResourceDescription_const hrd = 
00555       GATResourceDescription_ToGATHardwareResourceDescription_const(rd);
00556     GATTable_const attributes = 
00557       GATHardwareResourceDescription_GetDescription(hrd);
00558 
00559     char buffer[256];
00560     int len = GATTable_Get_String(attributes, "machine.node", buffer, 
00561       sizeof(buffer));
00562     struct utsname sysinfo;
00563 
00564     /* query for the system information */
00565     if ((uname(&sysinfo) >= 0) && (0 < len) && 
00566         !strcmp(buffer, sysinfo.nodename))
00567     {
00568       GATJobCPIInstance_Data *instance_data = 
00569         GATJobCPIInstance_Data_Create(jd, resource, GATFalse);
00570 
00571       GAT_CREATE_STATUS_IF(NULL == instance_data, GAT_MEMORYFAILURE);
00572       if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()))
00573       {
00574         GATString jobid = NULL;
00575         GATPreferences preferences = NULL;
00576         
00577         GAT_CREATE_STATUS(resourcebroker_adaptor_MyPreferences(context, 
00578           &preferences));
00579         GAT_CREATE_STATUS(resourcebroker_adaptor_make_sample_jobid(vo_name, 
00580           &jobid));
00581         
00582         if (GAT_SUCCEEDED(GAT_CURRENT_STATUS()))
00583         {
00584           GATJob new_job = GATJob_Create(context, preferences, jobid, 
00585             instance_data);
00586           if (NULL == new_job)
00587           {
00588             GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00589           }
00590           else
00591           {
00592             *job = new_job;
00593           }
00594         }
00595 
00596         GATPreferences_Destroy(&preferences);
00597         GATString_Destroy(&jobid);
00598         GATJobCPIInstance_Data_Destroy(&instance_data);
00599       }
00600     }
00601     else
00602     {
00603       /* currently we support job submission to the local host only */
00604       GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00605     }
00606   }
00607   else
00608   {
00609     /* currently we support only hardware resource descriptions 
00610        (hey it's a sample!) */
00611     GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00612   }
00613   return GAT_RETURN_STATUS();
00614 }
00615 
00616 /** resourcebroker_adaptor_MyPreferences
00617  *
00618  *  
00619  */
00620 GATResult 
00621 resourcebroker_adaptor_MyPreferences(GATContext context, GATPreferences *prefs)
00622 {
00623   GAT_USES_STATUS(context, "resourcebroker_adaptor_MyPreferences");
00624   
00625   if (NULL != prefs)
00626   {
00627     GATPreferences preferences = GATPreferences_Create();
00628     if(NULL != preferences)
00629     {
00630       GAT_CREATE_STATUS(GATPreferences_Add(preferences, "Name", 
00631         "resourcebroker_adaptor"));
00632       GAT_CREATE_STATUS(GATPreferences_Add(preferences, "Security", "none"));
00633       GAT_CREATE_STATUS(GATPreferences_Add(preferences, "Local", "true"));
00634       
00635       *prefs = preferences;
00636     }
00637     else
00638     {
00639       GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00640     }
00641   }
00642   else
00643   {
00644     GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00645   }
00646   return GAT_RETURN_STATUS();
00647 }
00648 
00649 /* create a sample RMS jobID */
00650 GATResult
00651 resourcebroker_adaptor_make_sample_jobid(GATString_const vo_name,
00652   GATString *new_job_id)
00653 {
00654   GATResult retval = GAT_MEMORYFAILURE;
00655   GATString local_vo_name = NULL;
00656 
00657   if (NULL == vo_name)
00658   {
00659     local_vo_name = GATString_Create("", 1, "ASCII");
00660   }  
00661   if (NULL != vo_name || NULL != local_vo_name)
00662   {
00663     GATString jobid = NULL;
00664     char jobid_string[64] = { 0 };  /* should suffice for a signed 64 bit integer */
00665     sprintf(jobid_string, "%d", getpid());
00666     
00667     jobid = GATString_Create(jobid_string, (GATuint32)strlen(jobid_string)+1, 
00668       "ASCII");
00669     
00670     if (NULL != jobid)
00671     {
00672       GATString unique_jobid = NULL;
00673       retval = GATString_Concatenate(NULL != vo_name ? vo_name : local_vo_name, 
00674         jobid, &unique_jobid);
00675       if (GAT_SUCCEEDED(retval))
00676       {
00677         GATString_Destroy(&jobid);
00678         jobid = unique_jobid;
00679       }
00680     }
00681     else
00682     {
00683       retval = GAT_MEMORYFAILURE;
00684     }
00685     
00686     if (GAT_SUCCEEDED(retval))
00687     {
00688       if (NULL != new_job_id)
00689       {
00690         *new_job_id = jobid;
00691       }
00692       else
00693       {
00694         GATString_Destroy(&jobid);
00695         retval = GAT_INVALID_PARAMETER;
00696       }
00697     }
00698     else
00699     {
00700       GATString_Destroy(&jobid);
00701     }
00702   }
00703   
00704   GATString_Destroy(&local_vo_name);
00705   return retval;
00706 }
00707 
00708 
00709 /* create a hardware resource description describing the existing job 
00710    environment */
00711 GATResourceDescription
00712 resourcebroker_adaptor_CreateHardwareResourceDescription(void)
00713 {
00714   GATHardwareResourceDescription hw_desc = NULL;
00715   struct utsname sysinfo;
00716 
00717   /* create and fill the requirements table */
00718   GATTable requirements = GATTable_Create();
00719   assert(NULL != requirements);
00720   
00721   /* query for the system information */
00722   assert(uname(&sysinfo) >= 0);
00723   
00724   /* add required OS parameters to the requirements table */
00725   GATTable_Add_float(requirements, "memory.size", 0.256f);
00726   GATTable_Add_String(requirements, "machine.type", sysinfo.machine);
00727   GATTable_Add_String(requirements, "machine.node", sysinfo.nodename);
00728   GATTable_Add_String(requirements, "cpu.type", "unknown");
00729   GATTable_Add_float(requirements, "cpu.speed", 1.f);
00730   GATTable_Add_float(requirements, "disk.size", 10.f);
00731 
00732   /* create the software Resource description */
00733   hw_desc = GATHardwareResourceDescription_Create(requirements);
00734   assert(NULL != hw_desc);
00735 
00736   GATTable_Destroy(&requirements);
00737   return GATHardwareResourceDescription_ToGATResourceDescription(hw_desc);
00738 }
00739