Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Set new templates with specified vm-init #760

Merged
merged 1 commit into from
Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1003,10 +1003,10 @@ private void addVmTemplateToDb() {
vmTemplateDao.save(getVmTemplate());
getCompensationContext().snapshotNewEntity(getVmTemplate());
setActionReturnValue(getVmTemplate().getId());
// Load Vm Init from DB and set it to the template
vmHandler.updateVmInitFromDB(getParameters().getMasterVm(), false);
getVmTemplate().setVmInit(getParameters().getMasterVm().getVmInit());
vmHandler.addVmInitToDB(getVmTemplate().getVmInit());
if (getVmTemplate().getVmInit() != null) {
vmHandler.addVmInitToDB(getVmTemplate().getVmInit());
}
}

private void updateVmIcons() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1339,31 +1339,37 @@ private void onNewTemplate() {
private void postNameUniqueCheck() {
UnitVmModel model = (UnitVmModel) getWindow();
VM vm = getSelectedItem();
// populating VMInit
AsyncQuery<VM> getVmInitQuery = new AsyncQuery<>(completeVm -> {
VM newVm = buildVmOnNewTemplate(model, completeVm);
ljelinkova marked this conversation as resolved.
Show resolved Hide resolved

AddVmTemplateParameters addVmTemplateParameters =
new AddVmTemplateParameters(newVm,
model.getName().getEntity(),
model.getDescription().getEntity());
BuilderExecutor.build(model, addVmTemplateParameters, new UnitToAddVmTemplateParametersBuilder());
model.startProgress();
Frontend.getInstance().runAction(ActionType.AddVmTemplate, addVmTemplateParameters,
result -> {
getWindow().stopProgress();
ActionReturnValue returnValueBase = result.getReturnValue();
if (returnValueBase != null && returnValueBase.getSucceeded()) {
cancel();
}

VM newVm = buildVmOnNewTemplate(model, vm);

AddVmTemplateParameters addVmTemplateParameters =
new AddVmTemplateParameters(newVm,
model.getName().getEntity(),
model.getDescription().getEntity());
BuilderExecutor.build(model, addVmTemplateParameters, new UnitToAddVmTemplateParametersBuilder());
model.startProgress();
Frontend.getInstance().runAction(ActionType.AddVmTemplate, addVmTemplateParameters,
result -> {
getWindow().stopProgress();
ActionReturnValue returnValueBase = result.getReturnValue();
if (returnValueBase != null && returnValueBase.getSucceeded()) {
cancel();
}

}, this);
}, this);
});
// TODO: if we ever support creation of templates from a running vm,
// we would need to take into account next-run configuration here
AsyncDataProvider.getInstance().getVmById(getVmInitQuery, vm.getId());
}

protected static VM buildVmOnNewTemplate(UnitVmModel model, VM vm) {
VM resultVm = new VM();
resultVm.setId(vm.getId());
BuilderExecutor.build(model, resultVm.getStaticData(), new CommonUnitToVmBaseBuilder());
BuilderExecutor.build(vm.getStaticData(), resultVm.getStaticData(), new VmBaseToVmBaseForTemplateCompositeBaseBuilder());
resultVm.setVmInit(vm.getVmInit());
return resultVm;
}

Expand Down