Search in sources :

Example 11 with ContainerProxy

use of io.fabric8.itests.paxexam.support.ContainerProxy in project fabric8 by jboss-fuse.

the class ExampleCamelCxfTest 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 {
        Set<ContainerProxy> containers = ContainerBuilder.create(fabricProxy).withName("child").withProfiles("example-camel-cxf").assertProvisioningResult().build();
        try {
            System.out.println(executeCommand("fabric:container-list"));
            Assert.assertTrue(Provision.waitForCondition(containers, new ContainerCondition() {

                @Override
                public Boolean checkConditionOnContainer(final Container c) {
                    String response = new AnsiString(executeCommand("fabric:container-connect -u admin -p admin " + c.getId() + " camel:route-list | grep fabric-camel-cxf")).getPlain().toString();
                    return response.contains("fabric-camel-cxf");
                }
            }, 60000L));
            for (Container container : containers) {
                System.out.println(executeCommand("fabric:container-connect -u admin -p admin " + container.getId() + " osgi:list"));
                String response = executeCommand("fabric:container-connect -u admin -p admin " + container.getId() + " camel:route-list | grep fabric-camel-cxf");
                System.out.println(response);
                Assert.assertTrue(response.contains("Started"));
            }
        } finally {
            ContainerBuilder.destroy(containers);
        }
    } finally {
        fabricProxy.close();
    }
}
Also used : Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) AnsiString(org.fusesource.jansi.AnsiString) AnsiString(org.fusesource.jansi.AnsiString) ContainerProxy(io.fabric8.itests.paxexam.support.ContainerProxy) ContainerCondition(io.fabric8.itests.paxexam.support.ContainerCondition) Test(org.junit.Test)

Example 12 with ContainerProxy

use of io.fabric8.itests.paxexam.support.ContainerProxy in project fabric8 by jboss-fuse.

the class CreateContainerTask method call.

@Override
public Set<ContainerProxy> call() throws Exception {
    Set<ContainerProxy> containers = new HashSet<ContainerProxy>();
    FabricService fabricService = fabricServiceProxy.getService();
    CreateContainerMetadata[] allMetadata = fabricService.createContainers(options);
    if (allMetadata != null && allMetadata.length > 0) {
        for (CreateContainerMetadata metadata : allMetadata) {
            Container container = metadata.getContainer();
            containers.add(ContainerProxy.wrap(container, fabricServiceProxy));
            if (!metadata.isSuccess()) {
                throw new FabricException("Failed to create container.", metadata.getFailure());
            }
        }
    }
    return containers;
}
Also used : Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) CreateContainerMetadata(io.fabric8.api.CreateContainerMetadata) FabricException(io.fabric8.api.FabricException) HashSet(java.util.HashSet)

Example 13 with ContainerProxy

use of io.fabric8.itests.paxexam.support.ContainerProxy in project fabric8 by jboss-fuse.

the class MQProfileTest method testMQCreateBasic.

@Test
public void testMQCreateBasic() 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"));
    System.out.println(executeCommand("mq-create --no-ssl --jmx-user admin --jmx-password admin --minimumInstances 1 mq"));
    ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(bundleContext, FabricService.class);
    try {
        Set<ContainerProxy> containers = ContainerBuilder.create(fabricProxy, 2).withName("child").withProfiles("default").assertProvisioningResult().build();
        try {
            LinkedList<Container> containerList = new LinkedList<Container>(containers);
            Container broker = containerList.removeLast();
            Profile brokerProfile = broker.getVersion().getRequiredProfile("mq-broker-default.mq");
            broker.setProfiles(new Profile[] { brokerProfile });
            Provision.provisioningSuccess(Arrays.asList(broker), PROVISION_TIMEOUT);
            waitForBroker("default");
            final BrokerViewMBean bean = (BrokerViewMBean) Provision.getMBean(broker, new ObjectName("org.apache.activemq:type=Broker,brokerName=mq"), BrokerViewMBean.class, 120000);
            Assert.assertNotNull("Cannot get BrokerViewMBean from JMX", bean);
            System.out.println(executeCommand("container-list"));
            for (Container c : containerList) {
                Profile exampleProfile = broker.getVersion().getRequiredProfile("example-mq");
                c.setProfiles(new Profile[] { exampleProfile });
            }
            Provision.provisioningSuccess(containers, PROVISION_TIMEOUT);
            Provision.waitForCondition(new Callable<Boolean>() {

                @Override
                public Boolean call() throws Exception {
                    while (bean.getTotalProducerCount() == 0 || bean.getTotalConsumerCount() == 0) {
                        Thread.sleep(1000);
                    }
                    return true;
                }
            }, 120000L);
            Assert.assertEquals("Producer not present", 1, bean.getTotalProducerCount());
            Assert.assertEquals("Consumer not present", 1, bean.getTotalConsumerCount());
        } finally {
            ContainerBuilder.destroy(containers);
        }
    } finally {
        fabricProxy.close();
    }
}
Also used : LinkedList(java.util.LinkedList) Profile(io.fabric8.api.Profile) ObjectName(javax.management.ObjectName) BrokerViewMBean(org.apache.activemq.broker.jmx.BrokerViewMBean) Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) ContainerProxy(io.fabric8.itests.paxexam.support.ContainerProxy) Test(org.junit.Test)

Example 14 with ContainerProxy

use of io.fabric8.itests.paxexam.support.ContainerProxy in project fabric8 by jboss-fuse.

the class MQProfileTest method testMQCreateNetwork.

@Test
public void testMQCreateNetwork() 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"));
    executeCommand("mq-create --no-ssl --group us-east --network us-west --jmx-user admin --jmx-password admin --networks-username admin --networks-password admin --minimumInstances 1 us-east");
    executeCommand("mq-create --no-ssl --group us-west --network us-east --jmx-user admin --jmx-password admin --networks-username admin --networks-password admin --minimumInstances 1 us-west");
    ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(bundleContext, FabricService.class);
    try {
        Set<ContainerProxy> containers = ContainerBuilder.create(fabricProxy, 4).withName("child").withProfiles("default").assertProvisioningResult().build();
        try {
            LinkedList<Container> containerList = new LinkedList<Container>(containers);
            Container eastBroker = containerList.removeLast();
            Container westBroker = containerList.removeLast();
            Profile eastBrokerProfile = eastBroker.getVersion().getRequiredProfile("mq-broker-us-east.us-east");
            eastBroker.setProfiles(new Profile[] { eastBrokerProfile });
            Profile westBrokerProfile = eastBroker.getVersion().getRequiredProfile("mq-broker-us-west.us-west");
            westBroker.setProfiles(new Profile[] { westBrokerProfile });
            Provision.provisioningSuccess(Arrays.asList(westBroker, eastBroker), PROVISION_TIMEOUT);
            waitForBroker("us-east");
            waitForBroker("us-west");
            final BrokerViewMBean brokerEast = (BrokerViewMBean) Provision.getMBean(eastBroker, new ObjectName("org.apache.activemq:type=Broker,brokerName=us-east"), BrokerViewMBean.class, 120000);
            final BrokerViewMBean brokerWest = (BrokerViewMBean) Provision.getMBean(westBroker, new ObjectName("org.apache.activemq:type=Broker,brokerName=us-west"), BrokerViewMBean.class, 120000);
            Assert.assertNotNull("Cannot get BrokerViewMBean from JMX", brokerEast);
            Assert.assertNotNull("Cannot get BrokerViewMBean from JMX", brokerWest);
            Container eastProducer = containerList.removeLast();
            executeCommand("container-add-profile " + eastProducer.getId() + " example-mq-producer mq-client-us-east");
            Container westConsumer = containerList.removeLast();
            executeCommand("container-add-profile " + westConsumer.getId() + " example-mq-consumer mq-client-us-west");
            Provision.provisioningSuccess(Arrays.asList(eastProducer, westConsumer), PROVISION_TIMEOUT);
            System.out.println(executeCommand("fabric:container-list"));
            Provision.waitForCondition(new Callable<Boolean>() {

                @Override
                public Boolean call() throws Exception {
                    while (brokerEast.getTotalEnqueueCount() == 0 || brokerWest.getTotalDequeueCount() == 0) {
                        Thread.sleep(1000);
                    }
                    return true;
                }
            }, 120000L);
            System.out.println(executeCommand("fabric:container-connect -u admin -p admin " + eastBroker.getId() + " bstat"));
            System.out.println(executeCommand("fabric:container-connect -u admin -p admin " + westBroker.getId() + " bstat"));
            Assert.assertFalse("Messages not sent", brokerEast.getTotalEnqueueCount() == 0);
            Assert.assertFalse("Messages not received", brokerWest.getTotalDequeueCount() == 0);
        } finally {
            ContainerBuilder.destroy(containers);
        }
    } finally {
        fabricProxy.close();
    }
}
Also used : LinkedList(java.util.LinkedList) Profile(io.fabric8.api.Profile) ObjectName(javax.management.ObjectName) BrokerViewMBean(org.apache.activemq.broker.jmx.BrokerViewMBean) Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) ContainerProxy(io.fabric8.itests.paxexam.support.ContainerProxy) Test(org.junit.Test)

Aggregations

FabricService (io.fabric8.api.FabricService)14 ContainerProxy (io.fabric8.itests.paxexam.support.ContainerProxy)11 Test (org.junit.Test)11 Container (io.fabric8.api.Container)7 CuratorFramework (org.apache.curator.framework.CuratorFramework)7 Profile (io.fabric8.api.Profile)4 ContainerCondition (io.fabric8.itests.paxexam.support.ContainerCondition)4 LinkedList (java.util.LinkedList)4 FabricFeaturesTest (io.fabric8.itests.paxexam.support.FabricFeaturesTest)3 ArrayList (java.util.ArrayList)3 FabricException (io.fabric8.api.FabricException)2 HashSet (java.util.HashSet)2 ObjectName (javax.management.ObjectName)2 BrokerViewMBean (org.apache.activemq.broker.jmx.BrokerViewMBean)2 AnsiString (org.fusesource.jansi.AnsiString)2 BundleContext (org.osgi.framework.BundleContext)2 CreateContainerBasicOptions (io.fabric8.api.CreateContainerBasicOptions)1 CreateContainerMetadata (io.fabric8.api.CreateContainerMetadata)1 Hello (io.fabric8.demo.cxf.Hello)1 CreateSshContainerOptions (io.fabric8.service.ssh.CreateSshContainerOptions)1