Search in sources :

Example 41 with Container

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

the class FabricServiceImpl method stopContainer.

public void stopContainer(Container container, boolean force) {
    assertValid();
    LOGGER.info("Stopping container {}", container.getId());
    ContainerProvider provider = getProvider(container);
    try {
        provider.stop(container);
    } catch (RuntimeException ex) {
        // if its already stopped then ignore the exception
        boolean stopped = "Instance already stopped".equals(ex.getMessage());
        if (!stopped) {
            throw ex;
        }
    }
}
Also used : ContainerProvider(io.fabric8.api.ContainerProvider)

Example 42 with Container

use of io.fabric8.api.Container 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 43 with Container

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

the class FabricServiceImpl method getContainers.

@Override
public Container[] getContainers() {
    assertValid();
    Map<String, Container> containers = new HashMap<String, Container>();
    List<String> containerIds = dataStore.get().getContainers();
    for (String containerId : containerIds) {
        String parentId = dataStore.get().getContainerParent(containerId);
        if (parentId.isEmpty()) {
            if (!containers.containsKey(containerId)) {
                Container container = new ContainerImpl(null, containerId, this);
                containers.put(containerId, container);
            }
        } else {
            Container parent = containers.get(parentId);
            if (parent == null) {
                parent = new ContainerImpl(null, parentId, this);
                containers.put(parentId, parent);
            }
            Container container = new ContainerImpl(parent, containerId, this);
            containers.put(containerId, container);
        }
    }
    return containers.values().toArray(new Container[containers.size()]);
}
Also used : Container(io.fabric8.api.Container) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ContainerImpl(io.fabric8.internal.ContainerImpl)

Example 44 with Container

use of io.fabric8.api.Container 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 45 with Container

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

the class FabricServiceImpl method getProvider.

private ContainerProvider getProvider(Container container, boolean returnNull) {
    CreateContainerMetadata metadata = container.getMetadata();
    String type = metadata != null ? metadata.getCreateOptions().getProviderType() : null;
    if (type == null) {
        if (returnNull) {
            return null;
        }
        throw new UnsupportedOperationException("Container " + container.getId() + " has not been created using Fabric");
    }
    ContainerProvider provider = getProvider(type);
    if (provider == null) {
        if (returnNull) {
            return null;
        }
        throw new UnsupportedOperationException("Container provider " + type + " not supported");
    }
    return provider;
}
Also used : ContainerProvider(io.fabric8.api.ContainerProvider) CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata)

Aggregations

Container (io.fabric8.api.Container)139 Test (org.junit.Test)75 FabricService (io.fabric8.api.FabricService)56 ArrayList (java.util.ArrayList)39 Container (io.fabric8.kubernetes.api.model.Container)38 IOException (java.io.IOException)38 Profile (io.fabric8.api.Profile)37 HashMap (java.util.HashMap)34 Map (java.util.Map)30 FabricException (io.fabric8.api.FabricException)27 BundleContext (org.osgi.framework.BundleContext)24 Version (io.fabric8.api.Version)23 File (java.io.File)23 HashSet (java.util.HashSet)20 LinkedList (java.util.LinkedList)17 PodSpec (io.fabric8.kubernetes.api.model.PodSpec)16 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)16 CreateContainerMetadata (io.fabric8.api.CreateContainerMetadata)15 Pod (io.fabric8.kubernetes.api.model.Pod)12 List (java.util.List)12