Skip to content
Snippets Groups Projects
Commit 1b08a053 authored by Ondřej Trojan's avatar Ondřej Trojan
Browse files

config edit, config functionality

parent 80257abb
No related branches found
No related tags found
No related merge requests found
......@@ -15,7 +15,7 @@ public class VlcClient implements RemoteClient {
private static final int SOCKET_TIMEOUT = 900;
private static final int SOCKET_SINGLE_TIMEOUT = 200;
private static final int SOCKET_TIMEOUT_LIMIT = 1;
private static final String[] STARTUP_RESPONSE = {"VLC media player 3.0.10 Vetinari", "Command Line Interface initialized. Type `help' for help."};
private static String[] STARTUP_RESPONSE = {"VLC media player 3.0.10 Vetinari", "Command Line Interface initialized. Type `help' for help."};
private static final String PLAYLIST_END = "+----[ End of playlist ]";
private static final String WAITING_COMMAND = "> ";
private static final String IS_PLAYING_TRUE = "> 1";
......@@ -36,6 +36,7 @@ public class VlcClient implements RemoteClient {
private final String ip;
private final int port;
private final int id;
private final boolean vlcVersionCheck;
@Override
......@@ -54,10 +55,11 @@ public class VlcClient implements RemoteClient {
}
public VlcClient(String address, int port, int id) {
public VlcClient(String address, int port, int id, boolean vlcVersionCheck) {
this.ip = address;
this.port = port;
this.id = id;
this.vlcVersionCheck = vlcVersionCheck;
}
private void startConnection() throws InterruptedException {
......@@ -92,7 +94,7 @@ public class VlcClient implements RemoteClient {
line = in.readLine();
log.info("start_" + line);
received.add(line);
responseOk &= received.get(i).equals(STARTUP_RESPONSE[i]);
if(vlcVersionCheck || i != 0) responseOk &= received.get(i).equals(STARTUP_RESPONSE[i]);
}
String next = Character.toString((char) in.read()) + Character.toString((char) in.read());
received.add(next);
......@@ -252,7 +254,7 @@ public class VlcClient implements RemoteClient {
if (!next.equals(WAITING_COMMAND)) {
log.error("Not received next command character");
}
log.info("Send " + msg + " received in " + (System.currentTimeMillis() - start) + "ms " + Arrays.toString(resp.toArray()));
log.debug("Send " + msg + " received in " + (System.currentTimeMillis() - start) + "ms " + Arrays.toString(resp.toArray()));
return resp;
}
......
......@@ -12,9 +12,13 @@ public class CustomConfig {
private String playlistFolderPath;
private String videoFolderPath;
private Boolean vlcVersionCheck;
private Boolean queryAll;
private List<String> clientIps = new ArrayList<>();
private List<Integer> clientVlcPorts = new ArrayList<>();
private List<Integer> clientSshPorts = new ArrayList<>();
private List<String> clientUsername = new ArrayList<>();
private List<String> clientPasswords = new ArrayList<>();
private boolean enableVlcScheduling = true;
private int clientCount;
......@@ -87,4 +91,44 @@ public class CustomConfig {
public void setClientSshPorts(List<Integer> clientSshPorts) {
this.clientSshPorts = clientSshPorts;
}
public List<String> getClientPasswords() {
return clientPasswords;
}
public void setClientPasswords(List<String> clientPasswords) {
this.clientPasswords = clientPasswords;
}
public String getClientPassword(int client){
return clientPasswords.get(client);
}
public Boolean getVlcVersionCheck() {
return vlcVersionCheck;
}
public void setVlcVersionCheck(Boolean vlcVersionCheck) {
this.vlcVersionCheck = vlcVersionCheck;
}
public List<String> getClientUsername() {
return clientUsername;
}
public String getClientUsername(int client){
return clientUsername.get(client);
}
public void setClientUsername(List<String> clientUsername) {
this.clientUsername = clientUsername;
}
public Boolean getQueryAll() {
return queryAll;
}
public void setQueryAll(Boolean queryAll) {
this.queryAll = queryAll;
}
}
......@@ -29,7 +29,7 @@ public class VlcConfig {
List<RemoteClient> clients = new ArrayList<>();
for (int i = 0; i < propertiesConfig.getClientCount(); i++) {
System.out.println("Creating bean for vlcClient " + i);
clients.add(new VlcClient(propertiesConfig.getIp(i), propertiesConfig.getVlcPort(i), i));
clients.add(new VlcClient(propertiesConfig.getIp(i), propertiesConfig.getVlcPort(i), i, propertiesConfig.getVlcVersionCheck()));
}
return clients;
}
......
......@@ -56,37 +56,49 @@ public class ClientService {
@Scheduled(fixedRate = 200)
private void maintainCheck() throws InterruptedException {
if (connectedClient == Integer.MAX_VALUE || !controlService.isConnected(connectedClient)) {
//connect
currentTrack = ""; //nobody connected
connectedClient = Integer.MAX_VALUE;
if (config.getQueryAll()) {
for (int i = 0; i < config.getClientCount(); i++) {
if (controlService.isConnected(i)) {
connectedClient = i;
break;
}
querySingleClient(i);
}
if (connectedClient == Integer.MAX_VALUE) {
log.info("Cannot find client to connect");
return;
} else {
if (connectedClient == Integer.MAX_VALUE || !controlService.isConnected(connectedClient)) {
//connect
currentTrack = ""; //nobody connected
connectedClient = Integer.MAX_VALUE;
for (int i = 0; i < config.getClientCount(); i++) {
if (controlService.isConnected(i)) {
connectedClient = i;
break;
}
}
if (connectedClient == Integer.MAX_VALUE) {
log.info("Cannot find client to connect");
return;
}
}
querySingleClient(connectedClient);
}
currentTime = controlService.getTime(connectedClient);
}
private void querySingleClient(int clientId) {
currentTime = controlService.getTime(clientId);
long end = System.currentTimeMillis();
currentTrack = controlService.getTitle(connectedClient);
currentTrack = controlService.getTitle(clientId);
if (currentTrack == null || currentTrack.equals("")) {
log.info("No title to parse, title equals empty or null string");
log.info("Client " + clientId + ": No title to parse, title equals empty or null string");
return;
}
String[] split = currentTrack.split("-");
if (split.length != 3) {
log.error("Title " + currentTrack + " cannot be splitted to 3 items");
log.error("Client " + clientId + ": Title " + currentTrack + " cannot be splitted to 3 items");
return;
}
// DisplaySet
ResponseData<DisplaySetDto> displaySet = displaySetService.getDisplaySetById(split[0]);
if (displaySet.getData() == null) {
log.error("Cannot find displaySet with id " + split[0]);
log.error("Client " + clientId + ": Cannot find displaySet with id " + split[0]);
return;
}
currentDisplaySetName = displaySet.getData().getName();
......@@ -94,14 +106,13 @@ public class ClientService {
// DisplayTrack
ResponseData<DisplayTrackDto> displayTrack = displayTrackService.getDisplayTrackById(split[1]);
if (displayTrack.getData() == null) {
log.error("Cannot find displayTrack with id " + split[1]);
log.error("Client " + clientId + ": Cannot find displayTrack with id " + split[1]);
return;
}
if (!currentDisplayTrackId.equals(displayTrack.getData().getId()) || currentPlaylistTracks.isEmpty()) {
//check playlist
// List<String> displayTracks = new ArrayList<>();
List<ParsedPlaylistTrack> displayTracks = new ArrayList<>();
List<ParsedPlaylistTrack> tracks = playlistService.parseTitlesPlaylist(controlService.getPlaylist(connectedClient));
List<ParsedPlaylistTrack> tracks = playlistService.parseTitlesPlaylist(controlService.getPlaylist(clientId));
for (ParsedPlaylistTrack parsedTrack : tracks) {
ResponseData<DisplayTrackDto> displayTrackFromParsed = displayTrackService.getDisplayTrackById(parsedTrack.getName().split("-")[1]);
if (displayTrackFromParsed.getData() == null) {
......@@ -116,8 +127,7 @@ public class ClientService {
currentDisplayTrackId = displayTrack.getData().getId();
currentDisplayTrackName = displayTrack.getData().getName();
}
currentTrackLength = controlService.getLength(connectedClient);
//parse
currentTrackLength = controlService.getLength(clientId);
log.debug(LocalDateTime.now().toString() + " " + currentDisplaySetName + ", " + currentDisplayTrackName + ", " + split[2]);
}
......
......@@ -105,20 +105,21 @@ public class ControlService {
public String getTitle(int clientId) {
String command = "get_title";
List<String> ret = sendCommand(getRemoteClient(clientId), command);
if (ret == null || ret.isEmpty()) return "";
return ret.get(0);
}
public int getTime(int clientId) {
String command = "get_time";
List<String> ret = sendCommand(getRemoteClient(clientId), command);
if (ret.isEmpty() || ret.get(0).equals("")) return 0;
if (ret == null || ret.isEmpty() || ret.get(0).equals("")) return 0;
return Integer.parseInt(ret.get(0).replaceAll("\\s+", ""));
}
public int getLength(int clientId) {
String command = "get_length";
List<String> ret = sendCommand(getRemoteClient(clientId), command);
if (ret.isEmpty() || ret.get(0).equals("")) return 0;
if (ret == null || ret.isEmpty() || ret.get(0).equals("")) return 0;
return Integer.parseInt(ret.get(0));
}
......
......@@ -12,10 +12,7 @@ import org.springframework.integration.sftp.session.SftpSession;
import org.springframework.stereotype.Service;
import java.io.*;
import java.util.ArrayDeque;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;
@Service
......@@ -33,8 +30,8 @@ public class SynchronizationService {
factory.setHost(config.getIp(client));
factory.setPort(config.getSshPort(client));
factory.setAllowUnknownKeys(true);
factory.setUser("user");
factory.setPassword(client == 2 ? "prahaKrasna.12" : "user");
factory.setUser(config.getClientUsername(client));
factory.setPassword(config.getClientPassword(client));
return factory;
}
......@@ -45,7 +42,6 @@ public class SynchronizationService {
this.videofileService = videofileService;
}
// @Async
public ResponseData<Boolean> synchronizeAll() {
System.out.println(config.getClientIps().get(0));
......@@ -56,7 +52,6 @@ public class SynchronizationService {
}
return new ResponseData<>(true);
}
private ResponseData<Boolean> synchronizeClient(int clientId) {
boolean errorFree = true;
SftpSession session;
......@@ -80,8 +75,6 @@ public class SynchronizationService {
errorFree &= uploadFile(clientId, session, dest, file);
}
// remove all data on remote??
File videoFolder = new File(config.getVideoFolderPath());
if (!videoFolder.exists() || !videoFolder.isDirectory()) {
......@@ -112,7 +105,7 @@ public class SynchronizationService {
}
}
session.close();
if(!errorFree) return new ResponseData<>(false , "Some errors occurred, see log file for details");
if (!errorFree) return new ResponseData<>(false, "Some errors occurred, see log file for details");
return new ResponseData<>(true);
}
......
......@@ -29,21 +29,26 @@ app:
5d:
videoFolderPath: /home/otrojan/vid/
playlistFolderPath: /home/otrojan/playlists/
vlcVersionCheck: false
queryAll: true #all/first
scheduling:
enabled: true
clientCount: 2
clientIps:
- 127.0.0.1
# - 127.0.0.1
- 192.168.0.110
- 192.168.0.113
- 192.168.0.112
clientVlcPorts:
- 5041
# - 5051
- 5061
- 5091
- 5081
clientSshPorts:
- 2222
# - 2224
- 22
- 22
clientUsername:
- user
- user
clientPasswords:
- prahaKrasna.12
- prahaKrasna.12
################5D-projection-security###################
......
......@@ -11,7 +11,7 @@
<div layout:fragment="content_videoedit">
<h1>Video set</h1>
<p>Video set is a set of video tracks</p>
<form class="card" th:classappend="${somethingIsPublished} ? bg-info : ''" th:method="post"
<form class="card" th:classappend="${somethingIsPublished} ? bg-secondary : ''" th:method="post"
th:action="@{/control/videoedit/videoset/synchronize}">
<div class="card-body">
<h3 th:if="${somethingIsPublished}">You have a set to synchronize!</h3>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment