@Test
  public void testStreamDefinitionConversion() throws MalformedStreamDefinitionException {
    StreamDefinition streamDef = new StreamDefinition("stockStream", "1.1.0");
    List<Attribute> meta = new ArrayList<Attribute>(1);
    meta.add(new Attribute("symbol", AttributeType.STRING));
    List<Attribute> payload = new ArrayList<Attribute>(1);
    payload.add(new Attribute("price", AttributeType.DOUBLE));
    streamDef.setMetaData(meta);
    streamDef.setPayloadData(payload);

    org.wso2.siddhi.query.api.definition.StreamDefinition siddhiDefinition = null;
    try {
      siddhiDefinition =
          EventProcessorUtil.convertToSiddhiStreamDefinition(streamDef, "stockStream");
    } catch (EventStreamConfigurationException e) {
      log.error(e);
    }
    Assert.assertEquals(siddhiDefinition.getAttributeList().size(), 2);
    log.info(siddhiDefinition);

    /*
            StreamDefinition databrigeDefinition = EventProcessorUtil.convertToDatabridgeStreamDefinition(siddhiDefinition, "stockStream/1.1.0");
            Assert.assertEquals(databrigeDefinition.getPayloadData().size(), 2);
            log.info(databrigeDefinition);
    */
  }
예제 #2
0
  public void createMailInputStream(int tenantID) throws EmailMonitorServiceException {
    StreamDefinition streamDefinition;
    try {
      streamDefinition =
          eventStreamService.getStreamDefinition("gmailInputStream", "1.0.0", tenantID);
    } catch (EventStreamConfigurationException e) {
      logger.error(e.getMessage());
      throw new EmailMonitorServiceException("Error when getting stream definition", e);
    }
    if (streamDefinition == null) {
      try {
        streamDefinition = new StreamDefinition("gmailInputStream", "1.0.0");
      } catch (MalformedStreamDefinitionException e) {
        logger.error(e.getMessage());
        throw new EmailMonitorServiceException("Error defining new stream", e);
      }

      List<Attribute> metaData = new ArrayList<Attribute>();

      Attribute metaTenantID = new Attribute("tenant_id", AttributeType.INT);
      metaData.add(metaTenantID);

      Attribute metaHttpMethod = new Attribute("http_method", AttributeType.STRING);
      metaData.add(metaHttpMethod);

      Attribute metaCharacterSet = new Attribute("character_set_encoding", AttributeType.STRING);
      metaData.add(metaCharacterSet);

      Attribute metaRemoteAddress = new Attribute("remote_address", AttributeType.STRING);
      metaData.add(metaRemoteAddress);

      Attribute metaTransportIn = new Attribute("transport_in_url", AttributeType.STRING);
      metaData.add(metaTransportIn);

      Attribute metaMessageType = new Attribute("message_type", AttributeType.STRING);
      metaData.add(metaMessageType);

      Attribute metaRemoteHost = new Attribute("remote_host", AttributeType.STRING);
      metaData.add(metaRemoteHost);

      Attribute metaServicePrefix = new Attribute("service_prefix", AttributeType.STRING);
      metaData.add(metaServicePrefix);

      Attribute metaHost = new Attribute("host", AttributeType.STRING);
      metaData.add(metaHost);

      streamDefinition.setMetaData(metaData);

      List<Attribute> correlationData = new ArrayList<Attribute>();

      Attribute correlationActivityID = new Attribute("activity_id", AttributeType.STRING);
      correlationData.add(correlationActivityID);

      streamDefinition.setCorrelationData(correlationData);

      List<Attribute> payloadData = new ArrayList<Attribute>();

      Attribute payloadMessageDirection = new Attribute("message_direction", AttributeType.STRING);
      payloadData.add(payloadMessageDirection);

      Attribute payloadServiceName = new Attribute("service_name", AttributeType.STRING);
      payloadData.add(payloadServiceName);

      Attribute payloadOperationName = new Attribute("operation_name", AttributeType.STRING);
      payloadData.add(payloadOperationName);

      Attribute payloadMessageID = new Attribute("message_id", AttributeType.STRING);
      payloadData.add(payloadMessageID);

      Attribute payloadTimestamp = new Attribute("timestamp", AttributeType.LONG);
      payloadData.add(payloadTimestamp);

      Attribute payloadEmailMessageID = new Attribute("messageID", AttributeType.LONG);
      payloadData.add(payloadEmailMessageID);

      Attribute payloadSubject = new Attribute("subject", AttributeType.STRING);
      payloadData.add(payloadSubject);

      Attribute payloadFrom = new Attribute("sender", AttributeType.STRING);
      payloadData.add(payloadFrom);

      Attribute payloadTo = new Attribute("to", AttributeType.STRING);
      payloadData.add(payloadTo);

      Attribute payloadSentDate = new Attribute("sentDate", AttributeType.LONG);
      payloadData.add(payloadSentDate);

      Attribute payloadThreadID = new Attribute("threadID", AttributeType.LONG);
      payloadData.add(payloadThreadID);

      Attribute payloadStatus = new Attribute("status", AttributeType.STRING);
      payloadData.add(payloadStatus);

      Attribute payloadContent = new Attribute("content", AttributeType.STRING);
      payloadData.add(payloadContent);

      Attribute payloadLabels = new Attribute("labels", AttributeType.STRING);
      payloadData.add(payloadLabels);

      Attribute payloadSoapHeader = new Attribute("soap_header", AttributeType.STRING);
      payloadData.add(payloadSoapHeader);

      Attribute payloadSoapBody = new Attribute("soap_body", AttributeType.STRING);
      payloadData.add(payloadSoapBody);

      streamDefinition.setPayloadData(payloadData);
      streamDefinition.setDescription("email information stream");
      streamDefinition.setNickName("gmail");

      try {
        eventStreamService.addEventStreamDefinition(streamDefinition, tenantID);
      } catch (EventStreamConfigurationException e) {
        logger.error(e.getMessage());
        throw new EmailMonitorServiceException("Error when adding new stream", e);
      }
    }
  }