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);
}
}
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");
}
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;
});
}
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);
}
});
}
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);
}
});
}
Aggregations