<commit_before>package io.cattle.platform.core.addon.metadata;

import io.cattle.platform.core.addon.InstanceHealthCheck;
import io.cattle.platform.core.addon.LbConfig;
import io.cattle.platform.core.addon.Link;
import io.cattle.platform.core.addon.PortInstance;
import io.cattle.platform.core.constants.InstanceConstants;
import io.cattle.platform.core.constants.ServiceConstants;
import io.cattle.platform.core.model.Service;
import io.cattle.platform.core.util.ServiceUtil;
import io.cattle.platform.core.util.SystemLabels;
import io.cattle.platform.object.util.DataAccessor;
import io.cattle.platform.util.type.CollectionUtils;
import io.github.ibuildthecloud.gdapi.annotation.Field;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class ServiceInfo implements MetadataObject {

    long id;
    Long stackId;

    Integer scale;

    String environmentUuid;
    String fqdn;
    String token;
    String name;
    String uuid;
    String kind;
    String hostname;
    String vip;
    String state;
    String healthState;
    String selector;

    List<String> externalIps;
    List<String> sidekicks;
    Set<Long> instanceIds;
    Set<PortInstance> ports;
    List<Link> links;
    Map<String, String> labels;
    Map<String, Object> metadata;
    HealthcheckInfo healthCheck;
    LbConfig lbConfig;
    boolean global;

    public ServiceInfo(Service service) {
        this.id = service.getId();
        this.global = "true".equals(CollectionUtils.getNestedValue(service.getData(), "fields", "launchConfig", "labels",
                SystemLabels.LABEL_SERVICE_GLOBAL));
        this.stackId = service.getStackId();
        this.scale = DataAccessor.fieldInteger(service, ServiceConstants.FIELD_SCALE);
        this.fqdn = DataAccessor.fieldString(service, ServiceConstants.FIELD_FQDN);
        this.token = DataAccessor.fieldString(service, ServiceConstants.FIELD_TOKEN);
        this.name = service.getName();
        this.uuid = service.getUuid();
        this.kind = service.getKind();
        this.hostname = DataAccessor.fieldString(service, ServiceConstants.FIELD_HOSTNAME);
        this.healthState = service.getHealthState();
        this.externalIps = DataAccessor.fieldStringList(service, ServiceConstants.FIELD_EXTERNALIPS);
        this.sidekicks = ServiceUtil.getSidekickNames(service);
        this.ports = new HashSet<>(DataAccessor.fieldObjectList(service, ServiceConstants.FIELD_PUBLIC_ENDPOINTS, PortInstance.class));
        this.lbConfig = DataAccessor.field(service, ServiceConstants.FIELD_LB_CONFIG, LbConfig.class);
        this.links = DataAccessor.fieldObjectList(service, ServiceConstants.FIELD_SERVICE_LINKS, Link.class);
        this.labels = new HashMap<>();
        this.metadata = DataAccessor.fieldMapRO(service, ServiceConstants.FIELD_METADATA);<commit_msg>Labels to service metadata<commit_after>package io.cattle.platform.core.addon.metadata;

import io.cattle.platform.core.addon.InstanceHealthCheck;
import io.cattle.platform.core.addon.LbConfig;
import io.cattle.platform.core.addon.Link;
import io.cattle.platform.core.addon.PortInstance;
import io.cattle.platform.core.constants.InstanceConstants;
import io.cattle.platform.core.constants.ServiceConstants;
import io.cattle.platform.core.model.Service;
import io.cattle.platform.core.util.ServiceUtil;
import io.cattle.platform.core.util.SystemLabels;
import io.cattle.platform.object.util.DataAccessor;
import io.cattle.platform.util.type.CollectionUtils;

import io.github.ibuildthecloud.gdapi.annotation.Field;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class ServiceInfo implements MetadataObject {

    long id;
    Long stackId;

    Integer scale;

    String environmentUuid;
    String fqdn;
    String token;
    String name;
    String uuid;
    String kind;
    String hostname;
    String vip;
    String state;
    String healthState;
    String selector;

    List<String> externalIps;
    List<String> sidekicks;
    Set<Long> instanceIds;
    Set<PortInstance> ports;
    List<Link> links;
    Map<String, String> labels;
    Map<String, Object> metadata;
    HealthcheckInfo healthCheck;
    LbConfig lbConfig;
    boolean global;

    @SuppressWarnings("unchecked")
    public ServiceInfo(Service service) {
        this.id = service.getId();
        this.global = "true".equals(CollectionUtils.getNestedValue(service.getData(), "fields", "launchConfig", "labels",
                SystemLabels.LABEL_SERVICE_GLOBAL));
        this.stackId = service.getStackId();
        this.scale = DataAccessor.fieldInteger(service, ServiceConstants.FIELD_SCALE);
        this.fqdn = DataAccessor.fieldString(service, ServiceConstants.FIELD_FQDN);
        this.token = DataAccessor.fieldString(service, ServiceConstants.FIELD_TOKEN);
        this.name = service.getName();
        this.uuid = service.getUuid();
        this.kind = service.getKind();
        this.hostname = DataAccessor.fieldString(service, ServiceConstants.FIELD_HOSTNAME);
        this.healthState = service.getHealthState();
        this.externalIps = DataAccessor.fieldStringList(service, ServiceConstants.FIELD_EXTERNALIPS);
        this.sidekicks = ServiceUtil.getSidekickNames(service);
        this.ports = new HashSet<>(DataAccessor.fieldObjectList(service, ServiceConstants.FIELD_PUBLIC_ENDPOINTS, PortInstance.class));
        this.lbConfig = DataAccessor.field(service, ServiceConstants.FIELD_LB_CONFIG, LbConfig.class);
        this.links = DataAccessor.fieldObjectList(service, ServiceConstants.FIELD_SERVICE_LINKS, Link.class);
        Map<String, Object> lcData = ServiceUtil.getLaunchConfigDataAsMap(service, ServiceConstants.PRIMARY_LAUNCH_CONFIG_NAME);
        if (lcData.containsKey(InstanceConstants.FIELD_LABELS)) {
            this.labels = (HashMap<String, String>) lcData.get(InstanceConstants.FIELD_LABELS);
        } else {
            this.labels = new HashMap<String, String>();
        }
        this.metadata = DataAccessor.fieldMapRO(service, ServiceConstants.FIELD_METADATA);
{'fraction_non_alphanumeric': 0.10248901903367497, 'fraction_numerical': 0.0, 'mean_word_length': 4.106312292358804, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, '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': '5028703', 'n_tokens_mistral': 1781, 'n_tokens_neox': 1792, 'n_words': 312}