forked from futurewei-cloud/alcor-control-agent
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
API Gateway and web data schema (customer-facing) (futurewei-cloud#143)
*Add a API gateway/service module *Add a common web directory to store common web object *Add API support for API creation, get, and delete (partial). *Docker and K8s deployment file for API gateway Co-authored-by: Kevin <[email protected]>
- Loading branch information
1 parent
2de89fa
commit 13efc56
Showing
32 changed files
with
1,578 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
metadata: | ||
labels: | ||
app: apimanager | ||
name: apimanager | ||
spec: | ||
selector: | ||
matchLabels: | ||
app: apimanager | ||
replicas: 1 | ||
template: | ||
metadata: | ||
labels: | ||
app: apimanager | ||
spec: | ||
containers: | ||
- image: zhonghaolyu/repo:apiKube4 | ||
name: apimanager-web | ||
imagePullPolicy: IfNotPresent | ||
ports: | ||
- containerPort: 8080 | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: apimanager-service | ||
labels: | ||
name: apimanager-service | ||
spec: | ||
type: NodePort | ||
ports: | ||
- port: 8002 | ||
targetPort: 8080 | ||
nodePort: 30004 | ||
selector: | ||
app: apimanager |
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
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,16 @@ | ||
# Dockerfile for API Gateway | ||
|
||
FROM openjdk:8 | ||
|
||
MAINTAINER Zhonghao Lyu <[email protected]> | ||
|
||
# API Gateway process | ||
EXPOSE 8080 | ||
# API Gateway admin process | ||
|
||
# Generate container image and run container | ||
COPY ./target/AlcorApiGateway-0.1.0-SNAPSHOT.jar /app/AlcorApiGateway-0.1.0.jar | ||
#COPY ./config/machine.json /app/config/machine.json | ||
|
||
CMD ["java", "-jar", "/app/AlcorApiGateway-0.1.0.jar"] | ||
|
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,101 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>com.futurewei.alcor.apigateway</groupId> | ||
<artifactId>AlcorApiGateway</artifactId> | ||
<version>0.1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
<name>AlcorApiGateway</name> | ||
<description>Alcor API Gateway</description> | ||
|
||
<properties> | ||
<java.version>1.8</java.version> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<asciidoctor-plugin.version>1.5.6</asciidoctor-plugin.version> | ||
<snippets>${project.basedir}/target/generated-snippets/</snippets> | ||
</properties> | ||
|
||
<parent> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-parent</artifactId> | ||
<version>2.1.6.RELEASE</version> | ||
<relativePath/> <!-- lookup parent from repository --> | ||
</parent> | ||
|
||
<dependencyManagement> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-dependencies</artifactId> | ||
<version>Greenwich.SR2</version> | ||
<type>pom</type> | ||
<scope>import</scope> | ||
</dependency> | ||
</dependencies> | ||
</dependencyManagement> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-gateway</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-netflix-hystrix</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.cloud</groupId> | ||
<artifactId>spring-cloud-starter-contract-stub-runner</artifactId> | ||
<exclusions> | ||
<exclusion> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
<groupId>org.springframework.boot</groupId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-configuration-processor</artifactId> | ||
<optional>true</optional> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.futurewei.alcor.common</groupId> | ||
<artifactId>AlcorCommonLib</artifactId> | ||
<version>0.1.0-SNAPSHOT</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.futurewei.alcor.web</groupId> | ||
<artifactId>AlcorWeb</artifactId> | ||
<version>0.1.0-SNAPSHOT</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
</project> |
31 changes: 31 additions & 0 deletions
31
.../api_gateway/src/main/java/com/futurewei/alcor/apigateway/AlcorApiGatewayApplication.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,31 @@ | ||
/* | ||
Copyright 2019 The Alcor Authors. | ||
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 com.futurewei.alcor.apigateway; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.context.annotation.ComponentScan; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@SpringBootApplication | ||
@RestController | ||
public class AlcorApiGatewayApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(AlcorApiGatewayApplication.class, args); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...api_gateway/src/main/java/com/futurewei/alcor/apigateway/admin/AdminWebConfiguration.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,38 @@ | ||
/* | ||
Copyright 2019 The Alcor Authors. | ||
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 com.futurewei.alcor.apigateway.admin; | ||
|
||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.cloud.gateway.route.RouteLocator; | ||
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
@EnableConfigurationProperties(AdminWebDestinations.class) | ||
public class AdminWebConfiguration { | ||
|
||
@Bean | ||
public RouteLocator debugProxyRouting(RouteLocatorBuilder builder, AdminWebDestinations adminWebDestinations) { | ||
return builder.routes() | ||
.route(r -> r | ||
.path("/get") | ||
.filters(f -> f.addRequestHeader("Hello", "Alcor")) | ||
.uri(adminWebDestinations.getDebugServiceUrl())) | ||
.build(); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
.../api_gateway/src/main/java/com/futurewei/alcor/apigateway/admin/AdminWebDestinations.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,40 @@ | ||
/* | ||
Copyright 2019 The Alcor Authors. | ||
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 com.futurewei.alcor.apigateway.admin; | ||
|
||
import lombok.Data; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
@Data | ||
@ConfigurationProperties(prefix = "admin.destinations") | ||
public class AdminWebDestinations { | ||
|
||
private String defaultServiceUrl = "http://httpbin.org:80"; | ||
|
||
@NotNull | ||
private String debugServiceUrl; | ||
|
||
public String getDebugServiceUrl() { | ||
return this.debugServiceUrl == null ? defaultServiceUrl : this.debugServiceUrl; | ||
} | ||
|
||
public void setDebugServiceUrl(String debugServiceUrl) { | ||
this.debugServiceUrl = debugServiceUrl; | ||
} | ||
} |
Oops, something went wrong.