use of org.dcache.srm.FileMetaData in project dcache by dCache.
the class CopyFileRequest method runLocalToLocalCopy.
private void runLocalToLocalCopy() throws IllegalStateTransition, SRMException {
LOGGER.debug("copying from local to local");
FileMetaData fmd;
try {
fmd = getStorage().getFileMetaData(getUser(), getSourceSurl(), true);
} catch (SRMException srme) {
try {
setStateAndStatusCode(State.FAILED, srme.getMessage(), TStatusCode.SRM_INVALID_PATH);
} catch (IllegalStateTransition ist) {
LOGGER.error("Illegal State Transition : {}", ist.getMessage());
}
return;
}
setSize(fmd.size);
if (getDestinationFileId() == null) {
addHistoryEvent("Doing name space lookup.");
LOGGER.debug("calling storage.prepareToPut({})", getLocalDestinationPath());
CheckedFuture<String, ? extends SRMException> future = getStorage().prepareToPut(getUser(), getDestinationSurl(), size, Objects.toString(getContainerRequest().getTargetAccessLatency(), null), Objects.toString(getContainerRequest().getTargetRetentionPolicy(), null), getSpaceReservationId(), getContainerRequest().isOverwrite());
future.addListener(new PutCallbacks(getId(), future), directExecutor());
LOGGER.debug("callbacks.waitResult()");
return;
}
LOGGER.debug("known source size is {}", size);
try {
getStorage().localCopy(getUser(), getSourceSurl(), getDestinationFileId());
getStorage().putDone(getUser(), getDestinationFileId(), getDestinationSurl(), getContainerRequest().isOverwrite());
setStateToDone();
} catch (SRMException e) {
getStorage().abortPut(null, getDestinationFileId(), getDestinationSurl(), e.getMessage());
throw e;
}
}
use of org.dcache.srm.FileMetaData in project dcache by dCache.
the class LsFileRequest method run.
@Override
public synchronized void run() throws IllegalStateTransition {
LOGGER.trace("run");
if (!getState().isFinal()) {
try {
LsRequest parent = getContainerRequest();
long t0 = 0;
if (LOGGER.isDebugEnabled()) {
t0 = System.currentTimeMillis();
}
String fileId = SRM.getSRM().getUploadFileId(surl);
TMetaDataPathDetail detail;
if (fileId != null) {
// srmPrepareToPut (no srmPutDone is yet called) request for.
try {
FileMetaData fmd = getStorage().getFileMetaData(getUser(), surl, fileId);
detail = convertFileMetaDataToTMetaDataPathDetail(surl, fmd, parent.getLongFormat());
} catch (SRMInvalidPathException e) {
detail = new TMetaDataPathDetail();
detail.setType(TFileType.FILE);
}
detail.setPath(getPath(surl));
detail.setStatus(new TReturnStatus(TStatusCode.SRM_FILE_BUSY, "The requested SURL is locked by an upload."));
} else {
detail = getMetaDataPathDetail(surl, 0, parent.getOffset(), parent.getCount(), parent.getNumOfLevels(), parent.getLongFormat());
}
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("LsFileRequest.run(), TOOK {}", (System.currentTimeMillis() - t0));
}
try {
getContainerRequest().resetRetryDeltaTime();
} catch (SRMInvalidRequestException ire) {
LOGGER.error(ire.toString());
}
wlock();
try {
metaDataPathDetail = detail;
if (!getState().isFinal()) {
setState(State.DONE, State.DONE.toString());
}
} finally {
wunlock();
}
} catch (SRMException e) {
fail(e.getStatusCode(), e.getMessage());
} catch (URISyntaxException e) {
fail(TStatusCode.SRM_FAILURE, e.getMessage());
} catch (DataAccessException | IllegalStateTransition e) {
LOGGER.error(e.toString(), e);
fail(TStatusCode.SRM_INTERNAL_ERROR, e.getMessage());
}
}
}
use of org.dcache.srm.FileMetaData 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.FileMetaData in project dcache by dCache.
the class Storage method getFileMetaData.
private FileMetaData getFileMetaData(DcacheUser user, boolean checkReadPermissions, FsPath path) throws SRMException {
PnfsHandler handler = new PnfsHandler(_pnfs, user.getSubject(), user.getRestriction());
try {
/* Fetch file attributes.
*/
Set<FileAttribute> requestedAttributes = EnumSet.of(TYPE, LOCATIONS);
requestedAttributes.addAll(DcacheFileMetaData.getKnownAttributes());
requestedAttributes.addAll(PoolMonitorV5.getRequiredAttributesForFileLocality());
Set<AccessMask> accessMask = checkReadPermissions ? EnumSet.of(AccessMask.READ_DATA) : EnumSet.noneOf(AccessMask.class);
FileAttributes attributes = handler.getFileAttributes(path.toString(), requestedAttributes, accessMask, false);
FileMetaData fmd = new DcacheFileMetaData(attributes);
/* Determine file locality.
*/
if (attributes.getFileType() != FileType.DIR) {
FileLocality locality = _poolMonitor.getFileLocality(attributes, config.getSrmHost());
fmd.locality = locality.toTFileLocality();
fmd.isCached = locality.isCached();
}
/* Determine space tokens.
*/
if (_isSpaceManagerEnabled) {
try {
GetFileSpaceTokensMessage msg = new GetFileSpaceTokensMessage(attributes.getPnfsId());
msg = _spaceManagerStub.sendAndWait(msg);
if (msg.getSpaceTokens() != null) {
fmd.spaceTokens = new long[msg.getSpaceTokens().length];
System.arraycopy(msg.getSpaceTokens(), 0, fmd.spaceTokens, 0, msg.getSpaceTokens().length);
}
} catch (NoRouteToCellException e) {
/* SpaceManager is optional, so we don't classify this
* as an error.
*/
_log.info(e.getMessage());
}
}
return fmd;
} catch (TimeoutCacheException e) {
throw new SRMInternalErrorException(e.getMessage(), e);
} catch (PermissionDeniedCacheException e) {
throw new SRMAuthorizationException(e.getMessage(), e);
} catch (FileNotFoundCacheException e) {
throw new SRMInvalidPathException(e.getMessage(), e);
} catch (CacheException e) {
throw new SRMException("Could not get storage info by path: " + e.getMessage(), e);
} catch (InterruptedException e) {
throw new SRMInternalErrorException("Operation interrupted", e);
}
}
Aggregations