use of org.kie.server.controller.api.KieServerController 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.controller.api.KieServerController 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.controller.api.KieServerController in project droolsjbpm-integration by kiegroup.
the class KieServerImplInitTest method testDefaultStartupStrategyFromController.
@Test(timeout = 10000)
public void testDefaultStartupStrategyFromController() throws Exception {
final TestContainerManager testContainerManager = new TestContainerManager();
kieServer = new KieServerImpl(new KieServerStateFileRepository(REPOSITORY_DIR)) {
@Override
protected ContainerManager getContainerManager() {
return testContainerManager;
}
@Override
public KieServerController getController() {
return new KieServerController() {
@Override
public void disconnect(KieServerInfo serverInfo) {
}
@Override
public KieServerSetup connect(KieServerInfo serverInfo) {
KieServerSetup serverSetup = new KieServerSetup();
KieContainerResource container = new KieContainerResource("test", new ReleaseId("", "", ""), KieContainerStatus.STARTED);
Set<KieContainerResource> containers = new HashSet<>();
containers.add(container);
serverSetup.setContainers(containers);
return serverSetup;
}
};
}
};
kieServer.init();
assertTrue(testContainerManager.isInstalled());
assertEquals(1, testContainerManager.getInstalledContainers().size());
}
use of org.kie.server.controller.api.KieServerController in project droolsjbpm-integration by kiegroup.
the class KieServerImplInitTest method testLOcalContainersStartupStrategyFromController.
@Test(timeout = 10000)
public void testLOcalContainersStartupStrategyFromController() throws Exception {
System.setProperty(KieServerConstants.KIE_SERVER_STARTUP_STRATEGY, LocalContainersStartupStrategy.class.getSimpleName());
StartupStrategyProvider.clear();
final TestContainerManager testContainerManager = new TestContainerManager();
kieServer = new KieServerImpl(new KieServerStateFileRepository(REPOSITORY_DIR)) {
@Override
protected ContainerManager getContainerManager() {
return testContainerManager;
}
@Override
public KieServerController getController() {
return new KieServerController() {
@Override
public void disconnect(KieServerInfo serverInfo) {
}
@Override
public KieServerSetup connect(KieServerInfo serverInfo) {
KieServerSetup serverSetup = new KieServerSetup();
KieContainerResource container = new KieContainerResource("test", new ReleaseId("", "", ""), KieContainerStatus.STARTED);
Set<KieContainerResource> containers = new HashSet<>();
containers.add(container);
serverSetup.setContainers(containers);
return serverSetup;
}
};
}
};
kieServer.init();
assertTrue(testContainerManager.isInstalled());
// even though controller returns containers they should be ignored when LocalContainersStartupStrategy is used
assertEquals(0, testContainerManager.getInstalledContainers().size());
}
use of org.kie.server.controller.api.KieServerController in project droolsjbpm-integration by kiegroup.
the class KieServerImpl method destroy.
public void destroy() {
eventSupport.fireBeforeServerStopped(this);
kieServerActive.set(false);
policyManager.stop();
// disconnect from controller
KieServerController kieController = getDefaultController();
kieController.disconnect(getInfoInternal());
for (KieServerExtension extension : context.getServerExtensions()) {
try {
extension.destroy(this, this.context);
this.context.unregisterServerExtension(extension);
logger.info("{} has been successfully unregistered as server extension", extension);
} catch (Exception e) {
logger.error("Error when destroying server extension of type {}", extension, e);
}
}
eventSupport.fireAfterServerStopped(this);
}
Aggregations