-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Command consul registry #96
Merged
rayzhang0603
merged 9 commits into
weibocom:master
from
sunnights:consul-command-registry
Jun 21, 2016
Merged
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ca5052e
feat: 支持command的consul注册中心
zyseap 53197c2
feat: consul中用tags存储url的parameter信息
zyseap 7c43452
fix: 修改单测代码
zyseap b9ccea0
test: 补充单测
zyseap f593c1a
refactor: 整合ConsulRegistry
zyseap 78c359d
fix: service的tag标记兼容旧Consul版本
zyseap 60b6a22
docs: add log and comment
zyseap e0002bd
docs: fix comment
zyseap cf1e36b
test: extend unit test
zyseap File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
174 changes: 174 additions & 0 deletions
174
motan-manager/src/main/java/com/weibo/service/impl/AbstractCommandService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,174 @@ | ||
package com.weibo.service.impl; | ||
|
||
import com.alibaba.fastjson.JSONObject; | ||
import com.weibo.api.motan.registry.support.command.RpcCommand; | ||
import com.weibo.api.motan.registry.support.command.RpcCommandUtil; | ||
import com.weibo.api.motan.util.LoggerUtil; | ||
import com.weibo.dao.OperationRecordMapper; | ||
import com.weibo.model.OperationRecord; | ||
import com.weibo.service.CommandService; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public abstract class AbstractCommandService implements CommandService { | ||
|
||
@Autowired(required = false) | ||
private OperationRecordMapper recordMapper; | ||
|
||
/** | ||
* 向指定group添加指令 | ||
* | ||
* @param group | ||
* @param command | ||
* @return | ||
*/ | ||
@Override | ||
public boolean addCommand(String group, RpcCommand.ClientCommand command) { | ||
RpcCommand remoteCommand = RpcCommandUtil.stringToCommand(getCommands(group)); | ||
if (remoteCommand == null) { | ||
remoteCommand = new RpcCommand(); | ||
} | ||
List<RpcCommand.ClientCommand> clientCommandList = remoteCommand.getClientCommandList(); | ||
if (clientCommandList == null) { | ||
clientCommandList = new ArrayList<RpcCommand.ClientCommand>(); | ||
} | ||
|
||
// 该方法只在流量切换界面被调用,此时指令序号默认是0 | ||
int index = getRpcCommandMaxIndex(remoteCommand); | ||
command.setIndex(index + 1); | ||
clientCommandList.add(command); | ||
remoteCommand.setClientCommandList(clientCommandList); | ||
|
||
return setCommand(group, remoteCommand); | ||
} | ||
|
||
/** | ||
* 更新指定group的某条指令 | ||
* | ||
* @param command | ||
* @param group | ||
* @return | ||
*/ | ||
@Override | ||
public boolean updateCommand(String group, RpcCommand.ClientCommand command) { | ||
RpcCommand remoteCommand = RpcCommandUtil.stringToCommand(getCommands(group)); | ||
if (remoteCommand == null) { | ||
LoggerUtil.info("update failed, command not found"); | ||
return false; | ||
} | ||
List<RpcCommand.ClientCommand> clientCommandList = remoteCommand.getClientCommandList(); | ||
if (clientCommandList == null) { | ||
LoggerUtil.info("update failed, command not found"); | ||
return false; | ||
} | ||
boolean found = false; | ||
for (RpcCommand.ClientCommand cmd : clientCommandList) { | ||
if (cmd.getIndex().equals(command.getIndex())) { | ||
clientCommandList.remove(cmd); | ||
clientCommandList.add(command); | ||
found = true; | ||
break; | ||
} | ||
} | ||
if (!found) { | ||
LoggerUtil.info("update failed, command not found"); | ||
return false; | ||
} | ||
remoteCommand.setClientCommandList(clientCommandList); | ||
return setCommand(group, remoteCommand); | ||
} | ||
|
||
/** | ||
* 删除指定group的某条指令 | ||
* | ||
* @param group | ||
* @param index | ||
* @return | ||
*/ | ||
@Override | ||
public boolean deleteCommand(String group, int index) { | ||
RpcCommand remoteCommand = RpcCommandUtil.stringToCommand(getCommands(group)); | ||
if (remoteCommand == null) { | ||
LoggerUtil.info("delete failed, command not found"); | ||
return false; | ||
} | ||
List<RpcCommand.ClientCommand> clientCommandList = remoteCommand.getClientCommandList(); | ||
if (clientCommandList == null) { | ||
LoggerUtil.info("delete failed, command not found"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 日志里记录上下文 |
||
return false; | ||
} | ||
boolean found = false; | ||
for (RpcCommand.ClientCommand cmd : clientCommandList) { | ||
if (cmd.getIndex() == index) { | ||
clientCommandList.remove(cmd); | ||
found = true; | ||
break; | ||
} | ||
} | ||
if (!found) { | ||
LoggerUtil.info("delete failed, command not found"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 日志里记录上下文 |
||
return false; | ||
} | ||
remoteCommand.setClientCommandList(clientCommandList); | ||
|
||
return setCommand(group, remoteCommand); | ||
} | ||
|
||
/** | ||
* 获取指令集中最大的指令序号 | ||
* | ||
* @param rpcCommand | ||
* @return | ||
*/ | ||
@Override | ||
public int getRpcCommandMaxIndex(RpcCommand rpcCommand) { | ||
return 0; | ||
} | ||
|
||
/** | ||
* 预览指令 | ||
* | ||
* @param group | ||
* @param clientCommand | ||
* @param previewIP | ||
* @return | ||
*/ | ||
@Override | ||
public List<JSONObject> previewCommand(String group, RpcCommand.ClientCommand clientCommand, String previewIP) { | ||
return null; | ||
} | ||
|
||
/** | ||
* 根据group和clientCommand生成指令 | ||
* | ||
* @param group | ||
* @param clientCommand | ||
* @return | ||
*/ | ||
@Override | ||
public RpcCommand buildCommand(String group, RpcCommand.ClientCommand clientCommand) { | ||
RpcCommand rpcCommand = new RpcCommand(); | ||
List<RpcCommand.ClientCommand> commandList = new ArrayList<RpcCommand.ClientCommand>(); | ||
commandList.add(clientCommand); | ||
rpcCommand.setClientCommandList(commandList); | ||
return rpcCommand; | ||
} | ||
|
||
/** | ||
* 获取指令操作记录 | ||
* | ||
* @return | ||
*/ | ||
@Override | ||
public List<OperationRecord> getAllRecord() { | ||
List<OperationRecord> records; | ||
if (recordMapper != null) { | ||
records = recordMapper.selectAll(); | ||
} else { | ||
return null; | ||
} | ||
return records; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
日志里记录上下文