Skip to content

Commit ce3b7fa

Browse files
author
Johannes Duesing
committed
Changed some variable and function names for better understanding. Added scalastyle exclusion for number of methods.
1 parent 51dc16a commit ce3b7fa

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ import scala.concurrent.{Await, ExecutionContext, Future}
3636
import scala.language.postfixOps
3737
import scala.util.{Failure, Success, Try}
3838

39+
40+
// scalastyle:off number.of.methods
3941
class RequestHandler(configuration: Configuration, authDao: AuthDAO, instanceDao: InstanceDAO, connection: DockerConnection) extends AppLogging {
4042

4143

@@ -256,35 +258,41 @@ class RequestHandler(configuration: Configuration, authDao: AuthDAO, instanceDao
256258

257259
//Update link state
258260
if (!matchingSuccess) {
259-
val link = InstanceLink(callerId, matchedInstanceId, LinkState.Failed)
260-
instanceDao.updateLink(link) match {
261+
262+
setActiveLinksToFailed(matchedInstanceId) match {
261263
case Success(_) =>
262-
fireLinkStateChangedEvent(link)
263-
handleLinksUpdate(matchedInstanceId)
264264
OperationResult.Ok
265-
case Failure(_) => OperationResult.InternalError //Should not happen
265+
case Failure(_) =>
266+
// Message logged by method
267+
OperationResult.InternalError
266268
}
267269
} else {
268270
OperationResult.Ok
269271
}
270-
271272
}
272273
}
273274

274275

275-
def handleLinksUpdate(matchedInstanceId: Long): Unit = {
276+
def setActiveLinksToFailed(failedInstanceId: Long): Try[Unit] = {
276277

277-
val getlinkFrom = instanceDao.getLinksTo(matchedInstanceId)
278-
for (linklist <- getlinkFrom) {
279-
if (linklist.linkState != LinkState.Failed) {
280-
val link = InstanceLink(linklist.idFrom, matchedInstanceId, LinkState.Failed)
281-
instanceDao.updateLink(link) match {
278+
val linksToFailedInstance = instanceDao.getLinksTo(failedInstanceId)
279+
var errors = false
280+
281+
for (link <- linksToFailedInstance) {
282+
//Do not update outdated links
283+
if (link.linkState == LinkState.Assigned) {
284+
val newLink = InstanceLink(link.idFrom, failedInstanceId, LinkState.Failed)
285+
instanceDao.updateLink(newLink) match {
282286
case Success(_) =>
283287
fireLinkStateChangedEvent(link)
284-
case Failure(ex) => log.warning(s"There was a failure while updating the link state ${ex.getMessage}")
288+
case Failure(ex) =>
289+
errors = true
290+
log.warning(s"There was a failure while updating the link state ${ex.getMessage}")
285291
}
286292
}
287293
}
294+
295+
if(errors) Failure(new RuntimeException("Link updates unsuccessful")) else Success()
288296
}
289297

290298
// scalastyle:off method.length

0 commit comments

Comments
 (0)