use of org.dcache.srm.v2_2.TReturnStatus in project dcache by dCache.
the class SRMCopyClientV2 method abortAllPendingFiles.
private void abortAllPendingFiles() throws Exception {
if (pendingSurlsMap.isEmpty()) {
return;
}
if (requestToken == null) {
return;
}
java.net.URI[] surl_strings = pendingSurlsMap.keySet().toArray(new java.net.URI[pendingSurlsMap.size()]);
int len = surl_strings.length;
say("Releasing all remaining file requests");
URI[] surlArray = new URI[len];
for (int i = 0; i < len; ++i) {
URI uri = new URI(surl_strings[i].toASCIIString());
surlArray[i] = uri;
}
SrmAbortFilesRequest srmAbortFilesRequest = new SrmAbortFilesRequest();
srmAbortFilesRequest.setRequestToken(requestToken);
srmAbortFilesRequest.setArrayOfSURLs(new ArrayOfAnyURI(surlArray));
SrmAbortFilesResponse srmAbortFilesResponse = srm.srmAbortFiles(srmAbortFilesRequest);
if (srmAbortFilesResponse == null) {
logger.elog(" srmAbortFilesResponse is null");
} else {
TReturnStatus returnStatus = srmAbortFilesResponse.getReturnStatus();
if (returnStatus == null) {
esay("srmAbortFiles return status is null");
return;
}
say("srmAbortFiles status code=" + returnStatus.getStatusCode());
}
}
use of org.dcache.srm.v2_2.TReturnStatus in project dcache by dCache.
the class SRMExtendFileLifeTimeClientV2 method start.
@Override
public void start() throws Exception {
checkCredentialValid();
ArrayOfAnyURI surlarray = new ArrayOfAnyURI();
URI[] uriarray = new URI[surls.length];
URI uri;
for (int i = 0; i < uriarray.length; i++) {
uri = new URI(surl_strings[i]);
uriarray[i] = uri;
}
surlarray.setUrlArray(uriarray);
SrmExtendFileLifeTimeRequest req = new SrmExtendFileLifeTimeRequest();
req.setArrayOfSURLs(surlarray);
req.setRequestToken(configuration.getExtendFileLifetimeRequestToken());
req.setNewFileLifeTime(configuration.getNewFileLifetime());
req.setNewPinLifeTime(configuration.getNewPinLifetime());
SrmExtendFileLifeTimeResponse resp = srm.srmExtendFileLifeTime(req);
if (resp == null) {
esay("Received null SrmExtendFileLifeTimeResponse");
System.exit(1);
}
try {
TReturnStatus rs = resp.getReturnStatus();
if (rs.getStatusCode() != TStatusCode.SRM_SUCCESS || configuration.isDebug()) {
TStatusCode rc = rs.getStatusCode();
StringBuilder sb = new StringBuilder();
sb.append("Return code: ").append(rc.toString()).append("\n");
sb.append("Explanation: ").append(rs.getExplanation()).append("\n");
if (resp.getArrayOfFileStatuses() != null) {
if (resp.getArrayOfFileStatuses().getStatusArray() != null) {
for (int i = 0; i < resp.getArrayOfFileStatuses().getStatusArray().length; i++) {
TSURLLifetimeReturnStatus t = resp.getArrayOfFileStatuses().getStatusArray()[i];
sb.append("surl[").append(i).append("] ").append(t.getSurl()).append("\n");
sb.append("\tReturn code: ").append(t.getStatus().getStatusCode().toString()).append("\n");
sb.append("\tExplanation: ").append(t.getStatus().getExplanation()).append("\n");
sb.append("\t\tfilelifetime=").append(t.getFileLifetime()).append("\n");
sb.append("\t\tpinlifetime=").append(t.getPinLifetime()).append("\n");
}
} else {
sb.append("array of file statuse is null\n");
}
} else {
sb.append("array of file statuse is null\n");
}
if (rs.getStatusCode() != TStatusCode.SRM_SUCCESS) {
esay(sb.toString());
System.exit(1);
} else {
say(sb.toString());
}
} else {
System.exit(0);
}
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
use of org.dcache.srm.v2_2.TReturnStatus in project dcache by dCache.
the class SRMGetClientV2 method abortAllPendingFiles.
private void abortAllPendingFiles() throws Exception {
if (pendingSurlsToIndex.isEmpty()) {
return;
}
if (requestToken != null) {
String[] surl_strings = pendingSurlsToIndex.keySet().toArray(new String[pendingSurlsToIndex.size()]);
int len = surl_strings.length;
say("Releasing all remaining file requests");
URI[] surlArray = new URI[len];
for (int i = 0; i < len; ++i) {
surlArray[i] = new URI(surl_strings[i]);
}
SrmAbortFilesRequest srmAbortFilesRequest = new SrmAbortFilesRequest();
srmAbortFilesRequest.setRequestToken(requestToken);
srmAbortFilesRequest.setArrayOfSURLs(new ArrayOfAnyURI(surlArray));
SrmAbortFilesResponse srmAbortFilesResponse = srm.srmAbortFiles(srmAbortFilesRequest);
if (srmAbortFilesResponse == null) {
logger.elog(" srmAbortFilesResponse is null");
} else {
TReturnStatus returnStatus = srmAbortFilesResponse.getReturnStatus();
if (returnStatus == null) {
esay("srmAbortFiles return status is null");
return;
}
say("srmAbortFiles status code=" + returnStatus.getStatusCode());
}
}
}
use of org.dcache.srm.v2_2.TReturnStatus in project dcache by dCache.
the class SRMGetSpaceTokensClientV2 method start.
@Override
public void start() throws Exception {
checkCredentialValid();
try {
String tokenDescription = configuration.getSpaceTokenDescription();
SrmGetSpaceTokensRequest request = new SrmGetSpaceTokensRequest();
request.setUserSpaceTokenDescription(tokenDescription);
SrmGetSpaceTokensResponse response = srm.srmGetSpaceTokens(request);
if (response == null) {
throw new IOException(" null SrmGetSpaceTokensResponse");
}
TReturnStatus rs = response.getReturnStatus();
if (rs == null) {
throw new IOException(" null TReturnStatus ");
}
if (RequestStatusTool.isFailedRequestStatus(rs)) {
throw new IOException("SrmGetSpaceTokens failed, unexpected or failed return status : " + rs.getStatusCode() + " explanation=" + rs.getExplanation());
}
if (response.getArrayOfSpaceTokens() == null || response.getArrayOfSpaceTokens().getStringArray() == null) {
throw new IOException("SrmGetSpaceTokens returned null array of space tokens");
}
String[] spaceTokens = response.getArrayOfSpaceTokens().getStringArray();
System.out.println("Space Reservation Tokens:");
for (String spaceToken : spaceTokens) {
System.out.println(spaceToken);
}
} catch (Exception e) {
throw e;
}
}
use of org.dcache.srm.v2_2.TReturnStatus in project dcache by dCache.
the class SRMLsClientV2 method start.
@Override
public void start() throws Exception {
checkCredentialValid();
try {
SrmLsRequest req = new SrmLsRequest();
req.setAllLevelRecursive(Boolean.FALSE);
req.setFullDetailedList(configuration.isLongLsFormat());
req.setNumOfLevels(configuration.getRecursionDepth());
req.setOffset(configuration.getLsOffset());
if (configuration.getLsCount() != null) {
req.setCount(configuration.getLsCount());
}
URI[] turlia = new URI[surls.length];
for (int i = 0; i < surls.length; ++i) {
turlia[i] = new URI(surl_strings[i]);
}
req.setArrayOfSURLs(new ArrayOfAnyURI(turlia));
hook = new Thread(this);
Runtime.getRuntime().addShutdownHook(hook);
configuration.getStorageSystemInfo().ifPresent(req::setStorageSystemInfo);
SrmLsResponse response = srm.srmLs(req);
if (response == null) {
throw new Exception("srm ls response is null!");
}
TReturnStatus rs = response.getReturnStatus();
requestToken = response.getRequestToken();
if (rs == null) {
throw new IOException(" null TReturnStatus ");
}
StringBuffer sb = new StringBuffer();
String statusText = "Return status:\n" + " - Status code: " + response.getReturnStatus().getStatusCode().getValue() + '\n' + " - Explanation: " + response.getReturnStatus().getExplanation();
logger.log(statusText);
if (RequestStatusTool.isFailedRequestStatus(rs)) {
sb.append(statusText).append('\n');
}
if (!RequestStatusTool.isTransientStateStatus(rs)) {
if (response.getDetails() == null) {
throw new IOException(sb.toString() + "srm ls response path details array is null!");
} else {
if (response.getDetails().getPathDetailArray() != null) {
TMetaDataPathDetail[] details = response.getDetails().getPathDetailArray();
printResults(sb, details, 0, " ", configuration.isLongLsFormat());
}
}
if (RequestStatusTool.isFailedRequestStatus(rs)) {
throw new IOException(sb.toString());
}
System.out.println(sb.toString());
} else {
if (requestToken == null) {
throw new IOException("Request is queued on the server, however the server did not provide a request token.");
}
if (RequestStatusTool.isFailedRequestStatus(rs)) {
throw new IOException(sb.toString());
}
// we assume this is asynchronous call
SrmStatusOfLsRequestRequest statusRequest = new SrmStatusOfLsRequestRequest();
statusRequest.setRequestToken(requestToken);
statusRequest.setOffset(req.getOffset());
statusRequest.setCount(req.getCount());
statusRequest.setAuthorizationID(req.getAuthorizationID());
long estimatedWaitInSeconds = 2;
while (true) {
if (estimatedWaitInSeconds > 60) {
estimatedWaitInSeconds = 60;
}
try {
say("sleeping " + estimatedWaitInSeconds + " seconds ...");
Thread.sleep(estimatedWaitInSeconds * 1000);
} catch (InterruptedException ie) {
esay("Interrupted, quitting");
if (requestToken != null) {
abortRequest();
}
System.exit(1);
}
estimatedWaitInSeconds *= 2;
SrmStatusOfLsRequestResponse statusResponse = srm.srmStatusOfLsRequest(statusRequest);
if (statusResponse == null) {
throw new IOException("SrmStatusOfLsRequestResponse is null for request " + requestToken);
}
TReturnStatus status = statusResponse.getReturnStatus();
if (status == null) {
throw new IOException(" null return status");
}
if (status.getStatusCode() == null) {
throw new IOException(" null status code");
}
if (!RequestStatusTool.isTransientStateStatus(status)) {
statusText = "Return status:\n" + " - Status code: " + status.getStatusCode().getValue() + '\n' + " - Explanation: " + status.getExplanation() + '\n' + " - request token: " + requestToken;
logger.log(statusText);
if (RequestStatusTool.isFailedRequestStatus(status)) {
sb.append(statusText).append('\n');
}
if (statusResponse.getDetails() == null) {
throw new IOException(sb.toString() + "srm ls response path details array is null!");
} else {
if (statusResponse.getDetails().getPathDetailArray() != null) {
TMetaDataPathDetail[] details = statusResponse.getDetails().getPathDetailArray();
printResults(sb, details, 0, " ", configuration.isLongLsFormat());
if (RequestStatusTool.isFailedRequestStatus(status)) {
throw new IOException(sb.toString());
}
System.out.println(sb.toString());
}
}
break;
}
}
}
} catch (Exception e) {
esay(e.getMessage());
try {
if (requestToken != null) {
abortRequest();
}
} catch (Exception e1) {
logger.elog(e1.toString());
} finally {
Runtime.getRuntime().removeShutdownHook(hook);
System.exit(1);
}
} finally {
Runtime.getRuntime().removeShutdownHook(hook);
}
}
Aggregations