Search in sources :

Example 1 with BringOnlineRequest

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

the class SchedulerContainerTests method shouldScheduleBringOnlineRequest.

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

Example 2 with BringOnlineRequest

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

the class SrmBringOnline method srmBringOnline.

private SrmBringOnlineResponse srmBringOnline() throws SRMInvalidRequestException, SRMInternalErrorException, SRMNotSupportedException {
    String[] protocols = getProtocols(request);
    String clientHost = getClientNetwork(request).orElse(this.clientHost);
    TGetFileRequest[] fileRequests = getFileRequests(request);
    URI[] surls = getSurls(fileRequests);
    long requestTime = Lifetimes.calculateLifetime(request.getDesiredTotalRequestTime(), configuration.getBringOnlineLifetime());
    long desiredLifetimeInSeconds = getDesiredLifetime(request, requestTime);
    if (protocols != null && protocols.length > 0) {
        String[] supportedProtocols = storage.supportedGetProtocols();
        boolean isAnyProtocolSupported = any(asList(protocols), in(asList(supportedProtocols)));
        if (!isAnyProtocolSupported) {
            throw new SRMNotSupportedException("Protocol(s) not supported: " + Arrays.toString(protocols));
        }
    }
    BringOnlineRequest r = new BringOnlineRequest(srm.getSrmId(), user, surls, protocols, requestTime, desiredLifetimeInSeconds, configuration.getBringOnlineMaxPollPeriod(), request.getUserRequestDescription(), clientHost);
    try (JDC ignored = r.applyJdc()) {
        srm.acceptNewJob(r);
        return r.getSrmBringOnlineResponse(configuration.getBringOnlineSwitchToAsynchronousModeDelay());
    } catch (InterruptedException e) {
        throw new SRMInternalErrorException("Operation interrupted", e);
    } catch (IllegalStateTransition e) {
        throw new SRMInternalErrorException("Scheduling failure", e);
    }
}
Also used : IllegalStateTransition(org.dcache.srm.scheduler.IllegalStateTransition) SRMNotSupportedException(org.dcache.srm.SRMNotSupportedException) TGetFileRequest(org.dcache.srm.v2_2.TGetFileRequest) JDC(org.dcache.srm.util.JDC) URI(java.net.URI) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) SrmBringOnlineRequest(org.dcache.srm.v2_2.SrmBringOnlineRequest) BringOnlineRequest(org.dcache.srm.request.BringOnlineRequest)

Example 3 with BringOnlineRequest

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

the class BringOnlineRequestStorage method getContainerRequest.

@Override
protected BringOnlineRequest 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<BringOnlineFileRequest> fileRequests, ResultSet set, int next_index) throws SQLException {
    String sql = "SELECT PROTOCOL FROM " + getProtocolsTableName() + "  WHERE RequestID=?";
    PreparedStatement statement = _con.prepareStatement(sql);
    statement.setLong(1, ID);
    LOGGER.debug("executing: SELECT PROTOCOL FROM {} WHERE RequestID={} ", getProtocolsTableName(), ID);
    ResultSet fileIdsSet = statement.executeQuery();
    List<String> protocols = new ArrayList<>();
    while (fileIdsSet.next()) {
        protocols.add(fileIdsSet.getString(1));
    }
    statement.close();
    Job.JobHistory[] jobHistoryArray = getJobHistory(ID, _con);
    return new BringOnlineRequest(srmId, ID, NEXTJOBID, CREATIONTIME, LIFETIME, STATE, user, SCHEDULERID, SCHEDULER_TIMESTAMP, NUMOFRETR, LASTSTATETRANSITIONTIME, jobHistoryArray, fileRequests, RETRYDELTATIME, SHOULDUPDATERETRYDELTATIME, DESCRIPTION, CLIENTHOST, STATUSCODE, protocols.toArray(String[]::new));
}
Also used : BringOnlineRequest(org.dcache.srm.request.BringOnlineRequest) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement)

Example 4 with BringOnlineRequest

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

the class BringOnlineRequestStorage method getBatchCreateStatement.

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

Example 5 with BringOnlineRequest

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

the class SrmReleaseFiles method srmReleaseFiles.

private SrmReleaseFilesResponse srmReleaseFiles() throws DataAccessException, SRMInvalidRequestException, SRMInternalErrorException {
    ArrayOfAnyURI arrayOfSURLs = srmReleaseFilesRequest.getArrayOfSURLs();
    org.apache.axis.types.URI[] surls;
    if (arrayOfSURLs != null) {
        surls = arrayOfSURLs.getUrlArray();
    } else {
        surls = null;
    }
    if (surls != null && surls.length == 0) {
        throw new SRMInvalidRequestException("Request contains no SURL");
    }
    String requestToken = srmReleaseFilesRequest.getRequestToken();
    if (requestToken == null) {
        if (surls == null) {
            throw new SRMInvalidRequestException("Request contains no SURL");
        }
        return releaseBySURLs(surls);
    }
    ContainerRequest<?> requestToRelease;
    try {
        requestToRelease = Request.getRequest(requestToken, ContainerRequest.class);
    } catch (SRMInvalidRequestException e) {
        return unpinBySURLAndRequestToken(requestToken, surls);
    }
    try (JDC ignored = requestToRelease.applyJdc()) {
        TSURLReturnStatus[] surlReturnStatuses;
        if (requestToRelease instanceof GetRequest) {
            GetRequest getRequest = (GetRequest) requestToRelease;
            if (surls == null) {
                surlReturnStatuses = getRequest.release();
            } else {
                surlReturnStatuses = getRequest.releaseFiles(surls);
            }
            getRequest.updateStatus();
        } else if (requestToRelease instanceof BringOnlineRequest) {
            BringOnlineRequest bringOnlineRequest = (BringOnlineRequest) requestToRelease;
            if (surls == null) {
                surlReturnStatuses = bringOnlineRequest.release();
            } else {
                surlReturnStatuses = bringOnlineRequest.releaseFiles(surls);
            }
            bringOnlineRequest.updateStatus();
        } else {
            throw new SRMInvalidRequestException("No such get or bring online request: " + requestToken);
        }
        return new SrmReleaseFilesResponse(getSummaryReturnStatus(surlReturnStatuses), new ArrayOfTSURLReturnStatus(surlReturnStatuses));
    }
}
Also used : JDC(org.dcache.srm.util.JDC) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI) URI(java.net.URI) SrmReleaseFilesResponse(org.dcache.srm.v2_2.SrmReleaseFilesResponse) GetRequest(org.dcache.srm.request.GetRequest) BringOnlineRequest(org.dcache.srm.request.BringOnlineRequest) ContainerRequest(org.dcache.srm.request.ContainerRequest) ArrayOfTSURLReturnStatus(org.dcache.srm.v2_2.ArrayOfTSURLReturnStatus) TSURLReturnStatus(org.dcache.srm.v2_2.TSURLReturnStatus) ArrayOfTSURLReturnStatus(org.dcache.srm.v2_2.ArrayOfTSURLReturnStatus) SRMInvalidRequestException(org.dcache.srm.SRMInvalidRequestException) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI)

Aggregations

BringOnlineRequest (org.dcache.srm.request.BringOnlineRequest)5 URI (java.net.URI)2 PreparedStatement (java.sql.PreparedStatement)2 JDC (org.dcache.srm.util.JDC)2 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)1 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)1 SRMNotSupportedException (org.dcache.srm.SRMNotSupportedException)1 ContainerRequest (org.dcache.srm.request.ContainerRequest)1 GetRequest (org.dcache.srm.request.GetRequest)1 IllegalStateTransition (org.dcache.srm.scheduler.IllegalStateTransition)1 ArrayOfAnyURI (org.dcache.srm.v2_2.ArrayOfAnyURI)1 ArrayOfTSURLReturnStatus (org.dcache.srm.v2_2.ArrayOfTSURLReturnStatus)1 SrmBringOnlineRequest (org.dcache.srm.v2_2.SrmBringOnlineRequest)1 SrmReleaseFilesResponse (org.dcache.srm.v2_2.SrmReleaseFilesResponse)1 TGetFileRequest (org.dcache.srm.v2_2.TGetFileRequest)1 TSURLReturnStatus (org.dcache.srm.v2_2.TSURLReturnStatus)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1