Search in sources :

Example 21 with ProfileBuilder

use of io.fabric8.api.ProfileBuilder in project fabric8 by jboss-fuse.

the class ContainerImpl method getContainerProfile.

private Profile getContainerProfile() {
    Version version = getVersion();
    String profileId = "#container-" + getId();
    ProfileBuilder builder = ProfileBuilder.Factory.create(profileId).version(version.getId());
    ContainerProfileOptions optionsProvider = new ContainerProfileOptions(getId(), version, dataStore);
    return builder.addOptions(optionsProvider).getProfile();
}
Also used : Version(io.fabric8.api.Version) ProfileBuilder(io.fabric8.api.ProfileBuilder)

Example 22 with ProfileBuilder

use of io.fabric8.api.ProfileBuilder in project fabric8 by jboss-fuse.

the class MQServiceImpl method createOrUpdateMQClientProfile.

@Override
public Profile createOrUpdateMQClientProfile(String versionId, String profileId, String group, String parentProfileName) {
    Version version = profileService.getRequiredVersion(versionId);
    Profile parentProfile = null;
    if (Strings.isNotBlank(parentProfileName)) {
        parentProfile = version.getRequiredProfile(parentProfileName);
    }
    if (group == null || profileId == null)
        return parentProfile;
    ProfileBuilder builder;
    // create a profile if it doesn't exist
    boolean create = !version.hasProfile(profileId);
    if (create) {
        builder = ProfileBuilder.Factory.create(versionId, profileId);
    } else {
        Profile profile = version.getRequiredProfile(profileId);
        builder = ProfileBuilder.Factory.createFrom(profile);
    }
    // set the parent if its specified
    if (parentProfile != null) {
        builder.addParent(parentProfile.getId());
    }
    Map<String, String> config = builder.getConfiguration(MQ_CONNECTION_FACTORY_PID);
    config.put(GROUP, group);
    builder.addConfiguration(MQ_CONNECTION_FACTORY_PID, config);
    Profile profile = builder.getProfile();
    return create ? profileService.createProfile(profile) : profileService.updateProfile(profile);
}
Also used : Version(io.fabric8.api.Version) ProfileBuilder(io.fabric8.api.ProfileBuilder) Profile(io.fabric8.api.Profile)

Example 23 with ProfileBuilder

use of io.fabric8.api.ProfileBuilder in project fabric8 by jboss-fuse.

the class AbstractProfileManagementTest method testCreateVersion.

@Test
public void testCreateVersion() throws Exception {
    ProfileBuilder pbDefault = ProfileBuilder.Factory.create("1.1", "default");
    Profile prfDefault = pbDefault.addConfiguration("pidA", Collections.singletonMap("keyA", "valA")).getProfile();
    ProfileBuilder pbA11 = ProfileBuilder.Factory.create("1.1", "prfA");
    Profile prfA = pbA11.addConfiguration("pidA", Collections.singletonMap("keyA", "valA")).getProfile();
    VersionBuilder vb11 = VersionBuilder.Factory.create("1.1").addProfile(prfDefault).addProfile(prfA);
    try {
        VersionState v11 = getProxy().createVersion(new VersionState(vb11.getVersion()));
        Assert.assertEquals("1.1", v11.getId());
        Assert.assertTrue(v11.getAttributes().isEmpty());
        Assert.assertEquals("valA", v11.getProfileState("prfA").getConfiguration("pidA").get("keyA"));
    } finally {
        getProxy().deleteVersion("1.1");
    }
}
Also used : VersionBuilder(io.fabric8.api.VersionBuilder) ProfileBuilder(io.fabric8.api.ProfileBuilder) Profile(io.fabric8.api.Profile) VersionState(io.fabric8.api.mxbean.VersionState) Test(org.junit.Test)

Example 24 with ProfileBuilder

use of io.fabric8.api.ProfileBuilder in project fabric8 by jboss-fuse.

the class FabricCommand method getProfiles.

/**
 * Gets (or creates) all the profiles for the given names.
 * <p/>
 * <b>Important:</b> If a profile does not already exists with the given name, then a new {@link Profile} is
 * created and returned in the list.
 *
 * @see #getExistingProfiles(io.fabric8.api.FabricService, io.fabric8.api.Version, java.util.List)
 */
public static Profile[] getProfiles(FabricService fabricService, Version version, List<String> names) {
    List<Profile> allProfiles = version.getProfiles();
    List<Profile> profiles = new ArrayList<>();
    if (names == null) {
        return new Profile[0];
    }
    for (String profileId : names) {
        Profile profile = null;
        for (Profile p : allProfiles) {
            if (profileId.equals(p.getId())) {
                profile = p;
                break;
            }
        }
        if (profile == null) {
            ProfileBuilder builder = ProfileBuilder.Factory.create(version.getId(), profileId);
            ProfileService profileService = fabricService.adapt(ProfileService.class);
            profile = profileService.createProfile(builder.getProfile());
        }
        profiles.add(profile);
    }
    return profiles.toArray(new Profile[profiles.size()]);
}
Also used : ProfileService(io.fabric8.api.ProfileService) ArrayList(java.util.ArrayList) ProfileBuilder(io.fabric8.api.ProfileBuilder) Profile(io.fabric8.api.Profile)

Example 25 with ProfileBuilder

use of io.fabric8.api.ProfileBuilder in project fabric8 by jboss-fuse.

the class DataStoreBootstrapTemplate method doWith.

@Override
public void doWith(ProfileRegistry profileRegistry, DataStore dataStore) throws Exception {
    String versionId = options.getVersion();
    int minimumPort = options.getMinimumPort();
    int maximumPort = options.getMaximumPort();
    String zooKeeperServerHost = options.getBindAddress();
    int zooKeeperServerPort = options.getZooKeeperServerPort();
    int zooKeeperServerConnectionPort = options.getZooKeeperServerConnectionPort();
    int mappedPort = Ports.mapPortToRange(zooKeeperServerPort, minimumPort, maximumPort);
    CuratorFramework curator = null;
    try {
        curator = createCuratorFramework(connectionUrl, options);
        curator.start();
        curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
        LockHandle writeLock = profileRegistry.aquireWriteLock();
        try {
            // Make the import path absolute
            File importPath = new File(options.getImportPath());
            if (!importPath.isAbsolute()) {
                importPath = new File(homeDir, options.getImportPath());
            }
            // Import data into the DataStore
            if (options.isAutoImportEnabled()) {
                if (importPath.isDirectory()) {
                    profileRegistry.importFromFileSystem(importPath.getAbsolutePath());
                } else {
                    LOGGER.warn("Profile import dir does not exist: {}", importPath);
                }
            }
            // set the fabric configuration
            ZooKeeperUtils.setData(curator, ZkPath.CONFIG_DEFAULT_VERSION.getPath(), versionId);
            // Default JAAS config
            Map<String, String> jaasConfig = Collections.singletonMap("encryption.enabled", "${zk:/fabric/authentication/encryption.enabled}");
            // Default Zookeeper config
            Properties zkProps = new Properties();
            zkProps.setProperty("zookeeper.url", "${zk:" + ZkPath.CONFIG_ENSEMBLE_URL.getPath() + "}");
            zkProps.setProperty("zookeeper.password", "${zk:" + ZkPath.CONFIG_ENSEMBLE_PASSWORD.getPath() + "}");
            // Create or update default profile
            Profile defaultProfile = profileRegistry.getProfile(versionId, "default");
            if (defaultProfile == null) {
                ProfileBuilder prfBuilder = ProfileBuilder.Factory.create(versionId, "default");
                prfBuilder.addConfiguration("io.fabric8.jaas", jaasConfig);
                prfBuilder.addFileConfiguration("io.fabric8.zookeeper.properties", DataStoreUtils.toBytes(zkProps));
                Profile profile = prfBuilder.getProfile();
                if (profileRegistry.hasVersion(versionId)) {
                    profileRegistry.createProfile(profile);
                } else {
                    VersionBuilder verBuilder = VersionBuilder.Factory.create(versionId);
                    Version version = verBuilder.addProfile(profile).getVersion();
                    profileRegistry.createVersion(version);
                }
            } else {
                ProfileBuilder builder = ProfileBuilder.Factory.createFrom(defaultProfile);
                // be careful not to mess with existing *.properties files - for better "diffability"
                // during git-based patching
                Map<String, String> existingJaasConfig = builder.getConfiguration("io.fabric8.jaas");
                Map<String, String> existingZkConfig = builder.getConfiguration("io.fabric8.zookeeper");
                existingJaasConfig.putAll(jaasConfig);
                existingZkConfig.put("zookeeper.url", zkProps.getProperty("zookeeper.url"));
                existingZkConfig.put("zookeeper.password", zkProps.getProperty("zookeeper.password"));
                builder.addConfiguration("io.fabric8.jaas", existingJaasConfig);
                builder.addConfiguration("io.fabric8.zookeeper", existingZkConfig);
                profileRegistry.updateProfile(builder.getProfile());
            }
            ZooKeeperUtils.setData(curator, ZkPath.CONFIG_ENSEMBLE_URL.getPath(), "${zk:" + name + "/ip}:" + zooKeeperServerConnectionPort);
            ZooKeeperUtils.setData(curator, ZkPath.CONFIG_ENSEMBLE_PASSWORD.getPath(), PasswordEncoder.encode(options.getZookeeperPassword()));
            // Ensemble properties
            Properties ensembleProps = new Properties();
            ensembleProps.put("tickTime", String.valueOf(options.getZooKeeperServerTickTime()));
            ensembleProps.put("initLimit", String.valueOf(options.getZooKeeperServerInitLimit()));
            ensembleProps.put("syncLimit", String.valueOf(options.getZooKeeperServerSyncLimit()));
            ensembleProps.put("snapRetainCount", String.valueOf(options.getZookeeperSnapRetainCount()));
            ensembleProps.put("purgeInterval", String.valueOf(options.getZookeeperPurgeInterval()));
            ensembleProps.put("dataDir", options.getZooKeeperServerDataDir() + File.separator + "0000");
            loadPropertiesFrom(ensembleProps, importPath + "/fabric/profiles/default.profile/io.fabric8.zookeeper.server.properties");
            // Create ensemble profile
            String profileId = "fabric-ensemble-0000";
            IllegalStateAssertion.assertFalse(profileRegistry.hasProfile(versionId, profileId), "Profile already exists: " + versionId + "/" + profileId);
            ProfileBuilder ensembleProfileBuilder = ProfileBuilder.Factory.create(versionId, profileId);
            ensembleProfileBuilder.addAttribute(Profile.ABSTRACT, "true").addAttribute(Profile.HIDDEN, "true");
            ensembleProfileBuilder.addFileConfiguration("io.fabric8.zookeeper.server-0000.properties", DataStoreUtils.toBytes(ensembleProps));
            String ensembleProfileId = profileRegistry.createProfile(ensembleProfileBuilder.getProfile());
            // Ensemble server properties
            Properties serverProps = new Properties();
            serverProps.put("clientPort", String.valueOf(mappedPort));
            serverProps.put("clientPortAddress", zooKeeperServerHost);
            // Create ensemble server profile
            profileId = "fabric-ensemble-0000-1";
            IllegalStateAssertion.assertFalse(profileRegistry.hasProfile(versionId, profileId), "Profile already exists: " + versionId + "/" + profileId);
            ProfileBuilder serverProfileBuilder = ProfileBuilder.Factory.create(versionId, profileId);
            serverProfileBuilder.addAttribute(Profile.HIDDEN, "true").addAttribute(Profile.PARENTS, ensembleProfileId);
            serverProfileBuilder.addFileConfiguration("io.fabric8.zookeeper.server-0000.properties", DataStoreUtils.toBytes(serverProps));
            profileRegistry.createProfile(serverProfileBuilder.getProfile());
            ZooKeeperUtils.setData(curator, ZkPath.CONFIG_ENSEMBLES.getPath(), "0000");
            ZooKeeperUtils.setData(curator, ZkPath.CONFIG_ENSEMBLE.getPath("0000"), name);
            // configure fabric profile
            Profile fabricProfile = profileRegistry.getProfile(versionId, "fabric");
            if (fabricProfile == null) {
                ProfileBuilder builder = ProfileBuilder.Factory.create(versionId, "fabric");
                Properties agentProps = new Properties();
                agentProps.put("feature.fabric-commands", "fabric-commands");
                builder.addFileConfiguration("io.fabric8.agent.properties", DataStoreUtils.toBytes(agentProps));
                String createdId = profileRegistry.createProfile(builder.getProfile());
                fabricProfile = profileRegistry.getRequiredProfile(versionId, createdId);
            } else {
                ProfileBuilder builder = ProfileBuilder.Factory.createFrom(fabricProfile);
                Map<String, String> agentProps = builder.getConfiguration(Constants.AGENT_PID);
                agentProps.put("feature.fabric-commands", "fabric-commands");
                builder.addConfiguration(Constants.AGENT_PID, agentProps);
                String updatedId = profileRegistry.updateProfile(builder.getProfile());
                fabricProfile = profileRegistry.getRequiredProfile(versionId, updatedId);
            }
        } finally {
            writeLock.unlock();
        }
        ZooKeeperUtils.createDefault(curator, ZkPath.CONFIG_CONTAINER.getPath(name), versionId);
        StringBuilder profilesBuilder = new StringBuilder();
        Set<String> profiles = options.getProfiles();
        profilesBuilder.append("fabric").append(" ").append("fabric-ensemble-0000-1");
        for (String p : profiles) {
            if (!(p.equals("fabric") || p.equals("fabric-ensemble-0000-1"))) {
                profilesBuilder.append(" ").append(p);
            }
        }
        if (!options.isAgentEnabled()) {
            profilesBuilder.append(" ").append("unmanaged");
        }
        ZooKeeperUtils.createDefault(curator, ZkPath.CONFIG_VERSIONS_CONTAINER.getPath(versionId, name), profilesBuilder.toString());
        // outside of the profile storage area, so we'll keep these in zk
        EncryptionSupport encryption = addUsersToZookeeper(curator, options.getUsers());
        ZooKeeperUtils.createDefault(curator, "/fabric/authentication/encryption.enabled", Boolean.valueOf(encryption != null).toString());
        ZooKeeperUtils.createDefault(curator, "/fabric/authentication/domain", "karaf");
        ZooKeeperUtils.createDefault(curator, ZkPath.AUTHENTICATION_CRYPT_ALGORITHM.getPath(), "PBEWithMD5AndDES");
        ZooKeeperUtils.createDefault(curator, ZkPath.AUTHENTICATION_CRYPT_PASSWORD.getPath(), PasswordEncoder.encode(options.getZookeeperPassword()));
        // Ensure ACLs are from the beggining of the fabric tree.
        aclManager.fixAcl(curator, "/fabric", true);
    } finally {
        if (curator != null) {
            curator.close();
        }
    }
}
Also used : LockHandle(io.fabric8.api.LockHandle) Properties(java.util.Properties) ProfileBuilder(io.fabric8.api.ProfileBuilder) Profile(io.fabric8.api.Profile) CuratorFramework(org.apache.curator.framework.CuratorFramework) Version(io.fabric8.api.Version) VersionBuilder(io.fabric8.api.VersionBuilder) File(java.io.File) EncryptionSupport(org.apache.karaf.jaas.modules.encryption.EncryptionSupport)

Aggregations

ProfileBuilder (io.fabric8.api.ProfileBuilder)35 Profile (io.fabric8.api.Profile)33 Version (io.fabric8.api.Version)12 ProfileService (io.fabric8.api.ProfileService)4 GitVersion (io.fabric8.api.commands.GitVersion)3 Test (org.junit.Test)3 VersionBuilder (io.fabric8.api.VersionBuilder)2 ProjectRequirements (io.fabric8.deployer.dto.ProjectRequirements)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DownloadManager (io.fabric8.agent.download.DownloadManager)1 Feature (io.fabric8.agent.model.Feature)1 FabricException (io.fabric8.api.FabricException)1 FabricRequirements (io.fabric8.api.FabricRequirements)1 FabricService (io.fabric8.api.FabricService)1 LockHandle (io.fabric8.api.LockHandle)1 ProfileRegistry (io.fabric8.api.ProfileRegistry)1 ProfileRequirements (io.fabric8.api.ProfileRequirements)1 ProfileState (io.fabric8.api.mxbean.ProfileState)1