Skip to content

Commit 9018dfe

Browse files
authored
Merge pull request #1203 from cambridge-cares/1782-dev-upgrade-aqmesh-agent
1782 dev upgrade aqmesh agent
2 parents 5554269 + f970f5d commit 9018dfe

File tree

24 files changed

+1039
-426
lines changed

24 files changed

+1039
-426
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
<settingsSecurity>
2-
<master>MASTER_PASSWORD</master>
3-
</settingsSecurity>
2+
<master>MASTER_PASSWORD</master>
3+
</settingsSecurity>
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
<settings>
1+
<settings>
22
<!-- The path to the local repository Maven will use to store artifacts -->
33
<localRepository>${user.home}/.m2/repository</localRepository>
4-
4+
55
<!-- Will Maven prompt you when it needs input? If false, Maven will use a sensible default -->
66
<interactiveMode>false</interactiveMode>
7-
7+
88
<!-- Should Maven use the plugin-registry.xml to manage plugin version? -->
99
<usePluginRegistry>false</usePluginRegistry>
10-
10+
1111
<!-- Should Maven operate in offline mode? -->
1212
<offline>false</offline>
13-
13+
1414
<!-- Server credentials -->
1515
<servers>
1616
<server>
@@ -19,7 +19,7 @@
1919
<password>REPO_PASSWORD</password>
2020
</server>
2121
</servers>
22-
22+
2323
<profiles>
2424
<profile>
2525
<id>Default Profile</id>
@@ -34,7 +34,7 @@
3434
</releases>
3535
<snapshots>
3636
<enabled>true</enabled>
37-
</snapshots>
37+
</snapshots>
3838
</repository>
3939
</repositories>
4040
</profile>
@@ -43,5 +43,5 @@
4343
<!-- List of profiles that are active for all builds. -->
4444
<activeProfiles>
4545
<activeProfile>Default Profile</activeProfile>
46-
</activeProfiles>
47-
</settings>
46+
</activeProfiles>
47+
</settings>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<web-app
3+
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee/ http://java.sun.com/xml/ns/javaee/web-app_3_1.xsd"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
6+
metadata-complete="false"
7+
version="3.1">
8+
9+
<display-name>Aqmesh-input-agent</display-name>
10+
<description>Simple servlet to accept incoming request and retrieve readings from the aqmesh pod.</description>
11+
12+
<servlet>
13+
<servlet-name>AQMeshInputAgentServlet</servlet-name>
14+
<servlet-class>uk.ac.cam.cares.jps.agent.aqmesh.AQMeshInputAgentLauncher</servlet-class>
15+
</servlet>
16+
17+
<servlet-mapping>
18+
<servlet-name>AQMeshInputAgentServlet</servlet-name>
19+
<url-pattern>/</url-pattern>
20+
</servlet-mapping>
21+
22+
</web-app>

Agents/AQMeshInputAgent/AQMeshInputAgent/pom.xml

Lines changed: 77 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,25 @@
33

44
<modelVersion>4.0.0</modelVersion>
55
<groupId>uk.ac.cam.cares.jps</groupId>
6-
<artifactId>aqmesh_inputAgent</artifactId>
6+
<artifactId>aqmesh-input-agent</artifactId>
77
<version>1.3.0</version>
8-
<packaging>jar</packaging>
9-
8+
<packaging>war</packaging>
9+
1010
<!-- Project properties -->
1111
<properties>
1212
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1313
<maven.compiler.source>11</maven.compiler.source>
1414
<maven.compiler.target>11</maven.compiler.target>
15-
16-
<jps.base.version>1.30.0</jps.base.version>
17-
<!-- Artifact ID used to download Log4J2 config (for runtime) -->
18-
<log.artifact>java-logging-dev</log.artifact>
15+
<jps.base.version>1.41.1</jps.base.version>
1916
</properties>
2017

18+
<!-- Parent POM -->
19+
<parent>
20+
<groupId>uk.ac.cam.cares.jps</groupId>
21+
<artifactId>jps-parent-pom</artifactId>
22+
<version>2.2.0</version>
23+
</parent>
24+
2125
<!-- Profiles are used to switch between building for development and production
2226
environments. Use "-P profile-id" within an mvn command to build with a profile -->
2327
<profiles>
@@ -32,7 +36,6 @@
3236
<log.artifact>java-logging-dev</log.artifact>
3337
</properties>
3438
</profile>
35-
3639
<!-- This profile should be used for production builds. -->
3740
<profile>
3841
<id>prod-profile</id>
@@ -45,120 +48,71 @@
4548

4649
<!-- Build settings -->
4750
<build>
48-
<resources>
49-
<resource>
50-
<directory>${basedir}/logging</directory>
51-
</resource>
52-
<!-- Copies the downloaded default logger config into the compiled classes folder -->
53-
<resource>
54-
<directory>${project.build.directory}/${project.build.finalName}.conf</directory>
55-
<includes>
56-
<include>**/*.xml</include>
57-
</includes>
58-
</resource>
59-
</resources>
60-
6151
<plugins>
62-
6352
<plugin>
6453
<groupId>org.apache.maven.plugins</groupId>
6554
<artifactId>maven-compiler-plugin</artifactId>
66-
<version>3.7.0</version>
6755
<configuration>
68-
<source>${maven.compiler.source}</source>
69-
<target>${maven.compiler.target}</target>
56+
<release>11</release>
7057
</configuration>
7158
</plugin>
72-
73-
<!-- Maven plugin for unit tests -->
59+
<!-- Maven plugin for unit tests -->
7460
<plugin>
7561
<groupId>org.apache.maven.plugins</groupId>
7662
<artifactId>maven-surefire-plugin</artifactId>
77-
<version>2.22.0</version>
63+
<configuration>
64+
<argLine>
65+
--illegal-access=permit
66+
</argLine>
67+
</configuration>
7868
</plugin>
79-
80-
<!-- Downloads and extracts ZIP archives from Maven repository -->
69+
<!-- Maven plugin for packaging -->
8170
<plugin>
8271
<groupId>org.apache.maven.plugins</groupId>
83-
<artifactId>maven-dependency-plugin</artifactId>
84-
<version>3.2.0</version>
85-
<executions>
86-
87-
<!-- Downloads the Log4J2 config that will be used at runtime -->
88-
<execution>
89-
<id>download-runtime-log-config</id>
90-
<phase>initialize</phase>
91-
<goals>
92-
<goal>unpack</goal>
93-
</goals>
94-
95-
<configuration>
96-
<artifactItems>
97-
<artifactItem>
98-
<groupId>uk.ac.cam.cares.jps</groupId>
99-
<artifactId>${log.artifact}</artifactId>
100-
<version>1.0.0-SNAPSHOT</version>
101-
<type>zip</type>
102-
<overWrite>true</overWrite>
103-
<outputDirectory>${project.build.directory}/${project.build.finalName}.conf</outputDirectory>
104-
</artifactItem>
105-
</artifactItems>
106-
</configuration>
107-
</execution>
108-
109-
<!-- Copy dependencies in separate folder within build directory -->
110-
<execution>
111-
<id>copy-dependencies</id>
112-
<phase>prepare-package</phase>
113-
<goals>
114-
<goal>copy-dependencies</goal>
115-
</goals>
116-
<configuration>
117-
<outputDirectory>${project.build.directory}/${project.build.finalName}.lib</outputDirectory>
118-
</configuration>
119-
</execution>
120-
</executions>
72+
<artifactId>maven-war-plugin</artifactId>
12173
</plugin>
122-
123-
124-
<!-- Maven plugin for packaging -->
74+
<!-- Downloads and extracts ZIP archives from Maven repository -->
12575
<plugin>
12676
<groupId>org.apache.maven.plugins</groupId>
127-
<artifactId>maven-jar-plugin</artifactId>
128-
<version>3.2.0</version>
129-
<configuration>
130-
<archive>
131-
<manifest>
132-
<addClasspath>true</addClasspath>
133-
<useUniqueVersions>false</useUniqueVersions>
134-
<!-- To use the dependencies copied in separate folder -->
135-
<classpathPrefix>${project.build.finalName}.lib/</classpathPrefix>
136-
<mainClass>uk.ac.cam.cares.jps.agent.aqmesh.AQMeshInputAgentLauncher</mainClass>
137-
</manifest>
138-
</archive>
139-
</configuration>
77+
<artifactId>maven-dependency-plugin</artifactId>
78+
<!-- Version, configuration, and executions should be pulled from the
79+
parent POM unless overridden here. -->
14080
</plugin>
141-
14281
</plugins>
14382
</build>
144-
83+
14584
<!-- Dependencies -->
14685
<dependencies>
14786

87+
<dependency>
88+
<groupId>javax.servlet</groupId>
89+
<artifactId>javax.servlet-api</artifactId>
90+
<version>3.1.0</version>
91+
<scope>compile</scope>
92+
</dependency>
93+
14894
<!-- JSON handling -->
14995
<dependency>
15096
<groupId>org.json</groupId>
15197
<artifactId>json</artifactId>
152-
<version>20210307</version>
98+
<version>20180813</version>
99+
<type>jar</type>
153100
</dependency>
154-
101+
155102
<!-- JPS Base Library -->
156103
<dependency>
157104
<groupId>uk.ac.cam.cares.jps</groupId>
158105
<artifactId>jps-base-lib</artifactId>
159106
<version>${jps.base.version}</version>
160107
</dependency>
161108

109+
<!-- for interacting with the stack -->
110+
<dependency>
111+
<groupId>com.cmclinnovations</groupId>
112+
<artifactId>stack-clients</artifactId>
113+
<version>1.22.0</version>
114+
</dependency>
115+
162116
<!-- For sending HTTP request to the API -->
163117
<dependency>
164118
<groupId>org.apache.httpcomponents</groupId>
@@ -177,28 +131,51 @@
177131
<artifactId>log4j-core</artifactId>
178132
<version>2.17.0</version>
179133
</dependency>
180-
181-
<!-- Testing -->
182134
<dependency>
183-
<groupId>junit</groupId>
184-
<artifactId>junit</artifactId>
185-
<version>4.13</version>
186-
<scope>test</scope>
135+
<groupId>org.apache.logging.log4j</groupId>
136+
<artifactId>log4j-web</artifactId>
137+
<version>2.17.0</version>
187138
</dependency>
139+
188140
<!-- For mocking APIs -->
189141
<dependency>
190-
<groupId>com.github.tomakehurst</groupId>
191-
<artifactId>wiremock-jre8-standalone</artifactId>
192-
<version>2.29.1</version>
142+
<groupId>org.wiremock</groupId>
143+
<artifactId>wiremock</artifactId>
144+
<version>3.3.1</version>
193145
<scope>test</scope>
194146
</dependency>
147+
195148
<!-- For mocking static methods -->
196149
<dependency>
197150
<groupId>org.mockito</groupId>
198-
<artifactId>mockito-inline</artifactId>
199-
<version>3.11.2</version>
151+
<artifactId>mockito-core</artifactId>
152+
<version>5.4.0</version>
153+
<scope>test</scope>
154+
</dependency>
155+
<dependency>
156+
<groupId>org.mockito</groupId>
157+
<artifactId>mockito-junit-jupiter</artifactId>
158+
<version>5.4.0</version>
159+
</dependency>
160+
<!-- Used to mock environment variables in testing -->
161+
<dependency>
162+
<groupId>com.github.stefanbirkner</groupId>
163+
<artifactId>system-lambda</artifactId>
164+
<version>1.2.0</version>
165+
<scope>test</scope>
166+
</dependency>
167+
<dependency>
168+
<groupId>me.xdrop</groupId>
169+
<artifactId>fuzzywuzzy</artifactId>
170+
<version>1.4.0</version>
171+
</dependency>
172+
<dependency>
173+
<groupId>org.junit.jupiter</groupId>
174+
<artifactId>junit-jupiter</artifactId>
175+
<version>RELEASE</version>
200176
<scope>test</scope>
201177
</dependency>
178+
202179
<!-- For creating docker containers in tests -->
203180
<dependency>
204181
<groupId>org.testcontainers</groupId>
@@ -218,7 +195,5 @@
218195
<version>1.15.3</version>
219196
<scope>test</scope>
220197
</dependency>
221-
222198
</dependencies>
223-
224-
</project>
199+
</project>

Agents/AQMeshInputAgent/AQMeshInputAgent/src/main/java/uk/ac/cam/cares/jps/agent/aqmesh/AQMeshAPIConnector.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,15 +205,16 @@ public String ping() throws IOException {
205205
/**
206206
* Retrieves and sets the location of the AQMesh
207207
*/
208-
private void setLocation() throws IOException, JSONException {
208+
public JSONObject setLocation() throws IOException, JSONException {
209+
JSONArray responseBody;
209210
try (CloseableHttpClient httpclient = HttpClients.createDefault()) {
210211
HttpGet assetRequest = new HttpGet(api_url + ASSETS_PATH);
211212
setTokenAuthorization(assetRequest);
212213

213214
try (CloseableHttpResponse response = httpclient.execute(assetRequest)) {
214215
int status = response.getStatusLine().getStatusCode();
215216
if (status == 200) {
216-
JSONArray responseBody = new JSONArray(EntityUtils.toString(response.getEntity()));
217+
responseBody = new JSONArray(EntityUtils.toString(response.getEntity()));
217218
if (responseBody.isEmpty()) {
218219
throw new JSONException("No assets available in returned JSON Array.");
219220
}
@@ -225,6 +226,7 @@ private void setLocation() throws IOException, JSONException {
225226
else {
226227
throw new HttpResponseException(status, "Could not retrieve location number.");
227228
}
229+
return responseBody.getJSONObject(podIndex);
228230
}
229231
}
230232
}

0 commit comments

Comments
 (0)