GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



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

resourcesubsystem_tests.c

Go to the documentation of this file.
00001 /** @file resourcesubsystem_tests.c
00002  *  Source file for the resourcesubsystem tests.
00003  *
00004  *  This tests examines the resourcebroker_adaptor functionality.
00005  *
00006  *  @date Fri Oct 24 2003
00007  *
00008  *  @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/test/simple/resourcesubsystem_tests.c,v 1.14 2004/04/26 12:29:08 hartmutkaiser Exp $
00009  *
00010  *  Copyright (C) Hartmut Kaiser
00011  *  This file is part of the GAT Engine.
00012  *  Contributed by Hartmut Kaiser <hartmutkaiser [at] t-online [dot] de>.
00013  *
00014  *  Use, modification and distribution is subject to the Gridlab Software
00015  *  License. (See accompanying file GLlicense.txt or copy at
00016  *  http://www.gridlab.org/GLlicense.txt)
00017  */
00018 
00019 static const char *rcsid = "$Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/test/simple/resourcesubsystem_tests.c,v 1.14 2004/04/26 12:29:08 hartmutkaiser Exp $";
00020  
00021 /* System Header Files */
00022 #include <stdio.h>
00023 #include <stdlib.h>
00024 #include <string.h>
00025 #include <sys/utsname.h>
00026 
00027 /* GAT Header Files */
00028 #include "GAT.h"
00029 #include <GATTestUtils.h>
00030 
00031 /* Macros */
00032 
00033 /* Structures, unions and enums */
00034 
00035 /* Static function prototypes */
00036 static GATSoftwareDescription
00037   create_software_description(const char* exe, int nargs, const char** args);
00038 
00039 static GATResourceDescription
00040   create_hardware_resource_description(void);
00041 
00042 /* File scope variables */
00043 
00044 /* External functions */
00045 int main (void)
00046 {
00047   char*  exe   = strdup ("/bin/date");
00048   int    nargs = 0;
00049   char** args  = NULL;
00050 
00051 //  GATBool isequal = GATFalse;
00052   GATResult retval = GAT_FAIL;
00053   GATContext context = NULL;
00054   GATResourceBroker broker = NULL;
00055   GATJob job1 = NULL;
00056   GATJob job2 = NULL;
00057   GATSoftwareDescription sd = NULL;
00058   GATResourceDescription hrd = NULL;
00059   
00060   GAT_TEST_INIT  (-1);
00061   GAT_TEST_SUITE ("Resource subsystem")
00062 
00063   context = GATContext_Create();
00064   GAT_TEST(NULL != context);
00065   
00066   /* the following test makes sure, that there were no errors during the 
00067      creation of the GATContext object */
00068   GAT_TEST_TRACE(GATType_GATContext == GATContext_GetType(context), context);
00069 
00070   /* ask for the job object, which represent this executable */
00071   {
00072     GATJob self_job = NULL;
00073     GATJobID_const jobid = NULL;
00074     
00075     GAT_TEST_START ("self job tests (resource description)");
00076 
00077     retval = GATSelf_GetJob(context, &self_job);
00078     GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00079     
00080     retval = GATJob_GetJobID(self_job, &jobid);
00081     GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00082     
00083     /* The GAT jobid of this executable is taken from the environment.*/
00084     GAT_TEST_TRACE(NULL != jobid && !strcmp(GATString_GetBuffer(jobid), getenv("GAT_JOBID")), context);
00085     
00086     GATJob_Destroy(&self_job);
00087 
00088     GAT_TEST_STOP ();
00089   }
00090 
00091   /* submit the job to the resource broker */
00092   broker = GATResourceBroker_Create(context, 0, 0);
00093   GAT_TEST(NULL != broker);
00094   
00095   /* create the software description of the job to start */
00096   sd = create_software_description(exe, nargs, args);
00097   GAT_TEST_TRACE(NULL != sd, context);
00098 
00099   /* create a hardware resource description describing the required job 
00100      environment */
00101   hrd = create_hardware_resource_description();
00102   GAT_TEST_TRACE(NULL != hrd, context);
00103 
00104   /* test job submission through a resource description */
00105   {
00106     GATJobID_const jobid = NULL;
00107     
00108     /* make a job description out of the software and hardware resource 
00109        description */
00110     GATJobDescription jd = NULL;
00111 
00112     GAT_TEST_START ("submit job to broker (resource description)");
00113 
00114     jd = GATJobDescription_Create_Description(context, sd, hrd);
00115     GAT_TEST_TRACE(NULL != jd, context);
00116     
00117     /* submit a new job */
00118     GAT_TEST_TRACE(NULL != broker, context);
00119 
00120     retval = GATResourceBroker_SubmitJob(broker, jd, &job1);
00121     GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00122 
00123     /* retrieve the GAT job id of the newly created job */
00124     retval = GATJob_GetJobID(job1, &jobid);
00125     GAT_TEST_TRACE(GAT_SUCCEEDED(retval) && NULL != jobid, context);
00126     
00127     /* clean up memory */
00128     GATJobDescription_Destroy(&jd);
00129     
00130     GAT_TEST_STOP ();
00131   }
00132   
00133   /* test job submission on a specified resource */
00134   {
00135     GATJobID_const jobid = NULL;
00136     GATList_GATResource_Iterator first = NULL;
00137     GATResource_const *resource = NULL;
00138     GATJobDescription jd = NULL;
00139 
00140     /* find a matching resource */
00141     GATList_GATResource resources = NULL;
00142 
00143     GAT_TEST_START ("submit job to broker (specific resource)");
00144 
00145     retval = GATResourceBroker_FindResources(broker, hrd, &resources);
00146     GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00147 
00148     /* make a job description out of the software resource description and
00149         the given resource */
00150     first = GATList_GATResource_Begin(resources);
00151     GAT_TEST_TRACE(NULL != first, context);
00152 
00153     resource = GATList_GATResource_Get(first);
00154     GAT_TEST_TRACE(NULL != resource, context);
00155 
00156     jd = GATJobDescription_Create(context, sd, *resource);
00157     GAT_TEST_TRACE(NULL != jd, context);
00158 
00159     /* submit a new job */
00160     retval = GATResourceBroker_SubmitJob(broker, jd, &job2);
00161     GAT_TEST_TRACE(GAT_SUCCEEDED(retval), context);
00162 
00163     /* retrieve the GAT job id of the newly created job */
00164     retval = GATJob_GetJobID(job2, &jobid);
00165     GAT_TEST_TRACE(GAT_SUCCEEDED(retval) && NULL != jobid, context);
00166     
00167     /* clean up memory */
00168     GATList_GATResource_Destroy(&resources);
00169     GATJobDescription_Destroy(&jd);
00170 
00171     GAT_TEST_STOP ();
00172   }
00173   
00174   /* the two submitted jobs should be identical here */
00175 //  retval = GATJob_Equals(job1, job2, &isequal);
00176 //  GAT_TEST(GAT_SUCCEEDED(retval) && GATTrue == isequal);
00177 
00178 
00179   /* free up all allocated memory */
00180   GATJob_Destroy(&job1);
00181   GATJob_Destroy(&job2);
00182   GATResourceBroker_Destroy(&broker);
00183   GATResourceDescription_Destroy(&hrd);
00184   GATSoftwareDescription_Destroy(&sd);
00185   GATContext_Destroy(&context);
00186 
00187   GAT_TEST_FINISH ();
00188 
00189   free(exe);
00190   return 0;
00191 }
00192 
00193 /* Local functions */
00194 
00195 /* create a software description describing the job to start */
00196 static GATSoftwareDescription
00197 create_software_description(const char* exe, int nargs, const char** args)
00198 {
00199   GATSoftwareDescription sw_desc   = NULL;
00200   GATLocation            location  = NULL;
00201   GATList_String         arguments = NULL;
00202   int i = 0;
00203   GATTable attributes = NULL;
00204   
00205   GAT_TEST_START ("create software description");
00206   
00207   /* create and fill the attribute table */
00208   attributes = GATTable_Create ();
00209   GAT_TEST (NULL != attributes);
00210 
00211   /* create "location" attribute" */
00212   location = GATLocation_Create (exe);
00213   GAT_TEST (NULL != location);
00214   
00215   GATTable_Add_GATObject(attributes, "location", GATLocation_ToGATObject_const (location));    
00216   /* create and fill the "arguments" attribute */
00217   arguments = GATList_String_Create ();
00218   GAT_TEST (NULL != arguments);
00219 
00220   for (i = 0; i < nargs; ++i)
00221   {
00222     GATResult retval = (GATList_String_Insert(arguments, GATList_String_End(arguments), args[i]))
00223                ?  GAT_SUCCESS : GAT_MEMORYFAILURE;
00224 
00225     GAT_TEST (GAT_SUCCESS == retval);
00226   }
00227 
00228   GATTable_Add_GATObject(attributes, "arguments", 
00229     GATList_String_ToGATObject_const (arguments));
00230 
00231   /* create the software description object */
00232   sw_desc = GATSoftwareDescription_Create (attributes);
00233   GAT_TEST (NULL != sw_desc);
00234 
00235   /* free the allocated memory */
00236   GATList_String_Destroy (&arguments);
00237   GATLocation_Destroy    (&location);
00238   GATTable_Destroy       (&attributes);
00239 
00240   GAT_TEST_STOP ();
00241 
00242   return sw_desc;
00243 }
00244 
00245 /* create a hardware resource description describing the required job 
00246    environment */
00247 static GATResourceDescription 
00248 create_hardware_resource_description (void)
00249 {
00250   GATHardwareResourceDescription hw_desc = NULL;
00251   GATTable requirements = NULL;
00252   struct utsname sysinfo;
00253   
00254   GAT_TEST_START ("create hardware description");
00255 
00256   /* create and fill the requirements table */
00257   requirements = GATTable_Create ();
00258   GAT_TEST (NULL != requirements);
00259 
00260   /* query for the system information */
00261   GAT_TEST (uname (&sysinfo) >= 0);
00262   
00263   /* add required OS parameters to the requirements table */
00264   GATTable_Add_float  (requirements, "memory.size", 0.256f);
00265   GATTable_Add_String (requirements, "machine.type", sysinfo.machine);
00266   GATTable_Add_String (requirements, "machine.node", sysinfo.nodename);
00267   GATTable_Add_String (requirements, "cpu.type", "unknown");
00268   GATTable_Add_float  (requirements, "cpu.speed", 1.f);
00269   GATTable_Add_float  (requirements, "disk.size", 10.f);
00270 
00271   /* create the software Resource description */
00272   hw_desc = GATHardwareResourceDescription_Create(requirements);
00273   GAT_TEST (NULL != hw_desc);
00274 
00275   GATTable_Destroy (&requirements);
00276   
00277   GAT_TEST_STOP ();
00278   
00279   return (GATHardwareResourceDescription_ToGATResourceDescription (hw_desc));
00280 }
00281