summaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/src/conf/ConfigDestBean.java81
-rw-r--r--src/main/src/conf/ConfigGlobalsBean.java2
-rw-r--r--src/main/src/conf/ConfigSourceBean.java (renamed from src/main/src/conf/ConfigSrcOrDestBean.java)13
-rw-r--r--src/main/src/conf/ConfigTaskBean.java16
-rw-r--r--src/main/src/conf/SSSyncConnectionsFactory.java61
-rw-r--r--src/main/src/sync/SSSyncTasksFactory.java (renamed from src/main/src/conf/SSSyncTasksFactory.java)87
6 files changed, 156 insertions, 104 deletions
diff --git a/src/main/src/conf/ConfigDestBean.java b/src/main/src/conf/ConfigDestBean.java
new file mode 100644
index 0000000..2d9b2f7
--- /dev/null
+++ b/src/main/src/conf/ConfigDestBean.java
@@ -0,0 +1,81 @@
+/*
+ * SSSync, a Simple and Stupid Synchronizer for data with multi-valued attributes
+ * Copyright (C) 2014 Ludovic Pouzenc <ludovic@pouzenc.fr>
+ *
+ * This file is part of SSSync.
+ *
+ * SSSync is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * SSSync is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with SSSync. If not, see <http://www.gnu.org/licenses/>
+ */
+
+package conf;
+
+/**
+ * Generated Configuration Bean
+ */
+public class ConfigDestBean {
+ public enum DestinationKind { ldap };
+
+ private String name;
+ private DestinationKind kind;
+ private String conn;
+ private String attr;
+ private String base;
+ private int lookahead = 128; /* Only for ldap kind, query lookahead entries at once */
+
+ public String getName() {
+ return name;
+ }
+ public void setName(String name) {
+ this.name = name;
+ }
+ public DestinationKind getKind() {
+ return kind;
+ }
+ public void setKind(DestinationKind kind) {
+ this.kind = kind;
+ }
+ public String getConn() {
+ return conn;
+ }
+ public void setConn(String conn) {
+ this.conn = conn;
+ }
+ public String getAttr() {
+ return attr;
+ }
+ public void setAttr(String attr) {
+ this.attr = attr;
+ }
+ public String getBase() {
+ return base;
+ }
+ public void setBase(String base) {
+ this.base = base;
+ }
+ public int getLookahead() {
+ return lookahead;
+ }
+ public void setLookahead(int lookahead) {
+ this.lookahead = lookahead;
+ }
+
+ @Override
+ public String toString() {
+ return "ConfigDestBean [name=" + name + ", kind=" + kind + ", conn="
+ + conn + ", attr=" + attr + ", base=" + base + ", lookahead="
+ + lookahead + "]";
+ }
+
+
+}
diff --git a/src/main/src/conf/ConfigGlobalsBean.java b/src/main/src/conf/ConfigGlobalsBean.java
index 256acee..20243f3 100644
--- a/src/main/src/conf/ConfigGlobalsBean.java
+++ b/src/main/src/conf/ConfigGlobalsBean.java
@@ -24,7 +24,7 @@ package conf;
* Generated Configuration Bean
*/
public class ConfigGlobalsBean {
- private int maxExecTime;
+ private int maxExecTime = 5;
public int getMaxExecTime() {
return maxExecTime;
diff --git a/src/main/src/conf/ConfigSrcOrDestBean.java b/src/main/src/conf/ConfigSourceBean.java
index 5be1674..cf01dce 100644
--- a/src/main/src/conf/ConfigSrcOrDestBean.java
+++ b/src/main/src/conf/ConfigSourceBean.java
@@ -25,8 +25,9 @@ import data.filters.MVDataCombiner;
/**
* Generated Configuration Bean
*/
-public class ConfigSrcOrDestBean {
+public class ConfigSourceBean {
+ //TODO : fixed_csv ?
public enum SourceKind { csv, ldap, sorted_csv, sql };
private String name;
@@ -37,6 +38,7 @@ public class ConfigSrcOrDestBean {
private String path;
private String attr;
private String base;
+ private int lookahead = 128; /* Only for ldap kind, query lookahead entries at once */
public String getName() {
return name;
@@ -86,11 +88,18 @@ public class ConfigSrcOrDestBean {
public void setBase(String base) {
this.base = base;
}
+ public int getLookahead() {
+ return lookahead;
+ }
+ public void setLookahead(int lookahead) {
+ this.lookahead = lookahead;
+ }
@Override
public String toString() {
return "ConfigSrcOrDestBean [name=" + name + ", kind=" + kind
+ ", conn=" + conn + ", mode=" + mode + ", query=" + query
- + ", path=" + path + ", attr=" + attr + ", base=" + base + "]";
+ + ", path=" + path + ", attr=" + attr + ", base=" + base + ", lookahead="
+ + lookahead + "]";
}
}
diff --git a/src/main/src/conf/ConfigTaskBean.java b/src/main/src/conf/ConfigTaskBean.java
index ed34eee..11089d6 100644
--- a/src/main/src/conf/ConfigTaskBean.java
+++ b/src/main/src/conf/ConfigTaskBean.java
@@ -29,10 +29,10 @@ public class ConfigTaskBean {
private String name;
private ConfigOpLimitsBean opLimits;
- private List<ConfigSrcOrDestBean> sources;
- private ConfigSrcOrDestBean destination;
- private boolean skipReadErrors;
- private boolean skipEntryDelete;
+ private List<ConfigSourceBean> sources;
+ private ConfigDestBean destination;
+ private boolean skipReadErrors = false;
+ private boolean skipEntryDelete = false;
public String getName() {
return name;
@@ -46,16 +46,16 @@ public class ConfigTaskBean {
public void setOpLimits(ConfigOpLimitsBean opLimits) {
this.opLimits = opLimits;
}
- public List<ConfigSrcOrDestBean> getSources() {
+ public List<ConfigSourceBean> getSources() {
return sources;
}
- public void setSources(List<ConfigSrcOrDestBean> sources) {
+ public void setSources(List<ConfigSourceBean> sources) {
this.sources = sources;
}
- public ConfigSrcOrDestBean getDestination() {
+ public ConfigDestBean getDestination() {
return destination;
}
- public void setDestination(ConfigSrcOrDestBean destination) {
+ public void setDestination(ConfigDestBean destination) {
this.destination = destination;
}
public boolean isSkipReadErrors() {
diff --git a/src/main/src/conf/SSSyncConnectionsFactory.java b/src/main/src/conf/SSSyncConnectionsFactory.java
deleted file mode 100644
index e747258..0000000
--- a/src/main/src/conf/SSSyncConnectionsFactory.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * SSSync, a Simple and Stupid Synchronizer for data with multi-valued attributes
- * Copyright (C) 2014 Ludovic Pouzenc <ludovic@pouzenc.fr>
- *
- * This file is part of SSSync.
- *
- * SSSync is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * SSSync is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with SSSync. If not, see <http://www.gnu.org/licenses/>
- */
-
-package conf;
-
-import data.io.ConnectionsHolder;
-import data.io.ldap.LDAPConnectionWrapper;
-import data.io.sql.SQLConnectionWrapper;
-
-/**
- * TODO javadoc
- *
- * @author lpouzenc
- */
-public class SSSyncConnectionsFactory {
-
- /**
- * Setup all connections described in config
- * @return
- * @throws Exception
- */
- public static ConnectionsHolder setupConnections(ConfigConnectionsBean confConn) throws Exception {
- ConnectionsHolder connections = new ConnectionsHolder();
-
- for ( ConfigConnectionBean conn : confConn.getConnections() ) {
- switch (conn.getType()) {
- case jdbc:
- SQLConnectionWrapper connSQL = new SQLConnectionWrapper(conn.getDbms(), conn.getHost(), conn.getPort(), conn.getRess(), conn.getUser(), conn.getPass(), conn.getDb());
- connections.putConnSQL(conn.getId(), connSQL);
- break;
- case ldap:
- LDAPConnectionWrapper connLDAP = new LDAPConnectionWrapper(conn.getHost(), conn.getPort(), conn.getBind(), conn.getPass());
- connections.putConnLDAP(conn.getId(), connLDAP);
- break;
- default:
- //XXX : find better Exception type
- throw new Exception("Bad config : conn '" + conn.getId() + "' unsupported type");
- }
- }
-
- return connections;
- }
-
-}
diff --git a/src/main/src/conf/SSSyncTasksFactory.java b/src/main/src/sync/SSSyncTasksFactory.java
index de3e8f6..a91b3fa 100644
--- a/src/main/src/conf/SSSyncTasksFactory.java
+++ b/src/main/src/sync/SSSyncTasksFactory.java
@@ -18,17 +18,23 @@
* along with SSSync. If not, see <http://www.gnu.org/licenses/>
*/
-package conf;
+package sync;
import java.io.File;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
-import sync.BasicSyncTask;
+import conf.ConfigDestBean;
+import conf.ConfigRootBean;
+import conf.ConfigSourceBean;
+import conf.ConfigTaskBean;
+
+import sync.AbstractSyncTask;
import data.filters.MVDataCombiner;
import data.filters.MVDataCombiner.MVDataCombineMode;
import data.io.ConnectionsHolder;
+import data.io.MVDataReadWriterPair;
import data.io.MVDataReader;
import data.io.MVDataWriter;
import data.io.SafeDataReader;
@@ -43,14 +49,17 @@ import data.io.sql.SQLConnectionWrapper;
*/
public class SSSyncTasksFactory {
+
+
/**
- * Build tasks objects with all needed resources from a config beans tree
+ * Build tasks objects with all needed resources from a config bean tree
+ *
* @param conf
* @return
* @throws Exception
*/
- public static List<BasicSyncTask> setupTasks(ConnectionsHolder connections, ConfigRootBean confMain) throws Exception {
- List<BasicSyncTask> tasks = new ArrayList<BasicSyncTask>();
+ public static List<AbstractSyncTask> setupTasks(ConnectionsHolder connections, ConfigRootBean confMain) throws Exception {
+ List<AbstractSyncTask> tasks = new ArrayList<AbstractSyncTask>();
// For each task...
for ( ConfigTaskBean confTask: confMain.getTasks() ) {
@@ -58,20 +67,20 @@ public class SSSyncTasksFactory {
// Building all sources
- List<ConfigSrcOrDestBean> confSources = confTask.getSources();
+ List<ConfigSourceBean> confSources = confTask.getSources();
// See if we are in multiple source situation (then MVDataCombiner) or not (then simple MVDataReader)
if ( confSources.size() == 0 ) {
throw new Exception("Bad config : task '" + confTask.getName() + "' has no defined sources");
} else if ( confSources.size() == 1 ) {
- srcReader = new SafeDataReader(_makeReader(connections, confSources.get(0), confTask.getName()), confTask.isSkipReadErrors());
+ srcReader = new SafeDataReader(_makeSrcReader(connections, confSources.get(0), confTask.getName()), confTask.isSkipReadErrors());
} else {
List<MVDataReader> readers = new ArrayList<MVDataReader>();
List<MVDataCombineMode> mergeModes = new ArrayList<MVDataCombineMode>();
// For each source of the future MVDataCombiner...
- for ( ConfigSrcOrDestBean confSource: confSources ) {
+ for ( ConfigSourceBean confSource: confSources ) {
// Create and add the reader and his parameters
- readers.add(new SafeDataReader(_makeReader(connections, confSource, confTask.getName()), confTask.isSkipReadErrors()));
+ readers.add(new SafeDataReader(_makeSrcReader(connections, confSource, confTask.getName()), confTask.isSkipReadErrors()));
mergeModes.add(confSource.getMode());
}
@@ -79,28 +88,16 @@ public class SSSyncTasksFactory {
}
// Building destination
-
- MVDataReader dstReader=null;
- MVDataWriter dstWriter=null;
-
- ConfigSrcOrDestBean confDestination = confTask.getDestination();
- switch ( confDestination.getKind() ) {
- case ldap:
- LDAPConnectionWrapper builder = connections.getLDAPConnectionBuilder(confDestination.getConn());
- // TODO : configurable lookAhead
- MVDataReader tmpReader = builder.newFlatReader(confDestination.getName()+"_reader", confDestination.getBase(), confDestination.getAttr(), 128);
- dstReader = new SafeDataReader(tmpReader, false);
- dstWriter = builder.newFlatWriter(confDestination.getBase(), confDestination.getAttr());
- break;
- default:
- throw new Exception("Bad config : task '" + confTask.getName() + "' unsupported destination kind");
- }
-
- // Then building the sync task and add it to the task list
+ MVDataReadWriterPair dstRWriter = _makeDestRWriter(connections, confTask.getDestination(), confTask.getName());
+ MVDataWriter dstWriter = dstRWriter.writer;
+ MVDataReader dstReader = new SafeDataReader(dstRWriter.reader, false);
+
+ // Extract config opLimits
int maxInserts = confTask.getOpLimits().getInsert();
int maxUpdates = confTask.getOpLimits().getUpdate();
int maxDeletes = confTask.getOpLimits().getDelete();
+ // Building the sync task and add it to the task list
BasicSyncTask task = new BasicSyncTask(confTask.getName(), false, srcReader, dstReader, dstWriter);
task.setOperationLimits(maxInserts, maxUpdates, maxDeletes);
task.setSkipEntryDelete(confTask.isSkipEntryDelete());
@@ -112,12 +109,13 @@ public class SSSyncTasksFactory {
/**
* Helper function to make a new reader from an existing connection
+ * @param connections
* @param confSource
* @param taskName
* @return
* @throws Exception
*/
- private static MVDataReader _makeReader(ConnectionsHolder connections, ConfigSrcOrDestBean confSource, String taskName) throws Exception {
+ private static MVDataReader _makeSrcReader(ConnectionsHolder connections, ConfigSourceBean confSource, String taskName) throws Exception {
MVDataReader reader=null;
switch (confSource.getKind()) {
case csv:
@@ -125,16 +123,16 @@ public class SSSyncTasksFactory {
break;
case ldap:
LDAPConnectionWrapper ldapConnBuilder = connections.getLDAPConnectionBuilder(confSource.getConn());
- //FIXME : if conf error, get...ConnectionBuilder could return null
- //TODO : configurable lookAhead
- reader = ldapConnBuilder.newFlatReader(confSource.getName(), confSource.getBase(), confSource.getAttr(), 128);
+ //FIXME if conf error, getLDAPConnectionBuilder could return null
+ reader = ldapConnBuilder.newFlatReader(confSource.getName(), confSource.getBase(), confSource.getAttr(), confSource.getLookahead());
break;
case sorted_csv:
reader = new CSVDataReader(confSource.getName(), new FileReader(confSource.getPath()), true);
break;
case sql:
SQLConnectionWrapper sqlConnBuilder = connections.getSQLConnectionBuilder(confSource.getConn());
- //TODO We assume the query config item is a filepath. It isn't checked anywhere.
+ //FIXME if conf error, getSQLConnectionBuilder could return null
+ //TODO We assume the query config item is a filepath. It isn't checked anywhere.
reader = sqlConnBuilder.newReader(confSource.getName(), new File(confSource.getQuery()));
break;
default:
@@ -144,4 +142,29 @@ public class SSSyncTasksFactory {
return reader;
}
+ /**
+ * Helper function to make a new read-writer from an existing connection
+ *
+ * @param connections
+ * @param confDest
+ * @param taskName
+ * @return
+ * @throws Exception
+ */
+ private static MVDataReadWriterPair _makeDestRWriter(ConnectionsHolder connections, ConfigDestBean confDest, String taskName) throws Exception {
+ MVDataReader reader = null;
+ MVDataWriter writer = null;
+
+ switch ( confDest.getKind() ) {
+ case ldap:
+ LDAPConnectionWrapper builder = connections.getLDAPConnectionBuilder(confDest.getConn());
+ reader = builder.newFlatReader(confDest.getName()+"_reader", confDest.getBase(), confDest.getAttr(), confDest.getLookahead());
+ writer = builder.newFlatWriter(confDest.getBase(), confDest.getAttr());
+ break;
+ default:
+ throw new Exception("Bad config : task '" + taskName + "' unsupported destination kind");
+ }
+
+ return new MVDataReadWriterPair(reader, writer);
+ }
}