Search in sources :

Example 1 with MetadataAccessException

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();
    });
}
Also used : Item(javax.jcr.Item) StringWriter(java.io.StringWriter) MetadataAccessException(com.thinkbiganalytics.metadata.api.MetadataAccessException) PathNotFoundException(javax.jcr.PathNotFoundException) MetadataExecutionException(com.thinkbiganalytics.metadata.api.MetadataExecutionException) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) VersionException(javax.jcr.version.VersionException) ParseException(java.text.ParseException) MetadataAccessException(com.thinkbiganalytics.metadata.api.MetadataAccessException) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException) LockException(javax.jcr.lock.LockException) ValueFormatException(javax.jcr.ValueFormatException) MetadataExecutionException(com.thinkbiganalytics.metadata.api.MetadataExecutionException) PrintWriter(java.io.PrintWriter) Session(javax.jcr.Session) Path(javax.ws.rs.Path) JcrPath(com.thinkbiganalytics.metadata.modeshape.support.JcrPath) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with MetadataAccessException

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();
    });
}
Also used : StringWriter(java.io.StringWriter) MetadataAccessException(com.thinkbiganalytics.metadata.api.MetadataAccessException) Node(javax.jcr.Node) JcrTool(com.thinkbiganalytics.metadata.modeshape.support.JcrTool) MetadataExecutionException(com.thinkbiganalytics.metadata.api.MetadataExecutionException) JcrTools(org.modeshape.jcr.api.JcrTools) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) VersionException(javax.jcr.version.VersionException) ParseException(java.text.ParseException) MetadataAccessException(com.thinkbiganalytics.metadata.api.MetadataAccessException) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException) LockException(javax.jcr.lock.LockException) ValueFormatException(javax.jcr.ValueFormatException) MetadataExecutionException(com.thinkbiganalytics.metadata.api.MetadataExecutionException) PrintWriter(java.io.PrintWriter) Session(javax.jcr.Session) Path(javax.ws.rs.Path) JcrPath(com.thinkbiganalytics.metadata.modeshape.support.JcrPath) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with MetadataAccessException

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();
}
Also used : Item(javax.jcr.Item) StringWriter(java.io.StringWriter) MetadataAccessException(com.thinkbiganalytics.metadata.api.MetadataAccessException) PathNotFoundException(javax.jcr.PathNotFoundException) MetadataExecutionException(com.thinkbiganalytics.metadata.api.MetadataExecutionException) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) VersionException(javax.jcr.version.VersionException) ParseException(java.text.ParseException) MetadataAccessException(com.thinkbiganalytics.metadata.api.MetadataAccessException) PathNotFoundException(javax.jcr.PathNotFoundException) RepositoryException(javax.jcr.RepositoryException) LockException(javax.jcr.lock.LockException) ValueFormatException(javax.jcr.ValueFormatException) MetadataExecutionException(com.thinkbiganalytics.metadata.api.MetadataExecutionException) PrintWriter(java.io.PrintWriter) Session(javax.jcr.Session) Path(javax.ws.rs.Path) JcrPath(com.thinkbiganalytics.metadata.modeshape.support.JcrPath) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces)

Example 4 with MetadataAccessException

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);
        }
    }
}
Also used : LockException(javax.jcr.lock.LockException) MetadataLockException(com.thinkbiganalytics.metadata.modeshape.support.MetadataLockException) MetadataAccessException(com.thinkbiganalytics.metadata.api.MetadataAccessException) MetadataLockException(com.thinkbiganalytics.metadata.modeshape.support.MetadataLockException) RepositoryException(javax.jcr.RepositoryException) MetadataExecutionException(com.thinkbiganalytics.metadata.api.MetadataExecutionException) MetadataAccessException(com.thinkbiganalytics.metadata.api.MetadataAccessException) RepositoryException(javax.jcr.RepositoryException) LockException(javax.jcr.lock.LockException) MetadataLockException(com.thinkbiganalytics.metadata.modeshape.support.MetadataLockException) MetadataExecutionException(com.thinkbiganalytics.metadata.api.MetadataExecutionException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException)

Example 5 with MetadataAccessException

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);
        }
    }
}
Also used : SystemException(javax.transaction.SystemException) TransactionManager(javax.transaction.TransactionManager) MetadataAccessException(com.thinkbiganalytics.metadata.api.MetadataAccessException) RepositoryException(javax.jcr.RepositoryException) MetadataExecutionException(com.thinkbiganalytics.metadata.api.MetadataExecutionException) NotSupportedException(javax.transaction.NotSupportedException) MetadataAccessException(com.thinkbiganalytics.metadata.api.MetadataAccessException) RepositoryException(javax.jcr.RepositoryException) LockException(javax.jcr.lock.LockException) MetadataLockException(com.thinkbiganalytics.metadata.modeshape.support.MetadataLockException) MetadataExecutionException(com.thinkbiganalytics.metadata.api.MetadataExecutionException) NotSupportedException(javax.transaction.NotSupportedException) SystemException(javax.transaction.SystemException)

Aggregations

MetadataAccessException (com.thinkbiganalytics.metadata.api.MetadataAccessException)6 MetadataExecutionException (com.thinkbiganalytics.metadata.api.MetadataExecutionException)6 RepositoryException (javax.jcr.RepositoryException)6 LockException (javax.jcr.lock.LockException)6 JcrPath (com.thinkbiganalytics.metadata.modeshape.support.JcrPath)4 PrintWriter (java.io.PrintWriter)4 StringWriter (java.io.StringWriter)4 ParseException (java.text.ParseException)4 PathNotFoundException (javax.jcr.PathNotFoundException)4 Session (javax.jcr.Session)4 ValueFormatException (javax.jcr.ValueFormatException)4 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)4 VersionException (javax.jcr.version.VersionException)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 Item (javax.jcr.Item)3 MetadataLockException (com.thinkbiganalytics.metadata.modeshape.support.MetadataLockException)2 Node (javax.jcr.Node)2 NotSupportedException (javax.transaction.NotSupportedException)2 SystemException (javax.transaction.SystemException)2