Search in sources :

Example 6 with FabricRequirements

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);
}
Also used : Container(io.fabric8.api.Container) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 7 with FabricRequirements

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;
}
Also used : ContainerProvider(io.fabric8.api.ContainerProvider) ContainerAutoScalerFactory(io.fabric8.api.ContainerAutoScalerFactory) ContainerAutoScaler(io.fabric8.api.ContainerAutoScaler) TreeMap(java.util.TreeMap)

Example 8 with FabricRequirements

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;
}
Also used : Container(io.fabric8.api.Container) ProfileRequirements(io.fabric8.api.ProfileRequirements) FabricRequirements(io.fabric8.api.FabricRequirements)

Example 9 with FabricRequirements

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;
}
Also used : Container(io.fabric8.api.Container) ProfileRequirements(io.fabric8.api.ProfileRequirements)

Example 10 with FabricRequirements

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);
        }
    }
}
Also used : Container(io.fabric8.api.Container) FabricException(io.fabric8.api.FabricException) FabricRequirements(io.fabric8.api.FabricRequirements) IOException(java.io.IOException) Profile(io.fabric8.api.Profile)

Aggregations

FabricRequirements (io.fabric8.api.FabricRequirements)21 ProfileRequirements (io.fabric8.api.ProfileRequirements)13 Container (io.fabric8.api.Container)8 FabricService (io.fabric8.api.FabricService)5 Profile (io.fabric8.api.Profile)5 HostProfileCounter (io.fabric8.internal.autoscale.HostProfileCounter)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 IOException (java.io.IOException)4 Map (java.util.Map)4 ProfileService (io.fabric8.api.ProfileService)3 CountingMap (io.fabric8.utils.CountingMap)3 HashSet (java.util.HashSet)3 AutoScaleProfileStatus (io.fabric8.api.AutoScaleProfileStatus)2 AutoScaleRequest (io.fabric8.api.AutoScaleRequest)2 ContainerAutoScaler (io.fabric8.api.ContainerAutoScaler)2 FabricException (io.fabric8.api.FabricException)2 SshHostConfiguration (io.fabric8.api.SshHostConfiguration)2 Version (io.fabric8.api.Version)2 MQBrokerConfigDTO (io.fabric8.api.jmx.MQBrokerConfigDTO)2