mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: protect get KMS if there's no running and connected one
parent
a3406d3dfe
commit
7085bb899b
|
@ -114,7 +114,11 @@ public abstract class KmsManager {
|
||||||
public synchronized Kms getLessLoadedConnectedAndRunningKms() throws NoSuchElementException {
|
public synchronized Kms getLessLoadedConnectedAndRunningKms() throws NoSuchElementException {
|
||||||
List<KmsLoad> kmsLoads = getKmsLoads().stream().filter(kmsLoad -> kmsLoad.kms.isKurentoClientConnected()
|
List<KmsLoad> kmsLoads = getKmsLoads().stream().filter(kmsLoad -> kmsLoad.kms.isKurentoClientConnected()
|
||||||
&& mediaNodeStatusManager.isRunning(kmsLoad.kms.getId())).collect(Collectors.toList());
|
&& mediaNodeStatusManager.isRunning(kmsLoad.kms.getId())).collect(Collectors.toList());
|
||||||
return Collections.min(kmsLoads).kms;
|
if (kmsLoads.isEmpty()) {
|
||||||
|
throw new NoSuchElementException();
|
||||||
|
} else {
|
||||||
|
return Collections.min(kmsLoads).kms;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized List<KmsLoad> getKmssSortedByLoad() {
|
public synchronized List<KmsLoad> getKmssSortedByLoad() {
|
||||||
|
|
|
@ -27,6 +27,7 @@ import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import java.util.concurrent.CountDownLatch;
|
import java.util.concurrent.CountDownLatch;
|
||||||
|
@ -67,6 +68,7 @@ import io.openvidu.server.core.Session;
|
||||||
import io.openvidu.server.core.SessionEventsHandler;
|
import io.openvidu.server.core.SessionEventsHandler;
|
||||||
import io.openvidu.server.core.SessionManager;
|
import io.openvidu.server.core.SessionManager;
|
||||||
import io.openvidu.server.kurento.core.KurentoSession;
|
import io.openvidu.server.kurento.core.KurentoSession;
|
||||||
|
import io.openvidu.server.kurento.kms.Kms;
|
||||||
import io.openvidu.server.kurento.kms.KmsManager;
|
import io.openvidu.server.kurento.kms.KmsManager;
|
||||||
import io.openvidu.server.recording.Recording;
|
import io.openvidu.server.recording.Recording;
|
||||||
import io.openvidu.server.recording.RecordingDownloader;
|
import io.openvidu.server.recording.RecordingDownloader;
|
||||||
|
@ -678,59 +680,67 @@ public class RecordingManager {
|
||||||
if (this.kmsManager.getKmss().isEmpty()) {
|
if (this.kmsManager.getKmss().isEmpty()) {
|
||||||
log.warn("No KMSs were defined in KMS_URIS array. Recording path check aborted");
|
log.warn("No KMSs were defined in KMS_URIS array. Recording path check aborted");
|
||||||
} else {
|
} else {
|
||||||
|
Kms kms = null;
|
||||||
|
try {
|
||||||
|
kms = this.kmsManager.getLessLoadedConnectedAndRunningKms();
|
||||||
|
} catch (NoSuchElementException e) {
|
||||||
|
}
|
||||||
|
if (kms == null) {
|
||||||
|
log.warn("There are not running and connected KMSs. Recording path check aborted");
|
||||||
|
} else {
|
||||||
|
MediaPipeline pipeline = this.kmsManager.getLessLoadedConnectedAndRunningKms().getKurentoClient()
|
||||||
|
.createMediaPipeline();
|
||||||
|
RecorderEndpoint recorder = new RecorderEndpoint.Builder(pipeline, "file://" + testFilePath).build();
|
||||||
|
|
||||||
MediaPipeline pipeline = this.kmsManager.getLessLoadedConnectedAndRunningKms().getKurentoClient()
|
final AtomicBoolean kurentoRecorderError = new AtomicBoolean(false);
|
||||||
.createMediaPipeline();
|
|
||||||
RecorderEndpoint recorder = new RecorderEndpoint.Builder(pipeline, "file://" + testFilePath).build();
|
|
||||||
|
|
||||||
final AtomicBoolean kurentoRecorderError = new AtomicBoolean(false);
|
recorder.addErrorListener(new EventListener<ErrorEvent>() {
|
||||||
|
@Override
|
||||||
recorder.addErrorListener(new EventListener<ErrorEvent>() {
|
public void onEvent(ErrorEvent event) {
|
||||||
@Override
|
if (event.getErrorCode() == 6) {
|
||||||
public void onEvent(ErrorEvent event) {
|
// KMS write permissions error
|
||||||
if (event.getErrorCode() == 6) {
|
kurentoRecorderError.compareAndSet(false, true);
|
||||||
// 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue