Skip to content

Commit

Permalink
Merge branch 'fix-stopped-cluster-case'
Browse files Browse the repository at this point in the history
  • Loading branch information
idevat committed Oct 22, 2022
2 parents d2d72b9 + 9a64559 commit 84a8392
Show file tree
Hide file tree
Showing 21 changed files with 149 additions and 68 deletions.
10 changes: 6 additions & 4 deletions src/app/store/reducers/cluster/clusterStatus/apiToState/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@ export const apiToState = (apiClusterStatus: ApiCluster): Cluster => {
fenceDevicesSeverity,
resourceOnNodeStatusList,
} = analyzeApiResources(apiClusterStatus.resource_list);
const { nodeList, nodesSeverity, clusterStatus } = processApiNodes(
apiClusterStatus.node_list,
apiClusterStatus.node_attr ?? {},
);
const { nodeList, nodesSeverity, clusterStatus, hasCibInfo } =
processApiNodes(
apiClusterStatus.node_list,
apiClusterStatus.node_attr ?? {},
);
return {
name: apiClusterStatus.cluster_name,
status: clusterStatus,
hasCibInfo: hasCibInfo,
nodeList,
issueList: transformIssues(apiClusterStatus),
resourceTree,
Expand Down
21 changes: 17 additions & 4 deletions src/app/store/reducers/cluster/clusterStatus/apiToState/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,25 @@ const countNodesSeverity = (apiNodeList: ApiNode[]): StatusSeverity => {
};

const getClusterStatus = (apiNodeList: ApiNode[]): Cluster["status"] => {
if (apiNodeList.every(n => n.status === "unknown")) {
return "unknown";
if (
apiNodeList.every(n => n.status === "online")
&& apiNodeList.some(n => "quorum" in n && n.quorum)
) {
return "running";
}
if (apiNodeList.some(n => n.status === "online" && n.quorum)) {
return "degraded";
}
if (apiNodeList.some(n => n.status === "online" || n.status === "standby")) {
return "started";
return "inoperative";
}
if (apiNodeList.some(n => n.status === "unknown")) {
return "unknown";
}
return "stopped";
return "offline";
};
const hasCibInfo = (apiNodeList: ApiNode[]): Cluster["hasCibInfo"] =>
apiNodeList.some(n => n.status === "online" || n.status === "standby");

export const processApiNodes = (
apiNodeList: ApiNode[],
Expand All @@ -114,10 +125,12 @@ export const processApiNodes = (
nodeList: Node[];
nodesSeverity: StatusSeverity;
clusterStatus: Cluster["status"];
hasCibInfo: Cluster["hasCibInfo"];
} => ({
nodeList: apiNodeList.map(apiNode =>
toNode(apiNode, apiNodeAttrs[apiNode.name] || []),
),
nodesSeverity: countNodesSeverity(apiNodeList),
clusterStatus: getClusterStatus(apiNodeList),
hasCibInfo: hasCibInfo(apiNodeList),
});
1 change: 1 addition & 0 deletions src/app/store/reducers/cluster/clusterStatus/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Cluster, ClusterStatusService } from "./types";
export const clusterStatusDefault: Cluster = {
name: "",
status: "unknown",
hasCibInfo: false,
nodeList: [],
resourceTree: [],
fenceDeviceList: [],
Expand Down
3 changes: 2 additions & 1 deletion src/app/store/reducers/cluster/clusterStatus/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ type ApiSbdConfig = Exclude<
*/
export type Cluster = {
name: string;
status: "started" | "stopped" | "unknown";
status: "running" | "degraded" | "inoperative" | "offline" | "unknown";
hasCibInfo: boolean;
nodeList: ((
| {
name: string;
Expand Down
23 changes: 12 additions & 11 deletions src/app/view/cluster/acl/AclPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,8 @@ export const AclPage = () => {
label: `${aclEnabled ? "Disable" : "Enable"} ACL`,
confirm: {
title: aclEnabled ? "Disable ACL" : "Enable ACL",
description: `${
aclEnabled ? "Disable" : "Enable"
} access control lists.`,
description: `${aclEnabled ? "Disable" : "Enable"
} access control lists.`,
action: {
type: "CLUSTER.PROPERTIES.UPDATE",
key: { clusterName },
Expand All @@ -93,14 +92,16 @@ export const AclPage = () => {
},
]}
after={
<>
<ToolbarItem variant="separator" />
<ToolbarItem>
<Label variant="outline" color={aclEnabled ? "green" : "grey"}>
ACL {aclEnabled ? "enabled" : "disabled"}
</Label>
</ToolbarItem>
</>
cluster.hasCibInfo ? (
<>
<ToolbarItem variant="separator" />
<ToolbarItem>
<Label variant="outline" color={aclEnabled ? "green" : "grey"}>
ACL {aclEnabled ? "enabled" : "disabled"}
</Label>
</ToolbarItem>
</>
) : null
}
/>

Expand Down
3 changes: 2 additions & 1 deletion src/app/view/cluster/acl/lists/AclLists.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ const spacer: FlexProps["spacer"] = { default: "spacerNone" };

export const AclLists = () => {
const [cluster] = useClusterSelector(selectors.getCluster);
if (cluster.status !== "started") {
if (!cluster.hasCibInfo) {
return (
<EmptyStateClusterStopped
title={"Cannot get ACLs from stopped cluster"}
clusterName={cluster.name}
/>
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/view/cluster/constraints/ConstraintFilteredList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ export const ConstraintFilteredList = ({
};
const [cluster] = useClusterSelector(selectors.getCluster);

if (cluster.status !== "started") {
if (!cluster.hasCibInfo) {
return (
<EmptyStateClusterStopped
title={"Cannot get constraints from stopped cluster"}
clusterName={clusterName}
/>
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/app/view/cluster/fenceDevices/list/FenceDeviceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@ export const FenceDeviceList = ({
const { compact } = useGroupDetailViewContext();
const [cluster] = useClusterSelector(selectors.getCluster);

if (cluster.status !== "started") {
if (!cluster.hasCibInfo) {
return (
<EmptyStateClusterStopped
title={"Cannot get fence devices from stopped cluster"}
clusterName={cluster.name}
/>
);
}
Expand Down
29 changes: 16 additions & 13 deletions src/app/view/cluster/properties/ClusterPropertiesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ export const ClusterPropertiesPage = () => {
buttonsItems={[
...(!isEditing
? [
{
name: "edit-attributes",
run: () => setIsEditing(true),
launchDisable: launchDisable(
"Cannot edit cluster properties on stopped cluster",
),
},
]
{
name: "edit-attributes",
run: () => setIsEditing(true),
launchDisable: launchDisable(
"Cannot edit cluster properties on stopped cluster",
),
},
]
: []),
]}
/>
Expand All @@ -91,14 +91,17 @@ export const ClusterPropertiesPage = () => {
)}
{!isEditing && (
<>
{cluster.status !== "started" && (
{!cluster.hasCibInfo && (
<Alert
isInline
variant="warning"
title="Cannot get cluster properties values from stopped cluster"
className="pf-u-mb-sm"
>
<ClusterStoppedInfo />
<ClusterStoppedInfo
startButton="link"
clusterName={cluster.name}
/>
</Alert>
)}
<AttributeList
Expand All @@ -116,9 +119,9 @@ export const ClusterPropertiesPage = () => {
<AttributeValue
{...(property.name in cluster.clusterProperties
? {
value:
cluster.clusterProperties[property.name],
}
value:
cluster.clusterProperties[property.name],
}
: { defaultValue: property.default })}
/>
</React.Fragment>
Expand Down
3 changes: 2 additions & 1 deletion src/app/view/cluster/resources/tree/ResourceTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ export const ResourceTree = ({
const { compact } = useGroupDetailViewContext();
const [cluster] = useClusterSelector(selectors.getCluster);

if (cluster.status !== "started") {
if (!cluster.hasCibInfo) {
return (
<EmptyStateClusterStopped
title={"Cannot get resources from stopped cluster"}
clusterName={cluster.name}
/>
);
}
Expand Down
6 changes: 4 additions & 2 deletions src/app/view/dashboard/clusterList/DashboardCluster.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@ export const DashboardCluster = ({ cluster }: { cluster: Cluster }) => {
</Toggle>
<Toggle expandKey={COLUMNS.RESOURCES} data-test="resources">
<DashboardClusterCellSummary
itemsCount={cluster.resourceTree.length}
itemsCount={cluster.hasCibInfo ? cluster.resourceTree.length : "?"}
summaryStatus={cluster.summary.resourcesSeverity}
/>
</Toggle>
<Toggle expandKey={COLUMNS.FENCE_DEVICES} data-test="fence-devices">
<DashboardClusterCellSummary
itemsCount={cluster.fenceDeviceList.length}
itemsCount={
cluster.hasCibInfo ? cluster.fenceDeviceList.length : "?"
}
summaryStatus={cluster.summary.fenceDevicesSeverity}
/>
</Toggle>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React from "react";

import { ClusterStatusLabel, Link, location } from "app/view/share";
import { Cluster } from "app/view/cluster/types";

export const DashboardClusterCellName = ({
clusterName,
status,
}: {
clusterName: string;
status: Cluster["status"];
status: React.ComponentProps<typeof ClusterStatusLabel>["status"];
}) => {
return (
<th role="rowheader" data-test="name">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export const DashboardClusterCellSummary = ({
itemsCount,
summaryStatus,
}: {
itemsCount: number;
itemsCount: number | "?";
summaryStatus: React.ComponentProps<typeof StatusIco>["status"];
}) => {
if (summaryStatus === "OK") {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Cluster, FenceDevice } from "app/view/cluster/types";
import {
EmptyStateClusterStopped,
EmptyStateNoItem,
Link,
StatusSign,
Expand Down Expand Up @@ -34,6 +35,16 @@ export const DashboardClusterFenceDevices = ({
cluster: Cluster;
}) => {
const { sortState, compareItems } = SortableTh.useSorting<COLUMNS>("NAME");

if (!cluster.hasCibInfo) {
return (
<EmptyStateClusterStopped
title="Cannot get fence devices from stopped cluster"
clusterName={cluster.name}
/>
);
}

if (cluster.fenceDeviceList.length === 0) {
return (
<EmptyStateNoItem
Expand Down
10 changes: 10 additions & 0 deletions src/app/view/dashboard/clusterList/DashboardClusterResources.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Cluster, Resource } from "app/view/cluster/types";
import {
EmptyStateClusterStopped,
EmptyStateNoItem,
Link,
ResourceStatusInfoListSigns,
Expand Down Expand Up @@ -34,6 +35,15 @@ export const DashboardClusterResources = ({
}) => {
const { sortState, compareItems } = SortableTh.useSorting<COLUMNS>("NAME");

if (!cluster.hasCibInfo) {
return (
<EmptyStateClusterStopped
title="Cannot get resources from stopped cluster"
clusterName={cluster.name}
/>
);
}

if (cluster.resourceTree.length === 0) {
return (
<EmptyStateNoItem
Expand Down
6 changes: 4 additions & 2 deletions src/app/view/share/ClusterStatusLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ const statusColorMap: Record<
Cluster["status"],
React.ComponentProps<typeof Label>["color"]
> = {
started: "green",
stopped: "orange",
running: "green",
degraded: "gold",
inoperative: "orange",
offline: "red",
unknown: "grey",
};

Expand Down
54 changes: 35 additions & 19 deletions src/app/view/share/ClusterStoppedInfo.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,45 @@
import { useSelectedClusterName } from "app/view/share/SelectedClusterContext";
import { Label } from "@patternfly/react-core";

import { LauncherActionList } from "app/view/share/toolbar";

export const ClusterStoppedInfo = () => {
const clusterName = useSelectedClusterName();
export const ClusterStoppedInfo = ({
clusterName,
startButton,
}: {
clusterName: string;
startButton?: "button" | "link";
}) => {
return (
<>
<div>Cluster is stopped. You can start cluster on detail tab.</div>
<div>
<LauncherActionList
name="stopped-cluster-actions"
items={[
{
name: "start cluster",
confirm: {
title: "Start cluster?",
description: "Start the on all nodes",
action: {
type: "DASHBOARD.CLUSTER.START",
payload: { clusterName },
{startButton && (
<div>
<LauncherActionList
name="stopped-cluster-actions"
items={[
{
name: "start cluster",
confirm: {
title: "Start the cluster?",
description: (
<span>
Start the cluster{" "}
<Label color="blue">{clusterName}</Label> on all nodes
</span>
),
action: {
type: "DASHBOARD.CLUSTER.START",
payload: { clusterName },
},
},
button: {
variant: startButton === "button" ? "secondary" : "link",
},
},
},
]}
/>
</div>
]}
/>
</div>
)}
</>
);
};
Loading

0 comments on commit 84a8392

Please sign in to comment.