Search in sources :

Example 1 with ContainerImpl

use of io.fabric8.internal.ContainerImpl 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 2 with ContainerImpl

use of io.fabric8.internal.ContainerImpl 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 3 with ContainerImpl

use of io.fabric8.internal.ContainerImpl in project fabric8 by jboss-fuse.

the class ContainerPlaceholderResolverTest method testResolveCurrentName.

@Test
@Ignore("[FABRIC-1110] Mocked test makes invalid assumption on the implementation")
public void testResolveCurrentName() throws Exception {
    final FabricService fabricService = createMock(FabricService.class);
    final DataStore dataStore = createMock(DataStore.class);
    expect(fabricService.getCurrentContainerName()).andReturn("root").anyTimes();
    expect(fabricService.getContainer(EasyMock.<String>anyObject())).andReturn(new ContainerImpl(null, "root", fabricService));
    replay(fabricService);
    replay(dataStore);
    PlaceholderResolver resolver = getContainerPlaceholderResolver();
    assertEquals("root", resolver.resolve(fabricService, null, null, null, "container:name"));
    verify(fabricService);
    verify(dataStore);
}
Also used : FabricService(io.fabric8.api.FabricService) ContainerImpl(io.fabric8.internal.ContainerImpl) DataStore(io.fabric8.api.DataStore) PlaceholderResolver(io.fabric8.api.PlaceholderResolver) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 4 with ContainerImpl

use of io.fabric8.internal.ContainerImpl in project fabric8 by jboss-fuse.

the class FabricServiceImpl method getContainer.

@Override
public Container getContainer(String name) {
    assertValid();
    if (dataStore.get().hasContainer(name)) {
        Container parent = null;
        String parentId = dataStore.get().getContainerParent(name);
        if (parentId != null && !parentId.isEmpty()) {
            parent = getContainer(parentId);
        }
        return new ContainerImpl(parent, name, this);
    }
    throw new FabricException("Container '" + name + "' does not exist");
}
Also used : Container(io.fabric8.api.Container) ContainerImpl(io.fabric8.internal.ContainerImpl) FabricException(io.fabric8.api.FabricException)

Example 5 with ContainerImpl

use of io.fabric8.internal.ContainerImpl in project fabric8 by jboss-fuse.

the class ContainerLifecycleCommandsTest method testStopSingleContainer.

@Test
public void testStopSingleContainer() throws Exception {
    containers("c1");
    ContainerImpl c1 = newContainer("c1");
    expect(this.fabricService.adapt(CuratorFramework.class)).andReturn(this.curatorFramework).anyTimes();
    expect(this.fabricService.getContainers()).andReturn(new Container[] { c1 });
    this.fabricService.stopContainer(c1, false);
    replay(this.fabricService, this.commandSession);
    this.stop.execute(this.commandSession);
    verify(this.fabricService);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) ContainerImpl(io.fabric8.internal.ContainerImpl) Test(org.junit.Test)

Aggregations

ContainerImpl (io.fabric8.internal.ContainerImpl)11 Container (io.fabric8.api.Container)6 Test (org.junit.Test)6 FabricService (io.fabric8.api.FabricService)4 DataStore (io.fabric8.api.DataStore)3 FabricException (io.fabric8.api.FabricException)2 HashMap (java.util.HashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 CuratorFramework (org.apache.curator.framework.CuratorFramework)2 Before (org.junit.Before)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ContainerProvider (io.fabric8.api.ContainerProvider)1 CreateContainerBasicMetadata (io.fabric8.api.CreateContainerBasicMetadata)1 CreateContainerBasicOptions (io.fabric8.api.CreateContainerBasicOptions)1 CreateContainerMetadata (io.fabric8.api.CreateContainerMetadata)1 CreateContainerOptions (io.fabric8.api.CreateContainerOptions)1 CreationStateListener (io.fabric8.api.CreationStateListener)1 NameValidator (io.fabric8.api.NameValidator)1 NullCreationStateListener (io.fabric8.api.NullCreationStateListener)1 PlaceholderResolver (io.fabric8.api.PlaceholderResolver)1