Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apollo assembly optimization #5035

Merged
merged 70 commits into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
72f014f
table prefix
vdiskg Dec 1, 2023
b0223c2
assembly config v0.1
vdiskg Dec 1, 2023
b518cc6
assembly config v0.2
vdiskg Dec 1, 2023
aae21a1
assembly db init
vdiskg Dec 4, 2023
4b5ebee
assembly db init fix
vdiskg Dec 4, 2023
d0fbd74
assembly sql
vdiskg Dec 4, 2023
cb48902
Merge branch 'master' into assembly
vdiskg Dec 6, 2023
7bcc979
WebSecurity
vdiskg Dec 6, 2023
baf16c2
Merge branch 'master' into assembly
vdiskg Dec 13, 2023
af7f56e
H2Function
vdiskg Dec 13, 2023
c22644a
assembly profile
vdiskg Dec 13, 2023
73d45a7
assembly session
vdiskg Dec 13, 2023
ab86efe
ddl-auto=none
vdiskg Dec 13, 2023
d248136
DataSource
vdiskg Dec 13, 2023
8caeaa2
doc
vdiskg Dec 13, 2023
b9b055a
Merge branch 'master' into assembly
vdiskg Dec 18, 2023
d1590b5
admin assembly profile
vdiskg Dec 18, 2023
3000fa8
copy assembly sql on build
vdiskg Dec 18, 2023
889943f
merge sql conflict
vdiskg Dec 18, 2023
1782d58
sql comment
vdiskg Dec 18, 2023
497fb9f
sql converter
vdiskg Dec 18, 2023
2888dbf
sql converter delta
vdiskg Dec 22, 2023
ea07f15
sql converter clean
vdiskg Dec 22, 2023
84a54cc
fix assembly sql
vdiskg Dec 22, 2023
41b010f
fix assembly sql temp
vdiskg Dec 22, 2023
074376b
Merge branch 'master' into assembly
nobodyiam Dec 23, 2023
4a6837f
fix assembly sql temp v0.2
vdiskg Dec 29, 2023
d773cd7
fix assembly sql temp v0.3
vdiskg Jan 2, 2024
7663dd3
fix assembly sql temp v0.4
vdiskg Jan 2, 2024
7930dc3
fix assembly sql temp v0.5
vdiskg Jan 2, 2024
6763f62
assembly doc
vdiskg Jan 5, 2024
1fe8c27
autoGeneratedDeclaration
vdiskg Jan 5, 2024
cc438b8
rename sql-converter module
vdiskg Jan 5, 2024
b485a29
sql-converter h2
vdiskg Jan 5, 2024
e2de672
fix database-discovery
vdiskg Jan 5, 2024
08da155
Merge branch 'assembly-temp' into assembly
vdiskg Jan 5, 2024
7fc7246
Merge branch 'master' into assembly-temp
vdiskg Jan 8, 2024
001119f
mv sql
vdiskg Jan 8, 2024
5fba666
mv sql v0.2
vdiskg Jan 8, 2024
852feff
mv sql v0.3
vdiskg Jan 8, 2024
3ce7c39
multi datasource
vdiskg Jan 12, 2024
f305489
remove table prefix
vdiskg Jan 12, 2024
34c2596
update doc
vdiskg Jan 12, 2024
224bd7a
fix init
vdiskg Jan 12, 2024
435348a
log apollo datasource initialize
vdiskg Jan 12, 2024
0397d90
fix apollo datasource initialize
vdiskg Jan 12, 2024
ee487c8
mv h2 sql
vdiskg Jan 12, 2024
e24336a
fix apollo datasource initialize v0.2
vdiskg Jan 12, 2024
31657f3
Merge branch 'assembly-temp' into assembly
vdiskg Jan 12, 2024
bbe2163
clean import
vdiskg Jan 12, 2024
d0aa029
fix sql check
vdiskg Jan 12, 2024
5d212c3
fix sql check v0.2
vdiskg Jan 12, 2024
6e4ad6d
Merge branch 'assembly-temp' into assembly
vdiskg Jan 12, 2024
497e36e
Merge branch 'master' into assembly
vdiskg Jan 15, 2024
1080e41
merge sql
vdiskg Jan 15, 2024
bce70ef
merge sql generated
vdiskg Jan 15, 2024
d0e409e
add sql test temp
vdiskg Jan 23, 2024
1313fc3
add sql test temp 2
vdiskg Jan 24, 2024
db9a48a
add sql test
vdiskg Jan 26, 2024
c8b3765
sql convert
vdiskg Jan 26, 2024
08ffbb7
fix sql-convert
vdiskg Jan 26, 2024
10f65ae
Merge branch 'master' into assembly
vdiskg Jan 26, 2024
b1e370a
CHANGES.md
vdiskg Jan 26, 2024
768c250
fix copyright
vdiskg Jan 26, 2024
4d72047
clean logger
vdiskg Feb 2, 2024
a8398e5
Merge branch 'master' into assembly
vdiskg Feb 2, 2024
4941f4f
fix order
vdiskg Feb 2, 2024
06afabb
fix h2 converter
vdiskg Feb 2, 2024
d68ed97
fix h2 converter v0.2
vdiskg Feb 2, 2024
e8b44ee
fix order v0.2
vdiskg Feb 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
Expand All @@ -29,7 +30,9 @@
@EnableAspectJAutoProxy
@Configuration
@PropertySource(value = {"classpath:adminservice.properties"})
@EnableAutoConfiguration
@EnableAutoConfiguration(exclude = {
UserDetailsServiceAutoConfiguration.class,
})
@EnableTransactionManagement
@ComponentScan(basePackageClasses = {ApolloCommonConfig.class,
ApolloBizConfig.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
public class AdminServiceAutoConfiguration {
Expand All @@ -45,4 +48,18 @@

return filterRegistrationBean;
}

/**
* for apollo-assembly
*/
@Order(99)
@Configuration
static class AdminServiceSecurityConfigurer extends WebSecurityConfigurerAdapter {
vdiskg marked this conversation as resolved.
Show resolved Hide resolved

@Override
protected void configure(HttpSecurity http) throws Exception {
http.csrf().disable();
Fixed Show fixed Hide fixed
http.httpBasic();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.ctrip.framework.apollo.assembly;

import com.ctrip.framework.apollo.adminservice.AdminServiceApplication;
import com.ctrip.framework.apollo.assembly.datasource.ApolloAssemblySqlInitializationConfig;
import com.ctrip.framework.apollo.audit.configuration.ApolloAuditAutoConfiguration;
import com.ctrip.framework.apollo.configservice.ConfigServiceApplication;
import com.ctrip.framework.apollo.portal.PortalApplication;
Expand All @@ -25,14 +26,19 @@
import org.slf4j.LoggerFactory;
import org.springframework.boot.WebApplicationType;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.context.scope.refresh.RefreshScope;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Import;

@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class,
HibernateJpaAutoConfiguration.class, ApolloAuditAutoConfiguration.class})
@Import({
ApolloAssemblySqlInitializationConfig.class,
})
@SpringBootApplication(exclude = {
HibernateJpaAutoConfiguration.class,
ApolloAuditAutoConfiguration.class,
})
public class ApolloApplication {

private static final Logger logger = LoggerFactory.getLogger(ApolloApplication.class);
Expand All @@ -43,37 +49,31 @@ public static void main(String[] args) throws Exception {
*/
ConfigurableApplicationContext commonContext =
new SpringApplicationBuilder(ApolloApplication.class).web(WebApplicationType.NONE).run(args);
logger.info(commonContext.getId() + " isActive: " + commonContext.isActive());
logger.info("commonContext [{}] isActive: {}", commonContext.getId(), commonContext.isActive());

/**
* ConfigService
*/
if (commonContext.getEnvironment().containsProperty("configservice")) {
ConfigurableApplicationContext configContext =
new SpringApplicationBuilder(ConfigServiceApplication.class).parent(commonContext)
.sources(RefreshScope.class).run(args);
logger.info(configContext.getId() + " isActive: " + configContext.isActive());
}
ConfigurableApplicationContext configContext =
new SpringApplicationBuilder(ConfigServiceApplication.class).parent(commonContext)
.sources(RefreshScope.class).run(args);
logger.info("configContext [{}] isActive: {}", configContext.getId(), configContext.isActive());

/**
* AdminService
*/
if (commonContext.getEnvironment().containsProperty("adminservice")) {
ConfigurableApplicationContext adminContext =
new SpringApplicationBuilder(AdminServiceApplication.class).parent(commonContext)
.sources(RefreshScope.class).run(args);
logger.info(adminContext.getId() + " isActive: " + adminContext.isActive());
}
ConfigurableApplicationContext adminContext =
new SpringApplicationBuilder(AdminServiceApplication.class).parent(commonContext)
.sources(RefreshScope.class).run(args);
logger.info("adminContext [{}] isActive: {}" , adminContext.getId(), adminContext.isActive());

/**
* Portal
*/
if (commonContext.getEnvironment().containsProperty("portal")) {
ConfigurableApplicationContext portalContext =
new SpringApplicationBuilder(PortalApplication.class).parent(commonContext)
.sources(RefreshScope.class).run(args);
logger.info(portalContext.getId() + " isActive: " + portalContext.isActive());
}
ConfigurableApplicationContext portalContext =
new SpringApplicationBuilder(PortalApplication.class).parent(commonContext)
.sources(RefreshScope.class).run(args);
logger.info("portalContext [{}] isActive: {}", portalContext.getId(), portalContext.isActive());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/*
* Copyright 2023 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.ctrip.framework.apollo.assembly.datasource;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.sql.DataSource;
import org.springframework.boot.autoconfigure.sql.init.SqlDataSourceScriptDatabaseInitializer;
import org.springframework.boot.autoconfigure.sql.init.SqlInitializationProperties;
import org.springframework.boot.jdbc.DatabaseDriver;
import org.springframework.boot.jdbc.init.PlatformPlaceholderDatabaseDriverResolver;
import org.springframework.boot.sql.init.DatabaseInitializationSettings;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

public class ApolloAssemblyDataSourceScriptDatabaseInitializer extends
SqlDataSourceScriptDatabaseInitializer {

public ApolloAssemblyDataSourceScriptDatabaseInitializer(DataSource dataSource,
SqlInitializationProperties properties) {
super(dataSource, getSettings(dataSource, properties));
}

public static DatabaseInitializationSettings getSettings(DataSource dataSource,
SqlInitializationProperties properties) {

PlatformPlaceholderDatabaseDriverResolver platformResolver = new PlatformPlaceholderDatabaseDriverResolver().withDriverPlatform(
DatabaseDriver.MARIADB, "mysql");

List<String> schemaLocations = resolveLocations(properties.getSchemaLocations(),
platformResolver,
dataSource, properties);
List<String> dataLocations = resolveLocations(properties.getDataLocations(), platformResolver,
dataSource, properties);

DatabaseInitializationSettings settings = new DatabaseInitializationSettings();
settings.setSchemaLocations(
scriptLocations(schemaLocations, "schema", properties.getPlatform()));
settings.setDataLocations(scriptLocations(dataLocations, "data", properties.getPlatform()));
settings.setContinueOnError(properties.isContinueOnError());
settings.setSeparator(properties.getSeparator());
settings.setEncoding(properties.getEncoding());
settings.setMode(properties.getMode());
return settings;
}


private static List<String> resolveLocations(Collection<String> locations,
PlatformPlaceholderDatabaseDriverResolver platformResolver, DataSource dataSource,
SqlInitializationProperties properties) {

if (CollectionUtils.isEmpty(locations)) {
return null;
}

String platform = properties.getPlatform();
if (StringUtils.hasText(platform) && !"all".equals(platform)) {
return platformResolver.resolveAll(platform, locations.toArray(new String[0]));
}
return platformResolver.resolveAll(dataSource, locations.toArray(new String[0]));
}

private static List<String> scriptLocations(List<String> locations, String fallback,
String platform) {
if (locations != null) {
return locations;
}
List<String> fallbackLocations = new ArrayList<>();
fallbackLocations.add("optional:classpath*:" + fallback + "-" + platform + ".sql");
fallbackLocations.add("optional:classpath*:" + fallback + ".sql");
return fallbackLocations;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright 2023 Apollo Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package com.ctrip.framework.apollo.assembly.datasource;

import javax.sql.DataSource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.autoconfigure.sql.init.SqlInitializationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
import org.springframework.util.StringUtils;

@ConditionalOnProperty(prefix = "spring.sql.init", name = "enabled", matchIfMissing = true)
@Configuration
public class ApolloAssemblySqlInitializationConfig {

@Bean
ApolloAssemblyDataSourceScriptDatabaseInitializer dataSourceScriptDatabaseInitializer(DataSource dataSource,
SqlInitializationProperties properties) {
return new ApolloAssemblyDataSourceScriptDatabaseInitializer(
determineDataSource(dataSource, properties.getUsername(), properties.getPassword()), properties);
}

private static DataSource determineDataSource(DataSource dataSource, String username, String password) {
if (StringUtils.hasText(username) && StringUtils.hasText(password)) {
return DataSourceBuilder.derivedFrom(dataSource)
.username(username)
.password(password)
.type(SimpleDriverDataSource.class)
.build();
}
return dataSource;
}
}
38 changes: 38 additions & 0 deletions apollo-assembly/src/main/resources/application-github.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#
# Copyright 2023 Apollo Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# DataSource
spring.datasource.url=${spring_datasource_url}
spring.datasource.username=${spring_datasource_username}
spring.datasource.password=${spring_datasource_password}

# Default datasource
spring_datasource_url=jdbc:h2:mem:~/apolloassemblydb;mode=mysql;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1;BUILTIN_ALIAS_OVERRIDE=TRUE;DATABASE_TO_UPPER=FALSE

# Table prefix
spring.jpa.hibernate.naming.physical-strategy=com.ctrip.framework.apollo.common.jpa.TablePrefixNamingStrategy
spring.jpa.table-prefix.config-prefix=C_0_
spring.jpa.table-prefix.portal-prefix=P_0_

# H2 datasource
spring.sql.init.schema-locations=classpath:jpa/@@platform@@/apolloconfigdb.sql, classpath:jpa/@@platform@@/apolloportaldb.sql
vdiskg marked this conversation as resolved.
Show resolved Hide resolved
spring.sql.init.mode=embedded
spring.jpa.properties.hibernate.show_sql=false
spring.jpa.properties.hibernate.metadata_builder_contributor=com.ctrip.framework.apollo.common.jpa.SqlFunctionsMetadataBuilderContributor
spring.h2.console.enabled=true
spring.h2.console.settings.web-allow-others=true

# Default env
apollo.portal.envs=local
Loading
Loading