source: trunk/pbs_drmaa/pbs_conn.c @ 76

Revision 76, 4.7 KB checked in by mmamonski, 12 years ago (diff)

Wrap PBS API in 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       
57pbsdrmaa_pbs_conn_t *
58pbsdrmaa_pbs_conn_new( pbsdrmaa_session_t *session, char *server )
59{
60        pbsdrmaa_pbs_conn_t *volatile self = NULL;
61
62        fsd_log_enter((""));
63
64        TRY
65          {
66                fsd_malloc(self, pbsdrmaa_pbs_conn_t );
67               
68                self->session = session;
69               
70                self->submit = pbsdrmaa_pbs_submit;
71                self->statjob = pbsdrmaa_pbs_statjob;
72                self->statjob_free = pbsdrmaa_pbs_statjob_free;
73                self->sigjob = pbsdrmaa_pbs_sigjob;
74                self->deljob = pbsdrmaa_pbs_deljob;
75                self->rlsjob = pbsdrmaa_pbs_rlsjob;
76                self->holdjob = pbsdrmaa_pbs_holdjob;
77
78                self->server = fsd_strdup(server);
79
80                self->connection_fd = -1;
81                self->last_usage = time(NULL);
82               
83                /*ignore SIGPIPE - otheriwse pbs_disconnect cause the program to exit */
84                signal(SIGPIPE, SIG_IGN);       
85
86                pbsdrmaa_pbs_reconnect_internal(self, false);
87          }
88        EXCEPT_DEFAULT
89          {
90                if( self != NULL)
91                  {
92                        fsd_free(self->server);
93                        fsd_free(self);
94
95                        if (self->connection_fd != -1)
96                                pbs_disconnect(self->connection_fd);
97                  }
98                       
99                fsd_exc_reraise();
100          }
101        END_TRY
102
103        fsd_log_return((""));
104
105        return self;
106}
107
108
109void
110pbsdrmaa_pbs_conn_destroy ( pbsdrmaa_pbs_conn_t * self )
111{
112        fsd_log_enter((""));
113        TRY
114        {
115                if(self != NULL)
116                {
117                        fsd_free(self->server);
118                        fsd_free(self);
119
120                        if (self->connection_fd != -1)
121                                pbs_disconnect(self->connection_fd);
122                }
123        }
124        EXCEPT_DEFAULT
125        {
126                fsd_exc_reraise();
127        }
128        END_TRY
129       
130        fsd_log_return((""));
131}
132
133char*
134pbsdrmaa_pbs_submit( pbsdrmaa_pbs_conn_t *self, struct attropl *attrib, char *script, char *destination )
135{
136
137
138}
139
140struct batch_status*
141pbsdrmaa_pbs_statjob( pbsdrmaa_pbs_conn_t *self,  char *job_id, struct attrl *attrib )
142{
143
144}
145
146void
147pbsdrmaa_pbs_statjob_free( pbsdrmaa_pbs_conn_t *self, struct batch_status* job_status )
148{
149
150
151}
152
153void
154pbsdrmaa_pbs_sigjob( pbsdrmaa_pbs_conn_t *self, char *job_id, char *signal )
155{
156
157
158}
159
160void
161pbsdrmaa_pbs_deljob( pbsdrmaa_pbs_conn_t *self, char *job_id )
162{
163
164}
165
166void
167pbsdrmaa_pbs_rlsjob( pbsdrmaa_pbs_conn_t *self, char *job_id )
168{
169
170
171}
172
173void
174pbsdrmaa_pbs_holdjob( pbsdrmaa_pbs_conn_t *self,  char *job_id )
175{
176
177}
178
179void
180pbsdrmaa_pbs_reconnect_internal( pbsdrmaa_pbs_conn_t *self, bool force_reconnect)
181{
182        int tries_left = self->session->max_retries_count;
183        int sleep_time = 1;
184
185
186        fsd_log_enter(("(%d)", self->connection_fd));
187
188        if ( self->connection_fd != -1 )
189          {
190                if (!force_reconnect)
191                  {
192                        fsd_log_return(("(%d)", self->connection_fd));
193                        return;
194                  }
195                else
196                 {
197                        pbs_disconnect(self->connection_fd);
198                        self->connection_fd = -1;
199                 }
200          }
201
202retry_connect: /* Life... */
203        self->connection_fd = pbs_connect( self->server );
204        fsd_log_info(( "pbs_connect(%s) =%d", self->server, self->connection_fd ));
205        if( self->connection_fd < 0 && tries_left-- )
206          {
207                sleep(sleep_time);
208                sleep_time *=2;
209                goto retry_connect;
210          }
211       
212        if( self->connection_fd < 0 )
213                pbsdrmaa_exc_raise_pbs( "pbs_connect" );
214       
215        fsd_log_return(("(%d)", self->connection_fd));
216}
217
Note: See TracBrowser for help on using the repository browser.