Search in sources :

Example 1 with Workspace

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

the class ReindexUpgradeAction method upgradeTo.

@Override
public void upgradeTo(final KyloVersion startingVersion) {
    log.info("Re-indexing metadata for version:: {}", startingVersion);
    try {
        Workspace workspace = (Workspace) JcrMetadataAccess.getActiveSession().getWorkspace();
        workspace.reindex();
    } 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) RepositoryException(javax.jcr.RepositoryException) Workspace(org.modeshape.jcr.api.Workspace)

Example 2 with Workspace

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

the class MetadataJcrConfigurator method ensureIndexes.

private void ensureIndexes(Session session) throws RepositoryException {
    Workspace workspace = (Workspace) session.getWorkspace();
    log.info("Indexing users and groups");
    workspace.reindex("/users");
    log.info("Finished indexing users");
    workspace.reindex("/groups");
    log.info("Finished indexing groups");
}
Also used : Workspace(org.modeshape.jcr.api.Workspace)

Example 3 with Workspace

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

the class DebugController method queryJcr.

/**
 * Prints the nodes of the JCR path given, for debugging.
 *
 * @param query the jcr query
 * @return a printout of the JCR tree
 */
@GET
@Path("jcr-sql")
@Produces({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
public JcrQueryResult queryJcr(@QueryParam("query") final String query) {
    return metadata.read(() -> {
        this.accessController.checkPermission(AccessController.SERVICES, MetadataAccessControl.ADMIN_METADATA);
        List<List<String>> rows = new ArrayList<>();
        Long startTime = System.currentTimeMillis();
        JcrQueryResult jcrQueryResult = new JcrQueryResult();
        try {
            Session session = JcrMetadataAccess.getActiveSession();
            Workspace workspace = (Workspace) session.getWorkspace();
            String explainPlain = JcrQueryUtil.explainPlain(session, query);
            // start the timer now:
            startTime = System.currentTimeMillis();
            QueryResult result = JcrQueryUtil.query(session, query);
            jcrQueryResult.setExplainPlan(explainPlain);
            RowIterator rowItr = result.getRows();
            List<JcrQueryResultColumn> columns = new ArrayList<>();
            String colsStr = StringUtils.substringAfter(query.toLowerCase(), "select");
            colsStr = StringUtils.substringBefore(colsStr, "from");
            if (StringUtils.isNotBlank(colsStr)) {
                colsStr = colsStr.trim();
                columns = Arrays.asList(colsStr.split(",")).stream().map(c -> {
                    String columnName = c;
                    if (c.contains("as ")) {
                        columnName = StringUtils.substringAfter(c, "as ");
                    } else if (c.contains(" ")) {
                        columnName = StringUtils.substringAfter(c, " ");
                    }
                    return new JcrQueryResultColumn(columnName);
                }).collect(Collectors.toList());
            }
            jcrQueryResult.setColumns(columns);
            while (rowItr.hasNext()) {
                Row row = rowItr.nextRow();
                Value[] rowValues = row.getValues();
                if (rowValues != null) {
                    if (rowValues.length != columns.size()) {
                        columns = IntStream.range(0, rowValues.length).mapToObj(i -> new JcrQueryResultColumn("Column " + i)).collect(Collectors.toList());
                        jcrQueryResult.setColumns(columns);
                    }
                    JcrQueryResultRow jcrQueryResultRow = new JcrQueryResultRow();
                    jcrQueryResult.addRow(jcrQueryResultRow);
                    List<JcrQueryResultColumnValue> jcrQueryResultColumnValues = Arrays.asList(rowValues).stream().map(v -> {
                        try {
                            String value = v.getString();
                            return new JcrQueryResultColumnValue(value);
                        } catch (Exception e) {
                            return new JcrQueryResultColumnValue("ERROR: " + e.getMessage());
                        }
                    }).collect(Collectors.toList());
                    jcrQueryResultRow.setColumnValues(jcrQueryResultColumnValues);
                }
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        long totalTime = System.currentTimeMillis() - startTime;
        jcrQueryResult.setQueryTime(totalTime);
        return jcrQueryResult;
    });
}
Also used : Arrays(java.util.Arrays) Produces(javax.ws.rs.Produces) JcrQueryResultRow(com.thinkbiganalytics.metadata.rest.model.jcr.JcrQueryResultRow) Metric(com.thinkbiganalytics.metadata.sla.api.Metric) JcrTools(org.modeshape.jcr.api.JcrTools) JcrQueryResult(com.thinkbiganalytics.metadata.rest.model.jcr.JcrQueryResult) Path(javax.ws.rs.Path) QueryResult(javax.jcr.query.QueryResult) FeedPrecondition(com.thinkbiganalytics.metadata.rest.model.feed.FeedPrecondition) Property(javax.jcr.Property) StringUtils(org.apache.commons.lang3.StringUtils) JcrTool(com.thinkbiganalytics.metadata.modeshape.support.JcrTool) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) JcrQueryResultColumn(com.thinkbiganalytics.metadata.rest.model.jcr.JcrQueryResultColumn) QueryParam(javax.ws.rs.QueryParam) JcrPath(com.thinkbiganalytics.metadata.modeshape.support.JcrPath) JcrQueryUtil(com.thinkbiganalytics.metadata.modeshape.support.JcrQueryUtil) IndexDefinition(org.modeshape.jcr.api.index.IndexDefinition) Consumes(javax.ws.rs.Consumes) WithinSchedule(com.thinkbiganalytics.metadata.api.sla.WithinSchedule) JcrQueryResultColumnValue(com.thinkbiganalytics.metadata.rest.model.jcr.JcrQueryResultColumnValue) Map(java.util.Map) AccessController(com.thinkbiganalytics.security.AccessController) DefaultValue(javax.ws.rs.DefaultValue) ModeshapeIndexUtil(com.thinkbiganalytics.metadata.modeshape.support.ModeshapeIndexUtil) Collector(java.util.stream.Collector) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) ParseException(java.text.ParseException) DELETE(javax.ws.rs.DELETE) PrintWriter(java.io.PrintWriter) JcrPropertyUtil(com.thinkbiganalytics.metadata.modeshape.support.JcrPropertyUtil) Context(javax.ws.rs.core.Context) Session(javax.jcr.Session) MetadataAccessControl(com.thinkbiganalytics.metadata.api.security.MetadataAccessControl) Set(java.util.Set) PropertyType(javax.jcr.PropertyType) MetadataEventService(com.thinkbiganalytics.metadata.api.event.MetadataEventService) Collectors(java.util.stream.Collectors) JcrIndexDefinition(com.thinkbiganalytics.metadata.rest.model.jcr.JcrIndexDefinition) List(java.util.List) Row(javax.jcr.query.Row) UriInfo(javax.ws.rs.core.UriInfo) JcrMetadataAccess(com.thinkbiganalytics.metadata.modeshape.JcrMetadataAccess) IntStream(java.util.stream.IntStream) PathParam(javax.ws.rs.PathParam) FeedOperationStatusEvent(com.thinkbiganalytics.metadata.api.event.feed.FeedOperationStatusEvent) GET(javax.ws.rs.GET) ApiResponses(io.swagger.annotations.ApiResponses) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) Strings(com.google.common.base.Strings) PathNotFoundException(javax.jcr.PathNotFoundException) RestResponseStatus(com.thinkbiganalytics.rest.model.RestResponseStatus) RepositoryException(javax.jcr.RepositoryException) RowIterator(javax.jcr.query.RowIterator) Node(javax.jcr.Node) FeedExecutedSinceFeed(com.thinkbiganalytics.metadata.api.sla.FeedExecutedSinceFeed) Api(io.swagger.annotations.Api) Tag(io.swagger.annotations.Tag) OperationStatus(com.thinkbiganalytics.metadata.api.event.feed.OperationStatus) FeedOperation(com.thinkbiganalytics.metadata.api.op.FeedOperation) FeedExecutedSinceSchedule(com.thinkbiganalytics.metadata.api.sla.FeedExecutedSinceSchedule) POST(javax.ws.rs.POST) Datasource(com.thinkbiganalytics.metadata.rest.model.data.Datasource) StringWriter(java.io.StringWriter) HiveTableDatasource(com.thinkbiganalytics.metadata.rest.model.data.HiveTableDatasource) Component(org.springframework.stereotype.Component) Value(javax.jcr.Value) SwaggerDefinition(io.swagger.annotations.SwaggerDefinition) ApiResponse(io.swagger.annotations.ApiResponse) Workspace(org.modeshape.jcr.api.Workspace) Collections(java.util.Collections) JcrQueryResultRow(com.thinkbiganalytics.metadata.rest.model.jcr.JcrQueryResultRow) ArrayList(java.util.ArrayList) JcrQueryResultColumn(com.thinkbiganalytics.metadata.rest.model.jcr.JcrQueryResultColumn) ParseException(java.text.ParseException) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException) JcrQueryResult(com.thinkbiganalytics.metadata.rest.model.jcr.JcrQueryResult) QueryResult(javax.jcr.query.QueryResult) JcrQueryResult(com.thinkbiganalytics.metadata.rest.model.jcr.JcrQueryResult) RowIterator(javax.jcr.query.RowIterator) JcrQueryResultColumnValue(com.thinkbiganalytics.metadata.rest.model.jcr.JcrQueryResultColumnValue) DefaultValue(javax.ws.rs.DefaultValue) Value(javax.jcr.Value) JcrQueryResultColumnValue(com.thinkbiganalytics.metadata.rest.model.jcr.JcrQueryResultColumnValue) List(java.util.List) ArrayList(java.util.ArrayList) JcrQueryResultRow(com.thinkbiganalytics.metadata.rest.model.jcr.JcrQueryResultRow) Row(javax.jcr.query.Row) 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 4 with Workspace

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

the class DebugController method registerIndex.

@POST
@Path("jcr-index/register")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("registers an index with modeshape")
@ApiResponses(@ApiResponse(code = 200, message = "registers an index with modeshape", response = String.class))
public RestResponseStatus registerIndex(JcrIndexDefinition indexDefinition) {
    return metadata.commit(() -> {
        this.accessController.checkPermission(AccessController.SERVICES, MetadataAccessControl.ADMIN_METADATA);
        try {
            Session session = JcrMetadataAccess.getActiveSession();
            Workspace workspace = (Workspace) session.getWorkspace();
            ModeshapeIndexUtil.registerIndex(workspace.getIndexManager(), indexDefinition.getIndexName(), IndexDefinition.IndexKind.valueOf(indexDefinition.getIndexKind().toUpperCase()), "local", indexDefinition.getNodeType(), indexDefinition.getDescription(), null, indexDefinition.getPropertyName(), indexDefinition.getPropertyType());
            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) Path(javax.ws.rs.Path) JcrPath(com.thinkbiganalytics.metadata.modeshape.support.JcrPath) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 5 with Workspace

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

the class DebugController method unregisterIndex.

@POST
@Path("jcr-index/{indexName}/unregister")
@Produces(MediaType.APPLICATION_JSON)
public RestResponseStatus unregisterIndex(@PathParam("indexName") String indexName) {
    return metadata.commit(() -> {
        this.accessController.checkPermission(AccessController.SERVICES, MetadataAccessControl.ADMIN_METADATA);
        try {
            Session session = JcrMetadataAccess.getActiveSession();
            Workspace workspace = (Workspace) session.getWorkspace();
            ModeshapeIndexUtil.unregisterIndex(workspace.getIndexManager(), indexName);
            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) Path(javax.ws.rs.Path) JcrPath(com.thinkbiganalytics.metadata.modeshape.support.JcrPath) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces)

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