I am a newbie in Neo4j and facing a small problem.
I created around 5000 router nodes with its ipaddress property set to specific ip.
Now I have around 5000 more interfaces and needs to create their nodes. I am using json and rest api for that in c++.
Every interface has a Routerip property and if the routerip matches the ipaddress of the router node that is already created I need to create that interface.
I have used this
http://docs.neo4j.org/chunked/snapshot/rest-api-cypher.html#rest-api-create-mutiple-nodes-with-properties link to create my routers.
Now I want to use the same method in order to create my interfaces.
Is there a way wherein I can do so passing array of properties as paramaters in the cypher query and check for the router present to create my interface?
There are several ways to do this. Breaking it down into steps:
For each interface, find the matching router
Create the interface & connect the interface to that router
That would look something like
MATCH (router:Router)
WHERE router.ipaddress = props.RouterIp
CREATE (n:Interface { props } )-[:CONNECTED_TO]->(router)
Hey When I try to run this simple query as above it gives me java exception
{
"params" : {
"props" : [
{
"LocalAsNumber" : 0,
"NodeDescription" : "10TiMOS-B-4.0.R2 ",
"NodeId" : "10.227.28.95",
"NodeName" : "BLR_WAO_SARF7"
}
]
},
"query" : "MATCH (n:Router) where n.NodeId = {props}.NodeId RETURN n"}
"message" : "The statement has been closed.",
"exception" : "BadInputException",
"fullname" : "org.neo4j.server.rest.repr.BadInputException",
"stacktrace" : [ "org.neo4j.server.rest.repr.RepresentationExceptionHandlingIterable.exceptionOnHasNext(RepresentationExceptionHandlingIterable.java:50)", "org.neo4j.helpers.collection.ExceptionHandlingIterable$1.hasNext(ExceptionHandlingIterable.java:46)", "org.neo4j.helpers.collection.IteratorWrapper.hasNext(IteratorWrapper.java:42)", "org.neo4j.server.rest.repr.ListRepresentation.serialize(ListRepresentation.java:71)", "org.neo4j.server.rest.repr.Serializer.serialize(Serializer.java:75)", "org.neo4j.server.rest.repr.MappingSerializer.putList(MappingSerializer.java:61)", "org.neo4j.server.rest.repr.CypherResultRepresentation.serialize(CypherResultRepresentation.java:83)", "org.neo4j.server.rest.repr.MappingRepresentation.serialize(MappingRepresentation.java:41)", "org.neo4j.server.rest.repr.OutputFormat.assemble(OutputFormat.java:215)", "org.neo4j.server.rest.repr.OutputFormat.formatRepresentation(OutputFormat.java:147)", "org.neo4j.server.rest.repr.OutputFormat.response(OutputFormat.java:130)", "org.neo4j.server.rest.repr.OutputFormat.ok(OutputFormat.java:67)", "org.neo4j.server.rest.web.CypherService.cypher(CypherService.java:101)", "java.lang.reflect.Method.invoke(Method.java:606)", "org.neo4j.server.rest.transactional.TransactionalRequestDispatcher.dispatch(TransactionalRequestDispatcher.java:132)", "org.neo4j.server.rest.security.SecurityFilter.doFilter(SecurityFilter.java:112)", "java.lang.Thread.run(Thread.java:744)" ],
Related
A JSON string string passes the jsonlint test.
response = [
{
"article" : {
"info" : {
"initial" : {
"articleIds" : [
"7461221587662919569"
],
}
},
"text" : "where they would 'transfer to' next.",
"lang" : "en",
}
},
{
"article" : {
"info" : {
"initial" : {
"articleIds" : [
"6613144915874808065"
],
}
},
"text" : "produto regional.",
"lang" : "pt"
}
}
]
However, after processing
require 'json'
file = File.read('/Users/main/jugg//article_samples.js')
data_hash = JSON.parse(file)
One is left with an array, whereas more frequently a hash with a name labels a subsequent array, where one works with that nomenclature such as response['data']
But in this case the array is not accessible via response[0]. How can this be considered as an array in order to process each individual element collection.each do |member|?
A curiosity: data_hash.class => NilClass
The response = ... code from article_samples.js is JavaScript, not JSON. This initializes a variable named response with a JavaScript array.
To use this as JSON, then rename the file to article_samples.json and remove response = from the file. The first line should start with [.
Now your second block of code should work just fine as long as the article_samples.json file is in the correct path.
On a side note, I suggest that you find a way to make the path more flexible. The way you have it currently hard coded is tied directly to your current machine's file system. This won't work if you want to run this code from another machine because the folder /Users/main/jugg probalby won't exist.
If this is a web server with ruby on rails, then one solution is to create an environment variable with the path where this file is stored.
I want to create a global variable from json data. I'm sending the json data with websockets from a server to a client and I want that when the client receives json data, it creates a global variables for further use.
My json data is:
set_variable_data = [{
'component' : {
'name' : input("Component name: "),
'evse' : {
'id' : int(input("Number of Evses: ")),
'connector_id' : int(input("Number of connectors: "))
}
},
'variable' : {
'name' : input("Variable name: ")
}
}]
And I've tried to implement this code into the client program:
global set_variable_data[0]['variable']['name'] = set_variable_data[0]['component']['evse']['connector_id']
There's no problem with the send/receive procedures, all the messages are sent and received between the client and the server. I just want to know if we can create a global variable from this.
Thanks in advance
You can use the global keyword to modify a global variable from inside the function thar receives the data:
variable_data = {}
def receive_data(interface):
global variable_data
variable_data = interface.recv_json()
The global keyword allows to reference the variable variable_data when is assigned a value to it, in other case you will be making the assignation to a variable only inside the context of the function.
I am new to JSON. I have created custom JSON in AWS Opswork and trying to access it as an attribute in Chef recipe, but unfortunately its not catching the JSON values. My JSON file looks like..
{
"normal": {
"filebeat_minjar": {
"log_path" : "/var/log/*.log",
"hosts" : "Some Random Host ID",
"port" : 5000
}
}
}
and I am trying to catch it in recipe as,
log = node['filebeat_minjar']['log_path']
hosts = node['filebeat_minjar']['hosts']
port = node['filebeat_minjar']['port']
But it failed, I have also tried without 'normal'. I got the some []null class error.
Try this way,
log = node['normal']['filbeat_minjar']['log_path']
hosts = node['normal']['filbeat_minjar']['hosts']
port = node['normal']['filbeat_minjar']['port']
or
log = node.normal.filbeat_minjar.log_path
hosts = node.normal.filbeat_minjar.hosts
port = node.normal.filbeat_minjar.port
Json object is like a tree, the elements are the branches.
Hope this help
Your Chef code is correct, but you need to fix the JSON. You don't need the "normal": {...} in there, Chef and OpsWorks will handle that for you.
Following worked for me.
Custom JSON
{
"Production": {
"ApplicationLayer": {
"DockerTag" : "Version1"
}
}
}
Called from chef recipe.
node[:Production][:ApplicationLayer][:DockerTag]
I've been developing an app for about a year now, so I started it mid-2014 and have been upgrading ember.js and ember-cli as things move forward on those projects. I'm at Ember 1.11 now.
EDIT: Application Adapter
var ApplicationAdapter = DS.RESTAdapter.extend( {
namespace: 'api',
host: null,
setHost: Ember.on('init', function() {
set(this, 'host', this.container._registry.resolve('config:environment').API_ENDPOINT);
})
});
export default ApplicationAdapter;
My JSON API returns a main projects object, along with other sideloaded objects (like projectStatus). What I can't understand is, since I don't have any adapters or serializers that specify this, how I'm it's able to use the returned JSON, because it looks like this:
{
"projects" : {
"id": 4462875
"projectName" : "New business from Acme",
"projectDescription" : "Just another great project",
"pmlinks" : [ 1, 2],
"statusLinks" : [ 1440 ],
"commentsLinks" : [ 39 ]
},
"projectResources" : [ {
"id" : 1,
"name" : "Wile E. Coyote"
}, {
"id" : 2,
"name" : "Roadrunner"
}],
"projectComments" : [ {
"id" : 39,
"projectComment" : "started the project",
} ],
"projectStatuses" : [ {
"id" : 1440,
"status" : "G",
"trending" : "N",
"comment" : null,
"lastModifiedDate" : "2015-07-17T13:46:11.037+0000",
"project" : 4462875
} ],
}
I can't find anything in the Ember docs that recommend this "*Links" format for the relationships, and in fact it suggests using something more like status_ids. But the example it shows doesn't use _ids so I'm even more confused.
Here's a snippet of my project model:
statusUpdates: DS.hasMany('projectStatus'),
projectComments: DS.hasMany('projectComment'),
projectResources: DS.hasMany('projectResource'),
What I'm trying to figure out is with my new belongsTo relationship to schedule, how should the JSON be formatted from the API? It seems to work if the project object has a property like this "scheduleLinks": [10] but not if it's like "schedule": 10 or "schedule_id": 10 and that seems to be what the documentation says should work.
EDIT:
Maybe it's because the other objects like projectComments are named the way my model expects, and they're all returned at the same time from one API, that it doesn't even matter what the properties in the projects object is? Is that only to look up relationships if they're not all sideloaded?
The sideloading definitely is the thing here. Because if I change "statusLinks" to "projectStatus" then, since I have that relationship established in the project model, it will try to hit the API for that, e.g. /api/projectstatuses/:id.
So what seems to be happening is that the relationship is being hooked up from the belongsTo side implicitly; if the data is sideloaded, I don't need any links or IDs on the main object.
Using Drools 5.5.0.Final with Guvnor 5.5.0.Final with the sample mortgages package.
When submitting REST json request with the following Batch Execution Command:
{
"batch-execution": {
"lookup":"ksession1",
"commands":[
{
"insert":{
"out-identifier":"outApplicant",
"return-object":"true",
"object": {
"Applicant":{
"age":17
}
}
}
},
{
"fire-all-rules":""
}
]
}
}
returns: 500 Internal Server Error
com.thoughtworks.xstream.converters.ConversionException: Applicant : Applicant
---- Debugging information ----
message : Applicant
cause-exception : com.thoughtworks.xstream.mapper.CannotResolveClassException
cause-message : Applicant
class : org.drools.command.runtime.rule.InsertObjectCommand
required-type : org.drools.command.runtime.rule.InsertObjectCommand
converter-type : org.drools.runtime.help.impl.XStreamJson$JsonInsertConverter
line number : -1
class[1] : org.drools.command.runtime.BatchExecutionCommandImpl
converter-type[1] : org.drools.runtime.help..XSt...$JsonBatchExecutionCommandConverter
version : null
The Applicant class is defined in the mortgages package within an XSD like so:
age:Whole number (integer)
applicationDate:Date
creditRating:Text
name:Text
approved:True or False
How can I tell drools where to find the Applicant class? ( which is defined in the mortgage sample as an XSD file)
knowledge-services.xml currently looks like this:
<drools:grid-node id="node1"/>
<drools:kbase id="kbase1" node="node1">
<drools:resources>
<drools:resource type="PKG" source="http://localhost:8080/drools-guvnor/org.drools.guvnor.Guvnor/packages/mortgages"/>
</drools:resources>
</drools:kbase>
I suspect that changing the REST json request to fully specify the package name for Applicant class might work.
...
"object": {
"something.somethingelse.Applicant":{
"age":17
}
}
...
But can't seem to find where the fully qualified package name for Applicant is declared?
Acceptable answer must show an example which works without having to write java code, since the whole point of the REST interface is to access drools through a web service interface.
Is there a spring configuration , or some other way to write the json request that will work?
Since no one replied, I am posting the answer that worked for me along with the root cause and step-by-step procedure I used to debug the problem. Please do comment if there is a better way.
First, here is the complete and correct format for the REST Json request to insert an Applicant instance to the rules engine using drools-server when the model been defined in drools-guvnor GUI interface and not uploaded as a POJO model.
{
"batch-execution": {
"lookup":"ksession1",
"commands":[
{
"insert":{
"out-identifier":"outApplicant",
"return-object":"true",
"object": {
"mortgages.Applicant":{
"age":17
}
}
}
},
{
"fire-all-rules":""
}
]
}
}
Root cause: $TOMCAT_HOME/webapps/drools-server/WEB-INF/classes/knowledge-services.xml had incorrect resource.
The relevant parts of my corrected knowledge-services.xml:
<drools:grid-node id="node1"/>
<drools:kbase id="kbase1" node="node1">
<drools:resources>
<drools:resource
type="PKG"
source="http://localhost:8080/drools-guvnor/rest/packages/mortgages/binary"
basic-authentication="enabled"
username="admin"
password="admin"
/>
</drools:resources>
</drools:kbase>
Secondary issue: The authentication credentials were not specified in knowledge-services.xml
which resulted in this error:
Exception: java.io.IOException: Servier returned HTTP response code: 401 for URL: http://localhost:8080/drools-guvnor/rest/packages/mortgages/binary
Third issue: The example mortgage package was not built as a binary package in Guvnor.
ERROR: java.io.lang.RunTimeException: jav.io.StreamCorruptionException: Invalid Stream Header
To fix:
In Guvnor... Packages.. mortgages..Edit..build package
Additional note: INFO level logging is not enabled by default in drools-server.
To enable extra logging, so that you can see detailed debug messages in $TOMCAT_HOME/logs/catalina.log follow these steps:
Go to $TOMCAT_HOME/webapps/drools-server/WEB_INF/classes
create a file logging.properties
add these lines:
org.apache.catalina.core.ContainerBase.[Catalina].level = INFO
org.apache.catalina.core.ContainerBase.[Catalina].handlers = java.util.logging.ConsoleHandler
HTH