我是hdfs的新手.我正在编写可以连接数据并将数据写入远程hadoop集群的Java客户端.
String hdfsUrl = "hdfs://xxx.xxx.xxx.xxx:8020";
FileSystem fs = FileSystem.get(hdfsUrl , conf);
Run Code Online (Sandbox Code Playgroud)
这很好用.我的问题是如何处理启用HA的hadoop集群.启用HA的hadoop群集将具有两个名称节点 - 一个活动的名称节点和备用名称节点.如何在运行时从客户端代码中识别活动的名称节点.
http://docs.hortonworks.com/HDPDocuments/HDP2/HDP-2.1.1/bk_system-admin-guide/content/ch_hadoop-ha-3-1.html有关于可用于联系的java类的以下详细信息活动名称节点dfs.client.failover.proxy.provider.[$ nameservice ID]:
This property specifies the Java class that HDFS clients use to contact the Active NameNode. DFS Client uses this Java class to determine which NameNode is the current Active and therefore which NameNode is currently serving client requests.
Use the ConfiguredFailoverProxyProvider implementation if you are not using a custom implementation.
Run Code Online (Sandbox Code Playgroud)
例如:
<property>
<name>dfs.client.failover.proxy.provider.mycluster</name>
<value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
</property>
Run Code Online (Sandbox Code Playgroud)
我如何在我的Java客户端中使用此类,或者是否有任何其他方法来识别活动的名称节点...
您将获得一个段落,其中一行中所有单词的长度具有以下属性:
您将获得一个单词,并且必须编写代码以在给定段落中搜索它并返回行号.
我从我的Java应用程序连接到SSL over SSL.我已将MYSQL配置为支持SSL并生成客户端证书.我已将服务器CA证书和客户端证书导入密钥库.这就是我的代码目前的样子
String url = "jdbc:mysql://127.0.0.1:3306/MySampleDb? verifyServerCertificate =true&useSSL=true&requireSSL=true"
System.setProperty("javax.net.ssl.keyStore","/home/cert/keystore");
System.setProperty("javax.net.ssl.keyStorePassword","password");
System.setProperty("javax.net.ssl.trustStore","/home/cert/truststore");
System.setProperty("javax.net.ssl.trustStorePassword","password");
Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection(url, user, password);
Run Code Online (Sandbox Code Playgroud)
我想使用带有C3p0的spring通过SSL连接到MYSQL.这是我的spring配置文件,它从jdbc.properties读取参数.
<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
<property name="driverClass" value="${jdbc.driver}"/>
<property name="jdbcUrl" value="${jdbc.url}"/>
<property name="user" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
........
</bean>
Run Code Online (Sandbox Code Playgroud)
如何配置spring来设置属性
verifyServerCertificate = true
useSSL = true
requireSSL = true"
还可以在spring配置文件中设置keyStore和trustStore值.
我在Spring休息服务中有一个方法.
@RequestMapping(value = "test/process", method = RequestMethod.POST)
public @ResponseBody MyResponse processRequest(String RequestId, int count)
Run Code Online (Sandbox Code Playgroud)
我正在使用Spring RestTemplate来调用此服务.
RestTemplate restTemplate = this.getRestTemplate();
MultiValueMap<String, Object> map = new LinkedMultiValueMap<String, Object>();
map.add("RequestId", RequestId);
map.add("count", count);
restTemplate.postForObject(url, map,MyResponse.class);
Run Code Online (Sandbox Code Playgroud)
当我尝试调用客户端方法时,我得到的异常是找不到合适的HttpMessageConverter请求类型[java.lang.Integer]
org.springframework.http.converter.HttpMessageNotWritableException: Could not write request: no suitable HttpMessageConverter found for request type [java.lang.Integer]
at org.springframework.http.converter.FormHttpMessageConverter.writePart(FormHttpMessageConverter.java:310)
at org.springframework.http.converter.FormHttpMessageConverter.writeParts(FormHttpMessageConverter.java:270)
at org.springframework.http.converter.FormHttpMessageConverter.writeMultipart(FormHttpMessageConverter.java:260)
at org.springframework.http.converter.FormHttpMessageConverter.write(FormHttpMessageConverter.java:200)
at org.springframework.http.converter.FormHttpMessageConverter.write(FormHttpMessageConverter.java:1)
at org.springframework.web.client.RestTemplate$HttpEntityRequestCallback.doWithRequest(RestTemplate.java:596)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:444)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:409)
at org.springframework.web.client.RestTemplate.postForObject(RestTemplate.java:287)
Run Code Online (Sandbox Code Playgroud)
我知道其中一种方法是将所有参数作为String传递.但我可能需要稍后将复杂数据类型作为参数传递.有什么方法可以实现这一目标.我用谷歌搜索,一些选项似乎是编写我自己的转换器.我应该如何开始解决这个问题.
spring ×2
algorithm ×1
c3p0 ×1
hadoop ×1
hdfs ×1
jdbc ×1
rest ×1
resttemplate ×1
spring-jdbc ×1
spring-mvc ×1
ssl ×1