Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JBPM-9464] Kie server notification causes bad status in BC #2327

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ public class KieServerConstants {
public static final String KIE_SERVER_IMAGESERVICE_MAX_NODES = "org.kie.server.service.image.max_nodes";
public static final String KIE_SERVER_REST_MODE_READONLY = "org.kie.server.rest.mode.readonly";
public static final String KIE_SERVER_NOTIFY_UPDATES_TO_CONTROLLERS = "org.kie.server.update.notifications.rest.enabled";
public static final String KIE_SERVER_NOTIFY_UPDATES_TO_CONTROLLERS_DELAY = "org.kie.server.update.notifications.delay";

// configuration parameters
public static final String CFG_PERSISTANCE_DS = "org.kie.server.persistence.ds";
public static final String CFG_PERSISTANCE_TM = "org.kie.server.persistence.tm";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public Container( final String containerSpecId,
this.serverInstanceId = serverInstanceKey.getServerInstanceId();
this.messages.addAll( messages );
this.resolvedReleasedId = resolvedReleasedId;

setUrl(url);
}

public String getServerInstanceId() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@

import org.kie.server.api.KieServerConstants;
import org.kie.server.api.model.KieContainerResource;
import org.kie.server.api.model.KieContainerStatus;
import org.kie.server.api.model.KieScannerResource;
import org.kie.server.api.model.KieServerConfig;
import org.kie.server.api.model.KieServerConfigItem;
Expand Down Expand Up @@ -165,11 +164,7 @@ public KieServerSetup update(KieServerStateInfo kieServerStateInfo) {

// we update the server instance with the containers
List<Container> containerList = new ArrayList<Container>();
List<KieContainerStatus> invalidStatus = Collections.singletonList(KieContainerStatus.STOPPED);
for(ContainerSpec containerSpec : serverTemplate.getContainersSpec()) {
if(invalidStatus.contains(containerSpec.getStatus())) {
continue;
}
Container container = new Container(containerSpec.getId(),
containerSpec.getContainerName(),
serverInstanceKey,
Expand All @@ -189,7 +184,6 @@ public KieServerSetup update(KieServerStateInfo kieServerStateInfo) {

// we update and notify
notificationService.notify(new ServerInstanceUpdated(serverInstance));
notificationService.notify(new ServerTemplateUpdated(serverTemplate));
elguardian marked this conversation as resolved.
Show resolved Hide resolved

for(ContainerSpec currentSpec : serverTemplate.getContainersSpec()) {
List<Container> specContainerList = new ArrayList<Container>();
Expand All @@ -206,7 +200,6 @@ public KieServerSetup update(KieServerStateInfo kieServerStateInfo) {
notificationService.notify(serverTemplate, currentSpec, specContainerList);
}


return toKieServerSetup(serverTemplate);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@
package org.kie.server.controller.impl;

import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.ServiceLoader;

import org.kie.server.api.KieServerConstants;
import org.kie.server.api.model.KieContainerResource;
import org.kie.server.api.model.KieContainerResourceList;
import org.kie.server.api.model.KieContainerStatus;
import org.kie.server.api.model.KieScannerResource;
import org.kie.server.api.model.KieScannerStatus;
import org.kie.server.api.model.KieServerConfigItem;
Expand Down Expand Up @@ -61,6 +63,10 @@ public static KieServerInstanceManager getInstance() {
return INSTANCE;
}

public boolean isAsync() {
return false;
}

public List<Container> startScanner(ServerTemplate serverTemplate,
final ContainerSpec containerSpec,
final long interval) {
Expand Down Expand Up @@ -551,6 +557,7 @@ protected void collectContainerInfo(ContainerSpec containerSpec,
container.setResolvedReleasedId(containerResource.getResolvedReleaseId() == null ? containerResource.getReleaseId() : containerResource.getResolvedReleaseId());
container.setMessages(containerResource.getMessages());
container.setStatus(containerResource.getStatus());
container.setContainerName(containerResource.getContainerAlias());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,14 @@ public synchronized void saveContainerSpec(String serverTemplateId,

templateStorage.update(serverTemplate);


notificationService.notify(new ServerTemplateUpdated(serverTemplate));

if (containerSpec.getStatus().equals(KieContainerStatus.STARTED)) {
List<Container> containers = kieServerInstanceManager.startContainer(serverTemplate, containerSpec);
notificationService.notify(serverTemplate, containerSpec, containers);
if(!kieServerInstanceManager.isAsync()) {
notificationService.notify(serverTemplate, containerSpec, containers);
}
}
}

Expand Down Expand Up @@ -130,7 +133,9 @@ public synchronized void updateContainerSpec(String serverTemplateId, String con
// in case container was started before it was update or update comes with status started update container in running servers
if (currentVersion.getStatus().equals(KieContainerStatus.STARTED) || containerSpec.getStatus().equals(KieContainerStatus.STARTED)) {
List<Container> containers = kieServerInstanceManager.upgradeAndStartContainer(serverTemplate, containerSpec, resetBeforeUpdate);
notificationService.notify(serverTemplate, containerSpec, containers);
if(!kieServerInstanceManager.isAsync()) {
notificationService.notify(serverTemplate, containerSpec, containers);
}
}
}

Expand All @@ -150,7 +155,9 @@ public synchronized void saveServerTemplate(ServerTemplate serverTemplate) {
for (ContainerSpec containerSpec : containerSpecs) {
if (containerSpec.getStatus().equals(KieContainerStatus.STARTED)) {
List<Container> containers = kieServerInstanceManager.startContainer(serverTemplate, containerSpec);
notificationService.notify(serverTemplate, containerSpec, containers);
if(!kieServerInstanceManager.isAsync()) {
notificationService.notify(serverTemplate, containerSpec, containers);
}
}
}
}
Expand Down Expand Up @@ -414,7 +421,9 @@ public synchronized void startContainer(ContainerSpecKey containerSpecKey) {

List<Container> containers = kieServerInstanceManager.startContainer(serverTemplate, containerSpec);

notificationService.notify(serverTemplate, containerSpec, containers);
if(!kieServerInstanceManager.isAsync()) {
notificationService.notify(serverTemplate, containerSpec, containers);
}
}

@Override
Expand All @@ -435,7 +444,9 @@ public synchronized void stopContainer(ContainerSpecKey containerSpecKey) {

List<Container> containers = kieServerInstanceManager.stopContainer(serverTemplate, containerSpec);

notificationService.notify(serverTemplate, containerSpec, containers);
if(!kieServerInstanceManager.isAsync()) {
notificationService.notify(serverTemplate, containerSpec, containers);
}
}

@Override
Expand All @@ -460,7 +471,9 @@ public synchronized void activateContainer(ContainerSpecKey containerSpecKey) {

List<Container> containers = kieServerInstanceManager.activateContainer(serverTemplate, containerSpec);

notificationService.notify(serverTemplate, containerSpec, containers);
if(!kieServerInstanceManager.isAsync()) {
notificationService.notify(serverTemplate, containerSpec, containers);
}
}

@Override
Expand All @@ -485,7 +498,9 @@ public synchronized void deactivateContainer(ContainerSpecKey containerSpecKey)

List<Container> containers = kieServerInstanceManager.deactivateContainer(serverTemplate, containerSpec);

notificationService.notify(serverTemplate, containerSpec, containers);
if(!kieServerInstanceManager.isAsync()) {
notificationService.notify(serverTemplate, containerSpec, containers);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void testGetContainers() {

@Test
public void testGetContainersRemoteOperationWhenResponseTypeIsSUCCESS() {

doReturn(KieContainerStatus.STARTED).when(container).getStatus();
doReturn(containerResource).when(response).getResult();
doReturn(response).when(client).getContainerInfo(any());
doReturn(ServiceResponse.ResponseType.SUCCESS).when(response).getType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public ServiceResponse<KieContainerResource> createContainer(String containerId,
currentState.getContainers().add(container);
});
eventSupport.fireAfterContainerStarted(this, ci);
getDefaultController().update(getInternalServerState());
notifyStatusToControllers();
return new ServiceResponse<KieContainerResource>(ServiceResponse.ResponseType.SUCCESS, "Container " + containerId + " successfully deployed with module " + releaseId + ".", ci.getResource());
} else {
ci.getResource().setStatus(KieContainerStatus.FAILED);
Expand Down Expand Up @@ -432,7 +432,7 @@ public ServiceResponse<KieContainerResource> activateContainer(String containerI
});

eventSupport.fireAfterContainerActivated(this, kci);
getDefaultController().update(getInternalServerState());
notifyStatusToControllers();
messages.add(new Message(Severity.INFO, "Container " + containerId + " activated successfully."));
return new ServiceResponse<KieContainerResource>(ServiceResponse.ResponseType.SUCCESS, "Container " + containerId + " activated successfully.", kci.getResource());
}
Expand Down Expand Up @@ -481,7 +481,7 @@ public ServiceResponse<KieContainerResource> deactivateContainer(String containe
});

eventSupport.fireAfterContainerDeactivated(this, kci);
getDefaultController().update(getInternalServerState());
notifyStatusToControllers();
messages.add(new Message(Severity.INFO, "Container " + containerId + " deactivated successfully."));
return new ServiceResponse<KieContainerResource>(ServiceResponse.ResponseType.SUCCESS, "Container " + containerId + " deactivated successfully.", kci.getResource());
}
Expand Down Expand Up @@ -614,7 +614,7 @@ public ServiceResponse<Void> disposeContainer(String containerId) {
messages.add(new Message(Severity.INFO, "Container " + containerId + " successfully stopped."));

eventSupport.fireAfterContainerStopped(this, kci);
getDefaultController().update(getInternalServerState());
notifyStatusToControllers();
return new ServiceResponse<Void>(ServiceResponse.ResponseType.SUCCESS, "Container " + containerId + " successfully disposed.");
} else {
messages.add(new Message(Severity.INFO, "Container " + containerId + " was not instantiated."));
Expand Down Expand Up @@ -678,7 +678,7 @@ public ServiceResponse<KieScannerResource> updateScanner(String id, KieScannerRe
}
});
});
getDefaultController().update(getInternalServerState());
notifyStatusToControllers();
return scannerResponse;
}
} else {
Expand Down Expand Up @@ -955,7 +955,7 @@ public ServiceResponse<ReleaseId> updateContainerReleaseId(String containerId, R

logger.info("Container {} successfully updated to release id {}", containerId, releaseId);
ks.getRepository().removeKieModule(originalReleaseId);
getDefaultController().update(getInternalServerState());
notifyStatusToControllers();
messages.add(new Message(Severity.INFO, "Release id successfully updated for container " + containerId));
return new ServiceResponse<ReleaseId>(ServiceResponse.ResponseType.SUCCESS, "Release id successfully updated.", kci.getResource().getReleaseId());
} else {
Expand Down Expand Up @@ -1108,6 +1108,17 @@ protected KieServerController getController() {
return controller;
}

protected void notifyStatusToControllers() {
new Thread(() -> {
try {
Thread.sleep(Long.getLong(KieServerConstants.KIE_SERVER_NOTIFY_UPDATES_TO_CONTROLLERS_DELAY, 1000L));
getDefaultController().update(getInternalServerState());
} catch (InterruptedException e) {
// do nothing
}
}).start();
}

protected KieServerController getDefaultController() {
return new DefaultRestControllerImpl(context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,21 @@ public KieServerSetup connect(KieServerInfo serverInfo) {

KieServerConfig config = currentState.getConfiguration();
if (controllers != null && !controllers.isEmpty()) {
KieServerSetup kieServerSetup = null;
for (String controllerUrl : controllers) {

if (controllerUrl != null && !controllerUrl.isEmpty()) {
KieServerSetup kieServerSetup = connectToSingleController(serverInfo, config, controllerUrl);
if (kieServerSetup != null && kieServerSetup.hasNoErrors()) {
return kieServerSetup;
KieServerSetup kieServerSetupController = connectToSingleController(serverInfo, config, controllerUrl);
elguardian marked this conversation as resolved.
Show resolved Hide resolved
if (kieServerSetup == null && kieServerSetupController != null && kieServerSetupController.hasNoErrors()) {
kieServerSetup = kieServerSetupController;
}
}
}

if (kieServerSetup != null) {
return kieServerSetup;
}

throw new KieControllerNotConnectedException("Unable to connect to any controller");
} else {
throw new KieControllerNotDefinedException("Unable to connect to any controller");
Expand All @@ -170,13 +175,8 @@ public void disconnect(KieServerInfo serverInfo) {
KieServerConfig config = currentState.getConfiguration();

for (String controllerUrl : controllers ) {

if (controllerUrl != null && !controllerUrl.isEmpty()) {

boolean disconnected = disconnectFromSingleController(serverInfo, config, controllerUrl);
if (disconnected) {
break;
}
disconnectFromSingleController(serverInfo, config, controllerUrl);
}
}
}
Expand Down Expand Up @@ -212,9 +212,7 @@ public KieServerSetup update(KieServerStateInfo serverTemplateUpdate) {
}
}

} else {
logger.warn("No controllers found to update to new status {}", serverTemplateUpdate);
elguardian marked this conversation as resolved.
Show resolved Hide resolved
}
}
// we return one of them coming fron the controller
return kieServerSetup;
}
Expand Down