View Javadoc

1   /**
2      This file is part of GoldenGate Project (named also GoldenGate or GG).
3   
4      Copyright 2009, Frederic Bregier, and individual contributors by the @author
5      tags. See the COPYRIGHT.txt in the distribution for a full listing of
6      individual contributors.
7   
8      All GoldenGate Project is free software: you can redistribute it and/or 
9      modify it under the terms of the GNU General Public License as published 
10     by the Free Software Foundation, either version 3 of the License, or
11     (at your option) any later version.
12  
13     GoldenGate is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17  
18     You should have received a copy of the GNU General Public License
19     along with GoldenGate .  If not, see <http://www.gnu.org/licenses/>.
20   */
21  package openr66.server;
22  
23  import goldengate.common.database.exception.GoldenGateDatabaseNoConnectionException;
24  import goldengate.common.database.exception.GoldenGateDatabaseSqlException;
25  import goldengate.common.logging.GgInternalLogger;
26  import goldengate.common.logging.GgInternalLoggerFactory;
27  import goldengate.common.logging.GgSlf4JLoggerFactory;
28  
29  import java.io.File;
30  
31  import openr66.configuration.AuthenticationFileBasedConfiguration;
32  import openr66.configuration.FileBasedConfiguration;
33  import openr66.configuration.RuleFileBasedConfiguration;
34  import openr66.database.DbConstant;
35  import openr66.database.data.DbTaskRunner;
36  import openr66.protocol.configuration.Configuration;
37  import openr66.protocol.exception.OpenR66ProtocolBusinessException;
38  import openr66.protocol.exception.OpenR66ProtocolSystemException;
39  import openr66.protocol.utils.ChannelUtils;
40  
41  import org.jboss.netty.logging.InternalLoggerFactory;
42  
43  /**
44   * Server local configuration export to files
45   *
46   * @author Frederic Bregier
47   *
48   */
49  public class ServerExportConfiguration {
50      /**
51       * Internal Logger
52       */
53      private static GgInternalLogger logger;
54  
55      /**
56       *
57       * @param args as configuration file and the directory where to export
58       */
59      public static void main(String[] args) {
60          InternalLoggerFactory.setDefaultFactory(new GgSlf4JLoggerFactory(null));
61          if (logger == null) {
62              logger = GgInternalLoggerFactory.getLogger(ServerExportConfiguration.class);
63          }
64          if (args.length < 2) {
65              System.err
66                      .println("Need configuration file and the directory where to export");
67              System.exit(1);
68          }
69          try {
70              if (! FileBasedConfiguration
71                      .setConfigurationServerMinimalFromXml(Configuration.configuration, args[0])) {
72                  logger
73                          .error("Needs a correct configuration file as first argument");
74                  if (DbConstant.admin != null){
75                      DbConstant.admin.close();
76                  }
77                  ChannelUtils.stopLogger();
78                  System.exit(1);
79                  return;
80              }
81              String directory = args[1];
82              String hostname = Configuration.configuration.HOST_ID;
83              logger.info("Start of Export");
84              File dir = new File(directory);
85              if (! dir.isDirectory()) {
86                  dir.mkdirs();
87              }
88              try {
89                  RuleFileBasedConfiguration.writeXml(directory, hostname);
90              } catch (GoldenGateDatabaseNoConnectionException e1) {
91                  logger.error("Error",e1);
92                  DbConstant.admin.close();
93                  ChannelUtils.stopLogger();
94                  System.exit(2);
95              } catch (GoldenGateDatabaseSqlException e1) {
96                  logger.error("Error",e1);
97                  DbConstant.admin.close();
98                  ChannelUtils.stopLogger();
99                  System.exit(2);
100             } catch (OpenR66ProtocolSystemException e1) {
101                 logger.error("Error",e1);
102                 DbConstant.admin.close();
103                 ChannelUtils.stopLogger();
104                 System.exit(2);
105             }
106             String filename = dir.getAbsolutePath()+File.separator+hostname+"_Runners.run.xml";
107             try {
108                 DbTaskRunner.writeXMLWriter(filename);
109             } catch (GoldenGateDatabaseNoConnectionException e1) {
110                 logger.error("Error",e1);
111                 DbConstant.admin.close();
112                 ChannelUtils.stopLogger();
113                 System.exit(2);
114             } catch (GoldenGateDatabaseSqlException e1) {
115                 logger.error("Error",e1);
116                 DbConstant.admin.close();
117                 ChannelUtils.stopLogger();
118                 System.exit(2);
119             } catch (OpenR66ProtocolBusinessException e1) {
120                 logger.error("Error",e1);
121                 DbConstant.admin.close();
122                 ChannelUtils.stopLogger();
123                 System.exit(2);
124             }
125             filename = dir.getAbsolutePath()+File.separator+hostname+"_Authentications.xml";
126             try {
127                 AuthenticationFileBasedConfiguration.writeXML(Configuration.configuration, 
128                         filename);
129             } catch (GoldenGateDatabaseNoConnectionException e) {
130                 logger.error("Error",e);
131                 DbConstant.admin.close();
132                 ChannelUtils.stopLogger();
133                 System.exit(2);
134             } catch (GoldenGateDatabaseSqlException e) {
135                 logger.error("Error",e);
136                 DbConstant.admin.close();
137                 ChannelUtils.stopLogger();
138                 System.exit(2);
139             } catch (OpenR66ProtocolSystemException e) {
140                 logger.error("Error",e);
141                 DbConstant.admin.close();
142                 ChannelUtils.stopLogger();
143                 System.exit(2);
144             }
145             logger.info("End of Export");
146         } finally {
147             if (DbConstant.admin != null) {
148                 DbConstant.admin.close();
149             }
150         }
151     }
152 
153 }