├── .gitignore ├── .travis.yml ├── FAQ.adoc ├── LICENSE ├── README.adoc ├── pom.xml ├── service-consumption.adoc ├── service-discovery.adoc ├── service-registration.adoc ├── snoop-boot └── README.adoc ├── snoop-client ├── pom.xml └── src │ └── main │ └── java │ └── eu │ └── agilejava │ └── snoop │ ├── SnoopConfigurationException.java │ ├── annotation │ ├── Snoop.java │ └── package-info.java │ ├── client │ ├── SnoopConfig.java │ ├── SnoopProducer.java │ ├── SnoopServiceClient.java │ ├── SnoopServiceUnavailableException.java │ └── package-info.java │ └── package-info.java ├── snoop-eureka ├── README.adoc ├── pom.xml └── src │ └── main │ ├── java │ └── eu │ │ └── agilejava │ │ └── snoop │ │ └── eureka │ │ ├── annotation │ │ └── EnableEurekaClient.java │ │ ├── package-info.java │ │ └── scan │ │ ├── EurekaClient.java │ │ ├── EurekaConfig.java │ │ ├── InstanceConfig.java │ │ ├── SnoopEurekaExtensionHelper.java │ │ └── SnoopEurekaScannerExtension.java │ └── resources │ └── META-INF │ └── services │ └── javax.enterprise.inject.spi.Extension ├── snoop-service.adoc ├── snoop-service ├── README.adoc ├── loglevels.sh ├── pom.xml └── src │ └── main │ ├── glassfish │ ├── custom-logger-0.5.jar │ └── logging.properties │ ├── java │ └── eu │ │ └── agilejava │ │ └── snoop │ │ ├── SnoopClientRegistry.java │ │ ├── SnoopConfig.java │ │ ├── SnoopEndpoint.java │ │ ├── SnoopService.java │ │ ├── SnoopStatusEndpoint.java │ │ ├── api │ │ └── ServicesResource.java │ │ ├── config │ │ └── ApplicatonConfig.java │ │ ├── package-info.java │ │ └── ui │ │ └── SnoopController.java │ ├── webapp │ ├── WEB-INF │ │ ├── glassfish-web.xml │ │ ├── jboss-web.xml │ │ ├── template.xhtml │ │ └── web.xml │ ├── resources │ │ └── css │ │ │ ├── cssLayout.css │ │ │ └── default.css │ └── services.xhtml │ └── wildfly │ └── standalone-snoop.xml ├── snoop-swarm └── pom.xml └── snoop ├── pom.xml └── src └── main ├── java └── eu │ └── agilejava │ └── snoop │ ├── annotation │ ├── EnableSnoopClient.java │ └── package-info.java │ ├── package-info.java │ └── scan │ ├── SnoopExtensionHelper.java │ ├── SnoopRegistrationClient.java │ ├── SnoopScannerExtension.java │ └── package-info.java └── resources └── META-INF ├── beans.xml └── services └── javax.enterprise.inject.spi.Extension /.gitignore: -------------------------------------------------------------------------------- 1 | target/ 2 | pom.xml.tag 3 | pom.xml.releaseBackup 4 | pom.xml.versionsBackup 5 | pom.xml.next 6 | release.properties 7 | nbactions.xml 8 | nb-configuration.xml 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: java 2 | jdk: oraclejdk8 3 | -------------------------------------------------------------------------------- /FAQ.adoc: -------------------------------------------------------------------------------- 1 | = Frequently Asked Questions about Snoop 2 | 3 | ## Is Snoop a Load Balancer? 4 | *No*, the intention of Snoop is to provide a service registration and lookup 5 | mechanism. If you are running multiple instances of a microservice, this should 6 | be load balanced using any load balancer tool and it is the _load balancer's IP/hostname_ 7 | that is registered with snoop using the Snoop configuration parameters. 8 | 9 | _[todo] example_ 10 | 11 | 12 | link:README.adoc[[home\]] 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Ivar Grimstad 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | = SnoopEE - A Discovery Service for Java EE 2 | 3 | SnoopEE [ˈsnuːpı] is an experimental registration and discovery service for Java EE based microservices. 4 | 5 | SnoopEE 2.x has a new repo location. Go to the link:https://github.com/ivargrimstad/snoopee[new SnoopEE GitHub Repo] 6 | 7 | == Getting Started 8 | 9 | . Start the link:snoop-service.adoc[Snoop Service] 10 | . link:service-registration.adoc[Service Registration] 11 | . link:service-discovery.adoc[Service Discovery] 12 | 13 | == Maven 14 | 15 | . Released artifacts are available in link:http://search.maven.org/#search%7Cga%7C1%7Csnoop[Maven Central] 16 | . Snapshots configuration: 17 | 18 | 19 | 20 | agilejava-snapshots 21 | http://nexus.agilejava.eu/content/groups/public 22 | 23 | true 24 | 25 | 26 | 27 | 28 | == Examples 29 | 30 | - link:https://github.com/ivargrimstad/snoop-samples[snoop-samples@GitHub] 31 | - link:https://github.com/arun-gupta/microservices[https://github.com/arun-gupta/microservices] 32 | 33 | == FAQ 34 | 35 | - link:FAQ.adoc[Frequently Asked Questions] 36 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | eu.agilejava 5 | snoop-root 6 | 1.3.5-SNAPSHOT 7 | pom 8 | 9 | SnoopEE Root 10 | SnoopEE - A Discovery Service for Java EE 11 | https://github.com/ivargrimstad/snoop 12 | 13 | 14 | 15 | MIT License 16 | http://www.opensource.org/licenses/mit-license.php 17 | 18 | 19 | 20 | 21 | 22 | Ivar Grimstad 23 | ivar.grimstad@gmail.com 24 | AgileJava 25 | http://www.agilejava.eu 26 | 27 | 28 | 29 | 30 | UTF-8 31 | 1.8 32 | 1.8 33 | mit 34 | 0.4.9 35 | 36 | 37 | 38 | snoop 39 | snoop-client 40 | snoop-service 41 | snoop-swarm 42 | 43 | 44 | 45 | 46 | 47 | javax 48 | javaee-web-api 49 | 7.0 50 | provided 51 | 52 | 53 | 54 | 55 | 56 | 57 | ossrh 58 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 59 | 60 | 61 | ossrh 62 | https://oss.sonatype.org/content/repositories/snapshots 63 | 64 | 65 | 66 | 67 | scm:git:ssh://git@bitbucket.org:ivargrimstad/snoop.git 68 | scm:git:ssh://git@bitbucket.org:ivargrimstad/snoop.git 69 | git@bitbucket.org:ivargrimstad/snoop.git 70 | HEAD 71 | 72 | 73 | 74 | 75 | 76 | org.jacoco 77 | jacoco-maven-plugin 78 | 0.7.5.201505241946 79 | 80 | 81 | 82 | report 83 | 84 | report 85 | 86 | 87 | 88 | 89 | org.sonatype.plugins 90 | nexus-staging-maven-plugin 91 | 1.6.3 92 | true 93 | 94 | ossrh 95 | https://oss.sonatype.org/ 96 | true 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | release 105 | 106 | 107 | 108 | org.apache.maven.plugins 109 | maven-source-plugin 110 | 2.2.1 111 | 112 | 113 | attach-sources 114 | 115 | jar-no-fork 116 | 117 | 118 | 119 | 120 | 121 | org.apache.maven.plugins 122 | maven-javadoc-plugin 123 | 2.9.1 124 | 125 | 126 | attach-javadocs 127 | 128 | jar 129 | 130 | 131 | 132 | 133 | 134 | org.apache.maven.plugins 135 | maven-gpg-plugin 136 | 1.5 137 | 138 | 139 | sign-artifacts 140 | verify 141 | 142 | sign 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | -------------------------------------------------------------------------------- /service-consumption.adoc: -------------------------------------------------------------------------------- 1 | == Consuming a Snoop Service 2 | 3 | . link:service-discovery.adoc[Discover the Service] 4 | 5 | . Call the service 6 | .. Use the Client API. 7 | + 8 | [source,java] 9 | String helloResponse = helloService.simpleGet("hello") 10 | .filter(r -> r.getStatus() == 200) 11 | .map(r -> r.readEntity(String.class)) 12 | .orElse("goodbye"); 13 | 14 | .. Or use `WebTarget` directly. 15 | + 16 | [source,java] 17 | try { 18 | WebTarget endpoint = helloService.getServiceRoot(); 19 | ... 20 | } catch(SnoopServiceUnavailableException e) { 21 | ... 22 | } 23 | 24 | link:README.adoc[[home\]] 25 | -------------------------------------------------------------------------------- /service-discovery.adoc: -------------------------------------------------------------------------------- 1 | == Service Discovery 2 | 3 | . Maven Dependency 4 | 5 | 6 | eu.agilejava 7 | snoop-client 8 | ${snoop.version}/version> 9 | 10 | 11 | . Configure the client 12 | .. Using `snoop.yml` 13 | 14 | snoop: 15 | snoopService: 192.168.59.103:8081/snoop-service/ 16 | 17 | .. Or by environment variable 18 | 19 | docker run -it -p 8080:8080 -e "snoopService=192.168.59.103:8081/snoop-service/" ivargrimstad/snoop-helloworld:1.0.0-SNAPSHOT 20 | 21 | .. Or by system property 22 | 23 | -DsnoopService=192.168.59.103:8081/snoop-service/ 24 | 25 | . To discover a service, use the @Snoop qualifier to inject a client to the registered service. 26 | + 27 | [source,java] 28 | @Inject 29 | @Snoop(serviceName = "hello") 30 | private SnoopDiscoveryClient helloService; 31 | 32 | . link:service-consumption.adoc[Consume the Service] 33 | 34 | link:README.adoc[[home\]] 35 | -------------------------------------------------------------------------------- /service-registration.adoc: -------------------------------------------------------------------------------- 1 | == Service Registration 2 | 3 | . Maven Dependency 4 | 5 | 6 | eu.agilejava 7 | snoop 8 | ${snoop.version} 9 | 10 | 11 | . Enable Snoop 12 | + 13 | [source,java] 14 | @EnableSnoopClient(serviceName="myservice") 15 | @ApplicationPath("api") 16 | public class ApplicationConfig extends Application { 17 | ... 18 | } 19 | 20 | . Configure the service 21 | .. Use `snoop.yml` 22 | 23 | snoop: 24 | host: http://localhost 25 | port: 8080 26 | serviceRoot: snoop-hello-service/api 27 | snoopService: 192.168.59.103:8081/snoop-service/ 28 | 29 | .. Or by environment variables (remember prefix with service name) 30 | 31 | docker run -it -p 8080:8080 -e "hello.host=http://192.168.59.103" -e "hello.port=8080" -e "hello.serviceRoot=snoop-hello-service/api" -e "hello.snoopService=192.168.59.103:8081/snoop-service/" ivargrimstad/snoop-hello 32 | 33 | .. Or by system property 34 | 35 | -Dhost=http://192.168.59.103 -Dport=8080 -DserviceRoot=snoop-hello-service/api -DsnoopService: 192.168.59.103:8081/snoop-service/ 36 | 37 | link:README.adoc[[home\]] 38 | -------------------------------------------------------------------------------- /snoop-boot/README.adoc: -------------------------------------------------------------------------------- 1 | = Snoop Boot 2 | 3 | Snoop support for Spring Boot applications. 4 | -------------------------------------------------------------------------------- /snoop-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | eu.agilejava 5 | snoop-client 6 | 1.3.5-SNAPSHOT 7 | jar 8 | 9 | SnoopEE Client 10 | SnoopEE Discovery Client 11 | 12 | 13 | eu.agilejava 14 | snoop-root 15 | 1.3.5-SNAPSHOT 16 | 17 | 18 | 19 | 20 | 21 | com.fasterxml.jackson.dataformat 22 | jackson-dataformat-yaml 23 | 2.5.1 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /snoop-client/src/main/java/eu/agilejava/snoop/SnoopConfigurationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop; 25 | 26 | import javax.ejb.ApplicationException; 27 | 28 | /** 29 | * This exception indicates that the Snoop configuration is erroneous. 30 | * 31 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 32 | */ 33 | @ApplicationException 34 | public class SnoopConfigurationException extends RuntimeException { 35 | 36 | public SnoopConfigurationException() { 37 | } 38 | 39 | public SnoopConfigurationException(String message) { 40 | super(message); 41 | } 42 | 43 | public SnoopConfigurationException(String message, Throwable cause) { 44 | super(message, cause); 45 | } 46 | 47 | public SnoopConfigurationException(Throwable cause) { 48 | super(cause); 49 | } 50 | 51 | public SnoopConfigurationException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 52 | super(message, cause, enableSuppression, writableStackTrace); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /snoop-client/src/main/java/eu/agilejava/snoop/annotation/Snoop.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop.annotation; 25 | 26 | import java.lang.annotation.Documented; 27 | import static java.lang.annotation.ElementType.FIELD; 28 | import static java.lang.annotation.ElementType.METHOD; 29 | import java.lang.annotation.Retention; 30 | import java.lang.annotation.Target; 31 | 32 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 33 | import javax.enterprise.util.Nonbinding; 34 | import javax.inject.Qualifier; 35 | 36 | /** 37 | * Annotation for looking up a service registered with Snoop. 38 | * 39 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 40 | */ 41 | @Qualifier 42 | @Retention(RUNTIME) 43 | @Documented 44 | @Target({FIELD, METHOD}) 45 | public @interface Snoop { 46 | 47 | /** 48 | * The name of the service. 49 | * 50 | * @return The service name 51 | */ 52 | @Nonbinding 53 | String serviceName() default ""; 54 | } 55 | -------------------------------------------------------------------------------- /snoop-client/src/main/java/eu/agilejava/snoop/annotation/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop.annotation; 25 | -------------------------------------------------------------------------------- /snoop-client/src/main/java/eu/agilejava/snoop/client/SnoopConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop.client; 25 | 26 | import java.io.StringReader; 27 | import java.io.StringWriter; 28 | import java.io.Writer; 29 | import javax.json.Json; 30 | import javax.json.JsonObject; 31 | import javax.json.JsonReader; 32 | import javax.json.stream.JsonGenerator; 33 | 34 | /** 35 | * Holds the meta data for the registered service. 36 | * 37 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 38 | */ 39 | public class SnoopConfig { 40 | 41 | private String serviceName; 42 | private String serviceHome; 43 | private String serviceRoot; 44 | 45 | public String getServiceName() { 46 | return serviceName; 47 | } 48 | 49 | public void setServiceName(String serviceName) { 50 | this.serviceName = serviceName; 51 | } 52 | 53 | public String getServiceHome() { 54 | return serviceHome; 55 | } 56 | 57 | public void setServiceHome(String serviceHome) { 58 | this.serviceHome = serviceHome; 59 | } 60 | 61 | public String getServiceRoot() { 62 | return serviceRoot; 63 | } 64 | 65 | public void setServiceRoot(String serviceRoot) { 66 | this.serviceRoot = serviceRoot; 67 | } 68 | 69 | public String toJSON() { 70 | 71 | Writer w = new StringWriter(); 72 | try (JsonGenerator generator = Json.createGenerator(w)) { 73 | 74 | generator.writeStartObject() 75 | .write("serviceName", serviceName) 76 | .write("serviceHome", serviceHome) 77 | .write("serviceRoot", serviceRoot) 78 | .writeEnd(); 79 | } 80 | 81 | return w.toString(); 82 | } 83 | 84 | public static SnoopConfig fromJSON(String json) { 85 | 86 | SnoopConfig config = new SnoopConfig(); 87 | 88 | try (JsonReader reader = Json.createReader(new StringReader(json))) { 89 | 90 | JsonObject configJson = reader.readObject(); 91 | 92 | config.setServiceName(configJson.getString("serviceName")); 93 | config.setServiceHome(configJson.getString("serviceHome")); 94 | config.setServiceRoot(configJson.getString("serviceRoot")); 95 | } 96 | 97 | return config; 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /snoop-client/src/main/java/eu/agilejava/snoop/client/SnoopProducer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop.client; 25 | 26 | import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml; 27 | import com.fasterxml.jackson.dataformat.yaml.snakeyaml.error.YAMLException; 28 | import eu.agilejava.snoop.SnoopConfigurationException; 29 | import eu.agilejava.snoop.annotation.Snoop; 30 | import java.util.Collections; 31 | import java.util.Map; 32 | import java.util.Optional; 33 | import java.util.logging.Logger; 34 | import javax.annotation.PostConstruct; 35 | import javax.enterprise.context.ApplicationScoped; 36 | import javax.enterprise.context.Dependent; 37 | import javax.enterprise.inject.Produces; 38 | import javax.enterprise.inject.spi.InjectionPoint; 39 | 40 | /** 41 | * CDI Producer for SnoopServiceClient. 42 | * 43 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 44 | */ 45 | @ApplicationScoped 46 | public class SnoopProducer { 47 | 48 | private static final Logger LOGGER = Logger.getLogger("eu.agilejava.snoop"); 49 | 50 | private Map snoopConfig = Collections.EMPTY_MAP; 51 | 52 | /** 53 | * Creates a SnoopServiceClient for the named service. 54 | * 55 | * @param ip The injection point 56 | * @return a configured snoop service client 57 | */ 58 | @Snoop 59 | @Produces 60 | @Dependent 61 | public SnoopServiceClient lookup(InjectionPoint ip) { 62 | 63 | final String applicationName = ip.getAnnotated().getAnnotation(Snoop.class).serviceName(); 64 | 65 | LOGGER.config(() -> "producing " + applicationName); 66 | 67 | String serviceUrl = "http://" + readProperty("snoopService", snoopConfig); 68 | LOGGER.config(() -> "Service URL: " + serviceUrl); 69 | 70 | return new SnoopServiceClient.Builder(applicationName) 71 | .serviceUrl(serviceUrl) 72 | .build(); 73 | } 74 | 75 | private String readProperty(final String key, Map snoopConfig) { 76 | 77 | String property = Optional.ofNullable(System.getProperty(key)) 78 | .orElseGet(() -> { 79 | String envProp = Optional.ofNullable(System.getenv(key)) 80 | .orElseGet(() -> { 81 | String confProp = Optional.ofNullable(snoopConfig.get(key)) 82 | .orElseThrow(() -> { 83 | return new SnoopConfigurationException(key + " must be configured either in application.yml or as env or system property"); 84 | }) 85 | .toString(); 86 | return confProp; 87 | }); 88 | return envProp; 89 | }); 90 | 91 | return property; 92 | } 93 | 94 | /** 95 | * Initializes the producer with the Snoop configuration properties. 96 | */ 97 | @PostConstruct 98 | private void init() { 99 | 100 | try { 101 | Yaml yaml = new Yaml(); 102 | Map props = (Map) yaml.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("/snoop.yml")); 103 | 104 | snoopConfig = (Map) props.get("snoop"); 105 | 106 | } catch (YAMLException e) { 107 | LOGGER.config(() -> "No configuration file. Using env properties."); 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /snoop-client/src/main/java/eu/agilejava/snoop/client/SnoopServiceClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop.client; 25 | 26 | import java.util.Optional; 27 | import java.util.logging.Logger; 28 | import javax.ws.rs.ProcessingException; 29 | import javax.ws.rs.client.ClientBuilder; 30 | import javax.ws.rs.client.Entity; 31 | import javax.ws.rs.client.WebTarget; 32 | import static javax.ws.rs.core.MediaType.APPLICATION_JSON; 33 | import javax.ws.rs.core.Response; 34 | 35 | /** 36 | * Client API for calling services registered with Snoop. 37 | * 38 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 39 | */ 40 | public class SnoopServiceClient { 41 | 42 | private static final Logger LOGGER = Logger.getLogger("eu.agilejava.snoop"); 43 | private static final String DEFAULT_BASE_URI = "http://localhost:8080/snoop-service/"; 44 | 45 | private final String applicationName; 46 | private final String serviceUrl; 47 | 48 | static final class Builder { 49 | 50 | private final String applicationName; 51 | private String serviceUrl = DEFAULT_BASE_URI; 52 | 53 | Builder(final String applicationName) { 54 | this.applicationName = applicationName; 55 | } 56 | 57 | Builder serviceUrl(final String serviceUrl) { 58 | this.serviceUrl = serviceUrl; 59 | return this; 60 | } 61 | 62 | SnoopServiceClient build() { 63 | return new SnoopServiceClient(this); 64 | } 65 | } 66 | 67 | private SnoopServiceClient(final Builder builder) { 68 | this.applicationName = builder.applicationName; 69 | this.serviceUrl = builder.serviceUrl; 70 | LOGGER.info(() -> "client created for " + applicationName); 71 | } 72 | 73 | /** 74 | * Locator to get the service root for the service registered with Snoop. 75 | * 76 | * Use this method if the convenience methods simpleXXX are not sufficient or to avoid the extra call to Snoop for 77 | * every request. 78 | * 79 | * @return the serviceRoot 80 | * 81 | * @throws SnoopServiceUnavailableException if service is not available 82 | */ 83 | public WebTarget getServiceRoot() throws SnoopServiceUnavailableException { 84 | 85 | SnoopConfig snoopConfig = getConfigFromSnoop(); 86 | LOGGER.fine(() -> "looking up service for " + applicationName); 87 | 88 | return ClientBuilder.newClient() 89 | .target(snoopConfig.getServiceHome()) 90 | .path(snoopConfig.getServiceRoot()); 91 | } 92 | 93 | /** 94 | * Convenience method for making a simple GET request on a resource. 95 | * 96 | * Calling this method will result in a call to Snoop to retrieve the current configuration for the service in 97 | * addition to the actual GET request. 98 | * 99 | * @param resourcePath The relative path to the resource 100 | * @return an optional response that is empty if the service is unavailable. 101 | */ 102 | public Optional simpleGet(String resourcePath) { 103 | 104 | Optional returnValue = Optional.empty(); 105 | 106 | try { 107 | 108 | returnValue = Optional.of(getServiceRoot() 109 | .path(resourcePath) 110 | .request() 111 | .get()); 112 | 113 | } catch (SnoopServiceUnavailableException e) { 114 | LOGGER.warning(() -> "Service unavailable for " + applicationName); 115 | } 116 | 117 | return returnValue; 118 | } 119 | 120 | /** 121 | * Convenience method for making a simple DELETE request on a resource. 122 | * 123 | * Calling this method will result in a call to Snoop to retrieve the current configuration for the service in 124 | * addition to the actual DELETE request. 125 | * 126 | * @param resourcePath The relative path to the resource 127 | * @return an optional response that is empty if the service is unavailable. 128 | */ 129 | public Optional simpleDelete(String resourcePath) { 130 | 131 | Optional returnValue = Optional.empty(); 132 | 133 | try { 134 | 135 | returnValue = Optional.of(getServiceRoot() 136 | .path(resourcePath) 137 | .request() 138 | .delete()); 139 | 140 | } catch (SnoopServiceUnavailableException e) { 141 | LOGGER.warning(() -> "Service unavailable for " + applicationName); 142 | } 143 | 144 | return returnValue; 145 | } 146 | 147 | /** 148 | * Convenience method for making a simple PUT request on a resource. 149 | * 150 | * Calling this method will result in a call to Snoop to retrieve the current configuration for the service in 151 | * addition to the actual PUT request. 152 | * 153 | * @param resourcePath The relative path to the resource 154 | * @param resource The changes made to this resource 155 | * @return an optional response that is empty if the service is unavailable. 156 | */ 157 | public Optional simplePut(String resourcePath, Object resource) { 158 | 159 | Optional returnValue = Optional.empty(); 160 | 161 | try { 162 | 163 | returnValue = Optional.of(getServiceRoot() 164 | .path(resourcePath) 165 | .request() 166 | .put(Entity.entity(resource, APPLICATION_JSON))); 167 | 168 | } catch (SnoopServiceUnavailableException e) { 169 | LOGGER.warning(() -> "Service unavailable for " + applicationName); 170 | } 171 | 172 | return returnValue; 173 | } 174 | 175 | /** 176 | * Convenience method for making a simple POST request on a resource. 177 | * 178 | * Calling this method will result in a call to Snoop to retrieve the current configuration for the service in 179 | * addition to the actual POST request. 180 | * 181 | * @param resourcePath The relative path to the resource 182 | * @param resource The new resource 183 | * @return an optional response that is empty if the service is unavailable. 184 | */ 185 | public Optional simplePost(String resourcePath, Object resource) { 186 | 187 | Optional returnValue = Optional.empty(); 188 | 189 | try { 190 | 191 | returnValue = Optional.of(getServiceRoot() 192 | .path(resourcePath) 193 | .request() 194 | .post(Entity.entity(resource, APPLICATION_JSON))); 195 | 196 | } catch (SnoopServiceUnavailableException e) { 197 | LOGGER.warning(() -> "Service unavailable for " + applicationName); 198 | } 199 | 200 | return returnValue; 201 | } 202 | 203 | private SnoopConfig getConfigFromSnoop() throws SnoopServiceUnavailableException { 204 | 205 | try { 206 | Response response = ClientBuilder.newClient() 207 | .target(serviceUrl) 208 | .path("api") 209 | .path("services") 210 | .path(applicationName) 211 | .request(APPLICATION_JSON) 212 | .get(); 213 | 214 | if (response.getStatus() == 200) { 215 | return response.readEntity(SnoopConfig.class); 216 | } else { 217 | throw new SnoopServiceUnavailableException("Response from \"" + serviceUrl + "\"=" + response.getStatus()); 218 | } 219 | 220 | } catch (ProcessingException e) { 221 | throw new SnoopServiceUnavailableException(e); 222 | } 223 | } 224 | } 225 | -------------------------------------------------------------------------------- /snoop-client/src/main/java/eu/agilejava/snoop/client/SnoopServiceUnavailableException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop.client; 25 | 26 | import javax.ejb.ApplicationException; 27 | 28 | /** 29 | * This exception is thrown if the snoop service is not available. 30 | * 31 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 32 | */ 33 | @ApplicationException 34 | public class SnoopServiceUnavailableException extends RuntimeException { 35 | 36 | public SnoopServiceUnavailableException() { 37 | } 38 | 39 | public SnoopServiceUnavailableException(String message) { 40 | super(message); 41 | } 42 | 43 | public SnoopServiceUnavailableException(String message, Throwable cause) { 44 | super(message, cause); 45 | } 46 | 47 | public SnoopServiceUnavailableException(Throwable cause) { 48 | super(cause); 49 | } 50 | 51 | public SnoopServiceUnavailableException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { 52 | super(message, cause, enableSuppression, writableStackTrace); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /snoop-client/src/main/java/eu/agilejava/snoop/client/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop.client; 25 | -------------------------------------------------------------------------------- /snoop-client/src/main/java/eu/agilejava/snoop/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop; 25 | -------------------------------------------------------------------------------- /snoop-eureka/README.adoc: -------------------------------------------------------------------------------- 1 | = Snoop Eureka Client 2 | 3 | This is work in progress, but will eventually provide the same API for discovering clients from Eureka 4 | as the snoop-client does for Snoop. 5 | 6 | 7 | -------------------------------------------------------------------------------- /snoop-eureka/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | eu.agilejava 5 | snoop-eureka 6 | 1.0.2-SNAPSHOT 7 | jar 8 | 9 | Snoop Eureka 10 | 11 | 12 | UTF-8 13 | 1.8 14 | 1.8 15 | false 16 | mit 17 | 18 | 19 | 20 | 21 | 22 | javax 23 | javaee-web-api 24 | 7.0 25 | provided 26 | 27 | 28 | 29 | com.fasterxml.jackson.dataformat 30 | jackson-dataformat-yaml 31 | 2.5.1 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /snoop-eureka/src/main/java/eu/agilejava/snoop/eureka/annotation/EnableEurekaClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop.eureka.annotation; 25 | 26 | import java.lang.annotation.Documented; 27 | import java.lang.annotation.Retention; 28 | import java.lang.annotation.Target; 29 | 30 | import static java.lang.annotation.ElementType.TYPE; 31 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 32 | import javax.enterprise.context.ApplicationScoped; 33 | import javax.enterprise.inject.Stereotype; 34 | import javax.enterprise.util.Nonbinding; 35 | 36 | /** 37 | * Annotation for enabling application as Eureka client. 38 | * Use this annotation to register the application (service) with Eureka. 39 | * 40 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 41 | */ 42 | @Stereotype 43 | @Retention(RUNTIME) 44 | @Documented 45 | @ApplicationScoped 46 | @Target(TYPE) 47 | public @interface EnableEurekaClient { 48 | 49 | @Nonbinding 50 | String name(); 51 | } 52 | -------------------------------------------------------------------------------- /snoop-eureka/src/main/java/eu/agilejava/snoop/eureka/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop.eureka; 25 | -------------------------------------------------------------------------------- /snoop-eureka/src/main/java/eu/agilejava/snoop/eureka/scan/EurekaClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop.eureka.scan; 25 | 26 | import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml; 27 | import java.util.Calendar; 28 | import java.util.Map; 29 | import java.util.logging.Logger; 30 | import javax.annotation.PostConstruct; 31 | import javax.annotation.PreDestroy; 32 | import javax.annotation.Resource; 33 | import javax.ejb.ScheduleExpression; 34 | import javax.ejb.Singleton; 35 | import javax.ejb.Startup; 36 | import javax.ejb.Timeout; 37 | import javax.ejb.Timer; 38 | import javax.ejb.TimerConfig; 39 | import javax.ejb.TimerService; 40 | import javax.ws.rs.client.ClientBuilder; 41 | import javax.ws.rs.client.Entity; 42 | import javax.ws.rs.core.MediaType; 43 | import javax.ws.rs.core.Response; 44 | 45 | /** 46 | * Registers with Eureka and gives heartbeats every 10 second. 47 | * 48 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 49 | */ 50 | @Singleton 51 | @Startup 52 | public class EurekaClient { 53 | 54 | private static final Logger LOGGER = Logger.getLogger("eu.agilejava.snoop"); 55 | private static final String DEFAULT_SERVICE_URI = "http://localhost:8761/eureka/"; 56 | 57 | private String applicationName; 58 | private String serviceUrl; 59 | private String applicationHome; 60 | 61 | @Resource 62 | private TimerService timerService; 63 | 64 | @PostConstruct 65 | private void init() { 66 | 67 | LOGGER.config("Checking if snoop eureka is enabled"); 68 | LOGGER.config(() -> "YES: " + SnoopEurekaExtensionHelper.isEurekaEnabled()); 69 | 70 | if (SnoopEurekaExtensionHelper.isEurekaEnabled()) { 71 | 72 | readProperties(); 73 | 74 | EurekaConfig eurekaConfig = new EurekaConfig(); 75 | eurekaConfig.setHostName(applicationName); 76 | eurekaConfig.setApp(applicationName); 77 | eurekaConfig.setIpAddr("localhost"); 78 | eurekaConfig.setPort(8080); 79 | eurekaConfig.setStatus("UP"); 80 | eurekaConfig.setHomePageUrl(applicationHome); 81 | 82 | Entity entity = Entity.entity(new InstanceConfig(eurekaConfig), MediaType.APPLICATION_JSON); 83 | 84 | Response response = ClientBuilder.newClient() 85 | .target(serviceUrl + "apps/" + applicationName) 86 | .request() 87 | .post(entity); 88 | 89 | LOGGER.config(() -> "POST resulted in: " + response.getStatus() + ", " + response.getEntity()); 90 | 91 | ScheduleExpression schedule = new ScheduleExpression(); 92 | schedule.second("*/10").minute("*").hour("*").start(Calendar.getInstance().getTime()); 93 | 94 | TimerConfig config = new TimerConfig(); 95 | config.setPersistent(false); 96 | 97 | Timer timer = timerService.createCalendarTimer(schedule, config); 98 | 99 | LOGGER.config(() -> timer.getSchedule().toString()); 100 | 101 | } else { 102 | LOGGER.config("Snoop Eureka is not enabled. Use @EnableEurekaClient!"); 103 | } 104 | } 105 | 106 | @Timeout 107 | public void health(Timer timer) { 108 | LOGGER.config(() -> "health update: " + Calendar.getInstance().getTime()); 109 | LOGGER.config(() -> "Next: " + timer.getNextTimeout()); 110 | 111 | EurekaConfig eurekaConfig = new EurekaConfig(); 112 | eurekaConfig.setStatus("UP"); 113 | Entity entity = Entity.entity(new InstanceConfig(eurekaConfig), MediaType.APPLICATION_JSON); 114 | 115 | Response response = ClientBuilder.newClient() 116 | .target(serviceUrl + "apps/" + applicationName + "/" + applicationName) 117 | .request() 118 | .put(entity); 119 | 120 | LOGGER.config(() -> "PUT resulted in: " + response.getStatus() + ", " + response.getEntity()); 121 | 122 | } 123 | 124 | @PreDestroy 125 | private void deregister() { 126 | 127 | Response response = ClientBuilder.newClient() 128 | .target(serviceUrl + "apps/" + applicationName + "/" + applicationName) 129 | .request() 130 | .delete(); 131 | 132 | LOGGER.config(() -> "DELETE resulted in: " + response.getStatus() + ", " + response.getEntity()); 133 | } 134 | 135 | private void readProperties() { 136 | Yaml yaml = new Yaml(); 137 | Map props = (Map) yaml.load(this.getClass().getResourceAsStream("/application.yml")); 138 | 139 | Map snoopConfig = (Map) props.get("snoop"); 140 | 141 | applicationName = snoopConfig.get("applicationName"); 142 | applicationHome = snoopConfig.get("applicationHome"); 143 | 144 | LOGGER.config(() -> "application name: " + applicationName); 145 | 146 | Map eurekaProps = (Map) props.get("eureka"); 147 | Map eurekaClientProps = (Map) eurekaProps.get("client"); 148 | Map eurekaServiceProps = (Map) eurekaClientProps.get("serviceUrl"); 149 | 150 | serviceUrl = eurekaServiceProps.get("deafaultZone") != null ? snoopConfig.get("defaultZone") : DEFAULT_SERVICE_URI; 151 | } 152 | } 153 | -------------------------------------------------------------------------------- /snoop-eureka/src/main/java/eu/agilejava/snoop/eureka/scan/EurekaConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop.eureka.scan; 25 | 26 | /** 27 | * Eureka client configuration. 28 | * 29 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 30 | */ 31 | public class EurekaConfig { 32 | 33 | private String hostName; 34 | private String app; 35 | private String ipAddr; 36 | private int port; 37 | private int securePort; 38 | private String vipAddress; 39 | private String secureVipAddress; 40 | private String status; 41 | private String homePageUrl; 42 | private String statusPageUrl; 43 | private String healthCheckUrl; 44 | private DataCenterInfo dataCenterInfo; 45 | 46 | public class DataCenterInfo { 47 | 48 | public String getName() { 49 | return "MyOwn"; 50 | } 51 | } 52 | 53 | public String getHostName() { 54 | return hostName; 55 | } 56 | 57 | public void setHostName(String hostName) { 58 | this.hostName = hostName; 59 | } 60 | 61 | public String getApp() { 62 | return app; 63 | } 64 | 65 | public void setApp(String app) { 66 | this.app = app; 67 | } 68 | 69 | public String getIpAddr() { 70 | return ipAddr; 71 | } 72 | 73 | public void setIpAddr(String ipAddr) { 74 | this.ipAddr = ipAddr; 75 | } 76 | 77 | public int getPort() { 78 | return port; 79 | } 80 | 81 | public void setPort(int port) { 82 | this.port = port; 83 | } 84 | 85 | public int getSecurePort() { 86 | return securePort; 87 | } 88 | 89 | public void setSecurePort(int securePort) { 90 | this.securePort = securePort; 91 | } 92 | 93 | public String getVipAddress() { 94 | return vipAddress; 95 | } 96 | 97 | public void setVipAddress(String vipAddress) { 98 | this.vipAddress = vipAddress; 99 | } 100 | 101 | public String getSecureVipAddress() { 102 | return secureVipAddress; 103 | } 104 | 105 | public void setSecureVipAddress(String secureVipAddress) { 106 | this.secureVipAddress = secureVipAddress; 107 | } 108 | 109 | public String getStatus() { 110 | return status; 111 | } 112 | 113 | public void setStatus(String status) { 114 | this.status = status; 115 | } 116 | 117 | public String getHomePageUrl() { 118 | return homePageUrl; 119 | } 120 | 121 | public void setHomePageUrl(String homePageUrl) { 122 | this.homePageUrl = homePageUrl; 123 | } 124 | 125 | public String getStatusPageUrl() { 126 | return statusPageUrl; 127 | } 128 | 129 | public void setStatusPageUrl(String statusPageUrl) { 130 | this.statusPageUrl = statusPageUrl; 131 | } 132 | 133 | public String getHealthCheckUrl() { 134 | return healthCheckUrl; 135 | } 136 | 137 | public void setHealthCheckUrl(String healthCheckUrl) { 138 | this.healthCheckUrl = healthCheckUrl; 139 | } 140 | 141 | public DataCenterInfo getDataCenterInfo() { 142 | return new DataCenterInfo(); 143 | } 144 | } 145 | -------------------------------------------------------------------------------- /snoop-eureka/src/main/java/eu/agilejava/snoop/eureka/scan/InstanceConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop.eureka.scan; 25 | 26 | /** 27 | * Eureka instance configuration. 28 | * 29 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 30 | */ 31 | public class InstanceConfig { 32 | private EurekaConfig instance; 33 | 34 | public InstanceConfig(EurekaConfig eurekaConfig) { 35 | this.instance = eurekaConfig; 36 | } 37 | 38 | public EurekaConfig getInstance() { 39 | return instance; 40 | } 41 | 42 | public void setInstance(EurekaConfig instance) { 43 | this.instance = instance; 44 | } 45 | 46 | 47 | } 48 | -------------------------------------------------------------------------------- /snoop-eureka/src/main/java/eu/agilejava/snoop/eureka/scan/SnoopEurekaExtensionHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop.eureka.scan; 25 | 26 | /** 27 | * Singleton to store the information gathered from annotation scan. 28 | * 29 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 30 | */ 31 | public final class SnoopEurekaExtensionHelper { 32 | 33 | private String applicationName; 34 | private boolean eurekaEnabled; 35 | 36 | private static final SnoopEurekaExtensionHelper INSTANCE = new SnoopEurekaExtensionHelper(); 37 | 38 | public static String getApplicationName() { 39 | return INSTANCE.applicationName; 40 | } 41 | 42 | public static void setApplicationName(String applicationName) { 43 | INSTANCE.applicationName = applicationName; 44 | } 45 | 46 | public static boolean isEurekaEnabled() { 47 | return INSTANCE.eurekaEnabled; 48 | } 49 | 50 | public static void isEurekaEnabled(final boolean snoopEnabled) { 51 | INSTANCE.eurekaEnabled = snoopEnabled; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /snoop-eureka/src/main/java/eu/agilejava/snoop/eureka/scan/SnoopEurekaScannerExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop.eureka.scan; 25 | 26 | import eu.agilejava.snoop.eureka.annotation.EnableEurekaClient; 27 | import java.util.logging.Logger; 28 | import javax.enterprise.event.Observes; 29 | import javax.enterprise.inject.spi.AfterBeanDiscovery; 30 | import javax.enterprise.inject.spi.BeanManager; 31 | import javax.enterprise.inject.spi.BeforeBeanDiscovery; 32 | import javax.enterprise.inject.spi.Extension; 33 | import javax.enterprise.inject.spi.ProcessAnnotatedType; 34 | import javax.enterprise.inject.spi.WithAnnotations; 35 | 36 | /** 37 | * CDI Extension that scans for @EnableEurkeaClient annotations. 38 | * 39 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 40 | */ 41 | public class SnoopEurekaScannerExtension implements Extension { 42 | 43 | private static final Logger LOGGER = Logger.getLogger("eu.agilejava.snoop"); 44 | 45 | private String applicationName; 46 | private boolean eurekaEnabled; 47 | 48 | void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd) { 49 | LOGGER.config("Scanning for Eureka clients"); 50 | } 51 | 52 | void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager bm) { 53 | 54 | SnoopEurekaExtensionHelper.setApplicationName(applicationName); 55 | SnoopEurekaExtensionHelper.isEurekaEnabled(eurekaEnabled); 56 | LOGGER.config("Finished scanning for Eureka clients"); 57 | } 58 | 59 | void processAnnotatedType(@Observes @WithAnnotations({EnableEurekaClient.class}) ProcessAnnotatedType pat) { 60 | 61 | LOGGER.config(() -> "Found @EnableEurekaClient annotated class: " + pat.getAnnotatedType().getJavaClass().getName()); 62 | eurekaEnabled = true; 63 | applicationName = pat.getAnnotatedType().getAnnotation(EnableEurekaClient.class).name(); 64 | LOGGER.config(() -> "Eureka application name is: " + applicationName); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /snoop-eureka/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension: -------------------------------------------------------------------------------- 1 | eu.agilejava.snoop.eureka.scan.SnoopEurekaScannerExtension -------------------------------------------------------------------------------- /snoop-service.adoc: -------------------------------------------------------------------------------- 1 | == Snoop Service 2 | 3 | Start the Snoop Service 4 | 5 | docker run -it -p 8081:8080 ivargrimstad/snoop-service 6 | 7 | link:README.adoc[[home\]] 8 | -------------------------------------------------------------------------------- /snoop-service/README.adoc: -------------------------------------------------------------------------------- 1 | If you want to see logging of client registrations, heartbeats and discoveries. 2 | 3 | == Start the Snoop Service 4 | 5 | ``` 6 | docker run -it -p 8081:8080 ivargrimstad/snoop-service 7 | ``` 8 | 9 | == Set log levels 10 | 11 | ``` 12 | docker ps 13 | ./loglevels.sh [insert docker instance id here] 14 | ``` 15 | -------------------------------------------------------------------------------- /snoop-service/loglevels.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | docker exec $1 /opt/jboss/wildfly/bin/jboss-cli.sh --connect "/subsystem=logging/console-handler=CONSOLE:change-log-level(level="CONFIG")" 4 | docker exec $1 /opt/jboss/wildfly/bin/jboss-cli.sh --connect "/subsystem=logging/logger=eu.agilejava.snoop:add(level=CONFIG)" 5 | -------------------------------------------------------------------------------- /snoop-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | eu.agilejava 5 | snoop-service 6 | 1.3.5-SNAPSHOT 7 | war 8 | 9 | SnoopEE Service 10 | SnoopEE - A Discovery Service for Java EE. 11 | 12 | 13 | eu.agilejava 14 | snoop-root 15 | 1.3.5-SNAPSHOT 16 | 17 | 18 | 19 | 20 | glassfish 21 | 22 | true 23 | 24 | 25 | 26 | 27 | com.spotify 28 | docker-maven-plugin 29 | ${docker.plugin.version} 30 | 31 | docker-hub 32 | ivargrimstad/${project.artifactId}:${project.version} 33 | glassfish:4.1-jdk8 34 | Ivar Grimstad (ivar.grimstad@gmail.com) 35 | 36 | 37 | /usr/local/glassfish4/glassfish/domains/domain1/config/ 38 | ${basedir}/src/main/glassfish 39 | logging.properties 40 | 41 | 42 | /usr/local/glassfish4/glassfish/domains/domain1/lib/ext/ 43 | ${basedir}/src/main/glassfish 44 | custom-logger-0.5.jar 45 | 46 | 47 | /usr/local/glassfish4/glassfish/domains/domain1/autodeploy/ 48 | ${basedir}/target 49 | ${project.build.finalName}.war 50 | 51 | 52 | ["asadmin", "start-domain", "--verbose"] 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /snoop-service/src/main/glassfish/custom-logger-0.5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ivargrimstad/snoop/a1bc7e62340d5f5dbc6e431aae1ac148a6316806/snoop-service/src/main/glassfish/custom-logger-0.5.jar -------------------------------------------------------------------------------- /snoop-service/src/main/glassfish/logging.properties: -------------------------------------------------------------------------------- 1 | # 2 | # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. 3 | # 4 | # Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved. 5 | # 6 | # The contents of this file are subject to the terms of either the GNU 7 | # General Public License Version 2 only ("GPL") or the Common Development 8 | # and Distribution License("CDDL") (collectively, the "License"). You 9 | # may not use this file except in compliance with the License. You can 10 | # obtain a copy of the License at 11 | # https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html 12 | # or packager/legal/LICENSE.txt. See the License for the specific 13 | # language governing permissions and limitations under the License. 14 | # 15 | # When distributing the software, include this License Header Notice in each 16 | # file and include the License file at packager/legal/LICENSE.txt. 17 | # 18 | # GPL Classpath Exception: 19 | # Oracle designates this particular file as subject to the "Classpath" 20 | # exception as provided by Oracle in the GPL Version 2 section of the License 21 | # file that accompanied this code. 22 | # 23 | # Modifications: 24 | # If applicable, add the following below the License Header, with the fields 25 | # enclosed by brackets [] replaced by your own identifying information: 26 | # "Portions Copyright [year] [name of copyright owner]" 27 | # 28 | # Contributor(s): 29 | # If you wish your version of this file to be governed by only the CDDL or 30 | # only the GPL Version 2, indicate your decision by adding "[Contributor] 31 | # elects to include this software in this distribution under the [CDDL or GPL 32 | # Version 2] license." If you don't indicate a single choice of license, a 33 | # recipient has the option to distribute your version of this file under 34 | # either the CDDL, the GPL Version 2 or to extend the choice of license to 35 | # its licensees as provided above. However, if you add GPL Version 2 code 36 | # and therefore, elected the GPL Version 2 license, then the option applies 37 | # only if the new code is made subject to such option by the copyright 38 | # holder. 39 | # 40 | 41 | #GlassFish logging.properties list 42 | #Update Thurs Oct 18 2012 43 | #All attributes details 44 | handlers=java.util.logging.ConsoleHandler 45 | java.util.logging.ConsoleHandler.formatter=eu.agilejava.logger.CustomFormatter 46 | 47 | #All log level details 48 | java.util.logging.ConsoleHandler.level=CONFIG 49 | eu.agilejava.level=CONFIG 50 | 51 | #javax.enterprise.system.tools.admin.level=INFO 52 | #org.apache.jasper.level=INFO 53 | #javax.enterprise.system.core.level=INFO 54 | #javax.enterprise.system.core.classloading.level=INFO 55 | #javax.enterprise.system.tools.deployment.level=INFO 56 | #javax.enterprise.system.core.transaction.level=INFO 57 | #org.apache.catalina.level=INFO 58 | #org.apache.coyote.level=INFO 59 | #javax.level=INFO 60 | #javax.enterprise.system.util.level=INFO 61 | #javax.enterprise.resource.resourceadapter.level=INFO 62 | #javax.enterprise.system.core.config.level=INFO 63 | #javax.enterprise.system.level=INFO 64 | #javax.enterprise.system.core.security.level=INFO 65 | #javax.enterprise.system.container.cmp.level=INFO 66 | #javax.enterprise.system.core.selfmanagement.level=INFO 67 | #javax.enterprise.resource.jdo.level=INFO 68 | #javax.enterprise.resource.sqltrace.level=FINE 69 | #org.jvnet.hk2.osgiadapter.level=INFO 70 | #javax.enterprise.system.ssl.security.level=INFO 71 | 72 | #javax.enterprise.resource.corba.level=INFO 73 | #javax.enterprise.resource.jta.level=INFO 74 | #javax.enterprise.system.webservices.saaj.level=INFO 75 | #javax.enterprise.system.container.ejb.level=INFO 76 | #javax.enterprise.system.container.ejb.mdb.level=INFO 77 | #javax.enterprise.resource.javamail.level=INFO 78 | #javax.enterprise.system.webservices.rpc.level=INFO 79 | #javax.enterprise.system.container.web.level=INFO 80 | #javax.enterprise.resource.jms.level=INFO 81 | #javax.enterprise.system.webservices.registry.level=INFO 82 | #javax.enterprise.resource.webcontainer.jsf.application.level=INFO 83 | #javax.enterprise.resource.webcontainer.jsf.resource.level=INFO 84 | #javax.enterprise.resource.webcontainer.jsf.config.level=INFO 85 | #javax.enterprise.resource.webcontainer.jsf.context.level=INFO 86 | #javax.enterprise.resource.webcontainer.jsf.facelets.level=INFO 87 | #javax.enterprise.resource.webcontainer.jsf.lifecycle.level=INFO 88 | #javax.enterprise.resource.webcontainer.jsf.managedbean.level=INFO 89 | #javax.enterprise.resource.webcontainer.jsf.renderkit.level=INFO 90 | #javax.enterprise.resource.webcontainer.jsf.taglib.level=INFO 91 | #javax.enterprise.resource.webcontainer.jsf.timing.level=INFO 92 | #javax.org.glassfish.persistence.level=INFO 93 | #javax.enterprise.system.tools.backup.level=INFO 94 | #org.glassfish.admingui.level=INFO 95 | #org.glassfish.naming.level=INFO 96 | #org.eclipse.persistence.session.level=INFO 97 | 98 | -------------------------------------------------------------------------------- /snoop-service/src/main/java/eu/agilejava/snoop/SnoopClientRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop; 25 | 26 | import java.util.Calendar; 27 | import java.util.Collection; 28 | import java.util.Map; 29 | import java.util.Optional; 30 | import java.util.Set; 31 | import java.util.concurrent.ConcurrentHashMap; 32 | import java.util.logging.Logger; 33 | import java.util.stream.Collectors; 34 | import javax.ejb.Singleton; 35 | import static java.util.Calendar.getInstance; 36 | 37 | /** 38 | * Register of clients that have registered themselves. Automatically disregarded after a minute without heartbeat. 39 | * 40 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 41 | */ 42 | @Singleton 43 | public class SnoopClientRegistry { 44 | 45 | private static final Logger LOGGER = Logger.getLogger("eu.agilejava.snoop"); 46 | 47 | private final Map clients = new ConcurrentHashMap<>(); 48 | private final Map clientConfigurations = new ConcurrentHashMap<>(); 49 | 50 | public void register(final SnoopConfig client) { 51 | Calendar now = getInstance(); 52 | clients.put(client.getServiceName(), now.getTimeInMillis()); 53 | clientConfigurations.put(client.getServiceName(), client); 54 | 55 | LOGGER.config(() -> "Client: " + client.getServiceName() + " registered up at " + now.getTime()); 56 | } 57 | 58 | public void deRegister(final String clientId) { 59 | clients.remove(clientId); 60 | clientConfigurations.remove(clientId); 61 | 62 | LOGGER.warning(() -> "Client: " + clientId + " deregistered at " + Calendar.getInstance().getTime()); 63 | } 64 | 65 | public Set getClients() { 66 | 67 | return clients.keySet().stream() 68 | .filter(c -> clients.get(c) > System.currentTimeMillis() - 60000) 69 | .collect(Collectors.toSet()); 70 | } 71 | 72 | public Collection getServiceConfigs() { 73 | return clientConfigurations.values(); 74 | } 75 | 76 | public Optional getClientConfig(String clientId) { 77 | 78 | if (getClients().contains(clientId)) { 79 | 80 | return Optional.ofNullable(clientConfigurations.get(clientId)); 81 | 82 | } else { 83 | return Optional.empty(); 84 | } 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /snoop-service/src/main/java/eu/agilejava/snoop/SnoopConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop; 25 | 26 | import java.io.StringReader; 27 | import java.io.StringWriter; 28 | import java.io.Writer; 29 | import javax.json.Json; 30 | import javax.json.JsonObject; 31 | import javax.json.JsonReader; 32 | import javax.json.stream.JsonGenerator; 33 | 34 | /** 35 | * 36 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 37 | */ 38 | public class SnoopConfig { 39 | 40 | private String serviceName; 41 | private String serviceHome; 42 | private String serviceRoot; 43 | 44 | public String getServiceName() { 45 | return serviceName; 46 | } 47 | 48 | public void setServiceName(String serviceName) { 49 | this.serviceName = serviceName; 50 | } 51 | 52 | public String getServiceHome() { 53 | return serviceHome; 54 | } 55 | 56 | public void setServiceHome(String serviceHome) { 57 | this.serviceHome = serviceHome; 58 | } 59 | 60 | public String getServiceRoot() { 61 | return serviceRoot; 62 | } 63 | 64 | public void setServiceRoot(String serviceRoot) { 65 | this.serviceRoot = serviceRoot; 66 | } 67 | 68 | public String toJSON() { 69 | 70 | Writer w = new StringWriter(); 71 | try (JsonGenerator generator = Json.createGenerator(w)) { 72 | 73 | generator.writeStartObject() 74 | .write("serviceName", serviceName) 75 | .write("serviceHome", serviceHome) 76 | .write("serviceRoot", serviceRoot) 77 | .writeEnd(); 78 | } 79 | 80 | return w.toString(); 81 | } 82 | 83 | public static SnoopConfig fromJSON(String json) { 84 | 85 | SnoopConfig config = new SnoopConfig(); 86 | 87 | try (JsonReader reader = Json.createReader(new StringReader(json))) { 88 | 89 | JsonObject configJson = reader.readObject(); 90 | 91 | config.setServiceName(configJson.getString("serviceName")); 92 | config.setServiceHome(configJson.getString("serviceHome")); 93 | config.setServiceRoot(configJson.getString("serviceRoot")); 94 | } 95 | 96 | return config; 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /snoop-service/src/main/java/eu/agilejava/snoop/SnoopEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop; 25 | 26 | import static eu.agilejava.snoop.SnoopConfig.fromJSON; 27 | import java.util.logging.Logger; 28 | import javax.ejb.EJB; 29 | import javax.ejb.Stateless; 30 | import javax.websocket.OnMessage; 31 | import javax.websocket.server.ServerEndpoint; 32 | 33 | /** 34 | * WebSocket endpoint for client registration. 35 | * 36 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 37 | */ 38 | @ServerEndpoint("/snoop") 39 | @Stateless 40 | public class SnoopEndpoint { 41 | 42 | private static final Logger LOGGER = Logger.getLogger("eu.agilejava.snoop"); 43 | 44 | @EJB 45 | private SnoopClientRegistry clients; 46 | 47 | @OnMessage 48 | public String onMessage(String message) { 49 | LOGGER.config(() -> "Registering: " + message); 50 | 51 | SnoopConfig client = fromJSON(message); 52 | 53 | clients.register(client); 54 | return "snoopstatus/" + message; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /snoop-service/src/main/java/eu/agilejava/snoop/SnoopService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop; 25 | 26 | import java.util.logging.Logger; 27 | import javax.annotation.PostConstruct; 28 | import javax.annotation.PreDestroy; 29 | import javax.ejb.Singleton; 30 | import javax.ejb.Startup; 31 | 32 | /** 33 | * 34 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 35 | */ 36 | @Startup 37 | @Singleton 38 | public class SnoopService { 39 | 40 | private static final Logger LOGGER = Logger.getLogger("eu.agilejava.snoop"); 41 | 42 | @PostConstruct 43 | private void start() { 44 | 45 | // http://www.network-science.de/ascii/ Font: big 46 | LOGGER.config(" _____ ______ ______ "); 47 | LOGGER.config(" / ____| | ____| ____|"); 48 | LOGGER.config("| (___ _ __ ___ ___ _ __ | |__ | |__ "); 49 | LOGGER.config(" \\___ \\| '_ \\ / _ \\ / _ \\| '_ \\| __| | __| "); 50 | LOGGER.config(" ____) | | | | (_) | (_) | |_) | |____| |____ "); 51 | LOGGER.config("|_____/|_| |_|\\___/ \\___/| .__/|______|______|"); 52 | LOGGER.config(" | | "); 53 | LOGGER.config(" |_| "); 54 | 55 | } 56 | 57 | @PreDestroy 58 | private void stop() { 59 | LOGGER.severe("SnoopEE stopped"); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /snoop-service/src/main/java/eu/agilejava/snoop/SnoopStatusEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop; 25 | 26 | import static eu.agilejava.snoop.SnoopConfig.fromJSON; 27 | import java.util.logging.Logger; 28 | import javax.ejb.EJB; 29 | import javax.ejb.Stateless; 30 | import javax.websocket.OnMessage; 31 | import javax.websocket.server.PathParam; 32 | import javax.websocket.server.ServerEndpoint; 33 | 34 | /** 35 | * WebSocket endpoint for heartbeats. 36 | * 37 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 38 | */ 39 | @ServerEndpoint("/snoopstatus/{clientId}") 40 | @Stateless 41 | public class SnoopStatusEndpoint { 42 | 43 | private static final Logger LOGGER = Logger.getLogger("eu.agilejava.snoop"); 44 | 45 | @EJB 46 | private SnoopClientRegistry clients; 47 | 48 | /** 49 | * Heartbeat endpoint. 50 | * Registers that the client is still there and updates configuration 51 | * if changed. 52 | * 53 | * @param clientId The client id 54 | * @param applicationConfig The updated configuration 55 | */ 56 | @OnMessage 57 | public void onMessage(@PathParam("clientId") String clientId, String applicationConfig) { 58 | 59 | LOGGER.config(() -> "Client: " + clientId + ", status: " + applicationConfig); 60 | 61 | if (applicationConfig != null && !applicationConfig.isEmpty()) { 62 | clients.register(fromJSON(applicationConfig)); 63 | } else { 64 | clients.deRegister(clientId); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /snoop-service/src/main/java/eu/agilejava/snoop/api/ServicesResource.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop.api; 25 | 26 | import eu.agilejava.snoop.SnoopClientRegistry; 27 | import eu.agilejava.snoop.SnoopConfig; 28 | import java.util.Collection; 29 | import javax.ejb.EJB; 30 | import javax.ws.rs.GET; 31 | import javax.ws.rs.NotFoundException; 32 | import javax.ws.rs.Path; 33 | import javax.ws.rs.PathParam; 34 | import javax.ws.rs.Produces; 35 | import javax.ws.rs.core.GenericEntity; 36 | import static javax.ws.rs.core.MediaType.APPLICATION_JSON; 37 | import javax.ws.rs.core.Response; 38 | 39 | /** 40 | * 41 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 42 | */ 43 | @Path("services") 44 | public class ServicesResource { 45 | 46 | @EJB 47 | private SnoopClientRegistry snoopClientRegistry; 48 | 49 | @GET 50 | @Produces(APPLICATION_JSON) 51 | public Response all() { 52 | 53 | final Collection serviceConfigs = snoopClientRegistry.getServiceConfigs(); 54 | 55 | return Response.ok(new GenericEntity>(serviceConfigs) {}) 56 | .header("Access-Control-Allow-Origin", "*").build(); 57 | } 58 | 59 | @GET 60 | @Produces(APPLICATION_JSON) 61 | @Path("{serviceId}") 62 | public Response lookup(@PathParam("serviceId") String serviceId) { 63 | 64 | return Response.ok(snoopClientRegistry.getClientConfig(serviceId) 65 | .orElseThrow(NotFoundException::new)).build(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /snoop-service/src/main/java/eu/agilejava/snoop/config/ApplicatonConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop.config; 25 | 26 | import eu.agilejava.snoop.api.ServicesResource; 27 | import java.util.HashSet; 28 | import java.util.Set; 29 | import javax.ws.rs.ApplicationPath; 30 | import javax.ws.rs.core.Application; 31 | 32 | /** 33 | * 34 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 35 | */ 36 | @ApplicationPath("api") 37 | public class ApplicatonConfig extends Application { 38 | 39 | @Override 40 | public Set> getClasses() { 41 | 42 | Set> classes = new HashSet<>(); 43 | classes.add(ServicesResource.class); 44 | 45 | return classes; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /snoop-service/src/main/java/eu/agilejava/snoop/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop; 25 | -------------------------------------------------------------------------------- /snoop-service/src/main/java/eu/agilejava/snoop/ui/SnoopController.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop.ui; 25 | 26 | import eu.agilejava.snoop.SnoopClientRegistry; 27 | import eu.agilejava.snoop.SnoopConfig; 28 | import java.util.Collection; 29 | import java.util.Set; 30 | import java.util.logging.Logger; 31 | import javax.ejb.EJB; 32 | import javax.enterprise.context.RequestScoped; 33 | import javax.inject.Named; 34 | 35 | /** 36 | * Controller for the snoop service UI. 37 | * 38 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 39 | */ 40 | @Named 41 | @RequestScoped 42 | public class SnoopController { 43 | 44 | private static final Logger LOGGER = Logger.getLogger("eu.agilejava.snoop"); 45 | 46 | @EJB 47 | private SnoopClientRegistry clients; 48 | 49 | public Set getClients() { 50 | return clients.getClients(); 51 | } 52 | 53 | public Collection getClientConfigurations() { 54 | return clients.getServiceConfigs(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /snoop-service/src/main/webapp/WEB-INF/glassfish-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | snoop-service 5 | 6 | -------------------------------------------------------------------------------- /snoop-service/src/main/webapp/WEB-INF/jboss-web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | /snoop-service 4 | 5 | -------------------------------------------------------------------------------- /snoop-service/src/main/webapp/WEB-INF/template.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | SnoopEE Service 12 | 13 | 14 | 15 | 16 |
17 | 18 |

Welcome to SnoopEE Service

19 |
20 |
21 | 22 |
23 | Content 24 |
25 | 26 |
27 | 28 | @ivar_grimstad
29 | Licensed under the MIT License. 30 |
31 |
32 | 33 | 34 |
35 | 36 | 37 | -------------------------------------------------------------------------------- /snoop-service/src/main/webapp/WEB-INF/web.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | javax.faces.PROJECT_STAGE 6 | Production 7 | 8 | 9 | 10 | javax.faces.DEFAULT_SUFFIX 11 | .xhtml 12 | 13 | 14 | 15 | Faces Servlet 16 | javax.faces.webapp.FacesServlet 17 | 1 18 | 19 | 20 | 21 | Faces Servlet 22 | /faces/* 23 | *.jsf 24 | 25 | 26 | 27 | 28 | 30 29 | 30 | 31 | 32 | 33 | services.jsf 34 | 35 | 36 | 37 | Restrict access to XHTML files 38 | 39 | XHTML files 40 | *.xhtml 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /snoop-service/src/main/webapp/resources/css/cssLayout.css: -------------------------------------------------------------------------------- 1 | 2 | #top { 3 | position: relative; 4 | background-color: #036fab; 5 | color: white; 6 | padding: 5px; 7 | margin: 0px 0px 10px 0px; 8 | } 9 | 10 | #bottom { 11 | position: relative; 12 | background-color: #c2dfef; 13 | padding: 5px; 14 | margin: 10px 0px 0px 0px; 15 | } 16 | 17 | #left { 18 | float: left; 19 | background-color: #ece3a5; 20 | padding: 5px; 21 | width: 150px; 22 | } 23 | 24 | #right { 25 | float: right; 26 | background-color: #ece3a5; 27 | padding: 5px; 28 | width: 150px; 29 | } 30 | 31 | .center_content { 32 | position: relative; 33 | background-color: #dddddd; 34 | padding: 5px; 35 | } 36 | 37 | .left_content { 38 | background-color: #dddddd; 39 | padding: 5px; 40 | margin-left: 170px; 41 | } 42 | 43 | .right_content { 44 | background-color: #dddddd; 45 | padding: 5px; 46 | margin: 0px 170px 0px 170px; 47 | } 48 | 49 | #top a:link, #top a:visited { 50 | color: white; 51 | font-weight : bold; 52 | text-decoration: none; 53 | } 54 | 55 | #top a:link:hover, #top a:visited:hover { 56 | color: black; 57 | font-weight : bold; 58 | text-decoration : underline; 59 | } 60 | 61 | 62 | -------------------------------------------------------------------------------- /snoop-service/src/main/webapp/resources/css/default.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #ffffff; 3 | font-size: 12px; 4 | font-family: Verdana, "Verdana CE", Arial, "Arial CE", "Lucida Grande CE", lucida, "Helvetica CE", sans-serif; 5 | color: #000000; 6 | margin: 10px; 7 | } 8 | 9 | h1 { 10 | font-family: Arial, "Arial CE", "Lucida Grande CE", lucida, "Helvetica CE", sans-serif; 11 | font-size: 16px; 12 | font-weight: bold; 13 | margin: 0px; 14 | padding: 0px; 15 | color: #FFFFFF; 16 | } 17 | 18 | a:link, a:visited { 19 | color: #045491; 20 | font-weight : bold; 21 | text-decoration: none; 22 | } 23 | 24 | a:link:hover, a:visited:hover { 25 | color: #045491; 26 | font-weight : bold; 27 | text-decoration : underline; 28 | } 29 | -------------------------------------------------------------------------------- /snoop-service/src/main/webapp/services.xhtml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |

Registered Services

15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | #{client.serviceHome}#{client.serviceRoot} 30 | 31 | 32 | 33 | 34 |
35 | 36 |
37 | 38 |
39 | 40 | 41 | -------------------------------------------------------------------------------- /snoop-service/src/main/wildfly/standalone-snoop.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | jdbc:h2:mem:test;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE 133 | h2 134 | 135 | sa 136 | sa 137 | 138 | 139 | 140 | 141 | org.h2.jdbcx.JdbcDataSource 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | false 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | ${jboss.bind.address:127.0.0.1} 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | -------------------------------------------------------------------------------- /snoop-swarm/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | eu.agilejava 5 | snoop-swarm 6 | 1.3.5-SNAPSHOT 7 | jar 8 | 9 | SnoopEE Swarm 10 | SnoopEE Swarm Registration Client 11 | 12 | 13 | eu.agilejava 14 | snoop-root 15 | 1.3.5-SNAPSHOT 16 | 17 | 18 | 19 | UTF-8 20 | 1.8 21 | 1.8 22 | false 23 | mit 24 | 25 | 26 | 27 | 28 | eu.agilejava 29 | snoop 30 | 1.3.5-SNAPSHOT 31 | 32 | 33 | org.glassfish 34 | javax.json 35 | 1.0.4 36 | 37 | 38 | org.wildfly.swarm 39 | ejb 40 | 1.0.0.CR1 41 | 42 | 43 | org.wildfly.swarm 44 | cdi 45 | 1.0.0.CR1 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /snoop/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | eu.agilejava 5 | snoop 6 | 1.3.5-SNAPSHOT 7 | jar 8 | 9 | SnoopEE 10 | SnoopEE Registration Client 11 | 12 | 13 | eu.agilejava 14 | snoop-root 15 | 1.3.5-SNAPSHOT 16 | 17 | 18 | 19 | 20 | 21 | eu.agilejava 22 | snoop-client 23 | 1.3.5-SNAPSHOT 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /snoop/src/main/java/eu/agilejava/snoop/annotation/EnableSnoopClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop.annotation; 25 | 26 | import java.lang.annotation.Documented; 27 | import java.lang.annotation.Retention; 28 | import java.lang.annotation.Target; 29 | 30 | import static java.lang.annotation.ElementType.TYPE; 31 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 32 | import javax.enterprise.context.ApplicationScoped; 33 | import javax.enterprise.inject.Stereotype; 34 | import javax.enterprise.util.Nonbinding; 35 | 36 | /** 37 | * Annotation for enabling application as Snoop client. Use this annotation to register the application (service) with 38 | * Snoop. 39 | * 40 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 41 | */ 42 | @Stereotype 43 | @Retention(RUNTIME) 44 | @Documented 45 | @ApplicationScoped 46 | @Target(TYPE) 47 | public @interface EnableSnoopClient { 48 | 49 | /** 50 | * The service name. This is the unique identifier for this service when it is registered with Snoop. 51 | * 52 | * @return The name of the service 53 | */ 54 | @Nonbinding 55 | String serviceName(); 56 | } 57 | -------------------------------------------------------------------------------- /snoop/src/main/java/eu/agilejava/snoop/annotation/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop.annotation; 25 | -------------------------------------------------------------------------------- /snoop/src/main/java/eu/agilejava/snoop/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop; 25 | -------------------------------------------------------------------------------- /snoop/src/main/java/eu/agilejava/snoop/scan/SnoopExtensionHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop.scan; 25 | 26 | /** 27 | * Singleton to store the information gathered from annotation scan. 28 | * 29 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 30 | */ 31 | public final class SnoopExtensionHelper { 32 | 33 | private String serviceName; 34 | private boolean snoopEnabled; 35 | 36 | private static final SnoopExtensionHelper INSTANCE = new SnoopExtensionHelper(); 37 | 38 | public static String getServiceName() { 39 | return INSTANCE.serviceName; 40 | } 41 | 42 | public static void setServiceName(String serviceName) { 43 | INSTANCE.serviceName = serviceName; 44 | } 45 | 46 | public static boolean isSnoopEnabled() { 47 | return INSTANCE.snoopEnabled; 48 | } 49 | 50 | public static void setSnoopEnabled(final boolean snoopEnabled) { 51 | INSTANCE.snoopEnabled = snoopEnabled; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /snoop/src/main/java/eu/agilejava/snoop/scan/SnoopRegistrationClient.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop.scan; 25 | 26 | import com.fasterxml.jackson.dataformat.yaml.snakeyaml.Yaml; 27 | import com.fasterxml.jackson.dataformat.yaml.snakeyaml.error.YAMLException; 28 | import eu.agilejava.snoop.SnoopConfigurationException; 29 | import eu.agilejava.snoop.client.SnoopConfig; 30 | import java.io.IOException; 31 | import java.net.URI; 32 | import java.util.Calendar; 33 | import java.util.Collections; 34 | import java.util.Map; 35 | import java.util.Optional; 36 | import java.util.logging.Logger; 37 | import javax.annotation.PostConstruct; 38 | import javax.annotation.PreDestroy; 39 | import javax.annotation.Resource; 40 | import javax.ejb.ScheduleExpression; 41 | import javax.ejb.Singleton; 42 | import javax.ejb.Startup; 43 | import javax.ejb.TimedObject; 44 | import javax.ejb.Timeout; 45 | import javax.ejb.Timer; 46 | import javax.ejb.TimerConfig; 47 | import javax.ejb.TimerService; 48 | import javax.websocket.ClientEndpoint; 49 | import javax.websocket.ContainerProvider; 50 | import javax.websocket.DeploymentException; 51 | import javax.websocket.OnMessage; 52 | import javax.websocket.Session; 53 | import javax.websocket.WebSocketContainer; 54 | 55 | /** 56 | * Registers with Snoop and gives heartbeats every 10 second. 57 | * 58 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 59 | */ 60 | @ClientEndpoint 61 | @Singleton 62 | @Startup 63 | public class SnoopRegistrationClient { 64 | 65 | private static final Logger LOGGER = Logger.getLogger("eu.agilejava.snoop"); 66 | private static final String REGISTER_ENDPOINT = "snoop"; 67 | private static final String STATUS_ENDPOINT = "snoopstatus/"; 68 | 69 | private String serviceUrl; 70 | private final SnoopConfig applicationConfig = new SnoopConfig(); 71 | 72 | @Resource 73 | private TimerService timerService; 74 | 75 | @PostConstruct 76 | private void init() { 77 | LOGGER.config("Checking if snoop is enabled"); 78 | 79 | if (SnoopExtensionHelper.isSnoopEnabled()) { 80 | 81 | try { 82 | readConfiguration(); 83 | 84 | LOGGER.config(() -> "Registering " + applicationConfig.getServiceName()); 85 | register(applicationConfig.getServiceName()); 86 | 87 | } catch (SnoopConfigurationException e) { 88 | LOGGER.severe(() -> "Snoop is enabled but not configured properly: " + e.getMessage()); 89 | } 90 | 91 | } else { 92 | LOGGER.config("Snoop is not enabled. Use @EnableSnoopClient!"); 93 | } 94 | } 95 | 96 | public void register(final String clientId) { 97 | 98 | sendMessage(REGISTER_ENDPOINT, applicationConfig.toJSON()); 99 | 100 | ScheduleExpression schedule = new ScheduleExpression(); 101 | schedule.second("*/10").minute("*").hour("*").start(Calendar.getInstance().getTime()); 102 | 103 | TimerConfig config = new TimerConfig(); 104 | config.setPersistent(false); 105 | 106 | Timer timer = timerService.createCalendarTimer(schedule, config); 107 | 108 | LOGGER.config(() -> timer.getSchedule().toString()); 109 | } 110 | 111 | /** 112 | * Handles incoming message. 113 | * 114 | * @param session The WebSocket session 115 | * @param message The message 116 | */ 117 | @OnMessage 118 | public void onMessage(Session session, String message) { 119 | LOGGER.config(() -> "Message: " + message); 120 | sendMessage(STATUS_ENDPOINT + applicationConfig.getServiceName(), applicationConfig.toJSON()); 121 | } 122 | 123 | @Timeout 124 | public void health(Timer timer) { 125 | LOGGER.config(() -> "health update: " + Calendar.getInstance().getTime()); 126 | LOGGER.config(() -> "Next: " + timer.getNextTimeout()); 127 | sendMessage(STATUS_ENDPOINT + applicationConfig.getServiceName(), applicationConfig.toJSON()); 128 | } 129 | 130 | /** 131 | * Sends message to the WebSocket server. 132 | * 133 | * @param endpoint The server endpoint 134 | * @param msg The message 135 | * @return a return message 136 | */ 137 | private String sendMessage(String endpoint, String msg) { 138 | 139 | LOGGER.config(() -> "Sending message: " + msg); 140 | 141 | String returnValue = "-1"; 142 | try { 143 | WebSocketContainer container = ContainerProvider.getWebSocketContainer(); 144 | String uri = serviceUrl + endpoint; 145 | Session session = container.connectToServer(this, URI.create(uri)); 146 | session.getBasicRemote().sendText(msg != null ? msg : ""); 147 | returnValue = session.getId(); 148 | 149 | } catch (DeploymentException | IOException ex) { 150 | LOGGER.warning(ex.getMessage()); 151 | } 152 | 153 | return returnValue; 154 | } 155 | 156 | @PreDestroy 157 | private void deregister() { 158 | 159 | LOGGER.config(() -> "Deregistering " + applicationConfig.getServiceName()); 160 | sendMessage(STATUS_ENDPOINT + applicationConfig.getServiceName(), null); 161 | } 162 | 163 | private void readConfiguration() throws SnoopConfigurationException { 164 | 165 | Map snoopConfig = Collections.EMPTY_MAP; 166 | try { 167 | Yaml yaml = new Yaml(); 168 | Map props = (Map) yaml.load(Thread.currentThread().getContextClassLoader().getResourceAsStream("/snoop.yml")); 169 | 170 | snoopConfig = (Map) props.get("snoop"); 171 | 172 | } catch (YAMLException e) { 173 | LOGGER.config(() -> "No configuration file. Using env properties."); 174 | } 175 | 176 | applicationConfig.setServiceName(SnoopExtensionHelper.getServiceName()); 177 | final String host = readProperty("host", snoopConfig); 178 | final String port = readProperty("port", snoopConfig); 179 | applicationConfig.setServiceHome(host + ":" + port + "/"); 180 | applicationConfig.setServiceRoot(readProperty("serviceRoot", snoopConfig)); 181 | 182 | LOGGER.config(() -> "application config: " + applicationConfig.toJSON()); 183 | 184 | serviceUrl = "ws://" + readProperty("snoopService", snoopConfig); 185 | } 186 | 187 | private String readProperty(final String key, Map snoopConfig) { 188 | 189 | String property = Optional.ofNullable(System.getProperty(key)) 190 | .orElseGet(() -> { 191 | String envProp = Optional.ofNullable(System.getenv(applicationConfig.getServiceName() + "." + key)) 192 | .orElseGet(() -> { 193 | String confProp = Optional.ofNullable(snoopConfig.get(key)) 194 | .orElseThrow(() -> { 195 | return new SnoopConfigurationException(key + " must be configured either in application.yml or as env parameter"); 196 | }) 197 | .toString(); 198 | return confProp; 199 | }); 200 | return envProp; 201 | }); 202 | return property; 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /snoop/src/main/java/eu/agilejava/snoop/scan/SnoopScannerExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop.scan; 25 | 26 | import eu.agilejava.snoop.annotation.EnableSnoopClient; 27 | import java.util.logging.Logger; 28 | import javax.enterprise.event.Observes; 29 | import javax.enterprise.inject.spi.AfterBeanDiscovery; 30 | import javax.enterprise.inject.spi.BeanManager; 31 | import javax.enterprise.inject.spi.BeforeBeanDiscovery; 32 | import javax.enterprise.inject.spi.Extension; 33 | import javax.enterprise.inject.spi.ProcessAnnotatedType; 34 | import javax.enterprise.inject.spi.WithAnnotations; 35 | 36 | /** 37 | * CDI Extension that scans for @EnableSnoopClient annotations. 38 | * 39 | * @author Ivar Grimstad (ivar.grimstad@gmail.com) 40 | */ 41 | public class SnoopScannerExtension implements Extension { 42 | 43 | private static final Logger LOGGER = Logger.getLogger("eu.agilejava.snoop"); 44 | 45 | private String serviceName; 46 | private boolean snoopEnabled; 47 | 48 | void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd) { 49 | LOGGER.config("Scanning for Snoop clients"); 50 | } 51 | 52 | void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager bm) { 53 | 54 | SnoopExtensionHelper.setServiceName(serviceName); 55 | SnoopExtensionHelper.setSnoopEnabled(snoopEnabled); 56 | LOGGER.config("Finished scanning for Snoop clients"); 57 | } 58 | 59 | void processAnnotatedType(@Observes @WithAnnotations(EnableSnoopClient.class) ProcessAnnotatedType pat) { 60 | 61 | // workaround for WELD bug revealed by JDK8u60 62 | final ProcessAnnotatedType snoopAnnotated = pat; 63 | 64 | LOGGER.config(() -> "Found @EnableSnoopClient annotated class: " + snoopAnnotated.getAnnotatedType().getJavaClass().getName()); 65 | snoopEnabled = true; 66 | serviceName = snoopAnnotated.getAnnotatedType().getAnnotation(EnableSnoopClient.class).serviceName(); 67 | LOGGER.config(() -> "Snoop Service name is: " + serviceName); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /snoop/src/main/java/eu/agilejava/snoop/scan/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * The MIT License 3 | * 4 | * Copyright 2015 Ivar Grimstad (ivar.grimstad@gmail.com). 5 | * 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy 7 | * of this software and associated documentation files (the "Software"), to deal 8 | * in the Software without restriction, including without limitation the rights 9 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | * copies of the Software, and to permit persons to whom the Software is 11 | * furnished to do so, subject to the following conditions: 12 | * 13 | * The above copyright notice and this permission notice shall be included in 14 | * all copies or substantial portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | * THE SOFTWARE. 23 | */ 24 | package eu.agilejava.snoop.scan; 25 | -------------------------------------------------------------------------------- /snoop/src/main/resources/META-INF/beans.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | -------------------------------------------------------------------------------- /snoop/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension: -------------------------------------------------------------------------------- 1 | eu.agilejava.snoop.scan.SnoopScannerExtension --------------------------------------------------------------------------------