use of org.camunda.bpm.engine.impl.management.DatabasePurgeReport in project camunda-bpm-platform by camunda.
the class PurgeDatabaseAndCacheCmd method purgeDatabase.
private DatabasePurgeReport purgeDatabase(CommandContext commandContext) {
DbEntityManager dbEntityManager = commandContext.getDbEntityManager();
// For MySQL and MariaDB we have to disable foreign key check,
// to delete the table data as bulk operation (execution, incident etc.)
// The flag will be reset by the DBEntityManager after flush.
dbEntityManager.setIgnoreForeignKeysForNextFlush(true);
List<String> tablesNames = dbEntityManager.getTableNamesPresentInDatabase();
String databaseTablePrefix = commandContext.getProcessEngineConfiguration().getDatabaseTablePrefix().trim();
// for each table
DatabasePurgeReport databasePurgeReport = new DatabasePurgeReport();
for (String tableName : tablesNames) {
String tableNameWithoutPrefix = tableName.replace(databaseTablePrefix, EMPTY_STRING);
if (!TABLENAMES_EXCLUDED_FROM_DB_CLEAN_CHECK.contains(tableNameWithoutPrefix)) {
// Check if table contains data
Map<String, String> param = new HashMap<String, String>();
param.put(TABLE_NAME, tableName);
Long count = (Long) dbEntityManager.selectOne(SELECT_TABLE_COUNT, param);
if (count > 0) {
databasePurgeReport.addPurgeInformation(tableName, count);
// Get corresponding entity classes for the table, which contains data
List<Class<? extends DbEntity>> entities = commandContext.getTableDataManager().getEntities(tableName);
if (entities.isEmpty()) {
throw new ProcessEngineException("No mapped implementation of " + DbEntity.class.getName() + " was found for: " + tableName);
}
// Delete the table data as bulk operation with the first entity
Class<? extends DbEntity> entity = entities.get(0);
DbBulkOperation deleteBulkOp = new DbBulkOperation(DbOperationType.DELETE_BULK, entity, DELETE_TABLE_DATA, param);
dbEntityManager.getDbOperationManager().addOperation(deleteBulkOp);
}
}
}
return databasePurgeReport;
}
use of org.camunda.bpm.engine.impl.management.DatabasePurgeReport in project camunda-bpm-platform by camunda.
the class EnsureCleanDbPlugin method postProcessApplicationUndeploy.
@SuppressWarnings("resource")
@Override
public void postProcessApplicationUndeploy(ProcessApplicationInterface processApplication) {
// best example is TestWarDeploymentWithBrokenBpmnXml in integration-test-engine test suite
if (counter.get() == 0 || counter.decrementAndGet() == 0) {
final ProcessEngine defaultProcessEngine = BpmPlatform.getDefaultProcessEngine();
try {
logger.log(Level.INFO, "=== Ensure Clean Database ===");
ManagementServiceImpl managementService = (ManagementServiceImpl) defaultProcessEngine.getManagementService();
PurgeReport report = managementService.purge();
if (report.isEmpty()) {
logger.log(Level.INFO, "Clean DB and cache.");
} else {
StringBuilder builder = new StringBuilder();
DatabasePurgeReport databasePurgeReport = report.getDatabasePurgeReport();
if (!databasePurgeReport.isEmpty()) {
builder.append(DATABASE_NOT_CLEAN).append(databasePurgeReport.getPurgeReportAsString());
}
CachePurgeReport cachePurgeReport = report.getCachePurgeReport();
if (!cachePurgeReport.isEmpty()) {
builder.append(CACHE_IS_NOT_CLEAN).append(cachePurgeReport.getPurgeReportAsString());
}
logger.log(Level.INFO, builder.toString());
}
} catch (Throwable e) {
logger.log(Level.SEVERE, "Could not clean DB:", e);
}
}
}
use of org.camunda.bpm.engine.impl.management.DatabasePurgeReport in project camunda-bpm-platform by camunda.
the class PurgeDatabaseTest method testPurgeCmmnProcess.
// CMMN //////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Test
public void testPurgeCmmnProcess() {
// given cmmn process which is not managed by process engine rule
engineRule.getRepositoryService().createDeployment().addClasspathResource("org/camunda/bpm/engine/test/standalone/db/entitymanager/PurgeDatabaseTest.testPurgeCmmnProcess.cmmn").deploy();
VariableMap variables = Variables.createVariables();
variables.put("key", "value");
engineRule.getCaseService().createCaseInstanceByKey(PROCESS_DEF_KEY, variables);
// when purge is executed
ManagementServiceImpl managementService = (ManagementServiceImpl) engineRule.getManagementService();
PurgeReport purge = managementService.purge();
// then database and cache is cleaned
assertAndEnsureCleanDbAndCache(engineRule.getProcessEngine(), true);
// and report contains deleted entities
assertFalse(purge.isEmpty());
CachePurgeReport cachePurgeReport = purge.getCachePurgeReport();
assertEquals(1, cachePurgeReport.getReportValue(CachePurgeReport.CASE_DEF_CACHE).size());
DatabasePurgeReport databasePurgeReport = purge.getDatabasePurgeReport();
assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RE_DEPLOYMENT"));
assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RU_TASK"));
assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_GE_BYTEARRAY"));
assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RE_CASE_DEF"));
assertEquals(3, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RU_CASE_EXECUTION"));
assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RU_VARIABLE"));
assertEquals(2, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RU_CASE_SENTRY_PART"));
if (processEngineConfiguration.getHistoryLevel().equals(HistoryLevel.HISTORY_LEVEL_FULL)) {
assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_HI_DETAIL"));
assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_HI_TASKINST"));
assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_HI_VARINST"));
assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_HI_CASEINST"));
assertEquals(2, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_HI_CASEACTINST"));
}
}
use of org.camunda.bpm.engine.impl.management.DatabasePurgeReport in project camunda-bpm-platform by camunda.
the class PurgeDatabaseTest method testPurgeDmnProcess.
// DMN ///////////////////////////////////////////////////////////////////////////////////////////////////////////////
@Test
public void testPurgeDmnProcess() {
// given dmn process which is not managed by process engine rule
engineRule.getRepositoryService().createDeployment().addClasspathResource("org/camunda/bpm/engine/test/standalone/db/entitymanager/PurgeDatabaseTest.testPurgeDmnProcess.dmn").deploy();
VariableMap variables = Variables.createVariables().putValue("key", "value").putValue("season", "Test");
engineRule.getDecisionService().evaluateDecisionByKey("decisionId").variables(variables).evaluate();
// when purge is executed
ManagementServiceImpl managementService = (ManagementServiceImpl) engineRule.getManagementService();
PurgeReport purge = managementService.purge();
// then database and cache is cleaned
assertAndEnsureCleanDbAndCache(engineRule.getProcessEngine(), true);
// and report contains deleted entities
assertFalse(purge.isEmpty());
CachePurgeReport cachePurgeReport = purge.getCachePurgeReport();
assertEquals(2, cachePurgeReport.getReportValue(CachePurgeReport.DMN_DEF_CACHE).size());
assertEquals(1, cachePurgeReport.getReportValue(CachePurgeReport.DMN_REQ_DEF_CACHE).size());
DatabasePurgeReport databasePurgeReport = purge.getDatabasePurgeReport();
assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RE_DEPLOYMENT"));
assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_GE_BYTEARRAY"));
assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RE_DECISION_REQ_DEF"));
assertEquals(2, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_RE_DECISION_DEF"));
if (processEngineConfiguration.getHistoryLevel().equals(HistoryLevel.HISTORY_LEVEL_FULL)) {
assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_HI_DECINST"));
assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_HI_DEC_IN"));
assertEquals(1, (long) databasePurgeReport.getReportValue(databaseTablePrefix + "ACT_HI_DEC_OUT"));
}
}
use of org.camunda.bpm.engine.impl.management.DatabasePurgeReport in project camunda-bpm-platform by camunda.
the class PurgeDatabaseAndCacheCmd method execute.
@Override
public PurgeReport execute(CommandContext commandContext) {
PurgeReport purgeReport = new PurgeReport();
// purge the database
DatabasePurgeReport databasePurgeReport = purgeDatabase(commandContext);
purgeReport.setDatabasePurgeReport(databasePurgeReport);
// purge the deployment cache
DeploymentCache deploymentCache = commandContext.getProcessEngineConfiguration().getDeploymentCache();
CachePurgeReport cachePurgeReport = deploymentCache.purgeCache();
purgeReport.setCachePurgeReport(cachePurgeReport);
return purgeReport;
}
Aggregations