use of io.fabric8.utils.BundleUtils in project fabric8 by jboss-fuse.
the class JoinAction method doExecute.
@Override
protected Object doExecute() throws Exception {
if (nonManaged) {
profile = "unmanaged";
}
String oldName = runtimeProperties.getRuntimeIdentity();
if (System.getenv("OPENSHIFT_BROKER_HOST") != null && containerName != null) {
System.err.println("Containers in OpenShift cannot be renamed");
return null;
}
if (containerName == null) {
containerName = oldName;
}
FabricValidations.validateContainerName(containerName);
Configuration bootConfiguration = configAdmin.getConfiguration(BootstrapConfiguration.COMPONENT_PID, null);
Configuration dataStoreConfiguration = configAdmin.getConfiguration(Constants.DATASTORE_PID, null);
Configuration configZook = configAdmin.getConfiguration(Constants.ZOOKEEPER_CLIENT_PID, null);
if (configZook.getProperties() != null && configZook.getProperties().get("zookeeper.url") != null) {
System.err.println("This container is already connected to a fabric");
return null;
}
Dictionary<String, Object> bootProperties = bootConfiguration.getProperties();
if (bootProperties == null) {
bootProperties = new Hashtable<>();
}
if (resolver != null) {
bootProperties.put(ZkDefs.LOCAL_RESOLVER_PROPERTY, resolver);
}
if (manualIp != null) {
bootProperties.put(ZkDefs.MANUAL_IP, manualIp);
}
if (bindAddress != null) {
bootProperties.put(ZkDefs.BIND_ADDRESS, bindAddress);
}
zookeeperPassword = zookeeperPassword != null ? zookeeperPassword : ShellUtils.retrieveFabricZookeeperPassword(session);
if (zookeeperPassword == null) {
zookeeperPassword = promptForZookeeperPassword();
}
if (zookeeperPassword == null || zookeeperPassword.isEmpty()) {
System.out.println("No password specified. Cannot join fabric ensemble.");
return null;
}
ShellUtils.storeZookeeperPassword(session, zookeeperPassword);
log.debug("Encoding ZooKeeper password.");
String encodedPassword = PasswordEncoder.encode(zookeeperPassword);
bootProperties.put(ZkDefs.MINIMUM_PORT, String.valueOf(minimumPort));
bootProperties.put(ZkDefs.MAXIMUM_PORT, String.valueOf(maximumPort));
Hashtable<String, Object> dataStoreProperties = new Hashtable<String, Object>();
Configuration cfg = configAdmin.getConfiguration(Constants.DATASTORE_PID, null);
Dictionary<String, Object> props = cfg.getProperties();
if (props != null) {
for (Enumeration<String> keys = cfg.getProperties().keys(); keys.hasMoreElements(); ) {
String k = keys.nextElement();
dataStoreProperties.put(k, cfg.getProperties().get(k));
}
}
augmentDataStoreProperties(zookeeperPassword, dataStoreProperties);
if (!containerName.equals(oldName)) {
if (force || permissionToRenameContainer()) {
if (!registerContainer(containerName, zookeeperPassword, profile, force)) {
System.err.println("A container with the name: " + containerName + " is already member of the cluster. You can specify a different name as an argument.");
return null;
}
bootProperties.put(SystemProperties.KARAF_NAME, containerName);
// Ensure that if we bootstrap CuratorFramework via RuntimeProperties password is set before the URL.
bootProperties.put("zookeeper.password", encodedPassword);
bootProperties.put("zookeeper.url", zookeeperUrl);
// Rename the container
Path propsPath = runtimeProperties.getConfPath().resolve("system.properties");
Properties systemProps = new Properties(propsPath.toFile());
systemProps.put(SystemProperties.KARAF_NAME, containerName);
// Also pass zookeeper information so that the container can auto-join after the restart.
systemProps.put("zookeeper.url", zookeeperUrl);
systemProps.put("zookeeper.password", encodedPassword);
systemProps.save();
System.setProperty("runtime.id", containerName);
System.setProperty(SystemProperties.KARAF_NAME, containerName);
System.setProperty("karaf.restart", "true");
System.setProperty("karaf.restart.clean", "false");
if (!nonManaged) {
installBundles();
}
// it's only a(n almost certain) way of synchronizing CM and ManagedService.update()
if (!OsgiUtils.updateCmConfigurationAndWait(bundleContext, bootConfiguration, bootProperties, 10, TimeUnit.SECONDS)) {
log.warn("Timeout waiting for update of PID: {}", BootstrapConfiguration.COMPONENT_PID);
}
if (!OsgiUtils.updateCmConfigurationAndWait(bundleContext, dataStoreConfiguration, dataStoreProperties, 10, TimeUnit.SECONDS)) {
log.warn("Timeout waiting for update of PID: {}", Constants.DATASTORE_PID);
}
// we don't want fileinstall to trigger ConfigAdmin update
Bundle fileinstall = new BundleUtils(bundleContext).findBundle("org.apache.felix.fileinstall");
if (fileinstall != null) {
fileinstall.stop(Bundle.STOP_TRANSIENT);
}
persistConfiguration(configAdmin, Constants.DATASTORE_PID, dataStoreProperties);
// Restart the container
bundleContext.getBundle(0).stop();
return null;
} else {
return null;
}
} else {
bootConfiguration.update(bootProperties);
dataStoreConfiguration.update(dataStoreProperties);
persistConfiguration(configAdmin, Constants.DATASTORE_PID, dataStoreProperties);
if (!registerContainer(containerName, zookeeperPassword, profile, force)) {
System.err.println("A container with the name: " + containerName + " is already member of the cluster. You can specify a different name as an argument.");
return null;
}
Configuration config = configAdmin.getConfiguration(Constants.ZOOKEEPER_CLIENT_PID, null);
Hashtable<String, Object> properties = new Hashtable<String, Object>();
properties.put("zookeeper.url", zookeeperUrl);
properties.put("zookeeper.password", PasswordEncoder.encode(encodedPassword));
config.setBundleLocation(null);
config.update(properties);
if (!nonManaged) {
installBundles();
}
return null;
}
}
use of io.fabric8.utils.BundleUtils in project fabric8 by jboss-fuse.
the class FeatureConfigInstaller method restoreConfigAdminIfNeeded.
public void restoreConfigAdminIfNeeded() {
// we'll be doing confiadmin checks, so configadmin bundle has to be started and has its services registered
Bundle b = null;
try {
b = new BundleUtils(context).findBundle("org.apache.felix.configadmin");
if (b.getState() != Bundle.ACTIVE) {
b.start();
ServiceReference<ConfigurationAdmin> ref = context.getServiceReference(ConfigurationAdmin.class);
if (ref != null) {
configAdmin = context.getService(ref);
}
}
} catch (BundleException e) {
configAdmin = null;
LOGGER.warn(e.getMessage());
}
}
use of io.fabric8.utils.BundleUtils in project fabric8 by jboss-fuse.
the class ZooKeeperClusterBootstrapImpl method stopBundles.
private void stopBundles() throws BundleException {
BundleUtils bundleUtils = new BundleUtils(bundleContext);
bundleUtils.findAndStopBundle("io.fabric8.fabric-agent");
// bundleUtils.findAndStopBundle("org.ops4j.pax.web.pax-web-jetty");
}
use of io.fabric8.utils.BundleUtils in project fabric8 by jboss-fuse.
the class ZooKeeperClusterBootstrapImpl method startBundles.
private void startBundles(CreateEnsembleOptions options) throws BundleException {
BundleUtils bundleUtils = new BundleUtils(bundleContext);
Bundle agentBundle = bundleUtils.findBundle("io.fabric8.fabric-agent");
if (agentBundle != null && options.isAgentEnabled()) {
agentBundle.start();
}
// Bundle webBundle = bundleUtils.findBundle("org.ops4j.pax.web.pax-web-jetty");
// if (webBundle != null) {
// webBundle.start();
// }
}
use of io.fabric8.utils.BundleUtils in project fabric8 by jboss-fuse.
the class MetaTypeFacade method activate.
@Activate
void activate(BundleContext bundleContext) throws Exception {
this.bundleContext = bundleContext;
bundleUtils = new BundleUtils(bundleContext);
Objects.notNull(metaTypeService, "metaTypeService");
Objects.notNull(bundleContext, "bundleContext");
if (mbeanServer != null) {
StandardMBean mbean = new StandardMBean(this, MetaTypeFacadeMXBean.class);
JMXUtils.registerMBean(mbean, mbeanServer, OBJECT_NAME);
}
}
Aggregations