use of io.fabric8.api.ProfileRequirements in project fabric8 by jboss-fuse.
the class AutoScalers method requirementsSatisfied.
/**
* Returns true if the requirements are satisfied for the given profile requirements; updating the auto scale status
* accordingly
*/
public static boolean requirementsSatisfied(FabricService service, String version, FabricRequirements requirements, ProfileRequirements profileRequirement, AutoScaleStatus status) {
String profile = profileRequirement.getProfile();
List<String> dependentProfiles = profileRequirement.getDependentProfiles();
if (dependentProfiles != null) {
for (String dependentProfile : dependentProfiles) {
ProfileRequirements dependentProfileRequirements = requirements.getOrCreateProfileRequirement(dependentProfile);
Integer minimumInstances = dependentProfileRequirements.getMinimumInstances();
if (minimumInstances != null) {
List<Container> containers = Containers.aliveAndSuccessfulContainersForProfile(version, dependentProfile, service);
int dependentSize = containers.size();
if (minimumInstances > dependentSize) {
status.profileStatus(profile).missingDependency(dependentProfile, dependentSize, minimumInstances);
return false;
}
}
}
}
return true;
}
use of io.fabric8.api.ProfileRequirements in project fabric8 by jboss-fuse.
the class SshAutoScalerTest method assertSshAutoScale.
public static HostProfileCounter assertSshAutoScale(FabricRequirements requirements, AutoScaleStatus status) {
HostProfileCounter hostProfileCounter = new HostProfileCounter();
String version = requirements.getVersion();
if (Strings.isEmpty(version)) {
version = "1.0";
}
List<ProfileRequirements> profileRequirements = requirements.getProfileRequirements();
for (ProfileRequirements profileRequirement : profileRequirements) {
Integer minimumInstances = profileRequirement.getMinimumInstances();
if (minimumInstances != null) {
for (int i = 0; i < minimumInstances; i++) {
String profileId = profileRequirement.getProfile();
AutoScaleRequest request = new AutoScaleRequest(null, version, profileId, 1, requirements, profileRequirement, status);
CreateSshContainerOptions.Builder builder = chooseHostContainerOptions(request, hostProfileCounter);
assertNotNull("Should have found a builder for " + profileId, builder);
String host = builder.getHost();
hostProfileCounter.incrementContainers(host);
hostProfileCounter.incrementProfileCount(host, profileId);
}
}
}
Map<String, CountingMap> hostToProfileCounts = hostProfileCounter.getHostToProfileCounts();
assertProfilesUseSeparateHost(requirements, hostToProfileCounts);
assertMaximumContainerCountNotExceeded(requirements, hostToProfileCounts);
return hostProfileCounter;
}
use of io.fabric8.api.ProfileRequirements in project fabric8 by jboss-fuse.
the class MQManager method loadBrokerStatus.
@Override
public List<MQBrokerStatusDTO> loadBrokerStatus(String versionId) throws Exception {
FabricRequirements requirements = fabricService.getRequirements();
List<MQBrokerStatusDTO> answer = new ArrayList<MQBrokerStatusDTO>();
Version version = versionId == null ? fabricService.getDefaultVersion() : profileService.getVersion(versionId);
Container[] containers = fabricService.getContainers();
List<Profile> values = getActiveOrRequiredBrokerProfileMap(version, requirements);
for (Profile profile : values) {
List<MQBrokerConfigDTO> list = createConfigDTOs(mqService, profile);
for (MQBrokerConfigDTO configDTO : list) {
ProfileRequirements profileRequirements = requirements.findProfileRequirements(profile.getId());
int count = 0;
for (Container container : containers) {
if (Containers.containerHasProfile(container, profile)) {
MQBrokerStatusDTO status = createStatusDTO(profile, configDTO, profileRequirements, container);
count++;
answer.add(status);
}
}
// if there are no containers yet, lets create a record anyway
if (count == 0) {
MQBrokerStatusDTO status = createStatusDTO(profile, configDTO, profileRequirements, null);
answer.add(status);
}
}
}
addMasterSlaveStatus(answer);
return answer;
}
use of io.fabric8.api.ProfileRequirements 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;
}
use of io.fabric8.api.ProfileRequirements 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);
}
}
Aggregations