// Creates a block image and fills in the name, pool, and size fields. Then checks
// if the image is present in the Images table.
- async createImage(name, pool, size) {
+ async createImage(name: string, pool: string, size: string) {
await this.navigateTo('create');
// Need the string '[value="<pool>"]' to find the pool in the dropdown menu
return this.waitPresence(this.getFirstTableCellWithText(name));
}
- async editImage(name, pool, newName, newSize) {
+ async editImage(name: string, pool: string, newName: string, newSize: string) {
const base_url = '/#/block/rbd/edit/';
const editURL = base_url
.concat(encodeURIComponent(pool))
// Selects RBD image and moves it to the trash, checks that it is present in the
// trash table
- async moveToTrash(name) {
+ async moveToTrash(name: string) {
await this.navigateTo();
// wait for image to be created
await this.waitTextNotPresent($$('.datatable-body').first(), '(Creating...)');
// Checks trash tab table for image and then restores it to the RBD Images table
// (could change name if new name is given)
- async restoreImage(name, newName?: string) {
+ async restoreImage(name: string, newName?: string) {
await this.navigateTo();
// clicks on trash tab
await element(by.cssContainingText('.nav-link', 'Trash')).click();
// Enters trash tab and purges trash, thus emptying the trash table. Checks if
// Image is still in the table.
- async purgeTrash(name, pool?: string) {
+ async purgeTrash(name: string, pool?: string) {
await this.navigateTo();
// clicks trash tab
await element(by.cssContainingText('.nav-link', 'Trash')).click();
* pool and chooses an option (either pool, image, or disabled)
*/
@PageHelper.restrictTo(pages.index)
- async editMirror(name, option) {
+ async editMirror(name: string, option: string) {
// Clicks the pool in the table
await this.waitClickableAndClick(this.getFirstTableCellWithText(name));
index: '/#/configuration'
};
- async configClear(name) {
+ async configClear(name: string) {
// Clears out all the values in a config to reset before and after testing
// Does not work for configs with checkbox only, possible future PR
}
}
- async edit(name, ...values: [string, string][]) {
+ async edit(name: string, ...values: [string, string][]) {
// Clicks the designated config, then inputs the values passed into the edit function.
// Then checks if the edit is reflected in the config table. Takes in name of config and
// a list of tuples of values the user wants edited, each tuple having the desired value along
return $('cd-crushmap .card-header').getText();
}
- getCrushNode(idx) {
+ getCrushNode(idx: number) {
return $$('.node-name.type-osd').get(idx);
}
}
export class LogsPageHelper extends PageHelper {
pages = { index: '/#/logs' };
- async checkAuditForPoolFunction(poolname, poolfunction, hour, minute) {
+ async checkAuditForPoolFunction(
+ poolname: string,
+ poolfunction: string,
+ hour: number,
+ minute: number
+ ) {
await this.navigateTo();
// sometimes the modal from deleting pool is still present at this point.
await expect(logs.getText()).toMatch(`pool ${poolfunction}`);
}
- async checkAuditForConfigChange(configname, setting, hour, minute) {
+ async checkAuditForConfigChange(
+ configname: string,
+ setting: string,
+ hour: number,
+ minute: number
+ ) {
await this.navigateTo();
// go to audit logs tab
await this.waitVisibility(this.getFirstTableCellWithText('devicehealth'));
// Checks for visibility of devicehealth in table
await this.getFirstTableCellWithText('devicehealth').click();
- for (let i = 0, devHealthTuple; (devHealthTuple = devHealthArray[i]); i++) {
+ for (let i = 0, devHealthTuple: [string, string]; (devHealthTuple = devHealthArray[i]); i++) {
if (devHealthTuple[0] !== undefined) {
await this.waitFn(async () => {
// Repeatedly reclicks the module to check if edits has been done
await this.navigateTo();
await this.waitVisibility(this.getFirstTableCellWithText('devicehealth'));
await this.getFirstTableCellWithText('devicehealth').click();
- for (let i = 0, devHealthTuple; (devHealthTuple = devHealthArray[i]); i++) {
+ for (let i = 0, devHealthTuple: [string, string]; (devHealthTuple = devHealthArray[i]); i++) {
if (devHealthTuple[0] !== undefined) {
await this.waitFn(async () => {
// Repeatedly reclicks the module to check if clearing has been done
* help developers to prevent and highlight mistakes. It also reduces boilerplate code and by
* thus, increases readability.
*/
- static restrictTo(page): Function {
+ static restrictTo(page: string): Function {
return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
const fn: Function = descriptor.value;
- descriptor.value = function(...args) {
+ descriptor.value = function(...args: any) {
return browser
.getCurrentUrl()
.then((url) =>
return $('.breadcrumb-item.active');
}
- async getTabText(index): Promise<string> {
+ async getTabText(index: number): Promise<string> {
return $$('.nav.nav-tabs li')
.get(index)
.getText();
return element.all(by.cssContainingText('.datatable-body-cell-label', content)).first();
}
- getTableRow(content) {
+ getTableRow(content: string) {
return element(by.cssContainingText('.datatable-body-row', content));
}
}
}
- async navigateTo(page = null) {
+ async navigateTo(page: string = null) {
page = page || 'index';
const url = this.pages[page];
await browser.get(url);
return element(by.cssContainingText('button', 'Cancel')).click();
}
- async testInvalidEdit(name) {
+ async testInvalidEdit(name: string) {
await this.navigateTo();
await this.waitClickableAndClick(this.getFirstTableCellWithText(name)); // wait for table to load and click
pages = pages;
@PageHelper.restrictTo(pages.create)
- async create(username, fullname, email, maxbuckets) {
+ async create(username: string, fullname: string, email: string, maxbuckets: string) {
// Enter in username
await element(by.id('uid')).sendKeys(username);
}
@PageHelper.restrictTo(pages.index)
- async edit(name, new_fullname, new_email, new_maxbuckets) {
+ async edit(name: string, new_fullname: string, new_email: string, new_maxbuckets: string) {
await this.waitClickableAndClick(this.getFirstTableCellWithText(name)); // wait for table to load and click
await element(by.cssContainingText('button', 'Edit')).click(); // click button to move to edit page
create: '/#/user-management/roles/create'
};
- async create(name, description): Promise<void> {
+ async create(name: string, description: string): Promise<void> {
await this.navigateTo('create');
// fill in fields
await this.waitPresence(this.getFirstTableCellWithText(name));
}
- async edit(name, description): Promise<void> {
+ async edit(name: string, description: string): Promise<void> {
await this.navigateTo();
await this.getFirstTableCellWithText(name).click(); // select role from table
create: '/#/user-management/users/create'
};
- async create(username, password, name, email): Promise<void> {
+ async create(username: string, password: string, name: string, email: string): Promise<void> {
await this.navigateTo('create');
// fill in fields
await this.waitPresence(this.getFirstTableCellWithText(username));
}
- async edit(username, password, name, email): Promise<void> {
+ async edit(username: string, password: string, name: string, email: string): Promise<void> {
await this.navigateTo();
await this.getFirstTableCellWithText(username).click(); // select user from table
"integrity": "sha512-lMC2G0ItF2xv4UCiwbJGbnJlIuUixHrioOhNGHSCsYCJ8l4t9hMCUimCytvFv7qy6AfSzRxhRHoGa+UqaqwyeA==",
"dev": true
},
+ "@types/simplebar": {
+ "version": "2.4.2",
+ "resolved": "https://registry.npmjs.org/@types/simplebar/-/simplebar-2.4.2.tgz",
+ "integrity": "sha512-omSnWgcQ5hGANK8MijABHDNtj7bM2GH80g8wVqeRmaePJ2lPN4RmbrVihEbYtnovW2aS51a0joITsb6+Q1HnnA=="
+ },
"@types/source-list-map": {
"version": "0.1.2",
"resolved": "https://registry.npmjs.org/@types/source-list-map/-/source-list-map-0.1.2.tgz",
"@types/jest": "24.0.23",
"@types/lodash": "4.14.141",
"@types/node": "12.7.8",
+ "@types/simplebar": "2.4.2",
"codelyzer": "5.1.2",
"html-linter": "1.1.1",
"htmllint-cli": "0.0.7",
},
{
provide: TRANSLATIONS,
- useFactory: (locale) => {
+ useFactory: (locale: string) => {
locale = locale || environment.default_lang;
try {
return require(`raw-loader!locale/messages.${locale}.xlf`).default;
this.url = this.router.url;
}
- navigateTo(url) {
+ navigateTo(url: string) {
this.router.navigate([url]);
}
}
}
};
- const disks = [];
+ const disks: any[] = [];
_.forEach(this.selectedItem.disks, (disk) => {
const id = 'disk_' + disk.pool + '_' + disk.image;
this.metadata[id] = {
});
});
- const portals = [];
+ const portals: any[] = [];
_.forEach(this.selectedItem.portals, (portal) => {
portals.push({ value: `${portal.host}:${portal.ip}` });
});
- const clients = [];
+ const clients: any[] = [];
_.forEach(this.selectedItem.clients, (client) => {
const client_metadata = _.cloneDeep(client.auth);
if (client.info) {
}
this.metadata['client_' + client.client_iqn] = client_metadata;
- const luns = [];
- client.luns.forEach((lun) => {
+ const luns: any[] = [];
+ client.luns.forEach((lun: Record<string, any>) => {
luns.push({
value: `${lun.pool}/${lun.image}`,
id: 'disk_' + lun.pool + '_' + lun.image,
});
});
- const groups = [];
+ const groups: any[] = [];
_.forEach(this.selectedItem.groups, (group) => {
- const luns = [];
- group.disks.forEach((disk) => {
+ const luns: any[] = [];
+ group.disks.forEach((disk: Record<string, any>) => {
luns.push({
value: `${disk.pool}/${disk.image}`,
id: 'disk_' + disk.pool + '_' + disk.image
});
});
- const initiators = [];
- group.members.forEach((member) => {
+ const initiators: any[] = [];
+ group.members.forEach((member: string) => {
initiators.push({
value: member,
id: 'client_' + member
};
}
- private format(value) {
+ private format(value: any) {
if (typeof value === 'boolean') {
return this.booleanTextPipe.transform(value);
}
let httpTesting: HttpTestingController;
let req: TestRequest;
- const elem = (css) => fixture.debugElement.query(By.css(css));
- const elemDisabled = (css) => elem(css).nativeElement.disabled;
+ const elem = (css: string) => fixture.debugElement.query(By.css(css));
+ const elemDisabled = (css: string) => elem(css).nativeElement.disabled;
configureTestBed({
declarations: [IscsiTargetDiscoveryModalComponent],
api_version: 1
};
- const LIST_TARGET = [
+ const LIST_TARGET: any[] = [
{
target_iqn: 'iqn.2003-01.com.redhat.iscsi-gw:iscsi-igw',
portals: [{ host: 'node1', ip: '192.168.100.201' }],
ceph_iscsi_config_version: 11
};
- const RBD_LIST = [
+ const RBD_LIST: any[] = [
{ status: 0, value: [], pool_name: 'ganesha' },
{
status: 0,
// iscsiService.portals()
const portals: SelectOption[] = [];
- data[2].forEach((portal) => {
- portal.ip_addresses.forEach((ip) => {
+ data[2].forEach((portal: Record<string, any>) => {
+ portal.ip_addresses.forEach((ip: string) => {
portals.push(new SelectOption(false, portal.name + ':' + ip, ''));
});
});
target_controls: new FormControl({}),
portals: new FormControl([], {
validators: [
- CdValidators.custom('minGateways', (value) => {
+ CdValidators.custom('minGateways', (value: any[]) => {
const gateways = _.uniq(value.map((elem) => elem.split(':')[0]));
return gateways.length < Math.max(1, this.minimum_gateways);
})
}),
disks: new FormControl([], {
validators: [
- CdValidators.custom('dupLunId', (value) => {
+ CdValidators.custom('dupLunId', (value: any[]) => {
const lunIds = this.getLunIds(value);
return lunIds.length !== _.uniq(lunIds).length;
}),
- CdValidators.custom('dupWwn', (value) => {
+ CdValidators.custom('dupWwn', (value: any[]) => {
const wwns = this.getWwns(value);
return wwns.length !== _.uniq(wwns).length;
})
}
}
- resolveModel(res) {
+ resolveModel(res: Record<string, any>) {
this.targetForm.patchValue({
target_iqn: res.target_iqn,
target_controls: res.target_controls,
auth: res.auth
});
}
- const portals = [];
+ const portals: any[] = [];
_.forEach(res.portals, (portal) => {
const id = `${portal.host}:${portal.ip}`;
portals.push(id);
portals: portals
});
- const disks = [];
+ const disks: any[] = [];
_.forEach(res.disks, (disk) => {
const id = `${disk.pool}/${disk.image}`;
disks.push(id);
return false;
}
- removeImageRefs(name) {
+ removeImageRefs(name: string) {
this.initiators.controls.forEach((element) => {
- const newImages = element.value.luns.filter((item) => item !== name);
+ const newImages = element.value.luns.filter((item: string) => item !== name);
element.get('luns').setValue(newImages);
});
this.groups.controls.forEach((element) => {
- const newDisks = element.value.disks.filter((item) => item !== name);
+ const newDisks = element.value.disks.filter((item: string) => item !== name);
element.get('disks').setValue(newDisks);
});
});
}
- getDefaultBackstore(imageId) {
+ getDefaultBackstore(imageId: string) {
let result = this.default_backstore;
const image = this.getImageById(imageId);
if (!this.validFeatures(image, this.default_backstore)) {
return result;
}
- isLunIdInUse(lunId, imageId) {
- const images = this.disks.value.filter((currentImageId) => currentImageId !== imageId);
+ isLunIdInUse(lunId: string, imageId: string) {
+ const images = this.disks.value.filter((currentImageId: string) => currentImageId !== imageId);
return this.getLunIds(images).includes(lunId);
}
- getLunIds(images) {
+ getLunIds(images: object) {
return _.map(images, (image) => this.imagesSettings[image]['lun']);
}
- nextLunId(imageId) {
- const images = this.disks.value.filter((currentImageId) => currentImageId !== imageId);
+ nextLunId(imageId: string) {
+ const images = this.disks.value.filter((currentImageId: string) => currentImageId !== imageId);
const lunIdsInUse = this.getLunIds(images);
let lunIdCandidate = 0;
while (lunIdsInUse.includes(lunIdCandidate)) {
return lunIdCandidate;
}
- getWwns(images) {
+ getWwns(images: object) {
const wwns = _.map(images, (image) => this.imagesSettings[image]['wwn']);
return wwns.filter((wwn) => _.isString(wwn) && wwn !== '');
}
- onImageSelection($event) {
+ onImageSelection($event: any) {
const option = $event.option;
if (option.selected) {
client_iqn: new FormControl('', {
validators: [
Validators.required,
- CdValidators.custom('notUnique', (client_iqn) => {
+ CdValidators.custom('notUnique', (client_iqn: string) => {
const flattened = this.initiators.controls.reduce(function(accumulator, currentValue) {
return accumulator.concat(currentValue.value.client_iqn);
}, []);
);
}
- removeInitiator(index) {
+ removeInitiator(index: number) {
const removed = this.initiators.value[index];
this.initiators.removeAt(index);
});
this.groups.controls.forEach((element) => {
- const newMembers = element.value.members.filter((item) => item !== removed.client_iqn);
+ const newMembers = element.value.members.filter(
+ (item: string) => item !== removed.client_iqn
+ );
element.get('members').setValue(newMembers);
});
});
}
- removeInitiatorImage(initiator: any, lun_index: number, initiator_index: string, image: string) {
+ removeInitiatorImage(initiator: any, lun_index: number, initiator_index: number, image: string) {
const luns = initiator.getValue('luns');
luns.splice(lun_index, 1);
initiator.patchValue({ luns: luns });
- this.imagesInitiatorSelections[initiator_index].forEach((value) => {
+ this.imagesInitiatorSelections[initiator_index].forEach((value: Record<string, any>) => {
if (value.name === image) {
value.selected = false;
}
return fg;
}
- removeGroup(index) {
+ removeGroup(index: number) {
this.groups.removeAt(index);
this.groupDiskSelections.splice(index, 1);
}
- onGroupMemberSelection($event) {
+ onGroupMemberSelection($event: any) {
const option = $event.option;
let initiator_index: number;
});
}
- removeGroupInitiator(group, member_index, group_index) {
+ removeGroupInitiator(group: CdFormGroup, member_index: number, group_index: number) {
const name = group.getValue('members')[member_index];
group.getValue('members').splice(member_index, 1);
this.onGroupMemberSelection({ option: new SelectOption(false, name, '') });
}
- removeGroupDisk(group, disk_index, group_index) {
+ removeGroupDisk(group: CdFormGroup, disk_index: number, group_index: number) {
const name = group.getValue('disks')[disk_index];
group.getValue('disks').splice(disk_index, 1);
submit() {
const formValue = _.cloneDeep(this.targetForm.value);
- const request = {
+ const request: Record<string, any> = {
target_iqn: this.targetForm.getValue('target_iqn'),
target_controls: this.targetForm.getValue('target_controls'),
acl_enabled: this.targetForm.getValue('acl_enabled'),
}
// Disks
- formValue.disks.forEach((disk) => {
+ formValue.disks.forEach((disk: string) => {
const imageSplit = disk.split('/');
const backstore = this.imagesSettings[disk].backstore;
request.disks.push({
});
// Portals
- formValue.portals.forEach((portal) => {
+ formValue.portals.forEach((portal: string) => {
const index = portal.indexOf(':');
request.portals.push({
host: portal.substring(0, index),
// Clients
if (request.acl_enabled) {
- formValue.initiators.forEach((initiator) => {
+ formValue.initiators.forEach((initiator: Record<string, any>) => {
if (!initiator.auth.user) {
initiator.auth.user = '';
}
}
delete initiator.cdIsInGroup;
- const newLuns = [];
- initiator.luns.forEach((lun) => {
+ const newLuns: any[] = [];
+ initiator.luns.forEach((lun: string) => {
const imageSplit = lun.split('/');
newLuns.push({
pool: imageSplit[0],
// Groups
if (request.acl_enabled) {
- formValue.groups.forEach((group) => {
- const newDisks = [];
- group.disks.forEach((disk) => {
+ formValue.groups.forEach((group: Record<string, any>) => {
+ const newDisks: any[] = [];
+ group.disks.forEach((disk: string) => {
const imageSplit = disk.split('/');
newDisks.push({
pool: imageSplit[0],
this.modalRef = this.modalService.show(IscsiTargetIqnSettingsModalComponent, { initialState });
}
- imageSettingsModal(image) {
+ imageSettingsModal(image: string) {
const initialState = {
imagesSettings: this.imagesSettings,
image: image,
});
}
- validFeatures(image, backstore) {
+ validFeatures(image: Record<string, any>, backstore: string) {
const imageFeatures = image.features;
const requiredFeatures = this.required_rbd_features[backstore];
const unsupportedFeatures = this.unsupported_rbd_features[backstore];
return validRequiredFeatures && validSupportedFeatures;
}
- getImageById(imageId) {
+ getImageById(imageId: string) {
return this.imagesAll.find((image) => imageId === `${image.pool_name}/${image.name}`);
}
- getValidBackstores(image) {
+ getValidBackstores(image: object) {
return this.backstores.filter((backstore) => this.validFeatures(image, backstore));
}
}
constructor(public modalRef: BsModalRef, public iscsiService: IscsiService) {}
ngOnInit() {
- const fg = {
+ const fg: Record<string, FormControl> = {
backstore: new FormControl(this.imagesSettings[this.image]['backstore']),
lun: new FormControl(this.imagesSettings[this.image]['lun']),
wwn: new FormControl(this.imagesSettings[this.image]['wwn'])
this.settingsForm = new CdFormGroup(fg);
}
- getDiskControlLimits(backstore, setting) {
+ getDiskControlLimits(backstore: string, setting: string) {
if (this.disk_controls_limits) {
return this.disk_controls_limits[backstore][setting];
}
constructor(public modalRef: BsModalRef, public iscsiService: IscsiService) {}
ngOnInit() {
- const fg = {};
+ const fg: Record<string, FormControl> = {};
_.forIn(this.target_default_controls, (_value, key) => {
fg[key] = new FormControl(this.target_controls.value[key]);
});
this.modalRef.hide();
}
- getTargetControlLimits(setting) {
+ getTargetControlLimits(setting: string) {
if (this.target_controls_limits) {
return this.target_controls_limits[setting];
}
let summaryService: SummaryService;
let iscsiService: IscsiService;
- const refresh = (data) => {
+ const refresh = (data: any) => {
summaryService['summaryDataSource'].next(data);
};
describe('handling of executing tasks', () => {
let targets: any[];
- const addTarget = (name) => {
+ const addTarget = (name: string) => {
const model: any = {
target_iqn: name,
portals: [{ host: 'node1', ip: '192.168.100.201' }],
import { CdTableSelection } from '../../../shared/models/cd-table-selection';
import { FinishedTask } from '../../../shared/models/finished-task';
import { Permission } from '../../../shared/models/permissions';
+import { Task } from '../../../shared/models/task';
import { CephReleaseNamePipe } from '../../../shared/pipes/ceph-release-name.pipe';
import { NotAvailablePipe } from '../../../shared/pipes/not-available.pipe';
import { AuthStorageService } from '../../../shared/services/auth-storage.service';
status: string;
summaryDataSubscription: Subscription;
tableActions: CdTableAction[];
- targets = [];
+ targets: any[] = [];
icons = Icons;
builders = {
- 'iscsi/target/create': (metadata) => {
+ 'iscsi/target/create': (metadata: object) => {
return {
target_iqn: metadata['target_iqn']
};
}
prepareResponse(resp: any): any[] {
- resp.forEach((element) => {
- element.cdPortals = element.portals.map((portal) => `${portal.host}:${portal.ip}`);
- element.cdImages = element.disks.map((disk) => `${disk.pool}/${disk.image}`);
+ resp.forEach((element: Record<string, any>) => {
+ element.cdPortals = element.portals.map(
+ (portal: Record<string, any>) => `${portal.host}:${portal.ip}`
+ );
+ element.cdImages = element.disks.map(
+ (disk: Record<string, any>) => `${disk.pool}/${disk.image}`
+ );
});
return resp;
this.table.reset(); // Disable loading indicator.
}
- itemFilter(entry, task) {
+ itemFilter(entry: Record<string, any>, task: Task) {
return entry.target_iqn === task.metadata['target_iqn'];
}
- taskFilter(task) {
+ taskFilter(task: Task) {
return ['iscsi/target/create', 'iscsi/target/edit', 'iscsi/target/delete'].includes(task.name);
}
let component: IscsiComponent;
let fixture: ComponentFixture<IscsiComponent>;
let iscsiService: IscsiService;
- let tcmuiscsiData;
+ let tcmuiscsiData: Record<string, any>;
const fakeService = {
overview: () => {
@ViewChild('iscsiRelativeDateTpl', { static: true })
iscsiRelativeDateTpl: TemplateRef<any>;
- gateways = [];
+ gateways: any[] = [];
gatewaysColumns: any;
- images = [];
+ images: any[] = [];
imagesColumns: any;
constructor(
}
refresh() {
- this.iscsiService.overview().subscribe((overview: Array<any>) => {
+ this.iscsiService.overview().subscribe((overview: object) => {
this.gateways = overview['gateways'];
this.images = overview['images'];
this.images.map((image) => {
if (image.stats_history) {
- image.stats_history.rd_bytes = image.stats_history.rd_bytes.map((i) => i[1]);
- image.stats_history.wr_bytes = image.stats_history.wr_bytes.map((i) => i[1]);
+ image.stats_history.rd_bytes = image.stats_history.rd_bytes.map((i: any) => i[1]);
+ image.stats_history.wr_bytes = image.stats_history.wr_bytes.map((i: any) => i[1]);
}
image.cdIsBinary = true;
return image;
import { CdFormGroup } from '../../../../shared/forms/cd-form-group';
import { FinishedTask } from '../../../../shared/models/finished-task';
import { TaskWrapperService } from '../../../../shared/services/task-wrapper.service';
+import { Pool } from '../../../pool/pool';
@Component({
selector: 'cd-bootstrap-create-modal',
}
const pools = data.content_data.pools;
- this.pools = pools.reduce((acc, pool) => {
+ this.pools = pools.reduce((acc: any[], pool: Pool) => {
acc.push({
name: pool['name'],
mirror_mode: pool['mirror_mode']
),
this.rbdMirroringService
.createBootstrapToken(bootstrapPoolName)
- .pipe(tap((data) => this.createBootstrapForm.get('token').setValue(data['token'])))
+ .pipe(tap((data: any) => this.createBootstrapForm.get('token').setValue(data['token'])))
).pipe(last());
const finishHandler = () => {
import { CdFormGroup } from '../../../../shared/forms/cd-form-group';
import { FinishedTask } from '../../../../shared/models/finished-task';
import { TaskWrapperService } from '../../../../shared/services/task-wrapper.service';
+import { Pool } from '../../../pool/pool';
@Component({
selector: 'cd-bootstrap-import-modal',
}
const pools = data.content_data.pools;
- this.pools = pools.reduce((acc, pool) => {
+ this.pools = pools.reduce((acc: any[], pool: Pool) => {
acc.push({
name: pool['name'],
mirror_mode: pool['mirror_mode']
subs: Subscription;
- image_error = {
+ image_error: Record<string, any> = {
data: [],
columns: {}
};
- image_syncing = {
+ image_syncing: Record<string, any> = {
data: [],
columns: {}
};
- image_ready = {
+ image_ready: Record<string, any> = {
data: [],
columns: {}
};
import { CdTableSelection } from '../../../../shared/models/cd-table-selection';
import { Permission } from '../../../../shared/models/permissions';
import { AuthStorageService } from '../../../../shared/services/auth-storage.service';
+import { Pool } from '../../../pool/pool';
import { BootstrapCreateModalComponent } from '../bootstrap-create-modal/bootstrap-create-modal.component';
import { BootstrapImportModalComponent } from '../bootstrap-import-modal/bootstrap-import-modal.component';
import { EditSiteNameModalComponent } from '../edit-site-name-modal/edit-site-name-modal.component';
this.status = data.content_data.status;
this.siteName = data.site_name;
- this.peersExist = !!data.content_data.pools.find((o) => o['peer_uuids'].length > 0);
+ this.peersExist = !!data.content_data.pools.find((o: Pool) => o['peer_uuids'].length > 0);
});
}
}
const poolData = data.content_data.pools;
- const pool = poolData.find((o) => this.poolName === o['name']);
+ const pool = poolData.find((o: any) => this.poolName === o['name']);
this.peerExists = pool && pool['peer_uuids'].length;
});
}
this.modalRef = this.modalService.show(PoolEditModeModalComponent, { initialState });
}
- editPeersModal(mode) {
+ editPeersModal(mode: string) {
const initialState = {
poolName: this.selection.first().name,
mode: mode
});
}
- getPeerUUID() {
+ getPeerUUID(): any {
const selection = this.selection.first();
const pool = this.data.find((o) => selection && selection.name === o['name']);
if (pool && pool['peer_uuids']) {
const expected = sections
.map((section) => section.options)
.reduce((a, b) => a.concat(b))
- .map((option) => option.name);
+ .map((option: Record<string, any>) => option.name);
expect(actual).toEqual(expected);
/* Test form creation on a template level */
it('should return dirty values without any units', () => {
let dirtyValues = {};
- component.changes.subscribe((getDirtyValues) => {
+ component.changes.subscribe((getDirtyValues: Function) => {
dirtyValues = getDirtyValues();
});
});
describe('should verify that getDirtyValues() returns correctly', () => {
- let data;
+ let data: any;
beforeEach(() => {
component.initializeData = new EventEmitter<any>();
it('should also return all local values if they do not contain their initial values', () => {
// Change value for all options
- data.initialData = data.initialData.map((o) => {
+ data.initialData = data.initialData.map((o: Record<string, any>) => {
o.value = 22;
return o;
});
});
if (this.initializeData) {
- this.initializeData.subscribe((data) => {
+ this.initializeData.subscribe((data: Record<string, any>) => {
this.initialData = data.initialData;
const dataType = data.sourceType;
this.rbdConfigurationService.getWritableOptionFields().forEach((option) => {
- const optionData = data.initialData.filter((entry) => entry.name === option.name).pop();
+ const optionData = data.initialData
+ .filter((entry: Record<string, any>) => entry.name === option.name)
+ .pop();
if (optionData && optionData['source'] === dataType) {
this.form.get(`configuration.${option.name}`).setValue(optionData['value']);
}
const result = {};
this.rbdConfigurationService.getWritableOptionFields().forEach((config) => {
- const control = this.form.get('configuration').get(config.name);
+ const control: any = this.form.get('configuration').get(config.name);
const dirty = control.dirty;
if (this.initialData && this.initialData[config.name] === control.value) {
* Reset the value. The inherited value will be used instead.
*/
reset(optionName: string) {
- const formControl = this.form.get('configuration').get(optionName);
+ const formControl: any = this.form.get('configuration').get(optionName);
if (formControl.disabled) {
formControl.setValue(formControl['previousValue'] || 0);
formControl.enable();
return this.form.get('configuration').get(optionName).disabled;
}
- toggleSectionVisibility(className) {
+ toggleSectionVisibility(className: string) {
this.sectionVisibility[className] = !this.sectionVisibility[className];
}
}
value: '100'
}
];
- const filter = (keyword) => {
+ const filter = (keyword: string) => {
poolConfTable.search = keyword;
poolConfTable.updateFilter();
return poolConfTable.rows;
import { ImageSpec } from '../../../shared/models/image-spec';
import { SharedModule } from '../../../shared/shared.module';
import { RbdConfigurationFormComponent } from '../rbd-configuration-form/rbd-configuration-form.component';
+import { RbdImageFeature } from './rbd-feature.interface';
import { RbdFormMode } from './rbd-form-mode.enum';
import { RbdFormComponent } from './rbd-form.component';
let fixture: ComponentFixture<RbdFormComponent>;
let activatedRoute: ActivatedRouteStub;
- const queryNativeElement = (cssSelector) =>
+ const queryNativeElement = (cssSelector: string) =>
fixture.debugElement.query(By.css(cssSelector)).nativeElement;
configureTestBed({
});
describe('create/edit/clone/copy image', () => {
- let createAction;
- let editAction;
- let cloneAction;
- let copyAction;
- let rbdServiceGetSpy;
+ let createAction: jasmine.Spy;
+ let editAction: jasmine.Spy;
+ let cloneAction: jasmine.Spy;
+ let copyAction: jasmine.Spy;
+ let rbdServiceGetSpy: jasmine.Spy;
beforeEach(() => {
createAction = spyOn(component, 'createAction').and.stub();
});
describe('tests for feature flags', () => {
- let deepFlatten, layering, exclusiveLock, objectMap, journaling, fastDiff;
+ let deepFlatten: any,
+ layering: any,
+ exclusiveLock: any,
+ objectMap: any,
+ journaling: any,
+ fastDiff: any;
const defaultFeatures = [
// Supposed to be enabled by default
'deep-flatten',
'journaling',
'fast-diff'
];
- const setFeatures = (features) => {
+ const setFeatures = (features: Record<string, RbdImageFeature>) => {
component.features = features;
component.featuresList = component.objToArray(features);
component.createForm();
import { AuthStorageService } from '../../../shared/services/auth-storage.service';
import { FormatterService } from '../../../shared/services/formatter.service';
import { TaskWrapperService } from '../../../shared/services/task-wrapper.service';
+import { Pool } from '../../pool/pool';
import { RbdImageFeature } from './rbd-feature.interface';
import { RbdFormCloneRequestModel } from './rbd-form-clone-request.model';
import { RbdFormCopyRequestModel } from './rbd-form-copy-request.model';
namespaces: Array<string> = [];
namespacesByPoolCache = {};
- pools: Array<string> = null;
- allPools: Array<string> = null;
+ pools: Array<Pool> = null;
+ allPools: Array<Pool> = null;
dataPools: Array<string> = null;
allDataPools: Array<string> = null;
features: { [key: string]: RbdImageFeature };
}),
obj_size: new FormControl(this.defaultObjectSize),
features: new CdFormGroup(
- this.featuresList.reduce((acc, e) => {
+ this.featuresList.reduce((acc: object, e) => {
acc[e.key] = new FormControl({ value: false, disabled: !!e.initDisabled });
return acc;
}, {})
forkJoin(promisses).subscribe((data: object) => {
// poolService.list
if (data[Promisse.PoolServiceList]) {
- const pools = [];
+ const pools: Pool[] = [];
const dataPools = [];
for (const pool of data[Promisse.PoolServiceList]) {
if (this.rbdService.isRBDPool(pool)) {
this.dataPools = dataPools;
this.allDataPools = dataPools;
if (this.pools.length === 1) {
- const poolName = this.pools[0]['pool_name'];
+ const poolName = this.pools[0].pool_name;
this.rbdForm.get('pool').setValue(poolName);
this.onPoolChange(poolName);
}
});
}
- onPoolChange(selectedPoolName) {
+ onPoolChange(selectedPoolName: string) {
const newDataPools = this.allDataPools
? this.allDataPools.filter((dataPool: any) => {
return dataPool.pool_name !== selectedPoolName;
}
}
- onDataPoolChange(selectedDataPoolName) {
- const newPools = this.allPools.filter((pool: any) => {
+ onDataPoolChange(selectedDataPoolName: string) {
+ const newPools = this.allPools.filter((pool: Pool) => {
return pool.pool_name !== selectedDataPoolName;
});
if (this.rbdForm.getValue('pool') === selectedDataPoolName) {
return _.filter(this.features, (f) => f.requires === featureKey) || [];
}
- deepBoxCheck(key, checked) {
+ deepBoxCheck(key: string, checked: boolean) {
const childFeatures = this.getDependendChildFeatures(key);
childFeatures.forEach((feature) => {
const featureControl = this.rbdForm.get(feature.key);
});
}
- interlockCheck(key, checked) {
+ interlockCheck(key: string, checked: boolean) {
// Adds a compatibility layer for Ceph cluster where the feature interlock of features hasn't
// been implemented yet. It disables the feature interlock for images which only have one of
// both interlocked features (at the time of this writing: object-map and fast-diff) enabled.
}
}
- featureFormUpdate(key, checked) {
+ featureFormUpdate(key: string, checked: boolean) {
if (checked) {
const required = this.features[key].requires;
if (required && !this.rbdForm.getValue(required)) {
let summaryService: SummaryService;
let rbdService: RbdService;
- const refresh = (data) => {
+ const refresh = (data: any) => {
summaryService['summaryDataSource'].next(data);
};
describe('handling of executing tasks', () => {
let images: RbdModel[];
- const addImage = (name) => {
+ const addImage = (name: string) => {
const model = new RbdModel();
model.id = '-1';
model.name = name;
it('should gets all images without tasks', () => {
expect(component.images.length).toBe(3);
- expect(component.images.every((image) => !image.cdExecuting)).toBeTruthy();
+ expect(component.images.every((image: any) => !image.cdExecuting)).toBeTruthy();
});
it('should add a new image from a task', () => {
import { FinishedTask } from '../../../shared/models/finished-task';
import { ImageSpec } from '../../../shared/models/image-spec';
import { Permission } from '../../../shared/models/permissions';
+import { Task } from '../../../shared/models/task';
import { DimlessBinaryPipe } from '../../../shared/pipes/dimless-binary.pipe';
import { DimlessPipe } from '../../../shared/pipes/dimless.pipe';
import { AuthStorageService } from '../../../shared/services/auth-storage.service';
modalRef: BsModalRef;
builders = {
- 'rbd/create': (metadata) =>
+ 'rbd/create': (metadata: object) =>
this.createRbdFromTask(metadata['pool_name'], metadata['namespace'], metadata['image_name']),
- 'rbd/delete': (metadata) => this.createRbdFromTaskImageSpec(metadata['image_spec']),
- 'rbd/clone': (metadata) =>
+ 'rbd/delete': (metadata: object) => this.createRbdFromTaskImageSpec(metadata['image_spec']),
+ 'rbd/clone': (metadata: object) =>
this.createRbdFromTask(
metadata['child_pool_name'],
metadata['child_namespace'],
metadata['child_image_name']
),
- 'rbd/copy': (metadata) =>
+ 'rbd/copy': (metadata: object) =>
this.createRbdFromTask(
metadata['dest_pool_name'],
metadata['dest_namespace'],
}
];
- const itemFilter = (entry, task) => {
+ const itemFilter = (entry: Record<string, any>, task: Task) => {
let taskImageSpec: string;
switch (task.name) {
case 'rbd/copy':
);
};
- const taskFilter = (task) => {
+ const taskFilter = (task: Task) => {
return [
'rbd/clone',
'rbd/copy',
}
prepareResponse(resp: any[]): any[] {
- let images = [];
+ let images: any[] = [];
const viewCacheStatusMap = {};
resp.forEach((pool) => {
if (_.isUndefined(viewCacheStatusMap[pool.status])) {
viewCacheStatusMap[pool.status].push(pool.pool_name);
images = images.concat(pool.value);
});
- const viewCacheStatusList = [];
+ const viewCacheStatusList: any[] = [];
_.forEach(viewCacheStatusMap, (value: any, key) => {
viewCacheStatusList.push({
status: parseInt(key, 10),
import { Permission } from '../../../shared/models/permissions';
import { AuthStorageService } from '../../../shared/services/auth-storage.service';
import { NotificationService } from '../../../shared/services/notification.service';
+import { Pool } from '../../pool/pool';
@Component({
selector: 'cd-rbd-namespace-form',
})
export class RbdNamespaceFormComponent implements OnInit {
poolPermission: Permission;
- pools: Array<string> = null;
+ pools: Array<Pool> = null;
pool: string;
namespace: string;
if (this.poolPermission.read) {
this.poolService.list(['pool_name', 'type', 'application_metadata']).then((resp) => {
- const pools = [];
+ const pools: Pool[] = [];
for (const pool of resp) {
if (this.rbdService.isRBDPool(pool) && pool.type === 'replicated') {
pools.push(pool);
import { BsModalRef, BsModalService } from 'ngx-bootstrap/modal';
import * as _ from 'lodash';
-import { forkJoin } from 'rxjs';
+import { forkJoin, Observable } from 'rxjs';
import { PoolService } from '../../../shared/api/pool.service';
import { RbdService } from '../../../shared/api/rbd.service';
import { CriticalConfirmationModalComponent } from '../../../shared/components/critical-confirmation-modal/critical-confirmation-modal.component';
refresh() {
this.poolService.list(['pool_name', 'type', 'application_metadata']).then((pools: any) => {
- pools = pools.filter((pool) => this.rbdService.isRBDPool(pool) && pool.type === 'replicated');
- const promisses = [];
- pools.forEach((pool) => {
+ pools = pools.filter(
+ (pool: any) => this.rbdService.isRBDPool(pool) && pool.type === 'replicated'
+ );
+ const promisses: Observable<any>[] = [];
+ pools.forEach((pool: any) => {
promisses.push(this.rbdService.listNamespaces(pool['pool_name']));
});
if (promisses.length > 0) {
forkJoin(promisses).subscribe((data: Array<Array<string>>) => {
- const result = [];
+ const result: any[] = [];
for (let i = 0; i < data.length; i++) {
const namespaces = data[i];
const pool_name = pools[i]['pool_name'];
this.onSubmit = new Subject();
}
- setSnapName(snapName) {
+ setSnapName(snapName: string) {
this.snapName = snapName;
this.snapshotForm.get('snapshotName').setValue(snapName);
}
});
describe('api delete request', () => {
- let called;
+ let called: boolean;
let rbdService: RbdService;
let notificationService: NotificationService;
let authStorageService: AuthStorageService;
describe('handling of executing tasks', () => {
let snapshots: RbdSnapshotModel[];
- const addSnapshot = (name) => {
+ const addSnapshot = (name: string) => {
const model = new RbdSnapshotModel();
model.id = 1;
model.name = name;
summaryService.addRunningTask(task);
};
- const refresh = (data) => {
+ const refresh = (data: any) => {
summaryService['summaryDataSource'].next(data);
};
import { FinishedTask } from '../../../shared/models/finished-task';
import { ImageSpec } from '../../../shared/models/image-spec';
import { Permission } from '../../../shared/models/permissions';
+import { Task } from '../../../shared/models/task';
import { CdDatePipe } from '../../../shared/pipes/cd-date.pipe';
import { DimlessBinaryPipe } from '../../../shared/pipes/dimless-binary.pipe';
import { AuthStorageService } from '../../../shared/services/auth-storage.service';
modalRef: BsModalRef;
builders = {
- 'rbd/snap/create': (metadata) => {
+ 'rbd/snap/create': (metadata: any) => {
const model = new RbdSnapshotModel();
model.name = metadata['snapshot_name'];
return model;
actions.deleteSnap.click = () => this.deleteSnapshotModal();
this.tableActions = actions.ordering;
- const itemFilter = (entry, task) => {
+ const itemFilter = (entry: any, task: Task) => {
return entry.name === task.metadata['snapshot_name'];
};
- const taskFilter = (task) => {
+ const taskFilter = (task: Task) => {
return (
['rbd/snap/create', 'rbd/snap/delete', 'rbd/snap/edit', 'rbd/snap/rollback'].includes(
task.name
describe('handling of executing tasks', () => {
let images: any[];
- const addImage = (id) => {
+ const addImage = (id: string) => {
images.push({
id: id,
pool_name: 'pl'
it('should gets all images without tasks', () => {
expect(component.images.length).toBe(2);
- expect(component.images.every((image) => !image.cdExecuting)).toBeTruthy();
+ expect(
+ component.images.every((image: Record<string, any>) => !image.cdExecuting)
+ ).toBeTruthy();
});
it('should show when an existing image is being modified', () => {
import { FinishedTask } from '../../../shared/models/finished-task';
import { ImageSpec } from '../../../shared/models/image-spec';
import { Permission } from '../../../shared/models/permissions';
+import { Task } from '../../../shared/models/task';
import { CdDatePipe } from '../../../shared/pipes/cd-date.pipe';
import { AuthStorageService } from '../../../shared/services/auth-storage.service';
import { TaskListService } from '../../../shared/services/task-list.service';
}
];
- const itemFilter = (entry, task) => {
+ const itemFilter = (entry: any, task: Task) => {
const imageSpec = new ImageSpec(entry.pool_name, entry.namespace, entry.id);
return imageSpec.toString() === task.metadata['image_id_spec'];
};
- const taskFilter = (task) => {
+ const taskFilter = (task: Task) => {
return ['rbd/trash/remove', 'rbd/trash/restore'].includes(task.name);
};
}
prepareResponse(resp: any[]): any[] {
- let images = [];
+ let images: any[] = [];
const viewCacheStatusMap = {};
- resp.forEach((pool) => {
+ resp.forEach((pool: Record<string, any>) => {
if (_.isUndefined(viewCacheStatusMap[pool.status])) {
viewCacheStatusMap[pool.status] = [];
}
images = images.concat(pool.value);
});
- const viewCacheStatusList = [];
+ const viewCacheStatusList: any[] = [];
_.forEach(viewCacheStatusMap, (value: any, key) => {
viewCacheStatusList.push({
status: parseInt(key, 10),
});
}
- isExpired(expiresAt): boolean {
+ isExpired(expiresAt: string): boolean {
return moment().isAfter(expiresAt);
}
});
describe('should call moveImage', () => {
- let notificationService;
+ let notificationService: NotificationService;
beforeEach(() => {
notificationService = TestBed.get(NotificationService);
expiresAt: [
'',
[
- CdValidators.custom('format', (expiresAt) => {
+ CdValidators.custom('format', (expiresAt: string) => {
const result = expiresAt === '' || moment(expiresAt, 'YYYY-MM-DD HH:mm:ss').isValid();
return !result;
}),
- CdValidators.custom('expired', (expiresAt) => {
+ CdValidators.custom('expired', (expiresAt: string) => {
const result = moment().isAfter(expiresAt);
return result;
})
-import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
+import {
+ HttpClientTestingModule,
+ HttpTestingController,
+ TestRequest
+} from '@angular/common/http/testing';
import { ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';
describe('should call purge', () => {
let notificationService: NotificationService;
let modalRef: BsModalRef;
- let req;
+ let req: TestRequest;
beforeEach(() => {
fixture.detectChanges();
import { Permission } from '../../../shared/models/permissions';
import { AuthStorageService } from '../../../shared/services/auth-storage.service';
import { TaskWrapperService } from '../../../shared/services/task-wrapper.service';
+import { Pool } from '../../pool/pool';
@Component({
selector: 'cd-rbd-trash-purge-modal',
if (this.poolPermission.read) {
this.poolService.list(['pool_name', 'application_metadata']).then((resp) => {
this.pools = resp
- .filter((pool) => pool.application_metadata.includes('rbd'))
- .map((pool) => pool.pool_name);
+ .filter((pool: Pool) => pool.application_metadata.includes('rbd'))
+ .map((pool: Pool) => pool.pool_name);
});
}
-import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
+import {
+ HttpClientTestingModule,
+ HttpTestingController,
+ TestRequest
+} from '@angular/common/http/testing';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { ReactiveFormsModule } from '@angular/forms';
import { RouterTestingModule } from '@angular/router/testing';
let httpTesting: HttpTestingController;
let notificationService: NotificationService;
let modalRef: BsModalRef;
- let req;
+ let req: TestRequest;
beforeEach(() => {
httpTesting = TestBed.get(HttpTestingController);
const chartTooltip = new ChartTooltip(
this.chartCanvas,
this.chartTooltip,
- (tooltip) => tooltip.caretX + 'px',
- (tooltip) => tooltip.caretY - tooltip.height - 23 + 'px'
+ (tooltip: any) => tooltip.caretX + 'px',
+ (tooltip: any) => tooltip.caretY - tooltip.height - 23 + 'px'
);
chartTooltip.getTitle = (ts) => moment(ts, 'x').format('LTS');
chartTooltip.checkOffset = true;
* can handle (list of objects with millisecs-since-epoch
* timestamps)
*/
- private convertTimeSeries(sourceSeries) {
- const data = [];
+ private convertTimeSeries(sourceSeries: any) {
+ const data: any[] = [];
_.each(sourceSeries, (dp) => {
data.push({
x: dp[0] * 1000,
return data;
}
- private deltaTimeSeries(sourceSeries) {
+ private deltaTimeSeries(sourceSeries: any) {
let i;
let prev = sourceSeries[0];
const result = [];
let component: CephfsDetailComponent;
let fixture: ComponentFixture<CephfsDetailComponent>;
- const updateDetails = (standbys, pools, ranks, mdsCounters, name) => {
+ const updateDetails = (
+ standbys: string,
+ pools: any[],
+ ranks: any[],
+ mdsCounters: object,
+ name: string
+ ) => {
component.data = {
standbys,
pools,
ranks: CdTableColumn[];
pools: CdTableColumn[];
};
- standbys = [];
+ standbys: any[] = [];
objectValues = Object.values;
{
name: this.i18n('Usage'),
cellTemplate: this.poolUsageTpl,
- comparator: (_valueA, _valueB, rowA, rowB) => {
+ comparator: (_valueA: any, _valueB: any, rowA: any, rowB: any) => {
const valA = rowA.used / rowA.avail;
const valB = rowB.used / rowB.avail;
};
}
- trackByFn(_index, item) {
+ trackByFn(_index: any, item: any) {
return item.name;
}
}
let component: CephfsDirectoriesComponent;
let fixture: ComponentFixture<CephfsDirectoriesComponent>;
let cephfsService: CephfsService;
- let lsDirSpy;
- let modalShowSpy;
- let notificationShowSpy;
- let minValidator;
- let maxValidator;
- let minBinaryValidator;
- let maxBinaryValidator;
- let originalDate;
- let modal;
+ let lsDirSpy: jasmine.Spy;
+ let modalShowSpy: jasmine.Spy;
+ let notificationShowSpy: jasmine.Spy;
+ let minValidator: jasmine.Spy;
+ let maxValidator: jasmine.Spy;
+ let minBinaryValidator: jasmine.Spy;
+ let maxBinaryValidator: jasmine.Spy;
+ let originalDate: any;
+ let modal: any;
// Get's private attributes or functions
const get = {
});
return of(data);
},
- mkSnapshot: (_id, path, name) => {
+ mkSnapshot: (_id: any, path: string, name: string) => {
mockData.createdSnaps.push({
name,
path,
});
return of(name);
},
- rmSnapshot: (_id, path, name) => {
+ rmSnapshot: (_id: any, path: string, name: string) => {
mockData.deletedSnaps.push({
name,
path,
});
return of(name);
},
- updateQuota: (_id, path, updated: CephfsQuotas) => {
+ updateQuota: (_id: any, path: string, updated: CephfsQuotas) => {
mockData.updatedQuotas[path] = Object.assign(mockData.updatedQuotas[path] || {}, updated);
return of('Response');
},
- modalShow: (comp, init) => {
+ modalShow: (comp: any, init: any) => {
modal = modalServiceShow(comp, init);
return modal.ref;
},
- date: (arg) => (arg ? new originalDate(arg) : new Date('2022-02-22T00:00:00')),
+ date: (arg: string) => (arg ? new originalDate(arg) : new Date('2022-02-22T00:00:00')),
getControllerByPath: (path: string) => {
return {
expand: () => mockLib.expand(path),
noQuota: (key: 'bytes' | 'files') => {
assert.quotaRow(key, '', 0, '');
},
- quotaIsNotInherited: (key: 'bytes' | 'files', shownValue, nextMaximum) => {
+ quotaIsNotInherited: (key: 'bytes' | 'files', shownValue: any, nextMaximum: number) => {
const dir = component.selectedDir;
const path = dir.path;
assert.quotaRow(key, shownValue, nextMaximum, path);
},
- quotaIsInherited: (key: 'bytes' | 'files', shownValue, path) => {
+ quotaIsInherited: (key: 'bytes' | 'files', shownValue: any, path: string) => {
const isBytes = key === 'bytes';
const nextMaximum = get.nodeIds()[path].quotas[isBytes ? 'max_bytes' : 'max_files'];
assert.quotaRow(key, shownValue, nextMaximum, path);
}
});
},
- quotaUnsetModalTexts: (titleText, message, notificationMsg) => {
+ quotaUnsetModalTexts: (titleText: string, message: string, notificationMsg: string) => {
expect(modalShowSpy).toHaveBeenCalledWith(ConfirmationModalComponent, {
initialState: expect.objectContaining({
titleText,
});
expect(notificationShowSpy).toHaveBeenCalledWith(NotificationType.success, notificationMsg);
},
- quotaUpdateModalTexts: (titleText, message, notificationMsg) => {
+ quotaUpdateModalTexts: (titleText: string, message: string, notificationMsg: string) => {
expect(modalShowSpy).toHaveBeenCalledWith(FormModalComponent, {
initialState: expect.objectContaining({
titleText,
return this.dirs.filter((d) => d.parent.startsWith(path));
}
- selectOrigin(path) {
+ selectOrigin(path: string) {
this.treeComponent.getControllerByNodeId(path).select();
}
}
private setSettings(node: Tree) {
- const readable = (value: number, fn?: (number) => number | string): number | string =>
+ const readable = (value: number, fn?: (number: number) => number | string): number | string =>
value ? (fn ? fn(value) : value) : '';
this.settings = [
private getQuota(
tree: Tree,
quotaKey: string,
- valueConvertFn: (number) => number | string
+ valueConvertFn: (number: number) => number | string
): QuotaSetting {
// Get current maximum
const currentPath = tree.id;
: undefined,
fields: [this.getQuotaFormField(selection.row.name, key, value, nextMax.value)],
submitButtonText: this.i18n('Save'),
- onSubmit: (values) => this.updateQuota(values)
+ onSubmit: (values: CephfsQuotas) => this.updateQuota(values)
}
});
}
}
],
submitButtonText: this.i18n('Create Snapshot'),
- onSubmit: (values) => {
+ onSubmit: (values: CephfsSnapshot) => {
this.cephfsService.mkSnapshot(this.id, path, values.name).subscribe((name) => {
this.notificationService.show(
NotificationType.success,
};
let old: any;
- const getReload = () => component['reloadSubscriber'];
- const setReload = (sth?) => (component['reloadSubscriber'] = sth);
+ const getReload: any = () => component['reloadSubscriber'];
+ const setReload = (sth?: any) => (component['reloadSubscriber'] = sth);
const mockRunOutside = () => {
component['subscribeInterval'] = () => {
// It's mocked because the rxjs timer subscription ins't called through the use of 'tick'.
});
it('should set default values on id change before api request', () => {
- const defaultDetails = {
+ const defaultDetails: Record<string, any> = {
standbys: '',
pools: [],
ranks: [],
mdsCounters: {},
name: ''
};
- const defaultClients = {
+ const defaultClients: Record<string, any> = {
data: [],
status: ViewCacheStatus.ValueNone
};
import { Component, Input, NgZone, OnChanges, OnDestroy } from '@angular/core';
import * as _ from 'lodash';
-import { timer } from 'rxjs';
+import { Subscription, timer } from 'rxjs';
import { CephfsService } from '../../../shared/api/cephfs.service';
import { ViewCacheStatus } from '../../../shared/enum/view-cache-status.enum';
// Client tab
id: number;
- clients = {
+ clients: Record<string, any> = {
data: [],
status: ViewCacheStatus.ValueNone
};
// Details tab
- details = {
+ details: Record<string, any> = {
standbys: '',
pools: [],
ranks: [],
};
private data: any;
- private reloadSubscriber;
+ private reloadSubscriber: Subscription;
constructor(
private ngZone: NgZone,
}
}
- private setupSelected(id, mdsInfo) {
+ private setupSelected(id: number, mdsInfo: any) {
this.id = id;
- const firstMds = _.first(Object.values(mdsInfo));
+ const firstMds: any = _.first(Object.values(mdsInfo));
this.grafanaId = firstMds && firstMds['name'];
this.details = {
standbys: '',
}
createRequest(): ConfigFormCreateRequestModel | null {
- const values = [];
+ const values: any[] = [];
this.availSections.forEach((section) => {
const sectionValue = this.configForm.getValue(section);
export class ConfigurationComponent implements OnInit {
permission: Permission;
tableActions: CdTableAction[];
- data = [];
+ data: any[] = [];
icons = Icons;
columns: CdTableColumn[];
selection = new CdTableSelection();
tree: TreeModel;
metadata: any;
metadataTitle: string;
- metadataKeyMap: { [key: number]: number } = {};
+ metadataKeyMap: { [key: number]: any } = {};
constructor(private healthService: HealthService) {}
};
}
- const roots = [];
- nodes.reverse().forEach((node) => {
+ const roots: any[] = [];
+ nodes.reverse().forEach((node: any) => {
if (node.type === 'root') {
roots.push(node.id);
}
};
}
- private generateTreeLeaf(node: any, treeNodeMap) {
+ private generateTreeLeaf(node: any, treeNodeMap: any) {
const id = node.id;
this.metadataKeyMap[id] = node;
const settings = { static: true };
const children: any[] = [];
const resultNode = { value, status, settings, id, type: node.type };
if (node.children) {
- node.children.sort().forEach((childId) => {
+ node.children.sort().forEach((childId: any) => {
children.push(treeNodeMap[childId]);
});
describe('HostsComponent', () => {
let component: HostsComponent;
let fixture: ComponentFixture<HostsComponent>;
- let hostListSpy;
+ let hostListSpy: jasmine.Spy;
const fakeAuthStorageService = {
getPermissions: () => {
this.hostService.list().subscribe(
(resp: any[]) => {
resp.map((host) => {
- host.services.map((service) => {
+ host.services.map((service: any) => {
service.cdLink = `/perf_counters/${service.type}/${encodeURIComponent(service.id)}`;
const permission = this.permissions[typeToPermissionKey[service.type]];
service.canRead = permission ? permission.read : false;
}
],
submitButtonText: this.i18n('Execute'),
- onSubmit: (values) => {
+ onSubmit: (values: any) => {
this.orchService.identifyDevice(hostname, device, values.duration).subscribe(() => {
this.notificationService.show(
NotificationType.success,
});
describe('filterLogs', () => {
- const contentData = {
+ const contentData: Record<string, any> = {
clog: [
{
name: 'priority',
error = false;
loading = false;
moduleName = '';
- moduleOptions = [];
+ moduleOptions: any[] = [];
constructor(
private route: ActivatedRoute,
});
}
- getValidators(moduleOption): ValidatorFn[] {
+ getValidators(moduleOption: any): ValidatorFn[] {
const result = [];
switch (moduleOption.type) {
case 'addr':
beforeEach(() => {
fixture = TestBed.createComponent(MonitorComponent);
component = fixture.componentInstance;
- const getMonitorPayload = {
+ const getMonitorPayload: Record<string, any> = {
in_quorum: [
{
stats: { num_sessions: [[1, 5]] }
prop: 'cdOpenSessions',
name: this.i18n('Open Sessions'),
cellTransformation: CellTemplate.sparkline,
- comparator: (dataA, dataB) => {
+ comparator: (dataA: any, dataB: any) => {
// We get the last value of time series to compare:
const lastValueA = _.last(dataA);
const lastValueB = _.last(dataB);
refresh() {
this.monitorService.getMonitor().subscribe((data: any) => {
- data.in_quorum.map((row) => {
- row.cdOpenSessions = row.stats.num_sessions.map((i) => i[1]);
+ data.in_quorum.map((row: any) => {
+ row.cdOpenSessions = row.stats.num_sessions.map((i: string) => i[1]);
row.cdLink = '/perf_counters/mon/' + row.name;
row.cdParams = { fromLink: '/monitor' };
return row;
});
- data.out_quorum.map((row) => {
+ data.out_quorum.map((row: any) => {
row.cdLink = '/perf_counters/mon/' + row.name;
row.cdParams = { fromLink: '/monitor' };
return row;
let fixture: ComponentFixture<OsdDetailsComponent>;
let debugElement: DebugElement;
let osdService: OsdService;
- let getDetailsSpy;
+ let getDetailsSpy: jasmine.Spy;
configureTestBed({
imports: [HttpClientTestingModule, TabsModule.forRoot(), SharedModule],
i18nProviders
} from '../../../../../testing/unit-test-helper';
import { SharedModule } from '../../../../shared/shared.module';
+import { InventoryDevice } from '../../inventory/inventory-devices/inventory-device.model';
import { InventoryDevicesComponent } from '../../inventory/inventory-devices/inventory-devices.component';
import { OsdDevicesSelectionGroupsComponent } from './osd-devices-selection-groups.component';
let component: OsdDevicesSelectionGroupsComponent;
let fixture: ComponentFixture<OsdDevicesSelectionGroupsComponent>;
let fixtureHelper: FixtureHelper;
- const devices = [
+ const devices: InventoryDevice[] = [
{
hostname: 'node0',
uid: '1',
spyOn(component.cleared, 'emit');
fixtureHelper.clickElement(clearTextSelector);
fixtureHelper.expectElementVisible('cd-inventory-devices', false);
- const event = {
+ const event: Record<string, any> = {
type: undefined,
clearedDevices: devices
};
icons = Icons;
devices: InventoryDevice[] = [];
- appliedFilters = [];
+ appliedFilters: any[] = [];
constructor(private bsModalService: BsModalService) {}
allDevices: InventoryDevice[] = [];
availDevices: InventoryDevice[] = [];
- dataDeviceFilters = [];
- dbDeviceFilters = [];
- walDeviceFilters = [];
+ dataDeviceFilters: any[] = [];
+ dbDeviceFilters: any[] = [];
+ walDeviceFilters: any[] = [];
hostname = '';
driveGroup = new DriveGroup();
validators: [Validators.min(0)]
}),
features: new CdFormGroup(
- this.featureList.reduce((acc, e) => {
+ this.featureList.reduce((acc: object, e) => {
// disable initially because no data devices are selected
acc[e.key] = new FormControl({ value: false, disabled: true });
return acc;
}
};
- const getTableAction = (name) => component.tableActions.find((action) => action.name === name);
+ const getTableAction = (name: string) =>
+ component.tableActions.find((action) => action.name === name);
const setFakeSelection = () => {
// Default data and selection
component.permissions = fakeAuthStorageService.getPermissions();
};
- const openActionModal = (actionName) => {
+ const openActionModal = (actionName: string) => {
setFakeSelection();
getTableAction(actionName).click();
};
});
describe('getOsdList', () => {
- let osds;
-
- const createOsd = (n: number) => ({
- in: 'in',
- up: 'up',
- tree: {
- device_class: 'ssd'
- },
- stats_history: {
- op_out_bytes: [[n, n], [n * 2, n * 2]],
- op_in_bytes: [[n * 3, n * 3], [n * 4, n * 4]]
- },
- stats: {
- stat_bytes_used: n * n,
- stat_bytes: n * n * n
- },
- state: []
- });
+ let osds: any[];
+
+ const createOsd = (n: number) =>
+ <Record<string, any>>{
+ in: 'in',
+ up: 'up',
+ tree: {
+ device_class: 'ssd'
+ },
+ stats_history: {
+ op_out_bytes: [[n, n], [n * 2, n * 2]],
+ op_in_bytes: [[n * 3, n * 3], [n * 4, n * 4]]
+ },
+ stats: {
+ stat_bytes_used: n * n,
+ stat_bytes: n * n * n
+ },
+ state: []
+ };
const expectAttributeOnEveryOsd = (attr: string) =>
expect(component.osds.every((osd) => Boolean(_.get(osd, attr)))).toBeTruthy();
*
* @param modalClass - The expected class of the modal
*/
- const expectOpensModal = (actionName: string, modalClass): void => {
+ const expectOpensModal = (actionName: string, modalClass: any): void => {
openActionModal(actionName);
// @TODO: check why tsc is complaining when passing 'expectationFailOutput' param.
icons = Icons;
selection = new CdTableSelection();
- osds = [];
+ osds: any[] = [];
- protected static collectStates(osd) {
+ protected static collectStates(osd: any) {
const states = [osd['in'] ? 'in' : 'out'];
if (osd['up']) {
states.push('up');
this.osdService.getList().subscribe((data: any[]) => {
this.osds = data.map((osd) => {
osd.collectedStates = OsdListComponent.collectStates(osd);
- osd.stats_history.out_bytes = osd.stats_history.op_out_bytes.map((i) => i[1]);
- osd.stats_history.in_bytes = osd.stats_history.op_in_bytes.map((i) => i[1]);
+ osd.stats_history.out_bytes = osd.stats_history.op_out_bytes.map((i: string) => i[1]);
+ osd.stats_history.in_bytes = osd.stats_history.op_in_bytes.map((i: string) => i[1]);
osd.stats.usage = osd.stats.stat_bytes_used / osd.stats.stat_bytes;
osd.cdIsBinary = true;
return osd;
}
],
submitButtonText: this.i18n('Edit OSD'),
- onSubmit: (values) => {
+ onSubmit: (values: any) => {
this.osdService.update(selectedOsd.id, values.deviceClass).subscribe(() => {
this.notificationService.show(
NotificationType.success,
});
}
- scrubAction(deep) {
+ scrubAction(deep: boolean) {
if (!this.hasOsdSelected) {
return;
}
this.render();
}
- hexdigits(v): string {
+ hexdigits(v: number): string {
const i = Math.floor(v * 255).toString(16);
return i.length === 1 ? '0' + i : i;
}
- hexcolor(r, g, b) {
+ hexcolor(r: number, g: number, b: number) {
return '#' + this.hexdigits(r) + this.hexdigits(g) + this.hexdigits(b);
}
});
});
- this.valuesStyle = this.histogram.values.map((row, i) => {
- return row.map((col, j) => {
+ this.valuesStyle = this.histogram.values.map((row: any, i: number) => {
+ return row.map((col: any, j: number) => {
const val = this.last && this.last[i] && this.last[i][j] ? col - this.last[i][j] : col;
const g = max ? val / max : 0;
const r = 1 - g;
providers: [BsModalRef, i18nProviders]
});
- let configOptions = [];
+ let configOptions: any[] = [];
beforeEach(() => {
fixture = TestBed.createComponent(OsdRecvSpeedModalComponent);
});
describe('ngOnInit', () => {
- let setPriority;
- let setValidators;
+ let setPriority: jasmine.Spy;
+ let setValidators: jasmine.Spy;
beforeEach(() => {
setPriority = spyOn(component, 'setPriority').and.callThrough();
};
it('should return priority "low" if the config option values have been set accordingly', () => {
- component.detectPriority(configOptionsLow, (priority) => {
+ component.detectPriority(configOptionsLow, (priority: Record<string, any>) => {
expect(priority.name).toBe('low');
});
expect(component.osdRecvSpeedForm.getValue('customizePriority')).toBeFalsy();
});
it('should return priority "default" if the config option values have been set accordingly', () => {
- component.detectPriority(configOptionsDefault, (priority) => {
+ component.detectPriority(configOptionsDefault, (priority: Record<string, any>) => {
expect(priority.name).toBe('default');
});
expect(component.osdRecvSpeedForm.getValue('customizePriority')).toBeFalsy();
});
it('should return priority "high" if the config option values have been set accordingly', () => {
- component.detectPriority(configOptionsHigh, (priority) => {
+ component.detectPriority(configOptionsHigh, (priority: Record<string, any>) => {
expect(priority.name).toBe('high');
});
expect(component.osdRecvSpeedForm.getValue('customizePriority')).toBeFalsy();
});
it('should return priority "custom" if the config option values do not match any priority', () => {
- component.detectPriority(configOptionsCustom, (priority) => {
+ component.detectPriority(configOptionsCustom, (priority: Record<string, any>) => {
expect(priority.name).toBe('custom');
});
expect(component.osdRecvSpeedForm.getValue('customizePriority')).toBeTruthy();
});
it('should return no priority if the config option values are incomplete', () => {
- component.detectPriority(configOptionsIncomplete, (priority) => {
+ component.detectPriority(configOptionsIncomplete, (priority: Record<string, any>) => {
expect(priority.name).toBeNull();
});
expect(component.osdRecvSpeedForm.getValue('customizePriority')).toBeFalsy();
osdRecvSpeedForm: CdFormGroup;
permissions: Permissions;
- priorities = [];
+ priorities: any[] = [];
priorityAttrs = {};
constructor(
ngOnInit() {
this.configService.filter(Object.keys(this.priorityAttrs)).subscribe((data: any) => {
const config_option_values = this.getCurrentValues(data);
- this.detectPriority(config_option_values.values, (priority) => {
+ this.detectPriority(config_option_values.values, (priority: any) => {
this.setPriority(priority);
});
this.setDescription(config_option_values.configOptions);
}
getCurrentValues(configOptions: any) {
- const currentValues = { values: {}, configOptions: [] };
- configOptions.forEach((configOption) => {
+ const currentValues: Record<string, any> = { values: {}, configOptions: [] };
+ configOptions.forEach((configOption: any) => {
currentValues.configOptions.push(configOption);
if ('value' in configOption) {
- configOption.value.forEach((value) => {
+ configOption.value.forEach((value: any) => {
if (value.section === 'osd') {
currentValues.values[configOption.name] = Number(value.value);
}
};
this.setPriority(customPriority);
} else {
- this.detectPriority(values, (priority) => {
+ this.detectPriority(values, (priority: any) => {
this.setPriority(priority);
});
}
}
- onPriorityChange(selectedPriorityName) {
+ onPriorityChange(selectedPriorityName: string) {
const selectedPriority =
_.find(this.priorities, (p) => {
return p.name === selectedPriorityName;
export class OsdScrubModalComponent implements OnInit {
deep: boolean;
scrubForm: FormGroup;
- selected = [];
+ selected: any[] = [];
constructor(
public bsModalRef: BsModalRef,
let notificationService: NotificationService;
let router: Router;
// Spies
- let rulesSpy;
- let ifPrometheusSpy;
+ let rulesSpy: jasmine.Spy;
+ let ifPrometheusSpy: jasmine.Spy;
// Helper
let prometheus: PrometheusHelper;
let formHelper: FormHelper;
let fixtureH: FixtureHelper;
- let params;
+ let params: Record<string, any>;
// Date mocking related
- let originalDate;
+ let originalDate: any;
const baseTime = new Date('2022-02-22T00:00:00');
const beginningDate = new Date('2022-02-22T00:00:12.35');
i18nProviders,
{
provide: ActivatedRoute,
- useValue: { params: { subscribe: (fn) => fn(params) } }
+ useValue: { params: { subscribe: (fn: Function) => fn(params) } }
}
]
});
- const createMatcher = (name, value, isRegex) => ({ name, value, isRegex });
+ const createMatcher = (name: string, value: any, isRegex: boolean) => ({ name, value, isRegex });
- const addMatcher = (name, value, isRegex) =>
+ const addMatcher = (name: string, value: any, isRegex: boolean) =>
component['setMatcher'](createMatcher(name, value, isRegex));
const callInit = () =>
});
it('should remind user if prometheus is not set when it is not configured', () => {
- ifPrometheusSpy.and.callFake((_x, fn) => fn());
+ ifPrometheusSpy.and.callFake((_x: any, fn: Function) => fn());
callInit();
expect(component.rules).toEqual([]);
expect(notificationService.show).toHaveBeenCalledWith(
describe('redirect not allowed users', () => {
let prometheusPermissions: Permission;
- let navigateSpy;
+ let navigateSpy: jasmine.Spy;
const expectRedirect = (action: string, redirected: boolean) => {
changeAction(action);
describe('time', () => {
// Can't be used to set accurate UTC dates in unit tests as Date uses timezones,
// this means the UTC time changes depending on the timezone you are in.
- const changeDatePicker = (el, text) => {
+ const changeDatePicker = (el: any, text: string) => {
el.triggerEventHandler('change', { target: { value: text } });
};
- const getDatePicker = (i) =>
+ const getDatePicker = (i: number) =>
fixture.debugElement.queryAll(By.directive(BsDatepickerDirective))[i];
- const changeEndDate = (text) => changeDatePicker(getDatePicker(1), text);
- const changeStartDate = (text) => changeDatePicker(getDatePicker(0), text);
+ const changeEndDate = (text: string) => changeDatePicker(getDatePicker(1), text);
+ const changeStartDate = (text: string) => changeDatePicker(getDatePicker(0), text);
it('have all dates set at beginning', () => {
expect(form.getValue('startsAt')).toEqual(baseTime);
});
describe('matchers', () => {
- const expectMatch = (helpText) => {
+ const expectMatch = (helpText: string) => {
expect(fixtureH.getText('#match-state')).toBe(helpText);
};
spyOn(modalService, 'show').and.callFake(() => {
return {
content: {
- preFillControls: (matcher) => {
+ preFillControls: (matcher: any) => {
expect(matcher).toBe(component.matchers[0]);
},
submitAction: of({ name: 'alertname', value: 'alert0', isRegex: false })
let silence: AlertmanagerSilence;
const silenceId = '50M3-10N6-1D';
- const expectSuccessNotification = (titleStartsWith) =>
+ const expectSuccessNotification = (titleStartsWith: string) =>
expect(notificationService.show).toHaveBeenCalledWith(
NotificationType.success,
`${titleStartsWith} silence ${silenceId}`,
deletion.callSubmitAction();
};
- const expectSilenceToExpire = (silenceId) => {
+ const expectSilenceToExpire = (silenceId: string) => {
setSelectedSilence(silenceId);
expireSilence();
expect(prometheusService.expireSilence).toHaveBeenCalledWith(silenceId);
});
describe('test rule matching', () => {
- const expectMatch = (name, value, helpText) => {
+ const expectMatch = (name: string, value: string, helpText: string) => {
component.preFillControls({
name: name,
value: value,
isRegex: false
};
component.preFillControls(controlValues);
- component.submitAction.subscribe((resp) => {
+ component.submitAction.subscribe((resp: object) => {
expect(resp).toEqual(controlValues);
done();
});
});
}
- private setPossibleValues(name) {
+ private setPossibleValues(name: string) {
this.possibleValues = _.sortedUniq(
this.rules.map((r) => _.get(r, this.silenceMatcher.getAttributePath(name))).filter((x) => x)
);
display: true,
position: 'right',
labels: { usePointStyle: true },
- onClick: (event, legendItem) => {
+ onClick: (event: any, legendItem: any) => {
this.onLegendClick(event, legendItem);
}
},
}
}
};
- private hiddenSlices = [];
+ private hiddenSlices: any[] = [];
constructor(private dimlessBinary: DimlessBinaryPipe, private dimless: DimlessPipe) {}
}
});
- const getStyleTop = (tooltip, positionY) => {
+ const getStyleTop = (tooltip: any, positionY: number) => {
return positionY + tooltip.caretY - tooltip.height - 10 + 'px';
};
- const getStyleLeft = (tooltip, positionX) => {
+ const getStyleLeft = (tooltip: any, positionX: number) => {
return positionX + tooltip.caretX + 'px';
};
getStyleTop
);
- const getBody = (body) => {
+ const getBody = (body: any) => {
return this.getChartTooltipBody(body);
};
chartTooltip.getBody = getBody;
- this.chartConfig.options.tooltips.custom = (tooltip) => {
+ this.chartConfig.options.tooltips.custom = (tooltip: any) => {
chartTooltip.customTooltips(tooltip);
};
this.setChartSliceBorderWidth();
}
- private getChartTooltipBody(body) {
+ private getChartTooltipBody(body: string[]) {
const bodySplit = body[0].split(': ');
if (this.showLabelAsTooltip) {
this.chartConfig.dataset[0].borderWidth = nonZeroValueSlices > 1 ? 1 : 0;
}
- private onLegendClick(event, legendItem) {
+ private onLegendClick(event: any, legendItem: any) {
event.stopPropagation();
this.hiddenSlices[legendItem.index] = !legendItem.hidden;
this.ngOnChanges();
}
private hideSlices() {
- _.forEach(this.chartConfig.dataset[0].data, (_slice, sliceIndex) => {
+ _.forEach(this.chartConfig.dataset[0].data, (_slice, sliceIndex: number) => {
if (this.hiddenSlices[sliceIndex]) {
this.chartConfig.dataset[0].data[sliceIndex] = undefined;
}
describe('HealthComponent', () => {
let component: HealthComponent;
let fixture: ComponentFixture<HealthComponent>;
- let getHealthSpy;
- const healthPayload = {
+ let getHealthSpy: jasmine.Spy;
+ const healthPayload: Record<string, any> = {
health: { status: 'HEALTH_OK' },
mon_status: { monmap: { mons: [] }, quorum: [] },
osd_map: { osds: [] },
return new Permissions({ log: ['read'] });
}
};
- let fakeFeatureTogglesService;
+ let fakeFeatureTogglesService: jasmine.Spy;
configureTestBed({
imports: [SharedModule, HttpClientTestingModule, PopoverModule.forRoot()],
});
it('should render all groups and 1 card per group', () => {
- const payload = { hosts: 0, scrub_status: 'Inactive', pools: [] };
+ const payload: Record<string, any> = { hosts: 0, scrub_status: 'Inactive', pools: [] };
getHealthSpy.and.returnValue(of(payload));
fixture.detectChanges();
});
describe('preparePgStatus', () => {
- const calcPercentage = (data) => Math.round((data / 10) * 100) || 0;
+ const calcPercentage = (data: number) => Math.round((data / 10) * 100) || 0;
const expectedChart = (data: number[]) => ({
labels: [
});
}
- prepareReadWriteRatio(chart) {
+ prepareReadWriteRatio(chart: Record<string, any>) {
const ratioLabels = [];
const ratioData = [];
chart.labels = ratioLabels;
}
- prepareRawUsage(chart, data) {
+ prepareRawUsage(chart: Record<string, any>, data: Record<string, any>) {
const percentAvailable = this.calcPercentage(
data.df.stats.total_bytes - data.df.stats.total_used_raw_bytes,
data.df.stats.total_bytes
)} ${this.i18n('total')}`;
}
- preparePgStatus(chart, data) {
- const categoryPgAmount = {};
+ preparePgStatus(chart: Record<string, any>, data: Record<string, any>) {
+ const categoryPgAmount: Record<string, number> = {};
let totalPgs = 0;
_.forEach(data.pg_info.statuses, (pgAmount, pgStatesText) => {
];
}
- prepareObjects(chart, data) {
+ prepareObjects(chart: Record<string, any>, data: Record<string, any>) {
const totalReplicas = data.pg_info.object_stats.num_object_copies;
const healthy =
totalReplicas -
});
it('transforms with 0 filesystems', () => {
- const payload = {
+ const payload: Record<string, any> = {
standbys: [0],
filesystems: []
};
});
it('transforms with active_name undefined', () => {
- const payload = {
+ const payload: Record<string, any> = {
active_name: undefined,
standbys: []
};
let component: NfsDetailsComponent;
let fixture: ComponentFixture<NfsDetailsComponent>;
- const elem = (css) => fixture.debugElement.query(By.css(css));
+ const elem = (css: string) => fixture.debugElement.query(By.css(css));
configureTestBed({
declarations: [NfsDetailsComponent],
data: any;
clientsColumns: CdTableColumn[];
- clients = [];
+ clients: any[] = [];
constructor(private i18n: I18n) {
this.clientsColumns = [
this.data[this.i18n('Cluster')] = this.selectedItem.cluster_id;
this.data[this.i18n('Daemons')] = this.selectedItem.daemons;
this.data[this.i18n('NFS Protocol')] = this.selectedItem.protocols.map(
- (protocol) => 'NFSv' + protocol
+ (protocol: string) => 'NFSv' + protocol
);
this.data[this.i18n('Pseudo')] = this.selectedItem.pseudo;
this.data[this.i18n('Access Type')] = this.selectedItem.access_type;
import { Component, Input } from '@angular/core';
-import { FormArray, FormControl, Validators } from '@angular/forms';
+import { FormArray, FormControl, NgForm, Validators } from '@angular/forms';
import { I18n } from '@ngx-translate/i18n-polyfill';
import * as _ from 'lodash';
return this.i18n('-- Select the access type --');
}
- getAccessTypeHelp(index) {
+ getAccessTypeHelp(index: number) {
const accessTypeItem = this.nfsAccessType.find((currentAccessTypeItem) => {
return this.getValue(index, 'access_type') === currentAccessTypeItem.value;
});
return fg;
}
- removeClient(index) {
+ removeClient(index: number) {
const clients = this.form.get('clients') as FormArray;
clients.removeAt(index);
}
- showError(index, control, formDir, x) {
+ showError(index: number, control: string, formDir: NgForm, x: string) {
return (<any>this.form.controls.clients).controls[index].showError(control, formDir, x);
}
- getValue(index, control) {
+ getValue(index: number, control: string) {
const clients = this.form.get('clients') as FormArray;
const client = clients.at(index) as CdFormGroup;
return client.getValue(control);
});
}
- trackByFn(index) {
+ trackByFn(index: number) {
return index;
}
}
nfsForm: CdFormGroup;
isEdit = false;
- cluster_id = null;
- export_id = null;
+ cluster_id: string = null;
+ export_id: string = null;
isNewDirectory = false;
isNewBucket = false;
}
ngOnInit() {
- const promises: any[] = [
+ const promises: Observable<any>[] = [
this.nfsService.daemon(),
this.nfsService.fsals(),
this.nfsService.clients(),
this.docsUrl = `http://docs.ceph.com/docs/${releaseName}/radosgw/nfs/`;
}
- getData(promises) {
+ getData(promises: Observable<any>[]) {
forkJoin(promises).subscribe((data: any[]) => {
this.resolveDaemons(data[0]);
this.resolvefsals(data[1]);
path: new FormControl(''),
protocolNfsv3: new FormControl(true, {
validators: [
- CdValidators.requiredIf({ protocolNfsv4: false }, (value) => {
+ CdValidators.requiredIf({ protocolNfsv4: false }, (value: boolean) => {
return !value;
})
]
}),
protocolNfsv4: new FormControl(true, {
validators: [
- CdValidators.requiredIf({ protocolNfsv3: false }, (value) => {
+ CdValidators.requiredIf({ protocolNfsv3: false }, (value: boolean) => {
return !value;
})
]
}),
transportUDP: new FormControl(true, {
validators: [
- CdValidators.requiredIf({ transportTCP: false }, (value) => {
+ CdValidators.requiredIf({ transportTCP: false }, (value: boolean) => {
return !value;
})
]
}),
transportTCP: new FormControl(true, {
validators: [
- CdValidators.requiredIf({ transportUDP: false }, (value) => {
+ CdValidators.requiredIf({ transportUDP: false }, (value: boolean) => {
return !value;
})
]
});
}
- resolveModel(res) {
+ resolveModel(res: any) {
if (res.fsal.name === 'CEPH') {
res.sec_label_xattr = res.fsal.sec_label_xattr;
}
res.transportUDP = res.transports.indexOf('UDP') !== -1;
delete res.transports;
- res.clients.forEach((client) => {
+ res.clients.forEach((client: any) => {
let addressStr = '';
- client.addresses.forEach((address) => {
+ client.addresses.forEach((address: string) => {
addressStr += address + ', ';
});
if (addressStr.length >= 2) {
this.nfsClients.resolveModel(res.clients);
}
- resolveDaemons(daemons) {
+ resolveDaemons(daemons: Record<string, any>) {
daemons = _.sortBy(daemons, ['daemon_id']);
this.allClusters = _(daemons)
this.allFsals.push(fsalItem);
if (fsalItem.value === 'RGW') {
this.rgwUserService.list().subscribe((result: any) => {
- result.forEach((user) => {
+ result.forEach((user: Record<string, any>) => {
if (user.suspended === 0 && user.keys.length > 0) {
this.allRgwUsers.push(user.user_id);
}
}
}
- resolveClients(clients) {
+ resolveClients(clients: any[]) {
this.allCephxClients = clients;
}
- resolveFilesystems(filesystems) {
+ resolveFilesystems(filesystems: any[]) {
this.allFsNames = filesystems;
if (filesystems.length === 1) {
this.nfsForm.patchValue({
});
}
- getAccessTypeHelp(accessType) {
+ getAccessTypeHelp(accessType: string) {
const accessTypeItem = this.nfsAccessType.find((currentAccessTypeItem) => {
if (accessType === currentAccessTypeItem.value) {
return currentAccessTypeItem;
return '';
}
- getPathTypeahead(path) {
+ getPathTypeahead(path: any) {
if (!_.isString(path) || path === '/') {
return of([]);
}
this.nfsForm.patchValue({ daemons: [] });
}
- removeDaemon(index, daemon) {
+ removeDaemon(index: number, daemon: string) {
this.daemonsSelections.forEach((value) => {
if (value.name === daemon) {
value.selected = false;
}
delete requestModel.transportUDP;
- requestModel.clients.forEach((client) => {
+ requestModel.clients.forEach((client: any) => {
if (_.isString(client.addresses)) {
client.addresses = _(client.addresses)
.split(/[ ,]+/)
let nfsService: NfsService;
let httpTesting: HttpTestingController;
- const refresh = (data) => {
+ const refresh = (data: object) => {
summaryService['summaryDataSource'].next(data);
};
describe('handling of executing tasks', () => {
let exports: any[];
- const addExport = (export_id) => {
+ const addExport = (export_id: string) => {
const model = {
export_id: export_id,
path: 'path_' + export_id,
import { CdTableSelection } from '../../../shared/models/cd-table-selection';
import { FinishedTask } from '../../../shared/models/finished-task';
import { Permission } from '../../../shared/models/permissions';
+import { Task } from '../../../shared/models/task';
import { AuthStorageService } from '../../../shared/services/auth-storage.service';
import { TaskListService } from '../../../shared/services/task-list.service';
import { TaskWrapperService } from '../../../shared/services/task-wrapper.service';
modalRef: BsModalRef;
builders = {
- 'nfs/create': (metadata) => {
+ 'nfs/create': (metadata: any) => {
return {
path: metadata['path'],
cluster_id: metadata['cluster_id'],
}
prepareResponse(resp: any): any[] {
- let result = [];
- resp.forEach((nfs) => {
+ let result: any[] = [];
+ resp.forEach((nfs: any) => {
nfs.id = `${nfs.cluster_id}:${nfs.export_id}`;
nfs.state = 'LOADING';
result = result.concat(nfs);
this.viewCacheStatus = { status: ViewCacheStatus.ValueException };
}
- itemFilter(entry, task) {
+ itemFilter(entry: any, task: Task) {
return (
entry.cluster_id === task.metadata['cluster_id'] &&
entry.export_id === task.metadata['export_id']
);
}
- taskFilter(task) {
+ taskFilter(task: Task) {
return ['nfs/create', 'nfs/delete', 'nfs/edit'].includes(task.name);
}
});
it(`should show all default form controls`, () => {
- const showDefaults = (plugin) => {
+ const showDefaults = (plugin: string) => {
formHelper.setValue('plugin', plugin);
fixtureHelper.expectIdElementsVisible(
[
Validators.pattern('[A-Za-z0-9_-]+'),
CdValidators.custom(
'uniqueName',
- (value) => this.names && this.names.indexOf(value) !== -1
+ (value: string) => this.names && this.names.indexOf(value) !== -1
)
]
],
this.form.get('plugin').valueChanges.subscribe((plugin) => this.onPluginChange(plugin));
}
- onPluginChange(plugin) {
+ onPluginChange(plugin: string) {
this.plugin = plugin;
if (plugin === this.PLUGIN.JERASURE) {
this.setJerasureDefaults();
let router: Router;
let ecpService: ErasureCodeProfileService;
- const setPgNum = (pgs): AbstractControl => {
+ const setPgNum = (pgs: number): AbstractControl => {
const control = formHelper.setValue('pgNum', pgs);
fixture.debugElement.query(By.css('#pgNum')).nativeElement.dispatchEvent(new Event('blur'));
return control;
};
- const testPgUpdate = (pgs, jump, returnValue) => {
+ const testPgUpdate = (pgs: number, jump: number, returnValue: number) => {
if (pgs) {
setPgNum(pgs);
}
component.ngOnInit(); // Switches form into edit mode
formHelper.setValue('poolType', 'erasure');
fixture.detectChanges();
- formHelper.expectValid(setPgNum('8'));
+ formHelper.expectValid(setPgNum(8));
});
it('is valid if pgNum, poolType and name are valid', () => {
});
it('validates that odd size validator works as expected', () => {
- const odd = (min, max) => component['oddBlobSize'](min, max);
+ const odd = (min: string, max: string) => component['oddBlobSize'](min, max);
expect(odd('10', '8')).toBe(true);
expect(odd('8', '-')).toBe(false);
expect(odd('8', '10')).toBe(false);
expected: 256
});
- const testPgCalc = ({ type, osds, size, ecp, expected }) => {
+ const testPgCalc = ({ type, osds, size, ecp, expected }: Record<string, any>) => {
component.info.osd_count = osds;
formHelper.setValue('poolType', type);
if (type === 'replicated') {
deletion.submitActionObservable();
};
- const testPoolDeletion = (name) => {
+ const testPoolDeletion = (name: string) => {
setSelectedEcp(name);
callDeletion();
expect(ecpService.delete).toHaveBeenCalledWith(name);
});
describe('submit - create', () => {
- const setMultipleValues = (settings: {}) => {
+ const setMultipleValues = (settings: object) => {
Object.keys(settings).forEach((name) => {
formHelper.setValue(name, settings[name]);
});
};
- const testCreate = (pool) => {
+ const testCreate = (pool: object) => {
expectValidSubmit(pool, 'pool/create', 'create');
};
});
describe('edit mode', () => {
- const setUrl = (url) => {
+ const setUrl = (url: string) => {
Object.defineProperty(router, 'url', { value: url });
setUpPoolComponent(); // Renew of component needed because the constructor has to be called
};
});
it('should include the custom app as valid option', () => {
- expect(component.data.applications.available.map((app) => app.name)).toEqual([
- 'cephfs',
- 'ownApp',
- 'rbd',
- 'rgw'
- ]);
+ expect(
+ component.data.applications.available.map((app: Record<string, any>) => app.name)
+ ).toEqual(['cephfs', 'ownApp', 'rbd', 'rgw']);
});
it('set all control values to the given pool', () => {
});
describe('submit', () => {
- const markControlAsPreviouslySet = (controlName) => form.get(controlName).markAsPristine();
+ const markControlAsPreviouslySet = (controlName: string) =>
+ form.get(controlName).markAsPristine();
beforeEach(() => {
['algorithm', 'maxBlobSize', 'minBlobSize', 'mode', 'pgNum', 'ratio', 'name'].forEach(
data = new PoolFormData(this.i18n);
externalPgChange = false;
private modalSubscription: Subscription;
- current = {
+ current: Record<string, any> = {
rules: []
};
initializeConfigData = new EventEmitter<{
validators: [
CdValidators.custom(
'tooFewOsds',
- (rule) => this.info && rule && this.info.osd_count < rule.min_size
+ (rule: any) => this.info && rule && this.info.osd_count < rule.min_size
)
]
}),
validators: [Validators.min(0)]
})
},
- [CdValidators.custom('form', () => null)]
+ [CdValidators.custom('form', (): null => null)]
);
}
}
}
- private replicatedPgCalc(pgs): number {
+ private replicatedPgCalc(pgs: number): number {
const sizeControl = this.form.get('size');
const size = sizeControl.value;
if (sizeControl.valid && size > 0) {
return undefined;
}
- private erasurePgCalc(pgs): number {
+ private erasurePgCalc(pgs: number): number {
const ecpControl = this.form.get('erasureProfile');
const ecp = ecpControl.value;
if ((ecpControl.valid || ecpControl.disabled) && ecp) {
this.form.get('name').validator,
CdValidators.custom(
'uniqueName',
- (name) =>
+ (name: string) =>
this.data.pool &&
this.info &&
this.info.pool_names.indexOf(name) !== -1 &&
[
CdValidators.custom(
'min',
- (value) => this.form.getValue('size') && value < this.getMinSize()
+ (value: number) => this.form.getValue('size') && value < this.getMinSize()
),
CdValidators.custom(
'max',
- (value) => this.form.getValue('size') && this.getMaxSize() < value
+ (value: number) => this.form.getValue('size') && this.getMaxSize() < value
)
]
);
this.form.get('name').validator,
CdValidators.custom(
'uniqueName',
- (name) => this.info && this.info.pool_names.indexOf(name) !== -1
+ (name: string) => this.info && this.info.pool_names.indexOf(name) !== -1
)
]);
}
private setCompressionValidators() {
CdValidators.validateIf(this.form.get('minBlobSize'), () => this.hasCompressionEnabled(), [
Validators.min(0),
- CdValidators.custom('maximum', (size) =>
+ CdValidators.custom('maximum', (size: string) =>
this.oddBlobSize(size, this.form.getValue('maxBlobSize'))
)
]);
CdValidators.validateIf(this.form.get('maxBlobSize'), () => this.hasCompressionEnabled(), [
Validators.min(0),
- CdValidators.custom('minimum', (size) =>
+ CdValidators.custom('minimum', (size: string) =>
this.oddBlobSize(this.form.getValue('minBlobSize'), size)
)
]);
]);
}
- private oddBlobSize(minimum, maximum) {
- minimum = this.formatter.toBytes(minimum);
- maximum = this.formatter.toBytes(maximum);
- return Boolean(minimum && maximum && minimum >= maximum);
+ private oddBlobSize(minimum: string, maximum: string) {
+ const min = this.formatter.toBytes(minimum);
+ const max = this.formatter.toBytes(maximum);
+ return Boolean(min && max && min >= max);
}
hasCompressionEnabled() {
{
externalFieldName: 'pg_num',
formControlName: 'pgNum',
- replaceFn: (value) => (this.form.getValue('pgAutoscaleMode') === 'on' ? 1 : value),
+ replaceFn: (value: number) => (this.form.getValue('pgAutoscaleMode') === 'on' ? 1 : value),
editable: true
},
this.form.getValue('poolType') === 'replicated'
externalFieldName: 'compression_mode',
formControlName: 'mode',
editable: true,
- replaceFn: (value) => this.hasCompressionEnabled() && value
+ replaceFn: (value: boolean) => this.hasCompressionEnabled() && value
},
{
externalFieldName: 'compression_algorithm',
pool[externalFieldName] = apiValue;
}
- private triggerApiTask(pool) {
+ private triggerApiTask(pool: Record<string, any>) {
this.taskWrapper
.wrapTaskAroundCall({
task: new FinishedTask('pool/' + (this.editing ? URLVerbs.EDIT : URLVerbs.CREATE), {
let fixture: ComponentFixture<PoolListComponent>;
let poolService: PoolService;
- const createPool = (name, id): Pool => {
+ const createPool = (name: string, id: number): Pool => {
return _.merge(new Pool(name), {
pool: id,
pg_num: 256,
deletion.submitActionObservable();
};
- const testPoolDeletion = (poolName) => {
+ const testPoolDeletion = (poolName: string) => {
setSelectedPool(poolName);
callDeletion();
expect(poolService.delete).toHaveBeenCalledWith(poolName);
});
describe('getPgStatusCellClass', () => {
- const testMethod = (value, expected) =>
+ const testMethod = (value: string, expected: string) =>
expect(component.getPgStatusCellClass('', '', value)).toEqual({
'text-right': true,
[expected]: true
describe('custom row comparators', () => {
const expectCorrectComparator = (statsAttribute: string) => {
- const mockPool = (v) => ({ stats: { [statsAttribute]: { latest: v } } });
+ const mockPool = (v: number) => ({ stats: { [statsAttribute]: { latest: v } } });
const columnDefinition = _.find(
component.columns,
(column) => column.prop === `stats.${statsAttribute}.rates`
describe('transformPoolsData', () => {
let pool: Pool;
- const getPoolData = (o) => [
+ const getPoolData = (o: object) => [
_.merge(
_.merge(createPool('a', 0), {
cdIsBinary: true,
});
it('returns empty string', () => {
- const pgStatus = undefined;
+ const pgStatus: any = undefined;
const expected = '';
expect(component.transformPgStatus(pgStatus)).toEqual(expected);
import { URLBuilderService } from '../../../shared/services/url-builder.service';
import { PgCategoryService } from '../../shared/pg-category.service';
import { Pool } from '../pool';
-import { PoolStats } from '../pool-stat';
+import { PoolStat, PoolStats } from '../pool-stat';
const BASE_URL = 'pool';
{
prop: 'stats.rd_bytes.rates',
name: this.i18n('Read bytes'),
- comparator: (_valueA, _valueB, rowA: Pool, rowB: Pool) =>
+ comparator: (_valueA: any, _valueB: any, rowA: Pool, rowB: Pool) =>
compare('stats.rd_bytes.latest', rowA, rowB),
cellTransformation: CellTemplate.sparkline,
flexGrow: 3
{
prop: 'stats.wr_bytes.rates',
name: this.i18n('Write bytes'),
- comparator: (_valueA, _valueB, rowA: Pool, rowB: Pool) =>
+ comparator: (_valueA: any, _valueB: any, rowA: Pool, rowB: Pool) =>
compare('stats.wr_bytes.latest', rowA, rowB),
cellTransformation: CellTemplate.sparkline,
flexGrow: 3
});
}
- getPgStatusCellClass(_row, _column, value): object {
+ getPgStatusCellClass(_row: any, _column: any, value: string): object {
return {
'text-right': true,
[`pg-${this.pgCategoryService.getTypeByStates(value)}`]: true
transformPoolsData(pools: any) {
const requiredStats = ['bytes_used', 'max_avail', 'rd_bytes', 'wr_bytes', 'rd', 'wr'];
- const emptyStat = { latest: 0, rate: 0, rates: [] };
+ const emptyStat: PoolStat = { latest: 0, rate: 0, rates: [] };
_.forEach(pools, (pool: Pool) => {
pool['pg_status'] = this.transformPgStatus(pool['pg_status']);
}
['rd_bytes', 'wr_bytes'].forEach((stat) => {
- pool.stats[stat].rates = pool.stats[stat].rates.map((point) => point[1]);
+ pool.stats[stat].rates = pool.stats[stat].rates.map((point: any) => point[1]);
});
pool.cdIsBinary = true;
});
}
transformPgStatus(pgStatus: any): string {
- const strings = [];
+ const strings: string[] = [];
_.forEach(pgStatus, (count, state) => {
strings.push(`${count} ${state}`);
});
cdIsBinary?: boolean;
configuration: { source: number; name: string; value: string }[];
- constructor(name) {
+ constructor(name: string) {
this.pool_name = name;
}
}
let component: RgwBucketFormComponent;
let fixture: ComponentFixture<RgwBucketFormComponent>;
let rgwBucketService: RgwBucketService;
- let getPlacementTargetsSpy;
+ let getPlacementTargetsSpy: jasmine.Spy;
configureTestBed({
declarations: [RgwBucketFormComponent],
});
describe('bucketNameValidator', () => {
- const testValidator = (name, valid) => {
+ const testValidator = (name: string, valid: boolean) => {
const validatorFn = component.bucketNameValidator();
const ctrl = new FormControl(name);
ctrl.markAsDirty();
});
it('should get zonegroup and placement targets', () => {
- const payload = {
+ const payload: Record<string, any> = {
zonegroup: 'default',
placement_targets: [
{
editing = false;
error = false;
loading = false;
- owners = null;
+ owners: string[] = null;
action: string;
resource: string;
zonegroup: string;
- placementTargets: Object[] = [];
+ placementTargets: object[] = [];
constructor(
private route: ActivatedRoute,
if (!this.editing) {
// Get placement targets:
- this.rgwSiteService.getPlacementTargets().subscribe((placementTargets) => {
+ this.rgwSiteService.getPlacementTargets().subscribe((placementTargets: any) => {
this.zonegroup = placementTargets['zonegroup'];
_.forEach(placementTargets['placement_targets'], (placementTarget) => {
placementTarget['description'] = `${placementTarget['name']} (${this.i18n('pool')}: ${
// Get the default values.
const defaults = _.clone(this.bucketForm.value);
// Extract the values displayed in the form.
- let value = _.pick(resp, _.keys(this.bucketForm.value));
+ let value: object = _.pick(resp, _.keys(this.bucketForm.value));
value['placement-target'] = resp['placement_rule'];
// Append default values.
value = _.merge(defaults, value);
}
const constraints = [];
// - Bucket names cannot be formatted as IP address.
- constraints.push((name) => {
+ constraints.push((name: AbstractControl) => {
const validatorFn = CdValidators.ip();
return !validatorFn(name);
});
// - Bucket names can be between 3 and 63 characters long.
- constraints.push((name) => _.inRange(name.length, 3, 64));
+ constraints.push((name: string) => _.inRange(name.length, 3, 64));
// - Bucket names must not contain uppercase characters or underscores.
// - Bucket names must start with a lowercase letter or number.
// - Bucket names must be a series of one or more labels. Adjacent
// labels are separated by a single period (.). Bucket names can
// contain lowercase letters, numbers, and hyphens. Each label must
// start and end with a lowercase letter or a number.
- constraints.push((name) => {
+ constraints.push((name: string) => {
const labels = _.split(name, '.');
return _.every(labels, (label) => {
// Bucket names must not contain uppercase characters or underscores.
});
});
});
- if (!_.every(constraints, (func) => func(control.value))) {
+ if (!_.every(constraints, (func: Function) => func(control.value))) {
resolve({ bucketNameInvalid: true });
return;
}
if (_.isEmpty(this.serviceId)) {
return;
}
- this.rgwDaemonService.get(this.serviceId).subscribe((resp) => {
+ this.rgwDaemonService.get(this.serviceId).subscribe((resp: any) => {
this.metadata = resp['rgw_metadata'];
});
}
setCapabilities(capabilities: RgwUserCapability[]) {
// Parse the configured capabilities to get a list of types that
// should be displayed.
- const usedTypes = [];
+ const usedTypes: string[] = [];
capabilities.forEach((capability) => {
usedTypes.push(capability.type);
});
// Process the capabilities.
const mapPerm = { 'read, write': '*' };
- resp[0].caps.forEach((cap) => {
+ resp[0].caps.forEach((cap: any) => {
if (cap.perm in mapPerm) {
cap.perm = mapPerm[cap.perm];
}
* Add/Update a subuser.
*/
setSubuser(subuser: RgwUserSubuser, index?: number) {
- const mapPermissions = {
+ const mapPermissions: Record<string, string> = {
'full-control': 'full',
'read-write': 'readwrite'
};
* configuration has been modified.
*/
private _getUpdateArgs() {
- const result = {};
+ const result: Record<string, string> = {};
const keys = ['display_name', 'email', 'max_buckets', 'suspended'];
for (const key of keys) {
result[key] = this.userForm.getValue(key);
* Helper function to get the arguments for the API request when the user
* quota configuration has been modified.
*/
- private _getUserQuotaArgs(): object {
+ private _getUserQuotaArgs(): Record<string, any> {
const result = {
quota_type: 'user',
enabled: this.userForm.getValue('user_quota_enabled'),
* Helper function to get the arguments for the API request when the bucket
* quota configuration has been modified.
*/
- private _getBucketQuotaArgs(): object {
+ private _getBucketQuotaArgs(): Record<string, any> {
const result = {
quota_type: 'bucket',
enabled: this.userForm.getValue('bucket_quota_enabled'),
@Input()
hostname = '';
@Input()
- osdId = null;
+ osdId: number = null;
@ViewChild('deviceLocation', { static: true })
locationTemplate: TemplateRef<any>;
) {}
ngOnInit() {
- const updateDevicesFn = (devices) => (this.devices = devices);
+ const updateDevicesFn = (devices: CdDevice[]) => (this.devices = devices);
if (this.hostname) {
this.hostService.getDevices(this.hostname).subscribe(updateDevicesFn);
} else if (this.osdId !== null) {
});
describe('getTypeByStates', () => {
- const testMethod = (value, expected) =>
+ const testMethod = (value: string, expected: string) =>
expect(service.getTypeByStates(value)).toEqual(expected);
it(PgCategory.CATEGORY_CLEAN, () => {
);
}
- private getPgStatesFromText(pgStatesText) {
+ private getPgStatesFromText(pgStatesText: string) {
const pgStates = pgStatesText
.replace(/[^a-z]+/g, ' ')
.trim()
import { SimpleChange, SimpleChanges } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
-import { TabsetComponent, TabsetConfig, TabsModule } from 'ngx-bootstrap/tabs';
import * as _ from 'lodash';
+import { TabsetComponent, TabsetConfig, TabsModule } from 'ngx-bootstrap/tabs';
import { of } from 'rxjs';
import { configureTestBed, i18nProviders } from '../../../../testing/unit-test-helper';
const patchData = (path: string, newValue: any): any => {
return _.reduce(
_.cloneDeep(SMART_DATA_HDD_VERSION_1_0),
- (result, dataObj, deviceId) => {
+ (result: object, dataObj, deviceId) => {
result[deviceId] = _.set<any>(dataObj, path, newValue);
return result;
},
patch: { [path: string]: any } = null,
simpleChanges?: SimpleChanges
) => {
- let data = null;
+ let data: HddSmartDataV1 | NvmeSmartDataV1;
switch (dataType) {
case 'hdd_v1':
data = SMART_DATA_HDD_VERSION_1_0;
import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';
+
import { I18n } from '@ngx-translate/i18n-polyfill';
import * as _ from 'lodash';
+
import { HostService } from '../../../shared/api/host.service';
import { OsdService } from '../../../shared/api/osd.service';
import { CdTableColumn } from '../../../shared/models/cd-table-column';
return _.get(data, 'device.protocol', '').toLowerCase() === 'ata';
}
- private fetchData(data) {
+ private fetchData(data: any) {
const result: { [deviceId: string]: SmartDataResult | SmartErrorResult } = {};
_.each(data, (smartData, deviceId) => {
if (this.isSmartError(smartData)) {
// Make sure notification sidebar is closed.
this.notificationService.toggleSidebar(true);
- let token = null;
+ let token: string = null;
if (window.location.hash.indexOf('access_token=') !== -1) {
token = window.location.hash.split('access_token=')[1];
const uri = window.location.toString();
if (this.selection.hasSelection) {
this.selectedItem = this.selection.first();
// Build the scopes/permissions data used by the data table.
- const scopes_permissions = [];
+ const scopes_permissions: any[] = [];
_.each(this.scopes, (scope) => {
- const scope_permission = { read: false, create: false, update: false, delete: false };
+ const scope_permission: any = { read: false, create: false, update: false, delete: false };
scope_permission['scope'] = scope;
if (scope in this.selectedItem['scopes_permissions']) {
_.each(this.selectedItem['scopes_permissions'][scope], (permission) => {
let httpTesting: HttpTestingController;
let roleService: RoleService;
let router: Router;
- const setUrl = (url) => Object.defineProperty(router, 'url', { value: url });
+ const setUrl = (url: string) => Object.defineProperty(router, 'url', { value: url });
@Component({ selector: 'cd-fake', template: '' })
class FakeComponent {}
// Create/Update the data which is used by the data table to display the
// scopes/permissions every time the form field value has been changed.
this.roleForm.get('scopes_permissions').valueChanges.subscribe((value) => {
- const scopes_permissions = [];
+ const scopes_permissions: any[] = [];
_.each(this.scopes, (scope) => {
// Set the defaults values.
- const scope_permission = { read: false, create: false, update: false, delete: false };
+ const scope_permission: any = { read: false, create: false, update: false, delete: false };
scope_permission['scope'] = scope;
// Apply settings from the given value if they exist.
if (scope in value) {
});
}
- onClickCellCheckbox(scope: string, property: string, event: Event = null) {
+ onClickCellCheckbox(scope: string, property: string, event: any = null) {
// Use a copy of the form field data to do not trigger the redrawing of the
// data table with every change.
const scopes_permissions = _.cloneDeep(this.roleForm.getValue('scopes_permissions'));
this.roleForm.get('scopes_permissions').setValue(scopes_permissions);
}
- onClickHeaderCheckbox(property: 'scope' | 'read' | 'create' | 'update' | 'delete', event: Event) {
+ onClickHeaderCheckbox(property: 'scope' | 'read' | 'create' | 'update' | 'delete', event: any) {
// Use a copy of the form field data to do not trigger the redrawing of the
// data table with every change.
const scopes_permissions = _.cloneDeep(this.roleForm.getValue('scopes_permissions'));
],
titleText: this.i18n('Clone Role'),
submitButtonText: this.i18n('Clone Role'),
- onSubmit: (values) => {
+ onSubmit: (values: object) => {
this.roleService.clone(name, values['newName']).subscribe(() => {
this.getRoles();
this.notificationService.show(
scopes_permissions: object;
enabled = true;
- constructor(name, description) {
+ constructor(name: string, description: string) {
this.name = name;
this.description = description;
}
let router: Router;
let formHelper: FormHelper;
- const setUrl = (url) => Object.defineProperty(router, 'url', { value: url });
+ const setUrl = (url: string) => Object.defineProperty(router, 'url', { value: url });
@Component({ selector: 'cd-fake', template: '' })
class FakeComponent {}
this.url = this.router.url;
}
- navigateTo(url) {
+ navigateTo(url: string) {
this.router.navigate([url]);
}
}
});
summaryData$ = this.summaryDataSource.asObservable();
- subscribe(call) {
+ subscribe(call: any) {
return this.summaryData$.subscribe(call);
}
}
}
postProcess(breadcrumbs: IBreadcrumb[]) {
- const result = [];
+ const result: IBreadcrumb[] = [];
breadcrumbs.forEach((element) => {
const split = element.text.split('/');
if (split.length > 1) {
})
export class DashboardHelpComponent implements OnInit {
@ViewChild('docsForm', { static: true })
- docsFormElement;
+ docsFormElement: any;
docsUrl: string;
modalRef: BsModalRef;
icons = Icons;
});
it('should call getMdsCounters', () => {
- service.getMdsCounters(1).subscribe();
+ service.getMdsCounters('1').subscribe();
const req = httpTesting.expectOne('api/cephfs/1/mds_counters');
expect(req.request.method).toBe('GET');
});
return this.http.get(`${this.baseURL}`);
}
- lsDir(id, path?): Observable<CephfsDir[]> {
+ lsDir(id: number, path?: string): Observable<CephfsDir[]> {
let apiPath = `${this.baseURL}/${id}/ls_dir?depth=2`;
if (path) {
apiPath += `&path=${encodeURIComponent(path)}`;
return this.http.get<CephfsDir[]>(apiPath);
}
- getCephfs(id) {
+ getCephfs(id: number) {
return this.http.get(`${this.baseURL}/${id}`);
}
- getTabs(id) {
+ getTabs(id: number) {
return this.http.get(`ui-api/cephfs/${id}/tabs`);
}
- getClients(id) {
+ getClients(id: number) {
return this.http.get(`${this.baseURL}/${id}/clients`);
}
- evictClient(fsId, clientId) {
+ evictClient(fsId: number, clientId: number) {
return this.http.delete(`${this.baseURL}/${fsId}/client/${clientId}`);
}
- getMdsCounters(id) {
+ getMdsCounters(id: string) {
return this.http.get(`${this.baseURL}/${id}/mds_counters`);
}
- mkSnapshot(id, path, name?) {
+ mkSnapshot(id: number, path: string, name?: string) {
let params = new HttpParams();
params = params.append('path', path);
if (!_.isUndefined(name)) {
return this.http.post(`${this.baseURL}/${id}/mk_snapshot`, null, { params });
}
- rmSnapshot(id, path, name) {
+ rmSnapshot(id: number, path: string, name: string) {
let params = new HttpParams();
params = params.append('path', path);
params = params.append('name', name);
return this.http.post(`${this.baseURL}/${id}/rm_snapshot`, null, { params });
}
- updateQuota(id, path, quotas: CephfsQuotas) {
+ updateQuota(id: number, path: string, quotas: CephfsQuotas) {
let params = new HttpParams();
params = params.append('path', path);
return this.http.post(`${this.baseURL}/${id}/set_quotas`, quotas, {
export class ConfigurationService {
constructor(private http: HttpClient) {}
- private findValue(config, section: string) {
+ private findValue(config: any, section: string) {
if (!config.value) {
return undefined;
}
- return config.value.find((v) => v.section === section);
+ return config.value.find((v: any) => v.section === section);
}
- getValue(config, section: string) {
+ getValue(config: any, section: string) {
let val = this.findValue(config, section);
if (!val) {
const indexOfDot = section.indexOf('.');
return this.http.delete(`api/cluster_conf/${configOption}?section=${section}`);
}
- bulkCreate(configOptions: Object) {
+ bulkCreate(configOptions: object) {
return this.http.put('api/cluster_conf/', configOptions);
}
}
return this.http.get(this.baseURL);
}
- add(hostname) {
+ add(hostname: string) {
return this.http.post(this.baseURL, { hostname: hostname }, { observe: 'response' });
}
- remove(hostname) {
+ remove(hostname: string) {
return this.http.delete(`${this.baseURL}/${hostname}`, { observe: 'response' });
}
.pipe(map((devices) => devices.map((device) => this.deviceService.prepareDevice(device))));
}
- getSmartData(hostname) {
+ getSmartData(hostname: string) {
return this.http.get<SmartDataResponseV1>(`${this.baseURL}/${hostname}/smart`);
}
}
return this.http.get(`api/iscsi/target`);
}
- getTarget(target_iqn) {
+ getTarget(target_iqn: string) {
return this.http.get(`api/iscsi/target/${target_iqn}`);
}
- updateTarget(target_iqn, target) {
+ updateTarget(target_iqn: string, target: any) {
return this.http.put(`api/iscsi/target/${target_iqn}`, target, { observe: 'response' });
}
return this.http.get(`ui-api/iscsi/portals`);
}
- createTarget(target) {
+ createTarget(target: any) {
return this.http.post(`api/iscsi/target`, target, { observe: 'response' });
}
- deleteTarget(target_iqn) {
+ deleteTarget(target_iqn: string) {
return this.http.delete(`api/iscsi/target/${target_iqn}`, { observe: 'response' });
}
return this.http.get(`api/iscsi/discoveryauth`);
}
- updateDiscovery(auth) {
+ updateDiscovery(auth: any) {
return this.http.put(`api/iscsi/discoveryauth`, auth);
}
export class LoggingService {
constructor(private http: HttpClient) {}
- jsError(url, message, stack) {
+ jsError(url: string, message: string, stack: any) {
const request = {
url: url,
message: message,
return this.http.get('api/logs/all');
}
- validateDashboardUrl(uid) {
+ validateDashboardUrl(uid: string) {
return this.http.get(`api/grafana/validation/${uid}`);
}
}
* @param {object} config The configuration.
* @return {Observable<Object>}
*/
- updateConfig(module: string, config: Object): Observable<Object> {
+ updateConfig(module: string, config: object): Observable<Object> {
return this.http.put(`${this.url}/${module}`, { config: config });
}
return this.http.get(`${this.apiPath}/export`);
}
- get(clusterId, exportId) {
+ get(clusterId: string, exportId: string) {
return this.http.get(`${this.apiPath}/export/${clusterId}/${exportId}`);
}
- create(nfs) {
+ create(nfs: any) {
return this.http.post(`${this.apiPath}/export`, nfs, { observe: 'response' });
}
- update(clusterId, id, nfs) {
+ update(clusterId: string, id: string, nfs: any) {
return this.http.put(`${this.apiPath}/export/${clusterId}/${id}`, nfs, { observe: 'response' });
}
- delete(clusterId, exportId) {
+ delete(clusterId: string, exportId: string) {
return this.http.delete(`${this.apiPath}/export/${clusterId}/${exportId}`, {
observe: 'response'
});
}
- lsDir(root_dir) {
+ lsDir(root_dir: string) {
return this.http.get(`${this.uiApiPath}/lsdir?root_dir=${root_dir}`);
}
- buckets(user_id) {
+ buckets(user_id: string) {
return this.http.get(`${this.uiApiPath}/rgw/buckets?user_id=${user_id}`);
}
return this.http.get<SmartDataResponseV1>(`${this.path}/${id}/smart`);
}
- scrub(id, deep) {
+ scrub(id: string, deep: boolean) {
return this.http.post(`${this.path}/${id}/scrub?deep=${deep}`, null);
}
get(service_type: string, service_id: string) {
return this.http.get(`${this.url}/${service_type}/${service_id}`).pipe(
- mergeMap((resp) => {
+ mergeMap((resp: any) => {
return observableOf(resp['counters']);
})
);
constructor(private http: HttpClient, private rbdConfigurationService: RbdConfigurationService) {}
- create(pool) {
+ create(pool: any) {
return this.http.post(this.apiPath, pool, { observe: 'response' });
}
- update(pool) {
+ update(pool: any) {
let name: string;
if (pool.hasOwnProperty('srcpool')) {
name = pool.srcpool;
});
}
- delete(name) {
+ delete(name: string) {
return this.http.delete(`${this.apiPath}/${name}`, { observe: 'response' });
}
- get(poolName) {
+ get(poolName: string) {
return this.http.get(`${this.apiPath}/${poolName}`);
}
return this.http.get(`${this.apiPath}/_info` + (pool_name ? `?pool_name=${pool_name}` : ''));
}
- list(attrs = []) {
+ list(attrs: string[] = []) {
const attrsStr = attrs.join(',');
return this.http
.get(`${this.apiPath}?attrs=${attrsStr}`)
describe('ifAlertmanagerConfigured', () => {
let x: any;
- let host;
+ let host: string;
const receiveConfig = () => {
const req = httpTesting.expectOne('api/settings/alertmanager-api-host');
describe('ifPrometheusConfigured', () => {
let x: any;
- let host;
+ let host: string;
const receiveConfig = () => {
const req = httpTesting.expectOne('api/settings/prometheus-api-host');
constructor(private http: HttpClient, private settingsService: SettingsService) {}
- ifAlertmanagerConfigured(fn, elseFn?): void {
+ ifAlertmanagerConfigured(fn: (value?: string) => void, elseFn?: () => void): void {
this.settingsService.ifSettingConfigured(this.settingsKey.alertmanager, fn, elseFn);
}
this.settingsService.disableSetting(this.settingsKey.alertmanager);
}
- ifPrometheusConfigured(fn, elseFn?): void {
+ ifPrometheusConfigured(fn: (value?: string) => void, elseFn?: () => void): void {
this.settingsService.ifSettingConfigured(this.settingsKey.prometheus, fn, elseFn);
}
}
setSilence(silence: AlertmanagerSilence) {
- return this.http.post(`${this.baseURL}/silence`, silence, { observe: 'response' });
+ return this.http.post<object>(`${this.baseURL}/silence`, silence, { observe: 'response' });
}
expireSilence(silenceId: string) {
let service: RbdMirroringService;
let httpTesting: HttpTestingController;
- const summary = {
+ const summary: Record<string, any> = {
status: 0,
content_data: {
daemons: [],
});
it('should periodically poll summary', fakeAsync(() => {
- const calledWith = [];
+ const calledWith: any[] = [];
service.subscribeSummary((data) => {
calledWith.push(data);
});
return this.summaryData$.subscribe(next, error);
}
- getPool(poolName) {
+ getPool(poolName: string) {
return this.http.get(`api/block/mirroring/pool/${poolName}`);
}
- updatePool(poolName, request) {
+ updatePool(poolName: string, request: any) {
return this.http.put(`api/block/mirroring/pool/${poolName}`, request, { observe: 'response' });
}
return this.http.get(`api/block/mirroring/site_name`);
}
- setSiteName(@cdEncodeNot siteName) {
+ setSiteName(@cdEncodeNot siteName: string) {
return this.http.put(
`api/block/mirroring/site_name`,
{ site_name: siteName },
);
}
- createBootstrapToken(poolName) {
+ createBootstrapToken(poolName: string) {
return this.http.post(`api/block/mirroring/pool/${poolName}/bootstrap/token`, {});
}
- importBootstrapToken(poolName, @cdEncodeNot direction, @cdEncodeNot token) {
+ importBootstrapToken(
+ poolName: string,
+ @cdEncodeNot direction: string,
+ @cdEncodeNot token: string
+ ) {
const request = {
direction: direction,
token: token
});
}
- getPeer(poolName, peerUUID) {
+ getPeer(poolName: string, peerUUID: string) {
return this.http.get(`api/block/mirroring/pool/${poolName}/peer/${peerUUID}`);
}
- addPeer(poolName, request) {
+ addPeer(poolName: string, request: any) {
return this.http.post(`api/block/mirroring/pool/${poolName}/peer`, request, {
observe: 'response'
});
}
- updatePeer(poolName, peerUUID, request) {
+ updatePeer(poolName: string, peerUUID: string, request: any) {
return this.http.put(`api/block/mirroring/pool/${poolName}/peer/${peerUUID}`, request, {
observe: 'response'
});
}
- deletePeer(poolName, peerUUID) {
+ deletePeer(poolName: string, peerUUID: string) {
return this.http.delete(`api/block/mirroring/pool/${poolName}/peer/${peerUUID}`, {
observe: 'response'
});
export class RbdService {
constructor(private http: HttpClient, private rbdConfigurationService: RbdConfigurationService) {}
- isRBDPool(pool) {
+ isRBDPool(pool: any) {
return _.indexOf(pool.application_metadata, 'rbd') !== -1 && !pool.pool_name.includes('/');
}
- create(rbd) {
+ create(rbd: any) {
return this.http.post('api/block/image', rbd, { observe: 'response' });
}
});
}
- update(imageSpec: ImageSpec, rbd) {
+ update(imageSpec: ImageSpec, rbd: any) {
return this.http.put(`api/block/image/${imageSpec.toStringEncoded()}`, rbd, {
observe: 'response'
});
);
}
- copy(imageSpec: ImageSpec, rbd) {
+ copy(imageSpec: ImageSpec, rbd: any) {
return this.http.post(`api/block/image/${imageSpec.toStringEncoded()}/copy`, rbd, {
observe: 'response'
});
return this.http.get('api/block/image/default_features');
}
- createSnapshot(imageSpec: ImageSpec, @cdEncodeNot snapshotName) {
+ createSnapshot(imageSpec: ImageSpec, @cdEncodeNot snapshotName: string) {
const request = {
snapshot_name: snapshotName
};
});
}
- renameSnapshot(imageSpec: ImageSpec, snapshotName, @cdEncodeNot newSnapshotName) {
+ renameSnapshot(imageSpec: ImageSpec, snapshotName: string, @cdEncodeNot newSnapshotName: string) {
const request = {
new_snap_name: newSnapshotName
};
);
}
- protectSnapshot(imageSpec: ImageSpec, snapshotName, @cdEncodeNot isProtected) {
+ protectSnapshot(imageSpec: ImageSpec, snapshotName: string, @cdEncodeNot isProtected: boolean) {
const request = {
is_protected: isProtected
};
);
}
- rollbackSnapshot(imageSpec: ImageSpec, snapshotName) {
+ rollbackSnapshot(imageSpec: ImageSpec, snapshotName: string) {
return this.http.post(
`api/block/image/${imageSpec.toStringEncoded()}/snap/${snapshotName}/rollback`,
null,
);
}
- cloneSnapshot(imageSpec: ImageSpec, snapshotName, request) {
+ cloneSnapshot(imageSpec: ImageSpec, snapshotName: string, request: any) {
return this.http.post(
`api/block/image/${imageSpec.toStringEncoded()}/snap/${snapshotName}/clone`,
request,
);
}
- deleteSnapshot(imageSpec: ImageSpec, snapshotName) {
+ deleteSnapshot(imageSpec: ImageSpec, snapshotName: string) {
return this.http.delete(`api/block/image/${imageSpec.toStringEncoded()}/snap/${snapshotName}`, {
observe: 'response'
});
return this.http.get(`api/block/image/trash/`);
}
- createNamespace(pool, namespace) {
+ createNamespace(pool: string, namespace: string) {
const request = {
namespace: namespace
};
return this.http.post(`api/block/pool/${pool}/namespace`, request, { observe: 'response' });
}
- listNamespaces(pool) {
+ listNamespaces(pool: string) {
return this.http.get(`api/block/pool/${pool}/namespace/`);
}
- deleteNamespace(pool, namespace) {
+ deleteNamespace(pool: string, namespace: string) {
return this.http.delete(`api/block/pool/${pool}/namespace/${namespace}`, {
observe: 'response'
});
}
- moveTrash(imageSpec: ImageSpec, delay) {
+ moveTrash(imageSpec: ImageSpec, delay: number) {
return this.http.post(
`api/block/image/${imageSpec.toStringEncoded()}/move_trash`,
{ delay: delay },
);
}
- purgeTrash(poolName) {
+ purgeTrash(poolName: string) {
return this.http.post(`api/block/image/trash/purge/?pool_name=${poolName}`, null, {
observe: 'response'
});
return this.http.get(`${this.url}/${uid}/quota`);
}
- create(args: object) {
+ create(args: Record<string, string>) {
let params = new HttpParams();
_.keys(args).forEach((key) => {
params = params.append(key, args[key]);
return this.http.post(this.url, null, { params: params });
}
- update(uid: string, args: object) {
+ update(uid: string, args: Record<string, string>) {
let params = new HttpParams();
_.keys(args).forEach((key) => {
params = params.append(key, args[key]);
return this.http.put(`${this.url}/${uid}`, null, { params: params });
}
- updateQuota(uid: string, args: object) {
+ updateQuota(uid: string, args: Record<string, string>) {
let params = new HttpParams();
_.keys(args).forEach((key) => {
params = params.append(key, args[key]);
return this.http.delete(`${this.url}/${uid}`);
}
- createSubuser(uid: string, args: object) {
+ createSubuser(uid: string, args: Record<string, string>) {
let params = new HttpParams();
_.keys(args).forEach((key) => {
params = params.append(key, args[key]);
return this.http.delete(`${this.url}/${uid}/capability`, { params: params });
}
- addS3Key(uid: string, args: object) {
+ addS3Key(uid: string, args: Record<string, string>) {
let params = new HttpParams();
params = params.append('key_type', 's3');
_.keys(args).forEach((key) => {
});
describe('getSettingsValue', () => {
- const testMethod = (data, expected: string) => {
+ const testMethod = (data: object, expected: string) => {
expect(service['getSettingsValue'](data)).toBe(expected);
};
describe('isSettingConfigured', () => {
let increment: number;
- const testConfig = (url, value) => {
+ const testConfig = (url: string, value: string) => {
service.ifSettingConfigured(
url,
(setValue) => {
}
// Easiest way to stop reloading external content that can't be reached
- disableSetting(url) {
+ disableSetting(url: string) {
this.settings[url] = '';
}
return data.value || data.instance || '';
}
- validateGrafanaDashboardUrl(uid) {
+ validateGrafanaDashboardUrl(uid: string) {
return this.http.get(`api/grafana/validation/${uid}`);
}
return this.http.put(`api/user/${user.username}`, user);
}
- changePassword(username, oldPassword, newPassword) {
+ changePassword(username: string, oldPassword: string, newPassword: string) {
// Note, the specified user MUST be logged in to be able to change
// the password. The backend ensures that the password of another
// user can not be changed, otherwise an error will be thrown.
fixture.detectChanges();
configurationService = TestBed.get(ConfigurationService);
- const configOptions = [
+ const configOptions: Record<string, any> = [
{
name: 'osd_scrub_auto_repair_num_errors',
type: 'uint',
private loadStoredData() {
this.configService.filter(this.optionNames).subscribe((data: any) => {
- this.options = data.map((configOption) => {
+ this.options = data.map((configOption: any) => {
const formControl = this.optionsForm.get(configOption.name);
const typeValidators = ConfigOptionTypes.getTypeValidators(configOption);
configOption.additionalTypeInfo = ConfigOptionTypes.getType(configOption.type);
return;
}
- const typeValidators = { validators: [], patternHelpText: typeParams.patternHelpText };
+ const typeValidators: Record<string, any> = {
+ validators: [],
+ patternHelpText: typeParams.patternHelpText
+ };
if (typeParams.isNumberType) {
if (configOption.max && configOption.max !== '') {
// Normally private, but public is needed by tests
constructor(public modalService: BsModalService) {}
- private openModal(extendBaseState: object = {}) {
+ private openModal(extendBaseState = {}) {
this.modalRef = this.modalService.show(ConfirmationModalComponent, {
initialState: Object.assign(
{
constructor(public modalRef: BsModalRef, private modalService: BsModalService) {
this.confirmationForm = new FormGroup({});
- this.onHide = this.modalService.onHide.subscribe((e) => {
+ this.onHide = this.modalService.onHide.subscribe((e: any) => {
if (this.onCancel && (e || this.canceled)) {
this.onCancel();
}
});
describe('component functions', () => {
- const changeValue = (value) => {
+ const changeValue = (value: boolean) => {
const ctrl = component.deletionForm.get('confirmation');
ctrl.setValue(value);
ctrl.markAsDirty();
let fixture: ComponentFixture<FormModalComponent>;
let fh: FixtureHelper;
let formHelper: FormHelper;
- let submitted;
+ let submitted: object;
const initialState = {
titleText: 'Some title',
}
],
submitButtonText: 'Submit button name',
- onSubmit: (values) => (submitted = values)
+ onSubmit: (values: object) => (submitted = values)
};
configureTestBed({
import * as _ from 'lodash';
import { BsModalRef } from 'ngx-bootstrap/modal';
-import { DimlessBinaryPipe } from 'app/shared/pipes/dimless-binary.pipe';
import { CdFormBuilder } from '../../forms/cd-form-builder';
import { CdFormGroup } from '../../forms/cd-form-group';
import { CdFormModalFieldConfig } from '../../models/cd-form-modal-field-config';
+import { DimlessBinaryPipe } from '../../pipes/dimless-binary.pipe';
import { FormatterService } from '../../services/formatter.service';
@Component({
}
createForm() {
- const controlsConfig = {};
+ const controlsConfig: Record<string, FormControl> = {};
this.fields.forEach((field) => {
controlsConfig[field.name] = this.createFormControl(field);
});
return this.i18n('An error occurred.');
}
- onSubmitForm(values) {
+ onSubmitForm(values: any) {
const binaries = this.fields
.filter((field) => field.type === 'binary')
.map((field) => field.name);
grafanaExist = false;
mode = '&kiosk';
loading = true;
- styles = {};
+ styles: Record<string, string> = {};
dashboardExist = true;
time: string;
grafanaTimes: any;
expect(listLocales()).toEqual([]);\r
});\r
\r
- const expectLanguageChange = (lang) => {\r
+ const expectLanguageChange = (lang: string) => {\r
component.changeLanguage(lang);\r
const cookie = document.cookie.split(';').filter((item) => item.includes(`cd-lang=${lang}`));\r
expect(cookie.length).toBe(1);\r
@Input()\r
isDropdown = true;\r
\r
- supportedLanguages: Object = SupportedLanguages;\r
+ supportedLanguages: Record<string, any> = SupportedLanguages;\r
selectedLanguage: string;\r
\r
constructor(private localeService: BsLocaleService, private languageService: LanguageService) {}\r
this.notificationService.toggleSidebar(true);
}
- trackByFn(index) {
+ trackByFn(index: number) {
return index;
}
}
import { Icons } from '../../../shared/enum/icons.enum';
import { SelectMessages } from '../select/select-messages.model';
import { SelectOption } from '../select/select-option.model';
+import { SelectComponent } from '../select/select.component';
@Component({
selector: 'cd-select-badges',
selection = new EventEmitter();
@ViewChild('cdSelect', { static: true })
- cdSelect;
+ cdSelect: SelectComponent;
icons = Icons;
}
];
- options = {
+ options: Record<string, any> = {
animation: {
duration: 0
},
intersect: false,
custom: undefined,
callbacks: {
- label: (tooltipItem) => {
+ label: (tooltipItem: any) => {
if (this.isBinary) {
return this.dimlessBinaryPipe.transform(tooltipItem.yLabel);
} else {
constructor(private dimlessBinaryPipe: DimlessBinaryPipe) {}
ngOnInit() {
- const getStyleTop = (tooltip) => {
+ const getStyleTop = (tooltip: any) => {
return tooltip.caretY - tooltip.height - tooltip.yPadding - 5 + 'px';
};
- const getStyleLeft = (tooltip, positionX) => {
+ const getStyleLeft = (tooltip: any, positionX: number) => {
return positionX + tooltip.caretX + 'px';
};
borderColor: this.colors[0].pointBorderColor
};
- this.options.tooltips.custom = (tooltip) => {
+ this.options.tooltips.custom = (tooltip: any) => {
chartTooltip.customTooltips(tooltip);
};
}
});
}
- submit($event) {
+ submit($event: any) {
this.focusButton();
// Special handling for Template driven forms.
it('should make key value object pairs out of arrays with length two', () => {
component.data = [['someKey', 0], ['arrayKey', [1, 2, 3]], [3, 'something']];
component.ngOnInit();
- expect(component.tableData).toEqual([
+ const expected: any = [
{ key: 'arrayKey', value: '1, 2, 3' },
{ key: 'someKey', value: 0 },
{ key: 3, value: 'something' }
- ]);
+ ];
+ expect(component.tableData).toEqual(expected);
});
it('should not show data supposed to be have hidden by key', () => {
it('should remove items with objects as values', () => {
component.data = [[3, 'something'], ['will be removed', { a: 3, b: 4, c: 5 }]];
component.ngOnInit();
- expect(component.tableData).toEqual([{ key: 3, value: 'something' }]);
+ expect(component.tableData).toEqual(<any>[{ key: 3, value: 'something' }]);
});
it('makes key value object pairs out of an object', () => {
});
it('tests makePairs()', () => {
- const makePairs = (data) => component['makePairs'](data);
+ const makePairs = (data: any) => component['makePairs'](data);
expect(makePairs([['dash', 'board']])).toEqual([{ key: 'dash', value: 'board' }]);
const pair = [{ key: 'dash', value: 'board' }, { key: 'ceph', value: 'mimic' }];
const pairInverse = [{ key: 'ceph', value: 'mimic' }, { key: 'dash', value: 'board' }];
});
it('tests makePairsFromArray()', () => {
- const makePairsFromArray = (data) => component['makePairsFromArray'](data);
+ const makePairsFromArray = (data: any[]) => component['makePairsFromArray'](data);
expect(makePairsFromArray([['dash', 'board']])).toEqual([{ key: 'dash', value: 'board' }]);
const pair = [{ key: 'dash', value: 'board' }, { key: 'ceph', value: 'mimic' }];
expect(makePairsFromArray(pair)).toEqual(pair);
});
it('tests makePairsFromObject()', () => {
- const makePairsFromObject = (data) => component['makePairsFromObject'](data);
+ const makePairsFromObject = (data: object) => component['makePairsFromObject'](data);
expect(makePairsFromObject({ dash: 'board' })).toEqual([{ key: 'dash', value: 'board' }]);
expect(makePairsFromObject({ dash: 'board', ceph: 'mimic' })).toEqual([
{ key: 'dash', value: 'board' },
});
describe('tests convertValue()', () => {
- const convertValue = (data) => component['convertValue'](data);
- const expectConvertValue = (value, expectation) =>
+ const convertValue = (data: any) => component['convertValue'](data);
+ const expectConvertValue = (value: any, expectation: any) =>
expect(convertValue(value)).toBe(expectation);
it('should not convert strings', () => {
@Input()
hideEmpty = false;
@Input()
- hideKeys = []; // Keys of pairs not to be displayed
+ hideKeys: string[] = []; // Keys of pairs not to be displayed
// If set, the classAddingTpl is used to enable different css for different values
@Input()
- customCss?: { [css: string]: number | string | ((any) => boolean) };
+ customCss?: { [css: string]: number | string | ((any: any) => boolean) };
columns: Array<CdTableColumn> = [];
tableData: KeyValueItem[];
}
private makePairsFromArray(data: any[]): KeyValueItem[] {
- let temp = [];
+ let temp: any[] = [];
const first = data[0];
if (_.isArray(first)) {
if (first.length === 2) {
return temp;
}
- private makePairsFromObject(data: object): KeyValueItem[] {
+ private makePairsFromObject(data: any): KeyValueItem[] {
return Object.keys(data).map((k) => ({
key: k,
value: data[k]
return value;
}
- private isDate(s) {
+ private isDate(s: string) {
const sep = '[ -:.TZ]';
const n = '\\d{2}' + sep;
// year - m - d - h : m : s . someRest Z (if UTC)
let component: TableComponent;
let fixture: ComponentFixture<TableComponent>;
- const createFakeData = (n) => {
+ const createFakeData = (n: number) => {
const data = [];
for (let i = 0; i < n; i++) {
data.push({
});
describe('after ngInit', () => {
- const toggleColumn = (prop, checked) => {
+ const toggleColumn = (prop: string, checked: boolean) => {
component.toggleColumn({
target: {
name: prop,
});
it('should call fetchData callback function', () => {
- component.fetchData.subscribe((context) => {
+ component.fetchData.subscribe((context: any) => {
expect(context instanceof CdTableFetchDataContext).toBeTruthy();
});
component.reloadData();
it('should call error function', () => {
component.data = createFakeData(5);
- component.fetchData.subscribe((context) => {
+ component.fetchData.subscribe((context: any) => {
context.error();
expect(component.loadingError).toBeTruthy();
expect(component.data.length).toBe(0);
it('should call error function with custom config', () => {
component.data = createFakeData(10);
- component.fetchData.subscribe((context) => {
+ component.fetchData.subscribe((context: any) => {
context.errorConfig.resetData = false;
context.errorConfig.displayError = false;
context.error();
} from '@swimlane/ngx-datatable';
import { getterForProp } from '@swimlane/ngx-datatable/release/utils';
import * as _ from 'lodash';
-import { Observable, timer as observableTimer } from 'rxjs';
+import { Observable, Subject, Subscription, timer as observableTimer } from 'rxjs';
import { Icons } from '../../../shared/enum/icons.enum';
import { CellTemplate } from '../../enum/cell-template.enum';
// Only needed to set if the classAddingTpl is used
@Input()
- customCss?: { [css: string]: number | string | ((any) => boolean) };
+ customCss?: { [css: string]: number | string | ((any: any) => boolean) };
// Columns that aren't displayed but can be used as filters
@Input()
[key: string]: TemplateRef<any>;
} = {};
search = '';
- rows = [];
+ rows: any[] = [];
loadingIndicator = true;
loadingError = false;
paginationClasses = {
userConfig: CdUserConfig = {};
tableName: string;
localStorage = window.localStorage;
- private saveSubscriber;
- private reloadSubscriber;
+ private saveSubscriber: Subscription;
+ private reloadSubscriber: Subscription;
private updating = false;
// Internal variable to check if it is necessary to recalculate the
}
}
- _calculateUniqueTableName(columns) {
- const stringToNumber = (s) => {
+ _calculateUniqueTableName(columns: any[]) {
+ const stringToNumber = (s: string) => {
if (!_.isString(s)) {
return 0;
}
}
_initUserConfigAutoSave() {
- const source = Observable.create(this._initUserConfigProxy.bind(this));
+ const source: Observable<any> = Observable.create(this._initUserConfigProxy.bind(this));
this.saveSubscriber = source.subscribe(this._saveUserConfig.bind(this));
}
- _initUserConfigProxy(observer) {
+ _initUserConfigProxy(observer: Subject<any>) {
this.userConfig = new Proxy(this.userConfig, {
- set(config, prop, value) {
+ set(config, prop: string, value) {
config[prop] = value;
observer.next(config);
return true;
});
}
- _saveUserConfig(config) {
+ _saveUserConfig(config: any) {
this.localStorage.setItem(this.tableName, JSON.stringify(config));
}
doColumnFiltering() {
const appliedFilters: CdTableColumnFiltersChange['filters'] = [];
let data = [...this.data];
- let dataOut = [];
+ let dataOut: any[] = [];
this.columnFilters.forEach((filter) => {
if (filter.value === undefined) {
return;
this.useData();
}
- setLimit(e) {
+ setLimit(e: any) {
const value = parseInt(e.target.value, 10);
if (value > 0) {
this.userConfig.limit = value;
}
rowIdentity() {
- return (row) => {
+ return (row: any) => {
const id = row[this.identifier];
if (_.isUndefined(id)) {
throw new Error(`Wrong identifier "${this.identifier}" -> "${id}"`);
if (this.updateSelectionOnRefresh === 'never') {
return;
}
- const newSelected = [];
+ const newSelected: any[] = [];
this.selection.selected.forEach((selectedItem) => {
for (const row of this.data) {
if (selectedItem[this.identifier] === row[this.identifier]) {
this.onSelect(this.selection);
}
- onSelect($event) {
+ onSelect($event: any) {
this.selection.selected = $event['selected'];
this.updateSelection.emit(_.clone(this.selection));
}
];
}
- changeSorting({ sorts }) {
+ changeSorting({ sorts }: any) {
this.userConfig.sorts = sorts;
}
this.rows = rows;
}
- subSearch(data: any[], currentSearch: string[], columns: CdTableColumn[]) {
+ subSearch(data: any[], currentSearch: string[], columns: CdTableColumn[]): any[] {
if (currentSearch.length === 0 || data.length === 0) {
return data;
}
* @param {string} propertyKey
* @param {number} index
*/
-export function cdEncodeNot(target: Object, propertyKey: string, index: number) {
+export function cdEncodeNot(target: object, propertyKey: string, index: number) {
const metadataKey = `__ignore_${propertyKey}`;
if (Array.isArray(target[metadataKey])) {
target[metadataKey].push(index);
}
}
- setValue(value) {
+ setValue(value: string) {
if (/^[\d.]+$/.test(value)) {
value += this.defaultUnit || 'm';
}
}
}
- round(size) {
+ round(size: number) {
if (size !== null && size !== 0) {
if (!_.isUndefined(this.minBytes) && size < this.minBytes) {
return this.minBytes;
}
@HostListener('blur', ['$event.target.value'])
- onBlur(value) {
+ onBlur(value: string) {
this.setValue(value);
}
}
this.setValue(this.el.value);
}
- setValue(value) {
+ setValue(value: string) {
if (/^[\d.]+$/.test(value)) {
value += this.defaultUnit || 'm';
}
}
}
- round(size) {
+ round(size: number) {
if (size !== null && size !== 0) {
if (!_.isUndefined(this.minBytes) && size < this.minBytes) {
return this.minBytes;
}
@HostListener('blur', ['$event.target.value'])
- onBlur(value) {
+ onBlur(value: string) {
this.setValue(value);
}
}
}
@HostListener('blur', ['$event.target.value'])
- onUpdate(value) {
+ onUpdate(value: string) {
this.setValue(value);
}
}
}
@HostListener('blur', ['$event.target.value'])
- onUpdate(value) {
+ onUpdate(value: string) {
this.setValue(value);
}
}
constructor(private ngControl: NgControl) {}
@HostListener('input', ['$event.target.value'])
- onInput(value) {
+ onInput(value: string) {
this.setValue(value);
}
});
describe('CdFormGroup tests', () => {
- let x, nested, a, c;
+ let x: CdFormGroup, nested: CdFormGroup, a: FormControl, c: FormGroup;
beforeEach(() => {
a = new FormControl('a');
return control;
}
- _get(controlName): AbstractControl {
+ _get(controlName: string): AbstractControl {
return (
super.get(controlName) ||
Object.values(this.controls)
let formHelper: FormHelper;
let form: CdFormGroup;
- const expectValid = (value) => formHelper.expectValidChange('x', value);
- const expectPatternError = (value) => formHelper.expectErrorChange('x', value, 'pattern');
- const updateValidity = (controlName) => form.get(controlName).updateValueAndValidity();
+ const expectValid = (value: any) => formHelper.expectValidChange('x', value);
+ const expectPatternError = (value: any) => formHelper.expectErrorChange('x', value, 'pattern');
+ const updateValidity = (controlName: string) => form.get(controlName).updateValueAndValidity();
beforeEach(() => {
form = new CdFormGroup({
});
describe('uuid validator', () => {
- const expectUuidError = (value) =>
+ const expectUuidError = (value: string) =>
formHelper.expectErrorChange('x', value, 'invalidUuid', true);
beforeEach(() => {
form.get('x').setValidators(CdValidators.uuid());
});
it('should error because of successful condition', () => {
- const conditionFn = (value) => {
+ const conditionFn = (value: string) => {
return value === 'abc';
};
// Define prereqs that force the validator to validate the value of
describe('custom validation', () => {
beforeEach(() => {
form = new CdFormGroup({
- x: new FormControl(3, CdValidators.custom('odd', (x) => x % 2 === 1)),
+ x: new FormControl(3, CdValidators.custom('odd', (x: number) => x % 2 === 1)),
y: new FormControl(
5,
- CdValidators.custom('not-dividable-by-x', (y) => {
+ CdValidators.custom('not-dividable-by-x', (y: number) => {
const x = (form && form.get('x').value) || 1;
return y % x !== 0;
})
y: new FormControl(5)
});
CdValidators.validateIf(form.get('x'), () => ((form && form.get('y').value) || 0) > 10, [
- CdValidators.custom('min', (x) => x < 7),
- CdValidators.custom('max', (x) => x > 12)
+ CdValidators.custom('min', (x: number) => x < 7),
+ CdValidators.custom('max', (x: number) => x > 12)
]);
formHelper = new FormHelper(form);
});
* argument. The function must return true to set the validation error.
* @return {ValidatorFn} Returns the validator function.
*/
- static requiredIf(prerequisites: Object, condition?: Function | undefined): ValidatorFn {
+ static requiredIf(prerequisites: object, condition?: Function | undefined): ValidatorFn {
let isWatched = false;
return (control: AbstractControl): ValidationErrors | null => {
* into action when the prerequisites are met.
* @return {ValidatorFn} Returns the validator function.
*/
- static composeIf(prerequisites: Object, validators: ValidatorFn[]): ValidatorFn {
+ static composeIf(prerequisites: object, validators: ValidatorFn[]): ValidatorFn {
let isWatched = false;
return (control: AbstractControl): ValidationErrors | null => {
if (!isWatched && control.parent) {
pwdExpirationWarning1: number;
pwdExpirationWarning2: number;
- constructor(data) {
+ constructor(data: any) {
this.pwdExpirationSpan = data.user_pwd_expiration_span;
this.pwdExpirationWarning1 = data.user_pwd_expiration_warning_1;
this.pwdExpirationWarning2 = data.user_pwd_expiration_warning_2;
chartEl: any;
getStyleLeft: Function;
getStyleTop: Function;
- customColors = {
+ customColors: Record<string, any> = {
backgroundColor: undefined,
borderColor: undefined
};
* @param {any} tooltip
* @memberof ChartTooltip
*/
- customTooltips(tooltip) {
+ customTooltips(tooltip: any) {
// Hide if no tooltip
if (tooltip.opacity === 0) {
this.tooltipEl.style.opacity = 0;
// Set Text
if (tooltip.body) {
const titleLines = tooltip.title || [];
- const bodyLines = tooltip.body.map((bodyItem) => {
+ const bodyLines = tooltip.body.map((bodyItem: any) => {
return bodyItem.lines;
});
let innerHtml = '<thead>';
- titleLines.forEach((title) => {
+ titleLines.forEach((title: string) => {
innerHtml += '<tr><th>' + this.getTitle(title) + '</th></tr>';
});
innerHtml += '</thead><tbody>';
- bodyLines.forEach((body, i) => {
+ bodyLines.forEach((body: string, i: number) => {
const colors = tooltip.labelColors[i];
let style = 'background:' + (this.customColors.backgroundColor || colors.backgroundColor);
style += '; border-color:' + (this.customColors.borderColor || colors.borderColor);
this.tooltipEl.style.padding = tooltip.yPadding + 'px ' + tooltip.xPadding + 'px';
}
- getBody(body) {
+ getBody(body: string) {
return body;
}
- getTitle(title) {
+ getTitle(title: string) {
return title;
}
}
export class Task {
- constructor(name?, metadata?) {
+ constructor(name?: string, metadata?: object) {
this.name = name;
this.metadata = metadata;
}
});
it('transforms with empty value', () => {
- const value = undefined;
- expect(pipe.transform(value)).toBe('-');
+ expect(pipe.transform(undefined)).toBe('-');
});
it('transforms with some value', () => {
const filters = [
{
value: 'foo',
- applyFilter: (row, val) => {
+ applyFilter: (row: any[], val: any) => {
return row.indexOf(val) !== -1;
}
}
const filters = [
{
value: 'foo',
- applyFilter: (row, val) => {
+ applyFilter: (row: any[], val: any) => {
return row.indexOf(val) !== -1;
}
},
{
value: 'bar',
- applyFilter: (row, val) => {
+ applyFilter: (row: any[], val: any) => {
return row.indexOf(val) !== -1;
}
}
})
export class FilterPipe implements PipeTransform {
transform(value: any, args?: any): any {
- return value.filter((row) => {
+ return value.filter((row: any) => {
let result = true;
- args.forEach((filter): boolean | void => {
+ args.forEach((filter: any): boolean | void => {
if (!filter.value) {
return undefined;
}
});
it('transforms without value', () => {
- const value = undefined;
- expect(pipe.transform(value)).toBe('unknown');
+ expect(pipe.transform(undefined)).toBe('unknown');
});
it('transforms "in 7 days"', () => {
import { configureTestBed, i18nProviders } from '../../../testing/unit-test-helper';
import { AppModule } from '../../app.module';
+import { NotificationType } from '../enum/notification-type.enum';
import { CdNotification, CdNotificationConfig } from '../models/cd-notification';
import { ApiInterceptorService } from './api-interceptor.service';
import { NotificationService } from './notification.service';
let router: Router;
const url = 'api/xyz';
- const httpError = (error, errorOpts, done = (_resp) => {}) => {
+ const httpError = (error: any, errorOpts: object, done = (_resp: any) => {}) => {
httpClient.get(url).subscribe(
() => {},
(resp) => {
httpTesting.expectOne(url).error(error, errorOpts);
};
- const runRouterTest = (errorOpts, expectedCallParams) => {
+ const runRouterTest = (errorOpts: object, expectedCallParams: any[]) => {
httpError(new ErrorEvent('abc'), errorOpts);
httpTesting.verify();
expect(router.navigate).toHaveBeenCalledWith(...expectedCallParams);
};
- const runNotificationTest = (error, errorOpts, expectedCallParams) => {
+ const runNotificationTest = (
+ error: any,
+ errorOpts: object,
+ expectedCallParams: CdNotification
+ ) => {
httpError(error, errorOpts);
httpTesting.verify();
expect(notificationService.show).toHaveBeenCalled();
expect(notificationService.save).toHaveBeenCalledWith(expectedCallParams);
};
- const createCdNotification = (type, title?, message?, options?, application?) => {
+ const createCdNotification = (
+ type: NotificationType,
+ title?: string,
+ message?: string,
+ options?: any,
+ application?: string
+ ) => {
return new CdNotification(new CdNotificationConfig(type, title, message, options, application));
};
});
describe('interceptor error handling', () => {
- const expectSaveToHaveBeenCalled = (called) => {
+ const expectSaveToHaveBeenCalled = (called: boolean) => {
tick(510);
if (called) {
expect(notificationService.save).toHaveBeenCalled();
);
}
- private prepareNotification(resp): number {
+ private prepareNotification(resp: any): number {
return this.notificationService.show(() => {
let message = '';
if (_.isPlainObject(resp.error) && _.isString(resp.error.detail)) {
set(
username: string,
token: string,
- permissions: object = {},
+ permissions = {},
sso = false,
pwdExpirationDate: number = null
) {
});
describe('should test getDevices pipe', () => {
- let now = null;
+ let now: jasmine.Spy = null;
const newDevice = (data: object): CdDevice => {
const device: CdDevice = {
expect(service).toBeTruthy();
});
- function testCanActivate(path, feature_toggles_map) {
+ function testCanActivate(path: string, feature_toggles_map: object) {
let result: boolean;
spyOn(fakeFeatureTogglesService, 'get').and.returnValue(observableOf(feature_toggles_map));
import { Observable } from 'rxjs';
import { shareReplay } from 'rxjs/operators';
-export type FeatureTogglesMap = Map<string, boolean>;
+export type FeatureTogglesMap = Record<string, boolean>;
export type FeatureTogglesMap$ = Observable<FeatureTogglesMap>;
@Injectable({
* @returns Returns the given value in bytes without any unit appended or the defined error value
* in case xof an error.
*/
- toBytes(value: string, error_value = null): number | null {
+ toBytes(value: string, error_value: number = null): number | null {
const base = 1024;
const units = ['b', 'k', 'm', 'g', 't', 'p', 'e', 'z', 'y'];
const m = RegExp('^(\\d+(.\\d+)?) ?([' + units.join('') + ']?(b|ib|B/s)?)?$', 'i').exec(value);
export class JsErrorHandler implements ErrorHandler {
constructor(private injector: Injector) {}
- handleError(error) {
+ handleError(error: any) {
const loggingService = this.injector.get(LoggingService);
const url = window.location.href;
const message = error && error.message;
NotificationService,
TaskMessageService,
{ provide: ToastrService, useValue: toastFakeService },
- { provide: CdDatePipe, useValue: { transform: (d) => d } },
+ { provide: CdDatePipe, useValue: { transform: (d: any) => d } },
i18nProviders,
RbdService
],
}));
describe('Saved notifications', () => {
- const expectSavedNotificationToHave = (expected: {}) => {
+ const expectSavedNotificationToHave = (expected: object) => {
tick(510);
expect(service['dataSource'].getValue().length).toBe(1);
const notification = service['dataSource'].getValue()[0];
});
};
- const addNotifications = (quantity) => {
+ const addNotifications = (quantity: number) => {
for (let index = 0; index < quantity; index++) {
service.show(NotificationType.info, `${index}`);
tick(510);
beforeEach(() => {
spyOn(service, 'show').and.callThrough();
- service.cancel(service['justShownTimeoutId']);
+ service.cancel((<any>service)['justShownTimeoutId']);
});
it('should create a success notification and save it', fakeAsync(() => {
const n1 = new CdNotificationConfig(NotificationType.success, 'Some success');
const n2 = new CdNotificationConfig(NotificationType.info, 'Some info');
- const showArray = (arr) => arr.forEach((n) => service.show(n));
+ const showArray = (arr: any[]) => arr.forEach((n) => service.show(n));
beforeEach(() => {
spyOn(service, 'save').and.stub();
* Prevent the notification from being shown.
* @param {number} timeoutId A number representing the ID of the timeout to be canceled.
*/
- cancel(timeoutId) {
+ cancel(timeoutId: number) {
window.clearTimeout(timeoutId);
}
});
describe('test failing status codes and verify disabling of the alertmanager', () => {
- const isDisabledByStatusCode = (statusCode: number, expectedStatus: boolean, done) => {
+ const isDisabledByStatusCode = (statusCode: number, expectedStatus: boolean, done: any) => {
service = TestBed.get(PrometheusAlertService);
prometheusService = TestBed.get(PrometheusService);
spyOn(prometheusService, 'ifAlertmanagerConfigured').and.callFake((fn) => fn());
spyOn(prometheusService, 'getAlerts').and.returnValue(
- Observable.create((observer) => observer.error({ status: statusCode, error: {} }))
+ Observable.create((observer: any) => observer.error({ status: statusCode, error: {} }))
);
const disableFn = spyOn(prometheusService, 'disableAlertmanagerConfig').and.callFake(() => {
expect(expectedStatus).toBe(true);
tick(20);
};
- const expectShown = (expected: {}[]) => {
+ const expectShown = (expected: object[]) => {
tick(500);
expect(shown.length).toBe(expected.length);
expected.forEach((e, i) =>
providers: [i18nProviders]
});
- const addMatcher = (name, value) => ({
+ const addMatcher = (name: string, value: any) => ({
name: name,
value: value,
isRegex: false
});
describe('test rule matching with one matcher', () => {
- const expectSingleMatch = (name, value, helpText, successClass: boolean) => {
+ const expectSingleMatch = (
+ name: string,
+ value: any,
+ helpText: string,
+ successClass: boolean
+ ) => {
const match = service.singleMatch(addMatcher(name, value), rules);
expect(match.status).toBe(helpText);
expect(match.cssClass).toBe(successClass ? 'has-success' : 'has-warning');
});
describe('test rule matching with multiple matcher', () => {
- const expectMultiMatch = (matchers, helpText, successClass: boolean) => {
+ const expectMultiMatch = (matchers: any[], helpText: string, successClass: boolean) => {
const match = service.multiMatch(matchers, rules);
expect(match.status).toBe(helpText);
expect(match.cssClass).toBe(successClass ? 'has-success' : 'has-warning');
let summaryService: SummaryService;
let authStorageService: AuthStorageService;
- const summary = {
+ const summary: Record<string, any> = {
executing_tasks: [],
health_status: 'HEALTH_OK',
mgr_id: 'x',
it('should call refresh', fakeAsync(() => {
summaryService.enablePolling();
authStorageService.set('foobar', undefined, undefined);
- const calledWith = [];
+ const calledWith: any[] = [];
summaryService.subscribe((data) => {
calledWith.push(data);
});
}
if (_.isArray(current.executing_tasks)) {
- const exists = current.executing_tasks.find((element) => {
+ const exists = current.executing_tasks.find((element: any) => {
return element.name === task.name && _.isEqual(element.metadata, task.metadata);
});
if (!exists) {
let apiResp: any;
let tasks: any[];
- const addItem = (name) => {
+ const addItem = (name: string) => {
apiResp.push({ name: name });
};
(task) => task.name.startsWith('test'),
(item, task) => item.name === task.metadata['name'],
{
- default: (metadata) => ({ name: metadata['name'] })
+ default: (metadata: object) => ({ name: metadata['name'] })
}
);
});
setList: (_: any[]) => void;
onFetchError: (error: any) => void;
taskFilter: (task: ExecutingTask) => boolean;
- itemFilter: (item, task: ExecutingTask) => boolean;
+ itemFilter: (item: any, task: ExecutingTask) => boolean;
builders: object;
constructor(
setList: (_: any[]) => void,
onFetchError: (error: any) => void,
taskFilter: (task: ExecutingTask) => boolean,
- itemFilter: (item, task: ExecutingTask) => boolean,
+ itemFilter: (item: any, task: ExecutingTask) => boolean,
builders: object
) {
this.getUpdate = getUpdate;
import { SummaryService } from './summary.service';
import { TaskManagerService } from './task-manager.service';
-const summary = {
+const summary: Record<string, any> = {
executing_tasks: [],
health_status: 'HEALTH_OK',
mgr_id: 'x',
refresh() {
this.summaryDataSource.next(summary);
}
- subscribe(call) {
+ subscribe(call: any) {
return this.summaryData$.subscribe(call);
}
}
metadata: object;
onTaskFinished: (finishedTask: FinishedTask) => any;
- constructor(name, metadata, onTaskFinished) {
+ constructor(name: string, metadata: object, onTaskFinished: any) {
this.name = name;
this.metadata = metadata;
this.onTaskFinished = onTaskFinished;
});
}
- subscribe(name, metadata, onTaskFinished: (finishedTask: FinishedTask) => any) {
+ subscribe(name: string, metadata: object, onTaskFinished: (finishedTask: FinishedTask) => any) {
this.subscriptions.push(new TaskSubscription(name, metadata, onTaskFinished));
}
});
describe('rbd tasks', () => {
- let metadata;
+ let metadata: Record<string, any>;
let childMsg: string;
let destinationMsg: string;
let snapMsg: string;
i18n: I18n;
operation: TaskMessageOperation;
- involves: (object) => string;
- errors: (metadata) => object;
+ involves: (object: any) => string;
+ errors: (metadata: any) => object;
- failure(metadata): string {
+ failure(metadata: any): string {
return this.i18n('Failed to {{failure}} {{metadata}}', {
failure: this.operation.failure,
metadata: this.involves(metadata)
});
}
- running(metadata): string {
+ running(metadata: any): string {
return `${this.operation.running} ${this.involves(metadata)}`;
}
- success(metadata): string {
+ success(metadata: any): string {
return `${this.operation.success} ${this.involves(metadata)}`;
}
constructor(
i18n: I18n,
operation: TaskMessageOperation,
- involves: (metadata) => string,
- errors?: (metadata) => object
+ involves: (metadata: any) => string,
+ errors?: (metadata: any) => object
) {
this.i18n = i18n;
this.operation = operation;
};
rbd = {
- default: (metadata) =>
+ default: (metadata: any) =>
this.i18n(`RBD '{{id}}'`, {
id: `${metadata.image_spec}`
}),
- create: (metadata) => {
+ create: (metadata: any) => {
const id = new ImageSpec(
metadata.pool_name,
metadata.namespace,
id: id
});
},
- child: (metadata) => {
+ child: (metadata: any) => {
const id = new ImageSpec(
metadata.child_pool_name,
metadata.child_namespace,
id: id
});
},
- destination: (metadata) => {
+ destination: (metadata: any) => {
const id = new ImageSpec(
metadata.dest_pool_name,
metadata.dest_namespace,
id: id
});
},
- snapshot: (metadata) =>
+ snapshot: (metadata: any) =>
this.i18n(`RBD snapshot '{{id}}'`, {
id: `${metadata.image_spec}@${metadata.snapshot_name}`
})
rbd_mirroring = {
site_name: () => this.i18n('mirroring site name'),
bootstrap: () => this.i18n('bootstrap token'),
- pool: (metadata) =>
+ pool: (metadata: any) =>
this.i18n(`mirror mode for pool '{{id}}'`, {
id: `${metadata.pool_name}`
}),
- pool_peer: (metadata) =>
+ pool_peer: (metadata: any) =>
this.i18n(`mirror peer for pool '{{id}}'`, {
id: `${metadata.pool_name}`
})
newTaskMessage(
operation: TaskMessageOperation,
- involves: (metadata) => string,
- errors?: (metadata) => object
+ involves: (metadata: any) => string,
+ errors?: (metadata: any) => object
) {
return new TaskMessage(this.i18n, operation, involves, errors);
}
- host(metadata) {
+ host(metadata: any) {
return this.i18n(`host '{{hostname}}'`, {
hostname: metadata.hostname
});
}
- pool(metadata) {
+ pool(metadata: any) {
return this.i18n(`pool '{{pool_name}}'`, {
pool_name: metadata.pool_name
});
}
- ecp(metadata) {
+ ecp(metadata: any) {
return this.i18n(`erasure code profile '{{name}}'`, { name: metadata.name });
}
- iscsiTarget(metadata) {
+ iscsiTarget(metadata: any) {
return this.i18n(`target '{{target_iqn}}'`, { target_iqn: metadata.target_iqn });
}
- nfs(metadata) {
+ nfs(metadata: any) {
return this.i18n(`NFS {{nfs_id}}`, {
nfs_id: `'${metadata.cluster_id}:${metadata.export_id ? metadata.export_id : metadata.path}'`
});
let passed: boolean;
let summaryService: SummaryService;
- const fakeCall = (status?) =>
+ const fakeCall = (status?: number) =>
new Observable((observer) => {
if (!status) {
observer.error({ error: 'failed' });
observer.complete();
});
- const callWrapTaskAroundCall = (status, name) => {
+ const callWrapTaskAroundCall = (status: number, name: string) => {
return service.wrapTaskAroundCall({
task: new FinishedTask(name, { sth: 'else' }),
call: fakeCall(status)
const days = 24 * hours;
it('should allow different writings', () => {
- const expectDurationToBeMs = (duration, ms) =>
+ const expectDurationToBeMs = (duration: string, ms: number) =>
expect(service['getDurationMs'](duration)).toBe(ms);
expectDurationToBeMs('2h', 2 * hours);
expectDurationToBeMs('4 Days', 4 * days);
});
it('should create duration string from ms', () => {
- const expectMsToBeDuration = (ms, duration) =>
+ const expectMsToBeDuration = (ms: number, duration: string) =>
expect(service['getDuration'](ms)).toBe(duration);
expectMsToBeDuration(2 * hours, '2h');
expectMsToBeDuration(4 * days, '4d');
const m = date.getUTCMinutes();
const d = Math.floor(ms / (24 * 3600 * 1000));
- const format = (n, s) => (n ? n + s : n);
+ const format = (n: number, s: string) => (n ? n + s : n);
return [format(d, 'd'), format(h, 'h'), format(m, 'm')].filter((x) => x).join(' ');
}
return ((d * 24 + h) * 60 + m) * 60000;
}
- private getNumbersFromString(duration, prefix): number {
+ private getNumbersFromString(duration: string, prefix: string): number {
const match = duration.match(new RegExp(`[0-9 ]+${prefix}`, 'i'));
- return match ? parseInt(match, 10) : 0;
+ return match ? parseInt(match[0], 10) : 0;
}
}
const mock = () => {
let storage = {};
return {
- getItem: (key) => (key in storage ? storage[key] : null),
- setItem: (key, value) => (storage[key] = value || ''),
- removeItem: (key) => delete storage[key],
+ getItem: (key: string) => (key in storage ? storage[key] : null),
+ setItem: (key: string, value: any) => (storage[key] = value || ''),
+ removeItem: (key: string) => delete storage[key],
clear: () => (storage = {})
};
};
} from '../app/shared/models/prometheus-alerts';
import { _DEV_ } from '../unit-test-configuration';
-export function configureTestBed(configuration, useOldMethod?) {
+export function configureTestBed(configuration: any, useOldMethod?: boolean) {
if (_DEV_ && !useOldMethod) {
const resetTestingModule = TestBed.resetTestingModule;
beforeAll((done) =>
*
* Please make sure to call this function *inside* your mock and return the reference at the end.
*/
-export function modalServiceShow(componentClass: Type<any>, modalConfig) {
+export function modalServiceShow(componentClass: Type<any>, modalConfig: any) {
const ref = new BsModalRef();
const fixture = TestBed.createComponent(componentClass);
let component = fixture.componentInstance;
}
export class PrometheusHelper {
- createSilence(id) {
+ createSilence(id: string) {
return {
id: id,
createdBy: `Creator of ${id}`,
};
}
- createRule(name, severity, alerts: any[]): PrometheusRule {
+ createRule(name: string, severity: string, alerts: any[]): PrometheusRule {
return {
name: name,
labels: {
} as PrometheusRule;
}
- createAlert(name, state = 'active', timeMultiplier = 1): AlertmanagerAlert {
+ createAlert(name: string, state = 'active', timeMultiplier = 1): AlertmanagerAlert {
return {
fingerprint: name,
status: { state },
} as AlertmanagerAlert;
}
- createNotificationAlert(name, status = 'firing'): AlertmanagerNotificationAlert {
+ createNotificationAlert(name: string, status = 'firing'): AlertmanagerNotificationAlert {
return {
status: status,
labels: {
return { alerts, status } as AlertmanagerNotification;
}
- createLink(url) {
+ createLink(url: string) {
return `<a href="${url}" target="_blank"><i class="${Icons.lineChart}"></i></a>`;
}
}
"noFallthroughCasesInSwitch": true,
"noImplicitThis": true,
"noImplicitReturns": true,
+ "noImplicitAny": true,
+ "suppressImplicitAnyIndexErrors": true,
"target": "es2015",
"typeRoots": [
"node_modules/@types"