use of org.kie.server.services.api.KieServerExtension in project droolsjbpm-integration by kiegroup.
the class AbstractKieServerImplTest method testHealthCheckFailedExtension.
@Test
public void testHealthCheckFailedExtension() {
extensions.add(new KieServerExtension() {
@Override
public List<Message> healthCheck(boolean report) {
List<Message> messages = KieServerExtension.super.healthCheck(report);
messages.add(new Message(Severity.ERROR, "TEST extension is unhealthy"));
return messages;
}
@Override
public void updateContainer(String id, KieContainerInstance kieContainerInstance, Map<String, Object> parameters) {
}
@Override
public boolean isUpdateContainerAllowed(String id, KieContainerInstance kieContainerInstance, Map<String, Object> parameters) {
return false;
}
@Override
public boolean isInitialized() {
return true;
}
@Override
public boolean isActive() {
return true;
}
@Override
public void init(KieServerImpl kieServer, KieServerRegistry registry) {
}
@Override
public Integer getStartOrder() {
return 10;
}
@Override
public List<Object> getServices() {
return null;
}
@Override
public String getImplementedCapability() {
return "TEST";
}
@Override
public String getExtensionName() {
return "TEST";
}
@Override
public <T> T getAppComponents(Class<T> serviceType) {
return null;
}
@Override
public List<Object> getAppComponents(SupportedTransports type) {
return null;
}
@Override
public void disposeContainer(String id, KieContainerInstance kieContainerInstance, Map<String, Object> parameters) {
}
@Override
public void destroy(KieServerImpl kieServer, KieServerRegistry registry) {
}
@Override
public void createContainer(String id, KieContainerInstance kieContainerInstance, Map<String, Object> parameters) {
}
});
kieServer.init();
List<Message> healthMessages = kieServer.healthCheck(false);
assertEquals(healthMessages.size(), 1);
Message failedContainer = healthMessages.get(0);
assertEquals(Severity.ERROR, failedContainer.getSeverity());
assertEquals(1, failedContainer.getMessages().size());
assertEquals("TEST extension is unhealthy", failedContainer.getMessages().iterator().next());
}
use of org.kie.server.services.api.KieServerExtension in project droolsjbpm-integration by kiegroup.
the class AbstractKieServerImplTest method testUpdateContainerWithExtensionNotAllowing.
@Test
public void testUpdateContainerWithExtensionNotAllowing() {
KieServerExtension extension = mock(KieServerExtension.class);
when(extension.isUpdateContainerAllowed(any(), any(), any())).thenReturn(false);
extensions.add(extension);
String containerId = "container-to-update";
startContainerToUpdate(containerId, getVersion(mode));
ServiceResponse<ReleaseId> updateResponse = kieServer.updateContainerReleaseId(containerId, new ReleaseId(this.releaseId), true);
Assertions.assertThat(updateResponse.getType()).isEqualTo(ServiceResponse.ResponseType.FAILURE);
verify(extension).isUpdateContainerAllowed(anyString(), any(), any());
verify(extension, never()).updateContainer(any(), any(), any());
kieServer.disposeContainer(containerId);
}
use of org.kie.server.services.api.KieServerExtension in project droolsjbpm-integration by kiegroup.
the class AbstractKieServerImplTest method testUpdateContainer.
@Test
public void testUpdateContainer() {
KieServerExtension extension = mock(KieServerExtension.class);
when(extension.isUpdateContainerAllowed(any(), any(), any())).thenReturn(true);
extensions.add(extension);
String containerId = "container-to-update";
startContainerToUpdate(containerId, getVersion(mode));
ServiceResponse<ReleaseId> updateResponse = kieServer.updateContainerReleaseId(containerId, new ReleaseId(releaseId), true);
Assertions.assertThat(updateResponse.getType()).isEqualTo(ServiceResponse.ResponseType.SUCCESS);
verify(extension).isUpdateContainerAllowed(anyString(), any(), any());
verify(extension).updateContainer(any(), any(), any());
kieServer.disposeContainer(containerId);
}
use of org.kie.server.services.api.KieServerExtension in project droolsjbpm-integration by kiegroup.
the class KieServerImplDevelopmentModeTest method testUpdateContainer.
private void testUpdateContainer(String version) {
KieServerExtension extension = mock(KieServerExtension.class);
when(extension.isUpdateContainerAllowed(any(), any(), any())).thenReturn(true);
extensions.add(extension);
String containerId = "container-to-update";
startContainerToUpdate(containerId, version);
ReleaseId updateReleaseId = new ReleaseId(GROUP_ID, containerId, version);
ServiceResponse<ReleaseId> updateResponse = kieServer.updateContainerReleaseId(containerId, updateReleaseId, true);
Assertions.assertThat(updateResponse.getType()).isEqualTo(ServiceResponse.ResponseType.SUCCESS);
verify(extension).isUpdateContainerAllowed(anyString(), any(), any());
verify(extension).prepareContainerUpdate(anyString(), any(), any());
verify(extension).updateContainer(any(), any(), any());
kieServer.disposeContainer(containerId);
}
use of org.kie.server.services.api.KieServerExtension in project droolsjbpm-integration by kiegroup.
the class KieServerImpl method disposeContainer.
public ServiceResponse<Void> disposeContainer(String containerId, Boolean abortInstances) {
List<Message> messages = new CopyOnWriteArrayList<Message>();
try {
KieContainerInstanceImpl kci = context.unregisterContainer(containerId);
if (kci != null) {
synchronized (kci) {
eventSupport.fireBeforeContainerStopped(this, kci);
// just in case
kci.setStatus(KieContainerStatus.DISPOSING);
if (kci.getKieContainer() != null) {
org.kie.api.builder.ReleaseId releaseId = kci.getKieContainer().getReleaseId();
List<KieServerExtension> disposedExtensions = new ArrayList<KieServerExtension>();
try {
// first attempt to dispose container on all extensions
logger.debug("Container {} (for release id {}) shutdown: In Progress", containerId, kci.getResource().getReleaseId());
// process server extensions
List<KieServerExtension> extensions = context.getServerExtensions();
for (KieServerExtension extension : extensions) {
extension.disposeContainer(containerId, kci, singletonMap(KieServerConstants.IS_DISPOSE_CONTAINER_PARAM, abortInstances));
logger.debug("Container {} (for release id {}) {} shutdown: DONE", containerId, kci.getResource().getReleaseId(), extension);
disposedExtensions.add(extension);
}
} catch (Exception e) {
logger.warn("Dispose of container {} failed, putting it back to started state by recreating container on {}", containerId, disposedExtensions);
// since the dispose fail rollback must take place to put it back to running state
KieModuleMetaData metadata = buildKieModuleMetadata(kci.getKieContainer().getReleaseId());
Map<String, Object> parameters = getContainerParameters(metadata, messages);
for (KieServerExtension extension : disposedExtensions) {
extension.createContainer(containerId, kci, parameters);
logger.debug("Container {} (for release id {}) {} restart: DONE", containerId, kci.getResource().getReleaseId(), extension);
}
kci.setStatus(KieContainerStatus.STARTED);
context.registerContainer(containerId, kci);
logger.info("Container {} (for release id {}) STARTED after failed dispose", containerId, kci.getResource().getReleaseId());
messages.add(new Message(Severity.WARN, "Error disposing container '" + containerId + "' due to " + e.getMessage() + ", container is running"));
return new ServiceResponse<Void>(ResponseType.FAILURE, "Container " + containerId + " failed to dispose, exception was raised: " + e.getClass().getName() + ": " + e.getMessage());
}
if (kci.getScanner() != null && kci.getScanner().getStatus() != Status.SHUTDOWN) {
kci.stopScanner();
}
InternalKieContainer kieContainer = kci.getKieContainer();
// helps reduce concurrent access issues
kci.setKieContainer(null);
kci.disposeMarshallers();
// this may fail, but we already removed the container from the registry
kieContainer.dispose();
ks.getRepository().removeKieModule(releaseId);
logger.info("Container {} (for release id {}) successfully stopped", containerId, kci.getResource().getReleaseId());
// store the current state of the server
storeServerState(currentState -> {
List<KieContainerResource> containers = new ArrayList<>();
currentState.getContainers().forEach(containerResource -> {
if (!containerId.equals(containerResource.getContainerId())) {
containers.add(containerResource);
}
});
currentState.setContainers(new HashSet<KieContainerResource>(containers));
});
messages.add(new Message(Severity.INFO, "Container " + containerId + " successfully stopped."));
eventSupport.fireAfterContainerStopped(this, kci);
notifyStatusToControllers();
return new ServiceResponse<Void>(ServiceResponse.ResponseType.SUCCESS, "Container " + containerId + " successfully disposed.");
} else {
messages.add(new Message(Severity.INFO, "Container " + containerId + " was not instantiated."));
return new ServiceResponse<Void>(ServiceResponse.ResponseType.SUCCESS, "Container " + containerId + " was not instantiated.");
}
}
} else {
messages.add(new Message(Severity.INFO, "Container " + containerId + " was not instantiated."));
return new ServiceResponse<Void>(ServiceResponse.ResponseType.SUCCESS, "Container " + containerId + " was not instantiated.");
}
} catch (Exception e) {
messages.add(new Message(Severity.ERROR, "Error disposing container '" + containerId + "' due to " + e.getMessage()));
logger.error("Error disposing Container '" + containerId + "'", e);
return new ServiceResponse<Void>(ServiceResponse.ResponseType.FAILURE, "Error disposing container " + containerId + ": " + e.getClass().getName() + ": " + e.getMessage());
} finally {
this.containerMessages.put(containerId, messages);
}
}
Aggregations