Skip to content

Commit

Permalink
- Refactoring Class names.
Browse files Browse the repository at this point in the history
- Rename secure to ssl property.
- Remove unused property.
  • Loading branch information
Oleksandr authored and Oleksandr committed Feb 24, 2017
1 parent 4cfedee commit 2f711f6
Show file tree
Hide file tree
Showing 20 changed files with 82 additions and 81 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ You can use your personal keystore. Just create it by the following command and

keytool -genkey -alias replserver -keyalg RSA -keystore mock_keystore.jks -dname "CN=Mark Smith, OU=JavaSoft, O=Sun, L=Cupertino, S=California, C=US" -storepass mockpassword -keypass mockpassword

secure:
ssl:
enabled: true
keyStoreLocation: mock_keystore.jks
keyStorePassword: mockpassword
1 change: 0 additions & 1 deletion _config.yml

This file was deleted.

2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=1.1.2
version=1.2
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ua.com.lavi.komock.app
import org.slf4j.LoggerFactory
import org.yaml.snakeyaml.Yaml
import ua.com.lavi.komock.KomockRunner
import ua.com.lavi.komock.config.ApplicationConfiguration
import ua.com.lavi.komock.engine.model.config.KomockConfiguration
import java.io.IOException
import java.nio.file.Files
import java.nio.file.Paths
Expand All @@ -28,7 +28,7 @@ object KomockApplication {
log.info("Run Komock version: ${version()}. config path: $path")
try {
Files.newInputStream(Paths.get(path)).use { it ->
KomockRunner().run(Yaml().loadAs<ApplicationConfiguration>(it, ApplicationConfiguration::class.java))
KomockRunner().run(Yaml().loadAs<KomockConfiguration>(it, KomockConfiguration::class.java))
}
} catch (e: IOException) {
log.error("Unable to read configuration file: ", e)
Expand Down
14 changes: 7 additions & 7 deletions komock-core/mock_example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ springConfig:
- dev
- qa
server:
id: spring-config-server
name: spring-config-server
port: 8888
host: 127.0.0.1
secure:
ssl:
enabled: true
keyStoreLocation: mock_keystore.jks
keyStorePassword: mockpassword

servers:
-
enabled: true
id: firstServer
name: firstServer
port: 8081
routes:
-
Expand Down Expand Up @@ -110,12 +110,12 @@ servers:
responseBody: '{"patchedParameter": "patchedVariable with error"}'
code: 500
-
id: secondServer
name: secondServer
port: 8082
minThreads: 10
maxThreads: 20
idleTimeout: 60000
secure:
ssl:
enabled: true
keyStoreLocation: mock_keystore.jks
keyStorePassword: mockpassword
Expand All @@ -127,14 +127,14 @@ servers:
responseBody: Content from the second server
code: 200
-
id: thirdServer
name: thirdServer
port: 8083
minThreads: 10
maxThreads: 20
idleTimeout: 60000
virtualHosts:
- "vhost.mocka"
secure:
ssl:
enabled: true
keyStoreLocation: mock_keystore.jks
keyStorePassword: mockpassword
Expand Down
10 changes: 5 additions & 5 deletions komock-core/src/main/kotlin/ua/com/lavi/komock/KomockRunner.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ua.com.lavi.komock

import ua.com.lavi.komock.config.ApplicationConfiguration
import ua.com.lavi.komock.engine.model.config.KomockConfiguration
import ua.com.lavi.komock.registrar.ConsulRegistrar
import ua.com.lavi.komock.registrar.ServerRegistrar
import ua.com.lavi.komock.registrar.SpringConfigRegistrar
Expand All @@ -11,24 +11,24 @@ import ua.com.lavi.komock.registrar.SpringConfigRegistrar

class KomockRunner {

fun run(applicationConfiguration: ApplicationConfiguration) {
fun run(komockConfiguration: KomockConfiguration) {

//Server instances
val serverRegistrar = ServerRegistrar()
applicationConfiguration.servers.
komockConfiguration.servers.
filter { it.enabled }.
forEach { serverRegistrar.register(it) }

//Spring config-server
val springConfigRegistrar = SpringConfigRegistrar()
val springConfigProperties = applicationConfiguration.springConfig
val springConfigProperties = komockConfiguration.springConfig
if (springConfigProperties.enabled) {
springConfigRegistrar.register(springConfigProperties)
}

//Consul registration
val consulRegistrar = ConsulRegistrar()
val consulServerProperties = applicationConfiguration.consul
val consulServerProperties = komockConfiguration.consul
if (consulServerProperties.enabled) {
consulRegistrar.register(consulServerProperties)
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import java.util.concurrent.TimeUnit
* Created by Oleksandr Loushkin
*/

internal class JettyServer(val serverId: String,
internal class JettyServer(val serverName: String,
val virtualHosts: ArrayList<String>,
val httpHandler: Handler,
val host: String,
Expand All @@ -35,7 +35,7 @@ internal class JettyServer(val serverId: String,
}

fun start() {

log.debug("$serverName - initializing on $host:$port")
val contextHandler = buildContextHandler()
val serverConnector: ServerConnector = buildServerConnector(jettyServer, host, port, sslKeyStore)

Expand All @@ -46,13 +46,13 @@ internal class JettyServer(val serverId: String,
jettyServer.handler = handlerList

jettyServer.start()
log.debug("$serverId - listening on $host:$port")
log.debug("$serverName - listening on $host:$port")
}

fun stop() {
log.debug("Stopping $serverId")
log.debug("Stopping $serverName")
jettyServer.stop()
log.debug("$serverId is stopped")
log.debug("$serverName is stopped")
}

fun addVirtualHosts(virtualHosts: ArrayList<String>) {
Expand Down
13 changes: 8 additions & 5 deletions komock-core/src/main/kotlin/ua/com/lavi/komock/engine/Router.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package ua.com.lavi.komock.engine

import org.slf4j.LoggerFactory
import ua.com.lavi.komock.config.property.http.RouteProperties
import ua.com.lavi.komock.engine.model.config.property.http.RouteProperties
import ua.com.lavi.komock.engine.handler.AfterRouteHandler
import ua.com.lavi.komock.engine.handler.BeforeRouteHandler
import ua.com.lavi.komock.engine.handler.RouteHandler
Expand All @@ -13,6 +13,7 @@ import java.util.*

/**
* Created by Oleksandr Loushkin
* This class represents all logic according to manage server and link route with the server
*/

class Router(val serverId: String,
Expand All @@ -29,17 +30,18 @@ class Router(val serverId: String,
private var server: JettyServer
private var routingTable = RoutingTable()

//Helper object.
companion object {

private val routers = ArrayList<Router>()

@JvmStatic
fun startAllRouters() {
fun startAllServers() {
routers.forEach(Router::start)
}

@JvmStatic
fun stopAllRouters() {
fun stopAllServers() {
routers.forEach(Router::stop)
}
}
Expand All @@ -57,16 +59,17 @@ class Router(val serverId: String,
log.info("Started server: $serverId on port: $port, virtualHosts: ${virtualHosts.joinToString(",")}. " +
"maxThreads: $maxThreads, minThreads: $minThreads, idle timeout: $idleTimeout ms")
} else {
log.info("Server is already started!")
log.info("Unable to start because server is already started!")
}
}

fun stop() {
if (isStarted) {
server.stop()
isStarted = false
log.info("Server is stopped")
} else {
log.info("Server is not started!")
log.info("Unable to stop because server was not started!")
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ua.com.lavi.komock.engine.model

import ua.com.lavi.komock.config.property.http.CookieProperties
import ua.com.lavi.komock.engine.model.config.property.http.CookieProperties
import javax.servlet.http.Cookie
import javax.servlet.http.HttpServletResponse

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ua.com.lavi.komock.engine.model.config

import ua.com.lavi.komock.engine.model.config.property.consul.ConsulAgentProperties
import ua.com.lavi.komock.engine.model.config.property.http.ServerProperties
import ua.com.lavi.komock.engine.model.config.property.spring.SpringConfigProperties
import java.util.*

/**
* Created by Oleksandr Loushkin
*/

class KomockConfiguration {

var servers: ArrayList<ServerProperties> = ArrayList()
var consul: ConsulAgentProperties = ConsulAgentProperties()
var springConfig: SpringConfigProperties = SpringConfigProperties()

}
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
package ua.com.lavi.komock.config.property.consul
package ua.com.lavi.komock.engine.model.config.property.consul

import java.util.*

/**
* Created by Oleksandr Loushkin
*/

class ConsulServerProperties {
class ConsulAgentProperties {
var enabled: Boolean = false
var consulHost = "localhost"
var consulPort = 8500
var services = ArrayList<ConsulServiceProperties>()
var services = ArrayList<ConsulServiceAgentProperties>()
}

class ConsulServiceProperties {
class ConsulServiceAgentProperties {
var enabled: Boolean = true
var serviceId: String = "defaultConsulService"
var serviceName: String = "defaultConsulServiceName"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ua.com.lavi.komock.config.property.http
package ua.com.lavi.komock.engine.model.config.property.http


import java.util.*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ua.com.lavi.komock.config.property.http
package ua.com.lavi.komock.engine.model.config.property.http

import java.util.*

Expand All @@ -9,19 +9,19 @@ import java.util.*

class ServerProperties {
var enabled: Boolean = true
var id = "defaultInstance" // default name
var name = "defaultInstanceName" // default name
var virtualHosts = ArrayList<String>()
var host = "0.0.0.0" // listen on all interfaces
var port = 8080 // default port;
var routes = ArrayList<RouteProperties>()
var secure: SecureServerProperties = SecureServerProperties()
var ssl: SSLServerProperties = SSLServerProperties()
var minThreads: Int = 10
var maxThreads: Int = 100
var idleTimeout: Int = 60000
}

class SecureServerProperties {
class SSLServerProperties {
var enabled: Boolean = false
var keyStoreLocation: String = "keystore.jks"
var keyStorePassword: String = "passworwd"
var keyStorePassword: String = "password"
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package ua.com.lavi.komock.config.property.spring
package ua.com.lavi.komock.engine.model.config.property.spring

import ua.com.lavi.komock.config.property.http.ServerProperties
import ua.com.lavi.komock.engine.model.config.property.http.ServerProperties
import java.util.*

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ua.com.lavi.komock.config.property.spring
package ua.com.lavi.komock.engine.model.config.property.spring

import java.util.*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package ua.com.lavi.komock.registrar
import com.ecwid.consul.v1.ConsulClient
import com.ecwid.consul.v1.agent.model.NewService
import org.slf4j.LoggerFactory
import ua.com.lavi.komock.config.property.consul.ConsulServerProperties
import ua.com.lavi.komock.engine.model.config.property.consul.ConsulAgentProperties

/**
* Created by Oleksandr Loushkin
Expand All @@ -13,10 +13,10 @@ class ConsulRegistrar {

private val log = LoggerFactory.getLogger(this.javaClass)

fun register(consulServerProperties: ConsulServerProperties) {
val clientRegistrar = ConsulClient(consulServerProperties.consulHost, consulServerProperties.consulPort)
log.debug("Found: ${consulServerProperties.services.size} consul services")
for (consulService in consulServerProperties.services) {
fun register(consulAgentProperties: ConsulAgentProperties) {
val clientRegistrar = ConsulClient(consulAgentProperties.consulHost, consulAgentProperties.consulPort)
log.debug("Found: ${consulAgentProperties.services.size} consul services")
for (consulService in consulAgentProperties.services) {
val newService = NewService()
newService.id = consulService.serviceId
newService.name = consulService.serviceName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package ua.com.lavi.komock.registrar

import org.slf4j.LoggerFactory
import ua.com.lavi.komock.engine.Router
import ua.com.lavi.komock.config.property.http.ServerProperties
import ua.com.lavi.komock.engine.model.config.property.http.ServerProperties
import ua.com.lavi.komock.engine.model.SslKeyStore
import java.net.BindException

Expand All @@ -17,10 +17,10 @@ class ServerRegistrar {
fun register(serverProp: ServerProperties) {

var sslKeyStore: SslKeyStore? = null
if (serverProp.secure.enabled) {
sslKeyStore = SslKeyStore(serverProp.secure.keyStoreLocation, serverProp.secure.keyStorePassword)
if (serverProp.ssl.enabled) {
sslKeyStore = SslKeyStore(serverProp.ssl.keyStoreLocation, serverProp.ssl.keyStorePassword)
}
val router = Router(serverProp.id,
val router = Router(serverProp.name,
serverProp.host, serverProp.port,
serverProp.minThreads, serverProp.maxThreads,
serverProp.idleTimeout, sslKeyStore, serverProp.virtualHosts)
Expand Down
Loading

0 comments on commit 2f711f6

Please sign in to comment.