Search in sources :

Example 21 with IGatewayLink

use of io.apiman.manager.api.gateway.IGatewayLink in project apiman by apiman.

the class ActionResourceImpl method retireApi.

/**
 * Retires an API that is currently published to the Gateway.
 * @param action
 */
private void retireApi(ActionBean action) throws ActionException, NotAuthorizedException {
    securityContext.checkPermissions(PermissionType.apiAdmin, action.getOrganizationId());
    ApiVersionBean versionBean;
    try {
        versionBean = orgs.getApiVersion(action.getOrganizationId(), action.getEntityId(), action.getEntityVersion());
    } catch (ApiVersionNotFoundException e) {
        // $NON-NLS-1$
        throw ExceptionFactory.actionException(Messages.i18n.format("ApiNotFound"));
    }
    // Validate that it's ok to perform this action - API must be Published.
    if (versionBean.getStatus() != ApiStatus.Published) {
        // $NON-NLS-1$
        throw ExceptionFactory.actionException(Messages.i18n.format("InvalidApiStatus"));
    }
    Api gatewayApi = new Api();
    gatewayApi.setOrganizationId(versionBean.getApi().getOrganization().getId());
    gatewayApi.setApiId(versionBean.getApi().getId());
    gatewayApi.setVersion(versionBean.getVersion());
    // Retire the API from all relevant gateways
    try {
        storage.beginTx();
        Set<ApiGatewayBean> gateways = versionBean.getGateways();
        if (gateways == null) {
            // $NON-NLS-1$
            throw new PublishingException("No gateways specified for API!");
        }
        for (ApiGatewayBean apiGatewayBean : gateways) {
            IGatewayLink gatewayLink = createGatewayLink(apiGatewayBean.getGatewayId());
            gatewayLink.retireApi(gatewayApi);
            gatewayLink.close();
        }
        versionBean.setStatus(ApiStatus.Retired);
        versionBean.setRetiredOn(new Date());
        ApiBean api = storage.getApi(action.getOrganizationId(), action.getEntityId());
        if (api == null) {
            // $NON-NLS-1$ //$NON-NLS-2$
            throw new PublishingException("Error: could not find API - " + action.getOrganizationId() + "=>" + action.getEntityId());
        }
        if (api.getNumPublished() == null || api.getNumPublished() == 0) {
            api.setNumPublished(0);
        } else {
            api.setNumPublished(api.getNumPublished() - 1);
        }
        storage.updateApi(api);
        storage.updateApiVersion(versionBean);
        storage.createAuditEntry(AuditUtils.apiRetired(versionBean, securityContext));
        storage.commitTx();
    } catch (PublishingException e) {
        storage.rollbackTx();
        // $NON-NLS-1$
        throw ExceptionFactory.actionException(Messages.i18n.format("RetireError"), e);
    } catch (Exception e) {
        storage.rollbackTx();
        // $NON-NLS-1$
        throw ExceptionFactory.actionException(Messages.i18n.format("RetireError"), e);
    }
    log.debug(// $NON-NLS-1$
    String.format(// $NON-NLS-1$
    "Successfully retired API %s on specified gateways: %s", versionBean.getApi().getName(), versionBean.getApi()));
}
Also used : ApiBean(io.apiman.manager.api.beans.apis.ApiBean) ApiGatewayBean(io.apiman.manager.api.beans.apis.ApiGatewayBean) PublishingException(io.apiman.gateway.engine.beans.exceptions.PublishingException) Api(io.apiman.gateway.engine.beans.Api) ApiVersionBean(io.apiman.manager.api.beans.apis.ApiVersionBean) IGatewayLink(io.apiman.manager.api.gateway.IGatewayLink) Date(java.util.Date) ApiVersionNotFoundException(io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException) StorageException(io.apiman.manager.api.core.exceptions.StorageException) GatewayNotFoundException(io.apiman.manager.api.rest.exceptions.GatewayNotFoundException) NotAuthorizedException(io.apiman.manager.api.rest.exceptions.NotAuthorizedException) ActionException(io.apiman.manager.api.rest.exceptions.ActionException) PlanVersionNotFoundException(io.apiman.manager.api.rest.exceptions.PlanVersionNotFoundException) PublishingException(io.apiman.gateway.engine.beans.exceptions.PublishingException) ClientVersionNotFoundException(io.apiman.manager.api.rest.exceptions.ClientVersionNotFoundException) ApiVersionNotFoundException(io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException)

Example 22 with IGatewayLink

use of io.apiman.manager.api.gateway.IGatewayLink in project apiman by apiman.

the class ActionResourceImpl method createGatewayLink.

/**
 * Creates a gateway link given a gateway id.
 * @param gatewayId
 */
private IGatewayLink createGatewayLink(String gatewayId) throws PublishingException {
    try {
        GatewayBean gateway = storage.getGateway(gatewayId);
        if (gateway == null) {
            throw new GatewayNotFoundException();
        }
        IGatewayLink link = gatewayLinkFactory.create(gateway);
        return link;
    } catch (GatewayNotFoundException e) {
        throw e;
    } catch (Exception e) {
        throw new PublishingException(e.getMessage(), e);
    }
}
Also used : ApiGatewayBean(io.apiman.manager.api.beans.apis.ApiGatewayBean) GatewayBean(io.apiman.manager.api.beans.gateways.GatewayBean) PublishingException(io.apiman.gateway.engine.beans.exceptions.PublishingException) GatewayNotFoundException(io.apiman.manager.api.rest.exceptions.GatewayNotFoundException) IGatewayLink(io.apiman.manager.api.gateway.IGatewayLink) ApiVersionNotFoundException(io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException) StorageException(io.apiman.manager.api.core.exceptions.StorageException) GatewayNotFoundException(io.apiman.manager.api.rest.exceptions.GatewayNotFoundException) NotAuthorizedException(io.apiman.manager.api.rest.exceptions.NotAuthorizedException) ActionException(io.apiman.manager.api.rest.exceptions.ActionException) PlanVersionNotFoundException(io.apiman.manager.api.rest.exceptions.PlanVersionNotFoundException) PublishingException(io.apiman.gateway.engine.beans.exceptions.PublishingException) ClientVersionNotFoundException(io.apiman.manager.api.rest.exceptions.ClientVersionNotFoundException)

Example 23 with IGatewayLink

use of io.apiman.manager.api.gateway.IGatewayLink in project apiman by apiman.

the class OrganizationResourceImpl method getApiVersionEndpointInfoFromStorage.

private ApiVersionEndpointSummaryBean getApiVersionEndpointInfoFromStorage(ApiVersionBean apiVersion, String organizationId, String apiId, String version) throws GatewayNotFoundException, GatewayAuthenticationException, StorageException {
    Set<ApiGatewayBean> gateways = apiVersion.getGateways();
    if (gateways.isEmpty()) {
        // $NON-NLS-1$
        throw new SystemErrorException("No Gateways for published API!");
    }
    GatewayBean gateway = storage.getGateway(gateways.iterator().next().getGatewayId());
    if (gateway == null) {
        throw new GatewayNotFoundException();
    } else {
        // $NON-NLS-1$
        log.debug(String.format("Got endpoint summary: %s", gateway));
    }
    IGatewayLink link = gatewayLinkFactory.create(gateway);
    ApiEndpoint endpoint = link.getApiEndpoint(organizationId, apiId, version);
    ApiVersionEndpointSummaryBean rval = new ApiVersionEndpointSummaryBean();
    rval.setManagedEndpoint(endpoint.getEndpoint());
    return rval;
}
Also used : SystemErrorException(io.apiman.manager.api.rest.exceptions.SystemErrorException) ApiVersionEndpointSummaryBean(io.apiman.manager.api.beans.summary.ApiVersionEndpointSummaryBean) ApiGatewayBean(io.apiman.manager.api.beans.apis.ApiGatewayBean) ApiGatewayBean(io.apiman.manager.api.beans.apis.ApiGatewayBean) GatewayBean(io.apiman.manager.api.beans.gateways.GatewayBean) ApiEndpoint(io.apiman.gateway.engine.beans.ApiEndpoint) GatewayNotFoundException(io.apiman.manager.api.rest.exceptions.GatewayNotFoundException) IGatewayLink(io.apiman.manager.api.gateway.IGatewayLink)

Aggregations

IGatewayLink (io.apiman.manager.api.gateway.IGatewayLink)23 ApiGatewayBean (io.apiman.manager.api.beans.apis.ApiGatewayBean)19 StorageException (io.apiman.manager.api.core.exceptions.StorageException)17 GatewayBean (io.apiman.manager.api.beans.gateways.GatewayBean)15 ApiVersionBean (io.apiman.manager.api.beans.apis.ApiVersionBean)14 PublishingException (io.apiman.gateway.engine.beans.exceptions.PublishingException)13 GatewayNotFoundException (io.apiman.manager.api.rest.exceptions.GatewayNotFoundException)13 NotAuthorizedException (io.apiman.manager.api.rest.exceptions.NotAuthorizedException)11 ActionException (io.apiman.manager.api.rest.exceptions.ActionException)9 ApiVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ApiVersionNotFoundException)9 ClientVersionNotFoundException (io.apiman.manager.api.rest.exceptions.ClientVersionNotFoundException)9 PlanVersionNotFoundException (io.apiman.manager.api.rest.exceptions.PlanVersionNotFoundException)9 Date (java.util.Date)8 Api (io.apiman.gateway.engine.beans.Api)7 ClientVersionBean (io.apiman.manager.api.beans.clients.ClientVersionBean)7 SystemErrorException (io.apiman.manager.api.rest.exceptions.SystemErrorException)7 HashMap (java.util.HashMap)7 ApiBean (io.apiman.manager.api.beans.apis.ApiBean)6 PolicyBean (io.apiman.manager.api.beans.policies.PolicyBean)6 ArrayList (java.util.ArrayList)6