-
Notifications
You must be signed in to change notification settings - Fork 467
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue 30993 EsReadOnlyMonitorJob still shows error (#31074)
The job was still in the database, so an upgrade task was created to remove it from the tables that were related to the job.
- Loading branch information
1 parent
c74694b
commit 83e3277
Showing
3 changed files
with
135 additions
and
1 deletion.
There are no files selected for viewing
70 changes: 70 additions & 0 deletions
70
.../src/main/java/com/dotmarketing/startup/runonce/Task250107RemoveEsReadOnlyMonitorJob.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.dotmarketing.startup.runonce; | ||
|
||
import com.dotmarketing.common.db.DotConnect; | ||
import com.dotmarketing.exception.DotDataException; | ||
import com.dotmarketing.exception.DotRuntimeException; | ||
import com.dotmarketing.startup.StartupTask; | ||
|
||
import java.util.ArrayList; | ||
/** | ||
* Deletes the EsReadOnlyMonitorJob from the database and all the related records. | ||
* */ | ||
public class Task250107RemoveEsReadOnlyMonitorJob implements StartupTask { | ||
|
||
|
||
private final String JOB_NAME = "EsReadOnlyMonitorJob"; | ||
private final String TRIGGER_NAME = "trigger29"; | ||
private final String CRON_TABLE_NAME = "qrtz_excl_cron_triggers"; | ||
private final String TRIGGER_TABLE_NAME = "qrtz_excl_triggers"; | ||
private final String JOB_TABLE_NAME = "qrtz_excl_job_details"; | ||
|
||
/** | ||
* Determines if the task should be forced to run. | ||
* | ||
* @return true if EsReadOnlyMonitorJob is found, false otherwise. | ||
*/ | ||
@Override | ||
public final boolean forceRun() { | ||
String sql=String.format("SELECT * FROM %s WHERE job_name=?", JOB_TABLE_NAME); | ||
DotConnect dc=new DotConnect(); | ||
dc.setSQL(sql); | ||
|
||
dc.addParam(JOB_NAME); | ||
try { | ||
if (!dc.loadResults().isEmpty()){ | ||
return true; | ||
} | ||
} catch (DotDataException e) { | ||
e.printStackTrace(); | ||
} | ||
return false; | ||
} | ||
|
||
@Override | ||
public final void executeUpgrade() throws DotDataException, DotRuntimeException { | ||
removeCron(); | ||
removeTrigger(); | ||
removeJob(); | ||
} | ||
|
||
private void removeJob() throws DotDataException { | ||
DotConnect dc = new DotConnect(); | ||
dc.setSQL(String.format("DELETE FROM %s WHERE job_name = ?", JOB_TABLE_NAME)); | ||
dc.addParam(JOB_NAME); | ||
dc.loadResult(); | ||
} | ||
|
||
private void removeTrigger() throws DotDataException { | ||
DotConnect dc = new DotConnect(); | ||
dc.setSQL(String.format("DELETE FROM %s WHERE job_name = ?", TRIGGER_TABLE_NAME)); | ||
dc.addParam(JOB_NAME); | ||
dc.loadResult(); | ||
} | ||
|
||
private void removeCron() throws DotDataException { | ||
DotConnect dc = new DotConnect(); | ||
dc.setSQL(String.format("DELETE FROM %s WHERE trigger_name = ?", CRON_TABLE_NAME)); | ||
dc.addParam(TRIGGER_NAME); | ||
dc.loadResult(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
.../test/java/com/dotmarketing/startup/runonce/Task250107RemoveEsReadOnlyMonitorJobTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package com.dotmarketing.startup.runonce; | ||
|
||
import com.dotcms.util.IntegrationTestInitService; | ||
import com.dotmarketing.common.db.DotConnect; | ||
import com.dotmarketing.exception.DotDataException; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.junit.Assert; | ||
|
||
import java.sql.SQLException; | ||
|
||
public class Task250107RemoveEsReadOnlyMonitorJobTest { | ||
|
||
|
||
private final String JOB_NAME = "EsReadOnlyMonitorJob"; | ||
private final String TRIGGER_NAME = "trigger29"; | ||
private final String CRON_TABLE_NAME = "qrtz_excl_cron_triggers"; | ||
private final String TRIGGER_TABLE_NAME = "qrtz_excl_triggers"; | ||
private final String JOB_TABLE_NAME = "qrtz_excl_job_details"; | ||
|
||
|
||
@BeforeClass | ||
public static void prepare() throws Exception { | ||
IntegrationTestInitService.getInstance().init(); | ||
} | ||
|
||
|
||
@Test | ||
public void test_job() throws DotDataException, SQLException { | ||
final DotConnect dc = new DotConnect(); | ||
|
||
Task250107RemoveEsReadOnlyMonitorJob upgradeTask = new Task250107RemoveEsReadOnlyMonitorJob(); | ||
|
||
if (!upgradeTask.forceRun()) { | ||
dc.setSQL(String.format("INSERT INTO %s (job_name, job_group, job_class_name, is_durable, is_volatile, is_stateful, requests_recovery) VALUES (?, 'dotcms_jobs', 'com.dotmarketing.quartz.job.EsReadOnlyMonitorJob', 'f', 'f', 'f', 'f')", JOB_TABLE_NAME)); | ||
dc.addParam(JOB_NAME); | ||
dc.loadResults(); | ||
|
||
dc.setSQL(String.format("INSERT INTO %s (job_name, trigger_name, trigger_group, job_group, is_volatile, trigger_state, trigger_type, start_time) VALUES (?,?, 'group98', 'dotcms_jobs', 'f', 'WAITING', 'CRON', 17362" + | ||
"84300000)", TRIGGER_TABLE_NAME)); | ||
dc.addParam(JOB_NAME); | ||
dc.addParam(TRIGGER_NAME); | ||
dc.loadResults(); | ||
|
||
dc.setSQL(String.format("INSERT INTO %s (trigger_name, trigger_group, cron_expression) VALUES (?, 'group98', '0 */5 * ? * *')", CRON_TABLE_NAME)); | ||
dc.addParam(TRIGGER_NAME); | ||
dc.loadResults(); | ||
|
||
Assert.assertFalse(dc.setSQL("SELECT * FROM " + JOB_TABLE_NAME + " WHERE job_name = '" + JOB_NAME + "'").loadResults().isEmpty()); | ||
} | ||
|
||
|
||
Assert.assertTrue(upgradeTask.forceRun()); | ||
|
||
upgradeTask.executeUpgrade(); | ||
|
||
Assert.assertTrue(dc.setSQL("SELECT * FROM " + JOB_TABLE_NAME + " WHERE job_name = '" + JOB_NAME + "'").loadResults().isEmpty()); | ||
|
||
} | ||
|
||
|
||
} |