Search in sources :

Example 16 with FabricRequirements

use of io.fabric8.api.FabricRequirements in project fabric8 by jboss-fuse.

the class MQManager method getActiveOrRequiredBrokerProfileMap.

private List<Profile> getActiveOrRequiredBrokerProfileMap(Version version, FabricRequirements requirements) {
    IllegalArgumentAssertion.assertNotNull(fabricService, "fabricService");
    List<Profile> answer = new ArrayList<Profile>();
    if (version != null) {
        ProfileService profileService = fabricService.adapt(ProfileService.class);
        List<Profile> profiles = version.getProfiles();
        for (Profile profile : profiles) {
            String versionId = profile.getVersion();
            String profileId = profile.getId();
            if (!IGNORED_PROFILES.contains(profileId)) {
                Profile overlay = profileService.getOverlayProfile(profile);
                Map<String, Map<String, String>> configurations = overlay.getConfigurations();
                Set<Map.Entry<String, Map<String, String>>> entries = configurations.entrySet();
                for (Map.Entry<String, Map<String, String>> entry : entries) {
                    String key = entry.getKey();
                    if (isBrokerConfigPid(key)) {
                        answer.add(overlay);
                    }
                }
            }
        }
    }
    return answer;
}
Also used : ProfileService(io.fabric8.api.ProfileService) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) Profile(io.fabric8.api.Profile)

Example 17 with FabricRequirements

use of io.fabric8.api.FabricRequirements in project fabric8 by jboss-fuse.

the class RequirementsListSupport method doExecute.

@Override
protected Object doExecute() throws Exception {
    PrintStream out = System.out;
    FabricRequirements requirements = getFabricService().getRequirements();
    printRequirements(out, requirements);
    return null;
}
Also used : PrintStream(java.io.PrintStream) FabricRequirements(io.fabric8.api.FabricRequirements)

Example 18 with FabricRequirements

use of io.fabric8.api.FabricRequirements in project fabric8 by jboss-fuse.

the class FabricResource method setRequirements.

@POST
@Path("requirements")
public void setRequirements(FabricRequirements requirements) throws IOException {
    Objects.notNull(requirements, "requirements");
    FabricService service = getFabricService();
    Objects.notNull(service, "FabricService");
    service.setRequirements(requirements);
}
Also used : FabricService(io.fabric8.api.FabricService) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST)

Example 19 with FabricRequirements

use of io.fabric8.api.FabricRequirements in project fabric8 by jboss-fuse.

the class RequireProfileSetAction method updateRequirements.

@Override
protected boolean updateRequirements(FabricRequirements requirements) {
    if (v != null) {
        setVersion(v);
    } else {
        setVersion(getFabricService().getDefaultVersionId());
    }
    ProfileRequirements requirement = new ProfileRequirements(profile);
    if (minimumInstances != null) {
        requirement.setMinimumInstances(minimumInstances);
    }
    if (maximumInstances != null) {
        requirement.setMaximumInstances(maximumInstances);
    }
    if (dependentProfiles != null) {
        requirement.setDependentProfiles(dependentProfiles);
    }
    requirements.addOrUpdateProfileRequirements(requirement);
    return true;
}
Also used : ProfileRequirements(io.fabric8.api.ProfileRequirements)

Example 20 with FabricRequirements

use of io.fabric8.api.FabricRequirements in project fabric8 by jboss-fuse.

the class FabricServiceImpl method validateRequirements.

/**
 * Validates the requirements to ensure the profiles exist etc. and
 * removes those for a profile that does not exist.
 */
public static void validateRequirements(FabricService fabricService, FabricRequirements requirements) {
    ProfileService profileService = fabricService.adapt(ProfileService.class);
    String versionId = requirements.getVersion();
    Version version;
    if (!Strings.isNullOrEmpty(versionId)) {
        version = profileService.getRequiredVersion(versionId);
    } else {
        version = fabricService.getDefaultVersion();
    }
    Set<String> profileIds = new HashSet<>(Profiles.profileIds(version.getProfiles()));
    List<ProfileRequirements> profileRequirements = requirements.getProfileRequirements();
    List<String> profilesToBeRemoved = new ArrayList<>();
    for (ProfileRequirements profileRequirement : profileRequirements) {
        try {
            validateProfileRequirements(fabricService, requirements, profileRequirement, profileIds);
        } catch (IllegalArgumentException e) {
            LOGGER.info("Removing {}; {}", profileRequirement, e.getMessage());
            profilesToBeRemoved.add(profileRequirement.getProfile());
        }
    }
    for (String profile : profilesToBeRemoved) {
        requirements.removeProfileRequirements(profile);
    }
}
Also used : ProfileService(io.fabric8.api.ProfileService) ProfileRequirements(io.fabric8.api.ProfileRequirements) Version(io.fabric8.api.Version) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Aggregations

FabricRequirements (io.fabric8.api.FabricRequirements)21 ProfileRequirements (io.fabric8.api.ProfileRequirements)13 Container (io.fabric8.api.Container)8 FabricService (io.fabric8.api.FabricService)5 Profile (io.fabric8.api.Profile)5 HostProfileCounter (io.fabric8.internal.autoscale.HostProfileCounter)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 Map (java.util.Map)4 ProfileService (io.fabric8.api.ProfileService)3 CountingMap (io.fabric8.utils.CountingMap)3 HashSet (java.util.HashSet)3 AutoScaleProfileStatus (io.fabric8.api.AutoScaleProfileStatus)2 AutoScaleRequest (io.fabric8.api.AutoScaleRequest)2 ContainerAutoScaler (io.fabric8.api.ContainerAutoScaler)2 FabricException (io.fabric8.api.FabricException)2 SshHostConfiguration (io.fabric8.api.SshHostConfiguration)2 Version (io.fabric8.api.Version)2 MQBrokerConfigDTO (io.fabric8.api.jmx.MQBrokerConfigDTO)2