Creating and retrieving JIRA remote issue links - java

I am trying to write a transition post function for JIRA v5.x. It should check if there is already a Confluence page linked with the issue, and create and link the page if not.
I am developing this using the a groovy script and the scriptrunner plugin which can access the JAVA API.
While it was fairly easy to create the confluence page, I am struggling with the remote issue links.
How can I create a new remote issue link?
How can I determine if a link already exists for an issue?
This is how I try to create the link:
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.bc.issue.link.RemoteIssueLinkService
import com.atlassian.jira.issue.link.RemoteIssueLinkBuilder
//I use a wrapper class for the moment so I can run via scriptrunner and debug it in IDEA
class myWrapper {
def doStuff() {
//get the issue, this would already be available in an post action
def issueService = ComponentManager.getInstance().getIssueService();
def authContext = ComponentManager.getInstance().getJiraAuthenticationContext()
def issueResult = issueService.getIssue(authContext.getUser(), "DEV-1");
def issue = issueResult.getIssue()
//build link
def linkBuilder = new RemoteIssueLinkBuilder()
linkBuilder.issueId(issue.id)
linkBuilder.applicationName("myconluence")
linkBuilder.applicationType("com.atlassian.confluence")
linkBuilder.relationship("Wiki Page")
linkBuilder.title("testpage")
linkBuilder.url("http://localhost:8090/display/LIN/testpage")
linkBuilder.build()
def validationResult = RemoteIssueLinkService.validateCreate(authContext.getUser(), linkBuilder)
}
}
(new myWrapper()).doStuff()
When I run the code I get the following exception:
javax.script.ScriptException: groovy.lang.MissingMethodException: No signature of method: static com.atlassian.jira.bc.issue.link.RemoteIssueLinkService.validateCreate() is applicable for argument types: (com.atlassian.crowd.embedded.ofbiz.OfBizUser, com.atlassian.jira.issue.link.RemoteIssueLinkBuilder) values: [admin:1, com.atlassian.jira.issue.link.RemoteIssueLinkBuilder#180ca9]
For me it looks like I do not get the RemoteIssueLinkService correctly,but I do not know what I have to do to fix that.

I asked the same question in the atlassian forum . Here is the working answer that I received from Jamie Echlin for future reference
It's not a static method, so you need to get an instance of the class first:
def remoteIssueLinkService = ComponentManager.getComponentInstanceOfType(RemoteIssueLinkService.class)
remoteIssueLinkService.validateCreate(...)

Related

How to get model status in tensorflow serving

I'm tring to write a client in Scala (or Java) to get model status in tensorflow serving. After reading through all the proto files in the directory: /serving/tensorflow_serving/apis, I thought these two files: get_model_status.proto and model_service.proto provide the necessary apis for me to use. But my simple test returned with an error: "Exception in thread "main" io.grpc.StatusRuntimeException: UNIMPLEMENTED". And here is the code snippet:
val channel = ManagedChannelBuilder
.forAddress(host, port)
.usePlaintext(true)
.asInstanceOf[ManagedChannelBuilder[_]]
.build
val modelStub = tensorflow.serving.ModelServiceGrpc.newBlockingStub(channel)
val modelRequest = tensorflow.serving.GetModelStatus
.GetModelStatusRequest
.newBuilder
.setModelSpec(ModelSpec.newBuilder.setName("x").setSignatureName("x"))
.build
println(modelStub
.getModelStatus(modelRequest)
.getModelVersionStatusList
.asScala)
The error "UNIMPLEMENTED" seems to suggest that I have to define a new signature to add to the meta graph to process the request and return the response, which confuses me because this new signature is not the model I want to check anymore. My question is how to use this getModelStatus function? Any advices are appreciated!
Answer my own question:
the above code is correct;
no need to define extra signature, just use normally exported model;
using tf_serving version >= 1.5 solves this problem.
The "UNIMPLEMENTED" error came out when I used tf_serving binary of version 1.4.
For more details about this process, you could check the official python function testGetModelStatus in /serving/tensorflow_serving/model_servers/tensorflow_model_server_test.py

Calling methods between groovy scripts with correct parameters

I just started learning about groovy and trying to transpose my java code to groovy scripts. Usually java allows you have a class with only methods that you can call from other classes. I wanted to translate that to groovy. I have in one file - lets call it File1- a method like this:
def retrieveData(String name){
// do something
}
and in the second file, File2, I call File1 like this:
def file1Class = this.class.classLoader.parseClass(new File("../File1.groovy"))
and then try to call the method in File1 like this:
def data = file1Class.retrieveData("String")
but it keeps giving me this error - MissingMethodException:
groovy.lang.MissingMethodException: No signature of method: static File1.retrieveData() is applicable for argument types: (java.lang.String) values: [String] Possible solutions: retrieveData(java.lang.String)
so it does recognize that I am sending in the correct number of parameters and even the correct object, but it isn't running the method as it should?
Is there something I am missing? I tried to remove the object definition from the method - in other words - like this:
def retrieveData(name){
// do something
}
but that didn't work either. I am clueless about what the next step would be. Can anyone please help push me in the right direction? I would greatly appreciate it.
See the answer provided in this StackOverflow reponse.
Use the GroovyScriptEngine class. What does the GroovyScriptEngine do? From the docs:
Specific script engine able to reload modified scripts as well as
dealing properly with dependent scripts.
See the example below.
def script = new GroovyScriptEngine( '.' ).with {
loadScriptByName( '..\File1.groovy' )
}
this.metaClass.mixin script
retrieveData()
Note how we use the loadScriptByNamemethod to
Get the class of the scriptName in question, so that you can
instantiate Groovy objects with caching and reloading.
This will allow you to access Groovy objects from files however you please.

Searchanalytics Query JAVA API v3 (Google WebMaster Tools)

I am trying to implement Google Webmasters Searchanalytics Query using using the Java API but i did not found any Java sample to use , in Google website here there is only Python samples for Searchanalytics Query , and they did not say that it's not available in Java API.
I found this class Webmasters.Searchanalytics.Query in the Java API which I assume that is equivalent to the Python function searchanalytics.query() but i did not found any implementation of it.
My question if it is possible to query data from Google Search Console using the Java API??
if yes i wounder if there is someone who can provide a Java sample, something like the Python sample provided by Google here.
Thank you in advance.
I succeded to implement Webmasters.Searchanalytics.Query
as follow
first you need to create your QueryRequest using the SearchAnalyticsQueryRequest class example:
private static SearchAnalyticsQueryRequest createSearchAnalyticsQueryRequest() {
SearchAnalyticsQueryRequest searQueryRequest = new SearchAnalyticsQueryRequest();
searQueryRequest.setStartDate("2016-04-10");
searQueryRequest.setEndDate("2016-04-20");
List<String> dimensions = new ArrayList<String>();
dimensions.add("page");
dimensions.add("query");
dimensions.add("country");
dimensions.add("device");
dimensions.add("date");
searQueryRequest.setDimensions(dimensions);
return searQueryRequest;
}
then executing the query as follow :
public static String Query(String site,
SearchAnalyticsQueryRequest searQueryRequest) throws Exception {
Webmasters.Searchanalytics.Query query = service.searchanalytics()
.query(site, searQueryRequest);
SearchAnalyticsQueryResponse queryResponse = query.execute();
return queryResponse.toPrettyString();
}
I think You missed it. here. Actually all you need to do is to click the Java link on the left.

How do I evaluate a Groovy string within a script?

I'm essentially trying to create a CLI with Groovy. I have a whole JavaFX GUI set up in Java and I want to be able to type in groovy script to run different functions inside a groovy script.
For example, say I have this script:
void meow() {
println "walrus"
}
I want to be able to type in "meow();" and press enter and evaluate it using the script as a reference.
I've tried using
shell.evaluate(inputStr, "src/Server/Scripting/CommandLineScript.groovy");
but to no avail; it just comes up with the error:
groovy.lang.MissingMethodException: No signature of method: CommandLineScript.meow() is applicable for argument types: () values: []
I can call other standard functions, such as:
shell.evaluate("println 'Hello World!';");
but I just can't run my own methods... How to solve it?
The following worked for me.
evaluate(new File("/Users/jellin/meow.groovy"))
I did change the meow.groovy file to execute the method within the file.
void meow() {
println "walrus"
}
meow()
One issue is I don't see a way to pass a parameter to the calling script.
I have used the following before, you can pass parameters as part of the binding.
String script = "full path to the script"
GroovyScriptEngine gse = new GroovyScriptEngine()
Binding binding = new Binding();
Object result = gse.run(script, binding)
Also, you might be able to simply reference the other scripts as classes and execute the run method on them.
There is also an AST transformation that can be used to have scripts extend a base script.
See here for more info
http://mrhaki.blogspot.com/2014/05/groovy-goodness-basescript-with.html
Thanks for your time guys; after a little more searching (always after posting a question do I find the answer in research >,<), I found that you can set a base class for the GroovyShell... I did it this way:
ClassLoader parent = getClass().getClassLoader();
GroovyClassLoader loader = new GroovyClassLoader(parent);
loader.addClasspath("src/ScriptLoc/");
binding = new Binding();
CompilerConfiguration compConfig = new CompilerConfiguration();
compConfig.setScriptBaseClass("ScriptName");
shell = new GroovyShell(loader, binding, compConfig);
I thought there would be a way to do it, and there it is... Now whenever I need to evaluate a script from the text box, I can just evaluate it and it evaluates it in the context of the base script.

Could not find implementation class: "cassandra"

I'm trying to connect to Titan backed with Cassandra (installed with the Rexster Titan-Server package) via Titan-Node.
I get the error...
java.lang.IllegalArgumentException: Could not find implementation
class: "cassandra"
... when I run the following code....
var Titan = require('titan-node');
var gremlin = new Titan.Gremlin({ loglevel: 'OFF' });
var TitanFactory = gremlin.java.import('com.thinkaurelius.titan.core.TitanFactory');
var graph = TitanFactory.openSync('titan.config');
Config:
storage.directory = "/tmp/titan"
storage.backend = "cassandra"
storage.hostname = "127.0.0.1"
storage.port = 9160
Any ideas?
I seem to have the required .jar within my Titan installation folder and also in the target/dependency folder within the Titan-Node package.
Why can't Java find the file? Is there a missing classpath entry? If so would it need to be set for the database or for node? I figure it would be node because that's the app trying to load the class.
EDIT
Dan's suggestion gave me....
'java.lang.IllegalArgumentException: Could not find implementation
class:
"com.thinkaurelius.titan.diskstorage.cassandra.thrift.CassandraThriftStoreManager"'
...and...
'java.lang.IllegalArgumentException: Could not find implementation
class:
"com.thinkaurelius.titan.diskstorage.cassandra.astyanax.AstyanaxStoreManager"'
...respectively.
In fact whatever value you set storage.backend to in the config, that's the name of the class it can't find an implementation for that it reports in the exception message.
If you look in the code here...
https://github.com/thinkaurelius/titan/blob/master/titan-core/src/main/java/com/thinkaurelius/titan/diskstorage/Backend.java
...the instantiate method that is throwing the exception uses the method parameter clazzname in the message which is passed in by the call in getImplementationClass. The latter ought to be looking up the class to load via the key set in storage.backend but oddly it doesn't seem to find anything so it uses the value as is. Even so, it still can't find the class even if you set it directly. So there's a second mystery here.
I suppose I will have to go through Rexster until this is fixed.
At this time titan-node supports Titan 0.4.1 java jar files.
You can upgrade it by replacing new Titan jar files.
Then you can use the code bellow to connect to Titan
var Titan = require('titan-node');
var gremlin = new Titan.Gremlin({ loglevel: 'OFF' });
var BaseConfiguration = gremlin.java.import('org.apache.commons.configuration.BaseConfiguration');
var _confObj={'backend':'cassandra','hostname':'127.0.0.1'};
var TitanFactory = gremlin.java.import('com.thinkaurelius.titan.core.TitanFactory');
conf = new BaseConfiguration();
conf.setPropertySync("storage.backend",_confObj.backend);
conf.setPropertySync("storage.hostname",_confObj.hostname);
var graph = TitanFactory.openSync(conf);
var g = gremlin.wrap(graph);
g.addVertex(null, function (err, saturn) {
console.log('added');
g.commit(function() {
console.log('commited');
});
});

Categories