use of io.fabric8.api.ProfileService in project fabric8 by jboss-fuse.
the class ProfileDownloader method addMavenBundles.
protected void addMavenBundles(FabricService fabricService, Profile profile, Set<String> bundles, List<String> bundleList) {
for (String bundle : bundleList) {
if (bundle != null) {
if (bundle.contains("$")) {
// use similar logic as io.fabric8.agent.utils.AgentUtils.getProfileArtifacts method
// as we need to substitute version placeholders
ProfileService profileService = fabricService.adapt(ProfileService.class);
Profile overlay = profileService.getOverlayProfile(profile);
bundle = VersionPropertyPointerResolver.replaceVersions(fabricService, overlay.getConfigurations(), bundle);
}
bundles.add(bundle);
}
}
}
use of io.fabric8.api.ProfileService in project fabric8 by jboss-fuse.
the class ProfileDeleteAction method doExecute.
@Override
protected Object doExecute() throws Exception {
// do not validate the name in case a profile was created somehow with invalid name
ProfileService profileService = fabricService.adapt(ProfileService.class);
Version version = versionId != null ? profileService.getRequiredVersion(versionId) : fabricService.getRequiredDefaultVersion();
boolean deleted = false;
for (Profile profile : version.getProfiles()) {
String versionId = profile.getVersion();
String profileId = profile.getId();
if (name.equals(profileId)) {
profileService.deleteProfile(fabricService, versionId, profileId, force);
deleted = true;
}
}
if (!deleted) {
System.out.println("Profile " + name + " not found.");
}
return null;
}
use of io.fabric8.api.ProfileService in project fabric8 by jboss-fuse.
the class ProfileDisplayAction method displayProfile.
private void displayProfile(Profile profile) {
PrintStream output = System.out;
output.println("Profile id: " + profile.getId());
output.println("Version : " + profile.getVersion());
output.println("Attributes: ");
Map<String, String> props = profile.getAttributes();
for (String key : props.keySet()) {
output.println("\t" + key + ": " + props.get(key));
}
String versionId = profile.getVersion();
String profileId = profile.getId();
output.printf("Containers: %s\n", toString(fabricService.getAssociatedContainers(versionId, profileId)));
ProfileService profileService = fabricService.adapt(ProfileService.class);
if (overlay) {
profile = profileService.getOverlayProfile(profile);
}
Map<String, Map<String, String>> configuration = new HashMap<>(profile.getConfigurations());
Map<String, byte[]> resources = profile.getFileConfigurations();
Map<String, String> agentConfiguration = profile.getConfiguration(Constants.AGENT_PID);
List<String> agentProperties = new ArrayList<String>();
List<String> systemProperties = new ArrayList<String>();
List<String> configProperties = new ArrayList<String>();
List<String> otherResources = new ArrayList<String>();
for (Map.Entry<String, String> entry : agentConfiguration.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (value.contains(",")) {
value = "\t" + value.replace(",", ",\n\t\t");
}
if (key.startsWith("system.")) {
systemProperties.add(" " + key.substring("system.".length()) + " = " + value);
} else if (key.startsWith("config.")) {
configProperties.add(" " + key.substring("config.".length()) + " = " + value);
} else if (!key.startsWith("feature.") && !key.startsWith("repository") && !key.startsWith("bundle.") && !key.startsWith("fab.") && !key.startsWith("override.") && !key.startsWith("attribute.")) {
agentProperties.add(" " + key + " = " + value);
}
}
if (configuration.containsKey(Constants.AGENT_PID)) {
output.println("\nContainer settings");
output.println("----------------------------");
if (profile.getLibraries().size() > 0) {
printConfigList("Libraries : ", output, profile.getLibraries());
}
if (profile.getRepositories().size() > 0) {
printConfigList("Repositories : ", output, profile.getRepositories());
}
if (profile.getFeatures().size() > 0) {
printConfigList("Features : ", output, profile.getFeatures());
}
if (profile.getBundles().size() > 0) {
printConfigList("Bundles : ", output, profile.getBundles());
}
if (profile.getFabs().size() > 0) {
printConfigList("Fabs : ", output, profile.getFabs());
}
if (profile.getOverrides().size() > 0) {
printConfigList("Overrides : ", output, profile.getOverrides());
}
if (agentProperties.size() > 0) {
printConfigList("Agent Properties : ", output, agentProperties);
}
if (systemProperties.size() > 0) {
printConfigList("System Properties : ", output, systemProperties);
}
if (configProperties.size() > 0) {
printConfigList("Config Properties : ", output, configProperties);
}
configuration.remove(Constants.AGENT_PID);
}
output.println("\nConfiguration details");
output.println("----------------------------");
for (Map.Entry<String, Map<String, String>> cfg : configuration.entrySet()) {
output.println("PID: " + cfg.getKey());
for (Map.Entry<String, String> values : cfg.getValue().entrySet()) {
output.println(" " + values.getKey() + " " + values.getValue());
}
output.println("\n");
}
output.println("\nOther resources");
output.println("----------------------------");
for (Map.Entry<String, byte[]> resource : resources.entrySet()) {
String name = resource.getKey();
if (!name.endsWith(".properties")) {
output.println("Resource: " + resource.getKey());
if (displayResources) {
output.println(new String(resource.getValue(), Charsets.UTF_8));
output.println("\n");
}
}
}
}
use of io.fabric8.api.ProfileService in project fabric8 by jboss-fuse.
the class FabricServiceImpl method validateRequirements.
/**
* Validates the requirements to ensure the profiles exist etc. and
* removes those for a profile that does not exist.
*/
public static void validateRequirements(FabricService fabricService, FabricRequirements requirements) {
ProfileService profileService = fabricService.adapt(ProfileService.class);
String versionId = requirements.getVersion();
Version version;
if (!Strings.isNullOrEmpty(versionId)) {
version = profileService.getRequiredVersion(versionId);
} else {
version = fabricService.getDefaultVersion();
}
Set<String> profileIds = new HashSet<>(Profiles.profileIds(version.getProfiles()));
List<ProfileRequirements> profileRequirements = requirements.getProfileRequirements();
List<String> profilesToBeRemoved = new ArrayList<>();
for (ProfileRequirements profileRequirement : profileRequirements) {
try {
validateProfileRequirements(fabricService, requirements, profileRequirement, profileIds);
} catch (IllegalArgumentException e) {
LOGGER.info("Removing {}; {}", profileRequirement, e.getMessage());
profilesToBeRemoved.add(profileRequirement.getProfile());
}
}
for (String profile : profilesToBeRemoved) {
requirements.removeProfileRequirements(profile);
}
}
use of io.fabric8.api.ProfileService in project fabric8 by jboss-fuse.
the class ContainerImpl method setVersionId.
@Override
public void setVersionId(String versionId) {
String currentId = getVersionId();
if (versionId.compareTo(currentId) != 0) {
ProfileService profileService = fabricService.adapt(ProfileService.class);
Version version = profileService.getRequiredVersion(versionId);
setVersion(version);
}
}
Aggregations