use of password.pwm.util.localdb.LocalDB in project pwm by pwm-project.
the class ImportLocalDBCommand method doCommand.
@Override
void doCommand() throws Exception {
final LocalDB localDB = cliEnvironment.getLocalDB();
final String msg = "Proceeding with this operation will clear ALL data from the LocalDB." + "\n" + "Please consider backing up the LocalDB before proceeding. " + "\n" + "\n" + "The application must be stopped for this operation to succeed.";
if (!promptForContinue(msg)) {
out("exiting...");
return;
}
final LocalDBUtility pwmDBUtility = new LocalDBUtility(localDB);
final File inputFile = (File) cliEnvironment.getOptions().get(CliParameters.REQUIRED_EXISTING_INPUT_FILE.getName());
try {
pwmDBUtility.importLocalDB(inputFile, System.out);
} catch (PwmOperationalException e) {
out("error during import: " + e.getMessage());
}
}
use of password.pwm.util.localdb.LocalDB in project pwm by pwm-project.
the class LocalDBInfoCommand method doCommand.
public void doCommand() throws Exception {
final Instant startTime = Instant.now();
final LocalDB localDB = cliEnvironment.getLocalDB();
final long localDBdiskSpace = FileSystemUtility.getFileDirectorySize(localDB.getFileLocation());
out("beginning LocalDBInfo");
out("LocalDB total disk space = " + PwmNumberFormat.forDefaultLocale().format(localDBdiskSpace) + " (" + StringUtil.formatDiskSize(localDBdiskSpace) + ")");
out("examining LocalDB, this may take a while.... ");
for (final LocalDB.DB db : LocalDB.DB.values()) {
out("---" + db.toString() + "---");
final Map<LocalDBUtility.StatsKey, Object> stats = LocalDBUtility.dbStats(localDB, db);
out(JsonUtil.serializeMap(stats, JsonUtil.Flag.PrettyPrint));
}
out("completed LocalDBInfo in " + TimeDuration.fromCurrent(startTime).asCompactString());
}
use of password.pwm.util.localdb.LocalDB in project pwm by pwm-project.
the class ClearResponsesCommand method doCommand.
@Override
void doCommand() throws Exception {
final String msg = "Proceeding with this operation will clear all stored responses from the LocalDB." + "\n" + "Please consider exporting the responses before proceeding. " + "\n" + "\n" + "The application must be stopped for this operation to succeed." + "\n";
if (!promptForContinue(msg)) {
return;
}
final LocalDB localDB = cliEnvironment.getLocalDB();
if (localDB.size(LocalDB.DB.RESPONSE_STORAGE) == 0) {
out("The LocalDB response database is already empty");
return;
}
out("clearing " + localDB.size(LocalDB.DB.RESPONSE_STORAGE) + " responses");
localDB.truncate(LocalDB.DB.RESPONSE_STORAGE);
out("all saved responses are now removed from LocalDB");
}
use of password.pwm.util.localdb.LocalDB in project pwm by pwm-project.
the class ConfigManagerLocalDBServlet method restUploadLocalDB.
void restUploadLocalDB(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final HttpServletRequest req = pwmRequest.getHttpServletRequest();
if (pwmApplication.getApplicationMode() == PwmApplicationMode.RUNNING) {
final String errorMsg = "database upload is not permitted when in running mode";
final ErrorInformation errorInformation = new ErrorInformation(PwmError.CONFIG_UPLOAD_FAILURE, errorMsg, new String[] { errorMsg });
pwmRequest.respondWithError(errorInformation, true);
return;
}
if (!ServletFileUpload.isMultipartContent(req)) {
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, "no file found in upload");
pwmRequest.outputJsonResult(RestResultBean.fromError(errorInformation, pwmRequest));
LOGGER.error(pwmRequest, "error during database import: " + errorInformation.toDebugStr());
return;
}
final InputStream inputStream = pwmRequest.readFileUploadStream(PwmConstants.PARAM_FILE_UPLOAD);
final ContextManager contextManager = ContextManager.getContextManager(pwmRequest);
LocalDB localDB = null;
try {
final File localDBLocation = pwmApplication.getLocalDB().getFileLocation();
final Configuration configuration = pwmApplication.getConfig();
contextManager.shutdown();
localDB = LocalDBFactory.getInstance(localDBLocation, false, null, configuration);
final LocalDBUtility localDBUtility = new LocalDBUtility(localDB);
LOGGER.info(pwmRequest, "beginning LocalDB import");
localDBUtility.importLocalDB(inputStream, LOGGER.asAppendable(PwmLogLevel.DEBUG, pwmRequest.getSessionLabel()));
LOGGER.info(pwmRequest, "completed LocalDB import");
} catch (Exception e) {
final ErrorInformation errorInformation = e instanceof PwmException ? ((PwmException) e).getErrorInformation() : new ErrorInformation(PwmError.ERROR_UNKNOWN, e.getMessage());
pwmRequest.outputJsonResult(RestResultBean.fromError(errorInformation, pwmRequest));
LOGGER.error(pwmRequest, "error during LocalDB import: " + errorInformation.toDebugStr());
return;
} finally {
if (localDB != null) {
try {
localDB.close();
} catch (Exception e) {
LOGGER.error(pwmRequest, "error closing LocalDB after import process: " + e.getMessage());
}
}
contextManager.initialize();
}
pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
}
use of password.pwm.util.localdb.LocalDB in project pwm by pwm-project.
the class AppDashboardData method makeLocalDbTableSizes.
private static Map<LocalDB.DB, String> makeLocalDbTableSizes(final PwmApplication pwmApplication, final Locale locale) {
final Map<LocalDB.DB, String> returnData = new LinkedHashMap<>();
final LocalDB localDB = pwmApplication.getLocalDB();
final PwmNumberFormat numberFormat = PwmNumberFormat.forLocale(locale);
try {
for (final LocalDB.DB db : LocalDB.DB.values()) {
returnData.put(db, numberFormat.format(localDB.size(db)));
}
} catch (LocalDBException e) {
LOGGER.error("error making localDB size bean: " + e.getMessage());
}
return Collections.unmodifiableMap(returnData);
}
Aggregations