Search in sources :

Example 1 with PutRequest

use of org.dcache.srm.request.PutRequest in project dcache by dCache.

the class PutRequestStorage method getBatchCreateStatement.

@Override
public PreparedStatement getBatchCreateStatement(Connection connection, Job job) throws SQLException {
    if (job == null || !(job instanceof PutRequest)) {
        throw new IllegalArgumentException("Request is not PutRequest");
    }
    PutRequest pr = (PutRequest) job;
    String[] protocols = pr.getProtocols();
    if (protocols == null) {
        return null;
    }
    PreparedStatement statement = connection.prepareStatement(insertProtocols);
    for (String protocol : protocols) {
        statement.setString(1, protocol);
        statement.setLong(2, pr.getId());
        statement.addBatch();
    }
    return statement;
}
Also used : PutRequest(org.dcache.srm.request.PutRequest) PreparedStatement(java.sql.PreparedStatement)

Example 2 with PutRequest

use of org.dcache.srm.request.PutRequest in project dcache by dCache.

the class SchedulerContainerTests method shouldSchedulePutRequest.

@Test
public void shouldSchedulePutRequest() throws Exception {
    PutRequest job = mockJob(PutRequest.class);
    ArgumentCaptor<Scheduler> schedCapture = ArgumentCaptor.forClass(Scheduler.class);
    container.schedule(job);
    verify(job, times(1)).scheduleWith(schedCapture.capture());
    assertThat(schedCapture.getValue(), is(putScheduler));
}
Also used : PutRequest(org.dcache.srm.request.PutRequest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 3 with PutRequest

use of org.dcache.srm.request.PutRequest in project dcache by dCache.

the class SrmPrepareToPut method srmPrepareToPut.

private SrmPrepareToPutResponse srmPrepareToPut() throws IllegalStateTransition, InterruptedException, SRMNotSupportedException, SRMInvalidRequestException, SRMInternalErrorException {
    checkFileStorageType(request, TFileStorageType.PERMANENT);
    String[] protocols = getProtocols();
    String clientHost = getClientHost(request).orElse(this.clientHost);
    String spaceToken = request.getTargetSpaceToken();
    TRetentionPolicy retentionPolicy = null;
    TAccessLatency accessLatency = null;
    if (request.getTargetFileRetentionPolicyInfo() != null) {
        retentionPolicy = request.getTargetFileRetentionPolicyInfo().getRetentionPolicy();
        accessLatency = request.getTargetFileRetentionPolicyInfo().getAccessLatency();
    }
    TPutFileRequest[] fileRequests = getFileRequests(request);
    // assume transfers will take place in parallel
    long effectiveSize = largestFileOf(fileRequests);
    long lifetime = Lifetimes.calculateLifetime(request.getDesiredTotalRequestTime(), effectiveSize, configuration.getMaximumClientAssumedBandwidth(), configuration.getPutLifetime());
    TOverwriteMode overwriteMode = getOverwriteMode(request);
    String[] supportedProtocols = storage.supportedPutProtocols();
    boolean isAnyProtocolSupported = any(asList(protocols), in(asList(supportedProtocols)));
    if (!isAnyProtocolSupported) {
        throw new SRMNotSupportedException("Protocol(s) not supported: " + Arrays.toString(protocols));
    }
    URI[] surls = new URI[fileRequests.length];
    Long[] sizes = new Long[fileRequests.length];
    boolean[] wantPermanent = new boolean[fileRequests.length];
    for (int i = 0; i < fileRequests.length; ++i) {
        TPutFileRequest fileRequest = fileRequests[i];
        if (fileRequest == null) {
            throw new SRMInvalidRequestException("file request #" + (i + 1) + " is null.");
        }
        if (fileRequest.getTargetSURL() == null) {
            throw new SRMInvalidRequestException("surl of file request #" + (i + 1) + " is null.");
        }
        URI surl = URI.create(fileRequest.getTargetSURL().toString());
        UnsignedLong knownSize = fileRequest.getExpectedFileSize();
        if (knownSize != null) {
            sizes[i] = knownSize.longValue();
            if (sizes[i] < 0) {
                throw new SRMInvalidRequestException("Negative file size is not allowed.");
            }
        }
        // for now, extract type info from space token in the future
        wantPermanent[i] = true;
        /*                nextRequest.getFileStorageType()==
                TFileStorageType.PERMANENT;*/
        surls[i] = surl;
    }
    PutRequest r = new PutRequest(srm.getSrmId(), user, surls, sizes, wantPermanent, protocols, lifetime, configuration.getPutMaxPollPeriod(), clientHost, spaceToken, retentionPolicy, accessLatency, request.getUserRequestDescription());
    try (JDC ignored = r.applyJdc()) {
        if (overwriteMode != null) {
            r.setOverwriteMode(overwriteMode);
        }
        srm.acceptNewJob(r);
        // Return the request status
        return r.getSrmPrepareToPutResponse(configuration.getPutSwitchToAsynchronousModeDelay());
    }
}
Also used : SRMNotSupportedException(org.dcache.srm.SRMNotSupportedException) UnsignedLong(org.apache.axis.types.UnsignedLong) TRetentionPolicy(org.dcache.srm.v2_2.TRetentionPolicy) JDC(org.dcache.srm.util.JDC) PutRequest(org.dcache.srm.request.PutRequest) SrmPrepareToPutRequest(org.dcache.srm.v2_2.SrmPrepareToPutRequest) TOverwriteMode(org.dcache.srm.v2_2.TOverwriteMode) TPutFileRequest(org.dcache.srm.v2_2.TPutFileRequest) URI(java.net.URI) UnsignedLong(org.apache.axis.types.UnsignedLong) TAccessLatency(org.dcache.srm.v2_2.TAccessLatency) SRMInvalidRequestException(org.dcache.srm.SRMInvalidRequestException)

Example 4 with PutRequest

use of org.dcache.srm.request.PutRequest in project dcache by dCache.

the class PutRequestStorage method getContainerRequest.

@Override
protected PutRequest getContainerRequest(Connection _con, long ID, Long NEXTJOBID, long CREATIONTIME, long LIFETIME, int STATE, SRMUser user, String SCHEDULERID, long SCHEDULER_TIMESTAMP, int NUMOFRETR, long LASTSTATETRANSITIONTIME, Long CREDENTIALID, int RETRYDELTATIME, boolean SHOULDUPDATERETRYDELTATIME, String DESCRIPTION, String CLIENTHOST, String STATUSCODE, ImmutableList<PutFileRequest> fileRequests, ResultSet set, int next_index) throws SQLException {
    String sqlStatementString = "SELECT PROTOCOL FROM " + getProtocolsTableName() + " WHERE RequestID=" + ID;
    Statement sqlStatement = _con.createStatement();
    LOGGER.debug("executing statement: {}", sqlStatementString);
    ResultSet fileIdsSet = sqlStatement.executeQuery(sqlStatementString);
    List<String> protocols = new ArrayList<>();
    while (fileIdsSet.next()) {
        protocols.add(fileIdsSet.getString(1));
    }
    sqlStatement.close();
    Job.JobHistory[] jobHistoryArray = getJobHistory(ID, _con);
    return new PutRequest(srmId, ID, NEXTJOBID, CREATIONTIME, LIFETIME, STATE, user, SCHEDULERID, SCHEDULER_TIMESTAMP, NUMOFRETR, LASTSTATETRANSITIONTIME, jobHistoryArray, fileRequests, RETRYDELTATIME, SHOULDUPDATERETRYDELTATIME, DESCRIPTION, CLIENTHOST, STATUSCODE, protocols);
}
Also used : PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PutRequest(org.dcache.srm.request.PutRequest)

Example 5 with PutRequest

use of org.dcache.srm.request.PutRequest in project dcache by dCache.

the class SrmStatusOfPutRequest method srmPutStatus.

private SrmStatusOfPutRequestResponse srmPutStatus() throws SRMException {
    String requestToken = statusOfPutRequestRequest.getRequestToken();
    PutRequest putRequest = Request.getRequest(requestToken, PutRequest.class);
    try (JDC ignored = putRequest.applyJdc()) {
        putRequest.tryToReady();
        if (statusOfPutRequestRequest.getArrayOfTargetSURLs() == null) {
            return putRequest.getSrmStatusOfPutRequestResponse();
        }
        URI[] surls = statusOfPutRequestRequest.getArrayOfTargetSURLs().getUrlArray();
        if (surls.length == 0) {
            return putRequest.getSrmStatusOfPutRequestResponse();
        }
        return putRequest.getSrmStatusOfPutRequestResponse(surls);
    }
}
Also used : JDC(org.dcache.srm.util.JDC) PutRequest(org.dcache.srm.request.PutRequest) URI(org.apache.axis.types.URI)

Aggregations

PutRequest (org.dcache.srm.request.PutRequest)6 JDC (org.dcache.srm.util.JDC)3 PreparedStatement (java.sql.PreparedStatement)2 URI (org.apache.axis.types.URI)2 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)2 URI (java.net.URI)1 ResultSet (java.sql.ResultSet)1 Statement (java.sql.Statement)1 ArrayList (java.util.ArrayList)1 UnsignedLong (org.apache.axis.types.UnsignedLong)1 SRMAbortedException (org.dcache.srm.SRMAbortedException)1 SRMAuthorizationException (org.dcache.srm.SRMAuthorizationException)1 SRMFileRequestNotFoundException (org.dcache.srm.SRMFileRequestNotFoundException)1 SRMNotSupportedException (org.dcache.srm.SRMNotSupportedException)1 SRMRequestTimedOutException (org.dcache.srm.SRMRequestTimedOutException)1 PutFileRequest (org.dcache.srm.request.PutFileRequest)1 ArrayOfAnyURI (org.dcache.srm.v2_2.ArrayOfAnyURI)1 ArrayOfTSURLReturnStatus (org.dcache.srm.v2_2.ArrayOfTSURLReturnStatus)1 SrmPrepareToPutRequest (org.dcache.srm.v2_2.SrmPrepareToPutRequest)1 SrmPutDoneResponse (org.dcache.srm.v2_2.SrmPutDoneResponse)1