Search in sources :

Example 26 with FabricService

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

the class ContainerPlaceholderResolverTest method testResolveAttributeCase.

@Test
public void testResolveAttributeCase() throws Exception {
    PlaceholderResolver resolver = getContainerPlaceholderResolver();
    assertEquals(ip, resolver.resolve(fabricService, null, null, null, "container:root/IP"));
    assertEquals(localhostname, resolver.resolve(fabricService, null, null, null, "container:root/LocalHostName"));
    assertEquals(bindaddress, resolver.resolve(fabricService, null, null, null, "container:root/Bindaddress"));
    assertEquals(containerResolver, resolver.resolve(fabricService, null, null, null, "container:root/Resolver"));
    verify(fabricService);
    verify(dataStore);
}
Also used : PlaceholderResolver(io.fabric8.api.PlaceholderResolver) Test(org.junit.Test)

Example 27 with FabricService

use of io.fabric8.api.FabricService 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 28 with FabricService

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

the class EncryptedPropertyResolverTest method testResolve.

@Test
public void testResolve() throws Exception {
    CuratorFramework curator = createMock(CuratorFramework.class);
    GetDataBuilder getDataBuilder = createMock(GetDataBuilder.class);
    expect(curator.getData()).andReturn(getDataBuilder).anyTimes();
    expect(getDataBuilder.forPath(AUTHENTICATION_CRYPT_ALGORITHM.getPath())).andReturn("PBEWithMD5AndDES".getBytes()).anyTimes();
    expect(getDataBuilder.forPath(AUTHENTICATION_CRYPT_PASSWORD.getPath())).andReturn("mypassword".getBytes()).anyTimes();
    replay(curator);
    replay(getDataBuilder);
    FabricService fabricService = createMock(FabricService.class);
    expect(fabricService.adapt(CuratorFramework.class)).andReturn(curator).anyTimes();
    replay(fabricService);
    PlaceholderResolver resolver = getEncryptedPropertyResolver();
    assertEquals("encryptedpassword", resolver.resolve(fabricService, null, null, null, "crypt:URdoo9++D3tsoC9ODrTfLNK5WzviknO3Ig6qbI2HuvQ="));
    verify(curator);
    verify(getDataBuilder);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) FabricService(io.fabric8.api.FabricService) GetDataBuilder(org.apache.curator.framework.api.GetDataBuilder) PlaceholderResolver(io.fabric8.api.PlaceholderResolver) Test(org.junit.Test)

Example 29 with FabricService

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

the class EncryptedPropertyResolverTest method testResolveZkEnc.

@Test
public void testResolveZkEnc() throws Exception {
    CuratorFramework curator = createMock(CuratorFramework.class);
    GetDataBuilder getDataBuilder = createMock(GetDataBuilder.class);
    expect(curator.getData()).andReturn(getDataBuilder).anyTimes();
    expect(getDataBuilder.forPath(AUTHENTICATION_CRYPT_ALGORITHM.getPath())).andReturn("PBEWithMD5AndDES".getBytes()).anyTimes();
    expect(getDataBuilder.forPath(AUTHENTICATION_CRYPT_PASSWORD.getPath())).andReturn("ZKENC=bXlwYXNzd29yZA==".getBytes()).anyTimes();
    replay(curator);
    replay(getDataBuilder);
    FabricService fabricService = createMock(FabricService.class);
    expect(fabricService.adapt(CuratorFramework.class)).andReturn(curator).anyTimes();
    replay(fabricService);
    PlaceholderResolver resolver = getEncryptedPropertyResolver();
    assertEquals("encryptedpassword", resolver.resolve(fabricService, null, null, null, "crypt:URdoo9++D3tsoC9ODrTfLNK5WzviknO3Ig6qbI2HuvQ="));
    verify(curator);
    verify(getDataBuilder);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) FabricService(io.fabric8.api.FabricService) GetDataBuilder(org.apache.curator.framework.api.GetDataBuilder) PlaceholderResolver(io.fabric8.api.PlaceholderResolver) Test(org.junit.Test)

Example 30 with FabricService

use of io.fabric8.api.FabricService 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)

Aggregations

FabricService (io.fabric8.api.FabricService)80 Container (io.fabric8.api.Container)76 Test (org.junit.Test)52 Profile (io.fabric8.api.Profile)50 BundleContext (org.osgi.framework.BundleContext)29 Version (io.fabric8.api.Version)24 ArrayList (java.util.ArrayList)21 ProfileService (io.fabric8.api.ProfileService)19 HashMap (java.util.HashMap)16 CuratorFramework (org.apache.curator.framework.CuratorFramework)16 HashSet (java.util.HashSet)14 Map (java.util.Map)13 FabricException (io.fabric8.api.FabricException)12 IOException (java.io.IOException)12 ContainerProxy (io.fabric8.itests.paxexam.support.ContainerProxy)11 Ignore (org.junit.Ignore)10 File (java.io.File)9 LinkedList (java.util.LinkedList)9 Path (javax.ws.rs.Path)8 FabricRequirements (io.fabric8.api.FabricRequirements)7