private boolean isEmpty(final Collection<Container> containers) { for (final Container container : containers) { if (!container.getStatus().equals(KieContainerStatus.STOPPED)) { return false; } } return true; }
@Override public String locateContainer(String alias, List<? extends KieContainerInstance> containerInstances) { if (containerInstances.isEmpty()) { return alias; } logger.debug("Searching for latest container for alias {} within available containers {}", alias, containerInstances); List<ComparableVersion> comparableVersions = new ArrayList<ComparableVersion>(); Map<String, String> versionToIdentifier = new HashMap<String, String>(); containerInstances.forEach(c -> { if (c.getStatus().equals(KieContainerStatus.STARTED)) { comparableVersions.add(new ComparableVersion(c.getKieContainer().getReleaseId().getVersion())); versionToIdentifier.put(c.getKieContainer().getReleaseId().getVersion(), c.getContainerId()); } } ); ComparableVersion latest = Collections.max(comparableVersions); logger.debug("Latest version for alias {} is {}", alias, comparableVersions); return versionToIdentifier.get(latest.toString()); }
public void setup( final ContainerSpec containerSpec, final Collection<Container> containers ) { this.containerSpec = containerSpec; this.view.clear(); for ( Container container : containers ) { if ( !container.getStatus().equals( KieContainerStatus.STOPPED ) ) { buildAndIndexContainer( container ); } } }
if (container.getStatus().equals(KieContainerStatus.FAILED)) { healthMessages.add(new Message(Severity.ERROR, String.format("KIE Container '%s' is in FAILED state", container.getContainerId()) ));
@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); } }
try { KieContainerInstanceImpl kci = context.getContainer(containerId); if (kci != null && kci.getStatus().equals(KieContainerStatus.DEACTIVATED)) {
for ( final Container container : serverInstanceUpdated.getServerInstance().getContainers() ) { ContainerCardPresenter presenter = oldIndex.remove( container.getContainerSpecId() ); if ( !container.getStatus().equals( KieContainerStatus.STOPPED ) ) { if ( presenter != null ) { presenter.updateContent(serverInstanceUpdated.getServerInstance(),
try { KieContainerInstanceImpl kci = context.getContainer(containerId); if (kci != null && kci.getStatus().equals(KieContainerStatus.STARTED)) {
@Override public synchronized void saveServerTemplate(ServerTemplate serverTemplate) { if (templateStorage.exists(serverTemplate.getId())) { templateStorage.update(serverTemplate); } else { templateStorage.store(serverTemplate); } notificationService.notify(new ServerTemplateUpdated(serverTemplate)); Collection<ContainerSpec> containerSpecs = serverTemplate.getContainersSpec(); if (containerSpecs != null && !containerSpecs.isEmpty()) { for (ContainerSpec containerSpec : containerSpecs) { if (containerSpec.getStatus().equals(KieContainerStatus.STARTED)) { List<Container> containers = kieServerInstanceManager.startContainer(serverTemplate, containerSpec); notificationService.notify(serverTemplate, containerSpec, containers); } } } }
public void installContainersSync(KieServerImpl kieServer, Set<KieContainerResource> containers, KieServerState currentState, KieServerSetup kieServerSetup) { logger.info("About to install containers '{}' on kie server '{}'", containers, kieServer); if (containers == null) { kieServer.markAsReady(); return; } for (KieContainerResource containerResource : containers) { if (KieContainerStatus.STARTED.equals(containerResource.getStatus())) { kieServer.createContainer(containerResource.getContainerId(), containerResource); } else if (KieContainerStatus.DEACTIVATED.equals(containerResource.getStatus())) { kieServer.createContainer(containerResource.getContainerId(), containerResource); kieServer.deactivateContainer(containerResource.getContainerId()); containerResource.setStatus(KieContainerStatus.DEACTIVATED); } } currentState.setContainers(containers); if (kieServerSetup.getServerConfig() != null) { currentState.setConfiguration(kieServerSetup.getServerConfig()); } kieServer.getServerRegistry().getStateRepository().store(KieServerEnvironment.getServerId(), currentState); kieServer.markAsReady(); } }
@Override public synchronized void updateContainerSpec(final String serverTemplateId, final String containerId, final ContainerSpec containerSpec) { ServerTemplate serverTemplate = templateStorage.load(serverTemplateId); if (serverTemplate == null) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + serverTemplateId); } if (!containerSpec.getId().equals(containerId)) { throw new KieServerControllerException("Cannot update container " + containerSpec.getId() + " on container " + containerId); } if (!serverTemplate.hasContainerSpec(containerSpec.getId())) { throw new KieServerControllerIllegalArgumentException("Server template with id " + serverTemplateId + " has no container with id " + containerSpec.getId()); } if (!serverTemplate.hasMatchingId(containerSpec.getServerTemplateKey())) { throw new KieServerControllerException("Cannot change container template key during update."); } // make sure correct server template is set containerSpec.setServerTemplateKey(new ServerTemplateKey(serverTemplate.getId(), serverTemplate.getName())); ContainerSpec currentVersion = serverTemplate.getContainerSpec(containerSpec.getId()); serverTemplate.deleteContainerSpec(currentVersion.getId()); serverTemplate.addContainerSpec(containerSpec); templateStorage.update(serverTemplate); notificationService.notify(new ServerTemplateUpdated(serverTemplate)); // 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); notificationService.notify(serverTemplate, containerSpec, containers); } }
@Override public synchronized void saveContainerSpec(String serverTemplateId, ContainerSpec containerSpec) { ServerTemplate serverTemplate = templateStorage.load(serverTemplateId); if (serverTemplate == null) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + serverTemplateId); } if (serverTemplate.hasContainerSpec(containerSpec.getId())) { throw new KieServerControllerException("Server template with id " + serverTemplateId + " associated already with container " + containerSpec.getId()); } // make sure correct server template is set containerSpec.setServerTemplateKey(new ServerTemplateKey(serverTemplate.getId(), serverTemplate.getName())); serverTemplate.addContainerSpec(containerSpec); 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); } }
@Override public synchronized void deactivateContainer(ContainerSpecKey containerSpecKey) { ServerTemplate serverTemplate = templateStorage.load(containerSpecKey.getServerTemplateKey().getId()); if (serverTemplate == null) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + containerSpecKey.getServerTemplateKey().getId()); } ContainerSpec containerSpec = serverTemplate.getContainerSpec(containerSpecKey.getId()); if (containerSpec == null) { throw new KieServerControllerIllegalArgumentException("No container spec found for id " + containerSpecKey.getId() + " within server template with id " + serverTemplate.getId()); } if (!containerSpec.getStatus().equals(KieContainerStatus.STARTED)) { throw new KieServerControllerIllegalArgumentException("Container " + containerSpecKey.getId() + " cannot be deactivated because it's not in started state, actual state " + containerSpec.getStatus()); } containerSpec.setStatus(KieContainerStatus.DEACTIVATED); templateStorage.update(serverTemplate); List<Container> containers = kieServerInstanceManager.deactivateContainer(serverTemplate, containerSpec); notificationService.notify(serverTemplate, containerSpec, containers); }
@Override public synchronized void activateContainer(ContainerSpecKey containerSpecKey) { ServerTemplate serverTemplate = templateStorage.load(containerSpecKey.getServerTemplateKey().getId()); if (serverTemplate == null) { throw new KieServerControllerIllegalArgumentException("No server template found for id " + containerSpecKey.getServerTemplateKey().getId()); } final ContainerSpec containerSpec = serverTemplate.getContainerSpec(containerSpecKey.getId()); if (containerSpec == null) { throw new KieServerControllerIllegalArgumentException("No container spec found for id " + containerSpecKey.getId() + " within server template with id " + serverTemplate.getId()); } if (!containerSpec.getStatus().equals(KieContainerStatus.DEACTIVATED)) { throw new KieServerControllerIllegalArgumentException("Container " + containerSpecKey.getId() + " cannot be activated because it's not in deactivated state, actual state " + containerSpec.getStatus()); } containerSpec.setStatus(KieContainerStatus.STARTED); templateStorage.update(serverTemplate); List<Container> containers = kieServerInstanceManager.activateContainer(serverTemplate, containerSpec); notificationService.notify(serverTemplate, containerSpec, containers); }