use of io.fabric8.kubernetes.model.annotation.Version in project fabric8 by jboss-fuse.
the class VersionListAction method printVersions.
protected void printVersions(Container[] containers, List<String> versions, String defaultVersionId, PrintStream out) {
TablePrinter table = new TablePrinter();
table.columns("version", "default", "# containers", "description");
List<String> invalidVersion = new ArrayList<String>();
// they are sorted in the correct order by default
for (String versionId : versions) {
if (versionId != null && !versionId.isEmpty() && ALLOWED_PROFILE_NAMES_PATTERN.matcher(versionId).matches()) {
boolean isDefault = versionId.equals(defaultVersionId);
Version version = profileService.getRequiredVersion(versionId);
int active = countContainersByVersion(containers, version);
String description = version.getAttributes().get(Version.DESCRIPTION);
table.row(version.getId(), (isDefault ? "true" : ""), activeContainerCountText(active), description);
} else {
invalidVersion.add(versionId);
}
}
table.print();
if (!invalidVersion.isEmpty()) {
System.out.println("The following profile versions have been skipped since their names are not correct: " + invalidVersion.toString());
}
}
use of io.fabric8.kubernetes.model.annotation.Version in project fabric8 by jboss-fuse.
the class DefaultVersionBuilder method validate.
@Override
protected void validate() {
super.validate();
IllegalStateAssertion.assertNotNull(versionId, "Version must have an identity");
for (Profile profile : profiles.values()) {
String prfversion = profile.getVersion();
IllegalStateAssertion.assertEquals(versionId, prfversion, "Profile version not '" + versionId + "' for: " + profile);
}
}
use of io.fabric8.kubernetes.model.annotation.Version in project fabric8 by jboss-fuse.
the class ProfileWatcherImpl method findProfileArifacts.
// For each profile and version return the map of bundle locations to parsers
private Map<ProfileVersionKey, Map<String, Parser>> findProfileArifacts() throws Exception {
Map<ProfileVersionKey, Map<String, Parser>> profileArtifacts = new HashMap<ProfileVersionKey, Map<String, Parser>>();
ProfileService profileService = fabricService.get().adapt(ProfileService.class);
DownloadManager downloadManager = DownloadManagers.createDownloadManager(fabricService.get(), executorService);
Container[] containers = fabricService.get().getContainers();
for (Container container : containers) {
Profile[] profiles = container.getProfiles();
boolean javaOrProcessContainer = ChildContainers.isJavaOrProcessContainer(fabricService.get(), container);
// TODO allow filter on a profile here?
for (Profile profile : profiles) {
Profile overlay = profileService.getOverlayProfile(profile);
ProfileVersionKey key = new ProfileVersionKey(profile);
// if (!profileArtifacts.containsKey(key)) {
Map<String, Parser> artifacts = null;
if (javaOrProcessContainer) {
List<Profile> singletonList = Collections.singletonList(profile);
artifacts = JavaContainers.getJavaContainerArtifacts(fabricService.get(), singletonList, executorService);
} else {
artifacts = AgentUtils.getProfileArtifacts(fabricService.get(), downloadManager, overlay);
}
if (artifacts != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("Profile " + profile.getId() + " maps to artefacts: " + artifacts.keySet());
}
profileArtifacts.put(key, artifacts);
}
// }
}
}
return profileArtifacts;
}
use of io.fabric8.kubernetes.model.annotation.Version in project fabric8 by jboss-fuse.
the class ProfileWatcherImpl method getCurrentActiveProfileVersions.
/**
* Gets the set of active profile ids and versions
*/
protected SortedSet<String> getCurrentActiveProfileVersions() {
SortedSet<String> answer = new TreeSet<String>();
Container[] containers = fabricService.get().getContainers();
for (Container container : containers) {
container.getProvisionList();
Profile[] profiles = container.getProfiles();
// TODO allow filter on a profile here?
for (Profile profile : profiles) {
String id = profile.getId();
String version = profile.getVersion();
answer.add(id + "/" + version);
}
}
return answer;
}
use of io.fabric8.kubernetes.model.annotation.Version in project fabric8 by jboss-fuse.
the class Overrides method override.
/**
* Compute a list of bundles to install, taking into account overrides.
* <p/>
* The file containing the overrides will be loaded from the given url.
* Blank lines and lines starting with a '#' will be ignored, all other lines
* are considered as urls to override bundles.
* <p/>
* The list of resources to resolve will be scanned and for each bundle,
* if a bundle override matches that resource, it will be used instead.
* <p/>
* Matching is done on bundle symbolic name (they have to be the same)
* and version (the bundle override version needs to be greater than the
* resource to be resolved, and less than the next minor version. A range
* directive can be added to the override url in which case, the matching
* will succeed if the resource to be resolved is within the given range.
*
* @param resources the list of resources to resolve
* @param overrides list of bundle overrides
*/
public static <T extends Resource> void override(Map<String, T> resources, Collection<String> overrides) {
// Do override replacement
for (Clause override : Parser.parseClauses(overrides.toArray(new String[overrides.size()]))) {
String url = override.getName();
String vr = override.getAttribute(OVERRIDE_RANGE);
T over = resources.get(url);
if (over == null) {
// Ignore invalid overrides
continue;
}
for (String uri : new ArrayList<String>(resources.keySet())) {
Resource res = resources.get(uri);
if (getSymbolicName(res).equals(getSymbolicName(over))) {
VersionRange range;
if (vr == null) {
// default to micro version compatibility
Version v1 = getVersion(res);
Version v2 = new Version(v1.getMajor(), v1.getMinor() + 1, 0);
range = new VersionRange(false, v1, v2, true);
} else {
range = VersionRange.parseVersionRange(vr);
}
// if the override is actually a newer version than what we currently have
if (range.contains(getVersion(over)) && getVersion(res).compareTo(getVersion(over)) < 0) {
resources.put(uri, over);
}
}
}
}
}
Aggregations