diff options
author | Håkon Hallingstad <hakon@verizonmedia.com> | 2020-03-08 14:15:17 +0100 |
---|---|---|
committer | Håkon Hallingstad <hakon@verizonmedia.com> | 2020-03-08 14:15:17 +0100 |
commit | a34bb9650b92590ced290da1b2d131aabda10aac (patch) | |
tree | 4ad61009f278943cf24ebe98fffd78e85c2bac45 /orchestrator | |
parent | 3eb6aa9161ca016d8db3914970054d5519052c45 (diff) |
Avoid building lots of ApplicationInstances
Avoid building a full ApplicationInstance for each node...
- for all nodes in the node repo when reporting metrics repo every minute, and
- for all nodes in any /nodes/v1/node response
Diffstat (limited to 'orchestrator')
3 files changed, 23 insertions, 18 deletions
diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/Orchestrator.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/Orchestrator.java index 10fa10f1150..9d2d72277e5 100644 --- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/Orchestrator.java +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/Orchestrator.java @@ -2,8 +2,8 @@ package com.yahoo.vespa.orchestrator; import com.yahoo.config.provision.ApplicationId; +import com.yahoo.vespa.applicationmodel.ApplicationInstanceReference; import com.yahoo.vespa.applicationmodel.HostName; -import com.yahoo.vespa.orchestrator.model.NodeGroup; import com.yahoo.vespa.orchestrator.policy.BatchHostStateChangeDeniedException; import com.yahoo.vespa.orchestrator.policy.HostStateChangeDeniedException; import com.yahoo.vespa.orchestrator.status.ApplicationInstanceStatus; @@ -45,10 +45,13 @@ public interface Orchestrator { * * @param hostName The FQDN which are used in the noderepo. * @return The enum describing the current state. - * @throws HostNameNotFoundException if hostName is unrecognized (in node repo) + * @throws HostNameNotFoundException if hostName is not associated with any application */ HostStatus getNodeStatus(HostName hostName) throws HostNameNotFoundException; + /** Get host info for hostname in application, returning no-remarks if not in application. */ + HostInfo getHostInfo(ApplicationInstanceReference reference, HostName hostname); + /** * Returns a lambda, which when invoked with a hostname, returns its current host info. * diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/OrchestratorImpl.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/OrchestratorImpl.java index 5ac5c66cc7c..f36f7088424 100644 --- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/OrchestratorImpl.java +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/OrchestratorImpl.java @@ -127,19 +127,25 @@ public class OrchestratorImpl implements Orchestrator { @Override public HostStatus getNodeStatus(HostName hostName) throws HostNameNotFoundException { - return getNodeStatus(getApplicationInstance(hostName).reference(), hostName); + ApplicationInstanceReference reference = getApplicationInstanceReference(hostName); + return statusService.getHostInfo(reference, hostName).status(); + } + + @Override + public HostInfo getHostInfo(ApplicationInstanceReference reference, HostName hostname) { + return statusService.getHostInfo(reference, hostname); } @Override public Function<HostName, Optional<HostInfo>> getHostResolver() { return hostName -> serviceMonitor - .getApplication(hostName) - .map(application -> statusService.getHostInfo(application.reference(), hostName)); + .getApplicationInstanceReference(hostName) + .map(reference -> statusService.getHostInfo(reference, hostName)); } @Override public void setNodeStatus(HostName hostName, HostStatus status) throws OrchestrationException { - ApplicationInstanceReference reference = getApplicationInstance(hostName).reference(); + ApplicationInstanceReference reference = getApplicationInstanceReference(hostName); OrchestratorContext context = OrchestratorContext.createContextForSingleAppOp(clock); try (ApplicationLock lock = statusService.lockApplication(context, reference)) { lock.setHostState(hostName, status); @@ -347,11 +353,7 @@ public class OrchestratorImpl implements Orchestrator { return leftApplicationReference.asString().compareTo(rightApplicationReference.asString()); } - private HostStatus getNodeStatus(ApplicationInstanceReference applicationRef, HostName hostName) { - return statusService.getHostInfo(applicationRef, hostName).status(); - } - - private void setApplicationStatus(ApplicationId appId, ApplicationInstanceStatus status) + private void setApplicationStatus(ApplicationId appId, ApplicationInstanceStatus status) throws ApplicationStateChangeDeniedException, ApplicationIdNotFoundException{ OrchestratorContext context = OrchestratorContext.createContextForSingleAppOp(clock); ApplicationInstanceReference reference = OrchestratorUtil.toApplicationInstanceReference(appId, serviceMonitor); @@ -420,9 +422,14 @@ public class OrchestratorImpl implements Orchestrator { } } + private ApplicationInstanceReference getApplicationInstanceReference(HostName hostname) throws HostNameNotFoundException { + return serviceMonitor.getApplicationInstanceReference(hostname) + .orElseThrow(() -> new HostNameNotFoundException(hostname)); + } + private ApplicationInstance getApplicationInstance(HostName hostName) throws HostNameNotFoundException{ - return serviceMonitor.getApplication(hostName).orElseThrow( - () -> new HostNameNotFoundException(hostName)); + return serviceMonitor.getApplication(hostName) + .orElseThrow(() -> new HostNameNotFoundException(hostName)); } private static void sleep(long time, TimeUnit timeUnit) { diff --git a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/DummyServiceMonitor.java b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/DummyServiceMonitor.java index a784187fb62..501a09f78ff 100644 --- a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/DummyServiceMonitor.java +++ b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/DummyServiceMonitor.java @@ -163,11 +163,6 @@ public class DummyServiceMonitor implements ServiceMonitor, AntiServiceMonitor { } @Override - public Map<HostName, List<ServiceInstance>> getServicesByHostname() { - throw new UnsupportedOperationException(); - } - - @Override public CriticalRegion disallowDuperModelLockAcquisition(String regionDescription) { return () -> {}; } |