class PackageVersionChecker {

    public CheckResult checkInstancesHaveAllMandatoryPackageVersion(Set<InstanceMetaData> instanceMetaDataSet) {
        Map<String, List<String>> instancesWithMissingPackageVersions = instanceMetadataUpdater.collectInstancesWithMissingPackageVersions(instanceMetaDataSet);
        if (!instancesWithMissingPackageVersions.isEmpty()) {
            String message = messagesService.getMessage(CLUSTER_PACKAGE_VERSIONS_ON_INSTANCES_ARE_MISSING.getMessage(),
                    Collections.singletonList(instancesWithMissingPackageVersions.entrySet().stream()
                            .map(entry -> String.format("Instance ID: [%s] Packages without version: [%s]",
                                    entry.getKey(), StringUtils.join(entry.getValue(), ",")))
                            .collect(Collectors.joining(" * "))));
            return CheckResult.failed(message);
        }
        return CheckResult.ok();
    }

}