org.wso2.carbon.databridge.agent.AgentHolder Java Examples

The following examples show how to use org.wso2.carbon.databridge.agent.AgentHolder. 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: DataBridgePublisher.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
private static void loadConfigs() {

        String agentConfPath = MicroIntegratorBaseUtils.getCarbonConfigDirPath()
                + AnalyticsDataPublisherConstants.DATA_AGENT_CONFIG_PATH;

        AgentHolder.setConfigPath(agentConfPath);

        receiverUrl = CarbonServerConfigurationService.getInstance()
                .getFirstProperty(AnalyticsDataPublisherConstants.ANALYTICS_RECEIVER_URL);
        authUrl = CarbonServerConfigurationService.getInstance()
                .getFirstProperty(AnalyticsDataPublisherConstants.ANALYTICS_AUTH_URL);
        username = CarbonServerConfigurationService.getInstance()
                .getFirstProperty(AnalyticsDataPublisherConstants.ANALYTICS_USERNAME);
        password = CarbonServerConfigurationService.getInstance()
                .getFirstProperty(AnalyticsDataPublisherConstants.ANALYTICS_PASSWORD);

    }
 
Example #2
Source File: FileDataPublisherTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test
public void tryPublish() throws Exception {
    PowerMockito.mockStatic(AgentHolder.class);
    AgentHolder agentHolder = Mockito.mock(AgentHolder.class);
    PowerMockito.when(AgentHolder.getInstance()).thenReturn(agentHolder);
    DataEndpointAgent dataEndpointAgent = Mockito.mock(DataEndpointAgent.class);
    Mockito.when(agentHolder.getDefaultDataEndpointAgent()).thenReturn(dataEndpointAgent);
    AgentConfiguration agentConfig = Mockito.mock(AgentConfiguration.class);
    Mockito.when(dataEndpointAgent.getAgentConfiguration()).thenReturn(agentConfig);
    Mockito.when(agentConfig.getQueueSize()).thenReturn(32768);
    String carbonHome = System.getProperty(Constants.CARBON_HOME);
    String carbonConfigPath = System.getProperty(CARBON_HOME) + CARBON_CONFIGS_PATH;
    PowerMockito.mockStatic(CarbonUtils.class);
    PowerMockito.when(CarbonUtils.getCarbonHome()).thenReturn(carbonHome);
    PowerMockito.when(CarbonUtils.getCarbonConfigDirPath()).thenReturn(carbonConfigPath);
    DataBridgeRequestResponseStreamPublisherDTO dataBridgeRequestStreamPublisherDTO = Mockito.mock(DataBridgeRequestResponseStreamPublisherDTO.class);
    FileDataPublisher fileDataPublisher = new FileDataPublisher();
    fileDataPublisher.tryPublish("org.wso2.apimgt.statistics.request:1.0.0", 12324343,
            (Object[]) dataBridgeRequestStreamPublisherDTO.createMetaData(), null,
            (Object[]) dataBridgeRequestStreamPublisherDTO.createPayload());
}
 
Example #3
Source File: FileDataPublisherTest.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Test
public void shutdown() throws Exception {
    String carbonHome = System.getProperty(Constants.CARBON_HOME);
    PowerMockito.mockStatic(CarbonUtils.class);
    PowerMockito.when(CarbonUtils.getCarbonHome()).thenReturn(carbonHome);
    PowerMockito.mockStatic(AgentHolder.class);
    AgentHolder agentHolder = Mockito.mock(AgentHolder.class);
    PowerMockito.when(AgentHolder.getInstance()).thenReturn(agentHolder);
    DataEndpointAgent dataEndpointAgent = Mockito.mock(DataEndpointAgent.class);
    Mockito.when(agentHolder.getDefaultDataEndpointAgent()).thenReturn(dataEndpointAgent);
    AgentConfiguration agentConfig = Mockito.mock(AgentConfiguration.class);
    Mockito.when(dataEndpointAgent.getAgentConfiguration()).thenReturn(agentConfig);
    Mockito.when(agentConfig.getQueueSize()).thenReturn(32768);
    FileDataPublisher fileDataPublisher = new FileDataPublisher();
    fileDataPublisher.shutdown();
}
 
Example #4
Source File: EventPublisherServiceTest.java    From carbon-device-mgt with Apache License 2.0 5 votes vote down vote up
@Test(description = "Publishing with invalid data publisher config",
        dependsOnMethods = "publishWithDataEndpointConfigException",
        expectedExceptions = DataPublisherConfigurationException.class)
public void publishWithDataAgentConfigException() throws DataPublisherConfigurationException,
        NoSuchFieldException, IllegalAccessException, DataEndpointAgentConfigurationException {
    AnalyticsConfiguration.init();
    Field defaultAgentName = AgentHolder.getInstance().getClass().getDeclaredField("defaultDataEndpointAgentName");
    defaultAgentName.setAccessible(true);
    defaultAgentName.set(AgentHolder.getInstance(), "dummyAgent");
    publishAsTenant(getEventProps());
}
 
Example #5
Source File: HTTPMonitoringDataPublisher.java    From msf4j with Apache License 2.0 5 votes vote down vote up
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 #6
Source File: Client.java    From product-cep with Apache License 2.0 5 votes vote down vote up
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 #7
Source File: FileDataPublisher.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public FileDataPublisher() throws UsagePublisherException {
    int queueSize = 32768; //Default Value
    try {
        queueSize = AgentHolder.getInstance().getDefaultDataEndpointAgent().getAgentConfiguration().getQueueSize();
    } catch (DataEndpointAgentConfigurationException e) {
        log.warn("Error occurred while getting the Queue size from Agent Configuration. Hence default size " +
                "(32768) will be used");
    }
    this.eventQueue = new EventQueue(queueSize);
    UsageFileWriter.getInstance();
}
 
Example #8
Source File: APIMgtUsageFileDataPublisherTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Test
public void init() throws Exception {
    PowerMockito.mockStatic(AgentHolder.class);
    AgentHolder agentHolder = Mockito.mock(AgentHolder.class);
    PowerMockito.when(AgentHolder.getInstance()).thenReturn(agentHolder);
    DataEndpointAgent dataEndpointAgent = Mockito.mock(DataEndpointAgent.class);
    Mockito.when(agentHolder.getDefaultDataEndpointAgent()).thenReturn(dataEndpointAgent);
    AgentConfiguration agentConfig = Mockito.mock(AgentConfiguration.class);
    Mockito.when(dataEndpointAgent.getAgentConfiguration()).thenReturn(agentConfig);
    Mockito.when(agentConfig.getQueueSize()).thenReturn(32768);
    APIMgtUsageFileDataPublisher apiMgtUsageFileDataPublisher = new APIMgtUsageFileDataPublisher();
    apiMgtUsageFileDataPublisher.init();
}
 
Example #9
Source File: APIMgtUsageFileDataPublisherTest.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public void mockCommonCases() throws Exception {
    PowerMockito.mockStatic(AgentHolder.class);
    AgentHolder agentHolder = Mockito.mock(AgentHolder.class);
    PowerMockito.when(AgentHolder.getInstance()).thenReturn(agentHolder);
    DataEndpointAgent dataEndpointAgent = Mockito.mock(DataEndpointAgent.class);
    Mockito.when(agentHolder.getDefaultDataEndpointAgent()).thenReturn(dataEndpointAgent);
    AgentConfiguration agentConfig = Mockito.mock(AgentConfiguration.class);
    Mockito.when(dataEndpointAgent.getAgentConfiguration()).thenReturn(agentConfig);
    Mockito.when(agentConfig.getQueueSize()).thenReturn(32768);
    String carbonHome = System.getProperty(Constants.CARBON_HOME);
    PowerMockito.mockStatic(CarbonUtils.class);
    PowerMockito.when(CarbonUtils.getCarbonHome()).thenReturn(carbonHome);
}
 
Example #10
Source File: HttpdLogAgent.java    From product-cep with Apache License 2.0 4 votes vote down vote up
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 #11
Source File: Client.java    From product-cep with Apache License 2.0 4 votes vote down vote up
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);
        }
    }