use of org.dcache.srm.v2_2.SrmLsResponse in project dcache by dCache.
the class LsRequest method getSrmLsResponse.
public final SrmLsResponse getSrmLsResponse() throws SRMInvalidRequestException {
SrmLsResponse response = new SrmLsResponse();
response.setReturnStatus(getTReturnStatus());
if (!response.getReturnStatus().getStatusCode().isProcessing()) {
response.setDetails(new ArrayOfTMetaDataPathDetail(getPathDetailArray()));
} else {
response.setDetails(null);
}
response.setRequestToken(getTRequestToken());
return response;
}
use of org.dcache.srm.v2_2.SrmLsResponse in project dcache by dCache.
the class SRMLsClientV2 method start.
@Override
public void start() throws Exception {
checkCredentialValid();
try {
SrmLsRequest req = new SrmLsRequest();
req.setAllLevelRecursive(Boolean.FALSE);
req.setFullDetailedList(configuration.isLongLsFormat());
req.setNumOfLevels(configuration.getRecursionDepth());
req.setOffset(configuration.getLsOffset());
if (configuration.getLsCount() != null) {
req.setCount(configuration.getLsCount());
}
URI[] turlia = new URI[surls.length];
for (int i = 0; i < surls.length; ++i) {
turlia[i] = new URI(surl_strings[i]);
}
req.setArrayOfSURLs(new ArrayOfAnyURI(turlia));
hook = new Thread(this);
Runtime.getRuntime().addShutdownHook(hook);
configuration.getStorageSystemInfo().ifPresent(req::setStorageSystemInfo);
SrmLsResponse response = srm.srmLs(req);
if (response == null) {
throw new Exception("srm ls response is null!");
}
TReturnStatus rs = response.getReturnStatus();
requestToken = response.getRequestToken();
if (rs == null) {
throw new IOException(" null TReturnStatus ");
}
StringBuffer sb = new StringBuffer();
String statusText = "Return status:\n" + " - Status code: " + response.getReturnStatus().getStatusCode().getValue() + '\n' + " - Explanation: " + response.getReturnStatus().getExplanation();
logger.log(statusText);
if (RequestStatusTool.isFailedRequestStatus(rs)) {
sb.append(statusText).append('\n');
}
if (!RequestStatusTool.isTransientStateStatus(rs)) {
if (response.getDetails() == null) {
throw new IOException(sb.toString() + "srm ls response path details array is null!");
} else {
if (response.getDetails().getPathDetailArray() != null) {
TMetaDataPathDetail[] details = response.getDetails().getPathDetailArray();
printResults(sb, details, 0, " ", configuration.isLongLsFormat());
}
}
if (RequestStatusTool.isFailedRequestStatus(rs)) {
throw new IOException(sb.toString());
}
System.out.println(sb.toString());
} else {
if (requestToken == null) {
throw new IOException("Request is queued on the server, however the server did not provide a request token.");
}
if (RequestStatusTool.isFailedRequestStatus(rs)) {
throw new IOException(sb.toString());
}
// we assume this is asynchronous call
SrmStatusOfLsRequestRequest statusRequest = new SrmStatusOfLsRequestRequest();
statusRequest.setRequestToken(requestToken);
statusRequest.setOffset(req.getOffset());
statusRequest.setCount(req.getCount());
statusRequest.setAuthorizationID(req.getAuthorizationID());
long estimatedWaitInSeconds = 2;
while (true) {
if (estimatedWaitInSeconds > 60) {
estimatedWaitInSeconds = 60;
}
try {
say("sleeping " + estimatedWaitInSeconds + " seconds ...");
Thread.sleep(estimatedWaitInSeconds * 1000);
} catch (InterruptedException ie) {
esay("Interrupted, quitting");
if (requestToken != null) {
abortRequest();
}
System.exit(1);
}
estimatedWaitInSeconds *= 2;
SrmStatusOfLsRequestResponse statusResponse = srm.srmStatusOfLsRequest(statusRequest);
if (statusResponse == null) {
throw new IOException("SrmStatusOfLsRequestResponse is null for request " + requestToken);
}
TReturnStatus status = statusResponse.getReturnStatus();
if (status == null) {
throw new IOException(" null return status");
}
if (status.getStatusCode() == null) {
throw new IOException(" null status code");
}
if (!RequestStatusTool.isTransientStateStatus(status)) {
statusText = "Return status:\n" + " - Status code: " + status.getStatusCode().getValue() + '\n' + " - Explanation: " + status.getExplanation() + '\n' + " - request token: " + requestToken;
logger.log(statusText);
if (RequestStatusTool.isFailedRequestStatus(status)) {
sb.append(statusText).append('\n');
}
if (statusResponse.getDetails() == null) {
throw new IOException(sb.toString() + "srm ls response path details array is null!");
} else {
if (statusResponse.getDetails().getPathDetailArray() != null) {
TMetaDataPathDetail[] details = statusResponse.getDetails().getPathDetailArray();
printResults(sb, details, 0, " ", configuration.isLongLsFormat());
if (RequestStatusTool.isFailedRequestStatus(status)) {
throw new IOException(sb.toString());
}
System.out.println(sb.toString());
}
}
break;
}
}
}
} catch (Exception e) {
esay(e.getMessage());
try {
if (requestToken != null) {
abortRequest();
}
} catch (Exception e1) {
logger.elog(e1.toString());
} finally {
Runtime.getRuntime().removeShutdownHook(hook);
System.exit(1);
}
} finally {
Runtime.getRuntime().removeShutdownHook(hook);
}
}
use of org.dcache.srm.v2_2.SrmLsResponse in project dcache by dCache.
the class SrmLs method getFailedResponse.
public static final SrmLsResponse getFailedResponse(String error, TStatusCode statusCode) {
SrmLsResponse response = new SrmLsResponse();
response.setReturnStatus(new TReturnStatus(statusCode, error));
return response;
}
use of org.dcache.srm.v2_2.SrmLsResponse in project dcache by dCache.
the class LsRequest method getSrmLsResponse.
/**
* Waits for up to timeout milliseconds for the request to reach a non-queued state and then
* returns the current SrmLsResponse for this LsRequest.
*/
public final SrmLsResponse getSrmLsResponse(long timeout) throws InterruptedException, SRMInvalidRequestException {
/* To avoid a race condition between us querying the
* current response and us waiting for a state change
* notification, the notification scheme is counter
* based. This guarantees that we do not loose any
* notifications. A simple lock around the whole loop
* would not have worked, as the call to
* getSrmLsResponse may itself trigger a state change
* and thus cause a deadlock when the state change is
* signaled.
*/
Date deadline = getDateRelativeToNow(timeout);
int counter = _stateChangeCounter.get();
SrmLsResponse response = getSrmLsResponse();
while (response.getReturnStatus().getStatusCode().isProcessing() && deadline.after(new Date()) && _stateChangeCounter.awaitChangeUntil(counter, deadline)) {
counter = _stateChangeCounter.get();
response = getSrmLsResponse();
}
return response;
}
use of org.dcache.srm.v2_2.SrmLsResponse in project dcache by dCache.
the class AxisSrmFileSystem method doBulkStat.
private TMetaDataPathDetail[] doBulkStat(URI[] surls) throws RemoteException, SRMException, InterruptedException {
SrmLsResponse response = srm.srmLs(new SrmLsRequest(null, new ArrayOfAnyURI(surls), null, null, true, false, 0, 0, surls.length));
ArrayOfTMetaDataPathDetail details;
if (response.getReturnStatus().getStatusCode() != TStatusCode.SRM_REQUEST_QUEUED && response.getReturnStatus().getStatusCode() != TStatusCode.SRM_REQUEST_INPROGRESS) {
checkSuccess(response.getReturnStatus(), TStatusCode.SRM_SUCCESS, TStatusCode.SRM_PARTIAL_SUCCESS, TStatusCode.SRM_FAILURE);
details = response.getDetails();
} else {
SrmStatusOfLsRequestResponse status;
do {
TimeUnit.SECONDS.sleep(1);
status = srm.srmStatusOfLsRequest(new SrmStatusOfLsRequestRequest(null, response.getRequestToken(), 0, surls.length));
} while (status.getReturnStatus().getStatusCode() == TStatusCode.SRM_REQUEST_QUEUED || status.getReturnStatus().getStatusCode() == TStatusCode.SRM_REQUEST_INPROGRESS);
checkSuccess(status.getReturnStatus(), TStatusCode.SRM_SUCCESS, TStatusCode.SRM_PARTIAL_SUCCESS, TStatusCode.SRM_FAILURE);
details = status.getDetails();
}
return details.getPathDetailArray();
}
Aggregations