summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntje Fuhrmann2012-08-17 05:11:40 (EDT)
committerManik Kishore2012-08-17 05:11:40 (EDT)
commita86ae54141b9c4350947a5cfb3a655e18dad6300 (patch)
tree24b02a7c551f993dbd325a287547e28542f4c264
parent8c53db18fa906b90f273a977bf4f7439b4f22d28 (diff)
downloadorg.eclipse.stardust.engine-a86ae54141b9c4350947a5cfb3a655e18dad6300.zip
org.eclipse.stardust.engine-a86ae54141b9c4350947a5cfb3a655e18dad6300.tar.gz
org.eclipse.stardust.engine-a86ae54141b9c4350947a5cfb3a655e18dad6300.tar.bz2
Jira-ID: CRNT-25668
Runtime upgrade jobs should log output that makes it easy to identify progress during execution. git-svn-id: http://emeafrazerg/svn/ipp/product/trunk/stardust/engine@58469 8100b5e0-4d52-466c-ae9c-bdeccbdeaf6b
-rw-r--r--stardust-engine-core/src/main/java/org/eclipse/stardust/engine/core/upgrade/framework/RuntimeUpgradeTaskExecutor.java121
-rw-r--r--stardust-engine-core/src/main/java/org/eclipse/stardust/engine/core/upgrade/framework/UpgradeTask.java14
-rw-r--r--stardust-engine-core/src/main/java/org/eclipse/stardust/engine/core/upgrade/jobs/R7_0_0from6_x_xRuntimeJob.java458
-rw-r--r--stardust-engine-core/src/test/java/org/eclipse/stardust/engine/core/upgrade/UpgradeTestSuite.java3
-rw-r--r--stardust-engine-core/src/test/java/org/eclipse/stardust/engine/core/upgrade/framework/RuntimeUpgradeTaskExecutorTest.java127
5 files changed, 545 insertions, 178 deletions
diff --git a/stardust-engine-core/src/main/java/org/eclipse/stardust/engine/core/upgrade/framework/RuntimeUpgradeTaskExecutor.java b/stardust-engine-core/src/main/java/org/eclipse/stardust/engine/core/upgrade/framework/RuntimeUpgradeTaskExecutor.java
new file mode 100644
index 0000000..6fee7d6
--- /dev/null
+++ b/stardust-engine-core/src/main/java/org/eclipse/stardust/engine/core/upgrade/framework/RuntimeUpgradeTaskExecutor.java
@@ -0,0 +1,121 @@
+package org.eclipse.stardust.engine.core.upgrade.framework;
+
+import java.io.PrintStream;
+import java.util.List;
+
+import org.eclipse.stardust.common.CollectionUtils;
+
+/**
+ * The RuntimeUpgradeTaskExecutor executes all added upgrade tasks (upgrade schema,
+ * migrate data, finalize schema) of a runtime upgrade job and displays the progress
+ * during execution.
+ *
+ */
+public class RuntimeUpgradeTaskExecutor
+{
+ private List<UpgradeTask> upgradeSchemaTasks = CollectionUtils.newArrayList();
+
+ private List<UpgradeTask> migrateDataTasks = CollectionUtils.newArrayList();
+
+ private List<UpgradeTask> finalizeSchemaTasks = CollectionUtils.newArrayList();
+
+ private final boolean upgradeData;
+
+ private int currentTaskNumber = 1;
+
+ private final String jobName;
+
+ private final PrintStream console;
+
+ public RuntimeUpgradeTaskExecutor(String jobName, boolean upgradeData)
+ {
+ this(jobName, upgradeData, System.out);
+ }
+
+ RuntimeUpgradeTaskExecutor(String jobName, boolean upgradeData, PrintStream print)
+ {
+ this.console = print;
+ this.jobName = jobName;
+ this.upgradeData = upgradeData;
+ }
+
+ public void addUpgradeSchemaTask(UpgradeTask task)
+ {
+ upgradeSchemaTasks.add(task);
+ }
+
+ public void addMigrateDataTask(UpgradeTask task)
+ {
+ migrateDataTasks.add(task);
+ }
+
+ public void addFinalizeSchemaTask(UpgradeTask task)
+ {
+ finalizeSchemaTasks.add(task);
+ }
+
+ public void executeUpgradeSchemaTasks()
+ {
+ execute(upgradeSchemaTasks);
+ }
+
+ public void executeMigrateDataTasks()
+ {
+ execute(migrateDataTasks);
+ }
+
+ public void executeFinalizeSchemaTasks()
+ {
+ execute(finalizeSchemaTasks);
+ }
+
+ private void execute(List<UpgradeTask> upgradeTasks)
+ {
+ if (currentTaskNumber == 1)
+ {
+ console.println("Upgrade Job " + jobName + ":");
+ }
+ if (getUpgradeTaskCount() == 0)
+ {
+ console.println("No upgrade tasks available.");
+ }
+ for (UpgradeTask upgradeTask : upgradeTasks)
+ {
+ console.println("Upgrading data block: " + currentTaskNumber + " of "
+ + getUpgradeTaskCount() + ". " + getProgressInPercent() + " % completed.");
+ upgradeTask.execute();
+ currentTaskNumber++;
+ }
+ if (getUpgradeTaskCount() > 0 && currentTaskNumber > getUpgradeTaskCount())
+ {
+ console.println("Upgrade Job " + jobName + ": " + getProgressInPercent()
+ + " % completed.");
+ }
+ }
+
+ private int getProgressInPercent()
+ {
+ int percent = 0;
+ if (currentTaskNumber > 1)
+ {
+ percent = ((currentTaskNumber - 1) * 100) / getUpgradeTaskCount();
+ }
+ return percent;
+ }
+
+ private int getUpgradeTaskCount()
+ {
+ int count = 0;
+ if (upgradeData)
+ {
+ count = migrateDataTasks.size();
+ }
+ else
+ {
+ count = upgradeSchemaTasks.size() + migrateDataTasks.size()
+ + finalizeSchemaTasks.size();
+ }
+ return count;
+ }
+
+}
diff --git a/stardust-engine-core/src/main/java/org/eclipse/stardust/engine/core/upgrade/framework/UpgradeTask.java b/stardust-engine-core/src/main/java/org/eclipse/stardust/engine/core/upgrade/framework/UpgradeTask.java
new file mode 100644
index 0000000..5133ac4
--- /dev/null
+++ b/stardust-engine-core/src/main/java/org/eclipse/stardust/engine/core/upgrade/framework/UpgradeTask.java
@@ -0,0 +1,14 @@
+package org.eclipse.stardust.engine.core.upgrade.framework;
+
+/**
+ * The UpgradeTask provides a separate task of a runtime upgrade job.
+ *
+ */
+public interface UpgradeTask
+{
+
+ /**
+ * The upgrade task will be executed.
+ */
+ void execute();
+}
diff --git a/stardust-engine-core/src/main/java/org/eclipse/stardust/engine/core/upgrade/jobs/R7_0_0from6_x_xRuntimeJob.java b/stardust-engine-core/src/main/java/org/eclipse/stardust/engine/core/upgrade/jobs/R7_0_0from6_x_xRuntimeJob.java
index dbf5243..3ee5b1b 100644
--- a/stardust-engine-core/src/main/java/org/eclipse/stardust/engine/core/upgrade/jobs/R7_0_0from6_x_xRuntimeJob.java
+++ b/stardust-engine-core/src/main/java/org/eclipse/stardust/engine/core/upgrade/jobs/R7_0_0from6_x_xRuntimeJob.java
@@ -123,6 +123,8 @@ public class R7_0_0from6_x_xRuntimeJob extends DbmsAwareRuntimeUpgradeJob
private static final String AI_LCK_TABLE_NAME = "activity_instance_lck";
private static final String P_LCK_TABLE_NAME = "partition_lck";
private static final String P_LCK_FIELD__OID = "oid";
+
+ private RuntimeUpgradeTaskExecutor upgradeTaskExecutor;
R7_0_0from6_x_xRuntimeJob()
@@ -130,225 +132,340 @@ public class R7_0_0from6_x_xRuntimeJob extends DbmsAwareRuntimeUpgradeJob
super(new DBMSKey[] {
DBMSKey.ORACLE, DBMSKey.ORACLE9i, DBMSKey.DB2_UDB, DBMSKey.MYSQL,
DBMSKey.DERBY, DBMSKey.POSTGRESQL, DBMSKey.SYBASE, DBMSKey.MSSQL8});
+ initUpgradeTasks();
}
-
+
public Version getVersion()
{
return VERSION;
}
- protected void upgradeSchema(boolean recover) throws UpgradeException
+ private void initUpgradeTasks()
+ {
+ upgradeTaskExecutor = new RuntimeUpgradeTaskExecutor("R7_0_0from6_x_xRuntimeJob", Parameters.instance()
+ .getBoolean(RuntimeUpgrader.UPGRADE_DATA, false));
+ initUpgradeSchemaTasks();
+ initMigrateDataTasks();
+ initFinalizeSchemaTasks();
+ }
+
+ private void initUpgradeSchemaTasks()
{
- // Alter ActivityInstance Table
- DatabaseHelper.alterTable(item, new AlterTableInfo(ACTIVITY_INSTANCE_TABLE_NAME)
+ final R7_0_0from6_x_xRuntimeJob runtimeJob = this;
+
+ upgradeTaskExecutor.addUpgradeSchemaTask(new UpgradeTask()
{
- private final FieldInfo CRITICALITY = new FieldInfo(
- ACTIVITY_INSTANCE_FIELD_CRITICALITY, Double.TYPE);
+ @Override
+ public void execute()
+ {
+ // Alter ActivityInstance Table
+ DatabaseHelper.alterTable(item, new AlterTableInfo(ACTIVITY_INSTANCE_TABLE_NAME)
+ {
+ private final FieldInfo CRITICALITY = new FieldInfo(
+ ACTIVITY_INSTANCE_FIELD_CRITICALITY, Double.TYPE);
- private final FieldInfo PROPERTIES_AVAILABLE = new FieldInfo(
- ACTIVITY_INSTANCE_FIELD_PROPERTIES, Integer.TYPE);
+ private final FieldInfo PROPERTIES_AVAILABLE = new FieldInfo(
+ ACTIVITY_INSTANCE_FIELD_PROPERTIES, Integer.TYPE);
- private final FieldInfo PROCESS_INSTANCE = new FieldInfo(
- ACTIVITY_INSTANCE_FIELD_PI, Long.TYPE, 0, false);
+ private final FieldInfo PROCESS_INSTANCE = new FieldInfo(
+ ACTIVITY_INSTANCE_FIELD_PI, Long.TYPE, 0, false);
- @Override
- public FieldInfo[] getAddedFields()
- {
- return new FieldInfo[] {CRITICALITY, PROPERTIES_AVAILABLE};
- }
+ @Override
+ public FieldInfo[] getAddedFields()
+ {
+ return new FieldInfo[] {CRITICALITY, PROPERTIES_AVAILABLE};
+ }
- @Override
- public IndexInfo[] getAddedIndexes()
- {
- return new IndexInfo[] {//
- new IndexInfo(ACTIVITY_INSTANCE_IDX9, false, new FieldInfo[] {
- CRITICALITY,
- PROCESS_INSTANCE }) };
- }
+ @Override
+ public IndexInfo[] getAddedIndexes()
+ {
+ return new IndexInfo[] {//
+ new IndexInfo(ACTIVITY_INSTANCE_IDX9, false, new FieldInfo[] {
+ CRITICALITY,
+ PROCESS_INSTANCE }) };
+ }
- }, this);
+ }, runtimeJob);
- try
- {
- setColumnDefaultValue(item, ACTIVITY_INSTANCE_TABLE_NAME,
- ACTIVITY_INSTANCE_FIELD_CRITICALITY, -1);
- }
- catch (SQLException e)
- {
- reportExeption(e, "Could not update new column " + ACTIVITY_INSTANCE_TABLE_NAME
- + "." + ACTIVITY_INSTANCE_FIELD_CRITICALITY + " to -1.");
- }
+ try
+ {
+ setColumnDefaultValue(item, ACTIVITY_INSTANCE_TABLE_NAME,
+ ACTIVITY_INSTANCE_FIELD_CRITICALITY, -1);
+ }
+ catch (SQLException e)
+ {
+ reportExeption(e, "Could not update new column " + ACTIVITY_INSTANCE_TABLE_NAME
+ + "." + ACTIVITY_INSTANCE_FIELD_CRITICALITY + " to -1.");
+ }
- try
- {
- setColumnDefaultValue(item, ACTIVITY_INSTANCE_TABLE_NAME,
- ACTIVITY_INSTANCE_FIELD_PROPERTIES, 0);
- }
- catch (SQLException e)
+ try
+ {
+ setColumnDefaultValue(item, ACTIVITY_INSTANCE_TABLE_NAME,
+ ACTIVITY_INSTANCE_FIELD_PROPERTIES, 0);
+ }
+ catch (SQLException e)
+ {
+ reportExeption(e, "Could not update new column " + ACTIVITY_INSTANCE_TABLE_NAME
+ + "." + ACTIVITY_INSTANCE_FIELD_PROPERTIES + " to 0.");
+ }
+ }
+ });
+
+ upgradeTaskExecutor.addUpgradeSchemaTask(new UpgradeTask()
{
- reportExeption(e, "Could not update new column " + ACTIVITY_INSTANCE_TABLE_NAME
- + "." + ACTIVITY_INSTANCE_FIELD_PROPERTIES + " to 0.");
- }
+ @Override
+ public void execute()
+ {
+ // Alter WorkItem Table
+ DatabaseHelper.alterTable(item, new AlterTableInfo(WORK_ITEM_TABLE_NAME)
+ {
+ private final FieldInfo CRITICALITY = new FieldInfo(WORK_ITEM_FIELD_CRITICALITY,
+ Double.TYPE);
- // Alter WorkItem Table
- DatabaseHelper.alterTable(item, new AlterTableInfo(WORK_ITEM_TABLE_NAME)
- {
- private final FieldInfo CRITICALITY = new FieldInfo(WORK_ITEM_FIELD_CRITICALITY,
- Double.TYPE);
+ @Override
+ public FieldInfo[] getAddedFields()
+ {
+ return new FieldInfo[] {CRITICALITY};
+ }
+
+ }, runtimeJob);
+ try
+ {
+ setColumnDefaultValue(item, WORK_ITEM_TABLE_NAME, WORK_ITEM_FIELD_CRITICALITY,
+ -1);
+ }
+ catch (SQLException e)
+ {
+ reportExeption(e, "Could not update new column " + WORK_ITEM_TABLE_NAME + "."
+ + WORK_ITEM_FIELD_CRITICALITY + " to -1.");
+ }
+ }
+ });
+
+ upgradeTaskExecutor.addUpgradeSchemaTask(new UpgradeTask()
+ {
@Override
- public FieldInfo[] getAddedFields()
+ public void execute()
{
- return new FieldInfo[] {CRITICALITY};
- }
+ // Create ProcessInstanceLink Table
+ DatabaseHelper.createTable(item, new CreateTableInfo(
+ PROCESS_INSTANCE_LINK_TABLE_NAME)
+ {
+ private final FieldInfo processInstance = new FieldInfo(
+ PROCESS_INSTANCE_LINK_FIELD_PROCESS_INSTANCE, Long.TYPE, 0, true);
- }, this);
+ private final FieldInfo linkedProcessInstance = new FieldInfo(
+ PROCESS_INSTANCE_LINK_FIELD_LINKED_PROCESS_INSTANCE, Long.TYPE, 0, true);
- try
- {
- setColumnDefaultValue(item, WORK_ITEM_TABLE_NAME, WORK_ITEM_FIELD_CRITICALITY,
- -1);
- }
- catch (SQLException e)
- {
- reportExeption(e, "Could not update new column " + WORK_ITEM_TABLE_NAME + "."
- + WORK_ITEM_FIELD_CRITICALITY + " to -1.");
- }
+ private final FieldInfo linkType = new FieldInfo(
+ PROCESS_INSTANCE_LINK_FIELD_LINK_TYPE, Long.TYPE, 0, true);
- // Create ProcessInstanceLink Table
- DatabaseHelper.createTable(item, new CreateTableInfo(
- PROCESS_INSTANCE_LINK_TABLE_NAME)
- {
- private final FieldInfo processInstance = new FieldInfo(
- PROCESS_INSTANCE_LINK_FIELD_PROCESS_INSTANCE, Long.TYPE, 0, true);
+ private final FieldInfo createTime = new FieldInfo(
+ PROCESS_INSTANCE_LINK_FIELD_CREATE_TIME, Long.TYPE, 0, false);
- private final FieldInfo linkedProcessInstance = new FieldInfo(
- PROCESS_INSTANCE_LINK_FIELD_LINKED_PROCESS_INSTANCE, Long.TYPE, 0, true);
+ private final FieldInfo creatingUser = new FieldInfo(
+ PROCESS_INSTANCE_LINK_FIELD_CREATING_USER, Long.TYPE, 0, false);
- private final FieldInfo linkType = new FieldInfo(
- PROCESS_INSTANCE_LINK_FIELD_LINK_TYPE, Long.TYPE, 0, true);
+ private final FieldInfo linkingComment = new FieldInfo(
+ PROCESS_INSTANCE_LINK_FIELD_LINKING_COMMENT, String.class, 255, false);
- private final FieldInfo createTime = new FieldInfo(
- PROCESS_INSTANCE_LINK_FIELD_CREATE_TIME, Long.TYPE, 0, false);
+ @Override
+ public FieldInfo[] getFields()
+ {
+ return new FieldInfo[] {
+ processInstance, linkedProcessInstance, linkType, createTime,
+ creatingUser, linkingComment};
+ }
- private final FieldInfo creatingUser = new FieldInfo(
- PROCESS_INSTANCE_LINK_FIELD_CREATING_USER, Long.TYPE, 0, false);
+ @Override
+ public IndexInfo[] getIndexes()
+ {
+ return null;
+ }
- private final FieldInfo linkingComment = new FieldInfo(
- PROCESS_INSTANCE_LINK_FIELD_LINKING_COMMENT, String.class, 255, false);
+ @Override
+ public String getSequenceName()
+ {
+ return null;
+ }
- @Override
- public FieldInfo[] getFields()
- {
- return new FieldInfo[] {
- processInstance, linkedProcessInstance, linkType, createTime,
- creatingUser, linkingComment};
+ }, runtimeJob);
}
-
+ });
+
+ upgradeTaskExecutor.addUpgradeSchemaTask(new UpgradeTask()
+ {
@Override
- public IndexInfo[] getIndexes()
+ public void execute()
{
- return null;
- }
+ // Create ProcessInstanceLinkType Table
+ DatabaseHelper.createTable(item, new CreateTableInfo(
+ PROCESS_INSTANCE_LINK_TYPE_TABLE_NAME)
+ {
+ private final FieldInfo oid = new FieldInfo(
+ PROCESS_INSTANCE_LINK_TYPE_FIELD_OID, Long.TYPE, 0, true);
- @Override
- public String getSequenceName()
- {
- return null;
- }
+ private final FieldInfo id = new FieldInfo(PROCESS_INSTANCE_LINK_TYPE_FIELD_ID,
+ String.class, 50, false);
- }, this);
+ private final FieldInfo description = new FieldInfo(
+ PROCESS_INSTANCE_LINK_TYPE_FIELD_DESCRIPTION, String.class, 255, false);
- // Create ProcessInstanceLinkType Table
- DatabaseHelper.createTable(item, new CreateTableInfo(
- PROCESS_INSTANCE_LINK_TYPE_TABLE_NAME)
- {
- private final FieldInfo oid = new FieldInfo(
- PROCESS_INSTANCE_LINK_TYPE_FIELD_OID, Long.TYPE, 0, true);
+ private final FieldInfo partition = new FieldInfo(
+ PROCESS_INSTANCE_LINK_TYPE_FIELD_PARTITION, Long.TYPE, 0, false);
- private final FieldInfo id = new FieldInfo(PROCESS_INSTANCE_LINK_TYPE_FIELD_ID,
- String.class, 50, false);
+ private final IndexInfo IDX1 = new IndexInfo(PROCESS_INSTANCE_LINK_TYPE_IDX1,
+ true, new FieldInfo[] {oid});
- private final FieldInfo description = new FieldInfo(
- PROCESS_INSTANCE_LINK_TYPE_FIELD_DESCRIPTION, String.class, 255, false);
+ @Override
+ public FieldInfo[] getFields()
+ {
+ return new FieldInfo[] {oid, id, description, partition};
+ }
- private final FieldInfo partition = new FieldInfo(
- PROCESS_INSTANCE_LINK_TYPE_FIELD_PARTITION, Long.TYPE, 0, false);
+ @Override
+ public IndexInfo[] getIndexes()
+ {
+ return new IndexInfo[] {IDX1};
+ }
- private final IndexInfo IDX1 = new IndexInfo(PROCESS_INSTANCE_LINK_TYPE_IDX1,
- true, new FieldInfo[] {oid});
+ @Override
+ public String getSequenceName()
+ {
+ return PROCESS_INSTANCE_LINK_TYPE_PK_SEQUENCE;
+ }
- @Override
- public FieldInfo[] getFields()
- {
- return new FieldInfo[] {oid, id, description, partition};
+ }, runtimeJob);
}
-
+ });
+
+ upgradeTaskExecutor.addUpgradeSchemaTask(new UpgradeTask()
+ {
@Override
- public IndexInfo[] getIndexes()
+ public void execute()
{
- return new IndexInfo[] {IDX1};
+ // update datacluster setup key
+ StringBuffer dataClusterUpdateStatement = new StringBuffer();
+ dataClusterUpdateStatement.append("UPDATE property");
+ dataClusterUpdateStatement.append(" SET name=");
+ dataClusterUpdateStatement.append("'");
+ dataClusterUpdateStatement
+ .append("org.eclipse.stardust.engine.core.runtime.setup_definition");
+ dataClusterUpdateStatement.append("'");
+ dataClusterUpdateStatement.append(" where name=");
+ dataClusterUpdateStatement.append("'");
+ dataClusterUpdateStatement.append("ag.carnot.workflow.runtime.setup_definition");
+ dataClusterUpdateStatement.append("'");
+
+ try
+ {
+ DatabaseHelper.executeUpdate(item, dataClusterUpdateStatement.toString());
+ }
+ catch (SQLException e)
+ {
+ reportExeption(e, "could not update data cluster setup");
+ }
}
-
+ });
+
+ upgradeTaskExecutor.addUpgradeSchemaTask(new UpgradeTask()
+ {
@Override
- public String getSequenceName()
+ public void execute()
{
- return PROCESS_INSTANCE_LINK_TYPE_PK_SEQUENCE;
- }
+ // Lock table will only be created if any other lock table already exists, e.g. the one for AIBean
+ if (!item.isArchiveAuditTrail() && containsTable(AI_LCK_TABLE_NAME))
+ {
+ DatabaseHelper.createTable(item, new CreateTableInfo(P_LCK_TABLE_NAME)
+ {
+ private static final String INDEX_NAME = "partition_lck_idx";
- }, this);
-
- // update datacluster setup key
- StringBuffer dataClusterUpdateStatement = new StringBuffer();
- dataClusterUpdateStatement.append("UPDATE property");
- dataClusterUpdateStatement.append(" SET name=");
- dataClusterUpdateStatement.append("'");
- dataClusterUpdateStatement
- .append("org.eclipse.stardust.engine.core.runtime.setup_definition");
- dataClusterUpdateStatement.append("'");
- dataClusterUpdateStatement.append(" where name=");
- dataClusterUpdateStatement.append("'");
- dataClusterUpdateStatement.append("ag.carnot.workflow.runtime.setup_definition");
- dataClusterUpdateStatement.append("'");
+ private final FieldInfo OID = new FieldInfo(P_LCK_FIELD__OID, Long.TYPE, 0, true);
- try
- {
- DatabaseHelper.executeUpdate(item, dataClusterUpdateStatement.toString());
- }
- catch (SQLException e)
- {
- reportExeption(e, "could not update data cluster setup");
- }
+ private final IndexInfo IDX = new IndexInfo(INDEX_NAME, true,
+ new FieldInfo[] { OID });
+ public FieldInfo[] getFields()
+ {
+ return new FieldInfo[] { OID };
+ }
- // Lock table will only be created if any other lock table already exists, e.g. the one for AIBean
- if (!item.isArchiveAuditTrail() && containsTable(AI_LCK_TABLE_NAME))
+ public IndexInfo[] getIndexes()
+ {
+ return new IndexInfo[] { IDX };
+ }
+
+ public String getSequenceName()
+ {
+ return null;
+ }
+ }, runtimeJob);
+ }
+ }
+ });
+ }
+
+ private void initMigrateDataTasks()
+ {
+ upgradeTaskExecutor.addMigrateDataTask(new UpgradeTask()
{
- DatabaseHelper.createTable(item, new CreateTableInfo(P_LCK_TABLE_NAME)
+ @Override
+ public void execute()
{
- private static final String INDEX_NAME = "partition_lck_idx";
-
- private final FieldInfo OID = new FieldInfo(P_LCK_FIELD__OID, Long.TYPE, 0, true);
-
- private final IndexInfo IDX = new IndexInfo(INDEX_NAME, true,
- new FieldInfo[] { OID });
-
- public FieldInfo[] getFields()
+ try
{
- return new FieldInfo[] { OID };
+ initActivityInstanceProperties();
}
-
- public IndexInfo[] getIndexes()
+ catch (SQLException e)
{
- return new IndexInfo[] { IDX };
+ reportExeption(e,
+ "Failed init activity instance properties (nested exception).");
}
+ }
+ });
+
+ upgradeTaskExecutor.addMigrateDataTask(new UpgradeTask()
+ {
+ @Override
+ public void execute()
+ {
+ try
+ {
+ upgradeDataTypes();
+ }
+ catch (SQLException e)
+ {
+ reportExeption(e,
+ "Failed upgrade data types (nested exception).");
+ }
+ }
+ });
+ }
- public String getSequenceName()
+ private void initFinalizeSchemaTasks()
+ {
+ upgradeTaskExecutor.addFinalizeSchemaTask(new UpgradeTask()
+ {
+ @Override
+ public void execute()
+ {
+ try
{
- return null;
+ insertDefaultLinkTypes();
}
- }, this);
- }
+ catch (SQLException sqle)
+ {
+ reportExeption(sqle,
+ "Failed migrating runtime item tables (nested exception).");
+ }
+ }
+ });
+ }
+
+ protected void upgradeSchema(boolean recover) throws UpgradeException
+ {
+ upgradeTaskExecutor.executeUpgradeSchemaTasks();
}
@Override
@@ -381,15 +498,9 @@ public class R7_0_0from6_x_xRuntimeJob extends DbmsAwareRuntimeUpgradeJob
protected void migrateData(boolean recover) throws UpgradeException
{
- try
- {
- initActivityInstanceProperties();
- upgradeDataTypes();
- ((org.eclipse.stardust.engine.core.persistence.jdbc.Session) SessionFactory.getSession(SessionFactory.AUDIT_TRAIL)).flush();
- }
- catch (SQLException e)
- {
- }
+ upgradeTaskExecutor.executeMigrateDataTasks();
+ ((org.eclipse.stardust.engine.core.persistence.jdbc.Session) SessionFactory
+ .getSession(SessionFactory.AUDIT_TRAIL)).flush();
}
private void upgradeDataTypes() throws SQLException
@@ -686,14 +797,7 @@ public class R7_0_0from6_x_xRuntimeJob extends DbmsAwareRuntimeUpgradeJob
protected void finalizeSchema(boolean recover) throws UpgradeException
{
- try
- {
- insertDefaultLinkTypes();
- }
- catch (SQLException sqle)
- {
- reportExeption(sqle, "Failed migrating runtime item tables (nested exception).");
- }
+ upgradeTaskExecutor.executeFinalizeSchemaTasks();
}
private void reportExeption(SQLException sqle, String message)
diff --git a/stardust-engine-core/src/test/java/org/eclipse/stardust/engine/core/upgrade/UpgradeTestSuite.java b/stardust-engine-core/src/test/java/org/eclipse/stardust/engine/core/upgrade/UpgradeTestSuite.java
index 10e830a..4bb4fe4 100644
--- a/stardust-engine-core/src/test/java/org/eclipse/stardust/engine/core/upgrade/UpgradeTestSuite.java
+++ b/stardust-engine-core/src/test/java/org/eclipse/stardust/engine/core/upgrade/UpgradeTestSuite.java
@@ -10,12 +10,13 @@
*******************************************************************************/
package org.eclipse.stardust.engine.core.upgrade;
+import org.eclipse.stardust.engine.core.upgrade.framework.RuntimeUpgradeTaskExecutorTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
-@SuiteClasses({JobListTest.class})
+@SuiteClasses({JobListTest.class, RuntimeUpgradeTaskExecutorTest.class})
public class UpgradeTestSuite
{
diff --git a/stardust-engine-core/src/test/java/org/eclipse/stardust/engine/core/upgrade/framework/RuntimeUpgradeTaskExecutorTest.java b/stardust-engine-core/src/test/java/org/eclipse/stardust/engine/core/upgrade/framework/RuntimeUpgradeTaskExecutorTest.java
new file mode 100644
index 0000000..a566f19
--- /dev/null
+++ b/stardust-engine-core/src/test/java/org/eclipse/stardust/engine/core/upgrade/framework/RuntimeUpgradeTaskExecutorTest.java
@@ -0,0 +1,127 @@
+package org.eclipse.stardust.engine.core.upgrade.framework;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+
+import java.io.PrintStream;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+
+public class RuntimeUpgradeTaskExecutorTest
+{
+ private RuntimeUpgradeTaskExecutor upgradeTaskExecutor;
+
+ @Mock
+ private PrintStream console;
+
+ @Before
+ public void setup()
+ {
+ console = mock(PrintStream.class);
+ }
+
+ @Test
+ public void upgradeTaskProgress()
+ {
+ upgradeTaskExecutor = new RuntimeUpgradeTaskExecutor("R7_0_0from6_x_xRuntimeJob",
+ false, console);
+ for (int i = 0; i < 7; i++)
+ {
+ upgradeTaskExecutor.addUpgradeSchemaTask(createTask());
+ }
+ upgradeTaskExecutor.addMigrateDataTask(createTask());
+ upgradeTaskExecutor.addMigrateDataTask(createTask());
+ upgradeTaskExecutor.addMigrateDataTask(createTask());
+ upgradeTaskExecutor.addMigrateDataTask(createTask());
+ upgradeTaskExecutor.addFinalizeSchemaTask(createTask());
+ upgradeTaskExecutor.addFinalizeSchemaTask(createTask());
+ upgradeTaskExecutor.executeUpgradeSchemaTasks();
+ verify(console).println("Upgrade Job R7_0_0from6_x_xRuntimeJob:");
+ verify(console).println("Upgrading data block: 1 of 13. 0 % completed.");
+ verify(console).println("Upgrading data block: 2 of 13. 7 % completed.");
+ verify(console).println("Upgrading data block: 3 of 13. 15 % completed.");
+ verify(console).println("Upgrading data block: 4 of 13. 23 % completed.");
+ verify(console).println("Upgrading data block: 5 of 13. 30 % completed.");
+ verify(console).println("Upgrading data block: 6 of 13. 38 % completed.");
+ verify(console).println("Upgrading data block: 7 of 13. 46 % completed.");
+ upgradeTaskExecutor.executeMigrateDataTasks();
+ verify(console).println("Upgrading data block: 8 of 13. 53 % completed.");
+ verify(console).println("Upgrading data block: 9 of 13. 61 % completed.");
+ verify(console).println("Upgrading data block: 10 of 13. 69 % completed.");
+ verify(console).println("Upgrading data block: 11 of 13. 76 % completed.");
+ upgradeTaskExecutor.executeFinalizeSchemaTasks();
+ verify(console).println("Upgrading data block: 12 of 13. 84 % completed.");
+ verify(console).println("Upgrading data block: 13 of 13. 92 % completed.");
+ verify(console).println("Upgrade Job R7_0_0from6_x_xRuntimeJob: 100 % completed.");
+ }
+
+ @Test
+ public void upgradeTaskProgressDataOnly()
+ {
+ upgradeTaskExecutor = new RuntimeUpgradeTaskExecutor("R7_0_0from6_x_xRuntimeJob",
+ true, console);
+ for (int i = 0; i < 5; i++)
+ {
+ upgradeTaskExecutor.addUpgradeSchemaTask(createTask());
+ }
+ upgradeTaskExecutor.addMigrateDataTask(createTask());
+ upgradeTaskExecutor.addMigrateDataTask(createTask());
+ upgradeTaskExecutor.addMigrateDataTask(createTask());
+ upgradeTaskExecutor.addFinalizeSchemaTask(createTask());
+ upgradeTaskExecutor.executeMigrateDataTasks();
+ verify(console).println("Upgrade Job R7_0_0from6_x_xRuntimeJob:");
+ verify(console).println("Upgrading data block: 1 of 3. 0 % completed.");
+ verify(console).println("Upgrading data block: 2 of 3. 33 % completed.");
+ verify(console).println("Upgrading data block: 3 of 3. 66 % completed.");
+ verify(console).println("Upgrade Job R7_0_0from6_x_xRuntimeJob: 100 % completed.");
+ }
+
+ @Test
+ public void upgradeTaskProgressSchemaOnly()
+ {
+ upgradeTaskExecutor = new RuntimeUpgradeTaskExecutor("R7_0_0from6_x_xRuntimeJob",
+ false, console);
+ for (int i = 0; i < 6; i++)
+ {
+ upgradeTaskExecutor.addUpgradeSchemaTask(createTask());
+ }
+ upgradeTaskExecutor.executeUpgradeSchemaTasks();
+ verify(console).println("Upgrade Job R7_0_0from6_x_xRuntimeJob:");
+ verify(console).println("Upgrading data block: 1 of 6. 0 % completed.");
+ verify(console).println("Upgrading data block: 2 of 6. 16 % completed.");
+ verify(console).println("Upgrading data block: 3 of 6. 33 % completed.");
+ verify(console).println("Upgrading data block: 4 of 6. 50 % completed.");
+ verify(console).println("Upgrading data block: 5 of 6. 66 % completed.");
+ verify(console).println("Upgrading data block: 6 of 6. 83 % completed.");
+ verify(console).println("Upgrade Job R7_0_0from6_x_xRuntimeJob: 100 % completed.");
+ upgradeTaskExecutor.executeMigrateDataTasks();
+ upgradeTaskExecutor.executeFinalizeSchemaTasks();
+ }
+
+ @Test
+ public void upgradeTaskProgressDataOnlyNoTasks()
+ {
+ upgradeTaskExecutor = new RuntimeUpgradeTaskExecutor("R7_0_0from6_x_xRuntimeJob",
+ true, console);
+ for (int i = 0; i < 5; i++)
+ {
+ upgradeTaskExecutor.addUpgradeSchemaTask(createTask());
+ }
+ upgradeTaskExecutor.executeMigrateDataTasks();
+ verify(console).println("Upgrade Job R7_0_0from6_x_xRuntimeJob:");
+ verify(console).println("No upgrade tasks available.");
+ }
+
+ private UpgradeTask createTask()
+ {
+ return new UpgradeTask()
+ {
+ @Override
+ public void execute()
+ {}
+ };
+ }
+
+}