Search in sources :

Example 1 with State

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;
}
Also used : Preconditions.checkState(com.google.common.base.Preconditions.checkState) State(org.dcache.srm.scheduler.State) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 2 with State

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();
        }
    }
}
Also used : IllegalStateTransition(org.dcache.srm.scheduler.IllegalStateTransition) Preconditions.checkState(com.google.common.base.Preconditions.checkState) State(org.dcache.srm.scheduler.State)

Example 3 with State

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 + "   "));
    }
}
Also used : State(org.dcache.srm.scheduler.State) TRetentionPolicy(org.dcache.srm.v2_2.TRetentionPolicy) TAccessLatency(org.dcache.srm.v2_2.TAccessLatency) TStatusCode(org.dcache.srm.v2_2.TStatusCode)

Example 4 with State

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();
    }
}
Also used : IllegalStateTransition(org.dcache.srm.scheduler.IllegalStateTransition) SRMException(org.dcache.srm.SRMException) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) State(org.dcache.srm.scheduler.State)

Example 5 with State

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);
}
Also used : SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) SRMUser(org.dcache.srm.SRMUser) SRMException(org.dcache.srm.SRMException) AbstractStorageElement(org.dcache.srm.AbstractStorageElement) State(org.dcache.srm.scheduler.State) SRMInvalidRequestException(org.dcache.srm.SRMInvalidRequestException)

Aggregations

State (org.dcache.srm.scheduler.State)17 IllegalStateTransition (org.dcache.srm.scheduler.IllegalStateTransition)8 SRMException (org.dcache.srm.SRMException)6 TStatusCode (org.dcache.srm.v2_2.TStatusCode)4 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)3 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)3 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)3 Preconditions.checkState (com.google.common.base.Preconditions.checkState)2 AbstractStorageElement (org.dcache.srm.AbstractStorageElement)2 SRMUser (org.dcache.srm.SRMUser)2 IOException (java.io.IOException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 TimeoutException (java.util.concurrent.TimeoutException)1 TurlGetterPutter (org.dcache.srm.client.TurlGetterPutter)1 TAccessLatency (org.dcache.srm.v2_2.TAccessLatency)1 TRetentionPolicy (org.dcache.srm.v2_2.TRetentionPolicy)1