use of io.fabric8.api.AutoScaleRequest in project fabric8 by jboss-fuse.
the class ChildAutoScaler method chooseRootContainer.
protected String chooseRootContainer(AutoScaleRequest request, List<String> containerIds) {
ChildScalingRequirements scalingRequirements = getChildScalingRequirements(request);
if (scalingRequirements != null) {
List<String> rootContainerPatterns = scalingRequirements.getRootContainerPatterns();
if (rootContainerPatterns != null && !rootContainerPatterns.isEmpty()) {
Filter<String> filter = Filters.createStringFilters(rootContainerPatterns);
List<String> matchingRootContainers = Filters.filter(containerIds, filter);
return Filters.matchRandomElement(matchingRootContainers);
}
}
return Filters.matchRandomElement(containerIds);
}
use of io.fabric8.api.AutoScaleRequest 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.AutoScaleRequest in project fabric8 by jboss-fuse.
the class ChildAutoScaler method getChildScalingRequirements.
protected ChildScalingRequirements getChildScalingRequirements(AutoScaleRequest request) {
ChildScalingRequirements scalingRequirements = null;
ProfileRequirements profileRequirements = request.getProfileRequirements();
if (profileRequirements != null) {
scalingRequirements = profileRequirements.getChildScalingRequirements();
}
return scalingRequirements;
}
use of io.fabric8.api.AutoScaleRequest in project fabric8 by jboss-fuse.
the class ChildAutoScaler method createContainers.
@Override
public void createContainers(AutoScaleRequest request) throws Exception {
int count = request.getDelta();
String profile = request.getProfile();
String version = request.getVersion();
FabricService fabricService = request.getFabricService();
CreateChildContainerOptions.Builder builder = null;
if (fabricService != null) {
builder = createAutoScaleOptions(request, fabricService);
}
if (builder != null) {
Set<String> ignoreContainerNames = new HashSet<>();
for (int i = 0; i < count; i++) {
final CreateChildContainerOptions.Builder configuredBuilder = builder.number(1).version(version).profiles(profile);
Container[] containers = fabricService.getContainers();
NameValidator nameValidator = Containers.createNameValidator(containers);
String name = Containers.createAutoScaleContainerName(containers, profile, containerProvider.getScheme(), nameValidator);
ignoreContainerNames.add(name);
CreateChildContainerOptions options = configuredBuilder.name(name).build();
LOG.info("Creating container name " + name + " version " + version + " profile " + profile + " " + count + " container(s)");
fabricService.createContainers(options);
}
} else {
LOG.warn("Could not create version " + version + " profile " + profile + " due to missing autoscale configuration");
}
}
use of io.fabric8.api.AutoScaleRequest 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);
}
}
}
}
Aggregations