mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: new class KmsProperties refactoring
parent
a8ffe78411
commit
7d6cbeb049
|
@ -26,15 +26,16 @@ import org.kurento.commons.exception.KurentoException;
|
||||||
public class FixedOneKmsManager extends KmsManager {
|
public class FixedOneKmsManager extends KmsManager {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Kms> initializeKurentoClients(List<String> kmsUris, boolean disconnectUponFailure) throws Exception {
|
public List<Kms> initializeKurentoClients(List<KmsProperties> kmsProperties, boolean disconnectUponFailure)
|
||||||
final String kmsUri = kmsUris.get(0);
|
throws Exception {
|
||||||
|
KmsProperties firstProps = kmsProperties.get(0);
|
||||||
KurentoClient kClient = null;
|
KurentoClient kClient = null;
|
||||||
Kms kms = new Kms(kmsUri, loadManager);
|
Kms kms = new Kms(firstProps, loadManager);
|
||||||
this.addKms(kms);
|
this.addKms(kms);
|
||||||
try {
|
try {
|
||||||
kClient = KurentoClient.create(kmsUri, this.generateKurentoConnectionListener(kms.getId()));
|
kClient = KurentoClient.create(firstProps.getUri(), this.generateKurentoConnectionListener(kms.getId()));
|
||||||
} catch (KurentoException e) {
|
} catch (KurentoException e) {
|
||||||
log.error("KMS in {} is not reachable by OpenVidu Server", kmsUri);
|
log.error("KMS in {} is not reachable by OpenVidu Server", firstProps.getUri());
|
||||||
if (kClient != null) {
|
if (kClient != null) {
|
||||||
kClient.destroy();
|
kClient.destroy();
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.concurrent.atomic.AtomicLong;
|
import java.util.concurrent.atomic.AtomicLong;
|
||||||
|
|
||||||
import org.apache.commons.lang3.RandomStringUtils;
|
|
||||||
import org.kurento.client.KurentoClient;
|
import org.kurento.client.KurentoClient;
|
||||||
import org.kurento.client.ModuleInfo;
|
import org.kurento.client.ModuleInfo;
|
||||||
import org.kurento.client.ServerInfo;
|
import org.kurento.client.ServerInfo;
|
||||||
|
@ -64,9 +63,9 @@ public class Kms {
|
||||||
|
|
||||||
private Map<String, KurentoSession> kurentoSessions = new ConcurrentHashMap<>();
|
private Map<String, KurentoSession> kurentoSessions = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public Kms(String uri, LoadManager loadManager) {
|
public Kms(KmsProperties props, LoadManager loadManager) {
|
||||||
this.uri = uri;
|
this.id = props.getId();
|
||||||
this.id = "KMS-" + RandomStringUtils.randomAlphanumeric(6).toUpperCase();
|
this.uri = props.getUri();
|
||||||
|
|
||||||
String parsedUri = uri.replaceAll("^ws://", "http://").replaceAll("^wss://", "https://");
|
String parsedUri = uri.replaceAll("^ws://", "http://").replaceAll("^wss://", "https://");
|
||||||
URL url = null;
|
URL url = null;
|
||||||
|
|
|
@ -28,6 +28,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
import javax.annotation.PreDestroy;
|
import javax.annotation.PreDestroy;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.RandomStringUtils;
|
||||||
import org.kurento.client.KurentoConnectionListener;
|
import org.kurento.client.KurentoConnectionListener;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -184,13 +185,19 @@ public abstract class KmsManager {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract List<Kms> initializeKurentoClients(List<String> kmsUris, boolean disconnectUponFailure)
|
public abstract List<Kms> initializeKurentoClients(List<KmsProperties> kmsProperties, boolean disconnectUponFailure)
|
||||||
throws Exception;
|
throws Exception;
|
||||||
|
|
||||||
@PostConstruct
|
@PostConstruct
|
||||||
private void postConstruct() {
|
private void postConstruct() {
|
||||||
try {
|
try {
|
||||||
this.initializeKurentoClients(this.openviduConfig.getKmsUris(), true);
|
List<KmsProperties> kmsProps = new ArrayList<>();
|
||||||
|
String kmsId;
|
||||||
|
for (String kmsUri : this.openviduConfig.getKmsUris()) {
|
||||||
|
kmsId = "KMS-" + RandomStringUtils.randomAlphanumeric(6).toUpperCase();
|
||||||
|
kmsProps.add(new KmsProperties(kmsId, kmsUri));
|
||||||
|
}
|
||||||
|
this.initializeKurentoClients(kmsProps, true);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
// Some KMS wasn't reachable
|
// Some KMS wasn't reachable
|
||||||
log.error("Shutting down OpenVidu Server");
|
log.error("Shutting down OpenVidu Server");
|
||||||
|
|
|
@ -0,0 +1,37 @@
|
||||||
|
/*
|
||||||
|
* (C) Copyright 2017-2019 OpenVidu (https://openvidu.io/)
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.openvidu.server.kurento.kms;
|
||||||
|
|
||||||
|
public class KmsProperties {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
private String uri;
|
||||||
|
|
||||||
|
public KmsProperties(String id, String uri) {
|
||||||
|
this.id = id;
|
||||||
|
this.uri = uri;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUri() {
|
||||||
|
return uri;
|
||||||
|
}
|
||||||
|
}
|
|
@ -44,7 +44,7 @@ public class RecordingInfoUtils {
|
||||||
this.infoFilePath = infoFilePath;
|
this.infoFilePath = infoFilePath;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
this.json = new JsonUtils().fromFileToJson(infoFilePath);
|
this.json = new JsonUtils().fromFileToJsonObject(infoFilePath);
|
||||||
} catch (JsonIOException | JsonSyntaxException e) {
|
} catch (JsonIOException | JsonSyntaxException e) {
|
||||||
// Recording metadata from ffprobe is not a JSON: video file is corrupted
|
// Recording metadata from ffprobe is not a JSON: video file is corrupted
|
||||||
throw new OpenViduException(Code.RECORDING_FILE_EMPTY_ERROR, "The recording file is corrupted");
|
throw new OpenViduException(Code.RECORDING_FILE_EMPTY_ERROR, "The recording file is corrupted");
|
||||||
|
|
|
@ -408,7 +408,7 @@ public class RecordingManager {
|
||||||
if (file.isFile() && file.getName().startsWith(RecordingManager.RECORDING_ENTITY_FILE)) {
|
if (file.isFile() && file.getName().startsWith(RecordingManager.RECORDING_ENTITY_FILE)) {
|
||||||
JsonObject json;
|
JsonObject json;
|
||||||
try {
|
try {
|
||||||
json = jsonUtils.fromFileToJson(file.getAbsolutePath());
|
json = jsonUtils.fromFileToJsonObject(file.getAbsolutePath());
|
||||||
} catch (JsonIOException | JsonSyntaxException | IOException e) {
|
} catch (JsonIOException | JsonSyntaxException | IOException e) {
|
||||||
log.error("Error reading recording entity file {}: {}", file.getAbsolutePath(), (e.getMessage()));
|
log.error("Error reading recording entity file {}: {}", file.getAbsolutePath(), (e.getMessage()));
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -36,11 +36,11 @@ public class CommandExecutor {
|
||||||
return commonExecCommand(processBuilder);
|
return commonExecCommand(processBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String execCommandRedirectStandardOutputAndError(File standardOutputFile, File errorOutputFile,
|
public static void execCommandRedirectStandardOutputAndError(File standardOutputFile, File errorOutputFile,
|
||||||
String... command) throws IOException, InterruptedException {
|
String... command) throws IOException, InterruptedException {
|
||||||
ProcessBuilder processBuilder = new ProcessBuilder(command).redirectOutput(standardOutputFile)
|
ProcessBuilder processBuilder = new ProcessBuilder(command).redirectOutput(standardOutputFile)
|
||||||
.redirectError(errorOutputFile);
|
.redirectError(errorOutputFile);
|
||||||
return commonExecCommand(processBuilder);
|
commonExecCommand(processBuilder);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String commonExecCommand(ProcessBuilder processBuilder) throws IOException, InterruptedException {
|
private static String commonExecCommand(ProcessBuilder processBuilder) throws IOException, InterruptedException {
|
||||||
|
|
|
@ -17,17 +17,18 @@
|
||||||
|
|
||||||
package io.openvidu.server.utils;
|
package io.openvidu.server.utils;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
|
||||||
import org.kurento.jsonrpc.Props;
|
import org.kurento.jsonrpc.Props;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonIOException;
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParseException;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import com.google.gson.JsonSyntaxException;
|
|
||||||
|
|
||||||
public class JsonUtils {
|
public class JsonUtils {
|
||||||
|
|
||||||
|
@ -43,14 +44,36 @@ public class JsonUtils {
|
||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JsonObject fromFileToJson(String filePath) throws JsonIOException, JsonSyntaxException, IOException {
|
public JsonObject fromFileToJsonObject(String filePath)
|
||||||
JsonObject json;
|
throws IOException, FileNotFoundException, JsonParseException, IllegalStateException {
|
||||||
|
return this.fromFileToJsonElement(filePath).getAsJsonObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonArray fromFileToJsonArray(String filePath)
|
||||||
|
throws IOException, FileNotFoundException, JsonParseException, IllegalStateException {
|
||||||
|
return this.fromFileToJsonElement(filePath).getAsJsonArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonElement fromFileToJsonElement(String filePath)
|
||||||
|
throws IOException, FileNotFoundException, JsonParseException, IllegalStateException {
|
||||||
|
JsonElement json = null;
|
||||||
JsonParser parser = new JsonParser();
|
JsonParser parser = new JsonParser();
|
||||||
FileReader reader = new FileReader(filePath);
|
FileReader reader = null;
|
||||||
try {
|
try {
|
||||||
json = parser.parse(new FileReader(filePath)).getAsJsonObject();
|
reader = new FileReader(filePath);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
json = parser.parse(reader);
|
||||||
|
} catch (JsonParseException | IllegalStateException exception) {
|
||||||
|
throw exception;
|
||||||
} finally {
|
} finally {
|
||||||
reader.close();
|
try {
|
||||||
|
reader.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return json;
|
return json;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue