Package org.osgi.service.cm

Examples of org.osgi.service.cm.Configuration


            p.save();
            this.session.put(PROPERTY_CONFIG_PID, null);
            this.session.put(PROPERTY_CONFIG_PROPS, null);
        } else {
            String pid = (String) this.session.get(PROPERTY_CONFIG_PID);
            Configuration cfg = admin.getConfiguration(pid, null);
            cfg.update(props);
            this.session.put(PROPERTY_CONFIG_PID, null);
            this.session.put(PROPERTY_CONFIG_PROPS, null);
        }
    }
View Full Code Here


       
        session = new MockCommandSession();
    }
   
    public void testExecuteOnExistingPid() throws Exception {       
        Configuration config = createMock(Configuration.class);
        expect(admin.getConfiguration(PID)).andReturn(config);
        replay(admin);
       
        // the ConfigAdmin service returns a Dictionary for an existing PID
        Properties props = new Properties();
        expect(config.getProperties()).andReturn(props);
        replay(config);
       
        command.pid = PID;
        command.execute(session);
       
View Full Code Here

                   props, session.get(ConfigCommandSupport.PROPERTY_CONFIG_PROPS));
    }
   
    @SuppressWarnings("unchecked")
    public void testExecuteOnNewPid() throws Exception {       
        Configuration config = createMock(Configuration.class);
        expect(admin.getConfiguration(PID)).andReturn(config);
        replay(admin);
       
        // the ConfigAdmin service does not return a Dictionary for a new PID
        expect(config.getProperties()).andReturn(null);
        replay(config);
       
        command.pid = PID;
        command.execute(session);
View Full Code Here

            doInstallFeature(state, fi, verbose);
        }
        for (String config : feature.getConfigurations().keySet()) {
            Dictionary<String,String> props = new Hashtable<String, String>(feature.getConfigurations().get(config));
            String[] pid = parsePid(config);
            Configuration cfg = findExistingConfiguration(configAdmin, pid[0], pid[1]);
            if (cfg == null) {
                cfg = createConfiguration(configAdmin, pid[0], pid[1]);
                String key = (pid[1] == null ? pid[0] : pid[0] + "-" + pid[1]);
                props.put(CONFIG_KEY, key);
                if (cfg.getBundleLocation() != null) {
                    cfg.setBundleLocation(null);
                }
                cfg.update(props);
            }
        }
        for (ConfigFileInfo configFile : feature.getConfigurationFiles()) {
          installConfigurationFile(configFile.getLocation(), configFile.getFinalname(), verbose);
        }
View Full Code Here

     * @param api
     * @return
     * @throws java.io.IOException
     */
    protected Configuration findOrCreateFactoryConfiguration(ConfigurationAdmin configurationAdmin, String factoryPid, String id, String api) throws IOException {
        Configuration configuration = null;
        if (configurationAdmin != null) {
            try {
                Configuration[] configurations = configurationAdmin.listConfigurations(String.format(FACTORY_FILTER, factoryPid));
                if (configurations != null) {
                    for (Configuration conf : configurations) {
View Full Code Here

  @Argument(index = 0, required = true, multiValued = false, description = "The service id. Used to distinct between multiple service of the same provider/api. Only ")
  protected String id;

   @Override
   protected Object doExecute() throws Exception {
      Configuration configuration = findOrCreateFactoryConfiguration(configAdmin, "org.jclouds.chef", id, null);
      if (configuration != null) {
         configuration.delete();
      } else {
         System.out.println("No service found with id " + id);
      }
      return null;
   }
View Full Code Here

                                     final Map<String, String> props) throws Exception {
        Runnable registrationTask = new Runnable() {
            @Override
            public void run() {
                try {
                    Configuration configuration = findOrCreateFactoryConfiguration(configurationAdmin, "org.jclouds.chef", name, api);
                    if (configuration != null) {
                        @SuppressWarnings("unchecked")
                        Dictionary<String, Object> dictionary = configuration.getProperties();
                        if (dictionary == null) {
                            dictionary = new Hashtable<String, Object>();
                        }

                        String apiValue = ChefHelper.getChefApi(api);
                        String clientNameValue = ChefHelper.getClientName(clientName);
                        String clientKeyFileValue = ChefHelper.getClientKeyFile(clientKeyFile);
                        String validatorNameValue = ChefHelper.getValidatorName(validator);
                        String validatorKeyFileValue = ChefHelper.getValidatorKeyFile(validatorKeyFile);
                        String endpointValue = ChefHelper.getChefEndpoint(endpoint);

                        if (name != null) {
                            dictionary.put(ChefConstants.NAME, name);
                        }
                        if (apiValue != null) {
                            dictionary.put(ChefConstants.API, apiValue);
                        }
                        if (endpointValue != null) {
                            dictionary.put(ChefConstants.ENDPOINT, endpointValue);
                        }
                        if (clientNameValue != null) {
                            dictionary.put(ChefConstants.CLIENT_NAME, clientNameValue);
                        }
                        if (clientKeyFileValue != null) {
                            dictionary.put(ChefConstants.CLIENT_KEY_FILE, clientKeyFileValue);
                        }
                        if (validatorNameValue != null) {
                            dictionary.put(ChefConstants.VALIDATOR_NAME, validatorNameValue);
                        }
                        if (validatorKeyFileValue != null) {
                            dictionary.put(ChefConstants.VALIDATOR_KEY_FILE, validatorKeyFileValue);
                        }

                        for (Map.Entry<String, String> entry : props.entrySet()) {
                            String key = entry.getKey();
                            String value = entry.getValue();
                            dictionary.put(key, value);
                        }
                        configuration.update(dictionary);
                    }
                } catch (Exception ex) {
                    // noop
                }
            }
View Full Code Here

                }
                // try to get the configadmin
                final ConfigurationAdmin configAdmin = (ConfigurationAdmin) this.bundleContext
                        .getService(sr);
                if (configAdmin != null) {
                    Configuration config;
                    if (pid == null || pid.length() == 0) {
                        config = configAdmin.createFactoryConfiguration(LogConfigManager.FACTORY_PID_CONFIGS);
                    } else {
                        config = configAdmin.getConfiguration(pid);
                    }
                    if (config != null) {
                        Dictionary<String, Object> dict = new Hashtable<String, Object>();
                        dict.put(LogConfigManager.LOG_LEVEL, logLevel.toLowerCase());
                        dict.put(LogConfigManager.LOG_LOGGERS, loggers);
                        dict.put(LogConfigManager.LOG_FILE, logFile);
                        config.update(dict);
                    }
                }
            } finally {
                // release the configadmin reference
                this.bundleContext.ungetService(sr);
View Full Code Here

                // try to get the configadmin
                final ConfigurationAdmin configAdmin = (ConfigurationAdmin) this.bundleContext
                        .getService(sr);
                if (configAdmin != null) {
                    try {
                        Configuration config = configAdmin.getConfiguration(pid);
                        if (config != null) {
                            config.delete();
                        } else {
                            throw new ConfigurationException(LogConfigManager.PID,
                                    "No configuration for this PID:" + pid);
                        }
                    } catch (IOException ioe) {
View Full Code Here

            } else {
               initDefaultConfig(defaultConfig, bundleContext);
            }

            // create the factory and set the properties
            Configuration config = ca.createFactoryConfiguration(SERVER_REPOSITORY_FACTORY_PID);
            config.update(defaultConfig);

            log.info("verifyConfiguration: Created configuration {} for {}",
                config.getPid(), config.getFactoryPid());

        } catch (Throwable t) {
            log.error(
                "verifyConfiguration: Cannot check or define configuration", t);
        } finally {
View Full Code Here

TOP

Related Classes of org.osgi.service.cm.Configuration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.