Search in sources :

Example 6 with Workspace

use of org.modeshape.jcr.api.Workspace in project kylo by Teradata.

the class DebugController method getIndexes.

@GET
@Path("jcr-index")
@Produces(MediaType.APPLICATION_JSON)
public List<JcrIndexDefinition> getIndexes() {
    return metadata.read(() -> {
        this.accessController.checkPermission(AccessController.SERVICES, MetadataAccessControl.ACCESS_METADATA);
        try {
            Session session = JcrMetadataAccess.getActiveSession();
            Workspace workspace = (Workspace) session.getWorkspace();
            Map<String, IndexDefinition> indexDefinitionMap = workspace.getIndexManager().getIndexDefinitions();
            if (indexDefinitionMap != null) {
                return indexDefinitionMap.entrySet().stream().map((Map.Entry<String, IndexDefinition> e) -> {
                    JcrIndexDefinition indexDefinition = new JcrIndexDefinition();
                    StringBuffer names = new StringBuffer();
                    StringBuffer types = new StringBuffer();
                    for (int i = 0; i < e.getValue().size(); i++) {
                        if (i > 0) {
                            names.append(",");
                            types.append(",");
                        }
                        int columnType = e.getValue().getColumnDefinition(i).getColumnType();
                        String propertyName = e.getValue().getColumnDefinition(i).getPropertyName();
                        names.append(propertyName);
                        types.append(PropertyType.nameFromValue(columnType));
                    }
                    indexDefinition.setIndexKind(e.getValue().getKind().name());
                    indexDefinition.setIndexName(e.getKey());
                    indexDefinition.setNodeType(e.getValue().getNodeTypeName());
                    indexDefinition.setPropertyName(names.toString());
                    indexDefinition.setPropertyTypes(types.toString());
                    return indexDefinition;
                }).collect(Collectors.toList());
            } else {
                return Collections.emptyList();
            }
        } catch (RepositoryException e) {
            throw new RuntimeException(e);
        }
    });
}
Also used : IndexDefinition(org.modeshape.jcr.api.index.IndexDefinition) JcrIndexDefinition(com.thinkbiganalytics.metadata.rest.model.jcr.JcrIndexDefinition) RepositoryException(javax.jcr.RepositoryException) Map(java.util.Map) JcrIndexDefinition(com.thinkbiganalytics.metadata.rest.model.jcr.JcrIndexDefinition) Session(javax.jcr.Session) Workspace(org.modeshape.jcr.api.Workspace) Path(javax.ws.rs.Path) JcrPath(com.thinkbiganalytics.metadata.modeshape.support.JcrPath) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 7 with Workspace

use of org.modeshape.jcr.api.Workspace in project kylo by Teradata.

the class DebugController method reindex.

private RestResponseStatus reindex() {
    return metadata.commit(() -> {
        this.accessController.checkPermission(AccessController.SERVICES, MetadataAccessControl.ADMIN_METADATA);
        try {
            Session session = JcrMetadataAccess.getActiveSession();
            Workspace workspace = (Workspace) session.getWorkspace();
            workspace.reindex();
            return RestResponseStatus.SUCCESS;
        } catch (RepositoryException e) {
            throw new RuntimeException(e);
        }
    });
}
Also used : RepositoryException(javax.jcr.RepositoryException) Session(javax.jcr.Session) Workspace(org.modeshape.jcr.api.Workspace)

Example 8 with Workspace

use of org.modeshape.jcr.api.Workspace in project kylo by Teradata.

the class CreateDefaultUsersGroupsAction method upgradeTo.

/* (non-Javadoc)
     * @see com.thinkbiganalytics.metadata.upgrade.UpgradeState#upgradeFrom(com.thinkbiganalytics.metadata.api.app.KyloVersion)
     */
@Override
public void upgradeTo(KyloVersion startingVersion) {
    log.info("Creating default users/groups for version: " + startingVersion);
    User dladmin = createDefaultUser("dladmin", "Data Lake Administrator", null);
    User analyst = createDefaultUser("analyst", "Analyst", null);
    User designer = createDefaultUser("designer", "Designer", null);
    User operator = createDefaultUser("operator", "Operator", null);
    // Create default groups if they don't exist.
    UserGroup adminsGroup = createDefaultGroup("admin", "Administrators");
    UserGroup opsGroup = createDefaultGroup("operations", "Operations");
    UserGroup designersGroup = createDefaultGroup("designers", "Designers");
    UserGroup analystsGroup = createDefaultGroup("analysts", "Analysts");
    UserGroup usersGroup = createDefaultGroup("user", "Users");
    // Add default users to their respective groups
    adminsGroup.addUser(dladmin);
    designersGroup.addUser(designer);
    analystsGroup.addUser(analyst);
    opsGroup.addUser(operator);
    usersGroup.addUser(dladmin);
    usersGroup.addUser(analyst);
    usersGroup.addUser(designer);
    usersGroup.addUser(operator);
    // Setup initial group access control.  Administrators group already has all rights.
    actionsProvider.getAllowedActions(AllowedActions.SERVICES).ifPresent((allowed) -> {
        allowed.enable(opsGroup.getRootPrincial(), OperationsAccessControl.ADMIN_OPS, FeedServicesAccessControl.ACCESS_CATEGORIES, FeedServicesAccessControl.ACCESS_FEEDS, FeedServicesAccessControl.ACCESS_TEMPLATES, FeedServicesAccessControl.ACCESS_TABLES, FeedServicesAccessControl.ACCESS_SERVICE_LEVEL_AGREEMENTS);
        allowed.enable(designersGroup.getRootPrincial(), OperationsAccessControl.ACCESS_OPS, FeedServicesAccessControl.EDIT_FEEDS, FeedServicesAccessControl.ACCESS_TABLES, FeedServicesAccessControl.IMPORT_FEEDS, FeedServicesAccessControl.EXPORT_FEEDS, FeedServicesAccessControl.EDIT_CATEGORIES, FeedServicesAccessControl.EDIT_DATASOURCES, FeedServicesAccessControl.EDIT_TEMPLATES, FeedServicesAccessControl.IMPORT_TEMPLATES, FeedServicesAccessControl.EXPORT_TEMPLATES, FeedServicesAccessControl.ADMIN_TEMPLATES, FeedServicesAccessControl.ACCESS_SERVICE_LEVEL_AGREEMENTS, FeedServicesAccessControl.EDIT_SERVICE_LEVEL_AGREEMENTS, FeedServicesAccessControl.ACCESS_GLOBAL_SEARCH);
        allowed.enable(analystsGroup.getRootPrincial(), OperationsAccessControl.ACCESS_OPS, FeedServicesAccessControl.EDIT_FEEDS, FeedServicesAccessControl.ACCESS_TABLES, FeedServicesAccessControl.IMPORT_FEEDS, FeedServicesAccessControl.EXPORT_FEEDS, FeedServicesAccessControl.EDIT_CATEGORIES, FeedServicesAccessControl.ACCESS_TEMPLATES, FeedServicesAccessControl.ACCESS_DATASOURCES, FeedServicesAccessControl.ACCESS_SERVICE_LEVEL_AGREEMENTS, FeedServicesAccessControl.EDIT_SERVICE_LEVEL_AGREEMENTS, FeedServicesAccessControl.ACCESS_GLOBAL_SEARCH);
    });
    try {
        Workspace workspace = (Workspace) JcrMetadataAccess.getActiveSession().getWorkspace();
        workspace.reindex("/users");
        workspace.reindex("/groups");
    } catch (RepositoryException e) {
        log.error("Failed to re-index metadata", e);
        throw new UpgradeException("Failed to re-index metadata", e);
    }
}
Also used : UpgradeException(com.thinkbiganalytics.server.upgrade.UpgradeException) User(com.thinkbiganalytics.metadata.api.user.User) RepositoryException(javax.jcr.RepositoryException) UserGroup(com.thinkbiganalytics.metadata.api.user.UserGroup) Workspace(org.modeshape.jcr.api.Workspace)

Aggregations

Workspace (org.modeshape.jcr.api.Workspace)8 RepositoryException (javax.jcr.RepositoryException)7 Session (javax.jcr.Session)5 JcrPath (com.thinkbiganalytics.metadata.modeshape.support.JcrPath)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 POST (javax.ws.rs.POST)3 JcrIndexDefinition (com.thinkbiganalytics.metadata.rest.model.jcr.JcrIndexDefinition)2 UpgradeException (com.thinkbiganalytics.server.upgrade.UpgradeException)2 ApiOperation (io.swagger.annotations.ApiOperation)2 ApiResponses (io.swagger.annotations.ApiResponses)2 Consumes (javax.ws.rs.Consumes)2 Strings (com.google.common.base.Strings)1 MetadataAccess (com.thinkbiganalytics.metadata.api.MetadataAccess)1 MetadataEventService (com.thinkbiganalytics.metadata.api.event.MetadataEventService)1 FeedOperationStatusEvent (com.thinkbiganalytics.metadata.api.event.feed.FeedOperationStatusEvent)1 OperationStatus (com.thinkbiganalytics.metadata.api.event.feed.OperationStatus)1 FeedOperation (com.thinkbiganalytics.metadata.api.op.FeedOperation)1 MetadataAccessControl (com.thinkbiganalytics.metadata.api.security.MetadataAccessControl)1 FeedExecutedSinceFeed (com.thinkbiganalytics.metadata.api.sla.FeedExecutedSinceFeed)1