use of io.fabric8.maven.docker.config.CopyConfiguration.Entry 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());
}
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8 by jboss-fuse.
the class ComponentConfigurer method configure.
@Override
public <T> Map<String, ?> configure(final Map<String, ?> configuration, T target, String... ignorePrefix) throws Exception {
assertValid();
Map<String, Object> result = new HashMap<>();
final PropertiesProvider runtimeProperties = new PropertiesProvider() {
@Override
public Object getProperty(String key) {
return bundleContext.getProperty(key);
}
@Override
public Object getRequiredProperty(String key) {
String value = bundleContext.getProperty(key);
IllegalStateAssertion.assertNotNull(value, "Cannot obtain property: " + key);
return value;
}
@Override
public Object getProperty(String key, Object defaultValue) {
String value = bundleContext.getProperty(key);
return value != null ? value : defaultValue;
}
};
final PropertiesProvider configurationProvider = new MapPropertiesProvider((Map<String, Object>) configuration);
final PropertiesProvider[] propertiesProviders = new PropertiesProvider[] { configurationProvider, runtimeProperties };
PropertiesProvider provider = new SubstitutionPropertiesProvider(propertiesProviders);
for (Map.Entry<String, ?> entry : configuration.entrySet()) {
String key = entry.getKey();
Object value = provider.getProperty(key);
result.put(key, value);
}
ConfigInjection.applyConfiguration(result, target, ignorePrefix);
return result;
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8 by jboss-fuse.
the class ZkDataStoreImpl method createContainerConfig.
@Override
public void createContainerConfig(CreateContainerMetadata metadata) {
assertValid();
try {
CreateContainerOptions options = metadata.getCreateOptions();
String containerId = metadata.getContainerName();
// String parent = options.getParent();
// String versionId = options.getVersion() != null ? options.getVersion() : getDefaultVersion();
// Set<String> profileIds = options.getProfiles();
// if (profileIds == null || profileIds.isEmpty()) {
// profileIds = new LinkedHashSet<String>();
// profileIds.add("default");
// }
// StringBuilder sb = new StringBuilder();
// for (String profileId : profileIds) {
// if (sb.length() > 0) {
// sb.append(" ");
// }
// sb.append(profileId);
// }
//
// setData(curator.get(), ZkPath.CONFIG_CONTAINER.getPath(containerId), versionId);
// setData(curator.get(), ZkPath.CONFIG_VERSIONS_CONTAINER.getPath(versionId, containerId), sb.toString());
// setData(curator.get(), ZkPath.CONTAINER_PARENT.getPath(containerId), parent);
setContainerMetadata(metadata);
Map<String, String> configuration = metadata.getContainerConfiguration();
for (Map.Entry<String, String> entry : configuration.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
setData(curator.get(), ZkPath.CONTAINER_ENTRY.getPath(metadata.getContainerName(), key), value);
}
// If no resolver specified but a resolver is already present in the registry, use the registry value
String resolver = metadata.getOverridenResolver() != null ? metadata.getOverridenResolver() : options.getResolver();
if (resolver == null && exists(curator.get(), ZkPath.CONTAINER_RESOLVER.getPath(containerId)) != null) {
resolver = getStringData(curator.get(), ZkPath.CONTAINER_RESOLVER.getPath(containerId));
} else if (options.getResolver() != null) {
// Use the resolver specified in the options and do nothing.
} else if (exists(curator.get(), ZkPath.POLICIES.getPath(ZkDefs.RESOLVER)) != null) {
// If there is a globlal resolver specified use it.
resolver = getStringData(curator.get(), ZkPath.POLICIES.getPath(ZkDefs.RESOLVER));
} else {
// Fallback to the default resolver
resolver = ZkDefs.DEFAULT_RESOLVER;
}
// Set the resolver if not already set
setData(curator.get(), ZkPath.CONTAINER_RESOLVER.getPath(containerId), resolver);
} catch (Exception e) {
throw FabricException.launderThrowable(e);
}
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8 by jboss-fuse.
the class FabricServiceImpl method validateProfileDependencies.
protected void validateProfileDependencies(CreateContainerOptions options) {
Map<String, Map<String, String>> profileDependencies = Profiles.getOverlayFactoryConfigurations(this, options.getProfiles(), options.getVersion(), ProfileDependencyConfig.PROFILE_DEPENDENCY_CONFIG_PID);
Set<Map.Entry<String, Map<String, String>>> entries = profileDependencies.entrySet();
for (Map.Entry<String, Map<String, String>> entry : entries) {
String configName = entry.getKey();
Map<String, String> exportConfig = entry.getValue();
if (exportConfig != null && !exportConfig.isEmpty()) {
ProfileDependencyConfig config = new ProfileDependencyConfig();
try {
configurer.configure(exportConfig, config);
} catch (Exception e) {
throw new FabricException("Failed to load configuration for " + configName + " of " + config + " due to: " + e, e);
}
// Ensure dependent container exists
if (ProfileDependencyKind.ZOOKEEPER_SERVICE.equals(config.getKind())) {
try {
List<String> children = getChildren(this.curator.get(), config.getZookeeperPath());
if (children == null || children.isEmpty()) {
throw new ProfileDependencyException(options.getProfiles(), config.getProfileWildcards(), config.getProfileTags(), config.getSummary());
}
boolean dependencyFound = false;
Iterator<String> childIterator = children.iterator();
while (!dependencyFound && childIterator.hasNext()) {
String containerName = childIterator.next();
Container container = this.getContainer(containerName);
Profile[] profiles = container.getProfiles();
int profileCount = 0;
while (!dependencyFound && profileCount < profiles.length) {
Profile profile = profiles[profileCount];
if (config.getProfileWildcards() != null) {
for (String profileWildcard : config.getProfileWildcards()) {
if (profile.getId().contains(profileWildcard)) {
dependencyFound = true;
break;
}
}
}
if (!dependencyFound && config.getProfileTags() != null) {
List<String> profileTags = profile.getTags();
int foundTags = 0;
for (String configProfileTag : config.getProfileTags()) {
if (profileTags.contains(configProfileTag)) {
foundTags++;
}
}
if (foundTags == config.getProfileTags().length) {
dependencyFound = true;
}
}
}
}
if (!dependencyFound) {
throw new ProfileDependencyException(options.getProfiles(), config.getProfileWildcards(), config.getProfileTags(), config.getSummary());
}
} catch (Exception e) {
throw new ProfileDependencyException(options.getProfiles(), config.getProfileWildcards(), config.getProfileTags(), config.getSummary(), e);
}
}
}
}
}
use of io.fabric8.maven.docker.config.CopyConfiguration.Entry in project fabric8 by jboss-fuse.
the class SshAutoScalerTest method assertMaximumContainerCountNotExceeded.
/**
* lets assert that no host has more than its maximum number of containers
*/
public static void assertMaximumContainerCountNotExceeded(FabricRequirements requirements, Map<String, CountingMap> hostToProfileCounts) {
for (Map.Entry<String, CountingMap> entry : hostToProfileCounts.entrySet()) {
String hostName = entry.getKey();
CountingMap counts = entry.getValue();
int total = counts.total();
SshConfiguration sshConfiguration = requirements.getSshConfiguration();
assertNotNull("Should have a sshConfiguration!", sshConfiguration);
SshHostConfiguration hostConfiguration = sshConfiguration.getHost(hostName);
assertNotNull("Should have a hosts configuration for host " + hostName, hostConfiguration);
Integer maximumContainerCount = hostConfiguration.getMaximumContainerCount();
if (maximumContainerCount != null) {
assertTrue("Host " + hostName + " has a maximum container count of " + maximumContainerCount + " but was " + total, total <= maximumContainerCount);
}
}
}
Aggregations