Skip to content

Commit b63677e

Browse files
committed
cells: remove backward compatibility 7.0
Motivation: The initial implementation of tls support cell tunneling used `/dcache/lm/core-config` file to flag dcache to start inter-cell tunnels in plain of tls modes. This have been later replaces with urls syntax tcp:// and tls://. The old code left in place for backward compatibility, so, time to drop. Modification: Remove handling of `/dcache/lm/core-config` ZK node. Removed commands `get/set core-config` Result: Less dead code. Acked-by: Lea Morschel Target: master Require-book: no Require-notes: yes
1 parent 69f5c77 commit b63677e

File tree

1 file changed

+10
-207
lines changed

1 file changed

+10
-207
lines changed

modules/cells/src/main/java/dmg/cells/services/LocationManager.java

Lines changed: 10 additions & 207 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* dCache - http://www.dcache.org/
33
*
4-
* Copyright (C) 2016 - 2021 Deutsches Elektronen-Synchrotron
4+
* Copyright (C) 2016 - 2024 Deutsches Elektronen-Synchrotron
55
*
66
* This program is free software: you can redistribute it and/or modify
77
* it under the terms of the GNU Affero General Public License as
@@ -20,12 +20,8 @@
2020
package dmg.cells.services;
2121

2222
import static com.google.common.base.Preconditions.checkArgument;
23-
import static java.nio.charset.StandardCharsets.UTF_8;
2423

25-
import com.google.common.base.Joiner;
2624
import com.google.common.collect.ImmutableMap;
27-
import com.google.common.collect.ImmutableSet;
28-
import com.google.common.collect.Sets;
2925
import com.google.common.net.HostAndPort;
3026
import dmg.cells.network.LocationManagerConnector;
3127
import dmg.cells.nucleus.CellAdapter;
@@ -36,15 +32,13 @@
3632
import dmg.cells.zookeeper.LmPersistentNode;
3733
import dmg.cells.zookeeper.LmPersistentNode.PersistentNodeException;
3834
import dmg.util.CommandException;
39-
import dmg.util.command.Argument;
4035
import dmg.util.command.Command;
4136
import java.io.ByteArrayInputStream;
4237
import java.io.ByteArrayOutputStream;
4338
import java.io.Closeable;
4439
import java.io.DataInputStream;
4540
import java.io.DataOutputStream;
4641
import java.io.IOException;
47-
import java.net.InetAddress;
4842
import java.net.URI;
4943
import java.net.UnknownHostException;
5044
import java.util.Arrays;
@@ -57,21 +51,15 @@
5751
import java.util.Set;
5852
import java.util.concurrent.Callable;
5953
import java.util.concurrent.ExecutionException;
60-
import java.util.function.BiConsumer;
6154
import java.util.function.Consumer;
6255
import java.util.stream.Collectors;
6356
import javax.net.SocketFactory;
6457
import org.apache.curator.framework.CuratorFramework;
6558
import org.apache.curator.framework.recipes.cache.ChildData;
66-
import org.apache.curator.framework.recipes.cache.NodeCache;
67-
import org.apache.curator.framework.recipes.cache.NodeCacheListener;
6859
import org.apache.curator.framework.recipes.cache.PathChildrenCache;
6960
import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent;
7061
import org.apache.curator.utils.CloseableUtils;
7162
import org.apache.curator.utils.ZKPaths;
72-
import org.apache.zookeeper.CreateMode;
73-
import org.apache.zookeeper.KeeperException.ConnectionLossException;
74-
import org.apache.zookeeper.data.Stat;
7563
import org.dcache.ssl.CanlSslSocketCreator;
7664
import org.dcache.util.Args;
7765
import org.dcache.util.ColumnWriter;
@@ -88,10 +76,8 @@ public class LocationManager extends CellAdapter {
8876
LoggerFactory.getLogger(LocationManager.class);
8977

9078
private static final String ZK_CORES_URI = "/dcache/lm/cores-uri";
91-
private static final String ZK_CORE_CONFIG = "/dcache/lm/core-config";
9279

9380
private final CoreDomains coreDomains;
94-
private final CoreConfig coreConfig;
9581
private final Args args;
9682
private final CellDomainRole role;
9783
private final Client client;
@@ -137,10 +123,6 @@ enum Mode {
137123

138124
private final String _mode;
139125

140-
private static final ImmutableSet<Mode> tls = ImmutableSet.of(Mode.TLS);
141-
private static final ImmutableSet<Mode> plain = ImmutableSet.of(Mode.PLAIN);
142-
private static final ImmutableSet<Mode> plainAndTls = ImmutableSet.of(Mode.PLAIN, Mode.TLS);
143-
144126
Mode(String mode) {
145127
_mode = mode;
146128
}
@@ -154,17 +136,6 @@ public String getMode() {
154136
return this._mode;
155137
}
156138

157-
public Set<Mode> getModeAsSet() {
158-
switch (this) {
159-
case PLAIN_TLS:
160-
return plainAndTls;
161-
case TLS:
162-
return tls;
163-
default:
164-
return plain;
165-
}
166-
}
167-
168139
public static Mode fromString(String mode) {
169140
String m = filterAndSort(mode);
170141

@@ -176,17 +147,6 @@ public static Mode fromString(String mode) {
176147
throw new IllegalArgumentException("No Mode of type: " + mode);
177148
}
178149

179-
public static boolean isValid(String mode) {
180-
String m = filterAndSort(mode);
181-
182-
for (Mode b : Mode.values()) {
183-
if (b._mode.equalsIgnoreCase(m)) {
184-
return true;
185-
}
186-
}
187-
return false;
188-
}
189-
190150
private static String filterAndSort(String mode) {
191151
return Arrays.stream(mode.split(","))
192152
.map(String::trim)
@@ -394,102 +354,6 @@ Map<String, CoreDomainInfo> cores() {
394354
}
395355
}
396356

397-
private class CoreConfig implements NodeCacheListener, Closeable {
398-
399-
private final CuratorFramework _curator;
400-
401-
/**
402-
* Current modes extracted from the CoreDomain configuration.
403-
*/
404-
private Mode _mode = Mode.PLAIN;
405-
406-
/**
407-
* Cache of the ZooKeeper node identified by {@code _node}.
408-
*/
409-
private final NodeCache _cache;
410-
411-
/**
412-
* Stat of the last value loaded from the ZooKeeper node identified by {@code _node}.
413-
*/
414-
private Stat _current;
415-
416-
/**
417-
* Callable to reset the CoreDomains when a change in config is detected
418-
*/
419-
private final BiConsumer<Mode, State> _reset;
420-
421-
CoreConfig(CuratorFramework curator, BiConsumer<Mode, State> f) {
422-
_curator = curator;
423-
_cache = new NodeCache(_curator, ZK_CORE_CONFIG);
424-
_reset = f;
425-
}
426-
427-
public Mode getMode() {
428-
return _mode;
429-
}
430-
431-
synchronized void start() throws Exception {
432-
_cache.getListenable().addListener(this);
433-
try {
434-
_cache.start(true);
435-
apply(_cache.getCurrentData());
436-
} catch (ConnectionLossException e) {
437-
LOGGER.warn(
438-
"Failed to connect to zookeeper, using mode {} until connection reestablished",
439-
_mode);
440-
}
441-
}
442-
443-
private void apply(ChildData currentData) {
444-
if (currentData == null) {
445-
_current = null;
446-
_mode = Mode.PLAIN;
447-
LOGGER.info(
448-
"CoreDomain config node " + ZK_CORE_CONFIG + " not present; assuming mode {}",
449-
_mode);
450-
} else if (_current == null
451-
|| currentData.getStat().getVersion() > _current.getVersion()) {
452-
_mode = Mode.fromString(new String(currentData.getData(), UTF_8));
453-
LOGGER.info("CoreDomain config node " + ZK_CORE_CONFIG + " switching to mode {}",
454-
_mode);
455-
_current = currentData.getStat();
456-
} else {
457-
LOGGER.info(
458-
"Ignoring spurious CoreDomain config node " + ZK_CORE_CONFIG + " updated");
459-
}
460-
}
461-
462-
@Override
463-
public synchronized void nodeChanged() throws Exception {
464-
Set<Mode> oldModes = _mode.getModeAsSet();
465-
apply(_cache.getCurrentData());
466-
Set<Mode> curModes = _mode.getModeAsSet();
467-
468-
// old cur down up
469-
// none,tls - tls = none
470-
// none,tls - none = tls
471-
// none - tls = none tls
472-
// tls - none = tls none
473-
// none - none,tls = tls
474-
// tls - none,tls = none
475-
476-
Set<Mode> up = Sets.difference(curModes, oldModes).copyInto(new HashSet<>());
477-
LOGGER.info("Following modes from CoreDomain are being brought up: [{}]",
478-
Joiner.on(',').join(up));
479-
up.stream().forEach(u -> _reset.accept(u, State.BRING_UP));
480-
481-
Set<Mode> down = Sets.difference(oldModes, curModes).copyInto(new HashSet<>());
482-
LOGGER.info("Following modes from CoreDomain are being taken down: [{}]",
483-
Joiner.on(',').join(down));
484-
down.stream().forEach(d -> _reset.accept(d, State.TEAR_DOWN));
485-
}
486-
487-
@Override
488-
public void close() {
489-
CloseableUtils.closeQuietly(_cache);
490-
}
491-
}
492-
493357
/**
494358
* Client component of the location manager for satellite domains.
495359
* <p>
@@ -607,16 +471,21 @@ public class CoreClient extends Client {
607471

608472
private LoginManager lmTls;
609473
private LoginManager lmPlain;
474+
private final Mode connectionType;
610475
private volatile CoreDomainInfo info = new CoreDomainInfo();
611476

477+
public CoreClient(Mode connectionType) {
478+
this.connectionType = connectionType;
479+
}
480+
612481
@Override
613482
protected boolean shouldConnectTo(String domain) {
614483
return domain.compareTo(getCellDomainName()) < 0;
615484
}
616485

617486
@Override
618487
public void start() throws Exception {
619-
switch (coreConfig.getMode()) {
488+
switch (connectionType) {
620489
case PLAIN:
621490
startListenerWithTcp();
622491
break;
@@ -628,16 +497,11 @@ public void start() throws Exception {
628497
break;
629498
default:
630499
throw new IllegalArgumentException(
631-
"Mode " + coreConfig.getMode() + "not supported for Core Domain");
500+
"Mode " + connectionType + "not supported for Core Domain");
632501
}
633502
coreDomains.setCoreDomainInfoUri(info);
634503
}
635504

636-
@Override
637-
public void close() {
638-
coreConfig.close();
639-
}
640-
641505
@Override
642506
public synchronized void reset(Mode mode, State state) {
643507
try {
@@ -737,6 +601,7 @@ public LocationManager(String name, String args)
737601
super(name, "System", args);
738602
this.args = getArgs();
739603

604+
Mode connectionType = Mode.fromString(this.args.getOption("mode"));
740605
coreDomains = CoreDomains.createWithMode(getCellDomainName(), getCuratorFramework(),
741606
this.args.getOpt("mode"));
742607

@@ -745,30 +610,24 @@ public LocationManager(String name, String args)
745610
switch (role) {
746611
case CORE:
747612
checkArgument(this.args.argc() >= 1, "Listening port is required.");
748-
client = new CoreClient();
613+
client = new CoreClient(connectionType);
749614
coreDomains.onChange(client::update);
750-
coreConfig = new CoreConfig(getCuratorFramework(), client::reset);
751615
break;
752616
default:
753617
client = new Client();
754618
coreDomains.onChange(client::update);
755-
coreConfig = null;
756619
break;
757620
}
758621
} else {
759622
role = null;
760623
client = null;
761-
coreConfig = null;
762624
}
763625
}
764626

765627
@Override
766628
protected void started() {
767629
try {
768630
coreDomains.start();
769-
if (coreConfig != null) {
770-
coreConfig.start();
771-
}
772631
if (client != null) {
773632
client.start();
774633
}
@@ -906,60 +765,4 @@ public String call() {
906765
return writer.toString();
907766
}
908767
}
909-
910-
@Command(name = "set core-config", hint = "set operating mode for CoreDomain",
911-
description = "Specify the mode to be none, tls or none,tls in which the CoreDomain should run")
912-
class SetCoreConfigCommand implements Callable<String> {
913-
914-
@Argument(index = 0,
915-
usage = "Mode in which CoreDomain should run.")
916-
String _modes;
917-
918-
@Override
919-
public synchronized String call() throws Exception {
920-
CuratorFramework curator = getCuratorFramework();
921-
Set<String> modes = Sets.newHashSet(_modes.split(","))
922-
.stream()
923-
.map(String::trim)
924-
.filter(s -> !s.isEmpty())
925-
.collect(Collectors.toSet());
926-
927-
if (modes.stream().allMatch(Mode::isValid)) {
928-
String config = Joiner.on(",").join(modes);
929-
byte[] data = config.getBytes(UTF_8);
930-
931-
if (curator.checkExists().forPath(ZK_CORE_CONFIG) != null) {
932-
curator.setData()
933-
.forPath(ZK_CORE_CONFIG, data);
934-
} else {
935-
curator.create()
936-
.creatingParentContainersIfNeeded()
937-
.withMode(CreateMode.PERSISTENT)
938-
.forPath(ZK_CORE_CONFIG, data);
939-
}
940-
941-
if (Arrays.equals(curator.getData().forPath(ZK_CORE_CONFIG), data)) {
942-
return "Successfully updated CoreDomain mode configuration to " + config;
943-
} else {
944-
return "Could not change CoreDomain configuration to " + config;
945-
}
946-
}
947-
948-
throw new BadConfigException("Invalid Modes provided for CoreDomain configuration. " +
949-
"Valid modes are \"none\", \"tls\" or \"none,tls\"");
950-
}
951-
}
952-
953-
@Command(name = "get core-config", hint = "get current mode of operation for CoreDomain",
954-
description =
955-
"Get the current operating modes of the CoreDomain. It should be one of the following "
956-
+
957-
"\"none\", \"tls\" or \"none,tls\".")
958-
class GetCoreConfigCommand implements Callable<String> {
959-
960-
@Override
961-
public String call() throws Exception {
962-
return new String(getCuratorFramework().getData().forPath(ZK_CORE_CONFIG), UTF_8);
963-
}
964-
}
965768
}

0 commit comments

Comments
 (0)