@Override public void listApis(String organizationId, int page, int pageSize, IAsyncResultHandler<List<String>> handler) { // For now, ignore paging, but it's there for future. Would need to ensure stable ordering. List<String> res = map.entrySet().stream() .map(Map.Entry::getValue) .filter(entity -> entity instanceof Api) .map(entity -> (Api) entity) .filter(api -> api.getOrganizationId().equals(organizationId)) .map(api -> api.getApiId()) .distinct() .collect(Collectors.toList()); handler.handle(AsyncResultImpl.create(res)); }
@Override public void listApiVersions(String organizationId, String apiId, int page, int pageSize, IAsyncResultHandler<List<String>> handler) { // For now, ignore paging, but it's there for future. Would need to ensure stable ordering. List<String> res = map.entrySet().stream() .map(Map.Entry::getValue) .filter(entity -> entity instanceof Api) .map(entity -> (Api) entity) .filter(api -> api.getOrganizationId().equals(organizationId) && api.getApiId().equals(apiId)) .map(api -> api.getVersion()) .distinct() .collect(Collectors.toList()); handler.handle(AsyncResultImpl.create(res)); }
@Override public void listApiVersions(String organizationId, String apiId, int page, int pageSize, IAsyncResultHandler<List<String>> handler) { // For now, ignore paging, but it's there for future. Would need to ensure stable ordering. List<String> res = map.entrySet().stream() .map(Map.Entry::getValue) .filter(entity -> entity instanceof Api) .map(entity -> (Api) entity) .filter(api -> api.getOrganizationId().equals(organizationId) && api.getApiId().equals(apiId)) .map(api -> api.getVersion()) .distinct() .collect(Collectors.toList()); handler.handle(AsyncResultImpl.create(res)); }
@Override public void listApis(String organizationId, int page, int pageSize, IAsyncResultHandler<List<String>> handler) { // For now, ignore paging, but it's there for future. Would need to ensure stable ordering. List<String> res = map.entrySet().stream() .map(Map.Entry::getValue) .filter(entity -> entity instanceof Api) .map(entity -> (Api) entity) .filter(api -> api.getOrganizationId().equals(organizationId)) .map(api -> api.getApiId()) .distinct() .collect(Collectors.toList()); handler.handle(AsyncResultImpl.create(res)); }
@Override public void listOrgs(IAsyncResultHandler<List<String>> handler) { // TODO: We should track set of OrgId -> AtomicCounter if this API has meaningfully high usage. List<String> res = map.entrySet().stream() .map(Map.Entry::getValue) .map(elem -> { if (elem instanceof Api) { return ((Api) elem).getOrganizationId(); } else { return ((Client) elem).getOrganizationId(); } }) .distinct() .collect(Collectors.toList()); handler.handle(AsyncResultImpl.create(res)); }
@Override public void listOrgs(IAsyncResultHandler<List<String>> handler) { // TODO: We should track set of OrgId -> AtomicCounter if this API has meaningfully high usage. List<String> res = map.entrySet().stream() .map(Map.Entry::getValue) .map(elem -> { if (elem instanceof Api) { return ((Api) elem).getOrganizationId(); } else { return ((Client) elem).getOrganizationId(); } }) .distinct() .collect(Collectors.toList()); handler.handle(AsyncResultImpl.create(res)); }
/** * Generates an in-memory key for an api, used to index the client for later quick * retrieval. * @param api an api * @return a api key */ private String getApiIndex(Api api) { return getApiIndex(api.getOrganizationId(), api.getApiId(), api.getVersion()); }
/** * Generates a valid document ID for a api, used to index the api in ES. * @param api an api * @return a api key */ private String getApiId(Api api) { return getApiId(api.getOrganizationId(), api.getApiId(), api.getVersion()); }
/** * Generates a valid document ID for a api, used to index the api in ES. * @param api an api * @return a api key */ private String getApiId(Api api) { return getApiId(api.getOrganizationId(), api.getApiId(), api.getVersion()); }
/** * Generates an in-memory key for an api, used to index the client for later quick * retrieval. * @param api an api * @return a api key */ private String getApiIndex(Api api) { return getApiIndex(api.getOrganizationId(), api.getApiId(), api.getVersion()); }
private String getApiIndex(Api api) { return getApiIndex(api.getOrganizationId(), api.getApiId(), api.getVersion()); }
private String getApiIndex(Api api) { return getApiIndex(api.getOrganizationId(), api.getApiId(), api.getVersion()); }
/** * @see io.apiman.gateway.engine.IRegistry#publishApi(io.apiman.gateway.engine.beans.Api, io.apiman.gateway.engine.async.IAsyncResultHandler) */ @Override public void publishApi(Api api, IAsyncResultHandler<Void> handler) { List<Policy> policies = api.getApiPolicies(); encryptPolicies(api.getOrganizationId(), api.getApiId(), api.getVersion(), EntityType.Api, policies); encryptEndpointProperties(api.getOrganizationId(), api.getApiId(), api.getVersion(), EntityType.Api, api.getEndpointProperties()); delegate.publishApi(api, handler); decryptPolicies(api.getOrganizationId(), api.getApiId(), api.getVersion(), EntityType.Api, policies); decryptEndpointProperties(api.getOrganizationId(), api.getApiId(), api.getVersion(), EntityType.Api, api.getEndpointProperties()); }
/** * @see io.apiman.gateway.engine.IRegistry#publishApi(io.apiman.gateway.engine.beans.Api, io.apiman.gateway.engine.async.IAsyncResultHandler) */ @Override public void publishApi(Api api, IAsyncResultHandler<Void> handler) { List<Policy> policies = api.getApiPolicies(); encryptPolicies(api.getOrganizationId(), api.getApiId(), api.getVersion(), EntityType.Api, policies); encryptEndpointProperties(api.getOrganizationId(), api.getApiId(), api.getVersion(), EntityType.Api, api.getEndpointProperties()); delegate.publishApi(api, handler); decryptPolicies(api.getOrganizationId(), api.getApiId(), api.getVersion(), EntityType.Api, policies); decryptEndpointProperties(api.getOrganizationId(), api.getApiId(), api.getVersion(), EntityType.Api, api.getEndpointProperties()); }
/** * @see io.apiman.gateway.engine.IRegistry#publishApi(io.apiman.gateway.engine.beans.Api, io.apiman.gateway.engine.async.IAsyncResultHandler) */ @Override public void publishApi(Api api, IAsyncResultHandler<Void> handler) { Connection conn = null; try { conn = ds.getConnection(); conn.setAutoCommit(false); QueryRunner run = new QueryRunner(); // First delete any record we might already have. run.update(conn, "DELETE FROM gw_apis WHERE org_id = ? AND id = ? AND version = ?", //$NON-NLS-1$ api.getOrganizationId(), api.getApiId(), api.getVersion()); // Now insert a row for the api. String bean = mapper.writeValueAsString(api); run.update(conn, "INSERT INTO gw_apis (org_id, id, version, bean) VALUES (?, ?, ?, ?)", //$NON-NLS-1$ api.getOrganizationId(), api.getApiId(), api.getVersion(), bean); DbUtils.commitAndClose(conn); handler.handle(AsyncResultImpl.create((Void) null, Void.class)); } catch (SQLException | JsonProcessingException e) { handler.handle(AsyncResultImpl.create(e)); } }
/** * @see io.apiman.manager.api.gateway.IGatewayLink#retireApi(io.apiman.gateway.engine.beans.Api) */ @Override public void retireApi(Api api) throws PublishingException, GatewayAuthenticationException { if (!isGatewayUp()) { throw new PublishingException(Messages.i18n.format("RestGatewayLink.GatewayNotRunning")); //$NON-NLS-1$ } getClient().retire(api.getOrganizationId(), api.getApiId(), api.getVersion()); }
/** * @see io.apiman.gateway.engine.IRegistry#retireApi(io.apiman.gateway.engine.beans.Api, io.apiman.gateway.engine.async.IAsyncResultHandler) */ @Override public void retireApi(Api api, IAsyncResultHandler<Void> handler) { QueryRunner run = new QueryRunner(ds); try { run.update("DELETE FROM gw_apis WHERE org_id = ? AND id = ? AND version = ?", //$NON-NLS-1$ api.getOrganizationId(), api.getApiId(), api.getVersion()); handler.handle(AsyncResultImpl.create((Void) null, Void.class)); } catch (SQLException e) { handler.handle(AsyncResultImpl.create(e)); } }
/** * @see io.apiman.gateway.engine.IRegistry#retireApi(io.apiman.gateway.engine.beans.Api, io.apiman.gateway.engine.async.IAsyncResultHandler) */ @Override public void retireApi(Api api, IAsyncResultHandler<Void> handler) { QueryRunner run = new QueryRunner(ds); try { run.update("DELETE FROM gw_apis WHERE org_id = ? AND id = ? AND version = ?", //$NON-NLS-1$ api.getOrganizationId(), api.getApiId(), api.getVersion()); handler.handle(AsyncResultImpl.create((Void) null, Void.class)); } catch (SQLException e) { handler.handle(AsyncResultImpl.create(e)); } }
@Override public void handle(IAsyncResult<ApiContract> result) { if (result.isSuccess()) { ApiContract contract = result.getResult(); List<Policy> policies = contract.getPolicies(); decryptPolicies(contract.getClient().getOrganizationId(), contract.getClient().getClientId(), contract.getClient().getVersion(), EntityType.ClientApp, policies); Api api = contract.getApi(); if (api != null) { List<Policy> apiPolicies = api.getApiPolicies(); decryptPolicies(api.getOrganizationId(), api.getApiId(), api.getVersion(), EntityType.Api, apiPolicies); decryptEndpointProperties(api.getOrganizationId(), api.getApiId(), api.getVersion(), EntityType.Api, api.getEndpointProperties()); } } handler.handle(result); } });
@Override public void handle(IAsyncResult<ApiContract> result) { if (result.isSuccess()) { ApiContract contract = result.getResult(); List<Policy> policies = contract.getPolicies(); decryptPolicies(contract.getClient().getOrganizationId(), contract.getClient().getClientId(), contract.getClient().getVersion(), EntityType.ClientApp, policies); Api api = contract.getApi(); if (api != null) { List<Policy> apiPolicies = api.getApiPolicies(); decryptPolicies(api.getOrganizationId(), api.getApiId(), api.getVersion(), EntityType.Api, apiPolicies); decryptEndpointProperties(api.getOrganizationId(), api.getApiId(), api.getVersion(), EntityType.Api, api.getEndpointProperties()); } } handler.handle(result); } });