source: trunk/pbs_drmaa/pbs_conn.c @ 83

Revision 83, 5.8 KB checked in by mmamonski, 11 years ago (diff)

PBS Sumbit API i single class

  • Property svn:keywords set to Id
Line 
1/* $Id$ */
2/*
3 *  FedStage DRMAA for PBS Pro
4 *  Copyright (C) 2006-2007  FedStage Systems
5 *
6 *  This program is free software: you can redistribute it and/or modify
7 *  it under the terms of the GNU General Public License as published by
8 *  the Free Software Foundation, either version 3 of the License, or
9 *  (at your option) any later version.
10 *
11 *  This program is distributed in the hope that it will be useful,
12 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 *  GNU General Public License for more details.
15 *
16 *  You should have received a copy of the GNU General Public License
17 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #ifdef HAVE_CONFIG_H
21#       include <config.h>
22#endif
23
24#include <pbs_error.h>
25
26#include <drmaa_utils/datetime.h>
27#include <drmaa_utils/drmaa.h>
28#include <drmaa_utils/iter.h>
29#include <drmaa_utils/conf.h>
30#include <drmaa_utils/session.h>
31#include <drmaa_utils/datetime.h>
32
33#include <pbs_drmaa/pbs_conn.h>
34#include <pbs_drmaa/util.h>
35
36#include <errno.h>
37#include <signal.h>
38#include <unistd.h>
39
40
41static char* pbsdrmaa_pbs_submit( pbsdrmaa_pbs_conn_t *self, struct attropl *attrib, char *script, char *destination );
42
43static struct batch_status* pbsdrmaa_pbs_statjob( pbsdrmaa_pbs_conn_t *self,  char *job_id, struct attrl *attrib );
44
45static void pbsdrmaa_pbs_statjob_free( pbsdrmaa_pbs_conn_t *self, struct batch_status* job_status );
46
47static void pbsdrmaa_pbs_sigjob( pbsdrmaa_pbs_conn_t *self, char *job_id, char *signal );
48
49static void pbsdrmaa_pbs_deljob( pbsdrmaa_pbs_conn_t *self,  char *job_id );
50
51static void pbsdrmaa_pbs_rlsjob( pbsdrmaa_pbs_conn_t *self, char *job_id );
52
53static void pbsdrmaa_pbs_holdjob( pbsdrmaa_pbs_conn_t *self,  char *job_id );
54
55static void pbsdrmaa_pbs_reconnect_internal( pbsdrmaa_pbs_conn_t *self, bool reconnect);
56
57static void pbsdrmaa_pbs_check_connect_internal( pbsdrmaa_pbs_conn_t *self, bool reconnect);
58
59#define IS_TRANSIENT_ERROR (pbs_errno == PBSE_PROTOCOL || pbs_errno == PBSE_EXPIRED || pbs_errno == PBSOLDE_PROTOCOL || pbs_errno == PBSOLDE_EXPIRED)
60
61       
62pbsdrmaa_pbs_conn_t *
63pbsdrmaa_pbs_conn_new( pbsdrmaa_session_t *session, char *server )
64{
65        pbsdrmaa_pbs_conn_t *volatile self = NULL;
66
67        fsd_log_enter((""));
68
69        TRY
70          {
71                fsd_malloc(self, pbsdrmaa_pbs_conn_t );
72               
73                self->session = session;
74               
75                self->submit = pbsdrmaa_pbs_submit;
76                self->statjob = pbsdrmaa_pbs_statjob;
77                self->statjob_free = pbsdrmaa_pbs_statjob_free;
78                self->sigjob = pbsdrmaa_pbs_sigjob;
79                self->deljob = pbsdrmaa_pbs_deljob;
80                self->rlsjob = pbsdrmaa_pbs_rlsjob;
81                self->holdjob = pbsdrmaa_pbs_holdjob;
82
83                self->server = fsd_strdup(server);
84
85                self->connection_fd = -1;
86                self->last_usage = time(NULL);
87
88                /*ignore SIGPIPE - otherwise pbs_disconnect cause the program to exit */
89                signal(SIGPIPE, SIG_IGN);       
90
91                pbsdrmaa_pbs_reconnect_internal(self, false);
92          }
93        EXCEPT_DEFAULT
94          {
95                if( self != NULL)
96                  {
97                        fsd_free(self->server);
98                        fsd_free(self);
99
100                        if (self->connection_fd != -1)
101                                pbs_disconnect(self->connection_fd);
102                  }
103                       
104                fsd_exc_reraise();
105          }
106        END_TRY
107
108        fsd_log_return((""));
109
110        return self;
111}
112
113
114void
115pbsdrmaa_pbs_conn_destroy ( pbsdrmaa_pbs_conn_t * self )
116{
117        fsd_log_enter((""));
118
119        TRY
120        {
121                if(self != NULL)
122                {
123                        fsd_free(self->server);
124                        fsd_free(self);
125
126                        if (self->connection_fd != -1)
127                                pbs_disconnect(self->connection_fd);
128                }
129        }
130        EXCEPT_DEFAULT
131        {
132                fsd_exc_reraise();
133        }
134        END_TRY
135       
136        fsd_log_return((""));
137}
138
139char*
140pbsdrmaa_pbs_submit( pbsdrmaa_pbs_conn_t *self, struct attropl *attrib, char *script, char *destination )
141{
142        char *volatile job_id = NULL;
143        volatile bool first_try = true;
144        volatile bool conn_lock = false;
145
146        fsd_log_enter((""));
147
148        TRY
149         {
150                conn_lock = fsd_mutex_lock(&self->session->super.drm_connection_mutex);
151
152                pbsdrmaa_pbs_reconnect_internal(self, false);
153
154retry:
155                job_id = pbs_submit(self->connection_fd, attrib, script, destination, NULL);
156
157                fsd_log_info(("pbs_submit(%s, %s) = %s", script, destination, job_id));
158
159                if(job_id == NULL)
160                 {
161                        fsd_log_error(( "pbs_submit failed, pbs_errno = %d", pbs_errno ));
162                        if (IS_TRANSIENT_ERROR && first_try)
163                         {
164                                pbsdrmaa_pbs_reconnect_internal(self, true);
165                                first_try = false;
166                                goto retry;
167                         }
168                        else
169                         {
170                                pbsdrmaa_exc_raise_pbs( "pbs_submit");
171                         }
172                 }
173         }
174        EXCEPT_DEFAULT
175         {
176                fsd_free(job_id);
177                fsd_exc_reraise();
178         }
179        FINALLY
180         {
181                if(conn_lock)
182                        conn_lock = fsd_mutex_unlock(&self->session->super.drm_connection_mutex);
183         }
184        END_TRY
185
186
187        fsd_log_return(("%s", job_id));
188
189        return job_id;
190}
191
192struct batch_status*
193pbsdrmaa_pbs_statjob( pbsdrmaa_pbs_conn_t *self,  char *job_id, struct attrl *attrib )
194{
195
196}
197
198void
199pbsdrmaa_pbs_statjob_free( pbsdrmaa_pbs_conn_t *self, struct batch_status* job_status )
200{
201
202
203}
204
205void
206pbsdrmaa_pbs_sigjob( pbsdrmaa_pbs_conn_t *self, char *job_id, char *signal )
207{
208
209
210}
211
212void
213pbsdrmaa_pbs_deljob( pbsdrmaa_pbs_conn_t *self, char *job_id )
214{
215
216}
217
218void
219pbsdrmaa_pbs_rlsjob( pbsdrmaa_pbs_conn_t *self, char *job_id )
220{
221
222
223}
224
225void
226pbsdrmaa_pbs_holdjob( pbsdrmaa_pbs_conn_t *self,  char *job_id )
227{
228
229}
230
231void
232pbsdrmaa_pbs_reconnect_internal( pbsdrmaa_pbs_conn_t *self, bool force_reconnect)
233{
234        int tries_left = self->session->max_retries_count;
235        int sleep_time = 1;
236
237        fsd_log_enter(("(%d)", self->connection_fd));
238
239        if ( self->connection_fd != -1 )
240          {
241                if (!force_reconnect)
242                  {
243                        fsd_log_return(("(%d)", self->connection_fd));
244                        return;
245                  }
246                else
247                 {
248                        pbs_disconnect(self->connection_fd);
249                        self->connection_fd = -1;
250                 }
251          }
252
253retry_connect: /* Life... */
254        self->connection_fd = pbs_connect( self->server );
255        fsd_log_info(( "pbs_connect(%s) =%d", self->server, self->connection_fd ));
256        if( self->connection_fd < 0 && tries_left-- )
257          {
258                sleep(sleep_time);
259                sleep_time *=2;
260                goto retry_connect;
261          }
262       
263        if( self->connection_fd < 0 )
264                pbsdrmaa_exc_raise_pbs( "pbs_connect" );
265       
266        fsd_log_return(("(%d)", self->connection_fd));
267}
268
Note: See TracBrowser for help on using the repository browser.