Skip to content

Commit 24bc1c5

Browse files
committed
Merge pull request #1 from PredixDev/develop
Pull to master for LA release - RC1
2 parents 963f33e + 19cb336 commit 24bc1c5

File tree

15 files changed

+604
-530
lines changed

15 files changed

+604
-530
lines changed

demo-adder-java/README.md

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
#demo-adder-java
22

3-
A java-based sample analytic for Predix Analytics.
3+
A java-based sample analytic for the Predix Analytics platform.
44

55
## Compiled binaries
66
Refer to the Releases page for compiled binaries you can upload directly to Predix Analytics.
77

88
## Pre-requisites
99
To build and run this analytic, you will need to have the following:
10+
1011
- JDK 1.7+
1112
- Maven 3+
1213

1314
## Building, deploying and running the analytic
1415
1. From the demo-analytics/demo-adder-java directory, run the `mvn clean install` command to build and perform the component test.
1516
2. Create an analytic in Analytics Catalog with the name "Demo Adder Java" and the version "v1".
16-
3. Upload the jar file demo-adder-java-1.0.0-SNAPSHOT.jar from the demo-adder-java/target directory and attach it to the created analytic entry.
17+
3. Upload the jar file demo-adder-java-1.0.0.jar from the demo-adder-java/target directory and attach it to the created analytic entry.
1718
4. Deploy and test the analytic on Predix Analytics platform.
1819

1920
## Input format
@@ -24,37 +25,18 @@ The expected JSON input data format is as follows:
2425
The JSON output format from the analytic is as follows:
2526
`{"result":579}`
2627

27-
## Testing the analytic locally
28-
1. From the demo-analytics/demo-adder-java directory, run the `mvn spring-boot:run` command to run the analytic locally.
29-
2. The analytic should come up using the TCP port defined in demo-analytics/demo-adder-java/src/main/resource/application.properties file.
30-
3. Using Chrome POSTMAN or curl, POST the REST request to http://localhost:9090/api/v1/demo_adder_java/execution. Set "Accept" header to "application/json". Set "Content-Type" header to "application/json". Specify the request body as defined in "Input format" section.
31-
3228
## Developing a java-based analytic
33-
Define the REST API with the URL of api/{version}/{analytic_name}/execution where
34-
- "api" is the URL prefix expected by Predix Analytics
35-
- {version} is based on the version of the analytic to be defined in the Analytic Catalog
36-
- {analytic_name} is based on the name of the analytic to be defined in the Analytic Catalog
37-
- "execution" is the REST resource name expected by Predix Analytics
38-
39-
40-
Note: The version of the analytic to be included in the URL should match that defined in the Analytic Catalog with the following modifications
41-
42-
- Substitute dots '.' with underscores '_'
43-
- Convert all letters to lower case
44-
45-
46-
Note: The name of the analytic to be included in the URL should match that defined in the Analytic Catalog with the following modifications
47-
48-
- Substitute spaces ' ' with underscores '_'
49-
- Convert all letters to lower case
50-
29+
1. Create an entry-point method which takes in the input data as a String and returns the output as a String.
30+
2. Create the JSON configuration file `src/main/resources/config.json` containing the className and MethodName definitions that instruct the generated wrapper code to call your designated entry point method with the request payload.
5131

52-
For example, suppose you defined the following analytic in the analytic catalog
32+
In this example, the entry-point is `add2Numbers` in the [DemoAdderJavaEntryPoint](src/main/java/com/ge/predix/analytics/demo/java/DemoAdderJavaEntryPoint.java) class.
33+
[config.json](src/main/resources/config.json) properly maps the entry point to the `add2Numbers` method of the `DemoAdderJavaEntryPoint` class.
34+
This method takes in a JSON String, maps it to a HashMap (see line 19), performs the computation, and returns the result as a new JSON String (see line 27).
5335

54-
- Name: Anomaly Detection
55-
- Version: v1.0
36+
## Deploying the analytic to the Predix Cloud
37+
When you upload the jar file as an 'Executable' artifact the platform wraps the executable as a web service exposing the analytic via a URI derived from the analytic name.
38+
Requests made to this generated URI will be passed to the entry point method.
5639

57-
Then define the REST URL as api/v1_0/anomaly_detection/execution
5840

5941

6042
For more information, see "Analytic Development" in the Predix Analytics Services documentation on Predix IO.

demo-adder-java/pom.xml

Lines changed: 29 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,91 +1,57 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
44

55
<modelVersion>4.0.0</modelVersion>
6-
<groupId>com.ge.predix.demo</groupId>
6+
<groupId>com.ge.predix.insight</groupId>
77
<artifactId>demo-adder-java</artifactId>
8-
<version>1.0.0-SNAPSHOT</version>
8+
<name>Demo adder analytic implementation</name>
99
<packaging>jar</packaging>
10-
11-
<name>demo-adder-java</name>
12-
<description>Demo adder java analytic microservice</description>
10+
<description>Implementation of java demo analytic service</description>
11+
<version>1.0.0</version>
1312

1413
<parent>
15-
<groupId>org.springframework.boot</groupId>
16-
<artifactId>spring-boot-starter-parent</artifactId>
17-
<version>1.2.1.RELEASE</version>
14+
<groupId>com.ge.predix.insight</groupId>
15+
<artifactId>analytics-catalog-service-parent</artifactId>
16+
<relativePath>../../</relativePath>
17+
<version>1.5.0-SNAPSHOT</version>
1818
</parent>
19-
20-
<properties>
21-
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
22-
<java.version>1.7</java.version>
23-
<commons-io.version>1.4</commons-io.version>
24-
<maven-failsafe-plugin.version>2.18.1</maven-failsafe-plugin.version>
25-
<rest-assured.version>2.4.0</rest-assured.version>
26-
<start-class>com.ge.predix.demo.DemoAnalyticApplication</start-class>
27-
</properties>
28-
2919
<dependencies>
20+
3021
<dependency>
31-
<groupId>org.springframework.boot</groupId>
32-
<artifactId>spring-boot-starter-web</artifactId>
33-
</dependency>
34-
<dependency>
35-
<groupId>org.springframework.boot</groupId>
36-
<artifactId>spring-boot-starter-test</artifactId>
37-
<scope>test</scope>
22+
<groupId>org.slf4j</groupId>
23+
<artifactId>slf4j-api</artifactId>
24+
<version>1.6.6</version>
25+
<scope>provided</scope>
3826
</dependency>
3927
<dependency>
40-
<groupId>commons-io</groupId>
41-
<artifactId>commons-io</artifactId>
42-
<version>${commons-io.version}</version>
43-
<scope>test</scope>
28+
<groupId>com.fasterxml.jackson.core</groupId>
29+
<artifactId>jackson-core</artifactId>
30+
<version>2.4.1</version>
31+
<scope>provided</scope>
4432
</dependency>
4533
<dependency>
46-
<groupId>com.jayway.restassured</groupId>
47-
<artifactId>rest-assured</artifactId>
48-
<version>${rest-assured.version}</version>
49-
<scope>test</scope>
34+
<groupId>com.fasterxml.jackson.core</groupId>
35+
<artifactId>jackson-databind</artifactId>
36+
<version>2.4.1</version>
37+
<scope>provided</scope>
5038
</dependency>
39+
5140
</dependencies>
5241

5342
<build>
5443
<plugins>
5544
<plugin>
56-
<groupId>org.springframework.boot</groupId>
57-
<artifactId>spring-boot-maven-plugin</artifactId>
45+
<groupId>org.apache.maven.plugins</groupId>
46+
<artifactId>maven-compiler-plugin</artifactId>
5847
<configuration>
59-
<mainClass>${start-class}</mainClass>
48+
<source>1.7</source>
49+
<target>1.7</target>
6050
</configuration>
61-
<executions>
62-
<execution>
63-
<goals>
64-
<goal>repackage</goal>
65-
</goals>
66-
</execution>
67-
</executions>
68-
</plugin>
69-
<plugin>
70-
<groupId>org.apache.maven.plugins</groupId>
71-
<artifactId>maven-failsafe-plugin</artifactId>
72-
<version>${maven-failsafe-plugin.version}</version>
73-
<executions>
74-
<execution>
75-
<goals>
76-
<goal>integration-test</goal>
77-
<goal>verify</goal>
78-
</goals>
79-
<configuration>
80-
<includes>
81-
<include>**/IT*.java</include>
82-
<include>**/CT*.java</include>
83-
</includes>
84-
</configuration>
85-
</execution>
86-
</executions>
8751
</plugin>
52+
8853
</plugins>
8954
</build>
9055

9156
</project>
57+

demo-adder-java/src/main/java/com/ge/predix/demo/DemoAnalyticRequest.java renamed to demo-adder-java/src/main/java/com/ge/predix/analytics/customdto/AdderRequest.java

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
1-
/*
2-
* Copyright (c) 2015 General Electric Company. All rights reserved.
3-
*
4-
* The copyright to the computer software herein is the property of
5-
* General Electric Company. The software may be used and/or copied only
6-
* with the written permission of General Electric Company or in accordance
7-
* with the terms and conditions stipulated in the agreement/contract
8-
* under which the software has been supplied.
9-
*/
10-
package com.ge.predix.demo;
11-
12-
public class DemoAnalyticRequest {
1+
package com.ge.predix.analytics.customdto;
2+
3+
public class AdderRequest {
134

145
protected long number1;
156
protected long number2;
@@ -47,10 +38,33 @@ public void setNumber2(long value) {
4738
}
4839

4940
@Override public String toString() {
50-
return "DemoAnalyticRequest{" +
41+
return "AdderInput{" +
5142
"number1=" + number1 +
5243
", number2=" + number2 +
5344
'}';
5445
}
5546

47+
@Override
48+
public boolean equals(Object o) {
49+
if (this == o)
50+
return true;
51+
if (o == null || getClass() != o.getClass())
52+
return false;
53+
54+
AdderRequest that = (AdderRequest) o;
55+
56+
if (number1 != that.number1)
57+
return false;
58+
if (number2 != that.number2)
59+
return false;
60+
61+
return true;
62+
}
63+
64+
@Override
65+
public int hashCode() {
66+
int result = (int) (number1 ^ (number1 >>> 32));
67+
result = 31 * result + (int) (number2 ^ (number2 >>> 32));
68+
return result;
69+
}
5670
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package com.ge.predix.analytics.customdto;
2+
3+
public class AdderResponse {
4+
5+
protected Long result;
6+
7+
@Override
8+
public boolean equals(Object o) {
9+
if (this == o)
10+
return true;
11+
if (o == null || getClass() != o.getClass())
12+
return false;
13+
14+
AdderResponse that = (AdderResponse) o;
15+
16+
if (result != null ? !result.equals(that.result) : that.result != null)
17+
return false;
18+
19+
return true;
20+
}
21+
22+
@Override
23+
public int hashCode() {
24+
return result != null ? result.hashCode() : 0;
25+
}
26+
27+
@Override public String toString() {
28+
return "AdderOutput{" +
29+
"result=" + result +
30+
31+
'}';
32+
}
33+
34+
/**
35+
* Gets the value of the result property.
36+
*
37+
38+
* @return
39+
* possible object is
40+
* {@link Long }
41+
*
42+
*/
43+
public Long getResult() {
44+
return result;
45+
}
46+
47+
/**
48+
* Sets the value of the result property.
49+
*
50+
* @param value
51+
* allowed object is
52+
* {@link Long }
53+
*
54+
*/
55+
public void setResult(Long value) {
56+
this.result = value;
57+
}
58+
59+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package com.ge.predix.analytics.demo.java;
2+
3+
import java.util.HashMap;
4+
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
7+
8+
import com.fasterxml.jackson.databind.ObjectMapper;
9+
import com.ge.predix.analytics.customdto.AdderResponse;
10+
11+
public class DemoAdderJavaEntryPoint {
12+
13+
Logger logger = LoggerFactory.getLogger(DemoAdderJavaEntryPoint.class);
14+
ObjectMapper mapper = new ObjectMapper();
15+
16+
public String add2Numbers(String jsonStr) {
17+
18+
try {
19+
HashMap<String, Integer> jsonDataMap = mapper.readValue(jsonStr, HashMap.class);
20+
long number1 = jsonDataMap.get("number1");
21+
long number2 = jsonDataMap.get("number2");
22+
23+
AdderResponse output = null;
24+
output = new AdderResponse();
25+
output.setResult(number1 + number2);
26+
27+
return mapper.writeValueAsString(output);
28+
29+
} catch (Exception e) {
30+
e.printStackTrace();
31+
throw new RuntimeException(e);
32+
}
33+
34+
}
35+
36+
}

demo-adder-java/src/main/java/com/ge/predix/demo/DemoAnalyticApplication.java

Lines changed: 0 additions & 23 deletions
This file was deleted.

0 commit comments

Comments
 (0)