Search in sources :

Example 51 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 52 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 53 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 54 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 55 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)95 IOException (java.io.IOException)35 File (java.io.File)33 Test (org.junit.Test)27 Subject (javax.security.auth.Subject)25 NamePasswordCallbackHandler (org.apache.karaf.jaas.modules.NamePasswordCallbackHandler)21 Path (java.nio.file.Path)13 HashMap (java.util.HashMap)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)9 FileInputStream (java.io.FileInputStream)8 URL (java.net.URL)8 MalformedURLException (java.net.MalformedURLException)7 HashSet (java.util.HashSet)6 Hashtable (java.util.Hashtable)6 LinkedHashMap (java.util.LinkedHashMap)6 TreeMap (java.util.TreeMap)6 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 FileNotFoundException (java.io.FileNotFoundException)5 LoginException (javax.security.auth.login.LoginException)5