This is an automated email from the ASF dual-hosted git repository. kezhenxu94 pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/skywalking-showcase.git
commit 542327a396754bdc7b8ecb85656a42e66e6a2db5 Author: kezhenxu94 <[email protected]> AuthorDate: Wed Oct 27 14:50:04 2021 +0800 Finish song-service and set up project structure --- .gitignore | 4 ++ .../resources/application.properties => Makefile | 1 + .../application.properties => Makefile.in | 3 ++ build.gradle | 23 ----------- buildSrc/build.gradle | 26 ------------ ...ng.showcase.java-application-conventions.gradle | 26 ------------ ...walking.showcase.java-common-conventions.gradle | 44 -------------------- ...alking.showcase.java-library-conventions.gradle | 27 ------------ gradle/wrapper/gradle-wrapper.properties | 19 +-------- services/recommendation-service/build.gradle | 6 +++ .gitignore => services/song-service/Dockerfile | 18 +++++--- .gitignore => services/song-service/Makefile | 22 +++++++--- .../{java-service => song-service}/build.gradle | 1 + .../song-service/gradle.properties | 2 + .../song-service/gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 59536 bytes .../gradle}/wrapper/gradle-wrapper.properties | 3 +- gradlew => services/song-service/gradlew | 0 gradlew.bat => services/song-service/gradlew.bat | 0 .../song-service/settings.gradle | 5 +-- .../services/song/SongServiceApplication.java} | 6 +-- .../services/song/controller/SongController.java | 39 +++++++++++++++++ .../showcase/services/song/entity/Song.java | 46 +++++++++++++++++++++ .../showcase/services/song/repo/SongsRepo.java | 27 ++++++++++++ .../src/main/resources/application.yaml} | 6 +++ services/song-service/src/main/resources/data.sql | 33 +++++++++++++++ .../song}/JavaServicesApplicationTests.java | 2 +- 26 files changed, 205 insertions(+), 184 deletions(-) diff --git a/.gitignore b/.gitignore index f922fe7..d425778 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,7 @@ build .idea *.iml + +.venv + +.DS_Store diff --git a/services/java-service/src/main/resources/application.properties b/Makefile similarity index 99% copy from services/java-service/src/main/resources/application.properties copy to Makefile index d0a78df..a4c0b62 100644 --- a/services/java-service/src/main/resources/application.properties +++ b/Makefile @@ -15,3 +15,4 @@ # specific language governing permissions and limitations # under the License. # + diff --git a/services/java-service/src/main/resources/application.properties b/Makefile.in similarity index 90% copy from services/java-service/src/main/resources/application.properties copy to Makefile.in index d0a78df..1a32095 100644 --- a/services/java-service/src/main/resources/application.properties +++ b/Makefile.in @@ -15,3 +15,6 @@ # specific language governing permissions and limitations # under the License. # + +HUB ?= ghcr.io/apache/skywalking-showcase +TAG ?= $(shell git rev-parse --short HEAD) diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 9e986a6..0000000 --- a/build.gradle +++ /dev/null @@ -1,23 +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. - * - */ -allprojects { - group 'org.apache.skywalking.showcase' - version '1.0.0-SNAPSHOT' -} diff --git a/buildSrc/build.gradle b/buildSrc/build.gradle deleted file mode 100644 index 3d8de41..0000000 --- a/buildSrc/build.gradle +++ /dev/null @@ -1,26 +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. - * - */ -plugins { - id 'groovy-gradle-plugin' -} - -repositories { - gradlePluginPortal() -} diff --git a/buildSrc/src/main/groovy/org.apache.skywalking.showcase.java-application-conventions.gradle b/buildSrc/src/main/groovy/org.apache.skywalking.showcase.java-application-conventions.gradle deleted file mode 100644 index f20a0d6..0000000 --- a/buildSrc/src/main/groovy/org.apache.skywalking.showcase.java-application-conventions.gradle +++ /dev/null @@ -1,26 +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. - * - */ -plugins { - // Apply the common convention plugin for shared build configuration between library and application projects. - id 'org.apache.skywalking.showcase.java-common-conventions' - - // Apply the application plugin to add support for building a CLI application in Java. - id 'application' -} diff --git a/buildSrc/src/main/groovy/org.apache.skywalking.showcase.java-common-conventions.gradle b/buildSrc/src/main/groovy/org.apache.skywalking.showcase.java-common-conventions.gradle deleted file mode 100644 index c96cd7b..0000000 --- a/buildSrc/src/main/groovy/org.apache.skywalking.showcase.java-common-conventions.gradle +++ /dev/null @@ -1,44 +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. - * - */ - -plugins { - // Apply the java Plugin to add support for Java. - id 'java' -} - -repositories { - // Use Maven Central for resolving dependencies. - mavenCentral() -} - -dependencies { - constraints { - // Define dependency versions as constraints - implementation 'org.apache.commons:commons-text:1.9' - } - - // Use JUnit Jupiter for testing. - testImplementation 'org.junit.jupiter:junit-jupiter:5.7.2' -} - -tasks.named('test') { - // Use JUnit Platform for unit tests. - useJUnitPlatform() -} diff --git a/buildSrc/src/main/groovy/org.apache.skywalking.showcase.java-library-conventions.gradle b/buildSrc/src/main/groovy/org.apache.skywalking.showcase.java-library-conventions.gradle deleted file mode 100644 index 059b2fa..0000000 --- a/buildSrc/src/main/groovy/org.apache.skywalking.showcase.java-library-conventions.gradle +++ /dev/null @@ -1,27 +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. - * - */ - -plugins { - // Apply the common convention plugin for shared build configuration between library and application projects. - id 'org.apache.skywalking.showcase.java-common-conventions' - - // Apply the java-library plugin for API and implementation separation. - id 'java-library' -} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 4cfc668..69a9715 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,22 +1,5 @@ -# 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. -# distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.1-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/services/recommendation-service/build.gradle b/services/recommendation-service/build.gradle new file mode 100644 index 0000000..6684127 --- /dev/null +++ b/services/recommendation-service/build.gradle @@ -0,0 +1,6 @@ +afterEvaluate { + exec { + commandLine 'python3', '-m', 'venv', '.venv' + ignoreExitValue true + } +} diff --git a/.gitignore b/services/song-service/Dockerfile similarity index 72% copy from .gitignore copy to services/song-service/Dockerfile index f922fe7..48e26d5 100644 --- a/.gitignore +++ b/services/song-service/Dockerfile @@ -15,11 +15,17 @@ # specific language governing permissions and limitations # under the License. # -# Ignore Gradle project-specific cache directory -.gradle -# Ignore Gradle build output directory -build +FROM ghcr.io/apache/skywalking-java/jdk-11:latest as build -.idea -*.iml +COPY . /workspace + +WORKDIR /workspace + +RUN ./gradlew build + +FROM ghcr.io/apache/skywalking-java/jdk-11:latest + +COPY --from=build /workspace/build/libs/skywalking-showcase-0.0.1-SNAPSHOT.jar /app.jar + +CMD ["java", "-jar", "/app.jar"] diff --git a/.gitignore b/services/song-service/Makefile similarity index 73% copy from .gitignore copy to services/song-service/Makefile index f922fe7..47f6405 100644 --- a/.gitignore +++ b/services/song-service/Makefile @@ -15,11 +15,21 @@ # specific language governing permissions and limitations # under the License. # -# Ignore Gradle project-specific cache directory -.gradle -# Ignore Gradle build output directory -build +include ../../Makefile.in -.idea -*.iml +.PHONY: build clean +build: + ./gradlew build +clean: + ./gradlew clean + +.PHONY: docker docker.build docker.push + +docker: docker.push + +docker.build: clean + docker build . -t $(HUB)/song-service:$(TAG) + +docker.push: docker.build + docker push $(HUB)/song-service:$(TAG) diff --git a/services/java-service/build.gradle b/services/song-service/build.gradle similarity index 97% rename from services/java-service/build.gradle rename to services/song-service/build.gradle index 703a247..c88e4f4 100644 --- a/services/java-service/build.gradle +++ b/services/song-service/build.gradle @@ -40,6 +40,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.springframework.kafka:spring-kafka' + implementation 'com.h2database:h2' compileOnly 'org.projectlombok:lombok' annotationProcessor 'org.projectlombok:lombok' testImplementation 'org.springframework.boot:spring-boot-starter-test' diff --git a/gradle.properties b/services/song-service/gradle.properties similarity index 96% rename from gradle.properties rename to services/song-service/gradle.properties index d0a78df..e957a1d 100644 --- a/gradle.properties +++ b/services/song-service/gradle.properties @@ -15,3 +15,5 @@ # specific language governing permissions and limitations # under the License. # + +org.gradle.daemon=false diff --git a/services/song-service/gradle/wrapper/gradle-wrapper.jar b/services/song-service/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..7454180 Binary files /dev/null and b/services/song-service/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/services/song-service/gradle/wrapper/gradle-wrapper.properties similarity index 95% copy from gradle/wrapper/gradle-wrapper.properties copy to services/song-service/gradle/wrapper/gradle-wrapper.properties index 4cfc668..3899240 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/services/song-service/gradle/wrapper/gradle-wrapper.properties @@ -17,6 +17,7 @@ # distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +# PyGradle doesn't support 7 +distributionUrl=https\://services.gradle.org/distributions/gradle-6.8-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/services/song-service/gradlew similarity index 100% rename from gradlew rename to services/song-service/gradlew diff --git a/gradlew.bat b/services/song-service/gradlew.bat old mode 100644 new mode 100755 similarity index 100% rename from gradlew.bat rename to services/song-service/gradlew.bat diff --git a/settings.gradle b/services/song-service/settings.gradle similarity index 92% rename from settings.gradle rename to services/song-service/settings.gradle index 4ec5775..d877293 100644 --- a/settings.gradle +++ b/services/song-service/settings.gradle @@ -19,7 +19,6 @@ */ rootProject.name = 'skywalking-showcase' -include( - 'services:java-service' -) +include 'services:song-service' +include 'services:recommendation-service' diff --git a/services/java-service/src/main/java/org/apache/skywalking/showcase/services/j/JavaServicesApplication.java b/services/song-service/src/main/java/org/apache/skywalking/showcase/services/song/SongServiceApplication.java similarity index 86% rename from services/java-service/src/main/java/org/apache/skywalking/showcase/services/j/JavaServicesApplication.java rename to services/song-service/src/main/java/org/apache/skywalking/showcase/services/song/SongServiceApplication.java index 0becfa1..034a90f 100644 --- a/services/java-service/src/main/java/org/apache/skywalking/showcase/services/j/JavaServicesApplication.java +++ b/services/song-service/src/main/java/org/apache/skywalking/showcase/services/song/SongServiceApplication.java @@ -17,16 +17,16 @@ * under the License. * */ -package org.apache.skywalking.showcase.services.j; +package org.apache.skywalking.showcase.services.song; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication -public class JavaServicesApplication { +public class SongServiceApplication { public static void main(String[] args) { - SpringApplication.run(JavaServicesApplication.class, args); + SpringApplication.run(SongServiceApplication.class, args); } } diff --git a/services/song-service/src/main/java/org/apache/skywalking/showcase/services/song/controller/SongController.java b/services/song-service/src/main/java/org/apache/skywalking/showcase/services/song/controller/SongController.java new file mode 100644 index 0000000..6dcafb2 --- /dev/null +++ b/services/song-service/src/main/java/org/apache/skywalking/showcase/services/song/controller/SongController.java @@ -0,0 +1,39 @@ +/* + * 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.skywalking.showcase.services.song.controller; + +import java.util.List; +import lombok.RequiredArgsConstructor; +import org.apache.skywalking.showcase.services.song.entity.Song; +import org.apache.skywalking.showcase.services.song.repo.SongsRepo; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/songs") +public class SongController { + private final SongsRepo songsRepo; + + @GetMapping + public List<Song> songs() { + return songsRepo.findAll(); + } +} diff --git a/services/song-service/src/main/java/org/apache/skywalking/showcase/services/song/entity/Song.java b/services/song-service/src/main/java/org/apache/skywalking/showcase/services/song/entity/Song.java new file mode 100644 index 0000000..7d5a57a --- /dev/null +++ b/services/song-service/src/main/java/org/apache/skywalking/showcase/services/song/entity/Song.java @@ -0,0 +1,46 @@ +/* + * 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.skywalking.showcase.services.song.entity; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.GeneratedValue; +import javax.persistence.Id; +import lombok.Data; +import lombok.ToString; + +import static javax.persistence.GenerationType.IDENTITY; + +@Data +@Entity +@ToString +public class Song { + @Id + @GeneratedValue(strategy = IDENTITY) + private Integer id; + + @Column(nullable = false) + private String name; + + @Column + private String artist; + + @Column + private String genre; +} diff --git a/services/song-service/src/main/java/org/apache/skywalking/showcase/services/song/repo/SongsRepo.java b/services/song-service/src/main/java/org/apache/skywalking/showcase/services/song/repo/SongsRepo.java new file mode 100644 index 0000000..7e12707 --- /dev/null +++ b/services/song-service/src/main/java/org/apache/skywalking/showcase/services/song/repo/SongsRepo.java @@ -0,0 +1,27 @@ +/* + * 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.skywalking.showcase.services.song.repo; + +import org.apache.skywalking.showcase.services.song.entity.Song; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface SongsRepo extends JpaRepository<Song, Integer> { +} diff --git a/services/java-service/src/main/resources/application.properties b/services/song-service/src/main/resources/application.yaml similarity index 90% rename from services/java-service/src/main/resources/application.properties rename to services/song-service/src/main/resources/application.yaml index d0a78df..92fbf21 100644 --- a/services/java-service/src/main/resources/application.properties +++ b/services/song-service/src/main/resources/application.yaml @@ -15,3 +15,9 @@ # specific language governing permissions and limitations # under the License. # +server: + port: 8081 + +spring: + jpa: + defer-datasource-initialization: true diff --git a/services/song-service/src/main/resources/data.sql b/services/song-service/src/main/resources/data.sql new file mode 100644 index 0000000..0bda17a --- /dev/null +++ b/services/song-service/src/main/resources/data.sql @@ -0,0 +1,33 @@ +/* + * 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. + * + */ +-- +-- 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. +-- + +insert into song + (id, name, artist, genre) +values (1, '倩女幽魂', '张国荣', 'HK-POP'), + (2, '沉默是金', '张国荣', 'HK-POP') +; diff --git a/services/java-service/src/test/java/org/apache/skywalking/showcase/services/j/JavaServicesApplicationTests.java b/services/song-service/src/test/java/org/apache/skywalking/showcase/services/song/JavaServicesApplicationTests.java similarity index 94% rename from services/java-service/src/test/java/org/apache/skywalking/showcase/services/j/JavaServicesApplicationTests.java rename to services/song-service/src/test/java/org/apache/skywalking/showcase/services/song/JavaServicesApplicationTests.java index 00846b2..8fda4b0 100644 --- a/services/java-service/src/test/java/org/apache/skywalking/showcase/services/j/JavaServicesApplicationTests.java +++ b/services/song-service/src/test/java/org/apache/skywalking/showcase/services/song/JavaServicesApplicationTests.java @@ -17,7 +17,7 @@ * under the License. * */ -package org.apache.skywalking.showcase.services.j; +package org.apache.skywalking.showcase.services.song; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest;
