Search in sources :

Example 6 with Manager

use of io.fabric8.dosgi.impl.Manager 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 7 with Manager

use of io.fabric8.dosgi.impl.Manager in project fabric8 by jboss-fuse.

the class Activator method destroyManager.

protected void destroyManager() {
    if (manager != null) {
        Manager mgr = manager;
        manager = null;
        try {
            mgr.destroy();
        } catch (IOException e) {
        // ignore
        }
    }
}
Also used : IOException(java.io.IOException) Manager(io.fabric8.dosgi.impl.Manager)

Example 8 with Manager

use of io.fabric8.dosgi.impl.Manager in project fabric8-maven-plugin by fabric8io.

the class ResourceMojo method generateResources.

private KubernetesList generateResources(List<ImageConfiguration> images) throws IOException, MojoExecutionException {
    // Manager for calling enrichers.
    openshiftDependencyResources = new OpenShiftDependencyResources(log);
    loadOpenShiftOverrideResources();
    EnricherContext.Builder ctxBuilder = new EnricherContext.Builder().project(project).session(session).goalFinder(goalFinder).config(extractEnricherConfig()).resources(resources).images(resolvedImages).log(log).useProjectClasspath(useProjectClasspath).openshiftDependencyResources(openshiftDependencyResources);
    if (resources != null) {
        ctxBuilder.namespace(resources.getNamespace());
    }
    EnricherManager enricherManager = new EnricherManager(resources, ctxBuilder.build());
    // Generate all resources from the main resource diretory, configuration and enrich them accordingly
    KubernetesListBuilder builder = generateAppResources(images, enricherManager);
    // Add resources found in subdirectories of resourceDir, with a certain profile
    // applied
    addProfiledResourcesFromSubirectories(builder, resourceDir, enricherManager);
    return builder.build();
}
Also used : EnricherContext(io.fabric8.maven.enricher.api.EnricherContext) EnricherManager(io.fabric8.maven.plugin.enricher.EnricherManager)

Example 9 with Manager

use of io.fabric8.dosgi.impl.Manager in project fabric8-maven-plugin by fabric8io.

the class EnricherManagerTest method enrichSimple.

@Test
public void enrichSimple() {
    new Expectations() {

        {
            context.getConfig();
            result = new ProcessorConfig(Arrays.asList("fmp-project"), null, new HashMap<String, TreeMap>());
        }
    };
    EnricherManager manager = new EnricherManager(null, context);
    KubernetesListBuilder builder = new KubernetesListBuilder();
    builder.addNewReplicaSetItem().withNewSpec().withNewTemplate().withNewSpec().addNewContainer().withName("test").withImage("busybox").endContainer().endSpec().endTemplate().endSpec().endReplicaSetItem();
    manager.enrich(builder);
    KubernetesList list = builder.build();
    assertEquals(1, list.getItems().size());
    ReplicaSet pod = (ReplicaSet) list.getItems().get(0);
    ObjectMeta metadata = pod.getMetadata();
    assertNotNull(metadata);
    Map<String, String> labels = metadata.getLabels();
    assertNotNull(labels);
    assertEquals("fabric8", labels.get("provider"));
}
Also used : Expectations(mockit.Expectations) ReplicaSet(io.fabric8.kubernetes.api.model.extensions.ReplicaSet) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) Test(org.junit.Test)

Example 10 with Manager

use of io.fabric8.dosgi.impl.Manager in project fabric8-maven-plugin by fabric8io.

the class EnricherManagerTest method createDefaultResources.

@Test
public void createDefaultResources() {
    new Expectations() {

        {
            context.getConfig();
            result = new ProcessorConfig(Arrays.asList("fmp-controller"), null, null);
            context.getImages();
            result = new ImageConfiguration.Builder().alias("img1").name("img1").build();
        }
    };
    EnricherManager manager = new EnricherManager(null, context);
    KubernetesListBuilder builder = new KubernetesListBuilder();
    manager.createDefaultResources(builder);
    assertTrue(builder.build().getItems().size() > 0);
}
Also used : Expectations(mockit.Expectations) ProcessorConfig(io.fabric8.maven.core.config.ProcessorConfig) Test(org.junit.Test)

Aggregations

IOException (java.io.IOException)9 Downloader (io.fabric8.agent.download.Downloader)7 HashMap (java.util.HashMap)7 MultiException (io.fabric8.common.util.MultiException)6 StreamProvider (io.fabric8.agent.download.StreamProvider)5 Test (org.junit.Test)5 DownloadCallback (io.fabric8.agent.download.DownloadCallback)4 File (java.io.File)4 Bundle (org.osgi.framework.Bundle)4 DownloadManager (io.fabric8.agent.download.DownloadManager)3 BundleInfo (io.fabric8.agent.model.BundleInfo)3 Feature (io.fabric8.agent.model.Feature)3 Repository (io.fabric8.agent.model.Repository)3 FileInputStream (java.io.FileInputStream)3 MalformedURLException (java.net.MalformedURLException)3 Map (java.util.Map)3 Set (java.util.Set)3 MapUtils.addToMapSet (io.fabric8.agent.internal.MapUtils.addToMapSet)2 ConfigFile (io.fabric8.agent.model.ConfigFile)2 StaticRepository (io.fabric8.agent.repository.StaticRepository)2