-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Release 3.0: MetaServletCaller CLI added with migrateDatabase action
- Loading branch information
Showing
33 changed files
with
311 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/main/java/de/cimt/talendcomp/tac/MetaServletCaller.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package de.cimt.talendcomp.tac; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.InputStream; | ||
import java.util.Properties; | ||
|
||
import org.apache.log4j.BasicConfigurator; | ||
import org.apache.log4j.Level; | ||
import org.apache.log4j.Logger; | ||
|
||
public class MetaServletCaller { | ||
|
||
private static final Logger logger = Logger.getLogger(MetaServletCaller.class); | ||
|
||
public static void main(String[] args) { | ||
BasicConfigurator.configure(); | ||
if (args == null || args.length == 0) { | ||
printUsage(); | ||
System.exit(1); | ||
} | ||
String action = args[0]; | ||
if ("migrateDatabase".equalsIgnoreCase(action)) { | ||
if (args.length < 2) { | ||
printUsage(); | ||
System.out.println("Command to migrate a database: java -jar cimt-metaservletcaller-<version>.jar migrateDatabase /path/to/your-configuration.properties"); | ||
System.exit(1); | ||
} | ||
String configFilePath = args[1]; | ||
try { | ||
migrateDatabase(configFilePath); | ||
} catch (Exception e) { | ||
logger.error("migrateDatabase failed: " + e.getMessage()); | ||
System.exit(2); | ||
} | ||
} else { | ||
printUsage(); | ||
System.out.println("Unknown action: " + action); | ||
System.exit(1); | ||
} | ||
System.exit(0); | ||
} | ||
|
||
private static void migrateDatabase(String configFile) throws Exception { | ||
Properties properties = loadConfiguration(configFile); | ||
boolean debug = "true".equals(properties.getProperty("debug")); | ||
if (debug) { | ||
Logger.getRootLogger().setLevel(Level.DEBUG); | ||
Logger.getRootLogger().info("Debug level set"); | ||
} | ||
System.out.println("Setup migrate database request..."); | ||
TACConnection conn = new TACConnection(properties.getProperty("targetTacUrl")); | ||
MigrateDatabaseAction action = new MigrateDatabaseAction(conn); | ||
action.setDbConfigPassword(properties.getProperty("dbConfigPassword")); | ||
action.setSourceUser(properties.getProperty("sourceUser")); | ||
action.setSourcePasswd(properties.getProperty("sourcePasswd")); | ||
action.setSourceUrl(properties.getProperty("sourceUrl")); | ||
action.setTargetUser(properties.getProperty("targetUser")); | ||
action.setTargetPasswd(properties.getProperty("targetPasswd")); | ||
action.setTargetUrl(properties.getProperty("targetUrl")); | ||
System.out.println("Send migrate database request..."); | ||
action.execute(); | ||
} | ||
|
||
private static void printUsage() { | ||
System.out.println("Caller for TAC-Metaservlet"); | ||
System.out.println("@cimt AG version 1.0"); | ||
System.out.println("Usage: java -jar cimt-metaservletcaller-<version>.jar <action> [<more parameters>]"); | ||
} | ||
|
||
public static Properties loadConfiguration(String configFilePath) throws Exception { | ||
if (configFilePath == null || configFilePath.trim().isEmpty()) { | ||
throw new IllegalArgumentException("configuration file path cannot be null or empty!"); | ||
} | ||
File configFile = new File(configFilePath); | ||
if (configFile.isAbsolute() == false) { | ||
configFile = new File(System.getProperty("work.dir"), configFilePath); | ||
} | ||
if (configFile.exists() == false) { | ||
throw new Exception("Given configuration file: " + configFile.getAbsolutePath() + " does not exist!"); | ||
} | ||
System.out.println("Load configuration file: " + configFile.getAbsolutePath()); | ||
Properties properties = new Properties(); | ||
InputStream in = new FileInputStream(configFile); | ||
try { | ||
properties.load(in); | ||
} catch (Exception e) { | ||
logger.error("loadConfiguration failed: " + e.getMessage()); | ||
throw e; | ||
} finally { | ||
in.close(); | ||
} | ||
return properties; | ||
} | ||
|
||
} |
129 changes: 129 additions & 0 deletions
129
src/main/java/de/cimt/talendcomp/tac/MigrateDatabaseAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package de.cimt.talendcomp.tac; | ||
|
||
import org.apache.log4j.Logger; | ||
|
||
public class MigrateDatabaseAction extends TACAction { | ||
|
||
private static Logger logger = Logger.getLogger(MigrateDatabaseAction.class); | ||
private String sourceUrl = null; | ||
private String sourceUser = null; | ||
private String sourcePasswd = null; | ||
private String targetUrl = null; | ||
private String targetUser = null; | ||
private String targetPasswd = null; | ||
private String mode = "synchronous"; | ||
private String dbConfigPassword = null; | ||
|
||
public MigrateDatabaseAction(TACConnection connection) { | ||
super(connection); | ||
} | ||
|
||
@Override | ||
public String getAction() { | ||
return "migrateDatabase"; | ||
} | ||
|
||
@Override | ||
public void execute() throws Exception { | ||
if (dbConfigPassword == null || dbConfigPassword.trim().isEmpty()) { | ||
throw new Exception("dbConfigPassword not set!"); | ||
} | ||
addParam("dbConfigPassword", dbConfigPassword); | ||
addParam("mode", mode); | ||
if (sourceUrl == null || sourceUrl.trim().isEmpty()) { | ||
throw new Exception("sourceUrl not set!"); | ||
} | ||
addParam("sourceUrl", sourceUrl); | ||
if (sourceUser == null || sourceUser.trim().isEmpty()) { | ||
throw new Exception("sourceUser not set!"); | ||
} | ||
addParam("sourceUser", sourceUser); | ||
if (sourcePasswd == null || sourcePasswd.trim().isEmpty()) { | ||
throw new Exception("sourcePasswd not set!"); | ||
} | ||
addParam("sourcePasswd", sourcePasswd); | ||
if (targetUrl == null || targetUrl.trim().isEmpty()) { | ||
throw new Exception("targetUrl not set!"); | ||
} | ||
addParam("targetUrl", targetUrl); | ||
if (targetUser == null || targetUser.trim().isEmpty()) { | ||
throw new Exception("targetUser not set!"); | ||
} | ||
addParam("targetUser", targetUser); | ||
if (targetPasswd == null || targetPasswd.trim().isEmpty()) { | ||
throw new Exception("targetPasswd not set!"); | ||
} | ||
addParam("targetPasswd", targetPasswd); | ||
String result = null; | ||
try { | ||
result = executeRequest(); | ||
} catch (Exception e) { | ||
logger.error("Execute migrateDatabase failed: " + e.getMessage(), e); | ||
throw e; | ||
} | ||
if (result != null && result.trim().startsWith(ERROR)) { | ||
logger.error("Execute migrateDatabase failed: " + result); | ||
} else { | ||
logger.info("Response: " + result); | ||
System.out.println("Finished migrating database. Please check the result!"); | ||
} | ||
} | ||
|
||
public String getSourceUrl() { | ||
return sourceUrl; | ||
} | ||
|
||
public void setSourceUrl(String sourceUrl) { | ||
this.sourceUrl = sourceUrl; | ||
} | ||
|
||
public String getSourceUser() { | ||
return sourceUser; | ||
} | ||
|
||
public void setSourceUser(String sourceUser) { | ||
this.sourceUser = sourceUser; | ||
} | ||
|
||
public String getSourcePasswd() { | ||
return sourcePasswd; | ||
} | ||
|
||
public void setSourcePasswd(String sourcePasswd) { | ||
this.sourcePasswd = sourcePasswd; | ||
} | ||
|
||
public String getTargetUrl() { | ||
return targetUrl; | ||
} | ||
|
||
public void setTargetUrl(String targetUrl) { | ||
this.targetUrl = targetUrl; | ||
} | ||
|
||
public String getTargetUser() { | ||
return targetUser; | ||
} | ||
|
||
public void setTargetUser(String targetUser) { | ||
this.targetUser = targetUser; | ||
} | ||
|
||
public String getTargetPasswd() { | ||
return targetPasswd; | ||
} | ||
|
||
public void setTargetPasswd(String targetPasswd) { | ||
this.targetPasswd = targetPasswd; | ||
} | ||
|
||
public String getDbConfigPassword() { | ||
return dbConfigPassword; | ||
} | ||
|
||
public void setDbConfigPassword(String dbConfigPassword) { | ||
this.dbConfigPassword = dbConfigPassword; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.