Search in sources :

Example 1 with TransientException

use of ca.nrc.cadc.net.TransientException in project caom2db by opencadc.

the class InventoryClient method createTransferSync.

public Transfer createTransferSync(URI target, Direction direction, List<Protocol> protocolList) throws TransientException {
    Transfer transfer = new Transfer(target, direction);
    transfer.getProtocols().addAll(protocolList);
    transfer.version = VOS.VOSPACE_21;
    TransferWriter tw = new TransferWriter();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    try {
        tw.write(transfer, out);
    } catch (IOException ex) {
        String msg = "Failed to write transfer to output stream. ";
        throw new RuntimeException(msg + ex.getMessage());
    }
    FileContent content = new FileContent(out.toByteArray(), "text/xml");
    HttpPost post = new HttpPost(baseTransferURL, content, false);
    post.setConnectionTimeout(InventoryArtifactStore.DEFAULT_TIMEOUT);
    post.setReadTimeout(InventoryArtifactStore.DEFAULT_TIMEOUT);
    post.run();
    if (post.getThrowable() != null) {
        if (post.getThrowable() instanceof Exception) {
            if (post.getThrowable() instanceof AccessControlException) {
                throw (AccessControlException) post.getThrowable();
            } else {
                throw new IllegalStateException(post.getThrowable().getMessage());
            }
        } else {
            throw new RuntimeException(post.getThrowable());
        }
    }
    int respCode = post.getResponseCode();
    if (respCode != 200 && respCode != 201) {
        String msg = "Failed to create a transfer, received response code " + respCode;
        throw new RuntimeException(msg);
    }
    try {
        TransferReader tr = new TransferReader();
        Transfer result = tr.read(post.getInputStream(), target.getScheme());
        return result;
    } catch (TransferParsingException ex) {
        throw new TransientException(ex.getMessage());
    } catch (IOException ex) {
        throw new IllegalStateException("Failed to negotiate transfer, " + ex.getMessage());
    }
}
Also used : HttpPost(ca.nrc.cadc.net.HttpPost) AccessControlException(java.security.AccessControlException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) MalformedURLException(java.net.MalformedURLException) TransferParsingException(ca.nrc.cadc.vos.TransferParsingException) IOException(java.io.IOException) TransientException(ca.nrc.cadc.net.TransientException) AccessControlException(java.security.AccessControlException) FileContent(ca.nrc.cadc.net.FileContent) TransferReader(ca.nrc.cadc.vos.TransferReader) TransientException(ca.nrc.cadc.net.TransientException) Transfer(ca.nrc.cadc.vos.Transfer) HttpTransfer(ca.nrc.cadc.net.HttpTransfer) TransferParsingException(ca.nrc.cadc.vos.TransferParsingException) TransferWriter(ca.nrc.cadc.vos.TransferWriter)

Example 2 with TransientException

use of ca.nrc.cadc.net.TransientException in project caom2db by opencadc.

the class ReadAccessGenerator method checkProposalGroup.

private int checkProposalGroup(GroupURI groupURI) throws AccessControlException, IOException, TransientException {
    if (groupURI == null) {
        return 0;
    }
    int ret = 0;
    String proposalGroupName = groupURI.getName();
    Group proposalGroup = null;
    if (updatedProposalGroups.contains(proposalGroupName)) {
        log.debug("group recently updated: " + proposalGroupName);
    } else {
        try {
            proposalGroup = gmsClient.getGroup(proposalGroupName);
        } catch (IOException ioex) {
            throw new TransientException("GMSClient failed to get proposal group " + proposalGroupName, ioex);
        } catch (GroupNotFoundException ignore) {
        // try to create below
        }
        try {
            if (proposalGroup == null) {
                proposalGroup = new Group(groupURI);
                proposalGroup.getGroupAdmins().add(new Group(staffGroupURI));
                gmsClient.createGroup(proposalGroup);
                log.debug("created group: " + proposalGroupName);
            } else {
                Group g = new Group(staffGroupURI);
                if (!proposalGroup.getGroupAdmins().contains(g)) {
                    proposalGroup.getGroupAdmins().add(g);
                    try {
                        gmsClient.updateGroup(proposalGroup);
                        log.debug("updated group: " + proposalGroupName);
                    } catch (ReaderException | URISyntaxException oops) {
                        log.warn("updated group: " + proposalGroupName + "but GMSClient failed to read response... assuming OK");
                    }
                }
            }
        } catch (GroupNotFoundException ex) {
            throw new RuntimeException("CONFIG: group not found " + proposalGroupName + " or " + staffGroupURI + " for update");
        } catch (GroupAlreadyExistsException ex) {
            throw new RuntimeException("CONFIG: group collision " + proposalGroupName + " for create (right after negative check)");
        } catch (UserNotFoundException ex) {
            throw new RuntimeException("BUG: unexpected failure (reasons)", ex);
        } catch (WriterException ex) {
            throw new TransientException("failed to update proposal group: " + proposalGroupName, ex);
        }
        // cache groups we have already updated
        updatedProposalGroups.add(proposalGroupName);
        if (updatedProposalGroups.size() > 1000) {
            // remove the oldest few hundred to keep list size moderate
            for (int i = 0; i < 200; i++) {
                updatedProposalGroups.remove(0);
            }
        }
    }
    return ret;
}
Also used : UserNotFoundException(ca.nrc.cadc.ac.UserNotFoundException) Group(ca.nrc.cadc.ac.Group) GroupAlreadyExistsException(ca.nrc.cadc.ac.GroupAlreadyExistsException) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) ReaderException(ca.nrc.cadc.ac.ReaderException) TransientException(ca.nrc.cadc.net.TransientException) GroupNotFoundException(ca.nrc.cadc.ac.GroupNotFoundException) WriterException(ca.nrc.cadc.ac.WriterException)

Example 3 with TransientException

use of ca.nrc.cadc.net.TransientException in project caom2db by opencadc.

the class RepoAction method validate.

protected void validate(Observation obs) throws AccessControlException, IOException, TransientException {
    try {
        if (computeMetadata) {
            for (Plane p : obs.getPlanes()) {
                ComputeUtil.clearTransientState(p);
            }
        }
        CaomValidator.validate(obs);
        for (Plane pl : obs.getPlanes()) {
            for (Artifact a : pl.getArtifacts()) {
                CaomWCSValidator.validate(a);
            }
        }
        if (computeMetadata) {
            String ostr = obs.getCollection() + "/" + obs.getObservationID();
            String cur = ostr;
            try {
                for (Plane p : obs.getPlanes()) {
                    cur = ostr + "/" + p.getProductID();
                    ComputeUtil.computeTransientState(obs, p);
                }
            } catch (Error er) {
                throw new RuntimeException("failed to compute metadata for plane " + cur, er);
            } catch (Exception ex) {
                throw new IllegalArgumentException("failed to compute metadata for plane " + cur, ex);
            }
        }
        ReadAccessGenerator ratGenerator = getReadAccessTuplesGenerator(getCollection(), raGroupConfig);
        if (ratGenerator != null) {
            ratGenerator.generateTuples(obs);
        }
    } catch (IllegalArgumentException ex) {
        log.debug(ex.getMessage(), ex);
        throw new IllegalArgumentException("invalid input: " + uri + " reason: " + ex.getMessage(), ex);
    }
}
Also used : Plane(ca.nrc.cadc.caom2.Plane) ReadAccessGenerator(ca.nrc.cadc.caom2.ac.ReadAccessGenerator) Artifact(ca.nrc.cadc.caom2.Artifact) URISyntaxException(java.net.URISyntaxException) ResourceNotFoundException(ca.nrc.cadc.net.ResourceNotFoundException) ParseException(java.text.ParseException) ObservationParsingException(ca.nrc.cadc.caom2.xml.ObservationParsingException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) TransientException(ca.nrc.cadc.net.TransientException) UserNotFoundException(ca.nrc.cadc.ac.UserNotFoundException) AccessControlException(java.security.AccessControlException)

Example 4 with TransientException

use of ca.nrc.cadc.net.TransientException in project vos by opencadc.

the class NodeDAO method getPath.

/**
 * Get a complete path from the root container. For the container nodes in
 * the returned node, only child nodes on the path will be included in the
 * list of children; other children are not included. Nodes returned from
 * this method will have some but not all properties set. Specifically, any
 * properties that are inherently single-valued and stored in the Node table
 * are included, as are the access-control properties (isPublic, group-read,
 * and group-write). The remaining properties for a node can be obtained by
 * calling getProperties(Node).
 *
 * @see getProperties(Node)
 * @param path
 * @param allowPartialPath
 * @return the last node in the path, with all parents or null if not found
 */
public Node getPath(String path, boolean allowPartialPath, boolean resolveMetadata) throws TransientException {
    log.debug("getPath: " + path);
    if (path.length() > 0 && path.charAt(0) == '/')
        path = path.substring(1);
    // generate single join query to extract path
    NodePathStatementCreator npsc = new NodePathStatementCreator(path.split("/"), getNodeTableName(), getNodePropertyTableName(), allowPartialPath);
    TransactionStatus dirtyRead = null;
    try {
        dirtyRead = transactionManager.getTransaction(dirtyReadTransactionDef);
        prof.checkpoint("TransactionManager.getTransaction");
        // execute query with NodePathExtractor
        Node ret = (Node) jdbc.query(npsc, new NodePathExtractor());
        prof.checkpoint("NodePathStatementCreator");
        transactionManager.commit(dirtyRead);
        dirtyRead = null;
        prof.checkpoint("commit.NodePathStatementCreator");
        // for non-LinkNode,
        // if ((ret != null) && !(ret.getUri().getPath().equals("/" + path)))
        // {
        // if (!(ret instanceof LinkNode))
        // ret = null;
        // }
        getOwners(ret, resolveMetadata);
        return ret;
    } catch (CannotCreateTransactionException ex) {
        log.error("failed to create transaction: " + path, ex);
        dirtyRead = null;
        if (DBUtil.isTransientDBException(ex))
            throw new TransientException("failed to get node: " + path, ex);
        else
            throw new RuntimeException("failed to get node: " + path, ex);
    } catch (Throwable t) {
        if (dirtyRead != null)
            try {
                log.error("rollback dirtyRead for node: " + path, t);
                transactionManager.rollback(dirtyRead);
                dirtyRead = null;
                prof.checkpoint("rollback.NodePathStatementCreator");
            } catch (Throwable oops) {
                log.error("failed to dirtyRead rollback transaction", oops);
            }
        if (DBUtil.isTransientDBException(t))
            throw new TransientException("failed to get node " + path, t);
        else
            throw new RuntimeException("failed to get node: " + path, t);
    } finally {
        if (dirtyRead != null)
            try {
                log.warn("put: BUG - dirtyRead transaction still open in finally... calling rollback");
                transactionManager.rollback(dirtyRead);
            } catch (Throwable oops) {
                log.error("failed to rollback dirtyRead transaction in finally", oops);
            }
    }
}
Also used : TransientException(ca.nrc.cadc.net.TransientException) Node(ca.nrc.cadc.vos.Node) LinkNode(ca.nrc.cadc.vos.LinkNode) ContainerNode(ca.nrc.cadc.vos.ContainerNode) DataNode(ca.nrc.cadc.vos.DataNode) CannotCreateTransactionException(org.springframework.transaction.CannotCreateTransactionException) TransactionStatus(org.springframework.transaction.TransactionStatus)

Example 5 with TransientException

use of ca.nrc.cadc.net.TransientException in project vos by opencadc.

the class NodeDAO method getProperties.

/**
 * Load all the properties for the specified Node.
 *
 * @param node
 */
public void getProperties(Node node) throws TransientException {
    log.debug("getProperties: " + node.getUri().getPath() + ", " + node.getClass().getSimpleName());
    expectPersistentNode(node);
    log.debug("getProperties: " + node.getUri().getPath() + ", " + node.getClass().getSimpleName());
    String sql = getSelectNodePropertiesByID(node);
    log.debug("getProperties: " + sql);
    TransactionStatus dirtyRead = null;
    try {
        dirtyRead = transactionManager.getTransaction(dirtyReadTransactionDef);
        prof.checkpoint("TransactionManager.getTransaction");
        List<NodeProperty> props = jdbc.query(sql, new NodePropertyMapper());
        node.getProperties().addAll(props);
        prof.checkpoint("getProperties");
        transactionManager.commit(dirtyRead);
        dirtyRead = null;
        prof.checkpoint("commit.getProperties");
    } catch (CannotCreateTransactionException ex) {
        log.error("failed to create transaction: " + node.getUri().getPath(), ex);
        dirtyRead = null;
        if (DBUtil.isTransientDBException(ex))
            throw new TransientException("failed to get node: " + node.getUri().getPath(), ex);
        else
            throw new RuntimeException("failed to get node: " + node.getUri().getPath(), ex);
    } catch (Throwable t) {
        log.error("rollback dirtyRead for node: " + node.getUri().getPath(), t);
        try {
            transactionManager.rollback(dirtyRead);
            dirtyRead = null;
            prof.checkpoint("rollback.getProperties");
        } catch (Throwable oops) {
            log.error("failed to dirtyRead rollback transaction", oops);
        }
        if (DBUtil.isTransientDBException(t))
            throw new TransientException("failed to get node: " + node.getUri().getPath(), t);
        else
            throw new RuntimeException("failed to get node: " + node.getUri().getPath(), t);
    } finally {
        if (dirtyRead != null)
            try {
                log.warn("put: BUG - dirtyRead transaction still open in finally... calling rollback");
                transactionManager.rollback(dirtyRead);
            } catch (Throwable oops) {
                log.error("failed to rollback dirtyRead transaction in finally", oops);
            }
    }
}
Also used : NodeProperty(ca.nrc.cadc.vos.NodeProperty) TransientException(ca.nrc.cadc.net.TransientException) CannotCreateTransactionException(org.springframework.transaction.CannotCreateTransactionException) TransactionStatus(org.springframework.transaction.TransactionStatus)

Aggregations

TransientException (ca.nrc.cadc.net.TransientException)18 ContainerNode (ca.nrc.cadc.vos.ContainerNode)9 DataNode (ca.nrc.cadc.vos.DataNode)7 LinkNode (ca.nrc.cadc.vos.LinkNode)7 Node (ca.nrc.cadc.vos.Node)7 CannotCreateTransactionException (org.springframework.transaction.CannotCreateTransactionException)6 IOException (java.io.IOException)5 URISyntaxException (java.net.URISyntaxException)5 AccessControlException (java.security.AccessControlException)5 LinkingException (ca.nrc.cadc.vos.LinkingException)4 NodeProperty (ca.nrc.cadc.vos.NodeProperty)3 TransactionStatus (org.springframework.transaction.TransactionStatus)3 UserNotFoundException (ca.nrc.cadc.ac.UserNotFoundException)2 NotAuthenticatedException (ca.nrc.cadc.auth.NotAuthenticatedException)2 Artifact (ca.nrc.cadc.caom2.Artifact)2 Plane (ca.nrc.cadc.caom2.Plane)2 LongRowMapper (ca.nrc.cadc.db.LongRowMapper)2 ByteLimitExceededException (ca.nrc.cadc.io.ByteLimitExceededException)2 NodeLockedException (ca.nrc.cadc.vos.NodeLockedException)2 NodeNotFoundException (ca.nrc.cadc.vos.NodeNotFoundException)2