diff --git a/config/examples/docker-compose/constants.env b/config/examples/docker-compose/constants.env new file mode 100644 index 0000000..22c85cd --- /dev/null +++ b/config/examples/docker-compose/constants.env @@ -0,0 +1,18 @@ +RABBITMQ_DEFAULT_USER=rabbit_user +RABBITMQ_DEFAULT_PASS=rabbit_pswrd +RABBIT_PORT=5672 +RABBIT_IP= +TORRENT_IP="[{\"ip\": \"\",\"port\": \"9093\"}, {\"name\": \"hdd\",\"ip\": \"\",\"port\": \"9092\"}]" + +BOT_TOKEN= +BOT_NAME= +BOT_TRUSTED_USERS= + +LONG_PAUSE_MILIS=10000 +MEDIUM_PAUSE_MILIS=5000 +SMALL_PAUSE_MILIS=500 + +PING=/ping +PONG=pong + +LOGS_LEVEL=info \ No newline at end of file diff --git a/config/examples/docker-compose/constants.yml b/config/examples/docker-compose/constants.yml deleted file mode 100644 index cf30f07..0000000 --- a/config/examples/docker-compose/constants.yml +++ /dev/null @@ -1,19 +0,0 @@ -common-variables: &common-variables - RABBITMQ_DEFAULT_USER: rabbit_user - RABBITMQ_DEFAULT_PASS: rabbit_pswrd - RABBIT_PORT: 5672 - RABBIT_IP: - BOT_NAME: - BOT_TRUSTED_USERS: - - LONG_PAUSE_MILIS: 10000 - MEDIUM_PAUSE_MILIS: 5000 - SMALL_PAUSE_MILIS: 500 - - PING: /ping - PONG: pong - - LOGS_LEVEL: info \ No newline at end of file diff --git a/config/examples/docker-compose/docker-compose-bot.yml b/config/examples/docker-compose/docker-compose-bot.yml index 93e803e..260a8e1 100644 --- a/config/examples/docker-compose/docker-compose-bot.yml +++ b/config/examples/docker-compose/docker-compose-bot.yml @@ -1,13 +1,10 @@ version: '3.7' -x-common-variables: &common-variables - extends: - file: constants.yml - service: common-variables services: torrent: image: halushko/cinema-torrent:alpha - environment: *common-variables + env_file: + - constants.env restart: always container_name: "torrent" volumes: @@ -17,7 +14,8 @@ services: network_mode: host bot: image: halushko/cinema-bot:alpha - environment: *common-variables + env_file: + - constants.env restart: always container_name: "bot" volumes: @@ -26,7 +24,8 @@ services: bot_network_local: text: image: halushko/cinema-text:alpha - environment: *common-variables + env_file: + - constants.env restart: always container_name: "text" volumes: @@ -35,7 +34,8 @@ services: bot_network_local: file: image: halushko/cinema-file:alpha - environment: *common-variables + env_file: + - constants.env restart: always container_name: "file" volumes: diff --git a/config/examples/docker-compose/docker-compose-bot_debug.yml b/config/examples/docker-compose/docker-compose-bot_debug.yml index 07a3a76..2d35aec 100644 --- a/config/examples/docker-compose/docker-compose-bot_debug.yml +++ b/config/examples/docker-compose/docker-compose-bot_debug.yml @@ -1,47 +1,47 @@ version: '3.7' -x-common-variables: &common-variables - extends: - file: constants.yml - service: common-variables services: - torrent_debug: - image: halushko/cinema-torrent:beta - environment: *common-variables - restart: always - container_name: "torrent_debug" - volumes: - - ./workdir/config/transmission:/home/app/transmission_config - - ./workdir/config/logs:/home/app/logs - network_mode: host +# torrent_debug: +# image: halushko/cinema-torrent:beta +# env_file: +# - constants.env +# restart: always +# container_name: "torrent_debug" +# volumes: +# - ./workdir/config/transmission:/home/app/transmission_config +# - ./workdir/config/logs:/home/app/logs +# network_mode: host bot_debug: image: halushko/cinema-bot:beta - environment: *common-variables + env_file: + - constants.env restart: always container_name: "bot_debug" volumes: - ./workdir/config/logs:/home/app/logs networks: - at_private_network_debug: + bot_network_debug: text_debug: image: halushko/cinema-text:beta - environment: *common-variables + env_file: + - constants.env restart: always container_name: "text_debug" volumes: - ./workdir/config/logs:/home/app/logs networks: - at_private_network_debug: + bot_network_debug: file_debug: image: halushko/cinema-file:beta - environment: *common-variables + env_file: + - constants.env restart: always container_name: "file_debug" volumes: - ./workdir/config/files_from_telegram:/home/torrent_files/ - ./workdir/config/logs:/home/app/logs networks: - at_private_network_debug: + bot_network_debug: networks: bot_network_debug: driver: bridge \ No newline at end of file diff --git a/config/examples/docker-compose/docker-compose-media.yml b/config/examples/docker-compose/docker-compose-media.yml index ce22a2e..eff1465 100644 --- a/config/examples/docker-compose/docker-compose-media.yml +++ b/config/examples/docker-compose/docker-compose-media.yml @@ -11,7 +11,7 @@ services: - VERSION=docker volumes: - ./workdir/config/plex/config:/config - - ./workdir/mediadata:/movies/local - - ./workdir/mediadata_hdd:/movies/hdd + - ./workdir/mediadata:/movies +# - ./workdir/mediadata_hdd:/movies/hdd restart: unless-stopped network_mode: host \ No newline at end of file diff --git a/config/examples/etc/systemd/services/bot_debug_down.service b/config/examples/etc/systemd/services/bot-debug-down.service similarity index 100% rename from config/examples/etc/systemd/services/bot_debug_down.service rename to config/examples/etc/systemd/services/bot-debug-down.service diff --git a/config/examples/etc/systemd/services/bot_down.service b/config/examples/etc/systemd/services/bot-down.service similarity index 89% rename from config/examples/etc/systemd/services/bot_down.service rename to config/examples/etc/systemd/services/bot-down.service index 6540812..34fe37c 100644 --- a/config/examples/etc/systemd/services/bot_down.service +++ b/config/examples/etc/systemd/services/bot-down.service @@ -1,7 +1,7 @@ [Unit] Description=Shut down Bot Requires=docker.service -After=message_broker.service +After=message-broker.service [Service] Type=oneshot diff --git a/config/examples/etc/systemd/services/bot_pull.service b/config/examples/etc/systemd/services/bot-pull.service similarity index 91% rename from config/examples/etc/systemd/services/bot_pull.service rename to config/examples/etc/systemd/services/bot-pull.service index 6de058e..de62278 100644 --- a/config/examples/etc/systemd/services/bot_pull.service +++ b/config/examples/etc/systemd/services/bot-pull.service @@ -1,7 +1,7 @@ [Unit] Description=Bot update Requires=docker.service -After=bot_down.service +After=bot-down.service [Service] Type=oneshot diff --git a/config/examples/etc/systemd/services/bot.service b/config/examples/etc/systemd/services/bot.service index 59a4fe5..0a983fd 100644 --- a/config/examples/etc/systemd/services/bot.service +++ b/config/examples/etc/systemd/services/bot.service @@ -1,7 +1,7 @@ [Unit] Description=Bot start -Requires=message_broker.service -After=bot_pull.service +Requires=docker.service +After=bot-pull.service [Service] Type=oneshot diff --git a/config/examples/etc/systemd/services/create_services.sh b/config/examples/etc/systemd/services/create_services.sh index 7597d6f..b6f3771 100644 --- a/config/examples/etc/systemd/services/create_services.sh +++ b/config/examples/etc/systemd/services/create_services.sh @@ -1,35 +1,35 @@ #!/bin/bash systemctl stop bot.service -systemctl stop bot_debug_down.service -systemctl stop bot_down.service -systemctl stop bot_pull.service -systemctl stop media_server.service -systemctl stop media_server_down.service -systemctl stop media_server_pull.service -systemctl stop message_broker.service -systemctl stop message_broker_down.service -systemctl stop message_broker_pull.service +systemctl stop bot-debug-down.service +systemctl stop bot-down.service +systemctl stop bot-pull.service +systemctl stop media-server.service +systemctl stop media-server-down.service +systemctl stop media-server-pull.service +systemctl stop message-broker.service +systemctl stop message-broker-down.service +systemctl stop message-broker-pull.service systemctl stop torrent.service -systemctl stop torrent_down.service -systemctl stop torrent_pull.service +systemctl stop torrent-down.service +systemctl stop torrent-pull.service systemctl stop torrent-hdd.service systemctl stop torrent-hdd-down.service systemctl stop torrent-hdd-pull.service systemctl disable bot.service -systemctl disable bot_debug_down.service -systemctl disable bot_down.service -systemctl disable bot_pull.service -systemctl disable media_server.service -systemctl disable media_server_down.service -systemctl disable media_server_pull.service -systemctl disable message_broker.service -systemctl disable message_broker_down.service -systemctl disable message_broker_pull.service +systemctl disable bot-debug-down.service +systemctl disable bot-down.service +systemctl disable bot-pull.service +systemctl disable media-server.service +systemctl disable media-server-down.service +systemctl disable media-server-pull.service +systemctl disable message-broker.service +systemctl disable message-broker-down.service +systemctl disable message-broker-pull.service systemctl disable torrent.service -systemctl disable torrent_down.service -systemctl disable torrent_pull.service +systemctl disable torrent-down.service +systemctl disable torrent-pull.service systemctl disable torrent-hdd.service systemctl disable torrent-hdd-down.service systemctl disable torrent-hdd-pull.service @@ -37,18 +37,18 @@ systemctl disable torrent-hdd-pull.service cp -f *.service /etc/systemd/system systemctl enable bot.service -systemctl enable bot_debug_down.service -systemctl enable bot_down.service -systemctl enable bot_pull.service -systemctl enable media_server.service -systemctl enable media_server_down.service -systemctl enable media_server_pull.service -systemctl enable message_broker.service -systemctl enable message_broker_down.service -systemctl enable message_broker_pull.service +systemctl enable bot-debug-down.service +systemctl enable bot-down.service +systemctl enable bot-pull.service +systemctl enable media-server.service +systemctl enable media-server-down.service +systemctl enable media-server-pull.service +systemctl enable message-broker.service +systemctl enable message-broker-down.service +systemctl enable message-broker-pull.service systemctl enable torrent.service -systemctl enable torrent_down.service -systemctl enable torrent_pull.service +systemctl enable torrent-down.service +systemctl enable torrent-pull.service systemctl enable torrent-hdd.service systemctl enable torrent-hdd-down.service systemctl enable torrent-hdd-pull.service \ No newline at end of file diff --git a/config/examples/etc/systemd/services/media_server_down.service b/config/examples/etc/systemd/services/media-server-down.service similarity index 100% rename from config/examples/etc/systemd/services/media_server_down.service rename to config/examples/etc/systemd/services/media-server-down.service diff --git a/config/examples/etc/systemd/services/media_server_pull.service b/config/examples/etc/systemd/services/media-server-pull.service similarity index 89% rename from config/examples/etc/systemd/services/media_server_pull.service rename to config/examples/etc/systemd/services/media-server-pull.service index c9d530c..b50685c 100644 --- a/config/examples/etc/systemd/services/media_server_pull.service +++ b/config/examples/etc/systemd/services/media-server-pull.service @@ -1,7 +1,7 @@ [Unit] Description=Media server update Requires=docker.service -After=media_server_down.service +After=media-server-down.service [Service] Type=oneshot diff --git a/config/examples/etc/systemd/services/media_server.service b/config/examples/etc/systemd/services/media-server.service similarity index 91% rename from config/examples/etc/systemd/services/media_server.service rename to config/examples/etc/systemd/services/media-server.service index 50b299a..a157bc1 100644 --- a/config/examples/etc/systemd/services/media_server.service +++ b/config/examples/etc/systemd/services/media-server.service @@ -1,7 +1,7 @@ [Unit] Description=Media server start Requires=docker.service -After=media_server_pull.service +After=media-server-pull.service [Service] Type=oneshot diff --git a/config/examples/etc/systemd/services/message_broker_down.service b/config/examples/etc/systemd/services/message-broker-down.service similarity index 100% rename from config/examples/etc/systemd/services/message_broker_down.service rename to config/examples/etc/systemd/services/message-broker-down.service diff --git a/config/examples/etc/systemd/services/message_broker_pull.service b/config/examples/etc/systemd/services/message-broker-pull.service similarity index 88% rename from config/examples/etc/systemd/services/message_broker_pull.service rename to config/examples/etc/systemd/services/message-broker-pull.service index 7aa7df0..64dba12 100644 --- a/config/examples/etc/systemd/services/message_broker_pull.service +++ b/config/examples/etc/systemd/services/message-broker-pull.service @@ -1,7 +1,7 @@ [Unit] Description=Message brocker Service Requires=docker.service -After=message_broker_down.service +After=message-broker-down.service [Service] Type=oneshot diff --git a/config/examples/etc/systemd/services/message_broker.service b/config/examples/etc/systemd/services/message-broker.service similarity index 90% rename from config/examples/etc/systemd/services/message_broker.service rename to config/examples/etc/systemd/services/message-broker.service index 6264c74..013cfe6 100644 --- a/config/examples/etc/systemd/services/message_broker.service +++ b/config/examples/etc/systemd/services/message-broker.service @@ -1,7 +1,7 @@ [Unit] Description=Message broker start Requires=docker.service -After=message_broker_pull.service +After=message-broker-pull.service [Service] Type=oneshot diff --git a/config/examples/etc/systemd/services/torrent_down.service b/config/examples/etc/systemd/services/torrent-down.service similarity index 100% rename from config/examples/etc/systemd/services/torrent_down.service rename to config/examples/etc/systemd/services/torrent-down.service diff --git a/config/examples/etc/systemd/services/torrent-hdd-pull.service b/config/examples/etc/systemd/services/torrent-hdd-pull.service index ae9b9ba..91cef96 100644 --- a/config/examples/etc/systemd/services/torrent-hdd-pull.service +++ b/config/examples/etc/systemd/services/torrent-hdd-pull.service @@ -1,7 +1,7 @@ [Unit] Description=Torrent update Requires=docker.service -After=torrent_down.service +After=torrent-hdd-down.service [Service] Type=oneshot diff --git a/config/examples/etc/systemd/services/torrent-hdd.service b/config/examples/etc/systemd/services/torrent-hdd.service index e0c5ce2..b8db45b 100644 --- a/config/examples/etc/systemd/services/torrent-hdd.service +++ b/config/examples/etc/systemd/services/torrent-hdd.service @@ -1,7 +1,7 @@ [Unit] Description=Torrent start Requires=docker.service -After=bot.service +After=torrent-hdd-pull.service [Service] Type=oneshot diff --git a/config/examples/etc/systemd/services/torrent_pull.service b/config/examples/etc/systemd/services/torrent-pull.service similarity index 90% rename from config/examples/etc/systemd/services/torrent_pull.service rename to config/examples/etc/systemd/services/torrent-pull.service index a1c36f4..bd395ca 100644 --- a/config/examples/etc/systemd/services/torrent_pull.service +++ b/config/examples/etc/systemd/services/torrent-pull.service @@ -1,7 +1,7 @@ [Unit] Description=Torrent update Requires=docker.service -After=torrent_down.service +After=torrent-down.service [Service] Type=oneshot diff --git a/config/examples/etc/systemd/services/torrent.service b/config/examples/etc/systemd/services/torrent.service index 17b36c1..afb44fb 100644 --- a/config/examples/etc/systemd/services/torrent.service +++ b/config/examples/etc/systemd/services/torrent.service @@ -1,7 +1,7 @@ [Unit] Description=Torrent start Requires=docker.service -After=bot.service +After=torrent-pull.service [Service] Type=oneshot diff --git a/core/src/main/java/com/halushko/kinocat/core/web/InputMessageHandlerApiRequest.java b/core/src/main/java/com/halushko/kinocat/core/web/InputMessageHandlerApiRequest.java index b509cf8..a36e26f 100644 --- a/core/src/main/java/com/halushko/kinocat/core/web/InputMessageHandlerApiRequest.java +++ b/core/src/main/java/com/halushko/kinocat/core/web/InputMessageHandlerApiRequest.java @@ -19,7 +19,7 @@ @SuppressWarnings("unused") @Slf4j public abstract class InputMessageHandlerApiRequest extends InputMessageHandler { - private final Map serverUrls = new LinkedHashMap<>(); + protected final Map serverUrls = new LinkedHashMap<>(); public InputMessageHandlerApiRequest(String protocol, String ip, int port, String suffix) { this.serverUrls.put("default", String.format("%s://%s:%s/%s", protocol, ip, port, suffix)); @@ -33,12 +33,12 @@ public InputMessageHandlerApiRequest(String urls) { .map((x -> (Map) x)) .forEach( x -> this.serverUrls.put( - String.valueOf(x.containsValue("name") ? x.get("name") : "default"), + String.valueOf(x.getOrDefault("name", "default")), String.format("%s://%s:%s/%s", - x.containsValue("protocol") ? x.get("protocol") : "http", - x.get("ip"), - x.get("port"), - x.containsValue("suffix") ? x.get("suffix") : "transmission/rpc" + x.getOrDefault("protocol", "http"), + x.getOrDefault("ip", "localhost"), + x.getOrDefault("port", "9091"), + x.getOrDefault("suffix", "transmission/rpc") ) ) ); diff --git a/torrent/src/main/java/com/halushko/kinocat/torrent/requests/common/TransmissionWebApiExecutor.java b/torrent/src/main/java/com/halushko/kinocat/torrent/requests/common/TransmissionWebApiExecutor.java index 1cd3777..e3c4603 100644 --- a/torrent/src/main/java/com/halushko/kinocat/torrent/requests/common/TransmissionWebApiExecutor.java +++ b/torrent/src/main/java/com/halushko/kinocat/torrent/requests/common/TransmissionWebApiExecutor.java @@ -16,10 +16,11 @@ public abstract class TransmissionWebApiExecutor extends InputMessageHandlerApiRequest { private final static Map sessionIdValues = new HashMap<>(); protected final static String sessionIdKey = "X-Transmission-Session-Id"; - public static final String TRANSMISSION_IP = System.getenv("TORRENT_IP"); + public static final String TRANSMISSION_IP = "[{\"ip\": \"192.168.50.132\",\"port\": \"9093\"}, {\"name\": \"hdd\",\"ip\": \"192.168.50.132\",\"port\": \"9092\"}]";//System.getenv("TORRENT_IP"); public TransmissionWebApiExecutor() { super(TRANSMISSION_IP); + serverUrls.keySet().forEach(x -> sessionIdValues.put(x, null)); } @Override @@ -33,8 +34,8 @@ protected final String getDeliverCallbackPrivate(SmartJson message) { //new session log.debug("[getDeliverCallbackPrivate] Create a new session"); - val responce = send("", "Content-Type", "application/json", ""); - TransmissionWebApiExecutor.sessionIdValues.put(session.getKey(), responce.getHeader(sessionIdKey)); + val responce = send(session.getKey(), "Content-Type", "application/json", ""); + sessionIdValues.put(session.getKey(), responce.getHeader(sessionIdKey)); } String requestBodyFormat = ResourceReader.readResourceContent(String.format("transmission_requests/%s", getRequest())); Object[] requestBodyFormatArguments = getRequestArguments(message.getSubMessage(SmartJson.KEYS.COMMAND_ARGUMENTS)); @@ -42,7 +43,7 @@ protected final String getDeliverCallbackPrivate(SmartJson message) { String requestBody = String.format(requestBodyFormat, requestBodyFormatArguments); log.debug("[getDeliverCallbackPrivate] Request body:\n{}", requestBody); - ApiResponce responce = send(requestBody, session.getKey(), "Content-Type", "application/json", sessionIdKey, session.getValue()); + ApiResponce responce = send(session.getKey(), requestBody, session.getKey(), "Content-Type", "application/json", sessionIdKey, session.getValue()); String responceBody = responce.getBody(); if (responceBody.contains("409: Conflict")) { //expired session