int main(int argc, char *argv[])
{
    char *                              callback_contact;
    char *                              job_contact;
    char *                              rm_contact;
    monitor_t                           monitor;
    int                                 rc = 0;

    LTDL_SET_PRELOADED_SYMBOLS();

    printf("1..1\n");
    rm_contact = getenv("CONTACT_STRING");

    if (argc == 2)
    {
        rm_contact = argv[1];
    }

    if (rm_contact == NULL)
    {
        fprintf(stderr, "Usage: %s resource-manager-contact\n", argv[0]);
        exit(1);
    }

    rc = globus_module_activate(GLOBUS_COMMON_MODULE);
    if(rc)
    {
        goto end;
    }
    rc = globus_module_activate(GLOBUS_GRAM_CLIENT_MODULE);
    if(rc)
    {
        goto disable_modules;
    }

    globus_mutex_init(&monitor.mutex ,GLOBUS_NULL);
    globus_cond_init(&monitor.cond, GLOBUS_NULL);
    monitor.state = GLOBUS_GRAM_PROTOCOL_JOB_STATE_PENDING;

    rc = globus_gram_client_callback_allow(gram_state_callback,
                                           &monitor,
                                           &callback_contact);
    if(rc != GLOBUS_SUCCESS)
    {
        fprintf(stderr,
                "Error creating callback contact %s.\n",
                globus_gram_client_error_string(rc));

        goto error_exit;
    }

    globus_mutex_lock(&monitor.mutex);
    rc = globus_gram_client_job_request(
            rm_contact,
            "&(executable=/bin/sleep)(arguments=300)",
            GLOBUS_GRAM_PROTOCOL_JOB_STATE_ALL,
            callback_contact,
            &job_contact);

    if(rc != GLOBUS_SUCCESS)
    {
        fprintf(stderr,
                "Error submitting job request %s.\n",
                globus_gram_client_error_string(rc));

        goto destroy_callback_contact;
    }

    while(monitor.state != GLOBUS_GRAM_PROTOCOL_JOB_STATE_ACTIVE &&
          monitor.state != GLOBUS_GRAM_PROTOCOL_JOB_STATE_FAILED &&
          monitor.state != GLOBUS_GRAM_PROTOCOL_JOB_STATE_DONE)
    {
        globus_cond_wait(&monitor.cond, &monitor.mutex);
    }

    if(monitor.state == GLOBUS_GRAM_PROTOCOL_JOB_STATE_ACTIVE)
    {
        rc = globus_gram_client_job_cancel(job_contact);
        if(rc != GLOBUS_SUCCESS)
        {
            fprintf(stderr,
                    "Error cancelling job %s.\n",
                    globus_gram_client_error_string(rc));

            goto destroy_callback_contact;
        }
    }

    while(monitor.state != GLOBUS_GRAM_PROTOCOL_JOB_STATE_DONE &&
          monitor.state != GLOBUS_GRAM_PROTOCOL_JOB_STATE_FAILED)
    {
        globus_cond_wait(&monitor.cond, &monitor.mutex);
    }
    rc = monitor.errorcode;
    if(rc == GLOBUS_GRAM_PROTOCOL_ERROR_USER_CANCELLED)
    {
        rc = GLOBUS_SUCCESS;
    }
destroy_callback_contact:
    globus_mutex_unlock(&monitor.mutex);
    globus_gram_client_callback_disallow(callback_contact);
    free(callback_contact);
    free(job_contact);
error_exit:
    globus_mutex_destroy(&monitor.mutex);
    globus_cond_destroy(&monitor.cond);
disable_modules:
    globus_module_deactivate_all();
end:
    printf("%s - cancel-test\n", rc == 0 ? "ok" : "not ok");
    return rc;
}
Ejemplo n.º 2
0
void gw_em_mad_state_callback(void *arg, char *job_contact, int job_state,
            int error_code )
{                              
    int jid = -1;
    int done = 0;

    jid = get_jid(job_contact);

    if (jid == -1)
    {
        return;
    }
 
    switch (job_state)
    {
        case GLOBUS_GRAM_PROTOCOL_JOB_STATE_PENDING:    
            printf("CALLBACK %d SUCCESS PENDING\n", jid);
            if (job_pool.cancel_state[jid] == 1)
            {
                globus_gram_client_job_cancel(job_contact);            
                job_pool.cancel_state[jid] = 0;
            }
        break;
        
        case GLOBUS_GRAM_PROTOCOL_JOB_STATE_SUSPENDED:
            printf("CALLBACK %d SUCCESS SUSPENDED\n", jid);
            if (job_pool.cancel_state[jid] == 1)
            {
                globus_gram_client_job_cancel(job_contact);            
                job_pool.cancel_state[jid] = 0;
            }
        break;
        
        case GLOBUS_GRAM_PROTOCOL_JOB_STATE_ACTIVE:
            printf("CALLBACK %d SUCCESS ACTIVE\n", jid);
            if (job_pool.cancel_state[jid] == 1)
            {
                globus_gram_client_job_cancel(job_contact);            
                job_pool.cancel_state[jid] = 0;
            }

        break;
        
        case GLOBUS_GRAM_PROTOCOL_JOB_STATE_FAILED:
            if (error_code == GLOBUS_GRAM_PROTOCOL_ERROR_USER_CANCELLED )
                printf("CALLBACK %d SUCCESS FAILED\n", jid);
            else
                printf("CALLBACK %d FAILURE %s (error %d)\n", jid,
                        globus_gram_client_error_string(error_code),
                        error_code);
            done = 1;            
            job_pool.cancel_state[jid] = 0;
                  
        break;
        
        case GLOBUS_GRAM_PROTOCOL_JOB_STATE_DONE:
            printf("CALLBACK %d SUCCESS DONE\n", jid);
            done = 1;
            job_pool.cancel_state[jid] = 0;            
        break;
    }

    if (done && (jid != -1))
        del_job(jid);
}
Ejemplo n.º 3
0
void gw_em_mad_state_callback(void *arg, const char *job_contact,
        globus_gram_client_job_info_t *job_info)
{                              
    globus_gram_protocol_extension_t *entry;
    int jid = -1;
    int done = 0;
    int job_state;

    jid = get_jid(job_contact);

    if (jid == -1)
    {
        return;
    }
 
    job_state = job_info->job_state;

    switch (job_state)
    {
        case GLOBUS_GRAM_PROTOCOL_JOB_STATE_PENDING:    
            printf("CALLBACK %d SUCCESS PENDING\n", jid);
            if (job_pool.cancel_state[jid] == 1)
            {
                globus_gram_client_job_cancel(job_contact);            
                job_pool.cancel_state[jid] = 0;
            }
        break;
        
        case GLOBUS_GRAM_PROTOCOL_JOB_STATE_SUSPENDED:
            printf("CALLBACK %d SUCCESS SUSPENDED\n", jid);
            if (job_pool.cancel_state[jid] == 1)
            {
                globus_gram_client_job_cancel(job_contact);            
                job_pool.cancel_state[jid] = 0;
            }
        break;
        
        case GLOBUS_GRAM_PROTOCOL_JOB_STATE_ACTIVE:
            printf("CALLBACK %d SUCCESS ACTIVE\n", jid);
            if (job_pool.cancel_state[jid] == 1)
            {
                globus_gram_client_job_cancel(job_contact);            
                job_pool.cancel_state[jid] = 0;
            }

        break;
        
        case GLOBUS_GRAM_PROTOCOL_JOB_STATE_FAILED:
            if (job_info->protocol_error_code == GLOBUS_GRAM_PROTOCOL_ERROR_USER_CANCELLED )
                printf("CALLBACK %d SUCCESS FAILED\n", jid);
            else
                printf("CALLBACK %d FAILURE %s (error %d)\n", jid,
                        globus_gram_client_error_string(job_info->protocol_error_code),
                        job_info->protocol_error_code);

            done = 1;            
            job_pool.cancel_state[jid] = 0;
                  
        break;
        
        case GLOBUS_GRAM_PROTOCOL_JOB_STATE_DONE:
            if (job_info->extensions)
            {
                entry = globus_hashtable_lookup(&job_info->extensions, "exit-code");

                if (entry != NULL)
                    printf("CALLBACK %d SUCCESS DONE:%s\n", jid, entry->value);
                else
                    printf("CALLBACK %d SUCCESS DONE\n", jid);
            }
            else
                printf("CALLBACK %d SUCCESS DONE\n", jid);

            done = 1;
            job_pool.cancel_state[jid] = 0;            
        break;
    }

    if (done && (jid != -1))
        del_job(jid);
}