Search in sources :

Example 46 with Config

use of io.fabric8.docker.client.Config in project fabric8 by jboss-fuse.

the class Fabric8Container method start.

@Override
public void start() throws LifecycleException {
    // lets kill any containers that are running before we start
    FabricAssertions.killJavaAndDockerProcesses();
    fabricControllerManager = createFabricControllerManager();
    Fabric8ContainerConfiguration config = configuration.get();
    config.configure(fabricControllerManager);
    try {
        FabricController fabricController = FabricAssertions.assertFabricCreate(fabricControllerManager);
        controller.set(fabricController);
    } catch (Exception e) {
        throw new LifecycleException("Failed to create fabric: " + e, e);
    }
    System.out.println("Created a controller " + controller.get());
}
Also used : LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) FabricController(io.fabric8.testkit.FabricController) LifecycleException(org.jboss.arquillian.container.spi.client.container.LifecycleException) DeploymentException(org.jboss.arquillian.container.spi.client.container.DeploymentException)

Example 47 with Config

use of io.fabric8.docker.client.Config in project fabric8 by jboss-fuse.

the class ProxyServlet method init.

/**
 * Initialize the <code>ProxyServlet</code>
 *
 * @param config The Servlet configuration passed in by the servlet container
 */
@Override
public void init(ServletConfig config) throws ServletException {
    HttpProxyRuleBase ruleBase = new HttpProxyRuleBase();
    loadRuleBase(config, ruleBase);
    resolver.setMappingRules(ruleBase);
    Protocol.registerProtocol("http", new Protocol("http", new NonBindingSocketFactory(), 80));
    Protocol.registerProtocol("https", new Protocol("https", new NonBindingSocketFactory(), 443));
}
Also used : HttpProxyRuleBase(io.fabric8.gateway.model.HttpProxyRuleBase) Protocol(org.apache.commons.httpclient.protocol.Protocol) NonBindingSocketFactory(io.fabric8.gateway.servlet.support.NonBindingSocketFactory)

Example 48 with Config

use of io.fabric8.docker.client.Config in project fabric8 by jboss-fuse.

the class Log4jLogQuery method loadCoords.

protected String loadCoords(String coords, String filePath, String classifier) throws IOException {
    String[] split = coords.split("/");
    if (split != null && split.length > 2) {
        String groupId = split[0];
        String artifactId = split[1];
        String version = split[2];
        if (resolver == null) {
            Properties defaultProperties = getDefaultProperties();
            Properties systemProperties = System.getProperties();
            if (config == null) {
                Properties combined = new Properties();
                combined.putAll(defaultProperties);
                combined.putAll(systemProperties);
                if (properties != null) {
                    combined.putAll(properties);
                }
                config = new MavenConfigurationImpl(new PropertiesPropertyResolver(combined), ServiceConstants.PID);
            }
            resolver = new AetherBasedResolver(config);
        }
        File file = resolver.resolveFile(groupId, artifactId, classifier, "jar", version);
        if (file.exists() && file.isFile()) {
            if (isRoot(filePath)) {
                return jarIndex(file);
            }
            String fileUri = file.toURI().toString();
            URL url = new URL("jar:" + fileUri + "!" + filePath);
            return loadString(url);
        }
    }
    return null;
}
Also used : MavenConfigurationImpl(io.fabric8.maven.util.MavenConfigurationImpl) PropertiesPropertyResolver(org.ops4j.util.property.PropertiesPropertyResolver) Properties(java.util.Properties) File(java.io.File) URL(java.net.URL) AetherBasedResolver(io.fabric8.maven.url.internal.AetherBasedResolver)

Example 49 with Config

use of io.fabric8.docker.client.Config in project fabric8 by jboss-fuse.

the class ServiceFactoryTest method testDiscoveryOnRestartCurator.

@Test
public void testDiscoveryOnRestartCurator() throws Exception {
    underTest = new ActiveMQServiceFactory();
    underTest.curator = curator;
    Properties props = new Properties();
    props.put("config", "amq.xml");
    props.put("broker-name", "amq");
    props.put("group", "amq");
    props.put("connectors", "openwire");
    props.put("openwire-port", "0");
    props.put("container.ip", "localhost");
    underTest.updated("b", props);
    final AtomicReference<CuratorFramework> curatorFrameworkAtomicReference = new AtomicReference<>(curator);
    OsgiFabricDiscoveryAgent osgiFabricDiscoveryAgent = new OsgiFabricDiscoveryAgent(new BundleContext() {

        @Override
        public String getProperty(String s) {
            return null;
        }

        @Override
        public Bundle getBundle() {
            return null;
        }

        @Override
        public Bundle installBundle(String s, InputStream inputStream) throws BundleException {
            return null;
        }

        @Override
        public Bundle installBundle(String s) throws BundleException {
            return null;
        }

        @Override
        public Bundle getBundle(long l) {
            return null;
        }

        @Override
        public Bundle[] getBundles() {
            return new Bundle[0];
        }

        @Override
        public void addServiceListener(ServiceListener serviceListener, String s) throws InvalidSyntaxException {
        }

        @Override
        public void addServiceListener(ServiceListener serviceListener) {
        }

        @Override
        public void removeServiceListener(ServiceListener serviceListener) {
        }

        @Override
        public void addBundleListener(BundleListener bundleListener) {
        }

        @Override
        public void removeBundleListener(BundleListener bundleListener) {
        }

        @Override
        public void addFrameworkListener(FrameworkListener frameworkListener) {
        }

        @Override
        public void removeFrameworkListener(FrameworkListener frameworkListener) {
        }

        @Override
        public ServiceRegistration<?> registerService(String[] strings, Object o, Dictionary<String, ?> dictionary) {
            return null;
        }

        @Override
        public ServiceRegistration<?> registerService(String s, Object o, Dictionary<String, ?> dictionary) {
            return null;
        }

        @Override
        public <S> ServiceRegistration<S> registerService(Class<S> aClass, S s, Dictionary<String, ?> dictionary) {
            return null;
        }

        @Override
        public ServiceReference<?>[] getServiceReferences(String s, String s1) throws InvalidSyntaxException {
            return new ServiceReference<?>[0];
        }

        @Override
        public ServiceReference<?>[] getAllServiceReferences(String s, String s1) throws InvalidSyntaxException {
            return new ServiceReference<?>[0];
        }

        @Override
        public ServiceReference<?> getServiceReference(String s) {
            return null;
        }

        @Override
        public <S> ServiceReference<S> getServiceReference(Class<S> aClass) {
            return null;
        }

        @Override
        public <S> Collection<ServiceReference<S>> getServiceReferences(Class<S> aClass, String s) throws InvalidSyntaxException {
            return null;
        }

        @Override
        public <S> S getService(ServiceReference<S> serviceReference) {
            return (S) curatorFrameworkAtomicReference.get();
        }

        @Override
        public boolean ungetService(ServiceReference<?> serviceReference) {
            return false;
        }

        @Override
        public File getDataFile(String s) {
            return null;
        }

        @Override
        public Filter createFilter(String s) throws InvalidSyntaxException {
            return null;
        }

        @Override
        public Bundle getBundle(String s) {
            return null;
        }
    });
    final LinkedBlockingQueue<DiscoveryEvent> discoveryEvents = new LinkedBlockingQueue<DiscoveryEvent>(10);
    osgiFabricDiscoveryAgent.setDiscoveryListener(new DiscoveryListener() {

        @Override
        public void onServiceAdd(DiscoveryEvent discoveryEvent) {
            discoveryEvents.offer(discoveryEvent);
        }

        @Override
        public void onServiceRemove(DiscoveryEvent discoveryEvent) {
        }
    });
    // will call into dummy bundle and get curator
    osgiFabricDiscoveryAgent.addingService(null);
    osgiFabricDiscoveryAgent.setGroupName("amq");
    osgiFabricDiscoveryAgent.start();
    DiscoveryEvent event = discoveryEvents.poll(5, TimeUnit.SECONDS);
    LOG.info("event: " + event);
    assertNotNull("got added service", event);
    underTest.deleted("b");
    // swap curator ref
    CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString("localhost:" + zkPort).sessionTimeoutMs(15000).retryPolicy(new RetryNTimes(5000, 1000));
    curator = builder.build();
    LOG.debug("Starting new curator " + curator);
    curator.start();
    curatorFrameworkAtomicReference.get().close();
    curatorFrameworkAtomicReference.set(curator);
    // will call into dummy bundle and get new curator ref
    osgiFabricDiscoveryAgent.addingService(null);
    // start broker again
    underTest.curator = curator;
    underTest.updated("b", props);
    event = discoveryEvents.poll(5, TimeUnit.SECONDS);
    LOG.info("new event: " + event);
    assertNotNull("got newly added service", event);
    underTest.deleted("b");
}
Also used : CuratorFrameworkFactory(org.apache.curator.framework.CuratorFrameworkFactory) DiscoveryEvent(org.apache.activemq.command.DiscoveryEvent) Properties(java.util.Properties) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) CuratorFramework(org.apache.curator.framework.CuratorFramework) RetryNTimes(org.apache.curator.retry.RetryNTimes) InputStream(java.io.InputStream) AtomicReference(java.util.concurrent.atomic.AtomicReference) OsgiFabricDiscoveryAgent(io.fabric8.mq.fabric.discovery.OsgiFabricDiscoveryAgent) Collection(java.util.Collection) File(java.io.File) DiscoveryListener(org.apache.activemq.transport.discovery.DiscoveryListener) Test(org.junit.Test)

Example 50 with Config

use of io.fabric8.docker.client.Config in project fabric8 by jboss-fuse.

the class DeploymentAgentTest method testFeatureRepoResolution.

@Test
@SuppressWarnings("unchecked")
public void testFeatureRepoResolution() throws Exception {
    CommandSupport.executeCommand("fabric:create --force --clean -n --wait-for-provisioning");
    // We are just want to use a feature repository that is not part of the distribution.
    CommandSupport.executeCommand("fabric:profile-create --parent feature-camel test-profile");
    CommandSupport.executeCommand("fabric:version-create --parent 1.0 1.1");
    CommandSupport.executeCommand("fabric:profile-edit --repository mvn:io.fabric8.examples.fabric-camel-dosgi/features/" + System.getProperty("fabric.version") + "/xml/features test-profile 1.1");
    CommandSupport.executeCommand("fabric:profile-edit --feature fabric-dosgi test-profile 1.1");
    // We remove all repositories from agent config but the maven central to rely on the fabric-maven-proxy.
    // Also remove local repository
    CommandSupport.executeCommand("fabric:profile-edit --pid io.fabric8.agent/org.ops4j.pax.url.mvn.repositories=http://repo1.maven.org/maven2@id=m2central default 1.1");
    CommandSupport.executeCommand("fabric:profile-edit --pid test-profile 1.1");
    BundleContext moduleContext = ServiceLocator.getSystemContext();
    ServiceProxy<FabricService> fabricProxy = ServiceProxy.createServiceProxy(moduleContext, FabricService.class);
    try {
        FabricService fabricService = fabricProxy.getService();
        Set<Container> containers = ContainerBuilder.create().withName("smoke_cnt_a").withProfiles("test-profile").assertProvisioningResult().build(fabricService);
        try {
            // We want to remove all repositories from fabric-agent.
            for (Container container : containers) {
                CommandSupport.executeCommand("fabric:container-upgrade 1.1 " + container.getId());
                System.out.flush();
            }
            ProvisionSupport.provisioningSuccess(containers, ProvisionSupport.PROVISION_TIMEOUT);
            CommandSupport.executeCommand("fabric:container-list");
            for (Container container : containers) {
                CommandSupport.executeCommand("fabric:container-connect -u admin -p admin " + container.getId() + " osgi:list");
                CommandSupport.executeCommand("fabric:container-connect -u admin -p admin " + container.getId() + " config:proplist --pid org.ops4j.pax.url.mvn");
                System.out.flush();
            }
        } finally {
            ContainerBuilder.stop(fabricService, containers);
        }
    } finally {
        fabricProxy.close();
    }
}
Also used : Container(io.fabric8.api.Container) FabricService(io.fabric8.api.FabricService) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)106 BuildImageConfiguration (io.fabric8.maven.docker.config.BuildImageConfiguration)37 HashMap (java.util.HashMap)34 IOException (java.io.IOException)32 ResourceConfig (io.fabric8.maven.core.config.ResourceConfig)28 File (java.io.File)26 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)24 Map (java.util.Map)24 ProcessorConfig (io.fabric8.maven.core.config.ProcessorConfig)23 ImageConfiguration (io.fabric8.maven.docker.config.ImageConfiguration)21 Expectations (mockit.Expectations)20 DefaultKubernetesClient (io.fabric8.kubernetes.client.DefaultKubernetesClient)17 ArrayList (java.util.ArrayList)17 VolumeConfig (io.fabric8.maven.core.config.VolumeConfig)15 AbstractConfigHandlerTest (io.fabric8.maven.docker.config.handler.AbstractConfigHandlerTest)15 ConfigMapBuilder (io.fabric8.kubernetes.api.model.ConfigMapBuilder)14 AuthConfig (io.fabric8.maven.docker.access.AuthConfig)13 DeploymentConfig (io.fabric8.openshift.api.model.DeploymentConfig)12 Before (org.junit.Before)12 KubernetesClient (io.fabric8.kubernetes.client.KubernetesClient)11