Tag: groovy

将Netflix Zuul与Netflix Hystrix结合使用

我是Netflix开源项目的忠实粉丝。 他们做了一些很酷的东西。 我已经建立了一个Zuul,工作正常。 创建了所有类型的filter,并动态加载和运行。 我现在尝试做的是在filter中使用Hystrix。 我所看到的是,如果一切都很好,那一切都有效。 但是当run()方法中存在exception时,Zuul会捕获它而不是Hystrix。 所以从不调用getFallback()。 我分享了我的代码Github 。 有人知道Hystrix如何捕捉exception而不是Zuul?

Jenkins如何查找给定的奴隶是否正在运行作业

我有这个独特的要求来检查给定节点是否正在运行作业。 我正在考虑使用groovy,因为它看起来最简单。 我发现这个答案很有用。 如何通过Jenkins中的脚本或插件检查从属是否在线,然后再从其他项目开始构建 它允许我查找从站是否在线。 我的下一步是检查它是否正在运行一个作业。 我正在考虑使用API函数setAcceptingTasks(false)将slave标记为运行Job,这样当我下次使用isAcceptingTasks()查询时,我得到false,因此不会在该slave上启动作业。 但我宁愿拥有奴隶标记本身。 想到了taskAccepted()和taskCompleted() 。 一旦接受任务,我就可以将setAcceptingTasks调用为false,并且在完成任务后再次将isAcceptingTasks设置为true。 但我不确定这些函数的参数,例如执行器和任务。 这些函数调用在哪里适合groovy脚本。 我不确定我的任务假设是否等同于工作是否属实。 这就是我现在所拥有的: import hudson.model.* def requiredNodes = [‘Slave1’, ‘Slave2’, ‘Slave3’]; def status = 0; for (node in requiredNodes) { println “Searching for $node”; slave = Hudson.instance.slaves.find({it.name == node}); if (slave != null) { computer = slave.getComputer(); if (computer.isOffline()) { println “Error! $node […]

使用Groovy将bean序列化和反序列化为json

我已经通过groovy http://www.infoq.com/news/2014/04/groovy-2.3-json阅读了有关json的新闻。 所以我尝试使用本地方法(de)序列化包含日期的groovy bean。 但我有问题,使用JsonOutput.toJson(对象)和JsonObject.fromObject()与java.util.Date String jsonDat a= groovy.json.JsonOutput.toJson(contact) Contact reloadContact = new Contact(net.sf.json.JSONObject.fromObject(jsonData)) 在groovy 2.3+中使用本机方法的正确方法是什么? 否则,我可以去另一个像gson这样的图书馆( http://www.mkyong.com/java/how-do-convert-java-object-to-from-json-format-gson-api/ ) package test import groovy.json.JsonOutput import net.sf.json.JSONObject class JsonTest { public static void main(String[] args) { JsonTest test = new JsonTest() test.serialization() } public void serialization(){ Contact contact = new Contact() contact.name = ‘John’ contact.registration = Date.parse(‘dd/MM/yyyy’, […]

ElasticSearch Java API的异步性质

想为elasticSearch服务编写集成测试: 1.指数 2.搜索 3.检查结果 每个Java api方法都是异步执行的。 如何将其设为简单的同步api:call api.a ,等待结果,调用api.b ,等待结果…

在groovy bean中注入Spring bean

我有spring-boot-starter-remote-shell的Spring Boot应用程序。 当我把这个hello.groovy脚本打印出’hello’时就可以了。 package commands import org.crsh.cli.Usage import org.crsh.cli.Command class hello { @Usage(“Say Hello”) @Command def main(InvocationContext context) { return “hello”; } } 但是当我尝试注入一些Spring bean时,它总是为null。 package commands import org.crsh.cli.Usage import org.crsh.cli.Command import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Component import org.springframework.batch.core.launch.JobLauncher @Component class hello { @Autowired JobLauncher jobLauncher; @Usage(“Say Hello”) @Command def main(InvocationContext context) { if(jobLauncher != null){ return […]

在groovy中读取Excel文件的最简单方法?

是否有任何warappers / utils可用于读取Groovy中的Excel文件。 我正在寻找类似于Groovy SQL的行函数的东西,如下面的spock测试示例所示。 我的目的是在Spock测试框架中使用excel进行数据驱动测试 import groovy.sql.Sql import spock.lang.* class DatabaseDriven extends Specification { @Shared sql = Sql.newInstance(“jdbc:h2:mem:”, “org.h2.Driver”) // normally an external database would be used, // and the test data wouldn’t have to be inserted here def setupSpec() { sql.execute(“create table maxdata (id int primary key, a int, b int, c int)”) […]

什么是Groovy / Grails / Hibernate / JBoss / Jade非常简单?

我是Java新手。 它只有六个月,但我确实理解Java。 在阅读有关它的同时,我遇到了这些术语 – Groovy,Grails,Hibernate,JBoss,Jade等等。 我知道我可以单独阅读所有这些内容。 但有人可以给我一个关于这里发生的事情的树梢视图吗? 这是什么? 我们有Java,这些都是基于Java的? 为什么这么多东西? 我们为什么需要它们?

在Java中使用GroovyClassLoader时,找不到类:org.apache.ivy.core.report.ResolveReport

我有一个像这样的groovy脚本: @Grab(‘com.univocity:univocity-parsers:2.0.0’) import com.univocity.parsers.csv.*; class MyCsvParser { } 我想通过GroovyClassLoader在我的java应用程序中加载这个类。 但@Grab以某种方式在常春藤例外产生: SomeJavaClass { void someMethod() { String script = FileUtils.readFileToString(“the groovy File”); Class c = new GroovyClassLoader(this.getClass().getClassLoader())).parse(script); } } 堆: Caused by: java.lang.ClassNotFoundException: org.apache.ivy.core.report.ResolveReport at java.net.URLClassLoader.findClass(URLClassLoader.java:381) at java.lang.ClassLoader.loadClass(ClassLoader.java:424) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331) at java.lang.ClassLoader.loadClass(ClassLoader.java:357) … 41 more 当我评论@Grab一切正常。 如何在GroovyClassLoader启用Grapes?

Spring Tool Suite(STS)3.5.0 – org.codehaus.groovy.eclipse在求解器中是未知的

STS 3.5.0存在问题 https://issuetracker.springsource.com/browse/STS-3792 org.codehaus.groovy.eclipse 2.9.0.xx-201403261719-e43j8在求解器中未知! 这些是我修复它的步骤,它允许我使用eclipse市场

有没有比这更容易的方式开始当前时间?

我基本上想要获得零或开始时间的一天。 def today = Calendar.instance today.set(Calendar.HOUR_OF_DAY, 0) today.set(Calendar.MINUTE, 0) today.set(Calendar.SECOND, 0) println today // Mon Mar 15 00:00:00 SGT 2010