Skip to content

Commit aa57474

Browse files
authored
Merge pull request #56 from ChannelFinder/updates_and_integrationtests_adjust
Updates and integrationtests adjust
2 parents 9b08922 + 9139c27 commit aa57474

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+6789
-319
lines changed

.gitignore

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,10 @@
55
/.classpath
66
.pydevproject
77
*.iml
8-
**/site/sphinx/build/*
8+
**/site/sphinx/build/*
9+
10+
### Eclipse ###
11+
.settings/org.eclipse.jdt.core.prefs
12+
13+
### Docker ###
14+
docker-compose-local*

Dockerfile.integrationtest

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# ------------------------------------------------------------------------------
2+
# Copyright (C) 2021 European Spallation Source ERIC.
3+
#
4+
# This program is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU General Public License
6+
# as published by the Free Software Foundation; either version 2
7+
# of the License, or (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program; if not, write to the Free Software
16+
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17+
# ------------------------------------------------------------------------------
18+
19+
FROM openjdk:11
20+
21+
# deployment unit
22+
COPY target/ChannelFinder-*.jar /channelfinder/ChannelFinder-*.jar
23+
24+
CMD ["java", "-jar", "/channelfinder/ChannelFinder-*.jar", "--spring.config.name=application"]

docker-compose-integrationtest.yml

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# ------------------------------------------------------------------------------
2+
# Copyright (C) 2021 European Spallation Source ERIC.
3+
#
4+
# This program is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU General Public License
6+
# as published by the Free Software Foundation; either version 2
7+
# of the License, or (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program; if not, write to the Free Software
16+
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17+
# ------------------------------------------------------------------------------
18+
19+
version: "3.7"
20+
services:
21+
channelfinder:
22+
build:
23+
context: .
24+
dockerfile: Dockerfile.integrationtest
25+
hostname: channelfinder
26+
networks:
27+
- channelfinder-net
28+
ports:
29+
- 8080:8080
30+
- 8443:8443
31+
depends_on:
32+
- elasticsearch
33+
environment:
34+
elasticsearch.network.host: elasticsearch-cf
35+
ldap.enabled: "false"
36+
embedded_ldap.enabled: "false"
37+
demo_auth.enabled: "true"
38+
command: >
39+
/bin/bash -c "
40+
until curl -s -f http://elasticsearch-cf:9200/_cluster/health; do
41+
echo Waiting for Elasticsearch;
42+
sleep 1;
43+
done;
44+
java -jar /channelfinder/ChannelFinder-*.jar --spring.config.name=application"
45+
46+
elasticsearch:
47+
image: docker.elastic.co/elasticsearch/elasticsearch:8.2.0
48+
hostname: elasticsearch-cf
49+
networks:
50+
- channelfinder-net
51+
ports:
52+
- 9200:9200
53+
- 9300:9300
54+
environment:
55+
cluster.name: channelfinder
56+
bootstrap.memory_lock: "true"
57+
discovery.type: single-node
58+
ES_JAVA_OPTS: "-Xms512m -Xmx512m"
59+
xpack.security.enabled: "false"
60+
volumes:
61+
- channelfinder-es-data:/usr/share/elasticsearch/data
62+
63+
volumes:
64+
channelfinder-es-data:
65+
driver: local
66+
67+
networks:
68+
channelfinder-net:
69+
driver: bridge

pom.xml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
</developers>
3838
<properties>
3939
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
40-
<spring.boot-version>2.6.7</spring.boot-version>
40+
<spring.boot-version>2.7.3</spring.boot-version>
4141
<elasticsearch.version>8.2.0</elasticsearch.version>
4242
</properties>
4343
<dependencyManagement>
@@ -159,6 +159,18 @@
159159
<artifactId>spring-boot-starter-test</artifactId>
160160
<scope>test</scope>
161161
</dependency>
162+
<dependency>
163+
<groupId>org.testcontainers</groupId>
164+
<artifactId>testcontainers</artifactId>
165+
<version>1.17.3</version>
166+
<scope>test</scope>
167+
</dependency>
168+
<dependency>
169+
<groupId>org.testcontainers</groupId>
170+
<artifactId>junit-jupiter</artifactId>
171+
<version>1.17.3</version>
172+
<scope>test</scope>
173+
</dependency>
162174
</dependencies>
163175
<build>
164176
<plugins>

src/main/java/org/phoebus/channelfinder/Application.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2626
import org.springframework.boot.autoconfigure.SpringBootApplication;
2727
import org.springframework.context.annotation.ComponentScan;
28-
import org.springframework.context.annotation.PropertySource;
2928
import org.springframework.util.FileCopyUtils;
3029

3130
@EnableAutoConfiguration

src/main/java/org/phoebus/channelfinder/AuthorizationService.java

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import org.springframework.beans.factory.annotation.Value;
1111
import org.springframework.security.core.Authentication;
1212
import org.springframework.security.core.GrantedAuthority;
13-
import org.springframework.security.core.authority.SimpleGrantedAuthority;
1413
import org.springframework.stereotype.Service;
1514

1615
@Service
@@ -23,27 +22,27 @@ public class AuthorizationService {
2322

2423
@Value("${admin-groups:cf-admins}")
2524
void initializeAdminRoles(String groups) {
26-
this.admin_groups = Arrays.asList(groups.split(",")).stream().map(g -> {
27-
return "ROLE_" + g.trim().toUpperCase();
28-
}).collect(Collectors.toList());
25+
AuthorizationService.admin_groups = Arrays.asList(groups.split(",")).stream().map(g ->
26+
"ROLE_" + g.trim().toUpperCase()
27+
).collect(Collectors.toList());
2928
}
3029
@Value("${channel-groups:cf-channels}")
3130
void initializeChannelModRoles(String groups) {
32-
this.channel_groups = Arrays.asList(groups.split(",")).stream().map(g -> {
33-
return "ROLE_" + g.trim().toUpperCase();
34-
}).collect(Collectors.toList());
31+
AuthorizationService.channel_groups = Arrays.asList(groups.split(",")).stream().map(g ->
32+
"ROLE_" + g.trim().toUpperCase()
33+
).collect(Collectors.toList());
3534
}
3635
@Value("${property-groups:cf-properties}")
3736
void initializePropertyRoles(String groups) {
38-
this.property_groups = Arrays.asList(groups.split(",")).stream().map(g -> {
39-
return "ROLE_" + g.trim().toUpperCase();
40-
}).collect(Collectors.toList());
37+
AuthorizationService.property_groups = Arrays.asList(groups.split(",")).stream().map(g ->
38+
"ROLE_" + g.trim().toUpperCase()
39+
).collect(Collectors.toList());
4140
}
4241
@Value("${tag-groups:cf-tags}")
4342
void initializeTagRoles(String groups) {
44-
this.tag_groups = Arrays.asList(groups.split(",")).stream().map(g -> {
45-
return "ROLE_" + g.trim().toUpperCase();
46-
}).collect(Collectors.toList());
43+
AuthorizationService.tag_groups = Arrays.asList(groups.split(",")).stream().map(g ->
44+
"ROLE_" + g.trim().toUpperCase()
45+
).collect(Collectors.toList());
4746
}
4847

4948
public enum ROLES {
@@ -57,11 +56,10 @@ public enum ROLES {
5756
private ROLES(List<String> groups) {
5857
this.groups = groups;
5958
}
60-
61-
};
59+
}
6260

6361
public boolean isAuthorizedOwner(Authentication authentication, XmlTag data) {
64-
ArrayList<String> auth = new ArrayList<String>();
62+
ArrayList<String> auth = new ArrayList<>();
6563
Collection<? extends GrantedAuthority> auths = authentication.getAuthorities();
6664
for(GrantedAuthority a: auths)
6765
auth.add(a.getAuthority());
@@ -74,7 +72,7 @@ public boolean isAuthorizedOwner(Authentication authentication, XmlTag data) {
7472
}
7573

7674
public boolean isAuthorizedOwner(Authentication authentication, XmlProperty data) {
77-
ArrayList<String> auth = new ArrayList<String>();
75+
ArrayList<String> auth = new ArrayList<>();
7876
Collection<? extends GrantedAuthority> auths = authentication.getAuthorities();
7977
for(GrantedAuthority a: auths)
8078
auth.add(a.getAuthority());
@@ -87,7 +85,7 @@ public boolean isAuthorizedOwner(Authentication authentication, XmlProperty data
8785
}
8886

8987
public boolean isAuthorizedOwner(Authentication authentication, XmlChannel data) {
90-
ArrayList<String> auth = new ArrayList<String>();
88+
ArrayList<String> auth = new ArrayList<>();
9189
Collection<? extends GrantedAuthority> auths = authentication.getAuthorities();
9290
for(GrantedAuthority a: auths)
9391
auth.add(a.getAuthority());
@@ -100,7 +98,7 @@ public boolean isAuthorizedOwner(Authentication authentication, XmlChannel data)
10098
}
10199

102100
public boolean isAuthorizedRole(Authentication authentication, ROLES expectedRole) {
103-
ArrayList<String> auth = new ArrayList<String>();
101+
ArrayList<String> auth = new ArrayList<>();
104102
Collection<? extends GrantedAuthority> auths = authentication.getAuthorities();
105103
for(GrantedAuthority a: auths)
106104
auth.add(a.getAuthority());

src/main/java/org/phoebus/channelfinder/ChannelManager.java

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

1111
import javax.servlet.ServletContext;
1212

13-
import co.elastic.clients.elasticsearch._types.Refresh;
1413
import com.google.common.collect.Lists;
1514
import org.phoebus.channelfinder.AuthorizationService.ROLES;
1615
import org.springframework.beans.factory.annotation.Autowired;
@@ -184,9 +183,9 @@ public Iterable<XmlChannel> create(@RequestBody Iterable<XmlChannel> channels) {
184183
channel.getTags().forEach(tag -> tag.setOwner(tagRepository.findById(tag.getName()).get().getOwner()));
185184
}
186185

187-
channels.forEach(log -> {
188-
channelManagerAudit.info("PUT" + log.toLog());
189-
});
186+
channels.forEach(log ->
187+
channelManagerAudit.info("PUT" + log.toLog())
188+
);
190189

191190
// create new channels
192191
return channelRepository.indexAll(Lists.newArrayList(channels));

src/main/java/org/phoebus/channelfinder/ChannelRepository.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,13 @@
88
import java.util.logging.Level;
99
import java.util.logging.Logger;
1010
import java.util.stream.Collectors;
11-
import java.util.stream.Stream;
1211
import java.util.stream.StreamSupport;
1312

1413
import co.elastic.clients.elasticsearch._types.*;
1514
import co.elastic.clients.elasticsearch._types.query_dsl.*;
1615
import co.elastic.clients.elasticsearch.core.*;
1716
import co.elastic.clients.elasticsearch.core.bulk.BulkResponseItem;
18-
import co.elastic.clients.elasticsearch.core.bulk.UpdateOperation;
1917
import co.elastic.clients.elasticsearch.core.search.Hit;
20-
import co.elastic.clients.elasticsearch.core.search.ScoreMode;
2118
import co.elastic.clients.json.JsonData;
2219
import co.elastic.clients.json.jackson.JacksonJsonpMapper;
2320
import org.springframework.beans.factory.annotation.Autowired;
@@ -85,7 +82,6 @@ public XmlChannel index(XmlChannel channel) {
8582
* @param channels - channels to be created
8683
* @return the created channels
8784
*/
88-
@SuppressWarnings("unchecked")
8985
public List<XmlChannel> indexAll(List<XmlChannel> channels) {
9086
BulkRequest.Builder br = new BulkRequest.Builder();
9187

@@ -129,7 +125,6 @@ public List<XmlChannel> indexAll(List<XmlChannel> channels) {
129125
* @param channel - channel to be saved
130126
* @return the updated/saved channel
131127
*/
132-
@SuppressWarnings("unchecked")
133128
public XmlChannel save(String channelName, XmlChannel channel) {
134129
try {
135130
IndexResponse response = client.index(i -> i.index(ES_CHANNEL_INDEX)

src/main/java/org/phoebus/channelfinder/ChannelScroll.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import org.springframework.beans.factory.annotation.Value;
2222
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
2323
import org.springframework.http.HttpStatus;
24-
import org.springframework.util.LinkedMultiValueMap;
2524
import org.springframework.util.MultiValueMap;
2625
import org.springframework.web.bind.annotation.CrossOrigin;
2726
import org.springframework.web.bind.annotation.GetMapping;
@@ -38,7 +37,7 @@
3837
@RequestMapping(SCROLL_RESOURCE_URI)
3938
@EnableAutoConfiguration
4039
public class ChannelScroll {
41-
static Logger log = Logger.getLogger(ChannelRepository.class.getName());
40+
static Logger log = Logger.getLogger(ChannelScroll.class.getName());
4241

4342
@Value("${elasticsearch.channel.index:channelfinder}")
4443
private String ES_CHANNEL_INDEX;

src/main/java/org/phoebus/channelfinder/InfoManager.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public class InfoManager {
3535
@Autowired
3636
private ElasticConfig esService;
3737

38-
private final static ObjectMapper objectMapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
38+
private static final ObjectMapper objectMapper = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
3939

4040
/**
4141
*
@@ -44,11 +44,11 @@ public class InfoManager {
4444
@GetMapping
4545
public String info() {
4646

47-
Map<String, Object> cfServiceInfo = new LinkedHashMap<String, Object>();
47+
Map<String, Object> cfServiceInfo = new LinkedHashMap<>();
4848
cfServiceInfo.put("name", "ChannelFinder Service");
4949
cfServiceInfo.put("version", version);
5050

51-
Map<String, String> elasticInfo = new LinkedHashMap<String, String>();
51+
Map<String, String> elasticInfo = new LinkedHashMap<>();
5252
try {
5353

5454
ElasticsearchClient client = esService.getSearchClient();

0 commit comments

Comments
 (0)