Skip to content

Commit 97ba972

Browse files
committed
update default configuration for kubernetes-api + update time tools
1 parent f667ced commit 97ba972

File tree

6 files changed

+64
-34
lines changed

6 files changed

+64
-34
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ThisBuild / organization := "app.softnetwork"
3030

3131
name := "generic-persistence-api"
3232

33-
ThisBuild / version := "0.2.6.1"
33+
ThisBuild / version := "0.2.6.2"
3434

3535
ThisBuild / scalaVersion := "2.12.11"
3636

common/src/main/scala/app/softnetwork/time/package.scala

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,58 @@
11
package app.softnetwork
22

33
import java.time.temporal.ChronoField
4-
import java.time.{Instant, LocalDate, LocalDateTime, ZoneOffset, ZonedDateTime}
4+
import java.time.{Instant, LocalDate, LocalDateTime, ZoneId, ZonedDateTime}
55
import java.util.Date
66
import scala.language.implicitConversions
77

88
/** Created by smanciot on 10/05/2021.
99
*/
1010
package object time {
1111

12-
def now(): ZonedDateTime = ZonedDateTime.now()
12+
implicit def zoneId: ZoneId = ZoneId.systemDefault()
1313

14-
implicit class DateExtensions(date: Date) {
15-
lazy val zdt: ZonedDateTime = ZonedDateTime.ofInstant(date.toInstant, ZoneOffset.UTC)
16-
lazy val toLocalDateTime: LocalDateTime = zdt.toLocalDateTime
17-
lazy val toLocalDate: LocalDate = zdt.toLocalDate
18-
lazy val toEpochSecond: Long = zdt.toEpochSecond
14+
implicit def epochSecondToInstant(epochSecond: Long): Instant = {
15+
Instant.ofEpochSecond(epochSecond)
16+
}
17+
18+
implicit def instantToDate(instant: Instant): Date = {
19+
Date.from(instant)
1920
}
2021

2122
implicit def epochSecondToDate(epochSecond: Long): Date = {
22-
Date.from(Instant.ofEpochSecond(epochSecond).atZone(ZoneOffset.UTC).toInstant)
23+
Date.from(epochSecond)
2324
}
2425

25-
implicit def epochSecondToLocalDate(epochSecond: Long): LocalDate = {
26-
Instant.ofEpochSecond(epochSecond).atZone(ZoneOffset.UTC).toLocalDate
26+
implicit def localDateToDate(ld: LocalDate): Date = {
27+
Date.from(ld.atStartOfDay(zoneId).toInstant)
28+
}
29+
30+
implicit def localDateTimeToDate(ldt: LocalDateTime): Date = {
31+
Date.from(ldt.atZone(zoneId).toInstant)
32+
}
33+
34+
implicit def zonedDateTimeToDate(zdt: ZonedDateTime): Date = {
35+
Date.from(zdt.toInstant)
2736
}
2837

29-
implicit def toLocalDate(d: Date): LocalDate = {
30-
d.toLocalDate
38+
implicit def epochSecondToLocalDate(epochSecond: Long): LocalDate = {
39+
Instant.ofEpochSecond(epochSecond).atZone(zoneId).toLocalDate
3140
}
3241

33-
implicit class LocalDateExtensions(ld: LocalDate) {
34-
lazy val toDate: Date = Date.from(ld.atStartOfDay(ZoneOffset.UTC).toInstant)
42+
implicit def dateToEpochSecond(d: Date): Long = {
43+
d.toInstant.getEpochSecond
3544
}
3645

37-
implicit def toDate(ld: LocalDate): Date = {
38-
ld.toDate
46+
implicit def dateToLocalDate(d: Date): LocalDate = {
47+
ZonedDateTime.ofInstant(d.toInstant, zoneId).toLocalDate
3948
}
4049

41-
implicit class LocalDateTimeExtensions(ldt: LocalDateTime) {
42-
lazy val toDate: Date = Date.from(ldt.atZone(ZoneOffset.UTC).toInstant)
50+
implicit def dateToLocalDateTime(d: Date): LocalDateTime = {
51+
ZonedDateTime.ofInstant(d.toInstant, zoneId).toLocalDateTime
4352
}
4453

45-
implicit def toDate(ldt: LocalDateTime): Date = {
46-
ldt.toDate
54+
implicit def dateToZonedDateTime(d: Date): ZonedDateTime = {
55+
ZonedDateTime.ofInstant(d.toInstant, zoneId)
4756
}
4857

4958
def weekNumber(ld: LocalDate = LocalDate.now()): Int = {

core/src/main/resources/softnetwork-kubernetes-discovery.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ akka {
66
shutdown-after-unsuccessful-join-seed-nodes = ${?JOIN_SEED_NODES_TIMEOUT}
77
}
88

9+
discovery {
10+
method = kubernetes-api
11+
}
12+
913
management {
1014
cluster{
1115
bootstrap {

core/src/main/resources/softnetwork-persistence.conf

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,19 @@ akka {
7171
# By default, just bind to loopback and do not allow access from the network
7272
remote {
7373
artery {
74-
canonical.hostname = "127.0.0.1" # external (logical) hostname
75-
canonical.hostname = ${?CLUSTER_IP}
76-
canonical.port = 25520 # external (logical) port
77-
canonical.port = ${?CLUSTER_PORT}
74+
canonical {
75+
# Hostname clients should connect to. Can be set to an ip, hostname
76+
# or one of the following special values:
77+
# "<getHostAddress>" InetAddress.getLocalHost.getHostAddress
78+
# "<getHostName>" InetAddress.getLocalHost.getHostName
79+
hostname = "<getHostAddress>" # external (logical) hostname
80+
hostname = ${?CLUSTER_IP}
81+
# The default remote server port clients should connect to.
82+
# Default is 25520, use 0 if you want a random available port
83+
# This port needs to be unique for each actor system on the same machine.
84+
port = 25520 # external (logical) port
85+
port = ${?CLUSTER_PORT}
86+
}
7887
}
7988
}
8089

@@ -173,13 +182,15 @@ akka {
173182
discovery{
174183
method = aggregate
175184
aggregate {
185+
# List of service discovery methods to try in order. E.g config then fall back to DNS
186+
# ["config", "akka-dns"]
176187
discovery-methods = ["akka-dns", "config"]
177188
}
178189
config.services = {
179190
local = {
180191
endpoints = [
181192
{
182-
host = "127.0.0.1"
193+
host = "<getHostAddress>"
183194
host = ${?CLUSTER_MANAGEMENT_HOST}
184195
port = 8558
185196
port = ${?CLUSTER_MANAGEMENT_PORT}
@@ -247,7 +258,14 @@ akka {
247258
required-contact-point-nr = 1
248259
required-contact-point-nr = ${?REQUIRED_CONTACT_POINT_NR}
249260
service-name = local
250-
service-name = ${?CONTACT_POINT_SERVICE_NAME}
261+
service-name = ${?CONTACT_POINT_SERVICE_NAME} #AKKA_CLUSTER_BOOTSTRAP_SERVICE_NAME
262+
# Added as suffix to the service-name to build the effective-service name used in the contact-point service lookups
263+
# If undefined, nothing will be appended to the service-name.
264+
#
265+
# Examples, set this to:
266+
# "default.svc.cluster.local" or "my-namespace.svc.cluster.local" for kubernetes clusters.
267+
service-namespace = "<service-namespace>"
268+
service-namespace = ${?CONTACT_POINT_SERVICE_NAMESPACE}
251269
}
252270
}
253271
}

core/src/main/scala/app/softnetwork/persistence/package.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package app.softnetwork
22

3-
import java.util.{Calendar, Date, UUID}
4-
3+
import java.util.{Date, UUID}
54
import app.softnetwork.build.info.persistence.core.BuildInfo
65
import app.softnetwork.security._
7-
86
import app.softnetwork.persistence.model.Timestamped
97

8+
import java.time.Instant
109
import scala.language.implicitConversions
1110

1211
/** Created by smanciot on 13/04/2020.
@@ -24,7 +23,7 @@ package object persistence {
2423
case _ => UUID.randomUUID().toString
2524
}
2625

27-
def now(): Date = Calendar.getInstance().getTime
26+
def now(): Date = Date.from(Instant.now())
2827

2928
def getType[T <: Timestamped](implicit m: Manifest[T]): String = {
3029
m.runtimeClass.getSimpleName.toLowerCase

project/src/main/scala/app/softnetwork/sbt/build/Versions.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ object Versions {
88

99
val akkaPersistenceJdbc = "3.5.2"
1010

11-
val akkaManagement = "1.1.4" // 1.0.10 -> 1.1.4
11+
val akkaManagement = "1.1.4" // 1.1.4 -> 1.2
1212

13-
val postgresql = "42.2.18" //"9.4.1210"
13+
val postgresql = "42.2.18"
1414

1515
val scalatest = "3.1.1"
1616

@@ -20,7 +20,7 @@ object Versions {
2020

2121
val jackson = "2.11.4"
2222

23-
val json4s = "3.6.12" // 3.6.7 -> 3.6.12
23+
val json4s = "3.6.12"
2424

2525
val scalaLogging = "3.9.2"
2626

0 commit comments

Comments
 (0)