mirror of https://github.com/OpenVidu/openvidu.git
openvidu-server: cdr logger refactoring
parent
42863065d4
commit
a8495a6f54
|
@ -45,6 +45,7 @@ import com.google.gson.JsonArray;
|
|||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParser;
|
||||
|
||||
import io.openvidu.server.cdr.CDRLoggerFile;
|
||||
import io.openvidu.server.cdr.CallDetailRecord;
|
||||
import io.openvidu.server.config.OpenviduConfig;
|
||||
import io.openvidu.server.core.SessionManager;
|
||||
|
@ -132,7 +133,7 @@ public class OpenViduServer implements JsonRpcConfigurer {
|
|||
@Bean
|
||||
@ConditionalOnMissingBean
|
||||
public CallDetailRecord cdr() {
|
||||
return new CallDetailRecord();
|
||||
return new CallDetailRecord(new CDRLoggerFile());
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
|
|
@ -26,16 +26,7 @@ import io.openvidu.server.recording.Recording;
|
|||
|
||||
public class CDREvent implements Comparable<CDREvent> {
|
||||
|
||||
static final String SESSION_CREATED = "sessionCreated";
|
||||
static final String SESSION_DESTROYED = "sessionDestroyed";
|
||||
static final String PARTICIPANT_JOINED = "participantJoined";
|
||||
static final String PARTICIPANT_LEFT = "participantLeft";
|
||||
static final String CONNECTION_CREATED = "webrtcConnectionCreated";
|
||||
static final String CONNECTION_DESTROYED = "webrtcConnectionDestroyed";
|
||||
static final String RECORDING_STARTED = "recordingStarted";
|
||||
static final String RECORDING_STOPPED = "recordingStopped";
|
||||
|
||||
protected String eventName;
|
||||
protected CDREventName eventName;
|
||||
protected String sessionId;
|
||||
protected Long timeStamp;
|
||||
private Long startTime;
|
||||
|
@ -53,17 +44,17 @@ public class CDREvent implements Comparable<CDREvent> {
|
|||
private Boolean hasVideo;
|
||||
private RecordingLayout recordingLayout;
|
||||
|
||||
public CDREvent(String eventName, CDREvent event) {
|
||||
public CDREvent(CDREventName eventName, CDREvent event) {
|
||||
this(eventName, event.participant, event.sessionId, event.mediaOptions, event.receivingFrom, event.startTime, event.reason);
|
||||
this.duration = (int) (this.timeStamp - this.startTime / 1000);
|
||||
}
|
||||
|
||||
public CDREvent(String eventName, CDREvent event, String reason) {
|
||||
public CDREvent(CDREventName eventName, CDREvent event, String reason) {
|
||||
this(eventName, event.participant, event.sessionId, event.mediaOptions, event.receivingFrom, event.startTime, reason);
|
||||
this.duration = (int) (this.timeStamp - this.startTime / 1000);
|
||||
}
|
||||
|
||||
public CDREvent(String eventName, String sessionId) {
|
||||
public CDREvent(CDREventName eventName, String sessionId) {
|
||||
this.eventName = eventName;
|
||||
if ((sessionId.indexOf('/')) != -1) {
|
||||
this.sessionId = sessionId.substring(sessionId.lastIndexOf('/') + 1, sessionId.length());
|
||||
|
@ -74,7 +65,7 @@ public class CDREvent implements Comparable<CDREvent> {
|
|||
this.startTime = this.timeStamp;
|
||||
}
|
||||
|
||||
public CDREvent(String eventName, String sessionId, Recording recording) {
|
||||
public CDREvent(CDREventName eventName, String sessionId, Recording recording) {
|
||||
this.eventName = eventName;
|
||||
if ((sessionId.indexOf('/')) != -1) {
|
||||
this.sessionId = sessionId.substring(sessionId.lastIndexOf('/') + 1, sessionId.length());
|
||||
|
@ -91,13 +82,13 @@ public class CDREvent implements Comparable<CDREvent> {
|
|||
this.recordingLayout = recording.getRecordingLayout();
|
||||
}
|
||||
|
||||
public CDREvent(String eventName, Participant participant, String sessionId) {
|
||||
public CDREvent(CDREventName eventName, Participant participant, String sessionId) {
|
||||
this(eventName, sessionId);
|
||||
this.participant = participant;
|
||||
this.startTime = this.timeStamp;
|
||||
}
|
||||
|
||||
public CDREvent(String eventName, Participant participant, String sessionId, MediaOptions mediaOptions,
|
||||
public CDREvent(CDREventName eventName, Participant participant, String sessionId, MediaOptions mediaOptions,
|
||||
String receivingFrom, Long startTime, String reason) {
|
||||
this(eventName, sessionId);
|
||||
this.participant = participant;
|
||||
|
@ -171,7 +162,7 @@ public class CDREvent implements Comparable<CDREvent> {
|
|||
}
|
||||
|
||||
JSONObject root = new JSONObject();
|
||||
root.put(this.eventName, json);
|
||||
root.put(this.eventName.name(), json);
|
||||
|
||||
return root.toJSONString();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* (C) Copyright 2017-2018 OpenVidu (https://openvidu.io/)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.openvidu.server.cdr;
|
||||
|
||||
public enum CDREventName {
|
||||
|
||||
sessionCreated, sessionDestroyed, participantJoined, participantLeft, webrtcConnectionCreated, webrtcConnectionDestroyed, recordingStarted, recordingStopped
|
||||
|
||||
}
|
|
@ -0,0 +1,24 @@
|
|||
/*
|
||||
* (C) Copyright 2017-2018 OpenVidu (https://openvidu.io/)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.openvidu.server.cdr;
|
||||
|
||||
public interface CDRLogger {
|
||||
|
||||
public void log(CDREvent event);
|
||||
|
||||
}
|
|
@ -0,0 +1,32 @@
|
|||
/*
|
||||
* (C) Copyright 2017-2018 OpenVidu (https://openvidu.io/)
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
*/
|
||||
|
||||
package io.openvidu.server.cdr;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class CDRLoggerFile implements CDRLogger {
|
||||
|
||||
private Logger log = LoggerFactory.getLogger(CDRLoggerFile.class);
|
||||
|
||||
@Override
|
||||
public void log(CDREvent event) {
|
||||
log.info("{}", event);
|
||||
}
|
||||
|
||||
}
|
|
@ -23,9 +23,6 @@ import java.util.Set;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ConcurrentSkipListSet;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import io.openvidu.server.core.MediaOptions;
|
||||
import io.openvidu.server.core.Participant;
|
||||
import io.openvidu.server.recording.Recording;
|
||||
|
@ -76,47 +73,51 @@ import io.openvidu.server.recording.Recording;
|
|||
*/
|
||||
public class CallDetailRecord {
|
||||
|
||||
private Logger log = LoggerFactory.getLogger(CallDetailRecord.class);
|
||||
private CDRLogger logger;
|
||||
|
||||
private Map<String, CDREvent> sessions = new ConcurrentHashMap<>();
|
||||
private Map<String, CDREvent> participants = new ConcurrentHashMap<>();
|
||||
private Map<String, CDREvent> publications = new ConcurrentHashMap<>();
|
||||
private Map<String, Set<CDREvent>> subscriptions = new ConcurrentHashMap<>();
|
||||
|
||||
public CallDetailRecord(CDRLogger logger) {
|
||||
this.logger = logger;
|
||||
}
|
||||
|
||||
public void recordSessionCreated(String sessionId) {
|
||||
CDREvent e = new CDREvent(CDREvent.SESSION_CREATED, sessionId);
|
||||
CDREvent e = new CDREvent(CDREventName.sessionCreated, sessionId);
|
||||
this.sessions.put(sessionId, e);
|
||||
log.info("{}", e);
|
||||
this.logger.log(e);
|
||||
}
|
||||
|
||||
public void recordSessionDestroyed(String sessionId, String reason) {
|
||||
CDREvent e = this.sessions.remove(sessionId);
|
||||
log.info("{}", new CDREvent(CDREvent.SESSION_DESTROYED, e, reason));
|
||||
this.logger.log(new CDREvent(CDREventName.sessionDestroyed, e, reason));
|
||||
}
|
||||
|
||||
public void recordParticipantJoined(Participant participant, String sessionId) {
|
||||
CDREvent e = new CDREvent(CDREvent.PARTICIPANT_JOINED, participant, sessionId);
|
||||
CDREvent e = new CDREvent(CDREventName.participantJoined, participant, sessionId);
|
||||
this.participants.put(participant.getParticipantPublicId(), e);
|
||||
log.info("{}", e);
|
||||
this.logger.log(e);
|
||||
}
|
||||
|
||||
public void recordParticipantLeft(Participant participant, String sessionId, String reason) {
|
||||
CDREvent e = this.participants.remove(participant.getParticipantPublicId());
|
||||
log.info("{}", new CDREvent(CDREvent.PARTICIPANT_LEFT, e, reason));
|
||||
this.logger.log(new CDREvent(CDREventName.participantLeft, e, reason));
|
||||
}
|
||||
|
||||
public void recordNewPublisher(Participant participant, String sessionId, MediaOptions mediaOptions) {
|
||||
CDREvent publisher = new CDREvent(CDREvent.CONNECTION_CREATED, participant, sessionId, mediaOptions, null,
|
||||
System.currentTimeMillis(), null);
|
||||
CDREvent publisher = new CDREvent(CDREventName.webrtcConnectionCreated, participant, sessionId, mediaOptions,
|
||||
null, System.currentTimeMillis(), null);
|
||||
this.publications.put(participant.getParticipantPublicId(), publisher);
|
||||
log.info("{}", publisher);
|
||||
this.logger.log(publisher);
|
||||
}
|
||||
|
||||
public boolean stopPublisher(String participantPublicId, String reason) {
|
||||
CDREvent publisher = this.publications.remove(participantPublicId);
|
||||
if (publisher != null) {
|
||||
publisher = new CDREvent(CDREvent.CONNECTION_DESTROYED, publisher, reason);
|
||||
log.info("{}", publisher);
|
||||
publisher = new CDREvent(CDREventName.webrtcConnectionDestroyed, publisher, reason);
|
||||
this.logger.log(publisher);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -124,11 +125,11 @@ public class CallDetailRecord {
|
|||
|
||||
public void recordNewSubscriber(Participant participant, String sessionId, String senderPublicId) {
|
||||
CDREvent publisher = this.publications.get(senderPublicId);
|
||||
CDREvent subscriber = new CDREvent(CDREvent.CONNECTION_CREATED, participant, sessionId,
|
||||
CDREvent subscriber = new CDREvent(CDREventName.webrtcConnectionCreated, participant, sessionId,
|
||||
publisher.getMediaOptions(), publisher.getParticipantPublicId(), System.currentTimeMillis(), null);
|
||||
this.subscriptions.putIfAbsent(participant.getParticipantPublicId(), new ConcurrentSkipListSet<>());
|
||||
this.subscriptions.get(participant.getParticipantPublicId()).add(subscriber);
|
||||
log.info("{}", subscriber);
|
||||
this.logger.log(subscriber);
|
||||
}
|
||||
|
||||
public boolean stopSubscriber(String participantPublicId, String senderPublicId, String reason) {
|
||||
|
@ -139,8 +140,8 @@ public class CallDetailRecord {
|
|||
subscription = it.next();
|
||||
if (subscription.getReceivingFrom().equals(senderPublicId)) {
|
||||
it.remove();
|
||||
subscription = new CDREvent(CDREvent.CONNECTION_DESTROYED, subscription, reason);
|
||||
log.info("{}", subscription);
|
||||
subscription = new CDREvent(CDREventName.webrtcConnectionDestroyed, subscription, reason);
|
||||
this.logger.log(subscription);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -149,11 +150,11 @@ public class CallDetailRecord {
|
|||
}
|
||||
|
||||
public void recordRecordingStarted(String sessionId, Recording recording) {
|
||||
log.info("{}", new CDREvent(CDREvent.RECORDING_STARTED, sessionId, recording));
|
||||
this.logger.log(new CDREvent(CDREventName.recordingStarted, sessionId, recording));
|
||||
}
|
||||
|
||||
public void recordRecordingStopped(String sessionId, Recording recording) {
|
||||
log.info("{}", new CDREvent(CDREvent.RECORDING_STOPPED, sessionId, recording));
|
||||
this.logger.log(new CDREvent(CDREventName.recordingStopped, sessionId, recording));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,12 +38,14 @@ import org.kurento.client.SdpEndpoint;
|
|||
import org.kurento.client.internal.server.KurentoServerException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import io.openvidu.client.OpenViduException;
|
||||
import io.openvidu.client.OpenViduException.Code;
|
||||
import io.openvidu.client.internal.ProtocolElements;
|
||||
import io.openvidu.server.cdr.CallDetailRecord;
|
||||
import io.openvidu.server.config.InfoHandler;
|
||||
import io.openvidu.server.config.OpenviduConfig;
|
||||
import io.openvidu.server.core.MediaOptions;
|
||||
import io.openvidu.server.core.Participant;
|
||||
import io.openvidu.server.kurento.MutedMediaType;
|
||||
|
@ -56,6 +58,9 @@ import io.openvidu.server.kurento.endpoint.SubscriberEndpoint;
|
|||
public class KurentoParticipant extends Participant {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(KurentoParticipant.class);
|
||||
|
||||
@Autowired
|
||||
protected OpenviduConfig openviduConfig;
|
||||
|
||||
private InfoHandler infoHandler;
|
||||
private CallDetailRecord CDR;
|
||||
|
@ -102,7 +107,9 @@ public class KurentoParticipant extends Participant {
|
|||
this.publisher.getEndpoint().addTag("name", publisherStreamId);
|
||||
addEndpointListeners(this.publisher);
|
||||
|
||||
CDR.recordNewPublisher(this, this.session.getSessionId(), mediaOptions);
|
||||
if (openviduConfig.isCdrEnabled()) {
|
||||
CDR.recordNewPublisher(this, this.session.getSessionId(), mediaOptions);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -307,7 +314,7 @@ public class KurentoParticipant extends Participant {
|
|||
log.info("PARTICIPANT {}: Is now receiving video from {} in room {}", this.getParticipantPublicId(),
|
||||
senderName, this.session.getSessionId());
|
||||
|
||||
if (!ProtocolElements.RECORDER_PARTICIPANT_PUBLICID.equals(this.getParticipantPublicId())) {
|
||||
if (openviduConfig.isCdrEnabled() && !ProtocolElements.RECORDER_PARTICIPANT_PUBLICID.equals(this.getParticipantPublicId())) {
|
||||
CDR.recordNewSubscriber(this, this.session.getSessionId(), sender.getParticipantPublicId());
|
||||
}
|
||||
|
||||
|
@ -468,7 +475,9 @@ public class KurentoParticipant extends Participant {
|
|||
this.streaming = false;
|
||||
publisher = null;
|
||||
|
||||
CDR.stopPublisher(this.getParticipantPublicId(), reason);
|
||||
if (openviduConfig.isCdrEnabled()) {
|
||||
CDR.stopPublisher(this.getParticipantPublicId(), reason);
|
||||
}
|
||||
|
||||
} else {
|
||||
log.warn("PARTICIPANT {}: Trying to release publisher endpoint but is null", getParticipantPublicId());
|
||||
|
@ -480,7 +489,7 @@ public class KurentoParticipant extends Participant {
|
|||
subscriber.unregisterErrorListeners();
|
||||
releaseElement(senderName, subscriber.getEndpoint());
|
||||
|
||||
if (!ProtocolElements.RECORDER_PARTICIPANT_PUBLICID.equals(this.getParticipantPublicId())) {
|
||||
if (openviduConfig.isCdrEnabled() && !ProtocolElements.RECORDER_PARTICIPANT_PUBLICID.equals(this.getParticipantPublicId())) {
|
||||
CDR.stopSubscriber(this.getParticipantPublicId(), senderName, reason);
|
||||
}
|
||||
|
||||
|
|
|
@ -35,12 +35,14 @@ import org.kurento.client.KurentoClient;
|
|||
import org.kurento.client.MediaPipeline;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import io.openvidu.client.OpenViduException;
|
||||
import io.openvidu.client.OpenViduException.Code;
|
||||
import io.openvidu.client.internal.ProtocolElements;
|
||||
import io.openvidu.java.client.SessionProperties;
|
||||
import io.openvidu.server.cdr.CallDetailRecord;
|
||||
import io.openvidu.server.config.OpenviduConfig;
|
||||
import io.openvidu.server.core.Participant;
|
||||
import io.openvidu.server.core.Session;
|
||||
|
||||
|
@ -51,6 +53,9 @@ public class KurentoSession implements Session {
|
|||
|
||||
private final static Logger log = LoggerFactory.getLogger(Session.class);
|
||||
public static final int ASYNC_LATCH_TIMEOUT = 30;
|
||||
|
||||
@Autowired
|
||||
protected OpenviduConfig openviduConfig;
|
||||
|
||||
private final ConcurrentMap<String, KurentoParticipant> participants = new ConcurrentHashMap<>();
|
||||
private String sessionId;
|
||||
|
@ -89,7 +94,7 @@ public class KurentoSession implements Session {
|
|||
public String getSessionId() {
|
||||
return this.sessionId;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public SessionProperties getSessionProperties() {
|
||||
return this.sessionProperties;
|
||||
|
@ -109,8 +114,8 @@ public class KurentoSession implements Session {
|
|||
});
|
||||
|
||||
log.info("SESSION {}: Added participant {}", sessionId, participant);
|
||||
|
||||
if (!ProtocolElements.RECORDER_PARTICIPANT_PUBLICID.equals(participant.getParticipantPublicId())) {
|
||||
|
||||
if (openviduConfig.isCdrEnabled() && !ProtocolElements.RECORDER_PARTICIPANT_PUBLICID.equals(participant.getParticipantPublicId())) {
|
||||
CDR.recordParticipantJoined(participant, sessionId);
|
||||
}
|
||||
}
|
||||
|
@ -165,8 +170,8 @@ public class KurentoSession implements Session {
|
|||
}
|
||||
this.removeParticipant(participant, reason);
|
||||
participant.close(reason);
|
||||
|
||||
if (!ProtocolElements.RECORDER_PARTICIPANT_PUBLICID.equals(participant.getParticipantPublicId())) {
|
||||
|
||||
if (openviduConfig.isCdrEnabled() && !ProtocolElements.RECORDER_PARTICIPANT_PUBLICID.equals(participant.getParticipantPublicId())) {
|
||||
CDR.recordParticipantLeft(participant, participant.getSession().getSessionId(), reason);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@
|
|||
<pattern>%m\n</pattern>
|
||||
</layout>
|
||||
</appender>
|
||||
<logger name="io.openvidu.server.cdr.CallDetailRecord">
|
||||
<logger name="io.openvidu.server.cdr.CDRLoggerFile">
|
||||
<level value="INFO" />
|
||||
<appender-ref ref="CDR" />
|
||||
</logger>
|
||||
|
|
Loading…
Reference in New Issue