<commit_before>// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.persistence;

import com.yahoo.component.Version;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.slime.ArrayTraverser;
import com.yahoo.slime.Cursor;
import com.yahoo.slime.Inspector;
import com.yahoo.slime.Slime;
import com.yahoo.vespa.hosted.controller.versions.DeploymentStatistics;
import com.yahoo.vespa.hosted.controller.versions.NodeVersions;
import com.yahoo.vespa.hosted.controller.versions.VersionStatus;
import com.yahoo.vespa.hosted.controller.versions.VespaVersion;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * Serializer for {@link VersionStatus}.
 *
 * @author mpolden
 */
public class VersionStatusSerializer {

    // WARNING: Since there are multiple servers in a ZooKeeper cluster and they upgrade one by one
    //          (and rewrite all nodes on startup), changes to the serialized format must be made
    //          such that what is serialized on version N+1 can be read by version N:
    //          - ADDING FIELDS: Always ok
    //          - REMOVING FIELDS: Stop reading the field first. Stop writing it on a later version.
    //          - CHANGING THE FORMAT OF A FIELD: Don't do it bro.

    // VersionStatus fields
    private static final String versionsField = "versions";

    // VespaVersion fields
    private static final String releaseCommitField = "releaseCommit";
    private static final String committedAtField = "releasedAt";
    private static final String isControllerVersionField = "isCurrentControllerVersion";
    private static final String isSystemVersionField = "isCurrentSystemVersion";
    private static final String isReleasedField = "isReleased";
    private static final String deploymentStatisticsField = "deploymentStatistics";
    private static final String confidenceField = "confidence";
    private static final String configServersField = "configServerHostnames";

    // NodeVersions fields<commit_msg>Remove unused field<commit_after>// Copyright 2019 Oath Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.vespa.hosted.controller.persistence;

import com.yahoo.component.Version;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.slime.ArrayTraverser;
import com.yahoo.slime.Cursor;
import com.yahoo.slime.Inspector;
import com.yahoo.slime.Slime;
import com.yahoo.vespa.hosted.controller.versions.DeploymentStatistics;
import com.yahoo.vespa.hosted.controller.versions.NodeVersions;
import com.yahoo.vespa.hosted.controller.versions.VersionStatus;
import com.yahoo.vespa.hosted.controller.versions.VespaVersion;

import java.time.Instant;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/**
 * Serializer for {@link VersionStatus}.
 *
 * @author mpolden
 */
public class VersionStatusSerializer {

    // WARNING: Since there are multiple servers in a ZooKeeper cluster and they upgrade one by one
    //          (and rewrite all nodes on startup), changes to the serialized format must be made
    //          such that what is serialized on version N+1 can be read by version N:
    //          - ADDING FIELDS: Always ok
    //          - REMOVING FIELDS: Stop reading the field first. Stop writing it on a later version.
    //          - CHANGING THE FORMAT OF A FIELD: Don't do it bro.

    // VersionStatus fields
    private static final String versionsField = "versions";

    // VespaVersion fields
    private static final String releaseCommitField = "releaseCommit";
    private static final String committedAtField = "releasedAt";
    private static final String isControllerVersionField = "isCurrentControllerVersion";
    private static final String isSystemVersionField = "isCurrentSystemVersion";
    private static final String isReleasedField = "isReleased";
    private static final String deploymentStatisticsField = "deploymentStatistics";
    private static final String confidenceField = "confidence";

    // NodeVersions fields
{'fraction_non_alphanumeric': 0.07803065490013934, 'fraction_numerical': 0.003251277287505806, 'mean_word_length': 3.9166666666666665, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6024425', 'n_tokens_mistral': 1170, 'n_tokens_neox': 1119, 'n_words': 385}