GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



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

resource.c

Go to the documentation of this file.
00001 /** @file resource.c
00002  *  Source file for the GATResourceCPI provider class for the 
00003  *  resourcebroker adaptor.
00004  *
00005  *  TODO: Fill in the description of the new CPI provider here
00006  *
00007  *  @date Wed Nov 19 2003
00008  *
00009  *  @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/adaptors/resourcebroker/resource.c,v 1.11 2004/04/27 11:34:50 hartmutkaiser Exp $
00010  *
00011  *  Copyright (C) Hartmut Kaiser
00012  *  This file is part of the GAT Engine.
00013  *  Contributed by Hartmut Kaiser <hartmutkaiser [at] t-online [dot] de>.
00014  *
00015  *  Use, modification and distribution is subject to the Gridlab Software
00016  *  License. (See accompanying file GLlicense.txt or copy at
00017  *  http://www.gridlab.org/GLlicense.txt)
00018  */
00019 
00020 static const char *rcsid = "$Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/adaptors/resourcebroker/resource.c,v 1.11 2004/04/27 11:34:50 hartmutkaiser Exp $";
00021  
00022 /* System Header Files */
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include <string.h>
00026 
00027 /* GAT Header Files */
00028 #include "GATCPI.h"
00029 
00030 #include "GATResourceCPIInstanceData.h"
00031 
00032 /* Macros */
00033 
00034 /* Structures, unions and enums */
00035 
00036 /* Static function prototypes */
00037 static void
00038 resourcebroker_adaptor_GATResourceCPI_Destroy(void *data);
00039 
00040 /* instance specific functions */
00041 static GATResult
00042 resourcebroker_adaptor_GATResourceCPI_ServiceActions(void *data, 
00043   GATResourceCPI_Instance *instance_data, GATTimePeriod_const timeout);
00044 
00045 static GATResult 
00046   resourcebroker_adaptor_GATResourceCPI_CreateInstance(
00047     void *data, GATResourceCPI_Instance *instance_data,
00048     void *initialisation_data);
00049 
00050 static void 
00051   resourcebroker_adaptor_GATResourceCPI_DestroyInstance(
00052     void *data, GATResourceCPI_Instance *instance_data);
00053 
00054 static GATResult 
00055   resourcebroker_adaptor_GATResourceCPI_CloneInstance(
00056     void *data, GATResourceCPI_Instance const *instance_data, 
00057     GATResourceCPI_Instance *new_instance_data);
00058 
00059 static GATResult 
00060   resourcebroker_adaptor_GATResourceCPI_EqualsInstance(
00061     void *data, GATResourceCPI_Instance const *lhs, 
00062     GATResourceCPI_Instance const *rhs, GATBool *isequal);
00063 
00064 /* Monitoring support */
00065 static GATResult 
00066   resourcebroker_adaptor_GATResourceCPI_GetMetrics(
00067     void *data, GATResourceCPI_Instance const *instance_data, 
00068     GATList_GATMetric *metrics);
00069 static GATResult 
00070   resourcebroker_adaptor_GATResourceCPI_GetMetricEvent(
00071     void *data, GATResourceCPI_Instance const *instance_data, 
00072     GATMetric metric, GATMetricEvent *event);
00073 
00074 /* Serialisation support */
00075 static GATResult 
00076 resourcebroker_adaptor_GATResourceCPI_Serialise(
00077   void *data, GATResourceCPI_Instance const *instance_data, 
00078   GATObject stream, GATBool clear_dirty);
00079 static GATResult 
00080 resourcebroker_adaptor_GATResourceCPI_DeSerialise(
00081   void *data, GATObject stream, 
00082   GATResourceCPI_Instance *instance_data);
00083 
00084 /* CPI API functionality */
00085 static GATResult
00086 resourcebroker_adaptor_GATResourceCPI_GetResourceDescription(
00087   void *data, GATResourceCPI_Instance const *instance_data, 
00088   GATResourceDescription_const *description);
00089 static GATResult
00090 resourcebroker_adaptor_GATResourceCPI_GetReservation(
00091   void *data, GATResourceCPI_Instance const *instance_data, 
00092   GATReservation_const *reservation);
00093 
00094 /* File scope variables */
00095 
00096 /* External functions */
00097 
00098 /* Register the CPI to implement */
00099 GATResult resourcebroker_adaptor_Register_GATResourceCPI(
00100   GATContext error_context, GATRegistry registry, 
00101   GATTable_const system_config, GATTable_const instance_config, void *token)
00102 {
00103   GAT_USES_STATUS(error_context, "resourcebroker_adaptor_Register_GATResourceCPI");
00104   
00105   GATResourceCPI cpi = NULL;
00106   GATResourceCPI_Data cpidata;
00107 
00108   {
00109     memset(&cpidata, 0, sizeof(GATResourceCPI_Data));
00110       
00111     /*
00112      *  provide the appropriate callback functions
00113      */
00114     cpidata.data = NULL;   /* no adaptor instance data */
00115     cpidata.destroy = resourcebroker_adaptor_GATResourceCPI_Destroy;
00116     
00117     /* instance data handling */
00118     cpidata.service_actions = resourcebroker_adaptor_GATResourceCPI_ServiceActions;
00119     cpidata.create_instance = resourcebroker_adaptor_GATResourceCPI_CreateInstance;
00120     cpidata.destroy_instance = resourcebroker_adaptor_GATResourceCPI_DestroyInstance;
00121     cpidata.clone_instance = resourcebroker_adaptor_GATResourceCPI_CloneInstance;
00122     cpidata.equals_instance = resourcebroker_adaptor_GATResourceCPI_EqualsInstance;
00123 
00124     /* monitoring support functions */
00125     cpidata.get_metrics = resourcebroker_adaptor_GATResourceCPI_GetMetrics;
00126     cpidata.get_metric_event = resourcebroker_adaptor_GATResourceCPI_GetMetricEvent;
00127     
00128     /* serialisation support functions */
00129     cpidata.serialise = resourcebroker_adaptor_GATResourceCPI_Serialise;
00130     cpidata.deserialise = resourcebroker_adaptor_GATResourceCPI_DeSerialise;
00131     
00132     /* CPI specific API functions */
00133     cpidata.get_resource_description = resourcebroker_adaptor_GATResourceCPI_GetResourceDescription;
00134     cpidata.get_reservation = resourcebroker_adaptor_GATResourceCPI_GetReservation;
00135   
00136     /* Create a GATResourceCPI object. */
00137     cpi = GATResourceCPI_Create(GATRESOURCECPI_VERSION, &cpidata);
00138     if(NULL != cpi)
00139     {
00140       /* Need to pass preferences to allow matching
00141        * of a user's preferences with what this adaptor does.
00142        */
00143       GATPreferences preferences = GATPreferences_Create();
00144       if(NULL != preferences)
00145       {
00146         GAT_CREATE_STATUS(GATPreferences_Add(preferences, "Name", 
00147           "resourcebroker_adaptor"));
00148         GAT_CREATE_STATUS(GATPreferences_Add(preferences, "Security", "none"));
00149         GAT_CREATE_STATUS(GATPreferences_Add(preferences, "Local", "true"));
00150         
00151         GAT_CREATE_STATUS(GATRegistry_AddGATResourceCPI(registry, cpi, token, 
00152           preferences));
00153         
00154         GATPreferences_Destroy(&preferences);
00155       }
00156       else
00157       {
00158         GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00159       }
00160     }
00161     else
00162     {
00163       GAT_CREATE_STATUS(GAT_MEMORYFAILURE);
00164     }
00165   }
00166 
00167   if (GAT_FAILED(GAT_CURRENT_STATUS()))
00168   {
00169     GATResourceCPI_Destroy(&cpi);
00170   }
00171 
00172   return GAT_RETURN_STATUS();
00173 }
00174 
00175 /* Local functions */
00176 
00177 static void
00178 resourcebroker_adaptor_GATResourceCPI_Destroy(void *data)
00179 {
00180   /* nothing to do here (no internal data allocated) */
00181   assert(NULL == data);
00182 }
00183 
00184 
00185 /* instance specific functions */
00186 
00187 /** resourcebroker_adaptor_GATResourceCPI_ServiceActions
00188  *  
00189  *  The function resourcebroker_adaptor_GATResourceCPI_ServiceActions is called, whenever
00190  *  the client calls GATContext_ServiceActions. This function is called for 
00191  *  every created object.
00192  *  This function should be used to update all instance specific data, which 
00193  *  may have been changed asynchronously or to fire pending events.
00194  *
00195  *  @param data Adaptor-provided data object.
00196  *  @param instance_data The instance data of this CPI object
00197  *  @param timeout This may be a 0 timeout to indicate no timeout at all, or
00198  *        a specific time length.
00199  *
00200  *  @return An error code.
00201  */
00202 static GATResult
00203 resourcebroker_adaptor_GATResourceCPI_ServiceActions(void *data, 
00204   GATResourceCPI_Instance *instance_data, GATTimePeriod_const timeout)
00205 {
00206   return GAT_NOTIMPL;
00207 }
00208 
00209 /** resourcebroker_adaptor_GATResourceCPI_CreateInstance
00210  *  Create a new CPI object instance.
00211  *  Adaptor implementation of create instance capability.
00212  *
00213  * @param data Adaptor-provided data object.
00214  * @param context The GATContext for this CPI instance
00215  * @param target The location of the file in question.
00216  * @param new_instance_data The pointer to the variable, where the instance 
00217  *      data of this CPI object is to be returned to.
00218  * 
00219  * @return An error code.
00220  */
00221 static GATResult 
00222 resourcebroker_adaptor_GATResourceCPI_CreateInstance(void *data, 
00223   GATResourceCPI_Instance *new_instance_data, void *initialisation_data)
00224 {
00225   if (NULL != new_instance_data)
00226   {
00227     GAT_USES_STATUS(new_instance_data->context, 
00228       "resourcebroker_adaptor_GATResourceCPI_CreateInstance");
00229 
00230     GAT_CREATE_STATUS(GATResourceCPIInstance_Data_Clone(
00231       (GATResourceCPIInstance_Data *) initialisation_data, 
00232       (GATResourceCPIInstance_Data **) &new_instance_data->instance_data));
00233     
00234     return GAT_RETURN_STATUS();
00235   }
00236   return GAT_INVALID_HANDLE;
00237 }
00238 
00239 /** resourcebroker_adaptor_GATResourceCPI_DestroyInstance
00240  *  Destroy a CPI object instance.
00241  *  Adaptor implementation of destroy instance capability.
00242  *
00243  * @param data Adaptor-provided data object.
00244  * @param instance_data The instance data of the CPI object to destroy.
00245  */
00246 static void
00247 resourcebroker_adaptor_GATResourceCPI_DestroyInstance(void *data, 
00248   GATResourceCPI_Instance *instance_data)
00249 {
00250   if (NULL != instance_data)
00251   {
00252     GATResourceCPIInstance_Data_Destroy(
00253       (GATResourceCPIInstance_Data **)&instance_data->instance_data);
00254   }
00255 }
00256 
00257 /** resourcebroker_adaptor_GATResourceCPI_CloneInstance
00258  *  Clone a CPI object instance.
00259  *  Adaptor implementation of the clone instance capability.
00260  *
00261  * @param data Adaptor-provided data object.
00262  * @param instance_data The instance data of this CPI object
00263  * @param new_instance_data The pointer to the variable, where the instance 
00264  *      data of the cloned CPI object is to be returned to.
00265  * 
00266  * @return An error code.
00267  */
00268 static GATResult 
00269 resourcebroker_adaptor_GATResourceCPI_CloneInstance(
00270   void *data, GATResourceCPI_Instance const *instance_data, 
00271   GATResourceCPI_Instance *new_instance_data)
00272 {
00273   if (NULL != instance_data)
00274   {
00275     GAT_USES_STATUS(instance_data->context, 
00276       "resourcebroker_adaptor_GATResourceCPI_CloneInstance");
00277     
00278     if (NULL != instance_data && NULL != new_instance_data)
00279     {
00280       GAT_CREATE_STATUS(GATResourceCPIInstance_Data_Clone(
00281         (GATResourceCPIInstance_Data const *) instance_data->instance_data, 
00282         (GATResourceCPIInstance_Data **) &new_instance_data->instance_data));
00283     }
00284     else
00285     {
00286       GAT_CREATE_STATUS(GAT_INVALID_PARAMETER);
00287     }
00288     return GAT_RETURN_STATUS();
00289   }
00290   return GAT_INVALID_HANDLE;
00291 }
00292 
00293 /** resourcebroker_adaptor_GATResourceCPI_EqualsInstance
00294  *  Clone a CPI object instance.
00295  *  Adaptor implementation of the clone instance capability.
00296  *
00297  * @param data Adaptor-provided data object.
00298  * @param lhs The instance data of the left CPI object.
00299  * @param lhs The instance data of the right CPI object.
00300  * @param isequal The pointer to the variable, where the result is to be 
00301  *        returned to.
00302  *
00303  * @return An error code.
00304  */
00305 static GATResult 
00306 resourcebroker_adaptor_GATResourceCPI_EqualsInstance(
00307   void *data, GATResourceCPI_Instance const *lhs, 
00308   GATResourceCPI_Instance const *rhs, GATBool *isequal)
00309 {
00310   if (NULL != lhs)
00311   {
00312     GAT_USES_STATUS(lhs->context, 
00313       "resourcebroker_adaptor_GATResourceCPI_CloneInstance");
00314 
00315     if (NULL != rhs)
00316     {
00317       GAT_CREATE_STATUS(GATResourceCPIInstance_Data_Equals(
00318         (GATResourceCPIInstance_Data const *) lhs->instance_data, 
00319         (GATResourceCPIInstance_Data *) rhs->instance_data, isequal));
00320     }
00321     else
00322     {
00323       GAT_CREATE_STATUS(GAT_INVALID_HANDLE);
00324     }
00325     
00326     return GAT_RETURN_STATUS();
00327   }
00328   return GAT_INVALID_HANDLE;
00329 }
00330 
00331 
00332 /* Monitoring support */
00333 
00334 /** resourcebroker_adaptor_GATResourceCPI_GetMetrics
00335  *
00336  *  The function resourcebroker_adaptor_GATResourceCPI_GetMetrics should return a 
00337  *  list of GATMetric objects supported by this adaptor. I.e. the adaptor is 
00338  *  capable to fire GATMetricEvents for the returned metrics. This list should 
00339  *  include all the supported metrics, event like and continuous ones.
00340  *
00341  *  @param data Adaptor-provided data object.
00342  *  @param instance_data Instance data for the CPI provider object.
00343  *  @param metrics The pointer to the variable, which receives the returned 
00344  *        list of metrics.
00345  *
00346  *  @return An error code.
00347  */
00348 static GATResult 
00349 resourcebroker_adaptor_GATResourceCPI_GetMetrics(void *data, 
00350   GATResourceCPI_Instance const *instance_data, GATList_GATMetric *metrics)
00351 {
00352   /* TODO: Add code to return a list of supported metrics here */
00353   GATResult retval = GAT_NOTIMPL;
00354   return retval;
00355 }
00356 
00357 /** resourcebroker_adaptor_GATResourceCPI_GetMetricEvent
00358  *
00359  *  The function resourcebroker_adaptor_GATResourceCPI_GetMetricEvent should 
00360  *  return the GATMetricEvent associated with the given continuous metric. This 
00361  *  function gets called for continuous metrics only, since returning the 
00362  *  metric event object to the caller is th only way for the client to get 
00363  *  access to it.
00364  *
00365  *  @param data Adaptor-provided data object.
00366  *  @param instance_data Instance data for the CPI provider object.
00367  *  @param metric The metric instance describing the metric event to return.
00368  *        This metric should be equivalent to one of the metrics returned by
00369  *        our own GetMetrics CPI function (see above). If this is another
00370  *        (not known to us metric), an error should be returned.
00371  *  @param event The pointer to the variable, which receives the metric event 
00372  *        to return.
00373  *
00374  *  @return An error code.
00375  */
00376 static GATResult 
00377 resourcebroker_adaptor_GATResourceCPI_GetMetricEvent(void *data, 
00378   GATResourceCPI_Instance const *instance_data, GATMetric metric, 
00379   GATMetricEvent *event)
00380 {
00381   GATResult retval = GAT_NOTIMPL;
00382   return retval;
00383 }
00384 
00385 
00386 /* Serialisation support */
00387 
00388 /** resourcebroker_adaptor_GATResourceCPI_Serialise
00389  *
00390  *  The function resourcebroker_adaptor_GATResourceCPI_Serialise is called by the 
00391  *  GAT engine, whenever the client requested a Serialise operation on the 
00392  *  corresponding object. The function should serialise into the given stream 
00393  *  all the instance specific data of the object.
00394  *
00395  *  @param data Adaptor-provided data object.
00396  *  @param instance_data The instance data of this CPI object.
00397  *  @param stream The GATSTream object to use for serialisation of the instance 
00398  *        data.
00399  *
00400  *  @return An error code
00401  */
00402 static GATResult 
00403 resourcebroker_adaptor_GATResourceCPI_Serialise(void *data, 
00404   GATResourceCPI_Instance const *instance_data, GATObject stream, 
00405   GATBool clear_dirty)
00406 {
00407   if (NULL != instance_data)
00408   {
00409     GAT_USES_STATUS(instance_data->context, 
00410       "resourcebroker_adaptor_GATResourceCPI_Serialise");
00411 
00412     GAT_CREATE_STATUS(GATResourceCPIInstance_Data_Serialize(
00413       (GATResourceCPIInstance_Data const *)instance_data->instance_data, stream,
00414       clear_dirty));
00415     
00416     return GAT_RETURN_STATUS();
00417   }
00418   return GAT_INVALID_HANDLE;
00419 }
00420 
00421 /** resourcebroker_adaptor_GATResourceCPI_DeSerialise
00422  *
00423  *  The function resourcebroker_adaptor_GATResourceCPI_DeSerialise is called by 
00424  *  the GATEngine, whenever the client requested a DeSerialise operation for
00425  *  a corresponding object. The function should deserialise all the instance 
00426  *  specific data of the object from the given stream.
00427  *
00428  *  @param data Adaptor-provided data object.
00429  *  @param stream The GATSTream object to use for de-serialisation of the 
00430  *        instance data.
00431  *  @param instance_data The instance data of this CPI object.
00432  *
00433  *  @return An error code
00434  */
00435 static GATResult 
00436 resourcebroker_adaptor_GATResourceCPI_DeSerialise(void *data, 
00437   GATObject stream, GATResourceCPI_Instance *instance_data)
00438 {
00439   if (NULL != instance_data)
00440   {
00441     GAT_USES_STATUS(instance_data->context, 
00442       "resourcebroker_adaptor_GATResourceCPI_DeSerialise");
00443 
00444     GAT_CREATE_STATUS(GATResourceCPIInstance_Data_DeSerialize(
00445       instance_data->context, stream,
00446       (GATResourceCPIInstance_Data **)&instance_data->instance_data));
00447     
00448     return GAT_RETURN_STATUS();
00449   }
00450   return GAT_INVALID_HANDLE;
00451 }
00452 
00453 
00454 /* CPI API functionality */
00455 
00456 /** resourcebroker_adaptor_GATResourceCPI_GetResourceDescription
00457  *
00458  *  
00459  */
00460 static GATResult
00461 resourcebroker_adaptor_GATResourceCPI_GetResourceDescription(
00462   void *data, GATResourceCPI_Instance const *instance_data, 
00463   GATResourceDescription_const *description)
00464 {
00465   if (NULL != instance_data)
00466   {
00467     GAT_USES_STATUS(instance_data->context, 
00468       "resourcebroker_adaptor_GATResourceCPI_GetResourceDescription");
00469 
00470     GAT_CREATE_STATUS(GATResourceCPIInstance_Data_GetResourceDescription(
00471       (GATResourceCPIInstance_Data const *)instance_data->instance_data,
00472       description));
00473     
00474     return GAT_RETURN_STATUS();
00475   }
00476   return GAT_INVALID_HANDLE;
00477 }
00478 
00479 static GATResult
00480 resourcebroker_adaptor_GATResourceCPI_GetReservation(
00481   void *data, GATResourceCPI_Instance const *instance_data, 
00482   GATReservation_const *reservation)
00483 {
00484   GATResult retval = GAT_NOTIMPL;
00485   return retval;
00486 }
00487