diff --git a/README.md b/README.md index ecd8898..f7d97f6 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,23 @@ mvn clean install ``` +## PCF +Pivotal cf can be used on both: server trial and local installation: PCF dev, more information: +https://docs.pivotal.io/pcf-dev/ + +manifest.yml was created to push with configured environment options and set spring-profile 'cloud' to enable eureka +detection via 'VCAP' environment based configuration. More information about environment variables: +http://docs.pivotal.io/pivotalcf/1-11/devguide/deploy-apps/environment-variable.html + +To set eureka service after push to cloud-foundry run: +cf cups eureka -p '{"url": "http://discovery.{YOUR_DEFINED_CF_HOST}/eureka/"}', i.e.: +YOUR_DEFINED_CF_HOST = local.pcfdev.io. + +In application \ bootstrap properties is used "nonSecurePort: 8080", as eureka is deployed on '8080', +as all other instances, so it redefines default 80 port to make possible interconnection between registered via +eureka services. + + ## TODO Items - [ ] Check Feign Fallback ? - [x] Storage Service (persistance + Eureka client) diff --git a/config-server/src/main/resources/application.properties b/config-server/src/main/resources/application.properties index 4cf2381..500db0c 100644 --- a/config-server/src/main/resources/application.properties +++ b/config-server/src/main/resources/application.properties @@ -1,4 +1,4 @@ -spring.cloud.config.server.git.uri=${JAVA_CLUB_SRC_HOME}/spring-cloud +spring.cloud.config.server.git.uri=https://github.com/lvivJavaClub/spring-cloud spring.cloud.config.server.git.search-paths=config spring.cloud.config.discovery.enabled=true diff --git a/config-server/src/main/resources/application.yml b/config-server/src/main/resources/application.yml new file mode 100644 index 0000000..2ccd9f4 --- /dev/null +++ b/config-server/src/main/resources/application.yml @@ -0,0 +1,12 @@ +--- +spring: + profiles: + active: cloud +eureka: + instance: + nonSecurePort: 8080 + hostname: ${vcap.application.uris[0]} + preferIpAddress: true + client: + service-url: + defaultZone: ${vcap.services.eureka.credentials.url} diff --git a/discovery-server/src/main/resources/application.properties b/discovery-server/src/main/resources/application.properties index bac323d..2b93e78 100644 --- a/discovery-server/src/main/resources/application.properties +++ b/discovery-server/src/main/resources/application.properties @@ -3,3 +3,5 @@ server.port=8761 eureka.client.register-with-eureka=false eureka.client.fetch-registry=false + +eureka.instance.preferIpAddress=true diff --git a/dsl-executor-service/pom.xml b/dsl-executor-service/pom.xml new file mode 100644 index 0000000..bff61af --- /dev/null +++ b/dsl-executor-service/pom.xml @@ -0,0 +1,77 @@ + + + 4.0.0 + + com.lohika.jclub.dsl.service + dsl-executor-service + 0.0.1-SNAPSHOT + jar + + DSL Executor service + DSL Executor Service + + + org.springframework.boot + spring-boot-starter-parent + 1.5.3.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + Dalston.RELEASE + + + + + com.lohika.jclub.storage.client + storage-service-client + 0.0.1-SNAPSHOT + + + com.lohika.jclub.rating.client + rating-service-client + 0.0.1-SNAPSHOT + + + com.lohika.jclub.dsl + dsl + 0.0.1-SNAPSHOT + + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.cloud + spring-cloud-starter-eureka + + + org.springframework.boot + spring-boot-starter-web + + + + org.codehaus.groovy + groovy + 2.4.11 + + + + + + + org.springframework.cloud + spring-cloud-dependencies + ${spring-cloud.version} + pom + import + + + + + diff --git a/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslController.java b/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslController.java new file mode 100644 index 0000000..fd9f1a8 --- /dev/null +++ b/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslController.java @@ -0,0 +1,54 @@ +package com.lohika.jclub.dsl.service; + +import groovy.lang.GroovyShell; +import groovy.util.DelegatingScript; + +import com.lohika.jclub.dsl.MyDsl; +import com.lohika.jclub.rating.client.RatingServiceClient; +import com.lohika.jclub.storage.client.StorageServiceClient; + +import org.codehaus.groovy.control.CompilerConfiguration; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; + +@RestController +@RequestMapping(path = "/dsl") +public class DslController { + + @Value("${dsl.basepath}") + private String basepath; + + @Autowired + private StorageServiceClient storageServiceClient; + + @Autowired + private RatingServiceClient ratingServiceClient; + + @GetMapping(path = "/{scriptName}") + public Object runScript(@PathVariable(name = "scriptName") String scriptName) throws IOException { + File file = new File(basepath + scriptName + ".groovy"); + String script = new String(Files.readAllBytes(Paths.get(file.getPath()))); + + MyDsl dsl = new MyDsl(ratingServiceClient, storageServiceClient); + + CompilerConfiguration configuration = new CompilerConfiguration(); + configuration.setScriptBaseClass(DelegatingScript.class.getName()); + + GroovyShell groovy = new GroovyShell(configuration); + + DelegatingScript delegatingScript = (DelegatingScript) groovy.parse(script); + delegatingScript.setDelegate(dsl); + delegatingScript.run(); + + return dsl; + } +} diff --git a/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslServiceApplication.java b/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslServiceApplication.java new file mode 100644 index 0000000..f47c5aa --- /dev/null +++ b/dsl-executor-service/src/main/java/com/lohika/jclub/dsl/service/DslServiceApplication.java @@ -0,0 +1,22 @@ +package com.lohika.jclub.dsl.service; + +import com.lohika.jclub.rating.client.EnableRatingServiceClient; +import com.lohika.jclub.rating.client.RatingServiceClient; +import com.lohika.jclub.storage.client.EnableStorageServiceClient; +import com.lohika.jclub.storage.client.StorageServiceClient; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.netflix.feign.EnableFeignClients; + +@EnableDiscoveryClient +@EnableStorageServiceClient +@EnableRatingServiceClient +@EnableFeignClients(clients = {StorageServiceClient.class, RatingServiceClient.class}) +@SpringBootApplication +public class DslServiceApplication { + public static void main(String[] args) { + SpringApplication.run(DslServiceApplication.class, args); + } +} diff --git a/dsl-executor-service/src/main/resources/application.properties b/dsl-executor-service/src/main/resources/application.properties new file mode 100644 index 0000000..31769f9 --- /dev/null +++ b/dsl-executor-service/src/main/resources/application.properties @@ -0,0 +1,14 @@ +server.port=8088 +spring.application.name=dsl-executor-service + +dsl.basepath=dsl-scripts/ + +eureka.instance.preferIpAddress=true + +feign.hystrix.enabled=true + +endpoints.info.id=info +endpoints.info.sensitive=false +endpoints.info.enabled=true + +info.app.name=DSL executor service diff --git a/dsl-executor-service/src/main/resources/banner.txt b/dsl-executor-service/src/main/resources/banner.txt new file mode 100644 index 0000000..8f39951 --- /dev/null +++ b/dsl-executor-service/src/main/resources/banner.txt @@ -0,0 +1,6 @@ + ____ _____ __ _ + / __ \/ ___// / ________ ______ __(_)_______ + / / / /\__ \/ / / ___/ _ \/ ___/ | / / / ___/ _ \ + / /_/ /___/ / /___ (__ ) __/ / | |/ / / /__/ __/ +/_____//____/_____/ /____/\___/_/ |___/_/\___/\___/ +v.${application.version} diff --git a/dsl-scripts/demo.mydsl b/dsl-scripts/demo.mydsl new file mode 100644 index 0000000..ac42911 --- /dev/null +++ b/dsl-scripts/demo.mydsl @@ -0,0 +1,20 @@ +String myPhone = '123' +String myName = 'bot' +String myEmail = 'bot@company.name' + +(1..100).each { + String location = "location-${it}" + double myPrice = 2 + double mySqft = 1 + (it as int) + def rating = rating location, myPrice, mySqft + + if (rating > 400) { + apartment(location) { + price myPrice + sqft mySqft + phone myPhone + realtorName myName + mail myEmail + } + } +} diff --git a/dsl-scripts/simple.mydsl b/dsl-scripts/simple.mydsl new file mode 100644 index 0000000..26b0867 --- /dev/null +++ b/dsl-scripts/simple.mydsl @@ -0,0 +1,25 @@ +apartment { + location "location" + price 1 + sqft 1 + phone 'phone' + realtorName 'realtorName' + mail 'mail' +} + +apartment("location", { + price 1 + sqft 1 + phone 'phone' + realtorName 'realtorName' + mail 'mail' +}) + + +apartment("location") { + price 1 + sqft 1 + phone 'phone' + realtorName 'realtorName' + mail 'mail' +} diff --git a/dsl/pom.xml b/dsl/pom.xml new file mode 100644 index 0000000..a8c8164 --- /dev/null +++ b/dsl/pom.xml @@ -0,0 +1,66 @@ + + + 4.0.0 + + com.lohika.jclub.dsl + dsl + 0.0.1-SNAPSHOT + jar + + DSL + DSL + + + UTF-8 + UTF-8 + 2.4.3 + 2.4.3-01 + 2.9.2-01 + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + groovy-eclipse-compiler + + + + org.codehaus.groovy + groovy-eclipse-compiler + ${groovy-eclipse-compiler.version} + + + + + org.codehaus.groovy + groovy-eclipse-batch + ${groovy-eclipse-batch.version} + + + + + + + + + org.codehaus.groovy + groovy + ${groovy.version} + + + com.lohika.jclub.storage.client + storage-service-client + 0.0.1-SNAPSHOT + + + com.lohika.jclub.rating.client + rating-service-client + 0.0.1-SNAPSHOT + + + diff --git a/dsl/src/main/groovy/com/lohika/jclub/dsl/MyDsl.groovy b/dsl/src/main/groovy/com/lohika/jclub/dsl/MyDsl.groovy new file mode 100644 index 0000000..1dd3c63 --- /dev/null +++ b/dsl/src/main/groovy/com/lohika/jclub/dsl/MyDsl.groovy @@ -0,0 +1,20 @@ +package com.lohika.jclub.dsl + +import com.lohika.jclub.rating.client.Apartment +import com.lohika.jclub.rating.client.RatingServiceClient +import com.lohika.jclub.storage.client.StorageServiceClient +import groovy.transform.ToString +import groovy.util.logging.Log + +@Log +@ToString(excludes = ["ratingServiceClient", "storageServiceClient"]) +class MyDsl { + + private RatingServiceClient ratingServiceClient + private StorageServiceClient storageServiceClient + + MyDsl(RatingServiceClient ratingServiceClient, StorageServiceClient storageServiceClient) { + this.storageServiceClient = storageServiceClient + this.ratingServiceClient = ratingServiceClient + } +} diff --git a/dsl/src/main/java/package-info.java b/dsl/src/main/java/package-info.java new file mode 100644 index 0000000..e69de29 diff --git a/dsl/src/main/resources/idea.gdsl b/dsl/src/main/resources/idea.gdsl new file mode 100644 index 0000000..621cb21 --- /dev/null +++ b/dsl/src/main/resources/idea.gdsl @@ -0,0 +1,25 @@ +def dslContext = context( + filetypes: ['mydsl'], + scope: scriptScope()) + +contributor(dslContext) { + method name: 'rating', type: 'java.lang.Double', params: [location: 'java.lang.String', price: 'java.lang.Double', sqft: 'java.lang.Double'] + + method name: 'apartment', type: 'void', params: [body: 'groovy.lang.Closure'] + method name: 'apartment', type: 'void', params: [location: 'java.lang.String', body: 'groovy.lang.Closure'] +} + +def contributorBody = context( + filetypes: ['mydsl'], + scope: closureScope(isArg: true)) + +contributor([contributorBody]) { + if (enclosingCall("apartment")) { + method name: 'location', type: 'void', params: [value: 'java.lang.String'] + method name: 'price', type: 'void', params: [value: 'java.lang.Double'] + method name: 'sqft', type: 'void', params: [value: 'java.lang.Double'] + method name: 'realtorName', type: 'void', params: [value: 'java.lang.String'] + method name: 'mail', type: 'void', params: [value: 'java.lang.String'] + } +} + diff --git a/hackster-service-client/src/test/java/com/lohika/jclub/hackster/client/HacksterServiceClientTest.java b/hackster-service-client/src/test/java/com/lohika/jclub/hackster/client/HacksterServiceClientTest.java index 5377ccb..e5398b3 100644 --- a/hackster-service-client/src/test/java/com/lohika/jclub/hackster/client/HacksterServiceClientTest.java +++ b/hackster-service-client/src/test/java/com/lohika/jclub/hackster/client/HacksterServiceClientTest.java @@ -26,6 +26,8 @@ public class HacksterServiceClientTest { public static GenericContainer HacksterService = new GenericContainer("hackster-service:latest") .withExposedPorts(8082) .withEnv("maxAllowedApartmentsPerRealtor", Integer.toString(MAX_ALLOWED_APARTMENTS_PER_REALTOR)) + .withEnv("spring.cloud.config.discovery.enabled", "false") + .withEnv("spring.cloud.config.fail-fast", "false") .waitingFor(new LogMessageWaitStrategy().withRegEx(".*Started HacksterServiceApplication in.*\\s")); @Autowired diff --git a/hackster-service/src/main/resources/bootstrap.yml b/hackster-service/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..2ccd9f4 --- /dev/null +++ b/hackster-service/src/main/resources/bootstrap.yml @@ -0,0 +1,12 @@ +--- +spring: + profiles: + active: cloud +eureka: + instance: + nonSecurePort: 8080 + hostname: ${vcap.application.uris[0]} + preferIpAddress: true + client: + service-url: + defaultZone: ${vcap.services.eureka.credentials.url} diff --git a/hackster-service/src/test/resources/bootstrap.properties b/hackster-service/src/test/resources/bootstrap.properties new file mode 100644 index 0000000..756b6f9 --- /dev/null +++ b/hackster-service/src/test/resources/bootstrap.properties @@ -0,0 +1,2 @@ +spring.cloud.config.discovery.enabled=false +spring.cloud.config.fail-fast=false diff --git a/manifest.yml b/manifest.yml index 7638483..4404b13 100644 --- a/manifest.yml +++ b/manifest.yml @@ -1,7 +1,7 @@ --- applications: - name: discovery-server - memory: 512M + memory: 400M disk_quota: 512M instances: 1 path: discovery-server/target/discovery-server-0.0.1-SNAPSHOT.jar @@ -13,4 +13,36 @@ applications: path: storage-service/target/storage-service-0.0.1-SNAPSHOT.jar host: storage env: - eureka.client.serviceUrl.defaultZone: https://discovery.lv-cf-openstack.lohika.com/eureka/ \ No newline at end of file + spring.profiles.active: cloud + services: + - eureka +- name: config-server + memory: 400M + disk_quota: 512M + instances: 1 + path: config-server/target/config-server-0.0.1-SNAPSHOT.jar + host: config + env: + spring.profiles.active: cloud + services: + - eureka +- name: hackster-service + memory: 512M + disk_quota: 512M + instances: 1 + path: hackster-service/target/hackster-service-0.0.1-SNAPSHOT.jar + host: hackster + env: + spring.profiles.active: cloud + services: + - eureka +- name: rating-service + memory: 400M + disk_quota: 400M + instances: 1 + path: rating-service/target/rating-service-0.0.1-SNAPSHOT.jar + host: rating + env: + spring.profiles.active: cloud + services: + - eureka \ No newline at end of file diff --git a/pom.xml b/pom.xml index 07fad45..2b67310 100644 --- a/pom.xml +++ b/pom.xml @@ -13,6 +13,8 @@ config-server + dsl + dsl-executor-service discovery-server rating-service rating-service-client @@ -24,4 +26,4 @@ api-gateway-service client-service - \ No newline at end of file + diff --git a/rating-service-client/src/main/java/com/lohika/jclub/rating/client/EnableRatingServiceClient.java b/rating-service-client/src/main/java/com/lohika/jclub/rating/client/EnableRatingServiceClient.java index 37852ca..cda7780 100644 --- a/rating-service-client/src/main/java/com/lohika/jclub/rating/client/EnableRatingServiceClient.java +++ b/rating-service-client/src/main/java/com/lohika/jclub/rating/client/EnableRatingServiceClient.java @@ -1,7 +1,5 @@ package com.lohika.jclub.rating.client; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.cloud.netflix.feign.EnableFeignClients; import org.springframework.context.annotation.Import; import org.springframework.hateoas.config.EnableHypermediaSupport; @@ -16,8 +14,6 @@ @Documented @EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL) -@EnableFeignClients(clients = {RatingServiceClient.class}) @Import({FeignMappingDefaultConfiguration.class, RatingServiceClientConfiguration.class}) -@EnableDiscoveryClient public @interface EnableRatingServiceClient { } diff --git a/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientTest.java b/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientTest.java index 596d606..6ad55ae 100644 --- a/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientTest.java +++ b/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientTest.java @@ -28,6 +28,8 @@ public class RatingServiceClientTest { public static GenericContainer RatingService = new GenericContainer("rating-service:latest") .withExposedPorts(8081) .withEnv("rate", "100") + .withEnv("spring.cloud.config.discovery.enabled", "false") + .withEnv("spring.cloud.config.fail-fast", "false") .waitingFor(new LogMessageWaitStrategy().withRegEx(".*Started RatingServiceApplication in.*\\s")); @Autowired diff --git a/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientTestApplication.java b/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientTestApplication.java index 7de2bcc..63e5ae9 100644 --- a/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientTestApplication.java +++ b/rating-service-client/src/test/java/com/lohika/jclub/rating/client/RatingServiceClientTestApplication.java @@ -2,8 +2,12 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.netflix.feign.EnableFeignClients; +@EnableDiscoveryClient @EnableRatingServiceClient +@EnableFeignClients(clients = {RatingServiceClient.class}) @SpringBootApplication public class RatingServiceClientTestApplication { diff --git a/rating-service/src/main/resources/application.properties b/rating-service/src/main/resources/application.properties index fc1c858..c9df4a2 100644 --- a/rating-service/src/main/resources/application.properties +++ b/rating-service/src/main/resources/application.properties @@ -1,2 +1,3 @@ server.port=8081 spring.application.name=rating-service +eureka.instance.preferIpAddress=true diff --git a/rating-service/src/main/resources/bootstrap.yml b/rating-service/src/main/resources/bootstrap.yml new file mode 100644 index 0000000..2ccd9f4 --- /dev/null +++ b/rating-service/src/main/resources/bootstrap.yml @@ -0,0 +1,12 @@ +--- +spring: + profiles: + active: cloud +eureka: + instance: + nonSecurePort: 8080 + hostname: ${vcap.application.uris[0]} + preferIpAddress: true + client: + service-url: + defaultZone: ${vcap.services.eureka.credentials.url} diff --git a/rating-service/src/test/resources/bootstrap.properties b/rating-service/src/test/resources/bootstrap.properties new file mode 100644 index 0000000..756b6f9 --- /dev/null +++ b/rating-service/src/test/resources/bootstrap.properties @@ -0,0 +1,2 @@ +spring.cloud.config.discovery.enabled=false +spring.cloud.config.fail-fast=false diff --git a/storage-service-client/src/main/java/com/lohika/jclub/storage/client/EnableStorageServiceClient.java b/storage-service-client/src/main/java/com/lohika/jclub/storage/client/EnableStorageServiceClient.java index 7acaa50..2a6c899 100644 --- a/storage-service-client/src/main/java/com/lohika/jclub/storage/client/EnableStorageServiceClient.java +++ b/storage-service-client/src/main/java/com/lohika/jclub/storage/client/EnableStorageServiceClient.java @@ -1,7 +1,5 @@ package com.lohika.jclub.storage.client; -import org.springframework.cloud.client.discovery.EnableDiscoveryClient; -import org.springframework.cloud.netflix.feign.EnableFeignClients; import org.springframework.context.annotation.Import; import org.springframework.hateoas.config.EnableHypermediaSupport; @@ -16,8 +14,6 @@ @Documented @EnableHypermediaSupport(type = EnableHypermediaSupport.HypermediaType.HAL) -@EnableFeignClients(clients = {StorageServiceClient.class}) @Import({FeignMappingDefaultConfiguration.class, StorageServiceClientConfiguration.class}) -@EnableDiscoveryClient public @interface EnableStorageServiceClient { } diff --git a/storage-service-client/src/test/java/com/lohika/jclub/storage/client/StorageServiceClientTestApplication.java b/storage-service-client/src/test/java/com/lohika/jclub/storage/client/StorageServiceClientTestApplication.java index e763567..ba94331 100644 --- a/storage-service-client/src/test/java/com/lohika/jclub/storage/client/StorageServiceClientTestApplication.java +++ b/storage-service-client/src/test/java/com/lohika/jclub/storage/client/StorageServiceClientTestApplication.java @@ -2,8 +2,12 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.cloud.client.discovery.EnableDiscoveryClient; +import org.springframework.cloud.netflix.feign.EnableFeignClients; +@EnableDiscoveryClient @EnableStorageServiceClient +@EnableFeignClients(clients = {StorageServiceClient.class}) @SpringBootApplication public class StorageServiceClientTestApplication { diff --git a/storage-service/src/main/resources/application.yml b/storage-service/src/main/resources/application.yml new file mode 100644 index 0000000..2ccd9f4 --- /dev/null +++ b/storage-service/src/main/resources/application.yml @@ -0,0 +1,12 @@ +--- +spring: + profiles: + active: cloud +eureka: + instance: + nonSecurePort: 8080 + hostname: ${vcap.application.uris[0]} + preferIpAddress: true + client: + service-url: + defaultZone: ${vcap.services.eureka.credentials.url}