Removed 'plan_transfer' table from the database
- Removed TransferTable - Added a TransferTableRemovalPatch - Removed TransferOperations (and Database#transfer) - Removed SQLTransferOps - Removed UnsupportedTransferDatabaseException - Removed uses in NetworkSettings and related tests
This commit is contained in:
parent
f4db11f2fa
commit
940c414f7d
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.api.exceptions.connection;
|
||||
|
||||
import com.djrapitops.plan.system.database.databases.Database;
|
||||
|
||||
/**
|
||||
* Exception thrown when calling Database#transfer and Database implementation doesn't support it.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class UnsupportedTransferDatabaseException extends WebException {
|
||||
|
||||
public UnsupportedTransferDatabaseException(Database db) {
|
||||
super(db.getType().getName() + " does not support Transfer operations!");
|
||||
}
|
||||
}
|
|
@ -63,5 +63,4 @@ public abstract class Database {
|
|||
|
||||
public abstract void scheduleClean(long delay);
|
||||
|
||||
public abstract TransferOperations transfer();
|
||||
}
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.system.database.databases.operation;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Operations for transferring data via Database to another server.
|
||||
* <p>
|
||||
* Receiving server has to be using the same database.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public interface TransferOperations {
|
||||
|
||||
// Save
|
||||
|
||||
void storeConfigSettings(String encodedSettingString);
|
||||
|
||||
// Get
|
||||
|
||||
Optional<String> getEncodedConfigSettings();
|
||||
}
|
|
@ -81,7 +81,6 @@ public abstract class SQLDB extends Database {
|
|||
private final WorldTable worldTable;
|
||||
private final WorldTimesTable worldTimesTable;
|
||||
private final ServerTable serverTable;
|
||||
private final TransferTable transferTable;
|
||||
private final PingTable pingTable;
|
||||
|
||||
private final SQLBackupOps backupOps;
|
||||
|
@ -91,7 +90,6 @@ public abstract class SQLDB extends Database {
|
|||
private final SQLSearchOps searchOps;
|
||||
private final SQLCountOps countOps;
|
||||
private final SQLSaveOps saveOps;
|
||||
private final SQLTransferOps transferOps;
|
||||
|
||||
private PluginTask dbCleanTask;
|
||||
|
||||
|
@ -127,7 +125,6 @@ public abstract class SQLDB extends Database {
|
|||
killsTable = new KillsTable(this);
|
||||
worldTable = new WorldTable(this);
|
||||
worldTimesTable = new WorldTimesTable(this);
|
||||
transferTable = new TransferTable(this);
|
||||
pingTable = new PingTable(this);
|
||||
|
||||
backupOps = new SQLBackupOps(this);
|
||||
|
@ -137,7 +134,6 @@ public abstract class SQLDB extends Database {
|
|||
countOps = new SQLCountOps(this);
|
||||
searchOps = new SQLSearchOps(this);
|
||||
saveOps = new SQLSaveOps(this);
|
||||
transferOps = new SQLTransferOps(this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -191,7 +187,6 @@ public abstract class SQLDB extends Database {
|
|||
Patch[] patches = new Patch[]{
|
||||
new Version10Patch(this),
|
||||
new GeoInfoLastUsedPatch(this),
|
||||
new TransferPartitionPatch(this),
|
||||
new SessionAFKTimePatch(this),
|
||||
new KillsServerIDPatch(this),
|
||||
new WorldTimesSeverIDPatch(this),
|
||||
|
@ -208,7 +203,8 @@ public abstract class SQLDB extends Database {
|
|||
new PingOptimizationPatch(this),
|
||||
new NicknamesOptimizationPatch(this),
|
||||
new UserInfoOptimizationPatch(this),
|
||||
new GeoInfoOptimizationPatch(this)
|
||||
new GeoInfoOptimizationPatch(this),
|
||||
new TransferTableRemovalPatch(this)
|
||||
};
|
||||
|
||||
try {
|
||||
|
@ -243,7 +239,7 @@ public abstract class SQLDB extends Database {
|
|||
serverTable, usersTable, userInfoTable, geoInfoTable,
|
||||
nicknamesTable, sessionsTable, killsTable, pingTable,
|
||||
commandUseTable, tpsTable, worldTable,
|
||||
worldTimesTable, securityTable, transferTable
|
||||
worldTimesTable, securityTable
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -254,7 +250,7 @@ public abstract class SQLDB extends Database {
|
|||
*/
|
||||
public Table[] getAllTablesInRemoveOrder() {
|
||||
return new Table[]{
|
||||
transferTable, geoInfoTable, nicknamesTable, killsTable,
|
||||
geoInfoTable, nicknamesTable, killsTable,
|
||||
worldTimesTable, sessionsTable, worldTable, pingTable,
|
||||
userInfoTable, usersTable, commandUseTable,
|
||||
tpsTable, securityTable, serverTable
|
||||
|
@ -273,7 +269,6 @@ public abstract class SQLDB extends Database {
|
|||
|
||||
private void clean() {
|
||||
tpsTable.clean();
|
||||
transferTable.clean();
|
||||
pingTable.clean();
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
|
@ -434,10 +429,6 @@ public abstract class SQLDB extends Database {
|
|||
return userInfoTable;
|
||||
}
|
||||
|
||||
public TransferTable getTransferTable() {
|
||||
return transferTable;
|
||||
}
|
||||
|
||||
public PingTable getPingTable() {
|
||||
return pingTable;
|
||||
}
|
||||
|
@ -477,11 +468,6 @@ public abstract class SQLDB extends Database {
|
|||
return saveOps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TransferOperations transfer() {
|
||||
return transferOps;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
|
|
@ -35,7 +35,6 @@ public class SQLOps {
|
|||
protected final WorldTable worldTable;
|
||||
protected final WorldTimesTable worldTimesTable;
|
||||
protected final ServerTable serverTable;
|
||||
protected final TransferTable transferTable;
|
||||
protected final PingTable pingTable;
|
||||
|
||||
public SQLOps(SQLDB db) {
|
||||
|
@ -53,7 +52,6 @@ public class SQLOps {
|
|||
worldTable = db.getWorldTable();
|
||||
worldTimesTable = db.getWorldTimesTable();
|
||||
serverTable = db.getServerTable();
|
||||
transferTable = db.getTransferTable();
|
||||
pingTable = db.getPingTable();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,45 +0,0 @@
|
|||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.system.database.databases.sql.operation;
|
||||
|
||||
import com.djrapitops.plan.system.database.databases.operation.TransferOperations;
|
||||
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* TransferOperations for MySQL Database.
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class SQLTransferOps extends SQLOps implements TransferOperations {
|
||||
|
||||
public SQLTransferOps(SQLDB db) {
|
||||
super(db);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void storeConfigSettings(String encodedSettingString) {
|
||||
transferTable.storeConfigSettings(encodedSettingString);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> getEncodedConfigSettings() {
|
||||
return transferTable.getConfigSettings();
|
||||
}
|
||||
|
||||
}
|
|
@ -17,21 +17,20 @@
|
|||
package com.djrapitops.plan.system.database.databases.sql.patches;
|
||||
|
||||
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
|
||||
import com.djrapitops.plan.system.database.databases.sql.tables.TransferTable;
|
||||
|
||||
public class TransferPartitionPatch extends Patch {
|
||||
public class TransferTableRemovalPatch extends Patch {
|
||||
|
||||
public TransferPartitionPatch(SQLDB db) {
|
||||
public TransferTableRemovalPatch(SQLDB db) {
|
||||
super(db);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasBeenApplied() {
|
||||
return hasColumn(TransferTable.TABLE_NAME, TransferTable.Col.PART.get());
|
||||
return !hasTable("plan_transfer");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply() {
|
||||
addColumn(TransferTable.TABLE_NAME, TransferTable.Col.PART + " bigint NOT NULL DEFAULT 0");
|
||||
dropTable("plan_transfer");
|
||||
}
|
||||
}
|
|
@ -1,194 +0,0 @@
|
|||
/*
|
||||
* This file is part of Player Analytics (Plan).
|
||||
*
|
||||
* Plan is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License v3 as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Plan is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Plan. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package com.djrapitops.plan.system.database.databases.sql.tables;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.database.DBInitException;
|
||||
import com.djrapitops.plan.system.database.databases.DBType;
|
||||
import com.djrapitops.plan.system.database.databases.sql.SQLDB;
|
||||
import com.djrapitops.plan.system.database.databases.sql.processing.ExecStatement;
|
||||
import com.djrapitops.plan.system.database.databases.sql.processing.QueryStatement;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Column;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.Sql;
|
||||
import com.djrapitops.plan.system.database.databases.sql.statements.TableSqlParser;
|
||||
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
/**
|
||||
* Table that is in charge of transferring data between network servers.
|
||||
* <p>
|
||||
* Table Name: plan_transfer
|
||||
* <p>
|
||||
* For contained columns {@see Col}
|
||||
*
|
||||
* @author Rsl1122
|
||||
*/
|
||||
public class TransferTable extends Table {
|
||||
|
||||
public static final String TABLE_NAME = "plan_transfer";
|
||||
private final String insertStatementNoParts;
|
||||
|
||||
private final ServerTable serverTable;
|
||||
private final String selectStatement;
|
||||
|
||||
public TransferTable(SQLDB db) {
|
||||
super(TABLE_NAME, db);
|
||||
|
||||
serverTable = db.getServerTable();
|
||||
|
||||
if (db.getType() == DBType.H2) {
|
||||
insertStatementNoParts = "INSERT INTO " + tableName + " (" +
|
||||
Col.SENDER_ID + ", " +
|
||||
Col.EXPIRY + ", " +
|
||||
Col.INFO_TYPE + ", " +
|
||||
Col.EXTRA_VARIABLES + ", " +
|
||||
Col.CONTENT +
|
||||
") VALUES (" +
|
||||
serverTable.statementSelectServerID + ", " +
|
||||
"?, ?, ?, ?)" +
|
||||
" ON DUPLICATE KEY UPDATE" +
|
||||
" " + Col.EXPIRY + "=?," +
|
||||
" " + Col.INFO_TYPE + "=?," +
|
||||
" " + Col.EXTRA_VARIABLES + "=?," +
|
||||
" " + Col.CONTENT + "=?";
|
||||
} else {
|
||||
insertStatementNoParts = "REPLACE INTO " + tableName + " (" +
|
||||
Col.SENDER_ID + ", " +
|
||||
Col.EXPIRY + ", " +
|
||||
Col.INFO_TYPE + ", " +
|
||||
Col.EXTRA_VARIABLES + ", " +
|
||||
Col.CONTENT +
|
||||
") VALUES (" +
|
||||
serverTable.statementSelectServerID + ", " +
|
||||
"?, ?, ?, ?)";
|
||||
}
|
||||
|
||||
selectStatement = "SELECT * FROM " + tableName +
|
||||
" WHERE " + Col.INFO_TYPE + "= ?" +
|
||||
" AND " + Col.EXPIRY + "> ?" +
|
||||
" ORDER BY " + Col.EXPIRY + " DESC, "
|
||||
+ Col.PART + " ASC";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createTable() throws DBInitException {
|
||||
createTable(TableSqlParser.createTable(tableName)
|
||||
.column(Col.SENDER_ID, Sql.INT).notNull()
|
||||
.column(Col.EXPIRY, Sql.LONG).notNull().defaultValue("0")
|
||||
.column(Col.INFO_TYPE, Sql.varchar(100)).notNull()
|
||||
.column(Col.EXTRA_VARIABLES, Sql.varchar(255)).defaultValue("''")
|
||||
.column(Col.CONTENT, supportsMySQLQueries ? "MEDIUMTEXT" : Sql.varchar(1)) // SQLite does not enforce varchar limits.
|
||||
.column(Col.PART, Sql.LONG).notNull().defaultValue("0")
|
||||
.foreignKey(Col.SENDER_ID, serverTable.toString(), ServerTable.Col.SERVER_ID)
|
||||
.toString()
|
||||
);
|
||||
}
|
||||
|
||||
public void clean() {
|
||||
String sql = "DELETE FROM " + tableName +
|
||||
" WHERE " + Col.EXPIRY + " < ?" +
|
||||
" AND " + Col.INFO_TYPE + " != ?";
|
||||
|
||||
execute(new ExecStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setLong(1, System.currentTimeMillis());
|
||||
statement.setString(2, "onlineStatus");
|
||||
}
|
||||
});
|
||||
sql = "DELETE FROM " + tableName +
|
||||
" WHERE " + Col.SENDER_ID + " = " + serverTable.statementSelectServerID +
|
||||
" AND " + Col.INFO_TYPE + " = ?";
|
||||
|
||||
execute(new ExecStatement(sql) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, getServerUUID().toString());
|
||||
statement.setString(2, "onlineStatus");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void storeConfigSettings(String encodedSettingString) {
|
||||
execute(new ExecStatement(insertStatementNoParts) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
long expiration = System.currentTimeMillis() + TimeUnit.HOURS.toMillis(1L);
|
||||
|
||||
statement.setString(1, getServerUUID().toString());
|
||||
statement.setLong(2, expiration);
|
||||
statement.setString(3, "configSettings");
|
||||
statement.setString(4, null);
|
||||
statement.setString(5, encodedSettingString);
|
||||
|
||||
if (db.getType() == DBType.H2) {
|
||||
statement.setLong(6, expiration);
|
||||
statement.setString(7, "configSettings");
|
||||
statement.setString(8, null);
|
||||
statement.setString(9, encodedSettingString);
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public Optional<String> getConfigSettings() {
|
||||
return query(new QueryStatement<Optional<String>>(selectStatement, 100) {
|
||||
@Override
|
||||
public void prepare(PreparedStatement statement) throws SQLException {
|
||||
statement.setString(1, "configSettings");
|
||||
statement.setLong(2, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> processResults(ResultSet set) throws SQLException {
|
||||
if (set.next()) {
|
||||
return Optional.ofNullable(set.getString(Col.CONTENT.get()));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public enum Col implements Column {
|
||||
SENDER_ID("sender_server_id"),
|
||||
EXPIRY("expiry_date"),
|
||||
INFO_TYPE("type"),
|
||||
CONTENT("content_64"),
|
||||
EXTRA_VARIABLES("extra_variables"),
|
||||
PART("part");
|
||||
|
||||
private final String column;
|
||||
|
||||
Col(String column) {
|
||||
this.column = column;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String get() {
|
||||
return toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return column;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -59,8 +59,7 @@ public class WebExceptionLogger {
|
|||
if (shouldLog(e)) {
|
||||
logger.debug(e.getMessage());
|
||||
}
|
||||
} catch (UnsupportedTransferDatabaseException | UnauthorizedServerException
|
||||
| NotFoundException | NoServersException e) {
|
||||
} catch (UnauthorizedServerException | NotFoundException | NoServersException e) {
|
||||
logger.debug(e.getMessage());
|
||||
} catch (WebException e) {
|
||||
errorHandler.log(L.WARN, definingClass, e);
|
||||
|
|
|
@ -16,7 +16,10 @@
|
|||
*/
|
||||
package com.djrapitops.plan.system.processing.processors.info;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.connection.*;
|
||||
import com.djrapitops.plan.api.exceptions.connection.ConnectionFailException;
|
||||
import com.djrapitops.plan.api.exceptions.connection.NoServersException;
|
||||
import com.djrapitops.plan.api.exceptions.connection.NotFoundException;
|
||||
import com.djrapitops.plan.api.exceptions.connection.UnauthorizedServerException;
|
||||
import com.djrapitops.plan.system.cache.SessionCache;
|
||||
import com.djrapitops.plan.system.info.InfoSystem;
|
||||
import com.djrapitops.plan.system.info.connection.WebExceptionLogger;
|
||||
|
@ -63,7 +66,7 @@ public class InspectCacheRequestProcessor implements Runnable {
|
|||
try {
|
||||
infoSystem.generateAndCachePlayerPage(uuid);
|
||||
msgSender.accept(sender, playerName);
|
||||
} catch (ConnectionFailException | UnsupportedTransferDatabaseException | UnauthorizedServerException
|
||||
} catch (ConnectionFailException | UnauthorizedServerException
|
||||
| NotFoundException | NoServersException e) {
|
||||
sender.sendMessage("§c" + e.getMessage());
|
||||
}
|
||||
|
|
|
@ -20,11 +20,11 @@ import com.djrapitops.plan.system.database.DBSystem;
|
|||
import com.djrapitops.plan.system.info.server.ServerInfo;
|
||||
import com.djrapitops.plan.system.processing.Processing;
|
||||
import com.djrapitops.plan.system.settings.config.PlanConfig;
|
||||
import com.djrapitops.plan.system.settings.paths.*;
|
||||
import com.djrapitops.plan.system.settings.paths.DisplaySettings;
|
||||
import com.djrapitops.plan.system.settings.paths.PluginSettings;
|
||||
import com.djrapitops.plan.system.settings.paths.WebserverSettings;
|
||||
import com.djrapitops.plan.system.settings.paths.key.Setting;
|
||||
import com.djrapitops.plan.utilities.Base64Util;
|
||||
import com.djrapitops.plugin.api.Check;
|
||||
import com.djrapitops.plugin.logging.L;
|
||||
import com.djrapitops.plugin.logging.console.PluginLogger;
|
||||
import com.djrapitops.plugin.logging.error.ErrorHandler;
|
||||
import com.djrapitops.plugin.utilities.Verify;
|
||||
|
@ -32,10 +32,7 @@ import dagger.Lazy;
|
|||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
|
@ -47,9 +44,6 @@ import java.util.UUID;
|
|||
@Deprecated
|
||||
public class NetworkSettings {
|
||||
|
||||
private static final String SPLIT = ";;SETTING;;";
|
||||
private static final String VAL_SPLIT = ";;VALUE;;";
|
||||
|
||||
private final Lazy<PlanConfig> config;
|
||||
private final ServerSpecificSettings serverSpecificSettings;
|
||||
private final Processing processing;
|
||||
|
@ -87,142 +81,12 @@ public class NetworkSettings {
|
|||
// Don't load settings if they are overridden.
|
||||
return;
|
||||
}
|
||||
|
||||
processing.submitNonCritical(this::loadFromDatabase);
|
||||
}
|
||||
|
||||
public void placeSettingsToDB() {
|
||||
if (!Check.isBungeeAvailable() && !Check.isVelocityAvailable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
processing.submitNonCritical(this::placeToDatabase);
|
||||
}
|
||||
|
||||
void loadFromDatabase() {
|
||||
logger.debug("NetworkSettings: Fetch Config settings from database..");
|
||||
Optional<String> encodedConfigSettings = dbSystem.get().getDatabase().transfer().getEncodedConfigSettings();
|
||||
|
||||
if (!encodedConfigSettings.isPresent()) {
|
||||
logger.debug("NetworkSettings: No Config settings in database.");
|
||||
return;
|
||||
}
|
||||
|
||||
String configSettings = Base64Util.decode(encodedConfigSettings.get());
|
||||
Map<String, String> pathValueMap = getPathsAndValues(configSettings);
|
||||
|
||||
logger.debug("NetworkSettings: Updating Settings");
|
||||
try {
|
||||
serverSpecificSettings.updateSettings(pathValueMap);
|
||||
} catch (IOException e) {
|
||||
errorHandler.log(L.ERROR, this.getClass(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, String> getPathsAndValues(String configSettings) {
|
||||
Map<String, String> pathValueMap = new HashMap<>();
|
||||
|
||||
logger.debug("NetworkSettings: Reading Config String..");
|
||||
String[] settings = configSettings.split(SPLIT);
|
||||
UUID thisServerUUID = serverInfo.get().getServerUUID();
|
||||
for (String settingAndVal : settings) {
|
||||
String[] settingValSplit = settingAndVal.split(VAL_SPLIT);
|
||||
String setting = settingValSplit[0];
|
||||
String[] pathSplit = setting.split(":");
|
||||
String path;
|
||||
if (pathSplit.length == 2) {
|
||||
UUID serverUUID = UUID.fromString(pathSplit[0]);
|
||||
if (!thisServerUUID.equals(serverUUID)) {
|
||||
continue;
|
||||
}
|
||||
path = pathSplit[1];
|
||||
} else {
|
||||
path = setting;
|
||||
}
|
||||
|
||||
String value = settingValSplit.length == 2 ? settingValSplit[1] : "";
|
||||
pathValueMap.put(path, value);
|
||||
}
|
||||
return pathValueMap;
|
||||
}
|
||||
|
||||
void placeToDatabase() {
|
||||
Map<String, Object> configValues = getConfigValues();
|
||||
|
||||
logger.debug("NetworkSettings: Building Base64 String..");
|
||||
StringBuilder transferBuilder = new StringBuilder();
|
||||
int size = configValues.size();
|
||||
int i = 0;
|
||||
for (Map.Entry<String, Object> entry : configValues.entrySet()) {
|
||||
String path = entry.getKey();
|
||||
String value = entry.getValue().toString();
|
||||
|
||||
transferBuilder.append(path).append(VAL_SPLIT).append(value);
|
||||
|
||||
if (i < size - 1) {
|
||||
transferBuilder.append(SPLIT);
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
String base64 = Base64Util.encode(transferBuilder.toString());
|
||||
|
||||
logger.debug("NetworkSettings: Saving Config settings to database..");
|
||||
dbSystem.get().getDatabase().transfer().storeConfigSettings(base64);
|
||||
}
|
||||
|
||||
private Map<String, Object> getConfigValues() {
|
||||
logger.debug("NetworkSettings: Loading Config Values..");
|
||||
Map<String, Object> configValues = new HashMap<>();
|
||||
addConfigValue(configValues, DatabaseSettings.TYPE, "mysql");
|
||||
Setting[] sameStrings = new Setting[]{
|
||||
DatabaseSettings.MYSQL_HOST,
|
||||
DatabaseSettings.MYSQL_USER,
|
||||
DatabaseSettings.MYSQL_PASS,
|
||||
DatabaseSettings.MYSQL_DATABASE,
|
||||
DatabaseSettings.MYSQL_LAUNCH_OPTIONS,
|
||||
FormatSettings.DECIMALS,
|
||||
FormatSettings.SECONDS,
|
||||
FormatSettings.DAY,
|
||||
FormatSettings.DAYS,
|
||||
FormatSettings.HOURS,
|
||||
FormatSettings.MINUTES,
|
||||
FormatSettings.MONTHS,
|
||||
FormatSettings.MONTH,
|
||||
FormatSettings.YEAR,
|
||||
FormatSettings.YEARS,
|
||||
FormatSettings.ZERO_SECONDS,
|
||||
TimeSettings.USE_SERVER_TIME,
|
||||
DisplaySettings.REPLACE_SESSION_ACCORDION_WITH_TABLE,
|
||||
DisplaySettings.SESSION_MOST_PLAYED_WORLD_IN_TITLE,
|
||||
DisplaySettings.ORDER_WORLD_PIE_BY_PERC,
|
||||
DisplaySettings.SESSIONS_PER_PAGE,
|
||||
DisplaySettings.PLAYERS_PER_SERVER_PAGE,
|
||||
DisplaySettings.PLAYERS_PER_PLAYERS_PAGE,
|
||||
FormatSettings.DATE_RECENT_DAYS,
|
||||
FormatSettings.DATE_RECENT_DAYS_PATTERN,
|
||||
FormatSettings.DATE_CLOCK,
|
||||
FormatSettings.DATE_NO_SECONDS,
|
||||
FormatSettings.DATE_FULL,
|
||||
DisplaySettings.PLAYER_IPS,
|
||||
TimeSettings.ACTIVE_LOGIN_THRESHOLD,
|
||||
TimeSettings.ACTIVE_PLAY_THRESHOLD,
|
||||
DisplaySettings.GAPS_IN_GRAPH_DATA,
|
||||
TimeSettings.AFK_THRESHOLD,
|
||||
DataGatheringSettings.GEOLOCATIONS,
|
||||
PluginSettings.KEEP_LOGS_DAYS,
|
||||
TimeSettings.KEEP_INACTIVE_PLAYERS,
|
||||
TimeSettings.PING_SERVER_ENABLE_DELAY,
|
||||
TimeSettings.PING_PLAYER_LOGIN_DELAY
|
||||
};
|
||||
logger.debug("NetworkSettings: Adding Config Values..");
|
||||
PlanConfig planConfig = config.get();
|
||||
for (Setting setting : sameStrings) {
|
||||
addConfigValue(configValues, setting, planConfig.get(setting));
|
||||
}
|
||||
addConfigValue(configValues, DatabaseSettings.MYSQL_PORT, planConfig.get(DatabaseSettings.MYSQL_PORT));
|
||||
addServerSpecificValues(configValues);
|
||||
return configValues;
|
||||
}
|
||||
|
||||
private void addConfigValue(Map<String, Object> configValues, Setting setting, Object value) {
|
||||
|
|
|
@ -35,7 +35,6 @@ import com.djrapitops.plan.system.database.databases.sql.SQLDB;
|
|||
import com.djrapitops.plan.system.database.databases.sql.tables.*;
|
||||
import com.djrapitops.plan.system.info.server.Server;
|
||||
import com.djrapitops.plan.system.settings.paths.WebserverSettings;
|
||||
import com.djrapitops.plan.utilities.Base64Util;
|
||||
import com.djrapitops.plan.utilities.SHA256Hash;
|
||||
import org.junit.*;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
@ -813,15 +812,8 @@ public abstract class CommonDBTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Not yet re-implemented")
|
||||
public void testSettingTransfer() {
|
||||
String testString = RandomData.randomString(100);
|
||||
|
||||
TransferTable transferTable = db.getTransferTable();
|
||||
transferTable.storeConfigSettings(Base64Util.encode(testString));
|
||||
Optional<String> configSettings = transferTable.getConfigSettings();
|
||||
|
||||
assertTrue(configSettings.isPresent());
|
||||
assertEquals(testString, Base64Util.decode(configSettings.get()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
package com.djrapitops.plan.system.settings.network;
|
||||
|
||||
import com.djrapitops.plan.api.exceptions.EnableException;
|
||||
import com.djrapitops.plan.system.PlanSystem;
|
||||
import com.djrapitops.plan.system.settings.paths.WebserverSettings;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.ClassRule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import rules.BukkitComponentMocker;
|
||||
import rules.ComponentMocker;
|
||||
import utilities.RandomData;
|
||||
|
||||
public class NetworkSettingsTest {
|
||||
|
||||
@ClassRule
|
||||
public static TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
@ClassRule
|
||||
public static ComponentMocker component = new BukkitComponentMocker(temporaryFolder);
|
||||
|
||||
private final int TEST_PORT_NUMBER = RandomData.randomInt(9005, 9500);
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownClass() {
|
||||
component.getPlanSystem().disable();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void transferDoesNotProduceException() throws EnableException {
|
||||
PlanSystem system = component.getPlanSystem();
|
||||
system.getConfigSystem().getConfig().set(WebserverSettings.PORT, TEST_PORT_NUMBER);
|
||||
system.enable();
|
||||
|
||||
NetworkSettings networkSettings = system.getConfigSystem().getConfig().getNetworkSettings();
|
||||
networkSettings.placeToDatabase();
|
||||
networkSettings.loadFromDatabase();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue