aboutsummaryrefslogtreecommitdiffstats
path: root/configserver/src/main/java/com/yahoo/vespa/config/server/application/ApplicationMapper.java
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-07-06 15:50:48 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-07-06 15:50:48 +0200
commitbec3d408785a17d53e40afe0c8872e3068693a2c (patch)
treef1f3765c84b1963c9b10ccbfdecb0ab51e99fa1c /configserver/src/main/java/com/yahoo/vespa/config/server/application/ApplicationMapper.java
parent4dd6e1bda2f24d94f48c36ce24f882589c9c226f (diff)
Refactor
Diffstat (limited to 'configserver/src/main/java/com/yahoo/vespa/config/server/application/ApplicationMapper.java')
-rw-r--r--configserver/src/main/java/com/yahoo/vespa/config/server/application/ApplicationMapper.java78
1 files changed, 78 insertions, 0 deletions
diff --git a/configserver/src/main/java/com/yahoo/vespa/config/server/application/ApplicationMapper.java b/configserver/src/main/java/com/yahoo/vespa/config/server/application/ApplicationMapper.java
new file mode 100644
index 00000000000..aacd7ef5624
--- /dev/null
+++ b/configserver/src/main/java/com/yahoo/vespa/config/server/application/ApplicationMapper.java
@@ -0,0 +1,78 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.config.server.application;
+
+import com.yahoo.config.provision.ApplicationId;
+import com.yahoo.config.provision.Version;
+
+import java.util.Map;
+import java.util.Optional;
+import java.util.concurrent.ConcurrentHashMap;
+
+import com.yahoo.vespa.config.server.VersionDoesNotExistException;
+import com.yahoo.vespa.config.server.http.NotFoundException;
+
+/**
+ * Used during config request handling to route to the right config model
+ * based on application id and version.
+ *
+ * @author Vegard Sjonfjell
+ */
+public final class ApplicationMapper {
+
+ private final Map<ApplicationId, ApplicationSet> requestHandlers = new ConcurrentHashMap<>();
+
+ private ApplicationSet getApplicationSet(ApplicationId applicationId) {
+ ApplicationSet list = requestHandlers.get(applicationId);
+ if (list != null) {
+ return list;
+ }
+
+ throw new NotFoundException("No such application id: " + applicationId);
+ }
+
+ /**
+ * Register a Application to an application id and specific vespa version
+ */
+ public void register(ApplicationId applicationId, ApplicationSet applicationSet) {
+ requestHandlers.put(applicationId, applicationSet);
+ }
+
+ /**
+ * Remove all applications associated with this application id
+ */
+ public void remove(ApplicationId applicationId) {
+ requestHandlers.remove(applicationId);
+ }
+
+ /**
+ * Retrieve the Application corresponding to this application id and specific vespa version.
+ *
+ * @return the matching application, or null if none matches
+ */
+ public Application getForVersion(ApplicationId applicationId, Optional<Version> vespaVersion) throws VersionDoesNotExistException {
+ return getApplicationSet(applicationId).getForVersionOrLatest(vespaVersion);
+ }
+
+ /** Returns whether this registry has an application for the given application id */
+ public boolean hasApplication(ApplicationId applicationId) {
+ return hasApplicationForVersion(applicationId, Optional.<Version>empty());
+ }
+
+ /** Returns whether this registry has an application for the given application id and vespa version */
+ public boolean hasApplicationForVersion(ApplicationId applicationId, Optional<Version> vespaVersion) {
+ try {
+ return getForVersion(applicationId, vespaVersion) != null;
+ }
+ catch (VersionDoesNotExistException | NotFoundException ex) {
+ return false;
+ }
+ }
+
+ /**
+ * Get the number of applications registered
+ */
+ public int numApplications() {
+ return requestHandlers.size();
+ }
+
+}