use of com.thinkbiganalytics.metadata.api.MetadataAccessException in project kylo by Teradata.
the class DebugController method printJcrTree.
/**
* Prints the nodes of the JCR path given, for debugging.
*
* @param abspath the path in JCR
* @return a printout of the JCR tree
*/
@GET
@Path("jcr/{abspath: .*}")
@Produces({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
public String printJcrTree(@PathParam("abspath") final String abspath) {
return metadata.read(() -> {
this.accessController.checkPermission(AccessController.SERVICES, MetadataAccessControl.ACCESS_METADATA);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
try {
Session session = JcrMetadataAccess.getActiveSession();
java.nio.file.Path path = JcrPath.get(abspath);
try {
Item item = getItem(abspath, session);
printItem(item, pw);
} catch (PathNotFoundException e) {
return "Path not found: " + path.toString();
}
} catch (MetadataAccessException | MetadataExecutionException e) {
pw.println("Failed to get JCR node tree: " + e.getCause().getMessage());
log.error("Failed to get JCR node tree", e);
} catch (Exception e) {
e.printStackTrace(pw);
log.error("Failed to get JCR node tree", e);
}
pw.flush();
return sw.toString();
});
}
use of com.thinkbiganalytics.metadata.api.MetadataAccessException in project kylo by Teradata.
the class DebugController method printJcrId.
/**
* Prints the subgraph of the node in JCR with the specified ID.
*
* @param jcrId the id of the node in JCR
* @return the subgraph print out
*/
@GET
@Path("jcr")
@Produces({ MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON })
public String printJcrId(@QueryParam("id") final String jcrId) {
return metadata.read(() -> {
this.accessController.checkPermission(AccessController.SERVICES, MetadataAccessControl.ACCESS_METADATA);
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
// If the ID is over 36 characters long then assume it is a cache key and
// extract only the node ID portion of the key.
String nodeId = jcrId.length() > 36 ? jcrId.substring(jcrId.length() - 36, jcrId.length()) : jcrId;
try {
Session session = JcrMetadataAccess.getActiveSession();
Node node = session.getNodeByIdentifier(nodeId);
pw.print("Path: ");
pw.println(node.getPath());
JcrTools tools = new JcrTool(true, pw);
tools.printSubgraph(node);
} catch (MetadataAccessException | MetadataExecutionException e) {
pw.println("Failed to show JCR node with ID " + jcrId + ": " + e.getCause().getMessage());
log.error("Failed to show JCR node with ID: {}", jcrId, e);
} catch (Exception e) {
e.printStackTrace(pw);
log.error("Failed to show JCR node with ID: {}", jcrId, e);
}
pw.flush();
return sw.toString();
});
}
use of com.thinkbiganalytics.metadata.api.MetadataAccessException in project kylo by Teradata.
the class DebugController method deleteJcrTree.
/**
* Delete the JCR tree specified by the absolute path following ".../jcr/".
*
* @param abspath the path with JCR to delete
* @return a confirmation message that the path was deleted
*/
@DELETE
@Path("jcr/{abspath: .*}")
@Produces(MediaType.TEXT_PLAIN)
public String deleteJcrTree(@PathParam("abspath") final String abspath) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
try {
metadata.commit(() -> {
this.accessController.checkPermission(AccessController.SERVICES, MetadataAccessControl.ADMIN_METADATA);
Session session = JcrMetadataAccess.getActiveSession();
java.nio.file.Path path = JcrPath.get(abspath);
try {
Item item = getItem(abspath, session);
item.remove();
pw.print("DELETE " + abspath + " ");
} catch (PathNotFoundException e) {
pw.print("Path not found: " + path.toString());
}
});
} catch (MetadataAccessException | MetadataExecutionException e) {
pw.println("Failed to delete JCR node tree: " + e.getCause().getMessage());
log.error("Failed to delete JCR node tree: {}", abspath, e);
} catch (Exception e) {
e.printStackTrace(pw);
log.error("Failed to delete JCR node tree: {}", abspath, e);
}
pw.flush();
return sw.toString();
}
use of com.thinkbiganalytics.metadata.api.MetadataAccessException in project kylo by Teradata.
the class JcrMetadataAccess method commit.
public <R> R commit(Credentials creds, MetadataCommand<R> cmd, MetadataRollbackCommand rollbackCmd) {
ActiveSession active = activeSession.get();
if (active == null) {
try {
activeSession.set(new ActiveSession(this.repository.login(creds)));
try {
Exception failException = null;
while (failException == null) {
try {
return doCommit(creds, cmd, rollbackCmd);
} catch (MetadataLockException | LockException e) {
// If a lock acquisition failed then retry the command if the number of retries has not been exceeded.
if (activeSession.get().retriesRemaining > 0) {
activeSession.get().decrementRetry();
log.debug("Failed to aquire lock - retries remaining: {}", activeSession.get().retriesRemaining, e);
try {
Thread.sleep(activeSession.get().retryDelay);
} catch (InterruptedException ie) {
// Just continue.
}
// Start a new session before the retry.
activeSession.get().updateSession(this.repository.login(creds));
} else {
performPostTransactionActions(false);
failException = e;
}
} catch (Exception e) {
failException = e;
}
}
throw failException;
} finally {
activeSession.remove();
postTransactionActions.remove();
checkedOutNodes.remove();
}
} catch (RuntimeException e) {
throw e;
} catch (RepositoryException e) {
throw new MetadataAccessException("Failure accessing the metadata store", e);
} catch (Exception e) {
throw new MetadataExecutionException(e);
}
} else {
try {
return cmd.execute();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new MetadataExecutionException(e);
}
}
}
use of com.thinkbiganalytics.metadata.api.MetadataAccessException in project kylo by Teradata.
the class JcrMetadataAccess method read.
public <R> R read(Credentials creds, MetadataCommand<R> cmd) {
ActiveSession session = activeSession.get();
if (session == null) {
try {
activeSession.set(new ActiveSession(this.repository.login(creds)));
TransactionManager txnMgr = this.txnLookup.getTransactionManager();
try {
txnMgr.begin();
return execute(creds, cmd);
} finally {
try {
txnMgr.rollback();
} catch (SystemException e) {
log.error("Failed to rollback transaction", e);
}
activeSession.get().session.refresh(false);
activeSession.get().session.logout();
activeSession.remove();
}
} catch (SystemException | NotSupportedException | RepositoryException e) {
throw new MetadataAccessException("Failure accessing the metadata store", e);
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new MetadataExecutionException(e);
}
} else {
try {
return cmd.execute();
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new MetadataExecutionException(e);
}
}
}
Aggregations