release version 1.10.0
This commit is contained in:
@ -0,0 +1,169 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* cluster-persistence-service
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
* rights to the Software and any copies are the property of the Copyright Holder. Unless
|
||||
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
|
||||
* Software for commercial purposes to provide services to third parties.
|
||||
*
|
||||
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
|
||||
* Under no circumstances does the Copyright Holder guarantee or promise that the
|
||||
* Software provided by him will be suitable or not suitable for the specific purposes
|
||||
* of the User, that the Software will meet all commercial and personal subjective
|
||||
* expectations of the User, that the Software will work properly, without technical
|
||||
* errors, quickly and uninterruptedly.
|
||||
*
|
||||
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
|
||||
* to the User for any direct or indirect losses of the User, his expenses or actual
|
||||
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
|
||||
* or damage to data, property, etc.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
* or implied. See the License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package ru.entaxy.esb.platform.core.cluster.persistence.handler;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.karaf.cellar.config.ClusterConfigurationEvent;
|
||||
import org.apache.karaf.cellar.config.ConfigurationEventHandler;
|
||||
import org.apache.karaf.cellar.config.ConfigurationSupport;
|
||||
import org.apache.karaf.cellar.config.Constants;
|
||||
import org.apache.karaf.cellar.core.Configurations;
|
||||
import org.apache.karaf.cellar.core.Group;
|
||||
import org.apache.karaf.cellar.core.control.BasicSwitch;
|
||||
import org.apache.karaf.cellar.core.control.Switch;
|
||||
import org.apache.karaf.cellar.core.control.SwitchStatus;
|
||||
import org.apache.karaf.cellar.core.event.EventHandler;
|
||||
import org.apache.karaf.cellar.core.event.EventType;
|
||||
import org.osgi.service.cm.Configuration;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ru.entaxy.esb.platform.core.cluster.persistence.PersistenceManager;
|
||||
|
||||
/**
|
||||
* LocalConfigurationEventHandler handles received configuration cluster event.
|
||||
*/
|
||||
public class LocalConfigurationEventHandler extends ConfigurationSupport
|
||||
implements EventHandler<ClusterConfigurationEvent> {
|
||||
|
||||
private static final transient Logger LOGGER = LoggerFactory.getLogger(LocalConfigurationEventHandler.class);
|
||||
|
||||
public static final String SWITCH_ID = "org.apache.karaf.cellar.configuration.handler";
|
||||
|
||||
private final Switch eventSwitch = new BasicSwitch(SWITCH_ID);
|
||||
|
||||
private PersistenceManager persistenceManager;
|
||||
|
||||
@Override
|
||||
public void handle(ClusterConfigurationEvent event) {
|
||||
|
||||
// check if the handler is ON
|
||||
if (this.getSwitch().getStatus().equals(SwitchStatus.OFF)) {
|
||||
LOGGER.debug("CELLAR CONFIG: {} switch is OFF, cluster event not handled", SWITCH_ID);
|
||||
return;
|
||||
}
|
||||
|
||||
if (groupManager == null) {
|
||||
// in rare cases for example right after installation this happens!
|
||||
LOGGER.error("CELLAR CONFIG: retrieved event {} while groupManager is not available yet!", event);
|
||||
return;
|
||||
}
|
||||
|
||||
// check if the group is local
|
||||
if (!groupManager.isLocalGroup(event.getSourceGroup().getName())) {
|
||||
LOGGER.debug("CELLAR CONFIG: node is not part of the event cluster group {}",
|
||||
event.getSourceGroup().getName());
|
||||
return;
|
||||
}
|
||||
|
||||
// @ENTAXY:SKIP check if it's not a "local" event
|
||||
//if (event.getLocal() != null && event.getLocal().getId().equalsIgnoreCase(clusterManager.getNode().getId())) {
|
||||
// LOGGER.trace("CELLAR CONFIG: cluster event is local (coming from local synchronizer or listener)");
|
||||
// return;
|
||||
//}
|
||||
|
||||
Group group = event.getSourceGroup();
|
||||
String groupName = group.getName();
|
||||
|
||||
Map<String, Properties> clusterConfigurations =
|
||||
clusterManager.getMap(Constants.CONFIGURATION_MAP + Configurations.SEPARATOR + groupName);
|
||||
|
||||
String pid = event.getId();
|
||||
|
||||
if (isAllowed(event.getSourceGroup(), Constants.CATEGORY, pid, EventType.INBOUND)) {
|
||||
try {
|
||||
// TODO mark cluster state as needed to be saved
|
||||
LOGGER.debug("-->> WE NEED TO SAVE CLUSTER STATE");
|
||||
this.persistenceManager.updated();
|
||||
} catch (Exception ex) {
|
||||
LOGGER.error("CELLAR CONFIG: failed to read cluster configuration", ex);
|
||||
}
|
||||
} else
|
||||
LOGGER.trace("CELLAR CONFIG: configuration PID {} is marked BLOCKED INBOUND for cluster group {}", pid,
|
||||
groupName);
|
||||
}
|
||||
|
||||
public void init() {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cluster configuration event handler switch.
|
||||
*
|
||||
* @return the cluster configuration event handler switch.
|
||||
*/
|
||||
@Override
|
||||
public Switch getSwitch() {
|
||||
// load the switch status from the config
|
||||
try {
|
||||
Configuration configuration = configurationAdmin.getConfiguration(Configurations.NODE, null);
|
||||
if (configuration != null) {
|
||||
Boolean status = new Boolean((String) configuration.getProperties()
|
||||
.get(Configurations.HANDLER + "." + ConfigurationEventHandler.class.getName()));
|
||||
if (status) {
|
||||
eventSwitch.turnOn();
|
||||
} else {
|
||||
eventSwitch.turnOff();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// nothing to do
|
||||
}
|
||||
return eventSwitch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the cluster event type.
|
||||
*
|
||||
* @return the cluster configuration event type.
|
||||
*/
|
||||
@Override
|
||||
public Class<ClusterConfigurationEvent> getType() {
|
||||
return ClusterConfigurationEvent.class;
|
||||
}
|
||||
|
||||
public void setPersistenceManager(PersistenceManager persistenceManager) {
|
||||
this.persistenceManager = persistenceManager;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,174 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* cluster-persistence-service
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
* rights to the Software and any copies are the property of the Copyright Holder. Unless
|
||||
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
|
||||
* Software for commercial purposes to provide services to third parties.
|
||||
*
|
||||
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
|
||||
* Under no circumstances does the Copyright Holder guarantee or promise that the
|
||||
* Software provided by him will be suitable or not suitable for the specific purposes
|
||||
* of the User, that the Software will meet all commercial and personal subjective
|
||||
* expectations of the User, that the Software will work properly, without technical
|
||||
* errors, quickly and uninterruptedly.
|
||||
*
|
||||
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
|
||||
* to the User for any direct or indirect losses of the User, his expenses or actual
|
||||
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
|
||||
* or damage to data, property, etc.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
* or implied. See the License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package ru.entaxy.esb.platform.core.cluster.persistence.handler;
|
||||
|
||||
import org.apache.karaf.cellar.core.Configurations;
|
||||
import org.apache.karaf.cellar.core.control.BasicSwitch;
|
||||
import org.apache.karaf.cellar.core.control.Switch;
|
||||
import org.apache.karaf.cellar.core.control.SwitchStatus;
|
||||
import org.apache.karaf.cellar.core.event.EventHandler;
|
||||
import org.apache.karaf.cellar.core.event.EventType;
|
||||
import org.apache.karaf.cellar.features.ClusterFeaturesEvent;
|
||||
import org.apache.karaf.cellar.features.Constants;
|
||||
import org.apache.karaf.cellar.features.FeatureState;
|
||||
import org.apache.karaf.cellar.features.FeaturesEventHandler;
|
||||
import org.apache.karaf.cellar.features.FeaturesSupport;
|
||||
import org.apache.karaf.cellar.features.FeaturesSynchronizer;
|
||||
import org.apache.karaf.features.FeatureEvent;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.osgi.service.cm.Configuration;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ru.entaxy.esb.platform.core.cluster.persistence.PersistenceManager;
|
||||
|
||||
/**
|
||||
* Handler for cluster features event.
|
||||
*/
|
||||
public class LocalFeaturesEventHandler extends FeaturesSupport implements EventHandler<ClusterFeaturesEvent> {
|
||||
|
||||
private static final transient Logger LOGGER = LoggerFactory.getLogger(FeaturesSynchronizer.class);
|
||||
|
||||
public static final String SWITCH_ID = "org.apache.karaf.cellar.event.features.handler";
|
||||
|
||||
private final Switch eventSwitch = new BasicSwitch(SWITCH_ID);
|
||||
|
||||
private PersistenceManager<FeatureState> persistenceManager;
|
||||
|
||||
public PersistenceManager<FeatureState> getPersistenceManager() {
|
||||
return persistenceManager;
|
||||
}
|
||||
|
||||
public void setPersistenceManager(PersistenceManager<FeatureState> persistenceManager) {
|
||||
this.persistenceManager = persistenceManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(BundleContext bundleContext) {
|
||||
super.init(bundleContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle a received cluster features event.
|
||||
*
|
||||
* @param event the received cluster feature event.
|
||||
*/
|
||||
public void handle(ClusterFeaturesEvent event) {
|
||||
|
||||
if (this.getSwitch().getStatus().equals(SwitchStatus.OFF)) {
|
||||
LOGGER.debug("CELLAR FEATURE: {} switch is OFF, cluster event is not handled", SWITCH_ID);
|
||||
return;
|
||||
}
|
||||
|
||||
if (groupManager == null) {
|
||||
// in rare cases for example right after installation this happens!
|
||||
LOGGER.error("CELLAR FEATURE: retrieved event {} while groupManager is not available yet!", event);
|
||||
return;
|
||||
}
|
||||
|
||||
// check if the group is local
|
||||
if (!groupManager.isLocalGroup(event.getSourceGroup().getName())) {
|
||||
LOGGER.debug("CELLAR FEATURE: node is not part of the event cluster group {}",
|
||||
event.getSourceGroup().getName());
|
||||
return;
|
||||
}
|
||||
|
||||
// check if it's not a "local" event
|
||||
if (event.getLocal() != null && event.getLocal().getId().equalsIgnoreCase(clusterManager.getNode().getId())) {
|
||||
LOGGER.trace("CELLAR FEATURE: cluster event is local (coming from local synchronizer or listener)");
|
||||
return;
|
||||
}
|
||||
|
||||
String name = event.getName();
|
||||
String version = event.getVersion();
|
||||
if (isAllowed(event.getSourceGroup(), Constants.CATEGORY, name, EventType.INBOUND) || event.getForce()) {
|
||||
FeatureEvent.EventType type = event.getType();
|
||||
Boolean isInstalled = isFeatureInstalledLocally(name, version);
|
||||
try {
|
||||
|
||||
persistenceManager.updated();
|
||||
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("CELLAR FEATURE: failed to handle cluster feature event", e);
|
||||
}
|
||||
} else
|
||||
LOGGER.trace("CELLAR FEATURE: feature {} is marked BLOCKED INBOUND for cluster group {}", name,
|
||||
event.getSourceGroup().getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the event type that this handler is able to handle.
|
||||
*
|
||||
* @return the cluster features event type.
|
||||
*/
|
||||
@Override
|
||||
public Class<ClusterFeaturesEvent> getType() {
|
||||
return ClusterFeaturesEvent.class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the handler switch.
|
||||
*
|
||||
* @return the handler switch.
|
||||
*/
|
||||
@Override
|
||||
public Switch getSwitch() {
|
||||
// load the switch status from the config
|
||||
try {
|
||||
Configuration configuration = configurationAdmin.getConfiguration(Configurations.NODE, null);
|
||||
if (configuration != null) {
|
||||
Boolean status = new Boolean((String) configuration.getProperties()
|
||||
.get(Configurations.HANDLER + "." +
|
||||
FeaturesEventHandler.class.getName()));
|
||||
if (status) {
|
||||
eventSwitch.turnOn();
|
||||
} else {
|
||||
eventSwitch.turnOff();
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
return eventSwitch;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,135 @@
|
||||
/*-
|
||||
* ~~~~~~licensing~~~~~~
|
||||
* cluster-persistence-service
|
||||
* ==========
|
||||
* Copyright (C) 2020 - 2024 EmDev LLC
|
||||
* ==========
|
||||
* You may not use this file except in accordance with the License Terms of the Copyright
|
||||
* Holder located at: https://entaxy.ru/eula . All copyrights, all intellectual property
|
||||
* rights to the Software and any copies are the property of the Copyright Holder. Unless
|
||||
* it is explicitly allowed the Copyright Holder, the User is prohibited from using the
|
||||
* Software for commercial purposes to provide services to third parties.
|
||||
*
|
||||
* The Copyright Holder hereby declares that the Software is provided on an "AS IS".
|
||||
* Under no circumstances does the Copyright Holder guarantee or promise that the
|
||||
* Software provided by him will be suitable or not suitable for the specific purposes
|
||||
* of the User, that the Software will meet all commercial and personal subjective
|
||||
* expectations of the User, that the Software will work properly, without technical
|
||||
* errors, quickly and uninterruptedly.
|
||||
*
|
||||
* Under no circumstances shall the Copyright Holder or its Affiliates is not liable
|
||||
* to the User for any direct or indirect losses of the User, his expenses or actual
|
||||
* damage, including, downtime; loss of bussines; lost profit; lost earnings; loss
|
||||
* or damage to data, property, etc.
|
||||
* ~~~~~~/licensing~~~~~~
|
||||
*/
|
||||
/*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
|
||||
* in compliance with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License
|
||||
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
|
||||
* or implied. See the License for the specific language governing permissions and limitations under
|
||||
* the License.
|
||||
*/
|
||||
package ru.entaxy.esb.platform.core.cluster.persistence.handler;
|
||||
|
||||
import org.apache.karaf.cellar.core.control.BasicSwitch;
|
||||
import org.apache.karaf.cellar.core.control.Switch;
|
||||
import org.apache.karaf.cellar.core.control.SwitchStatus;
|
||||
import org.apache.karaf.cellar.core.event.EventHandler;
|
||||
import org.apache.karaf.cellar.features.ClusterRepositoryEvent;
|
||||
import org.apache.karaf.cellar.features.FeaturesSupport;
|
||||
import org.apache.karaf.features.RepositoryEvent;
|
||||
import org.osgi.framework.BundleContext;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import ru.entaxy.esb.platform.core.cluster.persistence.PersistenceManager;
|
||||
|
||||
/**
|
||||
* Handler for cluster features repository event.
|
||||
*/
|
||||
public class LocalRepositoryEventHandler extends FeaturesSupport implements EventHandler<ClusterRepositoryEvent> {
|
||||
|
||||
private static final transient Logger LOGGER = LoggerFactory.getLogger(LocalRepositoryEventHandler.class);
|
||||
|
||||
public static final String SWITCH_ID = "org.apache.karaf.cellar.event.repository.handler";
|
||||
|
||||
private final Switch eventSwitch = new BasicSwitch(SWITCH_ID);
|
||||
|
||||
private PersistenceManager<String> persistenceManager;
|
||||
|
||||
@Override
|
||||
public void init(BundleContext bundleContext) {
|
||||
super.init(bundleContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle cluster features repository event.
|
||||
*
|
||||
* @param event the cluster event to handle.
|
||||
*/
|
||||
@Override
|
||||
public void handle(ClusterRepositoryEvent event) {
|
||||
|
||||
// check if the handler is ON
|
||||
if (eventSwitch.getStatus().equals(SwitchStatus.OFF)) {
|
||||
LOGGER.debug("CELLAR FEATURE: {} switch is OFF, cluster event is not handled", SWITCH_ID);
|
||||
return;
|
||||
}
|
||||
|
||||
if (groupManager == null) {
|
||||
// in rare cases for example right after installation this happens!
|
||||
LOGGER.error("CELLAR FEATURE: retrieved event {} while groupManager is not available yet!", event);
|
||||
return;
|
||||
}
|
||||
|
||||
// check if the group is local
|
||||
if (!groupManager.isLocalGroup(event.getSourceGroup().getName())) {
|
||||
LOGGER.debug("CELLAR FEATURE: node is not part of the event cluster group");
|
||||
return;
|
||||
}
|
||||
|
||||
// check if the event is not "local"
|
||||
if (event.getLocal() != null && event.getLocal().getId().equals(clusterManager.getNode().getId())) {
|
||||
LOGGER.trace("CELLAR FEATURE: event is local (coming from synchronizer or listener)");
|
||||
return;
|
||||
}
|
||||
|
||||
String uri = event.getId();
|
||||
RepositoryEvent.EventType type = event.getType();
|
||||
try {
|
||||
|
||||
// TODO mark cluster state as needed to be saved
|
||||
LOGGER.debug("-->> WE NEED TO SAVE CLUSTER STATE");
|
||||
this.persistenceManager.updated();
|
||||
|
||||
} catch (Exception e) {
|
||||
LOGGER.error("CELLAR FEATURE: failed to add/remove repository URL {}", uri, e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ClusterRepositoryEvent> getType() {
|
||||
return ClusterRepositoryEvent.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Switch getSwitch() {
|
||||
return eventSwitch;
|
||||
}
|
||||
|
||||
public void setPersistenceManager(PersistenceManager<String> persistenceManager) {
|
||||
this.persistenceManager = persistenceManager;
|
||||
}
|
||||
|
||||
|
||||
}
|
Reference in New Issue
Block a user