Limit HostSwitchUpdater to relevant systems
// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.maintenance;
+import com.yahoo.config.provision.SystemName;
import com.yahoo.vespa.hosted.controller.Controller;
import com.yahoo.vespa.hosted.controller.api.integration.configserver.Node;
import com.yahoo.vespa.hosted.controller.api.integration.configserver.NodeRepository;
@@ -8,8 +9,10 @@ import com.yahoo.vespa.hosted.controller.api.integration.entity.NodeEntity;
import com.yahoo.vespa.hosted.controller.api.integration.noderepository.NodeRepositoryNode;
import java.time.Duration;
+import java.util.EnumSet;
import java.util.Map;
import java.util.function.Function;
+import java.util.logging.Logger;
import java.util.stream.Collectors;
/**
@@ -19,10 +22,12 @@ import java.util.stream.Collectors;
*/
public class HostSwitchUpdater extends ControllerMaintainer {
+ private static final Logger log = Logger.getLogger(HostSwitchUpdater.class.getName());
+
private final NodeRepository nodeRepository;
public HostSwitchUpdater(Controller controller, Duration interval) {
- super(controller, interval);
+ super(controller, interval, null, EnumSet.of(SystemName.cd, SystemName.main));
this.nodeRepository = controller.serviceRegistry().configServer().nodeRepository();
}
@@ -31,6 +36,8 @@ public class HostSwitchUpdater extends ControllerMaintainer {
Map<String, NodeEntity> nodeEntities = controller().serviceRegistry().entityService().listNodes().stream()
.collect(Collectors.toMap(NodeEntity::hostname,
Function.identity()));
+ int nodesUpdated = 0;
+ try {
for (var zone : controller().zoneRegistry().zones().controllerUpgraded().all().ids()) {
for (var node : nodeRepository.list(zone)) {
NodeEntity nodeEntity = nodeEntities.get(node.hostname().value());
@@ -39,6 +46,12 @@ public class HostSwitchUpdater extends ControllerMaintainer {
NodeRepositoryNode updatedNode = new NodeRepositoryNode();
updatedNode.setSwitchHostname(nodeEntity.switchHostname().get());
nodeRepository.patchNode(zone, node.hostname().value(), updatedNode);
+ nodesUpdated++;
+ }
+ }
+ } finally {
+ if (nodesUpdated > 0) {
+ log.info("Updated switch hostname for " + nodesUpdated + " node(s)");
}
}
return true;
