Skip to content

Commit 75db552

Browse files
Prabhu JosephPrabhu Joseph
authored andcommitted
YARN-1806. Add ThreadDump Option in YARN UI2 to fetch for running containers
Contributed by Siddharth Ahuja. Reviewed by Akhil PB.
1 parent 6e618b6 commit 75db552

File tree

10 files changed

+743
-0
lines changed

10 files changed

+743
-0
lines changed
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import RESTAbstractAdapter from './restabstract';
20+
21+
export default RESTAbstractAdapter.extend({
22+
address: "rmWebAddress",
23+
restNameSpace: "cluster",
24+
25+
handleResponse(status, headers, payload, requestData) {
26+
// If the user is not authorized to signal a threaddump for a container,
27+
// the response contains a RemoteException with a 403 (Forbidden) status
28+
// code. Extract out the error message from the RemoteException in this
29+
// case.
30+
// If the status is '0' or empty, it is symptomatic of the YARN role not
31+
// available or able to respond or a network timeout/firewall issue.
32+
if (status === 403) {
33+
if (payload
34+
&& typeof payload === 'object'
35+
&& payload.RemoteException
36+
&& payload.RemoteException.message) {
37+
return new Error(payload.RemoteException.message);
38+
}
39+
} else if (status === 0 && payload === "") {
40+
return new Error("Not able to connect to YARN!");
41+
}
42+
43+
return payload;
44+
},
45+
46+
/**
47+
* Set up the POST request to use the signalToContainer REST API
48+
* to signal a thread dump for a running container to RM.
49+
*/
50+
signalContainerForThreaddump(request, containerId, user) {
51+
var url = this.buildURL();
52+
if (user && containerId) {
53+
url += "/containers" + "/" + containerId + "/signal"
54+
+ "/OUTPUT_THREAD_DUMP" + "?user.name=" + user;
55+
}
56+
return this.ajax(url, "POST", {data: request});
57+
},
58+
59+
ajax(url, method, hash) {
60+
hash = {};
61+
hash.crossDomain = true;
62+
hash.xhrFields = {withCredentials: true};
63+
hash.targetServer = "RM";
64+
return this._super(url, method, hash);
65+
},
66+
67+
/**
68+
* Override options so that result is not expected to be JSON
69+
*/
70+
ajaxOptions: function (url, type, options) {
71+
var hash = options || {};
72+
hash.url = url;
73+
hash.type = type;
74+
// Make sure jQuery does not try to convert response to JSON.
75+
hash.dataType = 'text';
76+
hash.context = this;
77+
78+
var headers = Ember.get(this, 'headers');
79+
if (headers !== undefined) {
80+
hash.beforeSend = function (xhr) {
81+
Object.keys(headers).forEach(function (key) {
82+
return xhr.setRequestHeader(key, headers[key]);
83+
});
84+
};
85+
}
86+
return hash;
87+
}
88+
});
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import DS from 'ember-data';
20+
import Ember from 'ember';
21+
import Converter from 'yarn-ui/utils/converter';
22+
23+
/**
24+
* REST URL's response when fetching container logs will be
25+
* in plain text format and not JSON.
26+
*/
27+
export default DS.RESTAdapter.extend({
28+
headers: {
29+
Accept: 'text/plain'
30+
},
31+
32+
host: Ember.computed("address", function () {
33+
return this.get(`hosts.localBaseAddress`);
34+
}),
35+
36+
namespace: Ember.computed("restNameSpace", function () {
37+
return this.get(`env.app.namespaces.node`);
38+
}),
39+
40+
urlForQueryRecord(query) {
41+
var url = this._buildURL();
42+
url = url.replace("{nodeAddress}", query.nodeHttpAddr) + "/containerlogs/"
43+
+ query.containerId + "/" + query.fileName;
44+
return url;
45+
},
46+
47+
queryRecord: function (store, type, query) {
48+
var url = this.urlForQueryRecord(query);
49+
// Query params not required.
50+
query = null;
51+
console.log(url);
52+
return this.ajax(url, 'GET', { data: query });
53+
},
54+
55+
ajax(url, method, hash) {
56+
hash = hash || {};
57+
hash.crossDomain = true;
58+
hash.xhrFields = {withCredentials: true};
59+
hash.targetServer = "NM";
60+
return this._super(url, method, hash);
61+
},
62+
63+
/**
64+
* Override options so that result is not expected to be JSON
65+
*/
66+
ajaxOptions: function (url, type, options) {
67+
var hash = options || {};
68+
hash.url = url;
69+
hash.type = type;
70+
// Make sure jQuery does not try to convert response to JSON.
71+
hash.dataType = 'text';
72+
hash.context = this;
73+
74+
var headers = Ember.get(this, 'headers');
75+
if (headers !== undefined) {
76+
hash.beforeSend = function (xhr) {
77+
Object.keys(headers).forEach(function (key) {
78+
return xhr.setRequestHeader(key, headers[key]);
79+
});
80+
};
81+
}
82+
return hash;
83+
},
84+
85+
handleResponse(status, headers, payload, requestData) {
86+
// If the status is '0' or empty, it is symptomatic of the YARN role not
87+
// available or able to respond or a network timeout/firewall issue.
88+
if (status === 0 && payload === "") {
89+
return new Error("Not able to connect to YARN!");
90+
}
91+
92+
return payload;
93+
}
94+
});

0 commit comments

Comments
 (0)