public void testSendingTwoDifferentStreamDefinitionsWithSameStreamId()
      throws MalformedURLException, AuthenticationException, TransportException, AgentException,
          UndefinedEventTypeException, InterruptedException, DataBridgeException,
          MalformedStreamDefinitionException, StreamDefinitionException,
          DifferentStreamDefinitionAlreadyDefinedException {

    TestServer testServer = new TestServer();
    testServer.start(7617);
    KeyStoreUtil.setTrustStoreParams();
    Thread.sleep(2000);

    // according to the convention the authentication port will be 7611+100= 7711 and its host will
    // be the same
    DataPublisher dataPublisher = new DataPublisher("tcp://localhost:7617", "admin", "admin");
    dataPublisher.defineStream(
        "{"
            + "  'name':'org.wso2.esb.MediatorStatistics3',"
            + "  'version':'2.3.0',"
            + "  'nickName': 'Stock Quote Information',"
            + "  'description': 'Some Desc',"
            + "  'tags':['foo', 'bar'],"
            + "  'metaData':["
            + "          {'name':'ipAdd','type':'STRING'}"
            + "  ],"
            + "  'payloadData':["
            + "          {'name':'symbol','type':'STRING'},"
            + "          {'name':'price','type':'DOUBLE'},"
            + "          {'name':'volume','type':'INT'},"
            + "          {'name':'max','type':'DOUBLE'},"
            + "          {'name':'min','type':'Double'}"
            + "  ]"
            + "}");
    Boolean exceptionOccurred = false;
    try {
      dataPublisher.defineStream(
          "{"
              + "  'name':'org.wso2.esb.MediatorStatistics3',"
              + "  'version':'2.3.0',"
              + "  'nickName': 'Stock Quote Information',"
              + "  'description': 'Some Desc',"
              + "  'tags':['foo', 'bar'],"
              + "  'metaData':["
              + "          {'name':'ipAdd','type':'STRING'}"
              + "  ],"
              + "  'payloadData':["
              + "          {'name':'symbol','type':'STRING'},"
              + "          {'name':'price','type':'DOUBLE'},"
              + "          {'name':'volume','type':'INT'},"
              + "          {'name':'min','type':'Double'}"
              + "  ]"
              + "}");

    } catch (DifferentStreamDefinitionAlreadyDefinedException e) {
      exceptionOccurred = true;
    }
    Assert.assertTrue(exceptionOccurred);

    dataPublisher.stop();
    testServer.stop();
  }
  public void testSendingSameStreamDefinitions()
      throws MalformedURLException, AuthenticationException, TransportException, AgentException,
          UndefinedEventTypeException, DifferentStreamDefinitionAlreadyDefinedException,
          InterruptedException, DataBridgeException, MalformedStreamDefinitionException,
          StreamDefinitionException {

    TestServer testServer = new TestServer();
    testServer.start(7614);
    KeyStoreUtil.setTrustStoreParams();
    Thread.sleep(2000);

    // according to the convention the authentication port will be 7611+100= 7711 and its host will
    // be the same
    DataPublisher dataPublisher = new DataPublisher("tcp://localhost:7614", "admin", "admin");
    String id1 =
        dataPublisher.defineStream(
            "{"
                + "  'name':'org.wso2.esb.MediatorStatistics',"
                + "  'version':'2.3.0',"
                + "  'nickName': 'Stock Quote Information',"
                + "  'description': 'Some Desc',"
                + "  'tags':['foo', 'bar'],"
                + "  'metaData':["
                + "          {'name':'ipAdd','type':'STRING'}"
                + "  ],"
                + "  'payloadData':["
                + "          {'name':'symbol','type':'STRING'},"
                + "          {'name':'price','type':'DOUBLE'},"
                + "          {'name':'volume','type':'INT'},"
                + "          {'name':'max','type':'DOUBLE'},"
                + "          {'name':'min','type':'Double'}"
                + "  ]"
                + "}");
    String id2 =
        dataPublisher.defineStream(
            "{"
                + "  'name':'org.wso2.esb.MediatorStatistics',"
                + "  'version':'2.3.0',"
                + "  'nickName': 'Stock Quote Information',"
                + "  'description': 'Some Desc',"
                + "  'tags':['foo', 'bar'],"
                + "  'metaData':["
                + "          {'name':'ipAdd','type':'STRING'}"
                + "  ],"
                + "  'payloadData':["
                + "          {'name':'symbol','type':'STRING'},"
                + "          {'name':'price','type':'DOUBLE'},"
                + "          {'name':'volume','type':'INT'},"
                + "          {'name':'max','type':'DOUBLE'},"
                + "          {'name':'min','type':'Double'}"
                + "  ]"
                + "}");

    Assert.assertEquals(id1, id2);
    // In this case correlation data is null
    dataPublisher.publish(
        id1, new Object[] {"127.0.0.1"}, null, new Object[] {"IBM", 96.8, 300, 120.6, 70.4});
    dataPublisher.stop();
    testServer.stop();
  }
  public static String addStreamId(DataPublisher dataPublisher)
      throws AgentException, MalformedStreamDefinitionException, StreamDefinitionException,
          DifferentStreamDefinitionAlreadyDefinedException, NoStreamDefinitionExistException {

    try {
      dataPublisher.findStream(
          APIMgtUsagePublisherConstants.API_MANAGER_FAULT_STREAM_NAME,
          APIMgtUsagePublisherConstants.API_MANAGER_FAULT_STREAM_VERSION);

    } catch (NoStreamDefinitionExistException e) {
      dataPublisher.defineStream(
          "{"
              + "  'name':'"
              + APIMgtUsagePublisherConstants.API_MANAGER_FAULT_STREAM_NAME
              + "',"
              + "  'version':'"
              + APIMgtUsagePublisherConstants.API_MANAGER_FAULT_STREAM_VERSION
              + "',"
              + "  'nickName': 'API Manager Fault Data',"
              + "  'description': 'Fault Data',"
              + "  'metaData':["
              + "          {'name':'clientType','type':'STRING'}"
              + "  ],"
              + "  'payloadData':["
              + "          {'name':'consumerKey','type':'STRING'},"
              + "          {'name':'context','type':'STRING'},"
              + "          {'name':'api_version','type':'STRING'},"
              + "          {'name':'api','type':'STRING'},"
              + "          {'name':'resource','type':'STRING'},"
              + "          {'name':'method','type':'STRING'},"
              + "          {'name':'version','type':'STRING'},"
              + "          {'name':'errorCode','type':'STRING'},"
              + "          {'name':'errorMessage','type':'STRING'},"
              + "          {'name':'requestTime','type':'STRING'},"
              + "          {'name':'userId','type':'STRING'},"
              + "          {'name':'tenantDomain','type':'STRING'},"
              + "          {'name':'hostName','type':'STRING'},"
              + "          {'name':'apiPublisher','type':'STRING'},"
              + "          {'name':'applicationName','type':'STRING'},"
              + "          {'name':'applicationId','type':'STRING'}"
              + "  ]"
              + "}");
    }
    return dataPublisher.findStream(
        APIMgtUsagePublisherConstants.API_MANAGER_FAULT_STREAM_NAME,
        APIMgtUsagePublisherConstants.API_MANAGER_FAULT_STREAM_VERSION);
  }
예제 #4
0
  private static void publishEvents(DataPublisher dataPublisher, String streamId, int i)
      throws AgentException {
    String currServiceName = getRandomServiceName();
    String currOperationName = getBodyOperationName();
    String currActivityID = getRandomActivityID();
    boolean currIsError = false;

    Event eventOne =
        new Event(
            streamId,
            System.currentTimeMillis(),
            getMetadata(currServiceName),
            getCorrelationdata(currActivityID),
            getPayloadData(currServiceName, currOperationName, currActivityID, currIsError));
    dataPublisher.publish(eventOne);
  }
예제 #5
0
  public static void main(String[] args)
      throws AgentException, MalformedStreamDefinitionException, StreamDefinitionException,
          DifferentStreamDefinitionAlreadyDefinedException, MalformedURLException,
          AuthenticationException, NoStreamDefinitionExistException, TransportException,
          SocketException, org.wso2.carbon.databridge.commons.exception.AuthenticationException {
    System.out.println("Starting Activity Monitoring Sample");

    KeyStoreUtil.setTrustStoreParams();

    String host = args[0];
    String port = args[1];
    String username = args[2];
    String password = args[3];
    int events = Integer.parseInt(args[4]);

    // create data publisher

    DataPublisher dataPublisher =
        new DataPublisher("tcp://" + host + ":" + port, username, password);
    String streamId = null;

    try {
      streamId = dataPublisher.findStream(ACTIVITY_MONITORING_STREAM, VERSION);
      System.out.println("Stream already defined");

    } catch (NoStreamDefinitionExistException e) {
      streamId =
          dataPublisher.defineStream(
              "{"
                  + "  'name':'"
                  + ACTIVITY_MONITORING_STREAM
                  + "',"
                  + "  'version':'"
                  + VERSION
                  + "',"
                  + "  'nickName': 'Activity_Monitoring',"
                  + "  'description': 'A sample for Activity Monitoring',"
                  + "  'metaData':["
                  + "          {'name':'character_set_encoding','type':'STRING'},"
                  + "          {'name':'host','type':'STRING'},"
                  + "          {'name':'http_method','type':'STRING'},"
                  + "          {'name':'message_type','type':'STRING'},"
                  + "          {'name':'remote_address','type':'STRING'},"
                  + "          {'name':'remote_host','type':'STRING'},"
                  + "          {'name':'service_prefix','type':'STRING'},"
                  + "          {'name':'tenant_id','type':'INT'},"
                  + "          {'name':'transport_in_url','type':'STRING'}"
                  + "  ],"
                  + "  'correlationData':["
                  + "          {'name':'bam_activity_id','type':'STRING'}"
                  + "  ],"
                  + "  'payloadData':["
                  + "          {'name':'soap_body','type':'STRING'},"
                  + "          {'name':'soap_header','type':'STRING'},"
                  + "          {'name':'message_direction','type':'STRING'},"
                  + "          {'name':'message_id','type':'STRING'},"
                  + "          {'name':'operation_name','type':'STRING'},"
                  + "          {'name':'service_name','type':'STRING'},"
                  + "          {'name':'timestamp','type':'LONG'}"
                  + "  ]"
                  + "}");
      //            //Define event stream
    }

    // Publish event for a valid stream
    if (!streamId.isEmpty()) {
      System.out.println("Stream ID: " + streamId);

      for (int i = 0; i < events; i++) {
        publishEvents(dataPublisher, streamId, i);
        System.out.println("Events published : " + (i + 1));
      }
      try {
        Thread.sleep(2000);
      } catch (InterruptedException e) {
      }

      dataPublisher.stop();
    }
  }
예제 #6
0
  public static void main(String[] args)
      throws AgentException, MalformedStreamDefinitionException, StreamDefinitionException,
          DifferentStreamDefinitionAlreadyDefinedException, MalformedURLException,
          AuthenticationException, NoStreamDefinitionExistException, TransportException,
          SocketException, org.wso2.carbon.databridge.commons.exception.AuthenticationException {
    System.out.println("Starting Mediator Statistic Sample");
    AgentConfiguration agentConfiguration = new AgentConfiguration();
    String currentDir = System.getProperty("user.dir");
    System.setProperty(
        "javax.net.ssl.trustStore", currentDir + "/src/main/resources/client-truststore.jks");
    System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon");
    Agent agent = new Agent(agentConfiguration);
    String host;

    if (getLocalAddress() != null) {
      host = getLocalAddress().getHostAddress();
    } else {
      host = "localhost"; // Defaults to localhost
    }

    String url = getProperty("url", "tcp://" + host + ":" + "7611");
    String username = getProperty("username", "admin");
    String password = getProperty("password", "admin");

    // create data publisher

    DataPublisher dataPublisher = new DataPublisher(url, username, password, agent);
    String streamId = null;

    try {
      streamId = dataPublisher.findStream(MEDIATOR_STATISTICS_STREAM, VERSION);
      System.out.println("Stream already defined");

    } catch (NoStreamDefinitionExistException e) {
      streamId =
          dataPublisher.defineStream(
              "{"
                  + "  'name':'"
                  + MEDIATOR_STATISTICS_STREAM
                  + "',"
                  + "  'version':'"
                  + VERSION
                  + "',"
                  + "  'nickName': 'MediationStatsDataAgent',"
                  + "  'description': 'A sample for Mediator Statistics',"
                  + "  'metaData':["
                  + "          {'name':'host','type':'STRING'}"
                  + "  ],"
                  + "  'payloadData':["
                  + "          {'name':'direction','type':'STRING'},"
                  + "          {'name':'timestamp','type':'LONG'},"
                  + "          {'name':'resource_id','type':'STRING'},"
                  + "          {'name':'stats_type','type':'STRING'},"
                  + "          {'name':'max_processing_time','type':'LONG'},"
                  + "          {'name':'avg_processing_time','type':'DOUBLE'},"
                  + "          {'name':'min_processing_time','type':'LONG'},"
                  + "          {'name':'fault_count','type':'INT'},"
                  + "          {'name':'count','type':'INT'}"
                  + "  ]"
                  + "}");
    }

    // Publish event for a valid stream
    if (!streamId.isEmpty()) {
      System.out.println("Stream ID: " + streamId);

      for (int i = 0; i < 3000; i++) {
        publishEvents(dataPublisher, streamId);
        System.out.println("Events published : " + (i + 1));
        if ((i % 100) == 0) {
          try {
            Thread.sleep(1000);
          } catch (InterruptedException e) {
            // Do nothing. Just add time buffer
          }
        }
      }
      try {

        Thread.sleep(2000);
      } catch (InterruptedException e) {
      }
      dataPublisher.stop();
    }
  }
예제 #7
0
 private static void publishEvents(DataPublisher dataPublisher, String streamId)
     throws AgentException {
   Event eventOne =
       new Event(streamId, System.currentTimeMillis(), getMetadata(), null, getPayloadData());
   dataPublisher.publish(eventOne);
 }