Докеризация, отказ от server.yml файлов, проброс .env
This commit is contained in:
@@ -2,8 +2,6 @@ package com.rosetta.im;
|
||||
|
||||
import com.rosetta.im.client.ClientManager;
|
||||
import com.rosetta.im.client.OnlineManager;
|
||||
import com.rosetta.im.config.Configuration;
|
||||
import com.rosetta.im.config.ServerConfiguration;
|
||||
import com.rosetta.im.event.EventManager;
|
||||
import com.rosetta.im.executors.Executor0Handshake;
|
||||
import com.rosetta.im.executors.Executor10RequestUpdate;
|
||||
@@ -73,8 +71,6 @@ public class Boot {
|
||||
private ServerAdapter serverAdapter;
|
||||
private ClientManager clientManager;
|
||||
private OnlineManager onlineManager;
|
||||
private Configuration configuration;
|
||||
private ServerConfiguration serverConfiguration;
|
||||
|
||||
/**
|
||||
* Конструктор по умолчанию, использует порт 3000 для сервера
|
||||
@@ -98,7 +94,6 @@ public class Boot {
|
||||
30
|
||||
), packetManager, this.serverAdapter);
|
||||
this.clientManager = new ClientManager(server);
|
||||
this.configuration = new Configuration("server.yml");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -139,7 +134,6 @@ public class Boot {
|
||||
*/
|
||||
public Boot bootstrap() {
|
||||
try{
|
||||
this.serverConfiguration = this.configuration.loadConfiguration();
|
||||
this.server.start();
|
||||
this.registerAllPackets();
|
||||
this.registerAllExecutors();
|
||||
@@ -196,9 +190,9 @@ public class Boot {
|
||||
this.packetManager.registerExecutor(4, new Executor4OnlineState(this.onlineManager, this.clientManager));
|
||||
this.packetManager.registerExecutor(6, new Executor6Message(this.clientManager, this.packetManager));
|
||||
this.packetManager.registerExecutor(7, new Executor7Read(this.clientManager, this.packetManager));
|
||||
this.packetManager.registerExecutor(10, new Executor10RequestUpdate(this.serverConfiguration));
|
||||
this.packetManager.registerExecutor(10, new Executor10RequestUpdate());
|
||||
this.packetManager.registerExecutor(11, new Executor11Typeing(this.clientManager, this.packetManager));
|
||||
this.packetManager.registerExecutor(15, new Executor15RequestTransport(this.serverConfiguration));
|
||||
this.packetManager.registerExecutor(15, new Executor15RequestTransport());
|
||||
this.packetManager.registerExecutor(16, new Executor16PushNotification());
|
||||
this.packetManager.registerExecutor(17, new Executor17GroupCreate());
|
||||
this.packetManager.registerExecutor(18, new Executor18GroupInfo());
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
package com.rosetta.im.config;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import org.yaml.snakeyaml.LoaderOptions;
|
||||
import org.yaml.snakeyaml.Yaml;
|
||||
|
||||
import com.rosetta.im.exception.ConfigurationException;
|
||||
|
||||
public class Configuration {
|
||||
|
||||
private String serverConfigName;
|
||||
|
||||
public Configuration(String serverConfigName) {
|
||||
this.serverConfigName = serverConfigName;
|
||||
}
|
||||
|
||||
public ServerConfiguration loadConfiguration() throws ConfigurationException, Exception {
|
||||
if(!Files.exists(Paths.get(this.serverConfigName))){
|
||||
/**
|
||||
* Файл конфигурации с переданным названием не найден
|
||||
*/
|
||||
throw new ConfigurationException(this.serverConfigName + " is missing");
|
||||
}
|
||||
|
||||
LoaderOptions options = new LoaderOptions();
|
||||
Yaml yaml = new Yaml(options);
|
||||
|
||||
InputStream inputStream = Files.newInputStream(Paths.get(this.serverConfigName));
|
||||
/**
|
||||
* SnakeYAML автоматически загрузит обьект ServerConfiguration через рефлексию
|
||||
* обратите внимание название полей в ServerConfiguration должны совпадать с названиями в
|
||||
* server.yml
|
||||
*/
|
||||
ServerConfiguration serverConfiguration = yaml.loadAs(inputStream, ServerConfiguration.class);
|
||||
return serverConfiguration;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
package com.rosetta.im.config;
|
||||
|
||||
public class DatabaseConfiguration {
|
||||
|
||||
public String host;
|
||||
public String user;
|
||||
public String password;
|
||||
public String db;
|
||||
|
||||
public String getHost() {
|
||||
return host;
|
||||
}
|
||||
|
||||
public void setHost(String host) {
|
||||
this.host = host;
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return user;
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getDb() {
|
||||
return db;
|
||||
}
|
||||
|
||||
public void setDb(String db) {
|
||||
this.db = db;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
package com.rosetta.im.config;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Этот файл отвечает за конфигурацию которая хранится в файле server.yml
|
||||
*/
|
||||
public class ServerConfiguration {
|
||||
|
||||
public DatabaseConfiguration database;
|
||||
|
||||
public List<String> transport_servers;
|
||||
|
||||
public List<String> update_servers;
|
||||
|
||||
public List<String> getUpdateServers() {
|
||||
return update_servers;
|
||||
}
|
||||
|
||||
public void setUpdateServers(List<String> update_servers) {
|
||||
this.update_servers = update_servers;
|
||||
}
|
||||
|
||||
public DatabaseConfiguration getDatabase() {
|
||||
return database;
|
||||
}
|
||||
|
||||
public void setDatabase(DatabaseConfiguration database) {
|
||||
this.database = database;
|
||||
}
|
||||
|
||||
public List<String> getTransportServers() {
|
||||
return transport_servers;
|
||||
}
|
||||
|
||||
public void setTransportServers(List<String> transport_servers) {
|
||||
this.transport_servers = transport_servers;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -9,8 +9,21 @@ public class HibernateUtil {
|
||||
|
||||
static {
|
||||
try {
|
||||
sessionFactory = new Configuration().configure().buildSessionFactory();
|
||||
Configuration cfg = new Configuration().configure();
|
||||
|
||||
String host = System.getenv("DB_HOST");
|
||||
String port = System.getenv("DB_PORT");
|
||||
String user = System.getenv("DB_USER");
|
||||
String pass = System.getenv("DB_PASSWORD");
|
||||
String name = System.getenv("DB_NAME");
|
||||
String url = String.format("jdbc:postgresql://%s:%s/%s", host, port, name);
|
||||
cfg.setProperty("hibernate.connection.url", url);
|
||||
cfg.setProperty("hibernate.connection.username", user);
|
||||
cfg.setProperty("hibernate.connection.password", pass);
|
||||
|
||||
sessionFactory = cfg.buildSessionFactory();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new ExceptionInInitializerError("Error initializing Hibernate: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package com.rosetta.im.executors;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.rosetta.im.config.ServerConfiguration;
|
||||
import com.rosetta.im.packet.Packet10RequestUpdate;
|
||||
import com.rosetta.im.util.RandomUtil;
|
||||
|
||||
@@ -17,12 +17,6 @@ import io.orprotocol.packet.PacketExecutor;
|
||||
*/
|
||||
public class Executor10RequestUpdate extends PacketExecutor<Packet10RequestUpdate> {
|
||||
|
||||
private ServerConfiguration serverConfiguration;
|
||||
|
||||
public Executor10RequestUpdate(ServerConfiguration serverConfiguration) {
|
||||
this.serverConfiguration = serverConfiguration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketReceived(Packet10RequestUpdate packet, Client client) throws Exception, ProtocolException {
|
||||
/**
|
||||
@@ -37,7 +31,7 @@ public class Executor10RequestUpdate extends PacketExecutor<Packet10RequestUpdat
|
||||
*
|
||||
* TODO: Логика проверки на доступность (health)
|
||||
*/
|
||||
List<String> cdnServers = this.serverConfiguration.getUpdateServers();
|
||||
List<String> cdnServers = Arrays.asList(System.getenv("SDU_SERVERS").split(","));
|
||||
String selectedServer = cdnServers.get(RandomUtil.randomBetween(0, cdnServers.size() - 1));
|
||||
packet.setServer(selectedServer);
|
||||
/**
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.rosetta.im.executors;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.rosetta.im.Failures;
|
||||
import com.rosetta.im.client.tags.ECIAuthentificate;
|
||||
import com.rosetta.im.config.ServerConfiguration;
|
||||
import com.rosetta.im.packet.Packet15RequestTransport;
|
||||
import com.rosetta.im.util.RandomUtil;
|
||||
|
||||
@@ -14,12 +14,6 @@ import io.orprotocol.packet.PacketExecutor;
|
||||
|
||||
public class Executor15RequestTransport extends PacketExecutor<Packet15RequestTransport> {
|
||||
|
||||
private ServerConfiguration serverConfiguration;
|
||||
|
||||
public Executor15RequestTransport(ServerConfiguration serverConfiguration){
|
||||
this.serverConfiguration = serverConfiguration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketReceived(Packet15RequestTransport packet, Client client) throws Exception, ProtocolException {
|
||||
ECIAuthentificate eciAuthentificate = client.getTag(ECIAuthentificate.class);
|
||||
@@ -36,7 +30,7 @@ public class Executor15RequestTransport extends PacketExecutor<Packet15RequestTr
|
||||
*
|
||||
* TODO: Логика проверки на доступность (health)
|
||||
*/
|
||||
List<String> cdnServers = this.serverConfiguration.getTransportServers();
|
||||
List<String> cdnServers = Arrays.asList(System.getenv("CDN_SERVERS").split(","));
|
||||
String selectedServer = cdnServers.get(RandomUtil.randomBetween(0, cdnServers.size() - 1));
|
||||
packet.setServer(selectedServer);
|
||||
/**
|
||||
|
||||
@@ -3,10 +3,6 @@
|
||||
<hibernate-configuration>
|
||||
<session-factory>
|
||||
<property name="hibernate.connection.driver_class">org.postgresql.Driver</property>
|
||||
<property name="hibernate.connection.url">jdbc:postgresql://localhost:5432/your_database</property>
|
||||
<property name="hibernate.connection.username">your_user</property>
|
||||
<property name="hibernate.connection.password">your_password</property>
|
||||
|
||||
<property name="hibernate.hbm2ddl.auto">update</property>
|
||||
<!--Зарегистрированные таблицы-->
|
||||
<mapping class="com.rosetta.im.database.entity.User"/>
|
||||
|
||||
Reference in New Issue
Block a user