/** * Create receiver element. Assume that imported streams contains all the receiver elements. * * @param document * @param queryExpressions * @param importedStreams @return * @throws EventStreamConfigurationException */ private static Element constructReceiverElement(Document document, String queryExpressions, List<String> importedStreams) throws EventStreamConfigurationException { Element receiverElement = document.createElement(EventProcessorConstants.EVENT_RECEIVER); receiverElement.setAttribute(EventProcessorConstants.NAME, EventProcessorConstants.EVENT_RECEIVER_SPOUT); ExecutionPlan executionPlan = SiddhiCompiler.parse(queryExpressions); receiverElement.setAttribute(EventProcessorConstants.PARALLEL, String.valueOf(getParallelism(executionPlan.getAnnotations(), EventProcessorConstants.RECEIVER_PARALLELISM))); Element streams = document.createElement(EventProcessorConstants.STREAMS); for (String definition : importedStreams) { Element stream = getStreamElement(document, definition); streams.appendChild(stream); } receiverElement.appendChild(streams); return receiverElement; }
/** * Create publisher element. Assumes that exported streams contains all publisher streams. * * @param exportedStreams * @return * @throws EventStreamConfigurationException */ private static Element constructPublisherElement(Document document, String queryExpressions, List<String> exportedStreams) throws EventStreamConfigurationException { Element publisherElement = document.createElement(EventProcessorConstants.EVENT_PUBLISHER); Element publisherInputStream = document.createElement(EventProcessorConstants.INPUT_STREAMS); Element publisherOutputStream = document.createElement(EventProcessorConstants.OUTPUT_STREAMS); publisherElement.setAttribute(EventProcessorConstants.NAME, EventProcessorConstants.EVENT_PUBLISHER_BOLT); ExecutionPlan executionPlan = SiddhiCompiler.parse(queryExpressions); publisherElement.setAttribute(EventProcessorConstants.PARALLEL, String.valueOf(getParallelism(executionPlan.getAnnotations(), EventProcessorConstants.PUBLISHER_PARALLELISM))); for (String definition : exportedStreams) { Element stream = getStreamElement(document, definition); publisherOutputStream.appendChild(stream); Element clonedStream = (Element) stream.cloneNode(true); publisherInputStream.appendChild(clonedStream); } publisherElement.appendChild(publisherInputStream); publisherElement.appendChild(publisherOutputStream); return publisherElement; }
private static List<Element> constructTriggerElement(Document document, String queryExpression) throws StormQueryConstructionException { ExecutionPlanRuntime executionPlanRuntime = EventProcessorValueHolder.getSiddhiManager().createExecutionPlanRuntime(queryExpression); Map<String, AbstractDefinition> streamDefinitionMap = executionPlanRuntime.getStreamDefinitionMap(); executionPlanRuntime.shutdown(); ExecutionPlan executionPlan = SiddhiCompiler.parse(queryExpression); List<Element> triggerElementList = new ArrayList<Element>(); for (Map.Entry entry : executionPlan.getTriggerDefinitionMap().entrySet()){ Element triggerElement = document.createElement(EventProcessorConstants.TRIGGER_TAG); ParallelismInfoHolder holder = new ParallelismInfoHolder(1, false); setAttributes(triggerElement, (String)entry.getKey() , holder); String getTriggerDefinition = EventProcessorUtil.getTriggerDefinitionString((TriggerDefinition) entry.getValue()); Element triggerDefinitionElement = document.createElement(EventProcessorConstants.TRIGGER_DEFINITION); triggerDefinitionElement.setTextContent(getTriggerDefinition); triggerElement.appendChild(triggerDefinitionElement); String outputStreamDefinition = EventProcessorUtil.getDefinitionString(streamDefinitionMap.get(entry.getKey())); Element outputStreamElement = document.createElement(EventProcessorConstants.OUTPUT_STREAM); outputStreamElement.setTextContent(outputStreamDefinition); triggerElement.appendChild(outputStreamElement); triggerElementList.add(triggerElement); } return triggerElementList; }
/** * Returns the execution plan name * * @param executionPlanAsString executionPlan (taken from code mirror) as a string * @return execution plan name as given in @Plan:name('MyPlanName'). Returns null in the absence of @Plan:name('MyPlanName') */ public static String getExecutionPlanName(String executionPlanAsString) { String executionPlanName = null; ExecutionPlan executionPlan = SiddhiCompiler.parse(executionPlanAsString); executionPlanName = AnnotationHelper.getAnnotationElement(EventProcessorConstants.ANNOTATION_NAME_NAME, null, executionPlan.getAnnotations()).getValue(); return executionPlanName; }
public Response siddhiAppElementsGet(String appName) throws NotFoundException { Map<String, SiddhiAppData> siddhiAppDataMap = StreamProcessorDataHolder.getStreamProcessorService() .getSiddhiAppMap(); if (siddhiAppDataMap.containsKey(appName)) { String siddhiAppString = siddhiAppDataMap.get(appName).getSiddhiApp(); SiddhiApp siddhiApp = SiddhiCompiler.parse(String.valueOf(siddhiAppString)); SiddhiAppRuntime siddhiAppRuntime = new SiddhiManager().createSiddhiAppRuntime(siddhiApp); List<SiddhiAppElements> listOfSiddhiAppElements = new ArrayList<>(); for (int i = 0; i < siddhiApp.getExecutionElementList().size(); i++) { ExecutionElement executionElement = siddhiApp.getExecutionElementList().get(i); if (executionElement instanceof Query) { loadQueryExecutionElements(siddhiApp, siddhiAppRuntime, executionElement, siddhiAppString, listOfSiddhiAppElements); } else if (executionElement instanceof Partition) { loadPartitionExecutionElements(siddhiApp, siddhiAppRuntime, executionElement, siddhiAppString, listOfSiddhiAppElements); } } loadAggregarionData(siddhiApp, siddhiAppRuntime, listOfSiddhiAppElements, siddhiAppString); loadSources(siddhiApp, siddhiAppRuntime, listOfSiddhiAppElements, siddhiAppString); loadSinks(siddhiApp, siddhiAppRuntime, listOfSiddhiAppElements, siddhiAppString); return Response.ok().entity(listOfSiddhiAppElements).build(); } String jsonString = new Gson().toJson(new ApiResponseMessage(ApiResponseMessage.NOT_FOUND, "There is no Siddhi App exist with provided name : " + appName)); return Response.status(Response.Status.NOT_FOUND).entity(jsonString).build(); }
List<String> sourceList = new ArrayList<>(); List<String> sinkList = new ArrayList<>(); SiddhiApp siddhiApp = SiddhiCompiler.parse(siddhiAppHolder.getSiddhiApp()); for (Map.Entry<String, StreamDefinition> sourceStream : siddhiApp.getStreamDefinitionMap().entrySet()) { for (Annotation annotation : sourceStream.getValue().getAnnotations()) {
public String getSiddhiAppName(String siddhiApp) throws SiddhiAppConfigurationException { try { SiddhiApp parsedSiddhiApp = SiddhiCompiler.parse(siddhiApp); Element nameAnnotation = AnnotationHelper. getAnnotationElement(SiddhiAppProcessorConstants.ANNOTATION_NAME_NAME, null, parsedSiddhiApp.getAnnotations()); if (nameAnnotation == null || nameAnnotation.getValue().isEmpty()) { throw new SiddhiAppConfigurationException("Siddhi App name must " + "be provided as @App:name('name')."); } return nameAnnotation.getValue(); } catch (Throwable e) { throw new SiddhiAppConfigurationException("Exception occurred when retrieving Siddhi App Name ", e); } }
parsedExecutionPlan = SiddhiCompiler.parse(executionPlan); String executionPlanName = AnnotationHelper.getAnnotationElement(EventProcessorConstants.ANNOTATION_NAME_NAME, null, parsedExecutionPlan.getAnnotations()).getValue();
private void parse() throws Exception { SiddhiApp siddhiApp = SiddhiCompiler.parse(enrichedExecutionPlan); for (ExecutionElement executionElement : siddhiApp.getExecutionElementList()) { if (!(executionElement instanceof Query)) {
List<String> stringQueryList = SiddhiQLStormQuerySplitter.split(queryExpressions); List<String> eventTableDefinitionList = SiddhiQLStormQuerySplitter.getEventTableList(queryExpressions); ExecutionPlan executionPlan = SiddhiCompiler.parse(queryExpressions); List<ExecutionElement> executionElements = executionPlan.getExecutionElementList(); Set<String> eventTableIdSet = executionPlan.getTableDefinitionMap().keySet();
public void editInactiveExecutionPlan(String executionPlan, String filename) throws ExecutionPlanConfigurationException, ExecutionPlanDependencyValidationException { EventProcessorHelper.validateExecutionPlan(executionPlan); org.wso2.siddhi.query.api.ExecutionPlan parsedExecutionPlan = SiddhiCompiler.parse(executionPlan); String newExecutionPlanName = AnnotationHelper.getAnnotationElement(EventProcessorConstants.ANNOTATION_NAME_NAME, null, parsedExecutionPlan.getAnnotations()).getValue(); EventProcessorConfigurationFilesystemInvoker.delete(filename); EventProcessorConfigurationFilesystemInvoker.save(executionPlan, newExecutionPlanName, filename); }
Pattern streamVersionPattern = Pattern.compile(EventProcessorConstants.STREAM_VER_REGEX); ExecutionPlan parsedExecPlan = SiddhiCompiler.parse(executionPlan); Element element = AnnotationHelper.getAnnotationElement(EventProcessorConstants.ANNOTATION_NAME_NAME, null, parsedExecPlan.getAnnotations());
@Override public SiddhiTopology createTopology(String userDefinedSiddhiApp) { this.userDefinedSiddhiApp = userDefinedSiddhiApp; this.siddhiApp = SiddhiCompiler.parse(userDefinedSiddhiApp); this.siddhiAppRuntime = (new SiddhiManager()).createSiddhiAppRuntime(userDefinedSiddhiApp); SiddhiQueryGroup siddhiQueryGroup;
public void editActiveExecutionPlan(String executionPlan, String executionPlanName) throws ExecutionPlanConfigurationException, ExecutionPlanDependencyValidationException { EventProcessorHelper.validateExecutionPlan(executionPlan); org.wso2.siddhi.query.api.ExecutionPlan parsedExecutionPlan = SiddhiCompiler.parse(executionPlan); String newExecutionPlanName = AnnotationHelper.getAnnotationElement(EventProcessorConstants.ANNOTATION_NAME_NAME, null, parsedExecutionPlan.getAnnotations()).getValue(); if (!(newExecutionPlanName.equals(executionPlanName))) { if (isExecutionPlanAlreadyExist(newExecutionPlanName)) { throw new ExecutionPlanConfigurationException(newExecutionPlanName + " " + "already registered as an execution in this tenant"); } } if (executionPlanName != null && executionPlanName.length() > 0) { String fileName; ExecutionPlanConfigurationFile file = getExecutionPlanConfigurationFileByPlanName(executionPlanName); if (file == null) { fileName = executionPlanName + EventProcessorConstants.EP_CONFIG_FILE_EXTENSION_WITH_DOT; } else { fileName = file.getFileName(); } EventProcessorConfigurationFilesystemInvoker.delete(fileName); EventProcessorConfigurationFilesystemInvoker.save(executionPlan, newExecutionPlanName, newExecutionPlanName + EventProcessorConstants.EP_CONFIG_FILE_EXTENSION_WITH_DOT); } else { throw new ExecutionPlanConfigurationException("Invalid configuration provided, No execution plan name."); } }
private PolicyExecutionPlan doParse() throws Exception { PolicyExecutionPlan policyExecutionPlan = new PolicyExecutionPlan(); try { ExecutionPlan executionPlan = SiddhiCompiler.parse(this.executionPlan);
EventProcessorHelper.loadDataSourceConfiguration(siddhiManager); ExecutionPlanRuntime executionPlanRuntime = null; org.wso2.siddhi.query.api.ExecutionPlan parsedExecutionPlan = SiddhiCompiler.parse(executionPlan);
SiddhiCompiler.parse(updatedExecutionPlan).getAnnotations()) == null || !updatedExecutionPlan.contains(ExecutionPlanDeployerConstants.EXECUTION_PLAN_NAME_ANNOTATION)) { updatedExecutionPlan = executionPlanNameDefinition + updatedExecutionPlan;
SiddhiAppRuntime siddhiAppRuntime; try { siddhiApp = SiddhiCompiler.parse(siddhiAppString); siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiApp); } catch (Exception e) {