openvidu-server: allow for empty kms.uris array. DockerManager#getRunningContainers

pull/375/head
pabloFuente 2019-08-21 15:04:22 +02:00
parent 4253292ca1
commit c3da6e9b8b
5 changed files with 75 additions and 49 deletions

View File

@ -394,10 +394,15 @@ public class OpenviduConfig {
Gson gson = new Gson(); Gson gson = new Gson();
JsonArray kmsUrisArray = gson.fromJson(kmsUris, JsonArray.class); JsonArray kmsUrisArray = gson.fromJson(kmsUris, JsonArray.class);
this.kmsUrisList = JsonUtils.toStringList(kmsUrisArray); this.kmsUrisList = JsonUtils.toStringList(kmsUrisArray);
if (kmsUrisList.size() == 1 && kmsUrisList.get(0).isEmpty()) {
log.warn("Array kms.uris is empty");
this.kmsUrisList = new ArrayList<>();
} else {
for (String uri : kmsUrisList) { for (String uri : kmsUrisList) {
this.checkWebsocketUri(uri); this.checkWebsocketUri(uri);
} }
} }
}
public void initiateOpenViduWebhookEndpoint(String endpoint) throws Exception { public void initiateOpenViduWebhookEndpoint(String endpoint) throws Exception {
try { try {

View File

@ -26,7 +26,7 @@ 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) throws Exception { public List<Kms> initializeKurentoClients(List<String> kmsUris, boolean disconnectUponFailure) throws Exception {
final String kmsUri = kmsUris.get(0); final String kmsUri = kmsUris.get(0);
KurentoClient kClient = null; KurentoClient kClient = null;
Kms kms = new Kms(kmsUri, loadManager); Kms kms = new Kms(kmsUri, loadManager);
@ -35,6 +35,9 @@ public class FixedOneKmsManager extends KmsManager {
kClient = KurentoClient.create(kmsUri, this.generateKurentoConnectionListener(kms.getId())); kClient = KurentoClient.create(kmsUri, 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", kmsUri);
if (kClient != null) {
kClient.destroy();
}
throw new Exception(); throw new Exception();
} }

View File

@ -183,12 +183,13 @@ public abstract class KmsManager {
}; };
} }
public abstract List<Kms> initializeKurentoClients(List<String> kmsUris) throws Exception; public abstract List<Kms> initializeKurentoClients(List<String> kmsUris, boolean disconnectUponFailure)
throws Exception;
@PostConstruct @PostConstruct
private void postConstruct() { private void postConstruct() {
try { try {
this.initializeKurentoClients(this.openviduConfig.getKmsUris()); this.initializeKurentoClients(this.openviduConfig.getKmsUris(), 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");

View File

@ -428,8 +428,8 @@ public class RecordingManager {
} }
public String getRecordingUrl(Recording recording) { public String getRecordingUrl(Recording recording) {
return openviduConfig.getFinalUrl() + "recordings/" + recording.getId() + "/" return openviduConfig.getFinalUrl() + "recordings/" + recording.getId() + "/" + recording.getName() + "."
+ recording.getName() + "." + this.getExtensionFromRecording(recording); + this.getExtensionFromRecording(recording);
} }
private String getExtensionFromRecording(Recording recording) { private String getExtensionFromRecording(Recording recording) {
@ -574,6 +574,10 @@ public class RecordingManager {
final String testFilePath = testFolderPath + "/TEST_RECORDING_PATH.webm"; final String testFilePath = testFolderPath + "/TEST_RECORDING_PATH.webm";
// Check Kurento Media Server write permissions in recording path // Check Kurento Media Server write permissions in recording path
if (this.openviduConfig.getKmsUris().isEmpty()) {
log.warn("No KMSs were defined in kms.uris array. Recording path check aborted");
} else {
MediaPipeline pipeline = this.kmsManager.getLessLoadedKms().getKurentoClient().createMediaPipeline(); MediaPipeline pipeline = this.kmsManager.getLessLoadedKms().getKurentoClient().createMediaPipeline();
RecorderEndpoint recorder = new RecorderEndpoint.Builder(pipeline, "file://" + testFilePath).build(); RecorderEndpoint recorder = new RecorderEndpoint.Builder(pipeline, "file://" + testFilePath).build();
@ -621,10 +625,12 @@ public class RecordingManager {
+ "Try running Kurento Media Server as user \"" + System.getProperty("user.name") + "Try running Kurento Media Server as user \"" + System.getProperty("user.name")
+ "\" or run OpenVidu Server as superuser"; + "\" or run OpenVidu Server as superuser";
log.error(errorMessage); log.error(errorMessage);
log.error("Be aware that a folder \"{}\" was created and should be manually deleted (\"sudo rm -rf {}\")", log.error(
"Be aware that a folder \"{}\" was created and should be manually deleted (\"sudo rm -rf {}\")",
testFolderPath, testFolderPath); testFolderPath, testFolderPath);
throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID, errorMessage); throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID, errorMessage);
} }
}
if (openviduConfig.openviduRecordingCustomLayoutChanged(openviduRecordingCustomLayout)) { if (openviduConfig.openviduRecordingCustomLayoutChanged(openviduRecordingCustomLayout)) {
// Property openvidu.recording.custom-layout changed // Property openvidu.recording.custom-layout changed

View File

@ -208,6 +208,17 @@ public class DockerManager {
} }
} }
public List<String> getRunningContainers(String fullImageName) {
List<String> containerIds = new ArrayList<>();
List<Container> existingContainers = this.dockerClient.listContainersCmd().exec();
for (Container container : existingContainers) {
if (container.getImage().startsWith(fullImageName)) {
containerIds.add(container.getId());
}
}
return containerIds;
}
static public String getDockerGatewayIp() { static public String getDockerGatewayIp() {
try { try {
return CommandExecutor.execCommand("/bin/sh", "-c", return CommandExecutor.execCommand("/bin/sh", "-c",