-
Notifications
You must be signed in to change notification settings - Fork 823
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#3727]adjust router match same with governance and fix edge version …
…rule test cases (#4009)
- Loading branch information
Showing
26 changed files
with
334 additions
and
498 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# About edge service API compatibility | ||
|
||
* Edge service use the latest version of the microservice meta. e.g. For business 1.0.0, 1.1.0, 2.0.0 have the following APIs: | ||
|
||
* 1.0.0: /business/v1/add | ||
* 1.1.0: /business/v1/add, /business/v1/dec | ||
* 2.0.0: /business/v2/add, /business/v2/dec | ||
|
||
If users invoke /business/v1/add, edge service will give NOT FOUND, because 2.0.0 microservice meta do not have this API. Even using router to route all /business/v1/* requests to 1.1.0, path locating happens before load balance. | ||
|
||
* It's very important to keep your API compatibility cross versions if these versions need work together. e.g. | ||
|
||
* 1.0.0: /business/v1/add | ||
* 1.1.0: /business/v1/add, /business/v1/dec | ||
* 2.0.0: /business/v1/add, /business/v1/dec, /business/v2/add, /business/v2/dec | ||
|
||
Together with router, /business/v1/add will go correctly to 1.0.0 or 1.1.0, and /business/v2/add will go correctly to 2.0.0. Without router, /business/v2/add may route to 1.0.0 or 1.1.0 and NOT FOUND is reported. | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
125 changes: 125 additions & 0 deletions
125
...o-edge/business-2.0.0/src/main/java/org/apache/servicecomb/demo/edge/business/ImplV2.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* 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.demo.edge.business; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.RandomAccessFile; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.apache.servicecomb.demo.edge.model.AppClientDataRsp; | ||
import org.apache.servicecomb.demo.edge.model.ChannelRequestBase; | ||
import org.apache.servicecomb.demo.edge.model.DependTypeA; | ||
import org.apache.servicecomb.demo.edge.model.RecursiveSelfType; | ||
import org.apache.servicecomb.demo.edge.model.ResultWithInstance; | ||
import org.apache.servicecomb.demo.edge.model.User; | ||
import org.apache.servicecomb.provider.rest.common.RestSchema; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
|
||
import io.swagger.v3.oas.annotations.media.Content; | ||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
|
||
@RestSchema(schemaId = "news-v2") | ||
@RequestMapping(path = "/business/v2") | ||
public class ImplV2 { | ||
private Environment environment; | ||
|
||
@Autowired | ||
public void setEnvironment(Environment environment) { | ||
this.environment = environment; | ||
} | ||
|
||
File tempDir = new File("target/downloadTemp"); | ||
|
||
public ImplV2() throws IOException { | ||
FileUtils.forceMkdir(tempDir); | ||
} | ||
|
||
@RequestMapping(path = "/channel/news/subscribe", method = RequestMethod.POST) | ||
public AppClientDataRsp subscribeNewsColumn(@RequestBody ChannelRequestBase request) { | ||
AppClientDataRsp response = new AppClientDataRsp(); | ||
String rsp = "result from 2.0.0"; | ||
response.setRsp(rsp); | ||
return response; | ||
} | ||
|
||
@RequestMapping(path = "/add", method = RequestMethod.GET) | ||
public ResultWithInstance add(int x, int y) { | ||
return ResultWithInstance.create(x + y, environment); | ||
} | ||
|
||
@RequestMapping(path = "/dec", method = RequestMethod.GET) | ||
public ResultWithInstance dec(int x, int y) { | ||
return ResultWithInstance.create(x - y, environment); | ||
} | ||
|
||
@GetMapping(path = "/download") | ||
@ApiResponses({ | ||
@ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = File.class)), description = ""), | ||
}) | ||
public ResponseEntity<InputStream> download() throws IOException { | ||
return ResponseEntity | ||
.ok() | ||
.header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN_VALUE) | ||
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment;filename=download.txt") | ||
.body(new ByteArrayInputStream("download".getBytes(StandardCharsets.UTF_8))); | ||
} | ||
|
||
protected File createBigFile() throws IOException { | ||
File file = new File(tempDir, "bigFile.txt"); | ||
file.delete(); | ||
RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw"); | ||
randomAccessFile.setLength(10 * 1024 * 1024); | ||
randomAccessFile.close(); | ||
return file; | ||
} | ||
|
||
@GetMapping(path = "/bigFile") | ||
public File bigFile() throws IOException { | ||
return createBigFile(); | ||
} | ||
|
||
@PostMapping(path = "recursiveSelf") | ||
public RecursiveSelfType recursiveSelf(@RequestBody RecursiveSelfType value) { | ||
return value; | ||
} | ||
|
||
@PostMapping(path = "dependType") | ||
public DependTypeA dependType(@RequestBody DependTypeA value) { | ||
return value; | ||
} | ||
|
||
@PostMapping(path = "encrypt") | ||
public User encrypt(@RequestBody User value) { | ||
return value; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.