Commit 137993aa authored by Adrian-Eduard Negru's avatar Adrian-Eduard Negru Committed by Costin Grigoras
Browse files

Update catalogue MD5 for PFNs with blank / null checksums

parent 4e72ec8a
package alien.api.catalogue;
import alien.api.Request;
import alien.catalogue.GUIDUtils;
import alien.user.AliEnPrincipal;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
public class UpdateGUIDMD5 extends Request {
private UUID uuid;
private String md5;
private boolean updateSuccessful;
public UpdateGUIDMD5(final AliEnPrincipal user, final UUID uuid, String md5) {
setRequestUser(user);
this.uuid = uuid;
this.md5 = md5;
}
@Override
public List<String> getArguments() {
return Arrays.asList(uuid.toString(), md5);
}
@Override
public void run() {
this.updateSuccessful = GUIDUtils.updateMd5(uuid, md5);
}
public boolean isUpdateSuccessful() {
return updateSuccessful;
}
}
package alien.catalogue;
import alien.api.Dispatcher;
import alien.api.ServerException;
import alien.api.catalogue.UpdateGUIDMD5;
import alien.catalogue.access.AccessType;
import alien.catalogue.access.AuthorizationFactory;
import alien.config.ConfigUtils;
import alien.io.IOUtils;
import alien.io.protocols.TempFileManager;
import alien.monitoring.Monitor;
import alien.monitoring.MonitorFactory;
import alien.user.AliEnPrincipal;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
......@@ -19,16 +30,8 @@ import java.util.UUID;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
import alien.catalogue.access.AccessType;
import alien.catalogue.access.AuthorizationFactory;
import alien.config.ConfigUtils;
import alien.io.IOUtils;
import alien.io.protocols.TempFileManager;
import alien.monitoring.Monitor;
import alien.monitoring.MonitorFactory;
import alien.user.AliEnPrincipal;
import lazyj.DBFunctions;
import lazyj.Format;
import lia.util.process.ExternalProcesses;
/**
......@@ -706,6 +709,62 @@ public final class GUIDUtils {
return true;
}
/**
* @param guid
* @param md5
* @return <code>true</code> if the MD5 was already set or if it could be now set, <code>false</code> if there was any error setting it
*/
public static boolean updateMd5(UUID guid, String md5) {
if (guid == null || md5 == null)
return false;
if (!ConfigUtils.isCentralService())
try {
final UpdateGUIDMD5 request = new UpdateGUIDMD5(null, guid, md5);
return Dispatcher.execute(request).isUpdateSuccessful();
}
catch (@SuppressWarnings("unused") final ServerException se) {
return false;
}
final int host = getGUIDHost(guid);
if (host < 0)
return false;
final Host h = CatalogueUtils.getHost(host);
if (h == null)
return false;
try (DBFunctions db = h.getDB()) {
if (db == null)
return false;
final int tableName = GUIDUtils.getTableNameForGUID(guid);
if (tableName < 0)
return false;
if (!db.query("UPDATE G" + tableName + "L SET md5='" + Format.escSQL(md5) + "' WHERE guid=string2binary('" + Format.escSQL(guid.toString()) + "') AND (md5 is null OR length(md5) = 0)"))
return false;
if (db.getUpdateCount() == 0)
return false;
List<LFN> lfns = LFNUtils.getLFNsFromUUIDs(Set.of(guid));
for(LFN lfn : lfns) {
String guidMD5 = GUIDUtils.getGUID(lfn).getMD5();
if (guidMD5 != null && guidMD5.length() > 0)
GUIDUtils.checkMD5(lfn);
}
}
return true;
}
/**
* @param pfn
* @return the GUID, or <code>null</code> if it cannot be located
......
......@@ -11,7 +11,18 @@ import static utils.crawler.CrawlingStatusCode.E_PFN_XRDSTAT_FAILED;
import static utils.crawler.CrawlingStatusCode.E_UNEXPECTED_ERROR;
import static utils.crawler.CrawlingStatusCode.S_FILE_CHECKSUM_MATCH;
import static utils.crawler.CrawlingStatusCode.S_FILE_CHECKSUM_MISMATCH;
import alien.catalogue.GUID;
import alien.catalogue.PFN;
import alien.config.ConfigUtils;
import alien.io.IOUtils;
import alien.io.protocols.Factory;
import alien.io.protocols.SourceException;
import alien.io.protocols.SourceExceptionCode;
import alien.io.protocols.Xrootd;
import alien.se.SE;
import alien.se.SEUtils;
import alien.shell.commands.JAliEnCOMMander;
import alien.user.JAKeyStore;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
......@@ -24,22 +35,8 @@ import java.util.Iterator;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import alien.catalogue.GUID;
import alien.catalogue.PFN;
import alien.config.ConfigUtils;
import alien.io.IOUtils;
import alien.io.protocols.Factory;
import alien.io.protocols.SourceException;
import alien.io.protocols.SourceExceptionCode;
import alien.io.protocols.Xrootd;
import alien.se.SE;
import alien.se.SEUtils;
import alien.shell.commands.JAliEnCOMMander;
import alien.user.JAKeyStore;
import utils.StatusType;
/**
......@@ -431,10 +428,14 @@ public class SEFileCrawler {
if (Long.valueOf(0).equals(catalogueFileSize))
status = new CrawlingStatus(E_FILE_EMPTY, "Catalogue file size is 0");
else if (catalogueMD5 == null)
else if (catalogueMD5 == null) {
// GUIDUtils.updateMd5(guid.guid, observedMD5);
status = new CrawlingStatus(E_CATALOGUE_MD5_IS_NULL, "Catalogue MD5 is null");
else if (catalogueMD5.isBlank())
}
else if (catalogueMD5.isBlank()) {
// GUIDUtils.updateMd5(guid.guid, observedMD5);
status = new CrawlingStatus(E_CATALOGUE_MD5_IS_BLANK, "Catalogue MD5 is blank");
}
else if (!catalogueMD5.equalsIgnoreCase(observedMD5))
status = new CrawlingStatus(S_FILE_CHECKSUM_MISMATCH, "Recomputed checksum does not match catalogue checksum");
else
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment