Search in sources :

Example 6 with Archive

use of org.jboss.shrinkwrap.api.Archive in project wildfly-swarm by wildfly-swarm.

the class ConfigurableManagerTest method testDeploymentConfigurableUsingAlias.

@Test
public void testDeploymentConfigurableUsingAlias() throws Exception {
    Properties props = new Properties();
    Map<String, String> env = new HashMap<>();
    ConfigViewFactory factory = new ConfigViewFactory(props, env);
    factory.withProperty("swarm.http.context", "/myapp");
    ConfigView configView = factory.get(true);
    DeploymentContext context = new DeploymentContextImpl();
    ConfigurableManager manager = new ConfigurableManager(configView, context);
    Archive archive = ShrinkWrap.create(JavaArchive.class, "myapp.war");
    try {
        context.activate(archive, archive.getName(), false);
        Component component = new Component();
        manager.scan(component);
        assertThat(component.context.get()).isEqualTo("/myapp");
    } finally {
        context.deactivate();
    }
}
Also used : DeploymentContext(org.wildfly.swarm.container.runtime.cdi.DeploymentContext) Archive(org.jboss.shrinkwrap.api.Archive) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) HashMap(java.util.HashMap) ConfigView(org.wildfly.swarm.spi.api.config.ConfigView) ConfigViewFactory(org.wildfly.swarm.container.config.ConfigViewFactory) Properties(java.util.Properties) DeploymentContextImpl(org.wildfly.swarm.container.runtime.cdi.DeploymentContextImpl) Test(org.junit.Test)

Example 7 with Archive

use of org.jboss.shrinkwrap.api.Archive in project wildfly-swarm by wildfly-swarm.

the class ConfigurableManagerTest method testDeploymentConfigurable.

@Test
public void testDeploymentConfigurable() throws Exception {
    Properties props = new Properties();
    Map<String, String> env = new HashMap<>();
    ConfigViewFactory factory = new ConfigViewFactory(props, env);
    factory.withProperty("swarm.deployment.[myapp.war].context", "/myapp");
    ConfigView configView = factory.get(true);
    DeploymentContext context = new DeploymentContextImpl();
    ConfigurableManager manager = new ConfigurableManager(configView, context);
    Archive archive = ShrinkWrap.create(JavaArchive.class, "myapp.war");
    try {
        context.activate(archive, archive.getName(), false);
        Component component = new Component();
        manager.scan(component);
        assertThat(component.context.get()).isEqualTo("/myapp");
    } finally {
        context.deactivate();
    }
}
Also used : DeploymentContext(org.wildfly.swarm.container.runtime.cdi.DeploymentContext) Archive(org.jboss.shrinkwrap.api.Archive) JavaArchive(org.jboss.shrinkwrap.api.spec.JavaArchive) HashMap(java.util.HashMap) ConfigView(org.wildfly.swarm.spi.api.config.ConfigView) ConfigViewFactory(org.wildfly.swarm.container.config.ConfigViewFactory) Properties(java.util.Properties) DeploymentContextImpl(org.wildfly.swarm.container.runtime.cdi.DeploymentContextImpl) Test(org.junit.Test)

Example 8 with Archive

use of org.jboss.shrinkwrap.api.Archive in project wildfly-swarm by wildfly-swarm.

the class RuntimeServer method start.

public Deployer start(boolean eagerOpen) throws Exception {
    UUID uuid = UUIDFactory.getUUID();
    System.setProperty("jboss.server.management.uuid", uuid.toString());
    File configurationFile;
    try {
        configurationFile = TempFileManager.INSTANCE.newTempFile("swarm-config-", ".xml");
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    this.networkConfigurer.configure();
    List<ModelNode> bootstrapOperations = new ArrayList<>();
    BootstrapConfiguration bootstrapConfiguration = () -> bootstrapOperations;
    this.container = new SelfContainedContainer(new Bootstrap.ConfigurationPersisterFactory() {

        @Override
        public ExtensibleConfigurationPersister createConfigurationPersister(ServerEnvironment serverEnvironment, ExecutorService executorService) {
            return new BootstrapPersister(bootstrapConfiguration, configurationFile);
        }
    });
    try (AutoCloseable handle = Performance.time("pre-customizers")) {
        for (Customizer each : this.preCustomizers) {
            SwarmMessages.MESSAGES.callingPreCustomizer(each);
            each.customize();
        }
    }
    try (AutoCloseable handle = Performance.time("post-customizers")) {
        for (Customizer each : this.postCustomizers) {
            SwarmMessages.MESSAGES.callingPostCustomizer(each);
            each.customize();
        }
    }
    this.networkConfigurer.configure();
    try (AutoCloseable handle = Performance.time("configurable-manager rescan")) {
        this.configurableManager.rescan();
        this.configurableManager.log();
    }
    try (AutoCloseable handle = Performance.time("marshall DMR")) {
        this.dmrMarshaller.marshal(bootstrapOperations);
    }
    SwarmMessages.MESSAGES.wildflyBootstrap(bootstrapOperations.toString());
    Thread.currentThread().setContextClassLoader(RuntimeServer.class.getClassLoader());
    List<ServiceActivator> activators = new ArrayList<>();
    StreamSupport.stream(serviceActivators.spliterator(), false).filter(Objects::nonNull).forEach(activators::add);
    activators.add(new ContentRepositoryServiceActivator(this.contentRepository));
    try (AutoCloseable wildflyStart = Performance.time("WildFly start")) {
        ServiceContainer serviceContainer = null;
        try (AutoCloseable startWildflyItself = Performance.time("Starting WildFly itself")) {
            // serviceContainer = this.container.start(bootstrapOperations, this.contentProvider, activators);
            serviceContainer = this.container.start(bootstrapOperations, activators);
            this.containerStarted = true;
        }
        try (AutoCloseable checkFailedServices = Performance.time("Checking for failed services")) {
            for (ServiceName serviceName : serviceContainer.getServiceNames()) {
                ServiceController<?> serviceController = serviceContainer.getService(serviceName);
                /*
                    if (serviceController.getImmediateUnavailableDependencies().size() > 0) {
                        System.err.println("Service missing dependencies: " + serviceController.getName());
                        for (ServiceName name : serviceController.getImmediateUnavailableDependencies()) {
                            System.err.println("  - " + name);
                        }
                    }
                    */
                StartException exception = serviceController.getStartException();
                if (exception != null) {
                    throw exception;
                }
            }
        }
        /*
            for (ServiceName serviceName : serviceContainer.getServiceNames()) {
                System.err.println(" === " + serviceName);
            }
            */
        ModelController controller = (ModelController) serviceContainer.getService(Services.JBOSS_SERVER_CONTROLLER).getValue();
        Executor executor = Executors.newSingleThreadExecutor();
        try (AutoCloseable creatingControllerClient = Performance.time("Creating controller client")) {
            // Can't use controller.getClientFactory() due to non-public nature of that method.
            // noinspection deprecation
            this.client = controller.createClient(executor);
        }
        RuntimeDeployer deployer = this.deployer.get();
        try (AutoCloseable installDeployer = Performance.time("Installing deployer")) {
            serviceContainer.addService(ServiceName.of("swarm", "deployer"), new ValueService<>(new ImmediateValue<Deployer>(deployer))).install();
        }
        try (AutoCloseable configUserSpaceExt = Performance.time("Configure user-space extensions")) {
            configureUserSpaceExtensions();
        }
        try (AutoCloseable deployments = Performance.time("Implicit Deployments")) {
            for (Archive each : this.implicitDeployments) {
                if (each != null) {
                    deployer.deploy(each);
                }
            }
        }
        this.artifactDeployer.deploy();
        deployer.implicitDeploymentsComplete();
        return deployer;
    }
}
Also used : Archive(org.jboss.shrinkwrap.api.Archive) ContentRepositoryServiceActivator(org.wildfly.swarm.container.runtime.wildfly.ContentRepositoryServiceActivator) ArrayList(java.util.ArrayList) ValueService(org.jboss.msc.service.ValueService) ServiceContainer(org.jboss.msc.service.ServiceContainer) Executor(java.util.concurrent.Executor) ServerEnvironment(org.jboss.as.server.ServerEnvironment) StartException(org.jboss.msc.service.StartException) UUID(java.util.UUID) SelfContainedContainer(org.wildfly.swarm.internal.wildfly.SelfContainedContainer) BootstrapPersister(org.wildfly.swarm.container.runtime.xmlconfig.BootstrapPersister) Deployer(org.wildfly.swarm.container.internal.Deployer) BootstrapConfiguration(org.wildfly.swarm.container.runtime.xmlconfig.BootstrapConfiguration) IOException(java.io.IOException) ContentRepositoryServiceActivator(org.wildfly.swarm.container.runtime.wildfly.ContentRepositoryServiceActivator) ServiceActivator(org.jboss.msc.service.ServiceActivator) ServiceName(org.jboss.msc.service.ServiceName) ExecutorService(java.util.concurrent.ExecutorService) Customizer(org.wildfly.swarm.spi.api.Customizer) ModelNode(org.jboss.dmr.ModelNode) ModelController(org.jboss.as.controller.ModelController) File(java.io.File)

Example 9 with Archive

use of org.jboss.shrinkwrap.api.Archive in project wildfly-swarm by wildfly-swarm.

the class DeploymentProducer method index.

private void index(Archive<?> archive, List<IndexView> indexes) throws IOException {
    LOGGER.debugv("Indexing archive: {0}", archive.getName());
    // First try to load attached index
    Node indexNode = archive.get(ArchivePaths.create(INDEX_LOCATION));
    if (indexNode != null) {
        try (InputStream indexStream = indexNode.getAsset().openStream()) {
            LOGGER.debugv("Loading attached index from archive: {0}", archive.getName());
            indexes.add(new IndexReader(indexStream).read());
        }
    } else {
        // No index found - index all classes found
        Indexer indexer = new Indexer();
        for (Map.Entry<ArchivePath, Node> entry : archive.getContent(this::isClass).entrySet()) {
            try (InputStream contentStream = entry.getValue().getAsset().openStream()) {
                LOGGER.debugv("Indexing asset: {0} from archive: {1}", entry.getKey().get(), archive.getName());
                indexer.index(contentStream);
            } catch (IOException indexerIOException) {
                LOGGER.warnv(indexerIOException, "Failed parsing: {0} from archive: {1}", entry.getKey().get(), archive.getName());
            }
        }
        Index index = indexer.complete();
        indexes.add(index);
    }
    if (archive instanceof LibraryContainer) {
        for (Map.Entry<ArchivePath, Node> entry : archive.getContent(a -> a.get().endsWith(JAR_SUFFIX)).entrySet()) {
            if (entry.getValue().getAsset() instanceof ArchiveAsset) {
                ArchiveAsset archiveAsset = (ArchiveAsset) entry.getValue().getAsset();
                index(archiveAsset.getArchive(), indexes);
            } else {
                try (InputStream contentStream = entry.getValue().getAsset().openStream()) {
                    JARArchive jarArchive = ShrinkWrap.create(JARArchive.class, entry.getKey().get()).as(ZipImporter.class).importFrom(contentStream).as(JARArchive.class);
                    index(jarArchive, indexes);
                }
            }
        }
    }
}
Also used : Produces(javax.enterprise.inject.Produces) DeploymentScoped(org.wildfly.swarm.spi.runtime.annotations.DeploymentScoped) Logger(org.jboss.logging.Logger) Node(org.jboss.shrinkwrap.api.Node) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Indexer(org.jboss.jandex.Indexer) ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) ArchivePaths(org.jboss.shrinkwrap.api.ArchivePaths) CompositeIndex(org.jboss.jandex.CompositeIndex) Map(java.util.Map) Index(org.jboss.jandex.Index) DeploymentContext(org.wildfly.swarm.container.runtime.cdi.DeploymentContext) IndexView(org.jboss.jandex.IndexView) ZipImporter(org.jboss.shrinkwrap.api.importer.ZipImporter) ShrinkWrap(org.jboss.shrinkwrap.api.ShrinkWrap) IndexReader(org.jboss.jandex.IndexReader) JARArchive(org.wildfly.swarm.spi.api.JARArchive) IOException(java.io.IOException) Archive(org.jboss.shrinkwrap.api.Archive) List(java.util.List) LibraryContainer(org.jboss.shrinkwrap.api.container.LibraryContainer) ApplicationScoped(javax.enterprise.context.ApplicationScoped) InputStream(java.io.InputStream) ArchiveAsset(org.jboss.shrinkwrap.api.asset.ArchiveAsset) InputStream(java.io.InputStream) Node(org.jboss.shrinkwrap.api.Node) CompositeIndex(org.jboss.jandex.CompositeIndex) Index(org.jboss.jandex.Index) ArchiveAsset(org.jboss.shrinkwrap.api.asset.ArchiveAsset) IOException(java.io.IOException) ArchivePath(org.jboss.shrinkwrap.api.ArchivePath) Indexer(org.jboss.jandex.Indexer) IndexReader(org.jboss.jandex.IndexReader) LibraryContainer(org.jboss.shrinkwrap.api.container.LibraryContainer) JARArchive(org.wildfly.swarm.spi.api.JARArchive) Map(java.util.Map)

Example 10 with Archive

use of org.jboss.shrinkwrap.api.Archive in project wildfly-swarm by wildfly-swarm.

the class ApimanManagerApiDeploymentTest method testApimanManagerWAR.

@Test
public void testApimanManagerWAR() throws Exception {
    File warFile = Maven.resolver().resolve("io.apiman:apiman-manager-api-war:war:1.3.1.Final").withoutTransitivity().asSingleFile();
    WildFlyConfigBuilder cfgBuilder = new WildFlyConfigBuilder();
    cfgBuilder.addDefaultSources();
    Config cfg = cfgBuilder.build();
    Archive archive = ShrinkWrap.createFromZipFile(JAXRSArchive.class, warFile);
    OpenApiConfig config = new OpenApiConfig(cfg);
    OpenApiDocument.INSTANCE.reset();
    OpenApiDeploymentProcessor processor = new OpenApiDeploymentProcessor(config, archive);
    processor.process();
    new OpenApiServletContextListener().contextInitialized(null);
    String actual = OpenApiSerializer.serialize(OpenApiDocument.INSTANCE.get(), Format.JSON);
    String expected = loadResource(getClass().getResource("testApimanManagerWAR.expected.json"));
    // System.out.println(actual);
    assertJsonEquals(expected, actual);
}
Also used : WildFlyConfigBuilder(org.wildfly.microprofile.config.WildFlyConfigBuilder) Archive(org.jboss.shrinkwrap.api.Archive) JAXRSArchive(org.wildfly.swarm.jaxrs.JAXRSArchive) OpenApiServletContextListener(org.wildfly.swarm.microprofile.openapi.deployment.OpenApiServletContextListener) OpenApiConfig(org.wildfly.swarm.microprofile.openapi.api.OpenApiConfig) Config(org.eclipse.microprofile.config.Config) OpenApiConfig(org.wildfly.swarm.microprofile.openapi.api.OpenApiConfig) File(java.io.File) Test(org.junit.Test)

Aggregations

Archive (org.jboss.shrinkwrap.api.Archive)37 Node (org.jboss.shrinkwrap.api.Node)17 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)12 Test (org.junit.Test)12 File (java.io.File)11 URL (java.net.URL)10 ArrayList (java.util.ArrayList)9 ArchivePath (org.jboss.shrinkwrap.api.ArchivePath)8 JolokiaFraction (org.wildfly.swarm.jolokia.JolokiaFraction)8 BufferedReader (java.io.BufferedReader)7 IOException (java.io.IOException)7 InputStreamReader (java.io.InputStreamReader)7 Map (java.util.Map)7 HashMap (java.util.HashMap)6 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)6 List (java.util.List)5 ZipImporter (org.jboss.shrinkwrap.api.importer.ZipImporter)5 DeploymentContext (org.wildfly.swarm.container.runtime.cdi.DeploymentContext)5 JARArchive (org.wildfly.swarm.spi.api.JARArchive)5 Path (java.nio.file.Path)4