use of io.fabric8.annotations.Configuration in project docker-maven-plugin by fabric8io.
the class BuildMojo method executeInternal.
@Override
protected void executeInternal(ServiceHub hub) throws DockerAccessException, MojoExecutionException {
if (skipBuild) {
return;
}
List<ImageConfiguration> resolvedImages = getResolvedImages();
if (resolvedImages.isEmpty()) {
// No Configuration found, so build one up dynamically.
if (imageName == null) {
/*
* Image name defaults to:
* `${project.groupId}/${project.artifactId}:${project.version}`
*/
imageName = project.getGroupId() + "/" + project.getArtifactId() + ":" + project.getVersion();
}
ImageConfiguration aDefaultImageConfig = ImageConfiguration.getDefaultImageConfiguration(imageName, project.getBasedir().getAbsolutePath());
processImageConfig(hub, aDefaultImageConfig);
return;
} else {
// Iterate over all the ImageConfigurations and process one by one
for (ImageConfiguration imageConfig : resolvedImages) {
processImageConfig(hub, imageConfig);
}
}
}
use of io.fabric8.annotations.Configuration in project kie-wb-common by kiegroup.
the class OpenShiftAccessInterfaceImpl method buildOpenShiftConfig.
// package-protected for junit testing purposes (from inside the package)
static OpenShiftConfig buildOpenShiftConfig(OpenShiftProviderConfig config) {
OpenShiftConfigBuilder builder = new OpenShiftConfigBuilder(OpenShiftConfig.wrap(Config.autoConfigure()));
/*
* Kubernetes configuration properties; see io.fabric8.kubernetes.client.Config
*/
String allProxy = trimToNull(config.getAllProxy());
if (allProxy != null) {
builder = builder.withHttpProxy(allProxy);
builder = builder.withHttpsProxy(allProxy);
}
String httpProxy = trimToNull(config.getHttpProxy());
if (httpProxy != null) {
// NOTE: overrides allProxy above
builder = builder.withHttpProxy(httpProxy);
}
String httpsProxy = trimToNull(config.getHttpsProxy());
if (httpsProxy != null) {
// NOTE: overrides allProxy above
builder = builder.withHttpsProxy(httpsProxy);
}
String kubernetesApiVersion = trimToNull(config.getKubernetesApiVersion());
if (kubernetesApiVersion != null) {
builder = builder.withApiVersion(kubernetesApiVersion);
}
String kubernetesAuthBasicPassword = trimToNull(config.getKubernetesAuthBasicPassword());
if (kubernetesAuthBasicPassword != null) {
builder = builder.withPassword(kubernetesAuthBasicPassword);
}
String kubernetesAuthBasicUsername = trimToNull(config.getKubernetesAuthBasicUsername());
if (kubernetesAuthBasicUsername != null) {
builder = builder.withUsername(kubernetesAuthBasicUsername);
}
String kubernetesAuthToken = trimToNull(config.getKubernetesAuthToken());
if (kubernetesAuthToken != null) {
builder = builder.withOauthToken(kubernetesAuthToken);
}
String kubernetesCertsCaData = trimToNull(config.getKubernetesCertsCaData());
if (kubernetesCertsCaData != null) {
builder = builder.withCaCertData(kubernetesCertsCaData);
}
String kubernetesCertsCaFile = trimToNull(config.getKubernetesCertsCaFile());
if (kubernetesCertsCaFile != null) {
builder = builder.withCaCertFile(kubernetesCertsCaFile);
}
String kubernetesCertsClientData = trimToNull(config.getKubernetesCertsClientData());
if (kubernetesCertsClientData != null) {
builder = builder.withClientCertData(kubernetesCertsClientData);
}
String kubernetesCertsClientFile = trimToNull(config.getKubernetesCertsClientFile());
if (kubernetesCertsClientFile != null) {
builder = builder.withClientCertFile(kubernetesCertsClientFile);
}
String kubernetesCertsClientKeyAlgo = trimToNull(config.getKubernetesCertsClientKeyAlgo());
if (kubernetesCertsClientKeyAlgo != null) {
builder = builder.withClientKeyAlgo(kubernetesCertsClientKeyAlgo);
}
String kubernetesCertsClientKeyData = trimToNull(config.getKubernetesCertsClientKeyData());
if (kubernetesCertsClientKeyData != null) {
builder = builder.withClientKeyData(kubernetesCertsClientKeyData);
}
String kubernetesCertsClientKeyFile = trimToNull(config.getKubernetesCertsClientKeyFile());
if (kubernetesCertsClientKeyFile != null) {
builder = builder.withClientKeyFile(kubernetesCertsClientKeyFile);
}
String kubernetesCertsClientKeyPassphrase = trimToNull(config.getKubernetesCertsClientKeyPassphrase());
if (kubernetesCertsClientKeyPassphrase != null) {
builder = builder.withClientKeyPassphrase(kubernetesCertsClientKeyPassphrase);
}
String kubernetesConnectionTimeout = trimToNull(config.getKubernetesConnectionTimeout());
if (kubernetesConnectionTimeout != null) {
builder = builder.withConnectionTimeout(Integer.parseInt(kubernetesConnectionTimeout));
}
String kubernetesKeystoreFile = trimToNull(config.getKubernetesKeystoreFile());
if (kubernetesKeystoreFile != null) {
builder = builder.withKeyStoreFile(kubernetesKeystoreFile);
}
String kubernetesKeystorePassphrase = trimToNull(config.getKubernetesKeystorePassphrase());
if (kubernetesKeystorePassphrase != null) {
builder = builder.withKeyStorePassphrase(kubernetesKeystorePassphrase);
}
String kubernetesLoggingInterval = trimToNull(config.getKubernetesLoggingInterval());
if (kubernetesLoggingInterval != null) {
builder = builder.withLoggingInterval(Integer.parseInt(kubernetesLoggingInterval));
}
String kubernetesMaster = trimToNull(config.getKubernetesMaster());
if (kubernetesMaster != null) {
builder = builder.withMasterUrl(kubernetesMaster);
}
String kubernetesNamespace = trimToNull(config.getKubernetesNamespace());
if (kubernetesNamespace != null) {
builder = builder.withNamespace(kubernetesNamespace);
}
String kubernetesRequestTimeout = trimToNull(config.getKubernetesRequestTimeout());
if (kubernetesRequestTimeout != null) {
builder = builder.withRequestTimeout(Integer.parseInt(kubernetesRequestTimeout));
}
String kubernetesRollingTimeout = trimToNull(config.getKubernetesRollingTimeout());
if (kubernetesRollingTimeout != null) {
builder = builder.withRollingTimeout(Long.parseLong(kubernetesRollingTimeout));
}
String kubernetesScaleTimeout = trimToNull(config.getKubernetesScaleTimeout());
if (kubernetesScaleTimeout != null) {
builder = builder.withScaleTimeout(Long.parseLong(kubernetesScaleTimeout));
}
String kubernetesTlsVersions = trimToNull(config.getKubernetesTlsVersions());
if (kubernetesTlsVersions != null) {
String[] split = kubernetesTlsVersions.split(",");
TlsVersion[] vers = new TlsVersion[split.length];
for (int i = 0; i < split.length; i++) {
vers[i] = TlsVersion.forJavaName(split[i]);
}
builder.withTlsVersions(vers);
}
String kubernetesTrustCertificates = trimToNull(config.getKubernetesTrustCertificates());
if (kubernetesTrustCertificates != null) {
builder = builder.withTrustCerts(Boolean.parseBoolean(kubernetesTrustCertificates));
}
String kubernetesTruststoreFile = trimToNull(config.getKubernetesTruststoreFile());
if (kubernetesTruststoreFile != null) {
builder = builder.withTrustStoreFile(kubernetesTruststoreFile);
}
String kubernetesTruststorePassphrase = trimToNull(config.getKubernetesTruststorePassphrase());
if (kubernetesTruststorePassphrase != null) {
builder = builder.withTrustStorePassphrase(kubernetesTruststorePassphrase);
}
String kubernetesUserAgent = trimToNull(config.getKubernetesUserAgent());
if (kubernetesUserAgent != null) {
builder = builder.withUserAgent(kubernetesUserAgent);
}
String kubernetesWatchReconnectInterval = trimToNull(config.getKubernetesWatchReconnectInterval());
if (kubernetesWatchReconnectInterval != null) {
builder = builder.withWatchReconnectInterval(Integer.parseInt(kubernetesWatchReconnectInterval));
}
String kubernetesWatchReconnectLimit = trimToNull(config.getKubernetesWatchReconnectLimit());
if (kubernetesWatchReconnectLimit != null) {
builder = builder.withWatchReconnectLimit(Integer.parseInt(kubernetesWatchReconnectLimit));
}
String kubernetesWebsocketPingInterval = trimToNull(config.getKubernetesWebsocketPingInterval());
if (kubernetesWebsocketPingInterval != null) {
builder = builder.withWebsocketPingInterval(Long.parseLong(kubernetesWebsocketPingInterval));
}
String kubernetesWebsocketTimeout = trimToNull(config.getKubernetesWebsocketTimeout());
if (kubernetesWebsocketTimeout != null) {
builder = builder.withWebsocketTimeout(Long.parseLong(kubernetesWebsocketTimeout));
}
String noProxy = trimToNull(config.getNoProxy());
if (noProxy != null) {
builder = builder.withNoProxy(noProxy.split(","));
}
String proxyPassword = trimToNull(config.getProxyPassword());
if (proxyPassword != null) {
builder = builder.withProxyPassword(proxyPassword);
}
String proxyUsername = trimToNull(config.getProxyUsername());
if (proxyUsername != null) {
builder = builder.withProxyUsername(proxyUsername);
}
/*
* OpenShift configuration properties; see io.fabric8.openshift.client.OpenShiftConfig
*/
String kubernetesOapiVersion = trimToNull(config.getKubernetesOapiVersion());
if (kubernetesOapiVersion != null) {
builder = builder.withOapiVersion(kubernetesOapiVersion);
}
String openshiftBuildTimeout = trimToNull(config.getOpenshiftBuildTimeout());
if (openshiftBuildTimeout != null) {
builder = builder.withBuildTimeout(Long.parseLong(openshiftBuildTimeout));
}
String openshiftUrl = trimToNull(config.getOpenshiftUrl());
if (openshiftUrl != null) {
// The OPENSHIFT_URL environment variable may be set to the root url (i.e. without the '/oapi/version' path) in some configurations
if (isRootUrl(openshiftUrl)) {
openshiftUrl = URLUtils.join(openshiftUrl, "oapi", builder.getOapiVersion());
}
builder = builder.withOpenShiftUrl(openshiftUrl);
} else {
builder.withOpenShiftUrl(URLUtils.join(builder.getMasterUrl(), "oapi", builder.getOapiVersion()));
}
return builder.build();
}
use of io.fabric8.annotations.Configuration in project fabric8 by jboss-fuse.
the class JoinAction method doExecute.
@Override
protected Object doExecute() throws Exception {
if (nonManaged) {
profile = "unmanaged";
}
String oldName = runtimeProperties.getRuntimeIdentity();
if (System.getenv("OPENSHIFT_BROKER_HOST") != null && containerName != null) {
System.err.println("Containers in OpenShift cannot be renamed");
return null;
}
if (containerName == null) {
containerName = oldName;
}
FabricValidations.validateContainerName(containerName);
Configuration bootConfiguration = configAdmin.getConfiguration(BootstrapConfiguration.COMPONENT_PID, null);
Configuration dataStoreConfiguration = configAdmin.getConfiguration(Constants.DATASTORE_PID, null);
Configuration configZook = configAdmin.getConfiguration(Constants.ZOOKEEPER_CLIENT_PID, null);
if (configZook.getProperties() != null && configZook.getProperties().get("zookeeper.url") != null) {
System.err.println("This container is already connected to a fabric");
return null;
}
Dictionary<String, Object> bootProperties = bootConfiguration.getProperties();
if (bootProperties == null) {
bootProperties = new Hashtable<>();
}
if (resolver != null) {
bootProperties.put(ZkDefs.LOCAL_RESOLVER_PROPERTY, resolver);
}
if (manualIp != null) {
bootProperties.put(ZkDefs.MANUAL_IP, manualIp);
}
if (bindAddress != null) {
bootProperties.put(ZkDefs.BIND_ADDRESS, bindAddress);
}
zookeeperPassword = zookeeperPassword != null ? zookeeperPassword : ShellUtils.retrieveFabricZookeeperPassword(session);
if (zookeeperPassword == null) {
zookeeperPassword = promptForZookeeperPassword();
}
if (zookeeperPassword == null || zookeeperPassword.isEmpty()) {
System.out.println("No password specified. Cannot join fabric ensemble.");
return null;
}
ShellUtils.storeZookeeperPassword(session, zookeeperPassword);
log.debug("Encoding ZooKeeper password.");
String encodedPassword = PasswordEncoder.encode(zookeeperPassword);
bootProperties.put(ZkDefs.MINIMUM_PORT, String.valueOf(minimumPort));
bootProperties.put(ZkDefs.MAXIMUM_PORT, String.valueOf(maximumPort));
Hashtable<String, Object> dataStoreProperties = new Hashtable<String, Object>();
Configuration cfg = configAdmin.getConfiguration(Constants.DATASTORE_PID, null);
Dictionary<String, Object> props = cfg.getProperties();
if (props != null) {
for (Enumeration<String> keys = cfg.getProperties().keys(); keys.hasMoreElements(); ) {
String k = keys.nextElement();
dataStoreProperties.put(k, cfg.getProperties().get(k));
}
}
augmentDataStoreProperties(zookeeperPassword, dataStoreProperties);
if (!containerName.equals(oldName)) {
if (force || permissionToRenameContainer()) {
if (!registerContainer(containerName, zookeeperPassword, profile, force)) {
System.err.println("A container with the name: " + containerName + " is already member of the cluster. You can specify a different name as an argument.");
return null;
}
bootProperties.put(SystemProperties.KARAF_NAME, containerName);
// Ensure that if we bootstrap CuratorFramework via RuntimeProperties password is set before the URL.
bootProperties.put("zookeeper.password", encodedPassword);
bootProperties.put("zookeeper.url", zookeeperUrl);
// Rename the container
Path propsPath = runtimeProperties.getConfPath().resolve("system.properties");
Properties systemProps = new Properties(propsPath.toFile());
systemProps.put(SystemProperties.KARAF_NAME, containerName);
// Also pass zookeeper information so that the container can auto-join after the restart.
systemProps.put("zookeeper.url", zookeeperUrl);
systemProps.put("zookeeper.password", encodedPassword);
systemProps.save();
System.setProperty("runtime.id", containerName);
System.setProperty(SystemProperties.KARAF_NAME, containerName);
System.setProperty("karaf.restart", "true");
System.setProperty("karaf.restart.clean", "false");
if (!nonManaged) {
installBundles();
}
// it's only a(n almost certain) way of synchronizing CM and ManagedService.update()
if (!OsgiUtils.updateCmConfigurationAndWait(bundleContext, bootConfiguration, bootProperties, 10, TimeUnit.SECONDS)) {
log.warn("Timeout waiting for update of PID: {}", BootstrapConfiguration.COMPONENT_PID);
}
if (!OsgiUtils.updateCmConfigurationAndWait(bundleContext, dataStoreConfiguration, dataStoreProperties, 10, TimeUnit.SECONDS)) {
log.warn("Timeout waiting for update of PID: {}", Constants.DATASTORE_PID);
}
// we don't want fileinstall to trigger ConfigAdmin update
Bundle fileinstall = new BundleUtils(bundleContext).findBundle("org.apache.felix.fileinstall");
if (fileinstall != null) {
fileinstall.stop(Bundle.STOP_TRANSIENT);
}
persistConfiguration(configAdmin, Constants.DATASTORE_PID, dataStoreProperties);
// Restart the container
bundleContext.getBundle(0).stop();
return null;
} else {
return null;
}
} else {
bootConfiguration.update(bootProperties);
dataStoreConfiguration.update(dataStoreProperties);
persistConfiguration(configAdmin, Constants.DATASTORE_PID, dataStoreProperties);
if (!registerContainer(containerName, zookeeperPassword, profile, force)) {
System.err.println("A container with the name: " + containerName + " is already member of the cluster. You can specify a different name as an argument.");
return null;
}
Configuration config = configAdmin.getConfiguration(Constants.ZOOKEEPER_CLIENT_PID, null);
Hashtable<String, Object> properties = new Hashtable<String, Object>();
properties.put("zookeeper.url", zookeeperUrl);
properties.put("zookeeper.password", PasswordEncoder.encode(encodedPassword));
config.setBundleLocation(null);
config.update(properties);
if (!nonManaged) {
installBundles();
}
return null;
}
}
use of io.fabric8.annotations.Configuration 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.annotations.Configuration in project fabric8 by jboss-fuse.
the class ManagedCartridgeConfig method loadConfig.
/**
* Loads the managed cartridge configuration for the given containerId
*/
public static ManagedCartridgeConfig loadConfig(FabricService fabricService, String containerId) throws IOException {
String propertiesText = fabricService.adapt(DataStore.class).getContainerAttribute(containerId, DataStore.ContainerAttribute.OpenShift, "", false, substitutedStringValue);
if (propertiesText == null) {
return null;
}
Properties properties = new Properties();
properties.load(new StringReader(propertiesText));
ManagedCartridgeConfig answer = new ManagedCartridgeConfig(properties);
LOG.info("Loaded managed cartridge configuration " + answer);
return answer;
}
Aggregations