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);
}
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;
}
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);
}
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;
}
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);
}
Aggregations