use of org.dcache.srm.v2_2.ArrayOfTMetaDataPathDetail in project dcache by dCache.
the class LsFileRequest method getRecursiveMetaDataPathDetail.
private void getRecursiveMetaDataPathDetail(TMetaDataPathDetail metaDataPathDetail, FileMetaData fmd, int depth, long offset, long count, int recursionDepth, boolean longFormat) throws SRMException, URISyntaxException {
if (!fmd.isDirectory || depth >= recursionDepth) {
return;
}
List<FileMetaData> directoryList;
URI surl = new URI(null, null, metaDataPathDetail.getPath(), null);
// rely on our own counting
if (offset == 0) {
//
// if offset=0, trivial case, just grab information w/ verbosity level
// provided by the user
//
directoryList = getStorage().listDirectory(getUser(), surl, longFormat, 0, (int) count);
} else {
//
// if offset!=0, we loop over direntries in non-verbose mode until
// we hit offset, then start getting information with verbosity
// level specified by the user by calling getStorage().getFileMetaData on
// each entry
//
directoryList = getStorage().listDirectory(getUser(), surl, false, 0, Integer.MAX_VALUE);
}
//
// sort list such that directories are at the end of the list after
// sorting. The intent is to leave the recursion calls at the
// end of the tree, so we have less chance to even get there
//
Collections.sort(directoryList, DIRECTORY_LAST_ORDER);
List<TMetaDataPathDetail> metadataPathDetailList = new LinkedList<>();
for (FileMetaData md : directoryList) {
URI subpath = new URI(null, null, md.SURL, null);
TMetaDataPathDetail dirMetaDataPathDetail;
if (offset == 0) {
dirMetaDataPathDetail = convertFileMetaDataToTMetaDataPathDetail(subpath, md, longFormat);
} else {
FileMetaData fileMetaData = md;
if (!getContainerRequest().shouldSkipThisRecord()) {
if (longFormat) {
fileMetaData = getStorage().getFileMetaData(getUser(), subpath, false);
}
dirMetaDataPathDetail = convertFileMetaDataToTMetaDataPathDetail(subpath, fileMetaData, longFormat);
} else {
//
// skip this record - meaning count it, and request only minimal details, do not store it
//
dirMetaDataPathDetail = convertFileMetaDataToTMetaDataPathDetail(subpath, fileMetaData, false);
}
}
if (!getContainerRequest().shouldSkipThisRecord()) {
metadataPathDetailList.add(dirMetaDataPathDetail);
try {
if (!getContainerRequest().increaseResultsNumAndContinue()) {
break;
}
} catch (SRMTooManyResultsException e) {
metaDataPathDetail.setStatus(new TReturnStatus(TStatusCode.SRM_FAILURE, e.getMessage()));
break;
}
}
//
// increment global entries counter
//
getContainerRequest().incrementGlobalEntryCounter();
if (md.isDirectory) {
try {
getRecursiveMetaDataPathDetail(dirMetaDataPathDetail, md, depth + 1, offset, count, recursionDepth, longFormat);
} catch (SRMException e) {
String msg = e.getMessage();
if (e instanceof SRMAuthorizationException) {
dirMetaDataPathDetail.setStatus(new TReturnStatus(TStatusCode.SRM_AUTHORIZATION_FAILURE, msg));
} else if (e instanceof SRMInvalidPathException) {
dirMetaDataPathDetail.setStatus(new TReturnStatus(TStatusCode.SRM_INVALID_PATH, msg));
} else {
dirMetaDataPathDetail.setStatus(new TReturnStatus(TStatusCode.SRM_FAILURE, msg));
}
}
}
}
metaDataPathDetail.setArrayOfSubPaths(new ArrayOfTMetaDataPathDetail(metadataPathDetailList.toArray(TMetaDataPathDetail[]::new)));
}
use of org.dcache.srm.v2_2.ArrayOfTMetaDataPathDetail 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.ArrayOfTMetaDataPathDetail in project dcache by dCache.
the class LsFileRequest method getMetaDataPathDetail.
private void getMetaDataPathDetail(TMetaDataPathDetail metaDataPathDetail, long offset, long count, boolean longFormat) throws SRMException, URISyntaxException {
List<FileMetaData> directoryList;
//
// simplify things for the most common case when people perform
// ls on directory w/o specifying recursionDepth
//
URI surl = new URI(null, null, metaDataPathDetail.getPath(), null);
directoryList = getStorage().listDirectory(getUser(), surl, longFormat, (int) offset, (int) count);
getContainerRequest().setCounter(offset);
List<TMetaDataPathDetail> metadataPathDetailList = new LinkedList<>();
for (FileMetaData md : directoryList) {
URI subpath = new URI(null, null, md.SURL, null);
TMetaDataPathDetail dirMetaDataPathDetail = convertFileMetaDataToTMetaDataPathDetail(subpath, md, longFormat);
if (!getContainerRequest().shouldSkipThisRecord()) {
metadataPathDetailList.add(dirMetaDataPathDetail);
try {
if (!getContainerRequest().increaseResultsNumAndContinue()) {
break;
}
} catch (SRMTooManyResultsException e) {
metaDataPathDetail.setStatus(new TReturnStatus(TStatusCode.SRM_FAILURE, e.getMessage()));
break;
}
}
//
// increment global entries counter
//
getContainerRequest().incrementGlobalEntryCounter();
}
metaDataPathDetail.setArrayOfSubPaths(new ArrayOfTMetaDataPathDetail(metadataPathDetailList.toArray(TMetaDataPathDetail[]::new)));
}
use of org.dcache.srm.v2_2.ArrayOfTMetaDataPathDetail 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