Search in sources :

Example 6 with ProfileRegistry

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

the class FabricPatchServiceImpl method synchronize.

@Override
public String synchronize(final boolean verbose) throws Exception {
    final String[] remoteUrl = new String[] { null };
    patchManagement.pushPatchInfo(verbose);
    GitOperation operation = new GitOperation() {

        @Override
        public Object call(Git git, GitContext context) throws Exception {
            ProfileRegistry registry = fabricService.adapt(ProfileRegistry.class);
            Map<String, String> properties = registry.getDataStoreProperties();
            String username;
            String password;
            if (properties != null && properties.containsKey("gitRemoteUser") && properties.containsKey("gitRemotePassword")) {
                username = properties.get("gitRemoteUser");
                password = properties.get("gitRemotePassword");
            } else {
                username = ZooKeeperUtils.getContainerLogin(runtimeProperties);
                password = ZooKeeperUtils.generateContainerToken(runtimeProperties, curator);
            }
            remoteUrl[0] = git.getRepository().getConfig().getString("remote", "origin", "url");
            Iterable<PushResult> results = git.push().setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, password)).setPushTags().setPushAll().call();
            logPushResult(results, git.getRepository(), verbose);
            return null;
        }
    };
    try {
        gitDataStore.gitOperation(new GitContext(), operation, null);
    } catch (FabricException e) {
        if (e.getCause() != null && e.getCause() instanceof TransportException) {
            LOG.warn("Problem when synchronizing patch information: " + e.getCause().getMessage());
        } else {
            throw e;
        }
    }
    return remoteUrl[0];
}
Also used : UsernamePasswordCredentialsProvider(org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider) GitOperation(io.fabric8.git.internal.GitOperation) Git(org.eclipse.jgit.api.Git) GitContext(io.fabric8.api.GitContext) FabricException(io.fabric8.api.FabricException) ProfileRegistry(io.fabric8.api.ProfileRegistry) PushResult(org.eclipse.jgit.transport.PushResult) TransportException(org.eclipse.jgit.api.errors.TransportException)

Example 7 with ProfileRegistry

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

the class AbstractContainerCreateAction method getDataStoreProperties.

protected Map<String, String> getDataStoreProperties() {
    ProfileRegistry profileRegistry = fabricService.adapt(ProfileRegistry.class);
    Map<String, String> options = new HashMap<String, String>(profileRegistry.getDataStoreProperties());
    if (dataStoreOption != null) {
        for (String opt : dataStoreOption) {
            String[] parts = opt.trim().split(" +");
            options.put(parts[0], parts[1]);
        }
    }
    return options;
}
Also used : HashMap(java.util.HashMap) ProfileRegistry(io.fabric8.api.ProfileRegistry)

Example 8 with ProfileRegistry

use of io.fabric8.api.ProfileRegistry 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)

Example 9 with ProfileRegistry

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

the class VersionEditAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    ProfileService profileService = fabricService.adapt(ProfileService.class);
    ProfileRegistry profileRegistry = fabricService.adapt(ProfileRegistry.class);
    Version version = profileService.getVersion(versionId);
    if (version == null) {
        System.err.println("Version " + versionId + " does not exist.");
        return null;
    }
    profileRegistry.modifyVersionDescription(version, description);
    return null;
}
Also used : ProfileService(io.fabric8.api.ProfileService) Version(io.fabric8.api.Version) ProfileRegistry(io.fabric8.api.ProfileRegistry)

Example 10 with ProfileRegistry

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

the class Provision method profileAvailable.

public static Boolean profileAvailable(BundleContext bundleContext, String profile, String version, Long timeout) throws Exception {
    FabricService fabricService = ServiceLocator.awaitService(bundleContext, FabricService.class);
    ProfileRegistry profileRegistry = fabricService.adapt(ProfileRegistry.class);
    for (long t = 0; (!profileRegistry.hasProfile(version, profile) && t < timeout); t += 2000L) {
        Thread.sleep(2000L);
    }
    return profileRegistry.hasProfile(version, profile);
}
Also used : FabricService(io.fabric8.api.FabricService) ProfileRegistry(io.fabric8.api.ProfileRegistry)

Aggregations

ProfileRegistry (io.fabric8.api.ProfileRegistry)8 File (java.io.File)3 FabricService (io.fabric8.api.FabricService)2 GitContext (io.fabric8.api.GitContext)2 Version (io.fabric8.api.Version)2 HashMap (java.util.HashMap)2 CuratorFramework (org.apache.curator.framework.CuratorFramework)2 Git (org.eclipse.jgit.api.Git)2 PushResult (org.eclipse.jgit.transport.PushResult)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DataStore (io.fabric8.api.DataStore)1 FabricException (io.fabric8.api.FabricException)1 LockHandle (io.fabric8.api.LockHandle)1 Profile (io.fabric8.api.Profile)1 ProfileBuilder (io.fabric8.api.ProfileBuilder)1 ProfileService (io.fabric8.api.ProfileService)1 RuntimeProperties (io.fabric8.api.RuntimeProperties)1 VersionBuilder (io.fabric8.api.VersionBuilder)1 ValidatingReference (io.fabric8.api.scr.ValidatingReference)1 ValidationSupport (io.fabric8.api.scr.ValidationSupport)1