use of org.dcache.srm.v2_2.SrmReserveSpaceResponse in project dcache by dCache.
the class ReserveSpaceRequest method getSrmReserveSpaceResponse.
public SrmReserveSpaceResponse getSrmReserveSpaceResponse() {
rlock();
try {
SrmReserveSpaceResponse response = new SrmReserveSpaceResponse();
response.setReturnStatus(getTReturnStatus());
response.setRetentionPolicyInfo(new TRetentionPolicyInfo(retentionPolicy, accessLatency));
response.setRequestToken(String.valueOf(getId()));
response.setSpaceToken(getSpaceToken());
response.setSizeOfTotalReservedSpace(new UnsignedLong(sizeInBytes));
response.setSizeOfGuaranteedReservedSpace(new UnsignedLong(sizeInBytes));
response.setLifetimeOfReservedSpace((int) ((spaceReservationLifetime) == -1 ? -1 : TimeUnit.MILLISECONDS.toSeconds(spaceReservationLifetime)));
return response;
} finally {
runlock();
}
}
use of org.dcache.srm.v2_2.SrmReserveSpaceResponse in project dcache by dCache.
the class SRMReserveSpaceClientV2 method start.
@Override
public void start() throws Exception {
checkCredentialValid();
try {
TRetentionPolicy rp = configuration.getRetentionPolicy() != null ? RetentionPolicy.fromString(configuration.getRetentionPolicy()).toTRetentionPolicy() : null;
TAccessLatency al = configuration.getAccessLatency() != null ? AccessLatency.fromString(configuration.getAccessLatency()).toTAccessLatency() : null;
if ((al != null) && (rp == null)) {
throw new IllegalArgumentException("if access latency is specified, " + "then retention policy have to be specified as well");
} else if (rp != null) {
request.setRetentionPolicyInfo(new TRetentionPolicyInfo(rp, al));
}
if (configuration.getDesiredReserveSpaceSize() != null) {
request.setDesiredSizeOfTotalSpace(new UnsignedLong(configuration.getDesiredReserveSpaceSize().longValue()));
}
if (configuration.getGuaranteedReserveSpaceSize() != null) {
request.setDesiredSizeOfGuaranteedSpace(new UnsignedLong(configuration.getGuaranteedReserveSpaceSize().longValue()));
}
request.setUserSpaceTokenDescription(configuration.getSpaceTokenDescription());
if (configuration.getDesiredLifetime() != null) {
request.setDesiredLifetimeOfReservedSpace((int) (configuration.getDesiredLifetime().longValue()));
}
if (configuration.getArrayOfClientNetworks() != null || configuration.getConnectionType() != null || configuration.getAccessPattern() != null || configuration.getProtocols() != null) {
TTransferParameters tp = new TTransferParameters();
if (configuration.getArrayOfClientNetworks() != null) {
tp.setArrayOfClientNetworks(new ArrayOfString(configuration.getArrayOfClientNetworks()));
}
if (configuration.getConnectionType() != null) {
tp.setConnectionType(TConnectionType.fromString(configuration.getConnectionType()));
}
if (configuration.getAccessPattern() != null) {
tp.setAccessPattern(TAccessPattern.fromString(configuration.getAccessPattern()));
}
if (configuration.getProtocols() != null) {
tp.setArrayOfTransferProtocols(new ArrayOfString(configuration.getProtocols()));
}
request.setTransferParameters(tp);
}
configuration.getStorageSystemInfo().ifPresent(request::setStorageSystemInfo);
hook = new Thread(this);
Runtime.getRuntime().addShutdownHook(hook);
SrmReserveSpaceResponse response = srm.srmReserveSpace(request);
if (response == null) {
throw new IOException(" null SrmReserveSpace");
}
TReturnStatus rs = response.getReturnStatus();
requestToken = response.getRequestToken();
dsay(" srm returned requestToken = " + requestToken);
if (rs == null) {
throw new IOException(" null TReturnStatus ");
}
if (RequestStatusTool.isFailedRequestStatus(rs)) {
throw new IOException("srmReserveSpace submission failed, unexpected or failed return status : " + rs.getStatusCode() + " explanation=" + rs.getExplanation());
}
if (response.getSpaceToken() != null) {
System.out.println("Space token =" + response.getSpaceToken());
logger.log("lifetime = " + response.getLifetimeOfReservedSpace());
if (response.getRetentionPolicyInfo() != null) {
logger.log("access latency = " + response.getRetentionPolicyInfo().getAccessLatency());
logger.log("retention policy = " + response.getRetentionPolicyInfo().getRetentionPolicy());
}
logger.log("guaranteed size = " + response.getSizeOfGuaranteedReservedSpace());
logger.log("total size = " + response.getSizeOfTotalReservedSpace());
} else {
while (true) {
long estimatedWaitInSeconds = 5;
if (estimatedWaitInSeconds > 60) {
estimatedWaitInSeconds = 60;
}
try {
say("sleeping " + estimatedWaitInSeconds + " seconds ...");
Thread.sleep(estimatedWaitInSeconds * 1000);
} catch (InterruptedException ie) {
System.out.println("Interrupted, quitting");
if (requestToken != null) {
abortRequest();
}
System.exit(1);
}
//
// check our request
//
SrmStatusOfReserveSpaceRequestRequest req = new SrmStatusOfReserveSpaceRequestRequest();
req.setRequestToken(requestToken);
req.setAuthorizationID(request.getAuthorizationID());
SrmStatusOfReserveSpaceRequestResponse statusOfReserveSpaceRequestResponse = srm.srmStatusOfReserveSpaceRequest(req);
if (statusOfReserveSpaceRequestResponse == null) {
throw new IOException(" null statusOfReserveSpaceRequestResponse");
}
TReturnStatus status = statusOfReserveSpaceRequestResponse.getReturnStatus();
if (status == null) {
throw new IOException(" null return status");
}
if (status.getStatusCode() == null) {
throw new IOException(" null status code");
}
if (RequestStatusTool.isFailedRequestStatus(status)) {
logger.log("status: code=" + status.getStatusCode() + " explanantion=" + status.getExplanation());
throw new IOException("SrmStatusOfReserveSpaceRequest unexpected or failed status : " + status.getStatusCode() + " explanation=" + status.getExplanation());
}
if (status.getStatusCode() == TStatusCode.SRM_SUCCESS || status.getStatusCode() == TStatusCode.SRM_SPACE_AVAILABLE || status.getStatusCode() == TStatusCode.SRM_LOWER_SPACE_GRANTED) {
System.out.println("Space token =" + statusOfReserveSpaceRequestResponse.getSpaceToken());
logger.log("lifetime = " + statusOfReserveSpaceRequestResponse.getLifetimeOfReservedSpace());
logger.log("access latency = " + statusOfReserveSpaceRequestResponse.getRetentionPolicyInfo().getAccessLatency());
logger.log("retention policy = " + statusOfReserveSpaceRequestResponse.getRetentionPolicyInfo().getRetentionPolicy());
logger.log("guaranteed size = " + statusOfReserveSpaceRequestResponse.getSizeOfGuaranteedReservedSpace());
logger.log("total size = " + statusOfReserveSpaceRequestResponse.getSizeOfTotalReservedSpace());
break;
}
if (statusOfReserveSpaceRequestResponse.getEstimatedProcessingTime() != null && statusOfReserveSpaceRequestResponse.getEstimatedProcessingTime() < estimatedWaitInSeconds && statusOfReserveSpaceRequestResponse.getEstimatedProcessingTime() >= 1) {
estimatedWaitInSeconds = statusOfReserveSpaceRequestResponse.getEstimatedProcessingTime();
}
}
}
Runtime.getRuntime().removeShutdownHook(hook);
} catch (Exception e) {
try {
if (requestToken != null) {
abortRequest();
}
} catch (Exception e1) {
edsay(e1.toString());
}
throw e;
}
}
use of org.dcache.srm.v2_2.SrmReserveSpaceResponse in project dcache by dCache.
the class SrmReserveSpace method reserveSpace.
private SrmReserveSpaceResponse reserveSpace() throws SRMException {
TRetentionPolicyInfo retentionPolicyInfo = request.getRetentionPolicyInfo();
if (retentionPolicyInfo == null) {
throw new SRMInvalidRequestException("retentionPolicyInfo is missing");
}
TRetentionPolicy retentionPolicy = retentionPolicyInfo.getRetentionPolicy();
if (retentionPolicy == null) {
throw new SRMInvalidRequestException("retentionPolicy is missing");
}
TAccessLatency accessLatency = retentionPolicyInfo.getAccessLatency();
UnsignedLong size = request.getDesiredSizeOfGuaranteedSpace();
String userSpaceTokenDescription = request.getUserSpaceTokenDescription();
long lifetime = getDesiredLifetimeOfReservedSpace(request, configuration.getDefaultSpaceLifetime());
long requestLifetime = getRequestLifetime(lifetime);
Map<String, String> extraInfo = request.getStorageSystemInfo() == null ? Collections.emptyMap() : asMap(request.getStorageSystemInfo().getExtraInfoArray());
try {
ReserveSpaceRequest reserveRequest = new ReserveSpaceRequest(srm.getSrmId(), user, requestLifetime, configuration.getReserveSpaceMaxPollPeriod(), size.longValue(), lifetime, retentionPolicy, accessLatency, userSpaceTokenDescription, client_host, extraInfo);
reserveRequest.applyJdc();
srm.acceptNewJob(reserveRequest);
return reserveRequest.getSrmReserveSpaceResponse();
} catch (IllegalStateTransition e) {
LOGGER.error("Failed to schedule srmReserveSpace: {}", e);
throw new SRMException("Failed to schedule operation");
}
}
use of org.dcache.srm.v2_2.SrmReserveSpaceResponse in project dcache by dCache.
the class AxisSrmFileSystem method reserveSpace.
@Nonnull
@Override
public TMetaDataSpace reserveSpace(long size, @Nullable String description, @Nullable TAccessLatency al, TRetentionPolicy rp, @Nullable Integer lifetime) throws SRMException, RemoteException, InterruptedException {
SrmReserveSpaceResponse response = srm.srmReserveSpace(new SrmReserveSpaceRequest(null, description, new TRetentionPolicyInfo(rp, al), new UnsignedLong(size), new UnsignedLong(size), lifetime, null, null, null));
while (response.getReturnStatus().getStatusCode() == TStatusCode.SRM_REQUEST_QUEUED || response.getReturnStatus().getStatusCode() == TStatusCode.SRM_REQUEST_INPROGRESS) {
if (response.getEstimatedProcessingTime() != null) {
TimeUnit.SECONDS.sleep(response.getEstimatedProcessingTime());
} else {
TimeUnit.SECONDS.sleep(2);
}
SrmStatusOfReserveSpaceRequestResponse status = srm.srmStatusOfReserveSpaceRequest(new SrmStatusOfReserveSpaceRequestRequest(null, response.getRequestToken()));
response.setReturnStatus(status.getReturnStatus());
response.setLifetimeOfReservedSpace(status.getLifetimeOfReservedSpace());
response.setRetentionPolicyInfo(status.getRetentionPolicyInfo());
response.setSizeOfGuaranteedReservedSpace(status.getSizeOfGuaranteedReservedSpace());
response.setSizeOfTotalReservedSpace(status.getSizeOfTotalReservedSpace());
response.setSpaceToken(status.getSpaceToken());
response.setEstimatedProcessingTime(status.getEstimatedProcessingTime());
}
checkSuccess(response.getReturnStatus(), TStatusCode.SRM_SUCCESS, TStatusCode.SRM_LOWER_SPACE_GRANTED);
TMetaDataSpace space = new TMetaDataSpace();
space.setLifetimeAssigned(response.getLifetimeOfReservedSpace());
space.setRetentionPolicyInfo(response.getRetentionPolicyInfo());
space.setGuaranteedSize(response.getSizeOfGuaranteedReservedSpace());
space.setTotalSize(response.getSizeOfTotalReservedSpace());
space.setSpaceToken(response.getSpaceToken());
space.setStatus(response.getReturnStatus());
return space;
}
use of org.dcache.srm.v2_2.SrmReserveSpaceResponse in project dcache by dCache.
the class SrmReserveSpace method getFailedResponse.
public static final SrmReserveSpaceResponse getFailedResponse(String text, TStatusCode statusCode) {
SrmReserveSpaceResponse response = new SrmReserveSpaceResponse();
response.setReturnStatus(new TReturnStatus(statusCode, text));
return response;
}
Aggregations