Repository: aurora Updated Branches: refs/heads/master c9a71722c -> 3fbea09e5
Remove unused and deprecated code from commons. Testing Done: ./gradlew build -Pq Reviewed at https://reviews.apache.org/r/40510/ Project: http://git-wip-us.apache.org/repos/asf/aurora/repo Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/3fbea09e Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/3fbea09e Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/3fbea09e Branch: refs/heads/master Commit: 3fbea09e53b52e6559f16a0c27612f2c26b001a2 Parents: c9a7172 Author: Zameer Manji <[email protected]> Authored: Fri Nov 20 12:19:46 2015 -0800 Committer: Zameer Manji <[email protected]> Committed: Fri Nov 20 12:19:46 2015 -0800 ---------------------------------------------------------------------- .../common/net/InetSocketAddressHelper.java | 50 ------------- .../aurora/common/net/pool/DynamicHostSet.java | 19 +---- .../org/apache/aurora/common/thrift/Util.java | 75 -------------------- .../aurora/common/zookeeper/ServerSet.java | 36 +--------- .../aurora/common/zookeeper/ServerSetImpl.java | 32 --------- .../common/zookeeper/SingletonService.java | 67 +---------------- .../common/zookeeper/ZooKeeperClient.java | 2 +- .../log/mesos/MesosLogStreamModule.java | 2 +- 8 files changed, 10 insertions(+), 273 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/aurora/blob/3fbea09e/commons/src/main/java/org/apache/aurora/common/net/InetSocketAddressHelper.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/net/InetSocketAddressHelper.java b/commons/src/main/java/org/apache/aurora/common/net/InetSocketAddressHelper.java index 7e88b27..b3719d8 100644 --- a/commons/src/main/java/org/apache/aurora/common/net/InetSocketAddressHelper.java +++ b/commons/src/main/java/org/apache/aurora/common/net/InetSocketAddressHelper.java @@ -35,41 +35,6 @@ import java.util.Set; public final class InetSocketAddressHelper { /** - * A function that uses {@link #parse(String)} to map an endpoint spec to an - * {@link InetSocketAddress}. - */ - public static final Function<String, InetSocketAddress> STR_TO_INET = - new Function<String, InetSocketAddress>() { - @Override public InetSocketAddress apply(String value) { - return parse(value); - } - }; - - /** - * A function that uses {@link #getLocalAddress(int)} to map a local port number to an - * {@link InetSocketAddress}. - * If an {@link UnknownHostException} is thrown, it will be propagated as a - * {@link RuntimeException}. - */ - public static final Function<Integer, InetSocketAddress> INT_TO_INET = - new Function<Integer, InetSocketAddress>() { - @Override public InetSocketAddress apply(Integer port) { - try { - return getLocalAddress(port); - } catch (UnknownHostException e) { - throw Throwables.propagate(e); - } - } - }; - - public static final Function<InetSocketAddress, String> INET_TO_STR = - new Function<InetSocketAddress, String>() { - @Override public String apply(InetSocketAddress addr) { - return InetSocketAddressHelper.toString(addr); - } - }; - - /** * Attempts to parse an endpoint spec into an InetSocketAddress. * * @param value the endpoint spec @@ -115,22 +80,7 @@ public final class InetSocketAddressHelper { } } - public static InetSocketAddress getLocalAddress(int port) throws UnknownHostException { - String ipAddress = InetAddress.getLocalHost().getHostAddress(); - return new InetSocketAddress(ipAddress, port); - } - private InetSocketAddressHelper() { // utility } - - /** - * Converts backend definitions (in host:port form) a set of socket addresses. - * - * @param backends Backends to convert. - * @return Sockets representing the provided backends. - */ - public static Set<InetSocketAddress> convertToSockets(Iterable<String> backends) { - return Sets.newHashSet(Iterables.transform(backends, STR_TO_INET)); - } } http://git-wip-us.apache.org/repos/asf/aurora/blob/3fbea09e/commons/src/main/java/org/apache/aurora/common/net/pool/DynamicHostSet.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/net/pool/DynamicHostSet.java b/commons/src/main/java/org/apache/aurora/common/net/pool/DynamicHostSet.java index 93f6610..837d15c 100644 --- a/commons/src/main/java/org/apache/aurora/common/net/pool/DynamicHostSet.java +++ b/commons/src/main/java/org/apache/aurora/common/net/pool/DynamicHostSet.java @@ -31,29 +31,16 @@ public interface DynamicHostSet<T> { * changed. * * @param monitor the server set monitor to call back when the host set changes - * @throws MonitorException if there is a problem monitoring the host set - * @deprecated Deprecated in favor of {@link #watch(HostChangeMonitor)} - */ - @Deprecated - public void monitor(final HostChangeMonitor<T> monitor) throws MonitorException; - - /** - * Registers a monitor to receive change notices for this server set as long as this jvm process - * is alive. Blocks until the initial server set can be gathered and delivered to the monitor. - * The monitor will be notified if the membership set or parameters of existing members have - * changed. - * - * @param monitor the server set monitor to call back when the host set changes * @return A command which, when executed, will stop monitoring the host set. * @throws MonitorException if there is a problem monitoring the host set */ - public Command watch(final HostChangeMonitor<T> monitor) throws MonitorException; + Command watch(final HostChangeMonitor<T> monitor) throws MonitorException; /** * An interface to an object that is interested in receiving notification whenever the host set * changes. */ - public static interface HostChangeMonitor<T> { + interface HostChangeMonitor<T> { /** * Called when either the available set of services changes (when a service dies or a new @@ -64,7 +51,7 @@ public interface DynamicHostSet<T> { void onChange(ImmutableSet<T> hostSet); } - public static class MonitorException extends Exception { + class MonitorException extends Exception { public MonitorException(String msg) { super(msg); } http://git-wip-us.apache.org/repos/asf/aurora/blob/3fbea09e/commons/src/main/java/org/apache/aurora/common/thrift/Util.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/thrift/Util.java b/commons/src/main/java/org/apache/aurora/common/thrift/Util.java index 7802614..4ef7f49 100644 --- a/commons/src/main/java/org/apache/aurora/common/thrift/Util.java +++ b/commons/src/main/java/org/apache/aurora/common/thrift/Util.java @@ -13,18 +13,11 @@ */ package org.apache.aurora.common.thrift; -import java.net.InetSocketAddress; import java.util.List; import java.util.Map; import java.util.Set; -import javax.annotation.Nullable; - -import com.google.common.base.Function; import com.google.common.base.Joiner; -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import com.google.common.base.Predicate; import com.google.common.base.Strings; import com.google.common.collect.Lists; @@ -38,72 +31,6 @@ import org.apache.thrift.meta_data.FieldMetaData; * @author William Farner */ public class Util { - - /** - * Maps a {@link ServiceInstance} to an {@link InetSocketAddress} given the {@code endpointName}. - * - * @param optionalEndpointName the name of the end-point on the service's additional end-points, - * if not set, maps to the primary service end-point - */ - public static Function<ServiceInstance, InetSocketAddress> getAddress( - final Optional<String> optionalEndpointName) { - if (!optionalEndpointName.isPresent()) { - return GET_ADDRESS; - } - - final String endpointName = optionalEndpointName.get(); - return getAddress( - new Function<ServiceInstance, Endpoint>() { - @Override public Endpoint apply(@Nullable ServiceInstance serviceInstance) { - Map<String, Endpoint> endpoints = serviceInstance.getAdditionalEndpoints(); - Preconditions.checkArgument(endpoints.containsKey(endpointName), - "Did not find end-point %s on %s", endpointName, serviceInstance); - return endpoints.get(endpointName); - } - }); - } - - private static Function<ServiceInstance, InetSocketAddress> getAddress( - final Function<ServiceInstance, Endpoint> serviceToEndpoint) { - return new Function<ServiceInstance, InetSocketAddress>() { - @Override public InetSocketAddress apply(ServiceInstance serviceInstance) { - Endpoint endpoint = serviceToEndpoint.apply(serviceInstance); - return InetSocketAddress.createUnresolved(endpoint.getHost(), endpoint.getPort()); - } - }; - } - - private static Function<ServiceInstance, Endpoint> GET_PRIMARY_ENDPOINT = - new Function<ServiceInstance, Endpoint>() { - @Override public Endpoint apply(ServiceInstance input) { - return input.getServiceEndpoint(); - } - }; - - public static Function<ServiceInstance, InetSocketAddress> GET_ADDRESS = - getAddress(GET_PRIMARY_ENDPOINT); - - public static final Predicate<ServiceInstance> IS_ALIVE = new Predicate<ServiceInstance>() { - @Override public boolean apply(ServiceInstance serviceInstance) { - switch (serviceInstance.getStatus()) { - case ALIVE: - return true; - - // We'll be optimistic here and let MTCP's ranking deal with - // unhealthy services in a WARNING state. - case WARNING: - return true; - - // Services which are just starting up, on the other hand... are much easier to just not - // send requests to. The STARTING state is useful to distinguish from WARNING or ALIVE: - // you exist in ZooKeeper, but don't yet serve traffic. - case STARTING: - default: - return false; - } - } - }; - /** * Pretty-prints a thrift object contents. * @@ -139,8 +66,6 @@ public class Util { } } - private static final String METADATA_MAP_FIELD_NAME = "metaDataMap"; - /** * Prints a TBase. * http://git-wip-us.apache.org/repos/asf/aurora/blob/3fbea09e/commons/src/main/java/org/apache/aurora/common/zookeeper/ServerSet.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/zookeeper/ServerSet.java b/commons/src/main/java/org/apache/aurora/common/zookeeper/ServerSet.java index fb578e1..cfeac92 100644 --- a/commons/src/main/java/org/apache/aurora/common/zookeeper/ServerSet.java +++ b/commons/src/main/java/org/apache/aurora/common/zookeeper/ServerSet.java @@ -28,34 +28,16 @@ import java.util.Map; * TODO(William Farner): Explore decoupling this from thrift. */ public interface ServerSet extends DynamicHostSet<ServiceInstance> { - /** * Attempts to join a server set for this logical service group. * * @param endpoint the primary service endpoint * @param additionalEndpoints and additional endpoints keyed by their logical name - * @param status the current service status * @return an EndpointStatus object that allows the endpoint to adjust its status * @throws JoinException if there was a problem joining the server set * @throws InterruptedException if interrupted while waiting to join the server set - * @deprecated The status field is deprecated. Please use {@link #join(InetSocketAddress, Map)} */ - @Deprecated - public EndpointStatus join( - InetSocketAddress endpoint, - Map<String, InetSocketAddress> additionalEndpoints, - Status status) throws JoinException, InterruptedException; - - /** - * Attempts to join a server set for this logical service group. - * - * @param endpoint the primary service endpoint - * @param additionalEndpoints and additional endpoints keyed by their logical name - * @return an EndpointStatus object that allows the endpoint to adjust its status - * @throws JoinException if there was a problem joining the server set - * @throws InterruptedException if interrupted while waiting to join the server set - */ - public EndpointStatus join( + EndpointStatus join( InetSocketAddress endpoint, Map<String, InetSocketAddress> additionalEndpoints) throws JoinException, InterruptedException; @@ -78,19 +60,7 @@ public interface ServerSet extends DynamicHostSet<ServiceInstance> { /** * A handle to a service endpoint's status data that allows updating it to track current events. */ - public interface EndpointStatus { - - /** - * Attempts to update the status of the service endpoint associated with this endpoint. If the - * {@code status} is {@link Status#DEAD} then the endpoint will be removed from the server set. - * - * @param status the current status of the endpoint - * @throws UpdateException if there was a problem writing the update - * @deprecated Support for mutable status is deprecated. Please use {@link #leave()} - */ - @Deprecated - void update(Status status) throws UpdateException; - + interface EndpointStatus { /** * Removes the endpoint from the server set. * @@ -102,7 +72,7 @@ public interface ServerSet extends DynamicHostSet<ServiceInstance> { /** * Indicates an error updating a service's status information. */ - public static class UpdateException extends Exception { + class UpdateException extends Exception { public UpdateException(String message, Throwable cause) { super(message, cause); } http://git-wip-us.apache.org/repos/asf/aurora/blob/3fbea09e/commons/src/main/java/org/apache/aurora/common/zookeeper/ServerSetImpl.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/zookeeper/ServerSetImpl.java b/commons/src/main/java/org/apache/aurora/common/zookeeper/ServerSetImpl.java index 07ae383..bb6fbce 100644 --- a/commons/src/main/java/org/apache/aurora/common/zookeeper/ServerSetImpl.java +++ b/commons/src/main/java/org/apache/aurora/common/zookeeper/ServerSetImpl.java @@ -167,16 +167,6 @@ public class ServerSetImpl implements ServerSet { final Group.Membership membership = group.join(serviceInstanceSupplier); return new EndpointStatus() { - @Override public void update(Status status) throws UpdateException { - checkNotNull(status); - LOG.warning("This method is deprecated. Please use leave() instead."); - if (status == Status.DEAD) { - leave(); - } else { - LOG.warning("Status update has been ignored"); - } - } - @Override public void leave() throws UpdateException { memberStatus.leave(membership); } @@ -184,22 +174,6 @@ public class ServerSetImpl implements ServerSet { } @Override - public EndpointStatus join( - InetSocketAddress endpoint, - Map<String, InetSocketAddress> additionalEndpoints, - Status status) throws Group.JoinException, InterruptedException { - - LOG.warning("This method is deprecated. Please do not specify a status field."); - if (status != Status.ALIVE) { - LOG.severe("**************************************************************************\n" - + "WARNING: MUTABLE STATUS FIELDS ARE NO LONGER SUPPORTED.\n" - + "JOINING WITH STATUS ALIVE EVEN THOUGH YOU SPECIFIED " + status - + "\n**************************************************************************"); - } - return join(endpoint, additionalEndpoints); - } - - @Override public Command watch(HostChangeMonitor<ServiceInstance> monitor) throws MonitorException { ServerSetWatcher serverSetWatcher = new ServerSetWatcher(zkClient, monitor); try { @@ -211,12 +185,6 @@ public class ServerSetImpl implements ServerSet { } } - @Override - public void monitor(HostChangeMonitor<ServiceInstance> monitor) throws MonitorException { - LOG.warning("This method is deprecated. Please use watch instead."); - watch(monitor); - } - private class MemberStatus { private final InetSocketAddress endpoint; private final Map<String, InetSocketAddress> additionalEndpoints; http://git-wip-us.apache.org/repos/asf/aurora/blob/3fbea09e/commons/src/main/java/org/apache/aurora/common/zookeeper/SingletonService.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/zookeeper/SingletonService.java b/commons/src/main/java/org/apache/aurora/common/zookeeper/SingletonService.java index 110c9ef..231aa91 100644 --- a/commons/src/main/java/org/apache/aurora/common/zookeeper/SingletonService.java +++ b/commons/src/main/java/org/apache/aurora/common/zookeeper/SingletonService.java @@ -35,8 +35,6 @@ import org.apache.zookeeper.data.ACL; * the {@link ServerSet} at a time. */ public class SingletonService { - private static final Logger LOG = Logger.getLogger(SingletonService.class.getName()); - @VisibleForTesting static final String LEADER_ELECT_NODE_PREFIX = "singleton_candidate_"; @@ -61,32 +59,6 @@ public class SingletonService { private final Candidate candidate; /** - * Equivalent to {@link #SingletonService(ZooKeeperClient, String, Iterable)} with a default - * wide open {@code acl} ({@link ZooDefs.Ids#OPEN_ACL_UNSAFE}). - */ - public SingletonService(ZooKeeperClient zkClient, String servicePath) { - this(zkClient, servicePath, ZooDefs.Ids.OPEN_ACL_UNSAFE); - } - - /** - * Creates a new singleton service, identified by {@code servicePath}. All nodes related to the - * service (for both leader election and service registration) will live under the path and each - * node will be created with the supplied {@code acl}. Internally, two ZooKeeper {@code Group}s - * are used to manage a singleton service - one for leader election, and another for the - * {@code ServerSet} where the leader's endpoints are registered. Leadership election should - * guarantee that at most one instance will ever exist in the ServerSet at once. - * - * @param zkClient The ZooKeeper client to use. - * @param servicePath The path where service nodes live. - * @param acl The acl to apply to newly created candidate nodes and serverset nodes. - */ - public SingletonService(ZooKeeperClient zkClient, String servicePath, Iterable<ACL> acl) { - this( - new ServerSetImpl(zkClient, new Group(zkClient, acl, servicePath)), - createSingletonCandidate(zkClient, servicePath, acl)); - } - - /** * Creates a new singleton service that uses the supplied candidate to vie for leadership and then * advertises itself in the given server set once elected. * @@ -103,41 +75,6 @@ public class SingletonService { * * @param endpoint The primary endpoint to register as a leader candidate in the service. * @param additionalEndpoints Additional endpoints that are available on the host. - * @param status deprecated, will be ignored entirely - * @param listener Handler to call when the candidate is elected or defeated. - * @throws Group.WatchException If there was a problem watching the ZooKeeper group. - * @throws Group.JoinException If there was a problem joining the ZooKeeper group. - * @throws InterruptedException If the thread watching/joining the group was interrupted. - * @deprecated The status field is deprecated. Please use - * {@link #lead(InetSocketAddress, Map, LeadershipListener)} - */ - @Deprecated - public void lead(final InetSocketAddress endpoint, - final Map<String, InetSocketAddress> additionalEndpoints, - final Status status, - final LeadershipListener listener) - throws Group.WatchException, Group.JoinException, InterruptedException { - - if (status != Status.ALIVE) { - LOG.severe("******************************************************************************"); - LOG.severe("WARNING: MUTABLE STATUS FIELDS ARE NO LONGER SUPPORTED."); - LOG.severe("JOINING WITH STATUS ALIVE EVEN THOUGH YOU SPECIFIED " + status); - LOG.severe("******************************************************************************"); - } else { - LOG.warning("******************************************************************************"); - LOG.warning("WARNING: MUTABLE STATUS FIELDS ARE NO LONGER SUPPORTED."); - LOG.warning("Please use SingletonService.lead(InetSocketAddress, Map, LeadershipListener)"); - LOG.warning("******************************************************************************"); - } - - lead(endpoint, additionalEndpoints, listener); - } - - /** - * Attempts to lead the singleton service. - * - * @param endpoint The primary endpoint to register as a leader candidate in the service. - * @param additionalEndpoints Additional endpoints that are available on the host. * @param listener Handler to call when the candidate is elected or defeated. * @throws Group.WatchException If there was a problem watching the ZooKeeper group. * @throws Group.JoinException If there was a problem joining the ZooKeeper group. @@ -194,7 +131,7 @@ public class SingletonService { * * @param control A controller handle to advertise and/or leave advertised presence. */ - public void onLeading(LeaderControl control); + void onLeading(LeaderControl control); /** * Notifies the listener that it is no longer leader. The leader should take this opportunity @@ -202,7 +139,7 @@ public class SingletonService { * * @param status A handle on the endpoint status for the advertised leader. */ - public void onDefeated(@Nullable ServerSet.EndpointStatus status); + void onDefeated(@Nullable ServerSet.EndpointStatus status); } /** http://git-wip-us.apache.org/repos/asf/aurora/blob/3fbea09e/commons/src/main/java/org/apache/aurora/common/zookeeper/ZooKeeperClient.java ---------------------------------------------------------------------- diff --git a/commons/src/main/java/org/apache/aurora/common/zookeeper/ZooKeeperClient.java b/commons/src/main/java/org/apache/aurora/common/zookeeper/ZooKeeperClient.java index a032aa3..1761ab7 100644 --- a/commons/src/main/java/org/apache/aurora/common/zookeeper/ZooKeeperClient.java +++ b/commons/src/main/java/org/apache/aurora/common/zookeeper/ZooKeeperClient.java @@ -298,7 +298,7 @@ public class ZooKeeperClient { Iterable<String> servers = Iterables.transform(ImmutableSet.copyOf(zooKeeperServers), - InetSocketAddressHelper.INET_TO_STR); + InetSocketAddressHelper::toString); this.zooKeeperServers = Joiner.on(',').join(servers).concat(chrootPath.or("")); } http://git-wip-us.apache.org/repos/asf/aurora/blob/3fbea09e/src/main/java/org/apache/aurora/scheduler/log/mesos/MesosLogStreamModule.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/aurora/scheduler/log/mesos/MesosLogStreamModule.java b/src/main/java/org/apache/aurora/scheduler/log/mesos/MesosLogStreamModule.java index 377dbfd..64ab611 100644 --- a/src/main/java/org/apache/aurora/scheduler/log/mesos/MesosLogStreamModule.java +++ b/src/main/java/org/apache/aurora/scheduler/log/mesos/MesosLogStreamModule.java @@ -121,7 +121,7 @@ public class MesosLogStreamModule extends PrivateModule { } String zkConnectString = Joiner.on(',').join( - Iterables.transform(zkClientConfig.servers, InetSocketAddressHelper.INET_TO_STR)); + Iterables.transform(zkClientConfig.servers, InetSocketAddressHelper::toString)); PathUtils.validatePath(ZK_LOG_GROUP_PATH.get()); return new Log(
