use of org.dcache.srm.v2_2.TRetentionPolicy in project dcache by dCache.
the class SRMPutClientV2 method start.
@Override
public void start() throws Exception {
try {
copier = new Copier(configuration);
new Thread(copier).start();
int len = from.length;
TPutFileRequest[] fileRequests = new TPutFileRequest[len];
String[] SURLS = new String[len];
for (int i = 0; i < len; ++i) {
java.net.URI filesource = from[i];
int filetype = SRMDispatcher.getUrlType(filesource);
if ((filetype & SRMDispatcher.FILE_URL) == 0) {
throw new IOException(" source is not file " + filesource);
}
if ((filetype & SRMDispatcher.DIRECTORY_URL) == SRMDispatcher.DIRECTORY_URL) {
throw new IOException(" source is directory " + filesource);
}
if ((filetype & SRMDispatcher.CAN_READ_FILE_URL) == 0) {
throw new IOException(" source is not readable " + filesource);
}
File f = new File(filesource.getPath());
long filesize = f.length();
SURLS[i] = to[i].toASCIIString();
URI uri = new URI(SURLS[i]);
fileRequests[i] = new TPutFileRequest();
fileRequests[i].setExpectedFileSize(new UnsignedLong(filesize));
fileRequests[i].setTargetSURL(uri);
pendingSurlsToIndex.put(SURLS[i], i);
}
hook = new Thread(this);
Runtime.getRuntime().addShutdownHook(hook);
SrmPrepareToPutRequest srmPrepareToPutRequest = new SrmPrepareToPutRequest();
srmPrepareToPutRequest.setUserRequestDescription(configuration.getUserRequestDescription());
String storagetype = configuration.getStorageType();
if (storagetype != null) {
srmPrepareToPutRequest.setDesiredFileStorageType(FileStorageType.fromString(storagetype.toUpperCase()).toTFileStorageType());
}
srmPrepareToPutRequest.setDesiredTotalRequestTime((int) configuration.getRequestLifetime());
srmPrepareToPutRequest.setArrayOfFileRequests(new ArrayOfTPutFileRequest(fileRequests));
TAccessPattern ap = null;
if (configuration.getAccessPattern() != null) {
ap = TAccessPattern.fromString(configuration.getAccessPattern());
}
TConnectionType ct = null;
if (configuration.getConnectionType() != null) {
ct = TConnectionType.fromString(configuration.getConnectionType());
}
ArrayOfString protocolArray = null;
if (configuration.getProtocols() != null) {
protocolArray = new ArrayOfString(configuration.getProtocols());
}
ArrayOfString arrayOfClientNetworks = null;
if (configuration.getArrayOfClientNetworks() != null) {
arrayOfClientNetworks = new ArrayOfString(configuration.getArrayOfClientNetworks());
}
if (ap != null || ct != null || arrayOfClientNetworks != null || protocolArray != null) {
srmPrepareToPutRequest.setTransferParameters(new TTransferParameters(ap, ct, arrayOfClientNetworks, protocolArray));
}
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) {
srmPrepareToPutRequest.setTargetFileRetentionPolicyInfo(new TRetentionPolicyInfo(rp, al));
}
if (configuration.getOverwriteMode() != null) {
srmPrepareToPutRequest.setOverwriteOption(TOverwriteMode.fromString(configuration.getOverwriteMode()));
}
if (configuration.getSpaceToken() != null) {
srmPrepareToPutRequest.setTargetSpaceToken(configuration.getSpaceToken());
}
configuration.getStorageSystemInfo().ifPresent(srmPrepareToPutRequest::setStorageSystemInfo);
response = srm.srmPrepareToPut(srmPrepareToPutRequest);
if (response == null) {
throw new IOException(" null response");
}
TReturnStatus status = response.getReturnStatus();
if (status == null) {
throw new IOException(" null return status");
}
TStatusCode statusCode = status.getStatusCode();
if (statusCode == null) {
throw new IOException(" null status code");
}
if (RequestStatusTool.isFailedRequestStatus(status) && (statusCode != TStatusCode.SRM_FAILURE || response.getArrayOfFileStatuses() == null)) {
String explanation = status.getExplanation();
if (explanation != null) {
throw new IOException("srmPrepareToPut submission failed, unexpected or failed status : " + statusCode + " explanation= " + explanation);
} else {
throw new IOException("srmPrepareToPut submission failed, unexpected or failed status : " + statusCode);
}
}
requestToken = response.getRequestToken();
dsay(" srm returned requestToken = " + requestToken);
if (response.getArrayOfFileStatuses() == null) {
throw new IOException("returned PutRequestFileStatuses is an empty array");
}
TPutRequestFileStatus[] putRequestFileStatuses = response.getArrayOfFileStatuses().getStatusArray();
if (putRequestFileStatuses.length != len) {
throw new IOException("incorrect number of GetRequestFileStatuses" + "in RequestStatus expected " + len + " received " + putRequestFileStatuses.length);
}
while (!pendingSurlsToIndex.isEmpty()) {
long estimatedWaitInSeconds = 5;
for (TPutRequestFileStatus putRequestFileStatus : putRequestFileStatuses) {
URI surl = putRequestFileStatus.getSURL();
if (surl == null) {
esay("invalid putRequestFileStatus, surl is null");
continue;
}
String surl_string = surl.toString();
if (!pendingSurlsToIndex.containsKey(surl_string)) {
esay("invalid putRequestFileStatus, surl = " + surl_string + " not found");
continue;
}
TReturnStatus fileStatus = putRequestFileStatus.getStatus();
if (fileStatus == null) {
throw new IOException(" null file return status");
}
TStatusCode fileStatusCode = fileStatus.getStatusCode();
if (fileStatusCode == null) {
throw new IOException(" null file status code");
}
if (RequestStatusTool.isFailedFileRequestStatus(fileStatus)) {
String explanation = fileStatus.getExplanation();
String error = isNullOrEmpty(explanation) ? fileStatusCode.toString() : fileStatusCode + ": " + explanation;
say(error);
int indx = pendingSurlsToIndex.remove(surl_string);
setReportFailed(from[indx], to[indx], error);
continue;
}
if (putRequestFileStatus.getTransferURL() != null) {
java.net.URI globusTURL = new java.net.URI(putRequestFileStatus.getTransferURL().toString());
int indx = pendingSurlsToIndex.remove(surl_string);
setReportFailed(from[indx], to[indx], "received TURL, but did not complete transfer");
CopyJob job = new SRMV2CopyJob(from[indx], globusTURL, srm, requestToken, logger, to[indx], false, this);
copier.addCopyJob(job);
continue;
}
if (putRequestFileStatus.getEstimatedWaitTime() != null && putRequestFileStatus.getEstimatedWaitTime() < estimatedWaitInSeconds && putRequestFileStatus.getEstimatedWaitTime() >= 1) {
estimatedWaitInSeconds = putRequestFileStatus.getEstimatedWaitTime();
}
}
if (pendingSurlsToIndex.isEmpty()) {
dsay("no more pending transfers, breaking the loop");
Runtime.getRuntime().removeShutdownHook(hook);
break;
}
// do not wait longer then 60 seconds
if (estimatedWaitInSeconds > 60) {
estimatedWaitInSeconds = 60;
}
try {
say("sleeping " + estimatedWaitInSeconds + " seconds ...");
Thread.sleep(estimatedWaitInSeconds * 1000);
} catch (InterruptedException ie) {
logger.elog(ie.toString());
}
SrmStatusOfPutRequestRequest srmStatusOfPutRequestRequest = new SrmStatusOfPutRequestRequest();
srmStatusOfPutRequestRequest.setRequestToken(requestToken);
// if we do not have completed file requests
// we want to get status for all files
// we do not need to specify any surls
int expectedResponseLength;
// we do not know what to expect from the server when
// no surls are specified int the status update request
// so we always are sending the list of all pending srm urls
String[] pendingSurlStrings = pendingSurlsToIndex.keySet().toArray(new String[pendingSurlsToIndex.size()]);
expectedResponseLength = pendingSurlStrings.length;
URI[] surlArray = new URI[expectedResponseLength];
for (int i = 0; i < expectedResponseLength; ++i) {
surlArray[i] = new URI(pendingSurlStrings[i]);
}
srmStatusOfPutRequestRequest.setArrayOfTargetSURLs(new ArrayOfAnyURI(surlArray));
SrmStatusOfPutRequestResponse srmStatusOfPutRequestResponse = srm.srmStatusOfPutRequest(srmStatusOfPutRequestRequest);
if (srmStatusOfPutRequestResponse == null) {
throw new IOException(" null srmStatusOfPutRequestResponse");
}
if (srmStatusOfPutRequestResponse.getArrayOfFileStatuses() == null) {
esay("putRequestFileStatuses == null");
throw new IOException("putRequestFileStatuses == null");
}
putRequestFileStatuses = srmStatusOfPutRequestResponse.getArrayOfFileStatuses().getStatusArray();
if (putRequestFileStatuses.length != expectedResponseLength) {
esay("incorrect number of RequestFileStatuses");
throw new IOException("incorrect number of RequestFileStatuses");
}
status = srmStatusOfPutRequestResponse.getReturnStatus();
if (status == null) {
throw new IOException(" null return status");
}
statusCode = status.getStatusCode();
if (statusCode == null) {
throw new IOException(" null status code");
}
if (RequestStatusTool.isFailedRequestStatus(status)) {
String error = "srmPrepareToPut update failed, status : " + statusCode + " explanation=" + status.getExplanation();
esay(error);
for (int i = 0; i < expectedResponseLength; ++i) {
TReturnStatus frstatus = putRequestFileStatuses[i].getStatus();
if (frstatus != null) {
esay("PutFileRequest[" + putRequestFileStatuses[i].getSURL() + "] status=" + frstatus.getStatusCode() + " explanation=" + frstatus.getExplanation());
if (!RequestStatusTool.isTransientStateStatus(frstatus)) {
pendingSurlsToIndex.remove(putRequestFileStatuses[i].getSURL().toString());
}
}
}
throw new IOException(error);
}
}
} catch (Exception e) {
try {
if (copier != null) {
dsay("stopping copier" + e);
copier.stop();
abortAllPendingFiles();
}
} catch (Exception e1) {
edsay(e1.toString());
}
throw e;
} finally {
if (copier != null) {
copier.doneAddingJobs();
try {
copier.waitCompletion();
} catch (Exception e1) {
edsay(e1.toString());
}
}
report.dumpReport();
if (!report.everythingAllRight()) {
report.reportErrors(System.err);
}
}
}
use of org.dcache.srm.v2_2.TRetentionPolicy 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.TRetentionPolicy in project dcache by dCache.
the class SrmShell method append.
private void append(PrintWriter writer, TMetaDataSpace space) {
Integer lifetimeOfReservedSpace = space.getLifetimeAssigned();
Integer lifetimeLeft = space.getLifetimeLeft();
TRetentionPolicyInfo retentionPolicyInfo = space.getRetentionPolicyInfo();
UnsignedLong sizeOfTotalReservedSpace = space.getTotalSize();
UnsignedLong sizeOfGuaranteedReservedSpace = space.getGuaranteedSize();
UnsignedLong unusedSize = space.getUnusedSize();
writer.append("Space token : ").println(space.getSpaceToken());
if (space.getOwner() != null) {
writer.append("Owner : ").println(space.getOwner());
}
if (sizeOfTotalReservedSpace != null) {
writer.append("Total size : ").println(sizeOfTotalReservedSpace.longValue());
}
if (sizeOfGuaranteedReservedSpace != null) {
writer.append("Guaranteed size : ").println(sizeOfGuaranteedReservedSpace.longValue());
}
if (unusedSize != null) {
writer.append("Unused size : ").println(unusedSize.longValue());
}
if (lifetimeOfReservedSpace != null) {
writer.append("Assigned lifetime : ").println(lifetimeOfReservedSpace);
}
if (lifetimeLeft != null) {
writer.append("Remaining lifetime: ").println(lifetimeLeft);
}
if (retentionPolicyInfo != null) {
TRetentionPolicy retentionPolicy = retentionPolicyInfo.getRetentionPolicy();
TAccessLatency accessLatency = retentionPolicyInfo.getAccessLatency();
writer.append("Retention : ").append(retentionPolicy.toString());
if (accessLatency != null) {
writer.append("Access latency: ").append(accessLatency.toString());
}
writer.println();
}
}
use of org.dcache.srm.v2_2.TRetentionPolicy in project dcache by dCache.
the class Storage method srmGetSpaceMetaData.
/**
* @param spaceTokens
* @return
* @throws SRMException
*/
@Override
public TMetaDataSpace[] srmGetSpaceMetaData(SRMUser user, String[] spaceTokens) throws SRMException {
guardSpaceManagerEnabled();
GetSpaceMetaData getSpaces = new GetSpaceMetaData(spaceTokens);
try {
getSpaces = _spaceManagerStub.sendAndWait(getSpaces);
} catch (TimeoutCacheException e) {
throw new SRMInternalErrorException("Space manager timeout", e);
} catch (NoRouteToCellException e) {
throw new SRMNotSupportedException("Space manager is unavailable", e);
} catch (InterruptedException e) {
throw new SRMInternalErrorException("Operation interrupted", e);
} catch (CacheException e) {
_log.warn("GetSpaceMetaData failed with rc={} error={}", e.getRc(), e.getMessage());
throw new SRMException("Space manager failure: " + e.getMessage(), e);
}
Space[] spaces = getSpaces.getSpaces();
TMetaDataSpace[] spaceMetaDatas = new TMetaDataSpace[spaces.length];
for (int i = 0; i < spaceMetaDatas.length; ++i) {
Space space = spaces[i];
TMetaDataSpace metaDataSpace = new TMetaDataSpace();
TReturnStatus status;
if (space != null) {
Long expirationTime = space.getExpirationTime();
if (expirationTime == null) {
metaDataSpace.setLifetimeAssigned(-1);
metaDataSpace.setLifetimeLeft(-1);
} else {
long lifetimeleft = Math.max(0, MILLISECONDS.toSeconds(expirationTime - System.currentTimeMillis()));
metaDataSpace.setLifetimeAssigned((int) MILLISECONDS.toSeconds(expirationTime - space.getCreationTime()));
metaDataSpace.setLifetimeLeft((int) lifetimeleft);
}
RetentionPolicy retentionPolicy = space.getRetentionPolicy();
TRetentionPolicy policy = retentionPolicy.equals(RetentionPolicy.CUSTODIAL) ? TRetentionPolicy.CUSTODIAL : retentionPolicy.equals(RetentionPolicy.OUTPUT) ? TRetentionPolicy.OUTPUT : TRetentionPolicy.REPLICA;
AccessLatency accessLatency = space.getAccessLatency();
TAccessLatency latency = accessLatency.equals(AccessLatency.ONLINE) ? TAccessLatency.ONLINE : TAccessLatency.NEARLINE;
UnsignedLong totalSize = new UnsignedLong(space.getSizeInBytes());
UnsignedLong unusedSize = new UnsignedLong(space.getSizeInBytes() - space.getUsedSizeInBytes());
metaDataSpace.setRetentionPolicyInfo(new TRetentionPolicyInfo(policy, latency));
metaDataSpace.setTotalSize(totalSize);
metaDataSpace.setGuaranteedSize(totalSize);
metaDataSpace.setUnusedSize(unusedSize);
SpaceState spaceState = space.getState();
switch(spaceState) {
case RESERVED:
status = new TReturnStatus(TStatusCode.SRM_SUCCESS, null);
break;
case EXPIRED:
status = new TReturnStatus(TStatusCode.SRM_SPACE_LIFETIME_EXPIRED, "The lifetime on the space that is associated with the spaceToken has expired already");
break;
default:
status = new TReturnStatus(TStatusCode.SRM_FAILURE, "Space has been released");
break;
}
metaDataSpace.setOwner("VoGroup=" + space.getVoGroup() + " VoRole=" + space.getVoRole());
} else {
status = new TReturnStatus(TStatusCode.SRM_INVALID_REQUEST, "No such space");
}
metaDataSpace.setStatus(status);
metaDataSpace.setSpaceToken(spaceTokens[i]);
spaceMetaDatas[i] = metaDataSpace;
}
return spaceMetaDatas;
}
use of org.dcache.srm.v2_2.TRetentionPolicy in project dcache by dCache.
the class SRMBringOnlineClientV2 method start.
@Override
public void start() throws Exception {
try {
int len = from.length;
String[] SURLS = new String[len];
TGetFileRequest[] fileRequests = new TGetFileRequest[len];
for (int i = 0; i < len; ++i) {
SURLS[i] = from[i].toASCIIString();
URI uri = new URI(SURLS[i]);
fileRequests[i] = new TGetFileRequest();
fileRequests[i].setSourceSURL(uri);
pendingSurlsToIndex.put(SURLS[i], i);
}
hook = new Thread(this);
Runtime.getRuntime().addShutdownHook(hook);
SrmBringOnlineRequest srmBringOnlineRequest = new SrmBringOnlineRequest();
srmBringOnlineRequest.setUserRequestDescription(configuration.getUserRequestDescription());
srmBringOnlineRequest.setDesiredTotalRequestTime((int) configuration.getRequestLifetime());
if (configuration.getDesiredLifetime() != null) {
srmBringOnlineRequest.setDesiredLifeTime(configuration.getDesiredLifetime().intValue());
}
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 has to be specified as well");
} else if (rp != null) {
srmBringOnlineRequest.setTargetFileRetentionPolicyInfo(new TRetentionPolicyInfo(rp, al));
}
srmBringOnlineRequest.setArrayOfFileRequests(new ArrayOfTGetFileRequest(fileRequests));
TAccessPattern ap = null;
if (configuration.getAccessPattern() != null) {
ap = TAccessPattern.fromString(configuration.getAccessPattern());
}
TConnectionType ct = null;
if (configuration.getConnectionType() != null) {
ct = TConnectionType.fromString(configuration.getConnectionType());
}
ArrayOfString protocolArray = null;
if (configuration.getProtocols() != null) {
protocolArray = new ArrayOfString(configuration.getProtocols());
}
ArrayOfString arrayOfClientNetworks = null;
if (configuration.getArrayOfClientNetworks() != null) {
arrayOfClientNetworks = new ArrayOfString(configuration.getArrayOfClientNetworks());
}
if (ap != null || ct != null || arrayOfClientNetworks != null || protocolArray != null) {
srmBringOnlineRequest.setTransferParameters(new TTransferParameters(ap, ct, arrayOfClientNetworks, protocolArray));
}
configuration.getStorageSystemInfo().ifPresent(srmBringOnlineRequest::setStorageSystemInfo);
say("calling srmBringOnline");
SrmBringOnlineResponse response = srm.srmBringOnline(srmBringOnlineRequest);
say("received response");
if (response == null) {
throw new IOException(" null response");
}
TReturnStatus status = response.getReturnStatus();
if (status == null) {
throw new IOException(" null return status");
}
TStatusCode statusCode = status.getStatusCode();
if (statusCode == null) {
throw new IOException(" null status code");
}
if (RequestStatusTool.isFailedRequestStatus(status)) {
throw new IOException("srmBringOnline submission failed, unexpected or failed status : " + statusCode + " explanation=" + status.getExplanation());
}
requestToken = response.getRequestToken();
dsay(" srm returned requestToken = " + requestToken);
if (response.getArrayOfFileStatuses() == null) {
throw new IOException("returned bringOnlineRequestFileStatuses is an empty array");
}
TBringOnlineRequestFileStatus[] bringOnlineRequestFileStatuses = response.getArrayOfFileStatuses().getStatusArray();
if (bringOnlineRequestFileStatuses.length != len) {
throw new IOException("incorrect number of TBringOnlineRequestFileStatus" + "in RequestStatus expected " + len + " received " + bringOnlineRequestFileStatuses.length);
}
while (!pendingSurlsToIndex.isEmpty()) {
long estimatedWaitInSeconds = 60;
for (TBringOnlineRequestFileStatus bringOnlineRequestFileStatus : bringOnlineRequestFileStatuses) {
URI surl = bringOnlineRequestFileStatus.getSourceSURL();
if (surl == null) {
esay("invalid bringOnlineRequestFileStatus, surl is null");
continue;
}
String surl_string = surl.toString();
if (!pendingSurlsToIndex.containsKey(surl_string)) {
esay("invalid bringOnlineRequestFileStatus, surl = " + surl_string + " not found");
continue;
}
TReturnStatus fileStatus = bringOnlineRequestFileStatus.getStatus();
if (fileStatus == null) {
throw new IOException(" null file return status");
}
TStatusCode fileStatusCode = fileStatus.getStatusCode();
if (fileStatusCode == null) {
throw new IOException(" null file status code");
}
if (RequestStatusTool.isFailedFileRequestStatus(fileStatus)) {
String error = "retrieval of surl " + surl_string + " failed, status = " + fileStatusCode + " explanation=" + fileStatus.getExplanation();
esay(error);
int indx = pendingSurlsToIndex.remove(surl_string);
setReportFailed(from[indx], from[indx], error);
continue;
}
if (fileStatus.getStatusCode() == TStatusCode.SRM_SUCCESS) {
int indx = pendingSurlsToIndex.remove(surl_string);
setReportSucceeded(from[indx], from[indx]);
System.out.println(from[indx] + " brought online, use request id " + requestToken + " to release");
continue;
}
Integer estimatedWaitTime = bringOnlineRequestFileStatus.getEstimatedWaitTime();
if (estimatedWaitTime != null && estimatedWaitTime < estimatedWaitInSeconds && estimatedWaitTime >= 1) {
estimatedWaitInSeconds = estimatedWaitTime;
}
}
if (pendingSurlsToIndex.isEmpty()) {
dsay("no more pending transfers, breaking the loop");
Runtime.getRuntime().removeShutdownHook(hook);
break;
}
try {
say("sleeping " + estimatedWaitInSeconds + " seconds ...");
Thread.sleep(estimatedWaitInSeconds * 1000);
} catch (InterruptedException ie) {
}
SrmStatusOfBringOnlineRequestRequest srmStatusOfBringOnlineRequestRequest = new SrmStatusOfBringOnlineRequestRequest();
srmStatusOfBringOnlineRequestRequest.setRequestToken(requestToken);
// we do not know what to expect from the server when
// no surls are specified int the status update request
// so we always are sending the list of all pending srm urls
String[] pendingSurlStrings = pendingSurlsToIndex.keySet().toArray(new String[pendingSurlsToIndex.size()]);
// if we do not have completed file requests
// we want to get status for all files
// we do not need to specify any surls
int expectedResponseLength = pendingSurlStrings.length;
URI[] surlArray = new URI[expectedResponseLength];
for (int i = 0; i < expectedResponseLength; ++i) {
surlArray[i] = new URI(pendingSurlStrings[i]);
}
srmStatusOfBringOnlineRequestRequest.setArrayOfSourceSURLs(new ArrayOfAnyURI(surlArray));
SrmStatusOfBringOnlineRequestResponse srmStatusOfBringOnlineRequestResponse = srm.srmStatusOfBringOnlineRequest(srmStatusOfBringOnlineRequestRequest);
if (srmStatusOfBringOnlineRequestResponse == null) {
throw new IOException(" null srmStatusOfBringOnlineRequestResponse");
}
if (srmStatusOfBringOnlineRequestResponse.getArrayOfFileStatuses() == null) {
esay("incorrect number of RequestFileStatuses");
throw new IOException("incorrect number of RequestFileStatuses");
}
bringOnlineRequestFileStatuses = srmStatusOfBringOnlineRequestResponse.getArrayOfFileStatuses().getStatusArray();
if (bringOnlineRequestFileStatuses == null || bringOnlineRequestFileStatuses.length != expectedResponseLength) {
esay("incorrect number of RequestFileStatuses");
throw new IOException("incorrect number of RequestFileStatuses");
}
status = srmStatusOfBringOnlineRequestResponse.getReturnStatus();
if (status == null) {
throw new IOException(" null return status");
}
statusCode = status.getStatusCode();
if (statusCode == null) {
throw new IOException(" null status code");
}
if (RequestStatusTool.isFailedRequestStatus(status)) {
String error = "srmBringOnline update failed, status : " + statusCode + " explanation=" + status.getExplanation();
esay(error);
for (int i = 0; i < expectedResponseLength; ++i) {
TReturnStatus frstatus = bringOnlineRequestFileStatuses[i].getStatus();
if (frstatus != null) {
if (!RequestStatusTool.isTransientStateStatus(frstatus)) {
int indx = pendingSurlsToIndex.remove(bringOnlineRequestFileStatuses[i].getSourceSURL().toString());
setReportFailed(from[indx], from[indx], error);
}
esay("BringOnlineFileRequest[" + bringOnlineRequestFileStatuses[i].getSourceSURL() + "] status=" + frstatus.getStatusCode() + " explanation=" + frstatus.getExplanation());
}
}
throw new IOException(error);
}
}
} catch (Exception e) {
esay(e.toString());
} finally {
report.dumpReport();
if (!report.everythingAllRight()) {
report.reportErrors(System.err);
System.exit(1);
}
}
}
Aggregations