Skip to content

Commit 3c1a089

Browse files
ned29tobiasake
authored andcommitted
ADD: backend instance information (#32)
* Test * Fixes * Fixes * Test * Fixes * Fixes * ADD: raml config * FIX: rest test * FIX: rest test * FIX: raml file
1 parent c6b4317 commit 3c1a089

File tree

17 files changed

+489
-163
lines changed

17 files changed

+489
-163
lines changed

pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
<plugin-version>0.8.6</plugin-version>
1818
<output-relative-path>src/main/java</output-relative-path>
1919
<raml-path>src/main/resources/public/raml/subscription.raml</raml-path>
20+
<raml-path>src/main/resources/public/raml/instance_info.raml</raml-path>
2021
<base-package>com.ericsson.ei.controller</base-package>
2122
</properties>
2223

@@ -168,7 +169,12 @@
168169
<version>2.0.0</version>
169170
<scope>test</scope>
170171
</dependency>
171-
172+
<dependency>
173+
<groupId>org.projectlombok</groupId>
174+
<artifactId>lombok</artifactId>
175+
<version>1.16.16</version>
176+
<scope>provided</scope>
177+
</dependency>
172178
</dependencies>
173179
<build>
174180
<plugins>
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Copyright 2017 Ericsson AB.
3+
For a full list of individual contributors, please see the commit history.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
package com.ericsson.ei.controller.info;
18+
19+
import org.springframework.web.bind.annotation.RequestMapping;
20+
import org.springframework.web.bind.annotation.RequestMethod;
21+
import org.springframework.web.bind.annotation.RestController;
22+
23+
/**
24+
* Provides interaction with InstanceInfo resource
25+
* (Generated with springmvc-raml-parser v.0.8.6)
26+
*/
27+
@RestController
28+
@RequestMapping(value = "/information", produces = "application/json")
29+
public interface InstanceInfoController {
30+
31+
/**
32+
* @return Instance information
33+
*/
34+
@RequestMapping(value = "", method = RequestMethod.GET)
35+
public String parseInfo();
36+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Copyright 2017 Ericsson AB.
3+
For a full list of individual contributors, please see the commit history.
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
Unless required by applicable law or agreed to in writing, software
9+
distributed under the License is distributed on an "AS IS" BASIS,
10+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
See the License for the specific language governing permissions and
12+
limitations under the License.
13+
*/
14+
package com.ericsson.ei.controller.info;
15+
16+
import com.ericsson.ei.controller.model.ParseInstanceInfoEI;
17+
import com.fasterxml.jackson.databind.ObjectMapper;
18+
import io.swagger.annotations.Api;
19+
import io.swagger.annotations.ApiOperation;
20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
22+
import org.springframework.beans.factory.annotation.Autowired;
23+
import org.springframework.stereotype.Component;
24+
import org.springframework.web.bind.annotation.CrossOrigin;
25+
26+
@Component
27+
@CrossOrigin
28+
@Api(value = "information", description = "The Information about Eiffel Intelligence Backend instance")
29+
public class InstanceInfoControllerImpl implements InstanceInfoController {
30+
private static final Logger LOGGER = (Logger) LoggerFactory.getLogger(InstanceInfoControllerImpl.class);
31+
32+
@Autowired
33+
private ParseInstanceInfoEI istanceInfo;
34+
35+
@Override
36+
@CrossOrigin
37+
@ApiOperation(value = "Parse information")
38+
public String parseInfo() {
39+
try {
40+
return new ObjectMapper().writerWithDefaultPrettyPrinter().writeValueAsString(istanceInfo);
41+
} catch (Exception e) {
42+
LOGGER.error("Serialization has failed " + e.getMessage());
43+
}
44+
return null;
45+
}
46+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
Copyright 2017 Ericsson AB.
3+
For a full list of individual contributors, please see the commit history.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
package com.ericsson.ei.controller.model;
18+
19+
import com.ericsson.ei.erqueryservice.ERQueryService;
20+
import com.ericsson.ei.handlers.ObjectHandler;
21+
import com.ericsson.ei.mongodbhandler.MongoDBHandler;
22+
import com.ericsson.ei.rmqhandler.RmqHandler;
23+
import com.ericsson.ei.subscriptionhandler.InformSubscription;
24+
import com.ericsson.ei.subscriptionhandler.SendMail;
25+
import com.ericsson.ei.subscriptionhandler.SubscriptionHandler;
26+
import com.ericsson.ei.waitlist.WaitListStorageHandler;
27+
import lombok.Getter;
28+
import org.springframework.beans.factory.annotation.Autowired;
29+
import org.springframework.beans.factory.annotation.Value;
30+
import org.springframework.stereotype.Component;
31+
32+
import java.util.List;
33+
34+
/**
35+
* Parsing all classes which contains value annotation in eiffel-intelligence plugin.
36+
* Needed for generate Json file with information about backend instance.
37+
*/
38+
@Component
39+
public class ParseInstanceInfoEI {
40+
@Getter
41+
@Value("${spring.application.name}")
42+
private String applicationName;
43+
44+
@Getter
45+
@Value("${build.version}")
46+
private String version;
47+
48+
@Getter
49+
@Autowired
50+
private List<RmqHandler> rabbitmq;
51+
52+
@Getter
53+
@Autowired
54+
private List<MongoDBHandler> mongodb;
55+
56+
@Getter
57+
@Autowired
58+
private List<ThreadsValue> threads;
59+
60+
@Getter
61+
@Autowired
62+
private List<SendMail> email;
63+
64+
@Getter
65+
@Autowired
66+
private List<WaitListStorageHandler> waitList;
67+
68+
@Getter
69+
@Autowired
70+
private ObjectHandler objectHandler;
71+
72+
@Getter
73+
@Autowired
74+
private SubscriptionHandler subscriptionHandler;
75+
76+
@Getter
77+
@Autowired
78+
private InformSubscription informSubscription;
79+
80+
@Getter
81+
@Autowired
82+
private ERQueryService erUrl;
83+
84+
@Component
85+
private class ThreadsValue {
86+
@Getter
87+
@Value("${threads.corePoolSize}")
88+
private int corePoolSize;
89+
90+
@Getter
91+
@Value("${threads.queueCapacity}")
92+
private int queueCapacity;
93+
94+
@Getter
95+
@Value("${threads.maxPoolSize}")
96+
private int maxPoolSize;
97+
}
98+
}

src/main/java/com/ericsson/ei/erqueryservice/ERQueryService.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,12 @@
1717
*/
1818
package com.ericsson.ei.erqueryservice;
1919

20-
import java.io.IOException;
21-
import java.util.ArrayList;
2220
import java.util.HashMap;
23-
import java.util.List;
2421
import java.util.Map;
2522

2623
import javax.annotation.PostConstruct;
2724

25+
import lombok.Getter;
2826
import org.slf4j.Logger;
2927
import org.slf4j.LoggerFactory;
3028
import org.springframework.beans.factory.annotation.Value;
@@ -39,7 +37,6 @@
3937
import org.springframework.web.client.RestOperations;
4038
import org.springframework.web.util.UriComponentsBuilder;
4139

42-
import com.fasterxml.jackson.core.JsonProcessingException;
4340
import com.fasterxml.jackson.databind.JsonNode;
4441
import com.fasterxml.jackson.databind.ObjectMapper;
4542
import com.fasterxml.jackson.databind.node.ArrayNode;
@@ -60,13 +57,10 @@ public class ERQueryService {
6057
public final static int UPSTREAM = 1;
6158
public final static int DOWNANDUPSTREAM = 2;
6259

60+
@Getter
6361
@Value("${er.url}")
6462
private String url;
6563

66-
public String getUrl() {
67-
return url;
68-
}
69-
7064
public ERQueryService(RestTemplateBuilder builder) {
7165
rest = builder.build();
7266
}

src/main/java/com/ericsson/ei/handlers/ObjectHandler.java

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
import com.ericsson.ei.subscriptionhandler.SubscriptionHandler;
2222
import com.mongodb.DBObject;
23+
import lombok.Getter;
24+
import lombok.Setter;
2325
import org.slf4j.Logger;
2426
import org.slf4j.LoggerFactory;
2527
import org.springframework.beans.factory.annotation.Autowired;
@@ -38,47 +40,30 @@ public class ObjectHandler {
3840

3941
static Logger log = (Logger) LoggerFactory.getLogger(ObjectHandler.class);
4042

41-
@Value("${aggregated.collection.name}") private String collectionName;
42-
@Value("${database.name}") private String databaseName;
43+
@Getter @Setter
44+
@Value("${aggregated.collection.name}")
45+
private String collectionName;
4346

44-
public void setCollectionName(String collectionName) {
45-
this.collectionName = collectionName;
46-
}
47-
48-
public void setDatabaseName(String databaseName) {
49-
this.databaseName = databaseName;
50-
}
47+
@Getter @Setter
48+
@Value("${database.name}")
49+
private String databaseName;
5150

51+
@Setter
5252
@Autowired
5353
private MongoDBHandler mongoDbHandler;
5454

55-
public void setMongoDbHandler(MongoDBHandler mongoDbHandler) {
56-
this.mongoDbHandler = mongoDbHandler;
57-
}
58-
55+
@Setter
5956
@Autowired
6057
private JmesPathInterface jmespathInterface;
6158

62-
public void setJmespathInterface(JmesPathInterface jmespathInterface) {
63-
this.jmespathInterface = jmespathInterface;
64-
}
65-
59+
@Setter
6660
@Autowired
6761
private EventToObjectMapHandler eventToObjectMap;
6862

69-
70-
public void setEventToObjectMap(EventToObjectMapHandler eventToObjectMap) {
71-
this.eventToObjectMap = eventToObjectMap;
72-
}
73-
63+
@Setter
7464
@Autowired
7565
private SubscriptionHandler subscriptionHandler;
7666

77-
public void setSubscriptionHandler(SubscriptionHandler subscriptionHandler) {
78-
this.subscriptionHandler = subscriptionHandler;
79-
}
80-
81-
8267
public boolean insertObject(String aggregatedObject, RulesObject rulesObject, String event, String id) {
8368
if (id == null) {
8469
String idRules = rulesObject.getIdRule();

src/main/java/com/ericsson/ei/mongodbhandler/MongoDBHandler.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
import javax.annotation.PostConstruct;
2222

23+
import lombok.Getter;
2324
import org.slf4j.Logger;
2425
import org.slf4j.LoggerFactory;
2526
import org.springframework.beans.factory.annotation.Value;
@@ -44,8 +45,13 @@ public void setMongoClient(MongoClient mongoClient) {
4445
this.mongoClient = mongoClient;
4546
}
4647

47-
@Value("${mongodb.host}") private String host;
48-
@Value("${mongodb.port}") private int port;
48+
@Getter
49+
@Value("${mongodb.host}")
50+
private String host;
51+
52+
@Getter
53+
@Value("${mongodb.port}")
54+
private int port;
4955

5056
//TODO establish connection automatically when Spring instantiate this
5157
// based on connection data in properties file
@@ -108,7 +114,7 @@ public ArrayList<String> getAllDocuments(String dataBaseName, String collectionN
108114
public ArrayList<String> find(String dataBaseName, String collectionName, String condition){
109115
ArrayList<String> result = new ArrayList<>();
110116
log.debug("Find and retrieve data from database: " + dataBaseName + " Collection: " + collectionName +
111-
"\nwith Condition: " + condition);
117+
"\nwith Condition: " + condition);
112118
try{
113119
DB db = mongoClient.getDB(dataBaseName);
114120
DBCollection table = db.getCollection(collectionName);
@@ -191,4 +197,4 @@ public void createTTLIndex(String dataBaseName, String collectionName,String fie
191197
db.getCollection(collectionName).createIndex(ttlField,ttlTime);
192198
}
193199

194-
}
200+
}

0 commit comments

Comments
 (0)