Search in sources :

Example 31 with GatewayException

use of org.wso2.carbon.apimgt.core.exception.GatewayException in project carbon-apimgt by wso2.

the class APIGatewayPublisherImpl method deleteAPI.

@Override
public void deleteAPI(API api) throws GatewayException {
    // build the message to send
    APIEvent apiDeleteEvent = new APIEvent(APIMgtConstants.GatewayEventTypes.API_DELETE);
    apiDeleteEvent.setLabels(api.getLabels());
    apiDeleteEvent.setApiSummary(toAPISummary(api));
    publishToPublisherTopic(apiDeleteEvent);
    if (log.isDebugEnabled()) {
        log.debug("API : " + api.getName() + " deleted event has been successfully published to broker");
    }
    if (api.hasOwnGateway()) {
        // Delete the Gateway - check how we can assume that we complete the deletion
        try {
            List<String> labels = api.getLabels();
            if (labels != null && !labels.isEmpty()) {
                removeContainerBasedGateway(labels.toArray()[0].toString(), api);
            } else {
                log.error("Could not delete container based gateways as labels could not find in the API.");
            }
        } catch (ContainerBasedGatewayException e) {
            String msg = "Error while removing the container based gateway";
            throw new GatewayException(msg, e, ExceptionCodes.CONTAINER_GATEWAY_REMOVAL_FAILED);
        }
    }
}
Also used : APIEvent(org.wso2.carbon.apimgt.core.models.events.APIEvent) GatewayException(org.wso2.carbon.apimgt.core.exception.GatewayException) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException) ContainerBasedGatewayException(org.wso2.carbon.apimgt.core.exception.ContainerBasedGatewayException)

Example 32 with GatewayException

use of org.wso2.carbon.apimgt.core.exception.GatewayException in project carbon-apimgt by wso2.

the class APIGatewayPublisherImpl method changeAPIState.

@Override
public void changeAPIState(API api, String status) throws GatewayException {
    // create the message to be sent to the gateway. This contains the basic details of the API and target
    // lifecycle state.
    APIEvent gatewayDTO = new APIEvent(APIMgtConstants.GatewayEventTypes.API_STATE_CHANGE);
    gatewayDTO.setLabels(api.getLabels());
    gatewayDTO.setApiSummary(toAPISummary(api));
    publishToPublisherTopic(gatewayDTO);
}
Also used : APIEvent(org.wso2.carbon.apimgt.core.models.events.APIEvent)

Example 33 with GatewayException

use of org.wso2.carbon.apimgt.core.exception.GatewayException in project carbon-apimgt by wso2.

the class APIGatewayPublisherImpl method updateBlockCondition.

@Override
public void updateBlockCondition(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() + " update event has been successfully " + "published " + "to broker");
        }
    }
}
Also used : BlockEvent(org.wso2.carbon.apimgt.core.models.events.BlockEvent)

Example 34 with GatewayException

use of org.wso2.carbon.apimgt.core.exception.GatewayException in project carbon-apimgt by wso2.

the class APIGatewayPublisherImpl method updatePolicy.

@Override
public void updatePolicy(PolicyValidationData policyValidationData) throws GatewayException {
    if (policyValidationData != null) {
        PolicyEvent policyEvent = new PolicyEvent(APIMgtConstants.GatewayEventTypes.POLICY_UPDATE);
        policyEvent.setId(policyValidationData.getId());
        policyEvent.setName(policyValidationData.getName());
        policyEvent.setStopOnQuotaReach(policyValidationData.isStopOnQuotaReach());
        publishToThrottleTopic(policyEvent);
        if (log.isDebugEnabled()) {
            log.debug("Policy : " + policyValidationData.getName() + " update event has been successfully " + "published " + "to broker");
        }
    }
}
Also used : PolicyEvent(org.wso2.carbon.apimgt.core.models.events.PolicyEvent)

Example 35 with GatewayException

use of org.wso2.carbon.apimgt.core.exception.GatewayException 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)

Aggregations

GatewayException (org.wso2.carbon.apimgt.core.exception.GatewayException)14 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)13 API (org.wso2.carbon.apimgt.core.models.API)12 HashMap (java.util.HashMap)7 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)7 ArrayList (java.util.ArrayList)6 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)6 APIEvent (org.wso2.carbon.apimgt.core.models.events.APIEvent)6 Test (org.junit.Test)5 Broker (org.wso2.carbon.apimgt.core.api.Broker)5 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)4 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)4 Subscription (org.wso2.carbon.apimgt.core.models.Subscription)4 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)4 Test (org.testng.annotations.Test)3 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)3 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException)3 ApplicationEvent (org.wso2.carbon.apimgt.core.models.events.ApplicationEvent)3 PolicyEvent (org.wso2.carbon.apimgt.core.models.events.PolicyEvent)3 ThreatProtectionEvent (org.wso2.carbon.apimgt.core.models.events.ThreatProtectionEvent)3