use of org.apache.shenyu.common.dto.SelectorData in project incubator-shenyu by apache.
the class UpstreamCheckService method updateSelectorHandler.
private void updateSelectorHandler(final String selectorId, final List<CommonUpstream> aliveList) {
SelectorDO selectorDO = selectorMapper.selectById(selectorId);
if (Objects.isNull(selectorDO)) {
return;
}
PluginDO pluginDO = pluginMapper.selectById(selectorDO.getPluginId());
String handler = converterFactor.newInstance(pluginDO.getName()).handler(selectorDO.getHandle(), aliveList);
selectorDO.setHandle(handler);
selectorMapper.updateSelective(selectorDO);
List<ConditionData> conditionDataList = ConditionTransfer.INSTANCE.mapToSelectorDOS(selectorConditionMapper.selectByQuery(new SelectorConditionQuery(selectorDO.getId())));
SelectorData selectorData = SelectorDO.transFrom(selectorDO, pluginDO.getName(), conditionDataList);
selectorData.setHandle(handler);
// publish change event.
eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.SELECTOR, DataEventTypeEnum.UPDATE, Collections.singletonList(selectorData)));
}
use of org.apache.shenyu.common.dto.SelectorData in project incubator-shenyu by apache.
the class AbstractShenyuClientRegisterServiceImpl method doRegisterURI.
/**
* Register uri string.
*
* @param selectorName the selector name
* @param uriList the uri list
* @return the string
*/
@Override
public String doRegisterURI(final String selectorName, final List<URIRegisterDTO> uriList) {
if (CollectionUtils.isEmpty(uriList)) {
return "";
}
SelectorDO selectorDO = selectorService.findByNameAndPluginName(selectorName, PluginNameAdapter.rpcTypeAdapter(rpcType()));
if (Objects.isNull(selectorDO)) {
throw new ShenyuException("doRegister Failed to execute,wait to retry.");
}
// fetch UPSTREAM_MAP data from db
// upstreamCheckService.fetchUpstreamData();
// update upstream
String handler = buildHandle(uriList, selectorDO);
selectorDO.setHandle(handler);
SelectorData selectorData = selectorService.buildByName(selectorName, PluginNameAdapter.rpcTypeAdapter(rpcType()));
selectorData.setHandle(handler);
// update db
selectorService.updateSelective(selectorDO);
// publish change event.
eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.SELECTOR, DataEventTypeEnum.UPDATE, Collections.singletonList(selectorData)));
return ShenyuResultMessage.SUCCESS;
}
use of org.apache.shenyu.common.dto.SelectorData in project incubator-shenyu by apache.
the class SyncDataServiceTest method syncAllTest.
@Test
public void syncAllTest() {
PluginData pluginData = buildPluginData();
SelectorData selectorData = buildSelectorData();
RuleData ruleData = buildRuleData();
given(this.appAuthService.syncData()).willReturn(ShenyuAdminResult.success());
given(this.pluginService.listAll()).willReturn(Collections.singletonList(pluginData));
given(this.selectorService.listAll()).willReturn(Collections.singletonList(selectorData));
given(this.ruleService.listAll()).willReturn(Collections.singletonList(ruleData));
assertThat(syncDataService.syncAll(DataEventTypeEnum.CREATE), greaterThan(false));
}
use of org.apache.shenyu.common.dto.SelectorData in project incubator-shenyu by apache.
the class SyncDataServiceTest method syncPluginDataTest.
@Test
public void syncPluginDataTest() {
PluginVO pluginVO = buildPluginVO();
given(this.pluginService.findById(pluginVO.getId())).willReturn(pluginVO);
SelectorData selectorData = buildSelectorData();
given(this.selectorService.findByPluginId(pluginVO.getId())).willReturn(Collections.singletonList(selectorData));
assertThat(syncDataService.syncPluginData(pluginVO.getId()), greaterThan(false));
}
use of org.apache.shenyu.common.dto.SelectorData in project incubator-shenyu by apache.
the class ZookeeperDataChangedListenerTest method testOnSelectorChangedRefresh.
/**
* test case onSelectorChanged refresh event.
*/
@Test
public void testOnSelectorChangedRefresh() {
SelectorData selectorData = SelectorData.builder().id(MOCK_ID).name(MOCK_NAME).pluginName(MOCK_PLUGIN_NAME).build();
String selectorParentPath = DefaultPathConstants.buildSelectorParentPath(selectorData.getPluginName());
when(zkClient.exists(selectorParentPath)).thenReturn(true);
zookeeperDataChangedListener.onSelectorChanged(ImmutableList.of(selectorData), DataEventTypeEnum.REFRESH);
verify(zkClient, times(1)).deleteRecursive(selectorParentPath);
}
Aggregations