public String getElement(String key) { for (Element element : elements) { if (element.getKey() != null && element.getKey().equalsIgnoreCase(key)) { return element.getValue(); } } return null; }
public Partition addQuery(Query query) { if (query == null) { throw new SiddhiAppValidationException("Query should not be null"); } String name = null; Element element = AnnotationHelper.getAnnotationElement(SiddhiConstants.ANNOTATION_INFO, SiddhiConstants .ANNOTATION_ELEMENT_NAME, query.getAnnotations()); if (element != null) { name = element.getValue(); } if (name != null && queryNameList.contains(name)) { throw new SiddhiAppValidationException("Cannot add Query as another Execution Element already uses " + "its name=" + name + " within the same Partition", element.getQueryContextStartIndex(), element.getQueryContextEndIndex()); } queryNameList.add(name); this.queryList.add(query); return this; }
public SiddhiApp addQuery(Query query) { if (query == null) { throw new SiddhiAppValidationException("Query should not be null"); } String name = null; Element element = AnnotationHelper.getAnnotationElement(SiddhiConstants.ANNOTATION_INFO, SiddhiConstants .ANNOTATION_ELEMENT_NAME, query.getAnnotations()); if (element != null) { name = element.getValue(); } if (name != null && executionElementNameList.contains(name)) { throw new SiddhiAppValidationException( "Cannot add Query as another Execution Element already uses " + "its name=" + name, element.getQueryContextStartIndex(), element.getQueryContextEndIndex()); } executionElementNameList.add(name); this.executionElementList.add(query); return this; }
public SiddhiApp addPartition(Partition partition) { if (partition == null) { throw new SiddhiAppValidationException("Partition should not be null"); } String name = null; Element element = AnnotationHelper.getAnnotationElement(SiddhiConstants.ANNOTATION_INFO, SiddhiConstants .ANNOTATION_ELEMENT_NAME, partition.getAnnotations()); if (element != null) { name = element.getValue(); } if (name != null && executionElementNameList.contains(name)) { throw new SiddhiAppValidationException( "Cannot add Partition as another Execution Element already " + "uses its name=" + name, element.getQueryContextStartIndex(), element.getQueryContextEndIndex()); } executionElementNameList.add(name); this.executionElementList.add(partition); return this; }
/** * Util method used to convert a list of elements in an annotation to a comma-separated string. * * @param elements the list of annotation elements. * @return a comma-separated string of all elements in the list. */ public static String flattenAnnotatedElements(List<Element> elements) { StringBuilder sb = new StringBuilder(); elements.forEach(elem -> { sb.append(elem.getValue()); if (elements.indexOf(elem) != elements.size() - 1) { sb.append(RDBMSTableConstants.SEPARATOR); } }); return sb.toString(); }
/** * Get user preference on creating kafka topics from {@link org.wso2.carbon.sp.jobmanager.core.SiddhiAppCreator}. * If no value is defined 'true' is returned */ private boolean isTransportChannelCreationEnabled(List<Annotation> annotationList) { Element element = AnnotationHelper.getAnnotationElement( SiddhiTopologyCreatorConstants.TRANSPORT_CHANNEL_CREATION_IDENTIFIER, null, annotationList); if (element == null) { return true; } else { return Boolean.valueOf(element.getValue()); } }
public String getElement(String key) { for (Element element : elements) { if (element.getKey() != null && element.getKey().equalsIgnoreCase(key)) { return element.getValue(); } } return null; }
/** * Get parallel value of the execGroup if given by the user unless default parallel. * {@link SiddhiTopologyCreatorConstants#DEFAULT_PARALLEL} value is returned */ private int getExecGroupParallel(ExecutionElement executionElement) { Element element = AnnotationHelper.getAnnotationElement(SiddhiTopologyCreatorConstants.DISTRIBUTED_IDENTIFIER, SiddhiTopologyCreatorConstants.PARALLEL_IDENTIFIER, executionElement.getAnnotations()); if (element == null) { return SiddhiTopologyCreatorConstants.DEFAULT_PARALLEL; } else { return Integer.parseInt(element.getValue()); } }
/** * Traverse annotations and returns the name * * @param annotations * @return */ private static String getName(List<Annotation> annotations) { String name = UUID.randomUUID().toString(); if (annotations != null) { for (Annotation annotation : annotations) { if (annotation.getName().equals(EventProcessorConstants.NAME)) { name = annotation.getElements().get(0).getValue(); } } } return name; }
/** * Generates a PayloadOrAttributeElement object from the given Siddhi Element object * @param element Siddhi Element object * @return PayloadOrAttributeElement object */ private PayloadOrAttributeElement generatePayloadOrAttributesElement(Element element) { PayloadOrAttributeElement payloadOrAttributeElement = new PayloadOrAttributeElement(); payloadOrAttributeElement.key = element.getKey(); payloadOrAttributeElement.value = element.getValue(); return payloadOrAttributeElement; }
/** * Get SiddhiAppName if given by the user unless a unique SiddhiAppName is returned. * * @return String SiddhiAppName */ private String getSiddhiAppName() { Element element = AnnotationHelper.getAnnotationElement(SiddhiTopologyCreatorConstants.SIDDHIAPP_NAME_IDENTIFIER, null, siddhiApp.getAnnotations()); if (element == null) { return SiddhiTopologyCreatorConstants.DEFAULT_SIDDHIAPP_NAME + "-" + UUID.randomUUID(); //defaultName } else { return element.getValue(); } }
/** * Get execGroup name if given by the user unless a unique execGroup is returned. */ private String getExecGroupName(ExecutionElement executionElement, String siddhiAppName, String defaultExeGroupName) { Element element = AnnotationHelper.getAnnotationElement(SiddhiTopologyCreatorConstants.DISTRIBUTED_IDENTIFIER, SiddhiTopologyCreatorConstants.EXECGROUP_IDENTIFIER, executionElement.getAnnotations()); if (element == null) { return defaultExeGroupName; } else { return siddhiAppName + "-" + element.getValue(); } }
/** * Get the query element name if given by the user unless a default string is returned. * @param executionElement The query element. * @return Name of the query element. */ private String getElementName(ExecutionElement executionElement) { Element element = AnnotationHelper.getAnnotationElement(SiddhiTopologyCreatorConstants .INFO_IDENTIFIER, SiddhiTopologyCreatorConstants.SIDDHIAPP_NAME_IDENTIFIER, executionElement.getAnnotations()); if (element == null) { return SiddhiTopologyCreatorConstants.EXECUTION_ELEMENT; } else { return element.getValue(); } }
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); } }
protected void init(StreamDefinition streamDefinition, OptionHolder optionHolder, ConfigReader configReader, SiddhiAppContext siddhiAppContext) { this.siddhiAppContext = siddhiAppContext; uriOption = optionHolder.validateAndGetOption(Constants.FILE_URI); String append = optionHolder.validateAndGetStaticValue(Constants.APPEND, Constants.TRUE); properties = new HashMap<>(); properties.put(Constants.ACTION, Constants.WRITE); if (Constants.TRUE.equalsIgnoreCase(append)) { properties.put(Constants.APPEND, append); } String mapType = streamDefinition.getAnnotations().get(0).getAnnotations().get(0).getElements().get(0) .getValue(); addEventSeparator = optionHolder.isOptionExists(Constants.ADD_EVENT_SEPARATOR) ? Boolean.parseBoolean(optionHolder.validateAndGetStaticValue(Constants.ADD_EVENT_SEPARATOR)) : !mapType.equalsIgnoreCase("csv"); }
public StoreConfig generateStoreConfig(Annotation storeAnnotation) throws DesignGenerationException { String type = null; Map<String, String> options = new HashMap<>(); for (Element element : storeAnnotation.getElements()) { if (element.getKey().equalsIgnoreCase("TYPE")) { type = element.getValue(); } else { options.put(element.getKey(), element.getValue()); } } if (type == null) { throw new DesignGenerationException("Can not find type for the Store"); } StoreConfig storeConfig = new StoreConfig(type, options); preserveAndBindCodeSegment(storeAnnotation, storeConfig); return storeConfig; } }
/** * 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 SiddhiApp addQuery(Query query) { if (query == null) { throw new SiddhiAppValidationException("Query should not be null"); } String name = null; Element element = AnnotationHelper.getAnnotationElement(SiddhiConstants.ANNOTATION_INFO, SiddhiConstants .ANNOTATION_ELEMENT_NAME, query.getAnnotations()); if (element != null) { name = element.getValue(); } if (name != null && executionElementNameList.contains(name)) { throw new SiddhiAppValidationException( "Cannot add Query as another Execution Element already uses " + "its name=" + name, element.getQueryContextStartIndex(), element.getQueryContextEndIndex()); } executionElementNameList.add(name); this.executionElementList.add(query); return this; }
/** * Obtain query name of each siddhi app elements */ private void loadQueryName(List<Annotation> queryAnnotations, SiddhiAppElements siddhiAppElements) { for (Annotation annotation : queryAnnotations) { for (Element element : annotation.getElements()) { siddhiAppElements.setQueryName(element.getValue()); } } if (siddhiAppElements.getQueryName() == null) { siddhiAppElements.setQueryName(Constants.DEFAULT_QUERY_NAME); } }
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); }