/**
  * Add a stream definition using the Event stream publisher.
  *
  * @param streamDefinitionBean The stream definition bean class.
  */
 public String addStreamDefinition(StreamDefinitionBean streamDefinitionBean)
     throws AnalyticsWebServiceException, MalformedStreamDefinitionException {
   StreamDefinition streamDefinition = Utils.getStreamDefinition(streamDefinitionBean);
   try {
     eventStreamService.addEventStreamDefinition(streamDefinition);
     return streamDefinition.getStreamId();
   } catch (Exception e) {
     logger.error(
         "Unable to set the stream definition: ["
             + streamDefinition.getName()
             + ":"
             + streamDefinition.getVersion()
             + "]"
             + e.getMessage(),
         e);
     throw new AnalyticsWebServiceException(
         "Unable to set the stream definition: ["
             + streamDefinition.getName()
             + ":"
             + streamDefinition.getVersion()
             + "], "
             + e.getMessage(),
         e);
   }
 }
  @Override
  public void publish(Object[] payload) {
    if (!isEnabled()) {
      throw new RuntimeException("Statistics publisher is not enabled");
    }

    Event event = new Event();
    event.setPayloadData(payload);
    event.setArbitraryDataMap(new HashMap<String, String>());

    try {
      if (log.isDebugEnabled()) {
        log.debug(
            String.format(
                "Publishing cep event: [stream] %s [version] %s",
                streamDefinition.getName(), streamDefinition.getVersion()));
      }
      asyncDataPublisher.publish(streamDefinition.getName(), streamDefinition.getVersion(), event);
    } catch (AgentException e) {
      if (log.isErrorEnabled()) {
        log.error(
            String.format(
                "Could not publish cep event: [stream] %s [version] %s",
                streamDefinition.getName(), streamDefinition.getVersion()),
            e);
      }
    }
  }
Ejemplo n.º 3
0
  public boolean isStreamDefinitionValidForConfiguration(
      EventBuilderConfiguration eventBuilderConfiguration,
      StreamDefinition exportedStreamDefinition) {
    if (!(eventBuilderConfiguration.getToStreamName().equals(exportedStreamDefinition.getName())
        && eventBuilderConfiguration
            .getToStreamVersion()
            .equals(exportedStreamDefinition.getVersion()))) {
      return false;
    }
    if (eventBuilderConfiguration.getInputMapping() instanceof XMLInputMapping) {
      XMLInputMapping xmlInputMapping =
          (XMLInputMapping) eventBuilderConfiguration.getInputMapping();
      for (InputMappingAttribute inputMappingAttribute :
          xmlInputMapping.getInputMappingAttributes()) {
        Attribute attribute =
            new Attribute(
                inputMappingAttribute.getToElementKey(), inputMappingAttribute.getToElementType());
        if (!exportedStreamDefinition.getPayloadData().contains(attribute)) {
          return false;
        }
      }
    } else {
      return false;
    }

    return true;
  }
 public static void deployStreams(DeployableTemplate template) {
   if (template.getStreams() != null) {
     for (String stream : template.getStreams()) {
       StreamDefinition streamDefinition = null;
       try {
         streamDefinition = EventDefinitionConverterUtils.convertFromJson(stream);
         BatchScriptDeployerValueHolder.getEventStreamService()
             .addEventStreamDefinition(streamDefinition);
       } catch (MalformedStreamDefinitionException e) {
         log.error("Stream definition is incorrect in domain template " + stream, e);
       } catch (EventStreamConfigurationException e) {
         log.error("Exception occurred when configuring stream " + streamDefinition.getName(), e);
       } catch (StreamDefinitionAlreadyDefinedException e) {
         log.error(
             "Same template stream name "
                 + streamDefinition.getName()
                 + " has been defined for another definition ",
             e);
         throw e;
       }
     }
   }
 }
Ejemplo n.º 5
0
 private void publishEvent(
     BrokerConfiguration brokerConfiguration,
     AsyncDataPublisher dataPublisher,
     Event event,
     StreamDefinition streamDefinition)
     throws BrokerEventProcessingException {
   try {
     dataPublisher.publish(streamDefinition.getName(), streamDefinition.getVersion(), event);
   } catch (AgentException ex) {
     throw new BrokerEventProcessingException(
         "Cannot publish data via DataPublisher for the broker configuration:"
             + brokerConfiguration.getName()
             + " for the  event "
             + event,
         ex);
   }
 }
Ejemplo n.º 6
0
 private String createTopic(StreamDefinition streamDefinition) {
   return streamDefinition.getName() + "/" + streamDefinition.getVersion();
 }