From e88fa78b83745b2043942f6f5683f2c2e3ebc634 Mon Sep 17 00:00:00 2001 From: Shay Tsadok Date: Sun, 26 Jul 2015 10:37:59 +0300 Subject: [PATCH] delete content in order to do pull request code review in github --- Dockerfile | 6 - Dockerfile.build | 20 -- Dockerfile.build.proxy | 20 -- README.md | 39 ---- circle.yml | 29 --- logs/placeholder.txt | 0 pom.xml | 149 --------------- .../com/hp/gaia/mgs/amqp/AmqpManager.java | 63 ------- .../java/com/hp/gaia/mgs/dto/BaseEvent.java | 77 -------- .../gaia/mgs/dto/CommonDeserializerUtils.java | 68 ------- .../mgs/dto/InfluxLineProtocolConverter.java | 31 ---- .../InfluxLineProtocolConverterFactory.java | 26 --- .../gaia/mgs/dto/MainEventDeserializer.java | 80 -------- .../java/com/hp/gaia/mgs/dto/OldEvent.java | 26 --- .../hp/gaia/mgs/dto/OldEventsConverter.java | 22 --- .../com/hp/gaia/mgs/dto/OldMeasurement.java | 28 --- .../java/com/hp/gaia/mgs/dto/OldMetric.java | 85 --------- .../dto/change/IssueChangeDeserializer.java | 88 --------- .../gaia/mgs/dto/change/IssueChangeEvent.java | 43 ----- .../IssueChangeToInfluxLineProtocol.java | 75 -------- .../hp/gaia/mgs/dto/change/IssueField.java | 62 ------- .../gaia/mgs/dto/testrun/AlmTestRunEvent.java | 33 ---- .../mgs/dto/testrun/AlmTestRunResult.java | 26 --- .../mgs/dto/testrun/CodeTestRunEvent.java | 28 --- .../mgs/dto/testrun/TestRunDeserializer.java | 108 ----------- .../hp/gaia/mgs/dto/testrun/TestRunEvent.java | 15 -- .../gaia/mgs/dto/testrun/TestRunResult.java | 48 ----- .../testrun/TestRunToInfluxLineProtocol.java | 101 ---------- .../mgs/rest/MeasurementGatewayResource.java | 175 ------------------ .../hp/gaia/mgs/rest/MonitoringResource.java | 77 -------- .../hp/gaia/mgs/rest/filters/InputFilter.java | 45 ----- .../mgs/services/MetricsCollectorService.java | 128 ------------- .../gaia/mgs/services/MonitoringService.java | 42 ----- .../mgs/services/PropertiesKeeperService.java | 41 ---- .../spring/CustomResponseErrorHandler.java | 31 ---- .../hp/gaia/mgs/spring/DefaultController.java | 18 -- .../MultiTenantAccessTokenConverter.java | 24 --- .../MultiTenantOAuth2Authentication.java | 31 ---- .../hp/gaia/mgs/spring/MyCustomException.java | 44 ----- .../webapp/WEB-INF/classes/default.properties | 8 - src/main/webapp/WEB-INF/classes/logback.xml | 84 --------- src/main/webapp/WEB-INF/spring-security.xml | 54 ------ src/main/webapp/WEB-INF/spring-servlet.xml | 32 ---- src/main/webapp/WEB-INF/web.xml | 79 -------- src/main/webapp/index.jsp | 5 - .../hp/gaia/mgs/dto/MainEventParserTest.java | 78 -------- .../change/IssueChangeEventParserTest.java | 33 ---- .../dto/testrun/TestRunEventParserTest.java | 39 ---- .../services/MetricsCollectorServiceTest.java | 78 -------- src/test/resources/default.properties | 8 - 50 files changed, 2550 deletions(-) delete mode 100644 Dockerfile delete mode 100644 Dockerfile.build delete mode 100644 Dockerfile.build.proxy delete mode 100644 README.md delete mode 100644 circle.yml delete mode 100644 logs/placeholder.txt delete mode 100644 pom.xml delete mode 100644 src/main/java/com/hp/gaia/mgs/amqp/AmqpManager.java delete mode 100644 src/main/java/com/hp/gaia/mgs/dto/BaseEvent.java delete mode 100644 src/main/java/com/hp/gaia/mgs/dto/CommonDeserializerUtils.java delete mode 100644 src/main/java/com/hp/gaia/mgs/dto/InfluxLineProtocolConverter.java delete mode 100644 src/main/java/com/hp/gaia/mgs/dto/InfluxLineProtocolConverterFactory.java delete mode 100644 src/main/java/com/hp/gaia/mgs/dto/MainEventDeserializer.java delete mode 100644 src/main/java/com/hp/gaia/mgs/dto/OldEvent.java delete mode 100644 src/main/java/com/hp/gaia/mgs/dto/OldEventsConverter.java delete mode 100644 src/main/java/com/hp/gaia/mgs/dto/OldMeasurement.java delete mode 100644 src/main/java/com/hp/gaia/mgs/dto/OldMetric.java delete mode 100644 src/main/java/com/hp/gaia/mgs/dto/change/IssueChangeDeserializer.java delete mode 100644 src/main/java/com/hp/gaia/mgs/dto/change/IssueChangeEvent.java delete mode 100644 src/main/java/com/hp/gaia/mgs/dto/change/IssueChangeToInfluxLineProtocol.java delete mode 100644 src/main/java/com/hp/gaia/mgs/dto/change/IssueField.java delete mode 100644 src/main/java/com/hp/gaia/mgs/dto/testrun/AlmTestRunEvent.java delete mode 100644 src/main/java/com/hp/gaia/mgs/dto/testrun/AlmTestRunResult.java delete mode 100644 src/main/java/com/hp/gaia/mgs/dto/testrun/CodeTestRunEvent.java delete mode 100644 src/main/java/com/hp/gaia/mgs/dto/testrun/TestRunDeserializer.java delete mode 100644 src/main/java/com/hp/gaia/mgs/dto/testrun/TestRunEvent.java delete mode 100644 src/main/java/com/hp/gaia/mgs/dto/testrun/TestRunResult.java delete mode 100644 src/main/java/com/hp/gaia/mgs/dto/testrun/TestRunToInfluxLineProtocol.java delete mode 100644 src/main/java/com/hp/gaia/mgs/rest/MeasurementGatewayResource.java delete mode 100644 src/main/java/com/hp/gaia/mgs/rest/MonitoringResource.java delete mode 100644 src/main/java/com/hp/gaia/mgs/rest/filters/InputFilter.java delete mode 100644 src/main/java/com/hp/gaia/mgs/services/MetricsCollectorService.java delete mode 100644 src/main/java/com/hp/gaia/mgs/services/MonitoringService.java delete mode 100644 src/main/java/com/hp/gaia/mgs/services/PropertiesKeeperService.java delete mode 100644 src/main/java/com/hp/gaia/mgs/spring/CustomResponseErrorHandler.java delete mode 100644 src/main/java/com/hp/gaia/mgs/spring/DefaultController.java delete mode 100644 src/main/java/com/hp/gaia/mgs/spring/MultiTenantAccessTokenConverter.java delete mode 100644 src/main/java/com/hp/gaia/mgs/spring/MultiTenantOAuth2Authentication.java delete mode 100644 src/main/java/com/hp/gaia/mgs/spring/MyCustomException.java delete mode 100644 src/main/webapp/WEB-INF/classes/default.properties delete mode 100644 src/main/webapp/WEB-INF/classes/logback.xml delete mode 100644 src/main/webapp/WEB-INF/spring-security.xml delete mode 100644 src/main/webapp/WEB-INF/spring-servlet.xml delete mode 100644 src/main/webapp/WEB-INF/web.xml delete mode 100644 src/main/webapp/index.jsp delete mode 100644 src/test/java/com/hp/gaia/mgs/dto/MainEventParserTest.java delete mode 100644 src/test/java/com/hp/gaia/mgs/dto/change/IssueChangeEventParserTest.java delete mode 100644 src/test/java/com/hp/gaia/mgs/dto/testrun/TestRunEventParserTest.java delete mode 100644 src/test/java/com/hp/gaia/mgs/services/MetricsCollectorServiceTest.java delete mode 100644 src/test/resources/default.properties diff --git a/Dockerfile b/Dockerfile deleted file mode 100644 index 017a302..0000000 --- a/Dockerfile +++ /dev/null @@ -1,6 +0,0 @@ -FROM jetty:9.3.0-jre8 - -# DB is created under home directory of user jetty that must be created -RUN mkdir -p /home/jetty && chown jetty:jetty /home/jetty - -COPY ./target/*.war $JETTY_BASE/webapps/ diff --git a/Dockerfile.build b/Dockerfile.build deleted file mode 100644 index 918dffc..0000000 --- a/Dockerfile.build +++ /dev/null @@ -1,20 +0,0 @@ -FROM maven:3.3.3-jdk-8 - -ENV GAIA_HOME=/usr/local/gaia/ - -RUN mkdir -p $GAIA_HOME -WORKDIR $GAIA_HOME - -# speedup maven build, read https://keyholesoftware.com/2015/01/05/caching-for-maven-docker-builds/ - -# selectively add the POM file -ADD pom.xml $GAIA_HOME - -# get all the downloads out of the way -RUN ["mvn","verify","clean","--fail-never"] - -# add source -ADD . $GAIA_HOME - -# run maven verify -RUN ["mvn","verify"] diff --git a/Dockerfile.build.proxy b/Dockerfile.build.proxy deleted file mode 100644 index 9ce22bc..0000000 --- a/Dockerfile.build.proxy +++ /dev/null @@ -1,20 +0,0 @@ -FROM maven:3.3.3-jdk-8 - -ENV GAIA_HOME=/usr/local/gaia/ - -RUN mkdir -p $GAIA_HOME -WORKDIR $GAIA_HOME - -# speedup maven build, read https://keyholesoftware.com/2015/01/05/caching-for-maven-docker-builds/ - -# selectively add the POM file -ADD pom.xml $GAIA_HOME - -# get all the downloads out of the way -RUN ["mvn","-DuseProxy=true","-DproxyHost=web-proxy.israel.hp.com","-DproxyPort=8080","verify","clean","--fail-never"] - -# add source -ADD . $GAIA_HOME - -# run maven verify -RUN ["mvn","-DuseProxy=true","-DproxyHost=web-proxy.israel.hp.com","-DproxyPort=8080","verify"] diff --git a/README.md b/README.md deleted file mode 100644 index 2bc77c2..0000000 --- a/README.md +++ /dev/null @@ -1,39 +0,0 @@ -CircleCI build status: [![Circle CI](https://circleci.com/gh/gaia-adm/metrics-gateway-service.svg?style=svg)](https://circleci.com/gh/gaia-adm/metrics-gateway-service) -# metrics-gateway-service -Temporary metrics-gateway-service based on jax-rs and jersey with async I/O -This implementation is temporary, can be moved to another platform if we discover it is not robust and scalable enough -This implementation uses spring-security based authz server. Oltu build-in version is available in with_oltu branch - -How to run locally: build a war and put it on Jetty (tested with Jetty 9.2) or run mnn jetty:run - -Functionality: -- Accept metrics publishing and store it into logs/metrics-storage.log. Only metric name stored to the file. -- Publish API requires authorization token -- Monitor memory and number of threads consumed by this service - -Prerequisites: -- Authorization server (https://github.com/gaia-adm/auth-server) must be running in order to allow publishing -- (Optional) RabbitMQ - -Customization (-D parameters) - based on default.properties file. For example, -- Authorization server: -DauthServer=name:port. Defalut is localhot:9001 -- Output to log file (metrics-storage.log) or to RabbitMQ: -DuseAmqp=true/false. Default is false (print to log file) -- RabbitMQ parameters: host, port, user, password, routing key: -DamqpHost, -DamqpPort, -DamqpUser, -DamqpPassword, -DamqpRoutingKey. Defaults are localhost, 5672, admin, "", events-indexer - -API: -- Publish metrics - - URL: /mgs/rest/v1/gateway/publish3 - - Method: POST - - Headers: Authorization: Bearer - - Response code: 201 - - Body: my_metric,host=server02,region=us-east value=0.97 - -- Start/Stop monitoring memory and thread count every 1 second - - URL: /mgs/rest/monitor/action/{action} - - Method: GET - - Headers: Content-Type: application/json, Accept: application/json - - Response code: 200 - - Parameters: - - action: String; on - start monitoring, off - stop monitoring - -Please refer https://github.com/gaia-adm/security-token-service in order to obtain token diff --git a/circle.yml b/circle.yml deleted file mode 100644 index 2bed7dc..0000000 --- a/circle.yml +++ /dev/null @@ -1,29 +0,0 @@ -machine: - services: - - docker -dependencies: - override: - - cp Dockerfile Dockerfile.run - - cp Dockerfile.build Dockerfile - - docker build -t build-img . - - docker create --name build-cont build-img - - docker cp build-cont:/usr/local/gaia/target/mgs.war ./target/mgs.war - - cp Dockerfile.run Dockerfile - - docker build -t gaiaadm/mgs . -test: - override: - - docker run -d -p 9002:8080 gaiaadm/mgs:$BUILD_TAG; sleep 10 -# docker run -d --link sts:sts -e useAmqp=true -e authServer=sts:8080 -p 9002:8080 --name mgs gaiaadm/mgs - - curl -i http://localhost:9002/mgs/ | grep "200 OK" -deployment: - hub: - branch: master - commands: - - docker login -e $DOCKER_EMAIL -u $DOCKER_USER -p $DOCKER_PASS - - docker push gaiaadm/mgs -general: - branches: - only: - - master - artifacts: - - target/mgs.war diff --git a/logs/placeholder.txt b/logs/placeholder.txt deleted file mode 100644 index e69de29..0000000 diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 48f5cf3..0000000 --- a/pom.xml +++ /dev/null @@ -1,149 +0,0 @@ - - - 4.0.0 - - com.hp.gaia - metrics-gateway-service - 1.0-SNAPSHOT - - war - - mgs - - - - - - - - javax.servlet - javax.servlet-api - 3.1.0 - - - javax.ws.rs - javax.ws.rs-api - 2.0.1 - - - - - org.glassfish.jersey.containers - jersey-container-servlet-core - 2.17 - - - org.glassfish.jersey.containers - jersey-container-servlet - 2.17 - - - org.glassfish.jersey.media - jersey-media-json-jackson - 2.17 - - - org.codehaus.jackson - jackson-jaxrs - 1.9.12 - - - commons-io - commons-io - 2.4 - - - - - com.rabbitmq - amqp-client - 3.5.3 - - - - - junit - junit - 4.11 - test - - - org.mockito - mockito-all - 1.10.19 - test - - - - - org.slf4j - slf4j-api - 1.7.12 - - - ch.qos.logback - logback-classic - 1.1.3 - - - ch.qos.logback - logback-core - 1.1.3 - - - - - org.springframework.security - spring-security-web - 4.0.1.RELEASE - - - org.springframework.security - spring-security-config - 4.0.1.RELEASE - - - commons-logging - commons-logging - 1.2 - - - org.springframework.security.oauth - spring-security-oauth2 - 2.0.7.RELEASE - - - - - - ${final.name} - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.2 - - 1.8 - 1.8 - - - - org.eclipse.jetty - jetty-maven-plugin - 9.2.11.v20150529 - - - 9002 - - - /${final.name} - - - - - - - \ No newline at end of file diff --git a/src/main/java/com/hp/gaia/mgs/amqp/AmqpManager.java b/src/main/java/com/hp/gaia/mgs/amqp/AmqpManager.java deleted file mode 100644 index ae123dc..0000000 --- a/src/main/java/com/hp/gaia/mgs/amqp/AmqpManager.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.hp.gaia.mgs.amqp; - -import com.hp.gaia.mgs.services.PropertiesKeeperService; -import com.rabbitmq.client.Channel; -import com.rabbitmq.client.Connection; -import com.rabbitmq.client.ConnectionFactory; - -import java.io.IOException; -import java.util.concurrent.TimeoutException; - -/** - * Created by belozovs on 6/30/2015. - * Manage RabbitMQ connection for publish metrics - */ - -public class AmqpManager { - - private static String MQ_SERVER_NAME, MQ_SERVER_USERNAME, MQ_SERVER_PASSWORD, QUEUE_NAME; - private static Integer MQ_SERVER_PORT; - - private Channel channel = null; - - public AmqpManager() throws IOException { - MQ_SERVER_NAME = PropertiesKeeperService.getInstance().getEnvOrPropAsString("amqpHost"); - MQ_SERVER_PORT = Integer.parseInt(PropertiesKeeperService.getInstance().getEnvOrPropAsString("amqpPort")); - MQ_SERVER_USERNAME = PropertiesKeeperService.getInstance().getEnvOrPropAsString("amqpUser"); - MQ_SERVER_PASSWORD = PropertiesKeeperService.getInstance().getEnvOrPropAsString("amqpPassword"); - QUEUE_NAME = PropertiesKeeperService.getInstance().getEnvOrPropAsString("amqpRoutingKey"); - - System.out.println("MQ details: " + MQ_SERVER_NAME + ":" + MQ_SERVER_PORT + ":" + QUEUE_NAME); - - } - - public Channel getChannel() throws IOException, TimeoutException { - if (channel == null) { - ConnectionFactory factory = createConnectionFactory(); - Connection connection = factory.newConnection(); - channel = connection.createChannel(); - channel.queueDeclare(QUEUE_NAME, true, false, false, null); //durable, non-exclusive, no auto-delete - } - return channel; - } - - public String getQueueName() { - return QUEUE_NAME; - } - - private ConnectionFactory createConnectionFactory() { - ConnectionFactory factory = new ConnectionFactory(); - factory.setHost(MQ_SERVER_NAME); - factory.setPort(MQ_SERVER_PORT); - factory.setUsername(MQ_SERVER_USERNAME); - factory.setPassword(MQ_SERVER_PASSWORD); - - factory.setAutomaticRecoveryEnabled(true); // connection that will recover automatically - factory.setNetworkRecoveryInterval(10000); // attempt recovery to the max of 10 seconds - factory.setRequestedHeartbeat(30); // Setting heartbeat to 30 sec instead the default of 10 min - - return factory; - } - - -} diff --git a/src/main/java/com/hp/gaia/mgs/dto/BaseEvent.java b/src/main/java/com/hp/gaia/mgs/dto/BaseEvent.java deleted file mode 100644 index 6710de8..0000000 --- a/src/main/java/com/hp/gaia/mgs/dto/BaseEvent.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.hp.gaia.mgs.dto; - -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - -import java.util.Date; -import java.util.HashMap; -import java.util.Map; - -/** - * Created by belozovs on 7/15/2015. - * - * Base class for all kinds of events - * - */ -@JsonDeserialize(using = MainEventDeserializer.class) -public class BaseEvent { - - //EVENT_TYPE is not used here directly but needed for using with generic code - @SuppressWarnings("unused") - public static String EVENT_TYPE; - - @JsonProperty("event") - String type; - Date time; - Map id; - Map source; - Map tags; - - public BaseEvent() { - - source = new HashMap<>(); - tags = new HashMap<>(); - id = new HashMap<>(); - - } - - public String getType() { - return type; - } - - public Date getTime() { - return time; - } - - public void setTime(Date time) { - this.time = time; - } - - public void setType(String type) { - this.type = type; - } - - public Map getId() { - return id; - } - - public void setId(Map id) { - this.id = id; - } - - public Map getSource() { - return source; - } - - public void setSource(Map source) { - this.source = source; - } - - public Map getTags() { - return tags; - } - - public void setTags(Map tags) { - this.tags = tags; - } -} diff --git a/src/main/java/com/hp/gaia/mgs/dto/CommonDeserializerUtils.java b/src/main/java/com/hp/gaia/mgs/dto/CommonDeserializerUtils.java deleted file mode 100644 index c8ecb3b..0000000 --- a/src/main/java/com/hp/gaia/mgs/dto/CommonDeserializerUtils.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.hp.gaia.mgs.dto; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.hp.gaia.mgs.dto.change.IssueChangeEvent; -import com.hp.gaia.mgs.dto.testrun.AlmTestRunEvent; -import com.hp.gaia.mgs.dto.testrun.CodeTestRunEvent; - -import java.io.IOException; -import java.util.Iterator; -import java.util.Map; - -/** - * Created by belozovs on 7/16/2015. - * - * Utilities methods that can be useful for multiple types deserialization - */ - - -public interface CommonDeserializerUtils { - - /** - * Fill a map with data from mapType element of json node - */ - default int fillMap(Map map, String mapType, JsonNode node){ - - if(node.get(mapType) != null) { - Iterator> fields = node.get(mapType).fields(); - while (fields.hasNext()) { - Map.Entry field = fields.next(); - map.put(field.getKey(), field.getValue().asText()); - } - } - return map.size(); - } - - - /** - * Deserialize event with custom deserializer - * Custom deserializer is selected based on the event type its type - * If no valid event type found, exception thrown - * - * @param point json for deserialization - * @param pointType type to use for deserialization - * @return event of one of the types extending BaseEvent - * @throws IOException in case of deserialization problem - */ - default BaseEvent deserializeEvent(JsonNode point, String pointType) throws IOException { - - BaseEvent nextEvent; - switch (pointType) { - case IssueChangeEvent.EVENT_TYPE: - nextEvent = new ObjectMapper().readValue(point.toString(), IssueChangeEvent.class); - break; - case AlmTestRunEvent.EVENT_TYPE: - nextEvent = new ObjectMapper().readValue(point.toString(), AlmTestRunEvent.class); - break; - case CodeTestRunEvent.EVENT_TYPE: - nextEvent = new ObjectMapper().readValue(point.toString(), CodeTestRunEvent.class); - break; - default: - System.out.println("No valid event type found: " + pointType); - throw new RuntimeException("No valid event type provided: " + pointType); - } - return nextEvent; - } - -} diff --git a/src/main/java/com/hp/gaia/mgs/dto/InfluxLineProtocolConverter.java b/src/main/java/com/hp/gaia/mgs/dto/InfluxLineProtocolConverter.java deleted file mode 100644 index 8afa65d..0000000 --- a/src/main/java/com/hp/gaia/mgs/dto/InfluxLineProtocolConverter.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.hp.gaia.mgs.dto; - -/** - * Created by belozovs on 7/22/2015. - * Interface for converting event to InfluxDB 0.9 line protocol format - */ -public interface InfluxLineProtocolConverter { - - String convert(T event); - - /** - * Following characters must be escaped for InfluxDB: spaces, commas and double-quotes - * - * @param str String to replace spaces, commas and double-quotes - * @return String after the replacement - */ - default String getEscapedString(String str) { - return str.replace("\"", "\\\"").replace(" ", "\\ ").replace(",", "\\,"); - } - - /** - * String values must be double-quoted when inserting to InfluxDB - * - * @param str String value to be double-quoated - * @return double-quoted value - */ - default String getQuotedValue(String str) { - return "\"" + str + "\""; - } - -} diff --git a/src/main/java/com/hp/gaia/mgs/dto/InfluxLineProtocolConverterFactory.java b/src/main/java/com/hp/gaia/mgs/dto/InfluxLineProtocolConverterFactory.java deleted file mode 100644 index 1add38c..0000000 --- a/src/main/java/com/hp/gaia/mgs/dto/InfluxLineProtocolConverterFactory.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.hp.gaia.mgs.dto; - -import com.hp.gaia.mgs.dto.change.IssueChangeEvent; -import com.hp.gaia.mgs.dto.change.IssueChangeToInfluxLineProtocol; -import com.hp.gaia.mgs.dto.testrun.*; - -/** - * Created by belozovs on 7/23/2015. - * Create correct event converter and run it - */ -public class InfluxLineProtocolConverterFactory { - - public InfluxLineProtocolConverter getConverter(String type){ - if(type.equals(IssueChangeEvent.EVENT_TYPE)){ - return new IssueChangeToInfluxLineProtocol(); - } - if(type.equals(CodeTestRunEvent.EVENT_TYPE)){ - return new TestRunToInfluxLineProtocol(); - } - if (type.equals(AlmTestRunEvent.EVENT_TYPE)){ - return new TestRunToInfluxLineProtocol(); - } - throw new RuntimeException("OldEvent type not supported: " + type); - } - -} diff --git a/src/main/java/com/hp/gaia/mgs/dto/MainEventDeserializer.java b/src/main/java/com/hp/gaia/mgs/dto/MainEventDeserializer.java deleted file mode 100644 index b0ef2c0..0000000 --- a/src/main/java/com/hp/gaia/mgs/dto/MainEventDeserializer.java +++ /dev/null @@ -1,80 +0,0 @@ -package com.hp.gaia.mgs.dto; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.*; -import jersey.repackaged.com.google.common.collect.Lists; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -/** - * Created by belozovs on 7/16/2015. - * - * Strict common/point level separation - if common field presented, it is ignored on point level EXCEPTING event type - * - */ -public class MainEventDeserializer extends JsonDeserializer> implements CommonDeserializerUtils { - - @Override - public List deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { - - JsonNode node = jp.getCodec().readTree(jp); - BaseEvent commonPart = new BaseEvent(); - List events = new ArrayList<>(); - - //get points for further usage or fail immediately, if no points provided - List points = Lists.newArrayList(node.get("points")); - if(points.isEmpty()){ - throw new RuntimeException("No events provided"); - } - - if(node.get("id") != null){ - fillMap(commonPart.getId(), "id", node); - } - if(node.get("source") != null){ - fillMap(commonPart.getSource(), "source", node); - } - if(node.get("tags") != null){ - fillMap(commonPart.getTags(), "tags", node); - } - if(node.get("time") != null) { - commonPart.setTime(javax.xml.bind.DatatypeConverter.parseDateTime(node.get("time").asText()).getTime()); - } - if(node.get("event") != null){ - commonPart.setType(node.get("event").asText()); - } - - for (JsonNode point : points) { - - //for each point, the event type can be different, so we should check it - String pointType = (point.get("event") != null) ? point.get("event").asText() : commonPart.getType(); - //deserialization - BaseEvent nextEvent = deserializeEvent(point, pointType); - //Enrich event with "common" data (common for all events in the request), if relevant section inside the event is empty - if (nextEvent != null) { - if (nextEvent.getSource().isEmpty()) { - nextEvent.setSource(commonPart.getSource()); - } - if (nextEvent.getTags().isEmpty()) { - nextEvent.setTags(commonPart.getTags()); - } - if (nextEvent.getId().isEmpty()) { - nextEvent.setId(commonPart.getId()); - } - if (nextEvent.getTime() == null) { - nextEvent.setTime(commonPart.getTime()); - } - if (nextEvent.getType() == null) { - nextEvent.setType(pointType); - } - events.add(nextEvent); - } - - } - - return events; - } - - -} diff --git a/src/main/java/com/hp/gaia/mgs/dto/OldEvent.java b/src/main/java/com/hp/gaia/mgs/dto/OldEvent.java deleted file mode 100644 index c59879c..0000000 --- a/src/main/java/com/hp/gaia/mgs/dto/OldEvent.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.hp.gaia.mgs.dto; - -/** - * Created by belozovs on 5/27/2015. - */ -public class OldEvent { - - String name; - String value; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } -} diff --git a/src/main/java/com/hp/gaia/mgs/dto/OldEventsConverter.java b/src/main/java/com/hp/gaia/mgs/dto/OldEventsConverter.java deleted file mode 100644 index 71ff1c1..0000000 --- a/src/main/java/com/hp/gaia/mgs/dto/OldEventsConverter.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.hp.gaia.mgs.dto; - -/** - * Created by belozovs on 7/19/2015. - */ -public class OldEventsConverter { - - public static T convert(Object from, Class to){ - - if(from == null){ - throw new RuntimeException("from object is null"); - } - - if(to.isAssignableFrom(from.getClass())){ - return (T) to.cast(from); - } else { - throw new RuntimeException("Cannot convert " + from.getClass().getName() + "to " + to.getName()); - } - - } - -} diff --git a/src/main/java/com/hp/gaia/mgs/dto/OldMeasurement.java b/src/main/java/com/hp/gaia/mgs/dto/OldMeasurement.java deleted file mode 100644 index 871076c..0000000 --- a/src/main/java/com/hp/gaia/mgs/dto/OldMeasurement.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.hp.gaia.mgs.dto; - -/** - * Created by belozovs on 5/27/2015. - */ -public class OldMeasurement { - - String name; - Double value; - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - - - public Double getValue() { - return value; - } - - public void setValue(Double value) { - this.value = value; - } -} diff --git a/src/main/java/com/hp/gaia/mgs/dto/OldMetric.java b/src/main/java/com/hp/gaia/mgs/dto/OldMetric.java deleted file mode 100644 index 7701b96..0000000 --- a/src/main/java/com/hp/gaia/mgs/dto/OldMetric.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.hp.gaia.mgs.dto; - -import java.util.ArrayList; -import java.util.List; - -/** - * Created by belozovs on 5/27/2015. - */ - - -public class OldMetric { - - String metric; - String category; - String name; - String source; - Long timestamp; - List tags = new ArrayList<>(); - List measurements = new ArrayList<>(); - List events = new ArrayList<>(); - - public String getMetric() { - return metric; - } - - public void setMetric(String metric) { - this.metric = metric; - } - - public String getCategory() { - return category; - } - - public void setCategory(String category) { - this.category = category; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getSource() { - return source; - } - - public void setSource(String source) { - this.source = source; - } - - public Long getTimestamp() { - return timestamp; - } - - public void setTimestamp(Long timestamp) { - this.timestamp = timestamp; - } - - public List getTags() { - return tags; - } - - public void setTags(List tags) { - this.tags = tags; - } - - public List getMeasurements() { - return measurements; - } - - public void setMeasurements(List measurements) { - this.measurements = measurements; - } - - public List getEvents() { - return events; - } - - public void setEvents(List events) { - this.events = events; - } -} diff --git a/src/main/java/com/hp/gaia/mgs/dto/change/IssueChangeDeserializer.java b/src/main/java/com/hp/gaia/mgs/dto/change/IssueChangeDeserializer.java deleted file mode 100644 index 084064d..0000000 --- a/src/main/java/com/hp/gaia/mgs/dto/change/IssueChangeDeserializer.java +++ /dev/null @@ -1,88 +0,0 @@ -package com.hp.gaia.mgs.dto.change; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonNode; -import com.hp.gaia.mgs.dto.CommonDeserializerUtils; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.util.StringUtils; - -import java.io.IOException; -import java.util.Date; -import java.util.Iterator; - -/** - * Created by belozovs on 7/15/2015. - * IssueChange event deserializer - */ -public class IssueChangeDeserializer extends JsonDeserializer implements CommonDeserializerUtils { - - Logger logger = LoggerFactory.getLogger(IssueChangeDeserializer.class); - //TODO - Boris: comments support - @Override - public IssueChangeEvent deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { - - JsonNode node = jp.getCodec().readTree(jp); - - IssueChangeEvent ice = new IssueChangeEvent(); - - Iterator fieldNodes = node.get("fields").elements(); - - while (fieldNodes.hasNext()) { - JsonNode fieldNode = fieldNodes.next(); - ice.addField(fetchIssueField(fieldNode)); - } - - fillMap(ice.getId(), "id", node); - fillMap(ice.getSource(), "source", node); - fillMap(ice.getTags(), "tags", node); - - - if (node.get("time") != null) { - ice.setTime(javax.xml.bind.DatatypeConverter.parseDateTime(node.get("time").asText()).getTime()); - } else { - ice.setTime(new Date()); - } - - return ice; - } - - private IssueField fetchIssueField(JsonNode fieldNode) { - Iterator subfieldNames = fieldNode.fieldNames(); - JsonNode fieldNameNode = fieldNode.get("name"); - if (fieldNameNode == null) { - return null; - } - IssueField issueField = new IssueField(fieldNameNode.asText()); - - while (subfieldNames.hasNext()) { - String curSubFieldName = subfieldNames.next(); - switch (curSubFieldName.toLowerCase()) { - case "name": - break; - case "to": - issueField.setTo(fieldNode.get(curSubFieldName).asText()); - break; - case "from": - issueField.setFrom(fieldNode.get(curSubFieldName).asText()); - break; - case "ttc": - issueField.setTtc(fieldNode.get(curSubFieldName).asLong()); - break; - default: - issueField.addCustomField(curSubFieldName, fieldNode.get(curSubFieldName).asText()); - break; - } - } - - if(StringUtils.isEmpty(issueField.getName()) || StringUtils.isEmpty(issueField.getTo())){ - logger.error("Empty data provided for field 'name' or 'to' attribute: {}", fieldNode); - throw new RuntimeException("Incomplete data provided: 'name' and 'to' attributes are mandatory for all fields"); - } - - return issueField; - } - -} diff --git a/src/main/java/com/hp/gaia/mgs/dto/change/IssueChangeEvent.java b/src/main/java/com/hp/gaia/mgs/dto/change/IssueChangeEvent.java deleted file mode 100644 index 37acda9..0000000 --- a/src/main/java/com/hp/gaia/mgs/dto/change/IssueChangeEvent.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.hp.gaia.mgs.dto.change; - -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.hp.gaia.mgs.dto.BaseEvent; - -import javax.validation.constraints.NotNull; -import java.util.ArrayList; -import java.util.List; - -/** - * Created by belozovs on 7/15/2015. - *

- * No support for comments - */ - -@JsonDeserialize(using = IssueChangeDeserializer.class) -public class IssueChangeEvent extends BaseEvent { - - public final static String EVENT_TYPE = "issue_change"; - - @NotNull - List fields; - - public IssueChangeEvent() { - this.setType(EVENT_TYPE); - fields = new ArrayList<>(); - } - - public List getFields() { - return fields; - } - - @SuppressWarnings("unused") - public void setFields(List fields) { - this.fields = fields; - } - - public void addField(IssueField field) { - this.fields.add(field); - } - -} - diff --git a/src/main/java/com/hp/gaia/mgs/dto/change/IssueChangeToInfluxLineProtocol.java b/src/main/java/com/hp/gaia/mgs/dto/change/IssueChangeToInfluxLineProtocol.java deleted file mode 100644 index 23d42dc..0000000 --- a/src/main/java/com/hp/gaia/mgs/dto/change/IssueChangeToInfluxLineProtocol.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.hp.gaia.mgs.dto.change; - - -import com.hp.gaia.mgs.dto.InfluxLineProtocolConverter; - -/** - * Created by belozovs on 7/22/2015. - * Convert IssueChangeEvent object to input data for InfluxDB 0.9 - */ -public class IssueChangeToInfluxLineProtocol implements InfluxLineProtocolConverter { - - - /** - * Convert IssueChangeEvent to string compatible with InfluxDB 0.9 line protocol - * For each field separate line create with all its attributes as values and field name as a tag (beside other tags and source) - * Example of the output (single row): - * issue_change,server=http://alm-saas.hp.com,domain=IT,project=Project\ A,workspace=CRM,user=bob,field=Status id_uid="1111",to="Open",from="New",ttc=124 1437595557534000000 - * @param event event to be converted - * @return row to be inserted to InfluxDB - * - */ - @Override - public String convert(IssueChangeEvent event) { - - StringBuilder mainSb = new StringBuilder(); - for (IssueField field : event.getFields()) { - //create measurement and tags (tags, source and field name) - mainSb.append(getEscapedString(event.getType())); - for (String key : event.getSource().keySet()) { - mainSb.append(",").append(getEscapedString(key)).append("=").append(getEscapedString(event.getSource().get(key))); - } - for (String key : event.getTags().keySet()) { - mainSb.append(",").append(getEscapedString(key)).append("=").append(getEscapedString(event.getTags().get(key))); - } - mainSb.append(",").append("field").append("=").append(getEscapedString(field.getName())); - - //separator between measurement+tags and data part of the string - mainSb.append(" "); - //create data part - //id and values (fields, result, etc.) - for (String key : event.getId().keySet()) { - //note: id value is always String and should be quoted - mainSb.append("id_").append(getEscapedString(key)).append("=").append(getQuotedValue(event.getId().get(key))).append(","); - } - - mainSb.append("to=").append(getQuotedValue(field.getTo())).append(","); - if (field.getFrom() != null) { - mainSb.append("from=").append(getQuotedValue(field.getFrom())).append(","); - } - if (field.getTtc() != null) { - mainSb.append("ttc=").append(field.getTtc()).append(","); - } - if (field.getCustomFields() != null) { - for (String key : field.getCustomFields().keySet()) { - mainSb.append(getEscapedString(key)).append("=").append(getQuotedValue(field.getCustomFields().get(key))).append(","); - } - } - if (mainSb.length() > 0 && mainSb.charAt(mainSb.length() - 1) == ',') { - mainSb.setLength(mainSb.length() - 1); - } - //add timestamp - //TBD - boris: make InfluxDBManager in event-indexer adding &precision=ms query param to "writeToDB" URL and remove 1000000 from here - mainSb.append(" ").append(event.getTime().getTime() * 1000000); //switch to nanoseconds, as InfluxDB requires - - //prepare to the next row insert - mainSb.append(System.lineSeparator()); - } - - - return mainSb.toString(); - - } - - -} diff --git a/src/main/java/com/hp/gaia/mgs/dto/change/IssueField.java b/src/main/java/com/hp/gaia/mgs/dto/change/IssueField.java deleted file mode 100644 index 8742581..0000000 --- a/src/main/java/com/hp/gaia/mgs/dto/change/IssueField.java +++ /dev/null @@ -1,62 +0,0 @@ -package com.hp.gaia.mgs.dto.change; - -import java.util.HashMap; -import java.util.Map; - -/** - * Created by belozovs on 7/16/2015. - * Field of IssueChangeEvent - */ -public class IssueField { - - String name; - String to; - String from; - Long ttc; - Map customFields = new HashMap<>(); - - public IssueField(String name) { - this.name = name; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getTo() { - return to; - } - - public void setTo(String to) { - this.to = to; - } - - public String getFrom() { - return from; - } - - public void setFrom(String from) { - this.from = from; - } - - public Long getTtc() { - return ttc; - } - - public void setTtc(Long ttc) { - this.ttc = ttc; - } - - public Map getCustomFields() { - return customFields; - } - - public void addCustomField(String name, String value) { - customFields.put(name, value); - } - -} diff --git a/src/main/java/com/hp/gaia/mgs/dto/testrun/AlmTestRunEvent.java b/src/main/java/com/hp/gaia/mgs/dto/testrun/AlmTestRunEvent.java deleted file mode 100644 index 29ea3bf..0000000 --- a/src/main/java/com/hp/gaia/mgs/dto/testrun/AlmTestRunEvent.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.hp.gaia.mgs.dto.testrun; - -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - -/** - * Created by belozovs on 7/16/2015. - * Version of TestRunEvent for ALM (manual test) - * Main differentiators: EVENT_TYPE and {@link AlmTestRunResult} - */ -@JsonDeserialize(using = TestRunDeserializer.class) -public class AlmTestRunEvent extends TestRunEvent { - - public final static String EVENT_TYPE = "tm_testrun"; - - AlmTestRunResult result; - - public AlmTestRunEvent() { - this.setType(EVENT_TYPE); - } - - @SuppressWarnings("unchecked") - @Override - public AlmTestRunResult getResult() { - return result; - } - - @Override - public void setResult(T result) { - this.result = (AlmTestRunResult) result; - } - - -} diff --git a/src/main/java/com/hp/gaia/mgs/dto/testrun/AlmTestRunResult.java b/src/main/java/com/hp/gaia/mgs/dto/testrun/AlmTestRunResult.java deleted file mode 100644 index ce7440b..0000000 --- a/src/main/java/com/hp/gaia/mgs/dto/testrun/AlmTestRunResult.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.hp.gaia.mgs.dto.testrun; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -/** - * Created by belozovs on 7/16/2015. - * - * Version of TestRunResult for ALM - includes test steps - */ -public class AlmTestRunResult extends TestRunResult { - - List> steps = new ArrayList<>(); - - @Override - public List> getSteps() { - return steps; - } - - public void addStep(Map step) { - steps.add(step); - } - - -} diff --git a/src/main/java/com/hp/gaia/mgs/dto/testrun/CodeTestRunEvent.java b/src/main/java/com/hp/gaia/mgs/dto/testrun/CodeTestRunEvent.java deleted file mode 100644 index 5b56d3d..0000000 --- a/src/main/java/com/hp/gaia/mgs/dto/testrun/CodeTestRunEvent.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.hp.gaia.mgs.dto.testrun; - -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; - -/** - * Created by belozovs on 7/16/2015. - * Version of TestRunEvent for automatic test - * Main differentiator: EVENT_TYPE - */ -@JsonDeserialize(using = TestRunDeserializer.class) -public class CodeTestRunEvent extends TestRunEvent { - - public final static String EVENT_TYPE = "code_testrun"; - - TestRunResult result; - - @SuppressWarnings("unchecked") - @Override - public TestRunResult getResult() { - return result; - } - - @Override - public void setResult(TestRunResult result) { - this.result = result; - } - -} diff --git a/src/main/java/com/hp/gaia/mgs/dto/testrun/TestRunDeserializer.java b/src/main/java/com/hp/gaia/mgs/dto/testrun/TestRunDeserializer.java deleted file mode 100644 index 11c50fb..0000000 --- a/src/main/java/com/hp/gaia/mgs/dto/testrun/TestRunDeserializer.java +++ /dev/null @@ -1,108 +0,0 @@ -package com.hp.gaia.mgs.dto.testrun; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.core.type.TypeReference; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.deser.std.StdDeserializer; -import com.hp.gaia.mgs.dto.CommonDeserializerUtils; -import jersey.repackaged.com.google.common.collect.Lists; - -import java.io.IOException; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -/** - * Created by belozovs on 7/15/2015. - * Deserializer for all types of TestRunEvent - */ -public class TestRunDeserializer extends StdDeserializer implements CommonDeserializerUtils { - - public TestRunDeserializer() { - super(TestRunEvent.class); - } - - @Override - public TestRunEvent deserialize(JsonParser jp, DeserializationContext ctxt) throws IOException { - - JsonNode node = jp.getCodec().readTree(jp); - - Class trec = null; - if (node.findValue("event") != null) { - switch (node.findValue("event").asText()) { - case AlmTestRunEvent.EVENT_TYPE: - trec = AlmTestRunEvent.class; - break; - case CodeTestRunEvent.EVENT_TYPE: - trec = CodeTestRunEvent.class; - break; - } - } - if (trec == null) { - return null; - } - TestRunEvent tre; - try { - tre = trec.newInstance(); - } catch (ReflectiveOperationException e) { - e.printStackTrace(); - return null; - } - - fillMap(tre.getId(), "id", node); - fillMap(tre.getSource(), "source", node); - fillMap(tre.getTags(), "tags", node); - - tre.setType(node.findValue("event").asText()); - - if (node.get("time") != null) { - tre.setTime(javax.xml.bind.DatatypeConverter.parseDateTime(node.get("time").asText()).getTime()); - } else { - tre.setTime(new Date()); - } - - tre.setResult(fetchTestRunResult(node)); - - return tre; - - } - - private AlmTestRunResult fetchTestRunResult(JsonNode runNode) { - JsonNode resultNode = runNode.get("result"); - if (resultNode == null) { - return null; - } else { - AlmTestRunResult atrr = new AlmTestRunResult(); - Iterator fieldNames = resultNode.fieldNames(); - while (fieldNames.hasNext()) { - String fieldName = fieldNames.next(); - switch (fieldName) { - case "status": - atrr.setStatus(resultNode.get(fieldName).asText()); - break; - case "error": - atrr.setErrorString(resultNode.get(fieldName).asText()); - break; - case "run_time": - atrr.setRunTime(resultNode.get(fieldName).asLong()); - break; - case "steps": - List list = Lists.newArrayList(resultNode.get("steps").iterator()); - for (JsonNode node : list) { - atrr.addStep(new ObjectMapper().convertValue(node, new TypeReference>() { - })); - } - break; - default: - atrr.getCustomFields().put(fieldName, resultNode.get(fieldName)); - break; - } - } - return atrr; - } - } - -} diff --git a/src/main/java/com/hp/gaia/mgs/dto/testrun/TestRunEvent.java b/src/main/java/com/hp/gaia/mgs/dto/testrun/TestRunEvent.java deleted file mode 100644 index c336e6c..0000000 --- a/src/main/java/com/hp/gaia/mgs/dto/testrun/TestRunEvent.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.hp.gaia.mgs.dto.testrun; - -import com.hp.gaia.mgs.dto.BaseEvent; - -/** - * Created by belozovs on 7/16/2015. - * Base class for all types of TestRun (either manual in ALM or automatic) - */ -public abstract class TestRunEvent extends BaseEvent { - - public abstract void setResult(T result); - - public abstract T getResult(); - -} diff --git a/src/main/java/com/hp/gaia/mgs/dto/testrun/TestRunResult.java b/src/main/java/com/hp/gaia/mgs/dto/testrun/TestRunResult.java deleted file mode 100644 index 5a99452..0000000 --- a/src/main/java/com/hp/gaia/mgs/dto/testrun/TestRunResult.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.hp.gaia.mgs.dto.testrun; - -import java.util.*; - -/** - * Created by belozovs on 7/16/2015. - * Base class for all kinds of TestRunResults: either manual (ALM) or automatic test - */ -class TestRunResult { - - private String status; - private Long runTime; - private String errorString; - private Map customFields = new HashMap<>(); - - public String getStatus() { - return status; - } - - public void setStatus(String status) { - this.status = status; - } - - public Long getRunTime() { - return runTime; - } - - public void setRunTime(Long runTime) { - this.runTime = runTime; - } - - public String getErrorString() { - return errorString; - } - - public void setErrorString(String errorString) { - this.errorString = errorString; - } - - public Map getCustomFields() { - return customFields; - } - - @SuppressWarnings("unchecked") - public List> getSteps(){ - return new ArrayList(); - } -} diff --git a/src/main/java/com/hp/gaia/mgs/dto/testrun/TestRunToInfluxLineProtocol.java b/src/main/java/com/hp/gaia/mgs/dto/testrun/TestRunToInfluxLineProtocol.java deleted file mode 100644 index 39c82c9..0000000 --- a/src/main/java/com/hp/gaia/mgs/dto/testrun/TestRunToInfluxLineProtocol.java +++ /dev/null @@ -1,101 +0,0 @@ -package com.hp.gaia.mgs.dto.testrun; - -import com.hp.gaia.mgs.dto.InfluxLineProtocolConverter; - -import java.util.Map; - -/** - * Created by belozovs on 7/22/2015. - * Convert CodeTestRunEvent object to input data for InfluxDB 0.9 - */ -public class TestRunToInfluxLineProtocol implements InfluxLineProtocolConverter { - - /** - * Convert CodeTestRunEvent to string compatible with InfluxDB 0.9 line protocol - * For each field separate line create with all its attributes as values and status name as a tag (beside other tags and source) - * Example of the output (single row): - * code_testrun,repository=git://github.com/hp/mqm-server,branch=master,browser=firefox,build_label=1.7.0,build_job=backend_job,status=error id_package="com.hp.mqm",id_method="TestLogicalOperators",id_class="FilterBuilder",runTime=130,errorString="NullPointerException: ...",setup_time=35,tear_down_time=20 1447196400000000000 - * @param event CodeTestRunEvent to be converted before inserting to InfluxDB - * @return row to be inserted to InfluxDB - * - */ - @Override - public String convert(TestRunEvent event) { - - StringBuilder mainSb = new StringBuilder(); - StringBuilder commonPart = new StringBuilder(); - TestRunResult testResult = event.getResult(); - - commonPart.append(getEscapedString(event.getType())); - for (String key : event.getSource().keySet()) { - commonPart.append(",").append(getEscapedString(key)).append("=").append(getEscapedString(event.getSource().get(key))); - } - for (String key : event.getTags().keySet()) { - commonPart.append(",").append(getEscapedString(key)).append("=").append(getEscapedString(event.getTags().get(key))); - } - commonPart.append(",").append("status").append("=").append(getEscapedString(testResult.getStatus())); - - //separator between measurement+tags and data part of the string - commonPart.append(" "); - //create a data part - //id and values (fields, result, etc.) - for (String key : event.getId().keySet()) { - //note: id value is always String - commonPart.append("id_").append(getEscapedString(key)).append("=").append(getQuotedValue(event.getId().get(key))).append(","); - } - commonPart.append("runTime=").append(testResult.getRunTime()).append(","); - if(testResult.getErrorString()!= null) { - commonPart.append("errorString=").append(getQuotedValue(testResult.getErrorString())).append(","); - } - if (testResult.getCustomFields() != null) { - for (String key : testResult.getCustomFields().keySet()) { - if(testResult.getCustomFields().get(key).getClass().equals(java.lang.String.class)){ - commonPart.append(getEscapedString(key)).append("=").append(getQuotedValue((String) testResult.getCustomFields().get(key))).append(","); - } else { - commonPart.append(getEscapedString(key)).append("=").append(testResult.getCustomFields().get(key)).append(","); - } - - } - } - - //add steps if presented - if(testResult.getSteps().isEmpty()){ - //remove last comma - cutTrailingCharacter(commonPart,','); - mainSb.append(commonPart).append(" ").append(event.getTime().getTime() * 1000000); //switch to nanoseconds, as InfluxDB requires - //prepare to the next row insert - mainSb.append(System.lineSeparator()); - } else { - int i=0; - for (Map stepMap : testResult.getSteps()) { - StringBuilder steps = new StringBuilder(); - for (String key : stepMap.keySet()) { - //collect all attributes of the step - if (stepMap.get(key).getClass().equals(java.lang.String.class)) { - steps.append("step_").append(getEscapedString(key)).append("=").append(getQuotedValue((String) stepMap.get(key))).append(","); - } else { - steps.append("step_").append(getEscapedString(key)).append("=").append(stepMap.get(key)).append(","); - } - } - //remove last comma - cutTrailingCharacter(steps,','); - - //add timestamp - //TBD - boris: make InfluxDBManager in event-indexer adding &precision=ms query param to "writeToDB" URL and remove 1000000 from here - mainSb.append(commonPart).append(steps).append(" ").append((event.getTime().getTime() + (i++)) * 1000000); //switch to nanoseconds, as InfluxDB requires - - //prepare to the next row insert - mainSb.append(System.lineSeparator()); - } - } - return mainSb.toString(); - } - - private StringBuilder cutTrailingCharacter(StringBuilder sb, char ch){ - if (sb.length() > 0 && sb.charAt(sb.length() - 1) == ch) { - sb.setLength(sb.length() - 1); - } - return sb; - } - -} diff --git a/src/main/java/com/hp/gaia/mgs/rest/MeasurementGatewayResource.java b/src/main/java/com/hp/gaia/mgs/rest/MeasurementGatewayResource.java deleted file mode 100644 index f29486f..0000000 --- a/src/main/java/com/hp/gaia/mgs/rest/MeasurementGatewayResource.java +++ /dev/null @@ -1,175 +0,0 @@ -package com.hp.gaia.mgs.rest; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.hp.gaia.mgs.dto.BaseEvent; -import com.hp.gaia.mgs.dto.OldMetric; -import com.hp.gaia.mgs.services.MetricsCollectorService; -import com.hp.gaia.mgs.services.PropertiesKeeperService; -import com.hp.gaia.mgs.spring.MultiTenantOAuth2Authentication; -import org.springframework.security.core.context.SecurityContextHolder; - -import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.Consumes; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.Produces; -import javax.ws.rs.container.AsyncResponse; -import javax.ws.rs.container.Suspended; -import javax.ws.rs.core.Context; -import javax.ws.rs.core.Response; -import java.io.IOException; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; - -/** - * Created by belozovs on 5/21/2015. - * Endpoint to get the collected events of all type - */ -@Path("/v1/gateway") -public class MeasurementGatewayResource { - - MetricsCollectorService metricsCollector = new MetricsCollectorService(); - - - private Boolean useAmqp = Boolean.valueOf(PropertiesKeeperService.getInstance().getEnvOrPropAsString("useAmqp")); - - public MeasurementGatewayResource() throws IOException { - System.out.println("useAmqp flag is " + useAmqp); - if (useAmqp) { - System.out.println("Metrics will be published to RabbitMQ"); - } else { - System.out.println("Metrics will be published to log file"); - } - - } - - @POST - @Path("/publish") - @Consumes("application/json") - @Produces("application/json") - public void publishMetricAsync(@Context HttpServletRequest request, @Suspended final AsyncResponse response, List metrics) { - - - CompletableFuture.runAsync(() -> { - for (OldMetric metric : metrics) { - metricsCollector.storeMetric(metric); - } - }).thenApply((result) -> response.resume(Response.status(Response.Status.CREATED).entity(result).build())); - } - - - @POST - @Path("/publish2") - @Consumes("application/json") - @Produces("application/json") - public void publishMetricAsync2(@Context HttpServletRequest request, @Suspended final AsyncResponse response, JsonNode jsonMetrics) throws ExecutionException, InterruptedException { - - Map tenantDetails = ((MultiTenantOAuth2Authentication) SecurityContextHolder.getContext().getAuthentication()).getTenantDetails(); - - System.out.println("metric received"); - - CompletableFuture.supplyAsync(() -> { - if (useAmqp) { - try { - metricsCollector.publishMetric(String.valueOf(jsonMetrics.get("points")), String.valueOf(tenantDetails.get("tenantId"))); - return null; - } catch (Exception e) { - e.printStackTrace(); - return (e.getMessage() == null) ? e.getClass().getName() : e.getMessage(); - } - } else { - metricsCollector.storeMetric(String.valueOf(jsonMetrics.get("points").size()), (Integer) tenantDetails.get("tenantId")); - return null; - } - }).handle((result, ex) -> { - if (result == null) { - return response.resume(Response.status(Response.Status.CREATED).entity(result).build()); - - } else { - return response.resume(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(result).build()); - - } - }); - - } - - @POST - @Path("/publish3") - public void publishMetricAsync3(@Context HttpServletRequest request, @Suspended final AsyncResponse response, String jsonMetrics) throws ExecutionException, InterruptedException { - - Map tenantDetails = ((MultiTenantOAuth2Authentication) SecurityContextHolder.getContext().getAuthentication()).getTenantDetails(); - - System.out.println("metric received"); - - CompletableFuture.supplyAsync(() -> { - if (useAmqp) { - try { - metricsCollector.publishMetric(jsonMetrics, String.valueOf(tenantDetails.get("tenantId"))); - return null; - } catch (Exception e) { - e.printStackTrace(); - return (e.getMessage() == null) ? e.getClass().getName() : e.getMessage(); - } - } else { - metricsCollector.storeMetric(jsonMetrics, (Integer) tenantDetails.get("tenantId")); - return null; - } - }).handle((result, ex) -> { - if (result == null) { - return response.resume(Response.status(Response.Status.CREATED).build()); - - } else { - return response.resume(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(result).build()); - - } - }); - - } - - @POST - @Path("/event") - public void publishEvent(@Context HttpServletRequest request, @Suspended final AsyncResponse response, String jsonEvents) throws ExecutionException, InterruptedException, IOException { - - Map tenantDetails = ((MultiTenantOAuth2Authentication) SecurityContextHolder.getContext().getAuthentication()).getTenantDetails(); - - - CompletableFuture.supplyAsync(() -> { - if (useAmqp) { - try { - List receivedEvents = (List) new ObjectMapper().readValue(jsonEvents, BaseEvent.class); - System.out.println("Tenant " + tenantDetails.get("tenantId") + " Got result, number of points: " + receivedEvents.size()); - metricsCollector.publishEvent(receivedEvents, String.valueOf(tenantDetails.get("tenantId"))); - return null; - } catch (Exception e) { - e.printStackTrace(); - return (e.getMessage() == null) ? e.getClass().getName() : e.getMessage(); - } - } else { - try { - List receivedEvents = (List) new ObjectMapper().readValue(jsonEvents, BaseEvent.class); - System.out.println("Tenant " + tenantDetails.get("tenantId") + " Got result, number of points: " + receivedEvents.size()); - metricsCollector.storeEvent(receivedEvents, String.valueOf(tenantDetails.get("tenantId"))); - return null; - } catch (Exception e) { - e.printStackTrace(); - return (e.getMessage() == null) ? e.getClass().getName() : e.getMessage(); - } - } - }).handle((result, ex) -> { - if (result == null) { - return response.resume(Response.status(Response.Status.CREATED).build()); - - } else { - return response.resume(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(result).build()); - - } - }); - - - } - - -} diff --git a/src/main/java/com/hp/gaia/mgs/rest/MonitoringResource.java b/src/main/java/com/hp/gaia/mgs/rest/MonitoringResource.java deleted file mode 100644 index f8c0f1e..0000000 --- a/src/main/java/com/hp/gaia/mgs/rest/MonitoringResource.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.hp.gaia.mgs.rest; - -import com.hp.gaia.mgs.services.MonitoringService; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.ws.rs.*; -import javax.ws.rs.core.Response; -import java.lang.management.ManagementFactory; -import java.lang.management.ThreadInfo; -import java.lang.management.ThreadMXBean; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.TimeUnit; - -/** - * Created by belozovs on 5/21/2015. - */ - -@Path("/monitor") -public class MonitoringResource { - - private final static Logger logger = LoggerFactory.getLogger(MonitoringResource.class); - - private ScheduledExecutorService scheduler; - - @GET - @Path("/action/{action}") - @Consumes("application/json") - @Produces("application/json") - public Response monitoringControl(@PathParam("action") String action) { - - if (scheduler == null && action.equalsIgnoreCase("on")) { - scheduler = Executors.newSingleThreadScheduledExecutor(); - scheduler.scheduleAtFixedRate(MonitoringService.getIntstance(), 0L, 1000L, TimeUnit.MILLISECONDS); - logger.debug("Start monitoring"); - System.out.println("Start monitoring"); - return Response.status(Response.Status.OK).entity("Monitoring started").build(); - } - - if (scheduler != null && action.equalsIgnoreCase("off")) { - if (!scheduler.isShutdown()) { - scheduler.shutdown(); - scheduler = null; - logger.debug("Stop monitoring"); - System.out.println("Stop monitoring"); - } - return Response.status(Response.Status.OK).entity("Monitoring stopped").build(); - } - - return Response.status(Response.Status.OK).entity("Nothing to do with monitoring").build(); - - } - - @GET - @Path("/dump") - @Consumes("application/json") - @Produces("application/json") - public Response getThreadDump(@PathParam("action") String action) { - - StringBuilder sb = new StringBuilder(); - ThreadMXBean threadBean = ManagementFactory.getThreadMXBean(); - ThreadInfo[] threadInfos = threadBean.getThreadInfo(threadBean.getAllThreadIds()); - for(ThreadInfo threadInfo : threadInfos){ - sb.append(threadInfo.getThreadName()); - sb.append("\nstate: " + threadInfo.getThreadState()); - StackTraceElement[] traceElements = threadInfo.getStackTrace(); - for(int i =0; i<((traceElements.length>10) ? 10 : traceElements.length); i++){ - sb.append("\n at ").append(traceElements[i]); - } - sb.append("\n\n"); - } - - return Response.status(Response.Status.OK).entity(sb.toString()).build(); - } - -} diff --git a/src/main/java/com/hp/gaia/mgs/rest/filters/InputFilter.java b/src/main/java/com/hp/gaia/mgs/rest/filters/InputFilter.java deleted file mode 100644 index e02eb90..0000000 --- a/src/main/java/com/hp/gaia/mgs/rest/filters/InputFilter.java +++ /dev/null @@ -1,45 +0,0 @@ -package com.hp.gaia.mgs.rest.filters; - - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import javax.servlet.*; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.Response; -import java.io.IOException; - -/** - * Created by belozovs on 5/30/2015. - * Filter out requests that contain to few data to be correct (less than 100 bytes) and requests that seem to be suspiciously large (100KB) - */ - -public class InputFilter implements Filter { - - Logger logger = LoggerFactory.getLogger(InputFilter.class); - - private final static int MINIMAL_REQUEST_SIZE=10; - private final static int MAXIMAL_REQUEST_SIZE=102400; - - @Override - public void init(FilterConfig filterConfig) throws ServletException { - - } - - @Override - public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException { - if (servletRequest.getContentLengthLong() < MINIMAL_REQUEST_SIZE || servletRequest.getContentLengthLong() > MAXIMAL_REQUEST_SIZE) { - logger.error("Response content is too short or too large. Actual size in bytes is {}", servletRequest.getContentLengthLong()); - HttpServletResponse response = (HttpServletResponse) servletResponse; - response.reset(); - response.setStatus(Response.Status.PRECONDITION_FAILED.getStatusCode()); - return; - } - filterChain.doFilter(servletRequest, servletResponse); - } - - @Override - public void destroy() { - - } -} \ No newline at end of file diff --git a/src/main/java/com/hp/gaia/mgs/services/MetricsCollectorService.java b/src/main/java/com/hp/gaia/mgs/services/MetricsCollectorService.java deleted file mode 100644 index f46a982..0000000 --- a/src/main/java/com/hp/gaia/mgs/services/MetricsCollectorService.java +++ /dev/null @@ -1,128 +0,0 @@ -package com.hp.gaia.mgs.services; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.hp.gaia.mgs.amqp.AmqpManager; -import com.hp.gaia.mgs.dto.*; -import com.rabbitmq.client.AMQP; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.io.IOException; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.concurrent.TimeoutException; - -/** - * Created by belozovs on 5/27/2015. - */ -public class MetricsCollectorService { - - private final static Logger logger = LoggerFactory.getLogger(MetricsCollectorService.class); - - private final static String DB_NAME_PROPERTY = "dbname"; - AmqpManager amqpManager; - - public MetricsCollectorService() throws IOException { - this.amqpManager = new AmqpManager(); - } - - String basedir = System.getProperty("user.dir"); - - - public void storeMetric(OldMetric m) { - - String name = m.getName(); - String category = m.getCategory(); - String metric = m.getMetric(); - String source = m.getSource(); - Long timestamp = m.getTimestamp(); - List tags = m.getTags(); - List events = m.getEvents(); - List measurements = m.getMeasurements(); - - logger.info("OldMetric received: {}", name); - } - - public void storeMetric(String thingToPrint) { - logger.info("Received metrics - " + thingToPrint); - } - - public void storeMetric(String numOfMetrics, Integer tenantId) { - logger.info("Tenant " + tenantId + " received " + numOfMetrics + " metrics"); - } - - public void publishMetric(String metric, String tenantIdString) throws IOException, TimeoutException { - AMQP.BasicProperties.Builder propsBuilder = new AMQP.BasicProperties.Builder(); - Map map = new HashMap(); - map.put(DB_NAME_PROPERTY, tenantIdString); - propsBuilder.headers(map); - amqpManager.getChannel().basicPublish("", amqpManager.getQueueName(), propsBuilder.build(), metric.getBytes()); - System.out.println(" [x] Sent '" + metric + "'"); - - } - - /** - * Test method that can be used for running the service locally. - * Method just prints some data to STDOUT instead of publishing it to RabbitMQ in the full blown system - * - * @param events - List of input events (json); events must extend {@link com.hp.gaia.mgs.dto.BaseEvent} - * @param tenantId - tenant id reported the events - */ - public void storeEvent(Collection events, String tenantId) { - - logger.info("Going to publish {} events for tenant {}.", events.size(), tenantId); - - StringBuffer mainSb = new StringBuffer(); - - InfluxLineProtocolConverterFactory converterFactory = new InfluxLineProtocolConverterFactory(); - for (T event : events) { - mainSb.append(converterFactory.getConverter(event.getType()).convert(event)); - //mainSb.append(converter.createEventConverterAndRun(event)); - } - - logger.debug("Publishing event for tenant {}: {} ", tenantId, mainSb); - - logger.info("Successfully published {} events for tenant {}.", events.size(), tenantId); - } - - /** - * Translate json formatted input to InfluxDB line protocol (https://influxdb.com/docs/v0.9/write_protocols/write_syntax.html) and publish to the system - * InfluxDB line protocol requires the following format: [key] [fields] [timestamp] - * For example: cpu,host=server\ 01,region=us-west cpu load=10.0,alert=true,reason="value above maximum threshold" 1434055562005 - * NOTE: timestamp is in milliseconds, so inserting data to InfluxDB requires precision=ms parameter (default is nanoseconds) - *

- * Multiple events are published one by one to RabbitMQ. - * - * @param events - List of input events (json); events must extend {@link com.hp.gaia.mgs.dto.BaseEvent} - * @param tenantId - tenant id reported the events - * @throws JsonProcessingException - * @see com.hp.gaia.mgs.dto.BaseEvent - */ - public void publishEvent(Collection events, String tenantId) throws IOException, TimeoutException { - - logger.info("Going to publish {} events for tenant {}.", events.size(), tenantId); - - AMQP.BasicProperties.Builder propsBuilder = new AMQP.BasicProperties.Builder(); - Map map = new HashMap<>(); - map.put(DB_NAME_PROPERTY, tenantId); - propsBuilder.headers(map); - - StringBuffer mainSb = new StringBuffer(); - - InfluxLineProtocolConverterFactory converterFactory = new InfluxLineProtocolConverterFactory(); - for (T event : events) { - mainSb.append(converterFactory.getConverter(event.getType()).convert(event)); - //mainSb.append(converterFactory.createEventConverterAndRun(event)); - } - - logger.debug("Publishing event for tenant {}: {} ", tenantId, mainSb); - amqpManager.getChannel().basicPublish("", amqpManager.getQueueName(), propsBuilder.build(), mainSb.toString().getBytes()); - logger.debug(" [v] Sent event for tenant {}. ", tenantId); - - logger.info("Successfully published {} events for tenant {}.", events.size(), tenantId); - } - -} - diff --git a/src/main/java/com/hp/gaia/mgs/services/MonitoringService.java b/src/main/java/com/hp/gaia/mgs/services/MonitoringService.java deleted file mode 100644 index 0070750..0000000 --- a/src/main/java/com/hp/gaia/mgs/services/MonitoringService.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.hp.gaia.mgs.services; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Date; -import java.util.TimerTask; - -/** - * Created by belozovs on 5/31/2015. - */ -public class MonitoringService extends TimerTask{ - - private final static Logger logger = LoggerFactory.getLogger(MonitoringService.class); - - private static MonitoringService instance; - private Runtime runtime; - - private MonitoringService() { - runtime = Runtime.getRuntime(); - } - - public static MonitoringService getIntstance() { - if (instance == null) { - instance = new MonitoringService(); - } - return instance; - } - - @Override - public void run() { - logger.info("Free memory: {} Used memory: {} Thread counter: {}", runtime.freeMemory(), (runtime.totalMemory()-runtime.freeMemory()), Thread.activeCount()); -// System.out.println(new Date() + " Free memory: " + runtime.freeMemory() + " Used memory: " + (runtime.totalMemory()-runtime.freeMemory()) + " Thread counter: " + Thread.activeCount()); - } - - @Override - public boolean cancel() { - instance = null; - return super.cancel(); - } - -} diff --git a/src/main/java/com/hp/gaia/mgs/services/PropertiesKeeperService.java b/src/main/java/com/hp/gaia/mgs/services/PropertiesKeeperService.java deleted file mode 100644 index ac96205..0000000 --- a/src/main/java/com/hp/gaia/mgs/services/PropertiesKeeperService.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.hp.gaia.mgs.services; - -import java.io.IOException; -import java.util.Map; -import java.util.Properties; - -/** - * Created by belozovs on 6/30/2015. - * Return property from default.properties or environment variable if set to override defaults - */ -public class PropertiesKeeperService { - - private final static String PROP_FILE_NAME="default.properties"; - - private static PropertiesKeeperService instance = null; - private static Properties properties = null; - private static Map envVar = System.getenv(); - - - - private PropertiesKeeperService() throws IOException { - properties = new Properties(); - properties.load(Thread.currentThread().getContextClassLoader().getResourceAsStream(PROP_FILE_NAME)); - } - - public static PropertiesKeeperService getInstance() throws IOException { - if(instance == null){ - instance = new PropertiesKeeperService(); - } - return instance; - } - - public String getEnvOrPropAsString(String name) { - if(envVar.get(name) != null){ - return envVar.get(name); - } else { - return properties.getProperty(name); - } - } - -} diff --git a/src/main/java/com/hp/gaia/mgs/spring/CustomResponseErrorHandler.java b/src/main/java/com/hp/gaia/mgs/spring/CustomResponseErrorHandler.java deleted file mode 100644 index 4a47eff..0000000 --- a/src/main/java/com/hp/gaia/mgs/spring/CustomResponseErrorHandler.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.hp.gaia.mgs.spring; - -import org.apache.commons.io.IOUtils; -import org.springframework.http.HttpStatus; -import org.springframework.http.client.ClientHttpResponse; -import org.springframework.web.client.DefaultResponseErrorHandler; -import org.springframework.web.client.ResponseErrorHandler; -import org.springframework.web.client.RestClientException; - -import java.io.IOException; - -/** - * Created by belozovs on 6/21/2015. - */ -public class CustomResponseErrorHandler implements ResponseErrorHandler{ - - private ResponseErrorHandler errorHandler = new DefaultResponseErrorHandler(); - - @Override - public boolean hasError(ClientHttpResponse response) throws IOException { - return errorHandler.hasError(response); - } - - @Override - public void handleError(ClientHttpResponse response) throws IOException { - - String body = IOUtils.toString(response.getBody()); - MyCustomException myCustomException = new MyCustomException(HttpStatus.INTERNAL_SERVER_ERROR, body, body); - throw myCustomException; - } -} diff --git a/src/main/java/com/hp/gaia/mgs/spring/DefaultController.java b/src/main/java/com/hp/gaia/mgs/spring/DefaultController.java deleted file mode 100644 index 9fec200..0000000 --- a/src/main/java/com/hp/gaia/mgs/spring/DefaultController.java +++ /dev/null @@ -1,18 +0,0 @@ -package com.hp.gaia.mgs.spring; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.servlet.ModelAndView; - -/** - * Created by belozovs on 6/8/2015. - */ -@Controller -public class DefaultController { - - @RequestMapping("/") - public ModelAndView login(){ - return new ModelAndView("index"); - } - -} diff --git a/src/main/java/com/hp/gaia/mgs/spring/MultiTenantAccessTokenConverter.java b/src/main/java/com/hp/gaia/mgs/spring/MultiTenantAccessTokenConverter.java deleted file mode 100644 index dec052e..0000000 --- a/src/main/java/com/hp/gaia/mgs/spring/MultiTenantAccessTokenConverter.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.hp.gaia.mgs.spring; - -import org.springframework.security.oauth2.provider.OAuth2Authentication; -import org.springframework.security.oauth2.provider.token.DefaultAccessTokenConverter; - -import java.util.Map; - -/** - * Created by belozovs on 6/25/2015. - */ -public class MultiTenantAccessTokenConverter extends DefaultAccessTokenConverter { - - @Override - public MultiTenantOAuth2Authentication extractAuthentication(Map map) { - OAuth2Authentication auth = super.extractAuthentication(map); - - MultiTenantOAuth2Authentication mauth = new MultiTenantOAuth2Authentication(auth.getOAuth2Request(), auth.getUserAuthentication()); - - mauth.getTenantDetails().put("tenantId", map.get("tenantId")); - - - return mauth; - } -} diff --git a/src/main/java/com/hp/gaia/mgs/spring/MultiTenantOAuth2Authentication.java b/src/main/java/com/hp/gaia/mgs/spring/MultiTenantOAuth2Authentication.java deleted file mode 100644 index 19c22cf..0000000 --- a/src/main/java/com/hp/gaia/mgs/spring/MultiTenantOAuth2Authentication.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.hp.gaia.mgs.spring; - -import org.springframework.security.core.Authentication; -import org.springframework.security.oauth2.provider.OAuth2Authentication; -import org.springframework.security.oauth2.provider.OAuth2Request; - -import java.util.HashMap; -import java.util.Map; - -/** - * Created by belozovs on 6/25/2015. - */ -public class MultiTenantOAuth2Authentication extends OAuth2Authentication { - - private Map tenantDetails = new HashMap<>(); - - /** - * Construct an OAuth 2 authentication. Since some grant types don't require user authentication, the user - * authentication may be null. - * - * @param storedRequest The authorization request (must not be null). - * @param userAuthentication The user authentication (possibly null). - */ - public MultiTenantOAuth2Authentication(OAuth2Request storedRequest, Authentication userAuthentication) { - super(storedRequest, userAuthentication); - } - - public Map getTenantDetails() { - return tenantDetails; - } -} diff --git a/src/main/java/com/hp/gaia/mgs/spring/MyCustomException.java b/src/main/java/com/hp/gaia/mgs/spring/MyCustomException.java deleted file mode 100644 index 5ca7b9c..0000000 --- a/src/main/java/com/hp/gaia/mgs/spring/MyCustomException.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.hp.gaia.mgs.spring; - -import org.springframework.http.HttpStatus; -import org.springframework.web.client.RestClientException; - -import java.io.IOException; - -/** - * Created by belozovs on 6/21/2015. - */ -public class MyCustomException extends RestClientException { - - private HttpStatus statusCode; - - private String body; - - public MyCustomException(String msg) { - super(msg); - // TODO Auto-generated constructor stub - } - - public MyCustomException(HttpStatus statusCode, String body, String msg) { - super(msg); - this.statusCode = statusCode; - this.body = body; - } - - public HttpStatus getStatusCode() { - return statusCode; - } - - public void setStatusCode(HttpStatus statusCode) { - this.statusCode = statusCode; - } - - public String getBody() { - return body; - } - - public void setBody(String body) { - this.body = body; - } - -} diff --git a/src/main/webapp/WEB-INF/classes/default.properties b/src/main/webapp/WEB-INF/classes/default.properties deleted file mode 100644 index a39d5bd..0000000 --- a/src/main/webapp/WEB-INF/classes/default.properties +++ /dev/null @@ -1,8 +0,0 @@ -authServer=localhost:9001 -amqpHost=localhost -amqpPort=5672 -amqpUser=admin -amqpPassword= -amqpRoutingKey=events-indexer - -useAmqp=false \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/classes/logback.xml b/src/main/webapp/WEB-INF/classes/logback.xml deleted file mode 100644 index e094a5b..0000000 --- a/src/main/webapp/WEB-INF/classes/logback.xml +++ /dev/null @@ -1,84 +0,0 @@ - - - - - logs/mgs.log - - - %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{5}:%line - %msg%n - - - - - mgs.%d{yyyy-MM-dd}.%i.log - - 10MB - - - - - - logs/metrics-storage.log - - - %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{5}:%line - %msg%n - - - - - metrics-storage.%d{yyyy-MM-dd}.%i.log - - 10MB - - - - - - logs/mgs-monitor.log - - - %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{5}:%line - %msg%n - - - - - mgs-monitor.%d{yyyy-MM-dd}.%i.log - - 10MB - - - - - - - - %d{yyyy-MM-dd HH:mm:ss} [%thread] %-5level %logger{5}:%line - %msg%n - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/spring-security.xml b/src/main/webapp/WEB-INF/spring-security.xml deleted file mode 100644 index c896730..0000000 --- a/src/main/webapp/WEB-INF/spring-security.xml +++ /dev/null @@ -1,54 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/webapp/WEB-INF/spring-servlet.xml b/src/main/webapp/WEB-INF/spring-servlet.xml deleted file mode 100644 index 6b902ba..0000000 --- a/src/main/webapp/WEB-INF/spring-servlet.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 044f348..0000000 --- a/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,79 +0,0 @@ - - - - Measurements Gateway - - - contextConfigLocation - - /WEB-INF/spring-security.xml - - - - - org.springframework.web.context.ContextLoaderListener - - - - - spring - org.springframework.web.servlet.DispatcherServlet - 1 - true - - - spring - - / - - - - jersey-serlvet - org.glassfish.jersey.servlet.ServletContainer - - jersey.config.server.provider.packages - com.hp.gaia.mgs.rest - - - com.sun.jersey.api.json.POJOMappingFeature - true - - - javax.ws.rs.container.ContainerRequestFilter - com.hp.gaia.mgs.rest.filters.InputFilter - - - true - - - jersey-serlvet - /rest/* - - - - - InputFilter - com.hp.gaia.mgs.rest.filters.InputFilter - true - - - springSecurityFilterChain - org.springframework.web.filter.DelegatingFilterProxy - true - - - InputFilter - /rest/v1/gateway/* - - - springSecurityFilterChain - - /* - - - - diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp deleted file mode 100644 index ecb4764..0000000 --- a/src/main/webapp/index.jsp +++ /dev/null @@ -1,5 +0,0 @@ - - -

Metrics gateway service is ready

- - diff --git a/src/test/java/com/hp/gaia/mgs/dto/MainEventParserTest.java b/src/test/java/com/hp/gaia/mgs/dto/MainEventParserTest.java deleted file mode 100644 index 2f1aaa4..0000000 --- a/src/test/java/com/hp/gaia/mgs/dto/MainEventParserTest.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.hp.gaia.mgs.dto; - -import com.fasterxml.jackson.databind.ObjectMapper; -import com.hp.gaia.mgs.dto.change.IssueChangeEvent; -import com.hp.gaia.mgs.dto.testrun.AlmTestRunEvent; -import com.hp.gaia.mgs.dto.testrun.CodeTestRunEvent; -import org.junit.Before; -import org.junit.Test; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import static org.junit.Assert.*; - - -/** - * Created by belozovs on 7/16/2015. - */ -public class MainEventParserTest { - - private static String EVENT_SOURCE_OUTSIDE = "{\"event\":\"issue_change\",\"source\":{\"server\":\"http://alm-saas.hp.com\",\"domain\":\"IT\",\"project\":\"Project A\"},\"points\":[{\"time\":\"2015-11-10T23:00:00Z\",\"id\":{\"uid\":\"1122\"},\"tags\":{\"workspace\":\"CRM\",\"user\":\"bob\"},\"fields\":[{\"name\":\"Status\",\"from\":\"New\",\"to\":\"Open\",\"ttc\":124},{\"name\":\"Priority\",\"to\":\"2-Medium\",\"newfield\":\"my new field\"}]}]}"; - private static String EVENT_ALL_COMMON_OUTSIDE = "{\"event\":\"issue_change\",\"time\":\"2015-11-10T23:00:00Z\",\"source\":{\"server\":\"http://alm-saas.hp.com\",\"domain\":\"IT\",\"project\":\"Project A\"},\"tags\":{\"workspace\":\"CRM\",\"user\":\"bob\"},\"id\":{\"uid\":\"1122\"},\"points\":[{\"fields\":[{\"name\":\"Status\",\"from\":\"New\",\"to\":\"Open\",\"ttc\":124},{\"name\":\"Priority\",\"to\":\"2-Medium\",\"newfield\":\"my new field\"}]}]}"; - private static String EVENT_ALL_COMMON_OUTSIDE_MULTI = "{\"event\":\"issue_change\",\"time\":\"2015-11-10T23:00:00Z\",\"source\":{\"server\":\"http://alm-saas.hp.com\",\"domain\":\"IT\",\"project\":\"Project A\"},\"tags\":{\"workspace\":\"CRM\",\"user\":\"bob\"},\"id\":{\"uid\":\"1122\"},\"points\":[{\"fields\":[{\"name\":\"Status\",\"from\":\"New\",\"to\":\"Open\",\"ttc\":124},{\"name\":\"Priority\",\"to\":\"2-Medium\",\"newfield\":\"my new field\"}]},{\"fields\":[{\"name\":\"Owner\",\"to\":\"Obama\"},{\"name\":\"Severity\",\"to\":\"289-Extremely Sever\",\"isRealyExtrim\":true}]}]}"; - private static String EVENT_ALL_COMMON_OUTSIDE_MULTI_MULTITYPES = "{\"event\":\"issue_change\",\"time\":\"2015-11-10T23:00:00Z\",\"source\":{\"server\":\"http://alm-saas.hp.com\",\"domain\":\"IT\",\"project\":\"Project A\"},\"tags\":{\"workspace\":\"CRM\",\"user\":\"bob\"},\"id\":{\"uid\":\"1122\"},\"points\":[{\"fields\":[{\"name\":\"Status\",\"from\":\"New\",\"to\":\"Open\",\"ttc\":124},{\"name\":\"Priority\",\"to\":\"2-Medium\",\"newfield\":\"my new field\"}]},{\"fields\":[{\"name\":\"Owner\",\"to\":\"Obama\"},{\"name\":\"Severity\",\"to\":\"289-Extremely Sever\",\"isRealyExtrim\":true}]},{\"event\":\"tm_testrun\",\"time\":\"2015-11-10T23:00:00Z\",\"source\":{\"server\":\"http://alm-saas.hp.com\",\"domain\":\"IT\",\"project\":\"Project A\"},\"id\":{\"instance\":\"245\",\"test_id\":\"34\"},\"tags\":{\"workspace\":\"CRM\",\"testset\":\"Regression\",\"user\":\"john\",\"type\":\"Manual\"},\"result\":{\"status\":\"Passed\",\"run_time\":380,\"steps\":[{\"name\":\"step 1\",\"status\":\"Passed\",\"runt_time\":12},{\"name\":\"step 2\",\"status\":\"Skipped\"},{\"name\":\"step 3\",\"status\":\"Passed\",\"runt_time\":368}]}},{\"event\":\"code_testrun\",\"time\":\"2015-11-10T23:00:00Z\",\"source\":{\"repository\":\"git://github.com/hp/mqm-server\",\"branch\":\"master\"},\"id\":{\"package\":\"com.hp.mqm\",\"class\":\"FilterBuilder\",\"method\":\"TestLogicalOperators\"},\"tags\":{\"build_job\":\"backend_job\",\"browser\":\"firefox\",\"build_label\":\"1.7.0\"},\"result\":{\"status\":\"error\",\"error\":\"NullPointerException: ...\",\"setup_time\":35,\"tear_down_time\":20,\"run_time\":130}}]}"; - - private ObjectMapper mapper; - - @Before - public void setUp() throws Exception { - mapper = new ObjectMapper(); - } - - @Test - public void test_EVENT_SOURCE_OUTSIDE() throws Exception { - - List result = (List) mapper.readValue(EVENT_SOURCE_OUTSIDE, BaseEvent.class); - - System.out.println("done!"); - } - - @Test - public void test_EVENT_ALL_COMMON_OUTSIDE() throws Exception { - - List result = (List) mapper.readValue(EVENT_ALL_COMMON_OUTSIDE, BaseEvent.class); - - System.out.println("done!"); - } - - @Test - public void test_EVENT_ALL_COMMON_OUTSIDE_MULTI() throws Exception { - - List result = (List) mapper.readValue(EVENT_ALL_COMMON_OUTSIDE_MULTI, BaseEvent.class); - - System.out.println("done!"); - } - - - @Test - public void test_EVENT_ALL_COMMON_OUTSIDE_MULTI_MULTITYPES() throws Exception { - List result = (List) mapper.readValue(EVENT_ALL_COMMON_OUTSIDE_MULTI_MULTITYPES, BaseEvent.class); - - assertEquals("Four events expected", 4, result.size()); - Map eventTypes = new HashMap<>(); - for(BaseEvent event : result){ - if(eventTypes.get(event.getType()) == null){ - eventTypes.put(event.getType(), 1); - } else { - eventTypes.put(event.getType(), eventTypes.get(event.getType()) + 1); - } - } - assertEquals("Two issue changes expected", 2, eventTypes.get(IssueChangeEvent.EVENT_TYPE).longValue()); - assertEquals("One ALM test run expected", 1, eventTypes.get(AlmTestRunEvent.EVENT_TYPE).longValue()); - assertEquals("One code test run expected", 1, eventTypes.get(CodeTestRunEvent.EVENT_TYPE).longValue()); - - System.out.println("done!"); - } -} diff --git a/src/test/java/com/hp/gaia/mgs/dto/change/IssueChangeEventParserTest.java b/src/test/java/com/hp/gaia/mgs/dto/change/IssueChangeEventParserTest.java deleted file mode 100644 index 864e422..0000000 --- a/src/test/java/com/hp/gaia/mgs/dto/change/IssueChangeEventParserTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.hp.gaia.mgs.dto.change; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Before; -import org.junit.Test; - -import java.io.IOException; - -/** - * Created by belozovs on 7/15/2015. - */ - -public class IssueChangeEventParserTest { - - private final String ISSUE_CHANGE_EVENT = "{\"event\":\"issue_change\",\"time\":\"2015-11-10T23:00:00Z\",\"source\":{\"server\":\"http://alm-saas.hp.com\",\"domain\":\"IT\",\"project\":\"Project A\"},\"id\":{\"uid\":\"1122\"},\"tags\":{\"workspace\":\"CRM\",\"user\":\"bob\"},\"fields\":[{\"name\":\"Status\",\"from\":\"New\",\"to\":\"Open\",\"ttc\":124},{\"name\":\"Priority\",\"to\":\"2-Medium\"}]}"; - - private ObjectMapper mapper; - - - @Before - public void setUp() throws Exception { - - mapper = new ObjectMapper(); - - } - - @Test - public void test() throws IOException { - IssueChangeEvent result = mapper.readValue(ISSUE_CHANGE_EVENT, IssueChangeEvent.class); - System.out.println("done!"); - } - -} diff --git a/src/test/java/com/hp/gaia/mgs/dto/testrun/TestRunEventParserTest.java b/src/test/java/com/hp/gaia/mgs/dto/testrun/TestRunEventParserTest.java deleted file mode 100644 index aa962cd..0000000 --- a/src/test/java/com/hp/gaia/mgs/dto/testrun/TestRunEventParserTest.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.hp.gaia.mgs.dto.testrun; - -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import java.io.IOException; - -/** - * Created by belozovs on 7/16/2015. - */ -public class TestRunEventParserTest { - - private final static String CODE_TEST_RUN_EVENT = "{\"event\":\"code_testrun\",\"time\":\"2015-11-10T22:00:00Z\",\"source\":{\"repository\":\"git://github.com/hp/mqm-server\",\"branch\":\"master\"},\"id\":{\"package\":\"com.hp.mqm\",\"class\":\"FilterBuilder\",\"method\":\"TestLogicalOperators\"},\"tags\":{\"build_job\":\"backend_job\",\"browser\":\"firefox\",\"build_label\":\"1.7.0\"},\"result\":{\"status\":\"error\",\"error\":\"NullPointerException: ...\",\"setup_time\":35,\"tear_down_time\":20,\"run_time\":130}}"; - private final static String ALM_TEST_RUN_EVENT = "{\"event\":\"tm_testrun\",\"time\":\"2015-11-10T23:00:00Z\",\"source\":{\"server\":\"http://alm-saas.hp.com\",\"domain\":\"IT\",\"project\":\"Project A\"},\"id\":{\"instance\":\"245\",\"test_id\":\"34\"},\"tags\":{\"workspace\":\"CRM\",\"testset\":\"Regression\",\"user\":\"john\",\"type\":\"Manual\"},\"result\":{\"status\":\"Passed\",\"run_time\":380,\"steps\":[{\"name\":\"step 1\",\"status\":\"Passed\",\"runt_time\":12},{\"name\":\"step 2\",\"status\":\"Skipped\"},{\"name\":\"step 3\",\"status\":\"Passed\",\"runt_time\":368}]}}"; - private ObjectMapper mapper; - - - @Before - public void setUp() throws Exception { - - mapper = new ObjectMapper(); - - } - - @Test - public void testCodeTestRunEvent() throws IOException { - CodeTestRunEvent result = mapper.readValue(CODE_TEST_RUN_EVENT, CodeTestRunEvent.class); - System.out.println("done!"); - } - - @Test - public void testAlmTestRunEvent() throws IOException { - AlmTestRunEvent result = mapper.readValue(ALM_TEST_RUN_EVENT, AlmTestRunEvent.class); - System.out.println("done!"); - } - -} diff --git a/src/test/java/com/hp/gaia/mgs/services/MetricsCollectorServiceTest.java b/src/test/java/com/hp/gaia/mgs/services/MetricsCollectorServiceTest.java deleted file mode 100644 index f2321d6..0000000 --- a/src/test/java/com/hp/gaia/mgs/services/MetricsCollectorServiceTest.java +++ /dev/null @@ -1,78 +0,0 @@ -package com.hp.gaia.mgs.services; - -import com.hp.gaia.mgs.amqp.AmqpManager; -import com.hp.gaia.mgs.dto.change.IssueChangeEvent; -import com.hp.gaia.mgs.dto.change.IssueChangeToInfluxLineProtocol; -import com.rabbitmq.client.Channel; -import org.junit.Before; -import org.junit.Test; - -import java.util.*; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.spy; -import static org.mockito.Mockito.when; - -/** - * Created by belozovs on 7/19/2015. - */ -public class MetricsCollectorServiceTest { - - AmqpManager amqpManager = mock(AmqpManager.class); - Channel channel = mock(Channel.class); - private MetricsCollectorService mcs; - - - @Before - public void setUp() throws Exception { - mcs = new MetricsCollectorService(); - - mcs.amqpManager = amqpManager; - - } - - @Test - public void testEscapedString() throws Exception { - assertEquals("my\\ do\\\"uble\\ quoted\\ string\\ part\\ 1\\,\\ part\\ 2", new IssueChangeToInfluxLineProtocol().getEscapedString("my do\"uble quoted string part 1, part 2")); - } - - @Test - public void testQuoteString() throws Exception { - assertEquals("\"str\"", new IssueChangeToInfluxLineProtocol().getQuotedValue("str")); - } - - @Test - public void testPublishEvent() throws Exception { - - List eventList = new ArrayList<>(); - eventList.add(createIssueChangeEvent("aaa")); - eventList.add(createIssueChangeEvent("bbb")); - - when(amqpManager.getChannel()).thenReturn(channel); - //void method do nothing by default - keep it here just for the reference - // doNothing().when(channel).basicPublish(anyString(), anyString(), anyObject(), anyObject()); - - mcs.publishEvent(eventList, "1"); - - } - - private IssueChangeEvent createIssueChangeEvent(String prefix) { - - IssueChangeEvent ice = spy(IssueChangeEvent.class); -/* - Map valuesMap = new HashMap<>(); - valuesMap.put(prefix+"_numeric", 25); - valuesMap.put(prefix + "_string", "25"); - when(ice.getValues()).thenReturn(valuesMap); -*/ - ice.setTime(new Date()); - ice.setType(IssueChangeEvent.EVENT_TYPE); - ice.setId(Collections.singletonMap("uuid", prefix)); - ice.setSource(Collections.singletonMap("project", prefix)); - ice.setTags(Collections.singletonMap("server", prefix)); - - return ice; - } - -} \ No newline at end of file diff --git a/src/test/resources/default.properties b/src/test/resources/default.properties deleted file mode 100644 index a39d5bd..0000000 --- a/src/test/resources/default.properties +++ /dev/null @@ -1,8 +0,0 @@ -authServer=localhost:9001 -amqpHost=localhost -amqpPort=5672 -amqpUser=admin -amqpPassword= -amqpRoutingKey=events-indexer - -useAmqp=false \ No newline at end of file