Search in sources :

Example 1 with Profile

use of io.fabric8.maven.core.config.Profile in project fabric8 by jboss-fuse.

the class ContainerAddProfileAction method doExecute.

protected Object doExecute() throws Exception {
    FabricValidations.validateContainerName(container);
    FabricValidations.validateProfileNames(profiles);
    Container cont = FabricCommand.getContainer(fabricService, container);
    // we can add existing profiles
    Profile[] profs = FabricCommand.getExistingProfiles(fabricService, cont.getVersion(), this.profiles);
    cont.addProfiles(profs);
    return null;
}
Also used : Container(io.fabric8.api.Container) Profile(io.fabric8.api.Profile)

Example 2 with Profile

use of io.fabric8.maven.core.config.Profile in project fabric8 by jboss-fuse.

the class ContainerChangeProfileAction method doExecute.

protected Object doExecute() throws Exception {
    FabricValidations.validateContainerName(container);
    FabricValidations.validateProfileNames(profiles);
    Container cont = FabricCommand.getContainer(fabricService, container);
    // we can only change to existing profiles
    Profile[] profs = FabricCommand.getExistingProfiles(fabricService, cont.getVersion(), profiles);
    cont.setProfiles(profs);
    return null;
}
Also used : Container(io.fabric8.api.Container) Profile(io.fabric8.api.Profile)

Example 3 with Profile

use of io.fabric8.maven.core.config.Profile 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;
    }
}
Also used : ZkPath(io.fabric8.zookeeper.ZkPath) Path(java.nio.file.Path) Configuration(org.osgi.service.cm.Configuration) BootstrapConfiguration(io.fabric8.zookeeper.bootstrap.BootstrapConfiguration) Hashtable(java.util.Hashtable) Bundle(org.osgi.framework.Bundle) SystemProperties(io.fabric8.api.SystemProperties) RuntimeProperties(io.fabric8.api.RuntimeProperties) Properties(org.apache.felix.utils.properties.Properties) BundleUtils(io.fabric8.utils.BundleUtils)

Example 4 with Profile

use of io.fabric8.maven.core.config.Profile in project fabric8 by jboss-fuse.

the class FabricMBeanFacadeTest method testGetProfileIds.

@Test
public void testGetProfileIds() {
    // this can only be run if you have a fabric running...
    Assume.assumeTrue(Boolean.valueOf(System.getProperty("hasFabric")));
    FabricMBean facade = getFabricMBean();
    String json = facade.getProfileIds("1.0");
    try {
        Collection<String> profiles = Helpers.getObjectMapper().readValue(json, TypeFactory.defaultInstance().constructParametricType(Collection.class, String.class));
        Assume.assumeNotNull(profiles);
        for (String profile : profiles) {
            System.out.println("Profile id:" + profile);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : FabricMBean(io.fabric8.jolokia.facade.mbeans.FabricMBean) Collection(java.util.Collection) Test(org.junit.Test)

Example 5 with Profile

use of io.fabric8.maven.core.config.Profile in project fabric8 by jboss-fuse.

the class FabricMBeanFacadeTest method testGetProfilesFields.

@Test
public void testGetProfilesFields() {
    // this can only be run if you have a fabric running...
    Assume.assumeTrue(Boolean.valueOf(System.getProperty("hasFabric")));
    FabricMBean facade = getFabricMBean();
    String json = facade.getProfiles("1.0", Helpers.toList("id"));
    try {
        Collection<ProfileDTO> profiles = Helpers.getObjectMapper().readValue(json, TypeFactory.defaultInstance().constructParametricType(Collection.class, ProfileDTO.class));
        Assume.assumeNotNull(profiles);
        for (ProfileDTO profile : profiles) {
            System.out.println(profile);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : FabricMBean(io.fabric8.jolokia.facade.mbeans.FabricMBean) Collection(java.util.Collection) Test(org.junit.Test)

Aggregations

Profile (io.fabric8.api.Profile)125 Version (io.fabric8.api.Version)50 Container (io.fabric8.api.Container)49 ArrayList (java.util.ArrayList)37 ProfileBuilder (io.fabric8.api.ProfileBuilder)34 Test (org.junit.Test)32 FabricService (io.fabric8.api.FabricService)28 HashMap (java.util.HashMap)25 File (java.io.File)24 ProfileService (io.fabric8.api.ProfileService)23 Map (java.util.Map)22 IOException (java.io.IOException)19 ProfileRequirements (io.fabric8.api.ProfileRequirements)13 HashSet (java.util.HashSet)12 GitVersion (io.fabric8.api.commands.GitVersion)11 FabricRequirements (io.fabric8.api.FabricRequirements)10 LinkedList (java.util.LinkedList)9 TreeMap (java.util.TreeMap)9 LockHandle (io.fabric8.api.LockHandle)8 Parser (io.fabric8.maven.util.Parser)8