Search in sources :

Example 41 with Properties

use of org.apache.felix.utils.properties.Properties in project karaf by apache.

the class InstanceServiceImpl method cleanShutdown.

protected void cleanShutdown(InstanceState instance) {
    try {
        File file = new File(new File(instance.loc, "etc"), CONFIG_PROPERTIES_FILE_NAME);
        Properties props = PropertiesLoader.loadPropertiesFile(file.toURI().toURL(), false);
        props.put("karaf.base", new File(instance.loc).getCanonicalPath());
        props.put("karaf.home", System.getProperty("karaf.home"));
        props.put("karaf.data", new File(new File(instance.loc), "data").getCanonicalPath());
        props.put("karaf.etc", new File(new File(instance.loc), "etc").getCanonicalPath());
        InterpolationHelper.performSubstitution(props, null, true, false, true);
        int port = Integer.parseInt(props.getProperty(KARAF_SHUTDOWN_PORT, "0"));
        String host = props.getProperty(KARAF_SHUTDOWN_HOST, "localhost");
        String portFile = props.getProperty(KARAF_SHUTDOWN_PORT_FILE);
        String shutdown = props.getProperty(KARAF_SHUTDOWN_COMMAND, DEFAULT_SHUTDOWN_COMMAND);
        if (port == 0 && portFile != null) {
            BufferedReader r = new BufferedReader(new InputStreamReader(new FileInputStream(portFile)));
            String portStr = r.readLine();
            port = Integer.parseInt(portStr);
            r.close();
        }
        // We found the port, try to send the command
        if (port > 0) {
            Socket s = new Socket(host, port);
            s.getOutputStream().write(shutdown.getBytes());
            s.close();
            long stopTimeout = Long.parseLong(props.getProperty(KARAF_SHUTDOWN_TIMEOUT, Long.toString(getStopTimeout())));
            long t = System.currentTimeMillis() + stopTimeout;
            do {
                Thread.sleep(100);
                checkPid(instance);
            } while (System.currentTimeMillis() < t && instance.pid > 0);
        }
    } catch (Exception e) {
        LOGGER.debug("Unable to cleanly shutdown instance " + instance.name, e);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) TypedProperties(org.apache.felix.utils.properties.TypedProperties) Properties(org.apache.felix.utils.properties.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream) Socket(java.net.Socket) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Example 42 with Properties

use of org.apache.felix.utils.properties.Properties in project karaf by apache.

the class InstanceServiceImpl method loadPropertiesFile.

protected static Properties loadPropertiesFile(URL configPropURL) throws Exception {
    try (InputStream is = configPropURL.openConnection().getInputStream()) {
        Properties configProps = new Properties();
        configProps.load(is);
        return configProps;
    } catch (Exception ex) {
        System.err.println("Error loading config properties from " + configPropURL);
        System.err.println("Main: " + ex);
        return null;
    }
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) TypedProperties(org.apache.felix.utils.properties.TypedProperties) Properties(org.apache.felix.utils.properties.Properties) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Example 43 with Properties

use of org.apache.felix.utils.properties.Properties in project karaf by apache.

the class SystemServiceImpl method setSystemProperty.

@Override
public String setSystemProperty(String key, String value, boolean persist) {
    if (persist) {
        try {
            String etc = System.getProperty("karaf.etc");
            Properties props = new Properties(new File(etc, "system.properties"));
            props.put(key, value);
            props.save();
        } catch (IOException e) {
            throw new RuntimeException("Error persisting system property", e);
        }
    }
    return System.setProperty(key, value);
}
Also used : IOException(java.io.IOException) Properties(org.apache.felix.utils.properties.Properties) File(java.io.File)

Example 44 with Properties

use of org.apache.felix.utils.properties.Properties in project karaf by apache.

the class SystemServiceImpl method setFrameworkDebug.

public void setFrameworkDebug(boolean debug) {
    try {
        Properties properties = loadProps();
        if (debug) {
            properties.put("felix.log.level", "4");
            properties.put("osgi.debug", "etc/equinox-debug.properties");
        } else {
            properties.remove("felix.log.level");
            properties.remove("osgi.debug");
        }
        // TODO populate the equinox-debug.properties file with the one provided in shell/dev module
        properties.save();
    } catch (IOException e) {
        throw new RuntimeException("Error setting framework debugging: " + e.getMessage(), e);
    }
}
Also used : IOException(java.io.IOException) Properties(org.apache.felix.utils.properties.Properties)

Example 45 with Properties

use of org.apache.felix.utils.properties.Properties in project karaf by apache.

the class SystemServiceImpl method setName.

@Override
public void setName(String name) {
    try {
        String karafEtc = bundleContext.getProperty("karaf.etc");
        File etcDir = new File(karafEtc);
        File syspropsFile = new File(etcDir, "system.properties");
        FileInputStream fis = new FileInputStream(syspropsFile);
        Properties props = new Properties();
        props.load(fis);
        fis.close();
        props.setProperty("karaf.name", name);
        FileOutputStream fos = new FileOutputStream(syspropsFile);
        props.store(fos, "");
        fos.close();
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) Properties(org.apache.felix.utils.properties.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Aggregations

Properties (org.apache.felix.utils.properties.Properties)64 File (java.io.File)26 Test (org.junit.Test)22 IOException (java.io.IOException)21 Subject (javax.security.auth.Subject)21 NamePasswordCallbackHandler (org.apache.karaf.jaas.modules.NamePasswordCallbackHandler)21 RolePrincipal (org.apache.karaf.jaas.boot.principal.RolePrincipal)16 UserPrincipal (org.apache.karaf.jaas.boot.principal.UserPrincipal)16 Principal (java.security.Principal)12 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 GroupPrincipal (org.apache.karaf.jaas.boot.principal.GroupPrincipal)6 Map (java.util.Map)5 AbstractKerberosITest (org.apache.directory.server.kerberos.kdc.AbstractKerberosITest)5 FileInputStream (java.io.FileInputStream)4 MalformedURLException (java.net.MalformedURLException)4 URL (java.net.URL)4 LinkedHashMap (java.util.LinkedHashMap)4 TreeMap (java.util.TreeMap)4 FailedLoginException (javax.security.auth.login.FailedLoginException)4