use of com.sleepycat.je.rep.ReplicationConfig in project qpid-broker-j by apache.
the class BDBHAVirtualHostNodeRestTest method testIntruderProtection.
public void testIntruderProtection() throws Exception {
createHANode(NODE1, _node1HaPort, _node1HaPort);
assertNode(NODE1, _node1HaPort, _node1HaPort, NODE1);
Map<String, Object> nodeData = getRestTestHelper().getJsonAsMap(_baseNodeRestUrl + NODE1);
String node1StorePath = (String) nodeData.get(BDBHAVirtualHostNode.STORE_PATH);
long transactionId = ((Number) nodeData.get(BDBHAVirtualHostNode.LAST_KNOWN_REPLICATION_TRANSACTION_ID)).longValue();
// add permitted node
Map<String, Object> node3Data = createNodeAttributeMap(NODE3, _node3HaPort, _node1HaPort);
getRestTestHelper().submitRequest(_baseNodeRestUrl + NODE3, "PUT", node3Data, HttpServletResponse.SC_CREATED);
assertNode(NODE3, _node3HaPort, _node1HaPort, NODE1);
assertRemoteNodes(NODE1, NODE3);
// Ensure PINGDB is created
// in order to exclude hanging of environment
// when environment.close is called whilst PINGDB is created.
// On node joining, a record is updated in PINGDB
// if lastTransactionId is incremented then node ping task was executed
int counter = 0;
long newTransactionId = transactionId;
while (newTransactionId == transactionId && counter < 50) {
nodeData = getRestTestHelper().getJsonAsMap(_baseNodeRestUrl + NODE1);
newTransactionId = ((Number) nodeData.get(BDBHAVirtualHostNode.LAST_KNOWN_REPLICATION_TRANSACTION_ID)).longValue();
if (newTransactionId != transactionId) {
break;
}
counter++;
Thread.sleep(100L);
}
// connect intruder node
String nodeName = NODE2;
String nodeHostPort = "localhost:" + getNextAvailable(_node3HaPort + 1);
File environmentPathFile = new File(node1StorePath, nodeName);
environmentPathFile.mkdirs();
ReplicationConfig replicationConfig = new ReplicationConfig((String) nodeData.get(BDBHAVirtualHostNode.GROUP_NAME), nodeName, nodeHostPort);
replicationConfig.setHelperHosts((String) nodeData.get(BDBHAVirtualHostNode.ADDRESS));
replicationConfig.setConsistencyPolicy(NoConsistencyRequiredPolicy.NO_CONSISTENCY);
EnvironmentConfig envConfig = new EnvironmentConfig();
envConfig.setAllowCreate(true);
envConfig.setTransactional(true);
envConfig.setDurability(Durability.parse((String) nodeData.get(BDBHAVirtualHostNode.DURABILITY)));
ReplicatedEnvironment intruder = null;
try {
intruder = new ReplicatedEnvironment(environmentPathFile, replicationConfig, envConfig);
} finally {
if (intruder != null) {
intruder.close();
}
}
_restTestHelper.waitForAttributeChanged(_baseNodeRestUrl + NODE1, VirtualHostNode.STATE, State.ERRORED.name());
_restTestHelper.waitForAttributeChanged(_baseNodeRestUrl + NODE3, VirtualHostNode.STATE, State.ERRORED.name());
}
use of com.sleepycat.je.rep.ReplicationConfig in project qpid-broker-j by apache.
the class BDBHAVirtualHostNodeTest method joinIntruder.
private void joinIntruder(final int nodePortNumber, final String nodeName, final String groupName, final String helperAddress, final Durability durability, final File environmentPathFile) {
environmentPathFile.mkdirs();
ReplicationConfig replicationConfig = new ReplicationConfig(groupName, nodeName, "localhost:" + nodePortNumber);
replicationConfig.setNodePriority(0);
replicationConfig.setHelperHosts(helperAddress);
replicationConfig.setConsistencyPolicy(NoConsistencyRequiredPolicy.NO_CONSISTENCY);
EnvironmentConfig envConfig = new EnvironmentConfig();
envConfig.setAllowCreate(true);
envConfig.setTransactional(true);
envConfig.setDurability(durability);
ReplicatedEnvironment intruder = null;
String originalThreadName = Thread.currentThread().getName();
try {
intruder = new ReplicatedEnvironment(environmentPathFile, replicationConfig, envConfig);
} finally {
try {
if (intruder != null) {
intruder.close();
}
} finally {
Thread.currentThread().setName(originalThreadName);
}
}
}
use of com.sleepycat.je.rep.ReplicationConfig in project qpid-broker-j by apache.
the class ReplicatedEnvironmentFacade method createReplicationGroupAdmin.
private ReplicationGroupAdmin createReplicationGroupAdmin() {
final Set<InetSocketAddress> helpers = new HashSet<InetSocketAddress>();
final ReplicationConfig repConfig = getEnvironment().getRepConfig();
helpers.addAll(repConfig.getHelperSockets());
helpers.add(HostPortPair.getSocket(HostPortPair.getString(repConfig.getNodeHostname(), repConfig.getNodePort())));
return new ReplicationGroupAdmin(_configuration.getGroupName(), helpers);
}
use of com.sleepycat.je.rep.ReplicationConfig in project qpid-broker-j by apache.
the class ReplicatedEnvironmentFacade method createEnvironment.
private void createEnvironment(boolean createEnvironmentInSeparateThread, Runnable postCreationAction) {
String groupName = _configuration.getGroupName();
String helperHostPort = _configuration.getHelperHostPort();
String hostPort = _configuration.getHostPort();
boolean designatedPrimary = _configuration.isDesignatedPrimary();
int priority = _configuration.getPriority();
int quorumOverride = _configuration.getQuorumOverride();
String nodeName = _configuration.getName();
String helperNodeName = _configuration.getHelperNodeName();
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Creating environment");
LOGGER.info("Environment path " + _environmentDirectory.getAbsolutePath());
LOGGER.info("Group name " + groupName);
LOGGER.info("Node name " + nodeName);
LOGGER.info("Node host port " + hostPort);
LOGGER.info("Helper host port " + helperHostPort);
LOGGER.info("Helper node name " + helperNodeName);
LOGGER.info("Durability " + _defaultDurability);
LOGGER.info("Designated primary (applicable to 2 node case only) " + designatedPrimary);
LOGGER.info("Node priority " + priority);
LOGGER.info("Quorum override " + quorumOverride);
LOGGER.info("Permitted node list " + _permittedNodes);
}
Map<String, String> replicationEnvironmentParameters = new HashMap<>(ReplicatedEnvironmentFacade.REPCONFIG_DEFAULTS);
replicationEnvironmentParameters.putAll(_configuration.getReplicationParameters());
ReplicationConfig replicationConfig = new ReplicationConfig(groupName, nodeName, hostPort);
replicationConfig.setHelperHosts(helperHostPort);
replicationConfig.setDesignatedPrimary(designatedPrimary);
replicationConfig.setNodePriority(priority);
replicationConfig.setElectableGroupSizeOverride(quorumOverride);
for (Map.Entry<String, String> configItem : replicationEnvironmentParameters.entrySet()) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Setting ReplicationConfig key " + configItem.getKey() + " to '" + configItem.getValue() + "'");
}
replicationConfig.setConfigParam(configItem.getKey(), configItem.getValue());
}
Map<String, String> environmentParameters = new HashMap<>(EnvironmentFacade.ENVCONFIG_DEFAULTS);
environmentParameters.putAll(_configuration.getParameters());
EnvironmentConfig envConfig = new EnvironmentConfig();
envConfig.setAllowCreate(true);
envConfig.setTransactional(true);
envConfig.setExceptionListener(new ExceptionListener());
envConfig.setDurability(_defaultDurability);
envConfig.setCacheMode(_configuration.getCacheMode());
envConfig.setLoggingHandler(new Slf4jLoggingHandler(_configuration));
LOGGER.info("Cache mode {}", envConfig.getCacheMode());
for (Map.Entry<String, String> configItem : environmentParameters.entrySet()) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Setting EnvironmentConfig key " + configItem.getKey() + " to '" + configItem.getValue() + "'");
}
envConfig.setConfigParam(configItem.getKey(), configItem.getValue());
}
DbInternal.setLoadPropertyFile(envConfig, false);
File propsFile = new File(_environmentDirectory, "je.properties");
if (propsFile.exists()) {
LOGGER.warn("The BDB configuration file at '" + _environmentDirectory + File.separator + "je.properties' will NOT be loaded. Configure BDB using Qpid context variables instead.");
}
if (createEnvironmentInSeparateThread) {
createEnvironmentInSeparateThread(_environmentDirectory, envConfig, replicationConfig, postCreationAction);
} else {
createEnvironment(_environmentDirectory, envConfig, replicationConfig, postCreationAction);
}
}
use of com.sleepycat.je.rep.ReplicationConfig in project qpid-broker-j by apache.
the class OrphanConfigurationRecordPurger method createEnvironment.
private Environment createEnvironment(final EnvironmentConfig config) throws Exception {
final Environment env;
if (_ha) {
final ReplicationConfig repConfig = (ReplicationConfig) ReplicationConfig.DEFAULT.setNodeHostPort(_nodeHost).setGroupName(_groupName).setNodeName(_nodeName).setDesignatedPrimary(true).setElectableGroupSizeOverride(1);
env = new ReplicatedEnvironment(new File(_storePath), repConfig, config);
} else {
env = new Environment(new File(_storePath), config);
}
return env;
}
Aggregations