Search in sources :

Example 61 with org.wso2.carbon.humantask.client.api.types

use of org.wso2.carbon.humantask.client.api.types in project carbon-apimgt by wso2.

the class ApiImportExportManager method getAPIDetails.

/**
 * Retrieves all API details of the APIs for the given search query. API details consist of:
 *      1. API {@link org.wso2.carbon.apimgt.core.models.API}
 *      2. Document Info {@link org.wso2.carbon.apimgt.core.models.DocumentInfo}
 *      3. Document Content {@link org.wso2.carbon.apimgt.core.models.DocumentContent}
 *      4. Swagger Definition
 *      5. Gateway Definition
 *      6. Thumbnail content
 *
 * @param limit number of max results
 * @param offset starting location when returning a limited set of results
 * @param query searchQuery
 * @return {@link APIDetails} instance
 * @throws APIManagementException if an error occurs while retrieving API details
 */
public Set<APIDetails> getAPIDetails(Integer limit, Integer offset, String query) throws APIManagementException {
    Set<APIDetails> apiDetailSet = new HashSet<>();
    // search for APIs
    List<API> apis = apiPublisher.searchAPIs(limit, offset, query);
    if (apis == null || apis.isEmpty()) {
        // no APIs found, return
        return apiDetailSet;
    }
    // iterate and collect all information
    for (API api : apis) {
        api = apiPublisher.getAPIbyUUID(api.getId());
        // get endpoints at API Level
        Map<String, Endpoint> endpoints = api.getEndpoint();
        if (endpoints.isEmpty()) {
            log.error("No Endpoints found for api: " + api.getName() + ", version: " + api.getVersion());
        // skip this API
        // continue;
        }
        Set<Endpoint> endpointSet = new HashSet<>();
        for (Map.Entry<String, Endpoint> endpointEntry : endpoints.entrySet()) {
            if (APIMgtConstants.GLOBAL_ENDPOINT.equals(endpointEntry.getValue().getApplicableLevel())) {
                Endpoint endpoint = new Endpoint.Builder(apiPublisher.getEndpoint(endpointEntry.getValue().getId())).id("").build();
                endpoints.replace(endpointEntry.getKey(), endpoint);
                endpointSet.add(endpoint);
            }
        }
        // get Endpoints at Resource Level
        Map<String, UriTemplate> uriTemplateMap = api.getUriTemplates();
        uriTemplateMap.forEach((k, v) -> {
            UriTemplate.UriTemplateBuilder uriTemplateBuilder = new UriTemplate.UriTemplateBuilder(v);
            Map<String, Endpoint> resourceEndpoints = uriTemplateBuilder.getEndpoint();
            resourceEndpoints.forEach((type, value) -> {
                Endpoint endpoint = null;
                if (APIMgtConstants.GLOBAL_ENDPOINT.equals(value.getApplicableLevel())) {
                    try {
                        endpoint = new Endpoint.Builder(apiPublisher.getEndpoint(value.getId())).id("").build();
                        endpointSet.add(endpoint);
                    } catch (APIManagementException e) {
                        log.error("Error in getting endpoints for Resource: " + v.getTemplateId(), e);
                    }
                } else {
                    endpoint = new Endpoint.Builder(value).id("").build();
                }
                resourceEndpoints.replace(type, endpoint);
            });
            uriTemplateMap.replace(k, uriTemplateBuilder.endpoint(resourceEndpoints).build());
        });
        api = new API.APIBuilder(api).endpoint(endpoints).uriTemplates(uriTemplateMap).build();
        // get swagger definition
        String swaggerDefinition;
        try {
            swaggerDefinition = apiPublisher.getApiSwaggerDefinition(api.getId());
        } catch (APIManagementException e) {
            log.error("Error in getting Swagger configuration for api: " + api.getName() + ", version: " + api.getVersion(), e);
            // skip this API
            continue;
        }
        // get gateway configuration
        String gatewayConfig;
        try {
            gatewayConfig = apiPublisher.getApiGatewayConfig(api.getId());
        } catch (APIManagementException e) {
            log.error("Error in getting gateway configuration for api: " + api.getName() + ", version: " + api.getVersion(), e);
            // skip this API
            continue;
        }
        // get doc information
        List<DocumentInfo> documentInfo = null;
        try {
            documentInfo = apiPublisher.getAllDocumentation(api.getId(), 0, Integer.MAX_VALUE);
        } catch (APIManagementException e) {
            log.error("Error in getting documentation content for api: " + api.getName() + ", version: " + api.getVersion(), e);
        // no need to skip the API as docs don't affect API functionality
        }
        Set<DocumentContent> documentContents = new HashSet<>();
        if (documentInfo != null && !documentInfo.isEmpty()) {
            // iterate and collect document content
            for (DocumentInfo aDocumentInfo : documentInfo) {
                try {
                    documentContents.add(apiPublisher.getDocumentationContent(aDocumentInfo.getId()));
                } catch (APIManagementException e) {
                    log.error("Error in getting documentation content for api: " + api.getName() + ", version: " + api.getVersion() + ", doc id: " + aDocumentInfo.getId(), e);
                // no need to skip the API as docs don't affect API functionality
                }
            }
        }
        // get thumbnail
        InputStream thumbnailStream = null;
        try {
            thumbnailStream = apiPublisher.getThumbnailImage(api.getId());
        } catch (APIManagementException e) {
            log.error("Error in getting thumbnail for api: " + api.getName() + ", version: " + api.getVersion(), e);
        // no need to skip the API as thumbnail don't affect API functionality
        }
        // search operation returns a summary of APIs, need to get all details of APIs
        APIDetails apiDetails = new APIDetails(api, swaggerDefinition);
        apiDetails.setGatewayConfiguration(gatewayConfig);
        apiDetails.setEndpoints(endpointSet);
        if (documentInfo != null && !documentInfo.isEmpty()) {
            apiDetails.addDocumentInformation(documentInfo);
        }
        if (!documentContents.isEmpty()) {
            apiDetails.addDocumentContents(documentContents);
        }
        if (thumbnailStream != null) {
            apiDetails.setThumbnailStream(thumbnailStream);
        }
        apiDetailSet.add(apiDetails);
    }
    return apiDetailSet;
}
Also used : InputStream(java.io.InputStream) APIDetails(org.wso2.carbon.apimgt.core.models.APIDetails) UriTemplate(org.wso2.carbon.apimgt.core.models.UriTemplate) Endpoint(org.wso2.carbon.apimgt.core.models.Endpoint) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) DocumentContent(org.wso2.carbon.apimgt.core.models.DocumentContent) API(org.wso2.carbon.apimgt.core.models.API) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) DocumentInfo(org.wso2.carbon.apimgt.core.models.DocumentInfo)

Example 62 with org.wso2.carbon.humantask.client.api.types

use of org.wso2.carbon.humantask.client.api.types in project siddhi by wso2.

the class QueryParser method parse.

/**
 * Parse a query and return corresponding QueryRuntime.
 *
 * @param query                    query to be parsed.
 * @param siddhiAppContext         associated Siddhi app context.
 * @param streamDefinitionMap      keyvalue containing user given stream definitions.
 * @param tableDefinitionMap       keyvalue containing table definitions.
 * @param windowDefinitionMap      keyvalue containing window definition map.
 * @param aggregationDefinitionMap keyvalue containing aggregation definition map.
 * @param tableMap                 keyvalue containing event tables.
 * @param aggregationMap           keyvalue containing aggrigation runtimes.
 * @param windowMap                keyvalue containing event window map.
 * @param lockSynchronizer         Lock synchronizer for sync the lock across queries.
 * @param queryIndex               query index to identify unknown query by number
 * @return queryRuntime
 */
public static QueryRuntime parse(Query query, SiddhiAppContext siddhiAppContext, Map<String, AbstractDefinition> streamDefinitionMap, Map<String, AbstractDefinition> tableDefinitionMap, Map<String, AbstractDefinition> windowDefinitionMap, Map<String, AbstractDefinition> aggregationDefinitionMap, Map<String, Table> tableMap, Map<String, AggregationRuntime> aggregationMap, Map<String, Window> windowMap, LockSynchronizer lockSynchronizer, String queryIndex) {
    List<VariableExpressionExecutor> executors = new ArrayList<VariableExpressionExecutor>();
    QueryRuntime queryRuntime;
    Element nameElement = null;
    LatencyTracker latencyTracker = null;
    LockWrapper lockWrapper = null;
    try {
        nameElement = AnnotationHelper.getAnnotationElement("info", "name", query.getAnnotations());
        String queryName = null;
        if (nameElement != null) {
            queryName = nameElement.getValue();
        } else {
            queryName = "query_" + queryIndex + "_" + UUID.randomUUID().toString();
        }
        latencyTracker = QueryParserHelper.createLatencyTracker(siddhiAppContext, queryName, SiddhiConstants.METRIC_INFIX_QUERIES, null);
        OutputStream.OutputEventType outputEventType = query.getOutputStream().getOutputEventType();
        boolean outputExpectsExpiredEvents = false;
        if (outputEventType != OutputStream.OutputEventType.CURRENT_EVENTS) {
            outputExpectsExpiredEvents = true;
        }
        StreamRuntime streamRuntime = InputStreamParser.parse(query.getInputStream(), siddhiAppContext, streamDefinitionMap, tableDefinitionMap, windowDefinitionMap, aggregationDefinitionMap, tableMap, windowMap, aggregationMap, executors, latencyTracker, outputExpectsExpiredEvents, queryName);
        QuerySelector selector = SelectorParser.parse(query.getSelector(), query.getOutputStream(), siddhiAppContext, streamRuntime.getMetaComplexEvent(), tableMap, executors, queryName, SiddhiConstants.UNKNOWN_STATE);
        boolean isWindow = query.getInputStream() instanceof JoinInputStream;
        if (!isWindow && query.getInputStream() instanceof SingleInputStream) {
            for (StreamHandler streamHandler : ((SingleInputStream) query.getInputStream()).getStreamHandlers()) {
                if (streamHandler instanceof org.wso2.siddhi.query.api.execution.query.input.handler.Window) {
                    isWindow = true;
                    break;
                }
            }
        }
        Element synchronizedElement = AnnotationHelper.getAnnotationElement("synchronized", null, query.getAnnotations());
        if (synchronizedElement != null) {
            if (!("false".equalsIgnoreCase(synchronizedElement.getValue()))) {
                // Query LockWrapper does not need a unique
                lockWrapper = new LockWrapper("");
                // id since it will
                // not be passed to the LockSynchronizer.
                // LockWrapper does not have a default lock
                lockWrapper.setLock(new ReentrantLock());
            }
        } else {
            if (isWindow || !(streamRuntime instanceof SingleStreamRuntime)) {
                if (streamRuntime instanceof JoinStreamRuntime) {
                    // If at least one Window is involved in the join, use the LockWrapper of that window
                    // for the query as well.
                    // If join is between two EventWindows, sync the locks of the LockWrapper of those windows
                    // and use either of them for query.
                    MetaStateEvent metaStateEvent = (MetaStateEvent) streamRuntime.getMetaComplexEvent();
                    MetaStreamEvent[] metaStreamEvents = metaStateEvent.getMetaStreamEvents();
                    if (metaStreamEvents[0].getEventType() == EventType.WINDOW && metaStreamEvents[1].getEventType() == EventType.WINDOW) {
                        LockWrapper leftLockWrapper = windowMap.get(metaStreamEvents[0].getLastInputDefinition().getId()).getLock();
                        LockWrapper rightLockWrapper = windowMap.get(metaStreamEvents[1].getLastInputDefinition().getId()).getLock();
                        if (!leftLockWrapper.equals(rightLockWrapper)) {
                            // Sync the lock across both wrappers
                            lockSynchronizer.sync(leftLockWrapper, rightLockWrapper);
                        }
                        // Can use either leftLockWrapper or rightLockWrapper since both of them will hold the
                        // same lock internally
                        // If either of their lock is updated later, the other lock also will be update by the
                        // LockSynchronizer.
                        lockWrapper = leftLockWrapper;
                    } else if (metaStreamEvents[0].getEventType() == EventType.WINDOW) {
                        // Share the same wrapper as the query lock wrapper
                        lockWrapper = windowMap.get(metaStreamEvents[0].getLastInputDefinition().getId()).getLock();
                    } else if (metaStreamEvents[1].getEventType() == EventType.WINDOW) {
                        // Share the same wrapper as the query lock wrapper
                        lockWrapper = windowMap.get(metaStreamEvents[1].getLastInputDefinition().getId()).getLock();
                    } else {
                        // Join does not contain any Window
                        // Query LockWrapper does not need a unique
                        lockWrapper = new LockWrapper("");
                        // id since
                        // it will not be passed to the LockSynchronizer.
                        // LockWrapper does not have a default lock
                        lockWrapper.setLock(new ReentrantLock());
                    }
                } else {
                    lockWrapper = new LockWrapper("");
                    lockWrapper.setLock(new ReentrantLock());
                }
            }
        }
        OutputRateLimiter outputRateLimiter = OutputParser.constructOutputRateLimiter(query.getOutputStream().getId(), query.getOutputRate(), query.getSelector().getGroupByList().size() != 0, isWindow, siddhiAppContext.getScheduledExecutorService(), siddhiAppContext, queryName);
        if (outputRateLimiter instanceof WrappedSnapshotOutputRateLimiter) {
            selector.setBatchingEnabled(false);
        }
        siddhiAppContext.addEternalReferencedHolder(outputRateLimiter);
        OutputCallback outputCallback = OutputParser.constructOutputCallback(query.getOutputStream(), streamRuntime.getMetaComplexEvent().getOutputStreamDefinition(), tableMap, windowMap, siddhiAppContext, !(streamRuntime instanceof SingleStreamRuntime), queryName);
        QueryParserHelper.reduceMetaComplexEvent(streamRuntime.getMetaComplexEvent());
        QueryParserHelper.updateVariablePosition(streamRuntime.getMetaComplexEvent(), executors);
        QueryParserHelper.initStreamRuntime(streamRuntime, streamRuntime.getMetaComplexEvent(), lockWrapper, queryName);
        selector.setEventPopulator(StateEventPopulatorFactory.constructEventPopulator(streamRuntime.getMetaComplexEvent()));
        queryRuntime = new QueryRuntime(query, siddhiAppContext, streamRuntime, selector, outputRateLimiter, outputCallback, streamRuntime.getMetaComplexEvent(), lockWrapper != null, queryName);
        if (outputRateLimiter instanceof WrappedSnapshotOutputRateLimiter) {
            selector.setBatchingEnabled(false);
            ((WrappedSnapshotOutputRateLimiter) outputRateLimiter).init(streamRuntime.getMetaComplexEvent().getOutputStreamDefinition().getAttributeList().size(), selector.getAttributeProcessorList(), streamRuntime.getMetaComplexEvent());
        }
        outputRateLimiter.init(siddhiAppContext, lockWrapper, queryName);
    } catch (DuplicateDefinitionException e) {
        if (nameElement != null) {
            throw new DuplicateDefinitionException(e.getMessageWithOutContext() + ", when creating query " + nameElement.getValue(), e, e.getQueryContextStartIndex(), e.getQueryContextEndIndex(), siddhiAppContext.getName(), siddhiAppContext.getSiddhiAppString());
        } else {
            throw new DuplicateDefinitionException(e.getMessage(), e, e.getQueryContextStartIndex(), e.getQueryContextEndIndex(), siddhiAppContext.getName(), siddhiAppContext.getSiddhiAppString());
        }
    } catch (Throwable t) {
        ExceptionUtil.populateQueryContext(t, query, siddhiAppContext);
        throw t;
    }
    return queryRuntime;
}
Also used : Element(org.wso2.siddhi.query.api.annotation.Element) OutputStream(org.wso2.siddhi.query.api.execution.query.output.stream.OutputStream) ArrayList(java.util.ArrayList) OutputCallback(org.wso2.siddhi.core.query.output.callback.OutputCallback) QueryRuntime(org.wso2.siddhi.core.query.QueryRuntime) JoinInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.JoinInputStream) SingleInputStream(org.wso2.siddhi.query.api.execution.query.input.stream.SingleInputStream) WrappedSnapshotOutputRateLimiter(org.wso2.siddhi.core.query.output.ratelimit.snapshot.WrappedSnapshotOutputRateLimiter) OutputRateLimiter(org.wso2.siddhi.core.query.output.ratelimit.OutputRateLimiter) StreamHandler(org.wso2.siddhi.query.api.execution.query.input.handler.StreamHandler) SingleStreamRuntime(org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime) StreamRuntime(org.wso2.siddhi.core.query.input.stream.StreamRuntime) JoinStreamRuntime(org.wso2.siddhi.core.query.input.stream.join.JoinStreamRuntime) Window(org.wso2.siddhi.core.window.Window) ReentrantLock(java.util.concurrent.locks.ReentrantLock) DuplicateDefinitionException(org.wso2.siddhi.query.api.exception.DuplicateDefinitionException) SingleStreamRuntime(org.wso2.siddhi.core.query.input.stream.single.SingleStreamRuntime) JoinStreamRuntime(org.wso2.siddhi.core.query.input.stream.join.JoinStreamRuntime) VariableExpressionExecutor(org.wso2.siddhi.core.executor.VariableExpressionExecutor) QuerySelector(org.wso2.siddhi.core.query.selector.QuerySelector) LockWrapper(org.wso2.siddhi.core.util.lock.LockWrapper) MetaStateEvent(org.wso2.siddhi.core.event.state.MetaStateEvent) LatencyTracker(org.wso2.siddhi.core.util.statistics.LatencyTracker) WrappedSnapshotOutputRateLimiter(org.wso2.siddhi.core.query.output.ratelimit.snapshot.WrappedSnapshotOutputRateLimiter) MetaStreamEvent(org.wso2.siddhi.core.event.stream.MetaStreamEvent)

Example 63 with org.wso2.carbon.humantask.client.api.types

use of org.wso2.carbon.humantask.client.api.types in project siddhi by wso2.

the class DefinitionParserHelper method constructOptionHolder.

private static OptionHolder constructOptionHolder(StreamDefinition streamDefinition, Annotation annotation, org.wso2.siddhi.annotation.Extension extension, String[] supportedDynamicOptions) {
    List<String> supportedDynamicOptionList = new ArrayList<>();
    if (supportedDynamicOptions != null) {
        supportedDynamicOptionList = Arrays.asList(supportedDynamicOptions);
    }
    Map<String, String> options = new HashMap<String, String>();
    Map<String, String> dynamicOptions = new HashMap<String, String>();
    for (Element element : annotation.getElements()) {
        if (Pattern.matches("(.*?)\\{\\{.*?\\}\\}(.*?)", element.getValue())) {
            if (supportedDynamicOptionList.contains(element.getKey())) {
                dynamicOptions.put(element.getKey(), element.getValue());
            } else {
                throw new SiddhiAppCreationException("'" + element.getKey() + "' is not a supported " + "DynamicOption " + "for the Extension '" + extension.namespace() + ":" + extension.name() + "', it only supports following as its DynamicOptions: " + supportedDynamicOptionList, annotation.getQueryContextStartIndex(), annotation.getQueryContextEndIndex());
            }
        } else {
            options.put(element.getKey(), element.getValue());
        }
    }
    return new OptionHolder(streamDefinition, options, dynamicOptions, extension);
}
Also used : HashMap(java.util.HashMap) OptionHolder(org.wso2.siddhi.core.util.transport.OptionHolder) SiddhiAppCreationException(org.wso2.siddhi.core.exception.SiddhiAppCreationException) Element(org.wso2.siddhi.query.api.annotation.Element) ArrayList(java.util.ArrayList)

Example 64 with org.wso2.carbon.humantask.client.api.types

use of org.wso2.carbon.humantask.client.api.types in project siddhi by wso2.

the class DefinitionParserHelper method addEventSource.

public static void addEventSource(StreamDefinition streamDefinition, ConcurrentMap<String, List<Source>> eventSourceMap, SiddhiAppContext siddhiAppContext) {
    for (Annotation sourceAnnotation : streamDefinition.getAnnotations()) {
        if (SiddhiConstants.ANNOTATION_SOURCE.equalsIgnoreCase(sourceAnnotation.getName())) {
            sourceAnnotation = updateAnnotationRef(sourceAnnotation, SiddhiConstants.NAMESPACE_SOURCE, siddhiAppContext);
            Annotation mapAnnotation = AnnotationHelper.getAnnotation(SiddhiConstants.ANNOTATION_MAP, sourceAnnotation.getAnnotations());
            if (mapAnnotation == null) {
                mapAnnotation = Annotation.annotation(SiddhiConstants.ANNOTATION_MAP).element(SiddhiConstants.ANNOTATION_ELEMENT_TYPE, "passThrough");
            }
            final String sourceType = sourceAnnotation.getElement(SiddhiConstants.ANNOTATION_ELEMENT_TYPE);
            final String mapType = mapAnnotation.getElement(SiddhiConstants.ANNOTATION_ELEMENT_TYPE);
            if (sourceType != null && mapType != null) {
                SourceHandlerManager sourceHandlerManager = siddhiAppContext.getSiddhiContext().getSourceHandlerManager();
                SourceHandler sourceHandler = null;
                if (sourceHandlerManager != null) {
                    sourceHandler = sourceHandlerManager.generateSourceHandler();
                }
                // load input transport extension
                Extension sourceExtension = constructExtension(streamDefinition, SiddhiConstants.ANNOTATION_SOURCE, sourceType, sourceAnnotation, SiddhiConstants.NAMESPACE_SOURCE);
                Source source = (Source) SiddhiClassLoader.loadExtensionImplementation(sourceExtension, SourceExecutorExtensionHolder.getInstance(siddhiAppContext));
                ConfigReader configReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(sourceExtension.getNamespace(), sourceExtension.getName());
                // load input mapper extension
                Extension mapperExtension = constructExtension(streamDefinition, SiddhiConstants.ANNOTATION_MAP, mapType, sourceAnnotation, SiddhiConstants.NAMESPACE_SOURCE_MAPPER);
                SourceMapper sourceMapper = (SourceMapper) SiddhiClassLoader.loadExtensionImplementation(mapperExtension, SourceMapperExecutorExtensionHolder.getInstance(siddhiAppContext));
                ConfigReader mapperConfigReader = siddhiAppContext.getSiddhiContext().getConfigManager().generateConfigReader(mapperExtension.getNamespace(), mapperExtension.getName());
                validateSourceMapperCompatibility(streamDefinition, sourceType, mapType, source, sourceMapper, sourceAnnotation);
                OptionHolder sourceOptionHolder = constructOptionHolder(streamDefinition, sourceAnnotation, source.getClass().getAnnotation(org.wso2.siddhi.annotation.Extension.class), null);
                OptionHolder mapOptionHolder = constructOptionHolder(streamDefinition, mapAnnotation, sourceMapper.getClass().getAnnotation(org.wso2.siddhi.annotation.Extension.class), null);
                AttributesHolder attributesHolder = getAttributeMappings(mapAnnotation, mapType, streamDefinition);
                String[] transportPropertyNames = getTransportPropertyNames(attributesHolder);
                try {
                    source.init(sourceType, sourceOptionHolder, sourceMapper, transportPropertyNames, configReader, mapType, mapOptionHolder, attributesHolder.payloadMappings, attributesHolder.transportMappings, mapperConfigReader, sourceHandler, streamDefinition, siddhiAppContext);
                } catch (Throwable t) {
                    ExceptionUtil.populateQueryContext(t, sourceAnnotation, siddhiAppContext);
                    throw t;
                }
                siddhiAppContext.getSnapshotService().addSnapshotable(source.getStreamDefinition().getId(), source);
                if (sourceHandlerManager != null) {
                    sourceHandlerManager.registerSourceHandler(sourceHandler.getElementId(), sourceHandler);
                    siddhiAppContext.getSnapshotService().addSnapshotable(streamDefinition.getId(), sourceHandler);
                }
                List<Source> eventSources = eventSourceMap.get(streamDefinition.getId());
                if (eventSources == null) {
                    eventSources = new ArrayList<>();
                    eventSources.add(source);
                    eventSourceMap.put(streamDefinition.getId(), eventSources);
                } else {
                    eventSources.add(source);
                }
            } else {
                throw new SiddhiAppCreationException("Both @Sink(type=) and @map(type=) are required.", sourceAnnotation.getQueryContextStartIndex(), sourceAnnotation.getQueryContextEndIndex());
            }
        }
    }
}
Also used : SourceHandler(org.wso2.siddhi.core.stream.input.source.SourceHandler) SourceHandlerManager(org.wso2.siddhi.core.stream.input.source.SourceHandlerManager) SiddhiAppCreationException(org.wso2.siddhi.core.exception.SiddhiAppCreationException) ConfigReader(org.wso2.siddhi.core.util.config.ConfigReader) Annotation(org.wso2.siddhi.query.api.annotation.Annotation) Source(org.wso2.siddhi.core.stream.input.source.Source) Extension(org.wso2.siddhi.query.api.extension.Extension) OptionHolder(org.wso2.siddhi.core.util.transport.OptionHolder) SourceMapper(org.wso2.siddhi.core.stream.input.source.SourceMapper)

Example 65 with org.wso2.carbon.humantask.client.api.types

use of org.wso2.carbon.humantask.client.api.types in project siddhi by wso2.

the class DistinctCountAttributeAggregatorTestCase method distinctCountTest.

@Test
public void distinctCountTest() throws InterruptedException {
    log.info("Distinct Count TestCase");
    SiddhiManager siddhiManager = new SiddhiManager();
    String inStreamDefinition = "" + "define stream inputStream (eventId string, userID string, pageID string); ";
    String query = "" + "@info(name = 'query1') " + "from inputStream#window.time(5 sec) " + "select userID, pageID, distinctCount(pageID) as distinctPages " + "group by userID " + "having distinctPages > 3 " + "insert into outputStream; ";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(inStreamDefinition + query);
    siddhiAppRuntime.addCallback("outputStream", new StreamCallback() {

        @Override
        public void receive(org.wso2.siddhi.core.event.Event[] events) {
            for (org.wso2.siddhi.core.event.Event event : events) {
                AssertJUnit.assertEquals("User ID", "USER_1", event.getData(0));
                AssertJUnit.assertEquals("Page ID", "WEB_PAGE_4", event.getData(1));
                AssertJUnit.assertEquals("Distinct Pages", 4L, event.getData(2));
                count++;
            }
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("inputStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "E001", "USER_1", "WEB_PAGE_1" });
    Thread.sleep(1000);
    inputHandler.send(new Object[] { "E002", "USER_2", "WEB_PAGE_1" });
    Thread.sleep(1000);
    // 1st Event in window
    inputHandler.send(new Object[] { "E003", "USER_1", "WEB_PAGE_2" });
    Thread.sleep(1000);
    inputHandler.send(new Object[] { "E004", "USER_2", "WEB_PAGE_2" });
    Thread.sleep(1000);
    // 2nd Event in window
    inputHandler.send(new Object[] { "E005", "USER_1", "WEB_PAGE_3" });
    Thread.sleep(1000);
    // 3rd Event in window
    inputHandler.send(new Object[] { "E006", "USER_1", "WEB_PAGE_1" });
    Thread.sleep(1000);
    // 4th Event in window
    inputHandler.send(new Object[] { "E007", "USER_1", "WEB_PAGE_4" });
    Thread.sleep(1000);
    inputHandler.send(new Object[] { "E008", "USER_2", "WEB_PAGE_2" });
    Thread.sleep(1000);
    inputHandler.send(new Object[] { "E009", "USER_1", "WEB_PAGE_1" });
    Thread.sleep(1000);
    inputHandler.send(new Object[] { "E010", "USER_2", "WEB_PAGE_1" });
    Thread.sleep(2000);
    siddhiAppRuntime.shutdown();
    AssertJUnit.assertEquals("Event count", 1, count);
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) StreamCallback(org.wso2.siddhi.core.stream.output.StreamCallback) Test(org.testng.annotations.Test)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)18 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)13 HashMap (java.util.HashMap)12 Query (javax.persistence.Query)9 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)9 ArrayList (java.util.ArrayList)8 Map (java.util.Map)8 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)5 TAttachment (org.wso2.carbon.attachment.mgt.skeleton.types.TAttachment)5 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)4 AttachmentDAO (org.wso2.carbon.attachment.mgt.core.dao.AttachmentDAO)4 AttachmentMgtException (org.wso2.carbon.attachment.mgt.core.exceptions.AttachmentMgtException)4 AttachmentMgtException (org.wso2.carbon.attachment.mgt.skeleton.AttachmentMgtException)4 Test (org.testng.annotations.Test)3 ConfigurationException (org.wso2.carbon.config.ConfigurationException)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 File (java.io.File)2 PrintStream (java.io.PrintStream)2 Connection (java.sql.Connection)2 List (java.util.List)2