Search in sources :

Example 46 with Broker

use of org.wso2.broker.core.Broker in project carbon-apimgt by wso2.

the class APIGatewayPublisherImpl method updateApplication.

@Override
public void updateApplication(Application application) throws GatewayException {
    if (application != null) {
        ApplicationEvent applicationEvent = new ApplicationEvent(APIMgtConstants.GatewayEventTypes.APPLICATION_UPDATE);
        applicationEvent.setApplicationId(application.getId());
        applicationEvent.setName(application.getName());
        applicationEvent.setThrottlingTier(application.getPolicy().getUuid());
        applicationEvent.setSubscriber(application.getCreatedUser());
        publishToStoreTopic(applicationEvent);
        if (log.isDebugEnabled()) {
            log.debug("Application : " + application.getName() + " updated event has been successfully published " + "to broker");
        }
    }
}
Also used : ApplicationEvent(org.wso2.carbon.apimgt.core.models.events.ApplicationEvent)

Example 47 with Broker

use of org.wso2.broker.core.Broker in project carbon-apimgt by wso2.

the class APIGatewayPublisherImpl method deleteAPISubscription.

/**
 * {@inheritDoc}
 */
@Override
public void deleteAPISubscription(List<SubscriptionValidationData> subscriptionValidationDataList) throws GatewayException {
    SubscriptionEvent subscriptionDeleteEvent = new SubscriptionEvent(APIMgtConstants.GatewayEventTypes.SUBSCRIPTION_DELETE);
    subscriptionDeleteEvent.setSubscriptionsList(subscriptionValidationDataList);
    publishToStoreTopic(subscriptionDeleteEvent);
    if (log.isDebugEnabled()) {
        log.debug("Subscription deleted event has been successfully published to broker");
    }
}
Also used : SubscriptionEvent(org.wso2.carbon.apimgt.core.models.events.SubscriptionEvent)

Example 48 with Broker

use of org.wso2.broker.core.Broker in project carbon-apimgt by wso2.

the class APIGatewayPublisherImpl method addApplication.

@Override
public void addApplication(Application application) throws GatewayException {
    if (application != null) {
        ApplicationEvent applicationEvent = new ApplicationEvent(APIMgtConstants.GatewayEventTypes.APPLICATION_CREATE);
        applicationEvent.setApplicationId(application.getId());
        applicationEvent.setName(application.getName());
        applicationEvent.setThrottlingTier(application.getPolicy().getUuid());
        applicationEvent.setSubscriber(application.getCreatedUser());
        publishToStoreTopic(applicationEvent);
        if (log.isDebugEnabled()) {
            log.debug("Application : " + application.getName() + " created event has been successfully published " + "to broker");
        }
    }
}
Also used : ApplicationEvent(org.wso2.carbon.apimgt.core.models.events.ApplicationEvent)

Example 49 with Broker

use of org.wso2.broker.core.Broker in project carbon-apimgt by wso2.

the class APIGatewayPublisherImpl method addBlockCondition.

@Override
public void addBlockCondition(BlockConditions blockConditions) throws GatewayException {
    if (blockConditions != null) {
        BlockEvent blockEvent = new BlockEvent(APIMgtConstants.GatewayEventTypes.BLOCK_CONDITION_ADD);
        blockEvent.setConditionId(blockConditions.getConditionId());
        blockEvent.setUuid(blockConditions.getUuid());
        blockEvent.setConditionType(blockConditions.getConditionType());
        blockEvent.setEnabled(blockConditions.isEnabled());
        blockEvent.setConditionValue(blockConditions.getConditionValue());
        if (APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITIONS_IP.equals(blockConditions.getConditionType())) {
            blockEvent.setFixedIp(APIUtils.ipToLong(blockConditions.getConditionValue()));
        }
        if (APIMgtConstants.ThrottlePolicyConstants.BLOCKING_CONDITION_IP_RANGE.equals(blockConditions.getConditionType())) {
            blockEvent.setStartingIP(APIUtils.ipToLong(blockConditions.getStartingIP()));
            blockEvent.setEndingIP(APIUtils.ipToLong(blockConditions.getEndingIP()));
        }
        publishToThrottleTopic(blockEvent);
        if (log.isDebugEnabled()) {
            log.debug("BlockCondition : " + blockConditions.getUuid() + " add event has been successfully " + "published " + "to broker");
        }
    }
}
Also used : BlockEvent(org.wso2.carbon.apimgt.core.models.events.BlockEvent)

Example 50 with Broker

use of org.wso2.broker.core.Broker in project siddhi by wso2.

the class InMemoryTransportTestCase method inMemoryWithFailingSink.

@Test
public void inMemoryWithFailingSink() throws InterruptedException {
    log.info("Test failing inMemorySink");
    InMemoryBroker.Subscriber subscriptionWSO2 = new InMemoryBroker.Subscriber() {

        @Override
        public void onMessage(Object msg) {
            wso2Count.incrementAndGet();
        }

        @Override
        public String getTopic() {
            return "WSO2";
        }
    };
    InMemoryBroker.Subscriber subscriptionIBM = new InMemoryBroker.Subscriber() {

        @Override
        public void onMessage(Object msg) {
            ibmCount.incrementAndGet();
        }

        @Override
        public String getTopic() {
            return "IBM";
        }
    };
    // subscribe to "inMemory" broker per topic
    InMemoryBroker.subscribe(subscriptionWSO2);
    InMemoryBroker.subscribe(subscriptionIBM);
    String streams = "" + "@app:name('TestSiddhiApp')" + "define stream FooStream (symbol string, price float, volume long); " + "@sink(type='testFailingInMemory', topic='{{symbol}}', @map(type='passThrough')) " + "define stream BarStream (symbol string, price float, volume long); ";
    String query = "" + "from FooStream " + "select * " + "insert into BarStream; ";
    SiddhiManager siddhiManager = new SiddhiManager();
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query);
    InputHandler stockStream = siddhiAppRuntime.getInputHandler("FooStream");
    siddhiAppRuntime.start();
    stockStream.send(new Object[] { "WSO2", 55.6f, 100L });
    stockStream.send(new Object[] { "IBM", 75.6f, 100L });
    TestFailingInMemorySink.fail = true;
    stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
    stockStream.send(new Object[] { "WSO2", 57.6f, 100L });
    TestFailingInMemorySink.fail = false;
    Thread.sleep(5500);
    stockStream.send(new Object[] { "IBM", 75.6f, 100L });
    // assert event count
    AssertJUnit.assertEquals("Number of WSO2 events", 1, wso2Count.get());
    AssertJUnit.assertEquals("Number of IBM events", 2, ibmCount.get());
    AssertJUnit.assertEquals("Number of errors", 2, TestFailingInMemorySink.numberOfErrorOccurred);
    siddhiAppRuntime.shutdown();
    // unsubscribe from "inMemory" broker per topic
    InMemoryBroker.unsubscribe(subscriptionWSO2);
    InMemoryBroker.unsubscribe(subscriptionIBM);
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) InMemoryBroker(org.wso2.siddhi.core.util.transport.InMemoryBroker) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)19 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)19 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)16 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)16 InMemoryBroker (org.wso2.siddhi.core.util.transport.InMemoryBroker)16 Environment (org.wso2.carbon.apimgt.api.model.Environment)15 InputHandler (org.wso2.siddhi.core.stream.input.InputHandler)13 ArrayList (java.util.ArrayList)11 SolaceAdminApis (org.wso2.carbon.apimgt.solace.SolaceAdminApis)9 APIRevisionDeployment (org.wso2.carbon.apimgt.api.model.APIRevisionDeployment)8 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)7 DeployerException (org.wso2.carbon.apimgt.impl.deployer.exceptions.DeployerException)7 NotifierException (org.wso2.carbon.apimgt.impl.notifier.exceptions.NotifierException)7 IOException (java.io.IOException)6 Broker (org.wso2.carbon.apimgt.core.api.Broker)6 Test (org.junit.Test)5 API (org.wso2.carbon.apimgt.core.models.API)5 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)4 ExternalGatewayDeployer (org.wso2.carbon.apimgt.impl.deployer.ExternalGatewayDeployer)4 JsonParser (com.google.gson.JsonParser)3