From 7e2a3ed7460ea45ddd7e4cd75e5f82236f1feb47 Mon Sep 17 00:00:00 2001 From: Andrea Ceccanti Date: Tue, 14 Jan 2014 16:48:30 +0100 Subject: [PATCH 01/45] Fix for STOR-501 --- pom.xml | 2 +- src/main/java/it/grid/storm/namespace/Namespace.java | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 8ec40ec4..7eb7dd23 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ StoRM Backend server org.italiangrid.storm storm-backend-server - 1.11.3 + 1.11.4-SNAPSHOT diff --git a/src/main/java/it/grid/storm/namespace/Namespace.java b/src/main/java/it/grid/storm/namespace/Namespace.java index 03347043..e9d147e0 100644 --- a/src/main/java/it/grid/storm/namespace/Namespace.java +++ b/src/main/java/it/grid/storm/namespace/Namespace.java @@ -227,8 +227,11 @@ private StoRI resolveStoRIbySURL(TSURL surl, "Unable to perform getWinnerRule, invalid arguments"); } String stfnStr = surl.sfn().stfn().toString(); - MappingRule winnerRule = getWinnerRule(NamespaceUtil.getStFNPath(stfnStr), + + // Fix for STOR-501 + MappingRule winnerRule = getWinnerRule(stfnStr, vfsApproachable, withVFSList); + if (winnerRule == null) { /* attempt using complete file path */ winnerRule = getWinnerRule(stfnStr, vfsApproachable, withVFSList); From 35e0363b744e4155838249c118408858b6452716 Mon Sep 17 00:00:00 2001 From: Andrea Ceccanti Date: Tue, 14 Jan 2014 16:49:31 +0100 Subject: [PATCH 02/45] 1.11.4 version --- pom.xml | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/pom.xml b/pom.xml index 7eb7dd23..2e731901 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ StoRM Backend server org.italiangrid.storm storm-backend-server - 1.11.4-SNAPSHOT + 1.11.4 @@ -66,7 +66,7 @@ maven-surefire-plugin 2.13 - true @@ -93,12 +93,12 @@ - - + org.apache.maven.plugins maven-dependency-plugin @@ -116,7 +116,7 @@ - + org.codehaus.mojo wagon-maven-plugin @@ -132,7 +132,7 @@ ${remoteDeployment.url}/ ${remoteDeployment.serverId} etc - logging.xml, namespace.xml, path-authz.db, @@ -180,7 +180,7 @@ /etc/logrotate.d - + upload-deps deploy @@ -195,7 +195,7 @@ /usr/share/java/storm-backend-server - + upload-jar deploy @@ -210,10 +210,10 @@ /usr/share/java/storm-backend-server - + - + @@ -351,10 +351,10 @@ ${jsonVersion} - org.globus @@ -402,7 +402,7 @@ ${cogGlobusVersion} - srm22client @@ -473,7 +473,7 @@ runtime - org.apache.oro From 02dde9602fde4576bf70d9f2ab1ffda1a84fba19 Mon Sep 17 00:00:00 2001 From: enricovianello Date: Wed, 15 Jan 2014 16:59:02 +0100 Subject: [PATCH 03/45] little adjustments to Namespace.java --- .../it/grid/storm/namespace/Namespace.java | 119 +++++++----------- 1 file changed, 47 insertions(+), 72 deletions(-) diff --git a/src/main/java/it/grid/storm/namespace/Namespace.java b/src/main/java/it/grid/storm/namespace/Namespace.java index e9d147e0..961a4f32 100644 --- a/src/main/java/it/grid/storm/namespace/Namespace.java +++ b/src/main/java/it/grid/storm/namespace/Namespace.java @@ -96,8 +96,7 @@ public String getNamespaceVersion() throws NamespaceException { return parser.getNamespaceVersion(); } - public Collection getAllDefinedVFS() - throws NamespaceException { + public Collection getAllDefinedVFS() { return parser.getVFSs().values(); } @@ -161,12 +160,15 @@ public StoRI resolveStoRIbySURL(TSURL surl, GridUserInterface user) log.error("Received null parameters: surl= " + surl + " user=" + user); throw new IllegalArgumentException("Received null parameters"); } + List vfsApproachable = getApproachableVFS(user); - - StoRI stori = resolveStoRIbySURL(surl, vfsApproachable); - if (stori == null) + StoRI stori = resolveStoRIbySURL(surl); + + if (stori == null + || !vfsApproachable.contains(stori.getVirtualFileSystem())) { throw new UnapprochableSurlException("Surl " + surl + " is not approchable by user " + user); + } return stori; } @@ -183,31 +185,17 @@ public StoRI resolveStoRIbySURL(TSURL surl, GridUserInterface user) * @return StoRI * @throws NamespaceException */ - private StoRI resolveStoRIbySURL(TSURL surl, - List vfsApproachable) throws UnapprochableSurlException { - - log.debug("Resolving StoRI from surl " + surl + " on " + vfsApproachable - + " VFS"); - return resolveStoRIbySURL(surl, vfsApproachable, true); - } - - /** - * - * The resolution is based on the retrieving of the Winner Rule 1) First - * attempt is based on StFN-Path 2) Second attempt is based on all StFN. That - * because is possible that SURL is expressed without File Name so StFN is a - * directory. ( Special case is when the SFN does not contain the File Name - * and ALL the StFN is considerable as StFN-Path. ) - * - * @param surl - * TSURL - * @return StoRI - * @throws NamespaceException - */ - public StoRI resolveStoRIbySURL(TSURL surl) throws UnapprochableSurlException { + public StoRI resolveStoRIbySURL(TSURL surl) throws IllegalArgumentException, + UnapprochableSurlException { + + if (surl == null) { + log.error("Unable to perform resolveStoRIbySURL, invalid arguments: surl=" + surl); + throw new IllegalArgumentException("Unable to perform getWinnerRule, invalid arguments"); + } log.debug("Resolving StoRI from surl " + surl + " on any VFS"); - StoRI stori = resolveStoRIbySURL(surl, null, false); + StoRI stori = resolveStoRIbySURL(surl, + new ArrayList(getAllDefinedVFS())); if (stori == null) { throw new UnapprochableSurlException("Surl " + surl + " is not managed by this StoRM instance"); @@ -216,51 +204,35 @@ public StoRI resolveStoRIbySURL(TSURL surl) throws UnapprochableSurlException { } private StoRI resolveStoRIbySURL(TSURL surl, - List vfsApproachable, boolean withVFSList) { + List vfsApproachable) throws UnapprochableSurlException { - if (surl == null || withVFSList && vfsApproachable == null) { - log - .error("Unable to perform resolveStoRIbySURL, invalid arguments: surl=" - + surl + " withVFSList=" + withVFSList + " vfsApproachable=" - + vfsApproachable); - throw new IllegalArgumentException( - "Unable to perform getWinnerRule, invalid arguments"); - } String stfnStr = surl.sfn().stfn().toString(); - - // Fix for STOR-501 - MappingRule winnerRule = getWinnerRule(stfnStr, - vfsApproachable, withVFSList); - + MappingRule winnerRule = getWinnerRule(stfnStr, vfsApproachable); if (winnerRule == null) { - /* attempt using complete file path */ - winnerRule = getWinnerRule(stfnStr, vfsApproachable, withVFSList); + log.debug("Unable to perform resolveStoRIbySURL, no MappingRule matches SURL " + surl); + return null; } StoRI stori = null; - if (winnerRule != null) { - log.debug("For StFN " + stfnStr + " the winner Rule is " - + winnerRule.getRuleName()); - stori = winnerRule.getMappedFS().createFile( - NamespaceUtil.extractRelativePath(winnerRule.getStFNRoot(), - stfnStr), StoRIType.FILE); - stori.setStFNRoot(winnerRule.getStFNRoot()); - stori.setMappingRule(winnerRule); - try { - if (!stori.getLocalFile().getCanonicalPath().startsWith(winnerRule.getMappedFS().getRootPath())) { - log.debug("Unable to perform resolveStoRIbySURL, '" - + stori.getLocalFile().getCanonicalPath() + "' doesn't belong to '" - + winnerRule.getMappedFS().getAliasName() + "'"); - return null; - } else { - log.debug("'" + stori.getLocalFile().getCanonicalPath() + "' belongs to '" - + winnerRule.getMappedFS().getAliasName() + "'"); - } - } catch (IOException e) { - log.debug("Unable to perform resolveStoRIbySURL, " + e.getMessage()); + log.debug("For StFN " + stfnStr + " the winner Rule is " + + winnerRule.getRuleName()); + stori = winnerRule.getMappedFS().createFile( + NamespaceUtil.extractRelativePath(winnerRule.getStFNRoot(), stfnStr), + StoRIType.FILE); + stori.setStFNRoot(winnerRule.getStFNRoot()); + stori.setMappingRule(winnerRule); + try { + if (!stori.getLocalFile().getCanonicalPath() + .startsWith(winnerRule.getMappedFS().getRootPath())) { + log.debug("Unable to perform resolveStoRIbySURL, '" + + stori.getLocalFile().getCanonicalPath() + "' doesn't belong to '" + + winnerRule.getMappedFS().getAliasName() + "'"); return null; + } else { + log.debug("'" + stori.getLocalFile().getCanonicalPath() + + "' belongs to '" + winnerRule.getMappedFS().getAliasName() + "'"); } - } else { - log.debug("Unable to perform resolveStoRIbySURL, no MappingRule matches SURL " + surl); + } catch (IOException e) { + log.debug("Unable to perform resolveStoRIbySURL, " + e.getMessage()); return null; } return stori; @@ -280,12 +252,15 @@ public VirtualFSInterface resolveVFSbySURL(TSURL surl, GridUserInterface user) private VirtualFSInterface resolveVFSbySURL(TSURL surl, List vfsApproachable) { - - MappingRule winnerRule = getWinnerRule( - NamespaceUtil.getStFNPath(surl.sfn().stfn().toString()), vfsApproachable); - log.debug("For surl " + surl + " the winner Rule is " - + winnerRule.getRuleName()); - return parser.getVFS(winnerRule.getMappedFS().getAliasName()); + + String stfnStr = surl.sfn().stfn().toString(); + MappingRule winnerRule = getWinnerRule(stfnStr, vfsApproachable); + if (winnerRule == null) { + log.debug("Unable to perform resolveStoRIbySURL, no MappingRule matches SURL " + surl); + return null; + } + log.debug("For surl " + surl + " the winner Rule is " + winnerRule.getRuleName()); + return winnerRule.getMappedFS(); } public StoRI resolveStoRIbyAbsolutePath(String absolutePath, From a81d3de3ac31300b2030e98eb437ce587212282a Mon Sep 17 00:00:00 2001 From: Andrea Ceccanti Date: Wed, 15 Jan 2014 19:07:03 +0100 Subject: [PATCH 04/45] Fix for STOR-505 Now the StFN are correctly computed from the winning mapping rule for a given ls request. --- .../it/grid/storm/namespace/Namespace.java | 72 +++++++++++-------- .../java/it/grid/storm/namespace/StoRI.java | 2 + .../it/grid/storm/namespace/StoRIImpl.java | 69 ++++++++++-------- .../command/directory/LsCommand.java | 8 +-- 4 files changed, 88 insertions(+), 63 deletions(-) diff --git a/src/main/java/it/grid/storm/namespace/Namespace.java b/src/main/java/it/grid/storm/namespace/Namespace.java index e9d147e0..6a8cfbe9 100644 --- a/src/main/java/it/grid/storm/namespace/Namespace.java +++ b/src/main/java/it/grid/storm/namespace/Namespace.java @@ -226,44 +226,54 @@ private StoRI resolveStoRIbySURL(TSURL surl, throw new IllegalArgumentException( "Unable to perform getWinnerRule, invalid arguments"); } + String stfnStr = surl.sfn().stfn().toString(); - // Fix for STOR-501 MappingRule winnerRule = getWinnerRule(stfnStr, vfsApproachable, withVFSList); - if (winnerRule == null) { - /* attempt using complete file path */ - winnerRule = getWinnerRule(stfnStr, vfsApproachable, withVFSList); - } - StoRI stori = null; - if (winnerRule != null) { - log.debug("For StFN " + stfnStr + " the winner Rule is " - + winnerRule.getRuleName()); - stori = winnerRule.getMappedFS().createFile( - NamespaceUtil.extractRelativePath(winnerRule.getStFNRoot(), - stfnStr), StoRIType.FILE); - stori.setStFNRoot(winnerRule.getStFNRoot()); - stori.setMappingRule(winnerRule); - try { - if (!stori.getLocalFile().getCanonicalPath().startsWith(winnerRule.getMappedFS().getRootPath())) { - log.debug("Unable to perform resolveStoRIbySURL, '" - + stori.getLocalFile().getCanonicalPath() + "' doesn't belong to '" - + winnerRule.getMappedFS().getAliasName() + "'"); - return null; - } else { - log.debug("'" + stori.getLocalFile().getCanonicalPath() + "' belongs to '" - + winnerRule.getMappedFS().getAliasName() + "'"); - } - } catch (IOException e) { - log.debug("Unable to perform resolveStoRIbySURL, " + e.getMessage()); - return null; - } - } else { - log.debug("Unable to perform resolveStoRIbySURL, no MappingRule matches SURL " + surl); + if (winnerRule == null){ + log.debug("Unable to perform resolveStoRIbySURL, " + + "no MappingRule matches SURL " + surl); return null; } - return stori; + + log.debug("For StFN " + stfnStr + " the winner Rule is " + + winnerRule.getRuleName()); + + StoRI stori = winnerRule.getMappedFS().createFile( + NamespaceUtil.extractRelativePath(winnerRule.getStFNRoot(), + stfnStr), StoRIType.FILE); + + stori.setStFNRoot(winnerRule.getStFNRoot()); + stori.setMappingRule(winnerRule); + + try { + + if (stori + .getLocalFile() + .getCanonicalPath() + .startsWith(winnerRule.getMappedFS().getRootPath())){ + + log.debug("'" + stori.getLocalFile().getCanonicalPath() + "' belongs to '" + + winnerRule.getMappedFS().getAliasName() + "'"); + return stori; + + } else { + + log.debug("Unable to perform resolveStoRIbySURL, '" + + stori.getLocalFile().getCanonicalPath() + "' doesn't belong to '" + + winnerRule.getMappedFS().getAliasName() + "'"); + return null; + } + } catch (IOException e) { + + log.error("Error resolving stori for surl {}: {}.", + surl, e.getMessage(), e); + + return null; + } + } public VirtualFSInterface resolveVFSbySURL(TSURL surl, GridUserInterface user) diff --git a/src/main/java/it/grid/storm/namespace/StoRI.java b/src/main/java/it/grid/storm/namespace/StoRI.java index 685c8b50..6d06c961 100644 --- a/src/main/java/it/grid/storm/namespace/StoRI.java +++ b/src/main/java/it/grid/storm/namespace/StoRI.java @@ -60,6 +60,8 @@ public TTURL getTURL(TURLPrefix prefixOfAcceptedTransferProtocols) public PFN getPFN(); public StFN getStFN(); + + public StFN getStFNFromMappingRule(); public String getRelativePath(); diff --git a/src/main/java/it/grid/storm/namespace/StoRIImpl.java b/src/main/java/it/grid/storm/namespace/StoRIImpl.java index 5aac23db..9c3b50c5 100644 --- a/src/main/java/it/grid/storm/namespace/StoRIImpl.java +++ b/src/main/java/it/grid/storm/namespace/StoRIImpl.java @@ -22,6 +22,7 @@ import it.grid.storm.balancer.Node; import it.grid.storm.catalogs.VolatileAndJiTCatalog; import it.grid.storm.common.types.InvalidPFNAttributeException; +import it.grid.storm.common.types.InvalidStFNAttributeException; import it.grid.storm.common.types.PFN; import it.grid.storm.common.types.StFN; import it.grid.storm.common.types.TURLPrefix; @@ -362,7 +363,11 @@ public ArrayList getChildren(TDirOption dirOption) log.debug(":Creation of new StoRI with path : " + childPath); try { - stoRIList.add(namespace.resolveStoRIbyAbsolutePath(childPath)); + + StoRI childStorI = namespace.resolveStoRIbyAbsolutePath(childPath); + childStorI.setMappingRule(getMappingRule()); + + stoRIList.add(childStorI); } catch (NamespaceException ex) { log.error("Error occurred while resolving StoRI by absolute path", ex); @@ -566,7 +571,7 @@ public TTURL getTURL(TURLPrefix desiredProtocols) transProt = protList.get(0); authority = transProt.getAuthority(); } - // TODO HTTPS TURL + resultTURL = buildTURL(choosen, authority); turlBuilt = true; } @@ -659,14 +664,11 @@ public void setStoRIType(StoRIType type) { this.type = type; } - /*********************************************** - * UTILITY METHODS - **********************************************/ - @Override public String toString() { StringBuffer sb = new StringBuffer(); + sb.append("\n"); sb.append(" stori.stfn : " + this.getStFN().toString() + "\n"); sb.append(" stori.vfs-root :" + this.vfsRoot + "\n"); @@ -680,6 +682,7 @@ public String toString() { sb.append(" story.type : " + this.type + "\n"); sb.append(" stori.SURL : " + this.getSURL() + "\n"); sb.append(" stori.localFile : " + this.getLocalFile() + "\n"); + sb.append(" stori.mappingRule : " + this.getMappingRule() + "\n"); return sb.toString(); } @@ -691,29 +694,11 @@ private String buildSURLString() throws NamespaceException { return surl.toString(); } - // TODO MICHELE HTTPS here we can add a case to build https TURL...what really - // matter is that probably because it is an URL we cannot build it - // just using the infomation available actually from the parameters - // I can make an hypothesis on web server url construction, maybe it is - // https://server_name.server_domain:web_server_https_port/file_server_service_identifier/file_relative_url - // in such a case we need: web_server_https_port -> can be retrieved from - // Protocol object : we can associate a default port to protocol the effective - // value - // has to be demanded to the connector - // file_server_service_identifier -> also from Protocol object ... not so - // true... hummm : it has to be demanded to the connector - // file_relative_url -> here start real problems... : we have to hope that - // from the physicalFN we are able to build this value - // - it has to be demanded to the connector - // TODO HTTPS TURL - // private TTURL buildTURL(Protocol protocol, Authority authority, PFN - // physicalFN) throws InvalidProtocolForTURLException { private TTURL buildTURL(Protocol protocol, Authority authority) throws InvalidProtocolForTURLException { TTURL result = null; - // TODO MICHELE HTTPS NOTE: this is the only access point to TURLBuilder - // class (good sign) + switch (protocol.getProtocolIndex()) { case 0: // EMPTY Protocol throw new InvalidProtocolForTURLException(protocol.getSchema()); @@ -731,7 +716,6 @@ private TTURL buildTURL(Protocol protocol, Authority authority) case 5: result = TURLBuilder.buildROOTTURL(authority, this.getPFN()); break; // ROOT Protocol - // TODO HTTPS TURL case 6: try { result = TURLBuilder.buildHTTPTURL(authority, this.getLocalFile()); @@ -756,8 +740,9 @@ private TTURL buildTURL(Protocol protocol, Authority authority) break; // HTTPS Protocol default: - throw new InvalidProtocolForTURLException(protocol.getSchema()); // UNKNOWN - // Protocol + // Unknown protocol + throw new InvalidProtocolForTURLException(protocol.getSchema()); + } return result; } @@ -813,4 +798,32 @@ private void setVolatileInformation() { volatileInformationAreSet = true; } + @Override + public StFN getStFNFromMappingRule() { + try { + + if (getMappingRule() == null){ + log.warn("Mapping rule is null for this StorI. " + + "Falling back to VFS StFN."); + return getStFN(); + } + + String mappingRuleRoot = getMappingRule().getStFNRoot(); + String mappedStfn = mappingRuleRoot + NamingConst.SEPARATOR + + relativeStFN; + + return StFN.make(mappedStfn); + + } catch (InvalidStFNAttributeException e) { + + log.error("Error building StFN from mapping rule. Reason: {}", + e.getMessage(),e); + + log.error("Falling back to VFS StFN."); + + return getStFN(); + + } + } + } diff --git a/src/main/java/it/grid/storm/synchcall/command/directory/LsCommand.java b/src/main/java/it/grid/storm/synchcall/command/directory/LsCommand.java index 2ae7b4fa..d81342b1 100644 --- a/src/main/java/it/grid/storm/synchcall/command/directory/LsCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/directory/LsCommand.java @@ -343,7 +343,7 @@ public OutputData execute(InputData data) { elementDetail.setStatus(status); elementDetail.setSurl(surl); if (stori != null) { - elementDetail.setStFN(stori.getStFN()); + elementDetail.setStFN(stori.getStFNFromMappingRule()); } else { elementDetail.setStFN(surl.sfn().stfn()); } @@ -505,7 +505,7 @@ private int manageAuthorizedLS(LSInputData inputData, StoRI stori, } } // In Any case set SURL value into TMetaDataPathDetail - currentElementDetail.setStFN(stori.getStFN()); + currentElementDetail.setStFN(stori.getStFNFromMappingRule()); numberOfResults.increment(); rootArray.addTMetaDataPathDetail(currentElementDetail); @@ -565,7 +565,7 @@ private int manageAuthorizedLS(LSInputData inputData, StoRI stori, } // In Any case set SURL value into TMetaDataPathDetail - currentElementDetail.setStFN(stori.getStFN()); + currentElementDetail.setStFN(stori.getStFNFromMappingRule()); numberOfResults.increment(); rootArray.addTMetaDataPathDetail(currentElementDetail); } @@ -577,7 +577,7 @@ private int manageAuthorizedLS(LSInputData inputData, StoRI stori, if (numberOfIterations.intValue() >= offset) { errorCount++; // In Any case set SURL value into TMetaDataPathDetail - currentElementDetail.setStFN(stori.getStFN()); + currentElementDetail.setStFN(stori.getStFNFromMappingRule()); // Set Error Status Code and Explanation populateDetailFromFS(stori, currentElementDetail); // Add the information into details structure From 50090e8b1265d25e3394af365302c84c0326de88 Mon Sep 17 00:00:00 2001 From: enricovianello Date: Fri, 17 Jan 2014 10:54:44 +0100 Subject: [PATCH 05/45] Explanation string is truncated if too long --- .../grid/storm/srm/types/TReturnStatus.java | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/main/java/it/grid/storm/srm/types/TReturnStatus.java b/src/main/java/it/grid/storm/srm/types/TReturnStatus.java index 01915f9b..5e9529ce 100644 --- a/src/main/java/it/grid/storm/srm/types/TReturnStatus.java +++ b/src/main/java/it/grid/storm/srm/types/TReturnStatus.java @@ -31,15 +31,23 @@ import java.util.HashMap; import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class TReturnStatus implements Serializable { private static final long serialVersionUID = -4550845540710062810L; + private static final Logger log = LoggerFactory + .getLogger(TReturnStatus.class); + protected TStatusCode statusCode = null; protected String explanation = null; private Long lastUpdateTIme = null; private static final String UNDEFINED_EXPLANATION = "undefined"; + private static final String EMPTY_EXPLANATION = ""; + private static final int MAX_EXPLANATION_LENGTH = 255; public static final String PNAME_RETURNSTATUS = "returnStatus"; public static final String PNAME_STATUS = "status"; @@ -62,7 +70,7 @@ public TReturnStatus(TReturnStatus original) throw new InvalidTReturnStatusAttributeException(statusCode); } this.statusCode = original.statusCode; - this.explanation = original.explanation; + this.setExplanation(original.getExplanation()); updated(); } @@ -82,7 +90,7 @@ public TReturnStatus(TStatusCode statusCode, String explanation) throw new InvalidTReturnStatusAttributeException(statusCode); } this.statusCode = statusCode; - this.explanation = explanation; + this.setExplanation(explanation); updated(); } @@ -143,7 +151,16 @@ protected void setStatusCode(TStatusCode statusCode) { */ protected void setExplanation(String explanationString) { - explanation = (explanationString == null ? "" : explanationString); + if (explanationString == null) { + this.explanation = EMPTY_EXPLANATION; + } else if (explanationString.length() <= MAX_EXPLANATION_LENGTH) { + this.explanation = explanationString; + } else { + this.explanation = explanationString.substring(0, MAX_EXPLANATION_LENGTH); + log.warn(String.format( + "Explanation string truncated at %d characters: '%s'", + MAX_EXPLANATION_LENGTH, this.explanation)); + } updated(); } @@ -201,7 +218,7 @@ public boolean isSRM_SUCCESS() { public void extendExplaination(String string) { - this.explanation += " [ " + string + " ]"; + this.setExplanation(this.getExplanation() + " [ " + string + " ]"); } /* From 2cbbfd7893c916e9f8a8e69beabc46a62a8ab665 Mon Sep 17 00:00:00 2001 From: enricovianello Date: Fri, 17 Jan 2014 18:13:40 +0100 Subject: [PATCH 06/45] Fixed sym link management --- .../it/grid/storm/namespace/Namespace.java | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/main/java/it/grid/storm/namespace/Namespace.java b/src/main/java/it/grid/storm/namespace/Namespace.java index 0500334a..8267e861 100644 --- a/src/main/java/it/grid/storm/namespace/Namespace.java +++ b/src/main/java/it/grid/storm/namespace/Namespace.java @@ -205,14 +205,6 @@ private StoRI resolveStoRIbySURL(TSURL surl, MappingRule winnerRule = getWinnerRule(surl); log.debug(String.format("For SURL %s the winner Rule is %s", surl, winnerRule.getRuleName())); - - if (!vfsApproachable.contains(winnerRule.getMappedFS())) { - String msg = String.format( - "VFS '%s' is not on the approachable VFS list!", winnerRule - .getMappedFS().getAliasName()); - log.debug(msg); - throw new UnapprochableSurlException(msg); - } StoRI stori = winnerRule.getMappedFS().createFile( NamespaceUtil.extractRelativePath(winnerRule.getStFNRoot(), surl.sfn() @@ -231,18 +223,33 @@ private StoRI resolveStoRIbySURL(TSURL surl, } if (realPath.startsWith(winnerRule.getMappedFS().getRootPath())) { - log.debug(String.format("Resource '%s' belongs to '%s'", realPath, - winnerRule.getMappedFS().getAliasName())); - return stori; + if (vfsApproachable.contains(winnerRule.getMappedFS())) { + log.debug(String.format("Resource '%s' belongs to '%s'", realPath, + winnerRule.getMappedFS().getAliasName())); + return stori; + } + String msg = String.format( + "VFS '%s' is not on the approachable VFS list!", winnerRule + .getMappedFS().getAliasName()); + log.debug(msg); + throw new UnapprochableSurlException(msg); } - + String msg = String.format("Resource '%s' doesn't belong to %s", realPath, winnerRule.getMappedFS().getAliasName()); log.debug(msg); VirtualFSInterface redirectedVFS = getWinnerVFS(realPath); - log.debug(String.format("Surl %s is a symbolic link to %s", surl, redirectedVFS.getAliasName())); - if (vfsApproachable.contains(winnerRule.getMappedFS())) { - log.debug(String.format("%s is approachable", redirectedVFS.getAliasName())); + log.debug(String.format("Surl %s is a symbolic link to %s", surl, + redirectedVFS.getAliasName())); + if (vfsApproachable.contains(redirectedVFS)) { + log.debug(String.format("%s is approachable", + redirectedVFS.getAliasName())); + MappingRule rule = redirectedVFS.getMappingRules().get(0); + stori = redirectedVFS.createFile(NamespaceUtil.extractRelativePath( + redirectedVFS.getRootPath(), realPath), StoRIType.FILE); + + stori.setStFNRoot(rule.getStFNRoot()); + stori.setMappingRule(rule); return stori; } throw new UnapprochableSurlException(String.format( From 5df1971b7455f62dcd8171778997b65d590c3b91 Mon Sep 17 00:00:00 2001 From: Andrea Ceccanti Date: Wed, 22 Jan 2014 14:05:03 +0100 Subject: [PATCH 07/45] Improved error reporting for SpaceHelper. --- .gitignore | 1 + .../java/it/grid/storm/space/SpaceHelper.java | 217 +++++++++--------- 2 files changed, 114 insertions(+), 104 deletions(-) diff --git a/.gitignore b/.gitignore index 4c28d9d8..306f8b0d 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ .checkstyle target src/main/java/rebel*.xml +/bin diff --git a/src/main/java/it/grid/storm/space/SpaceHelper.java b/src/main/java/it/grid/storm/space/SpaceHelper.java index 8a6ba2a7..fa43188f 100644 --- a/src/main/java/it/grid/storm/space/SpaceHelper.java +++ b/src/main/java/it/grid/storm/space/SpaceHelper.java @@ -66,8 +66,8 @@ public class SpaceHelper { - private static final int ADD = 0; - private static final int REMOVE = 1; + private static final int ADD_FREE_SPACE = 0; + private static final int REMOVE_FREE_SPACE = 1; private Configuration config; private static final Logger log = LoggerFactory.getLogger(SpaceHelper.class); public static GridUserInterface storageAreaOwner = GridUserManager @@ -77,119 +77,128 @@ public SpaceHelper() { config = Configuration.getInstance(); } + - /** - * @param log - * @param funcName - * @param user - * @param surl - */ private void updateSpaceUsageForSA(Logger log, String funcName, GridUserInterface user, TSURL surl, int operation, long filesize) { - log.debug(funcName + " Updating Storage Area free size on db"); + log.debug("{}: Updating Storage Area free size on db", funcName); + ReservedSpaceCatalog catalog = new ReservedSpaceCatalog(); StoRI stori = null; - // Retrieve the StoRI associate to the SURL - if (user == null) { - // implicit put done by TimerTask - try { - stori = NamespaceDirector.getNamespace().resolveStoRIbySURL(surl); - } catch (UnapprochableSurlException e) { - log.warn("Unable to build a stori for requested surl " + surl - + " UnapprochableSurlException: " + e.getMessage()); - return; - } - } else { - try { - stori = NamespaceDirector.getNamespace().resolveStoRIbySURL(surl, user); - } catch (IllegalArgumentException e) { - log.error( - funcName + " Unable to build StoRI by SURL and user: " + surl, e); - return; - } catch (UnapprochableSurlException e) { - log.warn("Unable to build a stori for surl " + surl + " for user " - + user + " UnapprochableSurlException: " + e.getMessage()); - return; + + try { + // FIXME: should be fixed in NamespaceDirector to avoid having + // two distinct calls if user is null or not. + // The resolveStoRIBySURL(surl, user) should handle this. + if (user == null){ + + stori = NamespaceDirector.getNamespace().resolveStoRIbySURL(surl); + + } else { + + stori = NamespaceDirector + .getNamespace() + .resolveStoRIbySURL(surl, user); } - } - // Get Virtual FileSystem for DB information - VirtualFSInterface fs = stori.getVirtualFileSystem(); - - // Get StorageSpaceData from the database - StorageSpaceData spaceData = null; - - spaceData = catalog.getStorageSpaceByAlias(fs.getSpaceTokenDescription()); + + } catch(UnapprochableSurlException e){ + + log.warn("Unable to build stori for surl {} and user {}: {}", + new Object[]{surl,user,e.getMessage()},e); + return; + + } catch( IllegalArgumentException e) { + + log.error(e.getMessage(),e); + return; + } - // Get the localELement to know the real file size, if exists + VirtualFSInterface fs = stori.getVirtualFileSystem(); + StorageSpaceData spaceData = catalog.getStorageSpaceByAlias(fs.getSpaceTokenDescription()); LocalFile localElement = stori.getLocalFile(); - - if (spaceData != null - && (localElement.exists() || operation == SpaceHelper.ADD)) { - - // IF PutDone, calculate the real fileSize - if (operation == SpaceHelper.REMOVE) { - // increase used size by localElement size - filesize = localElement.getExactSize(); - // else in case of RM the filesize is passed from the client - } - - TSizeInBytes availableSize = spaceData.getAvailableSpaceSize(); - long usedSize = -1; - if (operation == SpaceHelper.REMOVE) { - // remainingSize = availableSize.value() - filesize; - usedSize = spaceData.getUsedSpaceSize().value() + filesize; - } else if (operation == SpaceHelper.ADD) { - // The new remaining size cannot be greater than the total size - long newAvailableSize = availableSize.value() + filesize; - // Use Storage Area Total Size as upper limit for the new Unused Size - long totalSize = spaceData.getTotalSpaceSize().value(); - newAvailableSize = (newAvailableSize > totalSize) ? totalSize - : newAvailableSize; - long reservedSize = spaceData.getReservedSpaceSize().isEmpty() ? 0 - : spaceData.getReservedSpaceSize().value(); - long unavailableSize = spaceData.getUnavailableSpaceSize().isEmpty() ? 0 - : spaceData.getUnavailableSpaceSize().value(); - usedSize = totalSize - newAvailableSize - reservedSize - - unavailableSize; - } - - // Prevent negative value - if (usedSize < 0) { - usedSize = 0; - } - - // Update the unused space size with new value - TSizeInBytes newUsedSize = spaceData.getTotalSpaceSize(); - try { - newUsedSize = TSizeInBytes.make(usedSize, SizeUnit.BYTES); - } catch (InvalidTSizeAttributesException ex) { - // never thrown - log - .error( - funcName - + " Unexpected InvalidTSizeAttributesException , Unable to create new used size, so the previous one is used", - ex); - } - - spaceData.setUsedSpaceSize(newUsedSize); - - try { - fs.storeSpaceByToken(spaceData); - } catch (NamespaceException e) { - log.error(funcName + " Unable to update the new free size.", e); + + if (spaceData == null){ + log.error("{}: StorageSpace not found from space token description: {}", + funcName, + fs.getSpaceTokenDescription()); + return; + } + + TSizeInBytes availableSize = spaceData.getAvailableSpaceSize(); + long usedSize = -1; + + if (operation == SpaceHelper.ADD_FREE_SPACE){ + + log.debug("Adding {} bytes of free space to Storage Area {}", + filesize, fs.getAliasName()); + + long totalSize = spaceData.getTotalSpaceSize().value(); + long newAvailableSize = availableSize.value() + filesize; + + // The new remaining size cannot be greater than the total size + if (newAvailableSize > totalSize) { + newAvailableSize = totalSize; } + + long reservedSize = spaceData.getReservedSpaceSize().isEmpty() ? 0 + : spaceData.getReservedSpaceSize().value(); + + long unavailableSize = spaceData.getUnavailableSpaceSize().isEmpty() ? 0 + : spaceData.getUnavailableSpaceSize().value(); + + usedSize = totalSize - newAvailableSize - reservedSize + - unavailableSize; + + } else if (operation == SpaceHelper.REMOVE_FREE_SPACE){ + + if (!localElement.exists()){ + log.error("{}: Local file not found to compute space size change: {}", + funcName, + localElement); + return; + } + + log.debug("Removing {} bytes of free space from Storage Area {}", + filesize, fs.getAliasName()); + + usedSize = spaceData.getUsedSpaceSize().value() + localElement.getSize(); + + } + + // Prevent used size negative values. + if (usedSize < 0){ + usedSize = 0; + } + + TSizeInBytes oldUsedSize = null, newUsedSize = null; + + // Update used size + try{ + + oldUsedSize = spaceData.getTotalSpaceSize(); + newUsedSize = TSizeInBytes.make(usedSize, SizeUnit.BYTES); + spaceData.setUsedSpaceSize(newUsedSize); + + }catch(InvalidTSizeAttributesException e){ + + log.error("Error creating new used size: {}.",e.getMessage(),e); + log.info("Falling back to old used size value: {}", oldUsedSize.value()); + spaceData.setUsedSpaceSize(oldUsedSize); + } + + + try { - log.debug(funcName + " Storage Area used size updated to: " - + newUsedSize.value()); + fs.storeSpaceByToken(spaceData); - } else { - // Nothing to do. Problem with DB? - log.error(funcName + " Unable to update the DB used size!"); + } catch (NamespaceException e) { + log.error("Error storing updated space data: {}. {}", spaceData, e.getMessage(), e); return; } - + + log.debug("{}: Starage Area used size updated to {}", spaceData.getUsedSpaceSize().value()); } /** @@ -217,7 +226,7 @@ public void consumeSpaceForSA(Logger log, String funcName, .get(i); TSURL surl = chunkData.toSURL(); - updateSpaceUsageForSA(log, funcName, user, surl, SpaceHelper.REMOVE, 0); + updateSpaceUsageForSA(log, funcName, user, surl, SpaceHelper.REMOVE_FREE_SPACE, 0); } @@ -232,7 +241,7 @@ public void consumeSpaceForSA(Logger log, String funcName, public void decreaseFreeSpaceForSA(Logger log, String funcName, GridUserInterface user, TSURL surl) { - updateSpaceUsageForSA(log, funcName, user, surl, SpaceHelper.REMOVE, 0); + updateSpaceUsageForSA(log, funcName, user, surl, SpaceHelper.REMOVE_FREE_SPACE, 0); } @@ -249,13 +258,13 @@ public void decreaseFreeSpaceForSA(Logger log, String funcName, public void increaseFreeSpaceForSA(Logger log, String funcName, GridUserInterface user, TSURL surl, long fileSize) { - updateSpaceUsageForSA(log, funcName, user, surl, SpaceHelper.ADD, fileSize); + updateSpaceUsageForSA(log, funcName, user, surl, SpaceHelper.ADD_FREE_SPACE, fileSize); } public void increaseFreeSpaceForSA(Logger log, String funcName, TSURL surl, long fileSize) { - updateSpaceUsageForSA(log, funcName, null, surl, SpaceHelper.ADD, fileSize); + updateSpaceUsageForSA(log, funcName, null, surl, SpaceHelper.ADD_FREE_SPACE, fileSize); } public boolean isSAFull(Logger log, StoRI stori) { From 4b3b40733e8f62b42875e8bcbcfb62355a78d74e Mon Sep 17 00:00:00 2001 From: enricovianello Date: Wed, 22 Jan 2014 16:54:54 +0100 Subject: [PATCH 08/45] Fixed StoRI resolving --- .../it/grid/storm/namespace/Namespace.java | 213 ++++++++++-------- 1 file changed, 115 insertions(+), 98 deletions(-) diff --git a/src/main/java/it/grid/storm/namespace/Namespace.java b/src/main/java/it/grid/storm/namespace/Namespace.java index 8267e861..673b7c85 100644 --- a/src/main/java/it/grid/storm/namespace/Namespace.java +++ b/src/main/java/it/grid/storm/namespace/Namespace.java @@ -152,7 +152,7 @@ public boolean isApproachable(StoRI storageResource, GridUserInterface gridUser) throws NamespaceException { return getApproachableVFS(gridUser).contains(storageResource.getVirtualFileSystem()); } - + /** * * The resolution is based on the retrieving of the Winner Rule 1) First @@ -170,92 +170,114 @@ public boolean isApproachable(StoRI storageResource, public StoRI resolveStoRIbySURL(TSURL surl) throws IllegalArgumentException, UnapprochableSurlException, NamespaceException, InvalidSURLException { - if (surl == null) { - String errorMsg = String.format("Received null parameter: surl=%s", surl); - log.error(errorMsg); - throw new IllegalArgumentException(errorMsg); - } - - List allVFSs = new ArrayList(this.getAllDefinedVFS()); - - return resolveStoRIbySURL(surl, allVFSs); + return resolveStoRI(surl, null); } - + public StoRI resolveStoRIbySURL(TSURL surl, GridUserInterface user) - throws IllegalArgumentException, UnapprochableSurlException, NamespaceException, InvalidSURLException { - - if (surl == null || user == null) { - log.error("Received null parameters: surl= " + surl + " user=" + user); - throw new IllegalArgumentException("Received null parameters"); - } - - List vfsApproachable = getApproachableVFS(user); - if (vfsApproachable.isEmpty()) { - String errorMsg = String.format("Surl %s is not approachable by user %s", surl, user); - log.debug(errorMsg); - throw new UnapprochableSurlException(errorMsg); - } + throws IllegalArgumentException, UnapprochableSurlException, + NamespaceException, InvalidSURLException { - return resolveStoRIbySURL(surl, vfsApproachable); + return resolveStoRI(surl, user); } - private StoRI resolveStoRIbySURL(TSURL surl, - List vfsApproachable) throws UnapprochableSurlException, InvalidSURLException, NamespaceException { + private StoRI resolveStoRI(TSURL surl, GridUserInterface user) + throws IllegalArgumentException, UnapprochableSurlException, + NamespaceException, InvalidSURLException { - MappingRule winnerRule = getWinnerRule(surl); - log.debug(String.format("For SURL %s the winner Rule is %s", surl, - winnerRule.getRuleName())); - - StoRI stori = winnerRule.getMappedFS().createFile( - NamespaceUtil.extractRelativePath(winnerRule.getStFNRoot(), surl.sfn() - .stfn().toString()), StoRIType.FILE); + if (surl == null) { + log.error("resolveStoRIbySURL: invalid null surl"); + throw new IllegalArgumentException( + "resolveStoRIbySURL: invalid null surl"); + } - stori.setStFNRoot(winnerRule.getStFNRoot()); - stori.setMappingRule(winnerRule); + List vfsApproachable = null; + if (user != null) { + // get the user approachable VFSs + vfsApproachable = getApproachableVFS(user); + if (vfsApproachable.isEmpty()) { + String errorMsg = String + .format("User %s can't approach any VFS!", user); + log.debug(errorMsg); + throw new UnapprochableSurlException(errorMsg); + } + } else { + // get all the approachable VFSs + vfsApproachable = new ArrayList(getAllDefinedVFS()); + } + // get the winner rule for SURL + MappingRule winnerRule = getWinnerRule(surl, vfsApproachable); + if (winnerRule == null) { + if (user == null) { + // there's no VFS where the surl can be mapped + String msg = String.format("No mapping rule found for surl='%s'", surl); + log.debug(msg); + throw new InvalidSURLException(surl, msg); + } + // user's VFSs can't map the surl + String msg = String.format( + "No mapping rule found for surl='%s' and user ='%s'", surl, user); + log.debug(msg); + if (getWinnerRule(surl) == null) { + // invalid surl + throw new InvalidSURLException(surl, msg); + } + throw new UnapprochableSurlException(msg); + } + log.debug(String.format( + "For surl='%s' and vfsApproachable=[%s] the winner Rule is %s", surl, + vfsApproachable, winnerRule.getRuleName())); + // create StoRI + String stfnPath = surl.sfn().stfn().toString(); + String relativePath = NamespaceUtil.extractRelativePath( + winnerRule.getStFNRoot(), stfnPath); + StoRI stori = winnerRule.getMappedFS().createFile(relativePath, + StoRIType.FILE); + stori.setStFNRoot(winnerRule.getStFNRoot()); + stori.setMappingRule(winnerRule); + // check if StoRI real path is enclosed into the mapped VFS String realPath = null; try { realPath = stori.getLocalFile().getCanonicalPath(); } catch (IOException e) { - log.error("Error resolving stori for surl {}: {}.", surl, e.getMessage(), - e); + log.error("Error on reading the canonical path: " + e.getMessage()); throw new NamespaceException(e.getMessage()); } - if (realPath.startsWith(winnerRule.getMappedFS().getRootPath())) { - if (vfsApproachable.contains(winnerRule.getMappedFS())) { - log.debug(String.format("Resource '%s' belongs to '%s'", realPath, - winnerRule.getMappedFS().getAliasName())); - return stori; - } - String msg = String.format( - "VFS '%s' is not on the approachable VFS list!", winnerRule - .getMappedFS().getAliasName()); - log.debug(msg); - throw new UnapprochableSurlException(msg); + log.debug(String.format("Resource '%s' belongs to '%s'", realPath, + winnerRule.getMappedFS().getAliasName())); + return stori; } - - String msg = String.format("Resource '%s' doesn't belong to %s", realPath, - winnerRule.getMappedFS().getAliasName()); - log.debug(msg); + log.debug(String.format("Resource '%s' doesn't belong to %s", realPath, + winnerRule.getMappedFS().getAliasName())); + /* get the VFS where the resource is phisically located, if exists */ VirtualFSInterface redirectedVFS = getWinnerVFS(realPath); - log.debug(String.format("Surl %s is a symbolic link to %s", surl, + if (redirectedVFS == null) { + log.debug(String.format("Unable to find a valid VFS from path '%s'", + realPath)); + throw new InvalidSURLException(surl, + "The requested SURL is not managed by this instance of StoRM"); + } + log.debug(String.format("%s belongs to %s", realPath, redirectedVFS.getAliasName())); - if (vfsApproachable.contains(redirectedVFS)) { - log.debug(String.format("%s is approachable", - redirectedVFS.getAliasName())); - MappingRule rule = redirectedVFS.getMappingRules().get(0); - stori = redirectedVFS.createFile(NamespaceUtil.extractRelativePath( - redirectedVFS.getRootPath(), realPath), StoRIType.FILE); - - stori.setStFNRoot(rule.getStFNRoot()); - stori.setMappingRule(rule); - return stori; + if (user != null && !vfsApproachable.contains(redirectedVFS)) { + String msg = String.format("%s is not approachable by the user", + redirectedVFS.getAliasName()); + log.debug(msg); + throw new UnapprochableSurlException(msg); } - throw new UnapprochableSurlException(String.format( - "%s is not approachable", redirectedVFS.getAliasName())); - } + log.debug(String.format("%s is approachable by the user", + redirectedVFS.getAliasName())); + MappingRule rule = redirectedVFS.getMappingRules().get(0); + relativePath = NamespaceUtil.extractRelativePath(rule.getStFNRoot(), + stfnPath); + stori = rule.getMappedFS().createFile(relativePath, StoRIType.FILE); + stori.setStFNRoot(rule.getStFNRoot()); + stori.setMappingRule(rule); + return stori; + } + public VirtualFSInterface resolveVFSbySURL(TSURL surl, GridUserInterface user) throws UnapprochableSurlException, IllegalArgumentException, InvalidSURLException, NamespaceException { @@ -459,13 +481,26 @@ public Space retrieveSpaceByToken(TSizeInBytes totSize, TSpaceToken token) { /*********************************************** * UTILITY METHODS **********************************************/ + + /** + * + * @param surl + * @param vfsApproachable + * @return the mapped rule or null if not found + * @throws IllegalArgumentException + * @throws InvalidSURLException + * @throws UnapprochableSurlException + * @throws NamespaceException + */ + private MappingRule getWinnerRule(TSURL surl, + List vfsApproachable) throws IllegalArgumentException, + InvalidSURLException, UnapprochableSurlException, NamespaceException { - private MappingRule getWinnerRule(TSURL surl) - throws IllegalArgumentException, InvalidSURLException, - UnapprochableSurlException, NamespaceException { - - if (surl == null) { - String errorMsg = "Unable to perform getWinnerRule, invalid argument stfnPath"; + if (surl == null || vfsApproachable == null || vfsApproachable.isEmpty()) { + String errorMsg = String + .format( + "Unable to perform getWinnerRule, invalid argument(s): surl=%s, vfs=%s", + surl, vfsApproachable); log.error(errorMsg); throw new IllegalArgumentException(errorMsg); } @@ -484,7 +519,8 @@ private MappingRule getWinnerRule(TSURL surl) MappingRule winnerRule = null; int minDistance = Integer.MAX_VALUE; for (MappingRule rule : rules) { - if (NamespaceUtil.isEnclosed(rule.getStFNRoot(), stfnPath)) { + if (NamespaceUtil.isEnclosed(rule.getStFNRoot(), stfnPath) + && vfsApproachable.contains(rule.getMappedFS())) { int distance = NamespaceUtil.computeDistanceFromPath(rule.getStFNRoot(), stfnPath); if (distance < minDistance) { minDistance = distance; @@ -492,35 +528,16 @@ private MappingRule getWinnerRule(TSURL surl) } } } - if (winnerRule == null) { - String errorMsg = "No mapping rules defined for stfnPath=" + stfnPath; - log.error(errorMsg); - throw new InvalidSURLException(surl, errorMsg); - } return winnerRule; } - - private MappingRule getWinnerRule(TSURL surl, - List vfsApproachable) throws IllegalArgumentException, - InvalidSURLException, UnapprochableSurlException, NamespaceException { - if (vfsApproachable == null || vfsApproachable.isEmpty()) { - String errorMsg = "Unable to perform getWinnerRule, invalid argument vfsApproachable"; - log.error(errorMsg); - throw new IllegalArgumentException(errorMsg); - } - - MappingRule winnerRule = getWinnerRule(surl); - - if (vfsApproachable.contains(winnerRule.getMappedFS())) { - return winnerRule; - } + private MappingRule getWinnerRule(TSURL surl) throws IllegalArgumentException, + InvalidSURLException, UnapprochableSurlException, NamespaceException { - String errorMsg = String.format("Surl %s is not approachable by the user", surl); - log.error(errorMsg); - throw new UnapprochableSurlException(errorMsg); + List allVFSs = new ArrayList(getAllDefinedVFS()); + return getWinnerRule(surl, allVFSs); } - + @SuppressWarnings("unchecked") public VirtualFSInterface getWinnerVFS(String absolutePath) throws NamespaceException { From 902a4187afd56e5c8403e3b47d403bd48b2a9536 Mon Sep 17 00:00:00 2001 From: enricovianello Date: Thu, 23 Jan 2014 18:26:47 +0100 Subject: [PATCH 09/45] Fixed Namespace StoRI resolution alghoritm --- .../it/grid/storm/namespace/Namespace.java | 159 ++++++++++++------ .../storm/namespace/NamespaceInterface.java | 27 +++ 2 files changed, 133 insertions(+), 53 deletions(-) diff --git a/src/main/java/it/grid/storm/namespace/Namespace.java b/src/main/java/it/grid/storm/namespace/Namespace.java index 673b7c85..69ae8d77 100644 --- a/src/main/java/it/grid/storm/namespace/Namespace.java +++ b/src/main/java/it/grid/storm/namespace/Namespace.java @@ -114,6 +114,57 @@ public List getApproachableVFS(GridUserInterface user) { return approachVFS; } + @Override + public List getApproachableByAnonymousVFS() + throws NamespaceException { + + LinkedList anonymousVFS = new LinkedList(); + LinkedList allVFS = new LinkedList( + getAllDefinedVFS()); + + for (VirtualFSInterface vfs : allVFS) { + if (vfs.isApproachableByAnonymous()) { + anonymousVFS.add(vfs); + } + } + + return anonymousVFS; + } + + @Override + public List getReadableByAnonymousVFS() + throws NamespaceException { + + LinkedList readableVFS = new LinkedList(); + LinkedList allVFS = new LinkedList( + getAllDefinedVFS()); + + for (VirtualFSInterface vfs : allVFS) { + if (vfs.isHttpWorldReadable()) { + readableVFS.add(vfs); + } + } + + return readableVFS; + } + + @Override + public List getReadableOrApproachableByAnonymousVFS() + throws NamespaceException { + + LinkedList rowVFS = new LinkedList(); + LinkedList allVFS = new LinkedList( + getAllDefinedVFS()); + + for (VirtualFSInterface vfs : allVFS) { + if (vfs.isHttpWorldReadable() || vfs.isApproachableByAnonymous()) { + rowVFS.add(vfs); + } + } + + return rowVFS; + } + public VirtualFSInterface getDefaultVFS(GridUserInterface user) throws NamespaceException { @@ -184,58 +235,65 @@ private StoRI resolveStoRI(TSURL surl, GridUserInterface user) throws IllegalArgumentException, UnapprochableSurlException, NamespaceException, InvalidSURLException { + StoRI stori = null; + + /* check surl */ if (surl == null) { - log.error("resolveStoRIbySURL: invalid null surl"); - throw new IllegalArgumentException( - "resolveStoRIbySURL: invalid null surl"); + String msg = "resolveStoRIbySURL: invalid null surl"; + log.error(msg); + throw new IllegalArgumentException(msg); } List vfsApproachable = null; if (user != null) { - // get the user approachable VFSs + // get the grid user approachable VFSs vfsApproachable = getApproachableVFS(user); - if (vfsApproachable.isEmpty()) { - String errorMsg = String - .format("User %s can't approach any VFS!", user); - log.debug(errorMsg); - throw new UnapprochableSurlException(errorMsg); - } } else { - // get all the approachable VFSs - vfsApproachable = new ArrayList(getAllDefinedVFS()); + // get all the R or RW by anonymous VFSs + vfsApproachable = getReadableOrApproachableByAnonymousVFS(); + } + + //check vfsApproachable + if (vfsApproachable.isEmpty()) { + String errorMsg = "No approachable VFS found for user!"; + log.debug(errorMsg); + throw new UnapprochableSurlException(errorMsg); } // get the winner rule for SURL MappingRule winnerRule = getWinnerRule(surl, vfsApproachable); + if (winnerRule == null) { - if (user == null) { - // there's no VFS where the surl can be mapped - String msg = String.format("No mapping rule found for surl='%s'", surl); + /* is this surl invalid for this instance of StoRM? */ + if (getWinnerRule(surl, new ArrayList(getAllDefinedVFS())) == null) { + String msg = "The requested SURL is not managed by this instance of StoRM"; log.debug(msg); throw new InvalidSURLException(surl, msg); } - // user's VFSs can't map the surl - String msg = String.format( - "No mapping rule found for surl='%s' and user ='%s'", surl, user); - log.debug(msg); - if (getWinnerRule(surl) == null) { - // invalid surl - throw new InvalidSURLException(surl, msg); + + String msg = null; + if (user != null) { + msg = String.format("No mapping rule found for surl='%s' and user '%s'", surl, user); + } else { + msg = String.format("No mapping rule found for surl='%s'", surl); } + log.debug(msg); throw new UnapprochableSurlException(msg); } - log.debug(String.format( - "For surl='%s' and vfsApproachable=[%s] the winner Rule is %s", surl, - vfsApproachable, winnerRule.getRuleName())); + + log.debug("The winner Rule is %s", winnerRule.getRuleName()); + // create StoRI String stfnPath = surl.sfn().stfn().toString(); - String relativePath = NamespaceUtil.extractRelativePath( + + String relPath = NamespaceUtil.extractRelativePath( winnerRule.getStFNRoot(), stfnPath); - StoRI stori = winnerRule.getMappedFS().createFile(relativePath, - StoRIType.FILE); + + stori = winnerRule.getMappedFS().createFile(relPath, StoRIType.FILE); stori.setStFNRoot(winnerRule.getStFNRoot()); stori.setMappingRule(winnerRule); - // check if StoRI real path is enclosed into the mapped VFS + + // verify if StoRI real resource is enclosed into the winner VFS String realPath = null; try { realPath = stori.getLocalFile().getCanonicalPath(); @@ -243,38 +301,40 @@ private StoRI resolveStoRI(TSURL surl, GridUserInterface user) log.error("Error on reading the canonical path: " + e.getMessage()); throw new NamespaceException(e.getMessage()); } + if (realPath.startsWith(winnerRule.getMappedFS().getRootPath())) { log.debug(String.format("Resource '%s' belongs to '%s'", realPath, winnerRule.getMappedFS().getAliasName())); return stori; } - log.debug(String.format("Resource '%s' doesn't belong to %s", realPath, - winnerRule.getMappedFS().getAliasName())); + + log.debug("Resource '{}' doesn't belong to {}", realPath, winnerRule + .getMappedFS().getAliasName()); + /* get the VFS where the resource is phisically located, if exists */ - VirtualFSInterface redirectedVFS = getWinnerVFS(realPath); - if (redirectedVFS == null) { - log.debug(String.format("Unable to find a valid VFS from path '%s'", - realPath)); + VirtualFSInterface targetVFS = getWinnerVFS(realPath); + + if (targetVFS == null) { + log.debug("Unable to find a valid VFS from path '{}'", realPath); throw new InvalidSURLException(surl, "The requested SURL is not managed by this instance of StoRM"); } - log.debug(String.format("%s belongs to %s", realPath, - redirectedVFS.getAliasName())); - if (user != null && !vfsApproachable.contains(redirectedVFS)) { + + log.debug("{} belongs to {}", realPath, targetVFS.getAliasName()); + + if (!vfsApproachable.contains(targetVFS)) { String msg = String.format("%s is not approachable by the user", - redirectedVFS.getAliasName()); + targetVFS.getAliasName()); log.debug(msg); throw new UnapprochableSurlException(msg); } - log.debug(String.format("%s is approachable by the user", - redirectedVFS.getAliasName())); - MappingRule rule = redirectedVFS.getMappingRules().get(0); - relativePath = NamespaceUtil.extractRelativePath(rule.getStFNRoot(), + log.debug("{} is approachable by the user", targetVFS.getAliasName()); + relPath = NamespaceUtil.extractRelativePath(winnerRule.getStFNRoot(), stfnPath); - stori = rule.getMappedFS().createFile(relativePath, StoRIType.FILE); - stori.setStFNRoot(rule.getStFNRoot()); - stori.setMappingRule(rule); + stori = targetVFS.createFile(relPath, StoRIType.FILE); + stori.setStFNRoot(winnerRule.getStFNRoot()); + stori.setMappingRule(winnerRule); return stori; } @@ -531,13 +591,6 @@ private MappingRule getWinnerRule(TSURL surl, return winnerRule; } - private MappingRule getWinnerRule(TSURL surl) throws IllegalArgumentException, - InvalidSURLException, UnapprochableSurlException, NamespaceException { - - List allVFSs = new ArrayList(getAllDefinedVFS()); - return getWinnerRule(surl, allVFSs); - } - @SuppressWarnings("unchecked") public VirtualFSInterface getWinnerVFS(String absolutePath) throws NamespaceException { diff --git a/src/main/java/it/grid/storm/namespace/NamespaceInterface.java b/src/main/java/it/grid/storm/namespace/NamespaceInterface.java index 4e0ea168..1869a85e 100644 --- a/src/main/java/it/grid/storm/namespace/NamespaceInterface.java +++ b/src/main/java/it/grid/storm/namespace/NamespaceInterface.java @@ -99,6 +99,33 @@ public Collection getAllDefinedVFS() public List getApproachableVFS(GridUserInterface user) throws NamespaceException; + /** + * + * @return List : Return a List of readable and writable by anonymous users + * VirtualFS instances + * @throws NamespaceException + */ + public List getApproachableByAnonymousVFS() + throws NamespaceException; + + /** + * + * @return List : Return a List of readable by anonymous users + * VirtualFS instances + * @throws NamespaceException + */ + public List getReadableByAnonymousVFS() + throws NamespaceException; + + /** + * + * @return List : Return a List of readable or writable by anonymous users + * VirtualFS instances + * @throws NamespaceException + */ + public List getReadableOrApproachableByAnonymousVFS() + throws NamespaceException; + /** * * @param user From 65157818217d732da4121f1e550c88ba9cd01982 Mon Sep 17 00:00:00 2001 From: enricovianello Date: Thu, 23 Jan 2014 18:26:59 +0100 Subject: [PATCH 10/45] Fixed typo --- .../grid/storm/authz/remote/resource/PermissionEvaluator.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/it/grid/storm/authz/remote/resource/PermissionEvaluator.java b/src/main/java/it/grid/storm/authz/remote/resource/PermissionEvaluator.java index 80fff4f1..f08a3cfa 100644 --- a/src/main/java/it/grid/storm/authz/remote/resource/PermissionEvaluator.java +++ b/src/main/java/it/grid/storm/authz/remote/resource/PermissionEvaluator.java @@ -161,7 +161,7 @@ static Boolean evaluateAnonymousPermission(String filePathDecoded, if (!fileVFS.getCapabilities().getAllManagedProtocols() .contains(Protocol.HTTP)) { log.debug("The requeste Storage Area \'" + fileVFS.getAliasName() - + "\' is not appoachable via HTTPS"); + + "\' is not approachable via HTTPS"); return Boolean.FALSE; } log.info("Authorization decision for Anonymous user requesting " + request @@ -189,7 +189,7 @@ static Boolean evaluateAnonymousPermission(String filePathDecoded, if (!fileVFS.isApproachableByAnonymous() && !(request.isReadOnly() && fileVFS.isHttpWorldReadable())) { log.debug("The requeste Storage Area \'" + fileVFS.getAliasName() - + "\' is not appoachable by anonymous users"); + + "\' is not approachable by anonymous users"); return new Boolean(false); } StFN fileStFN = buildStFN(filePathDecoded, fileVFS); From 57e3f4ff54bb1e0c8621c196da4869a11656615a Mon Sep 17 00:00:00 2001 From: enricovianello Date: Fri, 24 Jan 2014 14:14:40 +0100 Subject: [PATCH 11/45] Fixed SRM_INVALID_PATH returned if surl is unsolvable --- .../it/grid/storm/namespace/Namespace.java | 210 ++++++++++-------- .../config/xml/XMLNamespaceParser.java | 1 - 2 files changed, 120 insertions(+), 91 deletions(-) diff --git a/src/main/java/it/grid/storm/namespace/Namespace.java b/src/main/java/it/grid/storm/namespace/Namespace.java index 69ae8d77..e8831485 100644 --- a/src/main/java/it/grid/storm/namespace/Namespace.java +++ b/src/main/java/it/grid/storm/namespace/Namespace.java @@ -172,36 +172,31 @@ public VirtualFSInterface getDefaultVFS(GridUserInterface user) getApproachableRules(user)); if (appRules.isEmpty()) { if (user instanceof AbstractGridUser) { - log.error("No approachable rules found for user with DN='" - + user.getDn() + "' and VO = '" + ((AbstractGridUser) user).getVO() - + "'"); - throw new NamespaceException( - "No approachable rules found for user with DN='" + user.getDn() - + "' and VO = '" + ((AbstractGridUser) user).getVO() + "'"); + String msg = String.format( + "No approachable rules found for user with DN='%s' and VO = '%s'", + user.getDn(), ((AbstractGridUser) user).getVO()); + log.error(msg); + throw new NamespaceException(msg); } else { - log.error("No approachable rules found for user with DN='" - + user.getDn() + "' User certificate has not VOMS extension"); - throw new NamespaceException( - "No approachable rules found for user with DN='" + user.getDn() - + "' User certificate has not VOMS extension"); + String msg = String.format("No approachable rules found for user with " + + "DN='%s' User certificate has not VOMS extension", user.getDn()); + log.error(msg); + throw new NamespaceException(msg); } } - log.debug("Compatible Approachable rules : " + appRules); + log.debug("Compatible Approachable rules : {}", appRules); ApproachableRule firstAppRule = appRules.first(); - log.debug("Default APP_RULE is the first (in respsect of name): " - + firstAppRule); + log.debug("Default APP_RULE is the first: {}", firstAppRule); - // Retrieve default VFS for the first Approachable Rule compatible for the - // user. VirtualFSInterface vfs = getApproachableDefaultVFS(firstAppRule); - log.debug("Default VFS for Space Files : " + vfs); + log.debug("Default VFS for Space Files : {}", vfs); return vfs; - } - public boolean isApproachable(StoRI storageResource, - GridUserInterface gridUser) throws NamespaceException { - return getApproachableVFS(gridUser).contains(storageResource.getVirtualFileSystem()); + public boolean isApproachable(StoRI stori, GridUserInterface user) + throws NamespaceException { + + return getApproachableVFS(user).contains(stori.getVirtualFileSystem()); } /** @@ -221,6 +216,13 @@ public boolean isApproachable(StoRI storageResource, public StoRI resolveStoRIbySURL(TSURL surl) throws IllegalArgumentException, UnapprochableSurlException, NamespaceException, InvalidSURLException { + /* check surl */ + if (surl == null) { + String msg = "resolveStoRIbySURL: invalid null surl"; + log.error(msg); + throw new IllegalArgumentException(msg); + } + return resolveStoRI(surl, null); } @@ -228,100 +230,79 @@ public StoRI resolveStoRIbySURL(TSURL surl, GridUserInterface user) throws IllegalArgumentException, UnapprochableSurlException, NamespaceException, InvalidSURLException { - return resolveStoRI(surl, user); - } - - private StoRI resolveStoRI(TSURL surl, GridUserInterface user) - throws IllegalArgumentException, UnapprochableSurlException, - NamespaceException, InvalidSURLException { - - StoRI stori = null; - /* check surl */ if (surl == null) { String msg = "resolveStoRIbySURL: invalid null surl"; log.error(msg); throw new IllegalArgumentException(msg); } + + return resolveStoRI(surl, user); + } + + private StoRI resolveStoRI(TSURL surl, GridUserInterface user) + throws IllegalArgumentException, UnapprochableSurlException, + NamespaceException, InvalidSURLException { + StoRI stori = null; List vfsApproachable = null; - if (user != null) { - // get the grid user approachable VFSs - vfsApproachable = getApproachableVFS(user); + + /* 1. compute user's approachable VFS: */ + if (isAnonymous(user)) { + vfsApproachable = new ArrayList(getAllDefinedVFS()); } else { - // get all the R or RW by anonymous VFSs - vfsApproachable = getReadableOrApproachableByAnonymousVFS(); + vfsApproachable = getApproachableVFS(user); } - //check vfsApproachable if (vfsApproachable.isEmpty()) { String errorMsg = "No approachable VFS found for user!"; log.debug(errorMsg); throw new UnapprochableSurlException(errorMsg); } - // get the winner rule for SURL + /* get the winner rule for SURL */ MappingRule winnerRule = getWinnerRule(surl, vfsApproachable); if (winnerRule == null) { - /* is this surl invalid for this instance of StoRM? */ - if (getWinnerRule(surl, new ArrayList(getAllDefinedVFS())) == null) { - String msg = "The requested SURL is not managed by this instance of StoRM"; - log.debug(msg); - throw new InvalidSURLException(surl, msg); - } - - String msg = null; - if (user != null) { - msg = String.format("No mapping rule found for surl='%s' and user '%s'", surl, user); - } else { - msg = String.format("No mapping rule found for surl='%s'", surl); + /* check if surl can be resolved by this instance of StoRM */ + if (!isAnonymous(user) && isSolvable(surl)) { + log.debug("No mapping rule found for surl='{}' and user '{}'", surl, + user); + throw new UnapprochableSurlException("User '" + user + "' is not " + + "authorized to access '" + surl + "'"); } + /* this surl is invalid for this instance of StoRM? */ + String msg = "The requested SURL is not managed by this instance of StoRM"; log.debug(msg); - throw new UnapprochableSurlException(msg); + throw new InvalidSURLException(surl, msg); } - log.debug("The winner Rule is %s", winnerRule.getRuleName()); + log.debug("The winner rule is {}", winnerRule.getRuleName()); // create StoRI - String stfnPath = surl.sfn().stfn().toString(); - - String relPath = NamespaceUtil.extractRelativePath( - winnerRule.getStFNRoot(), stfnPath); - - stori = winnerRule.getMappedFS().createFile(relPath, StoRIType.FILE); - stori.setStFNRoot(winnerRule.getStFNRoot()); - stori.setMappingRule(winnerRule); + stori = buildStoRI(winnerRule.getMappedFS(), winnerRule, surl); - // verify if StoRI real resource is enclosed into the winner VFS - String realPath = null; - try { - realPath = stori.getLocalFile().getCanonicalPath(); - } catch (IOException e) { - log.error("Error on reading the canonical path: " + e.getMessage()); - throw new NamespaceException(e.getMessage()); - } - - if (realPath.startsWith(winnerRule.getMappedFS().getRootPath())) { - log.debug(String.format("Resource '%s' belongs to '%s'", realPath, - winnerRule.getMappedFS().getAliasName())); + // verify if StoRI canonical path is enclosed into the winner VFS + if (isStoRIEnclosed(stori, winnerRule.getMappedFS())) { + log.debug("Resource '{}' belongs to '{}'", stori.getLocalFile(), + winnerRule.getMappedFS().getAliasName()); return stori; } - log.debug("Resource '{}' doesn't belong to {}", realPath, winnerRule - .getMappedFS().getAliasName()); + log.debug("Resource '{}' doesn't belong to {}", stori.getLocalFile(), + winnerRule.getMappedFS().getAliasName()); /* get the VFS where the resource is phisically located, if exists */ + String realPath = getStoRICanonicalPath(stori); VirtualFSInterface targetVFS = getWinnerVFS(realPath); - if (targetVFS == null) { log.debug("Unable to find a valid VFS from path '{}'", realPath); throw new InvalidSURLException(surl, "The requested SURL is not managed by this instance of StoRM"); } - log.debug("{} belongs to {}", realPath, targetVFS.getAliasName()); + /* check if target VFS is approachable */ if (!vfsApproachable.contains(targetVFS)) { String msg = String.format("%s is not approachable by the user", targetVFS.getAliasName()); @@ -330,14 +311,51 @@ private StoRI resolveStoRI(TSURL surl, GridUserInterface user) } log.debug("{} is approachable by the user", targetVFS.getAliasName()); - relPath = NamespaceUtil.extractRelativePath(winnerRule.getStFNRoot(), - stfnPath); - stori = targetVFS.createFile(relPath, StoRIType.FILE); - stori.setStFNRoot(winnerRule.getStFNRoot()); - stori.setMappingRule(winnerRule); - return stori; + return buildStoRI(targetVFS, winnerRule, surl); } - + + private boolean isSolvable(TSURL surl) throws IllegalArgumentException, + InvalidSURLException, UnapprochableSurlException, NamespaceException { + + return getWinnerRule(surl) != null; + } + + private String getStoRICanonicalPath(StoRI stori) + throws NamespaceException { + + String realPath = null; + try { + realPath = stori.getLocalFile().getCanonicalPath(); + } catch (IOException e) { + log.error("Error on reading the canonical path: " + e.getMessage()); + throw new NamespaceException(e.getMessage()); + } + return realPath; + } + + private boolean isStoRIEnclosed(StoRI stori, VirtualFSInterface vfs) + throws NamespaceException { + + return getStoRICanonicalPath(stori).startsWith(vfs.getRootPath()); + } + + private StoRI buildStoRI(VirtualFSInterface vfs, MappingRule mappingRule, + TSURL surl) { + + String stfnPath = surl.sfn().stfn().toString(); + String relativePath = NamespaceUtil.extractRelativePath( + mappingRule.getStFNRoot(), stfnPath); + StoRI stori = vfs.createFile(relativePath, StoRIType.FILE); + stori.setStFNRoot(mappingRule.getStFNRoot()); + stori.setMappingRule(mappingRule); + return stori; + } + + private boolean isAnonymous(GridUserInterface user) { + + return user == null; + } + public VirtualFSInterface resolveVFSbySURL(TSURL surl, GridUserInterface user) throws UnapprochableSurlException, IllegalArgumentException, InvalidSURLException, NamespaceException { @@ -371,8 +389,8 @@ public StoRI resolveStoRIbyAbsolutePath(String absolutePath) throws NamespaceException { VirtualFSInterface vfs = resolveVFSbyAbsolutePath(absolutePath); - log.debug("VFS retrivied is " + vfs.getAliasName()); - log.debug("VFS instance is " + vfs.hashCode()); + log.debug("VFS retrivied is {}", vfs.getAliasName()); + log.debug("VFS instance is {}", vfs.hashCode()); String relativePath = NamespaceUtil.extractRelativePath(vfs.getRootPath(), absolutePath); StoRI stori = vfs.createFile(relativePath); @@ -556,15 +574,18 @@ private MappingRule getWinnerRule(TSURL surl, List vfsApproachable) throws IllegalArgumentException, InvalidSURLException, UnapprochableSurlException, NamespaceException { - if (surl == null || vfsApproachable == null || vfsApproachable.isEmpty()) { - String errorMsg = String - .format( - "Unable to perform getWinnerRule, invalid argument(s): surl=%s, vfs=%s", - surl, vfsApproachable); + if (surl == null || vfsApproachable == null) { + String errorMsg = String.format("Unable to perform getWinnerRule, " + + "invalid argument(s): surl=%s, vfs=%s", surl, vfsApproachable); log.error(errorMsg); throw new IllegalArgumentException(errorMsg); } + if (vfsApproachable.isEmpty()) { + log.debug("Empty VFS list!"); + return null; + } + Vector rules = new Vector(parser .getMappingRules().values()); @@ -581,7 +602,8 @@ private MappingRule getWinnerRule(TSURL surl, for (MappingRule rule : rules) { if (NamespaceUtil.isEnclosed(rule.getStFNRoot(), stfnPath) && vfsApproachable.contains(rule.getMappedFS())) { - int distance = NamespaceUtil.computeDistanceFromPath(rule.getStFNRoot(), stfnPath); + int distance = NamespaceUtil.computeDistanceFromPath( + rule.getStFNRoot(), stfnPath); if (distance < minDistance) { minDistance = distance; winnerRule = rule; @@ -590,6 +612,14 @@ private MappingRule getWinnerRule(TSURL surl, } return winnerRule; } + + private MappingRule getWinnerRule(TSURL surl) + throws IllegalArgumentException, InvalidSURLException, + UnapprochableSurlException, NamespaceException { + + return getWinnerRule(surl, new ArrayList( + getAllDefinedVFS())); + } @SuppressWarnings("unchecked") public VirtualFSInterface getWinnerVFS(String absolutePath) diff --git a/src/main/java/it/grid/storm/namespace/config/xml/XMLNamespaceParser.java b/src/main/java/it/grid/storm/namespace/config/xml/XMLNamespaceParser.java index aaabf07c..be4ddf66 100644 --- a/src/main/java/it/grid/storm/namespace/config/xml/XMLNamespaceParser.java +++ b/src/main/java/it/grid/storm/namespace/config/xml/XMLNamespaceParser.java @@ -49,7 +49,6 @@ import it.grid.storm.namespace.model.VirtualFS; import it.grid.storm.space.SpaceHelper; import it.grid.storm.space.gpfsquota.GPFSFilesetQuotaInfo; -import it.grid.storm.space.gpfsquota.GPFSQuotaInfo; import it.grid.storm.space.gpfsquota.GetGPFSFilesetQuotaInfoCommand; import it.grid.storm.srm.types.TSizeInBytes; import it.grid.storm.srm.types.TSpaceToken; From 2bbdd859710fc0dea442c433a88cd0e116db3930 Mon Sep 17 00:00:00 2001 From: enricovianello Date: Wed, 29 Jan 2014 16:35:31 +0100 Subject: [PATCH 12/45] Improved log verbosity in case of a malformed log configuration file --- src/main/java/it/grid/storm/startup/Bootstrap.java | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/it/grid/storm/startup/Bootstrap.java b/src/main/java/it/grid/storm/startup/Bootstrap.java index a2728d26..a03319c4 100644 --- a/src/main/java/it/grid/storm/startup/Bootstrap.java +++ b/src/main/java/it/grid/storm/startup/Bootstrap.java @@ -55,8 +55,11 @@ public static void configureLogging(String loggingConfigFilePath) { String message = String.format("Error loading logging configuration: " + "'%s' does not exist or is not readable.",loggingConfigFilePath); + + log.error(message); + throw new RuntimeException(message); - } + } LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory(); JoranConfigurator configurator = new JoranConfigurator(); @@ -69,11 +72,15 @@ public static void configureLogging(String loggingConfigFilePath) { } catch (JoranException e) { + System.err.println(e + "\n" + e.getCause()); + throw new RuntimeException(e); - } + } finally { + + StatusPrinter.printInCaseOfErrorsOrWarnings(lc); - StatusPrinter.printInCaseOfErrorsOrWarnings(lc); + } } public static void initializePathAuthz(String pathAuthzDBFileName) From 9bdc41bc85136c76f0bcccd8eb4a820b0dc58128 Mon Sep 17 00:00:00 2001 From: enricovianello Date: Wed, 29 Jan 2014 16:40:20 +0100 Subject: [PATCH 13/45] Removed useless log message --- src/main/java/it/grid/storm/startup/Bootstrap.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/it/grid/storm/startup/Bootstrap.java b/src/main/java/it/grid/storm/startup/Bootstrap.java index a03319c4..2b0bc982 100644 --- a/src/main/java/it/grid/storm/startup/Bootstrap.java +++ b/src/main/java/it/grid/storm/startup/Bootstrap.java @@ -72,8 +72,6 @@ public static void configureLogging(String loggingConfigFilePath) { } catch (JoranException e) { - System.err.println(e + "\n" + e.getCause()); - throw new RuntimeException(e); } finally { From e0bdebd067af9c5c8bd6775e83465d5f8a9a3729 Mon Sep 17 00:00:00 2001 From: enricovianello Date: Thu, 30 Jan 2014 16:14:51 +0100 Subject: [PATCH 14/45] Fixed symbolic-link case in StoRI resolution algorithm - anonymous users = not allowed sym links - auth users = verify target vfs permissions (source vfs must be approachable) --- src/main/java/it/grid/storm/namespace/Namespace.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/it/grid/storm/namespace/Namespace.java b/src/main/java/it/grid/storm/namespace/Namespace.java index e8831485..274a3be8 100644 --- a/src/main/java/it/grid/storm/namespace/Namespace.java +++ b/src/main/java/it/grid/storm/namespace/Namespace.java @@ -265,7 +265,7 @@ private StoRI resolveStoRI(TSURL surl, GridUserInterface user) if (winnerRule == null) { /* check if surl can be resolved by this instance of StoRM */ - if (!isAnonymous(user) && isSolvable(surl)) { + if (isSolvable(surl)) { log.debug("No mapping rule found for surl='{}' and user '{}'", surl, user); throw new UnapprochableSurlException("User '" + user + "' is not " @@ -292,6 +292,11 @@ private StoRI resolveStoRI(TSURL surl, GridUserInterface user) log.debug("Resource '{}' doesn't belong to {}", stori.getLocalFile(), winnerRule.getMappedFS().getAliasName()); + if (isAnonymous(user)) { + throw new UnapprochableSurlException(stori.getLocalFile() + + " is not approachable by anonymous users!"); + } + /* get the VFS where the resource is phisically located, if exists */ String realPath = getStoRICanonicalPath(stori); VirtualFSInterface targetVFS = getWinnerVFS(realPath); @@ -311,7 +316,7 @@ private StoRI resolveStoRI(TSURL surl, GridUserInterface user) } log.debug("{} is approachable by the user", targetVFS.getAliasName()); - return buildStoRI(targetVFS, winnerRule, surl); + return stori; } private boolean isSolvable(TSURL surl) throws IllegalArgumentException, From 34aa813d4fe9d1b9eec1ca4c12c7d17c834a6168 Mon Sep 17 00:00:00 2001 From: enricovianello Date: Mon, 3 Feb 2014 11:39:13 +0100 Subject: [PATCH 15/45] Proper use of string formatting in log calls - package it.grid.storm --- src/main/java/it/grid/storm/Constants.java | 14 ++-- src/main/java/it/grid/storm/StoRM.java | 20 +++--- .../it/grid/storm/StoRMCommandServer.java | 70 ++++++++++++------- 3 files changed, 59 insertions(+), 45 deletions(-) diff --git a/src/main/java/it/grid/storm/Constants.java b/src/main/java/it/grid/storm/Constants.java index 8f80a82c..6f013641 100644 --- a/src/main/java/it/grid/storm/Constants.java +++ b/src/main/java/it/grid/storm/Constants.java @@ -61,24 +61,22 @@ private static String getDistribution() { + "issue"; File issueFile = new File(issuePath); if (!issueFile.exists() || !issueFile.isFile() || !issueFile.canRead()) { - log.warn("Unable to read " + issueFile.getAbsolutePath() + " file!!"); + log.warn("Unable to read {} file!!", issueFile.getAbsolutePath()); } else { try { BufferedReader issueReader = new BufferedReader(new FileReader( issueFile)); String output = issueReader.readLine(); if (output == null) { - log.warn("The file " + issueFile.getAbsolutePath() + " is empty!"); + log.warn("The file {} is empty!", issueFile.getAbsolutePath()); } else { distribution = output; } issueReader.close(); } catch (FileNotFoundException e) { - log.error("Unable to read file '" + issueFile.getAbsolutePath() + "'. " - + e); + log.error("Unable to read file '{}'. {}", issueFile.getAbsolutePath(), e); } catch (IOException e) { - log.error("Unable to read file '" + issueFile.getAbsolutePath() + "'." - + e); + log.error("Unable to read file '{}'. {}", issueFile.getAbsolutePath(), e); } } return distribution; @@ -105,14 +103,14 @@ private static HashMap getPlatformKernel() { while (error != null) { error += stdError.readLine(); } - log.error("Unable to invoke \'uname -ri\' . Standard error : " + error); + log.error("Unable to invoke \'uname -ri\' . Standard error : {}", error); } else { String[] fields = output.trim().split(" "); map.put("kernelRelease", fields[0]); map.put("platform", fields[1]); } } catch (IOException e) { - log.error("Unable to invoke \'uname -ri\' . IOException " + e); + log.error("Unable to invoke \'uname -ri\' . IOException {}", e); } return map; } diff --git a/src/main/java/it/grid/storm/StoRM.java b/src/main/java/it/grid/storm/StoRM.java index 0d6c187c..281d7bec 100644 --- a/src/main/java/it/grid/storm/StoRM.java +++ b/src/main/java/it/grid/storm/StoRM.java @@ -145,10 +145,9 @@ private void configureXMLRPCService(){ } catch (StoRMXmlRpcException e) { - log.error("Unable to create the XML-RPC Server. StoRMXmlRpcException: " - + e.getMessage()); + log.error(e.getMessage(), e); - throw new RuntimeException("Unable to create the XML-RPC Server", e); + throw new RuntimeException(e.getMessage(), e); } } @@ -281,11 +280,11 @@ synchronized public void startRestServer() throws Exception { try { RestService.startServer(); } catch (IOException e) { - log.error("Unable to start internal HTTP Server listening for RESTFul services. IOException : " - + e.getMessage()); - throw new Exception( - "Unable to start internal HTTP Server listening for RESTFul services. IOException : " - + e.getMessage()); + + String emsg = String.format("Unable to start internal HTTP Server " + + "listening for RESTFul services. IOException : %s", e.getMessage()); + log.error(emsg, e); + throw new Exception(emsg); } this.isRestServerRunning = true; } @@ -301,8 +300,9 @@ synchronized public void stopRestServer() { } catch (Exception e) { - log.error("Unable to stop internal HTTP Server listening for RESTFul services: " - + e.getMessage()); + String emsg = String.format("Unable to stop internal HTTP Server " + + "listening for RESTFul services: %s", e.getMessage()); + log.error(emsg, e); } this.isRestServerRunning = false; diff --git a/src/main/java/it/grid/storm/StoRMCommandServer.java b/src/main/java/it/grid/storm/StoRMCommandServer.java index b0c7cb2a..03f7f910 100644 --- a/src/main/java/it/grid/storm/StoRMCommandServer.java +++ b/src/main/java/it/grid/storm/StoRMCommandServer.java @@ -144,9 +144,9 @@ private void startCommandServer() { } catch (IOException e) { - log.error("Could not bind to port {}: {}", - new Object[]{listeningPort,e.getMessage()}, - e); + String emsg = String.format("Could not bind to port %d: %s", + listeningPort, e.getMessage()); + log.error(emsg, e); System.exit(1); } @@ -164,9 +164,11 @@ public void run() { } } catch (IOException e) { - log - .error("UNEXPECTED ERROR! Something went wrong " + - "with server.accept(): {}", e.getMessage(), e); + String emsg = String.format( + "UNEXPECTED ERROR! Something went wrong with server.accept(): %s", + e.getMessage()); + log.error(emsg, e); + System.exit(1); } } @@ -294,7 +296,7 @@ public void run() { // sequence of commands completed break; case UNKNOW: - log.warn("Received an unknown command: " + inputLine); + log.warn("Received an unknown command: {}", inputLine); acceptCommands = false; // any other command breaks the connection, but the command server // remains on! @@ -303,15 +305,16 @@ public void run() { // any other command breaks the connection, but the command server // remains on! acceptCommands = false; - log.warn("Received an unknown command: " + inputLine); + log.warn("Received an unknown command: {}", inputLine); break; } try { inputLine = in.readLine(); } catch (IOException e) { - log - .error("UNEXPECTED ERROR! Unable to read from the client socket. IOException : " - + e.getMessage()); + + String emsg = String.format("UNEXPECTED ERROR! Unable to read from " + + "the client socket. IOException : %s", e.getMessage()); + log.error(emsg, e); return; } } while (inputLine != null && acceptCommands); @@ -333,8 +336,11 @@ private boolean startServices() { storm.startXmlRpcServer(); } } catch (Exception e) { - log.error("Unable to start the xmlrpc server. Exception: " - + e.getMessage(),e); + + String emsg = String.format("Unable to start the xmlrpc server. " + + "Exception: %s", e.getMessage()); + log.error(emsg, e); + stopServices(); return false; } @@ -343,8 +349,11 @@ private boolean startServices() { storm.startRestServer(); } } catch (Exception e) { - log.error("Unable to start the Rest server. Exception: " - + e.getMessage(),e); + + String emsg = String.format("Unable to start the Rest server. " + + "Exception: %s", e.getMessage()); + log.error(emsg, e); + stopServices(); return false; } @@ -384,25 +393,31 @@ private void sendOutputAndClose(String response, BufferedWriter out, out.write(response, 0, response.length()); out.newLine(); } catch (IOException e) { - log - .error("UNEXPECTED ERROR! Unable to write on the client socket. IOException : " - + e.getMessage(),e); + + String emsg = String.format("UNEXPECTED ERROR! Unable to write on " + + "the client socket. IOException : %s", e.getMessage()); + log.error(emsg, e); + } try { out.close(); in.close(); } catch (IOException e) { - log - .error("UNEXPECTED ERROR! Unable to close client socket streams. IOException : " - + e.getMessage(),e); + + String emsg = String.format("UNEXPECTED ERROR! Unable to close client " + + "socket streams. IOException : %s", e.getMessage()); + log.error(emsg, e); + } } finally { try { socket.close(); } catch (IOException e) { - log - .error("UNEXPECTED ERROR! Unable to close client socket. IOException : " - + e.getMessage(),e); + + String emsg = String.format("UNEXPECTED ERROR! Unable to close client " + + "socket. IOException : %s", e.getMessage()); + log.error(emsg, e); + } } } @@ -507,16 +522,17 @@ public static void main(String[] args) { configurationPathname = args[0]; log.info("StoRMCommandServer invoked with two parameters."); - log.info("Configuration file: " + configurationPathname); + log.info("Configuration file: {}", configurationPathname); try { refresh = Integer.parseInt(args[1]); - log.info("Configuration file refresh rate: " + refresh + " seconds"); + log.info("Configuration file refresh rate: {} seconds", refresh); } catch (NumberFormatException e) { - log.error("Configuration file refresh rate: NOT an integer! Disabling refresh by default!"); + log.error("Configuration file refresh rate: NOT an integer! " + + "Disabling refresh by default!", e); } } else { From 05f77180d619e4e0256cec3b7df4bb4dba1db1b0 Mon Sep 17 00:00:00 2001 From: enricovianello Date: Tue, 4 Feb 2014 16:48:40 +0100 Subject: [PATCH 16/45] Fix log calls in storm backend - package it.grid.storm.asynch --- .../it/grid/storm/asynch/AdvancedPicker.java | 58 +- src/main/java/it/grid/storm/asynch/BoL.java | 293 ++++---- .../java/it/grid/storm/asynch/BoLFeeder.java | 216 +++--- .../grid/storm/asynch/BoLPersistentChunk.java | 31 +- src/main/java/it/grid/storm/asynch/Copy.java | 86 +-- .../java/it/grid/storm/asynch/CopyFeeder.java | 56 +- .../storm/asynch/GlobalStatusManager.java | 630 ++++++++++-------- .../InvalidBoLChunkAttributesException.java | 7 +- .../InvalidBoLFeederAttributesException.java | 6 +- .../InvalidCopyAttributesException.java | 12 +- .../InvalidCopyFeederAttributesException.java | 6 +- ...opyPersistentChunkAttributesException.java | 16 +- ...dPersistentRequestAttributesException.java | 6 +- .../asynch/InvalidPtGAttributesException.java | 4 +- .../InvalidPtGChunkAttributesException.java | 7 +- .../InvalidPtGFeederAttributesException.java | 6 +- .../InvalidPtPFeederAttributesException.java | 6 +- .../InvalidPutStatusAttributesException.java | 4 +- .../InvalidRequestAttributesException.java | 4 +- .../asynch/NaiveGridFTPTransferClient.java | 2 +- .../it/grid/storm/asynch/NaiveSRMClient.java | 115 +--- ...NoGridFTPTransferClientFoundException.java | 3 +- .../asynch/NoSRMClientFoundException.java | 3 +- src/main/java/it/grid/storm/asynch/PtG.java | 482 +++++++------- .../java/it/grid/storm/asynch/PtGBuilder.java | 23 +- .../java/it/grid/storm/asynch/PtGFeeder.java | 290 ++++---- .../grid/storm/asynch/PtGPersistentChunk.java | 21 +- src/main/java/it/grid/storm/asynch/PtP.java | 591 +++++++--------- .../java/it/grid/storm/asynch/PtPBuilder.java | 24 +- .../java/it/grid/storm/asynch/PtPFeeder.java | 36 +- .../grid/storm/asynch/PtPPersistentChunk.java | 8 +- .../grid/storm/asynch/PushCopyGetVisitor.java | 5 +- .../grid/storm/asynch/PushCopyPutVisitor.java | 42 +- .../storm/asynch/PushCopyTransferVisitor.java | 29 +- .../it/grid/storm/asynch/SRM22Client.java | 38 +- .../ThirdPartGridFTPTransferClient.java | 24 +- .../storm/asynch/WSRequestTokenConverter.java | 5 +- .../it/grid/storm/asynch/WSTurlConverter.java | 5 +- 38 files changed, 1513 insertions(+), 1687 deletions(-) diff --git a/src/main/java/it/grid/storm/asynch/AdvancedPicker.java b/src/main/java/it/grid/storm/asynch/AdvancedPicker.java index 46df50d1..884727f3 100644 --- a/src/main/java/it/grid/storm/asynch/AdvancedPicker.java +++ b/src/main/java/it/grid/storm/asynch/AdvancedPicker.java @@ -155,7 +155,7 @@ public void retrieve() { } else { - log.info("ADVANCED PICKER: dispatching " + requests.size() + " requests."); + log.info("ADVANCED PICKER: dispatching {} requests.", requests.size()); } @@ -207,12 +207,12 @@ public void retrieve() { } else { - log.warn("ADVANCED PICKER received request " + rt + " of type " - + rtype + " which is NOT currently supported. Dropping request... "); + log.warn("ADVANCED PICKER received request {} of type which is NOT " + + "currently supported. Dropping request... ", rt, rtype); - log.warn("ADVANCED PICKER: Beware that the global status of request " - + rt + " will transit to SRM_FAILURE, but each chunk in the request " + - "will remain in SRM_REQUEST_QUEUED!"); + log.warn("ADVANCED PICKER: Beware that the global status of " + + "request {} will transit to SRM_FAILURE, but each chunk in the " + + "request will remain in SRM_REQUEST_QUEUED!", rt); try { @@ -222,57 +222,59 @@ public void retrieve() { } catch (InvalidTReturnStatusAttributeException ex) { - log.error("ADVANCED PICKER! Unable to change global status in DB: " + ex - , ex); + log.error("ADVANCED PICKER! Unable to change global status in " + + "DB: {}", ex.getMessage(), ex); } } } catch (InvalidPtGFeederAttributesException e) { + + log.error("ADVANCED PICKER ERROR! PtGFeeder could not be created " + + "because of invalid attributes: {}", e.getMessage(), e); - log.error("ADVANCED PICKER ERROR! PtGFeeder could not be created because of invalid attributes:\n" - + e,e); - - log.error("PtG Request is being dropped: " + rsd.requestToken()); + log.error("PtG Request is being dropped: {}", rsd.requestToken()); RequestSummaryCatalog.getInstance().failRequest(rsd, "Internal error does not allow request to be fed to scheduler."); } catch (InvalidPtPFeederAttributesException e) { - log.error("ADVANCED PICKER ERROR! PtPFeeder could not be created" + - " because of invalid attributes:\n" + e,e); + log.error("ADVANCED PICKER ERROR! PtPFeeder could not be created " + + "because of invalid attributes: {}", e.getMessage(),e); - log.error("PtP Request is being dropped: " + rsd.requestToken()); + log.error("PtP Request is being dropped: {}", rsd.requestToken()); RequestSummaryCatalog.getInstance().failRequest(rsd, "Internal error does not allow request to be fed to scheduler."); } catch (InvalidCopyFeederAttributesException e) { - log.error("ADVANCED PICKER ERROR! CopyFeeder could not be created" + - " because of invalid attributes:\n" + e, e); - - log.error("Copy Request is being dropped: " + rsd.requestToken()); + + log.error("ADVANCED PICKER ERROR! CopyFeeder could not be created " + + "because of invalid attributes: {}", e.getMessage(),e); + + log.error("Copy Request is being dropped: {}", rsd.requestToken()); RequestSummaryCatalog.getInstance().failRequest(rsd, "Internal error does not allow request to be fed to scheduler."); } catch (InvalidBoLFeederAttributesException e) { - - log.error("ADVANCED PICKER ERROR! BoLFeeder could not be created " + - "because of invalid attributes:\n" + e, e); - log.error("BoL Request is being dropped: " + rsd.requestToken()); - + + log.error("ADVANCED PICKER ERROR! BoLFeeder could not be created " + + "because of invalid attributes: {}", e.getMessage(), e); + + log.error("BoL Request is being dropped: {}", rsd.requestToken()); + RequestSummaryCatalog.getInstance().failRequest(rsd, "Internal error does not allow request to be fed to scheduler."); } catch (SchedulerException e) { - log.error("ADVANCED PICKER ERROR! The request could not be scheduled" + - " because of scheduler errors!\n" + e, e); - log.error("ADVANCED PICKER ERROR! Request " + rsd.requestToken() - + " of type " + rsd.requestType() + " dropped."); + log.error("ADVANCED PICKER ERROR! The request could not be scheduled" + + "because of scheduler errors: {}", e.getMessage(), e); + log.error("ADVANCED PICKER ERROR! Request {} of type {} dropped.", + rsd.requestToken(), rsd.requestType()); RequestSummaryCatalog.getInstance().failRequest(rsd, "Internal scheduler has problems accepting request feed."); diff --git a/src/main/java/it/grid/storm/asynch/BoL.java b/src/main/java/it/grid/storm/asynch/BoL.java index d15aa8ce..d6a3d141 100644 --- a/src/main/java/it/grid/storm/asynch/BoL.java +++ b/src/main/java/it/grid/storm/asynch/BoL.java @@ -45,7 +45,6 @@ import it.grid.storm.srm.types.TSizeInBytes; import it.grid.storm.srm.types.TSpaceToken; import it.grid.storm.srm.types.TStatusCode; -import it.grid.storm.synchcall.data.DataHelper; import it.grid.storm.synchcall.surl.SurlStatusManager; import it.grid.storm.tape.recalltable.TapeRecallCatalog; import it.grid.storm.tape.recalltable.model.TapeRecallStatus; @@ -165,34 +164,32 @@ public void choose(Streets s) { */ public Boolean completeRequest(TapeRecallStatus recallStatus) { - boolean requestSuccessfull = false; - if (recallStatus == TapeRecallStatus.SUCCESS) { - try { - if (bupLocalFile.isOnDisk()) { - requestData.changeStatusSRM_SUCCESS("File recalled from tape"); - requestSuccessfull = true; - } else { - log - .error("File " - + bupLocalFile.getAbsolutePath() - + " not found on the disk, but it was reported to be successfully recalled from tape"); - requestData.changeStatusSRM_FAILURE("Error recalling file from tape"); - } - } catch (FSException e) { - log.error("Unable to determine if file " - + bupLocalFile.getAbsolutePath() + " is on disk . FSException : " - + e.getMessage(),e); - requestData - .changeStatusSRM_FAILURE("Internal error: unable to determine if the file is on disk"); - } - } else { - if (recallStatus == TapeRecallStatus.ABORTED) { - requestData.changeStatusSRM_ABORTED("Recalling file from tape aborted"); - } else { - requestData.changeStatusSRM_FAILURE("Error recalling file from tape"); + if (TapeRecallStatus.ABORTED.equals(recallStatus)) { + requestData.changeStatusSRM_ABORTED("Recalling file from tape aborted"); + return false; + } + + if (!TapeRecallStatus.SUCCESS.equals(recallStatus)) { + requestData.changeStatusSRM_FAILURE("Error recalling file from tape"); + return false; + } + + try { + if (bupLocalFile.isOnDisk()) { + requestData.changeStatusSRM_SUCCESS("File recalled from tape"); + return true; } + } catch (FSException e) { + log.error("Unable to determine if file {} is on disk. FSException: {}", + bupLocalFile.getAbsolutePath(), e.getMessage(), e); + requestData.changeStatusSRM_FAILURE("Unable to determine if file is on disk"); + return false; } - return requestSuccessfull; + + log.error("File {} not found on the disk, but it was reported to be " + + "successfully recalled from tape", bupLocalFile.getAbsolutePath()); + requestData.changeStatusSRM_FAILURE("Error recalling file from tape"); + return false; } /** @@ -201,67 +198,67 @@ public Boolean completeRequest(TapeRecallStatus recallStatus) { */ public void doIt() { - log.debug("Handling BoL chunk for user DN: " + gu.getDn() + "; for SURL: " - + requestData.getSURL()); + TSURL surl = requestData.getSURL(); + TRequestToken rToken = requestData.getRequestToken(); + String user = gu.getDn(); + + log.debug("Handling BoL chunk for user DN: {}; for SURL: {}", user, surl); - if (!verifySurlStatusTransition(requestData.getSURL(), - requestData.getRequestToken())) { + if (!verifySurlStatusTransition(surl, rToken)) { failure = true; + log.info("Unable to perform the BOL request, surl busy"); requestData.changeStatusSRM_FILE_BUSY("Requested file is" + " busy (in an incompatible state with BOL)"); - log.info("Unable to perform the BOL request, surl busy"); - printOutcome(gu.getDn(), requestData.getSURL(), requestData.getStatus()); + printOutcome(user, surl, requestData.getStatus()); return; } - else { - StoRI fileStoRI = null; - try { - fileStoRI = NamespaceDirector.getNamespace().resolveStoRIbySURL( - requestData.getSURL(), gu); - } catch (IllegalArgumentException e) { - failure = true; - requestData - .changeStatusSRM_INTERNAL_ERROR("Unable to get StoRI for surl " - + requestData.getSURL()); - log.error("Unable to get StoRI for surl " + requestData.getSURL() - + " IllegalArgumentException: " + e.getMessage()); - } catch (UnapprochableSurlException e) { - requestData.changeStatusSRM_AUTHORIZATION_FAILURE(e.getMessage()); - failure = true; - log.info("Unable to build a stori for surl " + requestData.getSURL() - + " for user " + DataHelper.getRequestor(requestData) - + " UnapprochableSurlException: " + e.getMessage()); - } catch (NamespaceException e) { - requestData.changeStatusSRM_INTERNAL_ERROR(e.getMessage()); - failure = true; - log.info("Unable to build a stori for surl " + requestData.getSURL() - + " for user " + DataHelper.getRequestor(requestData) - + " NamespaceException: " + e.getMessage()); - } catch (InvalidSURLException e) { - requestData.changeStatusSRM_INVALID_PATH(e.getMessage()); - failure = true; - log.info("Unable to build a stori for surl " + requestData.getSURL() - + " for user " + DataHelper.getRequestor(requestData) - + " InvalidSURLException: " + e.getMessage()); - } - if (!failure) { - SpaceHelper sp = new SpaceHelper(); - TSpaceToken token = sp.getTokenFromStoRI(log, fileStoRI); - SpaceAuthzInterface spaceAuth = AuthzDirector.getSpaceAuthz(token); - - if (spaceAuth.authorize(gu, SRMSpaceRequest.BOL)) { - manageIsPermit(fileStoRI); - } else { - failure = true; - requestData - .changeStatusSRM_AUTHORIZATION_FAILURE("Space authoritazion denied " - + requestData.getSURL() + " in Storage Area: " + token); - log.debug("Read access to " + requestData.getSURL() - + " in Storage Area: " + token + " denied!"); - } + + StoRI fileStoRI = null; + try { + fileStoRI = NamespaceDirector.getNamespace().resolveStoRIbySURL(surl, gu); + } catch (IllegalArgumentException e) { + log.error("Unable to build a stori for surl '{}' and user '{}'. " + + "IllegalArgumentException: {}", surl, user, e.getMessage(), e); + requestData.changeStatusSRM_INTERNAL_ERROR(e.getMessage()); + failure = true; + } catch (UnapprochableSurlException e) { + log.info("Unable to build a stori for surl '{}' and user '{}'. " + + "UnapprochableSurlException: {}", surl, user, e.getMessage()); + requestData.changeStatusSRM_AUTHORIZATION_FAILURE(e.getMessage()); + failure = true; + } catch (NamespaceException e) { + log.error("Unable to build a stori for surl '{}' and user '{}'. " + + "NamespaceException: {}", surl, user, e.getMessage(), e); + requestData.changeStatusSRM_INTERNAL_ERROR(e.getMessage()); + failure = true; + } catch (InvalidSURLException e) { + log.info("Unable to build a stori for surl '{}' and user '{}'. " + + "InvalidSURLException: {}", surl, user, e.getMessage()); + requestData.changeStatusSRM_INVALID_PATH(e.getMessage()); + failure = true; + } finally { + if (failure) { + printOutcome(user, surl, requestData.getStatus()); + return; } } - printOutcome(gu.getDn(), requestData.getSURL(), requestData.getStatus()); + + SpaceHelper sp = new SpaceHelper(); + TSpaceToken token = sp.getTokenFromStoRI(log, fileStoRI); + SpaceAuthzInterface spaceAuth = AuthzDirector.getSpaceAuthz(token); + + if (!spaceAuth.authorize(gu, SRMSpaceRequest.BOL)) { + String emsg = String.format("Space authorization denied %s" + + " in Storage Area: %s", surl, token); + log.debug(emsg); + requestData.changeStatusSRM_AUTHORIZATION_FAILURE(emsg); + failure = true; + printOutcome(user, surl, requestData.getStatus()); + return; + } + + manageIsPermit(fileStoRI); + printOutcome(user, surl, requestData.getStatus()); } @Override @@ -291,13 +288,9 @@ public String getUserDN() { public boolean isResultSuccess() { - boolean result = false; TStatusCode statusCode = requestData.getStatus().getStatusCode(); - if ((statusCode.getValue().equals(TStatusCode.SRM_FILE_PINNED.getValue())) - || requestData.getStatus().isSRM_SUCCESS()) { - result = true; - } - return result; + return ((statusCode.equals(TStatusCode.SRM_FILE_PINNED)) + || requestData.getStatus().isSRM_SUCCESS()); } private void backupData(LocalFile localFile) { @@ -313,74 +306,77 @@ private void manageIsPermit(StoRI fileStoRI) { LocalFile localFile = fileStoRI.getLocalFile(); try { + if ((!localFile.exists()) || (localFile.isDirectory())) { - // File does not exist, or it is a directory! Fail request with - // SRM_INVALID_PATH! - requestData - .changeStatusSRM_INVALID_PATH("The requested file either does not exist, or it is a directory!"); + + String emsg = "The requested file either does not exist, or it is a directory!"; + requestData.changeStatusSRM_INVALID_PATH(emsg); failure = true; - log - .debug("BoLChunk: the requested file either does not exist, or it is a directory!"); - - } else { // File exists and it is not a directory - - if (fileStoRI.getVirtualFileSystem().getStorageClassType() - .isTapeEnabled()) { - - // Compute the Expiration Time in seconds - // Add the deferred start time to the expiration date - long expDate = (System.currentTimeMillis() / 1000 + (requestData - .getLifeTime().value() + requestData.getDeferredStartTime())); - StormEA.setPinned(localFile.getAbsolutePath(), expDate); - - // set group permission for tape quota management - fileStoRI.setGroupTapeRead(); - requestData.setFileSize(TSizeInBytes.make(localFile.length(), - SizeUnit.BYTES)); - - if (isStoriOndisk(fileStoRI)) { - - requestData - .changeStatusSRM_SUCCESS("srmBringOnLine successfully handled!"); - - } else { - - requestData - .changeStatusSRM_REQUEST_INPROGRESS("Recalling file from tape"); - - String voName = null; - if (gu instanceof AbstractGridUser) { - voName = ((AbstractGridUser) gu).getVO().getValue(); - } - new TapeRecallCatalog().insertTask(this, voName, - localFile.getAbsolutePath()); - backupData(localFile); - } - } else { - requestData - .changeStatusSRM_NOT_SUPPORTED("Tape not supported for this filesystem"); - } + log.debug("BoLChunk: {}", emsg); + return; + } + + if (!fileStoRI.getVirtualFileSystem().getStorageClassType() + .isTapeEnabled()) { + + String emsg = "Tape not supported for this filesystem"; + log.debug(emsg); + requestData.changeStatusSRM_NOT_SUPPORTED(emsg); + return; + } + + // Compute the Expiration Time in seconds + // Add the deferred start time to the expiration date + long expDate = (System.currentTimeMillis() / 1000 + (requestData + .getLifeTime().value() + requestData.getDeferredStartTime())); + StormEA.setPinned(localFile.getAbsolutePath(), expDate); + + // set group permission for tape quota management + fileStoRI.setGroupTapeRead(); + requestData.setFileSize(TSizeInBytes.make(localFile.length(), + SizeUnit.BYTES)); + + if (isStoriOndisk(fileStoRI)) { + requestData + .changeStatusSRM_SUCCESS("srmBringOnLine successfully handled!"); + + } else { + + requestData + .changeStatusSRM_REQUEST_INPROGRESS("Recalling file from tape"); + String voName = null; + if (gu instanceof AbstractGridUser) { + voName = ((AbstractGridUser) gu).getVO().getValue(); + } + new TapeRecallCatalog().insertTask(this, voName, + localFile.getAbsolutePath()); + backupData(localFile); } + } catch (SecurityException e) { - // The check for existence of the File failed because there is a - // SecurityManager installed that - // denies read privileges for that File! Perhaps the local system - // administrator of StoRM set - // up Java policies that contrast policies described by the - // PolicyCollector! There is a conflict here! + /* + * The check for existence of the File failed because there is a + * SecurityManager installed that denies read privileges for that File! + * Perhaps the local system administrator of StoRM set up Java policies + * that contrast policies described by the PolicyCollector! There is a + * conflict here! + */ requestData - .changeStatusSRM_FAILURE("StoRM is not allowed to work on requested file!"); + .changeStatusSRM_FAILURE("StoRM is not allowed to work on requested file!"); failure = true; - log - .error("ATTENTION in BoLChunk! BoLChunk received a SecurityException from Java SecurityManager; StoRM cannot check-existence or check-if-directory for: " - + localFile.toString() + "; exception: " + e); + log.error("ATTENTION in BoLChunk! BoLChunk received a SecurityException " + + "from Java SecurityManager; StoRM cannot check-existence or " + + "check-if-directory for: {}; exception: {}", localFile.toString(), + e.getMessage(), e); + return; + } catch (Exception e) { - requestData - .changeStatusSRM_FAILURE("StoRM encountered an unexpected error!"); + requestData.changeStatusSRM_FAILURE("StoRM encountered an unexpected error!"); failure = true; - log.error("ERROR in BoLChunk! StoRM process got an unexpected error! " - + e); + log.error("ERROR in BoLChunk! StoRM process got an unexpected error! {}", + e.getMessage(), e); + return; } } @@ -388,9 +384,8 @@ private boolean isStoriOndisk(StoRI storiFile) throws FSException { if (!storiFile.getVirtualFileSystem().getStorageClassType().isTapeEnabled()) { return true; - } else { - return storiFile.getLocalFile().isOnDisk(); } + return storiFile.getLocalFile().isOnDisk(); } private boolean verifySurlStatusTransition(TSURL surl, @@ -404,7 +399,7 @@ private boolean verifySurlStatusTransition(TSURL surl, private void printOutcome(String dn, TSURL surl, TReturnStatus status) { - log.info("Finished handling BoL chunk for user DN: " + dn + "; for SURL: " - + surl + "; result is: " + status); + log.info("Finished handling BoL chunk for user DN: {}; for SURL: {}; " + + "result is: {}", dn, surl, status); } } diff --git a/src/main/java/it/grid/storm/asynch/BoLFeeder.java b/src/main/java/it/grid/storm/asynch/BoLFeeder.java index fa1c21df..cbb759b4 100644 --- a/src/main/java/it/grid/storm/asynch/BoLFeeder.java +++ b/src/main/java/it/grid/storm/asynch/BoLFeeder.java @@ -123,14 +123,16 @@ public BoLFeeder(RequestSummaryData rsd) throw new InvalidBoLFeederAttributesException(rsd, null, null); } try { + gu = rsd.gridUser(); this.rsd = rsd; gsm = new GlobalStatusManager(rsd.requestToken()); + } catch (InvalidOverallRequestAttributeException e) { - log - .error("ATTENTION in BoLFeeder! Programming bug when creating GlobalStatusManager! " - + e); + + log.error(e.getMessage(), e); throw new InvalidBoLFeederAttributesException(rsd, gu, null); + } } @@ -141,7 +143,7 @@ public BoLFeeder(RequestSummaryData rsd) */ public void doIt() { - log.debug("BoLFeeder: pre-processing " + rsd.requestToken()); + log.debug("BoLFeeder: pre-processing {}", rsd.requestToken()); // Get all parts in request Collection chunks = BoLChunkCatalog.getInstance() .lookup(rsd.requestToken()); @@ -153,7 +155,7 @@ public void doIt() { "This SRM Get request contained nothing to process!"); } else { manageChunks(chunks); - log.debug("BoLFeeder: finished pre-processing " + rsd.requestToken()); + log.debug("BoLFeeder: finished pre-processing {}", rsd.requestToken()); } } @@ -163,7 +165,7 @@ public void doIt() { */ private void manageChunks(Collection chunks) { - log.debug("BoLFeeder - number of chunks in request: " + chunks.size()); + log.debug("BoLFeeder - number of chunks in request: {}", chunks.size()); for (BoLPersistentChunkData chunkData : chunks) { /* add chunk for global status consideration */ gsm.addChunk(chunkData); @@ -184,9 +186,9 @@ private void manageChunks(Collection chunks) { * fromSURL does _not_ correspond to this installation of StoRM: fail * chunk! */ - log.warn("BoLFeeder: srmBoL contract violation! fromSURL" - + " does not correspond to this machine!\n Request: " - + rsd.requestToken() + "\n Chunk: " + chunkData); + log.warn("BoLFeeder: srmBoL contract violation! fromSURL does not " + + "correspond to this machine!\n Request: {}\n Chunk: {}", + rsd.requestToken(), chunkData); chunkData.changeStatusSRM_FAILURE("SRM protocol violation! " + "Cannot do an srmBoL of a SURL that is not local!"); @@ -221,10 +223,10 @@ private void manageNotDirectory(BoLPersistentChunkData auxChunkData) { * for some reason gu, rsd or auxChunkData may be null! This should not be * so! */ - log.error("UNEXPECTED ERROR in BoLFeeder! Chunk could not be created!\n" - + e); - log.error("Request: " + rsd.requestToken()); - log.error("Chunk: " + auxChunkData); + log.error("UNEXPECTED ERROR in BoLFeeder! Chunk could not be " + + "created!\n{}", e.getMessage(), e); + log.error("Request: {}" + rsd.requestToken()); + log.error("Chunk: {}" + auxChunkData); auxChunkData.changeStatusSRM_FAILURE("StoRM internal error does" + " not allow this chunk to be processed!"); @@ -233,11 +235,10 @@ private void manageNotDirectory(BoLPersistentChunkData auxChunkData) { gsm.failedChunk(auxChunkData); } catch (SchedulerException e) { /* Internal error of scheduler! */ - log - .error("UNEXPECTED ERROR in ChunkScheduler! Chunk could not be scheduled!\n" - + e); - log.error("Request: " + rsd.requestToken()); - log.error("Chunk: " + auxChunkData); + log.error("UNEXPECTED ERROR in ChunkScheduler! Chunk could not be " + + "scheduled!\n{}", e.getMessage(), e); + log.error("Request: {}", rsd.requestToken()); + log.error("Chunk: {}", auxChunkData); auxChunkData.changeStatusSRM_FAILURE("StoRM internal scheduler " + "error prevented this chunk from being processed!"); @@ -254,105 +255,104 @@ private void manageNotDirectory(BoLPersistentChunkData auxChunkData) { private void manageIsDirectory(BoLPersistentChunkData chunkData) { log.debug("BoLFeeder - pre-processing Directory chunk..."); - chunkData - .changeStatusSRM_REQUEST_INPROGRESS("srmBringOnLine chunk is being processed!"); + chunkData.changeStatusSRM_REQUEST_INPROGRESS("srmBringOnLine chunk " + + "is being processed!"); BoLChunkCatalog.getInstance().update(chunkData); - try { - StoRI stori = null; - try { - stori = NamespaceDirector.getNamespace().resolveStoRIbySURL( - chunkData.getSURL(), gu); - } catch (IllegalArgumentException e) { - log.error("Unable to build StoRI by SURL and user", e); - chunkData - .changeStatusSRM_INTERNAL_ERROR("Unable to build StoRI by SURL and user"); - BoLChunkCatalog.getInstance().update(chunkData); + TSURL surl = chunkData.getSURL(); + String user = DataHelper.getRequestor(chunkData); - log.debug("ATTENTION in BoLFeeder! BoLFeeder received request" - + " for a SURL and user not recognised by StoRI!"); - gsm.failedChunk(chunkData); - } catch (UnapprochableSurlException e) { - chunkData.changeStatusSRM_AUTHORIZATION_FAILURE(e.getMessage()); - BoLChunkCatalog.getInstance().update(chunkData); - log.info("Unable to build a stori for surl " + chunkData.getSURL() - + " for user " + DataHelper.getRequestor(chunkData) - + " UnapprochableSurlException: " + e.getMessage()); - gsm.failedChunk(chunkData); - } catch (NamespaceException e) { - chunkData.changeStatusSRM_INTERNAL_ERROR(e.getMessage()); - BoLChunkCatalog.getInstance().update(chunkData); - log.info("Unable to build a stori for surl " + chunkData.getSURL() - + " for user " + DataHelper.getRequestor(chunkData) - + " NamespaceException: " + e.getMessage()); - gsm.failedChunk(chunkData); - } catch (InvalidSURLException e) { - chunkData.changeStatusSRM_INVALID_PATH(e.getMessage()); + StoRI stori = null; + try { + stori = NamespaceDirector.getNamespace().resolveStoRIbySURL(surl, gu); + } catch (IllegalArgumentException e) { + log.error("Unable to build a stori for surl {} for user {}. " + + "IllegalArgumentException: {}", surl, user, e.getMessage(), e); + chunkData.changeStatusSRM_INTERNAL_ERROR(e.getMessage()); + } catch (UnapprochableSurlException e) { + log.info("Unable to build a stori for surl {} for user {}. " + + "UnapprochableSurlException: {}", surl, user, e.getMessage()); + chunkData.changeStatusSRM_AUTHORIZATION_FAILURE(e.getMessage()); + } catch (NamespaceException e) { + log.error("Unable to build a stori for surl {} for user {}. " + + "NamespaceException: {}", surl, user, e.getMessage(), e); + chunkData.changeStatusSRM_INTERNAL_ERROR(e.getMessage()); + } catch (InvalidSURLException e) { + log.info("Unable to build a stori for surl {} for user {}. " + + "InvalidSURLException: {}", surl, user, e.getMessage()); + chunkData.changeStatusSRM_INVALID_PATH(e.getMessage()); + } finally { + if (stori == null) { + // failed: BoLChunkCatalog.getInstance().update(chunkData); - log.info("Unable to build a stori for surl " + chunkData.getSURL() - + " for user " + DataHelper.getRequestor(chunkData) - + " InvalidSURLException: " + e.getMessage()); gsm.failedChunk(chunkData); + return; } - if (stori != null) { - /* Collection of children! */ - Collection storiChildren = stori.getChildren(chunkData - .getDirOption()); - log.debug("BoLFeeder - Number of children in parent: " - + storiChildren.size()); - - TDirOption notDir = new TDirOption(false, false, 0); - BoLPersistentChunkData childData; - for (StoRI storiChild : storiChildren) { - try { - childData = new BoLPersistentChunkData(chunkData.getRequestToken(), - storiChild.getSURL(), chunkData.getLifeTime(), notDir, - chunkData.getTransferProtocols(), chunkData.getFileSize(), - chunkData.getStatus(), chunkData.getTransferURL(), - chunkData.getDeferredStartTime()); - - /* fill in new db row and set the PrimaryKey of ChildData! */ - BoLChunkCatalog.getInstance().addChild(childData); - - log.debug("BoLFeeder - added child data: " + childData); - /* add chunk for global status consideration */ - gsm.addChunk(childData); - - manageNotDirectory(childData); - } catch (InvalidSurlRequestDataAttributesException e) { - /* - * For some reason it was not possible to create a BoLChunkData: it - * is a programme bug!!! It should not occur!!! Log it and skip to - * the next one! - */ - log.error("ERROR in BoLFeeder! While expanding recursive request" - + ", it was not possible to create a new BoLChunkData! " + e); + } + + try { + + /* Collection of children! */ + Collection storiChildren = stori.getChildren(chunkData + .getDirOption()); + log.debug("BoLFeeder - Number of children in parent: {}", + storiChildren.size()); + + TDirOption notDir = new TDirOption(false, false, 0); + BoLPersistentChunkData childData; + + for (StoRI storiChild : storiChildren) { + try { + childData = new BoLPersistentChunkData(chunkData.getRequestToken(), + storiChild.getSURL(), chunkData.getLifeTime(), notDir, + chunkData.getTransferProtocols(), chunkData.getFileSize(), + chunkData.getStatus(), chunkData.getTransferURL(), + chunkData.getDeferredStartTime()); + + /* fill in new db row and set the PrimaryKey of ChildData! */ + BoLChunkCatalog.getInstance().addChild(childData); + + log.debug("BoLFeeder - added child data: {}", childData); + /* add chunk for global status consideration */ + gsm.addChunk(childData); + + manageNotDirectory(childData); + } catch (InvalidSurlRequestDataAttributesException e) { + /* + * For some reason it was not possible to create a BoLChunkData: it + * is a programme bug!!! It should not occur!!! Log it and skip to + * the next one! + */ + log.error("ERROR in BoLFeeder! While expanding recursive request, " + + "it was not possible to create a new BoLChunkData! {}", + e.getMessage(), e); } } - log.debug("BoLFeeder - expansion completed."); // info + log.debug("BoLFeeder - expansion completed."); chunkData.changeStatusSRM_SUCCESS("srmBringOnLine with dirOption" + " set: request successfully expanded!"); BoLChunkCatalog.getInstance().update(chunkData); gsm.successfulChunk(chunkData); - } + } catch (InvalidTDirOptionAttributesException e) { + /* Could not create TDirOption that specifies no-expansion! */ chunkData.changeStatusSRM_FAILURE("srmBringOnLine with dirOption set:" + " expansion failure due to internal error!"); BoLChunkCatalog.getInstance().update(chunkData); - log.error("UNEXPECTED ERROR in BoLFeeder! Could" - + " not create TDirOption specifying non-expansion!\n" + e); - log.error("Request: " + rsd.requestToken()); - log.error("Chunk: " + chunkData); + log.error("UNEXPECTED ERROR in BoLFeeder! Could not create TDirOption " + + "specifying non-expansion!\n{}", e.getMessage(), e); + log.error("Request: {}", rsd.requestToken()); + log.error("Chunk: {}", chunkData); gsm.failedChunk(chunkData); + } catch (InvalidDescendantsEmptyRequestException e) { - chunkData - .changeStatusSRM_SUCCESS("BEWARE! srmBringOnLine with dirOption set:" - + " it referred to a directory that was empty!"); + chunkData.changeStatusSRM_SUCCESS("BEWARE! srmBringOnLine with " + + "dirOption set: it referred to a directory that was empty!"); BoLChunkCatalog.getInstance().update(chunkData); @@ -361,32 +361,34 @@ private void manageIsDirectory(BoLPersistentChunkData chunkData) { gsm.successfulChunk(chunkData); } catch (InvalidDescendantsPathRequestException e) { + /* Attempting to expand non existent directory! */ - chunkData - .changeStatusSRM_INVALID_PATH("srmBringOnLine with dirOption set:" - + " it referred to a non-existent directory!"); + chunkData.changeStatusSRM_INVALID_PATH("srmBringOnLine with dirOption " + + "set: it referred to a non-existent directory!"); BoLChunkCatalog.getInstance().update(chunkData); - log.debug("ATTENTION in BoLFeeder! BoLFeeder received request" - + " to expand non-existing directory."); + log.debug("ATTENTION in BoLFeeder! BoLFeeder received request to expand " + + "non-existing directory."); gsm.failedChunk(chunkData); + } catch (InvalidDescendantsFileRequestException e) { + /* Attempting to expand a file! */ - chunkData - .changeStatusSRM_INVALID_PATH("srmBringOnLine with dirOption set: " - + "a file was asked to be expanded!"); + chunkData.changeStatusSRM_INVALID_PATH("srmBringOnLine with dirOption " + + "set: a file was asked to be expanded!"); BoLChunkCatalog.getInstance().update(chunkData); - log - .debug("ATTENTION in BoLFeeder! BoLFeeder received request to expand a file."); + log.debug("ATTENTION in BoLFeeder! BoLFeeder received request to expand " + + "a file."); gsm.failedChunk(chunkData); + } catch (InvalidDescendantsAuthRequestException e) { + /* No rights to directory! */ - chunkData - .changeStatusSRM_AUTHORIZATION_FAILURE("srmBringOnLine with dirOption set:" - + " user has no right to access directory!"); + chunkData.changeStatusSRM_AUTHORIZATION_FAILURE("srmBringOnLine with " + + "dirOption set: user has no right to access directory!"); BoLChunkCatalog.getInstance().update(chunkData); diff --git a/src/main/java/it/grid/storm/asynch/BoLPersistentChunk.java b/src/main/java/it/grid/storm/asynch/BoLPersistentChunk.java index dfd56be2..b45643fc 100644 --- a/src/main/java/it/grid/storm/asynch/BoLPersistentChunk.java +++ b/src/main/java/it/grid/storm/asynch/BoLPersistentChunk.java @@ -128,15 +128,13 @@ public Boolean completeRequest(TapeRecallStatus recallStatus) { persistStatus(); if (requestSuccessfull) { gsm.successfulChunk((BoLPersistentChunkData) requestData); - log.info("Completed BoL request (" + rsd.requestToken() - + "), file successfully recalled from tape: " - + requestData.getSURL().toString()); + log.info( + "Completed BoL request ({}), file successfully recalled from tape: {}", + rsd.requestToken(), requestData.getSURL().toString()); } else { gsm.failedChunk((BoLPersistentChunkData) requestData); - log - .error("BoL request (" + requestData.getRequestToken() - + "), file not recalled from tape: " - + requestData.getSURL().toString()); + log.error("BoL request ({}), file not recalled from tape: {}", + requestData.getRequestToken(), requestData.getSURL().toString()); } return requestSuccessfull; } @@ -148,8 +146,8 @@ public Boolean completeRequest(TapeRecallStatus recallStatus) { @Override public String getName() { - return "BoLChunk of request " + rsd.requestToken() + " for SURL " - + requestData.getSURL(); + return String.format("BoLChunk of request %s for SURL %s", + rsd.requestToken(), requestData.getSURL()); } public String getRequestToken() { @@ -167,12 +165,15 @@ public void updateGlobalStatus() { * a SUCCESS in the corresponding row (and the file will have been * recalled). */ - if (requestData.getStatus().getStatusCode() != TStatusCode.SRM_REQUEST_INPROGRESS) { - if (failure) { - gsm.failedChunk((BoLPersistentChunkData) requestData); - } else { - gsm.successfulChunk((BoLPersistentChunkData) requestData); - } + if (TStatusCode.SRM_REQUEST_INPROGRESS.equals(requestData.getStatus() + .getStatusCode())) { + + return; + } + if (failure) { + gsm.failedChunk((BoLPersistentChunkData) requestData); + } else { + gsm.successfulChunk((BoLPersistentChunkData) requestData); } } diff --git a/src/main/java/it/grid/storm/asynch/Copy.java b/src/main/java/it/grid/storm/asynch/Copy.java index a1891bb4..85387b57 100644 --- a/src/main/java/it/grid/storm/asynch/Copy.java +++ b/src/main/java/it/grid/storm/asynch/Copy.java @@ -100,8 +100,8 @@ public Copy(GridUserInterface gu, CopyData requestData, int n) .getTime()); } catch (InvalidTRequestTokenAttributesException e) { // never thrown - log.error("Unexpected InvalidTRequestTokenAttributesException: " - + e.getMessage()); + log.error("Unexpected InvalidTRequestTokenAttributesException: {}", + e.getMessage(), e); throw new IllegalStateException( "Unexpected InvalidTRequestTokenAttributesException"); } @@ -141,16 +141,18 @@ public void choose(Streets s) { */ public void doIt() { - log.debug("Handling Copy chunk for user DN: " + this.gu.getDn() - + "; fromSURL: " + this.requestData.getSURL() + "; toSURL: " - + this.requestData.getDestinationSURL()); - log.debug("RequestToken used for local operation: " + localrt); + log.debug("Handling Copy chunk for user DN: {}; fromSURL: {}; toSURL: {}", + gu.getDn(), requestData.getSURL(), requestData.getDestinationSURL()); + + log.debug("RequestToken used for local operation: {}", localrt); GetOperationResult getResult = executeGetOperation(); - log.debug("Result from get: " + getResult); + log.debug("Result from get: {}", getResult); + if (getResult.successful() - && getResult.status().getStatusCode() == TStatusCode.SRM_FILE_PINNED) { + && TStatusCode.SRM_FILE_PINNED.equals(getResult.status().getStatusCode())) { + PutOperationResult putResult = executePutOperation(getResult.filesize()); - log.debug("Result from put: " + putResult); + log.debug("Result from put: {}", putResult); /* * ATTENTION! the following check for SRM_SUCCESS is done to keep * compatibility between StoRM servers which use a hack thereby switching @@ -162,15 +164,16 @@ public void doIt() { && ((putResult.status().getStatusCode() .equals(TStatusCode.SRM_SPACE_AVAILABLE)) || (putResult.status() .getStatusCode().equals(TStatusCode.SRM_SUCCESS)))) { + TransferResult transferResult = executeTransfer(getResult, putResult); - log.debug("Result from transfer: " + transferResult); + log.debug("Result from transfer: {}", transferResult); if (transferResult.successful()) { requestData.changeStatusSRM_SUCCESS("srmCopy successfully handled!"); log.debug("SRM Copy successful!"); this.failure = false; // gsm.successfulChunk(chunkData); } else { - String message = "GSIFTP transfer failed! " - + transferResult.failureExplanation(); + String message = String.format("GSIFTP transfer failed! %s", + transferResult.failureExplanation()); log.error(message); requestData.changeStatusSRM_FAILURE(message); this.failure = true; // gsm.failedChunk(chunkData); @@ -178,28 +181,20 @@ public void doIt() { } else { // The put operation was problematic! String message = "PUT part of srmCopy failed! "; - if (putResult.successful()) { - message = message + putResult.status().toString(); - } log.error(message); - requestData.changeStatusSRM_FAILURE("PUT part of srmCopy failed! " - + message); + requestData.changeStatusSRM_FAILURE(message); this.failure = true; } } else { // the get operation was problematic! String message = "GET part of srmCopy failed! "; - if (getResult.successful()) { - message = message + getResult.status().toString(); - } log.error(message); requestData.changeStatusSRM_FAILURE(message); - this.failure = true; // gsm.failedChunk(chunkData); + this.failure = true; } - log.info("Finished handling Copy chunk for user DN: " + this.gu.getDn() - + "; fromSURL: " + this.requestData.getSURL() + "; toSURL: " - + this.requestData.getDestinationSURL() + " result is: " - + this.requestData.getStatus()); + log.info("Finished handling Copy chunk for user DN: {}; fromSURL: {}; " + + "toSURL: {} result is: {}", gu.getDn(), requestData.getSURL(), + requestData.getDestinationSURL(), requestData.getStatus()); } /** @@ -208,8 +203,8 @@ public void doIt() { */ public String getName() { - return "Copy for SURL " + requestData.getSURL() + " to SURL " - + requestData.getDestinationSURL(); + return String.format("Copy for SURL %s to SURL %s", requestData.getSURL(), + requestData.getDestinationSURL()); } @Override @@ -271,8 +266,6 @@ protected class TransferResult implements Result { private boolean successful = false; private String failureExplanation = ""; - private final Copy.ResultType type = Copy.ResultType.TRANSFER; - /** * Constructor used to indicate a failed transfer: it requires a String * explaining the failure. @@ -325,7 +318,6 @@ public String failureExplanation() { */ protected class GetOperationResult implements Result { - private final Copy.ResultType type = Copy.ResultType.GET; /** * boolean indicating if the operation was successful */ @@ -377,7 +369,7 @@ public GetOperationResult(TReturnStatus status, TTURL getTURL, try { this.status = new TReturnStatus(); } catch (InvalidTReturnStatusAttributeException e) { - log.warn("Unexpected InvalidTReturnStatusAttributeException: " + e); + log.warn("Unexpected InvalidTReturnStatusAttributeException: {}", e); } } } @@ -397,7 +389,7 @@ public GetOperationResult(String failureExplanation) { try { this.status = new TReturnStatus(); } catch (InvalidTReturnStatusAttributeException e) { - log.warn("Unexpected InvalidTReturnStatusAttributeException: " + e); + log.warn("Unexpected InvalidTReturnStatusAttributeException: {}", e); } } @@ -452,9 +444,9 @@ public TRequestToken requetToken() { @Override public String toString() { - return "GetOperationResult: successful=" + successful + "; status=" - + status + "; getTURL=" + getTURL + "; filesize=" + filesize - + "; requestToken=" + rt; + return String.format("GetOperationResult: successful=%b; status=%s; " + + "getTURL=%s; filesize=%s; requestToken=%s", successful, status, + getTURL, filesize, rt); } } @@ -471,15 +463,11 @@ public String toString() { */ protected class PutOperationResult implements Result { - private final Copy.ResultType type = Copy.ResultType.PUT; - - private boolean successful = false; // boolean indicating if the operation - // was successful - private TReturnStatus status; // TReturnStatus from srmPrepareToGet - private TTURL putTURL = TTURL.makeEmpty(); // TURL from srmPrepareToGet - private String failureExplanation = ""; // String containing an explanation - // of failure - private TRequestToken rt = null; // TRequestToken associated to PtP + private boolean successful = false; + private TReturnStatus status; + private TTURL putTURL = TTURL.makeEmpty(); + private String failureExplanation = ""; + private TRequestToken rt = null; /** * Constructor to make a successful PutOperationResult containing the @@ -500,7 +488,7 @@ public PutOperationResult(TReturnStatus status, TTURL putTURL, try { this.status = new TReturnStatus(); } catch (InvalidTReturnStatusAttributeException e) { - log.warn("Unexpected InvalidTReturnStatusAttributeException: " + e); + log.warn("Unexpected InvalidTReturnStatusAttributeException: {}", e); } } } @@ -520,7 +508,7 @@ public PutOperationResult(String failureExplanation) { try { this.status = new TReturnStatus(); } catch (InvalidTReturnStatusAttributeException e) { - log.warn("Unexpected InvalidTReturnStatusAttributeException: " + e); + log.warn("Unexpected InvalidTReturnStatusAttributeException: {}", e); } } @@ -568,9 +556,9 @@ public TRequestToken requestToken() { @Override public String toString() { - return "PutOperationResult: successful=" + successful + "; status=" - + status + "; putTURL=" + putTURL + "; failureExplanation=" - + failureExplanation; + return String.format("PutOperationResult: successful=%b; status=%s; " + + "putTURL=%s; failureExplanation=%s", successful, status, putTURL, + failureExplanation); } } } diff --git a/src/main/java/it/grid/storm/asynch/CopyFeeder.java b/src/main/java/it/grid/storm/asynch/CopyFeeder.java index 9d428d95..ac29379f 100644 --- a/src/main/java/it/grid/storm/asynch/CopyFeeder.java +++ b/src/main/java/it/grid/storm/asynch/CopyFeeder.java @@ -86,7 +86,7 @@ public CopyFeeder(RequestSummaryData rsd) gsm = new GlobalStatusManager(rsd.requestToken()); } catch (InvalidOverallRequestAttributeException e) { log.error("ATTENTION in CopyFeeder! " - + "Programming bug when creating GlobalStatusManager! " + e); + + "Programming bug when creating GlobalStatusManager! {}", e); throw new InvalidCopyFeederAttributesException(rsd, gu, gsm); } } @@ -102,14 +102,13 @@ public void doIt() { Collection chunks = CopyChunkCatalog.getInstance() .lookup(rsd.requestToken()); if (chunks.isEmpty()) { - log.warn("ATTENTION in CopyFeeder! " - + "This SRM Copy request contained nothing to process! " - + rsd.requestToken()); + log.warn("ATTENTION in CopyFeeder! This SRM Copy request contained " + + "nothing to process! {}", rsd.requestToken()); RequestSummaryCatalog.getInstance().failRequest(rsd, "This SRM Copy request contained nothing to process!"); } else { manageChunks(chunks); - log.debug("CopyFeeder: finished pre-processing " + rsd.requestToken()); + log.debug("CopyFeeder: finished pre-processing {}", rsd.requestToken()); } } @@ -119,7 +118,7 @@ public void doIt() { */ private void manageChunks(Collection chunksData) { - log.debug("CopyFeeder: number of chunks in request " + chunksData.size()); + log.debug("CopyFeeder: number of chunks in request {}", chunksData.size()); int counter = 0; // counter of the number of chunk retrieved for (CopyPersistentChunkData chunkData : chunksData) { /* Add chunk for global status consideration */ @@ -156,8 +155,8 @@ private void manage(CopyPersistentChunkData chunkData, int counter) { * CHANGED SOON!!! ONLY FOR DEBUG PURPOSES!!! */ log.info("CopyFeeder: chunk is localCopy."); - log.debug("Request: " + rsd.requestToken()); - log.debug("Chunk: " + chunkData); + log.debug("Request: {}", rsd.requestToken()); + log.debug("Chunk: {]", chunkData); SchedulerFacade .getInstance() @@ -173,8 +172,8 @@ private void manage(CopyPersistentChunkData chunkData, int counter) { * copy to destination! */ log.info("CopyFeeder: chunk is pushCopy."); - log.debug("Request: " + rsd.requestToken()); - log.debug("Chunk: " + chunkData); + log.debug("Request: {}", rsd.requestToken()); + log.debug("Chunk: {}", chunkData); SchedulerFacade .getInstance() @@ -194,11 +193,11 @@ private void manage(CopyPersistentChunkData chunkData, int counter) { * WARNING!!! OPERATION NOT SUPPORTED!!! MUST BE CHANGED SOON!!! */ log.warn("CopyFeeder: srmCopy in pull mode NOT supported yet!"); - log.debug("Request: " + rsd.requestToken()); - log.debug("Chunk: " + chunkData); + log.debug("Request: {}", rsd.requestToken()); + log.debug("Chunk: {}", chunkData); - chunkData.changeStatusSRM_NOT_SUPPORTED("srmCopy in pull " - + "mode NOT supported yet!"); + chunkData + .changeStatusSRM_NOT_SUPPORTED("srmCopy in pull mode NOT supported yet!"); CopyChunkCatalog.getInstance().update(chunkData); /* @@ -213,11 +212,11 @@ private void manage(CopyPersistentChunkData chunkData, int counter) { log.warn("CopyFeeder: srmCopy contract violation! Neither fromSURL" + " nor toSURL are this machine! Cannot do a third party SRM" + " transfer as per protocol!"); - log.warn("Request: " + rsd.requestToken()); - log.warn("Chunk: " + chunkData); + log.warn("Request: {}", rsd.requestToken()); + log.warn("Chunk: {}", chunkData); - chunkData.changeStatusSRM_FAILURE("SRM protocol violation" - + "! Cannot do an srmCopy between third parties!"); + chunkData + .changeStatusSRM_FAILURE("SRM protocol violation! Cannot do an srmCopy between third parties!"); CopyChunkCatalog.getInstance().update(chunkData); /* @@ -233,25 +232,24 @@ private void manage(CopyPersistentChunkData chunkData, int counter) { */ log.error("UNEXPECTED ERROR in CopyFeeder! Chunk could not be created!\n" + e); - log.error("Request: " + rsd.requestToken()); - log.error("Chunk: " + chunkData); + log.error("Request: {}", rsd.requestToken()); + log.error("Chunk: {}", chunkData); - chunkData.changeStatusSRM_FAILURE("StoRM internal error does not" - + " allow this chunk to be processed!"); + chunkData + .changeStatusSRM_FAILURE("StoRM internal error does not allow this chunk to be processed!"); CopyChunkCatalog.getInstance().update(chunkData); /* inform global status computation of the chunk s failure */ gsm.failedChunk(chunkData); } catch (SchedulerException e) { /* Internal error of scheduler! */ - log - .error("UNEXPECTED ERROR in ChunkScheduler! Chunk could not be scheduled!\n" - + e); - log.error("Request: " + rsd.requestToken()); - log.error("Chunk: " + chunkData); + log.error("UNEXPECTED ERROR in ChunkScheduler! Chunk could not be " + + "scheduled!\n{}", e); + log.error("Request: {}", rsd.requestToken()); + log.error("Chunk: {}", chunkData); - chunkData.changeStatusSRM_FAILURE("StoRM internal scheduler " - + "error prevented this chunk from being processed!"); + chunkData + .changeStatusSRM_FAILURE("StoRM internal scheduler error prevented this chunk from being processed!"); CopyChunkCatalog.getInstance().update(chunkData); /* inform global status computation of the chunk s failure */ diff --git a/src/main/java/it/grid/storm/asynch/GlobalStatusManager.java b/src/main/java/it/grid/storm/asynch/GlobalStatusManager.java index cb860c8b..19871a5b 100644 --- a/src/main/java/it/grid/storm/asynch/GlobalStatusManager.java +++ b/src/main/java/it/grid/storm/asynch/GlobalStatusManager.java @@ -78,20 +78,28 @@ public GlobalStatusManager(TRequestToken rt) */ synchronized public void addChunk(ChunkData c) { - log.debug("GlobalStatusManager: asked to add chunkData " - + c.getIdentifier()); - if ((!finished) && (c != null)) { - if (chunks.contains(new Long(c.getIdentifier()))) { - log - .warn("GlobalStatusManager: chunkData NOT added because of another chunkData already added with the same identifier"); - } else { - chunks.add(new Long(c.getIdentifier())); - log.debug("GlobalStatusManager: chunkData added."); - } - } else { - log - .warn("GlobalStatusManager: chunkData NOT added because either it is null or finishedAdding has already been invoked!"); + if (c == null) { + log.warn("GlobalStatusManager: chunkData NOT added because it is null!"); + return; + } + + log.debug("GlobalStatusManager: asked to add chunkData {}", + c.getIdentifier()); + + if (finished) { + log.warn("GlobalStatusManager: chunkData NOT added because finishedAdding " + + "has already been invoked!"); + return; + } + + if (chunks.contains(new Long(c.getIdentifier()))) { + log.warn("GlobalStatusManager: chunkData NOT added because of another " + + "chunkData already added with the same identifier"); + return; } + + chunks.add(new Long(c.getIdentifier())); + log.debug("GlobalStatusManager: chunkData added."); } /** @@ -103,20 +111,23 @@ synchronized public void finishedAdding() { log.debug("GlobalStatusManager: received finishedAdding signal."); this.finished = true; - if (chunks.isEmpty()) { - // finishedAdding invoked after _all_ ChunkData were processed! - // make final state transition - if (internal == InternalState.INTERMEDIATE_SUCCESS) { - internal = InternalState.SUCCESS; - } else if (internal == InternalState.INTERMEDIATE_FAIL) { - internal = InternalState.FAIL; - } - // save state in persistence - log - .debug("GlobalStatusManager: since all chunks have been processed, saving final state " - + internal); - saveRequestState(); + + if (!chunks.isEmpty()) { + log.debug("Empty chunks!"); + return; + } + + // finishedAdding invoked after _all_ ChunkData were processed! + // do final state transition: + if (internal.equals(InternalState.INTERMEDIATE_SUCCESS)) { + internal = InternalState.SUCCESS; + } else if (internal.equals(InternalState.INTERMEDIATE_FAIL)) { + internal = InternalState.FAIL; } + // save state in persistence + log.debug("GlobalStatusManager: since all chunks have been processed, " + + "saving final state {}", internal); + saveRequestState(); } /** @@ -127,99 +138,115 @@ synchronized public void finishedAdding() { */ synchronized public void successfulChunk(ChunkData c) { - log.debug("GlobalStatusManager: received successfulChunk signal for " + c); - - if (c != null && !chunks.isEmpty() - && chunks.remove(new Long(c.getIdentifier()))) { - - // manage state transition: c was indeed there - if (finished && (chunks.isEmpty())) { - // no other chunk will be added to request, and none is left: this was - // the last one to be processed! - log.debug("GlobalStatusManager: finished and no more chunks left... "); - if (internal == InternalState.IN_PROGRESS) { - internal = InternalState.SUCCESS; - } else if (internal == InternalState.INTERMEDIATE_SUCCESS) { - internal = InternalState.SUCCESS; - } else if (internal == InternalState.INTERMEDIATE_FAIL) { - internal = InternalState.PARTIAL; - } else if (internal == InternalState.PARTIAL) { - internal = InternalState.PARTIAL; // stays the same! - } else if (internal == InternalState.ERROR) { - internal = InternalState.ERROR; // stays the same! - } else { - log - .error("ERROR in GlobalStatusManager: programming bug! Unexpected InternalState: " - + internal); - } - - log.debug("GlobalStatusManager: saving final global state " + internal); - saveRequestState(); - - } else if (finished && (!chunks.isEmpty())) { - - // no chunk will be added to request, but there are _more_ left to be - // processed! - log - .debug("GlobalStatusManager: finished but there are more chunks to be processed... "); - if (internal == InternalState.IN_PROGRESS) { - internal = InternalState.INTERMEDIATE_SUCCESS; - } else if (internal == InternalState.INTERMEDIATE_SUCCESS) { - internal = InternalState.INTERMEDIATE_SUCCESS; // stays the same! - } else if (internal == InternalState.INTERMEDIATE_FAIL) { - internal = InternalState.PARTIAL; - } else if (internal == InternalState.PARTIAL) { - internal = InternalState.PARTIAL; // stays the same! - } else if (internal == InternalState.ERROR) { - internal = InternalState.ERROR; // stays the same! - } else { - log - .error("ERROR in GlobalStatusManager: programming bug! Unexpected InternalState: " - + internal); - } - log.debug("GlobalStatusManager: transited to " + internal); - - } else if (!finished) { - - // more chunks may be added to request, and it is all the same if there - // are or aren't any left to be - // processed! - log - .debug("GlobalStatusManager: still not finished adding chunks for consideration, but it is the same whether there are more to be processed or not..."); - if (internal == InternalState.IN_PROGRESS) { - internal = InternalState.INTERMEDIATE_SUCCESS; - } else if (internal == InternalState.INTERMEDIATE_SUCCESS) { - internal = InternalState.INTERMEDIATE_SUCCESS; // stays the same! - } else if (internal == InternalState.INTERMEDIATE_FAIL) { - internal = InternalState.PARTIAL; - } else if (internal == InternalState.PARTIAL) { - internal = InternalState.PARTIAL; // stays the same! - } else if (internal == InternalState.ERROR) { - internal = InternalState.ERROR; // stays the same! - } else { - log - .error("ERROR in GlobalStatusManager: programming bug! Unexpected InternalState: " - + internal); - } - log.debug("GlobalStatusManager: transited to " + internal); + log.debug("GlobalStatusManager: received successfulChunk signal for {}", c); + if (c == null) { + log.error("ERROR IN GLOBAL STATUS EVALUATION! There was an attempt to " + + "signal a successful Chunk, but it is null!"); + log.error("Request: {}", rt); + log.error("Chunk: {}", c); + internal = InternalState.ERROR; + return; + } + + if (chunks.isEmpty()) { + log.error("ERROR IN GLOBAL STATUS EVALUATION! There was an attempt to " + + "signal a successful Chunk, but there are actually no Chunks left to " + + "be considered!"); + log.error("Request: {}", rt); + log.error("Chunk: {}", c); + internal = InternalState.ERROR; + return; + } + + boolean removed = chunks.remove(new Long(c.getIdentifier())); + + if (!removed) { + log.error("ERROR IN GLOBAL STATUS EVALUATION! There was an attempt to " + + "signal a successful Chunk, but it was not originally asked to be " + + "considered in the evaluation!"); + log.error("Request: {}", rt); + log.error("Chunk: {}", c); + internal = InternalState.ERROR; + return; + } + + // manage state transition: c was indeed there + if (finished && (chunks.isEmpty())) { + // no other chunk will be added to request, and none is left: this was + // the last one to be processed! + log.debug("GlobalStatusManager: finished and no more chunks left... "); + if (internal.equals(InternalState.IN_PROGRESS)) { + internal = InternalState.SUCCESS; + } else if (internal.equals(InternalState.INTERMEDIATE_SUCCESS)) { + internal = InternalState.SUCCESS; + } else if (internal.equals(InternalState.INTERMEDIATE_FAIL)) { + internal = InternalState.PARTIAL; + } else if (internal.equals(InternalState.PARTIAL)) { + internal = InternalState.PARTIAL; // stays the same! + } else if (internal.equals(InternalState.ERROR)) { + internal = InternalState.ERROR; // stays the same! } else { - // This cannot possibly occur by logic! But there could be - // multithreading issues in case of bugs! - log - .error("ERROR IN GLOBAL STATUS EVALUATION! An impossible logic codition has materialised: it may be due to multithreading issues! Request is " - + rt); - internal = InternalState.ERROR; + log.error("ERROR in GlobalStatusManager: programming bug! Unexpected InternalState: {}", internal); + return; } + log.debug("GlobalStatusManager: saving final global state {}", internal); + saveRequestState(); + } else if (finished && (!chunks.isEmpty())) { + + // no chunk will be added to request, but there are _more_ left to be + // processed! + log.debug("GlobalStatusManager: finished but there are more chunks to be processed... "); + if (internal.equals(InternalState.IN_PROGRESS)) { + internal = InternalState.INTERMEDIATE_SUCCESS; + } else if (internal.equals(InternalState.INTERMEDIATE_SUCCESS)) { + internal = InternalState.INTERMEDIATE_SUCCESS; // stays the same! + } else if (internal.equals(InternalState.INTERMEDIATE_FAIL)) { + internal = InternalState.PARTIAL; + } else if (internal.equals(InternalState.PARTIAL)) { + internal = InternalState.PARTIAL; // stays the same! + } else if (internal.equals(InternalState.ERROR)) { + internal = InternalState.ERROR; // stays the same! + } else { + log.error("ERROR in GlobalStatusManager: programming bug! Unexpected InternalState: {}", internal); + return; + } + log.debug("GlobalStatusManager: transited to {}", internal); + + } else if (!finished) { + + // more chunks may be added to request, and it is all the same if there + // are or aren't any left to be processed! + log.debug("GlobalStatusManager: still not finished adding chunks for " + + "consideration, but it is the same whether there are more to be " + + "processed or not..."); + + if (internal.equals(InternalState.IN_PROGRESS)) { + internal = InternalState.INTERMEDIATE_SUCCESS; + } else if (internal.equals(InternalState.INTERMEDIATE_SUCCESS)) { + internal = InternalState.INTERMEDIATE_SUCCESS; // stays the same! + } else if (internal.equals(InternalState.INTERMEDIATE_FAIL)) { + internal = InternalState.PARTIAL; + } else if (internal.equals(InternalState.PARTIAL)) { + internal = InternalState.PARTIAL; // stays the same! + } else if (internal.equals(InternalState.ERROR)) { + internal = InternalState.ERROR; // stays the same! + } else { + log.error("ERROR in GlobalStatusManager: programming bug! Unexpected InternalState: {}", internal); + return; + } + + log.debug("GlobalStatusManager: transited to {}", internal); } else { - // error situation! - log - .error("ERROR IN GLOBAL STATUS EVALUATION! There was an attempt to signal a successful Chunk, but it is either null, or there are actually no Chunks left to be considered, or it was not originally asked to be considered in the evaluation!"); - log.error("Request: " + rt); - log.error("Chunk: " + c); - internal = InternalState.ERROR; + // This cannot possibly occur by logic! But there could be + // multithreading issues in case of bugs! + log.error("ERROR IN GLOBAL STATUS EVALUATION! An impossible logic " + + "condition has materialised: it may be due to multithreading issues! " + + "Request is {}", rt); + internal = InternalState.ERROR; } + } /** @@ -230,88 +257,113 @@ synchronized public void successfulChunk(ChunkData c) { */ synchronized public void failedChunk(ChunkData c) { - log.debug("GlobalStatusManager: received failedChunk signal for " + c); - if ((c != null) && (!chunks.isEmpty()) - && chunks.remove(new Long(c.getIdentifier()))) { - // manage state transition: c was indeed there - if (finished && (chunks.isEmpty())) { - // no other chunk will be added to request, and none is left: this was - // the last one to be processed! - log.debug("GlobalStatusManager: finished and no more chunks left... "); - if (internal == InternalState.IN_PROGRESS) { - internal = InternalState.FAIL; - } else if (internal == InternalState.INTERMEDIATE_SUCCESS) { - internal = InternalState.PARTIAL; - } else if (internal == InternalState.INTERMEDIATE_FAIL) { - internal = InternalState.FAIL; - } else if (internal == InternalState.PARTIAL) { - internal = InternalState.PARTIAL; // stays the same! - } else if (internal == InternalState.ERROR) { - internal = InternalState.ERROR; // stays the same! - } else { - log - .error("ERROR in GlobalStatusManager: programming bug! Unexpected InternalState: " - + internal); - } - log.debug("GlobalStatusManager: saving final global state " + internal); - saveRequestState(); - } else if (finished && (!chunks.isEmpty())) { - // no chunk will be added to request, but there are _more_ left to be - // processed! - log - .debug("GlobalStatusManager: finished but there are more chunks to be processed... "); - if (internal == InternalState.IN_PROGRESS) { - internal = InternalState.INTERMEDIATE_FAIL; - } else if (internal == InternalState.INTERMEDIATE_SUCCESS) { - internal = InternalState.PARTIAL; - } else if (internal == InternalState.INTERMEDIATE_FAIL) { - internal = InternalState.INTERMEDIATE_FAIL; // stays the same! - } else if (internal == InternalState.PARTIAL) { - internal = InternalState.PARTIAL; // stays the same! - } else if (internal == InternalState.ERROR) { - internal = InternalState.ERROR; // stays the same! - } else { - log - .error("ERROR in GlobalStatusManager: programming bug! Unexpected InternalState: " - + internal); - } - log.debug("GlobalStatusManager: transited to " + internal); - } else if (!finished) { - // more chunks may be added to request, and it is all the same if there - // are or arent any left to be - // processed! - log - .debug("GlobalStatusManager: still not finished adding chunks for consideration, but it is the same whether there are more to be processed or not..."); - if (internal == InternalState.IN_PROGRESS) { - internal = InternalState.INTERMEDIATE_FAIL; - } else if (internal == InternalState.INTERMEDIATE_SUCCESS) { - internal = InternalState.PARTIAL; - } else if (internal == InternalState.INTERMEDIATE_FAIL) { - internal = InternalState.INTERMEDIATE_FAIL; // stays the same! - } else if (internal == InternalState.PARTIAL) { - internal = InternalState.PARTIAL; // stays the same! - } else if (internal == InternalState.ERROR) { - internal = InternalState.ERROR; // stays the same! - } else { - log - .error("ERROR in GlobalStatusManager: programming bug! Unexpected InternalState: " - + internal); - } - log.debug("GlobalStatusManager: transited to " + internal); + log.debug("GlobalStatusManager: received failedChunk signal for {}", c); + + if (c == null) { + log.error("ERROR IN GLOBAL STATUS EVALUATION! There was an attempt to " + + "signal a failed Chunk, but it is null!"); + log.error("Request: {}", rt); + log.error("ChunkData: {}", c); + internal = InternalState.ERROR; + return; + } + + if (chunks.isEmpty()) { + log.error("ERROR IN GLOBAL STATUS EVALUATION! There was an attempt to " + + "signal a failed Chunk, but there are actually no Chunks left to be " + + "considered!"); + log.error("Request: {}", rt); + log.error("ChunkData: {}", c); + internal = InternalState.ERROR; + return; + } + + boolean removed = chunks.remove(new Long(c.getIdentifier())); + + if (!removed) { + log.error("ERROR IN GLOBAL STATUS EVALUATION! There was an attempt to " + + "signal a successful Chunk, but it was not originally asked to be " + + "considered in the evaluation!"); + log.error("Request: {}", rt); + log.error("ChunkData: {}", c); + internal = InternalState.ERROR; + return; + } + + // manage state transition: c was indeed there + if (finished && (chunks.isEmpty())) { + // no other chunk will be added to request, and none is left: this was + // the last one to be processed! + log.debug("GlobalStatusManager: finished and no more chunks left... "); + if (internal.equals(InternalState.IN_PROGRESS)) { + internal = InternalState.FAIL; + } else if (internal.equals(InternalState.INTERMEDIATE_SUCCESS)) { + internal = InternalState.PARTIAL; + } else if (internal.equals(InternalState.INTERMEDIATE_FAIL)) { + internal = InternalState.FAIL; + } else if (internal.equals(InternalState.PARTIAL)) { + internal = InternalState.PARTIAL; // stays the same! + } else if (internal.equals(InternalState.ERROR)) { + internal = InternalState.ERROR; // stays the same! } else { - // This cannot possibly occur by logic! But there could be - // multithreading issues in case of bugs! - log - .error("ERROR IN GLOBAL STATUS EVALUATION! An impossible logic codition has materialised: it may be due to multithreading issues! Request is " - + rt); - internal = InternalState.ERROR; + log.error("ERROR in GlobalStatusManager: programming bug! " + + "Unexpected InternalState: {}", internal); + return; + } + log.debug("GlobalStatusManager: saving final global state {}", internal); + saveRequestState(); + } else if (finished && (!chunks.isEmpty())) { + // no chunk will be added to request, but there are _more_ left to be + // processed! + log.debug("GlobalStatusManager: finished but there are more chunks to be " + + "processed... "); + if (internal.equals(InternalState.IN_PROGRESS)) { + internal = InternalState.INTERMEDIATE_FAIL; + } else if (internal.equals(InternalState.INTERMEDIATE_SUCCESS)) { + internal = InternalState.PARTIAL; + } else if (internal.equals(InternalState.INTERMEDIATE_FAIL)) { + internal = InternalState.INTERMEDIATE_FAIL; // stays the same! + } else if (internal.equals(InternalState.PARTIAL)) { + internal = InternalState.PARTIAL; // stays the same! + } else if (internal.equals(InternalState.ERROR)) { + internal = InternalState.ERROR; // stays the same! + } else { + log.error("ERROR in GlobalStatusManager: programming bug! Unexpected " + + "InternalState: {}", internal); + return; + } + log.debug("GlobalStatusManager: transited to {}", internal); + + } else if (!finished) { + // more chunks may be added to request, and it is all the same if there + // are or arent any left to be processed! + log.debug("GlobalStatusManager: still not finished adding chunks for " + + "consideration, but it is the same whether there are more to be " + + "processed or not..."); + + if (internal.equals(InternalState.IN_PROGRESS)) { + internal = InternalState.INTERMEDIATE_FAIL; + } else if (internal.equals(InternalState.INTERMEDIATE_SUCCESS)) { + internal = InternalState.PARTIAL; + } else if (internal.equals(InternalState.INTERMEDIATE_FAIL)) { + internal = InternalState.INTERMEDIATE_FAIL; // stays the same! + } else if (internal.equals(InternalState.PARTIAL)) { + internal = InternalState.PARTIAL; // stays the same! + } else if (internal.equals(InternalState.ERROR)) { + internal = InternalState.ERROR; // stays the same! + } else { + log.error("ERROR in GlobalStatusManager: programming bug! Unexpected " + + "InternalState: {}", internal); + return; } + log.debug("GlobalStatusManager: transited to " + internal); + } else { - // error situation! - log - .error("ERROR IN GLOBAL STATUS EVALUATION! There was an attempt to signal a failed Chunk, but it is either null, or there are actually no Chunks left to be considered, or it was not originally asked to be considered in the evaluation!"); - log.error("Request: " + rt); - log.error("ChunkData: " + c); + // This cannot possibly occur by logic! But there could be + // multithreading issues in case of bugs! + log.error("ERROR IN GLOBAL STATUS EVALUATION! An impossible logic " + + "condition has materialised: it may be due to multithreading issues! " + + "Request is {}", rt); internal = InternalState.ERROR; } } @@ -325,78 +377,107 @@ synchronized public void failedChunk(ChunkData c) { */ synchronized public void expiredSpaceLifetimeChunk(ChunkData c) { - log - .debug("GlobalStatusManager: received expiredSpaceLifetimeChunk signal for " - + c); - if ((c != null) && (!chunks.isEmpty()) - && chunks.remove(new Long(c.getIdentifier()))) { - // manage state transition: c was indeed there - if (finished && (chunks.isEmpty())) { - // no other chunk will be added to request, and none is left: this was - // the last one to be processed! - log.debug("GlobalStatusManager: finished and no more chunks left... "); - if (internal == InternalState.IN_PROGRESS) { - internal = InternalState.SPACEFAIL; - } else if (internal == InternalState.SPACEFAIL) { - internal = InternalState.SPACEFAIL; // stays the same! - } else if (internal == InternalState.ERROR) { - internal = InternalState.ERROR; // stays the same! - } else { - log - .error("ERROR in GlobalStatusManager: programming bug! Unexpected InternalState: " - + internal); - } - log.debug("GlobalStatusManager: saving final global state " + internal); - saveRequestState(); - } else if (finished && (!chunks.isEmpty())) { - // no chunk will be added to request, but there are _more_ left to be - // processed! - log - .debug("GlobalStatusManager: finished but there are more chunks to be processed... "); - if (internal == InternalState.IN_PROGRESS) { - internal = InternalState.SPACEFAIL; - } else if (internal == InternalState.SPACEFAIL) { - internal = InternalState.SPACEFAIL; // stays the same! - } else if (internal == InternalState.ERROR) { - internal = InternalState.ERROR; // stays the same! - } else { - log - .error("ERROR in GlobalStatusManager: programming bug! Unexpected InternalState: " - + internal); - } - log.debug("GlobalStatusManager: transited to " + internal); - } else if (!finished) { - // more chunks may be added to request, and it is all the same if there - // are or arent any left to be - // processed! - log - .debug("GlobalStatusManager: still not finished adding chunks for consideration, but it is the same whether there are more to be processed or not..."); - if (internal == InternalState.IN_PROGRESS) { - internal = InternalState.SPACEFAIL; - } else if (internal == InternalState.SPACEFAIL) { - internal = InternalState.SPACEFAIL; // stays the same! - } else if (internal == InternalState.ERROR) { - internal = InternalState.ERROR; // stays the same! - } else { - log - .error("ERROR in GlobalStatusManager: programming bug! Unexpected InternalState: " - + internal); - } - log.debug("GlobalStatusManager: transited to " + internal); + log.debug("GlobalStatusManager: received expiredSpaceLifetimeChunk signal for {}", c); + + if (c == null) { + log.error("ERROR IN GLOBAL STATUS EVALUATION! There was an attempt to " + + "signal a failed Chunk, but it is null!"); + log.error("Request: {}", rt); + log.error("ChunkData: {}", c); + internal = InternalState.ERROR; + return; + } + + if (chunks.isEmpty()) { + log.error("ERROR IN GLOBAL STATUS EVALUATION! There was an attempt to " + + "signal a failed Chunk, but there are actually no Chunks left to be " + + "considered!"); + log.error("Request: {}", rt); + log.error("ChunkData: {}", c); + internal = InternalState.ERROR; + return; + } + + boolean removed = chunks.remove(new Long(c.getIdentifier())); + + if (!removed) { + log.error("ERROR IN GLOBAL STATUS EVALUATION! There was an attempt to " + + "signal a successful Chunk, but it was not originally asked to be " + + "considered in the evaluation!"); + log.error("Request: {}", rt); + log.error("ChunkData: {}", c); + internal = InternalState.ERROR; + return; + } + + // manage state transition: c was indeed there + if (finished && (chunks.isEmpty())) { + + // no other chunk will be added to request, and none is left: this was + // the last one to be processed! + log.debug("GlobalStatusManager: finished and no more chunks left... "); + if (internal.equals(InternalState.IN_PROGRESS)) { + internal = InternalState.SPACEFAIL; + } else if (internal.equals(InternalState.SPACEFAIL)) { + internal = InternalState.SPACEFAIL; // stays the same! + } else if (internal.equals(InternalState.ERROR)) { + internal = InternalState.ERROR; // stays the same! } else { - // This cannot possibly occur by logic! But there could be - // multithreading issues in case of bugs! - log - .error("ERROR IN GLOBAL STATUS EVALUATION! An impossible logic codition has materialised: it may be due to multithreading issues! Request is " - + rt); - internal = InternalState.ERROR; + log.error("ERROR in GlobalStatusManager: programming bug! Unexpected " + + "InternalState: {}", internal); + return; } + log.debug("GlobalStatusManager: saving final global state {}", internal); + saveRequestState(); + + } else if (finished && (!chunks.isEmpty())) { + + // no chunk will be added to request, but there are _more_ left to be + // processed! + log.debug("GlobalStatusManager: finished but there are more chunks to be " + + "processed... "); + if (internal.equals(InternalState.IN_PROGRESS)) { + internal = InternalState.SPACEFAIL; + } else if (internal.equals(InternalState.SPACEFAIL)) { + internal = InternalState.SPACEFAIL; // stays the same! + } else if (internal.equals(InternalState.ERROR)) { + internal = InternalState.ERROR; // stays the same! + } else { + log.error("ERROR in GlobalStatusManager: programming bug! Unexpected " + + "InternalState: {}", internal); + return; + } + log.debug("GlobalStatusManager: transited to {}", internal); + + } else if (!finished) { + + // more chunks may be added to request, and it is all the same if there + // are or arent any left to be processed! + log.debug("GlobalStatusManager: still not finished adding chunks for " + + "consideration, but it is the same whether there are more to be " + + "processed or not..."); + + if (internal.equals(InternalState.IN_PROGRESS)) { + internal = InternalState.SPACEFAIL; + } else if (internal.equals(InternalState.SPACEFAIL)) { + internal = InternalState.SPACEFAIL; // stays the same! + } else if (internal.equals(InternalState.ERROR)) { + internal = InternalState.ERROR; // stays the same! + } else { + log.error("ERROR in GlobalStatusManager: programming bug! Unexpected " + + "InternalState: {}", internal); + return; + } + + log.debug("GlobalStatusManager: transited to {}", internal); + } else { - // error situation! - log - .error("ERROR IN GLOBAL STATUS EVALUATION! There was an attempt to signal a space failed Chunk, but it is either null, or there are actually no Chunks left to be considered, or it was not originally asked to be considered in the evaluation!"); - log.error("Request: " + rt); - log.error("ChunkData: " + c); + + // This cannot possibly occur by logic! But there could be + // multithreading issues in case of bugs! + log.error("ERROR IN GLOBAL STATUS EVALUATION! An impossible logic " + + "condition has materialised: it may be due to multithreading issues! " + + "Request is {}", rt); internal = InternalState.ERROR; } } @@ -414,48 +495,48 @@ private void saveRequestState() { TReturnStatus retstat = null; - if (internal == InternalState.ERROR) { + if (internal.equals(InternalState.ERROR)) { updatePinFileLifetime = true; retstat = new TReturnStatus(TStatusCode.SRM_PARTIAL_SUCCESS, "Global status cannot be evaluated: single file status must be checked."); - } else if (internal == InternalState.FAIL) { + } else if (internal.equals(InternalState.FAIL)) { updatePinFileLifetime = false; retstat = new TReturnStatus(TStatusCode.SRM_FAILURE, "All chunks failed!"); - } else if (internal == InternalState.SUCCESS) { + } else if (internal.equals(InternalState.SUCCESS)) { updatePinFileLifetime = true; retstat = new TReturnStatus(TStatusCode.SRM_SUCCESS, "All chunks successfully handled!"); - } else if (internal == InternalState.PARTIAL) { + } else if (internal.equals(InternalState.PARTIAL)) { updatePinFileLifetime = true; retstat = new TReturnStatus(TStatusCode.SRM_PARTIAL_SUCCESS, "Some chunks were successful while others failed!"); - } else if (internal == InternalState.SPACEFAIL) { + } else if (internal.equals(InternalState.SPACEFAIL)) { updatePinFileLifetime = false; retstat = new TReturnStatus(TStatusCode.SRM_SPACE_LIFETIME_EXPIRED, "Supplied SpaceToken has expired lifetime!"); + } else { updatePinFileLifetime = true; retstat = new TReturnStatus(TStatusCode.SRM_PARTIAL_SUCCESS, "Global status cannot be evaluated: single file status must be checked."); - log - .error("ERROR IN GLOBAL STATUS EVALUATION! " - + internal - + " was attempted to be written into persistence, but it is not a final state!"); - log.error("Request: " + rt); + log.error("ERROR IN GLOBAL STATUS EVALUATION! {} was attempted to be " + + "written into persistence, but it is not a final state!", internal); + log.error("Request: {}", rt); + } - log.debug("GlobalStatusManager: saving into persistence " + retstat); + log.debug("GlobalStatusManager: saving into persistence {}", retstat); if (updatePinFileLifetime) { RequestSummaryCatalog.getInstance().updateGlobalStatusPinFileLifetime( @@ -466,9 +547,8 @@ private void saveRequestState() { } } catch (InvalidTReturnStatusAttributeException e) { - log - .error("ERROR IN GLOBAL STATUS EVALUATION! Could not create a valid TReturnStatus: this is a programming bug! " - + e); + log.error("ERROR IN GLOBAL STATUS EVALUATION! Could not create a valid " + + "TReturnStatus: this is a programming bug! {}", e); } } diff --git a/src/main/java/it/grid/storm/asynch/InvalidBoLChunkAttributesException.java b/src/main/java/it/grid/storm/asynch/InvalidBoLChunkAttributesException.java index 392e0f61..d6cea5db 100644 --- a/src/main/java/it/grid/storm/asynch/InvalidBoLChunkAttributesException.java +++ b/src/main/java/it/grid/storm/asynch/InvalidBoLChunkAttributesException.java @@ -55,8 +55,9 @@ public InvalidBoLChunkAttributesException(GridUserInterface gu, public String toString() { - return "Invalid attributes when creating BoLChunk: nullGridUser=" + nullGu - + ", nullRequestSumamryData=" + nullRsd + "nullBoLChunkData=" - + nullChunkData + "nullGlobalStatusManager=" + nullGlobalStatusManager; + return String.format("Invalid attributes when creating BoLChunk: " + + "nullGridUser=%b; nullRequestSumamryData=%b; nullBoLChunkData=%b; " + + "nullGlobalStatusManager=%b" ,nullGu, nullRsd, nullChunkData, + nullGlobalStatusManager); } } diff --git a/src/main/java/it/grid/storm/asynch/InvalidBoLFeederAttributesException.java b/src/main/java/it/grid/storm/asynch/InvalidBoLFeederAttributesException.java index 33c09c72..41c71da8 100644 --- a/src/main/java/it/grid/storm/asynch/InvalidBoLFeederAttributesException.java +++ b/src/main/java/it/grid/storm/asynch/InvalidBoLFeederAttributesException.java @@ -51,8 +51,8 @@ public InvalidBoLFeederAttributesException(RequestSummaryData rsd, public String toString() { - return "null-RequestSummaryData=" + nullRequestSummaryData - + "; null-GridUser=" + nullGridUser + "; null-GlobalStatusManagerr=" - + nullGlobalStatusManager; + return String.format("null-RequestSummaryData=%b; null-GridUser=%b; " + + "null-GlobalStatusManager=%b", nullRequestSummaryData, nullGridUser, + nullGlobalStatusManager); } } diff --git a/src/main/java/it/grid/storm/asynch/InvalidCopyAttributesException.java b/src/main/java/it/grid/storm/asynch/InvalidCopyAttributesException.java index a1b115c2..03b4d43b 100644 --- a/src/main/java/it/grid/storm/asynch/InvalidCopyAttributesException.java +++ b/src/main/java/it/grid/storm/asynch/InvalidCopyAttributesException.java @@ -55,14 +55,8 @@ public InvalidCopyAttributesException(GridUserInterface gu, @Override public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("InvalidCopyAttributesException [negativeN="); - builder.append(negativeN); - builder.append(", nullGu="); - builder.append(nullGu); - builder.append(", nullChunkData="); - builder.append(nullChunkData); - builder.append("]"); - return builder.toString(); + return String.format("InvalidCopyAttributesException [negativeN=%b, " + + "nullGu=%b, nullChunkData=%b]", negativeN, nullGu, nullChunkData); + } } diff --git a/src/main/java/it/grid/storm/asynch/InvalidCopyFeederAttributesException.java b/src/main/java/it/grid/storm/asynch/InvalidCopyFeederAttributesException.java index 5821810c..71982752 100644 --- a/src/main/java/it/grid/storm/asynch/InvalidCopyFeederAttributesException.java +++ b/src/main/java/it/grid/storm/asynch/InvalidCopyFeederAttributesException.java @@ -49,8 +49,8 @@ public InvalidCopyFeederAttributesException(RequestSummaryData rsd, public String toString() { - return "null-RequestSummaryData=" + nullRequestSummaryData - + "; null-GridUser=" + nullGridUser + "; null-GlobalStatusManager=" - + nullGlobalStatusManager; + return String.format("null-RequestSummaryData=%b; null-GridUser=%b; " + + "null-GlobalStatusManager=%b", nullRequestSummaryData, nullGridUser, + nullGlobalStatusManager); } } diff --git a/src/main/java/it/grid/storm/asynch/InvalidCopyPersistentChunkAttributesException.java b/src/main/java/it/grid/storm/asynch/InvalidCopyPersistentChunkAttributesException.java index fb915957..46131f6f 100644 --- a/src/main/java/it/grid/storm/asynch/InvalidCopyPersistentChunkAttributesException.java +++ b/src/main/java/it/grid/storm/asynch/InvalidCopyPersistentChunkAttributesException.java @@ -48,18 +48,8 @@ public InvalidCopyPersistentChunkAttributesException(GridUserInterface gu, @Override public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("InvalidCopyPersistentChunkAttributesException [nullrsd="); - builder.append(nullrsd); - builder.append(", nullgsm="); - builder.append(nullgsm); - builder.append(", negativeN="); - builder.append(negativeN); - builder.append(", nullGu="); - builder.append(nullGu); - builder.append(", nullChunkData="); - builder.append(nullChunkData); - builder.append("]"); - return builder.toString(); + return String.format("InvalidCopyPersistentChunkAttributesException " + + "[nullrsd=%b, nullgsm=%b, negativeN=%b, nullGu=%b, nullChunkData=%b]", + nullrsd, nullgsm, negativeN, nullGu, nullChunkData); } } diff --git a/src/main/java/it/grid/storm/asynch/InvalidPersistentRequestAttributesException.java b/src/main/java/it/grid/storm/asynch/InvalidPersistentRequestAttributesException.java index 99391c7d..b958b5dd 100644 --- a/src/main/java/it/grid/storm/asynch/InvalidPersistentRequestAttributesException.java +++ b/src/main/java/it/grid/storm/asynch/InvalidPersistentRequestAttributesException.java @@ -56,8 +56,8 @@ public InvalidPersistentRequestAttributesException(GridUserInterface gu, public String toString() { - return "Invalid attributes when creating Chunk: nullGridUser=" + nullGu - + ", nullRequestSumamryData=" + nullRsd + " , nullChunkData=" - + nullChunkData + " , nullGsm=" + nullGsm; + return String.format("Invalid attributes when creating Chunk: " + + "nullGridUser=%b, nullRequestSumamryData=%b, nullChunkData=%b, " + + "nullGsm=%b", nullGu, nullRsd, nullChunkData, nullGsm); } } diff --git a/src/main/java/it/grid/storm/asynch/InvalidPtGAttributesException.java b/src/main/java/it/grid/storm/asynch/InvalidPtGAttributesException.java index f9623dea..66b73b52 100644 --- a/src/main/java/it/grid/storm/asynch/InvalidPtGAttributesException.java +++ b/src/main/java/it/grid/storm/asynch/InvalidPtGAttributesException.java @@ -28,7 +28,7 @@ public InvalidPtGAttributesException(GridUserInterface gu, PtGData chunkData) { public String toString() { - return "Invalid attributes when creating PtG: null-GridUser=" + nullGu - + " null-PtGChunkData=" + nullChunkData; + return String.format("Invalid attributes when creating PtG: " + + "null-GridUser=%b, null-PtGChunkData=%b", nullGu, nullChunkData); } } diff --git a/src/main/java/it/grid/storm/asynch/InvalidPtGChunkAttributesException.java b/src/main/java/it/grid/storm/asynch/InvalidPtGChunkAttributesException.java index c23d27fe..7cdc1467 100644 --- a/src/main/java/it/grid/storm/asynch/InvalidPtGChunkAttributesException.java +++ b/src/main/java/it/grid/storm/asynch/InvalidPtGChunkAttributesException.java @@ -61,8 +61,9 @@ public InvalidPtGChunkAttributesException(GridUserInterface gu, public String toString() { - return "Invalid attributes when creating PtGChunk: null-GridUser=" + nullGu - + ", null-RequestSumamryData=" + nullRsd + " null-PtGChunkData=" - + nullChunkData + " null-GlobalStatusManager=" + nullGlobalStatusManager; + return String.format("Invalid attributes when creating PtGChunk: " + + "null-GridUser=%b, null-RequestSumamryData=%b, null-PtGChunkData=%b, " + + "null-GlobalStatusManager=%b", nullGu, nullRsd, nullChunkData, + nullGlobalStatusManager); } } diff --git a/src/main/java/it/grid/storm/asynch/InvalidPtGFeederAttributesException.java b/src/main/java/it/grid/storm/asynch/InvalidPtGFeederAttributesException.java index feef7e84..d6e02eb5 100644 --- a/src/main/java/it/grid/storm/asynch/InvalidPtGFeederAttributesException.java +++ b/src/main/java/it/grid/storm/asynch/InvalidPtGFeederAttributesException.java @@ -49,8 +49,8 @@ public InvalidPtGFeederAttributesException(RequestSummaryData rsd, public String toString() { - return "null-RequestSummaryData=" + nullRequestSummaryData - + "; null-GridUser=" + nullGridUser + "; null-GlobalStatusManagerr=" - + nullGlobalStatusManager; + return String.format("null-RequestSummaryData=%b; null-GridUser=%b; " + + "null-GlobalStatusManager=%b", nullRequestSummaryData, nullGridUser, + nullGlobalStatusManager); } } diff --git a/src/main/java/it/grid/storm/asynch/InvalidPtPFeederAttributesException.java b/src/main/java/it/grid/storm/asynch/InvalidPtPFeederAttributesException.java index 32430b42..bc56b8c8 100644 --- a/src/main/java/it/grid/storm/asynch/InvalidPtPFeederAttributesException.java +++ b/src/main/java/it/grid/storm/asynch/InvalidPtPFeederAttributesException.java @@ -48,8 +48,8 @@ public InvalidPtPFeederAttributesException(RequestSummaryData rsd, public String toString() { - return "null-RequestSummaryData=" + nullRequestSummaryData - + "; null-GridUser=" + nullGridUser + "; null-GlobalStatusManager=" - + nullGlobalStatusManager; + return String.format("null-RequestSummaryData=%b; null-GridUser=%b; " + + "null-GlobalStatusManager=%b", nullRequestSummaryData, nullGridUser, + nullGlobalStatusManager); } } diff --git a/src/main/java/it/grid/storm/asynch/InvalidPutStatusAttributesException.java b/src/main/java/it/grid/storm/asynch/InvalidPutStatusAttributesException.java index 348de870..1a65e3bc 100644 --- a/src/main/java/it/grid/storm/asynch/InvalidPutStatusAttributesException.java +++ b/src/main/java/it/grid/storm/asynch/InvalidPutStatusAttributesException.java @@ -48,7 +48,7 @@ public InvalidPutStatusAttributesException(TTURL toTURL, public String toString() { - return "nullToTURL=" + nullToTURL + "; nullReturnStatus=" - + nullReturnStatus; + return String.format("nullToTURL=%b; nullReturnStatus=%b", nullToTURL, + nullReturnStatus); } } diff --git a/src/main/java/it/grid/storm/asynch/InvalidRequestAttributesException.java b/src/main/java/it/grid/storm/asynch/InvalidRequestAttributesException.java index 59b89836..6c96f4cc 100644 --- a/src/main/java/it/grid/storm/asynch/InvalidRequestAttributesException.java +++ b/src/main/java/it/grid/storm/asynch/InvalidRequestAttributesException.java @@ -45,7 +45,7 @@ public InvalidRequestAttributesException(GridUserInterface gu, public String toString() { - return "Invalid attributes when creating Request: nullGridUser=" + nullGu - + " , nullChunkData=" + nullChunkData; + return String.format("Invalid attributes when creating Request: " + + "nullGridUser=%b, nullChunkData=%b", nullGu, nullChunkData); } } diff --git a/src/main/java/it/grid/storm/asynch/NaiveGridFTPTransferClient.java b/src/main/java/it/grid/storm/asynch/NaiveGridFTPTransferClient.java index f2261f93..7a45faef 100644 --- a/src/main/java/it/grid/storm/asynch/NaiveGridFTPTransferClient.java +++ b/src/main/java/it/grid/storm/asynch/NaiveGridFTPTransferClient.java @@ -95,7 +95,7 @@ public void putFile(GridUserInterface gu, TTURL local, TTURL remote) proxy), GSSCredential.INITIATE_AND_ACCEPT)); client.setType(Session.TYPE_IMAGE); FeatureList fl = client.getFeatureList(); - log.debug("NAIVE GSIFTP CLIENT: Remote server supports " + fl.toString()); + log.debug("NAIVE GSIFTP CLIENT: Remote server supports {}", fl.toString()); if (!fl.contains(FeatureList.DCAU)) { log.debug("NAIVE GSIFTP CLIENT: disabling DCAU"); client.setLocalNoDataChannelAuthentication(); // compatibility with old diff --git a/src/main/java/it/grid/storm/asynch/NaiveSRMClient.java b/src/main/java/it/grid/storm/asynch/NaiveSRMClient.java index 6d6d55b1..9466c6b6 100644 --- a/src/main/java/it/grid/storm/asynch/NaiveSRMClient.java +++ b/src/main/java/it/grid/storm/asynch/NaiveSRMClient.java @@ -90,8 +90,7 @@ public SRMPrepareToPutReply prepareToPut(GridUserInterface gu, TSURL toSURL, srmClientStubs.ISRM _srm = setUpGSI(gu, toSURL); // prepare srm request and execute it - srmClientStubs.SrmPrepareToPutRequest req = new srmClientStubs.SrmPrepareToPutRequest(); // srm - // request + srmClientStubs.SrmPrepareToPutRequest req = new srmClientStubs.SrmPrepareToPutRequest(); // set authorization ID String stubuid = gu.getDn(); req.setAuthorizationID(stubuid); @@ -123,10 +122,8 @@ public SRMPrepareToPutReply prepareToPut(GridUserInterface gu, TSURL toSURL, .intValue())); // set request specific info - srmClientStubs.TPutFileRequest stubpfr = new srmClientStubs.TPutFileRequest(); // ws - // put - // file - // request! + // ws put file request! + srmClientStubs.TPutFileRequest stubpfr = new srmClientStubs.TPutFileRequest(); // set file size org.apache.axis.types.UnsignedLong ulFileSize = new org.apache.axis.types.UnsignedLong( filesize.value()); @@ -134,23 +131,18 @@ public SRMPrepareToPutReply prepareToPut(GridUserInterface gu, TSURL toSURL, // set target SURL stubpfr.setTargetSURL(new org.apache.axis.types.URI(toSURL.toString())); - // set array of requests - srmClientStubs.TPutFileRequest[] stubpfrArray = new srmClientStubs.TPutFileRequest[1]; // ws - // array - // of - // put - // file - // request! + // set array of requests ws array of put file request! + srmClientStubs.TPutFileRequest[] stubpfrArray = new srmClientStubs.TPutFileRequest[1]; stubpfrArray[0] = stubpfr; srmClientStubs.ArrayOfTPutFileRequest arrayOfPut = new srmClientStubs.ArrayOfTPutFileRequest( stubpfrArray); req.setArrayOfFileRequests(arrayOfPut); // execute request! - log.debug("NAIVE SRM CLIENT: sending request " + arrayOfPut); + log.debug("NAIVE SRM CLIENT: sending request {}", arrayOfPut); srmClientStubs.SrmPrepareToPutResponse response = _srm .srmPrepareToPut(req); - log.debug("NAIVE SRM CLIENT: received reply " + response); + log.debug("NAIVE SRM CLIENT: received reply {}", response); // get TRequestToken it.grid.storm.srm.types.TRequestToken requestToken = new WSRequestTokenConverter() @@ -256,10 +248,10 @@ public SRMStatusOfPutRequestReply statusOfPutRequest( stubSurlArray); req.setArrayOfTargetSURLs(arrayOfTSURL); - log.debug("NAIVE SRM CLIENT: invoking status of put with " + req); + log.debug("NAIVE SRM CLIENT: invoking status of put with {}", req); srmClientStubs.SrmStatusOfPutRequestResponse response = _srm .srmStatusOfPutRequest(req); - log.debug("NAIVE SRM CLIENT: received response " + response); + log.debug("NAIVE SRM CLIENT: received response {}", response); // process response srmClientStubs.ArrayOfTPutRequestFileStatus arrayOfPutStatuses = response @@ -333,12 +325,6 @@ public SRMPutDoneReply srmPutDone(TRequestToken rt, GridUserInterface gu, TSURL toSURL) throws SRMClientException { return null; - /* - * try { return new SRMPutDoneReply(new - * it.grid.storm.srm.types.TReturnStatus - * (it.grid.storm.srm.types.TStatusCode.SRM_SUCCESS,"DUMMY SUCCESS")); } - * catch (Exception e) { throw new SRMClientException(); } - */ } /** @@ -364,86 +350,31 @@ private srmClientStubs.ISRM setUpGSI(GridUserInterface gu, // set proxy in stub if (((AbstractGridUser) gu).getUserCredentials() == null) { - log.error("ERROR in NaiveSRMClient! No proxy present for " + gu.getDn()); + log.error("ERROR in NaiveSRMClient! No proxy present for {}", gu.getDn()); } + // String containing the proxy seen as an input stream! InputStream proxy = new ByteArrayInputStream(((AbstractGridUser) gu) - .getUserCredentials().getBytes()); // String containing the proxy seen as - // an input stream! + .getUserCredentials().getBytes()); + // GSSCredential containing the proxy! GSSCredential globusProxy = new GlobusGSSCredentialImpl( - new GlobusCredential(proxy), GSSCredential.INITIATE_AND_ACCEPT); // GSSCredential - // containing - // the - // proxy! - ((Stub) _srm)._setProperty(GSIHTTPTransport.GSI_CREDENTIALS, globusProxy); // set - // the - // proxy - // to - // be - // used - // during - // GSI - // connection! + new GlobusCredential(proxy), GSSCredential.INITIATE_AND_ACCEPT); + // set the proxy to be used during GSI connection! + ((Stub) _srm)._setProperty(GSIHTTPTransport.GSI_CREDENTIALS, globusProxy); + // set the authorization that will be performed by the web service for the + // supplied credentails! ((Stub) _srm)._setProperty(GSIHTTPTransport.GSI_AUTHORIZATION, - NoAuthorization.getInstance()); // set the authorization that will be - // performed by the web service for the - // supplied credentails! + NoAuthorization.getInstance()); + // set the supply of both private and public key of credentials ((Stub) _srm)._setProperty(GSIHTTPTransport.GSI_MODE, - GSIHTTPTransport.GSI_MODE_NO_DELEG); // set the supply of both private and - // public key of credentials + GSIHTTPTransport.GSI_MODE_NO_DELEG); // set service endpoint address - String sea = "httpg://" + toSURL.sfn().machine() + ":" - + toSURL.sfn().port() + "/"; + String sea = String.format("httpg://%s:%s/", toSURL.sfn().machine(), toSURL + .sfn().port()); ((Stub) _srm)._setProperty(Stub.ENDPOINT_ADDRESS_PROPERTY, sea); // return the interface return _srm; } - /** - * Private method that returns a String representation of - * srmClientStubs.SrmPrepareToPutResponse - */ - /* - * private String - * srmPtPResponseToString(srmClientStubs.SrmPrepareToPutResponse response) { - * StringBuffer sb = new StringBuffer(); if (response==null) { - * sb.append("srmClientStubs.SrmPrepareToPutResponse is null!"); } else { - * sb.append("srmClientStubs.SrmPrepareToPutResponse:\n"); - * srmClientStubs.TRequestToken stubrt = response.getRequestToken(); if - * (stubrt==null) { sb.append("srmClientStubs.TRequestToken is null!\n"); } - * else { sb.append("srmClientStubs.TRequestToken is "); - * sb.append(stubrt.getValue()); sb.append("\n"); } - * srmClientStubs.TReturnStatus stubretstat = response.getReturnStatus(); if - * (stubretstat==null) { sb.append("srmClientStubs.TReturnStatus is null!\n"); - * } else { sb.append("srmClientStubs.TReturnStatus has "); - * srmClientStubs.TStatusCode stubstatcode = stubretstat.getStatusCode(); if - * (stubstatcode==null) { sb.append("TStatusCode=null and "); } else { - * sb.append("TStatusCode="); sb.append(stubstatcode.getValue()); - * sb.append(" and "); } String aux = stubretstat.getExplanation(); if - * (aux==null) { sb.append("explanationString=null"); } else { - * sb.append("explanationString="); sb.append(aux); } sb.append("\n"); } - * srmClientStubs.ArrayOfTPutRequestFileStatus stubaprfs = - * response.getArrayOfFileStatuses(); if (stubaprfs==null) { - * sb.append("srmClientStubs.ArrayOfTPutRequestFileStatus is null!\n"); } else - * { srmClientStubs.TPutRequestFileStatus[] stubprfs = - * stubaprfs.getPutStatusArray(); int arraysize = stubprfs.length; - * sb.append("srmClientStubs.ArrayOfTPutRequestFileStatus has "); - * sb.append(arraysize); sb.append(" elements\n"); - * srmClientStubs.TPutRequestFileStatus stubaux; srmClientStubs.TReturnStatus - * stubauxretstat; srmClientStubs.TStatusCode stubauxstatcode; String - * auxString; for (int i=0; i aclList = acl.getACL(); - for (ACLEntry ace : aclList) { - /* Re-Check if the ACE is yet valid */ - if (ace.isValid()) { - log.debug("Adding DefaultACL for the gid: " + ace.getGroupID() - + " with permission: " + ace.getFilePermissionString()); - LocalUser u = new LocalUser(ace.getGroupID(), ace.getGroupID()); - if (ace.getFilesystemPermission() == null) { - log - .warn("Unable to setting up the ACL. ACl entry permission is null!"); - } else { - try { - AclManagerFSAndHTTPS.getInstance().grantGroupPermission( - localFile, u, ace.getFilesystemPermission()); - - } catch (IllegalArgumentException e) { - log - .error("Unable to grant group permissions on the file. IllegalArgumentException: " - + e.getMessage()); - } - } - } + + if ((acl == null) || (acl.isEmpty())) { + log.debug("{} acl null or empty!", vfs.getAliasName()); + return; + } + + /* There are ACLs to set n file */ + List aclList = acl.getACL(); + for (ACLEntry ace : aclList) { + /* Re-Check if the ACE is yet valid */ + if (!ace.isValid()) { + log.debug("ACE {} is not valid!", ace.toString()); + continue; + } + log.debug("Adding DefaultACL for the gid: {} with permission: {}", + ace.getGroupID(), ace.getFilePermissionString()); + LocalUser u = new LocalUser(ace.getGroupID(), ace.getGroupID()); + if (ace.getFilesystemPermission() == null) { + log.warn("Unable to setting up the ACL. ACl entry permission is null!"); + continue; } + try { + AclManagerFSAndHTTPS.getInstance().grantGroupPermission(localFile, u, + ace.getFilesystemPermission()); + } catch (IllegalArgumentException e) { + log.error("Unable to grant group permissions on the file. " + + "IllegalArgumentException: {}", e.getMessage(), e); + } } } @@ -824,9 +807,8 @@ private boolean isStoriOndisk(StoRI storiFile) throws FSException { if (!storiFile.getVirtualFileSystem().getStorageClassType().isTapeEnabled()) { return true; - } else { - return storiFile.getLocalFile().isOnDisk(); } + return storiFile.getLocalFile().isOnDisk(); } /** @@ -852,47 +834,47 @@ public void choose(Streets s) { @Override public Boolean completeRequest(TapeRecallStatus recallStatus) { - Boolean success = false; - if (recallStatus == TapeRecallStatus.SUCCESS) { - try { - if (bupLocalFile.isOnDisk()) { - success = managePermitReadFileStep(bupFileStori, bupLocalFile, - bupLocalUser, bupTURL); - if (bupLocalUser != null) { - success = managePermitReadFileStep(bupFileStori, bupLocalFile, - bupLocalUser, bupTURL); - } else { - success = true; - setDefaultAcl(bupFileStori, bupLocalFile); - } - if (success) { - requestData.setTransferURL(bupTURL); - requestData - .changeStatusSRM_FILE_PINNED("srmPrepareToGet successfully handled!"); - } else { - requestData - .changeStatusSRM_FAILURE("Local filesystem mask does not allow" - + " setting up correct ACLs for PtG!"); - } - } else { - log.error("File " + bupLocalFile.getAbsolutePath() - + " not found on the disk, but it was reported to" - + " be successfully recalled from tape"); - requestData.changeStatusSRM_FAILURE("Error recalling file from tape"); - } - } catch (FSException e) { - log.error("Unable to determine if file " - + bupLocalFile.getAbsolutePath() + " is on disk . FSException : " - + e.getMessage()); - requestData - .changeStatusSRM_FAILURE("Internal error: unable to determine if the file is on disk"); - } + if (recallStatus.equals(TapeRecallStatus.ABORTED)) { + requestData.changeStatusSRM_ABORTED("Recalling file from tape aborted"); + return false; + } + if (!recallStatus.equals(TapeRecallStatus.SUCCESS)) { + requestData.changeStatusSRM_FAILURE("Error recalling file from tape"); + return false; + } + + Boolean isOnDisk = false; + try { + isOnDisk = bupLocalFile.isOnDisk(); + } catch (FSException e) { + log.error("Unable to determine if file {} is on disk. FSException: ", + bupLocalFile.getAbsolutePath(), e.getMessage(), e); + requestData.changeStatusSRM_FAILURE("Internal error: unable to determine " + + "if the file is on disk"); + return false; + } + if (!isOnDisk) { + log.error("File {} not found on the disk, but it was reported to be " + + "successfully recalled from tape", bupLocalFile.getAbsolutePath()); + requestData.changeStatusSRM_FAILURE("Error recalling file from tape"); + return false; + } + Boolean success = managePermitReadFileStep(bupFileStori, bupLocalFile, + bupLocalUser, bupTURL); + if (bupLocalUser != null) { + success = managePermitReadFileStep(bupFileStori, bupLocalFile, + bupLocalUser, bupTURL); } else { - if (recallStatus == TapeRecallStatus.ABORTED) { - requestData.changeStatusSRM_ABORTED("Recalling file from tape aborted"); - } else { - requestData.changeStatusSRM_FAILURE("Error recalling file from tape"); - } + success = true; + setDefaultAcl(bupFileStori, bupLocalFile); + } + if (success) { + requestData.setTransferURL(bupTURL); + requestData.changeStatusSRM_FILE_PINNED("srmPrepareToGet successfully " + + "handled!"); + } else { + requestData.changeStatusSRM_FAILURE("Local filesystem mask does not " + + "allow setting up correct ACLs for PtG!"); } return success; } @@ -926,13 +908,9 @@ public String getUserDN() { @Override public boolean isResultSuccess() { - boolean result = false; TStatusCode statusCode = requestData.getStatus().getStatusCode(); - if ((statusCode.getValue().equals(TStatusCode.SRM_FILE_PINNED.getValue())) - || requestData.getStatus().isSRM_SUCCESS()) { - result = true; - } - return result; + return ((statusCode.equals(TStatusCode.SRM_FILE_PINNED)) + || requestData.getStatus().isSRM_SUCCESS()); } /** @@ -940,10 +918,11 @@ public boolean isResultSuccess() { */ private void manageIsDeny() { - requestData.changeStatusSRM_AUTHORIZATION_FAILURE("Read access to " - + requestData.getSURL() + " denied!"); + String emsg = String.format("Read access to %s denied!", + requestData.getSURL()); + log.debug(emsg); + requestData.changeStatusSRM_AUTHORIZATION_FAILURE(emsg); failure = true; - log.debug("Read access to " + requestData.getSURL() + " denied!"); } /** @@ -956,10 +935,10 @@ private void manageIsIndeterminate(AuthzDecision ad) { requestData.changeStatusSRM_FAILURE("Failure in PolicySource prevented" + " PolicyCollector from establishing access rights! Processing failed!"); failure = true; - log - .error("ERROR in PtGChunk! PolicyCollector received an error from PolicySource!"); - log.error("Received state: " + ad); - log.error("Requested SURL: " + requestData.getSURL()); + log.error("ERROR in PtGChunk! PolicyCollector received an error from " + + "PolicySource!"); + log.error("Received state: {}", ad); + log.error("Requested SURL: {}", requestData.getSURL()); } /** @@ -969,14 +948,13 @@ private void manageIsIndeterminate(AuthzDecision ad) { */ private void manageIsNotApplicabale(AuthzDecision ad) { - requestData - .changeStatusSRM_FAILURE("No policies found for the requested SURL! " - + "Therefore access rights cannot be established! Processing cannot continue!"); + requestData.changeStatusSRM_FAILURE("No policies found for the requested " + + "SURL! Therefore access rights cannot be established! Processing cannot " + + "continue!"); failure = true; - log - .warn("PtGChunk: PolicyCollector found no policy for the supplied SURL!"); - log.warn("Received state: " + ad); - log.warn("Requested SURL: " + requestData.getSURL()); + log.warn("PtGChunk: PolicyCollector found no policy for the supplied SURL!"); + log.warn("Received state: {}", ad); + log.warn("Requested SURL: {}", requestData.getSURL()); } protected void printRequestOutcome(PtGData inputData) { diff --git a/src/main/java/it/grid/storm/asynch/PtGBuilder.java b/src/main/java/it/grid/storm/asynch/PtGBuilder.java index d5d9bd61..0e998847 100644 --- a/src/main/java/it/grid/storm/asynch/PtGBuilder.java +++ b/src/main/java/it/grid/storm/asynch/PtGBuilder.java @@ -60,13 +60,12 @@ public static PtG build(FileTransferInputData inputData) status = new TReturnStatus(TStatusCode.SRM_REQUEST_INPROGRESS, "Synchronous request created"); } catch (InvalidTReturnStatusAttributeException e) { - log - .error("Unable to build TReturnStatus. InvalidTReturnStatusAttributeException: " - + e.getMessage()); + log.error("Unable to build TReturnStatus. " + + "InvalidTReturnStatusAttributeException: {}", e.getMessage(), e); throw new BuilderException( "Error building PtG TReturnStatus. Building failed"); } - ; + TTURL transferURL = TTURL.makeEmpty(); PtGData data; try { @@ -80,21 +79,19 @@ public static PtG build(FileTransferInputData inputData) } data.store(); } catch (InvalidPtGDataAttributesException e) { - log - .error("Unable to build PtGChunkData. InvalidPtGChunkDataAttributesException: " - + e.getMessage()); + log.error("Unable to build PtGChunkData. " + + "InvalidPtGChunkDataAttributesException: {}", e.getMessage(), e); throw new BuilderException( "Error building PtG PtGChunkData. Building failed"); } catch (InvalidFileTransferDataAttributesException e) { - log - .error("Unable to build PtGChunkData. InvalidFileTransferChunkDataAttributesException: " - + e.getMessage()); + log.error("Unable to build PtGChunkData. " + + "InvalidFileTransferChunkDataAttributesException: {}", + e.getMessage(), e); throw new BuilderException( "Error building PtG PtGChunkData. Building failed"); } catch (InvalidSurlRequestDataAttributesException e) { - log - .error("Unable to build PtGChunkData. InvalidSurlRequestDataAttributesException: " - + e.getMessage()); + log.error("Unable to build PtGChunkData. " + + "InvalidSurlRequestDataAttributesException: {}", e.getMessage(), e); throw new BuilderException( "Error building PtG PtGChunkData. Building failed"); } diff --git a/src/main/java/it/grid/storm/asynch/PtGFeeder.java b/src/main/java/it/grid/storm/asynch/PtGFeeder.java index bdb97fcb..202c7463 100644 --- a/src/main/java/it/grid/storm/asynch/PtGFeeder.java +++ b/src/main/java/it/grid/storm/asynch/PtGFeeder.java @@ -127,9 +127,8 @@ public PtGFeeder(RequestSummaryData rsd) this.rsd = rsd; gsm = new GlobalStatusManager(rsd.requestToken()); } catch (InvalidOverallRequestAttributeException e) { - log - .error("ATTENTION in PtGFeeder! Programming bug when creating GlobalStatusManager! " - + e); + log.error("ATTENTION in PtGFeeder! Programming bug when creating " + + "GlobalStatusManager! {}", e.getMessage(), e); throw new InvalidPtGFeederAttributesException(rsd, null, null); } } @@ -141,19 +140,18 @@ public PtGFeeder(RequestSummaryData rsd) */ public void doIt() { - log.debug("PtGFeeder: pre-processing " + rsd.requestToken()); + log.debug("PtGFeeder: pre-processing {}", rsd.requestToken()); // Get all parts in request Collection chunks = PtGChunkCatalog.getInstance() .lookup(rsd.requestToken()); if (chunks.isEmpty()) { - log - .warn("ATTENTION in PtGFeeder! This SRM PtG request contained nothing to process! " - + rsd.requestToken()); + log.warn("ATTENTION in PtGFeeder! This SRM PtG request contained nothing " + + "to process! {}", rsd.requestToken()); RequestSummaryCatalog.getInstance().failRequest(rsd, "This SRM Get request contained nothing to process!"); } else { manageChunks(chunks); - log.debug("PtGFeeder: finished pre-processing " + rsd.requestToken()); + log.debug("PtGFeeder: finished pre-processing {}", rsd.requestToken()); } } @@ -163,7 +161,7 @@ public void doIt() { */ private void manageChunks(Collection chunks) { - log.debug("PtGFeeder - number of chunks in request: " + chunks.size()); + log.debug("PtGFeeder - number of chunks in request: {}", chunks.size()); for (PtGPersistentChunkData chunkData : chunks) { gsm.addChunk(chunkData); // add chunk for global status // consideration @@ -184,10 +182,10 @@ private void manageChunks(Collection chunks) { * fromSURL does _not_ correspond to this installation of StoRM: fail * chunk! */ - log.warn("PtGFeeder: srmPtG contract violation!" - + " fromSURL does not correspond to this machine!"); - log.warn("Request: " + rsd.requestToken()); - log.warn("Chunk: " + chunkData); + log.warn("PtGFeeder: srmPtG contract violation! fromSURL does not" + + "correspond to this machine!"); + log.warn("Request: {}", rsd.requestToken()); + log.warn("Chunk: {}", chunkData); chunkData.changeStatusSRM_FAILURE("SRM protocol violation!" + " Cannot do an srmPtG of a SURL that is not local!"); @@ -222,10 +220,10 @@ private void manageNotDirectory(PtGPersistentChunkData auxChunkData) { .schedule(new PtGPersistentChunk(rsd, auxChunkData, gsm)); log.debug("PtGFeeder - chunk scheduled."); } catch (InvalidPersistentRequestAttributesException e) { - log.error("UNEXPECTED ERROR in PtGFeeder! Chunk could not be created!\n" - + e); - log.error("Request: " + rsd.requestToken()); - log.error("Chunk: " + auxChunkData); + log.error("UNEXPECTED ERROR in PtGFeeder! Chunk could not be created!"); + log.error(e.getMessage(), e); + log.error("Request: {}", rsd.requestToken()); + log.error("Chunk: {}", auxChunkData); auxChunkData.changeStatusSRM_FAILURE("StoRM internal error does" + " not allow this chunk to be processed!"); @@ -233,10 +231,10 @@ private void manageNotDirectory(PtGPersistentChunkData auxChunkData) { PtGChunkCatalog.getInstance().update(auxChunkData); gsm.failedChunk(auxChunkData); } catch (InvalidRequestAttributesException e) { - log.error("UNEXPECTED ERROR in PtGFeeder! Chunk could not be created!\n" - + e); - log.error("Request: " + rsd.requestToken()); - log.error("Chunk: " + auxChunkData); + log.error("UNEXPECTED ERROR in PtGFeeder! Chunk could not be created!"); + log.error(e.getMessage(), e); + log.error("Request: {}", rsd.requestToken()); + log.error("Chunk: {}", auxChunkData); auxChunkData.changeStatusSRM_FAILURE("StoRM internal error does" + " not allow this chunk to be processed!"); @@ -245,10 +243,10 @@ private void manageNotDirectory(PtGPersistentChunkData auxChunkData) { gsm.failedChunk(auxChunkData); } catch (SchedulerException e) { /* Internal error of scheduler! */ - log.error("UNEXPECTED ERROR in ChunkScheduler! " - + "Chunk could not be scheduled!\n" + e); - log.error("Request: " + rsd.requestToken()); - log.error("Chunk: " + auxChunkData); + log.error("UNEXPECTED ERROR in ChunkScheduler! Chunk could not be scheduled!"); + log.error(e.getMessage(), e); + log.error("Request: {}", rsd.requestToken()); + log.error("Chunk: {}", auxChunkData); auxChunkData.changeStatusSRM_FAILURE("StoRM internal scheduler " + "error prevented this chunk from being processed!"); @@ -270,157 +268,149 @@ private void manageIsDirectory(PtGPersistentChunkData chunkData) { /* Change status of this chunk to being processed! */ chunkData.changeStatusSRM_REQUEST_INPROGRESS("srmPrepareToGet " + "chunk is being processed!"); + + TSURL surl = chunkData.getSURL(); + String user = DataHelper.getRequestor(chunkData); + /* update persistence!!! */ PtGChunkCatalog.getInstance().update(chunkData); + + /* Build StoRI for current chunk */ + StoRI stori = null; try { - /* Build StoRI for current chunk */ - StoRI stori = null; - try { - stori = NamespaceDirector.getNamespace().resolveStoRIbySURL( - chunkData.getSURL(), chunkData.getUser()); - } catch (IllegalArgumentException e) { - log.error("Unable to build StoRI by SURL and user", e); - chunkData.changeStatusSRM_INTERNAL_ERROR(e.getMessage()); - PtGChunkCatalog.getInstance().update(chunkData); - log.error("ATTENTION in PtGFeeder! PtGFeeder received " - + "request for a SURL and user not recognised by StoRI!"); // info - gsm.failedChunk(chunkData); - } catch (UnapprochableSurlException e) { - chunkData.changeStatusSRM_AUTHORIZATION_FAILURE(e.getMessage()); - PtGChunkCatalog.getInstance().update(chunkData); - log.info(String.format( - "Unable to build a stori for surl %s for user %s %s: %s", chunkData - .getSURL(), DataHelper.getRequestor(chunkData), e.getClass() - .getCanonicalName(), e.getMessage())); - gsm.failedChunk(chunkData); - } catch (NamespaceException e) { - chunkData.changeStatusSRM_INTERNAL_ERROR(e.getMessage()); + stori = NamespaceDirector.getNamespace().resolveStoRIbySURL(surl, + chunkData.getUser()); + } catch (IllegalArgumentException e) { + log.error("Unable to build a stori for surl {} for user {}. " + + "IllegalArgumentException: {}", surl, user, e.getMessage(), e); + chunkData.changeStatusSRM_INTERNAL_ERROR(e.getMessage()); + } catch (UnapprochableSurlException e) { + log.info("Unable to build a stori for surl {} for user {}. " + + "UnapprochableSurlException: {}", surl, user, e.getMessage()); + chunkData.changeStatusSRM_AUTHORIZATION_FAILURE(e.getMessage()); + } catch (NamespaceException e) { + log.error("Unable to build a stori for surl {} for user {}. " + + "NamespaceException: {}", surl, user, e.getMessage(), e); + chunkData.changeStatusSRM_INTERNAL_ERROR(e.getMessage()); + } catch (InvalidSURLException e) { + log.info("Unable to build a stori for surl {} for user {}. " + + "InvalidSURLException: {}", surl, user, e.getMessage()); + chunkData.changeStatusSRM_INVALID_PATH(e.getMessage()); + } finally { + if (stori == null) { + // failed! PtGChunkCatalog.getInstance().update(chunkData); - log.info(String.format( - "Unable to build a stori for surl %s for user %s %s: %s", chunkData - .getSURL(), DataHelper.getRequestor(chunkData), e.getClass() - .getCanonicalName(), e.getMessage())); - gsm.failedChunk(chunkData); - } catch (InvalidSURLException e) { - chunkData.changeStatusSRM_INVALID_PATH(e.getMessage()); - PtGChunkCatalog.getInstance().update(chunkData); - log.info(String.format( - "Unable to build a stori for surl %s for user %s %s: %s", chunkData - .getSURL(), DataHelper.getRequestor(chunkData), e.getClass() - .getCanonicalName(), e.getMessage())); gsm.failedChunk(chunkData); + return; } - if (stori != null) { - /* Collection of children! */ - // TODO MICHELE here if the recursion on directory is supported - // substiture the following withe the commented one - Collection storiChildren = stori.getChildren(chunkData - .getDirOption()); - - log.debug("PtGFeeder - Number of children in parent: " - + storiChildren.size()); - - // FIXME MICHELE why here we set the diroption in this way? maybe it - // is correct in this other way: - // new TDirOption(childStoRI.isDirectory() (this method doesn't - // exists), (childStoRI.isDirectory() ? auxChunkData.dirOption() : - // false).isAllLevelRecursive(), (childStoRI.isDirectory() ? - // auxChunkData.dirOption().getNumLevel() > 0 ? - // (auxChunkData.dirOption().getNumLevel()-1)) : 0 ) :0)); - TDirOption notDir = new TDirOption(false, false, 0); - - PtGPersistentChunkData childData; - for (StoRI storiChild : storiChildren) { - try { - childData = new PtGPersistentChunkData(chunkData.getUser(), - chunkData.getRequestToken(), storiChild.getSURL(), - chunkData.getPinLifeTime(), notDir, - chunkData.getTransferProtocols(), chunkData.getFileSize(), - chunkData.getStatus(), chunkData.getTransferURL()); - /* fill in new db row and set the PrimaryKey of ChildData! */ - PtGChunkCatalog.getInstance().addChild(childData); - log.debug("PtGFeeder - added child data: " + childData); - - /* add chunk for global status consideration */ - gsm.addChunk(childData); - /* manage chunk */ - manageNotDirectory(childData); - } catch (InvalidSurlRequestDataAttributesException e) { - log.error("ERROR in PtGFeeder! While expanding recursive request," - + " it was not possible to create a new PtGPersistentChunkData! " - + e); - } - } - log.debug("PtGFeeder - expansion completed."); - /* - * A request on a Directory is considered done whether there is somethig - * to expand or not! - */ - // FIXME MICHELE maybe here as in BOL we have to set the success status - // and not pinned - chunkData - .changeStatusSRM_FILE_PINNED("srmPrepareToGet with dirOption set: " - + "request successfully expanded!"); - PtGChunkCatalog.getInstance().update(chunkData); - gsm.successfulChunk(chunkData); - } - } catch (InvalidTDirOptionAttributesException e) { - // Could not create TDirOption that specifies no-expansion! - chunkData.changeStatusSRM_FAILURE("srmPrepareToGet with dirOption set:" - + " expansion failure due to internal error!"); - PtGChunkCatalog.getInstance().update(chunkData); - - log.error("UNEXPECTED ERROR in PtGFeeder! Could not" - + " create TDirOption specifying non-expansion!\n" + e); - log.error("Request: " + rsd.requestToken()); - log.error("Chunk: " + chunkData); - gsm.failedChunk(chunkData); + } + + Collection storiChildren = null; + + try { + + storiChildren = stori.getChildren(chunkData.getDirOption()); + } catch (InvalidDescendantsEmptyRequestException e) { + + log.debug("ATTENTION in PtGFeeder! PtGFeeder received request to expand " + + "empty directory."); /* * The expanded directory was empty, anyway a request on a Directory is * considered done whether there is somethig to expand or not! */ - chunkData - .changeStatusSRM_FILE_PINNED("BEWARE! srmPrepareToGet with dirOption" - + " set: it referred to a directory that was empty!"); + chunkData.changeStatusSRM_FILE_PINNED("BEWARE! srmPrepareToGet with " + + "dirOption set: it referred to a directory that was empty!"); PtGChunkCatalog.getInstance().update(chunkData); - - log.debug("ATTENTION in PtGFeeder! PtGFeeder received " - + "request to expand empty directory."); gsm.successfulChunk(chunkData); - } + return; - catch (InvalidDescendantsPathRequestException e) { - // Attempting to expand non existent directory! - chunkData - .changeStatusSRM_INVALID_PATH("srmPrepareToGet with dirOption set:" - + " it referred to a non-existent directory!"); - PtGChunkCatalog.getInstance().update(chunkData); - + } catch (InvalidDescendantsPathRequestException e) { + log.debug("ATTENTION in PtGFeeder! PtGFeeder received request" + " to expand non-existing directory."); + // Attempting to expand non existent directory! + chunkData.changeStatusSRM_INVALID_PATH("srmPrepareToGet with dirOption " + + "set: it referred to a non-existent directory!"); + PtGChunkCatalog.getInstance().update(chunkData); gsm.failedChunk(chunkData); + return; + } catch (InvalidDescendantsFileRequestException e) { + + log.debug("ATTENTION in PtGFeeder! PtGFeeder received request to " + + "expand a file."); // Attempting to expand a file! - chunkData - .changeStatusSRM_INVALID_PATH("srmPrepareToGet with dirOption set:" - + " a file was asked to be expanded!"); + chunkData.changeStatusSRM_INVALID_PATH("srmPrepareToGet with dirOption " + + "set: a file was asked to be expanded!"); PtGChunkCatalog.getInstance().update(chunkData); - - log - .debug("ATTENTION in PtGFeeder! PtGFeeder received request to expand a file."); gsm.failedChunk(chunkData); + return; + } catch (InvalidDescendantsAuthRequestException e) { + + log.debug("ATTENTION in PtGFeeder! PtGFeeder received request to" + + " expand a directory for which the user has no rights."); // No rights to directory! - chunkData - .changeStatusSRM_AUTHORIZATION_FAILURE("srmPrepareToGet with dirOption set:" - + " user has no right to access directory!"); + chunkData.changeStatusSRM_AUTHORIZATION_FAILURE("srmPrepareToGet with " + + "dirOption set: user has no right to access directory!"); PtGChunkCatalog.getInstance().update(chunkData); - - log.debug("ATTENTION in PtGFeeder! PtGFeeder received request to" - + " expand a directory for which the user has no rights."); // info gsm.failedChunk(chunkData); + return; } + + log.debug("PtGFeeder - Number of children in parent: {}", storiChildren.size()); + + TDirOption notDir = null; + + try { + + notDir = new TDirOption(false, false, 0); + + } catch (InvalidTDirOptionAttributesException e) { + + log.error("UNEXPECTED ERROR in PtGFeeder! Could not create TDirOption " + + "specifying non-expansion!\n{}\nRequest: {}\nChunk: {}", + e.getMessage(), rsd.requestToken(), chunkData, e); + + chunkData.changeStatusSRM_FAILURE("srmPrepareToGet with dirOption set:" + + " expansion failure due to internal error!"); + PtGChunkCatalog.getInstance().update(chunkData); + gsm.failedChunk(chunkData); + return; + } + + PtGPersistentChunkData childData; + for (StoRI storiChild : storiChildren) { + try { + childData = new PtGPersistentChunkData(chunkData.getUser(), + chunkData.getRequestToken(), storiChild.getSURL(), + chunkData.getPinLifeTime(), notDir, + chunkData.getTransferProtocols(), chunkData.getFileSize(), + chunkData.getStatus(), chunkData.getTransferURL()); + /* fill in new db row and set the PrimaryKey of ChildData! */ + PtGChunkCatalog.getInstance().addChild(childData); + log.debug("PtGFeeder - added child data: {}", childData); + + /* add chunk for global status consideration */ + gsm.addChunk(childData); + /* manage chunk */ + manageNotDirectory(childData); + } catch (InvalidSurlRequestDataAttributesException e) { + log.error("ERROR in PtGFeeder! While expanding recursive request," + + " it was not possible to create a new PtGPersistentChunkData! {}", + e.getMessage(), e); + } + } + log.debug("PtGFeeder - expansion completed."); + /* + * A request on a Directory is considered done whether there is something + * to expand or not! + */ + chunkData.changeStatusSRM_FILE_PINNED("srmPrepareToGet with dirOption " + + "set: request successfully expanded!"); + PtGChunkCatalog.getInstance().update(chunkData); + gsm.successfulChunk(chunkData); } /** diff --git a/src/main/java/it/grid/storm/asynch/PtGPersistentChunk.java b/src/main/java/it/grid/storm/asynch/PtGPersistentChunk.java index a1c34fcb..5a8b1283 100644 --- a/src/main/java/it/grid/storm/asynch/PtGPersistentChunk.java +++ b/src/main/java/it/grid/storm/asynch/PtGPersistentChunk.java @@ -134,18 +134,18 @@ public Boolean completeRequest(TapeRecallStatus recallStatus) { boolean success = super.completeRequest(recallStatus); persistStatus(); + if (success) { - + gsm.successfulChunk((PtGPersistentChunkData) requestData); - log.info("Completed PtG request (" + rsd.requestToken() - + "), file successfully recalled from tape: " - + requestData.getSURL().toString()); + log.info("Completed PtG request ({}), file successfully recalled from " + + "tape: {}", rsd.requestToken(), requestData.getSURL().toString()); + } else { + gsm.failedChunk((PtGPersistentChunkData) requestData); - log - .error("BoL request (" + rsd.requestToken() - + "), file not recalled from tape: " - + requestData.getSURL().toString()); + log.error("BoL request ({}), file not recalled from tape: {}", + rsd.requestToken(), requestData.getSURL().toString()); } return success; } @@ -170,13 +170,12 @@ public String getRequestToken() { @Override public boolean isResultSuccess() { - boolean result = false; if ((requestData.getStatus().getStatusCode() .equals(TStatusCode.SRM_FILE_PINNED)) || requestData.getStatus().isSRM_SUCCESS()) { - result = true; + return true; } - return result; + return false; } @Override diff --git a/src/main/java/it/grid/storm/asynch/PtP.java b/src/main/java/it/grid/storm/asynch/PtP.java index f5c4b8fd..ab9553b2 100644 --- a/src/main/java/it/grid/storm/asynch/PtP.java +++ b/src/main/java/it/grid/storm/asynch/PtP.java @@ -158,126 +158,103 @@ public PtP(PtPData chunkData) throws InvalidRequestAttributesException { @Override public void doIt() { - log.debug("Handling PtP chunk for user DN: " - + DataHelper.getRequestor(requestData) + "; for SURL: " - + requestData.getSURL()); - if (!verifySurlStatusTransition(requestData.getSURL(), - requestData.getRequestToken())) {// should return SRM_DUPLICATION_ERROR if - // file overwrite disabled instead of - // SRM_FILE_BUSY + String user = DataHelper.getRequestor(requestData); + TSURL surl = requestData.getSURL(); + TRequestToken rToken = requestData.getRequestToken(); + + log.debug("Handling PtP chunk for user DN: {}; for SURL: {}", user, surl); + + if (!verifySurlStatusTransition(surl, rToken)) { + // should return SRM_DUPLICATION_ERROR if file overwrite is disabled, + // instead of SRM_FILE_BUSY failure = true; - requestData.changeStatusSRM_FILE_BUSY("The surl " + requestData.getSURL() - + " is currently busy"); + requestData.changeStatusSRM_FILE_BUSY("The surl " + surl + " is currently busy"); log.info("Unable to perform the PTP request, surl busy"); printRequestOutcome(requestData); return; } + requestData.changeStatusSRM_REQUEST_INPROGRESS("request in progress"); + StoRI fileStoRI = null; - if (requestData instanceof IdentityInputData) { - try { - fileStoRI = NamespaceDirector.getNamespace().resolveStoRIbySURL( - requestData.getSURL(), ((IdentityInputData) requestData).getUser()); - } catch (UnapprochableSurlException e) { - requestData.changeStatusSRM_AUTHORIZATION_FAILURE(e.getMessage()); - log.info(String.format( - "Unable to build a stori for surl %s for user %s %s: %s", requestData - .getSURL(), DataHelper.getRequestor(requestData), e.getClass() - .getCanonicalName(), e.getMessage())); - printRequestOutcome(requestData); - return; - } catch (IllegalArgumentException e) { - requestData - .changeStatusSRM_INTERNAL_ERROR(e.getMessage()); - log.error("Unable to get StoRI for surl " + requestData.getSURL() - + " IllegalArgumentException: " + e.getMessage()); - printRequestOutcome(requestData); - return; - } catch (NamespaceException e) { - requestData.changeStatusSRM_INTERNAL_ERROR(e.getMessage()); - log.info(String.format( - "Unable to build a stori for surl %s for user %s %s: %s", requestData - .getSURL(), DataHelper.getRequestor(requestData), e.getClass() - .getCanonicalName(), e.getMessage())); - printRequestOutcome(requestData); - return; - } catch (InvalidSURLException e) { - requestData.changeStatusSRM_INVALID_PATH(e.getMessage()); - log.info(String.format( - "Unable to build a stori for surl %s for user %s %s: %s", requestData - .getSURL(), DataHelper.getRequestor(requestData), e.getClass() - .getCanonicalName(), e.getMessage())); - printRequestOutcome(requestData); - return; + + try { + + if (requestData instanceof IdentityInputData) { + fileStoRI = NamespaceDirector.getNamespace().resolveStoRIbySURL(surl, + ((IdentityInputData) requestData).getUser()); + } else { + fileStoRI = NamespaceDirector.getNamespace().resolveStoRIbySURL(surl); } - } else { - try { - fileStoRI = NamespaceDirector.getNamespace().resolveStoRIbySURL( - requestData.getSURL()); - } catch (UnapprochableSurlException e) { - log.info(String.format("Unable to build a stori for surl %s %s: %s", - requestData.getSURL(), e.getClass().getCanonicalName(), - e.getMessage())); - requestData.changeStatusSRM_AUTHORIZATION_FAILURE(e.getMessage()); - printRequestOutcome(requestData); - return; - } catch (IllegalArgumentException e) { - log.error(String.format("Unable to build a stori for surl %s %s: %s", - requestData.getSURL(), e.getClass().getCanonicalName(), - e.getMessage())); - requestData.changeStatusSRM_INTERNAL_ERROR(e.getMessage()); - printRequestOutcome(requestData); - return; - } catch (NamespaceException e) { - log.info(String.format("Unable to build a stori for surl %s %s: %s", - requestData.getSURL(), e.getClass().getCanonicalName(), - e.getMessage())); - requestData.changeStatusSRM_INTERNAL_ERROR(e.getMessage()); - printRequestOutcome(requestData); - return; - } catch (InvalidSURLException e) { - log.info(String.format("Unable to build a stori for surl %s %s: %s", - requestData.getSURL(), e.getClass().getCanonicalName(), - e.getMessage())); - requestData.changeStatusSRM_INVALID_PATH(e.getMessage()); + + } catch (UnapprochableSurlException e) { + log.info("Unable to build a stori for surl {} for user {}. " + + "UnapprochableSurlExceptions: {}", surl, user, e.getMessage()); + requestData.changeStatusSRM_AUTHORIZATION_FAILURE(e.getMessage()); + } catch (IllegalArgumentException e) { + log.error("Unable to build a stori for surl {} for user {}. " + + "IllegalArgumentException: {}", surl, user, e.getMessage(), e); + requestData.changeStatusSRM_INTERNAL_ERROR(e.getMessage()); + } catch (NamespaceException e) { + log.error("Unable to build a stori for surl {} for user {}. " + + "NamespaceException: {}", surl, user, e.getMessage(), e); + requestData.changeStatusSRM_INTERNAL_ERROR(e.getMessage()); + } catch (InvalidSURLException e) { + log.info("Unable to build a stori for surl {} for user {}. " + + "InvalidSURLException: {}", surl, user, e.getMessage()); + requestData.changeStatusSRM_INVALID_PATH(e.getMessage()); + } finally { + if (fileStoRI == null) { + // Failed! + failure = true; printRequestOutcome(requestData); return; } } + boolean exists = false; try { + exists = fileStoRI.getLocalFile().exists(); + } catch (SecurityException e) { - requestData - .changeStatusSRM_FAILURE("StoRM is not allowed to work on requested file!"); + log.error("ATTENTION in PtPChunk! PtPChunk received a SecurityException " + + "from Java SecurityManager: StoRM cannot check for the existence of " + + "file: {}; exception: {}", fileStoRI.getLocalFile().toString(), + e.getMessage(), e); failure = true; - log - .error("ATTENTION in PtPChunk! PtPChunk received a SecurityException from Java SecurityManager: StoRM cannot check for the existence of file: " - + fileStoRI.getLocalFile().toString() + "; exception: " + e); + requestData.changeStatusSRM_FAILURE("StoRM is not allowed to work on " + + "requested file!"); printRequestOutcome(requestData); return; } + if (!exists) { + manageNotExistentFile(fileStoRI); + } else { - if (requestData.overwriteOption() == TOverwriteMode.ALWAYS - || requestData.overwriteOption() == TOverwriteMode.WHENFILESAREDIFFERENT) { + + TOverwriteMode mode = requestData.overwriteOption(); + + if (mode.equals(TOverwriteMode.ALWAYS) || mode.equals(TOverwriteMode.WHENFILESAREDIFFERENT)) { + manageOverwriteExistingFile(fileStoRI); + + } else if (mode.equals(TOverwriteMode.NEVER)) { + + requestData.changeStatusSRM_DUPLICATION_ERROR("Cannot srmPut file " + + "because it already exists!"); + failure = true; + } else { - if (requestData.overwriteOption() == TOverwriteMode.NEVER) { - requestData - .changeStatusSRM_DUPLICATION_ERROR("Cannot srmPut file because it already exists!"); - failure = true; - } else { - // unexpected overwrite option!!! - requestData - .changeStatusSRM_FAILURE("Unexpected overwrite option! Processing failed!"); - failure = true; - log - .error("UNEXPECTED ERROR in PtPChunk! The specified overwrite option is unknown!"); - log.error("Received Overwrite Option: " - + requestData.overwriteOption()); - } + + log.error("UNEXPECTED ERROR in PtPChunk! The specified overwrite " + + "option '{}' is unknown!", mode); + requestData.changeStatusSRM_FAILURE("Unexpected overwrite option! " + + "Processing failed!"); + failure = true; + } } printRequestOutcome(requestData); @@ -353,8 +330,8 @@ private void manageOverwriteExistingFile(StoRI fileStoRI) { requestData.changeStatusSRM_AUTHORIZATION_FAILURE("Write access to " + requestData.getSURL() + " denied!"); failure = true; - log.debug("Write access to " + requestData.getSURL() + " for user " - + DataHelper.getRequestor(requestData) + " denied!"); + log.debug("Write access to {} for user {} denied!", + requestData.getSURL(), DataHelper.getRequestor(requestData)); } else { manageAnomaly(decision); } @@ -381,8 +358,8 @@ private void managePermit(StoRI fileStoRI) { .changeStatusSRM_AUTHORIZATION_FAILURE("Create/Write access for " + requestData.getSURL() + " in Storage Area: " + token + " denied!"); failure = true; - log.debug("Create/Write access for " + requestData.getSURL() - + " in Storage Area: " + token + " denied!"); + log.debug("Create/Write access for {} in Storage Area: {} denied!", + requestData.getSURL(), token); return; } TTURL auxTURL; @@ -391,23 +368,22 @@ private void managePermit(StoRI fileStoRI) { } catch (IllegalArgumentException e) { requestData.changeStatusSRM_FAILURE("Unable to decide TURL!"); failure = true; - log - .error("ERROR in PtPChunk! Null TURLPrefix in PtPChunkData caused StoRI to be unable to establish TTURL! IllegalArgumentException: " - + e); + log.error("ERROR in PtPChunk! Null TURLPrefix in PtPChunkData caused " + + "StoRI to be unable to establish TTURL! IllegalArgumentException: {}", + e.getMessage(), e); return; } catch (InvalidGetTURLProtocolException e) { - requestData - .changeStatusSRM_NOT_SUPPORTED("Unable to build TURL with specified transfer protocols!"); + requestData.changeStatusSRM_NOT_SUPPORTED("Unable to build TURL with " + + "specified transfer protocols!"); failure = true; log.error("ERROR in PtPChunk! No valid transfer protocol found."); return; } catch (TURLBuildingException e) { - requestData - .changeStatusSRM_FAILURE("Unable to build the TURL for the provided transfer protocol"); + requestData.changeStatusSRM_FAILURE("Unable to build the TURL for the " + + "provided transfer protocol"); failure = true; - log - .error("ERROR in PtPChunk! There was a failure building the TURL. : TURLBuildingException " - + e); + log.error("ERROR in PtPChunk! There was a failure building the TURL. " + + "TURLBuildingException: {} ", e.getMessage(), e); return; } boolean canTraverse; @@ -419,9 +395,9 @@ private void managePermit(StoRI fileStoRI) { requestData.changeStatusSRM_FAILURE("Unable to find local user for " + DataHelper.getRequestor(requestData)); failure = true; - log.error("ERROR in PtGChunk! Unable to find LocalUser for " - + DataHelper.getRequestor(requestData) + "! CannotMapUserException: " - + e.getMessage()); + log.error("ERROR in PtGChunk! Unable to find LocalUser for {}! " + + "CannotMapUserException: {}", DataHelper.getRequestor(requestData), + e.getMessage(), e); return; } if (canTraverse) { @@ -435,23 +411,22 @@ private void managePermit(StoRI fileStoRI) { requestData.changeStatusSRM_FAILURE("Unable to find local user for " + DataHelper.getRequestor(requestData)); failure = true; - log.error("ERROR in PtGChunk! Unable to find LocalUser for " - + DataHelper.getRequestor(requestData) - + "! CannotMapUserException: " + e.getMessage()); + log.error("ERROR in PtGChunk! Unable to find LocalUser for {}! " + + "CannotMapUserException: {}", DataHelper.getRequestor(requestData), + e.getMessage(), e); return; } if (!canWrite) { // URGENT!!! // roll back! ok3, ok2 and ok1 } else { - log - .debug("PTP CHUNK. Addition of ReadWrite ACL on file successfully completed for " - + fileStoRI.getAbsolutePath()); + log.debug("PTP CHUNK. Addition of ReadWrite ACL on file successfully " + + "completed for {}", fileStoRI.getAbsolutePath()); requestData.setTransferURL(auxTURL); - requestData - .changeStatusSRM_SPACE_AVAILABLE("srmPrepareToPut successfully handled!"); + requestData.changeStatusSRM_SPACE_AVAILABLE("srmPrepareToPut " + + "successfully handled!"); failure = false; - if (requestData.fileStorageType() == TFileStorageType.VOLATILE) { + if (requestData.fileStorageType().equals(TFileStorageType.VOLATILE)) { VolatileAndJiTCatalog.getInstance().trackVolatile( fileStoRI.getPFN(), Calendar.getInstance(), requestData.fileLifetime()); @@ -509,8 +484,8 @@ private boolean verifyPath(StoRI fileStoRI) { } requestData.changeStatusSRM_INVALID_PATH(errorString); failure = true; - log.debug(errorString + " Parent points to " - + parentStoRI.getLocalFile().toString() + "."); + log.debug("{} Parent points to {}.", errorString, + parentStoRI.getLocalFile().toString()); return false; } } @@ -519,17 +494,19 @@ private boolean verifyPath(StoRI fileStoRI) { private boolean setParentAcl(StoRI fileStoRI, LocalUser localUser) { - log.debug("PtPChunk: setting parent traverse ACL for " - + fileStoRI.getAbsolutePath() + " to user " + localUser); + log.debug("PtPChunk: setting parent traverse ACL for {} to user {}", + fileStoRI.getAbsolutePath(), localUser); + boolean automaticDirectoryCreation = Configuration.getInstance() .getAutomaticDirectoryCreation(); + for (StoRI parentStoRI : fileStoRI.getParents()) { LocalFile parentFile = parentStoRI.getLocalFile(); - log.debug("PtPChunk TraverseStep - processing parent " - + parentFile.toString()); + log.debug("PtPChunk TraverseStep - processing parent {}", + parentFile.toString()); if (!prepareDirectory(parentFile, automaticDirectoryCreation)) { - log.warn("Unable to perform directory preparation step on parent file " - + parentFile.getAbsolutePath()); + log.warn("Unable to perform directory preparation step on parent " + + "file {}", parentFile.getAbsolutePath()); failure = true; return false; } else { @@ -561,23 +538,21 @@ private boolean prepareDirectory(LocalFile f, boolean canCreate) throws SecurityException { if ((!f.exists()) && (!canCreate)) { - requestData - .changeStatusSRM_INVALID_PATH("Directory structure as specified in SURL does not exist!"); + requestData.changeStatusSRM_INVALID_PATH("Directory structure as " + + "specified in SURL does not exist!"); failure = true; - log - .debug("ATTENTION in PtPChunk! Directory structure as specified in " - + f - + " does not exist, and automatic directory creation is disbaled! Failing this chunk of request!"); // info + log.debug("ATTENTION in PtPChunk! Directory structure as specified " + + "in {} does not exist, and automatic directory creation is disbaled! " + + "Failing this chunk of request!", f); return false; } else { if (!f.exists()) { if (f.mkdirs()) { - requestData - .changeStatusSRM_INTERNAL_ERROR("Local filesystem error: could not crete directory!"); + requestData.changeStatusSRM_INTERNAL_ERROR("Local filesystem error: " + + "could not crete directory!"); failure = true; - log - .error("ERROR in PtPChunk! Filesystem was unable to successfully create directory: " - + f.toString()); + log.error("ERROR in PtPChunk! Filesystem was unable to successfully " + + "create directory: {}", f.toString()); return false; } } @@ -594,16 +569,15 @@ private boolean managePermitSetFileStep(StoRI fileStoRI) setDefaultAcl(fileStoRI); setTapeManagementAcl(fileStoRI); return true; - } else { - return false; - } - } else { - setDefaultAcl(fileStoRI); - setTapeManagementAcl(fileStoRI); - setHttpsServiceAcl(fileStoRI.getLocalFile(), - FilesystemPermission.ReadWrite); - return true; - } + } + return false; + } + + setDefaultAcl(fileStoRI); + setTapeManagementAcl(fileStoRI); + setHttpsServiceAcl(fileStoRI.getLocalFile(), + FilesystemPermission.ReadWrite); + return true; } /** @@ -614,8 +588,9 @@ private boolean managePermitSetFileStep(StoRI fileStoRI, LocalUser localUser) { // BEWARE THAT READ PERMISSION IS NEEDED BECAUSE GRID_FTP SERVER _ALSO_ // REQUIRES READ RIGHTS ELSE IT WON T BE ABLE TO WRITE THE FILE!!! - log.debug("PtPChunk: setting RW ACL for " + fileStoRI.getAbsolutePath() - + " for user " + localUser); + log.debug("PtPChunk: setting RW ACL for {} for user {}", + fileStoRI.getAbsolutePath(), localUser); + try { if (!setAcl(fileStoRI, localUser, FilesystemPermission.ReadWrite, fileStoRI.hasJustInTimeACLs())) { @@ -639,27 +614,26 @@ private boolean setAcl(StoRI parentStoRI, LocalUser localUser, if (hasJustInTimeACLs) { return setJiTAcl(parentStoRI, localUser, permission); - } else { - return setAoTAcl(parentStoRI, localUser, permission); - } + } + return setAoTAcl(parentStoRI, localUser, permission); } private boolean setJiTAcl(StoRI fileStori, LocalUser localUser, FilesystemPermission permission) throws Exception { - log.debug("SrmMkdir: Adding JiT ACL " + permission + " to user " - + localUser + " for directory : '" + fileStori.getAbsolutePath() + "'"); + log.debug("SrmMkdir: Adding JiT ACL {} to user {} for directory: '{}'", + permission, localUser, fileStori.getAbsolutePath()); + try { AclManagerFSAndHTTPS.getInstance().grantUserPermission( fileStori.getLocalFile(), localUser, permission); } catch (IllegalArgumentException e) { - log - .error("Unable to grant user traverse permission on parent file. IllegalArgumentException: " - + e.getMessage()); + log.error("Unable to grant user traverse permission on parent file. " + + "IllegalArgumentException: {}", e.getMessage(), e); return false; } + boolean response; - FilesystemPermission fp = fileStori.getLocalFile() .getEffectiveUserPermission(localUser); if (fp != null) { @@ -669,15 +643,14 @@ private boolean setJiTAcl(StoRI fileStori, LocalUser localUser, response = true; } else { log.error("ATTENTION in PtPChunk! The local filesystem has" - + " a mask that does not allow " + permission + " User-ACL to " - + "be set up on" + fileStori.getLocalFile().toString() + "!"); + + " a mask that does not allow {} User-ACL to be set up on!", + permission, fileStori.getLocalFile().toString()); response = false; } } else { - log.error("ERROR in PtPChunk! A " + permission + " User-ACL was set on " - + fileStori.getAbsolutePath() + " for user " + localUser.toString() - + " but when subsequently verifying its effectivity," - + " a null ACE was found!"); + log.error("ERROR in PtPChunk! A {} User-ACL was set on {} for user {} but " + + "when subsequently verifying its effectivity, a null ACE was found!", + permission, fileStori.getAbsolutePath(), localUser.toString()); throw new Exception("Unable to verify user ACL"); } return response; @@ -686,19 +659,19 @@ private boolean setJiTAcl(StoRI fileStori, LocalUser localUser, private boolean setAoTAcl(StoRI fileStori, LocalUser localUser, FilesystemPermission permission) throws Exception { - log.debug("SrmMkdir: Adding AoT ACL " + permission + " to user " - + localUser + " for directory : '" + fileStori.getAbsolutePath() + "'"); + log.debug("SrmMkdir: Adding AoT ACL {} to user {} for directory: '{}'", + permission, localUser, fileStori.getAbsolutePath()); + try { AclManagerFSAndHTTPS.getInstance().grantGroupPermission( fileStori.getLocalFile(), localUser, permission); } catch (IllegalArgumentException e) { - log - .error("Unable to grant user traverse permission on parent file. IllegalArgumentException: " - + e.getMessage()); + log.error("Unable to grant user traverse permission on parent file. " + + "IllegalArgumentException: {}", e.getMessage(), e); return false; } - boolean response; + boolean response; FilesystemPermission fp = fileStori.getLocalFile() .getEffectiveGroupPermission(localUser); if (fp != null) { @@ -706,15 +679,14 @@ private boolean setAoTAcl(StoRI fileStori, LocalUser localUser, response = true; } else { log.error("ATTENTION in PtPChunk! The local filesystem has a mask" - + " that does not allow Traverse Group-ACL to be set up on" - + fileStori.getLocalFile().toString() + "!"); + + " that does not allow Traverse Group-ACL to be set up on {}!", + fileStori.getLocalFile().toString()); response = false; } } else { - log.error("ERROR in PtPChunk! A Traverse Group-ACL was set on " - + fileStori.getAbsolutePath() + " for user " + localUser.toString() - + " but when subsequently verifying its effectivity, " - + "a null ACE was found!"); + log.error("ERROR in PtPChunk! A Traverse Group-ACL was set on {} for " + + "user {} but when subsequently verifying its effectivity, a null ACE " + + "was found!", fileStori.getAbsolutePath(), localUser.toString()); response = false; } return response; @@ -722,8 +694,8 @@ private boolean setAoTAcl(StoRI fileStori, LocalUser localUser, private void setHttpsServiceParentAcl(StoRI fileStoRI) { - log.debug("SrmMkdir: Adding parent https ACL for directory : '" - + fileStoRI.getAbsolutePath() + "' parents"); + log.debug("SrmMkdir: Adding parent https ACL for directory: '{}' parents", + fileStoRI.getAbsolutePath()); for (StoRI parentStoRI : fileStoRI.getParents()) { setHttpsServiceAcl(parentStoRI.getLocalFile(), FilesystemPermission.Traverse); @@ -733,15 +705,15 @@ private void setHttpsServiceParentAcl(StoRI fileStoRI) { private void setHttpsServiceAcl(LocalFile file, FilesystemPermission permission) { - log.debug("SrmMkdir: Adding https ACL " + permission + "for directory : '" - + file + "'"); + log.debug("SrmMkdir: Adding https ACL {} for directory : '{}'", + permission, file); + try { AclManagerFSAndHTTPS.getInstance().grantHttpsServiceGroupPermission(file, permission); } catch (IllegalArgumentException e) { - log - .error("Unable to grant user permission on the created folder. IllegalArgumentException: " - + e.getMessage()); + log.error("Unable to grant user permission on the created folder. " + + "IllegalArgumentException: {}", e.getMessage(), e); requestData.getStatus().extendExplaination( "Unable to grant group permission on the created folder"); } @@ -753,8 +725,8 @@ private void setHttpsServiceAcl(LocalFile file, */ private boolean managePermitReserveSpaceStep(StoRI fileStoRI) { - log.debug("PtPChunk: entered ReserveSpaceStep for " - + fileStoRI.getAbsolutePath()); + log.debug("PtPChunk: entered ReserveSpaceStep for {}", + fileStoRI.getAbsolutePath()); TSizeInBytes size = requestData.expectedFileSize(); TSpaceToken spaceToken = requestData.getSpaceToken(); LocalFile localFile = fileStoRI.getLocalFile(); @@ -778,10 +750,9 @@ private boolean managePermitReserveSpaceStep(StoRI fileStoRI) { */ TSpaceToken SASpaceToken = sp.getTokenFromStoRI(PtP.log, fileStoRI); if (SASpaceToken == null || SASpaceToken.isEmpty()) { - log - .error("PtPChunk - ReserveSpaceStep: Unable to get a valid TSpaceToken for stori " - + fileStoRI - + " . Unable to verify storage area space initialization"); + log.error("PtPChunk - ReserveSpaceStep: Unable to get a valid " + + "TSpaceToken for stori {} . Unable to verify storage area space " + + "initialization", fileStoRI); requestData .changeStatusSRM_FAILURE("No valid space token for the Storage Area"); failure = true; // gsm.failedChunk(chunkData); @@ -790,14 +761,12 @@ private boolean managePermitReserveSpaceStep(StoRI fileStoRI) { if (!sp.isSAInitialized(PtP.log, fileStoRI) && SpaceInfoManager.isInProgress(SASpaceToken)) { /* Trust we got space, let the request pass */ - log - .debug("PtPChunk: ReserveSpaceStep: the storage area space initialization is in progress, " - + "optimistic approach, considering we got enough space"); + log.debug("PtPChunk: ReserveSpaceStep: the storage area space " + + "initialization is in progress, optimistic approach, considering " + + "we got enough space"); } else { - log - .debug("PtPChunk - ReserveSpaceStep: no free space on Storage Area!"); - requestData - .changeStatusSRM_FAILURE("No free space on Storage Area"); + log.debug("PtPChunk - ReserveSpaceStep: no free space on Storage Area!"); + requestData.changeStatusSRM_FAILURE("No free space on Storage Area"); failure = true; return false; } @@ -809,78 +778,41 @@ private boolean managePermitReserveSpaceStep(StoRI fileStoRI) { // set space! boolean successful = localFile.createNewFile(); if ((!successful) - && (requestData.overwriteOption() == TOverwriteMode.NEVER)) { - // atomic operation of creation of file if non existent, failed: - // so the file - // did exist before. The Overwrite option was set to NEVER, so - // fail request! - // - // this test is done here, in case concurrent PtP chunks get - // executed at the - // same time: this is the _only_ place where the concurrent - // operation can be - // spotted without incurring in exceptionally tough - // syncronisation issues! - // - // File exists but Overwrite set to NEVER!!! - log - .debug("PtPChunk - ReserveSpaceStep: no overwrite allowed! Failing chunk... "); - requestData - .changeStatusSRM_DUPLICATION_ERROR("Cannot srmPut file because it already exists!"); - failure = true; // gsm.failedChunk(chunkData); + && (requestData.overwriteOption().equals(TOverwriteMode.NEVER))) { + + log.debug("PtPChunk - ReserveSpaceStep: no overwrite allowed! " + + "Failing chunk... "); + requestData.changeStatusSRM_DUPLICATION_ERROR("Cannot srmPut file " + + "because it already exists!"); + failure = true; return false; + } else if (!successful && TStatusCode.SRM_SPACE_AVAILABLE.equals(SurlStatusManager - .getSurlStatus(requestData.getSURL())))// PtPChunkCatalog.getInstance().isSRM_SPACE_AVAILABLE(requestData.getSURL())) - { - // atomic operation of creation of file if non existent, failed: - // so the file - // did exist before. A check in the catalogue shows that there - // is a past request - // which has the SURL in SRM_SPACE_AVAILABLE! So request must be - // failed with - // SRM_FILE_BUSY - // - // WARNING! Unfortunately although this test is done here, in - // case concurrent PtP - // chunks get executed at the same time, it is still NOT - // guaranteed that one of the - // two PtP will get an SRM_FILE_BUSY. - // - // The operation isSRM_SPACE_AVAILABLE _is_ atomic because that - // method is - // synchronised. But the couple createNewFile AND - // isSRM_FILE_BUSY - // is NOT atomic! Hence the inability to guarantee one of the - // two - // will get an SRM_FILE_BUSY. - // - // Putting the check here minimizes the chances, but cannot be - // eliminated - // altogether. - // - // fail request with SRM_FILE_BUSY - requestData - .changeStatusSRM_FILE_BUSY("Requested file is still in SRM_SPACE_AVAILABLE state!"); + .getSurlStatus(requestData.getSURL()))) { + + requestData.changeStatusSRM_FILE_BUSY("Requested file is still in " + + "SRM_SPACE_AVAILABLE state!"); failure = true; - log - .debug("ATTENTION in PtPChunk! PtPChunk received request for SURL that is still in SRM_SPACE_AVAILABLE state!"); + log.debug("ATTENTION in PtPChunk! PtPChunk received request for SURL " + + "that is still in SRM_SPACE_AVAILABLE state!"); return false; } else if ((spaceToken.isEmpty()) && (size.isEmpty())) { - log - .debug("PtPChunk - ReserveSpaceStep: no SpaceToken and no FileSize specified; mock file will be created... "); + log.debug("PtPChunk - ReserveSpaceStep: no SpaceToken and no FileSize " + + "specified; mock file will be created... "); } else if ((spaceToken.isEmpty()) && (!size.isEmpty())) { - log - .debug("PtPChunk - ReserveSpaceStep: no SpaceToken available but there is a FileSize specified; implicit space reservation taking place..."); + log.debug("PtPChunk - ReserveSpaceStep: no SpaceToken available but " + + "there is a FileSize specified; implicit space reservation " + + "taking place..."); fileStoRI.allotSpaceForFile(size); } else if ((!spaceToken.isEmpty()) && (!size.isEmpty())) { - log - .debug("PtPChunk - ReserveSpaceStep: SpaceToken available and FileSize specified; reserving space by token..."); + log.debug("PtPChunk - ReserveSpaceStep: SpaceToken available and " + + "FileSize specified; reserving space by token..."); if (!isExistingSpaceToken(spaceToken)) { - requestData - .changeStatusSRM_INVALID_REQUEST("The provided Space Token does not exists"); - log.info("PtPChunk execution failed. The space token " + spaceToken - + " provided by user does not exists"); + requestData.changeStatusSRM_INVALID_REQUEST("The provided Space Token " + + "does not exists"); + log.info("PtPChunk execution failed. The space token {} provided by " + + "user does not exists", spaceToken); return false; } else { fileStoRI.allotSpaceByToken(spaceToken, size); @@ -889,20 +821,20 @@ private boolean managePermitReserveSpaceStep(StoRI fileStoRI) { // spaceToken is NOT empty but size IS! // Use of EMPTY Space Size. That means total size of Storage // Space will be used!! - log - .debug("PtPChunk - ReserveSpaceStep: SpaceToken available and FileSize specified; reserving space by token..."); + log.debug("PtPChunk - ReserveSpaceStep: SpaceToken available and " + + "FileSize specified; reserving space by token..."); if (!isExistingSpaceToken(spaceToken)) { - requestData - .changeStatusSRM_INVALID_REQUEST("The provided Space Token does not exists"); - log.info("PtPChunk execution failed. The space token " + spaceToken - + " provided by user does not exists"); + requestData.changeStatusSRM_INVALID_REQUEST("The provided Space Token " + + "does not exists"); + log.info("PtPChunk execution failed. The space token {} provided by " + + "user does not exists", spaceToken); return false; } else { fileStoRI.allotSpaceByToken(spaceToken); } } - log.debug("PtPChunk: finished ReserveSpaceStep for " - + fileStoRI.getAbsolutePath()); + log.debug("PtPChunk: finished ReserveSpaceStep for {}", + fileStoRI.getAbsolutePath()); return true; } catch (SecurityException e) { // file.createNewFile could not create file because the Java @@ -911,72 +843,60 @@ private boolean managePermitReserveSpaceStep(StoRI fileStoRI) { // local system administrator // who applied a strict local policy, and policies as specified by // the PolicyCollector! - requestData - .changeStatusSRM_FAILURE("Space Management step in srmPrepareToPut failed!"); + requestData.changeStatusSRM_FAILURE("Space Management step in " + + "srmPrepareToPut failed!"); failure = true; - log - .error("ERROR in PtPChunk! During space reservation step in PtP, could not create file: " - + localFile.toString() - + "; Java s SecurityManager does not allow writing the file! " + e); + log.error("ERROR in PtPChunk! During space reservation step in PtP, " + + "could not create file: {}; Java s SecurityManager does not allow " + + "writing the file! ", localFile.toString(), e); return false; } catch (IOException e) { // file.createNewFile could not create file because of a local IO // Error! - requestData - .changeStatusSRM_FAILURE("Space Management step in srmPrepareToPut failed!"); + requestData.changeStatusSRM_FAILURE("Space Management step in " + + "srmPrepareToPut failed!"); failure = true; - log - .error("ERROR in PtPChunk! During space reservation step in PtP, an error occured while trying to create the file:" - + localFile.toString() + "; error: " + e); + log.error("ERROR in PtPChunk! During space reservation step in PtP, " + + "an error occured while trying to create the file: {}; error: {}", + localFile.toString(), e.getMessage(), e); return false; } catch (it.grid.storm.filesystem.InvalidPermissionOnFileException e) { // I haven t got the right to create a file as StoRM user! // This is thrown when executing createNewFile method! - requestData - .changeStatusSRM_FAILURE("Space Management step in srmPrepareToPut failed!"); + requestData.changeStatusSRM_FAILURE("Space Management step in " + + "srmPrepareToPut failed!"); failure = true; - log - .error("ERROR in PtPChunk! During space reservation step in PtP, an attempt to create file " - + localFile.toString() - + " failed because StoRM lacks the privileges to do so! Exception follows: " - + e); + log.error("ERROR in PtPChunk! During space reservation step in PtP, an " + + "attempt to create file {} failed because StoRM lacks the privileges " + + "to do so! Exception follows: {}", localFile.toString(), + e.getMessage(), e); return false; } catch (ReservationException e) { // Something went wrong while using space reservation component! - requestData - .changeStatusSRM_FAILURE("Space Management step in srmPrepareToPut failed!"); + requestData.changeStatusSRM_FAILURE("Space Management step in " + + "srmPrepareToPut failed!"); failure = true; - log - .error("ERROR in PtPChunk! Space component failed! Exception follows: " - + e); + log.error("ERROR in PtPChunk! Space component failed! Exception " + + "follows: {}", e.getMessage(), e); return false; } catch (ExpiredSpaceTokenException e) { // The supplied space token is expired - requestData - .changeStatusSRM_SPACE_LIFETIME_EXPIRED("The provided Space Token has expired its lifetime"); + requestData.changeStatusSRM_SPACE_LIFETIME_EXPIRED("The provided Space " + + "Token has expired its lifetime"); spacefailure = true; - log.info("PtPChunk execution failed. ExpiredSpaceTokenException : " - + e.getMessage()); + log.info("PtPChunk execution failed. ExpiredSpaceTokenException: {}", + e.getMessage()); return false; } catch (Exception e) { // This could be thrown by Java from Filesystem component given that - // there is GPFS under the hoods, - // but I do not know exactly how java.io.File behaves with an ACL - // capable filesystem!! - requestData - .changeStatusSRM_FAILURE("Space Management step in srmPrepareToPut failed!"); + // there is GPFS under the hoods, but I do not know exactly how + // java.io.File behaves with an ACL capable filesystem!! + requestData.changeStatusSRM_FAILURE("Space Management step in " + + "srmPrepareToPut failed!"); failure = true; - log - .error("ERROR in PtPChunk - space Step! Unexpected error in reserve space step of PtP for file " - + localFile.toString() + "! Exception follows: " + e); - log.error("Complete error stack trace follows: "); - StackTraceElement[] ste = e.getStackTrace(); - if (ste != null) { - for (StackTraceElement element : ste) { - log.error(element.toString()); - } - } - + log.error("ERROR in PtPChunk - space Step! Unexpected error in reserve " + + "space step of PtP for file {}! Exception follows: {}", + localFile.toString(), e.getMessage(), e); // ROOLBACK?? // The file already exists!!! return false; @@ -989,18 +909,15 @@ private boolean isExistingSpaceToken(TSpaceToken spaceToken) throws Exception { try { spaceData = new ReservedSpaceCatalog().getStorageSpace(spaceToken); } catch (TransferObjectDecodingException e) { - log - .error("Unable to build StorageSpaceData from StorageSpaceTO. TransferObjectDecodingException: " - + e.getMessage()); - throw new Exception( - "Error retrieving Storage Area information from Token. TransferObjectDecodingException : " - + e.getMessage()); + log.error("Unable to build StorageSpaceData from StorageSpaceTO." + + " TransferObjectDecodingException: {}", e.getMessage()); + throw new Exception("Error retrieving Storage Area information from Token." + + " TransferObjectDecodingException: " + e.getMessage()); } catch (DataAccessException e) { - log.error("Unable to build get StorageSpaceTO. DataAccessException: " - + e.getMessage()); - throw new Exception( - "Error retrieving Storage Area information from Token. DataAccessException : " - + e.getMessage()); + log.error("Unable to build get StorageSpaceTO. DataAccessException: {}", + e.getMessage()); + throw new Exception("Error retrieving Storage Area information from Token." + + " DataAccessException: " + e.getMessage()); } return spaceData != null; } @@ -1012,25 +929,23 @@ private void setDefaultAcl(StoRI fileStoRI) { if (dacl != null && !dacl.isEmpty()) { for (ACLEntry ace : dacl.getACL()) { if (ace.isValid()) { - log.debug("Adding DefaultACL for the gid: " + ace.getGroupID() - + " with permission: " + ace.getFilePermissionString()); + log.debug("Adding DefaultACL for the gid: {} with permission: {}", + ace.getGroupID(), ace.getFilePermissionString()); LocalUser u = new LocalUser(ace.getGroupID(), ace.getGroupID()); if (ace.getFilesystemPermission() == null) { - log - .warn("Unable to setting up the ACL. ACl entry permission is null!"); + log.warn("Unable to setting up the ACL. ACl entry permission " + + "is null!"); } else { try { AclManagerFSAndHTTPS.getInstance().grantGroupPermission( fileStoRI.getLocalFile(), u, ace.getFilesystemPermission()); } catch (IllegalArgumentException e) { - log - .error("Unable to grant group permission on the file. IllegalArgumentException: " - + e.getMessage()); + log.error("Unable to grant group permission on the file. " + + "IllegalArgumentException: {}", e.getMessage(), e); } } } } - } } @@ -1060,8 +975,8 @@ private void manageDeny() { requestData.changeStatusSRM_AUTHORIZATION_FAILURE("Create/Write access to " + requestData.getSURL() + " denied!"); failure = true; - log.debug("Create/Write access to " + requestData.getSURL() + " for user " - + DataHelper.getRequestor(requestData) + " denied!"); // info + log.debug("Create/Write access to {}, for user {} denied!", + requestData.getSURL(), DataHelper.getRequestor(requestData)); } /** @@ -1083,9 +998,9 @@ private void manageAnomaly(AuthzDecision decision) { requestData .changeStatusSRM_FAILURE("Missing Policy! Access rights cannot be established!"); failure = true; - log - .error("PtPChunk: PolicyCollector warned of missing policies for the supplied SURL!"); - log.error("Requested SURL: " + requestData.getSURL()); + log.error("PtPChunk: PolicyCollector warned of missing policies for the " + + "supplied SURL!"); + log.error("Requested SURL: {}", requestData.getSURL()); break; case INDETERMINATE: // PolicyCollector error @@ -1093,7 +1008,7 @@ private void manageAnomaly(AuthzDecision decision) { .changeStatusSRM_FAILURE("PolicyCollector error! Access rights cannot be established!"); failure = true; log.error("PtPChunk: PolicyCollector encountered internal problems!"); - log.error("Requested SURL: " + requestData.getSURL()); + log.error("Requested SURL: {}", requestData.getSURL()); break; default: // Unexpected policy! @@ -1102,7 +1017,7 @@ private void manageAnomaly(AuthzDecision decision) { failure = true; log .error("PtPChunk: unexpected policy returned by PolicyCollector for the supplied SURL!"); - log.error("Requested SURL: " + requestData.getSURL()); + log.error("Requested SURL: {}", requestData.getSURL()); break; } } diff --git a/src/main/java/it/grid/storm/asynch/PtPBuilder.java b/src/main/java/it/grid/storm/asynch/PtPBuilder.java index bf9154be..f2382b9b 100644 --- a/src/main/java/it/grid/storm/asynch/PtPBuilder.java +++ b/src/main/java/it/grid/storm/asynch/PtPBuilder.java @@ -66,9 +66,8 @@ public static PtP build(PrepareToPutInputData inputData) status = new TReturnStatus(TStatusCode.SRM_REQUEST_QUEUED, "Synchronous request created"); } catch (InvalidTReturnStatusAttributeException e) { - log - .error("Unable to build TReturnStatus. InvalidTReturnStatusAttributeException: " - + e.getMessage()); + log.error("Unable to build TReturnStatus. " + + "InvalidTReturnStatusAttributeException: {}", e.getMessage()); throw new BuilderException( "Error building PtP TReturnStatus. Building failed"); } @@ -88,29 +87,26 @@ public static PtP build(PrepareToPutInputData inputData) } data.store(); } catch (InvalidPtPDataAttributesException e) { - log - .error("Unable to build PtPChunkData. InvalidPtPChunkDataAttributesException: " - + e.getMessage()); + log.error("Unable to build PtPChunkData. " + + "InvalidPtPChunkDataAttributesException: {}", e.getMessage()); throw new BuilderException( "Error building PtP PtPChunkData. Building failed"); } catch (InvalidFileTransferDataAttributesException e) { - log - .error("Unable to build PtPChunkData. InvalidFileTransferChunkDataAttributesException: " - + e.getMessage()); + log.error("Unable to build PtPChunkData. " + + "InvalidFileTransferChunkDataAttributesException: {}", e.getMessage()); throw new BuilderException( "Error building PtP PtPChunkData. Building failed"); } catch (InvalidSurlRequestDataAttributesException e) { - log - .error("Unable to build PtPChunkData. InvalidSurlRequestDataAttributesException: " - + e.getMessage()); + log.error("Unable to build PtPChunkData. " + + "InvalidSurlRequestDataAttributesException: ", e.getMessage()); throw new BuilderException( "Error building PtP PtPChunkData. Building failed"); } try { return new PtP(data); } catch (InvalidRequestAttributesException e) { - log.error("Unable to build PtP. InvalidRequestAttributesException: " - + e.getMessage()); + log.error("Unable to build PtP. " + + "InvalidRequestAttributesException: {}", e.getMessage()); throw new BuilderException("Error building PtP. Building failed"); } } diff --git a/src/main/java/it/grid/storm/asynch/PtPFeeder.java b/src/main/java/it/grid/storm/asynch/PtPFeeder.java index a94a70e9..fcaf5eeb 100644 --- a/src/main/java/it/grid/storm/asynch/PtPFeeder.java +++ b/src/main/java/it/grid/storm/asynch/PtPFeeder.java @@ -83,9 +83,8 @@ public PtPFeeder(RequestSummaryData rsd) this.rsd = rsd; gsm = new GlobalStatusManager(rsd.requestToken()); } catch (InvalidOverallRequestAttributeException e) { - log - .error("ATTENTION in PtPFeeder! Programming bug when creating GlobalStatusManager! " - + e); + log.error("ATTENTION in PtPFeeder! Programming bug when creating " + + "GlobalStatusManager! {}", e.getMessage()); throw new InvalidPtPFeederAttributesException(rsd, gu, null); } } @@ -96,19 +95,18 @@ public PtPFeeder(RequestSummaryData rsd) */ public void doIt() { - log.debug("PtPFeeder: pre-processing " + rsd.requestToken()); + log.debug("PtPFeeder: pre-processing {}", rsd.requestToken()); /* Get all parts in request */ Collection chunks = PtPChunkCatalog.getInstance() .lookup(rsd.requestToken()); if (chunks.isEmpty()) { - log - .warn("ATTENTION in PtPFeeder! This SRM put request contained nothing to process! " - + rsd.requestToken()); + log.warn("ATTENTION in PtPFeeder! This SRM put request contained nothing " + + "to process! {}", rsd.requestToken()); RequestSummaryCatalog.getInstance().failRequest(rsd, "This SRM put request contained nothing to process!"); } else { manageChunks(chunks); - log.debug("PtPFeeder: finished pre-processing " + rsd.requestToken()); + log.debug("PtPFeeder: finished pre-processing {}", rsd.requestToken()); } } @@ -120,7 +118,7 @@ public void doIt() { */ private void manageChunks(Collection chunksData) { - log.debug("PtPFeeder: number of chunks in request " + chunksData.size()); + log.debug("PtPFeeder: number of chunks in request {}", chunksData.size()); /* chunk currently being processed */ for (PtPPersistentChunkData chunkData : chunksData) { /* add chunk for global status consideration */ @@ -134,8 +132,8 @@ private void manageChunks(Collection chunksData) { */ log.warn("PtPFeeder: srmPtP contract violation! toSURL" + " does not refer to this machine!"); - log.warn("Request: " + rsd.requestToken()); - log.warn("Chunk: " + chunkData); + log.warn("Request: {}", rsd.requestToken()); + log.warn("Chunk: {}", chunkData); chunkData.changeStatusSRM_FAILURE("SRM protocol violation!" + " Cannot do an srmPtP of a SURL that is not local!"); @@ -171,7 +169,8 @@ private void manage(PtPPersistentChunkData auxChunkData) { .schedule(new PtPPersistentChunk(rsd, auxChunkData, gsm)); log.debug("PtPFeeder - chunk scheduled."); } catch (IllegalArgumentException e) { - log.error("Unable to schedule the chunk. IllegalArgumentException: " + e); + log.error("Unable to schedule the chunk. IllegalArgumentException: {}", + e.getMessage(), e); auxChunkData.changeStatusSRM_FAILURE("StoRM internal error" + " does not allow this chunk to be processed!"); @@ -179,19 +178,18 @@ private void manage(PtPPersistentChunkData auxChunkData) { PtPChunkCatalog.getInstance().update(auxChunkData); gsm.failedChunk(auxChunkData); } catch (InvalidRequestAttributesException e) { - log.error("UNEXPECTED ERROR in PtPFeeder! Chunk could not be created!\n" - + e); + log.error("UNEXPECTED ERROR in PtPFeeder! Chunk could not be " + + "created!\n{}", e.getMessage(), e); - auxChunkData.changeStatusSRM_FAILURE("StoRM internal error" - + " does not allow this chunk to be processed!"); + auxChunkData.changeStatusSRM_FAILURE("StoRM internal error does not " + + "allow this chunk to be processed!"); PtPChunkCatalog.getInstance().update(auxChunkData); gsm.failedChunk(auxChunkData); } catch (SchedulerException e) { /* Internal error of scheduler! */ - log - .error("UNEXPECTED ERROR in ChunkScheduler! Chunk could not be scheduled!\n" - + e); + log.error("UNEXPECTED ERROR in ChunkScheduler! Chunk could not be " + + "scheduled!\n{}", e.getMessage(), e); auxChunkData.changeStatusSRM_FAILURE("StoRM internal scheduler " + "error prevented this chunk from being processed!"); diff --git a/src/main/java/it/grid/storm/asynch/PtPPersistentChunk.java b/src/main/java/it/grid/storm/asynch/PtPPersistentChunk.java index 629beeba..9fddbc2d 100644 --- a/src/main/java/it/grid/storm/asynch/PtPPersistentChunk.java +++ b/src/main/java/it/grid/storm/asynch/PtPPersistentChunk.java @@ -89,16 +89,16 @@ public String getRequestToken() { @Override public void persistStatus() { - PtPPersistentChunk.log.debug("Persisting status of request : " - + rsd.requestToken() + " on SURL " + this.requestData.getSURL()); + PtPPersistentChunk.log.debug("Persisting status of request: {} on SURL {}", + rsd.requestToken(), requestData.getSURL()); PtPChunkCatalog.getInstance().update((PtPPersistentChunkData) requestData); } @Override public void updateGlobalStatus() { - PtPPersistentChunk.log.debug("Updating global status for request : " - + rsd.requestToken() + " on SURL " + this.requestData.getSURL()); + PtPPersistentChunk.log.debug("Updating global status for request: {} on " + + "SURL ", rsd.requestToken(), requestData.getSURL()); if (failure) { gsm.failedChunk((PtPPersistentChunkData) requestData); } else { diff --git a/src/main/java/it/grid/storm/asynch/PushCopyGetVisitor.java b/src/main/java/it/grid/storm/asynch/PushCopyGetVisitor.java index a250b7d6..c3ffca7c 100644 --- a/src/main/java/it/grid/storm/asynch/PushCopyGetVisitor.java +++ b/src/main/java/it/grid/storm/asynch/PushCopyGetVisitor.java @@ -77,9 +77,8 @@ public Copy.Result visit(VisitableCopy copy) { parameters.add(4, copy.getLocalrt()); return copy.buildOperationResult(parameters, ResultType.GET); } catch (Exception e) { - copy.getLog().error( - "ERROR IN PushCopyChunk! Cannot initiate local PtG! Requested SURL: " - + copy.getRequestData().getSURL()); + copy.getLog().error("ERROR IN PushCopyChunk! Cannot initiate local PtG! " + + "Requested SURL: {}", copy.getRequestData().getSURL()); copy.getLog().error(e.getMessage(), e); return copy.buildOperationResult("Cannot initiate local PtG! " + e, ResultType.GET); diff --git a/src/main/java/it/grid/storm/asynch/PushCopyPutVisitor.java b/src/main/java/it/grid/storm/asynch/PushCopyPutVisitor.java index 8fd33837..b2ed73b2 100644 --- a/src/main/java/it/grid/storm/asynch/PushCopyPutVisitor.java +++ b/src/main/java/it/grid/storm/asynch/PushCopyPutVisitor.java @@ -46,7 +46,7 @@ public Result visit(VisitableCopy copy) { .getRequestData().getSpaceToken(), getFileSize, TransferProtocol.GSIFTP, "StoRM Remote PtP for (push) srmCopy", copy .getRequestData().getOverwriteOption(), retryTime); - copy.getLog().debug("... got it! Reply was: " + reply); + copy.getLog().debug("... got it! Reply was: {}", reply); // Polling... long timeOut = new Date().getTime() + Configuration.getInstance().getSRMClientPutTimeOut() * 1000; @@ -69,20 +69,17 @@ public Result visit(VisitableCopy copy) { .getDestinationSURL()); replyCode = statusOfPutRequestReply.returnStatus().getStatusCode(); timedOut = (new Date().getTime() > timeOut); - copy.getLog().debug( - "PUSH COPY CHUNK: reply was " + statusOfPutRequestReply - + "; the reply code was: " + replyCode + "; timedOut is:" - + timedOut); + copy.getLog().debug("PUSH COPY CHUNK: reply was {}; the reply code " + + "was: {}; timedOut is: {}", statusOfPutRequestReply, replyCode, + timedOut); } while (((replyCode == TStatusCode.SRM_REQUEST_QUEUED) - || (replyCode == TStatusCode.SRM_REQUEST_INPROGRESS) || (replyCode == TStatusCode.SRM_INTERNAL_ERROR)) + || (replyCode == TStatusCode.SRM_REQUEST_INPROGRESS) + || (replyCode == TStatusCode.SRM_INTERNAL_ERROR)) && !timedOut); } catch (SRMClientException e2) { // The SRMClient statusOfPutRequest functionality failed! - copy - .getLog() - .error( - "ERROR IN PushCopyChunk! PutOperation failed: SRMClient could not do an srmStatusOfPutRequest! " - + e2); + copy.getLog().error("ERROR IN PushCopyChunk! PutOperation failed: " + + "SRMClient could not do an srmStatusOfPutRequest! {}", e2); StringBuffer sb = new StringBuffer(); sb.append("Parameters passed to client: "); sb.append("requestToken: "); @@ -109,9 +106,8 @@ public Result visit(VisitableCopy copy) { ResultType.PUT); } // The remote operation completed!!! - copy.getLog().debug( - "PushCopyChunk! The PutOperation completed! " - + statusOfPutRequestReply.returnStatus()); + copy.getLog().debug("PushCopyChunk! The PutOperation completed! {}", + statusOfPutRequestReply.returnStatus()); ArrayList parameters = new ArrayList(3); parameters.add(1, statusOfPutRequestReply.returnStatus()); parameters.add(2, statusOfPutRequestReply.toTURL()); @@ -119,11 +115,8 @@ public Result visit(VisitableCopy copy) { return copy.buildOperationResult(parameters, ResultType.PUT); } catch (SRMClientException e1) { // The SRMClient prepareToPut functionality failed! - copy - .getLog() - .error( - "ERROR IN PushCopyChunk! PutOperation failed: SRMClient could not do an srmPrepareToPut! " - + e1); + copy.getLog().error("ERROR IN PushCopyChunk! PutOperation failed: " + + "SRMClient could not do an srmPrepareToPut! {}", e1); StringBuffer sb = new StringBuffer(); sb.append("Parameters passed to client: "); sb.append("GridUser:"); @@ -161,11 +154,8 @@ public Result visit(VisitableCopy copy) { "SRMClient failure! Could not do an srmPrepareToPut! " + e1, ResultType.PUT); } catch (NoSRMClientFoundException e1) { - copy - .getLog() - .error( - "ERROR IN PushCopyChunk! Cannot call remote SRM server because no SRM client could be loaded! " - + e1, ResultType.PUT); + copy.getLog().error("ERROR IN PushCopyChunk! Cannot call remote SRM " + + "server because no SRM client could be loaded! {}", e1, ResultType.PUT); return copy .buildOperationResult( "Cannot talk to other SRM server because no SRM client could be loaded!", @@ -174,8 +164,8 @@ public Result visit(VisitableCopy copy) { } catch (IllegalArgumentException e3) { // Cannot create TLifeTimeInSeconds! This is a programming bug and should // not occur!!! - copy.getLog().error( - "ERROR IN PushCopyChunk! Cannot create TLifeTimeInSeconds! " + e3); + copy.getLog().error("ERROR IN PushCopyChunk! Cannot create " + + "TLifeTimeInSeconds! {}", e3.getMessage(), e3); return copy.buildOperationResult(e3.toString(), ResultType.PUT); } } diff --git a/src/main/java/it/grid/storm/asynch/PushCopyTransferVisitor.java b/src/main/java/it/grid/storm/asynch/PushCopyTransferVisitor.java index a443aa13..f6c42ecc 100644 --- a/src/main/java/it/grid/storm/asynch/PushCopyTransferVisitor.java +++ b/src/main/java/it/grid/storm/asynch/PushCopyTransferVisitor.java @@ -98,17 +98,13 @@ public Result visit(VisitableCopy copy) { .getRequestData().getDestinationSURL()); replyCode = reply.overallRetStat().getStatusCode(); timedOut = (new Date().getTime() > timeOut); - copy.getLog().debug( - "PUSH COPY CHUNK: reply was " + reply + "; the reply code was: " - + replyCode + "; timedOut is:" + timedOut); + copy.getLog().debug("PUSH COPY CHUNK: reply was {}; the reply code " + + "was: {}; timedOut is: {}", reply, replyCode, timedOut); } while ((replyCode == TStatusCode.SRM_INTERNAL_ERROR) && !timedOut); } catch (SRMClientException e2) { // The SRMClient putDone functionality failed! - copy - .getLog() - .error( - "File transfer completed successfully, but problems were encountered performing final srmPutDone! " - + e2); + copy.getLog().error("File transfer completed successfully, but problems " + + "were encountered performing final srmPutDone! {}", e2); StringBuffer sb = new StringBuffer(); sb.append("Parameters passed to client: "); sb.append(", "); @@ -139,24 +135,19 @@ public Result visit(VisitableCopy copy) { return copy.buildOperationResult(new ArrayList(0), ResultType.TRANSFER); } catch (NoSRMClientFoundException e) { - copy - .getLog() - .error( - "ERROR IN PushCopyChunk! TransferOperation could not invoke srmPutDone on remote SRM server because no SRM client could be loaded! " - + e); + copy.getLog().error("ERROR IN PushCopyChunk! TransferOperation could not " + + "invoke srmPutDone on remote SRM server because no SRM client could " + + "be loaded! {}", e); return copy .buildOperationResult( "TransferOperation could not invoke srmPutDone on remote SRM server because no SRM client could be loaded!", ResultType.TRANSFER); } catch (GridFTPTransferClientException e) { - copy.getLog().error("ERROR IN PushCopyChunk! File transfer failed! " + e); + copy.getLog().error("ERROR IN PushCopyChunk! File transfer failed! {}", e); return copy.buildOperationResult(e.toString(), ResultType.TRANSFER); } catch (NoGridFTPTransferClientFoundException e) { - copy - .getLog() - .error( - "ERROR IN PushCopyChunk! Cannot transfer file because no transfer client could be loaded! " - + e); + copy.getLog().error("ERROR IN PushCopyChunk! Cannot transfer file because " + + "no transfer client could be loaded! {}", e); return copy.buildOperationResult( "Cannot transfer file because no transfer client could be loaded!", ResultType.TRANSFER); diff --git a/src/main/java/it/grid/storm/asynch/SRM22Client.java b/src/main/java/it/grid/storm/asynch/SRM22Client.java index 40088167..f3b05805 100644 --- a/src/main/java/it/grid/storm/asynch/SRM22Client.java +++ b/src/main/java/it/grid/storm/asynch/SRM22Client.java @@ -100,52 +100,48 @@ public SRMPrepareToPutReply prepareToPut(GridUserInterface gu, TSURL toSURL, srmClientStubs.SrmPrepareToPutRequest req = new srmClientStubs.SrmPrepareToPutRequest(); // srm // request // set description - log.debug("NAIVE SRM CLIENT; setting description to: " + description); + log.debug("NAIVE SRM CLIENT; setting description to: {}", description); req.setUserRequestDescription(description); // set array of transfer protocols String[] protocolArray = new String[1]; protocolArray[0] = protocol.toString(); - log - .debug("NAIVE SRM CLIENT; setting protocol array to: " + protocolArray); + log.debug("NAIVE SRM CLIENT; setting protocol array to: {}", (Object[]) protocolArray); srmClientStubs.ArrayOfString protocolArrayString = new srmClientStubs.ArrayOfString(); protocolArrayString.setStringArray(protocolArray); srmClientStubs.TTransferParameters stubtp = new srmClientStubs.TTransferParameters(); stubtp.setArrayOfTransferProtocols(protocolArrayString); req.setTransferParameters(stubtp); // set Overwrite Option - log.debug("NAIVE SRM CLIENT; setting overwrite option to: " - + overwriteOption); + log.debug("NAIVE SRM CLIENT; setting overwrite option to: {}", overwriteOption); req.setOverwriteOption(new WSOverwriteModeConverter() .fromStoRM(overwriteOption)); // set retry time Integer dtrt = new Integer(new Long(retryTime.value()).intValue()); - log - .debug("NAIVE SRM CLIENT; setting desired total request time: " + dtrt); + log.debug("NAIVE SRM CLIENT; setting desired total request time: {}", dtrt); req.setDesiredTotalRequestTime(dtrt); // set storage type srmClientStubs.TFileStorageType stubfst = new WSFileStorageTypeConverter() .fromStoRM(fileStorageType); // ws file storage type! - log.debug("NAIVE SRM CLIENT; setting file storage type to: " - + fileStorageType); + log.debug("NAIVE SRM CLIENT; setting file storage type to: {}", fileStorageType); req.setDesiredFileStorageType(stubfst); // set space token if (!spaceToken.isEmpty()) { String st = spaceToken.toString(); - log.debug("NAIVE SRM CLIENT; setting space token to: " + st); + log.debug("NAIVE SRM CLIENT; setting space token to: {}", st); req.setTargetSpaceToken(st); } else { log.debug("NAIVE SRM CLIENT; setting space token to null. "); } // set lifetime Integer dflt = new Integer(new Long(lifetime.value()).intValue()); - log.debug("NAIVE SRM CLIENT; setting desired file life time to: " + dflt); + log.debug("NAIVE SRM CLIENT; setting desired file life time to: {}", dflt); req.setDesiredFileLifeTime(dflt); // set pinLifetime Integer dplt = new Integer(Configuration.getInstance() .getSRM22ClientPinLifeTime()); - log.debug("NAIVE SRM CLIENT; setting desired pin life time to: " + dplt); + log.debug("NAIVE SRM CLIENT; setting desired pin life time to: {}", dplt); req.setDesiredPinLifeTime(dplt); // set request specific info @@ -155,7 +151,7 @@ public SRMPrepareToPutReply prepareToPut(GridUserInterface gu, TSURL toSURL, // request! // set file size long efs = filesize.value(); - log.debug("NAIVE SRM CLIENT; setting expected file size to: " + efs); + log.debug("NAIVE SRM CLIENT; setting expected file size to: {}", efs); // FIXME here we can have -1, that means the absence of information about // filesize. manage this case considering the following method! org.apache.axis.types.UnsignedLong ulFileSize = new org.apache.axis.types.UnsignedLong( @@ -163,7 +159,7 @@ public SRMPrepareToPutReply prepareToPut(GridUserInterface gu, TSURL toSURL, stubpfr.setExpectedFileSize(ulFileSize); // set target SURL String ts = toSURL.toString(); - log.debug("NAIVE SRM CLIENT; setting target SURL to: " + ts); + log.debug("NAIVE SRM CLIENT; setting target SURL to: {}", ts); stubpfr.setTargetSURL(new org.apache.axis.types.URI(ts)); // set array of requests @@ -179,10 +175,10 @@ public SRMPrepareToPutReply prepareToPut(GridUserInterface gu, TSURL toSURL, req.setArrayOfFileRequests(arrayOfPut); // execute request! - log.debug("NAIVE SRM CLIENT: sending request " + arrayOfPut); + log.debug("NAIVE SRM CLIENT: sending request {}", arrayOfPut); srmClientStubs.SrmPrepareToPutResponse response = _srm .srmPrepareToPut(req); - log.debug("NAIVE SRM CLIENT: received reply " + response); + log.debug("NAIVE SRM CLIENT: received reply {}", response); // get overall request status if (response == null) { @@ -307,10 +303,10 @@ public SRMStatusOfPutRequestReply statusOfPutRequest(TRequestToken rt, req.setArrayOfTargetSURLs(arrayOfTSURL); // execute request - log.debug("NAIVE SRM CLIENT: invoking status of put with " + req); + log.debug("NAIVE SRM CLIENT: invoking status of put with {}", req); srmClientStubs.SrmStatusOfPutRequestResponse response = _srm .srmStatusOfPutRequest(req); - log.debug("NAIVE SRM CLIENT: received response " + response); + log.debug("NAIVE SRM CLIENT: received response {}", response); // get overall request status if (response == null) { @@ -442,9 +438,9 @@ public SRMPutDoneReply srmPutDone(TRequestToken rt, GridUserInterface gu, req.setArrayOfSURLs(arrayOfTSURL); // execute request - log.debug("NAIVE SRM CLIENT: invoking srmPutDone with " + req); + log.debug("NAIVE SRM CLIENT: invoking srmPutDone with {}", req); srmClientStubs.SrmPutDoneResponse response = _srm.srmPutDone(req); - log.debug("NAIVE SRM CLIENT: received response " + response); + log.debug("NAIVE SRM CLIENT: received response {}", response); // get overall request status if (response == null) { @@ -579,7 +575,7 @@ private ISRM setUpGSI(GridUserInterface gu, TSURL toSURL) // set proxy in stub if (((AbstractGridUser) gu).getUserCredentials() == null) { - log.error("ERROR in NaiveSRMClient! No proxy present for " + gu.getDn()); + log.error("ERROR in NaiveSRMClient! No proxy present for {}", gu.getDn()); } InputStream proxy = new ByteArrayInputStream(((AbstractGridUser) gu) .getUserCredentials().getBytes()); // String containing the proxy seen as diff --git a/src/main/java/it/grid/storm/asynch/ThirdPartGridFTPTransferClient.java b/src/main/java/it/grid/storm/asynch/ThirdPartGridFTPTransferClient.java index 7c033817..04c57979 100644 --- a/src/main/java/it/grid/storm/asynch/ThirdPartGridFTPTransferClient.java +++ b/src/main/java/it/grid/storm/asynch/ThirdPartGridFTPTransferClient.java @@ -98,8 +98,8 @@ public void putFile(GridUserInterface gu, TTURL source, TTURL destination) String fullSourceFile = "/" + source.tfn().pfn().getValue(); String fullDestinationFile = "/" + destination.tfn().pfn().getValue(); - log.debug("source file: " + fullSourceFile); - log.debug("destin file: " + fullDestinationFile); + log.debug("source file: {}", fullSourceFile); + log.debug("destin file: {}", fullDestinationFile); // Smart implementation of Marker Listener MarkerListenerImpl listener = new MarkerListenerImpl(); @@ -115,8 +115,7 @@ public void putFile(GridUserInterface gu, TTURL source, TTURL destination) // Set up of remote Source GridFTP String remoteSourceHost = source.tfn().machine().getValue(); int remoteSourcePort = source.tfn().port().toInt(); - log.debug("remote source GridFTP : " + remoteSourceHost + ":" - + remoteSourcePort); + log.debug("remote source GridFTP {}:{}", remoteSourceHost, remoteSourcePort); GridFTPClient sourceClient = new GridFTPClient(remoteSourceHost, remoteSourcePort); setParams(sourceClient, cred); @@ -124,8 +123,8 @@ public void putFile(GridUserInterface gu, TTURL source, TTURL destination) // Set up of remote Destination GridFTP String remoteDestinationHost = destination.tfn().machine().getValue(); int remoteDestinationPort = destination.tfn().port().toInt(); - log.debug("remote destination GridFTP : " + remoteDestinationHost + ":" - + remoteDestinationPort); + log.debug("remote destination GridFTP: {}:{}", remoteDestinationHost, + remoteDestinationPort); GridFTPClient destClient = new GridFTPClient(remoteDestinationHost, remoteDestinationPort); setParams(destClient, cred); @@ -134,7 +133,7 @@ public void putFile(GridUserInterface gu, TTURL source, TTURL destination) // org.globus.ftp.test.gridftp.parallelism=6 int parallelism = 6; sourceClient.setOptions(new RetrieveOptions(parallelism)); - log.debug(" Transfer parallelism : " + parallelism); + log.debug(" Transfer parallelism: {}", parallelism); // Execute the transfer log.debug(" Starting transfer ... "); @@ -221,19 +220,19 @@ private void restartMarkerArrived(GridFTPRestartMarker marker) { log.info("--> restart marker arrived:"); list.merge(marker.toVector()); - log.info("Current transfer state: " + list.toFtpCmdArgument()); + log.info("Current transfer state: {}", list.toFtpCmdArgument()); } private void perfMarkerArrived(PerfMarker marker) { log.info("--> perf marker arrived"); // time stamp - log.info("Timestamp = " + marker.getTimeStamp()); + log.info("Timestamp = {}", marker.getTimeStamp()); // stripe index if (marker.hasStripeIndex()) { try { - log.info("Stripe index =" + marker.getStripeIndex()); + log.info("Stripe index = {}", marker.getStripeIndex()); } catch (PerfMarkerException e) { log.warn(e.toString()); } @@ -244,8 +243,7 @@ private void perfMarkerArrived(PerfMarker marker) { // stripe bytes transferred if (marker.hasStripeBytesTransferred()) { try { - log.info("Stripe bytes transferred = " - + marker.getStripeBytesTransferred()); + log.info("Stripe bytes transferred = {}", marker.getStripeBytesTransferred()); } catch (PerfMarkerException e) { log.warn(e.toString()); } @@ -256,7 +254,7 @@ private void perfMarkerArrived(PerfMarker marker) { // total stripe count if (marker.hasTotalStripeCount()) { try { - log.info("Total stripe count = " + marker.getTotalStripeCount()); + log.info("Total stripe count = {}", marker.getTotalStripeCount()); } catch (PerfMarkerException e) { log.warn(e.toString()); } diff --git a/src/main/java/it/grid/storm/asynch/WSRequestTokenConverter.java b/src/main/java/it/grid/storm/asynch/WSRequestTokenConverter.java index 6ae08242..6f73f122 100644 --- a/src/main/java/it/grid/storm/asynch/WSRequestTokenConverter.java +++ b/src/main/java/it/grid/storm/asynch/WSRequestTokenConverter.java @@ -67,9 +67,8 @@ public it.grid.storm.srm.types.TRequestToken fromWS(String stub) return new it.grid.storm.srm.types.TRequestToken(auxString, Calendar .getInstance().getTime()); } catch (InvalidTRequestTokenAttributesException e) { - log - .debug("Unexpected error in WSRequestTokenConverter! This is a programming bug! Could not translate TRequestToken from WS! " - + e); + log.debug("Unexpected error in WSRequestTokenConverter! This is a " + + "programming bug! Could not translate TRequestToken from WS! {}", e); throw new WSConversionException(e.toString()); } } diff --git a/src/main/java/it/grid/storm/asynch/WSTurlConverter.java b/src/main/java/it/grid/storm/asynch/WSTurlConverter.java index 06f927ce..79e45122 100644 --- a/src/main/java/it/grid/storm/asynch/WSTurlConverter.java +++ b/src/main/java/it/grid/storm/asynch/WSTurlConverter.java @@ -65,9 +65,8 @@ public it.grid.storm.srm.types.TTURL fromWS(org.apache.axis.types.URI auxURI) } return it.grid.storm.srm.types.TTURL.makeFromString(auxString); } catch (InvalidTTURLAttributesException e) { - log - .debug("Unexpected error in WSTurlConverter! This is a programming bug! Could not translate TTURL from WS! " - + e); + log.debug("Unexpected error in WSTurlConverter! This is a programming " + + "bug! Could not translate TTURL from WS! {}", e); throw new WSConversionException(e.toString()); } } From 6e929aa3988c9650d6cf55a75f475d6022fe521f Mon Sep 17 00:00:00 2001 From: dandreotti Date: Tue, 4 Feb 2014 16:03:03 +0000 Subject: [PATCH 17/45] Fix for https://issues.infn.it/jira/browse/STOR-524 --- .../it/grid/storm/xmlrpc/XMLRPCExecutor.java | 21 ++++++------ .../grid/storm/xmlrpc/XmlRpcTokenFilter.java | 6 ++-- .../xmlrpc/converter/ConveterFactory.java | 2 +- .../datatransfer/AbortFilesConverter.java | 6 ++-- .../datatransfer/AbortRequestConverter.java | 6 ++-- .../ExtendFileLifeTimeConverter.java | 10 +++--- .../FileTransferRequestInputConverter.java | 32 ++++++++----------- .../ManageFileTransferRequestConverter.java | 8 ++--- .../PrepareToGetRequestConverter.java | 6 ++-- .../PrepareToPutRequestConverter.java | 14 ++++---- .../datatransfer/PutDoneConverter.java | 6 ++-- .../converter/directory/LsConverter.java | 22 ++++++------- .../converter/directory/MkdirConverter.java | 10 +++--- .../converter/directory/MvConverter.java | 12 +++---- .../converter/directory/RmConverter.java | 8 ++--- .../converter/directory/RmdirConverter.java | 10 +++--- .../space/GetSpaceTokensConverter.java | 2 +- .../space/ReleaseSpaceConverter.java | 8 ++--- .../space/ReserveSpaceConverter.java | 8 ++--- 19 files changed, 95 insertions(+), 102 deletions(-) diff --git a/src/main/java/it/grid/storm/xmlrpc/XMLRPCExecutor.java b/src/main/java/it/grid/storm/xmlrpc/XMLRPCExecutor.java index 7e48a9b1..0d3dcfa7 100644 --- a/src/main/java/it/grid/storm/xmlrpc/XMLRPCExecutor.java +++ b/src/main/java/it/grid/storm/xmlrpc/XMLRPCExecutor.java @@ -65,31 +65,30 @@ public Map execute(OperationType type, Map inputParam) long startTime = System.currentTimeMillis(); long duration = System.nanoTime(); - log.debug("Executing a \'" + type.toString() + "\'" + "Call"); - log.debug(" Structure size : " + inputParam.size()); + log.debug("Executing a '{}' call" , type.toString()); + log.debug(" Structure size : {}" , inputParam.size()); Converter converter = ConveterFactory.getConverter(type); SynchcallDispatcher dispatcher = SynchcallDispatcherFactory.getDispatcher(); - log.debug("Converting input data with Converter " - + converter.getClass().getName()); + log.debug("Converting input data with Converter {}", converter.getClass().getName()); InputData inputData = converter.convertToInputData(inputParam); - log.debug("Dispatching request using SynchcallDispatcher " - + dispatcher.getClass().getName()); + log.debug("Dispatching request using SynchcallDispatcher {}" + , dispatcher.getClass().getName()); OutputData outputData; try { outputData = dispatcher.processRequest(type, inputData); } catch (IllegalArgumentException e) { log - .error("Unable to process the request. Error from the SynchcallDispatcher. IllegalArgumentException: " - + e.getMessage()); + .error("Unable to process the request. Error from the SynchcallDispatcher. IllegalArgumentException: {}" + , e.getMessage(),e); throw new StoRMXmlRpcException( "Unable to process the request. IllegalArgumentException: " + e.getMessage()); } catch (CommandException e) { log - .error("Unable to execute the request. Error from the SynchcallDispatcher. CommandException: " - + e.getMessage()); + .error("Unable to execute the request. Error from the SynchcallDispatcher. CommandException: {}" + , e.getMessage(),e); throw new StoRMXmlRpcException( "Unable to process the request. CommandException: " + e.getMessage()); } @@ -113,7 +112,7 @@ private void logExecution(it.grid.storm.health.OperationType opType, LogEvent event = new LogEvent(opType, dn, startTime, duration, successResult); if (!(bookKeepers.isEmpty())) { - log.debug("Found # " + bookKeepers.size() + "bookeepers."); + log.debug("Found # {} bookeepers." , bookKeepers.size()); for (int i = 0; i < bookKeepers.size(); i++) { bookKeepers.get(i).addLogEvent(event); } diff --git a/src/main/java/it/grid/storm/xmlrpc/XmlRpcTokenFilter.java b/src/main/java/it/grid/storm/xmlrpc/XmlRpcTokenFilter.java index 93843fde..2418017e 100644 --- a/src/main/java/it/grid/storm/xmlrpc/XmlRpcTokenFilter.java +++ b/src/main/java/it/grid/storm/xmlrpc/XmlRpcTokenFilter.java @@ -74,8 +74,7 @@ public void doFilter(ServletRequest request, ServletResponse response, if (token == null) { log - .error("The XML-RPC request security token is missing. The calling " - + "service is probably misconfigured."); + .error("The XML-RPC request security token is missing. The calling service is probably misconfigured."); ((HttpServletResponse) response).getWriter().write( prepareXml("The request security token is missing")); @@ -87,8 +86,7 @@ public void doFilter(ServletRequest request, ServletResponse response, if (!token.equals(this.secret)) { log - .error("The XML-RPC request security token does not match. The calling " - + "service is probably misconfigured."); + .error("The XML-RPC request security token does not match. The calling service is probably misconfigured."); ((HttpServletResponse) response).getWriter().write( prepareXml("The request security token does not match")); diff --git a/src/main/java/it/grid/storm/xmlrpc/converter/ConveterFactory.java b/src/main/java/it/grid/storm/xmlrpc/converter/ConveterFactory.java index a6f041aa..83b55894 100644 --- a/src/main/java/it/grid/storm/xmlrpc/converter/ConveterFactory.java +++ b/src/main/java/it/grid/storm/xmlrpc/converter/ConveterFactory.java @@ -109,7 +109,7 @@ public static Converter getConverter(OperationType type) case SPTG: return new ManageFileTransferRequestConverter(); default: - log.error("No Converter available for OperationType " + type); + log.error("No Converter available for OperationType {}" , type); throw new StoRMXmlRpcException( "No Converter available for OperationType " + type); } diff --git a/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/AbortFilesConverter.java b/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/AbortFilesConverter.java index b45d4da4..31bd320e 100644 --- a/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/AbortFilesConverter.java +++ b/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/AbortFilesConverter.java @@ -75,10 +75,10 @@ public InputData convertToInputData(Map inputParam) { try { requestToken = TRequestToken.decode(inputParam, TRequestToken.PNAME_REQUESTOKEN); - log.debug("requestToken=" + requestToken.toString()); + log.debug("requestToken={}" , requestToken.toString()); } catch (InvalidTRequestTokenAttributesException e) { requestToken = null; - log.debug("requestToken=NULL"); + log.debug("requestToken=NULL",e); } ArrayOfSURLs arrayOfSURLs; @@ -121,7 +121,7 @@ public Map convertFromOutputData(OutputData data) { ArrayOfTSURLReturnStatus.PNAME_ARRAYOFFILESTATUSES); } - log.debug("AbortFilesConverter - Sending: " + outputParam.toString()); + log.debug("AbortFilesConverter - Sending: {}" , outputParam.toString()); // Return global structure. return outputParam; diff --git a/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/AbortRequestConverter.java b/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/AbortRequestConverter.java index 2c07bc78..4fea0384 100644 --- a/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/AbortRequestConverter.java +++ b/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/AbortRequestConverter.java @@ -72,10 +72,10 @@ public InputData convertToInputData(Map inputParam) { try { requestToken = TRequestToken.decode(inputParam, TRequestToken.PNAME_REQUESTOKEN); - log.debug("requestToken=" + requestToken.toString()); + log.debug("requestToken={}" , requestToken.toString()); } catch (InvalidTRequestTokenAttributesException e) { requestToken = null; - log.debug("requestToken=NULL"); + log.debug("requestToken=NULL",e); } AbortInputData inputData; if (guser != null) { @@ -100,7 +100,7 @@ public Map convertFromOutputData(OutputData data) { if (returnStatus != null) { returnStatus.encode(outputParam, TReturnStatus.PNAME_RETURNSTATUS); } - log.debug("AbortRequestConverter - Sending: " + outputParam.toString()); + log.debug("AbortRequestConverter - Sending: {}" , outputParam.toString()); // Return global structure. return outputParam; diff --git a/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/ExtendFileLifeTimeConverter.java b/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/ExtendFileLifeTimeConverter.java index 4f594386..24dd6e03 100644 --- a/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/ExtendFileLifeTimeConverter.java +++ b/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/ExtendFileLifeTimeConverter.java @@ -85,17 +85,17 @@ public InputData convertToInputData(Map inputParam) { try { requestToken = TRequestToken.decode(inputParam, TRequestToken.PNAME_REQUESTOKEN); - log.debug("requestToken=" + requestToken.toString()); + log.debug("requestToken={}" , requestToken.toString()); } catch (InvalidTRequestTokenAttributesException e) { requestToken = null; - log.error("requestToken=NULL"); + log.error("requestToken=NULL",e); } ArrayOfSURLs arrayOfSURLs; try { arrayOfSURLs = ArrayOfSURLs.decode(inputParam, ArrayOfSURLs.ARRAYOFSURLS); } catch (InvalidArrayOfSURLsAttributeException e) { - log.error("Empty surlArray!"); + log.error("Empty surlArray!",e); arrayOfSURLs = null; } @@ -138,8 +138,8 @@ public Hashtable convertFromOutputData(OutputData data) { ArrayOfTSURLLifetimeReturnStatus.PNAME_ARRAYOFFILESTATUSES); } - log.debug("ExtendFileLifeTimeConverter - Sending: " - + outputParam.toString()); + log.debug("ExtendFileLifeTimeConverter - Sending: {}" + , outputParam.toString()); // Return global structure. return outputParam; diff --git a/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/FileTransferRequestInputConverter.java b/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/FileTransferRequestInputConverter.java index 2d7888c3..e8b100e2 100644 --- a/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/FileTransferRequestInputConverter.java +++ b/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/FileTransferRequestInputConverter.java @@ -55,16 +55,14 @@ public InputData convertToInputData(Map inputParam) TSURL surl = decodeSURL(inputParam); if (surl == null) { - log.error("Missing mandatory parameter \'" + TSURL.PNAME_SURL - + "\' Unable to build FileTransferInputData"); + log.error("Missing mandatory parameter '{}' Unable to build FileTransferInputData" , TSURL.PNAME_SURL); throw new IllegalArgumentException("Missing mandatory parameter \'" + TSURL.PNAME_SURL + "\'"); } GridUserInterface user = decodeUser(inputParam); TURLPrefix transferProtocols = decodeTransferProtocols(inputParam); if (transferProtocols == null) { - log.error("Missing mandatory parameter \'" + TURLPrefix.PNAME_TURL_PREFIX - + "\' Unable to build FileTransferInputData"); + log.error("Missing mandatory parameter '{}' Unable to build FileTransferInputData" , TURLPrefix.PNAME_TURL_PREFIX); throw new IllegalArgumentException("Missing mandatory parameter \'" + TURLPrefix.PNAME_TURL_PREFIX + "\'"); } @@ -79,8 +77,8 @@ public InputData convertToInputData(Map inputParam) } } catch (IllegalArgumentException e) { log - .error("Unable to build FileTransferInputData. IllegalArgumentException: " - + e.getMessage()); + .error("Unable to build FileTransferInputData. IllegalArgumentException: {}" + , e.getMessage(),e); throw new StoRMXmlRpcException("Unable to build FileTransferInputData"); } TLifeTimeInSeconds desiredPinLifetime = decodeDesiredPinLifetime(inputParam); @@ -99,14 +97,14 @@ public Map convertFromOutputData(OutputData outputData) throws IllegalArgumentException { if (outputData == null) { - log.error("Unable to build an output map. Null argument: outputData= " - + outputData); + log.error("Unable to build an output map. Null argument: outputData={}" + , outputData); throw new IllegalArgumentException( "Unable to build a valid output map, null argument"); } if (!(outputData instanceof FileTransferOutputData)) { - log.error("Unable to convert from OutputData. Wrong OutputData type: \'" - + outputData.getClass().getName() + "\'"); + log.error("Unable to convert from OutputData. Wrong OutputData type: '{}'" + , outputData.getClass().getName()); throw new IllegalArgumentException( "Unable to convert from OutputData. Wrong OutputData type: \'" + outputData.getClass().getName() + "\'"); @@ -120,8 +118,8 @@ public Map convertFromOutputData(OutputData outputData) || turl == null || status == null || requestToken == null || requestToken.getValue() == null || requestToken.getValue().isEmpty()) { log - .error("Unable to build a valid output map. Missing mandatory values from FileTransferOutputData: " - + ftOutputData.toString()); + .error("Unable to build a valid output map. Missing mandatory values from FileTransferOutputData: {}" + , ftOutputData.toString()); throw new IllegalArgumentException( "Unable to build a valid output map from FileTransferOutputData"); } @@ -130,7 +128,7 @@ public Map convertFromOutputData(OutputData outputData) turl.encode(outputParam, TTURL.PNAME_TURL); status.encode(outputParam, TReturnStatus.PNAME_RETURNSTATUS); outputParam.put(TRequestToken.PNAME_REQUESTOKEN, requestToken.toString()); - log.debug("Built output Map: " + outputParam.toString()); + log.debug("Built output Map: {}" , outputParam.toString()); return outputParam; } @@ -152,8 +150,7 @@ protected TURLPrefix decodeTransferProtocols(Map inputParam) TURLPrefix transferProtocols = TURLPrefix.decode(inputParam, TURLPrefix.PNAME_TURL_PREFIX); if (transferProtocols == null) { - log.error("Missing mandatory parameter \'" + TURLPrefix.PNAME_TURL_PREFIX - + "\' Unable to build FileTransferInputData"); + log.error("Missing mandatory parameter '{}' Unable to build FileTransferInputData" , TURLPrefix.PNAME_TURL_PREFIX); throw new IllegalArgumentException("Missing mandatory parameter \'" + TURLPrefix.PNAME_TURL_PREFIX + "\'"); } @@ -172,9 +169,8 @@ protected TSURL decodeSURL(Map inputParam) try { surl = TSURL.decode(inputParam, TSURL.PNAME_SURL); } catch (InvalidTSURLAttributesException e) { - log.error("Unable to decode \'" + TSURL.PNAME_SURL - + "\' parameter as TSURL. InvalidTSURLAttributesException: " - + e.getMessage()); + log.error("Unable to decode '{}' parameter as TSURL. InvalidTSURLAttributesException: {}" , TSURL.PNAME_SURL + , e.getMessage(),e); throw new IllegalArgumentException("Unable to decode \'" + TSURL.PNAME_SURL + "\' parameter as TSURL"); } diff --git a/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/ManageFileTransferRequestConverter.java b/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/ManageFileTransferRequestConverter.java index cce803a2..8f8b5b5e 100644 --- a/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/ManageFileTransferRequestConverter.java +++ b/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/ManageFileTransferRequestConverter.java @@ -60,11 +60,11 @@ public InputData convertToInputData(Map inputParam) { try { requestToken = TRequestToken.decode(inputParam, TRequestToken.PNAME_REQUESTOKEN); - log.debug("requestToken=" + requestToken.toString()); + log.debug("requestToken={}" , requestToken.toString()); } catch (InvalidTRequestTokenAttributesException e) { log - .debug("No request token provided by user. InvalidTRequestTokenAttributesException: " - + e.getMessage()); + .debug("No request token provided by user. InvalidTRequestTokenAttributesException: {}" + , e.getMessage(),e); } /* (3) anyURI[] arrayOfSURLs */ @@ -72,7 +72,7 @@ public InputData convertToInputData(Map inputParam) { try { arrayOfSURLs = ArrayOfSURLs.decode(inputParam, ArrayOfSURLs.ARRAYOFSURLS); } catch (InvalidArrayOfSURLsAttributeException e) { - log.debug("Empty surlArray!"); + log.debug("Empty surlArray!",e); arrayOfSURLs = null; } diff --git a/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/PrepareToGetRequestConverter.java b/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/PrepareToGetRequestConverter.java index e27bd04f..7b11a34e 100644 --- a/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/PrepareToGetRequestConverter.java +++ b/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/PrepareToGetRequestConverter.java @@ -39,8 +39,8 @@ public class PrepareToGetRequestConverter extends public Map convertFromOutputData(OutputData outputData) { if (!(outputData instanceof PrepareToGetOutputData)) { - log.error("Unable to convert from OutputData. Wrong OutputData type: \'" - + outputData.getClass().getName() + "\'"); + log.error("Unable to convert from OutputData. Wrong OutputData type: '{}'" + , outputData.getClass().getName()); throw new IllegalArgumentException( "Unable to convert from OutputData. Wrong OutputData type: \'" + outputData.getClass().getName() + "\'"); @@ -50,7 +50,7 @@ public Map convertFromOutputData(OutputData outputData) { ptgOutputData.getFileSize().encode(outputParam, TSizeInBytes.PNAME_SIZE); ptgOutputData.getRemainingPinTime().encode(outputParam, TLifeTimeInSeconds.PNAME_PINLIFETIME); - log.debug("Built output Map: " + outputParam.toString()); + log.debug("Built output Map: {}" , outputParam.toString()); return outputParam; } diff --git a/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/PrepareToPutRequestConverter.java b/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/PrepareToPutRequestConverter.java index 64a03cc4..f6810692 100644 --- a/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/PrepareToPutRequestConverter.java +++ b/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/PrepareToPutRequestConverter.java @@ -62,8 +62,8 @@ public InputData convertToInputData(Map inputParam) } } catch (IllegalArgumentException e) { log - .error("Unable to build PrepareToPutInputData. IllegalArgumentException: " - + e.getMessage()); + .error("Unable to build PrepareToPutInputData. IllegalArgumentException: {}" + , e.getMessage(),e); throw new StoRMXmlRpcException("Unable to build PrepareToPutInputData"); } TLifeTimeInSeconds desiredFileLifetime = TLifeTimeInSeconds.decode( @@ -94,17 +94,17 @@ public InputData convertToInputData(Map inputParam) try { overwriteMode = TOverwriteMode.getTOverwriteMode(overwriteModeString); } catch (IllegalArgumentException e) { - log.error("Unable to build TOverwriteMode from \'" - + overwriteModeString + "\'. IllegalArgumentException: " - + e.getMessage()); + log.error("Unable to build TOverwriteMode from '{}'. IllegalArgumentException: {}" + , overwriteModeString + , e.getMessage() + , e); throw new StoRMXmlRpcException("Unable to build PrepareToPutInputData"); } if (!overwriteMode.equals(TOverwriteMode.EMPTY)) { inputData.setOverwriteMode(overwriteMode); } else { log - .warn("Unable to use the received \'" + OVERWRITE_MODE_PARAMETER_NAME - + "\', interpreted as an empty value"); + .warn("Unable to use the received '{}', interpreted as an empty value" , OVERWRITE_MODE_PARAMETER_NAME); } } log.debug("PrepareToPutInputData Created!"); diff --git a/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/PutDoneConverter.java b/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/PutDoneConverter.java index 0f63ddff..eadcb2c9 100644 --- a/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/PutDoneConverter.java +++ b/src/main/java/it/grid/storm/xmlrpc/converter/datatransfer/PutDoneConverter.java @@ -70,17 +70,17 @@ public InputData convertToInputData(Map inputParam) { try { requestToken = TRequestToken.decode(inputParam, TRequestToken.PNAME_REQUESTOKEN); - log.debug("requestToken=" + requestToken.toString()); + log.debug("requestToken={}" , requestToken.toString()); } catch (InvalidTRequestTokenAttributesException e) { requestToken = null; - log.debug("requestToken=NULL" + e); + log.debug("requestToken=NULL" , e); } ArrayOfSURLs arrayOfSURLs; try { arrayOfSURLs = ArrayOfSURLs.decode(inputParam, ArrayOfSURLs.ARRAYOFSURLS); } catch (InvalidArrayOfSURLsAttributeException e) { - log.debug("Empty surlArray!"); + log.debug("Empty surlArray!",e); arrayOfSURLs = null; } diff --git a/src/main/java/it/grid/storm/xmlrpc/converter/directory/LsConverter.java b/src/main/java/it/grid/storm/xmlrpc/converter/directory/LsConverter.java index a4dfd203..6206f98d 100644 --- a/src/main/java/it/grid/storm/xmlrpc/converter/directory/LsConverter.java +++ b/src/main/java/it/grid/storm/xmlrpc/converter/directory/LsConverter.java @@ -76,10 +76,10 @@ public LsConverter() { */ public InputData convertToInputData(Map inputParam) { - log.debug("SrmLs: LSConverter :Call received :Creation of SpaceResData = " - + inputParam.size()); - log.debug("SrmLs: LSConverter: Input Structure toString: " - + ParameterDisplayHelper.display(inputParam)); + log.debug("SrmLs: LSConverter :Call received :Creation of SpaceResData = {}" + , inputParam.size()); + log.debug("SrmLs: LSConverter: Input Structure toString: {}" + , ParameterDisplayHelper.display(inputParam)); // Member name definition for inputParam struct , from SRM V2.2 String member_fullDL = new String("fullDetailedList"); @@ -96,33 +96,33 @@ public InputData convertToInputData(Map inputParam) { try { surlArray = ArrayOfSURLs.decode(inputParam, ArrayOfSURLs.ARRAYOFSURLS); } catch (InvalidArrayOfSURLsAttributeException e2) { - log.debug("SrmLs: Empty surlArray found!"); + log.debug("SrmLs: Empty surlArray found!",e2); surlArray = null; } TFileStorageType fileStorageType = TFileStorageType.decode(inputParam, TFileStorageType.PNAME_FILESTORAGETYPE); - log.debug("fileType: " + fileStorageType); + log.debug("fileType: {}" , fileStorageType); /* (5) fullDetailedList */ Boolean fullDL = (Boolean) inputParam.get(member_fullDL); - log.debug("fullDetailedList: " + fullDL); + log.debug("fullDetailedList: {}" , fullDL); /* (6) allLevelRecursive */ Boolean allLR = (Boolean) inputParam.get(member_allLR); - log.debug("allLevelRecursive: " + allLR); + log.debug("allLevelRecursive: {}" , allLR); /* (7) numOfLevels */ Integer numOL = (Integer) inputParam.get(member_numOL); - log.debug("numOfLevels: " + numOL); + log.debug("numOfLevels: {}" , numOL); /* (8) offset */ Integer offset = (Integer) inputParam.get(member_offset); - log.debug("offset: " + offset); + log.debug("offset: {}" , offset); /* (9) count */ Integer count = (Integer) inputParam.get(member_count); - log.debug("count: " + count); + log.debug("count: {}" , count); LSInputData inputData; if (guser != null) { diff --git a/src/main/java/it/grid/storm/xmlrpc/converter/directory/MkdirConverter.java b/src/main/java/it/grid/storm/xmlrpc/converter/directory/MkdirConverter.java index 04d35bfb..ff6dd01f 100644 --- a/src/main/java/it/grid/storm/xmlrpc/converter/directory/MkdirConverter.java +++ b/src/main/java/it/grid/storm/xmlrpc/converter/directory/MkdirConverter.java @@ -66,10 +66,10 @@ public MkdirConverter() { public InputData convertToInputData(Map inputParam) { log - .debug("SrmMkdir: Converter :Call received :Creation of MkdirInputData = " - + inputParam.size()); - log.debug("SrmMkdir: Converter: Input Structure toString: " - + ParameterDisplayHelper.display(inputParam)); + .debug("SrmMkdir: Converter :Call received :Creation of MkdirInputData = {}" + , inputParam.size()); + log.debug("SrmMkdir: Converter: Input Structure toString: {}" + , ParameterDisplayHelper.display(inputParam)); GridUserInterface guser = GridUserManager.decode(inputParam); @@ -78,7 +78,7 @@ public InputData convertToInputData(Map inputParam) { try { surl = TSURL.decode(inputParam, TSURL.PNAME_SURL); } catch (InvalidTSURLAttributesException e1) { - log.debug("SrmMkdir: ErrorCreating surl: " + e1.toString()); + log.debug("SrmMkdir: ErrorCreating surl: {}" , e1.toString(),e1); } MkdirInputData inputData; diff --git a/src/main/java/it/grid/storm/xmlrpc/converter/directory/MvConverter.java b/src/main/java/it/grid/storm/xmlrpc/converter/directory/MvConverter.java index 602d0876..f608573b 100644 --- a/src/main/java/it/grid/storm/xmlrpc/converter/directory/MvConverter.java +++ b/src/main/java/it/grid/storm/xmlrpc/converter/directory/MvConverter.java @@ -67,10 +67,10 @@ public MvConverter() { */ public InputData convertToInputData(Map inputParam) { - log.debug("SrmMv: Converter :Call received :Creation of MvInputData = " - + inputParam.size()); - log.debug("SrmMv: Converter: Input Structure toString: " - + ParameterDisplayHelper.display(inputParam)); + log.debug("SrmMv: Converter :Call received :Creation of MvInputData = {}" + , inputParam.size()); + log.debug("SrmMv: Converter: Input Structure toString: {}" + , ParameterDisplayHelper.display(inputParam)); GridUserInterface guser = GridUserManager.decode(inputParam); @@ -79,7 +79,7 @@ public InputData convertToInputData(Map inputParam) { try { fromSURL = TSURL.decode(inputParam, TSURL.PNAME_FROMSURL); } catch (InvalidTSURLAttributesException e1) { - log.debug("SrmMv: ErrorCreating surl: " + e1.toString()); + log.debug("SrmMv: ErrorCreating surl: {}" , e1.toString(),e1); } /* (3) toSURL */ @@ -87,7 +87,7 @@ public InputData convertToInputData(Map inputParam) { try { toSURL = TSURL.decode(inputParam, TSURL.PNAME_TOSURL); } catch (InvalidTSURLAttributesException e1) { - log.debug("SrmMv: ErrorCreating surl: " + e1.toString()); + log.debug("SrmMv: ErrorCreating surl: {}" , e1.toString(),e1); } MvInputData inputData; diff --git a/src/main/java/it/grid/storm/xmlrpc/converter/directory/RmConverter.java b/src/main/java/it/grid/storm/xmlrpc/converter/directory/RmConverter.java index 553bd57d..0e4614cd 100644 --- a/src/main/java/it/grid/storm/xmlrpc/converter/directory/RmConverter.java +++ b/src/main/java/it/grid/storm/xmlrpc/converter/directory/RmConverter.java @@ -70,10 +70,10 @@ public RmConverter() { */ public InputData convertToInputData(Map inputParam) { - log.debug("RmConverter :Call received :Creation of RmdirInputData = " - + inputParam.size()); - log.debug("RmConverter: Input Structure toString: " - + ParameterDisplayHelper.display(inputParam)); + log.debug("RmConverter :Call received :Creation of RmdirInputData = {}" + , inputParam.size()); + log.debug("RmConverter: Input Structure toString: {}" + , ParameterDisplayHelper.display(inputParam)); GridUserInterface guser = GridUserManager.decode(inputParam); diff --git a/src/main/java/it/grid/storm/xmlrpc/converter/directory/RmdirConverter.java b/src/main/java/it/grid/storm/xmlrpc/converter/directory/RmdirConverter.java index a68e837a..623beea9 100644 --- a/src/main/java/it/grid/storm/xmlrpc/converter/directory/RmdirConverter.java +++ b/src/main/java/it/grid/storm/xmlrpc/converter/directory/RmdirConverter.java @@ -71,10 +71,10 @@ public RmdirConverter() { public InputData convertToInputData(Map inputParam) { log - .debug("srmRmdir: Converter :Call received :Creation of RmdirInputData = " - + inputParam.size()); - log.debug("srmRmdir: Converter: Input Structure toString: " - + ParameterDisplayHelper.display(inputParam)); + .debug("srmRmdir: Converter :Call received :Creation of RmdirInputData = {}" + , inputParam.size()); + log.debug("srmRmdir: Converter: Input Structure toString: {}" + , ParameterDisplayHelper.display(inputParam)); /* Creation of VomsGridUser */ GridUserInterface guser = GridUserManager.decode(inputParam); @@ -84,7 +84,7 @@ public InputData convertToInputData(Map inputParam) { try { surl = TSURL.decode(inputParam, TSURL.PNAME_SURL); } catch (InvalidTSURLAttributesException e1) { - log.debug("srmRm: ErrorCreating surl: " + e1.toString()); + log.debug("srmRm: ErrorCreating surl: {}" , e1.toString(),e1); } /* (4) recursive */ diff --git a/src/main/java/it/grid/storm/xmlrpc/converter/space/GetSpaceTokensConverter.java b/src/main/java/it/grid/storm/xmlrpc/converter/space/GetSpaceTokensConverter.java index 7e8a1d6e..5a306f0c 100644 --- a/src/main/java/it/grid/storm/xmlrpc/converter/space/GetSpaceTokensConverter.java +++ b/src/main/java/it/grid/storm/xmlrpc/converter/space/GetSpaceTokensConverter.java @@ -104,7 +104,7 @@ public Map convertFromOutputData(OutputData data) { ArrayOfTSpaceToken.PNAME_ARRAYOFSPACETOKENS); } - log.debug("Sending: " + outputParam.toString()); + log.debug("Sending: {}" , outputParam.toString()); // Return output Parameter structure return outputParam; diff --git a/src/main/java/it/grid/storm/xmlrpc/converter/space/ReleaseSpaceConverter.java b/src/main/java/it/grid/storm/xmlrpc/converter/space/ReleaseSpaceConverter.java index 8767de5e..10fd82e3 100644 --- a/src/main/java/it/grid/storm/xmlrpc/converter/space/ReleaseSpaceConverter.java +++ b/src/main/java/it/grid/storm/xmlrpc/converter/space/ReleaseSpaceConverter.java @@ -68,10 +68,10 @@ public ReleaseSpaceConverter() { public InputData convertToInputData(Map inputParam) { log - .debug("ReleaseSpaceConverter :Call received :Creation of SpaceResData = " - + inputParam.size()); - log.debug("ReleaseSpaceConverter: Input Structure toString: " - + ParameterDisplayHelper.display(inputParam)); + .debug("ReleaseSpaceConverter :Call received :Creation of SpaceResData = {}" + , inputParam.size()); + log.debug("ReleaseSpaceConverter: Input Structure toString: {}" + , ParameterDisplayHelper.display(inputParam)); GridUserInterface guser = GridUserManager.decode(inputParam); diff --git a/src/main/java/it/grid/storm/xmlrpc/converter/space/ReserveSpaceConverter.java b/src/main/java/it/grid/storm/xmlrpc/converter/space/ReserveSpaceConverter.java index 037650b3..fb5cfdbe 100644 --- a/src/main/java/it/grid/storm/xmlrpc/converter/space/ReserveSpaceConverter.java +++ b/src/main/java/it/grid/storm/xmlrpc/converter/space/ReserveSpaceConverter.java @@ -72,10 +72,10 @@ public ReserveSpaceConverter() { public InputData convertToInputData(Map inputParam) { log - .debug("reserveSpaceConverter :Call received :Creation of SpaceResData = " - + inputParam.size()); - log.debug("reserveSpaceConverter: Input Structure toString: " - + ParameterDisplayHelper.display(inputParam)); + .debug("reserveSpaceConverter :Call received :Creation of SpaceResData = {}" + , inputParam.size()); + log.debug("reserveSpaceConverter: Input Structure toString: {}" + , ParameterDisplayHelper.display(inputParam)); String memberName = null; From c2081a94b975445c7168273f64cd4888b714f58e Mon Sep 17 00:00:00 2001 From: dandreotti Date: Tue, 4 Feb 2014 17:21:58 +0000 Subject: [PATCH 18/45] Fix for https://issues.infn.it/jira/browse/STOR-524 --- .../tape/recalltable/TapeRecallCatalog.java | 47 +++++++++---------- .../model/PutTapeRecallStatusLogic.java | 22 ++++----- .../model/PutTapeRecallStatusValidator.java | 3 +- .../recalltable/model/TapeRecallData.java | 34 +++++++------- .../recalltable/persistence/PropertiesDB.java | 15 +++--- .../persistence/TapeRecallBuilder.java | 9 ++-- .../recalltable/resources/TaskResource.java | 22 ++++----- .../resources/TasksCardinality.java | 6 +-- .../recalltable/resources/TasksResource.java | 12 ++--- 9 files changed, 76 insertions(+), 94 deletions(-) diff --git a/src/main/java/it/grid/storm/tape/recalltable/TapeRecallCatalog.java b/src/main/java/it/grid/storm/tape/recalltable/TapeRecallCatalog.java index 36f2530d..d42a0d96 100644 --- a/src/main/java/it/grid/storm/tape/recalltable/TapeRecallCatalog.java +++ b/src/main/java/it/grid/storm/tape/recalltable/TapeRecallCatalog.java @@ -93,8 +93,8 @@ public int getNumberTaskInProgress() throws DataAccessException { result = tapeRecallDAO.getNumberInProgress(); } catch (DataAccessException e) { log - .error("Unable to retrieve the number of tasks currently in progress. DataAccessException: " - + e.getMessage()); + .error("Unable to retrieve the number of tasks currently in progress. DataAccessException: {}" + , e.getMessage(),e); throw e; } return result; @@ -114,8 +114,8 @@ public int getNumberTaskInProgress(String voName) throws DataAccessException { result = tapeRecallDAO.getNumberInProgress(voName); } catch (DataAccessException e) { log - .error("Unable to retrieve the number of tasks currently in progress. DataAccessException: " - + e.getMessage()); + .error("Unable to retrieve the number of tasks currently in progress. DataAccessException: {}" + , e.getMessage(),e); throw e; } return result; @@ -134,8 +134,8 @@ public int getNumberTaskQueued() throws DataAccessException { result = tapeRecallDAO.getNumberQueued(); } catch (DataAccessException e) { log - .error("Unable to retrieve the number of tasks queued. DataAccessException: " - + e.getMessage()); + .error("Unable to retrieve the number of tasks queued. DataAccessException: {}" + , e.getMessage(),e); throw e; } return result; @@ -154,8 +154,8 @@ public int getNumberTaskQueued(String voName) throws DataAccessException { result = tapeRecallDAO.getNumberQueued(voName); } catch (DataAccessException e) { log - .error("Unable to retrieve the number of tasks queued. DataAccessException: " - + e.getMessage()); + .error("Unable to retrieve the number of tasks queued. DataAccessException: {}" + , e.getMessage(),e); throw e; } return result; @@ -176,8 +176,8 @@ public int getReadyForTakeOver() throws DataAccessException { result = tapeRecallDAO.getReadyForTakeOver(); } catch (DataAccessException e) { log - .error("Unable to retrieve the number of tasks ready for the take-over. DataAccessException: " - + e.getMessage()); + .error("Unable to retrieve the number of tasks ready for the take-over. DataAccessException: {}" + , e.getMessage(),e); throw e; } return result; @@ -197,8 +197,8 @@ public int getReadyForTakeOver(String voName) throws DataAccessException { result = tapeRecallDAO.getReadyForTakeOver(voName); } catch (DataAccessException e) { log - .error("Unable to retrieve the number of tasks ready for the take-over. DataAccessException: " - + e.getMessage()); + .error("Unable to retrieve the number of tasks ready for the take-over. DataAccessException: {}" + , e.getMessage(),e); throw e; } return result; @@ -258,10 +258,10 @@ public boolean existsGroupTask(UUID groupTaskId) throws DataAccessException { public void purgeCatalog(int n) { try { - log.debug("purging.. '" + n + "' tasks."); + log.debug("purging.. '{}' tasks.", n); tapeRecallDAO.purgeCompletedTasks(n); } catch (DataAccessException e) { - log.error("Unable to takeover a task", e); + log.error("Unable to takeover a task {}", e); } } @@ -278,7 +278,7 @@ public ArrayList takeoverNTasksWithDoubles(int numberOfTaks) { try { taskList.addAll(tapeRecallDAO.takeoverTasksWithDoubles(numberOfTaks)); } catch (DataAccessException e) { - log.error("Unable to takeover " + numberOfTaks + " tasks", e); + log.error("Unable to takeover {} tasks" , numberOfTaks , e); } return taskList; } @@ -328,7 +328,7 @@ public TapeRecallTO takeoverTask(String voName) { try { task = tapeRecallDAO.takeoverTask(voName); } catch (DataAccessException e) { - log.error("Unable to takeover a task for vo " + voName, e); + log.error("Unable to takeover a task for vo {}" , voName, e); } return task; } @@ -345,8 +345,7 @@ public List takeoverTasks(int numberOfTaks, String voName) { taskList.addAll(tapeRecallDAO.takeoverTasksWithDoubles(numberOfTaks, voName)); } catch (DataAccessException e) { - log.error("Unable to takeover " + numberOfTaks + " tasks for vo " - + voName, e); + log.error("Unable to takeover {} tasks for vo {}" , numberOfTaks , voName, e); } return taskList; } @@ -412,9 +411,7 @@ public UUID insertNewTask(TapeRecallTO task) throws DataAccessException { TapeRecallStatus.IN_PROGRESS.getStatusId() }, newGroupTaskId); if (newGroupTaskId != groupTaskId) { - log.debug("Task with taskId " + task.getTaskId() - + " of request with token " + task.getRequestTokenStr() - + " has benn added to an existentr group : " + groupTaskId); + log.debug("Task with taskId {} of request with token {} has benn added to an existent group : " , task.getTaskId(),task.getRequestTokenStr(), groupTaskId); } return groupTaskId; } @@ -479,17 +476,15 @@ public boolean changeGroupTaskStatus(UUID groupTaskId, if ((recallTaskStatus == TapeRecallStatus.IN_PROGRESS) || (recallTaskStatus == TapeRecallStatus.QUEUED)) { log - .warn("Setting the status to IN_PROGRESS or QUEUED using setGroupTaskStatus() is not " - + "a legal operation, doing it anyway. groupTaskId=" - + groupTaskId); + .warn("Setting the status to IN_PROGRESS or QUEUED using setGroupTaskStatus() is not a legal operation, doing it anyway. groupTaskId={}", groupTaskId); } else { // the status is a terminal status chunkBucket = recallBuckets.remove(groupTaskId); // end if (chunkBucket == null) { log - .error("Unable to perform the final status update. No bucket found for Recall Group Task ID " - + groupTaskId.toString()); + .error("Unable to perform the final status update. No bucket found for Recall Group Task ID {}" + , groupTaskId.toString()); throw new DataAccessException( "Unable to perform the final status update. No bucket found for Recall Group Task ID " + groupTaskId.toString()); diff --git a/src/main/java/it/grid/storm/tape/recalltable/model/PutTapeRecallStatusLogic.java b/src/main/java/it/grid/storm/tape/recalltable/model/PutTapeRecallStatusLogic.java index 39c4ca28..81c27c77 100644 --- a/src/main/java/it/grid/storm/tape/recalltable/model/PutTapeRecallStatusLogic.java +++ b/src/main/java/it/grid/storm/tape/recalltable/model/PutTapeRecallStatusLogic.java @@ -13,6 +13,7 @@ import java.util.Date; import java.util.UUID; + import it.grid.storm.filesystem.FSException; import it.grid.storm.filesystem.LocalFile; import it.grid.storm.namespace.StoRI; @@ -20,8 +21,11 @@ import it.grid.storm.persistence.model.TapeRecallTO; import it.grid.storm.tape.recalltable.TapeRecallCatalog; import it.grid.storm.tape.recalltable.TapeRecallException; + import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; + +import org.apache.commons.httpclient.methods.GetMethod; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,8 +53,7 @@ public static Response serveRequest(String requestToken, StoRI stori) try { fileOnDisk = localFile.isOnDisk(); } catch (FSException e) { - log.error("Unable to test file " + localFile.getAbsolutePath() - + " presence on disk. FSException " + e.getMessage()); + log.error("Unable to test file {} presence on disk. FSException {}" , localFile.getAbsolutePath() , e.getMessage() , e); throw new TapeRecallException("Error checking file existence"); } if (fileOnDisk) { @@ -63,9 +66,7 @@ public static Response serveRequest(String requestToken, StoRI stori) try { exists = rtCat.existsTask(taskId, requestToken); } catch (DataAccessException e) { - log.error("Error checking existence of a recall task for taskId=" - + taskId + " requestToken=" + requestToken - + ". DataAccessException: " + e); + log.error("Error checking existence of a recall task for taskId={} requestToken={}. DataAccessException: {}" , taskId , requestToken , e.getMessage() , e); throw new TapeRecallException("Error reading from tape recall table"); } if (exists) { @@ -74,8 +75,8 @@ public static Response serveRequest(String requestToken, StoRI stori) task = rtCat.getTask(taskId, requestToken); } catch (DataAccessException e) { log - .error("Unable to update task recall status because unable to retrieve groupTaskId for token " - + requestToken + " DataAccessException: " + e.getMessage()); + .error("Unable to update task recall status because unable to retrieve groupTaskId for token {}. DataAccessException: {}" + , requestToken , e.getMessage(),e); throw new TapeRecallException( "Error reading from tape recall table"); } @@ -87,14 +88,11 @@ public static Response serveRequest(String requestToken, StoRI stori) statusUpdated = rtCat.changeGroupTaskStatus(groupTaskId, TapeRecallStatus.SUCCESS, new Date()); } catch (DataAccessException e) { - log.error("Unable to update task recall status for token " - + requestToken + " with groupTaskId=" + groupTaskId - + ". DataAccessException : " + e.getMessage()); + log.error("Unable to update task recall status for token {} with groupTaskId={}. DataAccessException : {}", requestToken , groupTaskId , e.getMessage() , e); throw new TapeRecallException("Error updating tape recall table"); } if (statusUpdated) { - log.info("Task status set to SUCCESS. groupTaskId=" + groupTaskId - + " requestToken=" + requestToken + " pfn=" + pfn); + log.info("Task status set to SUCCESS. groupTaskId={} requestToken={} pfn={}" , groupTaskId , requestToken , pfn); } outputMessage = "true"; } else { diff --git a/src/main/java/it/grid/storm/tape/recalltable/model/PutTapeRecallStatusValidator.java b/src/main/java/it/grid/storm/tape/recalltable/model/PutTapeRecallStatusValidator.java index cc80e066..31388f1e 100644 --- a/src/main/java/it/grid/storm/tape/recalltable/model/PutTapeRecallStatusValidator.java +++ b/src/main/java/it/grid/storm/tape/recalltable/model/PutTapeRecallStatusValidator.java @@ -144,8 +144,7 @@ private boolean validateSurl(String surlString) { try { stori = NamespaceDirector.getNamespace().resolveStoRIbySURL(surl); } catch (Exception e) { - log.warn("Unable to build a stori for surl " + surl - + " UnapprochableSurlException: " + e.getMessage()); + log.warn("Unable to build a stori for surl {} UnapprochableSurlException: {}" , surl , e.getMessage(),e); return false; } return true; diff --git a/src/main/java/it/grid/storm/tape/recalltable/model/TapeRecallData.java b/src/main/java/it/grid/storm/tape/recalltable/model/TapeRecallData.java index 703e4877..5871f238 100644 --- a/src/main/java/it/grid/storm/tape/recalltable/model/TapeRecallData.java +++ b/src/main/java/it/grid/storm/tape/recalltable/model/TapeRecallData.java @@ -85,13 +85,13 @@ public static TapeRecallData buildFromString(String inputString) String parameters = inputString.substring(beginArray + 1, endArray); String[] paramArray = parameters.split(TapeRecallBuilder.elementSep); for (int i = 0; i < paramArray.length; i++) { - log.debug("param[" + i + "]=" + paramArray[i]); + log.debug("param[{}]={}" , i , paramArray[i]); if (paramArray[i].contains(TapeRecallBuilder.equalChar)) { int equalIndex = paramArray[i].indexOf(TapeRecallBuilder.equalChar); String key = paramArray[i].substring(0, equalIndex); String value = paramArray[i].substring(equalIndex + 1, paramArray[i].length()); - log.debug("KEY:" + key + " VALUE:" + value); + log.debug("KEY: {} VALUE: {}" , key , value); // Scan for known keys. if (key.equals(TapeRecallBuilder.fnPrefix)) { result.fileName = value; @@ -102,8 +102,7 @@ public static TapeRecallData buildFromString(String inputString) } else if (key.equals(TapeRecallBuilder.fqansPrefix)) { result.fqans = result.parseFQANs(value, 0, 0, 0, value.length()); } else { - log.warn("Unknown key-value pair (" + key + "," + value - + "). StoRM will ignore them."); + log.warn("Unknown key-value pair ({},{}. StoRM will ignore them.)" , key , value); } } } @@ -164,10 +163,10 @@ public TapeRecallData(String textFormat) throws TapeRecallException { userDN = parseDN(taskDataText, fnPos, dnPos, fqansPos, voNamePos); fqans = parseFQANs(taskDataText, fnPos, dnPos, fqansPos, voNamePos); voName = parseVOName(taskDataText, fnPos, dnPos, fqansPos, voNamePos); - log.debug("filename='" + fileName + "'"); - log.debug("userDN ='" + userDN + "'"); - log.debug("fqans='" + fqans + "'"); - log.debug("voName='" + voName + "'"); + log.debug("filename='{}'" , fileName); + log.debug("userDN ='{}'" , userDN); + log.debug("fqans='{}'" , fqans); + log.debug("voName='{}'" , voName); } } else { throw new TapeRecallException("Unable to find the File Name"); @@ -299,8 +298,7 @@ private String parseDN(String taskDataText, int fnPos, int dnPos, if (dnPos > 0) { if (fqansPos > 0) { result = taskDataText.substring(dnPos, fqansPos - 1); - log.debug("dn to parse (dnPos=" + dnPos + " fqansPos=" + fqansPos - + ": " + result); + log.debug("dn to parse dnPos={} fqansPos={}: {}" , dnPos , fqansPos , result); } else if (voNamePos > 0) { result = taskDataText.substring(dnPos, voNamePos - 1); } else { @@ -313,7 +311,7 @@ private String parseDN(String taskDataText, int fnPos, int dnPos, int pos = result.indexOf(TapeRecallBuilder.elementSep); pos = pos < 0 ? result.length() : pos; result = result.substring(TapeRecallBuilder.dnPrefix.length(), pos); - log.debug("DN to parse ='" + result + "'"); + log.debug("DN to parse ='{}'" , result); log.warn("## TODO Feature ## : Bug in parsing DN in RFC 2253 format."); /** @@ -334,7 +332,7 @@ private String parseDN(String taskDataText, int fnPos, int dnPos, * ################# END TEMPORARY FIX */ - log.debug("DN parsed ='" + result + "'"); + log.debug("DN parsed ='{}'" , result); return result; } @@ -359,11 +357,11 @@ private String parseFN(String taskDataText, int fnPos, int dnPos, } else { result = taskDataText.substring(fnPos); } - log.debug("FN to parse ='" + result + "'"); + log.debug("FN to parse ='{}'" , result); int pos = result.indexOf(TapeRecallBuilder.elementSep); pos = pos < 0 ? result.length() : pos; result = result.substring(TapeRecallBuilder.fnPrefix.length(), pos); - log.debug("FN parsed ='" + result + "'"); + log.debug("FN parsed ='{}'" , result); return result; } @@ -403,13 +401,13 @@ private ArrayList parseFQANs(String taskDataText, int fnPos, int dnPos, FQAN fqan; int count = 0; for (String fqanIter : fqans) { - log.debug("fqanString = '" + fqanIter + "'"); + log.debug("fqanString = '{}'" , fqanIter); // Trim out the prefix and the separator (if there) pos = fqansSt.indexOf(TapeRecallBuilder.fqanSep); pos = pos < 0 ? fqansSt.length() : pos; fqanIter = fqanIter.substring(TapeRecallBuilder.fqanPrefix.length(), pos); - log.debug("fqanString (purged) = '" + fqanIter + "'"); + log.debug("fqanString (purged) = '{}'" , fqanIter); fqan = new FQAN(fqanIter); result.add(fqan); fqansString[count] = fqan.toString(); @@ -435,7 +433,7 @@ private String parseVOName(String taskDataText, int fnPos, int dnPos, String result = null; if (voNamePos > 0) { result = taskDataText.substring(voNamePos); - log.debug("vo-name to parse ='" + result + "'"); + log.debug("vo-name to parse ='{}'" , result); int pos = result.indexOf(TapeRecallBuilder.elementSep); pos = pos < 0 ? result.length() : pos; result = result.substring(TapeRecallBuilder.voNamePrefix.length(), pos); @@ -448,7 +446,7 @@ private String parseVOName(String taskDataText, int fnPos, int dnPos, } } - log.debug("vo-name parsed ='" + result + "'"); + log.debug("vo-name parsed ='{}'" , result); return result; } diff --git a/src/main/java/it/grid/storm/tape/recalltable/persistence/PropertiesDB.java b/src/main/java/it/grid/storm/tape/recalltable/persistence/PropertiesDB.java index 7283fe3d..373f9f9c 100644 --- a/src/main/java/it/grid/storm/tape/recalltable/persistence/PropertiesDB.java +++ b/src/main/java/it/grid/storm/tape/recalltable/persistence/PropertiesDB.java @@ -58,7 +58,7 @@ public PropertiesDB() { char sep = File.separatorChar; propertiesDBName = configurationDir + sep + "etc" + sep + "db" + sep + dataFileName; - log.debug("Properties RecallTable-DB = " + propertiesDBName); + log.debug("Properties RecallTable-DB = {}" , propertiesDBName); } public PropertiesDB(boolean test) { @@ -78,11 +78,10 @@ public PropertiesDB(boolean test) { try { success = tasksDBfile.createNewFile(); } catch (IOException e) { - log.error("Error while trying to check : " + propertiesDBName); - e.printStackTrace(); + log.error("Error while trying to check : {}" , propertiesDBName,e); } if (success) { - log.debug("TaskDB = '" + propertiesDBName + "' exists ? " + success); + log.debug("TaskDB = '{}' exists ? {}" , propertiesDBName , success); } } @@ -174,7 +173,7 @@ public void updateRecallTask(TapeRecallTO task) throws FileNotFoundException, // Check if the Task exists within the Properties DB boolean taskExist = properties.containsKey(taskId.toString()); if (!(taskExist)) { - log.error("Unable to find the task with ID = " + taskId); + log.error("Unable to find the task with ID = {}" , taskId); throw new DataAccessException("Unable to find the task with ID = " + taskId); } else { @@ -182,7 +181,7 @@ public void updateRecallTask(TapeRecallTO task) throws FileNotFoundException, String taskStr = task.toString(); // Insert the new property entry properties.setProperty(taskId.toString(), taskStr); - log.debug("Removed tasks '" + taskId + "'"); + log.debug("Removed tasks '{}'" , taskId); } // Store the properties into disk @@ -198,12 +197,12 @@ public void deleteRecallTask(UUID taskId) throws FileNotFoundException, // Retrieve the Task from taskId String task = properties.getProperty(taskId.toString()); if (task == null) { - log.error("Unable to find the task with ID = " + taskId); + log.error("Unable to find the task with ID = {}" , taskId); throw new DataAccessException("Unable to find the task with ID = " + taskId); } else { properties.remove(taskId); - log.debug("Removed tasks '" + taskId + "'"); + log.debug("Removed tasks '{}'" , taskId); } // Store the properties into disk diff --git a/src/main/java/it/grid/storm/tape/recalltable/persistence/TapeRecallBuilder.java b/src/main/java/it/grid/storm/tape/recalltable/persistence/TapeRecallBuilder.java index 82fd3d09..3dacc2d0 100644 --- a/src/main/java/it/grid/storm/tape/recalltable/persistence/TapeRecallBuilder.java +++ b/src/main/java/it/grid/storm/tape/recalltable/persistence/TapeRecallBuilder.java @@ -115,8 +115,7 @@ private static TapeRecallStatus parseTaskStatus(String taskStatus) { try { result = TapeRecallStatus.getRecallTaskStatus(taskStatus); } catch (Exception e) { - log.error("Task Status '" + taskStatus + "' is not in a valid format."); - e.printStackTrace(); + log.error("Task Status '{}' is not in a valid format." , taskStatus , e); } return result; } @@ -131,8 +130,7 @@ private static int parseInt(String number) { try { result = Integer.parseInt(number); } catch (Exception e) { - log.error("Number'" + number + "' is not in a valid format."); - e.printStackTrace(); + log.error("Number '{}' is not in a valid format." , number , e); } return result; } @@ -148,8 +146,7 @@ private static Date parseDate(String dateString) { try { date = formatter.parse(dateString); } catch (ParseException e) { - log.error("Date '" + dateString + "' is not in a valid format."); - e.printStackTrace(); + log.error("Date '{}' is not in a valid format." , dateString , e); } return date; } diff --git a/src/main/java/it/grid/storm/tape/recalltable/resources/TaskResource.java b/src/main/java/it/grid/storm/tape/recalltable/resources/TaskResource.java index 6cbf93f6..7c914b6d 100644 --- a/src/main/java/it/grid/storm/tape/recalltable/resources/TaskResource.java +++ b/src/main/java/it/grid/storm/tape/recalltable/resources/TaskResource.java @@ -107,7 +107,7 @@ public Response putTaskStatus(InputStream input) { String inputString = buildInputString(input); - log.debug("putTaskStatus() - Input:" + inputString); + log.debug("putTaskStatus() - Input: {}" , inputString); PutTapeRecallStatusValidator validator = new PutTapeRecallStatusValidator(inputString); @@ -127,7 +127,7 @@ public Response putTaskStatus(InputStream input) { } catch (TapeRecallException e) { - log.error("Error serving request. TapeRecallException: " + e.getMessage()); + log.error("Error serving request. TapeRecallException: {}" , e.getMessage() , e); response = Response.status(Status.INTERNAL_SERVER_ERROR).build(); @@ -147,11 +147,11 @@ public Response putTaskStatus(InputStream input) { public void putNewTaskStatusOrRetryValue(@PathParam("groupTaskId") UUID groupTaskId, InputStream input) throws TapeRecallException { - log.debug("Requested to change recall table value for taskId " + groupTaskId); + log.debug("Requested to change recall table value for taskId {}" , groupTaskId); String inputStr = buildInputString(input); - log.debug("@PUT (input string) = '" + inputStr + "'"); + log.debug("@PUT (input string) = '{}'" , inputStr); // Retrieve Tasks corresponding to taskId // - the relationship between groupTaskId and entries within the DB is @@ -165,14 +165,14 @@ public void putNewTaskStatusOrRetryValue(@PathParam("groupTaskId") UUID groupTas if (!rtCat.existsGroupTask(groupTaskId)) { - log.info("Received a tape recall status update but no Recall Group Task found with ID = '" + groupTaskId + "'"); + log.info("Received a tape recall status update but no Recall Group Task found with ID = '{}'" , groupTaskId); throw new TapeRecallException("No Recall Group Task found with ID = '" + groupTaskId + "'"); } } catch (DataAccessException e) { - log.error("Unable to retrieve Recall Group Task with ID = '" + groupTaskId + "' " + e.getMessage()); + log.error("Unable to retrieve Recall Group Task with ID = '{}' DataAccessException: {}" , groupTaskId , e.getMessage() , e); throw new TapeRecallException("Unable to retrieve recall group task " + "with ID = '" + groupTaskId + "' " + e.getMessage()); @@ -211,14 +211,14 @@ public void putNewTaskStatusOrRetryValue(@PathParam("groupTaskId") UUID groupTas if (key.equals(keyRetryValue)) { // **** Set the Retry value - log.debug("Changing retry attempt of task " + groupTaskId + " to " + intValue); + log.debug("Changing retry attempt of task {} to {}" , groupTaskId , intValue); rtCat.changeGroupTaskRetryValue(groupTaskId, intValue); } else { if (key.equals(keyStatus)) { // **** Set the Status - log.debug("Changing status of task " + groupTaskId + " to " + intValue); + log.debug("Changing status of task {} to {}" , groupTaskId , intValue); try { @@ -227,9 +227,7 @@ public void putNewTaskStatusOrRetryValue(@PathParam("groupTaskId") UUID groupTas } catch (DataAccessException e) { - log.error("Unable to change the status for group task id " - + groupTaskId + " to status " + intValue - + " . DataAccessException : " + e.getMessage()); + log.error("Unable to change the status for group task id {} to status {} DataAccessException : {}" , groupTaskId , intValue , e.getMessage() , e); throw new TapeRecallException( "Unable to change the status for group task id " + groupTaskId @@ -272,7 +270,7 @@ public Response postNewTask(TapeRecallTO task) { result = Response.created(newResource).build(); - log.debug("New task resource created: " + newResource); + log.debug("New task resource created: {}" , newResource); return result; } diff --git a/src/main/java/it/grid/storm/tape/recalltable/resources/TasksCardinality.java b/src/main/java/it/grid/storm/tape/recalltable/resources/TasksCardinality.java index dc697a64..f0d37a34 100644 --- a/src/main/java/it/grid/storm/tape/recalltable/resources/TasksCardinality.java +++ b/src/main/java/it/grid/storm/tape/recalltable/resources/TasksCardinality.java @@ -69,11 +69,11 @@ public Response getNumberQueued() { if (nQueued > 0) { - log.info("Number of tasks queued = " + nQueued); + log.info("Number of tasks queued = {}" , nQueued); } else { - log.trace("Number of tasks queued = " + nQueued); + log.trace("Number of tasks queued = {}" , nQueued); } numberQueued += nQueued; @@ -116,7 +116,7 @@ public Response getReadyForTakeover() { nReadyForTakeover = rtCat.getReadyForTakeOver(); - log.debug("Number of tasks queued = " + nReadyForTakeover); + log.debug("Number of tasks queued = {}" , nReadyForTakeover); numberReadyForTakeover += nReadyForTakeover; diff --git a/src/main/java/it/grid/storm/tape/recalltable/resources/TasksResource.java b/src/main/java/it/grid/storm/tape/recalltable/resources/TasksResource.java index 82bdebbe..19a391b9 100644 --- a/src/main/java/it/grid/storm/tape/recalltable/resources/TasksResource.java +++ b/src/main/java/it/grid/storm/tape/recalltable/resources/TasksResource.java @@ -74,7 +74,7 @@ public Response putTakeoverTasks(InputStream input) throws TapeRecallException { // retrieve the Input String String inputStr = buildInputString(input); - log.debug("@PUT (input string) = '" + inputStr + "'"); + log.debug("@PUT (input string) = '{}'" , inputStr); // retrieve the number of tasks to takeover (default = 1) int numbOfTask = 1; @@ -119,8 +119,8 @@ public Response putTakeoverTasks(InputStream input) throws TapeRecallException { } catch (IllegalArgumentException e) { - log.error("Unable to makeOne the task list . IllegalArgumentException : " + e.getMessage()); - log.error("Erroneous task list (long output): " + groupTaskList.toString()); + log.error("Unable to makeOne the task list . IllegalArgumentException : {}" , e.getMessage() , e); + log.error("Erroneous task list (long output): {}" , groupTaskList.toString()); log.error("Skip the erroneous task list and go on...Please contact StoRM support"); } } @@ -130,8 +130,7 @@ public Response putTakeoverTasks(InputStream input) throws TapeRecallException { log.debug("Taking over some multy-group tasks"); } - log.debug("Number of tasks recalled : <" + groupTasks.size() + "> over <" - + tasks.size() + "> tasks requested"); + log.debug("Number of tasks recalled : <{}> over <{}> tasks requested" , groupTasks.size() , tasks.size()); // need a generic entity GenericEntity> entity = @@ -188,8 +187,7 @@ private TapeRecallTO makeOne(ArrayList recallTasks) if (!recallTask.getTaskId().equals(taskId)) { - log.error("Received a list of not omogeneous tasks, the taskid \'" - + taskId + "\' is not matched by : " + recallTask.toString()); + log.error("Received a list of not omogeneous tasks, the taskid '{}' is not matched by : {}" , taskId , recallTask.toString()); throw new IllegalArgumentException( "Received a list of not omogeneous tasks"); From 14b434d805a41c0a4b035323575cbadf4cae6137 Mon Sep 17 00:00:00 2001 From: Andrea Ceccanti Date: Wed, 5 Feb 2014 11:03:50 +0100 Subject: [PATCH 19/45] Log messages rationalization. --- .../it/grid/storm/srm/types/ArrayOfSURLs.java | 2 +- .../storm/srm/types/ArrayOfTExtraInfo.java | 8 +- ...InvalidArrayOfSURLsAttributeException.java | 1 - .../grid/storm/srm/types/TAccessPattern.java | 1 - .../it/grid/storm/srm/types/TFileType.java | 1 - .../it/grid/storm/srm/types/TGroupID.java | 1 - .../storm/srm/types/TGroupPermission.java | 1 - .../storm/srm/types/TRetentionPolicy.java | 1 - .../java/it/grid/storm/srm/types/TSURL.java | 266 +-- .../srm/types/TSURLLifetimeReturnStatus.java | 2 - .../it/grid/storm/srm/types/TSizeInBytes.java | 5 +- .../java/it/grid/storm/srm/types/TTURL.java | 18 +- .../storm/srm/types/TTransferParameters.java | 10 - .../java/it/grid/storm/srm/types/TUserID.java | 8 +- .../java/it/grid/storm/startup/Bootstrap.java | 70 +- .../synchcall/command/AbstractCommand.java | 10 + .../synchcall/command/CommandFactory.java | 6 +- .../synchcall/command/CommandHelper.java | 188 +- .../command/DataTransferCommand.java | 9 +- .../synchcall/command/DirectoryCommand.java | 9 +- .../synchcall/command/DiscoveryCommand.java | 9 +- .../storm/synchcall/command/SpaceCommand.java | 9 +- .../command/SurlStatusCommandHelper.java | 2 +- .../datatransfer/AbortFilesCommand.java | 297 ++- .../datatransfer/AbortRequestCommand.java | 225 +-- .../command/directory/LsCommand.java | 173 +- .../command/directory/MkdirCommand.java | 106 +- .../command/directory/MvCommand.java | 192 +- .../command/directory/RmCommand.java | 109 +- .../command/directory/RmdirCommand.java | 60 +- .../java/it/grid/storm/synchcall/xmlrpc.cld | 1646 ----------------- 31 files changed, 797 insertions(+), 2648 deletions(-) create mode 100644 src/main/java/it/grid/storm/synchcall/command/AbstractCommand.java delete mode 100644 src/main/java/it/grid/storm/synchcall/xmlrpc.cld diff --git a/src/main/java/it/grid/storm/srm/types/ArrayOfSURLs.java b/src/main/java/it/grid/storm/srm/types/ArrayOfSURLs.java index 7016c92d..2933b725 100644 --- a/src/main/java/it/grid/storm/srm/types/ArrayOfSURLs.java +++ b/src/main/java/it/grid/storm/srm/types/ArrayOfSURLs.java @@ -94,7 +94,7 @@ public static ArrayOfSURLs decode(Map inputParam, String name) */ list = Arrays.asList((Object[]) inputParam.get(name)); } catch (NullPointerException e) { - // log.warn("Empty SURL array found!"); + } if (list == null) { diff --git a/src/main/java/it/grid/storm/srm/types/ArrayOfTExtraInfo.java b/src/main/java/it/grid/storm/srm/types/ArrayOfTExtraInfo.java index 10ee3094..2fed4e20 100644 --- a/src/main/java/it/grid/storm/srm/types/ArrayOfTExtraInfo.java +++ b/src/main/java/it/grid/storm/srm/types/ArrayOfTExtraInfo.java @@ -30,7 +30,12 @@ public class ArrayOfTExtraInfo implements Serializable { - public static String PNAME_STORAGESYSTEMINFO = "storageSystemInfo"; + /** + * + */ + private static final long serialVersionUID = 1L; + + public static String PNAME_STORAGESYSTEMINFO = "storageSystemInfo"; private ArrayList extraInfoList; @@ -44,7 +49,6 @@ public ArrayOfTExtraInfo(TExtraInfo[] infoArray) if (infoArray == null) { throw new InvalidArrayOfTExtraInfoAttributeException(infoArray); } - // FIXME this.tokenArray = tokenArray; } public ArrayOfTExtraInfo() { diff --git a/src/main/java/it/grid/storm/srm/types/InvalidArrayOfSURLsAttributeException.java b/src/main/java/it/grid/storm/srm/types/InvalidArrayOfSURLsAttributeException.java index 1faca0d5..a37852a3 100644 --- a/src/main/java/it/grid/storm/srm/types/InvalidArrayOfSURLsAttributeException.java +++ b/src/main/java/it/grid/storm/srm/types/InvalidArrayOfSURLsAttributeException.java @@ -27,7 +27,6 @@ package it.grid.storm.srm.types; import java.util.List; -import java.util.Vector; public class InvalidArrayOfSURLsAttributeException extends Exception { diff --git a/src/main/java/it/grid/storm/srm/types/TAccessPattern.java b/src/main/java/it/grid/storm/srm/types/TAccessPattern.java index 6830fedb..3ba636a3 100644 --- a/src/main/java/it/grid/storm/srm/types/TAccessPattern.java +++ b/src/main/java/it/grid/storm/srm/types/TAccessPattern.java @@ -25,7 +25,6 @@ */ package it.grid.storm.srm.types; -import java.util.Hashtable; import java.util.Map; public class TAccessPattern { diff --git a/src/main/java/it/grid/storm/srm/types/TFileType.java b/src/main/java/it/grid/storm/srm/types/TFileType.java index 12932772..08f7df34 100644 --- a/src/main/java/it/grid/storm/srm/types/TFileType.java +++ b/src/main/java/it/grid/storm/srm/types/TFileType.java @@ -17,7 +17,6 @@ package it.grid.storm.srm.types; -import java.util.Hashtable; import java.util.Map; /** diff --git a/src/main/java/it/grid/storm/srm/types/TGroupID.java b/src/main/java/it/grid/storm/srm/types/TGroupID.java index cb9d068f..7dcab8fb 100644 --- a/src/main/java/it/grid/storm/srm/types/TGroupID.java +++ b/src/main/java/it/grid/storm/srm/types/TGroupID.java @@ -26,7 +26,6 @@ package it.grid.storm.srm.types; -import java.util.Hashtable; import java.util.Map; public class TGroupID { diff --git a/src/main/java/it/grid/storm/srm/types/TGroupPermission.java b/src/main/java/it/grid/storm/srm/types/TGroupPermission.java index e5e65e37..f52d4ea0 100644 --- a/src/main/java/it/grid/storm/srm/types/TGroupPermission.java +++ b/src/main/java/it/grid/storm/srm/types/TGroupPermission.java @@ -27,7 +27,6 @@ package it.grid.storm.srm.types; import java.util.HashMap; -import java.util.Hashtable; import java.util.Map; public class TGroupPermission { diff --git a/src/main/java/it/grid/storm/srm/types/TRetentionPolicy.java b/src/main/java/it/grid/storm/srm/types/TRetentionPolicy.java index 68feff70..9e722e2a 100644 --- a/src/main/java/it/grid/storm/srm/types/TRetentionPolicy.java +++ b/src/main/java/it/grid/storm/srm/types/TRetentionPolicy.java @@ -25,7 +25,6 @@ */ package it.grid.storm.srm.types; -import java.util.Hashtable; import java.util.Map; public class TRetentionPolicy { diff --git a/src/main/java/it/grid/storm/srm/types/TSURL.java b/src/main/java/it/grid/storm/srm/types/TSURL.java index 7eea6529..1e6c8236 100644 --- a/src/main/java/it/grid/storm/srm/types/TSURL.java +++ b/src/main/java/it/grid/storm/srm/types/TSURL.java @@ -52,6 +52,9 @@ public class TSURL { private static Logger log = LoggerFactory.getLogger(TSURL.class); + + private static final String EMPTY_STRING = ""; + /** * The surl as provided by User */ @@ -71,35 +74,41 @@ public class TSURL { private static LinkedList defaultPorts = new LinkedList(); static { + // Lazy initialization from Configuration if (tsurlManaged.isEmpty()) { - // This is the first call + TSURL checkTSURL; String[] surlValid = Configuration.getInstance().getManagedSURLs(); for (String checkSurl : surlValid) { - // Building TSURL - try {// TODO MICHELE USER_SURL FIXME!!! here the generated SURL has the - // port added also if it is blank!! + try { + checkTSURL = TSURL.makeFromStringWellFormed(checkSurl); tsurlManaged.add(checkTSURL); - log.debug("### SURL Managed : " + checkTSURL); + log.debug("### SURL Managed : {}",checkTSURL); + } catch (InvalidTSURLAttributesException e) { - log.error("Unable to build a TSURL : '" + checkSurl + "'"); + + log.error("Unable to build a TSURL : {}", checkSurl, e); } } } + if (defaultPorts.isEmpty()) { - // This is the first call + Integer[] ports = Configuration.getInstance() .getManagedSurlDefaultPorts(); + for (Integer portInteger : ports) { - // Building Port try { defaultPorts.add(Port.make(portInteger.intValue())); - log.debug("### Default SURL port : " + defaultPorts.getLast()); + log.debug("### Default SURL port : {}", defaultPorts.getLast()); + } catch (InvalidPortAttributeException e) { - log.error("Unable to build a Port : '" + portInteger + "'" + e); + + log.error("Unable to build a Port : {}", portInteger , e); + } } } @@ -111,6 +120,7 @@ private TSURL(SiteProtocol sp, SFN sfn, String rawSurl, boolean empty) { this.sfn = sfn; this.rawSurl = rawSurl; this.empty = empty; + } /** @@ -134,83 +144,91 @@ public static TSURL decode(Map inputParam, String name) * @return * @throws InvalidTSURLAttributesException */ - // TODO MICHELE USER_SURL as it is now we don't need to pass through the SURL - // object, maybe it will be useful for the equals method and storm normal form - public static TSURL getWellFormed(SURL surl, String rawSurl) - throws InvalidTSURLAttributesException { + public static TSURL getWellFormed(SURL surl, String rawSurl) + throws InvalidTSURLAttributesException { - TSURL result; - SFN sfn; - // TODO MICHELE USER_SURL - Machine machine = null; - try { - machine = Machine.make(surl.getServiceHostname()); - log.debug("Machine built : '" + machine + "'"); - } catch (InvalidMachineAttributeException ex1) { - log.error("MACHINE '" + surl.getServiceHostname() + "' is invalid! "); - throw new InvalidTSURLAttributesException(null, null); - } + TSURL result; + SFN sfn; + Machine machine = null; + String stfn = null; + EndPoint serviceEndpoint = null; + Port port = null; - String stfn = surl.getStFN(); - StFN stfnClass = null; - try { - stfnClass = StFN.make(stfn); - log.debug("StFN Class built : '" + stfnClass + "'"); - } catch (InvalidStFNAttributeException ex2) { - log.error("StFN '" + stfn + "' is invalid! "); - throw new InvalidTSURLAttributesException(null, null); - } - int portInt = surl.getServiceHostPort(); - - EndPoint serviceEndpoint = null; - if (surl.isQueriedFormSURL()) { - String serviceEndPointString = surl.getServiceEndPoint(); - try { - serviceEndpoint = EndPoint.make(serviceEndPointString); - log.debug("EndPoint built : '" + serviceEndpoint + "'"); - } catch (InvalidEndPointAttributeException e) { - log.error("EndPoint '" + serviceEndpoint + "' is invalid! " + e); - throw new InvalidTSURLAttributesException(null, null); - } - } + try { - if (portInt > -1) { - Port port = null; - try { - port = Port.make(portInt); - log.debug("PORT built : '" + port + "'"); - } catch (InvalidPortAttributeException ex3) { - log.error("PORT '" + portInt + "' is invalid! "); - throw new InvalidTSURLAttributesException(null, null); - } - try { - if (serviceEndpoint == null) { - sfn = SFN.makeInSimpleForm(machine, port, stfnClass); - } else { - sfn = SFN.makeInQueryForm(machine, port, serviceEndpoint, stfnClass); - } + machine = Machine.make(surl.getServiceHostname()); - log.debug("SFN built : '" + sfn + "'"); - } catch (InvalidSFNAttributesException ex4) { - log.error("SFN building problem"); - throw new InvalidTSURLAttributesException(null, null); - } - } else { - try { - if (serviceEndpoint == null) { - sfn = SFN.makeInSimpleForm(machine, stfnClass); - } else { - sfn = SFN.makeInQueryForm(machine, serviceEndpoint, stfnClass); - } - log.debug("SFN built : '" + sfn + "'"); - } catch (InvalidSFNAttributesException ex5) { - log.error("SFN building problem"); - throw new InvalidTSURLAttributesException(null, null); - } - } - result = TSURL.make(SiteProtocol.SRM, sfn, rawSurl); - return result; - } + log.debug("Machine: {}", machine); + + stfn = surl.getStFN(); + StFN stfnClass = StFN.make(stfn); + + log.debug("StFN Class: {}", stfnClass); + + if (surl.isQueriedFormSURL()) { + String serviceEndPointString = surl.getServiceEndPoint(); + + serviceEndpoint = EndPoint.make(serviceEndPointString); + log.debug("EndPoint: {}", serviceEndpoint); + + } + + if (surl.getServiceHostPort() > -1) { + + port = Port.make(surl.getServiceHostPort()); + log.debug("Port: {}", port); + + } + + if (port != null) { + + if (serviceEndpoint == null) { + sfn = SFN.makeInSimpleForm(machine, port, stfnClass); + } else { + sfn = SFN.makeInQueryForm(machine, port, serviceEndpoint, stfnClass); + } + + } else { + + if (serviceEndpoint == null) { + sfn = SFN.makeInSimpleForm(machine, stfnClass); + } else { + sfn = SFN.makeInQueryForm(machine, serviceEndpoint, stfnClass); + } + } + + log.debug("SFN: {}", sfn); + + result = TSURL.make(SiteProtocol.SRM, sfn, rawSurl); + return result; + + } catch (InvalidMachineAttributeException e) { + + log.error("Invalid machine: {}", surl.getServiceHostname(), e); + throw new InvalidTSURLAttributesException(null, null); + + } catch (InvalidStFNAttributeException e) { + + log.error("Invalid StFN: {}", stfn, e); + throw new InvalidTSURLAttributesException(null, null); + + } catch (InvalidEndPointAttributeException e) { + + log.error("Invalid endpoint: {}", serviceEndpoint, e); + throw new InvalidTSURLAttributesException(null, null); + + } catch (InvalidPortAttributeException e) { + + log.error("Invalid port: {}", surl.getServiceHostPort(), e); + throw new InvalidTSURLAttributesException(null, null); + + } catch (InvalidSFNAttributesException e) { + + log.error("Error building SFN: {}", e.getMessage(), e); + throw new InvalidTSURLAttributesException(null, null); + } + + } /** * Static factory method that returns a TSURL and that requires the @@ -259,21 +277,24 @@ public static TSURL makeFromStringWellFormed(String surlString) sp = SiteProtocol.fromString(spString); } catch (IllegalArgumentException e) { // do nothing - sp remains null and that is fine! - log.warn("TSURL: Site protocol by '" + spString - + "' is empty, but that's fine."); + log.warn("TSURL: Site protocol by {} is empty, but that's fine.", + spString); } if ((separator + 3) > (surlString.length())) { // separator found at the end! throw new InvalidTSURLAttributesException(sp, null); } - log.debug("MAKE SURL : '" + surlString + "'"); + + log.debug("SURL string: {}", surlString); SURL surl; + try { surl = SURL.makeSURLfromString(surlString); } catch (NamespaceException ex) { - log.error("SURL '" + surlString + "' is invalid! "); + log.error("Invalid surl: {}", surlString, ex); throw new InvalidTSURLAttributesException(null, null); } + result = getWellFormed(surl, surlString); return result; @@ -286,13 +307,13 @@ public static TSURL makeFromStringWellFormed(String surlString) public static TSURL makeFromStringValidate(String surlString) throws InvalidTSURLAttributesException { - log.debug("MAKE SURL in Validating mode: '" + surlString + "'"); - // TODO MICHELE USER_SURL TSURL tsurl = makeFromStringWellFormed(surlString); - if (!(isValid(tsurl))) { - log.warn("The SURL '" + tsurl - + "' is not managed by this instance of StoRM"); + + if (!isValid(tsurl)) { + + log.warn("SURL {} is not managed by this StoRM instance.", tsurl); throw new InvalidTSURLAttributesException(tsurl.sp, tsurl.sfn()); + } return tsurl; } @@ -303,9 +324,6 @@ public static TSURL makeFromStringValidate(String surlString) * */ public static boolean isValid(TSURL surl) { - - // TODO MICHELE USER_SURL moved code from isValid to isManaged to support in - // future managedSurl separation by VO return isManaged(surl, TSURL.tsurlManaged); } @@ -334,32 +352,32 @@ public static boolean isManaged(TSURL surl, List managedSurls) { private static boolean isSURLManaged(TSURL comingSURL, TSURL managedSURL) { boolean result = false; - // TODO MICHELE USER_SURL String serviceHost = comingSURL.sfn().machine().toString(); String expectedServiceHost = managedSURL.sfn().machine().toString(); - log.debug("SURL VALID [ coming-service-host = '" + serviceHost - + "' expected : '" + expectedServiceHost + "'"); + + log.debug("SURL VALID [ coming-service-host = {}, expected = {} ]", + serviceHost, expectedServiceHost); if (comingSURL.sfn().port().isEmpty()) { - // no port, check the host + if (serviceHost.equalsIgnoreCase(expectedServiceHost)) { result = true; } } else { - // we got port + if (!managedSURL.sfn().port().isEmpty()) { - // both got port, normal check + int expectedServicePort = managedSURL.sfn().port().toInt(); int port = comingSURL.sfn().port().toInt(); - log.debug("SURL VALID [ coming-service-port = '" + port - + "' expected : '" + expectedServicePort + "'"); + + log.debug("SURL VALID [ coming-service-port = {}, expected = {} ]", + port, expectedServicePort); + if ((serviceHost.equalsIgnoreCase(expectedServiceHost)) && (expectedServicePort == port)) { result = true; } } else { - // surl with port, managed surl without, check the default ports and the - // host int port = comingSURL.sfn().port().toInt(); try { Port comingPort = Port.make(port); @@ -368,28 +386,18 @@ private static boolean isSURLManaged(TSURL comingSURL, TSURL managedSURL) { result = true; } } catch (InvalidPortAttributeException e) { - log.warn("The SURL '" + comingSURL - + "' has ha not valid port. Unable to create the Port : " + e); - + log.error("Invalid surl: {}", comingSURL, e); } } } return result; } - /** - * Encode TSURL for FE communication. - */ public void encode(Map param, String name) { param.put(name, toString()); } - /* - * (non-Javadoc) - * - * @see java.lang.Object#hashCode() - */ @Override public int hashCode() { @@ -406,11 +414,6 @@ public int hashCode() { return result; } - /* - * (non-Javadoc) - * - * @see java.lang.Object#equals(java.lang.Object) - */ @Override public boolean equals(Object obj) { @@ -469,9 +472,15 @@ public boolean equals(Object obj) { public String getSURLString() { if (empty) { - return ""; + return EMPTY_STRING; } - return sp + "://" + sfn; + + StringBuilder builder = new StringBuilder(); + builder.append(sp); + builder.append("://"); + builder.append(sfn); + + return builder.toString(); } public boolean isEmpty() { @@ -511,7 +520,6 @@ public SFN sfn() { return sfn; } - // TODO MICHELE USER_SURL /** * @return */ @@ -536,13 +544,11 @@ public void setNormalizedStFN(String normalizedStFN) { * @param uniqueID * the uniqueID to set */ - // TODO MICHELE USER_SURL public void setUniqueID(int uniqueID) { this.uniqueID = uniqueID; } - // TODO MICHELE USER_SURL /** * @return */ @@ -560,6 +566,12 @@ public String toString() { if (empty) { return "Empty TSURL"; } - return sp + "://" + sfn; + + StringBuilder builder = new StringBuilder(); + builder.append(sp); + builder.append("://"); + builder.append(sfn); + + return builder.toString(); } } diff --git a/src/main/java/it/grid/storm/srm/types/TSURLLifetimeReturnStatus.java b/src/main/java/it/grid/storm/srm/types/TSURLLifetimeReturnStatus.java index 9d42560a..dfd518ae 100644 --- a/src/main/java/it/grid/storm/srm/types/TSURLLifetimeReturnStatus.java +++ b/src/main/java/it/grid/storm/srm/types/TSURLLifetimeReturnStatus.java @@ -27,10 +27,8 @@ package it.grid.storm.srm.types; import java.util.HashMap; -import java.util.Hashtable; import java.util.List; import java.util.Map; -import java.util.Vector; public class TSURLLifetimeReturnStatus { diff --git a/src/main/java/it/grid/storm/srm/types/TSizeInBytes.java b/src/main/java/it/grid/storm/srm/types/TSizeInBytes.java index 1bb18438..c9f7ec6d 100644 --- a/src/main/java/it/grid/storm/srm/types/TSizeInBytes.java +++ b/src/main/java/it/grid/storm/srm/types/TSizeInBytes.java @@ -25,12 +25,11 @@ */ package it.grid.storm.srm.types; +import it.grid.storm.common.types.SizeUnit; + import java.io.Serializable; -import java.util.Hashtable; import java.util.Map; -import it.grid.storm.common.types.*; - public class TSizeInBytes implements Serializable { public static String PNAME_SIZE = "size"; diff --git a/src/main/java/it/grid/storm/srm/types/TTURL.java b/src/main/java/it/grid/storm/srm/types/TTURL.java index 7b2b23bd..3deaa6e4 100644 --- a/src/main/java/it/grid/storm/srm/types/TTURL.java +++ b/src/main/java/it/grid/storm/srm/types/TTURL.java @@ -96,9 +96,8 @@ public static TTURL makeFromString(String s) try { tp = TransferProtocol.getTransferProtocol(tpString); } catch (IllegalArgumentException e) { - // do nothing - tp remains null and that is fine! - log.warn("TTURL: Transfer protocol by '" + tpString - + "' is empty, but that's fine."); + log.warn("TTURL: Transfer protocol by {} is empty, but that's fine.", + tpString); } if ((separator + 3) > (s.length())) { throw new InvalidTTURLAttributesException(tp, null); // separator found at @@ -107,25 +106,18 @@ public static TTURL makeFromString(String s) String tfnString = s.substring(separator + 3, s.length()); TFN tfn = null; if (tfnString.startsWith("/")) { - // TFN without hostname and port try { tfn = TFN.makeByPFN(PFN.make(tfnString)); } catch (InvalidTFNAttributesException e) { - // do nothing - tfn remains null and that is fine: an exception will be - // thrown later on! - log.warn("TFN by '" + tfnString + "' is empty, but that's fine."); + log.warn("TFN by {} is empty, but that's fine.", tfnString); } catch (InvalidPFNAttributeException ex) { - /** @todo Handle this exception */ - log.error("PFN by '" + tfnString + "' cause an error : " + ex); + log.error("Invalid PFN: {}", tfnString, ex); } } else { - // TFN does have host and port! try { tfn = TFN.makeFromString(tfnString); } catch (InvalidTFNAttributesException e) { - // do nothing - tfn remains null and that is fine: an exception will be - // thrown later on! - log.warn("TFN by '" + tfnString + "' is empty, but that's fine."); + log.warn("TFN by {} is empty, but that's fine.", tfnString); } } return TTURL.make(tp, tfn); diff --git a/src/main/java/it/grid/storm/srm/types/TTransferParameters.java b/src/main/java/it/grid/storm/srm/types/TTransferParameters.java index 24bd0448..22e0c49f 100644 --- a/src/main/java/it/grid/storm/srm/types/TTransferParameters.java +++ b/src/main/java/it/grid/storm/srm/types/TTransferParameters.java @@ -30,16 +30,10 @@ import java.util.List; import java.util.Map; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - public class TTransferParameters implements Serializable { private static final long serialVersionUID = 7309411351545907539L; - private static final Logger log = LoggerFactory - .getLogger(TTransferParameters.class); - public static final String PNAME_transferParameters = "transferParameters"; private TAccessPattern accessPattern = null; @@ -106,11 +100,9 @@ public static TTransferParameters decode(Map param) { TConnectionType.PNAME_connectionType); memberName = new String("arrayOfClientNetworks"); - // vector = (Hashtable) param.get(memberName); try { vector = Arrays.asList((Object[]) param.get(memberName)); } catch (NullPointerException e) { - // log.warn("Empty SURL array found!"); } if (vector != null) { @@ -122,11 +114,9 @@ public static TTransferParameters decode(Map param) { } memberName = new String("arrayOfTransferProtocols"); - // vector = (Hashtable) param.get(memberName); try { vector = Arrays.asList((Object[]) param.get(memberName)); } catch (NullPointerException e) { - // log.warn("Empty SURL array found!"); } if (vector != null) { int arraySize = vector.size(); diff --git a/src/main/java/it/grid/storm/srm/types/TUserID.java b/src/main/java/it/grid/storm/srm/types/TUserID.java index 254fc979..e22c1d98 100644 --- a/src/main/java/it/grid/storm/srm/types/TUserID.java +++ b/src/main/java/it/grid/storm/srm/types/TUserID.java @@ -52,10 +52,14 @@ public TUserID(String id) throws InvalidTUserIDAttributeException { public static TUserID makeEmpty() { try { + return new TUserID("Unknown."); + } catch (InvalidTUserIDAttributeException e) { - log.error("Strange. Exception shold be never thrown here." + e); - } + + log.error("Invalid TUserID: {}", e.getMessage(), e); + } + return null; } diff --git a/src/main/java/it/grid/storm/startup/Bootstrap.java b/src/main/java/it/grid/storm/startup/Bootstrap.java index 2b0bc982..269d778e 100644 --- a/src/main/java/it/grid/storm/startup/Bootstrap.java +++ b/src/main/java/it/grid/storm/startup/Bootstrap.java @@ -28,7 +28,7 @@ import java.io.File; import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -87,8 +87,11 @@ public static void initializePathAuthz(String pathAuthzDBFileName) try { AuthzDirector.initializePathAuthz(pathAuthzDBFileName); } catch (DirectorException e) { - log.error("Unable to initialize the AuthzDirector : " + e); - throw new BootstrapException("Unable to initialize the AuthzDirector"); + + log.error("Unable to initialize the AuthzDirector: {}", + e.getMessage(), e); + + throw new BootstrapException("Unable to initialize the AuthzDirector",e); } } @@ -97,12 +100,11 @@ public static void initializeUsedSpace() { int numberOfSpaceInitialized = SpaceInfoManager.getInstance() .initSpaceFromINIFile(); - log.info("Initialized '" + numberOfSpaceInitialized - + "' SA from 'used-space.ini'"); + log.info("Initialized {} SA from used-space.ini", numberOfSpaceInitialized); SpaceInfoManager.getInstance().updateSpaceUsed(); int numberOfBgDU = SpaceInfoManager.howManyBackgroundDU(); - log.info("Submitted '" + numberOfBgDU + "' background DU tasks."); + log.info("Submitted {} background DU tasks.", numberOfBgDU); } /** @@ -112,62 +114,52 @@ public static void initializeUsedSpace() { public static void initializeAclManager(String httpsInterfaceClassName, Logger log) { - log.debug("Obtaining an instance of class " + httpsInterfaceClassName); + log.debug("ACL manager. httpsInterfaceClassName: {}", + httpsInterfaceClassName); + Class httpsInterfaceClass = null; try { httpsInterfaceClass = Class.forName(httpsInterfaceClassName); } catch (ClassNotFoundException e) { - log.error("Unable to load https plugin class" + httpsInterfaceClassName - + " . ClassNotFoundException : " + e.getMessage()); + log.error("Unable to load https plugin class {}. Message: {}", + httpsInterfaceClassName, e.getMessage(), e); return; } if (!HTTPSPluginInterface.class.isAssignableFrom(httpsInterfaceClass)) { - log - .error("The class specified \'" - + httpsInterfaceClassName - + "\' does not implements the Interface HTTPSPluginInterface. Unable to load the https plugin"); + log.error("Unable to load the https plugin. " + + "The specified class '{}' does not implement " + + "the HTTPSPluginInterface.", + httpsInterfaceClassName); return; } + Constructor c = null; + try { c = httpsInterfaceClass.getConstructor(null); - } catch (SecurityException e) { - log.error("Unable to load a no argument constructor for class " - + httpsInterfaceClassName + " SecurityException : " + e.getMessage()); - return; - } catch (NoSuchMethodException e) { - log.error("Unable to load a no argument constructor for class " - + httpsInterfaceClassName + " NoSuchMethodException : " - + e.getMessage()); + } catch (Throwable e) { + log.error("Error instantiating https plugin: {}", e.getMessage(),e); return; } + Class[] parameters = c.getParameterTypes(); + if (parameters != null && parameters.length > 0) { - log.error("Unable to construct an instance of class " + parameters.length - + " It does not provides a no argument constructor"); + log.error("Invalid number of arguments for https plugin constructor."); return; } + HTTPSPluginInterface httpsInterface = null; try { httpsInterface = (HTTPSPluginInterface) c.newInstance(); - } catch (IllegalArgumentException e) { - log.error("Unable to isntantiate class " + httpsInterfaceClassName - + " IllegalArgumentException : " + e.getMessage()); - return; - } catch (InstantiationException e) { - log.error("Unable to isntantiate class " + httpsInterfaceClassName - + " InstantiationException : " + e.getMessage()); - return; - } catch (IllegalAccessException e) { - log.error("Unable to isntantiate class " + httpsInterfaceClassName - + " IllegalAccessException : " + e.getMessage()); - return; - } catch (InvocationTargetException e) { - log.error("Unable to isntantiate class " + httpsInterfaceClassName - + " InvocationTargetException : " + e.getMessage()); + } catch (Throwable e) { + log.error("Error instantiating HTTPS plugin {}: {}", + httpsInterfaceClassName, + e.getMessage(), e); return; } - log.info("Initializing AclManager"); + + log.info("Initializing ACL manager"); HTTPPluginManager.init(httpsInterface); log.info("ACL manager initialization completed"); } diff --git a/src/main/java/it/grid/storm/synchcall/command/AbstractCommand.java b/src/main/java/it/grid/storm/synchcall/command/AbstractCommand.java new file mode 100644 index 00000000..41e8429f --- /dev/null +++ b/src/main/java/it/grid/storm/synchcall/command/AbstractCommand.java @@ -0,0 +1,10 @@ +package it.grid.storm.synchcall.command; + +import it.grid.storm.config.Configuration; + + +public abstract class AbstractCommand implements Command { + + protected static Configuration config = Configuration.getInstance(); + +} diff --git a/src/main/java/it/grid/storm/synchcall/command/CommandFactory.java b/src/main/java/it/grid/storm/synchcall/command/CommandFactory.java index cffb010b..5bbebdda 100644 --- a/src/main/java/it/grid/storm/synchcall/command/CommandFactory.java +++ b/src/main/java/it/grid/storm/synchcall/command/CommandFactory.java @@ -94,9 +94,9 @@ public static Command getCommand(OperationType type) return new PrepareToGetRequestStatusCommand(); default: - log.error("No Command available for OperationType " + type); - throw new IllegalArgumentException( - "No Command available for OperationType " + type); + String msg = String.format("No command found for OperationType %s", type); + log.error(msg); + throw new IllegalArgumentException(msg); } } diff --git a/src/main/java/it/grid/storm/synchcall/command/CommandHelper.java b/src/main/java/it/grid/storm/synchcall/command/CommandHelper.java index 1c3e3d64..d76b974f 100644 --- a/src/main/java/it/grid/storm/synchcall/command/CommandHelper.java +++ b/src/main/java/it/grid/storm/synchcall/command/CommandHelper.java @@ -1,7 +1,6 @@ package it.grid.storm.synchcall.command; -import java.util.List; -import org.slf4j.Logger; +import it.grid.storm.srm.types.ArrayOfSURLs; import it.grid.storm.srm.types.InvalidTReturnStatusAttributeException; import it.grid.storm.srm.types.InvalidTSURLReturnStatusAttributeException; import it.grid.storm.srm.types.TRequestToken; @@ -12,8 +11,36 @@ import it.grid.storm.synchcall.data.DataHelper; import it.grid.storm.synchcall.data.InputData; -public class CommandHelper { +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.slf4j.Logger; +public class CommandHelper { + + public static final Map STATUS_MESSAGES; + private static final String FAILED_STRING = "failed"; + + static{ + + STATUS_MESSAGES = new HashMap(); + STATUS_MESSAGES.put(TStatusCode.SRM_SUCCESS, "succesfully done"); + STATUS_MESSAGES.put(TStatusCode.SRM_SPACE_AVAILABLE, "succesfully done"); + STATUS_MESSAGES.put(TStatusCode.SRM_FILE_PINNED, "succesfully done"); + STATUS_MESSAGES.put(TStatusCode.SRM_PARTIAL_SUCCESS, "partially succeded"); + + } + + private static String getStatusMessage(TStatusCode statusCode){ + + String result = STATUS_MESSAGES.get(statusCode); + if (result == null) + return FAILED_STRING; + + return result; + } + public static TReturnStatus buildStatus(TStatusCode statusCode, String explaination) throws IllegalArgumentException, IllegalStateException { @@ -24,7 +51,6 @@ public static TReturnStatus buildStatus(TStatusCode statusCode, try { return new TReturnStatus(statusCode, explaination); } catch (InvalidTReturnStatusAttributeException e) { - // Never thrown throw new IllegalStateException( "Unexpected InvalidTReturnStatusAttributeException " + "in building TReturnStatus: " + e.getMessage()); @@ -43,7 +69,6 @@ public static TSURLReturnStatus buildStatus(TSURL surl, try { return new TSURLReturnStatus(surl, returnStatus); } catch (InvalidTSURLReturnStatusAttributeException e) { - // Never thrown throw new IllegalStateException( "Unexpected InvalidTSURLReturnStatusAttributeException " + "in building TSURLReturnStatus: " + e.getMessage()); @@ -52,113 +77,98 @@ public static TSURLReturnStatus buildStatus(TSURL surl, public static void printRequestOutcome(String srmCommand, Logger log, TReturnStatus status) { - - if (status.getStatusCode().equals(TStatusCode.SRM_SUCCESS)) { - log.info(srmCommand + ": Request successfully done with: [status: " - + status + "]"); - } else { - if (status.getStatusCode().equals(TStatusCode.SRM_PARTIAL_SUCCESS)) { - log.info(srmCommand + ": Request partially done with [status: " - + status + "]"); - } else { - log.info(srmCommand + ": Request failed with [status: " + status + "]"); - } - } + + log.info("{}: Request {} with: [status: {}]", + srmCommand, + getStatusMessage(status.getStatusCode()), + status); } public static void printRequestOutcome(String srmCommand, Logger log, TReturnStatus status, InputData inputData) { - if (status.getStatusCode().equals(TStatusCode.SRM_SUCCESS)) { - log.info(srmCommand + ": user <" + DataHelper.getRequestor(inputData) - + "> Request successfully done with: [status: " + status + "]"); - } else { - if (status.getStatusCode().equals(TStatusCode.SRM_PARTIAL_SUCCESS)) { - log.info(srmCommand + ": <" + DataHelper.getRequestor(inputData) - + "> Request partially done with [status: " + status + "]"); - } else { - log.info(srmCommand + ": <" + DataHelper.getRequestor(inputData) - + "> Request failed with [status: " + status + "]"); - } - } + log.info("{}: user <{}> Request {} with: [status: {}]", + srmCommand, + DataHelper.getRequestor(inputData), + getStatusMessage(status.getStatusCode()), + status); + } public static void printRequestOutcome(String srmCommand, Logger log, TReturnStatus status, InputData inputData, List surls) { - if (status.getStatusCode().equals(TStatusCode.SRM_SUCCESS)) { - log.info(srmCommand + ": user <" + DataHelper.getRequestor(inputData) - + "> Request for [SURL: " + surls - + "] successfully done with: [status: " + status + "]"); - } else { - if (status.getStatusCode().equals(TStatusCode.SRM_PARTIAL_SUCCESS)) { - log.info(srmCommand + ": <" + DataHelper.getRequestor(inputData) - + "> Request for [SURL: " + surls + "] partially done with [status: " - + status + "]"); - } else { - log.info(srmCommand + ": <" + DataHelper.getRequestor(inputData) - + "> Request for [SURL: " + surls + "] failed with [status: " - + status + "]"); - } - } + log.info("{}: user <{}> Request for [SURL: {}] {} with: [status: {}]", + srmCommand, + DataHelper.getRequestor(inputData), + surls, + getStatusMessage(status.getStatusCode()), + status); + } + + public static void printRequestOutcome(String srmCommand, Logger log, + TReturnStatus status, InputData inputData, TRequestToken token, ArrayOfSURLs surls) { + + log.info("{}: user <{}> Request for [token: {}] for [SURL: {}] {} with: [status: {}]", + srmCommand, + DataHelper.getRequestor(inputData), + token, + surls, + getStatusMessage(status.getStatusCode()), + status); } public static void printRequestOutcome(String srmCommand, Logger log, TReturnStatus status, InputData inputData, TRequestToken token) { + + log.info("{}: user <{}> Request for [token: {}] {} with: [status: {}]", + srmCommand, + DataHelper.getRequestor(inputData), + token, + getStatusMessage(status.getStatusCode()), + status); - if (status.getStatusCode().equals(TStatusCode.SRM_SUCCESS)) { - log.info(srmCommand + ": user <" + DataHelper.getRequestor(inputData) - + "> Request for [token:" + token - + "] successfully done with: [status: " + status + "]"); - } else { - if (status.getStatusCode().equals(TStatusCode.SRM_PARTIAL_SUCCESS)) { - log.info(srmCommand + ": <" + DataHelper.getRequestor(inputData) - + "> Request for [token:" + token + "] partially done with [status: " - + status + "]"); - } else { - log.info(srmCommand + ": <" + DataHelper.getRequestor(inputData) - + "> Request for [token:" + token + "] failed with [status: " - + status + "]"); - } - } } public static void printRequestOutcome(String srmCommand, Logger log, TReturnStatus status, InputData inputData, TRequestToken token, List surls) { - - if (status.getStatusCode().equals(TStatusCode.SRM_SUCCESS) - || status.getStatusCode().equals(TStatusCode.SRM_SPACE_AVAILABLE) - || status.getStatusCode().equals(TStatusCode.SRM_FILE_PINNED)) { - log.info(srmCommand + ": user <" + DataHelper.getRequestor(inputData) - + "> Request for [token:" + token + "] for [SURL: " + surls - + "] successfully done with: [status: " + status + "]"); - } else { - if (status.getStatusCode().equals(TStatusCode.SRM_PARTIAL_SUCCESS)) { - log.info(srmCommand + ": <" + DataHelper.getRequestor(inputData) - + "> Request for [token:" + token + "] for [SURL: " + surls - + "] partially done with [status: " + status + "]"); - } else { - log.info(srmCommand + ": <" + DataHelper.getRequestor(inputData) - + "> Request for [token:" + token + "] for [SURL: " + surls - + "] failed with [status: " + status + "]"); - } - } + + log.info("{}: user<{}> Request for [token: {}] for [SURL: {}] {} with " + +" [status: {}]", + srmCommand, + DataHelper.getRequestor(inputData), + token, + surls, + getStatusMessage(status.getStatusCode()), + status); } public static void printSurlOutcome(String srmCommand, Logger log, TReturnStatus status, InputData inputData, TSURL surl) { - // TODO add all the successfull status for any request - if (status.getStatusCode().equals(TStatusCode.SRM_SUCCESS)) { - log.info(srmCommand + ": user <" + DataHelper.getRequestor(inputData) - + "> operation on [SURL: " + surl - + "] successfully done with: [status: " + status + "]"); - } else { - log.info(srmCommand + ": <" + DataHelper.getRequestor(inputData) - + "> operation on [SURL: " + surl + "] failed with [status: " + status - + "]"); - } + log.info("{}: user <{}> operation on [SURL: {}] {} with: [status: {}]", + srmCommand, + DataHelper.getRequestor(inputData), + surl, + getStatusMessage(status.getStatusCode()), + status); + } - -} + + public static void printSurlOutcome(String srmCommand, + Logger log, + TReturnStatus status, + InputData inputData, + TRequestToken token, + TSURL surl) { + + log.info("{}: user <{}> operation for token [token:{}] on [SURL: {}] {} with: [status: {}]", + srmCommand, + DataHelper.getRequestor(inputData), + token, + surl, + getStatusMessage(status.getStatusCode()), + status); + } +} \ No newline at end of file diff --git a/src/main/java/it/grid/storm/synchcall/command/DataTransferCommand.java b/src/main/java/it/grid/storm/synchcall/command/DataTransferCommand.java index bfb066d7..7bf4441e 100644 --- a/src/main/java/it/grid/storm/synchcall/command/DataTransferCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/DataTransferCommand.java @@ -17,14 +17,7 @@ package it.grid.storm.synchcall.command; -import it.grid.storm.config.Configuration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public abstract class DataTransferCommand implements Command { - - protected Logger log = LoggerFactory.getLogger(DataTransferCommand.class); - protected static Configuration config = Configuration.getInstance(); +public abstract class DataTransferCommand extends AbstractCommand { } diff --git a/src/main/java/it/grid/storm/synchcall/command/DirectoryCommand.java b/src/main/java/it/grid/storm/synchcall/command/DirectoryCommand.java index 7cbc2abd..786bd826 100644 --- a/src/main/java/it/grid/storm/synchcall/command/DirectoryCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/DirectoryCommand.java @@ -17,14 +17,7 @@ package it.grid.storm.synchcall.command; -import it.grid.storm.config.Configuration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public abstract class DirectoryCommand implements Command { - - protected Logger log = LoggerFactory.getLogger(DirectoryCommand.class); - protected static Configuration config = Configuration.getInstance(); +public abstract class DirectoryCommand extends AbstractCommand { } diff --git a/src/main/java/it/grid/storm/synchcall/command/DiscoveryCommand.java b/src/main/java/it/grid/storm/synchcall/command/DiscoveryCommand.java index d3582fc4..6f27fb35 100644 --- a/src/main/java/it/grid/storm/synchcall/command/DiscoveryCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/DiscoveryCommand.java @@ -17,14 +17,7 @@ package it.grid.storm.synchcall.command; -import it.grid.storm.config.Configuration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public abstract class DiscoveryCommand implements Command { - - protected Logger log = LoggerFactory.getLogger(DiscoveryCommand.class); - protected static Configuration config = Configuration.getInstance(); +public abstract class DiscoveryCommand extends AbstractCommand { } diff --git a/src/main/java/it/grid/storm/synchcall/command/SpaceCommand.java b/src/main/java/it/grid/storm/synchcall/command/SpaceCommand.java index f7fb1be9..495dbed6 100644 --- a/src/main/java/it/grid/storm/synchcall/command/SpaceCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/SpaceCommand.java @@ -17,14 +17,7 @@ package it.grid.storm.synchcall.command; -import it.grid.storm.config.Configuration; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public abstract class SpaceCommand implements Command { - - protected Logger log = LoggerFactory.getLogger(SpaceCommand.class); - protected static Configuration config = Configuration.getInstance(); +public abstract class SpaceCommand extends AbstractCommand { } diff --git a/src/main/java/it/grid/storm/synchcall/command/SurlStatusCommandHelper.java b/src/main/java/it/grid/storm/synchcall/command/SurlStatusCommandHelper.java index bf879e98..0cd61141 100644 --- a/src/main/java/it/grid/storm/synchcall/command/SurlStatusCommandHelper.java +++ b/src/main/java/it/grid/storm/synchcall/command/SurlStatusCommandHelper.java @@ -172,7 +172,7 @@ private static Map getSurlsStatus( throw new IllegalStateException( "Unexpected IllegalArgumentException in getSurlsStatus: " + e); } catch (UnknownSurlException e) { - log.info("Requested surl " + surl + " is unknown"); + log.info("Requested surl {} is unknown", surl); } } if (surlsStatuses.isEmpty()) { diff --git a/src/main/java/it/grid/storm/synchcall/command/datatransfer/AbortFilesCommand.java b/src/main/java/it/grid/storm/synchcall/command/datatransfer/AbortFilesCommand.java index 24d21cec..ae7568ff 100644 --- a/src/main/java/it/grid/storm/synchcall/command/datatransfer/AbortFilesCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/datatransfer/AbortFilesCommand.java @@ -34,8 +34,8 @@ import it.grid.storm.srm.types.TSURLReturnStatus; import it.grid.storm.srm.types.TStatusCode; import it.grid.storm.synchcall.command.Command; +import it.grid.storm.synchcall.command.CommandHelper; import it.grid.storm.synchcall.command.DataTransferCommand; -import it.grid.storm.synchcall.data.DataHelper; import it.grid.storm.synchcall.data.InputData; import it.grid.storm.synchcall.data.OutputData; import it.grid.storm.synchcall.data.datatransfer.AbortFilesInputData; @@ -50,22 +50,13 @@ public class AbortFilesCommand extends DataTransferCommand implements Command { + private static final String SRM_COMMAND = "srmAbortFiles"; + private static final Logger log = LoggerFactory .getLogger(AbortFilesCommand.class); - // private RequestSummaryCatalog summaryCat = null; - // private Scheduler scheduler = null; - private AdvancedPicker advancedPicker = null; - private AbortExecutorInterface executor = null; - - public AbortFilesCommand() { - }; - - /** - * This executor performs a SrmAbortFiles. This function prematurely terminate - * asynchronous requests of any types. The effects of srmAbortFiles() depends - * on the type of request. - */ + private AdvancedPicker advancedPicker; + private AbortExecutorInterface executor; public OutputData execute(InputData data) { @@ -79,21 +70,22 @@ public OutputData execute(InputData data) { AbortFilesCommand.log.debug("Started AbortRequest function."); - /******************** Check for malformed request: missing mandatory input parameters ****************/ - if (inputData == null || inputData.getRequestToken() == null || (inputData.getType().equals(AbortInputData.AbortType.ABORT_FILES) && inputData .getArrayOfSURLs() == null)) { - AbortFilesCommand.log - .debug("srmAbortFiles: Invalid input parameter specified"); + + log.debug("srmAbortFiles: Invalid input parameter specified"); + globalStatus = manageStatus(TStatusCode.SRM_INVALID_REQUEST, "Missing mandatory parameters"); + outputData.setReturnStatus(globalStatus); outputData.setArrayOfFileStatuses(null); - AbortFilesCommand.log - .error("srmAbortFiles: <> Request for [token:] [SURL:] failed with [status: " - + globalStatus + "]"); + + log.error("srmAbortFiles: <> Request for [token:] [SURL:] failed with " + + "[status: {}]", globalStatus); + return outputData; } @@ -124,22 +116,11 @@ public OutputData execute(InputData data) { TRequestToken requestToken = inputData.getRequestToken(); ArrayOfSURLs surlArray = inputData.getArrayOfSURLs(); - AbortFilesCommand.log.debug("srmAbortFiles: requestToken=" - + requestToken.toString()); + AbortFilesCommand.log.debug("srmAbortFiles: requestToken={}", + requestToken); /****************************** PHASE (1) LOOKING INTO PENDING DB AND ADVANCED PICKER ***************************/ - /******* Phase 1.A Look in the Summary Catalog ************/ - - /* - * Insert Security Here! Add the GridUser field in the catalog abortRequest - * method to verify if the request is associated to the same user that want - * to abort it.? - */ - - // CONTROLLO SE GRIDUSER ASSOCIATO AL TOKEN e' il RICHIEDENTE. - // MA SI DEVE FARE COSI? E IL VOMANAGER? - /** * Note: If a global request if found to be be in SRM_QUEUED status in the * SummaryCatalog it means that both the global status and each chunk are @@ -147,64 +128,70 @@ public OutputData execute(InputData data) { * to abort it is sufficient transit both global status and each chunk in * SRM_ABORTED. */ - if (inputData.getType().equals(AbortInputData.AbortType.ABORT_REQUEST)) { - // SrmAbortRequest case - log.debug("Phase (1.A) AbortRequest: SurlArray Not specified."); - // Update the request Status both for global request and for each chunk to - // SRM_ABORTED. - // summaryCat.abortRequest(inputData.getRequestToken()); + + log.debug("AbortRequest: SurlArray Not specified."); + try { - SurlStatusManager.checkAndUpdateStatus(requestToken, - TStatusCode.SRM_REQUEST_QUEUED, TStatusCode.SRM_ABORTED, + + SurlStatusManager.checkAndUpdateStatus( + requestToken, + TStatusCode.SRM_REQUEST_QUEUED, + TStatusCode.SRM_ABORTED, "User aborted request!"); + } catch (UnknownTokenException e) { - log.info("Unable to update surls status on token " + requestToken - + " .UnknownTokenException: " + e.getMessage()); + + log.info("Unable to update surls status on token {}: {}", + requestToken, e.getMessage(), e); + globalStatus = manageStatus(TStatusCode.SRM_INVALID_REQUEST, "Invalid request token"); + outputData.setArrayOfFileStatuses(null); - AbortFilesCommand.log.info("srmAbortFiles: <" - + DataHelper.getRequestor(inputData) + "> Request for [token:" - + inputData.getRequestToken() + "] failed with [status: " - + globalStatus + "]"); + + CommandHelper.printRequestOutcome( + SRM_COMMAND, + log, + globalStatus, + inputData, + inputData.getRequestToken()); + return outputData; + } catch (ExpiredTokenException e) { - log.info("Unable to update surls status on token " + requestToken - + " .ExpiredTokenException: " + e.getMessage()); + + log.info("Expired token: {}. {}", + requestToken, e.getMessage(), e); + globalStatus = manageStatus(TStatusCode.SRM_REQUEST_TIMED_OUT, "Request expired"); outputData.setArrayOfFileStatuses(null); - AbortFilesCommand.log.info("srmAbortFiles: <" - + DataHelper.getRequestor(inputData) + "> Request for [token:" - + inputData.getRequestToken() + "] failed with [status: " - + globalStatus + "]"); + + CommandHelper.printRequestOutcome( + SRM_COMMAND, + log, + globalStatus, + inputData, + inputData.getRequestToken()); + return outputData; } RequestSummaryCatalog.getInstance().updateFromPreviousGlobalStatus( requestToken, TStatusCode.SRM_REQUEST_QUEUED, TStatusCode.SRM_ABORTED, "User aborted request!"); res = false; - } else { - if (inputData.getType().equals(AbortInputData.AbortType.ABORT_FILES)) { - // SrmAbortFiles case - log.debug("Phase (1.A) AbortRequest: SurlArray Specified."); - // Update the request Status both for global request and for each *chunk - // to SRM_ABORTED. - - // TODO REMOVE THIS COMMENT! - // summaryCat.abortRequest(inputData.getRequestToken(), surlArray); - res = false; - } else { - // failure? - } + + } else if (inputData.getType().equals(AbortInputData.AbortType.ABORT_FILES)){ + + log.debug("Phase (1.A) AbortRequest: SurlArray Specified."); + res = false; } + if (res == false) { AbortFilesCommand.log.debug("Phase (1.A) AbortRequest: Token not found."); } else { - /** - * Request Successfully Aborted. Return here! Build outputdata and return! - */ + arrayOfTSURLReturnStatus = new ArrayOfTSURLReturnStatus(); globalStatus = manageStatus(TStatusCode.SRM_SUCCESS, "Abort sucessfully completed."); @@ -216,24 +203,36 @@ public OutputData execute(InputData data) { surlRetStatus.setSurl(surlArray.getTSURL(i)); surlRetStatus.setStatus(manageStatus(TStatusCode.SRM_SUCCESS, "File request aborted.")); - AbortFilesCommand.log.info("srmAbortFiles: <" - + DataHelper.getRequestor(inputData) + "> Request for [token:" - + inputData.getRequestToken() + "] for SURL " + (i + 1) + " of " - + surlArray.size() + " [SURL:" + surlArray.getTSURL(i) - + "] successfully done with [status: " + surlRetStatus.getStatus() - + "]"); + + CommandHelper.printSurlOutcome( + SRM_COMMAND, + log, + globalStatus, + inputData, + inputData.getRequestToken(), + surlArray.getTSURL(i)); + arrayOfTSURLReturnStatus.addTSurlReturnStatus(surlRetStatus); } - AbortFilesCommand.log.info("srmAbortFiles: <" - + DataHelper.getRequestor(inputData) + "> Request for [token:" - + inputData.getRequestToken() + "] for [SURL:" + surlArray - + "] successfully done with [status: " + globalStatus + "]"); + + CommandHelper.printRequestOutcome( + SRM_COMMAND, + log, + globalStatus, + inputData, + inputData.getRequestToken(), + surlArray); + } else { + outputData.setArrayOfFileStatuses(null); - AbortFilesCommand.log.info("srmAbortFiles: <" - + DataHelper.getRequestor(inputData) + "> Request for [token:" - + inputData.getRequestToken() + "] successfully done with [status: " - + globalStatus + "]"); + + CommandHelper.printRequestOutcome( + SRM_COMMAND, + log, + globalStatus, + inputData, + inputData.getRequestToken()); } return outputData; } @@ -249,32 +248,19 @@ public OutputData execute(InputData data) { */ if (inputData.getType().equals(AbortInputData.AbortType.ABORT_REQUEST)) { - AbortFilesCommand.log - .debug("Phase (1.B) AbortRequest: SurlArray Not specified."); - // Update the request Status both for global request and for each *chunk - // to SRM_ABORTED. - - // TODO REMOVE THIS COMMENT! + log.debug("Phase (1.B) AbortRequest: SurlArray Not specified."); advancedPicker.abortRequest(inputData.getRequestToken()); res = false; } else if (inputData.getType().equals(AbortInputData.AbortType.ABORT_FILES)) { - AbortFilesCommand.log - .debug("Phase (1.B) AbortRequest: SurlArray Specified."); - // Update the request Status both for global request and for each *chunk - // to SRM_ABORTED. - - // TODO REMOVE THIS COMMENT! - // advancedPicker.abortRequest(inputData.getRequestToken(), surlArray); + log.debug("Phase (1.B) AbortRequest: SurlArray Specified."); res = false; } if (res == false) { AbortFilesCommand.log.debug("Phase (1.B) AbortRequest: Token not found."); } else { - /** - * Request Successfully Aborted. Return here! Build outputdata and return! - */ + arrayOfTSURLReturnStatus = new ArrayOfTSURLReturnStatus(); globalStatus = manageStatus(TStatusCode.SRM_SUCCESS, "Abort sucessfully completed."); @@ -285,60 +271,40 @@ public OutputData execute(InputData data) { surlRetStatus.setSurl(surlArray.getTSURL(i)); surlRetStatus.setStatus(manageStatus(TStatusCode.SRM_SUCCESS, "File request aborted.")); - AbortFilesCommand.log.info("srmAbortFiles: <" - + DataHelper.getRequestor(inputData) + "> Request for [token:" - + inputData.getRequestToken() + "] for SURL " + (i + 1) + " of " - + surlArray.size() + " [SURL:" + surlArray.getTSURL(i) - + "] successfully done with [status: " + surlRetStatus.getStatus() - + "]"); + + CommandHelper.printSurlOutcome( + SRM_COMMAND, + log, + globalStatus, + inputData, + inputData.getRequestToken(), + surlArray.getTSURL(i)); + arrayOfTSURLReturnStatus.addTSurlReturnStatus(surlRetStatus); } - AbortFilesCommand.log.info("srmAbortFiles: <" - + DataHelper.getRequestor(inputData) + "> Request for [token:" - + inputData.getRequestToken() + "] for [SURL:" + surlArray - + "] successfully done with [status: " + globalStatus + "]"); + + CommandHelper.printRequestOutcome( + SRM_COMMAND, + log, + globalStatus, + inputData, + inputData.getRequestToken(), + surlArray); + } else { outputData.setArrayOfFileStatuses(null); - AbortFilesCommand.log.info("srmAbortFiles: <" - + DataHelper.getRequestor(inputData) + "> Request for [token:" - + inputData.getRequestToken() + "] successfully done with [status: " - + globalStatus + "]"); + + CommandHelper.printRequestOutcome( + SRM_COMMAND, + log, + globalStatus, + inputData, + inputData.getRequestToken()); + } return outputData; - } - /***************************** PHASE (2) LOOKING INTO THE SCHEDULER **************************/ - - /** - * Insert Secutiry Here!. - */ - - // TODO REMOVE THIS COMMENT! - /* - * if((surlArray == null)&&(scheduler.remove(requestToken)) { - * log.debug("Phase (2) AbortRequest: Token FOUND."); //Update the request - * Status both for global request and for each *chunk to SRM_ABORTED. - * summaryCat.abortRequest(inputData.getRequestToken()); } else - * if((surlArray != null)&&(scheduler.remove(requestToken,surlArray))) { - * log.debug("Phase (2) AbortRequest: Token and SURL FOUND."); //Update the - * request Status both for global request and for each *chunk to - * SRM_ABORTED. summaryCat.abortRequest(inputData.getRequestToken(), - * surlArray); } else { - * log.debug("Phase (2) AbortRequest: Token not found."); } - */ - /************* PHASE (3) [WAIT END AND MANAGE ROLLBACK] OR [SEND ABORT TO COPY] *************/ - - // First of all, identify the request type. - - /** - * Add Security Check Here CHeck if user associated with global request is - * the requester of Abort. - * - * @todo - */ - - // TRequestType rtype = summaryCat.typeOf(requestToken); TRequestType rtype = SurlStatusManager.isPersisted(requestToken); if (rtype == TRequestType.PREPARE_TO_GET) { @@ -353,49 +319,34 @@ public OutputData execute(InputData data) { executor = new CopyAbortExecutor(); return executor.doIt(inputData); } else { - // This case is really possibile? - AbortFilesCommand.log.debug("This case is really possibile?"); - AbortFilesCommand.log - .debug("srmAbortFiles : Invalid input parameter specified"); + log.debug("srmAbortFiles : Invalid input parameter specified"); + globalStatus = manageStatus(TStatusCode.SRM_INVALID_REQUEST, "Invalid request token. Abort only works for PtG, PtP and Copy."); - AbortFilesCommand.log.error("srmAbortFiles: <" - + DataHelper.getRequestor(inputData) + "> Request for [token:" - + inputData.getRequestToken() + "] failed with [status: " - + globalStatus + "]"); + + CommandHelper.printRequestOutcome( + SRM_COMMAND, + log, + globalStatus, + inputData, + inputData.getRequestToken()); + outputData.setReturnStatus(globalStatus); outputData.setArrayOfFileStatuses(null); return outputData; } } } - - /* - * if(requestFailure) { - * log.error("SrmAbortRequest : Invalid input parameter specified"); - * globalStatus = manageStatus(TStatusCode.SRM_INVALID_REQUEST, - * "Request Token does not referes to existing known requests."); - * outputData.setReturnStatus(globalStatus); - * outputData.setArrayOfFileStatuses(null); return outputData; } - */ } - /** - * - * @param statusCode - * statusCode - * @param explanation - * explanation string - * @return returnStatus returnStatus - */ private TReturnStatus manageStatus(TStatusCode statusCode, String explanation) { TReturnStatus returnStatus = null; try { returnStatus = new TReturnStatus(statusCode, explanation); } catch (InvalidTReturnStatusAttributeException ex1) { - AbortFilesCommand.log - .debug("AbortExecutor : Error creating returnStatus " + ex1); + log.debug("AbortExecutor : Error creating returnStatus: {}", + ex1.getMessage(), ex1); } return returnStatus; } diff --git a/src/main/java/it/grid/storm/synchcall/command/datatransfer/AbortRequestCommand.java b/src/main/java/it/grid/storm/synchcall/command/datatransfer/AbortRequestCommand.java index 2bdd1437..57a2304b 100644 --- a/src/main/java/it/grid/storm/synchcall/command/datatransfer/AbortRequestCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/datatransfer/AbortRequestCommand.java @@ -25,8 +25,8 @@ import it.grid.storm.srm.types.TReturnStatus; import it.grid.storm.srm.types.TStatusCode; import it.grid.storm.synchcall.command.Command; +import it.grid.storm.synchcall.command.CommandHelper; import it.grid.storm.synchcall.command.DataTransferCommand; -import it.grid.storm.synchcall.data.DataHelper; import it.grid.storm.synchcall.data.InputData; import it.grid.storm.synchcall.data.OutputData; import it.grid.storm.synchcall.data.datatransfer.AbortInputData; @@ -56,6 +56,7 @@ public class AbortRequestCommand extends DataTransferCommand implements Command private static final Logger log = LoggerFactory .getLogger(AbortRequestCommand.class); + private AdvancedPicker advancedPicker = null; private AbortExecutorInterface executor = null; @@ -63,136 +64,73 @@ public AbortRequestCommand() { }; - /** - * This executor performs a SrmAbortRequests. This function prematurely - * terminate asynchronous requests of any types. The effects of - * SrmAbortRequests() depends on the type of request. - */ - public OutputData execute(InputData data) { advancedPicker = new AdvancedPicker(); AbortRequestOutputData outputData = new AbortRequestOutputData(); AbortInputData inputData = (AbortInputData) data; - // Risultato Parziale boolean res = false; - // Risultato Finale - TReturnStatus globalStatus = null; AbortRequestCommand.log.debug("Started AbortRequest function."); - /******************** Check for malformed request: missing mandatory input parameters ****************/ - if (inputData == null || inputData.getRequestToken() == null || (inputData.getType().equals(AbortInputData.AbortType.ABORT_FILES))) { - AbortRequestCommand.log - .debug("SrmAbortRequest: Invalid input parameter specified"); + log.debug("SrmAbortRequest: Invalid input parameter specified"); globalStatus = manageStatus(TStatusCode.SRM_INVALID_REQUEST, "Missing mandatory parameters"); outputData.setReturnStatus(globalStatus); outputData.setArrayOfFileStatuses(null); - AbortRequestCommand.log - .error("srmAbortRequest: <> Request for [token:] [SURL:] failed with [status: " - + globalStatus + "]"); + log.error("srmAbortRequest: <> Request for [token:] [SURL:] failed with [status: {}]", + globalStatus); return outputData; } - /** - * !!! LocalUser is unnecessary !!! - * - * // Maps the VOMS Grid user into Local User LocalUser lUser = null; try { - * lUser = user.getLocalUser(); } catch (CannotMapUserException e) { - * log.error("AbortRequest : Unable to map the user '" + user + - * "' in a local user.", e); globalStatus = - * manageStatus(TStatusCode.SRM_AUTHORIZATION_FAILURE, - * "Unable to map the user"); outputData.setReturnStatus(globalStatus); - * outputData.setArrayOfFileStatuses(null); return outputData; } - **/ - - /********************************** Start to manage the request ***********************************/ - - /** - * We can identify 3 different phases of execution: - * - * 1) Look for the request into the pending DB table, in such case the - * request is still in SRM_QUEUED status and the AbortRequest can be - * satisfied simply removing the request from the pending table, updating - * the request status to SRM_ABORTED and copying it into the appropriate - * table. - * - * 2) If we are not in the first case, look for the request into the - * scheduler internal structures. If the request is found and removed, the - * request status into the appropriate table should be updated to - * SRM_ABORTED. - * - * 3) In this case the request to abort is under execution. The behaviour is - * different depending on the request type. For the SrmPrepareToPut and - * SrmPrepareToGet, we decide to wait until the ending of execution, and - * then perform a rollback and mark the request as SRM_ABORTED. In case of - * SrmCopy, we need to stop the Copy execution so the dedicated - * AbortExecutor invoke an appropriate abort method. - * - */ - TRequestToken requestToken = inputData.getRequestToken(); - AbortRequestCommand.log.debug("srmAbortRequest: requestToken=" - + requestToken.toString()); - - /****************************** PHASE (1) LOOKING INTO PENDING DB AND ADVANCED PICKER ***************************/ - - /******* Phase 1.A Look in the Summary Catalog ************/ - - /* - * Insert Security Here! Add the GridUser field in the catalog abortRequest - * method to verify if the request is associated to the same user that want - * to abort it.? - */ - - // CONTROLLO SE GRIDUSER ASSOCIATO AL TOKEN e' il RICHIEDENTE. - // MA SI DEVE FARE COSI? E IL VOMANAGER? - - /** - * Note: If a global request if found to be be in SRM_QUEUED status in the - * SummaryCatalog it means that both the global status and each chunk are - * still in SRM_QUEUED. There is not the possibility of partial execution, - * to abort it is sufficient transit both global status and each chunk in - * SRM_ABORTED. - */ + log.debug("srmAbortRequest: requestToken={}", requestToken); if (inputData.getType().equals(AbortInputData.AbortType.ABORT_REQUEST)) { - // SrmAbortRequest case + AbortRequestCommand.log .debug("Phase (1.A) AbortRequest: SurlArray Not specified."); - // Update the request Status both for global request and for each *chunk - // to SRM_ABORTED. - // TODO REMOVE THIS COMMENT! - // summaryCat.abortRequest(inputData.getRequestToken()); try { + SurlStatusManager.checkAndUpdateStatus(inputData.getRequestToken(), TStatusCode.SRM_REQUEST_QUEUED, TStatusCode.SRM_ABORTED, "User aborted request!"); + } catch (UnknownTokenException e) { - log.info("Unable to update surls status on token " + requestToken - + " .UnknownTokenException: " + e.getMessage()); + + log.info("Unknown token: {}", e.getMessage()); globalStatus = manageStatus(TStatusCode.SRM_INVALID_REQUEST, "Invalid request token"); outputData.setArrayOfFileStatuses(null); - log.info("srmAbortRequest: <" + DataHelper.getRequestor(inputData) - + "> Request for [token:" + inputData.getRequestToken() - + "] failed with [status: " + globalStatus + "]"); + + CommandHelper.printRequestOutcome("srmAbortRequest", + log, + globalStatus, + inputData, + inputData.getRequestToken()); + return outputData; + } catch (ExpiredTokenException e) { - log.info("Unable to update surls status on token " + requestToken - + " .ExpiredTokenException: " + e.getMessage()); + + log.info("Expired token: {}. {}", requestToken, e.getMessage()); + globalStatus = manageStatus(TStatusCode.SRM_REQUEST_TIMED_OUT, "Request expired"); + outputData.setArrayOfFileStatuses(null); - log.info("srmAbortRequest: <" + DataHelper.getRequestor(inputData) - + "> Request for [token:" + inputData.getRequestToken() - + "] failed with [status: " + globalStatus + "]"); + + CommandHelper.printRequestOutcome("srmAbortRequest", + log, + globalStatus, + inputData, + inputData.getRequestToken()); + return outputData; } @@ -203,91 +141,30 @@ public OutputData execute(InputData data) { res = false; } else if (inputData.getType().equals(AbortInputData.AbortType.ABORT_FILES)) { - // SrmAbortFiles case - AbortRequestCommand.log - .debug("Phase (1.A) AbortRequest: SurlArray Specified."); - // Update the request Status both for global request and for each *chunk - // to SRM_ABORTED. - - // TODO REMOVE THIS COMMENT! - // summaryCat.abortRequest(inputData.getRequestToken(), surlArray); + + log.debug("Phase (1.A) AbortRequest: SurlArray Specified."); res = false; - } else { - // failure? - } + } if (res == false) { - AbortRequestCommand.log - .debug("Phase (1.A) AbortRequest: Token not found."); + log.debug("Phase (1.A) AbortRequest: Token not found."); } - /******** Phase 1.B Look in the AdvancedPicker ************/ - /** - * Note: There is the possibility that the global request status is changed - * in SRM_IN_PROGESS but each chunk is not really yet executed, (each chunk - * status is still in SRM_QUEUED). The only component able to manage this - * situation is the advanced picker. There is not the possibility of partial - * execution, to abort it is sufficient ask to advancePicker to transit both - * global status and each chunk in SRM_ABORTED. - */ - if (inputData.getType().equals(AbortInputData.AbortType.ABORT_REQUEST)) { - AbortRequestCommand.log - .debug("Phase (1.B) AbortRequest: SurlArray Not specified."); - // Update the request Status both for global request and for each *chunk - // to SRM_ABORTED. + log.debug("Phase (1.B) AbortRequest: SurlArray Not specified."); - // TODO REMOVE THIS COMMENT! advancedPicker.abortRequest(inputData.getRequestToken()); res = false; } else if (inputData.getType().equals(AbortInputData.AbortType.ABORT_FILES)) { - AbortRequestCommand.log - .debug("Phase (1.B) AbortRequest: SurlArray Specified."); - // Update the request Status both for global request and for each *chunk - // to SRM_ABORTED. - - // TODO REMOVE THIS COMMENT! - // advancedPicker.abortRequest(inputData.getRequestToken(), surlArray); + log.debug("Phase (1.B) AbortRequest: SurlArray Specified."); res = false; } if (res == false) { - AbortRequestCommand.log - .debug("Phase (1.B) AbortRequest: Token not found."); + log.debug("Phase (1.B) AbortRequest: Token not found."); } - /***************************** PHASE (2) LOOKING INTO THE SCHEDULER **************************/ - - /** - * Insert Secutiry Here!. - */ - - // TODO REMOVE THIS COMMENT! - /* - * if((surlArray == null)&&(scheduler.remove(requestToken)) { - * log.debug("Phase (2) AbortRequest: Token FOUND."); //Update the request - * Status both for global request and for each *chunk to SRM_ABORTED. - * summaryCat.abortRequest(inputData.getRequestToken()); } else - * if((surlArray != null)&&(scheduler.remove(requestToken,surlArray))) { - * log.debug("Phase (2) AbortRequest: Token and SURL FOUND."); //Update the - * request Status both for global request and for each *chunk to - * SRM_ABORTED. summaryCat.abortRequest(inputData.getRequestToken(), - * surlArray); } else { - * log.debug("Phase (2) AbortRequest: Token not found."); } - */ - /************* PHASE (3) [WAIT END AND MANAGE ROLLBACK] OR [SEND ABORT TO COPY] *************/ - - // First of all, identify the request type. - - /** - * Add Security Check Here CHeck if user associated with global request is - * the requester of Abort. - * - * @todo - */ - - // TRequestType rtype = summaryCat.typeOf(requestToken); TRequestType rtype = SurlStatusManager.isPersisted(requestToken); if (rtype == TRequestType.PREPARE_TO_GET) { @@ -300,29 +177,20 @@ public OutputData execute(InputData data) { executor = new CopyAbortExecutor(); return executor.doIt(inputData); } else { - // This case is really possibile? - AbortRequestCommand.log.debug("This case is really possibile?"); - AbortRequestCommand.log - .debug("SrmAbortRequest : Invalid input parameter specified"); + log.debug("SrmAbortRequest : Invalid input parameter specified"); globalStatus = manageStatus(TStatusCode.SRM_INVALID_REQUEST, "Invalid request token. Abort only works for PtG, PtP and Copy."); - AbortRequestCommand.log.error("srmAbortRequest: <" - + DataHelper.getRequestor(inputData) + "> Request for [token:" - + inputData.getRequestToken() + "] failed with [status: " - + globalStatus + "]"); + + CommandHelper.printRequestOutcome("srmAbortRequest", + log, + globalStatus, + inputData, + inputData.getRequestToken()); + outputData.setReturnStatus(globalStatus); outputData.setArrayOfFileStatuses(null); return outputData; } - - /* - * if(requestFailure) { - * log.error("SrmAbortRequest : Invalid input parameter specified"); - * globalStatus = manageStatus(TStatusCode.SRM_INVALID_REQUEST, - * "Request Token does not referes to existing known requests."); - * outputData.setReturnStatus(globalStatus); - * outputData.setArrayOfFileStatuses(null); return outputData; } - */ } /** @@ -340,7 +208,8 @@ private TReturnStatus manageStatus(TStatusCode statusCode, String explanation) { returnStatus = new TReturnStatus(statusCode, explanation); } catch (InvalidTReturnStatusAttributeException ex1) { AbortRequestCommand.log - .debug("AbortExecutor : Error creating returnStatus " + ex1); + .debug("AbortExecutor : Error creating returnStatus: {}", + ex1.getMessage(), ex1); } return returnStatus; } diff --git a/src/main/java/it/grid/storm/synchcall/command/directory/LsCommand.java b/src/main/java/it/grid/storm/synchcall/command/directory/LsCommand.java index 1a3b1310..05199d24 100644 --- a/src/main/java/it/grid/storm/synchcall/command/directory/LsCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/directory/LsCommand.java @@ -83,6 +83,8 @@ import java.util.Map; import org.apache.commons.lang.mutable.MutableInt; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import it.grid.storm.checksum.ChecksumAlgorithm; @@ -97,6 +99,8 @@ public class LsCommand extends DirectoryCommand implements Command { + public static final Logger log = LoggerFactory.getLogger(LsCommand.class); + private static final String SRM_COMMAND = "srmLs"; private final NamespaceInterface namespace; @@ -126,10 +130,6 @@ public OutputData execute(InputData data) { outputData.setRequestToken(null); outputData.setDetails(null); - /** - * Validate LSInputData. The check is done at this level to separate - * internal StoRM logic from xmlrpc specific operation. - */ if (inputData == null || inputData.getSurlArray() == null || inputData.getSurlArray().size() == 0) { log.debug("srmLs: Input parameters for srmLs request NOT found!"); @@ -142,12 +142,6 @@ public OutputData execute(InputData data) { ArrayOfSURLs surlArray = inputData.getSurlArray(); - /***************** Check for DEFAULT parameters not specified in input Data **************/ - - /** - * Filtering result by storageType is not supported by StoRM. According to - * SRM specific if fileStorageType is specified return SRM_NOT_SUPPORTED - */ if (inputData.getStorageTypeSpecified()) { globalStatus = CommandHelper.buildStatus(TStatusCode.SRM_NOT_SUPPORTED, "Filtering result by fileStorageType not supported."); @@ -167,7 +161,6 @@ public OutputData execute(InputData data) { boolean allLevelRecursive; if (inputData.getAllLevelRecursive() == null) { - // Set to the default value. allLevelRecursive = DirectoryCommand.config.getLSallLevelRecursive(); } else { allLevelRecursive = inputData.getAllLevelRecursive().booleanValue(); @@ -175,7 +168,6 @@ public OutputData execute(InputData data) { int numOfLevels; if (inputData.getNumOfLevels() == null) { - // Set to the default value. numOfLevels = DirectoryCommand.config.getLSnumOfLevels(); } else { numOfLevels = inputData.getNumOfLevels().intValue(); @@ -227,18 +219,13 @@ public OutputData execute(InputData data) { coutOrOffsetAreSpecified = true; } - /********************************* Start LS Execution **********************************/ - /* - * From this point the log can be more verbose reporting also the SURL - * involved in the request. - */ - ArrayOfTMetaDataPathDetail details = new ArrayOfTMetaDataPathDetail(); TStatusCode fileLevelStatusCode = TStatusCode.EMPTY; String fileLevelExplanation = ""; int errorCount = 0; int maxEntries = DirectoryCommand.config.getLSMaxNumberOfEntry(); + if (count < maxEntries) { maxEntries = count; } @@ -253,7 +240,7 @@ public OutputData execute(InputData data) { StoRI stori = null; boolean failure = false; - log.debug("srmLs: surlArray.size=" + surlArray.size()); + log.debug("srmLs: surlArray.size={}",surlArray.size()); TSURL surl = surlArray.getTSURL(j); if (!surl.isEmpty()) { @@ -265,27 +252,38 @@ public OutputData execute(InputData data) { ((IdentityInputData) inputData).getUser()); } catch (UnapprochableSurlException e) { failure = true; - log.info("Unable to build a stori for surl " + surl - + " for user " + DataHelper.getRequestor(inputData) - + " UnapprochableSurlException: " + e.getMessage()); + + log.info("Unable to build a stori for surl {} for user {}. {}", + surl, + DataHelper.getRequestor(inputData), + e.getMessage()); + fileLevelStatusCode = TStatusCode.SRM_AUTHORIZATION_FAILURE; fileLevelExplanation = e.getMessage(); printRequestOutcome(CommandHelper.buildStatus( fileLevelStatusCode, fileLevelExplanation), inputData); + } catch (NamespaceException e) { failure = true; - log.error("Unable to build a stori for surl " + surl - + " for user " + DataHelper.getRequestor(inputData) - + " UnapprochableSurlException: " + e.getMessage()); + + log.info("Unable to build a stori for surl {} for user {}. {}", + surl, + DataHelper.getRequestor(inputData), + e.getMessage()); + fileLevelStatusCode = TStatusCode.SRM_INTERNAL_ERROR; fileLevelExplanation = e.getMessage(); printRequestOutcome(CommandHelper.buildStatus( fileLevelStatusCode, fileLevelExplanation), inputData); + } catch (InvalidSURLException e) { failure = true; - log.info("Unable to build a stori for surl " + surl - + " for user " + DataHelper.getRequestor(inputData) - + " UnapprochableSurlException: " + e.getMessage()); + + log.info("Unable to build a stori for surl {} for user {}. {}", + surl, + DataHelper.getRequestor(inputData), + e.getMessage()); + fileLevelStatusCode = TStatusCode.SRM_INVALID_PATH; fileLevelExplanation = e.getMessage(); printRequestOutcome(CommandHelper.buildStatus( @@ -296,24 +294,30 @@ public OutputData execute(InputData data) { stori = namespace.resolveStoRIbySURL(surl); } catch (UnapprochableSurlException e) { failure = true; - log.info("Unable to build a stori for surl " + surl - + " UnapprochableSurlException: " + e.getMessage()); + log.info("Unable to build a stori for surl {}. {}", + surl, e.getMessage()); + fileLevelStatusCode = TStatusCode.SRM_AUTHORIZATION_FAILURE; fileLevelExplanation = e.getMessage(); printRequestOutcome(CommandHelper.buildStatus( fileLevelStatusCode, fileLevelExplanation), inputData); + } catch (NamespaceException e) { failure = true; - log.info("Unable to build a stori for surl " + surl - + " NamespaceException: " + e.getMessage()); + + log.info("Unable to build a stori for surl {}. {}", + surl, e.getMessage()); + fileLevelStatusCode = TStatusCode.SRM_INTERNAL_ERROR; fileLevelExplanation = e.getMessage(); printRequestOutcome(CommandHelper.buildStatus( fileLevelStatusCode, fileLevelExplanation), inputData); } catch (InvalidSURLException e) { failure = true; - log.info("Unable to build a stori for surl " + surl - + " InvalidSURLException: " + e.getMessage()); + + log.info("Unable to build a stori for surl {}. {}", + surl, e.getMessage()); + fileLevelStatusCode = TStatusCode.SRM_INVALID_PATH; fileLevelExplanation = e.getMessage(); printRequestOutcome(CommandHelper.buildStatus( @@ -321,7 +325,8 @@ public OutputData execute(InputData data) { } } } catch (IllegalArgumentException e) { - log.error("srmLs: Unable to build StoRI by SURL: " + e); + log.error("srmLs: Unable to build StoRI by SURL: {}", e.getMessage() + ,e); failure = true; fileLevelStatusCode = TStatusCode.SRM_INTERNAL_ERROR; fileLevelExplanation = e.getMessage(); @@ -338,14 +343,7 @@ public OutputData execute(InputData data) { inputData); } - // Check for authorization and execute Ls. if (!failure) { - - // AuthorizationDecision lsAuth = - // AuthorizationCollector.getInstance().canListDirectory(guser, stori); - /** - * 1.5.0 Path Authorization - */ AuthzDecision lsAuthz; if (inputData instanceof IdentityInputData) { lsAuthz = AuthzDirector.getPathAuthz() @@ -355,17 +353,18 @@ public OutputData execute(InputData data) { lsAuthz = AuthzDirector.getPathAuthz().authorizeAnonymous( SRMFileRequest.LS, stori.getStFN()); } + if (lsAuthz.equals(AuthzDecision.PERMIT)) { - log.debug("srmLs: Ls authorized for user [" - + DataHelper.getRequestor(inputData) + "] and PFN = [" - + stori.getPFN() + "]"); - // At this point starts the recursive call + log.debug("srmLs: Ls authorized for user [{}] and PFN = [{}]", + DataHelper.getRequestor(inputData), stori.getPFN()); + errorCount += manageAuthorizedLS(inputData, stori, details, allLevelRecursive, numOfLevels, fullDetailedList, errorCount, maxEntries, offset, numberOfReturnedEntries, 0, numberOfIterations); } else { + fileLevelStatusCode = TStatusCode.SRM_AUTHORIZATION_FAILURE; fileLevelExplanation = "User does not have valid permissions"; printRequestOutcome(CommandHelper.buildStatus(fileLevelStatusCode, @@ -373,7 +372,10 @@ public OutputData execute(InputData data) { failure = true; } } + + if (failure) { + errorCount++; TReturnStatus status = CommandHelper.buildStatus(fileLevelStatusCode, fileLevelExplanation); @@ -381,6 +383,7 @@ public OutputData execute(InputData data) { TMetaDataPathDetail elementDetail = new TMetaDataPathDetail(); elementDetail.setStatus(status); elementDetail.setSurl(surl); + if (stori != null) { elementDetail.setStFN(stori.getStFNFromMappingRule()); } else { @@ -411,11 +414,10 @@ public OutputData execute(InputData data) { } } - log.debug("srmLs: Number of details specified in srmLs request:" - + details.size()); + log.debug("srmLs: Number of details specified in srmLs request: {}", + details.size()); log.debug("srmLs: Creation of srmLs outputdata"); - // Set the Global return status. String warningMessage = ""; if ((numOfLevels > 0) && atLeastOneInputSURLIsDir @@ -439,6 +441,7 @@ public OutputData execute(InputData data) { "All requests failed"); printRequestOutcome(globalStatus, inputData); } + outputData.setStatus(globalStatus); outputData.setDetails(details); return outputData; @@ -529,21 +532,19 @@ private int manageAuthorizedLS(LSInputData inputData, StoRI stori, try { fullDetail(inputData, stori, currentElementDetail); } catch (FSException e) { - log.error("srmLs: unable to get full details on stori " - + stori.getAbsolutePath() + " . FSException : " - + e.getMessage()); + log.error("srmLs: unable to get full details on stori {}. {}", + stori.getAbsolutePath(), + e.getMessage(), e); errorCount++; - // Set the file level request status to FAILURE try { currentElementDetail.setStatus(new TReturnStatus( TStatusCode.SRM_FAILURE, "Unable to get full details")); } catch (InvalidTReturnStatusAttributeException ex1) { - log.error("srmLs: Error creating returnStatus " + ex1 - + " NOTE: this is impossible!"); + log.error(ex1.getMessage(),ex1); } } } - // In Any case set SURL value into TMetaDataPathDetail + currentElementDetail.setStFN(stori.getStFNFromMappingRule()); numberOfResults.increment(); @@ -588,22 +589,21 @@ private int manageAuthorizedLS(LSInputData inputData, StoRI stori, try { fullDetail(inputData, stori, currentElementDetail); } catch (FSException e) { - log.error("srmLs: unable to get full details on stori " - + stori.getAbsolutePath() + " . FSException : " - + e.getMessage()); + log.error("srmLs: unable to get full details on stori {}. {}", + stori.getAbsolutePath(), + e.getMessage(), + e); errorCount++; - // Set the file level request status to FAILURE + try { currentElementDetail.setStatus(new TReturnStatus( TStatusCode.SRM_FAILURE, "Unable to get full details")); } catch (InvalidTReturnStatusAttributeException ex1) { - log.error("srmLs: Error creating returnStatus " + ex1 - + " NOTE: this is impossible"); + log.error(ex1.getMessage(),ex1); } } } - // In Any case set SURL value into TMetaDataPathDetail currentElementDetail.setStFN(stori.getStFNFromMappingRule()); numberOfResults.increment(); rootArray.addTMetaDataPathDetail(currentElementDetail); @@ -635,8 +635,7 @@ private List getFirstLevel(StoRI element) { try { dirOption = new TDirOption(true, false, 1); } catch (InvalidTDirOptionAttributesException ex) { - // Never thrown - log.debug("srmLs: Unable to create DIR OPTION. WOW!"); + log.debug(ex.getMessage(), ex); } try { @@ -644,13 +643,13 @@ private List getFirstLevel(StoRI element) { result = element.getChildren(dirOption); } catch (InvalidDescendantsFileRequestException ex1) { - log.error("srmLs: Unable to retrieve StoRI children !" + ex1); + log.error("srmLs: Unable to retrieve StoRI children !", ex1); } catch (InvalidDescendantsPathRequestException ex1) { - log.error("srmLs: Unable to retrieve StoRI children !" + ex1); + log.error("srmLs: Unable to retrieve StoRI children !", ex1); } catch (InvalidDescendantsAuthRequestException ex1) { - log.error("srmLs: Unable to retrieve StoRI children !" + ex1); + log.error("srmLs: Unable to retrieve StoRI children !", ex1); } catch (InvalidDescendantsEmptyRequestException ex1) { - log.debug("srmLs: directory " + element.getAbsolutePath() + " is empty"); + log.debug("srmLs: directory {} is empty", element.getAbsolutePath()); } if (result == null) { @@ -678,15 +677,13 @@ private void populateDetailFromFS(StoRI element, LocalFile localElement = element.getLocalFile(); if (localElement.exists()) { - // Set Size TSizeInBytes size = TSizeInBytes.makeEmpty(); try { if (!(localElement.isDirectory())) { - // Patch. getExactSize now works with Java and not with the use of FS - // Driver (native code) size = TSizeInBytes.make(localElement.getExactSize(), SizeUnit.BYTES); - log.debug("srmLs: Extracting size: " + localElement.getPath() - + " SIZE: " + size); + log.debug("srmLs: Extracting size for {}. Size: {}", + localElement.getPath(), + size); } else { size = TSizeInBytes.make(0, SizeUnit.BYTES); } @@ -705,14 +702,11 @@ private void populateDetailFromFS(StoRI element, statusCode = TStatusCode.SRM_SUCCESS; } - // log.debug("srmLs: Listing on SURL [" + element.getSURL() + - // "] sucessfully done with:["+statusCode+" : "+explanation+"]"); - } else { explanation = "Request failed"; statusCode = TStatusCode.SRM_FAILURE; } - } else { // localElement does not exist + } else { explanation = "No such file or directory"; statusCode = TStatusCode.SRM_INVALID_PATH; } @@ -720,9 +714,8 @@ private void populateDetailFromFS(StoRI element, try { returnStatus = new TReturnStatus(statusCode, explanation); } catch (InvalidTReturnStatusAttributeException ex1) { - log.error("srmLs: Error creating returnStatus " + ex1); + log.error("srmLs: Error creating returnStatus ", ex1); } - // Set Status into elementDetail. elementDetail.setStatus(returnStatus); } @@ -743,7 +736,7 @@ private boolean isStoRISURLBusy(StoRI element) { "unexpected IllegalArgumentException in SurlStatusManager.getSurlsStatus: " + e); } catch (UnknownSurlException e) { - log.debug("Surl " + element.getSURL() + " not stored, surl is not busy"); + log.debug("Surl {} not stored, surl is not busy.", element.getSURL()); return false; } } @@ -764,7 +757,6 @@ private void fullDetail(StoRI element, GridUserInterface guser, fullDetail(element, elementDetail); - // enrich TMetaDataPathDetail with permissions TUserPermission userPermission = null; TGroupPermission groupPermission = null; TPermissionMode otherPermission = null; @@ -787,11 +779,11 @@ private void fullDetail(StoRI element, GridUserInterface guser, otherPermission = TPermissionMode.getTPermissionMode(permission); } } catch (CannotMapUserException e) { - log.error("Cannot map user. CannotMapUserException: " + e.getMessage()); + log.error("Cannot map user. CannotMapUserException: {}", e.getMessage()); return; } catch (InvalidTUserIDAttributeException e) { - log.error("Error creating TUserID. InvalidTUserIDAttributeException: " - + e.getMessage()); + log.error("Error creating TUserID. InvalidTUserIDAttributeException: {}", + e.getMessage()); return; } if (element.getLocalFile().isDirectory()) { @@ -837,11 +829,10 @@ private void fullDetail(StoRI element, TMetaDataPathDetail elementDetail) elementDetail.setModificationTime(new Date(localElement .getLastModifiedTime())); - /** Set specific information of files and directories */ + if (localElement.isDirectory()) { elementDetail.setFileType(TFileType.getTFileType("Directory")); } else { - /** Set common information (for files and directories) */ elementDetail.setFileType(TFileType.getTFileType("File")); TRetentionPolicyInfo retentionPolicyInfo; @@ -879,7 +870,6 @@ private void fullDetail(StoRI element, TMetaDataPathDetail elementDetail) elementDetail.setLifetimeLeft(TLifeTimeInSeconds.makeInfinite()); } - // checksum Map checksums = retrieveChecksum(localElement, isTapeEnabled, isFileOnDisk); if (!(checksums.isEmpty())) { @@ -894,12 +884,11 @@ private void fullDetail(StoRI element, TMetaDataPathDetail elementDetail) elementDetail.setCheckSumValue(checkSumValue); } catch (IllegalArgumentException iae) { - log.error("Checksum algorithm '" + cksmAlg + "' is unknown!"); + log.error("Checksum algorithm {} is unknown!",cksmAlg); } catch (NullPointerException npe) { log.error("Checksum algorithm is empty or null!"); } } - // Retrieve information on directory from PERSISTENCE populateFileDetailsFromPersistence(element, elementDetail); } } @@ -921,8 +910,8 @@ private Map retrieveChecksum(LocalFile localFile, if (cksms.isEmpty()) { // Checksum is not available // so StoRM doesn't set the attributes checkSumType and checkSumValue - log.warn("Checksum value is not available for file :'" - + localFile.getAbsolutePath() + "'"); + log.warn("Checksum value is not available for file : {}", + localFile.getAbsolutePath()); } else { // Return the first checksum found String cksmAlg = cksms.keySet().iterator().next(); diff --git a/src/main/java/it/grid/storm/synchcall/command/directory/MkdirCommand.java b/src/main/java/it/grid/storm/synchcall/command/directory/MkdirCommand.java index 77176c29..e08eed3e 100644 --- a/src/main/java/it/grid/storm/synchcall/command/directory/MkdirCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/directory/MkdirCommand.java @@ -55,6 +55,9 @@ import java.util.Arrays; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * This class is part of the StoRM project. Copyright: Copyright (c) 2008 * Company: INFN-CNAF and ICTP/EGRID project @@ -65,6 +68,8 @@ public class MkdirCommand extends DirectoryCommand implements Command { + public static final Logger log = LoggerFactory.getLogger(MkdirCommand.class); + private static final String SRM_COMMAND = "SrmMkdir"; private final NamespaceInterface namespace; @@ -87,10 +92,6 @@ public OutputData execute(InputData data) { MkdirInputData inputData = (MkdirInputData) data; MkdirOutputData outData = null; - /** - * Validate MkdirInputData. The check is done at this level to separate - * internal StoRM logic from xmlrpc specific operation. - */ if ((inputData == null) || ((inputData != null) && (inputData.getSurl() == null))) { @@ -118,27 +119,33 @@ public OutputData execute(InputData data) { stori = namespace.resolveStoRIbySURL(surl, ((IdentityInputData) inputData).getUser()); } catch (UnapprochableSurlException e) { - log.info("Unable to build a stori for surl " + surl + " for user " - + DataHelper.getRequestor(inputData) - + " UnapprochableSurlException: " + e.getMessage()); + log.info("Unable to build a stori for surl {} for user {}. {}", + surl, + DataHelper.getRequestor(inputData), + e.getMessage()); + returnStatus = CommandHelper.buildStatus( TStatusCode.SRM_AUTHORIZATION_FAILURE, e.getMessage()); printRequestOutcome(returnStatus, inputData); outData = new MkdirOutputData(returnStatus); return outData; } catch (NamespaceException e) { - log.info("Unable to build a stori for surl " + surl + " for user " - + DataHelper.getRequestor(inputData) - + " NamespaceException: " + e.getMessage()); + log.info("Unable to build a stori for surl {} for user {}. {}", + surl, + DataHelper.getRequestor(inputData), + e.getMessage()); returnStatus = CommandHelper.buildStatus( TStatusCode.SRM_INTERNAL_ERROR, e.getMessage()); printRequestOutcome(returnStatus, inputData); outData = new MkdirOutputData(returnStatus); return outData; } catch (InvalidSURLException e) { - log.info("Unable to build a stori for surl " + surl + " for user " - + DataHelper.getRequestor(inputData) - + " InvalidSURLException: " + e.getMessage()); + + log.info("Unable to build a stori for surl {} for user {}. {}", + surl, + DataHelper.getRequestor(inputData), + e.getMessage()); + returnStatus = CommandHelper.buildStatus( TStatusCode.SRM_INVALID_PATH, e.getMessage()); printRequestOutcome(returnStatus, inputData); @@ -149,24 +156,25 @@ public OutputData execute(InputData data) { try { stori = namespace.resolveStoRIbySURL(surl); } catch (UnapprochableSurlException e) { - log.info("Unable to build a stori for surl " + surl - + " UnapprochableSurlException: " + e.getMessage()); + log.info("Unable to build a stori for surl {}. {}", + surl, e.getMessage()); + returnStatus = CommandHelper.buildStatus( TStatusCode.SRM_AUTHORIZATION_FAILURE, e.getMessage()); printRequestOutcome(returnStatus, inputData); outData = new MkdirOutputData(returnStatus); return outData; } catch (NamespaceException e) { - log.info("Unable to build a stori for surl " + surl - + " NamespaceException: " + e.getMessage()); + log.info("Unable to build a stori for surl {}. {}", + surl, e.getMessage()); returnStatus = CommandHelper.buildStatus( TStatusCode.SRM_INTERNAL_ERROR, e.getMessage()); printRequestOutcome(returnStatus, inputData); outData = new MkdirOutputData(returnStatus); return outData; } catch (InvalidSURLException e) { - log.info("Unable to build a stori for surl " + surl - + " InvalidSURLException: " + e.getMessage()); + log.info("Unable to build a stori for surl {}. {}", + surl, e.getMessage()); returnStatus = CommandHelper.buildStatus( TStatusCode.SRM_INVALID_PATH, e.getMessage()); printRequestOutcome(returnStatus, inputData); @@ -175,8 +183,7 @@ public OutputData execute(InputData data) { } } } catch (IllegalArgumentException e) { - log.error("Unable to get surl's stori. IllegalArgumentException: " - + e.getMessage()); + log.error(e.getMessage(),e); returnStatus = CommandHelper.buildStatus(TStatusCode.SRM_INTERNAL_ERROR, e.getMessage()); printRequestOutcome(returnStatus, inputData); @@ -195,22 +202,19 @@ public OutputData execute(InputData data) { isSpaceAuthorized = spaceAuth.authorizeAnonymous(SRMSpaceRequest.MD); } if (!isSpaceAuthorized) { - // User not authorized to perform RM request on the storage area - log - .debug("srmMkdir: User not authorized to perform srmMkdir request on the storage area: " - + token); + log.debug("srmMkdir: User not authorized to perform srmMkdir request " + + "on the storage area: {}", token); + returnStatus = CommandHelper.buildStatus( TStatusCode.SRM_AUTHORIZATION_FAILURE, ": User not authorized to perform srmMkdir request on the storage area: " + token); + printRequestOutcome(returnStatus, inputData); outData = new MkdirOutputData(returnStatus); return outData; } - /** - * 1.5.0 Path Authorization - */ AuthzDecision decision; if (inputData instanceof IdentityInputData) { decision = AuthzDirector.getPathAuthz().authorize( @@ -220,8 +224,9 @@ public OutputData execute(InputData data) { SRMFileRequest.MD, stori.getStFN()); } if (decision.equals(AuthzDecision.PERMIT)) { - log.debug("srmMkdir authorized for " + DataHelper.getRequestor(inputData) - + " for directory = " + stori.getPFN()); + + log.debug("srmMkdir authorized for {} for directory = {}", + DataHelper.getRequestor(inputData), stori.getPFN()); returnStatus = manageAuthorizedMKDIR(stori, data); } else { @@ -260,7 +265,7 @@ private TReturnStatus createFolder(LocalFile file) { LocalFile parent = file.getParentFile(); if (parent != null) { - log.debug("Mkdir : Parent of '" + file + "' exists"); + log.debug("Mkdir : Parent of '{}' exists.", file); if (!file.exists()) { if (file.mkdir()) { log.debug("SrmMkdir: Request success!"); @@ -332,8 +337,7 @@ private void setAcl(GridUserInterface user, LocalFile file, * read-write-list the new directory Call wrapper to set ACL on file * created. */ - log.debug("SrmMkdir: Adding ACL for directory created : '" + file + "' " - + "group:g_name:--x"); + log.debug("SrmMkdir: Adding ACL for directory '{}' group:g_name:--x", file); /* * Set permission on directory In case of local auth source enable also @@ -346,25 +350,23 @@ private void setAcl(GridUserInterface user, LocalFile file, try { if (user.getLocalUser() == null) { log - .warn("SrmMkdir: Unable to setting up the ACL. LocalUser il null!"); - returnStatus.extendExplaination("Unable to setting up the ACL"); + .warn("SrmMkdir: Unable to setting up the ACL. LocalUser is null!"); + returnStatus.extendExplaination("ACL setup error. Invalid local user."); } else { try { AclManagerFSAndHTTPS.getInstance().grantGroupPermission(file, user.getLocalUser(), permission); } catch (IllegalArgumentException e) { - log - .error("Unable to grant user permission on the created folder. IllegalArgumentException: " - + e.getMessage()); + log.error("Unable to grant user permission on folder. {}", + e.getMessage(),e); returnStatus .extendExplaination("Unable to grant group permission on the created folder"); } } } catch (CannotMapUserException e) { log - .warn("SrmMkdir: Unable to setting up the ACL.CannotMapUserException: " - + e.getMessage()); - returnStatus.extendExplaination("Unable to setting up the ACL"); + .warn("SrmMkdir: ACL setup error. {}", e.getMessage(),e); + returnStatus.extendExplaination("ACL setup error. Local mapping error."); } } } @@ -380,17 +382,18 @@ private void manageDefaultACL(StoRI stori, FilesystemPermission permission, * TODO ATTENTION: here we never set the acl contained in the ACE, we * just add xr or xrw in respect to getEnableWritePermOnDirectory */ - log.debug("Adding DefaultACL for the gid: " + ace.getGroupID() - + " with permission: " + ace.getFilePermissionString()); + log.debug("Adding DefaultACL for the gid: {} with permission: {}", + ace.getGroupID(), ace.getFilePermissionString()); + LocalUser user = new LocalUser(ace.getGroupID(), ace.getGroupID()); try { AclManagerFSAndHTTPS.getInstance().grantGroupPermission( stori.getLocalFile(), user, permission); } catch (IllegalArgumentException e) { log - .error("Unable to grant group permission on the created folder to user " - + user + " . IllegalArgumentException: " + e.getMessage()); - returnStatus.extendExplaination("Errors setting default acls"); + .error("Unable to grant group permission on folder to user {}. {}", + user, e.getMessage(), e); + returnStatus.extendExplaination("Default ACL setup error."); } } } @@ -399,15 +402,18 @@ private void manageDefaultACL(StoRI stori, FilesystemPermission permission, private void setHttpsServiceAcl(LocalFile file, FilesystemPermission permission, TReturnStatus returnStatus) { - log.debug("SrmMkdir: Adding default ACL for directory created : '" + file - + "' " + permission); + log.debug("SrmMkdir: Adding default ACL for directory {}: {}", + file, + permission); + try { AclManagerFSAndHTTPS.getInstance().grantHttpsServiceGroupPermission(file, permission); } catch (IllegalArgumentException e) { log - .error("Unable to grant user permission on the created folder. IllegalArgumentException: " - + e.getMessage()); + .error("Unable to grant user permission on folder. {}", + e.getMessage(), e); + returnStatus .extendExplaination("Unable to grant group permission on the created folder"); } diff --git a/src/main/java/it/grid/storm/synchcall/command/directory/MvCommand.java b/src/main/java/it/grid/storm/synchcall/command/directory/MvCommand.java index 8a788753..f864b34c 100644 --- a/src/main/java/it/grid/storm/synchcall/command/directory/MvCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/directory/MvCommand.java @@ -19,6 +19,9 @@ import java.util.Arrays; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import it.grid.storm.acl.AclManagerFSAndHTTPS; import it.grid.storm.authz.AuthzDecision; import it.grid.storm.authz.AuthzDirector; @@ -64,6 +67,8 @@ public class MvCommand extends DirectoryCommand implements Command { + public static final Logger log = LoggerFactory.getLogger(MvCommand.class); + private static final String SRM_COMMAND = "SrmMv"; private final NamespaceInterface namespace; @@ -95,8 +100,9 @@ public OutputData execute(InputData data) { || (inputData.getToSURL() == null)) { outputData.setStatus(CommandHelper.buildStatus(TStatusCode.SRM_FAILURE, "Invalid parameter specified.")); - log.warn("srmMv: Request failed with [status: " + outputData.getStatus() - + "]"); + log.warn("srmMv: Request failed with [status: {}]", + outputData.getStatus()); + return outputData; } @@ -127,25 +133,29 @@ public OutputData execute(InputData data) { fromStori = namespace.resolveStoRIbySURL(fromSURL, ((IdentityInputData) inputData).getUser()); } catch (UnapprochableSurlException e) { - log.info("srmMv: Unable to build a stori for surl " + fromSURL - + " for user " + DataHelper.getRequestor(inputData) - + " UnapprochableSurlException: " + e.getMessage()); + log.info("srmMv: Unable to build a stori for surl {} for user {}. {}", + fromSURL, + DataHelper.getRequestor(inputData), + e.getMessage()); + outputData.setStatus(CommandHelper.buildStatus( TStatusCode.SRM_AUTHORIZATION_FAILURE, e.getMessage())); printRequestOutcome(outputData.getStatus(), inputData); return outputData; } catch (NamespaceException e) { - log.info("srmMv: Unable to build a stori for surl " + fromSURL - + " for user " + DataHelper.getRequestor(inputData) - + " NamespaceException: " + e.getMessage()); + log.info("srmMv: Unable to build a stori for surl {} for user {}. {}", + fromSURL, + DataHelper.getRequestor(inputData), + e.getMessage()); outputData.setStatus(CommandHelper.buildStatus( TStatusCode.SRM_INTERNAL_ERROR, e.getMessage())); printRequestOutcome(outputData.getStatus(), inputData); return outputData; } catch (InvalidSURLException e) { - log.info("srmMv: Unable to build a stori for surl " + fromSURL - + " for user " + DataHelper.getRequestor(inputData) - + " InvalidSURLException: " + e.getMessage()); + log.info("srmMv: Unable to build a stori for surl {} for user {}. {}", + fromSURL, + DataHelper.getRequestor(inputData), + e.getMessage()); outputData.setStatus(CommandHelper.buildStatus( TStatusCode.SRM_INVALID_PATH, e.getMessage())); printRequestOutcome(outputData.getStatus(), inputData); @@ -154,22 +164,22 @@ public OutputData execute(InputData data) { try { fromStori = namespace.resolveStoRIbySURL(fromSURL); } catch (UnapprochableSurlException e) { - log.info("srmMv: Unable to build a stori for surl " + fromSURL - + " UnapprochableSurlException: " + e.getMessage()); + log.info("srmMv: Unable to build a stori for surl {}. {}",fromSURL + ,e.getMessage()); outputData.setStatus(CommandHelper.buildStatus( TStatusCode.SRM_AUTHORIZATION_FAILURE, e.getMessage())); printRequestOutcome(outputData.getStatus(), inputData); return outputData; } catch (NamespaceException e) { - log.info("srmMv: Unable to build a stori for surl " + fromSURL - + " NamespaceException: " + e.getMessage()); + log.info("srmMv: Unable to build a stori for surl {}. {}",fromSURL + ,e.getMessage()); outputData.setStatus(CommandHelper.buildStatus( TStatusCode.SRM_INTERNAL_ERROR, e.getMessage())); printRequestOutcome(outputData.getStatus(), inputData); return outputData; } catch (InvalidSURLException e) { - log.info("srmMv: Unable to build a stori for surl " + fromSURL - + " InvalidSURLException: " + e.getMessage()); + log.info("srmMv: Unable to build a stori for surl {}. {}",fromSURL + ,e.getMessage()); outputData.setStatus(CommandHelper.buildStatus( TStatusCode.SRM_INVALID_PATH, e.getMessage())); printRequestOutcome(outputData.getStatus(), inputData); @@ -177,8 +187,8 @@ public OutputData execute(InputData data) { } } } catch (IllegalArgumentException e) { - log.warn("srmMv: Unable to build StoRI by SURL:[" + fromSURL - + "]. IllegalArgumentException: " + e.getMessage()); + log.warn("srmMv: Unable to build StoRI by SURL: {}. {}", fromSURL + ,e.getMessage()); outputData.setStatus(CommandHelper.buildStatus( TStatusCode.SRM_INVALID_REQUEST, "Unable to build StoRI by SURL")); printRequestOutcome(outputData.getStatus(), inputData); @@ -192,25 +202,28 @@ public OutputData execute(InputData data) { toStori = namespace.resolveStoRIbySURL(toSURL, ((IdentityInputData) inputData).getUser()); } catch (UnapprochableSurlException e) { - log.info("srmMv: Unable to build a stori for surl " + toSURL - + " for user " + DataHelper.getRequestor(inputData) - + " UnapprochableSurlException: " + e.getMessage()); + log.info("srmMv: Unable to build a stori for surl {} for user {}. {}", + fromSURL, + DataHelper.getRequestor(inputData), + e.getMessage()); outputData.setStatus(CommandHelper.buildStatus( TStatusCode.SRM_AUTHORIZATION_FAILURE, e.getMessage())); printRequestOutcome(outputData.getStatus(), inputData); return outputData; } catch (NamespaceException e) { - log.info("srmMv: Unable to build a stori for surl " + toSURL - + " for user " + DataHelper.getRequestor(inputData) - + " NamespaceException: " + e.getMessage()); + log.info("srmMv: Unable to build a stori for surl {} for user {}. {}", + fromSURL, + DataHelper.getRequestor(inputData), + e.getMessage()); outputData.setStatus(CommandHelper.buildStatus( TStatusCode.SRM_INTERNAL_ERROR, e.getMessage())); printRequestOutcome(outputData.getStatus(), inputData); return outputData; } catch (InvalidSURLException e) { - log.info("srmMv: Unable to build a stori for surl " + toSURL - + " for user " + DataHelper.getRequestor(inputData) - + " InvalidSURLException: " + e.getMessage()); + log.info("srmMv: Unable to build a stori for surl {} for user {}. {}", + fromSURL, + DataHelper.getRequestor(inputData), + e.getMessage()); outputData.setStatus(CommandHelper.buildStatus( TStatusCode.SRM_INVALID_PATH, e.getMessage())); printRequestOutcome(outputData.getStatus(), inputData); @@ -220,22 +233,22 @@ public OutputData execute(InputData data) { try { toStori = namespace.resolveStoRIbySURL(toSURL); } catch (UnapprochableSurlException e) { - log.info("srmMv: Unable to build a stori for surl " + toSURL - + " UnapprochableSurlException: " + e.getMessage()); + log.info("srmMv: Unable to build a stori for surl {}. {}",fromSURL + ,e.getMessage()); outputData.setStatus(CommandHelper.buildStatus( TStatusCode.SRM_AUTHORIZATION_FAILURE, e.getMessage())); printRequestOutcome(outputData.getStatus(), inputData); return outputData; } catch (NamespaceException e) { - log.info("srmMv: Unable to build a stori for surl " + toSURL - + " NamespaceException: " + e.getMessage()); + log.info("srmMv: Unable to build a stori for surl {}. {}",fromSURL + ,e.getMessage()); outputData.setStatus(CommandHelper.buildStatus( TStatusCode.SRM_INTERNAL_ERROR, e.getMessage())); printRequestOutcome(outputData.getStatus(), inputData); return outputData; } catch (InvalidSURLException e) { - log.info("srmMv: Unable to build a stori for surl " + toSURL - + " InvalidSURLException: " + e.getMessage()); + log.info("srmMv: Unable to build a stori for surl {}. {}",fromSURL + ,e.getMessage()); outputData.setStatus(CommandHelper.buildStatus( TStatusCode.SRM_INVALID_PATH, e.getMessage())); printRequestOutcome(outputData.getStatus(), inputData); @@ -243,8 +256,8 @@ public OutputData execute(InputData data) { } } } catch (IllegalArgumentException e) { - log.error("srmMv: Unable to build StoRI by SURL:[" + toSURL - + "]. IllegalArgumentException: " + e.getMessage()); + log.error("srmMv: Unable to build StoRI by SURL: {}. {}", fromSURL + ,e.getMessage(),e); outputData.setStatus(CommandHelper.buildStatus( TStatusCode.SRM_INTERNAL_ERROR, "Unable to build StoRI by destination SURL")); @@ -263,13 +276,10 @@ public OutputData execute(InputData data) { isSpaceAuthorized = spaceAuth.authorizeAnonymous(SRMSpaceRequest.MV); } if (!isSpaceAuthorized) { - log - .debug("srmMv: User not authorized to perform srmMv request on the storage area: " - + token); + log.debug("srmMv: User not authorized to perform srmMv on SA: {}", token); outputData.setStatus(CommandHelper.buildStatus( TStatusCode.SRM_AUTHORIZATION_FAILURE, - ": User not authorized to perform srmMv request on the storage area: " - + token)); + ": User not authorized to perform srmMv on SA: " + token)); printRequestOutcome(outputData.getStatus(), inputData); return outputData; } @@ -287,47 +297,48 @@ public OutputData execute(InputData data) { try { toStori = buildDestinationStoryForFolder(toSURL, fromStori, data); } catch (IllegalArgumentException e) { - log.debug("srmMv : Unable to build StoRI by SURL '" + toSURL - + "'. IllegalArgumentException: " + e.getMessage()); + log.debug("srmMv : Unable to build StoRI for SURL {}. {}", + toSURL, e.getMessage()); + outputData.setStatus(CommandHelper.buildStatus( TStatusCode.SRM_INTERNAL_ERROR, "Unable to build StoRI by SURL")); printRequestOutcome(outputData.getStatus(), inputData); return outputData; } catch (UnapprochableSurlException e) { - log.info("srmMv: Unable to build a stori for surl " + toSURL - + " for user " + DataHelper.getRequestor(inputData) - + " UnapprochableSurlException: " + e.getMessage()); + log.info("srmMv: Unable to build a stori for surl {} for user {}. {}", + toSURL, DataHelper.getRequestor(inputData),e.getMessage()); + outputData.setStatus(CommandHelper.buildStatus( TStatusCode.SRM_AUTHORIZATION_FAILURE, e.getMessage())); printRequestOutcome(outputData.getStatus(), inputData); return outputData; } catch (InvalidTSURLAttributesException e) { - log - .error("Unable to create toSURL. InvalidTSURLAttributesException: " - + e.getMessage()); + log.info("srmMv: Unable to build a stori for surl {} for user {}. {}", + toSURL, DataHelper.getRequestor(inputData),e.getMessage()); + outputData.setStatus(CommandHelper.buildStatus( TStatusCode.SRM_INVALID_PATH, "Invalid toSURL specified!")); printRequestOutcome(outputData.getStatus(), inputData); return outputData; } catch (NamespaceException e) { - log.info("srmMv: Unable to build a stori for surl " + toSURL - + " for user " + DataHelper.getRequestor(inputData) - + " NamespaceException: " + e.getMessage()); + log.info("srmMv: Unable to build a stori for surl {} for user {}. {}", + toSURL, DataHelper.getRequestor(inputData),e.getMessage()); + outputData.setStatus(CommandHelper.buildStatus( TStatusCode.SRM_INTERNAL_ERROR, e.getMessage())); printRequestOutcome(outputData.getStatus(), inputData); return outputData; } catch (InvalidSURLException e) { - log.info("srmMv: Unable to build a stori for surl " + toSURL - + " for user " + DataHelper.getRequestor(inputData) - + " InvalidSURLException: " + e.getMessage()); + log.info("srmMv: Unable to build a stori for surl {} for user {}. {}", + toSURL, DataHelper.getRequestor(inputData),e.getMessage()); + outputData.setStatus(CommandHelper.buildStatus( TStatusCode.SRM_INVALID_PATH, e.getMessage())); printRequestOutcome(outputData.getStatus(), inputData); return outputData; } } else { - log.debug("srmMv : destination SURL " + toSURL + " already exists! "); + log.debug("srmMv : destination SURL {} already exists.", toSURL); outputData.setStatus(CommandHelper .buildStatus(TStatusCode.SRM_DUPLICATION_ERROR, "destination SURL already exists!")); @@ -357,9 +368,12 @@ public OutputData execute(InputData data) { TReturnStatus returnStatus; if ((sourceDecision.equals(AuthzDecision.PERMIT)) && (destinationDecision.equals(AuthzDecision.PERMIT))) { - log.debug("SrmMv: Mv authorized for " - + DataHelper.getRequestor(inputData) + " for Source file = " - + fromStori.getPFN() + " to Target file =" + toStori.getPFN()); + + log.debug("SrmMv: Mv authorized for user {}. Source: {}. Target: {}", + DataHelper.getRequestor(inputData), + fromStori.getPFN(), + toStori.getPFN()); + returnStatus = manageAuthorizedMV(fromStori, toStori.getLocalFile()); if (returnStatus.isSRM_SUCCESS()) { LocalUser user = null; @@ -368,7 +382,12 @@ public OutputData execute(InputData data) { user = ((IdentityInputData) inputData).getUser().getLocalUser(); } catch (CannotMapUserException e) { log - .warn("srmMv: failed to get the requesting local user,unable to set user acls on the created file"); + .warn("srmMv: user mapping error {}", e.getMessage()); + + if (log.isDebugEnabled()){ + log.error(e.getMessage(),e); + } + returnStatus .extendExplaination("unable to set user acls on the destination file"); } @@ -379,27 +398,33 @@ public OutputData execute(InputData data) { setAcl(fromStori, toStori); } } else { - log.warn("srmMv: <" + DataHelper.getRequestor(inputData) - + "> Request for [fromSURL=" + fromSURL + "; toSURL=" + toSURL - + "] failed with [status: " + returnStatus.toString() + "]"); + log.warn("srmMv: <{}> Request for [fromSURL={}; toSURL={}] failed with [status: {}]", + DataHelper.getRequestor(inputData), + fromSURL, + toSURL, + returnStatus); } } else { + + String errorMsg = "Authorization error"; + if (sourceDecision.equals(AuthzDecision.PERMIT)) { - returnStatus = CommandHelper.buildStatus( - TStatusCode.SRM_AUTHORIZATION_FAILURE, - "User is not authorized to create and/or write the destination file"); + errorMsg = + "User is not authorized to create and/or write the destination file"; } else { if (destinationDecision.equals(AuthzDecision.PERMIT)) { - returnStatus = CommandHelper.buildStatus( - TStatusCode.SRM_AUTHORIZATION_FAILURE, - "User is not authorized to read and/or delete the source file"); + errorMsg = + "User is not authorized to read and/or delete the source file"; } else { - returnStatus = CommandHelper.buildStatus( - TStatusCode.SRM_AUTHORIZATION_FAILURE, - "User is neither authorized to read and/or delete the source file " - + "nor to create and/or write the destination file"); + errorMsg = + "User is neither authorized to read and/or delete the source file " + + "nor to create and/or write the destination file"; } } + + returnStatus = + CommandHelper.buildStatus(TStatusCode.SRM_AUTHORIZATION_FAILURE, + errorMsg); } outputData.setStatus(returnStatus); printRequestOutcome(outputData.getStatus(), inputData); @@ -417,7 +442,7 @@ private StoRI buildDestinationStoryForFolder(TSURL toSURL, StoRI fromStori, toSURLString += "/"; } toSURLString += fromStori.getFilename(); - log.debug("srmMv: New toSURL: " + toSURLString); + log.debug("srmMv: New toSURL: {}", toSURLString); if (inputData instanceof IdentityInputData) { toStori = namespace.resolveStoRIbySURL( TSURL.makeFromStringValidate(toSURLString), @@ -436,8 +461,8 @@ private void setAcl(StoRI oldFileStoRI, StoRI newFileStoRI) { oldFileStoRI.getLocalFile(), newFileStoRI.getLocalFile()); } catch (IllegalArgumentException e) { log - .error("Unable to move permissions from the old to the new file. IllegalArgumentException: " - + e.getMessage()); + .error("Unable to move permissions from the old to the new file.{}", + e.getMessage(), e); } } @@ -453,8 +478,9 @@ private void setAcl(StoRI oldFileStoRI, StoRI newFileStoRI, FilesystemPermission.ReadWrite); } catch (IllegalArgumentException e) { log - .error("Unable to grant user read and write permission on the new file. IllegalArgumentException: " - + e.getMessage()); + .error("Unable to grant user read and write permission on file. {}", + e.getMessage(), + e); } } else { // AoT @@ -464,8 +490,8 @@ private void setAcl(StoRI oldFileStoRI, StoRI newFileStoRI, FilesystemPermission.ReadWrite); } catch (IllegalArgumentException e) { log - .error("Unable to grant group read and write permission on the new file. IllegalArgumentException: " - + e.getMessage()); + .error("Unable to grant group read and write permission on file. {}" + ,e.getMessage(),e); } } } @@ -514,7 +540,6 @@ private TReturnStatus manageAuthorizedMV(StoRI fromStori, LocalFile toFile) { } if (sourceExists && targetDirExists && !targetFileExists) { - // Request on valid from and to file. log.debug("srmMv : All Check passed."); /** @@ -534,14 +559,11 @@ private TReturnStatus manageAuthorizedMV(StoRI fromStori, LocalFile toFile) { "Unexpected IllegalArgumentException in SurlStatusManager.getSurlsStatus: " + e); } catch (UnknownSurlException e) { - log.debug("Surl " + fromStori.getSURL() - + " not stored, surl is not busy. UnknownSurlException: " - + e.getMessage()); + log.debug("Unknown surl: {}. {}", fromStori.getSURL(), e.getMessage()); } if ((surlStatus != null) && (TStatusCode.SRM_SPACE_AVAILABLE.equals(surlStatus.getStatusCode()))) { - // There is an active PrepareToPut! log .debug("srmMv requests fails because there is a PrepareToPut on the from SURL."); explanation = "There is an active SrmPrepareToPut on from SURL."; diff --git a/src/main/java/it/grid/storm/synchcall/command/directory/RmCommand.java b/src/main/java/it/grid/storm/synchcall/command/directory/RmCommand.java index cbeecf55..81dcd632 100644 --- a/src/main/java/it/grid/storm/synchcall/command/directory/RmCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/directory/RmCommand.java @@ -65,7 +65,7 @@ public class RmCommand implements Command { private static final String SRM_COMMAND = "srmRm"; - private final Logger log = LoggerFactory.getLogger(RmCommand.class); + private static final Logger log = LoggerFactory.getLogger(RmCommand.class); private final String funcName = "srmRm"; private final NamespaceInterface namespace; @@ -108,9 +108,9 @@ public OutputData execute(InputData inputDataGeneric) { ArrayOfSURLs surlArray = inputData.getSurlArray(); ArrayOfTSURLReturnStatus arrayOfFileStatus = new ArrayOfTSURLReturnStatus(); - log.debug("srmRm: DirManager: Rm: SURLVectorSize: " + surlArray.size()); + log.debug("srmRm: DirManager: Rm: SURLVectorSize: {}", surlArray.size()); for (TSURL surl : inputData.getSurlArray().getArrayList()) { - log.debug("srmRm: DirManager: Rm: SURL: " + surl); + log.debug("srmRm: DirManager: Rm: SURL: {}" ,surl); TSURLReturnStatus fileStatus = new TSURLReturnStatus(); fileStatus.setSurl(surl); TReturnStatus returnStatus = null; @@ -122,9 +122,11 @@ public OutputData execute(InputData inputDataGeneric) { stori = namespace.resolveStoRIbySURL(surl, ((IdentityInputData) inputData).getUser()); } catch (UnapprochableSurlException e) { - log.info("Unable to build a stori for surl " + surl - + " for user " + DataHelper.getRequestor(inputData) - + " UnapprochableSurlException: " + e.getMessage()); + log.info("Unable to build a stori for surl {} for user {}. {}", + surl, + DataHelper.getRequestor(inputData), + e.getMessage()); + globalStatus = CommandHelper.buildStatus( TStatusCode.SRM_AUTHORIZATION_FAILURE, e.getMessage()); printRequestOutcome(globalStatus, inputData); @@ -132,9 +134,10 @@ public OutputData execute(InputData inputDataGeneric) { outputData.setSurlStatus(null); return outputData; } catch (NamespaceException e) { - log.info("Unable to build a stori for surl " + surl - + " for user " + DataHelper.getRequestor(inputData) - + " NamespaceException: " + e.getMessage()); + log.info("Unable to build a stori for surl {} for user {}. {}", + surl, + DataHelper.getRequestor(inputData), + e.getMessage()); globalStatus = CommandHelper.buildStatus( TStatusCode.SRM_INTERNAL_ERROR, e.getMessage()); printRequestOutcome(globalStatus, inputData); @@ -142,9 +145,10 @@ public OutputData execute(InputData inputDataGeneric) { outputData.setSurlStatus(null); return outputData; } catch (InvalidSURLException e) { - log.info("Unable to build a stori for surl " + surl - + " for user " + DataHelper.getRequestor(inputData) - + " InvalidSURLException: " + e.getMessage()); + log.info("Unable to build a stori for surl {} for user {}. {}", + surl, + DataHelper.getRequestor(inputData), + e.getMessage()); globalStatus = CommandHelper.buildStatus( TStatusCode.SRM_INVALID_PATH, e.getMessage()); printRequestOutcome(globalStatus, inputData); @@ -156,8 +160,8 @@ public OutputData execute(InputData inputDataGeneric) { try { stori = namespace.resolveStoRIbySURL(surl); } catch (UnapprochableSurlException e) { - log.info("Unable to build a stori for surl " + surl - + " UnapprochableSurlException: " + e.getMessage()); + log.info("Unable to build a stori for surl {}. {}", + surl, e.getMessage()); globalStatus = CommandHelper.buildStatus( TStatusCode.SRM_AUTHORIZATION_FAILURE, e.getMessage()); printRequestOutcome(globalStatus, inputData); @@ -165,8 +169,8 @@ public OutputData execute(InputData inputDataGeneric) { outputData.setSurlStatus(null); return outputData; } catch (NamespaceException e) { - log.info("Unable to build a stori for surl " + surl - + " NamespaceException: " + e.getMessage()); + log.info("Unable to build a stori for surl {}. {}", + surl, e.getMessage()); globalStatus = CommandHelper.buildStatus( TStatusCode.SRM_INTERNAL_ERROR, e.getMessage()); printRequestOutcome(globalStatus, inputData); @@ -174,8 +178,8 @@ public OutputData execute(InputData inputDataGeneric) { outputData.setSurlStatus(null); return outputData; } catch (InvalidSURLException e) { - log.info("Unable to build a stori for surl " + surl - + " InvalidSURLException: " + e.getMessage()); + log.info("Unable to build a stori for surl {}. {}", + surl, e.getMessage()); globalStatus = CommandHelper.buildStatus( TStatusCode.SRM_INVALID_PATH, e.getMessage()); printRequestOutcome(globalStatus, inputData); @@ -185,9 +189,9 @@ public OutputData execute(InputData inputDataGeneric) { } } } catch (IllegalArgumentException e) { - log - .error("SrmRm: Unable to build StoRI by surl and user. IllegalArgumentException: " - + e.getMessage()); + + log.error("SrmRm: StoRI from surl error: {}", e.getMessage(), e); + globalStatus = CommandHelper.buildStatus( TStatusCode.SRM_INTERNAL_ERROR, e.getMessage()); printRequestOutcome(globalStatus, inputData); @@ -196,7 +200,7 @@ public OutputData execute(InputData inputDataGeneric) { return outputData; } } else { - log.error("srmRm: Malformed SURL passed from converter "); + log.error("srmRm: Invalid SURL {}", surl); returnStatus = CommandHelper.buildStatus(TStatusCode.SRM_INVALID_PATH, "Invalid SURL"); printSurlOutcome(returnStatus, inputData, surl); @@ -223,9 +227,8 @@ public OutputData execute(InputData inputDataGeneric) { } if (decision.equals(AuthzDecision.PERMIT)) { - log.debug("srmRm: authorized for " - + DataHelper.getRequestor(inputData) + " for file = " - + stori.getPFN()); + log.debug("srmRm: authorized for {} on file= {}", + DataHelper.getRequestor(inputData) , stori.getPFN()); // Prior to delete the file get the actual file size to update // properly the DB @@ -237,8 +240,8 @@ public OutputData execute(InputData inputDataGeneric) { returnStatus = manageAuthorizedRM(surl, stori); } catch (IllegalArgumentException e) { log - .error("srmRm: IllegalArgumentException from manageAuthorizedRM: " - + e); + .error("srmRm: {}", e.getMessage(), e); + globalStatus = CommandHelper.buildStatus( TStatusCode.SRM_INTERNAL_ERROR, "Error while performing an authorized rm"); @@ -247,8 +250,7 @@ public OutputData execute(InputData inputDataGeneric) { outputData.setSurlStatus(null); return outputData; } catch (UnknownSurlException e) { - log.error("srmRm: UnknownSurlException from manageAuthorizedRM: " - + e); + log.error("srmRm: {}", e.getMessage(), e); returnStatus = CommandHelper.buildStatus( TStatusCode.SRM_INVALID_PATH, "The SURL is unknown"); } @@ -269,16 +271,17 @@ public OutputData execute(InputData inputDataGeneric) { } } else { log - .debug("srmRm: User not authorized to delete the file AuthzDecision is :'" - + decision + "')"); + .debug("srmRm: User not authorized to delete file. AuthzDecision: {}", + decision); returnStatus = CommandHelper.buildStatus( TStatusCode.SRM_AUTHORIZATION_FAILURE, "User is not authorized to delete the file"); } } else { log - .debug("srmRm: User not authorized to perform srmRm request on the storage area: " - + token); + .debug("srmRm: User not authorized to perform srmRm on SA: {}", + token); + returnStatus = CommandHelper.buildStatus( TStatusCode.SRM_AUTHORIZATION_FAILURE, "User not authorized to perform " @@ -391,39 +394,18 @@ private TReturnStatus manageAuthorizedRM(TSURL surl, StoRI stori) } } - // Build the ReturnStatus try { returnStatus = new TReturnStatus(statusCode, explanation); } catch (InvalidTReturnStatusAttributeException ex1) { - log.debug("srmRm: Error creating returnStatus " + ex1); + log.debug("srmRm: {}", ex1.getMessage(), ex1); } return returnStatus; } - private boolean removeTarget(LocalFile file/* , LocalUser lUser */) { + private boolean removeTarget(LocalFile file) { boolean result = false; - // Check Permission - // FilesystemPermission groupPermission = null; - // try { - // groupPermission = file.getGroupPermission(lUser); - // } catch (CannotMapUserException ex) { - // /** - // * @todo : Why this exception? - // */ - // log.debug("srmRm: WHY THIS? " + ex); - // } - - // FilesystemPermission userPermission = null; - // try { - // userPermission = file.getUserPermission(lUser); - // } catch (CannotMapUserException ex1) { - // /** - // * @todo : Why this exception? - // */ - // log.debug("srmRm: WHY THIS? " + ex1); - // } /** * Same situation in Rmdir This check is really needed here? The check can @@ -431,23 +413,14 @@ private boolean removeTarget(LocalFile file/* , LocalUser lUser */) { * case add check for null permission. */ - // Check if user or group permission are null to prevent Null Pointer boolean canDelete = true; - /* - * if(userPermission!=null) { canDelete = userPermission.canDelete(); - * log.debug("removeTarget:userP:"+userPermission.canDelete()); } if - * ((groupPermission!=null)&&(!canDelete)) { - * log.debug("removeTarget:groupP:"+groupPermission.canDelete()); canDelete - * = groupPermission.canDelete(); } - */ - - // if ( (userPermission.canDelete()) || (groupPermission.canDelete())) { if (canDelete) { result = file.delete(); } else { - log.debug("srmRm : Unable to delete the file '" + file - + "'. Permission denied."); + + log.debug("srmRm : Unable to delete the file {}. Permission denied.", + file); } return result; } diff --git a/src/main/java/it/grid/storm/synchcall/command/directory/RmdirCommand.java b/src/main/java/it/grid/storm/synchcall/command/directory/RmdirCommand.java index 1cc9b037..9cf9408f 100644 --- a/src/main/java/it/grid/storm/synchcall/command/directory/RmdirCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/directory/RmdirCommand.java @@ -19,6 +19,9 @@ import java.util.Arrays; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import it.grid.storm.authz.AuthzDecision; import it.grid.storm.authz.AuthzDirector; import it.grid.storm.authz.SpaceAuthzInterface; @@ -57,6 +60,7 @@ public class RmdirCommand extends DirectoryCommand implements Command { + public static final Logger log = LoggerFactory.getLogger(RmdirCommand.class); private static final String SRM_COMMAND = "srmRmdir"; private final NamespaceInterface namespace; @@ -103,25 +107,29 @@ public OutputData execute(InputData data) { stori = namespace.resolveStoRIbySURL(surl, ((IdentityInputData) inputData).getUser()); } catch (UnapprochableSurlException e) { - log.info("Unable to build a stori for surl " + surl + " for user " - + DataHelper.getRequestor(inputData) - + " UnapprochableSurlException: " + e.getMessage()); + log.info("Unable to build a stori for surl {} for user {}: {}", + surl, + DataHelper.getRequestor(inputData), + e.getMessage()); + returnStatus = CommandHelper.buildStatus( TStatusCode.SRM_AUTHORIZATION_FAILURE, e.getMessage()); printRequestOutcome(returnStatus, inputData); return new RmdirOutputData(returnStatus); } catch (NamespaceException e) { - log.info("Unable to build a stori for surl " + surl + " for user " - + DataHelper.getRequestor(inputData) - + " NamespaceException: " + e.getMessage()); + log.info("Unable to build a stori for surl {} for user {}: {}", + surl, + DataHelper.getRequestor(inputData), + e.getMessage()); returnStatus = CommandHelper.buildStatus( TStatusCode.SRM_INTERNAL_ERROR, e.getMessage()); printRequestOutcome(returnStatus, inputData); return new RmdirOutputData(returnStatus); } catch (InvalidSURLException e) { - log.info("Unable to build a stori for surl " + surl + " for user " - + DataHelper.getRequestor(inputData) - + " InvalidSURLException: " + e.getMessage()); + log.info("Unable to build a stori for surl {} for user {}: {}", + surl, + DataHelper.getRequestor(inputData), + e.getMessage()); returnStatus = CommandHelper.buildStatus( TStatusCode.SRM_INVALID_PATH, e.getMessage()); printRequestOutcome(returnStatus, inputData); @@ -131,22 +139,25 @@ public OutputData execute(InputData data) { try { stori = namespace.resolveStoRIbySURL(surl); } catch (UnapprochableSurlException e) { - log.info("Unable to build a stori for surl " + surl - + " UnapprochableSurlException: " + e.getMessage()); + log.info("Unable to build a stori for surl {}: {}", + surl, + e.getMessage()); returnStatus = CommandHelper.buildStatus( TStatusCode.SRM_AUTHORIZATION_FAILURE, e.getMessage()); printRequestOutcome(returnStatus, inputData); return new RmdirOutputData(returnStatus); } catch (NamespaceException e) { - log.info("Unable to build a stori for surl " + surl - + " NamespaceException: " + e.getMessage()); + log.info("Unable to build a stori for surl {}: {}", + surl, + e.getMessage()); returnStatus = CommandHelper.buildStatus( TStatusCode.SRM_INTERNAL_ERROR, e.getMessage()); printRequestOutcome(returnStatus, inputData); return new RmdirOutputData(returnStatus); } catch (InvalidSURLException e) { - log.info("Unable to build a stori for surl " + surl - + " InvalidSURLException: " + e.getMessage()); + log.info("Unable to build a stori for surl {}: {}", + surl, + e.getMessage()); returnStatus = CommandHelper.buildStatus( TStatusCode.SRM_INVALID_PATH, e.getMessage()); printRequestOutcome(returnStatus, inputData); @@ -154,9 +165,8 @@ public OutputData execute(InputData data) { } } } catch (IllegalArgumentException e) { - log - .error("srmRmdir: Unable to build StoRI by surl and user. IllegalArgumentException: " - + e.getMessage()); + log.error("StoRI from surl build error: {}", + e.getMessage(), e); returnStatus = CommandHelper.buildStatus( TStatusCode.SRM_INTERNAL_ERROR, e.getMessage()); printRequestOutcome(returnStatus, inputData); @@ -193,16 +203,13 @@ public OutputData execute(InputData data) { isSpaceAuthorized = spaceAuth.authorizeAnonymous(SRMSpaceRequest.RMD); } if (!isSpaceAuthorized) { - log - .debug("srmRmdir: User not authorized to perform srmRmdir request on the storage area: " - + token); + log.debug("User not authorized to perform srmRmdir on SA: {}", token); returnStatus = CommandHelper.buildStatus( TStatusCode.SRM_AUTHORIZATION_FAILURE, - "User not authorized to perform srmRmdir request on the storage area"); + "User not authorized to perform srmRmdir on storage area"); printRequestOutcome(returnStatus, inputData); outData = new RmdirOutputData(returnStatus); return outData; - } AuthzDecision decision; @@ -214,9 +221,10 @@ public OutputData execute(InputData data) { SRMFileRequest.RMD, stori.getStFN()); } if (decision.equals(AuthzDecision.PERMIT)) { - log.debug("RMDIR is authorized for " + DataHelper.getRequestor(inputData) - + " and the directory = " + stori.getPFN() + " with recursove opt = " - + recursive); + log.debug("srmRmDir authorized for {}. Dir={}. Recursive={}", + DataHelper.getRequestor(inputData), + stori.getPFN(), + recursive); returnStatus = manageAuthorizedRMDIR(stori.getLocalFile(), recursive.booleanValue()); } else { diff --git a/src/main/java/it/grid/storm/synchcall/xmlrpc.cld b/src/main/java/it/grid/storm/synchcall/xmlrpc.cld deleted file mode 100644 index b5c65dec..00000000 --- a/src/main/java/it/grid/storm/synchcall/xmlrpc.cld +++ /dev/null @@ -1,1646 +0,0 @@ - - - - - - - it.grid.storm.synchcall.CommandFactory - - - 1350 - 158 - -1 - -1 - - - - - - - - - it.grid.storm.synchcall.SynchcallDispatcher - - false - - 1285 - 279 - -1 - -1 - - - - - - - - - cmdFactory - CommandFactory - false - - 255 - 255 - 206 - - - 0 - 0 - 0 - - true - - - - - 2 - - - - - - - - - processRequest - OutputData - - - type - OperationType - - - inputData - InputData - - - false - false - - - true - - - - - 2 - - - - - - - - - - - true - - - - - 2 - - - - - - - - true - - - - 2 - - - - - - - - - - - it.grid.storm.synchcall.SimpleCommandFactory - - false - - 1340 - 48 - -1 - -1 - - - - - - - - - getCommand - Command - - - type - OperationType - - - false - false - - - true - - - - - 2 - - - - - - - - - - - true - - - - - 2 - - - - - - - - - true - - - - 2 - - - - - - - - - - - getCommand - Command - - - type - OperationType - - - false - false - - - true - - - - - 2 - - - - - - - - - - - true - - - - - 2 - - - - - - - - - - it.grid.storm.xmlrpc.XMLRPCExecutor - - false - - 0 - 800 - -1 - -1 - - - - - - - - - it.grid.storm.xmlrpc.XMLRPCMethods - - false - - 0 - 265 - -1 - -1 - - - - - - - - - log - Logger - true - - - true - - - - - 2 - - - - - - - - - config - Configuration - false - - - true - - - - - 2 - - - - - - - - - converterFactory - XMLRPCConveterFactory - false - - - true - - - - - 2 - - - - - - - - - executor - XMLRPCExecutor - false - - - true - - - - - 2 - - - - - - - - - XMLRPCMethods - void - - false - false - - - true - - - - - 2 - - - - - - - - - addTwo - int - - - x - int - - - y - int - - - false - false - - - true - - - - - 2 - - - - - - - - - vectorSize - int - - - vect - Vector - - - false - false - - - true - - - - - 2 - - - - - - - - - ping - Map - - - inputParam - Map - - - false - false - - - true - - - - - 2 - - - - - - - - - putDone - Map - - - inputParam - Map - - - false - false - - - true - - - - - 2 - - - - - - - - - releaseFiles - Map - - - inputParam - Map - - - false - false - - - true - - - - - 2 - - - - - - - - - extendFileLifeTime - Map - - - inputParam - Map - - - false - false - - - true - - - - - 2 - - - - - - - - - abortRequest - Map - - - inputParam - Map - - - false - false - - - true - - - - - 2 - - - - - - - - - abortFiles - Map - - - inputParam - HashMap - - - false - false - - - true - - - - - 2 - - - - - - - - - reserveSpace - Map - - - inputParam - Map - - - false - false - - - true - - - - - 2 - - - - - - - - - getSpaceMetaData - Map - - - inputParam - HashMap - - - false - false - - - true - - - - - 2 - - - - - - - - - getSpaceTokens - Map - - - inputParam - Map - - - false - false - - - true - - - - - 2 - - - - - - - - - ReleaseSpace - Map - - - inputParam - Map - - - false - false - - - true - - - - - 2 - - - - - - - - - ls - Map - - - inputParam - Map - - - false - false - - - true - - - - - 2 - - - - - - - - - mkdir - Map - - - inputParam - Map - - - false - false - - - true - - - - - 2 - - - - - - - - - rmdir - Map - - - inputParam - Map - - - false - false - - - true - - - - - 2 - - - - - - - - - rm - Map - - - inputParam - Map - - - false - false - - - true - - - - - 2 - - - - - - - - - mv - Map - - - inputParam - Map - - - false - false - - - true - - - - - 2 - - - - - - - - - logExecution - void - - - opType - OperationType - - - dn - String - - - startTime - long - - - duration - long - - - successResult - boolean - - - false - false - - - true - - - - - 2 - - - - - - - - - - - true - - - - - 2 - - - - - - - - true - - - - 2 - - - - - - - - - - - - log - Logger - true - - - true - - - - - 2 - - - - - - - - - converterFactory - XMLRPCConveterFactory - false - - - true - - - - - 2 - - - - - - - - - execute - Map - - - type - OperationType - - - inputParam - Map - - - false - false - - - true - - - - - 2 - - - - - - - - - logExecution - void - - - opType - OperationType - - - dn - String - - - startTime - long - - - duration - long - - - successResult - boolean - - - false - false - - - true - - - - - 2 - - - - - - - - - - - true - - - - - 2 - - - - - - - - it.grid.storm.xmlrpc.XMLRPCHttpServer - - false - - 0 - 0 - -1 - -1 - - - - - - - log - Logger - true - - - true - - - - - 2 - - - - - - - - - _port - int - false - - - true - - - - - 2 - - - - - - - - - _secure_port - int - false - - - true - - - - - 2 - - - - - - - - - fe_hostname_array - List - false - - - true - - - - - 2 - - - - - - - - - fe_IP_array - List - false - - - true - - - - - 2 - - - - - - - - - config - Configuration - false - - - true - - - - - 2 - - - - - - - - - XMLRPCHttpServer - void - - false - false - - - true - - - - - 2 - - - - - - - - - createServer - void - - false - false - - - true - - - - - 2 - - - - - - - - - logExecution - void - - - opType - OperationType - - - dn - String - - - startTime - long - - - duration - long - - - successResult - boolean - - - false - false - - - true - - - - - 2 - - - - - - - - - main - void - - - args - String[] - - - false - true - - - true - - - - - 2 - - - - - - - - - - - true - - - - - 2 - - - - - - - - - it.grid.storm.xmlrpc.converter.Converter - - - 1286 - 796 - -1 - -1 - - - - - - it.grid.storm.xmlrpc.converter.directory.RmConverter - - false - - 1289 - 941 - -1 - -1 - - - - - - - - - log - Logger - true - - - true - - - - - 2 - - - - - - - - - RmConverter - void - - false - false - - - true - - - - - 2 - - - - - - - - - convertToInputData - InputData - - - inputParam - Map - - - false - false - - - true - - - - - 2 - - - - - - - - - convertFromOutputData - Map - - - outputData - OutputData - - - false - false - - - true - - - - - 2 - - - - - - - - - - - true - - - - - 2 - - - - - - - - - true - - - - 2 - - - - - - - - - - - convertToInputData - InputData - - - inputParam - Map - - - true - false - - - true - - - - - 2 - - - - - - - - - convertFromOutputData - Map - - - outputData - OutputData - - - true - false - - - true - - - - - 2 - - - - - - - - - - - true - - - - - 2 - - - - - - - - it.grid.storm.xmlrpc.converter.ConverterFactory - - - 862 - 648 - -1 - -1 - - - - - - it.grid.storm.xmlrpc.converter.XMLRPCConveterFactory - - false - - 837 - 791 - -1 - -1 - - - - - - - - - getConverter - Converter - - - type - OperationType - - - false - false - - - true - - - - - 2 - - - - - - - - - - - true - - - - - 2 - - - - - - - - - true - - - - 2 - - - - - - - - - - - RM - int - false - - - true - - - - - 2 - - - - - - - - - getConverter - Converter - - - type - int - - - false - false - - - true - - - - - 2 - - - - - - - - - - - true - - - - - 2 - - - - - - - - - - - - - true - - - - 2 - - - - - - \ No newline at end of file From 14be7cf530b3da894563bc7222387aa11bd6121f Mon Sep 17 00:00:00 2001 From: Andrea Ceccanti Date: Wed, 5 Feb 2014 11:17:04 +0100 Subject: [PATCH 20/45] Fix broken build. --- .../grid/storm/synchcall/command/discovery/PingCommand.java | 4 ++++ .../synchcall/command/space/GetSpaceMetaDataCommand.java | 5 +++++ .../storm/synchcall/command/space/GetSpaceTokensCommand.java | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/src/main/java/it/grid/storm/synchcall/command/discovery/PingCommand.java b/src/main/java/it/grid/storm/synchcall/command/discovery/PingCommand.java index 670a7573..f8799fcd 100644 --- a/src/main/java/it/grid/storm/synchcall/command/discovery/PingCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/discovery/PingCommand.java @@ -45,6 +45,9 @@ import java.util.Properties; import java.util.Map.Entry; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * This class is part of the StoRM project. Copyright: Copyright (c) 2008 * Company: INFN-CNAF and ICTP/EGRID project @@ -57,6 +60,7 @@ public class PingCommand extends DiscoveryCommand implements Command { + public static final Logger log = LoggerFactory.getLogger(PingCommand.class); private static final String KEY_ELEMENT_KEY = "key="; public PingCommand() { diff --git a/src/main/java/it/grid/storm/synchcall/command/space/GetSpaceMetaDataCommand.java b/src/main/java/it/grid/storm/synchcall/command/space/GetSpaceMetaDataCommand.java index 3636c3b2..ce196bec 100644 --- a/src/main/java/it/grid/storm/synchcall/command/space/GetSpaceMetaDataCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/space/GetSpaceMetaDataCommand.java @@ -17,6 +17,9 @@ package it.grid.storm.synchcall.command.space; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import it.grid.storm.catalogs.ReservedSpaceCatalog; import it.grid.storm.griduser.GridUserInterface; import it.grid.storm.persistence.exceptions.DataAccessException; @@ -58,6 +61,8 @@ public class GetSpaceMetaDataCommand extends SpaceCommand implements Command { + public static final Logger log = LoggerFactory.getLogger(GetSpaceMetaDataCommand.class); + private ReservedSpaceCatalog catalog = null; private static final boolean SUCCESS = true; diff --git a/src/main/java/it/grid/storm/synchcall/command/space/GetSpaceTokensCommand.java b/src/main/java/it/grid/storm/synchcall/command/space/GetSpaceTokensCommand.java index 56a2c5ea..b49bf73c 100644 --- a/src/main/java/it/grid/storm/synchcall/command/space/GetSpaceTokensCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/space/GetSpaceTokensCommand.java @@ -17,6 +17,9 @@ package it.grid.storm.synchcall.command.space; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import it.grid.storm.catalogs.ReservedSpaceCatalog; import it.grid.storm.griduser.GridUserInterface; import it.grid.storm.srm.types.ArrayOfTSpaceToken; @@ -47,6 +50,8 @@ public class GetSpaceTokensCommand extends SpaceCommand implements Command { + public static final Logger log = LoggerFactory.getLogger(GetSpaceTokensCommand.class); + private static final String SRM_COMMAND = "srmGetSpaceTokens"; private ReservedSpaceCatalog catalog = null; From 06931f0d00df842b85b5076c293c8942ae51aae3 Mon Sep 17 00:00:00 2001 From: Andrea Ceccanti Date: Wed, 5 Feb 2014 14:53:13 +0100 Subject: [PATCH 21/45] More logging rationalization work. --- .../command/directory/RmdirCommand.java | 19 +++--- .../command/discovery/PingCommand.java | 61 ++++++------------- 2 files changed, 29 insertions(+), 51 deletions(-) diff --git a/src/main/java/it/grid/storm/synchcall/command/directory/RmdirCommand.java b/src/main/java/it/grid/storm/synchcall/command/directory/RmdirCommand.java index 9cf9408f..25edb41d 100644 --- a/src/main/java/it/grid/storm/synchcall/command/directory/RmdirCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/directory/RmdirCommand.java @@ -256,16 +256,15 @@ private TReturnStatus manageAuthorizedRMDIR(LocalFile directory, if ((directory.exists()) && (directory.isDirectory())) { if (recursive) { - // All directory and files contained are removed. - log.debug(SRM_COMMAND - + ": Recursive deletion. Removing dir with all files included! "); + + log.debug("{}: Recursive deletion will remove directory and contents.", SRM_COMMAND); + if (!deleteDirectoryContent(directory)) { return CommandHelper.buildStatus(TStatusCode.SRM_FAILURE, "Unable to delete some files within directory."); } } - // Now Directory should be Empty; - // NON-Recursive Option + if (!removeFile(directory)) { returnStatus = CommandHelper.buildStatus( TStatusCode.SRM_NON_EMPTY_DIRECTORY, "Directory is not empty"); @@ -274,7 +273,7 @@ private TReturnStatus manageAuthorizedRMDIR(LocalFile directory, "Directory removed with success!"); } } else { - log.debug("RMDIR : request with invalid directory specified!"); + log.debug("{}: request with invalid directory specified!", SRM_COMMAND); if (!directory.exists()) { returnStatus = CommandHelper.buildStatus(TStatusCode.SRM_INVALID_PATH, "Directory does not exists"); @@ -322,8 +321,10 @@ private boolean removeFile(LocalFile file) { list = file.listFiles(); if (list.length > 0) { result = false; - log.info(SRM_COMMAND + ": Unable to delete the target file '" + file - + "' . It is a not-empty directory."); + + log.info("{} : Unable to delete non-empty directory {}", + SRM_COMMAND, file); + } else { result = file.delete(); } @@ -332,7 +333,7 @@ private boolean removeFile(LocalFile file) { } } else { result = false; - log.debug("RMDIR : the target file '" + file + "' does not exists! "); + log.debug("{}: file {} does not exist", SRM_COMMAND, file); } return result; } diff --git a/src/main/java/it/grid/storm/synchcall/command/discovery/PingCommand.java b/src/main/java/it/grid/storm/synchcall/command/discovery/PingCommand.java index f8799fcd..64dc286a 100644 --- a/src/main/java/it/grid/storm/synchcall/command/discovery/PingCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/discovery/PingCommand.java @@ -87,10 +87,9 @@ public OutputData execute(InputData data) { try { otherInfo = new TExtraInfo(entry.getKey().toString(), entry .getValue().toString()); - log.debug("srmPing: Found the value for key='" + key + "' = '" - + otherInfo + "'"); + log.debug("srmPing: {} -> {}", key, otherInfo); } catch (InvalidTExtraInfoAttributeException ex) { - log.error("Invalid KEY requested in Ping."); + log.error(ex.getMessage(),ex); otherInfo = new TExtraInfo(); } extraInfoArray.addTExtraInfo(otherInfo); @@ -101,12 +100,10 @@ public OutputData execute(InputData data) { outputData.setExtraInfoArray(extraInfoArray); - String infoLogs = "srmPing: " + "<" - + DataHelper.getRequestor(inputData).toString() + ">" + "[AuthID:'" - + inputData.getAuthorizationID() + "']" + "return values: [" - + extraInfoArray + "]"; - - log.info(infoLogs); + log.info("srmPing: <{}> [AuthID: {}] extraInfo: {}", + DataHelper.getRequestor(inputData), + inputData.getAuthorizationID(), + extraInfoArray); return outputData; } @@ -127,8 +124,6 @@ private String getKey(String authorizationID) { if (result.substring(0, 4).equalsIgnoreCase(KEY_ELEMENT_KEY)) { result = result.substring(4); } - log.debug("Retrieved KEY:'" + result + "' from AuthorizationID : '" - + authorizationID + "'"); return result; } @@ -141,34 +136,24 @@ private Properties loadProperties() { Properties properties = new Properties(); Configuration config = Configuration.getInstance(); - String configurationPATH = config.namespaceConfigPath(); // Default = - // "./etc/" - String pingPropertiesFileName = config.getPingValuesPropertiesFilename(); // Default - // = - // "ping-values.properties" + String configurationPATH = config.namespaceConfigPath(); + String pingPropertiesFileName = config.getPingValuesPropertiesFilename(); String propertiesFile = configurationPATH + File.separator + pingPropertiesFileName; - // Check if the file Exists if (new File(propertiesFile).exists()) { - // Read properties file. try { properties.load(new FileInputStream(propertiesFile)); - log.debug("srmPing: Loaded PING values from the properties file: '" - + pingPropertiesFileName + "'"); } catch (IOException e) { - log.error("Error while readind Ping Values in file : '" - + propertiesFile + "' EXCEPTION:" + e); + log.error("Error loading ping properties from file {}. {}", + propertiesFile, e.getMessage(), e); } } - // Add in properties the Mandatory Properties Values properties.put(Constants.BE_VERSION.getKey(), Constants.BE_VERSION.getValue()); properties.put(Constants.BE_OS_DISTRIBUTION.getKey(), Constants.BE_OS_DISTRIBUTION.getValue()); - log.debug("srmPing: Loaded NR " + properties.size() - + " PING key/value couple."); return properties; } @@ -195,7 +180,7 @@ private ArrayOfTExtraInfo manageSpecialKey(String key) { arrayResult.addTExtraInfo(new TExtraInfo(key, Constants.BE_OS_PLATFORM .getValue())); } catch (InvalidTExtraInfoAttributeException e) { - log.warn("Really strange!"); + log.error(e.getMessage(),e); } break; case BE_OS_KERNEL_RELEASE: @@ -203,7 +188,7 @@ private ArrayOfTExtraInfo manageSpecialKey(String key) { arrayResult.addTExtraInfo(new TExtraInfo(key, Constants.BE_OS_KERNEL_RELEASE.getValue())); } catch (InvalidTExtraInfoAttributeException e) { - log.warn("Really strange!"); + log.error(e.getMessage(),e); } break; case TEST_POST_NEW_TASK: @@ -224,7 +209,7 @@ private ArrayOfTExtraInfo manageSpecialKey(String key) { extraInfo = new TExtraInfo(SpecialKey.UNKNOWN.toString(), SpecialKey.UNKNOWN.getDescription() + ":'" + key + "'"); } catch (InvalidTExtraInfoAttributeException e) { - log.warn("Really strange!"); + log.error(e.getMessage(),e); } arrayResult.addTExtraInfo(extraInfo); break; @@ -243,16 +228,14 @@ private ArrayOfTExtraInfo allKeys(String param) { ArrayOfTExtraInfo arrayResult = new ArrayOfTExtraInfo(); Properties pingValues = loadProperties(); TExtraInfo otherInfo = new TExtraInfo(); - log.debug("srmPing: Found a request to retrieve ALL key values. (NR:" - + pingValues.size() + ")"); - // Insert all keys/values in to the results + for (Enumeration e = pingValues.propertyNames(); e.hasMoreElements();) { String key = (String) e.nextElement(); String value = pingValues.getProperty(key); try { otherInfo = new TExtraInfo(key, value); } catch (InvalidTExtraInfoAttributeException ex) { - log.error("Invalid KEY (key='" + key + "') requested in Ping."); + log.error(ex.getMessage(),ex); otherInfo = new TExtraInfo(); } arrayResult.addTExtraInfo(otherInfo); @@ -268,29 +251,23 @@ private ArrayOfTExtraInfo allKeys(String param) { private ArrayOfTExtraInfo test_post_new_task(String param) { ArrayOfTExtraInfo arrayResult = new ArrayOfTExtraInfo(); - // Recall Table Catalog String errorStr; - // Parsing of the inputString to extract the fields of RecallTask + TapeRecallData rtd; try { rtd = TapeRecallData.buildFromString(param); - log.debug("RTD=" + rtd.toString()); - // Store the new Recall Task if it is all OK. TapeRecallTO task = TapeRecallBuilder.buildFromPOST(rtd); try { new TapeRecallCatalog().insertNewTask(task); } catch (DataAccessException e) { - errorStr = "Unable to use RecallTable DB."; - log.error(errorStr); + log.error(e.getMessage(),e); return arrayResult; } URI newResource = URI.create("/" + task.getTaskId()); - log.debug("New task resource created: " + newResource); + log.debug("New resource created: {}", newResource); } catch (TapeRecallException e) { - errorStr = "Unable to use build the recall task from the provided string \'" - + param + "\'"; - log.error(errorStr); + log.error(e.getMessage(),e); return arrayResult; } From 64f9c2965883492305a5a32908f0be5a9619b675 Mon Sep 17 00:00:00 2001 From: dandreotti Date: Wed, 5 Feb 2014 16:02:22 +0000 Subject: [PATCH 22/45] Fix for https://issues.infn.it/jira/browse/STOR-524 --- .../java/it/grid/storm/space/CallableDU.java | 18 +-- .../java/it/grid/storm/space/ExecCommand.java | 64 +++++----- .../java/it/grid/storm/space/SpaceHelper.java | 51 ++++---- .../it/grid/storm/space/StorageSpaceData.java | 120 +++++++++--------- .../grid/storm/space/init/UsedSpaceFile.java | 55 +++----- 5 files changed, 139 insertions(+), 169 deletions(-) diff --git a/src/main/java/it/grid/storm/space/CallableDU.java b/src/main/java/it/grid/storm/space/CallableDU.java index 8a589313..d4a06024 100644 --- a/src/main/java/it/grid/storm/space/CallableDU.java +++ b/src/main/java/it/grid/storm/space/CallableDU.java @@ -115,19 +115,19 @@ public DUResult call() throws Exception { ExecCommand ec = new ExecCommand(commandList, this.timeout); cmdResult = ExitCode.getExitCode(ec.runCommand()); - LOG.debug("Command result: " + cmdResult); + LOG.debug("Command result: {}" , cmdResult); String output = ec.getOutput(); - LOG.debug(" Output: '" + output + "'"); + LOG.debug(" Output: '{}'" , output); if (output != null) { String[] outputArray = output.split("\\s"); for (int i = 0; i < outputArray.length; i++) { - LOG.trace("outputArray[" + i + "]=" + outputArray[i]); + LOG.trace("outputArray[{}]={}" , i , outputArray[i]); } try { size = Long.valueOf(outputArray[0]).longValue(); } catch (NumberFormatException nfe) { - LOG.error("Unable to retrieve the disk usage of '" + this.rootPath - + "'. " + nfe.getMessage()); + LOG.error("Unable to retrieve the disk usage of '{}'. {}" , this.rootPath + , nfe.getMessage(),nfe); } } @@ -136,8 +136,7 @@ public DUResult call() throws Exception { // Size is present? if (size > 0) { cmdResult = ExitCode.PARTIAL_SUCCESS; - LOG.info("IO Error occurred 'du: cannot access '" + this.rootPath - + "': No such file or ..' but SUCCESSFully managed."); + LOG.info("IO Error occurred 'du: cannot access '{}': No such file or ..' but SUCCESSFully managed." , this.rootPath); } } @@ -146,10 +145,7 @@ public DUResult call() throws Exception { // Size is yet undefined? if (size < 0) { cmdResult = ExitCode.IO_ERROR; - LOG - .warn("DU of " - + this.rootPath - + " successfully ended, but an IO_ERROR occurred retrieving command output."); + LOG.warn("DU of {} successfully ended, but an IO_ERROR occurred retrieving command output." , this.rootPath); } } diff --git a/src/main/java/it/grid/storm/space/ExecCommand.java b/src/main/java/it/grid/storm/space/ExecCommand.java index cea27f34..8414e573 100644 --- a/src/main/java/it/grid/storm/space/ExecCommand.java +++ b/src/main/java/it/grid/storm/space/ExecCommand.java @@ -59,7 +59,7 @@ public String call() { String eol = System.getProperty("line.separator"); while ((buff = br.readLine()) != null) { readBuffer.append(buff).append(eol); - LOG.debug(" - output-reader: " + buff); + LOG.debug(" - output-reader: {}" , buff); } output = readBuffer.toString(); @@ -69,8 +69,8 @@ public String call() { } catch (IOException e) { LOG - .warn("IO Exception occours when retrieve output form the execution on a native command. " - + e.getMessage()); + .warn("IO Exception occours when retrieve output from the execution on a native command. {}" + , e.getMessage()); } finally { IOUtils.closeQuietly(br); IOUtils.closeQuietly(isr); @@ -124,7 +124,7 @@ public int runCommand() { try { ProcessBuilder pb = new ProcessBuilder(this.command); Process process = pb.start(); - LOG.debug("Running command: '" + command + "'"); + LOG.debug("Running command: '{}'" , command); int corePoolSize = 3; int maxPoolSize = 3; @@ -160,31 +160,31 @@ public Integer call() throws Exception { LOG.debug("END WaitFor the result of Native Command."); } catch (IOException e) { - LOG.warn("IO Exception occours during the execution of a native command " - + command + ". " + e.getMessage()); + LOG.warn("IO Exception occours during the execution of a native command {}. {}" + , command , e.getMessage()); result = 1; } catch (InterruptedException e) { LOG - .warn("Interrupted Exception occours during the execution of a native command " - + command + ". " + e.getMessage()); + .warn("Interrupted Exception occours during the execution of a native command {}. {}" + , command , e.getMessage()); result = 2; } catch (TimeoutException e) { - LOG.warn("Native command " + command + " was in TimeOut."); + LOG.warn("Native command {} was in TimeOut." , command); result = 3; } catch (NullPointerException npe) { - LOG.error("The command to execute is NULL! " + npe); + LOG.error("The command to execute is NULL!" , npe); result = 4; } catch (SecurityException se) { - LOG.error("The program have Security limitation to execute the command '" - + command + "'." + se); + LOG.error("The program have Security limitation to execute the command '{}'" + , command , se); result = 5; } catch (IllegalArgumentException iae) { - LOG.error("The command to execute is EMPTY or ILLEGAL ('" + command - + "')! " + iae); + LOG.error("The command to execute is EMPTY or ILLEGAL {}" , command + , iae); result = 6; } catch (ExecutionException e) { - LOG.error("Execution Exception during the execution of '" + command - + "'! " + e); + LOG.error("Execution Exception during the execution of {}" , command + , e); result = 7; } return result; @@ -201,22 +201,22 @@ public String getOutput() { } else { outputResult = outputFuture.get(DEFAULT_TIMEOUT, TimeUnit.SECONDS); } - LOG.debug(" .. :" + outputResult); + LOG.debug(" .. :{}" , outputResult); } else { LOG.warn("Unable to get outputResult value. outputResult is NULL"); } } catch (ExecutionException e) { LOG - .warn("ExecutionException occours when retrieving OUTPUT stream returned by native command." - + e.getMessage()); + .warn("ExecutionException occours when retrieving OUTPUT stream returned by native command: {}" + , e.getMessage()); } catch (TimeoutException e) { LOG - .warn("Timeout occours when retrieving OUTPUT stream returned by native command." - + e.getMessage()); + .warn("Timeout occours when retrieving OUTPUT stream returned by native command: {}" + , e.getMessage()); } catch (InterruptedException e) { LOG - .warn("Interrupt occours when retrieving OUTPUT stream returned by native command." - + e.getMessage()); + .warn("Interrupt occours when retrieving OUTPUT stream returned by native command: {}" + , e.getMessage()); } return outputResult; } @@ -231,20 +231,20 @@ public String getError() { } else { errorResult = outputFuture.get(DEFAULT_TIMEOUT, TimeUnit.SECONDS); } - LOG.debug(" .. :" + errorResult); + LOG.debug(" .. :{}" , errorResult); } catch (ExecutionException e) { LOG - .warn("ExecutionException occours when retrieving error stream returned by native command." - + e.getMessage()); + .warn("ExecutionException occours when retrieving error stream returned by native command: {}" + , e.getMessage()); } catch (TimeoutException e) { LOG - .warn("Timeout occours when retrieving error stream returned by native command." - + e.getMessage()); + .warn("Timeout occours when retrieving error stream returned by native command: {}" + , e.getMessage()); } catch (InterruptedException e) { LOG - .warn("Interrupt occours when retrieving error stream returned by native command." - + e.getMessage()); + .warn("Interrupt occours when retrieving error stream returned by native command: {}" + , e.getMessage()); } return errorResult; } @@ -261,9 +261,9 @@ public void stopExecution() { executorService.awaitTermination(millisecToWait, TimeUnit.MILLISECONDS); LOG.debug("Shutted down!"); } catch (InterruptedException ie) { - LOG.debug("Interrupted excep. " + ie); + LOG.debug("Interrupted excep." , ie); } finally { - LOG.debug("Tasks killed: " + executorService.shutdownNow().size()); + LOG.debug("Tasks killed: {}" , executorService.shutdownNow().size()); } } } diff --git a/src/main/java/it/grid/storm/space/SpaceHelper.java b/src/main/java/it/grid/storm/space/SpaceHelper.java index be911741..a6df52d8 100644 --- a/src/main/java/it/grid/storm/space/SpaceHelper.java +++ b/src/main/java/it/grid/storm/space/SpaceHelper.java @@ -273,7 +273,7 @@ public boolean isSAFull(Logger log, StoRI stori) { spaceData = catalog.getStorageSpaceByAlias(SSDesc); if ((spaceData != null) && (spaceData.getAvailableSpaceSize().value() == 0)) { - log.debug("AvailableSize=" + spaceData.getAvailableSpaceSize().value()); + log.debug("AvailableSize={}" , spaceData.getAvailableSpaceSize().value()); return true; } else { return false; @@ -334,9 +334,8 @@ public boolean isSAInitialized(Logger log, StoRI stori) && !(spaceData.getUsedSpaceSize().value() < 0)) { response = true; } - log.debug("The storage area is initialized with token alias " - + spaceData.getSpaceTokenAlias() + " is " + (response ? "" : "not") - + "initialized"); + log.debug("The storage area is initialized with token alias {} is {} initialized" + , spaceData.getSpaceTokenAlias() , (response ? "" : "not")); return response; } @@ -355,7 +354,7 @@ public TSpaceToken getTokenFromStoRI(Logger log, StoRI stori) { try { token = fs.getSpaceToken(); } catch (NamespaceException e) { - log.warn("Unable to retrieve SpaceToken for stori:'" + stori + "'"); + log.warn("Unable to retrieve SpaceToken for stori:'{}'" , stori); } return token; @@ -427,14 +426,13 @@ public TSpaceToken createVOSA_Token(String spaceTokenAlias, if (tokenArray == null || tokenArray.size() == 0) { // the VOSpaceArea does not exist yet - SpaceHelper.log.debug("VoSpaceArea " + spaceTokenAlias - + " still does not exists. Start creation process."); + SpaceHelper.log.debug("VoSpaceArea {} still does not exists. Start creation process." , spaceTokenAlias); PFN sfname = null; try { sfname = PFN.make(spaceFileName); } catch (InvalidPFNAttributeException e1) { - log.error("Error building PFN with " + spaceFileName + " : " + e1); + log.error("Error building PFN with {} : " , spaceFileName , e1); } StorageSpaceData ssd = null; @@ -450,18 +448,18 @@ public TSpaceToken createVOSA_Token(String spaceTokenAlias, } catch (InvalidTSizeAttributesException e) { // never thrown - log.error("Unexpected InvalidTSizeAttributesException: " - + e.getMessage()); + log.error("Unexpected InvalidTSizeAttributesException: {}" + , e.getMessage(),e); } spaceToken = ssd.getSpaceToken(); } catch (InvalidSpaceDataAttributesException e) { - log.error("Error building StorageSpaceData: " + e); + log.error("Error building StorageSpaceData: " , e); } try { spaceCatalog.addStorageSpace(ssd); } catch (DataAccessException e) { - log.error("Error storing StorageSpaceData on the DB: " + e); + log.error("Error storing StorageSpaceData on the DB: " , e); } // Track into global set to remove obsolete SA_token ReservedSpaceCatalog.addSpaceToken(spaceToken); @@ -483,11 +481,11 @@ public TSpaceToken createVOSA_Token(String spaceTokenAlias, catalog_ssd = spaceCatalog.getStorageSpace(spaceToken); } catch (TransferObjectDecodingException e) { log - .error("Unable to build StorageSpaceData from StorageSpaceTO. TransferObjectDecodingException: " - + e.getMessage()); + .error("Unable to build StorageSpaceData from StorageSpaceTO. TransferObjectDecodingException: {}" + , e.getMessage(),e); } catch (DataAccessException e) { - log.error("Unable to build get StorageSpaceTO. DataAccessException: " - + e.getMessage()); + log.error("Unable to build get StorageSpaceTO. DataAccessException: {}" + , e.getMessage(),e); } if (catalog_ssd != null) { @@ -506,16 +504,15 @@ public TSpaceToken createVOSA_Token(String spaceTokenAlias, if (equal) { // Do nothing if equals, everything are already present into // the DB - SpaceHelper.log.debug("VOSpaceArea for space token description " - + spaceTokenAlias + " is already up to date."); + SpaceHelper.log.debug("VOSpaceArea for space token description {} is already up to date." + , spaceTokenAlias); ReservedSpaceCatalog.addSpaceToken(spaceToken); } else { // If the new data has been modified, update the data into the // catalog - SpaceHelper.log.debug("VOSpaceArea for space token description " - + spaceTokenAlias - + " is different in some parameters. Updating the catalog."); + SpaceHelper.log.debug("VOSpaceArea for space token description {} is different in some parameters. Updating the catalog." + , spaceTokenAlias); try { catalog_ssd.setOwner(storageAreaOwner); catalog_ssd.setTotalSpaceSize(totalOnLineSize); @@ -550,8 +547,8 @@ public TSpaceToken createVOSA_Token(String spaceTokenAlias, // is not allowed if (tokenArray.size() > 1) { SpaceHelper.log - .error("Error: multiple Space Token found for the same space Alias: " - + spaceTokenAlias + ". Only one has been evaluated!"); + .error("Error: multiple Space Token found for the same space Alias: {}. Only one has been evaluated!" + , spaceTokenAlias); } } @@ -577,7 +574,7 @@ public void purgeOldVOSA_token(Logger log) { Iterator iter = ReservedSpaceCatalog.getTokenSet().iterator(); while (iter.hasNext()) { - log.debug("VO SA token REGISTRED:" + iter.next().getValue()); + log.debug("VO SA token REGISTRED: {}" , iter.next().getValue()); } GridUserInterface stormServiceUser = GridUserManager.makeSAGridUser(); @@ -585,8 +582,7 @@ public void purgeOldVOSA_token(Logger log) { // Remove obsolete space ArrayOfTSpaceToken token_a = spacec.getSpaceTokens(stormServiceUser, null); for (int i = 0; i < token_a.size(); i++) { - log.debug("VO SA token IN CATALOG:" - + token_a.getTSpaceToken(i).getValue()); + log.debug("VO SA token IN CATALOG: {}" , token_a.getTSpaceToken(i).getValue()); } if ((token_a != null) && (token_a.size() > 0)) { @@ -596,8 +592,7 @@ public void purgeOldVOSA_token(Logger log) { token_a.getTSpaceToken(i))) { // This VOSA_token is no more used, removing it from persistence TSpaceToken tokenToRemove = token_a.getTSpaceToken(i); - log.debug("VO SA token " + tokenToRemove - + " is no more used, removing it from persistence."); + log.debug("VO SA token {} is no more used, removing it from persistence." , tokenToRemove); spacec.release(stormServiceUser, tokenToRemove); } } diff --git a/src/main/java/it/grid/storm/space/StorageSpaceData.java b/src/main/java/it/grid/storm/space/StorageSpaceData.java index fb836496..274d7e36 100644 --- a/src/main/java/it/grid/storm/space/StorageSpaceData.java +++ b/src/main/java/it/grid/storm/space/StorageSpaceData.java @@ -103,9 +103,9 @@ public StorageSpaceData(GridUserInterface guOwner, TSpaceType spaceType, boolean ok = (spaceType != null && ((guOwner != null) || (spaceType == TSpaceType.VOSPACE)) && spaceTokenAlias != null); - log.debug("Storage Space Data - User identity : " + guOwner); - log.debug("Storage Space Data - Space Type : " + spaceType); - log.debug("Storage Space Data - Space Token Alias : " + spaceTokenAlias); + log.debug("Storage Space Data - User identity : {}" , guOwner); + log.debug("Storage Space Data - Space Type : {}" , spaceType); + log.debug("Storage Space Data - Space Token Alias : {}" , spaceTokenAlias); if (!ok) { throw new InvalidSpaceDataAttributesException(guOwner); @@ -154,22 +154,22 @@ public StorageSpaceData(StorageSpaceTO ssTO) throws IllegalArgumentException { ssTO.getVoName()); } catch (IllegalArgumentException e) { log - .error("Unexpected error on voms grid user creation. Contact StoRM Support : IllegalArgumentException " - + e.getMessage()); + .error("Unexpected error on voms grid user creation. Contact StoRM Support : IllegalArgumentException {}" + , e.getMessage(),e); throw e; } } else { this.owner = GridUserManager.makeGridUser(ssTO.getOwnerName()); } if (this.owner != null) { - log.trace("StorageSpaceData - Owner: " + this.owner.toString()); + log.trace("StorageSpaceData - Owner: {}" , this.owner.toString()); } else { log.trace("StorageSpaceData - Owner: NULL"); } // TYPE of Storage Space this.spaceType = TSpaceType.getTSpaceType(ssTO.getSpaceType()); if (this.spaceType != null) { - log.trace("StorageSpaceData - spaceType: " + this.spaceType); + log.trace("StorageSpaceData - spaceType: {}" , this.spaceType); } else { log.trace("StorageSpaceData - spaceType: NULL"); } @@ -177,7 +177,7 @@ public StorageSpaceData(StorageSpaceTO ssTO) throws IllegalArgumentException { this.spaceTokenAlias = ssTO.getAlias(); if (this.spaceTokenAlias != null) { log - .trace("StorageSpaceData - spaceTokenAlias: " + this.spaceTokenAlias); + .trace("StorageSpaceData - spaceTokenAlias: {}" , this.spaceTokenAlias); } else { log.trace("StorageSpaceData - spaceTokenAlias: NULL"); } @@ -188,7 +188,7 @@ public StorageSpaceData(StorageSpaceTO ssTO) throws IllegalArgumentException { log.error("Error while constructing TSpaceToken", ex); } if (this.spaceToken != null) { - log.trace("StorageSpaceData - spaceToken: " + this.spaceToken); + log.trace("StorageSpaceData - spaceToken: {}" , this.spaceToken); } // Storage Space File Name @@ -198,7 +198,7 @@ public StorageSpaceData(StorageSpaceTO ssTO) throws IllegalArgumentException { log.error("Error while constructing Storage Space File Name", e); } if (this.spaceFileName != null) { - log.trace("StorageSpaceData - spaceFileName: " + this.spaceFileName); + log.trace("StorageSpaceData - spaceFileName: {}" , this.spaceFileName); } // Life Time for Storage Space. @@ -209,83 +209,83 @@ public StorageSpaceData(StorageSpaceTO ssTO) throws IllegalArgumentException { log.error("Error while constructing Space Life Time", e); } if (this.spaceLifetime != null) { - log.trace("StorageSpaceData - spaceLifetime: " + this.spaceLifetime); + log.trace("StorageSpaceData - spaceLifetime: {}" , this.spaceLifetime); } // Storage System Info. // this.storageInfo = new TStorageSystemInfo("", true); this.storageInfo = TStorageSystemInfo.make(ssTO.getStorageInfo()); if (this.storageInfo.getValue() != null) { - log.trace("StorageSpaceData - storageInfo: " + this.storageInfo); + log.trace("StorageSpaceData - storageInfo: {}" , this.storageInfo); } else { log.trace("StorageSpaceData - storageInfo: NULL"); } // Creation time of Storage Space this.creationDate = ssTO.getCreated(); if (this.creationDate != null) { - log.trace("StorageSpaceData - date: " + this.creationDate); + log.trace("StorageSpaceData - date: {}" , this.creationDate); } else { log.trace("StorageSpaceData - date: NULL"); } // Space TOTAL Desired for Storage Space - log.debug("StorageSpaceData - TOTAL (Desired) size:" - + ssTO.getTotalSize()); + log.debug("StorageSpaceData - TOTAL (Desired) size: {}" + , ssTO.getTotalSize()); this.totalSpaceSize = TSizeInBytes.makeEmpty(); if (ssTO.getTotalSize() >= 0) { try { this.totalSpaceSize = TSizeInBytes.make(ssTO.getTotalSize(), SizeUnit.BYTES); - log.trace("StorageSpaceData - TotalSize (desired): " - + this.totalSpaceSize); + log.trace("StorageSpaceData - TotalSize (desired): {}" + , this.totalSpaceSize); } catch (InvalidTSizeAttributesException ex1) { log.error("Error while constructing TotalSize (desired)", ex1); } } else { - log.trace("StorageSpaceData - TotalSize (desired): EMPTY " - + this.totalSpaceSize); + log.trace("StorageSpaceData - TotalSize (desired): EMPTY {}" + , this.totalSpaceSize); } // Space TOTAL Guaranteed for Storage Space - log.debug("StorageSpaceData - TOTAL (Guaranteed) size:" - + ssTO.getGuaranteedSize()); + log.debug("StorageSpaceData - TOTAL (Guaranteed) size: {}" + , ssTO.getGuaranteedSize()); this.setTotalGuaranteedSize(TSizeInBytes.makeEmpty()); if (ssTO.getGuaranteedSize() >= 0) { try { this.totalGuaranteedSize = TSizeInBytes.make( ssTO.getGuaranteedSize(), SizeUnit.BYTES); - log.trace("StorageSpaceData - TotalSize (guaranteed): " - + this.totalGuaranteedSize); + log.trace("StorageSpaceData - TotalSize (guaranteed): {}" + , this.totalGuaranteedSize); } catch (InvalidTSizeAttributesException ex2) { log.error("Error while constructing SpaceGuaranteed", ex2); } } else { // log.debug("StorageSpaceData - TotalSize (guaranteed): EMPTY " + // this.reservedSpaceSize); - log.trace("StorageSpaceData - TotalSize (guaranteed): EMPTY " - + this.totalGuaranteedSize); + log.trace("StorageSpaceData - TotalSize (guaranteed): EMPTY {}" + , this.totalGuaranteedSize); } // AVAILABLE space - log.trace("StorageSpaceData - AVAILABLE size:" + ssTO.getAvailableSize()); + log.trace("StorageSpaceData - AVAILABLE size: {}" , ssTO.getAvailableSize()); // this.availableSpaceSize = TSizeInBytes.makeEmpty(); this.forceAvailableSpaceSize(TSizeInBytes.makeEmpty()); if (ssTO.getAvailableSize() >= 0) { try { this.forceAvailableSpaceSize(TSizeInBytes.make( ssTO.getAvailableSize(), SizeUnit.BYTES)); - log.trace("StorageSpaceData - AVAILABLE size : " - + this.getAvailableSpaceSize()); + log.trace("StorageSpaceData - AVAILABLE size : {}" + , this.getAvailableSpaceSize()); } catch (InvalidTSizeAttributesException ex3) { log.error("Error while constructing AvailableSpaceSize", ex3); } } else { - log.trace("StorageSpaceData - AVAILABLE size : EMPTY " - + this.getAvailableSpaceSize()); + log.trace("StorageSpaceData - AVAILABLE size : EMPTY {}" + , this.getAvailableSpaceSize()); } // FREE space - log.trace("StorageSpaceData - FREE (= available + unavailable) size :" - + ssTO.getFreeSize()); + log.trace("StorageSpaceData - FREE (= available + unavailable) size : {}" + , ssTO.getFreeSize()); this.forceFreeSpaceSize(TSizeInBytes.makeEmpty()); if (ssTO.getFreeSize() >= 0) { try { @@ -293,88 +293,88 @@ public StorageSpaceData(StorageSpaceTO ssTO) throws IllegalArgumentException { this.forceFreeSpaceSize(TSizeInBytes.make(ssTO.getFreeSize(), SizeUnit.BYTES)); log - .trace("StorageSpaceData - FREE (= available + unavailable) size : " - + this.getFreeSpaceSize()); + .trace("StorageSpaceData - FREE (= available + unavailable) size : {}" + , this.getFreeSpaceSize()); } catch (InvalidTSizeAttributesException ex3) { log.error("Error while constructing FreeSpaceSize", ex3); } } else { log - .trace("StorageSpaceData - FREE (= available + unavailable) size : EMPTY " - + this.getFreeSpaceSize()); + .trace("StorageSpaceData - FREE (= available + unavailable) size : EMPTY {}" + , this.getFreeSpaceSize()); } // USED space - log.debug("StorageSpaceData - USED size:" + ssTO.getUsedSize()); + log.debug("StorageSpaceData - USED size: {}" , ssTO.getUsedSize()); this.usedSpaceSize = TSizeInBytes.makeEmpty(); if (ssTO.getUsedSize() >= 0) { try { this.usedSpaceSize = TSizeInBytes.make(ssTO.getUsedSize(), SizeUnit.BYTES); - log.trace("StorageSpaceData - USED size: " + this.usedSpaceSize); + log.trace("StorageSpaceData - USED size: {}" , this.usedSpaceSize); } catch (InvalidTSizeAttributesException ex3) { log.error("Error while constructing UsedSpaceSize", ex3); } } else { - log.trace("StorageSpaceData - USED size: EMPTY " + this.usedSpaceSize); + log.trace("StorageSpaceData - USED size: EMPTY {}" , this.usedSpaceSize); } // BUSY space log - .debug("StorageSpaceData - BUSY (= used + reserved + unavailable) size:" - + ssTO.getBusySize()); + .debug("StorageSpaceData - BUSY (= used + reserved + unavailable) size: {}" + , ssTO.getBusySize()); this.forceBusySpaceSize(TSizeInBytes.makeEmpty()); if (ssTO.getBusySize() >= 0) { try { this.forceBusySpaceSize(TSizeInBytes.make(ssTO.getBusySize(), SizeUnit.BYTES)); log - .trace("StorageSpaceData - BUSY (= used + reserved + unavailable) size:" - + this.getBusySpaceSize()); + .trace("StorageSpaceData - BUSY (= used + reserved + unavailable) size: {}" + , this.getBusySpaceSize()); } catch (InvalidTSizeAttributesException ex3) { log.error("Error while constructing BusySpaceSize", ex3); } } else { log - .trace("StorageSpaceData - BUSY (= used + reserved + unavailable) size: EMPTY " - + this.getBusySpaceSize()); + .trace("StorageSpaceData - BUSY (= used + reserved + unavailable) size: EMPTY {}" + , this.getBusySpaceSize()); } // UNAVAILABLE space - log.trace("StorageSpaceData - UNAVAILABLE size:" - + ssTO.getUnavailableSize()); + log.trace("StorageSpaceData - UNAVAILABLE size: {}" + , ssTO.getUnavailableSize()); this.unavailableSpaceSize = TSizeInBytes.makeEmpty(); if (ssTO.getUnavailableSize() >= 0) { try { this.unavailableSpaceSize = TSizeInBytes.make( ssTO.getUnavailableSize(), SizeUnit.BYTES); - log.trace("StorageSpaceData - UNAVAILABLE size: " - + this.unavailableSpaceSize); + log.trace("StorageSpaceData - UNAVAILABLE size: {}" + , this.unavailableSpaceSize); } catch (InvalidTSizeAttributesException ex3) { log.error("Error while constructing UnavailableSpaceSize", ex3); } } else { - log.trace("StorageSpaceData - UNAVAILABLE size: EMPTY " - + this.unavailableSpaceSize); + log.trace("StorageSpaceData - UNAVAILABLE size: EMPTY {}" + , this.unavailableSpaceSize); } // Space Reserved for Storage Space - log.trace("StorageSpaceData - TOTAL (Reserved) size:" - + ssTO.getReservedSize()); + log.trace("StorageSpaceData - TOTAL (Reserved) size: {}" + , ssTO.getReservedSize()); this.reservedSpaceSize = TSizeInBytes.makeEmpty(); if (ssTO.getReservedSize() >= 0) { try { this.reservedSpaceSize = TSizeInBytes.make(ssTO.getReservedSize(), SizeUnit.BYTES); - log.trace("StorageSpaceData - TotalSize (reserved): " - + this.reservedSpaceSize); + log.trace("StorageSpaceData - TotalSize (reserved): {}" + , this.reservedSpaceSize); } catch (InvalidTSizeAttributesException ex2) { log.error("Error while constructing SpaceReserved", ex2); } } else { - log.trace("StorageSpaceData - Reserved : EMPTY " - + this.reservedSpaceSize); + log.trace("StorageSpaceData - Reserved : EMPTY {}" + , this.reservedSpaceSize); } } @@ -736,9 +736,9 @@ public final TSizeInBytes getAvailableSpaceSize() { this.totalSpaceSize.value() - this.getBusySpaceSize().value(), SizeUnit.BYTES); } catch (InvalidTSizeAttributesException e) { - log.warn("Unable to produce the TSizeInBytes object from \'" - + (this.totalSpaceSize.value() - this.getBusySpaceSize().value()) - + "\' and \'" + SizeUnit.BYTES + "\'"); + log.warn("Unable to produce the TSizeInBytes object from '{}' and '{}'" + , (this.totalSpaceSize.value() - this.getBusySpaceSize().value()) + , SizeUnit.BYTES); this.availableSpaceSize = TSizeInBytes.makeEmpty(); } } diff --git a/src/main/java/it/grid/storm/space/init/UsedSpaceFile.java b/src/main/java/it/grid/storm/space/init/UsedSpaceFile.java index 382638d8..54be1d0f 100644 --- a/src/main/java/it/grid/storm/space/init/UsedSpaceFile.java +++ b/src/main/java/it/grid/storm/space/init/UsedSpaceFile.java @@ -104,8 +104,8 @@ private Ini retrieveUsedSpaceIniFile() { try { iniFile = new IniReader().getIniFile(INI_FILENAME); } catch (IllegalArgumentException e) { - log.error("Unable to get the Ini file handle for file " + INI_FILENAME - + " in the default ini folder " + IniReader.DEFAULT_CONF_PATH); + log.error("Unable to get the Ini file handle for file {} in the default ini folder {}" , INI_FILENAME + , IniReader.DEFAULT_CONF_PATH , e); } return iniFile; } @@ -172,8 +172,7 @@ public boolean hasUpdateTime() { public List getDefinedSizes() { LinkedList saUsedSizeList = new LinkedList(); - log.debug("Initializing '" + saNames.size() - + "' not initialized storage areas"); + log.debug("Initializing '{}' not initialized storage areas" , saNames.size()); /* Log initialized storage areas */ if (iniFile != null) { @@ -187,45 +186,31 @@ public List getDefinedSizes() { switch (Key.getKey(optionKey)) { case USED_SIZE: if (section.length(optionKey) > 1) { - log.warn("Unable to get " + Key.USED_SIZE.getName() - + " value from section [" + saName - + "] . Check for repeated declarations of this " - + "Section or repeated declarations of " - + Key.USED_SIZE.getName() + " in this section"); + log.warn("Unable to get {} value from section [{}] . Check for repeated declarations of this Section or repeated declarations of {} in this section" , Key.USED_SIZE.getName() + , saName , Key.USED_SIZE.getName()); } else { try { usedSpace = Long.parseLong(section.get(optionKey)); } catch (NumberFormatException e) { log - .warn(Key.USED_SIZE.getName() - + " from section [" - + saName - + "] doesn't contain a valid Long value. NumberFormatException: " - + e.getMessage()); + .warn("{} from section [{}] doesn't contain a valid Long value. NumberFormatException: " , Key.USED_SIZE.getName() , saName , e.getMessage()); } } break; case CHECK_TIME: if (section.length(optionKey) > 1) { - log.warn("Unable to get " + Key.CHECK_TIME.getName() - + " value from section [" + saName - + "] . Check for repeated declarations of this " - + "Section or repeated declarations of " - + Key.CHECK_TIME.getName() + " in this section"); + log.warn("Unable to get {} value from section [{}]. Check for repeated declarations of this Section or repeated declarations of {} in this section" , Key.CHECK_TIME.getName() , saName + , Key.CHECK_TIME.getName()); } else { try { updateTime = parseDate(section.get(optionKey)); } catch (ParseException e) { - log.warn(Key.CHECK_TIME.getName() + " from section [" - + saName - + "] doesn't contain a valid Date value. ParseException: " - + e.getMessage()); + log.warn("{} from section [{}] doesn't contain a valid Date value. ParseException: {}" , Key.CHECK_TIME.getName() , saName , e.getMessage()); } } break; default: - log.warn("Key: '" + optionKey + "' from section [" + saName - + "] is not recognized as a valid key."); + log.warn("Key: '{}' from section [{}] is not recognized as a valid key." , optionKey , saName); break; } } @@ -233,8 +218,7 @@ public List getDefinedSizes() { saUsedSizeList.add(new SaUsedSize(saName, usedSpace, updateTime)); } } else { - log.warn("Unable to find section named " + saName - + " in the ini file"); + log.warn("Unable to find section named {} in the ini file" , saName); } } } else { @@ -258,20 +242,18 @@ private ArrayList getSAdefined(Ini iniFile) } ArrayList storageAreas = new ArrayList(); - log.debug("Number of ini file sections: " + iniFile.size()); + log.debug("Number of ini file sections: {}" , iniFile.size()); for (String sectionName : iniFile.keySet()) { - log.debug("SA candidate from ini file is [" + sectionName + "]"); + log.debug("SA candidate from ini file is [{}]" , sectionName); // Check the existence in namespace.xml if (saNames.contains(sectionName)) { storageAreas.add(sectionName); } else { - log.info("SA defined in the ini file is [" + sectionName - + "] is not going to be updated"); + log.info("SA defined in the ini file is [{}] is not going to be updated" , sectionName); } } if (storageAreas.size() > 0) { - log.info("Found '" + storageAreas.size() - + "' valid storage area defined in used-space.ini"); + log.info("Found '{}' valid storage area defined in used-space.ini" , storageAreas.size()); } else { log .info("Found no defined Storage Area to initialize using used-size.ini file."); @@ -295,16 +277,13 @@ private Date parseDate(String dateStr) throws ParseException { dateUpdate = formatRFC2822.parse(dateStr); return dateUpdate; } catch (ParseException e) { - log.debug("Unable to parse date " + dateStr - + " using RFC2822 formatter.ParseException: " + e.getMessage() - + " Attempting with default formatter"); + log.debug("Unable to parse date {} using RFC2822 formatter.ParseException: {} Attempting with default formatter" , dateStr , e.getMessage(),e); moreSignificantException = e; } try { dateUpdate = formatDefault.parse(dateStr); } catch (ParseException e) { - log.warn("Unable to parse the date '" + dateStr - + "' with default formatter. ParseException: " + e.getMessage()); + log.warn("Unable to parse the date {} with default formatter. ParseException: {}" , dateStr , e.getMessage()); throw moreSignificantException; } return dateUpdate; From f7a74f798292f96dd9fd6b6508603c36b6549640 Mon Sep 17 00:00:00 2001 From: enricovianello Date: Wed, 5 Feb 2014 17:46:20 +0100 Subject: [PATCH 23/45] Fix log calls in storm backend - package it.grid.storm.authz --- .../it/grid/storm/authz/AuthzDirector.java | 35 ++--- .../it/grid/storm/authz/AuthzException.java | 5 + .../it/grid/storm/authz/path/PathAuthz.java | 32 ++-- .../authz/path/conf/PathAuthzDBReader.java | 102 ++++++------ .../grid/storm/authz/path/model/PathACE.java | 29 +--- .../path/model/PathAuthzAlgBestMatch.java | 66 ++++---- .../storm/authz/path/model/PathOperation.java | 15 +- .../storm/authz/path/model/PathPrincipal.java | 13 +- .../authz/path/model/SRMFileRequest.java | 35 ++++- .../resource/AuthorizationResource.java | 148 ++++++++---------- .../remote/resource/PermissionEvaluator.java | 119 +++++++------- .../remote/resource/RequestParameters.java | 48 +++--- .../it/grid/storm/authz/sa/SpaceAuthz.java | 16 +- .../it/grid/storm/authz/sa/SpaceDBAuthz.java | 4 +- .../authz/sa/conf/FileAuthzDBListener.java | 13 +- .../authz/sa/conf/FileAuthzDBParser.java | 6 +- .../authz/sa/conf/FileAuthzDBReader.java | 8 +- .../sa/conf/FileAuthzDBReloadingStrategy.java | 8 +- .../authz/sa/conf/FileAuthzDBWatcher.java | 28 ++-- .../authz/sa/conf/SpaceACETextParser.java | 33 +--- .../it/grid/storm/authz/sa/model/AceType.java | 8 +- .../authz/sa/model/DNEveryonePattern.java | 5 +- .../grid/storm/authz/sa/model/DNPattern.java | 9 +- .../storm/authz/sa/model/EGEEFQANPattern.java | 16 +- .../storm/authz/sa/model/FQANPattern.java | 4 - .../storm/authz/sa/model/FileAuthzDB.java | 6 +- .../authz/sa/test/EGEEFQANPatternTest.java | 53 ------- .../storm/authz/sa/test/MockSpaceAuthz.java | 4 +- .../authz/util/ConfigurationWatcher.java | 6 - .../util/PathAuthzConfigurationWatcher.java | 7 +- 30 files changed, 369 insertions(+), 512 deletions(-) delete mode 100644 src/main/java/it/grid/storm/authz/sa/test/EGEEFQANPatternTest.java diff --git a/src/main/java/it/grid/storm/authz/AuthzDirector.java b/src/main/java/it/grid/storm/authz/AuthzDirector.java index 07ebe482..9b8118e9 100644 --- a/src/main/java/it/grid/storm/authz/AuthzDirector.java +++ b/src/main/java/it/grid/storm/authz/AuthzDirector.java @@ -40,9 +40,7 @@ public class AuthzDirector { private static final Logger log = LoggerFactory .getLogger(AuthzDirector.class); - private static int refreshInSeconds = 5; // Default value; private static String configurationPATH; - private static String stormPropertiesFileName; // Map between 'SpaceToken' and the related 'SpaceAuthz' private static Map spaceAuthzs = null; @@ -69,24 +67,23 @@ private static Map buildSpaceAuthzsMAP() { if (authzTp.equals(SAAuthzType.AUTHZDB)) { // The Space Authz is based on Authz DB authzName = vfs.getStorageAreaAuthzDB(); - log.debug("Loading AuthzDB '" + authzName + "'"); + log.debug("Loading AuthzDB '{}'", authzName); if (existsAuthzDBFile(authzName)) { // Digest the Space AuthzDB File TSpaceToken spaceToken = vfs.getSpaceToken(); SpaceAuthzInterface spaceAuthz = new SpaceDBAuthz(authzName); spaceAuthzMap.put(spaceToken, spaceAuthz); } else { - log.error("File AuthzDB '" + authzName + "' related to '" + vfsName - + "' does not exists."); + log.error("File AuthzDB '{}' related to '{}' does not exists.", + authzName, vfsName); } } else { authzName = vfs.getStorageAreaAuthzFixed(); } - log.debug("VFS ['" + vfsName + "'] = " + authzTp + " : " + authzName); + log.debug("VFS ['{}'] = {} : {}", vfsName, authzTp, authzName); } } catch (NamespaceException e) { - log.warn("Unable to initialize AUTHZ DB!" + e.getMessage()); - log.warn(".. (Workaround): AuthzDirector INITIALIZED evenly.."); + log.error("Unable to initialize AUTHZ DB! Error: {}", e.getMessage(), e); } return spaceAuthzMap; @@ -103,8 +100,8 @@ private static boolean existsAuthzDBFile(String dbFileName) { String fileName = configurationPATH + File.separator + dbFileName; boolean exists = (new File(fileName)).exists(); - if (!(exists)) { - log.warn("The AuthzDB File '" + dbFileName + "' does not exists"); + if (!exists) { + log.warn("The AuthzDB File '{}' does not exists", dbFileName); } return exists; } @@ -113,14 +110,6 @@ private static boolean existsAuthzDBFile(String dbFileName) { // PUBLIC METHODS // **************************************** - /** - * Retrieve the Logger used in all the package AUTHZ - */ - public static Logger getLogger() { - - return log; - } - /****************************** * SPACE AUTHORIZATION ENGINE ******************************/ @@ -142,11 +131,11 @@ public static SpaceAuthzInterface getSpaceAuthz(TSpaceToken token) { // Retrieve the SpaceAuthz related to the Space Token if ((spaceAuthzs != null) && (spaceAuthzs.containsKey(token))) { spaceAuthz = spaceAuthzs.get(token); - log.debug("Space Authz related to S.Token ='" + token + "' is '" - + spaceAuthz.getSpaceAuthzID() + "'"); + log.debug("Space Authz related to S.Token ='{}' is '{}'", token, + spaceAuthz.getSpaceAuthzID()); } else { - log.debug("Space Authz related to S.Token ='" + token - + "' does not exists. Use the MOCK one."); + log.debug("Space Authz related to S.Token ='{}' does not exists. " + + "Use the MOCK one.", token); } return spaceAuthz; } @@ -167,7 +156,7 @@ public static void initializePathAuthz(String pathAuthzDBFileName) try { authzDBReader = new PathAuthzDBReader(pathAuthzDBFileName); } catch (Exception e) { - log.error("Unable to build a PathAuthzDBReader : " + e); + log.error("Unable to build a PathAuthzDBReader: {}", e.getMessage(), e); throw new DirectorException("Unable to build a PathAuthzDBReader"); } AuthzDirector.pathAuthz = new PathAuthz(authzDBReader.getPathAuthzDB()); diff --git a/src/main/java/it/grid/storm/authz/AuthzException.java b/src/main/java/it/grid/storm/authz/AuthzException.java index 6ed72047..f55f1708 100644 --- a/src/main/java/it/grid/storm/authz/AuthzException.java +++ b/src/main/java/it/grid/storm/authz/AuthzException.java @@ -26,6 +26,11 @@ */ public class AuthzException extends Exception { + /** + * + */ + private static final long serialVersionUID = 1L; + public AuthzException() { super(); diff --git a/src/main/java/it/grid/storm/authz/path/PathAuthz.java b/src/main/java/it/grid/storm/authz/path/PathAuthz.java index c1fadce2..0b7ef5da 100644 --- a/src/main/java/it/grid/storm/authz/path/PathAuthz.java +++ b/src/main/java/it/grid/storm/authz/path/PathAuthz.java @@ -21,7 +21,6 @@ package it.grid.storm.authz.path; import it.grid.storm.authz.AuthzDecision; -import it.grid.storm.authz.AuthzDirector; import it.grid.storm.authz.PathAuthzInterface; import it.grid.storm.authz.path.conf.PathAuthzDB; import it.grid.storm.authz.path.model.PathOperation; @@ -33,13 +32,14 @@ import it.grid.storm.namespace.util.userinfo.LocalGroups; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author zappi */ public class PathAuthz implements PathAuthzInterface { - private final Logger log = AuthzDirector.getLogger(); + private static final Logger log = LoggerFactory.getLogger(PathAuthz.class); private final PathAuthzDB pathAuthzDB; public PathAuthz(PathAuthzDB pathAuthzDB) { @@ -61,13 +61,11 @@ public AuthzDecision authorize(GridUserInterface guser, groupName = LocalGroups.getInstance().getGroupName( guser.getLocalUser().getPrimaryGid()); } catch (CannotMapUserException e) { - log.error("Unable to retrieve the local group for '" + guser + "'"); + log.error("Unable to retrieve the local group for '{}'", guser, e); return AuthzDecision.INDETERMINATE; } - log - .debug(" Compute authorization for groupName:'" + groupName - + "', filename:'" + fileStFN + "', pathOperation:'" + pathOperation - + "'"); + log.debug(" Compute authorization for groupName:'{}', " + + "filename:'{}', pathOperation:'{}'", groupName, fileStFN, pathOperation); return pathAuthzDB.evaluate(groupName, fileStFN, pathOperation); } @@ -79,13 +77,11 @@ public AuthzDecision authorize(GridUserInterface guser, groupName = LocalGroups.getInstance().getGroupName( guser.getLocalUser().getPrimaryGid()); } catch (CannotMapUserException e) { - log.error("Unable to retrieve the local group for '" + guser + "'"); + log.error("Unable to retrieve the local group for '{}'", guser, e); return AuthzDecision.INDETERMINATE; } - log - .debug(" Compute authorization for groupName:'" + groupName - + "', filename:'" + fileStFN + "', pathOperation:'" + pathOperation - + "'"); + log.debug(" Compute authorization for groupName:'{}', " + + "filename:'{}', pathOperation:'{}'", groupName, fileStFN, pathOperation); return pathAuthzDB.evaluate(groupName, fileStFN, pathOperation); } @@ -93,9 +89,8 @@ public AuthzDecision authorize(GridUserInterface guser, public AuthzDecision authorizeAnonymous(PathOperation pathOperation, StFN fileStFN) { - log - .debug(" Compute authorization for anonymous user on filename:'" - + fileStFN + "', pathOperation:'" + pathOperation + "'"); + log.debug(" Compute authorization for anonymous user on " + + "filename:'{}', pathOperation:'{}'", fileStFN, pathOperation); return pathAuthzDB.evaluateAnonymous(fileStFN, pathOperation); } @@ -103,9 +98,8 @@ public AuthzDecision authorizeAnonymous(PathOperation pathOperation, public AuthzDecision authorizeAnonymous(SRMFileRequest srmPathOp, StFN fileStFN) { - log - .debug(" Compute authorization for anonymous user on filename:'" - + fileStFN + "', SRMFileRequest:'" + srmPathOp + "'"); + log.debug(" Compute authorization for anonymous user on " + + "filename:'{}', SRMFileRequest:'{}'", fileStFN, srmPathOp); return pathAuthzDB.evaluateAnonymous(fileStFN, srmPathOp); } @@ -201,7 +195,7 @@ public AuthzDecision authorize(GridUserInterface guser, int localGroup = guser.getLocalUser().getPrimaryGid(); groupName = LocalGroups.getInstance().getGroupName(localGroup); } catch (CannotMapUserException e) { - log.error("Unable to retrieve the local group for '" + guser + "'"); + log.error("Unable to retrieve the local group for ''", guser, e); groupName = "unknown"; } diff --git a/src/main/java/it/grid/storm/authz/path/conf/PathAuthzDBReader.java b/src/main/java/it/grid/storm/authz/path/conf/PathAuthzDBReader.java index 70aca879..f4473f82 100644 --- a/src/main/java/it/grid/storm/authz/path/conf/PathAuthzDBReader.java +++ b/src/main/java/it/grid/storm/authz/path/conf/PathAuthzDBReader.java @@ -20,7 +20,6 @@ */ package it.grid.storm.authz.path.conf; -import it.grid.storm.authz.AuthzDirector; import it.grid.storm.authz.AuthzException; import it.grid.storm.authz.path.model.PathACE; import it.grid.storm.authz.path.model.PathAuthzEvaluationAlgorithm; @@ -36,13 +35,14 @@ import java.io.FileNotFoundException; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author zappi */ public class PathAuthzDBReader { - private final Logger log = AuthzDirector.getLogger(); + private static final Logger log = LoggerFactory.getLogger(PathAuthzDBReader.class); private final String authzDBFilename; private PathAuthzDB pathAuthzDB; @@ -59,18 +59,16 @@ public PathAuthzDBReader(String filename) throws Exception { .namespaceConfigPath(); if (configurationPATH.length() == 0) { String userDir = System.getProperty("user.dir"); - log.debug("Unable to found the configuration path. Assume: '" + userDir - + "'"); + log.debug("Unable to found the configuration path. Assume: '{}'", userDir); configurationPATH = userDir + File.separator + "etc"; } authzDBFilename = configurationPATH + File.separator + filename; } else { authzDBFilename = filename; } - log.debug("Loading Path Authz DB : '" + authzDBFilename + "'."); + log.debug("Loading Path Authz DB : '{}'", authzDBFilename); pathAuthzDB = loadPathAuthzDB(authzDBFilename); - log - .info("Path Authz DB ('" + pathAuthzDB.getPathAuthzDBID() + "') loaded."); + log.info("Path Authz DB ('{}') loaded.", pathAuthzDB.getPathAuthzDBID()); log.info(pathAuthzDB.toString()); } @@ -79,8 +77,7 @@ public void refreshPathAuthzDB() throws Exception { log.debug(" Start refreshing."); pathAuthzDB = loadPathAuthzDB(authzDBFilename); log.debug(" End refreshing."); - log.info("Path Authz DB ('" + pathAuthzDB.getPathAuthzDBID() - + "') RE-loaded."); + log.info("Path Authz DB ('{}') RE-loaded.", pathAuthzDB.getPathAuthzDBID()); log.info(pathAuthzDB.toString()); } @@ -100,11 +97,11 @@ private PathAuthzDB loadPathAuthzDB(String authzDBFilename) throws Exception { if (existsAuthzDBFile(authzDBFilename)) { log.debug("Parsing the Path Authz DB ..."); PathAuthzDB result = parsePathAuthzDB(authzDBFilename); - log.info("Loaded a Path Authz DB containing '" + result.getACL().size() - + "' path ACE."); + log.info("Loaded a Path Authz DB containing '{}' path ACE.", + result.getACL().size()); return result; } - log.warn("Unable to get a valid Path Authz DB. Loaded the default one! "); + log.warn("Unable to get a valid Path Authz DB. Loaded the default one!"); return new PathAuthzDB(); } @@ -120,8 +117,8 @@ private PathAuthzDB parsePathAuthzDB(String authzDBFilename) throws Exception { try { reader = new BufferedReader(new FileReader(authzDBFilename)); } catch (FileNotFoundException e) { - log.error("Unable to get a FIleReader on \'" + authzDBFilename - + "\' . FileNotFoundException: " + e); + log.error("Unable to get a FIleReader on '{}'. FileNotFoundException: ", + authzDBFilename, e.getMessage(), e); throw new Exception("No file available at path \'" + authzDBFilename + "\' . FileNotFoundException: " + e.getMessage()); } @@ -131,36 +128,35 @@ private PathAuthzDB parsePathAuthzDB(String authzDBFilename) throws Exception { ParseLineResults parsedLine = parseLine(str); switch (parsedLine.type) { case COMMENT: - log.debug("comment line : " + parsedLine.getComment()); + log.debug("comment line : {}", parsedLine.getComment()); break; case ALGORITHM_NAME: if (algorithm != null) { - log - .error("Attention! More than one Algorithm specified in configuration file: '" - + parsedLine.getAlgorithmName() + "' , " + algorithm.getClass()); + log.error("Attention! More than one Algorithm specified in " + + "configuration file: '{}', {}", parsedLine.getAlgorithmName(), + algorithm.getClass()); throw new Exception( "More than one Algorithm specified in configuration file"); } try { algorithm = buildAlgorithmInstance(parsedLine.getAlgorithmName()); - log.debug("algorithm name: " + parsedLine.getAlgorithmName()); + log.debug("algorithm name: {}", parsedLine.getAlgorithmName()); } catch (Exception e) { - log.error("Unable to get Algorithm: '" - + parsedLine.getAlgorithmName() + "'"); + log.error("Unable to get Algorithm: '{}'", parsedLine.getAlgorithmName()); throw new Exception("Unable to build a valid Algorithm"); } break; case PATH_ACE: aces.add(parsedLine.getPathAce()); - log.debug("path ace : " + parsedLine.getPathAce()); + log.debug("path ace : {}", parsedLine.getPathAce()); break; case OTHER: - log.debug("something was wrong in '" + str + "'"); + log.debug("something was wrong in '{}'", str); break; } } } catch (IOException e) { - log.error("Error while reading Path Authz DB '" + authzDBFilename + "'"); + log.error("Error while reading Path Authz DB '{}'", authzDBFilename); throw new Exception("Error while reading Path Authz DB. IOException: " + e); } finally { @@ -176,8 +172,8 @@ private PathAuthzEvaluationAlgorithm buildAlgorithmInstance( try { clazz = Class.forName(algorithmName); } catch (ClassNotFoundException e) { - log.error("Unable to load the Path Authz Algorithm Class '" - + algorithmName + "' . ClassNotFoundException: " + e); + log.error("Unable to load the Path Authz Algorithm Class '{}'. " + + "ClassNotFoundException: {}", algorithmName, e.getMessage(), e); throw new Exception("Unable to load a class with name \'" + algorithmName + "\'"); } @@ -185,8 +181,9 @@ private PathAuthzEvaluationAlgorithm buildAlgorithmInstance( try { authzAlgClass = clazz.asSubclass(PathAuthzEvaluationAlgorithm.class); } catch (ClassCastException e) { - log.error("The loaded class Class '" + algorithmName - + "' is not a PathAuthzEvaluationAlgorithm. ClassCastException: " + e); + log.error("The loaded class Class '{}' is not a " + + "PathAuthzEvaluationAlgorithm. ClassCastException: {}", + algorithmName, e.getMessage(), e); throw new Exception("Class \'" + algorithmName + "\' is not a PathAuthzEvaluationAlgorithm"); } @@ -194,47 +191,45 @@ private PathAuthzEvaluationAlgorithm buildAlgorithmInstance( try { instanceMethod = authzAlgClass.getMethod("getInstance", new Class[0]); } catch (NoSuchMethodException e) { - log.error("The loaded class Class '" + algorithmName - + "' has not a getInstance method. NoSuchMethodException: " + e); + log.error("The loaded class Class '{}' has not a getInstance method. " + + "NoSuchMethodException: {}", algorithmName, e.getMessage(), e); throw new Exception("Class \'" + algorithmName + "\' has not a getInstance method"); } catch (SecurityException e) { - log.error("Unable to get getInstance method. SecurityException: " + e); + log.error("Unable to get getInstance method. SecurityException: {}", + e.getMessage(), e); throw new Exception("Unable to get getInstance method"); } if (instanceMethod == null) { - log.error("The retrieved getInstance methos is null"); - throw new Exception("The retrieved getInstance methos is null"); + log.error("The retrieved getInstance method is null"); + throw new Exception("The retrieved getInstance method is null"); } Object authzAlgInstance; try { authzAlgInstance = instanceMethod.invoke(null, new Object[0]); } catch (IllegalAccessException e) { - log.error("Unable to call getInstance method. IllegalAccessException: " - + e); + log.error("Unable to call getInstance method. IllegalAccessException: {}", + e.getMessage(), e); throw new Exception("Unable to call getInstance method"); } catch (IllegalArgumentException e) { - log.error("Unable to call getInstance method. IllegalArgumentException: " - + e); + log.error("Unable to call getInstance method. IllegalArgumentException: {}", + e.getMessage(), e); throw new Exception("Unable to call getInstance method"); } catch (InvocationTargetException e) { - log - .error("Unable to call getInstance method. InvocationTargetException: " - + e); + log.error("Unable to call getInstance method. InvocationTargetException: {}", + e.getMessage(), e); throw new Exception("Unable to call getInstance method"); } if (authzAlgInstance instanceof PathAuthzEvaluationAlgorithm) { - log - .debug("Found a valid Path Authz Evaluation Algorithm. It implements the algorithm : " - + ((PathAuthzEvaluationAlgorithm) authzAlgInstance).getDescription()); + log.debug("Found a valid Path Authz Evaluation Algorithm. It implements " + + "the algorithm : {}", + ((PathAuthzEvaluationAlgorithm) authzAlgInstance).getDescription()); return (PathAuthzEvaluationAlgorithm) authzAlgInstance; } else { - log - .error("The method getInstance of class '" - + algorithmName - + "' does not return a valid Path Authz Evaluation Algorithm object but a \'" - + authzAlgInstance.getClass() + "\'"); + log.error("The method getInstance of class '{}' does not return a valid " + + "Path Authz Evaluation Algorithm object but a '{}'", algorithmName, + authzAlgInstance.getClass()); throw new Exception( "Unable to get a valid instance of PathAuthzEvaluationAlgorithm"); } @@ -273,9 +268,8 @@ private ParseLineResults parseLine(String pathACEString) { result = new ParseLineResults(LineType.PATH_ACE); result.setPathAce(ace); } catch (AuthzException e) { - log - .error("Something of inexiplicable in the line " + pathACEString); - log.error(" - explanation: " + e.getMessage()); + log.error("Something of inexiplicable in the line {}", pathACEString); + log.error(" - explanation: {}", e.getMessage()); result = new ParseLineResults(LineType.OTHER); } @@ -293,15 +287,15 @@ private boolean existsAuthzDBFile(String fileName) { File file = new File(fileName); if (!file.exists()) { - log.warn("The AuthzDB File '" + fileName + "' does not exists"); + log.warn("The AuthzDB File '{}' does not exists", fileName); return false; } if (!file.isFile()) { - log.warn("The AuthzDB File '" + fileName + "' is a directory"); + log.warn("The AuthzDB File '{}' is a directory", fileName); return false; } if (!file.canRead()) { - log.warn("The AuthzDB File '" + fileName + "' cannot be read"); + log.warn("The AuthzDB File '{}' cannot be read", fileName); return false; } return true; diff --git a/src/main/java/it/grid/storm/authz/path/model/PathACE.java b/src/main/java/it/grid/storm/authz/path/model/PathACE.java index 87b0d4dc..88b00f59 100644 --- a/src/main/java/it/grid/storm/authz/path/model/PathACE.java +++ b/src/main/java/it/grid/storm/authz/path/model/PathACE.java @@ -20,26 +20,25 @@ */ package it.grid.storm.authz.path.model; -import it.grid.storm.authz.AuthzDirector; import it.grid.storm.authz.AuthzException; import it.grid.storm.common.types.InvalidStFNAttributeException; import it.grid.storm.common.types.StFN; import it.grid.storm.namespace.util.userinfo.LocalGroups; import java.net.URI; -import java.util.ArrayList; import java.util.LinkedList; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author zappi */ public class PathACE { - private static final Logger log = AuthzDirector.getLogger(); + private static final Logger log = LoggerFactory.getLogger(PathACE.class); public static final String ALL_GROUPS_PATTERN = "@ALL@?|\\*"; public static final String ALL_GROUPS = "@ALL@"; @@ -214,8 +213,7 @@ public boolean subjectMatch(String subjectGroup) { Matcher allGroupsMatcher = allGroupsPattern.matcher(localGroupName); if (allGroupsMatcher.matches() || localGroupName.equals(subjectGroup)) { - log.debug("ACE (" + toString() + ") matches with the requestor '" - + subjectGroup + "'"); + log.debug("ACE ({}) matches with the requestor '{}'", this, subjectGroup); return true; } return false; @@ -227,18 +225,17 @@ public boolean subjectMatch(String subjectGroup) { @Override public boolean equals(Object other) { - boolean result = false; if (other instanceof PathACE) { PathACE pathOther = (PathACE) other; if (pathOther.getLocalGroupName() == localGroupName) { if (pathOther.getStorageFileName().equals(storageFileName)) { if (pathOther.getPathAccessMask().equals(pathAccessMask)) { - result = true; + return true; } } } } - return result; + return false; } @Override @@ -258,19 +255,9 @@ public int hashCode() { @Override public String toString() { - String result = ""; - if (localGroupName == null) { - result += "NULL"; - } else { - result += localGroupName; - } - result += " "; - result += storageFileName; - result += " "; - result += pathAccessMask; - result += " "; - result += isPermitACE ? "PERMIT" : "DENY"; - return result; + return String.format("%s %s %s %s", + localGroupName == null ? "NULL" : localGroupName, storageFileName, + pathAccessMask, isPermitACE ? "PERMIT" : "DENY"); } } diff --git a/src/main/java/it/grid/storm/authz/path/model/PathAuthzAlgBestMatch.java b/src/main/java/it/grid/storm/authz/path/model/PathAuthzAlgBestMatch.java index c4cd472d..38767b6b 100644 --- a/src/main/java/it/grid/storm/authz/path/model/PathAuthzAlgBestMatch.java +++ b/src/main/java/it/grid/storm/authz/path/model/PathAuthzAlgBestMatch.java @@ -18,7 +18,6 @@ package it.grid.storm.authz.path.model; import it.grid.storm.authz.AuthzDecision; -import it.grid.storm.authz.AuthzDirector; import it.grid.storm.common.types.StFN; import it.grid.storm.namespace.naming.NamespaceUtil; @@ -26,9 +25,10 @@ import java.util.HashMap; import java.util.LinkedList; import java.util.List; - import java.util.Collections; + import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author zappi @@ -47,13 +47,12 @@ private PathAuthzAlgBestMatch() { } - protected static final Logger log = AuthzDirector.getLogger(); + private static final Logger log = LoggerFactory.getLogger(PathAuthzAlgBestMatch.class); @Override public String getDescription() { - String description = "< Best Match Path Authorization Algorithm >"; - return description; + return "< Best Match Path Authorization Algorithm >"; } /** @@ -71,14 +70,13 @@ public AuthzDecision evaluate(String subject, StFN fileName, } List orderedACEs = getOrderedACEs(fileName, compACE); - log.debug("There are '" + orderedACEs.size() - + "' ACEs regarding the subject '" + subject + "'"); - + log.debug("There are '{}' ACEs regarding the subject '{}'", + orderedACEs.size(), subject); // Retrieve the list of Path Operation needed to authorize the SRM request PathAccessMask requestedOps = pathOperation.getSRMPathAccessMask(); ArrayList ops = new ArrayList( requestedOps.getPathOperations()); - log.trace(" Operation to authorize: " + ops); + log.trace(" Operation to authorize: {}", ops); HashMap decision = new HashMap(); String explanation = "Operations to authorize to '" + subject + "' are :" @@ -91,13 +89,13 @@ public AuthzDecision evaluate(String subject, StFN fileName, if (oAce.ace.isPermitAce()) { // Path Operation is PERMIT explanation += "PERMIT, thanks to ACE: '" + oAce + "'\n"; - log.trace("Path Operation '" + op + "' is PERMIT"); + log.trace("Path Operation '{}' is PERMIT", op); decision.put(op, AuthzDecision.PERMIT); break; } else { // Path Operation is DENY explanation += "DENY, thanks to ACE: '" + oAce + "'\n"; - log.trace("Path Operation '" + op + "' is DENY"); + log.trace("Path Operation '{}' is DENY", op); decision.put(op, AuthzDecision.DENY); break; } @@ -109,8 +107,7 @@ public AuthzDecision evaluate(String subject, StFN fileName, } // Print the decision - log.debug("Decision explanation : \n --------------" + explanation - + "--------------"); + log.debug("Decision explanation : \n --------------{}--------------", explanation); // Make the final results // - PERMIT if and only if ALL the permissions are PERMIT @@ -139,19 +136,18 @@ public AuthzDecision evaluate(String subject, StFN fileName, // Retrieve the best ACE within compatible ones. List orderedACEs = getOrderedACEs(fileName, compACE); - log.debug("There are '" + orderedACEs.size() - + "' ACEs regarding the subject '" + subject + "'"); + log.debug("There are '{}' ACEs regarding the subject '{}'", + orderedACEs.size(), subject); - log.trace(" Operation to authorize to '" + subject + "' is : " - + op); + log.trace(" Operation to authorize to '{}' is : {}", subject, op); for (OrderedACE oAce : orderedACEs) { if (oAce.ace.getPathAccessMask().containsPathOperation(op)) { if (oAce.ace.isPermitAce()) { - log.trace("Path Operation '" + op + "' is PERMIT"); + log.trace("Path Operation '{}' is PERMIT", op); return AuthzDecision.PERMIT; } else { - log.trace("Path Operation '" + op + "' is DENY"); + log.trace("Path Operation '{}' is DENY", op); return AuthzDecision.DENY; } } @@ -169,20 +165,20 @@ public AuthzDecision evaluateAnonymous(StFN fileName, // Retrieve the best ACE within compatible ones. List orderedACEs = getOrderedACEs(fileName, authzDB); - log.debug("There are '" + orderedACEs.size() + "' ACEs regarding file '" - + fileName + "'"); + log.debug("There are '{}' ACEs regarding file '{}'", orderedACEs.size(), + fileName); - log.trace(" Operation that needs anonymous authorization is : " - + pathOperation); + log.trace(" Operation that needs anonymous authorization " + + "is: {}", pathOperation); for (OrderedACE oAce : orderedACEs) { if (oAce.ace.isAllGroupsACE() && oAce.ace.getPathAccessMask().containsPathOperation(pathOperation)) { if (oAce.ace.isPermitAce()) { - log.trace("Path Operation '" + pathOperation + "' is PERMIT"); + log.trace("Path Operation '{}' is PERMIT", pathOperation); return AuthzDecision.PERMIT; } else { - log.trace("Path Operation '" + pathOperation + "' is DENY"); + log.trace("Path Operation '{}' is DENY", pathOperation); return AuthzDecision.DENY; } } @@ -200,11 +196,11 @@ public AuthzDecision evaluateAnonymous(StFN fileName, // Retrieve the best ACE within compatible ones. List orderedACEs = getOrderedACEs(fileName, authzDB); - log.debug("There are '" + orderedACEs.size() + "' ACEs regarding file '" - + fileName + "'"); + log.debug("There are '' ACEs regarding file '{}'", orderedACEs.size(), + fileName); - log.trace(" Operation that needs anonymous authorization is : " - + pathOperation); + log.trace(" Operation that needs anonymous authorization " + + "is: {}", pathOperation); PathAccessMask requestedOps = pathOperation.getSRMPathAccessMask(); ArrayList ops = new ArrayList( requestedOps.getPathOperations()); @@ -214,10 +210,10 @@ public AuthzDecision evaluateAnonymous(StFN fileName, if (oAce.ace.isAllGroupsACE() && oAce.ace.getPathAccessMask().containsPathOperation(op)) { if (oAce.ace.isPermitAce()) { - log.trace("Path Operation '" + pathOperation + "' is PERMIT"); + log.trace("Path Operation '{}' is PERMIT", pathOperation); decision.put(op, AuthzDecision.PERMIT); } else { - log.trace("Path Operation '" + pathOperation + "' is DENY"); + log.trace("Path Operation '{}' is DENY", pathOperation); decision.put(op, AuthzDecision.DENY); } } @@ -246,12 +242,12 @@ private List getCompatibleACE(String subjectGroup, List acl) { if ((acl != null) && (!(acl.isEmpty()))) { for (PathACE pathACE : acl) { if (pathACE.subjectMatch(subjectGroup)) { - log.trace("-compatibleACE: ACE:'" + pathACE - + "' match with subject='" + subjectGroup + "'"); + log.trace("-compatibleACE: ACE:'{}' match with " + + "subject='{}'", pathACE, subjectGroup); compatibleACE.add(pathACE); } else { - log.trace("-compatibleACE: ACE:'" + pathACE - + "' DOESN'T match with subject='" + subjectGroup + "'"); + log.trace("-compatibleACE: ACE:'{}' DOESN'T match with " + + "subject='{}'", pathACE, subjectGroup); } } } else { diff --git a/src/main/java/it/grid/storm/authz/path/model/PathOperation.java b/src/main/java/it/grid/storm/authz/path/model/PathOperation.java index 624df6cc..182c4dc6 100644 --- a/src/main/java/it/grid/storm/authz/path/model/PathOperation.java +++ b/src/main/java/it/grid/storm/authz/path/model/PathOperation.java @@ -27,12 +27,10 @@ public enum PathOperation { WRITE_FILE('W', "WRITE_FILE", "Write data"), READ_FILE('R', "READ_FILE", "Read data", true), RENAME('F', "RENAME", "Rename a file or a directory"), DELETE( - 'D', "DELETE", "Delete a file or a directory"), - // TRAVERSE_DIRECTORY('T', "TRAVERSE_DIRECTORY", "Traverse a directory"), - LIST_DIRECTORY('L', "LIST_DIRECTORY", "Listing a directory", true), MAKE_DIRECTORY( - 'M', "CREATE_DIRECTORY", "Create a directory"), CREATE_FILE('N', - "CREATE_FILE", "Create a new file"), UNDEFINED('?', "UNDEFINED", - "Undefined"); + 'D', "DELETE", "Delete a file or a directory"), LIST_DIRECTORY('L', + "LIST_DIRECTORY", "Listing a directory", true), MAKE_DIRECTORY('M', + "CREATE_DIRECTORY", "Create a directory"), CREATE_FILE('N', "CREATE_FILE", + "Create a new file"), UNDEFINED('?', "UNDEFINED", "Undefined"); private final char operation; private final String operationName; @@ -56,6 +54,11 @@ private PathOperation(char operation, String spaceOpName, String spaceOpDesc, this.readonly = readonly; } + public String getDescription() { + + return operationDescription; + } + public static PathOperation getSpaceOperation(char op) { switch (op) { diff --git a/src/main/java/it/grid/storm/authz/path/model/PathPrincipal.java b/src/main/java/it/grid/storm/authz/path/model/PathPrincipal.java index d9656fab..8191b18a 100644 --- a/src/main/java/it/grid/storm/authz/path/model/PathPrincipal.java +++ b/src/main/java/it/grid/storm/authz/path/model/PathPrincipal.java @@ -33,15 +33,13 @@ public class PathPrincipal { public PathPrincipal(String principal) { - if (principal.startsWith(prefix)) { - principalCategory = true; - } + principalCategory = principal.startsWith(prefix); localGroupName = principal; } public boolean isLocalGroup() { - return (!(principalCategory)); + return !principalCategory; } public String getLocalGroupName() { @@ -51,16 +49,13 @@ public String getLocalGroupName() { public boolean equals(Object o) { - boolean result = false; if (o instanceof PathPrincipal) { PathPrincipal op = (PathPrincipal) o; if (op.isLocalGroup() && (isLocalGroup())) { - result = (op.getLocalGroupName().equals(getLocalGroupName())); - } else { - result = false; + return (op.getLocalGroupName().equals(getLocalGroupName())); } } - return result; + return false; } @Override diff --git a/src/main/java/it/grid/storm/authz/path/model/SRMFileRequest.java b/src/main/java/it/grid/storm/authz/path/model/SRMFileRequest.java index 2a133f20..ae30edc7 100644 --- a/src/main/java/it/grid/storm/authz/path/model/SRMFileRequest.java +++ b/src/main/java/it/grid/storm/authz/path/model/SRMFileRequest.java @@ -38,6 +38,8 @@ public enum SRMFileRequest { PTP_Overwrite("srmPrepareToPut-overwrite", "PTP-Over", new ArrayList() { + private static final long serialVersionUID = 1L; + { add(PathOperation.WRITE_FILE); } @@ -45,6 +47,8 @@ public enum SRMFileRequest { PTP("srmPrepareToPut", "PTP", new ArrayList() { + private static final long serialVersionUID = 1L; + { add(PathOperation.CREATE_FILE); add(PathOperation.WRITE_FILE); @@ -53,6 +57,8 @@ public enum SRMFileRequest { PTG("srmPrepareToGet", "PTG", new ArrayList() { + private static final long serialVersionUID = 1L; + { add(PathOperation.READ_FILE); } @@ -60,6 +66,8 @@ public enum SRMFileRequest { CPto("srmCopy to", "CPto", new ArrayList() { + private static final long serialVersionUID = 1L; + { add(PathOperation.WRITE_FILE); add(PathOperation.CREATE_FILE); @@ -69,6 +77,8 @@ public enum SRMFileRequest { CPto_Overwrite("srmCopy to-overwrite", "CPto_Over", new ArrayList() { + private static final long serialVersionUID = 1L; + { add(PathOperation.WRITE_FILE); } @@ -76,6 +86,8 @@ public enum SRMFileRequest { CPfrom("srmCopy from", "CPfrom", new ArrayList() { + private static final long serialVersionUID = 1L; + { add(PathOperation.READ_FILE); } @@ -84,6 +96,8 @@ public enum SRMFileRequest { // OVERLOAD with OP RM("srmRemove", "RM", new ArrayList() { + private static final long serialVersionUID = 1L; + { add(PathOperation.DELETE); } @@ -91,6 +105,8 @@ public enum SRMFileRequest { RMD("srmRemoveDir", "RMD", new ArrayList() { + private static final long serialVersionUID = 1L; + { add(PathOperation.DELETE); } @@ -98,6 +114,8 @@ public enum SRMFileRequest { MD("srmMakeDir", "MD", new ArrayList() { + private static final long serialVersionUID = 1L; + { add(PathOperation.MAKE_DIRECTORY); } @@ -105,6 +123,8 @@ public enum SRMFileRequest { LS("srmLS", "LS", new ArrayList() { + private static final long serialVersionUID = 1L; + { add(PathOperation.LIST_DIRECTORY); } @@ -112,6 +132,8 @@ public enum SRMFileRequest { MV_source("srmMove-source", "MV-source", new ArrayList() { + private static final long serialVersionUID = 1L; + { add(PathOperation.READ_FILE); add(PathOperation.DELETE); @@ -121,6 +143,8 @@ public enum SRMFileRequest { MV_dest_Overwrite("srmMove-dest-overwrite", "MV-dest-Over", new ArrayList() { + private static final long serialVersionUID = 1L; + { add(PathOperation.WRITE_FILE); } @@ -128,6 +152,8 @@ public enum SRMFileRequest { MV_dest("srmMove-dest-overwrite", "MV-dest", new ArrayList() { + private static final long serialVersionUID = 1L; + { add(PathOperation.CREATE_FILE); add(PathOperation.WRITE_FILE); @@ -140,6 +166,11 @@ public enum SRMFileRequest { private static HashMap ops = new HashMap() { + /** + * + */ + private static final long serialVersionUID = 1L; + { put("PTP-Over", PTP_Overwrite); put("srmPrepareToPut-overwrite", PTP_Overwrite); @@ -204,9 +235,7 @@ public PathAccessMask getSRMPathAccessMask() { @Override public String toString() { - String result; - result = srmOp + " : " + description + " = " + requestedPathOps; - return result; + return String.format("%s : %s = %s", srmOp, description, requestedPathOps); } public boolean isReadOnly() { diff --git a/src/main/java/it/grid/storm/authz/remote/resource/AuthorizationResource.java b/src/main/java/it/grid/storm/authz/remote/resource/AuthorizationResource.java index 164b3b25..7da10638 100644 --- a/src/main/java/it/grid/storm/authz/remote/resource/AuthorizationResource.java +++ b/src/main/java/it/grid/storm/authz/remote/resource/AuthorizationResource.java @@ -54,8 +54,8 @@ public String evaluateVomsGridUserReadPermission( @QueryParam(Constants.FQANS_KEY) String FQANS) throws WebApplicationException { - log.info("Serving read operation authorization on file '" + filePath - + "\' User provides a VOMS proxy"); + log.info("Serving read operation authorization on file '{}' User provides " + + "a VOMS proxy", filePath); RequestParameters parameters = new RequestParameters(filePath, DN, FQANS); return PermissionEvaluator.evaluateVomsGridUserPermission( parameters.getDNDecoded(), parameters.getFQANSDecoded(), @@ -79,8 +79,8 @@ public String evaluateVomsGridUserWritePermission( @QueryParam(Constants.FQANS_KEY) String FQANS) throws WebApplicationException { - log.info("Serving write operation authorization on file '" + filePath - + "\' User provides a VOMS proxy"); + log.info("Serving write operation authorization on file '{}' User provides " + + "a VOMS proxy", filePath); RequestParameters parameters = new RequestParameters(filePath, DN, FQANS); return PermissionEvaluator.evaluateVomsGridUserPermission( parameters.getDNDecoded(), parameters.getFQANSDecoded(), @@ -104,8 +104,8 @@ public String evaluateVomsGridUserPTPPermission( @QueryParam(Constants.FQANS_KEY) String FQANS) throws WebApplicationException { - log.info("Serving prepareToPut operation authorization on file '" - + filePath + "\' User provides a VOMS proxy"); + log.info("Serving prepareToPut operation authorization on file '{}'. " + + "User provides a VOMS proxy", filePath); RequestParameters parameters = new RequestParameters(filePath, DN, FQANS); return PermissionEvaluator.evaluateVomsGridUserPermission( parameters.getDNDecoded(), parameters.getFQANSDecoded(), @@ -129,8 +129,8 @@ public String evaluateVomsGridUserPTPOverwritePermission( @QueryParam(Constants.FQANS_KEY) String FQANS) throws WebApplicationException { - log.info("Serving prepareToPut Overwrite operation authorization on file '" - + filePath + "\' User provides a VOMS proxy"); + log.info("Serving prepareToPut Overwrite operation authorization on " + + "file '{}'. User provides a VOMS proxy", filePath); RequestParameters parameters = new RequestParameters(filePath, DN, FQANS); return new Boolean(PermissionEvaluator.evaluateVomsGridUserPermission( parameters.getDNDecoded(), parameters.getFQANSDecoded(), @@ -155,8 +155,8 @@ public String evaluateVomsGridUserPTGPermission( @QueryParam(Constants.FQANS_KEY) String FQANS) throws WebApplicationException { - log.info("Serving prepareToGet operation authorization on file '" - + filePath + "\' User provides a VOMS proxy"); + log.info("Serving prepareToGet operation authorization on file '{}'. " + + "User provides a VOMS proxy", filePath); RequestParameters parameters = new RequestParameters(filePath, DN, FQANS); return PermissionEvaluator.evaluateVomsGridUserPermission( parameters.getDNDecoded(), parameters.getFQANSDecoded(), @@ -180,8 +180,8 @@ public String evaluateVomsGridUserRmPermission( @QueryParam(Constants.FQANS_KEY) String FQANS) throws WebApplicationException { - log.info("Serving rm operation authorization on file '" + filePath - + "\' User provides a VOMS proxy"); + log.info("Serving rm operation authorization on file '{}'. " + + "User provides a VOMS proxy", filePath); RequestParameters parameters = new RequestParameters(filePath, DN, FQANS); File file = new File(parameters.getFilePathDecoded()); if (file.isDirectory()) { @@ -213,8 +213,8 @@ public String evaluateVomsGridUserLsPermission( @QueryParam(Constants.FQANS_KEY) String FQANS) throws WebApplicationException { - log.info("Serving ls operation authorization on file '" + filePath - + "\' User provides a VOMS proxy"); + log.info("Serving ls operation authorization on file '{}'. " + + "User provides a VOMS proxy", filePath); RequestParameters parameters = new RequestParameters(filePath, DN, FQANS); return PermissionEvaluator.evaluateVomsGridUserPermission( parameters.getDNDecoded(), parameters.getFQANSDecoded(), @@ -238,8 +238,8 @@ public String evaluateVomsGridUserMkdirPermission( @QueryParam(Constants.FQANS_KEY) String FQANS) throws WebApplicationException { - log.info("Serving mkdir operation authorization on file '" + filePath - + "\' User provides a VOMS proxy"); + log.info("Serving mkdir operation authorization on file '{}'. " + + "User provides a VOMS proxy", filePath); RequestParameters parameters = new RequestParameters(filePath, DN, FQANS); return PermissionEvaluator.evaluateVomsGridUserPermission( parameters.getDNDecoded(), parameters.getFQANSDecoded(), @@ -263,8 +263,8 @@ public String evaluateVomsGridUserCpFromPermission( @QueryParam(Constants.FQANS_KEY) String FQANS) throws WebApplicationException { - log.info("Serving cpFrom operation authorization on file '" + filePath - + "\' User provides a VOMS proxy"); + log.info("Serving cpFrom operation authorization on file '{}'. " + + "User provides a VOMS proxy", filePath); RequestParameters parameters = new RequestParameters(filePath, DN, FQANS); return PermissionEvaluator.evaluateVomsGridUserPermission( parameters.getDNDecoded(), parameters.getFQANSDecoded(), @@ -288,8 +288,8 @@ public String evaluateVomsGridUserCpToOverwritePermission( @QueryParam(Constants.FQANS_KEY) String FQANS) throws WebApplicationException { - log.info("Serving cpTo Overwrite operation authorization on file '" - + filePath + "\' User provides a VOMS proxy"); + log.info("Serving cpTo Overwrite operation authorization on file '{}'. " + + "User provides a VOMS proxy", filePath); RequestParameters parameters = new RequestParameters(filePath, DN, FQANS); return new Boolean(PermissionEvaluator.evaluateVomsGridUserPermission( parameters.getDNDecoded(), parameters.getFQANSDecoded(), @@ -314,8 +314,8 @@ public String evaluateVomsGridUserCpToPermission( @QueryParam(Constants.FQANS_KEY) String FQANS) throws WebApplicationException { - log.info("Serving cpTo operation authorization on file '" + filePath - + "\' User provides a VOMS proxy"); + log.info("Serving cpTo operation authorization on file '{}'. " + + "User provides a VOMS proxy", filePath); RequestParameters parameters = new RequestParameters(filePath, DN, FQANS); return PermissionEvaluator.evaluateVomsGridUserPermission( parameters.getDNDecoded(), parameters.getFQANSDecoded(), @@ -339,8 +339,8 @@ public String evaluateVomsGridUserMvFromPermission( @QueryParam(Constants.FQANS_KEY) String FQANS) throws WebApplicationException { - log.info("Serving mvFrom operation authorization on file '" + filePath - + "\' User provides a VOMS proxy"); + log.info("Serving mvFrom operation authorization on file '{}'. " + + "User provides a VOMS proxy", filePath); RequestParameters parameters = new RequestParameters(filePath, DN, FQANS); return PermissionEvaluator.evaluateVomsGridUserPermission( parameters.getDNDecoded(), parameters.getFQANSDecoded(), @@ -357,8 +357,8 @@ public String evaluateVomsGridUserMvToOverwritePermission( @QueryParam(Constants.FQANS_KEY) String FQANS) throws WebApplicationException { - log.info("Serving mvTo operation authorization on file '" + filePath - + "\' User provides a VOMS proxy"); + log.info("Serving mvTo operation authorization on file '{}'. " + + "User provides a VOMS proxy", filePath); RequestParameters parameters = new RequestParameters(filePath, DN, FQANS); return new Boolean(PermissionEvaluator.evaluateVomsGridUserPermission( parameters.getDNDecoded(), parameters.getFQANSDecoded(), @@ -383,8 +383,8 @@ public String evaluateVomsGridUserMvToPermission( @QueryParam(Constants.FQANS_KEY) String FQANS) throws WebApplicationException { - log.info("Serving mvTo operation authorization on file '" + filePath - + "\' User provides a VOMS proxy"); + log.info("Serving mvTo operation authorization on file '{}'. " + + "User provides a VOMS proxy", filePath); RequestParameters parameters = new RequestParameters(filePath, DN, FQANS); return PermissionEvaluator.evaluateVomsGridUserPermission( parameters.getDNDecoded(), parameters.getFQANSDecoded(), @@ -405,8 +405,7 @@ public String evaluateGridUserReadPermission( @PathParam("filePath") String filePath, @QueryParam(Constants.DN_KEY) String DN) throws WebApplicationException { - log - .info("Serving read operation authorization on file '" + filePath + "\'"); + log.info("Serving read operation authorization on file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath, DN); return PermissionEvaluator.evaluateVomsGridUserPermission( parameters.getDNDecoded(), parameters.getFQANSDecoded(), @@ -427,8 +426,7 @@ public String evaluateGridUserWritePermission( @PathParam("filePath") String filePath, @QueryParam(Constants.DN_KEY) String DN) throws WebApplicationException { - log.info("Serving write operation authorization on file '" + filePath - + "\'"); + log.info("Serving write operation authorization on file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath, DN); return PermissionEvaluator.evaluateVomsGridUserPermission( @@ -444,8 +442,8 @@ public String evaluateGridUserPTPOverwritePermission( @PathParam("filePath") String filePath, @QueryParam(Constants.DN_KEY) String DN) throws WebApplicationException { - log.info("Serving prepareToPut Overwrite operation authorization on file '" - + filePath + "\'"); + log.info("Serving prepareToPut Overwrite operation authorization on " + + "file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath, DN); return new Boolean(PermissionEvaluator.evaluateVomsGridUserPermission( parameters.getDNDecoded(), parameters.getFQANSDecoded(), @@ -467,8 +465,8 @@ public String evaluateGridUserPTPPermission( @PathParam("filePath") String filePath, @QueryParam(Constants.DN_KEY) String DN) throws WebApplicationException { - log.info("Serving prepareToPut operation authorization on file '" - + filePath + "\'"); + log.info("Serving prepareToPut operation authorization on " + + "file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath, DN); return PermissionEvaluator.evaluateVomsGridUserPermission( @@ -492,8 +490,7 @@ public String evaluateGridUserPTGPermission( @PathParam("filePath") String filePath, @QueryParam(Constants.DN_KEY) String DN) throws WebApplicationException { - log.info("Serving prepareToGet operation authorization on file '" - + filePath + "\'"); + log.info("Serving prepareToGet operation authorization on file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath, DN); return PermissionEvaluator.evaluateVomsGridUserPermission( parameters.getDNDecoded(), parameters.getFQANSDecoded(), @@ -515,7 +512,7 @@ public String evaluateGridUserRmPermission( @PathParam("filePath") String filePath, @QueryParam(Constants.DN_KEY) String DN) throws WebApplicationException { - log.info("Serving rm operation authorization on file '" + filePath + "\'"); + log.info("Serving rm operation authorization on file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath, DN); File file = new File(parameters.getFilePathDecoded()); if (file.isDirectory()) { @@ -545,7 +542,7 @@ public String evaluateGridUserLsPermission( @PathParam("filePath") String filePath, @QueryParam(Constants.DN_KEY) String DN) throws WebApplicationException { - log.info("Serving ls operation authorization on file '" + filePath + "\'"); + log.info("Serving ls operation authorization on file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath, DN); return PermissionEvaluator.evaluateVomsGridUserPermission( parameters.getDNDecoded(), parameters.getFQANSDecoded(), @@ -567,8 +564,7 @@ public String evaluateGridUserMkdirPermission( @PathParam("filePath") String filePath, @QueryParam(Constants.DN_KEY) String DN) throws WebApplicationException { - log.info("Serving mkdir operation authorization on file '" + filePath - + "\'"); + log.info("Serving mkdir operation authorization on file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath, DN); return PermissionEvaluator.evaluateVomsGridUserPermission( parameters.getDNDecoded(), parameters.getFQANSDecoded(), @@ -590,8 +586,7 @@ public String evaluateGridUserCpFromPermission( @PathParam("filePath") String filePath, @QueryParam(Constants.DN_KEY) String DN) throws WebApplicationException { - log.info("Serving cpFrom operation authorization on file '" + filePath - + "\'"); + log.info("Serving cpFrom operation authorization on file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath, DN); return PermissionEvaluator.evaluateVomsGridUserPermission( parameters.getDNDecoded(), parameters.getFQANSDecoded(), @@ -612,8 +607,7 @@ public String evaluateGridUserCpToOverwritePermission( @PathParam("filePath") String filePath, @QueryParam(Constants.DN_KEY) String DN) throws WebApplicationException { - log.info("Serving cpTo Overwrite operation authorization on file '" - + filePath + "\'"); + log.info("Serving cpTo Overwrite operation authorization on file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath, DN); return new Boolean(PermissionEvaluator.evaluateVomsGridUserPermission( parameters.getDNDecoded(), parameters.getFQANSDecoded(), @@ -635,8 +629,7 @@ public String evaluateGridUserCpToPermission( @PathParam("filePath") String filePath, @QueryParam(Constants.DN_KEY) String DN) throws WebApplicationException { - log - .info("Serving cpTo operation authorization on file '" + filePath + "\'"); + log.info("Serving cpTo operation authorization on file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath, DN); return PermissionEvaluator.evaluateVomsGridUserPermission( parameters.getDNDecoded(), parameters.getFQANSDecoded(), @@ -658,8 +651,7 @@ public String evaluateGridUserMvFromPermission( @PathParam("filePath") String filePath, @QueryParam(Constants.DN_KEY) String DN) throws WebApplicationException { - log.info("Serving mvFrom operation authorization on file '" + filePath - + "\'"); + log.info("Serving mvFrom operation authorization on file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath, DN); return PermissionEvaluator.evaluateVomsGridUserPermission( parameters.getDNDecoded(), parameters.getFQANSDecoded(), @@ -680,8 +672,7 @@ public String evaluateGridUserMvToOverwritePermission( @PathParam("filePath") String filePath, @QueryParam(Constants.DN_KEY) String DN) throws WebApplicationException { - log - .info("Serving mvTo operation authorization on file '" + filePath + "\'"); + log.info("Serving mvTo operation authorization on file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath, DN); return new Boolean(PermissionEvaluator.evaluateVomsGridUserPermission( parameters.getDNDecoded(), parameters.getFQANSDecoded(), @@ -703,8 +694,7 @@ public String evaluateGridUserMvToPermission( @PathParam("filePath") String filePath, @QueryParam(Constants.DN_KEY) String DN) throws WebApplicationException { - log - .info("Serving mvTo operation authorization on file '" + filePath + "\'"); + log.info("Serving mvTo operation authorization on file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath, DN); return PermissionEvaluator.evaluateVomsGridUserPermission( parameters.getDNDecoded(), parameters.getFQANSDecoded(), @@ -723,8 +713,7 @@ public String evaluateGridUserMvToPermission( public String evaluateAnonymousReadPermission( @PathParam("filePath") String filePath) throws WebApplicationException { - log.info("Serving Anonymous read operation authorization on file '" - + filePath + "\'"); + log.info("Serving Anonymous read operation authorization on file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath); return PermissionEvaluator.evaluateAnonymousPermission( parameters.getFilePathDecoded(), PathOperation.READ_FILE).toString(); @@ -742,8 +731,7 @@ public String evaluateAnonymousReadPermission( public String evaluateAnonymousWritePermission( @PathParam("filePath") String filePath) throws WebApplicationException { - log.info("Serving Anonymous write operation authorization on file '" - + filePath + "\'"); + log.info("Serving Anonymous write operation authorization on file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath); return PermissionEvaluator.evaluateAnonymousPermission( @@ -756,9 +744,8 @@ public String evaluateAnonymousWritePermission( public String evaluateAnonymousPTPOverwritePermission( @PathParam("filePath") String filePath) throws WebApplicationException { - log - .info("Serving Anonymous prepareToPut Overwrite operation authorization on file '" - + filePath + "\'"); + log.info("Serving Anonymous prepareToPut Overwrite operation " + + "authorization on file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath); return new Boolean(PermissionEvaluator.evaluateAnonymousPermission( parameters.getFilePathDecoded(), SRMFileRequest.PTP_Overwrite) @@ -777,8 +764,8 @@ public String evaluateAnonymousPTPOverwritePermission( public String evaluateAnonymousPTPPermission( @PathParam("filePath") String filePath) throws WebApplicationException { - log.info("Serving Anonymous prepareToPut operation authorization on file '" - + filePath + "\'"); + log.info("Serving Anonymous prepareToPut operation authorization on " + + "file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath); return PermissionEvaluator.evaluateAnonymousPermission( @@ -799,8 +786,8 @@ public String evaluateAnonymousPTPPermission( public String evaluateAnonymousPTGPermission( @PathParam("filePath") String filePath) throws WebApplicationException { - log.info("Serving Anonymous prepareToGet operation authorization on file '" - + filePath + "\'"); + log.info("Serving Anonymous prepareToGet operation authorization on " + + "file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath); return PermissionEvaluator.evaluateAnonymousPermission( parameters.getFilePathDecoded(), SRMFileRequest.PTG).toString(); @@ -819,8 +806,7 @@ public String evaluateAnonymousPTGPermission( public String evaluateAnonymousRmPermission( @PathParam("filePath") String filePath) throws WebApplicationException { - log.info("Serving Anonymous rm operation authorization on file '" - + filePath + "\'"); + log.info("Serving Anonymous rm operation authorization on file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath); File file = new File(parameters.getFilePathDecoded()); if (file.isDirectory()) { @@ -846,8 +832,7 @@ public String evaluateAnonymousRmPermission( public String evaluateAnonymousLsPermission( @PathParam("filePath") String filePath) throws WebApplicationException { - log.info("Serving Anonymous ls operation authorization on file '" - + filePath + "\'"); + log.info("Serving Anonymous ls operation authorization on file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath); return PermissionEvaluator.evaluateAnonymousPermission( parameters.getFilePathDecoded(), SRMFileRequest.LS).toString(); @@ -866,8 +851,7 @@ public String evaluateAnonymousLsPermission( public String evaluateAnonymousPermission( @PathParam("filePath") String filePath) throws WebApplicationException { - log.info("Serving Anonymous mkdir operation authorization on file '" - + filePath + "\'"); + log.info("Serving Anonymous mkdir operation authorization on file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath); return PermissionEvaluator.evaluateAnonymousPermission( parameters.getFilePathDecoded(), SRMFileRequest.MD).toString(); @@ -886,8 +870,7 @@ public String evaluateAnonymousPermission( public String evaluateAnonymousCpFromPermission( @PathParam("filePath") String filePath) throws WebApplicationException { - log.info("Serving Anonymous cpFrom operation authorization on file '" - + filePath + "\'"); + log.info("Serving Anonymous cpFrom operation authorization on file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath); return PermissionEvaluator.evaluateAnonymousPermission( parameters.getFilePathDecoded(), SRMFileRequest.CPfrom).toString(); @@ -906,8 +889,7 @@ public String evaluateAnonymousCpFromPermission( public String evaluateAnonymousCpToPermission( @PathParam("filePath") String filePath) throws WebApplicationException { - log.info("Serving Anonymous cpTo operation authorization on file '" - + filePath + "\'"); + log.info("Serving Anonymous cpTo operation authorization on file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath); return PermissionEvaluator.evaluateAnonymousPermission( parameters.getFilePathDecoded(), SRMFileRequest.CPto).toString(); @@ -926,9 +908,8 @@ public String evaluateAnonymousCpToPermission( public String evaluateAnonymousCpToOverwritePermission( @PathParam("filePath") String filePath) throws WebApplicationException { - log - .info("Serving Anonymous cpTo Overwrite operation authorization on file '" - + filePath + "\'"); + log.info("Serving Anonymous cpTo Overwrite operation authorization on" + + " file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath); return new Boolean(PermissionEvaluator.evaluateAnonymousPermission( parameters.getFilePathDecoded(), SRMFileRequest.CPto_Overwrite) @@ -948,8 +929,8 @@ public String evaluateAnonymousCpToOverwritePermission( public String evaluateAnonymousMvFromPermission( @PathParam("filePath") String filePath) throws WebApplicationException { - log.info("Serving Anonymous mvFrom operation authorization on file '" - + filePath + "\'"); + log.info("Serving Anonymous mvFrom operation authorization on " + + "file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath); return PermissionEvaluator.evaluateAnonymousPermission( parameters.getFilePathDecoded(), SRMFileRequest.MV_source).toString(); @@ -968,8 +949,8 @@ public String evaluateAnonymousMvFromPermission( public String evaluateAnonymousMvToOverwritePermission( @PathParam("filePath") String filePath) throws WebApplicationException { - log.info("Serving Anonymous mvTo operation authorization on file '" - + filePath + "\'"); + log.info("Serving Anonymous mvTo operation authorization on " + + "file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath); return new Boolean(PermissionEvaluator.evaluateAnonymousPermission( parameters.getFilePathDecoded(), SRMFileRequest.MV_dest_Overwrite) @@ -989,8 +970,7 @@ public String evaluateAnonymousMvToOverwritePermission( public String evaluateAnonymousMvToPermission( @PathParam("filePath") String filePath) throws WebApplicationException { - log.info("Serving Anonymous mvTo operation authorization on file '" - + filePath + "\'"); + log.info("Serving Anonymous mvTo operation authorization on file '{}'", filePath); RequestParameters parameters = new RequestParameters(filePath); return PermissionEvaluator.evaluateAnonymousPermission( parameters.getFilePathDecoded(), SRMFileRequest.MV_dest).toString(); diff --git a/src/main/java/it/grid/storm/authz/remote/resource/PermissionEvaluator.java b/src/main/java/it/grid/storm/authz/remote/resource/PermissionEvaluator.java index f08a3cfa..ee302174 100644 --- a/src/main/java/it/grid/storm/authz/remote/resource/PermissionEvaluator.java +++ b/src/main/java/it/grid/storm/authz/remote/resource/PermissionEvaluator.java @@ -66,9 +66,8 @@ static Boolean evaluateVomsGridUserPermission(String DNDecoded, fileVFS = NamespaceDirector.getNamespace().resolveVFSbyAbsolutePath( filePathDecoded); } catch (NamespaceException e) { - log - .error("Unable to determine a VFS that maps the requested file path \'" - + filePathDecoded + "\'. NamespaceException: " + e.getMessage()); + log.error("Unable to determine a VFS that maps the requested file " + + "path '{}'. NamespaceException: {}", filePathDecoded, e.getMessage()); ResponseBuilderImpl responseBuilder = new ResponseBuilderImpl(); responseBuilder.status(Response.Status.NOT_FOUND); responseBuilder @@ -77,23 +76,21 @@ static Boolean evaluateVomsGridUserPermission(String DNDecoded, } if (!fileVFS.getCapabilities().getAllManagedProtocols() .contains(Protocol.HTTPS)) { - log.debug("User\'" + gu - + "\' not authorize to access the requeste file \'" + filePathDecoded - + "\' via HTTPS"); + log.debug("User '{}' is not authorized to access the requeste file '{}' via " + + "HTTPS", gu, filePathDecoded); return new Boolean(false); } if (!fileVFS.isApproachableByUser(gu)) { - log.debug("User\'" + gu - + "\' not authorize to approach the requeste Storage Area \'" - + fileVFS.getAliasName() + "\' via HTTPS"); + log.debug("User '{}' is not authorized to approach the requested " + + "Storage Area '{}' via HTTPS", gu, fileVFS.getAliasName()); return new Boolean(false); } StFN fileStFN = buildStFN(filePathDecoded, fileVFS); AuthzDecision decision = AuthzDirector.getPathAuthz().authorize(gu, operation, fileStFN); - log.info("Authorization decision for user " + DNDecoded - + (FQANSDecoded == null ? "" : " - " + FQANSDecoded) + " requesting " - + operation + " on " + filePathDecoded + " is [" + decision + "]"); + log.info("Authorization decision for user '{}{}' requesting {} on {} is " + + "[{}]", DNDecoded, FQANSDecoded == null ? "" : " - " + FQANSDecoded, + operation, filePathDecoded, decision); return evaluateDecision(decision); } @@ -117,9 +114,8 @@ static Boolean evaluateVomsGridUserPermission(String DNDecoded, fileVFS = NamespaceDirector.getNamespace().resolveVFSbyAbsolutePath( filePathDecoded); } catch (NamespaceException e) { - log - .error("Unable to determine a VFS that maps the requested file path \'" - + filePathDecoded + "\'. NamespaceException: " + e.getMessage()); + log.error("Unable to determine a VFS that maps the requested file " + + "path '{}'. NamespaceException: {}", filePathDecoded, e.getMessage()); ResponseBuilderImpl responseBuilder = new ResponseBuilderImpl(); responseBuilder.status(Response.Status.NOT_FOUND); responseBuilder @@ -127,17 +123,16 @@ static Boolean evaluateVomsGridUserPermission(String DNDecoded, throw new WebApplicationException(responseBuilder.build()); } if (!fileVFS.isApproachableByUser(gu)) { - log.debug("User\'" + gu - + "\' not authorize to approach the requeste Storage Area \'" - + fileVFS.getAliasName() + "\'"); + log.debug("User '{}' is not authorized to approach the requeste Storage " + + "Area '{}'", gu, fileVFS.getAliasName()); return new Boolean(false); } StFN fileStFN = buildStFN(filePathDecoded, fileVFS); AuthzDecision decision = AuthzDirector.getPathAuthz().authorize(gu, request, fileStFN); - log.info("Authorization decision for user " + DNDecoded - + (FQANSDecoded == null ? "" : " - " + FQANSDecoded) + " requesting " - + request + " on " + filePathDecoded + " is [" + decision + "]"); + log.info("Authorization decision for user '{}{}' requesting {} on {} is " + + "[{}]", DNDecoded, FQANSDecoded == null ? "" : " - " + FQANSDecoded, + request, filePathDecoded, decision); return evaluateDecision(decision); } @@ -149,9 +144,8 @@ static Boolean evaluateAnonymousPermission(String filePathDecoded, fileVFS = NamespaceDirector.getNamespace().resolveVFSbyAbsolutePath( filePathDecoded); } catch (NamespaceException e) { - log - .error("Unable to determine a VFS that maps the requested file path \'" - + filePathDecoded + "\'. NamespaceException: " + e.getMessage()); + log.error("Unable to determine a VFS that maps the requested file " + + "path '{}'. NamespaceException: {}", filePathDecoded, e.getMessage()); ResponseBuilderImpl responseBuilder = new ResponseBuilderImpl(); responseBuilder.status(Response.Status.NOT_FOUND); responseBuilder @@ -160,12 +154,12 @@ static Boolean evaluateAnonymousPermission(String filePathDecoded, } if (!fileVFS.getCapabilities().getAllManagedProtocols() .contains(Protocol.HTTP)) { - log.debug("The requeste Storage Area \'" + fileVFS.getAliasName() - + "\' is not approachable via HTTPS"); + log.debug("The requeste Storage Area '{}' is not approachable via " + + "HTTPS", fileVFS.getAliasName()); return Boolean.FALSE; } - log.info("Authorization decision for Anonymous user requesting " + request - + " on " + filePathDecoded + " is [" + AuthzDecision.PERMIT + "]"); + log.info("Authorization decision for Anonymous user requesting {} on {} " + + "is [{}]", request, filePathDecoded, AuthzDecision.PERMIT); return Boolean.TRUE; } @@ -177,9 +171,8 @@ static Boolean evaluateAnonymousPermission(String filePathDecoded, fileVFS = NamespaceDirector.getNamespace().resolveVFSbyAbsolutePath( filePathDecoded); } catch (NamespaceException e) { - log - .error("Unable to determine a VFS that maps the requested file path \'" - + filePathDecoded + "\'. NamespaceException: " + e.getMessage()); + log.error("Unable to determine a VFS that maps the requested file " + + "path '{}'. NamespaceException: {}", filePathDecoded, e.getMessage()); ResponseBuilderImpl responseBuilder = new ResponseBuilderImpl(); responseBuilder.status(Response.Status.NOT_FOUND); responseBuilder @@ -188,15 +181,15 @@ static Boolean evaluateAnonymousPermission(String filePathDecoded, } if (!fileVFS.isApproachableByAnonymous() && !(request.isReadOnly() && fileVFS.isHttpWorldReadable())) { - log.debug("The requeste Storage Area \'" + fileVFS.getAliasName() - + "\' is not approachable by anonymous users"); + log.debug("The requeste Storage Area '{}' is not approachable by " + + "anonymous users", fileVFS.getAliasName()); return new Boolean(false); } StFN fileStFN = buildStFN(filePathDecoded, fileVFS); AuthzDecision decision = AuthzDirector.getPathAuthz().authorizeAnonymous( request, fileStFN); - log.info("Authorization decision for Anonymous user requesting " + request - + " on " + filePathDecoded + " is [" + decision + "]"); + log.info("Authorization decision for Anonymous user requesting {} " + + "on {} is [{}]", request, filePathDecoded, decision); return evaluateDecision(decision); } @@ -209,14 +202,14 @@ private static Boolean evaluateDecision(AuthzDecision decision) { return new Boolean(false); } else { if (decision.equals(AuthzDecision.INDETERMINATE)) { - log - .warn("Authorization decision is INDETERMINATE! Unable to determine authorization of the user to perform requested operation on the resource"); + log.warn("Authorization decision is INDETERMINATE! Unable to " + + "determine authorization of the user to perform requested " + + "operation on the resource"); return new Boolean(false); } else { - log - .warn("Authorization decision has an unknown value \'" - + decision - + "\' ! Unable to determine authorization of the user to perform requested operation on the resource"); + log.warn("Authorization decision has an unknown value '{}'! " + + "Unable to determine authorization of the user to perform " + + "requested operation on the resource", decision); return new Boolean(false); } } @@ -233,8 +226,8 @@ private static StFN buildStFN(String filePathDecoded, VFSRootPath = fileVFS.getRootPath(); if (VFSRootPath == null) { - log.error("Unable to build StFN for path \'" + filePathDecoded - + "\'. VFS: " + fileVFS.getAliasName() + " has null RootPath"); + log.error("Unable to build StFN for path '{}'. VFS: {} has null " + + "RootPath", filePathDecoded, fileVFS.getAliasName()); ResponseBuilderImpl responseBuilder = new ResponseBuilderImpl(); responseBuilder.status(Response.Status.INTERNAL_SERVER_ERROR); responseBuilder @@ -247,13 +240,13 @@ private static StFN buildStFN(String filePathDecoded, if (VFSRootPath.endsWith("/")) { VFSRootPath = VFSRootPath.substring(0, VFSRootPath.length() - 1); } - log.debug("Chosen VFSRootPath " + VFSRootPath); + log.debug("Chosen VFSRootPath {}", VFSRootPath); List VFSMappingRules = fileVFS.getMappingRules(); if (VFSMappingRules != null && VFSMappingRules.size() > 0) { VFSStFNRoot = VFSMappingRules.get(0).getStFNRoot(); if (VFSStFNRoot == null) { - log.error("Unable to build StFN for path \'" + filePathDecoded - + "\'. VFS: " + fileVFS.getAliasName() + " has null StFNRoot"); + log.error("Unable to build StFN for path '{}'. VFS: {} has null " + + "StFNRoot", filePathDecoded, fileVFS.getAliasName()); ResponseBuilderImpl responseBuilder = new ResponseBuilderImpl(); responseBuilder.status(Response.Status.INTERNAL_SERVER_ERROR); responseBuilder @@ -266,10 +259,10 @@ private static StFN buildStFN(String filePathDecoded, if (VFSStFNRoot.endsWith("/")) { VFSStFNRoot = VFSStFNRoot.substring(0, VFSStFNRoot.length() - 1); } - log.debug("Chosen StFNRoot " + VFSStFNRoot); + log.debug("Chosen StFNRoot {}", VFSStFNRoot); } else { - log - .error("Unable to determine the StFNRoot for file path's VFS. VFSMappingRules is empty!"); + log.error("Unable to determine the StFNRoot for file path's VFS. " + + "VFSMappingRules is empty!"); ResponseBuilderImpl responseBuilder = new ResponseBuilderImpl(); responseBuilder.status(Response.Status.NOT_FOUND); responseBuilder @@ -277,8 +270,8 @@ private static StFN buildStFN(String filePathDecoded, throw new WebApplicationException(responseBuilder.build()); } } else { - log.error("None of the VFS maps the requested file path \'" - + filePathDecoded + "\'. fileVFS is null!"); + log.error("None of the VFS maps the requested file path '{}'. " + + "fileVFS is null!", filePathDecoded); ResponseBuilderImpl responseBuilder = new ResponseBuilderImpl(); responseBuilder.status(Response.Status.NOT_FOUND); responseBuilder @@ -286,9 +279,8 @@ private static StFN buildStFN(String filePathDecoded, throw new WebApplicationException(responseBuilder.build()); } } catch (NamespaceException e) { - log - .error("Unable to determine a VFS that maps the requested file path \'" - + filePathDecoded + "\'. NamespaceException: " + e.getMessage()); + log.error("Unable to determine a VFS that maps the requested file " + + "path '{}'. NamespaceException: {}", filePathDecoded, e.getMessage()); ResponseBuilderImpl responseBuilder = new ResponseBuilderImpl(); responseBuilder.status(Response.Status.NOT_FOUND); responseBuilder @@ -296,8 +288,8 @@ private static StFN buildStFN(String filePathDecoded, throw new WebApplicationException(responseBuilder.build()); } if (!filePathDecoded.startsWith(VFSRootPath)) { - log - .error("The provided file path does not starts with the VFSRoot of its VFS"); + log.error("The provided file path does not starts with the VFSRoot " + + "of its VFS"); ResponseBuilderImpl responseBuilder = new ResponseBuilderImpl(); responseBuilder.status(Response.Status.INTERNAL_SERVER_ERROR); responseBuilder @@ -310,8 +302,8 @@ private static StFN buildStFN(String filePathDecoded, try { return StFN.make(fileStFNpath); } catch (InvalidStFNAttributeException e) { - log.error("Unable to build StFN for path \'" + fileStFNpath - + "\'. InvalidStFNAttributeException: " + e.getMessage()); + log.error("Unable to build StFN for path '{}'. " + + "InvalidStFNAttributeException: {}", fileStFNpath, e.getMessage()); ResponseBuilderImpl responseBuilder = new ResponseBuilderImpl(); responseBuilder.status(Response.Status.INTERNAL_SERVER_ERROR); responseBuilder @@ -332,9 +324,9 @@ private static GridUserInterface buildGridUser(String DNDecoded, } catch (IllegalArgumentException e) { // never thrown - log.error("Unable to build the GridUserInterface object for DN \'" - + DNDecoded + "\' and FQANS \'" + Arrays.toString(FQANSArray) - + "\'. IllegalArgumentException: " + e.getMessage()); + log.error("Unable to build the GridUserInterface object for DN '{}' " + + "and FQANS '{}'. IllegalArgumentException: {}", DNDecoded, + Arrays.toString(FQANSArray), e.getMessage()); ResponseBuilderImpl builder = new ResponseBuilderImpl(); builder.status(Response.Status.BAD_REQUEST); builder.entity("Unable to build a GridUser for DN \'" + DNDecoded @@ -382,9 +374,8 @@ private static GridUserInterface loadVomsGridUser(String dn, try { gridUser = GridUserManager.makeVOMSGridUser(dn, fqansVector); } catch (IllegalArgumentException e) { - log - .error("Unexpected error on voms grid user creation. Contact StoRM Support : IllegalArgumentException " - + e.getMessage()); + log.error("Unexpected error on voms grid user creation. Contact " + + "StoRM Support : IllegalArgumentException {}", e.getMessage(), e); } return gridUser; } diff --git a/src/main/java/it/grid/storm/authz/remote/resource/RequestParameters.java b/src/main/java/it/grid/storm/authz/remote/resource/RequestParameters.java index 53565742..09a9444e 100644 --- a/src/main/java/it/grid/storm/authz/remote/resource/RequestParameters.java +++ b/src/main/java/it/grid/storm/authz/remote/resource/RequestParameters.java @@ -21,7 +21,7 @@ class RequestParameters { RequestParameters(String filePath) throws WebApplicationException { - log.debug("Building RequestParameters from filePath =" + filePath); + log.debug("Building RequestParameters from filePath = {}", filePath); filePathDecoded = decodeAndCheckFilePath(filePath); hasVomsExtension = false; @@ -31,8 +31,7 @@ class RequestParameters { RequestParameters(String filePath, String DN) throws WebApplicationException { - log.debug("Building RequestParameters from filePath =" + filePath - + " , DN=" + DN); + log.debug("Building RequestParameters from filePath={}, DN={}",filePath, DN); filePathDecoded = decodeAndCheckFilePath(filePath); DNDecoded = decodeAndCheckDN(DN); @@ -43,8 +42,8 @@ class RequestParameters { RequestParameters(String filePath, String DN, String FQANS) throws WebApplicationException { - log.debug("Building RequestParameters from filePath =" + filePath - + " , DN=" + DN + " , FQANS=" + FQANS); + log.debug("Building RequestParameters from filePath={}, DN={}, FQANS={}", + filePath, DN, FQANS); filePathDecoded = decodeAndCheckFilePath(filePath); DNDecoded = decodeAndCheckDN(DN); @@ -59,9 +58,8 @@ private static String decodeAndCheckFilePath(String filePath) try { filePathDecoded = URLDecoder.decode(filePath, Constants.ENCODING_SCHEME); } catch (UnsupportedEncodingException e) { - log - .error("Unable to decode filePath parameter. UnsupportedEncodingException : " - + e.getMessage()); + log.error("Unable to decode filePath parameter. " + + "UnsupportedEncodingException: {}", e.getMessage(), e); ResponseBuilderImpl responseBuilder = new ResponseBuilderImpl(); responseBuilder.status(Response.Status.BAD_REQUEST); responseBuilder @@ -69,12 +67,11 @@ private static String decodeAndCheckFilePath(String filePath) + Constants.ENCODING_SCHEME + "\'"); throw new WebApplicationException(responseBuilder.build()); } - log.debug("Decoded filePath = " + filePathDecoded); + log.debug("Decoded filePath = {}", filePathDecoded); if (filePathDecoded == null || filePathDecoded.trim().equals("")) { - log - .error("Unable to evaluate permissions. Some parameters are missing : filePath " - + filePathDecoded); + log.error("Unable to evaluate permissions. Some parameters are missing: " + + "filePath {}", filePathDecoded); ResponseBuilderImpl responseBuilder = new ResponseBuilderImpl(); responseBuilder.status(Response.Status.BAD_REQUEST); responseBuilder @@ -85,8 +82,8 @@ private static String decodeAndCheckFilePath(String filePath) try { filePathURI = new URI(filePathDecoded); } catch (URISyntaxException e) { - log.error("Unable to evaluate permissions on path " + filePathDecoded - + " .URISyntaxException : " + e.getMessage()); + log.error("Unable to evaluate permissions on path {}. " + + "URISyntaxException: {}", filePathDecoded, e.getMessage(), e); ResponseBuilderImpl responseBuilder = new ResponseBuilderImpl(); responseBuilder.status(Response.Status.BAD_REQUEST); responseBuilder @@ -103,9 +100,8 @@ private static String decodeAndCheckDN(String DN) try { DNDecoded = URLDecoder.decode(DN, Constants.ENCODING_SCHEME); } catch (UnsupportedEncodingException e) { - log - .error("Unable to decode DN parameter. UnsupportedEncodingException : " - + e.getMessage()); + log.error("Unable to decode DN parameter. " + + "UnsupportedEncodingException: {}", e.getMessage(), e); ResponseBuilderImpl responseBuilder = new ResponseBuilderImpl(); responseBuilder.status(Response.Status.BAD_REQUEST); responseBuilder @@ -113,12 +109,10 @@ private static String decodeAndCheckDN(String DN) + Constants.ENCODING_SCHEME + "\'"); throw new WebApplicationException(responseBuilder.build()); } - log.debug("Decoded DN = " + DNDecoded); + log.debug("Decoded DN = {}", DNDecoded); if (DNDecoded == null || DNDecoded.trim().equals("")) { - log - .error("Unable to evaluate permissions. Some parameters are missing : DN " - + DNDecoded); + log.error("Unable to evaluate permissions. Some parameters are missing : DN {}", DNDecoded); ResponseBuilderImpl responseBuilder = new ResponseBuilderImpl(); responseBuilder.status(Response.Status.BAD_REQUEST); responseBuilder @@ -135,9 +129,8 @@ private static String decodeAndCheckFQANS(String FQANS) try { FQANSDecoded = URLDecoder.decode(FQANS, Constants.ENCODING_SCHEME); } catch (UnsupportedEncodingException e) { - log - .error("Unable to decode FQANS parameter. UnsupportedEncodingException : " - + e.getMessage()); + log.error("Unable to decode FQANS parameter. " + + "UnsupportedEncodingException: {}", e.getMessage(), e); ResponseBuilderImpl responseBuilder = new ResponseBuilderImpl(); responseBuilder.status(Response.Status.BAD_REQUEST); responseBuilder @@ -145,12 +138,11 @@ private static String decodeAndCheckFQANS(String FQANS) + Constants.ENCODING_SCHEME + "\'"); throw new WebApplicationException(responseBuilder.build()); } - log.debug("Decoded FQANS = " + FQANSDecoded); + log.debug("Decoded FQANS = {}", FQANSDecoded); if (FQANSDecoded == null || FQANSDecoded.trim().equals("")) { - log - .error("Unable to evaluate permissions. Some parameters are missing : FQANS " - + FQANS); + log.error("Unable to evaluate permissions. Some parameters are " + + "missing : FQANS {}", FQANS); ResponseBuilderImpl responseBuilder = new ResponseBuilderImpl(); responseBuilder.status(Response.Status.BAD_REQUEST); responseBuilder diff --git a/src/main/java/it/grid/storm/authz/sa/SpaceAuthz.java b/src/main/java/it/grid/storm/authz/sa/SpaceAuthz.java index 74284833..18b46ff2 100644 --- a/src/main/java/it/grid/storm/authz/sa/SpaceAuthz.java +++ b/src/main/java/it/grid/storm/authz/sa/SpaceAuthz.java @@ -17,17 +17,12 @@ package it.grid.storm.authz.sa; -import it.grid.storm.authz.AuthzDirector; import it.grid.storm.authz.SpaceAuthzInterface; import it.grid.storm.authz.sa.model.SRMSpaceRequest; import it.grid.storm.griduser.GridUserInterface; -import org.slf4j.Logger; - public abstract class SpaceAuthz implements SpaceAuthzInterface { - private final Logger log = AuthzDirector.getLogger(); - private AuthzDBInterface authzDB; /** @@ -42,18 +37,17 @@ public SpaceAuthz() { super(); } - /* - * - */ public abstract boolean authorize(GridUserInterface guser, SRMSpaceRequest srmSpaceOp); - /* - * - */ public void setAuthzDB(AuthzDBInterface authzDB) { this.authzDB = authzDB; } + public AuthzDBInterface getAuthzDB() { + + return authzDB; + } + } diff --git a/src/main/java/it/grid/storm/authz/sa/SpaceDBAuthz.java b/src/main/java/it/grid/storm/authz/sa/SpaceDBAuthz.java index 1b1a9a83..c07b07ca 100644 --- a/src/main/java/it/grid/storm/authz/sa/SpaceDBAuthz.java +++ b/src/main/java/it/grid/storm/authz/sa/SpaceDBAuthz.java @@ -20,7 +20,6 @@ */ package it.grid.storm.authz.sa; -import it.grid.storm.authz.AuthzDirector; import it.grid.storm.authz.sa.model.FileAuthzDB; import it.grid.storm.authz.sa.model.SRMSpaceRequest; import it.grid.storm.config.Configuration; @@ -29,13 +28,14 @@ import java.io.File; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author zappi */ public class SpaceDBAuthz extends SpaceAuthz { - private final Logger log = AuthzDirector.getLogger(); + private static final Logger log = LoggerFactory.getLogger(SpaceDBAuthz.class); public final static String UNDEF = "undef-SpaceAuthzDB"; private String spaceAuthzDBID = "not-defined"; private static String configurationPATH; diff --git a/src/main/java/it/grid/storm/authz/sa/conf/FileAuthzDBListener.java b/src/main/java/it/grid/storm/authz/sa/conf/FileAuthzDBListener.java index c20a8e14..a3950da3 100644 --- a/src/main/java/it/grid/storm/authz/sa/conf/FileAuthzDBListener.java +++ b/src/main/java/it/grid/storm/authz/sa/conf/FileAuthzDBListener.java @@ -17,15 +17,14 @@ package it.grid.storm.authz.sa.conf; -import it.grid.storm.authz.AuthzDirector; - import org.apache.commons.configuration.event.ConfigurationEvent; import org.apache.commons.configuration.event.ConfigurationListener; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class FileAuthzDBListener implements ConfigurationListener { - private final Logger log = AuthzDirector.getLogger(); + private static final Logger log = LoggerFactory.getLogger(FileAuthzDBListener.class); private String authzFileName; public FileAuthzDBListener(String authzFileName) { @@ -43,13 +42,13 @@ public void configurationChanged(ConfigurationEvent configurationEvent) { if (!configurationEvent.isBeforeUpdate()) { // only display events after the modification was done - log.debug("Authz DB File " + this.authzFileName + " is changed!"); - log.debug(" - Type = " + configurationEvent.getType()); + log.debug("Authz DB File {} is changed!", authzFileName); + log.debug(" - Type = {}" + configurationEvent.getType()); if (configurationEvent.getPropertyName() != null) { - log.debug("Property name = " + configurationEvent.getPropertyName()); + log.debug("Property name = {}", configurationEvent.getPropertyName()); } if (configurationEvent.getPropertyValue() != null) { - log.debug("Property value = " + configurationEvent.getPropertyValue()); + log.debug("Property value = {}", configurationEvent.getPropertyValue()); } } } diff --git a/src/main/java/it/grid/storm/authz/sa/conf/FileAuthzDBParser.java b/src/main/java/it/grid/storm/authz/sa/conf/FileAuthzDBParser.java index 2a72e43d..43795941 100644 --- a/src/main/java/it/grid/storm/authz/sa/conf/FileAuthzDBParser.java +++ b/src/main/java/it/grid/storm/authz/sa/conf/FileAuthzDBParser.java @@ -17,7 +17,6 @@ package it.grid.storm.authz.sa.conf; -import it.grid.storm.authz.AuthzDirector; import it.grid.storm.authz.SpaceAuthzInterface; import it.grid.storm.authz.sa.AuthzDBInterface; import it.grid.storm.authz.sa.AuthzDBReaderInterface; @@ -27,6 +26,7 @@ import org.apache.commons.configuration.PropertiesConfiguration; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class FileAuthzDBParser implements Observer { @@ -35,7 +35,7 @@ public class FileAuthzDBParser implements Observer { private final AuthzDBInterface authzFileDB; private SpaceAuthzInterface spaceAuthz = null; - private final Logger log = AuthzDirector.getLogger(); + private static final Logger log = LoggerFactory.getLogger(FileAuthzDBParser.class); public FileAuthzDBParser(SpaceAuthzInterface spaceAuthz, AuthzDBReaderInterface reader, boolean verboseLogging) { @@ -80,7 +80,7 @@ public AuthzDBInterface getAuthzDB() { public void update(Observable observed, Object arg) { - log.debug(arg + " Refreshing Namespace Memory Cache .. "); + log.debug("{} Refreshing Namespace Memory Cache .. ", arg); // //////TEMPORARY FIX // ////// THIS METHOD HAS BEEN COMMENTED TO MAKE EVERYTHING COMPILE // FileAuthzDBReader reader = (FileAuthzDBReader) observed; diff --git a/src/main/java/it/grid/storm/authz/sa/conf/FileAuthzDBReader.java b/src/main/java/it/grid/storm/authz/sa/conf/FileAuthzDBReader.java index 69695342..b581d5fa 100644 --- a/src/main/java/it/grid/storm/authz/sa/conf/FileAuthzDBReader.java +++ b/src/main/java/it/grid/storm/authz/sa/conf/FileAuthzDBReader.java @@ -17,7 +17,6 @@ package it.grid.storm.authz.sa.conf; -import it.grid.storm.authz.AuthzDirector; import it.grid.storm.authz.sa.AuthzDBInterface; import it.grid.storm.authz.sa.AuthzDBReaderInterface; import it.grid.storm.authz.sa.model.FileAuthzDB; @@ -31,12 +30,11 @@ import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.PropertiesConfiguration; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class FileAuthzDBReader implements AuthzDBReaderInterface { - private final Logger log = AuthzDirector.getLogger(); - - private long period = 5000; // repeat every sec. + private static final Logger log = LoggerFactory.getLogger(FileAuthzDBReader.class); private String authzDBPath; @@ -106,7 +104,7 @@ public void onChangeAuthzDB(String authzDBName) throws AuthzDBReaderException { authzDBs.put(authzDBName, fileAuthzDB); long pTime = System.currentTimeMillis(); parsedTime.put(authzDBName, new Long(pTime)); - log.debug("Bound FileAuthzDBReader with " + authzDBName); + log.debug("Bound FileAuthzDBReader with {}", authzDBName); } catch (ConfigurationException ex) { ex.printStackTrace(); throw new AuthzDBReaderException("Unable to parse the AuthzDB '" diff --git a/src/main/java/it/grid/storm/authz/sa/conf/FileAuthzDBReloadingStrategy.java b/src/main/java/it/grid/storm/authz/sa/conf/FileAuthzDBReloadingStrategy.java index 9b1089a9..72c351be 100644 --- a/src/main/java/it/grid/storm/authz/sa/conf/FileAuthzDBReloadingStrategy.java +++ b/src/main/java/it/grid/storm/authz/sa/conf/FileAuthzDBReloadingStrategy.java @@ -17,16 +17,15 @@ package it.grid.storm.authz.sa.conf; -import it.grid.storm.authz.AuthzDirector; - import java.io.File; import org.apache.commons.configuration.reloading.FileChangedReloadingStrategy; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class FileAuthzDBReloadingStrategy extends FileChangedReloadingStrategy { - private final Logger log = AuthzDirector.getLogger(); + private static final Logger log = LoggerFactory.getLogger(FileAuthzDBReloadingStrategy.class); private long reloadingTime; private boolean notifing = false; @@ -89,8 +88,7 @@ protected boolean hasChanged() { boolean result = file.lastModified() > lastModified; if (result) { notifyNeeded(); - log.debug(" AuthZ DB " + file.getName() - + " is CHANGED ---> Notify needed.."); + log.debug(" AuthZ DB {} is CHANGED ---> Notify needed..", file.getName()); } return result; } diff --git a/src/main/java/it/grid/storm/authz/sa/conf/FileAuthzDBWatcher.java b/src/main/java/it/grid/storm/authz/sa/conf/FileAuthzDBWatcher.java index c4abb1c3..99b934fd 100644 --- a/src/main/java/it/grid/storm/authz/sa/conf/FileAuthzDBWatcher.java +++ b/src/main/java/it/grid/storm/authz/sa/conf/FileAuthzDBWatcher.java @@ -20,8 +20,6 @@ */ package it.grid.storm.authz.sa.conf; -import it.grid.storm.authz.AuthzDirector; - import java.io.File; import java.io.FilenameFilter; import java.text.SimpleDateFormat; @@ -32,6 +30,7 @@ import java.util.TimerTask; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author zappi @@ -39,7 +38,7 @@ */ public class FileAuthzDBWatcher { - private final Logger log = AuthzDirector.getLogger(); + private static final Logger log = LoggerFactory.getLogger(FileAuthzDBWatcher.class); private String authzDBPath; private Map authzDBfiles; // private final long delay = 1000; // 1 seconds @@ -91,8 +90,7 @@ public FileAuthzDBWatcher(long period, String authzDBPath) + "' is not a directory!"); } String[] authzDBs = authzPath.list(authzDBFileFilter); - log.debug("Found " + authzDBs.length + " authzDBs in '" + authzDBPath - + "' path."); + log.debug("Found {} authzDBs in '{}' path.", authzDBs.length, authzDBPath); for (String authzDB : authzDBs) { authzDBfiles.put(authzDB, status); } @@ -125,7 +123,7 @@ public void startWatching() { timer.schedule(fWatcher, delay, period); log.debug("AuthzDB-Watcher started."); - log.debug(" and observing the files: " + authzDBfiles); + log.debug(" and observing the files: {}", authzDBfiles); } public void onChange(String dbFileName) { @@ -146,7 +144,7 @@ public void authzDBParsed(String dbFileName) { long parsingTime = System.currentTimeMillis(); fWatcher.setParsingTime(dbFileName, parsingTime); - log.debug("Authz DB '" + dbFileName + "' parsed"); + log.debug("Authz DB '{}' parsed", dbFileName); } /** @@ -197,17 +195,15 @@ public void addFileToWatch(String dbFileName) { public void setParsingTime(String dbFileName, long parsingTime) { lastModification.put(dbFileName, parsingTime); - log.debug("Watcher updated with the occurred parsing of '" + dbFileName - + "'"); + log.debug("Watcher updated with the occurred parsing of '{}'", dbFileName); } public long getParsingTime(String dbFileName) { if (lastModification.containsKey(dbFileName)) { return lastModification.get(dbFileName).longValue(); - } else { - return -1L; } + return -1L; } /* @@ -221,13 +217,11 @@ public void run() { // Check for new authz db files File authzPath = new File(authzDBPath); String[] authzDBs = authzPath.list(authzDBFileFilter); - log.debug("Found " + authzDBs.length + " authzDBs in '" + authzDBPath - + "' path."); + log.debug("Found {} authzDBs in '{}' path.", authzDBs.length, authzDBPath); for (String authzDB : authzDBs) { if (!(authzDBfiles.containsKey(authzDB))) { authzDBfiles.put(authzDB, AuthzDBFileStatus.ERROR1); - log.debug("Found a new authz files ('" + authzDB - + "')in authzDB path."); + log.debug("Found a new authz files ('{}')in authzDB path.", authzDB); } } @@ -237,11 +231,11 @@ public void run() { f = new File(fileName); if (!f.exists()) { // authz DB file is disappeared - log.error("Unable to find the AuthzDB file '" + fileName + "' "); + log.error("Unable to find the AuthzDB file '{}'", fileName); authzDBfiles.put(fileName, AuthzDBFileStatus.ERROR2); } if (f.lastModified() > lastModification.get(fileName)) { - log.debug("Found authzDB '" + fileName + "' modified!"); + log.debug("Found authzDB '{}' modified!", fileName); onChange(fileName); } } diff --git a/src/main/java/it/grid/storm/authz/sa/conf/SpaceACETextParser.java b/src/main/java/it/grid/storm/authz/sa/conf/SpaceACETextParser.java index 06c56a98..7540e9b8 100644 --- a/src/main/java/it/grid/storm/authz/sa/conf/SpaceACETextParser.java +++ b/src/main/java/it/grid/storm/authz/sa/conf/SpaceACETextParser.java @@ -17,7 +17,6 @@ package it.grid.storm.authz.sa.conf; -import it.grid.storm.authz.AuthzDirector; import it.grid.storm.authz.sa.model.AceType; import it.grid.storm.authz.sa.model.SpaceACE; import it.grid.storm.authz.sa.model.SpaceAccessMask; @@ -26,10 +25,11 @@ import it.grid.storm.authz.sa.model.SubjectType; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class SpaceACETextParser { - private static final Logger LOG = AuthzDirector.getLogger(); + private static final Logger log = LoggerFactory.getLogger(SpaceACETextParser.class); private SpaceACETextParser() { @@ -40,31 +40,6 @@ public static SpaceACE parse(String aceString) throws AuthzDBReaderException { return parseACE(aceString); } - /** - * String invalidReason = "none"; String[] fields = new String[4]; // // - * Retrieve fields from the line; // //== ACE # == int i0 = 0; int i1 = - * line.indexOf('='); if (i1>0) { fields[0] = line.substring(i0, i1); } else { - * valid = false; invalidReason = "Unable to found 'ace.xx='"; } // == - * DNPattern|FQANPattern # == i0 = line.indexOf("dn:"); i1 = - * line.indexOf("fqan:"); if ((i0 < 0) && (i1 < 0)) { valid = false; - * invalidReason = "Unable to found 'dn:' or 'fqan:'"; } else { if (i0 > 0) { - * // found DN if (i1 > 0) { // found also fqan! ERROR valid = false; - * invalidReason = "Found both 'dn:' and 'fqan:'. Only one is allowed."; } - * else { // only DN subjectType = SubjectType.DN; fields[1] = } } else { // - * found FQAN - * - * } } - * - * - * if (validate) { valid = validate(line); } return result; - **/ - /** - * ace.1=dn:/DC=ch/DC=cern/OU=Organic - * Units/OU=Users/CN=elanciot/CN=576215/CN=Elisa Lanciotti:DURWSCP:ALLOW - * ace.3=fqan:EVERYONE:RQ:ALLOW - field[0] = ace number - field[0] = subject - * string ==> subject-type + subject - field[1] = space access mask - field[2] - * = ace type - */ private static SpaceACE parseACE(String aceString) throws AuthzDBReaderException { @@ -80,7 +55,7 @@ private static SpaceACE parseACE(String aceString) + " is not well formed"); } for (int i = 0; i < fields.length; i++) { - LOG.debug("Field[" + i + "]='" + fields[i] + "'"); + log.debug("Field[{}]='{}'", i, fields[i]); } // FIELD 0 = SubjectType + SubjectPattern SubjectType subjectType = parseSubjectType(fields[0].substring(1)); @@ -126,7 +101,7 @@ private static int parseAceNumber(String aceString) throw new AuthzDBReaderException("Number Format error in '" + aceString + "'"); } - LOG.debug("number = " + aceNumber); + log.debug("number = {}", aceNumber); return aceNumber; } diff --git a/src/main/java/it/grid/storm/authz/sa/model/AceType.java b/src/main/java/it/grid/storm/authz/sa/model/AceType.java index 7d08e6d4..f91594c9 100644 --- a/src/main/java/it/grid/storm/authz/sa/model/AceType.java +++ b/src/main/java/it/grid/storm/authz/sa/model/AceType.java @@ -32,16 +32,18 @@ private AceType(String aceType) { public static AceType getAceType(String aceTp) { - if (aceTp.toUpperCase().equals(ALLOW.toString())) + if (aceTp.toUpperCase().equals(ALLOW.toString())) { return AceType.ALLOW; - if (aceTp.toUpperCase().equals(DENY.toString())) + } + if (aceTp.toUpperCase().equals(DENY.toString())) { return AceType.DENY; + } return AceType.UNKNOWN; } public String toString() { - return this.aceType; + return aceType; } } diff --git a/src/main/java/it/grid/storm/authz/sa/model/DNEveryonePattern.java b/src/main/java/it/grid/storm/authz/sa/model/DNEveryonePattern.java index a82d5068..55dea47a 100644 --- a/src/main/java/it/grid/storm/authz/sa/model/DNEveryonePattern.java +++ b/src/main/java/it/grid/storm/authz/sa/model/DNEveryonePattern.java @@ -64,11 +64,10 @@ public boolean isValidPattern() throws AuthzDBReaderException { @Override public boolean match(SubjectAttribute subjectAttribute) { - boolean result = false; if (subjectAttribute instanceof DistinguishedName) { - result = true; + return true; } - return result; + return false; } } diff --git a/src/main/java/it/grid/storm/authz/sa/model/DNPattern.java b/src/main/java/it/grid/storm/authz/sa/model/DNPattern.java index de5ff697..ded0dc49 100644 --- a/src/main/java/it/grid/storm/authz/sa/model/DNPattern.java +++ b/src/main/java/it/grid/storm/authz/sa/model/DNPattern.java @@ -373,13 +373,12 @@ public boolean match(SubjectAttribute subjectAttribute) { public boolean isValidPattern() throws AuthzDBReaderException { // Matches to the specification. - Matcher m = DNPattern.dnWildcardPattern.matcher(this.dnPatternString); + Matcher m = DNPattern.dnWildcardPattern.matcher(dnPatternString); if (!m.matches()) { if (checkValidity) { - throw new IllegalArgumentException("DN '" + this.dnPatternString + "'"); - } else { - return false; - } + throw new IllegalArgumentException("DN '" + dnPatternString + "'"); + } + return false; } return true; } diff --git a/src/main/java/it/grid/storm/authz/sa/model/EGEEFQANPattern.java b/src/main/java/it/grid/storm/authz/sa/model/EGEEFQANPattern.java index 64bbae28..c0af599a 100644 --- a/src/main/java/it/grid/storm/authz/sa/model/EGEEFQANPattern.java +++ b/src/main/java/it/grid/storm/authz/sa/model/EGEEFQANPattern.java @@ -22,8 +22,13 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public class EGEEFQANPattern extends FQANPattern { + private static final Logger log = LoggerFactory.getLogger(EGEEFQANPattern.class); + // To verify the Regular Expression visit the site // "http://www.fileformat.info/tool/regex.htm" static private Pattern fqanWildcardPattern = Pattern @@ -31,8 +36,6 @@ public class EGEEFQANPattern extends FQANPattern { private String fqanRE = null; private String voName = null; - // private String groupPattern = null; - // private String rolePattern = null; private final boolean checkValidity; /** @@ -98,10 +101,10 @@ private void generatePattern() throws AuthzDBReaderException { groupPatternString = groupPatternString + "/" + groups[i]; } } - log.debug("voName = " + voName); - log.debug("groupPattern = " + groupPatternString); + log.debug("voName = {}", voName); + log.debug("groupPattern = {}", groupPatternString); } - log.debug("RolePattern = " + rolePatternString); + log.debug("RolePattern = {}", rolePatternString); } /** @@ -116,9 +119,8 @@ public boolean isValidPattern() throws AuthzDBReaderException { if (checkValidity) { throw new IllegalArgumentException("FQAN '" + fqanRE + "' is malformed (syntax: /VO[(/subgroup(s)|*)]][/Role=(role|*)])"); - } else { - return false; } + return false; } return true; } diff --git a/src/main/java/it/grid/storm/authz/sa/model/FQANPattern.java b/src/main/java/it/grid/storm/authz/sa/model/FQANPattern.java index ae1a4e5e..eb908acf 100644 --- a/src/main/java/it/grid/storm/authz/sa/model/FQANPattern.java +++ b/src/main/java/it/grid/storm/authz/sa/model/FQANPattern.java @@ -17,7 +17,6 @@ package it.grid.storm.authz.sa.model; -import it.grid.storm.authz.AuthzDirector; import it.grid.storm.authz.sa.conf.AuthzDBReaderException; import it.grid.storm.griduser.FQAN; import it.grid.storm.griduser.SubjectAttribute; @@ -25,11 +24,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.slf4j.Logger; - public abstract class FQANPattern implements SubjectPattern { - protected Logger log = AuthzDirector.getLogger(); protected static final String ADMIT_ALL = ".*"; protected String groupPatternString = null; protected String rolePatternString = null; diff --git a/src/main/java/it/grid/storm/authz/sa/model/FileAuthzDB.java b/src/main/java/it/grid/storm/authz/sa/model/FileAuthzDB.java index 92126e70..f6506079 100644 --- a/src/main/java/it/grid/storm/authz/sa/model/FileAuthzDB.java +++ b/src/main/java/it/grid/storm/authz/sa/model/FileAuthzDB.java @@ -17,7 +17,6 @@ package it.grid.storm.authz.sa.model; -import it.grid.storm.authz.AuthzDirector; import it.grid.storm.authz.sa.AuthzDBInterface; import it.grid.storm.authz.sa.conf.AuthzDBReaderException; import it.grid.storm.namespace.model.SAAuthzType; @@ -29,10 +28,11 @@ import org.apache.commons.configuration.PropertiesConfiguration; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class FileAuthzDB implements AuthzDBInterface { - private final Logger log = AuthzDirector.getLogger(); + private static final Logger log = LoggerFactory.getLogger(FileAuthzDB.class); private final PropertiesConfiguration authzDB; private final String acePrefix = "ace"; @@ -107,7 +107,7 @@ private List populateACL() { while (scanKeys.hasNext()) { String key = scanKeys.next(); String value = authzDB.getString(key); - log.debug("KEY:" + key + " VALUE:" + value); + log.debug("KEY: {} VALUE: {}", key, value); /** @todo IMPLEMENT PARSING OF VALUE */ } diff --git a/src/main/java/it/grid/storm/authz/sa/test/EGEEFQANPatternTest.java b/src/main/java/it/grid/storm/authz/sa/test/EGEEFQANPatternTest.java deleted file mode 100644 index b173d544..00000000 --- a/src/main/java/it/grid/storm/authz/sa/test/EGEEFQANPatternTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -/** - * - */ -package it.grid.storm.authz.sa.test; - -import it.grid.storm.authz.sa.model.FQANPattern; -import it.grid.storm.griduser.FQAN; - -import java.util.ArrayList; -import java.util.List; - -/** - * @author zappi - * - */ -public class EGEEFQANPatternTest { - - private final List testListFQANPattern = new ArrayList(); - private final List testListFQAN = new ArrayList(); - - public void invalidFQANPattern() { - - String invalidFQANPattern = "/atlas*"; - // FQANPattern fqanPattern = new EGEEFQANMatchingRule - } - - /** - * @param args - */ - public static void main(String[] args) { - - // TODO Auto-generated method stub - - } - -} diff --git a/src/main/java/it/grid/storm/authz/sa/test/MockSpaceAuthz.java b/src/main/java/it/grid/storm/authz/sa/test/MockSpaceAuthz.java index 586091c3..a605ddd2 100644 --- a/src/main/java/it/grid/storm/authz/sa/test/MockSpaceAuthz.java +++ b/src/main/java/it/grid/storm/authz/sa/test/MockSpaceAuthz.java @@ -17,18 +17,18 @@ package it.grid.storm.authz.sa.test; -import it.grid.storm.authz.AuthzDirector; import it.grid.storm.authz.SpaceAuthzInterface; import it.grid.storm.authz.sa.AuthzDBInterface; import it.grid.storm.authz.sa.model.SRMSpaceRequest; import it.grid.storm.griduser.GridUserInterface; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class MockSpaceAuthz implements SpaceAuthzInterface { private static final String MOCK_ID = "mock-space-authz"; - private final Logger log = AuthzDirector.getLogger(); + private static final Logger log = LoggerFactory.getLogger(MockSpaceAuthz.class); public MockSpaceAuthz() { diff --git a/src/main/java/it/grid/storm/authz/util/ConfigurationWatcher.java b/src/main/java/it/grid/storm/authz/util/ConfigurationWatcher.java index 560362d4..894bbec1 100644 --- a/src/main/java/it/grid/storm/authz/util/ConfigurationWatcher.java +++ b/src/main/java/it/grid/storm/authz/util/ConfigurationWatcher.java @@ -20,13 +20,9 @@ */ package it.grid.storm.authz.util; -import it.grid.storm.authz.AuthzDirector; - import java.io.File; import java.util.TimerTask; -import org.slf4j.Logger; - /** * @author ritz */ @@ -34,13 +30,11 @@ public abstract class ConfigurationWatcher extends TimerTask { private long timeStamp; private final File file; - Logger log; public ConfigurationWatcher(File file) { this.file = file; timeStamp = file.lastModified(); - log = AuthzDirector.getLogger(); } @Override diff --git a/src/main/java/it/grid/storm/authz/util/PathAuthzConfigurationWatcher.java b/src/main/java/it/grid/storm/authz/util/PathAuthzConfigurationWatcher.java index d12f566f..cc273cc8 100644 --- a/src/main/java/it/grid/storm/authz/util/PathAuthzConfigurationWatcher.java +++ b/src/main/java/it/grid/storm/authz/util/PathAuthzConfigurationWatcher.java @@ -22,18 +22,23 @@ import java.io.File; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** * @author ritz */ public class PathAuthzConfigurationWatcher extends ConfigurationWatcher { + private static final Logger log = LoggerFactory.getLogger(PathAuthzConfigurationWatcher.class); + /** * @param file */ public PathAuthzConfigurationWatcher(File file) { super(file); - log.debug("Watcher manages the configuration file :" + file); + log.debug("Watcher manages the configuration file: {}", file); } /* From 61497c75653df46da7dda75f5b3f4948d562da94 Mon Sep 17 00:00:00 2001 From: enricovianello Date: Wed, 5 Feb 2014 18:52:46 +0100 Subject: [PATCH 24/45] Fix log calls in storm backend - package it.grid.storm.balancer --- .../grid/storm/balancer/ResponsivenessCache.java | 16 ++++++++-------- .../storm/balancer/SmartRoundRobinStrategy.java | 4 ++-- .../it/grid/storm/balancer/ftp/TelnetClient.java | 13 ++++++------- .../storm/balancer/ftp/TelnetClientHandler.java | 2 +- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/main/java/it/grid/storm/balancer/ResponsivenessCache.java b/src/main/java/it/grid/storm/balancer/ResponsivenessCache.java index 7f164915..d37171e7 100644 --- a/src/main/java/it/grid/storm/balancer/ResponsivenessCache.java +++ b/src/main/java/it/grid/storm/balancer/ResponsivenessCache.java @@ -24,7 +24,7 @@ public ResponsivenessCache(long entryLifetimeMillisec) { public ResponsivenessCacheEntry addEntry(Node node) { - log.debug("Adding cache entry for " + node); + log.debug("Adding cache entry for {}", node); ResponsivenessCacheEntry newEntry = this.new ResponsivenessCacheEntry(node, Responsiveness.UNKNOWN); cache.put(node, newEntry); @@ -43,14 +43,14 @@ public Responsiveness getResponsiveness(Node node) throws Exception { ResponsivenessCacheEntry entry = getEntry(node); if (entry != null) { if (isExpired(entry)) { - log.debug("Cache entry " + entry.toString() + " expired. Refresching"); + log.debug("Cache entry {} expired. Refreshing..", entry.toString()); resp = entry.refresh(); } else { - log.debug("Found valid cache entry for " + entry.toString()); + log.debug("Found valid cache entry for {}", entry.toString()); resp = entry.getStatus(); } } else { - log.debug("Missing cache entry for " + node + " .Adding and refresching"); + log.debug("Missing cache entry for {}. Adding and refreshing..", node); entry = addEntry(node); resp = entry.refresh(); } @@ -64,7 +64,7 @@ public Responsiveness getResponsiveness(Node node) throws Exception { public boolean isExpired(ResponsivenessCacheEntry entry) { if (entry != null) { - return entry.isExpired(this.entryLifetime); + return entry.isExpired(entryLifetime); } return true; } @@ -129,9 +129,9 @@ public final Responsiveness refresh() throws Exception { } else { respness = Responsiveness.UNRESPONSIVE; } - this.checkTime = new Date().getTime(); - this.setStatus(respness); - return this.status; + checkTime = new Date().getTime(); + setStatus(respness); + return status; } /* diff --git a/src/main/java/it/grid/storm/balancer/SmartRoundRobinStrategy.java b/src/main/java/it/grid/storm/balancer/SmartRoundRobinStrategy.java index a3893601..67682882 100644 --- a/src/main/java/it/grid/storm/balancer/SmartRoundRobinStrategy.java +++ b/src/main/java/it/grid/storm/balancer/SmartRoundRobinStrategy.java @@ -51,8 +51,8 @@ public E getNextElement() throws BalancingStrategyException { try { responsiveFound = manager.isResponsive(node); } catch (Exception e) { - log.warn("Unable to check the status of the The GFTP " - + node.toString() + " . .Exception : " + e.getMessage()); + log.warn("Unable to check the status of the The GFTP {}. " + + "Exception: ", node.toString(), e.getMessage()); throw new BalancingStrategyException( "Unable to check the status of the The GFTP"); } diff --git a/src/main/java/it/grid/storm/balancer/ftp/TelnetClient.java b/src/main/java/it/grid/storm/balancer/ftp/TelnetClient.java index 9367b7f3..e47abea8 100644 --- a/src/main/java/it/grid/storm/balancer/ftp/TelnetClient.java +++ b/src/main/java/it/grid/storm/balancer/ftp/TelnetClient.java @@ -107,21 +107,21 @@ public static boolean check(InetSocketAddress address) throws Exception { bootstrap.setOption("connectTimeoutMillis", 5000); // 5 seconds - logger.debug("Connecting to Gridftp at " + address.toString()); + logger.debug("Connecting to Gridftp at {}", address.toString()); ChannelFuture channelFuture = bootstrap.connect(address); Channel channel = channelFuture.awaitUninterruptibly().getChannel(); if (!channelFuture.isSuccess()) { - logger.info("GridFTP Telnet connection to server " + address.toString() - + "failed. Cause : " + channelFuture.getCause()); + logger.info("GridFTP Telnet connection to server {} failed. Cause: {}", + address.toString(), channelFuture.getCause()); bootstrap.releaseExternalResources(); return false; } logger.debug("Channel created successfully"); if (!channel.isConnected()) { - logger.info("GridFTP Telnet connection failed " + address.toString() - + "failed. Cause : " + channelFuture.getCause()); + logger.info("GridFTP Telnet connection failed {}. Cause: {}", + address.toString(), channelFuture.getCause()); bootstrap.releaseExternalResources(); return false; } @@ -141,8 +141,7 @@ public static boolean check(InetSocketAddress address) throws Exception { failed = true; } } catch (Exception e) { - logger.warn("Unable to check handler response. Exception : " - + e.getMessage()); + logger.warn("Unable to check handler response. Exception: {}", e.getMessage()); failedAttempts++; failed = true; } diff --git a/src/main/java/it/grid/storm/balancer/ftp/TelnetClientHandler.java b/src/main/java/it/grid/storm/balancer/ftp/TelnetClientHandler.java index 05d2b78c..348042c3 100644 --- a/src/main/java/it/grid/storm/balancer/ftp/TelnetClientHandler.java +++ b/src/main/java/it/grid/storm/balancer/ftp/TelnetClientHandler.java @@ -42,7 +42,7 @@ public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) @Override public void exceptionCaught(ChannelHandlerContext ctx, ExceptionEvent e) { - log.warn("Server unreachable " + e.getCause().getMessage()); + log.warn("Server unreachable {}", e.getCause().getMessage()); this.state.setError(); state.updated(); } From cfdd5066547be36ea44d94d27244d3bc6542807e Mon Sep 17 00:00:00 2001 From: Andrea Ceccanti Date: Wed, 5 Feb 2014 19:02:04 +0100 Subject: [PATCH 25/45] More logging rationalization work. --- .../synchcall/command/CommandHelper.java | 1 + .../space/GetSpaceMetaDataCommand.java | 78 +- .../command/space/GetSpaceTokensCommand.java | 225 +- .../command/space/ReleaseSpaceCommand.java | 447 ++-- .../command/space/ReserveSpaceCommand.java | 2153 ++++++++--------- 5 files changed, 1357 insertions(+), 1547 deletions(-) diff --git a/src/main/java/it/grid/storm/synchcall/command/CommandHelper.java b/src/main/java/it/grid/storm/synchcall/command/CommandHelper.java index d76b974f..285f5cb1 100644 --- a/src/main/java/it/grid/storm/synchcall/command/CommandHelper.java +++ b/src/main/java/it/grid/storm/synchcall/command/CommandHelper.java @@ -7,6 +7,7 @@ import it.grid.storm.srm.types.TReturnStatus; import it.grid.storm.srm.types.TSURL; import it.grid.storm.srm.types.TSURLReturnStatus; +import it.grid.storm.srm.types.TSpaceToken; import it.grid.storm.srm.types.TStatusCode; import it.grid.storm.synchcall.data.DataHelper; import it.grid.storm.synchcall.data.InputData; diff --git a/src/main/java/it/grid/storm/synchcall/command/space/GetSpaceMetaDataCommand.java b/src/main/java/it/grid/storm/synchcall/command/space/GetSpaceMetaDataCommand.java index ce196bec..4a5b4399 100644 --- a/src/main/java/it/grid/storm/synchcall/command/space/GetSpaceMetaDataCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/space/GetSpaceMetaDataCommand.java @@ -61,15 +61,11 @@ public class GetSpaceMetaDataCommand extends SpaceCommand implements Command { - public static final Logger log = LoggerFactory.getLogger(GetSpaceMetaDataCommand.class); + public static final Logger log = LoggerFactory + .getLogger(GetSpaceMetaDataCommand.class); private ReservedSpaceCatalog catalog = null; - private static final boolean SUCCESS = true; - private static final boolean FAILURE = false; - private static final boolean GLOBALSTATUS = true; - private static final boolean LOCALSTATUS = false; - private static final String SRM_COMMAND = "srmGetSpaceMetaData"; /** @@ -116,9 +112,8 @@ public OutputData execute(InputData indata) { try { spaceData = catalog.getStorageSpace(token); } catch (TransferObjectDecodingException e) { - log - .error("Unable to build StorageSpaceData from StorageSpaceTO. TransferObjectDecodingException: " - + e.getMessage()); + log.error("Error getting storage space data for token {}. {}", + token, e.getMessage(),e); metadata = createFailureMetadata(token, TStatusCode.SRM_INTERNAL_ERROR, "Error building space data from row DB data", data.getUser()); errorCount++; @@ -126,8 +121,8 @@ public OutputData execute(InputData indata) { continue; } catch (DataAccessException e) { - log.error("Unable to build get StorageSpaceTO. DataAccessException: " - + e.getMessage()); + log.error("Error getting storage space data for token {}. {}", + token, e.getMessage(),e); metadata = createFailureMetadata(token, TStatusCode.SRM_INTERNAL_ERROR, "Error retrieving row space token data from DB", data.getUser()); errorCount++; @@ -136,9 +131,7 @@ public OutputData execute(InputData indata) { } if (spaceData != null) { if (!spaceData.isInitialized()) { - log - .warn("Unable to create a valid TMetaDataSpace for storage space token \'" - + token + "\', the space is not initialized"); + log.warn("Uninitialized storage data found for token {}", token); metadata = createFailureMetadata(token, TStatusCode.SRM_FAILURE, "Storage Space not initialized yet", data.getUser()); errorCount++; @@ -146,18 +139,14 @@ public OutputData execute(InputData indata) { try { metadata = new TMetaDataSpace(spaceData); } catch (InvalidTMetaDataSpaceAttributeException e) { - log - .error("Unable to build TMetaDataSpace from StorageSpaceData. InvalidTMetaDataSpaceAttributeException: " - + e.getMessage()); + log.error("Metadata error. {}", e.getMessage(), e); metadata = createFailureMetadata(token, TStatusCode.SRM_INTERNAL_ERROR, "Error building Storage Space Metadata from row data", data.getUser()); errorCount++; } catch (InvalidTSizeAttributesException e) { - log - .error("Unable to build TMetaDataSpace from StorageSpaceData. InvalidTSizeAttributesException: " - + e.getMessage()); + log.error("Metadata error. {}", e.getMessage(), e); metadata = createFailureMetadata(token, TStatusCode.SRM_INTERNAL_ERROR, "Error building Storage Space Metadata from row data", @@ -166,8 +155,7 @@ public OutputData execute(InputData indata) { } } } else { - log.warn("getMetaDataSpace: unable to retrieve SpaceData for token: " - + token); + log.warn("Unable to retrieve space data for token {}.",token); metadata = createFailureMetadata(token, TStatusCode.SRM_INVALID_REQUEST, "Space Token not found", data.getUser()); @@ -179,39 +167,50 @@ public OutputData execute(InputData indata) { boolean requestSuccess = (errorCount == 0); boolean requestFailure = (errorCount == data.getSpaceTokenArray().size()); - // Create Global Status Response try { if (requestSuccess) { globalStatus = new TReturnStatus(TStatusCode.SRM_SUCCESS, ""); - log.info(formatLogMessage(SUCCESS, GLOBALSTATUS, data.getUser(), null, - data.getSpaceTokenArray(), globalStatus)); + + log.info("srmGetSpaceMetadata: user <{}> Request for [spaceTokens: {}] " + + "done succesfully with: [status: {}]", + data.getUser(), + data.getSpaceTokenArray(), + globalStatus); + } else { if (requestFailure) { globalStatus = new TReturnStatus(TStatusCode.SRM_FAILURE, "No valid space tokens"); - log.info(formatLogMessage(FAILURE, GLOBALSTATUS, data.getUser(), - null, data.getSpaceTokenArray(), globalStatus)); + + log.info("srmGetSpaceMetadata: user <{}> Request for [spaceTokens: {}] " + + "failed with: [status: {}]", + data.getUser(), + data.getSpaceTokenArray(), + globalStatus); + } else { + globalStatus = new TReturnStatus(TStatusCode.SRM_PARTIAL_SUCCESS, "Check space tokens statuses for details"); - log.info(formatLogMessage(SUCCESS, GLOBALSTATUS, data.getUser(), - null, data.getSpaceTokenArray(), globalStatus)); + + log.info("srmGetSpaceMetadata: user <{}> Request for [spaceTokens: {}] " + + "partially done with: [status: {}]", + data.getUser(), + data.getSpaceTokenArray(), + globalStatus); + } } } catch (InvalidTReturnStatusAttributeException ex) { - log.error("srmGetSpaceMetaData: Impossible is happen!!", ex); + log.error(ex.getMessage(),ex); return new GetSpaceMetaDataOutputData(); } - log.debug(" all value retrived..."); GetSpaceMetaDataOutputData response = null; try { response = new GetSpaceMetaDataOutputData(globalStatus, arrayData); } catch (InvalidGetSpaceMetaDataOutputAttributeException e) { - // never thrown - log - .error("Unexpected InvalidGetSpaceMetaDataOutputAttributeException in execute : " - + e.getMessage()); + log.error(e.getMessage(),e); } return response; } @@ -221,16 +220,13 @@ private TMetaDataSpace createFailureMetadata(TSpaceToken token, TMetaDataSpace metadata = TMetaDataSpace.makeEmpty(); metadata.setSpaceToken(token); + try { metadata.setStatus(new TReturnStatus(statusCode, message)); } catch (InvalidTReturnStatusAttributeException e) { - // never thrown - log - .error("Unexpected InvalidTReturnStatusAttributeException in execute : " - + e); + log.error(e.getMessage(),e); } - log.error(formatLogMessage(SUCCESS, LOCALSTATUS, user, token, null, - metadata.getStatus())); + return metadata; } diff --git a/src/main/java/it/grid/storm/synchcall/command/space/GetSpaceTokensCommand.java b/src/main/java/it/grid/storm/synchcall/command/space/GetSpaceTokensCommand.java index b49bf73c..367afb5a 100644 --- a/src/main/java/it/grid/storm/synchcall/command/space/GetSpaceTokensCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/space/GetSpaceTokensCommand.java @@ -50,122 +50,111 @@ public class GetSpaceTokensCommand extends SpaceCommand implements Command { - public static final Logger log = LoggerFactory.getLogger(GetSpaceTokensCommand.class); - - private static final String SRM_COMMAND = "srmGetSpaceTokens"; - private ReservedSpaceCatalog catalog = null; - - public GetSpaceTokensCommand() { - - catalog = new ReservedSpaceCatalog(); - }; - - public OutputData execute(InputData data) { - - GetSpaceTokensOutputData outputData; - IdentityGetSpaceTokensInputData inputData; - if (data instanceof IdentityInputData) { - inputData = (IdentityGetSpaceTokensInputData) data; - } else { - outputData = new GetSpaceTokensOutputData(); - outputData.setStatus(CommandHelper.buildStatus( - TStatusCode.SRM_NOT_SUPPORTED, "Anonymous user can not perform" - + SRM_COMMAND)); - printRequestOutcome(outputData.getStatus(), - (GetSpaceTokensInputData) data); - return outputData; - } - TReturnStatus status = null; - - log.debug("Started GetSpaceTokens function"); - - /** - * ******************** Check user authentication and authorization - * ***************************** - */ - GridUserInterface user = inputData.getUser(); - if (user == null) { - log.debug("GetSpaceTokens: the user field is NULL"); - try { - status = new TReturnStatus(TStatusCode.SRM_AUTHENTICATION_FAILURE, - "Unable to get user credential!"); - } catch (InvalidTReturnStatusAttributeException ex1) { - - // Nothing to do, it will never be thrown - log.debug("GetSpaceTokens: Error creating returnStatus "); - } - log.error("srmGetSpaceTokens: <" + user - + "> Request for [spaceTokenDescription:" - + inputData.getSpaceTokenAlias() + "] failed with: [status:" + status - + "]"); - outputData = new GetSpaceTokensOutputData(status, null); - return outputData; - } - - /** - * ******************************** Start to manage the request - * ********************************** - */ - String spaceAlias = inputData.getSpaceTokenAlias(); - if (spaceAlias == null) { - log.debug("userSpaceTokenDescription=NULL"); - } else { - log.debug("userSpaceTokenDescription=" + spaceAlias); - } - - ArrayOfTSpaceToken arrayOfSpaceTokens = catalog.getSpaceTokens(user, - spaceAlias); - - // If no valid tokenis found try withVOSPACEToken - if (arrayOfSpaceTokens.size() == 0) { - arrayOfSpaceTokens = catalog.getSpaceTokensByAlias(spaceAlias); - // //TODO ADD HERE A CHECK IF THE RESULTS ID A DEFAULT TOKEN OF NOT - - } - - try { - if (arrayOfSpaceTokens.size() == 0) { - if (spaceAlias != null) { - status = new TReturnStatus(TStatusCode.SRM_INVALID_REQUEST, - "'userSpaceTokenDescription' does not refer to an existing space"); - } else { - status = new TReturnStatus(TStatusCode.SRM_FAILURE, - "No space tokens owned by this user"); - } - arrayOfSpaceTokens = null; - } else { - status = new TReturnStatus(TStatusCode.SRM_SUCCESS, ""); - } - } catch (InvalidTReturnStatusAttributeException e) { - // Nothing to do, it will never be thrown - log.error("GetSpaceTokens: Error creating returnStatus "); - } - - if (status.isSRM_SUCCESS()) { - log.info("srmGetSpaceTokens: <" + user - + "> Request for [spaceTokenDescription:" - + inputData.getSpaceTokenAlias() + "] successfully done with: [status:" - + status + "]"); - } else { - log.error("srmGetSpaceTokens: <" + user - + "> Request for [spaceTokenDescription:" - + inputData.getSpaceTokenAlias() + "] failed with: [status:" + status - + "]"); - } - - outputData = new GetSpaceTokensOutputData(status, arrayOfSpaceTokens); - - return outputData; - - } - - private void printRequestOutcome(TReturnStatus status, - GetSpaceTokensInputData data) { - - if (data != null) { - CommandHelper.printRequestOutcome(SRM_COMMAND, log, status, data); - } else { - CommandHelper.printRequestOutcome(SRM_COMMAND, log, status); - } - } + public static final Logger log = LoggerFactory + .getLogger(GetSpaceTokensCommand.class); + + private static final String SRM_COMMAND = "srmGetSpaceTokens"; + private ReservedSpaceCatalog catalog = null; + + public GetSpaceTokensCommand() { + + catalog = new ReservedSpaceCatalog(); + }; + + public OutputData execute(InputData data) { + + GetSpaceTokensOutputData outputData; + IdentityGetSpaceTokensInputData inputData; + if (data instanceof IdentityInputData) { + inputData = (IdentityGetSpaceTokensInputData) data; + } else { + outputData = new GetSpaceTokensOutputData(); + outputData.setStatus(CommandHelper.buildStatus( + TStatusCode.SRM_NOT_SUPPORTED, "Anonymous user can not perform" + + SRM_COMMAND)); + printRequestOutcome(outputData.getStatus(), + (GetSpaceTokensInputData) data); + return outputData; + } + + TReturnStatus status = null; + + log.debug("Started GetSpaceTokens function"); + + GridUserInterface user = inputData.getUser(); + if (user == null) { + log.debug("GetSpaceTokens: the user field is NULL"); + try { + status = new TReturnStatus(TStatusCode.SRM_AUTHENTICATION_FAILURE, + "Unable to get user credential!"); + } catch (InvalidTReturnStatusAttributeException ex1) { + log.error(ex1.getMessage(), ex1); + } + + log.error("srmGetSpaceTokens: <{}> " + + "Request for [spaceTokenDescription:{}] failed with: [status: {}]", + user, + inputData.getSpaceTokenAlias(), + status); + + outputData = new GetSpaceTokensOutputData(status, null); + return outputData; + } + + String spaceAlias = inputData.getSpaceTokenAlias(); + log.debug("spaceAlias= {}", spaceAlias); + + ArrayOfTSpaceToken arrayOfSpaceTokens = catalog.getSpaceTokens(user, + spaceAlias); + + if (arrayOfSpaceTokens.size() == 0) { + arrayOfSpaceTokens = catalog.getSpaceTokensByAlias(spaceAlias); + } + + try { + if (arrayOfSpaceTokens.size() == 0) { + if (spaceAlias != null) { + status = new TReturnStatus(TStatusCode.SRM_INVALID_REQUEST, + "'userSpaceTokenDescription' does not refer to an existing space"); + } else { + status = new TReturnStatus(TStatusCode.SRM_FAILURE, + "No space tokens owned by this user"); + } + arrayOfSpaceTokens = null; + } else { + status = new TReturnStatus(TStatusCode.SRM_SUCCESS, ""); + } + } catch (InvalidTReturnStatusAttributeException e) { + log.error(e.getMessage(), e); + } + + if (status.isSRM_SUCCESS()) { + log.info("srmGetSpaceTokens: <{}> Request for [spaceTokenDescription: {}] " + + "succesfully done with: [status: {}]", + user, + inputData.getSpaceTokenAlias(), + status); + } else { + log.error("srmGetSpaceTokens: <{}> Request for [spaceTokenDescription: {}] " + + "failed with: [status: {}]", + user, + inputData.getSpaceTokenAlias(), + status); + } + + outputData = new GetSpaceTokensOutputData(status, arrayOfSpaceTokens); + + return outputData; + + } + + private void printRequestOutcome(TReturnStatus status, + GetSpaceTokensInputData data) { + + if (data != null) { + CommandHelper.printRequestOutcome(SRM_COMMAND, log, status, data); + } else { + CommandHelper.printRequestOutcome(SRM_COMMAND, log, status); + } + } } diff --git a/src/main/java/it/grid/storm/synchcall/command/space/ReleaseSpaceCommand.java b/src/main/java/it/grid/storm/synchcall/command/space/ReleaseSpaceCommand.java index a40f4e57..e9c7373f 100644 --- a/src/main/java/it/grid/storm/synchcall/command/space/ReleaseSpaceCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/space/ReleaseSpaceCommand.java @@ -54,253 +54,204 @@ public class ReleaseSpaceCommand extends SpaceCommand implements Command { - private final ReservedSpaceCatalog catalog; - - /** - * Logger - */ - private static final Logger log = LoggerFactory - .getLogger(ReleaseSpaceCommand.class); - - private static final String SRM_COMMAND = "srmReleaseSpace"; - - public ReleaseSpaceCommand() { - - catalog = new ReservedSpaceCatalog(); - }; - - public OutputData execute(InputData indata) { - - ReleaseSpaceOutputData outputData = new ReleaseSpaceOutputData(); - IdentityReleaseSpaceInputData inputData; - if (indata instanceof IdentityInputData) { - inputData = (IdentityReleaseSpaceInputData) indata; - } else { - outputData.setStatus(CommandHelper.buildStatus( - TStatusCode.SRM_NOT_SUPPORTED, "Anonymous user can not perform" - + SRM_COMMAND)); - printRequestOutcome(outputData.getStatus(), - (ReleaseSpaceInputData) indata); - return outputData; - } - TReturnStatus returnStatus = null; - - /** - * Check input parameter. - * - * Validate ReleaseSpaceInputData. The check is done at this level to - * separate internal StoRM logic from xmlrpc specific operation. - */ - - if ((inputData == null) - || ((inputData != null) && (inputData.getSpaceToken() == null))) { - ReleaseSpaceCommand.log - .error("ReleaseSpace : Invalid input parameter specified"); - returnStatus = manageStatus(TStatusCode.SRM_INVALID_REQUEST, - "SpaceToken is empty."); - outputData.setStatus(returnStatus); - return outputData; - } - - /** - * Check if GridUser in InputData is not null, otherwise return with an - * error message. - */ - GridUserInterface user = inputData.getUser(); - if (user == null) { - ReleaseSpaceCommand.log - .debug("Release Space: Unable to get user credential. "); - returnStatus = manageStatus(TStatusCode.SRM_AUTHENTICATION_FAILURE, - "Unable to get user credential"); - outputData.setStatus(returnStatus); - ReleaseSpaceCommand.log.error("srmReleaseSpace: <" + user - + "> Request for [spacetoken:" + inputData.getSpaceToken() - + "] failed with: [status:" + returnStatus + "]"); - return outputData; - } - - ReleaseSpaceCommand.log.debug("INPUT data not null"); - - boolean forceFileRelease = inputData.isForceFileRelease(); - boolean nopinned = true; - boolean failure = false; - String explanation = ""; - TStatusCode statusCode = null; - - /** - * Get StorageSpaceData linked with the specified space Token. - */ - StorageSpaceData data; - try { - data = catalog.getStorageSpace(inputData.getSpaceToken()); - } catch (TransferObjectDecodingException e) { - log - .error("Unable to build StorageSpaceData from StorageSpaceTO. TransferObjectDecodingException: " - + e.getMessage()); - failure = true; - explanation = "Error building space data from row DB data."; - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - returnStatus = manageStatus(statusCode, explanation); - outputData.setStatus(returnStatus); - ReleaseSpaceCommand.log.error("srmReleaseSpace: <" + user - + "> Request for [spacetoken:" + inputData.getSpaceToken() - + "] for failed with: [status:" + returnStatus + "]"); - return outputData; - - } catch (DataAccessException e) { - log.error("Unable to build get StorageSpaceTO. DataAccessException: " - + e.getMessage()); - failure = true; - explanation = "Error retrieving row space token data from DB."; - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - returnStatus = manageStatus(statusCode, explanation); - outputData.setStatus(returnStatus); - ReleaseSpaceCommand.log.error("srmReleaseSpace: <" + user - + "> Request for [spacetoken:" + inputData.getSpaceToken() - + "] for failed with: [status:" + returnStatus + "]"); - return outputData; - } - - if (data == null) { - failure = true; - explanation = "SpaceToken does not refers to an existing space."; - statusCode = TStatusCode.SRM_INVALID_REQUEST; - returnStatus = manageStatus(statusCode, explanation); - outputData.setStatus(returnStatus); - ReleaseSpaceCommand.log.error("srmReleaseSpace: <" + user - + "> Request for [spacetoken:" + inputData.getSpaceToken() - + "] for failed with: [status:" + returnStatus + "]"); - return outputData; - - } - - ReleaseSpaceCommand.log - .debug("ReleaseExecutor: space data not null retrieved."); - - /** - * With forceFileRelease = false, the space is not released if there are - * still file pinned on it. - */ - if (!forceFileRelease) { - /** - * @todo Verify if there are still pinned files... - */ - nopinned = true; - } - - if ((forceFileRelease) || (nopinned)) { - // Verify if the requester is the owner of the token - if (data.getOwner().getDn().equals(user.getDn())) { - // This is an authorized request of ReleaseSpace. - // The user that perform the ReleaseSpace is the owner of the - // SpaceToken. - ReleaseSpaceCommand.log - .debug("ReleaseCommand: Authorized Release Space for user: " - + data.getOwner()); - returnStatus = manageAuthorizedReleaseSpace(data, user); - } else { - ReleaseSpaceCommand.log - .debug("ReleaseCommand: Unauthorized ReleaseSpaceRequest!"); - failure = true; - explanation = "User is not authorized to release this token"; - statusCode = TStatusCode.SRM_AUTHORIZATION_FAILURE; - returnStatus = manageStatus(statusCode, explanation); - } - - } else { - ReleaseSpaceCommand.log - .debug("ReleaseCommand: Space still contains pinned files!"); - failure = true; - explanation = "Space still contains pinned files. "; - statusCode = TStatusCode.SRM_FAILURE; - returnStatus = manageStatus(statusCode, explanation); - } - - // if (failure) { - // returnStatus = manageStatus(statusCode, explanation); - // } - ReleaseSpaceCommand.log.debug("ReleaseCommand:return outputData"); - outputData.setStatus(returnStatus); - if (returnStatus.isSRM_SUCCESS()) { - ReleaseSpaceCommand.log.info("srmReleaseSpace: <" + user - + "> Request for [spacetoken:" + inputData.getSpaceToken() - + "] successfully done with: [status:" + returnStatus + "]"); - } else { - ReleaseSpaceCommand.log.error("srmReleaseSpace: <" + user - + "> Request for [spacetoken:" + inputData.getSpaceToken() - + "] for failed with: [status:" + returnStatus + "]"); - } - - return outputData; - } - - /** - * - * @param user - * GridUserInterface - * @param data - * StorageSpaceData - * @return TReturnStatus - */ - private TReturnStatus manageAuthorizedReleaseSpace(StorageSpaceData data, - GridUserInterface user) { - - // Get Space File name - String spaceFileName; - PFN pfn = data.getSpaceFileName(); - ReleaseSpaceCommand.log - .debug("ReleaseCommand: manageAuthorizedReleaseSpace"); - - if (pfn != null) { - spaceFileName = pfn.getValue(); - ReleaseSpaceCommand.log.debug("ReleaseCommand: spaceFileName: " - + spaceFileName); - File spaceFile = new File(spaceFileName); - if (spaceFile.delete()) { - // Remove spaceData from presistence - if (catalog.release(user, data.getSpaceToken())) { - return manageStatus(TStatusCode.SRM_SUCCESS, "Space Released."); - } else { - return manageStatus(TStatusCode.SRM_INTERNAL_ERROR, - "Space removed, but spaceToken was not found in the DB"); - } - } else { - return manageStatus(TStatusCode.SRM_FAILURE, - "Space can not be removed by StoRM!"); - } - } else { - return manageStatus(TStatusCode.SRM_FAILURE, "SRM Internal failure."); - } - } - - /** - * - * @param statusCode - * statusCode - * @param explanation - * explanation string - * @return returnStatus returnStatus - */ - private TReturnStatus manageStatus(TStatusCode statusCode, String explanation) { - - TReturnStatus returnStatus = null; - try { - returnStatus = new TReturnStatus(statusCode, explanation); - } catch (InvalidTReturnStatusAttributeException ex1) { - ReleaseSpaceCommand.log - .debug("ReleaseFile : Error creating returnStatus " + ex1); - } - return returnStatus; - } - - private void printRequestOutcome(TReturnStatus status, - ReleaseSpaceInputData indata) { - - if (indata != null) { - CommandHelper.printRequestOutcome(SRM_COMMAND, log, status, indata); - } else { - CommandHelper.printRequestOutcome(SRM_COMMAND, log, status); - } - } + private final ReservedSpaceCatalog catalog; + + /** + * Logger + */ + private static final Logger log = LoggerFactory + .getLogger(ReleaseSpaceCommand.class); + + private static final String SRM_COMMAND = "srmReleaseSpace"; + + public ReleaseSpaceCommand() { + + catalog = new ReservedSpaceCatalog(); + }; + + public OutputData execute(InputData indata) { + + ReleaseSpaceOutputData outputData = new ReleaseSpaceOutputData(); + IdentityReleaseSpaceInputData inputData; + if (indata instanceof IdentityInputData) { + inputData = (IdentityReleaseSpaceInputData) indata; + } else { + outputData.setStatus(CommandHelper.buildStatus( + TStatusCode.SRM_NOT_SUPPORTED, "Anonymous user can not perform" + + SRM_COMMAND)); + printRequestOutcome(outputData.getStatus(), + (ReleaseSpaceInputData) indata); + return outputData; + } + TReturnStatus returnStatus = null; + + if ((inputData == null) + || ((inputData != null) && (inputData.getSpaceToken() == null))) { + log.error("Empty space token."); + returnStatus = manageStatus(TStatusCode.SRM_INVALID_REQUEST, + "SpaceToken is empty."); + outputData.setStatus(returnStatus); + return outputData; + } + + GridUserInterface user = inputData.getUser(); + if (user == null) { + log.debug("Null user credentials."); + returnStatus = manageStatus(TStatusCode.SRM_AUTHENTICATION_FAILURE, + "Unable to get user credential"); + outputData.setStatus(returnStatus); + + log.error("srmReleaseSpace: <{}> Request for [spacetoken: {}] failed " + + "with: [status: {}]", user, inputData.getSpaceToken(), returnStatus); + + return outputData; + } + + boolean forceFileRelease = inputData.isForceFileRelease(); + boolean nopinned = true; + boolean failure = false; + String explanation = ""; + TStatusCode statusCode = null; + + StorageSpaceData data; + try { + data = catalog.getStorageSpace(inputData.getSpaceToken()); + } catch (Throwable e) { + log.error("Error fetching data for space token {}. {}", + inputData.getSpaceToken(), e.getMessage(), e); + + failure = true; + explanation = "Error building space data from row DB data."; + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + returnStatus = manageStatus(statusCode, explanation); + outputData.setStatus(returnStatus); + + log.error("srmReleaseSpace: <{}> Request for [spacetoken: {}] failed " + + "with: [status: {}]", user, inputData.getSpaceToken(), returnStatus); + + return outputData; + } + + if (data == null) { + failure = true; + explanation = "SpaceToken does not refers to an existing space."; + statusCode = TStatusCode.SRM_INVALID_REQUEST; + returnStatus = manageStatus(statusCode, explanation); + outputData.setStatus(returnStatus); + + log.error("srmReleaseSpace: <{}> Request for [spacetoken: {}] failed " + + "with: [status: {}]", user, inputData.getSpaceToken(), returnStatus); + + return outputData; + } + + if (!forceFileRelease) { + nopinned = true; + } + + if ((forceFileRelease) || (nopinned)) { + + if (data.getOwner().getDn().equals(user.getDn())) { + + log.debug("Authorized Release Space for user: {}", data.getOwner()); + returnStatus = manageAuthorizedReleaseSpace(data, user); + + } else { + + log.debug("User {} not authorized to release space.", data.getOwner()); + failure = true; + explanation = "User is not authorized to release this token"; + statusCode = TStatusCode.SRM_AUTHORIZATION_FAILURE; + returnStatus = manageStatus(statusCode, explanation); + } + + } else { + log.debug("Space contains pinned files."); + failure = true; + explanation = "Space still contains pinned files. "; + statusCode = TStatusCode.SRM_FAILURE; + returnStatus = manageStatus(statusCode, explanation); + } + + outputData.setStatus(returnStatus); + + if (returnStatus.isSRM_SUCCESS()) { + + log.error("srmReleaseSpace: <{}> Request for [spacetoken: {}] succesfully done " + + "with: [status: {}]", user, inputData.getSpaceToken(), returnStatus); + + } else { + + log.error("srmReleaseSpace: <" + user + "> Request for [spacetoken:" + + inputData.getSpaceToken() + "] for failed with: [status:" + + returnStatus + "]"); + + } + + return outputData; + } + + /** + * + * @param user + * GridUserInterface + * @param data + * StorageSpaceData + * @return TReturnStatus + */ + private TReturnStatus manageAuthorizedReleaseSpace(StorageSpaceData data, + GridUserInterface user) { + + String spaceFileName; + PFN pfn = data.getSpaceFileName(); + + if (pfn != null) { + spaceFileName = pfn.getValue(); + log.debug("spaceFileName: {}", spaceFileName); + File spaceFile = new File(spaceFileName); + if (spaceFile.delete()) { + if (catalog.release(user, data.getSpaceToken())) { + return manageStatus(TStatusCode.SRM_SUCCESS, "Space Released."); + } else { + return manageStatus(TStatusCode.SRM_INTERNAL_ERROR, + "Space removed, but spaceToken was not found in the DB"); + } + } else { + return manageStatus(TStatusCode.SRM_FAILURE, + "Space can not be removed by StoRM!"); + } + } else { + return manageStatus(TStatusCode.SRM_FAILURE, "SRM Internal failure."); + } + } + + /** + * + * @param statusCode + * statusCode + * @param explanation + * explanation string + * @return returnStatus returnStatus + */ + private TReturnStatus manageStatus(TStatusCode statusCode, String explanation) { + + TReturnStatus returnStatus = null; + try { + returnStatus = new TReturnStatus(statusCode, explanation); + } catch (InvalidTReturnStatusAttributeException ex1) { + log.error(ex1.getMessage(), ex1); + } + return returnStatus; + } + + private void printRequestOutcome(TReturnStatus status, + ReleaseSpaceInputData indata) { + + if (indata != null) { + CommandHelper.printRequestOutcome(SRM_COMMAND, log, status, indata); + } else { + CommandHelper.printRequestOutcome(SRM_COMMAND, log, status); + } + } } diff --git a/src/main/java/it/grid/storm/synchcall/command/space/ReserveSpaceCommand.java b/src/main/java/it/grid/storm/synchcall/command/space/ReserveSpaceCommand.java index d73e2cdb..d8faa95c 100644 --- a/src/main/java/it/grid/storm/synchcall/command/space/ReserveSpaceCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/space/ReserveSpaceCommand.java @@ -80,1144 +80,1017 @@ */ public class ReserveSpaceCommand extends SpaceCommand implements Command { - private ReservedSpaceCatalog catalog; - private static final Logger log = LoggerFactory - .getLogger(ReserveSpaceCommand.class); - private NamespaceInterface namespace; - - private static final boolean SUCCESS = true; - private static final boolean FAILURE = false; - private static final String SRM_COMMAND = "srmReserveSpace"; - - TStatusCode statusCode = TStatusCode.EMPTY; - String explanation = null; - - private String formatLogMessage(boolean success, GridUserInterface user, - TSizeInBytes desSize, TSizeInBytes guarSize, TLifeTimeInSeconds lifetime, - TRetentionPolicyInfo rpinfo, TStatusCode code, String expl) { - - TReturnStatus status = null; - try { - status = new TReturnStatus(code, expl); - } catch (InvalidTReturnStatusAttributeException e) { - log.error(e.getMessage()); - } - return formatLogMessage(success, user, desSize, guarSize, lifetime, rpinfo, - status); - } - - private String formatLogMessage(boolean success, GridUserInterface user, - TSizeInBytes desSize, TSizeInBytes guarSize, TLifeTimeInSeconds lifetime, - TRetentionPolicyInfo rpinfo, TReturnStatus status) { - - StringBuffer buf = new StringBuffer("srmReserveSpace: "); - buf.append("<" + user + "> "); - buf.append("Request for ["); - buf.append("desiredSizeOfTotalSpace: " + desSize); - buf.append(", desiredSizeOfGuaranteedSpace: " + guarSize); - buf.append("] "); - buf.append("with [desiredLifetimeOfReservedSpace: " + lifetime + "] "); - buf.append("with [retentionPolicyInfo: " + rpinfo + "] "); - - if (success) { - buf.append("successfully done with:[status:"); - } else { - buf.append("failed with:[status:"); - } - - buf.append(status); - - buf.append("]"); - - return buf.toString(); - - } - - public ReserveSpaceCommand() { - - namespace = NamespaceDirector.getNamespace(); - catalog = new ReservedSpaceCatalog(); - } - - /** - * Method that provide space reservation for srmReserveSpace request. - * - * @param data - * Contain information about data procived in SRM request. - * @return SpaceResOutputData that contain all SRM return parameter. - * @todo Implement this it.grid.storm.synchcall.space.SpaceManager method - */ - public OutputData execute(InputData indata) { - - IdentityReserveSpaceInputData data; - if (indata instanceof IdentityInputData) { - data = (IdentityReserveSpaceInputData) indata; - } else { - GetSpaceMetaDataOutputData outputData = new GetSpaceMetaDataOutputData(); - outputData.setStatus(CommandHelper.buildStatus( - TStatusCode.SRM_NOT_SUPPORTED, "Anonymous user can not perform" - + SRM_COMMAND)); - printRequestOutcome(outputData.getStatus(), - (ReserveSpaceInputData) indata); - return outputData; - } - log.debug(":reserveSpace start."); - - if (!checkParameters(data)) { - return manageError(statusCode, explanation); - } - - String spaceFN = null; - try { - spaceFN = getSpaceFN(data.getUser()); - } catch (Exception e) { - log.error(formatLogMessage(FAILURE, data.getUser(), - data.getDesiredSize(), data.getGuaranteedSize(), - data.getSpaceLifetime(), data.getRetentionPolicyInfo(), statusCode, - explanation)); - return manageError(statusCode, explanation); - } - - VirtualFSInterface vfs = null; - try { - vfs = getSpaceVFS(spaceFN); - } catch (Exception e) { - log.error(formatLogMessage(FAILURE, data.getUser(), - data.getDesiredSize(), data.getGuaranteedSize(), - data.getSpaceLifetime(), data.getRetentionPolicyInfo(), statusCode, - explanation)); - return manageError(statusCode, explanation); - } - - setDefaults(data, vfs); - - String relativeSpaceFN = null; - try { - relativeSpaceFN = getRelativeSpaceFilePath(vfs, spaceFN); - } catch (Exception e) { - log.error(formatLogMessage(FAILURE, data.getUser(), - data.getDesiredSize(), data.getGuaranteedSize(), - data.getSpaceLifetime(), data.getRetentionPolicyInfo(), statusCode, - explanation)); - return manageError(statusCode, explanation); - } - - SpaceSize spaceSize = null; - try { - spaceSize = computeSpaceSize(data.getDesiredSize(), - data.getGuaranteedSize(), vfs); - } catch (Exception e) { - log.error(formatLogMessage(FAILURE, data.getUser(), - data.getDesiredSize(), data.getGuaranteedSize(), - data.getSpaceLifetime(), data.getRetentionPolicyInfo(), statusCode, - explanation)); - return manageError(statusCode, explanation); - } - - StoRI spaceStori = null; - try { - spaceStori = getSpaceStoRI(vfs, relativeSpaceFN, - spaceSize.getDesiderataSpaceSize()); - } catch (Exception e) { - log.error(formatLogMessage(FAILURE, data.getUser(), - data.getDesiredSize(), data.getGuaranteedSize(), - data.getSpaceLifetime(), data.getRetentionPolicyInfo(), statusCode, - explanation)); - return manageError(statusCode, explanation); - } - - log.debug("Reserve Space File Size :" - + spaceSize.getDesiderataSpaceSize().toString()); - try { - /* - * here the file is created, (note that since there is no chance to space - * is reserved) reclaim allocated space from gpfs, space is never - * allocated!) errors from here on must revert this operation - */ - spaceStori.getSpace().fakeAllot(); - } catch (ReservationException e) { - log.debug("Space reservation fail at FS level" + e); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to create Space File into filesystem. \n"; - log.error(formatLogMessage(FAILURE, data.getUser(), - data.getDesiredSize(), data.getGuaranteedSize(), - data.getSpaceLifetime(), data.getRetentionPolicyInfo(), statusCode, - explanation)); - return manageError(statusCode, explanation); - } - - try { - setSpaceFilePermissions(spaceStori, data.getUser()); - } catch (Exception e) { - log.error(formatLogMessage(FAILURE, data.getUser(), - data.getDesiredSize(), data.getGuaranteedSize(), - data.getSpaceLifetime(), data.getRetentionPolicyInfo(), statusCode, - explanation)); - revertAllocation(spaceStori.getSpace()); - return manageError(statusCode, explanation); - } - - TSpaceToken spaceToken = null; - try { - spaceToken = registerIntoDB(data.getUser(), data.getSpaceTokenAlias(), - spaceSize.getTotalSize(), spaceSize.getDesiderataSpaceSize(), - data.getSpaceLifetime(), spaceStori.getPFN()); - } catch (Exception e) { - log.error(formatLogMessage(FAILURE, data.getUser(), - data.getDesiredSize(), data.getGuaranteedSize(), - data.getSpaceLifetime(), data.getRetentionPolicyInfo(), statusCode, - explanation)); - revertAllocation(spaceStori.getSpace()); - return manageError(statusCode, explanation); - } - - ReserveSpaceOutputData output = null; - try { - output = buildOutput(spaceSize, spaceToken, data.getSpaceLifetime()); - log.info(formatLogMessage(SUCCESS, data.getUser(), data.getDesiredSize(), - data.getGuaranteedSize(), data.getSpaceLifetime(), - data.getRetentionPolicyInfo(), output.getStatus())); - } catch (Exception e) { - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to build a valid output object "; - log.error(formatLogMessage(FAILURE, data.getUser(), - data.getDesiredSize(), data.getGuaranteedSize(), - data.getSpaceLifetime(), data.getRetentionPolicyInfo(), statusCode, - explanation)); - revertAllocation(spaceStori.getSpace()); - return manageError(statusCode, explanation); - } - return output; - } - - private void revertAllocation(Space space) { - - try { - space.fakeRelease(); - } catch (ReservationException e) { - log.error("Error releasing space: ReservationException" + e.getMessage()); - } - } - - private StoRI getSpaceStoRI(VirtualFSInterface vfs, String relativeSpaceFN, - TSizeInBytes desiderataSpaceSize) throws Exception { - - StoRI spaceFile = null; - try { - spaceFile = vfs.createSpace(relativeSpaceFN, desiderataSpaceSize.value()); - } catch (NamespaceException e) { - log.debug("Unable to create Space File in VFS ", e); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to create Space File in VFS \n" + e; - throw new Exception(explanation); - } - return spaceFile; - } - - private boolean checkParameters(IdentityReserveSpaceInputData data) { - - if (data == null) { - explanation = "Invalid Parameter specified"; - statusCode = TStatusCode.SRM_FAILURE; - log.error(formatLogMessage(FAILURE, null, null, null, null, null, - statusCode, explanation)); - return false; - } - - if (data.getUser() == null) { - log.error("SpaceRes: Unable to get user credential. "); - statusCode = TStatusCode.SRM_AUTHENTICATION_FAILURE; - explanation = "Unable to get user credential!"; - log.error(formatLogMessage(FAILURE, null, data.getDesiredSize(), - data.getGuaranteedSize(), data.getSpaceLifetime(), - data.getRetentionPolicyInfo(), statusCode, explanation)); - return false; - } - - if (data.getRetentionPolicyInfo() == null) { - log - .debug("SpaceRes: Invalid request, null TRetentionPolicyInfo specified"); - statusCode = TStatusCode.SRM_INVALID_REQUEST; - explanation = "RetentionPolicy not specified."; - log.error(formatLogMessage(FAILURE, data.getUser(), - data.getDesiredSize(), data.getGuaranteedSize(), - data.getSpaceLifetime(), data.getRetentionPolicyInfo(), statusCode, - explanation)); - return false; - } - - TAccessLatency latency = data.getRetentionPolicyInfo().getAccessLatency(); - TRetentionPolicy retentionPolicy = data.getRetentionPolicyInfo() - .getRetentionPolicy(); - if (!((latency == null || latency.equals(TAccessLatency.EMPTY) || latency - .equals(TAccessLatency.ONLINE)) && (retentionPolicy == null - || retentionPolicy.equals(TRetentionPolicy.EMPTY) || retentionPolicy - .equals(TRetentionPolicy.REPLICA)))) { - log.debug("SpaceRes: Invalid TRetentionPolicyInfo specified: " - + data.getRetentionPolicyInfo().getAccessLatency().toString() + "," - + (data.getRetentionPolicyInfo().getRetentionPolicy().toString())); - statusCode = TStatusCode.SRM_NOT_SUPPORTED; - explanation = "RetentionPolicy requested cannot be satisfied."; - log.error(formatLogMessage(FAILURE, data.getUser(), - data.getDesiredSize(), data.getGuaranteedSize(), - data.getSpaceLifetime(), data.getRetentionPolicyInfo(), statusCode, - explanation)); - return false; - } - return true; - } - - private String getSpaceFN(GridUserInterface user) throws Exception { - - String spaceFN = null; - try { - spaceFN = namespace.makeSpaceFileURI(user); - log.debug(" Space FN : " + spaceFN); - } catch (NamespaceException ex) { - log.error("Unable to build default Space FN ", ex); - statusCode = TStatusCode.SRM_INVALID_REQUEST; - explanation = "Unable to build default Space FN \n" + ex; - throw new Exception(explanation); - } - return spaceFN; - } - - private VirtualFSInterface getSpaceVFS(String spaceFN) throws Exception { - - VirtualFSInterface vfs = null; - try { - vfs = namespace.resolveVFSbyAbsolutePath(spaceFN); - log.debug("Space File belongs to VFS : " + vfs.getAliasName()); - } catch (NamespaceException ex2) { - log.debug("Unable to resolve VFS ", ex2); - statusCode = TStatusCode.SRM_INVALID_REQUEST; - explanation = "Unable to resolve VFS \n" + ex2; - throw new Exception(explanation); - } - - return vfs; - } - - private void setDefaults(IdentityReserveSpaceInputData data, - VirtualFSInterface vfs) { - - if (data.getRetentionPolicyInfo().getAccessLatency() == null - || data.getRetentionPolicyInfo().getAccessLatency() - .equals(TAccessLatency.EMPTY)) { - data.getRetentionPolicyInfo().setAccessLatency(TAccessLatency.ONLINE); - } - if (data.getRetentionPolicyInfo().getRetentionPolicy() == null - || data.getRetentionPolicyInfo().getRetentionPolicy() - .equals(TRetentionPolicy.EMPTY)) { - data.getRetentionPolicyInfo() - .setRetentionPolicy(TRetentionPolicy.REPLICA); - } - if (data.getSpaceLifetime().isEmpty()) { - log.debug("LifeTime is EMPTY. Using default value."); - data.setSpaceLifetime(vfs.getDefaultValues().getDefaultSpaceLifetime()); - } - } - - private SpaceSize computeSpaceSize(TSizeInBytes totalSize, - TSizeInBytes guarSize, VirtualFSInterface vfs) throws Exception { - - // ************ RETRIEVE THE SIZEs OF SPACE ******************** - TSizeInBytes desiderataSpaceSize = TSizeInBytes.makeEmpty(); - - // Malformed request check: if totalSize and guaranteedSize are used - // defined - // and guaranteedSize > totalSize we consider the request as malformed - if ((!(totalSize.isEmpty())) - && (!((guarSize.isEmpty()) || guarSize.value() == 0))) { - if (totalSize.value() < guarSize.value()) { - log.debug("Error: totalSize < guaranteedSize"); - statusCode = TStatusCode.SRM_INVALID_REQUEST; - explanation = "Error: totalSize can not be greater then guaranteedSize"; - throw new Exception(explanation); - } - } else { // Assign default values if totalSize and guaranteedSize are - // not defined - if (!(totalSize.isEmpty())) { - guarSize = vfs.getDefaultValues().getDefaultGuaranteedSpaceSize(); - if (totalSize.value() < guarSize.value()) { - guarSize = totalSize; - } - } else { - if (!((guarSize.isEmpty()) || guarSize.value() == 0)) { - totalSize = vfs.getDefaultValues().getDefaultTotalSpaceSize(); - if (totalSize.value() < guarSize.value()) { - totalSize = guarSize; - log.debug("GuaranteedSize greater than default total size!"); - } - } else { - totalSize = vfs.getDefaultValues().getDefaultTotalSpaceSize(); - guarSize = vfs.getDefaultValues().getDefaultGuaranteedSpaceSize(); - // totalSize must be greater than guaranteedSize the following - // check is to be sure - // that the default parameters are correctly set. - if (totalSize.value() < guarSize.value()) { - totalSize = guarSize; - } - } - } - } - - log.debug("Parameter parsing end"); - /* - * At this point either totalSize and guarSize contains significative value. - * desiderataSpaceSize is setted to totalSize. - */ - desiderataSpaceSize = totalSize; - // This is valid because StoRM only reserve GUARANTEED space. - guarSize = desiderataSpaceSize; - - TSizeInBytes freeSpace = null; - try { - freeSpace = TSizeInBytes.make(vfs.getFilesystem().getFreeSpace(), - SizeUnit.BYTES); - } catch (InvalidTSizeAttributesException e) { - log - .debug("Error while retrieving free Space in underlying Filesystem", e); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Error while retrieving free Space in underlying Filesystem \n" - + e; - throw new Exception(explanation); - } catch (NamespaceException ex) { - log - .debug( - "Error while retrieving free Space in underlying Filesystem. Unable to retrieve FS Driver", - ex); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Error while retrieving free Space in underlying Filesystem. Unable to retrieve FS Driver \n" - + ex; - throw new Exception(explanation); - } - - /** - * @todo Change here, also granted SpaceSize must be considered. - */ - boolean lower_space = false; - // If there is not enogh free space on storage - if (freeSpace.value() < desiderataSpaceSize.value()) { - if (freeSpace.value() < guarSize.value()) { - // Not enough freespace - log - .debug(":reserveSpace Not Enough Free Space on storage!"); - statusCode = TStatusCode.SRM_NO_FREE_SPACE; - explanation = "SRM has not more free space."; - throw new Exception(explanation); - } else { - // Enough free space to reserve granted space asked. - desiderataSpaceSize = guarSize; - lower_space = true; - } - } - return this.new SpaceSize(desiderataSpaceSize, totalSize, lower_space); - } - - private String getRelativeSpaceFilePath(VirtualFSInterface vfs, String spaceFN) - throws Exception { - - String relativeSpaceFN = null; - - log.debug("ExtraceRelativeSpace: root:" + vfs.getRootPath() + " spaceFN:" - + spaceFN); - relativeSpaceFN = NamespaceUtil.extractRelativePath(vfs.getRootPath(), - spaceFN); - log.debug("relativeSpaceFN:" + relativeSpaceFN); - - return relativeSpaceFN; - } - - private void setSpaceFilePermissions(StoRI spaceStori, GridUserInterface user) - throws Exception { - - FilesystemPermission fp = FilesystemPermission.ReadWrite; - - AclManager manager = AclManagerFSAndHTTPS.getInstance(); - LocalFile localFile = spaceStori.getLocalFile(); - LocalUser localUser; - try { - localUser = user.getLocalUser(); - } catch (CannotMapUserException e) { - log.debug("Unable to setting up the ACL ", e); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to setting up the ACL "; - throw new Exception(explanation); - } - if (localFile == null || localUser == null) { - log.warn("Unable to setting up the ACL. Null value/s : LocalFile " - + localFile + " , localUser " + localUser); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to setting up the ACL "; - throw new Exception(explanation); - } - if (spaceStori.hasJustInTimeACLs()) { - // JiT Case - log.debug(":reserveSpace AddACL for FIle: " - + spaceStori.getPFN() + " " + "USER RW"); - try { - manager.grantUserPermission(localFile, localUser, fp); - } catch (IllegalArgumentException e) { - log - .error("Unable to grant user permission on space file. IllegalArgumentException: " - + e.getMessage()); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to grant group permission on space file "; - throw new Exception(explanation); - } - } else { - // AoT Case - log.debug(":reserveSpace AddACL for FIle: " - + spaceStori.getPFN() + " " + "GROUP RW"); - try { - manager.grantGroupPermission(localFile, localUser, fp); - } catch (IllegalArgumentException e) { - log - .error("Unable to grant group permission on the space file. IllegalArgumentException: " - + e.getMessage()); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to setting up the ACL "; - throw new Exception(explanation); - } - } - } - - private TSpaceToken registerIntoDB(GridUserInterface user, - String spaceTokenAlias, TSizeInBytes totalSize, - TSizeInBytes desiderataSpaceSize, TLifeTimeInSeconds lifeTime, PFN pfn) - throws Exception { - - log.debug("-- Creating Storage Space Data ..."); - StorageSpaceData spaceData = null; - try { - // passing null TStorageSystemInfo, is not used even when added to the DB - spaceData = new StorageSpaceData(user, TSpaceType.PERMANENT, - spaceTokenAlias, totalSize, desiderataSpaceSize, lifeTime, null, - new Date(), pfn); - } catch (InvalidSpaceDataAttributesException e) { - log.debug("Unable to create Storage Space Data", e); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to create storage space data."; - log.error(formatLogMessage(FAILURE, user, totalSize, desiderataSpaceSize, - lifeTime, null, statusCode, explanation)); - throw new Exception(explanation); - } - - spaceData.setUsedSpaceSize(TSizeInBytes.make(0, SizeUnit.BYTES)); - spaceData.setUnavailableSpaceSize(TSizeInBytes.make(0, SizeUnit.BYTES)); - spaceData.setReservedSpaceSize(desiderataSpaceSize); - - log.debug("Created space data: " + spaceData.toString()); - try { - catalog.addStorageSpace(spaceData); - } catch (DataAccessException e) { - log.debug("Unable to register Storage Space Data into DB", e); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to register Storage Space Data into DB."; - log.error(formatLogMessage(FAILURE, user, totalSize, desiderataSpaceSize, - lifeTime, null, statusCode, explanation)); - throw new Exception(explanation); - } - - TSpaceToken spaceToken = null; - try { - spaceToken = TSpaceToken.make(spaceData.getSpaceToken().toString()); - } catch (InvalidTSpaceTokenAttributesException e) { - log.debug("Error creating Space Token . Critical error!" + e); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to create space token."; - log.error(formatLogMessage(FAILURE, user, totalSize, desiderataSpaceSize, - lifeTime, null, statusCode, explanation)); - throw new Exception(explanation); - } - return spaceToken; - } - - private ReserveSpaceOutputData buildOutput(SpaceSize spaceSize, - TSpaceToken spaceToken, TLifeTimeInSeconds lifeTime) throws Exception { - - TReturnStatus status = null; - try { - if (!spaceSize.isLowerSpace()) { - status = new TReturnStatus(TStatusCode.SRM_SUCCESS, - "Space Reservation done"); - - } else { - status = new TReturnStatus(TStatusCode.SRM_LOWER_SPACE_GRANTED, - "Space Reservation done, lower space granted."); - } - } catch (InvalidTReturnStatusAttributeException e) { - log.debug("InvalidTReturnStatusAttributeException", e); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to build a valid return status "; - throw new Exception(explanation); - } - - ReserveSpaceOutputData outputData = null; - try { - outputData = new ReserveSpaceOutputData(spaceSize.getTotalSize(), - spaceSize.getDesiderataSpaceSize(), lifeTime, spaceToken, status); - } catch (InvalidReserveSpaceOutputDataAttributesException ex11) { - log.error("Error creating Output DATA . Critical error!" + ex11); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to build a valid return output object "; - throw new Exception(explanation); - } - return outputData; - } - - private class SpaceSize { - - private final TSizeInBytes desiderataSpaceSize; - private final TSizeInBytes totalSize; - private final boolean lowerSpace; - - public SpaceSize(TSizeInBytes desiderataSpaceSize, TSizeInBytes totalSize, - boolean lowerSpace) { - - this.desiderataSpaceSize = desiderataSpaceSize; - this.totalSize = totalSize; - this.lowerSpace = lowerSpace; - } - - protected TSizeInBytes getDesiderataSpaceSize() { - - return desiderataSpaceSize; - } - - protected TSizeInBytes getTotalSize() { - - return totalSize; - } - - protected boolean isLowerSpace() { - - return lowerSpace; - } - } - - /** - * Method that reset an already done reservation to the original status. - * - * @param token - * TSpaceToken that contains information about data procived in SRM - * request. - * @return TReturnStatus that contains of all SRM return parameters. - */ - public TReturnStatus resetReservation(TSpaceToken token) { - - String explanation = null; - TStatusCode statusCode = TStatusCode.EMPTY; - - StorageSpaceData sdata; - try { - sdata = catalog.getStorageSpace(token); - } catch (TransferObjectDecodingException e) { - log - .error("Unable to build StorageSpaceData from StorageSpaceTO. TransferObjectDecodingException: " - + e.getMessage()); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Error building space data from row DB data\n" + e; - return manageErrorStatus(statusCode, explanation); - } catch (DataAccessException e) { - log.error("Unable to build get StorageSpaceTO. DataAccessException: " - + e.getMessage()); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Error retrieving row space token data from DB\n" + e; - return manageErrorStatus(statusCode, explanation); - } - - // Check if it a VO_SA_Token, in that case do nothing - if (sdata.getSpaceType().equals(TSpaceType.VOSPACE)) { - return manageErrorStatus(TStatusCode.SRM_SUCCESS, "Abort file done."); - } - - GridUserInterface user = sdata.getOwner(); - PFN spacePFN = sdata.getSpaceFileName(); - - // Obtain the PFN of the user-root directory. - - String spaceFN = null; - - spaceFN = spacePFN.toString(); - - VirtualFSInterface vfs = null; - try { - vfs = namespace.resolveVFSbyAbsolutePath(spaceFN); - log.debug("Space File belongs to VFS : " + vfs.getAliasName()); - } catch (NamespaceException ex2) { - log.debug("Unable to resolve VFS ", ex2); - statusCode = TStatusCode.SRM_INVALID_REQUEST; - explanation = "Unable to resolve VFS \n" + ex2; - return manageErrorStatus(statusCode, explanation); - } - - String relativeSpaceFN = null; - - log.debug("ExtractRelativeSpace: root:" + vfs.getRootPath() + " spaceFN:" - + spaceFN); - relativeSpaceFN = NamespaceUtil.extractRelativePath(vfs.getRootPath(), - spaceFN); - log.debug("relativeSpaceFN:" + relativeSpaceFN); - - // ************ RETRIEVE THE SIZEs OF SPACE from DB******************** - TSizeInBytes desiderataSpaceSize = sdata.getTotalSpaceSize(); - TSizeInBytes totalSize = sdata.getTotalSpaceSize(); - TSizeInBytes guarSize = sdata.getReservedSpaceSize(); - - /** - * Check free space on file system. - */ - - TSizeInBytes freeSpace; - try { - long bytesFree = vfs.getFilesystem().getFreeSpace(); - freeSpace = TSizeInBytes.make(bytesFree, SizeUnit.BYTES); - } catch (InvalidTSizeAttributesException e) { - log - .debug("Error while retrieving free Space in underlying Filesystem", e); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Error while retrieving free Space in underlying Filesystem \n" - + e; - return manageErrorStatus(statusCode, explanation); - } catch (NamespaceException ex) { - log - .debug( - "Error while retrieving free Space in underlying Filesystem. Unable to retrieve FS Driver", - ex); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Error while retrieving free Space in underlying Filesystem. Unable to retrieve FS Driver \n" - + ex; - return manageErrorStatus(statusCode, explanation); - } - - /* - * Start with the reservation - */ - boolean authorize = true; - - if (authorize) { - - // Call wrapper to reserve Space. - log.debug("reserve Space File Size :" + desiderataSpaceSize.toString()); - - StoRI spaceFile = null; - try { - spaceFile = vfs.createSpace(relativeSpaceFN, - desiderataSpaceSize.value()); - } catch (NamespaceException ex4) { - log.debug("Unable to create Space File in VFS ", ex4); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to create Space File in VFS \n" + ex4; - return manageErrorStatus(statusCode, explanation); - } - - // Create Space into FileSyste - try { - spaceFile.getSpace().allot(); - } catch (ReservationException e) { - log.debug("Space reservation fail at FS level" + e); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to create Space File into filesystem. \n"; - return manageErrorStatus(statusCode, explanation); - } - - // Call wrapper to set ACL on file created. - /** Check for JiT or AoT */ - boolean hasJiTACL = spaceFile.hasJustInTimeACLs(); - - FilesystemPermission fp = FilesystemPermission.ReadWrite; - - if (hasJiTACL) { - // JiT Case - log.debug(":reserveSpace AddACL for FIle: " + spacePFN - + " " + "USER RW"); - try { - AclManager manager = AclManagerFSAndHTTPS.getInstance(); - // TODO ACL manager - LocalFile localFile = spaceFile.getLocalFile(); - LocalUser localUser = user.getLocalUser(); - if (localFile == null || localUser == null) { - log.warn("Unable to setting up the ACL. Null value/s : LocalFile " - + localFile + " , localUser " + localUser); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to setting up the ACL "; - return manageErrorStatus(statusCode, explanation); - } else { - try { - manager.grantGroupPermission(localFile, localUser, fp); - } catch (IllegalArgumentException e) { - log - .error("Unable to grant group permission on space file. IllegalArgumentException: " - + e.getMessage()); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to grant group permission on space file "; - return manageErrorStatus(statusCode, explanation); - } - } - // spaceFile.getLocalFile().grantUserPermission( - // user.getLocalUser(), fp); - } catch (CannotMapUserException ex5) { - log.debug("Unable to setting up the ACL ", ex5); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to setting up the ACL "; - return manageErrorStatus(statusCode, explanation); - } - } else { - // AoT Case - log.debug(":reserveSpace AddACL for FIle: " + spacePFN - + " " + "GROUP RW"); - try { - AclManager manager = AclManagerFSAndHTTPS.getInstance(); - // TODO ACL manager - LocalFile localFile = spaceFile.getLocalFile(); - LocalUser localUser = user.getLocalUser(); - if (localFile == null || localUser == null) { - log.warn("Unable to setting up the ACL. Null value/s : LocalFile " - + localFile + " , localUser " + localUser); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to setting up the ACL "; - return manageErrorStatus(statusCode, explanation); - } else { - try { - manager.grantGroupPermission(localFile, localUser, fp); - } catch (IllegalArgumentException e) { - log - .error("Unable to grant group permission on space file. IllegalArgumentException: " - + e.getMessage()); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to grant group permission on space file "; - return manageErrorStatus(statusCode, explanation); - } - } - // spaceFile.getLocalFile().grantGroupPermission( - // user.getLocalUser(), fp); - } catch (CannotMapUserException ex5) { - log.debug("Unable to setting up the ACL ", ex5); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to setting up the ACL "; - return manageErrorStatus(statusCode, explanation); - } - } - - } - - /* - * Update data into DB - */ - // sdata.setSpaceFileName(spacePFN); - sdata.setUsedSpaceSize(desiderataSpaceSize); - - // UpdateData into the ReserveSpaceCatalog - try { - catalog.updateStorageSpaceFreeSpace(sdata); - } catch (DataAccessException e) { - log - .error("Unable to persist the space reservation into the DB. DataAccessException: " - + e.getMessage()); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Error persisting space token data into the DB\n" - + e.getMessage(); - return manageErrorStatus(statusCode, explanation); - } - - return manageErrorStatus(TStatusCode.SRM_SUCCESS, "Successfull creation."); - } - - /** - * Method that update an already done reservation. - * - * @param data - * Contain information about data procvided in a SRM request. - * @return SpaceResOutputData that contain all SRM return parameter. - */ - - public TReturnStatus updateReservation(TSpaceToken token, - TSizeInBytes sizeToAdd, TSURL toSurl) { - - String explanation = null; - TStatusCode statusCode = TStatusCode.EMPTY; - - StorageSpaceData sdata; - try { - sdata = catalog.getStorageSpace(token); - } catch (TransferObjectDecodingException e) { - log - .error("Unable to build StorageSpaceData from StorageSpaceTO. TransferObjectDecodingException: " - + e.getMessage()); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Error building space data from row DB data\n" + e; - return manageErrorStatus(statusCode, explanation); - } catch (DataAccessException e) { - log.error("Unable to build get StorageSpaceTO. DataAccessException: " - + e.getMessage()); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Error retrieving row space token data from DB\n" + e; - return manageErrorStatus(statusCode, explanation); - } - GridUserInterface user = sdata.getOwner(); - PFN spacePFN = sdata.getSpaceFileName(); - - // Check if it a VO_SA_Token, in that case do nothing - if (sdata.getSpaceType().equals(TSpaceType.VOSPACE)) { - return manageErrorStatus(TStatusCode.SRM_SUCCESS, "Abort file done."); - } - - /** - * Verification of the free Space available in file system - */ - - // Obtain the PFN of the user-root directory. - String spaceFN = null; - - spaceFN = spacePFN.toString(); - - VirtualFSInterface vfs = null; - try { - vfs = namespace.resolveVFSbyAbsolutePath(spaceFN); - log.debug("Space File belongs to VFS : " + vfs.getAliasName()); - } catch (NamespaceException ex2) { - log.debug("Unable to resolve VFS ", ex2); - statusCode = TStatusCode.SRM_INVALID_REQUEST; - explanation = "Unable to resolve VFS \n" + ex2; - return manageErrorStatus(statusCode, explanation); - } - - String relativeSpaceFN = null; - - log.debug("ExtractRelativeSpace: root:" + vfs.getRootPath() + " spaceFN:" - + spaceFN); - relativeSpaceFN = NamespaceUtil.extractRelativePath(vfs.getRootPath(), - spaceFN); - log.debug("relativeSpaceFN:" + relativeSpaceFN); - - // ************ RETRIEVE THE SIZEs OF SPACE from DB******************** - TSizeInBytes desiderataSpaceSize = sdata.getTotalSpaceSize(); - TSizeInBytes availableSize = sdata.getAvailableSpaceSize(); - - log.debug("available Size : " + availableSize.value()); - log.debug("Size of removed file: " + sizeToAdd.value()); - - /** - * Add to the desiderata size the bytes freed from the abort - */ - try { - desiderataSpaceSize = TSizeInBytes.make( - availableSize.value() + sizeToAdd.value(), SizeUnit.BYTES); - } catch (InvalidTSizeAttributesException e1) { - log.error(e1.getMessage()); - } - - /* - * Start with the reservation - */ - // Call wrapper to reserve Space. - log.debug("reserve Space File Size :" + desiderataSpaceSize.toString()); - - StoRI spaceFile = null; - try { - spaceFile = vfs.createSpace(relativeSpaceFN, desiderataSpaceSize.value()); - } catch (NamespaceException ex4) { - log.debug("Unable to create Space File in VFS ", ex4); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to create Space File in VFS \n" + ex4; - return manageErrorStatus(statusCode, explanation); - } - - // Remove the old spaceFile with not updated size - LocalFile localFile = spaceFile.getLocalFile(); - - if (localFile != null) { - // Old spaceFile with wrong chunk - localFile.delete(); - } else { - // spaceFile does not exist yet - } - - // Create Space into FileSyste - try { - spaceFile.getSpace().allot(); - } catch (ReservationException e) { - log.debug("Space reservation fail at FS level" + e); - revertOldSpaceFileDeletion(localFile); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to create Space File into filesystem. \n"; - return manageErrorStatus(statusCode, explanation); - } - - // Call wrapper to set ACL on file created. - /** Check for JiT or AoT */ - boolean hasJiTACL = spaceFile.hasJustInTimeACLs(); - - FilesystemPermission fp = FilesystemPermission.ReadWrite; - - if (hasJiTACL) { - // JiT Case - log.debug(":reserveSpace AddACL for FIle: " + spacePFN - + " " + "USER RW"); - try { - AclManager manager = AclManagerFSAndHTTPS.getInstance(); - // TODO ACL manager - localFile = spaceFile.getLocalFile(); - LocalUser localUser = user.getLocalUser(); - if (localFile == null || localUser == null) { - log.warn("Unable to setting up the ACL. Null value/s : LocalFile " - + localFile + " , localUser " + localUser); - revertOldSpaceFileDeletion(localFile); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to setting up the ACL "; - return manageErrorStatus(statusCode, explanation); - } else { - try { - manager.grantGroupPermission(localFile, localUser, fp); - } catch (IllegalArgumentException e) { - log - .error("Unable to grant group permission on space file. IllegalArgumentException: " - + e.getMessage()); - revertOldSpaceFileDeletion(localFile); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to grant group permission on space file "; - return manageErrorStatus(statusCode, explanation); - } - } - } catch (CannotMapUserException ex5) { - log.debug("Unable to setting up the ACL ", ex5); - revertOldSpaceFileDeletion(localFile); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to setting up the ACL "; - return manageErrorStatus(statusCode, explanation); - } - } else { - // AoT Case - log.debug(":reserveSpace AddACL for FIle: " + spacePFN - + " " + "GROUP RW"); - try { - AclManager manager = AclManagerFSAndHTTPS.getInstance(); - // TODO ACL manager - localFile = spaceFile.getLocalFile(); - LocalUser localUser = user.getLocalUser(); - if (localFile == null || localUser == null) { - log.warn("Unable to setting up the ACL. Null value/s : LocalFile " - + localFile + " , localUser " + localUser); - revertOldSpaceFileDeletion(localFile); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to setting up the ACL "; - return manageErrorStatus(statusCode, explanation); - } else { - try { - manager.grantGroupPermission(spaceFile.getLocalFile(), localUser, - fp); - } catch (IllegalArgumentException e) { - log - .error("Unable to grant group permission on space file. IllegalArgumentException: " - + e.getMessage()); - revertOldSpaceFileDeletion(localFile); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to grant group permission on space file "; - return manageErrorStatus(statusCode, explanation); - } - } - } catch (CannotMapUserException ex5) { - log.debug("Unable to setting up the ACL ", ex5); - revertOldSpaceFileDeletion(localFile); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Unable to setting up the ACL "; - return manageErrorStatus(statusCode, explanation); - } - } - - /* - * Update data into DB - */ - - /* - * TODO Update the StorageFile information related to the removed chunk. The - * SURL has been associated during the Put operation to the SpaceFile, due - * to an abort operation the SURL must be removed from the StorageFile - * relation, and the size of the spaceFile have to be updated. - */ - // - try { - availableSize = TSizeInBytes.make(sdata.getAvailableSpaceSize().value() - + sizeToAdd.value(), SizeUnit.BYTES); - } catch (InvalidTSizeAttributesException e) { - log - .error("Unable to compute new available space size. InvalidTSizeAttributesException: " - + e.getMessage()); - revertOldSpaceFileDeletion(localFile); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Error computing new available space size\n" - + e.getMessage(); - return manageErrorStatus(statusCode, explanation); - } - // Update the free bytes! - sdata.forceAvailableSpaceSize(availableSize); - - // UpdateData into the ReserveSpaceCatalog - try { - catalog.updateStorageSpaceFreeSpace(sdata); - } catch (DataAccessException e) { - log - .error("Unable to persist the space reservation into the DB. DataAccessException: " - + e.getMessage()); - revertOldSpaceFileDeletion(localFile); - statusCode = TStatusCode.SRM_INTERNAL_ERROR; - explanation = "Error persisting space token data into the DB\n" - + e.getMessage(); - return manageErrorStatus(statusCode, explanation); - } - return manageErrorStatus(TStatusCode.SRM_SUCCESS, "Successfull creation."); - } - - private void revertOldSpaceFileDeletion(LocalFile localFile) { - - // TODO Implement this method - } - - /** - * This function is use to create update data in case of various kind of - * error. - * - * @param statusCode - * TStatusCode - * @param explanation - * String - * @return outputData SpaceResOutputData - */ - - private ReserveSpaceOutputData manageError(TStatusCode statusCode, - String explanation) { - - TReturnStatus status = null; - try { - status = new TReturnStatus(statusCode, explanation); - } catch (InvalidTReturnStatusAttributeException ex1) { - log.warn("SpaceManger: Error creating returnStatus " + ex1); - } - - return new ReserveSpaceOutputData(status); - } - - private TReturnStatus manageErrorStatus(TStatusCode statusCode, - String explanation) { - - TReturnStatus status = null; - try { - status = new TReturnStatus(statusCode, explanation); - } catch (InvalidTReturnStatusAttributeException ex1) { - log.warn("SpaceManger: Error creating returnStatus " + ex1); - } - return status; - } - - private void printRequestOutcome(TReturnStatus status, - ReserveSpaceInputData data) { - - if (data != null) { - CommandHelper.printRequestOutcome(SRM_COMMAND, log, status, data); - } else { - CommandHelper.printRequestOutcome(SRM_COMMAND, log, status); - } - } + private ReservedSpaceCatalog catalog; + + private static final Logger log = LoggerFactory + .getLogger(ReserveSpaceCommand.class); + + private NamespaceInterface namespace; + + private static final boolean SUCCESS = true; + private static final boolean FAILURE = false; + private static final String SRM_COMMAND = "srmReserveSpace"; + + TStatusCode statusCode = TStatusCode.EMPTY; + String explanation = null; + + private void logRequestSuccess(GridUserInterface user, TSizeInBytes desSize, + TSizeInBytes guarSize, TLifeTimeInSeconds lifetime, + TRetentionPolicyInfo rpinfo, TReturnStatus status) { + + log.info("srmReservespace: <{}> Request for [desiredSizeOfTotalSpace: {}," + + " desiredSizeOfGuaranteedSpace: {}] with " + + "[desiredLifetimeOfReservedSpace: {}, retentionPolicyInfo: {}]" + + "succesfully done with: [status: {}]", user, desSize, guarSize, + lifetime, rpinfo, status); + } + + private void logRequestFailure(TStatusCode code, String explanation) { + + TReturnStatus status; + try { + status = new TReturnStatus(code, explanation); + } catch (InvalidTReturnStatusAttributeException e) { + throw new RuntimeException(e); + } + + log.error("srmReservespace: request failed with: [status: {}]", status); + } + + private void logRequestFailure(GridUserInterface user, TSizeInBytes desSize, + TSizeInBytes guarSize, TLifeTimeInSeconds lifetime, + TRetentionPolicyInfo rpinfo, TStatusCode code, String explanation) { + + TReturnStatus status; + try { + status = new TReturnStatus(code, explanation); + } catch (InvalidTReturnStatusAttributeException e) { + throw new RuntimeException(e); + } + + log.error("srmReservespace: <{}> Request for [desiredSizeOfTotalSpace: {}," + + " desiredSizeOfGuaranteedSpace: {}] with " + + "[desiredLifetimeOfReservedSpace: {}, retentionPolicyInfo: {}]" + + "failed with: [status: {}]", user, desSize, guarSize, lifetime, rpinfo, + status); + } + + public ReserveSpaceCommand() { + + namespace = NamespaceDirector.getNamespace(); + catalog = new ReservedSpaceCatalog(); + } + + /** + * Method that provide space reservation for srmReserveSpace request. + * + * @param data + * Contain information about data procived in SRM request. + * @return SpaceResOutputData that contain all SRM return parameter. + * @todo Implement this it.grid.storm.synchcall.space.SpaceManager method + */ + public OutputData execute(InputData indata) { + + IdentityReserveSpaceInputData data; + if (indata instanceof IdentityInputData) { + data = (IdentityReserveSpaceInputData) indata; + } else { + GetSpaceMetaDataOutputData outputData = new GetSpaceMetaDataOutputData(); + outputData.setStatus(CommandHelper.buildStatus( + TStatusCode.SRM_NOT_SUPPORTED, "Anonymous user can not perform" + + SRM_COMMAND)); + printRequestOutcome(outputData.getStatus(), + (ReserveSpaceInputData) indata); + return outputData; + } + log.debug(":reserveSpace start."); + + if (!checkParameters(data)) { + return manageError(statusCode, explanation); + } + + String spaceFN = null; + try { + spaceFN = getSpaceFN(data.getUser()); + } catch (Exception e) { + log.error(e.getMessage(), e); + + logRequestFailure(data.getUser(), data.getDesiredSize(), + data.getGuaranteedSize(), data.getSpaceLifetime(), + data.getRetentionPolicyInfo(), statusCode, explanation); + + return manageError(statusCode, explanation); + } + + VirtualFSInterface vfs = null; + try { + vfs = getSpaceVFS(spaceFN); + } catch (Exception e) { + + log.error(e.getMessage(), e); + + logRequestFailure(data.getUser(), data.getDesiredSize(), + data.getGuaranteedSize(), data.getSpaceLifetime(), + data.getRetentionPolicyInfo(), statusCode, explanation); + return manageError(statusCode, explanation); + } + + setDefaults(data, vfs); + + String relativeSpaceFN = null; + try { + relativeSpaceFN = getRelativeSpaceFilePath(vfs, spaceFN); + } catch (Exception e) { + + log.error(e.getMessage(), e); + + logRequestFailure(data.getUser(), data.getDesiredSize(), + data.getGuaranteedSize(), data.getSpaceLifetime(), + data.getRetentionPolicyInfo(), statusCode, explanation); + + return manageError(statusCode, explanation); + } + + SpaceSize spaceSize = null; + try { + spaceSize = computeSpaceSize(data.getDesiredSize(), + data.getGuaranteedSize(), vfs); + } catch (Exception e) { + + log.error(e.getMessage(), e); + + logRequestFailure(data.getUser(), data.getDesiredSize(), + data.getGuaranteedSize(), data.getSpaceLifetime(), + data.getRetentionPolicyInfo(), statusCode, explanation); + return manageError(statusCode, explanation); + } + + StoRI spaceStori = null; + try { + spaceStori = getSpaceStoRI(vfs, relativeSpaceFN, + spaceSize.getDesiderataSpaceSize()); + } catch (Exception e) { + log.error(e.getMessage(), e); + + logRequestFailure(data.getUser(), data.getDesiredSize(), + data.getGuaranteedSize(), data.getSpaceLifetime(), + data.getRetentionPolicyInfo(), statusCode, explanation); + + return manageError(statusCode, explanation); + } + + log + .debug("Reserve Space File Size: {}", spaceSize.getDesiderataSpaceSize()); + + try { + spaceStori.getSpace().fakeAllot(); + } catch (ReservationException e) { + log.debug("Space reservation error: {}", e.getMessage(), e); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to create Space File into filesystem. \n"; + + logRequestFailure(data.getUser(), data.getDesiredSize(), + data.getGuaranteedSize(), data.getSpaceLifetime(), + data.getRetentionPolicyInfo(), statusCode, explanation); + + return manageError(statusCode, explanation); + } + + try { + setSpaceFilePermissions(spaceStori, data.getUser()); + + } catch (Exception e) { + log.error(e.getMessage(), e); + + logRequestFailure(data.getUser(), data.getDesiredSize(), + data.getGuaranteedSize(), data.getSpaceLifetime(), + data.getRetentionPolicyInfo(), statusCode, explanation); + + revertAllocation(spaceStori.getSpace()); + return manageError(statusCode, explanation); + } + + TSpaceToken spaceToken = null; + try { + spaceToken = registerIntoDB(data.getUser(), data.getSpaceTokenAlias(), + spaceSize.getTotalSize(), spaceSize.getDesiderataSpaceSize(), + data.getSpaceLifetime(), spaceStori.getPFN()); + } catch (Exception e) { + log.error(e.getMessage(), e); + + logRequestFailure(data.getUser(), data.getDesiredSize(), + data.getGuaranteedSize(), data.getSpaceLifetime(), + data.getRetentionPolicyInfo(), statusCode, explanation); + + revertAllocation(spaceStori.getSpace()); + return manageError(statusCode, explanation); + } + + ReserveSpaceOutputData output = null; + try { + output = buildOutput(spaceSize, spaceToken, data.getSpaceLifetime()); + + logRequestSuccess(data.getUser(), data.getDesiredSize(), + data.getGuaranteedSize(), data.getSpaceLifetime(), + data.getRetentionPolicyInfo(), output.getStatus()); + + } catch (Exception e) { + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to build a valid output object "; + logRequestFailure(data.getUser(), data.getDesiredSize(), + data.getGuaranteedSize(), data.getSpaceLifetime(), + data.getRetentionPolicyInfo(), statusCode, explanation); + revertAllocation(spaceStori.getSpace()); + return manageError(statusCode, explanation); + } + return output; + } + + private void revertAllocation(Space space) { + + try { + space.fakeRelease(); + } catch (ReservationException e) { + log.error(e.getMessage(), e); + } + } + + private StoRI getSpaceStoRI(VirtualFSInterface vfs, String relativeSpaceFN, + TSizeInBytes desiderataSpaceSize) throws Exception { + + StoRI spaceFile = null; + try { + spaceFile = vfs.createSpace(relativeSpaceFN, desiderataSpaceSize.value()); + } catch (NamespaceException e) { + log.debug("Unable to create Space File in VFS ", e); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to create Space File in VFS \n" + e; + throw new Exception(explanation); + } + return spaceFile; + } + + private boolean checkParameters(IdentityReserveSpaceInputData data) { + + if (data == null) { + log.error("Invalid input parameters: null IdentityReserveSpaceInputData"); + explanation = "Invalid Parameter specified"; + statusCode = TStatusCode.SRM_FAILURE; + logRequestFailure(statusCode, explanation); + return false; + } + + if (data.getUser() == null) { + log.error("Null user credentials."); + statusCode = TStatusCode.SRM_AUTHENTICATION_FAILURE; + explanation = "Unable to get user credential!"; + logRequestFailure(statusCode, explanation); + return false; + } + + if (data.getRetentionPolicyInfo() == null) { + log.debug("Null retentionPolicyInfo."); + statusCode = TStatusCode.SRM_INVALID_REQUEST; + explanation = "RetentionPolicy not specified."; + logRequestFailure(data.getUser(), data.getDesiredSize(), + data.getGuaranteedSize(), data.getSpaceLifetime(), + data.getRetentionPolicyInfo(), statusCode, explanation); + return false; + } + + TAccessLatency latency = data.getRetentionPolicyInfo().getAccessLatency(); + TRetentionPolicy retentionPolicy = data.getRetentionPolicyInfo() + .getRetentionPolicy(); + + if (!((latency == null || latency.equals(TAccessLatency.EMPTY) || latency + .equals(TAccessLatency.ONLINE)) && (retentionPolicy == null + || retentionPolicy.equals(TRetentionPolicy.EMPTY) || retentionPolicy + .equals(TRetentionPolicy.REPLICA)))) { + + log.debug("Invalid retentionPolicyInfo: {}, {}", data + .getRetentionPolicyInfo().getAccessLatency(), data + .getRetentionPolicyInfo().getRetentionPolicy()); + + statusCode = TStatusCode.SRM_NOT_SUPPORTED; + explanation = "RetentionPolicy requested cannot be satisfied."; + + logRequestFailure(data.getUser(), data.getDesiredSize(), + data.getGuaranteedSize(), data.getSpaceLifetime(), + data.getRetentionPolicyInfo(), statusCode, explanation); + + return false; + } + return true; + } + + private String getSpaceFN(GridUserInterface user) throws Exception { + + String spaceFN = null; + try { + spaceFN = namespace.makeSpaceFileURI(user); + log.debug("Space FN : {}", spaceFN); + } catch (NamespaceException ex) { + log.error(ex.getMessage(), ex); + statusCode = TStatusCode.SRM_INVALID_REQUEST; + explanation = "Unable to build default Space FN \n" + ex; + throw new Exception(explanation); + } + return spaceFN; + } + + private VirtualFSInterface getSpaceVFS(String spaceFN) throws Exception { + + VirtualFSInterface vfs = null; + try { + vfs = namespace.resolveVFSbyAbsolutePath(spaceFN); + log.debug("Space File belongs to VFS : {}", vfs.getAliasName()); + } catch (NamespaceException ex2) { + log.debug(ex2.getMessage(), ex2); + statusCode = TStatusCode.SRM_INVALID_REQUEST; + explanation = "Unable to resolve VFS \n" + ex2; + throw new Exception(explanation); + } + + return vfs; + } + + private void setDefaults(IdentityReserveSpaceInputData data, + VirtualFSInterface vfs) { + + if (data.getRetentionPolicyInfo().getAccessLatency() == null + || data.getRetentionPolicyInfo().getAccessLatency() + .equals(TAccessLatency.EMPTY)) { + data.getRetentionPolicyInfo().setAccessLatency(TAccessLatency.ONLINE); + } + if (data.getRetentionPolicyInfo().getRetentionPolicy() == null + || data.getRetentionPolicyInfo().getRetentionPolicy() + .equals(TRetentionPolicy.EMPTY)) { + data.getRetentionPolicyInfo() + .setRetentionPolicy(TRetentionPolicy.REPLICA); + } + if (data.getSpaceLifetime().isEmpty()) { + log.debug("LifeTime is EMPTY. Using default value."); + data.setSpaceLifetime(vfs.getDefaultValues().getDefaultSpaceLifetime()); + } + } + + private SpaceSize computeSpaceSize(TSizeInBytes totalSize, + TSizeInBytes guarSize, VirtualFSInterface vfs) throws Exception { + + TSizeInBytes desiderataSpaceSize = TSizeInBytes.makeEmpty(); + + if ((!(totalSize.isEmpty())) + && (!((guarSize.isEmpty()) || guarSize.value() == 0))) { + if (totalSize.value() < guarSize.value()) { + log.debug("Error: totalSize < guaranteedSize"); + statusCode = TStatusCode.SRM_INVALID_REQUEST; + explanation = "Error: totalSize can not be greater then guaranteedSize"; + throw new Exception(explanation); + } + } else { // Assign default values if totalSize and guaranteedSize are + // not defined + if (!(totalSize.isEmpty())) { + guarSize = vfs.getDefaultValues().getDefaultGuaranteedSpaceSize(); + if (totalSize.value() < guarSize.value()) { + guarSize = totalSize; + } + } else { + if (!((guarSize.isEmpty()) || guarSize.value() == 0)) { + totalSize = vfs.getDefaultValues().getDefaultTotalSpaceSize(); + if (totalSize.value() < guarSize.value()) { + totalSize = guarSize; + log.debug("GuaranteedSize greater than default total size!"); + } + } else { + totalSize = vfs.getDefaultValues().getDefaultTotalSpaceSize(); + guarSize = vfs.getDefaultValues().getDefaultGuaranteedSpaceSize(); + // totalSize must be greater than guaranteedSize the following + // check is to be sure + // that the default parameters are correctly set. + if (totalSize.value() < guarSize.value()) { + totalSize = guarSize; + } + } + } + } + + /* + * At this point either totalSize and guarSize contains significative value. + * desiderataSpaceSize is setted to totalSize. + */ + desiderataSpaceSize = totalSize; + // This is valid because StoRM only reserve GUARANTEED space. + guarSize = desiderataSpaceSize; + + TSizeInBytes freeSpace = null; + try { + freeSpace = TSizeInBytes.make(vfs.getFilesystem().getFreeSpace(), + SizeUnit.BYTES); + } catch (InvalidTSizeAttributesException e) { + log + .debug("Error while retrieving free Space in underlying Filesystem", e); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Error while retrieving free Space in underlying Filesystem \n" + + e; + throw new Exception(explanation); + } catch (NamespaceException ex) { + log + .debug( + "Error while retrieving free Space in underlying Filesystem. Unable to retrieve FS Driver", + ex); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Error while retrieving free Space in underlying Filesystem. Unable to retrieve FS Driver \n" + + ex; + throw new Exception(explanation); + } + + /** + * @todo Change here, also granted SpaceSize must be considered. + */ + boolean lower_space = false; + // If there is not enogh free space on storage + if (freeSpace.value() < desiderataSpaceSize.value()) { + if (freeSpace.value() < guarSize.value()) { + // Not enough freespace + log + .debug(":reserveSpace Not Enough Free Space on storage!"); + statusCode = TStatusCode.SRM_NO_FREE_SPACE; + explanation = "SRM has not more free space."; + throw new Exception(explanation); + } else { + // Enough free space to reserve granted space asked. + desiderataSpaceSize = guarSize; + lower_space = true; + } + } + return this.new SpaceSize(desiderataSpaceSize, totalSize, lower_space); + } + + private String getRelativeSpaceFilePath(VirtualFSInterface vfs, String spaceFN) + throws Exception { + + String relativeSpaceFN = null; + + relativeSpaceFN = NamespaceUtil.extractRelativePath(vfs.getRootPath(), + spaceFN); + + log.debug("relativeSpaceFN: {}", relativeSpaceFN); + + return relativeSpaceFN; + } + + private void setSpaceFilePermissions(StoRI spaceStori, GridUserInterface user) + throws Exception { + + FilesystemPermission fp = FilesystemPermission.ReadWrite; + + AclManager manager = AclManagerFSAndHTTPS.getInstance(); + LocalFile localFile = spaceStori.getLocalFile(); + LocalUser localUser; + try { + localUser = user.getLocalUser(); + } catch (CannotMapUserException e) { + log.debug(e.getMessage(), e); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to setting up the ACL "; + throw new Exception(explanation); + } + if (localFile == null || localUser == null) { + log.error("ACL setup error. localFile={} , localUser={}", localFile, + localUser); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to setting up the ACL "; + throw new Exception(explanation); + } + if (spaceStori.hasJustInTimeACLs()) { + try { + manager.grantUserPermission(localFile, localUser, fp); + } catch (IllegalArgumentException e) { + log.error(e.getMessage(), e); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to grant group permission on space file "; + throw new Exception(explanation); + } + } else { + try { + manager.grantGroupPermission(localFile, localUser, fp); + } catch (IllegalArgumentException e) { + log.error(e.getMessage(), e); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to setting up the ACL "; + throw new Exception(explanation); + } + } + } + + private TSpaceToken registerIntoDB(GridUserInterface user, + String spaceTokenAlias, TSizeInBytes totalSize, + TSizeInBytes desiderataSpaceSize, TLifeTimeInSeconds lifeTime, PFN pfn) + throws Exception { + + StorageSpaceData spaceData = null; + try { + spaceData = new StorageSpaceData(user, TSpaceType.PERMANENT, + spaceTokenAlias, totalSize, desiderataSpaceSize, lifeTime, null, + new Date(), pfn); + } catch (InvalidSpaceDataAttributesException e) { + log.debug("Unable to create Storage Space Data", e); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to create storage space data."; + + logRequestFailure(user, totalSize, desiderataSpaceSize, lifeTime, null, + statusCode, explanation); + + throw new Exception(explanation); + } + + spaceData.setUsedSpaceSize(TSizeInBytes.make(0, SizeUnit.BYTES)); + spaceData.setUnavailableSpaceSize(TSizeInBytes.make(0, SizeUnit.BYTES)); + spaceData.setReservedSpaceSize(desiderataSpaceSize); + + log.debug("Created space data: {}", spaceData); + try { + catalog.addStorageSpace(spaceData); + } catch (DataAccessException e) { + log.debug("Unable to register Storage Space Data into DB", e); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to register Storage Space Data into DB."; + logRequestFailure(user, totalSize, desiderataSpaceSize, lifeTime, null, + statusCode, explanation); + throw new Exception(explanation); + } + + TSpaceToken spaceToken = null; + try { + spaceToken = TSpaceToken.make(spaceData.getSpaceToken().toString()); + } catch (InvalidTSpaceTokenAttributesException e) { + log.debug("Error creating Space Token", e); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to create space token."; + + logRequestFailure(user, totalSize, desiderataSpaceSize, lifeTime, null, + statusCode, explanation); + + throw new Exception(explanation); + } + return spaceToken; + } + + private ReserveSpaceOutputData buildOutput(SpaceSize spaceSize, + TSpaceToken spaceToken, TLifeTimeInSeconds lifeTime) throws Exception { + + TReturnStatus status = null; + try { + if (!spaceSize.isLowerSpace()) { + status = new TReturnStatus(TStatusCode.SRM_SUCCESS, + "Space Reservation done"); + + } else { + status = new TReturnStatus(TStatusCode.SRM_LOWER_SPACE_GRANTED, + "Space Reservation done, lower space granted."); + } + } catch (InvalidTReturnStatusAttributeException e) { + log.debug("InvalidTReturnStatusAttributeException", e); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to build a valid return status "; + throw new Exception(explanation); + } + + ReserveSpaceOutputData outputData = null; + try { + outputData = new ReserveSpaceOutputData(spaceSize.getTotalSize(), + spaceSize.getDesiderataSpaceSize(), lifeTime, spaceToken, status); + } catch (InvalidReserveSpaceOutputDataAttributesException e) { + log.error(e.getMessage(), e); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to build a valid return output object "; + throw new Exception(explanation); + } + return outputData; + } + + private class SpaceSize { + + private final TSizeInBytes desiderataSpaceSize; + private final TSizeInBytes totalSize; + private final boolean lowerSpace; + + public SpaceSize(TSizeInBytes desiderataSpaceSize, TSizeInBytes totalSize, + boolean lowerSpace) { + + this.desiderataSpaceSize = desiderataSpaceSize; + this.totalSize = totalSize; + this.lowerSpace = lowerSpace; + } + + protected TSizeInBytes getDesiderataSpaceSize() { + + return desiderataSpaceSize; + } + + protected TSizeInBytes getTotalSize() { + + return totalSize; + } + + protected boolean isLowerSpace() { + + return lowerSpace; + } + } + + /** + * Method that reset an already done reservation to the original status. + * + * @param token + * TSpaceToken that contains information about data procived in SRM + * request. + * @return TReturnStatus that contains of all SRM return parameters. + */ + public TReturnStatus resetReservation(TSpaceToken token) { + + String explanation = null; + TStatusCode statusCode = TStatusCode.EMPTY; + + StorageSpaceData sdata; + try { + sdata = catalog.getStorageSpace(token); + } catch (TransferObjectDecodingException e) { + log.error(e.getMessage(), e); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Error building space data from row DB data\n" + e; + return manageErrorStatus(statusCode, explanation); + } catch (DataAccessException e) { + log.error(e.getMessage(), e); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Error retrieving row space token data from DB\n" + e; + return manageErrorStatus(statusCode, explanation); + } + + if (sdata.getSpaceType().equals(TSpaceType.VOSPACE)) { + return manageErrorStatus(TStatusCode.SRM_SUCCESS, "Abort file done."); + } + + GridUserInterface user = sdata.getOwner(); + PFN spacePFN = sdata.getSpaceFileName(); + + String spaceFN = spacePFN.toString(); + + VirtualFSInterface vfs = null; + try { + vfs = namespace.resolveVFSbyAbsolutePath(spaceFN); + log.debug("Space File belongs to VFS : {}", vfs.getAliasName()); + } catch (NamespaceException ex2) { + log.debug("Unable to resolve VFS ", ex2); + statusCode = TStatusCode.SRM_INVALID_REQUEST; + explanation = "Unable to resolve VFS \n" + ex2.getMessage(); + return manageErrorStatus(statusCode, explanation); + } + + String relativeSpaceFN = null; + relativeSpaceFN = NamespaceUtil.extractRelativePath(vfs.getRootPath(), + spaceFN); + + log.debug("relativeSpaceFN: {}", relativeSpaceFN); + + TSizeInBytes desiderataSpaceSize = sdata.getTotalSpaceSize(); + + TSizeInBytes freeSpace; + try { + long bytesFree = vfs.getFilesystem().getFreeSpace(); + freeSpace = TSizeInBytes.make(bytesFree, SizeUnit.BYTES); + } catch (InvalidTSizeAttributesException e) { + log.debug(e.getMessage(), e); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Error while retrieving free Space in underlying Filesystem \n" + + e; + return manageErrorStatus(statusCode, explanation); + } catch (NamespaceException e) { + log.debug(e.getMessage(), e); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Error while retrieving free Space in underlying Filesystem. Unable to retrieve FS Driver \n" + + e.getMessage(); + return manageErrorStatus(statusCode, explanation); + } + + boolean authorize = true; + + if (authorize) { + log.debug("reserve Space File Size: {}", desiderataSpaceSize.toString()); + + StoRI spaceFile = null; + try { + spaceFile = vfs.createSpace(relativeSpaceFN, + desiderataSpaceSize.value()); + } catch (NamespaceException e) { + log.debug(e.getMessage(), e); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to create Space File in VFS \n" + e.getMessage(); + return manageErrorStatus(statusCode, explanation); + } + + try { + spaceFile.getSpace().allot(); + } catch (ReservationException e) { + log.debug(e.getMessage(), e); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to create Space File into filesystem. \n"; + return manageErrorStatus(statusCode, explanation); + } + + boolean hasJiTACL = spaceFile.hasJustInTimeACLs(); + FilesystemPermission fp = FilesystemPermission.ReadWrite; + + if (hasJiTACL) { + try { + AclManager manager = AclManagerFSAndHTTPS.getInstance(); + LocalFile localFile = spaceFile.getLocalFile(); + LocalUser localUser = user.getLocalUser(); + if (localFile == null || localUser == null) { + log.error("ACL setup error. localFile={} localUser={}", localFile, + localUser); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to setting up the ACL "; + return manageErrorStatus(statusCode, explanation); + } else { + try { + manager.grantGroupPermission(localFile, localUser, fp); + } catch (IllegalArgumentException e) { + log.error(e.getMessage(), e); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to grant group permission on space file "; + return manageErrorStatus(statusCode, explanation); + } + } + } catch (CannotMapUserException e) { + log.error(e.getMessage(), e); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to setting up the ACL "; + return manageErrorStatus(statusCode, explanation); + } + } else { + try { + AclManager manager = AclManagerFSAndHTTPS.getInstance(); + LocalFile localFile = spaceFile.getLocalFile(); + LocalUser localUser = user.getLocalUser(); + if (localFile == null || localUser == null) { + log.error("ACL setup error. localFile={} localUser={}", localFile, + localUser); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to setting up the ACL "; + return manageErrorStatus(statusCode, explanation); + } else { + try { + manager.grantGroupPermission(localFile, localUser, fp); + } catch (IllegalArgumentException e) { + log.error(e.getMessage(), e); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to grant group permission on space file "; + return manageErrorStatus(statusCode, explanation); + } + } + } catch (CannotMapUserException e) { + log.error(e.getMessage(), e); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to setting up the ACL "; + return manageErrorStatus(statusCode, explanation); + } + } + + } + + sdata.setUsedSpaceSize(desiderataSpaceSize); + + try { + catalog.updateStorageSpaceFreeSpace(sdata); + } catch (DataAccessException e) { + log.error(e.getMessage(), e); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Error persisting space token data into the DB\n" + + e.getMessage(); + return manageErrorStatus(statusCode, explanation); + } + + return manageErrorStatus(TStatusCode.SRM_SUCCESS, "Successfull creation."); + } + + public TReturnStatus updateReservation(TSpaceToken token, + TSizeInBytes sizeToAdd, TSURL toSurl) { + + String explanation = null; + TStatusCode statusCode = TStatusCode.EMPTY; + + StorageSpaceData sdata; + try { + sdata = catalog.getStorageSpace(token); + } catch (TransferObjectDecodingException e) { + log.error(e.getMessage(), e); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Error building space data from row DB data\n" + e; + return manageErrorStatus(statusCode, explanation); + } catch (DataAccessException e) { + log.error(e.getMessage(), e); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Error retrieving row space token data from DB\n" + e; + return manageErrorStatus(statusCode, explanation); + } + GridUserInterface user = sdata.getOwner(); + PFN spacePFN = sdata.getSpaceFileName(); + + if (sdata.getSpaceType().equals(TSpaceType.VOSPACE)) { + return manageErrorStatus(TStatusCode.SRM_SUCCESS, "Abort file done."); + } + + String spaceFN = null; + spaceFN = spacePFN.toString(); + + VirtualFSInterface vfs = null; + try { + vfs = namespace.resolveVFSbyAbsolutePath(spaceFN); + log.debug("Space File belongs to VFS : {}", vfs.getAliasName()); + } catch (NamespaceException e) { + log.debug("Unable to resolve VFS ", e); + statusCode = TStatusCode.SRM_INVALID_REQUEST; + explanation = "Unable to resolve VFS \n" + e.getMessage(); + return manageErrorStatus(statusCode, explanation); + } + + String relativeSpaceFN = null; + + relativeSpaceFN = NamespaceUtil.extractRelativePath(vfs.getRootPath(), + spaceFN); + + TSizeInBytes desiderataSpaceSize = sdata.getTotalSpaceSize(); + TSizeInBytes availableSize = sdata.getAvailableSpaceSize(); + + log.debug("available Size : {}" + availableSize.value()); + log.debug("Size of removed file: {}" + sizeToAdd.value()); + + try { + desiderataSpaceSize = TSizeInBytes.make( + availableSize.value() + sizeToAdd.value(), SizeUnit.BYTES); + } catch (InvalidTSizeAttributesException e) { + log.error(e.getMessage()); + } + + log.debug("reserve Space File Size :" + desiderataSpaceSize.toString()); + + StoRI spaceFile = null; + try { + spaceFile = vfs.createSpace(relativeSpaceFN, desiderataSpaceSize.value()); + } catch (NamespaceException e) { + log.debug("Unable to create Space File in VFS ", e); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to create Space File in VFS \n" + e.getMessage(); + return manageErrorStatus(statusCode, explanation); + } + + LocalFile localFile = spaceFile.getLocalFile(); + + if (localFile != null) { + localFile.delete(); + } + + try { + spaceFile.getSpace().allot(); + } catch (ReservationException e) { + log.debug(e.getMessage(), e); + revertOldSpaceFileDeletion(localFile); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to create Space File into filesystem. \n"; + return manageErrorStatus(statusCode, explanation); + } + + boolean hasJiTACL = spaceFile.hasJustInTimeACLs(); + + FilesystemPermission fp = FilesystemPermission.ReadWrite; + + if (hasJiTACL) { + try { + AclManager manager = AclManagerFSAndHTTPS.getInstance(); + localFile = spaceFile.getLocalFile(); + LocalUser localUser = user.getLocalUser(); + if (localFile == null || localUser == null) { + log.error("ACL setup error. localFile={} localUser={}", localFile, + localUser); + revertOldSpaceFileDeletion(localFile); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to setting up the ACL "; + return manageErrorStatus(statusCode, explanation); + } else { + try { + manager.grantGroupPermission(localFile, localUser, fp); + } catch (IllegalArgumentException e) { + log.error(e.getMessage(), e); + revertOldSpaceFileDeletion(localFile); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to grant group permission on space file "; + return manageErrorStatus(statusCode, explanation); + } + } + } catch (CannotMapUserException e) { + log.debug(e.getMessage(), e); + revertOldSpaceFileDeletion(localFile); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to setting up the ACL "; + return manageErrorStatus(statusCode, explanation); + } + } else { + try { + AclManager manager = AclManagerFSAndHTTPS.getInstance(); + localFile = spaceFile.getLocalFile(); + LocalUser localUser = user.getLocalUser(); + if (localFile == null || localUser == null) { + log.error("ACL setup error. localFile={} localUser={}", localFile, + localUser); + revertOldSpaceFileDeletion(localFile); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to setting up the ACL "; + return manageErrorStatus(statusCode, explanation); + } else { + try { + manager.grantGroupPermission(spaceFile.getLocalFile(), localUser, + fp); + } catch (IllegalArgumentException e) { + log.error(e.getMessage(), e); + revertOldSpaceFileDeletion(localFile); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to grant group permission on space file "; + return manageErrorStatus(statusCode, explanation); + } + } + } catch (CannotMapUserException e) { + log.debug(e.getMessage(), e); + revertOldSpaceFileDeletion(localFile); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Unable to setting up the ACL "; + return manageErrorStatus(statusCode, explanation); + } + } + + try { + availableSize = TSizeInBytes.make(sdata.getAvailableSpaceSize().value() + + sizeToAdd.value(), SizeUnit.BYTES); + } catch (InvalidTSizeAttributesException e) { + log.error(e.getMessage(), e); + revertOldSpaceFileDeletion(localFile); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Error computing new available space size\n" + + e.getMessage(); + return manageErrorStatus(statusCode, explanation); + } + + sdata.forceAvailableSpaceSize(availableSize); + + try { + catalog.updateStorageSpaceFreeSpace(sdata); + } catch (DataAccessException e) { + log.error(e.getMessage(), e); + revertOldSpaceFileDeletion(localFile); + statusCode = TStatusCode.SRM_INTERNAL_ERROR; + explanation = "Error persisting space token data into the DB\n" + + e.getMessage(); + return manageErrorStatus(statusCode, explanation); + } + return manageErrorStatus(TStatusCode.SRM_SUCCESS, "Successfull creation."); + } + + private void revertOldSpaceFileDeletion(LocalFile localFile) { + + } + + private ReserveSpaceOutputData manageError(TStatusCode statusCode, + String explanation) { + + TReturnStatus status = null; + try { + status = new TReturnStatus(statusCode, explanation); + } catch (InvalidTReturnStatusAttributeException e) { + log.warn(e.getMessage(), e); + } + + return new ReserveSpaceOutputData(status); + } + + private TReturnStatus manageErrorStatus(TStatusCode statusCode, + String explanation) { + + TReturnStatus status = null; + try { + status = new TReturnStatus(statusCode, explanation); + } catch (InvalidTReturnStatusAttributeException e) { + log.warn(e.getMessage(), e); + } + return status; + } + + private void printRequestOutcome(TReturnStatus status, + ReserveSpaceInputData data) { + + if (data != null) { + CommandHelper.printRequestOutcome(SRM_COMMAND, log, status, data); + } else { + CommandHelper.printRequestOutcome(SRM_COMMAND, log, status); + } + } } From 56d4de9974ea00dfac6ed0910f6a2d1aad4f05c2 Mon Sep 17 00:00:00 2001 From: Andrea Ceccanti Date: Thu, 6 Feb 2014 11:27:58 +0100 Subject: [PATCH 26/45] Fix log messages in scheduler package. --- .../grid/storm/scheduler/ChunkScheduler.java | 55 +++++----------- .../it/grid/storm/scheduler/ChunkTask.java | 64 ------------------- .../storm/scheduler/CrusherScheduler.java | 10 +-- .../it/grid/storm/scheduler/WorkerPool.java | 21 +++--- 4 files changed, 32 insertions(+), 118 deletions(-) diff --git a/src/main/java/it/grid/storm/scheduler/ChunkScheduler.java b/src/main/java/it/grid/storm/scheduler/ChunkScheduler.java index 7a10f794..1acfcc2c 100644 --- a/src/main/java/it/grid/storm/scheduler/ChunkScheduler.java +++ b/src/main/java/it/grid/storm/scheduler/ChunkScheduler.java @@ -151,8 +151,7 @@ public static ChunkScheduler getInstance() { public void schedule(Delegable chunk) throws SchedulerException { - // Debugging info logging - log.debug("Delegable Chunk " + chunk.getName() + " arrived at scheduler"); + log.debug("Scheduling chunk: {}", chunk.getName()); Chooser c = (Chooser) chunk; c.choose(this); } @@ -214,82 +213,58 @@ public SchedulerStatus getStatus(int type) { public void ptgStreet(Delegable chunk) { // Debugging info logging - log.debug("Chunk (declared PTG) " + chunk.getName() - + " entered into PTG-street"); + log.trace("ptgStreet got chunk: {}", chunk.getName()); - // Build a generic Chunk Task - // ChunkTask chunkTask = new ChunkTask(chunk, ChunkType.PREPARE_TO_GET); ChunkTask chunkTask = new ChunkTask(chunk); try { ptg_workers.submit(chunkTask); - log.debug("PtG QuotaJobResultsHandler Pool SIZE = " - + getStatus(Scheduler.PtG_WorkerPoolType).getPoolSize()); - } catch (SchedulerException ex) { - log.error("PrepareToGet_Street", ex); + } catch (SchedulerException e) { + log.error(e.getMessage(),e); } } public void ptpStreet(Delegable chunk) { - // Debugging info logging - log.debug("Chunk (declared PTP) " + chunk.getName() - + " entered into PTP-street"); - - // Build a generic Chunk Task - // ChunkTask chunkTask = new ChunkTask(chunk, ChunkType.PREPARE_TO_PUT); + log.trace("ptpStreet got chunk: {}", chunk.getName()); ChunkTask chunkTask = new ChunkTask(chunk); try { ptp_workers.submit(chunkTask); - log.debug("PtP QuotaJobResultsHandler Pool SIZE = " - + getStatus(Scheduler.PtP_WorkerPoolType).getPoolSize()); - } catch (SchedulerException ex) { - log.error("PrepareToPut_Street submission error", ex); + } catch (SchedulerException e) { + log.error(e.getMessage(),e); } } public void copyStreet(Delegable chunk) { - // Debugging info logging - log.debug("Chunk (declared COPY) " + chunk.getName() - + " entered into COPY-street"); + log.trace("copyStreet got chunk: {}", chunk.getName()); - // Build a generic Chunk Task - // ChunkTask chunkTask = new ChunkTask(chunk, ChunkType.COPY); ChunkTask chunkTask = new ChunkTask(chunk); try { copy_workers.submit(chunkTask); - log.debug("Copy QuotaJobResultsHandler Pool SIZE = " - + getStatus(Scheduler.Copy_WorkerPoolType).getPoolSize()); - } catch (SchedulerException ex) { - log.error("Copy_Street", ex); + } catch (SchedulerException e) { + log.error(e.getMessage(),e); } } public void bolStreet(Delegable chunk) { - // Debugging info logging - log.debug("Chunk (declared BOL) " + chunk.getName() - + " entered into BOL-street"); + log.trace("bolStret got chunk: {}", chunk.getName()); - // Build a generic Chunk Task - // ChunkTask chunkTask = new ChunkTask(chunk, ChunkType.BOL); ChunkTask chunkTask = new ChunkTask(chunk); try { bol_workers.submit(chunkTask); - log.debug("BoL QuotaJobResultsHandler Pool SIZE = " - + getStatus(Scheduler.BoL_WorkerPoolType).getPoolSize()); - } catch (SchedulerException ex) { - log.error("BoL_Street", ex); + } catch (SchedulerException e) { + log.error(e.getMessage(),e); } } public void abort(Delegable task) throws SchedulerException { - + log.warn("abort is not implemented"); } public void suspend(Delegable task) throws SchedulerException { - + log.warn("suspend is not implemented"); } } diff --git a/src/main/java/it/grid/storm/scheduler/ChunkTask.java b/src/main/java/it/grid/storm/scheduler/ChunkTask.java index ba014690..bbda32ca 100644 --- a/src/main/java/it/grid/storm/scheduler/ChunkTask.java +++ b/src/main/java/it/grid/storm/scheduler/ChunkTask.java @@ -64,70 +64,6 @@ public class ChunkTask extends Task { private boolean successResult = false; - // /** - // * - // */ - // public ChunkTask(Delegable todo, ChunkType type) - // { - // super(); - // this.todo = todo; - // this.taskName = todo.getName(); - // if(todo instanceof Request) - // { - // this.userDN = ((Request)todo).getUserDN(); - // this.surl = ((Request)todo).getSURL(); - // if(todo instanceof RequestChunk) - // { - // this.requestToken = ((RequestChunk)todo).getRequestToken(); - // } - // else - // { - // this.requestToken = "Empty"; - // } - // } - // else - // { - // this.userDN = "unknonw"; - // this.surl = "unknonw"; - // this.requestToken = "unknonw"; - // } - // // if (type.equals(ChunkType.PREPARE_TO_GET)) - // // { - // // PtGChunk ptgToDo = (PtGChunk) todo; - // // this.userDN = ptgToDo.getUserDN(); - // // this.surl = ptgToDo.getSURL(); - // // this.requestToken = ptgToDo.getRequestToken(); - // // } - // // else - // // { - // // if (type.equals(ChunkType.PREPARE_TO_PUT)) - // // { - // // PtP ptpToDo = (PtP) todo; - // // String requestToken = null; - // // if(todo instanceof PtPChunk) - // // { - // // requestToken = ((PtPChunk)ptpToDo).getRequestToken(); - // // this.userDN = ptpToDo.getUserDN(); - // // this.surl = ptpToDo.getSURL(); - // // this.requestToken = requestToken; - // // } - // // else - // // { - // // this.userDN = ptpToDo.getUserDN(); - // // this.surl = ptpToDo.getSURL(); - // // this.requestToken = "Empty"; - // // } - // // } - // // else - // // { - // // this.userDN = "unknonw"; - // // this.surl = "unknonw"; - // // this.requestToken = "unknonw"; - // // } - // // } - // this.isAsynchTask = todo instanceof DelegableChunk; - // } - public ChunkTask(Delegable todo) { super(); diff --git a/src/main/java/it/grid/storm/scheduler/CrusherScheduler.java b/src/main/java/it/grid/storm/scheduler/CrusherScheduler.java index f69fb494..030f57a0 100644 --- a/src/main/java/it/grid/storm/scheduler/CrusherScheduler.java +++ b/src/main/java/it/grid/storm/scheduler/CrusherScheduler.java @@ -88,8 +88,9 @@ private CrusherScheduler() { } public static CrusherScheduler getInstance() { + + log.trace("CrusherScheduler.getInstance"); - log.debug("Called multi-thread scheduler"); if (istance == null) { istance = new CrusherScheduler(); } @@ -98,13 +99,14 @@ public static CrusherScheduler getInstance() { public void schedule(Delegable cruncherTask) throws SchedulerException { - log.debug("Scheduling feed " + cruncherTask.getName()); + log.trace("CrusherScheduler.schedule() - cruncherTask: {}", + cruncherTask.getName()); try { Task task = new CruncherTask(cruncherTask); crusherPool.submit(task); - log.debug("Feed task nr. = " + crusherPool.getTaskCount()); - log.debug("Scheduled feed " + cruncherTask.getName()); + log.debug("Feed task nr. = {}" , crusherPool.getTaskCount()); + log.debug("Scheduled feed {}" , cruncherTask.getName()); } catch (SchedulerException se) { log.error(se.getMessage(), se); throw se; diff --git a/src/main/java/it/grid/storm/scheduler/WorkerPool.java b/src/main/java/it/grid/storm/scheduler/WorkerPool.java index caa2744a..2dd2fcef 100644 --- a/src/main/java/it/grid/storm/scheduler/WorkerPool.java +++ b/src/main/java/it/grid/storm/scheduler/WorkerPool.java @@ -59,7 +59,6 @@ public class WorkerPool { private static final Logger log = LoggerFactory.getLogger(WorkerPool.class); - // These values are not configurable in this version! private long keepAliveTime = 10000; // 10 seconds. private TimeUnit unit = TimeUnit.MILLISECONDS; @@ -88,16 +87,19 @@ public WorkerPool(int corePoolSize, int maxPoolSize, int queueSize) { */ public void submit(Task task) throws SchedulerException { - log.debug("Taskqueue Size:" + this.queueSize); - log.debug("Taskqueue RemCap:" + workers.getQueue().remainingCapacity()); + log.trace("WorkerPool.submit"); + log.debug("Taskqueue Size: {}", queueSize); + log.debug("Taskqueue Remaining Capacity: {}", + workers.getQueue().remainingCapacity()); + task.enqueueEvent(); try { - log.debug("Submitting task with name = " + task.getName()); + log.debug("Submitting task {}" , task.getName()); workers.execute(task); - } catch (RejectedExecutionException ret) { - log.error("Task " + task.getName() + "was rejected!", ret); - throw new SchedulerException(task.getName(), ret); + } catch (RejectedExecutionException e) { + log.error("Task {} was rejected. {}", task.getName(), e.getMessage(), e); + throw new SchedulerException(task.getName(), e); } } @@ -109,11 +111,10 @@ public void submit(Task task) throws SchedulerException { */ public void remove(Task task) throws SchedulerException { - log.debug("Abort request"); + log.trace("WorkerPool.remove"); task.abortEvent(); - log.debug("Aborting request with name : " + task.getName()); + log.debug("Aborting task {}", task.getName()); boolean taskFound = false; - // Looking for the task within the Queue BlockingQueue queue = workers.getQueue(); taskFound = queue.contains(task); From 8b4193132c4953e489d51ea8ccc7f439d8dd7f9b Mon Sep 17 00:00:00 2001 From: Andrea Ceccanti Date: Thu, 6 Feb 2014 14:26:47 +0100 Subject: [PATCH 27/45] More log messaages rationalization --- .../it/grid/storm/persistence/DAOFactory.java | 9 - .../storm/persistence/MemoryDAOFactory.java | 170 ----------------- .../storm/persistence/MockDAOFactory.java | 153 --------------- .../storm/persistence/MySqlDAOFactory.java | 52 ++---- .../persistence/PersistenceDirector.java | 51 ++--- .../storm/persistence/dao/AbstractDAO.java | 56 ++---- .../storm/persistence/dao/CopyChunkDAO.java | 37 ---- .../storm/persistence/dao/PermissionDAO.java | 25 --- .../persistence/dao/VOInfoStatusDAO.java | 50 ----- .../impl/mysql/StorageSpaceDAOMySql.java | 174 +++++++++--------- .../impl/mysql/TapeRecallDAOMySql.java | 42 ++--- .../storm/persistence/model/CopyChunkTO.java | 59 ------ .../it/grid/storm/persistence/model/GUID.java | 59 +----- .../storm/persistence/model/PtGChunkTO.java | 64 ++----- .../storm/persistence/model/PtPChunkTO.java | 41 ----- .../persistence/model/StorageSpaceTO.java | 9 +- .../storm/persistence/model/TapeRecallTO.java | 14 +- .../TransferObjectDecodingException.java | 4 - .../persistence/model/VOInfoStatusTO.java | 110 ----------- .../persistence/util/db/DBConnection.java | 79 ++------ .../persistence/util/db/DBConnectionPool.java | 92 ++------- .../persistence/util/db/DataBaseStrategy.java | 13 +- .../util/helper/TapeRecallMySQLHelper.java | 4 - .../java/it/grid/storm/rest/JettyThread.java | 6 +- .../java/it/grid/storm/rest/RestService.java | 5 +- 25 files changed, 226 insertions(+), 1152 deletions(-) delete mode 100644 src/main/java/it/grid/storm/persistence/MemoryDAOFactory.java delete mode 100644 src/main/java/it/grid/storm/persistence/MockDAOFactory.java delete mode 100644 src/main/java/it/grid/storm/persistence/dao/CopyChunkDAO.java delete mode 100644 src/main/java/it/grid/storm/persistence/dao/PermissionDAO.java delete mode 100644 src/main/java/it/grid/storm/persistence/dao/VOInfoStatusDAO.java delete mode 100644 src/main/java/it/grid/storm/persistence/model/CopyChunkTO.java delete mode 100644 src/main/java/it/grid/storm/persistence/model/VOInfoStatusTO.java diff --git a/src/main/java/it/grid/storm/persistence/DAOFactory.java b/src/main/java/it/grid/storm/persistence/DAOFactory.java index e4e2923c..31c64c4a 100644 --- a/src/main/java/it/grid/storm/persistence/DAOFactory.java +++ b/src/main/java/it/grid/storm/persistence/DAOFactory.java @@ -23,8 +23,6 @@ package it.grid.storm.persistence; -import it.grid.storm.persistence.dao.CopyChunkDAO; -import it.grid.storm.persistence.dao.PermissionDAO; import it.grid.storm.persistence.dao.PtGChunkDAO; import it.grid.storm.persistence.dao.PtPChunkDAO; import it.grid.storm.persistence.dao.RequestSummaryDAO; @@ -55,10 +53,6 @@ public interface DAOFactory { public TapeRecallDAO getTapeRecallDAO(boolean test) throws DataAccessException; - public PermissionDAO getPermissionDAO() throws DataAccessException; - - public CopyChunkDAO getCopyChunkDAO() throws DataAccessException; - public PtGChunkDAO getPtGChunkDAO() throws DataAccessException; public PtPChunkDAO getPtPChunkDAO() throws DataAccessException; @@ -67,7 +61,4 @@ public TapeRecallDAO getTapeRecallDAO(boolean test) public RequestSummaryDAO getRequestSummaryDAO() throws DataAccessException; - /** - * public PendingRequestDAO getPendingRequestDAO() throws DataAccessException; - **/ } diff --git a/src/main/java/it/grid/storm/persistence/MemoryDAOFactory.java b/src/main/java/it/grid/storm/persistence/MemoryDAOFactory.java deleted file mode 100644 index 97e1c3d0..00000000 --- a/src/main/java/it/grid/storm/persistence/MemoryDAOFactory.java +++ /dev/null @@ -1,170 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -/* - * (c)2004 INFN / ICTP-eGrid This file can be distributed and/or modified under - * the terms of the INFN Software License. For a copy of the licence please - * visit http://www.cnaf.infn.it/license.html - */ - -/** - * MemoryDAOFactory - */ -package it.grid.storm.persistence; - -import it.grid.storm.persistence.dao.CopyChunkDAO; -import it.grid.storm.persistence.dao.PermissionDAO; -import it.grid.storm.persistence.dao.PtGChunkDAO; -import it.grid.storm.persistence.dao.PtPChunkDAO; -import it.grid.storm.persistence.dao.RequestSummaryDAO; -import it.grid.storm.persistence.dao.StorageAreaDAO; -import it.grid.storm.persistence.dao.StorageSpaceDAO; -import it.grid.storm.persistence.dao.TapeRecallDAO; -import it.grid.storm.persistence.exceptions.DataAccessException; - -/** - * @author Riccardo Zappi - riccardo.zappi AT cnaf.infn.it - * @version $Id: MemoryDAOFactory.java,v 1.3 2005/06/06 10:47:37 rzappi Exp $ - * $Revision: 1.3 $ - */ -public class MemoryDAOFactory implements DAOFactory { - - private final String factoryName = "MEMORY DAO Factory"; - - /** - * getCopyChunkDAO - * - * @return CopyChunkDAO - * @throws DataAccessException - * @todo Implement this it.grid.storm.catalog.persistence.CatalogFactory - * method - */ - public CopyChunkDAO getCopyChunkDAO() throws DataAccessException { - - return null; - } - - /** - * getPermissionDAO - * - * @return PermissionDAO - * @throws DataAccessException - * @todo Implement this it.grid.storm.catalog.persistence.CatalogFactory - * method - */ - public PermissionDAO getPermissionDAO() throws DataAccessException { - - return null; - } - - /** - * getPtGChunkDAO - * - * @return PtGChunkDAO - * @throws DataAccessException - * @todo Implement this it.grid.storm.catalog.persistence.CatalogFactory - * method - */ - public PtGChunkDAO getPtGChunkDAO() throws DataAccessException { - - return null; - } - - /** - * getPtPChunkDAO - * - * @return PtPChunkDAO - * @throws DataAccessException - * @todo Implement this it.grid.storm.catalog.persistence.CatalogFactory - * method - */ - public PtPChunkDAO getPtPChunkDAO() throws DataAccessException { - - return null; - } - - /** - * getRequestSummaryDAO - * - * @return RequestSummaryDAO - * @throws DataAccessException - * @todo Implement this it.grid.storm.catalog.persistence.CatalogFactory - * method - */ - public RequestSummaryDAO getRequestSummaryDAO() throws DataAccessException { - - return null; - } - - /** - * getStorageAreaDAO - * - * @return StorageAreaDAO - * @throws DataAccessException - * @todo Implement this it.grid.storm.catalog.persistence.CatalogFactory - * method - */ - public StorageAreaDAO getStorageAreaDAO() throws DataAccessException { - - return null; - } - - /** - * Returns an implementation of StorageSpaceDAO, specific to a particular - * datastore. - * - * @throws DataAccessException - * @return StorageSpaceDAO - * @todo Implement this it.grid.storm.catalog.persistence.CatalogFactory - * method - */ - public StorageSpaceDAO getStorageSpaceDAO() throws DataAccessException { - - return null; - } - - /** - * Returns an implementation of TapeRecallCatalog, specific to a particular - * datastore. - * - * @throws DataAccessException - * @return TapeReallDAO - * @todo Implement this it.grid.storm.persistence.DAOFactory method - */ - public TapeRecallDAO getTapeRecallDAO() { - - return null; - } - - @Override - public String toString() { - - return factoryName; - } - - /* - * (non-Javadoc) - * - * @see it.grid.storm.persistence.DAOFactory#getTapeRecallDAO(boolean) - */ - public TapeRecallDAO getTapeRecallDAO(boolean test) - throws DataAccessException { - - // TODO Auto-generated method stub - return null; - } -} diff --git a/src/main/java/it/grid/storm/persistence/MockDAOFactory.java b/src/main/java/it/grid/storm/persistence/MockDAOFactory.java deleted file mode 100644 index 8b45c61a..00000000 --- a/src/main/java/it/grid/storm/persistence/MockDAOFactory.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.persistence; - -import it.grid.storm.persistence.dao.CopyChunkDAO; -import it.grid.storm.persistence.dao.PermissionDAO; -import it.grid.storm.persistence.dao.PtGChunkDAO; -import it.grid.storm.persistence.dao.PtPChunkDAO; -import it.grid.storm.persistence.dao.RequestSummaryDAO; -import it.grid.storm.persistence.dao.StorageAreaDAO; -import it.grid.storm.persistence.dao.StorageSpaceDAO; -import it.grid.storm.persistence.dao.TapeRecallDAO; -import it.grid.storm.persistence.exceptions.DataAccessException; - -public class MockDAOFactory implements DAOFactory { - - private final String factoryName = "MOCK DAO Factory"; - - public MockDAOFactory() { - - } - - /** - * getCopyChunkDAO - * - * @return CopyChunkDAO - * @throws DataAccessException - * @todo Implement this it.grid.storm.persistence.DAOFactory method - */ - public CopyChunkDAO getCopyChunkDAO() throws DataAccessException { - - return null; - } - - /** - * getPermissionDAO - * - * @return PermissionDAO - * @throws DataAccessException - * @todo Implement this it.grid.storm.persistence.DAOFactory method - */ - public PermissionDAO getPermissionDAO() throws DataAccessException { - - return null; - } - - /** - * getPtGChunkDAO - * - * @return PtGChunkDAO - * @throws DataAccessException - * @todo Implement this it.grid.storm.persistence.DAOFactory method - */ - public PtGChunkDAO getPtGChunkDAO() throws DataAccessException { - - return null; - } - - /** - * getPtPChunkDAO - * - * @return PtPChunkDAO - * @throws DataAccessException - * @todo Implement this it.grid.storm.persistence.DAOFactory method - */ - public PtPChunkDAO getPtPChunkDAO() throws DataAccessException { - - return null; - } - - /** - * getRequestSummaryDAO - * - * @return RequestSummaryDAO - * @throws DataAccessException - * @todo Implement this it.grid.storm.persistence.DAOFactory method - */ - public RequestSummaryDAO getRequestSummaryDAO() throws DataAccessException { - - return null; - } - - /** - * getStorageAreaDAO - * - * @return StorageAreaDAO - * @throws DataAccessException - * @todo Implement this it.grid.storm.persistence.DAOFactory method - */ - public StorageAreaDAO getStorageAreaDAO() throws DataAccessException { - - return null; - } - - /** - * Returns an implementation of StorageSpaceCatalog, specific to a particular - * datastore. - * - * @throws DataAccessException - * @return StorageSpaceDAO - * @todo Implement this it.grid.storm.persistence.DAOFactory method - */ - public StorageSpaceDAO getStorageSpaceDAO() throws DataAccessException { - - return null; - } - - /** - * Returns an implementation of TapeRecallCatalog, specific to a particular - * datastore. - * - * @throws DataAccessException - * @return TapeReallDAO - * @todo Implement this it.grid.storm.persistence.DAOFactory method - */ - public TapeRecallDAO getTapeRecallDAO() { - - return null; - } - - @Override - public String toString() { - - return factoryName; - } - - /* - * (non-Javadoc) - * - * @see it.grid.storm.persistence.DAOFactory#getTapeRecallDAO(boolean) - */ - public TapeRecallDAO getTapeRecallDAO(boolean test) - throws DataAccessException { - - // TODO Auto-generated method stub - return null; - } -} diff --git a/src/main/java/it/grid/storm/persistence/MySqlDAOFactory.java b/src/main/java/it/grid/storm/persistence/MySqlDAOFactory.java index 153d21bb..d2d366b8 100644 --- a/src/main/java/it/grid/storm/persistence/MySqlDAOFactory.java +++ b/src/main/java/it/grid/storm/persistence/MySqlDAOFactory.java @@ -18,8 +18,6 @@ package it.grid.storm.persistence; import it.grid.storm.config.Configuration; -import it.grid.storm.persistence.dao.CopyChunkDAO; -import it.grid.storm.persistence.dao.PermissionDAO; import it.grid.storm.persistence.dao.PtGChunkDAO; import it.grid.storm.persistence.dao.PtPChunkDAO; import it.grid.storm.persistence.dao.RequestSummaryDAO; @@ -43,6 +41,7 @@ public class MySqlDAOFactory implements DAOFactory { private static final Logger log = LoggerFactory .getLogger(MySqlDAOFactory.class); + private static final DataBaseStrategy datasource = DataBaseStrategy.MYSQL; private static DataSourceConnectionFactory connFactory = null; private static MySqlDAOFactory factory = new MySqlDAOFactory(); @@ -55,7 +54,7 @@ public class MySqlDAOFactory implements DAOFactory { * */ private MySqlDAOFactory() { - MySqlDAOFactory.log.info("DAO factory: " + MySqlDAOFactory.factoryName); + log.info("DAO factory: {}", MySqlDAOFactory.factoryName); } public static MySqlDAOFactory getInstance() { @@ -66,10 +65,11 @@ public static MySqlDAOFactory getInstance() { private static void initializeDataSource() { Configuration config = Configuration.getInstance(); - MySqlDAOFactory.datasource.setDbUrl(config.getBEPersistenceDBMSUrl()); - MySqlDAOFactory.datasource.setDbName(config.getBEPersistenceDBName()); - MySqlDAOFactory.datasource.setDbUsr(config.getBEPersistenceDBUserName()); - MySqlDAOFactory.datasource.setDbPwd(config.getBEPersistenceDBPassword()); + + datasource.setDbUrl(config.getBEPersistenceDBMSUrl()); + datasource.setDbName(config.getBEPersistenceDBName()); + datasource.setDbUsr(config.getBEPersistenceDBUserName()); + datasource.setDbPwd(config.getBEPersistenceDBPassword()); boolean pool = config.getBEPersistencePoolDB(); if (pool) { @@ -78,21 +78,18 @@ private static void initializeDataSource() { try { DBConnectionPool.initPool(MySqlDAOFactory.datasource, maxActive, maxWait); - } catch (PersistenceException ex) { - MySqlDAOFactory.log.error("Exception while setting up Pool", ex); + } catch (PersistenceException e) { + log.error(e.getMessage(), e); } MySqlDAOFactory.connFactory = DBConnectionPool.getPoolInstance(); } else { try { MySqlDAOFactory.connFactory = new DBConnection( MySqlDAOFactory.datasource); - } catch (PersistenceException ex1) { - MySqlDAOFactory.log.error("Exception while setting up DB connection", - ex1); + } catch (PersistenceException e) { + log.error(e.getMessage(), e); } } - log.debug("RECALL TABLE Catalog/DAO "); - } /** @@ -130,33 +127,6 @@ public String toString() { return MySqlDAOFactory.factoryName; } - /** - * NOT IMPLEMENTED! - */ - - /** - * getCopyChunkDAO - * - * @return CopyChunkDAO - * @throws DataAccessException - * @todo Implement this it.grid.storm.persistence.DAOFactory method - */ - public CopyChunkDAO getCopyChunkDAO() throws DataAccessException { - - return null; - } - - /** - * getPermissionDAO - * - * @return PermissionDAO - * @throws DataAccessException - * @todo Implement this it.grid.storm.persistence.DAOFactory method - */ - public PermissionDAO getPermissionDAO() throws DataAccessException { - - return null; - } /** * getPtGChunkDAO diff --git a/src/main/java/it/grid/storm/persistence/PersistenceDirector.java b/src/main/java/it/grid/storm/persistence/PersistenceDirector.java index 97a56db0..9b262615 100644 --- a/src/main/java/it/grid/storm/persistence/PersistenceDirector.java +++ b/src/main/java/it/grid/storm/persistence/PersistenceDirector.java @@ -36,7 +36,7 @@ public class PersistenceDirector { private static DataSourceConnectionFactory connFactory; static { - log.debug("Initializing Persistence Director..."); + log.trace("Initializing Persistence Director..."); dbMan = initializeDataBase(); daoFactory = initializeFactory(); connFactory = connectToDateSource(); @@ -45,68 +45,53 @@ public class PersistenceDirector { private static DataBaseStrategy initializeDataBase() { dbVendor = config.getBEPersistenceDBVendor(); - log.debug("DBMS Vendor = " + dbVendor); - log.debug("DBMS URL = " + config.getBEPersistenceDBMSUrl()); + log.debug("DBMS Vendor = {}",dbVendor); + log.debug("DBMS URL = {}", config.getBEPersistenceDBMSUrl()); return DataBaseStrategy.getInstance(dbVendor); } - /** - * Use an ad hoc String mapping scheme, and introduce an if-else branch for - * each alternative. - */ private static DAOFactory initializeFactory() { if (dbVendor.equalsIgnoreCase("MySql")) { return MySqlDAOFactory.getInstance(); - } else if (dbVendor.equalsIgnoreCase("memory")) { - return new MemoryDAOFactory(); - } else if (dbVendor.equalsIgnoreCase("mock")) { - return new MockDAOFactory(); - } else { - log.error("Persistence Data Source was setted in a BAD way.."); - throw new IllegalArgumentException("Unknown datastore identifier."); - } + } + + log.error("Unknown datastore id: {}", dbVendor); + throw new IllegalArgumentException("Unknown datastore identifier: " + +dbVendor); } private static DataSourceConnectionFactory connectToDateSource() { DataSourceConnectionFactory result = null; - // Collect Logging information - StringBuffer sf = new StringBuffer(); - sf.append("Connecting to Data Source..." + "\n"); - sf.append(" Connection String = " + dbMan.getConnectionString() + "\n"); - boolean poolMode = config.getBEPersistencePoolDB(); int maxActive = config.getBEPersistencePoolDBMaxActive(); int maxWait = config.getBEPersistencePoolDBMaxWait(); - sf.append(" Pool Mode = " + poolMode + "\n"); - if (poolMode) { - sf.append(" pool Max Active = " + maxActive + "\n"); - sf.append(" pool Max Wait = " + maxWait + "\n"); - } - log.debug(sf.toString()); + + log.debug("Datasource connection string = {}", dbMan.getConnectionString()); + + log.debug("Pool mode = {}", poolMode); + log.debug("Pool Max Active = {}", maxActive); + log.debug("Pool Max Wait = {}", maxWait); if (poolMode) { - log.debug("Setup Connection Pool"); try { DBConnectionPool.initPool(dbMan, maxActive, maxWait); result = DBConnectionPool.getPoolInstance(); - } catch (PersistenceException ex1) { - log.error("Connection In Pool Mode to Data Source FAIL ", ex1); + } catch (PersistenceException e) { + log.error(e.getMessage(), e); } } else { - log.debug("Setup Shared Connection"); try { result = new DBConnection(dbMan); - } catch (PersistenceException ex) { - log.error("Connection to Data Source FAIL", ex); + } catch (PersistenceException e) { + log.error(e.getMessage(), e); } } return result; } public static DAOFactory getDAOFactory() { - return daoFactory; } diff --git a/src/main/java/it/grid/storm/persistence/dao/AbstractDAO.java b/src/main/java/it/grid/storm/persistence/dao/AbstractDAO.java index bb56147e..7f773e37 100644 --- a/src/main/java/it/grid/storm/persistence/dao/AbstractDAO.java +++ b/src/main/java/it/grid/storm/persistence/dao/AbstractDAO.java @@ -32,46 +32,26 @@ public abstract class AbstractDAO { - /** - * - */ private static final Logger log = LoggerFactory.getLogger(AbstractDAO.class); - /** - * - */ private DataSourceConnectionFactory connFactory; - /** - * - */ public AbstractDAO() { - connFactory = PersistenceDirector.getConnectionFactory(); } - /** - * @param conn - */ protected void commit(Connection conn) { try { conn.commit(); conn.setAutoCommit(true); } catch (SQLException e) { - log.error("Cannot commit transaction", e); + log.error(e.getMessage(), e); } } - /** - * Retrieve a connection Accessor method. - * - * @return Connection - * @throws DataAccessException - */ protected Connection getConnection() throws DataAccessException { - // Retrieve a Connection Connection conn = null; try { conn = connFactory.borrowConnection(); @@ -81,14 +61,6 @@ protected Connection getConnection() throws DataAccessException { return conn; } - /** - * Retrieve a Statement from connection Accessor method. - * - * @param conn - * Connection - * @return Statement - * @throws DataAccessException - */ protected Statement getStatement(Connection conn) throws DataAccessException { Statement stat = null; @@ -98,9 +70,9 @@ protected Statement getStatement(Connection conn) throws DataAccessException { } else { try { stat = conn.createStatement(); - } catch (SQLException ex1) { - log.error("Error while creating the statement"); - throw new DataAccessException(ex1); + } catch (SQLException e) { + log.error(e.getMessage(), e); + throw new DataAccessException(e); } } return stat; @@ -163,9 +135,9 @@ private void closeResultSet(ResultSet resultSet) throws DataAccessException { if (resultSet != null) { try { resultSet.close(); - } catch (SQLException ex1) { - log.error("Error while releasing the result set"); - throw new DataAccessException(ex1); + } catch (SQLException e) { + log.error(e.getMessage(), e); + throw new DataAccessException(e); } } } @@ -175,9 +147,9 @@ private void closeStatement(Statement statement) throws DataAccessException { if (statement != null) { try { statement.close(); - } catch (SQLException ex2) { - log.error("Error while releasing the statement"); - throw new DataAccessException(ex2); + } catch (SQLException e) { + log.error(e.getMessage(), e); + throw new DataAccessException(e); } } } @@ -188,9 +160,9 @@ private void closeConnection(Connection connection) if (connection != null) { try { connFactory.giveBackConnection(connection); - } catch (PersistenceException ex3) { - log.error("Error while releasing the connection"); - throw new DataAccessException(ex3); + } catch (PersistenceException e) { + log.error(e.getMessage(), e); + throw new DataAccessException(e); } } } @@ -206,7 +178,7 @@ protected void rollback(Connection conn) { conn.setAutoCommit(true); } catch (SQLException e) { - log.error("Cannot rollback transaction", e); + log.error(e.getMessage(), e); } } diff --git a/src/main/java/it/grid/storm/persistence/dao/CopyChunkDAO.java b/src/main/java/it/grid/storm/persistence/dao/CopyChunkDAO.java deleted file mode 100644 index 0036a33d..00000000 --- a/src/main/java/it/grid/storm/persistence/dao/CopyChunkDAO.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.persistence.dao; - -import java.util.Collection; -import it.grid.storm.persistence.exceptions.DataAccessException; -import it.grid.storm.persistence.model.CopyChunkTO; -import it.grid.storm.srm.types.TRequestToken; - -public interface CopyChunkDAO { - - public CopyChunkTO getCopyChunkDataById(Long ssId) throws DataAccessException; - - public void addCopyChunkData(CopyChunkTO copyChunkTO) - throws DataAccessException; - - public Collection getCopyChunksDataByToken(TRequestToken token) - throws DataAccessException; - - public void removeCopyChunksData(CopyChunkTO copyChunkTO) - throws DataAccessException; -} diff --git a/src/main/java/it/grid/storm/persistence/dao/PermissionDAO.java b/src/main/java/it/grid/storm/persistence/dao/PermissionDAO.java deleted file mode 100644 index 6bdb2505..00000000 --- a/src/main/java/it/grid/storm/persistence/dao/PermissionDAO.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.persistence.dao; - -public interface PermissionDAO { - /** - * @todo : implement it. - */ - -} diff --git a/src/main/java/it/grid/storm/persistence/dao/VOInfoStatusDAO.java b/src/main/java/it/grid/storm/persistence/dao/VOInfoStatusDAO.java deleted file mode 100644 index 839d5e2e..00000000 --- a/src/main/java/it/grid/storm/persistence/dao/VOInfoStatusDAO.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.persistence.dao; - -/** - *

- * Title: - *

- * - *

- * Description: - *

- * - *

- * Copyright: Copyright (c) 2006 - *

- * - *

- * Company: INFN-CNAF - *

- * - * @author R.Zappi - * @version 1.0 - */ - -public class VOInfoStatusDAO { - - /** - * No-arg constructor for JavaBean tools. - */ - public VOInfoStatusDAO() { - - super(); - } -} diff --git a/src/main/java/it/grid/storm/persistence/impl/mysql/StorageSpaceDAOMySql.java b/src/main/java/it/grid/storm/persistence/impl/mysql/StorageSpaceDAOMySql.java index ceeaa0de..f20df208 100644 --- a/src/main/java/it/grid/storm/persistence/impl/mysql/StorageSpaceDAOMySql.java +++ b/src/main/java/it/grid/storm/persistence/impl/mysql/StorageSpaceDAOMySql.java @@ -74,18 +74,18 @@ public void addStorageSpace(StorageSpaceTO ss) throws DataAccessException { try { prepStatement = helper.insertQuery(conn, ss); - log.info("INSERT query = " + prepStatement.toString()); + log.info("INSERT query = {}", prepStatement.toString()); int res = prepStatement.executeUpdate(); - log.debug("INSERT result = " + res); + log.debug("INSERT result = {}", res); if (res <= 0) { log - .error("No row inserted for statement : " + prepStatement.toString()); + .error("No row inserted for statement : {}", prepStatement.toString()); throw new DataAccessException("No rows inserted for Storage Space"); } - } catch (SQLException ex) { - log.error("Error while executing INSERT query", ex); - throw new DataAccessException("Error while executing INSERT query", ex); + } catch (SQLException e) { + log.error(e.getMessage(), e); + throw new DataAccessException("Error while executing INSERT query", e); } finally { releaseConnection(null, prepStatement, conn); } @@ -135,22 +135,21 @@ public Collection getStorageSpaceByOwner( try { prepStatement = helper.selectBySpaceAliasQuery(conn, owner, spaceAlias); - log.debug("DB query = " + prepStatement.toString()); + log.debug("DB query = {}", prepStatement.toString()); res = prepStatement.executeQuery(); - log.debug("query result = " + res); + log.debug("query result = {}", res); if (res.first() == false) { - log.info("No rows found for query : " + prepStatement.toString()); + log.info("No rows found for query : {}", prepStatement.toString()); } else { - // Fetch each row from the result set do { ssTO = helper.makeStorageSpaceTO(res); result.add(ssTO); } while (res.next()); } } catch (SQLException e) { - log.error("Error while executing DB query", e); + log.error(e.getMessage(), e); throw new DataAccessException("Error while executing DB query", e); } finally { releaseConnection(res, prepStatement, conn); @@ -180,12 +179,12 @@ public Collection getStorageSpaceBySpaceType(String stype) try { prepStatement = helper.selectBySpaceType(conn, stype); - log.debug("DB query = " + prepStatement.toString()); + log.debug("DB query = {}", prepStatement.toString()); res = prepStatement.executeQuery(); - log.debug("query result = " + res); + log.debug("query result = {}", res); if (res.first() == false) { - log.info("No rows found for query : " + prepStatement.toString()); + log.info("No rows found for query : {}", prepStatement.toString()); } else { // Fetch each row from the result set do { @@ -194,7 +193,7 @@ public Collection getStorageSpaceBySpaceType(String stype) } while (res.next()); } } catch (SQLException e) { - log.error("Error while executing DB query", e); + log.error(e.getMessage(), e); throw new DataAccessException("Error while executing DB query", e); } finally { releaseConnection(res, prepStatement, conn); @@ -223,13 +222,13 @@ public Collection getStorageSpaceByAliasOnly(String spaceAlias) try { prepStatement = helper.selectBySpaceAliasOnlyQuery(conn, spaceAlias); - log.debug("DB query = " + prepStatement.toString()); + log.debug("DB query = {}" , prepStatement.toString()); res = prepStatement.executeQuery(); - log.debug("query result = " + res); + log.debug("query result = {}" , res); if (res.first() == false) { - log.info("No rows found for query : " + prepStatement.toString()); + log.info("No rows found for query : {}" , prepStatement.toString()); } else { // Fetch each row from the result set do { @@ -238,7 +237,7 @@ public Collection getStorageSpaceByAliasOnly(String spaceAlias) } while (res.next()); } } catch (SQLException e) { - log.error("Error while executing DB query", e); + log.error(e.getMessage(), e); throw new DataAccessException("Error while executing DB query", e); } finally { releaseConnection(res, prepStatement, conn); @@ -265,20 +264,20 @@ public StorageSpaceTO getStorageSpaceByToken(String token) PreparedStatement prepStatement = null; try { prepStatement = helper.selectByTokenQuery(conn, token); - log.debug("SELECT query = " + prepStatement.toString()); + log.debug("SELECT query = {}" , prepStatement.toString()); res = prepStatement.executeQuery(); - log.debug("SELECT result = " + res); + log.debug("SELECT result = {}" , res); if (res.first() == false) { - log.info("No rows found for query : " + prepStatement.toString()); + log.info("No rows found for query : {}" , prepStatement.toString()); } else { // take the first ssTO = helper.makeStorageSpaceTO(res); } - } catch (SQLException ex) { - log.error("Error while executing SELECT query", ex); - throw new DataAccessException("Error while executing INSERT query", ex); + } catch (SQLException e) { + log.error(e.getMessage(), e); + throw new DataAccessException("Error while executing INSERT query", e); } finally { releaseConnection(res, prepStatement, conn); } @@ -299,12 +298,12 @@ public Collection getStorageSpaceByUnavailableUsedSpace( try { prepStatement = helper.selectByUnavailableUsedSpaceSizeQuery(conn, unavailableSizeValue); - log.debug("SELECT query = " + prepStatement.toString()); + log.debug("SELECT query = {}" , prepStatement.toString()); res = prepStatement.executeQuery(); - log.debug("SELECT result = " + res); + log.debug("SELECT result = {}" , res); if (res.first() == false) { - log.info("No rows found for query : " + prepStatement.toString()); + log.info("No rows found for query : {}" , prepStatement.toString()); } else { // Fetch each row from the result set do { @@ -312,9 +311,9 @@ public Collection getStorageSpaceByUnavailableUsedSpace( result.add(ssTO); } while (res.next()); } - } catch (SQLException ex) { - log.error("Error while executing SELECT query", ex); - throw new DataAccessException("Error while executing INSERT query", ex); + } catch (SQLException e) { + log.error(e.getMessage(), e); + throw new DataAccessException("Error while executing INSERT query", e); } finally { releaseConnection(res, prepStatement, conn); } @@ -335,12 +334,12 @@ public Collection getStorageSpaceByPreviousLastUpdate( try { prepStatement = helper.selectByPreviousOrNullLastUpdateQuery(conn, lastUpdateTimestamp.getTime()); - log.debug("SELECT query = " + prepStatement.toString()); + log.debug("SELECT query = {}" , prepStatement.toString()); res = prepStatement.executeQuery(); - log.debug("SELECT result = " + res); + log.debug("SELECT result = {}" , res); if (res.first() == false) { - log.info("No rows found for query : " + prepStatement.toString()); + log.info("No rows found for query : {}" , prepStatement.toString()); } else { // Fetch each row from the result set do { @@ -348,9 +347,9 @@ public Collection getStorageSpaceByPreviousLastUpdate( result.add(ssTO); } while (res.next()); } - } catch (SQLException ex) { - log.error("Error while executing SELECT query", ex); - throw new DataAccessException("Error while executing INSERT query", ex); + } catch (SQLException e) { + log.error(e.getMessage(), e); + throw new DataAccessException("Error while executing INSERT query", e); } finally { releaseConnection(res, prepStatement, conn); } @@ -372,19 +371,20 @@ public void removeStorageSpace(GridUserInterface user, String spaceToken) try { prepStatement = helper.removeByTokenQuery(conn, user, spaceToken); - log.debug("query = " + prepStatement.toString()); + log.debug("query = {}" , prepStatement.toString()); int res = prepStatement.executeUpdate(); - log.debug("Number of rows removed: " + res); + log.debug("Number of rows removed: {}" , res); if (res <= 0) { - log.error("Unable to remove Storage Space with token = '" + spaceToken - + "' for user '" + user.getDn() + "' not found!"); + log.error("Error removing Storage Space with token = {} for " + + "user {} not found", spaceToken, user.getDn()); + throw new DataAccessException("Storage Space with token = '" + spaceToken + "' for user '" + user.getDn() + "' not found!"); } - } catch (SQLException ex) { - log.error("Error while executing DELETE query", ex); - throw new DataAccessException("Error while executing DELETE query", ex); + } catch (SQLException e) { + log.error(e.getMessage(), e); + throw new DataAccessException("Error while executing DELETE query", e); } finally { releaseConnection(null, prepStatement, conn); } @@ -404,19 +404,22 @@ public void removeStorageSpace(String spaceToken) throws DataAccessException { try { prepStatement = helper.removeByTokenQuery(conn, spaceToken); - log.debug("query = " + prepStatement.toString()); + + log.debug("query = {}" , prepStatement.toString()); int res = prepStatement.executeUpdate(); - log.debug("Number of rows removed: " + res); + log.debug("Number of rows removed: {}" , res); + if (res <= 0) { - log.error("Unable to remove Storage Space with token = '" + spaceToken - + "' not found!"); + log.error("Error removing Storage Space with token = {}. Space not found", + spaceToken); + throw new DataAccessException("Storage Space with token = '" + spaceToken + "' not found!"); } - } catch (SQLException ex) { - log.error("Error while executing DELETE query", ex); - throw new DataAccessException("Error while executing DELETE query", ex); + } catch (SQLException e) { + log.error(e.getMessage(), e); + throw new DataAccessException("Error while executing DELETE query", e); } finally { releaseConnection(null, prepStatement, conn); } @@ -436,23 +439,24 @@ public void updateStorageSpace(StorageSpaceTO ssTO) try { prepStatement = helper.updateByAliasAndTokenQuery(conn, ssTO); - log.debug("UPDATE query = " + prepStatement.toString()); + log.debug("UPDATE query = {}" , prepStatement.toString()); int res = prepStatement.executeUpdate(); - log.debug("UPDATE row count = " + res); + log.debug("UPDATE row count = {}" , res); if (res != 1) { if (res < 1) { - log.error("No storage space rows updated by query : " - + prepStatement.toString()); + log.error("No storage space rows updated by query : {}" + , prepStatement.toString()); } else { - log.warn("More than a single storage space rows updated by query : " - + prepStatement.toString() + " updated " + res + " rows"); + log.warn("More than a single storage space rows updated by " + + "query : {}. updated {} rows.", + prepStatement.toString(), res); } } - } catch (SQLException ex) { - log.error("Error while executing UPDATE query", ex); - throw new DataAccessException("Error while executing UPDATE query", ex); + } catch (SQLException e) { + log.error(e.getMessage(), e); + throw new DataAccessException("Error while executing UPDATE query", e); } finally { releaseConnection(null, prepStatement, conn); } @@ -475,17 +479,18 @@ public void updateStorageSpaceFreeSpace(StorageSpaceTO ssTO) try { prepStatement = helper.updateFreeSpaceByTokenQuery(conn, ssTO.getSpaceToken(), freeSpace, new Date()); - log.debug("UPDATE query = " + prepStatement.toString()); + + log.debug("UPDATE query = {}" , prepStatement.toString()); int res = prepStatement.executeUpdate(); - log.debug("UPDATE row count = " + res); + log.debug("UPDATE row count = {}", res); if (res <= 0) { - log.error("No storage space rows updated by query : " - + prepStatement.toString()); + log.error("No storage space rows updated by query : {}" + , prepStatement.toString()); } - } catch (SQLException ex) { - log.error("Error while executing UPDATE query", ex); - throw new DataAccessException("Error while executing UPDATE query", ex); + } catch (SQLException e) { + log.error(e.getMessage(), e); + throw new DataAccessException("Error while executing UPDATE query", e); } finally { releaseConnection(null, prepStatement, conn); } @@ -500,35 +505,28 @@ public void updateStorageSpaceFreeSpace(StorageSpaceTO ssTO) public void updateAllStorageSpace(StorageSpaceTO ssTO) throws DataAccessException { - /** - * @todo: Update all changeable column! not only FreeSpace. - */ - // String query = helper.updateAllByTokenQuery(ss.getSpaceToken(), - // ss.getAlias(), - // ss.getGuaranteedSize(), - // ss.getSpaceFile(), ss.getUpdateTime()); - Connection conn = getConnection(); PreparedStatement prepStatement = null; try { prepStatement = helper.updateByTokenQuery(conn, ssTO); - log.debug("UPDATE query = " + prepStatement.toString()); + log.debug("UPDATE query = {}", prepStatement.toString()); int res = prepStatement.executeUpdate(); - log.debug("UPDATE row count = " + res); + log.debug("UPDATE row count = {}" , res); if (res != 1) { if (res < 1) { - log.error("No storage space rows updated by query : " - + prepStatement.toString()); + log.error("No storage space rows updated by query {}" + , prepStatement.toString()); } else { - log.warn("More than a single storage space rows updated by query : " - + prepStatement.toString() + " updated " + res + " rows"); + log.warn("More than a single storage space rows updated " + + "by query : {}. updated {} rows" + ,prepStatement.toString(), res); } } - } catch (SQLException ex) { - log.error("Error while executing UPDATE query", ex); - throw new DataAccessException("Error while executing UPDATE query", ex); + } catch (SQLException e) { + log.error(e.getMessage(), e); + throw new DataAccessException("Error while executing UPDATE query", e); } finally { releaseConnection(null, prepStatement, conn); } @@ -552,13 +550,13 @@ public Collection getExpired(long currentTimeInSecond) try { prepStatement = helper.selectExpiredQuery(conn, currentTimeInSecond); - log.debug("DB query = " + prepStatement.toString()); + log.debug("DB query = {}" , prepStatement.toString()); res = prepStatement.executeQuery(); - log.debug("query result = " + res); + log.debug("query result = {}" , res); if (res.first() == false) { - log.info("No rows found for query : " + prepStatement.toString()); + log.info("No rows found for query : {}" , prepStatement.toString()); throw new DataAccessException("No storage space expired found at time " + currentTimeInSecond); } else { @@ -569,7 +567,7 @@ public Collection getExpired(long currentTimeInSecond) } while (res.next()); } } catch (SQLException e) { - log.error("Error while executing DB query", e); + log.error(e.getMessage(), e); throw new DataAccessException("Error while executing DB query", e); } finally { releaseConnection(res, prepStatement, conn); diff --git a/src/main/java/it/grid/storm/persistence/impl/mysql/TapeRecallDAOMySql.java b/src/main/java/it/grid/storm/persistence/impl/mysql/TapeRecallDAOMySql.java index ce827f1b..360082e5 100644 --- a/src/main/java/it/grid/storm/persistence/impl/mysql/TapeRecallDAOMySql.java +++ b/src/main/java/it/grid/storm/persistence/impl/mysql/TapeRecallDAOMySql.java @@ -78,7 +78,7 @@ public int getNumberInProgress(String voName) throws DataAccessException { .getQueryNumberInProgress(dbConnection, voName); } - log.debug("QUERY: " + prepStatement.toString()); + log.debug("QUERY: {}", prepStatement.toString()); res = prepStatement.executeQuery(); @@ -86,8 +86,7 @@ public int getNumberInProgress(String voName) throws DataAccessException { status = res.getInt(1); } } catch (SQLException e) { - throw new DataAccessException("Error executing query: '" - + prepStatement.toString() + "' " + e.getMessage(), e); + log.error(e.getMessage(), e); } finally { releaseConnection(res, prepStatement, dbConnection); } @@ -115,15 +114,14 @@ public int getNumberQueued(String voName) throws DataAccessException { prepStatement = sqlHelper.getQueryNumberQueued(dbConnection, voName); } - log.debug("QUERY: " + prepStatement.toString()); + log.debug("QUERY: {}", prepStatement.toString()); res = prepStatement.executeQuery(); if (res.first() == true) { status = res.getInt(1); } } catch (SQLException e) { - throw new DataAccessException("Error executing query: '" - + prepStatement.toString() + "' " + e.getMessage(), e); + log.error(e.getMessage(), e); } finally { releaseConnection(res, prepStatement, dbConnection); } @@ -152,7 +150,7 @@ public int getReadyForTakeOver(String voName) throws DataAccessException { .getQueryReadyForTakeOver(dbConnection, voName); } - log.debug("QUERY: " + prepStatement.toString()); + log.debug("QUERY: {}", prepStatement.toString()); res = prepStatement.executeQuery(); if (res.first() == true) { @@ -186,7 +184,7 @@ public List getGroupTasks(UUID groupTaskId) res = prepStatement.executeQuery(); if (res.first() == false) { - log.error("No tasks with GroupTaskId='" + groupTaskId + "'"); + log.error("No tasks with GroupTaskId='{}'", groupTaskId); throw new DataAccessException( "No recall table row retrieved executing query: '" + prepStatement.toString() + "'"); @@ -218,13 +216,14 @@ public boolean existsGroupTask(UUID groupTaskId) throws DataAccessException { prepStatement = sqlHelper .getQueryGetGroupTasks(dbConnection, groupTaskId); - log.debug("QUERY: " + prepStatement.toString()); + log.debug("QUERY: {}", prepStatement.toString()); res = prepStatement.executeQuery(); response = res.first(); if (response == false) { - log.info("No tasks found with GroupTaskId='" + groupTaskId + "'"); + log.info("No tasks found with GroupTaskId='{}'",groupTaskId); } } catch (SQLException e) { + log.error(e.getMessage(), e); throw new DataAccessException("Error executing query: '" + prepStatement.toString() + "' " + e.getMessage(), e); } finally { @@ -245,13 +244,15 @@ public TapeRecallTO getTask(UUID taskId, String requestToken) try { prepStatement = sqlHelper.getQueryGetTask(dbConnection, taskId, requestToken); - log.debug("QUERY: " + prepStatement); + log.debug("QUERY: {}", prepStatement.toString()); res = prepStatement.executeQuery(); if (res.first() == false) { - log.error("No task found for requestToken=" + requestToken + " " - + " taskId=" + taskId.toString() + ". Query = " - + prepStatement.toString()); + log.error("No task found for requestToken={} taskId={}. Query={}", + requestToken , + taskId.toString(), + prepStatement.toString()); + throw new DataAccessException("No task found for requestToken=" + requestToken + " " + "taskId=" + taskId.toString() + ". Query = " + prepStatement.toString()); @@ -259,6 +260,7 @@ public TapeRecallTO getTask(UUID taskId, String requestToken) task = new TapeRecallTO(); setTaskInfo(task, res); } catch (SQLException e) { + log.error(e.getMessage(), e); throw new DataAccessException("Error executing query: '" + prepStatement.toString() + "' " + e.getMessage(), e); } finally { @@ -282,12 +284,11 @@ public boolean existsTask(UUID taskId, String requestToken) prepStatement = sqlHelper.getQueryGetTask(dbConnection, taskId, requestToken); - log.debug("QUERY: " + prepStatement.toString()); + log.debug("QUERY: {}", prepStatement.toString()); res = prepStatement.executeQuery(); response = res.first(); - log.debug("Task for requestToken=" + requestToken + " " + " taskId=" - + taskId.toString() + " does " + (response ? "" : "NOT ") + "exists"); } catch (SQLException e) { + log.error(e.getMessage(), e); throw new DataAccessException("Error executing query: '" + prepStatement.toString() + "' " + e.getMessage(), e); } finally { @@ -296,13 +297,6 @@ public boolean existsTask(UUID taskId, String requestToken) return response; } - /* - * (non-Javadoc) - * - * @see - * it.grid.storm.persistence.dao.TapeRecallDAO#insertCloneTask(it.grid.storm - * .persistence.model.TapeRecallTO, int[], java.util.UUID) - */ @Override public UUID insertCloneTask(TapeRecallTO task, int[] statuses, UUID proposedGroupTaskId) throws DataAccessException { diff --git a/src/main/java/it/grid/storm/persistence/model/CopyChunkTO.java b/src/main/java/it/grid/storm/persistence/model/CopyChunkTO.java deleted file mode 100644 index 35d2d5f6..00000000 --- a/src/main/java/it/grid/storm/persistence/model/CopyChunkTO.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.persistence.model; - -import it.grid.storm.srm.types.*; -import it.grid.storm.namespace.*; -import java.util.Date; - -/** - * holds all info necessary to complete a srmCopy of a single file, and to - * report advancement status of this part of the request. Data supplied to the - * constructor should already be available in the user request (front-end). - */ - -public class CopyChunkTO { - // FIXME: lacks constructor!! - - /** - * public TRequestId getRequestId(); public StoRI getFromSURL(); public StoRI - * getToSURL(); public String getStorageSystemInfo(); public TDirOption - * getDirOption(); public TOverwriteMode getOverwriteMode(); public - * TLifetimeInSeconds getRequestedLifetime(); public TFileStorageType - * getFileStorageType(); public TSpaceID getSpaceId(); public String[] - * getClientAcceptedTransportProtocols(); - * - * public int getEstimatedWaitTimeInQueue(); public int - * getEstimatedProgressingTime(); public int setEstimatedWaitTimeInQueue(final - * Date time); public int setEstimatedProgressingTime(final Date time); - * - * public TSizeInBytes getFileSize(); public TSizeInBytes setFileSize(final - * size_t size); - * - * public TReturnStatus getStatus(); public int setStatus(final TStatusCode - * code, final String explanation); - * - * public int getProgressCounter(); - * - * public void advanceProgressCounter(); - * - * public String getTURL(); public String setTURL(final String TURL); - * - * public TLifetimeInSeconds getRemainingLifetime(); - **/ -} diff --git a/src/main/java/it/grid/storm/persistence/model/GUID.java b/src/main/java/it/grid/storm/persistence/model/GUID.java index 16808e44..e90da5cf 100644 --- a/src/main/java/it/grid/storm/persistence/model/GUID.java +++ b/src/main/java/it/grid/storm/persistence/model/GUID.java @@ -18,10 +18,13 @@ package it.grid.storm.persistence.model; import java.io.Serializable; + import java.net.InetAddress; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +//FIXME: Why isn't storm using the standard UUID class? + /** * GUID Value Object. @@ -32,24 +35,16 @@ public class GUID implements Serializable { - /** - * - */ private static final long serialVersionUID = 7241176020077117264L; private static final Logger log = LoggerFactory.getLogger(GUID.class); private byte guidValue[] = new byte[16]; - /** Creates a new instance of GUID */ public GUID() { - buildNewGUID(); } - /** - * Creates a new instance of GUID using a fixed guid. - */ public GUID(String guidString) { int pos = 0; @@ -70,25 +65,12 @@ public GUID(String guidString) { } } - /** - * Calculates the byte from a hex string. - * - * @param hex - * A string hex value. - * @return a byte value. - */ + private byte getByteValue(String hex) { return (byte) Integer.parseInt(hex, 16); } - /** - * Calculates the hex string from a byte. - * - * @param val - * A byte value. - * @return a string hex value. - */ private String getHexString(byte val) { String hexString; @@ -104,16 +86,6 @@ private String getHexString(byte val) { return hexString.toUpperCase(); } - /** - * Set the bytes in the array from another array. - * - * @param lg - * The other array of bytes. - * @param count - * How many there are. - * @param startPos - * The point in the main byte array these should go. - */ private void setByteValues(byte[] lg, int startPos, int count) { for (int i = 0; i < count; i++) { @@ -121,17 +93,6 @@ private void setByteValues(byte[] lg, int startPos, int count) { } } - /** - * Sets the byte in the array to the bytes in a long value. In reverse - * order(IE Least significant byte goes first) - * - * @param lg - * The long value. - * @param count - * How many there are. - * @param startPos - * The point in the main byte array these should go. - */ private void setByteValues(long lg, int startPos, int count) { for (int i = 0; i < count; i++) { @@ -140,10 +101,6 @@ private void setByteValues(long lg, int startPos, int count) { } } - /** - * Creates a new GUID from nowhere. Actually it uses the time, IPAddress and a - * random number. Stores it all in the main byte array. - */ private void buildNewGUID() { try { @@ -170,16 +127,10 @@ private void buildNewGUID() { setByteValues(lg, 14, 2); } catch (Exception e) { - log.error("Error while generating a GUID", e); + log.error("GUID generation error : {}", e.getMessage(), e); } } - /** - * Stores the 16 bytes seperately, this returns that array Not sure why - * though. - * - * @return array of bytes. - */ public byte[] getBytes() { return guidValue; diff --git a/src/main/java/it/grid/storm/persistence/model/PtGChunkTO.java b/src/main/java/it/grid/storm/persistence/model/PtGChunkTO.java index 9c4c21fe..a3fa431a 100644 --- a/src/main/java/it/grid/storm/persistence/model/PtGChunkTO.java +++ b/src/main/java/it/grid/storm/persistence/model/PtGChunkTO.java @@ -51,24 +51,12 @@ */ public class PtGChunkTO { - private static final Logger log = LoggerFactory.getLogger(PtGChunkTO.class); // Logger - // of - // error - // messages! - // Common - // to - // all - // Asynch - // package! - - private TRequestToken requestToken; // This is the requestToken of the - // multifile srm request to which this - // chunk belongs - - private TSURL fromSURL; // SURL that the srm command wants to get - private TStorageSystemInfo storageSystemInfo; // TStorageSystemInfo associated - // to fromSURL: it may be - // useless in StoRM! + private static final Logger log = LoggerFactory.getLogger(PtGChunkTO.class); + + private TRequestToken requestToken; + + private TSURL fromSURL; + private TStorageSystemInfo storageSystemInfo; private TLifeTimeInSeconds lifeTime; // requested lifetime for fromSURL - // BEWARE!!! It is the pin time!!! @@ -265,9 +253,7 @@ public void changeStatusSRM_REQUEST_QUEUED(String explanation) { } status = new TReturnStatus(TStatusCode.SRM_REQUEST_QUEUED, explanation); } catch (InvalidTReturnStatusAttributeException e) { - log - .debug("UNEXPECTED ERROR! Unable to set SRM request status to SRM_REQUEST_QUEUED! " - + e); + log.debug(e.getMessage(), e); } } @@ -284,9 +270,7 @@ public void changeStatusSRM_DONE(String explanation) { } status = new TReturnStatus(TStatusCode.SRM_DONE, explanation); } catch (InvalidTReturnStatusAttributeException e) { - log - .debug("UNEXPECTED ERROR! Unable to set SRM request status to SRM_DONE! " - + e); + log.debug(e.getMessage(), e); } } @@ -303,9 +287,7 @@ public void changeStatusSRM_INVALID_REQUEST(String explanation) { } status = new TReturnStatus(TStatusCode.SRM_INVALID_REQUEST, explanation); } catch (InvalidTReturnStatusAttributeException e) { - log - .debug("UNEXPECTED ERROR! Unable to set SRM request status to SRM_INVALID_REQUEST! " - + e); + log.debug(e.getMessage(), e); } } @@ -323,9 +305,7 @@ public void changeStatusSRM_AUTHORIZATION_FAILURE(String explanation) { status = new TReturnStatus(TStatusCode.SRM_AUTHORIZATION_FAILURE, explanation); } catch (InvalidTReturnStatusAttributeException e) { - log - .debug("UNEXPECTED ERROR! Unable to set SRM request status to SRM_AUTHORIZATION_FAILURE! " - + e); + log.debug(e.getMessage(), e); } } @@ -342,9 +322,7 @@ public void changeStatusSRM_ABORTED(String explanation) { } status = new TReturnStatus(TStatusCode.SRM_ABORTED, explanation); } catch (InvalidTReturnStatusAttributeException e) { - log - .debug("UNEXPECTED ERROR! Unable to set SRM request status to SRM_ABORTED! " - + e); + log.debug(e.getMessage(), e); } } @@ -362,9 +340,8 @@ public void changeStatusSRM_REQUEST_INPROGRESS(String explanation) { status = new TReturnStatus(TStatusCode.SRM_REQUEST_INPROGRESS, explanation); } catch (InvalidTReturnStatusAttributeException e) { - log - .debug("UNEXPECTED ERROR! Unable to set SRM request status to SRM_REQUEST_INPROGRESS! " - + e); + + log.debug(e.getMessage(), e); } } @@ -381,9 +358,8 @@ public void changeStatusSRM_INTERNAL_ERROR(String explanation) { } status = new TReturnStatus(TStatusCode.SRM_INTERNAL_ERROR, explanation); } catch (InvalidTReturnStatusAttributeException e) { - log - .debug("UNEXPECTED ERROR! Unable to set SRM request status to SRM_INTERNAL_ERROR! " - + e); + + log.debug(e.getMessage(), e); } } @@ -401,9 +377,8 @@ public void changeStatusSRM_FATAL_INTERNAL_ERROR(String explanation) { status = new TReturnStatus(TStatusCode.SRM_FATAL_INTERNAL_ERROR, explanation); } catch (InvalidTReturnStatusAttributeException e) { - log - .debug("UNEXPECTED ERROR! Unable to set SRM request status to SRM_FATAL_INTERNAL_ERROR! " - + e); + + log.debug(e.getMessage(), e); } } @@ -420,9 +395,8 @@ public void changeStatusSRM_INVALID_PATH(String explanation) { } status = new TReturnStatus(TStatusCode.SRM_INVALID_PATH, explanation); } catch (InvalidTReturnStatusAttributeException e) { - log - .debug("UNEXPECTED ERROR! Unable to set SRM request status to SRM_INVALID_PATH! " - + e); + + log.debug(e.getMessage(), e); } } diff --git a/src/main/java/it/grid/storm/persistence/model/PtPChunkTO.java b/src/main/java/it/grid/storm/persistence/model/PtPChunkTO.java index 91e79c11..b990f172 100644 --- a/src/main/java/it/grid/storm/persistence/model/PtPChunkTO.java +++ b/src/main/java/it/grid/storm/persistence/model/PtPChunkTO.java @@ -17,48 +17,7 @@ package it.grid.storm.persistence.model; -import it.grid.storm.srm.types.*; -import it.grid.storm.namespace.*; -import java.util.Date; -/** - * holds all info necessary to complete a srmPtP of a single file, and to report - * advancement status of this part of the request. Data supplied to the - * constructor should already be available in the user request (front-end). - */ public class PtPChunkTO { - /** - * public PtPChunkData( final TRequestId requestId, final StoRI fromSURL, - * final String storageSystemInfo, final TSizeInBytes knownSizeOfThisFile, - * final TLifetimeInSeconds requestedLifetime, final TFileStorageType - * fileStorageType, final String[] clientAcceptedTransportProtocols, final int - * estimatedWaitTimeInQueue, final int estimatedProgressingTime, final - * TReturnStatus status, final int progressCounter, final String TURL ); - * - * public TRequestId getRequestId(); public StoRI getToSURL(); public String - * getStorageSystemInfo(); public TOverwriteMode getOverwriteMode(); public - * TLifetimeInSeconds getRequestedLifetime(); public TFileStorageType - * getFileStorageType(); public TSpaceID getSpaceId(); public String[] - * getClientAcceptedTransportProtocols(); - * - * public int getEstimatedWaitTimeInQueue(); public int - * getEstimatedProgressingTime(); public int setEstimatedWaitTimeInQueue(final - * Date time); public int setEstimatedProgressingTime(final Date time); - * - * public TSizeInBytes getKnownSizeOfThisFile(); public TSizeInBytes - * getActualFileSize(final TSizeInBytes size); public TSizeInBytes - * setActualFileSize(final TSizeInBytes size); - * - * public TReturnStatus getStatus(); public int setStatus(final TStatusCode - * code, String explanation); - * - * public int getProgressCounter(); - * - * public void advanceProgressCounter(); - * - * public String getTURL(); public String setTURL(final String TURL); - * - * public TLifetimeInSeconds getRemainingPinTime(); - **/ } diff --git a/src/main/java/it/grid/storm/persistence/model/StorageSpaceTO.java b/src/main/java/it/grid/storm/persistence/model/StorageSpaceTO.java index 34ef6d6c..e1eb1d4a 100644 --- a/src/main/java/it/grid/storm/persistence/model/StorageSpaceTO.java +++ b/src/main/java/it/grid/storm/persistence/model/StorageSpaceTO.java @@ -43,19 +43,14 @@ */ public class StorageSpaceTO implements Serializable, Comparable { - /** - * - */ private static final long serialVersionUID = -87317982494792808L; - /** - * Logger. - */ private static final Logger log = LoggerFactory .getLogger(StorageSpaceTO.class); // ----- PRIMARY KEY ----// private Long storageSpaceId = null; // Persistence Object IDentifier + // ----- FIELDS ----// private String ownerName = null; private String voName = null; @@ -103,7 +98,7 @@ public StorageSpaceTO() { public StorageSpaceTO(StorageSpaceData spaceData) { if (spaceData != null) { - StorageSpaceTO.log.debug("Building StorageSpaceTO with " + spaceData); + log.debug("Building StorageSpaceTO with {}" , spaceData); if (spaceData.getOwner() != null) { ownerName = spaceData.getOwner().getDn(); voName = getVOName(spaceData.getOwner()); diff --git a/src/main/java/it/grid/storm/persistence/model/TapeRecallTO.java b/src/main/java/it/grid/storm/persistence/model/TapeRecallTO.java index 0ab0aa78..f95ae0b7 100644 --- a/src/main/java/it/grid/storm/persistence/model/TapeRecallTO.java +++ b/src/main/java/it/grid/storm/persistence/model/TapeRecallTO.java @@ -440,18 +440,16 @@ public void forceStatusUpdateInstants(Date inProgressInstant, || TapeRecallStatus.isFinalStatus(this.status.getStatusId())) { this.inProgressInstant = inProgressInstant; } else { - log - .error("Unable to force the in progress transition time-stamp, current status " - + this.status + " is not congruent"); + log.error("Unable to force the in progress transition time-stamp. " + + "Invalid status: {}", status); } } if (finalStateInstant != null) { if (TapeRecallStatus.isFinalStatus(this.status.getStatusId())) { this.finalStateInstant = finalStateInstant; } else { - log - .error("Unable to force the in final status transition time-stamp, current status " - + this.status + " is not final"); + log.error("Unable to force the in final status transition time-stamp. " + + "current status {} is not finale", status); } } } @@ -464,9 +462,7 @@ public void setFakeRequestToken() { .randomUUID().toString().substring(FAKE_PREFIX.length())), Calendar .getInstance().getTime())); } catch (InvalidTRequestTokenAttributesException e) { - // never thrown - log.error("Unexpected InvalidTRequestTokenAttributesException: " - + e.getMessage()); + log.error(e.getMessage(), e); } } } diff --git a/src/main/java/it/grid/storm/persistence/model/TransferObjectDecodingException.java b/src/main/java/it/grid/storm/persistence/model/TransferObjectDecodingException.java index 5c8efe12..32f20d52 100644 --- a/src/main/java/it/grid/storm/persistence/model/TransferObjectDecodingException.java +++ b/src/main/java/it/grid/storm/persistence/model/TransferObjectDecodingException.java @@ -10,12 +10,8 @@ public class TransferObjectDecodingException extends Exception { public TransferObjectDecodingException(String string) { - super(string); } - /** - * - */ private static final long serialVersionUID = -6613354584884266536L; } diff --git a/src/main/java/it/grid/storm/persistence/model/VOInfoStatusTO.java b/src/main/java/it/grid/storm/persistence/model/VOInfoStatusTO.java deleted file mode 100644 index 0f77bdc7..00000000 --- a/src/main/java/it/grid/storm/persistence/model/VOInfoStatusTO.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -package it.grid.storm.persistence.model; - -import it.grid.storm.info.model.VOInfoStatusData; -import it.grid.storm.persistence.PersistenceDirector; - -import java.io.Serializable; - -import org.slf4j.Logger; - -/** - *

- * Title: - *

- * - *

- * Description: - *

- * - *

- * Copyright: Copyright (c) 2006 - *

- * - *

- * Company: INFN-CNAF - *

- * - * @author R.Zappi - * @version 1.0 - */ - -/** - * - * @author Riccardo Zappi - riccardo.zappi AT cnaf.infn.it - * @version $Id $ - */ -public class VOInfoStatusTO implements Serializable, Comparable { - - private static final Logger log = PersistenceDirector.getLogger(); - - private String voInfoLocalIdentifier = null; - private long usedSpaceNearLine = -1L; - private long availableSpaceNearLine = -1L; - private long ReservedSpaceNearLine = -1L; - private long usedSpaceOnLine = -1L; - private long availableSpaceOnLine = -1L; - private long ReservedSpaceOnLine = -1L; - - /** - * No-arg constructor for JavaBean tools. - */ - public VOInfoStatusTO() { - - super(); - } - - /** - * Minimal constructor. - * - * @param maker - * User - */ - public VOInfoStatusTO(String voInfoLocalIdentifier) { - - this.voInfoLocalIdentifier = voInfoLocalIdentifier; - } - - /** - * Constructor from Domain Object - * - * @param spaceData - * SpaceData - */ - public VOInfoStatusTO(VOInfoStatusData voInfoData) { - - if (voInfoData != null) { - log.debug("Building VOInfoStatusTO with " + voInfoData); - if (voInfoData.getVOInfoLocalID() != null) { - } - } - } - - /** - * - * @param o - * Object - * @return int - */ - public int compareTo(Object o) { - - return 0; - } - -} diff --git a/src/main/java/it/grid/storm/persistence/util/db/DBConnection.java b/src/main/java/it/grid/storm/persistence/util/db/DBConnection.java index bd2f7e52..7441759e 100644 --- a/src/main/java/it/grid/storm/persistence/util/db/DBConnection.java +++ b/src/main/java/it/grid/storm/persistence/util/db/DBConnection.java @@ -27,11 +27,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -// DBConnection - manages one connection to the DataBase -// --->could be moved to be inner class of DBConnectionPool -// --->could keep track of things about itself, such as when last used and by -// what - public class DBConnection implements DataSourceConnectionFactory { @@ -40,84 +35,54 @@ public class DBConnection implements DataSourceConnectionFactory private Connection connection = null; private DataBaseStrategy db; - /*********************************************************** - * CLASS Constructors - */ - - /** - * - * @param db - * DataBase - */ public DBConnection(DataBaseStrategy db) throws PersistenceException { - // register the driver - this.db = db; try { Class.forName(db.getDriverName()).newInstance(); } catch (Exception ex) { - log.error("Exception while getting driver", ex); - throw new PersistenceException("Driver loading problem"); - + log.error("Exception while getting JDBC driver: {}", ex.getMessage(), ex); + throw new PersistenceException("Driver loading problem", ex); } } + + private void handleSQLException(SQLException e) throws PersistenceException{ + + log.error("SQL Error: {}, SQLState: {}, VendorError: {}.", + e.getMessage(), + e.getSQLState(), + e.getErrorCode(), + e); + + throw new PersistenceException(e); + + } - /*********************************************************** - * PUBLIC METHODs - */ - - /** - * - * @return Connection - * @throws PersistenceException - */ public Connection borrowConnection() throws PersistenceException { Connection result = null; try { result = getConnection(); - } catch (SQLException sqle) { - log.error("SQLException: " + sqle.getMessage() + "/n" + "SQLState: " - + sqle.getSQLState() + "/n" + "VendorError: " + sqle.getErrorCode(), - sqle); - throw new PersistenceException("Creating new connection problem", sqle); + } catch (SQLException e) { + handleSQLException(e); } return result; } - /** - * - * @param con - * Connection - * @throws PersistenceException - */ public void giveBackConnection(Connection con) throws PersistenceException { if (connection != null) { try { shutdown(); - } catch (SQLException sqle) { - log.error("SQLException: " + sqle.getMessage() + "/n" + "SQLState: " - + sqle.getSQLState() + "/n" + "VendorError: " + sqle.getErrorCode(), - sqle); - throw new PersistenceException("Closing existing connection problem", - sqle); + } catch (SQLException e) { + handleSQLException(e); } } else { throw new PersistenceException("Closing NON-Existing connection"); } } - /*********************************************************** - * PRIVATE METHODs - */ - - /** - * - * @return Connection - */ private Connection getConnection() throws SQLException { if (connection == null) { @@ -128,18 +93,10 @@ private Connection getConnection() throws SQLException { return connection; } - /** - * - * @throws SQLException - */ private void shutdown() throws SQLException { connection.close(); // if there are no other open connection connection = null; - - // db writes out to files and shuts down - // this happens anyway at garbage collection - // when program ends } } diff --git a/src/main/java/it/grid/storm/persistence/util/db/DBConnectionPool.java b/src/main/java/it/grid/storm/persistence/util/db/DBConnectionPool.java index b56d2f7a..2eceaf04 100644 --- a/src/main/java/it/grid/storm/persistence/util/db/DBConnectionPool.java +++ b/src/main/java/it/grid/storm/persistence/util/db/DBConnectionPool.java @@ -37,20 +37,11 @@ public class DBConnectionPool implements DataSourceConnectionFactory { private static DBConnectionPool instance = new DBConnectionPool(); private static long handle = -1; - /*********************************************************** - * CLASS Constructors - */ - - /** - * Private constructor. Singleton pattern. - */ private DBConnectionPool() { - super(); } public static DBConnectionPool getPoolInstance() { - if (handle == -1) { return null; } else { @@ -58,30 +49,23 @@ public static DBConnectionPool getPoolInstance() { } } - /** - * - * @param db - * DataBase - * @param maxActive - * int - * @param maxWait - * int - */ public static void initPool(DataBaseStrategy db, int maxActive, int maxWait) throws PersistenceException { - instance.init(db, maxActive, maxWait); } - - /*********************************************************** - * PUBLIC METHODs - */ - - /** - * - * @return Connection - * @throws PersistenceException - */ + + + private void handleSQLException(SQLException e) throws PersistenceException{ + + log.error("SQL Error: {}, SQLState: {}, VendorError: {}.", + e.getMessage(), + e.getSQLState(), + e.getErrorCode(), + e); + + throw new PersistenceException(e); + + } public Connection borrowConnection() throws PersistenceException { Connection result = null; @@ -90,48 +74,25 @@ public Connection borrowConnection() throws PersistenceException { } try { result = sharedDatasource.getConnection(); - } catch (SQLException sqle) { - log.error("SQLException: " + sqle.getMessage() + "/n" + "SQLState: " - + sqle.getSQLState() + "/n" + "VendorError: " + sqle.getErrorCode(), - sqle); - throw new PersistenceException("Problem retrieving connection from pool", - sqle); + } catch (SQLException e) { + handleSQLException(e); } return result; } - /** - * - * @param con - * Connection - * @throws PersistenceException - */ public void giveBackConnection(Connection con) throws PersistenceException { if (con != null) { try { shutdown(con); - } catch (SQLException sqle) { - log.error("SQLException: " + sqle.getMessage() + "/n" + "SQLState: " - + sqle.getSQLState() + "/n" + "VendorError: " + sqle.getErrorCode(), - sqle); - throw new PersistenceException("Closing existing connection problem", - sqle); + } catch (SQLException e) { + handleSQLException(e); } } else { throw new PersistenceException("Closing NON-Existing connection"); } } - /******************************************** - * VALIDATION Methods - */ - - /** - * - * @return String - * @throws PersistenceException - */ public String getPoolInfo() throws PersistenceException { String result = ""; @@ -154,19 +115,6 @@ public String getPoolInfo() throws PersistenceException { return result; } - /*********************************************************** - * PRIVATE METHODs - */ - - /** - * - * @param db - * DataBase - * @param maxActive - * int - * @param maxWait - * int - */ private void init(DataBaseStrategy db, int maxActive, int maxWait) { instance.setDatabaseStrategy(db); @@ -174,7 +122,7 @@ private void init(DataBaseStrategy db, int maxActive, int maxWait) { try { connectionPoolDatasource.setDriver(db.getDriverName()); } catch (Exception ex) { - log.error("Exception while getting driver", ex); + log.error("Exception while getting driver: {}", ex.getMessage(), ex); } connectionPoolDatasource.setUrl(db.getConnectionString()); @@ -203,9 +151,9 @@ private void shutdown(Connection conn) throws SQLException { public static void printInfo(DBConnectionPool pool) { try { - log.info("DATABASE POOL INFO: " + pool.getPoolInfo()); + log.info("DATABASE POOL INFO: {}" , pool.getPoolInfo()); } catch (PersistenceException ex2) { - log.error(ex2.getMessage()); + log.error(ex2.getMessage(),ex2); } } diff --git a/src/main/java/it/grid/storm/persistence/util/db/DataBaseStrategy.java b/src/main/java/it/grid/storm/persistence/util/db/DataBaseStrategy.java index 0c28190b..0c436693 100644 --- a/src/main/java/it/grid/storm/persistence/util/db/DataBaseStrategy.java +++ b/src/main/java/it/grid/storm/persistence/util/db/DataBaseStrategy.java @@ -31,22 +31,17 @@ public class DataBaseStrategy { private String dbUsr; private String dbPwd; private SQLFormat formatter; - // public static final DataBaseStrategy HSQL = new DataBaseStrategy("hsql", - // "org.hsqldb.jdbcDriver", - // "jdbc:hsqldb://", null); + public static final DataBaseStrategy MYSQL = new DataBaseStrategy("mysql", "com.mysql.jdbc.Driver", "jdbc:mysql://", new MySqlFormat()); + private static final Map DATABASES = new HashMap(); static { DataBaseStrategy.DATABASES.put(DataBaseStrategy.MYSQL.toString(), DataBaseStrategy.MYSQL); - // DATABASES.put(HSQL.toString(), HSQL); } - /** - * Prevent instantiation and subclassing with a private constructor. - */ private DataBaseStrategy(String dbmsVendor, String driverName, String prefix, SQLFormat formatter) { @@ -56,15 +51,12 @@ private DataBaseStrategy(String dbmsVendor, String driverName, String prefix, this.formatter = formatter; } - // ********************** Common Methods ********************** // public String getDbmsVendor() { - return dbmsVendor; } public String getDriverName() { - return driverName; } @@ -146,7 +138,6 @@ public String toString() { return dbmsVendor; } - // ********************** Common CLASS Methods ********************** // public static DataBaseStrategy getInstance(String vendor) { diff --git a/src/main/java/it/grid/storm/persistence/util/helper/TapeRecallMySQLHelper.java b/src/main/java/it/grid/storm/persistence/util/helper/TapeRecallMySQLHelper.java index ece17c5e..ca8490cf 100644 --- a/src/main/java/it/grid/storm/persistence/util/helper/TapeRecallMySQLHelper.java +++ b/src/main/java/it/grid/storm/persistence/util/helper/TapeRecallMySQLHelper.java @@ -33,10 +33,6 @@ public class TapeRecallMySQLHelper extends SQLHelper { - @SuppressWarnings("unused") - private static final Logger log = LoggerFactory - .getLogger(TapeRecallMySQLHelper.class); - private final static String TABLE_NAME = "tape_recall"; // primary key COL_TASK_ID + COL_REQUEST_TOKEN diff --git a/src/main/java/it/grid/storm/rest/JettyThread.java b/src/main/java/it/grid/storm/rest/JettyThread.java index 75052393..af4e9b14 100644 --- a/src/main/java/it/grid/storm/rest/JettyThread.java +++ b/src/main/java/it/grid/storm/rest/JettyThread.java @@ -1,6 +1,8 @@ package it.grid.storm.rest; import org.eclipse.jetty.server.Server; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Thread that starts a Jetty server. The thread is passed an instance of @@ -12,6 +14,8 @@ */ public class JettyThread extends Thread { + private static final Logger log = LoggerFactory.getLogger(JettyThread.class); + /** * The {@link Server} object. */ @@ -39,8 +43,8 @@ public void run() { server.join(); } catch (Exception e) { + log.error(e.getMessage(), e); - e.printStackTrace(); System.exit(1); } } diff --git a/src/main/java/it/grid/storm/rest/RestService.java b/src/main/java/it/grid/storm/rest/RestService.java index 0ae26f26..0016cd7c 100644 --- a/src/main/java/it/grid/storm/rest/RestService.java +++ b/src/main/java/it/grid/storm/rest/RestService.java @@ -63,7 +63,8 @@ private static int getPort() { int restServicePort = config.getRestServicesPort(); - log.debug("RESTFul services will be listening on port " + restServicePort); + log.debug("RESTFul services will be listening on port {}", + restServicePort); return restServicePort; } @@ -135,7 +136,7 @@ public static void startServer() throws Exception { */ public static void stop() throws Exception { - log.info("Starting RESTFul services ... "); + log.info("Stopping RESTFul services ... "); server.stop(); From be75b5afda5806e8fccc7e58cb2be983e4c96c21 Mon Sep 17 00:00:00 2001 From: Andrea Ceccanti Date: Thu, 6 Feb 2014 15:54:16 +0100 Subject: [PATCH 28/45] More logging rationalization work --- .../filesystem/ReservationException.java | 8 +- .../namespace/DefaultValuesInterface.java | 20 -- .../namespace/ExpiredSpaceTokenException.java | 20 -- .../it/grid/storm/namespace/Namespace.java | 110 +++------ .../storm/namespace/NamespaceDirector.java | 26 +- .../storm/namespace/NamespaceException.java | 20 -- .../storm/namespace/NamespaceInterface.java | 48 +--- .../storm/namespace/NamespaceValidator.java | 81 ++----- .../java/it/grid/storm/namespace/StoRI.java | 56 ++--- .../it/grid/storm/namespace/StoRIImpl.java | 226 ++++++------------ .../it/grid/storm/namespace/TURLBuilder.java | 79 +----- .../namespace/TURLBuildingException.java | 10 +- .../namespace/UnapprochableSurlException.java | 8 +- .../storm/namespace/VirtualFSInterface.java | 53 ---- 14 files changed, 177 insertions(+), 588 deletions(-) diff --git a/src/main/java/it/grid/storm/filesystem/ReservationException.java b/src/main/java/it/grid/storm/filesystem/ReservationException.java index 8f4f5651..7e8f948c 100644 --- a/src/main/java/it/grid/storm/filesystem/ReservationException.java +++ b/src/main/java/it/grid/storm/filesystem/ReservationException.java @@ -37,8 +37,14 @@ public ReservationException(String error) { if (error != null) this.error = error; } + + public ReservationException(String error, Throwable cause) { + super(error, cause); + } - public String toString() { + + + public String toString() { return error; } diff --git a/src/main/java/it/grid/storm/namespace/DefaultValuesInterface.java b/src/main/java/it/grid/storm/namespace/DefaultValuesInterface.java index 08a92795..1dbbd369 100644 --- a/src/main/java/it/grid/storm/namespace/DefaultValuesInterface.java +++ b/src/main/java/it/grid/storm/namespace/DefaultValuesInterface.java @@ -19,26 +19,6 @@ import it.grid.storm.srm.types.*; -/** - *

- * Title: - *

- * - *

- * Description: - *

- * - *

- * Copyright: Copyright (c) 2006 - *

- * - *

- * Company: - *

- * - * @author not attributable - * @version 1.0 - */ public interface DefaultValuesInterface { public TLifeTimeInSeconds getDefaultSpaceLifetime(); diff --git a/src/main/java/it/grid/storm/namespace/ExpiredSpaceTokenException.java b/src/main/java/it/grid/storm/namespace/ExpiredSpaceTokenException.java index 6ed3cb00..6c3300f9 100644 --- a/src/main/java/it/grid/storm/namespace/ExpiredSpaceTokenException.java +++ b/src/main/java/it/grid/storm/namespace/ExpiredSpaceTokenException.java @@ -17,26 +17,6 @@ package it.grid.storm.namespace; -/** - *

- * Title: - *

- * - *

- * Description: - *

- * - *

- * Copyright: Copyright (c) 2007 - *

- * - *

- * Company: - *

- * - * @author not attributable - * @version 1.0 - */ public class ExpiredSpaceTokenException extends Exception { public ExpiredSpaceTokenException() { diff --git a/src/main/java/it/grid/storm/namespace/Namespace.java b/src/main/java/it/grid/storm/namespace/Namespace.java index 274a3be8..e3ca4e00 100644 --- a/src/main/java/it/grid/storm/namespace/Namespace.java +++ b/src/main/java/it/grid/storm/namespace/Namespace.java @@ -53,26 +53,6 @@ import org.slf4j.Logger; -/** - *

- * Title: - *

- * - *

- * Description: - *

- * - *

- * Copyright: Copyright (c) 2006 - *

- * - *

- * Company: INFN-CNAF and ICTP/eGrid project - *

- * - * @author Riccardo Zappi - * @version 1.0 - */ public class Namespace implements NamespaceInterface { private static final String SPACE_FILE_NAME_SUFFIX = ".space"; @@ -80,12 +60,6 @@ public class Namespace implements NamespaceInterface { private final Logger log = NamespaceDirector.getLogger(); private final NamespaceParser parser; - /** - * Class CONSTRUCTOR - * - * @param parser - * NamespaceParser - */ public Namespace(NamespaceParser parser) { this.parser = parser; @@ -379,7 +353,8 @@ public VirtualFSInterface resolveVFSbySURL(TSURL surl, GridUserInterface user) } MappingRule winnerRule = getWinnerRule(surl, vfsApproachable); - log.debug("For surl " + surl + " the winner Rule is " + winnerRule.getRuleName()); + log.debug("For surl {} the winner rule is {}", surl, + winnerRule.getRuleName()); return winnerRule.getMappedFS(); } @@ -601,7 +576,7 @@ private MappingRule getWinnerRule(TSURL surl, } String stfnPath = surl.sfn().stfn().toString(); - log.debug("Searching winner rule for " + stfnPath); + log.debug("Searching winner rule for {}", stfnPath); MappingRule winnerRule = null; int minDistance = Integer.MAX_VALUE; for (MappingRule rule : rules) { @@ -643,8 +618,9 @@ public VirtualFSInterface getWinnerVFS(String absolutePath) while (scan.hasMoreElements()) { vfs_root = (String) scan.nextElement(); int d = NamespaceUtil.computeDistanceFromPath(vfs_root, path); - log.debug("Pondering VFS Root :'" + vfs_root + "' against '" + path - + "' DISTANCE = " + d); + log.debug("Pondering VFS Root '{}' against '{}'. Distance = {}", + vfs_root, path, d); + if (d < distance) { boolean enclosed = NamespaceUtil.isEnclosed(vfs_root, absolutePath); if (enclosed) { // Found a compatible Mapping rule @@ -652,61 +628,59 @@ public VirtualFSInterface getWinnerVFS(String absolutePath) vfsWinner = table.get(vfs_root); vfsNameWinner = vfsWinner.getAliasName(); vfs_root_winner = vfs_root; - log.debug("Partial winner is " + vfs_root_winner + " (VFS :'" - + vfsNameWinner + "'"); + log.debug("Partial winner is {} (VFS: {})", + vfs_root_winner, vfsNameWinner); found = true; } } } if (found) { - log.debug("VFS winner is " + vfs_root_winner + " (VFS :'" + vfsNameWinner - + "'"); + log.debug("Partial winner is {} (VFS: {})", + vfs_root_winner, vfsNameWinner); } else { - log.error("Unable to found a VFS compatible with path :'" + absolutePath - + "'"); + log.error("Unable to found a VFS compatible with path: '{}'", + absolutePath); throw new NamespaceException( "Unable to found a VFS compatible with path :'" + absolutePath + "'"); } return vfsWinner; } - /***************************************** - * Methods used for manage SPACE - *****************************************/ - public String makeSpaceFileURI(GridUserInterface user) throws NamespaceException { String result = null; TreeSet appRules = new TreeSet( getApproachableRules(user)); - log.debug("Compatible Approachable rules : " + appRules); + + log.debug("Compatible Approachable rules: {}", + appRules); + if (appRules.isEmpty()) { if (user instanceof AbstractGridUser) { - log.error("No approachable rules found for user with DN='" - + user.getDn() + "' and VO = '" + ((AbstractGridUser) user).getVO() - + "'"); + + log.error("No approachable rules found for user with DN='{}' " + + "and VO='{}'", user.getDn(), + ((AbstractGridUser) user).getVO()); + throw new NamespaceException( "No approachable rules found for user with DN='" + user.getDn() + "' and VO = '" + ((AbstractGridUser) user).getVO() + "'"); } else { - log.error("No approachable rules found for user with DN='" - + user.getDn() + "' User certificate has not VOMS extension"); + log.error("No approachable rules found for user with DN='{}'. " + + "No VOMS extensions found.", user.getDn()); + throw new NamespaceException( "No approachable rules found for user with DN='" + user.getDn() + "' User certificate has not VOMS extension"); } } ApproachableRule firstAppRule = appRules.first(); - log.debug("Default APP_RULE is the first (in respsect of name): " - + firstAppRule); - // Retrieve the Relative Path for Space Files - String spacePath = getRelativePathForSpaceFile(firstAppRule); + log.debug("First approachable rule: {}", firstAppRule); - // Retrieve default VFS for the first Approachable Rule compatible for the - // user. + String spacePath = getRelativePathForSpaceFile(firstAppRule); VirtualFSInterface vfs = getApproachableDefaultVFS(firstAppRule); - log.debug("Default VFS for Space Files : " + vfs); + log.debug("Default VFS for Space Files: {}", vfs); // Build the Space file path String rootPath = vfs.getRootPath(); @@ -726,14 +700,11 @@ public String getRelativePathForSpaceFile(ApproachableRule rule) { public String makeSpaceFileNameForUser(GridUserInterface user) { - /** - * @todo Instead of Local User name, extract from DN the NAME_SURNAME - */ String userName = null; try { userName = user.getLocalUser().getLocalUserName(); } catch (CannotMapUserException ex) { - log.error("Cannot map user."); + log.error("Cannot map user: {}", ex.getMessage(), ex); } if (userName == null) { userName = "unknown"; @@ -812,7 +783,7 @@ public VirtualFSInterface getApproachableDefaultVFS(ApproachableRule appRule) List listVFS = appRule.getApproachableVFS(); if (listVFS != null && !listVFS.isEmpty()) { - log.debug(" VFS List = " + listVFS); + log.debug(" VFS List = {}" , listVFS); // Looking for the default element, signed with a '*' char at the end // Various VFS names exists. The default is '*' tagged or the first. String vfsName = null; @@ -828,9 +799,9 @@ public VirtualFSInterface getApproachableDefaultVFS(ApproachableRule appRule) } else { defaultVFSName = vfsName; } - log.debug(" Default VFS detected : '" + defaultVFSName + "'"); + log.debug(" Default VFS detected : '{}'",defaultVFSName); defaultVFS = parser.getVFS(defaultVFSName); - log.debug(" VFS Description " + defaultVFS); + log.debug(" VFS Description {}", defaultVFS); return defaultVFS; } else { throw new NamespaceException( @@ -846,20 +817,8 @@ private static boolean matchSubject(ApproachableRule approachableRule, return result; } - /****************************************** - * VERSION 1.4 * - *******************************************/ - /** - * - * @param spaceToken - * TSpaceToken - * @return VirtualFSInterface - * @throws NamespaceException - */ public VirtualFSInterface resolveVFSbySpaceToken(TSpaceToken spaceToken) throws NamespaceException { - - /** @todo IMPLEMENT */ return null; } @@ -882,7 +841,7 @@ public boolean isStfnFittingSomewhere(String surlString, stfnRoots.add(stfnRoot); } } - log.debug("FITTING: List of StFNRoots approachables = " + stfnRoots); + log.debug("FITTING: List of StFNRoots approachables = {}", stfnRoots); // Build SURL and retrieve the StFN part. String stfn = SURL.makeSURLfromString(surlString).getStFN(); @@ -893,14 +852,13 @@ public boolean isStfnFittingSomewhere(String surlString, for (Object element : stfnRoots) { stfnRoot = (String) element; - log.debug("FITTING: considering StFNRoot = " + stfnRoot - + " against StFN = " + stfn); + log.debug("FITTING: considering StFNRoot = {} agaist StFN = {}", + stfnRoot, stfn); ArrayList stfnRootArray = (ArrayList) NamespaceUtil .getPathElement(stfnRoot); stfnRootArray.retainAll(stfnArray); if (!(stfnRootArray.isEmpty())) { result = true; - log.debug("FIT!"); break; } } diff --git a/src/main/java/it/grid/storm/namespace/NamespaceDirector.java b/src/main/java/it/grid/storm/namespace/NamespaceDirector.java index 60dd6ee1..5425e964 100644 --- a/src/main/java/it/grid/storm/namespace/NamespaceDirector.java +++ b/src/main/java/it/grid/storm/namespace/NamespaceDirector.java @@ -29,26 +29,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - *

- * Title: - *

- * - *

- * Description: - *

- * - *

- * Copyright: Copyright (c) 2006 - *

- * - *

- * Company: INFN-CNAF and ICTP/eGrid project - *

- * - * @author Riccardo Zappi - * @version 1.0 - */ public class NamespaceDirector { private static final Logger log = LoggerFactory @@ -121,9 +101,9 @@ public static void initializeDirector(boolean verboseMode, boolean testingMode) } - log.debug("Namespace Configuration PATH : " + configurationPATH); - log.debug("Namespace Configuration FILENAME : " + namespaceConfigFileName); - log.debug("Namespace Configuration GLANCE RATE : " + refreshInSeconds); + log.debug("Namespace Configuration PATH : {}" , configurationPATH); + log.debug("Namespace Configuration FILENAME : {}" , namespaceConfigFileName); + log.debug("Namespace Configuration GLANCE RATE : {}" , refreshInSeconds); parser = new XMLNamespaceParser(loader, verboseMode, testingMode); namespaceIstance = new Namespace(parser); diff --git a/src/main/java/it/grid/storm/namespace/NamespaceException.java b/src/main/java/it/grid/storm/namespace/NamespaceException.java index 2c227c36..88e8ec7a 100644 --- a/src/main/java/it/grid/storm/namespace/NamespaceException.java +++ b/src/main/java/it/grid/storm/namespace/NamespaceException.java @@ -17,26 +17,6 @@ package it.grid.storm.namespace; -/** - *

- * Title: - *

- * - *

- * Description: - *

- * - *

- * Copyright: Copyright (c) 2006 - *

- * - *

- * Company: - *

- * - * @author not attributable - * @version 1.0 - */ public class NamespaceException extends Exception { public NamespaceException() { diff --git a/src/main/java/it/grid/storm/namespace/NamespaceInterface.java b/src/main/java/it/grid/storm/namespace/NamespaceInterface.java index 1869a85e..1099ddd4 100644 --- a/src/main/java/it/grid/storm/namespace/NamespaceInterface.java +++ b/src/main/java/it/grid/storm/namespace/NamespaceInterface.java @@ -29,51 +29,6 @@ import java.util.Collection; import java.util.List; -/** - *

- * Title: - *

- * - *

- * Description - *

- * This interface represents the main entry point for namespace operation. The - * results of retrived informations depends on namespace configuration. The - * namespace configuration is read back every time that it changes, so it is - * possible mutates the namespace configuration at run time. - * - * - * The namespace configuration is divided in three main section: 1) Virtual File - * System definition 2) Mapping rules definition 3) Approachable rules - * definition - * - * - * VFS Configuration - * - * - * - * Mapping Rule - * - * - * - * Approachable Rule - * - * - * - * - *

- * - *

- * Copyright: Copyright (c) 2006 - *

- * - *

- * Company: INFN-CNAF and ICTP/eGrid project - *

- * - * @author Riccardo Zappi - * @version 1.0 - */ public interface NamespaceInterface { /** @@ -465,5 +420,4 @@ public VirtualFSInterface resolveVFSbyRoot(String absolutePath) public VirtualFSInterface resolveVFSbySpaceToken(TSpaceToken spaceToken) throws NamespaceException; - -} +} \ No newline at end of file diff --git a/src/main/java/it/grid/storm/namespace/NamespaceValidator.java b/src/main/java/it/grid/storm/namespace/NamespaceValidator.java index 47b14c82..eb84dae3 100644 --- a/src/main/java/it/grid/storm/namespace/NamespaceValidator.java +++ b/src/main/java/it/grid/storm/namespace/NamespaceValidator.java @@ -24,32 +24,11 @@ import org.xml.sax.SAXParseException; import org.xml.sax.helpers.DefaultHandler; -/** - *

- * Title: - *

- * - *

- * Description: - *

- * - *

- * Copyright: Copyright (c) 2006 - *

- * - *

- * Company: INFN-CNAF and ICTP/eGrid project - *

- * - * @author Riccardo Zappi - * @version 1.0 - */ public class NamespaceValidator { private Logger log = LoggerFactory.getLogger(NamespaceValidator.class); public boolean validateSchema(String SchemaUrl, String XmlDocumentUrl) { - boolean valid = false; SAXParser parser = new SAXParser(); try { @@ -71,36 +50,21 @@ public boolean validateSchema(String SchemaUrl, String XmlDocumentUrl) { log.info("Namespace Document is valid with Schema"); valid = true; } - } catch (java.io.IOException ioe) { - log.error("IOException" + ioe.getMessage()); - } catch (SAXException e) { - log.error("SAXException" + e.getMessage()); + } catch (Throwable e) { + log.error(e.getMessage(), e); } return valid; } - /** - * manageErrorWithinNamespace - * - * @param handler - * Validator - */ private void manageErrorWithinNamespace( it.grid.storm.namespace.NamespaceValidator.Validator handler) { - StringBuffer sb = new StringBuffer(); - sb.append("##############################################" + "\n"); - sb.append("### WARNING : namespace.xml INVALID ###" + "\n"); - sb.append("##############################################" + "\n"); - sb.append("# Please check it. " + "\n"); - sb.append("# The error is : " + handler.saxParseException.getMessage() - + "\n"); - sb.append("# at line : " + handler.saxParseException.getLineNumber() - + ", column " + handler.saxParseException.getColumnNumber() + "\n"); - sb.append("# in entity : " + handler.saxParseException.getSystemId() - + "\n"); - sb.append("##############################################" + "\n"); - log.error("\n" + sb.toString()); + log.error("namespace.xml validation error."); + log.error("Error: {} line: {}, column: {}, entity: {}", + handler.saxParseException.getMessage(), + handler.saxParseException.getLineNumber(), + handler.saxParseException.getColumnNumber(), + handler.saxParseException.getSystemId()); } private class Validator extends DefaultHandler { @@ -111,11 +75,12 @@ private class Validator extends DefaultHandler { @Override public void error(SAXParseException exception) throws SAXException { - log.error("ERROR : " + exception.getMessage()); - log.error(" at line " + exception.getLineNumber() + ", column " - + exception.getColumnNumber()); - log.error(" in entity " + exception.getSystemId()); - + log.error("XML error: {}. Line: {}, column: {}, entity: {}", + exception.getMessage(), + exception.getLineNumber(), + exception.getColumnNumber(), + exception.getSystemId()); + validationError = true; saxParseException = exception; } @@ -123,10 +88,11 @@ public void error(SAXParseException exception) throws SAXException { @Override public void fatalError(SAXParseException exception) throws SAXException { - log.error("FATAL ERROR: " + exception.getMessage()); - log.error(" at line " + exception.getLineNumber() + ", column " - + exception.getColumnNumber()); - log.error(" in entity " + exception.getSystemId()); + log.error("XML FATAL error: {}. Line: {}, column: {}, entity: {}", + exception.getMessage(), + exception.getLineNumber(), + exception.getColumnNumber(), + exception.getSystemId()); validationError = true; saxParseException = exception; @@ -135,10 +101,11 @@ public void fatalError(SAXParseException exception) throws SAXException { @Override public void warning(SAXParseException exception) throws SAXException { - log.error("Warning: " + exception.getMessage()); - log.error(" at line " + exception.getLineNumber() + ", column " - + exception.getColumnNumber()); - log.error(" in entity " + exception.getSystemId()); + log.warn("XML warning: {}. Line: {}, column: {}, entity: {}", + exception.getMessage(), + exception.getLineNumber(), + exception.getColumnNumber(), + exception.getSystemId()); } } diff --git a/src/main/java/it/grid/storm/namespace/StoRI.java b/src/main/java/it/grid/storm/namespace/StoRI.java index 6d06c961..92ac6e61 100644 --- a/src/main/java/it/grid/storm/namespace/StoRI.java +++ b/src/main/java/it/grid/storm/namespace/StoRI.java @@ -17,40 +17,29 @@ package it.grid.storm.namespace; -import java.util.*; - -import it.grid.storm.common.types.*; -import it.grid.storm.filesystem.*; -import it.grid.storm.namespace.model.*; -import it.grid.storm.srm.types.*; -import it.grid.storm.namespace.ExpiredSpaceTokenException; +import it.grid.storm.common.types.PFN; +import it.grid.storm.common.types.StFN; +import it.grid.storm.common.types.TURLPrefix; +import it.grid.storm.filesystem.LocalFile; +import it.grid.storm.filesystem.ReservationException; +import it.grid.storm.filesystem.Space; +import it.grid.storm.namespace.model.MappingRule; +import it.grid.storm.namespace.model.StoRIType; +import it.grid.storm.srm.types.TDirOption; +import it.grid.storm.srm.types.TLifeTimeInSeconds; +import it.grid.storm.srm.types.TSURL; +import it.grid.storm.srm.types.TSizeInBytes; +import it.grid.storm.srm.types.TSpaceToken; +import it.grid.storm.srm.types.TTURL; + +import java.util.ArrayList; +import java.util.Date; +import java.util.List; public interface StoRI { - /***************************************************************************** - * BUILDING METHODs - ****************************************************************************/ - public void setStoRIType(StoRIType type); - /***************************************************************************** - * READ METHODs - ***************************************************************************/ - - /** - * getTURL - * - * Create new Transport URL selecting correct protocol between - * TransferProtocols specified by input parameter and TransferProtocol - * assigned at Virtual Organization at Creation time. * - * - * @param prefixOfAcceptedTransferProtocols - * TURLPrefix Collection of @link TransferProcol specified in SRM - * Request. - * @return TTURL : TransportURL for StoRI. - * @throws InvalidGetTURLNullPrefixAttributeException - * @throws Exception - */ public TTURL getTURL(TURLPrefix prefixOfAcceptedTransferProtocols) throws IllegalArgumentException, InvalidGetTURLProtocolException, TURLBuildingException; @@ -97,10 +86,6 @@ public TTURL getTURL(TURLPrefix prefixOfAcceptedTransferProtocols) public MappingRule getMappingRule(); - /***************************************************************************** - * BUSINESS METHODs - ****************************************************************************/ - public ArrayList getChildren(TDirOption dirOption) throws InvalidDescendantsEmptyRequestException, InvalidDescendantsAuthRequestException, @@ -111,11 +96,6 @@ public ArrayList getChildren(TDirOption dirOption) public boolean hasJustInTimeACLs(); - /** - * Method that returns an ordered list of parent StoRI objects, starting from - * the root and excluding the StoRI itself. If no parents are present, an - * empty List is returned instead. - */ public List getParents(); public void allotSpaceForFile(TSizeInBytes totSize) diff --git a/src/main/java/it/grid/storm/namespace/StoRIImpl.java b/src/main/java/it/grid/storm/namespace/StoRIImpl.java index 9c3b50c5..11d41bcc 100644 --- a/src/main/java/it/grid/storm/namespace/StoRIImpl.java +++ b/src/main/java/it/grid/storm/namespace/StoRIImpl.java @@ -45,7 +45,6 @@ import it.grid.storm.namespace.naming.NamingConst; import it.grid.storm.namespace.naming.SURL; import it.grid.storm.namespace.util.userinfo.LocalGroups; -import it.grid.storm.srm.types.InvalidTSURLAttributesException; import it.grid.storm.srm.types.TDirOption; import it.grid.storm.srm.types.TLifeTimeInSeconds; import it.grid.storm.srm.types.TSURL; @@ -62,23 +61,6 @@ import org.slf4j.Logger; -/** - *

- * Title: - *

- *

- * Description: - *

- *

- * Copyright: Copyright (c) 2006 - *

- *

- * Company: INFN-CNAF and ICTP/eGrid project - *

- * - * @author Riccardo Zappi - * @version 1.0 - */ public class StoRIImpl implements StoRI { private Logger log = NamespaceDirector.getLogger(); @@ -111,58 +93,52 @@ public class StoRIImpl implements StoRI { // Boolean status for full detailed metadata private boolean volatileInformationAreSet = false; - /***************************************************************************** - * BUILDING METHODs - ****************************************************************************/ - public StoRIImpl(VirtualFSInterface vfs, MappingRule winnerRule, String relativeStFN, StoRIType type) { if (vfs != null) { this.vfs = vfs; - this.capability = (Capability) vfs.getCapabilities(); + capability = (Capability) vfs.getCapabilities(); } else { - log.error("!!! StoRI built without VFS!!?!"); + log.error("StoRI built without VFS!"); } - /** - * Retrieve from StFN the various part. - */ + if (winnerRule != null) { - this.stfnRoot = winnerRule.getStFNRoot(); - this.stfn = stfnRoot + NamingConst.SEPARATOR + relativeStFN; + stfnRoot = winnerRule.getStFNRoot(); + stfn = stfnRoot + NamingConst.SEPARATOR + relativeStFN; - this.vfsRoot = vfs.getRootPath(); + vfsRoot = vfs.getRootPath(); this.relativeStFN = relativeStFN; - this.stfnPath = NamespaceUtil.getStFNPath(stfn); + stfnPath = NamespaceUtil.getStFNPath(stfn); - this.relativePath = NamespaceUtil.consumeFileName(relativeStFN); + relativePath = NamespaceUtil.consumeFileName(relativeStFN); if (relativePath != null) { if (relativePath.startsWith(NamingConst.SEPARATOR)) { - this.relativePath = relativePath.substring(1); + relativePath = relativePath.substring(1); } } else { - this.relativePath = "/"; + relativePath = "/"; } - this.fileName = NamespaceUtil.getFileName(relativeStFN); - log.debug("StFN Filename : " + fileName + " [StFN = '" + relativeStFN - + "']"); + fileName = NamespaceUtil.getFileName(relativeStFN); + log.debug("StFN Filename : {} [StFN = '{}']", fileName, + relativeStFN); if (type == null) { if (relativeStFN.endsWith(NamingConst.SEPARATOR)) { - this.type = StoRIType.FOLDER; + type = StoRIType.FOLDER; } else { - this.type = StoRIType.UNKNOWN; + type = StoRIType.UNKNOWN; } } else { this.type = type; } } else { - log.warn("StoRI built without MAPPIG RULE!!"); + log.warn("StoRI built without mapping rule"); } } @@ -192,10 +168,11 @@ public StoRIImpl(VirtualFSInterface vfs, String stfnStr, this.stfnRoot = null; this.fileName = NamespaceUtil.getFileName(stfnStr); - log.debug("StFN Filename : " + fileName + " [StFN = '" + stfnStr + "']"); + log.debug("StFN Filename : {} [StFN = '{}']", fileName, + stfnStr); this.stfnPath = NamespaceUtil.getStFNPath(stfnStr); - log.debug("StFN StFNPath : " + stfnPath + " [StFN = '" + stfnStr + "']"); + log.debug("StFN StFNPath : {} [StFN = '{}']", stfnPath, stfnStr); } @@ -206,20 +183,19 @@ public void allotSpaceByToken(TSpaceToken token) throws ReservationException, if (spaceDriver == null) { try { this.spaceDriver = vfs.getSpaceSystemDriverInstance(); - } catch (NamespaceException ex) { - log.error("Error while retrieving Space System Driver for VFS ", ex); + } catch (NamespaceException e) { + log.error(e.getMessage(), e); throw new ReservationException( - "Error while retrieving Space System Driver for VFS "); + "Error while retrieving Space System Driver for VFS", e); } } try { vfs.useAllSpaceForFile(token, this); - } catch (NamespaceException ex1) { - log.error("Error while using Space with token '" + token + "' for " - + this.fileName, ex1); - throw new ReservationException("Error while using Space with token '" - + token + "' for " + this.fileName); + } catch (NamespaceException e) { + log.error("Error using space token {} for file {}: {}", + token, fileName, e.getMessage(),e); + throw new ReservationException(e.getMessage(), e); } } @@ -227,24 +203,22 @@ public void allotSpaceByToken(TSpaceToken token) throws ReservationException, public void allotSpaceByToken(TSpaceToken token, TSizeInBytes totSize) throws ReservationException, ExpiredSpaceTokenException { - // Retrieve SpaceSystem Driver if (spaceDriver == null) { try { this.spaceDriver = vfs.getSpaceSystemDriverInstance(); - } catch (NamespaceException ex) { - log.error("Error while retrieving Space System Driver for VFS ", ex); + } catch (NamespaceException e) { + log.error(e.getMessage(),e); throw new ReservationException( - "Error while retrieving Space System Driver for VFS "); + "Error while retrieving Space System Driver for VFS", e); } } try { vfs.useSpaceForFile(token, this, totSize); - } catch (NamespaceException ex1) { - log.error("Error while using Space with token '" + token + "' for " - + this.fileName, ex1); - throw new ReservationException("Error while using Space with token '" - + token + "' for " + this.fileName); + } catch (NamespaceException e) { + log.error("Error using space token {} for file {}: {}", + token, fileName, e.getMessage(),e); + throw new ReservationException(e.getMessage(), e); } } @@ -255,51 +229,32 @@ public void allotSpaceForFile(TSizeInBytes totSize) if (spaceDriver == null) { try { this.spaceDriver = vfs.getSpaceSystemDriverInstance(); - } catch (NamespaceException ex) { - log.error("Error while retrieving Space System Driver for VFS ", ex); + } catch (NamespaceException e) { + log.error("Error while retrieving Space System Driver for VFS {}", + e.getMessage(), e); + throw new ReservationException( - "Error while retrieving Space System Driver for VFS "); + "Error while retrieving Space System Driver for VFS", e); } } - // Make SILHOUETTE for File try { vfs.makeSilhouetteForFile(this, totSize); - } catch (NamespaceException ex1) { - log.error("Error while constructing 'Space Silhouette' for " - + this.fileName, ex1); + } catch (NamespaceException e) { + log.error(e.getMessage(),e); throw new ReservationException( - "Error while constructing 'Space Silhouette' for " + this.fileName); + "Error while constructing 'Space Silhouette' for " + this.fileName, e); } log.debug("Space built. Space " + this.getSpace().getSpaceFile().getPath()); - - // Make "space" physically in underlying file system this.getSpace().allot(); - } public String getAbsolutePath() { return vfs.getRootPath() + NamingConst.SEPARATOR + relativeStFN; } - /***************************************************************************** - * BUSINESS METHODs - ****************************************************************************/ - - /** - * Returns the SURL lifetime. This method queries the DB and retrieves also - * the startTime. The DB is queried only on the first invocation of this or - * the getFileStartTime() methods, therefore subsequent invocations of these - * two methods are computationally lighter. - * - * If the file is PERMANENT, or this StoRI refeers to a non-valid file then -1 - * is returned. - * - * @return TLifeTimeInSeconds - */ public TLifeTimeInSeconds getFileLifeTime() { - if (!(volatileInformationAreSet)) { setVolatileInformation(); } @@ -311,18 +266,6 @@ public String getFilename() { return this.fileName; } - /** - * Returns the SURL start time (time from which starts the lifetime). This - * method queries the DB and retrieves also the lifetime of the SURL. The DB - * is queried only on the first invocation of this or the getFileLifeTime() - * methods, therefore subsequent invocations of these two methods are - * computationally lighter. - * - * If the file is permanent or this StoRI refeers to a non-valid file then - * NULL is retuned! - * - * @return Date - */ public Date getFileStartTime() { if (!(volatileInformationAreSet)) { @@ -360,8 +303,8 @@ public ArrayList getChildren(TDirOption dirOption) } else { // Creation of StoRI LIST NamespaceInterface namespace = NamespaceDirector.getNamespace(); for (String childPath : pathList) { - log.debug(":Creation of new StoRI with path : " - + childPath); + log.debug(":Creation of new StoRI with path: {}", + childPath); try { StoRI childStorI = namespace.resolveStoRIbyAbsolutePath(childPath); @@ -392,7 +335,6 @@ public LocalFile getLocalFile() { } public MappingRule getMappingRule() { - return this.winnerRule; } @@ -424,9 +366,8 @@ public PFN getPFN() { if (pfn == null) { try { this.pfn = PFN.make(getAbsolutePath()); - } catch (InvalidPFNAttributeException ex) { - log.error("Unable to build the PFN in the VFS '" + getVFSName() - + "' with this path :'" + getAbsolutePath() + "'"); + } catch (InvalidPFNAttributeException e) { + log.error(e.getMessage(),e); } } return this.pfn; @@ -485,30 +426,18 @@ public TSURL getSURL() { if (this.surl == null) { try { this.surl = TSURL.makeFromStringValidate(buildSURLString()); - } catch (InvalidTSURLAttributesException ex) { - log.error("Unable to build the SURL with relative path : '" - + relativePath + "'", ex); - } catch (NamespaceException ex) { - /** @todo Handle this exception */ - log.error("Unable to build the SURL with relative path : '" - + relativePath + "'", ex); + } catch (Throwable e) { + log.error("Unable to build the SURL with relative path: {}. {}", + relativePath, e.getMessage(), e); } - } return surl; } - /***************************************************************************** - * READ METHODs - * - * @throws Exception - ***************************************************************************/ - public TTURL getTURL(TURLPrefix desiredProtocols) throws IllegalArgumentException, InvalidGetTURLProtocolException, TURLBuildingException { - // TransportProtocol protocolPrefix = null; TTURL resultTURL = null; if (desiredProtocols == null || desiredProtocols.size() == 0) { @@ -519,24 +448,26 @@ public TTURL getTURL(TURLPrefix desiredProtocols) + desiredProtocols); } else { - /** - * Retrieve Protocol to build the TURL - */ // Within the request there are some protocol preferences // Calculate the intersection between Desired Protocols and Available // Protocols ArrayList desiredP = new ArrayList( desiredProtocols.getDesiredProtocols()); + ArrayList availableP = new ArrayList( this.capability.getAllManagedProtocols()); + desiredP.retainAll(availableP); + if (desiredP.isEmpty()) { - // No match found! log .error("stori:No match with Protocol Preferences and Protocol Managed!"); throw new InvalidGetTURLProtocolException(desiredProtocols); + } else { - log.debug("Protocol matching.. Intersection size:" + desiredP.size()); + + log.debug("Protocol matching.. Intersection size: {}", + desiredP.size()); Protocol choosen = null; Authority authority = null; @@ -545,15 +476,15 @@ public TTURL getTURL(TURLPrefix desiredProtocols) while (!turlBuilt && index < desiredP.size()) { choosen = desiredP.get(index); authority = null; - log.debug("Selected Protocol :" + choosen); + log.debug("Selected Protocol: {}", choosen); if (capability.isPooledProtocol(choosen)) { log.debug("The protocol selected is in POOL Configuration"); try { authority = getPooledAuthority(choosen); } catch (BalancingStrategyException e) { log - .warn("Unable to get the pool member to be used to build the turl. BalancerException : " - + e.getMessage()); + .warn("Unable to get the pool member to be used to build the turl. BalancerException : {}", + e.getMessage()); index++; continue; } @@ -564,9 +495,9 @@ public TTURL getTURL(TURLPrefix desiredProtocols) .getManagedProtocolByScheme(choosen); if (protList.size() > 1) { // Strange case log - .warn("More than one protocol " - + choosen - + " defined but NOT in POOL Configuration. Taking the first one."); + .warn("More than one protocol {}" + + " defined but NOT in POOL Configuration. Taking the first one.", + choosen); } transProt = protList.get(0); authority = transProt.getAuthority(); @@ -585,7 +516,6 @@ public TTURL getTURL(TURLPrefix desiredProtocols) } public VirtualFSInterface getVirtualFileSystem() { - return this.vfs; } @@ -615,14 +545,13 @@ public void setGroupTapeRead() { try { localFile.setGroupOwnership(groupName); } catch (FSException e) { - log.warn("Unable to change in the new group owner ('" + groupName - + "') of the file: " + localFile.getAbsolutePath()); + log.warn("Unable to change in the new group owner '{}' for file '{}': {}", + groupName, localFile.getAbsolutePath(), e.getMessage(), e); } } else { - log.warn("The group for Read buffer in Tape support '" + groupName - + "' is not defined."); + log.warn("The group for Read buffer in Tape support '{}' is not defined", + groupName); } - } public void setGroupTapeWrite() { @@ -635,22 +564,20 @@ public void setGroupTapeWrite() { try { localFile.setGroupOwnership(groupName); } catch (FSException e) { - log.warn("Unable to change in the new group owner ('" + groupName - + "') of the file: " + localFile.getAbsolutePath()); + log.warn("Unable to change in the new group owner '{}' for file '{}': {}", + groupName, localFile.getAbsolutePath(), e.getMessage(), e); } } else { - log.warn("The group for Write buffer in Tape support '" + groupName - + "' is not defined."); + log.warn("The group for Write buffer in Tape support '{}' is not defined", + groupName); } } public void setMappingRule(MappingRule winnerRule) { - this.winnerRule = winnerRule; } public void setSpace(Space space) { - this.space = space; } @@ -688,7 +615,6 @@ public String toString() { } private String buildSURLString() throws NamespaceException { - String stfn = stfnRoot + NamingConst.SEPARATOR + relativeStFN; SURL surl = new SURL(stfn); return surl.toString(); @@ -720,10 +646,9 @@ private TTURL buildTURL(Protocol protocol, Authority authority) try { result = TURLBuilder.buildHTTPTURL(authority, this.getLocalFile()); } catch (HTTPSPluginException e) { - log.error("Unable to build the TURL for protocol " - + protocol.toString() + " for authority " + authority.toString() - + " and file " + this.getLocalFile().toString() - + " . HTTPSPluginException: " + e.getMessage()); + log.error("Unable to build the TURL for protocol {} for authority {} and file {}. {}", + protocol, authority, this.getLocalFile().toString(), + e.getMessage(),e); throw new InvalidProtocolForTURLException(e, protocol.getSchema()); } break; // HTTP Protocol @@ -731,10 +656,9 @@ private TTURL buildTURL(Protocol protocol, Authority authority) try { result = TURLBuilder.buildHTTPSTURL(authority, this.getLocalFile()); } catch (HTTPSPluginException e) { - log.error("Unable to build the TURL for protocol " - + protocol.toString() + " for authority " + authority.toString() - + " and file " + this.getLocalFile().toString() - + " . HTTPSPluginException: " + e.getMessage()); + log.error("Unable to build the TURL for protocol {} for authority {} and file {}. {}", + protocol, authority, this.getLocalFile().toString(), + e.getMessage(),e); throw new InvalidProtocolForTURLException(e, protocol.getSchema()); } break; // HTTPS Protocol diff --git a/src/main/java/it/grid/storm/namespace/TURLBuilder.java b/src/main/java/it/grid/storm/namespace/TURLBuilder.java index cb958b37..43965fd0 100644 --- a/src/main/java/it/grid/storm/namespace/TURLBuilder.java +++ b/src/main/java/it/grid/storm/namespace/TURLBuilder.java @@ -46,33 +46,22 @@ private static TTURL buildTURL(Protocol protocol, Authority authority, try { turlString = protocol.getProtocolPrefix() + authority.toString() + extraSlashes + physicalFN.getValue(); - log.debug("turlString used to build the TURL : " + turlString); + log.debug("turlString used to build the TURL : {}", turlString); turl = TTURL.makeFromString(turlString); } catch (InvalidTTURLAttributesException ex) { - log.error("Error while constructing TURL with Authority :'" + authority - + "'; EXCEP: " + ex); + log.error("Error while constructing TURL with Authority '{}': {}", + authority, ex.getMessage(), ex); } return turl; } - /** - * buildFileTURL - * - * @return TTURL - */ public static TTURL buildFileTURL(Authority authority, PFN physicalFN) { - // Authority for Protocol File is empty String extraSlashesForFile = Configuration.getInstance() .getExtraSlashesForFileTURL(); return buildTURL(Protocol.FILE, authority, extraSlashesForFile, physicalFN); } - /** - * buildGsiftpTURL - * - * @return TTURL - */ public static TTURL buildGsiftpTURL(Authority authority, PFN physicalFN) { String extraSlashesForGSIFTP = Configuration.getInstance() @@ -81,11 +70,6 @@ public static TTURL buildGsiftpTURL(Authority authority, PFN physicalFN) { physicalFN); } - /** - * buildRFIOTURL - * - * @return TTURL - */ public static TTURL buildRFIOTURL(Authority authority, PFN physicalFN) { String extraSlashesForRFIO = Configuration.getInstance() @@ -93,11 +77,6 @@ public static TTURL buildRFIOTURL(Authority authority, PFN physicalFN) { return buildTURL(Protocol.RFIO, authority, extraSlashesForRFIO, physicalFN); } - /** - * buildROOTTURL - * - * @return TTURL - */ public static TTURL buildROOTTURL(Authority authority, PFN physicalFN) { String extraSlashesForROOT = Configuration.getInstance() @@ -105,54 +84,22 @@ public static TTURL buildROOTTURL(Authority authority, PFN physicalFN) { return buildTURL(Protocol.ROOT, authority, extraSlashesForROOT, physicalFN); } - /** - * buildHHTPTURL - * - * @param authority - * @param physicalFN - * @return - * @throws Exception - * @throws IllegalStateException - */ - // TODO HTTPS TURL public static TTURL buildHTTPTURL(Authority authority, LocalFile localFile) throws HTTPSPluginException { - // ????? NEEDED ??? String extraSlashesFor?? = - // Configuration.getInstance().getExtraSlashesFor??PTURL(); - // return buildTURL(Protocol.HTTP, authority, extraSlashesForGSIFTP, - // physicalFN) ; - String serviceRelativePath = HTTPPluginManager .getHTTPSPluginInstance() - .mapLocalPath(authority.getServiceHostname(), localFile.getAbsolutePath());// HTTPSPluginInterface.MapLocalPath(localFile.getAbsolutePath()); + .mapLocalPath(authority.getServiceHostname(), localFile.getAbsolutePath()); + return buildTURL(Protocol.HTTP, authority, "", serviceRelativePath); } - /** - * buildHHTPTURL - * - * @param authority - * @param physicalFN - * @return - * @throws Exception - * @throws IllegalStateException - */ - // TODO HTTPS TURL public static TTURL buildHTTPSTURL(Authority authority, LocalFile localFile) throws HTTPSPluginException { - // ????? NEEDED ??? String extraSlashesFor?? = - // Configuration.getInstance().getExtraSlashesFor??PTURL(); - // return buildTURL(Protocol.HTTP, authority, extraSlashesForGSIFTP, - // physicalFN) ; - - // String servicePath = - // HTTPPluginManager.getHTTPSPluginInstance().getServicePath(); // - // HTTPSPluginInterface.getServicePath(); String serviceRelativePath = HTTPPluginManager .getHTTPSPluginInstance() - .mapLocalPath(authority.getServiceHostname(), localFile.getAbsolutePath());// HTTPSPluginInterface.MapLocalPath(localFile.getAbsolutePath()); + .mapLocalPath(authority.getServiceHostname(), localFile.getAbsolutePath()); return buildTURL(Protocol.HTTPS, authority, "", serviceRelativePath); } @@ -164,16 +111,12 @@ private static TTURL buildTURL(Protocol protocol, Authority authority, try { turlString = protocol.getProtocolPrefix() + authority.toString() + extraSlashes + serviceRelativePath; - log.debug("turlString used to build the TURL : " + turlString); + log.debug("turlString used to build the TURL : {}", turlString); turl = TTURL.makeFromString(turlString); - } catch (InvalidTTURLAttributesException ex) { - log.error("Error while constructing TURL with Authority :'" + authority - + "'; EXCEP: " + ex); + } catch (InvalidTTURLAttributesException e) { + log.error("Error while constructing TURL with Authority '{}'. {}", + authority, e.getMessage(), e); } return turl; } - - // TODO MICHELE HTTPS here add the method that builds the HTTPS turl using the - // installed connector - -} +} \ No newline at end of file diff --git a/src/main/java/it/grid/storm/namespace/TURLBuildingException.java b/src/main/java/it/grid/storm/namespace/TURLBuildingException.java index ed5d2bab..4a84df0f 100644 --- a/src/main/java/it/grid/storm/namespace/TURLBuildingException.java +++ b/src/main/java/it/grid/storm/namespace/TURLBuildingException.java @@ -2,27 +2,21 @@ public class TURLBuildingException extends Exception { - public TURLBuildingException() { + private static final long serialVersionUID = 1L; - // TODO Auto-generated constructor stub + public TURLBuildingException() { } public TURLBuildingException(String message) { - super(message); - // TODO Auto-generated constructor stub } public TURLBuildingException(Throwable cause) { - super(cause); - // TODO Auto-generated constructor stub } public TURLBuildingException(String message, Throwable cause) { - super(message, cause); - // TODO Auto-generated constructor stub } } diff --git a/src/main/java/it/grid/storm/namespace/UnapprochableSurlException.java b/src/main/java/it/grid/storm/namespace/UnapprochableSurlException.java index b3406c5c..49729734 100644 --- a/src/main/java/it/grid/storm/namespace/UnapprochableSurlException.java +++ b/src/main/java/it/grid/storm/namespace/UnapprochableSurlException.java @@ -2,14 +2,10 @@ public class UnapprochableSurlException extends Exception { - public UnapprochableSurlException(String string) { + private static final long serialVersionUID = -1004206794152723169L; + public UnapprochableSurlException(String string) { super(string); } - /** - * - */ - private static final long serialVersionUID = -1004206794152723169L; - } diff --git a/src/main/java/it/grid/storm/namespace/VirtualFSInterface.java b/src/main/java/it/grid/storm/namespace/VirtualFSInterface.java index 5d04744a..a0c84456 100644 --- a/src/main/java/it/grid/storm/namespace/VirtualFSInterface.java +++ b/src/main/java/it/grid/storm/namespace/VirtualFSInterface.java @@ -35,26 +35,6 @@ import java.util.List; -/** - *

- * Title: - *

- * - *

- * Description: - *

- * - *

- * Copyright: Copyright (c) 2006 - *

- * - *

- * Company: - *

- * - * @author not attributable - * @version 1.0 - */ public interface VirtualFSInterface { public String getFSType(); @@ -92,10 +72,6 @@ public interface VirtualFSInterface { public List getApproachableRules() throws NamespaceException; - /************************************************** - * Methods used to retrieve the Status of VFS - **************************************************/ - public TSizeInBytes getUsedNearlineSpace() throws NamespaceException; public TSizeInBytes getUsedOnlineSpace() throws NamespaceException; @@ -104,41 +80,21 @@ public List getApproachableRules() public TSizeInBytes getAvailableNearlineSpace() throws NamespaceException; - /************************************************** - * Methods used to create new FILE - **************************************************/ - public StoRI createFile(String relativePath) throws NamespaceException; public StoRI createFile(String relativePath, StoRIType type); - /************************************************** - * Methods Used for implicit space reservation - **************************************************/ - - /** - * Associate the file with a Space with the presumed size and StoRI name (PURE - * implicit reservation) - */ public void makeSilhouetteForFile(StoRI stori, TSizeInBytes presumedSize) throws NamespaceException; - // Use for the "not-so-implicit" space reservation the space file specified by - // token public void useSpaceForFile(TSpaceToken token, StoRI file, TSizeInBytes sizePresumed) throws ExpiredSpaceTokenException, NamespaceException; - // Use for the "not-so-implicit" space reservation the space file specified by - // token public void useAllSpaceForFile(TSpaceToken token, StoRI file) throws ExpiredSpaceTokenException, NamespaceException; - /************************************************** - * Methods Used for EXPLICIT space reservation - **************************************************/ - public StoRI createSpace(String relativePath, long guaranteedSize, long totalSize) throws NamespaceException; @@ -152,11 +108,6 @@ public StoRI createSpace(long guarSize, long totalSize) public StoRI createSpace() throws NamespaceException; - /************************************************** - * Methods Used as utility for SPACE management - **************************************************/ - - // Return a StoRI representing a new Space public TSizeInBytes splitSpace(StoRI spaceOrig, StoRI file, long sizePresumed) throws NamespaceException; @@ -166,10 +117,6 @@ public StorageSpaceData getSpaceByAlias(String alias) public void storeSpaceByToken(StorageSpaceData spaceData) throws NamespaceException; - /************************************************** - * Methods Used for Default use - **************************************************/ - public StoRI createDefaultStoRI() throws NamespaceException; public long getCreationTime(); From 8bdc190fa201f79ff6ede3bc68537ae0b5e6aa14 Mon Sep 17 00:00:00 2001 From: Andrea Ceccanti Date: Thu, 6 Feb 2014 16:38:47 +0100 Subject: [PATCH 29/45] More logging rationalization work --- .../java/it/grid/storm/info/BackgroundDU.java | 65 ++--- .../it/grid/storm/info/BackgroundDUTasks.java | 3 +- .../it/grid/storm/info/CatalogUpdater.java | 42 ++- .../java/it/grid/storm/info/InfoService.java | 1 - .../it/grid/storm/info/SAInfoException.java | 1 - .../it/grid/storm/info/SpaceInfoManager.java | 247 ++++++------------ .../it/grid/storm/info/TestBackgroundDU.java | 89 ------- .../grid/storm/info/TestSpaceInfoManager.java | 29 -- .../jna/lcmaps/lcmaps_account_info_t.java | 11 - .../java/it/grid/storm/logging/Files.java | 7 +- 10 files changed, 128 insertions(+), 367 deletions(-) delete mode 100644 src/main/java/it/grid/storm/info/TestBackgroundDU.java delete mode 100644 src/main/java/it/grid/storm/info/TestSpaceInfoManager.java diff --git a/src/main/java/it/grid/storm/info/BackgroundDU.java b/src/main/java/it/grid/storm/info/BackgroundDU.java index e45c7fdf..cf360187 100644 --- a/src/main/java/it/grid/storm/info/BackgroundDU.java +++ b/src/main/java/it/grid/storm/info/BackgroundDU.java @@ -28,7 +28,7 @@ public class BackgroundDU { - private static final Logger LOG = LoggerFactory.getLogger(BackgroundDU.class); + private static final Logger log= LoggerFactory.getLogger(BackgroundDU.class); private List todoTasks = new ArrayList(); @@ -117,7 +117,7 @@ public void startExecution() { } // Clean todo Task list; todoTasks.clear(); - LOG.info("Submitted all the DU task."); + log.info("Submitted all the DU task."); completionTaskHandle = singleExec.submit(new CompletionTask()); } @@ -140,24 +140,19 @@ public void stopExecution(boolean sweetDead) { } try { completionTaskHandle.get(millisecToWait, TimeUnit.MILLISECONDS); - } catch (TimeoutException te) { - LOG.debug("Timeout excep. " + te); - } catch (InterruptedException ie) { - LOG.debug("Interrupted excep. " + ie); - } catch (ExecutionException ee) { - LOG.debug("Execution excep. " + ee); + } catch (Throwable e){ + log.debug(e.getMessage(),e); } finally { completionTaskHandle.cancel(true); - LOG.debug("Completion task forced to be canceled."); + log.debug("Completion task forced to be canceled."); } try { - LOG.debug("Shutting down.."); + log.debug("Shutting down.."); shutdown(false, 1000); - LOG.debug("Shutted down!"); + log.debug("Shutted down!"); } catch (InterruptedException ie) { - LOG.debug("Interrupted excep. " + ie); + log.debug("Interrupted excep. " + ie); } - } /** @@ -176,8 +171,8 @@ private void shutdown(boolean interrupt, long waitMillis) throws InterruptedException { if (interrupt) { - LOG.debug("Tasks killed: " + exec.shutdownNow().size()); - LOG.debug("Tasks killed: " + singleExec.shutdownNow().size()); + log.debug("Tasks killed: {}", exec.shutdownNow().size()); + log.debug("Tasks killed: {}",singleExec.shutdownNow().size()); } else { exec.shutdown(); singleExec.shutdown(); @@ -186,11 +181,11 @@ private void shutdown(boolean interrupt, long waitMillis) exec.awaitTermination(waitMillis, TimeUnit.MILLISECONDS); singleExec.awaitTermination(waitMillis, TimeUnit.MILLISECONDS); } finally { - LOG.debug("Tasks killed: " + exec.shutdownNow().size()); - LOG.debug("Tasks killed: " + singleExec.shutdownNow().size()); + log.debug("Tasks killed: {}", exec.shutdownNow().size()); + log.debug("Tasks killed: {}", singleExec.shutdownNow().size()); } - LOG.debug("EXEC is terminated? : " + exec.isTerminated()); - LOG.debug("SingleEXEC is terminated? : " + singleExec.isTerminated()); + log.debug("EXEC is terminated? : {}" , exec.isTerminated()); + log.debug("SingleEXEC is terminated? : {}" , singleExec.isTerminated()); } /** @@ -198,19 +193,15 @@ private void shutdown(boolean interrupt, long waitMillis) */ private void processCompletedTask(DUResult duResult) { - LOG.trace("******* Store the result of DU ('" + duResult.getAbsRootPath() - + "')*******"); - LOG.debug("---- DU RESULT of '" + duResult.getAbsRootPath() + "' ----"); - LOG.info(duResult.toString()); + log.trace("BackgroundDU.processCompletedTask. duResult={}", duResult); + + log.info(duResult.toString()); if (duResult.getCmdResult().equals(ExitCode.SUCCESS)) { successResults.add(duResult); } else { failureResults.add(duResult); } - LOG.debug("------------------------------------------------------"); - SpaceInfoManager.getInstance().updateSA(duResult); - } /** @@ -221,7 +212,7 @@ private class CompletionTask implements Runnable { private boolean completeTask() throws InterruptedException { - LOG.debug("Checking for complete a task.."); + log.trace("BackgroundDU.CompletionTask.completeTask"); boolean poison = false; Future completedTask; DUResult duResult = null; @@ -230,12 +221,12 @@ private boolean completeTask() throws InterruptedException { completedTask = completionService.take(); // Add the processed task. completedTasks.add(completedTask); - LOG.debug("Completed Tasks: " + completedTasks.size()); + log.debug("Completed Tasks: {}", completedTasks.size()); // Wait 1 second to check if there is a result duResult = completedTask.get(1, TimeUnit.SECONDS); - LOG.debug("Completed Task : " + duResult.toString()); + log.debug("Completed Task : {}", duResult.toString()); if (duResult.isPoisoned()) { - LOG.debug("POISONED the DU Completion Service!!!"); + log.debug("POISONED the DU Completion Service!!!"); poison = true; } else { toCheckTasks.remove(completedTask); @@ -243,21 +234,21 @@ private boolean completeTask() throws InterruptedException { } catch (ExecutionException e) { Throwable cause = e.getCause(); if (!(cause instanceof InterruptedException)) { - LOG.error("Completion Task failed with unhandled exception", cause); + log.error("Completion Task failed with unhandled exception", cause); } } catch (TimeoutException e) { - LOG.info("Completion Task terminated due to a TimeOut. Cause: " - + e.getCause().getMessage()); + log.info("Completion Task terminated due to a TimeOut. Cause: {}" + , e.getCause().getMessage()); } catch (CancellationException e) { - LOG.info("Completion Task was cancelled. Cause: " - + e.getCause().getMessage()); + log.info("Completion Task was cancelled. Cause: {}" + , e.getCause().getMessage()); } if (duResult != null) { // a DUResult was created, store the results. processCompletedTask(duResult); } else { - LOG + log .warn("DU completed but unable to manage the result (something wrong was happen)."); } return poison; @@ -271,7 +262,7 @@ public void run() { poison_pill = completeTask(); } } catch (InterruptedException ie) { - LOG.info("CompletionTask has been terminated by an interruption. "); + log.info("CompletionTask has been terminated by an interruption. "); Thread.currentThread().interrupt(); } } diff --git a/src/main/java/it/grid/storm/info/BackgroundDUTasks.java b/src/main/java/it/grid/storm/info/BackgroundDUTasks.java index 03f0f275..5713cad8 100644 --- a/src/main/java/it/grid/storm/info/BackgroundDUTasks.java +++ b/src/main/java/it/grid/storm/info/BackgroundDUTasks.java @@ -18,8 +18,7 @@ public class BackgroundDUTasks { private Set tasks = new HashSet(); - private static final Logger LOG = LoggerFactory - .getLogger(BackgroundDUTasks.class); + private static final AtomicInteger taskId = new AtomicInteger(); public void addTask(TSpaceToken token, String path) throws SAInfoException { diff --git a/src/main/java/it/grid/storm/info/CatalogUpdater.java b/src/main/java/it/grid/storm/info/CatalogUpdater.java index 79131b89..b3ecd2a8 100644 --- a/src/main/java/it/grid/storm/info/CatalogUpdater.java +++ b/src/main/java/it/grid/storm/info/CatalogUpdater.java @@ -25,8 +25,9 @@ public class CatalogUpdater { - private static final Logger LOG = LoggerFactory + private static final Logger log = LoggerFactory .getLogger(CatalogUpdater.class); + private final ExecutorService saver = Executors.newFixedThreadPool(1, new NamedThreadFactory("CatalogSaver")); @@ -40,8 +41,8 @@ public Future saveData(TSpaceToken token, DUResult duResult) try { saverFuture = saver.submit(new NamedThread(new SaveSA(token, duResult), "SaverThread")); - } catch (RejectedExecutionException rej) { - LOG.error("Unable to start Saver tasks." + rej.getMessage()); + } catch (RejectedExecutionException e) { + log.error("Unable to start Saver tasks. {}", e.getMessage(), e); } return saverFuture; } @@ -51,7 +52,7 @@ public void stopSaver() { try { shutdown(false, 1000); } catch (InterruptedException ex) { - LOG.debug("DU Info SAVER is interrupted."); + log.debug("DU Info SAVER is interrupted."); } } @@ -59,16 +60,16 @@ private void shutdown(boolean interrupt, long waitMillis) throws InterruptedException { if (interrupt) { - LOG.debug("Tasks killed: " + saver.shutdownNow().size()); + log.debug("Tasks killed: {}", saver.shutdownNow().size()); } else { saver.shutdown(); } try { saver.awaitTermination(waitMillis, TimeUnit.MILLISECONDS); } finally { - LOG.debug("Tasks killed: " + saver.shutdownNow().size()); + log.debug("Tasks killed: {}", saver.shutdownNow().size()); } - LOG.debug("SAVER is terminated? : " + saver.isTerminated()); + log.debug("SAVER terminated? : {}", saver.isTerminated()); } private class SaveSA implements Runnable { @@ -85,8 +86,7 @@ public SaveSA(TSpaceToken spaceToken, DUResult duResult) { public void run() { - // TODO errors are not managed in this function - LOG.debug("Saving info into DB... "); + log.debug("Saving info into DB... "); StorageSpaceData ssd = null; if (SpaceInfoManager.getInstance().testMode.get()) { // this IS a TEST! @@ -97,7 +97,7 @@ public void run() { ssd.setSpaceToken(sT); ssd.setSpaceFileName(spaceFN); } catch (InvalidPFNAttributeException e) { - LOG.error("Unable to create PFN. " + e); + log.error("Unable to create PFN. {}", e.getMessage(), e); } } else { @@ -106,12 +106,12 @@ public void run() { try { ssd = spaceCatalog.getStorageSpace(sT); } catch (TransferObjectDecodingException e) { - LOG - .error("Unable to build StorageSpaceData from StorageSpaceTO. TransferObjectDecodingException: " - + e.getMessage()); + log + .error("Unable to build StorageSpaceData from StorageSpaceTO. TransferObjectDecodingException: {}", + e.getMessage(), e); } catch (DataAccessException e) { - LOG.error("Unable to build get StorageSpaceTO. DataAccessException: " - + e.getMessage()); + log.error("Unable to build get StorageSpaceTO. DataAccessException: {}", + e.getMessage(),e); } } @@ -121,22 +121,18 @@ public void run() { TSizeInBytes us = TSizeInBytes.make(usedSize, SizeUnit.BYTES); ssd.setUsedSpaceSize(us); } catch (InvalidTSizeAttributesException e) { - LOG.error("Negative size?"); + log.error(e.getMessage(),e); } if (SpaceInfoManager.getInstance().testMode.get()) { - // this IS a TEST! - LOG.debug("Saved SSD info into the DB "); + log.debug("Saved SSD info into the DB "); } else { - // This is not a TEST! // Update the SSD into the DB spaceCatalog.updateStorageSpace(ssd); } // Notify the manager about the saving was success SpaceInfoManager.getInstance().savedSA(duResult); - LOG.debug(String.format("DU info of %s is saved into DB.", - duResult.getAbsRootPath())); + log.debug("DU info for {} saved. ", duResult.getAbsRootPath()); } - } -} +} \ No newline at end of file diff --git a/src/main/java/it/grid/storm/info/InfoService.java b/src/main/java/it/grid/storm/info/InfoService.java index fcc8d9c7..be7d96f1 100644 --- a/src/main/java/it/grid/storm/info/InfoService.java +++ b/src/main/java/it/grid/storm/info/InfoService.java @@ -8,7 +8,6 @@ public class InfoService { private static final Logger log = LoggerFactory.getLogger(InfoService.class); public static String getResourcePackage() { - return "it.grid.storm.info.remote.resources"; } diff --git a/src/main/java/it/grid/storm/info/SAInfoException.java b/src/main/java/it/grid/storm/info/SAInfoException.java index 5a1a66b3..2686f449 100644 --- a/src/main/java/it/grid/storm/info/SAInfoException.java +++ b/src/main/java/it/grid/storm/info/SAInfoException.java @@ -5,7 +5,6 @@ public class SAInfoException extends Exception { private static final long serialVersionUID = 1L; public SAInfoException(String message) { - super(message); } diff --git a/src/main/java/it/grid/storm/info/SpaceInfoManager.java b/src/main/java/it/grid/storm/info/SpaceInfoManager.java index 02cb8d59..5111cadc 100644 --- a/src/main/java/it/grid/storm/info/SpaceInfoManager.java +++ b/src/main/java/it/grid/storm/info/SpaceInfoManager.java @@ -55,7 +55,8 @@ public class SpaceInfoManager { - private final Logger LOG; + private static final Logger log = + LoggerFactory.getLogger(SpaceInfoManager.class); private static final SpaceInfoManager instance = new SpaceInfoManager(); private int timeOutDurationInSec = 7200; // 2 hours per task (This value is // multiplied by attempt) @@ -78,12 +79,7 @@ public class SpaceInfoManager { private int quotas = 0; private int quotasDefined = 0; - /** - * - */ private SpaceInfoManager() { - - LOG = LoggerFactory.getLogger(SpaceInfoManager.class); List vfsS = retrieveSAtoInitializeWithQuota(); if (vfsS != null) { this.quotasDefined = vfsS.size(); @@ -92,11 +88,7 @@ private SpaceInfoManager() { } } - /** - * @return the quotasDefined - */ public final int getQuotasDefined() { - return quotasDefined; } @@ -104,12 +96,10 @@ public final int getQuotasDefined() { private int attempt = 1; public static SpaceInfoManager getInstance() { - return instance; } public static boolean isInProgress() { - boolean result = false; if (SpaceInfoManager.getInstance().tasksToComplete.get() > 0) { result = true; @@ -156,7 +146,7 @@ private int startBackGroundDU() { // This call populate the Task Queue: "bDUTasks" SpaceInfoManager.getInstance().foundSAtoAnalyze(); result = SpaceInfoManager.getInstance().bDUTasks.howManyTask(); - LOG.debug(String.format("Tasks: %d", result)); + log.debug("Tasks: {}", result); // Submit the tasks SpaceInfoManager.getInstance().submitTasks( SpaceInfoManager.getInstance().bDUTasks); @@ -225,13 +215,13 @@ public List retrieveQuotaNamesToUse() { List quotaNames = new ArrayList(); List vfsList = retrieveSAtoInitializeWithQuota(); for (VirtualFSInterface vfsEntry : vfsList) { - LOG.debug("vfsEntry (AliasName): " + vfsEntry.getAliasName()); + log.debug("vfsEntry (AliasName): {}", vfsEntry.getAliasName()); String quotaName = vfsEntry.getCapabilities().getQuota() .getQuotaElementName(); - LOG.debug("Found this quotaName to check: '" + quotaName + "'"); + log.debug("Found this quotaName to check: '{}'", quotaName); quotaNames.add(quotaName); } - LOG.debug("Number of quotaNames: " + quotaNames.size()); + log.debug("Number of quotaNames: {}" ,quotaNames.size()); return quotaNames; } @@ -244,13 +234,11 @@ public List retrieveSAtoInitializeWithQuota() { vfsSet = new ArrayList(NamespaceDirector .getNamespace().getAllDefinedVFS()); } catch (NamespaceException e) { - LOG - .error("Unable to get the defined Virtual File Systems. NamespaceException : " - + e.getMessage()); - LOG.error("Returning an empty list"); + log.error(e.getMessage(),e); + log.error("Returning an empty VFS list"); return new ArrayList(); } - LOG.debug("Found '" + vfsSet.size() + "' VFS defined in Namespace.xml"); + log.debug("Found '{}' VFS defined in Namespace.xml", vfsSet.size()); List vfsSetQuota = new ArrayList(); if (vfsSet.size() > 0) { // Exists at least a VFS defined for (VirtualFSInterface vfsItem : vfsSet) { @@ -259,7 +247,7 @@ public List retrieveSAtoInitializeWithQuota() { } } } - LOG.debug("Number of VFS with Quota enabled: " + vfsSetQuota.size()); + log.debug("Number of VFS with Quota enabled: {}", vfsSetQuota.size()); return vfsSetQuota; } @@ -300,16 +288,16 @@ private void fakeSAtoAnalyze(List absPaths) { StorageSpaceData ssd = new StorageSpaceData(); try { PFN spaceFN = PFN.make(pathNorm); - LOG.trace("PFN : " + spaceFN); + log.trace("PFN : " , spaceFN); ssd.setSpaceToken(TSpaceToken.make(new it.grid.storm.common.GUID() .toString())); ssd.setSpaceFileName(spaceFN); toAnalyze.add(ssd); } catch (InvalidTSpaceTokenAttributesException e) { - LOG.error("Unable to create Space Token. " + e); + log.error("Unable to create Space Token. {}", e.getMessage(), e); } catch (InvalidPFNAttributeException e) { - LOG.error("Unable to create PFN. " + e); + log.error("Unable to create PFN. {}", e.getMessage(),e); } } @@ -318,21 +306,16 @@ private void fakeSAtoAnalyze(List absPaths) { String absPath = ssd.getSpaceFileNameString(); try { bDUTasks.addTask(sT, absPath); - LOG.debug(String.format( - "Added %s to the DU-Task Queue. (Task queue size:%d)", absPath, - bDUTasks.howManyTask())); + log.debug("Added {} to the DU-Task Queue. (Task queue size: {})", + absPath, + bDUTasks.howManyTask()); } catch (SAInfoException e) { - LOG.error("Unable to add task with '" + absPath + "' absolute path." - + e.getMessage()); + log.error(e.getMessage(), e); } } - LOG.info(String.format("Background DU tasks size: %d", bDUTasks.getTasks() - .size())); + log.info("Background DU tasks size: {}", bDUTasks.getTasks().size()); } - /** - * Populate with DU tasks - */ private void foundSAtoAnalyze() { List toAnalyze = spaceCatalog @@ -341,36 +324,30 @@ private void foundSAtoAnalyze() { TSpaceToken sT = ssd.getSpaceToken(); String absPath = ssd.getSpaceFileNameString(); if (sT == null || absPath == null) { - LOG - .error("Unable to submit DU test, StorageSpaceData returns null values: SpaceToken=" - + sT + " , SpaceFileNameString=" + absPath); + log + .error("Unable to submit DU test, StorageSpaceData returns " + + "null values: SpaceToken={}, SpaceFileNameString={}", + sT, absPath); } else { try { bDUTasks.addTask(sT, absPath); - LOG.debug("Added " + absPath + " to the DU-Task Queue. (size:" - + bDUTasks.howManyTask() + ")"); + log.debug("Added {} to the DU-Task Queue. (size: {})", + absPath, bDUTasks.howManyTask()); + } catch (SAInfoException e) { - LOG.error("Unable to add task with '" + absPath + "' absolute path." - + e.getMessage()); + log.error(e.getMessage(),e); } } } } void stopExecution() { - + log.trace("SpaceInfoManager.stopExecution"); bDU.stopExecution(true); persist.stopSaver(); - LOG.debug("Stopping Background DU executions."); } - /** - * Used to update the DB if the Task is root, otherwise manage the split DU - * - * @param taskDU - * @param result - */ void updateSA(DUResult result) { // Retrieve BDUTask @@ -382,7 +359,7 @@ void updateSA(DUResult result) { try { bDUTasks.updateTask(task); } catch (SAInfoException e1) { - LOG.error("Something strange happen.." + e1); + log.error("Something strange happen.. {}", e1.getMessage(), e1); } // Check if the result is success, otherwise ... @@ -396,25 +373,23 @@ void updateSA(DUResult result) { persist.saveData(st, result); } catch (SAInfoException e) { - LOG.error("Unable to persist the DU result of '" - + result.getAbsRootPath() + "' " + e); + log.error(e.getMessage(),e); } } else { // Logging the failure - LOG.warn(String.format( - "DU of space with %s token is terminated with status %s", task - .getSpaceToken().toString(), result.getCmdResult())); + log.warn("DU of space with {} token is terminated with status {}", task + .getSpaceToken().toString(), result.getCmdResult()); } // Decrease the number of tasks to complete // - note: a task is complete despite of the final status (Success or // failure it is same) int ttc = tasksToComplete.decrementAndGet(); - LOG.debug("TaskToComplete: " + ttc); + log.debug("TaskToComplete: {}", ttc); if (tasksToComplete.get() <= 0) { // All the tasks are completed. - LOG.info("All the tasks are completed!"); + log.info("All the tasks are completed!"); // Check for failed tasks for (BgDUTask bTask : bDUTasks.getTasks()) { @@ -428,77 +403,46 @@ void updateSA(DUResult result) { // Update the attempt and maintain the task in processing queue bTask.increaseAttempt(); if (bTask.getAttempt() > MaxAttempt) { - LOG.error("Unable to compute Space Used for the SA with root '" - + bTask.getAbsPath() + "' for the reason :" - + bTask.getDuResult().getCmdResult()); + + log.error("Unable to compute Space Used for the SA with root {}. Reason: {}", + bTask.getAbsPath(), + bTask.getDuResult().getCmdResult()); + failures.incrementAndGet(); } else { // Retry try { bDUTasks.updateTask(bTask); } catch (SAInfoException e) { - LOG.error("Something starnge happen." + e); + log.error(e.getMessage(),e); } } - } } int s = success.get(); int f = failures.get(); int tot = numberOfTasks.get(); int r = tot - s - f; - LOG.debug(String.format( - "Total DU Tasks are %d (success:%d; to-retry:%d; failure:%d).", tot, s, - r, f)); + log.debug("Total DU Tasks are {} (success: {}; to-retry: {}; failure: {}.", + tot, s, r, f); + if (r == 0) { - // No more retry, so shutdown bDU stopExecution(); } } } - /** - * Method called when DUResult has been saved into the DB - * - * @param taskDU - * @param result - */ void savedSA(DUResult result) { - this.tasksToSave.decrementAndGet(); - LOG.debug("Result saved.."); - - // Check if all the tasks has been processed - // if (this.tasksToComplete.get()<=0) { - // //All the tasks has been processed - // //Check if there was some failures - // if ((failures.get()) >0) { - // attempt++; - // if (attempt>MaxAttempt) { - // //No more retry, so shutdown bDU - // bDU.stopExecution(); - // persist.stopSaver(); - // LOG.debug("Stopping Background DU executions."); - // } else { - // LOG.info("-- Resubmit DU tasks --"); - // //Remove from tasks queue successfully tasks - // bDUTasks.removeSuccessTask(); - // - // submitTasks(bDUTasks); - // } - // } - // } + log.debug("Result saved.."); } - /** - * Submit all the tasks to a BackgroundDU - */ void submitTasks(BackgroundDUTasks tasks) { bDU = new BackgroundDU(timeOutDurationInSec * attempt, TimeUnit.SECONDS); Collection tasksToSubmit = tasks.getTasks(); - LOG.debug("tasks to submit: " + tasksToSubmit); + log.debug("tasks to submit: {}", tasksToSubmit); int size = tasksToSubmit.size(); this.numberOfTasks = new AtomicInteger(size); this.tasksToComplete = new AtomicInteger(size); @@ -506,29 +450,21 @@ void submitTasks(BackgroundDUTasks tasks) { this.failures = new AtomicInteger(0); this.success = new AtomicInteger(0); - LOG.info("Submitting " + this.tasksToComplete + " DU tasks."); + log.info("Submitting {} DU tasks.", tasksToComplete); + for (BgDUTask task : tasksToSubmit) { - // task.getSpaceToken(); bDU.addStorageArea(task.getAbsPath(), task.getTaskId()); } - LOG.info("Setting fake used space to " + this.tasksToComplete - + " DU tasks."); - // Set fake used space, in order to avoid -1 result during the computation + log.info("Setting fake used space to {} DU tasks.", tasksToComplete); setFakeUsedSpace(tasksToSubmit); - LOG.info("Start DU background execution"); + log.info("Start DU background execution"); bDU.startExecution(); - } - /** - * - * @param tasksToSubmit - */ private void setFakeUsedSpace(Collection tasksToSubmit) { - // TODO errors are not managed in this function ReservedSpaceCatalog spaceCatalog = new ReservedSpaceCatalog(); for (BgDUTask task : tasksToSubmit) { TSpaceToken sToken = task.getSpaceToken(); @@ -536,30 +472,26 @@ private void setFakeUsedSpace(Collection tasksToSubmit) { try { ssd = spaceCatalog.getStorageSpace(sToken); } catch (TransferObjectDecodingException e) { - LOG - .error("Unable to build StorageSpaceData from StorageSpaceTO. TransferObjectDecodingException: " - + e.getMessage()); + log + .error("Unable to build StorageSpaceData from StorageSpaceTO. TransferObjectDecodingException: {}", + e.getMessage(),e); } catch (DataAccessException e) { - LOG.error("Unable to build get StorageSpaceTO. DataAccessException: " - + e.getMessage()); + log.error("Unable to build get StorageSpaceTO. DataAccessException: {}", + e.getMessage(),e); } TSizeInBytes totalSize = ssd.getTotalSpaceSize(); TSizeInBytes fakeUsed = TSizeInBytes.makeEmpty(); try { fakeUsed = TSizeInBytes.make(totalSize.value() / 2, SizeUnit.BYTES); } catch (InvalidTSizeAttributesException e) { - LOG.warn("Unable to create Fake Size to set to used_size"); + log.warn("Unable to create Fake Size to set to used_size. {}", + e.getMessage()); } - ssd.setUsedSpaceSize(fakeUsed); // By default also freeSize will be - // updated. + ssd.setUsedSpaceSize(fakeUsed); spaceCatalog.updateStorageSpace(ssd); } - } - /** - * @return - */ public int initSpaceFromINIFile() { List toAnalyze = spaceCatalog @@ -579,15 +511,12 @@ public int initSpaceFromINIFile() { saUsedSize.getUsedSize(), saUsedSize.getUpdateTime()); storageSpaceUpdated++; } catch (IllegalArgumentException e) { - LOG - .error("Unable to updated used space on persistence for Storage Area " - + saUsedSize.getSaName() - + " to value " - + saUsedSize.getUsedSize() - + " with update time " - + saUsedSize.getUpdateTime() - + ". IllegalArgumentException: " - + e.getMessage()); + log.error("Error updating used space for SA {} to value {} with update time {}. {}", + saUsedSize.getSaName(), + saUsedSize.getUsedSize(), + saUsedSize.getUpdateTime(), + e.getMessage(), + e); } } else { try { @@ -595,13 +524,12 @@ public int initSpaceFromINIFile() { saUsedSize.getUsedSize()); storageSpaceUpdated++; } catch (IllegalArgumentException e) { - LOG - .error("Unable to updated used space on persistence for Storage Area " - + saUsedSize.getSaName() - + " to value " - + saUsedSize.getUsedSize() - + ". IllegalArgumentException: " - + e.getMessage()); + log.error("Error updating used space for SA {} to value {} with update time {}. {}", + saUsedSize.getSaName(), + saUsedSize.getUsedSize(), + saUsedSize.getUpdateTime(), + e.getMessage(), + e); } } } @@ -609,64 +537,47 @@ public int initSpaceFromINIFile() { return storageSpaceUpdated; } - /** - * @return - */ private void printInitializedStorageAreas(List saAlias) { try { for (VirtualFSInterface vfs : NamespaceDirector.getNamespace() .getAllDefinedVFS()) { if (!(saAlias.contains(vfs.getSpaceTokenDescription()))) { - LOG.debug("SA '" + vfs.getAliasName() + "' is already initialized"); + log.debug("SA {} already initialized", vfs.getAliasName()); } } } catch (NamespaceException e) { - // never thrown - LOG.error( - "Unexpected Exception: NamespaceException on getAllDefinedVFS: ", e); + log.error(e.getMessage(), e); } } - /** - * @param saAlias - * @param usedSize - * @throws IllegalArgumentException - */ private void updateUsedSpaceOnPersistence(String saName, Long usedSize) throws IllegalArgumentException { if (saName == null || usedSize == null) { - LOG.error("Received null arguments: saName = " + saName + " usedSize = " - + usedSize); + log.error("Null arguments: saName={} usedSize={}", + saName, usedSize); throw new IllegalArgumentException("Received null arguments: saName = " + saName + " usedSize = " + usedSize); } updateUsedSpaceOnPersistence(saName, usedSize, null); } - /** - * @param saName - * @param usedSize - * @param updateTime - */ private void updateUsedSpaceOnPersistence(String saName, Long usedSize, Date updateTime) throws IllegalArgumentException { if (saName == null || usedSize == null) { - LOG.error("Received null arguments: saName = " + saName + " usedSize = " - + usedSize); + log.error("Null arguments: saName={} usedSize={}", + saName, usedSize); throw new IllegalArgumentException("Received null arguments: saName = " + saName + " usedSize = " + usedSize); } StorageSpaceData ssd = spaceCatalog.getStorageSpaceByAlias(saName); if (ssd != null) { - // Update the used space size with new value try { ssd.setUsedSpaceSize(TSizeInBytes.make(usedSize, SizeUnit.BYTES)); } catch (InvalidTSizeAttributesException e) { - LOG.error("Invalid Used Size: " + usedSize - + " . InvalidTSizeAttributesException: " + e.getMessage()); + log.error(e.getMessage(),e); throw new IllegalArgumentException("Invalid Used Size: " + usedSize + " Unable to update Storage Space"); } @@ -676,13 +587,13 @@ private void updateUsedSpaceOnPersistence(String saName, Long usedSize, } else { spaceCatalog.updateStorageSpace(ssd, updateTime); } - LOG.debug("StorageSpace table updated for SA: '" + saName - + "' with used size = " + usedSize); + log.debug("StorageSpace table updated for SA: '{}' with used size = {}", + saName, usedSize); + } else { - LOG.warn("Unable to retrieve StorageSpaceData with Alias: " + saName); + log.warn("Unable to retrieve StorageSpaceData with Alias: {}", saName); throw new IllegalArgumentException( "Unable to retrieve StorageSpaceData with Alias: " + saName); } - } } diff --git a/src/main/java/it/grid/storm/info/TestBackgroundDU.java b/src/main/java/it/grid/storm/info/TestBackgroundDU.java deleted file mode 100644 index 12a1e400..00000000 --- a/src/main/java/it/grid/storm/info/TestBackgroundDU.java +++ /dev/null @@ -1,89 +0,0 @@ -package it.grid.storm.info; - -import it.grid.storm.space.DUResult; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; -import java.util.concurrent.TimeUnit; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Arrays; - -public class TestBackgroundDU { - - private static final Logger LOG = LoggerFactory - .getLogger(TestBackgroundDU.class); - private static BackgroundDU bDu = new BackgroundDU(60, TimeUnit.SECONDS); - private static TestBackgroundDU tBDU = new TestBackgroundDU(); - - public void initSA(List paths) { - - int count = 0; - for (String path : paths) { - LOG.debug("Adding :'" + path + "'"); - bDu.addStorageArea(path, count); - count++; - } - } - - public void startComputation() { - - LOG.debug("Starting Computation.. in background"); - bDu.startExecution(); - LOG.debug(".. computation started"); - } - - /** - * @param args - */ - public static void main(String[] args) { - - LOG.debug("arg.length : " + args.length); - if (args.length == 0) { - List paths = new ArrayList(); - paths.add(System.getProperty("user.dir")); - paths.add(System.getProperty("user.dir") + File.separator + ".."); - paths.add(System.getProperty("user.dir") + File.separator + ".." - + File.separator + "TreeTraversal"); - tBDU.initSA(paths); - } else { - List paths = Arrays.asList(args); - tBDU.initSA(paths); - } - LOG.debug("how many? :" + bDu.howManyTaskToComplete()); - tBDU.startComputation(); - int howTodos = bDu.howManyTaskToComplete(); - while (howTodos > 0) { - howTodos = bDu.howManyTaskToComplete(); - LOG.debug("Task to complete: " + howTodos); - LOG.debug("Task success : " + bDu.howManyTaskSuccess()); - LOG.debug("Task failed : " + bDu.howManyTaskFailure()); - try { - Thread.sleep(5000); - } catch (InterruptedException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } - LOG.debug("***********************************"); - LOG.debug("***********************************"); - LOG.debug("***********************************"); - - bDu.stopExecution(false); - Set results = bDu.getSuccessTasks(); - for (DUResult duResult : results) { - LOG.debug("duResult : " + duResult); - } - Set failedTasks = bDu.getFailureTasks(); - for (DUResult duResult : failedTasks) { - LOG.debug("failed duResult : " + duResult); - } - bDu = null; - - } - -} diff --git a/src/main/java/it/grid/storm/info/TestSpaceInfoManager.java b/src/main/java/it/grid/storm/info/TestSpaceInfoManager.java deleted file mode 100644 index 224f4092..00000000 --- a/src/main/java/it/grid/storm/info/TestSpaceInfoManager.java +++ /dev/null @@ -1,29 +0,0 @@ -package it.grid.storm.info; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -public abstract class TestSpaceInfoManager { - - /** - * @param args - */ - public static void main(String[] args) { - - List paths = new ArrayList(); - paths.add(System.getProperty("user.dir")); - // paths.add(System.getProperty("user.dir")+File.separator+".."); - paths.add(System.getProperty("user.dir") + File.separator + ".." - + File.separator + "TreeTraversal"); - SpaceInfoManager.getInstance().startTest(paths); - // try { - // Thread.sleep(1500); - // } catch (InterruptedException e) { - // // TODO Auto-generated catch block - // e.printStackTrace(); - // } - // SpaceInfoManager.stop(); - } - -} diff --git a/src/main/java/it/grid/storm/jna/lcmaps/lcmaps_account_info_t.java b/src/main/java/it/grid/storm/jna/lcmaps/lcmaps_account_info_t.java index a202cab4..31ed6ecf 100644 --- a/src/main/java/it/grid/storm/jna/lcmaps/lcmaps_account_info_t.java +++ b/src/main/java/it/grid/storm/jna/lcmaps/lcmaps_account_info_t.java @@ -25,17 +25,6 @@ import com.sun.jna.Structure; import com.sun.jna.ptr.IntByReference; -/** - * This file was autogenerated by JNAerator,
- * a tool written by Olivier Chafik that - * uses a - * few opensource projects..
- * For help, please visit NativeLibs4Java , Rococoa, or JNA. - */ public class lcmaps_account_info_t extends Structure { // / < the uid of the local account diff --git a/src/main/java/it/grid/storm/logging/Files.java b/src/main/java/it/grid/storm/logging/Files.java index 29d4df84..355bf135 100644 --- a/src/main/java/it/grid/storm/logging/Files.java +++ b/src/main/java/it/grid/storm/logging/Files.java @@ -21,13 +21,9 @@ import java.io.FileInputStream; import java.io.IOException; -/** A utility class for working with files. */ public final class Files { - /** Constructor. */ - private Files() { - - } + private Files() {} /** * A convenience method for getting a file and requiring it to be a readable @@ -44,7 +40,6 @@ private Files() { * read */ public static File getReadableFile(String filePath) throws IOException { - return getFile(filePath, true, true, true, false); } From e9a4699b5bd2eff067e2f99485e6a623555dc0d0 Mon Sep 17 00:00:00 2001 From: enricovianello Date: Thu, 6 Feb 2014 17:28:04 +0100 Subject: [PATCH 30/45] Fix log calls in storm backend - package it.grid.storm.catalogs --- .../grid/storm/catalogs/AnonymousPtGData.java | 7 +- .../grid/storm/catalogs/AnonymousPtPData.java | 13 +- .../grid/storm/catalogs/BoLChunkCatalog.java | 206 ++++------- .../it/grid/storm/catalogs/BoLChunkDAO.java | 321 +++++++---------- .../grid/storm/catalogs/BoLChunkDataTO.java | 1 - .../java/it/grid/storm/catalogs/BoLData.java | 7 +- .../catalogs/BoLPersistentChunkData.java | 7 +- .../grid/storm/catalogs/CopyChunkCatalog.java | 64 ++-- .../it/grid/storm/catalogs/CopyChunkDAO.java | 73 ++-- .../grid/storm/catalogs/CopyChunkDataTO.java | 1 - .../java/it/grid/storm/catalogs/CopyData.java | 5 - .../catalogs/CopyPersistentChunkData.java | 6 +- ...validCopyChunkDataAttributesException.java | 2 + ...educedBoLChunkDataAttributesException.java | 2 + ...educedPtGChunkDataAttributesException.java | 2 + ...educedPtPChunkDataAttributesException.java | 2 + ...RequestSummaryDataAttributesException.java | 2 + .../InvalidRetrievedDataException.java | 2 + .../InvalidSpaceDataAttributesException.java | 5 +- .../catalogs/MalformedGridUserException.java | 2 + .../MultipleDataEntriesException.java | 2 + .../storm/catalogs/NoDataFoundException.java | 2 + .../grid/storm/catalogs/PtGChunkCatalog.java | 254 ++++--------- .../it/grid/storm/catalogs/PtGChunkDAO.java | 336 +++++++----------- .../grid/storm/catalogs/PtGChunkDataTO.java | 2 - .../catalogs/PtGPersistentChunkData.java | 7 +- .../grid/storm/catalogs/PtPChunkCatalog.java | 189 ++-------- .../it/grid/storm/catalogs/PtPChunkDAO.java | 187 ++++------ .../grid/storm/catalogs/PtPChunkDataTO.java | 1 - .../catalogs/PtPPersistentChunkData.java | 12 +- .../storm/catalogs/ReducedBoLChunkDataTO.java | 1 - .../catalogs/ReducedCopyChunkDataTO.java | 1 - .../storm/catalogs/ReducedPtGChunkDataTO.java | 1 - .../storm/catalogs/ReducedPtPChunkDataTO.java | 1 - .../storm/catalogs/RequestSummaryCatalog.java | 243 ++++++------- .../storm/catalogs/RequestSummaryDAO.java | 293 ++++++--------- .../storm/catalogs/ReservedSpaceCatalog.java | 180 +++++----- .../catalogs/SizeInBytesIntConverter.java | 3 +- .../catalogs/SpaceTokenStringConverter.java | 3 +- .../SurlMultyOperationRequestData.java | 81 ++--- .../grid/storm/catalogs/SurlRequestData.java | 13 +- .../storm/catalogs/VolatileAndJiTCatalog.java | 289 +++++++-------- .../storm/catalogs/VolatileAndJiTDAO.java | 155 ++++---- 43 files changed, 1152 insertions(+), 1834 deletions(-) diff --git a/src/main/java/it/grid/storm/catalogs/AnonymousPtGData.java b/src/main/java/it/grid/storm/catalogs/AnonymousPtGData.java index f8a02d1f..615c590f 100644 --- a/src/main/java/it/grid/storm/catalogs/AnonymousPtGData.java +++ b/src/main/java/it/grid/storm/catalogs/AnonymousPtGData.java @@ -75,6 +75,8 @@ public AnonymousPtGData(TSURL SURL, TLifeTimeInSeconds lifeTime, super(SURL, desiredProtocols, status, transferURL); if (lifeTime == null || dirOption == null || fileSize == null) { + log.debug("Invalid arguments: lifeTime={}, dirOption={}, fileSize={}", + lifeTime, dirOption, fileSize); throw new InvalidPtGDataAttributesException(SURL, lifeTime, dirOption, desiredProtocols, fileSize, status, transferURL); @@ -231,9 +233,4 @@ public boolean equals(Object obj) { return true; } - @Override - protected Logger getLog() { - - return log; - } } diff --git a/src/main/java/it/grid/storm/catalogs/AnonymousPtPData.java b/src/main/java/it/grid/storm/catalogs/AnonymousPtPData.java index a07b5e77..3951642f 100644 --- a/src/main/java/it/grid/storm/catalogs/AnonymousPtPData.java +++ b/src/main/java/it/grid/storm/catalogs/AnonymousPtPData.java @@ -37,7 +37,8 @@ public class AnonymousPtPData extends AnonymousFileTransferData implements PtPData { - static final Logger log = LoggerFactory.getLogger(AnonymousPtPData.class); + private static final Logger log = LoggerFactory.getLogger(AnonymousPtPData.class); + protected TSpaceToken spaceToken; protected TLifeTimeInSeconds pinLifetime; protected TLifeTimeInSeconds fileLifetime; @@ -58,6 +59,10 @@ public AnonymousPtPData(TSURL toSURL, TLifeTimeInSeconds pinLifetime, if (pinLifetime == null || fileLifetime == null || spaceToken == null || fileStorageType == null || expectedFileSize == null || overwriteOption == null) { + log.debug("Invalid arguments: pinLifetime={}, fileLifetime={}, " + + "spaceToken={}, fileStorageType={}, expectedFileSize={}, " + + "overwriteOption={}", pinLifetime, fileLifetime, spaceToken, + fileStorageType, expectedFileSize, overwriteOption); throw new InvalidPtPDataAttributesException(toSURL, pinLifetime, fileLifetime, fileStorageType, spaceToken, expectedFileSize, transferProtocols, overwriteOption, status, transferURL); @@ -70,12 +75,6 @@ public AnonymousPtPData(TSURL toSURL, TLifeTimeInSeconds pinLifetime, this.overwriteOption = overwriteOption; } - @Override - protected Logger getLog() { - - return log; - } - /* * (non-Javadoc) * diff --git a/src/main/java/it/grid/storm/catalogs/BoLChunkCatalog.java b/src/main/java/it/grid/storm/catalogs/BoLChunkCatalog.java index b17d9399..b6bdaf69 100644 --- a/src/main/java/it/grid/storm/catalogs/BoLChunkCatalog.java +++ b/src/main/java/it/grid/storm/catalogs/BoLChunkCatalog.java @@ -118,35 +118,30 @@ public static BoLChunkCatalog getInstance() { synchronized public Collection lookup(TRequestToken rt) { Collection chunkCollection = dao.find(rt); - log.debug("BoL CHUNK CATALOG: retrieved data " + chunkCollection); + log.debug("BoL CHUNK CATALOG: retrieved data {}", chunkCollection); List list = new ArrayList(); if (chunkCollection.isEmpty()) { - log - .warn("BoL CHUNK CATALOG! No chunks found in persistence for specified request: " - + rt); - } else { - // TODO MICHELE USER_SURL here I can update all requests that has - // not the new fields set alltogether in a bunch, adding a method to - // the DAO for this purpose - BoLPersistentChunkData chunk; - for (BoLChunkDataTO chunkTO : chunkCollection) { - chunk = makeOne(chunkTO, rt); - if (chunk != null) { - list.add(chunk); - // TODO MICHELE SURL STORE - // SurlStatusStore.getInstance().storeSurlStatus(chunk.getSURL(), - // chunk.getStatus().getStatusCode()); - if (!this.isComplete(chunkTO)) { - try { - dao.updateIncomplete(this.completeTO(chunkTO, chunk)); - } catch (InvalidReducedBoLChunkDataAttributesException e) { - log - .warn("PtG CHUNK CATALOG! unable to add missing informations on DB to the request: " - + e); - } - } - } + log.warn("BoL CHUNK CATALOG! No chunks found in persistence for specified " + + "request: {}", rt); + return list; + } + + BoLPersistentChunkData chunk; + for (BoLChunkDataTO chunkTO : chunkCollection) { + chunk = makeOne(chunkTO, rt); + if (chunk == null) { + continue; + } + list.add(chunk); + if (isComplete(chunkTO)) { + continue; + } + try { + dao.updateIncomplete(completeTO(chunkTO, chunk)); + } catch (InvalidReducedBoLChunkDataAttributesException e) { + log.warn("BoL CHUNK CATALOG! unable to add missing informations on DB " + + "to the request: {}", e.getMessage()); } } log.debug("BoL CHUNK CATALOG: returning " + list); @@ -184,7 +179,7 @@ private BoLPersistentChunkData makeOne(BoLChunkDataTO auxTO, TRequestToken rt) { long max = Configuration.getInstance().getPinLifetimeMaximum(); if (pinLifeTime > max) { log.warn("PinLifeTime is greater than the max value allowed. " - + "Drop the value to the max = " + max + " seconds"); + + "Drop the value to the max = {} seconds", max); pinLifeTime = max; } lifeTime = TLifeTimeInSeconds.make(pinLifeTime, TimeUnit.SECONDS); @@ -250,7 +245,7 @@ private BoLPersistentChunkData makeOne(BoLChunkDataTO auxTO, TRequestToken rt) { } catch (InvalidSurlRequestDataAttributesException e) { dao.signalMalformedBoLChunk(auxTO); log.warn("BoL CHUNK CATALOG! Retrieved malformed BoL " - + "chunk data from persistence. Dropping chunk from request " + rt); + + "chunk data from persistence. Dropping chunk from request {}", rt); log.warn(e.getMessage(), e); log.warn(errorSb.toString()); } @@ -401,38 +396,30 @@ synchronized public BoLPersistentChunkData refreshStatus( // Call the dao refresh method to synch with the db status BoLChunkDataTO auxTO = dao.refresh(inputChunk.getPrimaryKey()); - log.debug("BoL CHUNK CATALOG: retrieved data " + auxTO); + log.debug("BoL CHUNK CATALOG: retrieved data {}", auxTO); if (auxTO == null) { - log - .warn("BoL CHUNK CATALOG! Empty TO found in persistence for specified request: " - + inputChunk.getPrimaryKey()); - } else { - /* - * In this first version the only field updated is the Status. Once - * updated, the new status is rewritten into the input ChunkData - */ - - // status - TReturnStatus status = null; - TStatusCode code = StatusCodeConverter.getInstance().toSTORM( - auxTO.getStatus()); - if (code != TStatusCode.EMPTY) { - try { - status = new TReturnStatus(code, auxTO.getErrString()); - } catch (InvalidTReturnStatusAttributeException e) { - log - .debug("BoL Chunk: Unable to build the Return Status from the String '" - + auxTO.getErrString() - + " and code '" - + auxTO.getStatus() - + "''." + e); + log.warn("BoL CHUNK CATALOG! Empty TO found in persistence for specified " + + "request: {}", inputChunk.getPrimaryKey()); + return inputChunk; + } + + /* + * In this first version the only field updated is the Status. Once + * updated, the new status is rewritten into the input ChunkData + */ + + // status + TReturnStatus status = null; + TStatusCode code = StatusCodeConverter.getInstance().toSTORM(auxTO.getStatus()); + if (code != TStatusCode.EMPTY) { + try { + status = new TReturnStatus(code, auxTO.getErrString()); + } catch (InvalidTReturnStatusAttributeException e) { + log.debug("BoL Chunk: Unable to build the Return Status from the String " + + "'{}' and code '{}'.", auxTO.getErrString(), auxTO.getStatus()); } } inputChunk.setStatus(status); - // TODO MICHELE SURL STORE - // SurlStatusStore.getInstance().storeSurlStatus(inputChunk.getSURL(), - // status.getStatusCode()); - } return inputChunk; } @@ -453,26 +440,23 @@ synchronized public Collection lookupReducedBoLChunkData( Collection reducedChunkDataTOs = dao.findReduced(rt .getValue()); - log.debug("BoL CHUNK CATALOG: retrieved data " + reducedChunkDataTOs); + log.debug("BoL CHUNK CATALOG: retrieved data {}", reducedChunkDataTOs); ArrayList list = new ArrayList(); if (reducedChunkDataTOs.isEmpty()) { - log.debug("BoL CHUNK CATALOG! No chunks found in persistence for " + rt); + log.debug("BoL CHUNK CATALOG! No chunks found in persistence for {}", rt); } else { ReducedBoLChunkData reducedChunkData = null; for (ReducedBoLChunkDataTO reducedChunkDataTO : reducedChunkDataTOs) { reducedChunkData = makeOneReduced(reducedChunkDataTO); if (reducedChunkData != null) { list.add(reducedChunkData); - // TODO MICHELE SURL STORE - // SurlStatusStore.getInstance().storeSurlStatus(reducedChunkData.fromSURL(), - // reducedChunkData.status().getStatusCode()); if (!this.isComplete(reducedChunkDataTO)) { - this.completeTO(reducedChunkDataTO, reducedChunkData); + completeTO(reducedChunkDataTO, reducedChunkData); dao.updateIncomplete(reducedChunkDataTO); } } } - log.debug("BoL CHUNK CATALOG: returning " + list); + log.debug("BoL CHUNK CATALOG: returning {}", list); } return list; } @@ -517,7 +501,7 @@ private Collection lookupBoLChunkData( } Collection chunkDataTOCollection = dao.find(surlsUniqueIDs, surlsArray, user.getDn()); - log.debug("PtG CHUNK CATALOG: retrieved data " + chunkDataTOCollection); + log.debug("BoL CHUNK CATALOG: retrieved data {}", chunkDataTOCollection); return buildChunkDataList(chunkDataTOCollection); } @@ -533,7 +517,7 @@ public Collection lookupBoLChunkData(List surls) } Collection chunkDataTOCollection = dao.find(surlsUniqueIDs, surlsArray); - log.debug("PtG CHUNK CATALOG: retrieved data " + chunkDataTOCollection); + log.debug("BoL CHUNK CATALOG: retrieved data {}", chunkDataTOCollection); return buildChunkDataList(chunkDataTOCollection); } @@ -541,29 +525,24 @@ private Collection buildChunkDataList( Collection chunkDataTOCollection) { List list = new ArrayList(); - // TODO MICHELE USER_SURL here I can update all requests that has - // not the new fields set alltogether in a bunch, adding a method to - // the DAO for this purpose BoLPersistentChunkData chunk; for (BoLChunkDataTO chunkTO : chunkDataTOCollection) { chunk = makeOne(chunkTO); - if (chunk != null) { - list.add(chunk); - // TODO MICHELE SURL STORE - // SurlStatusStore.getInstance().storeSurlStatus(chunk.getSURL(), - // chunk.getStatus().getStatusCode()); - if (!this.isComplete(chunkTO)) { - try { - dao.updateIncomplete(this.completeTO(chunkTO, chunk)); - } catch (InvalidReducedBoLChunkDataAttributesException e) { - log - .warn("PtG CHUNK CATALOG! unable to add missing informations on DB to the request: " - + e); - } - } + if (chunk == null) { + continue; + } + list.add(chunk); + if (isComplete(chunkTO)) { + continue; + } + try { + dao.updateIncomplete(this.completeTO(chunkTO, chunk)); + } catch (InvalidReducedBoLChunkDataAttributesException e) { + log.warn("BoL CHUNK CATALOG! unable to add missing informations " + + "on DB to the request: {}", e.getMessage()); } } - log.debug("BoL CHUNK CATALOG: returning " + list); + log.debug("BoL CHUNK CATALOG: returning {}", list); return list; } @@ -604,38 +583,8 @@ synchronized public Collection lookupReducedBoLChunkData( } Collection chunkDataTOCollection = dao.findReduced( gu.getDn(), surlsUniqueIDs, surls); - log.debug("BoL CHUNK CATALOG: retrieved data " + chunkDataTOCollection); + log.debug("BoL CHUNK CATALOG: retrieved data {}", chunkDataTOCollection); return buildReducedChunkDataList(chunkDataTOCollection); - // ArrayList list = new - // ArrayList(); - // if(chunkDataTOCollection.isEmpty()) - // { - // log.debug("BoL CHUNK CATALOG! No chunks found in persistence for " + gu + - // " " + chunkDataTOCollection); - // } - // else - // { - // ReducedBoLChunkData reducedChunkData; - // for(ReducedBoLChunkDataTO reducedChunkDataTO : chunkDataTOCollection) - // { - // reducedChunkData = makeOneReduced(reducedChunkDataTO); - // if(reducedChunkData != null) - // { - // list.add(reducedChunkData); - // // TODO MICHELE SURL STORE - // // - // SurlStatusStore.getInstance().storeSurlStatus(reducedChunkData.fromSURL(), - // reducedChunkData.status().getStatusCode()); - // if(!this.isComplete(reducedChunkDataTO)) - // { - // this.completeTO(reducedChunkDataTO, reducedChunkData); - // dao.updateIncomplete(reducedChunkDataTO); - // } - // } - // } - // log.debug("BoL CHUNK CATALOG: returning " + list); - // } - // return list; } private Collection buildReducedChunkDataList( @@ -647,16 +596,13 @@ private Collection buildReducedChunkDataList( reducedChunkData = makeOneReduced(reducedChunkDataTO); if (reducedChunkData != null) { list.add(reducedChunkData); - // TODO MICHELE SURL STORE - // SurlStatusStore.getInstance().storeSurlStatus(reducedChunkData.fromSURL(), - // reducedChunkData.status().getStatusCode()); if (!this.isComplete(reducedChunkDataTO)) { this.completeTO(reducedChunkDataTO, reducedChunkData); dao.updateIncomplete(reducedChunkDataTO); } } } - log.debug("BoL CHUNK CATALOG: returning " + list); + log.debug("BoL CHUNK CATALOG: returning {}", list); return list; } @@ -747,10 +693,6 @@ synchronized public void addChild(BoLPersistentChunkData chunkData) { /* add the entry and update the Primary Key field */ dao.addChild(to); - // TODO MICHELE SURL STORE - // SurlStatusStore.getInstance().storeSurlStatus(chunkData.getSURL(), - // chunkData.getStatus().getStatusCode()); - /* set the assigned PrimaryKey! */ chunkData.setPrimaryKey(to.getPrimaryKey()); } @@ -793,10 +735,6 @@ synchronized public void add(BoLPersistentChunkData chunkData, /* add the entry and update the Primary Key field! */ dao.addNew(to, gu.getDn()); - // TODO MICHELE SURL STORE - // SurlStatusStore.getInstance().storeSurlStatus(chunkData.getSURL(), - // chunkData.getStatus().getStatusCode()); - /* set the assigned PrimaryKey! */ chunkData.setPrimaryKey(to.getPrimaryKey()); } @@ -809,9 +747,6 @@ synchronized public void add(BoLPersistentChunkData chunkData, synchronized public boolean isSRM_FILE_PINNED(TSURL surl) { return (dao.numberInSRM_SUCCESS(surl.uniqueId()) > 0); - // TODO MICHELE SURL STORE - // return - // TStatusCode.SRM_SUCCESS.equals(SurlStatusStore.getInstance().getSurlStatus(surl)); } /** @@ -831,9 +766,6 @@ synchronized public void transitSRM_SUCCESStoSRM_RELEASED( int index = 0; for (ReducedBoLChunkData chunkData : chunks) { if (chunkData != null) { - // TODO MICHELE SURL STORE - // SurlStatusStore.getInstance().storeSurlStatus(chunkData.fromSURL(), - // chunkData.status().getStatusCode()); primaryKeys[index] = chunkData.primaryKey(); index++; } @@ -863,10 +795,6 @@ synchronized public void transitSRM_SUCCESStoSRM_ABORTED(TSURL surl, } dao.transitSRM_SUCCESStoSRM_ABORTED(surl.uniqueId(), surl.toString(), explanation); - // TODO MICHELE SURL STORE - // SurlStatusStore.getInstance().storeSurlStatus(surl,TStatusCode.SRM_ABORTED); - // PinnedFilesCatalog.getInstance().removeAllJit(surl); - // PinnedfilesCatalog.getInstance().removeVolatile(surl); } /** @@ -877,12 +805,6 @@ synchronized public void transitSRM_SUCCESStoSRM_ABORTED(TSURL surl, synchronized public void transitExpiredSRM_SUCCESS() { dao.transitExpiredSRM_SUCCESS(); - // TODO MICHELE SURL STORE - // for (TSURL surl : expiredSurls) - // { - // SurlStatusStore.getInstance().storeSurlStatus(surl, - // TStatusCode.SRM_RELEASED); - // } } public void updateFromPreviousStatus(TRequestToken requestToken, diff --git a/src/main/java/it/grid/storm/catalogs/BoLChunkDAO.java b/src/main/java/it/grid/storm/catalogs/BoLChunkDAO.java index 2e5d9193..325f2d03 100644 --- a/src/main/java/it/grid/storm/catalogs/BoLChunkDAO.java +++ b/src/main/java/it/grid/storm/catalogs/BoLChunkDAO.java @@ -139,16 +139,13 @@ public synchronized void addChild(BoLChunkDataTO to) { // insertion try { - // WARNING!!!! We are forced to run a query to get the ID of the request, - // which should - // NOT be so - // because the corresponding request object should have been changed with - // the extra - // field! However, it is not possible - // at the moment to perform such change because of strict deadline and the - // change could - // wreak havoc - // the code. So we are forced to make this query!!! + /* WARNING!!!! We are forced to run a query to get the ID of the request, + * which should NOT be so because the corresponding request object should + * have been changed with the extra field! However, it is not possible + * at the moment to perform such change because of strict deadline and + * the change could wreak havoc the code. So we are forced to make this + * query!!! + */ // begin transaction con.setAutoCommit(false); @@ -163,7 +160,7 @@ public synchronized void addChild(BoLChunkDataTO to) { id.setString(1, to.getRequestToken()); logWarnings(id.getWarnings()); - log.debug("BoL CHUNK DAO: addChild; " + id.toString()); + log.debug("BoL CHUNK DAO: addChild; {}", id.toString()); rsid = id.executeQuery(); logWarnings(id.getWarnings()); @@ -180,12 +177,12 @@ public synchronized void addChild(BoLChunkDataTO to) { // update primary key reading the generated key to.setPrimaryKey(id_s); } catch (SQLException e) { - log.error("BoL CHUNK DAO: unable to complete addChild! BoLChunkDataTO: " - + to + "; exception received:" + e); + log.error("BoL CHUNK DAO: unable to complete addChild! BoLChunkDataTO: {}; " + + "exception received: {}", to, e.getMessage(), e); rollback(con); } catch (Exception e) { - log.error("BoL CHUNK DAO: unable to complete addChild! BoLChunkDataTO: " - + to + "; exception received:" + e); + log.error("BoL CHUNK DAO: unable to complete addChild! BoLChunkDataTO: {}; " + + "exception received: {}", to, e.getMessage(), e); rollback(con); } finally { close(rsid); @@ -254,7 +251,7 @@ public synchronized void addNew(BoLChunkDataTO to, String client_dn) { addNew.setInt(9, to.getDeferredStartTime()); logWarnings(addNew.getWarnings()); - log.trace("BoL CHUNK DAO: addNew; " + addNew.toString()); + log.trace("BoL CHUNK DAO: addNew; {}", addNew.toString()); addNew.execute(); logWarnings(addNew.getWarnings()); @@ -272,7 +269,7 @@ public synchronized void addNew(BoLChunkDataTO to, String client_dn) { addProtocols.setString(2, i.next()); logWarnings(addProtocols.getWarnings()); - log.trace("BoL CHUNK DAO: addNew; " + addProtocols.toString()); + log.trace("BoL CHUNK DAO: addNew; {}", addProtocols.toString()); addProtocols.execute(); logWarnings(addProtocols.getWarnings()); } @@ -289,13 +286,12 @@ public synchronized void addNew(BoLChunkDataTO to, String client_dn) { // update primary key reading the generated key to.setPrimaryKey(id_s); } catch (SQLException e) { - log - .error("BoL CHUNK DAO: Rolling back! Unable to complete addNew! BoLChunkDataTO: " - + to + "; exception received:" + e); + log.error("BoL CHUNK DAO: Rolling back! Unable to complete addNew! " + + "BoLChunkDataTO: {}; exception received: {}", to, e.getMessage(), e); rollback(con); } catch (Exception e) { - log.error("BoL CHUNK DAO: unable to complete addNew! BoLChunkDataTO: " - + to + "; exception received:" + e); + log.error("BoL CHUNK DAO: unable to complete addNew! BoLChunkDataTO: {}; " + + "exception received: {}", to, e.getMessage(), e); rollback(con); } finally { close(rs_new); @@ -343,7 +339,7 @@ private synchronized int fillBoLTables(BoLChunkDataTO to, int requestQueueID) addDirOption.setInt(3, to.getNumLevel()); logWarnings(addDirOption.getWarnings()); - log.trace("BoL CHUNK DAO: addNew; " + addDirOption.toString()); + log.trace("BoL CHUNK DAO: addNew; {}", addDirOption.toString()); addDirOption.execute(); logWarnings(addDirOption.getWarnings()); @@ -363,14 +359,13 @@ private synchronized int fillBoLTables(BoLChunkDataTO to, int requestQueueID) addBoL.setString(3, to.getFromSURL()); logWarnings(addBoL.getWarnings()); - // TODO MICHELE USER_SURL set new fields addBoL.setString(4, to.normalizedStFN()); logWarnings(addBoL.getWarnings()); addBoL.setInt(5, to.sulrUniqueID()); logWarnings(addBoL.getWarnings()); - log.trace("BoL CHUNK DAO: addNew; " + addBoL.toString()); + log.trace("BoL CHUNK DAO: addNew; {}", addBoL.toString()); addBoL.execute(); logWarnings(addBoL.getWarnings()); @@ -394,8 +389,6 @@ private synchronized int fillBoLTables(BoLChunkDataTO to, int requestQueueID) addChild.execute(); logWarnings(addChild.getWarnings()); - // rs_s = addChild.getGeneratedKeys(); - // return extractID(rs_s); return id_g; } finally { close(rs_do); @@ -422,7 +415,6 @@ public synchronized void update(BoLChunkDataTO to) { } PreparedStatement updateFileReq = null; try { - // TODO MICHELE USER_SURL set new fields // ready updateFileReq... updateFileReq = con .prepareStatement("UPDATE request_queue rq JOIN (status_BoL sb, request_BoL rb) ON (rq.ID=rb.request_queueID AND sb.request_BoLID=rb.ID)" @@ -441,7 +433,6 @@ public synchronized void update(BoLChunkDataTO to) { updateFileReq.setInt(4, to.getLifeTime()); logWarnings(updateFileReq.getWarnings()); - // TODO MICHELE USER_SURL fill new fields updateFileReq.setString(5, to.normalizedStFN()); logWarnings(updateFileReq.getWarnings()); @@ -451,11 +442,11 @@ public synchronized void update(BoLChunkDataTO to) { updateFileReq.setLong(7, to.getPrimaryKey()); logWarnings(updateFileReq.getWarnings()); // execute update - log.trace("BoL CHUNK DAO: update method; " + updateFileReq.toString()); + log.trace("BoL CHUNK DAO: update method; {}", updateFileReq.toString()); updateFileReq.executeUpdate(); logWarnings(updateFileReq.getWarnings()); } catch (SQLException e) { - log.error("BoL CHUNK DAO: Unable to complete update! " + e); + log.error("BoL CHUNK DAO: Unable to complete update! {}", e.getMessage(), e); } finally { close(updateFileReq); } @@ -467,16 +458,14 @@ public synchronized void update(BoLChunkDataTO to) { * * @param chunkTO */ - // TODO MICHELE USER_SURL new method public synchronized void updateIncomplete(ReducedBoLChunkDataTO chunkTO) { if (!checkConnection()) { - log - .error("BoL CHUNK DAO: updateIncomplete - unable to get a valid connection!"); + log.error("BoL CHUNK DAO: updateIncomplete - unable to get a valid connection!"); return; } - String str = "UPDATE request_BoL SET normalized_sourceSURL_StFN=?, sourceSURL_uniqueID=? " - + "WHERE ID=?"; + String str = "UPDATE request_BoL SET normalized_sourceSURL_StFN=?, " + + "sourceSURL_uniqueID=? WHERE ID=?"; PreparedStatement stmt = null; try { stmt = con.prepareStatement(str); @@ -491,11 +480,12 @@ public synchronized void updateIncomplete(ReducedBoLChunkDataTO chunkTO) { stmt.setLong(3, chunkTO.primaryKey()); logWarnings(stmt.getWarnings()); - log.trace("BoL CHUNK DAO - update incomplete: " + stmt.toString()); + log.trace("BoL CHUNK DAO - update incomplete: {}", stmt.toString()); stmt.executeUpdate(); logWarnings(stmt.getWarnings()); } catch (SQLException e) { - log.error("BoL CHUNK DAO: Unable to complete update incomplete! " + e); + log.error("BoL CHUNK DAO: Unable to complete update incomplete! {}", + e.getMessage(), e); } finally { close(stmt); } @@ -533,16 +523,13 @@ public synchronized BoLChunkDataTO refresh(long primary_key) { logWarnings(find.getWarnings()); BoLChunkDataTO aux = null; - // The result shoul be un - // TODO REMOVE THIS WHILE while (rs.next()) { aux = new BoLChunkDataTO(); aux.setStatus(rs.getInt("statusCode")); } return aux; } catch (SQLException e) { - log.error("BoL CHUNK DAO: " + e); - /* Return null TransferObject! */ + log.error("BoL CHUNK DAO: {}", e.getMessage(), e); return null; } finally { close(rs); @@ -586,7 +573,7 @@ public synchronized Collection find(TRequestToken requestToken) find.setString(1, strToken); logWarnings(find.getWarnings()); - log.trace("BoL CHUNK DAO: find method; " + find.toString()); + log.trace("BoL CHUNK DAO: find method; {}", find.toString()); rs = find.executeQuery(); logWarnings(find.getWarnings()); while (rs.next()) { @@ -595,7 +582,6 @@ public synchronized Collection find(TRequestToken requestToken) close(rs); close(find); - // TODO MICHELE USER_SURL get new fields // get chunks of the request str = "SELECT sb.statusCode, rq.timeStamp, rq.pinLifetime, rq.deferredStartTime, rb.ID, rb.sourceSURL, rb.normalized_sourceSURL_StFN, rb.sourceSURL_uniqueID, d.isSourceADirectory, d.allLevelRecursive, d.numOfLevels " + "FROM request_queue rq JOIN (request_BoL rb, status_BoL sb) " @@ -612,7 +598,7 @@ public synchronized Collection find(TRequestToken requestToken) StatusCodeConverter.getInstance().toDB(TStatusCode.SRM_ABORTED)); logWarnings(find.getWarnings()); - log.trace("BoL CHUNK DAO: find method; " + find.toString()); + log.trace("BoL CHUNK DAO: find method; {}", find.toString()); rs = find.executeQuery(); logWarnings(find.getWarnings()); @@ -626,7 +612,6 @@ public synchronized Collection find(TRequestToken requestToken) chunkDataTO.setTimeStamp(rs.getTimestamp("rq.timeStamp")); chunkDataTO.setPrimaryKey(rs.getLong("rb.ID")); chunkDataTO.setFromSURL(rs.getString("rb.sourceSURL")); - // TODO MICHELE USER_SURL fill new fields chunkDataTO.setNormalizedStFN(rs .getString("rb.normalized_sourceSURL_StFN")); @@ -643,7 +628,7 @@ public synchronized Collection find(TRequestToken requestToken) } return list; } catch (SQLException e) { - log.error("BOL CHUNK DAO: " + e); + log.error("BOL CHUNK DAO: {}", e.getMessage(), e); /* Return empty Collection! */ return new ArrayList(); } finally { @@ -660,14 +645,12 @@ public synchronized Collection findReduced( String reqtoken) { if (!checkConnection()) { - log - .error("BoL CHUNK DAO: findReduced - unable to get a valid connection!"); + log.error("BoL CHUNK DAO: findReduced - unable to get a valid connection!"); return new ArrayList(); } PreparedStatement find = null; ResultSet rs = null; try { - // TODO MICHELE USER_SURL get new fields // get reduced chunks String str = "SELECT sb.statusCode, rb.ID, rb.sourceSURL, rb.normalized_sourceSURL_StFN, rb.sourceSURL_uniqueID " + "FROM request_queue rq JOIN (request_BoL rb, status_BoL sb) " @@ -680,8 +663,7 @@ public synchronized Collection findReduced( find.setString(1, reqtoken); logWarnings(find.getWarnings()); - log.trace("BoL CHUNK DAO! findReduced with request token; " - + find.toString()); + log.trace("BoL CHUNK DAO! findReduced with request token; {}", find.toString()); rs = find.executeQuery(); logWarnings(find.getWarnings()); @@ -691,19 +673,17 @@ public synchronized Collection findReduced( chunkDataTO.setStatus(rs.getInt("sb.statusCode")); chunkDataTO.setPrimaryKey(rs.getLong("rb.ID")); chunkDataTO.setFromSURL(rs.getString("rb.sourceSURL")); - // TODO MICHELE USER_SURL fill new fields chunkDataTO.setNormalizedStFN(rs .getString("rb.normalized_sourceSURL_StFN")); int uniqueID = rs.getInt("rb.sourceSURL_uniqueID"); if (!rs.wasNull()) { chunkDataTO.setSurlUniqueID(uniqueID); } - list.add(chunkDataTO); } return list; } catch (SQLException e) { - log.error("BOL CHUNK DAO: " + e); + log.error("BOL CHUNK DAO: {}", e.getMessage(), e); /* Return empty Collection! */ return new ArrayList(); } finally { @@ -721,17 +701,12 @@ public synchronized Collection findReduced( TRequestToken requestToken, int[] surlUniqueIDs, String[] surls) { if (!checkConnection()) { - log - .error("BoL CHUNK DAO: findReduced - unable to get a valid connection!"); - return new ArrayList(); // return empty Collection! + log.error("BoL CHUNK DAO: findReduced - unable to get a valid connection!"); + return new ArrayList(); } PreparedStatement find = null; ResultSet rs = null; try { - // TODO MICHELE USER_SURL get new fields and select on the uniqueID and on - // the fromSurl - // TODO MICHELE USER_SURL when the uniqueID and normalized surl will be - // made on the FrontEnd remove the String[] surls parameter /* * NOTE: we search also on the fromSurl because otherwise we lost all * request_Bol that have not the uniqueID set because are not yet been @@ -752,8 +727,7 @@ public synchronized Collection findReduced( find.setString(1, requestToken.getValue()); logWarnings(find.getWarnings()); - log.trace("BoL CHUNK DAO! findReduced with griduser+surlarray; " - + find.toString()); + log.trace("BoL CHUNK DAO! findReduced with griduser+surlarray; {}", find.toString()); rs = find.executeQuery(); logWarnings(find.getWarnings()); @@ -763,20 +737,18 @@ public synchronized Collection findReduced( chunkDataTO.setStatus(rs.getInt("sb.statusCode")); chunkDataTO.setPrimaryKey(rs.getLong("rb.ID")); chunkDataTO.setFromSURL(rs.getString("rb.sourceSURL")); - // TODO MICHELE USER_SURL fill new fields chunkDataTO.setNormalizedStFN(rs .getString("rb.normalized_sourceSURL_StFN")); int uniqueID = rs.getInt("rb.sourceSURL_uniqueID"); if (!rs.wasNull()) { chunkDataTO.setSurlUniqueID(uniqueID); } - list.add(chunkDataTO); } return list; } catch (SQLException e) { - log.error("BoL CHUNK DAO: " + e); - return new ArrayList(); // return empty Collection! + log.error("BoL CHUNK DAO: {}", e.getMessage(), e); + return new ArrayList(); } finally { close(rs); close(find); @@ -792,17 +764,12 @@ public synchronized Collection findReduced( String griduser, int[] surlUniqueIDs, String[] surls) { if (!checkConnection()) { - log - .error("BoL CHUNK DAO: findReduced - unable to get a valid connection!"); - return new ArrayList(); // return empty Collection! + log.error("BoL CHUNK DAO: findReduced - unable to get a valid connection!"); + return new ArrayList(); } PreparedStatement find = null; ResultSet rs = null; try { - // TODO MICHELE USER_SURL get new fields and select on the uniqueID and on - // the fromSurl - // TODO MICHELE USER_SURL when the uniqueID and normalized surl will be - // made on the FrontEnd remove the String[] surls parameter /* * NOTE: we search also on the fromSurl because otherwise we lost all * request_Bol that have not the uniqueID set because are not yet been @@ -823,8 +790,7 @@ public synchronized Collection findReduced( find.setString(1, griduser); logWarnings(find.getWarnings()); - log.trace("BoL CHUNK DAO! findReduced with griduser+surlarray; " - + find.toString()); + log.trace("BoL CHUNK DAO! findReduced with griduser+surlarray; {}", find.toString()); rs = find.executeQuery(); logWarnings(find.getWarnings()); @@ -834,20 +800,18 @@ public synchronized Collection findReduced( chunkDataTO.setStatus(rs.getInt("sb.statusCode")); chunkDataTO.setPrimaryKey(rs.getLong("rb.ID")); chunkDataTO.setFromSURL(rs.getString("rb.sourceSURL")); - // TODO MICHELE USER_SURL fill new fields chunkDataTO.setNormalizedStFN(rs .getString("rb.normalized_sourceSURL_StFN")); int uniqueID = rs.getInt("rb.sourceSURL_uniqueID"); if (!rs.wasNull()) { chunkDataTO.setSurlUniqueID(uniqueID); } - list.add(chunkDataTO); } return list; } catch (SQLException e) { - log.error("BoL CHUNK DAO: " + e); - return new ArrayList(); // return empty Collection! + log.error("BoL CHUNK DAO: {}", e.getMessage(), e); + return new ArrayList(); } finally { close(rs); close(find); @@ -860,13 +824,10 @@ public synchronized Collection findReduced( * in the isSRM_SUCCESS method invocation. In case of any error, 0 is * returned. */ - // TODO MICHELE USER_SURL use the unique ID to perform the select on the - // request_Bol table public synchronized int numberInSRM_SUCCESS(int surlUniqueID) { if (!checkConnection()) { - log - .error("BoL CHUNK DAO: numberInSRM_SUCCESS - unable to get a valid connection!"); + log.error("BoL CHUNK DAO: numberInSRM_SUCCESS - unable to get a valid connection!"); return 0; } String str = "SELECT COUNT(rb.ID) " @@ -886,8 +847,7 @@ public synchronized int numberInSRM_SUCCESS(int surlUniqueID) { StatusCodeConverter.getInstance().toDB(TStatusCode.SRM_SUCCESS)); logWarnings(find.getWarnings()); - log.trace("BoL CHUNK DAO - numberInSRM_SUCCESS method: " - + find.toString()); + log.trace("BoL CHUNK DAO - numberInSRM_SUCCESS method: {}", find.toString()); rs = find.executeQuery(); logWarnings(find.getWarnings()); @@ -897,9 +857,8 @@ public synchronized int numberInSRM_SUCCESS(int surlUniqueID) { } return numberFileSuccessful; } catch (SQLException e) { - log - .error("BoL CHUNK DAO! Unable to determine numberInSRM_SUCCESS! Returning 0! " - + e); + log.error("BoL CHUNK DAO! Unable to determine numberInSRM_SUCCESS! " + + "Returning 0! ", e.getMessage(), e); return 0; } finally { close(rs); @@ -922,8 +881,7 @@ public synchronized int numberInSRM_SUCCESS(int surlUniqueID) { public synchronized void signalMalformedBoLChunk(BoLChunkDataTO auxTO) { if (!checkConnection()) { - log - .error("BoL CHUNK DAO: signalMalformedBoLChunk - unable to get a valid connection!"); + log.error("BoL CHUNK DAO: signalMalformedBoLChunk - unable to get a valid connection!"); return; } String signalSQL = "UPDATE status_BoL SET statusCode=" @@ -937,13 +895,13 @@ public synchronized void signalMalformedBoLChunk(BoLChunkDataTO auxTO) { signal.setString(1, "Request is malformed!"); logWarnings(signal.getWarnings()); - log.trace("BoL CHUNK DAO: signalMalformed; " + signal.toString()); + log.trace("BoL CHUNK DAO: signalMalformed; {}", signal.toString()); signal.executeUpdate(); logWarnings(signal.getWarnings()); } catch (SQLException e) { - log.error("BoLChunkDAO! Unable to signal in DB that the" - + " request was malformed! Request: " + auxTO.toString() - + "; Exception: " + e.toString()); + log.error("BoLChunkDAO! Unable to signal in DB that the request was " + + "malformed! Request: {}; Exception: {}", auxTO.toString(), + e.toString(), e); } finally { close(signal); } @@ -956,15 +914,10 @@ public synchronized void signalMalformedBoLChunk(BoLChunkDataTO auxTO) { * * @return */ - // TODO MICHELE USER_SURL debug public synchronized List transitExpiredSRM_SUCCESS() { - // TODO: put a limit on the queries..... - // TODO MICHELE USER_SURL moved the checks for surl requests from the surl - // tring to the surl unique ID if (!checkConnection()) { - log - .error("BoL CHUNK DAO: transitExpiredSRM_SUCCESS - unable to get a valid connection!"); + log.error("BoL CHUNK DAO: transitExpiredSRM_SUCCESS - unable to get a valid connection!"); return new ArrayList(); } @@ -998,8 +951,8 @@ public synchronized List transitExpiredSRM_SUCCESS() { TSURL tsurl = TSURL.makeFromStringWellFormed(sourceSURL); uniqueID = tsurl.uniqueId(); } catch (InvalidTSURLAttributesException e) { - log.warn("BoLChunkDAO! unable to build the TSURL from " - + sourceSURL + " : InvalidTSURLAttributesException " + e); + log.warn("BoLChunkDAO! unable to build the TSURL from {}: " + + "InvalidTSURLAttributesException ", sourceSURL, e.getMessage()); } } expiredSurlMap.put(sourceSURL, uniqueID); @@ -1007,12 +960,12 @@ public synchronized List transitExpiredSRM_SUCCESS() { if (expiredSurlMap.isEmpty()) { commit(con); - log - .trace("BoLChunkDAO! No chunk of BoL request was transited from SRM_SUCCESS to SRM_RELEASED."); + log.trace("BoLChunkDAO! No chunk of BoL request was transited from " + + "SRM_SUCCESS to SRM_RELEASED."); return new ArrayList(); } } catch (SQLException e) { - log.error("BoLChunkDAO! SQLException." + e); + log.error("BoLChunkDAO! SQLException.", e.getMessage(), e); rollback(con); return new ArrayList(); } finally { @@ -1040,8 +993,8 @@ public synchronized List transitExpiredSRM_SUCCESS() { StatusCodeConverter.getInstance().toDB(TStatusCode.SRM_SUCCESS)); logWarnings(prepStatement.getWarnings()); - log.trace("BoL CHUNK DAO - transitExpiredSRM_SUCCESS method: " - + prepStatement.toString()); + log.trace("BoL CHUNK DAO - transitExpiredSRM_SUCCESS method: {}", + prepStatement.toString()); int count = prepStatement.executeUpdate(); logWarnings(prepStatement.getWarnings()); @@ -1050,14 +1003,12 @@ public synchronized List transitExpiredSRM_SUCCESS() { log.trace("BoLChunkDAO! No chunk of BoL request was" + " transited from SRM_SUCCESS to SRM_RELEASED."); } else { - log.info("BoLChunkDAO! " + count - + " chunks of BoL requests were transited from" - + " SRM_SUCCESS to SRM_RELEASED."); + log.info("BoLChunkDAO! {} chunks of BoL requests were transited from " + + "SRM_SUCCESS to SRM_RELEASED.", count); } } catch (SQLException e) { - log - .error("BoLChunkDAO! Unable to transit expired SRM_SUCCESS chunks of BoL requests, to SRM_RELEASED! " - + e); + log.error("BoLChunkDAO! Unable to transit expired SRM_SUCCESS chunks of " + + "BoL requests, to SRM_RELEASED! ", e.getMessage(), e); rollback(con); return new ArrayList(); } finally { @@ -1096,8 +1047,8 @@ public synchronized List transitExpiredSRM_SUCCESS() { TSURL tsurl = TSURL.makeFromStringWellFormed(sourceSURL); uniqueID = tsurl.uniqueId(); } catch (InvalidTSURLAttributesException e) { - log.warn("BoLChunkDAO! unable to build the TSURL from " - + sourceSURL + " : InvalidTSURLAttributesException " + e); + log.warn("BoLChunkDAO! unable to build the TSURL from {}: " + + "InvalidTSURLAttributesException ", sourceSURL, e.getMessage()); } } pinnedSurlSet.add(uniqueID); @@ -1127,8 +1078,8 @@ public synchronized List transitExpiredSRM_SUCCESS() { TSURL tsurl = TSURL.makeFromStringWellFormed(sourceSURL); uniqueID = tsurl.uniqueId(); } catch (InvalidTSURLAttributesException e) { - log.warn("BoLChunkDAO! unable to build the TSURL from " - + sourceSURL + " : InvalidTSURLAttributesException " + e); + log.warn("BoLChunkDAO! unable to build the TSURL from {}: " + + "InvalidTSURLAttributesException {}", sourceSURL, e.getMessage()); } } pinnedSurlSet.add(uniqueID); @@ -1137,7 +1088,7 @@ public synchronized List transitExpiredSRM_SUCCESS() { commit(con); } catch (SQLException e) { - log.error("BoLChunkDAO! SQLException." + e); + log.error("BoLChunkDAO! SQLException. {}", e.getMessage(), e); rollback(con); } finally { close(prepStatement); @@ -1151,9 +1102,8 @@ public synchronized List transitExpiredSRM_SUCCESS() { try { surl = TSURL.makeFromStringValidate(surlEntry.getKey()); } catch (InvalidTSURLAttributesException e) { - log - .error("Invalid SURL, cannot release the pin (Extended Attribute): " - + surlEntry.getKey()); + log.error("Invalid SURL, cannot release the pin " + + "(Extended Attribute): {}", surlEntry.getKey()); continue; } expiredSurlList.add(surl); @@ -1161,11 +1111,8 @@ public synchronized List transitExpiredSRM_SUCCESS() { try { stori = NamespaceDirector.getNamespace().resolveStoRIbySURL(surl); } catch (Throwable e) { - log - .error(String.format( - "Invalid SURL %s cannot release the pin. %s: %s", - surlEntry.getKey(), e.getClass().getCanonicalName(), - e.getMessage())); + log.error("Invalid SURL {} cannot release the pin. {}: {}", + surlEntry.getKey(), e.getClass().getCanonicalName(), e.getMessage()); continue; } @@ -1188,14 +1135,9 @@ public synchronized void transitSRM_SUCCESStoSRM_ABORTED(int surlUniqueID, String surl, String explanation) { if (!checkConnection()) { - log - .error("BoL CHUNK DAO: transitSRM_SUCCESStoSRM_ABORTED - unable to get a valid connection!"); + log.error("BoL CHUNK DAO: transitSRM_SUCCESStoSRM_ABORTED - unable to get a valid connection!"); return; } - // TODO MICHELE USER_SURL use the unique ID to perform the select on the - // request_Bol table (removed a bug) - // TODO MICHELE USER_SURL when the uniqueID and normalized surl is provided - // by the FrontEnd remove the String surl parameter String str = "UPDATE " + "status_BoL sb JOIN request_BoL rb ON sb.request_BoLID=rb.ID " + "SET sb.statusCode=?, sb.explanation=?, sb.transferURL=NULL " @@ -1221,20 +1163,19 @@ public synchronized void transitSRM_SUCCESStoSRM_ABORTED(int surlUniqueID, stmt.setString(5, surl); logWarnings(stmt.getWarnings()); - log.trace("BoL CHUNK DAO - transitSRM_SUCCESStoSRM_ABORTED: " - + stmt.toString()); + log.trace("BoL CHUNK DAO - transitSRM_SUCCESStoSRM_ABORTED: {}", stmt.toString()); int count = stmt.executeUpdate(); logWarnings(stmt.getWarnings()); if (count > 0) { - log.info("BoL CHUNK DAO! " + count - + " chunks were transited from SRM_SUCCESS to SRM_ABORTED."); + log.info("BoL CHUNK DAO! {} chunks were transited from SRM_SUCCESS " + + "to SRM_ABORTED.", count); } else { - log.trace("BoL CHUNK DAO! No chunks were transited " - + "from SRM_SUCCESS to SRM_ABORTED."); + log.trace("BoL CHUNK DAO! No chunks were transited from SRM_SUCCESS " + + "to SRM_ABORTED."); } } catch (SQLException e) { - log.error("BoL CHUNK DAO! Unable to transitSRM_SUCCESStoSRM_ABORTED! " - + e); + log.error("BoL CHUNK DAO! Unable to transitSRM_SUCCESStoSRM_ABORTED! {}", + e.getMessage(), e); } finally { close(stmt); } @@ -1250,17 +1191,10 @@ public synchronized void transitSRM_SUCCESStoSRM_ABORTED(int surlUniqueID, public synchronized void transitSRM_SUCCESStoSRM_RELEASED(long[] ids) { if (!checkConnection()) { - log - .error("BoL CHUNK DAO: transitSRM_SUCCESStoSRM_RELEASED - unable to get a valid connection!"); + log.error("BoL CHUNK DAO: transitSRM_SUCCESStoSRM_RELEASED - unable to get a valid connection!"); return; } - String str = - // "UPDATE " - // + - // "status_BoL s JOIN (request_BoL rg, request_queue r) ON s.request_BoLID=rg.ID AND rg.request_queueID=r.ID " - // + "SET s.statusCode=? " + "WHERE s.statusCode=? AND s.ID IN " - // + makeWhereString(ids); - "UPDATE " + "status_BoL " + "SET statusCode=? " + String str = "UPDATE status_BoL SET statusCode=? " + "WHERE statusCode=? AND request_BoLID IN " + makeWhereString(ids); PreparedStatement stmt = null; try { @@ -1274,23 +1208,20 @@ public synchronized void transitSRM_SUCCESStoSRM_RELEASED(long[] ids) { StatusCodeConverter.getInstance().toDB(TStatusCode.SRM_SUCCESS)); logWarnings(stmt.getWarnings()); - log.trace("BoL CHUNK DAO - transitSRM_SUCCESStoSRM_RELEASED: " - + stmt.toString()); + log.trace("BoL CHUNK DAO - transitSRM_SUCCESStoSRM_RELEASED: {}", + stmt.toString()); int count = stmt.executeUpdate(); logWarnings(stmt.getWarnings()); if (count == 0) { log.trace("BoL CHUNK DAO! No chunk of BoL request " + "was transited from SRM_SUCCESS to SRM_RELEASED."); } else { - log - .info("BoL CHUNK DAO! " - + count - + " chunks of BoL requests were transited from SRM_SUCCESS to SRM_RELEASED."); + log.info("BoL CHUNK DAO! {} chunks of BoL requests were transited " + + "from SRM_SUCCESS to SRM_RELEASED.", count); } } catch (SQLException e) { - log - .error("BoL CHUNK DAO! Unable to transit chunks from SRM_SUCCESS to SRM_RELEASED! " - + e); + log.error("BoL CHUNK DAO! Unable to transit chunks from SRM_SUCCESS " + + "to SRM_RELEASED! {}", e.getMessage(), e); } finally { close(stmt); } @@ -1308,8 +1239,7 @@ public synchronized void transitSRM_SUCCESStoSRM_RELEASED(long[] ids, * the where subquery. */ if (!checkConnection()) { - log - .error("BoL CHUNK DAO: transitSRM_SUCCESStoSRM_RELEASED - unable to get a valid connection!"); + log.error("BoL CHUNK DAO: transitSRM_SUCCESStoSRM_RELEASED - unable to get a valid connection!"); return; } String str = "UPDATE " @@ -1328,21 +1258,20 @@ public synchronized void transitSRM_SUCCESStoSRM_RELEASED(long[] ids, StatusCodeConverter.getInstance().toDB(TStatusCode.SRM_SUCCESS)); logWarnings(stmt.getWarnings()); - log.trace("BoL CHUNK DAO - transitSRM_SUCCESStoSRM_RELEASED: " - + stmt.toString()); + log.trace("BoL CHUNK DAO - transitSRM_SUCCESStoSRM_RELEASED: {}", + stmt.toString()); int count = stmt.executeUpdate(); logWarnings(stmt.getWarnings()); if (count == 0) { log.trace("BoL CHUNK DAO! No chunk of BoL request was " + "transited from SRM_SUCCESS to SRM_RELEASED."); } else { - log.info("BoL CHUNK DAO! " + count - + " chunks of BoL requests were transited " - + "from SRM_SUCCESS to SRM_RELEASED."); + log.info("BoL CHUNK DAO! {} chunks of BoL requests were transited " + + "from SRM_SUCCESS to SRM_RELEASED.", count); } } catch (SQLException e) { log.error("BoL CHUNK DAO! Unable to transit chunks " - + "from SRM_SUCCESS to SRM_RELEASED! " + e); + + "from SRM_SUCCESS to SRM_RELEASED! {}", e.getMessage(), e); } finally { close(stmt); } @@ -1372,8 +1301,8 @@ private void close(Statement stmt) { try { stmt.close(); } catch (Exception e) { - log.error("BoL CHUNK DAO! Unable to close Statement " + stmt.toString() - + " - Exception: " + e); + log.error("BoL CHUNK DAO! Unable to close Statement {} - Exception: {}", + stmt.toString(), e.getMessage(), e); } } } @@ -1385,7 +1314,7 @@ private void commit(Connection con) { con.commit(); con.setAutoCommit(true); } catch (SQLException e) { - log.error("BoL, SQL EXception", e); + log.error("BoL, SQL EXception {}", e.getMessage(), e); } } } @@ -1401,7 +1330,7 @@ private void rollback(Connection con) { con.setAutoCommit(true); log.error("BoL CHUNK DAO: roll back successful!"); } catch (SQLException e2) { - log.error("BoL CHUNK DAO: roll back failed! " + e2); + log.error("BoL CHUNK DAO: roll back failed! {}", e2.getMessage(), e2); } } } @@ -1417,12 +1346,11 @@ private int extractID(ResultSet rs) throws Exception { } if (rs.next()) { return rs.getInt(1); - } else { - log.error("BoL CHUNK DAO! It was not possible to establish " - + "the assigned autoincrement primary key!"); - throw new Exception( - "BoL CHUNK DAO! It was not possible to establish the assigned autoincrement primary key!"); } + log.error("BoL CHUNK DAO! It was not possible to establish " + + "the assigned autoincrement primary key!"); + throw new Exception( + "BoL CHUNK DAO! It was not possible to establish the assigned autoincrement primary key!"); } /** @@ -1431,9 +1359,9 @@ private int extractID(ResultSet rs) throws Exception { private void logWarnings(SQLWarning w) { if (w != null) { - log.debug("BoL CHUNK DAO: " + w.toString()); + log.debug("BoL CHUNK DAO: {}", w.toString()); while ((w = w.getNextWarning()) != null) { - log.debug("BoL CHUNK DAO: " + w.toString()); + log.debug("BoL CHUNK DAO: {}", w.toString()); } } } @@ -1487,7 +1415,7 @@ private String makeSurlString(String[] surls) { requestedSURL = SURL.makeSURLfromString(surls[i]); } catch (NamespaceException e) { log.error(e.getMessage()); - log.debug("Skip '" + surls[i] + "' during query creation"); + log.debug("Skip '{}' during query creation", surls[i]); continue; } @@ -1524,9 +1452,11 @@ private boolean setUpConnection() { response = con.isValid(0); } } catch (ClassNotFoundException e) { - log.error("BoL CHUNK DAO! Exception in setUpConnection! " + e); + log.error("BoL CHUNK DAO! Exception in setUpConnection! {}", + e.getMessage(), e); } catch (SQLException e) { - log.error("BoL CHUNK DAO! Exception in setUpConenction! " + e); + log.error("BoL CHUNK DAO! Exception in setUpConenction! {}", + e.getMessage(), e); } return response; } @@ -1558,8 +1488,8 @@ private void takeDownConnection() { try { con.close(); } catch (SQLException e) { - log - .error("BoL CHUNK DAO! Exception in takeDownConnection method: " + e); + log.error("BoL CHUNK DAO! Exception in takeDownConnection method: {}", + e.getMessage(), e); } } } @@ -1642,22 +1572,19 @@ public synchronized void doUpdateStatusOnMatchingStatus( .setInt(2, StatusCodeConverter.getInstance().toDB(expectedStatusCode)); logWarnings(stmt.getWarnings()); - log.trace("BOL CHUNK DAO - updateStatusOnMatchingStatus: " - + stmt.toString()); + log.trace("BOL CHUNK DAO - updateStatusOnMatchingStatus: {}", stmt.toString()); int count = stmt.executeUpdate(); logWarnings(stmt.getWarnings()); if (count == 0) { - log.trace("BOL CHUNK DAO! No chunk of BOL request was" - + " updated from " + expectedStatusCode + " to " + newStatusCode - + "."); + log.trace("BOL CHUNK DAO! No chunk of BOL request was updated from {} " + + "to {}.", expectedStatusCode, newStatusCode); } else { - log.debug("BOL CHUNK DAO! " + count - + " chunks of BOL requests were updated from " + expectedStatusCode - + " to " + newStatusCode + "."); + log.debug("BOL CHUNK DAO! {} chunks of BOL requests were updated " + + "from {} to {}.", count, expectedStatusCode, newStatusCode); } } catch (SQLException e) { - log.error("BOL CHUNK DAO! Unable to updated from " + expectedStatusCode - + " to " + newStatusCode + " !" + e); + log.error("BOL CHUNK DAO! Unable to updated from {} to {}!", + expectedStatusCode, newStatusCode, e); } finally { close(stmt); } @@ -1705,7 +1632,6 @@ private synchronized Collection find(int[] surlsUniqueIDs, PreparedStatement find = null; ResultSet rs = null; try { - // TODO MICHELE USER_SURL get new fields // get chunks of the request String str = "SELECT rq.ID, rq.r_token, sb.statusCode, rq.timeStamp, rq.pinLifetime, " + "rq.deferredStartTime, rb.ID, rb.sourceSURL, rb.normalized_sourceSURL_StFN, " @@ -1725,7 +1651,7 @@ private synchronized Collection find(int[] surlsUniqueIDs, List list = new ArrayList(); - log.trace("BOL CHUNK DAO - find method: " + find.toString()); + log.trace("BOL CHUNK DAO - find method: {}", find.toString()); rs = find.executeQuery(); logWarnings(find.getWarnings()); BoLChunkDataTO chunkDataTO = null; @@ -1739,7 +1665,6 @@ private synchronized Collection find(int[] surlsUniqueIDs, chunkDataTO.setTimeStamp(rs.getTimestamp("rq.timeStamp")); chunkDataTO.setPrimaryKey(rs.getLong("rb.ID")); chunkDataTO.setFromSURL(rs.getString("rb.sourceSURL")); - // TODO MICHELE USER_SURL fill new fields chunkDataTO.setNormalizedStFN(rs .getString("rb.normalized_sourceSURL_StFN")); @@ -1756,7 +1681,7 @@ private synchronized Collection find(int[] surlsUniqueIDs, } return list; } catch (SQLException e) { - log.error("BOL CHUNK DAO: " + e); + log.error("BOL CHUNK DAO: {}", e.getMessage(), e); /* return empty Collection! */ return new ArrayList(); } finally { diff --git a/src/main/java/it/grid/storm/catalogs/BoLChunkDataTO.java b/src/main/java/it/grid/storm/catalogs/BoLChunkDataTO.java index 0d26e038..e2889297 100644 --- a/src/main/java/it/grid/storm/catalogs/BoLChunkDataTO.java +++ b/src/main/java/it/grid/storm/catalogs/BoLChunkDataTO.java @@ -43,7 +43,6 @@ public class BoLChunkDataTO { private long primaryKey = -1; // ID primary key of record in DB private String fromSURL = " "; private boolean dirOption; // initialised in constructor - // TODO MICHELE USER_SURL added new fields private String normalizedStFN = null; private Integer surlUniqueID = null; /* Database table request_Get fields END */ diff --git a/src/main/java/it/grid/storm/catalogs/BoLData.java b/src/main/java/it/grid/storm/catalogs/BoLData.java index ca2d767a..a96bd1d6 100644 --- a/src/main/java/it/grid/storm/catalogs/BoLData.java +++ b/src/main/java/it/grid/storm/catalogs/BoLData.java @@ -147,16 +147,11 @@ public void setLifeTime(long lifeTimeInSeconds) { try { lifeTime = TLifeTimeInSeconds.make(lifeTimeInSeconds, TimeUnit.SECONDS); } catch (IllegalArgumentException e) { + log.error(e.getMessage(), e); return; } this.lifeTime = lifeTime; } - @Override - protected Logger getLog() { - - return BoLData.log; - } - } diff --git a/src/main/java/it/grid/storm/catalogs/BoLPersistentChunkData.java b/src/main/java/it/grid/storm/catalogs/BoLPersistentChunkData.java index b68df3c7..651686cb 100644 --- a/src/main/java/it/grid/storm/catalogs/BoLPersistentChunkData.java +++ b/src/main/java/it/grid/storm/catalogs/BoLPersistentChunkData.java @@ -72,6 +72,7 @@ public BoLPersistentChunkData(TRequestToken requestToken, TSURL fromSURL, super(fromSURL, lifeTime, dirOption, desiredProtocols, fileSize, status, transferURL, deferredStartTime); if (requestToken == null) { + log.debug("BoLPersistentChunkData: requestToken is null!"); throw new InvalidBoLPersistentChunkDataAttributesException(requestToken, fromSURL, lifeTime, dirOption, desiredProtocols, fileSize, status, transferURL); @@ -105,12 +106,6 @@ public void setPrimaryKey(long l) { primaryKey = l; } - @Override - protected Logger getLog() { - - return BoLPersistentChunkData.log; - } - @Override public long getIdentifier() { diff --git a/src/main/java/it/grid/storm/catalogs/CopyChunkCatalog.java b/src/main/java/it/grid/storm/catalogs/CopyChunkCatalog.java index 49b1728c..d04e7e64 100644 --- a/src/main/java/it/grid/storm/catalogs/CopyChunkCatalog.java +++ b/src/main/java/it/grid/storm/catalogs/CopyChunkCatalog.java @@ -100,9 +100,6 @@ synchronized public void update(CopyPersistentChunkData cd) { to.setTargetSurlUniqueID(new Integer(cd.getDestinationSURL().uniqueId())); dao.update(to); - // TODO MICHELE SURL STORE - // SurlStatusStore.getInstance().storeSurlStatus(cd.getSURL(), - // cd.getStatus().getStatusCode()); } /** @@ -121,7 +118,7 @@ synchronized public Collection lookup( TRequestToken rt) { Collection chunkDataTOs = dao.find(rt); - log.debug("COPY CHUNK CATALOG: retrieved data " + chunkDataTOs); + log.debug("COPY CHUNK CATALOG: retrieved data {}", chunkDataTOs); return buildChunkDataList(chunkDataTOs, rt); } @@ -132,21 +129,21 @@ private Collection buildChunkDataList( CopyPersistentChunkData chunk; for (CopyChunkDataTO chunkTO : chunkDataTOs) { chunk = makeOne(chunkTO, rt); - if (chunk != null) { - list.add(chunk); - - if (!this.isComplete(chunkTO)) { - try { - dao.updateIncomplete(this.completeTO(chunkTO, chunk)); - } catch (InvalidReducedCopyChunkDataAttributesException e) { - log - .warn("PtG CHUNK CATALOG! unable to add missing informations on DB to the request: " - + e); - } - } + if (chunk == null) { + continue; + } + list.add(chunk); + if (isComplete(chunkTO)) { + continue; + } + try { + dao.updateIncomplete(completeTO(chunkTO, chunk)); + } catch (InvalidReducedCopyChunkDataAttributesException e) { + log.warn("COPY CHUNK CATALOG! unable to add missing informations on " + + "DB to the request: {}", e.getMessage()); } } - log.debug("COPY CHUNK CATALOG: returning " + list + "\n\n"); + log.debug("COPY CHUNK CATALOG: returning {}\n\n", list); return list; } @@ -157,21 +154,21 @@ private Collection buildChunkDataList( CopyPersistentChunkData chunk; for (CopyChunkDataTO chunkTO : chunkDataTOs) { chunk = makeOne(chunkTO); - if (chunk != null) { - list.add(chunk); - - if (!this.isComplete(chunkTO)) { - try { - dao.updateIncomplete(this.completeTO(chunkTO, chunk)); - } catch (InvalidReducedCopyChunkDataAttributesException e) { - log - .warn("PtG CHUNK CATALOG! unable to add missing informations on DB to the request: " - + e); - } - } + if (chunk == null) { + continue; + } + list.add(chunk); + if (isComplete(chunkTO)) { + continue; + } + try { + dao.updateIncomplete(completeTO(chunkTO, chunk)); + } catch (InvalidReducedCopyChunkDataAttributesException e) { + log.warn("COPY CHUNK CATALOG! unable to add missing informations on DB " + + "to the request: {}", e.getMessage()); } } - log.debug("COPY CHUNK CATALOG: returning " + list + "\n\n"); + log.debug("COPY CHUNK CATALOG: returning {}\n\n", list); return list; } @@ -296,9 +293,8 @@ private CopyPersistentChunkData makeOne(CopyChunkDataTO chunkDataTO, TFileStorageType fileStorageType = FileStorageTypeConverter.getInstance() .toSTORM(chunkDataTO.fileStorageType()); if (fileStorageType == TFileStorageType.EMPTY) { - log.error("\nTFileStorageType could not be " - + "translated from its String representation! String: " - + chunkDataTO.fileStorageType()); + log.error("\nTFileStorageType could not be translated from its String " + + "representation! String: {}", chunkDataTO.fileStorageType()); // fail creation of PtPChunk! fileStorageType = null; } @@ -357,7 +353,7 @@ private CopyPersistentChunkData makeOne(CopyChunkDataTO chunkDataTO, } catch (InvalidSurlRequestDataAttributesException e) { dao.signalMalformedCopyChunk(chunkDataTO); log.warn("COPY CHUNK CATALOG! Retrieved malformed Copy" - + " chunk data from persistence. Dropping chunk from request: " + rt); + + " chunk data from persistence. Dropping chunk from request: {}", rt); log.warn(e.getMessage()); log.warn(errorSb.toString()); } diff --git a/src/main/java/it/grid/storm/catalogs/CopyChunkDAO.java b/src/main/java/it/grid/storm/catalogs/CopyChunkDAO.java index 07218764..15d2e313 100644 --- a/src/main/java/it/grid/storm/catalogs/CopyChunkDAO.java +++ b/src/main/java/it/grid/storm/catalogs/CopyChunkDAO.java @@ -123,7 +123,6 @@ public synchronized void update(CopyChunkDataTO to) { } PreparedStatement updateFileReq = null; try { - // TODO MICHELE USER_SURL set new fields // ready updateFileReq... updateFileReq = con .prepareStatement("UPDATE request_queue rq JOIN (status_Copy sc, request_Copy rc) " @@ -148,7 +147,6 @@ public synchronized void update(CopyChunkDataTO to) { updateFileReq.setString(5, to.overwriteOption()); logWarnings(updateFileReq.getWarnings()); - // TODO MICHELE USER_SURL fill new fields updateFileReq.setString(6, to.normalizedSourceStFN()); logWarnings(updateFileReq.getWarnings()); @@ -168,7 +166,8 @@ public synchronized void update(CopyChunkDataTO to) { updateFileReq.executeUpdate(); logWarnings(updateFileReq.getWarnings()); } catch (SQLException e) { - log.error("COPY CHUNK DAO: Unable to complete update! " + e); + log.error("COPY CHUNK DAO: Unable to complete update! {}", + e.getMessage(), e); } finally { close(updateFileReq); } @@ -180,7 +179,6 @@ public synchronized void update(CopyChunkDataTO to) { * * @param chunkTO */ - // TODO MICHELE USER_SURL new method public synchronized void updateIncomplete(ReducedCopyChunkDataTO chunkTO) { if (!checkConnection()) { @@ -210,11 +208,12 @@ public synchronized void updateIncomplete(ReducedCopyChunkDataTO chunkTO) { stmt.setLong(5, chunkTO.primaryKey()); logWarnings(stmt.getWarnings()); - log.trace("COPY CHUNK DAO - update incomplete: " + stmt.toString()); + log.trace("COPY CHUNK DAO - update incomplete: {}", stmt.toString()); stmt.executeUpdate(); logWarnings(stmt.getWarnings()); } catch (SQLException e) { - log.error("COPY CHUNK DAO: Unable to complete update incomplete! " + e); + log.error("COPY CHUNK DAO: Unable to complete update incomplete! {}", + e.getMessage(), e); } finally { close(stmt); } @@ -254,7 +253,6 @@ public synchronized Collection find( PreparedStatement find = null; ResultSet rs = null; try { - // TODO MICHELE USER_SURL get new fields /* get chunks of the request */ str = "SELECT rq.s_token, rq.config_FileStorageTypeID, rq.config_OverwriteID, rq.fileLifetime, rc.ID, rc.sourceSURL, rc.targetSURL, rc.normalized_sourceSURL_StFN, rc.sourceSURL_uniqueID, rc.normalized_targetSURL_StFN, rc.targetSURL_uniqueID, d.isSourceADirectory, d.allLevelRecursive, d.numOfLevels " + "FROM request_queue rq JOIN (request_Copy rc, status_Copy sc) " @@ -289,7 +287,6 @@ public synchronized Collection find( chunkDataTO.setLifeTime(rs.getInt("rq.fileLifetime")); chunkDataTO.setPrimaryKey(rs.getLong("rc.ID")); chunkDataTO.setFromSURL(rs.getString("rc.sourceSURL")); - // TODO MICHELE USER_SURL fill new fields chunkDataTO.setNormalizedSourceStFN(rs .getString("rc.normalized_sourceSURL_StFN")); int uniqueID = rs.getInt("rc.sourceSURL_uniqueID"); @@ -298,7 +295,6 @@ public synchronized Collection find( } chunkDataTO.setToSURL(rs.getString("rc.targetSURL")); - // TODO MICHELE USER_SURL fill new fields chunkDataTO.setNormalizedTargetStFN(rs .getString("rc.normalized_sourceSURL_StFN")); uniqueID = rs.getInt("rc.sourceSURL_uniqueID"); @@ -310,7 +306,7 @@ public synchronized Collection find( } return list; } catch (SQLException e) { - log.error("COPY CHUNK DAO: " + e); + log.error("COPY CHUNK DAO: {}", e.getMessage(), e); /* return empty Collection! */ return new ArrayList(); } finally { @@ -332,7 +328,6 @@ public synchronized Collection find( PreparedStatement find = null; ResultSet rs = null; try { - // TODO MICHELE USER_SURL get new fields /* get chunks of the request */ str = "SELECT rq.s_token, rq.config_FileStorageTypeID, rq.config_OverwriteID, rq.fileLifetime, rc.ID, rc.sourceSURL, rc.targetSURL, rc.normalized_sourceSURL_StFN, rc.sourceSURL_uniqueID, rc.normalized_targetSURL_StFN, rc.targetSURL_uniqueID, d.isSourceADirectory, d.allLevelRecursive, d.numOfLevels " + "FROM request_queue rq JOIN (request_Copy rc, status_Copy sc) " @@ -350,7 +345,7 @@ public synchronized Collection find( find.setString(1, strToken); logWarnings(find.getWarnings()); - log.debug("COPY CHUNK DAO: find method; " + find.toString()); + log.debug("COPY CHUNK DAO: find method; {}", find.toString()); rs = find.executeQuery(); logWarnings(find.getWarnings()); @@ -366,7 +361,6 @@ public synchronized Collection find( chunkDataTO.setLifeTime(rs.getInt("rq.fileLifetime")); chunkDataTO.setPrimaryKey(rs.getLong("rc.ID")); chunkDataTO.setFromSURL(rs.getString("rc.sourceSURL")); - // TODO MICHELE USER_SURL fill new fields chunkDataTO.setNormalizedSourceStFN(rs .getString("rc.normalized_sourceSURL_StFN")); int uniqueID = rs.getInt("rc.sourceSURL_uniqueID"); @@ -375,7 +369,6 @@ public synchronized Collection find( } chunkDataTO.setToSURL(rs.getString("rc.targetSURL")); - // TODO MICHELE USER_SURL fill new fields chunkDataTO.setNormalizedTargetStFN(rs .getString("rc.normalized_sourceSURL_StFN")); uniqueID = rs.getInt("rc.sourceSURL_uniqueID"); @@ -387,7 +380,7 @@ public synchronized Collection find( } return list; } catch (SQLException e) { - log.error("COPY CHUNK DAO: " + e); + log.error("COPY CHUNK DAO: {}", e.getMessage(), e); /* return empty Collection! */ return new ArrayList(); } finally { @@ -438,9 +431,9 @@ public synchronized void signalMalformedCopyChunk(CopyChunkDataTO auxTO) { signal.executeUpdate(); logWarnings(signal.getWarnings()); } catch (SQLException e) { - log.error("CopyChunkDAO! Unable to signal in DB that the" - + "request was malformed! Request: " + auxTO.toString() - + "; Exception: " + e.toString()); + log.error("CopyChunkDAO! Unable to signal in DB that the request was " + + "malformed! Request: {}; Error: {}", auxTO.toString(), + e.getMessage(), e); } finally { close(signal); } @@ -455,8 +448,8 @@ private void close(Statement stmt) { try { stmt.close(); } catch (Exception e) { - log.error("COPY CHUNK DAO! Unable to close Statement " - + stmt.toString() + " - Exception: " + e); + log.error("COPY CHUNK DAO! Unable to close Statement {} - Error: {}", + stmt.toString(), e.getMessage(), e); } } } @@ -470,7 +463,8 @@ private void close(ResultSet rset) { try { rset.close(); } catch (Exception e) { - log.error("COPY CHUNK DAO! Unable to close ResultSet! Exception: " + e); + log.error("COPY CHUNK DAO! Unable to close ResultSet! Error: {}", + e.getMessage(), e); } } } @@ -481,9 +475,9 @@ private void close(ResultSet rset) { private void logWarnings(SQLWarning w) { if (w != null) { - log.debug("COPY CHUNK DAO: " + w.toString()); + log.debug("COPY CHUNK DAO: {}", w.toString()); while ((w = w.getNextWarning()) != null) { - log.debug("COPY CHUNK DAO: " + w.toString()); + log.debug("COPY CHUNK DAO: {}", w.toString()); } } } @@ -505,9 +499,11 @@ private boolean setUpConnection() { response = con.isValid(0); } } catch (ClassNotFoundException e) { - log.error("COPY CHUNK DAO! Exception in setUpConnection! " + e); + log.error("COPY CHUNK DAO! Exception in setUpConnection! {}", + e.getMessage(), e); } catch (SQLException e) { - log.error("COPY CHUNK DAO! Exception in setUpConnection! " + e); + log.error("COPY CHUNK DAO! Exception in setUpConnection! {}", + e.getMessage(), e); } return response; } @@ -539,8 +535,8 @@ private void takeDownConnection() { try { con.close(); } catch (SQLException e) { - log.error("COPY CHUNK DAO! Exception in takeDownConnection method: " - + e); + log.error("COPY CHUNK DAO! Exception in takeDownConnection method: {}", + e.getMessage(), e); } } } @@ -623,22 +619,19 @@ public synchronized void doUpdateStatusOnMatchingStatus( .setInt(2, StatusCodeConverter.getInstance().toDB(expectedStatusCode)); logWarnings(stmt.getWarnings()); - log.trace("COPY CHUNK DAO - updateStatusOnMatchingStatus: " - + stmt.toString()); + log.trace("COPY CHUNK DAO - updateStatusOnMatchingStatus: {}", stmt.toString()); int count = stmt.executeUpdate(); logWarnings(stmt.getWarnings()); if (count == 0) { - log.trace("COPY CHUNK DAO! No chunk of COPY request was" - + " updated from " + expectedStatusCode + " to " + newStatusCode - + "."); + log.trace("COPY CHUNK DAO! No chunk of COPY request was updated " + + "from {} to {}.", expectedStatusCode, newStatusCode); } else { - log.debug("COPY CHUNK DAO! " + count - + " chunks of COPY requests were updated from " + expectedStatusCode - + " to " + newStatusCode + "."); + log.debug("COPY CHUNK DAO! {} chunks of COPY requests were updated " + + "from {} to {}.", count, expectedStatusCode, newStatusCode); } } catch (SQLException e) { - log.error("COPY CHUNK DAO! Unable to updated from " + expectedStatusCode - + " to " + newStatusCode + " !" + e); + log.error("COPY CHUNK DAO! Unable to updated from {} to {}! {}", + expectedStatusCode, newStatusCode, e.getMessage(), e); } finally { close(stmt); } @@ -740,7 +733,7 @@ private synchronized Collection find(int[] surlsUniqueIDs, List list = new ArrayList(); - log.trace("COPY CHUNK DAO - find method: " + find.toString()); + log.trace("COPY CHUNK DAO - find method: {}", find.toString()); rs = find.executeQuery(); logWarnings(find.getWarnings()); CopyChunkDataTO chunkDataTO = null; @@ -755,7 +748,6 @@ private synchronized Collection find(int[] surlsUniqueIDs, chunkDataTO.setLifeTime(rs.getInt("rq.fileLifetime")); chunkDataTO.setPrimaryKey(rs.getLong("rc.ID")); chunkDataTO.setFromSURL(rs.getString("rc.sourceSURL")); - // TODO MICHELE USER_SURL fill new fields chunkDataTO.setNormalizedSourceStFN(rs .getString("rc.normalized_sourceSURL_StFN")); int uniqueID = rs.getInt("rc.sourceSURL_uniqueID"); @@ -764,7 +756,6 @@ private synchronized Collection find(int[] surlsUniqueIDs, } chunkDataTO.setToSURL(rs.getString("rc.targetSURL")); - // TODO MICHELE USER_SURL fill new fields chunkDataTO.setNormalizedTargetStFN(rs .getString("rc.normalized_sourceSURL_StFN")); uniqueID = rs.getInt("rc.sourceSURL_uniqueID"); @@ -775,7 +766,7 @@ private synchronized Collection find(int[] surlsUniqueIDs, } return list; } catch (SQLException e) { - log.error("COPY CHUNK DAO: " + e); + log.error("COPY CHUNK DAO: {}", e.getMessage(), e); /* return empty Collection! */ return new ArrayList(); } finally { diff --git a/src/main/java/it/grid/storm/catalogs/CopyChunkDataTO.java b/src/main/java/it/grid/storm/catalogs/CopyChunkDataTO.java index 802dfaba..03a02ef6 100644 --- a/src/main/java/it/grid/storm/catalogs/CopyChunkDataTO.java +++ b/src/main/java/it/grid/storm/catalogs/CopyChunkDataTO.java @@ -41,7 +41,6 @@ public class CopyChunkDataTO { private long primaryKey = -1; // ID primary key of record in DB private String fromSURL = " "; private String toSURL = " "; - // TODO MICHELE USER_SURL added new fields private String normalizedSourceStFN = null; private Integer sourceSurlUniqueID = null; private String normalizedTargetStFN = null; diff --git a/src/main/java/it/grid/storm/catalogs/CopyData.java b/src/main/java/it/grid/storm/catalogs/CopyData.java index 80a78e13..5d1437fc 100644 --- a/src/main/java/it/grid/storm/catalogs/CopyData.java +++ b/src/main/java/it/grid/storm/catalogs/CopyData.java @@ -153,9 +153,4 @@ public void changeStatusSRM_FATAL_INTERNAL_ERROR(String explanation) { setStatus(TStatusCode.SRM_FATAL_INTERNAL_ERROR, explanation); } - @Override - protected Logger getLog() { - - return CopyData.log; - } } diff --git a/src/main/java/it/grid/storm/catalogs/CopyPersistentChunkData.java b/src/main/java/it/grid/storm/catalogs/CopyPersistentChunkData.java index 49365371..c9c1185a 100644 --- a/src/main/java/it/grid/storm/catalogs/CopyPersistentChunkData.java +++ b/src/main/java/it/grid/storm/catalogs/CopyPersistentChunkData.java @@ -68,6 +68,7 @@ public CopyPersistentChunkData(TRequestToken requestToken, TSURL fromSURL, super(fromSURL, destinationSURL, lifetime, fileStorageType, spaceToken, overwriteOption, status); if (requestToken == null) { + log.debug("CopyPersistentChunkData: requestToken is null!"); throw new InvalidCopyPersistentChunkDataAttributesException(requestToken, fromSURL, destinationSURL, lifetime, fileStorageType, spaceToken, overwriteOption, status); @@ -106,9 +107,4 @@ public long getIdentifier() { return getPrimaryKey(); } - @Override - protected Logger getLog() { - - return CopyPersistentChunkData.log; - } } diff --git a/src/main/java/it/grid/storm/catalogs/InvalidCopyChunkDataAttributesException.java b/src/main/java/it/grid/storm/catalogs/InvalidCopyChunkDataAttributesException.java index ebba2a06..167c4873 100644 --- a/src/main/java/it/grid/storm/catalogs/InvalidCopyChunkDataAttributesException.java +++ b/src/main/java/it/grid/storm/catalogs/InvalidCopyChunkDataAttributesException.java @@ -37,6 +37,8 @@ */ public class InvalidCopyChunkDataAttributesException extends Exception { + private static final long serialVersionUID = 6786154038995023512L; + // booleans that indicate whether the corresponding variable is null private boolean nullRequestToken; private boolean nullFromSURL; diff --git a/src/main/java/it/grid/storm/catalogs/InvalidReducedBoLChunkDataAttributesException.java b/src/main/java/it/grid/storm/catalogs/InvalidReducedBoLChunkDataAttributesException.java index a3f4e96b..448ef835 100644 --- a/src/main/java/it/grid/storm/catalogs/InvalidReducedBoLChunkDataAttributesException.java +++ b/src/main/java/it/grid/storm/catalogs/InvalidReducedBoLChunkDataAttributesException.java @@ -30,6 +30,8 @@ */ public class InvalidReducedBoLChunkDataAttributesException extends Exception { + private static final long serialVersionUID = -8145580437017768234L; + // booleans that indicate whether the corresponding variable is null private boolean nullFromSURL; private boolean nullStatus; diff --git a/src/main/java/it/grid/storm/catalogs/InvalidReducedPtGChunkDataAttributesException.java b/src/main/java/it/grid/storm/catalogs/InvalidReducedPtGChunkDataAttributesException.java index 920389c9..06be96cf 100644 --- a/src/main/java/it/grid/storm/catalogs/InvalidReducedPtGChunkDataAttributesException.java +++ b/src/main/java/it/grid/storm/catalogs/InvalidReducedPtGChunkDataAttributesException.java @@ -30,6 +30,8 @@ */ public class InvalidReducedPtGChunkDataAttributesException extends Exception { + private static final long serialVersionUID = -7943458526292568164L; + // booleans that indicate whether the corresponding variable is null private boolean nullFromSURL; private boolean nullStatus; diff --git a/src/main/java/it/grid/storm/catalogs/InvalidReducedPtPChunkDataAttributesException.java b/src/main/java/it/grid/storm/catalogs/InvalidReducedPtPChunkDataAttributesException.java index f4047d5d..d3d54b8c 100644 --- a/src/main/java/it/grid/storm/catalogs/InvalidReducedPtPChunkDataAttributesException.java +++ b/src/main/java/it/grid/storm/catalogs/InvalidReducedPtPChunkDataAttributesException.java @@ -32,6 +32,8 @@ */ public class InvalidReducedPtPChunkDataAttributesException extends Exception { + private static final long serialVersionUID = 4945626188325362854L; + // booleans that indicate whether the corresponding variable is null private boolean nullToSURL; private boolean nullStatus; diff --git a/src/main/java/it/grid/storm/catalogs/InvalidRequestSummaryDataAttributesException.java b/src/main/java/it/grid/storm/catalogs/InvalidRequestSummaryDataAttributesException.java index c12c3e4a..ceb1650b 100644 --- a/src/main/java/it/grid/storm/catalogs/InvalidRequestSummaryDataAttributesException.java +++ b/src/main/java/it/grid/storm/catalogs/InvalidRequestSummaryDataAttributesException.java @@ -32,6 +32,8 @@ */ public class InvalidRequestSummaryDataAttributesException extends Exception { + private static final long serialVersionUID = -7729349713696058669L; + // booleans true if the corresponding variablesare null or negative private boolean nullRequestType = true; private boolean nullRequestToken = true; diff --git a/src/main/java/it/grid/storm/catalogs/InvalidRetrievedDataException.java b/src/main/java/it/grid/storm/catalogs/InvalidRetrievedDataException.java index 315da618..5a252b65 100644 --- a/src/main/java/it/grid/storm/catalogs/InvalidRetrievedDataException.java +++ b/src/main/java/it/grid/storm/catalogs/InvalidRetrievedDataException.java @@ -28,6 +28,8 @@ */ public class InvalidRetrievedDataException extends Exception { + private static final long serialVersionUID = -3645913441787012438L; + private String requestToken; private String requestType; private int totalFilesInThisRequest; diff --git a/src/main/java/it/grid/storm/catalogs/InvalidSpaceDataAttributesException.java b/src/main/java/it/grid/storm/catalogs/InvalidSpaceDataAttributesException.java index 6c7eeb50..dd0e2ff9 100644 --- a/src/main/java/it/grid/storm/catalogs/InvalidSpaceDataAttributesException.java +++ b/src/main/java/it/grid/storm/catalogs/InvalidSpaceDataAttributesException.java @@ -32,11 +32,10 @@ public class InvalidSpaceDataAttributesException extends Exception { + private static final long serialVersionUID = -5317879266114702669L; + private boolean nullAuth = true; - private boolean nullType = true; private boolean nullToken = true; - private boolean negSpaceDes = true; - private boolean negSpaceGuar = true; public InvalidSpaceDataAttributesException(GridUserInterface guser) { diff --git a/src/main/java/it/grid/storm/catalogs/MalformedGridUserException.java b/src/main/java/it/grid/storm/catalogs/MalformedGridUserException.java index 80206bd5..2a952b3a 100644 --- a/src/main/java/it/grid/storm/catalogs/MalformedGridUserException.java +++ b/src/main/java/it/grid/storm/catalogs/MalformedGridUserException.java @@ -27,6 +27,8 @@ */ public class MalformedGridUserException extends Exception { + private static final long serialVersionUID = 5607710323595609428L; + public String toString() { return "MalformedGridUserException"; diff --git a/src/main/java/it/grid/storm/catalogs/MultipleDataEntriesException.java b/src/main/java/it/grid/storm/catalogs/MultipleDataEntriesException.java index dd631af5..134b13ff 100644 --- a/src/main/java/it/grid/storm/catalogs/MultipleDataEntriesException.java +++ b/src/main/java/it/grid/storm/catalogs/MultipleDataEntriesException.java @@ -29,6 +29,8 @@ */ public class MultipleDataEntriesException extends Exception { + private static final long serialVersionUID = 427636739469695868L; + private TRequestToken requestToken; /** diff --git a/src/main/java/it/grid/storm/catalogs/NoDataFoundException.java b/src/main/java/it/grid/storm/catalogs/NoDataFoundException.java index 42fd85a1..bc44544a 100644 --- a/src/main/java/it/grid/storm/catalogs/NoDataFoundException.java +++ b/src/main/java/it/grid/storm/catalogs/NoDataFoundException.java @@ -29,6 +29,8 @@ */ public class NoDataFoundException extends Exception { + private static final long serialVersionUID = -718255813130266566L; + private TRequestToken requestToken; /** diff --git a/src/main/java/it/grid/storm/catalogs/PtGChunkCatalog.java b/src/main/java/it/grid/storm/catalogs/PtGChunkCatalog.java index 3fcec5a0..4404656f 100644 --- a/src/main/java/it/grid/storm/catalogs/PtGChunkCatalog.java +++ b/src/main/java/it/grid/storm/catalogs/PtGChunkCatalog.java @@ -138,9 +138,6 @@ synchronized public void update(PtGPersistentChunkData chunkData) { } dao.update(to); - // TODO MICHELE SURL STORE - // SurlStatusStore.getInstance().storeSurlStatus(cd.getSURL(), - // cd.getStatus().getStatusCode()); } /** @@ -160,44 +157,35 @@ synchronized public PtGPersistentChunkData refreshStatus( log.debug("PtG CHUNK CATALOG: retrieved data " + chunkDataTO); if (chunkDataTO == null) { - log - .warn("PtG CHUNK CATALOG! Empty TO found in persistence for specified request: " - + inputChunk.getPrimaryKey()); - } else { - /* - * In this first version the only field updated is the Status. Once - * updated, the new status is rewritten into the input ChunkData - */ - - // status - TReturnStatus status = null; - TStatusCode code = StatusCodeConverter.getInstance().toSTORM( - chunkDataTO.status()); - if (code != TStatusCode.EMPTY) { - try { - status = new TReturnStatus(code, chunkDataTO.errString()); - } catch (InvalidTReturnStatusAttributeException e) { - log - .error("PtGChunk : Unable to build the Return Status from the String '" - + chunkDataTO.errString() - + " and code '" - + chunkDataTO.status() - + "''." + e); - } - } - inputChunk.setStatus(status); - // TODO MICHELE SURL STORE - // SurlStatusStore.getInstance().storeSurlStatus(inputChunk.getSURL(), - // status.getStatusCode()); - TTURL turl = null; + log.warn("PtG CHUNK CATALOG! Empty TO found in persistence for specified " + + "request: {}", inputChunk.getPrimaryKey()); + return inputChunk; + } + + /* + * In this first version the only field updated is the Status. Once + * updated, the new status is rewritten into the input ChunkData + */ + + // status + TReturnStatus status = null; + TStatusCode code = StatusCodeConverter.getInstance().toSTORM(chunkDataTO.status()); + if (code != TStatusCode.EMPTY) { try { - turl = TTURL.makeFromString(chunkDataTO.turl()); - } catch (InvalidTTURLAttributesException e) { - log.info("PtGChunkCatalog (FALSE-ERROR-in-abort-refresh-status?):" - + " built a TURL with protocol NULL (retrieved from the DB..)"); + status = new TReturnStatus(code, chunkDataTO.errString()); + } catch (InvalidTReturnStatusAttributeException e) { + log.error("PtGChunk : Unable to build the Return Status from the String '{}' and code '{}'. {}", chunkDataTO.errString(), chunkDataTO.status(), e.getMessage()); } - inputChunk.setTransferURL(turl); } + inputChunk.setStatus(status); + TTURL turl = null; + try { + turl = TTURL.makeFromString(chunkDataTO.turl()); + } catch (InvalidTTURLAttributesException e) { + log.info("PtGChunkCatalog (FALSE-ERROR-in-abort-refresh-status?):" + + " built a TURL with protocol NULL (retrieved from the DB..)"); + } + inputChunk.setTransferURL(turl); return inputChunk; } @@ -219,31 +207,25 @@ synchronized public Collection lookup(TRequestToken rt) log.debug("PtG CHUNK CATALOG: retrieved data " + chunkTOs); ArrayList list = new ArrayList(); if (chunkTOs.isEmpty()) { - log - .warn("PtG CHUNK CATALOG! No chunks found in persistence for specified request: " - + rt); - } else { - // TODO MICHELE USER_SURL here I can update all requests that has not the - // new fields set alltogether in a bunch, adding a method to the DAO for - // this purpose - PtGPersistentChunkData chunk; - for (PtGChunkDataTO chunkTO : chunkTOs) { - chunk = makeOne(chunkTO, rt); - if (chunk != null) { - list.add(chunk); - // TODO MICHELE SURL STORE - // SurlStatusStore.getInstance().storeSurlStatus(chunk.getSURL(), - // chunk.getStatus().getStatusCode()); - if (!this.isComplete(chunkTO)) { - try { - dao.updateIncomplete(this.completeTO(chunkTO, chunk)); - } catch (InvalidReducedPtGChunkDataAttributesException e) { - log - .warn("PtG CHUNK CATALOG! unable to add missing informations on DB to the request: " - + e); - } - } - } + log.warn("PtG CHUNK CATALOG! No chunks found in persistence for " + + "specified request: {}", rt); + return list; + } + PtGPersistentChunkData chunk; + for (PtGChunkDataTO chunkTO : chunkTOs) { + chunk = makeOne(chunkTO, rt); + if (chunk == null) { + continue; + } + list.add(chunk); + if (isComplete(chunkTO)) { + continue; + } + try { + dao.updateIncomplete(this.completeTO(chunkTO, chunk)); + } catch (InvalidReducedPtGChunkDataAttributesException e) { + log.warn("PtG CHUNK CATALOG! unable to add missing informations on DB " + + "to the request: {}", e.getMessage()); } } log.debug("PtG CHUNK CATALOG: returning " + list); @@ -282,7 +264,7 @@ private PtGPersistentChunkData makeOne(PtGChunkDataTO chunkDataTO, long max = Configuration.getInstance().getPinLifetimeMaximum(); if (pinLifeTime > max) { log.warn("PinLifeTime is greater than the max value allowed." - + " Drop the value to the max = " + max + " seconds"); + + " Drop the value to the max = {} seconds", max); pinLifeTime = max; } lifeTime = TLifeTimeInSeconds.make((pinLifeTime), TimeUnit.SECONDS); @@ -342,9 +324,8 @@ private PtGPersistentChunkData makeOne(PtGChunkDataTO chunkDataTO, } } catch (IllegalArgumentException e) { - log - .error("Unexpected error on voms grid user creation. Contact StoRM Support : IllegalArgumentException " - + e.getMessage()); + log.error("Unexpected error on voms grid user creation." + + " IllegalArgumentException: {}", e.getMessage(), e); } // transferURL /* @@ -361,10 +342,8 @@ private PtGPersistentChunkData makeOne(PtGChunkDataTO chunkDataTO, aux.setPrimaryKey(chunkDataTO.primaryKey()); } catch (InvalidSurlRequestDataAttributesException e) { dao.signalMalformedPtGChunk(chunkDataTO); - log - .warn("PtG CHUNK CATALOG! Retrieved malformed" - + " PtG chunk data from persistence. Dropping chunk from request " - + rt); + log.warn("PtG CHUNK CATALOG! Retrieved malformed PtG chunk data from " + + "persistence. Dropping chunk from request {}", rt); log.warn(e.getMessage(), e); log.warn(errorSb.toString()); } @@ -486,26 +465,23 @@ synchronized public Collection lookupReducedPtGChunkData( Collection reducedChunkDataTOs = dao.findReduced(rt .getValue()); - log.debug("PtG CHUNK CATALOG: retrieved data " + reducedChunkDataTOs); + log.debug("PtG CHUNK CATALOG: retrieved data {}", reducedChunkDataTOs); ArrayList list = new ArrayList(); if (reducedChunkDataTOs.isEmpty()) { - log.debug("PtG CHUNK CATALOG! No chunks found in persistence for " + rt); + log.debug("PtG CHUNK CATALOG! No chunks found in persistence for {}", rt); } else { ReducedPtGChunkData reducedChunkData = null; for (ReducedPtGChunkDataTO reducedChunkDataTO : reducedChunkDataTOs) { reducedChunkData = makeOneReduced(reducedChunkDataTO); if (reducedChunkData != null) { list.add(reducedChunkData); - // TODO MICHELE SURL STORE - // SurlStatusStore.getInstance().storeSurlStatus(reducedChunkData.fromSURL(), - // reducedChunkData.status().getStatusCode()); if (!this.isComplete(reducedChunkDataTO)) { this.completeTO(reducedChunkDataTO, reducedChunkData); dao.updateIncomplete(reducedChunkDataTO); } } } - log.debug("PtG CHUNK CATALOG: returning " + list); + log.debug("PtG CHUNK CATALOG: returning {}", list); } return list; } @@ -523,7 +499,7 @@ public Collection lookupReducedPtGChunkData( } Collection chunkDataTOCollection = dao.findReduced( requestToken, surlsUniqueIDs, surlsArray); - log.debug("PtG CHUNK CATALOG: retrieved data " + chunkDataTOCollection); + log.debug("PtG CHUNK CATALOG: retrieved data {}", chunkDataTOCollection); return buildReducedChunkDataList(chunkDataTOCollection); } @@ -551,7 +527,7 @@ private Collection lookupPtGChunkData( } Collection chunkDataTOCollection = dao.find(surlsUniqueIDs, surlsArray, user.getDn()); - log.debug("PtG CHUNK CATALOG: retrieved data " + chunkDataTOCollection); + log.debug("PtG CHUNK CATALOG: retrieved data {}", chunkDataTOCollection); return buildChunkDataList(chunkDataTOCollection); } @@ -567,7 +543,7 @@ public Collection lookupPtGChunkData(List surls) } Collection chunkDataTOCollection = dao.find(surlsUniqueIDs, surlsArray); - log.debug("PtG CHUNK CATALOG: retrieved data " + chunkDataTOCollection); + log.debug("PtG CHUNK CATALOG: retrieved data {}", chunkDataTOCollection); return buildChunkDataList(chunkDataTOCollection); } @@ -575,26 +551,21 @@ private Collection buildChunkDataList( Collection chunkDataTOCollection) { ArrayList list = new ArrayList(); - // TODO MICHELE USER_SURL here I can update all requests that has not the - // new fields set alltogether - // in a bunch, adding a method to the DAO for this purpose PtGPersistentChunkData chunk; for (PtGChunkDataTO chunkTO : chunkDataTOCollection) { chunk = makeOne(chunkTO); - if (chunk != null) { - list.add(chunk); - // TODO MICHELE SURL STORE - // SurlStatusStore.getInstance().storeSurlStatus(chunk.getSURL(), - // chunk.getStatus().getStatusCode()); - if (!this.isComplete(chunkTO)) { - try { - dao.updateIncomplete(this.completeTO(chunkTO, chunk)); - } catch (InvalidReducedPtGChunkDataAttributesException e) { - log - .warn("PtG CHUNK CATALOG! unable to add missing informations on DB to the request: " - + e); - } - } + if (chunk == null) { + continue; + } + list.add(chunk); + if (isComplete(chunkTO)) { + continue; + } + try { + dao.updateIncomplete(this.completeTO(chunkTO, chunk)); + } catch (InvalidReducedPtGChunkDataAttributesException e) { + log.warn("PtG CHUNK CATALOG! unable to add missing informations on " + + "DB to the request: ", e.getMessage()); } } return list; @@ -635,38 +606,8 @@ synchronized public Collection lookupReducedPtGChunkData( } Collection chunkDataTOCollection = dao.findReduced( gu.getDn(), surlsUniqueIDs, surls); - log.debug("PtG CHUNK CATALOG: retrieved data " + chunkDataTOCollection); + log.debug("PtG CHUNK CATALOG: retrieved data {}", chunkDataTOCollection); return buildReducedChunkDataList(chunkDataTOCollection); - // ArrayList list = new ArrayList(); - // if(chunkDataTOCollection.isEmpty()) - // { - // log.debug("PtG CHUNK CATALOG! No chunks found in persistence for " + gu + - // " " - // + chunkDataTOCollection); - // } - // else - // { - // ReducedPtGChunkData reducedChunkData; - // for(ReducedPtGChunkDataTO reducedChunkDataTO : chunkDataTOCollection) - // { - // reducedChunkData = makeOneReduced(reducedChunkDataTO); - // if(reducedChunkData != null) - // { - // list.add(reducedChunkData); - // // TODO MICHELE SURL STORE - // // - // SurlStatusStore.getInstance().storeSurlStatus(reducedChunkData.fromSURL(), - // reducedChunkData.status().getStatusCode()); - // if(!this.isComplete(reducedChunkDataTO)) - // { - // this.completeTO(reducedChunkDataTO, reducedChunkData); - // dao.updateIncomplete(reducedChunkDataTO); - // } - // } - // } - // log.debug("PtG CHUNK CATALOG: returning " + list); - // } - // return list; } private Collection buildReducedChunkDataList( @@ -678,16 +619,13 @@ private Collection buildReducedChunkDataList( reducedChunkData = makeOneReduced(reducedChunkDataTO); if (reducedChunkData != null) { list.add(reducedChunkData); - // TODO MICHELE SURL STORE - // SurlStatusStore.getInstance().storeSurlStatus(reducedChunkData.fromSURL(), - // reducedChunkData.status().getStatusCode()); - if (!this.isComplete(reducedChunkDataTO)) { - this.completeTO(reducedChunkDataTO, reducedChunkData); + if (!isComplete(reducedChunkDataTO)) { + completeTO(reducedChunkDataTO, reducedChunkData); dao.updateIncomplete(reducedChunkDataTO); } } } - log.debug("PtG CHUNK CATALOG: returning " + list); + log.debug("PtG CHUNK CATALOG: returning {}",list); return list; } @@ -786,9 +724,6 @@ synchronized public void addChild(PtGPersistentChunkData chunkData) { } /* add the entry and update the Primary Key field! */ dao.addChild(to); - // TODO MICHELE SURL STORE - // SurlStatusStore.getInstance().storeSurlStatus(chunkData.getSURL(), - // chunkData.getStatus().getStatusCode()); /* set the assigned PrimaryKey! */ chunkData.setPrimaryKey(to.primaryKey()); } @@ -838,9 +773,6 @@ synchronized public void add(PtGPersistentChunkData chunkData, dao.addNew(to, gu.getDn()); // add the entry and update the Primary Key // field! - // TODO MICHELE SURL STORE - // SurlStatusStore.getInstance().storeSurlStatus(chunkData.getSURL(), - // chunkData.getStatus().getStatusCode()); chunkData.setPrimaryKey(to.primaryKey()); // set the assigned PrimaryKey! } @@ -853,9 +785,7 @@ synchronized public void add(PtGPersistentChunkData chunkData, synchronized public boolean isSRM_FILE_PINNED(TSURL surl) { return (dao.numberInSRM_FILE_PINNED(surl.uniqueId()) > 0); - // TODO MICHELE SURL STORE - // return - // TStatusCode.SRM_FILE_PINNED.equals(SurlStatusStore.getInstance().getSurlStatus(surl)); + } /** @@ -882,44 +812,12 @@ synchronized public void transitSRM_FILE_PINNEDtoSRM_RELEASED( dao.transitSRM_FILE_PINNEDtoSRM_RELEASED(primaryKeys, token); for (ReducedPtGChunkData chunkData : chunks) { if (chunkData != null) { - // TODO MICHELE SURL STORE - // SurlStatusStore.getInstance().storeSurlStatus(chunkData.fromSURL(), - // chunkData.status().getStatusCode()); primaryKeys[index] = chunkData.primaryKey(); index++; } } } - /** - * This method is intended to be used by srmRm to transit all PtG chunks on - * the given SURL which are in the SRM_FILE_PINNED state, to SRM_ABORTED. The - * supplied String will be used as explanation in those chunks return status. - * The global status of the request is _not_ changed. - * - * The TURL of those requests will automatically be set to empty. Notice that - * both removeAllJit(SURL) and removeVolatile(SURL) are automatically invoked - * on PinnedFilesCatalog, to remove any entry and corresponding physical ACLs. - * - * Beware, that the chunks may be part of requests that have finished, or that - * still have not finished because other chunks are being processed. - */ - // synchronized public void transitSRM_FILE_PINNEDtoSRM_ABORTED(TSURL - // surl,String explanation) { - // /* Actually (BE 1.5.4-0) not used*/ - // if(explanation == null) - // { - // explanation = ""; - // } - // dao.transitSRM_FILE_PINNEDtoSRM_ABORTED(surl.uniqueId(), surl.rawSurl(), - // explanation); - // // TODO MICHELE SURL STORE - // // - // SurlStatusStore.getInstance().storeSurlStatus(surl,TStatusCode.SRM_ABORTED); - // //PinnedFilesCatalog.getInstance().removeAllJit(surl); - // //PinnedfilesCatalog.getInstance().removeVolatile(surl); - // } - /** * Method used to force transition to SRM_RELEASED from SRM_FILE_PINNED, of * all PtG Requests whose pinLifetime has expired and the state still has not @@ -928,12 +826,6 @@ synchronized public void transitSRM_FILE_PINNEDtoSRM_RELEASED( synchronized public void transitExpiredSRM_FILE_PINNED() { List expiredSurls = dao.transitExpiredSRM_FILE_PINNED(); - // TODO MICHELE SURL STORE - // for (TSURL surl : expiredSurls) - // { - // SurlStatusStore.getInstance().storeSurlStatus(surl, - // TStatusCode.SRM_RELEASED); - // } } public void updateStatus(TRequestToken requestToken, TSURL surl, diff --git a/src/main/java/it/grid/storm/catalogs/PtGChunkDAO.java b/src/main/java/it/grid/storm/catalogs/PtGChunkDAO.java index 5c6cb016..0f82a9b3 100644 --- a/src/main/java/it/grid/storm/catalogs/PtGChunkDAO.java +++ b/src/main/java/it/grid/storm/catalogs/PtGChunkDAO.java @@ -164,7 +164,7 @@ public synchronized void addChild(PtGChunkDataTO to) { id.setString(1, to.requestToken()); logWarnings(id.getWarnings()); - log.debug("PTG CHUNK DAO: addChild; " + id.toString()); + log.debug("PTG CHUNK DAO: addChild; {}", id.toString()); rsid = id.executeQuery(); logWarnings(id.getWarnings()); @@ -181,24 +181,16 @@ public synchronized void addChild(PtGChunkDataTO to) { // update primary key reading the generated key to.setPrimaryKey(id_s); } catch (SQLException e) { - log.error("PTG CHUNK DAO: unable to complete addChild! PtGChunkDataTO: " - + to + "; exception received:" + e); + log.error("PTG CHUNK DAO: unable to complete addChild! " + + "PtGChunkDataTO: {}; error: {}", to, e.getMessage(), e); rollback(con); } catch (Exception e) { - log.error("PTG CHUNK DAO: unable to complete addChild! PtGChunkDataTO: " - + to + "; exception received:" + e); + log.error("PTG CHUNK DAO: unable to complete addChild! " + + "PtGChunkDataTO: {}; error: {}", to, e.getMessage(), e); rollback(con); } finally { close(rsid); close(id); - // TODO MICHELE IMPORTANT test if the close done in the called method - // doesn't causes troubles - // close(rsdo); - // close(addDirOption); - // close(rsg); - // close(addGet); - // close(rs); - // close(addChild); } } @@ -210,7 +202,6 @@ public synchronized void addChild(PtGChunkDataTO to) { * The supplied PtGChunkData is used to fill in all the DB tables where file * specific info gets recorded: it _adds_ a new request! */ - // TODO MICHELE USER_SURL refactored public synchronized void addNew(PtGChunkDataTO to, String client_dn) { if (!checkConnection()) { @@ -262,7 +253,7 @@ public synchronized void addNew(PtGChunkDataTO to, String client_dn) { addNew.setTimestamp(8, new Timestamp(new Date().getTime())); logWarnings(addNew.getWarnings()); - log.trace("PTG CHUNK DAO: addNew; " + addNew.toString()); + log.trace("PTG CHUNK DAO: addNew; {}", addNew.toString()); addNew.execute(); logWarnings(addNew.getWarnings()); @@ -280,7 +271,7 @@ public synchronized void addNew(PtGChunkDataTO to, String client_dn) { addProtocols.setString(2, i.next()); logWarnings(addProtocols.getWarnings()); - log.trace("PTG CHUNK DAO: addNew; " + addProtocols.toString()); + log.trace("PTG CHUNK DAO: addNew; {}", addProtocols.toString()); addProtocols.execute(); logWarnings(addProtocols.getWarnings()); } @@ -297,26 +288,17 @@ public synchronized void addNew(PtGChunkDataTO to, String client_dn) { // update primary key reading the generated key to.setPrimaryKey(id_s); } catch (SQLException e) { - log - .error("PTG CHUNK DAO: Rolling back! Unable to complete addNew! PtGChunkDataTO: " - + to + "; exception received:" + e); + log.error("PTG CHUNK DAO: Rolling back! Unable to complete addNew! " + + "PtGChunkDataTO: {}; error: {}", to, e.getMessage(), e); rollback(con); } catch (Exception e) { - log.error("PTG CHUNK DAO: unable to complete addNew! PtGChunkDataTO: " - + to + "; exception received:" + e); + log.error("PTG CHUNK DAO: unable to complete addNew! " + + "PtGChunkDataTO: {}; error: {}", to, e.getMessage(), e); rollback(con); } finally { close(rs_new); - // TODO MICHELE IMPORTANT test if the close done in the called method - // doesn't causes troubles - // close(rs_do); - // close(rs_g); - // close(rs_s); close(addNew); close(addProtocols); - // close(addDirOption); - // close(addGet); - // close(addChild); } } @@ -359,7 +341,7 @@ private synchronized int fillPtGTables(PtGChunkDataTO to, int requestQueueID) addDirOption.setInt(3, to.numLevel()); logWarnings(addDirOption.getWarnings()); - log.trace("PTG CHUNK DAO: addNew; " + addDirOption.toString()); + log.trace("PTG CHUNK DAO: addNew; {}", addDirOption.toString()); addDirOption.execute(); logWarnings(addDirOption.getWarnings()); @@ -379,14 +361,13 @@ private synchronized int fillPtGTables(PtGChunkDataTO to, int requestQueueID) addGet.setString(3, to.fromSURL()); logWarnings(addGet.getWarnings()); - // TODO MICHELE USER_SURL set new fields addGet.setString(4, to.normalizedStFN()); logWarnings(addGet.getWarnings()); addGet.setInt(5, to.surlUniqueID()); logWarnings(addGet.getWarnings()); - log.trace("PTG CHUNK DAO: addNew; " + addGet.toString()); + log.trace("PTG CHUNK DAO: addNew; {}", addGet.toString()); addGet.execute(); logWarnings(addGet.getWarnings()); @@ -406,12 +387,10 @@ private synchronized int fillPtGTables(PtGChunkDataTO to, int requestQueueID) addChild.setString(3, to.errString()); logWarnings(addChild.getWarnings()); - log.trace("PTG CHUNK DAO: addNew; " + addChild.toString()); + log.trace("PTG CHUNK DAO: addNew; {}", addChild.toString()); addChild.execute(); logWarnings(addChild.getWarnings()); - // rs_s = addChild.getGeneratedKeys(); - // return extractID(rs_s); return id_g; } finally { close(rs_do); @@ -441,7 +420,6 @@ public synchronized void update(PtGChunkDataTO to) { } PreparedStatement updateFileReq = null; try { - // TODO MICHELE USER_SURL set new fields // ready updateFileReq... updateFileReq = con .prepareStatement("UPDATE request_queue rq JOIN (status_Get sg, request_Get rg) ON (rq.ID=rg.request_queueID AND sg.request_GetID=rg.ID) " @@ -464,7 +442,6 @@ public synchronized void update(PtGChunkDataTO to) { updateFileReq.setInt(5, to.lifeTime()); logWarnings(updateFileReq.getWarnings()); - // TODO MICHELE USER_SURL fill new fields updateFileReq.setString(6, to.normalizedStFN()); logWarnings(updateFileReq.getWarnings()); @@ -474,11 +451,12 @@ public synchronized void update(PtGChunkDataTO to) { updateFileReq.setLong(8, to.primaryKey()); logWarnings(updateFileReq.getWarnings()); // execute update - log.trace("PTG CHUNK DAO: update method; " + updateFileReq.toString()); + log.trace("PTG CHUNK DAO: update method; {}", updateFileReq.toString()); updateFileReq.executeUpdate(); logWarnings(updateFileReq.getWarnings()); } catch (SQLException e) { - log.error("PtG CHUNK DAO: Unable to complete update! " + e); + log.error("PtG CHUNK DAO: Unable to complete update! {}", + e.getMessage(), e); } finally { close(updateFileReq); } @@ -490,7 +468,6 @@ public synchronized void update(PtGChunkDataTO to) { * * @param chunkTO */ - // TODO MICHELE USER_SURL new method public synchronized void updateIncomplete(ReducedPtGChunkDataTO chunkTO) { if (!checkConnection()) { @@ -514,11 +491,12 @@ public synchronized void updateIncomplete(ReducedPtGChunkDataTO chunkTO) { stmt.setLong(3, chunkTO.primaryKey()); logWarnings(stmt.getWarnings()); - log.trace("PtG CHUNK DAO - update incomplete: " + stmt.toString()); + log.trace("PtG CHUNK DAO - update incomplete: {}", stmt.toString()); stmt.executeUpdate(); logWarnings(stmt.getWarnings()); } catch (SQLException e) { - log.error("PtG CHUNK DAO: Unable to complete update incomplete! " + e); + log.error("PtG CHUNK DAO: Unable to complete update incomplete! {}", + e.getMessage(), e); } finally { close(stmt); } @@ -555,14 +533,13 @@ public synchronized PtGChunkDataTO refresh(long primary_key) { logWarnings(con.getWarnings()); find.setLong(1, primary_key); logWarnings(find.getWarnings()); - log.trace("PTG CHUNK DAO: refresh status method; " + find.toString()); + log.trace("PTG CHUNK DAO: refresh status method; {}", find.toString()); rs = find.executeQuery(); logWarnings(find.getWarnings()); PtGChunkDataTO chunkDataTO = null; // The result shoul be un - // TODO REMOVE THIS WHILE while (rs.next()) { chunkDataTO = new PtGChunkDataTO(); chunkDataTO.setStatus(rs.getInt("sg.statusCode")); @@ -570,7 +547,7 @@ public synchronized PtGChunkDataTO refresh(long primary_key) { } return chunkDataTO; } catch (SQLException e) { - log.error("PTG CHUNK DAO: " + e); + log.error("PTG CHUNK DAO: {}", e.getMessage(), e); /* Return null TransferObject! */ return null; } finally { @@ -626,7 +603,7 @@ public synchronized Collection find(TRequestToken requestToken) find.setString(1, strToken); logWarnings(find.getWarnings()); - log.trace("PTG CHUNK DAO: find method; " + find.toString()); + log.trace("PTG CHUNK DAO: find method; {}", find.toString()); rs = find.executeQuery(); logWarnings(find.getWarnings()); while (rs.next()) { @@ -635,7 +612,6 @@ public synchronized Collection find(TRequestToken requestToken) close(rs); close(find); - // TODO MICHELE USER_SURL get new fields // get chunks of the request str = "SELECT sg.statusCode, rq.pinLifetime, rg.ID, rq.timeStamp, rq.client_dn, rq.proxy, rg.sourceSURL, " + "rg.normalized_sourceSURL_StFN, rg.sourceSURL_uniqueID, d.isSourceADirectory, " @@ -665,8 +641,6 @@ public synchronized Collection find(TRequestToken requestToken) chunkDataTO.setRequestToken(strToken); chunkDataTO.setPrimaryKey(rs.getLong("rg.ID")); chunkDataTO.setFromSURL(rs.getString("rg.sourceSURL")); - - // TODO MICHELE USER_SURL fill new fields chunkDataTO.setNormalizedStFN(rs .getString("rg.normalized_sourceSURL_StFN")); int uniqueID = rs.getInt("rg.sourceSURL_uniqueID"); @@ -698,7 +672,7 @@ public synchronized Collection find(TRequestToken requestToken) } return list; } catch (SQLException e) { - log.error("PTG CHUNK DAO: " + e); + log.error("PTG CHUNK DAO: ", e.getMessage(), e); /* Return empty Collection! */ return new ArrayList(); } finally { @@ -722,7 +696,6 @@ public synchronized Collection findReduced( PreparedStatement find = null; ResultSet rs = null; try { - // TODO MICHELE USER_SURL get new fields // get reduced chunks String str = "SELECT sg.statusCode, rg.ID, rg.sourceSURL, rg.normalized_sourceSURL_StFN, rg.sourceSURL_uniqueID " + "FROM request_queue rq JOIN (request_Get rg, status_Get sg) " @@ -735,8 +708,7 @@ public synchronized Collection findReduced( find.setString(1, reqtoken); logWarnings(find.getWarnings()); - log.trace("PtG CHUNK DAO! findReduced with request token; " - + find.toString()); + log.trace("PtG CHUNK DAO! findReduced with request token; {}", find.toString()); rs = find.executeQuery(); logWarnings(find.getWarnings()); @@ -746,7 +718,6 @@ public synchronized Collection findReduced( reducedChunkDataTO.setStatus(rs.getInt("sg.statusCode")); reducedChunkDataTO.setPrimaryKey(rs.getLong("rg.ID")); reducedChunkDataTO.setFromSURL(rs.getString("rg.sourceSURL")); - // TODO MICHELE USER_SURL fill new fields reducedChunkDataTO.setNormalizedStFN(rs .getString("rg.normalized_sourceSURL_StFN")); int uniqueID = rs.getInt("rg.sourceSURL_uniqueID"); @@ -758,7 +729,7 @@ public synchronized Collection findReduced( } return list; } catch (SQLException e) { - log.error("PTG CHUNK DAO: " + e); + log.error("PTG CHUNK DAO: {}", e.getMessage(), e); /* Return empty Collection! */ return new ArrayList(); } finally { @@ -796,8 +767,7 @@ public synchronized Collection findReduced( find.setString(1, requestToken.getValue()); logWarnings(find.getWarnings()); - log.trace("PtG CHUNK DAO! findReduced with griduser+surlarray; " - + find.toString()); + log.trace("PtG CHUNK DAO! findReduced with griduser+surlarray; {}", find.toString()); rs = find.executeQuery(); logWarnings(find.getWarnings()); @@ -807,7 +777,6 @@ public synchronized Collection findReduced( chunkDataTO.setStatus(rs.getInt("sg.statusCode")); chunkDataTO.setPrimaryKey(rs.getLong("rg.ID")); chunkDataTO.setFromSURL(rs.getString("rg.sourceSURL")); - // TODO MICHELE USER_SURL fill new fields chunkDataTO.setNormalizedStFN(rs .getString("rg.normalized_sourceSURL_StFN")); int uniqueID = rs.getInt("rg.sourceSURL_uniqueID"); @@ -819,7 +788,7 @@ public synchronized Collection findReduced( } return list; } catch (SQLException e) { - log.error("PTG CHUNK DAO: " + e); + log.error("PTG CHUNK DAO: {}", e.getMessage(), e); /* Return empty Collection! */ return new ArrayList(); } finally { @@ -844,10 +813,6 @@ public synchronized Collection findReduced( PreparedStatement find = null; ResultSet rs = null; try { - // TODO MICHELE USER_SURL get new fields and select on the uniqueID and on - // the fromSurl - // TODO MICHELE USER_SURL when the uniqueID and normalized surl will be - // made on the FrontEnd remove the String[] surls parameter /* * NOTE: we search also on the fromSurl because otherwise we lost all * request_get that have not the uniqueID set because are not yet been @@ -868,8 +833,7 @@ public synchronized Collection findReduced( find.setString(1, griduser); logWarnings(find.getWarnings()); - log.trace("PtG CHUNK DAO! findReduced with griduser+surlarray; " - + find.toString()); + log.trace("PtG CHUNK DAO! findReduced with griduser+surlarray; {}", find.toString()); rs = find.executeQuery(); logWarnings(find.getWarnings()); @@ -879,7 +843,6 @@ public synchronized Collection findReduced( chunkDataTO.setStatus(rs.getInt("sg.statusCode")); chunkDataTO.setPrimaryKey(rs.getLong("rg.ID")); chunkDataTO.setFromSURL(rs.getString("rg.sourceSURL")); - // TODO MICHELE USER_SURL fill new fields chunkDataTO.setNormalizedStFN(rs .getString("rg.normalized_sourceSURL_StFN")); int uniqueID = rs.getInt("rg.sourceSURL_uniqueID"); @@ -891,7 +854,7 @@ public synchronized Collection findReduced( } return list; } catch (SQLException e) { - log.error("PTG CHUNK DAO: " + e); + log.error("PTG CHUNK DAO: {}", e.getMessage(), e); /* Return empty Collection! */ return new ArrayList(); } finally { @@ -935,13 +898,12 @@ public synchronized void signalMalformedPtGChunk(PtGChunkDataTO auxTO) { signal.setString(1, "Request is malformed!"); logWarnings(signal.getWarnings()); - log.trace("PTG CHUNK DAO: signalMalformed; " + signal.toString()); + log.trace("PTG CHUNK DAO: signalMalformed; {}", signal.toString()); signal.executeUpdate(); logWarnings(signal.getWarnings()); } catch (SQLException e) { - log.error("PtGChunkDAO! Unable to signal in DB that the" - + " request was malformed! Request: " + auxTO.toString() - + "; Exception: " + e.toString()); + log.error("PtGChunkDAO! Unable to signal in DB that the request was " + + "malformed! Request: {}; Exception: {}", auxTO.toString(), e.toString()); } finally { close(signal); } @@ -956,7 +918,6 @@ public synchronized void signalMalformedPtGChunk(PtGChunkDataTO auxTO) { * * In case of any error, 0 is returned. */ - // TODO MICHELE USER_SURL use the unique ID to perform the select on the // request_Get table public synchronized int numberInSRM_FILE_PINNED(int surlUniqueID) { @@ -982,8 +943,7 @@ public synchronized int numberInSRM_FILE_PINNED(int surlUniqueID) { StatusCodeConverter.getInstance().toDB(TStatusCode.SRM_FILE_PINNED)); logWarnings(find.getWarnings()); - log.trace("PtG CHUNK DAO - numberInSRM_FILE_PINNED method: " - + find.toString()); + log.trace("PtG CHUNK DAO - numberInSRM_FILE_PINNED method: {}", find.toString()); rs = find.executeQuery(); logWarnings(find.getWarnings()); @@ -993,9 +953,8 @@ public synchronized int numberInSRM_FILE_PINNED(int surlUniqueID) { } return numberFilePinned; } catch (SQLException e) { - log - .error("PtG CHUNK DAO! Unable to determine numberInSRM_FILE_PINNED! Returning 0! " - + e); + log.error("PtG CHUNK DAO! Unable to determine numberInSRM_FILE_PINNED! " + + "Returning 0! {}", e.getMessage(), e); return 0; } finally { close(rs); @@ -1013,8 +972,6 @@ public synchronized int numberInSRM_FILE_PINNED(int surlUniqueID) { */ public synchronized List transitExpiredSRM_FILE_PINNED() { - // TODO: put a limit on the queries..... - // TODO MICHELE USER_SURL moved the checks for surl requests from the surl // tring to the surl unique ID if (!checkConnection()) { log @@ -1052,8 +1009,8 @@ public synchronized List transitExpiredSRM_FILE_PINNED() { TSURL tsurl = TSURL.makeFromStringWellFormed(sourceSURL); uniqueID = tsurl.uniqueId(); } catch (InvalidTSURLAttributesException e) { - log.warn("PtGChunkDAO! unable to build the TSURL from " - + sourceSURL + " : InvalidTSURLAttributesException " + e); + log.warn("PtGChunkDAO! unable to build the TSURL from {}: " + + "InvalidTSURLAttributesException {}", sourceSURL, e.getMessage(), e); } } expiredSurlMap.put(sourceSURL, uniqueID); @@ -1066,7 +1023,7 @@ public synchronized List transitExpiredSRM_FILE_PINNED() { return new ArrayList(); } } catch (SQLException e) { - log.error("PtGChunkDAO! SQLException." + e); + log.error("PtGChunkDAO! SQLException. {}", e.getMessage(), e); rollback(con); return new ArrayList(); } finally { @@ -1094,8 +1051,8 @@ public synchronized List transitExpiredSRM_FILE_PINNED() { StatusCodeConverter.getInstance().toDB(TStatusCode.SRM_FILE_PINNED)); logWarnings(preparedStatement.getWarnings()); - log.trace("PtG CHUNK DAO - transitExpiredSRM_FILE_PINNED method: " - + preparedStatement.toString()); + log.trace("PtG CHUNK DAO - transitExpiredSRM_FILE_PINNED method: {}", + preparedStatement.toString()); int count = preparedStatement.executeUpdate(); logWarnings(preparedStatement.getWarnings()); @@ -1104,14 +1061,12 @@ public synchronized List transitExpiredSRM_FILE_PINNED() { log.trace("PtGChunkDAO! No chunk of PtG request was " + "transited from SRM_FILE_PINNED to SRM_RELEASED."); } else { - log.info("PtGChunkDAO! " + count - + " chunks of PtG requests were transited from" - + " SRM_FILE_PINNED to SRM_RELEASED."); + log.info("PtGChunkDAO! {} chunks of PtG requests were transited from" + + " SRM_FILE_PINNED to SRM_RELEASED.", count); } } catch (SQLException e) { - log - .error("PtGChunkDAO! Unable to transit expired SRM_FILE_PINNED chunks of PtG requests, to SRM_RELEASED! " - + e); + log.error("PtGChunkDAO! Unable to transit expired SRM_FILE_PINNED chunks " + + "of PtG requests, to SRM_RELEASED! {}", e.getMessage(), e); rollback(con); return new ArrayList(); } finally { @@ -1151,8 +1106,8 @@ public synchronized List transitExpiredSRM_FILE_PINNED() { TSURL tsurl = TSURL.makeFromStringWellFormed(sourceSURL); uniqueID = tsurl.uniqueId(); } catch (InvalidTSURLAttributesException e) { - log.warn("PtGChunkDAO! unable to build the TSURL from " - + sourceSURL + " : InvalidTSURLAttributesException " + e); + log.warn("PtGChunkDAO! unable to build the TSURL from {}. " + + "InvalidTSURLAttributesException: {}", sourceSURL, e.getMessage()); } } pinnedSurlSet.add(uniqueID); @@ -1161,21 +1116,11 @@ public synchronized List transitExpiredSRM_FILE_PINNED() { close(preparedStatement); // SURLs pinned by BoLs - // TODO MICHELE USER_SURL uncomment this line when the development goes on - // the BoL operation str = "SELECT rb.sourceSURL , rb.sourceSURL_uniqueID FROM " + "request_BoL rb JOIN (status_BoL sb, request_queue rq) ON sb.request_BoLID=rb.ID AND rb.request_queueID=rq.ID " + "WHERE sb.statusCode=?" + " AND UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(rq.timeStamp) < rq.pinLifetime "; - // str = "SELECT sourceSURL FROM " - // + - // "request_BoL rb JOIN (status_BoL s, request_queue r) ON s.request_BoLID=rb.ID AND rb.request_queueID=r.ID " - // + "WHERE s.statusCode=" - // + StatusCodeConverter.getInstance().toDB(TStatusCode.SRM_SUCCESS) - // + - // " AND UNIX_TIMESTAMP(NOW())-UNIX_TIMESTAMP(r.timeStamp) < r.pinLifetime "; - preparedStatement = con.prepareStatement(str); preparedStatement.setInt(1, StatusCodeConverter.getInstance().toDB(TStatusCode.SRM_SUCCESS)); @@ -1184,8 +1129,6 @@ public synchronized List transitExpiredSRM_FILE_PINNED() { logWarnings(preparedStatement.getWarnings()); while (res.next()) { - // TODO MICHELE USER_SURL uncomment this line when the development goes - // on the BoL operation String sourceSURL = res.getString("rb.sourceSURL"); Integer uniqueID = new Integer(res.getInt("rb.sourceSURL_uniqueID")); /* If the uniqueID is not setted compute it */ @@ -1194,15 +1137,15 @@ public synchronized List transitExpiredSRM_FILE_PINNED() { TSURL tsurl = TSURL.makeFromStringWellFormed(sourceSURL); uniqueID = tsurl.uniqueId(); } catch (InvalidTSURLAttributesException e) { - log.warn("PtGChunkDAO! unable to build the TSURL from " - + sourceSURL + " : InvalidTSURLAttributesException " + e); + log.warn("PtGChunkDAO! unable to build the TSURL from {}. " + + "InvalidTSURLAttributesException: {}", sourceSURL, e.getMessage(), e); } } pinnedSurlSet.add(uniqueID); } commit(con); } catch (SQLException e) { - log.error("PtGChunkDAO! SQLException." + e); + log.error("PtGChunkDAO! SQLException. {}", e.getMessage(), e); rollback(con); } finally { close(preparedStatement); @@ -1216,9 +1159,8 @@ public synchronized List transitExpiredSRM_FILE_PINNED() { try { surl = TSURL.makeFromStringValidate(surlEntry.getKey()); } catch (InvalidTSURLAttributesException e) { - log - .error("Invalid SURL, cannot release the pin (Extended Attribute): " - + surlEntry.getKey()); + log.error("Invalid SURL, cannot release the pin " + + "(Extended Attribute): {}", surlEntry.getKey()); continue; } expiredSurlList.add(surl); @@ -1226,11 +1168,8 @@ public synchronized List transitExpiredSRM_FILE_PINNED() { try { stori = NamespaceDirector.getNamespace().resolveStoRIbySURL(surl); } catch (Throwable e) { - log - .error(String.format( - "Invalid SURL %s cannot release the pin. %s: %s", - surlEntry.getKey(), e.getClass().getCanonicalName(), - e.getMessage())); + log.error("Invalid SURL {} cannot release the pin. {}: {}", + surlEntry.getKey(), e.getClass().getCanonicalName(), e.getMessage(), e); continue; } @@ -1260,13 +1199,7 @@ public synchronized void transitSRM_FILE_PINNEDtoSRM_RELEASED(long[] ids) { .error("PTG CHUNK DAO: transitSRM_FILE_PINNEDtoSRM_RELEASED - unable to get a valid connection!"); return; } - String str = - // "UPDATE " - // + - // "status_Get s JOIN (request_Get rg, request_queue r) ON s.request_GetID=rg.ID AND rg.request_queueID=r.ID " - // + "SET s.statusCode=? " + "WHERE s.statusCode=? AND s.ID IN " - // + makeWhereString(ids); - "UPDATE " + "status_Get sg " + "SET sg.statusCode=? " + String str = "UPDATE status_Get sg SET sg.statusCode=? " + "WHERE sg.statusCode=? AND sg.request_GetID IN " + makeWhereString(ids); PreparedStatement stmt = null; try { @@ -1280,21 +1213,20 @@ public synchronized void transitSRM_FILE_PINNEDtoSRM_RELEASED(long[] ids) { StatusCodeConverter.getInstance().toDB(TStatusCode.SRM_FILE_PINNED)); logWarnings(stmt.getWarnings()); - log.trace("PtG CHUNK DAO - transitSRM_FILE_PINNEDtoSRM_RELEASED: " - + stmt.toString()); + log.trace("PtG CHUNK DAO - transitSRM_FILE_PINNEDtoSRM_RELEASED: {}", + stmt.toString()); int count = stmt.executeUpdate(); logWarnings(stmt.getWarnings()); if (count == 0) { log.trace("PtG CHUNK DAO! No chunk of PtG request was " + "transited from SRM_FILE_PINNED to SRM_RELEASED."); } else { - log.info("PtG CHUNK DAO! " + count - + " chunks of PtG requests were transited " - + "from SRM_FILE_PINNED to SRM_RELEASED."); + log.info("PtG CHUNK DAO! {} chunks of PtG requests were transited " + + "from SRM_FILE_PINNED to SRM_RELEASED.", count); } } catch (SQLException e) { log.error("PtG CHUNK DAO! Unable to transit chunks" - + " from SRM_FILE_PINNED to SRM_RELEASED! " + e); + + " from SRM_FILE_PINNED to SRM_RELEASED! {}", e.getMessage(), e); } finally { close(stmt); } @@ -1309,51 +1241,49 @@ public synchronized void transitSRM_FILE_PINNEDtoSRM_RELEASED(long[] ids, if (token == null) { transitSRM_FILE_PINNEDtoSRM_RELEASED(ids); - } else { - /* - * If a request token has been specified, only the related Get requests - * have to be released. This is done adding the r.r_token="..." clause in - * the where subquery. - */ - if (!checkConnection()) { - log - .error("PTG CHUNK DAO: transitSRM_FILE_PINNEDtoSRM_RELEASED - unable to get a valid connection!"); - return; - } - String str = "UPDATE " - + "status_Get sg JOIN (request_Get rg, request_queue rq) ON sg.request_GetID=rg.ID AND rg.request_queueID=rq.ID " - + "SET sg.statusCode=? " + "WHERE sg.statusCode=? AND rq.r_token='" - + token.toString() + "' AND rg.ID IN " + makeWhereString(ids); - PreparedStatement stmt = null; - try { - stmt = con.prepareStatement(str); - logWarnings(con.getWarnings()); - stmt.setInt(1, - StatusCodeConverter.getInstance().toDB(TStatusCode.SRM_RELEASED)); - logWarnings(stmt.getWarnings()); - - stmt.setInt(2, - StatusCodeConverter.getInstance().toDB(TStatusCode.SRM_FILE_PINNED)); - logWarnings(stmt.getWarnings()); - - log.trace("PtG CHUNK DAO - transitSRM_FILE_PINNEDtoSRM_RELEASED: " - + stmt.toString()); - int count = stmt.executeUpdate(); - logWarnings(stmt.getWarnings()); - if (count == 0) { - log.trace("PtG CHUNK DAO! No chunk of PtG request was" - + " transited from SRM_FILE_PINNED to SRM_RELEASED."); - } else { - log.info("PtG CHUNK DAO! " + count - + " chunks of PtG requests were transited from " - + "SRM_FILE_PINNED to SRM_RELEASED."); - } - } catch (SQLException e) { - log.error("PtG CHUNK DAO! Unable to transit chunks from " - + "SRM_FILE_PINNED to SRM_RELEASED! " + e); - } finally { - close(stmt); + return; + } + + /* + * If a request token has been specified, only the related Get requests + * have to be released. This is done adding the r.r_token="..." clause in + * the where subquery. + */ + if (!checkConnection()) { + log.error("PTG CHUNK DAO: transitSRM_FILE_PINNEDtoSRM_RELEASED - " + + "unable to get a valid connection!"); + return; + } + + String str = "UPDATE " + + "status_Get sg JOIN (request_Get rg, request_queue rq) ON sg.request_GetID=rg.ID AND rg.request_queueID=rq.ID " + + "SET sg.statusCode=? " + "WHERE sg.statusCode=? AND rq.r_token='" + + token.toString() + "' AND rg.ID IN " + makeWhereString(ids); + PreparedStatement stmt = null; + try { + stmt = con.prepareStatement(str); + logWarnings(con.getWarnings()); + stmt.setInt(1,StatusCodeConverter.getInstance().toDB(TStatusCode.SRM_RELEASED)); + logWarnings(stmt.getWarnings()); + + stmt.setInt(2,StatusCodeConverter.getInstance().toDB(TStatusCode.SRM_FILE_PINNED)); + logWarnings(stmt.getWarnings()); + + log.trace("PtG CHUNK DAO - transitSRM_FILE_PINNEDtoSRM_RELEASED: {}", stmt.toString()); + int count = stmt.executeUpdate(); + logWarnings(stmt.getWarnings()); + if (count == 0) { + log.trace("PtG CHUNK DAO! No chunk of PtG request was" + + " transited from SRM_FILE_PINNED to SRM_RELEASED."); + } else { + log.info("PtG CHUNK DAO! {} chunks of PtG requests were transited from " + + "SRM_FILE_PINNED to SRM_RELEASED.", count); } + } catch (SQLException e) { + log.error("PtG CHUNK DAO! Unable to transit chunks from " + + "SRM_FILE_PINNED to SRM_RELEASED! {}", e.getMessage(), e); + } finally { + close(stmt); } } @@ -1382,18 +1312,19 @@ public synchronized void updateStatus(TRequestToken requestToken, stmt.setString(2, (explanation != null ? explanation : "")); logWarnings(stmt.getWarnings()); - log.trace("PtG CHUNK DAO - updateStatus: " + stmt.toString()); + log.trace("PtG CHUNK DAO - updateStatus: {}", stmt.toString()); int count = stmt.executeUpdate(); logWarnings(stmt.getWarnings()); if (count == 0) { - log.trace("PtG CHUNK DAO! No chunk of PtG request was" + " updated to " - + statusCode + "."); + log.trace("PtG CHUNK DAO! No chunk of PtG request was updated to {}.", + statusCode); } else { - log.info("PtG CHUNK DAO! " + count - + " chunks of PtG requests were updated to " + statusCode + "."); + log.info("PtG CHUNK DAO! {} chunks of PtG requests were updated to {}.", + count, statusCode); } } catch (SQLException e) { - log.error("PtG CHUNK DAO! Unable to updated to " + statusCode + " !" + e); + log.error("PtG CHUNK DAO! Unable to updated to {}! {}", statusCode, + e.getMessage(), e); } finally { close(stmt); } @@ -1496,22 +1427,19 @@ public synchronized void doUpdateStatusOnMatchingStatus( .setInt(2, StatusCodeConverter.getInstance().toDB(expectedStatusCode)); logWarnings(stmt.getWarnings()); - log.trace("PtG CHUNK DAO - updateStatusOnMatchingStatus: " - + stmt.toString()); + log.trace("PtG CHUNK DAO - updateStatusOnMatchingStatus: {}", stmt.toString()); int count = stmt.executeUpdate(); logWarnings(stmt.getWarnings()); if (count == 0) { - log.trace("PtG CHUNK DAO! No chunk of PtG request was" - + " updated from " + expectedStatusCode + " to " + newStatusCode - + "."); + log.trace("PtG CHUNK DAO! No chunk of PtG request was updated " + + "from {} to {}.", expectedStatusCode, newStatusCode); } else { - log.debug("PtG CHUNK DAO! " + count - + " chunks of PtG requests were updated from " + expectedStatusCode - + " to " + newStatusCode + "."); + log.debug("PtG CHUNK DAO! {} chunks of PtG requests were updated " + + "from {} to {}.", count, expectedStatusCode, newStatusCode); } } catch (SQLException e) { - log.error("PtG CHUNK DAO! Unable to updated from " + expectedStatusCode - + " to " + newStatusCode + " !" + e); + log.error("PtG CHUNK DAO! Unable to updated from {} to {}! {}", + expectedStatusCode, newStatusCode, e.getMessage(), e); } finally { close(stmt); } @@ -1526,7 +1454,8 @@ private void close(ResultSet rset) { try { rset.close(); } catch (Exception e) { - log.error("PTG CHUNK DAO! Unable to close ResultSet! Exception: " + e); + log.error("PTG CHUNK DAO! Unable to close ResultSet! Error: {}", + e.getMessage(), e); } } } @@ -1540,8 +1469,8 @@ private void close(Statement stmt) { try { stmt.close(); } catch (Exception e) { - log.error("PTG CHUNK DAO! Unable to close Statement " + stmt.toString() - + " - Exception: " + e); + log.error("PTG CHUNK DAO! Unable to close Statement {} - Error: {}", + stmt.toString(), e.getMessage(), e); } } } @@ -1553,7 +1482,7 @@ private void commit(Connection con) { con.commit(); con.setAutoCommit(true); } catch (SQLException e) { - log.error("PtG, SQL EXception", e); + log.error("PtG, SQL Exception: {}", e.getMessage(), e); } } } @@ -1569,7 +1498,7 @@ private void rollback(Connection con) { con.setAutoCommit(true); log.error("PTG CHUNK DAO: roll back successful!"); } catch (SQLException e2) { - log.error("PTG CHUNK DAO: roll back failed! " + e2); + log.error("PTG CHUNK DAO: roll back failed! {}", e2.getMessage(), e2); } } } @@ -1599,9 +1528,9 @@ private int extractID(ResultSet rs) throws Exception { private void logWarnings(SQLWarning w) { if (w != null) { - log.debug("PTG CHUNK DAO: " + w.toString()); + log.debug("PTG CHUNK DAO: {}", w.toString()); while ((w = w.getNextWarning()) != null) { - log.debug("PTG CHUNK DAO: " + w.toString()); + log.debug("PTG CHUNK DAO: {}", w.toString()); } } } @@ -1655,7 +1584,7 @@ private String makeSurlString(String[] surls) { requestedSURL = SURL.makeSURLfromString(surls[i]); } catch (NamespaceException e) { log.error(e.getMessage()); - log.debug("Skip '" + surls[i] + "' during query creation"); + log.debug("Skip '{}' during query creation", surls[i]); continue; } @@ -1692,9 +1621,11 @@ private boolean setUpConnection() { response = con.isValid(0); } } catch (ClassNotFoundException e) { - log.error("PTG CHUNK DAO! Exception in setUpConnection! " + e); + log.error("PTG CHUNK DAO! Exception in setUpConnection! {}", + e.getMessage(), e); } catch (SQLException e) { - log.error("PTG CHUNK DAO! Exception in setUpConenction! " + e); + log.error("PTG CHUNK DAO! Exception in setUpConenction! {}", + e.getMessage(), e); } return response; } @@ -1726,8 +1657,8 @@ private void takeDownConnection() { try { con.close(); } catch (SQLException e) { - log - .error("PTG CHUNK DAO! Exception in takeDownConnection method: " + e); + log.error("PTG CHUNK DAO! Exception in takeDownConnection method: {}", + e.getMessage(), e); } } } @@ -1797,7 +1728,7 @@ private synchronized Collection find(int[] surlsUniqueIDs, List list = new ArrayList(); - log.trace("PTG CHUNK DAO - find method: " + find.toString()); + log.trace("PTG CHUNK DAO - find method: {}", find.toString()); rs = find.executeQuery(); logWarnings(find.getWarnings()); PtGChunkDataTO chunkDataTO = null; @@ -1809,7 +1740,6 @@ private synchronized Collection find(int[] surlsUniqueIDs, chunkDataTO.setPrimaryKey(rs.getLong("rg.ID")); chunkDataTO.setFromSURL(rs.getString("rg.sourceSURL")); - // TODO MICHELE USER_SURL fill new fields chunkDataTO.setNormalizedStFN(rs .getString("rg.normalized_sourceSURL_StFN")); int uniqueID = rs.getInt("rg.sourceSURL_uniqueID"); @@ -1841,7 +1771,7 @@ private synchronized Collection find(int[] surlsUniqueIDs, } return list; } catch (SQLException e) { - log.error("PTG CHUNK DAO: " + e); + log.error("PTG CHUNK DAO: {}", e.getMessage(), e); /* return empty Collection! */ return new ArrayList(); } finally { diff --git a/src/main/java/it/grid/storm/catalogs/PtGChunkDataTO.java b/src/main/java/it/grid/storm/catalogs/PtGChunkDataTO.java index 245c0b65..86329cf3 100644 --- a/src/main/java/it/grid/storm/catalogs/PtGChunkDataTO.java +++ b/src/main/java/it/grid/storm/catalogs/PtGChunkDataTO.java @@ -43,7 +43,6 @@ public class PtGChunkDataTO { private long primaryKey = -1; // ID primary key of record in DB private boolean dirOption; // initialised in constructor private String fromSURL = " "; - // TODO MICHELE USER_SURL added new fields private String normalizedStFN = null; private Integer surlUniqueID = null; /* Database table request_Get fields END */ @@ -68,7 +67,6 @@ public PtGChunkDataTO() { this.protocolList = TransferProtocolListConverter.toDB(protocolPreferences); this.status = StatusCodeConverter.getInstance().toDB( TStatusCode.SRM_REQUEST_QUEUED); - // TODO MICHELE why? this field is from the DB like the fromSURL... this.dirOption = false; // this.allLevelRecursive = false; diff --git a/src/main/java/it/grid/storm/catalogs/PtGPersistentChunkData.java b/src/main/java/it/grid/storm/catalogs/PtGPersistentChunkData.java index 90b3c6b0..a363e36c 100644 --- a/src/main/java/it/grid/storm/catalogs/PtGPersistentChunkData.java +++ b/src/main/java/it/grid/storm/catalogs/PtGPersistentChunkData.java @@ -85,6 +85,7 @@ public PtGPersistentChunkData(GridUserInterface auth, super(auth, fromSURL, lifeTime, dirOption, desiredProtocols, fileSize, status, transferURL); if (requestToken == null) { + log.debug("PtGPersistentChunkData: requestToken is null!"); throw new InvalidPtGPersistentChunkDataAttributesException(requestToken, fromSURL, lifeTime, dirOption, desiredProtocols, fileSize, status, transferURL); @@ -130,12 +131,6 @@ public void changeStatusSRM_FILE_PINNED(String explanation) { setStatus(TStatusCode.SRM_FILE_PINNED, explanation); } - @Override - protected Logger getLog() { - - return PtGPersistentChunkData.log; - } - /* * (non-Javadoc) * diff --git a/src/main/java/it/grid/storm/catalogs/PtPChunkCatalog.java b/src/main/java/it/grid/storm/catalogs/PtPChunkCatalog.java index a5b61433..1d9cfa4a 100644 --- a/src/main/java/it/grid/storm/catalogs/PtPChunkCatalog.java +++ b/src/main/java/it/grid/storm/catalogs/PtPChunkCatalog.java @@ -109,10 +109,9 @@ public void run() { .toArray(new Long[ids.size()])); if (reduced.isEmpty()) { - log - .error("ATTENTION in PtP CHUNK CATALOG! Attempt to handle physical files for transited expired entries failed! " - + "No data could be translated from persitence for PtP Chunks with ID " - + ids); + log.error("ATTENTION in PtP CHUNK CATALOG! Attempt to handle physical " + + "files for transited expired entries failed! No data could be " + + "translated from persitence for PtP Chunks with ID {}", ids); } ArrayList surls = new ArrayList(reduced.size()); for (ReducedPtPChunkData data : reduced) { @@ -164,9 +163,6 @@ synchronized public void update(PtPPersistentChunkData chunkData) { } dao.update(to); - // TODO MICHELE SURL STORE - // SurlStatusStore.getInstance().storeSurlStatus(cd.getSURL(), - // cd.getStatus().getStatusCode()); } /** @@ -179,19 +175,14 @@ synchronized public PtPPersistentChunkData refreshStatus( PtPPersistentChunkData inputChunk) { PtPChunkDataTO auxTO = dao.refresh(inputChunk.getPrimaryKey()); - log.debug("PtP CHUNK CATALOG refreshStatus: retrieved data " + auxTO); + log.debug("PtP CHUNK CATALOG refreshStatus: retrieved data {}", auxTO); if (auxTO == null) { - log - .warn("PtP CHUNK CATALOG! Empty TO found in persistence for specified request: " - + inputChunk.getPrimaryKey()); + log.warn("PtP CHUNK CATALOG! Empty TO found in persistence for specified " + + "request: {}", inputChunk.getPrimaryKey()); return null; - } else { - PtPPersistentChunkData data = makeOne(auxTO, inputChunk.getRequestToken()); - // TODO MICHELE SURL STORE - // SurlStatusStore.getInstance().storeSurlStatus(data.getSURL(), - // data.getStatus().getStatusCode()); - return data; } + PtPPersistentChunkData data = makeOne(auxTO, inputChunk.getRequestToken()); + return data; } /** @@ -211,7 +202,7 @@ synchronized public Collection lookup( final TRequestToken rt) { Collection chunkTOs = dao.find(rt); - log.debug("PtPChunkCatalog: retrieved data " + chunkTOs); + log.debug("PtPChunkCatalog: retrieved data {}", chunkTOs); return buildChunkDataList(chunkTOs); } @@ -245,8 +236,8 @@ private PtPPersistentChunkData makeOne(PtPChunkDataTO auxTO, TRequestToken rt) { // Check for max value allowed long max = Configuration.getInstance().getPinLifetimeMaximum(); if (pinLifeTime > max) { - log.warn("PinLifeTime is greater than the max value " - + "allowed. Drop the value to the max = " + max + " seconds"); + log.warn("PinLifeTime is greater than the max value allowed. Drop the " + + "value to the max = {} seconds", max); pinLifeTime = max; } pinLifetime = TLifeTimeInSeconds.make(pinLifeTime, TimeUnit.SECONDS); @@ -367,9 +358,8 @@ private PtPPersistentChunkData makeOne(PtPChunkDataTO auxTO, TRequestToken rt) { } } catch (IllegalArgumentException e) { - log - .error("Unexpected error on voms grid user creation. Contact StoRM Support : IllegalArgumentException " - + e.getMessage()); + log.error("Unexpected error on voms grid user creation. " + + "IllegalArgumentException: {}", e.getMessage(), e); } // transferURL @@ -389,25 +379,25 @@ private PtPPersistentChunkData makeOne(PtPChunkDataTO auxTO, TRequestToken rt) { } catch (InvalidPtPPersistentChunkDataAttributesException e) { dao.signalMalformedPtPChunk(auxTO); log.warn("PtP CHUNK CATALOG! Retrieved malformed PtP chunk data" - + " from persistence. Dropping chunk from request: " + rt); + + " from persistence. Dropping chunk from request: {}", rt); log.warn(e.getMessage(), e); log.warn(errorSb.toString()); } catch (InvalidPtPDataAttributesException e) { dao.signalMalformedPtPChunk(auxTO); log.warn("PtP CHUNK CATALOG! Retrieved malformed PtP chunk data" - + " from persistence. Dropping chunk from request: " + rt); + + " from persistence. Dropping chunk from request: {}", rt); log.warn(e.getMessage(), e); log.warn(errorSb.toString()); } catch (InvalidFileTransferDataAttributesException e) { dao.signalMalformedPtPChunk(auxTO); log.warn("PtP CHUNK CATALOG! Retrieved malformed PtP chunk data" - + " from persistence. Dropping chunk from request: " + rt); + + " from persistence. Dropping chunk from request: {}", rt); log.warn(e.getMessage(), e); log.warn(errorSb.toString()); } catch (InvalidSurlRequestDataAttributesException e) { dao.signalMalformedPtPChunk(auxTO); log.warn("PtP CHUNK CATALOG! Retrieved malformed PtP chunk data" - + " from persistence. Dropping chunk from request: " + rt); + + " from persistence. Dropping chunk from request: {}", rt); log.warn(e.getMessage(), e); log.warn(errorSb.toString()); } @@ -526,36 +516,6 @@ synchronized public Collection lookupReducedPtPChunkData( TRequestToken rt) { return lookupReducedPtPChunkData(rt, new ArrayList(0)); - // Collection reducedChunkDataTOs = - // dao.findReduced(rt.getValue(), null); - // log.debug("PtP CHUNK CATALOG: retrieved data " + reducedChunkDataTOs); - // ArrayList list = new - // ArrayList(); - // if(reducedChunkDataTOs.isEmpty()) - // { - // log.debug("PtP CHUNK CATALOG! No chunks found in persistence for " + rt); - // } - // else - // { - // ReducedPtPChunkData reducedChunkData; - // for(ReducedPtPChunkDataTO reducedChunkDataTO : reducedChunkDataTOs) - // { - // reducedChunkData = makeOneReduced(reducedChunkDataTO); - // if(reducedChunkData != null) - // { - // list.add(reducedChunkData); - // SurlStatusStore.getInstance().storeSurlStatus(reducedChunkData.toSURL(), - // reducedChunkData.status().getStatusCode()); - // if(!this.isComplete(reducedChunkDataTO)) - // { - // this.completeTO(reducedChunkDataTO, reducedChunkData); - // dao.updateIncomplete(reducedChunkDataTO); - // } - // } - // } - // log.debug("PtP CHUNK CATALOG: returning " + list); - // } - // return list; } public Collection lookupReducedPtPChunkData( @@ -563,38 +523,8 @@ public Collection lookupReducedPtPChunkData( Collection reducedChunkDataTOs = dao.findReduced( requestToken.getValue(), surls); - log.debug("PtP CHUNK CATALOG: retrieved data " + reducedChunkDataTOs); + log.debug("PtP CHUNK CATALOG: retrieved data {}", reducedChunkDataTOs); return buildReducedChunkDataList(reducedChunkDataTOs); - // ArrayList list = new - // ArrayList(); - // if (reducedChunkDataTOs.isEmpty()) - // { - // log.debug("PtP CHUNK CATALOG! No chunks found in persistence for " + - // requestToken); - // } - // else - // { - // ReducedPtPChunkData reducedChunkData; - // for (ReducedPtPChunkDataTO reducedChunkDataTO : reducedChunkDataTOs) - // { - // reducedChunkData = makeOneReduced(reducedChunkDataTO); - // if (reducedChunkData != null) - // { - // list.add(reducedChunkData); - // // TODO MICHELE SURL STORE - // // - // SurlStatusStore.getInstance().storeSurlStatus(reducedChunkData.toSURL(), - // // reducedChunkData.status().getStatusCode()); - // if (!this.isComplete(reducedChunkDataTO)) - // { - // this.completeTO(reducedChunkDataTO, reducedChunkData); - // dao.updateIncomplete(reducedChunkDataTO); - // } - // } - // } - // log.debug("PtP CHUNK CATALOG: returning " + list); - // } - // return list; } public Collection lookupPtPChunkData(TSURL surl) { @@ -622,7 +552,7 @@ private Collection lookupPtPChunkData( } Collection chunkDataTOs = dao.find(surlsUniqueIDs, surlsArray, user.getDn()); - log.debug("PtP CHUNK CATALOG: retrieved data " + chunkDataTOs); + log.debug("PtP CHUNK CATALOG: retrieved data {}", chunkDataTOs); return buildChunkDataList(chunkDataTOs); } @@ -638,7 +568,7 @@ public Collection lookupPtPChunkData(List surls) } Collection chunkDataTOs = dao.find(surlsUniqueIDs, surlsArray); - log.debug("PtP CHUNK CATALOG: retrieved data " + chunkDataTOs); + log.debug("PtP CHUNK CATALOG: retrieved data {}", chunkDataTOs); return buildChunkDataList(chunkDataTOs); } @@ -649,23 +579,21 @@ private Collection buildChunkDataList( PtPPersistentChunkData chunk; for (PtPChunkDataTO chunkTO : chunkDataTOs) { chunk = makeOne(chunkTO); - if (chunk != null) { - list.add(chunk); - // TODO MICHELE SURL STORE - // SurlStatusStore.getInstance().storeSurlStatus(chunk.getSURL(), - // chunk.getStatus().getStatusCode()); - if (!this.isComplete(chunkTO)) { - try { - dao.updateIncomplete(this.completeTO(chunkTO, chunk)); - } catch (InvalidReducedPtPChunkDataAttributesException e) { - log - .warn("PtG CHUNK CATALOG! unable to add missing informations on DB to the request: " - + e); - } - } + if (chunk == null) { + continue; + } + list.add(chunk); + if (isComplete(chunkTO)) { + continue; + } + try { + dao.updateIncomplete(completeTO(chunkTO, chunk)); + } catch (InvalidReducedPtPChunkDataAttributesException e) { + log.warn("PtG CHUNK CATALOG! unable to add missing informations on " + + "DB to the request: {}", e.getMessage()); } } - log.debug("PtPChunkCatalog: returning " + list + "\n\n"); + log.debug("PtPChunkCatalog: returning {}\n\n", list); return list; } @@ -690,16 +618,13 @@ private Collection buildReducedChunkDataList( reducedChunkData = makeOneReduced(reducedChunkDataTO); if (reducedChunkData != null) { list.add(reducedChunkData); - // TODO MICHELE SURL STORE - // SurlStatusStore.getInstance().storeSurlStatus(reducedChunkData.toSURL(), - // reducedChunkData.status().getStatusCode()); if (!this.isComplete(reducedChunkDataTO)) { this.completeTO(reducedChunkDataTO, reducedChunkData); dao.updateIncomplete(reducedChunkDataTO); } } } - log.debug("PtP CHUNK CATALOG: returning " + list); + log.debug("PtP CHUNK CATALOG: returning {}", list); return list; } @@ -719,37 +644,8 @@ synchronized public Collection lookupReducedPtPChunkData( Collection reducedChunkDataTOs = dao .findReduced(Arrays.asList(volids)); - log.debug("PtP CHUNK CATALOG: fetched data " + reducedChunkDataTOs); + log.debug("PtP CHUNK CATALOG: fetched data {}", reducedChunkDataTOs); return buildReducedChunkDataList(reducedChunkDataTOs); - // List list = new ArrayList(); - // if(reducedChunkDataTOs.isEmpty()) - // { - // log.debug("PtP CHUNK CATALOG! No chunks found in persistence for " + - // volids); - // } - // else - // { - // ReducedPtPChunkData reducedChunkData; - // for(ReducedPtPChunkDataTO reducedChunkDataTO : reducedChunkDataTOs) - // { - // reducedChunkData = makeOneReduced(reducedChunkDataTO); - // if(reducedChunkData != null) - // { - // list.add(reducedChunkData); - // // TODO MICHELE SURL STORE - // // - // SurlStatusStore.getInstance().storeSurlStatus(reducedChunkData.toSURL(), - // reducedChunkData.status().getStatusCode()); - // if(!this.isComplete(reducedChunkDataTO)) - // { - // this.completeTO(reducedChunkDataTO, reducedChunkData); - // dao.updateIncomplete(reducedChunkDataTO); - // } - // } - // } - // log.debug("PtP CHUNK CATALOG: returning " + list); - // } - // return list; } private ReducedPtPChunkData makeOneReduced( @@ -833,9 +729,6 @@ private ReducedPtPChunkData makeOneReduced( synchronized public boolean isSRM_SPACE_AVAILABLE(TSURL surl) { return (dao.numberInSRM_SPACE_AVAILABLE(surl.uniqueId()) > 0); - // TODO MICHELE SURL STORE - // return - // TStatusCode.SRM_SPACE_AVAILABLE.equals(SurlStatusStore.getInstance().getSurlStatus(surl)); } /** @@ -876,15 +769,6 @@ synchronized public void transitSRM_SPACE_AVAILABLEtoSRM_SUCCESS( } } dao.transitSRM_SPACE_AVAILABLEtoSRM_SUCCESS(primaryKeys); - // TODO MICHELE SURL STORE - // for(TSURL surl : surls) - // { - // if(surl != null) - // { - // SurlStatusStore.getInstance().storeSurlStatus(surl, - // TStatusCode.SRM_SUCCESS); - // } - // } } /** @@ -911,9 +795,6 @@ synchronized public void transitSRM_SPACE_AVAILABLEtoSRM_ABORTED(TSURL surl, } dao.transitSRM_SPACE_AVAILABLEtoSRM_ABORTED(surl.uniqueId(), surl.toString(), explanation); - // TODO MICHELE SURL STORE - // SurlStatusStore.getInstance().storeSurlStatus(surl, - // TStatusCode.SRM_ABORTED); } public void updateStatus(TRequestToken requestToken, TSURL surl, diff --git a/src/main/java/it/grid/storm/catalogs/PtPChunkDAO.java b/src/main/java/it/grid/storm/catalogs/PtPChunkDAO.java index d1894705..44dbeeac 100644 --- a/src/main/java/it/grid/storm/catalogs/PtPChunkDAO.java +++ b/src/main/java/it/grid/storm/catalogs/PtPChunkDAO.java @@ -153,7 +153,6 @@ public synchronized void update(PtPChunkDataTO to) { updatePut.setString(7, to.overwriteOption()); logWarnings(updatePut.getWarnings()); - // TODO MICHELE USER_SURL fill new fields updatePut.setString(8, to.normalizedStFN()); logWarnings(updatePut.getWarnings()); @@ -163,11 +162,11 @@ public synchronized void update(PtPChunkDataTO to) { updatePut.setLong(10, to.primaryKey()); logWarnings(updatePut.getWarnings()); // run updateStatusPut... - log.trace("PtP CHUNK DAO - update method: " + updatePut.toString()); + log.trace("PtP CHUNK DAO - update method: {}", updatePut.toString()); updatePut.executeUpdate(); logWarnings(updatePut.getWarnings()); } catch (SQLException e) { - log.error("PtP CHUNK DAO: Unable to complete update! " + e); + log.error("PtP CHUNK DAO: Unable to complete update! {}", e.getMessage(), e); } finally { close(updatePut); } @@ -179,7 +178,6 @@ public synchronized void update(PtPChunkDataTO to) { * * @param chunkTO */ - // TODO MICHELE USER_SURL new method public synchronized void updateIncomplete(ReducedPtPChunkDataTO chunkTO) { if (!checkConnection()) { @@ -203,11 +201,12 @@ public synchronized void updateIncomplete(ReducedPtPChunkDataTO chunkTO) { stmt.setLong(3, chunkTO.primaryKey()); logWarnings(stmt.getWarnings()); - log.trace("PtP CHUNK DAO - update incomplete: " + stmt.toString()); + log.trace("PtP CHUNK DAO - update incomplete: {}", stmt.toString()); stmt.executeUpdate(); logWarnings(stmt.getWarnings()); } catch (SQLException e) { - log.error("PtP CHUNK DAO: Unable to complete update incomplete! " + e); + log.error("PtP CHUNK DAO: Unable to complete update incomplete! {}", + e.getMessage(), e); } finally { close(stmt); } @@ -247,7 +246,7 @@ public synchronized PtPChunkDataTO refresh(long primary_key) { stmt.setLong(1, primary_key); logWarnings(stmt.getWarnings()); - log.trace("PtP CHUNK DAO - refresh method: " + stmt.toString()); + log.trace("PtP CHUNK DAO - refresh method: {}", stmt.toString()); rs = stmt.executeQuery(); logWarnings(stmt.getWarnings()); while (rs.next()) { @@ -263,7 +262,7 @@ public synchronized PtPChunkDataTO refresh(long primary_key) { stmt.setLong(1, primary_key); logWarnings(stmt.getWarnings()); - log.trace("PtP CHUNK DAO - refresh method: " + stmt.toString()); + log.trace("PtP CHUNK DAO - refresh method: {}", stmt.toString()); rs = stmt.executeQuery(); logWarnings(stmt.getWarnings()); @@ -279,7 +278,6 @@ public synchronized PtPChunkDataTO refresh(long primary_key) { chunkDataTO.setRequestToken(rs.getString("rq.r_token")); chunkDataTO.setPrimaryKey(rs.getLong("rp.ID")); chunkDataTO.setToSURL(rs.getString("rp.targetSURL")); - // TODO MICHELE USER_SURL fill new fields chunkDataTO.setNormalizedStFN(rs .getString("rp.normalized_targetSURL_StFN")); int uniqueID = rs.getInt("rp.targetSURL_uniqueID"); @@ -307,16 +305,16 @@ public synchronized PtPChunkDataTO refresh(long primary_key) { } if (rs.next()) { log.warn("ATTENTION in PtP CHUNK DAO! Possible DB corruption! " - + "refresh method invoked for specific chunk with id " - + primary_key + ", but found more than one such chunks!"); + + "refresh method invoked for specific chunk with id {}, but found " + + "more than one such chunks!", primary_key); } } else { log.warn("ATTENTION in PtP CHUNK DAO! Possible DB corruption! " - + "refresh method invoked for specific chunk with id " + primary_key - + ", but chunk NOT found in persistence!"); + + "refresh method invoked for specific chunk with id {}, but chunk " + + "NOT found in persistence!", primary_key); } } catch (SQLException e) { - log.error("PtP CHUNK DAO! Unable to refresh chunk! " + e); + log.error("PtP CHUNK DAO! Unable to refresh chunk! {}", e.getMessage(), e); chunkDataTO = null; } finally { close(rs); @@ -363,7 +361,7 @@ public synchronized Collection find(TRequestToken requestToken) find.setString(1, strToken); logWarnings(find.getWarnings()); - log.trace("PtP CHUNK DAO - find method: " + find.toString()); + log.trace("PtP CHUNK DAO - find method: {}", find.toString()); rs = find.executeQuery(); logWarnings(find.getWarnings()); @@ -373,7 +371,6 @@ public synchronized Collection find(TRequestToken requestToken) close(rs); close(find); - // TODO MICHELE USER_SURL get new fields // get chunks of the request str = "SELECT rq.config_FileStorageTypeID, rq.config_OverwriteID, rq.timeStamp, rq.pinLifetime, rq.fileLifetime, rq.s_token, rq.client_dn, rq.proxy, rp.ID, rp.targetSURL, rp.expectedFileSize, rp.normalized_targetSURL_StFN, rp.targetSURL_uniqueID, sp.statusCode " + "FROM request_queue rq JOIN (request_Put rp, status_Put sp) " @@ -391,7 +388,7 @@ public synchronized Collection find(TRequestToken requestToken) StatusCodeConverter.getInstance().toDB(TStatusCode.SRM_ABORTED)); logWarnings(find.getWarnings()); - log.trace("PtP CHUNK DAO - find method: " + find.toString()); + log.trace("PtP CHUNK DAO - find method: {}", find.toString()); rs = find.executeQuery(); logWarnings(find.getWarnings()); PtPChunkDataTO chunkDataTO = null; @@ -421,7 +418,6 @@ public synchronized Collection find(TRequestToken requestToken) chunkDataTO.setPrimaryKey(rs.getLong("rp.ID")); chunkDataTO.setToSURL(rs.getString("rp.targetSURL")); - // TODO MICHELE USER_SURL fill new fields chunkDataTO.setNormalizedStFN(rs .getString("rp.normalized_targetSURL_StFN")); int uniqueID = rs.getInt("rp.targetSURL_uniqueID"); @@ -437,7 +433,7 @@ public synchronized Collection find(TRequestToken requestToken) } return list; } catch (SQLException e) { - log.error("PTP CHUNK DAO: " + e); + log.error("PTP CHUNK DAO: {}", e.getMessage(), e); /* return empty Collection! */ return new ArrayList(); } finally { @@ -489,8 +485,7 @@ public synchronized Collection findReduced( } } logWarnings(find.getWarnings()); - log.trace("PtP CHUNK DAO! findReduced with request token; " - + find.toString()); + log.trace("PtP CHUNK DAO! findReduced with request token; {}", find.toString()); rs = find.executeQuery(); logWarnings(find.getWarnings()); @@ -502,7 +497,6 @@ public synchronized Collection findReduced( .getString("rq.config_FileStorageTypeID")); reducedChunkDataTO.setPrimaryKey(rs.getLong("rp.ID")); reducedChunkDataTO.setToSURL(rs.getString("rp.targetSURL")); - // TODO MICHELE USER_SURL fill new fields reducedChunkDataTO.setNormalizedStFN(rs .getString("rp.normalized_targetSURL_StFN")); int uniqueID = rs.getInt("rp.targetSURL_uniqueID"); @@ -515,7 +509,7 @@ public synchronized Collection findReduced( } return list; } catch (SQLException e) { - log.error("PTP CHUNK DAO: " + e); + log.error("PTP CHUNK DAO: {}", e.getMessage(), e); /* return empty Collection! */ return new ArrayList(); } finally { @@ -550,7 +544,7 @@ public synchronized Collection findReduced( logWarnings(con.getWarnings()); List list = new ArrayList(); - log.trace("PtP CHUNK DAO! fetchReduced; " + find.toString()); + log.trace("PtP CHUNK DAO! fetchReduced; {}", find.toString()); rs = find.executeQuery(); logWarnings(find.getWarnings()); @@ -562,7 +556,6 @@ public synchronized Collection findReduced( .getString("rq.config_FileStorageTypeID")); reducedChunkDataTO.setPrimaryKey(rs.getLong("rp.ID")); reducedChunkDataTO.setToSURL(rs.getString("rp.targetSURL")); - // TODO MICHELE USER_SURL fill new fields reducedChunkDataTO.setNormalizedStFN(rs .getString("rp.normalized_targetSURL_StFN")); int uniqueID = rs.getInt("rp.targetSURL_uniqueID"); @@ -575,7 +568,7 @@ public synchronized Collection findReduced( } return list; } catch (SQLException e) { - log.error("PTP CHUNK DAO: " + e); + log.error("PTP CHUNK DAO: {}", e.getMessage(), e); /* return empty Collection */ return new ArrayList(); } finally { @@ -620,14 +613,14 @@ public synchronized void signalMalformedPtPChunk(PtPChunkDataTO auxTO) { signal.setString(1, "This chunk of the request is malformed!"); logWarnings(signal.getWarnings()); - log.trace("PtP CHUNK DAO - signalMalformedPtPChunk method: " - + signal.toString()); + log.trace("PtP CHUNK DAO - signalMalformedPtPChunk method: {}", + signal.toString()); signal.executeUpdate(); logWarnings(signal.getWarnings()); } catch (SQLException e) { log.error("PtPChunkDAO! Unable to signal in DB that a chunk of " - + "the request was malformed! Request: " + auxTO.toString() - + "; Exception: " + e.toString()); + + "the request was malformed! Request: {}; Error: {}", auxTO.toString(), + e.getMessage(), e); } finally { close(signal); } @@ -646,11 +639,7 @@ public synchronized int numberInSRM_SPACE_AVAILABLE(int surlUniqueID) { .error("PtP CHUNK DAO: numberInSRM_SPACE_AVAILABLE - unable to get a valid connection!"); return 0; } - /* - * TODO MICHELE USER_SURL now that we have the unique ID the RIGHT can be - * removed (not added the search on the id, but removed at all because we - * check that the status is SRM_SPACE_AVAILABLE) - */ + String str = "SELECT COUNT(rp.ID) FROM status_Put sp JOIN request_Put rp " + "ON (sp.request_PutID=rp.ID) " + "WHERE rp.targetSURL_uniqueID=? AND sp.statusCode=?"; @@ -664,15 +653,12 @@ public synchronized int numberInSRM_SPACE_AVAILABLE(int surlUniqueID) { stmt.setInt(1, surlUniqueID); logWarnings(stmt.getWarnings()); - stmt - .setInt( - 2, - StatusCodeConverter.getInstance().toDB( - TStatusCode.SRM_SPACE_AVAILABLE)); + stmt.setInt(2,StatusCodeConverter.getInstance().toDB( + TStatusCode.SRM_SPACE_AVAILABLE)); logWarnings(stmt.getWarnings()); - log.trace("PtP CHUNK DAO - numberInSRM_SPACE_AVAILABLE method: " - + stmt.toString()); + log.trace("PtP CHUNK DAO - numberInSRM_SPACE_AVAILABLE method: {}", + stmt.toString()); rs = stmt.executeQuery(); logWarnings(stmt.getWarnings()); @@ -683,7 +669,7 @@ public synchronized int numberInSRM_SPACE_AVAILABLE(int surlUniqueID) { return numberSpaceAvailable; } catch (SQLException e) { log.error("PtPChunkDAO! Unable to determine " - + "numberInSRM_SPACE_AVAILABLE! Returning 0! " + e); + + "numberInSRM_SPACE_AVAILABLE! Returning 0! {}", e.getMessage(), e); return 0; } finally { close(rs); @@ -724,8 +710,7 @@ public synchronized List getExpiredSRM_SPACE_AVAILABLE() { TStatusCode.SRM_SPACE_AVAILABLE)); logWarnings(stmt.getWarnings()); - log.trace("PtP CHUNK DAO - transitExpiredSRM_SPACE_AVAILABLE: " - + stmt.toString()); + log.trace("PtP CHUNK DAO - transitExpiredSRM_SPACE_AVAILABLE: {}", stmt.toString()); rs = stmt.executeQuery(); logWarnings(stmt.getWarnings()); @@ -735,7 +720,7 @@ public synchronized List getExpiredSRM_SPACE_AVAILABLE() { } } catch (SQLException e) { log.error("PtPChunkDAO! Unable to select expired " - + "SRM_SPACE_AVAILABLE chunks of PtP requests.", e); + + "SRM_SPACE_AVAILABLE chunks of PtP requests. {}", e.getMessage(), e); /* make an empty list! */ ids = new ArrayList(); @@ -776,15 +761,12 @@ public synchronized void transitSRM_SPACE_AVAILABLEtoSRM_SUCCESS( StatusCodeConverter.getInstance().toDB(TStatusCode.SRM_SUCCESS)); logWarnings(stmt.getWarnings()); - stmt - .setInt( - 2, - StatusCodeConverter.getInstance().toDB( + stmt.setInt(2, StatusCodeConverter.getInstance().toDB( TStatusCode.SRM_SPACE_AVAILABLE)); logWarnings(stmt.getWarnings()); log.trace("PtP CHUNK DAO - " - + "transitSRM_SPACE_AVAILABLEtoSRM_SUCCESS: " + stmt.toString()); + + "transitSRM_SPACE_AVAILABLEtoSRM_SUCCESS: {}", stmt.toString()); int count = stmt.executeUpdate(); logWarnings(stmt.getWarnings()); @@ -793,13 +775,12 @@ public synchronized void transitSRM_SPACE_AVAILABLEtoSRM_SUCCESS( log.trace("PtPChunkDAO! No chunk of PtP request was " + "transited from SRM_SPACE_AVAILABLE to SRM_SUCCESS."); } else { - log.info("PtPChunkDAO! " + count - + " chunks of PtP requests were transited " - + "from SRM_SPACE_AVAILABLE to SRM_SUCCESS."); + log.info("PtPChunkDAO! {} chunks of PtP requests were transited " + + "from SRM_SPACE_AVAILABLE to SRM_SUCCESS.", count); } } catch (SQLException e) { log.error("PtPChunkDAO! Unable to transit chunks from " - + "SRM_SPACE_AVAILABLE to SRM_SUCCESS! " + e); + + "SRM_SPACE_AVAILABLE to SRM_SUCCESS! {}", e.getMessage(), e); } finally { close(stmt); } @@ -835,10 +816,7 @@ public synchronized void transitSRM_SPACE_AVAILABLEtoSRM_ABORTED( stmt.setString(2, explanation); logWarnings(stmt.getWarnings()); - stmt - .setInt( - 3, - StatusCodeConverter.getInstance().toDB( + stmt.setInt(3, StatusCodeConverter.getInstance().toDB( TStatusCode.SRM_SPACE_AVAILABLE)); logWarnings(stmt.getWarnings()); @@ -849,20 +827,20 @@ public synchronized void transitSRM_SPACE_AVAILABLEtoSRM_ABORTED( logWarnings(stmt.getWarnings()); log.trace("PtP CHUNK DAO - " - + "transitSRM_SPACE_AVAILABLEtoSRM_ABORTED: " + stmt.toString()); + + "transitSRM_SPACE_AVAILABLEtoSRM_ABORTED: {}", stmt.toString()); int count = stmt.executeUpdate(); logWarnings(stmt.getWarnings()); if (count > 0) { - log.info("PtP CHUNK DAO! " + count + " chunks were transited from " - + "SRM_SPACE_AVAILABLE to SRM_ABORTED."); + log.info("PtP CHUNK DAO! {} chunks were transited from " + + "SRM_SPACE_AVAILABLE to SRM_ABORTED.", count); } else { log.trace("PtP CHUNK DAO! No chunks " + "were transited from SRM_SPACE_AVAILABLE to SRM_ABORTED."); } } catch (SQLException e) { log.error("PtP CHUNK DAO! Unable to " - + "transitSRM_SPACE_AVAILABLEtoSRM_ABORTED! " + e); + + "transitSRM_SPACE_AVAILABLEtoSRM_ABORTED! {}", e.getMessage(), e); } finally { close(stmt); } @@ -877,8 +855,8 @@ private void close(Statement stmt) { try { stmt.close(); } catch (Exception e) { - log.error("PTP CHUNK DAO! Unable to close Statement " + stmt.toString() - + " - Exception: " + e); + log.error("PTP CHUNK DAO! Unable to close Statement {} - Error: {}", + stmt.toString(), e.getMessage(), e); } } } @@ -892,7 +870,8 @@ private void close(ResultSet rset) { try { rset.close(); } catch (Exception e) { - log.error("PTP CHUNK DAO! Unable to close ResultSet! Exception: " + e); + log.error("PTP CHUNK DAO! Unable to close ResultSet! Error: {}", + e.getMessage(), e); } } } @@ -903,9 +882,9 @@ private void close(ResultSet rset) { private void logWarnings(SQLWarning w) { if (w != null) { - log.debug("PTP CHUNK DAO: " + w.toString()); + log.debug("PTP CHUNK DAO: {}", w.toString()); while ((w = w.getNextWarning()) != null) { - log.debug("PTP CHUNK DAO: " + w.toString()); + log.debug("PTP CHUNK DAO: {}", w.toString()); } } } @@ -927,25 +906,6 @@ private String makeWhereString(List rowids) { return sb.toString(); } - // /** - // * Method that returns a String containing all IDs. - // */ - // private String makeWhereString(long[] rowids) { - // - // StringBuffer sb = new StringBuffer("("); - // int n = rowids.length; - // for(int i = 0; i < n; i++) - // { - // sb.append(rowids[i]); - // if(i < (n - 1)) - // { - // sb.append(","); - // } - // } - // sb.append(")"); - // return sb.toString(); - // } - /** * Auxiliary method that sets up the conenction to the DB. */ @@ -962,9 +922,11 @@ private boolean setUpConnection() { response = con.isValid(0); } } catch (ClassNotFoundException e) { - log.error("PTP CHUNK DAO! Exception in setUpConenction! " + e); + log.error("PTP CHUNK DAO! Exception in setUpConenction! {}", + e.getMessage(), e); } catch (SQLException e) { - log.error("PTP CHUNK DAO! Exception in setUpConnection! " + e); + log.error("PTP CHUNK DAO! Exception in setUpConnection! {}", + e.getMessage(), e); } return response; } @@ -996,8 +958,8 @@ private void takeDownConnection() { try { con.close(); } catch (SQLException e) { - log.error("PTP CHUNK DAO! Exception in " - + "takeDownConnection method - could not close connection! " + e); + log.error("PTP CHUNK DAO! Exception in takeDownConnection method - " + + "could not close connection! {}", e.getMessage(), e); } } } @@ -1063,19 +1025,19 @@ private void doUpdateStatus(TRequestToken requestToken, int[] surlsUniqueIDs, stmt.setInt(1, StatusCodeConverter.getInstance().toDB(statusCode)); logWarnings(stmt.getWarnings()); - log.trace("PTP CHUNK DAO - updateStatus: " + stmt.toString()); + log.trace("PTP CHUNK DAO - updateStatus: {}", stmt.toString()); int count = stmt.executeUpdate(); logWarnings(stmt.getWarnings()); if (count == 0) { - log.trace("PTP CHUNK DAO! No chunk of PTP request was" + " updated to " - + statusCode + "."); + log.trace("PTP CHUNK DAO! No chunk of PTP request was updated to {}.", + statusCode); } else { - log.info("PTP CHUNK DAO! " + count - + " chunks of PTP requests were updated to " + statusCode + "."); + log.info("PTP CHUNK DAO! {} chunks of PTP requests were updated " + + "to {}.", count, statusCode); } } catch (SQLException e) { - log.error("PTP CHUNK DAO! Unable to updated from to " + statusCode + " !" - + e); + log.error("PTP CHUNK DAO! Unable to updated from to {}! {}", statusCode, + e.getMessage(), e); } finally { close(stmt); } @@ -1175,22 +1137,19 @@ private void doUpdateStatusOnMatchingStatus(TRequestToken requestToken, .setInt(2, StatusCodeConverter.getInstance().toDB(expectedStatusCode)); logWarnings(stmt.getWarnings()); - log.trace("PTP CHUNK DAO - updateStatusOnMatchingStatus: " - + stmt.toString()); + log.trace("PTP CHUNK DAO - updateStatusOnMatchingStatus: {}", stmt.toString()); int count = stmt.executeUpdate(); logWarnings(stmt.getWarnings()); if (count == 0) { - log.trace("PTP CHUNK DAO! No chunk of PTP request was" - + " updated from " + expectedStatusCode + " to " + newStatusCode - + "."); + log.trace("PTP CHUNK DAO! No chunk of PTP request was updated " + + "from {} to {}.", expectedStatusCode, newStatusCode); } else { - log.debug("PTP CHUNK DAO! " + count - + " chunks of PTP requests were updated from " + expectedStatusCode - + " to " + newStatusCode + "."); + log.debug("PTP CHUNK DAO! {} chunks of PTP requests were updated " + + "from {} to {}.", count, expectedStatusCode, newStatusCode); } } catch (SQLException e) { - log.error("PTP CHUNK DAO! Unable to updated from " + expectedStatusCode - + " to " + newStatusCode + " !" + e); + log.error("PTP CHUNK DAO! Unable to updated from {} to {}! Error: {}", + expectedStatusCode, newStatusCode, e.getMessage(), e); } finally { close(stmt); } @@ -1238,7 +1197,6 @@ private synchronized Collection find(int[] surlsUniqueIDs, PreparedStatement find = null; ResultSet rs = null; try { - // TODO MICHELE USER_SURL get new fields // get chunks of the request String str = "SELECT rq.ID, rq.r_token, rq.config_FileStorageTypeID, rq.config_OverwriteID, rq.timeStamp, rq.pinLifetime, rq.fileLifetime, " + "rq.s_token, rq.client_dn, rq.proxy, rp.ID, rp.targetSURL, rp.expectedFileSize, rp.normalized_targetSURL_StFN, rp.targetSURL_uniqueID, " @@ -1259,7 +1217,7 @@ private synchronized Collection find(int[] surlsUniqueIDs, List list = new ArrayList(); - log.trace("PtP CHUNK DAO - find method: " + find.toString()); + log.trace("PtP CHUNK DAO - find method: {}", find.toString()); rs = find.executeQuery(); logWarnings(find.getWarnings()); PtPChunkDataTO chunkDataTO = null; @@ -1289,7 +1247,6 @@ private synchronized Collection find(int[] surlsUniqueIDs, chunkDataTO.setPrimaryKey(rs.getLong("rp.ID")); chunkDataTO.setToSURL(rs.getString("rp.targetSURL")); - // TODO MICHELE USER_SURL fill new fields chunkDataTO.setNormalizedStFN(rs .getString("rp.normalized_targetSURL_StFN")); int uniqueID = rs.getInt("rp.targetSURL_uniqueID"); @@ -1304,7 +1261,7 @@ private synchronized Collection find(int[] surlsUniqueIDs, } return list; } catch (SQLException e) { - log.error("PTP CHUNK DAO: " + e); + log.error("PTP CHUNK DAO: {}", e.getMessage(), e); /* return empty Collection! */ return new ArrayList(); } finally { @@ -1333,7 +1290,7 @@ public synchronized List findProtocols(long requestQueueId) { find.setLong(1, requestQueueId); logWarnings(find.getWarnings()); - log.trace("PtP CHUNK DAO - findProtocols method: " + find.toString()); + log.trace("PtP CHUNK DAO - findProtocols method: {}", find.toString()); rs = find.executeQuery(); logWarnings(find.getWarnings()); @@ -1343,7 +1300,7 @@ public synchronized List findProtocols(long requestQueueId) { return protocols; } catch (SQLException e) { - log.error("PTP CHUNK DAO: " + e); + log.error("PTP CHUNK DAO: {}", e.getMessage(), e); /* return empty Collection! */ return new ArrayList(); } finally { @@ -1401,7 +1358,7 @@ private String makeSurlString(String[] surls) { requestedSURL = SURL.makeSURLfromString(surls[i]); } catch (NamespaceException e) { log.error(e.getMessage()); - log.debug("Skip '" + surls[i] + "' during query creation"); + log.debug("Skip '{}' during query creation", surls[i]); continue; } diff --git a/src/main/java/it/grid/storm/catalogs/PtPChunkDataTO.java b/src/main/java/it/grid/storm/catalogs/PtPChunkDataTO.java index 8d59f211..6a06c64a 100644 --- a/src/main/java/it/grid/storm/catalogs/PtPChunkDataTO.java +++ b/src/main/java/it/grid/storm/catalogs/PtPChunkDataTO.java @@ -48,7 +48,6 @@ public class PtPChunkDataTO { private long primaryKey = -1; // ID primary key of status_Put record in DB private String toSURL = " "; private long expectedFileSize = 0; - // TODO MICHELE USER_SURL added new fields private String normalizedStFN = null; private Integer surlUniqueID = null; /* Database table request_Get fields END */ diff --git a/src/main/java/it/grid/storm/catalogs/PtPPersistentChunkData.java b/src/main/java/it/grid/storm/catalogs/PtPPersistentChunkData.java index 93f05212..beee449d 100644 --- a/src/main/java/it/grid/storm/catalogs/PtPPersistentChunkData.java +++ b/src/main/java/it/grid/storm/catalogs/PtPPersistentChunkData.java @@ -12,6 +12,8 @@ package it.grid.storm.catalogs; import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import it.grid.storm.common.types.TURLPrefix; import it.grid.storm.griduser.GridUserInterface; import it.grid.storm.srm.types.TFileStorageType; @@ -40,6 +42,9 @@ public class PtPPersistentChunkData extends IdentityPtPData implements PersistentChunkData { + private static final Logger log = LoggerFactory + .getLogger(PtPPersistentChunkData.class); + /** * long representing the primary key for the persistence layer, in the * status_Put table @@ -66,6 +71,7 @@ public PtPPersistentChunkData(GridUserInterface auth, super(auth, toSURL, pinLifetime, fileLifetime, fileStorageType, spaceToken, expectedFileSize, transferProtocols, overwriteOption, status, transferURL); if (requestToken == null) { + log.debug("PtPPersistentChunkData: requestToken is null!"); throw new InvalidPtPPersistentChunkDataAttributesException(requestToken, toSURL, pinLifetime, fileLifetime, fileStorageType, spaceToken, expectedFileSize, transferProtocols, overwriteOption, status, @@ -101,12 +107,6 @@ public TRequestToken getRequestToken() { return requestToken; } - @Override - protected Logger getLog() { - - return PtPPersistentChunkData.log; - } - @Override public long getIdentifier() { diff --git a/src/main/java/it/grid/storm/catalogs/ReducedBoLChunkDataTO.java b/src/main/java/it/grid/storm/catalogs/ReducedBoLChunkDataTO.java index 517c2721..e63ab176 100644 --- a/src/main/java/it/grid/storm/catalogs/ReducedBoLChunkDataTO.java +++ b/src/main/java/it/grid/storm/catalogs/ReducedBoLChunkDataTO.java @@ -32,7 +32,6 @@ public class ReducedBoLChunkDataTO { private long primaryKey = -1; // ID primary key of record in DB private String fromSURL = " "; - // TODO MICHELE USER_SURL added new fields private String normalizedStFN = null; private Integer surlUniqueID = null; diff --git a/src/main/java/it/grid/storm/catalogs/ReducedCopyChunkDataTO.java b/src/main/java/it/grid/storm/catalogs/ReducedCopyChunkDataTO.java index f31fb2cc..8119142c 100644 --- a/src/main/java/it/grid/storm/catalogs/ReducedCopyChunkDataTO.java +++ b/src/main/java/it/grid/storm/catalogs/ReducedCopyChunkDataTO.java @@ -28,7 +28,6 @@ * * @author Michele Dibenedetto */ -// TODO MICHELE USER_SURL new class public class ReducedCopyChunkDataTO { /* Database table request_Get fields BEGIN */ diff --git a/src/main/java/it/grid/storm/catalogs/ReducedPtGChunkDataTO.java b/src/main/java/it/grid/storm/catalogs/ReducedPtGChunkDataTO.java index 4fd15931..6ca444b0 100644 --- a/src/main/java/it/grid/storm/catalogs/ReducedPtGChunkDataTO.java +++ b/src/main/java/it/grid/storm/catalogs/ReducedPtGChunkDataTO.java @@ -32,7 +32,6 @@ public class ReducedPtGChunkDataTO { private long primaryKey = -1; // ID primary key of record in DB private String fromSURL = " "; - // TODO MICHELE USER_SURL added new fields private String normalizedStFN = null; private Integer surlUniqueID = null; diff --git a/src/main/java/it/grid/storm/catalogs/ReducedPtPChunkDataTO.java b/src/main/java/it/grid/storm/catalogs/ReducedPtPChunkDataTO.java index 1b7dce7d..80306a96 100644 --- a/src/main/java/it/grid/storm/catalogs/ReducedPtPChunkDataTO.java +++ b/src/main/java/it/grid/storm/catalogs/ReducedPtPChunkDataTO.java @@ -33,7 +33,6 @@ public class ReducedPtPChunkDataTO { private long primaryKey = -1; // ID primary key of record in DB private String toSURL = " "; - // TODO MICHELE USER_SURL added new fields private String normalizedStFN = null; private Integer surlUniqueID = null; diff --git a/src/main/java/it/grid/storm/catalogs/RequestSummaryCatalog.java b/src/main/java/it/grid/storm/catalogs/RequestSummaryCatalog.java index 6324211f..c342e291 100644 --- a/src/main/java/it/grid/storm/catalogs/RequestSummaryCatalog.java +++ b/src/main/java/it/grid/storm/catalogs/RequestSummaryCatalog.java @@ -126,47 +126,39 @@ public static RequestSummaryCatalog getInstance() { synchronized public Collection fetchNewRequests( int capacity) { - // log.debug("Retrieving a maximum of " + capacity + - // " new requests. (remaining capacity in Crusher Scheduler) "); + List list = new ArrayList(); + Collection c = dao.findNew(capacity); - - if ((c != null) && (!c.isEmpty())) { - log.debug("REQUEST SUMMARY CATALOG: retrieved data " + c); + if (c == null || c.isEmpty()) { + return list; } - List list = new ArrayList(); - if (!c.isEmpty()) { - int fetched = c.size(); - log.debug("REQUEST SUMMARY CATALOG: " + fetched - + " new requests picked up. "); // info - for (RequestSummaryDataTO auxTO : c) { - try { - RequestSummaryData aux = makeOne(auxTO); - if (aux != null) { - RequestSummaryCatalog.log.debug("REQUEST SUMMARY CATALOG; " - + aux.requestToken() + " associated to " + aux.gridUser().getDn() - + " included for processing "); - list.add(aux); - } - } catch (IllegalArgumentException e) { - RequestSummaryCatalog.log - .error("REQUEST SUMMARY CATALOG; Failure performing makeOne operation. IllegalArgumentException: " - + e.getMessage()); - } + int fetched = c.size(); + log.debug("REQUEST SUMMARY CATALOG: {} new requests picked up.", fetched); + for (RequestSummaryDataTO auxTO : c) { + RequestSummaryData aux = null; + try { + aux = makeOne(auxTO); + } catch (IllegalArgumentException e) { + log.error("REQUEST SUMMARY CATALOG: Failure while performing makeOne " + + "operation. IllegalArgumentException: {}", e.getMessage(), e); + continue; } - int ret = list.size(); - if (ret < fetched) { - RequestSummaryCatalog.log.warn("REQUEST SUMMARY CATALOG: including " - + ret - + " requests for processing, since the dropped ones were malformed!"); - } else { - RequestSummaryCatalog.log - .debug("REQUEST SUMMARY CATALOG: including for processing all " + ret - + " requests."); + if (aux != null) { + log.debug("REQUEST SUMMARY CATALOG: {} associated to {} included " + + "for processing", aux.requestToken(), aux.gridUser().getDn()); + list.add(aux); } } + int ret = list.size(); + if (ret < fetched) { + log.warn("REQUEST SUMMARY CATALOG: including {} requests for processing, " + + "since the dropped ones were malformed!", ret); + } else { + log.debug("REQUEST SUMMARY CATALOG: including for processing all {} " + + "requests.", ret); + } if (!list.isEmpty()) { - RequestSummaryCatalog.log.debug("REQUEST SUMMARY CATALOG: returning " - + list + "\n\n"); + log.debug("REQUEST SUMMARY CATALOG: returning {}\n\n", list); } return list; } @@ -187,7 +179,7 @@ private RequestSummaryData makeOne(RequestSummaryDataTO to) sb.append("TRequestType could not be created from its String representation "); sb.append(to.requestType()); sb.append("\n"); - RequestSummaryCatalog.log.warn(sb.toString()); + log.warn(sb.toString()); throw new IllegalArgumentException( "Invalid TRequestType in the provided RequestSummaryDataTO"); } @@ -195,18 +187,14 @@ private RequestSummaryData makeOne(RequestSummaryDataTO to) try { auxrtoken = new TRequestToken(to.requestToken(), to.timestamp()); } catch (InvalidTRequestTokenAttributesException e) { - RequestSummaryCatalog.log - .warn("Unable to create TRequestToken from RequestSummaryDataTO. " - + "InvalidTRequestTokenAttributesException: " + e.getMessage()); + log.warn("Unable to create TRequestToken from RequestSummaryDataTO. " + + "InvalidTRequestTokenAttributesException: {}", e.getMessage()); throw new IllegalArgumentException( "Unable to create TRequestToken from RequestSummaryDataTO."); } GridUserInterface auxgu; try { - // auxgu = loadVomsGridUser(auxClientDN,auxTO.requestToken()); - // //BEWARE!!! NO VOMS ATTRIBUTES ARE LOADED AS OF TODAY!!! - // VOMS attributes workaround auxgu = loadVomsGridUser(to.clientDN(), to.vomsAttributes(), to.requestToken()); } catch (MalformedGridUserException e) { @@ -217,8 +205,7 @@ private RequestSummaryData makeOne(RequestSummaryDataTO to) sb.append(to.vomsAttributes()); sb.append(" and from request token String "); sb.append(to.requestToken()); - RequestSummaryCatalog.log.warn(sb.toString() - + " MalformedGridUserException: " + e.getMessage()); + log.warn("{}. MalformedGridUserException: {}", sb.toString(), e.getMessage()); throw new IllegalArgumentException( "Unable to load Voms Grid User from RequestSummaryDataTO. " + "MalformedGridUserException: " + e.getMessage()); @@ -229,27 +216,23 @@ private RequestSummaryData makeOne(RequestSummaryDataTO to) data.setPrimaryKey(to.primaryKey()); } catch (InvalidRequestSummaryDataAttributesException e) { dao.failRequest(to.primaryKey(), "The request data is malformed!"); - RequestSummaryCatalog.log - .warn("REQUEST SUMMARY CATALOG! Unable to create RequestSummaryData. " - + "InvalidRequestSummaryDataAttributesException: " + e.getMessage()); - RequestSummaryCatalog.log.warn(e.getMessage(), e); + log.warn("REQUEST SUMMARY CATALOG! Unable to create RequestSummaryData. " + + "InvalidRequestSummaryDataAttributesException: {}", e.getMessage(), e); throw new IllegalArgumentException("Unable to reate RequestSummaryData"); } TReturnStatus status = null; if (to.getStatus() != null) { - TStatusCode code = StatusCodeConverter.getInstance().toSTORM( - to.getStatus()); + TStatusCode code = StatusCodeConverter.getInstance().toSTORM(to.getStatus()); if (code == TStatusCode.EMPTY) { - log - .warn("RequestSummaryDataTO retrieved StatusCode was not recognised: " - + to.getStatus()); + log.warn("RequestSummaryDataTO retrieved StatusCode was not " + + "recognised: {}", to.getStatus()); } else { try { status = new TReturnStatus(code, to.getErrstring()); } catch (InvalidTReturnStatusAttributeException e) { - log.warn("Unable to build TReturnStatus from " + code + " " - + to.getErrstring() + ".InvalidTReturnStatusAttributeException : " - + e.getMessage()); + log.warn("Unable to build TReturnStatus from {} {}. " + + "InvalidTReturnStatusAttributeException: {}", code, + to.getErrstring(), e.getMessage()); } } } @@ -287,9 +270,8 @@ private RequestSummaryData makeOne(RequestSummaryDataTO to) private GridUserInterface loadVomsGridUser(String dn, String fqans_string, String rtoken) throws MalformedGridUserException { - RequestSummaryCatalog.log - .debug("REQUEST SUMMARY CATALOG! Received request to create VomsGridUser for " - + dn + " " + rtoken); + log.debug("REQUEST SUMMARY CATALOG! Received request to create VomsGridUser " + + "for {} {}", dn, rtoken); // set up proxy from file, if it exists! String proxyString = null; FQAN[] fqans_vector = null; @@ -308,31 +290,29 @@ private GridUserInterface loadVomsGridUser(String dn, String fqans_string, in.close(); out.close(); proxyString = new String(out.toByteArray()); - RequestSummaryCatalog.log - .debug("REQUEST SUMMARY CATALOG: Loaded proxy file " - + proxyFile.getAbsolutePath() + " for request " + rtoken); - RequestSummaryCatalog.log - .debug("REQUEST SUMMARY CATALOG: proxy content is " + proxyString); + log.debug("REQUEST SUMMARY CATALOG: Loaded proxy file {} for " + + "request {}", proxyFile.getAbsolutePath(), rtoken); + log.debug("REQUEST SUMMARY CATALOG: proxy content is {}", proxyString); } else { - RequestSummaryCatalog.log - .debug("REQUEST SUMMARY CATALOG: No proxy file " - + proxyFile.getAbsolutePath() + " found for request " + rtoken); + log.debug("REQUEST SUMMARY CATALOG: No proxy file {} found for request", + proxyFile.getAbsolutePath(), rtoken); } } catch (FileNotFoundException e) { // This should not happen given the existence test just performed! - RequestSummaryCatalog.log - .error("REQUEST SUMMARY CATALOG! The file containing the proxy was deleted just before reading its content! No proxy has been loaded!"); + log.error("REQUEST SUMMARY CATALOG! The file containing the proxy was " + + "deleted just before reading its content! No proxy has been loaded!", e); } catch (IOException e) { // Some generic IO error occured! - RequestSummaryCatalog.log - .error("REQUEST SUMMARY CATALOG! The file containing the proxy could not be read! No proxy has been loaded! " - + e); + log.error("REQUEST SUMMARY CATALOG! The file containing the proxy could " + + "not be read! No proxy has been loaded! {}", e.getMessage(), e); } catch (Exception e) { // An unexpected error occured: I am including this generic catch // because the underlaying filesystem has ACLs, and I do not know // how exactly Java behaves! - RequestSummaryCatalog.log - .error("REQUEST SUMMARY CATALOG! There was an unexpected error while attempting to read the file containing the proxy! No proxy has been loaded!"); + log.error("REQUEST SUMMARY CATALOG! There was an unexpected error while " + + "attempting to read the file containing the proxy! No proxy has been " + + "loaded!"); + log.error(e.getMessage(), e); } /** @@ -354,59 +334,50 @@ private GridUserInterface loadVomsGridUser(String dn, String fqans_string, fqans_string = null; } - RequestSummaryCatalog.log - .debug("REQUEST SUMMARY CATALOG! Received request to create VomsGridUser for " - + dn + " " + fqans_string + " " + proxyString); + log.debug("REQUEST SUMMARY CATALOG! Received request to create VomsGridUser " + + "for {} {} {}", dn, fqans_string, proxyString); if ((dn != null) && (fqans_vector != null) && (fqans_vector.length > 0) && (proxyString != null)) { // all credentials available! - RequestSummaryCatalog.log - .debug("REQUEST SUMMARY CATALOG! DN, VOMS Attributes, and Proxy certificate found for request " - + rtoken); + log.debug("REQUEST SUMMARY CATALOG! DN, VOMS Attributes, and Proxy " + + "certificate found for request {}", rtoken); GridUserInterface gridUser = null; try { gridUser = GridUserManager.makeVOMSGridUser(dn, proxyString, fqans_vector); } catch (IllegalArgumentException e) { - log - .error("Unexpected error on voms grid user creation. Contact StoRM Support : IllegalArgumentException " - + e.getMessage()); + log.error("Unexpected error on voms grid user creation. " + + "IllegalArgumentException: {}", e.getMessage(), e); } return gridUser; } else if ((dn != null) && (fqans_vector != null && fqans_vector.length > 0) && (proxyString == null)) { // voms credentials without proxy - RequestSummaryCatalog.log - .debug("REQUEST SUMMARY CATALOG! DN and VOMS Attributes found for request " - + rtoken); + log.debug("REQUEST SUMMARY CATALOG! DN and VOMS Attributes found for " + + "request {}", rtoken); GridUserInterface gridUser = null; try { gridUser = GridUserManager.makeVOMSGridUser(dn, fqans_vector); } catch (IllegalArgumentException e) { - log - .error("Unexpected error on voms grid user creation. Contact StoRM Support : IllegalArgumentException " - + e.getMessage()); + log.error("Unexpected error on voms grid user creation. " + + "IllegalArgumentException: {}", e.getMessage(), e); } return gridUser; } else if ((dn != null) && (fqans_string == null) && (proxyString != null)) { // NON-voms credentials with proxy - RequestSummaryCatalog.log - .debug("REQUEST SUMMARY CATALOG! DN and Proxy found for request " - + rtoken); + log.debug("REQUEST SUMMARY CATALOG! DN and Proxy found for request {}", rtoken); return GridUserManager.makeGridUser(dn, proxyString); } else if ((dn != null) && (fqans_string == null) && (proxyString == null)) { // NON-voms credentials without proxy - RequestSummaryCatalog.log - .debug("REQUEST SUMMARY CATALOG! DN only found for request " + rtoken); + log.debug("REQUEST SUMMARY CATALOG! DN only found for request {}", rtoken); return GridUserManager.makeGridUser(dn); } else { // unmanageble combination! - RequestSummaryCatalog.log - .warn("REQUEST SUMMARY CATALOG! Catalog retrieved invalid credentials data for request " - + rtoken); - RequestSummaryCatalog.log.warn("REQUEST SUMMARY CATALOG! proxy=" - + fqans_string + "\n dn=" + dn + "\n attributes=" + fqans_string); + log.warn("REQUEST SUMMARY CATALOG! Catalog retrieved invalid credentials " + + "data for request {}", rtoken); + log.warn("REQUEST SUMMARY CATALOG! proxy={}\n dn={}\n attributes={}", + proxyString, dn, fqans_string); throw new MalformedGridUserException(); } @@ -506,9 +477,9 @@ synchronized public void abortChunksOfRequest(TRequestToken rt, } dao.abortChunksOfRequest(rt.toString(), aux); } catch (ClassCastException e) { - RequestSummaryCatalog.log - .error("REQUEST SUMMARY CATALOG! Unexpected error in abortChunksOfRequest: the supplied Collection did not contain TSURLs! " - + c + e); + log.error("REQUEST SUMMARY CATALOG! Unexpected error in " + + "abortChunksOfRequest: the supplied Collection did not contain " + + "TSURLs! Error: {}", e.getMessage(), e); } } } @@ -532,10 +503,9 @@ synchronized public void abortChunksOfInProgressRequest(TRequestToken rt, } dao.abortChunksOfInProgressRequest(rt.toString(), aux); } catch (ClassCastException e) { - RequestSummaryCatalog.log - .error("REQUEST SUMMARY CATALOG! Unexpected error " - + "in abortChunksOfInProgressRequest: the supplied " - + "Collection did not contain TSURLs! " + tsurls + e); + log.error("REQUEST SUMMARY CATALOG! Unexpected error in " + + "abortChunksOfInProgressRequest: the supplied Collection did not " + + "contain TSURLs! Error: {}", e.getMessage()); } } } @@ -553,19 +523,16 @@ synchronized public RequestSummaryData find(TRequestToken requestToken) try { RequestSummaryData data = makeOne(to); if (data != null) { - RequestSummaryCatalog.log.debug("REQUEST SUMMARY CATALOG; " - + data.requestToken() + " associated to " + data.gridUser().getDn() - + " retrieved"); + log.debug("REQUEST SUMMARY CATALOG: {} associated to {} retrieved", + data.requestToken(), data.gridUser().getDn()); return data; } } catch (IllegalArgumentException e) { - RequestSummaryCatalog.log - .error("REQUEST SUMMARY CATALOG; Failure performing makeOne operation. IllegalArgumentException: " - + e.getMessage()); + log.error("REQUEST SUMMARY CATALOG; Failure performing makeOne operation. " + + "IllegalArgumentException: {}", e.getMessage(), e); } } else { - RequestSummaryCatalog.log.debug("REQUEST SUMMARY CATALOG; " - + requestToken + " token not found"); + log.debug("REQUEST SUMMARY CATALOG: {} token not found", requestToken); } return null; } @@ -620,18 +587,17 @@ synchronized private ArrayList purgeExpiredRequests() { if (nrExpiredTasks > minChunkSize) { // calculate number of chunks with an approximation to the next whole int nrChunks = (int) Math.ceil((double) nrExpiredTasks / garbageChunkSize); - log.debug("Purging the expired requests in " + nrChunks - + " steps (expired requests:" + nrExpiredTasks + ")"); + log.debug("Purging the expired requests in {} steps (expired " + + "requests: {})", nrChunks, nrExpiredTasks); for (int i = 0; i < nrChunks; i++) { expiredRequests.addAll(dao.purgeExpiredRequests()); } - log.info("REQUEST SUMMARY CATALOG; removed from DB < " - + expiredRequests.size() + " > expired requests"); + log.info("REQUEST SUMMARY CATALOG; removed from DB < {} > expired " + + "requests", expiredRequests.size()); } else { // not enough events to remove. Skip the purging phase - log - .debug("Skipping the purging phase of expired requests. (expired requests:" - + nrExpiredTasks + ")"); + log.debug("Skipping the purging phase of expired requests. (expired " + + "requests: {})", nrExpiredTasks); } return expiredRequests; } @@ -639,24 +605,23 @@ synchronized private ArrayList purgeExpiredRequests() { private void removeOrphanProxies(ArrayList expiredRequests) { if (expiredRequests.isEmpty()) { - - } else { - for (String rt : expiredRequests) { - String proxyFileName = Configuration.getInstance().getProxyHome() - + File.separator + rt; - File proxyFile = new File(proxyFileName); - if (proxyFile.exists()) { - boolean deleted = proxyFile.delete(); - if (!deleted) { - RequestSummaryCatalog.log - .error("ERROR IN REQUEST SUMMARY CATALOG! Removal of proxy file " - + proxyFileName + " failed!"); - } else { - RequestSummaryCatalog.log - .info("REQUEST SUMMARY CATALOG: removed proxy file " - + proxyFileName); - } - } + return; + } + + for (String rt : expiredRequests) { + String proxyFileName = Configuration.getInstance().getProxyHome() + + File.separator + rt; + File proxyFile = new File(proxyFileName); + if (!proxyFile.exists()) { + continue; + } + boolean deleted = proxyFile.delete(); + if (deleted) { + log.info("REQUEST SUMMARY CATALOG: removed proxy file {}", + proxyFileName); + } else { + log.error("ERROR IN REQUEST SUMMARY CATALOG! Removal of proxy file {} " + + "failed!", proxyFileName); } } } diff --git a/src/main/java/it/grid/storm/catalogs/RequestSummaryDAO.java b/src/main/java/it/grid/storm/catalogs/RequestSummaryDAO.java index 0fb95549..f92e019f 100644 --- a/src/main/java/it/grid/storm/catalogs/RequestSummaryDAO.java +++ b/src/main/java/it/grid/storm/catalogs/RequestSummaryDAO.java @@ -143,11 +143,8 @@ public Collection findNew(int freeSlot) { howMuch = freeSlot; } - // String query = - // "SELECT ID, config_RequestTypeID, r_token, client_dn FROM request_queue WHERE status="+StatusCodeConverter.getInstance().toDB(TStatusCode.SRM_REQUEST_QUEUED)+" LIMIT "+howMuch; - String query = "SELECT ID, config_RequestTypeID, r_token, timeStamp, client_dn, proxy FROM request_queue WHERE status=?" - + " LIMIT ?"; - // log.debug("REQUEST SUMMARY DAO - findNew: executing "+query); + String query = "SELECT ID, config_RequestTypeID, r_token, timeStamp, " + + "client_dn, proxy FROM request_queue WHERE status=? LIMIT ?"; // get id, request type, request token and client_DN of newly added // requests, which must be in SRM_REQUEST_QUEUED state @@ -165,9 +162,6 @@ public Collection findNew(int freeSlot) { RequestSummaryDataTO aux = null; // RequestSummaryDataTO made from // retrieved row long auxid; // primary key of retrieved row - // String auxreqtype = null; // request type of retrieved row - // String auxreqtok = null; // request token of retrieved row - // String auxdn = null; // dn of retrieved row while (rs.next()) { auxid = rs.getLong("ID"); rowids.add(new Long(auxid)); @@ -208,8 +202,7 @@ public Collection findNew(int freeSlot) { logWarnings(stmt.getWarnings()); stmt.setString(1, "Request handled!"); logWarnings(stmt.getWarnings()); - log - .trace("REQUEST SUMMARY DAO - findNew: executing " + stmt.toString()); + log.trace("REQUEST SUMMARY DAO - findNew: executing {}", stmt.toString()); stmt.executeUpdate(); close(stmt); } @@ -220,19 +213,15 @@ public Collection findNew(int freeSlot) { con.setAutoCommit(true); logWarnings(con.getWarnings()); } catch (SQLException e) { - log - .error("REQUEST SUMMARY DAO - findNew: Unable to complete picking... rolling back! " - + e); - rollback(con); + log.error("REQUEST SUMMARY DAO - findNew: Unable to complete picking. " + + "Error: {}. Rolling back!", e.getMessage(), e); } finally { close(rs); close(stmt); } // return collection of requests if (!list.isEmpty()) { - log.debug("REQUEST SUMMARY DAO - findNew: returning " + list); - } else { - // log.debug("REQUEST SUMMARY DAO - findNew: returning EMPTY LIST"); + log.debug("REQUEST SUMMARY DAO - findNew: returning {}", list); } return list; } @@ -263,13 +252,12 @@ public void failRequest(long index, String explanation) { logWarnings(signal.getWarnings()); signal.setLong(2, index); logWarnings(signal.getWarnings()); - log.trace("REQUEST SUMMARY DAO! failRequest executing: " + signal); + log.trace("REQUEST SUMMARY DAO! failRequest executing: {}", signal); signal.executeUpdate(); logWarnings(signal.getWarnings()); } catch (SQLException e) { - log - .error("REQUEST SUMMARY DAO! Unable to transit request identified by ID " - + index + " to SRM_FAILURE! Exception: " + e.toString()); + log.error("REQUEST SUMMARY DAO! Unable to transit request identified by " + + "ID {} to SRM_FAILURE! Error: {}", index, e.getMessage(), e); } finally { close(signal); } @@ -283,7 +271,6 @@ public void failRequest(long index, String explanation) { * of the global request. In case of any error, nothing gets done and no * exception is thrown, but proper error messagges get logged. */ - // TODO MICHELE USER_SURL debug public void failPtGRequest(long index, String explanation) { if (!checkConnection()) { @@ -314,7 +301,7 @@ public void failPtGRequest(long index, String explanation) { logWarnings(request.getWarnings()); request.setLong(3, index); logWarnings(request.getWarnings()); - log.trace("REQUEST SUMMARY DAO! failPtGRequest executing: " + request); + log.trace("REQUEST SUMMARY DAO! failPtGRequest executing: {}", request); request.executeUpdate(); logWarnings(request.getWarnings()); @@ -328,7 +315,7 @@ public void failPtGRequest(long index, String explanation) { logWarnings(chunk.getWarnings()); chunk.setLong(3, index); logWarnings(chunk.getWarnings()); - log.trace("REQUEST SUMMARY DAO! failPtGRequest executing: " + chunk); + log.trace("REQUEST SUMMARY DAO! failPtGRequest executing: {}", chunk); chunk.executeUpdate(); logWarnings(chunk.getWarnings()); @@ -338,12 +325,9 @@ public void failPtGRequest(long index, String explanation) { con.setAutoCommit(true); logWarnings(con.getWarnings()); } catch (SQLException e) { - log - .error("REQUEST SUMMARY DAO! Unable to transit PtG request identified by ID " - + index - + " to SRM_FAILURE! Exception: " - + e.toString() - + "\nRolling back..."); + log.error("REQUEST SUMMARY DAO! Unable to transit PtG request identified " + + "by ID {} to SRM_FAILURE! Error: {}\nRolling back...", index, + e.getMessage(), e); rollback(con); } finally { close(request); @@ -389,7 +373,7 @@ public void failPtPRequest(long index, String explanation) { logWarnings(request.getWarnings()); request.setLong(3, index); logWarnings(request.getWarnings()); - log.trace("REQUEST SUMMARY DAO! failPtPRequest executing: " + request); + log.trace("REQUEST SUMMARY DAO! failPtPRequest executing: {}", request); request.executeUpdate(); logWarnings(request.getWarnings()); @@ -403,7 +387,7 @@ public void failPtPRequest(long index, String explanation) { logWarnings(chunk.getWarnings()); chunk.setLong(3, index); logWarnings(chunk.getWarnings()); - log.trace("REQUEST SUMMARY DAO! failPtPRequest executing: " + chunk); + log.trace("REQUEST SUMMARY DAO! failPtPRequest executing: {}", chunk); chunk.executeUpdate(); logWarnings(chunk.getWarnings()); @@ -413,12 +397,9 @@ public void failPtPRequest(long index, String explanation) { con.setAutoCommit(true); logWarnings(con.getWarnings()); } catch (SQLException e) { - log - .error("REQUEST SUMMARY DAO! Unable to transit PtP request identified by ID " - + index - + " to SRM_FAILURE! Exception: " - + e.toString() - + "\nRolling back..."); + log.error("REQUEST SUMMARY DAO! Unable to transit PtP request identified " + + "by ID {} to SRM_FAILURE! Error: {}\nRolling back...", index, + e.getMessage(), e); rollback(con); } finally { close(request); @@ -464,7 +445,7 @@ public void failCopyRequest(long index, String explanation) { logWarnings(request.getWarnings()); request.setLong(3, index); logWarnings(request.getWarnings()); - log.trace("REQUEST SUMMARY DAO! failCopyRequest executing: " + request); + log.trace("REQUEST SUMMARY DAO! failCopyRequest executing: {}", request); request.executeUpdate(); logWarnings(request.getWarnings()); @@ -478,7 +459,7 @@ public void failCopyRequest(long index, String explanation) { logWarnings(chunk.getWarnings()); chunk.setLong(3, index); logWarnings(chunk.getWarnings()); - log.trace("REQUEST SUMMARY DAO! failCopyRequest executing: " + chunk); + log.trace("REQUEST SUMMARY DAO! failCopyRequest executing: {}", chunk); chunk.executeUpdate(); logWarnings(chunk.getWarnings()); @@ -488,12 +469,9 @@ public void failCopyRequest(long index, String explanation) { con.setAutoCommit(true); logWarnings(con.getWarnings()); } catch (SQLException e) { - log - .error("REQUEST SUMMARY DAO! Unable to transit Copy request identified by ID " - + index - + " to SRM_FAILURE! Exception: " - + e.toString() - + "\nRolling back..."); + log.error("REQUEST SUMMARY DAO! Unable to transit Copy request identified " + + "by ID {} to SRM_FAILURE! Error: {}\nRolling back...", index, + e.getMessage(), e); rollback(con); } finally { close(request); @@ -525,12 +503,11 @@ public void updateGlobalStatus(String rt, int status, String explanation) { logWarnings(update.getWarnings()); update.setString(3, rt); logWarnings(update.getWarnings()); - log - .trace("REQUEST SUMMARY DAO - updateGlobalStatus: executing " + update); + log.trace("REQUEST SUMMARY DAO - updateGlobalStatus: executing {}", update); update.executeUpdate(); logWarnings(update.getWarnings()); } catch (SQLException e) { - log.error("REQUEST SUMMARY DAO: " + e); + log.error("REQUEST SUMMARY DAO: {}", e.getMessage(), e); } finally { close(update); } @@ -560,13 +537,12 @@ public void updateGlobalStatusOnMatchingGlobalStatus( update.setInt(4, StatusCodeConverter.getInstance().toDB(expectedStatusCode)); logWarnings(update.getWarnings()); - log - .trace("REQUEST SUMMARY DAO - updateGlobalStatusOnMatchingGlobalStatus: executing " - + update); + log.trace("REQUEST SUMMARY DAO - updateGlobalStatusOnMatchingGlobalStatus: " + + "executing {}", update); update.executeUpdate(); logWarnings(update.getWarnings()); } catch (SQLException e) { - log.error("REQUEST SUMMARY DAO: " + e); + log.error("REQUEST SUMMARY DAO: {}", e.getMessage(), e); } finally { close(update); } @@ -583,8 +559,8 @@ public void updateGlobalStatusPinFileLifetime(String rt, int status, String explanation) { if (!checkConnection()) { - log - .error("REQUEST SUMMARY DAO - updateGlobalStatusPinFileLifetime: unable to get a valid connection!"); + log.error("REQUEST SUMMARY DAO - updateGlobalStatusPinFileLifetime: " + + "unable to get a valid connection!"); return; } PreparedStatement update = null; @@ -606,14 +582,13 @@ public void updateGlobalStatusPinFileLifetime(String rt, int status, update.setString(3, rt); logWarnings(update.getWarnings()); - log - .trace("REQUEST SUMMARY DAO - updateGlobalStatus: executing " + update); + log.trace("REQUEST SUMMARY DAO - updateGlobalStatus: executing {}", update); update.executeUpdate(); logWarnings(update.getWarnings()); } catch (SQLException e) { - log.error("REQUEST SUMMARY DAO: " + e); + log.error("REQUEST SUMMARY DAO: {}", e.getMessage(), e); } finally { close(update); } @@ -626,12 +601,10 @@ public void updateGlobalStatusPinFileLifetime(String rt, int status, * token is null, or not found, or not in the SRM_REQUEST_QUEUED state, then * nothing happens. */ - // TODO MICHELE USER_SURL debug public void abortRequest(String rt) { if (!checkConnection()) { - log - .error("REQUEST SUMMARY DAO - abortRequest: unable to get a valid connection!"); + log.error("REQUEST SUMMARY DAO - abortRequest: unable to get a valid connection!"); return; } PreparedStatement update = null; @@ -646,15 +619,12 @@ public void abortRequest(String rt) { query.setInt(2, StatusCodeConverter.getInstance().toDB(TStatusCode.SRM_REQUEST_QUEUED)); logWarnings(query.getWarnings()); - log.trace("REQUEST SUMMARY DAO - abortRequest - " + query); + log.trace("REQUEST SUMMARY DAO - abortRequest - {}", query); rs = query.executeQuery(); logWarnings(query.getWarnings()); if (rs.next()) { - // token found... - // get ID long id = rs.getLong("ID"); String type = rs.getString("config_RequestTypeID"); - // update global request status update = con .prepareStatement("UPDATE request_queue SET status=?, errstring=? WHERE ID=?"); logWarnings(con.getWarnings()); @@ -665,7 +635,7 @@ public void abortRequest(String rt) { logWarnings(update.getWarnings()); update.setLong(3, id); logWarnings(update.getWarnings()); - log.trace("REQUEST SUMMARY DAO - abortRequest - " + update); + log.trace("REQUEST SUMMARY DAO - abortRequest - {}", update); update.executeUpdate(); logWarnings(update.getWarnings()); close(update); @@ -705,16 +675,17 @@ public void abortRequest(String rt) { logWarnings(update.getWarnings()); update.setLong(3, id); logWarnings(update.getWarnings()); - log.trace("REQUEST SUMMARY DAO - abortRequest - " + update); + log.trace("REQUEST SUMMARY DAO - abortRequest - {}", update); update.executeUpdate(); logWarnings(update.getWarnings()); } else { - log - .error("REQUEST SUMMARY DAO - Unable to complete abortRequest: could not update file statuses because the request type could not be translated from the DB!"); + log.error("REQUEST SUMMARY DAO - Unable to complete abortRequest: " + + "could not update file statuses because the request type could " + + "not be translated from the DB!"); } } } catch (SQLException e) { - log.error("REQUEST SUMMARY DAO - abortRequest: " + e); + log.error("REQUEST SUMMARY DAO - abortRequest: {}", e.getMessage(), e); } finally { close(rs); close(query); @@ -729,12 +700,11 @@ public void abortRequest(String rt) { * token is null, or not found, or not in the SRM_REQUEST_INPROGRESS state, * then nothing happens. */ - // TODO MICHELE USER_SURL debug public void abortInProgressRequest(String rt) { if (!checkConnection()) { - log - .error("REQUEST SUMMARY DAO - abortInProgressRequest: unable to get a valid connection!"); + log.error("REQUEST SUMMARY DAO - abortInProgressRequest: unable to get " + + "a valid connection!"); return; } PreparedStatement update = null; @@ -746,12 +716,9 @@ public void abortInProgressRequest(String rt) { logWarnings(con.getWarnings()); query.setString(1, rt); logWarnings(query.getWarnings()); - query.setInt( - 2, - StatusCodeConverter.getInstance().toDB( - TStatusCode.SRM_REQUEST_INPROGRESS)); + query.setInt(2, StatusCodeConverter.getInstance().toDB(TStatusCode.SRM_REQUEST_INPROGRESS)); logWarnings(query.getWarnings()); - log.trace("REQUEST SUMMARY DAO - abortInProgressRequest - " + query); + log.trace("REQUEST SUMMARY DAO - abortInProgressRequest - {}", query); rs = query.executeQuery(); logWarnings(query.getWarnings()); if (rs.next()) { @@ -770,7 +737,7 @@ public void abortInProgressRequest(String rt) { logWarnings(update.getWarnings()); update.setLong(3, id); logWarnings(update.getWarnings()); - log.trace("REQUEST SUMMARY DAO - abortInProgressRequest - " + update); + log.trace("REQUEST SUMMARY DAO - abortInProgressRequest - {}", update); update.executeUpdate(); logWarnings(update.getWarnings()); close(update); @@ -810,16 +777,18 @@ public void abortInProgressRequest(String rt) { logWarnings(update.getWarnings()); update.setLong(3, id); logWarnings(update.getWarnings()); - log.trace("REQUEST SUMMARY DAO - abortInProgressRequest - " + update); + log.trace("REQUEST SUMMARY DAO - abortInProgressRequest - {}", update); update.executeUpdate(); logWarnings(update.getWarnings()); } else { - log - .error("REQUEST SUMMARY DAO - Unable to complete abortInProgressRequest: could not update file statuses because the request type could not be translated from the DB!"); + log.error("REQUEST SUMMARY DAO - Unable to complete " + + "abortInProgressRequest: could not update file statuses because " + + "the request type could not be translated from the DB!"); } } } catch (SQLException e) { - log.error("REQUEST SUMMARY DAO - abortInProgressRequest: " + e); + log.error("REQUEST SUMMARY DAO - abortInProgressRequest: {}", + e.getMessage(), e); } finally { close(rs); close(query); @@ -832,12 +801,11 @@ public void abortInProgressRequest(String rt) { * SRM_REQUEST_QUEUED state, to SRM_ABORTED. If the supplied token is null, or * not found, or not in the SRM_REQUEST_QUEUED state, then nothing happens. */ - // TODO MICHELE USER_SURL debug public void abortChunksOfRequest(String rt, Collection surls) { if (!checkConnection()) { - log - .error("REQUEST SUMMARY DAO - abortChunksOfRequest: unable to get a valid connection!"); + log.error("REQUEST SUMMARY DAO - abortChunksOfRequest: unable to get a " + + "valid connection!"); return; } PreparedStatement update = null; @@ -852,12 +820,10 @@ public void abortChunksOfRequest(String rt, Collection surls) { query.setInt(2, StatusCodeConverter.getInstance().toDB(TStatusCode.SRM_REQUEST_QUEUED)); logWarnings(query.getWarnings()); - log.trace("REQUEST SUMMARY DAO - abortChunksOfRequest - " + query); + log.trace("REQUEST SUMMARY DAO - abortChunksOfRequest - {}", query); rs = query.executeQuery(); logWarnings(query.getWarnings()); if (rs.next()) { - // token found... - // get ID long id = rs.getLong("ID"); String type = rs.getString("config_RequestTypeID"); // update single chunk file statuses @@ -902,16 +868,18 @@ public void abortChunksOfRequest(String rt, Collection surls) { logWarnings(update.getWarnings()); update.setLong(3, id); logWarnings(update.getWarnings()); - log.trace("REQUEST SUMMARY DAO - abortChunksOfRequest - " + update); + log.trace("REQUEST SUMMARY DAO - abortChunksOfRequest - {}", update); update.executeUpdate(); logWarnings(update.getWarnings()); } else { - log - .error("REQUEST SUMMARY DAO - Unable to complete abortChunksOfRequest: could not update file statuses because the request type could not be translated from the DB!"); + log.error("REQUEST SUMMARY DAO - Unable to complete " + + "abortChunksOfRequest: could not update file statuses because " + + "the request type could not be translated from the DB!"); } } } catch (SQLException e) { - log.error("REQUEST SUMMARY DAO - abortChunksOfRequest: " + e); + log.error("REQUEST SUMMARY DAO - abortChunksOfRequest: {}", + e.getMessage(), e); } finally { close(rs); close(query); @@ -925,12 +893,11 @@ public void abortChunksOfRequest(String rt, Collection surls) { * null, or not found, or not in the SRM_REQUEST_INPROGRESS state, then * nothing happens. */ - // TODO MICHELE USER_SURL debug public void abortChunksOfInProgressRequest(String rt, Collection surls) { if (!checkConnection()) { - log - .error("REQUEST SUMMARY DAO - abortChunksOfInProgressRequest: unable to get a valid connection!"); + log.error("REQUEST SUMMARY DAO - abortChunksOfInProgressRequest: unable " + + "to get a valid connection!"); return; } PreparedStatement update = null; @@ -942,18 +909,12 @@ public void abortChunksOfInProgressRequest(String rt, Collection surls) logWarnings(con.getWarnings()); query.setString(1, rt); logWarnings(query.getWarnings()); - query.setInt( - 2, - StatusCodeConverter.getInstance().toDB( - TStatusCode.SRM_REQUEST_INPROGRESS)); + query.setInt(2, StatusCodeConverter.getInstance().toDB(TStatusCode.SRM_REQUEST_INPROGRESS)); logWarnings(query.getWarnings()); - log.trace("REQUEST SUMMARY DAO - abortChunksOfInProgressRequest - " - + query); + log.trace("REQUEST SUMMARY DAO - abortChunksOfInProgressRequest - {}", query); rs = query.executeQuery(); logWarnings(query.getWarnings()); if (rs.next()) { - // token found... - // get ID long id = rs.getLong("ID"); String type = rs.getString("config_RequestTypeID"); // update single chunk file statuses @@ -998,17 +959,19 @@ public void abortChunksOfInProgressRequest(String rt, Collection surls) logWarnings(update.getWarnings()); update.setLong(3, id); logWarnings(update.getWarnings()); - log.trace("REQUEST SUMMARY DAO - abortChunksOfInProgressRequest - " - + update); + log.trace("REQUEST SUMMARY DAO - abortChunksOfInProgressRequest " + + "- {}", update); update.executeUpdate(); logWarnings(update.getWarnings()); } else { - log - .error("REQUEST SUMMARY DAO - Unable to complete abortChunksOfInProgressRequest: could not update file statuses because the request type could not be translated from the DB!"); + log.error("REQUEST SUMMARY DAO - Unable to complete " + + "abortChunksOfInProgressRequest: could not update file statuses " + + "because the request type could not be translated from the DB!"); } } } catch (SQLException e) { - log.error("REQUEST SUMMARY DAO - abortChunksOfInProgressRequest: " + e); + log.error("REQUEST SUMMARY DAO - abortChunksOfInProgressRequest: {}", + e.getMessage(), e); } finally { close(rs); close(query); @@ -1044,8 +1007,7 @@ public String typeOf(String rt) { ResultSet rs = null; String result = ""; if (!checkConnection()) { - log - .error("REQUEST SUMMARY DAO - typeOf: unable to get a valid connection!"); + log.error("REQUEST SUMMARY DAO - typeOf: unable to get a valid connection!"); return result; } try { @@ -1054,14 +1016,14 @@ public String typeOf(String rt) { logWarnings(con.getWarnings()); query.setString(1, rt); logWarnings(query.getWarnings()); - log.trace("REQUEST SUMMARY DAO - typeOf - " + query); + log.trace("REQUEST SUMMARY DAO - typeOf - {}", query); rs = query.executeQuery(); logWarnings(query.getWarnings()); if (rs.next()) { result = rs.getString("config_RequestTypeID"); } } catch (SQLException e) { - log.error("REQUEST SUMMARY DAO - typeOf - " + e); + log.error("REQUEST SUMMARY DAO - typeOf - {}", e.getMessage(), e); } finally { close(rs); close(query); @@ -1080,8 +1042,7 @@ public RequestSummaryDataTO find(String rt) { ResultSet rs = null; RequestSummaryDataTO to = null; if (!checkConnection()) { - log - .error("REQUEST SUMMARY DAO - find: unable to get a valid connection!"); + log.error("REQUEST SUMMARY DAO - find: unable to get a valid connection!"); return null; } try { @@ -1094,7 +1055,7 @@ public RequestSummaryDataTO find(String rt) { rs = query.executeQuery(); logWarnings(query.getWarnings()); if (!rs.first()) { - log.debug("No requests found with token " + rt); + log.debug("No requests found with token {}", rt); return null; } to = new RequestSummaryDataTO(); @@ -1131,12 +1092,12 @@ public RequestSummaryDataTO find(String rt) { to.setRemainingDeferredStartTime(rs.getInt("remainingDeferredStartTime")); if (rs.next()) { - log.warn("More than a row matches token " + rt); + log.warn("More than a row matches token {}", rt); } close(rs); close(query); } catch (SQLException e) { - log.error("REQUEST SUMMARY DAO - find - " + e); + log.error("REQUEST SUMMARY DAO - find - {}", e.getMessage(), e); } finally { close(rs); close(query); @@ -1155,7 +1116,6 @@ public RequestSummaryDataTO find(String rt) { * Notice that in case of errors only error messages get logged. An empty List * is also returned. */ - // TODO MICHELE USER_SURL debug public List purgeExpiredRequests() { PreparedStatement ps = null; @@ -1163,8 +1123,8 @@ public List purgeExpiredRequests() { List requestTokens = new ArrayList(); List ids = new ArrayList(); if (!checkConnection()) { - log - .error("REQUEST SUMMARY DAO - purgeExpiredRequests: unable to get a valid connection!"); + log.error("REQUEST SUMMARY DAO - purgeExpiredRequests: unable to get a " + + "valid connection!"); return requestTokens; } try { @@ -1184,7 +1144,7 @@ public List purgeExpiredRequests() { ps = con.prepareStatement(stmt); logWarnings(con.getWarnings()); - log.trace("REQUEST SUMMARY DAO - purgeExpiredRequests - " + ps); + log.trace("REQUEST SUMMARY DAO - purgeExpiredRequests - {}", ps); rs = ps.executeQuery(); logWarnings(ps.getWarnings()); @@ -1203,42 +1163,19 @@ public List purgeExpiredRequests() { ps = con.prepareStatement(stmt); logWarnings(con.getWarnings()); - log.trace("REQUEST SUMMARY DAO - purgeExpiredRequests - " + stmt); + log.trace("REQUEST SUMMARY DAO - purgeExpiredRequests - {}", stmt); int deleted = ps.executeUpdate(); logWarnings(ps.getWarnings()); if (deleted > 0) { - log.info("REQUEST SUMMARY DAO - purgeExpiredRequests - Deleted " - + deleted + " expired requests."); + log.info("REQUEST SUMMARY DAO - purgeExpiredRequests - Deleted {} " + + "expired requests.", deleted); } else { - log - .trace("REQUEST SUMMARY DAO - purgeExpiredRequests - No deleted expired requests."); + log.trace("REQUEST SUMMARY DAO - purgeExpiredRequests - No deleted " + + "expired requests."); } close(ps); - // REMOVE ORPHANED DIR OPTION - - // WARNING!! The subquery "WHERE ID NOT IN ..." does not work - // for more than 1000 entries - // for a bug of MySQL, fixed in 5.1 - // http://forums.mysql.com/read.php?121,143298,201486 - // Change using left inner join - - // stmt = - // "DELETE FROM request_DirOption "+ - // " WHERE ID NOT IN (SELECT DISTINCT request_DirOptionID FROM request_Get) "+ - // " AND ID NOT IN (SELECT DISTINCT request_DirOptionID FROM request_BoL) "+ - // " AND ID NOT IN (SELECT DISTINCT request_DirOptionID FROM request_Copy)"; - - // QUERY : DELETE request_DirOption from request_DirOption left - // JOIN request_Get ON request_DirOption.ID = - // request_Get.request_DirOptionID LEFT JOIN request_BoL ON - // request_DirOption.ID = request_BoL.request_DirOptionID LEFT - // JOIN request_Copy ON request_DirOption.ID = - // request_Copy.request_DirOptionID where - // request_Copy.request_DirOptionID IS NULL AND - // request_Get.request_DirOptionID IS NULL AND - // request_BoL.request_DirOptionID IS NULL ; stmt = "DELETE request_DirOption FROM request_DirOption " + " LEFT JOIN request_Get ON request_DirOption.ID = request_Get.request_DirOptionID" @@ -1250,16 +1187,16 @@ public List purgeExpiredRequests() { ps = con.prepareStatement(stmt); logWarnings(con.getWarnings()); - log.trace("REQUEST SUMMARY DAO - purgeExpiredRequests - " + stmt); + log.trace("REQUEST SUMMARY DAO - purgeExpiredRequests - {}", stmt); deleted = ps.executeUpdate(); logWarnings(ps.getWarnings()); if (deleted > 0) { - log.info("REQUEST SUMMARY DAO - purgeExpiredRequests - Deleted " - + deleted + " DirOption related to expired requests."); + log.info("REQUEST SUMMARY DAO - purgeExpiredRequests - Deleted {} " + + "DirOption related to expired requests.", deleted); } else { - log - .trace("REQUEST SUMMARY DAO - purgeExpiredRequests - No Deleted DirOption related to expired requests."); + log.trace("REQUEST SUMMARY DAO - purgeExpiredRequests - No Deleted " + + "DirOption related to expired requests."); } close(ps); @@ -1270,9 +1207,8 @@ public List purgeExpiredRequests() { con.setAutoCommit(true); logWarnings(con.getWarnings()); } catch (SQLException e) { - log - .error("REQUEST SUMMARY DAO - purgeExpiredRequests - Rolling back because of error: " - + e); + log.error("REQUEST SUMMARY DAO - purgeExpiredRequests - Rolling back " + + "because of error: {}", e.getMessage(), e); rollback(con); } finally { close(rs); @@ -1291,8 +1227,8 @@ public int getNumberExpired() { int rowCount = 0; if (!checkConnection()) { - log - .error("REQUEST SUMMARY DAO - getNumberExpired: unable to get a valid connection!"); + log.error("REQUEST SUMMARY DAO - getNumberExpired: unable to get a " + + "valid connection!"); return 0; } @@ -1315,21 +1251,20 @@ public int getNumberExpired() { ps = con.prepareStatement(stmt); logWarnings(con.getWarnings()); - log.trace("REQUEST SUMMARY DAO - Number of expired requests: " + ps); + log.trace("REQUEST SUMMARY DAO - Number of expired requests: {}", ps); rs = ps.executeQuery(); logWarnings(ps.getWarnings()); // Get the number of rows from the result set rs.next(); rowCount = rs.getInt(1); - log.debug("Nr of expired requests is: " + rowCount); + log.debug("Nr of expired requests is: {}", rowCount); close(rs); close(ps); } catch (SQLException e) { - log - .error("REQUEST SUMMARY DAO - purgeExpiredRequests - Rolling back because of error: " - + e); + log.error("REQUEST SUMMARY DAO - purgeExpiredRequests - Rolling back " + + "because of error: {}", e.getMessage(), e); rollback(con); } finally { close(rs); @@ -1368,16 +1303,17 @@ private boolean setUpConnection() { Class.forName(driver); con = DriverManager.getConnection(url, name, password); if (con == null) { - log - .error("REQUEST SUMMARY DAO! DriverManager returned null connection!"); + log.error("REQUEST SUMMARY DAO! DriverManager returned null connection!"); } else { logWarnings(con.getWarnings()); response = con.isValid(0); } } catch (ClassNotFoundException e) { - log.error("REQUEST SUMMARY DAO! Exception in setUpConnection! " + e); + log.error("REQUEST SUMMARY DAO! Exception in setUpConnection! {}", + e.getMessage(), e); } catch (SQLException e) { - log.error("REQUEST SUMMARY DAO! Exception in setUpConnection! " + e); + log.error("REQUEST SUMMARY DAO! Exception in setUpConnection! {}", + e.getMessage(), e); } return response; } @@ -1391,9 +1327,8 @@ private void takeDownConnection() { try { con.close(); } catch (SQLException e) { - log - .error("REQUEST SUMMARY DAO! Exception in takeDownConnection method: " - + e); + log.error("REQUEST SUMMARY DAO! Exception in takeDownConnection " + + "method: {}", e.getMessage(), e); } } } @@ -1424,8 +1359,8 @@ private void close(Statement stmt) { try { stmt.close(); } catch (Exception e) { - log.error("REQUEST SUMMARY DAO! Unable to close Statement " - + stmt.toString() + " - Exception: " + e); + log.error("REQUEST SUMMARY DAO! Unable to close Statement {} - " + + "Error: {}", stmt.toString(), e.getMessage(), e); } } } @@ -1439,8 +1374,8 @@ private void close(ResultSet rset) { try { rset.close(); } catch (Exception e) { - log.error("REQUEST SUMMARY DAO! Unable to close ResultSet! Exception: " - + e); + log.error("REQUEST SUMMARY DAO! Unable to close ResultSet! Error: {}", + e.getMessage(), e); } } } @@ -1456,7 +1391,7 @@ private void rollback(Connection con) { logWarnings(con.getWarnings()); log.error("PICKER2: roll back successful!"); } catch (SQLException e2) { - log.error("PICKER2: roll back failed! " + e2); + log.error("PICKER2: roll back failed! {}", e2.getMessage(), e2); } } } @@ -1467,9 +1402,9 @@ private void rollback(Connection con) { private void logWarnings(SQLWarning warning) { if (warning != null) { - log.debug("REQUEST SUMMARY DAO: " + warning.toString()); + log.debug("REQUEST SUMMARY DAO: {}", warning.toString()); while ((warning = warning.getNextWarning()) != null) { - log.debug("REQUEST SUMMARY DAO: " + warning.toString()); + log.debug("REQUEST SUMMARY DAO: {}", warning.toString()); } } } diff --git a/src/main/java/it/grid/storm/catalogs/ReservedSpaceCatalog.java b/src/main/java/it/grid/storm/catalogs/ReservedSpaceCatalog.java index 61c21964..96bc21e3 100644 --- a/src/main/java/it/grid/storm/catalogs/ReservedSpaceCatalog.java +++ b/src/main/java/it/grid/storm/catalogs/ReservedSpaceCatalog.java @@ -110,7 +110,7 @@ public static Date getUpdateTime(TSpaceToken token) { */ public ReservedSpaceCatalog() { - ReservedSpaceCatalog.log.debug("Building Reserve Space Catalog..."); + log.debug("Building Reserve Space Catalog..."); // Binding to the persistence component daoFactory = PersistenceDirector.getDAOFactory(); } @@ -137,15 +137,14 @@ public StorageSpaceData getStorageSpace(TSpaceToken spaceToken) try { result = new StorageSpaceData(ssTO); } catch (IllegalArgumentException e) { - log - .error("Error building StorageSpaceData from StorageSpaceTO IllegalArgumentException: " - + e.getLocalizedMessage()); + log.error("Error building StorageSpaceData from StorageSpaceTO " + + "IllegalArgumentException: {}", e.getLocalizedMessage(), e); throw new TransferObjectDecodingException( - "Unable to build StorageSpaceData " + "from StorageSpaceTO"); + "Unable to build StorageSpaceData from StorageSpaceTO"); } } else { - log - .info("Unable to build StorageSpaceData. No StorageSpaceTO built from the DB"); + log.info("Unable to build StorageSpaceData. No StorageSpaceTO built " + + "from the DB"); } return result; } @@ -190,9 +189,9 @@ public void updateStorageSpace(StorageSpaceData ssd, Date updateTime) { try { ssDAO = daoFactory.getStorageSpaceDAO(); - ReservedSpaceCatalog.log.debug("Storage Space DAO retrieved."); + log.debug("Storage Space DAO retrieved."); } catch (DataAccessException daEx) { - ReservedSpaceCatalog.log.error("Error while retrieving StorageSpaceDAO.", + log.error("Error while retrieving StorageSpaceDAO: {}", daEx.getMessage(), daEx); } @@ -207,9 +206,9 @@ public void updateStorageSpace(StorageSpaceData ssd, Date updateTime) { } try { ssDAO.updateStorageSpace(ssTO); - ReservedSpaceCatalog.log.debug("StorageSpaceTO updated in Persistence"); + log.debug("StorageSpaceTO updated in Persistence"); } catch (DataAccessException daEx) { - ReservedSpaceCatalog.log.error( + log.error( "Error while inserting new row in StorageSpace", daEx); } @@ -222,12 +221,12 @@ public void updateStorageSpaceFreeSpace(StorageSpaceData ssd) throws DataAccessException { ssDAO = daoFactory.getStorageSpaceDAO(); - ReservedSpaceCatalog.log.debug("Storage Space DAO retrieved."); + log.debug("Storage Space DAO retrieved."); StorageSpaceTO ssTO = new StorageSpaceTO(ssd); log.debug("Storage Space TO Created"); ssTO.setUpdateTime(new Date()); ssDAO.updateStorageSpaceFreeSpace(ssTO); - ReservedSpaceCatalog.log.debug("StorageSpaceTO updated in Persistence"); + log.debug("StorageSpaceTO updated in Persistence"); } @@ -271,7 +270,8 @@ public void updateAllStorageSpace(StorageSpaceData ssd, Date updateTime) ssDAO = daoFactory.getStorageSpaceDAO(); log.debug("Storage Space DAO retrieved."); } catch (DataAccessException daEx) { - log.error("Error while retrieving StorageSpaceDAO.", daEx); + log.error("Error while retrieving StorageSpaceDAO: {}", daEx.getMessage(), + daEx); } // Add the row to the persistence.. @@ -279,7 +279,8 @@ public void updateAllStorageSpace(StorageSpaceData ssd, Date updateTime) ssDAO.updateAllStorageSpace(ssTO); log.debug("StorageSpaceTO updated in Persistence"); } catch (DataAccessException daEx) { - log.error("Error while inserting new row in StorageSpace", daEx); + log.error("Error while inserting new row in StorageSpace: {}", + daEx.getMessage(), daEx); } } @@ -297,7 +298,8 @@ public StorageSpaceData getStorageSpaceByAlias(String desc) { ssDAO = daoFactory.getStorageSpaceDAO(); log.debug("Storage Space DAO retrieved."); } catch (DataAccessException daEx) { - log.debug("Error while retrieving StorageSpaceDAO.", daEx); + log.debug("Error while retrieving StorageSpaceDAO: {}", daEx.getMessage(), + daEx); } // Get StorageSpaceTO form persistence @@ -309,13 +311,13 @@ public StorageSpaceData getStorageSpaceByAlias(String desc) { try { result = new StorageSpaceData(cl.toArray(new StorageSpaceTO[0])[0]); } catch (IllegalArgumentException e) { - log - .error("unable to build StorageSpaceData from StorageSpaceTO IllegalArgumentException: " - + e.getLocalizedMessage()); + log.error("unable to build StorageSpaceData from StorageSpaceTO " + + "IllegalArgumentException: {}", e.getMessage(), e); } } } catch (DataAccessException daEx) { - log.debug("Error while retrieving StorageSpace", daEx); + log.debug("Error while retrieving StorageSpace: {}", daEx.getMessage(), + daEx); } return result; @@ -337,7 +339,8 @@ public List getStorageSpaceNotInitialized() { ssDAO = daoFactory.getStorageSpaceDAO(); log.debug("Storage Space DAO retrieved."); } catch (DataAccessException daEx) { - log.debug("Error while retrieving StorageSpaceDAO.", daEx); + log.debug("Error while retrieving StorageSpaceDAO: {}", daEx.getMessage(), + daEx); } // Get StorageSpaceTO form persistence try { @@ -349,13 +352,12 @@ public List getStorageSpaceNotInitialized() { try { result.add(new StorageSpaceData(storagesSpaceTO)); } catch (IllegalArgumentException e) { - log - .error("unable to build StorageSpaceData from StorageSpaceTO IllegalArgumentException: " - + e.getLocalizedMessage()); + log.error("unable to build StorageSpaceData from StorageSpaceTO. " + + "IllegalArgumentException: {}", e.getMessage(), e); } } else { - log - .warn("Received a collection of StorageSpaceTO containing null elements, skipping them"); + log.warn("Received a collection of StorageSpaceTO containing null " + + "elements, skipping them"); } } } catch (DataAccessException daEx) { @@ -381,7 +383,8 @@ public List getStorageSpaceByLastUpdate( ssDAO = daoFactory.getStorageSpaceDAO(); log.debug("Storage Space DAO retrieved."); } catch (DataAccessException daEx) { - log.debug("Error while retrieving StorageSpaceDAO.", daEx); + log.debug("Error while retrieving StorageSpaceDAO: {}", daEx.getMessage(), + daEx); } // GetStorageSpaceTO form persistence try { @@ -393,17 +396,17 @@ public List getStorageSpaceByLastUpdate( try { result.add(new StorageSpaceData(storagesSpaceTO)); } catch (IllegalArgumentException e) { - log - .error("unable to build StorageSpaceData from StorageSpaceTO IllegalArgumentException: " - + e.getLocalizedMessage()); + log.error("unable to build StorageSpaceData from StorageSpaceTO " + + "IllegalArgumentException: {}", e.getMessage(), e); } } else { - log - .warn("Received a collection of StorageSpaceTO containing null elements, skipping them"); + log.warn("Received a collection of StorageSpaceTO containing null " + + "elements, skipping them"); } } } catch (DataAccessException daEx) { - log.debug("Error while retrieving StorageSpace", daEx); + log.debug("Error while retrieving StorageSpace: {}", daEx.getMessage(), + daEx); } return result; } @@ -421,28 +424,27 @@ public ArrayOfTSpaceToken getSpaceTokens(GridUserInterface user, ArrayOfTSpaceToken result = new ArrayOfTSpaceToken(); - ReservedSpaceCatalog.log.debug("Retrieving space tokens..."); + log.debug("Retrieving space tokens..."); // Retrieve the Data Access Object from the factory try { ssDAO = daoFactory.getStorageSpaceDAO(); - ReservedSpaceCatalog.log.debug("Storage Space DAO retrieved."); + log.debug("Storage Space DAO retrieved."); } catch (DataAccessException daEx) { - ReservedSpaceCatalog.log.error("Error while retrieving StorageSpaceDAO.", + log.error("Error while retrieving StorageSpaceDAO: {}", daEx.getMessage(), daEx); } // Get StorageSpaceTO form persistence try { - Collection listOfStorageSpace = ssDAO.getStorageSpaceByOwner(user, + Collection listOfStorageSpace = ssDAO.getStorageSpaceByOwner(user, spaceAlias); int nItems = listOfStorageSpace.size(); - ReservedSpaceCatalog.log - .debug("getSpaceTokens : Number of Storage spaces retrieved with Alias '" - + spaceAlias + "': " + nItems); - Iterator j_ssTO = listOfStorageSpace.iterator(); + log.debug("getSpaceTokens : Number of Storage spaces retrieved with " + + "Alias '{}': {}", spaceAlias, nItems); + Iterator j_ssTO = listOfStorageSpace.iterator(); while (j_ssTO.hasNext()) { StorageSpaceTO ssTO = (StorageSpaceTO) j_ssTO.next(); @@ -450,16 +452,15 @@ public ArrayOfTSpaceToken getSpaceTokens(GridUserInterface user, TSpaceToken spaceToken = TSpaceToken.make(ssTO.getSpaceToken()); result.addTSpaceToken(spaceToken); } catch (InvalidTSpaceTokenAttributesException ex2) { - ReservedSpaceCatalog.log - .error("Retrieved invalid Space token from DB"); + log.error("Retrieved invalid Space token from DB"); } } } catch (DataAccessException daEx) { - ReservedSpaceCatalog.log.error("Error while retrieving StorageSpace", + log.error("Error while retrieving StorageSpace: {}", daEx.getMessage(), daEx); } catch (Exception e) { - ReservedSpaceCatalog.log.error( - "Exception while retrieving Storage Space", e); + log.error("Exception while retrieving Storage Space: {}", e.getMessage(), + e); } return result; } @@ -475,26 +476,25 @@ public ArrayOfTSpaceToken getSpaceTokensByAlias(String spaceAlias) { ArrayOfTSpaceToken result = new ArrayOfTSpaceToken(); - ReservedSpaceCatalog.log.debug("Retrieving space tokens..."); + log.debug("Retrieving space tokens..."); // Retrieve the Data Access Object from the factory try { ssDAO = daoFactory.getStorageSpaceDAO(); - ReservedSpaceCatalog.log.debug("Storage Space DAO retrieved."); + log.debug("Storage Space DAO retrieved."); } catch (DataAccessException daEx) { - ReservedSpaceCatalog.log.error("Error while retrieving StorageSpaceDAO.", + log.error("Error while retrieving StorageSpaceDAO: {}", daEx.getMessage(), daEx); } // Get StorageSpaceTO form persistence try { - Collection listOfStorageSpace = ssDAO + Collection listOfStorageSpace = ssDAO .getStorageSpaceByAliasOnly(spaceAlias); int nItems = listOfStorageSpace.size(); - ReservedSpaceCatalog.log.debug("Number of Storage spaces retrieved: " - + nItems); - Iterator j_ssTO = listOfStorageSpace.iterator(); + log.debug("Number of Storage spaces retrieved: {}", nItems); + Iterator j_ssTO = listOfStorageSpace.iterator(); while (j_ssTO.hasNext()) { StorageSpaceTO ssTO = (StorageSpaceTO) j_ssTO.next(); @@ -502,16 +502,15 @@ public ArrayOfTSpaceToken getSpaceTokensByAlias(String spaceAlias) { TSpaceToken spaceToken = TSpaceToken.make(ssTO.getSpaceToken()); result.addTSpaceToken(spaceToken); } catch (InvalidTSpaceTokenAttributesException ex2) { - ReservedSpaceCatalog.log - .error("Retrieved invalid Space token from DB"); + log.error("Retrieved invalid Space token from DB"); } } } catch (DataAccessException daEx) { - ReservedSpaceCatalog.log.error("Error while retrieving StorageSpace", + log.error("Error while retrieving StorageSpace: {}", daEx.getMessage(), daEx); } catch (Exception e) { - ReservedSpaceCatalog.log.error("Error getting data!", e); + log.error("Error getting data! Error: {}", e.getMessage(), e); } return result; } @@ -527,25 +526,24 @@ public ArrayOfTSpaceToken getSpaceTokensBySpaceType(String stype) { ArrayOfTSpaceToken result = new ArrayOfTSpaceToken(); - ReservedSpaceCatalog.log.debug("Retrieving space tokens..."); + log.debug("Retrieving space tokens..."); // Retrieve the Data Access Object from the factory try { ssDAO = daoFactory.getStorageSpaceDAO(); - ReservedSpaceCatalog.log.debug("Storage Space DAO retrieved."); + log.debug("Storage Space DAO retrieved."); } catch (DataAccessException daEx) { - ReservedSpaceCatalog.log.error("Error while retrieving StorageSpaceDAO.", + log.error("Error while retrieving StorageSpaceDAO: {}", daEx.getMessage(), daEx); } // Get StorageSpaceTO form persistence try { - Collection listOfStorageSpace = ssDAO.getStorageSpaceBySpaceType(stype); + Collection listOfStorageSpace = ssDAO.getStorageSpaceBySpaceType(stype); int nItems = listOfStorageSpace.size(); - ReservedSpaceCatalog.log.debug("Number of Storage spaces retrieved: " - + nItems); - Iterator j_ssTO = listOfStorageSpace.iterator(); + log.debug("Number of Storage spaces retrieved: {}", nItems); + Iterator j_ssTO = listOfStorageSpace.iterator(); while (j_ssTO.hasNext()) { StorageSpaceTO ssTO = (StorageSpaceTO) j_ssTO.next(); @@ -553,17 +551,14 @@ public ArrayOfTSpaceToken getSpaceTokensBySpaceType(String stype) { TSpaceToken spaceToken = TSpaceToken.make(ssTO.getSpaceToken()); result.addTSpaceToken(spaceToken); } catch (InvalidTSpaceTokenAttributesException ex2) { - ReservedSpaceCatalog.log - .error("Retrieved invalid Space token from DB"); + log.error("Retrieved invalid Space token from DB"); } } } catch (DataAccessException daEx) { - ReservedSpaceCatalog.log.error("Error while retrieving StorageSpace", - daEx); + log.error("Error while retrieving StorageSpace: {}", daEx.getMessage(), daEx); } catch (Exception e) { - ReservedSpaceCatalog.log.error( - "Generic Error while retrieving StorageSpace", e); + log.error("Generic Error while retrieving StorageSpace: {}", e.getMessage(), e); } return result; } @@ -580,25 +575,23 @@ public ArrayOfTSpaceToken getSpaceTokensBySpaceType(String stype) { */ public boolean release(GridUserInterface user, final TSpaceToken spaceToken) { - ReservedSpaceCatalog.log - .debug("Delete storage spaceToken info from persistence: " + spaceToken); + log.debug("Delete storage spaceToken info from persistence: {}", spaceToken); // Retrieve the Data Access Object from the factory try { ssDAO = daoFactory.getStorageSpaceDAO(); - ReservedSpaceCatalog.log.debug("Storage Space DAO retrieved."); + log.debug("Storage Space DAO retrieved."); } catch (DataAccessException daEx) { - ReservedSpaceCatalog.log.error("Error while retrieving StorageSpaceDAO.", - daEx); + log.error("Error while retrieving StorageSpaceDAO: {}", + daEx.getMessage(), daEx); } boolean rowRemoved = true; // Delete the row from persistence. try { ssDAO.removeStorageSpace(user, spaceToken.getValue()); - ReservedSpaceCatalog.log.debug("spaceToken removed from DB."); + log.debug("spaceToken removed from DB."); } catch (DataAccessException daEx) { - ReservedSpaceCatalog.log.error("spaceToken not found in the DB: " - + spaceToken.getValue()); + log.error("spaceToken not found in the DB: {}", spaceToken.getValue()); rowRemoved = false; } return rowRemoved; @@ -611,7 +604,7 @@ public boolean release(GridUserInterface user, final TSpaceToken spaceToken) { */ public void purge() { - ReservedSpaceCatalog.log.debug("Space Garbage Collector start!"); + log.debug("Space Garbage Collector start!"); Calendar rightNow = Calendar.getInstance(); // Retrieve the Data Access Object from the factory @@ -619,16 +612,16 @@ public void purge() { ssDAO = daoFactory.getStorageSpaceDAO(); log.debug("Storage Space DAO retrieved."); } catch (DataAccessException daEx) { - log.error("Error while retrieving StorageSpaceDAO.", daEx); + log.error("Error while retrieving StorageSpaceDAO: {}", daEx.getMessage(), + daEx); } // Get the Collection of Space Resrvation Expired - Collection expiredSpaceTO; + Collection expiredSpaceTO; try { expiredSpaceTO = ssDAO.getExpired(rightNow.getTimeInMillis() / 1000); } catch (DataAccessException e) { // No space expired FOUND - ReservedSpaceCatalog.log - .info("Space Garbage Collector: no space expired found."); + log.info("Space Garbage Collector: no space expired found."); return; } @@ -637,34 +630,27 @@ public void purge() { // 2) Remove the entry from the DB StorageSpaceTO spaceTO = null; - ReservedSpaceCatalog.log - .debug("Space Garbage Collector: Number of SpaceFile to remove " - + expiredSpaceTO.size() + "."); + log.debug("Space Garbage Collector: Number of SpaceFile to remove {}.", + expiredSpaceTO.size()); - for (Iterator i = expiredSpaceTO.iterator(); i.hasNext();) { + for (Iterator i = expiredSpaceTO.iterator(); i.hasNext();) { spaceTO = (StorageSpaceTO) i.next(); // Deleteing space File String spaceFileName = spaceTO.getSpaceFile(); File sfile = new File(spaceFileName); - ReservedSpaceCatalog.log - .debug("Space Garbage Collector: SpaceFile to remove " + spaceFileName - + "."); + log.debug("Space Garbage Collector: SpaceFile to remove {}.", spaceFileName); if (sfile.delete()) { - ReservedSpaceCatalog.log.debug("Space Garbage Collector: SpaceFile " - + spaceFileName + " removed."); + log.debug("Space Garbage Collector: SpaceFile {} removed.", spaceFileName); } else { - ReservedSpaceCatalog.log - .warn("Space Garbage Collector: problem removing " + spaceFileName - + "!"); + log.warn("Space Garbage Collector: problem removing {}", spaceFileName); } // Removing space entry from the DB try { ssDAO.removeStorageSpace(spaceTO.getSpaceToken()); } catch (DataAccessException e) { - ReservedSpaceCatalog.log - .warn("Space Garbage Collector: error removing space entry from catalog."); + log.warn("Space Garbage Collector: error removing space entry from catalog."); } } diff --git a/src/main/java/it/grid/storm/catalogs/SizeInBytesIntConverter.java b/src/main/java/it/grid/storm/catalogs/SizeInBytesIntConverter.java index cbaca41c..bc48611b 100644 --- a/src/main/java/it/grid/storm/catalogs/SizeInBytesIntConverter.java +++ b/src/main/java/it/grid/storm/catalogs/SizeInBytesIntConverter.java @@ -32,8 +32,7 @@ */ public class SizeInBytesIntConverter { - private static SizeInBytesIntConverter stc = new SizeInBytesIntConverter(); // only - // instance + private static SizeInBytesIntConverter stc = new SizeInBytesIntConverter(); private SizeInBytesIntConverter() { diff --git a/src/main/java/it/grid/storm/catalogs/SpaceTokenStringConverter.java b/src/main/java/it/grid/storm/catalogs/SpaceTokenStringConverter.java index 60b64071..75c79230 100644 --- a/src/main/java/it/grid/storm/catalogs/SpaceTokenStringConverter.java +++ b/src/main/java/it/grid/storm/catalogs/SpaceTokenStringConverter.java @@ -32,8 +32,7 @@ */ class SpaceTokenStringConverter { - private static SpaceTokenStringConverter stc = new SpaceTokenStringConverter(); // only - // instance + private static SpaceTokenStringConverter stc = new SpaceTokenStringConverter(); private SpaceTokenStringConverter() { diff --git a/src/main/java/it/grid/storm/catalogs/SurlMultyOperationRequestData.java b/src/main/java/it/grid/storm/catalogs/SurlMultyOperationRequestData.java index 249e97ab..52ed8a14 100644 --- a/src/main/java/it/grid/storm/catalogs/SurlMultyOperationRequestData.java +++ b/src/main/java/it/grid/storm/catalogs/SurlMultyOperationRequestData.java @@ -33,31 +33,33 @@ public SurlMultyOperationRequestData(TSURL surl, TReturnStatus status) public synchronized void store() { - if (!stored) { - try { - while (!stored) { - try { - if (this instanceof IdentityInputData) { - SurlStatusStore.getInstance().store( - generatedRequestToken, - ((IdentityInputData) this).getUser(), - buildSurlStatusMap(SURL, status.getStatusCode(), - status.getExplanation())); - } else { - SurlStatusStore.getInstance().store( - generatedRequestToken, - buildSurlStatusMap(SURL, status.getStatusCode(), - status.getExplanation())); - } - stored = true; - } catch (TokenDuplicationException e) { - generatedRequestToken = TRequestToken.getRandom(); + if (stored) { + return; + } + try { + while (!stored) { + try { + if (this instanceof IdentityInputData) { + SurlStatusStore.getInstance().store( + generatedRequestToken, + ((IdentityInputData) this).getUser(), + buildSurlStatusMap(SURL, status.getStatusCode(), + status.getExplanation())); + } else { + SurlStatusStore.getInstance().store( + generatedRequestToken, + buildSurlStatusMap(SURL, status.getStatusCode(), + status.getExplanation())); } + stored = true; + } catch (TokenDuplicationException e) { + generatedRequestToken = TRequestToken.getRandom(); } - } catch (IllegalArgumentException e) { - throw new IllegalStateException("Unexpected IllegalArgumentException: " - + e.getMessage()); } + } catch (IllegalArgumentException e) { + log.error(e.getMessage(), e); + throw new IllegalStateException("Unexpected IllegalArgumentException: " + + e.getMessage()); } } @@ -126,17 +128,16 @@ public final void setStatus(TReturnStatus status) { throw new IllegalStateException("Unexpected IllegalArgumentException " + "in updating status store: " + e.getMessage()); } catch (UnknownTokenException e) { - log - .warn("Received an UnknownTokenException, probably the token has expired, unable to update its status in the store : " - + e.getMessage()); + log.warn("Received an UnknownTokenException, probably the token has " + + "expired, unable to update its status in the store: {}", + e.getMessage()); } catch (ExpiredTokenException e) { - log - .warn("Received an ExpiredTokenException. The token is expired, unable to update its status in the store : " - + e.getMessage()); + log.warn("Received an ExpiredTokenException. The token is expired, " + + "unable to update its status in the store: {}", e.getMessage()); } catch (UnknownSurlException e) { - log - .warn("Received an UnknownSurlException, probably the token has expired, unable to update its status in the store : " - + e.getMessage()); + log.warn("Received an UnknownSurlException, probably the token has " + + "expired, unable to update its status in the store: {}", + e.getMessage()); } } } @@ -155,22 +156,22 @@ protected final void setStatus(TStatusCode statusCode, String explanation) { this.SURL, statusCode, explanation); } } catch (IllegalArgumentException e) { + log.error(e.getMessage(), e); // Never thrown throw new IllegalStateException("Unexpected IllegalArgumentException " + "in updating status store: " + e.getMessage()); } catch (UnknownTokenException e) { // Never thrown - log - .warn("Received an UnknownTokenException, probably the token has expired, unable to update its status in the store : " - + e.getMessage()); + log.warn("Received an UnknownTokenException, probably the token has " + + "expired, unable to update its status in the store: {}", + e.getMessage()); } catch (ExpiredTokenException e) { - log - .warn("Received an ExpiredTokenException. The token is expired, unable to update its status in the store : " - + e.getMessage()); + log.warn("Received an ExpiredTokenException. The token is expired, " + + "unable to update its status in the store: {}", e.getMessage()); } catch (UnknownSurlException e) { - log - .warn("Received an UnknownSurlException, probably the token has expired, unable to update its status in the store : " - + e.getMessage()); + log.warn("Received an UnknownSurlException, probably the token has " + + "expired, unable to update its status in the store: {}", + e.getMessage()); } } } diff --git a/src/main/java/it/grid/storm/catalogs/SurlRequestData.java b/src/main/java/it/grid/storm/catalogs/SurlRequestData.java index ddcd8981..56d45342 100644 --- a/src/main/java/it/grid/storm/catalogs/SurlRequestData.java +++ b/src/main/java/it/grid/storm/catalogs/SurlRequestData.java @@ -18,11 +18,14 @@ package it.grid.storm.catalogs; import java.util.Map; + import it.grid.storm.srm.types.InvalidTReturnStatusAttributeException; import it.grid.storm.srm.types.TReturnStatus; import it.grid.storm.srm.types.TSURL; import it.grid.storm.srm.types.TStatusCode; + import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * @author Michele Dibenedetto @@ -30,6 +33,9 @@ */ public abstract class SurlRequestData implements RequestData { + private static final Logger log = LoggerFactory + .getLogger(SurlRequestData.class); + protected TSURL SURL; protected TReturnStatus status; @@ -43,8 +49,6 @@ public SurlRequestData(TSURL toSURL, TReturnStatus status) this.status = status; } - protected abstract Logger getLog(); - /** * Method that returns the TURL for this chunk of the srm request. */ @@ -83,9 +87,8 @@ protected void setStatus(TStatusCode statusCode, String explanation) { status = new TReturnStatus(statusCode, explanation); } } catch (InvalidTReturnStatusAttributeException e) { - getLog().warn( - "UNEXPECTED ERROR! Unable to set SRM request status to SRM_ABORTED! " - + e); + log.error("Unable to set SRM request status to [{},{}]. Error: {}", + statusCode.getValue(), explanation, e.getMessage(), e); } } diff --git a/src/main/java/it/grid/storm/catalogs/VolatileAndJiTCatalog.java b/src/main/java/it/grid/storm/catalogs/VolatileAndJiTCatalog.java index a8a79206..37a43814 100644 --- a/src/main/java/it/grid/storm/catalogs/VolatileAndJiTCatalog.java +++ b/src/main/java/it/grid/storm/catalogs/VolatileAndJiTCatalog.java @@ -167,17 +167,12 @@ synchronized public boolean exists(PFN pfn) { */ synchronized public boolean expireGetJiTs(PFN pfn, LocalUser localUser) { - boolean ok = pfn != null && localUser != null; - if (!ok) { - log - .error("VolatileAndJiT CATALOG: programming bug! expireGetJiTs invoked on null attributes; pfn=" - + pfn + " localUser=" + localUser); - return false; - } else { - boolean result = true; - result = result && expireJiT(pfn, localUser, FilesystemPermission.Read); - return result; + if (pfn != null && localUser != null) { + return expireJiT(pfn, localUser, FilesystemPermission.Read); } + log.error("VolatileAndJiT CATALOG: programming bug! expireGetJiTs invoked " + + "on null attributes; pfn={} localUser={}", pfn, localUser); + return false; } /** @@ -197,13 +192,7 @@ synchronized public boolean expireGetJiTs(PFN pfn, LocalUser localUser) { synchronized public boolean expireJiT(PFN pfn, LocalUser localUser, FilesystemPermission acl) { - boolean ok = pfn != null && localUser != null && acl != null; - if (!ok) { - log - .error("VolatileAndJiT CATALOG: programming bug! expireJiT invoked on null attributes; pfn=" - + pfn + " localUser=" + localUser + " acl=" + acl); - return false; - } else { + if (pfn != null && localUser != null && acl != null) { String fileName = pfn.getValue(); int uid = localUser.getUid(); int intacl = acl.getInt(); @@ -216,24 +205,20 @@ synchronized public boolean expireJiT(PFN pfn, LocalUser localUser, long pinTime = 0; // set to zero the lifetime! int n = dao.numberJiT(fileName, uid, intacl); if (n == 0) { - log.warn("VolatileAndJiT CATALOG: expireJiT found no entry for (" - + fileName + "," + uid + "," + intacl + ")!"); + log.warn("VolatileAndJiT CATALOG: expireJiT found no entry for ({}, {}, " + + "{})!", fileName, uid, intacl); return false; - } else { - dao.forceUpdateJiT(fileName, uid, intacl, pinStart, pinTime); - if (n > 1) { - log - .warn("VolatileAndJiT CATALOG: expireJiT found more than one entry for (" - + fileName - + "," - + uid - + "," - + intacl - + "); the catalogue could be corrupt!"); - } - return true; + } + dao.forceUpdateJiT(fileName, uid, intacl, pinStart, pinTime); + if (n > 1) { + log.warn("VolatileAndJiT CATALOG: expireJiT found more than one entry " + + "for ({}, {}, {}); the catalogue could be corrupt!", fileName, uid, intacl); } + return true; } + log.error("VolatileAndJiT CATALOG: programming bug! expireJiT invoked on " + + "null attributes; pfn={} localUser={} acl={}", pfn, localUser, acl); + return false; } /** @@ -257,18 +242,14 @@ synchronized public boolean expireJiT(PFN pfn, LocalUser localUser, */ synchronized public boolean expirePutJiTs(PFN pfn, LocalUser localUser) { - boolean ok = pfn != null && localUser != null; - if (!ok) { - log - .error("VolatileAndJiT CATALOG: programming bug! expirePutJiTs invoked on null attributes; pfn=" - + pfn + " localUser=" + localUser); - return false; - } else { - boolean result = true; - result = result && expireJiT(pfn, localUser, FilesystemPermission.Read); - result = result && expireJiT(pfn, localUser, FilesystemPermission.Write); - return result; + if (pfn != null && localUser != null) { + return expireJiT(pfn, localUser, FilesystemPermission.Read) + && expireJiT(pfn, localUser, FilesystemPermission.Write); } + + log.error("VolatileAndJiT CATALOG: programming bug! expirePutJiTs invoked " + + "on null attributes; pfn={} localUser={}", pfn, localUser); + return false; } /** @@ -290,22 +271,19 @@ synchronized public void purge() { * set up on them. */ Collection[] expired = dao.removeExpired(rightNow.getTimeInMillis() / 1000); - Collection expiredVolatile = expired[0]; // collection of expired Volatile - // entries - Collection expiredJiT = expired[1]; // collection of expired JiTs + Collection expiredVolatile = expired[0]; + Collection expiredJiT = expired[1]; if (expiredVolatile.size() == 0) { log.debug("VolatileAndJiT CATALOG! No expired Volatile entries found."); } else { - log - .info("VolatileAndJiT CATALOG! Found and purged the following expired Volatile entries:\n " - + volatileString(expired[0])); + log.info("VolatileAndJiT CATALOG! Found and purged the following expired " + + "Volatile entries:\n {}", volatileString(expired[0])); } if (expiredJiT.size() == 0) { log.debug("VolatileAndJiT CATALOG! No JiT entries found."); } else { - log - .info("VolatileAndJiT CATALOG! Found and purged the following expired JiT ACLs entries:\n " - + jitString(expired[1])); + log.info("VolatileAndJiT CATALOG! Found and purged the following expired " + + "JiT ACLs entries:\n {}", jitString(expired[1])); } // Remove ACLs JiTData aux = null; @@ -316,39 +294,30 @@ synchronized public void purge() { int jituid = aux.uid(); int jitgid = aux.gid(); try { - log.info("VolatileAndJiT CATALOG. Removing ACL " + jitacl + " on file " - + jitfile + " for user " + jituid + "," + jitgid); + log.info("VolatileAndJiT CATALOG. Removing ACL {} on file {} for " + + "user {},{}", jitacl, jitfile, jituid, jitgid); LocalFile auxFile = NamespaceDirector.getNamespace() .resolveStoRIbyPFN(PFN.make(jitfile)).getLocalFile(); LocalUser auxUser = new LocalUser(jituid, jitgid); FilesystemPermission auxACL = new FilesystemPermission(jitacl); AclManager manager = AclManagerFSAndHTTPS.getInstance(); - // TODO ACL manager if (auxFile == null) { - log - .warn("VolatileAndJiT CATALOG! Unable to setting up the ACL. LocalFile is null!"); + log.warn("VolatileAndJiT CATALOG! Unable to setting up the ACL. " + + "LocalFile is null!"); } else { try { manager.revokeUserPermission(auxFile, auxUser, auxACL); } catch (IllegalArgumentException e) { - log - .error("Unable to revoke user permissions on the file. IllegalArgumentException: " - + e.getMessage()); + log.error("Unable to revoke user permissions on the file. " + + "IllegalArgumentException: {}", e.getMessage(), e); } } - // auxFile.revokeUserPermission(auxUser, auxACL); } catch (Exception e) { - // log exceptions - log - .error("VolatileAndJiT CATALOG! Entry removed from Catalog, but physical ACL " - + jitacl - + " for user " - + jituid - + "," - + jitgid - + " could NOT be removed from " + jitfile); - log.error("VolatileAndJiT CATALOG! " + e); + log.error("VolatileAndJiT CATALOG! Entry removed from Catalog, but " + + "physical ACL {} for user {}, could NOT be removed from {}", + jitacl, jituid, jitgid, jitfile); + log.error("VolatileAndJiT CATALOG! {}", e.getMessage(), e); } } // Delete files @@ -356,7 +325,7 @@ synchronized public void purge() { for (Iterator i = expiredVolatile.iterator(); i.hasNext();) { auxPFN = (String) i.next(); try { - log.info("VolatileAndJiT CATALOG. Deleting file " + auxPFN); + log.info("VolatileAndJiT CATALOG. Deleting file {}", auxPFN); LocalFile auxFile = NamespaceDirector.getNamespace() .resolveStoRIbyPFN(PFN.make(auxPFN)).getLocalFile(); boolean ok = auxFile.delete(); @@ -364,11 +333,9 @@ synchronized public void purge() { throw new Exception("Java File deletion failed!"); } } catch (Exception e) { - // log exceptions - log - .error("VolatileAndJiT CATALOG! Entry removed from Catalog, but physical file " - + auxPFN + " could NOT be deleted!"); - log.error("VolatileAndJiT CATALOG! " + e); + log.error("VolatileAndJiT CATALOG! Entry removed from Catalog, but " + + "physical file {} could NOT be deleted!", auxPFN); + log.error("VolatileAndJiT CATALOG! {}", e.getMessage(), e); } } } @@ -383,14 +350,12 @@ synchronized public void purge() { */ synchronized public void removeAllJiTsOn(PFN pfn) { - boolean ok = pfn != null; - if (!ok) { - log - .error("VolatileAndJiT CATALOG: programming bug! removeAllJiTsOn invoked on null pfn!"); - } else { - String fileName = pfn.getValue(); - dao.removeAllJiTsOn(fileName); + if (pfn != null) { + dao.removeAllJiTsOn(pfn.getValue()); + return; } + log.error("VolatileAndJiT CATALOG: programming bug! removeAllJiTsOn " + + "invoked on null pfn!"); } /** @@ -400,13 +365,12 @@ synchronized public void removeAllJiTsOn(PFN pfn) { */ synchronized public void removeVolatile(PFN pfn) { - boolean ok = pfn != null; - if (!ok) { - log - .warn("VolatileAndJiT CATALOG: programming bug! removeVolatile invoked on null pfn!"); - } else { + if (pfn != null) { dao.removeVolatile(pfn.getValue()); + return; } + log.warn("VolatileAndJiT CATALOG: programming bug! removeVolatile invoked " + + "on null pfn!"); } /** @@ -429,20 +393,9 @@ synchronized public void removeVolatile(PFN pfn) { synchronized public void trackJiT(PFN pfn, LocalUser localUser, FilesystemPermission acl, Calendar start, TLifeTimeInSeconds pinLifetime) { - boolean ok = pfn != null && localUser != null && acl != null - && start != null && pinLifetime != null; - if (!ok) { - log - .error("VolatileAndJiT CATALOG: programming bug! TrackACL invoked on null attributes; pfn=" - + pfn - + " localUser=" - + localUser - + " acl=" - + acl - + " start=" - + start - + " pinLifetime=" + pinLifetime); - } else { + if (pfn != null && localUser != null && acl != null && start != null + && pinLifetime != null) { + String fileName = pfn.getValue(); int uid = localUser.getUid(); int gid = localUser.getPrimaryGid(); @@ -456,12 +409,16 @@ synchronized public void trackJiT(PFN pfn, LocalUser localUser, } else { dao.updateJiT(fileName, uid, intacl, pinStart, pinTime); if (n > 1) { - log.warn("VolatileAndJiT CATALOG: More than one entry found for (" - + fileName + "," + uid + "," + intacl - + "); the catalogue could be corrupt!"); + log.warn("VolatileAndJiT CATALOG: More than one entry found for " + + "({}, {}, {}); the catalogue could be corrupt!", fileName, uid, + intacl); } } + return; } + log.error("VolatileAndJiT CATALOG: programming bug! TrackACL invoked on " + + "null attributes; pfn={} localUser={} acl={} start={} pinLifetime={}", + pfn, localUser, acl, start, pinLifetime); } /** @@ -486,12 +443,8 @@ synchronized public void trackJiT(PFN pfn, LocalUser localUser, synchronized public void trackVolatile(PFN pfn, Calendar start, TLifeTimeInSeconds fileLifetime) { - boolean ok = pfn != null && fileLifetime != null && start != null; - if (!ok) { - log - .warn("VolatileAndJiT CATALOG: programming bug! volatileEntry invoked on null attributes; pfn=" - + pfn + " start=" + start + " fileLifetime=" + fileLifetime); - } else { + if (pfn != null && fileLifetime != null && start != null) { + String fileName = pfn.getValue(); long fileTime = fileLifetime.value(); if (fileTime <= 0) { @@ -501,49 +454,52 @@ synchronized public void trackVolatile(PFN pfn, Calendar start, // milliseconds! int n = dao.numberVolatile(fileName); if (n == -1) { - log - .error("VolatileAndJiT CATALOG! DB problem does not allow to count number of Volatile entries for " - + pfn + "! Volatile entry NOT processed!"); + log.error("VolatileAndJiT CATALOG! DB problem does not allow to count " + + "number of Volatile entries for {}! Volatile entry NOT processed!", + pfn); } else if (n == 0) { dao.addVolatile(fileName, fileStart, fileTime); } else { dao.updateVolatile(fileName, fileStart, fileTime); if (n > 1) { - log.warn("VolatileAndJiT CATALOG: More than one entry found for " - + fileName + "; the catalogue could be corrupt!"); + log.warn("VolatileAndJiT CATALOG: More than one entry found for {}; " + + "the catalogue could be corrupt!", fileName); } } + return; } + log.warn("VolatileAndJiT CATALOG: programming bug! volatileEntry invoked " + + "on null attributes; pfn={} start={} fileLifetime={}", pfn, start, + fileLifetime); } synchronized public void setStartTime(PFN pfn, Calendar start) throws Exception { if (pfn == null || start == null) { - log - .warn("VolatileAndJiT CATALOG: programming bug! volatileEntry invoked on null attributes; pfn=" - + pfn + " start=" + start); - } else { - String fileName = pfn.getValue(); - long fileStart = start.getTimeInMillis() / 1000; // seconds needed and not - // milliseconds! - int n = dao.numberVolatile(fileName); - if (n == -1) { - log - .error("VolatileAndJiT CATALOG! DB problem does not allow to count number of Volatile entries for " - + pfn + "! Volatile entry NOT processed!"); - } else { - if (n == 0) { - throw new Exception("Unable to update row volatile for pfn \'" + pfn - + "\' , not on the database!"); - } else { - dao.updateVolatile(fileName, fileStart); - if (n > 1) { - log.warn("VolatileAndJiT CATALOG: More than one entry found for " - + fileName + "; the catalogue could be corrupt!"); - } - } - } + log.warn("VolatileAndJiT CATALOG: programming bug! volatileEntry invoked " + + "on null attributes; pfn={} start={}", pfn, start); + return; + } + + String fileName = pfn.getValue(); + long fileStart = start.getTimeInMillis() / 1000; // seconds needed and not + // milliseconds! + int n = dao.numberVolatile(fileName); + if (n == -1) { + log.error("VolatileAndJiT CATALOG! DB problem does not allow to count " + + "number of Volatile entries for {}! Volatile entry NOT processed!", + pfn); + return; + } + if (n == 0) { + throw new Exception("Unable to update row volatile for pfn \'" + pfn + + "\' , not on the database!"); + } + dao.updateVolatile(fileName, fileStart); + if (n > 1) { + log.warn("VolatileAndJiT CATALOG: More than one entry found for {}; " + + "the catalogue could be corrupt!", fileName); } } @@ -559,36 +515,35 @@ synchronized public void setStartTime(PFN pfn, Calendar start) */ synchronized public List volatileInfoOn(PFN pfn) { - boolean ok = pfn != null; ArrayList aux = new ArrayList(); - if (!ok) { - log - .error("VolatileAndJiT CATALOG: programming bug! volatileInfoOn invoked on null PFN!"); + if (pfn == null) { + log.error("VolatileAndJiT CATALOG: programming bug! volatileInfoOn " + + "invoked on null PFN!"); return aux; - } else { - Collection c = dao.volatileInfoOn(pfn.getValue()); - if (c.size() == 2) { - Iterator i = c.iterator(); - // start time - long startInMillis = i.next().longValue() * 1000; - Calendar auxcal = Calendar.getInstance(); - auxcal.setTimeInMillis(startInMillis); - aux.add(auxcal); - // lifeTime - long lifetimeInSeconds = ((Long) i.next()).longValue(); - TLifeTimeInSeconds auxLifeTime = TLifeTimeInSeconds.makeEmpty(); - try { - auxLifeTime = TLifeTimeInSeconds.make(lifetimeInSeconds, - TimeUnit.SECONDS); - } catch (IllegalArgumentException e) { - log - .error("VolatileAndJiT CATALOG: programming bug! Retrieved long does not allow TLifeTimeCreation! long is: " - + lifetimeInSeconds + "; exception is: " + e); - } - aux.add(auxLifeTime); - } + } + Collection c = dao.volatileInfoOn(pfn.getValue()); + if (c.size() != 2) { return aux; } + Iterator i = c.iterator(); + // start time + long startInMillis = i.next().longValue() * 1000; + Calendar auxcal = Calendar.getInstance(); + auxcal.setTimeInMillis(startInMillis); + aux.add(auxcal); + // lifeTime + long lifetimeInSeconds = ((Long) i.next()).longValue(); + TLifeTimeInSeconds auxLifeTime = TLifeTimeInSeconds.makeEmpty(); + try { + auxLifeTime = TLifeTimeInSeconds + .make(lifetimeInSeconds, TimeUnit.SECONDS); + } catch (IllegalArgumentException e) { + log.error("VolatileAndJiT CATALOG: programming bug! Retrieved long does " + + "not allow TLifeTimeCreation! long is: {}; error is: {}", + lifetimeInSeconds, e.getMessage(), e); + } + aux.add(auxLifeTime); + return aux; } /** diff --git a/src/main/java/it/grid/storm/catalogs/VolatileAndJiTDAO.java b/src/main/java/it/grid/storm/catalogs/VolatileAndJiTDAO.java index ce0bc4ba..e2ed6c2a 100644 --- a/src/main/java/it/grid/storm/catalogs/VolatileAndJiTDAO.java +++ b/src/main/java/it/grid/storm/catalogs/VolatileAndJiTDAO.java @@ -161,10 +161,10 @@ public void addJiT(String filename, int uid, int gid, int acl, long start, logWarnings(stmt.getWarnings()); stmt.setLong(6, pinLifetime); logWarnings(stmt.getWarnings()); - log.debug("VolatileAndJiTDAO. addJiT: " + stmt.toString()); + log.debug("VolatileAndJiTDAO. addJiT: {}", stmt.toString()); stmt.execute(); } catch (SQLException e) { - log.error("VolatileAndJiTDAO! Error in addJiT: " + e); + log.error("VolatileAndJiTDAO! Error in addJiT: {}", e.getMessage(), e); } finally { close(stmt); } @@ -197,10 +197,10 @@ public void addVolatile(String filename, long start, long fileLifetime) { logWarnings(stmt.getWarnings()); stmt.setLong(3, fileLifetime); logWarnings(stmt.getWarnings()); - log.debug("VolatileAndJiTDAO. addVolatile: " + stmt.toString()); + log.debug("VolatileAndJiTDAO. addVolatile: {}", stmt.toString()); stmt.execute(); } catch (SQLException e) { - log.error("VolatileAndJiTDAO! Error in addVolatile: " + e); + log.error("VolatileAndJiTDAO! Error in addVolatile: {}", e.getMessage(), e); } finally { close(stmt); } @@ -232,7 +232,7 @@ public boolean exists(String filename) { stmt.setString(1, filename); logWarnings(stmt.getWarnings()); - log.debug("VolatileAndJiTDAO - existsOnVolatile - " + stmt.toString()); + log.debug("VolatileAndJiTDAO - existsOnVolatile - {}", stmt.toString()); rs = stmt.executeQuery(); logWarnings(stmt.getWarnings()); @@ -243,7 +243,8 @@ public boolean exists(String filename) { result = false; } } catch (SQLException e) { - log.error("VolatileAndJiTDAO! Error in existsOnVolatile: ", e); + log.error("VolatileAndJiTDAO! Error in existsOnVolatile: {}", + e.getMessage(), e); result = false; } finally { close(rs); @@ -292,11 +293,12 @@ public void forceUpdateJiT(String filename, int uid, int acl, long start, logWarnings(stmt.getWarnings()); stmt.setInt(5, acl); logWarnings(stmt.getWarnings()); - log.debug("VolatileAndJiTDAO. forceUpdateJiT: " + stmt.toString()); + log.debug("VolatileAndJiTDAO. forceUpdateJiT: {}", stmt.toString()); int n = stmt.executeUpdate(); - log.debug("VolatileAndJiTDAO. " + n + " jit entries forced updated."); + log.debug("VolatileAndJiTDAO. {} jit entries forced updated.", n); } catch (SQLException e) { - log.error("VolatileAndJiTDAO! Error in forceUpdateJiT: " + e); + log.error("VolatileAndJiTDAO! Error in forceUpdateJiT: {}", + e.getMessage(), e); } finally { close(stmt); } @@ -314,8 +316,7 @@ public void forceUpdateJiT(String filename, int uid, int acl, long start, public int numberJiT(String filename, int uid, int acl) { if (!checkConnection()) { - log - .error("VolatileAndJiTDAO. numberJiT: unable to get a valid connection!"); + log.error("VolatileAndJiTDAO. numberJiT: unable to get a valid connection!"); return -1; } String sql = "SELECT COUNT(ID) FROM jit WHERE file=? AND uid=? AND acl=?"; @@ -330,21 +331,21 @@ public int numberJiT(String filename, int uid, int acl) { logWarnings(stmt.getWarnings()); stmt.setInt(3, acl); logWarnings(stmt.getWarnings()); - log.debug("VolatileAndJiTDAO. numberJiT: " + stmt.toString()); + log.debug("VolatileAndJiTDAO. numberJiT: {}", stmt.toString()); rs = stmt.executeQuery(); logWarnings(stmt.getWarnings()); int n = -1; if (rs.next()) { n = rs.getInt(1); } else { - log - .error("VolatileAndJiTDAO! Unexpected situation in numberJiT: result set empty!"); + log.error("VolatileAndJiTDAO! Unexpected situation in numberJiT: " + + "result set empty!"); } close(rs); close(stmt); return n; } catch (SQLException e) { - log.error("VolatileAndJiTDAO! Error in numberJiT: " + e); + log.error("VolatileAndJiTDAO! Error in numberJiT: {}", e.getMessage(), e); close(rs); close(stmt); return -1; @@ -375,21 +376,22 @@ public int numberVolatile(String filename) { logWarnings(con.getWarnings()); stmt.setString(1, filename); logWarnings(stmt.getWarnings()); - log.debug("VolatileAndJiTDAO. numberVolatile: " + stmt.toString()); + log.debug("VolatileAndJiTDAO. numberVolatile: {}", stmt.toString()); rs = stmt.executeQuery(); logWarnings(stmt.getWarnings()); int n = -1; if (rs.next()) { n = rs.getInt(1); } else { - log - .error("VolatileAndJiTDAO! Unexpected situation in numberVolatile: result set empty!"); + log.error("VolatileAndJiTDAO! Unexpected situation in numberVolatile: " + + "result set empty!"); } close(rs); close(stmt); return n; } catch (SQLException e) { - log.error("VolatileAndJiTDAO! Error in numberVolatile: " + e); + log.error("VolatileAndJiTDAO! Error in numberVolatile: {}", + e.getMessage(), e); close(rs); close(stmt); return -1; @@ -404,8 +406,8 @@ public int numberVolatile(String filename) { public void removeAllJiTsOn(String filename) { if (!checkConnection()) { - log - .error("VolatileAndJiTDAO. removeAllJiTsOn: unable to get a valid connection!"); + log.error("VolatileAndJiTDAO. removeAllJiTsOn: unable to get a " + + "valid connection!"); return; } String sql = "DELETE FROM jit WHERE file=?"; @@ -415,11 +417,11 @@ public void removeAllJiTsOn(String filename) { logWarnings(con.getWarnings()); stmt.setString(1, filename); logWarnings(stmt.getWarnings()); - log.debug("VolatileAndJiTDAO. removeJiT: " + stmt.toString()); + log.debug("VolatileAndJiTDAO. removeJiT: {}", stmt.toString()); int n = stmt.executeUpdate(); - log.debug("VolatileAndJiTDAO. removeJiT: " + n + " entries removed"); + log.debug("VolatileAndJiTDAO. removeJiT: {} entries removed", n); } catch (SQLException e) { - log.error("VolatileAndJiTDAO! Error in removeJiT: " + e); + log.error("VolatileAndJiTDAO! Error in removeJiT: {}", e.getMessage(), e); } finally { close(stmt); } @@ -471,7 +473,7 @@ public Collection[] removeExpired(long time) { logWarnings(con.getWarnings()); stmt.setLong(1, time); logWarnings(stmt.getWarnings()); - log.debug("VolatileAndJiTDAO. removeExpired: " + stmt.toString()); + log.debug("VolatileAndJiTDAO. removeExpired: {}", stmt.toString()); rs = stmt.executeQuery(); logWarnings(stmt.getWarnings()); Collection volat = new ArrayList(); @@ -493,7 +495,7 @@ public Collection[] removeExpired(long time) { logWarnings(con.getWarnings()); stmt.setLong(1, time); logWarnings(stmt.getWarnings()); - log.debug("VolatileAndJiTDAO. removeExpired: " + stmt.toString()); + log.debug("VolatileAndJiTDAO. removeExpired: {}", stmt.toString()); rs = stmt.executeQuery(); logWarnings(stmt.getWarnings()); Collection track = new ArrayList(); @@ -521,7 +523,7 @@ public Collection[] removeExpired(long time) { delvol = delvol + makeIDString(volatid); stmt = con.prepareStatement(delvol); logWarnings(con.getWarnings()); - log.debug("VolatileAndJiTDAO. removeExpired: " + stmt.toString()); + log.debug("VolatileAndJiTDAO. removeExpired: {}", stmt.toString()); deletedvol = stmt.executeUpdate(); logWarnings(stmt.getWarnings()); close(stmt); @@ -532,7 +534,7 @@ public Collection[] removeExpired(long time) { deljit = deljit + makeIDString(trackid); stmt = con.prepareStatement(deljit); logWarnings(con.getWarnings()); - log.debug("VolatileAndJiTDAO. removeExpired: " + stmt.toString()); + log.debug("VolatileAndJiTDAO. removeExpired: {}", stmt.toString()); deletedjit = stmt.executeUpdate(); logWarnings(stmt.getWarnings()); close(stmt); @@ -541,15 +543,13 @@ public Collection[] removeExpired(long time) { logWarnings(con.getWarnings()); con.setAutoCommit(true); // end transaction! logWarnings(con.getWarnings()); - log.debug("VolatileAndJiTDAO. Removed " + deletedvol - + " volatile catalogue entries and " + deletedjit - + " jit catalogue entries."); + log.debug("VolatileAndJiTDAO. Removed {} volatile catalogue entries " + + "and {} jit catalogue entries.", deletedvol, deletedjit); volcol = volat; jitcol = track; } catch (SQLException e) { - log - .error("VolatileAndJiTDAO! Unable to complete removeExpired... rolling back! " - + e); + log.error("VolatileAndJiTDAO! Unable to complete removeExpired... " + + "rolling back! {}", e.getMessage(), e); rollback(con); close(stmt); } @@ -559,7 +559,8 @@ public Collection[] removeExpired(long time) { } catch (SQLException e) { close(rs); close(stmt); - log.error("VolatileAndJiTDAO! Unable to complete removeExpired! " + e); + log.error("VolatileAndJiTDAO! Unable to complete removeExpired! {}", + e.getMessage(), e); return new Collection[] { new ArrayList(), new ArrayList() }; // in case // of any // failure @@ -577,8 +578,8 @@ public Collection[] removeExpired(long time) { public void removeVolatile(String filename) { if (!checkConnection()) { - log - .error("VolatileAndJiTDAO. removeVolatile: unable to get a valid connection!"); + log.error("VolatileAndJiTDAO. removeVolatile: unable to get a valid " + + "connection!"); return; } String sql = "DELETE FROM volatile WHERE file=?"; @@ -588,12 +589,12 @@ public void removeVolatile(String filename) { logWarnings(con.getWarnings()); stmt.setString(1, filename); logWarnings(stmt.getWarnings()); - log.debug("VolatileAndJiTDAO. removeVolatile: " + stmt.toString()); + log.debug("VolatileAndJiTDAO. removeVolatile: {}", stmt.toString()); int n = stmt.executeUpdate(); - log - .debug("VolatileAndJiTDAO. removeVolatile: " + n + " entries removed."); + log.debug("VolatileAndJiTDAO. removeVolatile: {} entries removed.", n); } catch (SQLException e) { - log.error("VolatileAndJiTDAO! Error in removeVolatile: " + e); + log.error("VolatileAndJiTDAO! Error in removeVolatile: {}", + e.getMessage(), e); } finally { close(stmt); } @@ -618,8 +619,8 @@ public void updateJiT(String filename, int uid, int acl, long start, long pinLifetime) { if (!checkConnection()) { - log - .error("VolatileAndJiTDAO. updateJiT: unable to get a valid connection!"); + log.error("VolatileAndJiTDAO. updateJiT: unable to get a valid " + + "connection!"); return; } String sql = "UPDATE jit " @@ -641,11 +642,11 @@ public void updateJiT(String filename, int uid, int acl, long start, logWarnings(stmt.getWarnings()); stmt.setLong(6, start + pinLifetime); logWarnings(stmt.getWarnings()); - log.debug("VolatileAndJiTDAO. updateJiT: " + stmt.toString()); + log.debug("VolatileAndJiTDAO. updateJiT: {}", stmt.toString()); int n = stmt.executeUpdate(); - log.debug("VolatileAndJiTDAO. " + n + " jit entries updated."); + log.debug("VolatileAndJiTDAO. {} jit entries updated.", n); } catch (SQLException e) { - log.error("VolatileAndJiTDAO! Error in updateJiT: " + e); + log.error("VolatileAndJiTDAO! Error in updateJiT: {}", e.getMessage(), e); } finally { close(stmt); } @@ -666,8 +667,8 @@ public void updateJiT(String filename, int uid, int acl, long start, public void updateVolatile(String filename, long start, long fileLifetime) { if (!checkConnection()) { - log - .error("VolatileAndJiTDAO. updateVolatile: unable to get a valid connection!"); + log.error("VolatileAndJiTDAO. updateVolatile: unable to get a valid " + + "connection!"); return; } String sql = "UPDATE volatile " @@ -687,11 +688,12 @@ public void updateVolatile(String filename, long start, long fileLifetime) { logWarnings(stmt.getWarnings()); stmt.setLong(5, start + fileLifetime); logWarnings(stmt.getWarnings()); - log.debug("VolatileAndJiTDAO. updateVolatile: " + stmt.toString()); + log.debug("VolatileAndJiTDAO. updateVolatile: {}", stmt.toString()); int n = stmt.executeUpdate(); - log.debug("VolatileAndJiTDAO. " + n + " volatile entries updated."); + log.debug("VolatileAndJiTDAO. {} volatile entries updated.", n); } catch (SQLException e) { - log.error("VolatileAndJiTDAO! Error in updateVolatile: " + e); + log.error("VolatileAndJiTDAO! Error in updateVolatile: {}", + e.getMessage(), e); } finally { close(stmt); } @@ -700,8 +702,8 @@ public void updateVolatile(String filename, long start, long fileLifetime) { public void updateVolatile(String fileName, long fileStart) { if (!checkConnection()) { - log - .error("VolatileAndJiTDAO. updateVolatile: unable to get a valid connection!"); + log.error("VolatileAndJiTDAO. updateVolatile: unable to get a valid " + + "connection!"); return; } String sql = "UPDATE volatile " + "SET start=FROM_UNIXTIME(?) " @@ -714,11 +716,12 @@ public void updateVolatile(String fileName, long fileStart) { logWarnings(stmt.getWarnings()); stmt.setString(2, fileName); logWarnings(stmt.getWarnings()); - log.debug("VolatileAndJiTDAO. updateVolatile: " + stmt.toString()); + log.debug("VolatileAndJiTDAO. updateVolatile: {}", stmt.toString()); int n = stmt.executeUpdate(); - log.debug("VolatileAndJiTDAO. " + n + " volatile entries updated."); + log.debug("VolatileAndJiTDAO. {} volatile entries updated.", n); } catch (SQLException e) { - log.error("VolatileAndJiTDAO! Error in updateVolatile: " + e); + log.error("VolatileAndJiTDAO! Error in updateVolatile: {}", + e.getMessage(), e); } finally { close(stmt); } @@ -738,8 +741,8 @@ public void updateVolatile(String fileName, long fileStart) { public List volatileInfoOn(String filename) { if (!checkConnection()) { - log - .error("VolatileAndJiTDAO. volatileInfoOn: unable to get a valid connection!"); + log.error("VolatileAndJiTDAO. volatileInfoOn: unable to get a valid " + + "connection!"); return new ArrayList(); } String sql = "SELECT UNIX_TIMESTAMP(start), fileLifetime FROM volatile WHERE file=?"; @@ -751,17 +754,18 @@ public List volatileInfoOn(String filename) { logWarnings(con.getWarnings()); stmt.setString(1, filename); logWarnings(stmt.getWarnings()); - log.debug("VolatileAndJiTDAO - infoOnVolatile - " + stmt.toString()); + log.debug("VolatileAndJiTDAO - infoOnVolatile - {}", stmt.toString()); rs = stmt.executeQuery(); logWarnings(stmt.getWarnings()); if (rs.next()) { aux.add(new Long(rs.getLong("UNIX_TIMESTAMP(start)"))); aux.add(new Long(rs.getLong("fileLifetime"))); } else { - log.debug("VolatileAndJiTDAO! infoOnVolatile did not find " + filename); + log.debug("VolatileAndJiTDAO! infoOnVolatile did not find {}", filename); } } catch (SQLException e) { - log.error("VolatileAndJiTDAO! Error in infoOnVolatile: " + e); + log.error("VolatileAndJiTDAO! Error in infoOnVolatile: {}", + e.getMessage(), e); } finally { close(rs); close(stmt); @@ -797,8 +801,8 @@ private void close(ResultSet rset) { try { rset.close(); } catch (Exception e) { - log.error("VolatileAndJiTDAO! Unable to close ResultSet - Exception: " - + e); + log.error("VolatileAndJiTDAO! Unable to close ResultSet - Error: {}", + e.getMessage(), e); } } } @@ -813,8 +817,8 @@ private void close(Statement stmt) { try { stmt.close(); } catch (Exception e) { - log.error("VolatileAndJiTDAO! Unable to close Statement " - + stmt.toString() + " - Exception: " + e); + log.error("VolatileAndJiTDAO! Unable to close Statement {} - Error: {}", + stmt.toString(), e.getMessage(), e); } } } @@ -825,9 +829,9 @@ private void close(Statement stmt) { private void logWarnings(SQLWarning warning) { if (warning != null) { - log.debug("VolatileAndJiTDAO: " + warning.toString()); + log.debug("VolatileAndJiTDAO: {}", warning.toString()); while ((warning = warning.getNextWarning()) != null) { - log.debug("VolatileAndJiTDAO: " + warning.toString()); + log.debug("VolatileAndJiTDAO: {}", warning.toString()); } } } @@ -878,7 +882,7 @@ private void rollback(Connection con) { logWarnings(con.getWarnings()); log.error("VolatileAndJiTDAO! Roll back successful!"); } catch (SQLException e3) { - log.error("VolatileAndJiTDAO! Roll back failed! " + e3); + log.error("VolatileAndJiTDAO! Roll back failed! {}", e3.getMessage(), e3); } } } @@ -893,18 +897,14 @@ private boolean setUpConnection() { Class.forName(driver); con = DriverManager.getConnection(url, name, password); if (con == null) { - log - .error("VolatileAndJiTDAO! DriverManager returned a null Connection!"); + log.error("VolatileAndJiTDAO! DriverManager returned a null Connection!"); } else { response = con.isValid(0); logWarnings(con.getWarnings()); } - } catch (ClassNotFoundException e) { - log.error("VolatileAndJiTDAO! Exception in setUpconnection! " + e); - } catch (SQLException e) { - log.error("VolatileAndJiTDAO! Exception in setUpConnection! " + e); - } catch (Exception e) { - log.error("VolatileAndJiTDAO! Exception in setUpConnection! " + e); + } catch (Throwable e) { + log.error("VolatileAndJiTDAO! Exception in setUpconnection! {}", + e.getMessage(), e); } return response; } @@ -918,7 +918,8 @@ private void takeDownConnection() { try { con.close(); } catch (Exception e) { - log.error("VolatileAndJiTDAO! Exception in takeDownConnection! " + e); + log.error("VolatileAndJiTDAO! Exception in takeDownConnection! {}", + e.getMessage(), e); } } } From e0194b09c2f24f8840b1f03a145705d997f61714 Mon Sep 17 00:00:00 2001 From: Andrea Ceccanti Date: Thu, 6 Feb 2014 18:24:46 +0100 Subject: [PATCH 31/45] More log rationalization & cleanup work --- .../filesystem/FileSystemCheckerFactory.java | 12 +- .../filesystem/FileSystemCheckerFromFile.java | 10 +- .../FileSystemCheckerMountsMonolithic.java | 6 +- .../FileSystemCheckerMtabMonolithic.java | 6 +- .../storm/filesystem/GPFSSpaceSystem.java | 2 +- .../it/grid/storm/filesystem/LocalFile.java | 38 +- .../storm/filesystem/MockSpaceSystem.java | 14 +- .../it/grid/storm/filesystem/MtabUtil.java | 28 +- .../grid/storm/griduser/AbstractGridUser.java | 105 +-- .../grid/storm/griduser/DNMatchingRule.java | 65 +- .../storm/griduser/DistinguishedName.java | 53 -- .../java/it/grid/storm/griduser/GridUser.java | 23 - .../grid/storm/griduser/GridUserFactory.java | 101 +- .../grid/storm/griduser/GridUserManager.java | 60 +- .../grid/storm/griduser/LcmapsJNAMapper.java | 49 +- .../it/grid/storm/griduser/LocalUser.java | 70 +- .../grid/storm/griduser/MapperInterface.java | 18 - .../grid/storm/griduser/SimpleUserMapper.java | 43 +- .../storm/griduser/StormLcmapsJNAMapper.java | 21 +- .../storm/griduser/VONameMatchingRule.java | 44 +- .../it/grid/storm/griduser/VomsGridUser.java | 25 +- .../grid/storm/griduser/swig.OLD/README.txt | 21 - .../swig/Copy of arrays_java.1.3.24.i.old | 392 -------- .../griduser/swig/Copy of string_array.i.old | 81 -- .../it/grid/storm/griduser/swig/FIXME.txt | 96 -- .../java/it/grid/storm/griduser/swig/Makefile | 129 --- .../storm/griduser/swig/arrays_java.1.3.24.i | 392 -------- .../storm/griduser/swig/lcmaps_interface.cpp | 243 ----- .../swig/lcmaps_interface.cpp.minimal | 207 ----- .../griduser/swig/lcmaps_interface.cpp.old | 207 ----- .../storm/griduser/swig/lcmaps_interface.h | 54 -- .../storm/griduser/swig/lcmaps_interface.i | 127 --- .../griduser/swig/lcmaps_interfaceJNI.java | 14 +- .../griduser/swig/lcmaps_interface_wrap.cxx | 860 ------------------ .../swig/load_native_lib_in_jniclass.i | 54 -- .../grid/storm/griduser/swig/string_array.i | 88 -- .../java/it/grid/storm/health/BookKeeper.java | 32 +- .../it/grid/storm/health/DetectiveGlance.java | 8 +- .../it/grid/storm/health/HealthMonitor.java | 26 +- .../java/it/grid/storm/health/LogEvent.java | 68 +- .../it/grid/storm/health/OperationType.java | 38 +- .../storm/health/OperationTypeCategory.java | 15 +- .../storm/health/PerformanceBookKeeper.java | 18 +- .../grid/storm/health/PerformanceGlance.java | 6 +- .../grid/storm/health/PerformancePulse.java | 5 - .../grid/storm/health/PerformanceStatus.java | 7 +- .../grid/storm/https/HTTPPluginManager.java | 2 +- .../storm/https/HTTPSPluginException.java | 9 - .../storm/https/HTTPSPluginInterfaceStub.java | 144 +-- 49 files changed, 203 insertions(+), 3933 deletions(-) delete mode 100644 src/main/java/it/grid/storm/griduser/swig.OLD/README.txt delete mode 100644 src/main/java/it/grid/storm/griduser/swig/Copy of arrays_java.1.3.24.i.old delete mode 100644 src/main/java/it/grid/storm/griduser/swig/Copy of string_array.i.old delete mode 100644 src/main/java/it/grid/storm/griduser/swig/FIXME.txt delete mode 100644 src/main/java/it/grid/storm/griduser/swig/Makefile delete mode 100644 src/main/java/it/grid/storm/griduser/swig/arrays_java.1.3.24.i delete mode 100644 src/main/java/it/grid/storm/griduser/swig/lcmaps_interface.cpp delete mode 100644 src/main/java/it/grid/storm/griduser/swig/lcmaps_interface.cpp.minimal delete mode 100644 src/main/java/it/grid/storm/griduser/swig/lcmaps_interface.cpp.old delete mode 100644 src/main/java/it/grid/storm/griduser/swig/lcmaps_interface.h delete mode 100644 src/main/java/it/grid/storm/griduser/swig/lcmaps_interface.i delete mode 100644 src/main/java/it/grid/storm/griduser/swig/lcmaps_interface_wrap.cxx delete mode 100644 src/main/java/it/grid/storm/griduser/swig/load_native_lib_in_jniclass.i delete mode 100644 src/main/java/it/grid/storm/griduser/swig/string_array.i diff --git a/src/main/java/it/grid/storm/filesystem/FileSystemCheckerFactory.java b/src/main/java/it/grid/storm/filesystem/FileSystemCheckerFactory.java index 5c314e46..eeba23d2 100644 --- a/src/main/java/it/grid/storm/filesystem/FileSystemCheckerFactory.java +++ b/src/main/java/it/grid/storm/filesystem/FileSystemCheckerFactory.java @@ -48,8 +48,8 @@ public static FileSystemCheckerFactory getInstance() { if (instance == null) { log - .info("FileSystemCheckerFactory not explicitaly initialized, using default checker type : " - + defaultType); + .info("FileSystemCheckerFactory not explicitaly initialized, " + + "using default checker type :{}", defaultType); init(defaultType); } return instance; @@ -82,10 +82,10 @@ public static void init(FileSystemCheckerType type) } else { if (!instance.chosenType.equals(type)) { log - .warn("Asked to initialize the already initialized FileSystemCheckerFactory " - + "with FileSystemCheckerType " - + type - + ". Current FileSystemCheckerType is " + instance.chosenType); + .warn("FileSystemCheckerFactory already initialized for {}. " + + "Cannot initialize it again for {}.", + instance.chosenType, + type); throw new IllegalStateException( "Asked to initialize the already initialized FileSystemCheckerFactory " + "with FileSystemCheckerType " + type diff --git a/src/main/java/it/grid/storm/filesystem/FileSystemCheckerFromFile.java b/src/main/java/it/grid/storm/filesystem/FileSystemCheckerFromFile.java index bbb45277..47762270 100644 --- a/src/main/java/it/grid/storm/filesystem/FileSystemCheckerFromFile.java +++ b/src/main/java/it/grid/storm/filesystem/FileSystemCheckerFromFile.java @@ -38,7 +38,6 @@ abstract class FileSystemCheckerFromFile implements FileSystemChecker { private static final String GPFS_FILESYSTEM_NAME = "gpfs"; protected FileSystemCheckerFromFile(Logger log) { - this.log = log; } @@ -122,8 +121,8 @@ private List listGPFSMountPoints() throws FileSystemCheckerException { try { mtab = new BufferedReader(new FileReader(getFilePath())); } catch (FileNotFoundException e) { - log.error("Error while trying to create a reader for mtab file at " - + getFilePath() + ". FileNotFoundException : " + e.getMessage()); + log.error(e.getMessage(),e); + throw new FileSystemCheckerException( "Error while trying to create a reader for mtab file at " + getFilePath() + ". FileNotFoundException : " + e.getMessage()); @@ -140,8 +139,7 @@ private List listGPFSMountPoints() throws FileSystemCheckerException { } } } catch (IOException e) { - log.error("Error while trying to read mtab file at " + getFilePath() - + ". IOException : " + e.getMessage()); + log.error(e.getMessage(), e); throw new FileSystemCheckerException( "Error while trying to read mtab file at " + getFilePath() + ". IOException : " + e.getMessage()); @@ -193,4 +191,4 @@ private List listGPFSMountPoints() throws FileSystemCheckerException { * @return true if the line has to be skipped, true otherwise */ protected abstract boolean skipLine(String line); -} +} \ No newline at end of file diff --git a/src/main/java/it/grid/storm/filesystem/FileSystemCheckerMountsMonolithic.java b/src/main/java/it/grid/storm/filesystem/FileSystemCheckerMountsMonolithic.java index 620ca77e..f7d03dc6 100644 --- a/src/main/java/it/grid/storm/filesystem/FileSystemCheckerMountsMonolithic.java +++ b/src/main/java/it/grid/storm/filesystem/FileSystemCheckerMountsMonolithic.java @@ -146,8 +146,7 @@ private static List listGPFSMountPoints() try { mtab = new BufferedReader(new FileReader(MOUNTS_FILE_PATH)); } catch (FileNotFoundException e) { - log.error("Error while trying to create a reader for mtab file at " - + MOUNTS_FILE_PATH + ". FileNotFoundException : " + e.getMessage()); + log.error(e.getMessage(), e); throw new FileSystemCheckerException( "Error while trying to create a reader for mtab file at " + MOUNTS_FILE_PATH + ". FileNotFoundException : " + e.getMessage()); @@ -164,8 +163,7 @@ private static List listGPFSMountPoints() } } } catch (IOException e) { - log.error("Error while trying to read mtab file at " + MOUNTS_FILE_PATH - + ". IOException : " + e.getMessage()); + log.error(e.getMessage(), e); throw new FileSystemCheckerException( "Error while trying to read mtab file at " + MOUNTS_FILE_PATH + ". IOException : " + e.getMessage()); diff --git a/src/main/java/it/grid/storm/filesystem/FileSystemCheckerMtabMonolithic.java b/src/main/java/it/grid/storm/filesystem/FileSystemCheckerMtabMonolithic.java index 4238fcaf..cd1c275c 100644 --- a/src/main/java/it/grid/storm/filesystem/FileSystemCheckerMtabMonolithic.java +++ b/src/main/java/it/grid/storm/filesystem/FileSystemCheckerMtabMonolithic.java @@ -146,8 +146,7 @@ private static List listGPFSMountPoints() try { mtab = new BufferedReader(new FileReader(MTAB_FILE_PATH)); } catch (FileNotFoundException e) { - log.error("Error while trying to create a reader for mtab file at " - + MTAB_FILE_PATH + ". FileNotFoundException : " + e.getMessage()); + log.error(e.getMessage(), e); throw new FileSystemCheckerException( "Error while trying to create a reader for mtab file at " + MTAB_FILE_PATH + ". FileNotFoundException : " + e.getMessage()); @@ -164,8 +163,7 @@ private static List listGPFSMountPoints() } } } catch (IOException e) { - log.error("Error while trying to read mtab file at " + MTAB_FILE_PATH - + ". IOException : " + e.getMessage()); + log.error(e.getMessage(), e); throw new FileSystemCheckerException( "Error while trying to read mtab file at " + MTAB_FILE_PATH + ". IOException : " + e.getMessage()); diff --git a/src/main/java/it/grid/storm/filesystem/GPFSSpaceSystem.java b/src/main/java/it/grid/storm/filesystem/GPFSSpaceSystem.java index cd935fde..38e92342 100644 --- a/src/main/java/it/grid/storm/filesystem/GPFSSpaceSystem.java +++ b/src/main/java/it/grid/storm/filesystem/GPFSSpaceSystem.java @@ -58,7 +58,7 @@ public long reserveSpace(String pathToFile, long size) throws ReservationException { try { - log.debug("GPFSSpaceSystem : pathToFile:" + pathToFile); + log.debug("GPFSSpaceSystem : pathToFile: {}" , pathToFile); fs.prealloc(pathToFile, size); return size; } catch (Exception e) { diff --git a/src/main/java/it/grid/storm/filesystem/LocalFile.java b/src/main/java/it/grid/storm/filesystem/LocalFile.java index 4f208f98..a6dfaeb4 100644 --- a/src/main/java/it/grid/storm/filesystem/LocalFile.java +++ b/src/main/java/it/grid/storm/filesystem/LocalFile.java @@ -86,7 +86,6 @@ public class LocalFile { // ---- class private variables ---- - /** Log4J logger. */ private static final Logger log = LoggerFactory.getLogger(LocalFile.class); // ---- instance private variables ---- @@ -238,8 +237,7 @@ public String getDefaultChecksum() { return ChecksumManager.getInstance().getDefaultChecksum( localFile.getAbsolutePath()); } catch (FileNotFoundException e) { - log.warn("Unable to get local file checksum. FileNotFoundException: " - + e.getMessage()); + log.error(e.getMessage(), e); return null; } @@ -251,8 +249,7 @@ public Map getChecksums() { return ChecksumManager.getInstance().getChecksums( localFile.getAbsolutePath()); } catch (FileNotFoundException e) { - log.warn("Unable to get local file checksum. FileNotFoundException: " - + e.getMessage()); + log.error(e.getMessage(), e); return new HashMap(0); } @@ -495,24 +492,16 @@ public FilesystemPermission grantUserPermission(final LocalUser u, * false otherwise. */ public boolean hasChecksum() { - try { return ChecksumManager.getInstance().hasChecksum( localFile.getAbsolutePath()); } catch (FileNotFoundException e) { - log - .warn("Unable to verify if local file has the checksum. FileNotFoundException: " - + e.getMessage()); + log.warn("File not found when checking checksum: {}",e.getMessage()); return false; } } - /** - * Method used to find out if This File is a directory or not, as per contract - * of java.io.File: refer thre for further info. - */ public boolean isDirectory() throws SecurityException { - return localFile.isDirectory(); } @@ -522,8 +511,9 @@ private boolean isGPFS() throws FSException { return FileSystemCheckerFactory.getInstance().createFileSystemChecker() .isGPFS(this.localFile); } catch (Exception e) { - log.error("Unable to check if file " + this.localFile.getAbsolutePath() - + " is on GPFS. IllegalArgumentException " + e.getMessage()); + log.error("Unable to check if file {} is on GPFS. {}", + this.localFile.getAbsolutePath(), + e.getMessage(),e); throw new FSException("Unable to check if file " + this.localFile.getAbsolutePath() + " is on GPFS. IllegalArgumentException " + e.getMessage()); @@ -547,15 +537,19 @@ public boolean isOnDisk() throws FSException { if (fileSizeInBlocks >= localFile.length()) { - log.debug("File is on disk: blockSize=" + fileSizeInBlocks - + " fileSize=" + localFile.length() + " file=" - + localFile.getAbsolutePath()); + log.debug("File {} is on disk: blockSize={} fileSize={}", + localFile.getAbsolutePath(), + fileSizeInBlocks, + localFile.length()); + return true; } else { - log.debug("File is NOT on disk: blockSize=" + fileSizeInBlocks - + " fileSize=" + localFile.length() + " file=" - + localFile.getAbsolutePath()); + + log.debug("File {} is NOT on disk: blockSize={} fileSize={}", + localFile.getAbsolutePath(), + fileSizeInBlocks, + localFile.length()); return false; } } diff --git a/src/main/java/it/grid/storm/filesystem/MockSpaceSystem.java b/src/main/java/it/grid/storm/filesystem/MockSpaceSystem.java index 98525f34..3cbcf5f4 100644 --- a/src/main/java/it/grid/storm/filesystem/MockSpaceSystem.java +++ b/src/main/java/it/grid/storm/filesystem/MockSpaceSystem.java @@ -56,16 +56,14 @@ public long reserveSpace(String pathToFile, long size) java.io.File localFile = new java.io.File(pathToFile); try { localFile.createNewFile(); - } catch (IOException ex) { - log.error("IO exception while creating local File named : " + pathToFile, - ex); + } catch (IOException e) { + log.error(e.getMessage(), e); throw new ReservationException( - "IO exception while creating local File named : " + pathToFile); - } catch (SecurityException sec_ex) { - log.error("Security exception while creating local File named : " - + pathToFile, sec_ex); + "IO exception while creating local File named : " + pathToFile,e); + } catch (SecurityException e) { + log.error(e.getMessage(), e); throw new ReservationException( - "Security exception while creating local File named : " + pathToFile); + "Security exception while creating local File named : " + pathToFile, e); } return size; } diff --git a/src/main/java/it/grid/storm/filesystem/MtabUtil.java b/src/main/java/it/grid/storm/filesystem/MtabUtil.java index 2fff695b..43f1a5f8 100644 --- a/src/main/java/it/grid/storm/filesystem/MtabUtil.java +++ b/src/main/java/it/grid/storm/filesystem/MtabUtil.java @@ -107,9 +107,8 @@ public static Map getFSMountPoints() throws Exception { try { mtab = new BufferedReader(new FileReader(getFilePath())); } catch (FileNotFoundException e) { - log.error("Unable to find mtab file at " + getFilePath() - + " . FileNotFoundException: " + e.getMessage()); - throw new Exception("Unable to get mount points. mtab file not found"); + log.error(e.getMessage(), e); + throw new Exception("Unable to get mount points. mtab file not found",e); } String line; try { @@ -120,19 +119,16 @@ public static Map getFSMountPoints() throws Exception { LinkedList elementsList = tokenizeLine(line); if ((elementsList.size() - 1) < getMountPointIndex() || (elementsList.size() - 1) < getFsNameIndex()) { - log - .warn("Unable to produce a valid file system mount point from line \'" - + line - + "\' . not enough elements in the tokenized array : " - + elementsList.toString() + ". Skipping the line"); + log.warn("FS mount point parsing error. " + + "Not enough elements found: {}. Skipping current line...", + elementsList); } else { mountPointToFSMap.put(elementsList.get(getMountPointIndex()), elementsList.get(getFsNameIndex())); } } } catch (IOException e) { - log.error("Unable to read from mtab file at " + getFilePath() - + " . IOException: " + e.getMessage()); + log.error(e.getMessage(), e); throw new Exception( "Unable to get mount points. Erro reading from mtab"); } @@ -156,21 +152,19 @@ public static List getRows() throws IOException { if (skipLineForMountPoints(line)) { continue; } - log.debug("Creting an mtab row from string \'" + line + "\'"); + log.debug("mtab row from string {}", line); MtabRow row = null; try { row = produceRow(line); } catch (IllegalArgumentException e) { - log.warn("Unable to produce a valid row from line \'" + line - + "\' . IllegalArgumentException : " + e.getMessage() - + ". Skipping the line"); + log.warn("Skipping line {}. {}", line, e.getMessage(), e); } if (row != null) { rows.add(row); } } - log.debug("Produced " + rows.size() + " mtab rows from file at " - + MTAB_FILE_PATH); + log.debug("Parsed {} mtab rows from file {}", + rows.size(), MTAB_FILE_PATH); return rows; } @@ -190,4 +184,4 @@ public static LinkedList tokenizeLine(String line) { } return elementsList; } -} +} \ No newline at end of file diff --git a/src/main/java/it/grid/storm/griduser/AbstractGridUser.java b/src/main/java/it/grid/storm/griduser/AbstractGridUser.java index cb337a8f..4acc9f26 100644 --- a/src/main/java/it/grid/storm/griduser/AbstractGridUser.java +++ b/src/main/java/it/grid/storm/griduser/AbstractGridUser.java @@ -33,26 +33,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - *

- * Title: - *

- * - *

- * Description: - *

- * - *

- * Copyright: Copyright (c) 2006 - *

- * - *

- * Company: INFN-CNAF - *

- * - * @author R.Zappi - * @version 1.0 - */ public abstract class AbstractGridUser implements GridUserInterface { protected static final Logger log = LoggerFactory @@ -62,16 +42,10 @@ public abstract class AbstractGridUser implements GridUserInterface { protected MapperInterface userMapperClass = null; protected LocalUser localUser = null; - /** - * @param mapperClass - * @param distinguishedName - */ protected AbstractGridUser(MapperInterface mapperClass, String distinguishedName) { if (mapperClass == null || distinguishedName == null) { - log.error("Provided null parameter: mapperClass=\'" + mapperClass - + "\' distinguishedName=\'" + distinguishedName + "\'"); throw new IllegalArgumentException( "Provided null parameter: mapperClass=\'" + mapperClass + "\' distinguishedName=\'" + distinguishedName + "\'"); @@ -80,11 +54,6 @@ protected AbstractGridUser(MapperInterface mapperClass, this.setDistinguishedName(distinguishedName); } - /** - * @param mapperClass - * @param distinguishedName - * @param proxy - */ protected AbstractGridUser(MapperInterface mapperClass, String distinguishedName, String proxy) { @@ -92,13 +61,6 @@ protected AbstractGridUser(MapperInterface mapperClass, this.setProxyString(proxy); } - /** - * used by the GridUserFactory to set User Mapper Instance. This method has - * package visibility. - * - * @param mapper - * MapperInterface - */ void setUserMapper(MapperInterface mapperClass) { if (mapperClass == null) { @@ -107,13 +69,6 @@ void setUserMapper(MapperInterface mapperClass) { this.userMapperClass = mapperClass; } - /** - * used by the GridUserFactory to set Distinguished Name. This method has - * package visibility. - * - * @param dnString - * String - */ void setDistinguishedName(String dnString) { if (dnString == null) { @@ -122,68 +77,32 @@ void setDistinguishedName(String dnString) { this.subjectDN = new DistinguishedName(dnString); } - /** - * Get GridUser Distinguish Name. - * - * @return String - */ public String getDn() { String dn = this.subjectDN.getDN(); return dn; } - /** - * Get GridUser Domain Name. Used for metadada purpose. - * - * @return DistinguishedName - */ public DistinguishedName getDistinguishedName() { return subjectDN; } - /** - * used by the GridUserFactory to set Proxy String. This method has package - * visibility. - * - * @param proxy - * String - */ void setProxyString(String proxy) { this.proxyString = proxy; } - /** - * Get Proxy certificate if there. Else return null. - * - * - * @return String - */ public String getProxyString() { return this.proxyString; } - /** - * Get Proxy certificate if there. Else return null. - * - * - * @return String - */ public String getUserCredentials() { return this.proxyString; } - /** - * Return the local user on wich the GridUser is mapped. This method is - * abstract. - * - * @throws CannotMapUserException - * @return LocalUser - */ public LocalUser getLocalUser() throws CannotMapUserException { if (localUser == null) { @@ -193,37 +112,21 @@ public LocalUser getLocalUser() throws CannotMapUserException { } else { localUser = userMapperClass.map(getDn(), null); } - } catch (CannotMapUserException ex) { - // log the operation that failed - log.error("Error in mapping '" + subjectDN.getX500DN_rfc1779() - + "' to a local user: " + ex.getMessage()); - // re-throw same exception - throw ex; + } catch (CannotMapUserException e) { + log.error("Mapping error: {}. Subject='{}'",e.getMessage(), + subjectDN.getX500DN_rfc1779(),e); + throw e; } } return localUser; } - /** - * @return - */ public abstract String[] getFQANsAsString(); - /** - * @return - */ public abstract FQAN[] getFQANs(); - /** - * @return - */ public abstract boolean hasVoms(); - /** - * Return the main Virtual Organization of the User. This method is abstract. - * - * @return VO - */ public abstract VO getVO(); } diff --git a/src/main/java/it/grid/storm/griduser/DNMatchingRule.java b/src/main/java/it/grid/storm/griduser/DNMatchingRule.java index 7fbc5c2a..ae8fc1f8 100644 --- a/src/main/java/it/grid/storm/griduser/DNMatchingRule.java +++ b/src/main/java/it/grid/storm/griduser/DNMatchingRule.java @@ -35,26 +35,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - *

- * Title: - *

- * - *

- * Description: - *

- * - *

- * Copyright: Copyright (c) 2006 - *

- * - *

- * Company: INFN-CNAF - *

- * - * @author R.Zappi - * @version 1.1 - */ public class DNMatchingRule { private static final Logger log = LoggerFactory @@ -127,17 +107,16 @@ public DNMatchingRule(String regularExpressionRule) { for (String rule : regularExpressionRule.split("/")) { if (!rule.contains("=")) { if (!(rule.trim().isEmpty() || rule.equals(ADMIT_ALL))) { - log.warn("Malformed DN regex element \'" + rule - + "\' it does not contains \'=\' key-value separator"); + log.warn("Malformed DN regex element '{}' " + + "it does not contains \'=\' key-value separator", rule); } continue; } String[] ruleCoupple = rule.split("="); if (ruleCoupple.length != 2) { log - .warn("Malformed DN regex element \'" - + rule - + "\' it does not contains the key or contains more \'=\' separators"); + .warn("Malformed DN regex element '{}' it does not contains " + + "the key or contains more \'=\' separators", rule); continue; } switch (DNFields.fromString(ruleCoupple[0])) { @@ -167,20 +146,6 @@ public DNMatchingRule(String regularExpressionRule) { initPatterns(); } - /** - * private method used to initialize everything - * - * @param countryPatternString - * String - * @param organizationPatternString - * String - * @param organizationalUnitPatternString - * String - * @param localityPatternString - * String - * @param commonNameString - * String - */ private void initPatterns() { // C country @@ -234,20 +199,6 @@ private static boolean isMatchAll(String pattern) { || pattern.trim().equals(".*"); } - /** - * Constructor with explicited Pattern String - * - * @param countryPatternString - * String - * @param organizationPatternString - * String - * @param organizationalUnitPatternString - * String - * @param localityPatternString - * String - * @param commonNameString - * String - */ public DNMatchingRule(String countryPatternString, String organizationPatternString, String organizationalUnitPatternString, String localityPatternString, String commonNamePatternString, @@ -272,14 +223,6 @@ && isMatchAll(commonNamePatternString) && isMatchAll(domainComponentPatternString); } - /** - * - * @param principalDN - * DistinguishedName - * @return boolean - * - * @todo Implement performance. After first false exit with false! - */ public boolean match(DistinguishedName principalDN) throws IllegalArgumentException { diff --git a/src/main/java/it/grid/storm/griduser/DistinguishedName.java b/src/main/java/it/grid/storm/griduser/DistinguishedName.java index 169658de..d7c0fdbe 100644 --- a/src/main/java/it/grid/storm/griduser/DistinguishedName.java +++ b/src/main/java/it/grid/storm/griduser/DistinguishedName.java @@ -28,7 +28,6 @@ package it.grid.storm.griduser; -import it.grid.storm.authz.path.model.PathOperation; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -38,42 +37,10 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - *

- * Title: - *

- * - *

- * Description: - *

- * - *

- * Copyright: Copyright (c) 2006 - *

- * - *

- * Company: INFN-CNAF - *

- * - * @author R.Zappi - * @version 1.0 - */ public class DistinguishedName implements SubjectAttribute { private static final Logger log = LoggerFactory .getLogger(DistinguishedName.class); - /** - * C Country Name ST State Or ProvinceName O Organization Name OU - * Organizational Unit Name L Locality Name CN Common Name EMail EMail address - * DC Domain Component - * - * "/C=IT/O=INFN/OU=Personal Certificate/L=CNAF/CN=Luca Magnoni/Email=luca.magnoni@cnaf.infn.it" - * "/DC=ch/DC=cern/OU=Organic Units/OU=Users/CN=elanciot/CN=576215/CN=Elisa Lanciotti" - * - * New in StoRM 1.4: service certificate support (please note the '/' char - * into the CN value...) - * "/DC=org/DC=doegrids/OU=Services/CN=sam/cdfsam1.cr.cnaf.infn.it" - */ private String countryName = null; private String provinceName = null; @@ -102,7 +69,6 @@ public DistinguishedName(String stringDN) { } if (commaIndex > -1) { parseDNcommed(); - // Java 1.6 - use the new constructor builderWithMap(stringDN); } @@ -128,7 +94,6 @@ private void builderWithMap(String stringDN) { if (pairs.size() > 0) { log .error("To use this functionality (DN rfc 2253) you have to recompile with Java 1.6"); - // x500DN = new X500Principal(stringDN, pairs); } } @@ -179,23 +144,6 @@ private void assignAttributes(String[] dnChunk) { private void parseDNslahed() { - /** - * New parser. Split by / doesn't work since DN could contain attributes - * with a '/' char as valid value. - * - * The idea is start from the end of the DN string: - * - * - get last index of '=' char - get last index of '\' char on the left of - * the '=' - Substring from the index obtained. - Add the resulting - * substring as an attribute-value pair of the DN - Cycle on each pair - * - * In this way, at the end of the cycle the List will contains the whole set - * of attribute-value pairs composing the DN, in the reverse order. Then, a - * reverse add to a string buffer, separated with ',' , compose the final DN - * representation in comma separated String. - * - */ - ArrayList list = new ArrayList(); String DN = distinguishedName; boolean stop = false; @@ -248,7 +196,6 @@ private void parseDNslahed() { private void parseDNcommed() { String[] attributes = distinguishedName.split(","); - // TODO set properly the canonizedDN string assignAttributes(attributes); } diff --git a/src/main/java/it/grid/storm/griduser/GridUser.java b/src/main/java/it/grid/storm/griduser/GridUser.java index f20b4f01..534d783f 100644 --- a/src/main/java/it/grid/storm/griduser/GridUser.java +++ b/src/main/java/it/grid/storm/griduser/GridUser.java @@ -30,19 +30,6 @@ import it.grid.storm.common.types.*; -/** - * Title: - *

- * Description: - *

- * Copyright: Copyright (c) 2006 - *

- * Company: INFN-CNAF - *

- * - * @author R.Zappi - * @version 1.0 - */ class GridUser extends AbstractGridUser { GridUser(MapperInterface mapper, String distinguishedName) { @@ -55,17 +42,7 @@ class GridUser extends AbstractGridUser { super(mapper, distinguishedName, proxy); } - /* - * (non-Javadoc) - * - * @see it.grid.storm.griduser.AbstractGridUser#getVO() - */ - /** - * Return the main Virtual Organization of the User. Since User is presenting - * without VOMS Proxy, then default VO is named NO_VO. - */ public VO getVO() { - VO vo = VO.makeNoVo(); return vo; } diff --git a/src/main/java/it/grid/storm/griduser/GridUserFactory.java b/src/main/java/it/grid/storm/griduser/GridUserFactory.java index 1ed370b5..a6e4ce4f 100644 --- a/src/main/java/it/grid/storm/griduser/GridUserFactory.java +++ b/src/main/java/it/grid/storm/griduser/GridUserFactory.java @@ -37,26 +37,6 @@ import org.slf4j.Logger; -/** - *

- * Title: - *

- * - *

- * Description: - *

- * - *

- * Copyright: Copyright (c) 2006 - *

- * - *

- * Company: INFN-CNAF - *

- * - * @author R.Zappi - * @version 1.0 - */ public class GridUserFactory { private static final Logger log = GridUserManager.log; @@ -106,7 +86,7 @@ void setUserMapper(String mapperClassName) throws GridUserException { GridUserInterface createGridUser(String distinguishName) { GridUserInterface user = new GridUser(defaultMapperClass, distinguishName); - log.debug("Created new Grid User (NO VOMS) : " + user); + log.debug("Created new Grid User (NO VOMS) : {}", user); return user; } @@ -120,7 +100,7 @@ GridUserInterface createGridUser(String distinguishName, String proxyString) { GridUserInterface user = new GridUser(defaultMapperClass, distinguishName, proxyString); - log.debug("Created new Grid User (NO VOMS with PROXY) : " + user); + log.debug("Created new Grid User (NO VOMS with PROXY) : {}", user); return user; } @@ -137,12 +117,10 @@ GridUserInterface createGridUser(String distinguishName, FQAN[] fqans) try { user = new VomsGridUser(defaultMapperClass, distinguishName, fqans); } catch (IllegalArgumentException e) { - log - .error("Unexpected error on VomsGridUser creation. Contact StoRM Support : IllegalArgumentException " - + e.getMessage()); + log.error(e.getMessage(), e); throw e; } - log.debug("Created new Grid User (VOMS USER) : " + user); + log.debug("Created new Grid User (VOMS USER) : {}", user); return user; } @@ -160,12 +138,10 @@ GridUserInterface createGridUser(String distinguishName, FQAN[] fqans, user = new VomsGridUser(defaultMapperClass, distinguishName, proxyString, fqans); } catch (IllegalArgumentException e) { - log - .error("Unexpected error on VomsGridUser creation. Contact StoRM Support : IllegalArgumentException " - + e.getMessage()); + log.error(e.getMessage(), e); throw e; } - log.debug("Created new Grid User (VOMS USER with PROXY) : " + user); + log.debug("Created new Grid User (VOMS USER with PROXY) : {}" , user); return user; } @@ -182,7 +158,7 @@ GridUserInterface decode(Map inputParam) { try { fqansList = Arrays.asList((Object[]) inputParam.get(member_Fqans)); } catch (NullPointerException e) { - log.debug("Empty FQAN[] found." + e); + log.debug("Empty FQAN[] found.", e); } // Destination Fqans array @@ -191,30 +167,27 @@ GridUserInterface decode(Map inputParam) { if (fqansList != null) { // Define FQAN[] fqans = new FQAN[fqansList.size()]; - log.debug("fqans_vector Size: " + fqansList.size()); + log.debug("fqans_vector Size: {}" , fqansList.size()); for (int i = 0; i < fqansList.size(); i++) { + String fqan_string = (String) fqansList.get(i); - log.debug("FQAN[" + i + "]:" + fqan_string); - // Create Fqan + log.debug("FQAN[{}]: {}",i, fqan_string); + FQAN fq = new FQAN(fqan_string); - // Add this into Array of Fqans fqans[i] = fq; } } - // Setting up VomsGridUser if (dnString != null) { - log.debug("DN: " + dnString); + log.debug("DN: {}" , dnString); // Creation of srm GridUser type if (fqans != null && fqans.length > 0) { log.debug("VomsGU with FQAN"); try { return createGridUser(dnString, fqans); } catch (IllegalArgumentException e) { - log - .error("Unexpected error on voms grid user creation. Contact StoRM Support : IllegalArgumentException " - + e.getMessage()); + log.error(e.getMessage(), e); } } else { return createGridUser(dnString); @@ -223,14 +196,6 @@ GridUserInterface decode(Map inputParam) { return null; } - /** - * Method used by Grid User (or Voms Grid User) to instatiate the mapper. - * - * @param mapperClass - * Class - * @return MapperInterface - * @throws GridUserException - */ MapperInterface makeMapperInstance(Class mapperClass) throws CannotMapUserException { @@ -256,25 +221,12 @@ MapperInterface makeMapperInstance(Class mapperClass) log.error("Unable to instantiate the Mapper Driver. Generic problem..", ex); throw new CannotMapUserException( - "Unable to instantiate the Mapper Driver. Generic problem..", ex); + "Unable to instantiate the Mapper Driver", ex); } return mapperInstance; } - /** - * PRIVATE METHODs - */ - - /** - * - * Mapper Factory - * - * @param mapperClassName - * String - * @return Class - * @throws GridUserException - */ private MapperInterface makeMapperClass(String mapperClassName) throws GridUserException { @@ -319,16 +271,12 @@ private MapperInterface makeMapperClass(String mapperClassName) try { mapper = (MapperInterface) method.invoke(this, null); } catch (IllegalArgumentException e) { - log - .error("makeMapperClass EXCEPTION during getInstance method invocation. " - + e); + log.error(e.getMessage(), e); throw new GridUserException( "Cannot instantiate Mapper Driver using getInstance for Mapper Driver named :'" + mapperClassName + "'"); } catch (InvocationTargetException e) { - log - .error("makeMapperClass EXCEPTION during getInstance method invocation. " - + e); + log.error(e.getMessage(), e); throw new GridUserException( "Cannot instantiate Mapper Driver using getInstance for Mapper Driver named :'" + mapperClassName + "'"); @@ -341,29 +289,26 @@ private MapperInterface makeMapperClass(String mapperClassName) + mapperClassName + "'"); } } catch (SecurityException e) { - log - .error("makeMapperClass EXCEPTION during getMethod(\"getInstance\") method invocation. " - + e); + log.error(e.getMessage(), e); throw new GridUserException( "Cannot instantiate Mapper Driver using getInstance for Mapper Driver named :'" + mapperClassName + "'"); } catch (NoSuchMethodException e) { - log - .error("Unable to instantiate the class using eiter no args constructor niether getInstance method. " - + e); + log.error(e.getMessage(), e); throw new GridUserException( "Cannot instantiate Mapper Driver using new or getInstance for Mapper Driver named :'" + mapperClassName + "'"); } } - } catch (IllegalAccessException ex) { - log.error("makeMapperClass EXCEPTION. " + ex); + } catch (IllegalAccessException e) { + log.error(e.getMessage(), e); throw new GridUserException( "Cannot create a new Instance of the Mapper Driver named :'" + mapperClassName + "'"); - } catch (InstantiationException ex) { - log.error("makeMapperClass EXCEPTION. " + ex); + } catch (InstantiationException e) { + + log.error(e.getMessage(), e); throw new GridUserException( "Cannot create a new Instance of the Mapper Driver named :'" + mapperClassName + "'"); diff --git a/src/main/java/it/grid/storm/griduser/GridUserManager.java b/src/main/java/it/grid/storm/griduser/GridUserManager.java index a77f3351..dfc1adb4 100644 --- a/src/main/java/it/grid/storm/griduser/GridUserManager.java +++ b/src/main/java/it/grid/storm/griduser/GridUserManager.java @@ -35,26 +35,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - *

- * Title: - *

- * - *

- * Description: - *

- * - *

- * Copyright: Copyright (c) 2006 - *

- * - *

- * Company: INFN-CNAF - *

- * - * @author R.Zappi - * @version 1.0 - */ public class GridUserManager { static final Logger log = LoggerFactory.getLogger(GridUserManager.class); @@ -81,16 +61,10 @@ public static String getMapperClassName() { return config.getGridUserMapperClassname(); } - /** - * PUBLIC and STATIC methods - */ - public static GridUserInterface makeVOMSGridUser(String dn, String proxy, FQAN[] fqans) throws IllegalArgumentException { if (proxy == null || dn == null || fqans == null || fqans.length == 0) { - log.error("Unable to make VomsGridUser. Inavlid arguments: dn=\'" + dn - + "\' fqans=\'" + fqans + "\' proxy=\'" + proxy + "\'"); throw new IllegalArgumentException( "Unable to make VomsGridUser. Inavlid arguments: dn=\'" + dn + "\' fqans=\'" + fqans + "\' proxy=\'" + proxy + "\'"); @@ -99,25 +73,16 @@ public static GridUserInterface makeVOMSGridUser(String dn, String proxy, try { gridUser = userFactory.createGridUser(dn, fqans, proxy); } catch (IllegalArgumentException e) { - log - .error("Unexpected error on voms grid user creation. Contact StoRM Support : IllegalArgumentException " - + e.getMessage()); + log.error(e.getMessage(), e); } return gridUser; } - /** - * @param dn - * @param vo - * @return - */ public static GridUserInterface makeVOMSGridUser(String dn, String vo) throws IllegalArgumentException { if (vo == null || dn == null) { - log.error("Unable to make VomsGridUser. Inavlid arguments: dn=\'" + dn - + "\' vo=\'" + vo + "\'"); throw new IllegalArgumentException( "Unable to make VomsGridUser. Inavlid arguments: dn=\'" + dn + "\' vo=\'" + vo + "\'"); @@ -128,25 +93,15 @@ public static GridUserInterface makeVOMSGridUser(String dn, String vo) try { gridUser = userFactory.createGridUser(dn, fqans); } catch (IllegalArgumentException e) { - log - .error("Unexpected error on voms grid user creation. Contact StoRM Support : IllegalArgumentException " - + e.getMessage()); + log.error(e.getMessage(), e); } return gridUser; } - /** - * @param dn - * @param fqans - * @return - * @throws IllegalArgumentException - */ public static GridUserInterface makeVOMSGridUser(String dn, String[] fqansString) throws IllegalArgumentException { if (fqansString == null || fqansString.length == 0) { - log.error("Unable to make VomsGridUser. Invalid fqansString argument: " - + fqansString); throw new IllegalArgumentException( "Unable to make VomsGridUser. Invalid fqansString argument: " + fqansString); @@ -158,18 +113,10 @@ public static GridUserInterface makeVOMSGridUser(String dn, return userFactory.createGridUser(dn, fqans); } - /** - * @param dn - * @param fqans - * @return - * @throws IllegalArgumentException - */ public static GridUserInterface makeVOMSGridUser(String dn, FQAN[] fqans) throws IllegalArgumentException { if (fqans == null || fqans.length == 0) { - log - .error("Unable to make VomsGridUser. Invalid fqans argument: " + fqans); throw new IllegalArgumentException( "Unable to make VomsGridUser. Invalid fqans argument: " + fqans); } @@ -187,7 +134,6 @@ public static GridUserInterface makeGridUser(String dn, String proxy) { } public static GridUserInterface makeSAGridUser() { - GridUserInterface result = null; String dn = "/DC=it/DC=infngrid/OU=Services/CN=storm"; result = userFactory.createGridUser(dn); @@ -198,4 +144,4 @@ public static GridUserInterface decode(Map inputParam) { return userFactory.decode(inputParam); } -} +} \ No newline at end of file diff --git a/src/main/java/it/grid/storm/griduser/LcmapsJNAMapper.java b/src/main/java/it/grid/storm/griduser/LcmapsJNAMapper.java index 5a8f707f..1e6fa6bd 100644 --- a/src/main/java/it/grid/storm/griduser/LcmapsJNAMapper.java +++ b/src/main/java/it/grid/storm/griduser/LcmapsJNAMapper.java @@ -35,7 +35,7 @@ public class LcmapsJNAMapper implements MapperInterface { private static final Object lock = new Object(); - /** To log LCMAPS failures. */ + private static final Logger log = LoggerFactory .getLogger(LcmapsJNAMapper.class); @@ -63,24 +63,23 @@ public LocalUser map(String dn, String[] fqans) throws CannotMapUserException { LocalUser mappedUser = null; synchronized (LcmapsJNAMapper.lock) { - log.debug("Mapping user with dn = " + dn + " and fqans = " - + ArrayUtils.toString(fqans)); + log.debug("Mapping user with dn = {} and fqans='{}'", + dn, ArrayUtils.toString(fqans)); log.debug("Initializing Lcmaps"); String lcmapsLogFile = getLcmapsLogFile(); - log.debug("Lcmaps log file is " + lcmapsLogFile); + log.debug("Lcmaps log file is {}", lcmapsLogFile); int retVal = LcmapsInterface.INSTANCE.lcmaps_init_and_logfile( lcmapsLogFile, null, LCMAPS_LOG_TYPE); if (retVal != 0) { - log.error("Unable to initialize lcmaps. Return value is " + retVal); + log.error("Unable to initialize lcmaps. Return value is {}" , retVal); throw new CannotMapUserException( "Unable to initialize lcmaps. Return value is " + retVal); } retVal = LcmapsAccountInterface.INSTANCE .lcmaps_account_info_init(account); if (retVal != 0) { - log.error("Unable to initialize lcmaps. Return value is " + retVal); throw new CannotMapUserException( "Unable to initialize lcmaps. Return value is " + retVal); } @@ -89,39 +88,38 @@ public LocalUser map(String dn, String[] fqans) throws CannotMapUserException { retVal = LcmapsPoolindexInterface.INSTANCE .lcmaps_return_account_without_gsi(dn, fqans, numFqans, 0, account); } catch (LastErrorException e) { - log.error("Unable to map user dn <" + dn + "> fqans <" - + ArrayUtils.toString(fqans) + "> . LastErrorException: " - + e.getMessage() + " , error code = " + e.getErrorCode()); + log.error("Unable to map user dn <{}> fqans <{}>. Error: {}. Error code: {}", + dn, ArrayUtils.toString(fqans), + e.getMessage(), + e.getErrorCode(), + e); throw new CannotMapUserException( "Unable to initialize lcmaps. Return value is " + retVal); } if (retVal != 0) { - log.error("Unable to map user dn <" + dn + "> fqans <" - + ArrayUtils.toString(fqans) + "> . Return value is " + retVal); + log.error("Unable to map user dn <{}> fqans <{}>. Retval: {}", + dn, ArrayUtils.toString(fqans), + retVal); throw new CannotMapUserException("Unable to map user dn <" + dn + "> fqans <" + ArrayUtils.toString(fqans) + "> . Return value is " + retVal); } + if (account.uid < 0) { - log.error("Unacceptable lower than zero uid returned by Lcmaps : " - + account.uid + " . Mapping error"); + log.error("Negative uid returned by lcmaps: {}", account.uid); throw new CannotMapUserException( "Unacceptable lower than zero uid returned by Lcmaps : " + account.uid + " . Mapping error"); } if (account.npgid < 0 || account.nsgid < 0) { - log - .error("Unacceptable primary or secondary gid array size returned by Lcmaps : primary = " - + account.npgid - + ", secondary = " - + account.nsgid - + ",. Mapping error"); + log.error("Negative primary or secondary gid array size. npgid: {} nsgid: {}", + account.npgid, account.nsgid); + throw new CannotMapUserException( - "Unacceptable primary or secondary gid array size returned by Lcmaps : primary = " + "Negative primary or secondary gid array size returned by Lcmaps : primary = " + account.npgid + ", secondary = " - + account.nsgid - + ",. Mapping error"); + + account.nsgid +". Mapping error"); } int[] gids = null; int numGids = account.npgid + account.nsgid; @@ -147,10 +145,11 @@ public LocalUser map(String dn, String[] fqans) throws CannotMapUserException { gids = account.pgid_list.getPointer().getIntArray(0, account.npgid); } } - log.info("Mapped user to : "); + log.info("Mapped user to : ", + account.uid, + ArrayUtils.toString(gids)); mappedUser = new LocalUser(account.uid, gids, numGids); } return mappedUser; } -} +} \ No newline at end of file diff --git a/src/main/java/it/grid/storm/griduser/LocalUser.java b/src/main/java/it/grid/storm/griduser/LocalUser.java index f8952b40..8056fd48 100644 --- a/src/main/java/it/grid/storm/griduser/LocalUser.java +++ b/src/main/java/it/grid/storm/griduser/LocalUser.java @@ -20,42 +20,13 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * Encapsulates a POSIX account numeric data: the UID, the primary GID and the - * supplementary GIDs (if any). This object is immutable, to all extents. - * - *

- * The uid_t and gid_t types are presently unsigned - * 32-bit integers on Linux, but they are wrapped in Java as int, - * as the special value -1 used by setuid() is of no - * concern here... - * - *

- * XXX: is this class a misnomer? - * - * @author Riccardo Murri , EGRID Project, ICTP - * @version $Revision: 1.9 $ - * @see it.grid.storm.griduser.swig.LocalUserInfo; - */ public class LocalUser { private static final Logger log = LoggerFactory.getLogger(LocalUser.class); - private int uid; /* FIXME: uid_t on Linux is unsigned 32-bit */ + private int uid; private int[] gids; - // --- constructors --- // - - /** - * Constructor taking UID, and a list of GIDs and the size of this list. The - * size of the list needs to be passed as an explicit parameter, to cater for - * naive arrays created by the SWIG interface wrapper, which have no - * .length attribute. The list of GIDs is copied into a proper - * Java array. - * - * @todo XXX: use objects from localuser_info instead of copying; problems - * with "fake" Java arrays should be gone now... (added 2006-03-15) - */ public LocalUser(int uid, int[] gids, long ngids) { this.uid = uid; @@ -66,9 +37,6 @@ public LocalUser(int uid, int[] gids, long ngids) { this.gids[i] = gids[i]; } - /** - * Constructor taking UID, GID and list of supplementary GIDs. - */ public LocalUser(int uid, int gid, int[] supplementaryGids) { this.uid = uid; @@ -80,24 +48,11 @@ public LocalUser(int uid, int gid, int[] supplementaryGids) { this.gids[i] = supplementaryGids[i - 1]; } - /** - * Constructor taking UID and GID. The list of supplementary GIDs is - * initialized to an empty array. - */ public LocalUser(int uid, int gid) { this(uid, gid, new int[0]); } - /** - * Constructor that requires the String representation of a LocalUser. The - * String representation consists of at least two comma separated integers, - * the first one being the uid, followed by all gids. For example: "501,501" - * "501,123,332,1223" - * - * In case the supplied String is null or invalid, by default a LocalUser with - * uid=501 and one gid=501 is created. - */ public LocalUser(String uidgids) { this.uid = 501; @@ -132,42 +87,19 @@ public String toString() { return sb.toString(); } - /** - * Return the LocalUser Name String on wich the GridUser is mapped. A string - * format is needed by current version of native library to enforce ACL. - */ - public String getLocalUserName() { - return Integer.toString(getUid()); } - // --- public accessor methods --- // - public int getUid() { - return uid; } - /** - * Return an array holding the GIDs; the primary GID is at index 0. If no - * supplementary GIDs were provided at construction time, then the array will - * have length 1, and contain only the primary GID. - * - * @return int[] holding all GIDs, with the primary one at index 0. - */ public int[] getGids() { - return gids; } - /** - * Return the primary GID. - * - * @return the primary GID of this POSIX account. - */ public int getPrimaryGid() { - return gids[0]; } } diff --git a/src/main/java/it/grid/storm/griduser/MapperInterface.java b/src/main/java/it/grid/storm/griduser/MapperInterface.java index 6da0fb23..8199585f 100644 --- a/src/main/java/it/grid/storm/griduser/MapperInterface.java +++ b/src/main/java/it/grid/storm/griduser/MapperInterface.java @@ -20,26 +20,8 @@ import it.grid.storm.griduser.CannotMapUserException; import it.grid.storm.griduser.LocalUser; -/** - * Defines a template method for mapping Grid credentials to local account - * credentials. - */ interface MapperInterface { - /** - * Template factory method for Mapper objects. Takes Grid credentials (user - * certificate subject DN and an array of VOMS FQANs) and returns a new - * LocalUser object holding the local credentials (UID, GIDs) of the POSIX - * account the given Grid user is mapped to. - * - * @param dn - * Grid user certificate subject DN - * @param fqans - * array of VOMS FQANs - * - * @return a new LocalUser object holding the local credentials (UID, GIDs) of - * the POSIX account the given Grid user is mapped to. - */ public LocalUser map(final String dn, final String[] fqans) throws CannotMapUserException; } diff --git a/src/main/java/it/grid/storm/griduser/SimpleUserMapper.java b/src/main/java/it/grid/storm/griduser/SimpleUserMapper.java index e5e05c03..dbf6ed3a 100644 --- a/src/main/java/it/grid/storm/griduser/SimpleUserMapper.java +++ b/src/main/java/it/grid/storm/griduser/SimpleUserMapper.java @@ -31,45 +31,30 @@ public SimpleUserMapper() { } - /** - * Template factory method for Mapper objects. - * - * @param dn - * Grid user certificate subject DN - * @param fqans - * array of VOMS FQANs - * @return a new LocalUser object holding the local credentials (UID, GIDs) of - * the POSIX account the given Grid user is mapped to. - * @throws CannotMapUserException - * @todo Implement this it.grid.storm.griduser.MapperInterface method - */ public LocalUser map(String dn, String[] fqans) throws CannotMapUserException { LocalUser localUser = null; int uid = 0; int gid = 0; try { - // String[] retrieveUserCmd = new String[1]; String retrieveUserCmd = "id -r -u"; String userIdStr = getOutput(retrieveUserCmd); // log.debug("Output = "+userIdStr); uid = Integer.parseInt(userIdStr); - } catch (CannotMapUserException ex) { - log.error("Unable to retrieve User ID from the system." + ex); - throw ex; + } catch (CannotMapUserException e) { + log.error(e.getMessage(), e); + throw e; } catch (NumberFormatException nfe) { log.error("Getting UID returns a result different from a integer"); throw new CannotMapUserException(nfe); } try { - // String[] retrieveUserCmd = new String[0]; String retrieveUserCmd = "id -r -g"; String groupIdStr = getOutput(retrieveUserCmd); - // log.debug("Output = "+groupIdStr); gid = Integer.parseInt(groupIdStr); } catch (CannotMapUserException ex) { - log.error("Unable to retrieve Group ID from the system." + ex); + log.error("Unable to retrieve Group ID from the system." , ex); throw ex; } catch (NumberFormatException nfe) { log.error("Getting GID returns a result different from a integer"); @@ -80,29 +65,19 @@ public LocalUser map(String dn, String[] fqans) throws CannotMapUserException { return localUser; } - /** - * - * @param command - * String[] - * @return String - */ private String getOutput(String command) throws CannotMapUserException { String result = null; try { Process child = Runtime.getRuntime().exec(command); - // Get the input stream and read from it BufferedReader stdInput = new BufferedReader(new InputStreamReader( child.getInputStream())); BufferedReader stdError = new BufferedReader(new InputStreamReader( child.getErrorStream())); - // process the Command Output (Input for StoRM ;) ) String line; int row = 0; - // log.debug("UserInfo Command Output :"); while ((line = stdInput.readLine()) != null) { - // log.debug(row + ": " + line); boolean lineOk = processOutput(row, line); if (lineOk) { result = line; @@ -114,25 +89,21 @@ private String getOutput(String command) throws CannotMapUserException { // process the Errors String errLine; while ((errLine = stdError.readLine()) != null) { - log.warn("User Info Command Output contains an ERROR message " - + errLine); + log.warn("User Info Command Output contains an ERROR message {}", + errLine); throw new CannotMapUserException(errLine); } } catch (IOException ex) { - log.error("getUserInfo (id) I/O Exception: " + ex); + log.error("getUserInfo (id) I/O Exception: {}", ex); throw new CannotMapUserException(ex); } return result; } private boolean processOutput(int row, String line) { - boolean result = false; if (row >= 0) { - /** - * @todo : Implement a more smart check to verify the right line - */ result = true; } return result; diff --git a/src/main/java/it/grid/storm/griduser/StormLcmapsJNAMapper.java b/src/main/java/it/grid/storm/griduser/StormLcmapsJNAMapper.java index 321d59b7..bf813c72 100644 --- a/src/main/java/it/grid/storm/griduser/StormLcmapsJNAMapper.java +++ b/src/main/java/it/grid/storm/griduser/StormLcmapsJNAMapper.java @@ -33,7 +33,7 @@ public class StormLcmapsJNAMapper implements MapperInterface { private static final Logger log = LoggerFactory .getLogger(StormLcmapsJNAMapper.class); - /** To synchronize on LCMAPS invocation. */ + private final Object lock = new Object(); private final String LCMAPS_DEFAULT_LOG_FILE = "/var/log/lcmaps.log"; @@ -51,9 +51,6 @@ public static StormLcmapsJNAMapper getInstance() { return instance; } - /** - * @return lcmaps log file path - */ private String getLcmapsLogFile() { String lcmapsLogFile = System.getenv(LCMAPS_LOG_FILE_PATH_ENV_VARIABLE); @@ -63,12 +60,6 @@ private String getLcmapsLogFile() { return lcmapsLogFile.trim(); } - /* - * (non-Javadoc) - * - * @see it.grid.storm.griduser.MapperInterface#map(java.lang.String, - * java.lang.String[]) - */ public LocalUser map(final String dn, final String[] fqans) throws CannotMapUserException { @@ -82,12 +73,12 @@ public LocalUser map(final String dn, final String[] fqans) Errors error = StormLcmapsLibrary.Errors.getError(retVal); if (!error.equals(Errors.UNKNOW_ERROR)) { log - .error("Unable to call successfully native map_user() method. Return value is " - + error.toString()); + .error("Unable to call successfully native map_user() method. " + + "Return value is {}", error); } else { log - .error("Unable to call successfully native map_user() method. Return value is " - + retVal + " . This is an unknown return value"); + .error("Unable to call successfully native map_user() method. " + + "Unknown return value: {}", retVal); } throw new CannotMapUserException( "LCMAPS error, cannot map user credentials to local user."); @@ -96,4 +87,4 @@ public LocalUser map(final String dn, final String[] fqans) new int[] { groupId.get() }, 1); return localUser; } -} +} \ No newline at end of file diff --git a/src/main/java/it/grid/storm/griduser/VONameMatchingRule.java b/src/main/java/it/grid/storm/griduser/VONameMatchingRule.java index 8e3518ee..8791e53a 100644 --- a/src/main/java/it/grid/storm/griduser/VONameMatchingRule.java +++ b/src/main/java/it/grid/storm/griduser/VONameMatchingRule.java @@ -20,26 +20,6 @@ import java.util.regex.Pattern; import java.util.regex.Matcher; -/** - *

- * Title: - *

- * - *

- * Description: - *

- * - *

- * Copyright: Copyright (c) 2006 - *

- * - *

- * Company: INFN-CNAF - *

- * - * @author R.Zappi - * @version 1.0 - */ public class VONameMatchingRule { private static final String ADMIT_ALL = ".*"; @@ -47,12 +27,6 @@ public class VONameMatchingRule { private final String voNameString; private Pattern voNamePattern = null; - /** - * Default Constructor - * - * @param regularExpressionRule - * String - */ public VONameMatchingRule(String regularExpressionRule) { if ((regularExpressionRule == null) || (regularExpressionRule.equals("*"))) { @@ -68,12 +42,6 @@ public static VONameMatchingRule buildMatchAllVONameMatchingRule() { return new VONameMatchingRule(ADMIT_ALL); } - /** - * init - * - * @param regularExpressionRule - * String - */ private void initPattern() { // VOName @@ -85,18 +53,10 @@ private void initPattern() { } private static boolean isMatchAll(String pattern) { - return pattern == null || pattern.trim().equals("*") || pattern.trim().equals(".*"); } - /** - * Match voName with this MatchingRule - * - * @param voName - * String - * @return boolean - */ public boolean match(String voName) { boolean result = false; @@ -114,8 +74,6 @@ public String toString() { } public boolean isMatchAll() { - return isMatchAll(voNameString); } - -} +} \ No newline at end of file diff --git a/src/main/java/it/grid/storm/griduser/VomsGridUser.java b/src/main/java/it/grid/storm/griduser/VomsGridUser.java index 60f30c01..51ee46f1 100644 --- a/src/main/java/it/grid/storm/griduser/VomsGridUser.java +++ b/src/main/java/it/grid/storm/griduser/VomsGridUser.java @@ -47,8 +47,6 @@ class VomsGridUser extends GridUser implements Serializable { super(mapper, distinguishedName, proxy); if (fqansArray == null || fqansArray.length == 0) { - log.error("Unable to create VomsGridUser. Inavlid fqansArray argument: " - + fqansArray); throw new IllegalArgumentException( "Unable to create VomsGridUser. Inavlid fqansArray argument: " + fqansArray); @@ -61,8 +59,6 @@ class VomsGridUser extends GridUser implements Serializable { super(mapper, distinguishedName); if (fqansArray == null || fqansArray.length == 0) { - log.error("Unable to create VomsGridUser. Inavlid fqansArray argument: " - + fqansArray); throw new IllegalArgumentException( "Unable to create VomsGridUser. Inavlid fqansArray argument: " + fqansArray); @@ -70,8 +66,6 @@ class VomsGridUser extends GridUser implements Serializable { this.setFqans(fqansArray); } - // --- SETTER Methods --- // - private void setFqans(FQAN[] fqans) { this.fqans.clear(); @@ -89,7 +83,6 @@ public void addFqan(FQAN fqan) { } - // --- GETTER Methods --- // /** * Return true if any VOMS attributes are stored in this object. @@ -106,11 +99,6 @@ public boolean hasVoms() { return true; } - /* - * (non-Javadoc) - * - * @see it.grid.storm.griduser.GridUser#getFQANsAsString() - */ @Override public FQAN[] getFQANs() { @@ -121,11 +109,6 @@ public FQAN[] getFQANs() { return FQANs; } - /* - * (non-Javadoc) - * - * @see it.grid.storm.griduser.GridUser#getFQANsAsString() - */ @Override public String[] getFQANsAsString() { @@ -136,11 +119,6 @@ public String[] getFQANsAsString() { return FQANs; } - /* - * (non-Javadoc) - * - * @see it.grid.storm.griduser.GridUser#getVO() - */ public VO getVO() { VO result = VO.makeNoVo(); @@ -212,5 +190,4 @@ public boolean equals(Object obj) { } return result; } - -} +} \ No newline at end of file diff --git a/src/main/java/it/grid/storm/griduser/swig.OLD/README.txt b/src/main/java/it/grid/storm/griduser/swig.OLD/README.txt deleted file mode 100644 index b64af5bd..00000000 --- a/src/main/java/it/grid/storm/griduser/swig.OLD/README.txt +++ /dev/null @@ -1,21 +0,0 @@ -==== - - Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -==== - -Do not remove this directory! - -It is for output files from the SWIG interface generator, but no -source files should be in CVS here... diff --git a/src/main/java/it/grid/storm/griduser/swig/Copy of arrays_java.1.3.24.i.old b/src/main/java/it/grid/storm/griduser/swig/Copy of arrays_java.1.3.24.i.old deleted file mode 100644 index e57009ca..00000000 --- a/src/main/java/it/grid/storm/griduser/swig/Copy of arrays_java.1.3.24.i.old +++ /dev/null @@ -1,392 +0,0 @@ -/* arrays_java.i - * These typemaps give more natural support for arrays. The typemaps are not efficient - * as there is a lot of copying of the array values whenever the array is passed to C/C++ - * from Java and visa versa. The Java array is expected to be the same size as the C array. - * An exception is thrown if they are not. - - Example usage: - Wrapping: - - %include "arrays_java.i" - %inline %{ - short FiddleSticks[3]; - %} - - Use from Java like this: - - short[] fs = new short[] {10, 11, 12}; - example.setFiddleSticks(fs); - fs = example.getFiddleSticks(); - - */ - -/* Primitive array support is a combination of SWIG macros and functions in order to reduce - * code bloat and aid maintainability. The SWIG preprocessor expands the macros into functions - * for inclusion in the generated code. */ - -/* Array support functions declarations macro */ -%define JAVA_ARRAYS_DECL(CTYPE, JNITYPE, JAVATYPE, JFUNCNAME) -%{ -int SWIG_JavaArrayIn##JFUNCNAME (JNIEnv *jenv, JNITYPE **jarr, CTYPE **carr, JNITYPE##Array input); -void SWIG_JavaArrayArgout##JFUNCNAME (JNIEnv *jenv, JNITYPE *jarr, CTYPE *carr, JNITYPE##Array input); -JNITYPE##Array SWIG_JavaArrayOut##JFUNCNAME (JNIEnv *jenv, CTYPE *result, jsize sz); -%} -%enddef - -/* Array support functions macro */ -%define JAVA_ARRAYS_IMPL(CTYPE, JNITYPE, JAVATYPE, JFUNCNAME) -%{ -/* CTYPE[] support */ -int SWIG_JavaArrayIn##JFUNCNAME (JNIEnv *jenv, JNITYPE **jarr, CTYPE **carr, JNITYPE##Array input) { - int i; - jsize sz; - if (!input) { - SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array"); - return 0; - } - sz = JCALL1(GetArrayLength, jenv, input); - *jarr = JCALL2(Get##JAVATYPE##ArrayElements, jenv, input, 0); - if (!*jarr) - return 0; %} -#ifdef __cplusplus -%{ *carr = new CTYPE[sz]; %} -#else -%{ *carr = (CTYPE*) calloc(sz, sizeof(CTYPE)); %} -#endif -%{ if (!*carr) { - SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed"); - return 0; - } - for (i=0; i liblcmap_interface.so - `-- dlopen() --> liblcmaps_without_gsi.so - `-- dlopen() --> liblcmaps_good.so - -This has to be checked with the LCMAPS maintainer. - -UPDATE 2006-01: checked with LCMAPS maintainer; looks like the problem -is in the way JVM calls dlopen(), but the bug shows up only in SLC3, -not on Debian. Anyway, no one has a clue on this topic. - - - -2) UPDATE 2006-03-15: corrected memory leak by moving to a C++ version -of the lcmaps_interface; the "solution" below was not working, due to -free()ing memory while it was still being used by the JVM: the -lifetime of the underlying C/C++ structure must be *at least* equal to -the lifetime of the corresponding Java object. - -THE FOLLOWING IS THEREFORE INCORRECT: - - UPDATE 2006-01-24: Corrected memory leak in the lcmaps_interface.i - code; see comment in the file. I tested sample code that was - allocating a struct and passing it to Java, and it does not leak if we - are using the %newobject+%typemap(newfree) mathod. - -THE FOLLOWING REMARKS ARE THEREFORE OBSOLETE: - -This code *may have* a memory leak, in that the wrapper code in -VomsInfo.java actually does a shallow free() of the voms_info -structure:: - - protected void finalize() { - delete(); - } - - public void delete() - { - if(swigCPtr != 0 && swigCMemOwn) { - swigCMemOwn = false; - voms_interface.voms_info_delete(this); - } - swigCPtr = 0; - } - -If the Java objects corresponding to the C members of the structure -hold a reference to the C object underneath, then *all is OK.* - -If the objects corresponding to the C members of the structure are -*copies* of the C objects underneath, then *we have a memory leak.* - -If we have a memory leak, then a solution could be along these lines:: - - // override default delete() implementation - %typemap(javadestruct, methodname="delete") struct voms_info %{ - { - if(swigCPtr != 0 && swigCMemOwn) { - swigCMemOwn = false; - voms_interface.voms_info_delete(this); - } - swigCPtr = 0; - } - %} - // import voms_interface into voms_info - %typemap(javaimports) struct voms_info %{ - import it.grid.storm.griduser.swig.voms_interface; - %} - -But I have yet to read the memory management part of the SWIG -manual... - diff --git a/src/main/java/it/grid/storm/griduser/swig/Makefile b/src/main/java/it/grid/storm/griduser/swig/Makefile deleted file mode 100644 index d8182888..00000000 --- a/src/main/java/it/grid/storm/griduser/swig/Makefile +++ /dev/null @@ -1,129 +0,0 @@ -#!/usr/bin/make -f -# -# Makefile for building the StoRM LCMAPS C code -# interfaces on SLC3.0.x and LCG-2.4.0. -# -# -# Copyright (c) 2005,2006 Riccardo Murri -# for the EGRID/INFN joint project StoRM. -# -# You may copy, modify and distribute this code under the same terms as -# StoRM itself; see file LICENSE.txt -# -# $Id: Makefile,v 1.3 2007/05/16 09:50:04 lmagnoni Exp $ -# - -top_srcdir=. -stagedir=. -distdir=. -globalprefix=storm -backendprefix=backend -package=storm-backend -version=1.5.4 -PREFIX=/opt/storm/backend - -lcmaps_prefix=${lcmaps_location} -lcmaps_without_gsi_prefix=${lcmaps_without_gsi_location} -lcmaps_plugins_basic_prefix=${lcmaps_plugins_basic_location} -lcmaps_plugins_voms_prefix=${lcmaps_plugins_voms_location} - -jdk_prefix=${jdk_location} -swig_prefix=${swig_location} -architecture=${arch} - --include Makefile.inc - -NAME := lcmaps_interface - -# where to put binary output files -DESTDIR ?= . - -JAVA_PACKAGE ?= it.grid.storm.griduser.swig -JAVA_INCLUDES ?= \ - -I$(JAVA_HOME)/include \ - -I$(JAVA_HOME)/include/linux - -LCMAPS_INCLUDES ?= -I$(lcmaps_without_gsi_prefix)/include/glite/security/lcmaps_without_gsi -LCMAPS_LIBS ?= \ - $(LCMAPS_RETURN_POOLINDEX_WITHOUT_GSI_LIBS) \ - $(LCMAPS_WITHOUT_GSI_LIBS) \ - $(LCMAPS_DUMMY_BAD_LIBS) \ - $(LCMAPS_DUMMY_GOOD_LIBS) \ - $(LCMAPS_LOCALACCOUNT_LIBS) \ - $(LCMAPS_POOLACCOUNT_LIBS) \ - $(LCMAPS_POSIX_ENF_LIBS) \ - $(LCMAPS_VOMS_LOCALACCOUNT_LIBS) \ - $(LCMAPS_VOMS_LOCALGROUP_LIBS) \ - $(LCMAPS_VOMS_POOLACCOUNT_LIBS) \ - $(LCMAPS_VOMS_POOLGROUP_LIBS) \ - $(LCMAPS_VOMS_LIBS) - -lcmaps_prefix=${lcmaps_location} -lcmaps_without_gsi_prefix=${lcmaps_without_gsi_location} -lcmaps_plugins_basic_prefix=${lcmaps_plugins_basic_location} -lcmaps_plugins_voms_prefix=${lcmaps_plugins_voms_location} - - -LCMAPS_RETURN_POOLINDEX_WITHOUT_GSI_LIBS:=$(shell file=`if test -e $(lcmaps_without_gsi_prefix)/lib$(architecture)/liblcmaps_return_poolindex_without_gsi.so; then file=$(lcmaps_without_gsi_prefix)/lib$(architecture)/liblcmaps_return_poolindex_without_gsi.so; else file=/usr/lib$(architecture)/liblcmaps_return_poolindex_without_gsi.so; fi;`) -LCMAPS_WITHOUT_GSI_LIBS:=$(shell file=`if test -e $(lcmaps_without_gsi_prefix)/lib$(architecture)/liblcmaps_without_gsi.so; then file=$(lcmaps_without_gsi_prefix)/lib$(architecture)/liblcmaps_without_gsi.so; else file=/usr/lib$(architecture)/liblcmaps_without_gsi.so; fi;`) -LCMAPS_DUMMY_BAD_LIBS:=$(shell file=`if test -e $(lcmaps_plugin_basic_prefix)/lib$(architecture)/liblcmaps_dummy_bad.so; then file=$(lcmaps_plugins_basic_prefix)/lib$(architecture)/liblcmaps_dummy_bad.so; else file=/usr/lib$(architecture)/liblcmaps_dummy_bad.so; fi;`) -LCMAPS_DUMMY_GOOD_LIBS:=$(shell file=`if test -e $(lcmaps_pluging_basic_prefix)/lib$(architecture)/liblcmaps_dummy_good.so; then file=$(lcmaps_plugins_basic_prefix)/lib$(architecture)/liblcmaps_dummy_good.so; else file=/usr/lib$(architecture)/liblcmaps_dummy_good.so; fi;`) -LCMAPS_LOCALACCOUNT_LIBS:=$(shell file=`if test -e $(lcmaps_plugins_basic_prefix)/lib$(architecture)/liblcmaps_localaccount.so; then file=$(lcmaps_plugins_basic_prefix)/lib$(architecture)/liblcmaps_localaccount.so; else file=/usr/lib$(architecture)/liblcmaps_localaccount.so; fi;`) -LCMAPS_POOLACCOUNT_LIBS:=$(shell file=`if test -e $(lcmaps_plugins_basic_prefix)/lib$(architecture)/liblcmaps_poolaccount.so; then file=$(lcmaps_plugins_basic_prefix)/lib$(architecture)/liblcmaps_poolaccount.so; else file=/usr/lib$(architecture)/liblcmaps_poolaccount.so; fi;`) -LCMAPS_POSIX_ENF_LIBS:=$(shell file=`if test -e $(lcmaps_plugins_basic_prefix)/lib$(architecture)/liblcmaps_posix_enf.so; then file=$(lcmaps_plugins_basic_prefix)/lib$(architecture)/liblcmaps_posix_enf.so; else file=/usr/lib$(architecture)/liblcmaps_posix_enf.so; fi;`) -LCMAPS_VOMS_LOCALACCOUNT_LIBS:=$(shell file=`if test -e $(lcmaps_plugins_voms_prefix)/lib$(architecture)/liblcmaps_voms_localaccount.so; then file=$(lcmaps_plugins_voms_prefix)/lib$(architecture)/liblcmaps_voms_localaccount.so; else file=/usr/lib$(architecture)/liblcmaps_voms_localaccount.so; fi;`) -LCMAPS_VOMS_LOCALGROUP_LIBS:=$(shell file=`if test -e $(lcmaps_plugins_voms_prefix)/lib$(architecture)/liblcmaps_voms_localgroup.so; then file=$(lcmaps_plugins_voms_prefix)/lib$(architecture)/liblcmaps_voms_localgroup.so; else file=/usr/lib$(architecture)/liblcmaps_voms_localgroup.so; fi;`) -LCMAPS_VOMS_POOLACCOUNT_LIBS:=$(shell file=`if test -e $(lcmaps_plugins_voms_prefix)/lib$(architecture)/liblcmaps_voms_poolaccount.so; then file=$(lcmaps_plugins_voms_prefix)/lib$(architecture)/liblcmaps_voms_poolaccount.so; else file=/usr/lib$(architecture)/liblcmaps_voms_poolaccount.so; fi;`) -LCMAPS_VOMS_POOLGROUP_LIBS:=$(shell file=`if test -e $(lcmaps_plugins_voms_prefix)/lib$(architecture)/liblcmaps_voms_poolgroup.so; then file=$(lcmaps_plugins_voms_prefix)/lib$(architecture)/liblcmaps_voms_poolgroup.so; else file=/usr/lib$(architecture)/liblcmaps_voms_poolgroup.so; fi;`) -LCMAPS_VOMS_LIBS:=$(shell file=`if test -e $(lcmaps_plugins_voms_prefix)/lib$(architecture)/liblcmaps_voms.so; then file=$(lcmaps_plugins_voms_prefix)/lib$(architecture)/liblcmaps_voms.so; else file=/usr/lib$(architecture)/liblcmaps_voms.so; fi;`) - -LIB_INCLUDES ?= -I$(libacl_devel_prefix)/usr/include -I$(libattr_devel_prefix)/usr/include -I$(libacl_devel_prefix)/include -I$(libattr_devel_prefix)/include -I/usr/include - -# the swig binary -SWIG_BIN ?= $(swig_prefix)/bin/swig - - -### NO CUSTOMIZATION BELOW THIS LINE!! - -override CXXFLAGS += -DDEBUG -D__USE_BSD -Wall -O2 -override INCLUDES += $(JAVA_INCLUDES) $(LIB_INCLUDES) $(LCMAPS_INCLUDES) -override LIBS += $(LCMAPS_LIBS) - -swig_interface := lcmaps_interface.i -h := lcmaps_interface.h -srcs := lcmaps_interface.cpp lcmaps_interface_wrap.cxx - -swig_output := lcmaps_interface_wrap.cxx \ - lcmaps_interface.java \ - lcmaps_interfaceJNI.java \ - localuser_info.java - - - -all: swig libso -#$(DESTDIR)/liblcmaps_interface.so - -libso: $(srcs) $(h) - $(CXX) -shared -fPIC -o $(DESTDIR)/liblcmaps_interface.so \ - $(CXXFLAGS) $(INCLUDES) $(srcs) $(LIBS) - -.PHONY: swig -swig: $(swig_output) -$(swig_output): $(swig_interface) - $(SWIG_BIN) -c++ -java -package $(JAVA_PACKAGE) $(swig_interface) - - -# FIXME: tests need a more complex incantation... -.PHONY: lcmaps_interface_test -lcmaps_interface_test: TestLcmapsInterface.class - java -Djava.library.path=. TestLcmapsInterface -TestLcmapsInterface.class: TestLcmapsInterface.java - javac -source 1.4 TestLcmapsInterface.java - - -.PHONY: clean swigclean extraclean -clean: - rm -f *~ $(objs) *.class -swigclean: - rm -f $(swig_output) -extraclean: clean swigclean diff --git a/src/main/java/it/grid/storm/griduser/swig/arrays_java.1.3.24.i b/src/main/java/it/grid/storm/griduser/swig/arrays_java.1.3.24.i deleted file mode 100644 index e57009ca..00000000 --- a/src/main/java/it/grid/storm/griduser/swig/arrays_java.1.3.24.i +++ /dev/null @@ -1,392 +0,0 @@ -/* arrays_java.i - * These typemaps give more natural support for arrays. The typemaps are not efficient - * as there is a lot of copying of the array values whenever the array is passed to C/C++ - * from Java and visa versa. The Java array is expected to be the same size as the C array. - * An exception is thrown if they are not. - - Example usage: - Wrapping: - - %include "arrays_java.i" - %inline %{ - short FiddleSticks[3]; - %} - - Use from Java like this: - - short[] fs = new short[] {10, 11, 12}; - example.setFiddleSticks(fs); - fs = example.getFiddleSticks(); - - */ - -/* Primitive array support is a combination of SWIG macros and functions in order to reduce - * code bloat and aid maintainability. The SWIG preprocessor expands the macros into functions - * for inclusion in the generated code. */ - -/* Array support functions declarations macro */ -%define JAVA_ARRAYS_DECL(CTYPE, JNITYPE, JAVATYPE, JFUNCNAME) -%{ -int SWIG_JavaArrayIn##JFUNCNAME (JNIEnv *jenv, JNITYPE **jarr, CTYPE **carr, JNITYPE##Array input); -void SWIG_JavaArrayArgout##JFUNCNAME (JNIEnv *jenv, JNITYPE *jarr, CTYPE *carr, JNITYPE##Array input); -JNITYPE##Array SWIG_JavaArrayOut##JFUNCNAME (JNIEnv *jenv, CTYPE *result, jsize sz); -%} -%enddef - -/* Array support functions macro */ -%define JAVA_ARRAYS_IMPL(CTYPE, JNITYPE, JAVATYPE, JFUNCNAME) -%{ -/* CTYPE[] support */ -int SWIG_JavaArrayIn##JFUNCNAME (JNIEnv *jenv, JNITYPE **jarr, CTYPE **carr, JNITYPE##Array input) { - int i; - jsize sz; - if (!input) { - SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array"); - return 0; - } - sz = JCALL1(GetArrayLength, jenv, input); - *jarr = JCALL2(Get##JAVATYPE##ArrayElements, jenv, input, 0); - if (!*jarr) - return 0; %} -#ifdef __cplusplus -%{ *carr = new CTYPE[sz]; %} -#else -%{ *carr = (CTYPE*) calloc(sz, sizeof(CTYPE)); %} -#endif -%{ if (!*carr) { - SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed"); - return 0; - } - for (i=0; i - * - * Utility functions for mapping grid user credentials to a local - * account with LCMAPS. - * - *

These bindings are tailored to provide only the subset of - * functionalities needed by the StoRM ``GridUser`` object, namely, - * get a local user UID and groups from the certificate subject DN and - * the VOMS FQANs. - * - *

Thanks to Martijn Steenbakkers for explanations on LCMAPS! - */ -/* - * Copyright (c) 2005,2006 Riccardo Murri - * for the EGRID/INFN joint project StoRM. - * - * You may copy, modify and distribute this file under the same terms - * expressed in the accompanying file LICENCE. - * - * This file use Doxygen (see http://www.doxygen.org/ ) for inline - * documentation; in short, Doxygen uses the same syntax as JavaDoc. - */ - -static const char* const -RCSID = "$Id: lcmaps_interface.cpp,v 1.4 2007/05/16 09:50:04 lmagnoni Exp $"; - - -#ifndef DEBUG -#define __DEBUG__(x) /* ignore */ -#else -#include -#define __DEBUG__(x) x -#endif - - - -/* --- include files --- */ - -#include "lcmaps_interface.h" - -#include -#include -#include -#include -#include -#include - -/* LCMAPS */ -extern "C" { -#include -} - - - -/* --- module-local functions --- */ - -/** Count the number of elements in a NULL-terminated list of strings. - * - * @return The number of elements in the list (not counting the final NULL). - */ -static inline size_t -count_fqans ( const char** fqans) -{ - size_t i = 0; - for ( const char** p = fqans; *p; p++) - i++; - - return i; -} - -//SET FQAN -void set_fqan(char** fqans) { - char** p = fqans; - for (int i=0;i<3;i++) { - *p="pippo"; - p++; - } -} - - -/* --- global functions, exported to Java --- */ - -/** Destructor. If the ngids field is > 0, free the - * pointer gids; otherwise frees only the parameter - * x. - */ -localuser_info::~localuser_info() -{ - //fprintf(stderr, "Destructor start\n"); - /* preconditions */ - assert ((ngids > 0) ? (NULL != gids) : 1); - - if (NULL != gids) - delete[] gids; - //fprintf(stderr, "Destructor ends\n"); -} - - -/** Constructor, taking user's certificate subject DN and a (possibly - * empty) list of VOMS FQANs. Call LCMAPS to map the passed - * credentials to a local user, and fill member fields with the - * returned local user credentials. - * - * @param user_dn the user certificate subject DN; cannot be NULL nor - * an empty string. - * - * @param fqan_list a NULL-terminated array of VOMS FQANs; can be - * NULL, to pass an empty FQAN list. - */ -//localuser_info::localuser_info (const char *user_dn, const char* fqan) -localuser_info::localuser_info (const char *user_dn, const char **fqan_list) - : uid(0), ngids(0), gids(NULL) -{ - - // std::cout << "##### localuser_info DEBUG ^^^^ START ^^^^ ####" << std::endl; - -// fprintf(stderr, "start0\n"); -// char** fqan_list = (char**) malloc(sizeof(char**)); -// *fqan_list=(char*)fqan; -// fqan_list[1]=NULL; -//set_fqan(fqan_list); -//const char* user_dn= "pippo"; -//const char* user_dn=NULL; - - - /* preconditions */ - assert (NULL != user_dn); - assert ('\0' != *user_dn); - - int nfqans; - if (NULL != fqan_list) - nfqans = count_fqans (fqan_list); - else - nfqans = 0; - - lcmaps_account_info_t lcmaps_account; - int rc = lcmaps_account_info_init (&lcmaps_account); - if (0 != rc) { - std::ostringstream msg; - msg << "lcmaps_account_info_init() returned " << rc; - throw std::runtime_error(msg.str().c_str()); - } - -//DEBUG PRINT - -// fprintf(stderr, "number of fqans: %i\n", nfqans); -// for(int i = 0; i(user_dn), - const_cast(fqan_list), - nfqans, - 0, - &lcmaps_account); - - - if (0 != rc) { - lcmaps_account_info_clean(&lcmaps_account); - - // build error message - std::ostringstream msg; - msg << "lcmaps_return_poolindex_without_gsi('" - << user_dn <<"',{"; - for(int i = 0; i 0) - ngids = lcmaps_account.npgid + lcmaps_account.nsgid; - else - ngids = lcmaps_account.npgid; - - // std::cout << " lcmaps_account.uid = " << lcmaps_account.uid << std::endl; - // std::cout << " lcmaps_account.npgid (primary) = " << lcmaps_account.npgid << std::endl; - // std::cout << " lcmaps_account.nsgid (secondary)= " << lcmaps_account.nsgid << std::endl; - // std::cout << " number of GIDs (sum) = " << ngids << std::endl; - - /* copy GIDs, primary first */ - - gids = new gid_t[ngids]; - gid_t *q = gids; - gid_t *p = lcmaps_account.pgid_list; - for (int i = 0; i < lcmaps_account.npgid; i++) - q[i] = p[i]; - if (lcmaps_account.nsgid > 0) { - p = lcmaps_account.sgid_list; - for (int i = 0; i < lcmaps_account.nsgid; i++) - q[i + lcmaps_account.npgid] = p[i]; - } - - // std::cout << "##### RETURN VALUES ####" << std::endl; - // std::cout << " uid = " << uid << std::endl; - // std::cout << " ngid = " << ngids << std::endl; - // for(int i = 0; i - * - * Utility functions for mapping grid user credentials to a local - * account with LCMAPS. - * - *

These bindings are tailored to provide only the subset of - * functionalities needed by the StoRM ``GridUser`` object, namely, - * get a local user UID and groups from the certificate subject DN and - * the VOMS FQANs. - * - *

Thanks to Martijn Steenbakkers for explanations on LCMAPS! - */ -/* - * Copyright (c) 2005,2006 Riccardo Murri - * for the EGRID/INFN joint project StoRM. - * - * You may copy, modify and distribute this file under the same terms - * expressed in the accompanying file LICENCE. - * - * This file use Doxygen (see http://www.doxygen.org/ ) for inline - * documentation; in short, Doxygen uses the same syntax as JavaDoc. - */ - -static const char* const -RCSID = "$Id: lcmaps_interface.cpp,v 1.3 2006/09/18 11:09:16 amessina Exp $"; - - -#ifndef DEBUG -#define __DEBUG__(x) /* ignore */ -#else -#include -#define __DEBUG__(x) x -#endif - - - -/* --- include files --- */ - -#include "lcmaps_interface.h" - -#include -#include -#include -#include -#include -#include - -/* LCMAPS */ -//extern "C" { -//#include -//} - - - -/* --- module-local functions --- */ - -/** Count the number of elements in a NULL-terminated list of strings. - * - * @return The number of elements in the list (not counting the final NULL). - */ -//static inline size_t -//count_fqans (const char** fqans) -//{ -// size_t i = 0; -// for (const char** p = fqans; *p; p++) -// i++; -// -// return i; -//} - - - -/* --- global functions, exported to Java --- */ - -/** Destructor. If the ngids field is > 0, free the - * pointer gids; otherwise frees only the parameter - * x. - */ -//localuser_info::~localuser_info() -//{ -// fprintf(stderr, "Destructor start\n"); -// /* preconditions */ -// assert ((ngids > 0) ? (NULL != gids) : 1); -// -// if (NULL != gids) -// delete[] gids; -// fprintf(stderr, "Destructor ends\n"); -//} - - -/** Constructor, taking user's certificate subject DN and a (possibly - * empty) list of VOMS FQANs. Call LCMAPS to map the passed - * credentials to a local user, and fill member fields with the - * returned local user credentials. - * - * @param user_dn the user certificate subject DN; cannot be NULL nor - * an empty string. - * - * @param fqan_list a NULL-terminated array of VOMS FQANs; can be - * NULL, to pass an empty FQAN list. - */ -localuser_info::localuser_info () - // : uid(-1), ngids(0), gids(NULL) -{ - fprintf(stderr, "start\n"); -// -// /* preconditions */ -// assert (NULL != user_dn); -// assert ('\0' != *user_dn); -// -// int nfqans; -// if (NULL != fqan_list) -// nfqans = count_fqans (fqan_list); -// else -// nfqans = 0; -// -// lcmaps_account_info_t lcmaps_account; -// fprintf(stderr, "init\n"); -// int rc = lcmaps_account_info_init (&lcmaps_account); -// if (0 != rc) { -// std::ostringstream msg; -// msg << "lcmaps_account_info_init() returned " << rc; -// throw std::runtime_error(msg.str().c_str()); -// } -// -////DEBUG PRINT -// -// fprintf(stderr, "number of fqans: %i\n", nfqans); -// for(int i = 0; i(user_dn), -// const_cast(fqan_list), -// nfqans, -// 0, -// &lcmaps_account); -// -// -////lcmaps_account.uid = 500; -////lcmaps_account.nsgid = 0; -// -// -///* -// rc = lcmaps_return_poolindex_without_gsi (const_cast(user_dn), -// const_cast(fqan_list), -// nfqans, -// &lcmaps_account); -//*/ -// -// fprintf(stderr, "lcmapss QUERY done with code: %i\n", rc); -// -// if (0 != rc) { -// lcmaps_account_info_clean(&lcmaps_account); -// -// // build error message -// std::ostringstream msg; -// msg << "lcmaps_return_poolindex_without_gsi('" -// << user_dn <<"',{"; -// for(int i = 0; i 0) -// ngids = lcmaps_account.npgid + lcmaps_account.nsgid; -// else -// ngids = lcmaps_account.npgid; -// -// fprintf(stderr, "Ngids: %i\n", ngids); -// -// /* copy GIDs, primary first */ -// -// gids = new gid_t[ngids]; -// gid_t *q = gids; -// gid_t *p = lcmaps_account.pgid_list; -// for (int i = 0; i < lcmaps_account.npgid; i++) -// q[i] = p[i]; -// if (lcmaps_account.nsgid > 0) { -// p = lcmaps_account.sgid_list; -// for (int i = 0; i < lcmaps_account.nsgid; i++) -// q[i + lcmaps_account.npgid] = p[i]; -// } -// -// -// -// /* XXX: need to check return value? */ -// fprintf(stderr, "Clean\n"); -// lcmaps_account_info_clean (&lcmaps_account); - fprintf(stderr, "Clesan done\n"); -// fprintf(stderr, "uid: %i\n", uid); -// fprintf(stderr, "Ngids: %i\n", ngids); - -} diff --git a/src/main/java/it/grid/storm/griduser/swig/lcmaps_interface.cpp.old b/src/main/java/it/grid/storm/griduser/swig/lcmaps_interface.cpp.old deleted file mode 100644 index 250df0d4..00000000 --- a/src/main/java/it/grid/storm/griduser/swig/lcmaps_interface.cpp.old +++ /dev/null @@ -1,207 +0,0 @@ -/** - * @file lcmaps_interface.c - * @author Riccardo Murri - * - * Utility functions for mapping grid user credentials to a local - * account with LCMAPS. - * - *

These bindings are tailored to provide only the subset of - * functionalities needed by the StoRM ``GridUser`` object, namely, - * get a local user UID and groups from the certificate subject DN and - * the VOMS FQANs. - * - *

Thanks to Martijn Steenbakkers for explanations on LCMAPS! - */ -/* - * Copyright (c) 2005,2006 Riccardo Murri - * for the EGRID/INFN joint project StoRM. - * - * You may copy, modify and distribute this file under the same terms - * expressed in the accompanying file LICENCE. - * - * This file use Doxygen (see http://www.doxygen.org/ ) for inline - * documentation; in short, Doxygen uses the same syntax as JavaDoc. - */ - -static const char* const -RCSID = "$Id: lcmaps_interface.cpp,v 1.3 2006/09/18 11:09:16 amessina Exp $"; - - -#ifndef DEBUG -#define __DEBUG__(x) /* ignore */ -#else -#include -#define __DEBUG__(x) x -#endif - - - -/* --- include files --- */ - -#include "lcmaps_interface.h" - -#include -#include -#include -#include -#include -#include - -/* LCMAPS */ -extern "C" { -#include -} - - - -/* --- module-local functions --- */ - -/** Count the number of elements in a NULL-terminated list of strings. - * - * @return The number of elements in the list (not counting the final NULL). - */ -static inline size_t -count_fqans (const char** fqans) -{ - size_t i = 0; - for (const char** p = fqans; *p; p++) - i++; - - return i; -} - - - -/* --- global functions, exported to Java --- */ - -/** Destructor. If the ngids field is > 0, free the - * pointer gids; otherwise frees only the parameter - * x. - */ -localuser_info::~localuser_info() -{ - fprintf(stderr, "Destructor start\n"); - /* preconditions */ - assert ((ngids > 0) ? (NULL != gids) : 1); - - if (NULL != gids) - delete[] gids; - fprintf(stderr, "Destructor ends\n"); -} - - -/** Constructor, taking user's certificate subject DN and a (possibly - * empty) list of VOMS FQANs. Call LCMAPS to map the passed - * credentials to a local user, and fill member fields with the - * returned local user credentials. - * - * @param user_dn the user certificate subject DN; cannot be NULL nor - * an empty string. - * - * @param fqan_list a NULL-terminated array of VOMS FQANs; can be - * NULL, to pass an empty FQAN list. - */ -localuser_info::localuser_info (const char *user_dn, const char **fqan_list) - : uid(-1), ngids(0), gids(NULL) -{ - fprintf(stderr, "start\n"); - - /* preconditions */ - assert (NULL != user_dn); - assert ('\0' != *user_dn); - - int nfqans; - if (NULL != fqan_list) - nfqans = count_fqans (fqan_list); - else - nfqans = 0; - - lcmaps_account_info_t lcmaps_account; - fprintf(stderr, "init\n"); - int rc = lcmaps_account_info_init (&lcmaps_account); - if (0 != rc) { - std::ostringstream msg; - msg << "lcmaps_account_info_init() returned " << rc; - throw std::runtime_error(msg.str().c_str()); - } - -//DEBUG PRINT - - fprintf(stderr, "number of fqans: %i\n", nfqans); - for(int i = 0; i(user_dn), - const_cast(fqan_list), - nfqans, - 0, - &lcmaps_account); - - -//lcmaps_account.uid = 500; -//lcmaps_account.nsgid = 0; - - -/* - rc = lcmaps_return_poolindex_without_gsi (const_cast(user_dn), - const_cast(fqan_list), - nfqans, - &lcmaps_account); -*/ - - fprintf(stderr, "lcmapss QUERY done with code: %i\n", rc); - - if (0 != rc) { - lcmaps_account_info_clean(&lcmaps_account); - - // build error message - std::ostringstream msg; - msg << "lcmaps_return_poolindex_without_gsi('" - << user_dn <<"',{"; - for(int i = 0; i 0) - ngids = lcmaps_account.npgid + lcmaps_account.nsgid; - else - ngids = lcmaps_account.npgid; - - fprintf(stderr, "Ngids: %i\n", ngids); - - /* copy GIDs, primary first */ - - gids = new gid_t[ngids]; - gid_t *q = gids; - gid_t *p = lcmaps_account.pgid_list; - for (int i = 0; i < lcmaps_account.npgid; i++) - q[i] = p[i]; - if (lcmaps_account.nsgid > 0) { - p = lcmaps_account.sgid_list; - for (int i = 0; i < lcmaps_account.nsgid; i++) - q[i + lcmaps_account.npgid] = p[i]; - } - - - - /* XXX: need to check return value? */ - fprintf(stderr, "Clean\n"); - lcmaps_account_info_clean (&lcmaps_account); - fprintf(stderr, "Clesan done\n"); - fprintf(stderr, "uid: %i\n", uid); - fprintf(stderr, "Ngids: %i\n", ngids); - -} diff --git a/src/main/java/it/grid/storm/griduser/swig/lcmaps_interface.h b/src/main/java/it/grid/storm/griduser/swig/lcmaps_interface.h deleted file mode 100644 index 74419a9e..00000000 --- a/src/main/java/it/grid/storm/griduser/swig/lcmaps_interface.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __LCMAPS_INTERFACE_H -#define __LCMAPS_INTERFACE_H - -/* --- include files --- */ -#include - - -/* --- data structures definition --- */ - -/** - * Account information that StoRM needs back. The - * gid_list is a list of all the groups returned by - * evaluation of LCMAPS plugins; by convention, the primary GID is - * first in list, although this does not matter in StoRM, as we use - * group membership only for access rights checking. - * - */ -class localuser_info { - public: - /** Numerical UID of the local user. */ - uid_t uid; - - /** Number of elements in the gid_list array. */ - gid_t *gids; - - /** List of (numerical) GIDs the local user belongs to. */ - size_t ngids; - - /** Constructor, taking user DN and FQANs list. */ - localuser_info (const char *user_dn, const char **fqan_list); - - /** Destructor, frees all memory allocated to the gids list. */ - ~localuser_info(); -}; - - -#endif /* __LCMAPS_INTERFACE_H */ diff --git a/src/main/java/it/grid/storm/griduser/swig/lcmaps_interface.i b/src/main/java/it/grid/storm/griduser/swig/lcmaps_interface.i deleted file mode 100644 index d73b321b..00000000 --- a/src/main/java/it/grid/storm/griduser/swig/lcmaps_interface.i +++ /dev/null @@ -1,127 +0,0 @@ -// ----------------------------------------------------------------------- -// ----------------------------------------------------------------------- -// -// lcmaps_interface.i -- SWIG interface module for lcmaps_interface.c -// -// Copyright (c) 2005, 2006 Riccardo Murri -// for the EGRID/INFN joint project StoRM. -// -// You may copy, modify and distribute this code under the terms of -// the INFN GRID licence. -// -// $Id: lcmaps_interface.i,v 1.12 2007/05/16 09:50:04 lmagnoni Exp $ -// -// ----------------------------------------------------------------------- -// ----------------------------------------------------------------------- - -%module lcmaps_interface - - -// ---- use Java language constants ---- // -// -%javaconst(1); - - -// ---- load native code in JNI class initialization ---- // -// -// This pragma will instruct SWIG code to load -// the native code library when the JNI-proxy class -// is loaded by the JVM. -// -%include load_native_lib_in_jniclass.i -LOAD_NATIVE_LIB_IN_JNICLASS(lcmaps_interface) - - -// --- additional include files for the generated C code --- // -// -// This section is copied verbatim into the generated C wrapper code; -// it should include all declarations that are needed in the C code -// compilation, and it should match the part that is repeated below in -// the SWIG interface directives. -// -%{ -#include "lcmaps_interface.h" -#include // for catching constructor exceptions -#include // robust exception throwing code -%} - - -// --- interface definition: lcmaps_interface.h --- // -// -// This section contains the code for which a wrapping interface will -// be generated. -// - -// uid_t, gid_t and size_t are in sys/types.h, -// but cannot be parsed because of -// gcc-specific constructs... -typedef int uid_t; -typedef int gid_t; -typedef int size_t; - -// map 'char **fqan_list' and 'char **vo_list' to a Java String[] -// -// The following include files were extracted from the ``various.i`` -// library file in SWIG 1.3.24; the same library file from 1.3.19 has -// different names; at some point in time, they should be removed from -// here... -// - -%include "string_array.i"; // map ``char**`` to Java ``String[]`` -%apply char **STRING_ARRAY { char **fqan_list}; - - - -// map 'gid_t *gid_list' to a Java int[] -// -// This turned out to be trickier than String[]: -// -// 1. swig-1.3.19 does not have support for arrays of unspecified -// size in ``arrays_java.i``, so I got the ``arrays_java.1.3.24.i`` -// from swig-1.3.24 -// 2. even that will not compile out-of-the-box: compilation spits out -// an error message - a line needs to be replaced; we do that -// by adding the ``%typemap`` directive below, which is a copy -// of the original SWIG-produce code, with the placeholder value -// substituted with the actual one. BEWARE!! If the type changes, -// then the typemap code should change accordingly. -// 3. for some reason, the C++ compiler won't cast a (gid_t*) -// to an (int*); so, we force the cast ... -// -// BEWARE!! it is not a true Java array, so no referencing -// int[].length, no bounds checking, etc... (This notice was taken from -// the SWIG docs... I don't think this is any longer valid, as we -// are putting in the correct size. -- RM) -// -%include "arrays_java.1.3.24.i" -%typemap(out) int[] %{ - /* next line comes from lcmaps_interface.i */ - $result = SWIG_JavaArrayOutInt(jenv, (int*)$1, (size_t) ((arg1)->ngids)); -%} -%apply int[] { gid_t *gids } - -// catch exceptions throw by the localuser_info ctor, -// and rethrow them as Java exceptions -// -//%javaexception("it.grid.storm.griduser.CannotMapUserException") { -%exception localuser_info::localuser_info %{ - try { - $action - } - catch (std::exception& x) { - // find corresponding Java excpetion class - jclass clazz = - jenv->FindClass("it/grid/storm/griduser/CannotMapUserException"); - // fail miserably if to-throw Java exception class cannot be found - assert (NULL != clazz); - // throw excpetion into JVM - jenv->ThrowNew(clazz, x.what()); - return $null; - } -%} - -// all wrapped objects are read-only, from the Java point of view -%immutable; - -// C++ interface -%include lcmaps_interface.h diff --git a/src/main/java/it/grid/storm/griduser/swig/lcmaps_interfaceJNI.java b/src/main/java/it/grid/storm/griduser/swig/lcmaps_interfaceJNI.java index 745e7713..64795ca0 100644 --- a/src/main/java/it/grid/storm/griduser/swig/lcmaps_interfaceJNI.java +++ b/src/main/java/it/grid/storm/griduser/swig/lcmaps_interfaceJNI.java @@ -37,17 +37,19 @@ class lcmaps_interfaceJNI { + "'"; final org.slf4j.Logger log = org.slf4j.LoggerFactory .getLogger(lcmaps_interfaceJNI.class); - log.error("Native code library " + libfile + " failed to load: ", + + log.error("Native code library {} failed to load: {}", + libfile, e.getMessage()); - // give some informational details, may be useful when debugging + final String ldpath = System.getProperty("java.library.path"); if (null != ldpath) - log.info("Java VM searched for " + libfile + "in java.library.path: " - + ldpath); + log.error("Java VM searched for {} in java.library.path: {}", + libfile, ldpath); else - log.info("Java VM library search path is null!"); + log.error("Java VM library search path is null!"); log - .info("Add the library location to the environment variable LD_LIBRARY_PATH or to the Java property java.library.path"); + .error("Add the library location to the environment variable LD_LIBRARY_PATH or to the Java property java.library.path"); throw new UnsatisfiedLinkError("Native code library " + libfile + " failed to load: " + e.getMessage()); } diff --git a/src/main/java/it/grid/storm/griduser/swig/lcmaps_interface_wrap.cxx b/src/main/java/it/grid/storm/griduser/swig/lcmaps_interface_wrap.cxx deleted file mode 100644 index 554db3c8..00000000 --- a/src/main/java/it/grid/storm/griduser/swig/lcmaps_interface_wrap.cxx +++ /dev/null @@ -1,860 +0,0 @@ -/* ---------------------------------------------------------------------------- - * This file was automatically generated by SWIG (http://www.swig.org). - * Version 1.3.24 - * - * This file is not intended to be easily readable and contains a number of - * coding conventions designed to improve portability and efficiency. Do not make - * changes to this file unless you know what you are doing--modify the SWIG - * interface file instead. - * ----------------------------------------------------------------------------- */ - - -#ifdef __cplusplus -template class SwigValueWrapper { - T *tt; -public: - SwigValueWrapper() : tt(0) { } - SwigValueWrapper(const SwigValueWrapper& rhs) : tt(new T(*rhs.tt)) { } - SwigValueWrapper(const T& t) : tt(new T(t)) { } - ~SwigValueWrapper() { delete tt; } - SwigValueWrapper& operator=(const T& t) { delete tt; tt = new T(t); return *this; } - operator T&() const { return *tt; } - T *operator&() { return tt; } -private: - SwigValueWrapper& operator=(const SwigValueWrapper& rhs); -}; -#endif - - -#ifndef SWIG_TEMPLATE_DISAMBIGUATOR -# if defined(__SUNPRO_CC) -# define SWIG_TEMPLATE_DISAMBIGUATOR template -# else -# define SWIG_TEMPLATE_DISAMBIGUATOR -# endif -#endif - - -#if defined(__GNUC__) - typedef long long __int64; /*For gcc on Windows */ -#endif -#include -#include -#include - - -/* Support for throwing Java exceptions */ -typedef enum { - SWIG_JavaOutOfMemoryError = 1, - SWIG_JavaIOException, - SWIG_JavaRuntimeException, - SWIG_JavaIndexOutOfBoundsException, - SWIG_JavaArithmeticException, - SWIG_JavaIllegalArgumentException, - SWIG_JavaNullPointerException, - SWIG_JavaDirectorPureVirtual, - SWIG_JavaUnknownError -} SWIG_JavaExceptionCodes; - -typedef struct { - SWIG_JavaExceptionCodes code; - const char *java_exception; -} SWIG_JavaExceptions_t; - - -static void SWIG_JavaThrowException(JNIEnv *jenv, SWIG_JavaExceptionCodes code, const char *msg) { - jclass excep; - static const SWIG_JavaExceptions_t java_exceptions[] = { - { SWIG_JavaOutOfMemoryError, "java/lang/OutOfMemoryError" }, - { SWIG_JavaIOException, "java/io/IOException" }, - { SWIG_JavaRuntimeException, "java/lang/RuntimeException" }, - { SWIG_JavaIndexOutOfBoundsException, "java/lang/IndexOutOfBoundsException" }, - { SWIG_JavaArithmeticException, "java/lang/ArithmeticException" }, - { SWIG_JavaIllegalArgumentException, "java/lang/IllegalArgumentException" }, - { SWIG_JavaNullPointerException, "java/lang/NullPointerException" }, - { SWIG_JavaDirectorPureVirtual, "java/lang/RuntimeException" }, - { SWIG_JavaUnknownError, "java/lang/UnknownError" }, - { (SWIG_JavaExceptionCodes)0, "java/lang/UnknownError" } }; - const SWIG_JavaExceptions_t *except_ptr = java_exceptions; - - while (except_ptr->code != code && except_ptr->code) - except_ptr++; - - jenv->ExceptionClear(); - excep = jenv->FindClass(except_ptr->java_exception); - if (excep) - jenv->ThrowNew(excep, msg); -} - - -/* Contract support */ - -#define SWIG_contract_assert(nullreturn, expr, msg) if (!(expr)) {SWIG_JavaThrowException(jenv, SWIG_JavaIllegalArgumentException, msg); return nullreturn; } else - - -#include "lcmaps_interface.h" -#include // for catching constructor exceptions -#include // robust exception throwing code - - -#if defined(SWIG_NOINCLUDE) || defined(SWIG_NOARRAYS) - - -int SWIG_JavaArrayInBool (JNIEnv *jenv, jboolean **jarr, bool **carr, jbooleanArray input); -void SWIG_JavaArrayArgoutBool (JNIEnv *jenv, jboolean *jarr, bool *carr, jbooleanArray input); -jbooleanArray SWIG_JavaArrayOutBool (JNIEnv *jenv, bool *result, jsize sz); - - -int SWIG_JavaArrayInSchar (JNIEnv *jenv, jbyte **jarr, signed char **carr, jbyteArray input); -void SWIG_JavaArrayArgoutSchar (JNIEnv *jenv, jbyte *jarr, signed char *carr, jbyteArray input); -jbyteArray SWIG_JavaArrayOutSchar (JNIEnv *jenv, signed char *result, jsize sz); - - -int SWIG_JavaArrayInUchar (JNIEnv *jenv, jshort **jarr, unsigned char **carr, jshortArray input); -void SWIG_JavaArrayArgoutUchar (JNIEnv *jenv, jshort *jarr, unsigned char *carr, jshortArray input); -jshortArray SWIG_JavaArrayOutUchar (JNIEnv *jenv, unsigned char *result, jsize sz); - - -int SWIG_JavaArrayInShort (JNIEnv *jenv, jshort **jarr, short **carr, jshortArray input); -void SWIG_JavaArrayArgoutShort (JNIEnv *jenv, jshort *jarr, short *carr, jshortArray input); -jshortArray SWIG_JavaArrayOutShort (JNIEnv *jenv, short *result, jsize sz); - - -int SWIG_JavaArrayInUshort (JNIEnv *jenv, jint **jarr, unsigned short **carr, jintArray input); -void SWIG_JavaArrayArgoutUshort (JNIEnv *jenv, jint *jarr, unsigned short *carr, jintArray input); -jintArray SWIG_JavaArrayOutUshort (JNIEnv *jenv, unsigned short *result, jsize sz); - - -int SWIG_JavaArrayInInt (JNIEnv *jenv, jint **jarr, int **carr, jintArray input); -void SWIG_JavaArrayArgoutInt (JNIEnv *jenv, jint *jarr, int *carr, jintArray input); -jintArray SWIG_JavaArrayOutInt (JNIEnv *jenv, int *result, jsize sz); - - -int SWIG_JavaArrayInUint (JNIEnv *jenv, jlong **jarr, unsigned int **carr, jlongArray input); -void SWIG_JavaArrayArgoutUint (JNIEnv *jenv, jlong *jarr, unsigned int *carr, jlongArray input); -jlongArray SWIG_JavaArrayOutUint (JNIEnv *jenv, unsigned int *result, jsize sz); - - -int SWIG_JavaArrayInLong (JNIEnv *jenv, jint **jarr, long **carr, jintArray input); -void SWIG_JavaArrayArgoutLong (JNIEnv *jenv, jint *jarr, long *carr, jintArray input); -jintArray SWIG_JavaArrayOutLong (JNIEnv *jenv, long *result, jsize sz); - - -int SWIG_JavaArrayInUlong (JNIEnv *jenv, jlong **jarr, unsigned long **carr, jlongArray input); -void SWIG_JavaArrayArgoutUlong (JNIEnv *jenv, jlong *jarr, unsigned long *carr, jlongArray input); -jlongArray SWIG_JavaArrayOutUlong (JNIEnv *jenv, unsigned long *result, jsize sz); - - -int SWIG_JavaArrayInLonglong (JNIEnv *jenv, jlong **jarr, jlong **carr, jlongArray input); -void SWIG_JavaArrayArgoutLonglong (JNIEnv *jenv, jlong *jarr, jlong *carr, jlongArray input); -jlongArray SWIG_JavaArrayOutLonglong (JNIEnv *jenv, jlong *result, jsize sz); - - -int SWIG_JavaArrayInFloat (JNIEnv *jenv, jfloat **jarr, float **carr, jfloatArray input); -void SWIG_JavaArrayArgoutFloat (JNIEnv *jenv, jfloat *jarr, float *carr, jfloatArray input); -jfloatArray SWIG_JavaArrayOutFloat (JNIEnv *jenv, float *result, jsize sz); - - -int SWIG_JavaArrayInDouble (JNIEnv *jenv, jdouble **jarr, double **carr, jdoubleArray input); -void SWIG_JavaArrayArgoutDouble (JNIEnv *jenv, jdouble *jarr, double *carr, jdoubleArray input); -jdoubleArray SWIG_JavaArrayOutDouble (JNIEnv *jenv, double *result, jsize sz); - - -#else - - -/* bool[] support */ -int SWIG_JavaArrayInBool (JNIEnv *jenv, jboolean **jarr, bool **carr, jbooleanArray input) { - int i; - jsize sz; - if (!input) { - SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array"); - return 0; - } - sz = jenv->GetArrayLength(input); - *jarr = jenv->GetBooleanArrayElements(input, 0); - if (!*jarr) - return 0; - *carr = new bool[sz]; - if (!*carr) { - SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed"); - return 0; - } - for (i=0; iGetArrayLength(input); - for (i=0; iReleaseBooleanArrayElements(input, jarr, 0); -} - -jbooleanArray SWIG_JavaArrayOutBool (JNIEnv *jenv, bool *result, jsize sz) { - jboolean *arr; - int i; - jbooleanArray jresult = jenv->NewBooleanArray(sz); - if (!jresult) - return NULL; - arr = jenv->GetBooleanArrayElements(jresult, 0); - if (!arr) - return NULL; - for (i=0; iReleaseBooleanArrayElements(jresult, arr, 0); - return jresult; -} - - -/* signed char[] support */ -int SWIG_JavaArrayInSchar (JNIEnv *jenv, jbyte **jarr, signed char **carr, jbyteArray input) { - int i; - jsize sz; - if (!input) { - SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array"); - return 0; - } - sz = jenv->GetArrayLength(input); - *jarr = jenv->GetByteArrayElements(input, 0); - if (!*jarr) - return 0; - *carr = new signed char[sz]; - if (!*carr) { - SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed"); - return 0; - } - for (i=0; iGetArrayLength(input); - for (i=0; iReleaseByteArrayElements(input, jarr, 0); -} - -jbyteArray SWIG_JavaArrayOutSchar (JNIEnv *jenv, signed char *result, jsize sz) { - jbyte *arr; - int i; - jbyteArray jresult = jenv->NewByteArray(sz); - if (!jresult) - return NULL; - arr = jenv->GetByteArrayElements(jresult, 0); - if (!arr) - return NULL; - for (i=0; iReleaseByteArrayElements(jresult, arr, 0); - return jresult; -} - - -/* unsigned char[] support */ -int SWIG_JavaArrayInUchar (JNIEnv *jenv, jshort **jarr, unsigned char **carr, jshortArray input) { - int i; - jsize sz; - if (!input) { - SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array"); - return 0; - } - sz = jenv->GetArrayLength(input); - *jarr = jenv->GetShortArrayElements(input, 0); - if (!*jarr) - return 0; - *carr = new unsigned char[sz]; - if (!*carr) { - SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed"); - return 0; - } - for (i=0; iGetArrayLength(input); - for (i=0; iReleaseShortArrayElements(input, jarr, 0); -} - -jshortArray SWIG_JavaArrayOutUchar (JNIEnv *jenv, unsigned char *result, jsize sz) { - jshort *arr; - int i; - jshortArray jresult = jenv->NewShortArray(sz); - if (!jresult) - return NULL; - arr = jenv->GetShortArrayElements(jresult, 0); - if (!arr) - return NULL; - for (i=0; iReleaseShortArrayElements(jresult, arr, 0); - return jresult; -} - - -/* short[] support */ -int SWIG_JavaArrayInShort (JNIEnv *jenv, jshort **jarr, short **carr, jshortArray input) { - int i; - jsize sz; - if (!input) { - SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array"); - return 0; - } - sz = jenv->GetArrayLength(input); - *jarr = jenv->GetShortArrayElements(input, 0); - if (!*jarr) - return 0; - *carr = new short[sz]; - if (!*carr) { - SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed"); - return 0; - } - for (i=0; iGetArrayLength(input); - for (i=0; iReleaseShortArrayElements(input, jarr, 0); -} - -jshortArray SWIG_JavaArrayOutShort (JNIEnv *jenv, short *result, jsize sz) { - jshort *arr; - int i; - jshortArray jresult = jenv->NewShortArray(sz); - if (!jresult) - return NULL; - arr = jenv->GetShortArrayElements(jresult, 0); - if (!arr) - return NULL; - for (i=0; iReleaseShortArrayElements(jresult, arr, 0); - return jresult; -} - - -/* unsigned short[] support */ -int SWIG_JavaArrayInUshort (JNIEnv *jenv, jint **jarr, unsigned short **carr, jintArray input) { - int i; - jsize sz; - if (!input) { - SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array"); - return 0; - } - sz = jenv->GetArrayLength(input); - *jarr = jenv->GetIntArrayElements(input, 0); - if (!*jarr) - return 0; - *carr = new unsigned short[sz]; - if (!*carr) { - SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed"); - return 0; - } - for (i=0; iGetArrayLength(input); - for (i=0; iReleaseIntArrayElements(input, jarr, 0); -} - -jintArray SWIG_JavaArrayOutUshort (JNIEnv *jenv, unsigned short *result, jsize sz) { - jint *arr; - int i; - jintArray jresult = jenv->NewIntArray(sz); - if (!jresult) - return NULL; - arr = jenv->GetIntArrayElements(jresult, 0); - if (!arr) - return NULL; - for (i=0; iReleaseIntArrayElements(jresult, arr, 0); - return jresult; -} - - -/* int[] support */ -int SWIG_JavaArrayInInt (JNIEnv *jenv, jint **jarr, int **carr, jintArray input) { - int i; - jsize sz; - if (!input) { - SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array"); - return 0; - } - sz = jenv->GetArrayLength(input); - *jarr = jenv->GetIntArrayElements(input, 0); - if (!*jarr) - return 0; - *carr = new int[sz]; - if (!*carr) { - SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed"); - return 0; - } - for (i=0; iGetArrayLength(input); - for (i=0; iReleaseIntArrayElements(input, jarr, 0); -} - -jintArray SWIG_JavaArrayOutInt (JNIEnv *jenv, int *result, jsize sz) { - jint *arr; - int i; - jintArray jresult = jenv->NewIntArray(sz); - if (!jresult) - return NULL; - arr = jenv->GetIntArrayElements(jresult, 0); - if (!arr) - return NULL; - for (i=0; iReleaseIntArrayElements(jresult, arr, 0); - return jresult; -} - - -/* unsigned int[] support */ -int SWIG_JavaArrayInUint (JNIEnv *jenv, jlong **jarr, unsigned int **carr, jlongArray input) { - int i; - jsize sz; - if (!input) { - SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array"); - return 0; - } - sz = jenv->GetArrayLength(input); - *jarr = jenv->GetLongArrayElements(input, 0); - if (!*jarr) - return 0; - *carr = new unsigned int[sz]; - if (!*carr) { - SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed"); - return 0; - } - for (i=0; iGetArrayLength(input); - for (i=0; iReleaseLongArrayElements(input, jarr, 0); -} - -jlongArray SWIG_JavaArrayOutUint (JNIEnv *jenv, unsigned int *result, jsize sz) { - jlong *arr; - int i; - jlongArray jresult = jenv->NewLongArray(sz); - if (!jresult) - return NULL; - arr = jenv->GetLongArrayElements(jresult, 0); - if (!arr) - return NULL; - for (i=0; iReleaseLongArrayElements(jresult, arr, 0); - return jresult; -} - - -/* long[] support */ -int SWIG_JavaArrayInLong (JNIEnv *jenv, jint **jarr, long **carr, jintArray input) { - int i; - jsize sz; - if (!input) { - SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array"); - return 0; - } - sz = jenv->GetArrayLength(input); - *jarr = jenv->GetIntArrayElements(input, 0); - if (!*jarr) - return 0; - *carr = new long[sz]; - if (!*carr) { - SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed"); - return 0; - } - for (i=0; iGetArrayLength(input); - for (i=0; iReleaseIntArrayElements(input, jarr, 0); -} - -jintArray SWIG_JavaArrayOutLong (JNIEnv *jenv, long *result, jsize sz) { - jint *arr; - int i; - jintArray jresult = jenv->NewIntArray(sz); - if (!jresult) - return NULL; - arr = jenv->GetIntArrayElements(jresult, 0); - if (!arr) - return NULL; - for (i=0; iReleaseIntArrayElements(jresult, arr, 0); - return jresult; -} - - -/* unsigned long[] support */ -int SWIG_JavaArrayInUlong (JNIEnv *jenv, jlong **jarr, unsigned long **carr, jlongArray input) { - int i; - jsize sz; - if (!input) { - SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array"); - return 0; - } - sz = jenv->GetArrayLength(input); - *jarr = jenv->GetLongArrayElements(input, 0); - if (!*jarr) - return 0; - *carr = new unsigned long[sz]; - if (!*carr) { - SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed"); - return 0; - } - for (i=0; iGetArrayLength(input); - for (i=0; iReleaseLongArrayElements(input, jarr, 0); -} - -jlongArray SWIG_JavaArrayOutUlong (JNIEnv *jenv, unsigned long *result, jsize sz) { - jlong *arr; - int i; - jlongArray jresult = jenv->NewLongArray(sz); - if (!jresult) - return NULL; - arr = jenv->GetLongArrayElements(jresult, 0); - if (!arr) - return NULL; - for (i=0; iReleaseLongArrayElements(jresult, arr, 0); - return jresult; -} - - -/* jlong[] support */ -int SWIG_JavaArrayInLonglong (JNIEnv *jenv, jlong **jarr, jlong **carr, jlongArray input) { - int i; - jsize sz; - if (!input) { - SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array"); - return 0; - } - sz = jenv->GetArrayLength(input); - *jarr = jenv->GetLongArrayElements(input, 0); - if (!*jarr) - return 0; - *carr = new jlong[sz]; - if (!*carr) { - SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed"); - return 0; - } - for (i=0; iGetArrayLength(input); - for (i=0; iReleaseLongArrayElements(input, jarr, 0); -} - -jlongArray SWIG_JavaArrayOutLonglong (JNIEnv *jenv, jlong *result, jsize sz) { - jlong *arr; - int i; - jlongArray jresult = jenv->NewLongArray(sz); - if (!jresult) - return NULL; - arr = jenv->GetLongArrayElements(jresult, 0); - if (!arr) - return NULL; - for (i=0; iReleaseLongArrayElements(jresult, arr, 0); - return jresult; -} - - -/* float[] support */ -int SWIG_JavaArrayInFloat (JNIEnv *jenv, jfloat **jarr, float **carr, jfloatArray input) { - int i; - jsize sz; - if (!input) { - SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array"); - return 0; - } - sz = jenv->GetArrayLength(input); - *jarr = jenv->GetFloatArrayElements(input, 0); - if (!*jarr) - return 0; - *carr = new float[sz]; - if (!*carr) { - SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed"); - return 0; - } - for (i=0; iGetArrayLength(input); - for (i=0; iReleaseFloatArrayElements(input, jarr, 0); -} - -jfloatArray SWIG_JavaArrayOutFloat (JNIEnv *jenv, float *result, jsize sz) { - jfloat *arr; - int i; - jfloatArray jresult = jenv->NewFloatArray(sz); - if (!jresult) - return NULL; - arr = jenv->GetFloatArrayElements(jresult, 0); - if (!arr) - return NULL; - for (i=0; iReleaseFloatArrayElements(jresult, arr, 0); - return jresult; -} - - -/* double[] support */ -int SWIG_JavaArrayInDouble (JNIEnv *jenv, jdouble **jarr, double **carr, jdoubleArray input) { - int i; - jsize sz; - if (!input) { - SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "null array"); - return 0; - } - sz = jenv->GetArrayLength(input); - *jarr = jenv->GetDoubleArrayElements(input, 0); - if (!*jarr) - return 0; - *carr = new double[sz]; - if (!*carr) { - SWIG_JavaThrowException(jenv, SWIG_JavaOutOfMemoryError, "array memory allocation failed"); - return 0; - } - for (i=0; iGetArrayLength(input); - for (i=0; iReleaseDoubleArrayElements(input, jarr, 0); -} - -jdoubleArray SWIG_JavaArrayOutDouble (JNIEnv *jenv, double *result, jsize sz) { - jdouble *arr; - int i; - jdoubleArray jresult = jenv->NewDoubleArray(sz); - if (!jresult) - return NULL; - arr = jenv->GetDoubleArrayElements(jresult, 0); - if (!arr) - return NULL; - for (i=0; iReleaseDoubleArrayElements(jresult, arr, 0); - return jresult; -} - - -#endif - - -#ifdef __cplusplus -extern "C" { -#endif - -JNIEXPORT jint JNICALL Java_it_grid_storm_griduser_swig_lcmaps_1interfaceJNI_get_1localuser_1info_1uid(JNIEnv *jenv, jclass jcls, jlong jarg1) { - jint jresult = 0 ; - localuser_info *arg1 = (localuser_info *) 0 ; - uid_t result; - - (void)jenv; - (void)jcls; - arg1 = *(localuser_info **)&jarg1; - result = (uid_t) ((arg1)->uid); - - jresult = (jint)result; - return jresult; -} - - -JNIEXPORT jintArray JNICALL Java_it_grid_storm_griduser_swig_lcmaps_1interfaceJNI_get_1localuser_1info_1gids(JNIEnv *jenv, jclass jcls, jlong jarg1) { - jintArray jresult = 0 ; - localuser_info *arg1 = (localuser_info *) 0 ; - gid_t *result; - - (void)jenv; - (void)jcls; - arg1 = *(localuser_info **)&jarg1; - result = (gid_t *) ((arg1)->gids); - - - /* next line comes from lcmaps_interface.i */ - jresult = SWIG_JavaArrayOutInt(jenv, (int*)result, (size_t) ((arg1)->ngids)); - - return jresult; -} - - -JNIEXPORT jlong JNICALL Java_it_grid_storm_griduser_swig_lcmaps_1interfaceJNI_get_1localuser_1info_1ngids(JNIEnv *jenv, jclass jcls, jlong jarg1) { - jlong jresult = 0 ; - localuser_info *arg1 = (localuser_info *) 0 ; - size_t result; - - (void)jenv; - (void)jcls; - arg1 = *(localuser_info **)&jarg1; - result = (size_t) ((arg1)->ngids); - - jresult = (jlong)result; - return jresult; -} - - -JNIEXPORT jlong JNICALL Java_it_grid_storm_griduser_swig_lcmaps_1interfaceJNI_new_1localuser_1info(JNIEnv *jenv, jclass jcls, jstring jarg1, jobjectArray jarg2) { - jlong jresult = 0 ; - char *arg1 = (char *) 0 ; - char **arg2 = (char **) 0 ; - localuser_info *result; - jint size2 ; - - (void)jenv; - (void)jcls; - { - arg1 = 0; - if (jarg1) { - arg1 = (char *)jenv->GetStringUTFChars(jarg1, 0); - if (!arg1) return 0; - } - } - { - int i = 0; - size2 = jenv->GetArrayLength(jarg2); - - arg2 = new char*[size2+1]; - - - - for (i = 0; iGetObjectArrayElement(jarg2, i); - const char *c_string = jenv->GetStringUTFChars(j_string, 0); - - arg2[i] = new char [strlen(c_string)+1]; - - - - strcpy(arg2[i], c_string); - jenv->ReleaseStringUTFChars(j_string, c_string); - jenv->DeleteLocalRef(j_string); - } - arg2[i] = 0; - } - - try { - result = (localuser_info *)new localuser_info((char const *)arg1,(char const **)arg2); - - } - catch (std::exception& x) { - // find corresponding Java excpetion class - jclass clazz = - jenv->FindClass("it/grid/storm/griduser/CannotMapUserException"); - // fail miserably if to-throw Java exception class cannot be found - assert (NULL != clazz); - // throw excpetion into JVM - jenv->ThrowNew(clazz, x.what()); - return 0; - } - - *(localuser_info **)&jresult = result; - { - if (arg1) jenv->ReleaseStringUTFChars(jarg1, arg1); - } - { - int i; - for (i=0; i - - A SWIG macro to put a module's native code loading statement - in the module JNI class. Uses Log4J to log failures; tries - to give informational and diagnostic errors. - -

Usage: (substitute @a libname with your native code library - name!) -

-
-     %include load_native_lib_in_jniclass.i
-     LOAD_NATIVE_LIB_IN_JNICLASS(libname)
-  
-   
- -

This is a more elaborate version of an example found in the - SWIG users' manual. - -**/ -%define LOAD_NATIVE_LIB_IN_JNICLASS(LIBNAME) -// ---- load native code in JNI class initialization ---- // -// -// This pragma will instruct SWIG code to load -// the native code library when the JNI-proxy class -// is loaded by the JVM. -// -%pragma(java) jniclasscode=%{ - static { - try { - System.loadLibrary(#LIBNAME); - } catch (UnsatisfiedLinkError e) { - final String libfile - = "'" + System.mapLibraryName(#LIBNAME) + "'"; - final org.slf4j.Logger log - = org.slf4j.LoggerFactory.getLogger(LIBNAME##JNI.class); - log.error("Native code library " + libfile - + " failed to load: ", e.getMessage()); - // give some informational details, may be useful when debugging - final String ldpath = System.getProperty("java.library.path"); - if (null != ldpath) - log.info("Java VM searched for " + libfile - + "in java.library.path: " + ldpath); - else - log.info("Java VM library search path is null!"); - log.info("Add the library location to the environment variable LD_LIBRARY_PATH or to the Java property java.library.path"); - throw new UnsatisfiedLinkError("Native code library " + libfile - + " failed to load: " + e.getMessage()); - } - } -%} -%enddef diff --git a/src/main/java/it/grid/storm/griduser/swig/string_array.i b/src/main/java/it/grid/storm/griduser/swig/string_array.i deleted file mode 100644 index 44db3718..00000000 --- a/src/main/java/it/grid/storm/griduser/swig/string_array.i +++ /dev/null @@ -1,88 +0,0 @@ -/* - * The following snippet of code is taken from the ``various.i`` library file - * in SWIG 1.3.24; the same library file from 1.3.19 has different names; - * at some point in time, they should be removed from here... - * - * UPDATE 16.05.2007: The ``various.i`` code from 1.3.24 for the string_array is bogus!!!! - * The following code is taken from the SWIG 1.3.31, this solve a big problem: - * NEW: new char [strlen(c_string)+1] <-> OLD: char [strlen((c_string)+1)]!!!! - * that cause the CRASH of the JVM in case of string[] not null. - * @author: Luca M. - */ - -/* - * char **STRING_ARRAY typemaps. - * These typemaps are for C String arrays which are NULL terminated. - * char *values[] = { "one", "two", "three", NULL }; // note NULL - * char ** is mapped to a Java String[]. - * - * Example usage wrapping: - * %apply char **STRING_ARRAY { char **input }; - * char ** foo(char **input); - * - * Java usage: - * String numbers[] = { "one", "two", "three" }; - * String[] ret = modulename.foo( numbers }; - */ - -%typemap(jni) char **STRING_ARRAY "jobjectArray" -%typemap(jtype) char **STRING_ARRAY "String[]" -%typemap(jstype) char **STRING_ARRAY "String[]" -%typemap(in) char **STRING_ARRAY (jint size) { - int i = 0; - size = JCALL1(GetArrayLength, jenv, $input); -#ifdef __cplusplus - $1 = new char*[size+1]; -#else - $1 = (char **)calloc(size+1, sizeof(char *)); -#endif - for (i = 0; i logbook = new ArrayList(); - /** - * - * @param logEvent - * LogEvent - */ public abstract void addLogEvent(LogEvent logEvent); - /** - * Removes all event's in logbook field - */ public synchronized void cleanLogBook() { - logbook.clear(); } - // //////////////////////////////////////// - - /** - * - * @param msg - * String - */ protected void logDebug(String msg) { if ((HealthDirector.isBookKeepingConfigured()) && (HealthDirector.isBookKeepingEnabled())) { - bookKeepingLog.debug("BK: " + msg); + bookKeepingLog.debug("BK: {}", msg); } - /** - * if ((HealthDirector.isPerformanceMonitorConfigured())&&(HealthDirector. - * isPerformanceMonitorEnabled())) { performanceLog.debug("P: " + msg); } - **/ } - /** - * - * @param msg - * String - */ protected void logInfo(String msg) { if ((HealthDirector.isBookKeepingConfigured()) && (HealthDirector.isBookKeepingEnabled())) { bookKeepingLog.info(msg); } - /** - * if ((HealthDirector.isPerformanceMonitorConfigured())&&(HealthDirector. - * isPerformanceMonitorEnabled())) { performanceLog.info(msg); } - **/ - } } diff --git a/src/main/java/it/grid/storm/health/DetectiveGlance.java b/src/main/java/it/grid/storm/health/DetectiveGlance.java index a678e08f..538bd95e 100644 --- a/src/main/java/it/grid/storm/health/DetectiveGlance.java +++ b/src/main/java/it/grid/storm/health/DetectiveGlance.java @@ -84,13 +84,9 @@ public static void addSynchRequest(int nrSynchRequest) { totSYNCHRequest += nrSynchRequest; } - /** - * - * @return StoRMStatus - */ public StoRMStatus haveaLook() { - log.debug(" The glange of the Detective.."); + log.trace("DetectiveGlance.haveaLook"); StoRMStatus stormStatus = new StoRMStatus(); stormStatus.setHeapFreeSize(getHeapFreeSize()); stormStatus.setMAXHeapSize(getHeapMaxSize()); @@ -127,7 +123,6 @@ public StoRMStatus haveaLook() { stormStatus.setSynchRequest(synchRequest); stormStatus.calculateLifeTime(); - bk.cleanLogBook(); log.debug(" .. glance completed."); } else { @@ -135,5 +130,4 @@ public StoRMStatus haveaLook() { } return stormStatus; } - } diff --git a/src/main/java/it/grid/storm/health/HealthMonitor.java b/src/main/java/it/grid/storm/health/HealthMonitor.java index 7ee575e2..1891136b 100644 --- a/src/main/java/it/grid/storm/health/HealthMonitor.java +++ b/src/main/java/it/grid/storm/health/HealthMonitor.java @@ -31,14 +31,11 @@ public class HealthMonitor { private Timer healthTimer = null; private Hashtable bookKeepers; - // private boolean perfEnabled = false; - // private int perfLogQueueTimeInterval = 20; //20 sec public static int perfGlanceTimeInterval = 15; // 15 sec public HealthMonitor(int delay, int period) { healthTimer = new Timer(); - // Set monitoring the HEARTHBEAT this.heartbeat(delay * 1000, period * 1000); // Create the Book Keepers @@ -50,15 +47,9 @@ public HealthMonitor(int delay, int period) { HEARTLOG.info("HEART MONITOR Initialized"); } - // public void setPerformanceEnabled(boolean status) { - // this.perfEnabled = status; - // } - public void initializePerformanceMonitor(int logTimeInterval, int defaultGlangeTimeInterval) { - // this.perfLogQueueTimeInterval = logTimeInterval; - // this.perfGlanceTimeInterval = defaultGlangeTimeInterval; if (defaultGlangeTimeInterval > logTimeInterval) { HealthDirector.getPerformanceLogger().warn( "WARNING: Log Book has the time " @@ -73,15 +64,12 @@ public void initializePerformanceMonitor(int logTimeInterval, // this.perfEnabled = true; healthTimer.scheduleAtFixedRate(new PerformancePulse(), 0, pulseTimeInterval); - PERFLOG.info("Set PERFORMANCE MONITOR in Timer Task (PERIOD:" - + perfGlanceTimeInterval + ")"); + PERFLOG.info("Set PERFORMANCE MONITOR in Timer Task (PERIOD:{})", + perfGlanceTimeInterval); + PERFLOG.info("--- PERFORMANCE MONITOR Initialized"); } - /** - * - * @return BookKeepers list - */ public ArrayList getBookKeepers() { return new ArrayList(bookKeepers.values()); @@ -105,14 +93,10 @@ public SimpleBookKeeper getSimpleBookKeeper() { } } - /** - * heartbeat - * - */ public void heartbeat(int delay, int period) { healthTimer.scheduleAtFixedRate(new Hearthbeat(), delay, period); - HEARTLOG.info("Set HEARTHBEAT in Timer Task (DELAY:" + delay + " PERIOD:" - + period + ")"); + HEARTLOG.info("Set HEARTHBEAT in Timer Task (DELAY: {}, PERIOD: {})", delay, + period); } } diff --git a/src/main/java/it/grid/storm/health/LogEvent.java b/src/main/java/it/grid/storm/health/LogEvent.java index 9c450b68..e25fb685 100644 --- a/src/main/java/it/grid/storm/health/LogEvent.java +++ b/src/main/java/it/grid/storm/health/LogEvent.java @@ -42,24 +42,6 @@ public class LogEvent implements Delayed { private String requestToken = null; private boolean successResult = false; - /** - * Constructor for ASYNCHRONOUS Event - * - * @param opType - * OperationType - * @param userDN - * String - * @param surl - * String - * @param startTime - * long - * @param duration - * long - * @param requestToken - * String - * @param successResult - * boolean - */ public LogEvent(OperationType opType, String userDN, String surl, long startTime, long duration, String requestToken, boolean successResult) { @@ -81,20 +63,6 @@ public LogEvent(OperationType opType, String userDN, String surl, } - /** - * Constructor for SYNCHRONOUS Event - * - * @param opType - * OperationType - * @param userDN - * String - * @param startTime - * long - * @param duration - * long - * @param successResult - * boolean - */ public LogEvent(OperationType opType, String userDN, long startTime, long duration, boolean successResult) { @@ -117,23 +85,9 @@ public LogEvent(OperationType opType, String userDN, long startTime, + (timeToLive * LogEvent.THOUSAND); this.birthTime = System.currentTimeMillis(); - HealthDirector.LOGGER.debug("Event TTL (milliSec): " + timeToLive); + HealthDirector.LOGGER.debug("Event TTL (milliSec): {}", timeToLive); } - /** - * Constructor for SYNCHRONOUS Event with surl - * - * @param opType - * OperationType - * @param userDN - * String - * @param startTime - * long - * @param duration - * long - * @param successResult - * boolean - */ public LogEvent(OperationType opType, String userDN, String surl, long startTime, long duration, boolean successResult) { @@ -155,7 +109,7 @@ public LogEvent(OperationType opType, String userDN, String surl, + (timeToLive * LogEvent.THOUSAND); this.birthTime = System.currentTimeMillis(); - HealthDirector.LOGGER.debug("Event TTL (milliSec): " + timeToLive); + HealthDirector.LOGGER.debug("Event TTL (milliSec): {}", timeToLive); } public OperationType getOperationType() { @@ -218,28 +172,17 @@ public String toString() { return sb.toString(); } - // ************** Methods of Delayed Interface ***************** - - /* - * (non-Javadoc) - * - * @see java.util.concurrent.Delayed#getDelay(java.util.concurrent.TimeUnit) - */ public long getDelay(TimeUnit unit) { long result = -1; result = unit.convert(deathTime - System.currentTimeMillis(), TimeUnit.MILLISECONDS); - HealthDirector.LOGGER.debug("Event TimeToLive : " + timeToLive - + " ... remaining : " + result); + HealthDirector.LOGGER.debug("Event TimeToLive : {} result: {}", + timeToLive, result); + return result; } - /* - * (non-Javadoc) - * - * @see java.lang.Comparable#compareTo(java.lang.Object) - */ public int compareTo(Delayed other) { LogEvent otherEvent = (LogEvent) other; @@ -251,5 +194,4 @@ public int compareTo(Delayed other) { } return 0; } - } diff --git a/src/main/java/it/grid/storm/health/OperationType.java b/src/main/java/it/grid/storm/health/OperationType.java index c8f922bb..3d4200b6 100644 --- a/src/main/java/it/grid/storm/health/OperationType.java +++ b/src/main/java/it/grid/storm/health/OperationType.java @@ -19,27 +19,6 @@ import it.grid.storm.scheduler.ChunkType; -/** - * - *

- * Title: - *

- * - *

- * Description: - *

- * - *

- * Copyright: Copyright (c) 2008 - *

- * - *

- * Company: - *

- * - * @author not attributable - * @version 1.0 - */ public class OperationType { private int operationIndex = -1; @@ -97,14 +76,6 @@ public class OperationType { public final static OperationType RS = new OperationType(17, "RS", "srmReserveSpace", OperationTypeCategory.SYNCH_FS_DB); - /** - * Constructor - * - * @param protocolName - * String - * @param protocolSchema - * String - */ public OperationType(int operationIndex, String operationName, String operationDescription, OperationTypeCategory opCat) { @@ -114,12 +85,6 @@ public OperationType(int operationIndex, String operationName, this.opTypeCategory = opCat; } - /** - * - * @param chunkType - * ChunkType - * @return OperationType - */ public static OperationType makeFromChunkType(ChunkType chunkType) { OperationType result = OperationType.UNDEF; @@ -186,5 +151,4 @@ public boolean equals(Object obj) { } return result; } - -} +} \ No newline at end of file diff --git a/src/main/java/it/grid/storm/health/OperationTypeCategory.java b/src/main/java/it/grid/storm/health/OperationTypeCategory.java index 7ac42768..023bd9ca 100644 --- a/src/main/java/it/grid/storm/health/OperationTypeCategory.java +++ b/src/main/java/it/grid/storm/health/OperationTypeCategory.java @@ -92,13 +92,6 @@ private OperationTypeCategory(String acronym, this.acronym = acronym; } - /******************************************************* - * Public methods - **/ - - /** - * - */ public boolean contains(OperationType op) { boolean result = false; @@ -108,11 +101,6 @@ public boolean contains(OperationType op) { return result; } - /** - * - * @param opType - * @return - */ public OperationTypeCategory getCategory(OperationType opType) { if (ASYNCH.contains(opType)) { @@ -138,5 +126,4 @@ public String toString() { return this.acronym; } - -} +} \ No newline at end of file diff --git a/src/main/java/it/grid/storm/health/PerformanceBookKeeper.java b/src/main/java/it/grid/storm/health/PerformanceBookKeeper.java index 549ec781..d995f32b 100644 --- a/src/main/java/it/grid/storm/health/PerformanceBookKeeper.java +++ b/src/main/java/it/grid/storm/health/PerformanceBookKeeper.java @@ -51,18 +51,12 @@ public PerformanceBookKeeper(int timeWindowInSecond, int glancerPeriodInSec) { this.visibleToGlancerInMSec = glancerPeriodInSec * THOUSAND; } - /* - * (non-Javadoc) - * - * @see - * it.grid.storm.health.BookKeeper#addLogEvent(it.grid.storm.health.LogEvent) - */ @Override public void addLogEvent(LogEvent logEvent) { boolean result = timedLogBook.offer(logEvent); - HealthDirector.LOGGER.debug("TimedLOGBOOK (offering result) " + result); - HealthDirector.LOGGER.debug("TimedLOGBOOK :" + timedLogBook.size()); + HealthDirector.LOGGER.debug("TimedLOGBOOK (offering result) {}", result); + HealthDirector.LOGGER.debug("TimedLOGBOOK : {}", timedLogBook.size()); } public long getGlanceWindowInMSec() { @@ -118,20 +112,20 @@ public ArrayList getCompleteSnapshot() { public ArrayList getEventsGlanced(long timeToLiveGraterThan) { ArrayList eGlanced = new ArrayList(); - log.debug("time to live - glance: "+timeToLiveGraterThan); + log.debug("time to live - glance: {}",timeToLiveGraterThan); removeZombieEvents(); for (LogEvent event : timedLogBook) { - log.debug("event: "+event.getDelay(TimeUnit.MILLISECONDS)); + log.debug("event: {}", event.getDelay(TimeUnit.MILLISECONDS)); if ((event.getDelay(TimeUnit.MILLISECONDS)) < timeToLiveGraterThan) { eGlanced.add(event); } } - log.debug("Nr. Events to analyze: "+eGlanced.size()); + log.debug("Nr. Events to analyze: {}", eGlanced.size()); + return eGlanced; } public PerformanceStatus getPerformanceStatus(long timeToLiveGraterThan) { - PerformanceStatus pStatus = new PerformanceStatus( getEventsGlanced(timeToLiveGraterThan)); return pStatus; diff --git a/src/main/java/it/grid/storm/health/PerformanceGlance.java b/src/main/java/it/grid/storm/health/PerformanceGlance.java index d7a873c0..ba040dd4 100644 --- a/src/main/java/it/grid/storm/health/PerformanceGlance.java +++ b/src/main/java/it/grid/storm/health/PerformanceGlance.java @@ -48,9 +48,9 @@ public PerformanceStatus haveaLook() { performanceStatus = pbk.getPerformanceStatus(); ArrayList zombies = pbk.removeZombieEvents(); HealthDirector.LOGGER - .debug("Removed # <" + zombies.size() + "> zombies."); - HealthDirector.LOGGER.debug("have a look : " + performanceStatus); - // *********************** pbk.cleanLogBook(); + .debug("Removed # <{}> zombies.", zombies.size()); + + HealthDirector.LOGGER.debug("have a look : {}", performanceStatus); } HealthDirector.LOGGER.debug(".. glance ended."); diff --git a/src/main/java/it/grid/storm/health/PerformancePulse.java b/src/main/java/it/grid/storm/health/PerformancePulse.java index 15305bb4..861f1f11 100644 --- a/src/main/java/it/grid/storm/health/PerformancePulse.java +++ b/src/main/java/it/grid/storm/health/PerformancePulse.java @@ -39,11 +39,6 @@ protected PerformancePulse() { perfMonitor = new PerformanceGlance(); } - /* - * (non-Javadoc) - * - * @see java.util.TimerTask#run() - */ @Override public void run() { diff --git a/src/main/java/it/grid/storm/health/PerformanceStatus.java b/src/main/java/it/grid/storm/health/PerformanceStatus.java index 233b7709..3446f954 100644 --- a/src/main/java/it/grid/storm/health/PerformanceStatus.java +++ b/src/main/java/it/grid/storm/health/PerformanceStatus.java @@ -37,17 +37,14 @@ public class PerformanceStatus { private Hashtable perfStatus = new Hashtable(); private static int timeWindows = HealthDirector.getHealthMonitor().perfGlanceTimeInterval; - /** - * - * @param eventToAnalyze - */ public PerformanceStatus(ArrayList eventToAnalyze) { PERF_LOG.debug("PERFORMANCE STATUS"); PerformanceEvent pEvent; OperationType ot; if (eventToAnalyze != null) { - PERF_LOG.debug("PERFORMANCE STATUS :" + eventToAnalyze.size()); + PERF_LOG.debug("PERFORMANCE STATUS : {}", + eventToAnalyze.size()); for (LogEvent event : eventToAnalyze) { ot = event.getOperationType(); if (perfStatus.containsKey(ot)) { diff --git a/src/main/java/it/grid/storm/https/HTTPPluginManager.java b/src/main/java/it/grid/storm/https/HTTPPluginManager.java index 7468ce31..787d0ff4 100644 --- a/src/main/java/it/grid/storm/https/HTTPPluginManager.java +++ b/src/main/java/it/grid/storm/https/HTTPPluginManager.java @@ -62,7 +62,7 @@ public static HTTPSPluginInterface getHTTPSPluginInstance() lock.wait(); log.debug("Initialization signaled!"); } catch (InterruptedException e) { - log.warn("Unexpected InterruptedException :" + e.getMessage()); + log.warn(e.getMessage(),e); } } if (!initialized) { diff --git a/src/main/java/it/grid/storm/https/HTTPSPluginException.java b/src/main/java/it/grid/storm/https/HTTPSPluginException.java index 21d5fd6e..4c685e87 100644 --- a/src/main/java/it/grid/storm/https/HTTPSPluginException.java +++ b/src/main/java/it/grid/storm/https/HTTPSPluginException.java @@ -22,31 +22,22 @@ */ public class HTTPSPluginException extends Exception { - /** - * - */ private static final long serialVersionUID = 1080597876348642193L; public HTTPSPluginException() { - // TODO Auto-generated constructor stub } public HTTPSPluginException(String message) { super(message); - // TODO Auto-generated constructor stub } public HTTPSPluginException(Throwable cause) { - super(cause); - // TODO Auto-generated constructor stub } public HTTPSPluginException(String message, Throwable cause) { - super(message, cause); - // TODO Auto-generated constructor stub } } diff --git a/src/main/java/it/grid/storm/https/HTTPSPluginInterfaceStub.java b/src/main/java/it/grid/storm/https/HTTPSPluginInterfaceStub.java index 64b8225c..cc7efa33 100644 --- a/src/main/java/it/grid/storm/https/HTTPSPluginInterfaceStub.java +++ b/src/main/java/it/grid/storm/https/HTTPSPluginInterfaceStub.java @@ -4,8 +4,10 @@ package it.grid.storm.https; import java.io.File; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import it.grid.storm.filesystem.FilesystemPermission; import it.grid.storm.filesystem.LocalFile; import it.grid.storm.griduser.LocalUser; @@ -22,179 +24,127 @@ public class HTTPSPluginInterfaceStub implements HTTPSPluginInterface { @Override public void grantServiceGroupPermission(LocalFile localFile, FilesystemPermission permission) { + + throw new UnsupportedOperationException("Unimplemented. " + + "Please check documentation on how to configure " + + "the HTTPs plugin properly"); - log.info("Granted group permission " + permission.toString() + " on file " - + localFile.toString() + " to service group"); } - /* - * (non-Javadoc) - * - * @see - * it.grid.storm.https.HTTPSPluginInterface#grantGroupPermission(it.grid.storm - * .filesystem.LocalFile, it.grid.storm.griduser.LocalUser, - * it.grid.storm.filesystem.FilesystemPermission) - */ @Override public void grantGroupPermission(LocalFile localFile, LocalUser localUser, FilesystemPermission permission) { - log.info("Granted group permission " + permission.toString() + " on file " - + localFile.toString() + " to group " + localUser.toString()); + throw new UnsupportedOperationException("Unimplemented. " + + "Please check documentation on how to configure " + + "the HTTPs plugin properly"); } @Override public void grantServiceUserPermission(LocalFile localFile, FilesystemPermission permission) { - log.info("Granted user permission " + permission.toString() + " on file " - + localFile.toString() + " to service user"); + throw new UnsupportedOperationException("Unimplemented. " + + "Please check documentation on how to configure " + + "the HTTPs plugin properly"); } - /* - * (non-Javadoc) - * - * @see - * it.grid.storm.https.HTTPSPluginInterface#grantUserPermission(it.grid.storm - * .filesystem.LocalFile, it.grid.storm.griduser.LocalUser, - * it.grid.storm.filesystem.FilesystemPermission) - */ @Override public void grantUserPermission(LocalFile localFile, LocalUser localUser, FilesystemPermission permission) { - log.info("Granted user permission " + permission.toString() + " on file " - + localFile.toString() + " to user " + localUser.toString()); - + throw new UnsupportedOperationException("Unimplemented. " + + "Please check documentation on how to configure " + + "the HTTPs plugin properly"); } - /* - * (non-Javadoc) - * - * @see - * it.grid.storm.https.HTTPSPluginInterface#removeGroupPermission(it.grid. - * storm.filesystem.LocalFile, it.grid.storm.griduser.LocalUser) - */ @Override public void removeGroupPermission(LocalFile localFile, LocalUser localUser) { - log.info("Removed group permission from file " + localFile.toString() - + " to group " + localUser.toString()); + throw new UnsupportedOperationException("Unimplemented. " + + "Please check documentation on how to configure " + + "the HTTPs plugin properly"); } - /* - * (non-Javadoc) - * - * @see - * it.grid.storm.https.HTTPSPluginInterface#removeUserPermission(it.grid.storm - * .filesystem.LocalFile, it.grid.storm.griduser.LocalUser) - */ @Override public void removeUserPermission(LocalFile localFile, LocalUser localUser) { - log.info("Removed user permission from file " + localFile.toString() - + " to user " + localUser.toString()); - + throw new UnsupportedOperationException("Unimplemented. " + + "Please check documentation on how to configure " + + "the HTTPs plugin properly"); } - /* - * (non-Javadoc) - * - * @see - * it.grid.storm.https.HTTPSPluginInterface#revokeGroupPermission(it.grid. - * storm.filesystem.LocalFile, it.grid.storm.griduser.LocalUser, - * it.grid.storm.filesystem.FilesystemPermission) - */ @Override public void revokeGroupPermission(LocalFile localFile, LocalUser localUser, FilesystemPermission permission) { - log.info("Revoked group permission " + permission.toString() - + " from file " + localFile.toString() + " to group " - + localUser.toString()); + throw new UnsupportedOperationException("Unimplemented. " + + "Please check documentation on how to configure " + + "the HTTPs plugin properly"); } - /* - * (non-Javadoc) - * - * @see - * it.grid.storm.https.HTTPSPluginInterface#revokeUserPermission(it.grid.storm - * .filesystem.LocalFile, it.grid.storm.griduser.LocalUser, - * it.grid.storm.filesystem.FilesystemPermission) - */ @Override public void revokeUserPermission(LocalFile localFile, LocalUser localUser, FilesystemPermission permission) { - log.info("Revoked user permission " + permission.toString() + " from file " - + localFile.toString() + " to user " + localUser.toString()); + throw new UnsupportedOperationException("Unimplemented. " + + "Please check documentation on how to configure " + + "the HTTPs plugin properly"); } - /* - * (non-Javadoc) - * - * @see - * it.grid.storm.https.HTTPSPluginInterface#setGroupPermission(it.grid.storm - * .filesystem.LocalFile, it.grid.storm.griduser.LocalUser, - * it.grid.storm.filesystem.FilesystemPermission) - */ @Override public void setGroupPermission(LocalFile localFile, LocalUser localUser, FilesystemPermission permission) { - log.info("Setted group permission " + permission.toString() + " on file " - + localFile.toString() + " to group " + localUser.toString()); - + throw new UnsupportedOperationException("Unimplemented. " + + "Please check documentation on how to configure " + + "the HTTPs plugin properly"); } - /* - * (non-Javadoc) - * - * @see - * it.grid.storm.https.HTTPSPluginInterface#setUserPermission(it.grid.storm - * .filesystem.LocalFile, it.grid.storm.griduser.LocalUser, - * it.grid.storm.filesystem.FilesystemPermission) - */ @Override public void setUserPermission(LocalFile localFile, LocalUser localUser, FilesystemPermission permission) { - log.info("Setted user permission " + permission.toString() + " on file " - + localFile.toString() + " to user " + localUser.toString()); - + throw new UnsupportedOperationException("Unimplemented. " + + "Please check documentation on how to configure " + + "the HTTPs plugin properly"); } @Override public void removeAllPermissions(LocalFile localFile) { - log.info("Removing all permissions from file " + localFile.toString()); - + throw new UnsupportedOperationException("Unimplemented. " + + "Please check documentation on how to configure " + + "the HTTPs plugin properly"); } @Override public void moveAllPermissions(LocalFile fromLocalFile, LocalFile toLocalFile) { - log.info("Moving all permissions from file " + fromLocalFile.toString() - + " to file " + toLocalFile.toString()); + throw new UnsupportedOperationException("Unimplemented. " + + "Please check documentation on how to configure " + + "the HTTPs plugin properly"); } @Override public String mapLocalPath(String hostname, String localAbsolutePath) { - log.info("Mapping local absolute path \'" + localAbsolutePath - + "\' to \'itIsTheSame" + File.separatorChar + localAbsolutePath + "\'"); - return File.separatorChar + "itIsTheSame" + localAbsolutePath; + throw new UnsupportedOperationException("Unimplemented. " + + "Please check documentation on how to configure " + + "the HTTPs plugin properly"); + } @Override public ServiceStatus getServiceStatus(String hostname, int port, Protocol protocol) throws HTTPSPluginException { - return ServiceStatus.RUNNING; + throw new UnsupportedOperationException("Unimplemented. " + + "Please check documentation on how to configure " + + "the HTTPs plugin properly"); } - -} +} \ No newline at end of file From 481d0f4c8552fb7869c65e28b36ed9b97b2133d7 Mon Sep 17 00:00:00 2001 From: Andrea Ceccanti Date: Thu, 6 Feb 2014 19:14:45 +0100 Subject: [PATCH 32/45] More logging rationalization work. --- .../storm/checksum/ChecksumClientImpl.java | 2 +- .../grid/storm/checksum/ChecksumManager.java | 7 +- .../checksum/ChecksumRuntimeException.java | 5 - src/main/java/it/grid/storm/common/GUID.java | 14 - .../java/it/grid/storm/common/HostLookup.java | 4 +- .../it/grid/storm/common/SRMConstants.java | 4 - .../java/it/grid/storm/common/types/SFN.java | 70 +++-- .../java/it/grid/storm/common/types/TFN.java | 37 +-- .../grid/storm/common/types/TURLPrefix.java | 5 +- .../grid/storm/concurrency/NamedThread.java | 27 +- .../storm/concurrency/TimingThreadPool.java | 13 +- .../it/grid/storm/config/ConfigReader.java | 78 +----- .../it/grid/storm/config/Configuration.java | 3 +- .../grid/storm/config/ConfigurationKeys.java | 256 ------------------ .../java/it/grid/storm/config/IniReader.java | 26 +- src/main/java/it/grid/storm/ea/StormEA.java | 5 +- .../it/grid/storm/ea/remote/Constants.java | 7 - .../ea/remote/resource/RequestParameters.java | 19 +- .../ea/remote/resource/StormEAResource.java | 24 +- 19 files changed, 121 insertions(+), 485 deletions(-) delete mode 100644 src/main/java/it/grid/storm/config/ConfigurationKeys.java diff --git a/src/main/java/it/grid/storm/checksum/ChecksumClientImpl.java b/src/main/java/it/grid/storm/checksum/ChecksumClientImpl.java index 508430a9..3750c540 100644 --- a/src/main/java/it/grid/storm/checksum/ChecksumClientImpl.java +++ b/src/main/java/it/grid/storm/checksum/ChecksumClientImpl.java @@ -132,7 +132,7 @@ public ChecksumServerStatus getStatus(String filePath) throws IOException { connection.disconnect(); - log.trace("Checksum server status response: " + responseBody); + log.trace("Checksum server status response: {}", responseBody); if (connection.getResponseCode() != 200) { return new ChecksumServerStatus(false, "HTML error: " diff --git a/src/main/java/it/grid/storm/checksum/ChecksumManager.java b/src/main/java/it/grid/storm/checksum/ChecksumManager.java index 3822a430..8d0df862 100644 --- a/src/main/java/it/grid/storm/checksum/ChecksumManager.java +++ b/src/main/java/it/grid/storm/checksum/ChecksumManager.java @@ -77,16 +77,13 @@ public String getDefaultAlgorithm() { public String getDefaultChecksum(String fileName) throws FileNotFoundException { - log.debug("Requesting checksum for file: " + fileName); + log.debug("Requesting checksum for file: {}", fileName); String checksum = null; try { checksum = StormEA.getChecksum(fileName, defaultAlgorithm); } catch (ExtendedAttributesException e) { - - log.warn("Error manipulating EA for default algorithm " - + defaultAlgorithm + " on file: " + fileName - + " ExtendedAttributesException: " + e.getMessage()); + log.warn(e.getMessage(),e); } return checksum; diff --git a/src/main/java/it/grid/storm/checksum/ChecksumRuntimeException.java b/src/main/java/it/grid/storm/checksum/ChecksumRuntimeException.java index d987c5f3..1eff3508 100644 --- a/src/main/java/it/grid/storm/checksum/ChecksumRuntimeException.java +++ b/src/main/java/it/grid/storm/checksum/ChecksumRuntimeException.java @@ -22,26 +22,21 @@ public class ChecksumRuntimeException extends RuntimeException { private static final long serialVersionUID = -6992922355763921291L; public ChecksumRuntimeException() { - - // TODO Auto-generated constructor stub } public ChecksumRuntimeException(String message) { super(message); - // TODO Auto-generated constructor stub } public ChecksumRuntimeException(Throwable cause) { super(cause); - // TODO Auto-generated constructor stub } public ChecksumRuntimeException(String message, Throwable cause) { super(message, cause); - // TODO Auto-generated constructor stub } } diff --git a/src/main/java/it/grid/storm/common/GUID.java b/src/main/java/it/grid/storm/common/GUID.java index 7f96d840..dda709b0 100644 --- a/src/main/java/it/grid/storm/common/GUID.java +++ b/src/main/java/it/grid/storm/common/GUID.java @@ -23,33 +23,19 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * GUID Value Object. - *

- * Used to retain/generate a GUID/UUID. - *

- */ public class GUID implements Serializable { - /** - * - */ private static final long serialVersionUID = -1750955753676929827L; private static final Logger log = LoggerFactory.getLogger(GUID.class); private byte guidValue[] = new byte[16]; - /** Creates a new instance of GUID */ public GUID() { - buildNewGUID(); } - /** - * Creates a new instance of GUID using a fixed guid. - */ public GUID(String guidString) { int pos = 0; diff --git a/src/main/java/it/grid/storm/common/HostLookup.java b/src/main/java/it/grid/storm/common/HostLookup.java index 7503d10f..661f3d5b 100644 --- a/src/main/java/it/grid/storm/common/HostLookup.java +++ b/src/main/java/it/grid/storm/common/HostLookup.java @@ -33,8 +33,10 @@ public HostLookup() { public String lookup(String hostname) throws UnknownHostException { - log.debug("Lookup:looking for hostname: " + hostname); InetAddress ia = InetAddress.getByName(hostname); + log.debug("Lookup for hostname: {} resulted in {}", + hostname, + ia.getHostAddress()); return ia.getHostAddress(); } diff --git a/src/main/java/it/grid/storm/common/SRMConstants.java b/src/main/java/it/grid/storm/common/SRMConstants.java index c2cf24b8..0ad26fd5 100644 --- a/src/main/java/it/grid/storm/common/SRMConstants.java +++ b/src/main/java/it/grid/storm/common/SRMConstants.java @@ -39,9 +39,5 @@ public class SRMConstants { */ public static final boolean fullDetailedList = false; - public SRMConstants() { - - // TODO Auto-generated constructor stub - } } diff --git a/src/main/java/it/grid/storm/common/types/SFN.java b/src/main/java/it/grid/storm/common/types/SFN.java index 59dddf16..08b78ec9 100644 --- a/src/main/java/it/grid/storm/common/types/SFN.java +++ b/src/main/java/it/grid/storm/common/types/SFN.java @@ -34,7 +34,7 @@ */ public class SFN { - static private Logger log = LoggerFactory.getLogger(SFN.class); + private static final Logger log = LoggerFactory.getLogger(SFN.class); private Machine m = null; private Port p = null; @@ -223,7 +223,6 @@ public static SFN makeFromString(String surlString) * @throws ParsingSFNAttributesException * @throws InvalidSFNAttributesException */ - // TODO MICHELE USER_SURL created private static SFN makeFromQueryForm(String surlString, int colon, int slash, int question) throws ParsingSFNAttributesException, InvalidSFNAttributesException { @@ -233,8 +232,8 @@ private static SFN makeFromQueryForm(String surlString, int colon, int slash, try { machine = Machine.make(machineString); } catch (InvalidMachineAttributeException e) { - log.warn("SFN: Unable to build -machine- attribute with the String '" - + machineString + "'." + e); + log.warn("SFN: Unable to build -machine- attribute from {}. {}", + machineString, e.getMessage()); } if ((colon + 1) == slash) { // slash found right after colon! There is no port! @@ -246,12 +245,8 @@ private static SFN makeFromQueryForm(String surlString, int colon, int slash, Port port = null; try { port = Port.make(Integer.parseInt(portString)); - } catch (InvalidPortAttributeException e) { - log.warn("SFN: Unable to build -port- attribute with the String '" - + portString + "'." + e); - } catch (NumberFormatException e) { - log.warn("SFN: Unable to build -port- attribute with the String (NFE) '" - + portString + "'." + e); + } catch (Throwable e) { + log.warn("SFN: Unable to build -port- attribute from {}. {}", portString, e.getMessage()); } // EndPoint String endpointString = surlString.substring(slash, question); @@ -259,8 +254,8 @@ private static SFN makeFromQueryForm(String surlString, int colon, int slash, try { endpoint = EndPoint.make(endpointString); } catch (InvalidEndPointAttributeException e) { - log.warn("SFN: Unable to build -endpoint- attribute with the String '" - + endpointString + "'." + e); + log.warn("SFN: Unable to build -endpoint- attribute from {}. {}", + endpointString, e.getMessage()); } // StFN checks only for a starting / while the rest can be empty! So it is // sufficient to choose whatever String starts at the /... even just the @@ -279,8 +274,9 @@ private static SFN makeFromQueryForm(String surlString, int colon, int slash, try { stfn = StFN.make(stfnString); } catch (InvalidStFNAttributeException e) { - log.warn("SFN: Unable to build -stfn- attribute with the String '" - + stfnString + "'." + e); + log.warn("SFN: Unable to build -stfn- attribute from {}. {}", + stfnString, + e.getMessage()); } return SFN.makeInQueryForm(machine, port, endpoint, stfn); } @@ -297,7 +293,6 @@ private static SFN makeFromQueryForm(String surlString, int colon, int slash, * @throws ParsingSFNAttributesException * @throws InvalidSFNAttributesException */ - // TODO MICHELE USER_SURL created private static SFN makeFromSimpleForm(String surlString, int colon, int slash) throws ParsingSFNAttributesException, InvalidSFNAttributesException { @@ -306,8 +301,9 @@ private static SFN makeFromSimpleForm(String surlString, int colon, int slash) try { machine = Machine.make(machineString); } catch (InvalidMachineAttributeException e) { - log.warn("SFN: Unable to build -machine- attribute with the String '" - + machineString + "'." + e); + + log.warn("SFN: Unable to build -machine- attribute from {}. {}", + machineString, e.getMessage()); } if ((colon + 1) == slash) { /* Slash found right after colon! There is no port! */ @@ -320,12 +316,9 @@ private static SFN makeFromSimpleForm(String surlString, int colon, int slash) Port port = null; try { port = Port.make(Integer.parseInt(portString)); - } catch (InvalidPortAttributeException e) { - log.warn("SFN: Unable to build -port- attribute with the String '" - + portString + "'." + e); - } catch (NumberFormatException e) { - log.warn("SFN: Unable to build -port- attribute with the String (NFE) '" - + portString + "'." + e); + } catch (Throwable e) { + log.warn("SFN: Unable to build -port- attribute from {}. {}", + portString, e.getMessage()); } // StFN checks only for a starting / while the rest can be empty! So it is // sufficient to choose whatever String starts at the /... even just the @@ -336,8 +329,9 @@ private static SFN makeFromSimpleForm(String surlString, int colon, int slash) try { stfn = StFN.make(stfnString); } catch (InvalidStFNAttributeException e) { - log.warn("SFN: Unable to build -stfn- attribute with the String '" - + stfnString + "'." + e); + log.warn("SFN: Unable to build -stfn- attribute from {}. {}", + stfnString, + e.getMessage()); } return SFN.makeInSimpleForm(machine, port, stfn); } @@ -353,7 +347,6 @@ private static SFN makeFromSimpleForm(String surlString, int colon, int slash) * @throws ParsingSFNAttributesException * @throws InvalidSFNAttributesException */ - // TODO MICHELE USER_SURL created private static SFN makeFromQueryFormNoPort(String surlString, int question, int slash) throws ParsingSFNAttributesException, InvalidSFNAttributesException { @@ -363,8 +356,9 @@ private static SFN makeFromQueryFormNoPort(String surlString, int question, try { machineType = Machine.make(machine); } catch (InvalidMachineAttributeException e) { - log.warn("SFN: Unable to build -machine- attribute with the String '" - + machine + "'." + e); + + log.warn("SFN: Unable to build -machine- attribute from {}. {}", + machine, e.getMessage()); } // EndPoint String endpoint = surlString.substring(slash, question); @@ -372,8 +366,9 @@ private static SFN makeFromQueryFormNoPort(String surlString, int question, try { endpointType = EndPoint.make(endpoint); } catch (InvalidEndPointAttributeException e) { - log.warn("SFN: Unable to build -endpoint- attribute with the String '" - + endpoint + "'." + e); + + log.warn("SFN: Unable to build -endpoint- attribute from {}. {}", + endpoint, e.getMessage()); } // StFN checks only for a starting / while the rest can be empty! So it is // sufficient to choose whatever String starts at the /... even just the @@ -392,8 +387,9 @@ private static SFN makeFromQueryFormNoPort(String surlString, int question, try { stfn = StFN.make(stfnString); } catch (InvalidStFNAttributeException e) { - log.warn("SFN: Unable to build -stfn- attribute with the String '" - + stfnString + "'." + e); + log.warn("SFN: Unable to build -stfn- attribute from {}. {}", + stfnString, + e.getMessage()); } return SFN.makeInQueryForm(machineType, endpointType, stfn); } @@ -409,7 +405,6 @@ private static SFN makeFromQueryFormNoPort(String surlString, int question, * @throws ParsingSFNAttributesException * @throws InvalidSFNAttributesException */ - // TODO MICHELE USER_SURL created private static SFN makeFromSimpleFormNoPort(String surlString, int slash) throws ParsingSFNAttributesException, InvalidSFNAttributesException { @@ -418,8 +413,8 @@ private static SFN makeFromSimpleFormNoPort(String surlString, int slash) try { machineType = Machine.make(machine); } catch (InvalidMachineAttributeException e) { - log.warn("SFN: Unable to build -machine- attribute with the String '" - + machine + "'." + e); + log.warn("SFN: Unable to build -machine- attribute from {}. {}", + machine, e.getMessage()); } // StFN checks only for a starting / while the rest can be empty! So it // is sufficient to choose whatever String starts at the /... even just @@ -430,8 +425,9 @@ private static SFN makeFromSimpleFormNoPort(String surlString, int slash) try { stfn = StFN.make(stfnString); } catch (InvalidStFNAttributeException e) { - log.warn("SFN: Unable to build -stfn- attribute with the String '" - + stfnString + "'." + e); + log.warn("SFN: Unable to build -stfn- attribute from {}. {}", + stfnString, + e.getMessage()); } return SFN.makeInSimpleForm(machineType, stfn); diff --git a/src/main/java/it/grid/storm/common/types/TFN.java b/src/main/java/it/grid/storm/common/types/TFN.java index 62ed0f72..25ddf375 100644 --- a/src/main/java/it/grid/storm/common/types/TFN.java +++ b/src/main/java/it/grid/storm/common/types/TFN.java @@ -111,8 +111,9 @@ public static TFN makeFromString(String s) try { m = Machine.make(mString); } catch (InvalidMachineAttributeException e) { - log.warn("TFN: Unable to build -machine- attribute with the String '" - + mString + "'." + e); + + log.warn("TFN: Unable to build -machine- attribute from {}. {}", + mString, e.getMessage()); } // Port is empty because it is optional specification @@ -126,8 +127,8 @@ public static TFN makeFromString(String s) try { pfn = PFN.make(pfnString); } catch (InvalidPFNAttributeException e) { - log.warn("TFN: Unable to build -pfn- attribute with the String '" - + pfnString + "'." + e); + log.warn("TFN: Unable to build -pfn- attribute from {}. {}", + pfnString,e.getMessage()); } return TFN.make(m, p, pfn); } else if ((slash != -1) && (colon > slash)) { @@ -145,8 +146,9 @@ public static TFN makeFromString(String s) try { m = Machine.make(mString); } catch (InvalidMachineAttributeException e) { - log.warn("TFN: Unable to build -machine- attribute with the String '" - + mString + "'." + e); + + log.warn("TFN: Unable to build -machine- attribute from {}. {}", + mString, e.getMessage()); } // Port is empty because it is optional specification Port p = Port.makeEmpty(); @@ -159,8 +161,8 @@ public static TFN makeFromString(String s) try { pfn = PFN.make(pfnString); } catch (InvalidPFNAttributeException e) { - log.warn("TFN: Unable to build -pfn- attribute with the String '" - + pfnString + "'." + e); + log.warn("TFN: Unable to build -pfn- attribute from {}. {}", + pfnString,e.getMessage()); } return TFN.make(m, p, pfn); } else if ((slash != -1) && (colon < slash)) { @@ -176,8 +178,9 @@ public static TFN makeFromString(String s) try { m = Machine.make(mString); } catch (InvalidMachineAttributeException e) { - log.warn("TFN: Unable to build -machine- attribute with the String '" - + mString + "'." + e); + + log.warn("TFN: Unable to build -machine- attribute from {}. {}", + mString, e.getMessage()); } // port if ((colon + 1) == slash) @@ -190,12 +193,11 @@ public static TFN makeFromString(String s) try { p = Port.make(Integer.parseInt(pString)); } catch (InvalidPortAttributeException e) { - log.warn("TFN: Unable to build -port- attribute with the String '" - + pString + "'." + e); + log.warn("TFN: Unable to build -port- attribute from {}.{}", + pString, e.getMessage()); } catch (NumberFormatException e) { - log - .warn("TFN: Unable to build -port- attribute with the String (NFE) '" - + pString + "'." + e); + log.warn("TFN: Unable to build -port- attribute from {}.{}", + pString, e.getMessage()); } // PFN checks only for a starting / while the rest can be empty! So it is // sufficient to choose whatever String starts at the /... even just the @@ -206,8 +208,9 @@ public static TFN makeFromString(String s) try { pfn = PFN.make(pfnString); } catch (InvalidPFNAttributeException e) { - log.warn("TFN: Unable to build -pfn- attribute with the String '" - + pfnString + "'." + e); + + log.warn("TFN: Unable to build -pfn- attribute from {}. {}", + pfnString,e.getMessage()); } return TFN.make(m, p, pfn); } else { diff --git a/src/main/java/it/grid/storm/common/types/TURLPrefix.java b/src/main/java/it/grid/storm/common/types/TURLPrefix.java index 98d90fa1..a1cacce3 100644 --- a/src/main/java/it/grid/storm/common/types/TURLPrefix.java +++ b/src/main/java/it/grid/storm/common/types/TURLPrefix.java @@ -29,7 +29,7 @@ */ public class TURLPrefix { - private static Logger log = LoggerFactory.getLogger(TURLPrefix.class); + private static final Logger log = LoggerFactory.getLogger(TURLPrefix.class); public static final String PNAME_TURL_PREFIX = "turlPrefix"; private ArrayList desiredProtocols; @@ -109,8 +109,7 @@ public static TURLPrefix decode(Map inputParam, String memberName) { for (Object value : valueArray) { Protocol protocol = Protocol.getProtocol(value.toString()); if (protocol.equals(Protocol.UNKNOWN)) { - log.warn("Unable to decode protocol " + value.toString() - + " . Unknown protocol"); + log.warn("Protocol {} is unknown." , value); } else { protocols.add(protocol); } diff --git a/src/main/java/it/grid/storm/concurrency/NamedThread.java b/src/main/java/it/grid/storm/concurrency/NamedThread.java index 45ca8a54..c0837a47 100644 --- a/src/main/java/it/grid/storm/concurrency/NamedThread.java +++ b/src/main/java/it/grid/storm/concurrency/NamedThread.java @@ -7,7 +7,6 @@ public class NamedThread extends Thread { public static final String DEFAULT_NAME = "StoRM-Thread"; - public static volatile boolean traceLevel = false; private static final AtomicInteger created = new AtomicInteger(); private static final AtomicInteger alive = new AtomicInteger(); private static final Logger log = LoggerFactory.getLogger(NamedThread.class); @@ -27,14 +26,14 @@ public NamedThread(Runnable target) { public NamedThread(Runnable target, String name) { super(target, name + "-" + created.incrementAndGet()); - boolean debug = traceLevel; - if (debug) - log.trace("Created " + getName()); + + log.trace("Created thread {}", getName()); + setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { public void uncaughtException(Thread t, Throwable e) { - log.error("UNCAUGHT in thread " + t.getName(), e); + log.error("UNCAUGHT in thread {}", t.getName(), e); } }); @@ -42,16 +41,14 @@ public void uncaughtException(Thread t, Throwable e) { public void run() { - boolean debug = traceLevel; - if (debug) - log.debug("Running " + getName()); + log.trace("NamedThread.run name={}", getName()); + try { alive.incrementAndGet(); super.run(); } finally { alive.decrementAndGet(); - if (debug) - log.debug("Exiting " + getName()); + log.trace("NamedThread.run name={} done.", getName()); } } @@ -65,14 +62,4 @@ public static int getThreadAlive() { return alive.get(); } - public static boolean getDebugStatus() { - - return traceLevel; - } - - public static void setTrace(boolean debug) { - - traceLevel = debug; - } - } diff --git a/src/main/java/it/grid/storm/concurrency/TimingThreadPool.java b/src/main/java/it/grid/storm/concurrency/TimingThreadPool.java index 17f89b47..46be7a3c 100644 --- a/src/main/java/it/grid/storm/concurrency/TimingThreadPool.java +++ b/src/main/java/it/grid/storm/concurrency/TimingThreadPool.java @@ -31,7 +31,7 @@ public TimingThreadPool(int corePoolSize, int maximumPoolSize, protected void beforeExecute(Thread t, Runnable r) { super.beforeExecute(t, r); - log.debug(String.format("Thread %s: start %s", t, r)); + log.debug("Thread {}: start {}", t, r); startTime.set(System.nanoTime()); } @@ -45,7 +45,7 @@ protected void afterExecute(Runnable r, Throwable t) { if (t == null && r instanceof Future) { try { Object result = ((Future) r).get(); - log.debug("Thread ended with result: " + result); + log.debug("Thread ended with result: {}", result); } catch (CancellationException ce) { t = ce; } catch (ExecutionException ee) { @@ -53,15 +53,14 @@ protected void afterExecute(Runnable r, Throwable t) { } catch (InterruptedException ie) { Thread.currentThread().interrupt(); // ignore/reset } - log.debug(String.format("Throwable %s: end %s, time=%dns", t, r, - taskTime)); + log.debug("Throwable {}. end {}, time={}ns", + t,r,taskTime); } else { - // Something was wrong - log.warn("Throwable : " + t); + log.debug("Throwable {}", t); + } } finally { super.afterExecute(r, t); } } - } diff --git a/src/main/java/it/grid/storm/config/ConfigReader.java b/src/main/java/it/grid/storm/config/ConfigReader.java index 27e2d936..7bfcf4b6 100644 --- a/src/main/java/it/grid/storm/config/ConfigReader.java +++ b/src/main/java/it/grid/storm/config/ConfigReader.java @@ -29,65 +29,21 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -/** - * Class that reads the configuration parameters from different sources. It - * makes use of org.apache.commons.configuration package. - * - * For now, the parameters are read from only one file, and there _is_ automatic - * reloading of parameters if they change on file! Yet not all parts of the BE - * are for now capable of changing their behaviour when those parameters change! - * - * Certain keys present in the configuration file may contain more comma - * separated values; see Class Configuration for information on each available - * key and whether such keys may or may not have several comma separated values. - * - * Be warned that the primary reason for this class is that Apache s package - * could not be loaded directly into StoRMs Configuration class because of name - * conflicts! - * - * @author Riccardo Zappi; EGRID - ICTP Trieste; - * @version 2.0 - */ public class ConfigReader { private static final Logger log = LoggerFactory.getLogger(ConfigReader.class); - private Configuration c = makeEmptyConfiguration(); // configuration object - // holding all parameters! - private String configurationPathname = ""; // complete path to configuration - // file set to empty! - private int refresh = 0; // refresh time in seconds before the configuration - // is checked for a change in parameters! + private Configuration c = makeEmptyConfiguration(); + + private String configurationPathname = ""; + + private int refresh = 0; + - /** - * Constructor that returns a ConfigReader made of an empty Configuration: no - * file from which to read parameters is specified, and essentially all - * requests for existance of specific keys returns false. - */ public ConfigReader() { - makeEmptyConfiguration(); } - /** - * Constructor used to setup the complete pathname to the sole file holding - * the configuration parameters. It requires a String representing the - * configurationPathname, and an int representing the refresh rate when - * checking for a change in the content of the configuration file. - * - * Beware, that by pathname it is meant the complete path from root, including - * the _name_ of the file. - * - * If null configurationPathname is passed, then no setting of file pathname - * takes place. In such case and in case of any error, such as missing file, - * then an empty Configuration gets set up and proper messages get displayed - * in std.err, st.out as well as in the logs. - * - * The second parameter refers to the refresh rate for checking modifications - * to the configuration file, in seconds: 0 means no refresh. If a negative - * refresh is specified, by default no refresh takes place (i.e. it is like - * supplying 0). - */ public ConfigReader(String configurationPathname, int refresh) { if (configurationPathname != null) { @@ -95,35 +51,31 @@ public ConfigReader(String configurationPathname, int refresh) { refresh = 0; this.refresh = refresh; this.configurationPathname = configurationPathname; - log.info("Reading configuration file " + configurationPathname - + " and setting refresh rate to " + refresh + " seconds."); + log.info("Configuration file {}. Refresh rate: {} seconds", + configurationPathname, + refresh); + try { - // create reloading strategy for refresh FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy(); strategy.setRefreshDelay(refresh); - // specify the properties file and set the reloading strategy for that - // file PropertiesConfiguration properties = new PropertiesConfiguration( configurationPathname); - log.debug("Properties read from file:"); + log.debug("Configuration properties:"); String key; for (Iterator i = properties.getKeys(); i.hasNext();) { key = (String) i.next(); - log.debug(key + "=" + properties.getProperty(key).toString()); + log.debug("{} = {}", key, properties.getProperty(key).toString()); } properties.setReloadingStrategy(strategy); - // add the properties to the configuration this.c = new CompositeConfiguration(); ((CompositeConfiguration) this.c).addConfiguration(properties); - log.info("Configuration file read successfully."); + log.info("Configuration read successfully."); } catch (ConfigurationException e) { this.c = makeEmptyConfiguration(); - log.error("ATTENTION! Reading of configuration file " + configurationPathname + " failed! " + e); - log.error("ATTENTION! Please check logs for exact configuration in use!"); + log.error("Configuration parsing error: {}", e.getMessage(), e); } } else { - System.err - .println("WARNING!!! Null configuration pathname supplied: this could be a programming bug! Please check standard output or logs for exact configuration in use!"); + throw new NullPointerException("Null configuration pathname."); } } diff --git a/src/main/java/it/grid/storm/config/Configuration.java b/src/main/java/it/grid/storm/config/Configuration.java index f06dcc27..7485e181 100644 --- a/src/main/java/it/grid/storm/config/Configuration.java +++ b/src/main/java/it/grid/storm/config/Configuration.java @@ -343,13 +343,12 @@ public String getDBDriver() { // return default return "com.mysql.jdbc.Driver"; } else { - // load from external source String vendor = cr.getConfiguration().getString(DB_DRIVER_KEY); String driver = ""; if (vendor.toLowerCase().equals("mysql")) { driver = "com.mysql.jdbc.Driver"; } else { - log.error("CONFIG ERROR 'RDBMS Vendor ('" + vendor + "')unknown.' "); + log.error("CONFIG ERROR 'RDBMS Vendor ('{}') unknown.'", vendor); } return driver; } diff --git a/src/main/java/it/grid/storm/config/ConfigurationKeys.java b/src/main/java/it/grid/storm/config/ConfigurationKeys.java deleted file mode 100644 index 501df6c2..00000000 --- a/src/main/java/it/grid/storm/config/ConfigurationKeys.java +++ /dev/null @@ -1,256 +0,0 @@ -/* - * - * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ - -/** - * - */ -package it.grid.storm.config; - -import java.io.BufferedReader; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileReader; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.HashMap; -import java.util.List; -import java.util.Properties; -import java.util.Set; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * @author ritz - * - */ -public class ConfigurationKeys { - - private static final Logger log = LoggerFactory.getLogger(ConfigurationKeys.class); - - private static final String fs = File.separator; - private final String configFN = "src" + fs + "it" + fs + "grid" + fs - + "storm" + fs + "config" + fs + "Configuration.java"; - - public HashMap getMethodsKeys() { - - HashMap method_key = new HashMap(); - - try { - // Retrieve the list of defined methods - Method m[] = Configuration.instance.getClass().getDeclaredMethods(); - - for (int i = 0; i < m.length; i++) { - String methodName = m[i].getName(); - if ((m[i].getName().substring(0, 3).equals("get")) - && (!m[i].getName().equals("getInstance"))) { - String keyName = "unknown"; - method_key.put(methodName, keyName); - } - } - log.debug("Configuration has " + method_key.size() + " methods getting key values."); - } catch (SecurityException se) { - log.error("Unable to list the definible keys.." + se); - } - - // Store the source code into ArrayList - int lineNr = 0; - String configurationCodeFileName = System.getProperty("user.dir") + fs - + configFN; - ArrayList configurationCode = new ArrayList(); - try { - BufferedReader in = new BufferedReader(new FileReader( - configurationCodeFileName)); - String str; - while ((str = in.readLine()) != null) { - configurationCode.add(str); - lineNr++; - } - in.close(); - log.debug("Configuration has " + lineNr + " lines of code."); - } catch (IOException e) { - log.error("Some problem to read '" + configurationCodeFileName + "'"); - } - - int currentLine = 0; - // Scan the source code to retrieve the keys - for (String line : configurationCode) { - String method; - currentLine++; - // check if the line is a get method definition. - if (line.contains("public")) { - String[] fields = line.split(" "); - for (String field : fields) { - if (field.startsWith("get")) { - int endIndex = field.indexOf("("); - if (endIndex == -1) { - endIndex = field.length(); - } - method = field.substring(0, endIndex); - - // Check if the method is present into the list - if (method_key.containsKey(method)) { - // Found the method, search for the key. - log.debug("found a method GET : '" + method + "'"); - int line_to_end = lineNr - currentLine; - int lineToScan = (line_to_end > 5 ? 5 : line_to_end); - for (int j = currentLine; j < currentLine + lineToScan; j++) { - if (configurationCode.get(j).contains("String key")) { - String lineKey = configurationCode.get(j); - log.debug("Key line : " + lineKey); - // Found a key.. extract the key-name - int beginIndex = lineKey.indexOf("\""); - if (beginIndex > 0) { - // Found \" - String keyName = lineKey.substring(beginIndex); - endIndex = keyName.indexOf(";"); - if (endIndex > 0) { - keyName = keyName.substring(1, endIndex - 1); - log.debug("found a KEY : '" + keyName + "'"); - method_key.put(method, keyName); - } - } - } - } - } - } - } - } - } - - return method_key; - } - - /** - * - * @return - */ - public List getKeys() { - - ArrayList definedKeys = new ArrayList(); - - HashMap method_key = getMethodsKeys(); - - // Print out method-keys - Set methods = method_key.keySet(); - for (String meth : methods) { - log.debug("method: " + meth); - String key = method_key.get(meth); - log.debug(" key : " + key); - if (key.equals("unknown")) { - log.warn("#### Meth: " + meth + " --- " + key); - } - definedKeys.add(key); - } - return definedKeys; - } - - public List getTemplateKeys() { - - ArrayList templateKeys = new ArrayList(); - // Store the source code into ArrayList - String templateFileName = System.getProperty("user.dir") + fs + "etc" + fs - + "storm.properties.template"; - Properties template = new Properties(); - try { - template.load(new FileInputStream(templateFileName)); - } catch (IOException e) { - log.error("Error while reading the properties template"); - } - - for (Enumeration scan = template.keys(); scan.hasMoreElements();) { - templateKeys.add("" + scan.nextElement()); - } - return templateKeys; - } - - public List getDuplicatedKeys() { - - ArrayList duplicatedKeys = new ArrayList(); - ArrayList keys = new ArrayList(); - // Store the source code into ArrayList - String templateFileName = System.getProperty("user.dir") + fs + "etc" + fs - + "storm.properties.template"; - - // Store the key into ArrayList - int lineNr = 0; - try { - BufferedReader in = new BufferedReader(new FileReader(templateFileName)); - String str; - while ((str = in.readLine()) != null) { - if (!(str.startsWith("#"))) { - if (str.length() > 0) { - String line = str.trim(); - int index = line.indexOf("="); - if (index < 0) { - log.warn("strange line : " + line); - } else { - String keyName = line.substring(0, index); - if (keys.contains(keyName)) { - duplicatedKeys.add(keyName); - } else { - keys.add(keyName); - } - } - } - } - } - in.close(); - log.debug("Configuration has " + lineNr + " lines of code."); - } catch (IOException e) { - log.error("Some problem to read '" + templateFileName + "'"); - } - int count = 1; - for (String key : keys) { - log.debug("key (" + count + "): " + key); - count++; - } - return duplicatedKeys; - } - - public HashMap getKeyValue() { - - HashMap method_keys = getMethodsKeys(); - HashMap keys_values = new HashMap(); - Method[] allMethods = Configuration.instance.getClass() - .getDeclaredMethods(); - Set methodNames = method_keys.keySet(); - log.debug("sizes KeySet= " + methodNames.size()); - log.debug("sizes methods = " + allMethods.length); - for (Method m : allMethods) { - log.debug("scanning for method '" + m + "'"); - if (methodNames.contains(m.getName())) { - log.debug("method invocable : " + m.getName()); - try { - Object result = m.invoke(Configuration.instance, new Object[0]); - log.debug("Output = '" + result.toString() + "'"); - } catch (IllegalArgumentException e) { - log.error(e.getMessage()); - } catch (IllegalAccessException e) { - log.error(e.getMessage()); - } catch (InvocationTargetException e) { - log.error(e.getMessage()); - } - } - } - return keys_values; - - } -} diff --git a/src/main/java/it/grid/storm/config/IniReader.java b/src/main/java/it/grid/storm/config/IniReader.java index c5e4dc1d..cfb9c434 100644 --- a/src/main/java/it/grid/storm/config/IniReader.java +++ b/src/main/java/it/grid/storm/config/IniReader.java @@ -36,17 +36,11 @@ public class IniReader { .configurationDir(); private List iniFiles = new ArrayList(); - /** - * - */ public IniReader() throws IllegalArgumentException { this(DEFAULT_CONF_PATH); } - /** - * @param configurationPath - */ public IniReader(String configurationPath) throws IllegalArgumentException { if (configurationPath == null) { @@ -56,8 +50,9 @@ public IniReader(String configurationPath) throws IllegalArgumentException { } File confFolder = new File(configurationPath); if (!confFolder.isDirectory()) { - log.error("The provided configurationPath " + configurationPath - + " is not a valid directory"); + + log.error("The provided configurationPath {} is not a valid directory", + configurationPath); throw new IllegalArgumentException("The provided configurationPath " + configurationPath + " is not a valid directory"); } @@ -69,8 +64,8 @@ public IniReader(String configurationPath) throws IllegalArgumentException { } } if (iniFiles.size() == 0) { - log.error("The provided configurationPath " + configurationPath - + " does not contains ini files"); + log.error("The provided configurationPath {} does not contains ini files", + configurationPath); throw new IllegalArgumentException("The provided configurationPath " + configurationPath + " does not contains ini files"); } @@ -99,15 +94,8 @@ public Ini getIniFile(String iniFileName) throws IllegalArgumentException { if (iniFile.getName().equals(iniFileName.trim())) { try { ini = new Ini(new FileReader(iniFile)); - } catch (InvalidFileFormatException e) { - log.error("Unable to parse '" + iniFile - + "' InvalidFileFormatException: ", e); - } catch (FileNotFoundException e) { - log.error("Unable to find '" + iniFile + "' FileNotFoundException: ", - e); - } catch (IOException e) { - log.error("IO Exception during load '" + iniFile + "' IOException: ", - e); + } catch (Throwable e) { + log.error(e.getMessage(), e); } break; } diff --git a/src/main/java/it/grid/storm/ea/StormEA.java b/src/main/java/it/grid/storm/ea/StormEA.java index c8fa66cb..a1e539bf 100644 --- a/src/main/java/it/grid/storm/ea/StormEA.java +++ b/src/main/java/it/grid/storm/ea/StormEA.java @@ -93,8 +93,9 @@ public static long getPinned(String fileName) { public static void removeChecksum(String fileName) { if (!ea.hasXAttr(fileName, EA_CHECKSUM)) { - log.info("Cannot remove '" + EA_CHECKSUM - + "' EA because the attribute was not found: " + fileName); + log.info("Cannot remove '{}' EA. Attribute not found for file: {}", + EA_CHECKSUM, + fileName); return; } diff --git a/src/main/java/it/grid/storm/ea/remote/Constants.java b/src/main/java/it/grid/storm/ea/remote/Constants.java index e3b61552..79af1195 100644 --- a/src/main/java/it/grid/storm/ea/remote/Constants.java +++ b/src/main/java/it/grid/storm/ea/remote/Constants.java @@ -26,11 +26,4 @@ public class Constants { public static final String CHECKSUM_VALUE_KEY = "value"; public static final String VERSION = "1.0"; - - /* - * - * GET: /RESOURCE/VERSION/path/ADLER_32 - * - * PUT: /RESOURCE/VERSION/path/ADLER_32?CHECKSUM_VALUE_KEY=value - */ } diff --git a/src/main/java/it/grid/storm/ea/remote/resource/RequestParameters.java b/src/main/java/it/grid/storm/ea/remote/resource/RequestParameters.java index 801f93b5..73570234 100644 --- a/src/main/java/it/grid/storm/ea/remote/resource/RequestParameters.java +++ b/src/main/java/it/grid/storm/ea/remote/resource/RequestParameters.java @@ -35,9 +35,7 @@ private static String decodeAndCheckFilePath(String filePath) try { filePathDecoded = URLDecoder.decode(filePath, Constants.ENCODING_SCHEME); } catch (UnsupportedEncodingException e) { - log - .error("Unable to decode filePath parameter. UnsupportedEncodingException : " - + e.getMessage()); + log.error(e.getMessage(), e); ResponseBuilderImpl responseBuilder = new ResponseBuilderImpl(); responseBuilder.status(Response.Status.BAD_REQUEST); responseBuilder @@ -45,12 +43,13 @@ private static String decodeAndCheckFilePath(String filePath) + Constants.ENCODING_SCHEME + "\'"); throw new WebApplicationException(responseBuilder.build()); } - log.debug("Decoded filePath = " + filePathDecoded); + + log.debug("Decoded filePath = {}", filePathDecoded); if (filePathDecoded == null || filePathDecoded.trim().equals("")) { log - .error("Unable to evaluate permissions. Some parameters are missing : filePath " - + filePathDecoded); + .error("Unable to evaluate permissions. Some parameters are missing : filePath {}", + filePathDecoded); ResponseBuilderImpl responseBuilder = new ResponseBuilderImpl(); responseBuilder.status(Response.Status.BAD_REQUEST); responseBuilder @@ -69,9 +68,7 @@ private static String decodeAndCheckChecksum(String checksum) try { checksumDecoded = URLDecoder.decode(checksum, Constants.ENCODING_SCHEME); } catch (UnsupportedEncodingException e) { - log - .error("Unable to decode checksum parameter. UnsupportedEncodingException : " - + e.getMessage()); + log.error(e.getMessage(), e); ResponseBuilderImpl responseBuilder = new ResponseBuilderImpl(); responseBuilder.status(Response.Status.BAD_REQUEST); responseBuilder @@ -83,8 +80,8 @@ private static String decodeAndCheckChecksum(String checksum) if (checksum == null || checksum.trim().equals("")) { log - .error("Unable to evaluate permissions. Some parameters are missing : checksum " - + checksumDecoded); + .error("Unable to evaluate permissions. Some parameters are missing : checksum {}" + , checksumDecoded); ResponseBuilderImpl responseBuilder = new ResponseBuilderImpl(); responseBuilder.status(Response.Status.BAD_REQUEST); responseBuilder diff --git a/src/main/java/it/grid/storm/ea/remote/resource/StormEAResource.java b/src/main/java/it/grid/storm/ea/remote/resource/StormEAResource.java index ef86e271..9b3f1dde 100644 --- a/src/main/java/it/grid/storm/ea/remote/resource/StormEAResource.java +++ b/src/main/java/it/grid/storm/ea/remote/resource/StormEAResource.java @@ -50,22 +50,23 @@ public String getAdler32Checksum(@PathParam("filePath") String filePath) RequestParameters parameters = new RequestParameters.Builder(filePath) .build(); - log.info("Getting " + Constants.ADLER_32 + " checksum for file " - + parameters.getFilePathDecoded()); + log.info("Getting {} checksum for file {}", + Constants.ADLER_32, + parameters.getFilePathDecoded()); + String checksum; try { checksum = StormEA.getChecksum(parameters.getFilePathDecoded(), Constants.ADLER_32); } catch (ExtendedAttributesException e) { - log.error("Unable to get file checksum. ExtendedAttributesException: " - + e.getMessage()); + log.error(e.getMessage(), e); ResponseBuilderImpl responseBuilder = new ResponseBuilderImpl(); responseBuilder.status(Response.Status.INTERNAL_SERVER_ERROR); responseBuilder .entity("Unable to get the checksum, Extended attributes management failure"); throw new WebApplicationException(responseBuilder.build()); } - log.info("Retrieved checksum is " + checksum); + log.info("Checksum for file {} is {}", filePath, checksum); return checksum; } @@ -78,15 +79,17 @@ public void setAdler32Checksum(@PathParam("filePath") String filePath, RequestParameters parameters = new RequestParameters.Builder(filePath) .checksum(checksum).build(); - log.info("Setting " + Constants.ADLER_32 + " \'" - + parameters.getChecksumDecoded() + "\' checksum for file " - + parameters.getFilePathDecoded()); + + log.info("Setting {} checksum for file {} with value {}", + Constants.ADLER_32, + parameters.getFilePathDecoded(), + parameters.getChecksumDecoded()); + try { StormEA.setChecksum(parameters.getFilePathDecoded(), parameters.getChecksumDecoded(), Constants.ADLER_32); } catch (ExtendedAttributesException e) { - log.error("Unable to set file checksum. ExtendedAttributesException: " - + e.getMessage()); + log.error(e.getMessage(), e); ResponseBuilderImpl responseBuilder = new ResponseBuilderImpl(); responseBuilder.status(Response.Status.INTERNAL_SERVER_ERROR); responseBuilder @@ -94,5 +97,4 @@ public void setAdler32Checksum(@PathParam("filePath") String filePath, throw new WebApplicationException(responseBuilder.build()); } } - } \ No newline at end of file From 7edcbea6caa9ae66d0067bb424ecd90d2de9946e Mon Sep 17 00:00:00 2001 From: enricovianello Date: Fri, 7 Feb 2014 09:35:23 +0100 Subject: [PATCH 33/45] Fix log calls in storm backend - package it.grid.storm.check --- .../it/grid/storm/check/CheckManager.java | 20 ++- .../grid/storm/check/SimpleCheckManager.java | 4 +- .../check/SimpleClassLoaderCheckManager.java | 14 +- .../NamespaceFSAssociationCheck.java | 52 ++++---- .../NamespaceFSExtendedACLUsageCheck.java | 115 ++++++++--------- ...ceFSExtendedAttributeDeclarationCheck.java | 120 +++++++++--------- ...amespaceFSExtendedAttributeUsageCheck.java | 81 ++++++------ 7 files changed, 190 insertions(+), 216 deletions(-) diff --git a/src/main/java/it/grid/storm/check/CheckManager.java b/src/main/java/it/grid/storm/check/CheckManager.java index 4a49b8bd..93998cbd 100644 --- a/src/main/java/it/grid/storm/check/CheckManager.java +++ b/src/main/java/it/grid/storm/check/CheckManager.java @@ -64,22 +64,20 @@ public CheckResponse lauchChecks() { getLogger().debug("Executing check schedule"); CheckResponse result = new CheckResponse(CheckStatus.SUCCESS, ""); for (Check check : checkSchedule) { - getLogger().info("Executing check : " + check.getName()); - getLogger().info("Check description : " + check.getDescription()); + getLogger().info("Executing check : {}", check.getName()); + getLogger().info("Check description : {}", check.getDescription()); CheckResponse response; try { response = check.execute(); } catch (GenericCheckException e) { - getLogger().warn( - "Received a GenericCheckException during " + check.getName() - + " check execution : " + e.getMessage()); + getLogger().warn("Received a GenericCheckException during {} check " + + "execution : {}", check.getName(), e.getMessage()); response = new CheckResponse(CheckStatus.INDETERMINATE, "Received a GenericCheckException during " + check.getName() + " check execution : " + e.getMessage()); } - getLogger().info( - "Check \'" + check.getName() + "\' response is : " - + response.toString()); + getLogger().info("Check '{}' response is : {}", check.getName(), + response.toString()); if (!response.isSuccessfull() && check.isCritical()) { result.setStatus(CheckStatus.and(result.getStatus(), CheckStatus.CRITICAL_FAILURE)); @@ -87,10 +85,8 @@ public CheckResponse lauchChecks() { result.setStatus(CheckStatus.and(result.getStatus(), response.getStatus())); } - getLogger() - .debug( - "Partial result is " - + (result.isSuccessfull() ? "success" : "failure")); + getLogger().debug("Partial result is {}", + result.isSuccessfull() ? "success" : "failure"); } return result; } diff --git a/src/main/java/it/grid/storm/check/SimpleCheckManager.java b/src/main/java/it/grid/storm/check/SimpleCheckManager.java index 5e38c515..f1d5951d 100644 --- a/src/main/java/it/grid/storm/check/SimpleCheckManager.java +++ b/src/main/java/it/grid/storm/check/SimpleCheckManager.java @@ -52,8 +52,8 @@ protected void loadChecks() { try { checks.add(getNamespaceFSAssociationCheck()); } catch (IllegalStateException e) { - log.warn("Skipping NamespaceFSAssociationCheck. IllegalStateException: " - + e.getMessage()); + log.warn("Skipping NamespaceFSAssociationCheck. " + + "IllegalStateException: {}", e.getMessage()); } // checks.add(new NamespaceFSExtendedAttributeDeclarationCheck()); Removed checks.add(new NamespaceFSExtendedAttributeUsageCheck()); diff --git a/src/main/java/it/grid/storm/check/SimpleClassLoaderCheckManager.java b/src/main/java/it/grid/storm/check/SimpleClassLoaderCheckManager.java index f3b9db69..c9843a1e 100644 --- a/src/main/java/it/grid/storm/check/SimpleClassLoaderCheckManager.java +++ b/src/main/java/it/grid/storm/check/SimpleClassLoaderCheckManager.java @@ -48,7 +48,7 @@ protected void loadChecks() { URL location = null; if (source != null) { location = source.getLocation(); - log.info("location: " + location); + log.info("location: {}", location); } String packageResourcePath = "it" + File.separatorChar + "grid" + File.separatorChar + "storm" + File.separatorChar + "check" @@ -69,18 +69,18 @@ protected void loadChecks() { Check check = (Check) constructor.newInstance(); checks.add(check); } catch (IllegalArgumentException e) { - log.error(e.getMessage()); + log.error(e.getMessage(), e); } catch (InstantiationException e) { - log.error(e.getMessage()); + log.error(e.getMessage(), e); } catch (IllegalAccessException e) { - log.error(e.getMessage()); + log.error(e.getMessage(), e); } catch (InvocationTargetException e) { - log.error(e.getMessage()); + log.error(e.getMessage(), e); } } catch (SecurityException e1) { - log.error(e1.getMessage()); + log.error(e1.getMessage(), e1); } catch (NoSuchMethodException e1) { - log.error(e1.getMessage()); + log.error(e1.getMessage(), e1); } } } diff --git a/src/main/java/it/grid/storm/check/sanity/filesystem/NamespaceFSAssociationCheck.java b/src/main/java/it/grid/storm/check/sanity/filesystem/NamespaceFSAssociationCheck.java index 9927c6bd..30dfde7e 100644 --- a/src/main/java/it/grid/storm/check/sanity/filesystem/NamespaceFSAssociationCheck.java +++ b/src/main/java/it/grid/storm/check/sanity/filesystem/NamespaceFSAssociationCheck.java @@ -21,7 +21,6 @@ import it.grid.storm.check.Check; import it.grid.storm.check.CheckResponse; import it.grid.storm.check.CheckStatus; -import it.grid.storm.namespace.NamespaceException; import it.grid.storm.namespace.VirtualFSInterface; import it.grid.storm.namespace.naming.NamespaceUtil; @@ -59,21 +58,20 @@ public NamespaceFSAssociationCheck(Map mountPoints, this(); if (mountPoints == null || vfsSet == null) { - log - .error("Unable to create NamespaceFSAssociationCheck received null arguments: mountPoints=" - + mountPoints + " vfsSet=" + vfsSet); + log.error("Unable to create NamespaceFSAssociationCheck received null " + + "arguments: mountPoints={} vfsSet={}", mountPoints, vfsSet); throw new IllegalArgumentException( "Unable to create NamespaceFSAssociationCheck received null arguments"); } if (!verifyMountPoints(mountPoints)) { - log - .error("Unable to create NamespaceFSAssociationCheck received invalid mountPoints"); + log.error("Unable to create NamespaceFSAssociationCheck received " + + "invalid mountPoints"); throw new IllegalArgumentException( "Unable to create NamespaceFSAssociationCheck received invalid mountPoints"); } if (!verifyVfsSet(vfsSet)) { - log - .error("Unable to create NamespaceFSAssociationCheck received invalid vfsSet"); + log.error("Unable to create NamespaceFSAssociationCheck received " + + "invalid vfsSet"); throw new IllegalArgumentException( "Unable to create NamespaceFSAssociationCheck received invalid vfsSet"); } @@ -93,12 +91,12 @@ private boolean verifyVfsSet(Collection vfsSet) { return false; } if (vfs.getFSType() == null) { - log.info("The vfs " + vfs.getAliasName() + " has null FSType"); + log.info("The vfs {} has null FSType", vfs.getAliasName()); return false; } if (vfs.getRootPath() == null) { - log.info("The vfs " + vfs.getAliasName() + " has null rootPath"); + log.info("The vfs {} has null rootPath", vfs.getAliasName()); return false; } @@ -119,7 +117,7 @@ private boolean verifyMountPoints(Map mountPoints) { return false; } if (mountPoints.get(key) == null) { - log.info("The mountPoint key " + key + " points to a null value"); + log.info("The mountPoint key {} points to a null value", key); return false; } } @@ -147,16 +145,16 @@ public CheckResponse execute() throws GenericCheckException { mountPoints); } if (!currentResponse) { - log.error("Check on VFS " + vfs.getAliasName() + " failed. Type =" - + vfs.getFSType() + " , root path =" + vfs.getRootPath()); + log.error("Check on VFS {} failed. FSType={}, rootPath={}", + vfs.getAliasName(), vfs.getFSType(), vfs.getRootPath()); errorMessage += "Check on VFS " + vfs.getAliasName() + " failed. Type =" + vfs.getFSType() + " , root path =" + vfs.getRootPath(); } - log.debug("Check response for path " + vfs.getRootPath() + " is " - + (currentResponse ? "success" : "failure")); + log.debug("Check response for path {} is {}", vfs.getRootPath(), + currentResponse ? "success" : "failure"); status = CheckStatus.and(status, currentResponse); - log.debug("Partial result is " + status.toString()); + log.debug("Partial result is {}", status.toString()); } return new CheckResponse(status, errorMessage); @@ -170,9 +168,8 @@ private boolean verifyPosixDeclaredFS(String FSType) throws IllegalArgumentException { if (FSType == null) { - log - .error("Unable to check posix filesystem declaration received null argument: FSType= " - + FSType); + log.error("Unable to check posix filesystem declaration received null " + + "argument: FSType={}", FSType); throw new IllegalArgumentException( "Unable to check posix filesystem declaration received null argument"); } @@ -192,28 +189,27 @@ private boolean check(String fsRootPath, String fsType, Map mountPoints) { boolean response = false; - log.debug("Checking fs at " + fsRootPath + " as a " + fsType); + log.debug("Checking fs at {} as a {}", fsRootPath, fsType); String canonicalpath; try { canonicalpath = new File(fsRootPath).getCanonicalPath(); } catch (IOException e) { - log.error("unable to build the canonical path for root \'" + fsRootPath - + "\' . IOException : " + e.getMessage()); + log.error("unable to build the canonical path for root '{}'. " + + "IOException: {}", fsRootPath, e.getMessage()); return false; } String mountPointFSType = getMountPointFSTypeBestmatch(canonicalpath, mountPoints); if (mountPointFSType != null) { - log.debug("Found on a mountPoint of a \'" + mountPointFSType + "\' FS"); + log.debug("Found on a mountPoint of a '{}' FS", mountPointFSType); if (fsType.equals(mountPointFSType)) { response = true; } else { - log.warn("Mount point File System type " + mountPointFSType - + " differs from the declared " + fsType + ". Check failed"); + log.warn("Mount point File System type {} differs from the declared. " + + "Check failed", mountPointFSType, fsType); } } else { - log.warn("No file systems are mounted at path " + fsRootPath - + "! Check failed"); + log.warn("No file systems are mounted at path! Check failed", fsRootPath); } return response; } @@ -226,7 +222,7 @@ private boolean check(String fsRootPath, String fsType, private String getMountPointFSTypeBestmatch(String fsRootPath, Map mountPoints) { - log.debug("Retrieving mout point for path " + fsRootPath); + log.debug("Retrieving mout point for path {}", fsRootPath); String fsType = null; int minDistance = -1; int pathSize = conputePathSize(fsRootPath); diff --git a/src/main/java/it/grid/storm/check/sanity/filesystem/NamespaceFSExtendedACLUsageCheck.java b/src/main/java/it/grid/storm/check/sanity/filesystem/NamespaceFSExtendedACLUsageCheck.java index 38fc720c..f215bdc0 100644 --- a/src/main/java/it/grid/storm/check/sanity/filesystem/NamespaceFSExtendedACLUsageCheck.java +++ b/src/main/java/it/grid/storm/check/sanity/filesystem/NamespaceFSExtendedACLUsageCheck.java @@ -59,7 +59,7 @@ public CheckResponse execute() throws GenericCheckException { try { TEST_LOCAL_USER = TEST_USER.getLocalUser(); } catch (CannotMapUserException e) { - log.warn("Unable to obtain local user for test user " + TEST_USER); + log.warn("Unable to obtain local user for test user {}", TEST_USER); throw new GenericCheckException( "Unable to obtain local user for test user " + TEST_USER); } @@ -76,9 +76,8 @@ public CheckResponse execute() throws GenericCheckException { try { checkFile = provideCheckFile(fsRootPath, TEST_FILE_INFIX); } catch (GenericCheckException e) { - log - .warn("Unable to obtain a check temporary file. GenericCheckException : " - + e.getMessage()); + log.warn("Unable to obtain a check temporary file. " + + "GenericCheckException: {}", e.getMessage()); errorMessage += "Unable to obtain a check temporary file. GenericCheckException : " + e.getMessage() + "; "; status = CheckStatus.INDETERMINATE; @@ -88,27 +87,26 @@ public CheckResponse execute() throws GenericCheckException { // tries to manage the extended attributes on file checkFile boolean currentResponse = this.checkEACL(checkFile, filesystem); if (!currentResponse) { - log.error("Check on VFS " + vfs.getAliasName() - + " to add an extended ACL on file " + checkFile.getAbsolutePath() - + " failed. File System type =" + vfs.getFSType() - + " , root path =" + fsRootPath); + log.error("Check on VFS {} to add an extended ACL on file {} failed. " + + "File System type = {}, root path = {}", vfs.getAliasName(), + checkFile.getAbsolutePath(), vfs.getFSType(), fsRootPath); errorMessage += "Check on VFS " + vfs.getAliasName() + " to add an extended ACL on file " + checkFile.getAbsolutePath() + " failed. File System type =" + vfs.getFSType() + " , root path =" + fsRootPath + "; "; } - log.debug("Check response for path " + fsRootPath + " is " - + (currentResponse ? "success" : "failure")); + log.debug("Check response for path {} is {}", fsRootPath, + currentResponse ? "success" : "failure"); status = CheckStatus.and(status, currentResponse); - log.debug("Partial result is " + status.toString()); + log.debug("Partial result is {}", status.toString()); if (!checkFile.delete()) { - log.warn("Unable to delete the temporary file used for the check " - + checkFile.getAbsolutePath()); + log.warn("Unable to delete the temporary file used for the check {}", + checkFile.getAbsolutePath()); } } } catch (NamespaceException e) { // NOTE: this exception is never thrown - log.warn("Unable to proceede. NamespaceException : " + e.getMessage()); + log.warn("Unable to proceede. NamespaceException : {}", e.getMessage()); errorMessage += "Unable to proceede. NamespaceException : " + e.getMessage() + "; "; status = CheckStatus.INDETERMINATE; @@ -138,31 +136,29 @@ private File provideCheckFile(String rootPath, String infix) if (checkFile.exists()) { if (checkFile.isFile()) { fileAvailable = true; - log.debug("A good check temporary file already exists at " - + checkFile.getAbsolutePath()); + log.debug("A good check temporary file already exists at {}", + checkFile.getAbsolutePath()); } else { - log - .warn("Unable to create check file, it already exists but is not a simple file : " - + checkFile.getAbsolutePath()); + log.warn("Unable to create check file, it already exists but is not " + + "a simple file : {}", checkFile.getAbsolutePath()); } } else { try { fileAvailable = checkFile.createNewFile(); if (fileAvailable) { - log.debug("Created check temporary file at " - + checkFile.getAbsolutePath()); + log.debug("Created check temporary file at {}", + checkFile.getAbsolutePath()); } } catch (IOException e) { - log.warn("Unable to create the check file : " - + checkFile.getAbsolutePath() + ". IOException: " + e.getMessage()); + log.warn("Unable to create the check file : {}. IOException: {}", + checkFile.getAbsolutePath(), e.getMessage()); } } attempCount++; } if (!fileAvailable) { - log - .warn("Unable to create check file, reaced maximum iterations at path : " - + checkFile.getAbsolutePath()); + log.warn("Unable to create check file, reaced maximum iterations at " + + "path : {}", checkFile.getAbsolutePath()); throw new GenericCheckException( "Unable to create the check file for root path '" + rootPath + "'"); } @@ -181,8 +177,8 @@ private File provideCheckFile(String rootPath, String infix) private boolean checkEACL(File file, Filesystem filesystem) { boolean response = true; - log.debug("Testing extended attribute management on file " - + file.getAbsolutePath()); + log.debug("Testing extended attribute management on file {}", + file.getAbsolutePath()); FilesystemPermission oldPermisssion = filesystem.getGroupPermission( TEST_LOCAL_USER, file.getAbsolutePath()); @@ -190,33 +186,32 @@ private boolean checkEACL(File file, Filesystem filesystem) { oldPermisssion = FilesystemPermission.None; } FilesystemPermission testPermission = TEST_PERMISSION.deny(oldPermisssion); - log.debug("Trying to set the extended ACL " + testPermission + " to group " - + TEST_LOCAL_USER.getPrimaryGid() + " on file " + file.getAbsolutePath()); + log.debug("Trying to set the extended ACL {} to group {} on file {}", + testPermission, TEST_LOCAL_USER.getPrimaryGid(), file.getAbsolutePath()); filesystem.grantGroupPermission(TEST_LOCAL_USER, file.getAbsolutePath(), testPermission); - log.debug("Original group permission : " + oldPermisssion); - log.debug("Trying to get the extended ACL of group " - + TEST_LOCAL_USER.getPrimaryGid() + " from file " - + file.getAbsolutePath()); + log.debug("Original group permission : {}", oldPermisssion); + log.debug("Trying to get the extended ACL of group {} from file {}", + TEST_LOCAL_USER.getPrimaryGid(), file.getAbsolutePath()); FilesystemPermission currentPermission = filesystem.getGroupPermission( TEST_LOCAL_USER, file.getAbsolutePath()); if (currentPermission == null) { currentPermission = FilesystemPermission.None; } - log.debug("Returned value is \'" + currentPermission + "\'"); - log.debug("Trying to remove the extended group ACL " + testPermission - + " from file " + file.getAbsolutePath()); + log.debug("Returned value is '{}'", currentPermission); + log.debug("Trying to remove the extended group ACL {} from file {}", + testPermission, file.getAbsolutePath()); FilesystemPermission previousPermission = filesystem.revokeGroupPermission( TEST_LOCAL_USER, file.getAbsolutePath(), testPermission); if (previousPermission == null) { previousPermission = FilesystemPermission.None; } - log.debug("Revoked group permission is : " + previousPermission); + log.debug("Revoked group permission is : {}", previousPermission); if (currentPermission.getInt() != previousPermission.getInt()) { - log.warn("Undesired behaviour! The revoked extended group ACL value \'" - + previousPermission + "\' differs from the one setted \'" - + currentPermission + "\'"); + log.warn("Undesired behaviour! The revoked extended group ACL value '{}' " + + "differs from the one setted '{}'", previousPermission, + currentPermission); response &= false; } else { response &= true; @@ -226,11 +221,10 @@ private boolean checkEACL(File file, Filesystem filesystem) { if (currentPermission == null) { currentPermission = FilesystemPermission.None; } - log.debug("Final group permission is : " + currentPermission); + log.debug("Final group permission is : {}", currentPermission); if (currentPermission.getInt() != oldPermisssion.getInt()) { - log.warn("Undesired behaviour! The final extended group ACL value \'" - + currentPermission + "\' differs from the original \'" - + oldPermisssion + "\'"); + log.warn("Undesired behaviour! The final extended group ACL value '{}' " + + "differs from the original '{}'", currentPermission, oldPermisssion); response &= false; } else { response &= true; @@ -241,31 +235,31 @@ private boolean checkEACL(File file, Filesystem filesystem) { oldPermisssion = FilesystemPermission.None; } testPermission = TEST_PERMISSION.deny(oldPermisssion); - log.debug("Trying to set the extended ACL " + testPermission + " to user " - + TEST_LOCAL_USER.getUid() + " on file " + file.getAbsolutePath()); + log.debug("Trying to set the extended ACL {} to user {} on file {}", + testPermission, TEST_LOCAL_USER.getUid(), file.getAbsolutePath()); filesystem.grantUserPermission(TEST_LOCAL_USER, file.getAbsolutePath(), testPermission); - log.debug("Original user permission : " + oldPermisssion); - log.debug("Trying to get the extended ACL of user " - + TEST_LOCAL_USER.getUid() + " from file " + file.getAbsolutePath()); + log.debug("Original user permission : {}", oldPermisssion); + log.debug("Trying to get the extended ACL of user {} from file {}", + TEST_LOCAL_USER.getUid(), file.getAbsolutePath()); currentPermission = filesystem.getUserPermission(TEST_LOCAL_USER, file.getAbsolutePath()); if (currentPermission == null) { currentPermission = FilesystemPermission.None; } - log.debug("Returned value is \'" + currentPermission + "\'"); - log.debug("Trying to remove the extended user ACL " + testPermission - + " from file " + file.getAbsolutePath()); + log.debug("Returned value is '{}'", currentPermission); + log.debug("Trying to remove the extended user ACL {} from file {}", + testPermission, file.getAbsolutePath()); previousPermission = filesystem.revokeUserPermission(TEST_LOCAL_USER, file.getAbsolutePath(), testPermission); if (previousPermission == null) { previousPermission = FilesystemPermission.None; } - log.debug("Revoked user permission is : " + previousPermission); + log.debug("Revoked user permission is : {}", previousPermission); if (currentPermission.getInt() != previousPermission.getInt()) { - log.warn("Undesired behaviour! The removed extended user ACL value \'" - + previousPermission + "\' differs from the one setted \'" - + currentPermission + "\'"); + log.warn("Undesired behaviour! The removed extended user ACL value '{}' " + + "differs from the one setted '{}'", previousPermission, + currentPermission); response &= false; } else { response &= true; @@ -275,11 +269,10 @@ private boolean checkEACL(File file, Filesystem filesystem) { if (currentPermission == null) { currentPermission = FilesystemPermission.None; } - log.debug("Final user permission is : " + currentPermission); + log.debug("Final user permission is : {}", currentPermission); if (currentPermission.getInt() != oldPermisssion.getInt()) { - log.warn("Undesired behaviour! The final extended user ACL value \'" - + currentPermission + "\' differs from the original \'" - + oldPermisssion + "\'"); + log.warn("Undesired behaviour! The final extended user ACL value '{}' " + + "differs from the original '{}'", currentPermission, oldPermisssion); response &= false; } else { response &= true; diff --git a/src/main/java/it/grid/storm/check/sanity/filesystem/NamespaceFSExtendedAttributeDeclarationCheck.java b/src/main/java/it/grid/storm/check/sanity/filesystem/NamespaceFSExtendedAttributeDeclarationCheck.java index b9fa3af8..473e431f 100644 --- a/src/main/java/it/grid/storm/check/sanity/filesystem/NamespaceFSExtendedAttributeDeclarationCheck.java +++ b/src/main/java/it/grid/storm/check/sanity/filesystem/NamespaceFSExtendedAttributeDeclarationCheck.java @@ -51,13 +51,13 @@ public CheckResponse execute() throws GenericCheckException { try { rows = MtabUtil.getRows(); } catch (IOException e) { - log.warn("Unable to get the rows from mtab. IOException : " - + e.getMessage()); + log.warn("Unable to get the rows from mtab. IOException : {}", + e.getMessage()); return new CheckResponse(CheckStatus.INDETERMINATE, "Check not performed. Unable to get the rows from mtab. IOException : " + e.getMessage()); } - log.debug("Retrieved Mtab : " + rows.toString()); + log.debug("Retrieved Mtab : {}", rows.toString()); try { // load declared file systems from namespace.xml for (VirtualFSInterface vfs : NamespaceDirector.getNamespace() @@ -65,75 +65,69 @@ public CheckResponse execute() throws GenericCheckException { String fsTypeName = vfs.getFSType(); String fsRootPath = vfs.getRootPath(); if (fsTypeName == null || fsRootPath == null) { - log.warn("Skipping chek on VFS with alias \'" + vfs.getAliasName() - + "\' has null type ->" + vfs.getFSType() + "<- or root path ->" - + vfs.getRootPath() + "<-"); - } else { - log - .debug("Checking fs at " + fsRootPath + " with type " + fsTypeName); - boolean found = false; - // for each root path get the matching line in mstab - for (MtabRow row : rows) { - if (fsRootPath.startsWith(row.getMountPoint())) { - log.debug("Found on mountPoint " + row.getMountPoint()); - // this is the row to check - found = true; - SupportedFSType fsType; - try { - fsType = SupportedFSType.parseFS(fsTypeName); - } catch (IllegalArgumentException e) { - log.warn("Unable to get the SupportedFSType for file system \'" - + fsTypeName + "\' IllegalArgumentException : " - + e.getMessage()); - throw new GenericCheckException( - "Unable to get the SupportedFSType for file system \'" - + fsTypeName + "\' IllegalArgumentException : " - + e.getMessage()); - } + log.warn("Skipping chek on VFS with alias '{}' has null type ->{}<- " + + "or root path ->{}<-", vfs.getAliasName(), vfs.getFSType(), + vfs.getRootPath()); + continue; + } + log.debug("Checking fs at {} with type {}", fsRootPath, fsTypeName); + boolean found = false; + // for each root path get the matching line in mstab + for (MtabRow row : rows) { + if (fsRootPath.startsWith(row.getMountPoint())) { + log.debug("Found on mountPoint {}", row.getMountPoint()); + // this is the row to check + found = true; + SupportedFSType fsType; + try { + fsType = SupportedFSType.parseFS(fsTypeName); + } catch (IllegalArgumentException e) { + log.warn( + "Unable to get the SupportedFSType for file system '{}'. " + + "IllegalArgumentException: {}", fsTypeName, e.getMessage()); + throw new GenericCheckException("Unable to get the " + + "SupportedFSType for file system \'" + fsTypeName + + "\' IllegalArgumentException: " + e.getMessage()); + } - // given the file system specified in the row check if the - // appropriate flag - // enabling EA is set - CheckStatus retrievedStatus; - switch (fsType) { + // given the file system specified in the row check if the + // appropriate flag enabling EA is set + CheckStatus retrievedStatus; + switch (fsType) { case EXT3: retrievedStatus = checkEXT3(row.getMountOptions()); - break; + break; case GPFS: retrievedStatus = checkGPFS(row.getMountOptions()); - break; + break; default: { - log - .error("Unable to switch on the provided SupportedFSType (unknown) : " - + fsType); - throw new GenericCheckException( - "Unable to switch on the provided SupportedFSType (unknown) : " - + fsType); - } + log.error("Unable to switch on the provided SupportedFSType " + + "(unknown): {}", fsType); + throw new GenericCheckException("Unable to switch on the " + + "provided SupportedFSType (unknown) : " + fsType); } - if (!retrievedStatus.equals(CheckStatus.SUCCESS)) { - log.error("Check failed for file system at " + fsRootPath - + " with type " + fsType); - errorMessage += "Check failed for file system at " + fsRootPath - + " with type " + fsType + "; "; - } - status = CheckStatus.and(status, retrievedStatus); - break; } + if (!retrievedStatus.equals(CheckStatus.SUCCESS)) { + log.error("Check failed for file system at {} with type {}", + fsRootPath, fsType); + errorMessage += "Check failed for file system at " + fsRootPath + + " with type " + fsType + "; "; + } + status = CheckStatus.and(status, retrievedStatus); + break; } - if (!found) { - log - .error("No file systems are mounted at path " + fsRootPath + "!"); - errorMessage += "No file systems are mounted at path " + fsRootPath - + "; "; - status = CheckStatus.INDETERMINATE; - } + } + if (!found) { + log.error("No file systems are mounted at path {}!", fsRootPath); + errorMessage += "No file systems are mounted at path " + fsRootPath + + ";"; + status = CheckStatus.INDETERMINATE; } } } catch (NamespaceException e) { // NOTE: this exception is never thrown - log.warn("Unable to proceede received a NamespaceException : " - + e.getMessage()); + log.warn("Unable to proceede received a NamespaceException: {}", + e.getMessage()); errorMessage += "Unable to proceede received a NamespaceException : " + e.getMessage() + "; "; status = CheckStatus.INDETERMINATE; @@ -151,8 +145,8 @@ public CheckResponse execute() throws GenericCheckException { */ private CheckStatus checkEXT3(List fsOptions) { - log.debug("Checking ext3 file system estended attribute options against \'" - + fsOptions.toString() + "\'"); + log.debug("Checking ext3 file system estended attribute options " + + "against '{}'", fsOptions.toString()); CheckStatus response = CheckStatus.FAILURE; if (fsOptions.contains(POSIX_EXTENDED_ATTRIBUTES_OPTION_NAME)) { log.debug("Options for ext3 correctly set"); @@ -170,8 +164,8 @@ private CheckStatus checkEXT3(List fsOptions) { */ private CheckStatus checkGPFS(List fsOptions) { - log.debug("Checking gpfs file system estended attribute options against \'" - + fsOptions.toString() + "\'"); + log.debug("Checking gpfs file system estended attribute options " + + "against '{}'", fsOptions.toString()); /* * According to Vladimir for GPFS the EA are enabled by default and their * status doesn't have any info in mtab diff --git a/src/main/java/it/grid/storm/check/sanity/filesystem/NamespaceFSExtendedAttributeUsageCheck.java b/src/main/java/it/grid/storm/check/sanity/filesystem/NamespaceFSExtendedAttributeUsageCheck.java index b513c428..a7c6c4f8 100644 --- a/src/main/java/it/grid/storm/check/sanity/filesystem/NamespaceFSExtendedAttributeUsageCheck.java +++ b/src/main/java/it/grid/storm/check/sanity/filesystem/NamespaceFSExtendedAttributeUsageCheck.java @@ -82,37 +82,36 @@ public CheckResponse execute() throws GenericCheckException { try { checkFile = provideCheckFile(fsRootPath, TEST_FILE_INFIX); } catch (GenericCheckException e) { - log - .warn("Unable to obtain a check temporary file. GenericCheckException : " - + e.getMessage()); - errorMessage += "Unable to obtain a check temporary file. GenericCheckException : " - + e.getMessage() + "; "; + log.warn("Unable to obtain a check temporary file. " + + "GenericCheckException: {}", e.getMessage()); + errorMessage += "Unable to obtain a check temporary file. " + + "GenericCheckException : " + e.getMessage() + "; "; status = CheckStatus.INDETERMINATE; continue; } // tries to manage the extended attributes on file checkFile boolean currentResponse = this.checkEA(checkFile); if (!currentResponse) { - log.warn("Check on VFS " + vfs.getAliasName() + " to add EA on file " - + checkFile.getAbsolutePath() + " failed. File System type =" - + vfs.getFSType() + " , root path =" + fsRootPath); + log.warn("Check on VFS {} to add EA on file {} failed. File System " + + "type = {}, root path = {}", vfs.getAliasName(), + checkFile.getAbsolutePath(), vfs.getFSType(), fsRootPath); errorMessage += "Check on VFS " + vfs.getAliasName() + " to add EA on file " + checkFile.getAbsolutePath() + " failed. File System type =" + vfs.getFSType() + " , root path =" + fsRootPath + "; "; } - log.debug("Check response for path " + fsRootPath + " is " - + (currentResponse ? "success" : "failure")); + log.debug("Check response for path {} is {}", fsRootPath, + currentResponse ? "success" : "failure"); status = CheckStatus.and(status, currentResponse); - log.debug("Partial result is " + status.toString()); + log.debug("Partial result is {}", status.toString()); if (!checkFile.delete()) { - log.warn("Unable to delete the temporary file used for the check " - + checkFile.getAbsolutePath()); + log.warn("Unable to delete the temporary file used for the check {}", + checkFile.getAbsolutePath()); } } } catch (NamespaceException e) { // NOTE: this exception is never thrown - log.warn("Unable to proceede. NamespaceException : " + e.getMessage()); + log.warn("Unable to proceede. NamespaceException: {}", e.getMessage()); errorMessage += "Unable to proceede. NamespaceException : " + e.getMessage() + "; "; status = CheckStatus.INDETERMINATE; @@ -143,31 +142,29 @@ private File provideCheckFile(String rootPath, String infix) if (checkFile.exists()) { if (checkFile.isFile()) { fileAvailable = true; - log.debug("A good check temporary file already exists at " - + checkFile.getAbsolutePath()); + log.debug("A good check temporary file already exists at {}", + checkFile.getAbsolutePath()); } else { - log - .warn("Unable to create check file, it already exists but is not a simple file : " - + checkFile.getAbsolutePath()); + log.warn("Unable to create check file, it already exists but is not " + + "a simple file: {}", checkFile.getAbsolutePath()); } } else { try { fileAvailable = checkFile.createNewFile(); if (fileAvailable) { - log.debug("Created check temporary file at " - + checkFile.getAbsolutePath()); + log.debug("Created check temporary file at {}", + checkFile.getAbsolutePath()); } } catch (IOException e) { - log.warn("Unable to create the check file : " - + checkFile.getAbsolutePath() + ". IOException: " + e.getMessage()); + log.warn("Unable to create the check file: {}. IOException: {}", + checkFile.getAbsolutePath(), e.getMessage()); } } attempCount++; } if (!fileAvailable) { - log - .warn("Unable to create check file, reaced maximum iterations at path : " - + checkFile.getAbsolutePath()); + log.warn("Unable to create check file, reaced maximum iterations at " + + "path: {}", checkFile.getAbsolutePath()); throw new GenericCheckException( "Unable to create the check file for root path '" + rootPath + "'"); } @@ -185,36 +182,34 @@ private File provideCheckFile(String rootPath, String infix) private boolean checkEA(File file) { boolean response = false; - log.debug("Testing extended attribute management on file " - + file.getAbsolutePath()); + log.debug("Testing extended attribute management on file {}", + file.getAbsolutePath()); try { - log.debug("Trying to set the extended attribute " + CHECK_ATTRIBUTE_NAME - + " to value " + CHECK_ATTRIBUTE_VALUE + " on file " - + file.getAbsolutePath()); + log.debug("Trying to set the extended attribute {} to value {} on file ", + CHECK_ATTRIBUTE_NAME, CHECK_ATTRIBUTE_VALUE, file.getAbsolutePath()); extendedAttribute.setXAttr(file.getAbsolutePath(), CHECK_ATTRIBUTE_NAME, CHECK_ATTRIBUTE_VALUE); - log.debug("Trying to get the extended attribute " + CHECK_ATTRIBUTE_NAME - + " from file " + file.getAbsolutePath()); + log.debug("Trying to get the extended attribute {} from file {}", + CHECK_ATTRIBUTE_NAME, file.getAbsolutePath()); String value = new String(extendedAttribute.getXAttr( file.getAbsolutePath(), CHECK_ATTRIBUTE_NAME)); - log.debug("Returned value is \'" + value + "\'"); - log.debug("Trying to remove the extended attribute " - + CHECK_ATTRIBUTE_NAME + " from file " + file.getAbsolutePath()); + log.debug("Returned value is '{}'", value); + log.debug("Trying to remove the extended attribute {} from file {}", + CHECK_ATTRIBUTE_NAME, file.getAbsolutePath()); extendedAttribute.rmXAttr(file.getAbsolutePath(), CHECK_ATTRIBUTE_NAME); if (!CHECK_ATTRIBUTE_VALUE.equals(value)) { - log - .warn("Undesired behaviour! The returned extended attribute value \'" - + value + "\' differs from the one setted \'" - + CHECK_ATTRIBUTE_VALUE + "\'"); + log.warn("Undesired behaviour! The returned extended attribute " + + "value '{}' differs from the one setted '{}'", value, + CHECK_ATTRIBUTE_VALUE); } else { response = true; } } catch (ExtendedAttributesException e) { - log.warn("Unable to manage extended attributes on file " - + file.getAbsolutePath() + " ExtendedAttributesException : " - + e.getMessage()); + log.warn("Unable to manage extended attributes on file {}. " + + "ExtendedAttributesException: {}", file.getAbsolutePath(), + e.getMessage()); } return response; From 472d68bf3ca6d6f3ddfdfde71f4a3a04754e0357 Mon Sep 17 00:00:00 2001 From: enricovianello Date: Fri, 7 Feb 2014 15:20:14 +0100 Subject: [PATCH 34/45] Little adjustments --- src/main/java/it/grid/storm/StoRM.java | 5 +- .../it/grid/storm/StoRMCommandServer.java | 63 ++++++++----------- .../it/grid/storm/asynch/AdvancedPicker.java | 4 +- src/main/java/it/grid/storm/asynch/BoL.java | 27 ++++---- .../it/grid/storm/authz/path/PathAuthz.java | 2 +- 5 files changed, 47 insertions(+), 54 deletions(-) diff --git a/src/main/java/it/grid/storm/StoRM.java b/src/main/java/it/grid/storm/StoRM.java index 281d7bec..c76e1f9f 100644 --- a/src/main/java/it/grid/storm/StoRM.java +++ b/src/main/java/it/grid/storm/StoRM.java @@ -300,9 +300,8 @@ synchronized public void stopRestServer() { } catch (Exception e) { - String emsg = String.format("Unable to stop internal HTTP Server " - + "listening for RESTFul services: %s", e.getMessage()); - log.error(emsg, e); + log.error("Unable to stop internal HTTP Server listening for RESTFul " + + "services: {}", e.getMessage(), e); } this.isRestServerRunning = false; diff --git a/src/main/java/it/grid/storm/StoRMCommandServer.java b/src/main/java/it/grid/storm/StoRMCommandServer.java index 03f7f910..c936627a 100644 --- a/src/main/java/it/grid/storm/StoRMCommandServer.java +++ b/src/main/java/it/grid/storm/StoRMCommandServer.java @@ -144,9 +144,8 @@ private void startCommandServer() { } catch (IOException e) { - String emsg = String.format("Could not bind to port %d: %s", - listeningPort, e.getMessage()); - log.error(emsg, e); + log.error("Could not bind to port {}: {}", listeningPort, + e.getMessage(), e); System.exit(1); } @@ -164,10 +163,8 @@ public void run() { } } catch (IOException e) { - String emsg = String.format( - "UNEXPECTED ERROR! Something went wrong with server.accept(): %s", - e.getMessage()); - log.error(emsg, e); + log.error("UNEXPECTED ERROR! Something went wrong with " + + "server.accept(): {}", e.getMessage(), e); System.exit(1); } @@ -205,9 +202,9 @@ public void run() { // input stream from client in = new BufferedReader(new InputStreamReader(socket.getInputStream())); } catch (IOException e) { - log - .error("UNEXPECTED ERROR! Unable to get a reader for the client socket. IOException : " - + e.getMessage(), e); + + log.error("UNEXPECTED ERROR! Unable to get a reader for the client " + + "socket. IOException: {}", e.getMessage(), e); return; } BufferedWriter out; @@ -215,9 +212,9 @@ public void run() { // output stream to the client out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); } catch (IOException e) { - log - .error("UNEXPECTED ERROR! Unable to get a writer for the client socket. IOException : " - + e.getMessage(), e); + + log.error("UNEXPECTED ERROR! Unable to get a writer for the client " + + "socket. IOException: {}", e.getMessage(), e); return; } String response = REQUEST_FAILURE_RESPONSE; @@ -226,9 +223,9 @@ public void run() { try { inputLine = in.readLine(); } catch (IOException e) { - log - .error("UNEXPECTED ERROR! Unable to read from the client socket. IOException : " - + e.getMessage(),e); + + log.error("UNEXPECTED ERROR! Unable to read from the client socket. " + + "IOException: {}", e.getMessage(), e); return; } if (inputLine != null) { @@ -312,9 +309,8 @@ public void run() { inputLine = in.readLine(); } catch (IOException e) { - String emsg = String.format("UNEXPECTED ERROR! Unable to read from " - + "the client socket. IOException : %s", e.getMessage()); - log.error(emsg, e); + log.error("UNEXPECTED ERROR! Unable to read from the client socket. " + + "IOException : {}", e.getMessage(), e); return; } } while (inputLine != null && acceptCommands); @@ -337,9 +333,8 @@ private boolean startServices() { } } catch (Exception e) { - String emsg = String.format("Unable to start the xmlrpc server. " - + "Exception: %s", e.getMessage()); - log.error(emsg, e); + log.error("Unable to start the xmlrpc server. Exception: {}", + e.getMessage(), e); stopServices(); return false; @@ -350,9 +345,8 @@ private boolean startServices() { } } catch (Exception e) { - String emsg = String.format("Unable to start the Rest server. " - + "Exception: %s", e.getMessage()); - log.error(emsg, e); + log.error("Unable to start the Rest server. Exception: {}", + e.getMessage(), e); stopServices(); return false; @@ -394,9 +388,8 @@ private void sendOutputAndClose(String response, BufferedWriter out, out.newLine(); } catch (IOException e) { - String emsg = String.format("UNEXPECTED ERROR! Unable to write on " - + "the client socket. IOException : %s", e.getMessage()); - log.error(emsg, e); + log.error("UNEXPECTED ERROR! Unable to write on the client socket. " + + "IOException : {}", e.getMessage(), e); } try { @@ -404,9 +397,8 @@ private void sendOutputAndClose(String response, BufferedWriter out, in.close(); } catch (IOException e) { - String emsg = String.format("UNEXPECTED ERROR! Unable to close client " - + "socket streams. IOException : %s", e.getMessage()); - log.error(emsg, e); + log.error("UNEXPECTED ERROR! Unable to close client socket streams. " + + "IOException : {}", e.getMessage(), e); } } finally { @@ -414,9 +406,8 @@ private void sendOutputAndClose(String response, BufferedWriter out, socket.close(); } catch (IOException e) { - String emsg = String.format("UNEXPECTED ERROR! Unable to close client " - + "socket. IOException : %s", e.getMessage()); - log.error(emsg, e); + log.error("UNEXPECTED ERROR! Unable to close client socket. " + + "IOException : {}", e.getMessage(), e); } } @@ -475,13 +466,11 @@ private boolean servicesStopped() { private boolean servicesStarting() { - // TODO Auto-generated method stub return false; } private boolean servicesStopping() { - // TODO Auto-generated method stub return false; } } @@ -532,7 +521,7 @@ public static void main(String[] args) { } catch (NumberFormatException e) { log.error("Configuration file refresh rate: NOT an integer! " - + "Disabling refresh by default!", e); + + "Disabling refresh by default! {}", e.getMessage(), e); } } else { diff --git a/src/main/java/it/grid/storm/asynch/AdvancedPicker.java b/src/main/java/it/grid/storm/asynch/AdvancedPicker.java index 884727f3..c0b723ff 100644 --- a/src/main/java/it/grid/storm/asynch/AdvancedPicker.java +++ b/src/main/java/it/grid/storm/asynch/AdvancedPicker.java @@ -207,8 +207,8 @@ public void retrieve() { } else { - log.warn("ADVANCED PICKER received request {} of type which is NOT " - + "currently supported. Dropping request... ", rt, rtype); + log.warn("ADVANCED PICKER received request {} of type {} which is " + + "NOT currently supported. Dropping request... ", rt, rtype); log.warn("ADVANCED PICKER: Beware that the global status of " + "request {} will transit to SRM_FAILURE, but each chunk in the " diff --git a/src/main/java/it/grid/storm/asynch/BoL.java b/src/main/java/it/grid/storm/asynch/BoL.java index d6a3d141..1b5dda60 100644 --- a/src/main/java/it/grid/storm/asynch/BoL.java +++ b/src/main/java/it/grid/storm/asynch/BoL.java @@ -165,17 +165,22 @@ public void choose(Streets s) { public Boolean completeRequest(TapeRecallStatus recallStatus) { if (TapeRecallStatus.ABORTED.equals(recallStatus)) { + log.debug("Recalling file {} from tape aborted", + bupLocalFile.getAbsolutePath()); requestData.changeStatusSRM_ABORTED("Recalling file from tape aborted"); return false; } if (!TapeRecallStatus.SUCCESS.equals(recallStatus)) { + log.debug("Error recalling file {} from tape", + bupLocalFile.getAbsolutePath()); requestData.changeStatusSRM_FAILURE("Error recalling file from tape"); return false; } try { if (bupLocalFile.isOnDisk()) { + log.debug("File {} recalled from tape", bupLocalFile.getAbsolutePath()); requestData.changeStatusSRM_SUCCESS("File recalled from tape"); return true; } @@ -200,16 +205,16 @@ public void doIt() { TSURL surl = requestData.getSURL(); TRequestToken rToken = requestData.getRequestToken(); - String user = gu.getDn(); + String dn = gu.getDn(); - log.debug("Handling BoL chunk for user DN: {}; for SURL: {}", user, surl); + log.debug("Handling BoL chunk for user DN: {}; for SURL: {}", dn, surl); if (!verifySurlStatusTransition(surl, rToken)) { failure = true; log.info("Unable to perform the BOL request, surl busy"); requestData.changeStatusSRM_FILE_BUSY("Requested file is" + " busy (in an incompatible state with BOL)"); - printOutcome(user, surl, requestData.getStatus()); + printOutcome(dn, surl, requestData.getStatus()); return; } @@ -218,27 +223,27 @@ public void doIt() { fileStoRI = NamespaceDirector.getNamespace().resolveStoRIbySURL(surl, gu); } catch (IllegalArgumentException e) { log.error("Unable to build a stori for surl '{}' and user '{}'. " - + "IllegalArgumentException: {}", surl, user, e.getMessage(), e); + + "IllegalArgumentException: {}", surl, dn, e.getMessage(), e); requestData.changeStatusSRM_INTERNAL_ERROR(e.getMessage()); failure = true; } catch (UnapprochableSurlException e) { log.info("Unable to build a stori for surl '{}' and user '{}'. " - + "UnapprochableSurlException: {}", surl, user, e.getMessage()); + + "UnapprochableSurlException: {}", surl, dn, e.getMessage()); requestData.changeStatusSRM_AUTHORIZATION_FAILURE(e.getMessage()); failure = true; } catch (NamespaceException e) { log.error("Unable to build a stori for surl '{}' and user '{}'. " - + "NamespaceException: {}", surl, user, e.getMessage(), e); + + "NamespaceException: {}", surl, dn, e.getMessage(), e); requestData.changeStatusSRM_INTERNAL_ERROR(e.getMessage()); failure = true; } catch (InvalidSURLException e) { log.info("Unable to build a stori for surl '{}' and user '{}'. " - + "InvalidSURLException: {}", surl, user, e.getMessage()); + + "InvalidSURLException: {}", surl, dn, e.getMessage()); requestData.changeStatusSRM_INVALID_PATH(e.getMessage()); failure = true; } finally { if (failure) { - printOutcome(user, surl, requestData.getStatus()); + printOutcome(dn, surl, requestData.getStatus()); return; } } @@ -253,12 +258,12 @@ public void doIt() { log.debug(emsg); requestData.changeStatusSRM_AUTHORIZATION_FAILURE(emsg); failure = true; - printOutcome(user, surl, requestData.getStatus()); + printOutcome(dn, surl, requestData.getStatus()); return; } manageIsPermit(fileStoRI); - printOutcome(user, surl, requestData.getStatus()); + printOutcome(dn, surl, requestData.getStatus()); } @Override @@ -309,7 +314,7 @@ private void manageIsPermit(StoRI fileStoRI) { if ((!localFile.exists()) || (localFile.isDirectory())) { - String emsg = "The requested file either does not exist, or it is a directory!"; + String emsg = "The requested file either does not exist, or is a directory!"; requestData.changeStatusSRM_INVALID_PATH(emsg); failure = true; log.debug("BoLChunk: {}", emsg); diff --git a/src/main/java/it/grid/storm/authz/path/PathAuthz.java b/src/main/java/it/grid/storm/authz/path/PathAuthz.java index 0b7ef5da..20f6f06a 100644 --- a/src/main/java/it/grid/storm/authz/path/PathAuthz.java +++ b/src/main/java/it/grid/storm/authz/path/PathAuthz.java @@ -195,7 +195,7 @@ public AuthzDecision authorize(GridUserInterface guser, int localGroup = guser.getLocalUser().getPrimaryGid(); groupName = LocalGroups.getInstance().getGroupName(localGroup); } catch (CannotMapUserException e) { - log.error("Unable to retrieve the local group for ''", guser, e); + log.error("Unable to retrieve the local group for '{}'", guser, e); groupName = "unknown"; } From dd0049f149b5e59cdff744a799dc83804b892f7c Mon Sep 17 00:00:00 2001 From: Andrea Ceccanti Date: Wed, 12 Feb 2014 18:07:35 +0100 Subject: [PATCH 35/45] Fix for https://issues.infn.it/jira/browse/STOR-560 --- etc/storm.properties.template | 13 +---- src/main/java/it/grid/storm/asynch/PtG.java | 53 ++++++++++++++----- .../it/grid/storm/config/Configuration.java | 5 ++ 3 files changed, 47 insertions(+), 24 deletions(-) diff --git a/etc/storm.properties.template b/etc/storm.properties.template index 203b9859..a2a17862 100644 --- a/etc/storm.properties.template +++ b/etc/storm.properties.template @@ -249,14 +249,5 @@ purge.size=800 #Time after that the GC consider a _terminated_ request as garbage expired.request.time=86400 - -############################################# -############ PRIVATE PARAMETERS ############ -############################################# -# ========================================== -# -- READ ONLY Properties -# ========================================== -# -# READ ONLY key; please don't edit that value -storm.properties.version = $Revision$ -# +# Skip ACL setup for PtG requests +ptg.skip-acl-setup = false \ No newline at end of file diff --git a/src/main/java/it/grid/storm/asynch/PtG.java b/src/main/java/it/grid/storm/asynch/PtG.java index a202083d..f711f447 100644 --- a/src/main/java/it/grid/storm/asynch/PtG.java +++ b/src/main/java/it/grid/storm/asynch/PtG.java @@ -20,6 +20,7 @@ import it.grid.storm.catalogs.PtGData; import it.grid.storm.catalogs.VolatileAndJiTCatalog; import it.grid.storm.common.types.SizeUnit; +import it.grid.storm.config.Configuration; import it.grid.storm.ea.StormEA; import it.grid.storm.filesystem.FSException; import it.grid.storm.filesystem.FilesystemPermission; @@ -97,21 +98,29 @@ public class PtG implements Delegable, Chooser, Request, Suspendedable { private TTURL bupTURL; private boolean downgradedToAnonymous = false; + private boolean setupACLs = true; /** * Constructor requiring the GridUser, the RequestSummaryData and the * PtGChunkData about this chunk. If the supplied attributes are null, an * InvalidPtGChunkAttributesException is thrown. */ - public PtG(PtGData requestData) throws IllegalArgumentException { + public PtG(PtGData reqData) throws IllegalArgumentException { - if (requestData == null) { + if (reqData == null) { throw new IllegalArgumentException( "Unable to build the object, invalid arguments: requestData=" - + requestData); + + reqData); } - this.requestData = requestData; + + requestData = reqData; start = Calendar.getInstance(); + + if (Configuration.getInstance().getPTGSkipACLSetup()){ + setupACLs = false; + log.debug("Skipping ACL setup on PTG as requested by configuration."); + } + } /** @@ -523,14 +532,23 @@ private boolean managePermitTraverseStep(StoRI fileStoRI) throws CannotMapUserException { if (!downgradedToAnonymous && requestData instanceof IdentityInputData) { + + if (!setupACLs) + return verifyPath(fileStoRI); + return verifyPath(fileStoRI) && setParentsAcl(fileStoRI, ((IdentityInputData) requestData).getUser() .getLocalUser()); } + if (verifyPath(fileStoRI)) { - setHttpsServiceParentAcl(fileStoRI); + + if (setupACLs) + setHttpsServiceParentAcl(fileStoRI); + return true; } + return false; } @@ -591,17 +609,26 @@ private boolean managePermitReadFileStep(StoRI fileStoRI, TTURL turl) if (!downgradedToAnonymous && requestData instanceof IdentityInputData) { - if (managePermitReadFileStep(fileStoRI, fileStoRI.getLocalFile(), - ((IdentityInputData) requestData).getUser().getLocalUser(), turl)) { + if (setupACLs){ + + if (managePermitReadFileStep(fileStoRI, fileStoRI.getLocalFile(), + ((IdentityInputData) requestData).getUser().getLocalUser(), turl)) { - setDefaultAcl(fileStoRI, fileStoRI.getLocalFile()); - return true; - } - return false; + setDefaultAcl(fileStoRI, fileStoRI.getLocalFile()); + + return true; + } else { + // we had an error setting up the ACL on file + return false; + } + } + } + + if (setupACLs){ + setDefaultAcl(fileStoRI, fileStoRI.getLocalFile()); + setHttpsServiceAcl(fileStoRI.getLocalFile(), FilesystemPermission.Read); } - setDefaultAcl(fileStoRI, fileStoRI.getLocalFile()); - setHttpsServiceAcl(fileStoRI.getLocalFile(), FilesystemPermission.Read); return true; } diff --git a/src/main/java/it/grid/storm/config/Configuration.java b/src/main/java/it/grid/storm/config/Configuration.java index 7485e181..862ca576 100644 --- a/src/main/java/it/grid/storm/config/Configuration.java +++ b/src/main/java/it/grid/storm/config/Configuration.java @@ -166,6 +166,7 @@ public class Configuration { private static final String SANITY_CHECK_ENABLED_KEY = "sanity-check.enabled"; private static final String XMLRPC_SECURITY_ENABLED_KEY = "synchcall.xmlrpc.security.enabled"; private static final String XMLRPC_SECURITY_TOKEN_KEY = "synchcall.xmlrpc.security.token"; + private static final String PTG_SKIP_ACL_SETUP = "ptg.skip-acl-setup"; private Configuration() { @@ -2264,6 +2265,10 @@ public String getXmlRpcToken() { return cr.getConfiguration().getString(XMLRPC_SECURITY_TOKEN_KEY); } + public Boolean getPTGSkipACLSetup(){ + return cr.getConfiguration().getBoolean(PTG_SKIP_ACL_SETUP, false); + } + @Override public String toString() { From be6ae6d6ae7aa1729d8b795982b2977f3eeae584 Mon Sep 17 00:00:00 2001 From: Andrea Ceccanti Date: Wed, 12 Feb 2014 18:26:03 +0100 Subject: [PATCH 36/45] Removes wrong import statement Which broke StoRM jenkins build --- .../tape/recalltable/model/PutTapeRecallStatusLogic.java | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/main/java/it/grid/storm/tape/recalltable/model/PutTapeRecallStatusLogic.java b/src/main/java/it/grid/storm/tape/recalltable/model/PutTapeRecallStatusLogic.java index 81c27c77..0a53c92b 100644 --- a/src/main/java/it/grid/storm/tape/recalltable/model/PutTapeRecallStatusLogic.java +++ b/src/main/java/it/grid/storm/tape/recalltable/model/PutTapeRecallStatusLogic.java @@ -11,9 +11,6 @@ package it.grid.storm.tape.recalltable.model; -import java.util.Date; -import java.util.UUID; - import it.grid.storm.filesystem.FSException; import it.grid.storm.filesystem.LocalFile; import it.grid.storm.namespace.StoRI; @@ -22,10 +19,12 @@ import it.grid.storm.tape.recalltable.TapeRecallCatalog; import it.grid.storm.tape.recalltable.TapeRecallException; +import java.util.Date; +import java.util.UUID; + import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import org.apache.commons.httpclient.methods.GetMethod; import org.slf4j.Logger; import org.slf4j.LoggerFactory; From ae6f7e92aea47cd8b92ba08389115c0f0ee0268f Mon Sep 17 00:00:00 2001 From: enricovianello Date: Wed, 26 Mar 2014 11:23:17 +0100 Subject: [PATCH 37/45] fix for https://issues.infn.it/jira/browse/STOR-598 --- .../java/it/grid/storm/health/LogEvent.java | 48 ++++--------------- .../it/grid/storm/scheduler/ChunkTask.java | 5 +- .../it/grid/storm/xmlrpc/XMLRPCExecutor.java | 3 +- 3 files changed, 13 insertions(+), 43 deletions(-) diff --git a/src/main/java/it/grid/storm/health/LogEvent.java b/src/main/java/it/grid/storm/health/LogEvent.java index e25fb685..1c2eed2c 100644 --- a/src/main/java/it/grid/storm/health/LogEvent.java +++ b/src/main/java/it/grid/storm/health/LogEvent.java @@ -43,13 +43,14 @@ public class LogEvent implements Delayed { private boolean successResult = false; public LogEvent(OperationType opType, String userDN, String surl, - long startTime, long duration, String requestToken, boolean successResult) { + long startTime, long duration, String requestToken, boolean successResult, + TimeUnit durationUnit) { this.opType = opType; this.userDN = userDN; this.surl = surl; this.startTime = startTime; - this.duration = duration; + this.duration = TimeUnit.MILLISECONDS.convert(duration, durationUnit); this.requestToken = requestToken; Date date = new Date(startTime); SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss,SSS"); @@ -64,51 +65,18 @@ public LogEvent(OperationType opType, String userDN, String surl, } public LogEvent(OperationType opType, String userDN, long startTime, - long duration, boolean successResult) { - - this.opType = opType; - this.userDN = userDN; - // Empty SURL - this.surl = TSURL.makeEmpty().toString(); - this.startTime = startTime; - // Store the duration in MicroSeconds (10^-6 sec) - this.duration = TimeUnit.MICROSECONDS.convert(duration, - TimeUnit.NANOSECONDS); - this.requestToken = "SYNCH"; - Date date = new Date(startTime); - SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss,SSS"); - this.startTimeStr = formatter.format(date); - this.successResult = successResult; - - this.timeToLive = HealthDirector.timeToLiveLogEventInSec; - this.deathTime = System.currentTimeMillis() - + (timeToLive * LogEvent.THOUSAND); - this.birthTime = System.currentTimeMillis(); + long duration, boolean successResult, TimeUnit durationUnit) { + this(opType, userDN, TSURL.makeEmpty().toString(), startTime, duration, + "SYNCH", successResult, TimeUnit.NANOSECONDS); HealthDirector.LOGGER.debug("Event TTL (milliSec): {}", timeToLive); } public LogEvent(OperationType opType, String userDN, String surl, - long startTime, long duration, boolean successResult) { + long startTime, long duration, boolean successResult, TimeUnit durationUnit) { - this.opType = opType; - this.userDN = userDN; - this.surl = surl; - this.startTime = startTime; - // Store the duration in MicroSeconds (10^-6 sec) - this.duration = TimeUnit.MICROSECONDS.convert(duration, + this(opType, userDN, surl, startTime, duration, "SYNCH", successResult, TimeUnit.NANOSECONDS); - this.requestToken = "SYNCH"; - Date date = new Date(startTime); - SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss,SSS"); - this.startTimeStr = formatter.format(date); - this.successResult = successResult; - - this.timeToLive = HealthDirector.timeToLiveLogEventInSec; - this.deathTime = System.currentTimeMillis() - + (timeToLive * LogEvent.THOUSAND); - this.birthTime = System.currentTimeMillis(); - HealthDirector.LOGGER.debug("Event TTL (milliSec): {}", timeToLive); } diff --git a/src/main/java/it/grid/storm/scheduler/ChunkTask.java b/src/main/java/it/grid/storm/scheduler/ChunkTask.java index bbda32ca..8d257a4c 100644 --- a/src/main/java/it/grid/storm/scheduler/ChunkTask.java +++ b/src/main/java/it/grid/storm/scheduler/ChunkTask.java @@ -29,6 +29,7 @@ import it.grid.storm.health.OperationType; import java.util.ArrayList; +import java.util.concurrent.TimeUnit; /** *

@@ -151,11 +152,11 @@ public void logExecution() { if (todo instanceof RequestChunk) { event = new LogEvent(buildOperationType(), this.userDN, this.surl, this.getStartExecutionTime(), this.howlongInExecution(), - this.requestToken, this.successResult); + this.requestToken, this.successResult, TimeUnit.MILLISECONDS); } else { event = new LogEvent(buildOperationType(), this.userDN, this.surl, this.getStartExecutionTime(), this.howlongInExecution(), - this.successResult); + this.successResult, TimeUnit.MILLISECONDS); } for (int i = 0; i < bks.size(); i++) { bks.get(i).addLogEvent(event); diff --git a/src/main/java/it/grid/storm/xmlrpc/XMLRPCExecutor.java b/src/main/java/it/grid/storm/xmlrpc/XMLRPCExecutor.java index 0d3dcfa7..dc0ca307 100644 --- a/src/main/java/it/grid/storm/xmlrpc/XMLRPCExecutor.java +++ b/src/main/java/it/grid/storm/xmlrpc/XMLRPCExecutor.java @@ -32,6 +32,7 @@ import java.util.ArrayList; import java.util.Map; +import java.util.concurrent.TimeUnit; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -110,7 +111,7 @@ private void logExecution(it.grid.storm.health.OperationType opType, String dn, long startTime, long duration, boolean successResult) { LogEvent event = new LogEvent(opType, dn, startTime, duration, - successResult); + successResult, TimeUnit.NANOSECONDS); if (!(bookKeepers.isEmpty())) { log.debug("Found # {} bookeepers." , bookKeepers.size()); for (int i = 0; i < bookKeepers.size(); i++) { From 9d8f8bfdc956127efcdbb9682c0b0a91f00ccb16 Mon Sep 17 00:00:00 2001 From: enricovianello Date: Wed, 26 Mar 2014 11:49:12 +0100 Subject: [PATCH 38/45] Moved TimeUnit conversion out from LogEvent --- .../java/it/grid/storm/health/LogEvent.java | 19 ++++++++++--------- .../it/grid/storm/scheduler/ChunkTask.java | 4 ++-- .../it/grid/storm/xmlrpc/XMLRPCExecutor.java | 8 ++++---- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/main/java/it/grid/storm/health/LogEvent.java b/src/main/java/it/grid/storm/health/LogEvent.java index 1c2eed2c..d39651d6 100644 --- a/src/main/java/it/grid/storm/health/LogEvent.java +++ b/src/main/java/it/grid/storm/health/LogEvent.java @@ -43,14 +43,13 @@ public class LogEvent implements Delayed { private boolean successResult = false; public LogEvent(OperationType opType, String userDN, String surl, - long startTime, long duration, String requestToken, boolean successResult, - TimeUnit durationUnit) { + long startTime, long durationInMilliSec, String requestToken, boolean successResult) { this.opType = opType; this.userDN = userDN; this.surl = surl; this.startTime = startTime; - this.duration = TimeUnit.MILLISECONDS.convert(duration, durationUnit); + this.duration = durationInMilliSec; this.requestToken = requestToken; Date date = new Date(startTime); SimpleDateFormat formatter = new SimpleDateFormat("HH:mm:ss,SSS"); @@ -65,18 +64,17 @@ public LogEvent(OperationType opType, String userDN, String surl, } public LogEvent(OperationType opType, String userDN, long startTime, - long duration, boolean successResult, TimeUnit durationUnit) { + long durationInMilliSec, boolean successResult) { - this(opType, userDN, TSURL.makeEmpty().toString(), startTime, duration, - "SYNCH", successResult, TimeUnit.NANOSECONDS); + this(opType, userDN, TSURL.makeEmpty().toString(), startTime, durationInMilliSec, + "SYNCH", successResult); HealthDirector.LOGGER.debug("Event TTL (milliSec): {}", timeToLive); } public LogEvent(OperationType opType, String userDN, String surl, - long startTime, long duration, boolean successResult, TimeUnit durationUnit) { + long startTime, long durationInMilliSec, boolean successResult) { - this(opType, userDN, surl, startTime, duration, "SYNCH", successResult, - TimeUnit.NANOSECONDS); + this(opType, userDN, surl, startTime, durationInMilliSec, "SYNCH", successResult); HealthDirector.LOGGER.debug("Event TTL (milliSec): {}", timeToLive); } @@ -105,6 +103,9 @@ public String getStartTimeString() { return this.startTimeStr; } + /** + * @return duration in millisec + */ public long getDuration() { return this.duration; diff --git a/src/main/java/it/grid/storm/scheduler/ChunkTask.java b/src/main/java/it/grid/storm/scheduler/ChunkTask.java index 8d257a4c..f33b712b 100644 --- a/src/main/java/it/grid/storm/scheduler/ChunkTask.java +++ b/src/main/java/it/grid/storm/scheduler/ChunkTask.java @@ -152,11 +152,11 @@ public void logExecution() { if (todo instanceof RequestChunk) { event = new LogEvent(buildOperationType(), this.userDN, this.surl, this.getStartExecutionTime(), this.howlongInExecution(), - this.requestToken, this.successResult, TimeUnit.MILLISECONDS); + this.requestToken, this.successResult); } else { event = new LogEvent(buildOperationType(), this.userDN, this.surl, this.getStartExecutionTime(), this.howlongInExecution(), - this.successResult, TimeUnit.MILLISECONDS); + this.successResult); } for (int i = 0; i < bks.size(); i++) { bks.get(i).addLogEvent(event); diff --git a/src/main/java/it/grid/storm/xmlrpc/XMLRPCExecutor.java b/src/main/java/it/grid/storm/xmlrpc/XMLRPCExecutor.java index dc0ca307..58be3b7f 100644 --- a/src/main/java/it/grid/storm/xmlrpc/XMLRPCExecutor.java +++ b/src/main/java/it/grid/storm/xmlrpc/XMLRPCExecutor.java @@ -97,10 +97,10 @@ public Map execute(OperationType type, Map inputParam) duration = System.nanoTime() - duration; logExecution(convertOperationType(type), - DataHelper.getRequestor(inputData), startTime, duration, + DataHelper.getRequestor(inputData), startTime, + TimeUnit.MILLISECONDS.convert(duration, TimeUnit.NANOSECONDS), outputData.isSuccess()); - // TODO rewrite the display method - // log.debug("Output Map: " + ParameterDisplayHelper.display(outputParam)); + return outputParam; } @@ -111,7 +111,7 @@ private void logExecution(it.grid.storm.health.OperationType opType, String dn, long startTime, long duration, boolean successResult) { LogEvent event = new LogEvent(opType, dn, startTime, duration, - successResult, TimeUnit.NANOSECONDS); + successResult); if (!(bookKeepers.isEmpty())) { log.debug("Found # {} bookeepers." , bookKeepers.size()); for (int i = 0; i < bookKeepers.size(); i++) { From 27ec7093853765edd9cdbf2c9b943d09f1e895d8 Mon Sep 17 00:00:00 2001 From: enricovianello Date: Wed, 26 Mar 2014 11:50:40 +0100 Subject: [PATCH 39/45] Removed useless import --- src/main/java/it/grid/storm/scheduler/ChunkTask.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/it/grid/storm/scheduler/ChunkTask.java b/src/main/java/it/grid/storm/scheduler/ChunkTask.java index f33b712b..bbda32ca 100644 --- a/src/main/java/it/grid/storm/scheduler/ChunkTask.java +++ b/src/main/java/it/grid/storm/scheduler/ChunkTask.java @@ -29,7 +29,6 @@ import it.grid.storm.health.OperationType; import java.util.ArrayList; -import java.util.concurrent.TimeUnit; /** *

From 298364a9b0280e9c0a0b399c6ea4526f32ede8de Mon Sep 17 00:00:00 2001 From: enricovianello Date: Thu, 27 Mar 2014 08:48:20 +0100 Subject: [PATCH 40/45] Cosmetic fix --- src/main/java/it/grid/storm/xmlrpc/XMLRPCExecutor.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/it/grid/storm/xmlrpc/XMLRPCExecutor.java b/src/main/java/it/grid/storm/xmlrpc/XMLRPCExecutor.java index 58be3b7f..1db02546 100644 --- a/src/main/java/it/grid/storm/xmlrpc/XMLRPCExecutor.java +++ b/src/main/java/it/grid/storm/xmlrpc/XMLRPCExecutor.java @@ -98,7 +98,7 @@ public Map execute(OperationType type, Map inputParam) logExecution(convertOperationType(type), DataHelper.getRequestor(inputData), startTime, - TimeUnit.MILLISECONDS.convert(duration, TimeUnit.NANOSECONDS), + TimeUnit.NANOSECONDS.toMillis(duration), outputData.isSuccess()); return outputParam; From 3d0335d7d4b10a1aa8a4a8ebd0fb7b152132c1b3 Mon Sep 17 00:00:00 2001 From: enricovianello Date: Mon, 14 Apr 2014 16:03:53 +0200 Subject: [PATCH 41/45] fix for https://issues.infn.it/jira/browse/STOR-602 --- .../it/grid/storm/scheduler/ChunkTask.java | 8 ++++- .../PrepareToGetRequestCommand.java | 2 +- .../PrepareToPutRequestCommand.java | 7 ++-- .../datatransfer/PrepareToGetOutputData.java | 7 ++++ .../datatransfer/PrepareToPutOutputData.java | 36 +++++++++++++++++++ 5 files changed, 55 insertions(+), 5 deletions(-) create mode 100644 src/main/java/it/grid/storm/synchcall/data/datatransfer/PrepareToPutOutputData.java diff --git a/src/main/java/it/grid/storm/scheduler/ChunkTask.java b/src/main/java/it/grid/storm/scheduler/ChunkTask.java index bbda32ca..3f2cd718 100644 --- a/src/main/java/it/grid/storm/scheduler/ChunkTask.java +++ b/src/main/java/it/grid/storm/scheduler/ChunkTask.java @@ -117,10 +117,16 @@ public int compareTo(Object o) { @Override public void run() { + this.run(true); + } + + public void run(boolean logExecution) { + this.runEvent(); todo.doIt(); this.endEvent(); - this.logExecution(); + if (logExecution) + this.logExecution(); } protected void endEvent() { diff --git a/src/main/java/it/grid/storm/synchcall/command/datatransfer/PrepareToGetRequestCommand.java b/src/main/java/it/grid/storm/synchcall/command/datatransfer/PrepareToGetRequestCommand.java index 1e9bb621..8ab7f6e8 100644 --- a/src/main/java/it/grid/storm/synchcall/command/datatransfer/PrepareToGetRequestCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/datatransfer/PrepareToGetRequestCommand.java @@ -59,7 +59,7 @@ public OutputData execute(InputData inputData) throws CommandException { "Unable to build PtG request from the InputData"); } ChunkTask ptgTask = new ChunkTask(request); - ptgTask.run(); + ptgTask.run(false); try { return new PrepareToGetOutputData(request.getRequestData().getSURL(), request.getRequestData().getTransferURL(), request.getRequestData() diff --git a/src/main/java/it/grid/storm/synchcall/command/datatransfer/PrepareToPutRequestCommand.java b/src/main/java/it/grid/storm/synchcall/command/datatransfer/PrepareToPutRequestCommand.java index 4424cfaa..33a3a1ef 100644 --- a/src/main/java/it/grid/storm/synchcall/command/datatransfer/PrepareToPutRequestCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/datatransfer/PrepareToPutRequestCommand.java @@ -19,6 +19,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; + import it.grid.storm.asynch.BuilderException; import it.grid.storm.asynch.PtP; import it.grid.storm.asynch.PtPBuilder; @@ -27,7 +28,7 @@ import it.grid.storm.synchcall.data.InputData; import it.grid.storm.synchcall.data.OutputData; import it.grid.storm.synchcall.data.datatransfer.PrepareToPutInputData; -import it.grid.storm.synchcall.data.datatransfer.FileTransferOutputData; +import it.grid.storm.synchcall.data.datatransfer.PrepareToPutOutputData; /** * @author Michele Dibenedetto @@ -60,9 +61,9 @@ public OutputData execute(InputData inputData) "Unable to build PtP request from the InputData"); } ChunkTask ptpTask = new ChunkTask(request); - ptpTask.run(); + ptpTask.run(false); try { - return new FileTransferOutputData(request.getRequestData().getSURL(), + return new PrepareToPutOutputData(request.getRequestData().getSURL(), request.getRequestData().getTransferURL(), request.getRequestData() .getStatus(), request.getRequestData().getGeneratedRequestToken()); } catch (IllegalArgumentException e) { diff --git a/src/main/java/it/grid/storm/synchcall/data/datatransfer/PrepareToGetOutputData.java b/src/main/java/it/grid/storm/synchcall/data/datatransfer/PrepareToGetOutputData.java index 0b9be75a..d6faf3cc 100644 --- a/src/main/java/it/grid/storm/synchcall/data/datatransfer/PrepareToGetOutputData.java +++ b/src/main/java/it/grid/storm/synchcall/data/datatransfer/PrepareToGetOutputData.java @@ -16,6 +16,7 @@ import it.grid.storm.srm.types.TReturnStatus; import it.grid.storm.srm.types.TSURL; import it.grid.storm.srm.types.TSizeInBytes; +import it.grid.storm.srm.types.TStatusCode; import it.grid.storm.srm.types.TTURL; /** @@ -56,4 +57,10 @@ public TLifeTimeInSeconds getRemainingPinTime() { return remainingPinTime; } + + @Override + public boolean isSuccess() { + + return this.getStatus().getStatusCode().equals(TStatusCode.SRM_FILE_PINNED); + } } diff --git a/src/main/java/it/grid/storm/synchcall/data/datatransfer/PrepareToPutOutputData.java b/src/main/java/it/grid/storm/synchcall/data/datatransfer/PrepareToPutOutputData.java new file mode 100644 index 00000000..93e69243 --- /dev/null +++ b/src/main/java/it/grid/storm/synchcall/data/datatransfer/PrepareToPutOutputData.java @@ -0,0 +1,36 @@ +/* + * Copyright (c) Istituto Nazionale di Fisica Nucleare (INFN). 2006-2010. + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by + * applicable law or agreed to in writing, software distributed under the + * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS + * OF ANY KIND, either express or implied. See the License for the specific + * language governing permissions and limitations under the License. + */ + +package it.grid.storm.synchcall.data.datatransfer; + +import it.grid.storm.srm.types.TRequestToken; +import it.grid.storm.srm.types.TReturnStatus; +import it.grid.storm.srm.types.TSURL; +import it.grid.storm.srm.types.TStatusCode; +import it.grid.storm.srm.types.TTURL; + +/** + * @author Enrico Vianello + */ +public class PrepareToPutOutputData extends FileTransferOutputData { + + public PrepareToPutOutputData(TSURL surl, TTURL turl, TReturnStatus status, + TRequestToken requestToken) throws IllegalArgumentException { + + super(surl, turl, status, requestToken); + } + + @Override + public boolean isSuccess() { + + return this.getStatus().getStatusCode().equals(TStatusCode.SRM_SPACE_AVAILABLE); + } +} From f39a274059e198f9587fa9996b4c146c1c7ec3fc Mon Sep 17 00:00:00 2001 From: enricovianello Date: Mon, 14 Apr 2014 16:23:01 +0200 Subject: [PATCH 42/45] fix for https://issues.infn.it/jira/browse/STOR-602 - cleaner code --- .../it/grid/storm/scheduler/ChunkTask.java | 60 +++++-------------- .../PrepareToGetRequestCommand.java | 3 +- .../PrepareToPutRequestCommand.java | 3 +- 3 files changed, 18 insertions(+), 48 deletions(-) diff --git a/src/main/java/it/grid/storm/scheduler/ChunkTask.java b/src/main/java/it/grid/storm/scheduler/ChunkTask.java index 3f2cd718..17809c3b 100644 --- a/src/main/java/it/grid/storm/scheduler/ChunkTask.java +++ b/src/main/java/it/grid/storm/scheduler/ChunkTask.java @@ -62,6 +62,7 @@ public class ChunkTask extends Task { private final boolean isAsynchTask; private final boolean isChunkTask; + private boolean executionLogged = true; private boolean successResult = false; public ChunkTask(Delegable todo) { @@ -117,16 +118,11 @@ public int compareTo(Object o) { @Override public void run() { - this.run(true); - } - - public void run(boolean logExecution) { - - this.runEvent(); + runEvent(); todo.doIt(); - this.endEvent(); - if (logExecution) - this.logExecution(); + endEvent(); + if (isExecutionLogged()) + logExecution(); } protected void endEvent() { @@ -263,43 +259,15 @@ public boolean equals(Object obj) { return true; } - /** - * - * @param o - * Object - * @return boolean - */ - // @Override - // public boolean equals(Object obj) { - // if (obj==this) { - // return true; - // } - // if (!(obj instanceof ChunkTask)) { - // return false; - // } - // ChunkTask other = (ChunkTask) obj; - // if (!(other.chunkType.equals(this.chunkType))) { - // return false; - // } - // if (!(other.getName().equals(this.getName()))) { - // return false; - // } - // if (!(other.todo.equals(this.todo))) { - // return false; - // } else { - // return true; - // } - // } + public boolean isExecutionLogged() { + + return executionLogged; + } - // @Override - // public int hashCode() { - // int hash = 17; - // if (this.taskName.length()!=0) { - // hash = 37*hash + taskName.hashCode(); - // } - // hash = 37*hash + this.todo.hashCode(); - // hash = 37*hash + this.chunkType.hashCode(); - // return hash; - // } + + public void setExecutionLogged(boolean executionLogged) { + + this.executionLogged = executionLogged; + } } diff --git a/src/main/java/it/grid/storm/synchcall/command/datatransfer/PrepareToGetRequestCommand.java b/src/main/java/it/grid/storm/synchcall/command/datatransfer/PrepareToGetRequestCommand.java index 8ab7f6e8..2e36b7c1 100644 --- a/src/main/java/it/grid/storm/synchcall/command/datatransfer/PrepareToGetRequestCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/datatransfer/PrepareToGetRequestCommand.java @@ -59,7 +59,8 @@ public OutputData execute(InputData inputData) throws CommandException { "Unable to build PtG request from the InputData"); } ChunkTask ptgTask = new ChunkTask(request); - ptgTask.run(false); + ptgTask.setExecutionLogged(false); + ptgTask.run(); try { return new PrepareToGetOutputData(request.getRequestData().getSURL(), request.getRequestData().getTransferURL(), request.getRequestData() diff --git a/src/main/java/it/grid/storm/synchcall/command/datatransfer/PrepareToPutRequestCommand.java b/src/main/java/it/grid/storm/synchcall/command/datatransfer/PrepareToPutRequestCommand.java index 33a3a1ef..341f8808 100644 --- a/src/main/java/it/grid/storm/synchcall/command/datatransfer/PrepareToPutRequestCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/datatransfer/PrepareToPutRequestCommand.java @@ -61,7 +61,8 @@ public OutputData execute(InputData inputData) "Unable to build PtP request from the InputData"); } ChunkTask ptpTask = new ChunkTask(request); - ptpTask.run(false); + ptpTask.setExecutionLogged(false); + ptpTask.run(); try { return new PrepareToPutOutputData(request.getRequestData().getSURL(), request.getRequestData().getTransferURL(), request.getRequestData() From c8dc4f9e123e4552573d8e1202f7ccded832cc8f Mon Sep 17 00:00:00 2001 From: Andrea Ceccanti Date: Tue, 15 Apr 2014 12:00:06 +0200 Subject: [PATCH 43/45] Initial fix for STOR-604. --- .../it/grid/storm/asynch/AdvancedPicker.java | 16 +- .../it/grid/storm/catalogs/DataModel.ucls | 190 ------------------ 2 files changed, 13 insertions(+), 193 deletions(-) delete mode 100644 src/main/java/it/grid/storm/catalogs/DataModel.ucls diff --git a/src/main/java/it/grid/storm/asynch/AdvancedPicker.java b/src/main/java/it/grid/storm/asynch/AdvancedPicker.java index c0b723ff..870a3b9a 100644 --- a/src/main/java/it/grid/storm/asynch/AdvancedPicker.java +++ b/src/main/java/it/grid/storm/asynch/AdvancedPicker.java @@ -105,7 +105,6 @@ public void startIt() { @Override public void run() { - retrieve(); } }; // retrieving task @@ -145,9 +144,20 @@ public void retrieve() { SchedulerStatus status = s.getStatus(0); crusherCapacity = status.getRemainingSize(); + Collection requests; + + try{ + + requests = RequestSummaryCatalog + .getInstance().fetchNewRequests(crusherCapacity); - Collection requests = RequestSummaryCatalog - .getInstance().fetchNewRequests(crusherCapacity); + }catch(Throwable t){ + + log.error("Error fetching new requests from database: {}", + t.getMessage(), t); + + return; + } if (requests.isEmpty()) { diff --git a/src/main/java/it/grid/storm/catalogs/DataModel.ucls b/src/main/java/it/grid/storm/catalogs/DataModel.ucls deleted file mode 100644 index 3dd61a3d..00000000 --- a/src/main/java/it/grid/storm/catalogs/DataModel.ucls +++ /dev/null @@ -1,190 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file From 3d6a993f5e6e55e14ae82c8652eb263992724f88 Mon Sep 17 00:00:00 2001 From: enricovianello Date: Tue, 15 Apr 2014 15:02:54 +0200 Subject: [PATCH 44/45] fix for https://issues.infn.it/jira/browse/STOR-602 - cleaner code --- .../it/grid/storm/scheduler/ChunkTask.java | 82 +++++++++---------- .../java/it/grid/storm/scheduler/Task.java | 6 +- .../PrepareToGetRequestCommand.java | 1 - .../PrepareToPutRequestCommand.java | 1 - 4 files changed, 43 insertions(+), 47 deletions(-) diff --git a/src/main/java/it/grid/storm/scheduler/ChunkTask.java b/src/main/java/it/grid/storm/scheduler/ChunkTask.java index 17809c3b..3af33707 100644 --- a/src/main/java/it/grid/storm/scheduler/ChunkTask.java +++ b/src/main/java/it/grid/storm/scheduler/ChunkTask.java @@ -30,6 +30,9 @@ import java.util.ArrayList; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + /** *

* Title: @@ -55,36 +58,43 @@ */ public class ChunkTask extends Task { + private static final Logger log = LoggerFactory + .getLogger(ChunkTask.class); + private final Delegable todo; private final String userDN; private final String surl; private final String requestToken; - private final boolean isAsynchTask; - private final boolean isChunkTask; - private boolean executionLogged = true; private boolean successResult = false; public ChunkTask(Delegable todo) { - super(); + super(todo.getName()); this.todo = todo; - this.taskName = todo.getName(); if (todo instanceof Request) { - this.userDN = ((Request) todo).getUserDN(); - this.surl = ((Request) todo).getSURL(); + userDN = ((Request) todo).getUserDN(); + surl = ((Request) todo).getSURL(); if (todo instanceof PersistentRequestChunk) { - this.requestToken = ((PersistentRequestChunk) todo).getRequestToken(); + requestToken = ((PersistentRequestChunk) todo).getRequestToken(); } else { - this.requestToken = "Empty"; + requestToken = "Empty"; } } else { - this.userDN = "unknonw"; - this.surl = "unknonw"; - this.requestToken = "unknonw"; + userDN = "unknonw"; + surl = "unknonw"; + requestToken = "unknonw"; } - this.isAsynchTask = todo instanceof PersistentRequestChunk; - this.isChunkTask = todo instanceof RequestChunk; + } + + private boolean isAsynchTask() { + + return todo instanceof PersistentRequestChunk; + } + + private boolean isChunkTask() { + + return todo instanceof RequestChunk; } public void setResult(boolean result) { @@ -121,20 +131,19 @@ public void run() { runEvent(); todo.doIt(); endEvent(); - if (isExecutionLogged()) - logExecution(); + logExecution(); } protected void endEvent() { super.endEvent(); if (todo instanceof Request) { - this.successResult = ((Request) todo).isResultSuccess(); + successResult = ((Request) todo).isResultSuccess(); } - if (isAsynchTask) { + if (isAsynchTask()) { ((PersistentRequestChunk) todo).persistStatus(); } - if (isChunkTask) { + if (isChunkTask()) { ((RequestChunk) todo).updateGlobalStatus(); } } @@ -144,21 +153,21 @@ protected void endEvent() { */ public void logExecution() { + if (!isAsynchTask()) { + log.debug("Booking Synch chunck execution disabled!"); + return; + } + ArrayList bks = HealthDirector.getHealthMonitor() .getBookKeepers(); if (bks.isEmpty()) { return; } - LogEvent event; - if (todo instanceof RequestChunk) { - event = new LogEvent(buildOperationType(), this.userDN, this.surl, - this.getStartExecutionTime(), this.howlongInExecution(), - this.requestToken, this.successResult); - } else { - event = new LogEvent(buildOperationType(), this.userDN, this.surl, - this.getStartExecutionTime(), this.howlongInExecution(), - this.successResult); - } + // if isAsynchTask then todo is instance of PersistentRequestChunk + LogEvent event = new LogEvent(buildOperationType(), userDN, surl, + getStartExecutionTime(), howlongInExecution(), + requestToken, successResult); + log.debug("Booking Asynch event {}", event); for (int i = 0; i < bks.size(); i++) { bks.get(i).addLogEvent(event); } @@ -194,7 +203,7 @@ public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + (isAsynchTask ? 1231 : 1237); + result = prime * result + (isAsynchTask() ? 1231 : 1237); result = prime * result + ((requestToken == null) ? 0 : requestToken.hashCode()); result = prime * result + (successResult ? 1231 : 1237); @@ -222,7 +231,7 @@ public boolean equals(Object obj) { return false; } ChunkTask other = (ChunkTask) obj; - if (isAsynchTask != other.isAsynchTask) { + if (isAsynchTask() != other.isAsynchTask()) { return false; } if (requestToken == null) { @@ -259,15 +268,4 @@ public boolean equals(Object obj) { return true; } - public boolean isExecutionLogged() { - - return executionLogged; - } - - - public void setExecutionLogged(boolean executionLogged) { - - this.executionLogged = executionLogged; - } - } diff --git a/src/main/java/it/grid/storm/scheduler/Task.java b/src/main/java/it/grid/storm/scheduler/Task.java index 92bfdba0..69903f03 100644 --- a/src/main/java/it/grid/storm/scheduler/Task.java +++ b/src/main/java/it/grid/storm/scheduler/Task.java @@ -53,15 +53,15 @@ public abstract class Task implements Runnable, Comparable { protected Task() { - taskName = UNDEF_TASKNAME; - creationTime = System.currentTimeMillis(); + this(UNDEF_TASKNAME); } protected Task(String name) { taskName = name; - if (taskName == null) + if (taskName == null) { taskName = UNDEF_TASKNAME; + } creationTime = System.currentTimeMillis(); } diff --git a/src/main/java/it/grid/storm/synchcall/command/datatransfer/PrepareToGetRequestCommand.java b/src/main/java/it/grid/storm/synchcall/command/datatransfer/PrepareToGetRequestCommand.java index 2e36b7c1..1e9bb621 100644 --- a/src/main/java/it/grid/storm/synchcall/command/datatransfer/PrepareToGetRequestCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/datatransfer/PrepareToGetRequestCommand.java @@ -59,7 +59,6 @@ public OutputData execute(InputData inputData) throws CommandException { "Unable to build PtG request from the InputData"); } ChunkTask ptgTask = new ChunkTask(request); - ptgTask.setExecutionLogged(false); ptgTask.run(); try { return new PrepareToGetOutputData(request.getRequestData().getSURL(), diff --git a/src/main/java/it/grid/storm/synchcall/command/datatransfer/PrepareToPutRequestCommand.java b/src/main/java/it/grid/storm/synchcall/command/datatransfer/PrepareToPutRequestCommand.java index 341f8808..dd93c082 100644 --- a/src/main/java/it/grid/storm/synchcall/command/datatransfer/PrepareToPutRequestCommand.java +++ b/src/main/java/it/grid/storm/synchcall/command/datatransfer/PrepareToPutRequestCommand.java @@ -61,7 +61,6 @@ public OutputData execute(InputData inputData) "Unable to build PtP request from the InputData"); } ChunkTask ptpTask = new ChunkTask(request); - ptpTask.setExecutionLogged(false); ptpTask.run(); try { return new PrepareToPutOutputData(request.getRequestData().getSURL(), From 502e6d2c84fcafac04ef0728be1a8d87dcf8e70a Mon Sep 17 00:00:00 2001 From: enricovianello Date: Tue, 15 Apr 2014 15:25:25 +0200 Subject: [PATCH 45/45] Cosmetic fix --- src/main/java/it/grid/storm/scheduler/ChunkTask.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/it/grid/storm/scheduler/ChunkTask.java b/src/main/java/it/grid/storm/scheduler/ChunkTask.java index 3af33707..372ade56 100644 --- a/src/main/java/it/grid/storm/scheduler/ChunkTask.java +++ b/src/main/java/it/grid/storm/scheduler/ChunkTask.java @@ -154,7 +154,7 @@ protected void endEvent() { public void logExecution() { if (!isAsynchTask()) { - log.debug("Booking Synch chunck execution disabled!"); + log.debug("logExecution disabled for synch chuncks"); return; } @@ -163,7 +163,6 @@ public void logExecution() { if (bks.isEmpty()) { return; } - // if isAsynchTask then todo is instance of PersistentRequestChunk LogEvent event = new LogEvent(buildOperationType(), userDN, surl, getStartExecutionTime(), howlongInExecution(), requestToken, successResult);