-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mgr/dashboard: display placement column in service table
Fixes: https://tracker.ceph.com/issues/44404 Signed-off-by: Volker Theile <[email protected]>
- Loading branch information
Showing
5 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/placement.pipe.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { PlacementPipe } from './placement.pipe'; | ||
|
||
describe('PlacementPipe', () => { | ||
const pipe = new PlacementPipe(); | ||
|
||
it('create an instance', () => { | ||
expect(pipe).toBeTruthy(); | ||
}); | ||
|
||
it('transforms to no spec', () => { | ||
expect(pipe.transform(undefined)).toBe('no spec'); | ||
}); | ||
|
||
it('transforms to unmanaged', () => { | ||
expect(pipe.transform({ unmanaged: true })).toBe('unmanaged'); | ||
}); | ||
|
||
it('transforms placement (1)', () => { | ||
expect( | ||
pipe.transform({ | ||
placement: { | ||
hosts: ['mon0'] | ||
} | ||
}) | ||
).toBe('mon0'); | ||
}); | ||
|
||
it('transforms placement (2)', () => { | ||
expect( | ||
pipe.transform({ | ||
placement: { | ||
hosts: ['mon0', 'mgr0'] | ||
} | ||
}) | ||
).toBe('mon0;mgr0'); | ||
}); | ||
|
||
it('transforms placement (3)', () => { | ||
expect( | ||
pipe.transform({ | ||
placement: { | ||
count: 1 | ||
} | ||
}) | ||
).toBe('count:1'); | ||
}); | ||
|
||
it('transforms placement (4)', () => { | ||
expect( | ||
pipe.transform({ | ||
placement: { | ||
label: 'foo' | ||
} | ||
}) | ||
).toBe('label:foo'); | ||
}); | ||
|
||
it('transforms placement (5)', () => { | ||
expect( | ||
pipe.transform({ | ||
placement: { | ||
host_pattern: '*' | ||
} | ||
}) | ||
).toBe('*'); | ||
}); | ||
|
||
it('transforms placement (6)', () => { | ||
expect( | ||
pipe.transform({ | ||
placement: { | ||
count: 2, | ||
hosts: ['mon0', 'mgr0'] | ||
} | ||
}) | ||
).toBe('mon0;mgr0;count:2'); | ||
}); | ||
}); |
41 changes: 41 additions & 0 deletions
41
src/pybind/mgr/dashboard/frontend/src/app/ceph/cluster/services/placement.pipe.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import { Pipe, PipeTransform } from '@angular/core'; | ||
|
||
import _ from 'lodash'; | ||
|
||
@Pipe({ | ||
name: 'placement' | ||
}) | ||
export class PlacementPipe implements PipeTransform { | ||
/** | ||
* Convert the placement configuration into human readable form. | ||
* The output is equal to the column 'PLACEMENT' in 'ceph orch ls'. | ||
* @param serviceSpec The service specification to process. | ||
* @return The placement configuration as human readable string. | ||
*/ | ||
transform(serviceSpec: object | undefined): string { | ||
if (_.isUndefined(serviceSpec)) { | ||
return $localize`no spec`; | ||
} | ||
if (_.get(serviceSpec, 'unmanaged', false)) { | ||
return $localize`unmanaged`; | ||
} | ||
const kv: Array<any> = []; | ||
const hosts: Array<string> = _.get(serviceSpec, 'placement.hosts'); | ||
const count: number = _.get(serviceSpec, 'placement.count'); | ||
const label: string = _.get(serviceSpec, 'placement.label'); | ||
const hostPattern: string = _.get(serviceSpec, 'placement.host_pattern'); | ||
if (_.isArray(hosts)) { | ||
kv.push(...hosts); | ||
} | ||
if (_.isNumber(count)) { | ||
kv.push($localize`count:${count}`); | ||
} | ||
if (_.isString(label)) { | ||
kv.push($localize`label:${label}`); | ||
} | ||
if (_.isString(hostPattern)) { | ||
kv.push(...hostPattern); | ||
} | ||
return kv.join(';'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters