use of org.dcache.srm.SRMUser 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.SRMUser in project dcache by dCache.
the class DatabaseRequestStorage method getJob.
@Override
protected final R getJob(Connection _con, long ID, Long NEXTJOBID, long CREATIONTIME, long LIFETIME, int STATE, String SCHEDULERID, long SCHEDULER_TIMESTAMP, int NUMOFRETR, long LASTSTATETRANSITIONTIME, ResultSet set, int next_index) throws SQLException {
Long CREDENTIALID = set.getLong(next_index++);
int RETRYDELTATIME = set.getInt(next_index++);
boolean SHOULDUPDATERETRYDELTATIME = set.getBoolean(next_index++);
String DESCRIPTION = set.getString(next_index++);
String CLIENTHOST = set.getString(next_index++);
String STATUSCODE = set.getString(next_index++);
long id = set.getLong(next_index++);
SRMUser user = set.wasNull() ? srmUserPersistenceManager.createAnonymous() : // FIXME: Using client host for this is not correct as the client may specify a different host
srmUserPersistenceManager.find(CLIENTHOST, id);
return getRequest(_con, ID, NEXTJOBID, CREATIONTIME, LIFETIME, STATE, user, SCHEDULERID, SCHEDULER_TIMESTAMP, NUMOFRETR, LASTSTATETRANSITIONTIME, CREDENTIALID, RETRYDELTATIME, SHOULDUPDATERETRYDELTATIME, DESCRIPTION, CLIENTHOST, STATUSCODE, set, next_index);
}
use of org.dcache.srm.SRMUser in project dcache by dCache.
the class SrmService method messageArrived.
public SrmResponse messageArrived(SrmRequest request) throws SRMException {
try {
CertPath certPath = getFirst(request.getSubject().getPublicCredentials(CertPath.class), null);
LoginReply login = new LoginReply(request.getSubject(), request.getLoginAttributes());
SRMUser user = userManager.persist(certPath, login);
String requestName = request.getRequestName();
Class<?> requestClass = request.getRequest().getClass();
String capitalizedRequestName = Character.toUpperCase(requestName.charAt(0)) + requestName.substring(1);
LOGGER.debug("About to call {} handler", requestName);
Constructor<?> handlerConstructor;
Object handler;
Method handleGetResponseMethod;
try {
Class<?> handlerClass = Class.forName("org.dcache.srm.handler." + capitalizedRequestName);
handlerConstructor = handlerClass.getConstructor(SRMUser.class, requestClass, AbstractStorageElement.class, SRM.class, String.class);
handler = handlerConstructor.newInstance(user, request.getRequest(), storage, srm, request.getRemoteHost());
if (handler instanceof CredentialAwareHandler) {
CredentialAwareHandler credentialAware = (CredentialAwareHandler) handler;
RequestCredential requestCredential = saveRequestCredential(request.getSubject(), request.getCredential());
credentialAware.setCredential(requestCredential);
}
handleGetResponseMethod = handlerClass.getMethod("getResponse");
} catch (ClassNotFoundException e) {
if (LOGGER.isDebugEnabled()) {
LOGGER.info("handler discovery and dynamic loading failed", e);
} else {
LOGGER.info("handler discovery and dynamic loading failed");
}
throw new SRMNotSupportedException(requestName + " is unsupported");
}
Object result = handleGetResponseMethod.invoke(handler);
return new SrmResponse(id, result);
} catch (CertificateEncodingException | KeyStoreException e) {
throw new SRMInternalErrorException("Failed to process certificate chain.", e);
} catch (InvocationTargetException | NoSuchMethodException | InstantiationException | IllegalAccessException | RuntimeException e) {
LOGGER.error("Please report this failure to support@dcache.org", e);
throw new SRMInternalErrorException("Internal error (server log contains additional information)");
}
}
use of org.dcache.srm.SRMUser in project dcache by dCache.
the class BringOnlineFileRequest method processStateChange.
@Override
protected void processStateChange(State newState, String description) {
State oldState = getState();
LOGGER.debug("State changed from {} to {}", oldState, getState());
switch(newState) {
case READY:
try {
getContainerRequest().resetRetryDeltaTime();
} catch (SRMInvalidRequestException ire) {
LOGGER.error(ire.toString());
}
break;
case CANCELED:
case FAILED:
try {
SRMUser user = getUser();
String pinId = getPinId();
String fileId = getFileId();
AbstractStorageElement storage = getStorage();
if (fileId != null && pinId != null) {
LOGGER.info("State changed to final state, unpinning fileId = {} pinId = {}.", fileId, pinId);
CheckedFuture<String, ? extends SRMException> future = storage.unPinFile(null, fileId, pinId);
future.addListener(() -> {
try {
LOGGER.debug("File unpinned (pinId={}).", future.checkedGet());
} catch (SRMException e) {
LOGGER.error("Unpinning failed: {}", e.getMessage());
}
}, MoreExecutors.directExecutor());
} else {
unpinBySURLandRequestToken(storage, user, String.valueOf(getRequestId()), getSurl());
}
} catch (SRMInternalErrorException | SRMInvalidRequestException ire) {
LOGGER.error(ire.toString());
}
break;
}
super.processStateChange(newState, description);
}
use of org.dcache.srm.SRMUser in project dcache by dCache.
the class BringOnlineRequest method release.
public TSURLReturnStatus[] release() throws SRMInternalErrorException {
SRMUser user = getUser();
int len = getNumOfFileRequest();
TSURLReturnStatus[] surlReturnStatuses = new TSURLReturnStatus[len];
LOGGER.debug("releaseFiles, releasing all {} files", len);
List<BringOnlineFileRequest> requests = getFileRequests();
for (int i = 0; i < len; i++) {
BringOnlineFileRequest request = requests.get(i);
org.apache.axis.types.URI surl;
try {
surl = new org.apache.axis.types.URI(request.getSurlString());
} catch (org.apache.axis.types.URI.MalformedURIException e) {
throw new RuntimeException("Failed to convert Java URI to Axis URI. " + "Please report this to support@dcache.org: " + e.getMessage(), e);
}
surlReturnStatuses[i] = new TSURLReturnStatus(surl, request.release(user));
}
return surlReturnStatuses;
}
Aggregations