First for all, i'm sorry for my english.
I have a problem with Java API Transport Client. I have one master node and three data nodes. Version of my Elasticsearch is 5.0.2 and i use 5.0.2 API.
I try to connect to my cluster with Transport Client and then i response
Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{8SAZOxXXTU61DuDDMN-vGw}{XX.XX.X.XXX}{XX.XX.X.XXX:9300}, {#transport#-2}{Fv3729YgTGClRBo5T2mWpA}{XX.XX.X.XXX}{XX.XX.X.XXX:9300}, {#transport#-3}{Fr98ApBbRv29Xv6Mc8L4TQ}{XX.XX.X.XXX}{XX.XX.X.XXX:9300}, {#transport#-4}{JOmpSH4LRzuP_XInxQtD9Q}{XX.XX.X.XXX}{XX.XX.X.XXX:9300}]]
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:328)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:226)
at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:59)
at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:339)
at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:403)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:80)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:54)
at org.elasticsearch.action.ActionRequestBuilder.get(ActionRequestBuilder.java:62)
at nn.Main.main(Main.java:57)
That is my code of client:
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.elasticsearch.action.search.SearchRequestBuilder;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.xpack.client.PreBuiltXPackTransportClient;
public class Main {
private static String[] hosts = new String[] {
"XX.XX.X.XXX"
,"XX.XX.X.XXX"
,"XX.XX.X.XXX"
,"XX.XX.X.XXX"
};
private static final Settings settings = Settings.builder()
.put("cluster.name", "myCluster")
.put("client.transport.sniff", true)
.put("transport.tcp.port", 9300)
.put("xpack.security.user", "transport_client_user:changeme")
.build();
private static final String index = "myIndex";
private static final String type = "myType";
private static TransportClient client;
public static void main(String[] args) throws UnknownHostException {
InetSocketTransportAddress[] ista = new InetSocketTransportAddress[hosts.length];
for (int i = 0; i < hosts.length; i++) {
ista[i] = new InetSocketTransportAddress(InetAddress.getByName(hosts[i]), 9300);
}
client = new PreBuiltXPackTransportClient(settings).addTransportAddresses(ista);
SearchRequestBuilder rb = client
.prepareSearch(index)
.setTypes(type)
.setSearchType(SearchType.DEFAULT)
.setQuery(QueryBuilders.termQuery("_id", 3524598));
SearchResponse sResponse = rb.get();
System.out.println(sResponse.toString());
}
}
Port for transport client - 9300, all my nodes communicate under this port. I saw a lot like my question, and i trying to follow the advice contained in them. But i have the same exception.
If need more information or any files or settings of my Elastic - i'm ready to answer.
If it is important this is content of elasticsearch.yml
cluster.name: myCluster
node.name: elastic-0
path.data: /var/db/elasticsearch
path.logs: /var/log/elasticsearch
path.scripts: /usr/local/libexec/elasticsearch
network.host: _vmx0_
node.master: true
node.data: false
node.ingest: false
node.attr.rack_id: rack_one
cluster.routing.allocation.awareness.attributes: rack_id
discovery.zen.minimum_master_nodes: 3
discovery.zen.ping.unicast.hosts: ["XX.XX.X.XXX","XX.XX.X.XXX","XX.XX.X.XXX","XX.XX.X.XXX","XX.XX.X.XXX"]
bootstrap.memory_lock: false
xpack.monitoring.exporters:
id1:
type: http
host: ["XX.XX.X.XXX:9200"]
auth.username: remote_monitor
auth.password: changeme
I tried to change TransportClient on just Client, and disable client.transport.sniff but without result.
I will be very gratefull for any help or ideas.
I found the reason for which i received "NoNodeAvailableException".
The reason is transport_client's role does not grant permission to view the data in all indices on default.
And i will to built my role for the access to data in indices.
Link: https://www.elastic.co/guide/en/x-pack/5.0/built-in-roles.html
This exception usually occurs when we try to use ES with TranscientClient (9300) and not with an API (9200).
These could be the reasons behind this:
Our IP address or the port that is provided is wrong. By default, the transport communication happens via 9300 until and unless we explicitly change in the elastisearch.yml
The IP address and the port is not reachable from the machine where we are running the Java Application. The ES machine is simply not reachable from Client Machine so we need to open the port and IP to the client.
If we change the 'transport.host' then ES considers as a prod environment and makes bootstrap checks. But in the scenario where the environment is not prod and we are running ES in one machine and trying to hit it from another machine with a transport client (Java app) then we can just add 'discovery.type: single-node'.
Change the Elastic Search yaml as follows:
cluster.name: elasticsearch
node.name: node-1
transport.host: 0.0.0.0
transport.tcp.port: 9300
http.port: 9200
network.host: 0.0.0.0
discovery.type: single-node
Related
I'd like to combine HiveMQ Client and HiveMQ Community Edition which is the implementation for the broker into one project. I tried adding the HiveMQ client as a dependency to the build.gradle file in the Hive MQ Community Edition (broker). It was able to build successfully but I'm not sure if I did it correctly. When I tried to reference client classes inside the Community Edition it gives me errors. Am I missing something? I want to be able to just put put the client project inside of the broker community edition and be able to create a client and access all of the classes I could in HiveMQ client. I left the instructions from the HiveMQ Client website, links, and also what the build.gradle file looks like the HiveMQ community edition.
Error I'm getting: The import com.hivemq.client cannot be resolved (Happens to all imports referencing anything in the HiveMQ Client project)
Link to the HiveMQ GitHubs:
https://github.com/hivemq/hivemq-mqtt-client
https://github.com/hivemq/hivemq-community-edition
Code from Main.Java that produces the error
package com.main;
import java.util.UUID;
import com.hivemq.client.mqtt.MqttGlobalPublishFilter;
import com.hivemq.client.mqtt.datatypes.MqttQos;
import com.hivemq.client.mqtt.mqtt5.Mqtt5BlockingClient;
import com.hivemq.client.mqtt.mqtt5.Mqtt5BlockingClient.Mqtt5Publishes;
import com.hivemq.client.mqtt.mqtt5.Mqtt5Client;
import com.hivemq.client.mqtt.mqtt5.message.publish.Mqtt5Publish;
import java.util.logging.Logger;
import java.nio.ByteBuffer;
import java.util.Optional;
import java.util.logging.Level;
import java.util.concurrent.TimeUnit;
public class Main {
private static final Logger LOGGER = Logger.getLogger(Main.class.getName()); // Creates a logger instance
public static void main(String[] args) {
// Creates the client object using Blocking API
Mqtt5BlockingClient client1 = Mqtt5Client.builder()
.identifier(UUID.randomUUID().toString()) // the unique identifier of the MQTT client. The ID is randomly generated between
.serverHost("0.0.0.0") // the host name or IP address of the MQTT server. Kept it 0.0.0.0 for testing. localhost is default if not specified.
.serverPort(1883) // specifies the port of the server
.buildBlocking(); // creates the client builder
client1.connect(); // connects the client
System.out.println("Client1 Connected");
String testmessage = "How is it going";
byte[] messagebytesend = testmessage.getBytes(); // stores a message as a byte array to be used in the payload
try {
Mqtt5Publishes publishes = client1.publishes(MqttGlobalPublishFilter.ALL); // creates a "publishes" instance thats used to queue incoming messages
client1.subscribeWith() // creates a subscription
.topicFilter("test/topic")
.send();
System.out.println("The client has subscribed");
client1.publishWith() // publishes the message to the subscribed topic
.topic("test/topic")
.payload(messagebytesend)
.send();
Mqtt5Publish receivedMessage = publishes.receive(5,TimeUnit.SECONDS).orElseThrow(() -> new RuntimeException("No message received.")); // receives the message using the "publishes" instance
LOGGER.info("Recieved: " + receivedMessage);
byte[] getdata = receivedMessage.getPayloadAsBytes();
System.out.println(getdata.toString());
System.out.println(receivedMessage);
}
catch (Exception e) { // Catches all exceptions using the "base exception"
LOGGER.log(Level.SEVERE, "Something went wrong.", e);
}
}
}
I didn't have the HiveMQ client in my build path. On the line with red errors Eclipse gave me the option of fixing the project set up and I click on it and it automatically added the HiveMQ client to the build path. I posted a screenshot below.
I am new to MQ, I have a requirement where in I have to send a mq message from 1 system to another. The Message queue and Queue Manager is Set up at the server, and i only have the qname and the mqmanager name,I have written the following code to create a connection to mq, but i am getting this Exception:
UnsatisfiedLinkError: mqjbnd (Not found in java.library.path)
The code is:
package com.demo.mqsamplimport com.ibm.mq.MQC;
import com.ibm.mq.MQEnvironment;
import com.ibm.mq.MQException;
import com.ibm.mq.MQGetMessageOptions;
import com.ibm.mq.MQMessage;
import com.ibm.mq.MQPutMessageOptions;
import com.ibm.mq.MQQueue;
import com.ibm.mq.MQQueueManager;
import com.ibm.mq.constants.MQConstants;
public class MQSample {
private static final String qManager = "(MyQueueManagerName)";
private static final String qName = "(MyQueueName)";
public static void putGet(String args[]) {
try {
MQQueueManager qMgr = new MQQueueManager(qManager);
int openOptions = MQConstants.MQOO_OUTPUT;
MQQueue queue = qMgr.accessQueue(qName, openOptions);
MQMessage msg = new MQMessage();
msg.writeString("Hello World!");
MQPutMessageOptions pmo = new MQPutMessageOptions();
queue.put(msg, pmo);
}
catch (MQException ex) {
ex.printstacktrace();
}
catch (java.io.IOException ex) {
ex.printstacktrace(););
}
}
}
can anyone please help me on this.
UnsatisfiedLinkError: mqjbnd (Not found in java.library.path) error is normally caused when you try to make a binding mode connection to IBM MQ Queue Manager hosted on the same server and the IBM MQ Classes for Java can not locate the library mqjbnd. If you do not specify a hostname and channel name for IBM MQ Classes for Java to use to connect, they default to a binding mode connection.
If your applications runs on the same server as the IBM MQ Queue Manager then you would need to tell the client how to find the mqjbnd libraries (on Linux this is /opt/mqm/java/lib) with one of the following methods:
set the LIBPATH environment variable for example on Linux bash export LIBPATH=/path/to/library
With the command line option -Djava.library.path=/path/to/library
Programmatically with System.setProperty("java.library.path", "/path/to/library");
If you are trying to connect to a IBM MQ Queue Manager hosted on a remote server I agree with #user7790438 that you would need to provide MQ with the details on how to connect to the remote queue manager. The MQEnvironment is global and not thread safe. You should use a hashtable to pass these values for example:
import java.util.Hashtable;
private static String host = "dns.name";
private static int port = 1414;
private static String channel = "MQ.SVRCONN.CHL";
Hashtable properties = new Hashtable<String, Object>();
properties.put("hostname", host);
properties.put("port", port);
properties.put("channel", channel);
MQQueueManager qMgr = new MQQueueManager(qManager, properties);
You do not mention what version of IBM MQ the queue manager is, or what version of IBM MQ classes for Java jar files you are referencing. Other details can be passed via the hash table, for example if you are using IBM MQ v8 or later Classes for Java and connecting to a IBM MQ v8 or later Queue Manager you may need to pass a UserID and Password, this would be accomplished by adding the following to the has table:
private static String user = "UserID";
private static String password = "Password";
properties.put(MQConstants.USE_MQCSP_AUTHENTICATION_PROPERTY, true);
properties.put(MQConstants.USER_ID_PROPERTY, user);
properties.put(MQConstants.PASSWORD_PROPERTY, password);
Please note that per the IBM v9.0 Knowledge center page "Deprecated, stabilized and removed features", IBM MQ Classes for Java have been Stabilization as of v8.0. This means that no further enhancements will be made and eventually IBM will deprecated the IBM MQ Classes for Java. You may want to write your application using the IBM MQ classes for JMS which has no support restrictions.
Stabilization of IBM MQ classes for Java
IBM will make no further enhancements to the IBM MQ classes for Java and they are functionally stabilized at the level shipped in IBM MQ Version 8.0. Existing applications that use the IBM MQ classes for Java will continue to be fully supported, but this API is stabilized, so new features will not be added and requests for enhancements rejected. Fully supported means that defects will be fixed together with any changes necessitated by changes to IBM MQ System Requirements.
You instantiated MQQueueManager before setting MQEnvironment's hostname and channel.
Just try add this:
MQEnvironment.hostname = "mq hostname";
MQEnvironment.channel = "mq channel";
Before:
MQQueueManager qMgr = new MQQueueManager(qManager);
Is there any specific Glassfish configuration required to allow remote CORBA lookup across a LAN? Or, does, perhaps, the routers firewall need configuration?
How do I troubleshoot this connection?
The CORBA lookup client just hangs:
BUILD SUCCESSFUL
Total time: 3 seconds
Nov 22, 2014 3:45:26 AM aggregatorclient.AggregatorClient remoteEJB
WARNING: {org.omg.CORBA.ORBInitialPort=3700, java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, Context.SECURITY_CREDENTIALS=pass123, org.omg.CORBA.ORBInitialHost=192.168.0.119, java.naming.factory.url.pkgs=com.sun.enterprise.naming, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, Context.SECURITY_PRINCIPAL=user1}
When run from localhost (ie, from localhost, connecting to localhost), with everything on the same computer, the connection works fine.
The CORBA connection lookup parameters, in jndi.properties:
java.naming.factory.initial=com.sun.enterprise.naming.SerialInitContextFactory
java.naming.factory.url.pkgs=com.sun.enterprise.naming
java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl
Context.SECURITY_PRINCIPAL=user1
Context.SECURITY_CREDENTIALS=pass123
org.omg.CORBA.ORBInitialHost=192.168.0.119
org.omg.CORBA.ORBInitialPort=3700
the connecting clients code:
package aggregatorclient;
import dur.ejb.AnswerSessionBeanRemote;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class AggregatorClient {
private static final Logger log = Logger.getLogger(AggregatorClient.class.getName());
public static void main(String[] args) {
try {
new AggregatorClient().remoteEJB();
} catch (NamingException ex) {
Logger.getLogger(AggregatorClient.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void remoteEJB() throws NamingException {
Context ctx = new InitialContext();
log.warning(ctx.getEnvironment().toString());
Object obj = ctx.lookup("dur.ejb.AnswerSessionBeanRemote");
AnswerSessionBeanRemote asbr = (AnswerSessionBeanRemote) obj;
log.info("answer\t" + asbr.lifeTheUniverseAndEverything());
}
}
The client is executed with Glassfish appclient.
Been having the same "hanging forever" lookup behavior with a standalone ejb client running on a remote host. It turned out to be related to the server host's ability to resolve its own hostname into its own non-loopback address. I resolved it by adding / fixing an entry in /etc/hosts:
10.0.10.102 my-server-hostname
I checked that the server could actually resolve the right ip address with hostname -i :
$ hostname -i
10.0.10.102
After restarting GlassFish, remote lookup and call to EJB worked like a charm!
Explanation
I found this solution after sniffing the traffic between my client and server. The underlying protocol is GIOP (had never heard of it).
When executing the remote lookup, my client's request was actually able to reach GlassFish. But the server replied with a misleading "Location Forward" response, indicating 127.0.1.1 as a IIOP:Profile_host. 127.0.1.1 was the loopback ip address that my server's hostname resolved to before I fixed the /etc/hosts.
I am New in Elastic Search Java Api[5.0]. I am Using elasticsearch-5.0.0.
I am try to create a Java Application(Maven) with Spring Boot. After run Application, it shows
2016-11-04 23:32:19.339 INFO 8280 --- [][generic][T#2]] org.elasticsearch.client.transport : [X-Ray] failed to get node info for [#transport#-1][DESKTOP-8SIPHSN][inet[localhost/127.0.0.1:9300]], disconnecting...
org.elasticsearch.transport.NodeDisconnectedException: [][inet[localhost/127.0.0.1:9300]][cluster:monitor/nodes/info] disconnected
My Config File Is
#Configuration
public class ElasticsearchConfiguration {
#Bean
public Client client() {
TransportClient client = new TransportClient();
TransportAddress address = new InetSocketTransportAddress("localhost",9300);
client.addTransportAddress(address);
return client;
}
}
And I am using default cluster "elasticsearch". I need help to solve my issue with proper detection of causes.
Try using the PreBuiltTransportClient mentioned in the 5.0 documentation:
TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.html
Also note that the TransportClient for ES version 2.x isn't compatible with 5.x:
The client must have the same major version (e.g. 2.x, or 5.x) as the
nodes in the cluster. Clients may connect to clusters which have a
different minor version (e.g. 2.3.x) but it is possible that new
functionality may not be supported. Ideally, the client should have
the same version as the cluster.
https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/client.html
Update
As a connectivity test, try executing the following simple program:
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
import java.net.InetAddress;
import java.net.UnknownHostException;
public class App {
public static void main(String[] args) throws UnknownHostException {
// The following settings aren't strictly necessary, because the default cluster name is "elasticsearch".
Settings settings = Settings.builder().put("cluster.name", "elasticsearch").build();
TransportClient client = new PreBuiltTransportClient(settings);
client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
System.out.println(client.connectedNodes());
}
}
It should print to stdout something like the following line:
[{luhcORJ}{luhcORJOSzSLPBeXocDsuQ}{mkTJpwIAQGuNYTHfRLqUIw}{127.0.0.1}{127.0.0.1:9300}]
I have a hiveserver(hiveserver2) running on port 10000.
If I run command:
netstat -nl | grep 10000
I get:
tcp 0 0 0.0.0.0:10000 0.0.0.0:* LISTEN
so the server is up and running.
My hive-site.xml settings:
<property>
<name>hive.server2.thrift.port</name>
<value>10000</value>
</property>
My code:
public class ThriftAgent {
private static final String HOST = "localhost";
private static final int PORT = 10000;
public static void main(String[] args) throws Exception {
TSocket transport = new TSocket(HOST, PORT);
transport.open();
TBinaryProtocol protocol = new TBinaryProtocol(transport);
Client client = new ThriftHive.Client(protocol);
client.execute("show tables");
final List<String> results = client.fetchAll();
for (String result : results) {
System.out.println(result);
}
transport.close();
}
}
I have tried different URL combos but it freezes at client.execute() and does not go any further than that. It does not throw any exceptions either.
I have also tried to disable authentication but that did not help either as per thread
Requests hang when using Hiveserver2 Thrift Java client
If I connect through JDBC to same host it works.
Also if I start HiveServer (not hiveserver2) it works so something is fishy with hiveserver2.
Well, with no error output to guide us, it could be several things.
It's been a while since I set up a Hive2 Server, but, you may want to define the IP address(or host) in the hive-site.xml using the hive.server2.thrift.bind.host property.
If you set the property above to 'localhost' you'll need to make certain the /etc/hosts file is set to resolve you properly, and if it's on another machine and you use the name, same thing. I would recommend testing with an IP address, and then move to name.
The comment requesting more information is a good one though, there is not much to go on here. What version of Hive2 are you using? What Hadoop distro? There will be differences affecting your solution depending on the answers.
Check if you have IPv6 disabled or in your environment settings make sure you add this to your java options:
-Djava.net.preferIPv4Stack=true
For the first one you should set this parameters on your /etc/sysctl.conf file:
#disable ipv6
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1
After a reboot check if it's disabled with:
cat /proc/sys/net/ipv6/conf/all/disable_ipv6
For the second one you can add this in you hadoop-env.sh
export HADOOP_OPTS="$HADOOP_OPTS -Djava.net.preferIPv4Stack=true
or in your .bashrc file:
alias java="java -Djava.net.preferIPv4Stack=true"