use of org.kie.server.services.api.KieServer in project kiegroup-examples by tkobayas.
the class MyKieServerWarmupEventListener method afterContainerStarted.
@Override
public void afterContainerStarted(KieServer kieServer, KieContainerInstance containerInstance) {
// To set the KIE_WARMUP_LISTENER_STRATEGY value, see CreateContainerWithWarmupTrue.java in Ex-kie-server-client-7.48.0.Final-redhat-00006
// If you comment-out this part, you can always trigger warm-up.
KieContainerResource resource = containerInstance.getResource();
Optional<KieServerConfigItem> optItem = resource.getConfigItems().stream().filter(item -> item.getName().equals(KIE_WARMUP_LISTENER_STRATEGY)).findFirst();
if (!optItem.isPresent()) {
LOGGER.info("{} is not enabled : ", KIE_WARMUP_LISTENER_STRATEGY);
return;
}
String strategy = optItem.get().getValue();
LOGGER.info("start warmup : " + strategy);
long start = System.currentTimeMillis();
try {
switch(strategy) {
case "internal-fire-only":
internalWarmupFireOnly(containerInstance);
break;
case "internal-full":
// in order to use internalWarmupFull, you need to edit the method to insert expected fact objects
internalWarmupFull(containerInstance);
break;
default:
break;
}
} catch (Exception e) {
LOGGER.warn("warmup failed. You can ignore the error and use the deployed container", e);
}
LOGGER.info("afterContainerStarted : elapsed time = {}ms", System.currentTimeMillis() - start);
}
use of org.kie.server.services.api.KieServer in project droolsjbpm-integration by kiegroup.
the class KeepLatestContainerOnlyPolicyTest method setUp.
@Before
public void setUp() {
kieServer = mock(KieServer.class);
when(kieServer.disposeContainer(anyString())).thenReturn(new ServiceResponse<>(ServiceResponse.ResponseType.NO_RESPONSE, "Success."));
kieContainerOne = mock(InternalKieContainer.class);
when(kieContainerOne.getReleaseId()).thenReturn(new ReleaseId("org.kie", "container", "1.0"));
when(kieContainerOne.getContainerReleaseId()).thenReturn(new ReleaseId("org.kie", "container", "1.0"));
kieContainerTwo = mock(InternalKieContainer.class);
when(kieContainerTwo.getReleaseId()).thenReturn(new ReleaseId("org.kie", "container", "2.0"));
when(kieContainerTwo.getContainerReleaseId()).thenReturn(new ReleaseId("org.kie", "container", "2.0"));
}
use of org.kie.server.services.api.KieServer in project droolsjbpm-integration by kiegroup.
the class KeepLatestContainerOnlyPolicy method apply.
@Override
public void apply(KieServerRegistry kieServerRegistry, KieServer kieServer) {
DefaultRestControllerImpl controller = new DefaultRestControllerImpl(kieServerRegistry);
List<String> containerAliases = kieServerRegistry.getContainerAliases();
if (containerAliases.isEmpty()) {
logger.debug("No containers found, quiting");
return;
}
for (String alias : containerAliases) {
List<KieContainerInstanceImpl> containerInstances = kieServerRegistry.getContainersForAlias(alias);
if (containerInstances.isEmpty() || containerInstances.size() == 1) {
logger.debug("Containers for alias {} are already on expected level (number of containers is {})", alias, containerInstances.size());
continue;
}
String latestContainerId = LatestContainerLocator.get().locateContainer(alias, containerInstances);
final Map<String, String> report = new HashMap<>();
containerInstances.stream().filter(kci -> !kci.getContainerId().equals(latestContainerId)).filter(kci -> !kci.getStatus().equals(KieContainerStatus.CREATING)).forEach(kci -> {
ServiceResponse<Void> response = kieServer.disposeContainer(kci.getContainerId());
report.put(kci.getContainerId(), response.getType().toString());
logger.debug("Dispose of container {} completed with {} message {}", kci.getContainerId(), response.getType().toString(), response.getMsg());
if (response.getType().equals(ServiceResponse.ResponseType.SUCCESS)) {
controller.stopContainer(kci.getContainerId());
}
});
logger.info("KeepLatestContainerOnlyPolicy applied to {} successfully (report {})", alias, report);
}
}
use of org.kie.server.services.api.KieServer in project droolsjbpm-integration by kiegroup.
the class KieServerRouterEventListenerRetryTest method testRouterServerStoppedRetry.
@Test(timeout = 10000)
public void testRouterServerStoppedRetry() throws Exception {
final CountDownLatch failureLatch = new CountDownLatch(1);
final CountDownLatch successLatch = new CountDownLatch(1);
int routerPort = findFreePort();
client = new KieServerRouterEventListener("test-server", "http://localhost:8080/kie-server", "http://localhost:" + routerPort, 2);
client.setObserver(new KieServerRouterEventListener.RouterConnectionObserver() {
@Override
public void onSuccess(String url) {
successLatch.countDown();
}
@Override
public void onFailure(String url) {
failureLatch.countDown();
}
});
wireMockServer = createMockServer(routerPort, "/mgmt/remove");
client.beforeServerStopped(new KieServer() {
@Override
public ServiceResponse<KieServerInfo> getInfo() {
return null;
}
@Override
public ServiceResponse<KieContainerResource> createContainer(String containerId, KieContainerResource container) {
return null;
}
@Override
public ServiceResponse<KieContainerResourceList> listContainers(KieContainerResourceFilter containerFilter) {
KieContainerResource containerResource = new KieContainerResource(containerInstance.getContainerId(), containerInstance.getResource().getReleaseId(), containerInstance.getStatus());
List<KieContainerResource> containers = new ArrayList<KieContainerResource>();
containers.add(containerResource);
KieContainerResourceList list = new KieContainerResourceList(containers);
return new ServiceResponse<KieContainerResourceList>(ServiceResponse.ResponseType.SUCCESS, "", list);
}
@Override
public ServiceResponse<KieContainerResource> getContainerInfo(String id) {
return null;
}
@Override
public ServiceResponse<Void> disposeContainer(String containerId) {
return null;
}
@Override
public ServiceResponse<KieScannerResource> getScannerInfo(String id) {
return null;
}
@Override
public ServiceResponse<KieScannerResource> updateScanner(String id, KieScannerResource resource) {
return null;
}
@Override
public ServiceResponse<ReleaseId> getContainerReleaseId(String id) {
return null;
}
@Override
public ServiceResponse<ReleaseId> updateContainerReleaseId(String id, ReleaseId releaseId) {
return null;
}
@Override
public ServiceResponse<ReleaseId> updateContainerReleaseId(String id, ReleaseId releaseId, boolean reset) {
return null;
}
@Override
public ServiceResponse<KieServerStateInfo> getServerState() {
return null;
}
@Override
public void addServerMessage(Message message) {
}
@Override
public void addContainerMessage(String containerId, Message message) {
}
});
failureLatch.await();
wireMockServer.start();
boolean met = successLatch.await(4L, TimeUnit.SECONDS);
assertFalse("On success should not be invoked", met);
wireMockServer.verify(0, postRequestedFor(urlEqualTo("/mgmt/remove")));
}
use of org.kie.server.services.api.KieServer in project kiegroup-examples by tkobayas.
the class MyKieServerWarmupEventListenerVariant method afterContainerStarted.
@Override
public void afterContainerStarted(KieServer kieServer, KieContainerInstance containerInstance) {
KieContainerResource resource = containerInstance.getResource();
Optional<KieServerConfigItem> optItem = resource.getConfigItems().stream().filter(item -> item.getName().equals(KIE_WARMUP_LISTENER_STRATEGY)).findFirst();
if (!optItem.isPresent()) {
LOGGER.info("{} is not enabled : ", KIE_WARMUP_LISTENER_STRATEGY);
return;
}
String strategy = optItem.get().getValue();
LOGGER.info("start warmup : " + strategy);
long start = System.currentTimeMillis();
switch(strategy) {
case "rest-full":
restWarmupFull(containerInstance);
break;
case "rest-fire-only":
restWarmupFireOnly(containerInstance);
break;
case "internal-full":
internalWarmupFull(containerInstance);
break;
case "internal-fire-only":
internalWarmupFireOnly(containerInstance);
break;
default:
break;
}
LOGGER.info("afterContainerStarted : elapsed time = {}ms", System.currentTimeMillis() - start);
}
Aggregations