use of org.kie.server.services.impl.controller.DefaultRestControllerImpl in project droolsjbpm-integration by kiegroup.
the class KieControllerCrashIntegrationTest method testCrashAfterRegistered.
@Test
public void testCrashAfterRegistered() throws Exception {
final String SERVER_TEMPLATE_ID = "template-id";
final String SERVER_NAME = "server-name";
KieServerEnvironment.setServerId(SERVER_TEMPLATE_ID);
ServerTemplate serverTemplate = new ServerTemplate(SERVER_TEMPLATE_ID, SERVER_NAME);
controllerClient.saveServerTemplate(serverTemplate);
ServerTemplateList instanceList = controllerClient.listServerTemplates();
assertEquals(1, instanceList.getServerTemplates().length);
// Register kie server in controller.
KieServerInfo kieServerInfo = new KieServerInfo(SERVER_TEMPLATE_ID, "1.0.0");
kieServerInfo.setLocation("http://127.0.0.1:20000");
kieServerInfo.setMode(KieServerMode.PRODUCTION);
kieServerInfo.setName(SERVER_NAME);
KieServerRegistry registry = new KieServerRegistryImpl();
KieServerStateRepository dummyKieServerStateRepository = new KieServerStateRepository() {
@Override
public void store(String serverId, KieServerState kieServerState) {
}
@Override
public KieServerState load(String serverId) {
KieServerState kieServerState = new KieServerState();
kieServerState.setControllers(Collections.singleton(TestConfig.getControllerHttpUrl()));
kieServerState.setConfiguration(new KieServerConfig());
if (TestConfig.isLocalServer()) {
kieServerState.getConfiguration().addConfigItem(new KieServerConfigItem(KieServerConstants.CFG_KIE_CONTROLLER_USER, "", null));
kieServerState.getConfiguration().addConfigItem(new KieServerConfigItem(KieServerConstants.CFG_KIE_CONTROLLER_PASSWORD, "", null));
} else {
kieServerState.getConfiguration().addConfigItem(new KieServerConfigItem(KieServerConstants.CFG_KIE_CONTROLLER_USER, TestConfig.getUsername(), null));
kieServerState.getConfiguration().addConfigItem(new KieServerConfigItem(KieServerConstants.CFG_KIE_CONTROLLER_PASSWORD, TestConfig.getPassword(), null));
}
return kieServerState;
}
};
registry.registerStateRepository(dummyKieServerStateRepository);
KieServerController controller = new DefaultRestControllerImpl(registry);
controller.connect(kieServerInfo);
// Check that kie server is registered.
serverUp.await(5, TimeUnit.SECONDS);
ServerInstanceKeyList list = controllerClient.getServerInstances(instanceList.getServerTemplates()[0].getId());
if (list.getServerInstanceKeys().length == 0) {
// Race condition when health check deleted server instance sooner than we were able to check. Resubmitting server instance again.
serverUp = new CountDownLatch(1);
serverDown = new CountDownLatch(1);
controller.connect(kieServerInfo);
serverUp.await(5, TimeUnit.SECONDS);
list = controllerClient.getServerInstances(instanceList.getServerTemplates()[0].getId());
}
assertNotNull(list.getServerInstanceKeys());
assertEquals(1, list.getServerInstanceKeys().length);
// Check that kie server is deregistered automatically.
serverDown.await(5, TimeUnit.SECONDS);
list = controllerClient.getServerInstances(instanceList.getServerTemplates()[0].getId());
assertNotNull(list.getServerInstanceKeys());
assertEquals(0, list.getServerInstanceKeys().length);
}
use of org.kie.server.services.impl.controller.DefaultRestControllerImpl in project droolsjbpm-integration by kiegroup.
the class KieControllerValidationIntegrationTest method testBadRegistered.
@Test
// Added to UnstableOnJenkinsPrBuilder to avoid random failures/timeouts on Jenkins builds
@Category({ UnstableOnJenkinsPrBuilder.class })
public void testBadRegistered() throws Exception {
final String SERVER_TEMPLATE_ID = "test.mode.bad";
final String SERVER_NAME = "server-name";
KieServerEnvironment.setServerId(SERVER_TEMPLATE_ID);
ServerTemplate serverTemplate = buildServerTemplate(SERVER_TEMPLATE_ID, SERVER_NAME, null, KieServerMode.DEVELOPMENT, Collections.singletonList(Capability.PROCESS.name()));
controllerClient.saveServerTemplate(serverTemplate);
ServerTemplateList instanceList = controllerClient.listServerTemplates();
assertEquals(1, instanceList.getServerTemplates().length);
// Register kie server in controller.
KieServerInfo kieServerInfo = new KieServerInfo(SERVER_TEMPLATE_ID, "1.0.0");
kieServerInfo.setLocation("http://127.0.0.1:20000");
kieServerInfo.setMode(KieServerMode.PRODUCTION);
kieServerInfo.setName(SERVER_NAME);
KieServerController controller = new DefaultRestControllerImpl(registry);
assertThatThrownBy(() -> controller.connect(kieServerInfo)).isInstanceOf(KieControllerNotConnectedException.class);
// Check that kie server is not registered.
ServerInstanceKeyList list = controllerClient.getServerInstances(SERVER_TEMPLATE_ID);
logger.info("list {}", (Object[]) list.getServerInstanceKeys());
assertTrue(list.getServerInstanceKeys() == null || list.getServerInstanceKeys().length == 0);
// clear up
controller.disconnect(kieServerInfo);
controllerClient.deleteServerTemplate(SERVER_TEMPLATE_ID);
}
use of org.kie.server.services.impl.controller.DefaultRestControllerImpl in project droolsjbpm-integration by kiegroup.
the class AbstractKieServerImplTest method delayedKieServer.
protected KieServerImpl delayedKieServer(CountDownLatch latch, CountDownLatch startedlatch) {
KieServerImpl server = new KieServerImpl(new KieServerStateFileRepository(REPOSITORY_DIR)) {
@Override
public void markAsReady() {
super.markAsReady();
startedlatch.countDown();
}
@Override
public KieServerController getController() {
return new DefaultRestControllerImpl(getServerRegistry()) {
@Override
public KieServerSetup connect(KieServerInfo serverInfo) {
try {
if (latch.await(10, TimeUnit.MILLISECONDS)) {
return new KieServerSetup();
}
throw new KieControllerNotConnectedException("Unable to connect to any controller");
} catch (InterruptedException e) {
throw new KieControllerNotConnectedException("Unable to connect to any controller");
}
}
};
}
};
server.init();
return server;
}
use of org.kie.server.services.impl.controller.DefaultRestControllerImpl in project droolsjbpm-integration by kiegroup.
the class WebSocketKieServerControllerImpl method setRegistry.
@Override
public void setRegistry(KieServerRegistry registry) {
this.context = registry;
this.restController = new DefaultRestControllerImpl(this.context);
}
use of org.kie.server.services.impl.controller.DefaultRestControllerImpl in project droolsjbpm-integration by kiegroup.
the class KieControllerValidationIntegrationTest method testGoodRegistered.
@Test
// Added to UnstableOnJenkinsPrBuilder to avoid random failures/timeouts on Jenkins builds
@Category({ UnstableOnJenkinsPrBuilder.class })
public void testGoodRegistered() throws Exception {
final String SERVER_TEMPLATE_ID = "test.mode.ok";
final String SERVER_NAME = "server-name";
KieServerEnvironment.setServerId(SERVER_TEMPLATE_ID);
ServerTemplate serverTemplate = buildServerTemplate(SERVER_TEMPLATE_ID, SERVER_NAME, null, KieServerMode.DEVELOPMENT, Collections.singletonList(Capability.PROCESS.name()));
controllerClient.saveServerTemplate(serverTemplate);
ServerTemplateList instanceList = controllerClient.listServerTemplates();
assertEquals(1, instanceList.getServerTemplates().length);
// Register kie server in controller.
KieServerInfo kieServerInfo = new KieServerInfo(SERVER_TEMPLATE_ID, "1.0.0");
kieServerInfo.setLocation("http://127.0.0.1:20000");
kieServerInfo.setMode(KieServerMode.DEVELOPMENT);
kieServerInfo.setCapabilities(Collections.singletonList(KieServerConstants.CAPABILITY_BPM));
kieServerInfo.setName(SERVER_NAME);
KieServerRegistry registry = new KieServerRegistryImpl();
registry.registerStateRepository(dummyKieServerStateRepository);
KieServerController controller = new DefaultRestControllerImpl(registry);
KieServerSetup setup = controller.connect(kieServerInfo);
Assert.assertTrue(setup.hasNoErrors());
// Check that kie server is registered.
ServerInstanceKeyList list = controllerClient.getServerInstances(SERVER_TEMPLATE_ID);
// Sometimes the controller healthcheck deletes server instance sooner than we retrieve it back, in such case register the instance again
if (list == null || list.getServerInstanceKeys() == null || list.getServerInstanceKeys().length == 0) {
setup = controller.connect(kieServerInfo);
Assert.assertTrue(setup.hasNoErrors());
list = controllerClient.getServerInstances(SERVER_TEMPLATE_ID);
}
assertNotNull(list.getServerInstanceKeys());
assertEquals(1, list.getServerInstanceKeys().length);
// clear up
controller.disconnect(kieServerInfo);
controllerClient.deleteServerTemplate(SERVER_TEMPLATE_ID);
}
Aggregations