use of com.alibaba.otter.shared.common.model.config.channel.Channel in project otter by alibaba.
the class ChannelServiceImpl method listByIds.
/*--------------------优化内容:listAll、listByIds、findById合并-------------------------------*/
public List<Channel> listByIds(Long... identities) {
List<Channel> channels = new ArrayList<Channel>();
try {
List<ChannelDO> channelDos = null;
if (identities.length < 1) {
channelDos = channelDao.listAll();
if (channelDos.isEmpty()) {
logger.debug("DEBUG ## couldn't query any channel, maybe hasn't create any channel.");
return channels;
}
} else {
channelDos = channelDao.listByMultiId(identities);
if (channelDos.isEmpty()) {
String exceptionCause = "couldn't query any channel by channelIds:" + Arrays.toString(identities);
logger.error("ERROR ## " + exceptionCause);
throw new ManagerException(exceptionCause);
}
}
channels = doToModel(channelDos);
} catch (Exception e) {
logger.error("ERROR ## query channels has an exception!");
throw new ManagerException(e);
}
return channels;
}
use of com.alibaba.otter.shared.common.model.config.channel.Channel in project otter by alibaba.
the class FileLoadActionTest method testLoadWithLocal.
@Test
public void testLoadWithLocal() throws IOException {
// 构造fileData使用的参数,fileDataStartIndex 决定着 pipeline 与 fileData 对应的关系(通过
// dataMediaPair 的 id),
// 以及 dataMediaPair 的 pushWeight
final int fileDataStartIndex = 0;
final int fileDataCount = 50;
final Pipeline pipeline = buildPipeline(fileDataStartIndex, fileDataCount);
final Channel channel = new Channel();
new NonStrictExpectations() {
{
configClientService.findChannel(anyLong);
returns(channel);
configClientService.findPipeline(anyLong);
returns(pipeline);
}
};
Identity id = buildIdentity(1L, 2L, 3L);
FileBatch fileBatch = buildFileBatch(id);
fileBatch.getFiles().addAll(buildFileDatas(null, EventType.INSERT, fileDataStartIndex, fileDataCount, true));
WeightController controller = new WeightController(1);
FileLoadContext context = fileLoadAction.load(fileBatch, ROOT_DIR, controller);
want.object(context.getChannel()).isEqualTo(channel);
want.object(context.getPipeline()).isEqualTo(pipeline);
want.object(context.getPrepareDatas()).isEqualTo(fileBatch.getFiles());
want.number(context.getProcessedDatas().size()).isEqualTo(fileBatch.getFiles().size());
}
use of com.alibaba.otter.shared.common.model.config.channel.Channel in project otter by alibaba.
the class DbLoadActionTest method test_db_load_mysql.
@Test
public void test_db_load_mysql() {
ArbitrateConfigRegistry.regist(configClientService);
dbLoadAction = (DbLoadAction) TestedObject.getSpringBeanFactory().getBean("dbLoadAction");
final Channel channel = new Channel();
channel.setId(1L);
final Pipeline pipeline = new Pipeline();
pipeline.setId(100L);
List<DataMediaPair> pairs = generatorDataMediaPairForMysql(20);
pipeline.setPairs(pairs);
pipeline.getParameters().merge(new SystemParameter());
pipeline.getParameters().merge(new ChannelParameter());
// pipeline.getParameters().setChannelInfo("LJH_DEMO");
// final Pipeline oppositePipeline = new Pipeline();
// oppositePipeline.setId(101L);
channel.setPipelines(Arrays.asList(pipeline));
final Node currentNode = new Node();
currentNode.setId(1L);
new NonStrictExpectations() {
{
configClientService.findChannel(anyLong);
returns(channel);
configClientService.findPipeline(anyLong);
returns(pipeline);
configClientService.currentNode();
returns(currentNode);
}
};
Identity identity = new Identity();
identity.setChannelId(100L);
identity.setPipelineId(100L);
identity.setProcessId(100L);
RowBatch rowBatch = new RowBatch();
rowBatch.setIdentity(identity);
List<EventData> eventDatas = generatorEventDataForMysql(0, 20, EventType.INSERT);
for (EventData eventData : eventDatas) {
rowBatch.merge(eventData);
}
eventDatas = generatorEventDataForMysql(10, 10, EventType.INSERT);
for (EventData eventData : eventDatas) {
rowBatch.merge(eventData);
}
eventDatas = generatorEventDataForMysql(19, 1, EventType.DELETE);
for (EventData eventData : eventDatas) {
rowBatch.merge(eventData);
}
WeightController controller = new WeightController(1);
dbLoadAction.load(rowBatch, controller);
}
use of com.alibaba.otter.shared.common.model.config.channel.Channel in project otter by alibaba.
the class ConfigClientServiceImpl method afterPropertiesSet.
public void afterPropertiesSet() throws Exception {
// 获取一下nid变量
String nid = System.getProperty(NID_NAME);
if (StringUtils.isEmpty(nid)) {
throw new ConfigException("nid is not set!");
}
this.nid = Long.valueOf(nid);
channelMapping = new MapMaker().makeComputingMap(new Function<Long, Long>() {
public Long apply(Long pipelineId) {
// 处理下pipline -> channel映射关系不存在的情况
FindChannelEvent event = new FindChannelEvent();
event.setPipelineId(pipelineId);
try {
Object obj = nodeCommmunicationClient.callManager(event);
if (obj != null && obj instanceof Channel) {
Channel channel = (Channel) obj;
// 排除下自己
updateMapping(channel, pipelineId);
// 更新下channelCache
channelCache.put(channel.getId(), channel);
return channel.getId();
}
} catch (Exception e) {
logger.error("call_manager_error", event.toString(), e);
}
throw new ConfigException("No Such Channel by pipelineId[" + pipelineId + "]");
}
});
nodeCache = new RefreshMemoryMirror<Long, Node>(timeout, new ComputeFunction<Long, Node>() {
public Node apply(Long key, Node oldValue) {
FindNodeEvent event = new FindNodeEvent();
event.setNid(key);
try {
Object obj = nodeCommmunicationClient.callManager(event);
if (obj != null && obj instanceof Node) {
return (Node) obj;
} else {
throw new ConfigException("No Such Node by id[" + key + "]");
}
} catch (Exception e) {
logger.error("call_manager_error", event.toString(), e);
}
// 其他情况直接返回内存中的旧值
return oldValue;
}
});
channelCache = new RefreshMemoryMirror<Long, Channel>(timeout, new ComputeFunction<Long, Channel>() {
public Channel apply(Long key, Channel oldValue) {
FindChannelEvent event = new FindChannelEvent();
event.setChannelId(key);
try {
Object obj = nodeCommmunicationClient.callManager(event);
if (obj != null && obj instanceof Channel) {
// 排除下自己
updateMapping((Channel) obj, null);
return (Channel) obj;
} else {
throw new ConfigException("No Such Channel by pipelineId[" + key + "]");
}
} catch (Exception e) {
logger.error("call_manager_error", event.toString(), e);
}
// 其他情况直接返回内存中的旧值
return oldValue;
}
});
}
use of com.alibaba.otter.shared.common.model.config.channel.Channel in project otter by alibaba.
the class ConfigClientServiceImpl method findOppositePipeline.
public Pipeline findOppositePipeline(Long pipelineId) {
Long channelId = channelMapping.get(pipelineId);
Channel channel = channelCache.get(channelId);
List<Pipeline> pipelines = channel.getPipelines();
for (Pipeline pipeline : pipelines) {
if (pipeline.getId().equals(pipelineId) == false) {
// 这里假定pipeline只有两个
return pipeline;
}
}
return null;
}
Aggregations