Search in sources :

Example 1 with SystemProperties

use of io.fabric8.api.SystemProperties in project fabric8 by jboss-fuse.

the class Log4jLogQuery method loadCoords.

protected String loadCoords(String coords, String filePath, String classifier) throws IOException {
    String[] split = coords.split("/");
    if (split != null && split.length > 2) {
        String groupId = split[0];
        String artifactId = split[1];
        String version = split[2];
        if (resolver == null) {
            Properties defaultProperties = getDefaultProperties();
            Properties systemProperties = System.getProperties();
            if (config == null) {
                Properties combined = new Properties();
                combined.putAll(defaultProperties);
                combined.putAll(systemProperties);
                if (properties != null) {
                    combined.putAll(properties);
                }
                config = new MavenConfigurationImpl(new PropertiesPropertyResolver(combined), ServiceConstants.PID);
            }
            resolver = new AetherBasedResolver(config);
        }
        File file = resolver.resolveFile(groupId, artifactId, classifier, "jar", version);
        if (file.exists() && file.isFile()) {
            if (isRoot(filePath)) {
                return jarIndex(file);
            }
            String fileUri = file.toURI().toString();
            URL url = new URL("jar:" + fileUri + "!" + filePath);
            return loadString(url);
        }
    }
    return null;
}
Also used : MavenConfigurationImpl(io.fabric8.maven.util.MavenConfigurationImpl) PropertiesPropertyResolver(org.ops4j.util.property.PropertiesPropertyResolver) Properties(java.util.Properties) File(java.io.File) URL(java.net.URL) AetherBasedResolver(io.fabric8.maven.url.internal.AetherBasedResolver)

Example 2 with SystemProperties

use of io.fabric8.api.SystemProperties 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 3 with SystemProperties

use of io.fabric8.api.SystemProperties in project fabric8 by jboss-fuse.

the class ProfileEditAction method editProfile.

private void editProfile(Profile profile) throws Exception {
    boolean editInLine = false;
    ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile);
    if (delete || remove) {
        editInLine = true;
    }
    if (features != null && features.length > 0) {
        editInLine = true;
        handleFeatures(builder, features, profile);
    }
    if (repositories != null && repositories.length > 0) {
        editInLine = true;
        handleFeatureRepositories(builder, repositories, profile);
    }
    if (libs != null && libs.length > 0) {
        editInLine = true;
        handleLibraries(builder, libs, profile, "lib", LIB_PREFIX);
    }
    if (endorsed != null && endorsed.length > 0) {
        editInLine = true;
        handleLibraries(builder, endorsed, profile, "endorsed lib", ENDORSED_PREFIX);
    }
    if (extension != null && extension.length > 0) {
        editInLine = true;
        handleLibraries(builder, extension, profile, "extension lib", EXT_PREFIX);
    }
    if (bundles != null && bundles.length > 0) {
        editInLine = true;
        handleBundles(builder, bundles, profile);
    }
    if (fabs != null && fabs.length > 0) {
        editInLine = true;
        handleFabs(builder, fabs, profile);
    }
    if (overrides != null && overrides.length > 0) {
        editInLine = true;
        handleOverrides(builder, overrides, profile);
    }
    if (pidProperties != null && pidProperties.length > 0) {
        editInLine = handlePid(builder, pidProperties, profile);
    }
    if (systemProperties != null && systemProperties.length > 0) {
        editInLine = true;
        handleSystemProperties(builder, systemProperties, profile);
    }
    if (configProperties != null && configProperties.length > 0) {
        editInLine = true;
        handleConfigProperties(builder, configProperties, profile);
    }
    if (resource != null && delete) {
        editInLine = true;
        builder.deleteFileConfiguration(resource);
    }
    profileService.updateProfile(builder.getProfile());
    if (!editInLine) {
        resource = resource != null ? resource : "io.fabric8.agent.properties";
        // then open the resource in the editor.
        if (pidProperties != null && pidProperties.length == 1) {
            resource = pidProperties[0] + ".properties";
        }
        openInEditor(profile, resource);
    }
}
Also used : ProfileBuilder(io.fabric8.api.ProfileBuilder)

Example 4 with SystemProperties

use of io.fabric8.api.SystemProperties in project fabric8 by jboss-fuse.

the class FabricServiceImpl method getEnvironment.

@Override
public String getEnvironment() {
    assertValid();
    String answer = runtimeProperties.get().getProperty(SystemProperties.FABRIC_ENVIRONMENT);
    if (answer == null) {
        // in case we've not updated the system properties in the JVM based on the profile
        // e.g. when adding/removing profiles
        Container currentContainer = getCurrentContainer();
        if (currentContainer != null) {
            Map<String, String> systemProperties = currentContainer.getOverlayProfile().getConfiguration(Constants.SYSTEM_PROPERTIES_PID);
            answer = systemProperties.get(SystemProperties.FABRIC_ENVIRONMENT);
        }
        // lets store the effective profile for later on
        if (answer != null) {
            System.setProperty(SystemProperties.FABRIC_PROFILE_ENVIRONMENT, answer);
        }
    }
    return answer;
}
Also used : Container(io.fabric8.api.Container)

Example 5 with SystemProperties

use of io.fabric8.api.SystemProperties in project fabric8 by jboss-fuse.

the class FabricManager method setProfileSystemProperties.

@Override
public void setProfileSystemProperties(String versionId, String profileId, Map<String, String> systemProperties) {
    Version version = profileService.getVersion(versionId);
    Profile profile = version.getRequiredProfile(profileId);
    ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile);
    Map<String, String> profileProperties = builder.getConfiguration(Constants.AGENT_PID);
    // remove those that are not present in passed systemProperties
    for (Iterator<Map.Entry<String, String>> iterator = profileProperties.entrySet().iterator(); iterator.hasNext(); ) {
        Map.Entry<String, String> entry = iterator.next();
        if (entry.getKey().startsWith("system.")) {
            String propertyName = entry.getKey().substring("system.".length());
            if (!systemProperties.containsKey(propertyName)) {
                iterator.remove();
            }
        }
    }
    // add changed
    for (String k : systemProperties.keySet()) {
        profileProperties.put("system." + k, systemProperties.get(k));
    }
    builder.addConfiguration(Constants.AGENT_PID, profileProperties);
    profileService.updateProfile(builder.getProfile());
}
Also used : GitVersion(io.fabric8.api.commands.GitVersion) Version(io.fabric8.api.Version) ProfileBuilder(io.fabric8.api.ProfileBuilder) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) Profile(io.fabric8.api.Profile)

Aggregations

ProfileBuilder (io.fabric8.api.ProfileBuilder)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Container (io.fabric8.api.Container)1 Profile (io.fabric8.api.Profile)1 ProfileService (io.fabric8.api.ProfileService)1 Version (io.fabric8.api.Version)1 GitVersion (io.fabric8.api.commands.GitVersion)1 AetherBasedResolver (io.fabric8.maven.url.internal.AetherBasedResolver)1 MavenConfigurationImpl (io.fabric8.maven.util.MavenConfigurationImpl)1 File (java.io.File)1 PrintStream (java.io.PrintStream)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Properties (java.util.Properties)1 TreeMap (java.util.TreeMap)1 PropertiesPropertyResolver (org.ops4j.util.property.PropertiesPropertyResolver)1