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); } }
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); } }
@PUT @Path("/{id}") @Timed public Response addOrUpdateDashboard(@PathParam("id") Long dashboardId, Dashboard dashboard) { Dashboard newDashboard = dashboardCatalogService.addOrUpdateDashboard(dashboardId, dashboard); return WSUtils.respondEntity(newDashboard, CREATED); }
@DELETE @Path("/{id}") @Timed public Response deleteDashboard(@PathParam("id") Long dashboardId) { Dashboard dashboard = dashboardCatalogService.removeDashboard(dashboardId); if (dashboard != null) { return WSUtils.respondEntity(dashboard, OK); } throw EntityNotFoundException.byId(dashboardId.toString()); }
@PUT @Path("/users/{id}") @Timed public Response addOrUpdateUser(@PathParam("id") Long userId, User user, @Context SecurityContext securityContext) { SecurityUtil.checkRole(authorizer, securityContext, ROLE_SECURITY_ADMIN); User newUser = catalogService.addOrUpdateUser(userId, user); return WSUtils.respondEntity(newUser, OK); }
@Timed @POST public Response addDashboard(Dashboard dashboard) { Dashboard createdDashboard = dashboardCatalogService.addDashboard(dashboard); return WSUtils.respondEntity(createdDashboard, CREATED); }
private Response removeCurrentTopologyVersion(Long topologyId) { Topology removedTopology = catalogService.removeTopology(topologyId, true); if (removedTopology != null) { return WSUtils.respondEntity(removedTopology, OK); } throw EntityNotFoundException.byId(topologyId.toString()); }
@GET @Produces(MediaType.APPLICATION_JSON) @Path("ml/models/pmml/{name}") @Timed public Response getMLModelContents(@PathParam("name") String modelName) { MLModel modelInfo = modelRegistryService.getModelInfo(modelName); return WSUtils.respondEntity(modelInfo.getPmml(), OK); } }
@DELETE @Path("/roles/{parentId}/children/{childId}") @Timed public Response deleteChildRole(@PathParam("parentId") Long parentId, @PathParam("childId") Long childId, @Context SecurityContext securityContext) throws Exception { SecurityUtil.checkRole(authorizer, securityContext, ROLE_SECURITY_ADMIN); RoleHierarchy roleHierarchy = catalogService.removeChildRole(parentId, childId); if (roleHierarchy != null) { return WSUtils.respondEntity(roleHierarchy, OK); } throw EntityNotFoundException.byId(childId.toString()); }
@GET @Path("/topologies/{topologyId}/deploymentstate") @Timed public Response topologyDeploymentState(@PathParam("topologyId") Long topologyId) throws Exception { return Optional.ofNullable(catalogService.getTopology(topologyId)) .flatMap(t -> catalogService.getTopologyState(t.getId())) .map(s -> WSUtils.respondEntity(s, OK)) .orElseThrow(() -> EntityNotFoundException.byId(topologyId.toString())); }
@DELETE @Path("/roles/{id}") @Timed public Response deleteRole(@PathParam("id") Long roleId, @Context SecurityContext securityContext) { SecurityUtil.checkRole(authorizer, securityContext, ROLE_SECURITY_ADMIN); Role role = catalogService.removeRole(roleId); if (role != null) { return WSUtils.respondEntity(role, OK); } throw EntityNotFoundException.byId(roleId.toString()); }
@DELETE @Path("/users/{id}") @Timed public Response deleteUser(@PathParam("id") Long userId, @Context SecurityContext securityContext) { SecurityUtil.checkRole(authorizer, securityContext, ROLE_SECURITY_ADMIN); User user = catalogService.removeUser(userId); if (user != null) { return WSUtils.respondEntity(user, OK); } throw EntityNotFoundException.byId(userId.toString()); }
@DELETE @Path("/system/topologyeditortoolbar/{id}") @Timed public Response removeTopologyEditorToolbar(@PathParam("id") Long userIdToBeDeleted, @Context SecurityContext securityContext) { SecurityUtil.checkPermissions(authorizer, securityContext, TopologyEditorToolbar.NAMESPACE, userIdToBeDeleted, Permission.DELETE); return catalogService.removeTopologyEditorToolbar(userIdToBeDeleted) .map(toolbar -> { SecurityUtil.removeAcl(authorizer, securityContext, TopologyEditorToolbar.NAMESPACE, userIdToBeDeleted); return WSUtils.respondEntity(toolbar, OK); }) .orElseThrow(() -> EntityNotFoundException.byId(String.valueOf(userIdToBeDeleted))); }
@PUT @Path("/acls/{id}") @Timed public Response addOrUpdateAcl(@PathParam("id") Long aclId, AclEntry aclEntry, @Context SecurityContext securityContext) { mayBeFillSidId(aclEntry); checkAclOp(aclEntry, securityContext, this::shouldAllowAclAddOrUpdate); AclEntry newAclEntry = catalogService.addOrUpdateAcl(aclId, aclEntry); return WSUtils.respondEntity(newAclEntry, OK); }
@GET @Path("/{dashboardId}/datasources/{datasourceId}") @Timed public Response getDatasource(@PathParam("dashboardId") Long dashboardId, @PathParam("datasourceId") Long datasourceId) { Datasource datasource = dashboardCatalogService.getDatasource(dashboardId, datasourceId); if (datasource != null) { return WSUtils.respondEntity(datasource, OK); } throw EntityNotFoundException.byId(getCompositeId(dashboardId, datasourceId)); }
@DELETE @Path("/{dashboardId}/datasources/{datasourceId}") @Timed public Response deleteDatasource(@PathParam("dashboardId") Long dashboardId, @PathParam("datasourceId") Long datasourceId) { Datasource datasource = dashboardCatalogService.removeDatasource(dashboardId, datasourceId); if (datasource != null) { return WSUtils.respondEntity(datasource, OK); } throw EntityNotFoundException.byId(getCompositeId(dashboardId, datasourceId)); }
@POST @Path("/acls") @Timed public Response addAcl(AclEntry aclEntry, @Context SecurityContext securityContext) { mayBeFillSidId(aclEntry); checkAclOp(aclEntry, securityContext, this::shouldAllowAclAddOrUpdate); AclEntry createdAcl = catalogService.addAcl(aclEntry); return WSUtils.respondEntity(createdAcl, CREATED); }
@PUT @Path("/componentbundles/{processor}/custom/upgrade") @Timed public Response upgradeCustomProcessorsWithDigest (@PathParam("processor") TopologyComponentBundle.TopologyComponentType componentType, @Context SecurityContext securityContext) throws Exception { SecurityUtil.checkRole(authorizer, securityContext, Roles.ROLE_TOPOLOGY_COMPONENT_BUNDLE_ADMIN); if (!TopologyComponentBundle.TopologyComponentType.PROCESSOR.equals(componentType)) { throw new CustomProcessorOnlyException(); } return WSUtils.respondEntity(catalogService.upgradeCustomProcessorsWithDigest(), OK); }
@DELETE @Path("/notifiers/{id}") @Timed public Response removeNotifierInfo(@PathParam("id") Long id, @Context SecurityContext securityContext) { SecurityUtil.checkPermissions(authorizer, securityContext, Notifier.NAMESPACE, id, DELETE); Notifier removedNotifier = catalogService.removeNotifierInfo(id); if (removedNotifier != null) { SecurityUtil.removeAcl(authorizer, securityContext, Notifier.NAMESPACE, id); return WSUtils.respondEntity(removedNotifier, OK); } throw EntityNotFoundException.byId(id.toString()); }
@GET @Path("/clusters/{clusterId}/services/hive/databases") @Timed public Response getDatabasesByClusterId(@PathParam("clusterId") Long clusterId, @Context SecurityContext securityContext) throws Exception { SecurityUtil.checkPermissions(authorizer, securityContext, Cluster.NAMESPACE, clusterId, READ); try(final HiveMetadataService hiveMetadataService = HiveMetadataService.newInstance(environmentService, clusterId, securityContext, subject)) { return WSUtils.respondEntity(hiveMetadataService.getHiveDatabases(), OK); } catch (EntityNotFoundException ex) { throw com.hortonworks.streamline.common.exception.service.exception.request.EntityNotFoundException.byId(ex.getMessage()); } }