|
| 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 | +}); |
0 commit comments