Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update BMI sample to fill latest docs #130

Merged
merged 1 commit into from
Nov 20, 2023
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
60 changes: 23 additions & 37 deletions bmi/calculator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,28 @@
-->

<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">
<parent>
<artifactId>bmi</artifactId>
<groupId>org.apache.servicecomb.samples</groupId>
<version>3.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>bmi-calculator</artifactId>
<name>Java Chassis::Samples::BMI::Calculator</name>

<dependencies>

<dependency>
<groupId>org.apache.servicecomb</groupId>
<artifactId>java-chassis-spring-boot-starter-servlet</artifactId>
</dependency>

<dependency>
<groupId>org.apache.servicecomb</groupId>
<artifactId>handler-flowcontrol-qps</artifactId>
</dependency>

<dependency>
<groupId>org.apache.servicecomb</groupId>
<artifactId>handler-tracing-zipkin</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>bmi</artifactId>
<groupId>org.apache.servicecomb.samples</groupId>
<version>3.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>bmi-calculator</artifactId>
<name>Java Chassis::Samples::BMI::Calculator</name>

<properties>
<start-class>org.apache.servicecomb.samples.CalculatorApplication</start-class>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@

package org.apache.servicecomb.samples;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;

@SpringBootApplication
public class CalculatorApplication {

public static void main(String[] args) {
SpringApplication.run(CalculatorApplication.class, args);
try {
new SpringApplicationBuilder().web(WebApplicationType.NONE).sources(CalculatorApplication.class).run(args);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,27 @@

package org.apache.servicecomb.samples;

import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.math.RoundingMode;

import org.apache.servicecomb.swagger.invocation.exception.CommonExceptionData;
import org.apache.servicecomb.swagger.invocation.exception.InvocationException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class CalculatorServiceImpl implements CalculatorService {
@Value("${bmi.mock.error:false}")
private boolean mockError = false;

/**
* {@inheritDoc}
*/
@Override
public double calculate(double height, double weight) {
if (mockError) {
throw new InvocationException(503, "mock error.", new CommonExceptionData("mock error."));
}
if (height <= 0 || weight <= 0) {
throw new IllegalArgumentException("Arguments must be above 0");
}
Expand Down
17 changes: 13 additions & 4 deletions bmi/calculator/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,6 @@
## limitations under the License.
## ---------------------------------------------------------------------------

server:
port: 7777

servicecomb:
registry:
sc:
Expand All @@ -29,4 +26,16 @@ servicecomb:
version: 0.0.1

rest:
address: 0.0.0.0:7777
address: 0.0.0.0:7777

matchGroup:
bmi-operation: |
matches:
- apiPath:
exact: "/bmi"
# rateLimiting:
# bmi-operation: |
# timeoutDuration: 0
# limitRefreshPeriod: 1000
# rate: 1

71 changes: 71 additions & 0 deletions bmi/calculator/src/main/resources/log4j2.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<Configuration>
<Properties>
<property name="FILE_PATH" value="./logs/calculator"/>
</Properties>

<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d [%p][%t][%c:%L] %m%n"/>
</Console>

<RollingFile name="AccessLog" fileName="${FILE_PATH}/access.log"
filePattern="${FILE_PATH}/access-%d{yyyy-MM-dd}_%i.log.gz">
<PatternLayout pattern="%d [%t] %m%n"/>
<Policies>
<SizeBasedTriggeringPolicy size="20MB"/>
</Policies>
<DefaultRolloverStrategy max="100"/>
</RollingFile>

<RollingFile name="MetricsLog" fileName="${FILE_PATH}/metrics.log"
filePattern="${FILE_PATH}/metrics-%d{yyyy-MM-dd}_%i.log.gz">
<PatternLayout pattern="%d [%t] %m%n"/>
<Policies>
<SizeBasedTriggeringPolicy size="20MB"/>
</Policies>
<DefaultRolloverStrategy max="100"/>
</RollingFile>

<RollingFile name="SlowLog" fileName="${FILE_PATH}/slow.log"
filePattern="${FILE_PATH}/slow-%d{yyyy-MM-dd}_%i.log.gz">
<PatternLayout pattern="%d [%t] %m%n"/>
<Policies>
<SizeBasedTriggeringPolicy size="20MB"/>
</Policies>
<DefaultRolloverStrategy max="100"/>
</RollingFile>
</Appenders>

<Loggers>
<Logger name="scb-access" level="INFO" additivity="false">
<AppenderRef ref="AccessLog"/>
</Logger>
<Logger name="scb-metrics" level="INFO" additivity="false">
<AppenderRef ref="MetricsLog"/>
</Logger>
<Logger name="scb-slow" level="INFO" additivity="false">
<AppenderRef ref="SlowLog"/>
</Logger>

<Root level="INFO">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
81 changes: 27 additions & 54 deletions bmi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
-->

<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">
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>

<groupId>org.apache.servicecomb.samples</groupId>
Expand All @@ -28,7 +28,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<servicecomb.version>3.0.0-SNAPSHOT</servicecomb.version>
<argLine>-Dfile.encoding=UTF-8</argLine>
<spring-boot-maven-plugin.version>3.1.3</spring-boot-maven-plugin.version>
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
<java.version>17</java.version>
</properties>

Expand All @@ -49,6 +50,27 @@
<groupId>org.apache.servicecomb</groupId>
<artifactId>registry-service-center</artifactId>
</dependency>
<dependency>
<groupId>org.apache.servicecomb</groupId>
<artifactId>java-chassis-spring-boot-starter-standalone</artifactId>
</dependency>
<dependency>
<groupId>org.apache.servicecomb</groupId>
<artifactId>solution-basic</artifactId>
</dependency>
<!-- using log4j2 -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
</dependency>
</dependencies>

<modules>
Expand All @@ -59,22 +81,22 @@
<description>Quick Start Demo for Using ServiceComb Java Chassis</description>

<build>

<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<version>${maven-compiler-plugin.version}</version>
<configuration>
<compilerArgument>-parameters</compilerArgument>
<source>17</source>
<target>17</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>2.1.2.RELEASE</version>
<version>${spring-boot-maven-plugin.version}</version>
<executions>
<execution>
<goals>
Expand All @@ -88,54 +110,5 @@
</plugin>
</plugins>
</pluginManagement>

<plugins>
<!-- 配置项目使用jdk1.8编译 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<compilerArgument>-parameters</compilerArgument>
<encoding>UTF-8</encoding>
<source>17</source>
<target>17</target>
<compilerArgs>
<arg>-Werror</arg>
<arg>-Xlint:all</arg>
<!--not care for jdk8/jdk7 compatible problem-->
<arg>-Xlint:-classfile</arg>
<!--not care for annotation not processed-->
<arg>-Xlint:-processing</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.rat</groupId>
<artifactId>apache-rat-plugin</artifactId>
<version>0.13</version>
<configuration>
<excludes>
<exclude>.travis.yml</exclude>
<exclude>**/*.md</exclude>
<exclude>**/target/*</exclude>
<!-- Skip the ssl configuration files -->
<exculde>**/resources/ssl/**</exculde>
<!-- Skip the protobuf files -->
<exclude>**/*.proto</exclude>
<!-- Skip the idl files -->
<exclude>**/*.idl</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Loading