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