org.wildfly.swarm.topology.TopologyArchive Java Examples

The following examples show how to use org.wildfly.swarm.topology.TopologyArchive. 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: TopologyWebAppDeploymentProducer.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Produces
@Dependent()
Archive deployment() {

    String context = TopologyWebAppFraction.DEFAULT_CONTEXT;
    if (this.contextPath != null) {
        context = this.contextPath;
    }

    if (fraction.exposeTopologyEndpoint()) {
        WARArchive war = ShrinkWrap.create(WARArchive.class, "topology-webapp.war");
        war.addAsWebInfResource(new StringAsset(getWebXml(fraction)), "web.xml");
        war.addClass(TopologySSEServlet.class);
        war.addModule("thorntail.application");
        war.addModule("org.wildfly.swarm.topology");
        war.addAsWebResource(new ClassLoaderAsset("topology.js", this.getClass().getClassLoader()), "topology.js");
        war.setContextRoot(context);
        war.as(TopologyArchive.class);
        return war;
    }
    return null;
}
 
Example #2
Source File: RegistrationAdvertiserActivator.java    From thorntail with Apache License 2.0 6 votes vote down vote up
@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {

    ServiceTarget target = context.getServiceTarget();


    forEachLine(TopologyArchive.REGISTRATION_CONF, registrationLine -> {
        int separatorIndex = registrationLine.indexOf(TopologyArchive.SERVICE_TAG_SEPARATOR);
        String serviceName = registrationLine;
        List<String> tags = Collections.emptyList();
        if (separatorIndex > 0) {
            serviceName = registrationLine.substring(0, separatorIndex);
            tags = getTags(registrationLine.substring(separatorIndex + 1));
        }
        RegistrationAdvertiser.install(target, serviceName, "http", tags);
        RegistrationAdvertiser.install(target, serviceName, "https", tags);
    });
}
 
Example #3
Source File: TopologyArchiveImpl.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
protected TopologyArchive doAdvertise() {
    if (!as(ServiceActivatorArchive.class).containsServiceActivator(SERVICE_ACTIVATOR_CLASS_NAME)) {
        as(ServiceActivatorArchive.class).addServiceActivator(SERVICE_ACTIVATOR_CLASS_NAME);
        as(JARArchive.class).addModule("org.wildfly.swarm.topology", "runtime");
    }

    StringBuffer buf = new StringBuffer();

    List<String> names = getServiceNames();
    for (String name : names) {
        buf.append(name).append("\n");
    }

    as(JARArchive.class).add(new StringAsset(buf.toString()), REGISTRATION_CONF);
    return this;
}
 
Example #4
Source File: TopologyWebAppConfiguration.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 6 votes vote down vote up
@Override
public List<Archive> getImplicitDeployments(TopologyWebAppFraction fraction) throws Exception {
    String context = System.getProperty(TopologyProperties.CONTEXT_PATH);
    if (context == null) context = DEFAULT_CONTEXT;

    List<Archive> list = new ArrayList<>();
    WARArchive war = ShrinkWrap.create(WARArchive.class, "topology-webapp.war");
    war.addAsWebInfResource(new StringAsset(getWebXml(fraction)), "web.xml");
    war.addClass(TopologySSEServlet.class);
    war.addModule("swarm.application");
    war.addModule("org.wildfly.swarm.topology");
    war.addAsWebResource(new ClassLoaderAsset("topology.js", this.getClass().getClassLoader()), "topology.js");
    war.setContextRoot(context);
    war.as(TopologyArchive.class);
    list.add(war);
    return list;
}
 
Example #5
Source File: TopologyArchiveImpl.java    From thorntail with Apache License 2.0 6 votes vote down vote up
protected TopologyArchive doAdvertise() {
    if (!as(ServiceActivatorArchive.class).containsServiceActivator(SERVICE_ACTIVATOR_CLASS_NAME)) {
        as(ServiceActivatorArchive.class).addServiceActivator(SERVICE_ACTIVATOR_CLASS_NAME);
        //as(JARArchive.class).addModule("org.wildfly.swarm.topology", "deployment");
    }

    StringBuilder registrationConf = new StringBuilder();

    List<String> names = getServiceNames();
    for (String name : names) {
        Collection<String> tags = tagsByService.getOrDefault(name, Collections.emptyList());
        registrationConf.append(name);
        if (!tags.isEmpty()) {
            registrationConf.append(" ")
                    .append(
                            tags.stream().collect(Collectors.joining(TAG_SEPARATOR))
                    );
        }
        registrationConf.append("\n");
    }

    as(JARArchive.class).add(new StringAsset(registrationConf.toString()), REGISTRATION_CONF);
    return this;
}
 
Example #6
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("foodService");
    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 #7
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 #8
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 #9
Source File: RegistrationAdvertiserActivator.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public void activate(ServiceActivatorContext context) throws ServiceRegistryException {

    ServiceTarget target = context.getServiceTarget();

    InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(TopologyArchive.REGISTRATION_CONF);

    if (in == null) {
        return;
    }

    try (BufferedReader reader = new BufferedReader(new InputStreamReader(in))) {

        String serviceName = null;

        while ((serviceName = reader.readLine()) != null) {
            serviceName = serviceName.trim();
            if (!serviceName.isEmpty()) {
                installAdvertiser( target, serviceName, "http" );
                installAdvertiser( target, serviceName, "https" );
            }
        }

    } catch (IOException e) {
        throw new ServiceRegistryException(e);
    }
}
 
Example #10
Source File: AdvertiseAndTagByMainTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Deployment(testable = false)
public static Archive<?> createDeployment() throws Exception {
    JAXRSArchive deployment = ShrinkWrap.create(JAXRSArchive.class);
    deployment.add(EmptyAsset.INSTANCE, "nothing");
    deployment.as(TopologyArchive.class).advertise(serviceName, asList(tag1, tag2));
    deployment.addAllDependencies();

    return deployment;
}
 
Example #11
Source File: TopologyArchiveImpl.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Override
public TopologyArchive advertise(String... serviceNames) {
    for (String serviceName : serviceNames) {
        this.serviceNames.add(serviceName);
    }

    return advertise();
}
 
Example #12
Source File: AdvertisingMetadataProcessorTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithRepeatingAnnotation() throws IOException {
    JARArchive archive = ShrinkWrap.create(JARArchive.class);

    archive.addClass(MyRepeatingClass.class);

    AdvertisingMetadataProcessor processor = new AdvertisingMetadataProcessor(archive, createIndex(archive));
    processor.process();

    List<String> advertisements = archive.as(TopologyArchive.class).advertisements();

    assertThat(advertisements).hasSize(2);
    assertThat(advertisements).contains("cheddar");
    assertThat(advertisements).contains("gouda");
}
 
Example #13
Source File: AdvertisingMetadataProcessorTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Test
public void testWithSingleAnnotation() throws IOException {
    JARArchive archive = ShrinkWrap.create(JARArchive.class);

    archive.addClass(MyClass.class);

    AdvertisingMetadataProcessor processor = new AdvertisingMetadataProcessor(archive, createIndex(archive));
    processor.process();

    List<String> advertisements = archive.as(TopologyArchive.class).advertisements();

    assertThat(advertisements).hasSize(1);
    assertThat(advertisements).contains("foo");
}
 
Example #14
Source File: AdvertisingMetadataProcessorTest.java    From thorntail with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoAnnotations() throws IOException {
    JARArchive archive = ShrinkWrap.create(JARArchive.class);

    AdvertisingMetadataProcessor processor = new AdvertisingMetadataProcessor(archive, createIndex(archive));
    processor.process();

    List<String> advertisements = archive.as(TopologyArchive.class).advertisements();

    assertThat(advertisements).isEmpty();
}
 
Example #15
Source File: AdvertisingMetadataProcessor.java    From thorntail with Apache License 2.0 5 votes vote down vote up
private void advertise(Archive<?> archive, AnnotationInstance anno) {

        String serviceName = anno.value().asString();
        List<String> tags = Optional.ofNullable(anno.value(Advertise.TAGS_ATTRIBUTE_NAME))
                .map(AnnotationValue::asStringArray)
                .map(Arrays::asList)
                .orElse(Collections.emptyList());
        TopologyArchive topologyArchive = archive.as(TopologyArchive.class);
        topologyArchive.advertise(serviceName, tags);
    }
 
Example #16
Source File: TopologyArchiveImpl.java    From thorntail with Apache License 2.0 4 votes vote down vote up
@Override
public TopologyArchive advertise(String serviceName, Collection<String> tags) {
    tagsByService.put(serviceName, tags);
    return doAdvertise();
}
 
Example #17
Source File: TopologyArchiveImpl.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 4 votes vote down vote up
@Override
public TopologyArchive advertise() {
    doAdvertise();
    return this;
}
 
Example #18
Source File: TopologyArchiveImpl.java    From thorntail with Apache License 2.0 4 votes vote down vote up
@Override
public TopologyArchive advertise(String serviceName) {
    return advertise(serviceName, Collections.emptyList());
}
 
Example #19
Source File: TopologyArchiveImpl.java    From thorntail with Apache License 2.0 4 votes vote down vote up
@Override
public TopologyArchive advertise() {
    return doAdvertise();
}
 
Example #20
Source File: RegistrationAdvertiserActivator.java    From thorntail with Apache License 2.0 4 votes vote down vote up
private List<String> getTags(String tagsAsString) {
    return Stream.of(tagsAsString.split(TopologyArchive.TAG_SEPARATOR))
            .map(String::trim)
            .collect(Collectors.toList());
}