diff options
author | Håkon Hallingstad <hakon@verizonmedia.com> | 2020-03-02 14:06:24 +0100 |
---|---|---|
committer | Håkon Hallingstad <hakon@verizonmedia.com> | 2020-03-02 14:06:24 +0100 |
commit | 4b6a2a891680dd778ccd5cf8761a888d44b3421a (patch) | |
tree | b42fad08259ffcebb809ab75316ded31527fcd01 /orchestrator | |
parent | 2120128c0194fad3507527b2e1a48187ea71d5cc (diff) |
Align names with status service
Diffstat (limited to 'orchestrator')
17 files changed, 221 insertions, 208 deletions
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 d9d41cdaecc..964d2875496 100644 --- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/OrchestratorImpl.java +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/OrchestratorImpl.java @@ -34,7 +34,7 @@ import com.yahoo.vespa.orchestrator.status.ApplicationInstanceStatus; import com.yahoo.vespa.orchestrator.status.HostInfo; import com.yahoo.vespa.orchestrator.status.HostInfos; import com.yahoo.vespa.orchestrator.status.HostStatus; -import com.yahoo.vespa.orchestrator.status.MutableStatusRegistry; +import com.yahoo.vespa.orchestrator.status.MutableStatusService; import com.yahoo.vespa.orchestrator.status.StatusService; import java.io.IOException; @@ -135,8 +135,8 @@ public class OrchestratorImpl implements Orchestrator { public void setNodeStatus(HostName hostName, HostStatus status) throws OrchestrationException { ApplicationInstanceReference reference = getApplicationInstance(hostName).reference(); OrchestratorContext context = OrchestratorContext.createContextForSingleAppOp(clock); - try (MutableStatusRegistry statusRegistry = statusService - .lockApplicationInstance_forCurrentThreadOnly(context, reference)) { + try (MutableStatusService statusRegistry = statusService + .lockApplication(context, reference)) { statusRegistry.setHostState(hostName, status); } } @@ -165,8 +165,8 @@ public class OrchestratorImpl implements Orchestrator { ApplicationInstance appInstance = getApplicationInstance(hostName); OrchestratorContext context = OrchestratorContext.createContextForSingleAppOp(clock); - try (MutableStatusRegistry statusRegistry = statusService - .lockApplicationInstance_forCurrentThreadOnly(context, appInstance.reference())) { + try (MutableStatusService statusRegistry = statusService + .lockApplication(context, appInstance.reference())) { HostStatus currentHostState = statusRegistry.getHostInfos().getOrNoRemarks(hostName).status(); if (currentHostState == HostStatus.NO_REMARKS) { return; @@ -202,8 +202,8 @@ public class OrchestratorImpl implements Orchestrator { .with(FetchVector.Dimension.HOSTNAME, hostName.s()) .value(); OrchestratorContext context = OrchestratorContext.createContextForSingleAppOp(clock, usePermanentlyDownStatus); - try (MutableStatusRegistry statusRegistry = statusService - .lockApplicationInstance_forCurrentThreadOnly(context, appInstance.reference())) { + try (MutableStatusService statusRegistry = statusService + .lockApplication(context, appInstance.reference())) { ApplicationApi applicationApi = applicationApiFactory.create(nodeGroup, statusRegistry, clusterControllerClientFactory); @@ -220,8 +220,8 @@ public class OrchestratorImpl implements Orchestrator { void suspendGroup(OrchestratorContext context, NodeGroup nodeGroup) throws HostStateChangeDeniedException { ApplicationInstanceReference applicationReference = nodeGroup.getApplicationReference(); - try (MutableStatusRegistry hostStatusRegistry = - statusService.lockApplicationInstance_forCurrentThreadOnly(context, applicationReference)) { + try (MutableStatusService hostStatusRegistry = + statusService.lockApplication(context, applicationReference)) { ApplicationInstanceStatus appStatus = hostStatusRegistry.getStatus(); if (appStatus == ApplicationInstanceStatus.ALLOWED_TO_BE_DOWN) { return; @@ -354,8 +354,8 @@ public class OrchestratorImpl implements Orchestrator { throws ApplicationStateChangeDeniedException, ApplicationIdNotFoundException{ OrchestratorContext context = OrchestratorContext.createContextForSingleAppOp(clock); ApplicationInstanceReference appRef = OrchestratorUtil.toApplicationInstanceReference(appId, instanceLookupService); - try (MutableStatusRegistry statusRegistry = - statusService.lockApplicationInstance_forCurrentThreadOnly(context, appRef)) { + try (MutableStatusService statusRegistry = + statusService.lockApplication(context, appRef)) { // Short-circuit if already in wanted state if (status == statusRegistry.getStatus()) return; diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/OrchestratorUtil.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/OrchestratorUtil.java index 91da046840d..5294a841412 100644 --- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/OrchestratorUtil.java +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/OrchestratorUtil.java @@ -65,7 +65,7 @@ public class OrchestratorUtil { private static final Pattern APPLICATION_INSTANCE_REFERENCE_REST_FORMAT_PATTERN = Pattern.compile("^([^:]+):(.+)$"); /** Returns an ApplicationInstanceReference constructed from the serialized format used in the REST API. */ - public static ApplicationInstanceReference parseAppInstanceReference(String restFormat) { + public static ApplicationInstanceReference parseApplicationInstanceReference(String restFormat) { if (restFormat == null) { throw new IllegalArgumentException("Could not construct instance id from null string"); } diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/model/ApplicationApiFactory.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/model/ApplicationApiFactory.java index 5e6ec59c28d..ef14a99d7db 100644 --- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/model/ApplicationApiFactory.java +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/model/ApplicationApiFactory.java @@ -2,7 +2,7 @@ package com.yahoo.vespa.orchestrator.model; import com.yahoo.vespa.orchestrator.controller.ClusterControllerClientFactory; -import com.yahoo.vespa.orchestrator.status.MutableStatusRegistry; +import com.yahoo.vespa.orchestrator.status.MutableStatusService; /** * @author mpolden @@ -16,7 +16,7 @@ public class ApplicationApiFactory { } public ApplicationApi create(NodeGroup nodeGroup, - MutableStatusRegistry hostStatusService, + MutableStatusService hostStatusService, ClusterControllerClientFactory clusterControllerClientFactory) { return new ApplicationApiImpl(nodeGroup, hostStatusService, clusterControllerClientFactory, numberOfConfigServers); } diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/model/ApplicationApiImpl.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/model/ApplicationApiImpl.java index cf6946fa7f8..92867cf3258 100644 --- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/model/ApplicationApiImpl.java +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/model/ApplicationApiImpl.java @@ -12,7 +12,7 @@ import com.yahoo.vespa.orchestrator.controller.ClusterControllerClientFactory; import com.yahoo.vespa.orchestrator.status.ApplicationInstanceStatus; import com.yahoo.vespa.orchestrator.status.HostInfos; import com.yahoo.vespa.orchestrator.status.HostStatus; -import com.yahoo.vespa.orchestrator.status.MutableStatusRegistry; +import com.yahoo.vespa.orchestrator.status.MutableStatusService; import java.util.Collection; import java.util.Comparator; @@ -32,12 +32,12 @@ public class ApplicationApiImpl implements ApplicationApi { private final ApplicationInstance applicationInstance; private final NodeGroup nodeGroup; - private final MutableStatusRegistry hostStatusService; + private final MutableStatusService hostStatusService; private final List<ClusterApi> clusterInOrder; private final HostInfos hostInfos; public ApplicationApiImpl(NodeGroup nodeGroup, - MutableStatusRegistry hostStatusService, + MutableStatusService hostStatusService, ClusterControllerClientFactory clusterControllerClientFactory, int numberOfConfigServers) { this.applicationInstance = nodeGroup.getApplication(); diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/HostedVespaPolicy.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/HostedVespaPolicy.java index f6a1e4f91f0..95ce34a8a61 100644 --- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/HostedVespaPolicy.java +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/HostedVespaPolicy.java @@ -13,7 +13,7 @@ import com.yahoo.vespa.orchestrator.model.NodeGroup; import com.yahoo.vespa.orchestrator.model.StorageNode; import com.yahoo.vespa.orchestrator.status.ApplicationInstanceStatus; import com.yahoo.vespa.orchestrator.status.HostStatus; -import com.yahoo.vespa.orchestrator.status.MutableStatusRegistry; +import com.yahoo.vespa.orchestrator.status.MutableStatusService; /** * @author oyving @@ -113,7 +113,7 @@ public class HostedVespaPolicy implements Policy { OrchestratorContext context, ApplicationInstance applicationInstance, HostName hostName, - MutableStatusRegistry hostStatusService) throws HostStateChangeDeniedException { + MutableStatusService hostStatusService) throws HostStateChangeDeniedException { NodeGroup nodeGroup = new NodeGroup(applicationInstance, hostName); ApplicationApi applicationApi = applicationApiFactory.create(nodeGroup, hostStatusService, clusterControllerClientFactory); releaseSuspensionGrant(context, applicationApi); diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/Policy.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/Policy.java index aa7636227c8..6e7a3552828 100644 --- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/Policy.java +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/policy/Policy.java @@ -5,8 +5,7 @@ import com.yahoo.vespa.applicationmodel.ApplicationInstance; import com.yahoo.vespa.applicationmodel.HostName; import com.yahoo.vespa.orchestrator.OrchestratorContext; import com.yahoo.vespa.orchestrator.model.ApplicationApi; -import com.yahoo.vespa.orchestrator.status.MutableStatusRegistry; -import com.yahoo.vespa.orchestrator.status.StatusService; +import com.yahoo.vespa.orchestrator.status.MutableStatusService; /** * @author oyving @@ -33,6 +32,6 @@ public interface Policy { void releaseSuspensionGrant( OrchestratorContext context, ApplicationInstance applicationInstance, HostName hostName, - MutableStatusRegistry hostStatusService) throws HostStateChangeDeniedException; + MutableStatusService hostStatusService) throws HostStateChangeDeniedException; } diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/InstanceResource.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/InstanceResource.java index cfdda3250f6..2ade81ff0f5 100644 --- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/InstanceResource.java +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/resources/InstanceResource.java @@ -37,7 +37,7 @@ import java.util.TreeMap; import java.util.stream.Collectors; import static com.yahoo.vespa.orchestrator.OrchestratorUtil.getHostsUsedByApplicationInstance; -import static com.yahoo.vespa.orchestrator.OrchestratorUtil.parseAppInstanceReference; +import static com.yahoo.vespa.orchestrator.OrchestratorUtil.parseApplicationInstanceReference; /** * Provides a read-only API for looking into the current state as seen by the Orchestrator. @@ -152,7 +152,7 @@ public class InstanceResource { static ApplicationInstanceReference parseInstanceId(String instanceIdString) { try { - return parseAppInstanceReference(instanceIdString); + return parseApplicationInstanceReference(instanceIdString); } catch (IllegalArgumentException e) { throwBadRequest(e.getMessage()); return null; // Necessary for compiler diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/MutableStatusRegistry.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/MutableStatusService.java index 24da83364aa..ad68652e968 100644 --- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/MutableStatusRegistry.java +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/MutableStatusService.java @@ -3,8 +3,6 @@ package com.yahoo.vespa.orchestrator.status; import com.yahoo.vespa.applicationmodel.HostName; -import java.util.Set; - /** * Registry of the suspension and host statuses for an application instance. * @@ -12,7 +10,7 @@ import java.util.Set; * @author Tony Vaagenes * @author bakksjo */ -public interface MutableStatusRegistry extends AutoCloseable { +public interface MutableStatusService extends AutoCloseable { /** Returns the status of this application. */ ApplicationInstanceStatus getStatus(); diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/StatusService.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/StatusService.java index e2be5ec7eb6..346d0523333 100644 --- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/StatusService.java +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/StatusService.java @@ -44,9 +44,8 @@ public interface StatusService { * this case, subsequent mutating operations will fail, but previous mutating operations are NOT rolled back. * This may leave the registry in an inconsistent state (as judged by the client code). */ - MutableStatusRegistry lockApplicationInstance_forCurrentThreadOnly( - OrchestratorContext context, - ApplicationInstanceReference applicationInstanceReference) throws UncheckedTimeoutException; + MutableStatusService lockApplication(OrchestratorContext context, ApplicationInstanceReference reference) + throws UncheckedTimeoutException; /** * Returns all application instances that are allowed to be down. The intention is to use this @@ -68,5 +67,5 @@ public interface StatusService { ApplicationInstanceStatus getApplicationInstanceStatus(ApplicationInstanceReference application); /** Get host info for hostname in application. This is consistent if its lock is held. */ - HostInfo getHostInfo(ApplicationInstanceReference applicationInstanceReference, HostName hostName); + HostInfo getHostInfo(ApplicationInstanceReference reference, HostName hostName); } diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/ZkMutableStatusService.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/ZkMutableStatusService.java new file mode 100644 index 00000000000..e855f78a03c --- /dev/null +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/ZkMutableStatusService.java @@ -0,0 +1,104 @@ +// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. + +package com.yahoo.vespa.orchestrator.status; + +import com.yahoo.log.LogLevel; +import com.yahoo.vespa.applicationmodel.ApplicationInstanceReference; +import com.yahoo.vespa.applicationmodel.HostName; +import com.yahoo.vespa.curator.Curator; +import org.apache.zookeeper.KeeperException; + +import java.util.logging.Logger; + +class ZkMutableStatusService implements MutableStatusService { + + private static final Logger log = Logger.getLogger(ZkMutableStatusService.class.getName()); + + private final ZkStatusService statusService; + private final Curator curator; + private final Runnable onClose; + private final ApplicationInstanceReference reference; + private final boolean probe; + private final HostInfosCache hostInfosCache; + + ZkMutableStatusService(ZkStatusService statusService, + Curator curator, + Runnable onClose, + ApplicationInstanceReference reference, + boolean probe, + HostInfosCache hostInfosCache) { + this.statusService = statusService; + this.curator = curator; + this.onClose = onClose; + this.reference = reference; + this.probe = probe; + this.hostInfosCache = hostInfosCache; + } + + @Override + public ApplicationInstanceStatus getStatus() { + return statusService.getApplicationInstanceStatus(reference); + } + + @Override + public HostInfos getHostInfos() { + return hostInfosCache.getHostInfos(reference); + } + + @Override + public void setHostState(final HostName hostName, final HostStatus status) { + if (probe) return; + log.log(LogLevel.INFO, "Setting host " + hostName + " to status " + status); + hostInfosCache.setHostStatus(reference, hostName, status); + } + + @Override + public void setApplicationInstanceStatus(ApplicationInstanceStatus applicationInstanceStatus) { + if (probe) return; + + log.log(LogLevel.INFO, "Setting app " + reference.asString() + " to status " + applicationInstanceStatus); + + String path = statusService.applicationInstanceSuspendedPath(reference); + switch (applicationInstanceStatus) { + case NO_REMARKS: + deleteNode_ignoreNoNodeException(path); + break; + case ALLOWED_TO_BE_DOWN: + createNode_ignoreNodeExistsException(path); + break; + } + } + + @Override + public void close() { + try { + onClose.run(); + } catch (RuntimeException e) { + // We may want to avoid logging some exceptions that may be expected, like when session expires. + log.log(LogLevel.WARNING, + "Failed close application lock in " + + ZkMutableStatusService.class.getSimpleName() + ", will ignore and continue", + e); + } + } + + void deleteNode_ignoreNoNodeException(String path) { + try { + curator.framework().delete().forPath(path); + } catch (KeeperException.NoNodeException e) { + // ok + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + void createNode_ignoreNodeExistsException(String path) { + try { + curator.framework().create().creatingParentsIfNeeded().forPath(path); + } catch (KeeperException.NodeExistsException e) { + // ok + } catch (Exception e) { + throw new RuntimeException(e); + } + } +} diff --git a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/ZookeeperStatusService.java b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/ZkStatusService.java index ba363b73973..4be629c6d21 100644 --- a/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/ZookeeperStatusService.java +++ b/orchestrator/src/main/java/com/yahoo/vespa/orchestrator/status/ZkStatusService.java @@ -13,8 +13,6 @@ import com.yahoo.vespa.curator.Curator; import com.yahoo.vespa.curator.Lock; import com.yahoo.vespa.orchestrator.OrchestratorContext; import com.yahoo.vespa.orchestrator.OrchestratorUtil; -import org.apache.zookeeper.KeeperException.NoNodeException; -import org.apache.zookeeper.KeeperException.NodeExistsException; import org.apache.zookeeper.data.Stat; import javax.inject.Inject; @@ -33,9 +31,9 @@ import java.util.logging.Logger; * TODO: expiry of old application instances * @author Tony Vaagenes */ -public class ZookeeperStatusService implements StatusService { +public class ZkStatusService implements StatusService { - private static final Logger log = Logger.getLogger(ZookeeperStatusService.class.getName()); + private static final Logger log = Logger.getLogger(ZkStatusService.class.getName()); final static String HOST_STATUS_BASE_PATH = "/vespa/host-status-service"; final static String APPLICATION_STATUS_BASE_PATH = "/vespa/application-status-service"; @@ -52,7 +50,7 @@ public class ZookeeperStatusService implements StatusService { private final ConcurrentHashMap<Map<String, String>, Metric.Context> cachedContexts = new ConcurrentHashMap<>(); @Inject - public ZookeeperStatusService(@Component Curator curator, @Component Metric metric, @Component Timer timer) { + public ZkStatusService(@Component Curator curator, @Component Metric metric, @Component Timer timer) { this.curator = curator; this.metric = metric; this.timer = timer; @@ -60,7 +58,7 @@ public class ZookeeperStatusService implements StatusService { } /** Non-private for testing only. */ - ZookeeperStatusService(Curator curator, Metric metric, Timer timer, HostInfosCache hostInfosCache) { + ZkStatusService(Curator curator, Metric metric, Timer timer, HostInfosCache hostInfosCache) { this.curator = curator; this.metric = metric; this.timer = timer; @@ -77,9 +75,9 @@ public class ZookeeperStatusService implements StatusService { if (stat == null) return resultSet; // The path exist and we may have children - for (String appRefStr : curator.framework().getChildren().forPath(APPLICATION_STATUS_BASE_PATH)) { - ApplicationInstanceReference appRef = OrchestratorUtil.parseAppInstanceReference(appRefStr); - resultSet.add(appRef); + for (String referenceString : curator.framework().getChildren().forPath(APPLICATION_STATUS_BASE_PATH)) { + ApplicationInstanceReference reference = OrchestratorUtil.parseApplicationInstanceReference(referenceString); + resultSet.add(reference); } return resultSet; @@ -112,20 +110,20 @@ public class ZookeeperStatusService implements StatusService { * (i.e. the request is for another applicationInstanceReference) */ @Override - public MutableStatusRegistry lockApplicationInstance_forCurrentThreadOnly( + public MutableStatusService lockApplication( OrchestratorContext context, - ApplicationInstanceReference applicationInstanceReference) throws UncheckedTimeoutException { + ApplicationInstanceReference reference) throws UncheckedTimeoutException { Runnable onRegistryClose; // A multi-application operation, aka batch suspension, will first issue a probe // then a non-probe. With "large locks", the lock is not release in between - // no lock is taken on the non-probe. Instead, the release is done on the multi-application // context close. - if (context.hasLock(applicationInstanceReference)) { + if (context.hasLock(reference)) { onRegistryClose = () -> {}; } else { - Runnable unlock = acquireLock(context, applicationInstanceReference); - if (context.registerLockAcquisition(applicationInstanceReference, unlock)) { + Runnable unlock = acquireLock(context, reference); + if (context.registerLockAcquisition(reference, unlock)) { onRegistryClose = () -> {}; } else { onRegistryClose = unlock; @@ -133,7 +131,13 @@ public class ZookeeperStatusService implements StatusService { } try { - return new ZkMutableStatusRegistry(onRegistryClose, applicationInstanceReference, context.isProbe()); + return new ZkMutableStatusService( + this, + curator, + onRegistryClose, + reference, + context.isProbe(), + hostInfosCache); } catch (Throwable t) { // In case the constructor throws an exception. onRegistryClose.run(); @@ -142,9 +146,9 @@ public class ZookeeperStatusService implements StatusService { } private Runnable acquireLock(OrchestratorContext context, - ApplicationInstanceReference applicationInstanceReference) + ApplicationInstanceReference reference) throws UncheckedTimeoutException { - ApplicationId applicationId = OrchestratorUtil.toApplicationId(applicationInstanceReference); + ApplicationId applicationId = OrchestratorUtil.toApplicationId(reference); String app = applicationId.application().value() + "." + applicationId.instance().value(); Map<String, String> dimensions = Map.of( "tenantName", applicationId.tenant().value(), @@ -153,7 +157,7 @@ public class ZookeeperStatusService implements StatusService { Metric.Context metricContext = cachedContexts.computeIfAbsent(dimensions, metric::createContext); Duration duration = context.getTimeLeft(); - String lockPath = applicationInstanceLock2Path(applicationInstanceReference); + String lockPath = applicationInstanceLock2Path(reference); Lock lock = new Lock(lockPath, curator); Instant startTime = timer.currentTime(); @@ -180,7 +184,7 @@ public class ZookeeperStatusService implements StatusService { // We may want to avoid logging some exceptions that may be expected, like when session expires. log.log(LogLevel.WARNING, "Failed to close application lock for " + - ZookeeperStatusService.class.getSimpleName() + ", will ignore and continue", + ZkStatusService.class.getSimpleName() + ", will ignore and continue", e); } @@ -194,42 +198,16 @@ public class ZookeeperStatusService implements StatusService { return Duration.between(startInstant, endInstant).toMillis() / 1000.0; } - private boolean deleteNode_ignoreNoNodeException(String path, String debugLogMessageIfNotExists) { - try { - curator.framework().delete().forPath(path); - return true; - } catch (NoNodeException e) { - log.log(LogLevel.DEBUG, debugLogMessageIfNotExists, e); - return false; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - - private boolean createNode_ignoreNodeExistsException(String path, String debugLogMessageIfExists) { - try { - curator.framework().create() - .creatingParentsIfNeeded() - .forPath(path); - return true; - } catch (NodeExistsException e) { - log.log(LogLevel.DEBUG, debugLogMessageIfExists, e); - return false; - } catch (Exception e) { - throw new RuntimeException(e); - } - } - @Override - public HostInfo getHostInfo(ApplicationInstanceReference applicationInstanceReference, HostName hostName) { - return hostInfosCache.getHostInfos(applicationInstanceReference).getOrNoRemarks(hostName); + public HostInfo getHostInfo(ApplicationInstanceReference reference, HostName hostName) { + return hostInfosCache.getHostInfos(reference).getOrNoRemarks(hostName); } @Override - public ApplicationInstanceStatus getApplicationInstanceStatus(ApplicationInstanceReference applicationInstanceReference) { + public ApplicationInstanceStatus getApplicationInstanceStatus(ApplicationInstanceReference reference) { try { Stat statOrNull = curator.framework().checkExists().forPath( - applicationInstanceSuspendedPath(applicationInstanceReference)); + applicationInstanceSuspendedPath(reference)); return (statOrNull == null) ? ApplicationInstanceStatus.NO_REMARKS : ApplicationInstanceStatus.ALLOWED_TO_BE_DOWN; } catch (Exception e) { @@ -237,89 +215,24 @@ public class ZookeeperStatusService implements StatusService { } } - static String applicationInstanceReferencePath(ApplicationInstanceReference applicationInstanceReference) { - return HOST_STATUS_BASE_PATH + '/' + - applicationInstanceReference.tenantId() + ":" + applicationInstanceReference.applicationInstanceId(); - } - - private static String hostsAllowedDownPath(ApplicationInstanceReference applicationInstanceReference) { - return applicationInstanceReferencePath(applicationInstanceReference) + "/hosts-allowed-down"; + static String applicationInstanceReferencePath(ApplicationInstanceReference reference) { + return HOST_STATUS_BASE_PATH + '/' + reference.tenantId() + ":" + reference.applicationInstanceId(); } - private static String applicationInstanceLock2Path(ApplicationInstanceReference applicationInstanceReference) { - return applicationInstanceReferencePath(applicationInstanceReference) + "/lock2"; + private static String hostsAllowedDownPath(ApplicationInstanceReference reference) { + return applicationInstanceReferencePath(reference) + "/hosts-allowed-down"; } - private String applicationInstanceSuspendedPath(ApplicationInstanceReference applicationInstanceReference) { - return APPLICATION_STATUS_BASE_PATH + "/" + OrchestratorUtil.toRestApiFormat(applicationInstanceReference); + private static String applicationInstanceLock2Path(ApplicationInstanceReference reference) { + return applicationInstanceReferencePath(reference) + "/lock2"; } - private static String hostAllowedDownPath(ApplicationInstanceReference applicationInstanceReference, HostName hostname) { - return hostsAllowedDownPath(applicationInstanceReference) + '/' + hostname.s(); + String applicationInstanceSuspendedPath(ApplicationInstanceReference reference) { + return APPLICATION_STATUS_BASE_PATH + "/" + OrchestratorUtil.toRestApiFormat(reference); } - private class ZkMutableStatusRegistry implements MutableStatusRegistry { - - private final Runnable onClose; - private final ApplicationInstanceReference applicationInstanceReference; - private final boolean probe; - - public ZkMutableStatusRegistry(Runnable onClose, - ApplicationInstanceReference applicationInstanceReference, - boolean probe) { - this.onClose = onClose; - this.applicationInstanceReference = applicationInstanceReference; - this.probe = probe; - } - - @Override - public ApplicationInstanceStatus getStatus() { - return getApplicationInstanceStatus(applicationInstanceReference); - } - - @Override - public HostInfos getHostInfos() { - return hostInfosCache.getHostInfos(applicationInstanceReference); - } - - @Override - public void setHostState(final HostName hostName, final HostStatus status) { - if (probe) return; - log.log(LogLevel.INFO, "Setting host " + hostName + " to status " + status); - hostInfosCache.setHostStatus(applicationInstanceReference, hostName, status); - } - - @Override - public void setApplicationInstanceStatus(ApplicationInstanceStatus applicationInstanceStatus) { - if (probe) return; - - log.log(LogLevel.INFO, "Setting app " + applicationInstanceReference.asString() + " to status " + applicationInstanceStatus); - - String path = applicationInstanceSuspendedPath(applicationInstanceReference); - switch (applicationInstanceStatus) { - case NO_REMARKS: - deleteNode_ignoreNoNodeException(path, - "Instance is already in state NO_REMARKS, path = " + path); - break; - case ALLOWED_TO_BE_DOWN: - createNode_ignoreNodeExistsException(path, - "Instance is already in state ALLOWED_TO_BE_DOWN, path = " + path); - break; - } - } - - @Override - public void close() { - try { - onClose.run(); - } catch (RuntimeException e) { - // We may want to avoid logging some exceptions that may be expected, like when session expires. - log.log(LogLevel.WARNING, - "Failed close application lock in " + - ZookeeperStatusService.class.getSimpleName() + ", will ignore and continue", - e); - } - } + private static String hostAllowedDownPath(ApplicationInstanceReference reference, HostName hostname) { + return hostsAllowedDownPath(reference) + '/' + hostname.s(); } } diff --git a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/OrchestratorImplTest.java b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/OrchestratorImplTest.java index 0869fde3422..3f560a3e274 100644 --- a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/OrchestratorImplTest.java +++ b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/OrchestratorImplTest.java @@ -27,9 +27,9 @@ import com.yahoo.vespa.orchestrator.policy.HostStateChangeDeniedException; import com.yahoo.vespa.orchestrator.policy.HostedVespaClusterPolicy; import com.yahoo.vespa.orchestrator.policy.HostedVespaPolicy; import com.yahoo.vespa.orchestrator.status.HostStatus; -import com.yahoo.vespa.orchestrator.status.MutableStatusRegistry; +import com.yahoo.vespa.orchestrator.status.MutableStatusService; import com.yahoo.vespa.orchestrator.status.StatusService; -import com.yahoo.vespa.orchestrator.status.ZookeeperStatusService; +import com.yahoo.vespa.orchestrator.status.ZkStatusService; import com.yahoo.vespa.service.model.ServiceModelCache; import com.yahoo.vespa.service.monitor.ServiceModel; import org.junit.Before; @@ -95,7 +95,7 @@ public class OrchestratorImplTest { clustercontroller = new ClusterControllerClientFactoryMock(); orchestrator = new OrchestratorImpl(new HostedVespaPolicy(new HostedVespaClusterPolicy(), clustercontroller, applicationApiFactory), clustercontroller, - new ZookeeperStatusService(new MockCurator(), mock(Metric.class), new TestTimer()), + new ZkStatusService(new MockCurator(), mock(Metric.class), new TestTimer()), new DummyInstanceLookupService(), 0, new ManualClock(), @@ -330,17 +330,17 @@ public class OrchestratorImplTest { var applicationInstanceReference = new ApplicationInstanceReference(tenantId, applicationInstanceId); var policy = mock(HostedVespaPolicy.class); - var zookeeperStatusService = mock(ZookeeperStatusService.class); + var zookeeperStatusService = mock(ZkStatusService.class); var instanceLookupService = mock(InstanceLookupService.class); var applicationInstance = mock(ApplicationInstance.class); var clusterControllerClientFactory = mock(ClusterControllerClientFactory.class); var clock = new ManualClock(); var applicationApiFactory = mock(ApplicationApiFactory.class); - var hostStatusRegistry = mock(MutableStatusRegistry.class); + var hostStatusRegistry = mock(MutableStatusService.class); when(instanceLookupService.findInstanceByHost(any())).thenReturn(Optional.of(applicationInstance)); when(applicationInstance.reference()).thenReturn(applicationInstanceReference); - when(zookeeperStatusService.lockApplicationInstance_forCurrentThreadOnly(any(), any())) + when(zookeeperStatusService.lockApplication(any(), any())) .thenReturn(hostStatusRegistry); when(hostStatusRegistry.getStatus()).thenReturn(NO_REMARKS); @@ -359,7 +359,7 @@ public class OrchestratorImplTest { orchestrator.suspendAll(parentHostname, List.of(parentHostname)); ArgumentCaptor<OrchestratorContext> contextCaptor = ArgumentCaptor.forClass(OrchestratorContext.class); - verify(zookeeperStatusService, times(2)).lockApplicationInstance_forCurrentThreadOnly(contextCaptor.capture(), any()); + verify(zookeeperStatusService, times(2)).lockApplication(contextCaptor.capture(), any()); List<OrchestratorContext> contexts = contextCaptor.getAllValues(); // First invocation is probe, second is not. @@ -375,7 +375,7 @@ public class OrchestratorImplTest { verify(hostStatusRegistry, times(2)).getStatus(); // Each zookeeperStatusService that is created, is closed. - verify(zookeeperStatusService, times(2)).lockApplicationInstance_forCurrentThreadOnly(any(), any()); + verify(zookeeperStatusService, times(2)).lockApplication(any(), any()); verify(hostStatusRegistry, times(2)).close(); verifyNoMoreInteractions( @@ -390,7 +390,7 @@ public class OrchestratorImplTest { @Test public void testGetHost() throws Exception { ClusterControllerClientFactory clusterControllerClientFactory = new ClusterControllerClientFactoryMock(); - StatusService statusService = new ZookeeperStatusService(new MockCurator(), mock(Metric.class), new TestTimer()); + StatusService statusService = new ZkStatusService(new MockCurator(), mock(Metric.class), new TestTimer()); HostName hostName = new HostName("host.yahoo.com"); TenantId tenantId = new TenantId("tenant"); diff --git a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/model/ModelTestUtils.java b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/model/ModelTestUtils.java index 991b5837111..b37d3fc3850 100644 --- a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/model/ModelTestUtils.java +++ b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/model/ModelTestUtils.java @@ -29,9 +29,9 @@ import com.yahoo.vespa.orchestrator.policy.HostedVespaPolicy; import com.yahoo.vespa.orchestrator.status.HostInfo; import com.yahoo.vespa.orchestrator.status.HostInfos; import com.yahoo.vespa.orchestrator.status.HostStatus; -import com.yahoo.vespa.orchestrator.status.MutableStatusRegistry; +import com.yahoo.vespa.orchestrator.status.MutableStatusService; import com.yahoo.vespa.orchestrator.status.StatusService; -import com.yahoo.vespa.orchestrator.status.ZookeeperStatusService; +import com.yahoo.vespa.orchestrator.status.ZkStatusService; import com.yahoo.vespa.service.model.ServiceModelCache; import com.yahoo.vespa.service.monitor.ServiceModel; import com.yahoo.vespa.service.monitor.ServiceMonitor; @@ -59,7 +59,7 @@ class ModelTestUtils { private final Map<ApplicationInstanceReference, ApplicationInstance> applications = new HashMap<>(); private final ClusterControllerClientFactory clusterControllerClientFactory = new ClusterControllerClientFactoryMock(); private final Map<HostName, HostStatus> hostStatusMap = new HashMap<>(); - private final StatusService statusService = new ZookeeperStatusService(new MockCurator(), mock(Metric.class), new TestTimer()); + private final StatusService statusService = new ZkStatusService(new MockCurator(), mock(Metric.class), new TestTimer()); private final TestTimer timer = new TestTimer(); private final ServiceMonitor serviceMonitor = new ServiceModelCache(() -> new ServiceModel(applications), timer); private final Orchestrator orchestrator = new OrchestratorImpl(new HostedVespaPolicy(new HostedVespaClusterPolicy(), clusterControllerClientFactory, applicationApiFactory()), @@ -114,7 +114,7 @@ class ModelTestUtils { ApplicationInstance applicationInstance, HostName... hostnames) { NodeGroup nodeGroup = new NodeGroup(applicationInstance, hostnames); - MutableStatusRegistry registry = statusService.lockApplicationInstance_forCurrentThreadOnly( + MutableStatusService registry = statusService.lockApplication( OrchestratorContext.createContextForSingleAppOp(Clock.systemUTC()), applicationInstance.reference()); return applicationApiFactory().create(nodeGroup, registry, clusterControllerClientFactory); diff --git a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/resources/ApplicationSuspensionResourceTest.java b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/resources/ApplicationSuspensionResourceTest.java index 80d0af09792..cedddf19d9e 100644 --- a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/resources/ApplicationSuspensionResourceTest.java +++ b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/resources/ApplicationSuspensionResourceTest.java @@ -161,7 +161,7 @@ public class ApplicationSuspensionResourceTest { " </config>\n" + " <component id=\"com.yahoo.vespa.flags.InMemoryFlagSource\" bundle=\"flags\" />\n" + " <component id=\"com.yahoo.vespa.curator.mock.MockCurator\" bundle=\"zkfacade\" />\n" + - " <component id=\"com.yahoo.vespa.orchestrator.status.ZookeeperStatusService\" bundle=\"orchestrator\" />\n" + + " <component id=\"com.yahoo.vespa.orchestrator.status.ZkStatusService\" bundle=\"orchestrator\" />\n" + " <component id=\"com.yahoo.vespa.orchestrator.DummyInstanceLookupService\" bundle=\"orchestrator\" />\n" + " <component id=\"com.yahoo.vespa.orchestrator.OrchestratorImpl\" bundle=\"orchestrator\" />\n" + " <component id=\"com.yahoo.vespa.orchestrator.controller.ClusterControllerClientFactoryMock\" bundle=\"orchestrator\" />\n" + diff --git a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/resources/HostResourceTest.java b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/resources/HostResourceTest.java index 4a7be5f3ab6..df5f31c8e47 100644 --- a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/resources/HostResourceTest.java +++ b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/resources/HostResourceTest.java @@ -39,9 +39,9 @@ import com.yahoo.vespa.orchestrator.restapi.wire.PatchHostResponse; import com.yahoo.vespa.orchestrator.restapi.wire.UpdateHostResponse; import com.yahoo.vespa.orchestrator.status.HostInfo; import com.yahoo.vespa.orchestrator.status.HostStatus; -import com.yahoo.vespa.orchestrator.status.MutableStatusRegistry; +import com.yahoo.vespa.orchestrator.status.MutableStatusService; import com.yahoo.vespa.orchestrator.status.StatusService; -import com.yahoo.vespa.orchestrator.status.ZookeeperStatusService; +import com.yahoo.vespa.orchestrator.status.ZkStatusService; import org.junit.Before; import org.junit.Test; @@ -78,7 +78,7 @@ public class HostResourceTest { private static final int SERVICE_MONITOR_CONVERGENCE_LATENCY_SECONDS = 0; private static final TenantId TENANT_ID = new TenantId("tenantId"); private static final ApplicationInstanceId APPLICATION_INSTANCE_ID = new ApplicationInstanceId("applicationId"); - private static final StatusService EVERY_HOST_IS_UP_HOST_STATUS_SERVICE = new ZookeeperStatusService( + private static final StatusService EVERY_HOST_IS_UP_HOST_STATUS_SERVICE = new ZkStatusService( new MockCurator(), mock(Metric.class), new TestTimer()); private static final ApplicationApiFactory applicationApiFactory = new ApplicationApiFactory(3); @@ -134,7 +134,7 @@ public class HostResourceTest { public void releaseSuspensionGrant( OrchestratorContext context, ApplicationInstance applicationInstance, HostName hostName, - MutableStatusRegistry hostStatusRegistry) { + MutableStatusService hostStatusRegistry) { } } @@ -236,7 +236,7 @@ public class HostResourceTest { public void releaseSuspensionGrant( OrchestratorContext context, ApplicationInstance applicationInstance, HostName hostName, - MutableStatusRegistry hostStatusRegistry) throws HostStateChangeDeniedException { + MutableStatusService hostStatusRegistry) throws HostStateChangeDeniedException { doThrow(); } diff --git a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/status/ZookeeperStatusService2Test.java b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/status/ZkStatusService2Test.java index 8f530f4abf3..10556a15c51 100644 --- a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/status/ZookeeperStatusService2Test.java +++ b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/status/ZkStatusService2Test.java @@ -27,12 +27,12 @@ import static org.mockito.Mockito.when; /** * @author hakonhall */ -public class ZookeeperStatusService2Test { +public class ZkStatusService2Test { private final Curator curator = mock(Curator.class); private final Timer timer = new TestTimer(); private final Metric metric = mock(Metric.class); private final HostInfosCache cache = mock(HostInfosCache.class); - private final ZookeeperStatusService zookeeperStatusService = new ZookeeperStatusService(curator, metric, timer, cache); + private final ZkStatusService zkStatusService = new ZkStatusService(curator, metric, timer, cache); private final OrchestratorContext context = mock(OrchestratorContext.class); private final InterProcessMutex mutex = mock(InterProcessMutex.class); @@ -50,7 +50,7 @@ public class ZookeeperStatusService2Test { when(context.getTimeLeft()).thenReturn(Duration.ofSeconds(12)); - try (MutableStatusRegistry registry = zookeeperStatusService.lockApplicationInstance_forCurrentThreadOnly(context, reference)) { + try (MutableStatusService registry = zkStatusService.lockApplication(context, reference)) { // nothing } @@ -65,7 +65,7 @@ public class ZookeeperStatusService2Test { when(context.isProbe()).thenReturn(false); - try (MutableStatusRegistry registry = zookeeperStatusService.lockApplicationInstance_forCurrentThreadOnly(context, reference)) { + try (MutableStatusService registry = zkStatusService.lockApplication(context, reference)) { // nothing } @@ -88,7 +88,7 @@ public class ZookeeperStatusService2Test { when(context.getTimeLeft()).thenReturn(Duration.ofSeconds(12)); - try (MutableStatusRegistry registry = zookeeperStatusService.lockApplicationInstance_forCurrentThreadOnly(context, reference)) { + try (MutableStatusService registry = zkStatusService.lockApplication(context, reference)) { // nothing } @@ -105,7 +105,7 @@ public class ZookeeperStatusService2Test { when(context.hasLock(any())).thenReturn(true); when(context.registerLockAcquisition(any(), any())).thenReturn(false); - try (MutableStatusRegistry registry = zookeeperStatusService.lockApplicationInstance_forCurrentThreadOnly(context, reference)) { + try (MutableStatusService registry = zkStatusService.lockApplication(context, reference)) { // nothing } diff --git a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/status/ZookeeperStatusServiceTest.java b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/status/ZkStatusServiceTest.java index 687ea951f88..48d50946e51 100644 --- a/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/status/ZookeeperStatusServiceTest.java +++ b/orchestrator/src/test/java/com/yahoo/vespa/orchestrator/status/ZkStatusServiceTest.java @@ -53,9 +53,9 @@ import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @RunWith(MockitoJUnitRunner.class) -public class ZookeeperStatusServiceTest { +public class ZkStatusServiceTest { private TestingServer testingServer; - private ZookeeperStatusService zookeeperStatusService; + private ZkStatusService zkStatusService; private Curator curator; private final Timer timer = mock(Timer.class); private final Metric metric = mock(Metric.class); @@ -70,7 +70,7 @@ public class ZookeeperStatusServiceTest { testingServer = new TestingServer(); curator = createConnectedCurator(testingServer); - zookeeperStatusService = new ZookeeperStatusService(curator, metric, timer); + zkStatusService = new ZkStatusService(curator, metric, timer); when(context.getTimeLeft()).thenReturn(Duration.ofSeconds(10)); when(context.isProbe()).thenReturn(false); when(timer.currentTime()).thenReturn(Instant.ofEpochMilli(1)); @@ -96,7 +96,7 @@ public class ZookeeperStatusServiceTest { @Test public void host_state_for_unknown_hosts_is_no_remarks() { assertThat( - zookeeperStatusService.getHostInfo(TestIds.APPLICATION_INSTANCE_REFERENCE, TestIds.HOST_NAME1).status(), + zkStatusService.getHostInfo(TestIds.APPLICATION_INSTANCE_REFERENCE, TestIds.HOST_NAME1).status(), is(HostStatus.NO_REMARKS)); } @@ -107,8 +107,8 @@ public class ZookeeperStatusServiceTest { Instant.ofEpochMilli((3)), Instant.ofEpochMilli(6)); - try (MutableStatusRegistry statusRegistry = zookeeperStatusService - .lockApplicationInstance_forCurrentThreadOnly(context, TestIds.APPLICATION_INSTANCE_REFERENCE)) { + try (MutableStatusService statusRegistry = zkStatusService + .lockApplication(context, TestIds.APPLICATION_INSTANCE_REFERENCE)) { //shuffling to catch "clean database" failures for all cases. for (HostStatus hostStatus: shuffledList(HostStatus.NO_REMARKS, HostStatus.ALLOWED_TO_BE_DOWN)) { @@ -141,15 +141,15 @@ public class ZookeeperStatusServiceTest { @Test public void locks_are_exclusive() throws Exception { - ZookeeperStatusService zookeeperStatusService2 = new ZookeeperStatusService(curator, mock(Metric.class), new TestTimer()); + ZkStatusService zkStatusService2 = new ZkStatusService(curator, mock(Metric.class), new TestTimer()); final CompletableFuture<Void> lockedSuccessfullyFuture; - try (MutableStatusRegistry statusRegistry = zookeeperStatusService - .lockApplicationInstance_forCurrentThreadOnly(context, TestIds.APPLICATION_INSTANCE_REFERENCE)) { + try (MutableStatusService statusRegistry = zkStatusService + .lockApplication(context, TestIds.APPLICATION_INSTANCE_REFERENCE)) { lockedSuccessfullyFuture = CompletableFuture.runAsync(() -> { - try (MutableStatusRegistry statusRegistry2 = zookeeperStatusService2 - .lockApplicationInstance_forCurrentThreadOnly(context, TestIds.APPLICATION_INSTANCE_REFERENCE)) + try (MutableStatusService statusRegistry2 = zkStatusService2 + .lockApplication(context, TestIds.APPLICATION_INSTANCE_REFERENCE)) { } }); @@ -166,15 +166,15 @@ public class ZookeeperStatusServiceTest { @Test public void failing_to_get_lock_closes_SessionFailRetryLoop() throws Exception { - ZookeeperStatusService zookeeperStatusService2 = new ZookeeperStatusService(curator, mock(Metric.class), new TestTimer()); + ZkStatusService zkStatusService2 = new ZkStatusService(curator, mock(Metric.class), new TestTimer()); - try (MutableStatusRegistry statusRegistry = zookeeperStatusService - .lockApplicationInstance_forCurrentThreadOnly(context, TestIds.APPLICATION_INSTANCE_REFERENCE)) { + try (MutableStatusService statusRegistry = zkStatusService + .lockApplication(context, TestIds.APPLICATION_INSTANCE_REFERENCE)) { //must run in separate thread, since having 2 locks in the same thread fails CompletableFuture<Void> resultOfZkOperationAfterLockFailure = CompletableFuture.runAsync(() -> { try { - zookeeperStatusService2.lockApplicationInstance_forCurrentThreadOnly(context, TestIds.APPLICATION_INSTANCE_REFERENCE); + zkStatusService2.lockApplication(context, TestIds.APPLICATION_INSTANCE_REFERENCE); fail("Both zookeeper host status services locked simultaneously for the same application instance"); } catch (RuntimeException e) { } @@ -239,29 +239,29 @@ public class ZookeeperStatusServiceTest { // Initial state is NO_REMARK assertThat( - zookeeperStatusService + zkStatusService .getApplicationInstanceStatus(TestIds.APPLICATION_INSTANCE_REFERENCE), is(ApplicationInstanceStatus.NO_REMARKS)); // Suspend - try (MutableStatusRegistry statusRegistry = zookeeperStatusService - .lockApplicationInstance_forCurrentThreadOnly(context, TestIds.APPLICATION_INSTANCE_REFERENCE)) { + try (MutableStatusService statusRegistry = zkStatusService + .lockApplication(context, TestIds.APPLICATION_INSTANCE_REFERENCE)) { statusRegistry.setApplicationInstanceStatus(ApplicationInstanceStatus.ALLOWED_TO_BE_DOWN); } assertThat( - zookeeperStatusService + zkStatusService .getApplicationInstanceStatus(TestIds.APPLICATION_INSTANCE_REFERENCE), is(ApplicationInstanceStatus.ALLOWED_TO_BE_DOWN)); // Resume - try (MutableStatusRegistry statusRegistry = zookeeperStatusService - .lockApplicationInstance_forCurrentThreadOnly(context, TestIds.APPLICATION_INSTANCE_REFERENCE)) { + try (MutableStatusService statusRegistry = zkStatusService + .lockApplication(context, TestIds.APPLICATION_INSTANCE_REFERENCE)) { statusRegistry.setApplicationInstanceStatus(ApplicationInstanceStatus.NO_REMARKS); } assertThat( - zookeeperStatusService + zkStatusService .getApplicationInstanceStatus(TestIds.APPLICATION_INSTANCE_REFERENCE), is(ApplicationInstanceStatus.NO_REMARKS)); } @@ -269,20 +269,20 @@ public class ZookeeperStatusServiceTest { @Test public void suspending_two_applications_returns_two_applications() { Set<ApplicationInstanceReference> suspendedApps - = zookeeperStatusService.getAllSuspendedApplications(); + = zkStatusService.getAllSuspendedApplications(); assertThat(suspendedApps.size(), is(0)); - try (MutableStatusRegistry statusRegistry = zookeeperStatusService - .lockApplicationInstance_forCurrentThreadOnly(context, TestIds.APPLICATION_INSTANCE_REFERENCE)) { + try (MutableStatusService statusRegistry = zkStatusService + .lockApplication(context, TestIds.APPLICATION_INSTANCE_REFERENCE)) { statusRegistry.setApplicationInstanceStatus(ApplicationInstanceStatus.ALLOWED_TO_BE_DOWN); } - try (MutableStatusRegistry statusRegistry = zookeeperStatusService - .lockApplicationInstance_forCurrentThreadOnly(context, TestIds.APPLICATION_INSTANCE_REFERENCE2)) { + try (MutableStatusService statusRegistry = zkStatusService + .lockApplication(context, TestIds.APPLICATION_INSTANCE_REFERENCE2)) { statusRegistry.setApplicationInstanceStatus(ApplicationInstanceStatus.ALLOWED_TO_BE_DOWN); } - suspendedApps = zookeeperStatusService.getAllSuspendedApplications(); + suspendedApps = zkStatusService.getAllSuspendedApplications(); assertThat(suspendedApps.size(), is(2)); assertThat(suspendedApps, hasItem(TestIds.APPLICATION_INSTANCE_REFERENCE)); assertThat(suspendedApps, hasItem(TestIds.APPLICATION_INSTANCE_REFERENCE2)); |