use of org.dcache.srm.SRMDuplicationException in project dcache by dCache.
the class PutFileRequest method run.
@Override
public void run() throws IllegalStateTransition, SRMException {
LOGGER.trace("run");
if (!getState().isFinal()) {
if (getFileId() == null) {
// SRM_DUPLICATION_ERROR must be returned at the file level.
if (SRM.getSRM().hasMultipleUploads(getSurl())) {
if (!getContainerRequest().isOverwrite()) {
throw new SRMDuplicationException("The requested SURL is locked by another upload.");
} else {
throw new SRMFileBusyException("The requested SURL is locked by another upload.");
}
}
addHistoryEvent("Doing name space lookup.");
SRMUser user = getUser();
CheckedFuture<String, ? extends SRMException> future = getStorage().prepareToPut(user, getSurl(), getSize(), Objects.toString(getAccessLatency(), null), Objects.toString(getRetentionPolicy(), null), getSpaceReservationId(), getContainerRequest().isOverwrite());
future.addListener(new PutCallbacks(user, getId(), surl, future), MoreExecutors.directExecutor());
return;
}
computeTurl();
wlock();
try {
if (getState() == State.INPROGRESS) {
setState(State.RQUEUED, "Putting on a \"Ready\" Queue.");
}
} finally {
wunlock();
}
}
}
use of org.dcache.srm.SRMDuplicationException in project dcache by dCache.
the class Storage method putDone.
@Override
public void putDone(SRMUser user, String localTransferPath, URI surl, boolean overwrite) throws SRMException {
try {
Subject subject = asDcacheUser(user).getSubject();
Restriction restriction = asDcacheUser(user).getRestriction();
FsPath fullPath = getPath(surl);
checkNonBrokenUpload(localTransferPath);
EnumSet<CreateOption> options = EnumSet.noneOf(CreateOption.class);
if (overwrite) {
options.add(CreateOption.OVERWRITE_EXISTING);
}
PnfsCommitUpload msg = new PnfsCommitUpload(subject, restriction, FsPath.create(localTransferPath), fullPath, options, EnumSet.of(PNFSID, SIZE, STORAGEINFO));
msg = _pnfsStub.sendAndWait(msg);
DoorRequestInfoMessage infoMsg = new DoorRequestInfoMessage(getCellAddress());
infoMsg.setSubject(subject);
infoMsg.setBillingPath(fullPath.toString());
infoMsg.setTransferPath(localTransferPath);
infoMsg.setTransaction(CDC.getSession());
infoMsg.setPnfsId(msg.getFileAttributes().getPnfsId());
infoMsg.setResult(0, "");
infoMsg.setFileSize(msg.getFileAttributes().getSizeIfPresent().orElse(0L));
infoMsg.setStorageInfo(msg.getFileAttributes().getStorageInfo());
Origin origin = Subjects.getOrigin(subject);
if (origin != null) {
infoMsg.setClient(origin.getAddress().getHostAddress());
}
_billingStub.notify(infoMsg);
} catch (FileNotFoundCacheException e) {
throw new SRMInvalidPathException(e.getMessage(), e);
} catch (FileIsNewCacheException | FileCorruptedCacheException e) {
throw new SRMException(e.getMessage(), e);
} catch (PermissionDeniedCacheException e) {
throw new SRMAuthorizationException("Permission denied.", e);
} catch (FileExistsCacheException e) {
throw new SRMDuplicationException(surl + " exists.", e);
} catch (CacheException e) {
throw new SRMInternalErrorException(e.getMessage(), e);
} catch (InterruptedException e) {
throw new SRMInternalErrorException("Operation interrupted", e);
} catch (NoRouteToCellException e) {
throw new SRMInternalErrorException("Internal communication failure", e);
}
}
use of org.dcache.srm.SRMDuplicationException in project dcache by dCache.
the class Storage method moveEntry.
@Override
public void moveEntry(SRMUser abstractUser, URI from, URI to) throws SRMException {
DcacheUser user = asDcacheUser(abstractUser);
PnfsHandler handler = new PnfsHandler(_pnfs, user.getSubject(), user.getRestriction());
FsPath fromPath = getPath(from);
FsPath toPath = getPath(to);
try {
try {
FileAttributes attr = handler.getFileAttributes(toPath.toString(), EnumSet.of(TYPE));
/* We now know the destination exists. In case the
* source and destination names are identical, we
* silently ignore the request.
*/
if (fromPath.equals(toPath)) {
return;
}
if (attr.getFileType() != FileType.DIR) {
throw new SRMDuplicationException("Destination exists");
}
toPath = toPath.child(fromPath.name());
} catch (FileNotFoundCacheException e) {
/* Destination name does not exist; not a problem.
*/
}
handler.renameEntry(fromPath.toString(), toPath.toString(), false);
} catch (FileNotFoundCacheException e) {
throw new SRMInvalidPathException("No such file or directory", e);
} catch (FileExistsCacheException e) {
throw new SRMDuplicationException("Destination exists", e);
} catch (NotDirCacheException e) {
/* The parent of the target name did not exist or was not
* a directory.
*/
FsPath parent = toPath.parent();
throw new SRMInvalidPathException("No such directory: " + parent, e);
} catch (PermissionDeniedCacheException e) {
throw new SRMAuthorizationException("Permission denied");
} catch (TimeoutCacheException e) {
_log.error("Failed to rename {} due to timeout", fromPath);
throw new SRMInternalErrorException("Internal name space timeout");
} catch (CacheException e) {
_log.error("Failed to rename {}: {}", fromPath, e.getMessage());
throw new SRMException(String.format("Rename failed [rc=%d,msg=%s]", e.getRc(), e.getMessage()));
}
}
use of org.dcache.srm.SRMDuplicationException in project dcache by dCache.
the class Storage method createDirectory.
@Override
public void createDirectory(SRMUser abstractUser, URI surl) throws SRMException {
_log.debug("Storage.createDirectory");
DcacheUser user = asDcacheUser(abstractUser);
PnfsHandler handler = new PnfsHandler(_pnfs, user.getSubject(), user.getRestriction());
try {
handler.createPnfsDirectory(getPath(surl).toString());
} catch (TimeoutCacheException e) {
throw new SRMInternalErrorException("Internal name space timeout", e);
} catch (NotDirCacheException e) {
throw new SRMInvalidPathException("Parent path is not a directory", e);
} catch (FileNotFoundCacheException e) {
throw new SRMInvalidPathException("Parent path does not exist", e);
} catch (FileExistsCacheException e) {
throw new SRMDuplicationException("File exists");
} catch (PermissionDeniedCacheException e) {
throw new SRMAuthorizationException("Permission denied");
} catch (CacheException e) {
_log.error("Failed to create directory {}: {}", surl, e.getMessage());
throw new SRMException(String.format("Failed to create directory [rc=%d,msg=%s]", e.getRc(), e.getMessage()));
}
}
use of org.dcache.srm.SRMDuplicationException in project dcache by dCache.
the class Storage method prepareToPut.
@Override
public CheckedFuture<String, ? extends SRMException> prepareToPut(final SRMUser srmUser, URI surl, Long size, String accessLatency, String retentionPolicy, String spaceToken, boolean overwrite) {
try {
DcacheUser user = asDcacheUser(srmUser);
Subject subject = user.getSubject();
Restriction restriction = user.getRestriction();
FsPath fullPath = getPath(surl);
if (spaceToken != null) {
if (!_isSpaceManagerEnabled) {
return immediateFailedCheckedFuture(new SRMNotSupportedException(SPACEMANAGER_DISABLED_MESSAGE));
}
/* This check could and maybe should be done on the SRM side of AbstractStorageElement:
* The targetSpaceToken is the same for all SURLs in an srmPrepareToPut request, and the
* SRM_EXCEED_ALLOCATION should also be returned if the entire srmPrepareToPut request
* is larger than available space in the reservation - that's a check we cannot possibly
* to on an individual SURL.
*/
try {
Optional<Space> optionalSpace = spaces.get(spaceToken);
if (!optionalSpace.isPresent()) {
return immediateFailedCheckedFuture(new SRMInvalidRequestException("The space token " + spaceToken + " does not refer to an existing known space reservation."));
}
Space space = optionalSpace.get();
if (space.getExpirationTime() != null && space.getExpirationTime() < System.currentTimeMillis()) {
return immediateFailedCheckedFuture(new SRMSpaceLifetimeExpiredException("Space reservation associated with the space token " + spaceToken + " is expired."));
}
if (size != null && space.getAvailableSpaceInBytes() < size) {
return immediateFailedCheckedFuture(new SRMExceedAllocationException("Space associated with the space token " + spaceToken + " is not enough to hold SURL."));
}
} catch (ExecutionException e) {
return immediateFailedCheckedFuture(new SRMException("Failure while querying space reservation: " + e.getCause().getMessage()));
}
}
AccessLatency al = (accessLatency != null) ? AccessLatency.valueOf(accessLatency) : null;
RetentionPolicy rp = (retentionPolicy != null) ? RetentionPolicy.valueOf(retentionPolicy) : null;
EnumSet<CreateOption> options = EnumSet.noneOf(CreateOption.class);
if (overwrite) {
options.add(CreateOption.OVERWRITE_EXISTING);
}
if (config.isRecursiveDirectoryCreation()) {
options.add(CreateOption.CREATE_PARENTS);
}
PnfsCreateUploadPath msg = new PnfsCreateUploadPath(subject, restriction, fullPath, user.getRoot(), size, al, rp, spaceToken, options);
final SettableFuture<String> future = SettableFuture.create();
CellStub.addCallback(_pnfsStub.send(msg), new AbstractMessageCallback<PnfsCreateUploadPath>() {
int failures = 0;
@Override
public void success(PnfsCreateUploadPath message) {
future.set(message.getUploadPath().toString());
}
@Override
public void failure(int rc, Object error) {
failures++;
String msg = Objects.toString(error, "");
switch(rc) {
case CacheException.PERMISSION_DENIED:
future.setException(new SRMAuthorizationException(msg));
break;
case CacheException.FILE_EXISTS:
future.setException(new SRMDuplicationException(msg));
break;
case CacheException.FILE_NOT_FOUND:
case CacheException.NOT_DIR:
future.setException(new SRMInvalidPathException(msg));
break;
case CacheException.LOCKED:
if (failures < 3) {
/* Usually due to concurrent uploads to the same non-existing target
* directory. Retry a few times.
*/
PnfsCreateUploadPath retry = new PnfsCreateUploadPath(subject, restriction, fullPath, user.getRoot(), size, al, rp, spaceToken, options);
CellStub.addCallback(_pnfsStub.send(retry), this, _executor);
} else {
future.setException(new SRMInternalErrorException(msg));
}
break;
case CacheException.TIMEOUT:
default:
future.setException(new SRMInternalErrorException(msg));
break;
}
}
}, _executor);
return Futures.makeChecked(future, new ToSRMException());
} catch (SRMAuthorizationException | SRMInvalidPathException e) {
return immediateFailedCheckedFuture(e);
}
}
Aggregations