Search in sources :

Example 1 with SelectorData

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)));
}
Also used : SelectorDO(org.apache.shenyu.admin.model.entity.SelectorDO) DataChangedEvent(org.apache.shenyu.admin.listener.DataChangedEvent) ConditionData(org.apache.shenyu.common.dto.ConditionData) PluginDO(org.apache.shenyu.admin.model.entity.PluginDO) SelectorConditionQuery(org.apache.shenyu.admin.model.query.SelectorConditionQuery) SelectorData(org.apache.shenyu.common.dto.SelectorData)

Example 2 with 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;
}
Also used : SelectorDO(org.apache.shenyu.admin.model.entity.SelectorDO) DataChangedEvent(org.apache.shenyu.admin.listener.DataChangedEvent) ShenyuException(org.apache.shenyu.common.exception.ShenyuException) SelectorData(org.apache.shenyu.common.dto.SelectorData)

Example 3 with SelectorData

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));
}
Also used : RuleData(org.apache.shenyu.common.dto.RuleData) PluginData(org.apache.shenyu.common.dto.PluginData) SelectorData(org.apache.shenyu.common.dto.SelectorData) Test(org.junit.jupiter.api.Test)

Example 4 with SelectorData

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));
}
Also used : PluginVO(org.apache.shenyu.admin.model.vo.PluginVO) SelectorData(org.apache.shenyu.common.dto.SelectorData) Test(org.junit.jupiter.api.Test)

Example 5 with SelectorData

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);
}
Also used : SelectorData(org.apache.shenyu.common.dto.SelectorData) Test(org.junit.jupiter.api.Test)

Aggregations

SelectorData (org.apache.shenyu.common.dto.SelectorData)96 Test (org.junit.jupiter.api.Test)60 RuleData (org.apache.shenyu.common.dto.RuleData)47 ShenyuContext (org.apache.shenyu.plugin.api.context.ShenyuContext)18 ShenyuPluginChain (org.apache.shenyu.plugin.api.ShenyuPluginChain)16 ServerWebExchange (org.springframework.web.server.ServerWebExchange)16 List (java.util.List)14 Objects (java.util.Objects)12 PluginData (org.apache.shenyu.common.dto.PluginData)12 Mono (reactor.core.publisher.Mono)12 Map (java.util.Map)10 MetaData (org.apache.shenyu.common.dto.MetaData)10 PluginEnum (org.apache.shenyu.common.enums.PluginEnum)10 Logger (org.slf4j.Logger)10 LoggerFactory (org.slf4j.LoggerFactory)10 ArrayList (java.util.ArrayList)8 Optional (java.util.Optional)8 CollectionUtils (org.apache.commons.collections4.CollectionUtils)7 AbstractShenyuPlugin (org.apache.shenyu.plugin.base.AbstractShenyuPlugin)7 Collectors (java.util.stream.Collectors)6