org.wso2.carbon.databridge.agent.DataPublisher Java Examples
The following examples show how to use
org.wso2.carbon.databridge.agent.DataPublisher.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Wso2EventClient.java From product-cep with Apache License 2.0 | 6 votes |
public static void publish(String protocol, String host, String port, String username, String password, String streamId,String dataFileName, String testCaseFolderName, StreamDefinition streamDefinition, int events, int delay) throws MalformedStreamDefinitionException, StreamDefinitionException, DifferentStreamDefinitionAlreadyDefinedException, MalformedURLException, NoStreamDefinitionExistException, AuthenticationException, TransportException, SocketException, DataEndpointAgentConfigurationException, DataEndpointException, DataEndpointAuthenticationException, DataEndpointConfigurationException { String relativeFilePath = getTestDataFileLocation(testCaseFolderName, dataFileName); KeyStoreUtil.setTrustStoreParams(); //create data publisher DataPublisher dataPublisher = new DataPublisher(protocol, "tcp://" + host + ":" + port, null, username, password); //Publish event for a valid stream publishEvents(dataPublisher, streamDefinition, relativeFilePath, events, delay); dataPublisher.shutdown(); }
Example #2
Source File: Client.java From product-cep with Apache License 2.0 | 6 votes |
private static void sendWarmUpEvents(DataPublisher dataPublisher, long warmUpCount) { long counter = 0; Random randomGenerator = new Random(); String streamId = "org.wso2.event.sensor.stream:1.0.0"; while (counter < warmUpCount) { boolean isPowerSaveEnabled = randomGenerator.nextBoolean(); int sensorId = randomGenerator.nextInt(); double longitude = randomGenerator.nextDouble(); double latitude = randomGenerator.nextDouble(); float humidity = randomGenerator.nextFloat(); double sensorValue = randomGenerator.nextDouble(); Event event = new Event(streamId, System.currentTimeMillis(), new Object[]{System.currentTimeMillis(), isPowerSaveEnabled, sensorId, "warmup-" + counter}, new Object[]{longitude, latitude}, new Object[]{humidity, sensorValue}); dataPublisher.publish(event); counter++; } }
Example #3
Source File: APIMgtWorkflowDataPublisher.java From carbon-apimgt with Apache License 2.0 | 6 votes |
public APIMgtWorkflowDataPublisher() { if (!enabled || skipEventReceiverConnection || analyticsConfig.isSkipWorkFlowEventReceiverConnection()) { return; } if (log.isDebugEnabled()) { log.debug("Initializing APIMgtUsageDataBridgeDataPublisher"); } wfStreamName = config.getFirstProperty(APIConstants.API_WF_STREAM_NAME); wfStreamVersion = config.getFirstProperty(APIConstants.API_WF_STREAM_VERSION); if (wfStreamName == null || wfStreamVersion == null) { log.error("Workflow stream name or version is null. Check api-manager.xml"); } dataPublisherMap = new ConcurrentHashMap<String, DataPublisher>(); this.dataPublisher = getDataPublisher(); }
Example #4
Source File: HttpdLogAgent.java From product-cep with Apache License 2.0 | 6 votes |
private static void publishLogEvents(DataPublisher dataPublisher, String streamId) throws FileNotFoundException { Scanner scanner = new Scanner(new FileInputStream(SAMPLE_LOG_PATH)); try { int i = 1; while (scanner.hasNextLine()) { System.out.println("Publish log event : " + i); String aLog = scanner.nextLine(); Event event = new Event(streamId, System.currentTimeMillis(), new Object[]{"external"}, null, new Object[]{aLog}); dataPublisher.publish(event); i++; } } finally { scanner.close(); } }
Example #5
Source File: UploadedUsagePublisherTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Test public void run() throws Exception { PowerMockito.mockStatic(ZIPUtils.class); PowerMockito.mockStatic(FileUtils.class); PowerMockito.mockStatic(UsagePublisherUtils.class); DataPublisher dataPublisher = Mockito.mock(DataPublisher.class); String fileDir = System.getProperty(Constants.CARBON_HOME) + File.separator + Constants.API_USAGE_DATA + File.separator + compressedFileName; InputStream anyInputStream = new FileInputStream(fileDir); PowerMockito.mockStatic(UploadedUsageFileInfoDAO.class); PowerMockito.when(UploadedUsageFileInfoDAO.class, "getFileContent", any(UploadedFileInfoDTO.class)) .thenReturn(anyInputStream); PowerMockito.doNothing() .when(UploadedUsageFileInfoDAO.class, "updateCompletion", any(UploadedFileInfoDTO.class)); PowerMockito.when(UsagePublisherUtils.getDataPublisher()).thenReturn(dataPublisher); UploadedFileInfoDTO infoDTO = new UploadedFileInfoDTO(tenantDomain, compressedFileName, 121232); UploadedUsagePublisher uploadedUsagePublisher = new UploadedUsagePublisher(infoDTO); uploadedUsagePublisher.run(); }
Example #6
Source File: UploadedUsagePublisherTest.java From carbon-apimgt with Apache License 2.0 | 6 votes |
@Test public void run_throwsExceptionWhileDecompressingFile() throws Exception { PowerMockito.mockStatic(ZIPUtils.class); PowerMockito.mockStatic(FileUtils.class); PowerMockito.mockStatic(UsagePublisherUtils.class); DataPublisher dataPublisher = Mockito.mock(DataPublisher.class); PowerMockito.when(UsagePublisherUtils.getDataPublisher()).thenReturn(dataPublisher); PowerMockito.mockStatic(UploadedUsageFileInfoDAO.class); InputStream anyInputStream = new ByteArrayInputStream("test data".getBytes()); PowerMockito.when(UploadedUsageFileInfoDAO.class, "getFileContent", any(UploadedFileInfoDTO.class)) .thenReturn(anyInputStream); PowerMockito.doNothing() .when(UploadedUsageFileInfoDAO.class, "updateCompletion", any(UploadedFileInfoDTO.class)); UploadedFileInfoDTO infoDTO = new UploadedFileInfoDTO(tenantDomain, compressedFileName, 1213232); UploadedUsagePublisher uploadedUsagePublisher = new UploadedUsagePublisher(infoDTO); uploadedUsagePublisher.run(); }
Example #7
Source File: HTTPMonitoringDataPublisher.java From msf4j with Apache License 2.0 | 5 votes |
private void init(DasConfig dasConfig) { if (logger.isInfoEnabled()) { logger.info("Initializing HTTP Monitoring Data Publisher"); } String type = dasConfig.getType(); String receiverURL = dasConfig.getReceiverURL(); String authURL = dasConfig.getAuthURL(); String username = dasConfig.getUsername(); String password = dasConfig.getPassword(); String dataAgentConfigPath = dasConfig.getDataAgentConfigPath(); if (type == null) { throw new IllegalArgumentException("Type cannot be null"); } if (receiverURL == null) { throw new IllegalArgumentException("Data Receiver URL cannot be null"); } if (username == null) { throw new IllegalArgumentException("Username cannot be null"); } if (password == null) { throw new IllegalArgumentException("Password cannot be null"); } if (dataAgentConfigPath == null) { throw new IllegalArgumentException("Data Agent Configuration Path cannot be null"); } AgentHolder.setConfigPath(dataAgentConfigPath); arbitraryAttributes = SystemVariableUtil.getArbitraryAttributes(); try { dataPublisher = new DataPublisher(type, receiverURL, authURL, username, password); } catch (DataEndpointAgentConfigurationException | DataEndpointException | DataEndpointConfigurationException | DataEndpointAuthenticationException | TransportException e) { throw new IllegalStateException("Error when initializing the Data Publisher", e); } }
Example #8
Source File: APIMgtWorkflowDataPublisherTestCase.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testGetPublisherFromMapDomainNotExists() throws Exception { DataPublisher dataPublisher = Mockito.mock(DataPublisher.class); new APIMgtWorkflowDataPublisher(); APIMgtWorkflowDataPublisher.addDataPublisher("bar.com", dataPublisher); DataPublisher dataPublisherFromMap = APIMgtWorkflowDataPublisher.getDataPublisher("foo.com"); Assert.assertNull(dataPublisherFromMap); }
Example #9
Source File: APIMgtWorkflowDataPublisherTestCase.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void testGetPublisherFromMapDomainExists() throws Exception { DataPublisher dataPublisher = Mockito.mock(DataPublisher.class); new APIMgtWorkflowDataPublisher(); APIMgtWorkflowDataPublisher.addDataPublisher("foo.com", dataPublisher); DataPublisher dataPublisherFromMap = APIMgtWorkflowDataPublisher.getDataPublisher("foo.com"); Assert.assertNotNull(dataPublisherFromMap); }
Example #10
Source File: APIMgtWorkflowDataPublisherTestCase.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test(expected = DataPublisherAlreadyExistsException.class) public void testAddPublisherToMapDomainExists() throws Exception { APIMgtWorkflowDataPublisher apiMgtWorkflowDataPublisher = new APIMgtWorkflowDataPublisher(); DataPublisher dataPublisher = Mockito.mock(DataPublisher.class); APIMgtWorkflowDataPublisher.addDataPublisher("foo.com", dataPublisher); APIMgtWorkflowDataPublisher.addDataPublisher("foo.com", dataPublisher); }
Example #11
Source File: APIMgtWorkflowDataPublisherTestCase.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Before public void setup() throws Exception { PowerMockito.mockStatic(ServiceReferenceHolder.class); PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder); Mockito.when(serviceReferenceHolder.getAPIManagerConfigurationService()).thenReturn(apiManagerConfigurationService); Mockito.when(apiManagerConfigurationService.getAPIManagerConfiguration()).thenReturn(apiManagerConfiguration); Mockito.when(apiManagerConfigurationService.getAPIAnalyticsConfiguration()).thenReturn(apiManagerAnalyticsConfiguration); PowerMockito.mockStatic(APIUtil.class); PowerMockito.when(APIUtil.isAnalyticsEnabled()).thenReturn(true); PowerMockito.whenNew(DataPublisher.class).withAnyArguments().thenReturn(dataPublisher); }
Example #12
Source File: APIMgtWorkflowDataPublisher.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Adds a DataPublisher to the data publisher map. * * @param tenantDomain - The tenant domain under which the data publisher will be registered. * @param dataPublisher - Instance of the DataPublisher * @throws org.wso2.carbon.apimgt.impl.workflow.events.DataPublisherAlreadyExistsException * - If a data publisher has already been registered under the * tenant domain */ public static void addDataPublisher(String tenantDomain, DataPublisher dataPublisher) throws DataPublisherAlreadyExistsException { if (dataPublisherMap.containsKey(tenantDomain)) { throw new DataPublisherAlreadyExistsException("A DataPublisher has already been created for the tenant " + tenantDomain); } dataPublisherMap.put(tenantDomain, dataPublisher); }
Example #13
Source File: APIMgtWorkflowDataPublisher.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Fetch the data publisher which has been registered under the tenant domain. * * @param tenantDomain - The tenant domain under which the data publisher is registered * @return - Instance of the DataPublisher which was registered. Null if not registered. */ public static DataPublisher getDataPublisher(String tenantDomain) { if (dataPublisherMap.containsKey(tenantDomain)) { return dataPublisherMap.get(tenantDomain); } return null; }
Example #14
Source File: UsageComponent.java From carbon-apimgt with Apache License 2.0 | 5 votes |
/** * Fetch the data publisher which has been registered under the tenant domain. * @param tenantDomain - The tenant domain under which the data publisher is registered * @return - Instance of the LoadBalancingDataPublisher which was registered. Null if not registered. */ public static DataPublisher getDataPublisher(String tenantDomain) { if (dataPublisherMap.containsKey(tenantDomain)) { return dataPublisherMap.get(tenantDomain); } return null; }
Example #15
Source File: UsageComponent.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Activate protected void activate(ComponentContext ctx) { try { DataPublisherUtil.setEnabledMetering(Boolean.parseBoolean(ServerConfiguration.getInstance().getFirstProperty("EnableMetering"))); dataPublisherMap = new ConcurrentHashMap<String, DataPublisher>(); log.debug("API Management Usage Publisher bundle is activated "); } catch (Exception e) { log.error("API Management Usage Publisher bundle ", e); } }
Example #16
Source File: DataProcessAndPublishingAgentTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void setDataReference() throws Exception { ThrottleProperties throttleProperties = new ThrottleProperties(); DataPublisher dataPublisher = Mockito.mock(DataPublisher.class); Mockito.when(dataPublisher.tryPublish(Mockito.any(Event.class))).thenReturn(true); throttleProperties.setEnabled(true); DataProcessAndPublishingAgent dataProcessAndPublishingAgent = new DataProcessAndPublishingAgentWrapper (throttleProperties); AuthenticationContext authenticationContext = new AuthenticationContext(); MessageContext messageContext = Mockito.mock(Axis2MessageContext.class); org.apache.axis2.context.MessageContext axis2MsgCntxt = Mockito.mock(org.apache.axis2.context.MessageContext .class); Mockito.when(((Axis2MessageContext) messageContext).getAxis2MessageContext()).thenReturn(axis2MsgCntxt); Mockito.when(messageContext.getProperty(RESTConstants.SYNAPSE_REST_API)).thenReturn("admin--PizzaShackAPI"); VerbInfoDTO verbInfoDTO = new VerbInfoDTO(); verbInfoDTO.setContentAware(false); ArrayList<VerbInfoDTO> list = new ArrayList<VerbInfoDTO>(); list.add(verbInfoDTO); Mockito.when(messageContext.getProperty(APIConstants.VERB_INFO_DTO)).thenReturn(list); Mockito.when(axis2MsgCntxt.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS)) .thenReturn(new TreeMap<>()); Mockito.when(messageContext.getProperty(RESTConstants.SYNAPSE_REST_API)).thenReturn("admin--PizzaShackAPI"); dataProcessAndPublishingAgent.setDataReference(applicationLevelThrottleKey, applicationLevelTier, apiLevelThrottleKey, apiLevelTier, subscriptionLevelThrottleKey, subscriptionLevelTier, resourceLevelThrottleKey, resourceLevelTier, authorizedUser, apiContext, apiVersion, appTenant, apiTenant, appId, messageContext, authenticationContext); dataProcessAndPublishingAgent.run(); }
Example #17
Source File: StockQuoteClient.java From product-cep with Apache License 2.0 | 5 votes |
public static void publish(String host, String port, String username, String password, int events) throws MalformedStreamDefinitionException, StreamDefinitionException, DifferentStreamDefinitionAlreadyDefinedException, MalformedURLException, AuthenticationException, NoStreamDefinitionExistException, org.wso2.carbon.databridge.commons.exception.AuthenticationException, TransportException, SocketException, DataEndpointAgentConfigurationException, DataEndpointException, DataEndpointAuthenticationException, DataEndpointConfigurationException { System.out.println("Starting Stock quote Agent"); KeyStoreUtil.setTrustStoreParams(); //create data publisher DataPublisher dataPublisher = new DataPublisher("tcp://" + host + ":" + port, username, password); String streamId = DataBridgeCommonsUtils.generateStreamId(STREAM_NAME1, VERSION1); //Publish event for a valid stream if (!streamId.isEmpty()) { System.out.println("Stream ID: " + streamId); while (sentEventCount < events) { dataPublisher.publish(streamId, null, null, getPayload()); sentEventCount++; System.out.println("Events published : " + sentEventCount); } try { Thread.sleep(3000); } catch (InterruptedException e) { //ignore } dataPublisher.shutdown(); } }
Example #18
Source File: UploadedUsagePublisherExecutorTaskTest.java From carbon-apimgt with Apache License 2.0 | 5 votes |
@Test public void run() throws Exception { String carbonHome = System.getProperty(Constants.CARBON_HOME); PowerMockito.mockStatic(CarbonUtils.class); PowerMockito.when(CarbonUtils.getCarbonHome()).thenReturn(carbonHome); DataPublisher dataPublisher = Mockito.mock(DataPublisher.class); Map<String, JSONArray> streamDefinitions = null; List<UploadedFileInfoDTO> uploadedFileList = new ArrayList<>(); PowerMockito.mockStatic(UsagePublisherUtils.class); PowerMockito.mockStatic(UploadedUsageFileInfoDAO.class); PowerMockito.when(UploadedUsageFileInfoDAO.getNextFilesToProcess(anyInt())).thenReturn(uploadedFileList); PowerMockito.when(UsagePublisherUtils.getDataPublisher()).thenReturn(dataPublisher); PowerMockito.when(UsagePublisherUtils.getStreamDefinitions()).thenReturn(streamDefinitions); UploadedUsagePublisherExecutorTask usagePublisherExecutorTask = new UploadedUsagePublisherExecutorTask(); usagePublisherExecutorTask.run(); }
Example #19
Source File: Client.java From product-cep with Apache License 2.0 | 5 votes |
public static void main(String[] args) { log.info(Arrays.deepToString(args)); try { log.info("Starting WSO2 Performance Test Client"); AgentHolder.setConfigPath(DataPublisherUtil.getDataAgentConfigPath()); DataPublisherUtil.setTrustStoreParams(); String protocol = args[0]; String host = args[1]; String port = args[2]; String username = args[3]; String password = args[4]; String eventCount = args[5]; String elapsedCount = args[6]; String warmUpCount = args[7]; String calcType = args[8]; //create data publisher DataPublisher dataPublisher = new DataPublisher(protocol, "tcp://" + host + ":" + port, null, username, password); //Publish event for a valid stream if ("latency".equalsIgnoreCase(calcType)) { publishEventsForLatency(dataPublisher, Long.parseLong(eventCount), Long.parseLong(elapsedCount), Long.parseLong(warmUpCount)); } else { publishEvents(dataPublisher, Long.parseLong(eventCount), Long.parseLong(elapsedCount), Long.parseLong(warmUpCount)); } dataPublisher.shutdownWithAgent(); } catch (Throwable e) { log.error(e); } }
Example #20
Source File: Client.java From product-cep with Apache License 2.0 | 5 votes |
private static void publishEvents(DataPublisher dataPublisher, long eventCount, long elapsedCount, long warmUpCount) { long counter = 0; Random randomGenerator = new Random(); String streamId = "org.wso2.event.sensor.stream:1.0.0"; long lastTime = System.currentTimeMillis(); DecimalFormat decimalFormat = new DecimalFormat("#"); while (counter < eventCount) { boolean isPowerSaveEnabled = randomGenerator.nextBoolean(); int sensorId = randomGenerator.nextInt(); double longitude = randomGenerator.nextDouble(); double latitude = randomGenerator.nextDouble(); float humidity = randomGenerator.nextFloat(); double sensorValue = randomGenerator.nextDouble(); Event event = new Event(streamId, System.currentTimeMillis(), new Object[]{System.currentTimeMillis(), isPowerSaveEnabled, sensorId, "temperature-" + counter}, new Object[]{longitude, latitude}, new Object[]{humidity, sensorValue}); dataPublisher.publish(event); if ((counter > warmUpCount) && ((counter + 1) % elapsedCount == 0)) { long currentTime = System.currentTimeMillis(); long elapsedTime = currentTime - lastTime; double throughputPerSecond = (((double) elapsedCount) / elapsedTime) * 1000; lastTime = currentTime; log.info("Sent " + elapsedCount + " sensor events in " + elapsedTime + " milliseconds with total throughput of " + decimalFormat.format(throughputPerSecond) + " events per second."); } counter++; } }
Example #21
Source File: Client.java From product-cep with Apache License 2.0 | 5 votes |
private static void publishEventsForLatency(DataPublisher dataPublisher, long eventCount, long elapsedCount, long warmUpCount) { sendWarmUpEvents(dataPublisher, warmUpCount); long counter = 0; Random randomGenerator = new Random(); String streamId = "org.wso2.event.sensor.stream:1.0.0"; while (counter < eventCount) { boolean isPowerSaveEnabled = randomGenerator.nextBoolean(); int sensorId = randomGenerator.nextInt(); double longitude = randomGenerator.nextDouble(); double latitude = randomGenerator.nextDouble(); float humidity = randomGenerator.nextFloat(); double sensorValue = randomGenerator.nextDouble(); Event event = new Event(streamId, System.currentTimeMillis(), new Object[]{System.currentTimeMillis(), isPowerSaveEnabled, sensorId, "temperature-" + counter}, new Object[]{longitude, latitude}, new Object[]{humidity, sensorValue}); dataPublisher.publish(event); log.info("Sent event " + counter + " at " + System.currentTimeMillis()); if (elapsedCount > 0) { try { Thread.sleep(elapsedCount); } catch (InterruptedException e) { e.printStackTrace(); } } counter++; } }
Example #22
Source File: APIMgtUsageDataBridgeDataPublisherTestCase.java From carbon-apimgt with Apache License 2.0 | 4 votes |
@Test public void testRequestResponseStreamPublishEvent() throws Exception { RequestResponseStreamDTO stream = new RequestResponseStreamDTO(); stream.setApiContext(CONTEXT); stream.setApiMethod(METHOD); stream.setApiName(API_NAME); stream.setApiHostname(HOST_NAME); stream.setApiCreatorTenantDomain(TENAT_DOMAIN); stream.setApiCreator(USERNAME); stream.setApiResourcePath(RESOURCE_PATH); stream.setApiResourceTemplate(""); stream.setApiTier("unlimitted"); stream.setApiVersion(API_VERSION); stream.setApplicationConsumerKey(CONSUMER_KEY); stream.setApplicationId(APP_ID); stream.setApplicationName(APP_NAME); stream.setApplicationOwner(USERNAME); stream.setBackendTime(System.currentTimeMillis()); stream.setDestination("description"); stream.setExecutionTime(new ExecutionTimeDTO()); stream.setMetaClientType(KEYTYPE); // check meta type stream.setProtocol(PROTOCOL); stream.setRequestTimestamp(System.currentTimeMillis()); stream.setResponseCacheHit(true); stream.setResponseCode(200); stream.setResponseSize(1232); stream.setServiceTime(1213); stream.setThrottledOut(false); stream.setUserAgent(USER_AGENT); stream.setUserIp("10.103.5.130"); stream.setUsername(USERNAME); stream.setUserTenantDomain(TENAT_DOMAIN); stream.setResponseTime(2233); stream.setCorrelationID(CORRELATION_ID); stream.setGatewayType(SYNAPDE_GW_LABEL); stream.setLabel("abc"); APIManagerAnalyticsConfiguration analyticsConfiguration = Mockito.mock(APIManagerAnalyticsConfiguration.class); PowerMockito.when(DataPublisherUtil.getApiManagerAnalyticsConfiguration()).thenReturn(analyticsConfiguration); PowerMockito.when(DataPublisherUtil.getHostAddress()).thenReturn("abc.com"); Mockito.when(analyticsConfiguration.getRequestStreamName()).thenReturn("org.wso2.apimgt.statistics.request"); Mockito.when(analyticsConfiguration.getRequestStreamVersion()).thenReturn("3.0.0"); Mockito.when(analyticsConfiguration.getDasReceiverUrlGroups()).thenReturn("tcp://localhost:7612"); Mockito.when(analyticsConfiguration.getDasReceiverServerUser()).thenReturn("admin"); Mockito.when(analyticsConfiguration.getDasReceiverServerPassword()).thenReturn("admin"); Mockito.when(analyticsConfiguration.getDasReceiverAuthUrlGroups()).thenReturn("ssl://localhost:7712"); DataPublisher dataPublisher = Mockito.mock(DataPublisher.class); PowerMockito.whenNew(DataPublisher.class).withAnyArguments().thenReturn(dataPublisher); //test data publish path. publisher.publishEvent(stream); // test data publishing fails due to null value in mandatory values. stream.setApplicationName(null); publisher.publishEvent(stream); }
Example #23
Source File: DataBridgePublisher.java From micro-integrator with Apache License 2.0 | 4 votes |
public static DataPublisher getDataPublisher() { if (publisher == null) { initDataPublisher(); } return publisher; }
Example #24
Source File: AnalyticStatClient.java From product-cep with Apache License 2.0 | 4 votes |
public static void publish(String host, String port, String username, String password, int events) throws MalformedStreamDefinitionException, StreamDefinitionException, DifferentStreamDefinitionAlreadyDefinedException, MalformedURLException, AuthenticationException, NoStreamDefinitionExistException, org.wso2.carbon.databridge.commons.exception.AuthenticationException, TransportException, SocketException, DataEndpointAgentConfigurationException, DataEndpointException, DataEndpointAuthenticationException, DataEndpointConfigurationException { System.out.println("Starting Statistics Agent"); KeyStoreUtil.setTrustStoreParams(); //create data publisher DataPublisher dataPublisher = new DataPublisher("tcp://" + host + ":" + port, username, password); // StreamDefinition streamDefinition = new StreamDefinition(STREAM_NAME1, VERSION1); // streamDefinition.addMetaData("ipAdd", AttributeType.STRING); // streamDefinition.addMetaData("index", AttributeType.LONG); // streamDefinition.addMetaData("timestamp", AttributeType.LONG); // streamDefinition.addMetaData("nanoTime", AttributeType.LONG); // streamDefinition.addPayloadData("userID", AttributeType.STRING); // streamDefinition.addPayloadData("searchTerms", AttributeType.STRING); // String streamId = dataPublisher.defineStream(streamDefinition); String streamId = DataBridgeCommonsUtils.generateStreamId(STREAM_NAME1, VERSION1); //Publish event for a valid stream if (!streamId.isEmpty()) { System.out.println("Stream ID: " + streamId); while (sentEventCount < events) { dataPublisher.publish(streamId, getMeta(), null, getPayload()); sentEventCount++; System.out.println("Events published : " + sentEventCount); } try { Thread.sleep(3000); } catch (InterruptedException e) { //ignore } dataPublisher.shutdown(); } }
Example #25
Source File: HttpdLogAgent.java From product-cep with Apache License 2.0 | 4 votes |
public static void main(String[] args) throws SocketException, MalformedURLException, AuthenticationException, TransportException, StreamDefinitionException, MalformedStreamDefinitionException, DifferentStreamDefinitionAlreadyDefinedException, FileNotFoundException, UnknownHostException, DataEndpointAuthenticationException, DataEndpointAgentConfigurationException, DataEndpointException, DataEndpointConfigurationException { System.out.println("Starting HttpLog Agent"); DataPublisherUtil.setTrustStoreParams(); AgentHolder.setConfigPath(DataPublisherUtil.getAgentConfigPath()); String host = args[0]; String port = args[1]; String username = args[2]; String password = args[3]; //create data publisher DataPublisher dataPublisher = new DataPublisher("tcp://" + host + ":" + port, username, password); String streamId = DataBridgeCommonsUtils.generateStreamId(HTTPD_LOG_STREAM,VERSION); // try { // streamId = dataPublisher.findStream(HTTPD_LOG_STREAM, VERSION); // System.out.println("Stream already defined"); // // } catch (NoStreamDefinitionExistException e) { // //Define event stream // streamId = dataPublisher.defineStream("{" + // " 'name':'" + HTTPD_LOG_STREAM + "'," + // " 'version':'" + VERSION + "'," + // " 'nickName': 'Httpd_Log_Stream'," + // " 'description': 'Sample of Httpd logs'," + // " 'metaData':[" + // " {'name':'clientType','type':'STRING'}" + // " ]," + // " 'payloadData':[" + // " {'name':'log','type':'STRING'}" + // " ]" + // "}"); // // } if (null != streamId && !streamId.isEmpty()) { publishLogEvents(dataPublisher, streamId); } try { Thread.sleep(2000); } catch (InterruptedException e) { } dataPublisher.shutdownWithAgent(); }
Example #26
Source File: APIMgtUsageDataBridgeDataPublisherTestCase.java From carbon-apimgt with Apache License 2.0 | 4 votes |
@Test public void testThrottleStreamPublishEvent() throws Exception { ThrottlePublisherDTO throttlePublisherDTO = new ThrottlePublisherDTO(); throttlePublisherDTO.setAccessToken("accesstoken"); throttlePublisherDTO.setUsername(USERNAME); throttlePublisherDTO.setTenantDomain(TENAT_DOMAIN); throttlePublisherDTO.setApiCreatorTenantDomain(TENAT_DOMAIN); throttlePublisherDTO.setApiname(API_NAME); throttlePublisherDTO.setVersion(API_VERSION); throttlePublisherDTO.setContext(CONTEXT); throttlePublisherDTO.setApiCreator(USERNAME); throttlePublisherDTO.setApplicationName(APP_NAME); throttlePublisherDTO.setApplicationId(APP_ID); throttlePublisherDTO.setThrottledTime(System.currentTimeMillis()); throttlePublisherDTO.setThrottledOutReason("ThrottledOutReason"); throttlePublisherDTO.setSubscriber(USERNAME); throttlePublisherDTO.setKeyType(KEYTYPE); throttlePublisherDTO.setCorrelationID(CORRELATION_ID); throttlePublisherDTO.setGatewayType(SYNAPDE_GW_LABEL); throttlePublisherDTO.setHostName(HOST_NAME); publisher.publishEvent(throttlePublisherDTO); APIManagerAnalyticsConfiguration analyticsConfiguration = Mockito.mock(APIManagerAnalyticsConfiguration.class); PowerMockito.when(DataPublisherUtil.getApiManagerAnalyticsConfiguration()).thenReturn(analyticsConfiguration); PowerMockito.when(DataPublisherUtil.getHostAddress()).thenReturn("abc.com"); Mockito.when(analyticsConfiguration.getThrottleStreamName()).thenReturn("org.wso2.apimgt.statistics.throttle"); Mockito.when(analyticsConfiguration.getThrottleStreamVersion()).thenReturn("3.0.0"); Mockito.when(analyticsConfiguration.getDasReceiverUrlGroups()).thenReturn("tcp://localhost:7612"); Mockito.when(analyticsConfiguration.getDasReceiverServerUser()).thenReturn("admin"); Mockito.when(analyticsConfiguration.getDasReceiverServerPassword()).thenReturn("admin"); Mockito.when(analyticsConfiguration.getDasReceiverAuthUrlGroups()).thenReturn("ssl://localhost:7712"); DataPublisher dataPublisher = Mockito.mock(DataPublisher.class); PowerMockito.whenNew(DataPublisher.class).withAnyArguments().thenReturn(dataPublisher); //test data publish path. publisher.publishEvent(throttlePublisherDTO); // test data publishing fails due to null value in mandatory values. throttlePublisherDTO.setApiname(null); publisher.publishEvent(throttlePublisherDTO); }
Example #27
Source File: ThrottleDataPublisher.java From carbon-apimgt with Apache License 2.0 | 4 votes |
public static DataPublisher getDataPublisher() { return dataPublisher; }
Example #28
Source File: APIMgtUsageDataBridgeDataPublisherTestCase.java From carbon-apimgt with Apache License 2.0 | 4 votes |
@Test public void testFaultStreamPublishEvent() throws Exception { FaultPublisherDTO faultPublisherDTO = new FaultPublisherDTO(); faultPublisherDTO.setApplicationConsumerKey(CONSUMER_KEY); faultPublisherDTO.setApiContext(CONTEXT); faultPublisherDTO.setApiVersion(API_VERSION); faultPublisherDTO.setApiName(API_NAME); faultPublisherDTO.setApiResourcePath(RESOURCE_PATH); faultPublisherDTO.setApiMethod(METHOD); faultPublisherDTO.setErrorCode(String.valueOf(ERROR_CODE)); faultPublisherDTO.setErrorMessage(ERROR_MESSAGE); faultPublisherDTO.setRequestTimestamp(System.currentTimeMillis()); faultPublisherDTO.setUsername(USERNAME); faultPublisherDTO.setUserTenantDomain(MultitenantUtils.getTenantDomain(faultPublisherDTO.getUsername())); faultPublisherDTO.setHostname(HOST_NAME); faultPublisherDTO.setApiCreator(USERNAME); faultPublisherDTO.setApiCreatorTenantDomain(TENAT_DOMAIN); faultPublisherDTO.setApplicationName(APP_NAME); faultPublisherDTO.setApplicationId(APP_ID); faultPublisherDTO.setProtocol(PROTOCOL); faultPublisherDTO.setMetaClientType(KEYTYPE); faultPublisherDTO.setGatewaType(SYNAPDE_GW_LABEL); APIMgtUsageDataBridgeDataPublisher publisher = new APIMgtUsageDataBridgeDataPublisher(); APIManagerAnalyticsConfiguration analyticsConfiguration = Mockito.mock(APIManagerAnalyticsConfiguration.class); PowerMockito.when(DataPublisherUtil.getApiManagerAnalyticsConfiguration()).thenReturn(analyticsConfiguration); PowerMockito.when(DataPublisherUtil.getHostAddress()).thenReturn(HOST_NAME); Mockito.when(analyticsConfiguration.getFaultStreamName()).thenReturn("org.wso2.apimgt.statistics.fault"); Mockito.when(analyticsConfiguration.getFaultStreamVersion()).thenReturn("3.0.0"); Mockito.when(analyticsConfiguration.getDasReceiverUrlGroups()).thenReturn("tcp://localhost:7612"); Mockito.when(analyticsConfiguration.getDasReceiverServerUser()).thenReturn("admin"); Mockito.when(analyticsConfiguration.getDasReceiverServerPassword()).thenReturn("admin"); Mockito.when(analyticsConfiguration.getDasReceiverAuthUrlGroups()).thenReturn("ssl://localhost:7712"); DataPublisher dataPublisher = Mockito.mock(DataPublisher.class); PowerMockito.whenNew(DataPublisher.class).withAnyArguments().thenReturn(dataPublisher); //test data publish path. publisher.publishEvent(faultPublisherDTO); // test data publishing fails due to null value in mandatory values. faultPublisherDTO.setHostname(null); publisher.publishEvent(faultPublisherDTO); }
Example #29
Source File: Client.java From product-cep with Apache License 2.0 | 4 votes |
public static void main(String[] args) { System.out.println(Arrays.deepToString(args)); try { System.out.println("Starting WSO2 Event Client"); AgentHolder.setConfigPath(DataPublisherUtil.getDataAgentConfigPath()); DataPublisherUtil.setTrustStoreParams(); String protocol = args[0]; String host = args[1]; String port = args[2]; String username = args[3]; String password = args[4]; String streamId = args[5]; String sampleNumber = args[6]; String filePath = args[7]; int events = Integer.parseInt(args[8]); int delay = Integer.parseInt(args[9]); Map<String, StreamDefinition> streamDefinitions = DataPublisherUtil.loadStreamDefinitions(sampleNumber); if (streamId == null || streamId.length() == 0) { throw new Exception("streamId not provided"); } StreamDefinition streamDefinition = streamDefinitions.get(streamId); if (streamDefinition == null) { throw new Exception("StreamDefinition not available for stream " + streamId); } else { log.info("StreamDefinition used :" + streamDefinition); } filePath = DataPublisherUtil.getEventFilePath(sampleNumber, streamId, filePath); //create data publisher DataPublisher dataPublisher = new DataPublisher(protocol, "tcp://" + host + ":" + port, null, username, password); //Publish event for a valid stream publishEvents(dataPublisher, streamDefinition, filePath, events, delay); dataPublisher.shutdownWithAgent(); } catch (Throwable e) { log.error(e); } }
Example #30
Source File: DataProcessAndPublishingAgentWrapper.java From carbon-apimgt with Apache License 2.0 | 4 votes |
@Override protected DataPublisher getDataPublisher() { return Mockito.mock(DataPublisher.class); }