use of io.fabric8.api.ProfileStatus in project fabric8 by jboss-fuse.
the class HealthCheck method healthList.
@Override
public List<HealthStatus> healthList() {
List<HealthStatus> answer = new ArrayList<HealthStatus>();
FabricStatus status = fabricService.getFabricStatus();
Collection<ProfileStatus> statuses = status.getProfileStatusMap().values();
for (ProfileStatus profile : statuses) {
String id = profile.getProfile();
int instances = profile.getCount();
Integer minimum = profile.getMinimumInstances();
Integer maximum = profile.getMaximumInstances();
double healthPercent = profile.getHealth(instances);
String level = "INFO";
String message = "Profile " + id + " has health " + percentInstance.format(healthPercent);
if (minimum != null) {
if (instances <= 0) {
level = "ERROR";
message = "Profile " + id + " has no instances running! Should have at least " + minimum;
} else if (instances < minimum) {
level = "WARNING";
message = "Profile " + id + " needs more instances running. Should have at least " + minimum + " but currently has only " + instances;
}
}
if (maximum != null && level.equals("INFO") && instances > maximum) {
level = "WARNING";
message = "Profile " + id + " has too many instances running. Should have at most " + maximum + " but currently has only " + instances;
}
answer.add(new HealthStatus("io.fabric8.profileHealth", id, level, message, instances, minimum, maximum, healthPercent));
}
String worries = "";
for (HealthStatus hs : answer) {
if ("WARNING".equals(hs.getLevel()) || "ERROR".equals(hs.getLevel())) {
worries += hs + " , ";
}
}
if ("".equals(worries)) {
this.currentStatus = "Good";
} else {
this.currentStatus = "Getting Worried {" + worries + " }";
}
return answer;
}
use of io.fabric8.api.ProfileStatus in project fabric8 by jboss-fuse.
the class AutoScaleController method stopContainers.
protected void stopContainers(List<Container> containers, ContainerAutoScaler autoScaler, FabricRequirements requirements, ProfileRequirements profileRequirement, AutoScaleStatus status, int delta) {
final String profile = profileRequirement.getProfile();
AutoScaleProfileStatus profileStatus = status.profileStatus(profile);
// TODO sort the containers using some kind of requirements sorting order
List<Container> sorted = new ArrayList<>(containers);
// lets stop the ones at the end of the list by default
Collections.reverse(sorted);
List<String> stoppingContainerIds = new ArrayList<>();
for (int i = 0; i < delta; i++) {
if (i >= sorted.size()) {
break;
}
Container container = sorted.get(i);
stoppingContainerIds.add(container.getId());
profileStatus.stoppingContainers(stoppingContainerIds);
container.stop(true);
}
}
use of io.fabric8.api.ProfileStatus in project fabric8 by jboss-fuse.
the class AutoScaleController method autoScaleProfile.
private void autoScaleProfile(FabricService service, final ContainerAutoScaler autoScaler, FabricRequirements requirements, ProfileRequirements profileRequirement, AutoScaleStatus status) {
final String profile = profileRequirement.getProfile();
Integer minimumInstances = profileRequirement.getMinimumInstances();
Integer maximumInstances = profileRequirement.getMaximumInstances();
String requirementsVersion = requirements.getVersion();
final String version = Strings.isNotBlank(requirementsVersion) ? requirementsVersion : service.getDefaultVersionId();
if (maximumInstances != null || minimumInstances != null) {
if (maximumInstances != null) {
List<Container> containers = Containers.aliveAndSuccessfulContainersForProfile(version, profile, service);
int count = containers.size();
int delta = count - maximumInstances;
if (delta > 0) {
stopContainers(containers, autoScaler, requirements, profileRequirement, status, delta);
}
}
if (minimumInstances != null) {
// lets check if we need to provision more
List<Container> containers = Containers.aliveOrPendingContainersForProfile(version, profile, service);
int count = containers.size();
int delta = minimumInstances - count;
try {
AutoScaleProfileStatus profileStatus = status.profileStatus(profile);
if (delta < 0) {
FabricService fs = this.fabricService.get();
if (fs != null) {
profileStatus.destroyingContainer();
for (int i = delta; i < 0; i++) {
while (!containers.isEmpty()) {
Container container = containers.remove(0);
if (container.getId().startsWith("auto_")) {
fs.destroyContainer(container);
break;
}
}
}
}
} else if (delta > 0) {
if (AutoScalers.requirementsSatisfied(service, version, requirements, profileRequirement, status)) {
profileStatus.creatingContainer();
final AutoScaleRequest command = new AutoScaleRequest(service, version, profile, delta, requirements, profileRequirement, status);
new Thread("Creating container for " + command.getProfile()) {
@Override
public void run() {
try {
autoScaler.createContainers(command);
} catch (Exception e) {
LOGGER.error("Failed to create container of profile: " + profile + ". Caught: " + e, e);
}
}
}.start();
}
} else {
profileStatus.provisioned();
}
} catch (Exception e) {
LOGGER.error("Failed to auto-scale " + profile + ". Caught: " + e, e);
}
}
}
}
use of io.fabric8.api.ProfileStatus in project fabric8 by jboss-fuse.
the class StatusAction method printStatus.
protected void printStatus(PrintStream out, FabricStatus status) {
out.println(String.format("%-40s %-14s %s", "[profile]", "[instances]", "[health]"));
Collection<ProfileStatus> statuses = status.getProfileStatusMap().values();
for (ProfileStatus profile : statuses) {
String id = profile.getProfile();
int instances = profile.getCount();
double health = profile.getHealth(instances);
out.println(String.format("%-40s %-14s %s", id, instances, percentText(health)));
}
}
Aggregations