Skip to content

Commit

Permalink
Merge pull request #202 from paterczm/utils-refactor
Browse files Browse the repository at this point in the history
Refactored utils module into facade and bean-consistency-checker modules
  • Loading branch information
bserdar committed Jun 4, 2015
2 parents 72868b3 + a63e8a4 commit 3ec16b3
Show file tree
Hide file tree
Showing 28 changed files with 221 additions and 85 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,12 @@ java -jar consistency-checker-1.0.0-alldeps.jar
--destinationconfig=destination-lightblue-client.properties
```

###[utils](utils)
###[facade](facade)
Provides some aid with migration to Lightblue.

###[entity-consistency-checker](entity-consistency-checker)
A utility to compare POJOs field by field. Use it during migration to lightblue to ensure consistency between entities returned by legacy and lightblue DAOs.

# License

The license of lightblue is [GPLv3](https://www.gnu.org/licenses/gpl.html). See LICENSE in root of project for the full text.
3 changes: 3 additions & 0 deletions bean-consistency-checker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Lightblue-entity-consistency-checker

A utility to compare POJOs field by field. Use it during migration to lightblue to ensure consistency between entities returned by legacy and lightblue DAOs.
63 changes: 63 additions & 0 deletions bean-consistency-checker/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.redhat.lightblue.migrator</groupId>
<artifactId>lightblue-migrator-pom</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>lightblue-bean-consistency-checker</artifactId>
<packaging>jar</packaging>
<name>lightblue-migrator: ${project.groupId}|${project.artifactId}</name>
<dependencies>
<dependency>
<groupId>org.jboss.spec</groupId>
<artifactId>jboss-javaee-6.0</artifactId>
<type>pom</type>
</dependency>
<dependency>
<groupId>com.redhat.lightblue.migrator</groupId>
<artifactId>lightblue-migrator-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>


</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redhat.lightblue.migrator.utils.consistency;
package com.redhat.lightblue.migrator.consistency;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redhat.lightblue.migrator.utils.consistency;
package com.redhat.lightblue.migrator.consistency;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package com.redhat.lightblue.migrator.utils.consistency;
package com.redhat.lightblue.migrator.consistency;

import java.util.Arrays;

import org.junit.Assert;
import org.junit.Test;

import com.redhat.lightblue.migrator.utils.Country;

public class BeanConsistencyCheckerTest {

BeanConsistencyChecker beanConsistencyChecker = new BeanConsistencyChecker();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package com.redhat.lightblue.migrator.utils;
package com.redhat.lightblue.migrator.consistency;

import java.util.Objects;

import com.redhat.lightblue.migrator.utils.consistency.BeanConsistencyChecker;
import com.redhat.lightblue.migrator.utils.consistency.ConsistencyCheck;

public class Country {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.redhat.lightblue.migrator.utils.consistency;
package com.redhat.lightblue.migrator.consistency;

import com.redhat.lightblue.migrator.utils.Country;

public class CountryInCountry extends Country {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.redhat.lightblue.migrator.utils.consistency;
package com.redhat.lightblue.migrator.consistency;

import com.redhat.lightblue.migrator.utils.Country;

public class ExtendedCountry extends Country {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redhat.lightblue.migrator.utils.consistency;
package com.redhat.lightblue.migrator.consistency;

public class VeryExtendedCountry extends ExtendedCountry {

Expand Down
File renamed without changes.
45 changes: 45 additions & 0 deletions facade/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Lightblue-migrator-facade

The facade helps with migrating a service to lightblue by offering following features:
* phased migration using feature flag support (Togglz - see LightblueMigrationFeatures),
* parallel processing (when possible),
* handling identifiers and
* checking for data integrity across source and destination (Lightblue) entities.

The facade stands in front of the source and destination DAOs, directing traffic as needed. 4 different operations are supported:

### get

Read from source and destination (Lightblue) DAOs in parallel.

Compare returned entities. If differences are found, return source entity and log inconsistency. Otherwise, return destination entity.

Will call lightblue in dual read phase and beyond.

### update

Update entity using source and destination (Lightblue) DAOs in parallel. An update operation requires entity ID to be present.

Compare returned entities. If differences are found, return source entity and log inconsistency. Otherwise, return destination entity.

Will call lightblue in dual write phase and beyond.

### create

Create new entity using source and destination (Lightblue) DAOs in serial. First create in source to obtain ID. Once ID is assigned by source datastore, use it to create entity in destination. The destination (Lightblue) DAO needs to use EntityIdStore to get the ID and have a setter for DAOFacadeBase to set it.

Compare returned entities. If differences are found, return source entity and log inconsistency. Otherwise, return destination entity.

Will call lightblue in dual write phase and beyond.

### create with read

Same as create, except it will call lightblue in dual read phase and beyond.

## Notes

The facade was designed to work with DAO objects (data access layer), but it can be also used in front of a service bean (business logic layer). In case of the latter, you may need to duplicate business logic when preparing service bean implementation for lightblue. Logic duplication is generally undesired, but re-implementing business logic for lightblue may improve performance (you will have opportunities to merge multiple data operations, reducing the number of remote calls).

## Examples

See unit tests.
17 changes: 9 additions & 8 deletions utils/pom.xml → facade/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>lightblue-migrator-pom</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>lightblue-migrator-utils</artifactId>
<artifactId>lightblue-migrator-facade</artifactId>
<packaging>jar</packaging>
<name>lightblue-migrator: ${project.groupId}|${project.artifactId}</name>
<dependencies>
Expand All @@ -20,26 +20,27 @@
<artifactId>lightblue-migrator-core</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.redhat.lightblue.migrator</groupId>
<artifactId>lightblue-bean-consistency-checker</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>org.togglz</groupId>
<artifactId>togglz-core</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
</dependency>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redhat.lightblue.migrator.utils;
package com.redhat.lightblue.migrator.facade;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redhat.lightblue.migrator.utils;
package com.redhat.lightblue.migrator.facade;

/**
* Extract ID of any entity. Define anonymous class inside facade implementation for your particular DAO and entity.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redhat.lightblue.migrator.utils;
package com.redhat.lightblue.migrator.facade;

/**
* A FIFO queue. Used to pass IDs to create apis in Lightblue DAO without changing the signatures.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redhat.lightblue.migrator.utils;
package com.redhat.lightblue.migrator.facade;

import java.util.LinkedList;
import java.util.NoSuchElementException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redhat.lightblue.migrator.utils;
package com.redhat.lightblue.migrator.facade;

import java.util.Date;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package com.redhat.lightblue.migrator.facade;

import com.redhat.lightblue.migrator.consistency.BeanConsistencyChecker;
import com.redhat.lightblue.migrator.consistency.ConsistencyCheck;


public class Country {

@ConsistencyCheck(ignore=true)
private String name;
private String iso2Code, iso3Code;
private Long id;

public long getId() {
return id;
}

public Country(String iso2Code) {
this(null, iso2Code);
}

public Country(Long id, String iso2Code) {
super();
this.id = id;
this.iso2Code = iso2Code;
}

public Country() {

}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getIso2Code() {
return iso2Code;
}

public void setIso2Code(String iso2code) {
this.iso2Code = iso2code;
}

public String getIso3Code() {
return iso3Code;
}

public void setIso3Code(String iso3code) {
this.iso3Code = iso3code;
}

@Override
public boolean equals(Object obj) {
return BeanConsistencyChecker.getInstance().consistent(this, obj);
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redhat.lightblue.migrator.utils;
package com.redhat.lightblue.migrator.facade;

public interface CountryDAO {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package com.redhat.lightblue.migrator.utils;
package com.redhat.lightblue.migrator.facade;

import com.redhat.lightblue.migrator.facade.EntityIdStore;

public interface CountryDAOLightblue extends CountryDAO {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
package com.redhat.lightblue.migrator.utils;
package com.redhat.lightblue.migrator.facade;

import com.redhat.lightblue.migrator.facade.DAOFacadeBase;
import com.redhat.lightblue.migrator.facade.EntityIdExtractor;



Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redhat.lightblue.migrator.utils;
package com.redhat.lightblue.migrator.facade;

import org.junit.After;
import org.junit.Assert;
Expand All @@ -11,6 +11,7 @@
import org.mockito.runners.MockitoJUnitRunner;
import org.togglz.junit.TogglzRule;

import com.redhat.lightblue.migrator.facade.DAOFacadeBase;
import com.redhat.lightblue.migrator.features.LightblueMigrationFeatures;
import com.redhat.lightblue.migrator.test.LightblueMigrationPhase;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.redhat.lightblue.migrator.utils;
package com.redhat.lightblue.migrator.facade;

import net.sf.ehcache.CacheManager;

import org.junit.After;
import org.junit.Assert;
import org.junit.Test;

import com.redhat.lightblue.migrator.facade.EntityIdStoreImpl;

public class EntityIdStoreImplTest {

@Test
Expand Down
8 changes: 8 additions & 0 deletions facade/src/test/resources/log4j.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
log4j.rootLogger=info, A1

log4j.appender.A1=org.apache.log4j.ConsoleAppender

log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

log4j.logger.com.redhat=DEBUG
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
<module>core</module>
<module>web</module>
<!--module>migrator</module-->
<module>utils</module>
<module>facade</module>
<module>bean-consistency-checker</module>
<module>test</module>
</modules>
<properties>
Expand Down
Loading

0 comments on commit 3ec16b3

Please sign in to comment.