Skip to content

Commit

Permalink
Merge pull request #161 from ostelco/feature/fix-locale-pseudonyms
Browse files Browse the repository at this point in the history
Use one specific locale for Calendar
  • Loading branch information
prasanthu authored Jun 11, 2018
2 parents b820f2f + e76058f commit 8ed22b6
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 47 deletions.
91 changes: 53 additions & 38 deletions pseudonym-server/README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,67 @@
# Pseudonym Server

#PROJECT_ID=pantel-2decb
export PROJECT_ID="$(gcloud config get-value project -q)"
export PSEUDONYM_VERSION="$(gradle properties -q | grep "version:" | awk '{print $2}' | tr -d '[:space:]')"

How to deploy this in kubernetes cluster

```
#PROJECT_ID=pantel-2decb
export PROJECT_ID="$(gcloud config get-value project -q)"
Build the Docker image (In the folder with Dockerfile)

# Create cluster
gcloud container clusters create private-cluster --scopes=default,bigquery,datastore,pubsub,sql,storage-rw --num-nodes=3
docker build -t gcr.io/${PROJECT_ID}/pseudonym-server:${PSEUDONYM_VERSION} .

# Build the Docker image (In the folder with Dockerfile)
docker build -t gcr.io/${PROJECT_ID}/pseudonym-server:v1 .
# Push to the registry
gcloud docker -- push gcr.io/${PROJECT_ID}/pseudonym-server:v1
Push to the registry

# Apply the deployment
kubectl apply -f ./pseudonym-server.yaml
gcloud docker -- push gcr.io/${PROJECT_ID}/pseudonym-server:${PSEUDONYM_VERSION}

# Details of the deployment
kubectl describe deployment pseudonym-server
kubectl get pods
Update the tag (version) of prime's docker image in `infra/prime.yaml`.

# Deploy the service
kubectl apply -f ./pseudonym-server-service.yaml
# Details of service
kubectl describe service pseudonym-server-service
Apply the deployment & service

# Delete service
kubectl delete service pseudonym-server-service
# Delete deployment
kubectl delete deployment pseudonym-server
sed -e "s/PSEUDONYM_VERSION/$PSEUDONYM_VERSION/" pseudonym-server.yaml | kubectl apply -f -

# Delete cluster
gcloud container clusters delete private-cluster

# Container to test DNS
kubectl run curl --image=radial/busyboxplus:curl -i --tty
nslookup pseudonym-server-service
curl pseudonym-server-service.default.svc.cluster.local/pseudonym/current/47333
Details of the deployment

# SQL for joining dataconsumption and pseudonyms table
SELECT
hc.bytes, ps.msisdnid, hc.timestamp
FROM
[pantel-2decb:data_consumption.hourly_consumption] as hc
JOIN
[pantel-2decb:exported_pseudonyms.3ebcdc4a7ecc4cd385e82087e49b7b7b] as ps
ON ps.msisdn = hc.msisdn
kubectl describe deployment pseudonym-server
kubectl get pods


Helper Commands

Create cluster

gcloud container clusters create private-cluster --scopes=default,bigquery,datastore,pubsub,sql,storage-rw --num-nodes=3

Delete cluster

gcloud container clusters delete private-cluster

Delete service

kubectl delete service pseudonym-server-service

Delete deployment

kubectl delete deployment pseudonym-server


Container to test DNS

kubectl run curl --image=radial/busyboxplus:curl -i --tty
nslookup pseudonym-server-service
curl pseudonym-server-service.default.svc.cluster.local/pseudonym/current/47333

SQL for joining dataconsumption and pseudonyms table

SELECT
hc.bytes, ps.msisdnid, hc.timestamp
FROM
[pantel-2decb:data_consumption.hourly_consumption] as hc
JOIN
[pantel-2decb:exported_pseudonyms.3ebcdc4a7ecc4cd385e82087e49b7b7b] as ps
ON ps.msisdn = hc.msisdn

Login to gcr.io for pushing images

docker login -u oauth2accesstoken -p "$(gcloud auth print-access-token)" https://gcr.io

```
2 changes: 1 addition & 1 deletion pseudonym-server/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
id "idea"
id "project-report"
}

version = "1.5.0"
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
implementation "io.dropwizard:dropwizard-core:$dropwizardVersion"
Expand Down
2 changes: 1 addition & 1 deletion pseudonym-server/pseudonym-server.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ spec:
spec:
containers:
- name: pseudonym-server
image: gcr.io/pantel-2decb/pseudonym-server:v1.4
image: gcr.io/pantel-2decb/pseudonym-server:PSEUDONYM_VERSION
ports:
- containerPort: 8080
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import java.util.*
*/
class WeeklyBounds : DateBounds {
private val timeZone = TimeZone.getTimeZone("UTC")
private val locale = java.util.Locale.UK
/**
* Returns the boundaries for the week of the given timestamp.
*/
fun getBounds(timestamp: Long): Pair<Long, Long> {
val cal = Calendar.getInstance(timeZone)
val cal = Calendar.getInstance(timeZone, locale)
cal.timeInMillis = timestamp
cal.set(Calendar.HOUR_OF_DAY, 0)
cal.clear(Calendar.MINUTE)
Expand All @@ -31,7 +32,7 @@ class WeeklyBounds : DateBounds {
}

override fun getNextPeriodStart(timestamp: Long): Long {
val cal = Calendar.getInstance(timeZone)
val cal = Calendar.getInstance(timeZone, locale)
cal.timeInMillis = timestamp
cal.set(Calendar.HOUR_OF_DAY, 0)
cal.clear(Calendar.MINUTE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@ class DateUtilsTest {
fun testGetNextPeriodStart() {
// GMT: Saturday, May 12, 2018 11:59:59.999 PM
val timestamp = 1526169599999
// GMT: Sunday, May 13, 2018 12:00:00 AM
val expectedNextTimestamp = 1526169600000
// GMT: Monday, May 14, 2018 12:00:00 AM
val expectedNextTimestamp = 1526256000000
val nextTimestamp = dateBounds.getNextPeriodStart(timestamp)
print("Expected Timestamp ${expectedNextTimestamp} Next timestamp ${nextTimestamp}");
assertEquals(expectedNextTimestamp, nextTimestamp)
}
/**
Expand All @@ -28,9 +29,9 @@ class DateUtilsTest {
fun testGetNextPeriodAtYearEnd() {
// GMT: Monday, December 31, 2018 11:59:59 PM
val timestamp = 1546300799000
// GMT: Sunday, January 6, 2019 12:00:00 AM
val expectedNextTimestamp = 1546732800000
// GMT: Monday, January 7, 2019 12:00:00 AM
val expectedNextTimestamp = 1546819200000
val nextTimestamp = dateBounds.getNextPeriodStart(timestamp)
assertEquals(expectedNextTimestamp, nextTimestamp)
}
}
}

0 comments on commit 8ed22b6

Please sign in to comment.