From 14ed5595c31fc1f803c5ae3bdcd50b0f743ee5d2 Mon Sep 17 00:00:00 2001 From: HÃ¥kon Hallingstad Date: Fri, 7 Dec 2018 01:59:58 +0100 Subject: Remove infra app from duper model only if it is supposed to be in duper model --- .../provision/maintenance/InfrastructureProvisioner.java | 8 ++++++++ .../main/java/com/yahoo/vespa/service/duper/DuperModel.java | 7 +++++++ .../java/com/yahoo/vespa/service/duper/DuperModelManager.java | 6 +++--- .../com/yahoo/vespa/service/duper/DuperModelManagerTest.java | 10 +++++----- 4 files changed, 23 insertions(+), 8 deletions(-) diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/InfrastructureProvisioner.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/InfrastructureProvisioner.java index a30da2c96ac..443cbf4c358 100644 --- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/InfrastructureProvisioner.java +++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/InfrastructureProvisioner.java @@ -92,6 +92,14 @@ public class InfrastructureProvisioner extends Maintainer { duperModel.infraApplicationActivated( application.getApplicationId(), hostSpecs.stream().map(HostSpec::hostname).map(HostName::from).collect(Collectors.toList())); + + String detail; + if (hostSpecs.size() < 10) { + detail = ": " + hostSpecs.stream().map(HostSpec::hostname).collect(Collectors.joining(",")); + } else { + detail = " with " + hostSpecs.size() + " hosts"; + } + logger.log(LogLevel.INFO, "Infrastructure application " + application.getApplicationId() + " activated" + detail); } catch (RuntimeException e) { logger.log(LogLevel.INFO, "Failed to activate " + application.getApplicationId(), e); // loop around to activate the next application diff --git a/service-monitor/src/main/java/com/yahoo/vespa/service/duper/DuperModel.java b/service-monitor/src/main/java/com/yahoo/vespa/service/duper/DuperModel.java index c90b37a4c2a..024282d3d21 100644 --- a/service-monitor/src/main/java/com/yahoo/vespa/service/duper/DuperModel.java +++ b/service-monitor/src/main/java/com/yahoo/vespa/service/duper/DuperModel.java @@ -3,12 +3,14 @@ package com.yahoo.vespa.service.duper; import com.yahoo.config.model.api.ApplicationInfo; import com.yahoo.config.provision.ApplicationId; +import com.yahoo.log.LogLevel; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Map; import java.util.TreeMap; +import java.util.logging.Logger; /** * A non-thread-safe mutable container of ApplicationInfo in the DuperModel, also taking care of listeners on changes. @@ -16,6 +18,8 @@ import java.util.TreeMap; * @author hakonhall */ public class DuperModel { + private static Logger logger = Logger.getLogger(DuperModel.class.getName()); + private final Map applications = new TreeMap<>(); private final List listeners = new ArrayList<>(); @@ -30,16 +34,19 @@ public class DuperModel { public void add(ApplicationInfo applicationInfo) { applications.put(applicationInfo.getApplicationId(), applicationInfo); + logger.log(LogLevel.DEBUG, "Added " + applicationInfo.getApplicationId()); listeners.forEach(listener -> listener.applicationActivated(applicationInfo)); } public void remove(ApplicationId applicationId) { if (applications.remove(applicationId) != null) { + logger.log(LogLevel.DEBUG, "Removed " + applicationId); listeners.forEach(listener -> listener.applicationRemoved(applicationId)); } } public List getApplicationInfos() { + logger.log(LogLevel.DEBUG, "Applications in duper model: " + applications.values().size()); return Collections.unmodifiableList(new ArrayList<>(applications.values())); } } diff --git a/service-monitor/src/main/java/com/yahoo/vespa/service/duper/DuperModelManager.java b/service-monitor/src/main/java/com/yahoo/vespa/service/duper/DuperModelManager.java index 1f8fa35d1cf..ed99d2e3166 100644 --- a/service-monitor/src/main/java/com/yahoo/vespa/service/duper/DuperModelManager.java +++ b/service-monitor/src/main/java/com/yahoo/vespa/service/duper/DuperModelManager.java @@ -174,7 +174,7 @@ public class DuperModelManager implements DuperModelInfraApi { public void infraApplicationRemoved(ApplicationId applicationId) { synchronized (monitor) { activeInfraInfos.remove(applicationId); - if (duperModel.contains(applicationId)) { + if (infraApplicationBelongsInDuperModel(applicationId)) { duperModel.remove(applicationId); } } @@ -204,7 +204,7 @@ public class DuperModelManager implements DuperModelInfraApi { if (isConfigServerFromConfigInDuperModel()) return false; if (!multitenant) return false; if (duperModel.contains(configServerApplication.getApplicationId())) { - logger.log(LogLevel.WARNING, "Refusing to add controller application to duper model " + + logger.log(LogLevel.ERROR, "Refusing to add controller application to duper model " + "since it already contains config server"); return false; } @@ -213,7 +213,7 @@ public class DuperModelManager implements DuperModelInfraApi { if (isConfigServerFromConfigInDuperModel()) return false; if (!multitenant) return false; if (duperModel.contains(controllerApplication.getApplicationId())) { - logger.log(LogLevel.WARNING, "Refusing to add config server application to duper model " + + logger.log(LogLevel.ERROR, "Refusing to add config server application to duper model " + "since it already contains controller"); return false; } diff --git a/service-monitor/src/test/java/com/yahoo/vespa/service/duper/DuperModelManagerTest.java b/service-monitor/src/test/java/com/yahoo/vespa/service/duper/DuperModelManagerTest.java index da693df77ce..ba38b99617b 100644 --- a/service-monitor/src/test/java/com/yahoo/vespa/service/duper/DuperModelManagerTest.java +++ b/service-monitor/src/test/java/com/yahoo/vespa/service/duper/DuperModelManagerTest.java @@ -149,15 +149,15 @@ public class DuperModelManagerTest { manager.infraApplicationActivated(secondId, hostnames2); verify(duperModel, times(1)).add(any()); + // Removing the second config server like application cannot be removed since it wasn't added + verify(duperModel, times(0)).remove(any()); + manager.infraApplicationRemoved(secondId); + verify(duperModel, times(0)).remove(any()); + verify(duperModel, times(0)).remove(any()); manager.infraApplicationRemoved(firstId); verify(duperModel, times(1)).remove(any()); when(duperModel.contains(firstId)).thenReturn(false); - - // Removing the second config server like application cannot be removed since it wasn't added - verify(duperModel, times(1)).remove(any()); - manager.infraApplicationRemoved(secondId); - verify(duperModel, times(1)).remove(any()); } @Test -- cgit v1.2.3