From c6a5fc7210188f60c9bc1a4986fdd10c33deb79e Mon Sep 17 00:00:00 2001 From: sergeyPensov Date: Tue, 18 Dec 2018 16:24:25 +0200 Subject: [PATCH 1/3] Implement gRpc bridge --- pom.xml | 12 ++ .../services/erlang/ErlangAccountBridge.java | 6 +- .../erlang/ErlangAccountHttpBridge.java | 3 +- .../erlang/ErlangAccountMqttBridge.java | 144 ++++++++++++++++++ .../erlang/interceptor/TokenInterceptor.java | 19 +++ .../TokenInterceptorConstants.java | 11 ++ src/main/resources/application-dev.yml | 2 +- 7 files changed, 192 insertions(+), 5 deletions(-) create mode 100644 src/main/java/biz/nynja/account/services/erlang/ErlangAccountMqttBridge.java create mode 100644 src/main/java/biz/nynja/account/services/erlang/interceptor/TokenInterceptor.java create mode 100644 src/main/java/biz/nynja/account/services/erlang/interceptor/TokenInterceptorConstants.java diff --git a/pom.xml b/pom.xml index 931932d..d9d421a 100644 --- a/pom.xml +++ b/pom.xml @@ -111,6 +111,18 @@ + + libs-snapshot-local.biz.nynja.protos + bridge-service-ny-5863-bridge-service + 1.0-SNAPSHOT + + + com.google.protobuf + protobuf-java + + + + com.googlecode.libphonenumber libphonenumber diff --git a/src/main/java/biz/nynja/account/services/erlang/ErlangAccountBridge.java b/src/main/java/biz/nynja/account/services/erlang/ErlangAccountBridge.java index 803db0e..f30b96d 100644 --- a/src/main/java/biz/nynja/account/services/erlang/ErlangAccountBridge.java +++ b/src/main/java/biz/nynja/account/services/erlang/ErlangAccountBridge.java @@ -6,18 +6,18 @@ package biz.nynja.account.services.erlang; import biz.nynja.account.models.Account; import biz.nynja.account.models.Profile; +import java.util.List; import java.util.UUID; - public interface ErlangAccountBridge { boolean createProfile(Profile profile, Account defaultAccount); - boolean deleteProfile(UUID profileId); + boolean deleteProfile(UUID profileId, List accountsIds); boolean createAccount(Account account); boolean updateAccount(Account account); - boolean deleteAccount(UUID accountId); + boolean deleteAccount(UUID profileId, UUID accountId); } diff --git a/src/main/java/biz/nynja/account/services/erlang/ErlangAccountHttpBridge.java b/src/main/java/biz/nynja/account/services/erlang/ErlangAccountHttpBridge.java index aa88d2f..8382eb1 100644 --- a/src/main/java/biz/nynja/account/services/erlang/ErlangAccountHttpBridge.java +++ b/src/main/java/biz/nynja/account/services/erlang/ErlangAccountHttpBridge.java @@ -6,6 +6,7 @@ package biz.nynja.account.services.erlang; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; +import java.util.List; import java.util.UUID; import org.slf4j.Logger; @@ -99,7 +100,7 @@ public class ErlangAccountHttpBridge implements ErlangAccountBridge { } @Override - public boolean deleteAccount(UUID accountId) { + public boolean deleteAccount(UUID accountId, List accountsIds) { if (!erlangBridgeConfiguration.isEnabled()) return true; JsonObject accountObject = new JsonObject(); diff --git a/src/main/java/biz/nynja/account/services/erlang/ErlangAccountMqttBridge.java b/src/main/java/biz/nynja/account/services/erlang/ErlangAccountMqttBridge.java new file mode 100644 index 0000000..cfaaad4 --- /dev/null +++ b/src/main/java/biz/nynja/account/services/erlang/ErlangAccountMqttBridge.java @@ -0,0 +1,144 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.services.erlang; + +import java.net.MalformedURLException; +import java.util.Arrays; +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + +import org.springframework.stereotype.Component; + +import biz.nynja.account.configuration.ErlangBridgeConfiguration; +import biz.nynja.account.models.Account; +import biz.nynja.account.models.Profile; +import biz.nynja.account.services.erlang.interceptor.TokenInterceptorConstants; +import biz.nynja.bridge.grpc.AccountBridgeGrpc; +import biz.nynja.bridge.grpc.AccountData; +import biz.nynja.bridge.grpc.BridgeSuccessResponse; +import biz.nynja.bridge.grpc.ProfileData; +import io.grpc.ManagedChannel; +import io.grpc.ManagedChannelBuilder; +import io.grpc.Metadata; +import io.grpc.stub.MetadataUtils; + +@Component +public class ErlangAccountMqttBridge implements ErlangAccountBridge { + + private final ErlangBridgeConfiguration erlangBridgeConfiguration; + + public ErlangAccountMqttBridge(ErlangBridgeConfiguration erlangBridgeConfiguration) throws MalformedURLException { + this.erlangBridgeConfiguration = erlangBridgeConfiguration; + } + + @Override + public boolean createProfile(Profile profile, Account account) { + + if (!erlangBridgeConfiguration.isEnabled()) + return true; + ProfileData profileData = buildProfileData(profile, account); + // todo update after testing with real connection + BridgeSuccessResponse response = buildGrpcConnection().createProfile(profileData); + return true; + } + + @Override + public boolean deleteProfile(UUID profileId, List accountsIds) { + if (!erlangBridgeConfiguration.isEnabled()) + return true; + BridgeSuccessResponse response = buildGrpcConnection() + .deleteProfile(buildDeleteProfileData(profileId, (UUID[]) accountsIds.toArray())); + return true; + } + + @Override + public boolean createAccount(Account account) { + if (!erlangBridgeConfiguration.isEnabled()) + return true; + BridgeSuccessResponse response = buildGrpcConnection().createAccount(buildAccountData(account)); + + return true; + } + + @Override + public boolean updateAccount(Account account) { + if (!erlangBridgeConfiguration.isEnabled()) + return true; + + return true; + } + + @Override + public boolean deleteAccount(UUID profileId, UUID accountId) { + if (!erlangBridgeConfiguration.isEnabled()) + return true; + BridgeSuccessResponse response = buildGrpcConnection() + .deleteAccount(buildDeleteProfileData(profileId, accountId)); + return true; + } + + private ProfileData buildProfileData(Profile profile, Account account) { + return ProfileData.newBuilder().setProfileId(profile.getProfileId().toString()) + .setDefaultAccount(buildAccountData(account)) + .setLastUpdateTimestamp(profile.getCreationTimestamp().toString()).build(); + } + + private AccountData buildAccountData(Account account) { + return AccountData.newBuilder().setAccountId(account.getAccountId().toString()) + .setFirstName(account.getFirstName()).setLastName(account.getLastName()) + .setUsername(account.getUsername()).setAvatar(account.getAvatar()) + .setLastUpdateTimestamp(account.getLastUpdateTimestamp().toString()).build(); + } + + // Erlang protocol + private ProfileData buildDeleteProfileData(UUID profileId, UUID... accountsId) { + return ProfileData.newBuilder().setProfileId(profileId.toString()) + .addAllAccountsIds(Arrays.stream(accountsId).map(UUID::toString).collect(Collectors.toList())).build(); + } + + private AccountBridgeGrpc.AccountBridgeBlockingStub buildGrpcConnection() { + ManagedChannel managedChannel = ManagedChannelBuilder.forAddress(erlangBridgeConfiguration.getHost(), + Integer.getInteger(erlangBridgeConfiguration.getPort())).usePlaintext().build(); + AccountBridgeGrpc.AccountBridgeBlockingStub bridgeServiceBlockingStub = AccountBridgeGrpc + .newBlockingStub(managedChannel); + return MetadataUtils.attachHeaders(bridgeServiceBlockingStub, getHeaders()); + } + + /* + * public StatusResponse updateAuthProvider(String profileId, AuthProviderDetails details, SidType sidTypeToRemove, + * String sidToRemove) { + * + * UpdateAuthenticationProviderRequest request = UpdateAuthenticationProviderRequest.newBuilder() + * .setProfileId(profileId) + * .setOldAuthProvider(AuthProviderDetails.newBuilder().setAuthenticationProvider(sidToRemove) + * .setAuthenticationType(AuthenticationType.valueOf(sidTypeToRemove.name()))) .setUpdatedAuthProvider( + * AuthProviderDetails.newBuilder().setAuthenticationProvider(details.getAuthenticationProvider()) + * .setAuthenticationType(details.getAuthenticationType())) .build(); ManagedChannel managedChannel = + * ManagedChannelBuilder.forAddress(accountServiceAddress, accountServicePort) .usePlaintext().build(); + * + * AccountServiceGrpc.AccountServiceBlockingStub accountServiceBlockingStub = AccountServiceGrpc + * .newBlockingStub(managedChannel); + * + * Metadata headers = getHeaders(); accountServiceBlockingStub = + * MetadataUtils.attachHeaders(accountServiceBlockingStub, headers); + * + * StatusResponse response = accountServiceBlockingStub.updateAuthenticationProviderForProfile(request); return + * response; } + * + */ + + /** + * Attaches the access token to the rpc header + * + * @return + * @throws InternalError + */ + private Metadata getHeaders() throws InternalError { + Metadata headers = new Metadata(); + Metadata.Key key = Metadata.Key.of("accessToken", Metadata.ASCII_STRING_MARSHALLER); + headers.put(key, "Bearer " + TokenInterceptorConstants.ACCESS_TOKEN_CTX.get()); + return headers; + } +} diff --git a/src/main/java/biz/nynja/account/services/erlang/interceptor/TokenInterceptor.java b/src/main/java/biz/nynja/account/services/erlang/interceptor/TokenInterceptor.java new file mode 100644 index 0000000..67de571 --- /dev/null +++ b/src/main/java/biz/nynja/account/services/erlang/interceptor/TokenInterceptor.java @@ -0,0 +1,19 @@ +/** + * Copyright (C) 2018 Nynja Inc. All rights reserved. + */ +package biz.nynja.account.services.erlang.interceptor; + +import io.grpc.*; +import org.lognet.springboot.grpc.GRpcGlobalInterceptor; + +@GRpcGlobalInterceptor +public class TokenInterceptor implements ServerInterceptor { + + @Override + public ServerCall.Listener interceptCall(ServerCall serverCall, Metadata metadata, + ServerCallHandler serverCallHandler) { + String accessToken = metadata.get(TokenInterceptorConstants.ACCESS_TOKEN_METADATA); + Context ctx = Context.current().withValue(TokenInterceptorConstants.ACCESS_TOKEN_CTX, accessToken); + return Contexts.interceptCall(ctx, serverCall, metadata, serverCallHandler); + } +} diff --git a/src/main/java/biz/nynja/account/services/erlang/interceptor/TokenInterceptorConstants.java b/src/main/java/biz/nynja/account/services/erlang/interceptor/TokenInterceptorConstants.java new file mode 100644 index 0000000..5df55f1 --- /dev/null +++ b/src/main/java/biz/nynja/account/services/erlang/interceptor/TokenInterceptorConstants.java @@ -0,0 +1,11 @@ +package biz.nynja.account.services.erlang.interceptor; + +import io.grpc.Context; +import io.grpc.Metadata; + +import static io.grpc.Metadata.ASCII_STRING_MARSHALLER; + +public class TokenInterceptorConstants { + public static final Metadata.Key ACCESS_TOKEN_METADATA = Metadata.Key.of("accessToken", ASCII_STRING_MARSHALLER); + public static final Context.Key ACCESS_TOKEN_CTX = Context.key("accessToken"); +} diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 5a241bc..b604e12 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -36,7 +36,7 @@ account-data: erlang-bridge: enable: false; - ip: + host: port: #Metrics related configurations -- GitLab From e6c7d5d0798a760ebbaddd8f5a2452865efdf8a1 Mon Sep 17 00:00:00 2001 From: sergeyPensov Date: Wed, 26 Dec 2018 15:58:13 +0200 Subject: [PATCH 2/3] Add saga to account --- .../AccountRepositoryAdditionalImpl.java | 48 +++++++++++++------ .../erlang/ErlangAccountHttpBridge.java | 10 ++-- 2 files changed, 37 insertions(+), 21 deletions(-) diff --git a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java index 2a9c034..361f53d 100644 --- a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java +++ b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java @@ -15,6 +15,8 @@ import java.util.Set; import java.util.UUID; import java.util.stream.Collectors; +import biz.nynja.account.repositories.batch.SagaTransaction; +import biz.nynja.account.repositories.batch.Transaction; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.cassandra.core.CassandraBatchOperations; @@ -102,7 +104,7 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio } public Account completePendingAccountCreation(CompletePendingAccountCreationRequest request) { - CassandraBatchOperations batchOperations = cassandraTemplate.batchOps(); + Transaction sagaTransaction = new SagaTransaction(cassandraTemplate); PendingAccount pendingAccount = pendingAccountRepository .findByAccountId(UUID.fromString(request.getAccountId())); if (pendingAccount == null) { @@ -122,10 +124,15 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio Long timeCreated = Instant.now().toEpochMilli(); WriteResult wr; try { - newAccountInsert(batchOperations, request, pendingAccount, timeCreated); - newProfileByAuthenticationProviderInsert(batchOperations, pendingAccount); - newProfileInsert(batchOperations, request, pendingAccount, timeCreated); - wr = batchOperations.execute(); + Account account = newAccountInsert(sagaTransaction, request, pendingAccount, timeCreated); + newProfileByAuthenticationProviderInsert(sagaTransaction, pendingAccount); + Profile profile = newProfileInsert(sagaTransaction, request, pendingAccount, timeCreated); + wr = sagaTransaction.execute(); + if (!erlangAccountBridge.createProfile(profile, account)) { + logger.error("Internal error with erlang"); + sagaTransaction.rollBack(); + return null; + } } catch (IllegalArgumentException | IllegalStateException e) { logger.info("Exception while completing pending account creation."); logger.debug("Exception while completing pending account creation: {} ...", e.getMessage()); @@ -169,7 +176,7 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio } public Account updateAccount(UpdateAccountRequest request) { - CassandraBatchOperations batchOperations = cassandraTemplate.batchOps(); + Transaction sagaTransaction = new SagaTransaction(cassandraTemplate); Account existingAccount = accountRepository.findByAccountId(UUID.fromString(request.getAccountId())); if (existingAccount == null) { logger.error("Existing account with the provided id {} was not found.", request.getAccountId()); @@ -180,12 +187,17 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio WriteResult wr = null; try { try { - updateAccountData(batchOperations, request, existingAccount, timeUpdated); + updateAccountData(sagaTransaction, request, existingAccount, timeUpdated); } catch (DateTimeException e) { logger.error("Exception with birthday date while updating account with id {}", request.getAccountId()); return null; } - wr = batchOperations.execute(); + wr = sagaTransaction.execute(); + if (!erlangAccountBridge.updateAccount(existingAccount)) { + logger.error("Internal error with erlang"); + sagaTransaction.rollBack(); + return null; + } } catch (IllegalArgumentException | IllegalStateException e) { logger.error("Exception while updating account with id {}.", request.getAccountId()); logger.debug("Exception while updating account: {}.", e.getMessage()); @@ -203,7 +215,7 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio } public boolean deleteAccount(UUID accountId) { - CassandraBatchOperations batchOperations = cassandraTemplate.batchOps(); + Transaction sagaTransaction = new SagaTransaction(cassandraTemplate); Account existingAccount = accountRepository.findByAccountId(accountId); if (!doExistAccountAndProfileToDelete(accountId)) { return false; @@ -219,23 +231,29 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio boolean alsoDeleteProfile = existingAccountsForProfile.size() == 1; WriteResult wr = null; try { - deleteAccountData(batchOperations, existingAccount); - deleteProfileByAuthenticationProvider(batchOperations, existingAccount.getProfileId(), + deleteAccountData(sagaTransaction, existingAccount); + deleteProfileByAuthenticationProvider(sagaTransaction, existingAccount.getProfileId(), AuthenticationProvider.createAuthenticationProviderFromStrings( existingAccount.getAuthenticationProviderType(), existingAccount.getAuthenticationProvider())); if (alsoDeleteProfile) { if (existingProfile.getAuthenticationProviders() != null) { - deleteAuthenticationProvidersFromProfile(batchOperations, existingProfile.getProfileId(), + deleteAuthenticationProvidersFromProfile(sagaTransaction, existingProfile.getProfileId(), existingProfile.getAuthenticationProviders()); } - deleteProfileData(batchOperations, existingProfile); + deleteProfileData(sagaTransaction, existingProfile); } else { - if (!removeCreationProvider(batchOperations, existingAccount, existingProfile)) { + if (!removeCreationProvider(sagaTransaction, existingAccount, existingProfile)) { return false; } } - wr = batchOperations.execute(); + wr = sagaTransaction.execute(); + + if (!erlangAccountBridge.deleteAccount(existingProfile.getProfileId(), accountId)) { + logger.error("Internal error with erlang"); + sagaTransaction.rollBack(); + return false; + } } catch (IllegalArgumentException | IllegalStateException e) { logger.error("Exception while deleting account: {}.", e.getMessage()); return false; diff --git a/src/main/java/biz/nynja/account/services/erlang/ErlangAccountHttpBridge.java b/src/main/java/biz/nynja/account/services/erlang/ErlangAccountHttpBridge.java index 8382eb1..918a66c 100644 --- a/src/main/java/biz/nynja/account/services/erlang/ErlangAccountHttpBridge.java +++ b/src/main/java/biz/nynja/account/services/erlang/ErlangAccountHttpBridge.java @@ -23,8 +23,6 @@ import biz.nynja.account.models.Account; import biz.nynja.account.models.Profile; import biz.nynja.account.services.erlang.connector.HttpClient; - - @Service // TODO: 11/19/2018 change boolean response when ENC will implement return error part public class ErlangAccountHttpBridge implements ErlangAccountBridge { @@ -67,7 +65,7 @@ public class ErlangAccountHttpBridge implements ErlangAccountBridge { } @Override - public boolean deleteProfile(UUID profileId) { + public boolean deleteProfile(UUID profileId, List accountsIds) { if (!erlangBridgeConfiguration.isEnabled()) return true; JsonObject profileObject = new JsonObject(); @@ -78,7 +76,7 @@ public class ErlangAccountHttpBridge implements ErlangAccountBridge { return false; } - return false; + return true; } @Override @@ -100,7 +98,7 @@ public class ErlangAccountHttpBridge implements ErlangAccountBridge { } @Override - public boolean deleteAccount(UUID accountId, List accountsIds) { + public boolean deleteAccount(UUID profileId, UUID accountId) { if (!erlangBridgeConfiguration.isEnabled()) return true; JsonObject accountObject = new JsonObject(); @@ -110,7 +108,7 @@ public class ErlangAccountHttpBridge implements ErlangAccountBridge { } catch (IOException e) { return false; } - return false; + return true; } private JsonObject prepareProfileJsonObject(Profile profile, Account account) { -- GitLab From a142f5bea7260e5974dce510dcb04c81290460b0 Mon Sep 17 00:00:00 2001 From: sergeyPensov Date: Wed, 9 Jan 2019 16:21:17 +0200 Subject: [PATCH 3/3] Fix bridge connection --- .../repositories/AccountRepositoryAdditionalImpl.java | 5 +++-- .../services/erlang/ErlangAccountHttpBridge.java | 4 ++-- .../services/erlang/ErlangAccountMqttBridge.java | 11 +++++++++-- src/main/resources/application-dev.yml | 6 +++--- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java index 1f63209..a8dadef 100644 --- a/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java +++ b/src/main/java/biz/nynja/account/repositories/AccountRepositoryAdditionalImpl.java @@ -17,6 +17,7 @@ import java.util.stream.Collectors; import biz.nynja.account.repositories.batch.SagaTransaction; import biz.nynja.account.repositories.batch.Transaction; +import biz.nynja.account.services.erlang.ErlangAccountBridge; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.cassandra.core.CassandraBatchOperations; @@ -72,7 +73,7 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio private final PendingAccountRepository pendingAccountRepository; private final AccountServiceHelper accountServiceHelper; private final Session session; - private final ErlangAccountHttpBridge erlangAccountBridge; + private final ErlangAccountBridge erlangAccountBridge; private final PermissionsValidator permissionsValidator; public AccountRepositoryAdditionalImpl(PendingAccountConfiguration pendingAccountConfiguration, @@ -83,7 +84,7 @@ public class AccountRepositoryAdditionalImpl implements AccountRepositoryAdditio ProfileByAuthenticationProviderRepository profileByAuthenticationProviderRepository, PendingAccountByAuthenticationProviderRepository pendingAccountByAuthenticationProviderRepository, PendingAccountRepository pendingAccountRepository, AccountServiceHelper accountServiceHelper, - Session session, ErlangAccountHttpBridge erlangAccountBridge, PermissionsValidator permissionsValidator, + Session session, ErlangAccountBridge erlangAccountBridge, PermissionsValidator permissionsValidator, AccountDataConfiguration accountDataConfiguration) { this.pendingAccountConfiguration = pendingAccountConfiguration; this.cassandraTemplate = cassandraTemplate; diff --git a/src/main/java/biz/nynja/account/services/erlang/ErlangAccountHttpBridge.java b/src/main/java/biz/nynja/account/services/erlang/ErlangAccountHttpBridge.java index 918a66c..84f6e7e 100644 --- a/src/main/java/biz/nynja/account/services/erlang/ErlangAccountHttpBridge.java +++ b/src/main/java/biz/nynja/account/services/erlang/ErlangAccountHttpBridge.java @@ -45,9 +45,9 @@ public class ErlangAccountHttpBridge implements ErlangAccountBridge { profileURL = null; return; } - accountURL = new URL( + accountURL = new URL("http://" + erlangBridgeConfiguration.getHost() + ":" + erlangBridgeConfiguration.getPort() + "/swm/account"); - profileURL = new URL( + profileURL = new URL("http://" + erlangBridgeConfiguration.getHost() + ":" + erlangBridgeConfiguration.getPort() + "/swm/profile"); } diff --git a/src/main/java/biz/nynja/account/services/erlang/ErlangAccountMqttBridge.java b/src/main/java/biz/nynja/account/services/erlang/ErlangAccountMqttBridge.java index cfaaad4..0bd0d70 100644 --- a/src/main/java/biz/nynja/account/services/erlang/ErlangAccountMqttBridge.java +++ b/src/main/java/biz/nynja/account/services/erlang/ErlangAccountMqttBridge.java @@ -6,9 +6,11 @@ package biz.nynja.account.services.erlang; import java.net.MalformedURLException; import java.util.Arrays; import java.util.List; +import java.util.Objects; import java.util.UUID; import java.util.stream.Collectors; +import org.springframework.context.annotation.Primary; import org.springframework.stereotype.Component; import biz.nynja.account.configuration.ErlangBridgeConfiguration; @@ -25,6 +27,7 @@ import io.grpc.Metadata; import io.grpc.stub.MetadataUtils; @Component +@Primary public class ErlangAccountMqttBridge implements ErlangAccountBridge { private final ErlangBridgeConfiguration erlangBridgeConfiguration; @@ -88,8 +91,12 @@ public class ErlangAccountMqttBridge implements ErlangAccountBridge { private AccountData buildAccountData(Account account) { return AccountData.newBuilder().setAccountId(account.getAccountId().toString()) .setFirstName(account.getFirstName()).setLastName(account.getLastName()) + .setProfileId(account.getProfileId().toString()) .setUsername(account.getUsername()).setAvatar(account.getAvatar()) - .setLastUpdateTimestamp(account.getLastUpdateTimestamp().toString()).build(); + .setLastUpdateTimestamp( + Objects.isNull(account.getLastUpdateTimestamp()) ? Long.toString(System.currentTimeMillis()) + : account.getLastUpdateTimestamp().toString()) + .build(); } // Erlang protocol @@ -100,7 +107,7 @@ public class ErlangAccountMqttBridge implements ErlangAccountBridge { private AccountBridgeGrpc.AccountBridgeBlockingStub buildGrpcConnection() { ManagedChannel managedChannel = ManagedChannelBuilder.forAddress(erlangBridgeConfiguration.getHost(), - Integer.getInteger(erlangBridgeConfiguration.getPort())).usePlaintext().build(); + Integer.parseInt(erlangBridgeConfiguration.getPort())).usePlaintext().build(); AccountBridgeGrpc.AccountBridgeBlockingStub bridgeServiceBlockingStub = AccountBridgeGrpc .newBlockingStub(managedChannel); return MetadataUtils.attachHeaders(bridgeServiceBlockingStub, getHeaders()); diff --git a/src/main/resources/application-dev.yml b/src/main/resources/application-dev.yml index 397d75c..aced73b 100644 --- a/src/main/resources/application-dev.yml +++ b/src/main/resources/application-dev.yml @@ -38,9 +38,9 @@ account-data: max-contact-info-of-type: 10 erlang-bridge: - enable: false; - host: - port: + enabled: true + host: localhost + port: 6580 #Metrics related configurations management: -- GitLab