openvidu-server: check recording paths fix

pull/203/head
pabloFuente 2019-02-14 12:29:37 +01:00
parent cde8290039
commit d38ecabecb
3 changed files with 38 additions and 29 deletions

View File

@ -138,11 +138,15 @@ public class OpenviduConfig {
public void setOpenViduRecordingCustomLayout(String recordingCustomLayout) { public void setOpenViduRecordingCustomLayout(String recordingCustomLayout) {
this.openviduRecordingCustomLayout = recordingCustomLayout; this.openviduRecordingCustomLayout = recordingCustomLayout;
} }
public boolean openviduRecordingCustomLayoutChanged() { public boolean openviduRecordingCustomLayoutChanged() {
return !"/opt/openvidu/custom-layout".equals(this.openviduRecordingCustomLayout); return !"/opt/openvidu/custom-layout".equals(this.openviduRecordingCustomLayout);
} }
public boolean openviduRecordingCustomLayoutChanged(String path) {
return !"/opt/openvidu/custom-layout".equals(path);
}
public String getFinalUrl() { public String getFinalUrl() {
return finalUrl; return finalUrl;
} }

View File

@ -161,7 +161,7 @@ public class RecordingManager {
public void checkRecordingRequirements(String openviduRecordingPath, String openviduRecordingCustomLayout) public void checkRecordingRequirements(String openviduRecordingPath, String openviduRecordingCustomLayout)
throws OpenViduException { throws OpenViduException {
this.checkDockerEnabled(); this.checkDockerEnabled();
this.checkRecordingPaths(); this.checkRecordingPaths(openviduRecordingPath, openviduRecordingCustomLayout);
} }
public Recording startRecording(Session session, RecordingProperties properties) throws OpenViduException { public Recording startRecording(Session session, RecordingProperties properties) throws OpenViduException {
@ -441,6 +441,11 @@ public class RecordingManager {
imageExists = false; imageExists = false;
} catch (ProcessingException e) { } catch (ProcessingException e) {
throw e; throw e;
} catch (NullPointerException e) {
// Restarting openvidu-server from openvidu.recording=false
// ComposedRecordingService was not initialized
this.composedRecordingService = new ComposedRecordingService(this, openviduConfig);
return this.recordingImageExistsLocally();
} }
return imageExists; return imageExists;
} }
@ -539,19 +544,16 @@ public class RecordingManager {
} }
} }
private void checkRecordingPaths() throws OpenViduException { private void checkRecordingPaths(String openviduRecordingPath, String openviduRecordingCustomLayout)
log.info("Initializing recording path"); throws OpenViduException {
log.info("Initializing recording paths");
final String recordingPathString = this.openviduConfig.getOpenViduRecordingPath();
final String testFolderPath = recordingPathString + "/TEST_RECORDING_PATH_" + System.currentTimeMillis();
final String testFilePath = testFolderPath + "/TEST_RECORDING_PATH.webm";
Path recordingPath = null; Path recordingPath = null;
try { try {
recordingPath = Files.createDirectories(Paths.get(recordingPathString)); recordingPath = Files.createDirectories(Paths.get(openviduRecordingPath));
} catch (IOException e) { } catch (IOException e) {
String errorMessage = "The recording path \"" + recordingPathString String errorMessage = "The recording path \"" + openviduRecordingPath
+ "\" is not valid. Reason: OpenVidu Server cannot find path \"" + recordingPathString + "\" is not valid. Reason: OpenVidu Server cannot find path \"" + openviduRecordingPath
+ "\" and doesn't have permissions to create it"; + "\" and doesn't have permissions to create it";
log.error(errorMessage); log.error(errorMessage);
throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID, errorMessage); throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID, errorMessage);
@ -559,15 +561,18 @@ public class RecordingManager {
// Check OpenVidu Server write permissions in recording path // Check OpenVidu Server write permissions in recording path
if (!Files.isWritable(recordingPath)) { if (!Files.isWritable(recordingPath)) {
String errorMessage = "The recording path \"" + recordingPathString String errorMessage = "The recording path \"" + openviduRecordingPath
+ "\" is not valid. Reason: OpenVidu Server needs write permissions. Try running command \"sudo chmod 777 " + "\" is not valid. Reason: OpenVidu Server needs write permissions. Try running command \"sudo chmod 777 "
+ recordingPathString + "\""; + openviduRecordingPath + "\"";
log.error(errorMessage); log.error(errorMessage);
throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID, errorMessage); throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID, errorMessage);
} else { } else {
log.info("OpenVidu Server has write permissions on recording path: {}", recordingPathString); log.info("OpenVidu Server has write permissions on recording path: {}", openviduRecordingPath);
} }
final String testFolderPath = openviduRecordingPath + "/TEST_RECORDING_PATH_" + System.currentTimeMillis();
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
KurentoClientSessionInfo kcSessionInfo = new OpenViduKurentoClientSessionInfo("TEST_RECORDING_PATH", KurentoClientSessionInfo kcSessionInfo = new OpenViduKurentoClientSessionInfo("TEST_RECORDING_PATH",
"TEST_RECORDING_PATH"); "TEST_RECORDING_PATH");
@ -596,9 +601,9 @@ public class RecordingManager {
} }
if (kurentoRecorderError.get()) { if (kurentoRecorderError.get()) {
String errorMessage = "The recording path \"" + recordingPathString String errorMessage = "The recording path \"" + openviduRecordingPath
+ "\" is not valid. Reason: Kurento Media Server needs write permissions. Try running command \"sudo chmod 777 " + "\" is not valid. Reason: Kurento Media Server needs write permissions. Try running command \"sudo chmod 777 "
+ recordingPathString + "\""; + openviduRecordingPath + "\"";
log.error(errorMessage); log.error(errorMessage);
throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID, errorMessage); throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID, errorMessage);
} }
@ -607,13 +612,13 @@ public class RecordingManager {
recorder.release(); recorder.release();
pipeline.release(); pipeline.release();
log.info("Kurento Media Server has write permissions on recording path: {}", recordingPathString); log.info("Kurento Media Server has write permissions on recording path: {}", openviduRecordingPath);
try { try {
new CustomFileManager().deleteFolder(testFolderPath); new CustomFileManager().deleteFolder(testFolderPath);
log.info("OpenVidu Server has write permissions over files created by Kurento Media Server"); log.info("OpenVidu Server has write permissions over files created by Kurento Media Server");
} catch (IOException e) { } catch (IOException e) {
String errorMessage = "The recording path \"" + recordingPathString String errorMessage = "The recording path \"" + openviduRecordingPath
+ "\" is not valid. Reason: OpenVidu Server does not have write permissions over files created by Kurento Media Server. " + "\" 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") + "Try running Kurento Media Server as user \"" + System.getProperty("user.name")
+ "\" or run OpenVidu Server as superuser"; + "\" or run OpenVidu Server as superuser";
@ -623,31 +628,31 @@ public class RecordingManager {
throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID, errorMessage); throw new OpenViduException(Code.RECORDING_PATH_NOT_VALID, errorMessage);
} }
if (openviduConfig.openviduRecordingCustomLayoutChanged()) { if (openviduConfig.openviduRecordingCustomLayoutChanged(openviduRecordingCustomLayout)) {
// Property openvidu.recording.custom-layout changed // Property openvidu.recording.custom-layout changed
File dir = new File(openviduConfig.getOpenviduRecordingCustomLayout()); File dir = new File(openviduRecordingCustomLayout);
if (dir.exists()) { if (dir.exists()) {
if (dir.listFiles() == null) { if (dir.listFiles() == null) {
String errorMessage = "The custom layouts path \"" String errorMessage = "The custom layouts path \"" + openviduRecordingCustomLayout
+ openviduConfig.getOpenviduRecordingCustomLayout()
+ "\" is not valid. Reason: OpenVidu Server needs read permissions. Try running command \"sudo chmod 755 " + "\" is not valid. Reason: OpenVidu Server needs read permissions. Try running command \"sudo chmod 755 "
+ openviduConfig.getOpenviduRecordingCustomLayout() + "\""; + openviduRecordingCustomLayout + "\"";
log.error(errorMessage); log.error(errorMessage);
throw new OpenViduException(Code.RECORDING_FILE_EMPTY_ERROR, errorMessage); throw new OpenViduException(Code.RECORDING_FILE_EMPTY_ERROR, errorMessage);
} else { } else {
log.info("OpenVidu Server has read permissions on custom layout path: {}", log.info("OpenVidu Server has read permissions on custom layout path: {}",
openviduConfig.getOpenviduRecordingCustomLayout()); openviduRecordingCustomLayout);
log.info("Custom layouts path successfully initialized at {}", openviduRecordingCustomLayout);
} }
} else { } else {
String errorMessage = "The custom layouts path \"" + openviduConfig.getOpenviduRecordingCustomLayout() String errorMessage = "The custom layouts path \"" + openviduRecordingCustomLayout
+ "\" is not valid. Reason: OpenVidu Server cannot find path \"" + "\" is not valid. Reason: OpenVidu Server cannot find path \"" + openviduRecordingCustomLayout
+ openviduConfig.getOpenviduRecordingCustomLayout() + "\""; + "\" and doesn't have permissions to create it";
log.error(errorMessage); log.error(errorMessage);
throw new OpenViduException(Code.RECORDING_FILE_EMPTY_ERROR, errorMessage); throw new OpenViduException(Code.RECORDING_FILE_EMPTY_ERROR, errorMessage);
} }
} }
log.info("Recording path successfully initialized at {}", this.openviduConfig.getOpenViduRecordingPath()); log.info("Recording path successfully initialized at {}", openviduRecordingPath);
} }
public static String finalReason(String reason) { public static String finalReason(String reason) {

View File

@ -2552,7 +2552,7 @@ public class OpenViduTestAppE2eTest {
/** GET /config **/ /** GET /config **/
restClient.rest(HttpMethod.GET, "/config", null, HttpStatus.SC_OK, true, restClient.rest(HttpMethod.GET, "/config", null, HttpStatus.SC_OK, true,
"{'version':'STR','openviduPublicurl':'STR','openviduCdr':false,'maxRecvBandwidth':0,'minRecvBandwidth':0,'maxSendBandwidth':0,'minSendBandwidth':0,'openviduRecording':false," "{'version':'STR','openviduPublicurl':'STR','openviduCdr':false,'maxRecvBandwidth':0,'minRecvBandwidth':0,'maxSendBandwidth':0,'minSendBandwidth':0,'openviduRecording':false,"
+ "'openviduRecordingVersion':'STR','openviduRecordingPath':'STR','openviduRecordingPublicAccess':false,'openviduRecordingNotification':'STR','openviduRecordingCustomLayout':'STR'}"); + "'openviduRecordingVersion':'STR','openviduRecordingPath':'STR','openviduRecordingPublicAccess':false,'openviduRecordingNotification':'STR','openviduRecordingCustomLayout':'STR','openviduRecordingAutostopTimeout':0}");
} }
private void listEmptyRecordings() { private void listEmptyRecordings() {