io.fabric8.api.Version.getRequiredProfile()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(105)

本文整理了Java中io.fabric8.api.Version.getRequiredProfile()方法的一些代码示例,展示了Version.getRequiredProfile()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Version.getRequiredProfile()方法的具体详情如下:
包路径:io.fabric8.api.Version
类名称:Version
方法名:getRequiredProfile

Version.getRequiredProfile介绍

[英]Get a profile for the given identity.
[中]获取给定身份的配置文件。

代码示例

代码示例来源:origin: jboss-fuse/fabric8

/**
 * Gets the profile for the given name
 *
 * @throws java.lang.IllegalArgumentException if the profile does not exists
 */
public static Profile getProfile(Version ver, String name) {
  Profile p = ver.getRequiredProfile(name);
  if (p == null) {
    throw new IllegalArgumentException("Profile " + name + " does not exist.");
  }
  return p;
}

代码示例来源:origin: io.fabric8/fabric-boot-commands

/**
 * Gets the profile for the given name
 *
 * @throws java.lang.IllegalArgumentException if the profile does not exists
 */
public static Profile getProfile(Version ver, String name) {
  Profile p = ver.getRequiredProfile(name);
  if (p == null) {
    throw new IllegalArgumentException("Profile " + name + " does not exist.");
  }
  return p;
}

代码示例来源:origin: jboss-fuse/fabric8

@Override
public String getConfigurationFile(String versionId, String profileId, String fileName) {
  return Base64.encodeBase64String(profileService.getVersion(versionId).getRequiredProfile(profileId).getFileConfigurations().get(fileName));
}

代码示例来源:origin: io.fabric8/fabric-api

private static void recursiveAddProfiles(Version version, Set<String> result, List<String> profiles) {
  for (String profileId : profiles) {
    result.add(profileId);
    Profile profile = version.getRequiredProfile(profileId);
    List<String> parents = profile.getParentIds();
    recursiveAddProfiles(version, result, parents);
  }
}

代码示例来源:origin: jboss-fuse/fabric8

private String getLastModified() {
    StringBuilder sb = new StringBuilder();
    sb.append(self.getProfileHash());
    for (String parentId : self.getParentIds()) {
      Profile parent = version.getRequiredProfile(parentId);
      sb.append("-").append(parent.getProfileHash());
    }
    return sb.toString();
  }
}

代码示例来源:origin: jboss-fuse/fabric8

@Override
public Map<String, Object> getConfigurationFiles(String versionId, List<String> profileIds, String filename) {
  Pattern pattern = Pattern.compile(filename);
  Map<String, Object> answer = new TreeMap<String, Object>();
  Version version = profileService.getVersion(versionId);
  for (String profileId : profileIds) {
    Profile profile = version.getRequiredProfile(profileId);
    if (profile != null) {
      Map<String, String> files = new TreeMap<String, String>();
      Map<String, byte[]> configs = profile.getFileConfigurations();
      for (Map.Entry<String, byte[]> configEntry : configs.entrySet()) {
        if (pattern.matcher(configEntry.getKey()).matches()) {
          files.put(configEntry.getKey(), Base64.encodeBase64String(configEntry.getValue()));
        }
      }
      answer.put(profileId, files);
    }
  }
  return answer;
}

代码示例来源:origin: jboss-fuse/fabric8

private static void recursiveAddProfiles(Version version, Set<String> result, List<String> profiles) {
  for (String profileId : profiles) {
    result.add(profileId);
    Profile profile = version.getRequiredProfile(profileId);
    List<String> parents = profile.getParentIds();
    recursiveAddProfiles(version, result, parents);
  }
}

代码示例来源:origin: jboss-fuse/fabric8

@Override
public Map<String, String> getProfileProperties(String versionId, String profileId, String pid) {
  Map<String, String> answer = null;
  Version version = profileService.getVersion(versionId);
  if (version != null) {
    Profile profile = version.getRequiredProfile(profileId);
    if (profile != null) {
      answer = profile.getConfiguration(pid);
    }
  }
  return answer;
}

代码示例来源:origin: jboss-fuse/fabric8

@Override
public Profile[] getProfiles() {
  Version version = getVersion();
  List<String> profileIds = dataStore.getContainerProfiles(id);
  List<Profile> profiles = new ArrayList<Profile>();
  for (String profileId : profileIds) {
    profiles.add(version.getRequiredProfile(profileId));
  }
  if (profiles.isEmpty() && version != null) {
    Profile defaultProfile = version.getProfile(ZkDefs.DEFAULT_PROFILE);
    if (defaultProfile != null) {
      profiles.add(defaultProfile);
    }
  }
  return profiles.toArray(new Profile[profiles.size()]);
}

代码示例来源:origin: io.fabric8/fabric-rest

@Path("profile/{profileId}")
public ProfileResource version(@PathParam("profileId") String profileId) {
  if (Strings.isNotBlank(profileId) && version != null && version.hasProfile(profileId)) {
    Profile profile = version.getRequiredProfile(profileId);
    if (profile != null) {
      return new ProfileResource(this, profile);
    }
  }
  return null;
}

代码示例来源:origin: jboss-fuse/fabric8

@Path("profile/{profileId}")
public ProfileResource version(@PathParam("profileId") String profileId) {
  if (Strings.isNotBlank(profileId) && version != null && version.hasProfile(profileId)) {
    Profile profile = version.getRequiredProfile(profileId);
    if (profile != null) {
      return new ProfileResource(this, profile);
    }
  }
  return null;
}

代码示例来源:origin: jboss-fuse/fabric8

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);
    }
  }
}

代码示例来源:origin: io.fabric8/fabric-commands

/**
 * Gets the profiles for upgrade/rollback
 *
 * @param existingProfiles  the existing profiles
 * @param targetVersion     the target version
 * @return the new profiles to be used
 */
public static Profile[] getProfilesForUpgradeOrRollback(Profile[] existingProfiles, Version targetVersion) {
  List<Profile> list = new ArrayList<Profile>(existingProfiles.length);
  for (Profile old : existingProfiles) {
    // get new profile
    Profile newProfile = targetVersion.getRequiredProfile(old.getId());
    if (newProfile != null) {
      list.add(newProfile);
    } else {
      // we expect a profile with the new version to exist
      throw new IllegalArgumentException("Profile " + old.getId() + " with version " + targetVersion.getId() + " does not exists");
    }
  }
  return list.toArray(new Profile[0]);
}

代码示例来源:origin: jboss-fuse/fabric8

/**
 * Returns the {@link Profile} objects for the given list of profile ids for the given version
 */
public static List<Profile> getProfiles(FabricService fabricService, Iterable<String> profileIds, String versionId) {
  ProfileService profileService = fabricService.adapt(ProfileService.class);
  Version version;
  if (versionId == null) {
    version = fabricService.getRequiredDefaultVersion();
  } else {
    version = profileService.getRequiredVersion(versionId);
  }
  List<Profile> answer = new ArrayList<Profile>();
  if (profileIds != null && version != null) {
    for (String profileId : profileIds) {
      Profile profile = version.getRequiredProfile(profileId);
      if (profile != null) {
        answer.add(profile);
      }
    }
  }
  return answer;
}

代码示例来源:origin: jboss-fuse/fabric8

private void fillParentProfiles(Profile profile, List<Profile> profiles) {
  if (!profiles.contains(profile)) {
    List<Profile> circularRelationship = new ArrayList<>();
    for (String parentId : profile.getParentIds()) {
      if (version.hasProfile(parentId)){
        Profile parent = version.getRequiredProfile(parentId);
        if (parent != null){
          if ( !isCircularRelationship(profile, parent)){
            fillParentProfiles(parent, profiles);
          } else {
            circularRelationship.add(parent);
          }
        }
      } else {
        LOGGER.error("Tried to load a profile[{}] not present in this version[{}]", parentId, version);
      }
    }
    profiles.add(profile);
    for(Profile p: circularRelationship){
      fillParentProfiles(p, profiles);
    }
  }
}

代码示例来源:origin: jboss-fuse/fabric8

@Override
public Map<String, String> getOverlayProfileProperties(String versionId, String profileId, String pid) {
  Map<String, String> answer = null;
  Version version = profileService.getVersion(versionId);
  if (version != null) {
    Profile profile = version.getRequiredProfile(profileId);
    if (profile != null) {
      Profile overlayProfile = profileService.getOverlayProfile(profile);
      answer = overlayProfile.getConfiguration(pid);
    }
  }
  return answer;
}

代码示例来源:origin: jboss-fuse/fabric8

@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;
}

代码示例来源:origin: jboss-fuse/fabric8

@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());
}

代码示例来源:origin: io.fabric8/fabric-project-deployer

private Profile getOrCreateProfile(Version version, ProjectRequirements requirements) {
  String profileId = getProfileId(requirements);
  if (Strings.isEmpty(profileId)) {
    throw new IllegalArgumentException("No profile ID could be deduced for requirements: " + requirements);
  }
  // make sure the profileId is valid
  FabricValidations.validateProfileName(profileId);
  Profile profile;
  if (!version.hasProfile(profileId)) {
    LOG.info("Creating new profile " + profileId + " version " + version + " for requirements: " + requirements);
    String versionId = version.getId();
    ProfileService profileService = fabricService.get().adapt(ProfileService.class);
    ProfileBuilder builder = ProfileBuilder.Factory.create(versionId, profileId);
    profile = profileService.createProfile(builder.getProfile());
  } else {
    profile = version.getRequiredProfile(profileId);
  }
  return profile;
}

代码示例来源:origin: io.fabric8/fabric-commands

@Override
protected Object doExecute() throws Exception {
  Version version = versionId != null ? profileService.getRequiredVersion(versionId) : fabricService.getRequiredDefaultVersion();
  Profile profile = version.getRequiredProfile(profileId);
  
  // we can only change parents to existing profiles
  Profile[] parents = FabricCommand.getExistingProfiles(fabricService, version, parentIds);
  ProfileBuilder builder = ProfileBuilder.Factory.createFrom(profile);
  List<String> oldParents = builder.getParents();
  for (Profile parent : parents) {
    builder.addParent(parent.getId());
  }
  //remove old parent profiles
  for (String oldParent : oldParents) {
    if (!parentIds.contains(oldParent)) {
      builder.removeParent(oldParent);
    }
  }
  profileService.updateProfile(builder.getProfile());
  return null;
}

相关文章