use of io.fabric8.maven.docker.model.Container 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.model.Container in project fabric8 by jboss-fuse.
the class FabricServiceImpl method getContainer.
@Override
public Container getContainer(String name) {
assertValid();
if (dataStore.get().hasContainer(name)) {
Container parent = null;
String parentId = dataStore.get().getContainerParent(name);
if (parentId != null && !parentId.isEmpty()) {
parent = getContainer(parentId);
}
return new ContainerImpl(parent, name, this);
}
throw new FabricException("Container '" + name + "' does not exist");
}
use of io.fabric8.maven.docker.model.Container in project fabric8 by jboss-fuse.
the class ProfileServiceImpl method deleteProfile.
@Override
public void deleteProfile(FabricService fabricService, String versionId, String profileId, boolean force) {
assertValid();
Profile profile = getRequiredProfile(versionId, profileId);
LOGGER.info("deleteProfile: {}", profile);
// TODO: what about child profiles ?
Container[] containers = fabricService != null ? fabricService.getAssociatedContainers(versionId, profileId) : new Container[0];
if (containers.length == 0) {
profileRegistry.get().deleteProfile(versionId, profileId);
} else if (force) {
for (Container container : containers) {
container.removeProfiles(profileId);
}
profileRegistry.get().deleteProfile(versionId, profileId);
} else {
StringBuilder sb = new StringBuilder();
sb.append("Cannot delete profile:").append(profileId).append(".");
sb.append("Profile has assigned ").append(containers.length).append(" container(s):");
for (Container c : containers) {
sb.append(" ").append(c.getId());
}
sb.append(". Use force option to also remove the profile from the containers.");
throw new FabricException(sb.toString());
}
// lets remove any pending requirements on this profile
FabricRequirements requirements = fabricService != null ? fabricService.getRequirements() : null;
if (requirements != null && requirements.removeProfileRequirements(profileId)) {
try {
fabricService.setRequirements(requirements);
} catch (IOException e) {
throw new FabricException("Failed to update requirements after deleting profile " + profileId + ". " + e, e);
}
}
}
use of io.fabric8.maven.docker.model.Container 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.docker.model.Container in project fabric8 by jboss-fuse.
the class BeanUtils method convertContainerToMap.
public static Map<String, Object> convertContainerToMap(FabricService fabricService, Container container, List<String> fields) {
Map<String, Object> answer = new TreeMap<String, Object>();
for (String field : fields) {
if (field.equalsIgnoreCase("profiles") || field.equalsIgnoreCase("profileIds")) {
answer.put(field, Ids.getIds(container.getProfiles()));
} else if (field.equalsIgnoreCase("childrenIds") || field.equalsIgnoreCase("children")) {
answer.put(field, Ids.getIds(container.getChildren()));
} else if (field.equalsIgnoreCase("parent") || field.equalsIgnoreCase("parentId")) {
answer.put(field, Ids.getId(container.getParent()));
} else if (field.equalsIgnoreCase("version") || field.equalsIgnoreCase("versionId")) {
answer.put(field, container.getVersionId());
} else if (field.equalsIgnoreCase("overlayProfile")) {
Profile overlayProfile = container.getOverlayProfile();
Profile effectiveProfile = Profiles.getEffectiveProfile(fabricService, overlayProfile);
answer.put(field, convertProfileToMap(fabricService, effectiveProfile, getFields(Profile.class)));
} else {
addProperty(container, field, answer);
}
}
return answer;
}
Aggregations