IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 12, 2015, 12:53:36 PM (12 years ago)
Author:
eugene
Message:

merging changes from ipp-pv3-20140717 (via branches/eam_branches/ipp-pv3-20140717-merge)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/ippTools/src/remotetool.c

    r37054 r37833  
    2121static bool listrunMode(pxConfig *config);
    2222static bool listcomponentMode(pxConfig *config);
     23
     24// list remoteRuns with all remoteComponents in state 'prep_done' or 'prep_fail'
     25static bool doneprepMode(pxConfig *config);
    2326
    2427// Update
     
    2629static bool updaterunMode(pxConfig *config);
    2730static bool updatepollMode(pxConfig *config);
     31static bool updatecomponentMode(pxConfig *config);
    2832static bool revertrunMode(pxConfig *config);
    2933static bool revertauthMode(pxConfig *config);
     34static bool revertcomponentMode(pxConfig *config);
    3035
    3136# define MODECASE(caseName, func) \
     
    4752
    4853  switch (config->mode) {
    49     MODECASE(REMOTETOOL_MODE_DEFINEBYQUERY, definebyqueryMode);
    50     MODECASE(REMOTETOOL_MODE_LISTRUN,       listrunMode);
    51     MODECASE(REMOTETOOL_MODE_LISTCOMPONENT, listcomponentMode);
    52     MODECASE(REMOTETOOL_MODE_DROPCOMPONENT, dropcomponentMode);
    53     MODECASE(REMOTETOOL_MODE_UPDATERUN,     updaterunMode);
    54     MODECASE(REMOTETOOL_MODE_UPDATEPOLL,    updatepollMode);
    55     MODECASE(REMOTETOOL_MODE_REVERTRUN,     revertrunMode);
    56     MODECASE(REMOTETOOL_MODE_REVERTAUTH,    revertauthMode);
     54    MODECASE(REMOTETOOL_MODE_DEFINEBYQUERY,   definebyqueryMode);
     55    MODECASE(REMOTETOOL_MODE_LISTRUN,         listrunMode);
     56    MODECASE(REMOTETOOL_MODE_DONEPREP,         doneprepMode);
     57    MODECASE(REMOTETOOL_MODE_LISTCOMPONENT,   listcomponentMode);
     58    MODECASE(REMOTETOOL_MODE_DROPCOMPONENT,   dropcomponentMode);
     59    MODECASE(REMOTETOOL_MODE_UPDATERUN,       updaterunMode);
     60    MODECASE(REMOTETOOL_MODE_UPDATEPOLL,      updatepollMode);
     61    MODECASE(REMOTETOOL_MODE_UPDATECOMPONENT, updatecomponentMode);
     62    MODECASE(REMOTETOOL_MODE_REVERTRUN,       revertrunMode);
     63    MODECASE(REMOTETOOL_MODE_REVERTAUTH,      revertauthMode);
     64    MODECASE(REMOTETOOL_MODE_REVERTCOMPONENT, revertcomponentMode);
    5765
    5866  default:
     
    92100  PXOPT_LOOKUP_BOOL(simple,    config->args, "-simple",       false);
    93101  PXOPT_LOOKUP_BOOL(pretend,   config->args, "-pretend",      false);
    94  
     102
    95103  set_label = set_label ? set_label : label;
    96104
     
    105113      return(false);
    106114    }
    107    
     115
    108116    if (label) {
    109117      psStringAppend(&whereOption, "\n AND (label = '%s')", label);
     
    116124      return(false);
    117125    }
    118    
     126
    119127    if (label) {
    120128      psStringAppend(&whereOption, "\n AND (label = '%s')", label);
    121129    }
    122   }   
     130  }
    123131  else if (!strcmp(stage,"warp")) {
    124132    query = pxDataGet("remotetool_definebyquery_warp.sql");
     
    127135      return(false);
    128136    }
    129    
     137
    130138    if (label) {
    131139      // Because warp has to check to see if something other than the state is set correctly, I have to use this wonky way to pass the label in.
     
    133141      psStringAppend(&whereOption, "\n AND (label = '%s')", label);
    134142    }
    135   }   
     143  }
    136144  else if (!strcmp(stage,"stack")) {
    137145    query = pxDataGet("remotetool_definebyquery_stack.sql");
     
    140148      return(false);
    141149    }
    142    
     150
    143151    if (label) {
    144152      psStringAppend(&whereOption, "\n AND (label = '%s')", label);
    145153    }
    146   }   
     154  }
     155  else if (!strcmp(stage,"staticsky")) {
     156    query = pxDataGet("remotetool_definebyquery_staticsky.sql");
     157    if (!query) {
     158      psError(PXTOOLS_ERR_SYS,false, "failed to retreive SQL statement");
     159      return(false);
     160    }
     161
     162    if (label) {
     163      psStringAppend(&whereOption, "\n AND (label = '%s')", label);
     164    }
     165  }
    147166  else {
    148167    psError(PS_ERR_UNKNOWN, true, "unknown value for stage: %s", stage);
     
    191210  // Insert the top level run object
    192211  remoteRunRow *run = remoteRunRowAlloc(0, // remote_id
    193                                         "new", // state
    194                                         stage,
    195                                         set_label,
    196                                         path_base,
    197                                         -1, // job_id
    198                                         NULL, // last_poll
    199                                         0   // fault
    200                                           );
     212                                        "new", // state
     213                                        stage,
     214                                        set_label,
     215                                        path_base,
     216                                        -1, // job_id
     217                                        NULL, // last_poll
     218                                        0   // fault
     219                                          );
    201220  if (!run) {
    202     psError(PS_ERR_UNKNOWN, false, "failed to alloc lapRun object");
     221    psError(PS_ERR_UNKNOWN, false, "failed to alloc remoteRun object");
    203222    return(true);
    204223  }
    205  
     224
    206225  if (!remoteRunInsertObject(config->dbh, run)) {
    207226    if (!psDBRollback(config->dbh)) {
     
    213232  }
    214233  psS64 remote_id = psDBLastInsertID(config->dbh);
    215  
     234
    216235  psArray *list = psArrayAllocEmpty(limit);
    217236  for (long i=0; i < psArrayLength(output); i++) {
     
    219238    psS64 stage_id = psMetadataLookupS64(NULL, md, "stage_id");
    220239
    221     remoteComponentRow *comp = remoteComponentRowAlloc(remote_id,
    222                                                        stage_id);
     240    remoteComponentRow *comp = remoteComponentRowAlloc(remote_id, stage_id, 0, "new", NULL);
    223241    if (!comp) {
    224       psError(PS_ERR_UNKNOWN, false, "failed to alloc lapRun object");
     242      psError(PS_ERR_UNKNOWN, false, "failed to alloc remoteComponent object");
    225243      return(true);
    226244    }
    227    
     245
    228246    if (!remoteComponentInsertObject(config->dbh, comp)) {
    229247      if (!psDBRollback(config->dbh)) {
    230         psError(PS_ERR_UNKNOWN, false, "database error");
     248        psError(PS_ERR_UNKNOWN, false, "database error");
    231249      }
    232250      psError(PS_ERR_UNKNOWN, false, "database error");
     
    237255    psArrayAdd(list, list->n, comp);
    238256    psFree(comp);
    239    
     257
    240258  }
    241259  psFree(run);
     
    245263    return false;
    246264  }
    247  
     265
    248266  if (!remoteComponentPrintObjects(stdout, list, !simple)) {
    249267    if (!psDBRollback(config->dbh)) {
     
    254272    return false;
    255273  }
    256  
     274
    257275  psFree(list);
    258276  psFree(output);
    259                                        
     277
    260278  return true;
    261279}
     
    265283{
    266284  psMetadata *where = psMetadataAlloc();
    267  
     285
    268286  PXOPT_COPY_S64(config->args, where, "-remote_id", "remote_id", "==");
    269287  PXOPT_COPY_STR(config->args, where, "-state", "state", "==");
     
    274292  PXOPT_COPY_TIME(config->args, where, "-poll_begin", "last_poll", ">=");
    275293  PXOPT_COPY_TIME(config->args, where, "-poll_end", "last_poll", "<=");
    276  
     294
    277295  PXOPT_COPY_S16(config->args, where, "-fault", "fault", "==");
    278296
    279297  PXOPT_LOOKUP_S16(limit,   config->args, "-limit",  false, false);
    280298  PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    281  
    282299
    283300  psArray *remRuns = NULL;
    284301  remRuns = psDBSelectRows(config->dbh, "remoteRun", where, limit);
    285  
     302
    286303  if (!ippdbPrintMetadatas(stdout, remRuns, "remoteRun", !simple)) {
    287304    psError(PS_ERR_UNKNOWN, false, "failed to print array");
     
    299316
    300317  PXOPT_COPY_S64(config->args, where, "-remote_id", "remote_id", "==");
     318  PXOPT_COPY_S64(config->args, where, "-stage_id",  "stage_id",  "==");
     319  PXOPT_COPY_S64(config->args, where, "-jobs",      "jobs",      "==");
     320
     321  PXOPT_COPY_STR(config->args, where, "-state", "remoteComponent.state", "==");
     322  PXOPT_COPY_STR(config->args, where, "-label", "remoteRun.label", "==");
     323
    301324  PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
    302  
    303   psArray *remComps = NULL;
    304   remComps = psDBSelectRows(config->dbh, "remoteComponent", where, 0);
    305  
    306   if (!ippdbPrintMetadatas(stdout, remComps, "remoteComponent", !simple)) {
     325  PXOPT_LOOKUP_S16(limit,   config->args, "-limit",  false, false);
     326
     327  psString query = pxDataGet("remotetool_listcomponent.sql");
     328  if (!query) {
     329      psError(PXTOOLS_ERR_SYS,false, "failed to retreive SQL statement");
     330      return(false);
     331  }
     332
     333  if (psListLength(where->list)) {
     334      psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     335      psStringAppend(&query, " WHERE %s", whereClause);
     336      psFree(whereClause);
     337  }
     338  psFree(where);
     339
     340  if (limit) {
     341    psString limitString = psDBGenerateLimitSQL(limit);
     342    psStringAppend(&query, " %s", limitString);
     343    psFree(limitString);
     344  }
     345
     346  if (!p_psDBRunQuery(config->dbh, query)) {
     347      psError(PS_ERR_UNKNOWN, false, "database error");
     348      psFree(query);
     349      return false;
     350  }
     351  psFree(query);
     352
     353  psArray *output = p_psDBFetchResult(config->dbh);
     354  if (!output) {
     355      psError(PS_ERR_UNKNOWN, false, "database error");
     356      return false;
     357  }
     358  if (!psArrayLength(output)) {
     359    psTrace("remotetool", PS_LOG_INFO, "no rows found");
     360    psFree(output);
     361    return true;
     362  }
     363
     364  if (!ippdbPrintMetadatas(stdout, output, "remoteComponent", !simple)) {
    307365    psError(PS_ERR_UNKNOWN, false, "failed to print array");
    308     psFree(remComps);
    309     return false;
    310   }
    311   psFree(remComps);
     366    psFree(output);
     367    return false;
     368  }
     369  psFree(output);
    312370
    313371  return true;
    314372}
    315373
     374// List
     375static bool doneprepMode(pxConfig *config)
     376{
     377  psMetadata *where = psMetadataAlloc();
     378
     379  PXOPT_COPY_S64(config->args, where, "-remote_id", "remote_id", "==");
     380  PXOPT_COPY_S64(config->args, where, "-job_id", "job_id", "==");
     381
     382  PXOPT_COPY_STR(config->args, where, "-stage",  "stage",  "==");
     383  PXOPT_COPY_STR(config->args, where, "-state", "remoteRun.state", "==");
     384  PXOPT_COPY_STR(config->args, where, "-label",  "label",  "==");
     385
     386  PXOPT_LOOKUP_S16(limit,   config->args, "-limit",  false, false);
     387  PXOPT_LOOKUP_BOOL(simple, config->args, "-simple", false);
     388
     389  psString query = pxDataGet("remotetool_doneprep.sql");
     390  if (!query) {
     391      psError(PXTOOLS_ERR_SYS,false, "failed to retreive SQL statement");
     392      return(false);
     393  }
     394
     395  psString whereDone = NULL;
     396  psString whereJobs = NULL;
     397  if (psListLength(where->list)) {
     398      psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
     399      psStringAppend(&whereDone, " \n AND %s", whereClause);
     400      psStringAppend(&whereJobs, " \n WHERE %s", whereClause);
     401      psFree(whereClause);
     402  }
     403
     404  if (limit) {
     405    psString limitString = psDBGenerateLimitSQL(limit);
     406    psStringAppend(&query, " %s", limitString);
     407    psFree(limitString);
     408  }
     409
     410  // fprintf (stderr, "query: %s\n", query);
     411  // fprintf (stderr, "whereDone: %s\n", whereDone);
     412  // fprintf (stderr, "whereJobs: %s\n", whereJobs);
     413
     414  if (!p_psDBRunQueryF(config->dbh, query, whereDone, whereJobs)) {
     415      psError(PS_ERR_UNKNOWN, false, "database error");
     416      psFree(whereDone);
     417      psFree(whereJobs);
     418      psFree(query);
     419      return false;
     420  }
     421  psFree(whereDone);
     422  psFree(whereJobs);
     423  psFree(query);
     424
     425  psArray *output = p_psDBFetchResult(config->dbh);
     426  if (!output) {
     427      psError(PS_ERR_UNKNOWN, false, "database error");
     428      return false;
     429  }
     430  if (!psArrayLength(output)) {
     431    psTrace("remotetool", PS_LOG_INFO, "no rows found");
     432    psFree(output);
     433    return true;
     434  }
     435
     436  if (!ippdbPrintMetadatas(stdout, output, "remoteRun", !simple)) {
     437    psError(PS_ERR_UNKNOWN, false, "failed to print array");
     438    psFree(output);
     439    return false;
     440  }
     441  psFree(output);
     442
     443  return true;
     444}
     445
    316446// Update
    317447
    318448static bool dropcomponentMode(pxConfig *config)
    319449{
     450  fprintf (stderr, "do we really want to use -dropcomponent?\n");
     451  exit (1);
     452
    320453  // Assert that we have a unique component to operate on.
    321454  PXOPT_LOOKUP_S64(remote_id,config->args, "-remote_id",true, false);
     
    329462    return false;
    330463  }
    331  
     464
    332465  if (!psDBTransaction(config->dbh)) {
    333466    psError(PS_ERR_UNKNOWN, false, "database error");
     
    341474  }
    342475  psFree(query);
    343  
    344  
    345476
    346477  // point of no return
     
    349480    return false;
    350481  }
    351  
     482
    352483  return true;
    353484}
     
    364495  // Wheres
    365496  PXOPT_COPY_S64(config->args, where, "-remote_id", "remote_id", "==");
    366  
     497
    367498  // Values to set
    368499  PXOPT_COPY_STR(config->args, values, "-set_label", "label", "==");
     
    374505  psFree(values);
    375506
    376   if (rows < 1) {
    377     psError(PS_ERR_UNKNOWN,false, "no rows affected");
    378     return(false);
    379   }
    380  
     507  if (rows < 1) fprintf (stderr, "no rows changed (run may already be in desired state)\n");
    381508  return(true);
    382509}
     
    393520  psString whereClause = psDBGenerateWhereConditionSQL(where, NULL);
    394521  psFree(where);
    395  
     522
    396523  psString query = NULL;
    397524  query = pxDataGet("remotetool_updatepoll.sql");
     
    412539  return(true);
    413540}
    414  
    415 
    416  
     541
     542static bool updatecomponentMode(pxConfig *config)
     543{
     544  PS_ASSERT_PTR_NON_NULL(config, false);
     545  PXOPT_LOOKUP_S64(remote_id,  config->args, "-remote_id",    true, false);
     546  psAssert(remote_id,"This should have failed before this point.");
     547
     548  psMetadata *where = psMetadataAlloc();
     549  psMetadata *values = psMetadataAlloc();
     550
     551  // Wheres
     552  PXOPT_COPY_S64(config->args, where, "-remote_id", "remote_id", "==");
     553  PXOPT_COPY_S64(config->args, where, "-stage_id",  "stage_id",  "==");
     554  PXOPT_COPY_STR(config->args, where, "-state",     "state",     "==");
     555
     556  // Values to set
     557  PXOPT_COPY_S32(config->args, values, "-set_jobs",      "jobs",      "==");
     558  PXOPT_COPY_STR(config->args, values, "-set_path_base", "path_base", "==");
     559  PXOPT_COPY_STR(config->args, values, "-set_state", "state", "==");
     560
     561  long rows = psDBUpdateRows(config->dbh, "remoteComponent", where, values);
     562  psFree(values);
     563
     564  if (rows < 1) fprintf (stderr, "no rows changed (component may already be in desired state)\n");
     565  return true;
     566}
    417567
    418568static bool revertrunMode(pxConfig *config)
     
    426576  PXOPT_COPY_S64(config->args, where, "-remote_id", "remote_id", "==");
    427577  PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
    428  
     578  PXOPT_COPY_S16(config->args, where, "-fault", "fault", "==");
    429579  // Value to set
    430   PXOPT_COPY_S16(config->args, values, "-fault", "fault", "==");
    431   long rows = psDBUpdateRows(config->dbh, "remoteRun", where, values);
    432   psFree(values);
    433   psFree(where);
    434   if (rows < 1) {
    435     psError(PS_ERR_UNKNOWN,false, "no rows affected");
    436     return(false);
    437   }
    438 
    439   return(true);
    440 }
    441 
    442 static bool revertauthMode(pxConfig *config)
    443 {
    444   PS_ASSERT_PTR_NON_NULL(config, false);
    445 
    446   psMetadata *where = psMetadataAlloc();
    447   psMetadata *values = psMetadataAlloc();
    448 
    449   // required
    450   PXOPT_COPY_S64(config->args, where, "-remote_id", "remote_id", "==");
    451   PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
    452 
    453   psMetadataAddStr(where, PS_LIST_TAIL, "state", 0, "==", "auth");
    454 
    455   // Value to set
    456   psMetadataAddStr(values, PS_LIST_TAIL, "state", 0, "==", "run");
     580  psMetadataAddS16(values,PS_LIST_TAIL,"fault",0, "==", 0);
    457581 
    458582  long rows = psDBUpdateRows(config->dbh, "remoteRun", where, values);
     
    466590  return(true);
    467591}
    468    
     592
     593static bool revertcomponentMode(pxConfig *config)
     594{
     595  PS_ASSERT_PTR_NON_NULL(config,false);
     596  psMetadata *where = psMetadataAlloc();
     597  psMetadata *values = psMetadataAlloc();
     598
     599  // required
     600  PXOPT_COPY_S64(config->args, where, "-remote_id", "remote_id", "==");
     601  PXOPT_COPY_S64(config->args, where, "-stage_id", "stage_id", "==");
     602  psMetadataAddStr(where,PS_LIST_TAIL,"state",0, "LIKE", "%fail");
     603 
     604  // value to set
     605  psMetadataAddStr(values, PS_LIST_TAIL, "state",0, "==", "retry");
     606 
     607
     608  long rows = psDBUpdateRows(config->dbh, "remoteComponent", where, values);
     609  psFree(values);
     610  psFree(where);
     611  if (rows < 1) {
     612    psError(PS_ERR_UNKNOWN,false, "no rows affected");
     613    return(false);
     614  }
     615
     616  return(true);
     617}
     618 
     619 
     620
     621static bool revertauthMode(pxConfig *config)
     622{
     623  PS_ASSERT_PTR_NON_NULL(config, false);
     624
     625  psMetadata *where = psMetadataAlloc();
     626  psMetadata *values = psMetadataAlloc();
     627
     628  // required
     629  PXOPT_COPY_S64(config->args, where, "-remote_id", "remote_id", "==");
     630  PXOPT_COPY_STR(config->args, where, "-label", "label", "==");
     631
     632  psMetadataAddStr(where, PS_LIST_TAIL, "state", 0, "==", "auth");
     633
     634  // Value to set
     635  psMetadataAddStr(values, PS_LIST_TAIL, "state", 0, "==", "run");
     636
     637  long rows = psDBUpdateRows(config->dbh, "remoteRun", where, values);
     638  psFree(values);
     639  psFree(where);
     640  if (rows < 1) {
     641    psError(PS_ERR_UNKNOWN,false, "no rows affected");
     642    return(false);
     643  }
     644
     645  return(true);
     646}
     647
Note: See TracChangeset for help on using the changeset viewer.