org.wildfly.swarm.container.Container Java Examples

The following examples show how to use org.wildfly.swarm.container.Container. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: App.java    From drools-workshop with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Container container = new Container();

    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);
    deployment.as(TopologyArchive.class).advertise("restaurantService");
    deployment.setContextRoot("/api");
    deployment.addPackages(true, "org.jboss.shrinkwrap.api");
    deployment.addAsLibrary(container.createDefaultDeployment());
    deployment.addAllDependencies();
    container.start();
    container.deploy(deployment);

    Topology lookup = Topology.lookup();
    lookup.addListener(new TopologyListener() {
        @Override
        public void onChange(Topology tplg) {
            System.out.println(">>> Delivery Service: The Topology Has Changed!");
            printTopology(lookup);
        }
    });
    
    printTopology(lookup);

}
 
Example #2
Source File: App.java    From drools-workshop with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    Container container = new Container();

    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);
    deployment.as(TopologyArchive.class).advertise("deliveryService");
    deployment.setContextRoot("/api");
    deployment.addPackages(true, "org.jboss.shrinkwrap.api");
    deployment.addAsLibrary(container.createDefaultDeployment());
    deployment.addAllDependencies();
    container.start();
    container.deploy(deployment);
    
    Topology lookup = Topology.lookup();
    lookup.addListener(new TopologyListener() {
        @Override
        public void onChange(Topology tplg) {
            System.out.println(">>> Delivery Service: The Topology Has Changed!");
            printTopology(lookup);
        }
    });
    
    printTopology(lookup);
    
}
 
Example #3
Source File: Main.java    From kubernetes-lab with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
	Container container = new Container();

	container.fraction(new DatasourcesFraction().jdbcDriver("com.mysql", (d) -> {
		d.driverClassName("com.mysql.jdbc.Driver");
		d.xaDatasourceClass("com.mysql.jdbc.jdbc2.optional.MysqlXADataSource");
		d.driverModuleName("com.mysql");
	}).dataSource("MySQLDS", (ds) -> {
		ds.driverName("com.mysql");
		ds.connectionUrl(System.getenv().getOrDefault("JDBC_URL", "jdbc:mysql://mysql:3306/guestbook?useSSL=false&autoReconnect=true"));
		ds.userName(System.getenv().getOrDefault("DATASOURCE_USERNAME", "myuser"));
		ds.password(System.getenv().getOrDefault("DATASOURCE_PASSWORD", "mypassword"));
		ds.backgroundValidation(true);
		ds.validConnectionCheckerClassName("org.jboss.jca.adapters.jdbc.extensions.mysql.MySQLValidConnectionChecker");
		ds.validateOnMatch(true);
		ds.checkValidConnectionSql("SELECT 1");
	}));

	// Start the container and deploy the default war
	container.start().deploy();
}
 
Example #4
Source File: JGroupsInVmTest.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
@Test
public void testCanFindKubePing() throws Exception {
    Container container = new Container();
    container.fraction(new JGroupsFraction()
            .defaultChannel("swarm-jgroups")
            .channel("swarm-jgroups", (c) -> {
                c.stack("udp");
            })
            .stack("udp", (s) -> {
                s.transport("UDP", (t) -> {
                    t.socketBinding("jgroups-udp");
                });
                s.protocol("openshift.KUBE_PING");
            }));
    container.start().stop();
}
 
Example #5
Source File: ArqSecuredManagementInterfaceTest.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
@Override
public Container newContainer(String... args) throws Exception {
    return new Container()
            .fraction(
                    ManagementFraction.createDefaultFraction()
                            .httpInterfaceManagementInterface((iface) -> {
                                iface.securityRealm("ManagementRealm");
                            })
                            .securityRealm("ManagementRealm", (realm) -> {
                                realm.inMemoryAuthentication((authn) -> {
                                    authn.add("bob", "tacos!", true);
                                });
                                realm.inMemoryAuthorization((authz) -> {
                                    authz.add("bob", "admin");
                                });
                            })
            );
}
 
Example #6
Source File: ArqSecuredManagementInterfaceWithPrecomputedPropertiesTest.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
@Override
public Container newContainer(String... args) throws Exception {
    return new Container()
            .fraction(
                    ManagementFraction.createDefaultFraction()
                            .httpInterfaceManagementInterface((iface) -> {
                                iface.securityRealm("ManagementRealm");
                            })
                            .securityRealm("ManagementRealm", (realm) -> {
                                realm.inMemoryAuthentication((authn) -> {
                                    authn.add(new Properties() {{
                                        put("bob", "9b511b00aa7f2265621e38d2cf665f2f");
                                    }});
                                });
                                realm.inMemoryAuthorization();
                            })
            );
}
 
Example #7
Source File: RuntimeServer.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
private void configureFractionsFromXML(Container container, List<ModelNode> operationList) throws Exception {

    StandaloneXmlParser parser = new StandaloneXmlParser();

    FractionProcessor<StandaloneXmlParser> consumer = (p, cfg, fraction) -> {
        try {
            if (cfg.getSubsystemParsers().isPresent()) {
                Map<QName, XMLElementReader<List<ModelNode>>> fractionParsers =
                        (Map<QName, XMLElementReader<List<ModelNode>>>) cfg.getSubsystemParsers().get();

                fractionParsers.forEach(p::addDelegate);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    };

    // collect parsers
    visitFractions(container, parser, consumer);

    // parse the configurations
    List<ModelNode> parseResult = parser.parse(xmlConfig.get());
    operationList.addAll(parseResult);

}
 
Example #8
Source File: JPAFraction.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
@Override
public void initialize(Container.InitContext initContext) {
    if (!inhibitDefaultDatasource) {
        final DatasourcesFraction datasources = new DatasourcesFraction()
                .jdbcDriver("h2", (d) -> {
                    d.driverClassName("org.h2.Driver");
                    d.xaDatasourceClass("org.h2.jdbcx.JdbcDataSource");
                    d.driverModuleName("com.h2database.h2");
                })
                .dataSource("ExampleDS", (ds) -> {
                    ds.driverName("h2");
                    ds.connectionUrl("jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE");
                    ds.userName("sa");
                    ds.password("sa");
                });

        initContext.fraction(datasources);
        System.err.println("setting default Datasource to ExampleDS");
        defaultDatasource("jboss/datasources/ExampleDS");
    }
}
 
Example #9
Source File: RuntimeServer.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
/**
 * Wraps common iteration pattern over fraction and server configurations
 *
 * @param container
 * @param context   processing context (i.e. accumulator)
 * @param fn        a {@link org.wildfly.swarm.container.runtime.RuntimeServer.FractionProcessor} instance
 */
private <T> void visitFractions(Container container, T context, FractionProcessor<T> fn) {
    OUTER:
    for (ServerConfiguration eachConfig : this.configList) {
        boolean found = false;
        INNER:
        for (Fraction eachFraction : container.fractions()) {
            if (eachConfig.getType().isAssignableFrom(eachFraction.getClass())) {
                found = true;
                fn.accept(context, eachConfig, eachFraction);
                break INNER;
            }
        }
        if (!found && !eachConfig.isIgnorable()) {
            System.err.println("*** unable to find fraction for: " + eachConfig.getType());
        }

    }
}
 
Example #10
Source File: EJBFraction.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
@Override
public void postInitialize(Container.PostInitContext initContext) {
    SecurityFraction security = (SecurityFraction) initContext.fraction("security");

    if (security != null) {
        SecurityDomain ejbPolicy = security.subresources().securityDomains().stream().filter((e) -> e.getKey().equals("jboss-ejb-policy")).findFirst().orElse(null);
        if (ejbPolicy == null) {
            ejbPolicy = new SecurityDomain("jboss-ejb-policy")
                    .classicAuthorization(new ClassicAuthorization()
                            .policyModule(new PolicyModule("default")
                                    .code("Delegating")
                                    .flag(Flag.REQUIRED)));
            security.securityDomain(ejbPolicy);
        }
    }
}
 
Example #11
Source File: RuntimeServer.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
private void configureInterfaces(Container config, List<ModelNode> list) {
    List<Interface> ifaces = config.ifaces();

    for (Interface each : ifaces) {
        configureInterface(each, list);
    }
}
 
Example #12
Source File: LogstashFraction.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Container.InitContext initContext) {
    final CustomHandler<?> logstashHandler = new CustomHandler<>("logstash-handler")
            .module("org.jboss.logmanager.ext")
            .attributeClass("org.jboss.logmanager.ext.handlers.SocketHandler")
            .namedFormatter("logstash")
            .properties(handlerProperties);
    initContext.fraction(new LoggingFraction()
            .customFormatter("logstash", "org.jboss.logmanager.ext", "org.jboss.logmanager.ext.formatters.LogstashFormatter", this.formatterProperties)
            .customHandler(logstashHandler)
            .rootLogger(this.level, logstashHandler.getKey()));
}
 
Example #13
Source File: StaticContentDeploymentTest.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Test
public void testStaticContent() throws Exception {
    Container container = newContainer();
    container.start();
    try {
        WARArchive deployment = ShrinkWrap.create(WARArchive.class);
        deployment.staticContent();
        container.deploy(deployment);
        assertBasicStaticContentWorks("");
        assertFileChangesReflected("");
    } finally {
        container.stop();
    }
}
 
Example #14
Source File: HawkularServerFraction.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void postInitialize(Container.PostInitContext initContext) {
    SecurityFraction security = (SecurityFraction) initContext.fraction("security");

    security.securityDomain("keycloak", (domain) -> {
        domain.classicAuthentication((auth) -> {
            auth.loginModule("default", (login) -> {
                login.code("org.keycloak.adapters.jboss.KeycloakLoginModule");
                login.flag(Flag.REQUIRED);
            });
        });
    });

}
 
Example #15
Source File: App.java    From drools-workshop with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    Container container = new Container();

    container.start();

    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);
    deployment.setContextRoot("/cep");
    deployment.addResource(TransactionEventService.class);
    deployment.addResource(TransactionEventServiceImpl.class);
    deployment.addClass(HttpStatusExceptionHandler.class);
    deployment.addClass(BusinessException.class);
    deployment.addAllDependencies();
    container.deploy(deployment);
}
 
Example #16
Source File: TopologyInVmTest.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Test
@Ignore
public void testCanFindKubePing() throws Exception {
    // TODO: We can't easily test KubePing without a server to hit
    System.setProperty(SwarmProperties.ENVIRONMENT, "openshift");
    Container container = new Container();
    container.start();
    // TODO: something useful here to verify we're actually using KubePing
    container.stop();
    System.setProperty(SwarmProperties.ENVIRONMENT, "");
}
 
Example #17
Source File: Main.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
public static void main(String... args) throws Exception {
    Container container = new Container();
    SwaggerWebAppFraction fraction = new SwaggerWebAppFraction();
    fraction.addWebContent(System.getProperty("swarm.swagger.ui.resources"));
    container.fraction(fraction);
    container.start();
}
 
Example #18
Source File: RuntimeServer.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
private void getList(Container config, List<ModelNode> list) throws Exception {

        if (xmlConfig.isPresent()) {
            configureFractionsFromXML(config, list);
        } else {
            configureInterfaces(config, list);
            configureSocketBindingGroups(config, list);
            configureFractions(config, list);
        }
    }
 
Example #19
Source File: RuntimeServer.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
private void configureFractions(Container config, List<ModelNode> list) throws Exception {
    for (ServerConfiguration<Fraction> eachConfig : this.configList) {
        boolean found = false;
        for (Fraction eachFraction : config.fractions()) {
            if (eachConfig.getType().isAssignableFrom(eachFraction.getClass())) {
                found = true;
                list.addAll(eachConfig.getList(eachFraction));
                break;
            }
        }
        if (!found && !eachConfig.isIgnorable()) {
            System.err.println("*** unable to find fraction for: " + eachConfig.getType());
        }
    }
}
 
Example #20
Source File: Main.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
public static void main(String...args) throws Exception
{
    Container container = new Container();
    container.start();

    // WARArchive archive = ShrinkWrap.create(WARArchive.class);
    // archive.addClass(...)

    // container.deploy( archive );
}
 
Example #21
Source File: InfinispanFraction.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void postInitialize(Container.PostInitContext initContext) {
    if (this.defaultFraction) {
        if (initContext.hasFraction("jgroups")) {
            clusteredDefaultFraction(initContext);
        } else {
            localDefaultFraction(initContext);
        }
    }
}
 
Example #22
Source File: HawkularArquillianTest.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public Container newContainer(String... args) throws Exception {
    return new Container().fraction(HawkularFraction.createDefaultHawkularFraction()
            .port(9090)
            .username("hawkular")
            .password("Hawkular1!"));
}
 
Example #23
Source File: EJBRemoteFraction.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Container.InitContext initContext) {
    initContext.fraction(
            createDefaultFraction()
                    .remoteService(
                            new RemoteService()
                                    .connectorRef("http-remoting-connector")
                                    .threadPoolName("default")
                    )
    );
}
 
Example #24
Source File: RuntimeServer.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
private void getExtensions(Container container, List<ModelNode> list) throws Exception {

        FractionProcessor<List<ModelNode>> consumer = (context, cfg, fraction) -> {
            try {
                Optional<ModelNode> extension = cfg.getExtension();
                extension.map(modelNode -> list.add(modelNode));
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        };

        visitFractions(container, list, consumer);

    }
 
Example #25
Source File: TransactionsFraction.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Container.InitContext initContext) {

    initContext.socketBinding(new SocketBinding("txn-recovery-environment")
            .port(this.port));

    initContext.socketBinding(new SocketBinding("txn-status-manager")
            .port(this.statusPort));
}
 
Example #26
Source File: BatchInVmTest.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimple() throws Exception {
    Container container = new Container()
            .fraction(BatchFraction.createDefaultFraction());

    try {
        container.start().deploy(Deployments.createDefaultDeployment().addClass(StartBatchJob.class));
        // There's not much that can be tested here, a failure to start/deploy is enough for this
    } finally {
        container.stop();
    }
}
 
Example #27
Source File: MailFraction.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void postInitialize(Container.PostInitContext initContext) {
    for (MailSession session : subresources().mailSessions()) {
        SMTPServer server = session.subresources().smtpServer();
        if (server != null && server instanceof EnhancedSMTPServer) {
            OutboundSocketBinding socketBinding = ((EnhancedSMTPServer) server).outboundSocketBinding();
            if (socketBinding != null) {
                initContext.outboundSocketBinding(socketBinding);
            }
        }
    }
}
 
Example #28
Source File: JGroupsFraction.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void initialize(Container.InitContext initContext) {
    initContext.socketBinding(
            new SocketBinding("jgroups-udp")
                    .port(55200)
                    .multicastAddress(SwarmProperties.propertyVar(JGroupsProperties.DEFAULT_MULTICAST_ADDRESS,
                            "230.0.0.4"))
                    .multicastPort(45688));

    initContext.socketBinding(
            new SocketBinding("jgroups-udp-fd")
                    .port(54200));

    initContext.socketBinding(
            new SocketBinding("jgroups-mping")
                    .port(0)
                    .multicastAddress(SwarmProperties.propertyVar(JGroupsProperties.DEFAULT_MULTICAST_ADDRESS,
                            "230.0.0.4"))
                    .multicastPort(45700));

    initContext.socketBinding(
            new SocketBinding("jgroups-tcp")
                    .port(7600));

    initContext.socketBinding(
            new SocketBinding("jgroups-tcp-fd")
                    .port(57600));

}
 
Example #29
Source File: UndertowArquillianTest.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 4 votes vote down vote up
@Override
public Container newContainer(String... args) throws Exception {
    return new Container().fraction(new UndertowFraction());
}
 
Example #30
Source File: MailArquillianTest.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 4 votes vote down vote up
@Override
public Container newContainer(String... args) throws Exception {
    return new Container().fraction(MailFraction.defaultFraction());
}