use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class BDBVirtualHostNodeTest method testValidateOnCreateForInvalidStorePath.
public void testValidateOnCreateForInvalidStorePath() throws Exception {
String nodeName = getTestName();
File file = new File(_storePath + File.separator + nodeName);
assertTrue("Empty file is not created", file.createNewFile());
Map<String, Object> attributes = new HashMap<>();
attributes.put(BDBVirtualHostNode.ID, UUID.randomUUID());
attributes.put(BDBVirtualHostNode.TYPE, BDBVirtualHostNodeImpl.VIRTUAL_HOST_NODE_TYPE);
attributes.put(BDBVirtualHostNode.NAME, nodeName);
attributes.put(BDBVirtualHostNode.STORE_PATH, file.getAbsolutePath());
BDBVirtualHostNodeImpl node = new BDBVirtualHostNodeImpl(attributes, _broker);
try {
node.create();
fail("Cannot create DBD node from existing empty file");
} catch (IllegalConfigurationException e) {
assertTrue("Unexpected exception " + e.getMessage(), e.getMessage().startsWith("Cannot open node configuration store"));
}
}
use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class ReplicatedEnvironmentFacade method getPermittedHostsFromHelper.
private static Collection<String> getPermittedHostsFromHelper(final String nodeName, final String groupName, final String helperNodeName, final String helperHostPort, final int dbPingSocketTimeout) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("Requesting state of the node '%s' at '%s'", helperNodeName, helperHostPort));
}
if (helperNodeName == null || "".equals(helperNodeName)) {
throw new IllegalConfigurationException(String.format("A helper node is not specified for node '%s'" + " joining the group '%s'", nodeName, groupName));
}
Collection<String> permittedNodes = null;
try {
ReplicationNodeImpl node = new ReplicationNodeImpl(helperNodeName, helperHostPort);
NodeState state = getRemoteNodeState(groupName, node, dbPingSocketTimeout);
byte[] applicationState = state.getAppState();
return convertApplicationStateBytesToPermittedNodeList(applicationState);
} catch (SocketTimeoutException ste) {
throw new ExternalServiceTimeoutException(String.format("Timed out trying to connect to existing node '%s' at '%s'", helperNodeName, helperHostPort), ste);
} catch (IOException | ServiceConnectFailedException e) {
throw new ExternalServiceException(String.format("Cannot connect to existing node '%s' at '%s'", helperNodeName, helperHostPort), e);
} catch (BinaryProtocol.ProtocolException e) {
String message = String.format("Unexpected protocol exception '%s' encountered while retrieving state for node '%s' (%s) from group '%s'", e.getUnexpectedMessage(), helperNodeName, helperHostPort, groupName);
LOGGER.warn(message, e);
throw new ExternalServiceException(message, e);
} catch (RuntimeException e) {
throw new ExternalServiceException(String.format("Cannot retrieve state for node '%s' (%s) from group '%s'", helperNodeName, helperHostPort, groupName), e);
}
}
use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class ReplicatedEnvironmentFacade method connectToHelperNodeAndCheckPermittedHosts.
public static Collection<String> connectToHelperNodeAndCheckPermittedHosts(final String nodeName, final String hostPort, final String groupName, final String helperNodeName, final String helperHostPort, final int dbPingSocketTimeout) {
ExecutorService executor = null;
Future<Collection<String>> future = null;
try {
executor = Executors.newSingleThreadExecutor(new DaemonThreadFactory(String.format("PermittedHostsCheck-%s-%s", groupName, nodeName)));
future = executor.submit(new Callable<Collection<String>>() {
@Override
public Collection<String> call() throws Exception {
return getPermittedHostsFromHelper(nodeName, groupName, helperNodeName, helperHostPort, dbPingSocketTimeout);
}
});
try {
final long timeout = (long) (dbPingSocketTimeout * 1.25);
final Collection<String> permittedNodes = dbPingSocketTimeout <= 0 ? future.get() : future.get(timeout, TimeUnit.MILLISECONDS);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug(String.format("Node '%s' permits nodes: '%s'", helperNodeName, String.valueOf(permittedNodes)));
}
if (permittedNodes == null || !permittedNodes.contains(hostPort)) {
throw new IllegalConfigurationException(String.format("Node using address '%s' is not permitted to join the group '%s'", hostPort, groupName));
}
return permittedNodes;
} catch (ExecutionException e) {
final Throwable cause = e.getCause();
if (cause instanceof RuntimeException) {
throw (RuntimeException) cause;
} else {
throw new RuntimeException(cause);
}
} catch (TimeoutException e) {
future.cancel(true);
throw new ExternalServiceTimeoutException(String.format("Task timed out trying to connect to existing node '%s' at '%s'", nodeName, hostPort));
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new ExternalServiceException(String.format("Task failed to connect to existing node '%s' at '%s'", nodeName, hostPort));
}
} finally {
executor.shutdown();
}
}
use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class AbstractConfiguredObject method asObjectRecord.
@Override
public final ConfiguredObjectRecord asObjectRecord() {
return new ConfiguredObjectRecord() {
@Override
public UUID getId() {
return AbstractConfiguredObject.this.getId();
}
@Override
public String getType() {
return getCategoryClass().getSimpleName();
}
@Override
public Map<String, Object> getAttributes() {
return Subject.doAs(getSubjectWithAddedSystemRights(), new PrivilegedAction<Map<String, Object>>() {
@Override
public Map<String, Object> run() {
Map<String, Object> attributes = new LinkedHashMap<>();
Map<String, Object> actualAttributes = getActualAttributes();
for (ConfiguredObjectAttribute<?, ?> attr : _attributeTypes.values()) {
if (attr.isPersisted() && !ID.equals(attr.getName())) {
if (attr.isDerived()) {
Object value = getAttribute(attr.getName());
attributes.put(attr.getName(), toRecordedForm(attr, value));
} else if (actualAttributes.containsKey(attr.getName())) {
Object value = actualAttributes.get(attr.getName());
attributes.put(attr.getName(), toRecordedForm(attr, value));
}
}
}
return attributes;
}
});
}
public Object toRecordedForm(final ConfiguredObjectAttribute<?, ?> attr, Object value) {
if (value instanceof ConfiguredObject) {
value = ((ConfiguredObject) value).getId();
}
if (attr.isSecure() && _encrypter != null && value != null) {
if (value instanceof Collection || value instanceof Map) {
ObjectMapper mapper = ConfiguredObjectJacksonModule.newObjectMapper(false);
try (StringWriter stringWriter = new StringWriter()) {
mapper.writeValue(stringWriter, value);
value = _encrypter.encrypt(stringWriter.toString());
} catch (IOException e) {
throw new IllegalConfigurationException("Failure when encrypting a secret value", e);
}
} else {
value = _encrypter.encrypt(value.toString());
}
}
return value;
}
@Override
public Map<String, UUID> getParents() {
Map<String, UUID> parents = new LinkedHashMap<>();
Class<? extends ConfiguredObject> parentClass = getModel().getParentType(getCategoryClass());
ConfiguredObject parent = (ConfiguredObject) getParent();
if (parent != null) {
parents.put(parentClass.getSimpleName(), parent.getId());
}
return parents;
}
@Override
public String toString() {
return AbstractConfiguredObject.this.getClass().getSimpleName() + "[name=" + getName() + ", categoryClass=" + getCategoryClass() + ", type=" + getType() + ", id=" + getId() + ", attributes=" + getAttributes() + "]";
}
};
}
use of org.apache.qpid.server.configuration.IllegalConfigurationException in project qpid-broker-j by apache.
the class AbstractContainer method updateEncrypter.
private void updateEncrypter(final String encryptionProviderType) {
if (encryptionProviderType != null && !"".equals(encryptionProviderType.trim())) {
PluggableFactoryLoader<ConfigurationSecretEncrypterFactory> factoryLoader = new PluggableFactoryLoader<>(ConfigurationSecretEncrypterFactory.class);
ConfigurationSecretEncrypterFactory factory = factoryLoader.get(encryptionProviderType);
if (factory == null) {
throw new IllegalConfigurationException("Unknown Configuration Secret Encryption method " + encryptionProviderType);
}
setEncrypter(factory.createEncrypter(this));
} else {
setEncrypter(null);
}
}
Aggregations