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,8 +394,13 @@ 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);
for (String uri : kmsUrisList) { if (kmsUrisList.size() == 1 && kmsUrisList.get(0).isEmpty()) {
this.checkWebsocketUri(uri); log.warn("Array kms.uris is empty");
this.kmsUrisList = new ArrayList<>();
} else {
for (String uri : kmsUrisList) {
this.checkWebsocketUri(uri);
}
} }
} }

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,56 +574,62 @@ 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
MediaPipeline pipeline = this.kmsManager.getLessLoadedKms().getKurentoClient().createMediaPipeline(); if (this.openviduConfig.getKmsUris().isEmpty()) {
RecorderEndpoint recorder = new RecorderEndpoint.Builder(pipeline, "file://" + testFilePath).build(); log.warn("No KMSs were defined in kms.uris array. Recording path check aborted");
} else {
final AtomicBoolean kurentoRecorderError = new AtomicBoolean(false); MediaPipeline pipeline = this.kmsManager.getLessLoadedKms().getKurentoClient().createMediaPipeline();
RecorderEndpoint recorder = new RecorderEndpoint.Builder(pipeline, "file://" + testFilePath).build();
recorder.addErrorListener(new EventListener<ErrorEvent>() { final AtomicBoolean kurentoRecorderError = new AtomicBoolean(false);
@Override
public void onEvent(ErrorEvent event) { recorder.addErrorListener(new EventListener<ErrorEvent>() {
if (event.getErrorCode() == 6) { @Override
// KMS write permissions error public void onEvent(ErrorEvent event) {
kurentoRecorderError.compareAndSet(false, true); if (event.getErrorCode() == 6) {
// KMS write permissions error
kurentoRecorderError.compareAndSet(false, true);
}
} }
});
recorder.record();
try {
// Give the error event some time to trigger if necessary
Thread.sleep(500);
} catch (InterruptedException e1) {
e1.printStackTrace();
} }
});
recorder.record(); if (kurentoRecorderError.get()) {
String errorMessage = "The recording path \"" + openviduRecordingPath
+ "\" is not valid. Reason: Kurento Media Server needs write permissions. Try running command \"sudo chmod 777 "
+ openviduRecordingPath + "\"";
log.error(errorMessage);
throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID, errorMessage);
}
try { recorder.stop();
// Give the error event some time to trigger if necessary recorder.release();
Thread.sleep(500); pipeline.release();
} catch (InterruptedException e1) {
e1.printStackTrace();
}
if (kurentoRecorderError.get()) { log.info("Kurento Media Server has write permissions on recording path: {}", openviduRecordingPath);
String errorMessage = "The recording path \"" + openviduRecordingPath
+ "\" is not valid. Reason: Kurento Media Server needs write permissions. Try running command \"sudo chmod 777 "
+ openviduRecordingPath + "\"";
log.error(errorMessage);
throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID, errorMessage);
}
recorder.stop(); try {
recorder.release(); new CustomFileManager().deleteFolder(testFolderPath);
pipeline.release(); log.info("OpenVidu Server has write permissions over files created by Kurento Media Server");
} catch (IOException e) {
log.info("Kurento Media Server has write permissions on recording path: {}", openviduRecordingPath); String errorMessage = "The recording path \"" + openviduRecordingPath
+ "\" is not valid. Reason: OpenVidu Server does not have write permissions over files created by Kurento Media Server. "
try { + "Try running Kurento Media Server as user \"" + System.getProperty("user.name")
new CustomFileManager().deleteFolder(testFolderPath); + "\" or run OpenVidu Server as superuser";
log.info("OpenVidu Server has write permissions over files created by Kurento Media Server"); log.error(errorMessage);
} catch (IOException e) { log.error(
String errorMessage = "The recording path \"" + openviduRecordingPath "Be aware that a folder \"{}\" was created and should be manually deleted (\"sudo rm -rf {}\")",
+ "\" is not valid. Reason: OpenVidu Server does not have write permissions over files created by Kurento Media Server. " testFolderPath, testFolderPath);
+ "Try running Kurento Media Server as user \"" + System.getProperty("user.name") throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID, errorMessage);
+ "\" or run OpenVidu Server as superuser"; }
log.error(errorMessage);
log.error("Be aware that a folder \"{}\" was created and should be manually deleted (\"sudo rm -rf {}\")",
testFolderPath, testFolderPath);
throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID, errorMessage);
} }
if (openviduConfig.openviduRecordingCustomLayoutChanged(openviduRecordingCustomLayout)) { if (openviduConfig.openviduRecordingCustomLayoutChanged(openviduRecordingCustomLayout)) {

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",