[rules-users] Guvnor service to compile part of a package ?

Jervis Liu jliu at redhat.com
Thu May 5 13:17:21 EDT 2011


On 2011/5/5 20:13, Vincent LEGENDRE wrote:
> Ok, thanks
>
> I had a look to this, and indeed you can query indiviual resource, or get a list of resources in one package.
> But If i understand well you idea, it is still necessary to compile manually some package using filters, and put then into separate snapshots by instance.
>
> I think it is really close to what I need, but I need to provide the filter in a query to get filtered assets (results got from REST query looses the Guvnor metadata, it only returns asset's content).
> Something like this would be perfect :
>     http://localhost:8080/path/to/guvnor/api/packages/my.sample.package?category=foo&category=bar&status=prod
> ->  return the list of assert having categories "foo" and "bar" and status set to "prod"
I am not sure if I understand you correctly. You want to return a 
compiled package binary based on certain criteria or you want to return 
individual assets based on certain criteria?
If its the former, you can do this through Guvnor REST API (to be 
precise, it is the new JAX-RS based REST api). In this case, you dont 
provide filters through the URL. When you hit the REST URL for example 
http://localhost:8080/drools-guvnor/rest/packages/mortgage, the REST 
service will first check if this package's binary is up-to-date. If not, 
it will build the package first, then return compiled binary. It is the 
Guvnor selector in charge of which assets get into the build. At the 
moment, we dont have a REST API to control which selector is taking 
effect during the build, but if this is what you need, I am sure we can 
figure this out.

> I am not familiar with feeds, but the last XML sample of your link seems to allow some filtering ? Or is it just metadata set in the package ? Or it is possible to create feed with filtered assets, and then query them (that would be perfect too).
>
>
If what you want is to return individual assets, you can send a HTTP GET 
request to URL 
http://host:portnumber/drools-guvnor/rest/packages/mortgage/assets 
<http://community.jboss.org/docs/DOC-16217> with 
Accept="application/atom+xml", this returns a list of assets under the 
mortgage package in Atom feed format. An example looks like below:

<feed xmlns="http://www.w3.org/2005/Atom" 
xmlns:xml="http://www.w3.org/XML/1998/namespace" 
xml:base="http://localhost:9080/ 
<http://localhost:9080/repository/packages/testPackage1/assets>drools-guvnor/rest 
<http://localhost:9080/repository/packages/testPackage1/assets>/packages/mortgage/assets 
<http://localhost:9080/repository/packages/testPackage1/assets>">
<title>testPackage1's asset</title>

<entry xml:base="http://localhost:9080/drools-guvnor/rest/packages/ 
<http://localhost:9080/repository/packages/testPackage1/assets>mortgage 
<http://localhost:9080/repository/packages/packageName/asset/testAsset2>/assets 
<http://localhost:9080/repository/packages/testPackage1/assets>">
<title>testAsset1</title>
<link href="http://localhost:9080/ 
<http://localhost:9080/repository/packages/packageName/asset/testAsset1>drools-guvnor/rest 
<http://localhost:9080/repository/packages/testPackage1/assets>/packages/ <http://localhost:9080/repository/packages/packageName/asset/testAsset1>mortgage 
<http://localhost:9080/repository/packages/packageName/asset/testAsset2>/assets/testAsset1 
<http://localhost:9080/repository/packages/packageName/asset/testAsset1>" />
</entry>

<entry xml:base="http://localhost:9080/ 
<http://localhost:9080/repository/packages/testPackage1/assets>drools-guvnor/rest 
<http://localhost:9080/repository/packages/testPackage1/assets>/packages/ <http://localhost:9080/repository/packages/testPackage1/assets>mortgage 
<http://localhost:9080/repository/packages/packageName/asset/testAsset2>/assets 
<http://localhost:9080/repository/packages/testPackage1/assets>">
<title>testAsset2</title>
<link href="http://localhost:9080/ 
<http://localhost:9080/repository/packages/packageName/asset/testAsset2>drools-guvnor/rest 
<http://localhost:9080/repository/packages/testPackage1/assets>/packages/mortgage/assets/testAsset2 
<http://localhost:9080/repository/packages/packageName/asset/testAsset2>" />
</entry>
</feed>

Then you can further navigate to individual assets using the link 
returned. For example a GET request to http://host:portnumber/ 
<http://community.jboss.org/docs/DOC-16217>drools-guvnor/rest 
<http://localhost:9080/repository/packages/testPackage1/assets>/packages/mortgage/assets 
<http://localhost:9080/repository/packages/packageName/asset/testAsset2>/testAsset1 
<http://community.jboss.org/docs/DOC-16217> with 
Accept="application/atom+xml" returns an atom entry which is the meta 
data info of that asset. Or URL http://host:portnumber/ 
<http://community.jboss.org/docs/DOC-16217>drools-guvnor/rest 
<http://localhost:9080/repository/packages/testPackage1/assets>/packages/mortgage/assets 
<http://localhost:9080/repository/packages/packageName/asset/testAsset2>/testAsset1/source 
<http://community.jboss.org/docs/DOC-16217> to return source and URL 
http://host:portnumber/ 
<http://community.jboss.org/docs/DOC-16217>drools-guvnor/rest 
<http://localhost:9080/repository/packages/testPackage1/assets>/packages/mortgage/assets 
<http://localhost:9080/repository/packages/packageName/asset/testAsset2>/testAsset1/binary 
<http://community.jboss.org/docs/DOC-16217> to return binary content.

JAX-RS does support query using URL like 
http://host:portnumber/drools-guvnor/rest/packages/mortgage/assets 
<http://community.jboss.org/docs/DOC-16217>?category=foo&category=bar&status=prod 
(and several other query mechanisms). But we have not implemented query 
in Guvnor yet. Of course you will be very welcome if you want to help ;-)

For more information about Guvnor REST interface please check: 
http://blog.athico.com/2011/03/atompub-interface-for-guvnor.html and 
http://community.jboss.org/wiki/AtomPubinterfaceforGuvnor

Cheers,
Jervis

> Otherwise I think I di have to write my own servlet doing that (like Michael suggests), or find another solution.
>
>
>
> ----- Mail original -----
> De: "Jervis Liu"<jliu at redhat.com>
> À: rules-users at lists.jboss.org
> Envoyé: Jeudi 5 Mai 2011 04:48:45
> Objet: Re: [rules-users] Guvnor service to compile part of a package ?
>
> On 2011/5/4 22:57, Vincent Legendre wrote:
>> Hi all,
>>
>> I am looking for a clever way to compile only parts of a Guvnor package
>> according to some criteria on items (categories, metadata ...), but
>> outside Guvnor if possible.
>> The main idea starts by the fact that it is a little bit complex for a
>> business user to manage packages and compilations, and even more if he
>> has to manage conditional compilations (using selectors) of a single
>> package to produce multiple KB compiled according to business criterions.
>>
>> I want to compile automatically some KB according to categories (more
>> generally asset's fields) with something external to Guvnor. Thus I need
>> a way to query Guvnor repository with criterion to get either :
>>        - the corresponding ressources (DRL)
>>        - the filtered compiled KB (PKG ressource)
>> Filtering with DRL (like custom selectors in Guvnor) will be perfect,
>> using a custom class too.
>>
>> Is there such service ?
>> Does the KnowledgeAgent allow filtering (did not see anything in docs) ?
> Not sure about KnowledgeAgent, I ll leave this question to someone more
> familiar with KnowledgeAgent. At the same time, you can probably use
> Guvnor REST service to achieve same goal. Check this example:
> http://community.jboss.org/wiki/PublishDroolsartifactsfromaproductionenvironment.
> This example polls package feed periodically to check if there is a new
> version of package available. If there is a new version created, it will
> download the package compiled binary. Package binary is compiled against
> selectors, so it is filtered as you need.
>
> Cheers,
> Jervis
>
>
>
>
>
>> Or do I need to add a new service in Guvnor war directly ?
>>
>> Thanks!
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20110506/f28752fb/attachment.html 


More information about the rules-users mailing list