Adding a dependent field for a BackupProvider Plugin is not working

Hello,

I am trying to create a BackupProvider plugin.
I was able to successfully register the plugin and updated my vCenter cloud provider to use my registered plugin as the “BackupProvider”.

Next, I am trying to create a new Instance from “Provisioning > Instances > Add” menu.
On the “Automation” tab “Backups” sections are the options I am trying to override the default options.

The options I am trying to override are:

  • Backup Type
  • Backup Job Type
  • Backup Schedule

Currently, I was able to override the options for “Backup Type” dropdown but I am not able to override the options for “Backup Job Type”

Here is the code that I am trying:

Backup Type:

@Override
	Collection<OptionType> getBackupOptionTypes() {
		Collection<OptionType> optionTypes = new ArrayList()

		log.info("********* Inside getBackupOptionTypes() function in TestBackupProvider class *******")

		optionTypes << new OptionType(
				code:'backup-provider', inputType:OptionType.InputType.SELECT, name:'backup.backupType', optionSource:'getTestBackupTypeOptions',
				category:'backup.backupType', fieldName:'backup.backupType', fieldCode: 'backupType', fieldLabel:'Backup Type', fieldContext:'backup.config',
				required:true, enabled:true, editable:true, global:false, placeHolder:null, helpBlock:'', defaultValue:null, custom:false,
				displayOrder:0, fieldClass:null
		)

		return optionTypes;
	}

Backup Job Type:

@Override
	Collection<OptionType> getBackupJobOptionTypes() {
		Collection<OptionType> optionTypes = new ArrayList()
		log.info("********* Inside getBackupJobOptionTypes() function in TestBackupProvider class *******")

		optionTypes << new OptionType(
				code:'backup-job-action', inputType:OptionType.InputType.SELECT, name:'backup.jobAction', optionSource:'getTestBackupJobTypeOptions',
				category:'backup.jobAction', fieldName:'backup.jobAction', fieldCode: 'backupJobAction', fieldLabel:'Backup Job Type', fieldContext:'backup.config',
				required:false, enabled:true, editable:true, global:false, placeHolder:null, helpBlock:'', defaultValue:null, custom:false,
				displayOrder:1, fieldClass:null, dependsOn: 'backup.config.backup.backupType'
		)

		return optionTypes;
	}

DOM Image for Backup Type and Backup Job Type:

Am I doing anything wrong here?

The default fields can’t be overridden. You can adjust the values in job actions by adjusting the following values on your backup provider:

	@Override
	public Boolean getHasCreateJob() { return true; }

	@Override
	public Boolean getHasCloneJob() { return true; }

	@Override
	public Boolean getHasAddToJob() { return true; }

	@Override
	public Boolean getHasOptionalJob() { return true; }

And you can disable job schedules with the return value on:

	@Override
	public Boolean getHasSchedule() { return true; }

Thanks @ddeyoung for your reply!

So, what you saying is, the “Backup Job Type” field values cannot be overridden but the field can be hidden. Is that the correct understanding?

Also, I was able to override the values for “Backup Type” dropdown by overriding the Collection<OptionType> getBackupOptionTypes() function.
Can’t I do the same by overriding the Collection<OptionType> getBackupJobOptionTypes() function?

If not, then do I have to add my custom fields on the form under the ``Collection getBackupOptionTypes() function itself?

Thanks @ddeyoung ! I have created my custom fields within getBackupOptionTypes() function and they are now showing up in the form.

I have added 2 dropdowns and one is dependent on the other but the dependent dropdown is not getting the value of the parent dropdown because of which my condition is not evaluating to true to load the options.

Here is my code:

Options:

@Override
	Collection<OptionType> getBackupOptionTypes() {
		Collection<OptionType> optionTypes = new ArrayList()

		log.info("********* Inside getBackupOptionTypes() function in HpeBackupProvider class *******")

		optionTypes << new OptionType(
				code:'backup-provider', inputType:OptionType.InputType.SELECT, name:'backup.backupType', optionSource:'getTestBackupTypeOptions',
				category:'backup.backupType', fieldName:'backup.backupType', fieldCode: 'backupType', fieldLabel:'Backup Type', fieldContext:'backup.config',
				required:true, enabled:true, editable:true, global:false, placeHolder:null, helpBlock:'', defaultValue:null, custom:false,
				displayOrder:0, fieldClass:null
		)

		optionTypes << new OptionType(
				code:'test-backup-job-action', inputType:OptionType.InputType.SELECT, name:'testBackup.jobAction', optionSource:'getBackupScheduleOptions',
				category:'testBackup.jobAction', fieldName:'testBackup.jobAction', fieldCode: 'testBackupJobAction', fieldLabel:'Backup Job Type', fieldContext:'backup.config',
				required:true, enabled:true, editable:true, global:false, placeHolder:null, helpBlock:'', defaultValue:null, custom:false,
				displayOrder:1, fieldClass:null, dependsOn: 'backup-provider'
		)

		return optionTypes;
	}

Function to populate dropdown options:

def getBackupScheduleOptions(args)
	{
		log.info("Args ${args}")
		log.info("jsonPayload ${args?.'jsonPayload'}") // [:]]]
		log.info("Args Config ${args?.'config'}") // [[noAgent:false, smbiosAssetTag:, nestedVirtualization:, hostId:, vmwareFolderId:/, expose:8080]] 
		log.info("Args backup.config.backup.backupType ${args?.'backup.config.backup.backupType'}") // null
		log.info("Args config.backup.backupType ${args?.'config.backup.backupType'}") // null
		log.info("Args backup.backupType ${args?.'backup.backupType'}") // null
		log.info("Args backup-provider ${args?.'backup-provider'}") // null
		log.info("Args config.backup-provider ${args?.'config?.backup-provider'}") // null


		if(StringUtils.equals(args?."backupType"?.toString(), "localBackup"))
		{
			return getLocalBackupScheduleOptions(args)
		}
		else
		{
			return getArrayBackupScheduleOptions(args)
		}
	}

I was able to get the functions working.
The only problem I have right now is, when the parent dropdown value is selected, the child dropdown does not get updated because the change event is not getting triggered.
It is only triggered when the “Backups” section of the form is collapsed first and then expanded.

Am I missing something?

You’re like hitting an issue where the event listener is only firing events on the first field with the same code/id/name. Try giving your “Backup Type” a unique code.

Overriding the default fields like this will likely cause other issues during and after the backup is created. I would suggest making multiple backup providers in your plugin rather than overriding the backup type field.

Thanks!

I tried your suggestion:

optionTypes << new OptionType(
				code:'test-1231232131231-backup-type', inputType:OptionType.InputType.SELECT, name:'backup.testBackupType', optionSource:'getTestBackupTypeOptions',
				category:'backup.testBackupType', fieldName:'backup.testBackupType', fieldCode: 'testBackupType', fieldLabel:'Test Backup Type', fieldContext:'backup.config',
				required:true, enabled:true, editable:true, global:false, placeHolder:null, helpBlock:'', defaultValue:null, custom:false,
				displayOrder:1, fieldClass:null
		)

		optionTypes << new OptionType(
				code:'test-123213213-backup-schedule', inputType:OptionType.InputType.SELECT, name:'testBackup.schedule', optionSource:'getBackupScheduleOptions',
				category:'testBackup.schedule', fieldName:'testBackup.schedule', fieldCode: 'testBackupSchedule', fieldLabel:'Test Backup Schedule', fieldContext:'backup.config',
				required:true, enabled:true, editable:true, global:false, placeHolder:null, helpBlock:'', defaultValue:null, custom:false,
				displayOrder:2, fieldClass:null, dependsOn: 'test-1231232131231-backup-type'
		)

Getting the same result. Only loads the first time and when the section is collapsed and expanded again :frowning_face:

Update:
It is now working :smiley: when I am launching the backup wizard from the VM details page (when the VM is already available).
It is not working from the page when a new Instance is being provisioned.
I see there are fields with similar names on that window but I verified that the names of my custom fields don’t match with them now. Can they still be causing a problem?