Search in sources :

Example 26 with Builder

use of io.fabric8.maven.docker.config.CopyConfiguration.Builder in project fabric8 by jboss-fuse.

the class CuratorFactoryBean method getObject.

// FactoryBean interface
// -------------------------------------------------------------------------
public CuratorFramework getObject() throws Exception {
    LOG.debug("Connecting to ZooKeeper on " + connectString);
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString(connectString).retryPolicy(new ExponentialBackoffRetry(5, 10)).connectionTimeoutMs(getTimeout());
    if (password != null && !password.isEmpty()) {
        builder.aclProvider(new CuratorACLManager());
        builder.authorization("digest", ("fabric:" + password).getBytes("UTF-8"));
    }
    this.curator = builder.build();
    LOG.debug("Starting curator " + curator);
    curator.start();
    return curator;
}
Also used : CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) CuratorACLManager(io.fabric8.zookeeper.curator.CuratorACLManager)

Example 27 with Builder

use of io.fabric8.maven.docker.config.CopyConfiguration.Builder in project fabric8 by jboss-fuse.

the class ManagerTest method testManager.

@Test
public void testManager() throws Exception {
    ZKServerFactoryBean zkServerFactoryBean = null;
    try {
        int zooKeeperPort = getFreePort();
        int serverPort = getFreePort();
        zkServerFactoryBean = new ZKServerFactoryBean();
        zkServerFactoryBean.setPurge(true);
        zkServerFactoryBean.setClientPortAddress(new InetSocketAddress("localhost", zooKeeperPort));
        zkServerFactoryBean.afterPropertiesSet();
        CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString("localhost:" + zooKeeperPort).retryPolicy(new RetryOneTime(1000)).connectionTimeoutMs(60000);
        CuratorFramework curator = builder.build();
        curator.start();
        curator.getZookeeperClient().blockUntilConnectedOrTimedOut();
        BundleContext bundleContext = createMock(BundleContext.class);
        ServiceRegistration registration = createMock(ServiceRegistration.class);
        Manager manager = new Manager(bundleContext, curator, "tcp://localhost:" + serverPort, "localhost", TimeUnit.MINUTES.toMillis(5));
        bundleContext.addServiceListener(manager, "(service.exported.interfaces=*)");
        expect(bundleContext.getProperty("org.osgi.framework.uuid")).andReturn("the-framework-uuid");
        expect(bundleContext.registerService(EasyMock.<String[]>anyObject(), same(manager), EasyMock.<Dictionary>same(null))).andReturn(registration);
        expect(bundleContext.getServiceReferences((String) null, "(service.exported.interfaces=*)")).andReturn(null);
        replay(bundleContext, registration);
        manager.init();
        verify(bundleContext, registration);
        reset(bundleContext, registration);
        BundleContext expBundleContext = createMock(BundleContext.class);
        Bundle expBundle = createMock(Bundle.class);
        ServiceReference reference = createMock(ServiceReference.class);
        final Properties props = new Properties();
        props.put(Constants.OBJECTCLASS, new String[] { ConfigurationAdmin.class.getName() });
        expect(reference.getProperty(EasyMock.<String>anyObject())).andAnswer(new IAnswer<Object>() {

            public Object answer() throws Throwable {
                return props.get(EasyMock.getCurrentArguments()[0]);
            }
        }).anyTimes();
        expect(reference.getPropertyKeys()).andReturn(props.keySet().toArray(new String[0]));
        expect(reference.getBundle()).andReturn(expBundle).anyTimes();
        expect(expBundle.getBundleContext()).andReturn(expBundleContext).anyTimes();
        expect(expBundle.getState()).andReturn(Bundle.ACTIVE).anyTimes();
        replay(bundleContext, registration, reference, expBundleContext, expBundle);
        manager.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, reference));
        Thread.sleep(1000);
        verify(bundleContext, registration, reference, expBundleContext, expBundle);
    } finally {
        try {
            zkServerFactoryBean.destroy();
        } catch (Throwable t) {
        }
    }
}
Also used : RetryOneTime(org.apache.curator.retry.RetryOneTime) CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) InetSocketAddress(java.net.InetSocketAddress) Bundle(org.osgi.framework.Bundle) ZKServerFactoryBean(io.fabric8.zookeeper.spring.ZKServerFactoryBean) Manager(io.fabric8.dosgi.impl.Manager) Properties(java.util.Properties) ServiceReference(org.osgi.framework.ServiceReference) IAnswer(org.easymock.IAnswer) CuratorFramework(org.apache.curator.framework.CuratorFramework) ServiceEvent(org.osgi.framework.ServiceEvent) ConfigurationAdmin(org.osgi.service.cm.ConfigurationAdmin) BundleContext(org.osgi.framework.BundleContext) ServiceRegistration(org.osgi.framework.ServiceRegistration) Test(org.junit.Test)

Example 28 with Builder

use of io.fabric8.maven.docker.config.CopyConfiguration.Builder in project fabric8 by jboss-fuse.

the class ContainerBuilder method prepareAsync.

public Future<Set<Container>> prepareAsync(B builder) {
    BundleContext syscontext = ServiceLocator.getSystemContext();
    ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(syscontext, FabricService.class);
    try {
        FabricService fabricService = fabricProxy.getService();
        CompletionService<Set<Container>> completionService = new ExecutorCompletionService<Set<Container>>(executorService);
        return completionService.submit(new CreateContainerTask(fabricService, builder));
    } finally {
        fabricProxy.close();
    }
}
Also used : Container(io.fabric8.api.Container) Set(java.util.Set) HashSet(java.util.HashSet) FabricService(io.fabric8.api.FabricService) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) BundleContext(org.osgi.framework.BundleContext)

Example 29 with Builder

use of io.fabric8.maven.docker.config.CopyConfiguration.Builder in project fabric8 by jboss-fuse.

the class ContainerBuilder method buildInternal.

private Set<ContainerProxy> buildInternal(Collection<B> buildersList) {
    Set<ContainerProxy> containers = new HashSet<ContainerProxy>();
    BundleContext bundleContext = getBundleContext();
    ServiceLocator.awaitService(getBundleContext(), FabricComplete.class);
    synchronizeGitRepositories();
    FabricService fabricService = fabricServiceServiceProxy.getService();
    CompletionService<Set<ContainerProxy>> completionService = new ExecutorCompletionService<Set<ContainerProxy>>(executorService);
    int tasks = 0;
    for (B builder : buildersList) {
        builder.profiles(profileNames);
        if (!builder.isEnsembleServer()) {
            builder.zookeeperUrl(fabricService.getZookeeperUrl());
            CreateContainerBasicOptions options = builder.build();
            ServiceLocator.awaitService(bundleContext, ContainerProvider.class, "(fabric.container.protocol=" + options.getProviderType() + ")", CREATE_TIMEOUT, TimeUnit.MILLISECONDS);
            completionService.submit(new CreateContainerTask(fabricServiceServiceProxy, options));
            tasks++;
        }
    }
    try {
        for (int i = 0; i < tasks; i++) {
            Future<Set<ContainerProxy>> futureContainerSet = completionService.poll(CREATE_TIMEOUT, TimeUnit.MILLISECONDS);
            Set<ContainerProxy> containerSet = futureContainerSet.get();
            containers.addAll(containerSet);
        }
        try {
            if (waitForProvisioning) {
                Provision.containerStatus(containers, provisionTimeOut);
            }
            if (assertProvisioningResult) {
                Provision.provisioningSuccess(containers, provisionTimeOut, ContainerCallback.DISPLAY_ALL);
            }
        } catch (Exception e) {
            throw FabricException.launderThrowable(e);
        }
    } catch (Exception e) {
        throw FabricException.launderThrowable(e);
    }
    return Collections.unmodifiableSet(containers);
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) FabricException(io.fabric8.api.FabricException) FabricService(io.fabric8.api.FabricService) CreateContainerBasicOptions(io.fabric8.api.CreateContainerBasicOptions) HashSet(java.util.HashSet) BundleContext(org.osgi.framework.BundleContext)

Example 30 with Builder

use of io.fabric8.maven.docker.config.CopyConfiguration.Builder in project fabric8 by jboss-fuse.

the class ManagedContainerTest method testContainerLifecycle.

@Test
public void testContainerLifecycle() throws Exception {
    ContainerConfigurationBuilder builder = ContainerConfigurationBuilder.create();
    ContainerConfiguration configuration = builder.setTargetDirectory("target/managed-container").getConfiguration();
    ManagedContainer<?> container = ManagedContainer.Factory.create(configuration);
    Assert.assertNotNull("ManagedContainer not null", container);
    try {
        Assert.assertNotNull("Container home not null", container.getContainerHome());
        container.start();
    } finally {
        container.destroy();
    }
}
Also used : ContainerConfigurationBuilder(io.fabric8.runtime.container.ContainerConfigurationBuilder) ContainerConfiguration(io.fabric8.runtime.container.ContainerConfiguration) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)60 ProfileBuilder (io.fabric8.api.ProfileBuilder)34 Profile (io.fabric8.api.Profile)33 KubernetesListBuilder (io.fabric8.kubernetes.api.model.KubernetesListBuilder)27 FabricService (io.fabric8.api.FabricService)24 InputStream (java.io.InputStream)21 Deployment (org.jboss.arquillian.container.test.api.Deployment)21 OSGiManifestBuilder (org.jboss.osgi.metadata.OSGiManifestBuilder)21 Asset (org.jboss.shrinkwrap.api.asset.Asset)21 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)21 ServiceTracker (org.osgi.util.tracker.ServiceTracker)20 HashMap (java.util.HashMap)19 Map (java.util.Map)19 Logger (org.slf4j.Logger)19 CommandSupport (io.fabric8.itests.support.CommandSupport)18 ConfigurationAdmin (org.osgi.service.cm.ConfigurationAdmin)17 ServiceLocator (io.fabric8.api.gravia.ServiceLocator)16 IOException (java.io.IOException)16 Action (org.apache.felix.gogo.commands.Action)16 AbstractCommand (org.apache.felix.gogo.commands.basic.AbstractCommand)16