Search in sources :

Example 11 with Config

use of io.fabric8.docker.client.Config in project fabric8 by jboss-fuse.

the class ProjectDeployerTest method setUp.

@Before
public void setUp() throws Exception {
    URL.setURLStreamHandlerFactory(new CustomBundleURLStreamHandlerFactory());
    basedir = System.getProperty("basedir", ".");
    String karafRoot = basedir + "/target/karaf";
    System.setProperty("karaf.root", karafRoot);
    System.setProperty("karaf.data", karafRoot + "/data");
    sfb = new ZKServerFactoryBean();
    delete(sfb.getDataDir());
    delete(sfb.getDataLogDir());
    sfb.setPort(9123);
    sfb.afterPropertiesSet();
    int zkPort = sfb.getClientPortAddress().getPort();
    LOG.info("Connecting to ZK on port: " + zkPort);
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString("localhost:" + zkPort).retryPolicy(new RetryOneTime(1000)).connectionTimeoutMs(360000);
    curator = builder.build();
    curator.start();
    curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
    // setup a local and remote git repo
    File root = new File(basedir + "/target/git").getCanonicalFile();
    delete(root);
    new File(root, "remote").mkdirs();
    remote = Git.init().setDirectory(new File(root, "remote")).setGitDir(new File(root, "remote/.git")).call();
    remote.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call();
    String remoteUrl = "file://" + new File(root, "remote").getCanonicalPath();
    new File(root, "local").mkdirs();
    git = Git.init().setDirectory(new File(root, "local")).setGitDir(new File(root, "local/.git")).call();
    git.commit().setMessage("First Commit").setCommitter("fabric", "user@fabric").call();
    StoredConfig config = git.getRepository().getConfig();
    config.setString("remote", "origin", "url", remoteUrl);
    config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*");
    config.save();
    runtimeProperties = EasyMock.createMock(RuntimeProperties.class);
    EasyMock.expect(runtimeProperties.getRuntimeIdentity()).andReturn("root").anyTimes();
    EasyMock.expect(runtimeProperties.getHomePath()).andReturn(Paths.get("target")).anyTimes();
    EasyMock.expect(runtimeProperties.getDataPath()).andReturn(Paths.get("target/data")).anyTimes();
    EasyMock.expect(runtimeProperties.getProperty(EasyMock.eq(SystemProperties.FABRIC_ENVIRONMENT))).andReturn("").anyTimes();
    EasyMock.expect(runtimeProperties.removeRuntimeAttribute(DataStoreTemplate.class)).andReturn(null).anyTimes();
    EasyMock.replay(runtimeProperties);
    FabricGitServiceImpl gitService = new FabricGitServiceImpl();
    gitService.bindRuntimeProperties(runtimeProperties);
    gitService.activate();
    gitService.setGitForTesting(git);
    /*
        dataStore = new GitDataStoreImpl();
        dataStore.bindCurator(curator);
        dataStore.bindGitService(gitService);
        dataStore.bindRuntimeProperties(runtimeProperties);
        dataStore.bindConfigurer(new Configurer() {
        

            @Override
            public <T> Map<String, ?> configure(Map<String, ?> configuration, T target, String... ignorePrefix) throws Exception {
                return null;
            }

            @Override
            public <T> Map<String, ?> configure(Dictionary<String, ?> configuration, T target, String... ignorePrefix) throws Exception {
                return null;
            }
        });
        Map<String, Object> datastoreProperties = new HashMap<String, Object>();
        datastoreProperties.put(GitDataStore.GIT_REMOTE_URL, remoteUrl);
        dataStore.activate(datastoreProperties);
        */
    fabricService = new FabricServiceImpl();
    // fabricService.bindDataStore(dataStore);
    fabricService.bindRuntimeProperties(runtimeProperties);
    fabricService.bindPlaceholderResolver(new DummyPlaceholerResolver("port"));
    fabricService.bindPlaceholderResolver(new DummyPlaceholerResolver("zk"));
    fabricService.bindPlaceholderResolver(new ProfilePropertyPointerResolver());
    fabricService.bindPlaceholderResolver(new ChecksumPlaceholderResolver());
    fabricService.bindPlaceholderResolver(new VersionPropertyPointerResolver());
    fabricService.bindPlaceholderResolver(new EnvPlaceholderResolver());
    fabricService.activateComponent();
    projectDeployer = new ProjectDeployerImpl();
    projectDeployer.bindFabricService(fabricService);
    projectDeployer.bindMBeanServer(ManagementFactory.getPlatformMBeanServer());
    // dataStore.getDefaultVersion();
    String defaultVersion = null;
    assertEquals("defaultVersion", "1.0", defaultVersion);
    // now lets import some data - using the old non-git file layout...
    String importPath = basedir + "/../fabric8-karaf/src/main/resources/distro/fabric/import";
    assertFolderExists(importPath);
    dataStore.importFromFileSystem(importPath);
    assertHasVersion(defaultVersion);
}
Also used : ProfilePropertyPointerResolver(io.fabric8.service.ProfilePropertyPointerResolver) RetryOneTime(org.apache.curator.retry.RetryOneTime) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) FabricGitServiceImpl(io.fabric8.git.internal.FabricGitServiceImpl) ZKServerFactoryBean(io.fabric8.zookeeper.spring.ZKServerFactoryBean) VersionPropertyPointerResolver(io.fabric8.service.VersionPropertyPointerResolver) EnvPlaceholderResolver(io.fabric8.service.EnvPlaceholderResolver) FabricServiceImpl(io.fabric8.service.FabricServiceImpl) StoredConfig(org.eclipse.jgit.lib.StoredConfig) DataStoreTemplate(io.fabric8.api.DataStoreTemplate) ChecksumPlaceholderResolver(io.fabric8.service.ChecksumPlaceholderResolver) File(java.io.File) RuntimeProperties(io.fabric8.api.RuntimeProperties) Before(org.junit.Before)

Example 12 with Config

use of io.fabric8.docker.client.Config in project fabric8 by jboss-fuse.

the class ManagedCartridgeConfig method saveConfig.

/**
 * Saves the managed cartridge configuration data
 */
public static ManagedCartridgeConfig saveConfig(FabricService fabricService, String containerId, CreateOpenshiftContainerOptions options, IApplication application) throws IOException {
    ManagedCartridgeConfig config = new ManagedCartridgeConfig();
    config.setServerUrl(options.getServerUrl());
    config.setLogin(options.getLogin());
    config.setPassword(options.getPassword());
    StringWriter writer = new StringWriter();
    config.getProperties().store(writer, "Saved by " + config.getClass() + " at " + new Date());
    String propertiesText = writer.toString();
    LOG.info("Saved managed cartridge configuration: " + propertiesText);
    fabricService.adapt(DataStore.class).setContainerAttribute(containerId, DataStore.ContainerAttribute.OpenShift, propertiesText);
    return config;
}
Also used : StringWriter(java.io.StringWriter) DataStore(io.fabric8.api.DataStore) Date(java.util.Date)

Example 13 with Config

use of io.fabric8.docker.client.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 14 with Config

use of io.fabric8.docker.client.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 15 with Config

use of io.fabric8.docker.client.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)

Aggregations

Test (org.junit.Test)128 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)44 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)43 IOException (java.io.IOException)41 HashMap (java.util.HashMap)40 File (java.io.File)31 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)28 ResourceConfig (io.fabric8.maven.core.config.ResourceConfig)28 Map (java.util.Map)28 RunImageConfiguration (io.fabric8.maven.docker.config.RunImageConfiguration)24 ArrayList (java.util.ArrayList)24 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)23 AbstractConfigHandlerTest (io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)21 Expectations (mockit.Expectations)20 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)19 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)17 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)16 VolumeConfig (io.fabric8.maven.core.config.VolumeConfig)15 AuthConfig (io.fabric8.maven.docker.access.AuthConfig)14 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)12