diff --git a/charts/calling-service/Chart.yaml b/charts/calling-service/Chart.yaml index c162c8d1fd98998f473b798fa78a0329865b2044..5fa2a3d88e22a43ca44948697e3a5c7a5ed393a1 100644 --- a/charts/calling-service/Chart.yaml +++ b/charts/calling-service/Chart.yaml @@ -2,4 +2,4 @@ apiVersion: v1 appVersion: "1.0" description: Calling service Helm chart name: calling-service -version: 0.2.15 +version: 0.2.18 diff --git a/charts/calling-service/templates/destinationrule.yaml b/charts/calling-service/templates/destinationrule.yaml index 14ab3bc31afffd2d4f3fd0235e247d604144a587..c0de141bf83ab814789c3736ee62c10c36eae94f 100644 --- a/charts/calling-service/templates/destinationrule.yaml +++ b/charts/calling-service/templates/destinationrule.yaml @@ -13,6 +13,7 @@ spec: connectionPool: http: http2MaxRequests: 30000 + h2UpgradePolicy: UPGRADE --- apiVersion: networking.istio.io/v1alpha3 kind: DestinationRule @@ -29,3 +30,4 @@ spec: connectionPool: http: http2MaxRequests: 30000 + h2UpgradePolicy: UPGRADE diff --git a/charts/calling-service/templates/history-service.yaml b/charts/calling-service/templates/history-service.yaml index 4e0b79fa363164fd8801fd16e18cdcfb8be9cbbc..155e75939dbddfd29beabec6222d9f9f6817a984 100644 --- a/charts/calling-service/templates/history-service.yaml +++ b/charts/calling-service/templates/history-service.yaml @@ -1,6 +1,8 @@ kind: Service apiVersion: v1 metadata: + annotations: + cloud.google.com/app-protocols: '{"h2c-history":"HTTP2"}' name: {{ template "calling-service.fullname" . }}-history labels: app: {{ template "calling-service.name" . }}-history @@ -20,4 +22,4 @@ spec: - protocol: TCP port: 41714 targetPort: 41714 - name: web-history + name: h2c-history diff --git a/charts/calling-service/templates/service.yaml b/charts/calling-service/templates/service.yaml index e42e9d751771e2b9022c11d2da5ba563eb1ebc26..3e21d92d2162c7ee8cfcc2e43dadb3f239280b91 100644 --- a/charts/calling-service/templates/service.yaml +++ b/charts/calling-service/templates/service.yaml @@ -1,6 +1,9 @@ kind: Service apiVersion: v1 metadata: + annotations: + cloud.google.com/app-protocols: '{"h2c-focus":"HTTP2"}' + name: {{ template "calling-service.fullname" . }} labels: app: {{ template "calling-service.name" . }} @@ -20,4 +23,4 @@ spec: - protocol: TCP port: 41514 targetPort: 41514 - name: http-focus + name: h2c-focus diff --git a/components/jitsi-backend/jvb/Dockerfile b/components/jitsi-backend/jvb/Dockerfile index 363530e374fa5b34afaab760cefdd3d8be59cf3e..9e21bc3680aefcd3e770a9eef8cdb1e0ef2615ae 100644 --- a/components/jitsi-backend/jvb/Dockerfile +++ b/components/jitsi-backend/jvb/Dockerfile @@ -2,38 +2,19 @@ FROM debian:stretch MAINTAINER Jarle Aase -ENV VIDEOBRIDGE_BUILDNUM="1124" - ENV STUN=stun.stunprotocol.org BRIDGE_IP=127.0.0.1 REST_IP=8080 BRIDGE_TCP_PORT=4443 BRIDGE_UDP_PORT=10000 # Install videobridge and dependencies USER root -RUN apt-get update && apt-get -y install \ - wget \ - unzip curl \ - default-jre-headless -RUN wget https://download.jitsi.org/jitsi-videobridge/linux/jitsi-videobridge-linux-x64-${VIDEOBRIDGE_BUILDNUM}.zip -RUN unzip jitsi-videobridge-linux-x64-${VIDEOBRIDGE_BUILDNUM}.zip && rm jitsi-videobridge-linux-x64-${VIDEOBRIDGE_BUILDNUM}.zip -RUN wget -N https://github.com/angel-popov/status/releases/download/tmp1/jitsi-videobridge.jar -P jitsi-videobridge-linux-x64-${VIDEOBRIDGE_BUILDNUM} - -#ADD conf/logging.properties /logging.properties -#RUN cp -f /logging.properties /jitsi-videobridge-linux-x64-${VIDEOBRIDGE_BUILDNUM}/lib +RUN apt update && apt install -y wget unzip curl default-jre-headless +RUN wget https://download.jitsi.org/stable/jitsi-videobridge2_2.1-163-g63d2f9da-1_all.deb +RUN apt install -y ./jitsi-videobridge2_2.1-163-g63d2f9da-1_all.deb -# Create videobridge user -RUN mkdir --parents /jvb/.sip-communicator && \ - groupadd -r jvb && \ - useradd -r -g jvb -d /jvb -s /sbin/nologin -c "Jitsi Videobridge User" jvb - # Configure and run -#USER jvb ADD conf/sip-communicator.properties /jvb/.sip-communicator/sip-communicator.properties ADD conf/logging.properties /jvb/.sip-communicator/logging.properties ADD scripts/run.sh /jvb/run.sh - -RUN chown -R jvb:jvb /jvb -USER jvb - +RUN chown -R jvb /jvb EXPOSE $REST_IP $BRIDGE_UDP_PORT/udp $BRIDGE_TCP_PORT - -CMD ["/jvb/run.sh"] +USER jvb diff --git a/components/jitsi-backend/jvb/scripts/run.sh b/components/jitsi-backend/jvb/scripts/run.sh index 683f0a22788280caea858fb9bb9bec7e41208527..2584a30b42fe870c9eaf14be7323be61c2ff6e3f 100755 --- a/components/jitsi-backend/jvb/scripts/run.sh +++ b/components/jitsi-backend/jvb/scripts/run.sh @@ -8,5 +8,4 @@ for VARIABLE in `env | cut -f1 -d=`; do sed -i "s={{ $VARIABLE }}=${!VARIABLE}=g" /jvb/.sip-communicator/sip-communicator.properties done -exec jitsi-videobridge-linux-x64-$VIDEOBRIDGE_BUILDNUM/jvb.sh \ - --apis=rest +exec /usr/share/jitsi-videobridge/jvb.sh --apis=rest diff --git a/focus/src/main/java/com/nynjacoin/nccs/call/service/Call.java b/focus/src/main/java/com/nynjacoin/nccs/call/service/Call.java index 644929d26a56cc635a5d14160fd4dd5c0ffdf62f..fb7438c34ed211e5d105d5308e1c2e80afd3ecdf 100644 --- a/focus/src/main/java/com/nynjacoin/nccs/call/service/Call.java +++ b/focus/src/main/java/com/nynjacoin/nccs/call/service/Call.java @@ -58,7 +58,7 @@ public class Call { private static final Long CONFIRM_TIMEOUT = 30000L; private static final Long ACCEPT_TIMEOUT = 30000L; private static final Long DESTROY_TIMEOUT = 10000L; - static final Long MISSING_PARTY_TIMEOUT = 30000L; + private static final Long MISSING_PARTY_TIMEOUT = 30000L; private static final int MAX_PUSH_OFFER_SIZE = 3 * 1024; private static final String OFFER_TRUNCATED = "OFFER_TRUNCATED"; @@ -721,16 +721,9 @@ public class Call { String from = callInfo.getFrom().getValue(); String to = callInfo.getTo().getValue(); - String feedId; - if (from.compareTo(to) < 0) { - feedId = composeFeedId(from, to); - } else { - feedId = composeFeedId(to, from); - } - parent.getBubbleSender().sendForP2P( from, - feedId, + to, callInfo.getId(), (int)(getDuration() / 1000), getStartTime().getTime(), @@ -754,10 +747,6 @@ public class Call { return ContentType.UNKNOWN; } - private String composeFeedId(String left, String right) { - return left + '/' + right; - } - private String getToAccountId() { Address address = callInfo.getTo(); assert address.getType() == Type.ACCOUNT; diff --git a/focus/src/main/java/com/nynjacoin/nccs/restclient/bubble/BubbleSender.java b/focus/src/main/java/com/nynjacoin/nccs/restclient/bubble/BubbleSender.java index 8f19b6b35dde63fef94edc10edaa21ae1a50018b..2e075e928f2d6bdf627e2e5fc0b454842a5507ae 100644 --- a/focus/src/main/java/com/nynjacoin/nccs/restclient/bubble/BubbleSender.java +++ b/focus/src/main/java/com/nynjacoin/nccs/restclient/bubble/BubbleSender.java @@ -2,10 +2,10 @@ package com.nynjacoin.nccs.restclient.bubble; import com.nynjacoin.nccs.focus.config.FocusConfigKey; import com.nynjacoin.nccs.lib.vertx.restclient.AuthenticationHandler; -import com.nynjacoin.nccs.lib.vertx.restclient.RestClientBase; -import com.nynjacoin.nccs.lib.vertx.restclient.RetryExecutor; +import com.nynjacoin.nccs.lib.vertx.restclient.JsonRetryExecutor; import com.nynjacoin.nccs.lib.vertx.restclient.WebClientFactory; import com.nynjacoin.nccs.protocol.def.CallEndedBy; +import io.vertx.core.Future; import io.vertx.core.Vertx; import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; @@ -15,7 +15,7 @@ import java.util.Objects; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -public class BubbleSender extends RestClientBase { +public class BubbleSender { public enum AnswerStatus { ANSWERED("answered"), @@ -51,8 +51,16 @@ public class BubbleSender extends RestClientBase { } } + private static final int DEFAULT_MAX_RETRIES = 3; + private static final long DEFAULT_RETRY_MILLISECONDS = 100L; + private static final Logger LOGGER = LogManager.getLogger(BubbleSender.class); + private final WebClient webClient; + private final AuthenticationHandler authenticationHandler; + private final JsonRetryExecutor retryExecutor; + private final String rootUrl; + public static BubbleSender create(Vertx vertx, JsonObject config) { int poolSize = config.getInteger(FocusConfigKey.BUBBLE_PER_REQUEST_POOL_SIZE.key(), 32); WebClient webClient = WebClientFactory.create(vertx, poolSize); @@ -60,12 +68,11 @@ public class BubbleSender extends RestClientBase { String auth = config.getString(FocusConfigKey.BUBBLE_KEY.key()); AuthenticationHandler authenticationHandler = AuthenticationHandler.create(auth); - RetryExecutor retryExecutor = RetryExecutor.newBuilder(vertx) - .setOrDefaultMaxRetries(config.getInteger( - FocusConfigKey.BUBBLE_MAX_RETRIES.key())) - .setOrDefaultRetryMilliseconds(config.getLong( - FocusConfigKey.BUBBLE_RETRY_AFTER_MILLISECONDS.key())) - .build(); + JsonRetryExecutor retryExecutor = new JsonRetryExecutor( + vertx, + config.getInteger(FocusConfigKey.BUBBLE_MAX_RETRIES.key(), DEFAULT_MAX_RETRIES), + config.getLong( + FocusConfigKey.BUBBLE_RETRY_AFTER_MILLISECONDS.key(), DEFAULT_RETRY_MILLISECONDS)); String rootUrl = config.getString(FocusConfigKey.BUBBLE_URL.key()); Objects.requireNonNull(rootUrl); @@ -76,13 +83,16 @@ public class BubbleSender extends RestClientBase { BubbleSender( WebClient webClient, AuthenticationHandler authenticationHandler , - RetryExecutor retryExecutor, + JsonRetryExecutor retryExecutor, String rootUrl) { - super(webClient, authenticationHandler, retryExecutor, rootUrl); + this.webClient = webClient; + this.authenticationHandler = authenticationHandler; + this.retryExecutor = retryExecutor; + this.rootUrl = rootUrl; } - public void sendForConference( + public Future sendForConference( String senderAccountId, String feedId, String callId, @@ -104,7 +114,7 @@ public class BubbleSender extends RestClientBase { .put("count", membersCount) .put("recipients", to); - send( + return send( senderAccountId, body, feedId, @@ -116,9 +126,9 @@ public class BubbleSender extends RestClientBase { endedBy); } - public void sendForP2P( + public Future sendForP2P( String senderAccountId, - String feedId, + String to, String callId, int duration, long startTime, @@ -126,11 +136,18 @@ public class BubbleSender extends RestClientBase { ContentType contentType, CallEndedBy endedBy) { + String feedId; + if (senderAccountId.compareTo(to) < 0) { + feedId = composeFeedId(senderAccountId, to); + } else { + feedId = composeFeedId(to, senderAccountId); + } + JsonObject body = new JsonObject() .put("type", "p2p"); - send( + return send( senderAccountId, body, feedId, @@ -142,7 +159,11 @@ public class BubbleSender extends RestClientBase { endedBy); } - private void send( + private String composeFeedId(String left, String right) { + return left + '/' + right; + } + + private Future send( String senderAccountId, JsonObject body, String feedId, @@ -153,10 +174,10 @@ public class BubbleSender extends RestClientBase { ContentType contentType, CallEndedBy endedBy) { - var request = getWebClient() - .postAbs(getRootUrl()) + var request = webClient + .postAbs(rootUrl) .putHeader("PhoneId", senderAccountId); - request = getAuthenticationHandler().apply(request); + request = authenticationHandler.apply(request); body .put("feed_id", feedId) @@ -168,14 +189,15 @@ public class BubbleSender extends RestClientBase { .put("ended_by", endedBy.name().toLowerCase()) ; - getRetryExecutor().execute(request, body).setHandler( - event -> { - if (event.succeeded()) { - LOGGER.debug("Bubble {} for {} SENT", callId, feedId); - } else { - LOGGER.error("Bubble {} for {} FAILED {}", callId, feedId, event.cause()); - } - } - ); + return retryExecutor.execute(request, body) + .recover(cause -> { + LOGGER.error("Bubble {} for {} FAILED {}", callId, feedId, cause); + return Future.failedFuture(cause); + }) + .map(res -> { + LOGGER.debug("Bubble {} for {} SENT", callId, feedId); + return null; + }) + ; } } diff --git a/focus/src/main/java/com/nynjacoin/nccs/restclient/bubble/NoopBubbleSender.java b/focus/src/main/java/com/nynjacoin/nccs/restclient/bubble/NoopBubbleSender.java index 27965bb067ebb009b55c55ad4ea41d2446ae0589..507cb02e84b233ab0cda07856fc2ad23f1fe57c2 100644 --- a/focus/src/main/java/com/nynjacoin/nccs/restclient/bubble/NoopBubbleSender.java +++ b/focus/src/main/java/com/nynjacoin/nccs/restclient/bubble/NoopBubbleSender.java @@ -1,6 +1,7 @@ package com.nynjacoin.nccs.restclient.bubble; import com.nynjacoin.nccs.protocol.def.CallEndedBy; +import io.vertx.core.Future; import java.util.List; public class NoopBubbleSender extends BubbleSender { @@ -10,7 +11,7 @@ public class NoopBubbleSender extends BubbleSender { } @Override - public void sendForConference( + public Future sendForConference( String senderAccountId, String feedId, String callId, @@ -21,10 +22,12 @@ public class NoopBubbleSender extends BubbleSender { CallEndedBy endedBy, int membersCount, List recipients) - {} + { + return Future.succeededFuture(); + } @Override - public void sendForP2P( + public Future sendForP2P( String senderAccountId, String feedId, String callId, @@ -33,5 +36,7 @@ public class NoopBubbleSender extends BubbleSender { AnswerStatus answerStatus, ContentType contentType, CallEndedBy endedBy) - {} + { + return Future.succeededFuture(); + } } diff --git a/focus/src/main/java/com/nynjacoin/nccs/restclient/chatroom/ChatRoomClient.java b/focus/src/main/java/com/nynjacoin/nccs/restclient/chatroom/ChatRoomClient.java index b301e297b2dd91f02e4b5b60fd66a7f7480005e9..5fc45f83945049780cb703499863c4676d33bc4c 100644 --- a/focus/src/main/java/com/nynjacoin/nccs/restclient/chatroom/ChatRoomClient.java +++ b/focus/src/main/java/com/nynjacoin/nccs/restclient/chatroom/ChatRoomClient.java @@ -2,10 +2,9 @@ package com.nynjacoin.nccs.restclient.chatroom; import com.nynjacoin.nccs.focus.config.FocusConfigKey; import com.nynjacoin.nccs.lib.vertx.restclient.AuthenticationHandler; -import com.nynjacoin.nccs.lib.vertx.restclient.RestClientBase; +import com.nynjacoin.nccs.lib.vertx.restclient.JsonRetryExecutor; import com.nynjacoin.nccs.lib.vertx.restclient.ValidatingJsonArray; import com.nynjacoin.nccs.lib.vertx.restclient.ValidatingJsonObject; -import com.nynjacoin.nccs.lib.vertx.restclient.RetryExecutor; import com.nynjacoin.nccs.lib.vertx.restclient.WebClientFactory; import com.nynjacoin.nccs.protocol.def.Void; import com.nynjacoin.nccs.lib.grpc.protocol.error.NccsError; @@ -20,10 +19,14 @@ import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -public class ChatRoomClient extends RestClientBase { +public class ChatRoomClient { + static final int DEFAULT_MAX_RETRIES = 3; + static final long DEFAULT_RETRY_MILLISECONDS = 100L; + private static final Logger LOGGER = LogManager.getLogger(ChatRoomClient.class); private static final String HEADER_ACCOUNT_ID = "PhoneId"; + private static final String HEADER_CONTENT_TYPE = "Content-Type"; private static final String QUERY_PARAM_ROOM_ID = "room_id"; private static final String QUERY_PARAM_ACCOUNT_IDS = "phone_ids"; @@ -37,6 +40,11 @@ public class ChatRoomClient extends RestClientBase { private static final String FIELD_IS_JOINING = "join"; private static final String FIELD_ACCOUNT_IDS = QUERY_PARAM_ACCOUNT_IDS; + private final WebClient webClient; + private final AuthenticationHandler authenticationHandler; + private final JsonRetryExecutor retryExecutor; + private final String rootUrl; + public static ChatRoomClient create(Vertx vertx, JsonObject config) { int poolSize = config.getInteger(FocusConfigKey.CHAT_ROOM_PER_REQUEST_POOL_SIZE.key(), 32); WebClient webClient = WebClientFactory.create(vertx, poolSize); @@ -44,12 +52,11 @@ public class ChatRoomClient extends RestClientBase { String auth = config.getString(FocusConfigKey.CHAT_ROOM_KEY.key()); AuthenticationHandler authenticationHandler = AuthenticationHandler.create(auth); - RetryExecutor retryExecutor = RetryExecutor.newBuilder(vertx) - .setOrDefaultMaxRetries(config.getInteger( - FocusConfigKey.CHAT_ROOM_MAX_RETRIES.key())) - .setOrDefaultRetryMilliseconds(config.getLong( - FocusConfigKey.CHAT_ROOM_RETRY_AFTER_MILLISECONDS.key())) - .build(); + JsonRetryExecutor retryExecutor = new JsonRetryExecutor( + vertx, + config.getInteger(FocusConfigKey.CHAT_ROOM_MAX_RETRIES.key(), DEFAULT_MAX_RETRIES), + config.getLong(FocusConfigKey.CHAT_ROOM_RETRY_AFTER_MILLISECONDS.key(), + DEFAULT_RETRY_MILLISECONDS)); String rootUrl = config.getString(FocusConfigKey.CHAT_ROOM_URL.key()); Objects.requireNonNull(rootUrl); @@ -62,20 +69,24 @@ public class ChatRoomClient extends RestClientBase { ChatRoomClient( WebClient webClient, AuthenticationHandler authenticationHandler , - RetryExecutor retryExecutor, + JsonRetryExecutor retryExecutor, String rootUrl) { - super(webClient, authenticationHandler, retryExecutor, rootUrl); - membersPath = getRootUrl() + "/members"; + this.webClient = webClient; + this.authenticationHandler = authenticationHandler; + this.retryExecutor = retryExecutor; + this.rootUrl = rootUrl; + membersPath = rootUrl + "/members"; } public Future createRoom(String ownerAccountId) { - var request = getWebClient() - .postAbs(getRootUrl()) + var request = webClient + .postAbs(rootUrl) .putHeader(HEADER_ACCOUNT_ID, ownerAccountId) - ; - request = getAuthenticationHandler().apply(request); - var response = getRetryExecutor().execute(request); + .putHeader(HEADER_CONTENT_TYPE, "application/json"); + + request =authenticationHandler.apply(request); + var response = retryExecutor.execute(request); Future result = Future.future(); response.compose(rawBody -> { ValidatingJsonObject body = wrapAndCheck(rawBody); @@ -91,14 +102,14 @@ public class ChatRoomClient extends RestClientBase { } public Future areAllMembers(String ownerAccountId, String roomId, List accountIds) { - var request = getWebClient() + var request = webClient .getAbs(membersPath) .putHeader(HEADER_ACCOUNT_ID, ownerAccountId) .addQueryParam(QUERY_PARAM_ROOM_ID, roomId) .addQueryParam(QUERY_PARAM_ACCOUNT_IDS, StringUtils.join(accountIds, ',')) ; - request = getAuthenticationHandler().apply(request); - var response = getRetryExecutor().execute(request); + request =authenticationHandler.apply(request); + var response = retryExecutor.execute(request); Future result = Future.future(); response.compose( rawBody-> { @@ -132,11 +143,11 @@ public class ChatRoomClient extends RestClientBase { String roomId, List accountIdsToAdd) { - var request = getWebClient() + var request = webClient .postAbs(membersPath) .putHeader(HEADER_ACCOUNT_ID, ownerAccountId) ; - request = getAuthenticationHandler().apply(request); + request =authenticationHandler.apply(request); var body = new JsonObject() .put(FIELD_ROOM_ID, roomId) @@ -144,54 +155,54 @@ public class ChatRoomClient extends RestClientBase { .put(FIELD_ACCOUNT_IDS, new JsonArray(accountIdsToAdd)) ; - var response = getRetryExecutor().execute(request, body); + var response = retryExecutor.execute(request, body); Future result = Future.future(); response.compose(rawBody -> result.complete(), result); return result; } public Future joinMember(String accountId, String roomId) { - var request = getWebClient() + var request = webClient .postAbs(membersPath) .putHeader(HEADER_ACCOUNT_ID, accountId) ; - request = getAuthenticationHandler().apply(request); + request =authenticationHandler.apply(request); var body = new JsonObject() .put(FIELD_ROOM_ID, roomId) .put(FIELD_IS_JOINING, true) ; - var response = getRetryExecutor().execute(request, body); + var response = retryExecutor.execute(request, body); Future result = Future.future(); response.compose(rawBody -> result.complete(), result); return result; } public Future removeMember(String ownerAccountId, String roomId, String accountId) { - var request = getWebClient() + var request = webClient .deleteAbs(membersPath) .putHeader(HEADER_ACCOUNT_ID, ownerAccountId) .addQueryParam(QUERY_PARAM_ROOM_ID, roomId) .addQueryParam(QUERY_PARAM_ACCOUNT_IDS, accountId) ; - request = getAuthenticationHandler().apply(request); + request =authenticationHandler.apply(request); - var response = getRetryExecutor().execute(request); + var response = retryExecutor.execute(request); Future result = Future.future(); response.compose(rawBody -> result.complete(), result); return result; } public Future tryDeleteRoom(String ownerAccountId, String roomId, boolean flag) { - var request = getWebClient() - .deleteAbs(getRootUrl()) + var request = webClient + .deleteAbs(rootUrl) .putHeader(HEADER_ACCOUNT_ID, ownerAccountId) .addQueryParam(QUERY_PARAM_ROOM_ID, roomId) .addQueryParam(QUERY_PARAM_DELETE, String.valueOf(flag)) ; - request = getAuthenticationHandler().apply(request); - var response = getRetryExecutor().execute(request); + request =authenticationHandler.apply(request); + var response = retryExecutor.execute(request); Future result = Future.future(); response.compose( rawBody -> { diff --git a/focus/src/main/java/com/nynjacoin/nccs/restclient/push/PushNotificationSender.java b/focus/src/main/java/com/nynjacoin/nccs/restclient/push/PushNotificationSender.java index 48b8a48e3db3ca524ee0a754db4c45aa05c2084b..f5b4d2b67030438403e2846bd6b42af044853fe3 100644 --- a/focus/src/main/java/com/nynjacoin/nccs/restclient/push/PushNotificationSender.java +++ b/focus/src/main/java/com/nynjacoin/nccs/restclient/push/PushNotificationSender.java @@ -2,8 +2,7 @@ package com.nynjacoin.nccs.restclient.push; import com.nynjacoin.nccs.focus.config.FocusConfigKey; import com.nynjacoin.nccs.lib.vertx.restclient.AuthenticationHandler; -import com.nynjacoin.nccs.lib.vertx.restclient.RestClientBase; -import com.nynjacoin.nccs.lib.vertx.restclient.RetryExecutor; +import com.nynjacoin.nccs.lib.vertx.restclient.JsonRetryExecutor; import com.nynjacoin.nccs.lib.vertx.restclient.WebClientFactory; import io.vertx.core.Vertx; import io.vertx.core.json.JsonArray; @@ -15,10 +14,16 @@ import org.apache.logging.log4j.Logger; import java.util.List; -public class PushNotificationSender extends RestClientBase { +public class PushNotificationSender { private static final Logger LOGGER = LogManager.getLogger(PushNotificationSender.class); + private static final int DEFAULT_MAX_RETRIES = 3; + private static final long DEFAULT_RETRY_MILLISECONDS = 100L; + private final WebClient webClient; + private final AuthenticationHandler authenticationHandler; + private final JsonRetryExecutor retryExecutor; + private final String rootUrl; private final Integer pushTtl; public static PushNotificationSender create(Vertx vertx, final JsonObject config) { @@ -28,12 +33,11 @@ public class PushNotificationSender extends RestClientBase { String auth = config.getString(FocusConfigKey.PUSH_KEY.key()); AuthenticationHandler authenticationHandler = AuthenticationHandler.create(auth); - RetryExecutor retryExecutor = RetryExecutor.newBuilder(vertx) - .setOrDefaultMaxRetries(config.getInteger( - FocusConfigKey.PUSH_MAX_RETRIES.key())) - .setOrDefaultRetryMilliseconds(config.getLong( - FocusConfigKey.PUSH_RETRY_AFTER_MILLISECONDS.key())) - .build(); + var retryExecutor = new JsonRetryExecutor( + vertx, + config.getInteger(FocusConfigKey.PUSH_MAX_RETRIES.key(), DEFAULT_MAX_RETRIES), + config.getLong( + FocusConfigKey.PUSH_RETRY_AFTER_MILLISECONDS.key(), DEFAULT_RETRY_MILLISECONDS)); String rootUrl = config.getString(FocusConfigKey.PUSH_URL.key()); if (Objects.isNull(rootUrl)) { @@ -59,11 +63,14 @@ public class PushNotificationSender extends RestClientBase { PushNotificationSender( WebClient webClient, AuthenticationHandler authenticationHandler , - RetryExecutor retryExecutor, + JsonRetryExecutor retryExecutor, String rootUrl, Integer pushTtl) { - super(webClient, authenticationHandler, retryExecutor, rootUrl); + this.webClient = webClient; + this.authenticationHandler = authenticationHandler; + this.retryExecutor = retryExecutor; + this.rootUrl = rootUrl; this.pushTtl = pushTtl; } @@ -71,8 +78,8 @@ public class PushNotificationSender extends RestClientBase { // Fire and forget. public void sendNotification(String id, List recipients, String module, String payload) { - var request = getWebClient().postAbs(getRootUrl()); - request = getAuthenticationHandler().apply(request); + var request = webClient.postAbs(rootUrl); + request = authenticationHandler.apply(request); JsonArray to = new JsonArray(); for (String r : recipients) { @@ -87,7 +94,7 @@ public class PushNotificationSender extends RestClientBase { .put("ttl", pushTtl) .put("payload", payload); - getRetryExecutor().execute(request, body).setHandler( + retryExecutor.execute(request, body).setHandler( event -> { if (event.succeeded()) { LOGGER.debug("Push notification {} to {} SENT", id, to); diff --git a/focus/src/main/java/com/nynjacoin/nccs/restclient/roomlink/RoomLinkClient.java b/focus/src/main/java/com/nynjacoin/nccs/restclient/roomlink/RoomLinkClient.java index dc67bcef814f0e521e378e13bc1fcfced7c4af24..4d3820d3a6df0bcf88b4f737b159eb15b0522352 100644 --- a/focus/src/main/java/com/nynjacoin/nccs/restclient/roomlink/RoomLinkClient.java +++ b/focus/src/main/java/com/nynjacoin/nccs/restclient/roomlink/RoomLinkClient.java @@ -3,8 +3,7 @@ package com.nynjacoin.nccs.restclient.roomlink; import com.nynjacoin.nccs.focus.config.FocusConfigKey; import com.nynjacoin.nccs.lib.vertx.restclient.AuthenticationHandler; import com.nynjacoin.nccs.lib.vertx.restclient.JsonHttpException; -import com.nynjacoin.nccs.lib.vertx.restclient.RestClientBase; -import com.nynjacoin.nccs.lib.vertx.restclient.RetryExecutor; +import com.nynjacoin.nccs.lib.vertx.restclient.JsonRetryExecutor; import com.nynjacoin.nccs.lib.vertx.restclient.ValidatingJsonObject; import com.nynjacoin.nccs.lib.vertx.restclient.WebClientFactory; import com.nynjacoin.nccs.lib.grpc.protocol.error.NccsError; @@ -14,10 +13,17 @@ import io.vertx.core.json.JsonObject; import io.vertx.ext.web.client.WebClient; import java.util.Objects; -public class RoomLinkClient extends RestClientBase { +public class RoomLinkClient { private static final String FIELD_ROOM_ID = "room_id"; private static final String FIELD_ROOM_NAME = "room_name"; + private static final int DEFAULT_MAX_RETRIES = 3; + private static final long DEFAULT_RETRY_MILLISECONDS = 100L; + + private final WebClient webClient; + private final AuthenticationHandler authenticationHandler; + private final JsonRetryExecutor retryExecutor; + private final String rootUrl; public static RoomLinkClient create(Vertx vertx, JsonObject config) { int poolSize = config.getInteger(FocusConfigKey.ROOM_LINK_PER_REQUEST_POOL_SIZE.key(), 32); @@ -26,12 +32,11 @@ public class RoomLinkClient extends RestClientBase { String auth = config.getString(FocusConfigKey.ROOM_LINK_KEY.key()); AuthenticationHandler authenticationHandler = AuthenticationHandler.create(auth); - RetryExecutor retryExecutor = RetryExecutor.newBuilder(vertx) - .setOrDefaultMaxRetries(config.getInteger( - FocusConfigKey.ROOM_LINK_MAX_RETRIES.key())) - .setOrDefaultRetryMilliseconds(config.getLong( - FocusConfigKey.ROOM_LINK_RETRY_AFTER_MILLISECONDS.key())) - .build(); + var retryExecutor = new JsonRetryExecutor( + vertx, + config.getInteger(FocusConfigKey.ROOM_LINK_MAX_RETRIES.key(), DEFAULT_MAX_RETRIES), + config.getLong( + FocusConfigKey.ROOM_LINK_RETRY_AFTER_MILLISECONDS.key(), DEFAULT_RETRY_MILLISECONDS)); String rootUrl = config.getString(FocusConfigKey.ROOM_LINK_URL.key()); Objects.requireNonNull(rootUrl); @@ -41,16 +46,19 @@ public class RoomLinkClient extends RestClientBase { private RoomLinkClient(WebClient webClient, AuthenticationHandler authenticationHandler, - RetryExecutor retryExecutor, + JsonRetryExecutor retryExecutor, String rootUrl) { - super(webClient, authenticationHandler, retryExecutor, rootUrl); + this.webClient = webClient; + this.authenticationHandler = authenticationHandler; + this.retryExecutor = retryExecutor; + this.rootUrl = rootUrl; } public Future getRoomInfo(String linkId) { - var request = getWebClient().getAbs(getRoomUrl(linkId)); - request = getAuthenticationHandler().apply(request); - var response = getRetryExecutor().execute(request); + var request = webClient.getAbs(getRoomUrl(linkId)); + request = authenticationHandler.apply(request); + var response = retryExecutor.execute(request); return response .map(rawBody -> { ValidatingJsonObject body = ValidatingJsonObject.wrap(rawBody); @@ -78,6 +86,6 @@ public class RoomLinkClient extends RestClientBase { } private String getRoomUrl(String linkId) { - return getRootUrl() + '/' + linkId + "/room_id"; + return rootUrl + '/' + linkId + "/room_id"; } } diff --git a/focus/src/test/java/com/nynjacoin/nccs/restclient/bubble/BubbleSenderManualTest.java b/focus/src/test/java/com/nynjacoin/nccs/restclient/bubble/BubbleSenderManualTest.java new file mode 100644 index 0000000000000000000000000000000000000000..e05bc42bafb1422a05edff827b549ef6b0ddccd7 --- /dev/null +++ b/focus/src/test/java/com/nynjacoin/nccs/restclient/bubble/BubbleSenderManualTest.java @@ -0,0 +1,68 @@ +package com.nynjacoin.nccs.restclient.bubble; + +import com.nynjacoin.nccs.focus.config.FocusConfigKey; +import com.nynjacoin.nccs.protocol.def.CallEndedBy; +import com.nynjacoin.nccs.restclient.bubble.BubbleSender.AnswerStatus; +import com.nynjacoin.nccs.restclient.bubble.BubbleSender.ContentType; +import io.vertx.core.Vertx; +import io.vertx.core.json.JsonObject; +import io.vertx.ext.unit.TestContext; +import io.vertx.ext.unit.junit.RunTestOnContext; +import io.vertx.ext.unit.junit.VertxUnitRunner; +import java.util.List; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(VertxUnitRunner.class) +@Ignore +public class BubbleSenderManualTest { + + private BubbleSender bubbleSender; + + @ClassRule + public static RunTestOnContext rule = new RunTestOnContext(); + + @Before + public void setUp() { + Vertx vertx = rule.vertx(); + JsonObject config = new JsonObject(); + config + .put(FocusConfigKey.BUBBLE_KEY.key(), "nynja:nynjaTS") + .put(FocusConfigKey.BUBBLE_URL.key(), "http://localhost:8888/cri/bubbles") + ; + bubbleSender = BubbleSender.create(vertx, config); + } + + @Test + public void sendForConference(TestContext context) { + bubbleSender.sendForConference( + "37936e07-1930-4317-8719-aadac2524184_2806", + "d57061b1-3313-43bb-b745-7612677d3195", + "dummy-call-id", + 10, + System.currentTimeMillis(), + AnswerStatus.ANSWERED, + ContentType.AUDIO_CALL, + CallEndedBy.CALLEE, + 3, + List.of("37936e07-1930-4317-8719-aadac2524184_2806") + ).setHandler(context.asyncAssertSuccess()); + } + + @Test + public void sendForP2P(TestContext context) { + bubbleSender.sendForP2P( + "37936e07-1930-4317-8719-aadac2524184_2806", + "5ef289e7-3c9b-44e2-9dce-637e30f3f02a_2807", + "dummy-call-id", + 10, + System.currentTimeMillis(), + AnswerStatus.ANSWERED, + ContentType.AUDIO_CALL, + CallEndedBy.CALLEE + ).setHandler(context.asyncAssertSuccess()); + } +} diff --git a/focus/src/test/java/com/nynjacoin/nccs/restclient/chatroom/ChatRoomClientManualTest.java b/focus/src/test/java/com/nynjacoin/nccs/restclient/chatroom/ChatRoomClientManualTest.java index ee23f427fd9e2970c8a87d6cb4fb49b272541603..a98839d4b9555d749708bf41be900503aa4d39b0 100644 --- a/focus/src/test/java/com/nynjacoin/nccs/restclient/chatroom/ChatRoomClientManualTest.java +++ b/focus/src/test/java/com/nynjacoin/nccs/restclient/chatroom/ChatRoomClientManualTest.java @@ -1,7 +1,7 @@ package com.nynjacoin.nccs.restclient.chatroom; import com.nynjacoin.nccs.lib.vertx.restclient.AuthenticationHandler; -import com.nynjacoin.nccs.lib.vertx.restclient.RetryExecutor; +import com.nynjacoin.nccs.lib.vertx.restclient.JsonRetryExecutor; import com.nynjacoin.nccs.protocol.def.Void; import io.vertx.core.Future; import io.vertx.core.Vertx; @@ -35,17 +35,19 @@ public class ChatRoomClientManualTest { // AuthenticationHandler authenticationHandler = AuthenticationHandler.create("nynja:nynjaTS"); AuthenticationHandler authenticationHandler = AuthenticationHandler.create("nynja:nynjaTS"); - RetryExecutor retryExecutor = RetryExecutor.newBuilder(vertx).build(); + JsonRetryExecutor retryExecutor = new JsonRetryExecutor( + vertx, ChatRoomClient.DEFAULT_MAX_RETRIES, ChatRoomClient.DEFAULT_RETRY_MILLISECONDS); // String rootUrl = "http://csdk.ci.nynja.net:8888/cri/rooms"; - String rootUrl = "https://im.dev.nynja.net/cri/rooms"; +// String rootUrl = "https://im.dev.nynja.net/cri/rooms"; + String rootUrl = "http://localhost:8888/cri/rooms"; chatRoomClient = new ChatRoomClient(webClient, authenticationHandler, retryExecutor, rootUrl); } @Test public void createRoom(TestContext context) { - Future result = chatRoomClient.createRoom("359999111101_166"); + Future result = chatRoomClient.createRoom("37936e07-1930-4317-8719-aadac2524184_2806"); result.setHandler(context.asyncAssertSuccess(roomId -> { context.assertNotNull(roomId); context.assertNotEquals(roomId, ""); @@ -60,9 +62,8 @@ public class ChatRoomClientManualTest { "359999111101_166", "conference_1547131523640_206", accounts); - result.setHandler(context.asyncAssertSuccess(allMembers -> { - System.out.println("Am I member: " + allMembers); - })); + result.setHandler(context.asyncAssertSuccess(allMembers -> + System.out.println("Am I member: " + allMembers))); } /* @@ -88,9 +89,8 @@ public class ChatRoomClientManualTest { "359999131313_76", "692D4F79-E63F-4A41-B17E-A8CEEC2139F7_359898773312_20_153935357591482_7DE313F6-B206-4205-ADCB-7432D8928A81", accounts); - result.setHandler(context.asyncAssertSuccess(allMembers -> { - System.out.println("ALL ARE MEMBERS: " + allMembers); - })); + result.setHandler(context.asyncAssertSuccess(allMembers -> + System.out.println("ALL ARE MEMBERS: " + allMembers))); } @Test diff --git a/gradle.properties b/gradle.properties index 77e0346acf8329850744e9f02dc840d690836f05..ffe1f234706199ce0cd82747c987e1f3e9f82da1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,4 +7,4 @@ rxjava2Version = 2.1.13 prometheusVersion = 0.5.0 cassandraDriverVersion = 3.6.0 junitVersion = 4.12 -nccsLibsVersion = 0.20.0 +nccsLibsVersion = 0.21.0