use of io.fabric8.api.FabricException in project fabric8 by jboss-fuse.
the class EncryptedPropertyResolver method initialize.
/**
* When {@link FabricService} becomes available, we can initialize this {@link PlaceholderResolver}
* @param fabricService
*/
public void initialize(FabricService fabricService) {
this.fabricService = fabricService;
encryptor = getEncryptor(fabricService);
if (bundleContext != null) {
seRegistration = bundleContext.registerService(PBEStringEncryptor.class, encryptor, null);
BundleContext context = FrameworkUtil.getBundle(PersistenceManager.class).getBundleContext();
encryptingPersistenceManager = new EncryptingPersistenceManager(context, context.getProperty(ConfigurationManager.CM_CONFIG_DIR), encryptor);
originalPersistenceManager = inject(configAdmin, encryptingPersistenceManager);
passwordNodeCache = new NodeCacheExtended(fabricService.adapt(CuratorFramework.class), AUTHENTICATION_CRYPT_PASSWORD.getPath());
passwordNodeCache.getListenable().addListener(this);
alogrithmNodeCache = new NodeCacheExtended(fabricService.adapt(CuratorFramework.class), AUTHENTICATION_CRYPT_ALGORITHM.getPath());
alogrithmNodeCache.getListenable().addListener(this);
try {
passwordNodeCache.start();
alogrithmNodeCache.start();
} catch (Exception e) {
throw new FabricException(e);
}
}
}
use of io.fabric8.api.FabricException in project fabric8 by jboss-fuse.
the class ZookeeperPortService method registerPort.
private void registerPort(Container container, String pid, String key, int port, Lease existingLease) {
assertValid();
String portAsString = String.valueOf(port);
String containerPortsPath = ZkPath.PORTS_CONTAINER_PID_KEY.getPath(container.getId(), pid, key);
String reservedPortsPath = ZkPath.PORTS_CONTAINER_RESERVED_PORTS.getPath(container.getId());
String ip = container.getIp();
assertValidIp(container, ip);
String ipPortsPath = ZkPath.PORTS_IP.getPath(ip);
Lease lease = null;
try {
if (existingLease != null) {
lease = existingLease;
} else {
lease = interProcessLock.acquire(60, TimeUnit.SECONDS);
}
if (lease != null) {
createDefault(curator.get(), containerPortsPath, portAsString);
createDefault(curator.get(), ipPortsPath, portAsString);
setData(curator.get(), containerPortsPath, portAsString);
String existingPorts = getStringData(curator.get(), ipPortsPath);
if (!existingPorts.contains(portAsString)) {
setData(curator.get(), ipPortsPath, existingPorts + " " + portAsString);
createDefault(curator.get(), reservedPortsPath, portAsString);
String reservedPortsPerContainer = getStringData(curator.get(), reservedPortsPath);
if (!reservedPortsPerContainer.contains(portAsString)) {
setData(curator.get(), reservedPortsPath, reservedPortsPerContainer + " " + portAsString);
}
}
} else {
throw new FabricException("Could not acquire port lock for pid " + pid);
}
} catch (InterruptedException ex) {
cleanUpDirtyZKNodes(interProcessLock);
throw FabricException.launderThrowable(ex);
} catch (Exception ex) {
throw FabricException.launderThrowable(ex);
} finally {
if (existingLease == null) {
releaseLock(lease);
}
}
}
use of io.fabric8.api.FabricException in project fabric8 by jboss-fuse.
the class ZookeeperPortService method registerPort.
@Override
public int registerPort(Container container, String pid, String key, int fromPort, int toPort, Set<Integer> excludes) {
assertValid();
Lease lease = null;
try {
lease = interProcessLock.acquire(60, TimeUnit.SECONDS);
if (lease != null) {
int port = lookupPort(container, pid, key);
if (port > 0 && (port >= fromPort && port <= toPort)) {
// get one from the port range
return port;
}
Set<Integer> boundPorts = findUsedPortByHost(container, lease);
boundPorts.addAll(excludes);
for (port = fromPort; port <= toPort; port++) {
if (!boundPorts.contains(port)) {
if (Ports.isPortFree(port)) {
registerPort(container, pid, key, port, lease);
return port;
}
}
}
} else {
throw new FabricException("Could not acquire port lock for pid " + pid);
}
throw new FabricException("Could not find port within range [" + fromPort + "," + toPort + "] for pid " + pid);
} catch (InterruptedException ex) {
cleanUpDirtyZKNodes(interProcessLock);
throw FabricException.launderThrowable(ex);
} catch (Exception ex) {
throw FabricException.launderThrowable(ex);
} finally {
releaseLock(lease);
}
}
use of io.fabric8.api.FabricException in project fabric8 by jboss-fuse.
the class ZookeeperPortService method findUsedPortByHost.
private Set<Integer> findUsedPortByHost(Container container, Lease existingLease) {
assertValid();
String ip = container.getIp();
assertValidIp(container, ip);
Set<Integer> ports = new HashSet<Integer>();
String path = ZkPath.PORTS_IP.getPath(ip);
Lease lease = null;
try {
if (existingLease != null) {
lease = existingLease;
} else {
lease = interProcessLock.acquire(60, TimeUnit.SECONDS);
}
if (lease != null) {
createDefault(curator.get(), path, "");
String boundPorts = getStringData(curator.get(), path);
if (boundPorts != null && !boundPorts.isEmpty()) {
for (String port : boundPorts.split(" ")) {
try {
ports.add(Integer.parseInt(port.trim()));
} catch (NumberFormatException ex) {
// ignore
}
}
}
} else {
throw new FabricException("Could not acquire port lock");
}
} catch (InterruptedException ex) {
cleanUpDirtyZKNodes(interProcessLock);
throw FabricException.launderThrowable(ex);
} catch (Exception ex) {
throw FabricException.launderThrowable(ex);
} finally {
if (existingLease == null) {
releaseLock(lease);
}
}
return ports;
}
use of io.fabric8.api.FabricException in project fabric8 by jboss-fuse.
the class ZookeeperPortService method findUsedPortByContainer.
@Override
public Set<Integer> findUsedPortByContainer(Container container) {
assertValid();
Set<Integer> ports = new HashSet<Integer>();
String path = ZkPath.PORTS_CONTAINER.getPath(container.getId());
Lease lease = null;
try {
lease = interProcessLock.acquire(60, TimeUnit.SECONDS);
if (lease != null) {
if (exists(curator.get(), path) != null) {
for (String pid : getChildren(curator.get(), path)) {
for (String key : getChildren(curator.get(), ZkPath.PORTS_CONTAINER_PID.getPath(container.getId(), pid))) {
String port = getStringData(curator.get(), ZkPath.PORTS_CONTAINER_PID_KEY.getPath(container.getId(), pid, key));
try {
ports.add(Integer.parseInt(port));
} catch (Exception ex) {
// ignore
}
}
}
}
} else {
throw new FabricException("Could not acquire port lock");
}
} catch (InterruptedException ex) {
cleanUpDirtyZKNodes(interProcessLock);
throw FabricException.launderThrowable(ex);
} catch (Exception ex) {
throw FabricException.launderThrowable(ex);
} finally {
releaseLock(lease);
}
return ports;
}
Aggregations