Search in sources :

Example 46 with QueryParam

use of com.hortonworks.registries.common.QueryParam in project streamline by hortonworks.

the class SecurityCatalogService method removeUser.

public User removeUser(Long userId) {
    User userToRemove = getUser(userId);
    if (userToRemove != null) {
        if (userToRemove.getRoles() != null) {
            userToRemove.getRoles().forEach(roleName -> {
                Optional<Role> r = getRole(roleName);
                if (r.isPresent()) {
                    removeUserRole(userId, r.get().getId());
                }
            });
        }
        // remove permissions assigned to user
        LOG.debug("Removing ACL entries for user {}", userToRemove);
        List<QueryParam> qps = QueryParam.params(AclEntry.SID_ID, String.valueOf(userId), AclEntry.SID_TYPE, AclEntry.SidType.USER.toString());
        listAcls(qps).forEach(aclEntry -> removeAcl(aclEntry.getId()));
        return dao.remove(new StorableKey(User.NAMESPACE, userToRemove.getPrimaryKey()));
    }
    throw new IllegalArgumentException("No user with id: " + userId);
}
Also used : UserRole(com.hortonworks.streamline.streams.security.catalog.UserRole) Role(com.hortonworks.streamline.streams.security.catalog.Role) User(com.hortonworks.streamline.streams.security.catalog.User) QueryParam(com.hortonworks.registries.common.QueryParam) StorableKey(com.hortonworks.registries.storage.StorableKey)

Example 47 with QueryParam

use of com.hortonworks.registries.common.QueryParam in project streamline by hortonworks.

the class SecurityCatalogService method removeRole.

public Role removeRole(Long roleId) {
    // check if role is part of any parent roles, if so parent role should be deleted first.
    Set<Role> parentRoles = getParentRoles(roleId);
    if (!parentRoles.isEmpty()) {
        throw new IllegalStateException("Role is a child role of the following parent role(s): " + parentRoles + ". Parent roles must be deleted first.");
    }
    // check if role has any users
    List<QueryParam> qps = QueryParam.params(UserRole.ROLE_ID, String.valueOf(roleId));
    Collection<UserRole> userRoles = listUserRoles(qps);
    if (!userRoles.isEmpty()) {
        throw new IllegalStateException("Role has users");
    }
    // remove child role associations
    qps = QueryParam.params(RoleHierarchy.PARENT_ID, String.valueOf(roleId));
    Collection<RoleHierarchy> roleHierarchies = dao.find(RoleHierarchy.NAMESPACE, qps);
    LOG.info("Removing child role association for role id {}", roleId);
    roleHierarchies.forEach(rh -> removeChildRole(roleId, rh.getChildId()));
    // remove permissions assigned to role
    qps = QueryParam.params(AclEntry.SID_ID, String.valueOf(roleId), AclEntry.SID_TYPE, AclEntry.SidType.ROLE.toString());
    LOG.info("Removing ACL entries for role id {}", roleId);
    listAcls(qps).forEach(aclEntry -> removeAcl(aclEntry.getId()));
    Role role = new Role();
    role.setId(roleId);
    return dao.remove(new StorableKey(Role.NAMESPACE, role.getPrimaryKey()));
}
Also used : UserRole(com.hortonworks.streamline.streams.security.catalog.UserRole) Role(com.hortonworks.streamline.streams.security.catalog.Role) QueryParam(com.hortonworks.registries.common.QueryParam) UserRole(com.hortonworks.streamline.streams.security.catalog.UserRole) StorableKey(com.hortonworks.registries.storage.StorableKey) RoleHierarchy(com.hortonworks.streamline.streams.security.catalog.RoleHierarchy)

Example 48 with QueryParam

use of com.hortonworks.registries.common.QueryParam in project streamline by hortonworks.

the class DashboardCatalogResource method listWidgets.

@GET
@Path("/{dashboardId}/widgets")
@Timed
public Response listWidgets(@PathParam("dashboardId") Long dashboardId, @Context UriInfo uriInfo) {
    List<QueryParam> queryParams = buildDashboardIdAwareQueryParams(dashboardId, uriInfo);
    Collection<Widget> widgets = dashboardCatalogService.listWidgets(queryParams);
    if (widgets != null) {
        List<WidgetDto> dtos = new ArrayList<>();
        widgets.forEach(widget -> {
            WidgetDto dto = WidgetDto.fromWidget(widget);
            dto.setDatasourceIds(dashboardCatalogService.getWidgetDatasourceMapping(widget));
            dtos.add(dto);
        });
        return WSUtils.respondEntities(dtos, OK);
    }
    throw EntityNotFoundException.byFilter(queryParams.toString());
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) Widget(com.hortonworks.streamline.registries.dashboard.entites.Widget) ArrayList(java.util.ArrayList) WidgetDto(com.hortonworks.streamline.registries.dashboard.dto.WidgetDto) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 49 with QueryParam

use of com.hortonworks.registries.common.QueryParam in project streamline by hortonworks.

the class DashboardCatalogResource method buildDashboardIdAwareQueryParams.

public static List<QueryParam> buildDashboardIdAwareQueryParams(Long dashboardId, UriInfo uriInfo) {
    List<QueryParam> queryParams = new ArrayList<>();
    queryParams.add(new QueryParam(Dashboard.DASHBOARD_ID, dashboardId.toString()));
    if (uriInfo != null) {
        MultivaluedMap<String, String> params = uriInfo.getQueryParameters();
        if (!params.isEmpty()) {
            queryParams.addAll(WSUtils.buildQueryParameters(params));
        }
    }
    return queryParams;
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) ArrayList(java.util.ArrayList)

Example 50 with QueryParam

use of com.hortonworks.registries.common.QueryParam in project streamline by hortonworks.

the class StormTopologyDependenciesHandler method visit.

@Override
public void visit(RulesProcessor rulesProcessor) {
    Set<UDF> udfsToShip = new HashSet<>();
    for (Rule rule : rulesProcessor.getRules()) {
        for (Udf udf : rule.getReferredUdfs()) {
            List<QueryParam> qps = QueryParam.params(UDF.NAME, udf.getName());
            // The null check for backward compatibility
            if (udf.getClassName() != null) {
                qps.add(new QueryParam(UDF.CLASSNAME, udf.getClassName()));
            }
            // The null check for backward compatibility
            if (udf.getType() != null) {
                qps.add(new QueryParam(UDF.TYPE, udf.getType().toString()));
            }
            Collection<UDF> udfs = catalogService.listUDFs(qps);
            if (udfs.size() > 1) {
                throw new IllegalStateException("Multiple UDF definitions for :" + udf);
            } else if (udfs.size() == 1) {
                udfsToShip.add(udfs.iterator().next());
            } else {
                throw new IllegalStateException("No catalog entity for udf: '" + udf + "'. " + "May be the UDF information is not bootstrapped or got deleted.");
            }
        }
        for (UDF udf : udfsToShip) {
            extraJars.add(udf.getJarStoragePath());
        }
    }
    resourceNames.addAll(rulesProcessor.getExtraResources());
    handleBundleForStreamlineComponent(rulesProcessor);
}
Also used : QueryParam(com.hortonworks.registries.common.QueryParam) UDF(com.hortonworks.streamline.streams.catalog.UDF) Udf(com.hortonworks.streamline.streams.layout.component.rule.expression.Udf) Rule(com.hortonworks.streamline.streams.layout.component.rule.Rule) HashSet(java.util.HashSet)

Aggregations

QueryParam (com.hortonworks.registries.common.QueryParam)72 ArrayList (java.util.ArrayList)42 WSUtils.buildEdgesFromQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesFromQueryParam)22 WSUtils.buildEdgesToQueryParam (com.hortonworks.streamline.common.util.WSUtils.buildEdgesToQueryParam)22 WSUtils.currentVersionQueryParam (com.hortonworks.streamline.common.util.WSUtils.currentVersionQueryParam)22 WSUtils.versionIdQueryParam (com.hortonworks.streamline.common.util.WSUtils.versionIdQueryParam)22 IOException (java.io.IOException)8 SchemaNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaNotFoundException)7 StorableKey (com.hortonworks.registries.storage.StorableKey)7 OrderByField (com.hortonworks.registries.storage.OrderByField)6 HashSet (java.util.HashSet)6 SchemaVersionLifecycleContext (com.hortonworks.registries.schemaregistry.state.SchemaVersionLifecycleContext)5 TopologyComponentBundle (com.hortonworks.streamline.streams.catalog.topology.TopologyComponentBundle)5 Timed (com.codahale.metrics.annotation.Timed)4 Preconditions (com.google.common.base.Preconditions)4 SchemaBranchNotFoundException (com.hortonworks.registries.schemaregistry.errors.SchemaBranchNotFoundException)4 StorageException (com.hortonworks.registries.storage.exception.StorageException)4 TopologyTestRunCaseSource (com.hortonworks.streamline.streams.catalog.TopologyTestRunCaseSource)4 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4