use of org.dcache.srm.scheduler.State in project dcache by dCache.
the class Job method getHistory.
protected CharSequence getHistory(String padding) {
StringBuilder historyStringBuillder = new StringBuilder();
long previousTransitionTime = 0;
State previousTransitionState = State.UNSCHEDULED;
rlock();
try {
SimpleDateFormat format = new SimpleDateFormat(TimeUtils.TIMESTAMP_FORMAT);
for (JobHistory nextHistoryElement : jobHistory) {
if (historyStringBuillder.length() != 0) {
appendDuration(historyStringBuillder, nextHistoryElement.getTransitionTime() - previousTransitionTime, "").append('\n');
}
previousTransitionTime = nextHistoryElement.getTransitionTime();
historyStringBuillder.append(padding);
historyStringBuillder.append(" ").append(format.format(new Date(nextHistoryElement.getTransitionTime())));
historyStringBuillder.append(" ").append(nextHistoryElement.getState());
historyStringBuillder.append(": ");
historyStringBuillder.append(nextHistoryElement.getDescription());
previousTransitionState = nextHistoryElement.getState();
}
} finally {
runlock();
}
if (historyStringBuillder.length() != 0) {
if (!previousTransitionState.isFinal()) {
long duration = System.currentTimeMillis() - previousTransitionTime;
appendDuration(historyStringBuillder, duration, ", so far");
}
historyStringBuillder.append('\n');
}
return historyStringBuillder;
}
use of org.dcache.srm.scheduler.State in project dcache by dCache.
the class Job method setState.
/**
* Changes the state of this job to a new state.
*/
public final void setState(State newState, String description) throws IllegalStateTransition {
wlock();
boolean isDowngraded = false;
try {
State oldState = state;
try {
if (newState == state) {
return;
}
if (!isValidTransition(state, newState)) {
throw new IllegalStateTransition("Illegal state transition from " + state + " to " + newState, state, newState);
}
processStateChange(newState, description);
saveJob(state == State.RQUEUED);
// Downgrade from write lock to read lock
rlock();
isDowngraded = true;
} finally {
wunlock();
}
notifyListeners(oldState, description);
} finally {
if (isDowngraded) {
runlock();
}
}
}
use of org.dcache.srm.scheduler.State in project dcache by dCache.
the class PutFileRequest method toString.
@Override
public void toString(StringBuilder sb, String padding, boolean longformat) {
sb.append(padding);
if (padding.isEmpty()) {
sb.append("Put ");
}
sb.append("file id:").append(getId());
State state = getState();
sb.append(" state:").append(state);
if (longformat) {
sb.append('\n');
sb.append(padding).append(" SURL: ").append(getSurlString()).append('\n');
sb.append(padding).append(" TURL: ").append(getTurlString()).append('\n');
if (getSize() != null) {
sb.append(padding).append(" Size: ").append(getSize()).append('\n');
}
TAccessLatency al = getAccessLatency();
if (al != null) {
sb.append(padding).append(" Access latency: ").append(al).append('\n');
}
TRetentionPolicy rp = getRetentionPolicy();
if (rp != null) {
sb.append(padding).append(" Retention policy: ").append(rp).append('\n');
}
String space = getSpaceReservationId();
if (space != null) {
sb.append(padding).append(" Space reservation: ").append(space).append('\n');
}
TStatusCode status = getStatusCode();
if (status != null) {
sb.append(padding).append(" Status:").append(status).append('\n');
}
sb.append(padding).append(" History:\n");
sb.append(getHistory(padding + " "));
}
}
use of org.dcache.srm.scheduler.State in project dcache by dCache.
the class PutRequest method abort.
/**
* this callbacks are given to storage.prepareToPut storage.prepareToPut calls methods of
* callbacks to indicate progress
*/
@Override
public TReturnStatus abort(String reason) {
wlock();
try {
/* [ SRM 2.2, 5.11.2 ]
*
* a) srmAbortRequest terminates all files in the request regardless of the file
* state. Remove files from the queue, and release cached files if a limited
* lifetime is associated with the file.
* c) Abort must be allowed to all requests with requestToken.
* f) When aborting srmPrepareToPut request before srmPutDone and before the file
* transfer, the SURL must not exist as the result of the successful abort on
* the SURL. Any srmRm request on the SURL must fail.
* g) When aborting srmPrepareToPut request before srmPutDone and after the file
* transfer, the SURL may exist, and a srmRm request on the SURL may remove
* the requested SURL.
* h) When aborting srmPrepareToPut request after srmPutDone, it must be failed
* for those files. An explicit srmRm is required to remove those successfully
* completed files for srmPrepareToPut.
* i) When duplicate abort request is issued on the same request, SRM_SUCCESS
* may be returned to all duplicate abort requests and no operations on
* duplicate abort requests are performed.
*/
boolean hasSuccess = false;
boolean hasFailure = false;
boolean hasCompleted = false;
updateStatus();
State state = getState();
if (!state.isFinal()) {
for (PutFileRequest file : getFileRequests()) {
try {
file.abort(reason);
hasSuccess = true;
} catch (SRMException e) {
hasFailure = true;
} catch (IllegalStateTransition e) {
if (e.getFromState() == State.DONE) {
hasCompleted = true;
}
hasFailure = true;
}
}
try {
setStateAndStatusCode(State.CANCELED, "Request aborted", TStatusCode.SRM_ABORTED);
} catch (IllegalStateTransition e) {
hasFailure = true;
}
} else if (state == State.DONE) {
return new TReturnStatus(TStatusCode.SRM_FAILURE, "Put request completed successfully and cannot be aborted");
}
TReturnStatus returnStatus = getSummaryReturnStatus(hasFailure, hasSuccess);
if (hasCompleted) {
returnStatus = new TReturnStatus(returnStatus.getStatusCode(), "Some SURLs have completed successfully and cannot be aborted");
}
return returnStatus;
} finally {
wunlock();
}
}
use of org.dcache.srm.scheduler.State 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);
}
Aggregations