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 {
|
||||
|
||||
@Override
|
||||
public List<Kms> initializeKurentoClients(List<String> kmsUris, boolean disconnectUponFailure) throws Exception {
|
||||
final String kmsUri = kmsUris.get(0);
|
||||
public List<Kms> initializeKurentoClients(List<KmsProperties> kmsProperties, boolean disconnectUponFailure)
|
||||
throws Exception {
|
||||
KmsProperties firstProps = kmsProperties.get(0);
|
||||
KurentoClient kClient = null;
|
||||
Kms kms = new Kms(kmsUri, loadManager);
|
||||
Kms kms = new Kms(firstProps, loadManager);
|
||||
this.addKms(kms);
|
||||
try {
|
||||
kClient = KurentoClient.create(kmsUri, this.generateKurentoConnectionListener(kms.getId()));
|
||||
kClient = KurentoClient.create(firstProps.getUri(), this.generateKurentoConnectionListener(kms.getId()));
|
||||
} 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) {
|
||||
kClient.destroy();
|
||||
}
|
||||
|
|
|
@ -25,7 +25,6 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.kurento.client.KurentoClient;
|
||||
import org.kurento.client.ModuleInfo;
|
||||
import org.kurento.client.ServerInfo;
|
||||
|
@ -64,9 +63,9 @@ public class Kms {
|
|||
|
||||
private Map<String, KurentoSession> kurentoSessions = new ConcurrentHashMap<>();
|
||||
|
||||
public Kms(String uri, LoadManager loadManager) {
|
||||
this.uri = uri;
|
||||
this.id = "KMS-" + RandomStringUtils.randomAlphanumeric(6).toUpperCase();
|
||||
public Kms(KmsProperties props, LoadManager loadManager) {
|
||||
this.id = props.getId();
|
||||
this.uri = props.getUri();
|
||||
|
||||
String parsedUri = uri.replaceAll("^ws://", "http://").replaceAll("^wss://", "https://");
|
||||
URL url = null;
|
||||
|
|
|
@ -28,6 +28,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||
import javax.annotation.PostConstruct;
|
||||
import javax.annotation.PreDestroy;
|
||||
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.kurento.client.KurentoConnectionListener;
|
||||
import org.slf4j.Logger;
|
||||
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;
|
||||
|
||||
@PostConstruct
|
||||
private void postConstruct() {
|
||||
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) {
|
||||
// Some KMS wasn't reachable
|
||||
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;
|
||||
|
||||
try {
|
||||
this.json = new JsonUtils().fromFileToJson(infoFilePath);
|
||||
this.json = new JsonUtils().fromFileToJsonObject(infoFilePath);
|
||||
} catch (JsonIOException | JsonSyntaxException e) {
|
||||
// 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");
|
||||
|
|
|
@ -408,7 +408,7 @@ public class RecordingManager {
|
|||
if (file.isFile() && file.getName().startsWith(RecordingManager.RECORDING_ENTITY_FILE)) {
|
||||
JsonObject json;
|
||||
try {
|
||||
json = jsonUtils.fromFileToJson(file.getAbsolutePath());
|
||||
json = jsonUtils.fromFileToJsonObject(file.getAbsolutePath());
|
||||
} catch (JsonIOException | JsonSyntaxException | IOException e) {
|
||||
log.error("Error reading recording entity file {}: {}", file.getAbsolutePath(), (e.getMessage()));
|
||||
return null;
|
||||
|
|
|
@ -36,11 +36,11 @@ public class CommandExecutor {
|
|||
return commonExecCommand(processBuilder);
|
||||
}
|
||||
|
||||
public static String execCommandRedirectStandardOutputAndError(File standardOutputFile, File errorOutputFile,
|
||||
public static void execCommandRedirectStandardOutputAndError(File standardOutputFile, File errorOutputFile,
|
||||
String... command) throws IOException, InterruptedException {
|
||||
ProcessBuilder processBuilder = new ProcessBuilder(command).redirectOutput(standardOutputFile)
|
||||
.redirectError(errorOutputFile);
|
||||
return commonExecCommand(processBuilder);
|
||||
commonExecCommand(processBuilder);
|
||||
}
|
||||
|
||||
private static String commonExecCommand(ProcessBuilder processBuilder) throws IOException, InterruptedException {
|
||||
|
|
|
@ -17,17 +17,18 @@
|
|||
|
||||
package io.openvidu.server.utils;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.kurento.jsonrpc.Props;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonIOException;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.JsonSyntaxException;
|
||||
|
||||
public class JsonUtils {
|
||||
|
||||
|
@ -43,14 +44,36 @@ public class JsonUtils {
|
|||
return props;
|
||||
}
|
||||
|
||||
public JsonObject fromFileToJson(String filePath) throws JsonIOException, JsonSyntaxException, IOException {
|
||||
JsonObject json;
|
||||
public JsonObject fromFileToJsonObject(String filePath)
|
||||
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();
|
||||
FileReader reader = new FileReader(filePath);
|
||||
FileReader reader = null;
|
||||
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 {
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue