Skip to content

Commit 78d2339

Browse files
authored
Merge pull request aol#276 from aol/sigar-provisioning
make sigar provisioning location configurable
2 parents d3f4a7d + bedb568 commit 78d2339

File tree

2 files changed

+56
-47
lines changed

2 files changed

+56
-47
lines changed

micro-machine-stats/src/main/java/com/aol/micro/server/machine/stats/sigar/StatsServletContextListener.java

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,43 @@
55
import javax.servlet.ServletContextEvent;
66
import javax.servlet.ServletContextListener;
77

8-
import kamon.sigar.SigarProvisioner;
9-
108
import org.slf4j.Logger;
119
import org.slf4j.LoggerFactory;
10+
import org.springframework.beans.factory.annotation.Value;
1211

1312
import com.aol.cyclops.util.ExceptionSoftener;
1413

14+
import kamon.sigar.SigarProvisioner;
1515

1616
public class StatsServletContextListener implements ServletContextListener {
1717

18-
private final Logger logger = LoggerFactory.getLogger(this.getClass());
19-
20-
@Override
21-
public void contextInitialized(ServletContextEvent sce) {
22-
23-
String workingDir = System.getProperty("user.dir");
24-
String destination = workingDir + "/sigar-lib";
25-
logger.info("java.library.path is {}", destination);
26-
System.setProperty("java.library.path", destination);
27-
28-
if(!new File(System.getProperty("java.library.path")).exists()){
29-
final File location = new File(System.getProperty("java.library.path"));
30-
try {
31-
SigarProvisioner.provision(location);
32-
} catch (Exception e) {
33-
throw ExceptionSoftener.throwSoftenedException(e);
34-
}
35-
36-
}
37-
}
38-
39-
@Override
40-
public void contextDestroyed(ServletContextEvent sce) {
41-
}
18+
private final Logger logger = LoggerFactory.getLogger(this.getClass());
19+
20+
@Value("${machine.stats.deploy.dir:#{null}}")
21+
String deployDir;
22+
23+
@Override
24+
public void contextInitialized(ServletContextEvent sce) {
25+
26+
String workingDir = deployDir == null ? System.getProperty("user.dir") : deployDir;
27+
String destination = workingDir + "/sigar-lib";
28+
29+
System.setProperty("java.library.path", destination);
30+
logger.info("java.library.path is {}", destination);
31+
if (!new File(
32+
System.getProperty("java.library.path")).exists()) {
33+
final File location = new File(
34+
System.getProperty("java.library.path"));
35+
try {
36+
SigarProvisioner.provision(location);
37+
} catch (Exception e) {
38+
throw ExceptionSoftener.throwSoftenedException(e);
39+
}
40+
41+
}
42+
}
43+
44+
@Override
45+
public void contextDestroyed(ServletContextEvent sce) {
46+
}
4247
}
Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package app.sigar.com.aol.micro.server;
22

3-
import static org.hamcrest.CoreMatchers.*;
3+
import static org.hamcrest.CoreMatchers.containsString;
44
import static org.junit.Assert.assertThat;
5+
import static org.junit.Assert.assertTrue;
56

67
import java.io.File;
78
import java.util.concurrent.ExecutionException;
@@ -15,34 +16,37 @@
1516
import com.aol.micro.server.module.ConfigurableModule;
1617
import com.aol.micro.server.testing.RestAgent;
1718

18-
@Microserver
19+
@Microserver(properties = { "machine.stats.deploy.dir", "/tmp" })
1920
public class StatsRunnerTest {
2021

21-
RestAgent rest = new RestAgent();
22+
RestAgent rest = new RestAgent();
2223

23-
MicroserverApp server;
24+
MicroserverApp server;
2425

25-
@Before
26-
public void startServer() {
27-
server = new MicroserverApp(ConfigurableModule.builder()
28-
.context("simple-app").build());
26+
@Before
27+
public void startServer() {
28+
new File(
29+
"/tmp/sigar-lib").delete();
30+
server = new MicroserverApp(
31+
ConfigurableModule.builder()
32+
.context("simple-app")
33+
.build());
2934

30-
server.start();
35+
server.start();
3136

32-
}
37+
}
3338

34-
@After
35-
public void stopServer() {
36-
server.stop();
37-
}
39+
@After
40+
public void stopServer() {
41+
server.stop();
42+
}
3843

39-
@Test
40-
public void runAppAndBasicTest() throws InterruptedException,
41-
ExecutionException {
44+
@Test
45+
public void runAppAndBasicTest() throws InterruptedException, ExecutionException {
4246

43-
assertThat(rest.get("http://localhost:8080/simple-app/stats/machine"),
44-
containsString("cpu-stats"));
45-
46-
}
47+
assertThat(rest.get("http://localhost:8080/simple-app/stats/machine"), containsString("cpu-stats"));
48+
assertTrue(new File(
49+
"/tmp/sigar-lib").exists());
50+
}
4751

4852
}

0 commit comments

Comments
 (0)