Kill Application

Automatically append user.name=root to Kill Application requests in YARN Web UI

ของเมื่อวันที่ 30-08-2023 ดู เวอร์ชันล่าสุด

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey, Greasemonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

You will need to install an extension such as Tampermonkey to install this script.

คุณจะต้องติดตั้งส่วนขยาย เช่น Tampermonkey หรือ Violentmonkey เพื่อติดตั้งสคริปต์นี้

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Kill Application
// @namespace    http://candao.com/
// @version      1.2
// @description  Automatically append user.name=root to Kill Application requests in YARN Web UI
// @author       Bruce Lu
// @match        http://node01:8088/*
// @match        http://node02:8088/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    function interceptRequests() {
        const userName = 'root';
        const originalOpen = XMLHttpRequest.prototype.open;
        const baseUris = ['http://node01:8088', 'http://node02:8088'];  // 这里使用了数组来存储两个基础URI

        XMLHttpRequest.prototype.open = function(method, url, async, user, password) {
            if (method.toLowerCase() === 'put' && url.includes('/ws/v1/cluster/apps/')) {
                
                for (const baseUri of baseUris) {  // 对数组进行循环
                    if (url.startsWith(baseUri)) {  // 检查当前URL是否以某个基础URI开头
                        url += (url.includes('?') ? '&' : '?') + 'user.name=' + userName;
                        console.log('Modified request URL:', url);
                        break;  // 如果找到匹配项,退出循环
                    }
                }
            }

            return originalOpen.apply(this, [method, url, async, user, password]);
        };
    }

    const script = document.createElement('script');
    script.textContent = `(${interceptRequests.toString()})();`;
    document.head.appendChild(script);
})();