Search in sources :

Example 1 with MetaData

use of org.apache.shenyu.common.dto.MetaData in project incubator-shenyu by apache.

the class MetaDataServiceImpl method delete.

@Override
@Transactional(rollbackFor = Exception.class)
public int delete(final List<String> ids) {
    int count = 0;
    Set<String> idSet = Optional.ofNullable(ids).orElseGet(ArrayList::new).stream().filter(StringUtils::isNotEmpty).collect(Collectors.toSet());
    if (CollectionUtils.isNotEmpty(idSet)) {
        List<MetaDataDO> metaDataDoList = metaDataMapper.selectByIdSet(idSet);
        List<MetaData> metaDataList = Optional.ofNullable(metaDataDoList).orElseGet(ArrayList::new).stream().map(MetaDataTransfer.INSTANCE::mapToData).collect(Collectors.toList());
        count = metaDataMapper.deleteByIdSet(idSet);
        eventPublisher.publishEvent(new DataChangedEvent(ConfigGroupEnum.META_DATA, DataEventTypeEnum.DELETE, metaDataList));
    }
    return count;
}
Also used : DataChangedEvent(org.apache.shenyu.admin.listener.DataChangedEvent) MetaData(org.apache.shenyu.common.dto.MetaData) MetaDataDO(org.apache.shenyu.admin.model.entity.MetaDataDO) MetaDataTransfer(org.apache.shenyu.admin.transfer.MetaDataTransfer) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with MetaData

use of org.apache.shenyu.common.dto.MetaData in project incubator-shenyu by apache.

the class AlibabaDubboProxyServiceTest method setup.

@BeforeEach
public void setup() {
    metaData = new MetaData();
    metaData.setId("1332017966661636096");
    metaData.setAppName("sofa");
    metaData.setPath(PATH);
    metaData.setServiceName("org.apache.shenyu.test.dubbo.api.service.DubboTestService");
    metaData.setMethodName(METHOD_NAME);
    metaData.setRpcType(RpcTypeEnum.SOFA.getName());
}
Also used : MetaData(org.apache.shenyu.common.dto.MetaData) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with MetaData

use of org.apache.shenyu.common.dto.MetaData in project incubator-shenyu by apache.

the class AlibabaDubboMetaDataSubscriberTest method testOnSubscribe.

@Test
public void testOnSubscribe() {
    alibabaDubboMetaDataSubscriber.onSubscribe(metaData);
    MetaData metaData = MetaData.builder().id("1332017966661636096").appName("dubbo").path("/dubbo/findAll").serviceName("org.apache.shenyu.test.dubbo.api.service.DubboTestService").methodName("findById").rpcType(RpcTypeEnum.DUBBO.getName()).rpcExt("{\"group\":\"Group\",\"version\":\"2.6.5\",\"loadbalance\":\"roundrobin\",\"url\":\"http://192.168.55.113/dubbo\"}").parameterTypes("parameterTypes").build();
    AlibabaDubboMetaDataSubscriber alibabaDubboMetaDataSubscriberMock = mock(AlibabaDubboMetaDataSubscriber.class);
    doNothing().when(alibabaDubboMetaDataSubscriberMock).onSubscribe(metaData);
    alibabaDubboMetaDataSubscriberMock.onSubscribe(metaData);
    alibabaDubboMetaDataSubscriber.unSubscribe(metaData);
}
Also used : MetaData(org.apache.shenyu.common.dto.MetaData) Test(org.junit.jupiter.api.Test)

Example 4 with MetaData

use of org.apache.shenyu.common.dto.MetaData in project incubator-shenyu by apache.

the class ApacheDubboConfigCacheTest method testInitRef.

@Test
public void testInitRef() {
    MetaData metaData = new MetaData();
    metaData.setPath("/test");
    ApacheDubboConfigCache apacheDubboConfigCacheMock = mock(ApacheDubboConfigCache.class);
    when(apacheDubboConfigCacheMock.initRef(metaData)).thenReturn(new org.apache.dubbo.config.ReferenceConfig<>());
    assertNotNull(apacheDubboConfigCacheMock.initRef(metaData));
}
Also used : MetaData(org.apache.shenyu.common.dto.MetaData) Test(org.junit.jupiter.api.Test)

Example 5 with MetaData

use of org.apache.shenyu.common.dto.MetaData in project incubator-shenyu by apache.

the class AlibabaDubboPlugin method doDubboInvoker.

/**
 * do dubbo invoker.
 *
 * @param exchange exchange the current server exchange {@linkplain ServerWebExchange}
 * @param chain    chain the current chain  {@linkplain ServerWebExchange}
 * @param selector selector    {@linkplain SelectorData}
 * @param rule     rule    {@linkplain RuleData}
 * @param metaData the medata
 * @param param    the param
 * @return {@code Mono<Void>} to indicate when request handling is complete
 */
@Override
protected Mono<Void> doDubboInvoker(final ServerWebExchange exchange, final ShenyuPluginChain chain, final SelectorData selector, final RuleData rule, final MetaData metaData, final String param) {
    RpcContext.getContext().setAttachment(Constants.DUBBO_SELECTOR_ID, selector.getId());
    RpcContext.getContext().setAttachment(Constants.DUBBO_RULE_ID, rule.getId());
    RpcContext.getContext().setAttachment(Constants.DUBBO_REMOTE_ADDRESS, Objects.requireNonNull(exchange.getRequest().getRemoteAddress()).getAddress().getHostAddress());
    return Mono.create(monoSink -> {
        ResponseFuture future = alibabaDubboProxyService.genericInvoker(param, metaData);
        future.setCallback(new ResponseCallback() {

            @Override
            public void done(final Object resultObj) {
                assert resultObj instanceof Result;
                Result result = (Result) resultObj;
                if (result.hasException()) {
                    this.caught(result.getException());
                    return;
                }
                monoSink.success(result.getValue());
            }

            @Override
            public void caught(final Throwable ex) {
                LOG.error("dubbo failed using async genericInvoker() metaData={} param={}", metaData, param, ex);
                monoSink.error(ex);
            }
        });
    }).flatMap(response -> {
        exchange.getAttributes().put(Constants.RPC_RESULT, Objects.nonNull(response) ? response : Constants.DUBBO_RPC_RESULT_EMPTY);
        exchange.getAttributes().put(Constants.CLIENT_RESPONSE_RESULT_TYPE, ResultEnum.SUCCESS.getName());
        return chain.execute(exchange);
    });
}
Also used : AlibabaDubboProxyService(org.apache.shenyu.plugin.alibaba.dubbo.proxy.AlibabaDubboProxyService) AbstractDubboPlugin(org.apache.shenyu.plugin.dubbo.common.AbstractDubboPlugin) Constants(org.apache.shenyu.common.constant.Constants) ResponseFuture(com.alibaba.dubbo.remoting.exchange.ResponseFuture) Logger(org.slf4j.Logger) Result(com.alibaba.dubbo.rpc.Result) ShenyuPluginChain(org.apache.shenyu.plugin.api.ShenyuPluginChain) ResponseCallback(com.alibaba.dubbo.remoting.exchange.ResponseCallback) LoggerFactory(org.slf4j.LoggerFactory) RuleData(org.apache.shenyu.common.dto.RuleData) Mono(reactor.core.publisher.Mono) ResultEnum(org.apache.shenyu.common.enums.ResultEnum) ServerWebExchange(org.springframework.web.server.ServerWebExchange) Objects(java.util.Objects) Map(java.util.Map) RpcContext(com.alibaba.dubbo.rpc.RpcContext) MetaData(org.apache.shenyu.common.dto.MetaData) SelectorData(org.apache.shenyu.common.dto.SelectorData) ResponseCallback(com.alibaba.dubbo.remoting.exchange.ResponseCallback) ResponseFuture(com.alibaba.dubbo.remoting.exchange.ResponseFuture) Result(com.alibaba.dubbo.rpc.Result)

Aggregations

MetaData (org.apache.shenyu.common.dto.MetaData)70 Test (org.junit.jupiter.api.Test)31 BeforeEach (org.junit.jupiter.api.BeforeEach)14 RuleData (org.apache.shenyu.common.dto.RuleData)11 SelectorData (org.apache.shenyu.common.dto.SelectorData)10 ShenyuContext (org.apache.shenyu.plugin.api.context.ShenyuContext)9 ArrayList (java.util.ArrayList)8 MetaDataSubscriber (org.apache.shenyu.sync.data.api.MetaDataSubscriber)8 ServerWebExchange (org.springframework.web.server.ServerWebExchange)7 Objects (java.util.Objects)6 ShenyuException (org.apache.shenyu.common.exception.ShenyuException)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 Optional (java.util.Optional)5 Constants (org.apache.shenyu.common.constant.Constants)5 ShenyuPluginChain (org.apache.shenyu.plugin.api.ShenyuPluginChain)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 ResultEnum (org.apache.shenyu.common.enums.ResultEnum)4 RpcTypeEnum (org.apache.shenyu.common.enums.RpcTypeEnum)4 GsonUtils (org.apache.shenyu.common.utils.GsonUtils)4