Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide ENSA version info to Wanda #2088

Merged
merged 5 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 5 additions & 1 deletion assets/js/pages/ClusterDetails/ClusterDetailsPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
getCluster,
getClusterHosts,
getClusterSapSystems,
getEnsaVersion,
} from '@state/selectors/cluster';
import { getCatalog } from '@state/selectors/catalog';
import { getLastExecution } from '@state/selectors/lastExecutions';
Expand All @@ -32,18 +33,21 @@ export function ClusterDetailsPage() {

const lastExecution = useSelector(getLastExecution(clusterID));

const ensaVersion = useSelector((state) => getEnsaVersion(state, clusterID));

useEffect(() => {
if (provider && type) {
dispatch(
updateCatalog({
provider,
target_type: TARGET_CLUSTER,
cluster_type: type,
ensa_version: ensaVersion,
})
);
dispatch(updateLastExecution(clusterID));
}
}, [dispatch, provider, type]);
}, [dispatch, provider, type, ensaVersion]);

const clusterHosts = useSelector((state) =>
getClusterHosts(state, clusterID)
Expand Down
16 changes: 16 additions & 0 deletions assets/js/state/selectors/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,22 @@ export const getClusterSapSystems = createSelector(
}
);

export const MIXED_VERSIONS = 'mixed_versions';

export const getEnsaVersion = createSelector(
[getClusterSapSystems],
(sapSystems) => {
const ensaVersions = new Set();
sapSystems.forEach(({ ensa_version }) => ensaVersions.add(ensa_version));

const firstEnsaVersion = [...ensaVersions.values()][0];

return firstEnsaVersion && ensaVersions.size === 1
? firstEnsaVersion
: MIXED_VERSIONS;
}
);

export const getClusterSelectedChecks = createSelector(
[(state, clusterID) => getCluster(clusterID)(state)],
(cluster) => get(cluster, 'selected_checks', [])
Expand Down
177 changes: 177 additions & 0 deletions assets/js/state/selectors/cluster.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import {
getClusterSapSystems,
getClusterSelectedChecks,
getClusterIDs,
MIXED_VERSIONS,
getEnsaVersion,
} from './cluster';

describe('Cluster selector', () => {
Expand Down Expand Up @@ -205,4 +207,179 @@ describe('Cluster selector', () => {

expect(getClusterIDs(state)).toEqual([clusterID1, clusterID2]);
});

it('should return ENSA version', () => {
const clusterID = faker.string.uuid();
const cluster = clusterFactory.build({ id: clusterID });

const sapSystems = sapSystemFactory.buildList(2, { ensa_version: 'ensa1' });
const [{ id: sapSystem1 }, { id: sapSystem2 }] = sapSystems;

const hosts = hostFactory
.buildList(4, { cluster_id: clusterID })
.concat(hostFactory.buildList(2));
const [{ id: host1 }, { id: host2 }, { id: host3 }, { id: host4 }] = hosts;

const applicationInstances = [
sapSystemApplicationInstanceFactory.build({
sap_system_id: sapSystem1,
host_id: host1,
}),
sapSystemApplicationInstanceFactory.build({
sap_system_id: sapSystem2,
host_id: host2,
}),
];

const databases = databaseFactory.buildList(4);

const databaseInstances = [
databaseInstanceFactory.build({
sap_system_id: sapSystem1,
host_id: host3,
}),
databaseInstanceFactory.build({
sap_system_id: sapSystem2,
host_id: host4,
}),
];

const state = {
hostsList: {
hosts,
},
databasesList: {
databases,
databaseInstances,
},
sapSystemsList: {
sapSystems,
applicationInstances,
databaseInstances,
},
clustersList: {
clusters: [cluster],
},
};

expect(getEnsaVersion(state, clusterID)).toEqual('ensa1');
});

it('should return mixed ENSA versions', () => {
const clusterID = faker.string.uuid();
const cluster = clusterFactory.build({ id: clusterID });

const sapSystems = [
sapSystemFactory.build({ ensa_version: 'ensa1' }),
sapSystemFactory.build({ ensa_version: 'ensa2' }),
];
const [{ id: sapSystem1 }, { id: sapSystem2 }] = sapSystems;

const hosts = hostFactory
.buildList(4, { cluster_id: clusterID })
.concat(hostFactory.buildList(2));
const [{ id: host1 }, { id: host2 }, { id: host3 }, { id: host4 }] = hosts;

const applicationInstances = [
sapSystemApplicationInstanceFactory.build({
sap_system_id: sapSystem1,
host_id: host1,
}),
sapSystemApplicationInstanceFactory.build({
sap_system_id: sapSystem2,
host_id: host2,
}),
];

const databases = databaseFactory.buildList(4);

const databaseInstances = [
databaseInstanceFactory.build({
sap_system_id: sapSystem1,
host_id: host3,
}),
databaseInstanceFactory.build({
sap_system_id: sapSystem2,
host_id: host4,
}),
];

const state = {
hostsList: {
hosts,
},
databasesList: {
databases,
databaseInstances,
},
sapSystemsList: {
sapSystems,
applicationInstances,
databaseInstances,
},
clustersList: {
clusters: [cluster],
},
};

expect(getEnsaVersion(state, clusterID)).toEqual(MIXED_VERSIONS);
});

it('should return mixed ENSA versions if SAP system does not have ENSA version info', () => {
const clusterID = faker.string.uuid();
const cluster = clusterFactory.build({ id: clusterID });

const sapSystems = sapSystemFactory.buildList(2, { ensa_version: 'ensa1' });
const [{ id: sapSystem1 }, { id: sapSystem2 }] = sapSystems;

const hosts = hostFactory
.buildList(4, { cluster_id: clusterID })
.concat(hostFactory.buildList(2));
const [{ id: host1 }, { id: host2 }, { id: host3 }, { id: host4 }] = hosts;

const applicationInstances = [
sapSystemApplicationInstanceFactory.build({
sap_system_id: sapSystem1,
host_id: host1,
}),
sapSystemApplicationInstanceFactory.build({
sap_system_id: sapSystem2,
host_id: host2,
}),
];

const databases = databaseFactory.buildList(4);
const [{ id: database1 }, { id: database2 }] = databases;

const databaseInstances = [
databaseInstanceFactory.build({
sap_system_id: database1,
host_id: host3,
}),
databaseInstanceFactory.build({
sap_system_id: database2,
host_id: host4,
}),
];

const state = {
hostsList: {
hosts,
},
databasesList: {
databases,
databaseInstances,
},
sapSystemsList: {
sapSystems,
applicationInstances,
databaseInstances,
},
clustersList: {
clusters: [cluster],
},
};

expect(getEnsaVersion(state, clusterID)).toEqual(MIXED_VERSIONS);
});
});