001 /** 002 * Copyright (c) 2003 Daffodil Software Ltd all rights reserved, 003 * Modifications Copyright (c) 2008 Regiscope Digital Imaging Co, LLC, All rights reserved. 004 * This program is free software; you can redistribute it and/or modify 005 * it under the terms of version 2 of the GNU General Public License as 006 * published by the Free Software Foundation. 007 * There are special exceptions to the terms and conditions of the GPL 008 * as it is applied to this software. See the GNU General Public License for more details. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU General Public License for more details. 014 * 015 * You should have received a copy of the GNU General Public License 016 * along with this program; if not, write to the Free Software 017 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 018 */ 019 020 package org.dbreplicator.repconsole; 021 022 import java.util.Properties; 023 import java.io.FileInputStream; 024 import java.io.File; 025 import org.dbreplicator.replication._ReplicationServer; 026 import org.dbreplicator.replication.ReplicationServer; 027 import org.dbreplicator.replication.RepException; 028 import org.dbreplicator.replication._Subscription; 029 import org.dbreplicator.replication.RepConstants; 030 import javax.crypto.SecretKey; 031 import java.io.ObjectInputStream; 032 import java.io.BufferedInputStream; 033 import java.io.IOException; 034 035 public class Subconfiguration { 036 037 private String subDbDriver , subDbURL , subDbUser , subDbPassword ; 038 private String subName; 039 private String portNumber; 040 private String subSysName;// = "192.168.4.129"; 041 private String pubName; 042 private String pubSysName;// = "192.168.4.129"; 043 private String pubPortNumber;// = 3001; 044 private String replicationType; 045 046 _ReplicationServer repSubscription; 047 _Subscription sub; 048 private DesEncrypter desEncrypter; 049 050 051 052 public Subconfiguration() { 053 try { 054 055 File f =new File("."+File.separator+"subconfig.ini"); 056 Properties p =new Properties(); 057 p.load(new FileInputStream(f)); 058 //RepConstants.writeMessage_FILE("GOING TO INITIALISE THE SUB AND PUB INFORMATION"); 059 initialiseSubAndPubInformation(p); 060 //RepConstants.writeMessage_FILE("SUB AND PUB INFORMATION INITIALISED SUCCESSFULLY"); 061 //RepConstants.writeMessage_FILE("GOING TO START THE REPLICATION SERVER"); 062 repSubscription = initialiseReplicationServer(); 063 //RepConstants.writeMessage_FILE("REPLICATION SERVER STARTED SUCCESSFULLY"); 064 sub =getSubscription(subName,pubName); 065 //RepConstants.writeMessage_FILE("sUBSCRIPTION GETTED "); 066 performReplication(sub,replicationType); 067 068 } 069 catch (Exception ex) { 070 RepConstants.writeERROR_FILE(ex); 071 System.out.println(" Problem occured in pull replication. For details see the error.lg"); 072 // System.exit(1); 073 } 074 } 075 076 077 078 private void performReplication(_Subscription sub,String replicationType) throws RepException{ 079 try{ 080 //RepConstants.writeMessage_FILE("PRFORME PULL "); 081 sub.pull(); 082 //RepConstants.writeMessage_FILE(" PULLED SUCCESS FULYY "); 083 System.out.println("Pulled successfully "); 084 }finally{ 085 System.exit(1); 086 } 087 /* 088 if(replicationType.equalsIgnoreCase("Sanpshot")) { 089 sub.getSnapShot(); 090 System.out.println(" SanpShot Taken Successfully"); 091 }else if(replicationType.equalsIgnoreCase("Synchronize")) { 092 sub.synchronize(); 093 System.out.println("Synchronize successfully "); 094 } else if(replicationType.equalsIgnoreCase("Pull")) { 095 sub.pull(); 096 097 } 098 else if(replicationType.equalsIgnoreCase("Push")) { 099 sub.push(); 100 System.out.println("Pushed successfully "); 101 102 } */ 103 } 104 105 106 private void initialiseSubAndPubInformation( Properties p) { 107 //set subscriber data 108 subDbDriver = p.getProperty("DRIVER"); 109 //System.out.println(" subDbDriver ="+subDbDriver); 110 subDbURL = p.getProperty("URL"); 111 //System.out.println(" subDbURL ="+subDbURL); 112 subDbUser = p.getProperty("USER"); 113 //System.out.println(" subDbUser ="+subDbUser); 114 subDbPassword = p.getProperty("PASSWORD"); 115 //System.out.println(" subDbPassword ="+subDbPassword); 116 subDbPassword = decryptPassword(subDbPassword); 117 //System.out.println(" subDbPassword ="+subDbPassword); 118 subName = p.getProperty("SUBNAME"); 119 //System.out.println(" subName ="+subName); 120 portNumber = p.getProperty("PORT"); 121 //System.out.println(" portNumber ="+portNumber); 122 subSysName = p.getProperty("SYSTEMNAME"); 123 //System.out.println(" subSysName ="+subSysName); 124 pubName =p.getProperty("PUBNAME"); 125 //System.out.println(" pubName ="+pubName); 126 pubSysName =p.getProperty("PUB_SYSTEMNAME"); 127 //System.out.println(" pubSysName ="+pubSysName); 128 pubPortNumber =p.getProperty("PUB_PORT"); 129 //System.out.println(" pubPortNumber ="+pubPortNumber); 130 replicationType =p.getProperty("REPLICATIONTYPE"); 131 132 } 133 134 135 private _ReplicationServer initialiseReplicationServer() throws RepException { 136 _ReplicationServer repSubscription = ReplicationServer.getInstance(Integer.parseInt(portNumber),subSysName); 137 repSubscription.setDataSource(subDbDriver,subDbURL,subDbUser,subDbPassword); 138 return repSubscription; 139 } 140 141 142 private _Subscription getSubscription(String subName, String pubName) throws RepException { 143 _Subscription sub = repSubscription.getSubscription(subName); 144 if (sub == null) { 145 sub = repSubscription.createSubscription(subName, pubName); 146 sub.setRemoteServerPortNo(Integer.parseInt(pubPortNumber)); 147 sub.setRemoteServerUrl(pubSysName); 148 try { 149 sub.subscribe(); 150 } 151 catch (RepException ex) { 152 throw ex; 153 // ex.printStackTrace(); 154 } 155 } 156 else { 157 sub.setRemoteServerPortNo(Integer.parseInt(pubPortNumber)); 158 sub.setRemoteServerUrl(pubSysName); 159 } 160 // System.out.println(" SUBSCRIBED "); 161 return sub; 162 } 163 164 165 private String decryptPassword(String password){ 166 SecretKey sk = getSecretKey(); 167 desEncrypter = new DesEncrypter(sk); 168 return desEncrypter.decrypt(password); 169 } 170 171 172 private SecretKey getSecretKey(){ 173 try { 174 String path ="/org.dbreplicator/repconsole/secretKey.obj"; 175 java.net.URL url1 = getClass().getResource(path); 176 //System.out.println(" url1 : "+url1); 177 ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(url1.openStream())); 178 SecretKey sk = (SecretKey) ois.readObject(); 179 return sk; 180 } 181 catch (IOException ex) { 182 RepConstants.writeERROR_FILE(ex); 183 // ex.printStackTrace(); 184 } 185 catch(ClassNotFoundException ex){ 186 RepConstants.writeERROR_FILE(ex); 187 // ex.printStackTrace(); 188 189 } 190 return null; 191 192 } 193 194 195 196 public static void main(String[] args) { 197 Subconfiguration sc = new Subconfiguration(); 198 } 199 200 }

