class ClusterConfigTypeValidator implements TopologyValidator {

  @Override
  public void validate(ClusterTopology topology) throws InvalidTopologyException {

    // config types in from the request / configuration is always set in the request instance
    Set<String> topologyClusterConfigTypes = new HashSet(topology.getConfiguration().getAllConfigTypes());
    LOGGER.debug("Cluster config types: {}", topologyClusterConfigTypes);

    if (topologyClusterConfigTypes.isEmpty()) {
      LOGGER.debug("No config types to be checked.");
      return;
    }

    // collecting all config types for services in the blueprint (from the related stack)
    Set<String> stackServiceConfigTypes = new HashSet<>();
    for (String serviceName : topology.getBlueprint().getServices()) {
      stackServiceConfigTypes.addAll(topology.getBlueprint().getStack().getConfigurationTypes(serviceName));
    }

    // identifying invalid config types
    Set<String> configTypeIntersection = new HashSet<>(topologyClusterConfigTypes);

    if (configTypeIntersection.retainAll(stackServiceConfigTypes)) {
      // there are config types not present in the stack for the services listed in the blueprint

      // get the wrong  config types
      Set<String> invalidConfigTypes = new HashSet<>(topologyClusterConfigTypes);
      invalidConfigTypes.removeAll(configTypeIntersection);

      LOGGER.error("The following config typess are wrong: {}", invalidConfigTypes);
      throw new InvalidTopologyException("The following configuration types are invalid: " + invalidConfigTypes);
    }
  }

}