Hello I am trying to connect a Java Maven application to Cassandra with hector. The code is very simple
imports......
public class App {
public static void main( String[] args ){
Cluster cluster = HFactory.getOrCreateCluster("TestCluster",
new CassandraHostConfigurator("localhost:9042"));
}
}
}
When I run it I have these exceptions:
log4j:WARN No appenders could be found for logger (me.prettyprint.cassandra.connection.CassandraHostRetryService).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
I think I need to set up something but I cannot find what it is.
You need a log4j properties file. From the Hector docs:
Run your application with the following parameter:
-Dlog4j.configuration=file:///path/to/log4j.properties
Where log4j.properties contains:
log4j.rootLogger=DEBUG,stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.SimpleLayout
Log4J is very powerful, check out the project site for more information.
Related
I downloaded Ignite 2.5.0 (I use maven dependences in Eclipse on a Mac for my Java class), and I tried to start Ignite with a configuration file given with an absolute path:
public static void main(String [] args) throws Exception {
try (Ignite ignite = Ignition.start("/Users/ahajnal/Documents/git/ignite/target/classes/default-config.xml")) {}
}
but I got exception:
Exception in thread "main" class org.apache.ignite.IgniteException: Failed to find configuration in: file:/Users/ahajnal/Documents/git/ignite/target/classes/default-config.xml
at org.apache.ignite.internal.util.IgniteUtils.convertException(IgniteUtils.java:990)
at org.apache.ignite.Ignition.start(Ignition.java:355)
at hu.sztaki.lpds.ml.ignite.WekaIgnite.main(WekaIgnite.java:82)
Caused by: class org.apache.ignite.IgniteCheckedException: Failed to find configuration in: file:/Users/ahajnal/Documents/git/ignite/target/classes/default-config.xml
at org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl.loadConfigurations(IgniteSpringHelperImpl.java:116)
at org.apache.ignite.internal.util.spring.IgniteSpringHelperImpl.loadConfigurations(IgniteSpringHelperImpl.java:98)
at org.apache.ignite.internal.IgnitionEx.loadConfigurations(IgnitionEx.java:744)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:945)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:854)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:724)
at org.apache.ignite.internal.IgnitionEx.start(IgnitionEx.java:693)
at org.apache.ignite.Ignition.start(Ignition.java:352)
... 1 more
The config file is there:
$ cat /Users/ahajnal/Documents/git/ignite/target/classes/default-config.xml
<?xml version="1.0" encoding="UTF-8"?>...
and:
new File("/Users/ahajnal/Documents/git/ignite/target/classes/default-config.xml").exists() is true
According to docs this path can be absolute.
What am I doing wrong?
Thank you.
I think, the problem is that default-config.xml file has only abstract IgniteConfiguration. This is the case in the default configuration file in examples.
Check, if the configuration bean's definition has abstract=true parameter, and remove it if it does.
P.S.
Creating Ignite as a resource of a try block is a pretty bad idea, since the node will stop right after execution of the try block is finished.
Who knows why class HiveConf has no HADOOPCONF enum type in hive-common jar now?
I write code using hive-common-1.2.1.jar HiveConf class to access HDFS(HA namenode), and I get an error below.
I realized my code didn't config HADOOPCONF so it can't connect to HDFS, but there is no HADOOPCONF in hive-common-1.2.1.jar any more, I found previous version of hive-common has the HADOOPCONF.
http://www.docjar.com/html/api/org/apache/hadoop/hive/conf/HiveConf.java.html
My question is how can I config to access HDFS(namenode HA) with HiveConf class by using hive-common-1.2.1.jar?
Here is the error:
Caused by: java.lang.IllegalArgumentException: java.net.UnknownHostException: cluster
at org.apache.hadoop.security.SecurityUtil.buildTokenService(SecurityUtil.java:374)
at org.apache.hadoop.hdfs.NameNodeProxies.createNonHAProxy(NameNodeProxies.java:312)
at org.apache.hadoop.hdfs.NameNodeProxies.createProxy(NameNodeProxies.java:178)
at org.apache.hadoop.hdfs.DFSClient.<init>(DFSClient.java:665)
My code is:
hiveConf.setVar(HiveConf.ConfVars.HADOOPBIN, "/opt/modules/hadoop/bin");
hiveConf.setVar(HiveConf.ConfVars.HADOOPFS, "hdfs://cluster");
hiveConf.setVar(HiveConf.ConfVars.LOCALSCRATCHDIR, "/opt/modules/hive/temp");
hiveConf.setVar(HiveConf.ConfVars.DOWNLOADED_RESOURCES_DIR, "/opt/modules/hive/temp");
hiveConf.setBoolVar(HiveConf.ConfVars.HIVE_SUPPORT_CONCURRENCY, false);
hiveConf.setVar(HiveConf.ConfVars.METASTOREWAREHOUSE, "/warehouse");
hiveConf.setVar(HiveConf.ConfVars.METASTOREURIS, "thrift://127.0.0.1:9083");
hiveConf.setVar(HiveConf.ConfVars.METASTORE_CONNECTION_DRIVER, "com.mysql.jdbc.Driver");
hiveConf.setVar(HiveConf.ConfVars.METASTORECONNECTURLKEY, "jdbc:mysql://192.168.5.29:3306/hive?createDatabaseIfNotExist=true");
hiveConf.setVar(HiveConf.ConfVars.METASTORE_CONNECTION_USER_NAME, "hive");
hiveConf.setVar(HiveConf.ConfVars.METASTOREPWD, "123456");
hiveConf.setVar(HiveConf.ConfVars.HIVEHISTORYFILELOC, "/opt/modules/hive/temp");
OK, I resolved this issue.
Because the class HiveConf in hive-common jar load "hdfs-site.xml" from hadoop by default, if only you set the classpath pointed to the folder of "hdfs-site.xml" when you running it.
CLASSPATH=$CLASSPATH:/opt/modules/hadoop/conf
$JAVA -cp $CLASSPATH com.baofeng.data.writer.HiveHcatalogWriter
I'm attempting to use Apache Curator with a dockerized zookeeper instance and no matter how I attempt to connect I always end up with a
org.apache.zookeeper.KeeperException$UnimplementedException:
KeeperErrorCode = Unimplemented for...
error. I've tried making sense of the documentation but I'm not getting anywhere. I've logged into the zookeeper CLI and ensured the port number is correct thusly:
snerd#powerglove:~$ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 31f1093495ba compose_zookeeper "/opt/zookeeper/bin/ 3 weeks ago Up About a minute 0.0.0.0:32770->2181/tcp,
0.0.0.0:32769->2888/tcp, 0.0.0.0:32768->3888/tcp zookeeper
here is the code I'm trying to use:
public class App {
public static void main( String[] args ) {
CuratorFramework client = CuratorFrameworkFactory.newClient("0.0.0.0:32770", new RetryUntilElapsed(3000, 1000));
client.start();
try {
client.create().forPath("/larry-smells/foop", "tuna?".getBytes());
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
As far as I can tell from the Curator getting started page, this should work. What am I missing?
edit1
just figured out that I'm able to pull data out of the zookeeper ensemble thusly:
System.out.println(new String(curatorFramework.getData().forPath("/larry-smells")));
but the create command is still blowing up.
edit2
stacktrace of the error:
org.apache.zookeeper.KeeperException$UnimplementedException:
KeeperErrorCode = Unimplemented for /larry-smells/foop at
org.apache.zookeeper.KeeperException.create(KeeperException.java:103)
at
org.apache.zookeeper.KeeperException.create(KeeperException.java:51)
at org.apache.zookeeper.ZooKeeper.create(ZooKeeper.java:1297) at
org.apache.curator.framework.imps.CreateBuilderImpl$17.call(CreateBuilderImpl.java:1040)
at
org.apache.curator.framework.imps.CreateBuilderImpl$17.call(CreateBuilderImpl.java:1023)
at
org.apache.curator.connection.StandardConnectionHandlingPolicy.callWithRetry(StandardConnectionHandlingPolicy.java:67)
at org.apache.curator.RetryLoop.callWithRetry(RetryLoop.java:99) at
org.apache.curator.framework.imps.CreateBuilderImpl.pathInForeground(CreateBuilderImpl.java:1020)
at
org.apache.curator.framework.imps.CreateBuilderImpl.protectedPathInForeground(CreateBuilderImpl.java:501)
at
org.apache.curator.framework.imps.CreateBuilderImpl.forPath(CreateBuilderImpl.java:491)
at
org.apache.curator.framework.imps.CreateBuilderImpl$4.forPath(CreateBuilderImpl.java:367)
at
org.apache.curator.framework.imps.CreateBuilderImpl$4.forPath(CreateBuilderImpl.java:309)
at com.mycompany.app.App.main(App.java:35)
Edit: Apparently this error can occur if you're using the wrong combination of Curator in combination with Zookeeper. From curator.apache.org :
Curator 2.x.x - compatible with both ZooKeeper 3.4.x and ZooKeeper 3.5.x
Curator 3.x.x - compatible only with ZooKeeper 3.5.x and includes support for new features such as dynamic reconfiguration, etc.
It's hard to pinpoint your problem with only that error-code and not a stack trace, but some improvements I would suggest to make your application more stable is:
public class App {
public static void main( String[] args ) {
CuratorFramework client = CuratorFrameworkFactory.newClient("0.0.0.0:32770", new RetryUntilElapsed(3000, 1000));
client.start();
try {
//make sure you're connected to zookeeper.
client.blockUntilConnected();
//Make sure the parents are created.
client.create().creatingParentsIfNeeded().forPath("/larry-smells/foop", "tuna?".getBytes());
} catch (Exception e) {
System.out.println(e.toString());
}
}
}
I also faced a similar exception, I used the below dependencies which are compatible and helps me to resolve the exception.
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.4.6</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-framework</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-x-discovery</artifactId>
<version>4.0.1</version>
</dependency>
I had the same problem.
I tried to use inTransaction () as explained here: http://www.programcreek.com/java-api-examples/index.php?api=org.apache.curator.framework.CuratorFramework on exercise 6
and seems to work.
client.inTransaction ().create().forPath("/larry-smells/foop", "tuna?".getBytes()).and ().commit ();
The issue is caused because of incompatibility.
To fix this, you need to change the version like it's explained here:
https://curator.apache.org/zk-compatibility.html
If this doesn't work, just look for the newest curator version which depends on a 3.4.x zookeeper version (currently '2.12.0').
#Massimo Da Ros solution works, but in new version Curator 4.0.0 inTransaction is deprecated, it's recommented use transaction method like below:
CuratorOp op = client.transactionOp().create()
.withMode(CreateMode.PERSISTENT)
.withACL(Ids.OPEN_ACL_UNSAFE)
.forPath("/test", "Data".getBytes());
result = client.transaction().forOperations(op).get(0).toString();
I faced similiar problem. I was using spring-cloud-starter-zookeeper-discovery which by itself of course has compatible zookeeper and curator versions.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
</dependency>
I checked the dependency tree and spring-cloud-starter-zookeeper-discovery Version 3.1.1. was using zookeeper Version 3.6.0
The problem was, in my docker-compose.yml I was using zookeeper Version 3.4!
So make sure your docker-compose.yml zookeeper version fits your maven zookeeper version.
version: "3.8"
services:
zookeeper:
container_name: zookeeper
image: zookeeper:3.6 <----------------- zookeeper version
ports:
- "2181:2181"
I am trying to run Mule Batch Code and getting below error when mule is trying to start an application:
org.mule.module.launcher.DeploymentInitException: ClassNotFoundException: org.mule.api.process.ProcessAdapter.
Which jars or mule module I am missing for org.mule.api.process.ProcessAdapter?
Is this enterprise license issue?
I am tried my mule code in both in mule studio and mule standalone but getting the same error.
Please provide input.
After backtracking to various versions (and actually downloading jar from each iteration from this https://repository.mulesoft.org/nexus/content/repositories/releases/org/mule/tools/devkit/mule-devkit-annotations/) I could find the class(actually an abstract interface) you are referring to in the mule-devkit-annotations but the last iteration that included the org.mule.api.process was 3.3.2 and it was dropped after 3.4.0
In mule-devkit-annotations-3.3.2:
public abstract interface ProcessAdapter<O>
{
public abstract <T> ProcessTemplate<T, O> getProcessTemplate();
}
However, I could find the same Interface in mule-module-devkit-support.jar (I was using 3.6.1)
In mule-module-devkit-support-3.6.1.jar:
public interface ProcessAdapter<O>
{
<T> ProcessTemplate<T, O> getProcessTemplate();
}
Update - this problem was of my own doing.
At one stage this particular test class had a test to ensure that something was logged. In the setup, I had previously removed all appenders and added my own appender for making test-time assertions. That test is long since gone, but this nugget remained in the setup: Logger.getRootLogger().removeAllAppenders();.
Sorry for the false alarm. :)
In IDEA I have the following test:
#Test
public void shouldLog() {
URL resource = Thread.currentThread().getContextClassLoader()
.getResource("log4j.properties");
System.out.println("resource = " + resource);
final Logger logger = Logger.getLogger(getClass());
logger.info("Hello world");
}
It outputs thusly:
"C:\Program Files\Java\jdk1.5.0_18\bin\java" -classpath "C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 11.1\lib\idea_rt.jar" -ea -Dfile.encoding=UTF-8 com.intellij.rt.execution.CommandLineWrapper C:\DOCUME~1\JMAWSO~1.NT3\LOCALS~1\Temp\classpath2294205410661538428.tmp #vm_params C:\DOCUME~1\JMAWSO~1.NT3\LOCALS~1\Temp\vm_params5645362020129462784.tmp com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 au.com.gmm.repo.RepoThreadCleanupServiceTest,shouldLog
resource = file:/C:/user/jem/projects/GMM/out/test/cashflow/log4j.properties
log4j:WARN No appenders could be found for logger (au.com.gmm.repo.RepoThreadCleanupServiceTest).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Process finished with exit code 0
This is a famous problem, seen by many newbies over and over again. I feel a little silly being stumped by it today.
http://logging.apache.org/log4j/1.2/faq.html#noconfig says log4j uses Thread.getContextClassLoader().getResource() to locate the default configuration files. However, my test checks Thread.currentThread().getContextClassLoader().getResource("log4j.properties") and finds the properties file with no problem.
The content of the file is:
log4j.rootLogger=DEBUG, CONSOLE
log4j.appender.CONSOLE=org.apache.log4j.ConsoleAppender
log4j.appender.CONSOLE.layout=org.apache.log4j.PatternLayout
log4j.appender.CONSOLE.layout.ConversionPattern=%d{HH:mm:ss.SSS} %c - %m%n
I am using log4j with slf4j in IntelliJ IDEA and it works perfectly for me. Just include these jars into your application dependencies in IntelliJ:
log4j-1.2.9.jar
slf4j-api-1.5.11.jar
slf4j-log4j12-1.5.11.jar
Than put somewhere in your app the log4j configuration. But DO NOT forget to mark that location of the log4j.properties in IntelliJ as Sources or if you using it on tests as Test Sources:
log4j.properties:
log4j.rootLogger=INFO,stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %X{file} %c{1} - %m%n
log4j.logger.your.app=DEBUG,yourApp
log4j.additivity.your.app=false
log4j.logger.yourApp=DEBUG,yourApp
log4j.additivity.yourApp=false
log4j.appender.yourApp=org.apache.log4j.ConsoleAppender
log4j.appender.yourApp.layout=org.apache.log4j.PatternLayout
log4j.appender.yourApp.layout.ConversionPattern=%d [%t] %-5p %X{file} %c{1} %m%n
log4j.appender.yourApp.ImmediateFlush=true
Then in your java class use this to get the logger:
private static final Logger LOGGER = LoggerFactory.getLogger(YourApp.class);
And you will not see any of warnings like: No appenders could be found for logger.
Hope this helps.