Below are more simple examples.
#include "globus_common.h" #include "globus_gass_server_ez.h" #include <iostream> #include "itso_cb.h" ITSO_CB callback; //invoked when client wants to shutdown the server void callback_c_function() { callback.setDone(); } main() { // Never forget to activate GLOBUS module globus_module_activate(GLOBUS_GASS_SERVER_EZ_MODULE); // let s define options for our GASS server unsigned long server_ez_opts=0UL; //Files openfor writing will be written a line at a time //so multiple writers can access them safely. server_ez_opts |= GLOBUS_GASS_SERVER_EZ_LINE_BUFFER; //URLs that have ~ character, will be expanded to the home //directory of the user who is running the server server_ez_opts |= GLOBUS_GASS_SERVER_EZ_TILDE_EXPAND; //URLs that have ~user character, will be expanded to the home //directory of the user on the server machine server_ez_opts |= GLOBUS_GASS_SERVER_EZ_TILDE_USER_EXPAND; //"get" requests will be fullfilled server_ez_opts |= GLOBUS_GASS_SERVER_EZ_READ_ENABLE; //"put" requests will be fullfilled server_ez_opts |= GLOBUS_GASS_SERVER_EZ_WRITE_ENABLE; // for put requets on /dev/stdout will be redirected to the standard // output stream of the gass server server_ez_opts |= GLOBUS_GASS_SERVER_EZ_STDOUT_ENABLE; // for put requets on /dev/stderr will be redirected to the standard // output stream of the gass server server_ez_opts |= GLOBUS_GASS_SERVER_EZ_STDERR_ENABLE; // "put requests" to the URL https://host/dev/globus_gass_client_shutdown // will cause the callback function to be called. this allows // the GASS client to communicate shutdown requests to the server server_ez_opts |= GLOBUS_GASS_SERVER_EZ_CLIENT_SHUTDOWN_ENABLE; // Secure char* scheme="https"; //unsecure //char* scheme="http"; globus_gass_transfer_listenerattr_t attr; globus_gass_transfer_listenerattr_init(&attr, scheme); //we want to listen on post 10000 globus_gass_transfer_listenerattr_set_port(&attr, 10000); //Now, we can start this gass server ! globus_gass_transfer_listener_t listener; globus_gass_transfer_requestattr_t * reqattr = GLOBUS_NULL; //purpose unknown int err = globus_gass_server_ez_init(&listener, &attr, scheme, GLOBUS_NULL, //purpose unknown server_ez_opts, callback_c_function); //or GLOBUS_NULL otherwise //GLOBUS_NULL); //or GLOBUS_NULL otherwise if((err != GLOBUS_SUCCESS)) { cerr << "Error: initializing GASS (" << err << ")" << endl; exit(1); } char * gass_server_url=globus_gass_transfer_listener_get_base_url(listener); cout << "we are listening on " << gass_server_url << endl; //wait until it is finished ! //that means that the "put requests" to the URL https://host/dev/globus_gass_client_shutdown //ITSO_CB implements the symchronization mechanism by using a mutex //and a condition variable callback.Wait(); // shutdown callback //stop everything globus_gass_server_ez_shutdown(listener); globus_module_deactivate(GLOBUS_GASS_SERVER_EZ_MODULE); }
Here is a quick example of how to check if your credentials are valid in a C or C++ program. These credentials are generated via the globus-proxy-init shell command.
#include "globus_gss_assist.h" #include <iostream> main() { gss_cred_id_t credential_handle = GSS_C_NO_CREDENTIAL; OM_uint32 major_status; OM_uint32 minor_status; major_status = globus_gss_assist_acquire_cred(&minor_status, GSS_C_INITIATE, /* or GSS_C_ACCEPT */ &credential_handle); if (major_status != GSS_S_COMPLETE) cout << "unable to authenticate !" << endl; else cout << "that s fine" << endl; }
Here is a small C example that provides a skeleton for submitting a job in a C program. The examples in this publication use the ITSO_GRAM_JOB C++ class, which is basically a C++ wrapper to this C skeleton.
#include <stdio.h> #include "globus_gram_client.h" #include <globus_gram_protocol_constants.h> /* It is the function used when the remote * Job Manager needs to contact your local program to inform it * about the status of the remote program. It is passed along * with the the job_request to the remote computer */ static void callback_func(void * user_callback_arg, char * job_contact, int state, int errorcode); /* Setting up the GRAM monitor. The monitor will stall * this program until the remote program is terminated, * either through failure or naturally. Without the monitor, * this program would submit the job, and end before the job * completed. The monitor works with a lock. Only one function * may access the Done flag at a time, so in order to access it, * the gram must set a lock on the monitor variable, so that * nothing else may access it, then change it, and finally * unlock it. This is seen later in the code. */ /* This whole structure is the monitor */ typedef struct { globus_mutex_t mutex; globus_cond_t cond; globus_bool_t done; } my_monitor_t; /*************************************************** Main Code ***************************************************/ int main(int argc, char ** argv) { int callback_fd; int job_state_mask; int rc; /* The return value of the request function. * If successful, it should be 0 */ char * callback_contact; /* This is the identifier for * the callback, returned by * globus_gram_job_request */ char * job_contact; /* This is the identifier for the job, * returned by globus_gram_job_request */ char * rm_contact; char * specification; globus_bool_t done; my_monitor_t Monitor; /* Retrieve relevant parameters from the command line */ if (argc!= 3 && argc != 4 && argc != 5) { /* invalid parameters passed */ printf("Usage: %s <rm_contact> <specification> " "<job_state_mask> <-debug> ", argv[0]); exit(1); } if ((rc = globus_module_activate(GLOBUS_GRAM_CLIENT_MODULE)) != GLOBUS_SUCCESS) { printf(" ERROR: gram module activation failed "); exit(1); } rm_contact = (char *)globus_malloc(strlen(argv[1])+1); strcpy(rm_contact, argv[1]); specification = (char *)globus_malloc(strlen(argv[2])+1); strcpy(specification, argv[2]); if (argc > 3) job_state_mask = atoi(argv[3]); else job_state_mask = GLOBUS_GRAM_PROTOCOL_JOB_STATE_ALL; /* Initialize the monitor function to look for callbacks. It * initializes the locking mechanism, and then the condition * variable */ globus_mutex_init(&Monitor.mutex, (globus_mutexattr_t *) NULL); globus_cond_init(&Monitor.cond, (globus_condattr_t *) NULL); /* entering the monitor and clearing the flag. Locking the * Monitor to prevent anything else from changing the value of * Monitor.done */ globus_mutex_lock(&Monitor.mutex); /* Change the value of Monitor.done to false, initializing it */ Monitor.done = GLOBUS_FALSE; /* Releasing the lock on the monitor, letting anything else access it */ globus_mutex_unlock(&Monitor.mutex); /* Setting up the communications port for returning the callback. * You pass it the callback function. The callback_contact is the * callback identifier returned by the function */ globus_gram_client_callback_allow(callback_func, (void *) &Monitor, &callback_contact); printf(" TEST: submitting to resource manager... "); /* Send the GRAM request. The rm_contact, specification, and * job_state_mask were retrieved earlier from the command line * The callback_contact was just returned by * globus_gram_client_callback_allow. The job_request is returned by * this function */ rc = globus_gram_client_job_request(rm_contact, specification, job_state_mask, callback_contact, &job_contact); if (rc != 0) /* if there is an error */ { printf("TEST: gram error: %d - %s ", rc, /* translate the error into english */ globus_gram_client_error_string(rc)); exit(1); } #ifdef CANCEL sleep(3); printf(" TEST: sending cancel to job manager... "); if ((rc = globus_gram_client_job_cancel(job_contact)) != 0) { printf(" TEST: Failed to cancel job. "); printf(" TEST: gram error: %d - %s ", rc, globus_gram_client_error_string(rc)); return(1); } else { printf(" TEST: job cancel was successful. "); } #endif /* Wait until there is a callback saying there was a termination, either * successful or failed. We lock the Monitor again so as to ensure that * no one else tampers with it. Then we wait until the condition is * signaled by the callback_function. When it is signaled, and * Monitor.done is set to GRAM_TRUE - (these two things always happen * in conjunction in our callback_func) Then we unlock the monitor and * continue the program. */ globus_mutex_lock(&Monitor.mutex); while (!Monitor.done) { /* Within the cond_wait function, it unlocks the monitor, * allowing the callback_func to take the lock. When it gets a * cond_signal, it re-locks the monitor, and returns to this * program. But DO NOT unlock the monitor yourself- use the * globus_gram_cond_wait function, as it insures safe * unlocking. */ globus_cond_wait(&Monitor.cond, &Monitor.mutex); } /* endwhile */ globus_mutex_unlock(&Monitor.mutex); /* Remove Monitor. Given that we are done with our monitor, (it has * already held the program until the job completed) we can now dispose * of it. We destroy both the mutex and the condition. This frees up any * space it may have occupied. */ globus_mutex_destroy(&Monitor.mutex); globus_cond_destroy(&Monitor.cond); /* Free up the resources of the job_contact, as the job is over, and * the contact is now useless. */ globus_gram_client_job_contact_free(job_contact); /* Deactivate GRAM */ globus_module_deactivate(GLOBUS_GRAM_CLIENT_MODULE); } /****************************************************************** * This is the callback function, as per the definition. We can write * whatever we want into the function, but remember that the * cond_signal must be triggered and Monitor.done must also be set to * true to exit the waiting loop in the main code. The function is called * from the job manager, which provides values for state and errorcode */ void callback_func(void * user_callback_arg, char * job_contact, int state, int errorcode) { my_monitor_t * Monitor = (my_monitor_t *) user_callback_arg; switch(state) { case GLOBUS_GRAM_PROTOCOL_JOB_STATE_PENDING: printf(" TEST: Got GLOBUS_GRAM_PROTOCOL_JOB_STATE_PENDING" " from job manager "); break; /* Reports state change to the user */ case GLOBUS_GRAM_PROTOCOL_JOB_STATE_ACTIVE: printf(" TEST: Got GLOBUS_GRAM_PROTOCOL_JOB_STATE_ACTIVE" " from job manager "); break; /* Reports state change to the user */ case GLOBUS_GRAM_PROTOCOL_JOB_STATE_FAILED: printf(" TEST: Got GLOBUS_GRAM_PROTOCOL_JOB_STATE_FAILED" " from job manager "); globus_mutex_lock(&Monitor->mutex); Monitor->done = GLOBUS_TRUE; globus_cond_signal(&Monitor->cond); globus_mutex_unlock(&Monitor->mutex); break; /* Reports state change to the user */ case GLOBUS_GRAM_PROTOCOL_JOB_STATE_DONE: printf(" TEST: Got GLOBUS_GRAM_PROTOCOL_JOB_STATE_DONE" " from job manager "); globus_mutex_lock(&Monitor->mutex); Monitor->done = GLOBUS_TRUE; globus_cond_signal(&Monitor->cond); globus_mutex_unlock(&Monitor->mutex); break; /* Reports state change to the user */ } }
3.144.123.155