/
GetFileRequest.java
885 lines (777 loc) · 28 KB
/
GetFileRequest.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
/*
COPYRIGHT STATUS:
Dec 1st 2001, Fermi National Accelerator Laboratory (FNAL) documents and
software are sponsored by the U.S. Department of Energy under Contract No.
DE-AC02-76CH03000. Therefore, the U.S. Government retains a world-wide
non-exclusive, royalty-free license to publish or reproduce these documents
and software for U.S. Government purposes. All documents and software
available from this server are protected under the U.S. and Foreign
Copyright Laws, and FNAL reserves all rights.
Distribution of the software available from this server is free of
charge subject to the user following the terms of the Fermitools
Software Legal Information.
Redistribution and/or modification of the software shall be accompanied
by the Fermitools Software Legal Information (including the copyright
notice).
The user is asked to feed back problems, benefits, and/or suggestions
about the software to the Fermilab Software Providers.
Neither the name of Fermilab, the URA, nor the names of the contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
DISCLAIMER OF LIABILITY (BSD):
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL FERMILAB,
OR THE URA, OR THE U.S. DEPARTMENT of ENERGY, OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Liabilities of the Government:
This software is provided by URA, independent from its Prime Contract
with the U.S. Department of Energy. URA is acting independently from
the Government and in its own private capacity and is not acting on
behalf of the U.S. Government, nor as its contractor nor its agent.
Correspondingly, it is understood and agreed that the U.S. Government
has no connection to this software and in no manner whatsoever shall
be liable for nor assume any responsibility or obligation for any claim,
cost, or damages arising out of or resulting from the use of the software
available from this server.
Export Control:
All documents and software available from this server are subject to U.S.
export control laws. Anyone downloading information from this server is
obligated to secure any necessary Government licenses before exporting
documents or software obtained from this server.
*/
/*
* FileRequest.java
*
* Created on July 5, 2002, 12:04 PM
*/
package org.dcache.srm.request;
import org.apache.axis.types.UnsignedLong;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.dao.DataAccessException;
import java.net.URI;
import diskCacheV111.srm.RequestFileStatus;
import org.dcache.srm.FileMetaData;
import org.dcache.srm.PinCallbacks;
import org.dcache.srm.SRM;
import org.dcache.srm.SRMAuthorizationException;
import org.dcache.srm.SRMException;
import org.dcache.srm.SRMInvalidRequestException;
import org.dcache.srm.SRMUser;
import org.dcache.srm.UnpinCallbacks;
import org.dcache.srm.scheduler.FatalJobFailure;
import org.dcache.srm.scheduler.IllegalStateTransition;
import org.dcache.srm.scheduler.NonFatalJobFailure;
import org.dcache.srm.scheduler.Scheduler;
import org.dcache.srm.scheduler.State;
import org.dcache.srm.v2_2.TGetRequestFileStatus;
import org.dcache.srm.v2_2.TReturnStatus;
import org.dcache.srm.v2_2.TSURLReturnStatus;
import org.dcache.srm.v2_2.TStatusCode;
/**
*
* @author timur
* @version
*/
public final class GetFileRequest extends FileRequest<GetRequest> {
private final static Logger logger = LoggerFactory.getLogger(GetFileRequest.class);
private URI surl;
private URI turl;
private String pinId;
private String fileId;
/**
* Transient, since we do not need to replicate the field,
* the field is needed only in jvm where the request is originally
* scheduled
*/
private transient FileMetaData fileMetaData;
/** Creates new FileRequest */
public GetFileRequest(long requestId,
Long requestCredentalId,
URI surl,
long lifetime,
int maxNumberOfRetries)
{
super(requestId,
requestCredentalId,
lifetime,
maxNumberOfRetries);
logger.debug("GetFileRequest, requestId="+requestId+" fileRequestId = "+getId());
this.surl = surl;
}
/**
* restore constructore, used for restoring the existing
* file request from the database
*/
public GetFileRequest(
long id,
Long nextJobId,
long creationTime,
long lifetime,
int stateId,
String errorMessage,
String scheduelerId,
long schedulerTimeStamp,
int numberOfRetries,
int maxNumberOfRetries,
long lastStateTransitionTime,
JobHistory[] jobHistoryArray,
long requestId,
Long requestCredentalId,
String statusCodeString,
String SURL,
String TURL,
String fileId,
String pinId
) {
super(id,
nextJobId,
creationTime,
lifetime,
stateId,
errorMessage,
scheduelerId,
schedulerTimeStamp,
numberOfRetries,
maxNumberOfRetries,
lastStateTransitionTime,
jobHistoryArray,
requestId,
requestCredentalId,
statusCodeString);
this.surl = URI.create(SURL);
if(TURL != null && !TURL.equalsIgnoreCase("null")) {
this.turl = URI.create(TURL);
}
if(fileId != null && (!fileId.equalsIgnoreCase("null"))) {
this.fileId = fileId;
}
if(pinId != null && (!pinId.equalsIgnoreCase("null"))) {
this.pinId = pinId;
}
}
public void setPinId(String pinId) {
wlock();
try {
this.pinId = pinId;
} finally {
wunlock();
}
}
public String getPinId() {
rlock();
try {
return pinId;
} finally {
runlock();
}
}
public boolean isPinned() {
return getPinId() != null;
}
public URI getSurl() {
rlock();
try {
return surl;
} finally {
runlock();
}
}
public URI getTurl() {
rlock();
try {
return turl;
} finally {
runlock();
}
}
public final String getSurlString() {
return getSurl().toASCIIString();
}
public String getTurlString() {
rlock();
try {
if (turl != null) {
return turl.toASCIIString();
}
} finally {
runlock();
}
return null;
}
public String getFileId() {
rlock();
try {
return fileId;
} finally {
runlock();
}
}
@Override
public RequestFileStatus getRequestFileStatus(){
RequestFileStatus rfs;
if(getFileMetaData() != null) {
rfs = new RequestFileStatus(getFileMetaData());
}
else {
rfs = new RequestFileStatus();
}
rfs.fileId = (int) getId();
rfs.SURL = getSurlString();
if(this.isPinned()) {
rfs.isPinned = true;
rfs.isCached = true;
}
State state = getState();
rfs.TURL = getTurlString();
if(state == State.DONE) {
rfs.state = "Done";
}
else if(state == State.READY) {
rfs.state = "Ready";
}
else if(state == State.TRANSFERRING) {
rfs.state = "Running";
}
else if(state == State.FAILED
|| state == State.CANCELED ) {
rfs.state = "Failed";
}
else {
rfs.state = "Pending";
}
//logger.debug(" returning requestFileStatus for "+rfs.toString());
return rfs;
}
public TGetRequestFileStatus getTGetRequestFileStatus()
throws SRMInvalidRequestException {
TGetRequestFileStatus fileStatus = new TGetRequestFileStatus();
if(getFileMetaData() != null) {
fileStatus.setFileSize(new UnsignedLong(getFileMetaData().size));
}
try {
fileStatus.setSourceSURL(new org.apache.axis.types.URI(getSurlString()));
} catch (org.apache.axis.types.URI.MalformedURIException e) {
logger.error(e.toString());
throw new SRMInvalidRequestException("wrong surl format");
}
String turlstring = getTurlString();
if(turlstring != null) {
try {
fileStatus.setTransferURL(new org.apache.axis.types.URI(turlstring));
} catch (org.apache.axis.types.URI.MalformedURIException e) {
logger.error(e.toString());
throw new SRMInvalidRequestException("wrong turl format");
}
}
if(this.isPinned()) {
fileStatus.setRemainingPinTime((int)(getRemainingLifetime()/1000));
}
fileStatus.setEstimatedWaitTime(getContainerRequest().getRetryDeltaTime());
fileStatus.setStatus(getReturnStatus());
return fileStatus;
}
public TSURLReturnStatus getTSURLReturnStatus() throws SRMInvalidRequestException
{
try {
return new TSURLReturnStatus(new org.apache.axis.types.URI(getSurlString()), getReturnStatus());
} catch (org.apache.axis.types.URI.MalformedURIException e) {
logger.error(e.toString());
throw new SRMInvalidRequestException("wrong surl format");
}
}
@Override
public void toString(StringBuilder sb, boolean longformat) {
sb.append(" GetFileRequest ");
sb.append(" id:").append(getId());
sb.append(" priority:").append(getPriority());
sb.append(" creator priority:");
try {
sb.append(getUser().getPriority());
} catch (SRMInvalidRequestException ire) {
sb.append("Unknown");
}
State state = getState();
sb.append(" state:").append(state);
if(longformat) {
sb.append('\n').append(" SURL: ").append(getSurlString());
sb.append('\n').append(" pinned: ").append(isPinned());
String thePinId = getPinId();
if(thePinId != null) {
sb.append('\n').append(" pinid: ").append(thePinId);
}
sb.append('\n').append(" TURL: ").append(getTurlString());
sb.append('\n').append(" status code:").append(getStatusCode());
sb.append('\n').append(" error message:").append(getErrorMessage());
sb.append('\n').append(" History of State Transitions: \n");
sb.append(getHistory());
}
}
@Override
public synchronized void run() throws NonFatalJobFailure, FatalJobFailure {
logger.debug("run()");
try {
if(getPinId() == null) {
// [ SRM 2.2, 5.2.2, g)] The file request must fail with an error SRM_FILE_BUSY
// if srmPrepareToGet requests for files which there is an active srmPrepareToPut
// (no srmPutDone is yet called) request for.
//
// [ SRM 2.2, 5.1.3] SRM_FILE_BUSY: client requests for a file which there is an
// active srmPrepareToPut (no srmPutDone is yet called) request for.
if (SRM.getSRM().isFileBusy(surl)) {
setStateAndStatusCode(State.FAILED, "The requested SURL is being used by another client.",
TStatusCode.SRM_FILE_BUSY);
}
pinFile();
if(getPinId() == null) {
setState(State.ASYNCWAIT, "Pinning file.");
logger.debug("GetFileRequest: waiting async notification about pinId...");
return;
}
}
try {
computeTurl();
} catch (SRMAuthorizationException e) {
String error =e.getMessage();
logger.error(error);
try {
setStateAndStatusCode(
State.FAILED,
error,
TStatusCode.SRM_AUTHORIZATION_FAILURE);
} catch(IllegalStateTransition ist) {
logger.error("Illegal State Transition : " + ist.getMessage());
}
} catch (SRMException e) {
String error = "cannot obtain turl for file:" + e.getMessage();
logger.error(error);
try {
setState(State.FAILED,error);
} catch(IllegalStateTransition ist) {
logger.error("Illegal State Transition : " + ist.getMessage());
}
}
} catch (IllegalStateTransition | DataAccessException | SRMException e) {
// FIXME some SRMException failures are temporary and others are
// permanent. Code currently doesn't distinguish between them and
// always retries, even if problem isn't transitory.
throw new NonFatalJobFailure(e.toString());
}
logger.info("PinId is "+getPinId()+" returning, scheduler should change state to \"Ready\"");
}
public void pinFile()
throws NonFatalJobFailure, FatalJobFailure, SRMException
{
GetRequest request = getContainerRequest();
if (!isProtocolSupported(request.protocols)) {
throw new FatalJobFailure("Transfer protocols not supported");
}
URI surl = getSurl();
logger.info("Pinning {}", surl);
getStorage().pinFile(getUser(),
surl,
getContainerRequest().getClient_host(),
lifetime,
String.valueOf(getRequestId()),
new ThePinCallbacks(getId()));
}
@Override
protected void stateChanged(State oldState) {
State state = getState();
logger.debug("State changed from "+oldState+" to "+getState());
if(state == State.READY) {
try {
getContainerRequest().resetRetryDeltaTime();
} catch (SRMInvalidRequestException ire) {
logger.error(ire.toString());
}
}
if(State.isFinalState(state)) {
if(getFileId() != null && getPinId() != null) {
UnpinCallbacks callbacks = new TheUnpinCallbacks(this.getId());
logger.info("state changed to final state, unpinning fileId= "+ getFileId()+" pinId = "+getPinId());
SRMUser user;
try {
user = getUser();
} catch (SRMInvalidRequestException ire) {
logger.error(ire.toString()) ;
return;
}
getStorage().unPinFile(user,getFileId(),callbacks, getPinId());
}
}
super.stateChanged(oldState);
}
private void computeTurl() throws SRMException
{
URI turl;
GetRequest request = getContainerRequest();
String firstDcapTurl = request.getFirstDcapTurl();
if (firstDcapTurl != null) {
turl = getStorage().getGetTurl(getUser(),
getSurl(),
URI.create(firstDcapTurl));
} else {
turl = getStorage().getGetTurl(getUser(),
getSurl(),
request.protocols);
if (turl.getScheme().equals("dcap")) {
request.setFirstDcapTurl(turl.toString());
}
}
setTurl(turl);
}
@Override
public boolean isTouchingSurl(URI surl)
{
return surl.equals(getSurl());
}
@Override
public TReturnStatus getReturnStatus()
{
String description = getLastJobChange().getDescription();
TStatusCode statusCode = getStatusCode();
if (statusCode != null) {
if (statusCode == TStatusCode.SRM_DONE || statusCode == TStatusCode.SRM_FILE_PINNED) {
description = null;
}
return new TReturnStatus(statusCode, description);
}
switch (getState()) {
case RESTORED:
case PENDING:
case RQUEUED:
return new TReturnStatus(TStatusCode.SRM_REQUEST_QUEUED, description);
case READY:
case TRANSFERRING:
return new TReturnStatus(TStatusCode.SRM_FILE_PINNED, null);
case DONE:
return new TReturnStatus(TStatusCode.SRM_RELEASED, null);
case CANCELED:
return new TReturnStatus(TStatusCode.SRM_ABORTED, description);
case FAILED:
return new TReturnStatus(TStatusCode.SRM_FAILURE, description);
default:
return new TReturnStatus(TStatusCode.SRM_REQUEST_INPROGRESS, description);
}
}
/**
*
* @param newLifetime new lifetime in millis
* -1 stands for infinite lifetime
* @return int lifetime left in millis
* -1 stands for infinite lifetime
*/
@Override
public long extendLifetime(long newLifetime) throws SRMException {
long remainingLifetime = getRemainingLifetime();
if(remainingLifetime >= newLifetime) {
return remainingLifetime;
}
long requestLifetime = getContainerRequest().extendLifetimeMillis(newLifetime);
if(requestLifetime <newLifetime) {
newLifetime = requestLifetime;
}
if(remainingLifetime >= newLifetime) {
return remainingLifetime;
}
newLifetime = extendLifetimeMillis(newLifetime);
if(remainingLifetime >= newLifetime) {
return remainingLifetime;
}
if(getPinId() == null) {
return newLifetime;
}
SRMUser user = getUser();
return getStorage().extendPinLifetime(user,getFileId(), getPinId(),newLifetime);
}
/**
* @param turl the turl to set
*/
private void setTurl(URI turl) {
wlock();
try {
this.turl = turl;
} finally {
wunlock();
}
}
/**
* @param fileId the fileId to set
*/
private void setFileId(String fileId) {
wlock();
try {
this.fileId = fileId;
} finally {
wunlock();
}
}
/**
* @return the fileMetaData
*/
private FileMetaData getFileMetaData() {
rlock();
try {
return fileMetaData;
} finally {
runlock();
}
}
/**
* @param fileMetaData the fileMetaData to set
*/
private void setFileMetaData(FileMetaData fileMetaData) {
wlock();
try {
this.fileMetaData = fileMetaData;
} finally {
wunlock();
}
}
public TReturnStatus release()
{
wlock();
try {
State state = getState();
switch (state) {
case READY:
setState(State.DONE, "TURL released.");
return new TReturnStatus(TStatusCode.SRM_SUCCESS, null);
case DONE:
return new TReturnStatus(TStatusCode.SRM_SUCCESS, null);
case CANCELED:
return new TReturnStatus(TStatusCode.SRM_ABORTED, "SURL has been aborted and cannot be released");
case FAILED:
return new TReturnStatus(TStatusCode.SRM_FAILURE, "Pinning failed");
default:
setState(State.CANCELED, "Aborted by srmReleaseFile request.");
return new TReturnStatus(TStatusCode.SRM_ABORTED, "SURL is not yet pinned, pinning aborted");
}
} catch (IllegalStateTransition e) {
return new TReturnStatus(TStatusCode.SRM_FAILURE, e.getMessage());
} finally {
wunlock();
}
}
private static class ThePinCallbacks implements PinCallbacks {
private final long fileRequestJobId;
public ThePinCallbacks(long fileRequestJobId) {
this.fileRequestJobId = fileRequestJobId;
}
public GetFileRequest getGetFileRequest()
throws SRMInvalidRequestException
{
return Job.getJob(fileRequestJobId, GetFileRequest.class);
}
@Override
public void FileNotFound(String reason) {
try {
GetFileRequest fr = getGetFileRequest();
try {
fr.setStateAndStatusCode(State.FAILED,
reason,
TStatusCode.SRM_INVALID_PATH);
}
catch(IllegalStateTransition ist) {
logger.warn("Illegal State Transition : " +ist.getMessage());
}
logger.warn("GetCallbacks error: "+ reason);
}
catch(Exception e) {
logger.error(e.toString());
}
}
@Override
public void Unavailable(String reason) {
try {
GetFileRequest fr = getGetFileRequest();
try {
fr.setStateAndStatusCode(State.FAILED,
reason,
TStatusCode.SRM_FILE_UNAVAILABLE);
}
catch(IllegalStateTransition ist) {
logger.warn("Illegal State Transition : " +ist.getMessage());
}
logger.error("GetCallbacks error: "+ reason);
}
catch(Exception e) {
logger.error(e.toString());
}
}
@Override
public void Error( String error) {
try {
GetFileRequest fr = getGetFileRequest();
try {
fr.setState(State.FAILED,error);
}
catch(IllegalStateTransition ist) {
logger.warn("Illegal State Transition : " +ist.getMessage());
}
logger.error("ThePinCallbacks error: "+ error);
}
catch(Exception e) {
logger.error(e.toString());
}
}
@Override
public void Exception( Exception e) {
try {
GetFileRequest fr = getGetFileRequest();
try {
fr.setState(State.FAILED,e.toString());
}
catch(IllegalStateTransition ist) {
logger.warn("Illegal State Transition : " +ist.getMessage());
}
logger.error("ThePinCallbacks exception",e);
}
catch(Exception e1) {
logger.error(e1.toString());
}
}
@Override
public void Timeout() {
try {
GetFileRequest fr = getGetFileRequest();
try {
fr.setState(State.FAILED, "Pin operation timed out.");
}
catch(IllegalStateTransition ist) {
logger.warn("Illegal State Transition : " +ist.getMessage());
}
logger.error("GetCallbacks Timeout");
}
catch(Exception e) {
logger.error(e.toString());
}
}
@Override
public void Pinned(FileMetaData fileMetaData, String pinId) {
try {
logger.debug("File pinned (pinId={})", pinId);
GetFileRequest fr = getGetFileRequest();
fr.wlock();
try {
State state = fr.getState();
if (state == State.ASYNCWAIT || state == State.RUNNING) {
fr.setFileId(fileMetaData.fileId);
fr.setFileMetaData(fileMetaData);
fr.setPinId(pinId);
if (state == State.ASYNCWAIT) {
Scheduler scheduler =
Scheduler.getScheduler(fr.getSchedulerId());
scheduler.schedule(fr);
}
}
} finally {
fr.wunlock();
}
} catch (InterruptedException e) {
logger.error(e.getMessage());
Thread.currentThread().interrupt();
} catch (SRMInvalidRequestException e) {
logger.error("BringOnlineFileRequest failed: {}", e.getMessage());
} catch (IllegalStateTransition e) {
logger.warn("Illegal State Transition: {}", e.getMessage());
}
}
@Override
public void PinningFailed(String reason) {
try {
GetFileRequest fr = getGetFileRequest();
try {
fr.setState(State.FAILED,reason);
}
catch(IllegalStateTransition ist) {
logger.warn("Illegal State Transition : " +ist.getMessage());
}
logger.error("ThePinCallbacks error: "+ reason);
}
catch(Exception e) {
logger.error(e.toString());
}
}
}
private static class TheUnpinCallbacks implements UnpinCallbacks {
private final long fileRequestJobId;
public TheUnpinCallbacks(long fileRequestJobId) {
this.fileRequestJobId = fileRequestJobId;
}
public GetFileRequest getGetFileRequest()
throws SRMInvalidRequestException {
return Job.getJob(fileRequestJobId, GetFileRequest.class);
}
@Override
public void Error( String error) {
try {
GetFileRequest fr = getGetFileRequest();
logger.error("TheUnpinCallbacks error: "+ error);
}
catch(Exception e) {
logger.error(e.toString());
}
}
@Override
public void Exception( Exception e) {
try {
GetFileRequest fr = getGetFileRequest();
logger.error("TheUnpinCallbacks exception",e);
}
catch(Exception e1) {
logger.error(e1.toString());
}
}
@Override
public void Timeout() {
try {
GetFileRequest fr = getGetFileRequest();
logger.error("TheUnpinCallbacks Timeout");
}
catch(Exception e) {
logger.error(e.toString());
}
}
@Override
public void Unpinned(String pinId) {
try {
GetFileRequest fr = getGetFileRequest();
logger.debug("TheUnpinCallbacks: Unpinned() pinId:"+pinId);
State state = fr.getState();
if(state == State.ASYNCWAIT) {
fr.setPinId(pinId);
Scheduler scheduler = Scheduler.getScheduler(fr.getSchedulerId());
try {
scheduler.schedule(fr);
}
catch(Exception ie) {
logger.error(ie.toString());
}
}
}
catch(Exception e) {
logger.error(e.toString());
}
}
@Override
public void UnpinningFailed(String reason) {
try {
GetFileRequest fr = getGetFileRequest();
logger.error("TheUnpinCallbacks error: "+ reason);
}
catch(Exception e) {
logger.error(e.toString());
}
}
}
}