From 383fb267b5e0f613e798a6939bf48fc9f142c9d8 Mon Sep 17 00:00:00 2001 From: lha Date: Wed, 13 Nov 2024 18:03:10 +0100 Subject: [PATCH 01/10] Migration to 6.1 - WIP --- pom.xml | 39 +- .../ReverseEpochViewComparator.java | 6 +- .../activeviam/formatter/ByteFormatter.java | 6 +- .../activeviam/formatter/ClassFormatter.java | 6 +- .../formatter/PartitionIdFormatter.java | 6 +- .../activeviam/mac/app/MacSpringBootApp.java | 5 +- .../impl/ActivePivotWithDatastoreConfig.java | 48 +++ .../impl/ActiveUiResourceServerConfig.java | 2 +- .../mac/cfg/impl/ContentServiceConfig.java | 29 +- .../mac/cfg/impl/MacServerConfig.java | 35 +- .../cfg/impl/ManagerDescriptionConfig.java | 190 +++++++--- .../impl/NoWriteDatastoreServiceConfig.java | 6 +- .../activeviam/mac/cfg/impl/SourceConfig.java | 40 +- .../cfg/security/impl/ASecurityConfig.java | 321 ---------------- .../impl/ActiveUiSecurityConfigurer.java | 44 --- .../mac/cfg/security/impl/CorsConfig.java | 47 +++ .../security/impl/JwtSecurityConfigurer.java | 52 --- .../mac/cfg/security/impl/SecurityConfig.java | 352 +++++++++++++----- .../impl/VersionSecurityConfigurer.java | 20 - .../cfg/security/impl/WebConfiguration.java | 12 + .../mac/memory/AnalysisDatastoreFeeder.java | 53 +-- .../mac/memory/ChunkRecordHandler.java | 83 ++--- .../mac/memory/DatastoreConstants.java | 4 +- ...oryAnalysisDatastoreDescriptionConfig.java | 32 +- .../visitor/impl/ADatastoreFeedVisitor.java | 4 +- .../memory/visitor/impl/AFeedVisitor.java | 22 +- .../impl/AFeedVisitorWithDictionary.java | 18 +- .../impl/ChunkSetStatisticVisitor.java | 43 ++- .../visitor/impl/DatastoreFeederVisitor.java | 53 +-- .../memory/visitor/impl/DebugVisitor.java | 43 +-- .../memory/visitor/impl/FeedVisitor.java | 57 +-- .../visitor/impl/LevelStatisticVisitor.java | 35 +- .../visitor/impl/PivotFeederVisitor.java | 69 ++-- .../visitor/impl/StatisticTreePrinter.java | 2 +- .../visitor/impl/VectorStatisticVisitor.java | 35 +- .../java/com/activeviam/mac/tools/Tools.java | 4 +- .../tools/bookmark/impl/BookmarkTool.java | 2 +- .../bookmark/impl/ContentServerToJsonUi.java | 8 +- .../bookmark/impl/JsonUiToContentServer.java | 4 +- .../mac/TestMemoryStatisticBuilder.java | 35 +- .../activeviam/mac/app/TestAppLoading.java | 2 +- .../memory/ATestMemoryStatistic.java | 140 +++---- .../mac/statistic/memory/CellSetUtils.java | 2 +- .../TestAggregateProvidersBookmark.java | 30 +- .../memory/TestAnalysisDatastoreFeeder.java | 30 +- .../mac/statistic/memory/TestBranches.java | 27 +- .../memory/TestDistributedCubeEpochs.java | 22 +- .../mac/statistic/memory/TestEpochs.java | 37 +- .../statistic/memory/TestFieldsBookmark.java | 35 +- ...tFieldsBookmarkWithDuplicateFieldName.java | 35 +- .../TestIndexAndDictionaryBookmarks.java | 41 +- .../mac/statistic/memory/TestMACMeasures.java | 69 ++-- .../TestMemoryMonitoringDatastoreContent.java | 114 +++--- .../memory/TestMemoryStatisticLoading.java | 16 +- ...emoryStatisticLoadingWithReverseOrder.java | 10 +- .../memory/TestOverviewBookmark.java | 38 +- .../statistic/memory/TestRatioMeasures.java | 30 +- .../memory/TestVectorBlockBookmark.java | 35 +- .../mac/statistic/memory/TestViewEpochs.java | 25 +- ...ateProviderWithVectorPrimitiveMeasure.java | 58 +-- .../memory/scenarios/TestMissingChunkId.java | 47 +-- .../TestMultipleFieldsDictionary.java | 69 ++-- .../TestNullableLevelDictionary.java | 66 ++-- .../com/qfs/chunk/impl/MemoryTestUtils.java | 16 +- 64 files changed, 1423 insertions(+), 1443 deletions(-) create mode 100644 src/main/java/com/activeviam/mac/cfg/impl/ActivePivotWithDatastoreConfig.java delete mode 100644 src/main/java/com/activeviam/mac/cfg/security/impl/ASecurityConfig.java delete mode 100644 src/main/java/com/activeviam/mac/cfg/security/impl/ActiveUiSecurityConfigurer.java create mode 100644 src/main/java/com/activeviam/mac/cfg/security/impl/CorsConfig.java delete mode 100644 src/main/java/com/activeviam/mac/cfg/security/impl/JwtSecurityConfigurer.java delete mode 100644 src/main/java/com/activeviam/mac/cfg/security/impl/VersionSecurityConfigurer.java create mode 100644 src/main/java/com/activeviam/mac/cfg/security/impl/WebConfiguration.java diff --git a/pom.xml b/pom.xml index d95a761b..61a35501 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ 11 - 6.0.10 + 6.1.1 5.1.13 9.0.31 @@ -46,10 +46,20 @@ pom import + + jakarta.servlet + jakarta.servlet-api + 6.0.0 + + + com.activeviam.springboot + atoti-server-starter + ${atoti-server.version} + org.projectlombok lombok @@ -66,12 +76,7 @@ com.activeviam.tech - composer-intf - compile - - - com.activeviam.tech - composer-impl + composer-core compile @@ -169,11 +176,6 @@ guava 32.1.3-jre test - - - io.atoti - directquery-bigquery - ${atoti-server.version} com.activeviam.source @@ -188,7 +190,31 @@ jakarta.persistence jakarta.persistence-api - 3.2.0 + ${jakarta-persistence.version} + + + org.yaml + snakeyaml + 2.2 + + + jakarta.ws.rs + jakarta.ws.rs-api + ${jakarta-ws-rs.version} + + + org.springframework + spring-web + ${spring-framework.version} + + + org.apache.tomcat.embed + tomcat-embed-core + ${tomcat.version} + + + org.springframework.boot + spring-boot-autoconfigure diff --git a/src/main/java/com/activeviam/mac/app/MacSpringBootApp.java b/src/main/java/com/activeviam/mac/app/MacSpringBootApp.java index 23041e81..dfd3d01e 100644 --- a/src/main/java/com/activeviam/mac/app/MacSpringBootApp.java +++ b/src/main/java/com/activeviam/mac/app/MacSpringBootApp.java @@ -9,7 +9,7 @@ import com.activeviam.mac.cfg.impl.MacServerConfig; import com.activeviam.tech.core.api.registry.Registry; -import javax.servlet.MultipartConfigElement; +import jakarta.servlet.MultipartConfigElement; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; diff --git a/src/main/java/com/activeviam/mac/cfg/impl/ActiveUiResourceServerConfig.java b/src/main/java/com/activeviam/mac/cfg/impl/ActiveUiResourceServerConfig.java index 1a375375..8215b7ff 100644 --- a/src/main/java/com/activeviam/mac/cfg/impl/ActiveUiResourceServerConfig.java +++ b/src/main/java/com/activeviam/mac/cfg/impl/ActiveUiResourceServerConfig.java @@ -41,9 +41,9 @@ protected void registerRedirections(final ResourceRegistry registry) { protected void registerExtensions(final ResourceRegistry registry) { registry.serve("/ui/extensions*.json").addResourceLocations("classpath:/static/activeui/"); - registry - .serve("/ui/extensions/text-editor-extension/**/*.js") - .addResourceLocations("classpath:/static/activeui/extensions/text-editor-extension/"); + // registry + // .serve("/ui/extensions/text-editor-extension/**/*.js") + // .addResourceLocations("classpath:/static/activeui/extensions/text-editor-extension/"); } /** diff --git a/src/main/java/com/activeviam/mac/cfg/impl/ContentServiceConfig.java b/src/main/java/com/activeviam/mac/cfg/impl/ContentServiceConfig.java index 456667ba..b94d5fc8 100644 --- a/src/main/java/com/activeviam/mac/cfg/impl/ContentServiceConfig.java +++ b/src/main/java/com/activeviam/mac/cfg/impl/ContentServiceConfig.java @@ -23,6 +23,7 @@ import com.activeviam.tools.bookmark.constant.impl.ContentServerConstants.Paths; import com.activeviam.tools.bookmark.constant.impl.ContentServerConstants.Role; import com.activeviam.tools.bookmark.impl.BookmarkTool; +import java.io.IOException; import java.lang.reflect.Method; import java.util.List; import java.util.Map; @@ -37,6 +38,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; +import org.springframework.core.io.ClassPathResource; +import org.springframework.core.io.Resource; /** * Spring configuration of the Content Service. @@ -82,11 +85,13 @@ public class ContentServiceConfig implements IActivePivotContentServiceConfig { * @return the Hibernate's configuration */ private static SessionFactory loadConfiguration(final Properties hibernateProperties) - throws HibernateException { + throws HibernateException, IOException { hibernateProperties.put( AvailableSettings.DATASOURCE, createTomcatJdbcDataSource(hibernateProperties)); + final Resource entityMappingFile = new ClassPathResource("content-service-hibernate.xml"); return new org.hibernate.cfg.Configuration() .addProperties(hibernateProperties) + .addInputStream(entityMappingFile.getInputStream()) .buildSessionFactory(); } @@ -141,7 +146,7 @@ public IContentService contentService() { try { sessionFactory = loadConfiguration(contentServiceHibernateProperties()); return new HibernateContentService(sessionFactory); - } catch (HibernateException e) { + } catch (HibernateException | IOException e) { throw new BeanInitializationException("Failed to initialize the Content Service", e); } } diff --git a/src/main/java/com/activeviam/mac/cfg/impl/MacServerConfig.java b/src/main/java/com/activeviam/mac/cfg/impl/MacServerConfig.java index b20c37fd..b29d2d16 100644 --- a/src/main/java/com/activeviam/mac/cfg/impl/MacServerConfig.java +++ b/src/main/java/com/activeviam/mac/cfg/impl/MacServerConfig.java @@ -7,22 +7,18 @@ package com.activeviam.mac.cfg.impl; -import com.activeviam.activepivot.server.impl.private_.observability.DynamicActivePivotManagerMBean; -import com.activeviam.activepivot.server.impl.private_.observability.memory.MemoryAnalysisService; import com.activeviam.activepivot.server.spring.api.config.IActivePivotConfig; import com.activeviam.activepivot.server.spring.api.config.IActivePivotContentServiceConfig; import com.activeviam.activepivot.server.spring.api.config.IDatastoreConfig; import com.activeviam.activepivot.server.spring.private_.config.impl.ActivePivotServicesConfig; import com.activeviam.activepivot.server.spring.private_.config.impl.ActiveViamRestServicesConfig; import com.activeviam.activepivot.server.spring.private_.config.impl.ActiveViamWebSocketServicesConfig; -import com.activeviam.activepivot.server.spring.private_.pivot.content.impl.DynamicActivePivotContentServiceMBean; import com.activeviam.mac.cfg.security.impl.SecurityConfig; import com.activeviam.mac.cfg.security.impl.UserConfig; import com.activeviam.tech.core.api.agent.AgentException; import com.activeviam.web.spring.internal.JMXEnabler; import com.activeviam.web.spring.internal.config.JwtConfig; import com.activeviam.web.spring.internal.config.JwtRestServiceConfig; -import java.nio.file.Paths; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.annotation.Bean; @@ -134,28 +130,6 @@ public JMXEnabler jmxMonitoringConnectorEnabler() { return new JMXEnabler("StatisticSource", this.sourceConfig); } - /** - * Enable JMX Monitoring for the Datastore. - * - * @return the {@link JMXEnabler} attached to the datastore - */ - @Bean - public JMXEnabler jmxDatastoreEnabler() { - return new JMXEnabler(this.datastoreConfig.database()); - } - - /** - * Enable JMX Monitoring for ActivePivot Components. - * - * @return the {@link JMXEnabler} attached to the activePivotManager - */ - @Bean - public JMXEnabler jmxActivePivotEnabler() { - startManager(); - - return new JMXEnabler(new DynamicActivePivotManagerMBean(apConfig.activePivotManager())); - } - /** * [Bean] JMX Bean to export bookmarks. * @@ -165,32 +139,4 @@ public JMXEnabler jmxActivePivotEnabler() { public JMXEnabler jmxBookmarkEnabler() { return new JMXEnabler("Bookmark", this.contentServiceConfig); } - - /** - * Enable JMX Monitoring for the ContentService. - * - * @return the {@link JMXEnabler} attached to the Content Service - */ - @Bean - public JMXEnabler jmxActivePivotContentServiceEnabler() { - // to allow operations from the JMX bean - return new JMXEnabler( - new DynamicActivePivotContentServiceMBean( - this.apContentServiceConfig.activePivotContentService(), - this.apConfig.activePivotManager())); - } - - /** - * Enable Memory JMX Monitoring. - * - * @return the {@link JMXEnabler} attached to the memory analysis service. - */ - @Bean - public JMXEnabler jmxMemoryMonitoringServiceEnabler() { - return new JMXEnabler( - new MemoryAnalysisService( - this.datastoreConfig.database(), - this.apConfig.activePivotManager(), - Paths.get(System.getProperty("java.io.tmpdir")))); - } } diff --git a/src/main/java/com/activeviam/mac/cfg/security/impl/SecurityConfig.java b/src/main/java/com/activeviam/mac/cfg/security/impl/SecurityConfig.java index 02c8d29a..58049ed6 100644 --- a/src/main/java/com/activeviam/mac/cfg/security/impl/SecurityConfig.java +++ b/src/main/java/com/activeviam/mac/cfg/security/impl/SecurityConfig.java @@ -6,7 +6,6 @@ import com.activeviam.activepivot.server.spring.private_.pivot.security.impl.UserDetailsServiceWrapper; import com.activeviam.tech.contentserver.storage.api.IContentService; import com.activeviam.tech.core.api.security.IUserDetailsService; -import com.activeviam.web.spring.api.config.ICorsConfig; import com.activeviam.web.spring.api.config.IJwtConfig; import com.activeviam.web.spring.api.jwt.JwtAuthenticationProvider; import com.activeviam.web.spring.internal.config.JwtRestServiceConfig; @@ -21,11 +20,17 @@ import org.springframework.core.env.Environment; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.authentication.AuthenticationProvider; +import org.springframework.security.authentication.ProviderManager; +import org.springframework.security.authentication.dao.DaoAuthenticationProvider; import org.springframework.security.config.Customizer; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer; +import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.factory.PasswordEncoderFactories; import org.springframework.security.crypto.password.DelegatingPasswordEncoder; import org.springframework.security.crypto.password.NoOpPasswordEncoder; @@ -36,11 +41,9 @@ import org.springframework.security.web.authentication.switchuser.SwitchUserFilter; import org.springframework.security.web.context.SecurityContextPersistenceFilter; import org.springframework.security.web.firewall.StrictHttpFirewall; -import org.springframework.web.cors.CorsConfiguration; -import org.springframework.web.cors.CorsConfigurationSource; -import org.springframework.web.cors.UrlBasedCorsConfigurationSource; @Configuration +@EnableWebSecurity public class SecurityConfig { /** Authentication Bean Name. */ @@ -81,8 +84,8 @@ public class SecurityConfig { /** {@code true} to enable the logout URL. */ protected final WebConfiguration webConfiguration; - public SecurityConfig(final String cookieName) { - this.webConfiguration = new WebConfiguration(cookieName); + public SecurityConfig() { + this.webConfiguration = new WebConfiguration(COOKIE_NAME); } /** @@ -118,6 +121,38 @@ public AuthenticationEntryPoint basicAuthenticationEntryPoint() { return new HttpStatusEntryPoint(HttpStatus.UNAUTHORIZED); } + /** + * Configures the authentication of the whole application. + * + *

This binds the defined user service to the authentication and sets the source for JWT + * tokens. + * + * @param inMemoryAuthenticationProvider the in-memory authentication provider + * @param jwtAuthenticationProvider is a provider which can perform authentication from the + * jwtService's tokens. Implementation from the {@link IJwtConfig} . + * @return the authentication manager + */ + @Bean + public AuthenticationManager authenticationManager( + final JwtAuthenticationProvider jwtAuthenticationProvider, + final AuthenticationProvider inMemoryAuthenticationProvider) { + final ProviderManager providerManager = + new ProviderManager(inMemoryAuthenticationProvider, jwtAuthenticationProvider); + providerManager.setEraseCredentialsAfterAuthentication(false); + + return providerManager; + } + + @Bean + public AuthenticationProvider inMemoryAuthenticationProvider( + final UserDetailsService userDetailsService, final PasswordEncoder passwordEncoder) { + final var authenticationProvider = new DaoAuthenticationProvider(); + authenticationProvider.setPasswordEncoder(passwordEncoder); + authenticationProvider.setUserDetailsService(userDetailsService); + + return authenticationProvider; + } + /** * Configures the authentication of the whole application. * @@ -136,28 +171,6 @@ public void configureGlobal( .authenticationProvider(jwtAuthenticationProvider); } - /** - * [Bean] Spring standard way of configuring CORS. - * - *

This simply forwards the configuration of {@link ICorsConfig} to Spring security system. - * - * @return the configuration for the application. - */ - @Bean - public CorsConfigurationSource corsConfigurationSource(final ICorsConfig corsConfig) { - final CorsConfiguration configuration = new CorsConfiguration(); - configuration.setAllowedOrigins(corsConfig.getAllowedOrigins()); - configuration.setAllowedHeaders(corsConfig.getAllowedHeaders()); - configuration.setExposedHeaders(corsConfig.getExposedHeaders()); - configuration.setAllowedMethods(corsConfig.getAllowedMethods()); - configuration.setAllowCredentials(true); - - final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource(); - source.registerCorsConfiguration("/**", configuration); - - return source; - } - /** * Returns the spring security bean user details service wrapper. * @@ -280,15 +293,21 @@ public SecurityFilterChain activePivotSecurity( .permitAll() .anyRequest() .hasAnyAuthority(ROLE_USER)) - // One has to be a user for all the other URLs - .securityMatcher("/**") - .authorizeHttpRequests(auth -> auth.anyRequest().hasAnyAuthority(ROLE_USER)) - .httpBasic(Customizer.withDefaults()) // SwitchUserFilter is the last filter in the chain. See FilterComparator class. .addFilterAfter(contextValueFilter, SwitchUserFilter.class); return http.build(); } + // One has to be a user for all the other URLs + @Bean + @Order(5) + public SecurityFilterChain otherSecurity(final HttpSecurity http) throws Exception { + http.securityMatcher("/**") + .authorizeHttpRequests(auth -> auth.anyRequest().permitAll()) + .httpBasic(Customizer.withDefaults()); + return http.build(); + } + public void configureWebSecurity( HttpSecurity http, JwtFilter jwtFilter, WebConfiguration webConfig) throws Exception { http diff --git a/src/test/java/com/activeviam/mac/app/TestAppLoading.java b/src/test/java/com/activeviam/mac/app/TestAppLoading.java index a6db2010..14f90173 100644 --- a/src/test/java/com/activeviam/mac/app/TestAppLoading.java +++ b/src/test/java/com/activeviam/mac/app/TestAppLoading.java @@ -12,14 +12,12 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.BeanCreationException; -import org.springframework.context.annotation.Import; -import org.springframework.context.annotation.PropertySource; +import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.web.WebAppConfiguration; /** Test class for tests related to loading cases of the SpringBoot application */ -@WebAppConfiguration -@Import({MacServerConfig.class}) -@PropertySource(value = "classpath:application.yml") +@WebAppConfiguration("classpath:application.yml") +@ContextConfiguration(classes = MacServerConfig.class) public class TestAppLoading { /** Ensures that the default application setup works */ diff --git a/src/test/java/com/activeviam/mac/statistic/memory/ATestMemoryStatistic.java b/src/test/java/com/activeviam/mac/statistic/memory/ATestMemoryStatistic.java index e73d147a..68564659 100644 --- a/src/test/java/com/activeviam/mac/statistic/memory/ATestMemoryStatistic.java +++ b/src/test/java/com/activeviam/mac/statistic/memory/ATestMemoryStatistic.java @@ -1247,16 +1247,10 @@ IDatastore assertLoadsCorrectly( protected static MemoryStatisticsTestUtils.StatisticsSummary computeStatisticsSummary( final Collection statistics, final Class creatorClass) { - // create a new list of statistics with no parent - final List statisticsWithoutParent = - statistics.stream() - .peek( - stat -> stat.setParent(null)) - .collect(Collectors.toList()); return MemoryStatisticsTestUtils.getStatisticsSummary( new TestMemoryStatisticBuilder(creatorClass.getName()) .withCreatorClasses(creatorClass) - .withChildren(statisticsWithoutParent) + .withChildren(statistics) .build()); } @@ -1457,7 +1451,7 @@ static AMemoryStatistic loadMemoryStatFromFolder( throw new RuntimeException("Cannot read " + file, e); } }) - .peek(stat -> stat.setParent(null)) + .peek(stat -> stat.setParent(null)) .collect(Collectors.toList()); return new DefaultMemoryStatistic.Builder() From d18bde69b3260b621398ac978d013db10b13ed36 Mon Sep 17 00:00:00 2001 From: lha Date: Fri, 29 Nov 2024 16:00:54 +0100 Subject: [PATCH 04/10] fix content service --- .../activeviam/mac/memory/ChunkRecordHandler.java | 12 ++++-------- src/main/resources/content-service-hibernate.xml | 10 ++++++++++ 2 files changed, 14 insertions(+), 8 deletions(-) create mode 100644 src/main/resources/content-service-hibernate.xml diff --git a/src/main/java/com/activeviam/mac/memory/ChunkRecordHandler.java b/src/main/java/com/activeviam/mac/memory/ChunkRecordHandler.java index 5bd9c370..4d4fc6a6 100644 --- a/src/main/java/com/activeviam/mac/memory/ChunkRecordHandler.java +++ b/src/main/java/com/activeviam/mac/memory/ChunkRecordHandler.java @@ -124,23 +124,19 @@ private void init(final IRecordReader record, final IDictionaryProvider dictiona } private int getPartition(final IRecordReader record) { - final int idx = record.getFormat().getFieldIndex(DatastoreConstants.CHUNK__PARTITION_ID); - return record.readInt(idx); + return record.getFormat().getFieldIndex(DatastoreConstants.CHUNK__PARTITION_ID); } private int getDicId(final IRecordReader record) { - final int idx = record.getFormat().getFieldIndex(DatastoreConstants.CHUNK__PARENT_DICO_ID); - return record.readInt(idx); + return record.getFormat().getFieldIndex(DatastoreConstants.CHUNK__PARENT_DICO_ID); } private int getIdxId(final IRecordReader record) { - final int idx = record.getFormat().getFieldIndex(DatastoreConstants.CHUNK__PARENT_INDEX_ID); - return record.readInt(idx); + return record.getFormat().getFieldIndex(DatastoreConstants.CHUNK__PARENT_INDEX_ID); } private int getRefId(final IRecordReader record) { - final int idx = record.getFormat().getFieldIndex(DatastoreConstants.CHUNK__PARENT_REF_ID); - return record.readInt(idx); + return record.getFormat().getFieldIndex(DatastoreConstants.CHUNK__PARENT_REF_ID); } private String getChunkClassName( diff --git a/src/main/resources/content-service-hibernate.xml b/src/main/resources/content-service-hibernate.xml new file mode 100644 index 00000000..a82dfc05 --- /dev/null +++ b/src/main/resources/content-service-hibernate.xml @@ -0,0 +1,10 @@ + + + + + + + + + + From 476ea4c5d775d03c3d3f7bcc063ed6f486142c8b Mon Sep 17 00:00:00 2001 From: lha Date: Mon, 2 Dec 2024 16:22:20 +0100 Subject: [PATCH 05/10] custom deserializer --- pom.xml | 2 +- .../activeviam/mac/cfg/impl/SourceConfig.java | 19 +- .../RetroCompatibleDeserializer.java | 285 ++++++++++++++++++ .../memory/scenarios/TestMissingChunkId.java | 13 +- 4 files changed, 291 insertions(+), 28 deletions(-) create mode 100644 src/main/java/com/activeviam/mac/statistic/memory/deserializer/RetroCompatibleDeserializer.java diff --git a/pom.xml b/pom.xml index c49288c7..849ae181 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ 11 - 6.1.2-SNAPSHOT + 6.1.3-SNAPSHOT 5.2.0-beta 10.1.30 diff --git a/src/main/java/com/activeviam/mac/cfg/impl/SourceConfig.java b/src/main/java/com/activeviam/mac/cfg/impl/SourceConfig.java index 11c5494f..0f3a3047 100644 --- a/src/main/java/com/activeviam/mac/cfg/impl/SourceConfig.java +++ b/src/main/java/com/activeviam/mac/cfg/impl/SourceConfig.java @@ -10,11 +10,11 @@ import static java.util.stream.Collectors.mapping; import static java.util.stream.Collectors.toUnmodifiableList; -import com.activeviam.activepivot.server.impl.private_.observability.memory.MemoryStatisticSerializerUtil; import com.activeviam.database.datastore.internal.IInternalDatastore; import com.activeviam.database.datastore.internal.impl.Datastore; import com.activeviam.mac.Loggers; import com.activeviam.mac.memory.AnalysisDatastoreFeeder; +import com.activeviam.mac.statistic.memory.deserializer.RetroCompatibleDeserializer; import com.activeviam.source.common.api.impl.WatcherService; import com.activeviam.source.csv.api.DirectoryCsvTopic; import com.activeviam.source.csv.api.ICsvDataProvider; @@ -215,7 +215,7 @@ private void loadDumps(final Map> dumpFiles) { (dumpName, entry) -> { try { final Stream inputs = - entry.stream().parallel().map(this::readStatisticFile); + entry.stream().parallel().map(RetroCompatibleDeserializer::readStatisticFile); final String message = feedDatastore(inputs, dumpName); LOGGER.info(message); } catch (final Exception e) { @@ -224,21 +224,6 @@ private void loadDumps(final Map> dumpFiles) { }); } - private AMemoryStatistic readStatisticFile(final Path file) { - try { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine("Reading statistics from " + file.toAbsolutePath()); - } - final AMemoryStatistic read = MemoryStatisticSerializerUtil.readStatisticFile(file.toFile()); - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine("Statistics read from " + file.toAbsolutePath()); - } - return read; - } catch (final IOException ioe) { - throw new RuntimeException("Cannot read statistics from " + file); - } - } - /** * Feeds the {@link SourceConfig#datastore datastore} with a stream of {@link IMemoryStatistic}. * diff --git a/src/main/java/com/activeviam/mac/statistic/memory/deserializer/RetroCompatibleDeserializer.java b/src/main/java/com/activeviam/mac/statistic/memory/deserializer/RetroCompatibleDeserializer.java new file mode 100644 index 00000000..bd430363 --- /dev/null +++ b/src/main/java/com/activeviam/mac/statistic/memory/deserializer/RetroCompatibleDeserializer.java @@ -0,0 +1,285 @@ +/* + * (C) ActiveViam 2015 + * ALL RIGHTS RESERVED. This material is the CONFIDENTIAL and PROPRIETARY + * property of ActiveViam. Any unauthorized use, + * reproduction or transfer of this material is strictly prohibited + */ + +package com.activeviam.mac.statistic.memory.deserializer; + +import static com.activeviam.activepivot.server.impl.private_.observability.memory.MemoryStatisticSerializerUtil.COMPRESSED_FILE_EXTENSION; + +import com.activeviam.activepivot.server.impl.private_.observability.memory.AStatisticDeserializer; +import com.activeviam.activepivot.server.impl.private_.observability.memory.MemoryStatisticAdapter; +import com.activeviam.tech.core.api.exceptions.ActiveViamRuntimeException; +import com.activeviam.tech.core.api.exceptions.service.InternalServiceException; +import com.activeviam.tech.observability.api.memory.IMemoryStatistic; +import com.activeviam.tech.observability.api.memory.IStatisticAttribute; +import com.activeviam.tech.observability.internal.memory.AMemoryStatistic; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.core.JsonToken; +import com.fasterxml.jackson.core.json.JsonReadFeature; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectReader; +import com.fasterxml.jackson.databind.module.SimpleModule; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.lang.reflect.InvocationTargetException; +import java.nio.charset.StandardCharsets; +import java.nio.file.Path; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; +import org.xerial.snappy.SnappyFramedInputStream; + +/** + * {@link JsonDeserializer} for {@link IMemoryStatistic}. + * + * @author ActiveViam + */ +public class RetroCompatibleDeserializer extends AStatisticDeserializer { + + /** Mapping from 6.1 to 6.0 classes */ + private static final Map CLASS_MAPPING_6_0_to_6_1 = + Map.of( + "com.qfs.monitoring.statistic.memory.impl.ChunkStatistic", + "com.activeviam.tech.observability.internal.memory.ChunkStatistic", + "com.qfs.monitoring.statistic.memory.impl.ChunkSetStatistic", + "com.activeviam.tech.observability.internal.memory.ChunkSetStatistic", + "com.qfs.monitoring.statistic.memory.impl.DefaultMemoryStatistic", + "com.activeviam.tech.observability.internal.memory.DefaultMemoryStatistic", + "com.qfs.monitoring.statistic.memory.impl.DictionaryStatistic", + "com.activeviam.tech.observability.internal.memory.DictionaryStatistic", + "com.qfs.monitoring.statistic.memory.impl.ReferenceStatistic", + "com.activeviam.tech.observability.internal.memory.ReferenceStatistic", + "com.qfs.monitoring.statistic.memory.impl.IndexStatistic", + "com.activeviam.tech.observability.internal.memory.IndexStatistic"); + + private static final Set AVAILABLE_CLASSES_6_1 = + Set.of( + "com.activeviam.tech.observability.internal.memory.ChunkStatistic", + "com.activeviam.tech.observability.internal.memory.ChunkSetStatistic", + "com.activeviam.tech.observability.internal.memory.DefaultMemoryStatistic", + "com.activeviam.tech.observability.internal.memory.DictionaryStatistic", + "com.activeviam.tech.observability.internal.memory.ReferenceStatistic", + "com.activeviam.tech.observability.internal.memory.IndexStatistic"); + + private static final Logger LOGGER = Logger.getLogger("mac.statistic.memory.deserializer"); + private static ObjectMapper serializer; + + static { + serializer = + new ObjectMapper() + .configure(JsonParser.Feature.AUTO_CLOSE_SOURCE, false) + .configure(JsonReadFeature.ALLOW_BACKSLASH_ESCAPING_ANY_CHARACTER.mappedFeature(), true) + .configure(JsonReadFeature.ALLOW_UNQUOTED_FIELD_NAMES.mappedFeature(), true) + .configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false) + .configure(JsonReadFeature.ALLOW_NON_NUMERIC_NUMBERS.mappedFeature(), true); + serializer.setSerializationInclusion(JsonInclude.Include.NON_NULL); + + final SimpleModule deserializeModule = new SimpleModule(); + deserializeModule.addDeserializer(AMemoryStatistic.class, new RetroCompatibleDeserializer()); + serializer.registerModule(deserializeModule); + } + + @Override + public AMemoryStatistic deserialize(final JsonParser parser, final DeserializationContext ctx) + throws IOException { + if (!JsonToken.START_OBJECT.equals(parser.currentToken())) { + throw new IllegalArgumentException("Should be called at the start of an object"); + } + + parser.nextToken(); + final String name; + if (Objects.equals(readFieldName(parser), MemoryStatisticAdapter.NAME_ATTR)) { + readAndCheckFieldName(parser, MemoryStatisticAdapter.NAME_ATTR); + name = readStringField(parser); + parser.nextToken(); + } else { + name = null; + } + + final long onHeap; + if (Objects.equals(readFieldName(parser), MemoryStatisticAdapter.ON_HEAP_ATTR)) { + onHeap = readLongField(parser); + parser.nextToken(); + } else { + onHeap = -1; + } + + final long offHeap; + if (Objects.equals(readFieldName(parser), MemoryStatisticAdapter.OFF_HEAP_ATTR)) { + offHeap = readLongField(parser); + parser.nextToken(); + } else { + offHeap = -1; + } + + checkFieldName(MemoryStatisticAdapter.STATISTIC_CLASS_ATTR, readFieldName(parser)); + final String klassName = readStringField(parser); + + parser.nextToken(); + final Map attributes; + if (Objects.equals(readFieldName(parser), MemoryStatisticAdapter.ATTRIBUTES_ATTR)) { + parser.nextToken(); + attributes = parseAttributes(parser, ctx); + } else { + attributes = Collections.emptyMap(); + } + + parser.nextToken(); + final List children; + if (Objects.equals(readFieldName(parser), MemoryStatisticAdapter.CHILDREN_ATTR)) { + parser.nextToken(); + children = parseChildren(parser, ctx, AMemoryStatistic.class); + } else { + children = Collections.emptyList(); + } + + handleExcessiveAttributes(parser); + + if (!Objects.equals(parser.currentToken(), JsonToken.END_OBJECT)) { + throw new IllegalStateException( + "Unexpected additional tokens. First is " + parser.currentToken()); + } + + return createDeserialized(klassName, name, onHeap, offHeap, attributes, children); + } + + /** + * Creates the actual statistic using the parsed attributed. + * + * @param klassName name of the statistic class + * @param name name of the statistic + * @param onHeap value read for the consumed on-heap memory - negative if unset + * @param offHeap value read for the consume off-heap memory - negative if unset + * @param attributes statistic attributes + * @param children child statistics + * @return the created deserialized statistic + */ + protected AMemoryStatistic createDeserialized( + final String klassName, + final String name, + final long onHeap, + final long offHeap, + final Map attributes, + final List children) { + Class klass; + if (AVAILABLE_CLASSES_6_1.contains(klassName)) { + klass = getClass(klassName); + } else if (classNeedsTranslation(klassName)) { + klass = getClass(getClassTranslation(klassName)); + } else { + throw new InternalServiceException("Cannot find statistic class " + klassName); + } + + final AMemoryStatistic objDeserialized; + try { + objDeserialized = (AMemoryStatistic) klass.getDeclaredConstructor().newInstance(); + } catch (final InstantiationException + | IllegalAccessException + | NoSuchMethodException + | InvocationTargetException e) { + throw new InternalServiceException("Cannot create instance of " + klassName, e); + } + + try { + klass.getMethod("setAttributes", Map.class).invoke(objDeserialized, attributes); + } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { + throw new InternalServiceException("Cannot set attributes for class " + klassName, e); + } + try { + klass.getMethod("setChildren", Collection.class).invoke(objDeserialized, children); + } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { + throw new InternalServiceException("Cannot set children for class " + klassName, e); + } + + if (name != null) { + objDeserialized.setName(name); + } + if (onHeap >= 0) { + objDeserialized.setShallowOnHeap(onHeap); + } + if (offHeap >= 0) { + objDeserialized.setShallowOffHeap(offHeap); + } + + return objDeserialized; + } + + public static AMemoryStatistic readStatisticFile(final Path file) { + if (LOGGER.isLoggable(Level.FINE)) { + LOGGER.fine("Reading statistics from " + file.toAbsolutePath()); + } + final AMemoryStatistic read = readStatistic(file.toFile()); + if (LOGGER.isLoggable(Level.FINE)) { + LOGGER.fine("Statistics read from " + file.toAbsolutePath()); + } + return read; + } + + public static AMemoryStatistic readStatistic(final File file) { + + try { + try (final InputStream inputStream = inputStream(file); + final InputStreamReader statistic = + new InputStreamReader(inputStream, StandardCharsets.UTF_8)) { + final ObjectReader reader = serializer.readerFor(AMemoryStatistic.class); + return readStatisticObject(reader, statistic); + } + } catch (IOException e) { + throw new ActiveViamRuntimeException(e); + } + } + + private static AMemoryStatistic readStatisticObject( + ObjectReader reader, InputStreamReader statistic) { + try { + return reader.readValue(new BufferedReader(statistic)); + } catch (final IOException e) { + throw new ActiveViamRuntimeException(e); + } + } + + private static InputStream inputStream(final File file) throws IOException { + final boolean isCompressedFile = file.getName().endsWith("." + COMPRESSED_FILE_EXTENSION); + + InputStream inputStream = + new FileInputStream(file); // NOSONAR: used in try-with-resources above + if (isCompressedFile) { + inputStream = new SnappyFramedInputStream(inputStream); + } + return inputStream; + } + + private static String getClassTranslation(final String klassName) { + return CLASS_MAPPING_6_0_to_6_1.get(klassName); + } + + private static boolean classNeedsTranslation(final String klassName) { + return CLASS_MAPPING_6_0_to_6_1.containsKey(klassName); + } + + private static Class getClass(final String klassName) { + Class klass; + try { + klass = Class.forName(klassName); + } catch (final ClassNotFoundException notFound) { + throw new InternalServiceException("Cannot get class " + klassName, notFound); + } + return klass; + } +} diff --git a/src/test/java/com/activeviam/mac/statistic/memory/scenarios/TestMissingChunkId.java b/src/test/java/com/activeviam/mac/statistic/memory/scenarios/TestMissingChunkId.java index 4ce966be..8626f166 100644 --- a/src/test/java/com/activeviam/mac/statistic/memory/scenarios/TestMissingChunkId.java +++ b/src/test/java/com/activeviam/mac/statistic/memory/scenarios/TestMissingChunkId.java @@ -11,14 +11,13 @@ import com.activeviam.activepivot.core.intf.api.description.IActivePivotManagerDescription; import com.activeviam.activepivot.server.impl.api.query.MDXQuery; import com.activeviam.activepivot.server.impl.api.query.MdxQueryUtil; -import com.activeviam.activepivot.server.impl.private_.observability.memory.MemoryStatisticSerializerUtil; import com.activeviam.activepivot.server.intf.api.dto.CellSetDTO; import com.activeviam.database.datastore.api.description.IDatastoreSchemaDescription; import com.activeviam.database.datastore.internal.IInternalDatastore; import com.activeviam.mac.cfg.impl.ManagerDescriptionConfig; import com.activeviam.mac.memory.MemoryAnalysisDatastoreDescriptionConfig; import com.activeviam.mac.statistic.memory.ATestMemoryStatistic; -import com.activeviam.tech.core.api.exceptions.ActiveViamRuntimeException; +import com.activeviam.mac.statistic.memory.deserializer.RetroCompatibleDeserializer; import com.activeviam.tech.core.api.query.QueryException; import com.activeviam.tech.core.api.registry.Registry; import com.activeviam.tech.observability.internal.memory.AMemoryStatistic; @@ -69,14 +68,8 @@ protected ApplicationInTests createAnalysisApplication() { protected Collection loadMemoryStatistic(final Path path) throws IOException { return Files.list(path) - .map( - file -> { - try { - return MemoryStatisticSerializerUtil.readStatisticFile(file.toFile()); - } catch (IOException exception) { - throw new ActiveViamRuntimeException(exception); - } - }) + .map(Path::toFile) + .map(RetroCompatibleDeserializer::readStatistic) .collect(Collectors.toList()); } From 670da99d9da96cfa55531232d682fe1f8247cd50 Mon Sep 17 00:00:00 2001 From: lha Date: Thu, 5 Dec 2024 10:28:54 +0100 Subject: [PATCH 06/10] fix code smells --- .../impl/ActiveUiResourceServerConfig.java | 3 - .../activeviam/mac/cfg/impl/SourceConfig.java | 23 ++++--- .../mac/cfg/security/impl/CorsConfig.java | 6 +- .../mac/cfg/security/impl/SecurityConfig.java | 13 ++-- .../mac/memory/ChunkRecordHandler.java | 35 ++++++----- .../visitor/impl/PivotFeederVisitor.java | 62 +++++++++---------- .../memory/TestVectorBlockBookmark.java | 14 ++--- 7 files changed, 84 insertions(+), 72 deletions(-) diff --git a/src/main/java/com/activeviam/mac/cfg/impl/ActiveUiResourceServerConfig.java b/src/main/java/com/activeviam/mac/cfg/impl/ActiveUiResourceServerConfig.java index 8215b7ff..ca7dde52 100644 --- a/src/main/java/com/activeviam/mac/cfg/impl/ActiveUiResourceServerConfig.java +++ b/src/main/java/com/activeviam/mac/cfg/impl/ActiveUiResourceServerConfig.java @@ -41,9 +41,6 @@ protected void registerRedirections(final ResourceRegistry registry) { protected void registerExtensions(final ResourceRegistry registry) { registry.serve("/ui/extensions*.json").addResourceLocations("classpath:/static/activeui/"); - // registry - // .serve("/ui/extensions/text-editor-extension/**/*.js") - // .addResourceLocations("classpath:/static/activeui/extensions/text-editor-extension/"); } /** diff --git a/src/main/java/com/activeviam/mac/cfg/impl/SourceConfig.java b/src/main/java/com/activeviam/mac/cfg/impl/SourceConfig.java index 0f3a3047..d44ece25 100644 --- a/src/main/java/com/activeviam/mac/cfg/impl/SourceConfig.java +++ b/src/main/java/com/activeviam/mac/cfg/impl/SourceConfig.java @@ -41,7 +41,6 @@ import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Lazy; @@ -60,10 +59,15 @@ public class SourceConfig { private static final Logger LOGGER = Logger.getLogger(Loggers.LOADING); /** Autowired {@link Datastore} to be fed by this source. */ - @Autowired protected IInternalDatastore datastore; + protected IInternalDatastore datastore; /** Spring environment, automatically wired. */ - @Autowired protected Environment env; + protected Environment env; + + public SourceConfig(final IInternalDatastore datastore, final Environment env) { + this.datastore = datastore; + this.env = env; + } /** * Provides a {@link DirectoryCsvTopic topic}. @@ -129,9 +133,14 @@ protected Path resolveDirectory(final String name) { e); } } - if (url == null - || !Files.isDirectory(directory = Paths.get(URI.create(url.toExternalForm())))) { - throw new IllegalArgumentException("'" + name + "' could not be resolved to a directory."); + if (url != null) { + directory = Paths.get(URI.create(url.toExternalForm())); + if (!Files.isDirectory(directory)) { + throw new IllegalArgumentException( + "'" + name + "' could not be resolved to a directory."); + } + } else { + throw new IllegalArgumentException("could not find '" + name + "' in the classpath."); } } return directory; @@ -207,7 +216,7 @@ private Map> collectDumpFiles( } private Path getStatisticFolder() { - return resolveDirectory(this.env.getRequiredProperty("statistic.folder")); + return resolveDirectory(this.env.getRequiredProperty(STATISTIC_FOLDER_PROPERTY)); } private void loadDumps(final Map> dumpFiles) { diff --git a/src/main/java/com/activeviam/mac/cfg/security/impl/CorsConfig.java b/src/main/java/com/activeviam/mac/cfg/security/impl/CorsConfig.java index 68d27425..bff9644d 100644 --- a/src/main/java/com/activeviam/mac/cfg/security/impl/CorsConfig.java +++ b/src/main/java/com/activeviam/mac/cfg/security/impl/CorsConfig.java @@ -35,11 +35,15 @@ public class CorsConfig implements ICorsConfig { /** The name of the Environment to use. */ - @Autowired protected Environment env; + protected Environment env; /** The address the UI is exposed to. */ public static final String ACTIVEUI_ADDRESS = "activeui.address"; + public CorsConfig(@Autowired Environment env) { + this.env = env; + } + @Override public List getAllowedOrigins() { return Collections.singletonList(env.getRequiredProperty(ACTIVEUI_ADDRESS)); diff --git a/src/main/java/com/activeviam/mac/cfg/security/impl/SecurityConfig.java b/src/main/java/com/activeviam/mac/cfg/security/impl/SecurityConfig.java index 58049ed6..3435e26d 100644 --- a/src/main/java/com/activeviam/mac/cfg/security/impl/SecurityConfig.java +++ b/src/main/java/com/activeviam/mac/cfg/security/impl/SecurityConfig.java @@ -74,17 +74,20 @@ public class SecurityConfig { private static final String PING_SUFFIX = "/ping"; /** The User Configuration. */ - @Autowired protected UserConfig userDetailsConfig; + protected UserConfig userDetailsConfig; /** The JWT Configuration. */ - @Autowired protected IJwtConfig jwtConfig; + protected IJwtConfig jwtConfig; /** The name of the Environment to use. */ - @Autowired protected Environment env; - + protected Environment env; /** {@code true} to enable the logout URL. */ protected final WebConfiguration webConfiguration; - public SecurityConfig() { + public SecurityConfig( + final UserConfig userDetailsConfig, final IJwtConfig jwtConfig, final Environment env) { + this.userDetailsConfig = userDetailsConfig; + this.jwtConfig = jwtConfig; + this.env = env; this.webConfiguration = new WebConfiguration(COOKIE_NAME); } diff --git a/src/main/java/com/activeviam/mac/memory/ChunkRecordHandler.java b/src/main/java/com/activeviam/mac/memory/ChunkRecordHandler.java index 4d4fc6a6..4a8e7b22 100644 --- a/src/main/java/com/activeviam/mac/memory/ChunkRecordHandler.java +++ b/src/main/java/com/activeviam/mac/memory/ChunkRecordHandler.java @@ -87,9 +87,10 @@ private IRecordReader createMergedRecord( } } - private void init(final IRecordReader record, final IDictionaryProvider dictionaryProvider) { + private void init( + final IRecordReader recordReader, final IDictionaryProvider dictionaryProvider) { if (this.sharedPartitionId < 0) { - final int dicIdIdx = getPartition(record); + final int dicIdIdx = getPartition(recordReader); @SuppressWarnings("unchecked") final IWritableDictionary partitionDictionary = (IWritableDictionary) dictionaryProvider.getDictionary(dicIdIdx); @@ -97,7 +98,7 @@ private void init(final IRecordReader record, final IDictionaryProvider dictiona partitionDictionary.map(MemoryAnalysisDatastoreDescriptionConfig.MANY_PARTITIONS); } if (this.defaultDicId < 0) { - final int dicIdIdx = getDicId(record); + final int dicIdIdx = getDicId(recordReader); @SuppressWarnings("unchecked") final IWritableDictionary dicIdDictionary = (IWritableDictionary) dictionaryProvider.getDictionary(dicIdIdx); @@ -105,7 +106,7 @@ private void init(final IRecordReader record, final IDictionaryProvider dictiona dicIdDictionary.map(MemoryAnalysisDatastoreDescriptionConfig.DEFAULT_COMPONENT_ID_VALUE); } if (this.defaultIdxId < 0) { - final int idxIdIdx = getIdxId(record); + final int idxIdIdx = getIdxId(recordReader); @SuppressWarnings("unchecked") final IWritableDictionary idxIdDictionary = (IWritableDictionary) dictionaryProvider.getDictionary(idxIdIdx); @@ -114,7 +115,7 @@ private void init(final IRecordReader record, final IDictionaryProvider dictiona } if (this.defaultRefId < 0) { - final int refIdIdx = getRefId(record); + final int refIdIdx = getRefId(recordReader); @SuppressWarnings("unchecked") final IWritableDictionary refIdDictionary = (IWritableDictionary) dictionaryProvider.getDictionary(refIdIdx); @@ -123,31 +124,31 @@ private void init(final IRecordReader record, final IDictionaryProvider dictiona } } - private int getPartition(final IRecordReader record) { - return record.getFormat().getFieldIndex(DatastoreConstants.CHUNK__PARTITION_ID); + private int getPartition(final IRecordReader recordReader) { + return recordReader.getFormat().getFieldIndex(DatastoreConstants.CHUNK__PARTITION_ID); } - private int getDicId(final IRecordReader record) { - return record.getFormat().getFieldIndex(DatastoreConstants.CHUNK__PARENT_DICO_ID); + private int getDicId(final IRecordReader recordReader) { + return recordReader.getFormat().getFieldIndex(DatastoreConstants.CHUNK__PARENT_DICO_ID); } - private int getIdxId(final IRecordReader record) { - return record.getFormat().getFieldIndex(DatastoreConstants.CHUNK__PARENT_INDEX_ID); + private int getIdxId(final IRecordReader recordReader) { + return recordReader.getFormat().getFieldIndex(DatastoreConstants.CHUNK__PARENT_INDEX_ID); } - private int getRefId(final IRecordReader record) { - return record.getFormat().getFieldIndex(DatastoreConstants.CHUNK__PARENT_REF_ID); + private int getRefId(final IRecordReader recordReader) { + return recordReader.getFormat().getFieldIndex(DatastoreConstants.CHUNK__PARENT_REF_ID); } private String getChunkClassName( - final IRecordReader record, final IDictionaryProvider dictionaryProvider) { - final int partitionIdx = getPartition(record); - final int idx = record.getFormat().getFieldIndex(DatastoreConstants.CHUNK__CLASS); + final IRecordReader recordReader, final IDictionaryProvider dictionaryProvider) { + final int partitionIdx = getPartition(recordReader); + final int idx = recordReader.getFormat().getFieldIndex(DatastoreConstants.CHUNK__CLASS); @SuppressWarnings("unchecked") final IWritableDictionary refIdDictionary = (IWritableDictionary) dictionaryProvider.getDictionary(partitionIdx); - return (String) refIdDictionary.read((Integer) record.read(idx)); + return (String) refIdDictionary.read((Integer) recordReader.read(idx)); } private IWritableRecord copyRecord(final IRecordReader record) { diff --git a/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/PivotFeederVisitor.java b/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/PivotFeederVisitor.java index 3247120f..8d45733a 100644 --- a/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/PivotFeederVisitor.java +++ b/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/PivotFeederVisitor.java @@ -151,39 +151,37 @@ private static String getProviderCategory(final IMemoryStatistic stat) { * MemoryStatisticConstants#STAT_NAME_MANAGER} named statistic */ public void startFrom(final AMemoryStatistic stat) { + if (this.current != null) { + throw new IllegalArgumentException("Cannot reuse a feed instance"); + } + final IStatisticAttribute dateAtt = stat.getAttribute(MemoryStatisticConstants.ATTR_NAME_DATE); + this.current = + Instant.ofEpochSecond(null != dateAtt ? dateAtt.asLong() : System.currentTimeMillis()); + readEpochAndBranchIfAny(stat); + if (this.epochId == null && stat.getName().equals(MemoryStatisticConstants.STAT_NAME_MANAGER)) { + // Look amongst the children to find the epoch + findEpoch(stat); + } - if (this.current == null) { - final IStatisticAttribute dateAtt = - stat.getAttribute(MemoryStatisticConstants.ATTR_NAME_DATE); - - this.current = - Instant.ofEpochSecond(null != dateAtt ? dateAtt.asLong() : System.currentTimeMillis()); - - readEpochAndBranchIfAny(stat); - if (this.epochId == null - && stat.getName().equals(MemoryStatisticConstants.STAT_NAME_MANAGER)) { - // Look amongst the children to find the epoch - for (final IMemoryStatistic child : stat.getChildren()) { - readEpochAndBranchIfAny(child); - if (this.epochId != null) { - break; - } - } - } + FeedVisitor.includeApplicationInfoIfAny(this.transaction, this.current, this.dumpName, stat); - FeedVisitor.includeApplicationInfoIfAny(this.transaction, this.current, this.dumpName, stat); + try { + stat.accept(this); + } catch (final RuntimeException e) { + if (Boolean.TRUE.equals(DEBUG)) { + final StatisticTreePrinter printer = DebugVisitor.createDebugPrinter(stat); + printer.print(); + } + throw e; + } + } - try { - stat.accept(this); - } catch (final RuntimeException e) { - if (Boolean.TRUE.equals(DEBUG)) { - final StatisticTreePrinter printer = DebugVisitor.createDebugPrinter(stat); - printer.print(); - } - throw e; + private void findEpoch(AMemoryStatistic stat) { + for (final IMemoryStatistic child : stat.getChildren()) { + readEpochAndBranchIfAny(child); + if (this.epochId != null) { + break; } - } else { - throw new RuntimeException("Cannot reuse a feed instance"); } } @@ -591,9 +589,9 @@ private boolean readEpochAndBranchIfAny(final IMemoryStatistic stat) { final IStatisticAttribute branchAttr = stat.getAttribute(MemoryStatisticConstants.ATTR_NAME_BRANCH); if (branchAttr != null) { - final String branch = branchAttr.asText(); - assert this.branch == null || this.branch.equals(branch); - this.branch = branch; + final String branchAttrText = branchAttr.asText(); + assert this.branch == null || this.branch.equals(branchAttrText); + this.branch = branchAttrText; epochOrBranchChanged = true; } diff --git a/src/test/java/com/activeviam/mac/statistic/memory/TestVectorBlockBookmark.java b/src/test/java/com/activeviam/mac/statistic/memory/TestVectorBlockBookmark.java index fc16f3e1..914447d3 100644 --- a/src/test/java/com/activeviam/mac/statistic/memory/TestVectorBlockBookmark.java +++ b/src/test/java/com/activeviam/mac/statistic/memory/TestVectorBlockBookmark.java @@ -58,7 +58,7 @@ public void setup() { .forEach(i -> tm.add("A", i * i, new double[] {i}, new double[] {-i, -i * i}))); // Force to discard all versions - this.monitoredApp.getDatabase().getEpochManager().forceDiscardEpochs(__ -> true); + this.monitoredApp.getDatabase().getEpochManager().forceDiscardEpochs(epoch -> true); // perform GCs before exporting the store data performGC(); @@ -102,7 +102,7 @@ public void tearDown() throws AgentException { } @Test - public void testVectorBlockRecordConsumptionIsZero() throws QueryException { + void testVectorBlockRecordConsumptionIsZero() throws QueryException { final MDXQuery recordQuery = new MDXQuery( "SELECT [Components].[Component].[Component].[RECORDS] ON ROWS," @@ -119,7 +119,7 @@ public void testVectorBlockRecordConsumptionIsZero() throws QueryException { } @Test - public void testVectorBlockConsumption() throws QueryException { + void testVectorBlockConsumption() throws QueryException { final MDXQuery vectorBlockQueryField1 = new MDXQuery( "SELECT {" @@ -143,8 +143,8 @@ public void testVectorBlockConsumption() throws QueryException { ((ADDED_DATA_SIZE * 2 + ADDED_DATA_SIZE) / MICROAPP_VECTOR_BLOCK_SIZE) + 1; final var directMemoryUsedOnVector = blockCountUsed * MICROAPP_VECTOR_BLOCK_SIZE * Double.BYTES; - assertThat((long) result1.getCells().get(1).getValue()).isEqualTo(directMemoryUsedOnVector); assertThat((long) result1.getCells().get(1).getValue()) + .isEqualTo(directMemoryUsedOnVector) .isEqualTo((long) result1.getCells().get(0).getValue()); final MDXQuery vectorBlockQueryField2 = @@ -163,13 +163,13 @@ public void testVectorBlockConsumption() throws QueryException { final CellSetDTO result2 = MdxQueryUtil.execute(this.monitoringApp.getManager(), vectorBlockQueryField2); - assertThat((long) result2.getCells().get(1).getValue()).isEqualTo(directMemoryUsedOnVector); assertThat((long) result2.getCells().get(1).getValue()) + .isEqualTo(directMemoryUsedOnVector) .isEqualTo((long) result2.getCells().get(0).getValue()); } @Test - public void testVectorBlockLength() throws QueryException { + void testVectorBlockLength() throws QueryException { final MDXQuery lengthQuery = new MDXQuery( "SELECT [Measures].[VectorBlock.Length] ON COLUMNS" @@ -186,7 +186,7 @@ public void testVectorBlockLength() throws QueryException { } @Test - public void testVectorBlockRefCount() throws QueryException { + void testVectorBlockRefCount() throws QueryException { final MDXQuery refCountQuery = new MDXQuery( "SELECT [Measures].[VectorBlock.RefCount] ON COLUMNS" From feaaf8f2c9db0fba1821f5cef8eae89be9cecde6 Mon Sep 17 00:00:00 2001 From: Olivier Peyrusse Date: Thu, 5 Dec 2024 15:11:09 +0100 Subject: [PATCH 07/10] Clean the code after the review --- pom.xml | 42 +--- .../impl/ActiveUiResourceServerConfig.java | 106 --------- .../mac/cfg/impl/ContentServiceConfig.java | 27 +-- .../mac/cfg/impl/MacServerConfig.java | 88 ++++---- .../impl/NoWriteDatastoreServiceConfig.java | 86 -------- .../activeviam/mac/cfg/impl/SourceConfig.java | 14 +- .../mac/cfg/security/impl/CorsConfig.java | 15 +- .../mac/cfg/security/impl/SecurityConfig.java | 206 +----------------- .../mac/cfg/security/impl/UserConfig.java | 3 +- .../mac/memory/AnalysisDatastoreFeeder.java | 34 +-- .../visitor/impl/ADatastoreFeedVisitor.java | 6 +- .../memory/visitor/impl/AFeedVisitor.java | 24 +- .../impl/AFeedVisitorWithDictionary.java | 11 +- .../impl/ChunkSetStatisticVisitor.java | 23 +- .../visitor/impl/DatastoreFeederVisitor.java | 36 +-- .../memory/visitor/impl/FeedVisitor.java | 30 ++- .../visitor/impl/LevelStatisticVisitor.java | 12 +- .../visitor/impl/PivotFeederVisitor.java | 40 ++-- .../visitor/impl/VectorStatisticVisitor.java | 18 +- src/main/resources/application.yml | 12 - src/main/resources/static/activeui/env.js | 14 -- src/main/resources/static/atoti-ui/env.js | 19 ++ .../{activeui => atoti-ui}/extensions.json | 4 +- .../static/js/492.84c9d447.js | 0 .../static/js/7.b5b094db.chunk.js | 0 .../static/js/main.6b2474f9.js | 0 .../text-editor-extension.js | 0 27 files changed, 222 insertions(+), 648 deletions(-) delete mode 100644 src/main/java/com/activeviam/mac/cfg/impl/ActiveUiResourceServerConfig.java delete mode 100644 src/main/java/com/activeviam/mac/cfg/impl/NoWriteDatastoreServiceConfig.java delete mode 100644 src/main/resources/static/activeui/env.js create mode 100644 src/main/resources/static/atoti-ui/env.js rename src/main/resources/static/{activeui => atoti-ui}/extensions.json (54%) rename src/main/resources/static/{activeui => atoti-ui}/extensions/text-editor-extension/static/js/492.84c9d447.js (100%) rename src/main/resources/static/{activeui => atoti-ui}/extensions/text-editor-extension/static/js/7.b5b094db.chunk.js (100%) rename src/main/resources/static/{activeui => atoti-ui}/extensions/text-editor-extension/static/js/main.6b2474f9.js (100%) rename src/main/resources/static/{activeui => atoti-ui}/extensions/text-editor-extension/text-editor-extension.js (100%) diff --git a/pom.xml b/pom.xml index 849ae181..c3240feb 100644 --- a/pom.xml +++ b/pom.xml @@ -12,7 +12,7 @@ com.activeviam.tools mac - 3.0.0-SNAPSHOT + 3.1.0-SNAPSHOT Atoti Server Memory Analysis Cube @@ -23,10 +23,9 @@ - 11 + 21 6.1.3-SNAPSHOT - 5.2.0-beta 10.1.30 @@ -65,36 +64,17 @@ atoti-server-starter ${atoti-server.version} + + com.activeviam.springboot + atoti-ui-starter + ${atoti-server.version} + org.projectlombok lombok provided - - - com.activeviam.activepivot - activepivot-server-spring - - - - - - com.activeviam.tech - composer-core - compile - - - - com.activeviam.tech - content-server-spring - - - com.activeviam.web - activeviam-web-spring - - org.hibernate @@ -111,14 +91,6 @@ 6.4.10.Final - - - com.activeviam.activeui - activeui - ${atoti-ui.version} - runtime - - org.springframework.boot diff --git a/src/main/java/com/activeviam/mac/cfg/impl/ActiveUiResourceServerConfig.java b/src/main/java/com/activeviam/mac/cfg/impl/ActiveUiResourceServerConfig.java deleted file mode 100644 index ca7dde52..00000000 --- a/src/main/java/com/activeviam/mac/cfg/impl/ActiveUiResourceServerConfig.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * (C) ActiveViam 2016 - * ALL RIGHTS RESERVED. This material is the CONFIDENTIAL and PROPRIETARY - * property of ActiveViam. Any unauthorized use, - * reproduction or transfer of this material is strictly prohibited - */ - -package com.activeviam.mac.cfg.impl; - -import com.activeviam.web.spring.internal.config.ASpringResourceServerConfig; -import java.util.Collections; -import java.util.Set; -import org.springframework.context.annotation.Configuration; - -/** - * Spring configuration for Atoti UI web application. - * - * @author ActiveViam - */ -@Configuration -public class ActiveUiResourceServerConfig extends ASpringResourceServerConfig { - - /** The namespace of the Atoti UI web application. */ - public static final String NAMESPACE = "ui"; - - /** Constructor. */ - public ActiveUiResourceServerConfig() { - super("/" + NAMESPACE); - } - - @Override - protected void registerRedirections(final ResourceRegistry registry) { - super.registerRedirections(registry); - // Redirect from the root to ActiveUI - registry.redirectTo(NAMESPACE + "/index.html", "/"); - // Redirect the calls to env*.js to the AP ones rather than the default of the ActiveUI apps - registry.serve("/content/ui/env*.js").addResourceLocations("classpath:/static/content/"); - registry.serve("/ui/env*.js").addResourceLocations("classpath:/static/activeui/"); - registerExtensions(registry); - } - - protected void registerExtensions(final ResourceRegistry registry) { - registry.serve("/ui/extensions*.json").addResourceLocations("classpath:/static/activeui/"); - } - - /** - * Registers resources to serve. - * - * @param registry registry to use - */ - @Override - protected void registerResources(final ResourceRegistry registry) { - super.registerResources(registry); - - // ActiveUI web app also serves request to the root, so that the redirection from root to - // ActiveUI works - registry - .serve("/") - .addResourceLocations("/", "classpath:META-INF/resources/") - .setCacheControl(getDefaultCacheControl()); - } - - /** - * Gets the extensions of files to serve. - * - * @return all files extensions - */ - @Override - public Set getServedExtensions() { - return Set.of( - // Default HTML files - "html", - "js", - "css", - "map", - "json", - // Image extensions - "png", - "jpg", - "gif", - "ico", - // Font extensions - "eot", - "svg", - "ttf", - "woff", - "woff2"); - } - - @Override - public Set getServedDirectories() { - return Collections.singleton("/"); - } - - @Override - public Set getResourceLocations() { - // ActiveUI is integrated in the sandbox project thanks to Maven integration. - // You can read more about this feature here - // https://support.activeviam.com/documentation/activeui/4.2.0/dev/setup/maven-integration.html - - return Set.of( - "/activeui/", // index.html, favicon.ico, etc. - "classpath:META-INF/resources/webjars/activeui/"); // ActiveUI SDK UMD scripts - // and supporting assets - } -} diff --git a/src/main/java/com/activeviam/mac/cfg/impl/ContentServiceConfig.java b/src/main/java/com/activeviam/mac/cfg/impl/ContentServiceConfig.java index b94d5fc8..c9c13d71 100644 --- a/src/main/java/com/activeviam/mac/cfg/impl/ContentServiceConfig.java +++ b/src/main/java/com/activeviam/mac/cfg/impl/ContentServiceConfig.java @@ -29,11 +29,11 @@ import java.util.Map; import java.util.Properties; import javax.sql.DataSource; +import lombok.RequiredArgsConstructor; import org.hibernate.HibernateException; import org.hibernate.SessionFactory; import org.hibernate.cfg.AvailableSettings; import org.springframework.beans.factory.BeanInitializationException; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -52,21 +52,9 @@ * @author ActiveViam */ @Configuration +@RequiredArgsConstructor public class ContentServiceConfig implements IActivePivotContentServiceConfig { - /** - * The name of the property which contains the role allowed to add new calculated members in the - * configuration service. - */ - public static final String CALCULATED_MEMBER_ROLE_PROPERTY = - "contentServer.security.calculatedMemberRole"; - - /** - * The name of the property which contains the role allowed to add new KPIs in the configuration - * service. - */ - public static final String KPI_ROLE_PROPERTY = "contentServer.security.kpiRole"; - /** * The name of the property that controls whether or not to force the reloading of the predefined * bookmarks even if they were already loaded previously. @@ -76,8 +64,7 @@ public class ContentServiceConfig implements IActivePivotContentServiceConfig { /** The name of the property that precise the name of the folder the bookmarks are in. */ public static final String UI_FOLDER_PROPERTY = "bookmarks.folder"; - /** Instance of the Spring context environment. */ - @Autowired public Environment env; + private final Environment env; /** * Loads the Hibernate's configuration from the specified file. @@ -164,18 +151,16 @@ public IActivePivotContentService activePivotContentService() { return new ActivePivotContentServiceBuilder() .with(contentService()) .withCacheForEntitlements(-1) - .needInitialization( - this.env.getRequiredProperty(CALCULATED_MEMBER_ROLE_PROPERTY), - this.env.getRequiredProperty(KPI_ROLE_PROPERTY)) + .needInitialization(SecurityConfig.ROLE_USER, SecurityConfig.ROLE_USER) .build(); } private Map> defaultBookmarkPermissions() { return Map.of( Role.OWNERS, - List.of(SecurityConfig.ROLE_CS_ROOT), + List.of(SecurityConfig.ROLE_USER), Role.READERS, - List.of(SecurityConfig.ROLE_CS_ROOT)); + List.of(SecurityConfig.ROLE_USER)); } /** diff --git a/src/main/java/com/activeviam/mac/cfg/impl/MacServerConfig.java b/src/main/java/com/activeviam/mac/cfg/impl/MacServerConfig.java index b29d2d16..4fbe7cd1 100644 --- a/src/main/java/com/activeviam/mac/cfg/impl/MacServerConfig.java +++ b/src/main/java/com/activeviam/mac/cfg/impl/MacServerConfig.java @@ -10,15 +10,11 @@ import com.activeviam.activepivot.server.spring.api.config.IActivePivotConfig; import com.activeviam.activepivot.server.spring.api.config.IActivePivotContentServiceConfig; import com.activeviam.activepivot.server.spring.api.config.IDatastoreConfig; -import com.activeviam.activepivot.server.spring.private_.config.impl.ActivePivotServicesConfig; -import com.activeviam.activepivot.server.spring.private_.config.impl.ActiveViamRestServicesConfig; -import com.activeviam.activepivot.server.spring.private_.config.impl.ActiveViamWebSocketServicesConfig; import com.activeviam.mac.cfg.security.impl.SecurityConfig; import com.activeviam.mac.cfg.security.impl.UserConfig; import com.activeviam.tech.core.api.agent.AgentException; import com.activeviam.web.spring.internal.JMXEnabler; import com.activeviam.web.spring.internal.config.JwtConfig; -import com.activeviam.web.spring.internal.config.JwtRestServiceConfig; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.event.ApplicationReadyEvent; import org.springframework.context.annotation.Bean; @@ -32,63 +28,71 @@ * Spring configuration of the ActivePivot Sandbox application. * *

We use {@link PropertySource} annotation(s) to define some .properties file(s), whose content - * will be loaded into the Spring {@link Environment}, allowing some externally-driven configuration - * of the application. Parameters can be quickly changed by modifying the {@code sandbox.properties} - * file. + * will be loaded into the Spring {@link Environment}, allowing some externally-driven configuration of the + * application. Parameters can be quickly changed by modifying the {@code sandbox.properties} file. * *

We use {@link Import} annotation(s) to reference additional Spring {@link Configuration} - * classes, so that we can manage the application configuration in a modular way (split by - * domain/feature, re-use of core config, override of core config, customized config, etc...). + * classes, so that we can manage the application configuration in a modular way (split by domain/feature, re-use + * of core config, override of core config, customized config, etc...). * *

Spring best practices recommends not to have arguments in bean methods if possible. One should - * rather autowire the appropriate spring configurations (and not beans directly unless necessary), - * and use the beans from there. + * rather autowire the appropriate spring configurations (and not beans directly unless necessary), and use the + * beans from there. * * @author ActiveViam */ @Configuration @Import( value = { - JwtRestServiceConfig.class, - JwtConfig.class, - ManagerDescriptionConfig.class, - - // Pivot - ActivePivotWithDatastoreConfig.class, - NoWriteDatastoreServiceConfig.class, - ActivePivotServicesConfig.class, - ActiveViamRestServicesConfig.class, - ActiveViamWebSocketServicesConfig.class, - - // Content server - ContentServiceConfig.class, - ActiveUiResourceServerConfig.class, - - // Specific to monitoring server - SecurityConfig.class, - UserConfig.class, - SourceConfig.class, + JwtConfig.class, + ManagerDescriptionConfig.class, + + // Pivot + ActivePivotWithDatastoreConfig.class, + + // Content server + ContentServiceConfig.class, + + // Specific to monitoring server + SecurityConfig.class, + UserConfig.class, + SourceConfig.class, }) public class MacServerConfig { - /** Datastore spring configuration. */ - @Autowired protected IDatastoreConfig datastoreConfig; + /** + * Datastore spring configuration. + */ + @Autowired + protected IDatastoreConfig datastoreConfig; - /** ActivePivot spring configuration. */ - @Autowired protected IActivePivotConfig apConfig; + /** + * ActivePivot spring configuration. + */ + @Autowired + protected IActivePivotConfig apConfig; - /** ActivePivot content service spring configuration. */ - @Autowired protected IActivePivotContentServiceConfig apContentServiceConfig; + /** + * ActivePivot content service spring configuration. + */ + @Autowired + protected IActivePivotContentServiceConfig apContentServiceConfig; - /** Content Service configuration. */ - @Autowired protected ContentServiceConfig contentServiceConfig; + /** + * Content Service configuration. + */ + @Autowired + protected ContentServiceConfig contentServiceConfig; - /** Spring configuration of the source files of the Memory Analysis Cube application. */ - @Autowired protected SourceConfig sourceConfig; + /** + * Spring configuration of the source files of the Memory Analysis Cube application. + */ + @Autowired + protected SourceConfig sourceConfig; /** - * Initialize and start the ActivePivot Manager, after performing all the injections into the - * ActivePivot plug-ins. + * Initialize and start the ActivePivot Manager, after performing all the injections into the ActivePivot + * plug-ins. * * @return void */ diff --git a/src/main/java/com/activeviam/mac/cfg/impl/NoWriteDatastoreServiceConfig.java b/src/main/java/com/activeviam/mac/cfg/impl/NoWriteDatastoreServiceConfig.java deleted file mode 100644 index e3c1aa11..00000000 --- a/src/main/java/com/activeviam/mac/cfg/impl/NoWriteDatastoreServiceConfig.java +++ /dev/null @@ -1,86 +0,0 @@ -/* - * (C) ActiveViam 2019 - * ALL RIGHTS RESERVED. This material is the CONFIDENTIAL and PROPRIETARY - * property of ActiveViam. Any unauthorized use - * reproduction or transfer of this material is strictly prohibited - */ - -package com.activeviam.mac.cfg.impl; - -import com.activeviam.activepivot.server.intf.api.database.config.ITablePermissions; -import com.activeviam.activepivot.server.intf.api.database.config.ITableSecurity; -import com.activeviam.activepivot.server.spring.private_.rest.database.ADatabaseServiceConfig; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; -import org.springframework.context.annotation.Configuration; - -/** Configuration preventing any edition to the datastore from the remote services. */ -@Configuration -public class NoWriteDatastoreServiceConfig extends ADatabaseServiceConfig { - - /** - * A constant for store security. - * - *

This allows to read any fields but forbids all updates. - */ - protected static final ITableSecurity defaultStoreSecurity = - new ITableSecurity() { - - @Override - public boolean isDeletingRecordsAllowed() { - return false; - } - - @Override - public boolean isAddingNewRecordsAllowed() { - return false; - } - - @Override - public ITablePermissions getTablePermissions() { - return new ITablePermissions() { - - @Override - public Set getTableWriterRoles() { - return Collections.emptySet(); - } - - @Override - public Set getTableReaderRoles() { - return Collections.emptySet(); - } - - @Override - public boolean canWriteField(String field, Set roles) { - return false; - } - - @Override - public boolean canReadField(String field, Set roles) { - return true; - } - }; - } - }; - /** - * A constant for the map which will always return the same store security, also defined as a - * constant below. - */ - protected static final Map storesSecurityMap = - new HashMap<>() { - - private static final long serialVersionUID = 5_08_00L; - - @Override - public ITableSecurity get(Object key) { - return containsKey(key) ? super.get(key) : defaultStoreSecurity; - } - }; - - /** Constructor. */ - public NoWriteDatastoreServiceConfig() { - super(Collections.emptyMap(), Collections.emptyMap(), storesSecurityMap, DEFAULT_QUERY_TIMEOUT); - } -} diff --git a/src/main/java/com/activeviam/mac/cfg/impl/SourceConfig.java b/src/main/java/com/activeviam/mac/cfg/impl/SourceConfig.java index d44ece25..c9286c3b 100644 --- a/src/main/java/com/activeviam/mac/cfg/impl/SourceConfig.java +++ b/src/main/java/com/activeviam/mac/cfg/impl/SourceConfig.java @@ -10,7 +10,7 @@ import static java.util.stream.Collectors.mapping; import static java.util.stream.Collectors.toUnmodifiableList; -import com.activeviam.database.datastore.internal.IInternalDatastore; +import com.activeviam.database.datastore.api.IDatastore; import com.activeviam.database.datastore.internal.impl.Datastore; import com.activeviam.mac.Loggers; import com.activeviam.mac.memory.AnalysisDatastoreFeeder; @@ -41,6 +41,7 @@ import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.Stream; +import lombok.RequiredArgsConstructor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Lazy; @@ -52,22 +53,19 @@ * @author ActiveViam */ @Configuration +@RequiredArgsConstructor public class SourceConfig { /** The name of the property that holds the path to the statistics folder. */ public static final String STATISTIC_FOLDER_PROPERTY = "statistic.folder"; private static final Logger LOGGER = Logger.getLogger(Loggers.LOADING); + /** Autowired {@link Datastore} to be fed by this source. */ - protected IInternalDatastore datastore; + private final IDatastore datastore; /** Spring environment, automatically wired. */ - protected Environment env; - - public SourceConfig(final IInternalDatastore datastore, final Environment env) { - this.datastore = datastore; - this.env = env; - } + private final Environment env; /** * Provides a {@link DirectoryCsvTopic topic}. diff --git a/src/main/java/com/activeviam/mac/cfg/security/impl/CorsConfig.java b/src/main/java/com/activeviam/mac/cfg/security/impl/CorsConfig.java index bff9644d..cb5ca029 100644 --- a/src/main/java/com/activeviam/mac/cfg/security/impl/CorsConfig.java +++ b/src/main/java/com/activeviam/mac/cfg/security/impl/CorsConfig.java @@ -14,10 +14,11 @@ import org.springframework.context.annotation.Configuration; import org.springframework.core.env.Environment; import org.springframework.security.config.annotation.authentication.configuration.EnableGlobalAuthentication; +import org.springframework.web.cors.CorsConfiguration; /** - * Generic implementation for security configuration of a server hosting ActivePivot, or Content - * server or ActiveMonitor. + * Generic implementation for security configuration of a server hosting ActivePivot, or Content server or + * ActiveMonitor. * *

This class contains methods: * @@ -34,10 +35,14 @@ @Configuration public class CorsConfig implements ICorsConfig { - /** The name of the Environment to use. */ + /** + * The name of the Environment to use. + */ protected Environment env; - /** The address the UI is exposed to. */ + /** + * The address the UI is exposed to. + */ public static final String ACTIVEUI_ADDRESS = "activeui.address"; public CorsConfig(@Autowired Environment env) { @@ -46,6 +51,6 @@ public CorsConfig(@Autowired Environment env) { @Override public List getAllowedOrigins() { - return Collections.singletonList(env.getRequiredProperty(ACTIVEUI_ADDRESS)); + return Collections.singletonList(env.getProperty(ACTIVEUI_ADDRESS, CorsConfiguration.ALL)); } } diff --git a/src/main/java/com/activeviam/mac/cfg/security/impl/SecurityConfig.java b/src/main/java/com/activeviam/mac/cfg/security/impl/SecurityConfig.java index 3435e26d..1518f233 100644 --- a/src/main/java/com/activeviam/mac/cfg/security/impl/SecurityConfig.java +++ b/src/main/java/com/activeviam/mac/cfg/security/impl/SecurityConfig.java @@ -1,96 +1,40 @@ package com.activeviam.mac.cfg.security.impl; -import static com.activeviam.web.core.api.IUrlBuilder.url; - -import com.activeviam.activepivot.server.impl.private_.spring.ContextValueFilter; -import com.activeviam.activepivot.server.spring.private_.pivot.security.impl.UserDetailsServiceWrapper; -import com.activeviam.tech.contentserver.storage.api.IContentService; -import com.activeviam.tech.core.api.security.IUserDetailsService; import com.activeviam.web.spring.api.config.IJwtConfig; import com.activeviam.web.spring.api.jwt.JwtAuthenticationProvider; -import com.activeviam.web.spring.internal.config.JwtRestServiceConfig; -import com.activeviam.web.spring.internal.security.NoRedirectLogoutSuccessHandler; -import com.activeviam.web.spring.private_.jwt.JwtFilter; -import org.springframework.beans.factory.annotation.Autowired; +import lombok.RequiredArgsConstructor; import org.springframework.boot.web.servlet.ServletContextInitializer; -import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import org.springframework.core.annotation.Order; -import org.springframework.core.env.Environment; -import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.security.authentication.AuthenticationManager; import org.springframework.security.authentication.AuthenticationProvider; import org.springframework.security.authentication.ProviderManager; import org.springframework.security.authentication.dao.DaoAuthenticationProvider; -import org.springframework.security.config.Customizer; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; -import org.springframework.security.config.annotation.web.configurers.HeadersConfigurer; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.factory.PasswordEncoderFactories; import org.springframework.security.crypto.password.DelegatingPasswordEncoder; import org.springframework.security.crypto.password.NoOpPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.web.AuthenticationEntryPoint; -import org.springframework.security.web.SecurityFilterChain; import org.springframework.security.web.authentication.HttpStatusEntryPoint; -import org.springframework.security.web.authentication.switchuser.SwitchUserFilter; -import org.springframework.security.web.context.SecurityContextPersistenceFilter; import org.springframework.security.web.firewall.StrictHttpFirewall; @Configuration @EnableWebSecurity +@RequiredArgsConstructor public class SecurityConfig { - /** Authentication Bean Name. */ - public static final String BASIC_AUTH_BEAN_NAME = "basicAuthenticationEntryPoint"; - - /** ActivePivot Cookie Name. */ - public static final String AP_COOKIE_NAME = "AP_JSESSIONID"; - /** Name of the User Role. */ public static final String ROLE_USER = "ROLE_USER"; /** Name of the Admin Role. */ public static final String ROLE_ADMIN = "ROLE_ADMIN"; - /** Name of the Tech Role. */ - public static final String ROLE_TECH = "ROLE_TECH"; - - /** Name of the ContentService Root Role. */ - public static final String ROLE_CS_ROOT = IContentService.ROLE_ROOT; - - /** The address the UI is exposed to. */ - public static final String ACTIVEUI_ADDRESS = "activeui.address"; - - private static final String REST_API_URL_PREFIX = "/versions/rest"; /** Name of the Cookies of the MAC application. */ public static final String COOKIE_NAME = "MEMORY_ANALYSIS_CUBE"; - private static final String PING_SUFFIX = "/ping"; - - /** The User Configuration. */ - protected UserConfig userDetailsConfig; - - /** The JWT Configuration. */ - protected IJwtConfig jwtConfig; - /** The name of the Environment to use. */ - protected Environment env; - /** {@code true} to enable the logout URL. */ - protected final WebConfiguration webConfiguration; - - public SecurityConfig( - final UserConfig userDetailsConfig, final IJwtConfig jwtConfig, final Environment env) { - this.userDetailsConfig = userDetailsConfig; - this.jwtConfig = jwtConfig; - this.env = env; - this.webConfiguration = new WebConfiguration(COOKIE_NAME); - } - /** * As of Spring Security 5.0, the way the passwords are encoded must be specified. When logging, * the input password will be encoded and compared with the stored encoded password. To determine @@ -156,35 +100,6 @@ public AuthenticationProvider inMemoryAuthenticationProvider( return authenticationProvider; } - /** - * Configures the authentication of the whole application. - * - *

This binds the defined user service to the authentication and sets the source for JWT - * tokens. - * - * @param auth Spring builder to manage authentication - * @throws Exception in case of error - */ - @Autowired - public void configureGlobal( - final AuthenticationManagerBuilder auth, - final JwtAuthenticationProvider jwtAuthenticationProvider) { - auth - // Required to allow JWT - .authenticationProvider(jwtAuthenticationProvider); - } - - /** - * Returns the spring security bean user details service wrapper. - * - * @return the {@link IUserDetailsService} used as spring security bean user details service - * wrapper. - */ - @Bean - public IUserDetailsService qfsUserDetailsService() { - return new UserDetailsServiceWrapper(this.userDetailsConfig.userDetailsService()); - } - /** * Returns a bean initializing the Cookies name in the Servlet Spring context. * @@ -219,121 +134,4 @@ public StrictHttpFirewall configureFirewall() { firewall.setAllowSemicolon(false); return firewall; } - - @Bean - @Order(1) - public SecurityFilterChain activeUiSecurity(final HttpSecurity http, final JwtFilter jwtFilter) - throws Exception { - configureWebSecurity(http, jwtFilter, this.webConfiguration); - final String activeUiUrl = env.getRequiredProperty(ACTIVEUI_ADDRESS); - // Only these URLs must be handled by this filter chain - http.securityMatcher(url(activeUiUrl)) - .authorizeHttpRequests( - auth -> - auth.requestMatchers(HttpMethod.OPTIONS) - .permitAll() - .requestMatchers(HttpMethod.GET) - .permitAll()); - // this allows pre-flight cross-origin requests - http.cors(Customizer.withDefaults()); - // Authorizing pages to be embedded in iframes to have ActiveUI in ActiveMonitor UI - http.headers( - customizer -> customizer.frameOptions(HeadersConfigurer.FrameOptionsConfig::disable)); - return http.build(); - } - - @Bean - @Order(2) - public SecurityFilterChain jwtSecurity( - final HttpSecurity http, - final ApplicationContext applicationContext, - final AuthenticationEntryPoint authenticationEntryPoint) - throws Exception { - http.securityMatcher(JwtRestServiceConfig.REST_API_URL_PREFIX + "/**") - // As of Spring Security 4.0, CSRF protection is enabled by default. - .csrf(AbstractHttpConfigurer::disable) - .cors(Customizer.withDefaults()) - // Configure CORS - .authorizeHttpRequests( - auth -> - auth.requestMatchers(HttpMethod.OPTIONS, "/**") - .permitAll() - .requestMatchers("/**") - .hasAnyAuthority(ROLE_USER)) - .httpBasic(customizer -> customizer.authenticationEntryPoint(authenticationEntryPoint)); - return http.build(); - } - - @Bean - @Order(3) - public SecurityFilterChain versionSecurity(final HttpSecurity http) throws Exception { - http.securityMatcher(REST_API_URL_PREFIX + "/**") - // As of Spring Security 4.0, CSRF protection is enabled by default. - .csrf(AbstractHttpConfigurer::disable) - .cors(Customizer.withDefaults()) - .authorizeHttpRequests(auth -> auth.requestMatchers("/**").permitAll()); - return http.build(); - } - - @Bean - @Order(4) - public SecurityFilterChain activePivotSecurity( - final HttpSecurity http, - final JwtFilter jwtFilter, - final ContextValueFilter contextValueFilter) - throws Exception { - configureWebSecurity(http, jwtFilter, this.webConfiguration); - http - // The ping service is temporarily authenticated (see PIVOT-3149) - .securityMatcher(url(REST_API_URL_PREFIX, PING_SUFFIX)) - .authorizeHttpRequests( - auth -> auth.requestMatchers(HttpMethod.GET).hasAnyAuthority(ROLE_USER, ROLE_TECH)) - // Rest services - .securityMatcher(REST_API_URL_PREFIX + "/**") - .authorizeHttpRequests( - auth -> - auth.requestMatchers(HttpMethod.OPTIONS) - .permitAll() - .anyRequest() - .hasAnyAuthority(ROLE_USER)) - // SwitchUserFilter is the last filter in the chain. See FilterComparator class. - .addFilterAfter(contextValueFilter, SwitchUserFilter.class); - return http.build(); - } - - // One has to be a user for all the other URLs - @Bean - @Order(5) - public SecurityFilterChain otherSecurity(final HttpSecurity http) throws Exception { - http.securityMatcher("/**") - .authorizeHttpRequests(auth -> auth.anyRequest().permitAll()) - .httpBasic(Customizer.withDefaults()); - return http.build(); - } - - public void configureWebSecurity( - HttpSecurity http, JwtFilter jwtFilter, WebConfiguration webConfig) throws Exception { - http - // As of Spring Security 4.0, CSRF protection is enabled by default. - .csrf(AbstractHttpConfigurer::disable) - .cors(Customizer.withDefaults()) - // To allow authentication with JWT (Required for ActiveUI) - .addFilterAfter(jwtFilter, SecurityContextPersistenceFilter.class); - - if (webConfig.logout) { - // Configure logout URL - http.logout( - auth -> - auth.permitAll() - .deleteCookies(webConfig.cookieName) - .invalidateHttpSession(true) - .logoutSuccessHandler(new NoRedirectLogoutSuccessHandler())); - } - - if (webConfig.useAnonymous) { - // Handle anonymous users. The granted authority ROLE_USER - // will be assigned to the anonymous request - http.anonymous(customizer -> customizer.principal("guest").authorities(ROLE_USER)); - } - } } diff --git a/src/main/java/com/activeviam/mac/cfg/security/impl/UserConfig.java b/src/main/java/com/activeviam/mac/cfg/security/impl/UserConfig.java index 9800b794..a6b12fea 100644 --- a/src/main/java/com/activeviam/mac/cfg/security/impl/UserConfig.java +++ b/src/main/java/com/activeviam/mac/cfg/security/impl/UserConfig.java @@ -7,6 +7,7 @@ package com.activeviam.mac.cfg.security.impl; +import com.activeviam.tech.contentserver.storage.api.IContentService; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.core.userdetails.UserDetailsService; @@ -43,7 +44,7 @@ public UserDetailsService userDetailsService() { SecurityConfig.ROLE_USER, SecurityConfig.ROLE_ADMIN, ROLE_KPI, - SecurityConfig.ROLE_CS_ROOT) + IContentService.ROLE_ROOT) .and() // We're done diff --git a/src/main/java/com/activeviam/mac/memory/AnalysisDatastoreFeeder.java b/src/main/java/com/activeviam/mac/memory/AnalysisDatastoreFeeder.java index 4cc24ea4..c3ff1554 100644 --- a/src/main/java/com/activeviam/mac/memory/AnalysisDatastoreFeeder.java +++ b/src/main/java/com/activeviam/mac/memory/AnalysisDatastoreFeeder.java @@ -10,9 +10,10 @@ import com.activeviam.database.api.conditions.BaseConditions; import com.activeviam.database.api.query.ListQuery; import com.activeviam.database.api.schema.FieldPath; +import com.activeviam.database.api.schema.IDataTable; +import com.activeviam.database.datastore.api.IDatastore; import com.activeviam.database.datastore.api.transaction.IOpenedTransaction; import com.activeviam.database.datastore.api.transaction.stats.IDatastoreSchemaTransactionInformation; -import com.activeviam.database.datastore.internal.IInternalDatastore; import com.activeviam.mac.Loggers; import com.activeviam.mac.entities.ChunkOwner; import com.activeviam.mac.entities.DistributedCubeOwner; @@ -22,7 +23,6 @@ import com.activeviam.mac.statistic.memory.visitor.impl.RegularEpochView; import com.activeviam.tech.observability.internal.memory.AMemoryStatistic; import com.activeviam.tech.records.api.ICursor; -import com.activeviam.tech.records.api.IRecordFormat; import com.activeviam.tech.records.api.IRecordReader; import java.util.Collection; import java.util.HashMap; @@ -52,12 +52,13 @@ public class AnalysisDatastoreFeeder { * statistics. */ private final Map> regularEpochsPerOwner; + /** * A mapping giving for each distributed owner the epochs that were expressed in their statistics. */ private final Map> distributedEpochsPerOwner; - final IInternalDatastore datastore; + final IDatastore datastore; /** * Constructor. @@ -65,7 +66,7 @@ public class AnalysisDatastoreFeeder { * @param dumpName the dump name to assign to the statistic * @param datastore */ - public AnalysisDatastoreFeeder(final String dumpName, IInternalDatastore datastore) { + public AnalysisDatastoreFeeder(final String dumpName, IDatastore datastore) { this.dumpName = dumpName; this.datastore = datastore; @@ -85,12 +86,12 @@ public AnalysisDatastoreFeeder(final String dumpName, IInternalDatastore datasto * @return the record */ private static Object[] generateEpochViewTuple( - final IRecordFormat recordFormat, + final IDataTable recordFormat, final ChunkOwner owner, final String dumpName, final long baseEpochId, final EpochView epochView) { - final Object[] tuple = new Object[recordFormat.getFieldCount()]; + final Object[] tuple = new Object[recordFormat.getFields().size()]; tuple[recordFormat.getFieldIndex(DatastoreConstants.EPOCH_VIEW__OWNER)] = owner; tuple[recordFormat.getFieldIndex(DatastoreConstants.CHUNK__DUMP_NAME)] = dumpName; tuple[recordFormat.getFieldIndex(DatastoreConstants.EPOCH_VIEW__BASE_EPOCH_ID)] = baseEpochId; @@ -126,8 +127,7 @@ private void feedChunk(final IOpenedTransaction transaction, final AMemoryStatis } statistic.accept( - new FeedVisitor( - this.datastore.getQueryMetadata().getMetadata(), transaction, this.dumpName)); + new FeedVisitor(this.datastore.getCurrentSchema(), transaction, this.dumpName)); if (LOGGER.isLoggable(Level.FINE)) { LOGGER.fine("Application processed " + statistic); @@ -182,13 +182,8 @@ private void replicateChunksForMissingEpochs(final IOpenedTransaction transactio } private void replicateDatastoreEpochs(final IOpenedTransaction transaction) { - final IRecordFormat epochViewRecordFormat = - this.datastore - .getQueryMetadata() - .getMetadata() - .getStoreMetadata(DatastoreConstants.EPOCH_VIEW_STORE) - .getStoreFormat() - .getRecordFormat(); + final var epochViewRecordFormat = + this.datastore.getCurrentSchema().getTable(DatastoreConstants.EPOCH_VIEW_STORE); for (final var datastoreEpochId : this.datastoreEpochs) { for (final ChunkOwner owner : this.regularEpochsPerOwner.keySet()) { @@ -222,13 +217,8 @@ private void replicateDatastoreEpochs(final IOpenedTransaction transaction) { } private void replicateDistributedEpochs(final IOpenedTransaction transaction) { - final IRecordFormat epochViewRecordFormat = - this.datastore - .getQueryMetadata() - .getMetadata() - .getStoreMetadata(DatastoreConstants.EPOCH_VIEW_STORE) - .getStoreFormat() - .getRecordFormat(); + final var epochViewRecordFormat = + this.datastore.getCurrentSchema().getTable(DatastoreConstants.EPOCH_VIEW_STORE); for (final ChunkOwner owner : this.distributedEpochsPerOwner.keySet()) { final Collection epochs = this.distributedEpochsPerOwner.get(owner); diff --git a/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/ADatastoreFeedVisitor.java b/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/ADatastoreFeedVisitor.java index b63d201f..9bc95391 100644 --- a/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/ADatastoreFeedVisitor.java +++ b/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/ADatastoreFeedVisitor.java @@ -7,8 +7,8 @@ package com.activeviam.mac.statistic.memory.visitor.impl; +import com.activeviam.database.api.schema.IDatabaseSchema; import com.activeviam.database.datastore.api.transaction.IOpenedTransaction; -import com.activeviam.database.datastore.internal.IDatastoreSchemaMetadata; import java.util.Collection; /** @@ -21,8 +21,10 @@ public abstract class ADatastoreFeedVisitor extends AFeedVisitorWithDictionar /** Names of the currently visited fields. */ protected Collection fields; + /** ID of the current index. */ protected Long indexId; + /** ID of the current reference. */ protected Long referenceId; @@ -34,7 +36,7 @@ public abstract class ADatastoreFeedVisitor extends AFeedVisitorWithDictionar * @param dumpName dumpName of the ongoing import */ public ADatastoreFeedVisitor( - IOpenedTransaction transaction, IDatastoreSchemaMetadata storageMetadata, String dumpName) { + IOpenedTransaction transaction, IDatabaseSchema storageMetadata, String dumpName) { super(transaction, storageMetadata, dumpName); } } diff --git a/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/AFeedVisitor.java b/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/AFeedVisitor.java index 08c1a305..5743a952 100644 --- a/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/AFeedVisitor.java +++ b/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/AFeedVisitor.java @@ -7,8 +7,9 @@ package com.activeviam.mac.statistic.memory.visitor.impl; +import com.activeviam.database.api.schema.IDataTable; +import com.activeviam.database.api.schema.IDatabaseSchema; import com.activeviam.database.datastore.api.transaction.IOpenedTransaction; -import com.activeviam.database.datastore.internal.IDatastoreSchemaMetadata; import com.activeviam.mac.entities.ChunkOwner; import com.activeviam.mac.memory.DatastoreConstants; import com.activeviam.tech.observability.internal.memory.AMemoryStatistic; @@ -25,10 +26,13 @@ public abstract class AFeedVisitor implements IMemoryStatisticVisitor { /** Ongoing transaction. */ protected final IOpenedTransaction transaction; + /** Metadata of the Analysis Datastore. */ - protected final IDatastoreSchemaMetadata storageMetadata; + protected final IDatabaseSchema storageMetadata; + /** Name of the import. */ protected final String dumpName; + /** Owner of the visited statistics. */ protected ChunkOwner owner = null; @@ -41,7 +45,7 @@ public abstract class AFeedVisitor implements IMemoryStatisticVisitor { */ public AFeedVisitor( final IOpenedTransaction transaction, - final IDatastoreSchemaMetadata storageMetadata, + final IDatabaseSchema storageMetadata, final String dumpName) { this.transaction = transaction; this.storageMetadata = storageMetadata; @@ -54,7 +58,7 @@ public AFeedVisitor( * @param storageMetadata metadata of the application datastore * @return the {@link DatastoreConstants#CHUNK_STORE} record format */ - protected static IRecordFormat getChunkFormat(IDatastoreSchemaMetadata storageMetadata) { + protected static IDataTable getChunkFormat(IDatabaseSchema storageMetadata) { return FeedVisitor.getRecordFormat(storageMetadata, DatastoreConstants.CHUNK_STORE); } @@ -64,7 +68,7 @@ protected static IRecordFormat getChunkFormat(IDatastoreSchemaMetadata storageMe * @param storageMetadata metadata of the application datastore * @return the {@link DatastoreConstants#PROVIDER_STORE} record format */ - protected static IRecordFormat getProviderFormat(IDatastoreSchemaMetadata storageMetadata) { + protected static IDataTable getProviderFormat(IDatabaseSchema storageMetadata) { return FeedVisitor.getRecordFormat(storageMetadata, DatastoreConstants.PROVIDER_STORE); } @@ -74,7 +78,7 @@ protected static IRecordFormat getProviderFormat(IDatastoreSchemaMetadata storag * @param storageMetadata metadata of the application datastore * @return the {@link DatastoreConstants#LEVEL_STORE} record format */ - protected static IRecordFormat getLevelFormat(IDatastoreSchemaMetadata storageMetadata) { + protected static IDataTable getLevelFormat(IDatabaseSchema storageMetadata) { return FeedVisitor.getRecordFormat(storageMetadata, DatastoreConstants.LEVEL_STORE); } @@ -84,7 +88,7 @@ protected static IRecordFormat getLevelFormat(IDatastoreSchemaMetadata storageMe * @param storageMetadata metadata of the application datastore * @return the {@link DatastoreConstants#INDEX_STORE} record format */ - protected static IRecordFormat getIndexFormat(IDatastoreSchemaMetadata storageMetadata) { + protected static IDataTable getIndexFormat(IDatabaseSchema storageMetadata) { return FeedVisitor.getRecordFormat(storageMetadata, DatastoreConstants.INDEX_STORE); } @@ -94,7 +98,7 @@ protected static IRecordFormat getIndexFormat(IDatastoreSchemaMetadata storageMe * @param storageMetadata metadata of the application datastore * @return the {@link DatastoreConstants#REFERENCE_STORE} record format */ - protected static IRecordFormat getReferenceFormat(IDatastoreSchemaMetadata storageMetadata) { + protected static IDataTable getReferenceFormat(IDatabaseSchema storageMetadata) { return FeedVisitor.getRecordFormat(storageMetadata, DatastoreConstants.REFERENCE_STORE); } @@ -104,7 +108,7 @@ protected static IRecordFormat getReferenceFormat(IDatastoreSchemaMetadata stora * @param storageMetadata metadata of the application datastore * @return the {@link DatastoreConstants#VERSION_STORE} record format */ - protected static IRecordFormat getVersionStoreFormat(IDatastoreSchemaMetadata storageMetadata) { + protected static IDataTable getVersionStoreFormat(IDatabaseSchema storageMetadata) { return FeedVisitor.getRecordFormat(storageMetadata, DatastoreConstants.VERSION_STORE); } @@ -114,7 +118,7 @@ protected static IRecordFormat getVersionStoreFormat(IDatastoreSchemaMetadata st * @param storageMetadata metadata of the application datastore * @return the {@link DatastoreConstants#DICTIONARY_STORE} record format */ - protected static IRecordFormat getDictionaryFormat(IDatastoreSchemaMetadata storageMetadata) { + protected static IDataTable getDictionaryFormat(IDatabaseSchema storageMetadata) { return FeedVisitor.getRecordFormat(storageMetadata, DatastoreConstants.DICTIONARY_STORE); } diff --git a/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/AFeedVisitorWithDictionary.java b/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/AFeedVisitorWithDictionary.java index 98d193fa..b15d9da6 100644 --- a/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/AFeedVisitorWithDictionary.java +++ b/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/AFeedVisitorWithDictionary.java @@ -10,15 +10,14 @@ import static com.activeviam.tech.observability.internal.memory.MemoryStatisticConstants.ATTR_NAME_CREATOR_CLASS; import static com.activeviam.tech.observability.internal.memory.MemoryStatisticConstants.ATTR_NAME_DICTIONARY_ID; +import com.activeviam.database.api.schema.IDatabaseSchema; import com.activeviam.database.datastore.api.transaction.IOpenedTransaction; -import com.activeviam.database.datastore.internal.IDatastoreSchemaMetadata; import com.activeviam.database.datastore.private_.structure.impl.StructureDictionaryManager; import com.activeviam.mac.Loggers; import com.activeviam.mac.memory.DatastoreConstants; import com.activeviam.tech.observability.api.memory.IStatisticAttribute; import com.activeviam.tech.observability.internal.memory.DictionaryStatistic; import com.activeviam.tech.observability.internal.memory.MemoryStatisticConstants; -import com.activeviam.tech.records.api.IRecordFormat; import java.util.logging.Logger; import lombok.AllArgsConstructor; import lombok.Data; @@ -40,7 +39,7 @@ public abstract class AFeedVisitorWithDictionary extends AFeedVisitor { * @param dumpName Name of the import */ public AFeedVisitorWithDictionary( - IOpenedTransaction transaction, IDatastoreSchemaMetadata storageMetadata, String dumpName) { + IOpenedTransaction transaction, IDatabaseSchema storageMetadata, String dumpName) { super(transaction, storageMetadata, dumpName); } @@ -88,7 +87,7 @@ protected DictionaryAttributes processDictionaryStatistic( if (!this.dictionaryAttributes .getDictionaryClass() .equals(StructureDictionaryManager.class.getName())) { - final IRecordFormat format = getDictionaryFormat(this.storageMetadata); + final var format = getDictionaryFormat(this.storageMetadata); final Object[] tuple = FeedVisitor.buildDictionaryTupleFrom( format, @@ -114,12 +113,16 @@ public static class DictionaryAttributes { /** An instance representing no dictionary (all attributes set to {@code null}. */ public static final DictionaryAttributes NONE = new DictionaryAttributes(); + /** ID of the current dictionary. */ protected Long dictionaryId; + /** Class of the current dictionary. */ protected String dictionaryClass; + /** Size of the current dictionary. */ protected Integer dictionarySize; + /** Order of the current dictionary (i.e. base-2 log of its size). */ protected Integer dictionaryOrder; diff --git a/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/ChunkSetStatisticVisitor.java b/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/ChunkSetStatisticVisitor.java index 14873f36..8ca783ab 100644 --- a/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/ChunkSetStatisticVisitor.java +++ b/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/ChunkSetStatisticVisitor.java @@ -7,8 +7,9 @@ package com.activeviam.mac.statistic.memory.visitor.impl; +import com.activeviam.database.api.schema.IDataTable; +import com.activeviam.database.api.schema.IDatabaseSchema; import com.activeviam.database.datastore.api.transaction.IOpenedTransaction; -import com.activeviam.database.datastore.internal.IDatastoreSchemaMetadata; import com.activeviam.mac.Workaround; import com.activeviam.mac.entities.ChunkOwner; import com.activeviam.mac.memory.DatastoreConstants; @@ -26,7 +27,6 @@ import com.activeviam.tech.observability.internal.memory.IndexStatistic; import com.activeviam.tech.observability.internal.memory.MemoryStatisticConstants; import com.activeviam.tech.observability.internal.memory.ReferenceStatistic; -import com.activeviam.tech.records.api.IRecordFormat; import java.time.Instant; import java.util.Collection; import java.util.Collections; @@ -41,30 +41,37 @@ public class ChunkSetStatisticVisitor extends ADatastoreFeedVisitor { /** The record format of the store that stores the chunks. */ - protected final IRecordFormat chunkRecordFormat; + protected final IDataTable chunkRecordFormat; /** The export date, found on the first statistics we read. */ protected final Instant current; /** Type of the root structure. */ protected final ParentType rootComponent; + /** Type of the direct parent structure. */ protected final ParentType directParentType; + /** id of the direct parent structure. */ protected final String directParentId; + /** Aggregate provider being currently visited. */ protected final Long providerId; /** The partition id of the visited statistic. */ protected final int partitionId; + /** Whether or not to ignore the field attributes of the visited statistics. */ protected final boolean ignoreFieldSpecifications; + /** The epoch id we are currently reading statistics for. */ protected Long epochId; + /** * Whether or not the currently visited statistics were flagged as used by the current version. */ protected UsedByVersion usedByVersion; + /** ID of the current {@link ChunkSet}. */ protected Long chunkSetId = null; @@ -93,7 +100,7 @@ public class ChunkSetStatisticVisitor extends ADatastoreFeedVisitor { * the encountered fields */ public ChunkSetStatisticVisitor( - final IDatastoreSchemaMetadata storageMetadata, + final IDatabaseSchema storageMetadata, final IOpenedTransaction transaction, final String dumpName, final Instant current, @@ -122,11 +129,7 @@ public ChunkSetStatisticVisitor( this.usedByVersion = usedByVersion; this.ignoreFieldSpecifications = ignoreFieldSpecifications; - this.chunkRecordFormat = - this.storageMetadata - .getStoreMetadata(DatastoreConstants.CHUNK_STORE) - .getStoreFormat() - .getRecordFormat(); + this.chunkRecordFormat = this.storageMetadata.getTable(DatastoreConstants.CHUNK_STORE); } @Override @@ -234,7 +237,7 @@ public Void visit(final ChunkStatistic chunkStatistic) { this.fields = Collections.singleton(fieldAttribute.asText()); } - final IRecordFormat format = this.chunkRecordFormat; + final var format = this.chunkRecordFormat; final Object[] tuple = FeedVisitor.buildChunkTupleFrom(format, chunkStatistic); FeedVisitor.setTupleElement( diff --git a/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/DatastoreFeederVisitor.java b/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/DatastoreFeederVisitor.java index 30f3d898..aba87fe5 100644 --- a/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/DatastoreFeederVisitor.java +++ b/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/DatastoreFeederVisitor.java @@ -9,8 +9,9 @@ import static com.activeviam.mac.statistic.memory.visitor.impl.DebugVisitor.DEBUG; +import com.activeviam.database.api.schema.IDataTable; +import com.activeviam.database.api.schema.IDatabaseSchema; import com.activeviam.database.datastore.api.transaction.IOpenedTransaction; -import com.activeviam.database.datastore.internal.IDatastoreSchemaMetadata; import com.activeviam.database.datastore.private_.IStore; import com.activeviam.mac.entities.StoreOwner; import com.activeviam.mac.memory.DatastoreConstants; @@ -27,7 +28,6 @@ import com.activeviam.tech.observability.internal.memory.IndexStatistic; import com.activeviam.tech.observability.internal.memory.MemoryStatisticConstants; import com.activeviam.tech.observability.internal.memory.ReferenceStatistic; -import com.activeviam.tech.records.api.IRecordFormat; import java.time.Instant; import java.util.Arrays; import java.util.Collection; @@ -46,17 +46,21 @@ public class DatastoreFeederVisitor extends ADatastoreFeedVisitor { /** The record format of the store that stores the chunks. */ - protected final IRecordFormat chunkRecordFormat; + protected final IDataTable chunkRecordFormat; + /** * A boolean that if true tells us that the currently visited component is responsible for storing * versioning data. */ // FIXME find a cleaner way to do that. (specific stat for instance). protected boolean isVersionColumn = false; + /** The export date, found on the first statistics we read. */ protected Instant current = null; + /** The epoch id we are currently reading statistics for. */ protected Long epochId = null; + /** Branch owning {@link #epochId}. */ protected String branch = null; @@ -67,10 +71,13 @@ public class DatastoreFeederVisitor extends ADatastoreFeedVisitor { /** Type of the root component visited. */ protected ParentType rootComponent; + /** Types of the direct parent component owning the chunk. */ protected ParentType directParentType; + /** Id of the direct parent owning the chunk. */ protected String directParentId; + /** The partition id of the visited statistic. */ protected Integer partitionId = null; @@ -85,20 +92,15 @@ public class DatastoreFeederVisitor extends ADatastoreFeedVisitor { * @param dumpName The name of the off-heap dump. Can be null. */ public DatastoreFeederVisitor( - final IDatastoreSchemaMetadata storageMetadata, + final IDatabaseSchema storageMetadata, final IOpenedTransaction transaction, final String dumpName) { super(transaction, storageMetadata, dumpName); - this.chunkRecordFormat = - this.storageMetadata - .getStoreMetadata(DatastoreConstants.CHUNK_STORE) - .getStoreFormat() - .getRecordFormat(); + this.chunkRecordFormat = this.storageMetadata.getTable(DatastoreConstants.CHUNK_STORE); } - private static Object[] buildIndexTupleFrom( - final IRecordFormat format, final IndexStatistic stat) { - final Object[] tuple = new Object[format.getFieldCount()]; + private static Object[] buildIndexTupleFrom(final IDataTable format, final IndexStatistic stat) { + final Object[] tuple = new Object[format.getFields().size()]; tuple[format.getFieldIndex(DatastoreConstants.INDEX_ID)] = stat.getAttribute(MemoryStatisticConstants.ATTR_NAME_INDEX_ID).asLong(); @@ -221,7 +223,7 @@ public Void visit(final DefaultMemoryStatistic stat) { final String initialBranch = this.branch; if (readEpochAndBranchIfAny(stat)) { - final IRecordFormat versionStoreFormat = getVersionStoreFormat(this.storageMetadata); + final var versionStoreFormat = getVersionStoreFormat(this.storageMetadata); final Object[] tuple = FeedVisitor.buildVersionTupleFrom( versionStoreFormat, stat, this.dumpName, this.epochId, this.branch); @@ -295,7 +297,7 @@ public Void visit(final ChunkSetStatistic stat) { @Override public Void visit(final ReferenceStatistic referenceStatistic) { final Object[] tuple = buildPartOfReferenceStatisticTuple(referenceStatistic); - final IRecordFormat refStoreFormat = getReferenceFormat(this.storageMetadata); + final var refStoreFormat = getReferenceFormat(this.storageMetadata); // fill out the tuple this.referenceId = @@ -332,7 +334,7 @@ public Void visit(final ReferenceStatistic referenceStatistic) { @Override public Void visit(final IndexStatistic stat) { - final IRecordFormat format = getIndexFormat(this.storageMetadata); + final var format = getIndexFormat(this.storageMetadata); final Object[] tuple = buildIndexTupleFrom(format, stat); this.indexId = stat.getAttribute(MemoryStatisticConstants.ATTR_NAME_INDEX_ID).asLong(); @@ -562,9 +564,9 @@ private void readFieldsIfAny(final IMemoryStatistic stat) { */ protected Object[] buildPartOfReferenceStatisticTuple( final ReferenceStatistic referenceStatistic) { - final IRecordFormat refStoreFormat = getReferenceFormat(this.storageMetadata); + final var refStoreFormat = getReferenceFormat(this.storageMetadata); - final Object[] tuple = new Object[refStoreFormat.getFieldCount()]; + final Object[] tuple = new Object[refStoreFormat.getFields().size()]; tuple[refStoreFormat.getFieldIndex(DatastoreConstants.REFERENCE_FROM_STORE)] = referenceStatistic.getAttribute(DatastoreConstants.REFERENCE_FROM_STORE).asText(); tuple[refStoreFormat.getFieldIndex(DatastoreConstants.REFERENCE_FROM_STORE_PARTITION_ID)] = diff --git a/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/FeedVisitor.java b/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/FeedVisitor.java index d89b6904..7d5c8279 100644 --- a/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/FeedVisitor.java +++ b/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/FeedVisitor.java @@ -9,8 +9,9 @@ import static com.activeviam.tech.observability.internal.memory.MemoryStatisticConstants.ATTR_NAME_CREATOR_CLASS; +import com.activeviam.database.api.schema.IDataTable; +import com.activeviam.database.api.schema.IDatabaseSchema; import com.activeviam.database.datastore.api.transaction.IOpenedTransaction; -import com.activeviam.database.datastore.internal.IDatastoreSchemaMetadata; import com.activeviam.mac.Loggers; import com.activeviam.mac.memory.DatastoreConstants; import com.activeviam.tech.observability.api.memory.IMemoryStatistic; @@ -40,7 +41,7 @@ public class FeedVisitor implements IMemoryStatisticVisitor { private static final Logger LOGGER = Logger.getLogger(Loggers.LOADING); - private final IDatastoreSchemaMetadata storageMetadata; + private final IDatabaseSchema storageMetadata; private final IOpenedTransaction transaction; private final String dumpName; private static final AtomicLong chunkIdGenerator = new AtomicLong(0L); @@ -53,9 +54,7 @@ public class FeedVisitor implements IMemoryStatisticVisitor { * @param dumpName name of the import being currently executed */ public FeedVisitor( - final IDatastoreSchemaMetadata storageMetadata, - final IOpenedTransaction tm, - final String dumpName) { + final IDatabaseSchema storageMetadata, final IOpenedTransaction tm, final String dumpName) { this.storageMetadata = storageMetadata; this.transaction = tm; this.dumpName = dumpName; @@ -74,8 +73,8 @@ protected static void add( transaction.add(store, tuple); } - static Object[] buildChunkTupleFrom(final IRecordFormat format, final ChunkStatistic stat) { - final Object[] tuple = new Object[format.getFieldCount()]; + static Object[] buildChunkTupleFrom(final IDataTable format, final ChunkStatistic stat) { + final Object[] tuple = new Object[format.getFields().size()]; tuple[format.getFieldIndex(DatastoreConstants.CHUNK_ID)] = getChunkId(stat); tuple[format.getFieldIndex(DatastoreConstants.CHUNK__CLASS)] = stat.getAttribute(ATTR_NAME_CREATOR_CLASS).asText(); @@ -125,7 +124,7 @@ static void writeChunkTupleForFields( final ChunkStatistic statistic, final IOpenedTransaction transaction, final Collection fields, - final IRecordFormat format, + final IDataTable format, final Object... tuple) { if (fields == null || fields.isEmpty()) { FeedVisitor.add(statistic, transaction, DatastoreConstants.CHUNK_STORE, tuple); @@ -139,12 +138,12 @@ static void writeChunkTupleForFields( } static Object[] buildDictionaryTupleFrom( - final IRecordFormat format, + final IDataTable format, final long dictionaryId, final String dictionaryClass, final int dictionarySize, final int dictionaryOrder) { - final Object[] tuple = new Object[format.getFieldCount()]; + final Object[] tuple = new Object[format.getFields().size()]; tuple[format.getFieldIndex(DatastoreConstants.DICTIONARY_ID)] = dictionaryId; tuple[format.getFieldIndex(DatastoreConstants.DICTIONARY_CLASS)] = dictionaryClass; tuple[format.getFieldIndex(DatastoreConstants.DICTIONARY_SIZE)] = dictionarySize; @@ -153,12 +152,12 @@ static Object[] buildDictionaryTupleFrom( } static Object[] buildVersionTupleFrom( - final IRecordFormat format, + final IDataTable format, final IMemoryStatistic statistic, final String dumpName, final long epochId, final String branch) { - final Object[] tuple = new Object[format.getFieldCount()]; + final Object[] tuple = new Object[format.getFields().size()]; FeedVisitor.setTupleElement(tuple, format, DatastoreConstants.VERSION__DUMP_NAME, dumpName); FeedVisitor.setTupleElement(tuple, format, DatastoreConstants.VERSION__EPOCH_ID, epochId); FeedVisitor.setTupleElement(tuple, format, DatastoreConstants.VERSION__BRANCH_NAME, branch); @@ -209,9 +208,8 @@ static void includeApplicationInfoIfAny( } } - static IRecordFormat getRecordFormat( - final IDatastoreSchemaMetadata storageMetadata, final String storeName) { - return storageMetadata.getStoreMetadata(storeName).getStoreFormat().getRecordFormat(); + static IDataTable getRecordFormat(final IDatabaseSchema storageMetadata, final String storeName) { + return storageMetadata.getTable(storeName); } /** @@ -223,7 +221,7 @@ static IRecordFormat getRecordFormat( * @param value data to insert */ protected static void setTupleElement( - Object[] tuple, IRecordFormat format, String field, final Object value) { + Object[] tuple, IDataTable format, String field, final Object value) { if (value == null) { throw new RuntimeException("Expected a non-null value for field " + field); } diff --git a/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/LevelStatisticVisitor.java b/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/LevelStatisticVisitor.java index 1072ebd1..7f8e37e4 100644 --- a/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/LevelStatisticVisitor.java +++ b/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/LevelStatisticVisitor.java @@ -7,8 +7,8 @@ package com.activeviam.mac.statistic.memory.visitor.impl; +import com.activeviam.database.api.schema.IDatabaseSchema; import com.activeviam.database.datastore.api.transaction.IOpenedTransaction; -import com.activeviam.database.datastore.internal.IDatastoreSchemaMetadata; import com.activeviam.mac.Loggers; import com.activeviam.mac.memory.DatastoreConstants; import com.activeviam.mac.memory.MemoryAnalysisDatastoreDescriptionConfig; @@ -23,7 +23,6 @@ import com.activeviam.tech.observability.internal.memory.IndexStatistic; import com.activeviam.tech.observability.internal.memory.MemoryStatisticConstants; import com.activeviam.tech.observability.internal.memory.ReferenceStatistic; -import com.activeviam.tech.records.api.IRecordFormat; import java.util.logging.Logger; /** @@ -39,6 +38,7 @@ public class LevelStatisticVisitor extends AFeedVisitorWithDictionary { private final PivotFeederVisitor parent; private final IOpenedTransaction transaction; private final Long epochId; + /** The number of members of the visited level. */ protected Integer memberCount; @@ -57,7 +57,7 @@ public class LevelStatisticVisitor extends AFeedVisitorWithDictionary { public LevelStatisticVisitor( final PivotFeederVisitor parent, final IOpenedTransaction transaction, - final IDatastoreSchemaMetadata storageMetadata, + final IDatabaseSchema storageMetadata, final String dumpName, final Long epochId) { super(transaction, storageMetadata, dumpName); @@ -97,7 +97,7 @@ public Void visit(final ChunkStatistic stat) { recordLevelForStructure(this.directParentType, this.directParentId); - final IRecordFormat format = getChunkFormat(this.storageMetadata); + final var format = getChunkFormat(this.storageMetadata); final Object[] tuple = FeedVisitor.buildChunkTupleFrom(format, stat); FeedVisitor.setTupleElement(tuple, format, DatastoreConstants.CHUNK__DUMP_NAME, this.dumpName); FeedVisitor.setTupleElement(tuple, format, DatastoreConstants.VERSION__EPOCH_ID, this.epochId); @@ -182,9 +182,9 @@ public Void visit(AMemoryStatistic memoryStatistic) { } private void recordLevelForStructure(final ParentType type, final String id) { - final IRecordFormat format = + final var format = FeedVisitor.getRecordFormat(this.storageMetadata, DatastoreConstants.CHUNK_TO_LEVEL_STORE); - final Object[] tuple = new Object[format.getFieldCount()]; + final Object[] tuple = new Object[format.getFields().size()]; FeedVisitor.setTupleElement(tuple, format, DatastoreConstants.CHUNK__DUMP_NAME, this.dumpName); FeedVisitor.setTupleElement( tuple, format, DatastoreConstants.CHUNK_TO_LEVEL__MANAGER_ID, this.parent.manager); diff --git a/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/PivotFeederVisitor.java b/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/PivotFeederVisitor.java index 8d45733a..229b895b 100644 --- a/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/PivotFeederVisitor.java +++ b/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/PivotFeederVisitor.java @@ -13,8 +13,9 @@ import com.activeviam.activepivot.core.intf.api.cube.metadata.HierarchyIdentifier; import com.activeviam.activepivot.core.intf.api.cube.metadata.LevelIdentifier; import com.activeviam.activepivot.dist.impl.api.cube.IMultiVersionDistributedActivePivot; +import com.activeviam.database.api.schema.IDataTable; +import com.activeviam.database.api.schema.IDatabaseSchema; import com.activeviam.database.datastore.api.transaction.IOpenedTransaction; -import com.activeviam.database.datastore.internal.IDatastoreSchemaMetadata; import com.activeviam.mac.entities.CubeOwner; import com.activeviam.mac.entities.DistributedCubeOwner; import com.activeviam.mac.memory.DatastoreConstants; @@ -32,7 +33,6 @@ import com.activeviam.tech.observability.internal.memory.IndexStatistic; import com.activeviam.tech.observability.internal.memory.MemoryStatisticConstants; import com.activeviam.tech.observability.internal.memory.ReferenceStatistic; -import com.activeviam.tech.records.api.IRecordFormat; import java.time.Instant; import java.util.Objects; @@ -45,28 +45,40 @@ public class PivotFeederVisitor extends AFeedVisitorWithDictionary { /** The export date, found on the first statistics we read. */ protected Instant current = null; + /** The epoch id we are currently reading statistics for. */ protected Long epochId = null; + /** The branch of the pivot we're currently reading statistics. */ protected String branch = null; + /** Current {@link ActivePivotManager}. */ protected String manager; + /** Aggregate provider being currently visited. */ protected Long providerId; + /** Partition being currently visited. */ protected Integer partition; + /** Dimension being currently visited. */ protected String dimension; + /** Hierarchy being currently visited. */ protected String hierarchy; + /** Level being currently visited. */ protected String level; + /** Type of the aggregate Provider being currently visited. */ protected ProviderComponentType providerComponentType; + /** Type of the root structure. */ protected ParentType rootComponent; + /** Type of the direct parent structure. */ protected ParentType directParentType; + /** Id of the direct parent structure. */ protected String directParentId; @@ -81,9 +93,7 @@ public class PivotFeederVisitor extends AFeedVisitorWithDictionary { * @param dumpName name of the current import */ public PivotFeederVisitor( - final IDatastoreSchemaMetadata storageMetadata, - final IOpenedTransaction tm, - final String dumpName) { + final IDatabaseSchema storageMetadata, final IOpenedTransaction tm, final String dumpName) { super(tm, storageMetadata, dumpName); } @@ -100,8 +110,8 @@ private static boolean isPivotDistributed(final IMemoryStatistic pivotStat) { } private static Object[] buildProviderTupleFrom( - final IRecordFormat format, final IMemoryStatistic stat) { - final Object[] tuple = new Object[format.getFieldCount()]; + final IDataTable format, final IMemoryStatistic stat) { + final Object[] tuple = new Object[format.getFields().size()]; final IStatisticAttribute indexAttr = stat.getAttribute(MemoryStatisticConstants.ATTR_NAME_PROVIDER_NAME); @@ -120,8 +130,8 @@ private static Object[] buildProviderTupleFrom( } private static Object[] buildLevelTupleFrom( - final IRecordFormat format, final IMemoryStatistic stat) { - final Object[] tuple = new Object[format.getFieldCount()]; + final IDataTable format, final IMemoryStatistic stat) { + final Object[] tuple = new Object[format.getFields().size()]; tuple[format.getFieldIndex(DatastoreConstants.LEVEL__ON_HEAP_SIZE)] = stat.getShallowOnHeap(); tuple[format.getFieldIndex(DatastoreConstants.LEVEL__OFF_HEAP_SIZE)] = stat.getShallowOffHeap(); @@ -197,8 +207,8 @@ public Void visit(final DefaultMemoryStatistic stat) { case MemoryStatisticConstants.STAT_NAME_PIVOT: processPivot(stat); break; - // Unless said otherwise we assume all providers are partial,safer than the - // other way + // Unless said otherwise we assume all providers are partial,safer than the + // other way case MemoryStatisticConstants.STAT_NAME_PROVIDER: case MemoryStatisticConstants.STAT_NAME_PARTIAL_PROVIDER: case MemoryStatisticConstants.STAT_NAME_FULL_PROVIDER: @@ -257,7 +267,7 @@ public Void visit(final ChunkSetStatistic stat) { @Override public Void visit(final ChunkStatistic stat) { - final IRecordFormat format = getChunkFormat(this.storageMetadata); + final var format = getChunkFormat(this.storageMetadata); final Object[] tuple = FeedVisitor.buildChunkTupleFrom(format, stat); FeedVisitor.setTupleElement(tuple, format, DatastoreConstants.CHUNK__DUMP_NAME, this.dumpName); FeedVisitor.setTupleElement(tuple, format, DatastoreConstants.VERSION__EPOCH_ID, this.epochId); @@ -379,7 +389,7 @@ private void processPivot(final AMemoryStatistic stat) { readEpochAndBranchIfAny(stat); if (readEpochAndBranchIfAny(stat)) { - final IRecordFormat versionStoreFormat = getVersionStoreFormat(this.storageMetadata); + final var versionStoreFormat = getVersionStoreFormat(this.storageMetadata); final Object[] tuple = FeedVisitor.buildVersionTupleFrom( versionStoreFormat, stat, this.dumpName, this.epochId, this.branch); @@ -415,7 +425,7 @@ private void processPivot(final AMemoryStatistic stat) { } private void processProvider(final AMemoryStatistic stat) { - final IRecordFormat format = getProviderFormat(this.storageMetadata); + final var format = getProviderFormat(this.storageMetadata); final Object[] tuple = buildProviderTupleFrom(format, stat); FeedVisitor.setTupleElement( @@ -458,7 +468,7 @@ private void processHierarchy(final AMemoryStatistic stat) { } private void processLevel(final AMemoryStatistic stat) { - final IRecordFormat format = getLevelFormat(this.storageMetadata); + final var format = getLevelFormat(this.storageMetadata); final Object[] tuple = buildLevelTupleFrom(format, stat); String levelDescription = diff --git a/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/VectorStatisticVisitor.java b/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/VectorStatisticVisitor.java index 2e5db8a3..40115b41 100644 --- a/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/VectorStatisticVisitor.java +++ b/src/main/java/com/activeviam/mac/statistic/memory/visitor/impl/VectorStatisticVisitor.java @@ -7,8 +7,9 @@ package com.activeviam.mac.statistic.memory.visitor.impl; +import com.activeviam.database.api.schema.IDataTable; +import com.activeviam.database.api.schema.IDatabaseSchema; import com.activeviam.database.datastore.api.transaction.IOpenedTransaction; -import com.activeviam.database.datastore.internal.IDatastoreSchemaMetadata; import com.activeviam.mac.entities.ChunkOwner; import com.activeviam.mac.memory.DatastoreConstants; import com.activeviam.mac.memory.MemoryAnalysisDatastoreDescriptionConfig; @@ -23,7 +24,6 @@ import com.activeviam.tech.observability.internal.memory.IndexStatistic; import com.activeviam.tech.observability.internal.memory.MemoryStatisticConstants; import com.activeviam.tech.observability.internal.memory.ReferenceStatistic; -import com.activeviam.tech.records.api.IRecordFormat; import java.time.Instant; import java.util.Collection; @@ -36,7 +36,7 @@ public class VectorStatisticVisitor extends AFeedVisitor { /** The record format of the store that stores the chunks. */ - protected final IRecordFormat chunkRecordFormat; + protected final IDataTable chunkRecordFormat; /** The export date, found on the first statistics we read. */ protected final Instant current; @@ -45,8 +45,10 @@ public class VectorStatisticVisitor extends AFeedVisitor { protected final int partitionId; private final UsedByVersion usedByVersion; + /** The epoch id we are currently reading statistics for. */ protected Long epochId; + /** The fields corresponding to the vector block statistic. */ protected Collection fields; @@ -64,7 +66,7 @@ public class VectorStatisticVisitor extends AFeedVisitor { * @param usedByVersion the used by version flag for the current statistic */ public VectorStatisticVisitor( - final IDatastoreSchemaMetadata storageMetadata, + final IDatabaseSchema storageMetadata, final IOpenedTransaction transaction, final String dumpName, final Instant current, @@ -81,11 +83,7 @@ public VectorStatisticVisitor( this.epochId = epochId; this.usedByVersion = usedByVersion; - this.chunkRecordFormat = - this.storageMetadata - .getStoreMetadata(DatastoreConstants.CHUNK_STORE) - .getStoreFormat() - .getRecordFormat(); + this.chunkRecordFormat = this.storageMetadata.getTable(DatastoreConstants.CHUNK_STORE); } /** @@ -182,7 +180,7 @@ public Void visit(DictionaryStatistic dictionaryStatistic) { protected void visitVectorBlock(final ChunkStatistic statistic) { assert statistic.getChildren().isEmpty() : "Vector statistics with children"; - final IRecordFormat format = this.chunkRecordFormat; + final var format = this.chunkRecordFormat; final Object[] tuple = FeedVisitor.buildChunkTupleFrom(format, statistic); FeedVisitor.setTupleElement( diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 469f97e9..29e658c1 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -1,10 +1,5 @@ server: port: 9092 - remote: - uri: localhost:9090 - -activeui: - address: http://localhost:9092/ui management: endpoints: @@ -12,13 +7,6 @@ management: exposure: include: "*" -contentServer: - security: - calculatedMemberRole: ROLE_USER - kpiRole: ROLE_USER - cache: - entitlementsTTL: 3600 - bookmarks: folder: ui diff --git a/src/main/resources/static/activeui/env.js b/src/main/resources/static/activeui/env.js deleted file mode 100644 index 2ef832bf..00000000 --- a/src/main/resources/static/activeui/env.js +++ /dev/null @@ -1,14 +0,0 @@ -var baseUrl = window.location.href.split('/ui')[0]; - -window.env = { - contentServerUrl: baseUrl, - contentServerVersion: "6.0.6", - // WARNING: Changing the keys of activePivotServers will break previously saved widgets and dashboards. - // If you must do it, then you also need to update each one's serverKey attribute on your content server. - activePivotServers: { - "MAC": { - url: baseUrl, - version: "6.0.6", - }, - }, -}; diff --git a/src/main/resources/static/atoti-ui/env.js b/src/main/resources/static/atoti-ui/env.js new file mode 100644 index 00000000..6a783ffd --- /dev/null +++ b/src/main/resources/static/atoti-ui/env.js @@ -0,0 +1,19 @@ +const baseUrl = window.location.href.split('/ui')[0]; +const version = "6.1.3"; + +window.env = { + contentServer: { + url: baseUrl, + version, + }, + atotiServers: { + "MAC": { + url: baseUrl, + version, + }, + }, + jwtServer: { + url: baseUrl, + version, + } +}; diff --git a/src/main/resources/static/activeui/extensions.json b/src/main/resources/static/atoti-ui/extensions.json similarity index 54% rename from src/main/resources/static/activeui/extensions.json rename to src/main/resources/static/atoti-ui/extensions.json index ead25337..883ad1ba 100644 --- a/src/main/resources/static/activeui/extensions.json +++ b/src/main/resources/static/atoti-ui/extensions.json @@ -1,5 +1,5 @@ { - "@activeviam/starter": "extensions/@activeviam/starter/@activeviam/starter.js", + "@activeviam/starter":"extensions/@activeviam/starter/extensionEntry.js", "text-editor-extension": "extensions/text-editor-extension/text-editor-extension.js", - "@activeviam/advanced-extension": "extensions/@activeviam/advanced-extension/@activeviam/advanced-extension.js" + "@activeviam/advanced-extension": "extensions/@activeviam/advanced-extension/extensionEntry.js" } diff --git a/src/main/resources/static/activeui/extensions/text-editor-extension/static/js/492.84c9d447.js b/src/main/resources/static/atoti-ui/extensions/text-editor-extension/static/js/492.84c9d447.js similarity index 100% rename from src/main/resources/static/activeui/extensions/text-editor-extension/static/js/492.84c9d447.js rename to src/main/resources/static/atoti-ui/extensions/text-editor-extension/static/js/492.84c9d447.js diff --git a/src/main/resources/static/activeui/extensions/text-editor-extension/static/js/7.b5b094db.chunk.js b/src/main/resources/static/atoti-ui/extensions/text-editor-extension/static/js/7.b5b094db.chunk.js similarity index 100% rename from src/main/resources/static/activeui/extensions/text-editor-extension/static/js/7.b5b094db.chunk.js rename to src/main/resources/static/atoti-ui/extensions/text-editor-extension/static/js/7.b5b094db.chunk.js diff --git a/src/main/resources/static/activeui/extensions/text-editor-extension/static/js/main.6b2474f9.js b/src/main/resources/static/atoti-ui/extensions/text-editor-extension/static/js/main.6b2474f9.js similarity index 100% rename from src/main/resources/static/activeui/extensions/text-editor-extension/static/js/main.6b2474f9.js rename to src/main/resources/static/atoti-ui/extensions/text-editor-extension/static/js/main.6b2474f9.js diff --git a/src/main/resources/static/activeui/extensions/text-editor-extension/text-editor-extension.js b/src/main/resources/static/atoti-ui/extensions/text-editor-extension/text-editor-extension.js similarity index 100% rename from src/main/resources/static/activeui/extensions/text-editor-extension/text-editor-extension.js rename to src/main/resources/static/atoti-ui/extensions/text-editor-extension/text-editor-extension.js From e86ed5ad4f4cb7efce9d4f264551ad4e680e6a34 Mon Sep 17 00:00:00 2001 From: Olivier Peyrusse Date: Thu, 5 Dec 2024 15:31:56 +0100 Subject: [PATCH 08/10] Use an event to setup the registry --- .../activeviam/mac/app/MacSpringBootApp.java | 6 ---- .../mac/cfg/impl/ContentServiceConfig.java | 16 ++++++---- .../cfg/impl/ManagerDescriptionConfig.java | 8 ++--- .../impl/RegistryInitializationConfig.java | 31 +++++++++++++++++++ .../ReverseEpochViewComparator.java | 2 +- .../{ => mac}/formatter/ByteFormatter.java | 2 +- .../{ => mac}/formatter/ClassFormatter.java | 2 +- .../formatter/PartitionIdFormatter.java | 2 +- src/main/resources/META-INF/spring.factories | 1 + src/main/resources/application.yml | 3 +- .../resources/static/atoti-ui/extensions.json | 1 - .../TestAggregateProvidersBookmark.java | 3 +- .../memory/TestAnalysisDatastoreFeeder.java | 4 +-- .../mac/statistic/memory/TestBranches.java | 3 +- .../memory/TestDistributedCubeEpochs.java | 3 +- .../mac/statistic/memory/TestEpochs.java | 4 +-- .../statistic/memory/TestFieldsBookmark.java | 4 +-- ...tFieldsBookmarkWithDuplicateFieldName.java | 3 +- .../TestIndexAndDictionaryBookmarks.java | 4 +-- .../mac/statistic/memory/TestMACMeasures.java | 3 +- .../memory/TestOverviewBookmark.java | 3 +- .../statistic/memory/TestRatioMeasures.java | 3 +- .../memory/TestVectorBlockBookmark.java | 4 +-- .../mac/statistic/memory/TestViewEpochs.java | 4 +-- .../memory/scenarios/TestMissingChunkId.java | 3 +- .../TestMultipleFieldsDictionary.java | 3 +- .../TestNullableLevelDictionary.java | 3 +- .../TestReverseEpochViewComparator.java | 2 +- 28 files changed, 85 insertions(+), 45 deletions(-) create mode 100644 src/main/java/com/activeviam/mac/cfg/impl/RegistryInitializationConfig.java rename src/main/java/com/activeviam/{ => mac}/comparators/ReverseEpochViewComparator.java (98%) rename src/main/java/com/activeviam/{ => mac}/formatter/ByteFormatter.java (98%) rename src/main/java/com/activeviam/{ => mac}/formatter/ClassFormatter.java (97%) rename src/main/java/com/activeviam/{ => mac}/formatter/PartitionIdFormatter.java (96%) create mode 100644 src/main/resources/META-INF/spring.factories diff --git a/src/main/java/com/activeviam/mac/app/MacSpringBootApp.java b/src/main/java/com/activeviam/mac/app/MacSpringBootApp.java index dfd3d01e..95c2c7f3 100644 --- a/src/main/java/com/activeviam/mac/app/MacSpringBootApp.java +++ b/src/main/java/com/activeviam/mac/app/MacSpringBootApp.java @@ -8,7 +8,6 @@ package com.activeviam.mac.app; import com.activeviam.mac.cfg.impl.MacServerConfig; -import com.activeviam.tech.core.api.registry.Registry; import jakarta.servlet.MultipartConfigElement; import org.springframework.beans.factory.ObjectProvider; import org.springframework.boot.SpringApplication; @@ -35,11 +34,6 @@ @Import({MacServerConfig.class}) public class MacSpringBootApp { - /* Before anything else we statically initialize the Quartet FS Registry. */ - static { - Registry.initialize(Registry.RegistryContributions.builder().build()); - } - /** * Starts the Memory Analysis Cube application. * diff --git a/src/main/java/com/activeviam/mac/cfg/impl/ContentServiceConfig.java b/src/main/java/com/activeviam/mac/cfg/impl/ContentServiceConfig.java index c9c13d71..7025e4a1 100644 --- a/src/main/java/com/activeviam/mac/cfg/impl/ContentServiceConfig.java +++ b/src/main/java/com/activeviam/mac/cfg/impl/ContentServiceConfig.java @@ -129,12 +129,16 @@ public Properties contentServiceHibernateProperties() { @Override @Bean public IContentService contentService() { - final SessionFactory sessionFactory; - try { - sessionFactory = loadConfiguration(contentServiceHibernateProperties()); - return new HibernateContentService(sessionFactory); - } catch (HibernateException | IOException e) { - throw new BeanInitializationException("Failed to initialize the Content Service", e); + if ("db".equals(this.env.getProperty("content-service.type", "db"))) { + return IContentService.builder().inMemory().build(); + } else { + final SessionFactory sessionFactory; + try { + sessionFactory = loadConfiguration(contentServiceHibernateProperties()); + return new HibernateContentService(sessionFactory); + } catch (HibernateException | IOException e) { + throw new BeanInitializationException("Failed to initialize the Content Service", e); + } } } diff --git a/src/main/java/com/activeviam/mac/cfg/impl/ManagerDescriptionConfig.java b/src/main/java/com/activeviam/mac/cfg/impl/ManagerDescriptionConfig.java index d321ee5e..21c863d1 100644 --- a/src/main/java/com/activeviam/mac/cfg/impl/ManagerDescriptionConfig.java +++ b/src/main/java/com/activeviam/mac/cfg/impl/ManagerDescriptionConfig.java @@ -30,11 +30,11 @@ import com.activeviam.activepivot.core.intf.api.description.builder.dimension.ICanStartBuildingDimensions; import com.activeviam.activepivot.server.spring.api.config.IActivePivotManagerDescriptionConfig; import com.activeviam.activepivot.server.spring.api.config.IDatastoreSchemaDescriptionConfig; -import com.activeviam.comparators.ReverseEpochViewComparator; +import com.activeviam.mac.comparators.ReverseEpochViewComparator; import com.activeviam.database.api.schema.FieldPath; -import com.activeviam.formatter.ByteFormatter; -import com.activeviam.formatter.ClassFormatter; -import com.activeviam.formatter.PartitionIdFormatter; +import com.activeviam.mac.formatter.ByteFormatter; +import com.activeviam.mac.formatter.ClassFormatter; +import com.activeviam.mac.formatter.PartitionIdFormatter; import com.activeviam.mac.entities.ChunkOwner; import com.activeviam.mac.entities.ChunkOwner.OwnerType; import com.activeviam.mac.memory.DatastoreConstants; diff --git a/src/main/java/com/activeviam/mac/cfg/impl/RegistryInitializationConfig.java b/src/main/java/com/activeviam/mac/cfg/impl/RegistryInitializationConfig.java new file mode 100644 index 00000000..1257ef77 --- /dev/null +++ b/src/main/java/com/activeviam/mac/cfg/impl/RegistryInitializationConfig.java @@ -0,0 +1,31 @@ +/* + * (C) ActiveViam 2024 + * ALL RIGHTS RESERVED. This material is the CONFIDENTIAL and PROPRIETARY + * property of ActiveViam. Any unauthorized use, + * reproduction or transfer of this material is strictly prohibited + */ + +package com.activeviam.mac.cfg.impl; + +import com.activeviam.tech.core.api.registry.Registry; +import com.activeviam.tech.core.api.registry.Registry.RegistryContributions; +import java.util.List; +import org.springframework.boot.context.event.ApplicationStartingEvent; +import org.springframework.context.ApplicationListener; + +/** + * Component initializing the registry as soon as possible when an application is starting. + * + * @author ActiveViam + */ +public class RegistryInitializationConfig implements ApplicationListener { + + public void onApplicationEvent(final ApplicationStartingEvent ignored) { + setupRegistry(); + } + + public static void setupRegistry() { + Registry.initialize( + RegistryContributions.builder().packagesToScan(List.of("com.activeviam.mac")).build()); + } +} diff --git a/src/main/java/com/activeviam/comparators/ReverseEpochViewComparator.java b/src/main/java/com/activeviam/mac/comparators/ReverseEpochViewComparator.java similarity index 98% rename from src/main/java/com/activeviam/comparators/ReverseEpochViewComparator.java rename to src/main/java/com/activeviam/mac/comparators/ReverseEpochViewComparator.java index 2b7b50ef..45d45d81 100644 --- a/src/main/java/com/activeviam/comparators/ReverseEpochViewComparator.java +++ b/src/main/java/com/activeviam/mac/comparators/ReverseEpochViewComparator.java @@ -5,7 +5,7 @@ * reproduction or transfer of this material is strictly prohibited */ -package com.activeviam.comparators; +package com.activeviam.mac.comparators; import com.activeviam.mac.statistic.memory.visitor.impl.DistributedEpochView; import com.activeviam.mac.statistic.memory.visitor.impl.EpochView; diff --git a/src/main/java/com/activeviam/formatter/ByteFormatter.java b/src/main/java/com/activeviam/mac/formatter/ByteFormatter.java similarity index 98% rename from src/main/java/com/activeviam/formatter/ByteFormatter.java rename to src/main/java/com/activeviam/mac/formatter/ByteFormatter.java index 2c59043a..eb284192 100644 --- a/src/main/java/com/activeviam/formatter/ByteFormatter.java +++ b/src/main/java/com/activeviam/mac/formatter/ByteFormatter.java @@ -5,7 +5,7 @@ * reproduction or transfer of this material is strictly prohibited */ -package com.activeviam.formatter; +package com.activeviam.mac.formatter; import com.activeviam.tech.core.api.format.IFormatter; import com.activeviam.tech.core.api.registry.AtotiExtendedPluginValue; diff --git a/src/main/java/com/activeviam/formatter/ClassFormatter.java b/src/main/java/com/activeviam/mac/formatter/ClassFormatter.java similarity index 97% rename from src/main/java/com/activeviam/formatter/ClassFormatter.java rename to src/main/java/com/activeviam/mac/formatter/ClassFormatter.java index 5952a9d6..edcf926c 100644 --- a/src/main/java/com/activeviam/formatter/ClassFormatter.java +++ b/src/main/java/com/activeviam/mac/formatter/ClassFormatter.java @@ -5,7 +5,7 @@ * reproduction or transfer of this material is strictly prohibited */ -package com.activeviam.formatter; +package com.activeviam.mac.formatter; import com.activeviam.tech.core.api.format.IFormatter; import com.activeviam.tech.core.api.registry.AtotiExtendedPluginValue; diff --git a/src/main/java/com/activeviam/formatter/PartitionIdFormatter.java b/src/main/java/com/activeviam/mac/formatter/PartitionIdFormatter.java similarity index 96% rename from src/main/java/com/activeviam/formatter/PartitionIdFormatter.java rename to src/main/java/com/activeviam/mac/formatter/PartitionIdFormatter.java index 00223c3b..1f627d88 100644 --- a/src/main/java/com/activeviam/formatter/PartitionIdFormatter.java +++ b/src/main/java/com/activeviam/mac/formatter/PartitionIdFormatter.java @@ -5,7 +5,7 @@ * reproduction or transfer of this material is strictly prohibited */ -package com.activeviam.formatter; +package com.activeviam.mac.formatter; import com.activeviam.mac.memory.MemoryAnalysisDatastoreDescriptionConfig; import com.activeviam.tech.core.api.format.IFormatter; diff --git a/src/main/resources/META-INF/spring.factories b/src/main/resources/META-INF/spring.factories new file mode 100644 index 00000000..4dd14a61 --- /dev/null +++ b/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.context.ApplicationListener=com.activeviam.mac.cfg.impl.RegistryInitializationConfig diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 29e658c1..cf9c9d02 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -37,7 +37,7 @@ activeviam: lULiNZ73+TSdoT8yD6mH2hVArkajsnv1PNw0cR2V2aLY1Cg030jyTtmdOky/ZBhMiT/bH7H1M/BNjsC23rcOtdwFRlApUlOkGMecZN\ 8IzqaYV0zuL+cQt2Iwo=" # The time of validity of a token in seconds - expiration: 86400 + expiration: PT24H # The path of the folder containing statistic files in .json or .json.sz (Snappy-compressed) formats # This path is relative to the execution directory of the Application @@ -45,6 +45,7 @@ statistic: folder: input_statistics content-service: + mode: "in-memory" # "in-memory" or "db" db: hibernate: dialect: org.hibernate.dialect.H2Dialect diff --git a/src/main/resources/static/atoti-ui/extensions.json b/src/main/resources/static/atoti-ui/extensions.json index 883ad1ba..d8471156 100644 --- a/src/main/resources/static/atoti-ui/extensions.json +++ b/src/main/resources/static/atoti-ui/extensions.json @@ -1,5 +1,4 @@ { "@activeviam/starter":"extensions/@activeviam/starter/extensionEntry.js", - "text-editor-extension": "extensions/text-editor-extension/text-editor-extension.js", "@activeviam/advanced-extension": "extensions/@activeviam/advanced-extension/extensionEntry.js" } diff --git a/src/test/java/com/activeviam/mac/statistic/memory/TestAggregateProvidersBookmark.java b/src/test/java/com/activeviam/mac/statistic/memory/TestAggregateProvidersBookmark.java index ff1bdb4c..4e9f1d02 100644 --- a/src/test/java/com/activeviam/mac/statistic/memory/TestAggregateProvidersBookmark.java +++ b/src/test/java/com/activeviam/mac/statistic/memory/TestAggregateProvidersBookmark.java @@ -17,6 +17,7 @@ import com.activeviam.database.datastore.api.IDatastore; import com.activeviam.database.datastore.internal.IInternalDatastore; import com.activeviam.mac.cfg.impl.ManagerDescriptionConfig; +import com.activeviam.mac.cfg.impl.RegistryInitializationConfig; import com.activeviam.mac.memory.MemoryAnalysisDatastoreDescriptionConfig; import com.activeviam.tech.core.api.agent.AgentException; import com.activeviam.tech.core.api.query.QueryException; @@ -37,7 +38,7 @@ public class TestAggregateProvidersBookmark extends ATestMemoryStatistic { @BeforeAll public static void setupRegistry() { - Registry.initialize(Registry.RegistryContributions.builder().build()); + RegistryInitializationConfig.setupRegistry(); } @BeforeEach diff --git a/src/test/java/com/activeviam/mac/statistic/memory/TestAnalysisDatastoreFeeder.java b/src/test/java/com/activeviam/mac/statistic/memory/TestAnalysisDatastoreFeeder.java index 5ff20f8f..c5d0eaf3 100644 --- a/src/test/java/com/activeviam/mac/statistic/memory/TestAnalysisDatastoreFeeder.java +++ b/src/test/java/com/activeviam/mac/statistic/memory/TestAnalysisDatastoreFeeder.java @@ -22,13 +22,13 @@ import com.activeviam.database.datastore.internal.IInternalDatastore; import com.activeviam.database.datastore.internal.query.impl.DatastoreQueryHelper; import com.activeviam.mac.cfg.impl.ManagerDescriptionConfig; +import com.activeviam.mac.cfg.impl.RegistryInitializationConfig; import com.activeviam.mac.entities.ChunkOwner; import com.activeviam.mac.entities.CubeOwner; import com.activeviam.mac.memory.DatastoreConstants; import com.activeviam.mac.memory.MemoryAnalysisDatastoreDescriptionConfig; import com.activeviam.mac.statistic.memory.visitor.impl.EpochView; import com.activeviam.tech.core.api.agent.AgentException; -import com.activeviam.tech.core.api.registry.Registry; import com.activeviam.tech.mvcc.api.IEpochHistory; import com.activeviam.tech.observability.internal.memory.AMemoryStatistic; import com.activeviam.tech.records.api.ICursor; @@ -55,7 +55,7 @@ public class TestAnalysisDatastoreFeeder extends ATestMemoryStatistic { @BeforeAll public static void setupRegistry() { - Registry.initialize(Registry.RegistryContributions.builder().build()); + RegistryInitializationConfig.setupRegistry(); } @BeforeEach diff --git a/src/test/java/com/activeviam/mac/statistic/memory/TestBranches.java b/src/test/java/com/activeviam/mac/statistic/memory/TestBranches.java index 675c66ae..faf2891e 100644 --- a/src/test/java/com/activeviam/mac/statistic/memory/TestBranches.java +++ b/src/test/java/com/activeviam/mac/statistic/memory/TestBranches.java @@ -20,6 +20,7 @@ import com.activeviam.database.datastore.api.transaction.ITransactionManager; import com.activeviam.database.datastore.internal.IInternalDatastore; import com.activeviam.mac.cfg.impl.ManagerDescriptionConfig; +import com.activeviam.mac.cfg.impl.RegistryInitializationConfig; import com.activeviam.mac.memory.DatastoreConstants; import com.activeviam.mac.memory.MemoryAnalysisDatastoreDescriptionConfig; import com.activeviam.mac.memory.MemoryAnalysisDatastoreDescriptionConfig.ParentType; @@ -51,7 +52,7 @@ public class TestBranches extends ATestMemoryStatistic { @BeforeAll public static void setupRegistry() { - Registry.initialize(Registry.RegistryContributions.builder().build()); + RegistryInitializationConfig.setupRegistry(); } @BeforeEach diff --git a/src/test/java/com/activeviam/mac/statistic/memory/TestDistributedCubeEpochs.java b/src/test/java/com/activeviam/mac/statistic/memory/TestDistributedCubeEpochs.java index 27d772be..75917841 100644 --- a/src/test/java/com/activeviam/mac/statistic/memory/TestDistributedCubeEpochs.java +++ b/src/test/java/com/activeviam/mac/statistic/memory/TestDistributedCubeEpochs.java @@ -20,6 +20,7 @@ import com.activeviam.database.datastore.api.IDatastore; import com.activeviam.database.datastore.internal.IInternalDatastore; import com.activeviam.mac.cfg.impl.ManagerDescriptionConfig; +import com.activeviam.mac.cfg.impl.RegistryInitializationConfig; import com.activeviam.mac.memory.DatastoreConstants; import com.activeviam.mac.memory.MemoryAnalysisDatastoreDescriptionConfig; import com.activeviam.mac.statistic.memory.visitor.impl.DistributedEpochView; @@ -49,7 +50,7 @@ public class TestDistributedCubeEpochs extends ATestMemoryStatistic { @BeforeAll public static void setupRegistry() { - Registry.initialize(Registry.RegistryContributions.builder().build()); + RegistryInitializationConfig.setupRegistry(); } @BeforeEach diff --git a/src/test/java/com/activeviam/mac/statistic/memory/TestEpochs.java b/src/test/java/com/activeviam/mac/statistic/memory/TestEpochs.java index c4614788..898887da 100644 --- a/src/test/java/com/activeviam/mac/statistic/memory/TestEpochs.java +++ b/src/test/java/com/activeviam/mac/statistic/memory/TestEpochs.java @@ -19,12 +19,12 @@ import com.activeviam.database.datastore.api.IDatastore; import com.activeviam.database.datastore.internal.IInternalDatastore; import com.activeviam.mac.cfg.impl.ManagerDescriptionConfig; +import com.activeviam.mac.cfg.impl.RegistryInitializationConfig; import com.activeviam.mac.memory.DatastoreConstants; import com.activeviam.mac.memory.MemoryAnalysisDatastoreDescriptionConfig; import com.activeviam.mac.memory.MemoryAnalysisDatastoreDescriptionConfig.ParentType; import com.activeviam.mac.memory.MemoryAnalysisDatastoreDescriptionConfig.UsedByVersion; import com.activeviam.tech.core.api.agent.AgentException; -import com.activeviam.tech.core.api.registry.Registry; import com.activeviam.tech.observability.internal.memory.AMemoryStatistic; import com.activeviam.tech.records.api.ICursor; import com.activeviam.tech.records.api.IRecordReader; @@ -50,7 +50,7 @@ public class TestEpochs extends ATestMemoryStatistic { @BeforeAll public static void setupRegistry() { - Registry.initialize(Registry.RegistryContributions.builder().build()); + RegistryInitializationConfig.setupRegistry(); } @BeforeEach diff --git a/src/test/java/com/activeviam/mac/statistic/memory/TestFieldsBookmark.java b/src/test/java/com/activeviam/mac/statistic/memory/TestFieldsBookmark.java index 4e9120fb..62fcb958 100644 --- a/src/test/java/com/activeviam/mac/statistic/memory/TestFieldsBookmark.java +++ b/src/test/java/com/activeviam/mac/statistic/memory/TestFieldsBookmark.java @@ -11,10 +11,10 @@ import com.activeviam.database.datastore.internal.IInternalDatastore; import com.activeviam.database.datastore.internal.monitoring.MemoryStatisticsTestUtils; import com.activeviam.mac.cfg.impl.ManagerDescriptionConfig; +import com.activeviam.mac.cfg.impl.RegistryInitializationConfig; import com.activeviam.mac.memory.MemoryAnalysisDatastoreDescriptionConfig; import com.activeviam.tech.core.api.agent.AgentException; import com.activeviam.tech.core.api.query.QueryException; -import com.activeviam.tech.core.api.registry.Registry; import com.activeviam.tech.observability.internal.memory.AMemoryStatistic; import java.nio.file.Path; import java.util.List; @@ -33,7 +33,7 @@ public class TestFieldsBookmark extends ATestMemoryStatistic { @BeforeAll public static void setupRegistry() { - Registry.initialize(Registry.RegistryContributions.builder().build()); + RegistryInitializationConfig.setupRegistry(); } @BeforeEach diff --git a/src/test/java/com/activeviam/mac/statistic/memory/TestFieldsBookmarkWithDuplicateFieldName.java b/src/test/java/com/activeviam/mac/statistic/memory/TestFieldsBookmarkWithDuplicateFieldName.java index 91fec44f..2d9c0692 100644 --- a/src/test/java/com/activeviam/mac/statistic/memory/TestFieldsBookmarkWithDuplicateFieldName.java +++ b/src/test/java/com/activeviam/mac/statistic/memory/TestFieldsBookmarkWithDuplicateFieldName.java @@ -18,6 +18,7 @@ import com.activeviam.database.datastore.internal.IInternalDatastore; import com.activeviam.database.datastore.internal.monitoring.MemoryStatisticsTestUtils; import com.activeviam.mac.cfg.impl.ManagerDescriptionConfig; +import com.activeviam.mac.cfg.impl.RegistryInitializationConfig; import com.activeviam.mac.memory.MemoryAnalysisDatastoreDescriptionConfig; import com.activeviam.tech.core.api.query.QueryException; import com.activeviam.tech.core.api.registry.Registry; @@ -39,7 +40,7 @@ public class TestFieldsBookmarkWithDuplicateFieldName extends ATestMemoryStatist @BeforeAll public static void setupRegistry() { - Registry.initialize(Registry.RegistryContributions.builder().build()); + RegistryInitializationConfig.setupRegistry(); } @BeforeEach diff --git a/src/test/java/com/activeviam/mac/statistic/memory/TestIndexAndDictionaryBookmarks.java b/src/test/java/com/activeviam/mac/statistic/memory/TestIndexAndDictionaryBookmarks.java index b95112ee..f1020435 100644 --- a/src/test/java/com/activeviam/mac/statistic/memory/TestIndexAndDictionaryBookmarks.java +++ b/src/test/java/com/activeviam/mac/statistic/memory/TestIndexAndDictionaryBookmarks.java @@ -19,10 +19,10 @@ import com.activeviam.activepivot.server.spring.api.config.IDatastoreSchemaDescriptionConfig; import com.activeviam.database.datastore.internal.IInternalDatastore; import com.activeviam.mac.cfg.impl.ManagerDescriptionConfig; +import com.activeviam.mac.cfg.impl.RegistryInitializationConfig; import com.activeviam.mac.memory.MemoryAnalysisDatastoreDescriptionConfig; import com.activeviam.tech.core.api.agent.AgentException; import com.activeviam.tech.core.api.query.QueryException; -import com.activeviam.tech.core.api.registry.Registry; import com.activeviam.tech.dictionaries.api.IDictionaryProvider; import com.activeviam.tech.observability.internal.memory.AMemoryStatistic; import java.nio.file.Path; @@ -42,7 +42,7 @@ public class TestIndexAndDictionaryBookmarks extends ATestMemoryStatistic { @BeforeAll public static void setupRegistry() { - Registry.initialize(Registry.RegistryContributions.builder().build()); + RegistryInitializationConfig.setupRegistry(); } @BeforeEach diff --git a/src/test/java/com/activeviam/mac/statistic/memory/TestMACMeasures.java b/src/test/java/com/activeviam/mac/statistic/memory/TestMACMeasures.java index 27f543ed..550a34a4 100644 --- a/src/test/java/com/activeviam/mac/statistic/memory/TestMACMeasures.java +++ b/src/test/java/com/activeviam/mac/statistic/memory/TestMACMeasures.java @@ -16,6 +16,7 @@ import com.activeviam.database.datastore.internal.NoTransactionException; import com.activeviam.database.datastore.internal.monitoring.MemoryStatisticsTestUtils; import com.activeviam.mac.cfg.impl.ManagerDescriptionConfig; +import com.activeviam.mac.cfg.impl.RegistryInitializationConfig; import com.activeviam.mac.memory.MemoryAnalysisDatastoreDescriptionConfig; import com.activeviam.tech.core.api.agent.AgentException; import com.activeviam.tech.core.api.exceptions.ActiveViamRuntimeException; @@ -68,7 +69,7 @@ public class TestMACMeasures extends ATestMemoryStatistic { @BeforeAll public static void init() { - Registry.initialize(Registry.RegistryContributions.builder().build()); + RegistryInitializationConfig.setupRegistry(); } private static Map extractApplicationStats(final IMemoryStatistic export) { diff --git a/src/test/java/com/activeviam/mac/statistic/memory/TestOverviewBookmark.java b/src/test/java/com/activeviam/mac/statistic/memory/TestOverviewBookmark.java index dbbac772..2eb4887e 100644 --- a/src/test/java/com/activeviam/mac/statistic/memory/TestOverviewBookmark.java +++ b/src/test/java/com/activeviam/mac/statistic/memory/TestOverviewBookmark.java @@ -10,6 +10,7 @@ import com.activeviam.database.datastore.internal.IInternalDatastore; import com.activeviam.database.datastore.internal.monitoring.MemoryStatisticsTestUtils; import com.activeviam.mac.cfg.impl.ManagerDescriptionConfig; +import com.activeviam.mac.cfg.impl.RegistryInitializationConfig; import com.activeviam.mac.memory.MemoryAnalysisDatastoreDescriptionConfig; import com.activeviam.tech.core.api.agent.AgentException; import com.activeviam.tech.core.api.query.QueryException; @@ -33,7 +34,7 @@ public class TestOverviewBookmark extends ATestMemoryStatistic { @BeforeAll public static void setupRegistry() { - Registry.initialize(Registry.RegistryContributions.builder().build()); + RegistryInitializationConfig.setupRegistry(); } @BeforeEach diff --git a/src/test/java/com/activeviam/mac/statistic/memory/TestRatioMeasures.java b/src/test/java/com/activeviam/mac/statistic/memory/TestRatioMeasures.java index 7e1064e3..f62d3ec5 100644 --- a/src/test/java/com/activeviam/mac/statistic/memory/TestRatioMeasures.java +++ b/src/test/java/com/activeviam/mac/statistic/memory/TestRatioMeasures.java @@ -10,6 +10,7 @@ import com.activeviam.database.datastore.api.IDatastore; import com.activeviam.database.datastore.internal.IInternalDatastore; import com.activeviam.mac.cfg.impl.ManagerDescriptionConfig; +import com.activeviam.mac.cfg.impl.RegistryInitializationConfig; import com.activeviam.mac.memory.MemoryAnalysisDatastoreDescriptionConfig; import com.activeviam.tech.core.api.query.QueryException; import com.activeviam.tech.core.api.registry.Registry; @@ -30,7 +31,7 @@ public class TestRatioMeasures extends ATestMemoryStatistic { @BeforeAll public static void setupRegistry() { - Registry.initialize(Registry.RegistryContributions.builder().build()); + RegistryInitializationConfig.setupRegistry(); } @BeforeEach diff --git a/src/test/java/com/activeviam/mac/statistic/memory/TestVectorBlockBookmark.java b/src/test/java/com/activeviam/mac/statistic/memory/TestVectorBlockBookmark.java index 914447d3..b011c94e 100644 --- a/src/test/java/com/activeviam/mac/statistic/memory/TestVectorBlockBookmark.java +++ b/src/test/java/com/activeviam/mac/statistic/memory/TestVectorBlockBookmark.java @@ -20,10 +20,10 @@ import com.activeviam.database.datastore.internal.IInternalDatastore; import com.activeviam.database.datastore.internal.monitoring.MemoryStatisticsTestUtils; import com.activeviam.mac.cfg.impl.ManagerDescriptionConfig; +import com.activeviam.mac.cfg.impl.RegistryInitializationConfig; import com.activeviam.mac.memory.MemoryAnalysisDatastoreDescriptionConfig; import com.activeviam.tech.core.api.agent.AgentException; import com.activeviam.tech.core.api.query.QueryException; -import com.activeviam.tech.core.api.registry.Registry; import com.activeviam.tech.observability.internal.memory.AMemoryStatistic; import java.nio.file.Path; import java.util.List; @@ -43,7 +43,7 @@ public class TestVectorBlockBookmark extends ATestMemoryStatistic { @BeforeAll public static void setupRegistry() { - Registry.initialize(Registry.RegistryContributions.builder().build()); + RegistryInitializationConfig.setupRegistry(); } @BeforeEach diff --git a/src/test/java/com/activeviam/mac/statistic/memory/TestViewEpochs.java b/src/test/java/com/activeviam/mac/statistic/memory/TestViewEpochs.java index 2d4f57ae..8ef9feca 100644 --- a/src/test/java/com/activeviam/mac/statistic/memory/TestViewEpochs.java +++ b/src/test/java/com/activeviam/mac/statistic/memory/TestViewEpochs.java @@ -18,6 +18,7 @@ import com.activeviam.database.datastore.api.transaction.ITransactionManager; import com.activeviam.database.datastore.internal.IInternalDatastore; import com.activeviam.mac.cfg.impl.ManagerDescriptionConfig; +import com.activeviam.mac.cfg.impl.RegistryInitializationConfig; import com.activeviam.mac.entities.ChunkOwner; import com.activeviam.mac.entities.CubeOwner; import com.activeviam.mac.entities.StoreOwner; @@ -25,7 +26,6 @@ import com.activeviam.mac.memory.MemoryAnalysisDatastoreDescriptionConfig; import com.activeviam.mac.statistic.memory.visitor.impl.EpochView; import com.activeviam.tech.core.api.agent.AgentException; -import com.activeviam.tech.core.api.registry.Registry; import com.activeviam.tech.observability.internal.memory.AMemoryStatistic; import com.activeviam.tech.records.api.ICursor; import com.activeviam.tech.records.api.IRecordReader; @@ -53,7 +53,7 @@ public class TestViewEpochs extends ATestMemoryStatistic { @BeforeAll public static void setupRegistry() { - Registry.initialize(Registry.RegistryContributions.builder().build()); + RegistryInitializationConfig.setupRegistry(); } @BeforeEach diff --git a/src/test/java/com/activeviam/mac/statistic/memory/scenarios/TestMissingChunkId.java b/src/test/java/com/activeviam/mac/statistic/memory/scenarios/TestMissingChunkId.java index 8626f166..bff4dde3 100644 --- a/src/test/java/com/activeviam/mac/statistic/memory/scenarios/TestMissingChunkId.java +++ b/src/test/java/com/activeviam/mac/statistic/memory/scenarios/TestMissingChunkId.java @@ -15,6 +15,7 @@ import com.activeviam.database.datastore.api.description.IDatastoreSchemaDescription; import com.activeviam.database.datastore.internal.IInternalDatastore; import com.activeviam.mac.cfg.impl.ManagerDescriptionConfig; +import com.activeviam.mac.cfg.impl.RegistryInitializationConfig; import com.activeviam.mac.memory.MemoryAnalysisDatastoreDescriptionConfig; import com.activeviam.mac.statistic.memory.ATestMemoryStatistic; import com.activeviam.mac.statistic.memory.deserializer.RetroCompatibleDeserializer; @@ -46,7 +47,7 @@ public class TestMissingChunkId { @BeforeAll public static void setupRegistry() { - Registry.initialize(Registry.RegistryContributions.builder().build()); + RegistryInitializationConfig.setupRegistry(); } @BeforeEach diff --git a/src/test/java/com/activeviam/mac/statistic/memory/scenarios/TestMultipleFieldsDictionary.java b/src/test/java/com/activeviam/mac/statistic/memory/scenarios/TestMultipleFieldsDictionary.java index e7a98049..181aa800 100644 --- a/src/test/java/com/activeviam/mac/statistic/memory/scenarios/TestMultipleFieldsDictionary.java +++ b/src/test/java/com/activeviam/mac/statistic/memory/scenarios/TestMultipleFieldsDictionary.java @@ -24,6 +24,7 @@ import com.activeviam.database.datastore.internal.IInternalDatastore; import com.activeviam.database.datastore.internal.dictionary.ISchemaDictionaryProvider; import com.activeviam.mac.cfg.impl.ManagerDescriptionConfig; +import com.activeviam.mac.cfg.impl.RegistryInitializationConfig; import com.activeviam.mac.entities.ChunkOwner; import com.activeviam.mac.memory.DatastoreConstants; import com.activeviam.mac.memory.MemoryAnalysisDatastoreDescriptionConfig; @@ -67,7 +68,7 @@ public class TestMultipleFieldsDictionary extends ATestMemoryStatistic { @BeforeAll public static void setupRegistry() { - Registry.initialize(Registry.RegistryContributions.builder().build()); + RegistryInitializationConfig.setupRegistry(); } @BeforeEach diff --git a/src/test/java/com/activeviam/mac/statistic/memory/scenarios/TestNullableLevelDictionary.java b/src/test/java/com/activeviam/mac/statistic/memory/scenarios/TestNullableLevelDictionary.java index 3a6046ec..eaa01870 100644 --- a/src/test/java/com/activeviam/mac/statistic/memory/scenarios/TestNullableLevelDictionary.java +++ b/src/test/java/com/activeviam/mac/statistic/memory/scenarios/TestNullableLevelDictionary.java @@ -23,6 +23,7 @@ import com.activeviam.database.datastore.api.description.IDatastoreSchemaDescription; import com.activeviam.database.datastore.internal.IInternalDatastore; import com.activeviam.mac.cfg.impl.ManagerDescriptionConfig; +import com.activeviam.mac.cfg.impl.RegistryInitializationConfig; import com.activeviam.mac.memory.MemoryAnalysisDatastoreDescriptionConfig; import com.activeviam.mac.statistic.memory.ATestMemoryStatistic; import com.activeviam.tech.core.api.exceptions.ActiveViamRuntimeException; @@ -59,7 +60,7 @@ public class TestNullableLevelDictionary { @BeforeAll public static void setupRegistry() { - Registry.initialize(Registry.RegistryContributions.builder().build()); + RegistryInitializationConfig.setupRegistry(); } @BeforeEach diff --git a/src/test/java/com/activeviam/mac/statistic/memory/visitor/TestReverseEpochViewComparator.java b/src/test/java/com/activeviam/mac/statistic/memory/visitor/TestReverseEpochViewComparator.java index 9898f82d..a4706aa8 100644 --- a/src/test/java/com/activeviam/mac/statistic/memory/visitor/TestReverseEpochViewComparator.java +++ b/src/test/java/com/activeviam/mac/statistic/memory/visitor/TestReverseEpochViewComparator.java @@ -9,7 +9,7 @@ import static org.assertj.core.api.Assertions.assertThat; -import com.activeviam.comparators.ReverseEpochViewComparator; +import com.activeviam.mac.comparators.ReverseEpochViewComparator; import com.activeviam.mac.statistic.memory.visitor.impl.DistributedEpochView; import com.activeviam.mac.statistic.memory.visitor.impl.EpochView; import com.activeviam.mac.statistic.memory.visitor.impl.RegularEpochView; From 5365931c01b74a96825c54034acdced7573d4fb7 Mon Sep 17 00:00:00 2001 From: Olivier Peyrusse Date: Thu, 5 Dec 2024 17:10:16 +0100 Subject: [PATCH 09/10] Refactor security a bit --- .../mac/cfg/impl/MacServerConfig.java | 72 ++++++++----------- .../InMemoryUserDetailsManagerBuilder.java | 54 -------------- .../mac/cfg/security/impl/SecurityConfig.java | 22 ++++++ .../mac/cfg/security/impl/UserConfig.java | 53 -------------- .../cfg/security/impl/WebConfiguration.java | 12 ---- 5 files changed, 50 insertions(+), 163 deletions(-) delete mode 100644 src/main/java/com/activeviam/mac/cfg/security/impl/InMemoryUserDetailsManagerBuilder.java delete mode 100644 src/main/java/com/activeviam/mac/cfg/security/impl/UserConfig.java delete mode 100644 src/main/java/com/activeviam/mac/cfg/security/impl/WebConfiguration.java diff --git a/src/main/java/com/activeviam/mac/cfg/impl/MacServerConfig.java b/src/main/java/com/activeviam/mac/cfg/impl/MacServerConfig.java index 4fbe7cd1..b7f81e14 100644 --- a/src/main/java/com/activeviam/mac/cfg/impl/MacServerConfig.java +++ b/src/main/java/com/activeviam/mac/cfg/impl/MacServerConfig.java @@ -11,7 +11,6 @@ import com.activeviam.activepivot.server.spring.api.config.IActivePivotContentServiceConfig; import com.activeviam.activepivot.server.spring.api.config.IDatastoreConfig; import com.activeviam.mac.cfg.security.impl.SecurityConfig; -import com.activeviam.mac.cfg.security.impl.UserConfig; import com.activeviam.tech.core.api.agent.AgentException; import com.activeviam.web.spring.internal.JMXEnabler; import com.activeviam.web.spring.internal.config.JwtConfig; @@ -28,71 +27,56 @@ * Spring configuration of the ActivePivot Sandbox application. * *

We use {@link PropertySource} annotation(s) to define some .properties file(s), whose content - * will be loaded into the Spring {@link Environment}, allowing some externally-driven configuration of the - * application. Parameters can be quickly changed by modifying the {@code sandbox.properties} file. + * will be loaded into the Spring {@link Environment}, allowing some externally-driven configuration + * of the application. Parameters can be quickly changed by modifying the {@code sandbox.properties} + * file. * *

We use {@link Import} annotation(s) to reference additional Spring {@link Configuration} - * classes, so that we can manage the application configuration in a modular way (split by domain/feature, re-use - * of core config, override of core config, customized config, etc...). + * classes, so that we can manage the application configuration in a modular way (split by + * domain/feature, re-use of core config, override of core config, customized config, etc...). * *

Spring best practices recommends not to have arguments in bean methods if possible. One should - * rather autowire the appropriate spring configurations (and not beans directly unless necessary), and use the - * beans from there. + * rather autowire the appropriate spring configurations (and not beans directly unless necessary), + * and use the beans from there. * * @author ActiveViam */ @Configuration @Import( value = { - JwtConfig.class, - ManagerDescriptionConfig.class, + JwtConfig.class, + ManagerDescriptionConfig.class, - // Pivot - ActivePivotWithDatastoreConfig.class, + // Pivot + ActivePivotWithDatastoreConfig.class, - // Content server - ContentServiceConfig.class, + // Content server + ContentServiceConfig.class, - // Specific to monitoring server - SecurityConfig.class, - UserConfig.class, - SourceConfig.class, + // Specific to monitoring server + SecurityConfig.class, + SourceConfig.class, }) public class MacServerConfig { - /** - * Datastore spring configuration. - */ - @Autowired - protected IDatastoreConfig datastoreConfig; + /** Datastore spring configuration. */ + @Autowired protected IDatastoreConfig datastoreConfig; - /** - * ActivePivot spring configuration. - */ - @Autowired - protected IActivePivotConfig apConfig; + /** ActivePivot spring configuration. */ + @Autowired protected IActivePivotConfig apConfig; - /** - * ActivePivot content service spring configuration. - */ - @Autowired - protected IActivePivotContentServiceConfig apContentServiceConfig; + /** ActivePivot content service spring configuration. */ + @Autowired protected IActivePivotContentServiceConfig apContentServiceConfig; - /** - * Content Service configuration. - */ - @Autowired - protected ContentServiceConfig contentServiceConfig; + /** Content Service configuration. */ + @Autowired protected ContentServiceConfig contentServiceConfig; - /** - * Spring configuration of the source files of the Memory Analysis Cube application. - */ - @Autowired - protected SourceConfig sourceConfig; + /** Spring configuration of the source files of the Memory Analysis Cube application. */ + @Autowired protected SourceConfig sourceConfig; /** - * Initialize and start the ActivePivot Manager, after performing all the injections into the ActivePivot - * plug-ins. + * Initialize and start the ActivePivot Manager, after performing all the injections into the + * ActivePivot plug-ins. * * @return void */ diff --git a/src/main/java/com/activeviam/mac/cfg/security/impl/InMemoryUserDetailsManagerBuilder.java b/src/main/java/com/activeviam/mac/cfg/security/impl/InMemoryUserDetailsManagerBuilder.java deleted file mode 100644 index d8e006dd..00000000 --- a/src/main/java/com/activeviam/mac/cfg/security/impl/InMemoryUserDetailsManagerBuilder.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * (C) ActiveViam 2015 - * ALL RIGHTS RESERVED. This material is the CONFIDENTIAL and PROPRIETARY - * property of ActiveViam. Any unauthorized use, - * reproduction or transfer of this material is strictly prohibited - */ - -package com.activeviam.mac.cfg.security.impl; - -import java.util.ArrayList; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.authentication.configurers.provisioning.InMemoryUserDetailsManagerConfigurer; -import org.springframework.security.config.annotation.authentication.configurers.provisioning.UserDetailsManagerConfigurer; -import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.provisioning.InMemoryUserDetailsManager; -import org.springframework.security.provisioning.UserDetailsManager; - -/** - * An In-memory {@link UserDetailsService} builder which can be used without {@link - * AuthenticationManagerBuilder} contrary to {@link InMemoryUserDetailsManagerConfigurer}. - * - * @author ActiveViam - */ -public class InMemoryUserDetailsManagerBuilder - extends UserDetailsManagerConfigurer< - AuthenticationManagerBuilder, InMemoryUserDetailsManagerBuilder> { - - /** Creates a new instance. */ - public InMemoryUserDetailsManagerBuilder() { - super(new InMemoryUserDetailsManager(new ArrayList<>())); - } - - @Override - public void configure(AuthenticationManagerBuilder builder) throws Exception { - if (null != builder) { - throw new IllegalArgumentException(); - } - initUserDetailsService(); - } - - /** - * Builds the In-memory {@link UserDetailsManager} and returns it. - * - * @return the built object - */ - public UserDetailsManager build() { - try { - configure(null); - return getUserDetailsService(); - } catch (Exception e) { - throw new RuntimeException(e); - } - } -} diff --git a/src/main/java/com/activeviam/mac/cfg/security/impl/SecurityConfig.java b/src/main/java/com/activeviam/mac/cfg/security/impl/SecurityConfig.java index 1518f233..541b6749 100644 --- a/src/main/java/com/activeviam/mac/cfg/security/impl/SecurityConfig.java +++ b/src/main/java/com/activeviam/mac/cfg/security/impl/SecurityConfig.java @@ -1,5 +1,6 @@ package com.activeviam.mac.cfg.security.impl; +import com.activeviam.tech.contentserver.storage.api.IContentService; import com.activeviam.web.spring.api.config.IJwtConfig; import com.activeviam.web.spring.api.jwt.JwtAuthenticationProvider; import lombok.RequiredArgsConstructor; @@ -12,11 +13,14 @@ import org.springframework.security.authentication.ProviderManager; import org.springframework.security.authentication.dao.DaoAuthenticationProvider; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.core.userdetails.User; +import org.springframework.security.core.userdetails.User.UserBuilder; import org.springframework.security.core.userdetails.UserDetailsService; import org.springframework.security.crypto.factory.PasswordEncoderFactories; import org.springframework.security.crypto.password.DelegatingPasswordEncoder; import org.springframework.security.crypto.password.NoOpPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.provisioning.InMemoryUserDetailsManager; import org.springframework.security.web.AuthenticationEntryPoint; import org.springframework.security.web.authentication.HttpStatusEntryPoint; import org.springframework.security.web.firewall.StrictHttpFirewall; @@ -35,6 +39,24 @@ public class SecurityConfig { /** Name of the Cookies of the MAC application. */ public static final String COOKIE_NAME = "MEMORY_ANALYSIS_CUBE"; + /** + * [Bean] Create the users that can access the application. + * + * @return {@link UserDetailsService user data} + */ + @Bean + public UserDetailsService userDetailsService(final PasswordEncoder passwordEncoder) { + final UserBuilder builder = User.builder().passwordEncoder(passwordEncoder::encode); + final InMemoryUserDetailsManager service = new InMemoryUserDetailsManager(); + service.createUser( + builder + .username("admin") + .password("admin") + .authorities(ROLE_USER, ROLE_ADMIN, IContentService.ROLE_ROOT) + .build()); + return service; + } + /** * As of Spring Security 5.0, the way the passwords are encoded must be specified. When logging, * the input password will be encoded and compared with the stored encoded password. To determine diff --git a/src/main/java/com/activeviam/mac/cfg/security/impl/UserConfig.java b/src/main/java/com/activeviam/mac/cfg/security/impl/UserConfig.java deleted file mode 100644 index a6b12fea..00000000 --- a/src/main/java/com/activeviam/mac/cfg/security/impl/UserConfig.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * (C) ActiveViam 2017 - * ALL RIGHTS RESERVED. This material is the CONFIDENTIAL and PROPRIETARY - * property of ActiveViam. Any unauthorized use, - * reproduction or transfer of this material is strictly prohibited - */ - -package com.activeviam.mac.cfg.security.impl; - -import com.activeviam.tech.contentserver.storage.api.IContentService; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.security.core.userdetails.UserDetailsService; - -/** - * Spring configuration that defines the users and their associated roles in the Sandbox - * application. - * - * @author ActiveViam - */ -@Configuration -public class UserConfig { - - /** - * ROLE_KPI is added to users, to give them permission to read kpis created by other users in the - * content server In order to "share" kpis created in the content server, the kpi reader role is - * set to : ROLE_KPI. - */ - public static final String ROLE_KPI = "ROLE_KPI"; - - /** - * [Bean] Create the users that can access the application. - * - * @return {@link UserDetailsService user data} - */ - @Bean - public UserDetailsService userDetailsService() { - return new InMemoryUserDetailsManagerBuilder() - - // "Real users" - .withUser("admin") - .password("admin") - .authorities( - SecurityConfig.ROLE_USER, - SecurityConfig.ROLE_ADMIN, - ROLE_KPI, - IContentService.ROLE_ROOT) - .and() - - // We're done - .build(); - } -} diff --git a/src/main/java/com/activeviam/mac/cfg/security/impl/WebConfiguration.java b/src/main/java/com/activeviam/mac/cfg/security/impl/WebConfiguration.java deleted file mode 100644 index b44ab869..00000000 --- a/src/main/java/com/activeviam/mac/cfg/security/impl/WebConfiguration.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.activeviam.mac.cfg.security.impl; - -public class WebConfiguration { - final boolean useAnonymous = false; - final String cookieName; - final boolean logout; - - public WebConfiguration(String cookieName) { - this.cookieName = cookieName; - this.logout = cookieName != null; - } -} From 0d92236ba0449b3c8f74872d9a2dcf5cbcffd2d4 Mon Sep 17 00:00:00 2001 From: lha Date: Thu, 12 Dec 2024 10:15:47 +0100 Subject: [PATCH 10/10] provide continuous build --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c3240feb..ce2ac285 100644 --- a/pom.xml +++ b/pom.xml @@ -25,7 +25,7 @@ 21 - 6.1.3-SNAPSHOT + 6.1.3-1733969770-ef208661 10.1.30