Skip to content

Commit e778e6e

Browse files
authored
Merge pull request #114 from delphi-hub/bugfix/invalidLinkStates
Fixed a bug concerning link state updates
2 parents 0f3799c + d8df5d8 commit e778e6e

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ class RequestHandler(configuration: Configuration, authDao: AuthDAO, instanceDao
295295

296296
deployResult match {
297297
case Failure(ex) =>
298-
log.warning(s"Failed to deploy container, docker host not reachable.")
298+
log.warning(s"Failed to deploy container, docker host not reachable. Message ${ex.getMessage}")
299299
instanceDao.removeInstance(id)
300300
fireDockerOperationErrorEvent(None, s"Deploy failed with message: ${ex.getMessage}")
301301
Failure(new RuntimeException(s"Failed to deploy container, docker host not reachable (${ex.getMessage})."))

src/main/scala/de/upb/cs/swt/delphi/instanceregistry/daos/DatabaseInstanceDAO.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -286,17 +286,18 @@ class DatabaseInstanceDAO (configuration : Configuration) extends InstanceDAO wi
286286
override def addLink(link: InstanceLink) : Try[Unit] = {
287287
if(hasInstance(link.idFrom) && hasInstance(link.idTo)){
288288

289+
//If new link is in state 'Assigned': Set any link that previously was assigned to 'outdated'
290+
//IMPORTANT: Only works bc every component has exactly one dependency!
291+
if(link.linkState == LinkState.Assigned){
292+
for (prevLink <- getLinksFrom(link.idFrom, Some(LinkState.Assigned))){
293+
updateLink(InstanceLink(prevLink.idFrom, prevLink.idTo, LinkState.Outdated))
294+
}
295+
}
296+
289297
if(getLinksFrom(link.idFrom).exists(l => l.idTo == link.idTo)){
290298
//There already is a link between the two instances. Update it instead of adding a new one
291299
updateLink(link)
292300
} else {
293-
//If new link is in state 'Assigned': Set any link that previously was assigned to 'outdated'
294-
//IMPORTANT: Only works bc every component has exactly one dependency!
295-
if(link.linkState == LinkState.Assigned){
296-
for (prevLink <- getLinksFrom(link.idFrom, Some(LinkState.Assigned))){
297-
updateLink(InstanceLink(prevLink.idFrom, prevLink.idTo, LinkState.Outdated))
298-
}
299-
}
300301
addLinkFromInstanceLink(link)
301302
}
302303
Success()

src/main/scala/de/upb/cs/swt/delphi/instanceregistry/daos/DynamicInstanceDAO.scala

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -242,17 +242,18 @@ class DynamicInstanceDAO (configuration : Configuration) extends InstanceDAO wit
242242
override def addLink(link: InstanceLink) : Try[Unit] = {
243243
if(hasInstance(link.idFrom) && hasInstance(link.idTo)){
244244

245+
//If new link is in state 'Assigned': Set any link that previously was assigned to 'outdated'
246+
//IMPORTANT: Only works bc every component has exactly one dependency!
247+
if(link.linkState == LinkState.Assigned){
248+
for (prevLink <- getLinksFrom(link.idFrom, Some(LinkState.Assigned))){
249+
updateLink(InstanceLink(prevLink.idFrom, prevLink.idTo, LinkState.Outdated))
250+
}
251+
}
252+
245253
if(getLinksFrom(link.idFrom).exists(l => l.idTo == link.idTo)){
246254
//There already is a link between the two instances. Update it instead of adding a new one
247255
updateLink(link)
248256
} else {
249-
//If new link is in state 'Assigned': Set any link that previously was assigned to 'outdated'
250-
//IMPORTANT: Only works bc every component has exactly one dependency!
251-
if(link.linkState == LinkState.Assigned){
252-
for (prevLink <- getLinksFrom(link.idFrom, Some(LinkState.Assigned))){
253-
updateLink(InstanceLink(prevLink.idFrom, prevLink.idTo, LinkState.Outdated))
254-
}
255-
}
256257
instanceLinks.add(link)
257258
}
258259
Success()
@@ -267,8 +268,8 @@ class DynamicInstanceDAO (configuration : Configuration) extends InstanceDAO wit
267268
if(linksMatching.nonEmpty){
268269
for(l <- linksMatching){
269270
instanceLinks.remove(l)
270-
instanceLinks.add(link)
271271
}
272+
instanceLinks.add(link)
272273
Success()
273274
} else {
274275
Failure(new RuntimeException(s"Cannot update link $link, this link is not present in the dao."))

0 commit comments

Comments
 (0)