Search in sources :

Example 26 with ProfileService

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);
        }
    }
}
Also used : ProfileService(io.fabric8.api.ProfileService) Profile(io.fabric8.api.Profile)

Example 27 with ProfileService

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;
}
Also used : ProfileService(io.fabric8.api.ProfileService) Version(io.fabric8.api.Version) Profile(io.fabric8.api.Profile)

Example 28 with ProfileService

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");
            }
        }
    }
}
Also used : PrintStream(java.io.PrintStream) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ProfileService(io.fabric8.api.ProfileService) HashMap(java.util.HashMap) Map(java.util.Map)

Example 29 with ProfileService

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);
    }
}
Also used : ProfileService(io.fabric8.api.ProfileService) ProfileRequirements(io.fabric8.api.ProfileRequirements) Version(io.fabric8.api.Version) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 30 with ProfileService

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);
    }
}
Also used : ProfileService(io.fabric8.api.ProfileService) Version(io.fabric8.api.Version)

Aggregations

ProfileService (io.fabric8.api.ProfileService)36 Profile (io.fabric8.api.Profile)22 Version (io.fabric8.api.Version)12 HashMap (java.util.HashMap)10 ArrayList (java.util.ArrayList)8 FabricService (io.fabric8.api.FabricService)7 Map (java.util.Map)6 Parser (io.fabric8.maven.util.Parser)5 File (java.io.File)5 HashSet (java.util.HashSet)5 ProfileBuilder (io.fabric8.api.ProfileBuilder)4 DownloadManager (io.fabric8.agent.download.DownloadManager)3 Feature (io.fabric8.agent.model.Feature)3 MalformedURLException (java.net.MalformedURLException)3 Container (io.fabric8.api.Container)2 ProfileRequirements (io.fabric8.api.ProfileRequirements)2 IOException (java.io.IOException)2 URL (java.net.URL)2 LinkedHashSet (java.util.LinkedHashSet)2 LinkedList (java.util.LinkedList)2