Skip to content

Commit f88f18f

Browse files
committed
Merging PR #89
1 parent fb26f52 commit f88f18f

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

src/main/scala/de/upb/cs/swt/delphi/instanceregistry/RequestHandler.scala

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -488,36 +488,37 @@ class RequestHandler(configuration: Configuration, instanceDao: InstanceDAO, con
488488
} else if (!isInstanceDockerContainer(id)) {
489489
val instance = instanceDao.getInstance(id).get
490490

491-
if(instance.componentType == ComponentType.ElasticSearch || instance.componentType == ComponentType.DelphiManagement){
491+
if (instance.componentType == ComponentType.ElasticSearch || instance.componentType == ComponentType.DelphiManagement) {
492492
log.warning(s"Cannot stop instance of type ${instance.componentType}.")
493493
OperationResult.InvalidTypeForOperation
494494
} else {
495495
log.info(s"Calling /stop on non-docker instance $instance..")
496-
RestClient.executePost(RestClient.getUri(instance) + "/stop").map{
496+
RestClient.executePost(RestClient.getUri(instance) + "/stop").map {
497497
response =>
498498
log.info(s"Request to /stop returned $response")
499-
if (response.status == StatusCodes.OK){
499+
if (response.status == StatusCodes.OK) {
500500
log.info(s"Instance with id $id has been shut down successfully.")
501501
} else {
502502
log.warning(s"Failed to shut down instance with id $id. Status code was: ${response.status}")
503503
}
504-
}.recover{
504+
}.recover {
505505
case ex: Exception =>
506506
log.warning(s"Failed to shut down instance with id $id. Message is: ${ex.getMessage}")
507507
}
508508
handleDeregister(id)
509509
OperationResult.Ok
510510
}
511-
} else {
511+
} else if (instanceDao.getInstance(id).get.instanceState != InstanceState.Paused) {
512512
log.info(s"Handling /stop for instance with id $id...")
513513

514514
val instance = instanceDao.getInstance(id).get
515515

516516
log.info("Stopping container...")
517517
implicit val timeout: Timeout = configuration.dockerOperationTimeout
518518

519-
(dockerActor ? stop(instance.dockerId.get)).map{
520-
_ => log.info(s"Instance $id stopped.")
519+
(dockerActor ? stop(instance.dockerId.get)).map {
520+
_ =>
521+
log.info(s"Instance $id stopped.")
521522
instanceDao.setStateFor(instance.id.get, InstanceState.Stopped)
522523
fireStateChangedEvent(instanceDao.getInstance(instance.id.get).get)
523524
}.recover {
@@ -535,6 +536,9 @@ class RequestHandler(configuration: Configuration, instanceDao: InstanceDAO, con
535536
}
536537

537538
OperationResult.Ok
539+
} else {
540+
log.warning(s"Cannot stop paused docker container for instance with id $id")
541+
OperationResult.InvalidStateForOperation
538542
}
539543
}
540544

src/main/scala/de/upb/cs/swt/delphi/instanceregistry/connection/Server.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -632,6 +632,11 @@ class Server(handler: RequestHandler) extends HttpApp
632632
complete {
633633
HttpResponse(StatusCodes.BadRequest, entity = s"Cannot stop instance of this type.")
634634
}
635+
case handler.OperationResult.InvalidStateForOperation =>
636+
log.warning(s"Cannot stop id $id, the associated container is paused.")
637+
complete {
638+
HttpResponse(StatusCodes.BadRequest, entity = s"Cannot stop instance while it is paused.")
639+
}
635640
case handler.OperationResult.Ok =>
636641
complete {
637642
HttpResponse(StatusCodes.Accepted, entity = "Operation accepted.")

0 commit comments

Comments
 (0)