use of org.apache.jena.atlas.RuntimeIOException in project jena by apache.
the class ActionDatasets method execDeleteItem.
// ---- DELETE
@Override
protected void execDeleteItem(HttpAction action) {
// Does not exist?
String name = getItemDatasetName(action);
if (name == null)
name = "";
action.log.info(format("[%d] DELETE dataset=%s", action.id, name));
if (!action.getDataAccessPointRegistry().isRegistered(name))
ServletOps.errorNotFound("No such dataset registered: " + name);
// This acts as a lock.
systemDSG.begin(ReadWrite.WRITE);
boolean committed = false;
try {
// Here, go offline.
// Need to reference count operations when they drop to zero
// or a timer goes off, we delete the dataset.
// Redo check inside transaction.
DataAccessPoint ref = action.getDataAccessPointRegistry().get(name);
if (ref == null)
ServletOps.errorNotFound("No such dataset registered: " + name);
// Get a reference before removing.
DataService dataService = ref.getDataService();
// ---- Make it invisible in this running server.
action.getDataAccessPointRegistry().remove(name);
// Find the configuration.
String filename = name.startsWith("/") ? name.substring(1) : name;
List<String> configurationFiles = FusekiWebapp.existingConfigurationFile(filename);
if (configurationFiles.isEmpty()) {
// ---- Unmanaged
action.log.warn(format("[%d] Can't delete database configuration - not a managed database", action.id, name));
// ServletOps.errorOccurred(format("Can't delete database - not a managed configuration", name));
systemDSG.commit();
committed = true;
ServletOps.success(action);
return;
}
if (configurationFiles.size() > 1) {
// -- This should not happen.
action.log.warn(format("[%d] There are %d configuration files, not one.", action.id, configurationFiles.size()));
ServletOps.errorOccurred(format("There are %d configuration files, not one. Delete not performed; clearup of the filesystem needed.", configurationFiles.size()));
return;
}
// ---- Remove managed database.
String cfgPathname = configurationFiles.get(0);
// Delete configuration file.
// Once deleted, server restart will not have the database.
FileOps.deleteSilent(cfgPathname);
// Delete the database for real only when it is in the server "run/databases"
// area. Don't delete databases that reside elsewhere. We do delete the
// configuration file, so the databases will not be associated with the server
// anymore.
boolean isTDB1 = org.apache.jena.tdb.sys.TDBInternal.isTDB1(dataService.getDataset());
boolean isTDB2 = org.apache.jena.tdb2.sys.TDBInternal.isTDB2(dataService.getDataset());
dataService.shutdown();
// JENA-1481: Really delete files.
if ((isTDB1 || isTDB2)) {
// Delete databases created by the UI, or the admin operation, which are
// in predictable, unshared location on disk.
// There may not be any database files, the in-memory case.
Path pDatabase = FusekiWebapp.dirDatabases.resolve(filename);
if (Files.exists(pDatabase)) {
try {
if (Files.isSymbolicLink(pDatabase)) {
action.log.info(format("[%d] Database is a symbolic link, not removing files", action.id, pDatabase));
} else {
IO.deleteAll(pDatabase);
action.log.info(format("[%d] Deleted database files %s", action.id, pDatabase));
}
} catch (RuntimeIOException ex) {
action.log.error(format("[%d] Error while deleting database files %s: %s", action.id, pDatabase, ex.getMessage()), ex);
// But we have managed to remove it from the running server, and removed its configuration, so declare victory.
}
}
}
// -- System database
// Find graph associated with this dataset name.
// (Statically configured databases aren't in the system database.)
Node n = NodeFactory.createLiteral(DataAccessPoint.canonical(name));
Quad q = getOne(systemDSG, null, null, pServiceName.asNode(), n);
// ServletOps.errorBadRequest("Failed to find dataset for '"+name+"'");
if (q != null) {
Node gn = q.getGraph();
// action.log.info("SHUTDOWN NEEDED"); // To ensure it goes away?
systemDSG.deleteAny(gn, null, null, null);
}
systemDSG.commit();
committed = true;
ServletOps.success(action);
} finally {
if (!committed)
systemDSG.abort();
systemDSG.end();
}
}
use of org.apache.jena.atlas.RuntimeIOException in project jena by apache.
the class TransInteger method read.
// -- Read/write the value
// This should really be checksum'ed or other internal check to make sure IO worked.
private static long read(String filename) {
try {
String str = IO.readWholeFileAsUTF8(filename);
if (str.endsWith("\n")) {
str = str.substring(0, str.length() - 1);
}
str = str.trim();
return Long.parseLong(str);
} catch (RuntimeIOException ex) {
Log.error(TransInteger.class, "IOException: " + ex.getMessage(), ex);
throw ex;
} catch (NumberFormatException ex) {
Log.error(TransInteger.class, "NumberformatException: " + ex.getMessage());
throw new InternalErrorException(ex);
}
}
Aggregations