Search in sources :

Example 11 with APIEvent

use of org.wso2.carbon.apimgt.impl.notifier.events.APIEvent in project carbon-apimgt by wso2.

the class ExternallyDeployedApiNotifier method process.

/**
 * Process API lifecycle notifier events related to APIs deployed in external gateway
 *
 * @param event related to deployments
 * @throws NotifierException if error occurs when casting event
 */
private void process(Event event) throws NotifierException {
    APIEvent apiEvent;
    apiEvent = (APIEvent) event;
    if (APIConstants.EventType.API_LIFECYCLE_CHANGE.name().equals(event.getType())) {
        // Handle API retiring life cycle change in external gateway
        undeployApiWhenRetiring(apiEvent);
    } else if (APIConstants.EventType.API_DELETE.name().equals(event.getType())) {
        // Handle API deletion in external gateway
        undeployWhenDeleting(apiEvent);
    }
}
Also used : APIEvent(org.wso2.carbon.apimgt.impl.notifier.events.APIEvent)

Example 12 with APIEvent

use of org.wso2.carbon.apimgt.impl.notifier.events.APIEvent in project carbon-apimgt by wso2.

the class ExternallyDeployedApiNotifier method undeployApiWhenRetiring.

/**
 * Undeploy APIs from external gateway when life cycle state changed to retire
 *
 * @param apiEvent APIEvent to undeploy APIs from external gateway
 * @throws NotifierException if error occurs when undeploying APIs from external gateway
 */
private void undeployApiWhenRetiring(APIEvent apiEvent) throws NotifierException {
    apiMgtDAO = ApiMgtDAO.getInstance();
    Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
    boolean deleted;
    String apiId = apiEvent.getUuid();
    if (!APIConstants.RETIRED.equals(apiEvent.getApiStatus())) {
        return;
    }
    try {
        APIProvider apiProvider = APIManagerFactory.getInstance().getAPIProvider(CarbonContext.getThreadLocalCarbonContext().getUsername());
        API api = apiProvider.getAPIbyUUID(apiId, apiMgtDAO.getOrganizationByAPIUUID(apiId));
        List<APIRevisionDeployment> test = apiMgtDAO.getAPIRevisionDeploymentsByApiUUID(apiId);
        for (APIRevisionDeployment deployment : test) {
            String deploymentEnv = deployment.getDeployment();
            if (gatewayEnvironments.containsKey(deploymentEnv)) {
                ExternalGatewayDeployer deployer = ServiceReferenceHolder.getInstance().getExternalGatewayDeployer(gatewayEnvironments.get(deploymentEnv).getProvider());
                if (deployer != null) {
                    try {
                        deleted = deployer.undeployWhenRetire(api, gatewayEnvironments.get(deploymentEnv));
                        if (!deleted) {
                            throw new NotifierException("Error while deleting API product from Solace broker");
                        }
                    } catch (DeployerException e) {
                        throw new NotifierException(e.getMessage());
                    }
                }
            }
        }
    } catch (APIManagementException e) {
        throw new NotifierException(e.getMessage());
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ExternalGatewayDeployer(org.wso2.carbon.apimgt.impl.deployer.ExternalGatewayDeployer) Environment(org.wso2.carbon.apimgt.api.model.Environment) DeployerException(org.wso2.carbon.apimgt.impl.deployer.exceptions.DeployerException) API(org.wso2.carbon.apimgt.api.model.API) APIRevisionDeployment(org.wso2.carbon.apimgt.api.model.APIRevisionDeployment) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) NotifierException(org.wso2.carbon.apimgt.impl.notifier.exceptions.NotifierException)

Example 13 with APIEvent

use of org.wso2.carbon.apimgt.impl.notifier.events.APIEvent in project carbon-apimgt by wso2.

the class APIGatewayPublisherImpl method updateAPI.

@Override
public void updateAPI(API api) throws GatewayException {
    // build the message to send
    APIEvent apiUpdateEvent = new APIEvent(APIMgtConstants.GatewayEventTypes.API_UPDATE);
    apiUpdateEvent.setLabels(api.getLabels());
    apiUpdateEvent.setApiSummary(toAPISummary(api));
    publishToPublisherTopic(apiUpdateEvent);
    if (log.isDebugEnabled()) {
        log.debug("API : " + api.getName() + " updated event has been successfully published to broker");
    }
}
Also used : APIEvent(org.wso2.carbon.apimgt.core.models.events.APIEvent)

Example 14 with APIEvent

use of org.wso2.carbon.apimgt.impl.notifier.events.APIEvent 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 15 with APIEvent

use of org.wso2.carbon.apimgt.impl.notifier.events.APIEvent 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)

Aggregations

APIEvent (org.wso2.carbon.apimgt.impl.notifier.events.APIEvent)15 API (org.wso2.carbon.apimgt.api.model.API)8 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)7 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)6 APIEvent (org.wso2.carbon.apimgt.core.models.events.APIEvent)6 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)5 ImportExportAPI (org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI)5 PublisherAPI (org.wso2.carbon.apimgt.persistence.dto.PublisherAPI)5 HashMap (java.util.HashMap)4 Map (java.util.Map)4 TreeMap (java.util.TreeMap)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)4 JSONObject (org.json.simple.JSONObject)4 Gson (com.google.gson.Gson)3 JSONParser (org.json.simple.parser.JSONParser)3 ParseException (org.json.simple.parser.ParseException)3 APIProductIdentifier (org.wso2.carbon.apimgt.api.model.APIProductIdentifier)3 HashSet (java.util.HashSet)2 APIProductResource (org.wso2.carbon.apimgt.api.model.APIProductResource)2 APIRevisionDeployment (org.wso2.carbon.apimgt.api.model.APIRevisionDeployment)2