private static String substituteFromProfile(FabricService fabricService, Map<String, Map<String, String>> configs, String pid, String key) { Map<String, String> configuration = configs.get(pid); if (configuration != null && configuration.containsKey(key)) { return configuration.get(key); } else { // lets default to the current container if a version doesn't exist in a different profile Profile overlayProfile = fabricService.getCurrentContainer().getOverlayProfile(); Profile effectiveProfile = Profiles.getEffectiveProfile(fabricService, overlayProfile); configuration = effectiveProfile.getConfiguration(pid); if (configuration != null && configuration.containsKey(key)) { return configuration.get(key); } else { return EMPTY; } } }
public void refreshProfile(String versionId, String profileId) { Version version = profileService.getVersion(versionId); if (version != null) { Profile profile = version.getRequiredProfile(profileId); if (profile != null) { Profiles.refreshProfile(fabricService, profile); } } }
/** * Takes a profile ID of the form "foo-bar" and if we are using directory trees for profiles then * converts it to "foo/bar.profile" */ public static String convertProfileIdToDirectory(String profileId) { return Profiles.convertProfileIdToPath(profileId); }
Profile lastOverlay = audit.overlayProfiles.get(profileId); if (lastOverlay == null) { LOGGER.debug("Overlay" + Profiles.getProfileInfo(overlayProfile)); audit.overlayProfiles.put(profileId, overlayProfile); } else if (!lastOverlay.equals(overlayProfile)) { LOGGER.debug("Overlay" + Profiles.getProfileDifference(lastOverlay, overlayProfile)); audit.overlayProfiles.put(profileId, overlayProfile);
/** * Returns links to the profiles implemented by this container */ @GET @Path("profiles") public Map<String, String> profiles() { if (container != null) { List<String> profileIds = Profiles.profileIds(container.getProfiles()); return mapToLinks(profileIds, "profile/"); } return Collections.EMPTY_MAP; }
/** * Returns the overlay configuration for the given list of profile ids and the configuration PID. * * This method will find the overlay profile for each profile id and combine all the configurations together. * * Usually we would use the Profile objects directly; but this API call is useful when creating new containers; letting us * figure out the effective overlay before a container exists. */ public static Map<String, String> getOverlayConfiguration(FabricService fabricService, Iterable<String> profileIds, String versionId, String pid) { String environment = fabricService.getEnvironment(); return getOverlayConfiguration(fabricService, profileIds, versionId, pid, environment); }
List<String> profileIds = Profiles.profileIds(container.getProfiles()); String profileLinkPrefix = baseApiLink + "/version/" + Profiles.versionId(container.getVersion()) + "/profile/"; answer.setProfiles(Links.mapIdsToLinks(profileIds, profileLinkPrefix)); answer.setVersion(Profiles.versionId(container.getVersion())); answer.setParent(Containers.containerId(container.getParent()));
@Override public void renameProfile(String versionId, String profileId, String newId, boolean force) { Version v = profileService.getVersion(versionId); if (v != null) { Profiles.renameProfile(fabricService, versionId, profileId, newId, force); } }
@Override public void copyProfile(String versionId, String sourceId, String targetId, boolean force) { Version v = profileService.getVersion(versionId); if (v != null) { Profiles.copyProfile(fabricService, versionId, sourceId, targetId, force); } }
LOGGER.debug("Create {}", Profiles.getProfileInfo(profile)); } else { LOGGER.debug("Update {}", profile); LOGGER.debug("Update {}", Profiles.getProfileDifference(lastProfile, profile));
@GET @Path("profiles") public Map<String, String> profiles() { if (version != null) { List<String> profileIds = Profiles.profileIds(version.getProfiles()); return mapToLinks(profileIds, "profile/"); } return Collections.EMPTY_MAP; }
/** * Returns the overlay configuration for the given list of profile ids and the configuration PID. * * This method will find the overlay profile for each profile id and combine all the configurations together. * * Usually we would use the Profile objects directly; but this API call is useful when creating new containers; letting us * figure out the effective overlay before a container exists. */ public static Map<String, String> getOverlayConfiguration(FabricService fabricService, Iterable<String> profileIds, String versionId, String pid) { String environment = fabricService.getEnvironment(); return getOverlayConfiguration(fabricService, profileIds, versionId, pid, environment); }
List<String> profileIds = Profiles.profileIds(container.getProfiles()); String profileLinkPrefix = baseApiLink + "/version/" + Profiles.versionId(container.getVersion()) + "/profile/"; answer.setProfiles(Links.mapIdsToLinks(profileIds, profileLinkPrefix)); answer.setVersion(Profiles.versionId(container.getVersion())); answer.setParent(Containers.containerId(container.getParent()));
@Override protected Object doExecute() throws Exception { // do not validate the old name in case a profile was created somehow with invalid name // but validate the new name try { FabricValidations.validateProfileName(newName); } catch (IllegalArgumentException e) { // we do not want exception in the server log, so print the error message to the console System.out.println(e.getMessage()); return null; } Version version; if (versionId != null) { version = profileService.getRequiredVersion(versionId); } else { version = fabricService.getDefaultVersion(); } if (!version.hasProfile(profileName)) { System.out.println("Profile " + profileName + " not found."); return null; } else if (version.hasProfile(newName)) { if (!force) { System.out.println("New name " + newName + " already exists. Use --force if you want to overwrite."); return null; } } Profiles.renameProfile(fabricService, versionId, profileName, newName, force); return null; }
@Override protected Object doExecute() throws Exception { // do not validate the old name in case a profile was created somehow with invalid name // but validate the target name try { FabricValidations.validateProfileName(target); } catch (IllegalArgumentException e) { // we do not want exception in the server log, so print the error message to the console System.out.println(e.getMessage()); return null; } Version version = versionParam != null ? profileService.getRequiredVersion(versionParam) : fabricService.getRequiredDefaultVersion(); String versionId = version.getId(); if (!version.hasProfile(source)) { System.out.println("Source profile " + source + " not found."); return null; } else if (version.hasProfile(target)) { if (!force) { System.out.println("Target profile " + target + " already exists. Use --force if you want to overwrite."); return null; } } Profiles.copyProfile(fabricService, versionId, source, target, force); return null; }
@Override public InputStream getInputStream() throws IOException { assertValid(); String path = url.getPath(); URL url = new URL(path); CompiledTemplate compiledTemplate = TemplateCompiler.compileTemplate(url.openStream()); Map<String, Object> data = new HashMap<String, Object>(); Profile overlayProfile = fabricService.get().getCurrentContainer().getOverlayProfile(); data.put("profile", Profiles.getEffectiveProfile(fabricService.get(), overlayProfile)); data.put("runtime", runtimeProperties.get()); String content = TemplateRuntime.execute(compiledTemplate, data).toString(); return new ByteArrayInputStream(content.getBytes()); } }
LOGGER.debug("Create {}", Profiles.getProfileInfo(profile)); } else { LOGGER.debug("Update {}", profile); LOGGER.debug("Update {}", Profiles.getProfileDifference(lastProfile, profile));
@Override protected Object doExecute() throws Exception { ProfileService profileService = fabricService.adapt(ProfileService.class); Version version = versionId != null ? profileService.getRequiredVersion(versionId) : fabricService.getRequiredDefaultVersion(); Profile profile = version.getProfile(profileName); if (profile != null) { Profiles.refreshProfile(fabricService, profile); } else { System.out.println("Profile " + profileName + " not found."); } return null; } }
@GET @Path("profiles") public Map<String, String> profiles() { if (version != null) { List<String> profileIds = Profiles.profileIds(version.getProfiles()); return mapToLinks(profileIds, "profile/"); } return Collections.EMPTY_MAP; }
/** * Returns true if the given container is a java child container */ public static boolean isJavaContainer(FabricService fabricService, CreateContainerOptions options) { Map<String, ?> javaContainerConfig = Profiles.getOverlayConfiguration(fabricService, options.getProfiles(), options.getVersion(), Constants.JAVA_CONTAINER_PID); return !javaContainerConfig.isEmpty(); }