Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion ambari-web/latest/src/screens/Hosts/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* limitations under the License.
*/

import { cloneDeep, get, set } from "lodash";
import { capitalize, cloneDeep, get, set } from "lodash";
import { HostsApi } from "../../api/hostsApi";
import {
doDecommissionRegionServer,
Expand All @@ -39,6 +39,7 @@ import {
} from "../../Utils/Utility";
import ConfirmationModal from "../../components/ConfirmationModal";
import { IHost } from "../../models/host";
import { t } from "i18next";

export const sendComponentCommand = async (
component: IHostComponent,
Expand Down Expand Up @@ -405,3 +406,33 @@ const executeCustomCommandErrorCallback = (error: any) => {
error.message
);
};

export const toggleMaintenanceMode = async (component: IHostComponent) => {
if (component.isImpliedState()) return null;

const hostname = get(component, "hostName");
const clusterName = get(component, "clusterName");
const componentName = get(component, "componentName");
const state = get(component, "passiveState") === "ON" ? "OFF" : "ON";
const displayName = get(component, "displayName");
let message = t(
"passiveState.turn" + capitalize(state.toString()) + "For"
).replace("{0}", displayName);

const data = JSON.stringify({
RequestInfo: {
context: message,
},
Body: {
HostRoles: {
maintenance_state: state,
},
},
});
await HostsApi.updateHostComponentForHost(
clusterName,
hostname,
componentName,
data
);
};