class CloudFileSystemViewProvider {

    public Optional<CloudFileSystemView> getCloudFileSystemView(FileSystem fileSystem,
            Map<String, Set<String>> componentsByHostGroup, InstanceGroup instanceGroup) {
        Optional<CloudFileSystemView> fileSystemView;
        if (fileSystem != null) {
            SpiFileSystem spiFileSystem = fileSystemConverter.fileSystemToSpi(fileSystem);
            Set<String> components = componentsByHostGroup.get(instanceGroup.getGroupName());
            CloudIdentityType identityType = cloudIdentityTypeDecider.getIdentityType(components);
            if (identityType == CloudIdentityType.ID_BROKER) {
                instanceGroupService.setCloudIdentityType(instanceGroup, CloudIdentityType.ID_BROKER);
                fileSystemView = spiFileSystem.getCloudFileSystems().stream()
                        .filter(cloudFileSystemView -> CloudIdentityType.ID_BROKER.equals(cloudFileSystemView.getCloudIdentityType()))
                        .findFirst();
            } else {
                instanceGroupService.setCloudIdentityType(instanceGroup, CloudIdentityType.LOG);
                fileSystemView = spiFileSystem.getCloudFileSystems().stream()
                        .filter(cloudFileSystemView -> CloudIdentityType.LOG.equals(cloudFileSystemView.getCloudIdentityType()))
                        .findFirst();
            }
        } else {
            fileSystemView = Optional.empty();
        }
        return fileSystemView;
    }

}