Search in sources :

Example 86 with Profile

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

the class ExampleCamelClusterTest method testRegistryEntries.

@Test
public void testRegistryEntries() throws Exception {
    System.out.println(executeCommand("fabric:create -n --wait-for-provisioning root"));
    // System.out.println(executeCommand("shell:info"));
    // System.out.println(executeCommand("fabric:info"));
    // System.out.println(executeCommand("fabric:profile-list"));
    ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(bundleContext, FabricService.class);
    try {
        FabricService fabricService = fabricProxy.getService();
        CuratorFramework curator = fabricService.adapt(CuratorFramework.class);
        Set<ContainerProxy> containers = ContainerBuilder.create(fabricProxy, 3).withName("fabric-camel").assertProvisioningResult().build();
        try {
            // We will use the first container as a client and the rest as servers.
            LinkedList<Container> containerList = new LinkedList<Container>(containers);
            Container client = containerList.removeLast();
            LinkedList<Container> servers = new LinkedList<Container>(containerList);
            for (Container c : servers) {
                Profile p1 = c.getVersion().getRequiredProfile("feature-camel");
                Profile p2 = c.getVersion().getRequiredProfile("example-camel-cluster-cluster.server");
                c.setProfiles(new Profile[] { p1, p2 });
            }
            Provision.provisioningSuccess(servers, PROVISION_TIMEOUT);
            Profile p1 = client.getVersion().getRequiredProfile("feature-camel");
            Profile p2 = client.getVersion().getRequiredProfile("example-camel-cluster-cluster.client");
            client.setProfiles(new Profile[] { p1, p2 });
            Provision.provisioningSuccess(Arrays.asList(new Container[] { client }), PROVISION_TIMEOUT);
            System.out.println(executeCommand("fabric:container-list"));
            System.out.println(executeCommand("fabric:profile-display --overlay fabric-camel-server"));
            // Check that the entries have been properly propagated.
            Assert.assertNotNull(exists(curator, "/fabric/registry/camel/endpoints"));
            Assert.assertEquals(1, getChildren(curator, "/fabric/registry/camel/endpoints").size());
            Assert.assertTrue(Provision.waitForCondition(Arrays.asList(client), new ContainerCondition() {

                @Override
                public Boolean checkConditionOnContainer(final Container c) {
                    return getCompletedExchangesCount(c) > 0;
                }
            }, 60000L));
            // We want to kill all but one server, so we take out the first and keep it to the end.
            Container lastActiveServerContainer = servers.removeLast();
            for (Container c : servers) {
                try {
                    c.destroy(true);
                } catch (Exception ex) {
                // ignore.
                }
                // Get the number of exchanges completed before we kill the server.
                final int completed = getCompletedExchangesCount(client);
                // Ensure that we still have messages flowing
                Assert.assertTrue(Provision.waitForCondition(Arrays.asList(client), new ContainerCondition() {

                    @Override
                    public Boolean checkConditionOnContainer(final Container c) {
                        return getCompletedExchangesCount(c) > completed + 3;
                    }
                }, 60000L));
            }
            System.out.println(new AnsiString(executeCommand("fabric:container-connect -u admin -p admin " + client.getId() + " camel:route-info fabric-client")).getPlain().toString());
        } finally {
            ContainerBuilder.destroy(containers);
        }
    } finally {
        fabricProxy.close();
    }
}
Also used : AnsiString(org.fusesource.jansi.AnsiString) LinkedList(java.util.LinkedList) Profile(io.fabric8.api.Profile) ContainerCondition(io.fabric8.itests.paxexam.support.ContainerCondition) CuratorFramework(org.apache.curator.framework.CuratorFramework) Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) ContainerProxy(io.fabric8.itests.paxexam.support.ContainerProxy) Test(org.junit.Test)

Example 87 with Profile

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

the class ProvisionSupport method profileAvailable.

public static Boolean profileAvailable(String profile, String version, Long timeout) throws Exception {
    FabricService fabricService = ServiceLocator.awaitService(FabricService.class);
    ProfileRegistry profileRegistry = fabricService.adapt(ProfileRegistry.class);
    for (long t = 0; (!profileRegistry.hasProfile(version, profile) && t < timeout); t += 2000L) {
        Thread.sleep(2000L);
    }
    return profileRegistry.hasProfile(version, profile);
}
Also used : FabricService(io.fabric8.api.FabricService) ProfileRegistry(io.fabric8.api.ProfileRegistry)

Example 88 with Profile

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

the class ExampleMQProfileTest method testExample.

@Test
public void testExample() throws Exception {
    System.out.println(executeCommand("fabric:create -n --wait-for-provisioning"));
    // System.out.println(executeCommand("shell:info"));
    // System.out.println(executeCommand("fabric:info"));
    // System.out.println(executeCommand("fabric:profile-list"));
    ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(bundleContext, FabricService.class);
    try {
        FabricService fabricService = fabricProxy.getService();
        CuratorFramework curator = fabricService.adapt(CuratorFramework.class);
        Set<ContainerProxy> containers = ContainerBuilder.create(fabricProxy, 2).withName("cnt").withProfiles("default").assertProvisioningResult().build();
        try {
            LinkedList<Container> containerList = new LinkedList<Container>(containers);
            Container broker = containerList.removeLast();
            setData(curator, ZkPath.CONTAINER_PROVISION_RESULT.getPath(broker.getId()), "changing");
            System.out.println(executeCommand("fabric:container-change-profile " + broker.getId() + " mq-default"));
            Provision.provisioningSuccess(Arrays.asList(new Container[] { broker }), PROVISION_TIMEOUT);
            System.out.println(executeCommand("fabric:cluster-list"));
            for (Container c : containerList) {
                setData(curator, ZkPath.CONTAINER_PROVISION_RESULT.getPath(c.getId()), "changing");
                System.out.println(executeCommand("fabric:container-change-profile " + c.getId() + " example-mq"));
            }
            Provision.provisioningSuccess(containerList, PROVISION_TIMEOUT);
            System.out.println(executeCommand("fabric:cluster-list"));
            Assert.assertTrue(Provision.waitForCondition(Arrays.asList(new Container[] { broker }), new ContainerCondition() {

                @Override
                public Boolean checkConditionOnContainer(final Container c) {
                    System.out.println(executeCommand("fabric:container-connect -u admin -p admin " + c.getId() + " activemq:bstat"));
                    String output = executeCommand("fabric:container-connect -u admin -p admin " + c.getId() + " activemq:query -QQueue=FABRIC.DEMO");
                    return output.contains("DequeueCount = ") && !output.contains("DequeueCount = 0");
                }
            }, 10000L));
        } finally {
            ContainerBuilder.destroy(containers);
        }
    } finally {
        fabricProxy.close();
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) ContainerProxy(io.fabric8.itests.paxexam.support.ContainerProxy) LinkedList(java.util.LinkedList) ContainerCondition(io.fabric8.itests.paxexam.support.ContainerCondition) Test(org.junit.Test)

Example 89 with Profile

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

the class AbstractProfileManagementTest method testCreateVersionFrom.

@Test
public void testCreateVersionFrom() throws Exception {
    // [FABRIC-1169] Profile version attributes leak to other versions
    // VersionState v12 = getProxy().createVersion("1.0", "1.2", Collections.singletonMap("keyA", "valA"));
    VersionState v12 = getProxy().createVersionFrom("1.0", "1.2", null);
    try {
        Assert.assertEquals("1.2", v12.getId());
        // Assert.assertEquals("valA", v12.getAttributes().get("keyA"));
        List<String> profiles = v12.getProfiles();
        Assert.assertTrue(profiles.contains("default"));
        Assert.assertTrue(profiles.contains("fabric"));
    } finally {
        getProxy().deleteVersion("1.2");
    }
}
Also used : VersionState(io.fabric8.api.mxbean.VersionState) Test(org.junit.Test)

Example 90 with Profile

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

the class FabricHTTPGateway method getGatewayVersion.

/**
 * Returns the default profile version used to filter out the current versions of services
 * if no version expression is used the URI template
 */
String getGatewayVersion() {
    assertValid();
    Container currentContainer = fabricService.get().getCurrentContainer();
    if (currentContainer != null) {
        Version version = currentContainer.getVersion();
        if (version != null) {
            return version.getId();
        }
    }
    return null;
}
Also used : Container(io.fabric8.api.Container) Version(io.fabric8.api.Version)

Aggregations

Profile (io.fabric8.api.Profile)125 Version (io.fabric8.api.Version)50 Container (io.fabric8.api.Container)49 ArrayList (java.util.ArrayList)37 ProfileBuilder (io.fabric8.api.ProfileBuilder)34 Test (org.junit.Test)32 FabricService (io.fabric8.api.FabricService)28 HashMap (java.util.HashMap)25 File (java.io.File)24 ProfileService (io.fabric8.api.ProfileService)23 Map (java.util.Map)22 IOException (java.io.IOException)19 ProfileRequirements (io.fabric8.api.ProfileRequirements)13 HashSet (java.util.HashSet)12 GitVersion (io.fabric8.api.commands.GitVersion)11 FabricRequirements (io.fabric8.api.FabricRequirements)10 LinkedList (java.util.LinkedList)9 TreeMap (java.util.TreeMap)9 LockHandle (io.fabric8.api.LockHandle)8 Parser (io.fabric8.maven.util.Parser)8