/
Manager.java
4593 lines (4324 loc) · 230 KB
/
Manager.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// -*- c-basic-offset: 8; -*-
//______________________________________________________________________________
//
// Space Manager - cell that handles space reservation management in SRM
// essentially a layer on top of a database
// database schema is described in ManagerSchemaConstants
//
// there are three essential tables:
//
// +------------+ +--------+ +------------+
// |srmlinkgroup|-<|srmspace|-<|srmspacefile|
// +------------+ +--------+ +------------+
// srmlinkgroup contains field that caches sum(size-usedsize) of all space
// reservations belonging to the linkgroup. Field is called reservedspaceinbytes
//
// srmspace contains fields that caches sum(size) of all files from srmspace
// that belong to this space reservation. Fields are usedspaceinbytes
// (for files in state STORED) and allocatespaceinbytes
// (for files in states RESERVED or TRANSFERRING)
//
// each time a space reservation is added/removed , reservedspaceinbytes in
// srmlinkgroup is updated
//
// each time a file is added/removed, usedspaceinbytes, allocatespaceinbytes and
// reservedspaceinbytes are updated depending on file state
//
// Dmitry Litvintsev (litvinse@fnal.gov)
// $Id: Manager.java 9764 2008-07-07 17:48:24Z litvinse $
// $Author: litvinse $
//______________________________________________________________________________
package diskCacheV111.services.space;
import com.google.common.collect.Iterables;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Required;
import javax.annotation.Nonnull;
import javax.security.auth.Subject;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import diskCacheV111.poolManager.PoolPreferenceLevel;
import diskCacheV111.poolManager.PoolSelectionUnit;
import diskCacheV111.services.space.message.CancelUse;
import diskCacheV111.services.space.message.ExtendLifetime;
import diskCacheV111.services.space.message.GetFileSpaceTokensMessage;
import diskCacheV111.services.space.message.GetLinkGroupIdsMessage;
import diskCacheV111.services.space.message.GetLinkGroupNamesMessage;
import diskCacheV111.services.space.message.GetLinkGroupsMessage;
import diskCacheV111.services.space.message.GetSpaceMetaData;
import diskCacheV111.services.space.message.GetSpaceTokenIdsMessage;
import diskCacheV111.services.space.message.GetSpaceTokens;
import diskCacheV111.services.space.message.GetSpaceTokensMessage;
import diskCacheV111.services.space.message.Release;
import diskCacheV111.services.space.message.Reserve;
import diskCacheV111.services.space.message.Use;
import diskCacheV111.util.AccessLatency;
import diskCacheV111.util.CacheException;
import diskCacheV111.util.DBManager;
import diskCacheV111.util.FileNotFoundCacheException;
import diskCacheV111.util.FsPath;
import diskCacheV111.util.IoPackage;
import diskCacheV111.util.PnfsHandler;
import diskCacheV111.util.PnfsId;
import diskCacheV111.util.RetentionPolicy;
import diskCacheV111.util.ThreadManager;
import diskCacheV111.util.VOInfo;
import diskCacheV111.vehicles.DoorTransferFinishedMessage;
import diskCacheV111.vehicles.IpProtocolInfo;
import diskCacheV111.vehicles.Message;
import diskCacheV111.vehicles.PnfsDeleteEntryNotificationMessage;
import diskCacheV111.vehicles.PoolAcceptFileMessage;
import diskCacheV111.vehicles.PoolFileFlushedMessage;
import diskCacheV111.vehicles.PoolLinkGroupInfo;
import diskCacheV111.vehicles.PoolMgrGetPoolLinkGroups;
import diskCacheV111.vehicles.PoolMgrSelectWritePoolMsg;
import diskCacheV111.vehicles.PoolRemoveFilesMessage;
import diskCacheV111.vehicles.ProtocolInfo;
import diskCacheV111.vehicles.StorageInfo;
import dmg.cells.nucleus.AbstractCellComponent;
import dmg.cells.nucleus.CellCommandListener;
import dmg.cells.nucleus.CellMessage;
import dmg.cells.nucleus.CellMessageReceiver;
import dmg.cells.nucleus.NoRouteToCellException;
import dmg.cells.nucleus.SerializationException;
import dmg.util.Args;
import org.dcache.auth.FQAN;
import org.dcache.auth.Subjects;
import org.dcache.cells.CellStub;
import org.dcache.namespace.FileAttribute;
import org.dcache.poolmanager.PoolMonitor;
import org.dcache.util.JdbcConnectionPool;
import org.dcache.vehicles.FileAttributes;
import static com.google.common.base.Preconditions.checkNotNull;
/**
* <pre> Space Manager dCache service provides ability
* \to reserve space in the pool linkGroups
*
*
* @author timur
*/
public final class Manager
extends AbstractCellComponent
implements CellCommandListener,
CellMessageReceiver,
Runnable {
private static final long EAGER_LINKGROUP_UPDATE_PERIOD = 1000;
private String jdbcUrl;
private String jdbcDriver;
private String jdbcUser;
private String jdbcPassword;
private String pwdfile;
private long updateLinkGroupsPeriod;
private long currentUpdateLinkGroupsPeriod = EAGER_LINKGROUP_UPDATE_PERIOD;
private long expireSpaceReservationsPeriod;
private boolean deleteStoredFileRecord;
private Thread updateLinkGroups;
private Thread expireSpaceReservations;
private AccessLatency defaultAccessLatency;
private RetentionPolicy defaultRetentionPolicy;
private boolean reserveSpaceForNonSRMTransfers;
private boolean returnFlushedSpaceToReservation;
private boolean cleanupExpiredSpaceFiles;
private String linkGroupAuthorizationFileName;
private boolean spaceManagerEnabled;
public static final int currentSchemaVersion = 4;
private int previousSchemaVersion;
private CellStub poolManagerStub;
private CellStub pnfsStub;
private PnfsHandler pnfs;
private SpaceManagerAuthorizationPolicy authorizationPolicy;
JdbcConnectionPool connection_pool;
DBManager dbManager;
private static Logger logger = LoggerFactory.getLogger(Manager.class);
private static IoPackage<File> fileIO = new FileIO();
private static IoPackage<Space> spaceReservationIO = new SpaceReservationIO();
private static IoPackage<LinkGroup> linkGroupIO = new LinkGroupIO();
private PoolMonitor poolMonitor;
@Required
public void setPoolManagerStub(CellStub poolManagerStub)
{
this.poolManagerStub = poolManagerStub;
}
@Required
public void setPnfsStub(CellStub pnfsStub)
{
this.pnfsStub = pnfsStub;
}
@Required
public void setPnfsHandler(PnfsHandler pnfs)
{
this.pnfs = pnfs;
}
public void setPoolMonitor(PoolMonitor poolMonitor)
{
this.poolMonitor = poolMonitor;
}
@Required
public void setJdbcUrl(String jdbcUrl)
{
this.jdbcUrl = jdbcUrl;
}
@Required
public void setJdbcDriver(String jdbcDriver)
{
this.jdbcDriver = jdbcDriver;
}
@Required
public void setJdbcUser(String jdbcUser)
{
this.jdbcUser = jdbcUser;
}
@Required
public void setJdbcPassword(String jdbcPassword)
{
this.jdbcPassword = jdbcPassword;
}
@Required
public void setSpaceManagerEnabled(boolean enabled)
{
this.spaceManagerEnabled = enabled;
}
@Required
public void setUpdateLinkGroupsPeriod(long updateLinkGroupsPeriod)
{
this.updateLinkGroupsPeriod = updateLinkGroupsPeriod;
}
@Required
public void setExpireSpaceReservationsPeriod(long expireSpaceReservationsPeriod)
{
this.expireSpaceReservationsPeriod = expireSpaceReservationsPeriod;
}
@Required
public void setDefaultRetentionPolicy(RetentionPolicy defaultRetentionPolicy)
{
this.defaultRetentionPolicy = defaultRetentionPolicy;
}
@Required
public void setDefaultAccessLatency(AccessLatency defaultAccessLatency)
{
this.defaultAccessLatency = defaultAccessLatency;
}
@Required
public void setReserveSpaceForNonSRMTransfers(boolean reserveSpaceForNonSRMTransfers)
{
this.reserveSpaceForNonSRMTransfers = reserveSpaceForNonSRMTransfers;
}
@Required
public void setDeleteStoredFileRecord(boolean deleteStoredFileRecord)
{
this.deleteStoredFileRecord = deleteStoredFileRecord;
}
@Required
public void setCleanupExpiredSpaceFiles(boolean cleanupExpiredSpaceFiles)
{
this.cleanupExpiredSpaceFiles = cleanupExpiredSpaceFiles;
}
@Required
public void setReturnFlushedSpaceToReservation(boolean returnFlushedSpaceToReservation)
{
this.returnFlushedSpaceToReservation = returnFlushedSpaceToReservation;
}
@Required
public void setLinkGroupAuthorizationFileName(String linkGroupAuthorizationFileName)
{
this.linkGroupAuthorizationFileName = linkGroupAuthorizationFileName;
}
@Required
public void setDbManager(DBManager manager)
{
dbManager = manager;
}
@Required
public void setAuthorizationPolicy(SpaceManagerAuthorizationPolicy authorizationPolicy)
{
this.authorizationPolicy = authorizationPolicy;
}
public void start() throws Exception
{
dbManager.initConnectionPool(jdbcUrl, jdbcDriver, jdbcUser, jdbcPassword);
connection_pool = dbManager.getConnectionPool();
dbinit();
(updateLinkGroups = new Thread(this,"UpdateLinkGroups")).start();
(expireSpaceReservations = new Thread(this,"ExpireThreadReservations")).start();
}
public void stop()
{
if (updateLinkGroups != null) {
updateLinkGroups.interrupt();
}
if (expireSpaceReservations != null) {
expireSpaceReservations.interrupt();
}
}
@Override
public void getInfo(PrintWriter printWriter) {
printWriter.println("space.Manager "+getCellName());
printWriter.println("spaceManagerEnabled="+spaceManagerEnabled);
printWriter.println("JdbcUrl="+jdbcUrl);
printWriter.println("jdbcDriver="+jdbcDriver);
printWriter.println("databse jdbcUser="+jdbcUser);
printWriter.println("updateLinkGroupsPeriod="
+ updateLinkGroupsPeriod);
printWriter.println("expireSpaceReservationsPeriod="
+ expireSpaceReservationsPeriod);
printWriter.println("deleteStoredFileRecord="
+ deleteStoredFileRecord);
printWriter.println("defaultLatencyForSpaceReservations="
+ defaultAccessLatency);
printWriter.println("reserveSpaceForNonSRMTransfers="
+ reserveSpaceForNonSRMTransfers);
printWriter.println("returnFlushedSpaceToReservation="
+ returnFlushedSpaceToReservation);
printWriter.println("linkGroupAuthorizationFileName="
+ linkGroupAuthorizationFileName);
}
public static final String hh_release = " <spaceToken> [ <bytes> ] # release the space " +
"reservation identified by <spaceToken>" ;
public String ac_release_$_1_2(Args args) throws Exception {
long reservationId = Long.parseLong( args.argv(0));
if(args.argc() == 1) {
updateSpaceState(reservationId,SpaceState.RELEASED);
StringBuffer sb = new StringBuffer();
Space space = getSpace(reservationId);
space.toStringBuffer(sb);
return sb.toString();
}
else {
return "partial release is not supported yet";
}
}
public static final String hh_update_space_reservation = " [-size=<size>] [-lifetime=<lifetime>] [-vog=<vogroup>] [-vor=<vorole>] <spaceToken> \n"+
" # set new size and/or lifetime for the space token \n " +
" # valid examples of size: 1000, 100kB, 100KB, 100KiB, 100MB, 100MiB, 100GB, 100GiB, 10.5TB, 100TiB \n" +
" # see http://en.wikipedia.org/wiki/Gigabyte for explanation \n"+
" # lifetime is in seconds (\"-1\" means infinity or permanent reservation";
public final long stringToSize(String s)
{
long size;
int endIndex;
int startIndex=0;
if (s.endsWith("kB") || s.endsWith("KB")) {
endIndex=s.indexOf("KB");
if (endIndex==-1) {
endIndex=s.indexOf("kB");
}
String sSize = s.substring(startIndex,endIndex);
size = sSize.equals("") ? 1000L : (long)(Double.parseDouble(sSize)*1.e+3+0.5);
}
else if (s.endsWith("KiB")) {
endIndex=s.indexOf("KiB");
String sSize = s.substring(startIndex,endIndex);
size = sSize.equals("") ? 1024L : (long)(Double.parseDouble(sSize)*1024.+0.5);
}
else if (s.endsWith("MB")) {
endIndex=s.indexOf("MB");
String sSize = s.substring(startIndex,endIndex);
size = sSize.equals("") ? 1000000L : (long)(Double.parseDouble(sSize)*1.e+6+0.5);
}
else if (s.endsWith("MiB")) {
endIndex=s.indexOf("MiB");
String sSize = s.substring(startIndex,endIndex);
size = sSize.equals("") ? 1048576L : (long)(Double.parseDouble(sSize)*1048576.+0.5);
}
else if (s.endsWith("GB")) {
endIndex=s.indexOf("GB");
String sSize = s.substring(startIndex,endIndex);
size = sSize.equals("") ? 1000000000L : (long)(Double.parseDouble(sSize)*1.e+9+0.5);
}
else if (s.endsWith("GiB")) {
endIndex=s.indexOf("GiB");
String sSize = s.substring(startIndex,endIndex);
size = sSize.equals("") ? 1073741824L : (long)(Double.parseDouble(sSize)*1073741824.+0.5);
}
else if (s.endsWith("TB")) {
endIndex=s.indexOf("TB");
String sSize = s.substring(startIndex,endIndex);
size = sSize.equals("") ? 1000000000000L : (long)(Double.parseDouble(sSize)*1.e+12+0.5);
}
else if (s.endsWith("TiB")) {
endIndex=s.indexOf("TiB");
String sSize = s.substring(startIndex,endIndex);
size = sSize.equals("") ? 1099511627776L : (long)(Double.parseDouble(sSize)*1099511627776.+0.5);
}
else {
size = Long.parseLong(s);
}
if (size<0L) {
throw new IllegalArgumentException("size have to be non-negative");
}
return size;
}
public String ac_update_space_reservation_$_1(Args args) throws Exception {
long reservationId = Long.parseLong(args.argv(0));
String sSize = args.getOpt("size");
String sLifetime = args.getOpt("lifetime");
String voRole = args.getOpt("vor");
String voGroup = args.getOpt("vog");
if (sLifetime==null&&
sSize==null&&
voRole==null&&
voGroup==null) {
return "Need to specify at least one option \"-lifetime\", \"-size\" \"-vog\" or \"-vor\". If -lifetime=\"-1\" then the reservation will not expire";
}
Long longLifetime = null;
if (sLifetime != null) {
long lifetime = Long.parseLong(sLifetime);
longLifetime = ( lifetime == -1 ) ? new Long(-1) : new Long ( lifetime * 1000 );
}
if (voRole!=null||voGroup!=null) {
// check that linkgroup allows these role/group combination
try {
Space space = getSpace(reservationId);
long lid = space.getLinkGroupId();
LinkGroup lg = getLinkGroup(lid);
boolean foundMatch=false;
// this will keep the same group/role
// if one of then is not specified:
if (voGroup==null) {
voGroup = space.getVoGroup();
}
if (voRole==null) {
voRole = space.getVoRole();
}
for (VOInfo info : lg.getVOs()) {
if (info.match(voGroup,voRole)) {
foundMatch=true;
break;
}
}
if (!foundMatch) {
StringBuilder sb = new StringBuilder();
for (VOInfo info : lg.getVOs()) {
sb.append(info).append('\n');
}
throw new IllegalArgumentException("cannot change voGroup:voRole to "+
voGroup+":"+voRole+
". Supported vogroup:vorole pairs for this spacereservation\n"+
sb.toString());
}
}
catch (SQLException e) {
return e.toString();
}
catch (Exception e) {
return e.toString();
}
}
try {
updateSpaceReservation(reservationId,
voGroup,
voRole,
null,
null,
null,
(sSize != null ? stringToSize(sSize) : null),
longLifetime,
null,
null);
}
catch (SQLException e) {
return e.toString();
}
StringBuffer sb = new StringBuffer();
StringBuilder id = new StringBuilder();
id.append(reservationId);
listSpaceReservations(false,
id.toString(),
null,
null,
null,
null,
null,
sb);
return sb.toString();
}
public static final String hh_update_link_groups = " #triggers update of the link groups";
public String ac_update_link_groups_$_0(Args args)
{
synchronized(updateLinkGroupsSyncObject) {
updateLinkGroupsSyncObject.notify();
}
return "update started";
}
public static final String hh_ls = " [-lg=LinkGroupName] [-lgid=LinkGroupId] [-vog=vogroup] [-vor=vorole] [-desc=description] [-l] <id> # list space reservations";
public String ac_ls_$_0_1(Args args) throws Exception {
String lgName = args.getOpt("lg");
String lgid = args.getOpt("lgid");
String voGroup = args.getOpt("vog");
String voRole = args.getOpt("vor");
String description = args.getOpt("desc");
boolean isLongFormat = args.hasOption("l");
String id = null;
if (args.argc() == 1) {
id = args.argv(0);
}
StringBuffer sb = new StringBuffer();
if (description != null && id !=null ) {
sb.append("Do not handle \"desc\" and id simultaneously\n");
return sb.toString();
}
if (lgName==null&&lgid==null&&voGroup==null&&description==null) {
sb.append("Reservations:\n");
}
listSpaceReservations(isLongFormat,
id,
lgName,
lgid,
description,
voGroup,
voRole,
sb);
if (lgName==null&&lgid==null&&voGroup==null&&description==null&id==null) {
sb.append("\n\nLinkGroups:\n");
listLinkGroups(isLongFormat,false,id,sb);
}
return sb.toString();
}
private void listSpaceReservations(boolean isLongFormat,
String id,
String linkGroupName,
String linkGroupId,
String description,
String group,
String role,
StringBuffer sb) throws Exception {
Set<Space> spaces;
long lgId = 0;
LinkGroup lg = null;
if (linkGroupId!=null) {
lgId = Long.parseLong(linkGroupId);
lg = getLinkGroup(lgId);
}
if (linkGroupName!=null) {
lg = getLinkGroupByName(linkGroupName);
if (lgId!=0) {
if (lg.getId()!=lgId) {
sb.append("Cannot find LinkGroup with id=").
append(linkGroupId).
append(" and name=").
append(linkGroupName);
return;
}
}
}
if (lg!=null) {
sb.append("Found LinkGroup:\n");
lg.toStringBuffer(sb);
sb.append("\n");
}
if(id != null) {
Long longid = Long.valueOf(id);
try {
spaces=dbManager.selectPrepared(spaceReservationIO,
SpaceReservationIO.SELECT_SPACE_RESERVATION_BY_ID,
longid);
if (spaces.isEmpty()==true) {
if(lg==null) {
sb.append("Space with id=").
append(id).
append(" not found ");
}
else {
sb.append("LinkGroup with id=").
append(lg.getId()).
append(" and name=").
append(lg.getName()).
append(
" does not contain space with id=").
append(id);
}
return;
}
for (Space space : spaces ) {
if (lg!=null) {
if (space.getLinkGroupId()!=lg.getId()) {
sb.append("LinkGroup with id=").
append(lg.getId()).
append(" and name=").
append(lg.getName()).
append(" does not contain space with id=").
append(id);
}
}
else {
space.toStringBuffer(sb);
}
sb.append('\n');
}
return;
}
catch(SQLException e) {
if(lg==null) {
sb.append("Space with id=").
append(id).
append(" not found ");
}
else {
sb.append("LinkGroup with id=").
append(lg.getId()).
append(" and name=").
append(lg.getName()).
append(" does not contain space with id=").
append(id);
}
return;
}
}
if (linkGroupName==null&&linkGroupId==null&&description==null&&group==null&&role==null){
try {
spaces=dbManager.selectPrepared(spaceReservationIO,
SpaceReservationIO.SELECT_CURRENT_SPACE_RESERVATIONS);
int count = spaces.size();
long totalReserved = 0;
for (Space space : spaces) {
totalReserved += space.getSizeInBytes();
space.toStringBuffer(sb);
sb.append('\n');
}
sb.append("total number of reservations: ").append(count).append('\n');
sb.append("total number of bytes reserved: ").append(totalReserved);
return;
}
catch(SQLException sqle) {
sb.append(sqle.getMessage());
return;
}
}
if (description==null&&group==null&&role==null&&lg!=null) {
try {
spaces=dbManager.selectPrepared(spaceReservationIO,
SpaceReservationIO.SELECT_SPACE_RESERVATION_BY_LINKGROUP_ID,
lg.getId());
if (spaces.isEmpty()==true) {
sb.append("LinkGroup with id=").
append(lg.getId()).
append(" and name=").
append(lg.getName()).
append(" does not contain any space reservations\n");
return;
}
for (Space space : spaces) {
space.toStringBuffer(sb);
sb.append('\n');
}
return;
}
catch(SQLException e) {
sb.append("LinkGroup with id=").
append(lg.getId()).
append(" and name=").
append(lg.getName()).
append(" does not contain any space reservations\n");
return;
}
}
if (description!=null) {
try {
if (lg==null) {
spaces=dbManager.selectPrepared(spaceReservationIO,
SpaceReservationIO.SELECT_SPACE_RESERVATION_BY_DESC,
description);
}
else {
spaces=dbManager.selectPrepared(spaceReservationIO,
SpaceReservationIO.SELECT_SPACE_RESERVATION_BY_DESC_AND_LINKGROUP_ID,
description,
lg.getId());
}
if (spaces.isEmpty()==true) {
if (lg==null) {
sb.append("Space with description ").
append(description).
append(" not found ");
}
else {
sb.append("LinkGroup with id=").
append(lg.getId()).
append(" and name=").
append(lg.getName()).
append(" does not contain space with description ").
append(description);
}
return;
}
for (Space space : spaces) {
space.toStringBuffer(sb);
sb.append('\n');
}
return;
}
catch(SQLException e) {
if (lg==null) {
sb.append("Space with description ").
append(description).
append(" not found ");
}
else {
sb.append("LinkGroup with id=").
append(lg.getId()).
append(" and name=").
append(lg.getName()).
append(" does not contain space with description ").
append(description);
}
return;
}
}
if (role!=null&&group!=null) {
try {
if (lg==null) {
spaces=dbManager.selectPrepared(spaceReservationIO,
SpaceReservationIO.SELECT_SPACE_RESERVATION_BY_VOGROUP_AND_VOROLE,
group,
role);
}
else {
spaces=dbManager.selectPrepared(spaceReservationIO,
SpaceReservationIO.SELECT_SPACE_RESERVATION_BY_VOGROUP_AND_VOROLE_AND_LINKGROUP_ID,
group,
role,
lg.getId());
}
if (spaces.isEmpty()==true) {
if (lg==null) {
sb.append("Space with vorole ").
append(role).
append(" and vogroup ").
append(group).
append(" not found ");
}
else {
sb.append("LinkGroup with id=").
append(lg.getId()).
append(" and name=").
append(lg.getName()).
append(" does not contain space with vorole ").
append(role).
append(" and vogroup ").
append(group);
}
return;
}
for (Space space : spaces) {
space.toStringBuffer(sb);
sb.append('\n');
}
return;
}
catch(SQLException e) {
if (lg==null) {
sb.append("Space with vorole ").
append(role).
append(" and vogroup ").
append(group).
append(" not found ");
}
else {
sb.append("LinkGroup with id=").
append(lg.getId()).
append(" and name=").
append(lg.getName()).
append(" does not contain space with vorole ").
append(role).
append(" and vogroup ").
append(group);
}
return;
}
}
if (group!=null) {
try {
if (lg==null) {
spaces=dbManager.selectPrepared(spaceReservationIO,
SpaceReservationIO.SELECT_SPACE_RESERVATION_BY_VOGROUP,
group);
}
else {
spaces=dbManager.selectPrepared(spaceReservationIO,
SpaceReservationIO.SELECT_SPACE_RESERVATION_BY_VOGROUP_AND_LINKGROUP_ID,
group,
lg.getId());
}
if (spaces.isEmpty()==true) {
if (lg==null) {
sb.append("Space with vogroup ").
append(group).
append(" not found ");
}
else {
sb.append("LinkGroup with id=").
append(lg.getId()).
append(" and name=").
append(
" does not contain space with vogroup=").
append(group);
}
return;
}
for (Space space : spaces) {
space.toStringBuffer(sb);
sb.append('\n');
}
return;
}
catch(SQLException e) {
if (lg==null) {
sb.append("Space with vogroup ").
append(group).
append(" not found ");
}
else {
sb.append("LinkGroup with id=").
append(lg.getId()).
append(" and name=").
append(
" does not contain space with vogroup=").
append(group);
}
return;
}
}
if (role!=null) {
try {
if (lg==null) {
spaces=dbManager.selectPrepared(spaceReservationIO,
SpaceReservationIO.SELECT_SPACE_RESERVATION_BY_VOROLE,
group);
}
else {
spaces=dbManager.selectPrepared(spaceReservationIO,
SpaceReservationIO.SELECT_SPACE_RESERVATION_BY_VOROLE_AND_LINKGROUP_ID,
group,
lg.getId());
}
if (spaces.isEmpty()==true) {
if (lg==null) {
sb.append("Space with vogroup ").
append(group).
append(" not found ");
}
else {
sb.append("LinkGroup with id=").
append(lg.getId()).
append(" and name=").
append(" does not contain space with vorole=").
append(role);
}
return;
}
for (Space space : spaces) {
space.toStringBuffer(sb);
sb.append('\n');
}
}
catch(SQLException e) {
if (lg==null) {
sb.append("Space with vogroup ").
append(group).
append(" not found ");
}
else {
sb.append("LinkGroup with id=").
append(lg.getId()).
append(" and name=").
append(" does not contain space with vorole=").
append(role);
}
}
}
}
private void listLinkGroups(boolean isLongFormat,
boolean all,
String id,
StringBuffer sb)
{
Set<LinkGroup> groups;
if(id != null) {
long longid = Long.parseLong(id);
try {
LinkGroup lg=getLinkGroup(longid);
lg.toStringBuffer(sb);
sb.append('\n');
return;
}
catch(SQLException e) {
sb.append("LinkGroup with id=").
append(id).
append(" not found ");
return;
}
}
try {
if(all) {
groups=dbManager.selectPrepared(linkGroupIO,
LinkGroupIO.SELECT_ALL_LINKGROUPS);
}
else {
groups=dbManager.selectPrepared(linkGroupIO,
LinkGroupIO.SELECT_CURRENT_LINKGROUPS,
latestLinkGroupUpdateTime);
}
int count = groups.size();
long totalReservable = 0L;
long totalReserved = 0L;
for (LinkGroup g : groups) {
totalReservable += g.getAvailableSpaceInBytes();
totalReserved += g.getReservedSpaceInBytes();
g.toStringBuffer(sb);
sb.append('\n');
}
sb.append("total number of linkGroups: ").
append(count).append('\n');
sb.append("total number of bytes reservable: ").
append(totalReservable).append('\n');
sb.append("total number of bytes reserved : ").
append(totalReserved).append('\n');
sb.append("last time all link groups were updated: ").
append((new Date(latestLinkGroupUpdateTime)).toString()).
append("(").append(latestLinkGroupUpdateTime).
append(")");
}
catch(SQLException sqle) {
sb.append(sqle.getMessage());
}
}
public static final String hh_ls_link_groups = " [-l] [-a] <id> # list link groups";
public String ac_ls_link_groups_$_0_1(Args args)
{
boolean isLongFormat = args.hasOption("l");
boolean all = args.hasOption("a");
String id = null;
if (args.argc() == 1) {
id = args.argv(0);
}
StringBuffer sb = new StringBuffer();
sb.append("\n\nLinkGroups:\n");
listLinkGroups(isLongFormat,all,id,sb);
return sb.toString();
}
public static final String hh_ls_file_space_tokens = " <pnfsId>|<pnfsPath> # list space tokens " +
"that contain a file";
public String ac_ls_file_space_tokens_$_1(Args args) throws Exception {
String pnfsPath = args.argv(0);
PnfsId pnfsId;
try {
pnfsId = new PnfsId(pnfsPath);
pnfsPath = null;
}
catch(Exception e) {
pnfsId = null;
}
StringBuilder sb = new StringBuilder();
long[] tokens= getFileSpaceTokens(pnfsId, pnfsPath);
if(tokens != null && tokens.length >0) {
for(long token:tokens) {
sb.append('\n').append(token);
}
}
else {
sb.append("\nno space tokens found for file:").append( args.argv(0));
}
return sb.toString();