use of io.fabric8.api.FabricRequirements in project fabric8 by jboss-fuse.
the class FabricServiceImpl method setRequirements.
@Override
public void setRequirements(FabricRequirements requirements) throws IOException {
assertValid();
validateRequirements(this, requirements);
Set<String> activeAutoScaledProfiles = new HashSet<>();
for (Container container : getContainers()) {
if (container.getId().startsWith("auto_")) {
activeAutoScaledProfiles.addAll(container.getProfileIds());
}
}
requirements.removeEmptyRequirements(activeAutoScaledProfiles);
dataStore.get().setRequirements(requirements);
}
use of io.fabric8.api.FabricRequirements in project fabric8 by jboss-fuse.
the class FabricServiceImpl method createContainerAutoScaler.
@Override
public ContainerAutoScaler createContainerAutoScaler(FabricRequirements requirements, ProfileRequirements profileRequirements) {
Collection<ContainerProvider> providerCollection = getProviders().values();
for (ContainerProvider containerProvider : providerCollection) {
// lets pick the highest weighted autoscaler (e.g. to prefer openshift to docker to child
SortedMap<Integer, ContainerAutoScaler> sortedAutoScalers = new TreeMap<Integer, ContainerAutoScaler>();
if (containerProvider instanceof ContainerAutoScalerFactory) {
ContainerAutoScalerFactory provider = (ContainerAutoScalerFactory) containerProvider;
ContainerAutoScaler autoScaler = provider.createAutoScaler(requirements, profileRequirements);
if (autoScaler != null) {
int weight = autoScaler.getWeight();
sortedAutoScalers.put(weight, autoScaler);
}
}
if (!sortedAutoScalers.isEmpty()) {
Integer key = sortedAutoScalers.lastKey();
if (key != null) {
return sortedAutoScalers.get(key);
}
}
}
return null;
}
use of io.fabric8.api.FabricRequirements in project fabric8 by jboss-fuse.
the class FabricServiceImpl method scaleProfile.
@Override
public boolean scaleProfile(String profile, int numberOfInstances) throws IOException {
if (numberOfInstances == 0) {
throw new IllegalArgumentException("numberOfInstances should be greater or less than zero");
}
FabricRequirements requirements = getRequirements();
ProfileRequirements profileRequirements = requirements.getOrCreateProfileRequirement(profile);
Integer minimumInstances = profileRequirements.getMinimumInstances();
List<Container> containers = Containers.containersForProfile(getContainers(), profile);
int containerCount = containers.size();
int newCount = containerCount + numberOfInstances;
if (newCount < 0) {
newCount = 0;
}
boolean update = minimumInstances == null || newCount != minimumInstances;
if (update) {
profileRequirements.setMinimumInstances(newCount);
setRequirements(requirements);
}
return update;
}
use of io.fabric8.api.FabricRequirements 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.FabricRequirements in project fabric8 by jboss-fuse.
the class ProfileServiceImpl method deleteProfile.
@Override
public void deleteProfile(FabricService fabricService, String versionId, String profileId, boolean force) {
assertValid();
Profile profile = getRequiredProfile(versionId, profileId);
LOGGER.info("deleteProfile: {}", profile);
// TODO: what about child profiles ?
Container[] containers = fabricService != null ? fabricService.getAssociatedContainers(versionId, profileId) : new Container[0];
if (containers.length == 0) {
profileRegistry.get().deleteProfile(versionId, profileId);
} else if (force) {
for (Container container : containers) {
container.removeProfiles(profileId);
}
profileRegistry.get().deleteProfile(versionId, profileId);
} else {
StringBuilder sb = new StringBuilder();
sb.append("Cannot delete profile:").append(profileId).append(".");
sb.append("Profile has assigned ").append(containers.length).append(" container(s):");
for (Container c : containers) {
sb.append(" ").append(c.getId());
}
sb.append(". Use force option to also remove the profile from the containers.");
throw new FabricException(sb.toString());
}
// lets remove any pending requirements on this profile
FabricRequirements requirements = fabricService != null ? fabricService.getRequirements() : null;
if (requirements != null && requirements.removeProfileRequirements(profileId)) {
try {
fabricService.setRequirements(requirements);
} catch (IOException e) {
throw new FabricException("Failed to update requirements after deleting profile " + profileId + ". " + e, e);
}
}
}
Aggregations