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));
}
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);
}
}
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));
}
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;
}
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));
}
}
Aggregations