This is an automated email from the ASF dual-hosted git repository. ningjiang pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-servicecomb-saga.git
commit 428f87794595a64c270d9d75796db9a1254ee241 Author: cherrylzhao <zhaoju...@126.com> AuthorDate: Mon Aug 27 10:55:33 2018 +0800 SCB-856 Refactor TCC alpha server using the same grpc port of saga. --- .../servicecomb/saga/alpha/server/AlphaConfig.java | 8 ++--- .../saga/alpha/server/GrpcServerConfig.java | 2 ++ .../saga/alpha/server/SagaGrpcServerConfig.java | 28 ---------------- .../saga/alpha/server/tcc/AlphaTccConfig.java | 38 ---------------------- .../saga/alpha/server/tcc/GrpcTccEventService.java | 4 +-- .../saga/alpha/server/tcc/TccGrpcServerConfig.java | 37 --------------------- .../src/main/resources/application.yaml | 2 -- .../saga/alpha/server/AlphaIntegrationTest.java | 19 +++-------- .../alpha/server/AlphaIntegrationWithSSLTest.java | 3 +- .../saga/alpha/tcc/server/AlphaTccServerTest.java | 5 ++- 10 files changed, 16 insertions(+), 130 deletions(-) diff --git a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/AlphaConfig.java b/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/AlphaConfig.java index 6e31628..8d9af1e 100644 --- a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/AlphaConfig.java +++ b/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/AlphaConfig.java @@ -34,15 +34,14 @@ import org.apache.servicecomb.saga.alpha.core.PushBackOmegaCallback; import org.apache.servicecomb.saga.alpha.core.TxConsistentService; import org.apache.servicecomb.saga.alpha.core.TxEventRepository; import org.apache.servicecomb.saga.alpha.core.TxTimeoutRepository; +import org.apache.servicecomb.saga.alpha.server.tcc.GrpcTccEventService; import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; import org.springframework.boot.autoconfigure.domain.EntityScan; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @EntityScan(basePackages = "org.apache.servicecomb.saga.alpha") @Configuration -@ConditionalOnExpression("'${alpha.mode:SAGA}'.contains('SAGA')") class AlphaConfig { private final BlockingQueue<Runnable> pendingCompensations = new LinkedBlockingQueue<>(); private final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); @@ -102,10 +101,11 @@ class AlphaConfig { } @Bean - ServerStartable sagaServerBootstrap(SagaGrpcServerConfig serverConfig, TxConsistentService txConsistentService, + ServerStartable serverStartable(GrpcServerConfig serverConfig, TxConsistentService txConsistentService, Map<String, Map<String, OmegaCallback>> omegaCallbacks) { ServerStartable bootstrap = new GrpcStartable(serverConfig, - new GrpcTxEventEndpointImpl(txConsistentService, omegaCallbacks)); + new GrpcTxEventEndpointImpl(txConsistentService, omegaCallbacks), + new GrpcTccEventService()); new Thread(bootstrap::start).start(); return bootstrap; } diff --git a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/GrpcServerConfig.java b/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/GrpcServerConfig.java index bb4c880..e1368c4 100644 --- a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/GrpcServerConfig.java +++ b/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/GrpcServerConfig.java @@ -18,7 +18,9 @@ package org.apache.servicecomb.saga.alpha.server; import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Configuration; +@Configuration public class GrpcServerConfig { @Value("${alpha.server.host:0.0.0.0}") private String host; diff --git a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/SagaGrpcServerConfig.java b/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/SagaGrpcServerConfig.java deleted file mode 100644 index fd86a91..0000000 --- a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/SagaGrpcServerConfig.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.servicecomb.saga.alpha.server; - -import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; -import org.springframework.context.annotation.Configuration; - -@Configuration -@ConditionalOnExpression("'${alpha.mode:SAGA}'.contains('SAGA')") -public class SagaGrpcServerConfig extends GrpcServerConfig { -} - - diff --git a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/tcc/AlphaTccConfig.java b/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/tcc/AlphaTccConfig.java deleted file mode 100644 index 97b35ee..0000000 --- a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/tcc/AlphaTccConfig.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.servicecomb.saga.alpha.server.tcc; - -import org.apache.servicecomb.saga.alpha.server.GrpcStartable; -import org.apache.servicecomb.saga.alpha.server.ServerStartable; -import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; -import org.springframework.boot.autoconfigure.domain.EntityScan; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -@Configuration -@EntityScan(basePackages = "org.apache.servicecomb.saga.alpha") -@ConditionalOnExpression("'${alpha.mode:SAGA}'.contains('TCC')") -public class AlphaTccConfig { - - @Bean - ServerStartable tccServerBootstrap(TccGrpcServerConfig serverConfig) { - ServerStartable bootstrap = new GrpcStartable(serverConfig, new GrpcTccEventService()); - new Thread(bootstrap::start).start(); - return bootstrap; - } -} diff --git a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/tcc/GrpcTccEventService.java b/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/tcc/GrpcTccEventService.java index cd61162..ef9adbe 100644 --- a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/tcc/GrpcTccEventService.java +++ b/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/tcc/GrpcTccEventService.java @@ -59,8 +59,8 @@ public class GrpcTccEventService extends TccEventServiceGrpc.TccEventServiceImpl public void onTccTransactionEnded(GrpcTccTransactionEndedEvent request, StreamObserver<GrpcAck> responseObserver) { try { for (ParticipatedEvent event : TransactionEventRegistry.retrieve(request.getGlobalTxId())) { - OmegaCallbacksRegistry.retrieve(event.getServiceName(), - event.getInstanceId()).invoke(event, request.getStatus()); + OmegaCallbacksRegistry.retrieve(event.getServiceName(), event.getInstanceId()) + .invoke(event, request.getStatus()); } } catch (AlphaException ex) { responseObserver.onNext(REJECT); diff --git a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/tcc/TccGrpcServerConfig.java b/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/tcc/TccGrpcServerConfig.java deleted file mode 100644 index 20ab063..0000000 --- a/alpha/alpha-server/src/main/java/org/apache/servicecomb/saga/alpha/server/tcc/TccGrpcServerConfig.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.apache.servicecomb.saga.alpha.server.tcc; - -import org.apache.servicecomb.saga.alpha.server.GrpcServerConfig; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; -import org.springframework.context.annotation.Configuration; - -@Configuration -@ConditionalOnExpression("'${alpha.mode:SAGA}'.contains('TCC')") -public class TccGrpcServerConfig extends GrpcServerConfig { - - @Value("${alpha.server.tcc-port:8080}") - private int port; - - public int getPort() { - return port; - } -} - - diff --git a/alpha/alpha-server/src/main/resources/application.yaml b/alpha/alpha-server/src/main/resources/application.yaml index 92009ac..b8cd118 100644 --- a/alpha/alpha-server/src/main/resources/application.yaml +++ b/alpha/alpha-server/src/main/resources/application.yaml @@ -21,8 +21,6 @@ alpha: server: host: 0.0.0.0 port: 8080 - tcc-port: 8180 - mode: SAGA,TCC --- spring: diff --git a/alpha/alpha-server/src/test/java/org/apache/servicecomb/saga/alpha/server/AlphaIntegrationTest.java b/alpha/alpha-server/src/test/java/org/apache/servicecomb/saga/alpha/server/AlphaIntegrationTest.java index 1af6b05..8f5122b 100644 --- a/alpha/alpha-server/src/test/java/org/apache/servicecomb/saga/alpha/server/AlphaIntegrationTest.java +++ b/alpha/alpha-server/src/test/java/org/apache/servicecomb/saga/alpha/server/AlphaIntegrationTest.java @@ -32,8 +32,10 @@ import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; -import java.io.File; -import java.util.Arrays; +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.netty.NettyChannelBuilder; +import io.grpc.stub.StreamObserver; import java.util.List; import java.util.Map; import java.util.Queue; @@ -41,10 +43,7 @@ import java.util.UUID; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.Executors; import java.util.function.Consumer; - import javax.annotation.PostConstruct; -import javax.net.ssl.SSLException; - import org.apache.servicecomb.saga.alpha.core.CommandRepository; import org.apache.servicecomb.saga.alpha.core.EventScanner; import org.apache.servicecomb.saga.alpha.core.OmegaCallback; @@ -70,22 +69,14 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringRunner; -import com.google.protobuf.ByteString; - -import io.grpc.ManagedChannel; -import io.grpc.netty.NettyChannelBuilder; -import io.grpc.stub.StreamObserver; - @RunWith(SpringRunner.class) @SpringBootTest(classes = {AlphaApplication.class, AlphaConfig.class}, properties = { "alpha.server.host=0.0.0.0", "alpha.server.port=8090", - "alpha.event.pollingInterval=1", - "alpha.mode=SAGA" + "alpha.event.pollingInterval=1" }) public class AlphaIntegrationTest { private static final int port = 8090; diff --git a/alpha/alpha-server/src/test/java/org/apache/servicecomb/saga/alpha/server/AlphaIntegrationWithSSLTest.java b/alpha/alpha-server/src/test/java/org/apache/servicecomb/saga/alpha/server/AlphaIntegrationWithSSLTest.java index e14775c..8a2df82 100644 --- a/alpha/alpha-server/src/test/java/org/apache/servicecomb/saga/alpha/server/AlphaIntegrationWithSSLTest.java +++ b/alpha/alpha-server/src/test/java/org/apache/servicecomb/saga/alpha/server/AlphaIntegrationWithSSLTest.java @@ -39,8 +39,7 @@ import io.netty.handler.ssl.SslProvider; properties = { "alpha.server.host=0.0.0.0", "alpha.server.port=8092", - "alpha.event.pollingInterval=1", - "alpha.mode=SAGA" + "alpha.event.pollingInterval=1" }) public class AlphaIntegrationWithSSLTest extends AlphaIntegrationTest { private static final int port = 8092; diff --git a/alpha/alpha-server/src/test/java/org/apache/servicecomb/saga/alpha/tcc/server/AlphaTccServerTest.java b/alpha/alpha-server/src/test/java/org/apache/servicecomb/saga/alpha/tcc/server/AlphaTccServerTest.java index 102141e..50b992f 100644 --- a/alpha/alpha-server/src/test/java/org/apache/servicecomb/saga/alpha/tcc/server/AlphaTccServerTest.java +++ b/alpha/alpha-server/src/test/java/org/apache/servicecomb/saga/alpha/tcc/server/AlphaTccServerTest.java @@ -57,12 +57,11 @@ import org.springframework.test.context.junit4.SpringRunner; @SpringBootTest(classes = {AlphaApplication.class}, properties = { "alpha.server.host=0.0.0.0", - "alpha.server.tcc-port=8190", - "alpha.mode=TCC" + "alpha.server.port=8090" }) public class AlphaTccServerTest { - private static final int port = 8190; + private static final int port = 8090; protected static ManagedChannel clientChannel; private final TccEventServiceStub asyncStub = TccEventServiceGrpc.newStub(clientChannel);