<!DOCTYPE html>
{% load staticfiles %}
<html>
<head>
    <link rel="icon" href="{% static 'favicon.ico' %}" type="image/x-icon">
    <title>Deploy {{ service }}</title>
    <link href="https://yandex.st/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />
    <link href="{% static 'css/navigation.css' %}" rel="stylesheet" />
    <link href="{% static 'css/font-awesome.min.css' %}" rel="stylesheet"/>
</head>
    <script src="https://yandex.st/jquery/2.0.3/jquery.min.js" type="text/javascript"></script>
    <script src="https://yandex.st/bootstrap/3.3.4/js/bootstrap.min.js" type="text/javascript"></script>
    <script type='text/javascript' src="{% static 'js/xmlhttp.js' %}"></script>
    <script type='text/javascript' src="{% static 'js/data_load.js' %}"></script>
<style>
    .btn-main-link {
        background-color: #FF9800;
    }
    .btn-main-link:after {
        border-left-color: #FF9800;
    }
    .page-title {
        color: #04766b;
        cursor: pointer;
    }
    .nav-service-link {
        color: #624444;
    }
    .nav-service-div {
        border-right: 2px solid beige;
    }
    .task-div {
        cursor: pointer;
        color: darkslategrey;
        text-decoration: underline;
    }
    .actions-div {
        border: 2px solid #feeac5;
        border-radius: 5px;
    }
    td {
        border: 2px solid white;
    }
</style>
<script type='text/javascript'>
    const ctype = '{{ ctype }}';
    const service = '{{ service }}';

    let current_tasks = {};
    let cached_tasks = {};

    let selected_slots = {};
    let selected_unused_slots = {};
    let selected_absent_slots = {};
    let selected_endpointsets = {};
    let free_slots_upd_started = false;

    const tasks_updates = {
        answer_id: 'tasks_list_answer',
        hr_legend: 'deploy tasks',
        url: '{% url "deploy_tasks" %}?ctype=' + ctype + '&service=' + service,
        on_load: update_tasks
    };

    function new_task_got(task_id) {
        task_id = task_id.trim();
        cached_tasks[task_id] = 'yours';
        start_task_watch(task_id);
    }

    function deploy(service_type) {
        let url = '{% url "deploy_do" %}?service=' + service + '&ctype=' + ctype;
        url += '&service_type=' + service_type;
        if (document.getElementById('only_save_chbox').checked) {
            url += '&slots=[]';
        }
        if (document.getElementById('only_diff_chbox').checked && !document.getElementById('only_save_chbox').checked) {
            url += '&diff_only=true';
        }
        document.getElementById('on-deploy-state').innerText = 'deploying...';
        let xmlhttp = getXmlHttp();
        xmlhttp.open('GET', url);
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState === 4) {
                if (xmlhttp.status === 200) {
                    try {
                        let res = JSON.parse(xmlhttp.responseText);
                        if (res['success']) {
                            console.log(xmlhttp.responseText);
                            let task_id = res['ans'];
                            new_task_got(task_id);
                        } else {
                            console.log(xmlhttp.responseText);
                        }
                        document.getElementById('on-deploy-state').innerText = '';
                    } catch(err) {
                        console.log(err);
                        document.getElementById('on-deploy-state').innerText = 'error ' + err;
                    }
                } else {
                    console.log('not 200 ' + xmlhttp.responseText);
                    document.getElementById('on-deploy-state').innerText = xmlhttp.responseText;
                }
            }
        };
        xmlhttp.send();
    }

    function cancel_task(task_id) {
        let url = '{% url "deploy_cancel" %}?task_id=' + encodeURIComponent(task_id);
        let load_cb = {
            url: url, do_once_any_case: true,
            answer_id: 'cancel-' + task_id, on_load: function(res){ console.log(res); }};
        do_data_load(load_cb);
    }

    function update_tasks(res) {
        current_tasks = res['ans'];

        try {
            let tb_el = document.getElementById('deploy_tasks');
            let trs = document.createElement('table');
            let show_tasks = {};
            for (let tid in cached_tasks) {
                show_tasks[tid] = cached_tasks[tid];
            }
            for (let tid in current_tasks['active']) {
                if (!current_tasks['active'].hasOwnProperty(tid)) { continue; }
                show_tasks[tid] = current_tasks['active'][tid];
            }
            for (let tid in show_tasks) {
                if (!show_tasks.hasOwnProperty(tid)) { continue; }
                let ttr = document.createElement('tr');
                let td_id = document.createElement('td');
                td_id.innerHTML = tid;
                td_id.className = 'task-div';
                td_id.onclick = function() {
                    let evt = new CustomEvent('taskattach', {detail: {task_id: tid}});
                    window.dispatchEvent(evt);
                };
                ttr.appendChild(td_id);
                let td_st = document.createElement('td');
                td_st.innerHTML = show_tasks[tid];
                let ext_link = document.createElement('a');
                ext_link.innerHTML = ' ';
                ext_link.href = '{% url "deploy_trace" %}?task_id=' + encodeURIComponent(tid);
                ext_link.target = '_blank';
                let ext_link_ic = document.createElement('i');
                ext_link_ic.className = 'fa fa-external-link';
                ext_link.appendChild(ext_link_ic);
                td_st.appendChild(ext_link);
                let cancel_btn = document.createElement('button');
                cancel_btn.innerHTML = 'Cancel';
                cancel_btn.onclick = function() { cancel_task(tid) };
                let canc_info_el = document.createElement('span');
                canc_info_el.id = 'cancel-' + tid;
                td_st.appendChild(cancel_btn);
                td_st.appendChild(canc_info_el);
                ttr.appendChild(td_st);
                trs.appendChild(ttr);
            }

            tb_el.innerHTML = '';
            tb_el.appendChild(trs);
        } catch(err) { console.log(err); }
    }

    function do_fill_tags_info(res) {
        if (res.hasOwnProperty('code') && res['code'] === 404) {
            //console.log('404');
            document.getElementById('nanny-send-button').disabled = false;
            setTimeout(do_set_answer, 500, statuses.hidden, 'no tags info', 'tags-info-answer');
            return;
        }
        try {
            let nannys = '';
            for (let i=0; i<res['ans']['nanny_services'].length; ++i) {
                if (i>0) { nannys += ','; }
                nannys += res['ans']['nanny_services'][i].split('@')[0];
            }
            let endpoint_sets = res['ans'].hasOwnProperty('endpointsets') ? res['ans']['endpointsets'].join(',') : '';
            let use_containers = res['ans']['use_container_names'];
            document.getElementById('nanny-service-input').value = nannys;
            document.getElementById('nanny-endpointsets').value = endpoint_sets;
            document.getElementById('nanny-use-containers').checked = use_containers;
            document.getElementById('nanny-send-button').disabled = false;
            document.getElementById('nanny-service-link').href = 'https://nanny.yandex-team.ru/ui/#/services/catalog/'
                + nannys.split(',')[0];
        } catch(err) {
            console.log(res);
            setTimeout(do_set_answer, 500, statuses.error, 'smth wrong', 'tags-info-answer');
        }
        if (res['ans'].hasOwnProperty('slots') || res['ans'].hasOwnProperty('exclude')) {
            console.log(res);
            setTimeout(do_set_answer, 500, statuses.error, 'unused props found', 'tags-info-answer');
        }
    }

    function do_fill_blocked_info(res) {
        let el = document.getElementById('blocked_details');
        if (!el) { return; }
        if (res['ans'].hasOwnProperty('blocked') && res['ans']['blocked'] === true) {
            el.innerText = 'blocked';
            el.style.color = '#bb5259';
            document.getElementById('blocked_yes').style.color = '#bb5259';
            document.getElementById('blocked_no').style.color = 'lightgrey';
            let author = '', reason = '';
            try {
                author = res['ans']['details']['author'];
                reason = res['ans']['details']['reason'];
            } catch(err) { console.log(err); }
            document.getElementById('blocked_info').title = 'Deploy is blocked by ' + author;
            document.getElementById('blocked_reason').value = reason;
        } else {
            document.getElementById('blocked_no').style.color = '#98d298';
            document.getElementById('blocked_yes').style.color = 'lightgrey';
            el.style.color = 'lightgrey';
            document.getElementById('blocked_info').title = 'Deploy is not blocked'; //. Press if you want to block it';
        }
    }

    function do_fill_action_answer(res) {
        if (res['ans'].startsWith('type=')) {
            let task_id = res['ans'];
            new_task_got(task_id);
        } else {
            setTimeout(do_set_answer, 500, statuses.attention, JSON.stringify(res), 'slots-group-action-answer');
        }
    }

    function do_fill_addrep_answer(res) {
        if (res['ans'].startsWith('type=')) {
            let task_id = res['ans'];
            new_task_got(task_id);
        } else {
            setTimeout(do_set_answer, 500, statuses.attention, JSON.stringify(res), 'add-replica-answer');
        }
    }

    function fill_blocked_info() {
        let el = document.getElementById('blocked_info');
        if (!el) { return; }
        let url = '{% url "deploy_is_blocked" %}?ctype=' + ctype + '&service=' + service;
        let load_cb = {
            url: url, do_once_any_case: true,
            answer_id: 'blocked_answer', on_load: do_fill_blocked_info};
        do_data_load(load_cb);
    }

    function fill_tags_info() {
        let el = document.getElementById('nanny_adds');
        if (!el) { return; }
        let url = '{% url "tags_info" %}?action=get&ctype=' + ctype + '&service=' + service;
        let load_cb = {
            url: url, do_once_any_case: true,
            answer_id: 'tags-info-answer', on_load: do_fill_tags_info};
        do_data_load(load_cb);
    }

    function modify_tags_info(action) {
        let el = document.getElementById('nanny_adds');
        if (!el) { return; }
        let url = '{% url "modify_tags_info" %}?action=' + action + '&ctype=' + ctype + '&service=' + service;
        let nannys = document.getElementById('nanny-service-input').value;
        let endpoint_sets = document.getElementById('nanny-endpointsets').value;
        let use_containers = document.getElementById('nanny-use-containers').checked;
        url += '&nanny_services=' + nannys;
        url += '&use_container_names=' + use_containers;
        url += '&endpointsets=' + endpoint_sets;
        let load_cb = {
            url: url, do_once_any_case: true,
            answer_id: 'tags-info-answer', on_load: function() {console.log("tags info sent")}};
        do_data_load(load_cb);
    }

    function set_blocked_info(action) {
        let url = '{% url "deploy_block" %}?ctype=' + ctype + '&service=' + service + '&action=' + action;
        let reason = document.getElementById('blocked_reason').value;
        url += '&reason=' + encodeURIComponent(reason);
        let load_cb = {
            url: url, do_once_any_case: true,
            answer_id: 'blocked_answer', on_load: function() {console.log("blocked info sent"); setTimeout(fill_blocked_info, 500);}};
        do_data_load(load_cb);
    }

    function searchind_set() {
        let act_search = document.getElementById('search-enabled-chb').checked ? 'enable_search' : 'disable_search';
        let act_index = document.getElementById('indexing-enabled-chb').checked ? 'enable_indexing' : 'disable_indexing';
        let action = act_search + ',' + act_index;
        let deploy_proxies = document.getElementById('deploy-proxies-chb').checked;
        let deploy_backends = document.getElementById('deploy-backends-chb').checked;
        let url = '{% url "modify_searchmap" %}?action=' + action + '&service=' + service + '&ctype=' + ctype
            + '&deploy_proxies=' + deploy_proxies + '&deploy=' + deploy_backends;
        let slots = [];
        for (let sl in selected_slots) {
            if (selected_slots.hasOwnProperty(sl)) { slots.push(sl); }
        }
        url += '&slots_vector=' + slots.join(',');
        let load_cb = {
            url: url, do_once_any_case: true,
            answer_id: 'slots-group-action-answer', on_load: do_fill_action_answer};
        do_data_load(load_cb);
    }

    function container_switch() {
        let url = '{% url "modify_searchmap" %}?action=switch_container&service=' + service + '&ctype=' + ctype
            + '&deploy_proxies=false&deploy=false';
        let slots = [];
        for (let sl in selected_slots) {
            if (selected_slots.hasOwnProperty(sl)) { slots.push(sl); }
        }
        url += '&slots_vector=' + slots.join(',');
        let load_cb = {
            url: url, do_once_any_case: true,
            answer_id: 'slots-group-action-answer', on_load: do_fill_action_answer};
        do_data_load(load_cb);
    }

    function restore_slots() {
        let slots = [];
        for (let sl in selected_slots) {
            if (selected_slots.hasOwnProperty(sl)) { slots.push(sl); }
        }
        let deploy_proxies = document.getElementById('deploy-proxies-chb').checked;
        let url = '{% url "slots_restore" %}?service=' + service + '&ctype=' + ctype + '&deploy_proxies=' + deploy_proxies;
        url += '&slots=' + slots.join(',');
        let load_cb = {
            url: url, do_once_any_case: true,
            answer_id: 'slots-group-action-answer', on_load: do_fill_action_answer};
        do_data_load(load_cb);
    }

    function replace_slots() {
        let slots = [];
        for (let sl in selected_slots) {
            if (selected_slots.hasOwnProperty(sl)) { slots.push(sl); }
        }
        let deploy_proxies = document.getElementById('deploy-proxies-chb').checked;
        let url = '{% url "slots_replace" %}?service=' + service + '&ctype=' + ctype + '&deploy_proxies=' + deploy_proxies;
        url += '&slots=' + slots.join(',');
        let unused_slots = [];
        for (let sl in selected_unused_slots) {
            if (selected_unused_slots.hasOwnProperty(sl)) { unused_slots.push(sl); }
        }
        url += '&new_slots_pool=' + unused_slots.join(',');
        let absent_slots = [];
        for (let sl in selected_absent_slots) {
            if (selected_absent_slots.hasOwnProperty(sl)) { absent_slots.push(sl); }
        }
        url += '&absent_replace_slots=' + absent_slots.join(',');

        let load_cb = {
            url: url, do_once_any_case: true,
            answer_id: 'slots-group-action-answer', on_load: do_fill_action_answer};
        do_data_load(load_cb);
    }

    function release_slots() {
        let slots = [];
        for (let sl in selected_slots) {
            if (selected_slots.hasOwnProperty(sl)) { slots.push(sl); }
        }
        let ep_sets = [];
        for (let eps in selected_endpointsets) {
            if (selected_endpointsets.hasOwnProperty(eps)) { ep_sets.push(eps.split(':')[0]); }
        }
        let url = '';
        if (ep_sets.length > 0) {
            url = '{% url "eps_release" %}?service=' + service + '&ctype=' + ctype;
            url += '&eps=' + ep_sets.join(',');
        } else {
            let deploy_proxies = document.getElementById('deploy-proxies-chb').checked;
            url = '{% url "slots_release" %}?service=' + service + '&ctype=' + ctype + '&deploy_proxies=' + deploy_proxies;
            url += '&slots=' + slots.join(',');
        }
        let load_cb = {
            url: url, do_once_any_case: true,
            answer_id: 'slots-group-action-answer', on_load: do_fill_action_answer};
        do_data_load(load_cb);
        selected_slots = {};
    }

    function add_replica() {
        let url = '{% url "add_replica" %}?service=' + service + '&ctype=' + ctype;
        let rep_cnt = document.getElementById("add_replica_replicas_count").value;
        let slot_cnt = document.getElementById("add_replica_slots_count").value;
        url += '&slots_count=' + slot_cnt + '&replicas_count=' + rep_cnt;

        let restore = document.getElementById("add_replica_restore").checked;
        let deploy_proxy = document.getElementById("add_replica_deploy_proxies").checked;
        url += '&restore=' + restore + '&deploy_proxy=' + deploy_proxy;

        let allocator = {};
        allocator.one_slot_on_server = document.getElementById("add_replica_one_slot_on_server").checked;
        allocator.allow_same_host_replica = document.getElementById("add_replica_allow_same_host_replica").checked;

        let alloc_kind = document.getElementById('add_replica_allocation').add_replica_allocator.value;
        if (alloc_kind === 'dc') {
            let dcs_selected = [];
            let dcs_els = document.getElementsByName('add-replica-dc-chb');
            for (let i=0; i<dcs_els.length; ++i) {
                if (dcs_els[i].checked) {
                    dcs_selected.push(dcs_els[i].getAttribute('data-dc'));
                }
            }
            allocator.pref_dcs = dcs_selected;
            allocator.pref_dc_only = true;
        } else if (alloc_kind === 'selected') {
            allocator.custom_slots = [];
            for (let sl in selected_unused_slots) {
                if (selected_unused_slots.hasOwnProperty(sl)) {
                    allocator.custom_slots.push(sl);
                }
            }
            if (allocator.custom_slots.length === 0) {
                alert('select some slots');
                return;
            }
        } else {
            alert('unknown allocation kind ' + alloc_kind);
            return;
        }
        url += '&slots_allocator=' + JSON.stringify(allocator);
        console.log(url);
        let load_cb = {
            url: url, do_once_any_case: true,
            answer_id: 'add-replica-answer', on_load: do_fill_addrep_answer};
        do_data_load(load_cb);
    }

    function fill_free_dcs(dc_stat) {
        let dcs_selected = {};
        let dcs_els = document.getElementsByName('add-replica-dc-chb');
        if (dcs_els) {
            for (let i=0; i<dcs_els.length; ++i) {
                if (dcs_els[i].checked) {
                    dcs_selected[dcs_els[i].getAttribute('data-dc')] = 1;
                }
            }
        }
        document.getElementById('dcs_free').innerHTML = '';
        for (let dc in dc_stat) {
            if (!dc_stat.hasOwnProperty(dc)) { continue; }
            let el = document.createElement('input');
            el.setAttribute('type', 'checkbox');
            el.setAttribute('data-dc', dc);
            el.setAttribute('name', 'add-replica-dc-chb');
            if (dcs_selected.hasOwnProperty(dc)) {
                el.checked = true;
            }
            let leg_el = document.createElement('span');
            leg_el.innerHTML = dc + ' (' + dc_stat[dc] + ')';

            let dc_lab = document.createElement('label');
            dc_lab.appendChild(el);
            dc_lab.appendChild(leg_el);
            document.getElementById('dcs_free').appendChild(dc_lab);
        }
    }

    function show_free_slots() {
        switch_element_hidden('free_slots');
        if (document.getElementById('free_slots').hasAttribute('hidden')) {
            return;
        }
        if (!free_slots_upd_started) {
            free_slots_upd_started = true;
            do_data_load(cluster_unused_updates);
        }
    }

    function show_add_replica() {
        switch_element_hidden('replica_adds');
        show_free_slots();
    }

    function go_to_diff() {
        let url = '{% url "diff" %}?slot=';
        let slot = '';
        for (let sl in selected_slots) { if (selected_slots.hasOwnProperty(sl)) {
                slot = sl; break;
        } }
        if (slot === '') {
            let els = document.getElementsByClassName('slot-used');
            if (els.length === 0) { return;}
            slot = els[0].id.substr(5);
        }
        url += slot;
        url += '&service=' + service + '&ctype=' + ctype;
        let wind = window.open(url);
        wind.focus();
    }

    function switch_element_hidden(id) {
        try {
            let el = document.getElementById(id);
            if (el.hasAttribute('hidden')) {
                el.removeAttribute('hidden');
            } else {
                el.setAttribute('hidden', 1);
            }
        } catch(err)  {console.log(err); }
    }

    function rebuild_selected_slots() {
        let els = document.getElementsByClassName('slot-selected');
        let new_selected_used = {};
        let new_selected_unused = {};
        let new_selected_absent = {};
        let new_selected_eps = {};
        let sz = 0;
        let usz = 0;
        let asz = 0;
        let esz = 0;
        for (let i=0; i<els.length; ++i) {
            let slot = els[i].id.substr(5); //id='cell-<slot>'
            if (els[i].classList.contains('slot-used')) {
                new_selected_used[slot] = '';
                ++sz;
            } else if (els[i].classList.contains('slot-unused')) {
                new_selected_unused[slot] = '';
                ++usz;
            } else if (els[i].classList.contains('slot-absent')) {
                new_selected_absent[slot] = '';
                ++asz;
            } else if (els[i].classList.contains('endpointset')) {
                new_selected_eps[slot] = '';
                ++esz;
            }
        }
        selected_slots = new_selected_used;
        selected_unused_slots = new_selected_unused;
        selected_absent_slots = new_selected_absent;
        selected_endpointsets = new_selected_eps;

        let sel_el = document.getElementById('selected_stat');
        sel_el.innerText = sz + asz;
        if (usz > 0 || esz > 0) {
            sel_el.innerText += ' used';
        }
        if (usz > 0) {
            sel_el.innerText += ', ' + usz + ' unused';
        }
        if (esz > 0) {
            sel_el.innerText += ', ' + esz + ' endpointsets';
        }
    }

    function on_slot_select(slot, is_unused) {
        rebuild_selected_slots();
    }

    $(document).ready(function() {
        do_data_load(tasks_updates);
        window.addEventListener('slotselect', function(evt){ on_slot_select(evt.detail.slot, evt.detail.is_unused);});
        window.addEventListener('freeslotstat', function(evt){ fill_free_dcs(evt.detail.data);});
        fill_tags_info();
        fill_blocked_info();
         // start_task_watch('type=RESTORE_INDEX_TASK;srv=zen_doc;time=153147515;hash=11356657331260547310;tsdiscr=10');
        //start_task_watch('type=MODIFY_SEARCHMAP_TASK;srv=fb_profiles;time=152232590;hash=16930558949978452375;tsdiscr=10');
       // start_task_watch('type=DEPLOY_TASK;srv=searchproxy;time=152044772;hash=15271653892820618944;tsdiscr=10');

    });

</script>
{% include "navigation.html" %}
{% include "nav_ctype.html" %}
<body>
<div style="border-bottom: 2px solid #fceacf">
    <button class="btn-main-link"><a href="{% url 'main' %}" class="main-link">SAAS</a></button>
    <span class="dropdown"><span class="page-title" data-toggle="dropdown">Cluster & deploy<span class="caret"></span></span>
        <ul id="nav-screens-menu" class="dropdown-menu">
            <li><a href="{% url 'deploy_page' %}?service={{ service }}&ctype={{ ctype }}">Cluster & deploy</a></li>
            <li><a href="{% url 'cluster_total' %}?service={{ service }}&ctype={{ ctype }}">Cluster hardware</a></li>
            <li><a href="{% url 'service_info' %}?service={{ service }}&ctype={{ ctype }}">Service conf</a></li>
            <li><a href="{% url 'monitor_hosts' %}?service={{ service }}&ctype={{ ctype }}">Monitor hosts</a></li>
            <li><a href="{% url 'monitor_gui' %}?service={{ service }}&ctype={{ ctype }}">Monitor</a></li>
        </ul></span>
    <span id="ctype_selector" style="font-weight:bold">{{ ctype }}</span><span class="caret"></span>
    <span class="nav-service-link" style="margin-left:10px;font-weight:bold;color:#d38004">{{ service }}</span>
</div>
<table>
    <tr>
        <td id="nav-services-list" style="vertical-align: top"></td>
        <td style="vertical-align: top">
        {% if is_root %}
            <div><a onclick="switch_element_hidden('nanny_adds')" style="cursor:pointer">
                Nanny<span class="caret"></span></a>
                <div id="nanny_adds" hidden class="actions-div">
                    <table style="width:100%">
                        <tr><td>Nanny services
                            <a id="nanny-service-link" title="open in nanny" style="float:right" target="_blank">
                                <i class="fa fa-external-link"></i></a></td>
                        <td style="width: 75%"><input id='nanny-service-input' type="text" style="width:100%">
                            <br><input type="checkbox" id="nanny-use-containers"><label for="nanny-use-containers">use container names</label>
                        </td>
                    </tr>
                        <tr title="For proxies mainly, format: cluster@endpointset_name"><td>Endpoint sets</td>
                        <td style="width: 75%">
                            <input id='nanny-endpointsets' type="text" style="width:100%">
                        </td>
                    </tr>
                    <tr><td>
                        <button id="nanny-send-button" onclick="modify_tags_info('set')" disabled>Send</button>
                        <button onclick="modify_tags_info('invalidate')">Cache reset</button>
                    </td><td id="tags-info-answer">loading</td></tr>
                    </table>
                </div></div>
            <div><a onclick="show_add_replica()" style="cursor:pointer">
                Add replica<span class="caret"></span></a>
                <div id="replica_adds" class="actions-div" hidden>
                    <table>
                        <tr><td>
                            <form id="add_replica_allocation">
                            <label><input type="radio" value='dc' name='add_replica_allocator' checked></label>Auto: <span id="dcs_free">(not loaded)</span><br>
                            <label><input type="radio" value='selected' name='add_replica_allocator'></label>Selected slots <span id="free_selected"></span>
                        </form></td><td>
                            <div id="dcs-free-stat"></div>
                        </td></tr>
                        <tr><td colspan="2">
                            <label>
                                replicas: <input id='add_replica_replicas_count' type='number' max=20 min=1 value=1>
                            </label>
                            <label style="margin-left:10px">
                                slots per replica: <input id='add_replica_slots_count' type='number' max=200 min=1 value=1>
                            </label>
                            <br>
                            <label><input type="checkbox" id="add_replica_restore" name="restore">Restore</label>
                            <label><input type="checkbox" id="add_replica_one_slot_on_server">1 slot per server</label>
                            <label><input type="checkbox" id="add_replica_deploy_proxies" checked>deploy proxy</label>
                            <label><input type="checkbox" id="add_replica_allow_same_host_replica">Allow few replicas on the same host</label>
                        </td></tr>
                        <tr><td>
                            <button id="ad-replica-button" onclick="add_replica()">Send</button>
                        </td><td id="add-replica-answer"></td></tr>
                    </table>
                </div></div>
        {% endif %}
        <div style="margin-top:15px;margin-bottom:15px">
{% if is_rty %}
<button onclick="deploy('rtyserver')">Deploy</button>
<button onclick="deploy('searchproxy')">Deploy Sp</button>
<button onclick="deploy('indexerproxy')">Deploy Ip</button>
{% elif service == 'deploy_manager' %}
{% else %}
<button onclick="deploy('{{ service }}')">Deploy</button>
{% endif %}
<label title="Do not restart slots, only save configuration"><input type="checkbox" id="only_save_chbox" checked> only save</label>
<label title="Restart only slots with configs diff"><input type="checkbox" id="only_diff_chbox"> only diff</label>
<a id="show-diff" target="_blank" onclick="go_to_diff()" style="cursor:pointer;margin-left:5px"
   title="List of changes that will be deployed to backends"><i class="fa fa-external-link"></i>diff</a>
<span id="blocked_info" style="color:lightgrey;margin-left: 5px" onclick="switch_element_hidden('block_do')">
    <i class="fa fa-check" id="blocked_no"></i><i class="fa fa-minus-circle" id="blocked_yes"></i><span id="blocked_details"></span></span>
<div id="block_do" hidden>
    <label>reason: <input type="text" id="blocked_reason"></label>
    <button onclick="set_blocked_info('set')">Block</button>
    <button onclick="set_blocked_info('remove')">Remove</button>
    <div id="blocked_answer"></div>
</div>
        <span id="on-deploy-state"></span>
        </div>
        {% if is_root %}
            <div>
                <a onclick="switch_element_hidden('multiple_slots_actions')" style="cursor:pointer">
                    Selected slots: <span id="selected_stat">0</span><span class="caret"></span></a>
                <div id="multiple_slots_actions" class="actions-div" hidden>
                    <label><input type="checkbox" id="search-enabled-chb" checked>Search enabled</label>
                    <label><input type="checkbox" id="indexing-enabled-chb" checked>Index enabled</label>
                    <label><input type="checkbox" id="deploy-proxies-chb">Deploy proxies</label>
                    <label><input type="checkbox" id="deploy-backends-chb" checked>Deploy backends</label>
                    <br><button onclick="searchind_set()" title="enable/disable search/indexing">SI send</button>
                    <button onclick="restore_slots()">Restore</button>
                    <button onclick="replace_slots()">Replace</button>
                    <button onclick="release_slots()">Release</button>
                    <button onclick="container_switch()" title="replace host->searchmap">Use containers</button>
                    <div id="slots-group-action-answer"></div>
                </div>
            </div>
        {% endif %}
{% include "service_cluster_table.html" %}
        <a onclick="show_free_slots()" style="cursor: pointer">Show free slots</a>
        <div id="free_slots" hidden>
            <div id="free_slots_table">Free slots will be here</div>
            <div id="free_slots_answer"></div>
        </div>
<div id="deploy_tasks"></div>
<div id="tasks_list_answer"></div>
{% include "deploy_trace.html" %}
        </td>
    </tr>
</table>
</body>
</html>
