public void setTargetVersion(NodeType nodeType, Version newTargetVersion, boolean force) {
        assertLegalNodeTypeForTargetVersion(nodeType);

        try (Lock lock = db.lockInfrastructureVersions()) {
            Map<NodeType, Version> infrastructureVersions = db.readInfrastructureVersions();
            Version currentTargetVersion = Optional.ofNullable(infrastructureVersions.get(nodeType))
                    .orElse(Version.emptyVersion);

            // Trying to set the version to the current version, skip
            if (currentTargetVersion.equals(newTargetVersion)) return;

            // If we don't force the set, we must set the new version to higher than the already set version
            if (!force && currentTargetVersion.isAfter(newTargetVersion)) {
                throw new IllegalArgumentException(String.format("Cannot downgrade version without setting 'force'. Current target version: %s, attempted to set target version: %s",
                        currentTargetVersion.toFullString(), newTargetVersion.toFullString()));
            }

            if (newTargetVersion.isEmpty()) {
                infrastructureVersions.remove(nodeType);
                logger.info("Removing target version for " + nodeType);
            } else {
                infrastructureVersions.put(nodeType, newTargetVersion);
                logger.info("Setting target version for " + nodeType + " to " + newTargetVersion.toFullString());
            }
            db.writeInfrastructureVersions(infrastructureVersions);
        }
    }
@Test
    public void can_only_set_version_on_certain_node_types() {
        // We can set version for config
        infrastructureVersions.setTargetVersion(NodeType.config, version, false);

        try {
            infrastructureVersions.setTargetVersion(NodeType.tenant, version, false);
            fail("Should not be able to set version for tenant nodes");
        } catch (IllegalArgumentException ignored) { }

        try {
            // Using 'force' does not help, force only applies to version downgrade
            infrastructureVersions.setTargetVersion(NodeType.tenant, version, true);
            fail("Should not be able to set version for tenant nodes");
        } catch (IllegalArgumentException ignored) { }
    }