Nipun
Nipun

Reputation: 4319

neo4j creating multiple nodes json

Please let me know where I am going wrong I am using neo4j to store my routers interface and link information. The link is to be created between 2 interfaces. I have successfully created nodes and interfaces but finding issues in creating links.

This is the query I use to create link

MATCH (I:Interface), (I2:Interface) 
FOREACH(p in FILTER(z in {props} WHERE z.OrigIPAddress = I.IfIPAddress or z.TermIPAddress = I.IfIPAddress) | 
MERGE (I {IfIPAddress:p.OrigIPAddress})-[r:link]->(I2 {IfIPAddress:p.TermIPAddress}) 
ON CREATE SET r = p 
ON MATCH SET r = p) 

I have an array of maps called props which I am passing in the json as params which contains the properties of link i.e OrigIPAddress (Originating interface IP), TermIPAddress (Terminating interface ip). In the foreach I first filter all those link which have their source or destination interfaces already present. Now after doing this I am creating links out of the props.

When I run this it runs properly but no links are created. There are both source and destination interfaces present.

EDIT 1: I modified the query and when I run this query

MATCH (I:Interface), (I2:Interface) 
FOREACH(p in FILTER(z in {props} WHERE z.OrigIPAddress = I.IfIPAddress and z.TermIPAddress = I2.IfIPAddress) | 
MERGE (I {IfIPAddress:p.OrigIPAddress})-[r:link]->(I {IfIPAddress:p.TermIPAddress}) 
ON CREATE SET r = p 
ON MATCH SET r = p)

I do not get ant response back from the neo4j and in neo4j web console I can see this meesage "Neo4j disconnected, check you socket..."

Here are the logs Apr 09, 2014 11:06:46 AM org.neo4j.server.logging.Logger log WARNING: You are using an unsupported Java runtime. Please use Oracle(R) Java(TM) Runtime Environment 7.

SEVERE: The response of the WebApplicationException cannot be utilized as the response is already committed. Re-throwing to the HTTP container
javax.ws.rs.WebApplicationException: javax.ws.rs.WebApplicationException: org.eclipse.jetty.io.EofException
    at org.neo4j.server.rest.repr.OutputFormat$1.write(OutputFormat.java:174)
    at com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider.writeTo(StreamingOutputProvider.java:71)
    at com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider.writeTo(StreamingOutputProvider.java:57)
    at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:306)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1437)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1506)
    at org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1477)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:503)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:211)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1096)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1030)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
    at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.Server.handle(Server.java:445)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:268)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:229)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532)
    at java.lang.Thread.run(Thread.java:744)
Caused by: javax.ws.rs.WebApplicationException: org.eclipse.jetty.io.EofException
    at org.neo4j.server.rest.repr.formats.StreamingJsonFormat$StreamingRepresentationFormat.flush(StreamingJsonFormat.java:401)
    at org.neo4j.server.rest.repr.formats.StreamingJsonFormat$StreamingRepresentationFormat.complete(StreamingJsonFormat.java:389)
    at org.neo4j.server.rest.repr.MappingRepresentation.serialize(MappingRepresentation.java:43)
    at org.neo4j.server.rest.repr.OutputFormat$1.write(OutputFormat.java:160)
    ... 30 more
Caused by: org.eclipse.jetty.io.EofException
    at org.eclipse.jetty.io.ChannelEndPoint.flush(ChannelEndPoint.java:186)
    at org.eclipse.jetty.io.WriteFlusher.write(WriteFlusher.java:335)
    at org.eclipse.jetty.io.AbstractEndPoint.write(AbstractEndPoint.java:125)
    at org.eclipse.jetty.server.HttpConnection$ContentCallback.process(HttpConnection.java:784)
    at org.eclipse.jetty.util.IteratingCallback.iterate(IteratingCallback.java:79)
    at org.eclipse.jetty.server.HttpConnection.send(HttpConnection.java:356)
    at org.eclipse.jetty.server.HttpChannel.sendResponse(HttpChannel.java:631)
    at org.eclipse.jetty.server.HttpChannel.write(HttpChannel.java:661)
    at org.eclipse.jetty.server.HttpOutput.flush(HttpOutput.java:151)
    at com.sun.jersey.spi.container.servlet.WebComponent$Writer.flush(WebComponent.java:315)
    at com.sun.jersey.spi.container.ContainerResponse$CommittingOutputStream.flush(ContainerResponse.java:145)
    at org.codehaus.jackson.impl.Utf8Generator.flush(Utf8Generator.java:1091)
    at org.neo4j.server.rest.repr.formats.StreamingJsonFormat$StreamingRepresentationFormat.flush(StreamingJsonFormat.java:397)
    ... 33 more
Caused by: java.io.IOException: Broken pipe
    at sun.nio.ch.FileDispatcherImpl.writev0(Native Method)
    at sun.nio.ch.SocketDispatcher.writev(SocketDispatcher.java:51)
    at sun.nio.ch.IOUtil.write(IOUtil.java:148)
    at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:524)
    at org.eclipse.jetty.io.ChannelEndPoint.flush(ChannelEndPoint.java:167)
    ... 45 more

Apr 09, 2014 11:10:17 AM com.sun.jersey.server.impl.application.WebApplicationImpl _handleRequest
SEVERE: The response of the WebApplicationException cannot be utilized as the response is already committed. Re-throwing to the HTTP container
javax.ws.rs.WebApplicationException: javax.ws.rs.WebApplicationException: org.eclipse.jetty.io.EofException
    at org.neo4j.server.rest.repr.OutputFormat$1.write(OutputFormat.java:174)
    at com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider.writeTo(StreamingOutputProvider.java:71)
    at com.sun.jersey.core.impl.provider.entity.StreamingOutputProvider.writeTo(StreamingOutputProvider.java:57)
    at com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.java:306)
    at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1437)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
    at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
    at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
    at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:699)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:848)
    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:698)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1506)
    at org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)
    at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1477)
    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:503)
    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:211)
    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1096)
    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:432)
    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:175)
    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1030)
    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136)
    at org.eclipse.jetty.server.handler.HandlerList.handle(HandlerList.java:52)
    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
    at org.eclipse.jetty.server.Server.handle(Server.java:445)
    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:268)
    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:229)
    at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:358)
    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:601)
    at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:532)
    at java.lang.Thread.run(Thread.java:744)
Caused by: javax.ws.rs.WebApplicationException: org.eclipse.jetty.io.EofException
    at org.neo4j.server.rest.repr.formats.StreamingJsonFormat$StreamingRepresentationFormat.flush(StreamingJsonFormat.java:401)
    at org.neo4j.server.rest.repr.formats.StreamingJsonFormat$StreamingRepresentationFormat.complete(StreamingJsonFormat.java:389)
    at org.neo4j.server.rest.repr.MappingRepresentation.serialize(MappingRepresentation.java:43)
    at org.neo4j.server.rest.repr.OutputFormat$1.write(OutputFormat.java:160)
    ... 30 more
Caused by: org.eclipse.jetty.io.EofException
    at org.eclipse.jetty.io.ChannelEndPoint.flush(ChannelEndPoint.java:186)
    at org.eclipse.jetty.io.WriteFlusher.write(WriteFlusher.java:335)
    at org.eclipse.jetty.io.AbstractEndPoint.write(AbstractEndPoint.java:125)
    at org.eclipse.jetty.server.HttpConnection$ContentCallback.process(HttpConnection.java:784)
    at org.eclipse.jetty.util.IteratingCallback.iterate(IteratingCallback.java:79)
    at org.eclipse.jetty.server.HttpConnection.send(HttpConnection.java:356)
    at org.eclipse.jetty.server.HttpChannel.sendResponse(HttpChannel.java:631)
    at org.eclipse.jetty.server.HttpChannel.write(HttpChannel.java:661)
    at org.eclipse.jetty.server.HttpOutput.flush(HttpOutput.java:151)
    at 

Let me know where I am I going wrong.

Upvotes: 0

Views: 249

Answers (2)

Nipun
Nipun

Reputation: 4319

Finally after googling I found the issue. Its server timeout. Since the query is taking some time to execute, the server is timing out and sending a response.

I increased the timeout and it worked Here is the reference on how to increase it. http://docs.neo4j.org/chunked/stable/server-configuration.html

Upvotes: 1

cybersam
cybersam

Reputation: 67019

Is this closer to what you are trying to do?

MATCH (I:Interface)
FOREACH(
  p in FILTER(z in {props}
    WHERE z.OrigIPAddress = I.IfIPAddress or z.TermIPAddress = I.IfIPAddress) | 
  MERGE (I)-[r:link]->(:Interface {IfIPAddress:p.TermIPAddress})
  SET I.IfIPAddress = p.OrigIPAddress, r = p
);

Upvotes: 1

Related Questions