Search in sources :

Example 1 with DatabasePurgeReport

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;
}
Also used : HashMap(java.util.HashMap) DatabasePurgeReport(org.camunda.bpm.engine.impl.management.DatabasePurgeReport) DbEntityManager(org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager) DbEntity(org.camunda.bpm.engine.impl.db.DbEntity) DbBulkOperation(org.camunda.bpm.engine.impl.db.entitymanager.operation.DbBulkOperation) ProcessEngineException(org.camunda.bpm.engine.ProcessEngineException)

Example 2 with 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);
        }
    }
}
Also used : ManagementServiceImpl(org.camunda.bpm.engine.impl.ManagementServiceImpl) DatabasePurgeReport(org.camunda.bpm.engine.impl.management.DatabasePurgeReport) CachePurgeReport(org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport) CachePurgeReport(org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport) DatabasePurgeReport(org.camunda.bpm.engine.impl.management.DatabasePurgeReport) PurgeReport(org.camunda.bpm.engine.impl.management.PurgeReport) ProcessEngine(org.camunda.bpm.engine.ProcessEngine)

Example 3 with DatabasePurgeReport

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"));
    }
}
Also used : ManagementServiceImpl(org.camunda.bpm.engine.impl.ManagementServiceImpl) VariableMap(org.camunda.bpm.engine.variable.VariableMap) DatabasePurgeReport(org.camunda.bpm.engine.impl.management.DatabasePurgeReport) CachePurgeReport(org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport) PurgeReport(org.camunda.bpm.engine.impl.management.PurgeReport) CachePurgeReport(org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport) DatabasePurgeReport(org.camunda.bpm.engine.impl.management.DatabasePurgeReport) Test(org.junit.Test)

Example 4 with DatabasePurgeReport

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"));
    }
}
Also used : ManagementServiceImpl(org.camunda.bpm.engine.impl.ManagementServiceImpl) VariableMap(org.camunda.bpm.engine.variable.VariableMap) DatabasePurgeReport(org.camunda.bpm.engine.impl.management.DatabasePurgeReport) CachePurgeReport(org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport) PurgeReport(org.camunda.bpm.engine.impl.management.PurgeReport) CachePurgeReport(org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport) DatabasePurgeReport(org.camunda.bpm.engine.impl.management.DatabasePurgeReport) Test(org.junit.Test)

Example 5 with DatabasePurgeReport

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;
}
Also used : DatabasePurgeReport(org.camunda.bpm.engine.impl.management.DatabasePurgeReport) DeploymentCache(org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache) CachePurgeReport(org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport) CachePurgeReport(org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport) DatabasePurgeReport(org.camunda.bpm.engine.impl.management.DatabasePurgeReport) PurgeReport(org.camunda.bpm.engine.impl.management.PurgeReport)

Aggregations

DatabasePurgeReport (org.camunda.bpm.engine.impl.management.DatabasePurgeReport)7 PurgeReport (org.camunda.bpm.engine.impl.management.PurgeReport)6 CachePurgeReport (org.camunda.bpm.engine.impl.persistence.deploy.cache.CachePurgeReport)6 ManagementServiceImpl (org.camunda.bpm.engine.impl.ManagementServiceImpl)5 Test (org.junit.Test)3 VariableMap (org.camunda.bpm.engine.variable.VariableMap)2 HashMap (java.util.HashMap)1 ProcessEngine (org.camunda.bpm.engine.ProcessEngine)1 ProcessEngineException (org.camunda.bpm.engine.ProcessEngineException)1 ProcessEngineImpl (org.camunda.bpm.engine.impl.ProcessEngineImpl)1 ProcessEngineConfigurationImpl (org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl)1 DbEntity (org.camunda.bpm.engine.impl.db.DbEntity)1 DbEntityManager (org.camunda.bpm.engine.impl.db.entitymanager.DbEntityManager)1 DbBulkOperation (org.camunda.bpm.engine.impl.db.entitymanager.operation.DbBulkOperation)1 DeploymentCache (org.camunda.bpm.engine.impl.persistence.deploy.cache.DeploymentCache)1 BpmnModelInstance (org.camunda.bpm.model.bpmn.BpmnModelInstance)1