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();
JsonArray kmsUrisArray = gson.fromJson(kmsUris, JsonArray.class);
this.kmsUrisList = JsonUtils.toStringList(kmsUrisArray);
for (String uri : kmsUrisList) {
this.checkWebsocketUri(uri);
if (kmsUrisList.size() == 1 && kmsUrisList.get(0).isEmpty()) {
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 {
@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);
KurentoClient kClient = null;
Kms kms = new Kms(kmsUri, loadManager);
@ -35,6 +35,9 @@ public class FixedOneKmsManager extends KmsManager {
kClient = KurentoClient.create(kmsUri, this.generateKurentoConnectionListener(kms.getId()));
} catch (KurentoException e) {
log.error("KMS in {} is not reachable by OpenVidu Server", kmsUri);
if (kClient != null) {
kClient.destroy();
}
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
private void postConstruct() {
try {
this.initializeKurentoClients(this.openviduConfig.getKmsUris());
this.initializeKurentoClients(this.openviduConfig.getKmsUris(), true);
} catch (Exception e) {
// Some KMS wasn't reachable
log.error("Shutting down OpenVidu Server");

View File

@ -428,8 +428,8 @@ public class RecordingManager {
}
public String getRecordingUrl(Recording recording) {
return openviduConfig.getFinalUrl() + "recordings/" + recording.getId() + "/"
+ recording.getName() + "." + this.getExtensionFromRecording(recording);
return openviduConfig.getFinalUrl() + "recordings/" + recording.getId() + "/" + recording.getName() + "."
+ this.getExtensionFromRecording(recording);
}
private String getExtensionFromRecording(Recording recording) {
@ -574,56 +574,62 @@ public class RecordingManager {
final String testFilePath = testFolderPath + "/TEST_RECORDING_PATH.webm";
// Check Kurento Media Server write permissions in recording path
MediaPipeline pipeline = this.kmsManager.getLessLoadedKms().getKurentoClient().createMediaPipeline();
RecorderEndpoint recorder = new RecorderEndpoint.Builder(pipeline, "file://" + testFilePath).build();
if (this.openviduConfig.getKmsUris().isEmpty()) {
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>() {
@Override
public void onEvent(ErrorEvent event) {
if (event.getErrorCode() == 6) {
// KMS write permissions error
kurentoRecorderError.compareAndSet(false, true);
final AtomicBoolean kurentoRecorderError = new AtomicBoolean(false);
recorder.addErrorListener(new EventListener<ErrorEvent>() {
@Override
public void onEvent(ErrorEvent event) {
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 {
// Give the error event some time to trigger if necessary
Thread.sleep(500);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
recorder.stop();
recorder.release();
pipeline.release();
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);
}
log.info("Kurento Media Server has write permissions on recording path: {}", openviduRecordingPath);
recorder.stop();
recorder.release();
pipeline.release();
log.info("Kurento Media Server has write permissions on recording path: {}", openviduRecordingPath);
try {
new CustomFileManager().deleteFolder(testFolderPath);
log.info("OpenVidu Server has write permissions over files created by Kurento Media Server");
} catch (IOException e) {
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 running Kurento Media Server as user \"" + System.getProperty("user.name")
+ "\" 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);
try {
new CustomFileManager().deleteFolder(testFolderPath);
log.info("OpenVidu Server has write permissions over files created by Kurento Media Server");
} catch (IOException e) {
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 running Kurento Media Server as user \"" + System.getProperty("user.name")
+ "\" 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)) {

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() {
try {
return CommandExecutor.execCommand("/bin/sh", "-c",