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