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()));
}
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);
}
}
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;
}
Aggregations