[12] | 1 | /* $Id$ */ |
---|
[7] | 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 | |
---|
[76] | 33 | #include <pbs_drmaa/pbs_conn.h> |
---|
[7] | 34 | #include <pbs_drmaa/util.h> |
---|
| 35 | |
---|
| 36 | #include <errno.h> |
---|
[76] | 37 | #include <signal.h> |
---|
| 38 | #include <unistd.h> |
---|
[7] | 39 | |
---|
| 40 | |
---|
[76] | 41 | static char* pbsdrmaa_pbs_submit( pbsdrmaa_pbs_conn_t *self, struct attropl *attrib, char *script, char *destination ); |
---|
[7] | 42 | |
---|
[76] | 43 | static struct batch_status* pbsdrmaa_pbs_statjob( pbsdrmaa_pbs_conn_t *self, char *job_id, struct attrl *attrib ); |
---|
[7] | 44 | |
---|
[76] | 45 | static void pbsdrmaa_pbs_statjob_free( pbsdrmaa_pbs_conn_t *self, struct batch_status* job_status ); |
---|
[7] | 46 | |
---|
[76] | 47 | static void pbsdrmaa_pbs_sigjob( pbsdrmaa_pbs_conn_t *self, char *job_id, char *signal ); |
---|
[7] | 48 | |
---|
[76] | 49 | static void pbsdrmaa_pbs_deljob( pbsdrmaa_pbs_conn_t *self, char *job_id ); |
---|
[21] | 50 | |
---|
[76] | 51 | static void pbsdrmaa_pbs_rlsjob( pbsdrmaa_pbs_conn_t *self, char *job_id ); |
---|
[21] | 52 | |
---|
[76] | 53 | static void pbsdrmaa_pbs_holdjob( pbsdrmaa_pbs_conn_t *self, char *job_id ); |
---|
[48] | 54 | |
---|
[76] | 55 | static void pbsdrmaa_pbs_reconnect_internal( pbsdrmaa_pbs_conn_t *self, bool reconnect); |
---|
| 56 | |
---|
| 57 | pbsdrmaa_pbs_conn_t * |
---|
| 58 | pbsdrmaa_pbs_conn_new( pbsdrmaa_session_t *session, char *server ) |
---|
[7] | 59 | { |
---|
[76] | 60 | pbsdrmaa_pbs_conn_t *volatile self = NULL; |
---|
[7] | 61 | |
---|
| 62 | fsd_log_enter(("")); |
---|
[29] | 63 | |
---|
[7] | 64 | TRY |
---|
[76] | 65 | { |
---|
| 66 | fsd_malloc(self, pbsdrmaa_pbs_conn_t ); |
---|
[7] | 67 | |
---|
| 68 | self->session = session; |
---|
[76] | 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; |
---|
[29] | 77 | |
---|
[76] | 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 | } |
---|
[7] | 88 | EXCEPT_DEFAULT |
---|
[76] | 89 | { |
---|
[7] | 90 | if( self != NULL) |
---|
[76] | 91 | { |
---|
| 92 | fsd_free(self->server); |
---|
[7] | 93 | fsd_free(self); |
---|
[76] | 94 | |
---|
| 95 | if (self->connection_fd != -1) |
---|
| 96 | pbs_disconnect(self->connection_fd); |
---|
| 97 | } |
---|
[7] | 98 | |
---|
| 99 | fsd_exc_reraise(); |
---|
[76] | 100 | } |
---|
[7] | 101 | END_TRY |
---|
[29] | 102 | |
---|
[7] | 103 | fsd_log_return(("")); |
---|
[29] | 104 | |
---|
[7] | 105 | return self; |
---|
| 106 | } |
---|
| 107 | |
---|
[21] | 108 | |
---|
[7] | 109 | void |
---|
[76] | 110 | pbsdrmaa_pbs_conn_destroy ( pbsdrmaa_pbs_conn_t * self ) |
---|
[7] | 111 | { |
---|
| 112 | fsd_log_enter(("")); |
---|
| 113 | TRY |
---|
| 114 | { |
---|
| 115 | if(self != NULL) |
---|
| 116 | { |
---|
[76] | 117 | fsd_free(self->server); |
---|
[7] | 118 | fsd_free(self); |
---|
[76] | 119 | |
---|
| 120 | if (self->connection_fd != -1) |
---|
| 121 | pbs_disconnect(self->connection_fd); |
---|
[29] | 122 | } |
---|
[7] | 123 | } |
---|
| 124 | EXCEPT_DEFAULT |
---|
| 125 | { |
---|
| 126 | fsd_exc_reraise(); |
---|
| 127 | } |
---|
| 128 | END_TRY |
---|
| 129 | |
---|
| 130 | fsd_log_return(("")); |
---|
| 131 | } |
---|
| 132 | |
---|
[76] | 133 | char* |
---|
| 134 | pbsdrmaa_pbs_submit( pbsdrmaa_pbs_conn_t *self, struct attropl *attrib, char *script, char *destination ) |
---|
[7] | 135 | { |
---|
[8] | 136 | |
---|
[7] | 137 | |
---|
[76] | 138 | } |
---|
[7] | 139 | |
---|
[76] | 140 | struct batch_status* |
---|
| 141 | pbsdrmaa_pbs_statjob( pbsdrmaa_pbs_conn_t *self, char *job_id, struct attrl *attrib ) |
---|
| 142 | { |
---|
[7] | 143 | |
---|
[76] | 144 | } |
---|
[26] | 145 | |
---|
[76] | 146 | void |
---|
| 147 | pbsdrmaa_pbs_statjob_free( pbsdrmaa_pbs_conn_t *self, struct batch_status* job_status ) |
---|
| 148 | { |
---|
[31] | 149 | |
---|
[7] | 150 | |
---|
[76] | 151 | } |
---|
[25] | 152 | |
---|
[76] | 153 | void |
---|
| 154 | pbsdrmaa_pbs_sigjob( pbsdrmaa_pbs_conn_t *self, char *job_id, char *signal ) |
---|
| 155 | { |
---|
[30] | 156 | |
---|
[25] | 157 | |
---|
[76] | 158 | } |
---|
[30] | 159 | |
---|
[76] | 160 | void |
---|
| 161 | pbsdrmaa_pbs_deljob( pbsdrmaa_pbs_conn_t *self, char *job_id ) |
---|
| 162 | { |
---|
[30] | 163 | |
---|
[7] | 164 | } |
---|
| 165 | |
---|
[76] | 166 | void |
---|
| 167 | pbsdrmaa_pbs_rlsjob( pbsdrmaa_pbs_conn_t *self, char *job_id ) |
---|
[7] | 168 | { |
---|
| 169 | |
---|
[48] | 170 | |
---|
[7] | 171 | } |
---|
| 172 | |
---|
[76] | 173 | void |
---|
| 174 | pbsdrmaa_pbs_holdjob( pbsdrmaa_pbs_conn_t *self, char *job_id ) |
---|
[7] | 175 | { |
---|
| 176 | |
---|
| 177 | } |
---|
| 178 | |
---|
[76] | 179 | void |
---|
| 180 | pbsdrmaa_pbs_reconnect_internal( pbsdrmaa_pbs_conn_t *self, bool force_reconnect) |
---|
[7] | 181 | { |
---|
[76] | 182 | int tries_left = self->session->max_retries_count; |
---|
| 183 | int sleep_time = 1; |
---|
[34] | 184 | |
---|
| 185 | |
---|
[76] | 186 | fsd_log_enter(("(%d)", self->connection_fd)); |
---|
[34] | 187 | |
---|
[76] | 188 | if ( self->connection_fd != -1 ) |
---|
| 189 | { |
---|
| 190 | if (!force_reconnect) |
---|
| 191 | { |
---|
| 192 | fsd_log_return(("(%d)", self->connection_fd)); |
---|
| 193 | return; |
---|
| 194 | } |
---|
[34] | 195 | else |
---|
| 196 | { |
---|
[76] | 197 | pbs_disconnect(self->connection_fd); |
---|
| 198 | self->connection_fd = -1; |
---|
[34] | 199 | } |
---|
[76] | 200 | } |
---|
[34] | 201 | |
---|
[76] | 202 | retry_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 | } |
---|
[49] | 211 | |
---|
[76] | 212 | if( self->connection_fd < 0 ) |
---|
| 213 | pbsdrmaa_exc_raise_pbs( "pbs_connect" ); |
---|
| 214 | |
---|
| 215 | fsd_log_return(("(%d)", self->connection_fd)); |
---|
[48] | 216 | } |
---|
| 217 | |
---|