PINTER
PINTER

Reputation: 1

KieScanner cannot fetch LATEST version automatically!

I want to integrate the drools workbench 6.4.0.Final with my own application.

This below is the main class:

package com.example;
import com.idss.poc.CouponFact;
import com.idss.poc.Result;
import org.codehaus.plexus.util.FileUtils;
import org.drools.compiler.kie.builder.impl.KieServicesImpl;
import org.drools.compiler.kproject.ReleaseIdImpl;
import org.drools.core.io.impl.UrlResource;
import org.kie.api.KieServices;
import org.kie.api.builder.KieModule;
import org.kie.api.builder.KieRepository;
import org.kie.api.builder.KieScanner;
import org.kie.api.builder.ReleaseId;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.StatelessKieSession;
import org.kie.scanner.KieScannerFactoryServiceImpl;

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class FunctionExample {
    public static void main(String[] args) {
        KieServices ks = KieServices.Factory.get();
        ReleaseId releaseId = ks.newReleaseId( "com.test", "poc", "LATEST" );

        KieContainer kContainer = ks.newKieContainer(releaseId);
        KieScanner kieScanner = ks.newKieScanner(kContainer);

        kieScanner.start( 10000L );

        Scanner scanner = new Scanner(System.in);

        while (true) {
            kieScanner.scanNow();
            String line = scanner.nextLine();
            runRule(kContainer);
        }
    }

    private static void runRule(KieContainer kieKontainer) {
        StatelessKieSession kSession =kieKontainer.newStatelessKieSession("ks");
        Result result = new Result();
        List<String> list = new ArrayList<String>();
        result.setRules(list);

        kSession.setGlobal("result", result);

        CouponFact cf = new CouponFact();
        cf.setPhoneCount(2);
        cf.setUserCount(2);
        cf.setDeviceCount(2);
        cf.setIp10mCount(10);
        cf.setIpDayCount(10);
        kSession.execute(cf);

        System.out.println(result.getScore() + "," + result.getRules());
    }
}

This below is my settings.xml used by own application.

<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" 
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
  <localRepository>~/.m2/repository</localRepository>
  <pluginGroups>
  </pluginGroups>
  <proxies>
  </proxies>
  <servers>
    <server>
      <id>guvnor-m2-repo</id>
      <username>workbench</username>
      <password>workbench!</password>
      <configuration>
        <wagonProvider>httpclient</wagonProvider>
        <httpConfiguration>
          <all>
            <usePreemptive>true</usePreemptive>
          </all>
        </httpConfiguration>
      </configuration>
    </server>
    <server>
      <id>mymirror</id>
      <username>workbench</username>
      <password>workbench!</password>
      <configuration>
        <wagonProvider>httpclient</wagonProvider>
        <httpConfiguration>
          <all>
            <usePreemptive>true</usePreemptive>
          </all>
        </httpConfiguration>
      </configuration>
    </server>
  </servers>
  <mirrors>
    <mirror>
      <id>mymirror</id>
      <url>http://10.10.10.57:8080/kie-wb/maven2</url>
      <mirrorOf>*</mirrorOf>
      <layout>default</layout>
    </mirror>
  </mirrors>
  <profiles>
    <profile>
      <id>guvnor-m2-repo</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <repositories>
        <repository>
            <id>guvnor-m2-repo</id>
            <name>Guvnor M2 Repo</name>
            <url>http://10.10.10.57:8080/kie-wb/maven2</url>
            <releases>
              <enabled>true</enabled>
            </releases>
            <updatePolicy>always</updatePolicy>
        </repository>
      </repositories>
    </profile>
  </profiles>
  <activeProfiles>
   <activeProfile>guvnor-m2-repo</activeProfile>
  </activeProfiles>
</settings>

When I update my drools rule in workbench, and upgrade the version of my repo, but my application do not get the LATEST version of my repo automatically. I get the log like this:

11:50:24.158 [Timer-0] DEBUG org.kie.scanner.embedder.MavenEmbedderUtils - Not in OSGi: using plexus based maven parser
11:50:24.212 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for /Users/pinter/Desktop/RiskGuard/~/.m2/repository
11:50:24.212 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for /Users/pinter/Desktop/RiskGuard/~/.m2/repository
11:50:24.213 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultRemoteRepositoryManager - Using mirror mymirror (http://10.10.10.57:8080/kie-wb/maven2) for guvnor-m2-repo (http://10.10.10.57:8080/kie-wb/maven2).
11:50:24.215 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultRemoteRepositoryManager - Using mirror mymirror (http://10.10.10.57:8080/kie-wb/maven2) for guvnor-m2-repo (http://10.10.10.57:8080/kie-wb/maven2).
11:50:24.215 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultRemoteRepositoryManager - Using mirror mymirror (http://10.10.10.57:8080/kie-wb/maven2) for central (https://repo.maven.apache.org/maven2).
11:50:24.216 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultDependencyCollector - Dependency collection stats: {ConflictMarker.analyzeTime=0, ConflictMarker.markTime=0, ConflictMarker.nodeCount=1, ConflictIdSorter.graphTime=0, ConflictIdSorter.topsortTime=0, ConflictIdSorter.conflictIdCount=0, ConflictIdSorter.conflictIdCycleCount=0, ConflictResolver.totalTime=0, ConflictResolver.conflictItemCount=0, DefaultDependencyCollector.collectTime=0, DefaultDependencyCollector.transformTime=0}
11:50:24.217 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for ~/.m2/repository
11:50:24.217 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultUpdateCheckManager - Skipped remote request for com.idss:poc/maven-metadata.xml, locally cached metadata up-to-date.

Can anyone help me to figure it out? Thank you!

Upvotes: 0

Views: 1939

Answers (3)

PINTER
PINTER

Reputation: 1

Thanks to @tarilabs and @Naved Alam, yours answer just help me. I read the drools document, it tells me:

The KieScanner will only pickup changes to deployed jars if it is using a SNAPSHOT, version range, the LATEST, or the RELEASE setting. Fixed versions will not automatically update at runtime.

So,I modified my workbench project, and set the version number to 2.0.0-SNAPSHOT, and change my code

ReleaseId releaseId = ks.newReleaseId( "com.test", "poc", "LATEST" );

to

ReleaseId releaseId = ks.newReleaseId( "com.test", "poc", "2.0.0-SNAPSHOT" );

As so far, it doesn't work fine again. The program show the log like this:

11:50:24.158 [Timer-0] DEBUG org.kie.scanner.embedder.MavenEmbedderUtils - Not in OSGi: using plexus based maven parser
11:50:24.212 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for /Users/pinter/Desktop/RiskGuard/~/.m2/repository
11:50:24.212 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for /Users/pinter/Desktop/RiskGuard/~/.m2/repository
11:50:24.213 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultRemoteRepositoryManager - Using mirror mymirror (http://10.10.10.57:8080/kie-wb/maven2) for guvnor-m2-repo (http://10.10.10.57:8080/kie-wb/maven2).
11:50:24.215 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultRemoteRepositoryManager - Using mirror mymirror (http://10.10.10.57:8080/kie-wb/maven2) for guvnor-m2-repo (http://10.10.10.57:8080/kie-wb/maven2).
11:50:24.215 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultRemoteRepositoryManager - Using mirror mymirror (http://10.10.10.57:8080/kie-wb/maven2) for central (https://repo.maven.apache.org/maven2).
11:50:24.216 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultDependencyCollector - Dependency collection stats: {ConflictMarker.analyzeTime=0, ConflictMarker.markTime=0, ConflictMarker.nodeCount=1, ConflictIdSorter.graphTime=0, ConflictIdSorter.topsortTime=0, ConflictIdSorter.conflictIdCount=0, ConflictIdSorter.conflictIdCycleCount=0, ConflictResolver.totalTime=0, ConflictResolver.conflictItemCount=0, DefaultDependencyCollector.collectTime=0, DefaultDependencyCollector.transformTime=0}
11:50:24.217 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultLocalRepositoryProvider - Using manager EnhancedLocalRepositoryManager with priority 10.0 for ~/.m2/repository
11:50:24.217 [Timer-0] DEBUG org.eclipse.aether.internal.impl.DefaultUpdateCheckManager - Skipped remote request for com.idss:poc/maven-metadata.xml, locally cached metadata up-to-date.

As we see, the central repository https://repo.maven.apache.org/maven2 has override by my custom remote repository http://10.10.10.57:8080/kie-wb/maven2.

I try to change my settings.xml,

<mirrors>
    <mirror>
      <id>mymirror</id>
      <url>http://10.10.10.57:8080/kie-wb/maven2</url>
      <mirrorOf>*</mirrorOf>
      <layout>default</layout>
    </mirror>
</mirrors>

to

<mirrors>
    <mirror>
      <id>mymirror</id>
      <url>http://10.10.10.57:8080/kie-wb/maven2</url>
      <mirrorOf>guvnor-m2-repo</mirrorOf>
      <layout>default</layout>
    </mirror>
</mirrors>

It just working fine!!!

Upvotes: 0

Naved Alam
Naved Alam

Reputation: 827

If you are using LATEST in version number field in your application, KieScanner try to match the version number of the jar available in the local repository with version number of jar available at kie-workbench. If both the version are same, it doesn't fetch the jar from remote repository and uses the jar from local repository. Each time you 'build and deploy', do increment your version number for the changes to get reflected on your application side.

If incrementing the version number each time you deploy is too much of work for you, I would suggest using the -SNAPSHOT in your version number. The snapshot version are always fetched from the remote repository even if the same version is available in local repo. <version>-SNAPSHOT should be used for development purpose only.

Upvotes: 1

tarilabs
tarilabs

Reputation: 2398

I assume you put "LATEST" in order to fetch the latest snapshot version of your KJAR.

If that is the case, I believe you need to set the snapshot update policy to something greater than "daily" the default. Moreover you seem to have an error in your maven settings file as the updatePolicy tag is not nested correctly. I would suggest you try something like this:

  <profiles>
    <profile>
      <id>guvnor-m2-repo</id>
      <activation>
        <activeByDefault>true</activeByDefault>
      </activation>
      <repositories>
        <repository>
            <id>guvnor-m2-repo</id>
            <name>Guvnor M2 Repo</name>
            <url>http://10.10.10.57:8080/kie-wb/maven2</url>

      <releases>
        <enabled>false</enabled>
        <updatePolicy>always</updatePolicy>
      </releases>
      <snapshots>
        <enabled>true</enabled>
        <updatePolicy>always</updatePolicy>
      </snapshots>

        </repository>
      </repositories>
    </profile>
  </profiles>

Ref: https://maven.apache.org/settings.html#Repositories

Upvotes: 0

Related Questions