use of org.apache.axis.types.URI in project dcache by dCache.
the class SrmHandler method mapReleaseFilesResponse.
private SrmReleaseFilesResponse mapReleaseFilesResponse(SrmReleaseFilesRequest request, List<SrmResponse> responses) {
Map<URI, TSURLReturnStatus> map = new HashMap<>();
for (SrmResponse srmResponse : responses) {
SrmReleaseFilesResponse response = (SrmReleaseFilesResponse) srmResponse.getResponse();
for (TSURLReturnStatus status : response.getArrayOfFileStatuses().getStatusArray()) {
if (status.getStatus().getStatusCode() == SRM_SUCCESS) {
map.put(status.getSurl(), status);
} else if (status.getStatus().getStatusCode() == SRM_INVALID_PATH) {
// no entry
} else if (status.getStatus().getStatusCode() == SRM_AUTHORIZATION_FAILURE) {
map.putIfAbsent(status.getSurl(), status);
} else if (status.getStatus().getStatusCode() == SRM_FILE_LIFETIME_EXPIRED) {
map.putIfAbsent(status.getSurl(), status);
} else if (status.getStatus().getStatusCode() == SRM_FAILURE) {
map.putIfAbsent(status.getSurl(), status);
}
}
}
TSURLReturnStatus[] statuses = Stream.of(request.getArrayOfSURLs().getUrlArray()).map(surl -> {
TSURLReturnStatus status = map.get(surl);
return (status != null) ? status : new TSURLReturnStatus(surl, new TReturnStatus(SRM_INVALID_PATH, "File not found"));
}).toArray(TSURLReturnStatus[]::new);
return new SrmReleaseFilesResponse(getSummaryReturnStatus(statuses), new ArrayOfTSURLReturnStatus(statuses));
}
use of org.apache.axis.types.URI in project dcache by dCache.
the class SRMMvClientV2 method start.
@Override
public void start() throws Exception {
checkCredentialValid();
SrmMvRequest req = new SrmMvRequest();
req.setFromSURL(new URI(surl_strings[0]));
req.setToSURL(new URI(surl_strings[1]));
configuration.getStorageSystemInfo().ifPresent(req::setStorageSystemInfo);
SrmMvResponse resp = srm.srmMv(req);
TReturnStatus rs = resp.getReturnStatus();
if (rs.getStatusCode() != TStatusCode.SRM_SUCCESS) {
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");
System.out.println(sb.toString());
System.exit(1);
}
}
use of org.apache.axis.types.URI 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.apache.axis.types.URI in project dcache by dCache.
the class SRMPutClientV2 method abortAllPendingFiles.
private void abortAllPendingFiles() throws Exception {
if (pendingSurlsToIndex.isEmpty()) {
return;
}
if (response != null) {
requestToken = response.getRequestToken();
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());
}
} else {
if (response.getArrayOfFileStatuses() != null) {
if (response.getArrayOfFileStatuses().getStatusArray() != null) {
for (int i = 0; i < response.getArrayOfFileStatuses().getStatusArray().length; i++) {
URI surl = response.getArrayOfFileStatuses().getStatusArray(i).getSURL();
TReturnStatus fst = response.getArrayOfFileStatuses().getStatusArray(i).getStatus();
esay("SURL[" + i + "]=" + surl.toString() + " status=" + fst.getStatusCode() + " explanation=" + fst.getExplanation());
}
}
}
}
}
}
use of org.apache.axis.types.URI in project dcache by dCache.
the class SRMRmClientV2 method start.
@Override
public void start() throws Exception {
checkCredentialValid();
SrmRmRequest req = new SrmRmRequest();
URI[] uris = new URI[surls.length];
for (int i = 0; i < surls.length; ++i) {
uris[i] = new URI(surl_strings[i]);
}
req.setArrayOfSURLs(new ArrayOfAnyURI(uris));
configuration.getStorageSystemInfo().ifPresent(req::setStorageSystemInfo);
SrmRmResponse resp = srm.srmRm(req);
TReturnStatus rs = resp.getReturnStatus();
if (rs.getStatusCode() != TStatusCode.SRM_SUCCESS) {
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) {
TSURLReturnStatus[] arrayOfStatuses = resp.getArrayOfFileStatuses().getStatusArray();
if (arrayOfStatuses != null) {
for (int i = 0; i < arrayOfStatuses.length; i++) {
if (arrayOfStatuses[i] != null) {
sb.append("file#").append(i).append(" : ");
if (arrayOfStatuses[i].getSurl() != null) {
sb.append(arrayOfStatuses[i].getSurl());
}
if (arrayOfStatuses[i].getStatus() != null) {
sb.append(", ");
sb.append(arrayOfStatuses[i].getStatus().getStatusCode());
sb.append(", \"");
sb.append(arrayOfStatuses[i].getStatus().getExplanation());
sb.append("\"");
}
sb.append('\n');
}
}
}
}
System.out.println(sb.toString());
System.exit(1);
}
}
Aggregations