@@ -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
0 commit comments