Search in sources :

Example 31 with Config

use of io.fabric8.kubernetes.api.model.Config in project fabric8 by jboss-fuse.

the class MavenResolvers method createMavenResolver.

public static MavenResolver createMavenResolver(Mirror mirror, Dictionary<String, String> properties, String pid, RepositorySystem repositorySystem) {
    PropertiesPropertyResolver syspropsResolver = new PropertiesPropertyResolver(System.getProperties());
    DictionaryPropertyResolver propertyResolver = new DictionaryPropertyResolver(properties, syspropsResolver);
    MavenConfigurationImpl config = new MavenConfigurationImpl(propertyResolver, pid);
    return new AetherBasedResolver(config, mirror, repositorySystem);
}
Also used : MavenConfigurationImpl(io.fabric8.maven.util.MavenConfigurationImpl) PropertiesPropertyResolver(org.ops4j.util.property.PropertiesPropertyResolver) DictionaryPropertyResolver(org.ops4j.util.property.DictionaryPropertyResolver) AetherBasedResolver(io.fabric8.maven.url.internal.AetherBasedResolver)

Example 32 with Config

use of io.fabric8.kubernetes.api.model.Config in project fabric8 by jboss-fuse.

the class EnsemblePasswordAction method doExecute.

@Override
protected Object doExecute() throws Exception {
    if (!commit) {
        if (newPassword == null) {
            System.out.println(fabricService.getZookeeperPassword());
        } else {
            String zookeeperUrl = fabricService.getZookeeperUrl();
            String oldPassword = fabricService.getZookeeperPassword();
            System.out.println("Updating the password...");
            // Since we will be changing the password, create a new ZKClient that won't
            // be getting update by the password change.
            CuratorACLManager aclManager = new CuratorACLManager();
            CuratorFramework curator = CuratorFrameworkFactory.builder().connectString(zookeeperUrl).retryPolicy(new RetryOneTime(500)).aclProvider(aclManager).authorization("digest", ("fabric:" + oldPassword).getBytes()).sessionTimeoutMs(30000).build();
            curator.start();
            try {
                // Lets first adjust the acls so that the new password and old passwords work against the ZK paths.
                String digestedIdPass = DigestAuthenticationProvider.generateDigest("fabric:" + newPassword);
                aclManager.registerAcl("/fabric", "auth::acdrw,world:anyone:,digest:" + digestedIdPass + ":acdrw");
                aclManager.fixAcl(curator, "/fabric", true);
                // Ok now lets push out a config update of what the password is.
                curator.setData().forPath(ZkPath.CONFIG_ENSEMBLE_PASSWORD.getPath(), PasswordEncoder.encode(newPassword).getBytes(Charsets.UTF_8));
            } finally {
                curator.close();
            }
            // Refresh the default profile to cause all nodes to pickup the new password.
            ProfileService profileService = fabricService.adapt(ProfileService.class);
            for (String ver : profileService.getVersions()) {
                Version version = profileService.getVersion(ver);
                if (version != null) {
                    Profile profile = version.getProfile("default");
                    if (profile != null) {
                        Profiles.refreshProfile(fabricService, profile);
                    }
                }
            }
            System.out.println("");
            System.out.println("Password updated. Please wait a little while for the new password to");
            System.out.println("get delivered as a config update to all the fabric nodes. Once, the ");
            System.out.println("nodes all updated (nodes must be online), please run:");
            System.out.println("");
            System.out.println("  fabric:ensemble-password --commit ");
            System.out.println("");
        }
    } else {
        // Now lets connect with the new password and reset the ACLs so that the old password
        // does not work anymore.
        CuratorACLManager aclManager = new CuratorACLManager();
        CuratorFramework curator = CuratorFrameworkFactory.builder().connectString(fabricService.getZookeeperUrl()).retryPolicy(new RetryOneTime(500)).aclProvider(aclManager).authorization("digest", ("fabric:" + fabricService.getZookeeperPassword()).getBytes()).sessionTimeoutMs(30000).build();
        curator.start();
        try {
            aclManager.fixAcl(curator, "/fabric", true);
            System.out.println("Only the current password is allowed access to fabric now.");
        } finally {
            curator.close();
        }
    }
    return null;
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) RetryOneTime(org.apache.curator.retry.RetryOneTime) CuratorACLManager(io.fabric8.zookeeper.curator.CuratorACLManager)

Example 33 with Config

use of io.fabric8.kubernetes.api.model.Config in project fabric8 by jboss-fuse.

the class MavenProxyServletSupportTest method createResolver.

private MavenResolver createResolver(String localRepo, List<String> remoteRepos, String proxyProtocol, String proxyHost, int proxyPort, String proxyUsername, String proxyPassword, String proxyNonProxyHosts) {
    Hashtable<String, String> props = new Hashtable<>();
    props.put("localRepository", localRepo);
    if (remoteRepos != null) {
        props.put("repositories", join(remoteRepos, ","));
    }
    MavenConfigurationImpl config = new MavenConfigurationImpl(new DictionaryPropertyResolver(props), null);
    if (proxyProtocol != null) {
        Proxy proxy = new Proxy();
        proxy.setProtocol(proxyProtocol);
        proxy.setHost(proxyHost);
        proxy.setPort(proxyPort);
        proxy.setUsername(proxyUsername);
        proxy.setPassword(proxyPassword);
        proxy.setNonProxyHosts(proxyNonProxyHosts);
        config.getSettings().addProxy(proxy);
    }
    return new AetherBasedResolver(config);
}
Also used : MavenConfigurationImpl(io.fabric8.maven.util.MavenConfigurationImpl) Proxy(org.apache.maven.settings.Proxy) Hashtable(java.util.Hashtable) DictionaryPropertyResolver(org.ops4j.util.property.DictionaryPropertyResolver) AetherBasedResolver(io.fabric8.maven.url.internal.AetherBasedResolver)

Example 34 with Config

use of io.fabric8.kubernetes.api.model.Config in project fabric8 by jboss-fuse.

the class FeatureConfigInstaller method installFeatureConfigs.

void installFeatureConfigs(Feature feature) throws IOException, InvalidSyntaxException {
    for (Config config : feature.getConfigurations()) {
        Properties props = config.getProperties();
        String[] split = parsePid(config.getName());
        // see http://felix.apache.org/documentation/subprojects/apache-felix-file-install.html#configurations
        String pid = split[0];
        String subname = split[1];
        Configuration cfg = findExistingConfiguration(configAdmin, pid, subname);
        if (cfg == null) {
            Dictionary<String, String> cfgProps = convertToDict(props);
            cfg = createConfiguration(configAdmin, pid, subname);
            String key = createConfigurationKey(pid, subname);
            cfgProps.put(CONFIG_KEY, key);
            cfg.update(cfgProps);
        } else if (config.isAppend()) {
            Dictionary<String, Object> properties = cfg.getProperties();
            // Ignore already managed configurations
            String fabricManagedPid = (String) properties.get(FABRIC_ZOOKEEPER_PID);
            if (Strings.isNotBlank(fabricManagedPid)) {
                continue;
            }
            for (Enumeration<String> propKeys = properties.keys(); propKeys.hasMoreElements(); ) {
                String key = propKeys.nextElement();
                // remove existing entry, since it's about appending.
                if (props.containsKey(key)) {
                    props.remove(key);
                }
            }
            if (props.size() > 0) {
                // convert props to dictionary
                Dictionary<String, String> cfgProps = convertToDict(props);
                cfg.update(cfgProps);
            }
        }
    }
    for (ConfigFile configFile : feature.getConfigurationFiles()) {
        installConfigurationFile(configFile.getLocation(), configFile.getFinalname(), configFile.isOverride());
    }
}
Also used : Dictionary(java.util.Dictionary) Enumeration(java.util.Enumeration) Configuration(org.osgi.service.cm.Configuration) ConfigFile(io.fabric8.agent.model.ConfigFile) Config(io.fabric8.agent.model.Config) Properties(java.util.Properties)

Example 35 with Config

use of io.fabric8.kubernetes.api.model.Config in project fabric8 by jboss-fuse.

the class DeployToProfileMojo method execute.

@Override
public void execute() throws MojoExecutionException, MojoFailureException {
    if (isIgnoreProject())
        return;
    try {
        ProjectRequirements requirements = new ProjectRequirements();
        if (isIncludeArtifact()) {
            DependencyDTO rootDependency = loadRootDependency();
            requirements.setRootDependency(rootDependency);
        }
        configureRequirements(requirements);
        // validate requirements
        if (requirements.getProfileId() != null) {
            // make sure the profile id is a valid name
            FabricValidations.validateProfileName(requirements.getProfileId());
        }
        boolean newUserAdded = false;
        fabricServer = mavenSettings.getServer(serverId);
        // we may have username and password from jolokiaUrl
        String jolokiaUsername = null;
        String jolokiaPassword = null;
        try {
            URL url = new URL(jolokiaUrl);
            String s = url.getUserInfo();
            if (Strings.isNotBlank(s) && s.indexOf(':') > 0) {
                int idx = s.indexOf(':');
                jolokiaUsername = s.substring(0, idx);
                jolokiaPassword = s.substring(idx + 1);
                customUsernameAndPassword = true;
            }
        } catch (MalformedURLException e) {
            throw new IllegalArgumentException("Option jolokiaUrl is invalid due " + e.getMessage());
        }
        // jolokia url overrides username/password configured in maven settings
        if (jolokiaUsername != null) {
            if (fabricServer == null) {
                fabricServer = new Server();
            }
            getLog().info("Using username: " + jolokiaUsername + " and password from provided jolokiaUrl option");
            fabricServer.setId(serverId);
            fabricServer.setUsername(jolokiaUsername);
            fabricServer.setPassword(jolokiaPassword);
        }
        if (fabricServer == null) {
            boolean create = false;
            if (mavenSettings.isInteractiveMode() && mavenSettingsWriter != null) {
                System.out.println("Maven settings file: " + mavenSettingsFile.getAbsolutePath());
                System.out.println();
                System.out.println();
                System.out.println("There is no <server> section in your ~/.m2/settings.xml file for the server id: " + serverId);
                System.out.println();
                System.out.println("You can enter the username/password now and have the settings.xml updated or you can do this by hand if you prefer.");
                System.out.println();
                while (true) {
                    String value = readInput("Would you like to update the settings.xml file now? (y/n): ").toLowerCase();
                    if (value.startsWith("n")) {
                        System.out.println();
                        System.out.println();
                        break;
                    } else if (value.startsWith("y")) {
                        create = true;
                        break;
                    }
                }
                if (create) {
                    System.out.println("Please let us know the login details for this server: " + serverId);
                    System.out.println();
                    String userName = readInput("Username: ");
                    String password = readPassword("Password: ");
                    String password2 = readPassword("Repeat Password: ");
                    while (!password.equals(password2)) {
                        System.out.println("Passwords do not match, please try again.");
                        password = readPassword("Password: ");
                        password2 = readPassword("Repeat Password: ");
                    }
                    System.out.println();
                    fabricServer = new Server();
                    fabricServer.setId(serverId);
                    fabricServer.setUsername(userName);
                    fabricServer.setPassword(password);
                    mavenSettings.addServer(fabricServer);
                    if (mavenSettingsFile.exists()) {
                        int counter = 1;
                        while (true) {
                            File backupFile = new File(mavenSettingsFile.getAbsolutePath() + ".backup-" + counter++ + ".xml");
                            if (!backupFile.exists()) {
                                System.out.println("Copied original: " + mavenSettingsFile.getAbsolutePath() + " to: " + backupFile.getAbsolutePath());
                                Files.copy(mavenSettingsFile, backupFile);
                                break;
                            }
                        }
                    }
                    Map<String, Object> config = new HashMap<String, Object>();
                    mavenSettingsWriter.write(mavenSettingsFile, config, mavenSettings);
                    System.out.println("Updated settings file: " + mavenSettingsFile.getAbsolutePath());
                    System.out.println();
                    newUserAdded = true;
                }
            }
        }
        if (fabricServer == null) {
            String message = "No <server> element can be found in ~/.m2/settings.xml for the server <id>" + serverId + "</id> so we cannot connect to fabric8!\n\n" + "Please add the following to your ~/.m2/settings.xml file (using the correct user/password values):\n\n" + "<servers>\n" + "  <server>\n" + "    <id>" + serverId + "</id>\n" + "    <username>admin</username>\n" + "    <password>admin</password>\n" + "  </server>\n" + "</servers>\n";
            getLog().error(message);
            throw new MojoExecutionException(message);
        }
        // now lets invoke the mbean
        J4pClient client = createJolokiaClient();
        if (upload) {
            uploadDeploymentUnit(client, newUserAdded || customUsernameAndPassword);
        } else {
            getLog().info("Uploading to the fabric8 maven repository is disabled");
        }
        DeployResults results = uploadRequirements(client, requirements);
        if (results != null) {
            uploadReadMeFile(client, results);
            uploadProfileConfigurations(client, results);
            refreshProfile(client, results);
        }
    } catch (MojoExecutionException e) {
        throw e;
    } catch (Exception e) {
        throw new MojoExecutionException("Error executing", e);
    }
}
Also used : MalformedURLException(java.net.MalformedURLException) DeployResults(io.fabric8.deployer.dto.DeployResults) Server(org.apache.maven.settings.Server) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) HashMap(java.util.HashMap) J4pClient(org.jolokia.client.J4pClient) DependencyDTO(io.fabric8.deployer.dto.DependencyDTO) URL(java.net.URL) MalformedObjectNameException(javax.management.MalformedObjectNameException) J4pRemoteException(org.jolokia.client.exception.J4pRemoteException) ArtifactDeploymentException(org.apache.maven.artifact.deployer.ArtifactDeploymentException) J4pConnectException(org.jolokia.client.exception.J4pConnectException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) J4pException(org.jolokia.client.exception.J4pException) ProjectRequirements(io.fabric8.deployer.dto.ProjectRequirements) File(java.io.File)

Aggregations

Test (org.junit.Test)106 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)37 HashMap (java.util.HashMap)34 IOException (java.io.IOException)32 ResourceConfig (io.fabric8.maven.core.config.ResourceConfig)28 File (java.io.File)26 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)24 Map (java.util.Map)24 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)23 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)21 Expectations (mockit.Expectations)20 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)17 ArrayList (java.util.ArrayList)17 VolumeConfig (io.fabric8.maven.core.config.VolumeConfig)15 AbstractConfigHandlerTest (io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)15 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)14 AuthConfig (io.fabric8.maven.docker.access.AuthConfig)13 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)12 Before (org.junit.Before)12 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)11