I am using elasticsearch-2.2.0 version. I need to enable scripting using JAVA API.
Basically I want to create a node using NodeBuilder and enable scripting support.
I tried setting the properties "script.inline : true" and "script.indexed : true" as below :
Settings settings = Settings.builder().put("script.inline", true).put("script.indexed", true).build();
but still it does not works.
Is there a way to enable scripting in elasticsearch-2.2.0 version using JAVA ?
This is similar to this issue and it seems that when creating a local NodeClient the lang-groovy module is not loaded by default.
So you need to add another dependency in your pom.xml
<dependency>
<groupId>org.elasticsearch.module</groupId>
<artifactId>lang-groovy</artifactId>
<version>2.2.0</version>
</dependency>
Related
I have project used Nashorn Javascript engine. I'm trying to migrate to java11 and also migrate from Nashorn to Graal. I've read here that I can use graal via the standard JDK installation starting from JDK 11. Also I've read there that Graal-SDK are uploaded to Maven central, and that there is Java flag polyglot.js.nashorn-compat for easy migration. So I've used jdk11, add maven dependency to pom.xml and used java flag but when I'm trying to get engine by name "graal.js", I've got null here:
ScriptEngine engine = engineManager.getEngineByName("graal.js")
What I'm missing? How to make it work?
Here is a sample maven project that shows how to run the GraalVM JavaScript engine on JDK11 both through the scripting API and the polyglot API. Hope it helps!
https://github.com/graalvm/graal-js-jdk11-maven-demo
The gist of it is to add the necessary dependencies (graal-sdk, js, js-scriptengine, and optionally profiler and chromeinspector), Run with enabled experimental options and the JVMCI compiler (-XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCI) and upgrade the module path with the graal jar (--upgrade-module-path=${compiler.dir}/compiler.jar) which is also available from maven (org.graalvm.compiler:compiler).
You are missing the following dependencies:
<dependency>
<groupId>org.graalvm.js</groupId>
<artifactId>js-scriptengine</artifactId>
</dependency>
<dependency>
<groupId>org.graalvm.truffle</groupId>
<artifactId>truffle-api</artifactId>
</dependency>
js-scriptengine contains the ScriptEngine implementation: com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.
And the truffle-api is required (you only get the rror message if you instanciate the GraalJSEngineFactory directly:
GraalJSEngineFactory gsf = new GraalJSEngineFactory();
However there seems to be another package missing, as it does not work for me.
Rest API works for me once I copy Rest api lib to libs folder and starting from a command line (./bin/ignite.sh ./examples/config/example-cache.xml
) and then trying url commands (e.g. http://localhost:8080/ignite?cmd=version).
How to do that from a java code? I tried starting a node with same configuration as above but Rest api seems that is not enabled (url commands do not work).
Thanks.
Most probably when you start Ignite from java code you don't have rest api lib in your classpath.
If you use maven, add this to dependencies in pom.xml:
<dependency>
<groupId>org.apache.ignite</groupId>
<artifactId>ignite-rest-http</artifactId>
<version>${ignite.version}</version>
</dependency>
Just don't forget to change ${ignite.version} to Ignite version you using.
How to get image that is captured from an azure VM created using ARM so that I can use it as a base image for all my subsequent VM creations with azure java sdk?
There is an offical blog can help you getting start with Azure Java SDK for Service Manage. Please refer to https://azure.microsoft.com/en-us/blog/getting-started-with-the-azure-java-management-libraries/.
For implementing this needs, you need to add some maven packages into your Java project. Please see the dependencies below.
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-svc-mgmt</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-svc-mgmt-compute</artifactId>
<version>0.9.0</version>
</dependency>
You can modify some code below to implement for listing custom images instead of the code for the section Calling the Azure API to Get a List of Regions at the blog.
VirtualMachineVMImageOperations virtualMachineVMImageOperations = client.getVirtualMachineVMImagesOperations();
VirtualMachineVMImageListResponse virtualMachineVMImageListResponse = virtualMachineVMImageOperations.list();
List<VirtualMachineVMImage> list = virtualMachineVMImageListResponse.getVMImages();
for(VirtualMachineVMImage virtualMachineVMImage: list) {
String vmImageName = virtualMachineVMImage.getName();
System.out.println(vmImageName);
}
Recently azure has released Java SDK 1.0.0 as LTS version.
Please refer below code to create a vm using custom image..
VirtualMachineCustomImage customImage = azure.virtualMachineCustomImages().getByResourceGroup("resource_gr_name", "image_name");
Creatable<VirtualMachine> linuxVM = azure.virtualMachines().define(vmName)
.withRegion(Region.US_WEST)
.withExistingResourceGroup("rishi")
.withExistingPrimaryNetwork(network)
.withSubnet("default") // Referencing the default subnet name when no name specified at creation
.withPrimaryPrivateIPAddressDynamic()
.withoutPrimaryPublicIPAddress()
.withLinuxCustomImage(customImage.id())
.withRootUsername("centos")
.withRootPassword("mdfxrJ68")
.withNewDataDisk(19)
.withDataDiskDefaultCachingType(CachingTypes.READ_WRITE)
.withDataDiskDefaultStorageAccountType(StorageAccountTypes.PREMIUM_LRS)
.withExistingStorageAccount(storageAccount)
.withOSDiskSizeInGB(10)
.withExistingStorageAccount(storageAccount)
.withSize(VirtualMachineSizeTypes.STANDARD_DS1_V2);
azure.virtualMachines().create(linuxVM);
I am using drools version 5.4 and I used url of changeset.xml to call the the drools-guvnor from my java code.
Now I am upgrading to drools 6.0 workbench version(Let me know if camel version is used), How can I call the drools workbench from my java code.
Thanks
Ganesh Neelekani
Everything in Drools 6 has become Mavenized. Instead of accessing a changeset.xml file you use the new Kie API to reference the Maven artifact that your rules are in.
First you would package your rules as a "kjar" (see this article for more info about kjars). Then, in your application you will need to add a the following dependency:
<dependency>
<groupId>org.kie</groupId>
<artifactId>kie-ci</artifactId>
<version>${drools.version}</version>
</dependency>
Then, to dynamically load the rules at runtime, you use the replacement for the ResourceChangeScanner which is called the KieScanner
ReleaseId releaseId = KieServices.Factory.get().newReleaseId( "com.acme", "my-rules", "0.0.1-SNAPSHOT" );
KieContainer kc = KieServices.Factory.get().newKieContainer( releaseId );
KieScanner kscanner = KieServices.Factory.get().newKieScanner( kcontainer );
kscanner.scanNow() // this will dynamically resolve the rules artifact and build it
From that point on you can use the kcontainer you attached to that scanner to create KieSessions. By calling scanNow() you are telling the scanner to poll that artifact for changes. It will automatically build updates that it detects to that artifact. You can also force a rebuild by calling scanNow() again.
I used to use neo4j-community-1.9.4 with my java maven project. I switched to version 2.0 and made completly new db in 2.0. When I run the same java code, I get error:
Exception in thread "main" org.neo4j.kernel.impl.storemigration.UpgradeNotAllowedByConfigurationException: Failed to start Neo4j with an older data store version. To enable automatic upgrade, please set configuration parameter "allow_store_upgrade=true"
at org.neo4j.kernel.impl.storemigration.ConfigMapUpgradeConfiguration.checkConfigurationAllowsAutomaticUpgrade(ConfigMapUpgradeConfiguration.java:39)
at org.neo4j.kernel.impl.storemigration.StoreUpgrader.attemptUpgrade(StoreUpgrader.java:64)
at org.neo4j.kernel.impl.nioneo.store.StoreFactory.tryToUpgradeStores(StoreFactory.java:104)
at org.neo4j.kernel.impl.nioneo.store.StoreFactory.newNeoStore(StoreFactory.java:86)
at org.neo4j.kernel.impl.nioneo.xa.NeoStoreXaDataSource.<init>(NeoStoreXaDataSource.java:232)
at org.neo4j.kernel.InternalAbstractGraphDatabase.create(InternalAbstractGraphDatabase.java:423)
at org.neo4j.kernel.InternalAbstractGraphDatabase.run(InternalAbstractGraphDatabase.java:226)
at org.neo4j.kernel.EmbeddedGraphDatabase.<init>(EmbeddedGraphDatabase.java:79)
at org.neo4j.graphdb.factory.GraphDatabaseFactory$1.newDatabase(GraphDatabaseFactory.java:70)
at org.neo4j.graphdb.factory.GraphDatabaseBuilder.newGraphDatabase(GraphDatabaseBuilder.java:205)
at org.neo4j.graphdb.factory.GraphDatabaseFactory.newEmbeddedDatabase(GraphDatabaseFactory.java:56)
at tools.Import.main(Import.java:32)
Any idea? Thank you.
Neo4j 2.0 requires an explicit store upgrade, because older versions will no longer be able to run on the upgraded store. The exception mentions this:
Failed to start Neo4j with an older data store version. To enable automatic upgrade, please set configuration parameter "allow_store_upgrade=true"
Simply add allow_store_upgrade=true to your neo4j.properties file, and start the database again. Then it should do the upgrade. You can read more about this here:
http://docs.neo4j.org/chunked/stable/deployment-upgrading.html#explicit-upgrade
Solved, I replaced dependency from spring:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-neo4j</artifactId>
<version>2.3.3.RELEASE</version>
</dependency>
By this:
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j</artifactId>
<version>2.0.0</version>
</dependency>
For community edition on windows,
click on Options, Database Configuration, Edit
look for allow_store_upgrade