public void setTransactionTimeout(long timeout) throws BagriException { if (timeout < 0) { throw new BagriException("negative timeout value is not supported", BagriException.ecTransaction); } this.txTimeout = timeout; }
@ManagedAttribute(description="Set transaction timeout in miliseconds. 0 means no timeout") public void setTransactionTimeout(long txTimeout) { try { txMgr.setTransactionTimeout(txTimeout); } catch (BagriException ex) { logger.error("setTransactionTimeout.error: " + ex.getMessage(), ex); } }
/** * a utility method to extract XQ exception information from the error stack provided * * @param ex the full error chain * @return XQ exception */ public static XQException getXQException(Throwable ex) { int errorCode = 0; Throwable cause = null; String message = ""; while (ex != null) { if (ex instanceof XQException) { return (XQException) ex; } else if (/*errorCode == 0 &&*/ ex instanceof BagriException) { // deeper is better! message += ex.getMessage() + "; "; errorCode = ((BagriException) ex).getErrorCode(); cause = ex; } ex = ex.getCause(); } XQException xqe = new XQException(message, String.valueOf(errorCode)); xqe.initCause(cause); return xqe; }
/** * {@inheritDoc} */ @Override public ParseResults parse(File file) throws BagriException { try (Reader reader = new FileReader(file)) { return parse(reader); } catch (IOException ex) { throw new BagriException(ex, BagriException.ecInOut); } }
@ManagedOperation(description="Returns Module functions") public String[] getDeclaredFunctions() { Module module = getEntity(); try { List<String> list = xqComp.getModuleFunctions(module); return list.toArray(new String[list.size()]); } catch (BagriException ex) { throw new RuntimeException(ex.getMessage()); } }
public void storeCustomerTest() throws Exception { long txId = 0; try { txId = getTxManagement().beginTransaction(); } catch (BagriException ex) { if (ex.getErrorCode() != BagriException.ecTransNoNested) { throw ex; } } uris.add(createDocumentTest(sampleRoot + getFileName("custacc.xml")).getUri()); if (txId > 0) { getTxManagement().commitTransaction(txId); } }
/** * {@inheritDoc} */ @Override public ParseResults parse(String xml) throws BagriException { try (Reader reader = new StringReader(xml)) { return parse(reader); } catch (IOException ex) { throw new BagriException(ex, BagriException.ecInOut); } }
public void afterInsert(Document doc, SchemaRepository repo) { logger.info("afterInsert.enter; doc: {}; repo: {}", doc, repo); try { Properties props = new Properties(); props.setProperty(pn_document_data_format, "XML"); DocumentAccessor da = repo.getDocumentManagement().getDocument(doc.getUri(), props); Security sec = da.getContent(); logger.info("afterInsert.exit; got security: {}/{}/{}", sec.getName(), sec.getSymbol(), sec.getId()); } catch (BagriException ex) { logger.info("afterInsert.error; got exception: {}", ex.getMessage()); } }
public void storeOrderTest() throws Exception { long txId = 0; try { txId = getTxManagement().beginTransaction(); } catch (BagriException ex) { if (ex.getErrorCode() != BagriException.ecTransNoNested) { throw ex; } } uris.add(createDocumentTest(sampleRoot + getFileName("order123.xml")).getUri()); uris.add(createDocumentTest(sampleRoot + getFileName("order654.xml")).getUri()); if (txId > 0) { getTxManagement().commitTransaction(txId); } }
public void checkClusterState() throws BagriException { if (checkState != HealthCheckState.skip) { if (!isClusterSafe()) { if (checkState == HealthCheckState.raise) { throw new BagriException("System is not healthy", BagriException.ecHealth); } else { // log unhealthy time here? logger.warn("System is not healthy"); } } } }
@ManagedOperation(description="Rollback in-flight transaction") @ManagedOperationParameters({ @ManagedOperationParameter(name = "txId", description = "Tx identifier")}) public boolean rollbackTransaction(long txId) { try { txMgr.rollbackTransaction(txId); return true; } catch (BagriException ex) { logger.error("rollbackTransaction.error: " + ex.getMessage(), ex); } return false; }
public void storeSecurityTest() throws Exception { long txId = 0; try { txId = getTxManagement().beginTransaction(); } catch (BagriException ex) { if (ex.getErrorCode() != BagriException.ecTransNoNested) { throw ex; } } uris.add(createDocumentTest(sampleRoot + getFileName("security1500.xml")).getUri()); uris.add(createDocumentTest(sampleRoot + getFileName("security5621.xml")).getUri()); uris.add(createDocumentTest(sampleRoot + getFileName("security9012.xml")).getUri()); uris.add(createDocumentTest(sampleRoot + getFileName("security29674.xml")).getUri()); if (txId > 0) { getTxManagement().commitTransaction(txId); } }
/** * {@inheritDoc} */ @Override public ParseResults parse(String json) throws BagriException { try (Reader reader = new StringReader(json)) { return parse(reader); } catch (IOException ex) { throw new BagriException(ex, BagriException.ecInOut); } }
@ManagedOperation(description="Commit in-flight transaction") @ManagedOperationParameters({ @ManagedOperationParameter(name = "txId", description = "Tx identifier")}) public boolean commitTransaction(long txId) { try { txMgr.commitTransaction(txId); return true; } catch (BagriException ex) { logger.error("commitTransaction.error: " + ex.getMessage(), ex); } return false; } @ManagedOperation(description="Rollback in-flight transaction")
/** * {@inheritDoc} */ @Override public ParseResults parse(File file) throws BagriException { try (Reader reader = new FileReader(file)) { return parse(reader); } catch (IOException ex) { throw new BagriException(ex, BagriException.ecInOut); } }
@ManagedOperation(description="Compiles registered Module") public boolean compileModule() { Module module = getEntity(); try { boolean result = true; xqComp.compileModule(module); ModuleReloader task = new ModuleReloader(module); Map<Member, Future<Boolean>> futures = execService.submitToMembers(task, new MemberSelector() { @Override public boolean select(Member member) { return !"admin".equalsIgnoreCase(member.getStringAttribute(pn_cluster_node_role)); } }); try { for (Map.Entry<Member, Future<Boolean>> e: futures.entrySet()) { if (!e.getValue().get()) { result = false; } } } catch (InterruptedException | ExecutionException ex) { logger.error("compileModule.error; {}", ex); result = false; } return result; } catch (BagriException ex) { throw new RuntimeException(ex.getMessage()); } }
private DocumentAccessor runSimpleDocumentTask(Callable<DocumentAccessor> task, Properties props) throws BagriException { //checkDocumentProperties(props); Future<DocumentAccessor> future = execService.submit(task); try { DocumentAccessor result = future.get(); logger.trace("storeDocument.exit; returning: {}", result); return (DocumentAccessor) result; } catch (InterruptedException | ExecutionException ex) { // the document could be processed anyway.. logger.error("runSimpleDocumentTask.error", ex); throw new BagriException(ex, ecDocument); } }
@ManagedOperation(description="Return Document Location Info") @ManagedOperationParameters({ @ManagedOperationParameter(name = "uri", description = "Document identifier")}) public CompositeData getDocumentLocation(String uri) { try { Properties props = new Properties(); props.setProperty("bdb.document.headers", String.valueOf(DocumentAccessor.HDR_URI)); DocumentAccessor doc = docManager.getDocument(uri, props); CompositeData result = null; if (doc != null) { int hash = schemaManager.getRepository().getDistributionStrategy().getDistributionHash(uri); Partition part = hzClient.getPartitionService().getPartition(hash); Map<String, Object> location = new HashMap<>(2); location.put("partition", part.getPartitionId()); location.put("owner", part.getOwner().toString()); result = JMXUtils.mapToComposite("document", "Document Location", location); } logger.debug("getDocumentLocation; returning: {}", result); return result; } catch (BagriException ex) { logger.error("getDocumentLocation.error: {}", ex.getMessage(), ex); throw new RuntimeException(ex.getMessage()); } }
/** * {@inheritDoc} */ public InputStream buildStream(Collection<Data> elements) throws BagriException { C content = buildContent(elements); if (content != null) { try { return new ByteArrayInputStream(((String) content).getBytes(def_encoding)); } catch (UnsupportedEncodingException ex) { throw new BagriException(ex, BagriException.ecInOut); } } return null; }
return result; } catch (BagriException ex) { logger.error("getDocumentInfo.error: {}", ex.getMessage(), ex); throw new RuntimeException(ex.getMessage());