Skip to content
This repository has been archived by the owner on Mar 25, 2023. It is now read-only.

Commit

Permalink
fix(vm-destroy): fix deleting of volumes while deleting the VM (closes
Browse files Browse the repository at this point in the history
  • Loading branch information
Darya Baklanova committed Jan 19, 2018
1 parent 7465e36 commit 60e7b9c
Show file tree
Hide file tree
Showing 6 changed files with 222 additions and 183 deletions.
File renamed without changes.
174 changes: 91 additions & 83 deletions src/app/reducers/vm/redux/vm.effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Router } from '@angular/router';
import { Actions, Effect } from '@ngrx/effects';
import { Action, Store } from '@ngrx/store';
import { Observable } from 'rxjs/Observable';
import { flatMap } from 'rxjs/operators';
import { DialogService } from '../../../dialog/dialog-service/dialog.service';
import { VmPulseComponent } from '../../../pulse/vm-pulse/vm-pulse.component';
// tslint:disable-next-line
Expand Down Expand Up @@ -55,9 +56,9 @@ export class VirtualMachinesEffects {
'JOB_NOTIFICATIONS.VM.FETCH_STATISTICS_IN_PROGRESS');
return this.vmService.getList(action.payload)
.do(() => this.jobsNotificationService.finish({
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.FETCH_STATISTICS_DONE'
}))
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.FETCH_STATISTICS_DONE'
}))
.map((vms: VirtualMachine[]) => new vmActions.UpdateVM(vms[0]))
.catch((error) => {
this.jobsNotificationService.fail({
Expand All @@ -78,9 +79,9 @@ export class VirtualMachinesEffects {
.setDescription(action.payload.vm, action.payload.description) : this.vmTagService
.removeDescription(action.payload.vm))
.do(() => this.jobsNotificationService.finish({
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.CHANGE_DESCRIPTION_DONE'
}))
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.CHANGE_DESCRIPTION_DONE'
}))
.map(vm => new vmActions.UpdateVM(vm))
.catch((error: Error) => {
this.jobsNotificationService.fail({
Expand Down Expand Up @@ -109,9 +110,9 @@ export class VirtualMachinesEffects {
return this.vmService
.changeServiceOffering(changeAction.payload.offering, changeAction.payload.vm)
.do(() => this.jobsNotificationService.finish({
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.CHANGE_SERVICE_OFFERING_DONE'
}))
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.CHANGE_SERVICE_OFFERING_DONE'
}))
.switchMap((newVm) => {
if (vmState === VmState.Running) {
return this.start(newVm);
Expand Down Expand Up @@ -157,9 +158,9 @@ export class VirtualMachinesEffects {
changeAction.payload.affinityGroupId
)
.do(() => this.jobsNotificationService.finish({
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.CHANGE_AFFINITY_GROUP_DONE'
}))
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.CHANGE_AFFINITY_GROUP_DONE'
}))
.switchMap((newVm) => {
if (vmState === VmState.Running) {
return this.start(newVm);
Expand Down Expand Up @@ -195,9 +196,9 @@ export class VirtualMachinesEffects {

return this.vmTagService.setGroup(newVm, action.payload.group)
.do(() => this.jobsNotificationService.finish({
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.CHANGE_INSTANCE_GROUP_DONE'
}))
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.CHANGE_INSTANCE_GROUP_DONE'
}))
.map(vm => new vmActions.UpdateVM(vm))
.catch((error: Error) => {
this.jobsNotificationService.fail({
Expand All @@ -217,9 +218,9 @@ export class VirtualMachinesEffects {

return this.vmTagService.removeGroup(action.payload)
.do(() => this.jobsNotificationService.finish({
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.REMOVE_INSTANCE_GROUP_DONE'
}))
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.REMOVE_INSTANCE_GROUP_DONE'
}))
.map(vm => {
const newVm = Object.assign(
{},
Expand All @@ -243,8 +244,8 @@ export class VirtualMachinesEffects {
.switchMap((action: vmActions.AddSecondaryIp) => {
return this.vmService.addIpToNic(action.payload.nicId)
.do(() => this.jobsNotificationService.finish({
message: 'JOB_NOTIFICATIONS.VM.ADD_SECONDARY_IP_DONE'
}))
message: 'JOB_NOTIFICATIONS.VM.ADD_SECONDARY_IP_DONE'
}))
.map(res => {
const newSecondaryIp = Object.assign([], action.payload.vm.nic[0].secondaryip);
newSecondaryIp.push(res.result.nicsecondaryip);
Expand Down Expand Up @@ -274,8 +275,8 @@ export class VirtualMachinesEffects {
.switchMap((action: vmActions.RemoveSecondaryIp) => {
return this.vmService.removeIpFromNic(action.payload.id)
.do(() => this.jobsNotificationService.finish({
message: 'JOB_NOTIFICATIONS.VM.REMOVE_SECONDARY_IP_DONE'
}))
message: 'JOB_NOTIFICATIONS.VM.REMOVE_SECONDARY_IP_DONE'
}))
.map(res => {
const newSecondaryIp = Object.assign([], action.payload.vm.nic[0].secondaryip)
.filter(ip => ip.id !== action.payload.id);
Expand Down Expand Up @@ -305,8 +306,8 @@ export class VirtualMachinesEffects {
.switchMap((action: vmActions.ChangeVmColor) => {
return this.vmTagService.setColor(action.payload.vm, action.payload.color)
.do(() => this.jobsNotificationService.finish({
message: 'JOB_NOTIFICATIONS.VM.COLOR_CHANGE_DONE'
}))
message: 'JOB_NOTIFICATIONS.VM.COLOR_CHANGE_DONE'
}))
.map(vm => new vmActions.UpdateVM(vm))
.catch((error: Error) => {
this.jobsNotificationService.fail({
Expand All @@ -329,9 +330,9 @@ export class VirtualMachinesEffects {
this.update(action.payload, VmState.Running);
return this.vmService.command(action.payload, 'stop')
.do(() => this.jobsNotificationService.finish({
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.STOP_DONE'
}))
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.STOP_DONE'
}))
.map(vm => new vmActions.UpdateVM(vm))
.catch((error: Error) => {
this.jobsNotificationService.fail({
Expand All @@ -341,7 +342,8 @@ export class VirtualMachinesEffects {
return Observable.of(new vmActions.VMUpdateError({
vm: action.payload,
state: VmState.Error,
error }));
error
}));
});
});
});
Expand Down Expand Up @@ -370,27 +372,31 @@ export class VirtualMachinesEffects {
const notificationId = this.jobsNotificationService.add(
'JOB_NOTIFICATIONS.VM.DESTROY_IN_PROGRESS');
this.update(action.payload, VmState.InProgress);

const actions = flatMap((vm: VirtualMachine): Action[] => {
if (params.expunge) {
this.jobsNotificationService.finish({
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.EXPUNGE_DONE'
});
return [
new vmActions.ExpungeVmSuccess(action.payload),
new volumeActions.DeleteVolumes(action.payload)
];
} else {
this.jobsNotificationService.finish({
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.DESTROY_DONE'
});
return [
new vmActions.UpdateVM(vm),
new volumeActions.DeleteVolumes(action.payload)
];
}
});

return this.vmService.command(action.payload, 'destroy', params)
.do(() => {
if (params.expunge) {
this.jobsNotificationService.finish({
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.EXPUNGE_DONE'
});
} else {
this.jobsNotificationService.finish({
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.DESTROY_DONE'
});
}
})
.map(vm => {
if (params.expunge) {
return new vmActions.ExpungeVmSuccess(action.payload);
} else {
return new vmActions.UpdateVM(vm);
}
})
.pipe(actions)
.catch((error: Error) => {
this.jobsNotificationService.fail({
id: notificationId,
Expand All @@ -399,7 +405,8 @@ export class VirtualMachinesEffects {
return Observable.of(new vmActions.VMUpdateError({
vm: action.payload,
state: VmState.Error,
error }));
error
}));
});
});
});
Expand All @@ -417,9 +424,9 @@ export class VirtualMachinesEffects {
this.update(action.payload, VmState.InProgress);
return this.vmService.command(action.payload, 'reboot')
.do(() => this.jobsNotificationService.finish({
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.REBOOT_DONE'
}))
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.REBOOT_DONE'
}))
.map(vm => new vmActions.UpdateVM(vm))
.catch((error: Error) => {
this.jobsNotificationService.fail({
Expand Down Expand Up @@ -449,9 +456,9 @@ export class VirtualMachinesEffects {

return this.vmService.command(action.payload, 'restore')
.do(() => this.jobsNotificationService.finish({
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.RESTORE_DONE'
}))
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.RESTORE_DONE'
}))
.map(newVm => new vmActions.UpdateVM(newVm))
.catch((error: Error) => {
this.jobsNotificationService.fail({
Expand Down Expand Up @@ -480,9 +487,9 @@ export class VirtualMachinesEffects {
this.update(action.payload, VmState.InProgress);
return this.vmService.commandSync(action.payload, 'recover')
.do(() => this.jobsNotificationService.finish({
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.RECOVER_DONE'
}))
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.RECOVER_DONE'
}))
.map(res => new vmActions.UpdateVM(res.virtualmachine))
.catch((error: Error) => {
this.jobsNotificationService.fail({
Expand Down Expand Up @@ -510,9 +517,9 @@ export class VirtualMachinesEffects {
'JOB_NOTIFICATIONS.VM.EXPUNGE_IN_PROGRESS');
return this.vmService.command(action.payload, 'expunge')
.do(() => this.jobsNotificationService.finish({
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.EXPUNGE_DONE'
}))
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.EXPUNGE_DONE'
}))
.map(vm => new vmActions.ExpungeVmSuccess(action.payload))
.catch((error: Error) => {
this.jobsNotificationService.fail({
Expand All @@ -532,9 +539,9 @@ export class VirtualMachinesEffects {
'JOB_NOTIFICATIONS.ISO.ATTACHMENT_IN_PROGRESS');
return this.isoService.attach(action.payload)
.do(() => this.jobsNotificationService.finish({
id: notificationId,
message: 'JOB_NOTIFICATIONS.ISO.ATTACHMENT_DONE'
}))
id: notificationId,
message: 'JOB_NOTIFICATIONS.ISO.ATTACHMENT_DONE'
}))
.map((vm) => new vmActions.UpdateVM(vm))
.catch((error: Error) => {
this.jobsNotificationService.fail({
Expand All @@ -553,9 +560,9 @@ export class VirtualMachinesEffects {
'JOB_NOTIFICATIONS.ISO.DETACHMENT_IN_PROGRESS');
return this.isoService.detach(action.payload)
.do(() => this.jobsNotificationService.finish({
id: notificationId,
message: 'JOB_NOTIFICATIONS.ISO.DETACHMENT_DONE'
}))
id: notificationId,
message: 'JOB_NOTIFICATIONS.ISO.DETACHMENT_DONE'
}))
.map((vm) => new vmActions.ReplaceVM(vm))
.catch((error: Error) => {
this.jobsNotificationService.fail({
Expand Down Expand Up @@ -593,9 +600,9 @@ export class VirtualMachinesEffects {
domainid: changeAction.payload.vm.domainid
})
.do(() => this.jobsNotificationService.finish({
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.CHANGE_SSH_DONE'
}))
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.CHANGE_SSH_DONE'
}))
.switchMap((newVm) => {
if (vmState === VmState.Running) {
return this.start(newVm);
Expand Down Expand Up @@ -638,9 +645,9 @@ export class VirtualMachinesEffects {

return this.vmService.command(resetAction.payload, 'resetPasswordFor')
.do(() => this.jobsNotificationService.finish({
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.RESET_PASSWORD_DONE'
}))
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.RESET_PASSWORD_DONE'
}))
.switchMap((newVm) => {
if (vmState === VmState.Running) {
return this.start(newVm)
Expand Down Expand Up @@ -670,8 +677,8 @@ export class VirtualMachinesEffects {
return this.showConfirmDialog().switchMap(() =>
this.vmTagService.setPassword(action.payload.vm, action.payload.tag)
.do(() => this.jobsNotificationService.finish({
message: 'JOB_NOTIFICATIONS.VM.SAVE_PASSWORD_DONE'
}))
message: 'JOB_NOTIFICATIONS.VM.SAVE_PASSWORD_DONE'
}))
.map((vm) => new vmActions.UpdateVM(vm))
.catch((error: Error) => {
this.jobsNotificationService.fail({
Expand Down Expand Up @@ -714,7 +721,8 @@ export class VirtualMachinesEffects {
new vmActions.DeploymentAddLoggerMessage({
text: 'VM_PAGE.VM_CREATION.DEPLOYMENT_FINISHED',
status: [ProgressLoggerMessageStatus.Highlighted]
})));
})
));

@Effect({ dispatch: false })
vmAccess$: Observable<VirtualMachine> = this.actions$
Expand Down Expand Up @@ -831,11 +839,11 @@ export class VirtualMachinesEffects {
this.update(vm, VmState.InProgress);
return this.vmService.command(vm, 'start')
.do(() => this.jobsNotificationService.finish({
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.START_DONE'
}))
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.START_DONE'
}))
.map((newVm) => new vmActions.UpdateVM(new VirtualMachine(
Object.assign({}, vm, newVm))))
Object.assign({}, vm, newVm))))
.catch((error: Error) => {
this.jobsNotificationService.fail({
id: notificationId,
Expand All @@ -855,9 +863,9 @@ export class VirtualMachinesEffects {
this.update(vm, VmState.InProgress);
return this.vmService.command(vm, 'stop')
.do(() => this.jobsNotificationService.finish({
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.STOP_DONE'
}))
id: notificationId,
message: 'JOB_NOTIFICATIONS.VM.STOP_DONE'
}))
.switchMap((newVm) => Observable.of(newVm))
.catch((error: Error) => {
this.jobsNotificationService.fail({
Expand Down
11 changes: 11 additions & 0 deletions src/app/reducers/volumes/redux/volumes.actions.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Action } from '@ngrx/store';
import { Volume, VolumeCreationData } from '../../../shared/models/volume.model';
import { VirtualMachine } from '../../../vm';

export const LOAD_VOLUMES_REQUEST = '[VOLUMES] LOAD_VOLUMES_REQUEST';
export const LOAD_VOLUMES_RESPONSE = '[VOLUMES] LOAD_VOLUMES_RESPONSE';
export const VOLUME_FILTER_UPDATE = '[VOLUMES] VOLUME_FILTER_UPDATE';
export const LOAD_SELECTED_VOLUME = '[VOLUMES] LOAD_SELECTED_VOLUME';
export const CREATE_VOLUME = '[VOLUMES] CREATE_VOLUME';
export const DELETE_VOLUME = '[VOLUMES] DELETE_VOLUME';
export const DELETE_VOLUMES = '[VOLUMES] DELETE_VOLUMES';
export const UPDATE_VOLUME = '[VOLUMES] UPDATE_VOLUME';
export const REPLACE_VOLUME = '[VOLUMES] REPLACE_VOLUME';
export const ATTACH_VOLUME = '[VOLUMES] ATTACH_VOLUME';
Expand Down Expand Up @@ -67,6 +69,13 @@ export class DeleteVolume implements Action {
}
}

export class DeleteVolumes implements Action {
readonly type = DELETE_VOLUMES;

constructor(public payload: VirtualMachine) {
}
}

export class UpdateVolume implements Action {
readonly type = UPDATE_VOLUME;

Expand Down Expand Up @@ -175,6 +184,8 @@ export type Actions = LoadVolumesRequest
| ReplaceVolume
| AttachVolume
| AttachVolumeToVM
| DeleteVolume
| DeleteVolumes
| DetachVolume
| ResizeVolume
| ChangeDescription;
Loading

0 comments on commit 60e7b9c

Please sign in to comment.