diff options
author | hakonhall <hakon@oath.com> | 2017-09-20 16:01:27 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-20 16:01:27 +0200 |
commit | f86ff3d0c201966a9406c2039f08a3313dd56454 (patch) | |
tree | 213ea6e03144541fc9aa0bb4c13ed726105751ee /configserver | |
parent | 34e754e45ec896ce918c6655c777fa41b93ad787 (diff) | |
parent | c683c5a16706434b101f5fe04bb51af1350e01c7 (diff) |
Merge pull request #3466 from vespa-engine/hakon/move-supermodel-api-to-config-model-api
Move SuperModel API to config-model-api
Diffstat (limited to 'configserver')
6 files changed, 39 insertions, 69 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationListener.java b/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationListener.java deleted file mode 100644 index bea25183eef..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/ApplicationListener.java +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -package com.yahoo.vespa.config.server; - -import com.yahoo.config.provision.ApplicationId; -import com.yahoo.config.provision.TenantName; -import com.yahoo.vespa.config.server.application.ApplicationSet; - -public interface ApplicationListener { - /** - * Configs has been activated for an application: Either an application - * has been deployed for the first time, or it has been externally or internally redeployed. - * - * Must be thread-safe. - */ - void configActivated(TenantName tenant, ApplicationSet application); - - /** - * Application has been removed. - * - * Must be thread-safe. - */ - void applicationRemoved(ApplicationId applicationId); -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/ReloadListener.java b/configserver/src/main/java/com/yahoo/vespa/config/server/ReloadListener.java index e392472480b..71c6d311172 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/ReloadListener.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/ReloadListener.java @@ -15,7 +15,7 @@ import java.util.Collection; * @author lulf * @since 5.1 */ -public interface ReloadListener extends ApplicationListener { +public interface ReloadListener { /** * Signal the listener that hosts used by by a particular tenant. * @@ -32,4 +32,19 @@ public interface ReloadListener extends ApplicationListener { * @throws java.lang.IllegalArgumentException if one or more of the hosts are in use by another tenant. */ void verifyHostsAreAvailable(TenantName tenant, Collection<String> newHosts); + + /** + * Configs has been activated for an application: Either an application + * has been deployed for the first time, or it has been externally or internally redeployed. + * + * Must be thread-safe. + */ + void configActivated(TenantName tenant, ApplicationSet application); + + /** + * Application has been removed. + * + * Must be thread-safe. + */ + void applicationRemoved(ApplicationId applicationId); } diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/SuperModelListener.java b/configserver/src/main/java/com/yahoo/vespa/config/server/SuperModelListener.java deleted file mode 100644 index 81d706cf2e9..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/SuperModelListener.java +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -package com.yahoo.vespa.config.server; - -import com.yahoo.config.provision.ApplicationId; -import com.yahoo.vespa.config.server.application.Application; -import com.yahoo.vespa.config.server.model.SuperModel; - -/** - * Interface for those wanting to be notified about changes to the SuperModel. - */ -public interface SuperModelListener { - /** - * Application has been activated: Either deployed the first time, - * internally redeployed, or externally triggered redeploy. - */ - void applicationActivated(SuperModel superModel, Application application); - - /** - * Application has been removed. - */ - void applicationRemoved(SuperModel superModel, ApplicationId applicationId); -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/SuperModelManager.java b/configserver/src/main/java/com/yahoo/vespa/config/server/SuperModelManager.java index c3fd417f434..06f7ffa66c4 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/SuperModelManager.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/SuperModelManager.java @@ -4,6 +4,9 @@ package com.yahoo.vespa.config.server; import com.google.inject.Inject; import com.yahoo.cloud.config.ConfigserverConfig; +import com.yahoo.config.model.api.ApplicationInfo; +import com.yahoo.config.model.api.SuperModelListener; +import com.yahoo.config.model.api.SuperModelProvider; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.NodeFlavors; import com.yahoo.config.provision.TenantName; @@ -14,13 +17,19 @@ import com.yahoo.vespa.config.server.application.ApplicationSet; import com.yahoo.vespa.config.server.model.SuperModel; import java.time.Instant; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.stream.Collectors; /** * Provides a SuperModel - a model of all application instances, and makes it stays * up to date as applications are added, redeployed, and removed. */ -public class SuperModelManager implements SuperModelProvider, ApplicationListener { +public class SuperModelManager implements SuperModelProvider { private final Zone zone; private SuperModel superModel; // Guarded by 'this' monitor private final List<SuperModelListener> listeners = new ArrayList<>(); // Guarded by 'this' monitor @@ -40,22 +49,23 @@ public class SuperModelManager implements SuperModelProvider, ApplicationListene makeNewSuperModel(new HashMap<>()); } - @Override public synchronized SuperModel getSuperModel() { return superModel; } - @Override public synchronized long getGeneration() { return generation; } @Override - public synchronized void registerListener(SuperModelListener listener) { + public synchronized List<ApplicationInfo> snapshot(SuperModelListener listener) { listeners.add(listener); + return superModel.applicationModels().values().stream() + .flatMap(applications -> applications.values().stream()) + .map(Application::toApplicationInfo) + .collect(Collectors.toList()); } - @Override public synchronized void configActivated(TenantName tenant, ApplicationSet applicationSet) { Map<TenantName, Map<ApplicationId, Application>> newModels = createModelCopy(); if (!newModels.containsKey(tenant)) { @@ -70,10 +80,9 @@ public class SuperModelManager implements SuperModelProvider, ApplicationListene newModels.get(tenant).put(applicationSet.getId(), application); makeNewSuperModel(newModels); - listeners.stream().forEach(listener -> listener.applicationActivated(superModel, application)); + listeners.stream().forEach(listener -> listener.applicationActivated(application.toApplicationInfo())); } - @Override public synchronized void applicationRemoved(ApplicationId applicationId) { Map<TenantName, Map<ApplicationId, Application>> newModels = createModelCopy(); if (newModels.containsKey(applicationId.tenant())) { @@ -84,7 +93,7 @@ public class SuperModelManager implements SuperModelProvider, ApplicationListene } makeNewSuperModel(newModels); - listeners.stream().forEach(listener -> listener.applicationRemoved(superModel, applicationId)); + listeners.stream().forEach(listener -> listener.applicationRemoved(applicationId)); } private void makeNewSuperModel(Map<TenantName, Map<ApplicationId, Application>> newModels) { diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/SuperModelProvider.java b/configserver/src/main/java/com/yahoo/vespa/config/server/SuperModelProvider.java deleted file mode 100644 index 81eb823c026..00000000000 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/SuperModelProvider.java +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. - -package com.yahoo.vespa.config.server; - -import com.yahoo.vespa.config.server.model.SuperModel; - -interface SuperModelProvider { - SuperModel getSuperModel(); - long getGeneration(); - - void registerListener(SuperModelListener listener); -} diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/application/Application.java b/configserver/src/main/java/com/yahoo/vespa/config/server/application/Application.java index 369bce70660..f8f11416811 100644 --- a/configserver/src/main/java/com/yahoo/vespa/config/server/application/Application.java +++ b/configserver/src/main/java/com/yahoo/vespa/config/server/application/Application.java @@ -2,6 +2,7 @@ package com.yahoo.vespa.config.server.application; import com.yahoo.config.ConfigurationRuntimeException; +import com.yahoo.config.model.api.ApplicationInfo; import com.yahoo.config.model.api.Model; import com.yahoo.config.provision.ApplicationId; import com.yahoo.config.provision.Version; @@ -74,6 +75,10 @@ public class Application implements ModelResult { return sb.toString(); } + public ApplicationInfo toApplicationInfo() { + return new ApplicationInfo(app, appGeneration, model); + } + public ServerCache getCache() { return cache; } |