<commit_before>package io.cattle.platform.configitem.server.model.impl;

import static io.cattle.platform.core.model.tables.InstanceTable.*;
import io.cattle.platform.archaius.util.ArchaiusUtil;
import io.cattle.platform.configitem.context.impl.ServiceMetadataInfoFactory;
import io.cattle.platform.configitem.server.model.Request;
import io.cattle.platform.configitem.version.ConfigItemStatusManager;
import io.cattle.platform.core.constants.InstanceConstants;
import io.cattle.platform.core.model.Instance;
import io.cattle.platform.docker.client.DockerImage;
import io.cattle.platform.object.ObjectManager;
import io.cattle.platform.object.util.DataAccessor;

import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.tuple.Pair;

import com.netflix.config.DynamicStringProperty;

public class MetadataConfigItem extends AbstractConfigItem {

    public static final String ITEM = "metadata-answers";
    DynamicStringProperty METADATA_IMAGE_VERSION = ArchaiusUtil.getString("metadata.instance.image");

    ObjectManager objectManager;
    ServiceMetadataInfoFactory factory;
    String sourceRevision;

    public MetadataConfigItem(ObjectManager objectManager, ServiceMetadataInfoFactory factory, ConfigItemStatusManager versionManager) throws IOException {
        super(ITEM, versionManager);
        this.factory = factory;
        this.objectManager = objectManager;
        try(InputStream is = ServiceMetadataInfoFactory.class.getResourceAsStream(ServiceMetadataInfoFactory.class.getSimpleName() + ".class")) {
            sourceRevision = Hex.encodeHexString(DigestUtils.md5(is));
        }
    }

    @Override
    public void handleRequest(Request req) throws IOException {
        Instance instance = objectManager.findAny(Instance.class,
                INSTANCE.AGENT_ID, req.getClient().getResourceId());
        if (instance == null) {
            return;
        }

        // serve 404 to old metadata containers
        String defaultImageUUID = METADATA_IMAGE_VERSION.get();
        String imageUUID = DataAccessor.fieldString(instance, InstanceConstants.FIELD_IMAGE_UUID).toString();
        Pair<Long, Long> defaultMajorMinor = getMajorAndMinorVersion(defaultImageUUID);
        Pair<Long, Long> majorMinor = getMajorAndMinorVersion(imageUUID);
        
        boolean returnNothing = false;
        
        if (majorMinor.getLeft() == null || majorMinor.getRight() == null) {
            returnNothing = true;
        } else if (majorMinor.getLeft().longValue() <= majorMinor.getLeft().longValue()<commit_msg>If there is no major/minor number then still send metadata<commit_after>package io.cattle.platform.configitem.server.model.impl;

import static io.cattle.platform.core.model.tables.InstanceTable.*;
import io.cattle.platform.archaius.util.ArchaiusUtil;
import io.cattle.platform.configitem.context.impl.ServiceMetadataInfoFactory;
import io.cattle.platform.configitem.server.model.Request;
import io.cattle.platform.configitem.version.ConfigItemStatusManager;
import io.cattle.platform.core.constants.InstanceConstants;
import io.cattle.platform.core.model.Instance;
import io.cattle.platform.docker.client.DockerImage;
import io.cattle.platform.object.ObjectManager;
import io.cattle.platform.object.util.DataAccessor;

import java.io.IOException;
import java.io.InputStream;

import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang3.tuple.Pair;

import com.netflix.config.DynamicStringProperty;

public class MetadataConfigItem extends AbstractConfigItem {

    public static final String ITEM = "metadata-answers";
    DynamicStringProperty METADATA_IMAGE_VERSION = ArchaiusUtil.getString("metadata.instance.image");

    ObjectManager objectManager;
    ServiceMetadataInfoFactory factory;
    String sourceRevision;

    public MetadataConfigItem(ObjectManager objectManager, ServiceMetadataInfoFactory factory, ConfigItemStatusManager versionManager) throws IOException {
        super(ITEM, versionManager);
        this.factory = factory;
        this.objectManager = objectManager;
        try(InputStream is = ServiceMetadataInfoFactory.class.getResourceAsStream(ServiceMetadataInfoFactory.class.getSimpleName() + ".class")) {
            sourceRevision = Hex.encodeHexString(DigestUtils.md5(is));
        }
    }

    @Override
    public void handleRequest(Request req) throws IOException {
        Instance instance = objectManager.findAny(Instance.class,
                INSTANCE.AGENT_ID, req.getClient().getResourceId());
        if (instance == null) {
            return;
        }

        // serve 404 to old metadata containers
        String defaultImageUUID = METADATA_IMAGE_VERSION.get();
        String imageUUID = DataAccessor.fieldString(instance, InstanceConstants.FIELD_IMAGE_UUID).toString();
        Pair<Long, Long> defaultMajorMinor = getMajorAndMinorVersion(defaultImageUUID);
        Pair<Long, Long> majorMinor = getMajorAndMinorVersion(imageUUID);
        
        boolean returnNothing = false;
        
        if (majorMinor.getLeft() == null || majorMinor.getRight() == null) {
            returnNothing = false;
        } else if (majorMinor.getLeft().longValue() <= majorMinor.getLeft().longValue()
{'fraction_non_alphanumeric': 0.09430803571428571, 'fraction_numerical': 0.0018601190476190475, 'mean_word_length': 4.205227492739594, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6749704', 'n_tokens_mistral': 1473, 'n_tokens_neox': 1435, 'n_words': 262}