示例#1
0
  /**
   * The set of module is specified by a primary configuration module (created using reflection and
   * moduleClassName) plus optional extra modules. For each module, sets the configuration filename
   * and invokes the module's run () method to allow it to set up ServiceRegistry instance(s).
   *
   * @param moduleClassName name of the primary configuration module
   * @param configItem name of the configuration file
   * @param extraModules extra modules to be configured
   */
  public static void configureServices(
      final String moduleClassName,
      final Object configItem,
      final ConfigurableModule... extraModules) {
    // Set up the main module.
    final ConfigurableModule mainModule = HcUtil.instantiate(moduleClassName);
    configureAndRun(configItem, mainModule);

    // And the extras.
    configureServices(configItem, extraModules);
  }
 /** IInstrumentationLogger */
 @Override
 public void onOperationTimedOut(
     final String contextId,
     final String operationName,
     final long msecDuration,
     final long msecLimit,
     final String limitPropertyName) {
   m_valueOnOperationTimedOut.add(operationName);
   writeToFile(
       Level.Warn,
       HcUtil.deepToString(
           "onOperationTimedOut",
           operationName,
           msecDuration,
           msecLimit,
           limitPropertyName,
           contextId));
 }
 /** IInstrumentationLogger */
 @Override
 public void onOperationFailed(
     final String contextId,
     final String messageText,
     final String operationName,
     final long msecDuration,
     final long msecLimit,
     final String limitPropertyName) {
   m_valueOnOperationFailed.add(messageText);
   writeToFile(
       Level.Fatal,
       HcUtil.deepToString(
           "onOperationFailed",
           messageText,
           operationName,
           msecDuration,
           msecLimit,
           limitPropertyName,
           contextId));
 }
 /** IInstrumentationLogger */
 @Override
 public void onExecutionSummary(
     final String contextId,
     final List<TimedScope> listTimedScope,
     final List<CounterThroughput> listCounterThroughput,
     final List<Counter> listCounter,
     final List<CounterRange> listCounterRange,
     final List<MaxCounter> listMaxCounter) {
   m_valueOnExecutionSummary.add(contextId);
   writeToFile(
       Level.Info,
       HcUtil.deepToString(
           "onExecutionSummary",
           contextId,
           listTimedScope,
           listCounterThroughput,
           listCounter,
           listCounterRange,
           listMaxCounter));
 }
  @Test
  public void testInstrumentation() {
    try (IScope scope = new ExecutionScope()) {
      Instrumentation.setPolicyAsyncInstrumentation(false); // execute actions synchronously

      final E2<DummyLogger, DummyRemoteInstrumentationLogger> loggers = setupLoggers("fewi");
      final DummyLogger localLogger = loggers.getE0();
      final DummyRemoteInstrumentationLogger remoteLogger = loggers.getE1();

      if (true) {
        Instrumentation.publishExecutionSummary();
        checkInstrumentationListener(remoteLogger, 1, 0, 0, 0);
        checkLogger(localLogger, 0, 0, 0, 1, 0, 0);
        checkLogger(remoteLogger, 0, 0, 0, 0, 0, 0);
      }

      if (true) {
        final String name = "timelyOperation";
        Instrumentation.execute(
            name,
            200,
            () -> {
              HcUtil.pause(10);
            },
            name);

        Instrumentation.publishExecutionSummary();
        checkInstrumentationListener(remoteLogger, 2, 0, 0, 0);
        checkLogger(localLogger, 0, 0, 0, 2, 0, 0);
        checkLogger(remoteLogger, 0, 0, 0, 0, 0, 0);
      }

      if (true) {
        final String name = "slowOperation";
        Instrumentation.execute(
            name,
            10,
            () -> {
              HcUtil.pause(100);
            },
            name);

        Instrumentation.publishExecutionSummary();
        checkInstrumentationListener(remoteLogger, 3, 1, 1, 0);
        checkLogger(localLogger, 0, 0, 2, 3, 0, 0);
        checkLogger(remoteLogger, 0, 0, 0, 0, 0, 0);
      }

      if (true) {
        try {
          final String name = "failedTimelyOperation";
          Instrumentation.execute(
              name,
              200,
              () -> {
                HcUtil.pause(10);
                ThreadContext.assertFaultNotNull(null);
              },
              name);
        } catch (final Exception e) {
        }

        Instrumentation.publishExecutionSummary();
        checkInstrumentationListener(remoteLogger, 4, 1, 1, 1);
        checkLogger(localLogger, 2, 0, 2, 4, 0, 0);
        checkLogger(remoteLogger, 1, 0, 0, 0, 0, 0);
      }

      if (true) {
        try {
          final String name = "failedTimelyOperationException";
          Instrumentation.execute(
              name,
              200,
              () -> {
                HcUtil.pause(10);
                throw new RuntimeException("Ooops");
              },
              name);
        } catch (final Exception e) {
        }

        Instrumentation.publishExecutionSummary();
        checkInstrumentationListener(remoteLogger, 5, 1, 1, 2);
        checkLogger(localLogger, 4, 0, 2, 5, 0, 0);
        checkLogger(remoteLogger, 2, 0, 0, 0, 0, 0);
      }
    }
  }
 private static String getTempPath(final String filename) {
   return HcUtil.formFilepath(HcUtil.getTempDirectoryName(), filename);
 }
示例#7
0
  private void analyseSchema() {
    try {
      final String jdbcUrl = m_options.m_jdbcUrl;
      final String schemaName = m_options.m_schemaName;

      System.out.printf("Analysing schema [%s] at [%s]...%n", schemaName, jdbcUrl);
      final long msecStart = System.currentTimeMillis();

      // Create a database connection
      final DataSource dataSource = new DatabaseConnectionOptions(jdbcUrl);
      final Connection connection =
          dataSource.getConnection(m_options.m_username, m_options.m_password);

      // Create the options
      final SchemaCrawlerOptions options = new SchemaCrawlerOptions();

      // Set what details are required in the schema - this affects the
      // time taken to crawl the schema
      options.setSchemaInfoLevel(SchemaInfoLevel.standard());
      options.setSchemaInclusionRule(new RegularExpressionInclusionRule(schemaName));

      final InclusionRule tableRule = new RegularExpressionExclusionRule(".+[\\$/].+");

      final InclusionRule procRule =
          s -> {
            // System.out.println (s);
            final String[] a =
                new String[] {
                  ".*" + "\\$" + ".*",
                  ".*" + "_RETRIGGER_EXPRESSION" + ".*",
                  ".*" + "BITOR" + ".*",
                  ".*" + "CENTRED" + ".*",
                  ".*" + "COMPLEMENT" + ".*",
                  ".*" + "D2" + ".*",
                  ".*" + "DDMMYYYYHHMMMSS" + ".*",
                  ".*" + "DOW" + ".*",
                  ".*" + "DSM" + ".*",
                  ".*" + "ENABLE" + ".*",
                  ".*" + "F2" + ".*",
                  ".*" + "GET_LAST_CHANGE_NUMBER" + ".*",
                  ".*" + "GROOM" + ".*",
                  ".*" + "IS_EVEN" + ".*",
                  ".*" + "IS_ODD" + ".*",
                  ".*" + "LEFT_PADDED" + ".*",
                  ".*" + "LOGICAL_" + ".*",
                  ".*" + "M2" + ".*",
                  ".*" + "MD5" + ".*",
                  ".*" + "MERGE_OSS_TRIP_LOCATION" + ".*",
                  ".*" + "MODF" + ".*",
                  ".*" + "NEXT_TIME_ABSOLUTE" + ".*",
                  ".*" + "NEXT_TIME_RELATIVE" + ".*",
                  ".*" + "RESERVE_FARM_STATUS" + ".*",
                  ".*" + "RIGHT_PADDED" + ".*",
                  ".*" + "S2" + ".*",
                  ".*" + "SCHEDULE_JOB" + ".*",
                  ".*" + "SNDF" + ".*",
                  ".*" + "SSM" + ".*",
                  ".*" + "XOR" + ".*",
                  ".*" + "XSD_TIMESTAMP" + ".*",
                  ".*" + "//dummy//" + ".*"
                };
            return !HcUtil.containsWildcard(a, s);
          };
      options.setTableInclusionRule(tableRule);

      options.setRoutineInclusionRule(procRule); // new ExcludeAll ()

      // Get the schema definition
      final Catalog catalog = SchemaCrawlerUtility.getCatalog(connection, options);
      final long msecDuration = System.currentTimeMillis() - msecStart;

      final Collection<Schema> schemas = catalog.getSchemas();
      ThreadContext.assertFault(
          schemas.size() == 1, "Expected one schema, got %s [%s]", schemas.size(), schemas.size());

      final Schema[] a = schemas.toArray(new Schema[schemas.size()]);
      final Schema schema = a[0];

      final DatabaseInfo di = catalog.getDatabaseInfo();

      System.out.printf(
          "  catalog[%s] database[%s] version[%s]%n",
          schema.getFullName(), di.getProductName(), di.getProductVersion());
      System.out.printf("  %s tables%n", catalog.getTables(schema).size());
      System.out.printf("  %s stored procedures%n", catalog.getRoutines(schema).size());
      System.out.printf("...analysed in %s seconds%n", msecDuration / 1_000L);

      outputSchemaXml(catalog, schema);
      System.out.printf("Schema file [%s] created.%n", m_options.m_outputFilename);
    } catch (final SchemaCrawlerException | SQLException e) {
      // Propagate exception as unchecked fault up to the fault barrier.
      ThreadContext.throwFault(e);
    }
  }