Upgrade getting failed when "output" folder is not present under ZIA directory when migrating to 13005 or above

Upgrade getting failed when "output" folder is not present under ZIA directory when migrating to 13005 or above

Issue:

In the issue fix SD-101380, the AI_DEFAULTMODEL table is removed. That table will be holding the default trained model IDs of Zia Approval Prediciton and the actual models will be stored physically under "<Installation Directory>/ServiceDesk/ZIA/output" folder. Since the table is getting dropped, the models should also be deleted in the mentioned directory and the fix was made accordingly.
      There is a case where customer may disabled all the Zia Prediction and took a backup and restored it in a setup and used it for production. In this scenario, there will be a row present in AI_DEFAULTMODEL for the previously used model during backup and it will be persisted again in restore. The output folder of the ZIA directory will not be taken during backup and new models will be created during startup after restore only if predictions are enabled. 
      So when migrating to the versions which has my SD-101380 fix (13005 and above), it will try to delete all the model files inside output directory which are found in AI_DEFAULTMODEL table but in the above case 'output' directory will not be present which led to NPE during upgrade.

Note: The below issue will occur only when the output folder is not present under "<Installation Directory>/ServiceDesk/ZIA" folder.

Reference Support Tickets:


Error Trace:

Jun 28, 2022 7:01:35 AM  [com.adventnet.persistence.SDPDDChangeListener]  [INFO] :  Post Invoke For Alter Table  Arc_ApprovalDetails finished here
Jun 28, 2022 7:01:35 AM  [com.adventnet.persistence.migration.MigrationUtil]  [INFO] : Going to execute query ::  DROP TABLE "AI_DefaultModel"
Jun 28, 2022 7:01:35 AM  [com.adventnet.persistence.migration.MigrationUtil]  [INFO] : Invoking PreListener
Jun 28, 2022 7:01:35 AM  [com.adventnet.persistence.SDPDDChangeListener]  [INFO] : 
Pre Invoke For Drop Table 
Jun 28, 2022 7:01:35 AM  [com.adventnet.persistence.migration.MigrationUtil]  [INFO] : Exception occured while executing...
Jun 28, 2022 7:01:35 AM  [SYSERR]  [INFO] : java.lang.NullPointerException
Jun 28, 2022 7:01:35 AM  [SYSERR]  [INFO] : at com.adventnet.persistence.SDPDDChangeUtil.deleteDefaultZiaModel(SDPDDChangeUtil.java:457)
Jun 28, 2022 7:01:35 AM  [SYSERR]  [INFO] : at com.adventnet.persistence.SDPDDChangeListener.preInvokeForDropTable(SDPDDChangeListener.java:154)
Jun 28, 2022 7:01:35 AM  [SYSERR]  [INFO] : at com.adventnet.persistence.migration.MigrationUtil.executeQuery(MigrationUtil.java:444)
Jun 28, 2022 7:01:35 AM  [SYSERR]  [INFO] : at com.adventnet.persistence.migration.MigrationUtil.applyDDLChanges(MigrationUtil.java:118)
Jun 28, 2022 7:01:35 AM  [SYSERR]  [INFO] : at com.adventnet.persistence.migration.MigrationUtil.applyDDLChanges(MigrationUtil.java:90)
Jun 28, 2022 7:01:35 AM  [SYSERR]  [INFO] : at com.adventnet.persistence.migration.MigrationUtil.applyDDLChanges(MigrationUtil.java:231)
Jun 28, 2022 7:01:35 AM  [SYSERR]  [INFO] : at com.adventnet.persistence.DefaultPostProcessor.updateDDs(DefaultPostProcessor.java:649)
Jun 28, 2022 7:01:35 AM  [SYSERR]  [INFO] : at com.zoho.iam.migration.IAMPostProcessor.updateDDs(IAMPostProcessor.java:30)
Jun 28, 2022 7:01:35 AM  [SYSERR]  [INFO] : at com.zoho.mickeyclient.migration.MickeyClientPostProcessor.updateDDs(MickeyClientPostProcessor.java:156)
Jun 28, 2022 7:01:35 AM  [SYSERR]  [INFO] : at com.manageengine.servicedesk.updatemgr.util.ESMPostProcessor.updateDDs(ESMPostProcessor.java:64)
Jun 28, 2022 7:01:35 AM  [SYSERR]  [INFO] : at com.adventnet.persistence.DefaultPostProcessor.installPatch(DefaultPostProcessor.java:2170)
Jun 28, 2022 7:01:35 AM  [SYSERR]  [INFO] : at com.zoho.mickeyclient.migration.MickeyClientPostProcessor.installPatch(MickeyClientPostProcessor.java:193)
Jun 28, 2022 7:01:35 AM  [SYSERR]  [INFO] : at com.adventnet.servicedesk.updatemgr.util.SDPostProcessor.installPatch(SDPostProcessor.java:85)
Jun 28, 2022 7:01:35 AM  [SYSERR]  [INFO] : at com.adventnet.persistence.DefaultPostProcessor.install(DefaultPostProcessor.java:1469)
Jun 28, 2022 7:01:35 AM  [SYSERR]  [INFO] : at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
Jun 28, 2022 7:01:35 AM  [SYSERR]  [INFO] : at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
Jun 28, 2022 7:01:35 AM  [SYSERR]  [INFO] : at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
Jun 28, 2022 7:01:35 AM  [SYSERR]  [INFO] : at java.lang.reflect.Method.invoke(Method.java:498)
Jun 28, 2022 7:01:35 AM  [SYSERR]  [INFO] : at com.adventnet.tools.update.installer.Unzipper.contextPostInstallation(Unzipper.java:1716)
Jun 28, 2022 7:01:35 AM  [SYSERR]  [INFO] : at com.adventnet.tools.update.installer.Unzipper.invokePostInstallationClasses(Unzipper.java:1505)
Jun 28, 2022 7:01:35 AM  [SYSERR]  [INFO] : at com.adventnet.tools.update.installer.ApplyPatch.installPatch(ApplyPatch.java:492)
Jun 28, 2022 7:01:35 AM  [SYSERR]  [INFO] : at com.adventnet.tools.update.installer.ApplyPatch.run(ApplyPatch.java:293)
Jun 28, 2022 7:01:35 AM  [SYSERR]  [INFO] : at java.lang.Thread.run(Thread.java:748)
Jun 28, 2022 7:01:35 AM  [com.adventnet.persistence.migration.MigrationUtil]  [INFO] : 
Going to revert


Workaround 1:
 Please follow the below steps:
-> Connect to the database.
-> Execute the below query:
delete from ai_defaultmodel;

Workaround 2:
Please follow the below steps:
-> Go to "<Installation Directory>/ServiceDesk/ZIA" folder
-> Create "output" folder inside it.

After trying the workaroud, now try to upgrade to 13005 or above.

Issue ID: SD-103532

                    New to ADSelfService Plus?