private Response buildNamespaceGetResponse(Namespace namespace, Boolean detail) { if (BooleanUtils.isTrue(detail)) { CatalogResourceUtil.NamespaceWithMapping namespaceWithMapping = CatalogResourceUtil.enrichNamespace(namespace, environmentService); return WSUtils.respondEntity(namespaceWithMapping, OK); } else { return WSUtils.respondEntity(namespace, OK); } }
/** * List all service bundles only the ones that match query params */ @GET @Path("/servicebundles") @Timed public Response listServiceBundles(@Context UriInfo uriInfo) { List<QueryParam> queryParams; MultivaluedMap<String, String> params = uriInfo.getQueryParameters(); queryParams = WSUtils.buildQueryParameters(params); Collection<ServiceBundle> serviceBundles = environmentService .listServiceBundles(queryParams); if (serviceBundles != null) { return WSUtils.respondEntities(serviceBundles, OK); } throw EntityNotFoundException.byFilter(queryParams.toString()); }
@GET @Path("/topologies/{topologyId}/versions") @Timed public Response listTopologyVersions(@PathParam("topologyId") Long topologyId, @Context SecurityContext securityContext) { SecurityUtil.checkRoleOrPermissions(authorizer, securityContext, Roles.ROLE_TOPOLOGY_USER, NAMESPACE, topologyId, READ); Collection<TopologyVersion> versionInfos = catalogService.listTopologyVersionInfos( WSUtils.buildTopologyIdAwareQueryParams(topologyId, null)); Response response; if (versionInfos != null) { response = WSUtils.respondEntities(versionInfos, OK); } else { response = WSUtils.respondEntities(Collections.emptyList(), OK); } return response; }
public static List<QueryParam> currentTopologyVersionQueryParam(Long topologyId, UriInfo uriInfo) { List<QueryParam> params = buildTopologyIdAwareQueryParams(topologyId, uriInfo); params.addAll(currentVersionQueryParam()); return params; }
public static List<QueryParam> buildTopologyIdAndVersionIdAwareQueryParams(Long topologyId, Long versionId, UriInfo uriInfo) { List<QueryParam> queryParams = new ArrayList<>(); queryParams.add(new QueryParam(TOPOLOGY_ID, topologyId.toString())); queryParams.addAll(versionIdQueryParam(versionId)); addQueryParams(uriInfo, queryParams); return queryParams; }
private Response buildClustersGetResponse(Collection<Cluster> clusters, Boolean detail) { if (BooleanUtils.isTrue(detail)) { List<ClusterResourceUtil.ClusterServicesImportResult> clustersWithServices = clusters.stream() .map(c -> ClusterResourceUtil.enrichCluster(c, environmentService)) .collect(Collectors.toList()); return WSUtils.respondEntities(clustersWithServices, OK); } else { return WSUtils.respondEntities(clusters, OK); } }
/** * @param uriInfo {@link UriInfo} from where to extract query parameters * @param queryParams {@link List<QueryParam>} to where add the query parameters extracted from {@link UriInfo} * @return the updated {@link List<QueryParam>} passed in the queryParams parameter * @throws NullPointerException if queryParams is null */ public static List<QueryParam> addQueryParams(UriInfo uriInfo, List<QueryParam> queryParams) { if (uriInfo != null) { MultivaluedMap<String, String> params = uriInfo.getQueryParameters(); if (!params.isEmpty()) { queryParams.addAll(WSUtils.buildQueryParameters(params)); } } return queryParams; }
private Response doGetAllSchemaVersionForBranch(String schemaName, String branchName) { try { LOG.info("Get all versions for schema : {}", schemaName); Collection<SchemaVersionInfo> schemaVersionInfos = schemaRegistryClient.getAllVersions(effectiveBranchName(branchName), schemaName); LOG.debug("Received schema versions [{}] from schema registry for schema: {}", schemaVersionInfos, schemaName); if (schemaVersionInfos != null && !schemaVersionInfos.isEmpty()) { List<String> schemaVersions = schemaVersionInfos.stream().map(x -> x.getVersion().toString()).collect(Collectors.toList()); return WSUtils.respondEntities(schemaVersions, OK); } else { return WSUtils.respondEntity(Collections.EMPTY_LIST, NOT_FOUND); } } catch (SchemaNotFoundException e) { LOG.error("Schema not found: [{}]", schemaName, e); throw EntityNotFoundException.byName(schemaName); } catch (Exception e) { throw new RuntimeException(e); } }
private Response deploy(Topology topology, SecurityContext securityContext) { String asUser = WSUtils.getUserFromSecurityContext(securityContext); try { ParallelStreamUtil.runAsync(() -> actionsService.deployTopology(topology, asUser), forkJoinPool); return WSUtils.respondEntity(topology, OK); } catch (TopologyAlreadyExistsOnCluster ex) { return ex.getResponse(); } }
@GET @Path("/topologies/{topologyId}/versions/{versionId}/rules") @Timed public Response listTopologySourcesForVersion(@PathParam("topologyId") Long topologyId, @PathParam("versionId") Long versionId, @Context UriInfo uriInfo, @Context SecurityContext securityContext) throws Exception { return listTopologyRules( buildTopologyIdAndVersionIdAwareQueryParams(topologyId, versionId, uriInfo), topologyId, securityContext); }
public static List<QueryParam> topologyVersionsQueryParam(Long topologyId) { List<QueryParam> params = buildTopologyIdAwareQueryParams(topologyId, null); return params; }
public Collection<TopologyVersion> listCurrentTopologyVersionInfos() { return listTopologyVersionInfos(currentVersionQueryParam()); }
private Collection<Topology> listTopologies(Long versionId) { Collection<Topology> topologies = this.dao.find(TOPOLOGY_NAMESPACE, versionIdQueryParam(versionId)); Long versionTimestamp = getVersionTimestamp(versionId); topologies.forEach(x -> x.setVersionTimestamp(versionTimestamp)); return topologies; }
private Response addRoleUsers(Long roleId, Set<Long> userIds) { List<UserRole> userRoles = new ArrayList<>(); userIds.forEach(userId -> { userRoles.add(catalogService.addUserRole(userId, roleId)); }); return WSUtils.respondEntities(userRoles, OK); }
private List<QueryParam> buildClusterIdAwareQueryParams(Long clusterId, UriInfo uriInfo) { List<QueryParam> queryParams = new ArrayList<>(); queryParams.add(new QueryParam("clusterId", clusterId.toString())); if (uriInfo != null) { MultivaluedMap<String, String> params = uriInfo.getQueryParameters(); if (!params.isEmpty()) { queryParams.addAll(WSUtils.buildQueryParameters(params)); } } return queryParams; }
@GET @Path("/topologies/{topologyId}/versions/{versionId}/sinks") @Timed public Response listTopologySinksForVersion(@PathParam("topologyId") Long topologyId, @PathParam("versionId") Long versionId, @Context UriInfo uriInfo, @Context SecurityContext securityContext) throws Exception { return listTopologySinks( buildTopologyIdAndVersionIdAwareQueryParams(topologyId, versionId, uriInfo), topologyId, securityContext); }
public Optional<TopologyVersion> getLatestVersionInfo(Long topologyId) { Collection<TopologyVersion> versions = listTopologyVersionInfos(WSUtils.buildTopologyIdAwareQueryParams(topologyId, null)); return versions.stream() .filter(v -> !v.getName().equals(CURRENT_VERSION)) .max((versionInfo1, versionInfo2) -> { // compares the number part from version strings like V1, V2 ... return versionInfo1.getVersionNumber() - versionInfo2.getVersionNumber(); }); } public TopologyVersion getTopologyVersionInfo(Long versionId) {
private Response buildClusterGetResponse(Cluster cluster, Boolean detail) { if (BooleanUtils.isTrue(detail)) { ClusterResourceUtil.ClusterServicesImportResult clusterWithServices = ClusterResourceUtil.enrichCluster(cluster, environmentService); return WSUtils.respondEntity(clusterWithServices, OK); } else { return WSUtils.respondEntity(cluster, OK); } }
@GET @Path("/files") @Timed public Response listFiles(@Context UriInfo uriInfo, @Context SecurityContext securityContext) { Collection<File> files = null; MultivaluedMap<String, String> params = uriInfo.getQueryParameters(); if (params == null || params.isEmpty()) { files = catalogService.listFiles(); } else { files = catalogService.listFiles(WSUtils.buildQueryParameters(params)); } Collection<File> result = SecurityUtil.filter(authorizer, securityContext, File.NAMESPACE, files, READ); return WSUtils.respondEntities(result, OK); }
private Response buildNamespacesGetResponse(Collection<Namespace> namespaces, Boolean detail) { if (BooleanUtils.isTrue(detail)) { List<CatalogResourceUtil.NamespaceWithMapping> namespacesWithMapping = namespaces.stream() .map(namespace -> CatalogResourceUtil.enrichNamespace(namespace, environmentService)) .collect(toList()); return WSUtils.respondEntities(namespacesWithMapping, OK); } else { return WSUtils.respondEntities(namespaces, OK); } }