openvidu-server: nodeCrashed event with lists of session and recording ids

pull/621/head
pabloFuente 2021-04-20 10:23:17 +02:00
parent f89f1abffd
commit 3e9f8b5669
4 changed files with 24 additions and 13 deletions

View File

@ -1,6 +1,5 @@
package io.openvidu.server.cdr;
import java.util.ArrayList;
import java.util.List;
import com.google.gson.JsonArray;
@ -11,15 +10,16 @@ import io.openvidu.server.kurento.kms.Kms;
public class CDREventNodeCrashed extends CDREvent {
private Kms kms;
private List<String> sessionIds = new ArrayList<>();
private List<String> recordingIds = new ArrayList<>();
private List<String> sessionIds;
private List<String> recordingIds;
private String environmentId;
public CDREventNodeCrashed(CDREventName eventName, Long timeStamp, Kms kms, String environmentId) {
public CDREventNodeCrashed(CDREventName eventName, Long timeStamp, Kms kms, String environmentId,
List<String> sessionIds, List<String> recordingIds) {
super(eventName, null, null, timeStamp);
this.kms = kms;
kms.getKurentoSessions().forEach(session -> sessionIds.add(session.getSessionId()));
kms.getActiveRecordings().forEach(entry -> recordingIds.add(entry.getKey()));
this.sessionIds = sessionIds;
this.recordingIds = recordingIds;
this.environmentId = environmentId;
}

View File

@ -19,6 +19,7 @@ package io.openvidu.server.cdr;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
@ -193,6 +194,13 @@ public class CallDetailRecord {
this.log(new CDREventSignal(sessionId, uniqueSessionId, from, to, type, data));
}
public void recordNodeCrashed(Kms kms, String environmentId, long timeOfKurentoDisconnection,
List<String> sessionIds, List<String> recordingIds) {
CDREvent e = new CDREventNodeCrashed(CDREventName.nodeCrashed, timeOfKurentoDisconnection, kms, environmentId,
sessionIds, recordingIds);
this.log(e);
}
protected void log(CDREvent event) {
this.loggers.forEach(logger -> {
@ -224,9 +232,4 @@ public class CallDetailRecord {
});
}
public void recordNodeCrashed(Kms kms, String environmentId, long timeOfKurentoDisconnection) {
CDREvent e = new CDREventNodeCrashed(CDREventName.nodeCrashed, timeOfKurentoDisconnection, kms, environmentId);
this.log(e);
}
}

View File

@ -18,6 +18,7 @@
package io.openvidu.server.core;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
@ -635,7 +636,8 @@ public class SessionEventsHandler {
* This handler must be called before cleaning any sessions or recordings hosted
* by the crashed Media Node
*/
public void onMediaNodeCrashed(Kms kms, long timeOfKurentoDisconnection) {
public void onMediaNodeCrashed(Kms kms, long timeOfKurentoDisconnection, List<String> sessionIds,
List<String> recordingIds) {
}
public void onMasterNodeCrashed() {

View File

@ -215,7 +215,13 @@ public abstract class KmsManager {
kms.getKurentoClientReconnectTimer().cancelTimer();
final long timeOfKurentoDisconnection = kms.getTimeOfKurentoClientDisconnection();
sessionEventsHandler.onMediaNodeCrashed(kms, timeOfKurentoDisconnection);
final List<String> affectedSessionIds = kms.getKurentoSessions().stream()
.map(session -> session.getSessionId()).collect(Collectors.toUnmodifiableList());
final List<String> affectedRecordingIds = kms.getActiveRecordings().stream()
.map(entry -> entry.getKey()).collect(Collectors.toUnmodifiableList());
sessionEventsHandler.onMediaNodeCrashed(kms, timeOfKurentoDisconnection, affectedSessionIds,
affectedRecordingIds);
// Close all sessions and recordings with reason "nodeCrashed"
log.warn("Closing {} sessions hosted by KMS with uri {}: {}", kms.getKurentoSessions().size(),