use of org.dcache.srm.v2_2.SrmLsRequest 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.SrmLsRequest 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();
}
use of org.dcache.srm.v2_2.SrmLsRequest in project dcache by dCache.
the class AxisSrmFileSystem method list.
private TMetaDataPathDetail list(URI surl, boolean verbose, int offset, int count) throws RemoteException, SRMException, InterruptedException {
SrmLsResponse response = srm.srmLs(new SrmLsRequest(null, new ArrayOfAnyURI(new URI[] { surl }), null, null, verbose, false, 1, offset, count));
while (response.getReturnStatus().getStatusCode() == TStatusCode.SRM_REQUEST_QUEUED || response.getReturnStatus().getStatusCode() == TStatusCode.SRM_REQUEST_INPROGRESS) {
TimeUnit.SECONDS.sleep(1);
SrmStatusOfLsRequestResponse status = srm.srmStatusOfLsRequest(new SrmStatusOfLsRequestRequest(null, response.getRequestToken(), offset, count));
response.setDetails(status.getDetails());
response.setReturnStatus(status.getReturnStatus());
}
checkSuccess(response.getReturnStatus());
TMetaDataPathDetail details = response.getDetails().getPathDetailArray()[0];
checkBulkSuccess(response.getReturnStatus(), Collections.singletonList(details.getStatus()));
return details;
}
Aggregations