Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@
import io.servicecomb.foundation.common.utils.BeanUtils;

public final class ExecutorManager {
public static final String KEY_EXECUTORS_DEFAULT = "cse.executors.default";

public static final String EXECUTOR_GROUP_THREADPOOL = "cse.executor.groupThreadPool";

public static final String EXECUTOR_REACTIVE = "cse.executor.reactive";

public static final String EXECUTOR_DEFAULT = EXECUTOR_GROUP_THREADPOOL;

private ExecutorManager() {
}

Expand All @@ -40,12 +48,12 @@ public static Executor findExecutor(OperationMeta operationMeta) {
return executor;
}

executor = findByKey("cse.executors.default");
executor = findByKey(KEY_EXECUTORS_DEFAULT);
if (executor != null) {
return executor;
}

return BeanUtils.getBean("cse.executor.default");
return BeanUtils.getBean(EXECUTOR_DEFAULT);
}

protected static Executor findByKey(String beanIdKey) {
Expand Down
27 changes: 14 additions & 13 deletions core/src/main/resources/META-INF/spring/cse.bean.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,25 @@
~ limitations under the License.
-->

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans classpath:org/springframework/beans/factory/xml/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:annotation-config />
<context:annotation-config />
<!-- <context:spring-configured /> -->
<context:component-scan base-package="io.servicecomb" />
<context:component-scan base-package="io.servicecomb" />

<bean class="io.servicecomb.core.config.ConfigurationSpringInitializer">
<property name="configId" value="config" />
</bean>
<bean class="io.servicecomb.core.config.ConfigurationSpringInitializer">
<property name="configId" value="config" />
</bean>

<bean class="io.servicecomb.core.CseContext" factory-method="getInstance"></bean>
<bean class="io.servicecomb.core.CseContext" factory-method="getInstance"></bean>

<bean class="io.servicecomb.core.CseApplicationListener">
</bean>
<bean class="io.servicecomb.core.CseApplicationListener">
</bean>

<bean id="cse.executor.default" class="io.servicecomb.core.executor.FixedThreadExecutor"></bean>
<bean id="cse.executor.reactive" class="io.servicecomb.core.executor.ReactiveExecutor"></bean>
<bean id="cse.executor.groupThreadPool" class="io.servicecomb.core.executor.FixedThreadExecutor"></bean>
<alias name="cse.executor.groupThreadPool" alias="cse.executor.default" />
<bean id="cse.executor.reactive" class="io.servicecomb.core.executor.ReactiveExecutor"></bean>
</beans>
19 changes: 19 additions & 0 deletions demo/demo-edge/authentication/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.servicecomb.demo</groupId>
<artifactId>demo-edge</artifactId>
<version>0.4.1-SNAPSHOT</version>
</parent>
<artifactId>authentication</artifactId>
<dependencies>
<dependency>
<groupId>io.servicecomb</groupId>
<artifactId>provider-springmvc</artifactId>
</dependency>
<dependency>
<groupId>io.servicecomb</groupId>
<artifactId>transport-rest-vertx</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2017 Huawei Technologies Co., Ltd
*
* Licensed 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 io.servicecomb.demo.edge.authentication;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;

import io.servicecomb.provider.rest.common.RestSchema;

@RestSchema(schemaId = "auth")
@RequestMapping(path = "auth/v1")
public class AuthImpl {
@PostMapping(path = "/auth")
public boolean auth(@RequestHeader(name = "info") String info) {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright 2017 Huawei Technologies Co., Ltd
*
* Licensed 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 io.servicecomb.demo.edge.authentication;

import io.servicecomb.foundation.common.utils.BeanUtils;
import io.servicecomb.foundation.common.utils.Log4jUtils;

public class AuthMain {
public static void main(String[] args) throws Exception {
Log4jUtils.init();
BeanUtils.init();
}
}
12 changes: 12 additions & 0 deletions demo/demo-edge/authentication/src/main/resources/microservice.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
APPLICATION_ID: hiboard
service_description:
name: auth
version: 0.0.1
cse:
service:
registry:
address: http://127.0.0.1:30100
rest:
address: 127.0.0.1:7070
server:
thread-count: 10
8 changes: 8 additions & 0 deletions demo/demo-edge/edge-service/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,13 @@
<groupId>io.servicecomb</groupId>
<artifactId>edge-core</artifactId>
</dependency>
<dependency>
<groupId>io.servicecomb</groupId>
<artifactId>handler-loadbalance</artifactId>
</dependency>
<dependency>
<groupId>io.servicecomb</groupId>
<artifactId>provider-pojo</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,23 @@
import java.util.Map;

import io.servicecomb.edge.core.AbstractEdgeDispatcher;
import io.servicecomb.edge.core.CompatiblePathVersionMapper;
import io.servicecomb.edge.core.EdgeInvocation;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;
import io.vertx.ext.web.handler.CookieHandler;

public class EdgeDispatcher extends AbstractEdgeDispatcher {
private CompatiblePathVersionMapper versionMapper = new CompatiblePathVersionMapper();

@Override
public int getOrder() {
return 10000;
}

@Override
public void init(Router router) {
String regex = "/api/([^\\/]+)/(.*)";
String regex = "/api/([^\\\\/]+)/([^\\\\/]+)/(.*)";
router.routeWithRegex(regex).handler(CookieHandler.create());
router.routeWithRegex(regex).handler(createBodyHandler());
router.routeWithRegex(regex).failureHandler(this::onFailure).handler(this::onRequest);
Expand All @@ -41,10 +44,13 @@ public void init(Router router) {
protected void onRequest(RoutingContext context) {
Map<String, String> pathParams = context.pathParams();
String microserviceName = pathParams.get("param0");
String path = "/" + pathParams.get("param1");
String pathVersion = pathParams.get("param1");
String path = context.request().path().substring(4);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How can we tell the path by removing the first 4 characters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a demo
and the path rule is :/api/ms/version/......


EdgeInvocation edgeInvocation = new EdgeInvocation();
edgeInvocation.setVersionRule(versionMapper.getOrCreate(pathVersion).getVersionRule());

EdgeInvocation invoker = new EdgeInvocation();
invoker.init(microserviceName, context, path, httpServerFilters);
invoker.invoke();
edgeInvocation.init(microserviceName, context, path, httpServerFilters);
edgeInvocation.invoke();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* Copyright 2017 Huawei Technologies Co., Ltd
*
* Licensed 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 io.servicecomb.demo.edge.service.handler;

public interface Auth {
boolean auth(String info);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2017 Huawei Technologies Co., Ltd
*
* Licensed 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 io.servicecomb.demo.edge.service.handler;

import javax.ws.rs.core.Response.Status;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import io.servicecomb.core.Handler;
import io.servicecomb.core.Invocation;
import io.servicecomb.core.definition.MicroserviceMeta;
import io.servicecomb.provider.pojo.Invoker;
import io.servicecomb.swagger.invocation.AsyncResponse;
import io.servicecomb.swagger.invocation.InvocationType;
import io.servicecomb.swagger.invocation.exception.InvocationException;

public class AuthHandler implements Handler {
private static Logger LOGGER = LoggerFactory.getLogger(AuthHandler.class);

private Auth auth;

public AuthHandler() {
auth = Invoker.createProxy("auth", "auth", Auth.class);
}

@Override
public void init(MicroserviceMeta microserviceMeta, InvocationType invocationType) {
}

@Override
public void handle(Invocation invocation, AsyncResponse asyncResp) throws Exception {
if (!auth.auth("")) {
asyncResp.consumerFail(new InvocationException(Status.UNAUTHORIZED, (Object) "auth failed"));
return;
}

LOGGER.debug("auth success.");
invocation.next(asyncResp);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<!--
~ Copyright 2017 Huawei Technologies Co., Ltd
~
~ Licensed 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.
-->

<config>
<handler id="auth"
class="io.servicecomb.demo.edge.service.handler.AuthHandler" />
</config>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
log4j.rootLogger=DEBUG,stdout
12 changes: 11 additions & 1 deletion demo/demo-edge/edge-service/src/main/resources/microservice.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,14 @@ cse:
rest:
address: 127.0.0.1:18080
server:
thread-count: 1
thread-count: 8
client:
thread-count: 8
handler:
chain:
Consumer:
default: auth,loadbalance
service:
auth: loadbalance
executors:
default: cse.executor.groupThreadPool
48 changes: 48 additions & 0 deletions demo/demo-edge/hiboard-business-1-1-0/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2017 Huawei Technologies Co., Ltd
~
~ Licensed 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.servicecomb.demo</groupId>
<artifactId>demo-edge</artifactId>
<version>0.4.1-SNAPSHOT</version>
</parent>
<artifactId>hiboard-business-1-1-0</artifactId>
<properties>
<demo.main>io.servicecomb.demo.edge.business.BusinessMain_V1_1_0</demo.main>
</properties>

<dependencies>
<dependency>
<groupId>io.servicecomb</groupId>
<artifactId>provider-springmvc</artifactId>
</dependency>
<dependency>
<groupId>io.servicecomb</groupId>
<artifactId>transport-rest-vertx</artifactId>
</dependency>
<dependency>
<groupId>io.servicecomb</groupId>
<artifactId>transport-rest-servlet</artifactId>
</dependency>
<dependency>
<groupId>io.servicecomb.demo</groupId>
<artifactId>hiboard-model</artifactId>
<version>0.4.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Loading