Search in sources :

Example 6 with AutoScaleRequest

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

the class OpenShiftAutoScaler 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();
    CreateOpenshiftContainerOptions.Builder builder = null;
    if (fabricService != null) {
        builder = createAutoScaleOptions(fabricService);
    }
    if (builder != null) {
        // TODO this is actually generic to all providers! :)
        for (int i = 0; i < count; i++) {
            Container[] containers = fabricService.getContainers();
            final CreateOpenshiftContainerOptions.Builder configuredBuilder = builder.number(1).version(version).profiles(profile);
            NameValidator openShiftValidator = containerProvider.createNameValidator(configuredBuilder.build());
            NameValidator fabricNameValidator = Containers.createNameValidator(fabricService.getContainers());
            NameValidator nameValidator = Containers.joinNameValidators(openShiftValidator, fabricNameValidator);
            String name = Containers.createAutoScaleContainerName(containers, profile, containerProvider.getScheme(), nameValidator);
            CreateOpenshiftContainerOptions 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");
    }
}
Also used : Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) NameValidator(io.fabric8.api.NameValidator)

Example 7 with AutoScaleRequest

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

the class SshAutoScaler method chooseHostContainerOptions.

/**
 * This method is public for easier testing
 */
public static CreateSshContainerOptions.Builder chooseHostContainerOptions(AutoScaleRequest request, HostProfileCounter hostProfileCounter) {
    CreateSshContainerOptions.Builder builder = CreateSshContainerOptions.builder();
    FabricRequirements requirements = request.getFabricRequirements();
    ProfileRequirements profileRequirements = request.getProfileRequirements();
    SshScalingRequirements sshScalingRequirements = profileRequirements.getSshScalingRequirements();
    List<SshHostConfiguration> hosts = requirements.getSshHosts();
    SortedSet<LoadSortedHostConfiguration<SshHostConfiguration>> sortedHostConfigurations = AutoScalers.filterHosts(profileRequirements, sshScalingRequirements, hostProfileCounter, hosts);
    SshHostConfiguration sshHostConfig = null;
    if (!sortedHostConfigurations.isEmpty()) {
        LoadSortedHostConfiguration<SshHostConfiguration> first = sortedHostConfigurations.first();
        sshHostConfig = first.getConfiguration();
    }
    if (sshHostConfig == null) {
        LOG.warn("Could not create version " + request.getVersion() + " profile " + request.getProfile() + " as no matching hosts could be found for " + sshScalingRequirements);
        request.getProfileAutoScaleStatus().noSuitableHost("" + sshScalingRequirements);
        return null;
    }
    builder.configure(sshHostConfig, requirements, profileRequirements);
    return builder;
}
Also used : ProfileRequirements(io.fabric8.api.ProfileRequirements) SshHostConfiguration(io.fabric8.api.SshHostConfiguration) FabricRequirements(io.fabric8.api.FabricRequirements) LoadSortedHostConfiguration(io.fabric8.internal.autoscale.LoadSortedHostConfiguration) SshScalingRequirements(io.fabric8.api.SshScalingRequirements)

Example 8 with AutoScaleRequest

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

the class SshAutoScaler 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();
    Container[] containers = fabricService.getContainers();
    FabricRequirements requirements = request.getFabricRequirements();
    List<? extends HostConfiguration> hostConfigurations = requirements.getSshHosts();
    HostProfileCounter hostProfileCounter = new HostProfileCounter();
    AutoScalers.createHostToProfileScaleMap(hostProfileCounter, hostConfigurations, containers);
    for (int i = 0; i < count; i++) {
        CreateSshContainerOptions.Builder builder = null;
        NameValidator nameValidator = Containers.createNameValidator(containers);
        String name = Containers.createAutoScaleContainerName(containers, profile, containerProvider.getScheme(), nameValidator);
        if (fabricService != null) {
            builder = createAutoScaleOptions(request, fabricService, hostProfileCounter);
        }
        if (builder != null) {
            final CreateSshContainerOptions.Builder configuredBuilder = builder.number(1).version(version).profiles(profile);
            CreateSshContainerOptions options = configuredBuilder.name(name).build();
            LOG.info("Creating container name " + name + " version " + version + " profile " + profile + " " + count + " container(s)");
            fabricService.createContainers(options);
        }
    }
}
Also used : Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) NameValidator(io.fabric8.api.NameValidator) FabricRequirements(io.fabric8.api.FabricRequirements) HostProfileCounter(io.fabric8.internal.autoscale.HostProfileCounter)

Aggregations

Container (io.fabric8.api.Container)4 FabricService (io.fabric8.api.FabricService)4 NameValidator (io.fabric8.api.NameValidator)3 ProfileRequirements (io.fabric8.api.ProfileRequirements)3 AutoScaleRequest (io.fabric8.api.AutoScaleRequest)2 ChildScalingRequirements (io.fabric8.api.ChildScalingRequirements)2 FabricRequirements (io.fabric8.api.FabricRequirements)2 HostProfileCounter (io.fabric8.internal.autoscale.HostProfileCounter)2 AutoScaleProfileStatus (io.fabric8.api.AutoScaleProfileStatus)1 CreateChildContainerOptions (io.fabric8.api.CreateChildContainerOptions)1 SshHostConfiguration (io.fabric8.api.SshHostConfiguration)1 SshScalingRequirements (io.fabric8.api.SshScalingRequirements)1 LoadSortedHostConfiguration (io.fabric8.internal.autoscale.LoadSortedHostConfiguration)1 CountingMap (io.fabric8.utils.CountingMap)1 HashSet (java.util.HashSet)1