ing
This commit is contained in:
parent
13d407043e
commit
7e5dea3cb6
|
@ -4,9 +4,18 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
|
||||
public class PublishMessage {
|
||||
private TargetType targetType;
|
||||
private List<String> targets;
|
||||
private PublishMessageBody message;
|
||||
|
||||
public void setTargetType(TargetType targetType) {
|
||||
this.targetType = targetType;
|
||||
}
|
||||
|
||||
public TargetType getTargetType() {
|
||||
return this.targetType;
|
||||
}
|
||||
|
||||
public void setTargets(List<String> targets) {
|
||||
this.targets = targets;
|
||||
}
|
||||
|
@ -30,6 +39,21 @@ public class PublishMessage {
|
|||
return message;
|
||||
}
|
||||
|
||||
public static enum TargetType {
|
||||
MEMBER_SESSION("MEMBER_SESSION"),
|
||||
MEMBER("MEMBER"),
|
||||
PROBE("PROBE");
|
||||
|
||||
final private String name;
|
||||
|
||||
private TargetType(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
|
||||
public static class PublishMessageBody {
|
||||
private String jsonrpc = "2.0";
|
||||
private PublishMessageBodyNotification result;
|
||||
|
|
|
@ -6,10 +6,46 @@ import io.grpc.Metadata;
|
|||
import static io.grpc.Metadata.ASCII_STRING_MARSHALLER;
|
||||
|
||||
public class SessionMetadata {
|
||||
public static final Context.Key<String> CTX_SESSION_ID_KEY = Context.key("SESSION_ID");
|
||||
public static final Metadata.Key<String> METADATA_SESSION_ID_KEY = Metadata.Key.of("SESSION_ID", ASCII_STRING_MARSHALLER);
|
||||
/*
|
||||
digits: 0-9
|
||||
uppercase letters: A-Z (normalized to lower)
|
||||
lowercase letters: a-z
|
||||
special characters: -_.
|
||||
*/
|
||||
|
||||
public static final String CLIENT_TYPE_KEY = "OVERFLOW_GRPC_CLIENT_TYPE";
|
||||
public static final String SESSION_ID_KEY = "OVERFLOW_GRPC_SESSION_ID";
|
||||
public static final String TARGET_ID_KEY = "OVERFLOW_GRPC_TARGET_ID";
|
||||
|
||||
public static final Context.Key<String> CTX_CLIENT_TYPE_KEY = Context.key(CLIENT_TYPE_KEY);
|
||||
public static final Context.Key<String> CTX_SESSION_ID_KEY = Context.key(SESSION_ID_KEY);
|
||||
public static final Context.Key<String> CTX_TARGET_ID_KEY = Context.key(TARGET_ID_KEY);
|
||||
|
||||
public static final Metadata.Key<String> METADATA_CLIENT_TYPE_KEY = Metadata.Key.of(CLIENT_TYPE_KEY, ASCII_STRING_MARSHALLER);
|
||||
public static final Metadata.Key<String> METADATA_SESSION_ID_KEY = Metadata.Key.of(SESSION_ID_KEY, ASCII_STRING_MARSHALLER);
|
||||
public static final Metadata.Key<String> METADATA_TARGET_ID_KEY = Metadata.Key.of(TARGET_ID_KEY, ASCII_STRING_MARSHALLER);
|
||||
|
||||
public static ClientType getClientType() {
|
||||
return ClientType.valueOf(CTX_CLIENT_TYPE_KEY.get());
|
||||
}
|
||||
public static String getSessionID() {
|
||||
return CTX_SESSION_ID_KEY.get();
|
||||
}
|
||||
public static String getTargetID() {
|
||||
return CTX_TARGET_ID_KEY.get();
|
||||
}
|
||||
|
||||
public static enum ClientType {
|
||||
MEMBER("MEMBER"),
|
||||
PROBE("PROBE");
|
||||
|
||||
final private String name;
|
||||
|
||||
private ClientType(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
public String toString() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,9 +3,11 @@ package com.loafle.overflow.commons.service;
|
|||
import com.loafle.overflow.module.domain.model.Domain;
|
||||
|
||||
public interface MessagePublisher {
|
||||
void publishToMember(final String channel, final String memberID, final String method, final Object... params);
|
||||
void publishToDomain(final String channel, final Domain domain, final String method, final Object... params);
|
||||
void publishToDomainByProbeKey(final String channel, final String probeKey, final String method, final Object... params);
|
||||
void publishToProbe(final String channel, final String key, final String method, final Object... params);
|
||||
void publishToDomainMembers(final long domainID, final String method, final Object... params);
|
||||
void publishToDomainMembersByProbeKey(final String probeKey, final String method, final Object... params);
|
||||
|
||||
void publishToMember(final String memberID, final String method, final Object... params);
|
||||
void publishToMemberSession(final String memberSessionID, final String method, final Object... params);
|
||||
|
||||
void publishToProbe(final String probeKey, final String method, final Object... params);
|
||||
}
|
||||
|
|
|
@ -38,75 +38,75 @@ public class DiscoveryService {
|
|||
// this.messagePublisher.publishToProbe("/auth", noAuthProbe.getTempProbeKey(), "NoAuthProbeService.acceptNoAuthProbe", probe.getProbeKey());
|
||||
}
|
||||
|
||||
public boolean testDiscovery(int types, String obj) {
|
||||
// public boolean testDiscovery(int types, String obj) {
|
||||
|
||||
Domain domain = new Domain();
|
||||
domain.setId(1);
|
||||
// Domain domain = new Domain();
|
||||
// domain.setId(1);
|
||||
|
||||
// int typeInt = Integer.valueOf(types);
|
||||
switch (types) {
|
||||
case 1 :
|
||||
messagePublisher.publishToDomain("/webapp", domain, "DiscoveryService.discoveryIngHost", obj);
|
||||
break;
|
||||
case 2 :
|
||||
messagePublisher.publishToDomain("/webapp", domain, "DiscoveryService.discoveryIngPort", obj);
|
||||
break;
|
||||
case 3 :
|
||||
messagePublisher.publishToDomain("/webapp", domain, "DiscoveryService.discoveryIngService", obj);
|
||||
break;
|
||||
}
|
||||
// // int typeInt = Integer.valueOf(types);
|
||||
// switch (types) {
|
||||
// case 1 :
|
||||
// messagePublisher.publishToDomainMembers(domain, "DiscoveryService.discoveryIngHost", obj);
|
||||
// break;
|
||||
// case 2 :
|
||||
// messagePublisher.publishToDomain("/webapp", domain, "DiscoveryService.discoveryIngPort", obj);
|
||||
// break;
|
||||
// case 3 :
|
||||
// messagePublisher.publishToDomain("/webapp", domain, "DiscoveryService.discoveryIngService", obj);
|
||||
// break;
|
||||
// }
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
// return true;
|
||||
// }
|
||||
|
||||
@WebappAPI
|
||||
public void discoverZone(String probeID, DiscoveryZone discoveryZone) {
|
||||
String requestMemberEmail = SessionMetadata.getSessionID();
|
||||
String requesterSessionID = SessionMetadata.getSessionID();
|
||||
|
||||
messagePublisher.publishToProbe("/probe", probeID, "DiscoveryService.DiscoverZone", requestMemberEmail, discoveryZone);
|
||||
messagePublisher.publishToProbe(probeID, "DiscoveryService.DiscoverZone", requesterSessionID, discoveryZone);
|
||||
}
|
||||
|
||||
@WebappAPI
|
||||
public void discoverHost(String probeID, Zone zone, DiscoveryHost discoveryHost) {
|
||||
String requestMemberEmail = SessionMetadata.getSessionID();
|
||||
String requesterSessionID = SessionMetadata.getSessionID();
|
||||
|
||||
messagePublisher.publishToProbe("/probe", probeID, "DiscoveryService.DiscoverHost", requestMemberEmail, zone, discoveryHost);
|
||||
messagePublisher.publishToProbe(probeID, "DiscoveryService.DiscoverHost", requesterSessionID, zone, discoveryHost);
|
||||
}
|
||||
|
||||
@WebappAPI
|
||||
public void discoverPort(String probeID, Host host, DiscoveryPort discoveryPort) {
|
||||
String requestMemberEmail = SessionMetadata.getSessionID();
|
||||
String requesterSessionID = SessionMetadata.getSessionID();
|
||||
|
||||
messagePublisher.publishToProbe("/probe", probeID, "DiscoveryService.DiscoverPort", requestMemberEmail, host, discoveryPort);
|
||||
messagePublisher.publishToProbe(probeID, "DiscoveryService.DiscoverPort", requesterSessionID, host, discoveryPort);
|
||||
}
|
||||
|
||||
@WebappAPI
|
||||
public void discoverService(String probeID, Port port, com.loafle.overflow.module.discovery.model.DiscoveryService discoveryService) {
|
||||
String requestMemberEmail = SessionMetadata.getSessionID();
|
||||
String requesterSessionID = SessionMetadata.getSessionID();
|
||||
|
||||
messagePublisher.publishToProbe("/probe", probeID, "DiscoveryService.DiscoverService", requestMemberEmail, port, discoveryService);
|
||||
messagePublisher.publishToProbe(probeID, "DiscoveryService.DiscoverService", requesterSessionID, port, discoveryService);
|
||||
}
|
||||
|
||||
|
||||
@ProbeAPI
|
||||
public void discoveredZone(String requestMemberEmail, Zone zone) {
|
||||
messagePublisher.publishToMember("/webapp", requestMemberEmail, "DiscoveryService.discoveredZone", zone);
|
||||
public void discoveredZone(String requesterSessionID, Zone zone) {
|
||||
messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveredZone", zone);
|
||||
}
|
||||
|
||||
@ProbeAPI
|
||||
public void discoveredHost(String requestMemberEmail, Host host) {
|
||||
messagePublisher.publishToMember("/webapp", requestMemberEmail, "DiscoveryService.discoveredHost", host);
|
||||
public void discoveredHost(String requesterSessionID, Host host) {
|
||||
messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveredHost", host);
|
||||
}
|
||||
|
||||
@ProbeAPI
|
||||
public void discoveredPort(String requestMemberEmail, Port port) {
|
||||
messagePublisher.publishToMember("/webapp", requestMemberEmail, "DiscoveryService.discoveredPort", port);
|
||||
public void discoveredPort(String requesterSessionID, Port port) {
|
||||
messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveredPort", port);
|
||||
}
|
||||
|
||||
@ProbeAPI
|
||||
public void discoveredService(String requestMemberEmail, com.loafle.overflow.module.discovery.model.Service service) {
|
||||
messagePublisher.publishToMember("/webapp", requestMemberEmail, "DiscoveryService.discoveredService", service);
|
||||
public void discoveredService(String requesterSessionID, com.loafle.overflow.module.discovery.model.Service service) {
|
||||
messagePublisher.publishToMemberSession(requesterSessionID, "DiscoveryService.discoveredService", service);
|
||||
}
|
||||
|
||||
}
|
|
@ -25,5 +25,6 @@ public interface DomainMemberDAO extends JpaRepository<DomainMember, Long> {
|
|||
@Query("SELECT dm.member from DomainMember dm where dm.domain = (:domain)")
|
||||
List<Member> findAllMemberByDomain(@Param("domain") Domain domain);
|
||||
|
||||
|
||||
@Query("SELECT dm.member from DomainMember dm where dm.domain.id = (:domainID)")
|
||||
List<Member> findAllMemberByDomainID(@Param("domainID") long domainID);
|
||||
}
|
||||
|
|
|
@ -39,4 +39,8 @@ public class DomainMemberService {
|
|||
return this.domainMemberDAO.findAllMemberByDomain(domain);
|
||||
}
|
||||
|
||||
public List<Member> readAllMemberByDomainID(final long domainID) {
|
||||
return this.domainMemberDAO.findAllMemberByDomainID(domainID);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -162,7 +162,7 @@ public class MemberService {
|
|||
|
||||
@WebappAPI
|
||||
public Member modify(Member member, String pw) {
|
||||
String email = SessionMetadata.getSessionID();
|
||||
String email = SessionMetadata.getTargetID();
|
||||
Member preMember = this.memberDAO.findByEmail(member.getEmail());
|
||||
|
||||
if (null != pw && !pw.equals("")) {
|
||||
|
@ -229,7 +229,7 @@ public class MemberService {
|
|||
|
||||
@WebappAPI
|
||||
public void withdrawal(Member member) {
|
||||
String email = SessionMetadata.getSessionID();
|
||||
String email = SessionMetadata.getTargetID();
|
||||
|
||||
// Todo DB delete?
|
||||
}
|
||||
|
@ -265,6 +265,11 @@ public class MemberService {
|
|||
return this.domainMemberService.readAllMemberByDomain(domain);
|
||||
}
|
||||
|
||||
public List<Member> readAllByDomainID(final long domainID) {
|
||||
|
||||
return this.domainMemberService.readAllMemberByDomainID(domainID);
|
||||
}
|
||||
|
||||
private static final String PASSWORD_REGEXP = "(" +
|
||||
"(?=.*[a-z])" +
|
||||
"(?=.*\\d)" +
|
||||
|
|
|
@ -55,7 +55,7 @@ public class NoAuthProbeService {
|
|||
ApiKey apiKey = apiKeyService.readByApiKey(noAuthProbe.getApiKey());
|
||||
noAuthProbe.setDomain(apiKey.getDomain());
|
||||
|
||||
messagePublisher.publishToDomain("/webapp", apiKey.getDomain(), "NoAuthProbeService.regist", noAuthProbe);
|
||||
messagePublisher.publishToDomainMembers(apiKey.getDomain().getId(), "NoAuthProbeService.regist", noAuthProbe);
|
||||
|
||||
return this.noAuthProbeDAO.save(noAuthProbe);
|
||||
}
|
||||
|
|
|
@ -7,8 +7,15 @@ public class ProxyServerInterceptor implements ServerInterceptor {
|
|||
|
||||
@Override
|
||||
public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
|
||||
String clientType = headers.get(SessionMetadata.METADATA_CLIENT_TYPE_KEY);
|
||||
String sessionID = headers.get(SessionMetadata.METADATA_SESSION_ID_KEY);
|
||||
Context ctx = Context.current().withValue(SessionMetadata.CTX_SESSION_ID_KEY, sessionID);
|
||||
String targetID = headers.get(SessionMetadata.METADATA_TARGET_ID_KEY);
|
||||
|
||||
Context ctx = Context.current().withValues(
|
||||
SessionMetadata.CTX_CLIENT_TYPE_KEY, clientType,
|
||||
SessionMetadata.CTX_SESSION_ID_KEY, sessionID,
|
||||
SessionMetadata.CTX_TARGET_ID_KEY, targetID
|
||||
);
|
||||
|
||||
return Contexts.interceptCall(ctx, call, headers, next);
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package com.loafle.overflow.redis.service;
|
|||
|
||||
import com.loafle.overflow.commons.model.PublishMessage;
|
||||
import com.loafle.overflow.commons.service.MessagePublisher;
|
||||
import com.loafle.overflow.module.domain.model.Domain;
|
||||
import com.loafle.overflow.module.member.model.Member;
|
||||
import com.loafle.overflow.module.member.service.MemberService;
|
||||
import org.codehaus.jackson.map.ObjectMapper;
|
||||
|
@ -19,6 +18,8 @@ import java.util.Map;
|
|||
|
||||
@Service
|
||||
public class RedisMessagePublisher implements MessagePublisher {
|
||||
private static final String CHANNEL_WEBAPP = "/webapp";
|
||||
private static final String CHANNEL_PROBE = "/probe";
|
||||
|
||||
@Autowired
|
||||
private RedisTemplate<String, Object> redisTemplate;
|
||||
|
@ -37,32 +38,43 @@ public class RedisMessagePublisher implements MessagePublisher {
|
|||
this.topics = topics;
|
||||
}
|
||||
|
||||
public void publishToMember(final String channel, final String memberID, final String method, final Object... params) {
|
||||
public void publishToDomainMembers(final long domainID, final String method, final Object... params) {
|
||||
PublishMessage message = new PublishMessage();
|
||||
message.addTarget(memberID);
|
||||
this.publish(channel, message, method, params);
|
||||
message.setTargetType(PublishMessage.TargetType.MEMBER);
|
||||
message.setTargets(getMemberListByDomainID(domainID));
|
||||
this.publish(CHANNEL_WEBAPP, message, method, params);
|
||||
}
|
||||
public void publishToDomain(final String channel, final Domain domain, final String method, final Object... params) {
|
||||
PublishMessage message = new PublishMessage();
|
||||
message.setTargets(getMemberListByDomain(domain));
|
||||
this.publish(channel, message, method, params);
|
||||
|
||||
}
|
||||
public void publishToDomainByProbeKey(final String channel, final String probeKey, final String method, final Object... params) {
|
||||
public void publishToDomainMembersByProbeKey(final String probeKey, final String method, final Object... params) {
|
||||
PublishMessage message = new PublishMessage();
|
||||
message.setTargetType(PublishMessage.TargetType.MEMBER);
|
||||
message.setTargets(getMemberListByProbeKey(probeKey));
|
||||
this.publish(channel, message, method, params);
|
||||
this.publish(CHANNEL_WEBAPP, message, method, params);
|
||||
}
|
||||
|
||||
public void publishToProbe(final String channel, final String key, final String method, final Object... params) {
|
||||
public void publishToMember(final String memberID, final String method, final Object... params) {
|
||||
PublishMessage message = new PublishMessage();
|
||||
message.addTarget(key);
|
||||
this.publish(channel, message, method, params);
|
||||
message.setTargetType(PublishMessage.TargetType.MEMBER);
|
||||
message.addTarget(memberID);
|
||||
this.publish(CHANNEL_WEBAPP, message, method, params);
|
||||
}
|
||||
public void publishToMemberSession(final String memberSessionID, final String method, final Object... params) {
|
||||
PublishMessage message = new PublishMessage();
|
||||
message.setTargetType(PublishMessage.TargetType.MEMBER_SESSION);
|
||||
message.addTarget(memberSessionID);
|
||||
this.publish(CHANNEL_WEBAPP, message, method, params);
|
||||
}
|
||||
|
||||
public void publishToProbe(final String probeKey, final String method, final Object... params) {
|
||||
PublishMessage message = new PublishMessage();
|
||||
message.setTargetType(PublishMessage.TargetType.PROBE);
|
||||
message.addTarget(probeKey);
|
||||
this.publish(CHANNEL_PROBE, message, method, params);
|
||||
}
|
||||
|
||||
|
||||
@Cacheable("memberListByDomain")
|
||||
protected List<String> getMemberListByDomain(final Domain domain) {
|
||||
return this.getMemberList(memberService.readAllByDomain(domain));
|
||||
protected List<String> getMemberListByDomainID(final long domainID) {
|
||||
return this.getMemberList(memberService.readAllByDomainID(domainID));
|
||||
}
|
||||
|
||||
@Cacheable("memberListByProbeKey")
|
||||
|
@ -108,10 +120,4 @@ public class RedisMessagePublisher implements MessagePublisher {
|
|||
return results;
|
||||
}
|
||||
|
||||
// public void publishToMember(final String message) {
|
||||
// redisTemplate.convertAndSend(topic.getTopic(), message);
|
||||
// }
|
||||
// public void publishToDomain(final String message) {
|
||||
// redisTemplate.convertAndSend(topic.getTopic(), message);
|
||||
// }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user