Navigation Menu

Skip to content

Commit

Permalink
Issue #23: Fixing some checkstyle issues to all base classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ulises Pulido authored and Ulises Pulido committed Nov 10, 2011
1 parent 40777d4 commit 92e08c0
Show file tree
Hide file tree
Showing 53 changed files with 1,995 additions and 1,750 deletions.
Expand Up @@ -15,45 +15,48 @@

package com.tacitknowledge.util.migration;

import java.util.ArrayList;
import java.util.List;

import com.tacitknowledge.util.discovery.ClassDiscoveryUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.tacitknowledge.util.discovery.ClassDiscoveryUtil;
import java.util.ArrayList;
import java.util.List;

/**
* Returns a list of all public, concrete classes that implement the
* <code>MigrationTask</code> in a specific package.
*
* @author Scott Askew (scott@tacitknowledge.com)
* @author Scott Askew (scott@tacitknowledge.com)
*/
public class ClassMigrationTaskSource implements MigrationTaskSource
{
/** Class logger */
/**
* Class logger
*/
private static Log log = LogFactory.getLog(ClassMigrationTaskSource.class);

/** {@inheritDoc} */

/**
* {@inheritDoc}
*/
public List<MigrationTask> getMigrationTasks(String packageName) throws MigrationException
{
if (packageName == null)
{
throw new MigrationException("You must specify a package to get tasks for");
}

Class[] taskClasses = ClassDiscoveryUtil.getClasses(packageName, MigrationTask.class);
log.debug("Found " + taskClasses.length + " patches in " + packageName);
return instantiateTasks(taskClasses);
}

/**
* Instantiates the given classes
*
* @param taskClasses the classes instantiate
*
* @param taskClasses the classes instantiate
* @return a list of <code>MigrationTasks</code>
* @throws MigrationException if a class could not be instantiated; this
* is most likely due to the abscense of a default constructor
* is most likely due to the abscense of a default constructor
*/
private List<MigrationTask> instantiateTasks(Class[] taskClasses) throws MigrationException
{
Expand All @@ -64,23 +67,23 @@ private List<MigrationTask> instantiateTasks(Class[] taskClasses) throws Migrati
try
{
Object o = taskClass.newInstance();

// It's not legal to have a null name.
MigrationTask task = (MigrationTask) o;
if (task.getName() != null)
if (task.getName() != null)
{
tasks.add(task);
}
else
{
log.warn("MigrationTask " + taskClass.getName()
+ " had no migration name. Is that intentional? Skipping task.");
log.warn("MigrationTask " + taskClass.getName()
+ " had no migration name. Is that intentional? Skipping task.");
}
}
catch (Exception e)
{
throw new MigrationException("Could not instantiate MigrationTask "
+ taskClass.getName(), e);
+ taskClass.getName(), e);
}
}
return tasks;
Expand Down
Expand Up @@ -15,25 +15,18 @@

package com.tacitknowledge.util.migration;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map.Entry;

import org.apache.commons.collections.CollectionUtils;
import com.tacitknowledge.util.migration.jdbc.JdbcMigrationContext;
import com.tacitknowledge.util.migration.jdbc.JdbcMigrationLauncher;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.tacitknowledge.util.migration.jdbc.JdbcMigrationContext;
import com.tacitknowledge.util.migration.jdbc.JdbcMigrationLauncher;
import java.util.*;
import java.util.Map.Entry;

/**
* Discovers and executes a sequence of system patches from multiple controlled
* systems, each of which has its own MigrationProcess.
*
*
* @author Mike Hardy (mike@tacitknowledge.com)
* @author Artie Pesh-Imam (apeshimam@tacitknowledge.com)
* @author Hemri Herrera (hemri@tacitknowledge.com)
Expand All @@ -42,10 +35,14 @@
*/
public class DistributedMigrationProcess extends MigrationProcess
{
/** Class logger */
/**
* Class logger
*/
private static Log log = LogFactory.getLog(DistributedMigrationProcess.class);

/** The JdbcMigrationLaunchers we are controlling, keyed by system name */
/**
* The JdbcMigrationLaunchers we are controlling, keyed by system name
*/
private HashMap controlledSystems = new HashMap();

/**
Expand All @@ -54,27 +51,26 @@ public class DistributedMigrationProcess extends MigrationProcess
* nodes. This is not enabled by default because in a distributed system, if
* there are cross schema dependencies, then the patching of the node may
* fail since it is being patched 'out of order'.
*
* <p/>
* For example:
*
* <p/>
* system 1 has one node system 2 has one node
*
* <p/>
* patch1 applies to system1 and creates a table patch2 applies to system2
* and creates a table that references the table in system1 patch3 applies
* to system2, dropping the reference to the table in system1 patch4 applies
* to system1, dropping the table.
*
* <p/>
* Later, to add capacity, system2 has a node added. When the second node is
* forcibly 'synced' patches 2 and 3 are applied to it. The patching fails
* when patch2 is applied because the table no longer exists in system1.
*
* <p/>
* Therefore, forcing a sync is usually safe for systems that don't contain
* external references, but should not be used for interdependent systems.
*
* <p/>
* Instead, it would be better to import the schema from a node already at
* the current patch level using database tools, then the new node can
* participate in the regular patching process.
*
*/
private boolean forceSync = false;

Expand All @@ -89,12 +85,13 @@ public DistributedMigrationProcess()
/**
* Execute a dry run of the rollback process and return a count of the
* number of tasks which will rollback.
*
* @param rollbacks a <code>List</code> of RollbackableMigrationTasks
*
* @param rollbacks a <code>List</code> of RollbackableMigrationTasks
* @param rollbacksWithLaunchers a <code>LinkedHashMap</code> of task to launcher
* @return count of the number of rollbacks
*/
protected final int rollbackDryRun(final List rollbacks, final LinkedHashMap rollbacksWithLaunchers)
protected final int rollbackDryRun(final List rollbacks,
final LinkedHashMap rollbacksWithLaunchers)
{
// take the list of rollbacks
// iterate through the rollbacks
Expand Down Expand Up @@ -128,12 +125,14 @@ protected final int rollbackDryRun(final List rollbacks, final LinkedHashMap rol
/**
* Execute a dry run of the patch process and return a count of the number
* of patches we would have executed.
*
* @param currentPatchInfoStore The current patch info store
*
* @param currentPatchInfoStore The current patch info store
* @param migrationsWithLaunchers a map of migration task to launcher
* @return count of the number of patches
*/
protected final int patchDryRun(final PatchInfoStore currentPatchInfoStore, final LinkedHashMap migrationsWithLaunchers) throws MigrationException {
protected final int patchDryRun(final PatchInfoStore currentPatchInfoStore,
final LinkedHashMap migrationsWithLaunchers) throws MigrationException
{
int taskCount = 0;

for (Iterator i = migrationsWithLaunchers.entrySet().iterator(); i.hasNext();)
Expand All @@ -143,7 +142,7 @@ protected final int patchDryRun(final PatchInfoStore currentPatchInfoStore, fina
JdbcMigrationLauncher launcher = (JdbcMigrationLauncher) entry.getValue();


if (getMigrationRunnerStrategy().shouldMigrationRun(task.getLevel(),currentPatchInfoStore))
if (getMigrationRunnerStrategy().shouldMigrationRun(task.getLevel(), currentPatchInfoStore))
{
log.info("Will execute patch task '" + getTaskLabel(task) + "'");
if (log.isDebugEnabled())
Expand All @@ -165,13 +164,12 @@ protected final int patchDryRun(final PatchInfoStore currentPatchInfoStore, fina

/**
* Applies the necessary rollbacks to the system.
*
*
* @param currentPatchInfoStore
* @param rollbackLevels the level that the system should rollback to
* @param context information and resources that are available to the migration tasks
* @throws MigrationException if a rollback fails
* @param rollbackLevels the level that the system should rollback to
* @param context information and resources that are available to the migration tasks
* @return the number of <code>RollbackableMigrationTasks</code> which have been rolled back
* @throws MigrationException if a rollback fails
* @Override
*/
public final int doRollbacks(final PatchInfoStore currentPatchInfoStore, final int[] rollbackLevels, final MigrationContext context,
Expand Down Expand Up @@ -245,15 +243,15 @@ public final int doRollbacks(final PatchInfoStore currentPatchInfoStore, final i

/**
* Applies necessary patches to the system.
*
*
* @param patchInfoStore of the system to run
* @param context information and resources that are available to the migration tasks
* @throws MigrationException if a migration fails
* @param context information and resources that are available to the migration tasks
* @return the number of <code>MigrationTask</code>s that have executed
* @throws MigrationException if a migration fails
* @Override
*/
public final int doMigrations(final PatchInfoStore patchInfoStore,
final MigrationContext context) throws MigrationException
final MigrationContext context) throws MigrationException
{
log.debug("Starting doMigrations");
// Get all the migrations, with their launchers, then get the list of
Expand Down Expand Up @@ -334,9 +332,9 @@ else if (forceSync)// if a sync is forced, need to check all
MigrationContext launcherContext = (MigrationContext) j.next();
PatchInfoStore patchInfoStoreOfContext =
(PatchInfoStore) launcher.getContexts().get(
launcherContext);
launcherContext);

if ( !getMigrationRunnerStrategy().isSynchronized(patchInfoStore, patchInfoStoreOfContext) )
if (!getMigrationRunnerStrategy().isSynchronized(patchInfoStore, patchInfoStoreOfContext))
{
outOfSyncContexts.add(launcherContext);
}
Expand Down Expand Up @@ -372,9 +370,9 @@ else if (forceSync)// if a sync is forced, need to check all

/**
* Validates that the controlled systems are all at the current patch level.
*
* @throws MigrationException if all the controlled systems are not at the current patch level.
*
* @param currentPatchInfoStore
* @throws MigrationException if all the controlled systems are not at the current patch level.
*/
protected final void validateControlledSystems(final PatchInfoStore currentPatchInfoStore) throws MigrationException
{
Expand Down Expand Up @@ -411,7 +409,7 @@ protected final void validateControlledSystems(final PatchInfoStore currentPatch
/**
* Returns a LinkedHashMap of task/launcher pairings, regardless of patch
* level.
*
*
* @return LinkedHashMap containing MigrationTask / JdbcMigrationLauncher
* pairings
* @throws MigrationException if one or more migration tasks could not be created
Expand Down Expand Up @@ -453,7 +451,7 @@ public final LinkedHashMap getMigrationTasksWithLaunchers() throws MigrationExce

/**
* Returns a List of MigrationTasks, regardless of patch level.
*
*
* @return List containing MigrationTask objects
* @throws MigrationException if one or more migration tasks could not be created
*/
Expand Down Expand Up @@ -493,7 +491,7 @@ public final List getMigrationTasks() throws MigrationException

/**
* Get the list of systems we are controlling
*
*
* @return HashMap of JdbcMigrationLauncher objects keyed by String system
* names
*/
Expand All @@ -504,7 +502,7 @@ public final HashMap getControlledSystems()

/**
* Set the list of systems to control
*
*
* @param controlledSystems HashMap of system name / JdbcMigrationLauncher pairs
*/
public final void setControlledSystems(final HashMap controlledSystems)
Expand Down

0 comments on commit 92e08c0

Please sign in to comment.