@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()); }
public static void refreshProfile(FabricService fabricService, Profile profile) { LOGGER.info("refreshProfile: {}", profile); ProfileService profileService = fabricService.adapt(ProfileService.class); ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile); Map<String, String> agentConfiguration = builder.getConfiguration(Constants.AGENT_PID); agentConfiguration.put("lastRefresh." + profile.getId(), String.valueOf(System.currentTimeMillis())); builder.addConfiguration(Constants.AGENT_PID, agentConfiguration); profileService.updateProfile(builder.getProfile()); }
public static void refreshProfile(FabricService fabricService, Profile profile) { LOGGER.info("refreshProfile: {}", profile); ProfileService profileService = fabricService.adapt(ProfileService.class); ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile); Map<String, String> agentConfiguration = builder.getConfiguration(Constants.AGENT_PID); agentConfiguration.put("lastRefresh." + profile.getId(), String.valueOf(System.currentTimeMillis())); builder.addConfiguration(Constants.AGENT_PID, agentConfiguration); profileService.updateProfile(builder.getProfile()); }
@Override public boolean setProfileProperties(String versionId, String profileId, String pid, Map<String, String> properties) { boolean answer = false; Version version = profileService.getVersion(versionId); if (version != null) { Profile profile = profileService.getRequiredProfile(versionId, profileId); ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile); Map<String, String> existingConfiguration = builder.getConfiguration(pid); for (Iterator<String> iterator = existingConfiguration.keySet().iterator(); iterator.hasNext(); ) { String key = iterator.next(); if (!properties.containsKey(key)) { iterator.remove(); } } existingConfiguration.putAll(properties); builder.addConfiguration(pid, existingConfiguration); profileService.updateProfile(builder.getProfile()); answer = true; } return answer; }
/** * Adds or remove the specified config properties to the specified profile. * @param configProperties The array of config properties. * @param profile The target profile. */ private void handleConfigProperties(ProfileBuilder builder, String[] configProperties, Profile profile) { Map<String, String> conf = getConfigurationFromBuilder(builder, Constants.AGENT_PID); for (String configProperty : configProperties) { Map<String, String> configMap = extractConfigs(configProperty); for (Map.Entry<String, String> configEntries : configMap.entrySet()) { String key = configEntries.getKey(); String value = configEntries.getValue(); if (append) { System.out.println("Appending value:" + value + " key:" + key + " from config properties and profile:" + profile.getId() + " version:" + versionId); } else if (delete) { System.out.println("Deleting key:" + key + " from config properties and profile:" + profile.getId() + " version:" + versionId); } else if (set) { System.out.println("Setting value:" + value + " key:" + key + " from config properties and profile:" + profile.getId() + " version:" + versionId); } updatedDelimitedList(conf, CONFIG_PREFIX + key, value, delimiter, set, delete, append, remove); } } builder.addConfiguration(Constants.AGENT_PID, conf); }
/** * Adds or remove the specified features to the specified profile. */ private void handleFeatures(ProfileBuilder builder, String[] features, Profile profile) { Map<String, String> conf = getConfigurationFromBuilder(builder, Constants.AGENT_PID); for (String feature : features) { if (delete) { System.out.println("Deleting feature:" + feature + " from profile:" + profile.getId() + " version:" + profile.getVersion()); } else { System.out.println("Adding feature:" + feature + " to profile:" + profile.getId() + " version:" + profile.getVersion()); } updateConfig(conf, FEATURE_PREFIX + feature , feature, set, delete); builder.addConfiguration(Constants.AGENT_PID, conf); } }
/** * Adds or remove the specified feature repositories to the specified profile. */ private void handleFeatureRepositories(ProfileBuilder builder, String[] repositories, Profile profile) { Map<String, String> conf = getConfigurationFromBuilder(builder, Constants.AGENT_PID); for (String repositoryURI : repositories) { if (set) { System.out.println("Adding feature repository:" + repositoryURI + " to profile:" + profile.getId() + " version:" + profile.getVersion()); } else if (delete) { System.out.println("Deleting feature repository:" + repositoryURI + " from profile:" + profile.getId() + " version:" + profile.getVersion()); } updateConfig(conf, REPOSITORY_PREFIX + repositoryURI, repositoryURI, set, delete); } builder.addConfiguration(Constants.AGENT_PID, conf); }
/** * Adds or remove the specified bundles to the specified profile. * @param bundles The array of bundles. * @param profile The target profile. */ private void handleBundles(ProfileBuilder builder, String[] bundles, Profile profile) { Map<String, String> conf = getConfigurationFromBuilder(builder, Constants.AGENT_PID); for (String bundle : bundles) { if (set) { System.out.println("Adding bundle:" + bundle + " to profile:" + profile.getId() + " version:" + profile.getVersion()); } else if (delete) { System.out.println("Deleting bundle:" + bundle + " from profile:" + profile.getId() + " version:" + profile.getVersion()); } updateConfig(conf, BUNDLE_PREFIX + bundle, bundle, set, delete); } builder.addConfiguration(Constants.AGENT_PID, conf); }
/** * Adds or remove the specified fabs to the specified profile. * @param fabs The array of fabs. * @param profile The target profile. */ private void handleFabs(ProfileBuilder builder, String[] fabs, Profile profile) { Map<String, String> conf = getConfigurationFromBuilder(builder, Constants.AGENT_PID); for (String fab : fabs) { if (set) { System.out.println("Adding FAB:" + fab + " to profile:" + profile.getId() + " version:" + profile.getVersion()); } else if (delete) { System.out.println("Deleting FAB:" + fab + " from profile:" + profile.getId() + " version:" + profile.getVersion()); } updateConfig(conf, FAB_PREFIX + fab, fab, set, delete); } builder.addConfiguration(Constants.AGENT_PID, conf); }
/** * Adds or remove the specified overrides to the specified profile. * @param overrides The array of overrides. * @param profile The target profile. */ private void handleOverrides(ProfileBuilder builder, String[] overrides, Profile profile) { Map<String, String> conf = getConfigurationFromBuilder(builder, Constants.AGENT_PID); for (String override : overrides) { if (set) { System.out.println("Adding override:" + override + " to profile:" + profile.getId() + " version:" + profile.getVersion()); } else if (delete) { System.out.println("Deleting override:" + override + " from profile:" + profile.getId() + " version:" + profile.getVersion()); } updateConfig(conf, OVERRIDE_PREFIX + override, override, set, delete); } builder.addConfiguration(Constants.AGENT_PID, conf); }
@Override public String setProfileProperty(String versionId, String profileId, String pid, String propertyName, String value) { Version version = profileService.getVersion(versionId); Profile profile = version.getRequiredProfile(profileId); ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile); Map<String, String> profileProperties = builder.getConfiguration(pid); String answer = profileProperties.put(propertyName, value); builder.addConfiguration(pid, profileProperties); profileService.updateProfile(builder.getProfile()); return answer; }
/** * Adds or remove the specified libraries to the specified profile. * @param libs The array of libs. * @param profile The target profile. * @param libType The type of lib. Used just for the command output. * @param libPrefix The prefix of the lib. */ private void handleLibraries(ProfileBuilder builder, String[] libs, Profile profile, String libType, String libPrefix) { Map<String, String> conf = getConfigurationFromBuilder(builder, Constants.AGENT_PID); for (String lib : libs) { if (set) { System.out.println("Adding "+libType+":" + lib + " to profile:" + profile.getId() + " version:" + profile.getVersion()); } else if (delete) { System.out.println("Deleting "+libType+":" + lib + " from profile:" + profile.getId() + " version:" + profile.getVersion()); } updateConfig(conf, libPrefix + lib, lib, set, delete); } builder.addConfiguration(Constants.AGENT_PID, conf); }
/** * Adds or remove the specified system properties to the specified profile. * @param systemProperties The array of system properties. * @param profile The target profile. */ private void handleSystemProperties(ProfileBuilder builder, String[] systemProperties, Profile profile) { Map<String, String> conf = getConfigurationFromBuilder(builder, Constants.AGENT_PID); for (String systemProperty : systemProperties) { Map<String, String> configMap = extractConfigs(systemProperty); for (Map.Entry<String, String> configEntries : configMap.entrySet()) { String key = configEntries.getKey(); String value = configEntries.getValue(); if (append) { System.out.println("Appending value:" + value + " key:" + key + " from system properties and profile:" + profile.getId() + " version:" + profile.getVersion()); } else if (delete) { System.out.println("Deleting key:" + key + " from system properties and profile:" + profile.getId() + " version:" + profile.getVersion()); } else if (set) { System.out.println("Setting value:" + value + " key:" + key + " from system properties and profile:" + profile.getId() + " version:" + profile.getVersion()); } else { System.out.println("Removing value:" + value + " key:" + key + " from system properties and profile:" + profile.getId() + " version:" + profile.getVersion()); } updatedDelimitedList(conf, SYSTEM_PREFIX + key, value, delimiter, set, delete, append, remove); } } builder.addConfiguration(Constants.AGENT_PID, conf); }
System.out.println("Importing pid:" + currentPid + " to profile:" + profile.getId() + " version:" + profile.getVersion()); importPidFromLocalConfigAdmin(currentPid, conf); builder.addConfiguration(currentPid, conf); return true; builder.addConfiguration(currentPid, conf);
@Override public void setConfigurationValue(String versionId, String profileId, String pid, String key, String value) { assertValid(); Version version = profileService.get().getRequiredVersion(versionId); Profile profile = version.getRequiredProfile(profileId); ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile); Map<String, String> config = builder.getConfiguration(pid); config.put(key, value); builder.addConfiguration(pid, config); profileService.get().updateProfile(builder.getProfile()); }
@Test public void testCreateVersion() throws Exception { ProfileBuilder pbA11 = ProfileBuilder.Factory.create("1.1", "prfA"); Profile prfA = pbA11.addConfiguration("pidA", Collections.singletonMap("keyA", "valA")).getProfile(); VersionBuilder vb11 = VersionBuilder.Factory.create("1.1").addProfile(prfA); VersionState v11 = getProxy().createVersion(new VersionState(vb11.getVersion())); try { Assert.assertEquals("1.1", v11.getId()); Assert.assertTrue(v11.getAttributes().isEmpty()); Assert.assertEquals("valA", v11.getProfileState("prfA").getConfiguration("pidA").get("keyA")); } finally { getProxy().deleteVersion("1.1"); } }
@Test public void testCreateUpdateDeleteProfile() throws Exception { ProfileBuilder pbA10 = ProfileBuilder.Factory.create("1.0", "prfA"); pbA10.addConfiguration("pidA", Collections.singletonMap("keyA", "valA")); ProfileState prfA = getProxy().createProfile(new ProfileState(pbA10.getProfile())); try { Assert.assertEquals("prfA", prfA.getId()); Assert.assertEquals("1.0", prfA.getVersion()); Assert.assertTrue(prfA.getAttributes().isEmpty()); Assert.assertEquals("valA", prfA.getConfiguration("pidA").get("keyA")); // getProfile Assert.assertEquals(prfA.toString(), getProxy().getProfile("1.0", "prfA").toString()); // updateProfile prfA = getProxy().getProfile("1.0", "prfA"); pbA10 = ProfileBuilder.Factory.createFrom(prfA.toProfile()); pbA10.addConfiguration("pidB", "keyB", "valB"); prfA = getProxy().updateProfile(new ProfileState(pbA10.getProfile())); Assert.assertEquals("prfA", prfA.getId()); Assert.assertEquals("1.0", prfA.getVersion()); Assert.assertTrue(prfA.getAttributes().isEmpty()); Assert.assertEquals("valA", prfA.getConfiguration("pidA").get("keyA")); Assert.assertEquals("valB", prfA.getConfiguration("pidB").get("keyB")); } finally { getProxy().deleteProfile("1.0", "prfA", false); } } }
if (defaultProfile == null) { ProfileBuilder prfBuilder = ProfileBuilder.Factory.create(versionId, "default"); prfBuilder.addConfiguration("io.fabric8.jaas", jaasConfig); prfBuilder.addFileConfiguration("io.fabric8.zookeeper.properties", DataStoreUtils.toBytes(zkProps)); Profile profile = prfBuilder.getProfile(); builder.addConfiguration("io.fabric8.jaas", jaasConfig); builder.addFileConfiguration("io.fabric8.zookeeper.properties", DataStoreUtils.toBytes(zkProps)); profileRegistry.updateProfile(builder.getProfile());
builder.addConfiguration(MQ_CONNECTION_FACTORY_PID, config);
if (!Objects.equal(current, webContextPath)) { contextPathConfig.put(key, webContextPath); builder.addConfiguration(Constants.WEB_CONTEXT_PATHS_PID, contextPathConfig);