Search in sources :

Example 31 with Builder

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

the class PatchBundlesIntegrationTest method createdeployment.

@Deployment
public static JavaArchive createdeployment() {
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "test.jar");
    archive.addClass(ServiceLocator.class);
    archive.addClass(IOHelpers.class);
    archive.addPackage(ServiceTracker.class.getPackage());
    archive.addPackages(true, OSGiManifestBuilder.class.getPackage());
    archive.setManifest(new Asset() {

        public InputStream openStream() {
            OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
            builder.addBundleSymbolicName(archive.getName());
            builder.addBundleManifestVersion(2);
            builder.addImportPackages(Bundle.class, Service.class, PatchManagement.class, Validatable.class);
            return builder.openStream();
        }
    });
    // add the original bundle as well as the patch zip files as resources
    archive.add(createPatchableBundle("1.0.0"), "/bundles", ZipExporter.class);
    archive.add(createPatchZipFile("patch-01"), "/patches", ZipExporter.class);
    archive.add(createPatchZipFile("patch-02"), "/patches", ZipExporter.class);
    archive.add(createPatchZipFile("patch-02-without-range"), "/patches", ZipExporter.class);
    return archive;
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) InputStream(java.io.InputStream) Bundle(org.osgi.framework.Bundle) PatchManagement(io.fabric8.patch.management.PatchManagement) OSGiManifestBuilder(org.jboss.osgi.metadata.OSGiManifestBuilder) Asset(org.jboss.shrinkwrap.api.asset.Asset) Service(io.fabric8.patch.Service) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Validatable(io.fabric8.api.scr.Validatable) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 32 with Builder

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

the class PatchFilesIntegrationTest method createdeployment.

@Deployment
public static JavaArchive createdeployment() {
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "test.jar");
    archive.addClass(ServiceLocator.class);
    archive.addClass(IOHelpers.class);
    archive.addPackage(ServiceTracker.class.getPackage());
    archive.addPackages(true, OSGiManifestBuilder.class.getPackage());
    archive.setManifest(new Asset() {

        public InputStream openStream() {
            OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
            builder.addBundleSymbolicName(archive.getName());
            builder.addBundleManifestVersion(2);
            builder.addImportPackages(Bundle.class, Service.class, PatchManagement.class, Validatable.class);
            return builder.openStream();
        }
    });
    // add the patch zip files as resources
    archive.add(createPatchZipFile("file-01"), "/patches", ZipExporter.class);
    archive.add(createPatchZipFile("file-02"), "/patches", ZipExporter.class);
    return archive;
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Bundle(org.osgi.framework.Bundle) PatchManagement(io.fabric8.patch.management.PatchManagement) OSGiManifestBuilder(org.jboss.osgi.metadata.OSGiManifestBuilder) Asset(org.jboss.shrinkwrap.api.asset.Asset) Service(io.fabric8.patch.Service) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Validatable(io.fabric8.api.scr.Validatable) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 33 with Builder

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

the class PatchMigratorTest method createdeployment.

@Deployment
public static JavaArchive createdeployment() {
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "test.jar");
    archive.setManifest(new Asset() {

        public InputStream openStream() {
            OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
            builder.addBundleSymbolicName(archive.getName());
            builder.addBundleManifestVersion(2);
            builder.addImportPackages(Bundle.class, Service.class, PatchManagement.class, Validatable.class);
            return builder.openStream();
        }
    });
    archive.addClass(ServiceLocator.class);
    archive.addClass(IOHelpers.class);
    archive.addPackage(ServiceTracker.class.getPackage());
    archive.addPackages(true, OSGiManifestBuilder.class.getPackage());
    // add the original bundle as well as the patch zip files as resources
    archive.add(createPatchZipFile("migrator-patch-01"), "/patches", ZipExporter.class);
    return archive;
}
Also used : ServiceTracker(org.osgi.util.tracker.ServiceTracker) InputStream(java.io.InputStream) Bundle(org.osgi.framework.Bundle) PatchManagement(io.fabric8.patch.management.PatchManagement) OSGiManifestBuilder(org.jboss.osgi.metadata.OSGiManifestBuilder) Asset(org.jboss.shrinkwrap.api.asset.Asset) Service(io.fabric8.patch.Service) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Validatable(io.fabric8.api.scr.Validatable) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 34 with Builder

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

the class PatchThePatchServiceTest method createdeployment.

@Deployment
public static JavaArchive createdeployment() throws Exception {
    final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "test.jar");
    archive.addClass(ServiceLocator.class);
    archive.addClass(IOHelpers.class);
    archive.addPackage(ServiceTracker.class.getPackage());
    archive.addPackages(true, OSGiManifestBuilder.class.getPackage());
    archive.addPackage(CommandSupport.class.getPackage());
    archive.addClass(VersionCleaner.class);
    archive.setManifest(new Asset() {

        public InputStream openStream() {
            OSGiManifestBuilder builder = OSGiManifestBuilder.newInstance();
            builder.addBundleSymbolicName(archive.getName());
            builder.addBundleManifestVersion(2);
            builder.addImportPackages(Bundle.class, Logger.class);
            builder.addImportPackages(AbstractCommand.class, Action.class, Function.class, Validatable.class);
            builder.addImportPackages(InvalidComponentException.class);
            builder.addImportPackage("org.apache.felix.service.command;status=provisional");
            return builder.openStream();
        }
    });
    // add the patch zip files as resource
    archive.add(createPatchZipFile(PATCH_ID), "/patches", ZipExporter.class);
    return archive;
}
Also used : Action(org.apache.felix.gogo.commands.Action) ServiceTracker(org.osgi.util.tracker.ServiceTracker) Bundle(org.osgi.framework.Bundle) AbstractCommand(org.apache.felix.gogo.commands.basic.AbstractCommand) Logger(org.slf4j.Logger) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) Validatable(io.fabric8.api.scr.Validatable) Function(org.apache.felix.service.command.Function) InvalidComponentException(io.fabric8.api.InvalidComponentException) OSGiManifestBuilder(org.jboss.osgi.metadata.OSGiManifestBuilder) Asset(org.jboss.shrinkwrap.api.asset.Asset) CommandSupport(io.fabric8.itests.support.CommandSupport) Deployment(org.jboss.arquillian.container.test.api.Deployment)

Example 35 with Builder

use of io.fabric8.maven.docker.config.CopyConfiguration.Builder 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)

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