diff --git a/Dockerfile b/Dockerfile index 40320a0f..6aefbb34 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,6 @@ FROM openjdk:11-jre WORKDIR /channelfinder -ADD https://repo1.maven.org/maven2/org/phoebus/app-channel-channelfinder/4.7.2/app-channel-channelfinder-4.7.2.jar . +ADD https://repo1.maven.org/maven2/org/phoebus/ChannelFinder/4.7.2/ChannelFinder-4.7.2.jar . + +CMD ["java", "-jar", "./ChannelFinder-*.jar", "--spring.config.name=application"] + diff --git a/src/main/java/org/phoebus/channelfinder/MetricsService.java b/src/main/java/org/phoebus/channelfinder/MetricsService.java index 17aa3ae0..82f82f00 100644 --- a/src/main/java/org/phoebus/channelfinder/MetricsService.java +++ b/src/main/java/org/phoebus/channelfinder/MetricsService.java @@ -11,80 +11,92 @@ import org.springframework.stereotype.Service; import org.springframework.util.LinkedMultiValueMap; +import java.util.ArrayList; import java.util.Arrays; -import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.stream.Collectors; - @Service @PropertySource(value = "classpath:application.properties") public class MetricsService { + private static final Logger logger = Logger.getLogger(MetricsService.class.getName()); + public static final String CF_TOTAL_CHANNEL_COUNT = "cf.total.channel.count"; + public static final String CF_PROPERTY_COUNT = "cf.property.count"; + public static final String CF_TAG_COUNT = "cf.tag.count"; + public static final String CF_CHANNEL_COUNT = "cf.channel.count"; + private static final String METRIC_DESCRIPTION_TOTAL_CHANNEL_COUNT = "Count of all ChannelFinder channels"; + private static final String METRIC_DESCRIPTION_PROPERTY_COUNT = "Count of all ChannelFinder properties"; + private static final String METRIC_DESCRIPTION_TAG_COUNT = "Count of all ChannelFinder tags"; + private static final String METRIC_DESCRIPTION_CHANNEL_COUNT = + "Count of channels with specific property with and specific value"; + private final ChannelRepository channelRepository; + private final PropertyRepository propertyRepository; + private final TagRepository tagRepository; + private final MeterRegistry meterRegistry; + + MultiGauge channelCounts; + @Value("${metrics.tags}") private String[] tags; - @Value("#{${metrics.properties:{'pvStatus': 'Active'}}}") - private Map properties; - - private static final Logger logger = Logger.getLogger(MetricsService.class.getName()); - private static final String METRIC_NAME_CHANNEL_COUNT = "cf_channel_count"; - private static final String METRIC_NAME_PROPERTIES_COUNT = "cf_properties_count"; - private static final String METRIC_NAME_TAGS_COUNT = "cf_tags_count"; - private static final String METRIC_NAME_CHANNEL_COUNT_PER_PROPERTY = "cf_channel_count_per_property"; - private static final String METRIC_NAME_CHANNEL_COUNT_PER_TAG = "cf_channel_count_per_tag"; - private static final String METRIC_DESCRIPTION_CHANNEL_COUNT = "Count of channel finder channels"; - private static final String METRIC_DESCRIPTION_PROPERTIES_COUNT = "Count of channel finder properties"; - private static final String METRIC_DESCRIPTION_TAGS_COUNT = "Count of channel finder tags"; - private static final String METRIC_DESCRIPTION_CHANNEL_COUNT_PER_PROPERTY = "Count of channels with specific property with and specific value"; - private static final String METRIC_DESCRIPTION_CHANNEL_COUNT_PER_TAG = "Count of channels with specific tag"; + @Value("#{${metrics.properties:{{'pvStatus', 'Active'}, {'pvStatus', 'Inactive'}}}}") + private String[][] properties; - private final ChannelRepository channelRepository; - private final PropertyRepository propertyRepository; @Autowired - public MetricsService(final ChannelRepository channelRepository, final PropertyRepository propertyRepository, final TagRepository tagRepository, final MeterRegistry meterRegistry) { + public MetricsService( + final ChannelRepository channelRepository, + final PropertyRepository propertyRepository, + final TagRepository tagRepository, + final MeterRegistry meterRegistry) { this.channelRepository = channelRepository; this.propertyRepository = propertyRepository; - registerGaugeMetrics(meterRegistry, tagRepository); + this.tagRepository = tagRepository; + this.meterRegistry = meterRegistry; + registerGaugeMetrics(); } - MultiGauge propertyCounts; - MultiGauge tagCounts; - - private void registerGaugeMetrics(MeterRegistry meterRegistry, TagRepository tagRepository){ - Gauge.builder(METRIC_NAME_CHANNEL_COUNT, () -> channelRepository.count(new LinkedMultiValueMap<>())) - .description(METRIC_DESCRIPTION_CHANNEL_COUNT) + private void registerGaugeMetrics() { + Gauge.builder(CF_TOTAL_CHANNEL_COUNT, () -> channelRepository.count(new LinkedMultiValueMap<>())) + .description(METRIC_DESCRIPTION_TOTAL_CHANNEL_COUNT) .register(meterRegistry); - Gauge.builder(METRIC_NAME_PROPERTIES_COUNT, - propertyRepository::count) - .description(METRIC_DESCRIPTION_PROPERTIES_COUNT) + Gauge.builder(CF_PROPERTY_COUNT, propertyRepository::count) + .description(METRIC_DESCRIPTION_PROPERTY_COUNT) .register(meterRegistry); - Gauge.builder(METRIC_NAME_TAGS_COUNT, - tagRepository::count) - .description(METRIC_DESCRIPTION_TAGS_COUNT) + Gauge.builder(CF_TAG_COUNT, tagRepository::count) + .description(METRIC_DESCRIPTION_TAG_COUNT) .register(meterRegistry); - - propertyCounts = MultiGauge.builder(METRIC_NAME_CHANNEL_COUNT_PER_PROPERTY) - .description(METRIC_DESCRIPTION_CHANNEL_COUNT_PER_PROPERTY) - .register(meterRegistry); - - tagCounts = MultiGauge.builder(METRIC_NAME_CHANNEL_COUNT_PER_TAG) - .description(METRIC_DESCRIPTION_CHANNEL_COUNT_PER_TAG) + channelCounts = MultiGauge.builder(CF_CHANNEL_COUNT) + .description(METRIC_DESCRIPTION_CHANNEL_COUNT) + .baseUnit("channels") .register(meterRegistry); - } - @Scheduled(fixedRate = 10000) + @Scheduled(fixedRate = 5000) public void updateMetrics() { - logger.log(Level.INFO, "Updating metrics"); - propertyCounts.register( - properties.entrySet().stream().map(property -> MultiGauge.Row.of(Tags.of(property.getKey(), property.getValue()), - channelRepository.countByProperty(property.getKey(), property.getValue()))).collect(Collectors.toList()) - ); - tagCounts.register( - Arrays.stream(tags).map(tag -> MultiGauge.Row.of(Tags.of("tag", tag), - channelRepository.countByTag(tag))).collect(Collectors.toList()) - ); + logger.log( + Level.FINER, + () -> "Updating metrics for properties " + Arrays.deepToString(properties) + " and tags " + Arrays.toString(tags)); + ArrayList> rows = new ArrayList<>(); + + // Add tags + for (String tag: tags) { + long count = channelRepository.countByTag(tag); + rows.add(MultiGauge.Row.of(Tags.of("tag", tag), count )); + logger.log( + Level.FINER, + () -> "Updating metrics for tag " + tag + " to " + count); + } + + // Add properties + for (String[] propertyValue: properties) { + long count = channelRepository.countByProperty(propertyValue[0], propertyValue[1]); + rows.add(MultiGauge.Row.of(Tags.of(propertyValue[0], propertyValue[1]), count)); + logger.log( + Level.FINER, + () -> "Updating metrics for property " + propertyValue[0] + ":" + propertyValue[1] + " to " + count); + } + + channelCounts.register(rows, true); } } diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 4e6a4d34..f692013f 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -13,17 +13,14 @@ server.ssl.key-alias=cf security.require-ssl=true -logging.level.org.springframework.web=INFO -spring.http.log-request-details=true - -# Enable HTTP/2 support, if the current environment supports it -server.http2.enabled=true - server.compression.enabled=true # opt in to content types server.compression.mime-types=application/json,application/xml,text/html,text/xml,text/plain,application/javascript,text/css # not worth the CPU cycles at some point, probably server.compression.min-response-size=1024 +# Enable HTTP/2 support, if the current environment supports it +server.http2.enabled=true +logging.level.org.springframework.web=INFO ############## LDAP - External ############## ldap.enabled = false @@ -36,6 +33,7 @@ ldap.groups.search.pattern = (memberUid= {1}) ############## LDAP - Embedded ############## embedded_ldap.enabled = false embedded_ldap.urls = ldap://localhost:8389/dc=cf,dc=local +embedded_ldap.base.dn = dc=cf,dc=local embedded_ldap.user.dn.pattern = uid={0},ou=People,dc=cf,dc=local embedded_ldap.groups.search.base = ou=Group,dc=cf,dc=local embedded_ldap.groups.search.pattern = (memberUid= {1}) @@ -58,7 +56,7 @@ demo_auth.users = admin,user demo_auth.pwds = adminPass,userPass demo_auth.roles = ADMIN,USER -############## Role --> group Mapping ############## +############## Group-->Role Mapping ############## # Customize group names here admin-groups=cf-admins,sys-admins,ADMIN channel-groups=cf-channels,USER @@ -67,13 +65,44 @@ tag-groups=cf-tags,USER ############################## Elastic Network And HTTP ############################### -# Elasticsearch host -#elasticsearch.network.host: 169.254.42.56 +# Elasticsearch, by default, binds itself to the 0.0.0.0 address, and listens +# on port [9200-9300] for HTTP traffic and on port [9300-9400] for node-to-node +# communication. (the range means that if the port is busy, it will automatically +# try the next port). + +# Set the bind address specifically (IPv4 or IPv6): +# +# network.bind_host: 169.254.42.56 + +# Set the address other nodes will use to communicate with this node. If not +# set, it is automatically derived. It must point to an actual IP address. +# +# network.publish_host: 192.168.0.1 + +# Set both 'bind_host' and 'publish_host': +# +elasticsearch.network.host: localhost + # Set a custom port for the node to node communication (9300 by default): +# #elasticsearch.transport.tcp.port: 9300 + +# Enable compression for all communication between nodes (disabled by default): +# +#transport.tcp.compress: true + # Set a custom port to listen for HTTP traffic: +# elasticsearch.http.port: 9200 +# Set a custom allowed content length: +# +#http.max_content_length: 100mb + +# Disable HTTP completely: +# +#http.enabled: false + # Elasticsearch index names and types used by channelfinder, ensure that any changes here should be replicated in the mapping_definitions.sh elasticsearch.tag.index = cf_tags elasticsearch.property.index = cf_properties @@ -101,8 +130,18 @@ aa.pva=false aa.archive_property_name=archive aa.archiver_property_name=archiver +# Set the auto pause behaviour +# +# Empty for no auto pause +# Or pvStatus to pause on pvStatus=Inactive +# Or match archive_property_name to pause on archive_property_name not existing +# Or both, i.e. aa.auto_pause=pvStatus,archive +# +aa.auto_pause=pvStatus,archive + + ############################## Metrics ############################### #actuator -management.endpoints.web.exposure.include=prometheus +management.endpoints.web.exposure.include=prometheus, metrics, health, info metrics.tags= -metrics.properties={'pvStatus': 'Active'} \ No newline at end of file +metrics.properties={{'pvStatus', 'Active'}, {'pvStatus', 'Inactive'}} \ No newline at end of file diff --git a/src/test/java/org/phoebus/channelfinder/ChannelRepositoryIT.java b/src/test/java/org/phoebus/channelfinder/ChannelRepositoryIT.java index 082489a5..995f7be7 100644 --- a/src/test/java/org/phoebus/channelfinder/ChannelRepositoryIT.java +++ b/src/test/java/org/phoebus/channelfinder/ChannelRepositoryIT.java @@ -476,40 +476,12 @@ public void setup() { @AfterEach public void cleanup() { - // clean up - testTags.forEach(tag -> { - try { - tagRepository.deleteById(tag.getName()); - } catch (Exception e) { - System.out.println("Failed to clean up tag: " + tag.getName()); - } - }); - testUpdatedTags.forEach(tag -> { - try { - tagRepository.deleteById(tag.getName()); - } catch (Exception e) { - System.out.println("Failed to clean up tag: " + tag.getName()); - } - }); - testProperties.forEach(property -> { - try { - propertyRepository.deleteById(property.getName()); - } catch (Exception e) { - System.out.println("Failed to clean up property: " + property.getName()); - } - }); - testUpdatedProperties.forEach(property -> { - try { - propertyRepository.deleteById(property.getName()); - } catch (Exception e) { - System.out.println("Failed to clean up property: " + property.getName()); - } - }); - cleanupTestChannels.forEach(channel -> { - if (channelRepository.existsById(channel.getName())) { - channelRepository.deleteById(channel.getName()); - } - }); + + MultiValueMap map = new LinkedMultiValueMap<>(); + map.set("~name", "*"); + channelRepository.search(map).getChannels().forEach(c -> channelRepository.deleteById(c.getName())); + tagRepository.findAll().forEach(t -> tagRepository.deleteById(t.getName())); + propertyRepository.findAll().forEach(p -> propertyRepository.deleteById(p.getName())); } @AfterAll diff --git a/src/test/java/org/phoebus/channelfinder/ChannelRepositorySearchIT.java b/src/test/java/org/phoebus/channelfinder/ChannelRepositorySearchIT.java index 853035a8..2b7f4122 100644 --- a/src/test/java/org/phoebus/channelfinder/ChannelRepositorySearchIT.java +++ b/src/test/java/org/phoebus/channelfinder/ChannelRepositorySearchIT.java @@ -63,7 +63,6 @@ public void setup() throws InterruptedException { @AfterEach public void cleanup() throws InterruptedException { populateService.cleanupDB(); - Thread.sleep(5000); } /** diff --git a/src/test/java/org/phoebus/channelfinder/ChannelScrollIT.java b/src/test/java/org/phoebus/channelfinder/ChannelScrollIT.java index a6675650..c9e4f372 100644 --- a/src/test/java/org/phoebus/channelfinder/ChannelScrollIT.java +++ b/src/test/java/org/phoebus/channelfinder/ChannelScrollIT.java @@ -47,7 +47,6 @@ public void setup() throws InterruptedException { @AfterEach public void cleanup() throws InterruptedException { populateService.cleanupDB(); - Thread.sleep(10000); } @BeforeAll diff --git a/src/test/java/org/phoebus/channelfinder/MetricsServiceIT.java b/src/test/java/org/phoebus/channelfinder/MetricsServiceIT.java new file mode 100644 index 00000000..b0593436 --- /dev/null +++ b/src/test/java/org/phoebus/channelfinder/MetricsServiceIT.java @@ -0,0 +1,167 @@ +package org.phoebus.channelfinder; + +import org.junit.jupiter.api.AfterAll; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.phoebus.channelfinder.entity.Channel; +import org.phoebus.channelfinder.entity.Property; +import org.phoebus.channelfinder.entity.Tag; +import org.phoebus.channelfinder.example.PopulateService; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.util.LinkedMultiValueMap; +import org.springframework.util.MultiValueMap; + +import java.io.IOException; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.testcontainers.shaded.org.awaitility.Awaitility.await; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK, classes = Application.class) +@AutoConfigureMockMvc +@ActiveProfiles("metrics") +@TestPropertySource( + locations = "classpath:application_test.properties", + properties = { + "metrics.tags=testTag0, testTag1", + "metrics.properties={{'testProperty0', 'testProperty0Value'}, {'testProperty1', 'testProperty1Value'}}" + }) +class MetricsServiceIT { + + private final List testTags = + Arrays.asList(new Tag("testTag0", "testTagOwner0"), new Tag("testTag1", "testTagOwner1")); + private final List testProperties = Arrays.asList( + new Property("testProperty0", "testPropertyOwner0"), + new Property("testProperty1", "testPropertyOwner1"), + new Property("testProperty2", "testPropertyOwner2")); + + @Autowired + ChannelRepository channelRepository; + + @Autowired + TagRepository tagRepository; + + @Autowired + PropertyRepository propertyRepository; + + @Autowired + ElasticConfig esService; + + @Autowired + PopulateService populateService; + + @Autowired + MetricsService metricsService; + + @Autowired + private MockMvc mockMvc; + + @BeforeAll + void setupAll() { + ElasticConfigIT.setUp(esService); + } + + @AfterAll + void tearDown() throws IOException { + ElasticConfigIT.teardown(esService); + } + + @AfterEach + public void cleanup() { + MultiValueMap map = new LinkedMultiValueMap<>(); + map.set("~name", "*"); + channelRepository.search(map).getChannels().forEach(c -> channelRepository.deleteById(c.getName())); + tagRepository.findAll().forEach(t -> tagRepository.deleteById(t.getName())); + propertyRepository.findAll().forEach(p -> propertyRepository.deleteById(p.getName())); + } + @Test + void testGaugeMetrics() throws Exception { + mockMvc.perform(get("/actuator/metrics")).andExpect(status().is(200)); + mockMvc.perform(get("/actuator/metrics/" + MetricsService.CF_TOTAL_CHANNEL_COUNT)) + .andExpect(jsonPath("$.measurements[0].value").value(0)); + mockMvc.perform(get("/actuator/metrics/" + MetricsService.CF_PROPERTY_COUNT)) + .andExpect(jsonPath("$.measurements[0].value").value(0)); + mockMvc.perform(get("/actuator/metrics/" + MetricsService.CF_TAG_COUNT)) + .andExpect(jsonPath("$.measurements[0].value").value(0)); + + Channel testChannel = new Channel("testChannel", "testOwner"); + channelRepository.save(testChannel); + propertyRepository.saveAll(testProperties); + tagRepository.saveAll(testTags); + + mockMvc.perform(get("/actuator/metrics/" + MetricsService.CF_TOTAL_CHANNEL_COUNT)) + .andExpect(jsonPath("$.measurements[0].value").value(1)); + mockMvc.perform(get("/actuator/metrics/" + MetricsService.CF_PROPERTY_COUNT)) + .andExpect(jsonPath("$.measurements[0].value").value(3)); + mockMvc.perform(get("/actuator/metrics/" + MetricsService.CF_TAG_COUNT)) + .andExpect(jsonPath("$.measurements[0].value").value(2)); + } + + @Test + void testTagMultiGaugeMetrics() throws Exception { + mockMvc.perform(get("/actuator/metrics/" + MetricsService.CF_CHANNEL_COUNT) + .param("tag", "tag:testTag0")) + .andExpect(jsonPath("$.measurements[0].value").value(0)); + mockMvc.perform(get("/actuator/metrics/" + MetricsService.CF_CHANNEL_COUNT) + .param("tag", "tag:testTag1")) + .andExpect(jsonPath("$.measurements[0].value").value(0)); + + tagRepository.saveAll(testTags); + + Channel testChannel = new Channel("testChannelTag", "testOwner", List.of(), testTags); + channelRepository.save(testChannel); + + await().untilAsserted(() -> { + mockMvc.perform(get("/actuator/metrics/" + MetricsService.CF_CHANNEL_COUNT) + .param("tag", "tag:testTag0")) + .andExpect(jsonPath("$.measurements[0].value").value(1)); + mockMvc.perform(get("/actuator/metrics/" + MetricsService.CF_CHANNEL_COUNT) + .param("tag", "tag:testTag1")) + .andExpect(jsonPath("$.measurements[0].value").value(1)); + }); + } + + @Test + void testPropertyMultiGaugeMetrics() throws Exception { + mockMvc.perform(get("/actuator/metrics/" + MetricsService.CF_CHANNEL_COUNT) + .param("tag", "testProperty0:testProperty0Value")) + .andExpect(jsonPath("$.measurements[0].value").value(0)); + mockMvc.perform(get("/actuator/metrics/" + MetricsService.CF_CHANNEL_COUNT) + .param("tag", "testProperty1:testProperty1Value")) + .andExpect(jsonPath("$.measurements[0].value").value(0)); + + + propertyRepository.saveAll(testProperties); + + Channel testChannel = new Channel( + "testChannelProp", + "testOwner", + testProperties.stream() + .map(p -> new Property(p.getName(), p.getOwner(), p.getName() + "Value")) + .collect(Collectors.toList()), + testTags); + channelRepository.save(testChannel); + + await().untilAsserted(() -> { + mockMvc.perform(get("/actuator/metrics/" + MetricsService.CF_CHANNEL_COUNT) + .param("tag", "testProperty0:testProperty0Value")) + .andExpect(jsonPath("$.measurements[0].value").value(1)); + mockMvc.perform(get("/actuator/metrics/" + MetricsService.CF_CHANNEL_COUNT) + .param("tag", "testProperty1:testProperty1Value")) + .andExpect(jsonPath("$.measurements[0].value").value(1)); + }); + } +} diff --git a/src/test/java/org/phoebus/channelfinder/PropertyManagerIT.java b/src/test/java/org/phoebus/channelfinder/PropertyManagerIT.java index b0c45f89..9bbb225d 100644 --- a/src/test/java/org/phoebus/channelfinder/PropertyManagerIT.java +++ b/src/test/java/org/phoebus/channelfinder/PropertyManagerIT.java @@ -69,20 +69,11 @@ public void setup() { @AfterEach public void cleanup() { - // clean up - testChannels.forEach(channel -> { - try { - if (channelRepository.existsById(channel.getName())) - channelRepository.deleteById(channel.getName()); - } catch (Exception e) { - System.out.println("Failed to clean up channel: " + channel.getName()); - } - }); - propertyRepository.findAll().forEach(property -> { - if (propertyRepository.existsById(property.getName())) { - propertyRepository.deleteById(property.getName()); - } - }); + + MultiValueMap map = new LinkedMultiValueMap<>(); + map.set("~name", "*"); + channelRepository.search(map).getChannels().forEach(c -> channelRepository.deleteById(c.getName())); + propertyRepository.findAll().forEach(p -> propertyRepository.deleteById(p.getName())); } @AfterAll void tearDown() throws IOException { diff --git a/src/test/java/org/phoebus/channelfinder/PropertyRepositoryIT.java b/src/test/java/org/phoebus/channelfinder/PropertyRepositoryIT.java index 970b14e0..435b57a3 100644 --- a/src/test/java/org/phoebus/channelfinder/PropertyRepositoryIT.java +++ b/src/test/java/org/phoebus/channelfinder/PropertyRepositoryIT.java @@ -268,17 +268,10 @@ void deleteXmlProperty() { @AfterEach public void cleanup() { - // clean up - cleanupTestProperties.forEach(property -> { - if (propertyRepository.existsById(property.getName())) { - propertyRepository.deleteById(property.getName()); - } - }); - - cleanupTestChannels.forEach(channel -> { - if (channelRepository.existsById(channel.getName())) { - channelRepository.deleteById(channel.getName()); - } - }); + + MultiValueMap map = new LinkedMultiValueMap<>(); + map.set("~name", "*"); + channelRepository.search(map).getChannels().forEach(c -> channelRepository.deleteById(c.getName())); + propertyRepository.findAll().forEach(p -> propertyRepository.deleteById(p.getName())); } } \ No newline at end of file diff --git a/src/test/java/org/phoebus/channelfinder/TagManagerIT.java b/src/test/java/org/phoebus/channelfinder/TagManagerIT.java index 0ab1ac68..2eab06a6 100644 --- a/src/test/java/org/phoebus/channelfinder/TagManagerIT.java +++ b/src/test/java/org/phoebus/channelfinder/TagManagerIT.java @@ -669,24 +669,11 @@ public void setup() { @AfterEach public void cleanup() { - // clean up - testChannels().forEach(channel -> { - try { - if(channelRepository.existsById(channel.getName())) - channelRepository.deleteById(channel.getName()); - } catch (Exception e) { - logger.log(Level.WARNING, "Failed to clean up channel: " + channel.getName()); - } - }); - // additional cleanup for "testChannelX" - if(channelRepository.existsById("testChannelX")) - channelRepository.deleteById("testChannelX"); - tagRepository.findAll().forEach(tag -> { - if (tagRepository.existsById(tag.getName())) { - tagRepository.deleteById(tag.getName()); - logger.log(Level.INFO, "deleted tag " + tag.getName()); - } - }); + + MultiValueMap map = new LinkedMultiValueMap<>(); + map.set("~name", "*"); + channelRepository.search(map).getChannels().forEach(c -> channelRepository.deleteById(c.getName())); + tagRepository.findAll().forEach(t -> tagRepository.deleteById(t.getName())); } /** diff --git a/src/test/java/org/phoebus/channelfinder/TagRepositoryIT.java b/src/test/java/org/phoebus/channelfinder/TagRepositoryIT.java index 5464f1cb..58996fac 100644 --- a/src/test/java/org/phoebus/channelfinder/TagRepositoryIT.java +++ b/src/test/java/org/phoebus/channelfinder/TagRepositoryIT.java @@ -241,11 +241,10 @@ void deleteXmlTag() { @AfterEach public void cleanup() { - // clean up - cleanupTestTags.forEach(tag -> { - if (tagRepository.existsById(tag.getName())) { - tagRepository.deleteById(tag.getName()); - } - }); + + MultiValueMap map = new LinkedMultiValueMap<>(); + map.set("~name", "*"); + channelRepository.search(map).getChannels().forEach(c -> channelRepository.deleteById(c.getName())); + tagRepository.findAll().forEach(t -> tagRepository.deleteById(t.getName())); } } \ No newline at end of file diff --git a/src/test/resources/application_test.properties b/src/test/resources/application_test.properties index df1aaa0c..78b60d53 100644 --- a/src/test/resources/application_test.properties +++ b/src/test/resources/application_test.properties @@ -1,6 +1,7 @@ ################## ChannelFinder Server #################### server.port=8443 +# Options support for unsecure http server.http.enable=true server.http.port=8080 @@ -22,7 +23,7 @@ logging.level.org.springframework.web=INFO ############## LDAP - External ############## ldap.enabled = false -ldap.urls = ldaps://controlns02.nsls2.bnl.gov/dc=nsls2,dc=bnl,dc=gov +#ldap.urls = ldaps://controlns02.nsls2.bnl.gov/dc=nsls2,dc=bnl,dc=gov ldap.base.dn = dc=nsls2,dc=bnl,dc=gov ldap.user.dn.pattern = uid={0},ou=People ldap.groups.search.base = ou=Group @@ -36,12 +37,19 @@ embedded_ldap.user.dn.pattern = uid={0},ou=People embedded_ldap.groups.search.base = ou=Group embedded_ldap.groups.search.pattern = (memberUid= {1}) spring.ldap.embedded.ldif=classpath:cf.ldif -spring.ldap.embedded.base-dn=dc=olog,dc=local -spring.ldap.embedded.port=8389 +spring.ldap.embedded.base-dn=dc=cf,dc=local +spring.ldap.embedded.port=8389 spring.ldap.embedded.validation.enabled=false ############## Demo Auth ############## +# users, pwds, roles - lists of comma-separated values (same length) +# roles may contain multiple roles for user separated by delimiter +# e.g. +# demo_auth.users = user1,user2 +# demo_auth.pwds = pwd1,pwd2 +# demo_auth.roles = role1,role2 +# demo_auth.roles = role1,role21:role22 demo_auth.enabled = true ############## Group-->Role Mapping ############## @@ -96,6 +104,20 @@ elasticsearch.tag.index = test_${random.int[1,1000]}_cf_tags elasticsearch.property.index = test_${random.int[1,1000]}_cf_properties elasticsearch.channel.index = test_${random.int[1,1000]}_channelfinder +# maximum query result size +elasticsearch.query.size = 10000 + +# Create the Channel Finder indices if they do not exist +elasticsearch.create.indices: true + +############################## Service Info ############################### +# ChannelFinder version as defined in the pom file +channelfinder.version=@project.version@ + +############################## REST Logging ############################### +# DEBUG level will log all requests and responses to and from the REST end points +logging.level.org.springframework.web.filter.CommonsRequestLoggingFilter=INFO + ################ Archiver Appliance Configuration Processor ################# aa.urls={'default': 'http://localhost:17665'} aa.default_alias=default @@ -115,8 +137,7 @@ aa.auto_pause=pvStatus,archive ############################## Metrics ############################### -#exclude metrics in tests - -management.endpoints.web.exposure.include=prometheus +#actuator +management.endpoints.web.exposure.include=prometheus, metrics, health, info metrics.tags=group4_10 -metrics.properties={'group4': '10'} \ No newline at end of file +metrics.properties={{'group4', '10'}, {'group5', '10'}} \ No newline at end of file