コード例 #1
0
 @BeforeClass
 public void setup() throws NamingException, AnalyticsException, IOException {
   GenericUtils.clearGlobalCustomDataSourceRepo();
   System.setProperty(
       GenericUtils.WSO2_ANALYTICS_CONF_DIRECTORY_SYS_PROP, "src/test/resources/conf3");
   AnalyticsServiceHolder.setHazelcastInstance(null);
   AnalyticsServiceHolder.setAnalyticsClusterManager(null);
   System.setProperty(AnalyticsServiceHolder.FORCE_INDEXING_ENV_PROP, Boolean.TRUE.toString());
   this.init(AnalyticsServiceHolder.getAnalyticsDataService());
 }
コード例 #2
0
 @AfterClass
 public void done() throws NamingException, AnalyticsException, IOException {
   this.service.destroy();
   System.clearProperty(AnalyticsServiceHolder.FORCE_INDEXING_ENV_PROP);
   AnalyticsServiceHolder.setAnalyticsDataService(null);
 }
コード例 #3
0
 @SuppressWarnings("static-access")
 public static void main(String[] args) throws Exception {
   String timePattern = "yy-mm-dd hh:mm:ss";
   Options options = new Options();
   options.addOption(new Option("backup", false, "backup analytics data"));
   options.addOption(new Option("restore", false, "restores analytics data"));
   options.addOption(new Option("enableIndexing", false, "enables indexing while restoring"));
   options.addOption(
       OptionBuilder.withArgName("directory")
           .hasArg()
           .withDescription("source/target directory")
           .create("dir"));
   options.addOption(
       OptionBuilder.withArgName("table list")
           .hasArg()
           .withDescription("analytics tables (comma separated) to backup/restore")
           .create("tables"));
   options.addOption(
       OptionBuilder.withArgName(timePattern)
           .hasArg()
           .withDescription("consider records from this time (inclusive)")
           .create("timefrom"));
   options.addOption(
       OptionBuilder.withArgName(timePattern)
           .hasArg()
           .withDescription("consider records to this time (non-inclusive)")
           .create("timeto"));
   options.addOption(
       OptionBuilder.withArgName("tenant id (default is super tenant)")
           .hasArg()
           .withDescription("specify tenant id of the tenant considered")
           .create("tenant_id"));
   options.addOption(
       OptionBuilder.withArgName("restore record batch size (default is 1000)")
           .hasArg()
           .withDescription("specify the number of records per batch for backup")
           .create("batch"));
   CommandLineParser parser = new BasicParser();
   CommandLine line = parser.parse(options, args);
   if (args.length < 2) {
     new HelpFormatter().printHelp("analytics-backup.sh|cmd", options);
     System.exit(1);
   }
   if (line.hasOption("restore")) {
     if (line.hasOption("enableIndexing")) {
       System.setProperty(AnalyticsServiceHolder.FORCE_INDEXING_ENV_PROP, Boolean.TRUE.toString());
       forceIndexing = true;
     }
   }
   if (line.hasOption("backup")) {
     if (line.hasOption("batch")) {
       String batchValue = line.getOptionValue("batch");
       batchSize = Integer.parseInt(batchValue);
     } else {
       batchSize = RECORD_BATCH_SIZE;
     }
   }
   AnalyticsDataService service = null;
   try {
     service = AnalyticsServiceHolder.getAnalyticsDataService();
     int tenantId;
     if (line.hasOption("tenant_id")) {
       tenantId = Integer.parseInt(args[2]);
     } else {
       tenantId = MultitenantConstants.SUPER_TENANT_ID;
     }
     SimpleDateFormat dateFormat = new SimpleDateFormat(timePattern);
     long timeFrom = Long.MIN_VALUE;
     String tfStr = "-~";
     if (line.hasOption("timefrom")) {
       tfStr = line.getOptionValue("timefrom");
       timeFrom = dateFormat.parse(tfStr).getTime();
     }
     long timeTo = Long.MAX_VALUE;
     String ttStr = "+~";
     if (line.hasOption("timeto")) {
       ttStr = line.getOptionValue("timeto");
       timeTo = dateFormat.parse(ttStr).getTime();
     }
     String[] specificTables = null;
     if (line.hasOption("tables")) {
       specificTables = line.getOptionValue("tables").split(",");
     }
     File baseDir = new File(line.getOptionValue("dir"));
     if (!baseDir.exists()) {
       baseDir.mkdirs();
     }
     System.out.println(
         "Intializing [tenant="
             + tenantId
             + "] [timefrom='"
             + tfStr
             + "'] [timeto='"
             + ttStr
             + "'] [dir='"
             + baseDir.getAbsolutePath()
             + "']"
             + (specificTables != null ? (" [table=" + Arrays.toString(specificTables) + "]") : "")
             + "...");
     if (line.hasOption("backup")) {
       backup(service, tenantId, baseDir, timeFrom, timeTo, specificTables);
     } else if (line.hasOption("restore")) {
       restore(service, tenantId, baseDir, timeFrom, timeTo, specificTables);
     }
     System.out.println("Done.");
   } finally {
     if (service != null) {
       service.destroy();
     }
   }
 }