Skip to content

Commit

Permalink
Wait until actor system terminated before exitting in examples (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
doriordan authored Dec 30, 2017
1 parent a2f5abe commit 8cfab5b
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 22 deletions.
2 changes: 1 addition & 1 deletion examples/application.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
akka {
loggers = ["akka.event.slf4j.Slf4jLogger"]
# loglevel = "DEBUG"
loglevel = "ERROR"
logging-filter = "akka.event.slf4j.Slf4jLoggingFilter"
actor {
debug {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,15 @@ object CreateCRD extends App {
case Success(_) =>
System.out.println("done!")
k8s.close
system.terminate().foreach { f =>
System.exit(0)
}
case Failure(ex) =>
System.err.println("Failed: " + ex)
k8s.close
system.terminate().foreach { f =>
System.exit(1)
}
}

def save(crd: CustomResourceDefinition) = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ object DeploymentExamples extends App {

val deployment = deployNginx("1.7.9")

deployment onSuccess {
case depl =>
deployment.foreach { depl =>

// Wait for initial deployment to complete before updating it.
// NOTE: Kubernetes v1.1 Deployment status subresource does not seem to be reliably populated
Expand All @@ -63,17 +62,18 @@ object DeploymentExamples extends App {
updateNginx("1.9.1") onComplete {
case scala.util.Success(_) =>
println("Update successfully requested - use'kubectl describe deployments' to monitor progress")
system.terminate()
System.exit(0)
system.terminate().foreach { f =>
System.exit(0)
}
case scala.util.Failure(ex) =>
ex.printStackTrace()
system.terminate()
System.exit(1)
system.terminate().map { f =>
System.exit(1)
}
}
}

deployment onFailure {
case ex =>
deployment.failed.foreach { ex =>
ex.printStackTrace()
system.terminate()
System.exit(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,13 @@ object FluentExamples extends App {
c <- deployControllers
} yield c

deployAll onFailure { case ex: K8SException => System.err.println("Request failed with status : " + ex.status) }
deployAll.failed.foreach { case ex: K8SException => System.err.println("Request failed with status : " + ex.status) }

deployAll andThen { case _ => k8s.close }
deployAll andThen { case _ =>
k8s.close
system.terminate().foreach { f =>
System.exit(0)
}
}
}
}
21 changes: 12 additions & 9 deletions examples/src/main/scala/skuber/examples/guestbook/Guestbook.scala
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@ object Guestbook extends App {
result match {
case GuestbookActor.DeployedSuccessfully => {
System.out.println("\n*** Deployment of Guestbook application to Kubernetes completed successfully!")
System.out.println("Waiting 5 seconds to allow skuber client to close...")
Thread.sleep(5000)
System.exit(0)
sys.terminate().foreach { f =>
System.exit(0)
}
}
case GuestbookActor.DeploymentFailed(ex) => {
System.err.println("\n!!! Deployment of Guestbook application failed: " + ex)
System.out.println("Waiting 5 seconds to allow skuber client to close...")
Thread.sleep(5000)
System.exit(1)
sys.terminate().foreach { f =>
System.exit(0)
}
}
}
}
deploymentResult onFailure {
case ex => System.err.println("Unexpected error deploying Guestbook: " + ex)
System.exit(-1)
deploymentResult.failed.foreach {
case ex =>
System.err.println("Unexpected error deploying Guestbook: " + ex)
sys.terminate().foreach { f =>
System.exit(1)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ class KubernetesProxyActor extends Actor with ActorLogging {
case Close => {
k8s.close
System.out.println("Closed skuber client")
system.terminate().foreach { f =>
System.exit(0)
}
sender ! Closed
}
}
Expand Down
6 changes: 6 additions & 0 deletions examples/src/main/scala/skuber/examples/job/PrintPiJob.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,15 @@ object PrintPiJob extends App {
case Success(job) =>
System.out.println("Job successfully created on the cluster")
k8s.close
system.terminate().foreach { f =>
System.exit(0)
}
case Failure(ex) =>
System.err.println("Failed to create job: " + ex)
k8s.close
system.terminate().foreach { f =>
System.exit(1)
}
}
// The job can be tracked using 'kubectl get pods' to get the name of the pod running the job (starts with "pi-")
// and then when the pod terminates use "kubectl logs <pod name>" to see the printed pi result
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,4 +72,7 @@ object ListExamples extends App {
Await.ready(printAllPods, 30 seconds)

k8s.close
system.terminate().foreach { f =>
System.exit(0)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ object ScaleExamples extends App {
"\n, message= " + k8sex.status.message.getOrElse("<>"))
case ex: Exception => ex.printStackTrace
}
autoScale onComplete { case _ => k8s.close }
autoScale onComplete { case _ =>
k8s.close
system.terminate().foreach { f =>
System.exit(0)
}
}
}
scaleNginxController
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ object WatchExamples {

Thread.sleep(30000) // watch for some time before closing the session
k8s.close
system.terminate
system.terminate().foreach { f =>
System.exit(0)
}
}
}

0 comments on commit 8cfab5b

Please sign in to comment.