Starting Elastic Search from java and not form any batch file - java

I ma totally new to this . . . I want to start Elastic search by java code say by a main method
`Node node = nodeBuilder().local( true ).node();
Client client = node.client();
node.start();`
I used the above code to run it which runs without error but it stops after two seconds only thing that i see in console is
log4j:WARN No appenders could be found for logger (org.elasticsearch.node).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Kindly help guys and here is the link of a similar question but it dint helped
starting elasticsearch instance from java?

If there is nothing else to your code, the issue is that the ES thread on it's own won't keep the program alive. You need to have a thread of your own to keep it alive.. for example:
BasicConfigurator.configure();
Node node = NodeBuilder.nodeBuilder().local(true).node();
node.start();
while (!node.isClosed()) {
try {
Thread.sleep(60*1000);
} catch (InterruptedException e) {
node.close();
}
}
node.stop();

Related

Can you send hierarchical logs to Graylog?

I want to send hierarchical logs to Graylog. Something like :
transactionId: 2a4c43ea-546a-4c31-afe6-4352446ef7ae Log: "start Instance"
transactionId: 50c45778-6c36-4d9f-93e6-5a7cf239ab61 Log: "query database"
"start Instance" would be the parent of "query database" and so on.
So far I did just a simple example, following this tutorial: [http://www.andrew-programming.com/2018/09/13/setup-graylog-on-local-machine-and-sent-logs-to-it-from-java-application/] sending some logs to Graylog like this:
Logger logger = LogManager.getLogger(DemoApplication.class);
logger.info("Application Start Running...");
logger.debug("Application Start Running...");
logger.error("Application Start Running...");
logger.warn("Application Start Running...");
logger.info("This a test");
But I need more then this. So basically I want to be able to send hierarchical logs , and also to be able to see them in Graylog UI as a hierarchy (this is very important to me and I am not sure this is possible). Can someone give some hints if this is possible and how?

Connecting Java logs and Traces traceId and span Id have the value of Zero

I am following the Connecting Java logs and Traces from the Datadog docs:
https://docs.datadoghq.com/tracing/connect_logs_and_traces/java/?tab=slf4jandlogback
I added the next code to my endpoint:
import org.slf4j.MDC;
import datadog.trace.api.CorrelationIdentifier;
// There must be spans started and active before this block.
try {
MDC.put("dd.trace_id", CorrelationIdentifier.getTraceId());
MDC.put("dd.span_id", CorrelationIdentifier.getSpanId());
// Log something
} finally {
MDC.remove("dd.trace_id");
MDC.remove("dd.span_id");
}
In the console I can see the next logs: dd.trace_id":"0","dd.span_id":"0"}
I am not pretty sure why I am not getting a correct trace_id and span_id and why these values are Zero.
Any ideas?

Getting java.sql.SQLException: Routine (cdc_endcapture) can not be resolved while initializing IfxCDCEngine builder on Informix Change Stream Client

Tried out this code for Informix Change Streams API for Java . from https://informix.hcldoc.com/14.10/help/index.jsp?topic=%2Fcom.ibm.cdc.doc%2Fids_cdc_streamapi.htm
I Keep on getting this error .Is there any fix for this or solution??
16:03:57.054 [main] DEBUG com.informix.stream.cdc.IfxCDCEngine - Closing down CDC engine
Exception in thread "main" java.sql.SQLException: Routine (cdc_opensess) can not be resolved.
at com.informix.util.IfxErrMsg.buildExceptionWithMessage(IfxErrMsg.java:422)
at com.informix.util.IfxErrMsg.buildIsamException(IfxErrMsg.java:401)
at com.informix.jdbc.IfxSqli.addException(IfxSqli.java:3022)
at com.informix.jdbc.IfxSqli.receiveError(IfxSqli.java:3273)
at com.informix.jdbc.IfxSqli.dispatchMsg(IfxSqli.java:2269)
at com.informix.jdbc.IfxSqli.receiveMessage(IfxSqli.java:2194)
at com.informix.jdbc.IfxSqli.executePrepare(IfxSqli.java:1194)
at com.informix.jdbc.IfxPreparedStatement.setupExecutePrepare(IfxPreparedStatement.java:245)
at com.informix.jdbc.IfxCallableStatement.<init>(IfxCallableStatement.java:143)
at com.informix.jdbc.IfxSqliConnect.prepareCall(IfxSqliConnect.java:5924)
at com.informix.jdbc.IfxSqliConnect.prepareCall(IfxSqliConnect.java:2499)
at com.informix.stream.cdc.IfxCDCEngine.init(IfxCDCEngine.java:177)
at com.example.informixchangestream.demo.CDCExDemoApplicationample.main(CDCExDemoApplicationample.java:33)
Suppressed: com.informix.stream.impl.IfxStreamException: Unable to end cdc capture
at com.informix.stream.cdc.IfxCDCEngine.endCapture(IfxCDCEngine.java:295)
at com.informix.stream.cdc.IfxCDCEngine.unwatchTable(IfxCDCEngine.java:275)
at com.informix.stream.cdc.IfxCDCEngine.close(IfxCDCEngine.java:343)
at com.example.informixchangestream.demo.CDCExDemoApplicationample.main(CDCExDemoApplicationample.java:52)
Caused by: java.sql.SQLException: Routine (cdc_endcapture) can not be resolved.
at com.informix.util.IfxErrMsg.buildExceptionWithMessage(IfxErrMsg.java:422)
at com.informix.util.IfxErrMsg.buildIsamException(IfxErrMsg.java:401)
at com.informix.jdbc.IfxSqli.addException(IfxSqli.java:3022)
at com.informix.jdbc.IfxSqli.receiveError(IfxSqli.java:3273)
at com.informix.jdbc.IfxSqli.dispatchMsg(IfxSqli.java:2269)
at com.informix.jdbc.IfxSqli.receiveMessage(IfxSqli.java:2194)
at com.informix.jdbc.IfxSqli.executePrepare(IfxSqli.java:1194)
at com.informix.jdbc.IfxPreparedStatement.setupExecutePrepare(IfxPreparedStatement.java:245)
at com.informix.jdbc.IfxCallableStatement.<init>(IfxCallableStatement.java:143)
at com.informix.jdbc.IfxSqliConnect.prepareCall(IfxSqliConnect.java:5924)
at com.informix.jdbc.IfxSqliConnect.prepareCall(IfxSqliConnect.java:2499)
at com.informix.stream.cdc.IfxCDCEngine.endCapture(IfxCDCEngine.java:282)
... 3 more
My code looks like this :
try (IfxCDCEngine engine = builder.build()) {
// initialize the engine (creates the connections and begins listening for
// changes)
engine.init();
IfmxStreamRecord record = null;
// This loop is where you can inject logic that compiles
// transactions, look for commits, throw away rollbacks
// The data here is all Java typed, so it can be easily then
// sent to MQTT, other JDBC drivers, streaming engines, or anything
// else you can think of.
while ((record = engine.getRecord()) != null) {
// Print out the basic record information
System.out.println("record changed");
System.out.println(record);
// If it is an insert/update/delete, print the column data
if (record.hasOperationData()) {
System.out.println("operation data");
System.out.println(((IfxCDCOperationRecord) record).getData());
}
}
}
This error is happens when the CDC routines are not found. Make sure that you first run the CDC setup script with the server to create the syscdcv1 database.
Then make sure your DataSource connects to the syscdcv1 database when you try CDC operations. It's not intuitive, but you 'connect' to the syscdcv1 database, then add watchers on databases and tables you are interested in getting the changes for.
Documentation on the CDC setup on the server is here, you need step #2 at least.
https://informix.hcldoc.com/14.10/help/index.jsp?topic=%2Fcom.ibm.cdc.doc%2Fids_cdc_streamapi.htm
A working example can be found here with a README and java code that you can use that might be easier to follow than the pages of the official docs
https://github.com/informix/informix-db-examples/tree/master/streaming/cdc

Java - Using JSch but getting an error when trying to move a file on FTP - %RNFR-bad%

I'm trying to use the rename functionality and keep getting this error.
Stacktrace:
3: %RNFR-bad%
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2873)
at com.jcraft.jsch.ChannelSftp.rename(ChannelSftp.java:1950)
...
Here's the method I'm using to move the file
private void moveFile(String sourcePath, String destinationPath) {
try {
System.out.println("Move: " + sourcePath + " to: " + destinationPath);
sftp.rename(sourcePath, destinationPath); //sftp = ChannelSftp
} catch (SftpException e) {
e.printStackTrace();
}
}
Here's the output for my println:
Move: /SND/OUTBOUND/TestOutboundFile1.txt to: /SND/OUTBOUND/PROCESSING/TestOutboundFile1.txt
I've tried some other options posted around on here (get then put, multiple connections, etc) but keep getting the same error or it just sits and hangs (this was happening with the get then put method). Everything I've seen on the web says this should be as easy as my method but I just can't seem to get it to work. Can't find anything with the "RNFR-bad" error that is useful either.
The destination directory already exists and it's empty. What am I missing? Any help much appreciated.
EDIT: This ended up being a permissions issue and the code posted above worked perfectly fine after the admin granted my account the correct permissions. I was able to create and delete both files and directories but was unable to rename files until account privs were modified.
3: %RNFR-bad%
SFTP error code 3 means "permission denied". This implies that you're getting an error because you don't have permission on the remote system to perform the file move operation that you're trying to do.
"%RNFR-bad%" doesn't seem to be meaningful. My guess is that the remote SFTP server is using localized messages and it doesn't have a proper message for this case, or it's malfunctioning in some other way.

How to log information in Forge?

I'm trying to log into using MinecraftServer.logInfo(), but I get a nosuchmethod exception.
server.logInfo("Example message");
I'm getting the instance of MinecraftServer in the server starting event.
MinecraftServer server = event.getServer();
An option for a fully fledged logger is
Logger logger = LogManager.getLogger(YourMod.MODID);
I'm pretty sure a simple
System.out.println("Information!");
Should do in forge.

Categories

Resources