Search in sources :

Example 1 with DeployerException

use of org.wso2.carbon.apimgt.impl.deployer.exceptions.DeployerException 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 2 with DeployerException

use of org.wso2.carbon.apimgt.impl.deployer.exceptions.DeployerException in project carbon-apimgt by wso2.

the class ExternalGatewayNotifier method unDeployApi.

/**
 * Undeploy APIs from external gateway
 *
 * @param deployAPIInGatewayEvent DeployAPIInGatewayEvent to undeploy APIs from external gateway
 * @throws NotifierException if error occurs when undeploying APIs from external gateway
 */
private void unDeployApi(DeployAPIInGatewayEvent deployAPIInGatewayEvent) throws NotifierException {
    boolean deleted;
    Set<String> gateways = deployAPIInGatewayEvent.getGatewayLabels();
    String apiId = deployAPIInGatewayEvent.getUuid();
    try {
        Map<String, Environment> environments = APIUtil.getEnvironments(deployAPIInGatewayEvent.getTenantDomain());
        APIProvider apiProvider = APIManagerFactory.getInstance().getAPIProvider(deployAPIInGatewayEvent.getProvider());
        API api = apiProvider.getAPIbyUUID(apiId, apiMgtDAO.getOrganizationByAPIUUID(apiId));
        for (String deploymentEnv : gateways) {
            if (environments.containsKey(deploymentEnv)) {
                ExternalGatewayDeployer deployer = ServiceReferenceHolder.getInstance().getExternalGatewayDeployer(environments.get(deploymentEnv).getProvider());
                if (deployer != null) {
                    try {
                        deleted = deployer.undeploy(api.getId().getName(), api.getId().getVersion(), api.getContext(), environments.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) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) NotifierException(org.wso2.carbon.apimgt.impl.notifier.exceptions.NotifierException)

Example 3 with DeployerException

use of org.wso2.carbon.apimgt.impl.deployer.exceptions.DeployerException in project carbon-apimgt by wso2.

the class ExternalGatewayNotifier method deployApi.

/**
 * Deploy APIs to external gateway
 *
 * @param deployAPIInGatewayEvent DeployAPIInGatewayEvent to deploy APIs to external gateway
 * @throws NotifierException if error occurs when deploying APIs to external gateway
 */
private void deployApi(DeployAPIInGatewayEvent deployAPIInGatewayEvent) throws NotifierException {
    boolean deployed;
    Set<String> gateways = deployAPIInGatewayEvent.getGatewayLabels();
    String apiId = deployAPIInGatewayEvent.getUuid();
    try {
        Map<String, Environment> environments = APIUtil.getEnvironments(deployAPIInGatewayEvent.getTenantDomain());
        APIProvider apiProvider = APIManagerFactory.getInstance().getAPIProvider(CarbonContext.getThreadLocalCarbonContext().getUsername());
        API api = apiProvider.getAPIbyUUID(apiId, apiMgtDAO.getOrganizationByAPIUUID(apiId));
        for (String deploymentEnv : gateways) {
            if (environments.containsKey(deploymentEnv)) {
                ExternalGatewayDeployer deployer = ServiceReferenceHolder.getInstance().getExternalGatewayDeployer(environments.get(deploymentEnv).getProvider());
                if (deployer != null) {
                    try {
                        deployed = deployer.deploy(api, environments.get(deploymentEnv));
                        if (!deployed) {
                            throw new APIManagementException("Error while deploying API product to Solace broker");
                        }
                    } catch (DeployerException e) {
                        throw new APIManagementException(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) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) NotifierException(org.wso2.carbon.apimgt.impl.notifier.exceptions.NotifierException)

Example 4 with DeployerException

use of org.wso2.carbon.apimgt.impl.deployer.exceptions.DeployerException in project carbon-apimgt by wso2.

the class ExternallyDeployedApiNotifier method undeployWhenDeleting.

/**
 * Undeploy APIs from external gateway when API is deleted
 *
 * @param apiEvent APIEvent to undeploy APIs from external gateway
 * @throws NotifierException if error occurs when undeploying APIs from external gateway
 */
private void undeployWhenDeleting(APIEvent apiEvent) throws NotifierException {
    Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
    boolean deleted;
    String apiId = apiEvent.getUuid();
    try {
        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.undeploy(apiEvent.getApiName(), apiEvent.getApiVersion(), apiEvent.getApiContext(), 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) APIRevisionDeployment(org.wso2.carbon.apimgt.api.model.APIRevisionDeployment) NotifierException(org.wso2.carbon.apimgt.impl.notifier.exceptions.NotifierException)

Example 5 with DeployerException

use of org.wso2.carbon.apimgt.impl.deployer.exceptions.DeployerException in project carbon-apimgt by wso2.

the class SolaceBrokerDeployer method undeployWhenRetire.

/**
 * Undeploy API artifact from provided environment in the external gateway when Api is retired
 *
 * @param api         API to be undeployed from the external gateway
 * @param environment Environment needed to be undeployed API from the external gateway
 * @throws DeployerException if error occurs when undeploying APIs from the external gateway
 */
public boolean undeployWhenRetire(API api, Environment environment) throws DeployerException {
    Application application;
    APIProvider apiProvider;
    // Remove subscription
    try {
        apiProvider = APIManagerFactory.getInstance().getAPIProvider(CarbonContext.getThreadLocalCarbonContext().getUsername());
        List<SubscribedAPI> apiUsages = apiProvider.getAPIUsageByAPIId(api.getUuid(), api.getOrganization());
        for (SubscribedAPI usage : apiUsages) {
            application = usage.getApplication();
            // Check whether the subscription is belongs to an API deployed in Solace
            if (SolaceConstants.SOLACE_ENVIRONMENT.equals(api.getGatewayVendor())) {
                SolaceNotifierUtils.unsubscribeAPIProductFromSolaceApplication(api, application);
            }
        }
    } catch (APIManagementException e) {
        throw new DeployerException("Error occurred when removing subscriptions of the API " + api.getUuid() + "to be retired", e);
    }
    // undeploy API from Solace
    boolean deletedFromSolace = undeploy(api.getId().getName(), api.getId().getVersion(), api.getContext(), environment);
    if (!deletedFromSolace) {
        throw new DeployerException("Error while deleting API product of API " + api.getUuid() + "from Solace " + "broker");
    }
    return true;
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) DeployerException(org.wso2.carbon.apimgt.impl.deployer.exceptions.DeployerException) Application(org.wso2.carbon.apimgt.api.model.Application) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)7 DeployerException (org.wso2.carbon.apimgt.impl.deployer.exceptions.DeployerException)7 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)4 Environment (org.wso2.carbon.apimgt.api.model.Environment)4 ExternalGatewayDeployer (org.wso2.carbon.apimgt.impl.deployer.ExternalGatewayDeployer)4 NotifierException (org.wso2.carbon.apimgt.impl.notifier.exceptions.NotifierException)4 API (org.wso2.carbon.apimgt.api.model.API)3 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)2 APIRevisionDeployment (org.wso2.carbon.apimgt.api.model.APIRevisionDeployment)2 SolaceAdminApis (org.wso2.carbon.apimgt.solace.SolaceAdminApis)2 Aai20Document (io.apicurio.datamodels.asyncapi.v2.models.Aai20Document)1 Application (org.wso2.carbon.apimgt.api.model.Application)1 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)1