00001
00002
00003
00004
00005
00006
00007
00008
00009 #include "collInfoMS.h"
00010 #include "eraUtil.h"
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052 int
00053 msiIsColl(msParam_t *targetPath, msParam_t *collId, msParam_t *status, ruleExecInfo_t *rei)
00054 {
00055 char *targetPathStr;
00056 rodsLong_t coll_id;
00057
00058
00059
00060
00061 RE_TEST_MACRO (" Calling msiIsColl")
00062
00063
00064
00065 if (rei == NULL || rei->rsComm == NULL) {
00066 rodsLog (LOG_ERROR, "msiIsColl: input rei or rsComm is NULL.");
00067 return (SYS_INTERNAL_NULL_INPUT_ERR);
00068 }
00069
00070
00071
00072 if (!targetPath)
00073 {
00074 rei->status = USER__NULL_INPUT_ERR;
00075 rodsLog (LOG_ERROR, "msiIsColl: input targetPath error. status = %d", rei->status);
00076 return (rei->status);
00077 }
00078
00079
00080
00081 targetPathStr = (char *) targetPath->inOutStruct;
00082 if ( !targetPathStr || !strlen(targetPathStr) || strlen(targetPathStr) > MAX_NAME_LEN )
00083 {
00084 rei->status = USER_INPUT_PATH_ERR;
00085 rodsLog (LOG_ERROR, "msiIsColl: input targetPath error. status = %d", rei->status);
00086 return (rei->status);
00087 }
00088
00089
00090
00091 rei->status = isColl (rei->rsComm, targetPathStr, &coll_id);
00092
00093
00094
00095 if (rei->status == CAT_NO_ROWS_FOUND)
00096 {
00097 coll_id = 0;
00098 rei->status = 0;
00099 }
00100
00101
00102 fillIntInMsParam (collId, (int)coll_id);
00103 fillIntInMsParam (status, rei->status);
00104
00105
00106 return rei->status;
00107 }
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147 int
00148 msiIsData(msParam_t *targetPath, msParam_t *dataId, msParam_t *status, ruleExecInfo_t *rei)
00149 {
00150 char *targetPathStr;
00151 rodsLong_t data_id;
00152
00153 char id_str[LONG_NAME_LEN];
00154
00155
00156
00157
00158 RE_TEST_MACRO (" Calling msiIsData")
00159
00160
00161
00162 if (rei == NULL || rei->rsComm == NULL) {
00163 rodsLog (LOG_ERROR, "msiIsData: input rei or rsComm is NULL.");
00164 return (SYS_INTERNAL_NULL_INPUT_ERR);
00165 }
00166
00167
00168
00169 if (!targetPath)
00170 {
00171 rei->status = USER__NULL_INPUT_ERR;
00172 rodsLog (LOG_ERROR, "msiIsData: input targetPath error. status = %d", rei->status);
00173 return (rei->status);
00174 }
00175
00176
00177
00178 targetPathStr = (char *) targetPath->inOutStruct;
00179 if ( !targetPathStr || !strlen(targetPathStr) || strlen(targetPathStr) > MAX_NAME_LEN )
00180 {
00181 rei->status = USER_INPUT_PATH_ERR;
00182 rodsLog (LOG_ERROR, "msiIsData: input targetPath error. status = %d", rei->status);
00183 return (rei->status);
00184 }
00185
00186
00187
00188 rei->status = isData (rei->rsComm, targetPathStr, &data_id);
00189
00190
00191
00192 if (rei->status == CAT_NO_ROWS_FOUND)
00193 {
00194 data_id = 0;
00195 rei->status = 0;
00196 }
00197
00198
00199
00200
00201 snprintf(id_str, LONG_NAME_LEN, "%d", (int)data_id);
00202 fillStrInMsParam (dataId, id_str);
00203
00204
00205
00206
00207
00208 fillIntInMsParam (status, rei->status);
00209
00210
00211 return rei->status;
00212 }
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248 int
00249 msiGetObjectPath(msParam_t *object, msParam_t *path, msParam_t *status, ruleExecInfo_t *rei)
00250 {
00251 dataObjInp_t dataObjInpCache, *dataObjInp;
00252
00253
00254
00255 RE_TEST_MACRO (" Calling msiGetObjectPath")
00256
00257
00258
00259 if (rei == NULL || rei->rsComm == NULL)
00260 {
00261 rodsLog (LOG_ERROR, "msiGetObjectPath: input rei or rsComm is NULL.");
00262 return (SYS_INTERNAL_NULL_INPUT_ERR);
00263 }
00264
00265
00266 rei->status = parseMspForDataObjInp (object, &dataObjInpCache, &dataObjInp, 0);
00267 if (rei->status < 0)
00268 {
00269 rodsLog (LOG_ERROR, "msiGetObjectPath: input error, status = %d", rei->status);
00270 return (rei->status);
00271 }
00272
00273
00274 fillStrInMsParam (path, dataObjInp->objPath);
00275
00276
00277 fillIntInMsParam (status, rei->status);
00278 return (rei->status);
00279 }
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292
00293
00294
00295
00296
00297
00298
00299
00300
00301
00302
00303
00304
00305
00306
00307
00308
00309
00310
00311
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321 int
00322 msiGetCollectionContentsReport(msParam_t *inpParam1, msParam_t *inpParam2, msParam_t *outParam, ruleExecInfo_t *rei)
00323 {
00324 collInp_t collInpCache, *outCollInp;
00325
00326 keyValPair_t *contents;
00327
00328 char collQCond[2*MAX_NAME_LEN];
00329 genQueryInp_t genQueryInp;
00330 genQueryOut_t *genQueryOut;
00331
00332 char *resultStringToken;
00333 char *oldValStr, newValStr[21];
00334 rodsLong_t newVal;
00335 sqlResult_t *sqlResult;
00336 int i;
00337
00338
00339 RE_TEST_MACRO (" Calling msiGetCollectionContentsReport")
00340
00341 if (rei == NULL || rei->rsComm == NULL) {
00342 rodsLog (LOG_ERROR, "msiGetCollectionContentsReport: input rei or rsComm is NULL.");
00343 return (SYS_INTERNAL_NULL_INPUT_ERR);
00344 }
00345
00346
00347
00348 rei->status = parseMspForCollInp (inpParam1, &collInpCache, &outCollInp, 0);
00349
00350 if (rei->status < 0) {
00351 rodsLog (LOG_ERROR, "msiGetCollectionContentsReport: input inpParam1 error. status = %d", rei->status);
00352 return (rei->status);
00353 }
00354
00355
00356
00357 contents = (keyValPair_t*)malloc(sizeof(keyValPair_t));
00358 memset (contents, 0, sizeof (keyValPair_t));
00359
00360
00361
00362 memset (&genQueryInp, 0, sizeof (genQueryInp));
00363 addInxIval (&genQueryInp.selectInp, COL_DATA_TYPE_NAME, 1);
00364 addInxIval (&genQueryInp.selectInp, COL_D_DATA_ID, 1);
00365 addInxIval (&genQueryInp.selectInp, COL_COLL_ID, 1);
00366
00367
00368
00369 genAllInCollQCond (outCollInp->collName, collQCond);
00370 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, collQCond);
00371 genQueryInp.maxRows = MAX_SQL_ROWS;
00372
00373
00374
00375
00376 rei->status = rsGenQuery (rei->rsComm, &genQueryInp, &genQueryOut);
00377
00378
00379
00380 if (rei->status == 0) {
00381
00382
00383 for (i=0;i<genQueryOut->rowCnt;i++) {
00384
00385
00386 sqlResult = getSqlResultByInx (genQueryOut, COL_DATA_TYPE_NAME);
00387
00388
00389 resultStringToken = sqlResult->value + i*sqlResult->len;
00390
00391
00392 oldValStr = getValByKey (contents, resultStringToken);
00393 if (oldValStr) {
00394 newVal = atoll(oldValStr) + 1;
00395 }
00396 else {
00397 newVal = 1;
00398 }
00399
00400
00401 snprintf(newValStr, 21, "%lld", newVal);
00402 addKeyVal(contents, resultStringToken, newValStr);
00403 }
00404
00405
00406 while (rei->status==0 && genQueryOut->continueInx > 0) {
00407 genQueryInp.continueInx=genQueryOut->continueInx;
00408 rei->status = rsGenQuery(rei->rsComm, &genQueryInp, &genQueryOut);
00409
00410
00411 for (i=0;i<genQueryOut->rowCnt;i++) {
00412
00413
00414 sqlResult = getSqlResultByInx (genQueryOut, COL_DATA_TYPE_NAME);
00415
00416
00417 resultStringToken = sqlResult->value + i*sqlResult->len;
00418
00419
00420 oldValStr = getValByKey (contents, resultStringToken);
00421 if (oldValStr) {
00422 newVal = atoll(oldValStr) + 1;
00423 }
00424 else {
00425 newVal = 1;
00426 }
00427
00428
00429 snprintf(newValStr, 21, "%lld", newVal);
00430 addKeyVal(contents, resultStringToken, newValStr);
00431 }
00432 }
00433 }
00434
00435
00436
00437 fillMsParam (inpParam2, NULL, KeyValPair_MS_T, contents, NULL);
00438
00439
00440
00441 fillIntInMsParam (outParam, rei->status);
00442
00443
00444 return (rei->status);
00445 }
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480
00481
00482
00483
00484
00485 int
00486 msiGetCollectionSize(msParam_t *collPath, msParam_t *outKVPairs, msParam_t *status, ruleExecInfo_t *rei)
00487 {
00488 collInp_t collInpCache, *outCollInp;
00489
00490 keyValPair_t *res;
00491
00492 char collQCond[2*MAX_NAME_LEN];
00493 genQueryInp_t genQueryInp;
00494 genQueryOut_t *genQueryOut;
00495
00496 rodsLong_t size, objCount;
00497 rodsLong_t coll_id;
00498 char tmpStr[21];
00499
00500 sqlResult_t *sqlResult;
00501
00502
00503 RE_TEST_MACRO (" Calling msiGetCollectionSize")
00504
00505 if (rei == NULL || rei->rsComm == NULL) {
00506 rodsLog (LOG_ERROR, "msiGetCollectionSize: input rei or rsComm is NULL.");
00507 return (SYS_INTERNAL_NULL_INPUT_ERR);
00508 }
00509
00510
00511
00512 rei->status = parseMspForCollInp (collPath, &collInpCache, &outCollInp, 0);
00513
00514 if (rei->status < 0) {
00515 rodsLog (LOG_ERROR, "msiGetCollectionSize: input collPath error. status = %d", rei->status);
00516 return (rei->status);
00517 }
00518
00519
00520
00521 res = (keyValPair_t*)malloc(sizeof(keyValPair_t));
00522 memset (res, 0, sizeof (keyValPair_t));
00523
00524
00525
00526 memset (&genQueryInp, 0, sizeof (genQueryInp));
00527 addInxIval (&genQueryInp.selectInp, COL_DATA_SIZE, SELECT_SUM);
00528 addInxIval (&genQueryInp.selectInp, COL_D_DATA_ID, SELECT_COUNT);
00529 addInxIval (&genQueryInp.selectInp, COL_DATA_REPL_NUM, 1);
00530
00531
00532
00533 genAllInCollQCond (outCollInp->collName, collQCond);
00534 addInxVal (&genQueryInp.sqlCondInp, COL_COLL_NAME, collQCond);
00535 genQueryInp.maxRows = MAX_SQL_ROWS;
00536
00537
00538
00539 rei->status = rsGenQuery (rei->rsComm, &genQueryInp, &genQueryOut);
00540
00541
00542
00543 size = 0;
00544 objCount = 0;
00545
00546
00547
00548 if (rei->status == 0) {
00549
00550
00551 sqlResult = getSqlResultByInx (genQueryOut, COL_DATA_SIZE);
00552 size = atoll(sqlResult->value);
00553
00554
00555 sqlResult = getSqlResultByInx (genQueryOut, COL_D_DATA_ID);
00556 objCount = atoll(sqlResult->value);
00557
00558 }
00559
00560
00561
00562 if (rei->status == CAT_NO_ROWS_FOUND)
00563 {
00564
00565 rei->status = isColl (rei->rsComm, outCollInp->collName, &coll_id);
00566 if (rei->status == CAT_NO_ROWS_FOUND)
00567 {
00568 rodsLog (LOG_ERROR, "msiGetCollectionSize: Collection %s was not found. Status = %d",
00569 outCollInp->collName, rei->status);
00570 free( res );
00571 return (rei->status);
00572 }
00573 }
00574
00575
00576 snprintf(tmpStr, 21, "%lld", size);
00577 addKeyVal(res, "Size", tmpStr);
00578
00579 snprintf(tmpStr, 21, "%lld", objCount);
00580 addKeyVal(res, "Object Count", tmpStr);
00581
00582
00583
00584 fillMsParam (outKVPairs, NULL, KeyValPair_MS_T, res, NULL);
00585
00586
00587
00588 fillIntInMsParam (status, rei->status);
00589
00590 return (rei->status);
00591 }
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624
00625
00626
00627
00628
00629
00630
00631
00632 int
00633 msiStructFileBundle(msParam_t *collection, msParam_t *bundleObj, msParam_t *resource, msParam_t *status, ruleExecInfo_t *rei)
00634 {
00635 collInp_t collInpCache, *collInp;
00636 dataObjInp_t destObjInpCache, *destObjInp;
00637 structFileExtAndRegInp_t *structFileBundleInp;
00638
00639
00640
00641
00642 RE_TEST_MACRO (" Calling msiStructfileBundle")
00643
00644
00645
00646 if (rei == NULL || rei->rsComm == NULL) {
00647 rodsLog (LOG_ERROR, "msistructFileBundle: input rei or rsComm is NULL.");
00648 return (SYS_INTERNAL_NULL_INPUT_ERR);
00649 }
00650
00651
00652
00653 rei->status = parseMspForCollInp (collection, &collInpCache, &collInp, 0);
00654
00655 if (rei->status < 0) {
00656 rodsLog (LOG_ERROR, "msiStructFileBundle: input collection error. status = %d", rei->status);
00657 return (rei->status);
00658 }
00659
00660
00661
00662 rei->status = parseMspForDataObjInp (bundleObj, &destObjInpCache, &destObjInp, 0);
00663
00664 if (rei->status < 0)
00665 {
00666 rodsLog (LOG_ERROR, "msiStructFileBundle: input bundleObj error. status = %d", rei->status);
00667 return (rei->status);
00668 }
00669
00670
00671
00672 rei->status = parseMspForCondInp (resource, &collInp->condInput, DEST_RESC_NAME_KW);
00673
00674 if (rei->status < 0) {
00675 rodsLog (LOG_ERROR, "msistructFileBundle: input resource error. status = %d", rei->status);
00676 return (rei->status);
00677 }
00678
00679
00680
00681 rei->status = rsCollRepl (rei->rsComm, collInp, NULL);
00682
00683
00684
00685 structFileBundleInp = (structFileExtAndRegInp_t *) malloc (sizeof(structFileExtAndRegInp_t));
00686 memset (structFileBundleInp, 0, sizeof (structFileExtAndRegInp_t));
00687 rstrcpy (structFileBundleInp->objPath, destObjInp->objPath, MAX_NAME_LEN);
00688 rstrcpy (structFileBundleInp->collection, collInp->collName, MAX_NAME_LEN);
00689
00690
00691 replKeyVal (&collInp->condInput, &structFileBundleInp->condInput);
00692
00693
00694 addKeyVal (&structFileBundleInp->condInput, DATA_TYPE_KW, "tar file");
00695
00696
00697
00698 rei->status = rsStructFileBundle (rei->rsComm, structFileBundleInp);
00699
00700
00701
00702 fillIntInMsParam (status, rei->status);
00703
00704
00705 return 0;
00706 }
00707
00708
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747 int
00748 msiCollectionSpider(msParam_t *collection, msParam_t *objects, msParam_t *action, msParam_t *status, ruleExecInfo_t *rei)
00749 {
00750 char *actionStr;
00751 collInp_t collInpCache, *collInp;
00752 collEnt_t *collEnt;
00753 int handleInx;
00754 msParam_t *msParam;
00755 dataObjInp_t *dataObjInp;
00756
00757
00758
00759
00760 RE_TEST_MACRO (" Calling msiCollectionSpider")
00761
00762
00763
00764 if (rei == NULL || rei->rsComm == NULL) {
00765 rodsLog (LOG_ERROR, "msiCollectionSpider: input rei or rsComm is NULL.");
00766 return (SYS_INTERNAL_NULL_INPUT_ERR);
00767 }
00768
00769
00770
00771 rei->status = parseMspForCollInp (collection, &collInpCache, &collInp, 0);
00772 if (rei->status < 0) {
00773 rodsLog (LOG_ERROR, "msiIsCollectionSpider: input collection error. status = %d", rei->status);
00774 return (rei->status);
00775 }
00776
00777
00778
00779 if (!objects->label || !strlen(objects->label))
00780 {
00781 rei->status = USER_PARAM_LABEL_ERR;
00782 rodsLog (LOG_ERROR, "msiIsCollectionSpider: input objects error. status = %d", rei->status);
00783 return (rei->status);
00784 }
00785
00786
00787
00788 if ((actionStr = parseMspForStr(action)) == NULL)
00789 {
00790 rei->status = USER_PARAM_TYPE_ERR;
00791 rodsLog (LOG_ERROR, "msiIsCollectionSpider: input action error. status = %d", rei->status);
00792 return (rei->status);
00793 }
00794
00795
00796
00797 dataObjInp = (dataObjInp_t *)malloc(sizeof(dataObjInp_t));
00798
00799
00800
00801 msParam = getMsParamByLabel(rei->msParamArray, objects->label);
00802 if(msParam == NULL)
00803 {
00804 addMsParam(rei->msParamArray, strdup(objects->label),
00805 strdup(DataObjInp_MS_T), (void *)dataObjInp, NULL);
00806 } else
00807 {
00808 resetMsParam (msParam);
00809 msParam->type = strdup(DataObjInp_MS_T);
00810 msParam->inOutStruct = (void *)dataObjInp;
00811 }
00812
00813
00814
00815
00816 collInp->flags = RECUR_QUERY_FG;
00817 handleInx = rsOpenCollection (rei->rsComm, collInp);
00818 if (handleInx < 0)
00819 {
00820 rodsLog (LOG_ERROR, "msiCollectionSpider: rsOpenCollection of %s error. status = %d", collInp->collName, handleInx);
00821 free(actionStr);
00822 return (handleInx);
00823 }
00824
00825
00826
00827 while ( ((rei->status = rsReadCollection (rei->rsComm, &handleInx, &collEnt)) >= 0) && NULL != collEnt )
00828 {
00829
00830
00831 if (collEnt->objType == DATA_OBJ_T)
00832 {
00833
00834 memset(dataObjInp, 0, sizeof(dataObjInp_t));
00835 snprintf(dataObjInp->objPath, MAX_NAME_LEN, "%s/%s", collEnt->collName, collEnt->dataName);
00836
00837
00838 rei->status = applyRuleUpdateParams(actionStr, rei->msParamArray, rei, 0);
00839
00840 if (rei->status < 0)
00841 {
00842
00843 rodsLog (LOG_ERROR, "msiCollectionSpider: execMyRule error. status = %d", rei->status);
00844 }
00845
00846 }
00847
00848
00849
00850
00851
00852 free(collEnt);
00853
00854 }
00855
00856
00857
00858 rei->status = rsCloseCollection (rei->rsComm, &handleInx);
00859
00860
00861
00862 fillIntInMsParam (status, rei->status);
00863
00864
00865
00866 return rei->status;
00867 }
00868
00869
00870