Package io.fabric8.api

Examples of io.fabric8.api.Profile


    }

    @Override
    public String getConfigurationValue(String versionId, String profileId, String pid, String key) {
        assertValid();
        Profile pr = profileService.get().getRequiredProfile(versionId, profileId);
        Map<String, byte[]> configs = pr.getFileConfigurations();

        byte[] b = configs.get(pid);

        Properties p = null;
        try {
View Full Code Here


    @Override
    public void setConfigurationValue(String versionId, String profileId, String pid, String key, String value) {
        assertValid();
        Version version = profileService.get().getRequiredVersion(versionId);
        Profile profile = version.getRequiredProfile(profileId);
       
        Map<String, byte[]> configs = profile.getFileConfigurations();
        byte[] bytes = configs.get(pid);
        Properties properties;
        if (bytes != null) {
            properties = DataStoreUtils.toProperties(bytes);
        } else {
View Full Code Here

        List<Profile> profiles = new ArrayList<Profile>();
        for (String profileId : profileIds) {
            profiles.add(version.getRequiredProfile(profileId));
        }
        if (profiles.isEmpty() && version != null) {
            Profile defaultProfile = version.getProfile(ZkDefs.DEFAULT_PROFILE);
            if (defaultProfile != null) {
                profiles.add(defaultProfile);
            }
        }
        return profiles.toArray(new Profile[profiles.size()]);
View Full Code Here

    public void removeProfiles(String... profileIds) {
        List<String> removedProfiles = Arrays.asList(profileIds);
        List<Profile> updatedProfileList = new LinkedList<>();
        for (String profileId : dataStore.getContainerProfiles(id)) {
            if (!removedProfiles.contains(profileId)) {
                Profile profile = getVersion().getProfile(profileId);
                if (profile != null) {
                    updatedProfileList.add(profile);
                }
            }
        }
View Full Code Here

        boolean requiresUpgrade = false;
        if (version.getId().compareTo(getVersionId()) == 0) {
            return false;
        }
        for (Profile oldProfile : getProfiles()) {
            Profile newProfile = version.getProfile(oldProfile.getId());
            if (newProfile != null && !Profiles.agentConfigurationEquals(fabricService, oldProfile, newProfile)) {
                requiresUpgrade = true;
                break;
            }
        }
View Full Code Here

    }

    @Override
    protected Object doExecute() throws Exception {
        Version version = versionId != null ? profileService.getRequiredVersion(versionId) : fabricService.getRequiredDefaultVersion();
        Profile profile = version.getRequiredProfile(profileId);
       
        // we can only change parents to existing profiles
        Profile[] parents = FabricCommand.getExistingProfiles(fabricService, version, parentIds);
        ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile);
        for (Profile parent : parents) {
View Full Code Here

        Map<String,Parser> artifacts = new HashMap<String, Parser>();
        for (String location : locations) {
            try {
                if (location.contains("$")) {
                    ProfileService profileService = fabricService.adapt(ProfileService.class);
                    Profile overlay = profileService.getOverlayProfile(profile);
          location = VersionPropertyPointerResolver.replaceVersions(fabricService, overlay.getConfigurations(), location);
                }
                if (location.startsWith("mvn:") || location.contains(":mvn:")) {
                    Parser parser = Parser.parsePathWithSchemePrefix(location);
                    artifacts.put(location, parser);
                } else {
View Full Code Here

        }
        if (Strings.isNullOrBlank(parentProfileName)) {
            parentProfileName = replicated ? MQ_PROFILE_REPLICATED : MQ_PROFILE_BASE;
        }
       
        Profile parentProfile = version.getRequiredProfile(parentProfileName);
        if (brokerName == null || profileId == null) {
            return parentProfile;
        }
       
        String pidName = getBrokerPID(brokerName);
        // lets check we have a config value

        ProfileBuilder builder;
       
        // create a profile if it doesn't exist
        Map<String, String> config = null;
        boolean create = !version.hasProfile(profileId);
        if (create) {
            builder = ProfileBuilder.Factory.create(versionId, profileId);
            if (parentProfile != null) {
                builder.addParent(parentProfile.getId());
            }
        } else {
            Profile profile = version.getRequiredProfile(profileId);
            builder = ProfileBuilder.Factory.createFrom(profile);
            config = new HashMap<>(builder.getConfiguration(pidName));
        }
       
        Map<String, String> parentProfileConfig = parentProfile.getConfiguration(MQ_PID_TEMPLATE);
        if (config == null) {
            config = new HashMap<>(parentProfileConfig);
        }

        if (configs != null && "true".equals(configs.get("ssl"))) {

            // Only generate the keystore file if it does not exist.
            // [TOOD] Fix direct data access! This should be part of the ProfileBuilder
            byte[] keystore  = builder.getFileConfiguration("keystore.jks");
            if( keystore==null ) {
                try {

                    String host = configs.get("keystore.cn");
                    if( host == null ) {
                        host = configs.get(GROUP);
                        if( host == null ) {
                            host = "localhost";
                        }
                        configs.put("keystore.cn", host);
                    }
                    String password = configs.get("keystore.password");
                    if( password == null ) {
                        password = generatePassword(8);
                        configs.put("keystore.password", password);
                    }

                    File keystoreFile = io.fabric8.utils.Files.createTempFile(runtimeProperties.getDataPath());
                    keystoreFile.delete();
                    LOG.info("Generating ssl keystore...");
                    int rc = system("keytool", "-genkey",
                            "-storetype", "JKS",
                            "-storepass", password,
                            "-keystore", keystoreFile.getCanonicalPath(),
                            "-keypass", password,
                            "-alias", host,
                            "-keyalg", "RSA",
                            "-keysize", "4096",
                            "-dname", String.format("cn=%s", host),
                            "-validity", "3650");

                    if(rc!=0) {
                      throw new IOException("keytool failed with exit code: "+rc);
                    }

                    keystore = Files.readBytes(keystoreFile);
                    keystoreFile.delete();
                    LOG.info("Keystore generated");

                    builder.addFileConfiguration("keystore.jks", keystore);
                    configs.put("keystore.file", "profile:keystore.jks");

                } catch (IOException e) {
                    LOG.info("Failed to generate keystore.jks: "+e, e);
                }

            }

            // [TOOD] Fix direct data access! This should be part of the ProfileBuilder
            byte[] truststore = builder.getFileConfiguration("truststore.jks");
            if (truststore == null) {
               try {
                    String password = configs.get("truststore.password");
                    if( password == null ) {
                        password = configs.get("keystore.password");
                        configs.put("truststore.password", password);
                    }

                    File keystoreFile = io.fabric8.utils.Files.createTempFile(runtimeProperties.getDataPath());
                    Files.writeToFile(keystoreFile, keystore);

                    File certFile = io.fabric8.utils.Files.createTempFile(runtimeProperties.getDataPath());
                    certFile.delete();

                    LOG.info("Exporting broker certificate to create truststore.jks");
                    int rc = system("keytool", "-exportcert", "-rfc",
                            "-keystore", keystoreFile.getCanonicalPath(),
                            "-storepass", configs.get("keystore.password"),
                            "-alias",  configs.get("keystore.cn"),
                            "--file", certFile.getCanonicalPath());

                    keystoreFile.delete();
                    if(rc!=0) {
                      throw new IOException("keytool failed with exit code: "+rc);
                    }

                    LOG.info("Creating truststore.jks");
                    File truststoreFile = io.fabric8.utils.Files.createTempFile(runtimeProperties.getDataPath());
                    truststoreFile.delete();
                    rc = system("keytool", "-importcert", "-noprompt",
                            "-keystore", truststoreFile.getCanonicalPath(),
                            "-storepass", password,
                            "--file", certFile.getCanonicalPath());
                    certFile.delete();
                    if(rc!=0) {
                      throw new IOException("keytool failed with exit code: "+rc);
                    }

                    truststore = Files.readBytes(truststoreFile);
                    truststoreFile.delete();
                   
                    builder.addFileConfiguration("truststore.jks", truststore);
                    configs.put("truststore.file", "profile:truststore.jks");

                } catch (IOException e) {
                    LOG.info("Failed to generate truststore.jks due: " + e.getMessage(), e);
                }
            }
        }

        config.put("broker-name", brokerName);
        if (configs != null) {
            config.putAll(configs);
        }

        // lets check we've a bunch of config values inherited from the template
        String[] propertiesToDefault = { CONFIG_URL, STANDBY_POOL, CONNECTORS };
        for (String key : propertiesToDefault) {
            if (config.get(key) == null) {
                String defaultValue = parentProfileConfig.get(key);
                if (Strings.isNotBlank(defaultValue)) {
                    config.put(key, defaultValue);
                }
            }
        }
       
        builder.addConfiguration(pidName, config);
        Profile profile = builder.getProfile();
        return create ? profileService.createProfile(profile) : profileService.updateProfile(profile);
    }
View Full Code Here

    public Map<String, String> getEnsembleConfiguration() throws Exception {
        String clusterId = getStringData(curator.get(), ZkPath.CONFIG_ENSEMBLES.getPath());
        String versionId = dataStore.get().getDefaultVersion();
        String profileId = "fabric-ensemble-" + clusterId;
        String ensembleConfigName = "io.fabric8.zookeeper.server-" + clusterId + ".properties";
        Profile ensembleProfile = profileRegistry.get().getRequiredProfile(versionId, profileId);
        Map<String, byte[]> fileconfigs = ensembleProfile.getFileConfigurations();
        return DataStoreUtils.toMap(fileconfigs.get(ensembleConfigName));
     }
View Full Code Here

    @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 = config != null ? new HashMap<>(config) : new HashMap<String, String>();
        config.put(GROUP, group);
        builder.addConfiguration(MQ_CONNECTION_FACTORY_PID, config);
       
        Profile profile = builder.getProfile();
        return create ? profileService.createProfile(profile) : profileService.updateProfile(profile);
    }
View Full Code Here

TOP

Related Classes of io.fabric8.api.Profile

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.