use of io.fabric8.maven.core.model.Configuration 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.core.model.Configuration 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.core.model.Configuration 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);
}
}
}
use of io.fabric8.maven.core.model.Configuration in project fabric8 by jboss-fuse.
the class FabricManager method currentContainerConfigurationFiles.
/**
* Returns a map of all the current configuration files in the profiles of
* the current container with the file name as the key and the profile ID as
* the value
*/
@Override
public Map<String, String> currentContainerConfigurationFiles() {
String containerName = getCurrentContainerName();
FabricServiceImpl service = fabricService;
Container container = service.getContainer(containerName);
if (container != null) {
Profile[] profiles = container.getProfiles();
return Profiles.getConfigurationFileNameMap(profiles);
}
return new HashMap<String, String>();
}
use of io.fabric8.maven.core.model.Configuration in project fabric8 by jboss-fuse.
the class MQManager method createConfigDTOs.
public static List<MQBrokerConfigDTO> createConfigDTOs(MQService mqService, Profile profile) {
List<MQBrokerConfigDTO> answer = new ArrayList<MQBrokerConfigDTO>();
Map<String, Map<String, String>> configurations = profile.getConfigurations();
Set<Map.Entry<String, Map<String, String>>> entries = configurations.entrySet();
for (Map.Entry<String, Map<String, String>> entry : entries) {
String key = entry.getKey();
Map<String, String> configuration = entry.getValue();
if (isBrokerConfigPid(key)) {
String brokerName = getBrokerNameFromPID(key);
String profileId = profile.getId();
MQBrokerConfigDTO dto = new MQBrokerConfigDTO();
dto.setProfile(profileId);
dto.setBrokerName(brokerName);
String version = profile.getVersion();
dto.setVersion(version);
List<String> parentIds = profile.getParentIds();
if (parentIds.size() > 0) {
dto.setParentProfile(parentIds.get(0));
}
if (configuration != null) {
dto.setData(configuration.get(DATA));
dto.setConfigUrl(configuration.get(CONFIG_URL));
dto.setGroup(configuration.get(GROUP));
dto.setKind(BrokerKind.fromValue(configuration.get(KIND)));
dto.setMinimumInstances(Maps.integerValue(configuration, MINIMUM_INSTANCES));
dto.setNetworks(Maps.stringValues(configuration, NETWORKS));
dto.setNetworksUserName(configuration.get(NETWORK_USER_NAME));
dto.setNetworksPassword(configuration.get(NETWORK_PASSWORD));
dto.setReplicas(Maps.integerValue(configuration, REPLICAS));
for (Map.Entry<String, String> configurationEntry : configuration.entrySet()) {
if (configurationEntry.getKey().endsWith("-port")) {
dto.getPorts().put(configurationEntry.getKey().substring(0, configurationEntry.getKey().indexOf("-port")), configurationEntry.getValue());
}
}
}
answer.add(dto);
}
}
return answer;
}
Aggregations