Search in sources :

Example 46 with Container

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

the class ContainerImplTest method testRemoveMissingProfile.

// We should be able to remove a profile that doesn't exist from a container.
// A missing profile may be added to a container during startup (not possible to validate) or after an upgrade / rollback operation.
@Test
@Ignore("[FABRIC-1110] Mocked test makes invalid assumption on the implementation")
public void testRemoveMissingProfile() throws Exception {
    String v = "1.0";
    String profile1Id = "feature-camel";
    String profile2Id = "feature-cxf";
    String missing = "missing";
    // new VersionImpl(v, fabricService);
    Version version = null;
    List<String> profiles = Arrays.asList(profile1Id, profile2Id, missing);
    List<String> profilesToSet = Arrays.asList(profile1Id, profile2Id);
    expect(profileService.getRequiredVersion(eq(v))).andReturn(version).anyTimes();
    expect(dataStore.getContainerVersion(eq(CONTAINER_ID))).andReturn(v).anyTimes();
    expect(dataStore.getContainerProfiles(eq(CONTAINER_ID))).andReturn(profiles).anyTimes();
    expect(profileRegistry.hasProfile(v, profile1Id)).andReturn(true).anyTimes();
    expect(profileRegistry.hasProfile(v, profile2Id)).andReturn(true).anyTimes();
    expect(profileRegistry.hasProfile(v, missing)).andReturn(false).anyTimes();
    // expect(profileRegistry.getProfileAttributes(eq(v), EasyMock.<String>anyObject())).andReturn(Maps.<String, String>newHashMap()).anyTimes();
    dataStore.setContainerProfiles(eq(CONTAINER_ID), eq(profilesToSet));
    expectLastCall().once();
    replay(fabricService);
    replay(dataStore);
    container.removeProfiles(missing);
    verify(fabricService);
    verify(dataStore);
}
Also used : Version(io.fabric8.api.Version) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 47 with Container

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

the class ContainerImplTest method setUp.

@Before
public void setUp() {
    fabricService = createMock(FabricService.class);
    dataStore = createMock(DataStore.class);
    expect(fabricService.adapt(DataStore.class)).andReturn(dataStore).anyTimes();
    container = new ContainerImpl(null, CONTAINER_ID, fabricService);
}
Also used : FabricService(io.fabric8.api.FabricService) ContainerImpl(io.fabric8.internal.ContainerImpl) DataStore(io.fabric8.api.DataStore) Before(org.junit.Before)

Example 48 with Container

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

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

the class ZookeeperPortService method registerPort.

private void registerPort(Container container, String pid, String key, int port, Lease existingLease) {
    assertValid();
    String portAsString = String.valueOf(port);
    String containerPortsPath = ZkPath.PORTS_CONTAINER_PID_KEY.getPath(container.getId(), pid, key);
    String reservedPortsPath = ZkPath.PORTS_CONTAINER_RESERVED_PORTS.getPath(container.getId());
    String ip = container.getIp();
    assertValidIp(container, ip);
    String ipPortsPath = ZkPath.PORTS_IP.getPath(ip);
    Lease lease = null;
    try {
        if (existingLease != null) {
            lease = existingLease;
        } else {
            lease = interProcessLock.acquire(60, TimeUnit.SECONDS);
        }
        if (lease != null) {
            createDefault(curator.get(), containerPortsPath, portAsString);
            createDefault(curator.get(), ipPortsPath, portAsString);
            setData(curator.get(), containerPortsPath, portAsString);
            String existingPorts = getStringData(curator.get(), ipPortsPath);
            if (!existingPorts.contains(portAsString)) {
                setData(curator.get(), ipPortsPath, existingPorts + " " + portAsString);
                createDefault(curator.get(), reservedPortsPath, portAsString);
                String reservedPortsPerContainer = getStringData(curator.get(), reservedPortsPath);
                if (!reservedPortsPerContainer.contains(portAsString)) {
                    setData(curator.get(), reservedPortsPath, reservedPortsPerContainer + " " + portAsString);
                }
            }
        } else {
            throw new FabricException("Could not acquire port lock for pid " + pid);
        }
    } catch (InterruptedException ex) {
        cleanUpDirtyZKNodes(interProcessLock);
        throw FabricException.launderThrowable(ex);
    } catch (Exception ex) {
        throw FabricException.launderThrowable(ex);
    } finally {
        if (existingLease == null) {
            releaseLock(lease);
        }
    }
}
Also used : Lease(org.apache.curator.framework.recipes.locks.Lease) FabricException(io.fabric8.api.FabricException) FabricException(io.fabric8.api.FabricException)

Example 50 with Container

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

the class ZookeeperPortService method registerPort.

@Override
public int registerPort(Container container, String pid, String key, int fromPort, int toPort, Set<Integer> excludes) {
    assertValid();
    Lease lease = null;
    try {
        lease = interProcessLock.acquire(60, TimeUnit.SECONDS);
        if (lease != null) {
            int port = lookupPort(container, pid, key);
            if (port > 0 && (port >= fromPort && port <= toPort)) {
                // get one from the port range
                return port;
            }
            Set<Integer> boundPorts = findUsedPortByHost(container, lease);
            boundPorts.addAll(excludes);
            for (port = fromPort; port <= toPort; port++) {
                if (!boundPorts.contains(port)) {
                    if (Ports.isPortFree(port)) {
                        registerPort(container, pid, key, port, lease);
                        return port;
                    }
                }
            }
        } else {
            throw new FabricException("Could not acquire port lock for pid " + pid);
        }
        throw new FabricException("Could not find port within range [" + fromPort + "," + toPort + "] for pid " + pid);
    } catch (InterruptedException ex) {
        cleanUpDirtyZKNodes(interProcessLock);
        throw FabricException.launderThrowable(ex);
    } catch (Exception ex) {
        throw FabricException.launderThrowable(ex);
    } finally {
        releaseLock(lease);
    }
}
Also used : Lease(org.apache.curator.framework.recipes.locks.Lease) FabricException(io.fabric8.api.FabricException) FabricException(io.fabric8.api.FabricException)

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