I have made my DSL and set some info, warning, and error messages.
For example:
warning('''some message''', obj, package.Literals.LITERAL)
Then I exported project(generator made class Main.xtend) into a some_name.jar
Main.xtend contains:
// Validate the resource
val issues = validator.validate(resource, CheckMode.ALL,CancelIndicator.NullImpl)
if (!issues.empty) {
issues.forEach[System.err.println(it)]
return
}
// Configure and start the generator
fileAccess.outputPath = 'src-gen/'
val context = new GeneratorContext => [cancelIndicator = CancelIndicator.NullImpl]
generator.generate(resource, fileAccess, context)
System.out.println('Code generation finished.')
Now when I run
> *java -jar some_name.jar my_file*
The generator doesn't generate code because these info/warning messages.
How can I suppress specific info/warning/error messages?
Related
I am trying to use some Java RHS to get the string value of dependent tokens using Stanford dependency parser in GATE, and add them as features of a new annotation.
I am having problems targeting just the 'dependencies' feature of the token, and getting the string value from the tokenID.
Using below specifying only 'depdencies' also throws a java null pointer error:
for(Annotation lookupAnn : tokens.inDocumentOrder())
{
FeatureMap lookupFeatures = lookupAnn.getFeatures();
token = lookupFeatures.get("dependencies").toString();
}
I can use below to get all the features of a token,
gate.Utils.inDocumentOrder
but it returns all features, including the dependent tokenID's; i.e:
dependencies = [nsubj(8390), dobj(8394)]
I would like to get just the dependent token's string value from these tokenID's.
Is there any way to access dependent token string value and add them as a feature to the annotation?
Many thanks for your help
Here is a working JAPE example. It only printns to the GATE's message window (std out), It doesn't create any new annotations with features you asked for. Please finish it yourself...
Stanford_CoreNLP plugin has to be loaded in GATE to make this JAPE file loadable. Otherwise you will get class not found exception for DependencyRelation class.
Imports: {
import gate.stanford.DependencyRelation;
}
Phase: GetTokenDepsPhase
Input: Token
Options: control = all
Rule: GetTokenDepsRule
(
{Token}
): token
-->
:token {
//note that tokenAnnots contains only a single annotation so the loop could be avoided...
for (Annotation token : tokenAnnots) {
Object deps = token.getFeatures().get("dependencies");
//sometimes the dependencies feature is missing - skip it
if (deps == null) continue;
//token.getFeatures().get("string") could be used instead of gate.Utils.stringFor(doc,token)...
System.out.println("Dependencies for token " + gate.Utils.stringFor(doc, token));
//the dependencies feature has to be typed to List<DependencyRelation>
List<DependencyRelation> typedDeps = (List<DependencyRelation>) deps;
for (DependencyRelation r : typedDeps) {
//use DependencyRelation.getTargetId() to get the id of the target token
//use inputAS.get(id) to get the annotation for its id
Annotation targetToken = inputAS.get(r.getTargetId());
//use DependencyRelation.getType() to get the dependency type
System.out.println(" " +r.getType()+ ": " +gate.Utils.stringFor(doc, targetToken));
}
}
}
I'm trying to use the Publish over SSH plugin inside a Jenkinsfile. However, I'm getting the exception java.io.NotSerializableException in the createClient method. This is my code:
def publish_ssh = Jenkins.getInstance().getDescriptor("jenkins.plugins.publish_over_ssh.BapSshPublisherPlugin")
def hostConfiguration = publish_ssh.getConfiguration("${env.DSV_DEPLOY_SERVER}");
if( hostConfiguration == null )
{
currentBuild.rawBuild.result = Result.ABORTED
throw new hudson.AbortException("Configuration for ${env.DSV_DEPLOY_SERVER} not found.")
}
def buildInfo = hostConfiguration.createDummyBuildInfo();
def sshClient = hostConfiguration.createClient( buildInfo, new BapSshTransfer(
env.SOURCE_FILE,
null,
env.DSV_DEPLOY_REMOTE_DIR,
env.REMOVE_PREFIX,
false,
false,
env.DSV_DEPLOY_COMMAND,
env.DSV_DEPLOY_TIMEOUT as Integer,
false,
false,
false,
null
));
How can I get rid of the exception?
It is because some variables are not serializable.
From doc
Since pipelines must survive Jenkins restarts, the state of the running program is periodically saved to disk so it can be resumed later (saves occur after every step or in the middle of steps such as sh).
You may use #NonCPS annotation to do the creation,
use the
#NonCPS
def createSSHClient() {
// your code here.
}
I need to run an aggregation Spark job using spark-jobserver using low-latency contexts. I have this Scala runner to run a job on using a Java method from a Java class.
object AggregationRunner extends SparkJob {
def main(args: Array[String]) {
val ctx = new SparkContext("local[4]", "spark-jobs")
val config = ConfigFactory.parseString("")
val results = runJob(ctx, config)
}
override def validate(sc: SparkContext, config: Config): SparkJobValidation = {
SparkJobValid;
}
override def runJob(sc: SparkContext, config: Config): Any = {
val context = new JavaSparkContext(sc)
val aggJob = new ServerAggregationJob()
val id = config.getString("input.string").split(" ")(0)
val field = config.getString("input.string").split(" ")(1)
return aggJob.aggregate(context, id, field)
}
}
However, I get the following error. I tried taking out the content returned in the Java method and am now just returning a test string, but it still doesn't work:
{
"status": "ERROR",
"result": {
"message": "Ask timed out on [Actor[akka://JobServer/user/context-supervisor/single-context#1243999360]] after [10000 ms]",
"errorClass": "akka.pattern.AskTimeoutException",
"stack": ["akka.pattern.PromiseActorRef$$anonfun$1.apply$mcV$sp(AskSupport.scala:333)", "akka.actor.Scheduler$$anon$7.run(Scheduler.scala:117)", "scala.concurrent.Future$InternalCallbackExecutor$.scala$concurrent$Future$InternalCallbackExecutor$$unbatchedExecute(Future.scala:694)", "scala.concurrent.Future$InternalCallbackExecutor$.execute(Future.scala:691)", "akka.actor.LightArrayRevolverScheduler$TaskHolder.executeTask(Scheduler.scala:467)", "akka.actor.LightArrayRevolverScheduler$$anon$8.executeBucket$1(Scheduler.scala:419)", "akka.actor.LightArrayRevolverScheduler$$anon$8.nextTick(Scheduler.scala:423)", "akka.actor.LightArrayRevolverScheduler$$anon$8.run(Scheduler.scala:375)", "java.lang.Thread.run(Thread.java:745)"]
}
}
I am not too sure why there is a timeout since I am only returning a string.
EDIT
So I figured out that the issue was occurring because I was using a Spark context that was created before updating a JAR. However, now that I try to use JavaSparkContext inside the Spark job, it returns to the error shown above.
What would be a permanent way to get rid of the error.
Also, would the fact that I am running a heavy Spark job on a local docker container be a plausible reason for the timeout.
For resolving ask time out issue, please add/change below properties in jobserver configuration file.
spray.can.server {
idle-timeout = 210 s
request-timeout = 200 s
}
for more information take a look at this https://github.com/spark-jobserver/spark-jobserver/blob/d1843cbca8e0d07f238cc664709e73bbeea05f2c/doc/troubleshooting.md
I'm using ph-schematron to validate my XML files. I'm able to validate the files correctly but I couldn't find how to generate reports about failing assertions.
This is my context(point-of-interest):
<bpmn:extensionElements>
<activiti:in sourceExpression="RESERVATION" target="OPERATION_CODE"/>
<activiti:in sourceExpression="true" target="IS_SYNC"/>
</bpmn:extensionElements>
This is my Schematron schema:
<iso:schema
xmlns="http://purl.oclc.org/dsdl/schematron"
xmlns:iso="http://purl.oclc.org/dsdl/schematron"
queryBinding='xslt2'
schemaVersion='ISO19757-3'>
<iso:title>Test ISO schematron file. Introduction mode</iso:title>
<iso:ns prefix='bpmn' uri='http://www.omg.org/spec/BPMN/20100524/MODEL'/>
<iso:ns prefix='activiti' uri='http://activiti.org/bpmn'/>
<iso:let name="callActivity" value="bpmn:definitions/bpmn:process/bpmn:callActivity"/>
<iso:let name="inSourceExpression" value="child::activiti:in/sourceExpression"/>
<iso:let name="outSourceExpression" value="child::activiti:out/sourceExpression"/>
<iso:let name="inTarget" value="child::activiti:in/target"/>
<iso:let name="outTarget" value="child::activiti:out/target"/>
<!-- Your constraints go here -->
<iso:pattern id="RESERVATION">
<iso:p>
This pattern validates call activities with RESERVATION operation code.
</iso:p>
<iso:rule context="$callActivity[bpmn:extensionElements/activiti:in[(#target='OPERATION_CODE') and (#sourceExpression='RESERVATION')]]/bpmn:extensionElements">
<iso:assert test="count(($inSourceExpression='RESERVATION') and ($inTarget='OPERATION_CODE')) = 0">err1</iso:assert>
<iso:assert test="count(($inSourceExpression='true') and ($inTarget='IS_SYNC')) = 1">err2</iso:assert>
</iso:rule>
</iso:pattern>
</iso:schema>
This is my Java code:
public static boolean validateXMLViaPureSchematron(#Nonnull final String aSchematronFilePath, #Nonnull final File aXMLFile) throws Exception {
final SchematronResourcePure schematronResourcePure = SchematronResourcePure.fromClassPath(aSchematronFilePath);
IPSErrorHandler errorHandler = new CollectingPSErrorHandler();
schematronResourcePure.setErrorHandler(errorHandler);
final boolean validSchematron = schematronResourcePure.isValidSchematron();
if (!validSchematron) {
throw new IllegalArgumentException("Invalid Schematron!");
}
final Source streamSource = new StreamSource(aXMLFile);
final EValidity schematronValidity = schematronResourcePure.getSchematronValidity(streamSource);
return schematronValidity.isValid();
}
I can see the result of the validation by calling schematronResourcePure.getSchematronValidity(streamSource) but I want to see (a report would be sufficient) which rules are failed(err1 or err2). I've read about SVRL but I don't know how to generate report.
Thank you.
Simply call applySchematronValidationToSVRL to get the full SVRL (Schematron Validation Result List) document. You can query it for failed asserts or reports.
Code example where only failed asserts are printed:
SchematronOutputType schematronOutputType = schematronResourcePure.applySchematronValidationToSVRL(streamSource);
List<Object> failedAsserts = schematronOutputType.getActivePatternAndFiredRuleAndFailedAssert();
for (Object object : failedAsserts) {
if (object instanceof FailedAssert) {
FailedAssert failedAssert = (FailedAssert) object;
System.out.println(failedAssert.getText());
System.out.println(failedAssert.getTest());
}
}
I am using a class that accepts overridden methods i meant optional argument signatures (not sure if that matters in this case, but maybe)
when I call this from IRB it is working as expected, eg, it accepts the arguments
(filtering namespaces and passwords with [filtered] where needed to keep secret stuff secret and my company happy)
jruby-1.5.0 > require 'java'
=> true
jruby-1.5.0 > Dir.glob('lib/java/*.jar').each{|jar| require jar}
=> ["lib/java/[filtered].jar", "lib/java/[filtered].jar", "lib/java/[filtered].jar"]
jruby-1.5.0 > import "[filtered].His351n1"
=> Java::[filtered]::His351n1
jruby-1.5.0 > broker = [filtered].Broker.new('[filtered]', '[filtered]')
=> #<Java::[filtered]::Broker:0x4c4936f3>
jruby-1.5.0 > rpc = "[filtered]"
=> "[filtered]"
jruby-1.5.0 > his = His351n1.new(broker, rpc)
=> #<Java::[filtered]::His351n1:0x7fb6a1c4>
and here is my spec and matching code
before(:each) do
#base = Legacy::Base.new
end
it "should create a valid his351n1 object" do
his = #base.create_his351n1
puts his.inpsect
end
# from within Legacy::Base
def create_his351n1
his = His351n1.new(build_broker, rpc)
end
and finally, the error which fails on the call to His351n1.new
1)
ArgumentError in 'Legacy::Base should create a valid his351n1 object'
wrong # of arguments(2 for 0)
To complicate things, on the irb, this is also apparently valid:
jruby-1.5.0 > his = His351n1.new
=> #<Java::[filtered]::His351n1:0x5ad3c69c>
Also, here are the overridden java methods
public His351n1() {
super();
}
public His351n1(Broker broker) {
this(broker, DEFAULT_SERVER);
}
public His351n1(BrokerService bs) {
this(bs.getBroker(), bs.toString());
}
public His351n1(Broker broker, String serverAddr) {
super(broker, serverAddr, "string", true);
}
public His351n1(final Broker broker, final String serverAddr, final String library)
{
super(broker, serverAddr, library, true);
}
it seems that you have to require the whole namespace in the instantiation of the object aka:
his = Java::[filtered_namesapce]::His351n1.new(build_broker, rpc)