@Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { if (exc != null) { throw exc; } if (builder != null) { Profile profile = builder.getProfile(); profiles.put(profile.getId(), profile); builder = null; } return FileVisitResult.CONTINUE; } @Override
@Override public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException { if (exc != null) { throw exc; } if (builder != null) { Profile profile = builder.getProfile(); profiles.put(profile.getId(), profile); builder = null; } return FileVisitResult.CONTINUE; } @Override
static void applyProfiles(File karafBase, List<String> profiles, boolean printOutput) throws IOException { BundleContext bundleContext = FrameworkUtil.getBundle(ProfileApplier.class).getBundleContext(); ServiceReference<ProfileService> reference = bundleContext.getServiceReference(ProfileService.class); ProfileService service = bundleContext.getService(reference); Profile profile = ProfileBuilder.Factory.create("temp") .addParents(profiles) .getProfile(); Profile overlay = service.getOverlayProfile(profile); final Profile effective = service.getEffectiveProfile(overlay, false); Map<String, byte[]> configs = effective.getFileConfigurations(); for (Map.Entry<String, byte[]> config : configs.entrySet()) { String pid = config.getKey(); if (!pid.equals(Profile.INTERNAL_PID + Profile.PROPERTIES_SUFFIX)) { Path configFile = Paths.get(karafBase.toString(), "etc", pid); logDebug("Creating file: %s", printOutput, configFile.toString()); Files.write(configFile, config.getValue()); } } FileLockUtils.execute(new File(karafBase, FEATURES_CFG), properties -> { appendToPropList(properties, "featuresBoot", effective.getFeatures()); appendToPropList(properties, "featuresRepositories", effective.getRepositories()); }, true); bundleContext.ungetService(reference); }
@Override public void create(String name, List<String> parents) { Profile profile = ProfileBuilder.Factory.create(name) .setParents(parents) .getProfile(); profileService.createProfile(profile); }
@Override public Object execute() throws Exception { Profile profile = ProfileBuilder.Factory.create(profileId) .setParents(parents) .getProfile(); profileService.createProfile(profile); return null; }
@Override public void create(String name, List<String> parents) { Profile profile = ProfileBuilder.Factory.create(name) .setParents(parents) .getProfile(); profileService.createProfile(profile); }
@Override public Object execute() throws Exception { Profile profile = ProfileBuilder.Factory.create(profileId) .setParents(parents) .getProfile(); profileService.createProfile(profile); return null; }
@Override public void copy(String source, String target) { Profile profile = ProfileBuilder.Factory.createFrom(profileService.getProfile(source)) .identity(target) .getProfile(); profileService.createProfile(profile); }
@Override public Object execute() throws Exception { Profile profile = ProfileBuilder.Factory.createFrom(profileService.getProfile(source)) .identity(target) .getProfile(); profileService.createProfile(profile); return null; }
@Override public Object execute() throws Exception { Profile profile = profileService.getRequiredProfile(profileId); Profile newProfile = ProfileBuilder.Factory.createFrom(profile) .addParents(parentIds) .getProfile(); profileService.updateProfile(newProfile); return null; }
@Override public void copy(String source, String target) { Profile profile = ProfileBuilder.Factory.createFrom(profileService.getProfile(source)) .identity(target) .getProfile(); profileService.createProfile(profile); }
@Override public Object execute() throws Exception { Profile profile = ProfileBuilder.Factory.createFrom(profileService.getProfile(source)) .identity(target) .getProfile(); profileService.createProfile(profile); return null; }
@Override public Object execute() throws Exception { Profile profile = profileService.getRequiredProfile(profileId); Profile newProfile = ProfileBuilder.Factory.createFrom(profile) .addParents(parentIds) .getProfile(); profileService.updateProfile(newProfile); return null; }
@Override public void rename(String name, String newName) { Profile profile = ProfileBuilder.Factory.createFrom(profileService.getProfile(name)) .identity(newName) .getProfile(); profileService.createProfile(profile); profileService.deleteProfile(name); }
/** * Generate internal profile (for the purpose of custom assembly builder) for given <code>stage</code>. * @param stage a {@link Stage} for which the profile is being generated * @param parentProfiles all profiles for given stage will be used as parent profiles * @param repositories repositories to use in generated profile * @param features features to declare in generated profile * @param bundles bundles to declare in generated profile * @return */ private Profile generateProfile(Stage stage, Map<String, Stage> parentProfiles, Map<String, RepositoryInfo> repositories, Map<String, Stage> features, Map<String, Stage> bundles) { String name = "generated-" + stage.name().toLowerCase(); List<String> stagedParentProfiles = getStaged(stage, parentProfiles); if (stagedParentProfiles.isEmpty()) { LOGGER.info("Generating {} profile", name); } else { LOGGER.info("Generating {} profile with parents: {}", name, stagedParentProfiles.stream().collect(Collectors.joining(", "))); } return ProfileBuilder.Factory.create(name) .setParents(stagedParentProfiles) .setRepositories(getStagedRepositories(stage, repositories)) .setFeatures(getStaged(stage, features)) .setBundles(getStaged(stage, bundles)) .getProfile(); }
@Override public Object execute() throws Exception { Profile profile = ProfileBuilder.Factory.createFrom(profileService.getProfile(profileName)) .identity(newName) .getProfile(); profileService.createProfile(profile); profileService.deleteProfile(profileName); return null; }
@Override public Object execute() throws Exception { Profile profile = ProfileBuilder.Factory.createFrom(profileService.getProfile(profileName)) .identity(newName) .getProfile(); profileService.createProfile(profile); profileService.deleteProfile(profileName); return null; }
@Override public void rename(String name, String newName) { Profile profile = ProfileBuilder.Factory.createFrom(profileService.getProfile(name)) .identity(newName) .getProfile(); profileService.createProfile(profile); profileService.deleteProfile(name); }
/** * <p>Gets an <em>overlay</em> profile for given <code>profile</code>, where passed in map of additional profiles * is searched for possible parent profiles of given <code>profile</code>.</p> * <p><code>environment</code> may be used to select different <em>variants</em> of profile configuration files. * For example, if <code>environment</code> is specified, configuration for <code>my.pid</code> PID will be read * from <code>my.pid.cfg#<environment></code>.</p> * @param profile * @param profiles * @param environment * @return */ public static Profile getOverlay(Profile profile, Map<String, Profile> profiles, String environment) { assertNotNull(profile, "profile is null"); assertNotNull(profile, "profiles is null"); if (profile.isOverlay()) { return profile; } else { String profileId = profile.getId(); ProfileBuilder builder = ProfileBuilder.Factory.create(profileId); new OverlayOptionsProvider(profiles, profile, environment).addOptions(builder); return builder.getProfile(); } }
/** * <p>Gets an <em>overlay</em> profile for given <code>profile</code>, where passed in map of additional profiles * is searched for possible parent profiles of given <code>profile</code>.</p> * <p><code>environment</code> may be used to select different <em>variants</em> of profile configuration files. * For example, if <code>environment</code> is specified, configuration for <code>my.pid</code> PID will be read * from <code>my.pid.cfg#<environment></code>.</p> * @param profile * @param profiles * @param environment * @return */ public static Profile getOverlay(Profile profile, Map<String, Profile> profiles, String environment) { assertNotNull(profile, "profile is null"); assertNotNull(profile, "profiles is null"); if (profile.isOverlay()) { return profile; } else { String profileId = profile.getId(); ProfileBuilder builder = ProfileBuilder.Factory.create(profileId); new OverlayOptionsProvider(profiles, profile, environment).addOptions(builder); return builder.getProfile(); } }