Skip to content

Added configuration to make possible to run on local PCF dev. #17

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

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion config-server/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 12 additions & 0 deletions config-server/src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -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}
2 changes: 2 additions & 0 deletions discovery-server/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ server.port=8761

eureka.client.register-with-eureka=false
eureka.client.fetch-registry=false

eureka.instance.preferIpAddress=true
77 changes: 77 additions & 0 deletions dsl-executor-service/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>com.lohika.jclub.dsl.service</groupId>
<artifactId>dsl-executor-service</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>DSL Executor service</name>
<description>DSL Executor Service</description>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Dalston.RELEASE</spring-cloud.version>
</properties>

<dependencies>
<dependency>
<groupId>com.lohika.jclub.storage.client</groupId>
<artifactId>storage-service-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lohika.jclub.rating.client</groupId>
<artifactId>rating-service-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lohika.jclub.dsl</groupId>
<artifactId>dsl</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>2.4.11</version>
</dependency>
</dependencies>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

</project>
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
14 changes: 14 additions & 0 deletions dsl-executor-service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions dsl-executor-service/src/main/resources/banner.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
____ _____ __ _
/ __ \/ ___// / ________ ______ __(_)_______
/ / / /\__ \/ / / ___/ _ \/ ___/ | / / / ___/ _ \
/ /_/ /___/ / /___ (__ ) __/ / | |/ / / /__/ __/
/_____//____/_____/ /____/\___/_/ |___/_/\___/\___/
v.${application.version}
20 changes: 20 additions & 0 deletions dsl-scripts/demo.mydsl
Original file line number Diff line number Diff line change
@@ -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
}
}
}
25 changes: 25 additions & 0 deletions dsl-scripts/simple.mydsl
Original file line number Diff line number Diff line change
@@ -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'
}
66 changes: 66 additions & 0 deletions dsl/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>com.lohika.jclub.dsl</groupId>
<artifactId>dsl</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>DSL</name>
<description>DSL</description>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<groovy.version>2.4.3</groovy.version>
<groovy-eclipse-batch.version>2.4.3-01</groovy-eclipse-batch.version>
<groovy-eclipse-compiler.version>2.9.2-01</groovy-eclipse-compiler.version>

</properties>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<compilerId>groovy-eclipse-compiler</compilerId>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-compiler</artifactId>
<version>${groovy-eclipse-compiler.version}</version>
</dependency>

<!-- the compiler version should match the groovy dependency version -->
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-eclipse-batch</artifactId>
<version>${groovy-eclipse-batch.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy</artifactId>
<version>${groovy.version}</version>
</dependency>
<dependency>
<groupId>com.lohika.jclub.storage.client</groupId>
<artifactId>storage-service-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.lohika.jclub.rating.client</groupId>
<artifactId>rating-service-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
20 changes: 20 additions & 0 deletions dsl/src/main/groovy/com/lohika/jclub/dsl/MyDsl.groovy
Original file line number Diff line number Diff line change
@@ -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
}
}
Empty file.
25 changes: 25 additions & 0 deletions dsl/src/main/resources/idea.gdsl
Original file line number Diff line number Diff line change
@@ -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']
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading