I was trying to write a simple text to HDFS using spring data hadoop. But I'm getting an unknown issue upon writing.
Exception in thread "main" org.springframework.data.hadoop.store.StoreException: Store output context not yet initialized; nested exception is java.io.IOException: Unexpected HTTP response: code=404 != 200, op=GETFILESTATUS, message=Not Found at org.springframework.data.hadoop.store.support.OutputStoreObjectSupport.getOutputContext(OutputStoreObjectSupport.java:135) at org.springframework.data.hadoop.store.output.AbstractDataStreamWriter.getOutput(AbstractDataStreamWriter.java:131) at org.springframework.data.hadoop.store.output.TextFileWriter.write(TextFileWriter.java:132) at com.mstack.app.MainApp.someMethod(MainApp.java:37) at com.mstack.app.MainApp.main(MainApp.java:32) Caused by: java.io.IOException: Unexpected HTTP response: code=404 != 200, op=GETFILESTATUS, message=Not Found at org.apache.hadoop.hdfs.web.WebHdfsFileSystem.validateResponse(WebHdfsFileSystem.java:347) at org.apache.hadoop.hdfs.web.WebHdfsFileSystem.access$200(WebHdfsFileSystem.java:90) at org.apache.hadoop.hdfs.web.WebHdfsFileSystem$AbstractRunner.runWithRetry(WebHdfsFileSystem.java:613) at org.apache.hadoop.hdfs.web.WebHdfsFileSystem$AbstractRunner.access$100(WebHdfsFileSystem.java:463) at org.apache.hadoop.hdfs.web.WebHdfsFileSystem$AbstractRunner$1.run(WebHdfsFileSystem.java:492) at java.security.AccessController.doPrivileged(Native Method) at javax.security.auth.Subject.doAs(Subject.java:422) at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1657) at org.apache.hadoop.hdfs.web.WebHdfsFileSystem$AbstractRunner.run(WebHdfsFileSystem.java:488) at org.apache.hadoop.hdfs.web.WebHdfsFileSystem.getHdfsFileStatus(WebHdfsFileSystem.java:848) at org.apache.hadoop.hdfs.web.WebHdfsFileSystem.getFileStatus(WebHdfsFileSystem.java:858) at org.apache.hadoop.fs.FileSystem.exists(FileSystem.java:1424) at org.springframework.data.hadoop.store.support.OutputStoreObjectSupport.findInitFiles(OutputStoreObjectSupport.java:111) at org.springframework.data.hadoop.store.support.OutputStoreObjectSupport.initOutputContext(OutputStoreObjectSupport.java:93) at org.springframework.data.hadoop.store.support.OutputStoreObjectSupport.getOutputContext(OutputStoreObjectSupport.java:133) ... 4 more Caused by: java.io.IOException: Content-Type "text/plain" is incompatible with "application/json" (parsed="text/plain") at org.apache.hadoop.hdfs.web.WebHdfsFileSystem.jsonParse(WebHdfsFileSystem.java:320) at org.apache.hadoop.hdfs.web.WebHdfsFileSystem.validateResponse(WebHdfsFileSystem.java:343) ... 18 more
My application-context.xml :-
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/hadoop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:hdp="http://www.springframework.org/schema/hadoop" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/hadoop http://www.springframework.org/schema/hadoop/spring-hadoop.xsd">
<hdp:configuration id="hadoopConfigBean">
fs.defaultFS=${hdp.fs}
</hdp:configuration>
<context:annotation-config />
<beans:bean id="textFileWriter"
class="org.springframework.data.hadoop.store.output.TextFileWriter">
<beans:constructor-arg index="0" ref="hadoopConfigBean"></beans:constructor-arg>
<beans:constructor-arg index="1"
type="org.apache.hadoop.fs.Path" value="/user/mhduser"></beans:constructor-arg>
<beans:constructor-arg index="2" type="org.springframework.data.hadoop.store.codec.CodecInfo" >
<beans:null></beans:null>
</beans:constructor-arg>
</beans:bean>
<context:property-placeholder location="hadoop-configs.properties" />
</beans:beans>
Main class :-
public class MainApp {
@Autowired
TextFileWriter textFileWriter;
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("/META-INF/spring/application-context.xml",
MainApp.class);
System.out.println("Context loaded...");
MainApp obj = new MainApp();
context.getAutowireCapableBeanFactory().autowireBean(obj);
obj.someMethod();
}
private void someMethod() {
try {
textFileWriter.write("Something");
} catch (IOException e) {
e.printStackTrace();
}
}
}
Any help would be appreciated ! Thanks
We have some samples here https://github.com/spring-projects/spring-hadoop-samples. Thought nothing store specific so I created a simple gist based on Spring Boot which can be run via its CLI. https://gist.github.com/jvalkeal/8145f0618f25c1d25d19f4e1e89de1e6
Also worth to look what we do in unit tests https://github.com/spring-projects/spring-hadoop/tree/master/spring-hadoop-store/src/test/java/org/springframework/data/hadoop/store