Add service connection support for Hazelcast
See gh-42416
This commit is contained in:
committed by
Moritz Halbritter
parent
fb3dd68dd3
commit
cee7439dbe
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright 2012-2024 the original author or 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
|
||||
*
|
||||
* https://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 org.springframework.boot.docker.compose.service.connection.hazelcast;
|
||||
|
||||
import com.hazelcast.client.config.ClientConfig;
|
||||
|
||||
import org.springframework.boot.autoconfigure.hazelcast.HazelcastConnectionDetails;
|
||||
import org.springframework.boot.docker.compose.core.RunningService;
|
||||
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionDetailsFactory;
|
||||
import org.springframework.boot.docker.compose.service.connection.DockerComposeConnectionSource;
|
||||
|
||||
/**
|
||||
* {@link DockerComposeConnectionDetailsFactory} to create
|
||||
* {@link HazelcastConnectionDetails} for a {@code hazelcast} service.
|
||||
*
|
||||
* @author Dmytro Nosan
|
||||
*/
|
||||
class HazelcastDockerComposeConnectionDetailsFactory
|
||||
extends DockerComposeConnectionDetailsFactory<HazelcastConnectionDetails> {
|
||||
|
||||
private static final int DEFAULT_PORT = 5701;
|
||||
|
||||
protected HazelcastDockerComposeConnectionDetailsFactory() {
|
||||
super("hazelcast/hazelcast", "com.hazelcast.client.config.ClientConfig");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected HazelcastConnectionDetails getDockerComposeConnectionDetails(DockerComposeConnectionSource source) {
|
||||
return new HazelcastDockerComposeConnectionDetails(source.getRunningService());
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link HazelcastConnectionDetails} backed by a {@code hazelcast}
|
||||
* {@link RunningService}.
|
||||
*/
|
||||
static class HazelcastDockerComposeConnectionDetails extends DockerComposeConnectionDetails
|
||||
implements HazelcastConnectionDetails {
|
||||
|
||||
private final String host;
|
||||
|
||||
private final int port;
|
||||
|
||||
private final HazelcastEnvironment environment;
|
||||
|
||||
HazelcastDockerComposeConnectionDetails(RunningService service) {
|
||||
super(service);
|
||||
this.host = service.host();
|
||||
this.port = service.ports().get(DEFAULT_PORT);
|
||||
this.environment = new HazelcastEnvironment(service.env());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClientConfig getClientConfig() {
|
||||
ClientConfig config = new ClientConfig();
|
||||
this.environment.getClusterName().ifPresent(config::setClusterName);
|
||||
config.getNetworkConfig().addAddress(this.host + ":" + this.port);
|
||||
return config;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2012-2024 the original author or 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
|
||||
*
|
||||
* https://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 org.springframework.boot.docker.compose.service.connection.hazelcast;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* Hazelcast environment details.
|
||||
*
|
||||
* @author Dmytro Nosan
|
||||
*/
|
||||
class HazelcastEnvironment {
|
||||
|
||||
private final String clusterName;
|
||||
|
||||
HazelcastEnvironment(Map<String, String> env) {
|
||||
this.clusterName = env.get("HZ_CLUSTERNAME");
|
||||
}
|
||||
|
||||
Optional<String> getClusterName() {
|
||||
return Optional.ofNullable(this.clusterName);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2012-2024 the original author or 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
|
||||
*
|
||||
* https://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.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Auto-configuration for Docker Compose Hazelcast service connections.
|
||||
*/
|
||||
package org.springframework.boot.docker.compose.service.connection.hazelcast;
|
||||
@@ -11,6 +11,7 @@ org.springframework.boot.docker.compose.service.connection.activemq.ArtemisDocke
|
||||
org.springframework.boot.docker.compose.service.connection.cassandra.CassandraDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.elasticsearch.ElasticsearchDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.flyway.JdbcAdaptingFlywayConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.hazelcast.HazelcastDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.ldap.OpenLdapDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.liquibase.JdbcAdaptingLiquibaseConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.mariadb.MariaDbJdbcDockerComposeConnectionDetailsFactory,\
|
||||
@@ -20,8 +21,8 @@ org.springframework.boot.docker.compose.service.connection.mysql.MySqlJdbcDocker
|
||||
org.springframework.boot.docker.compose.service.connection.mysql.MySqlR2dbcDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.neo4j.Neo4jDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.oracle.OracleFreeJdbcDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.oracle.OracleXeJdbcDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.oracle.OracleFreeR2dbcDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.oracle.OracleXeJdbcDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.oracle.OracleXeR2dbcDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.otlp.OpenTelemetryLoggingDockerComposeConnectionDetailsFactory,\
|
||||
org.springframework.boot.docker.compose.service.connection.otlp.OpenTelemetryMetricsDockerComposeConnectionDetailsFactory,\
|
||||
|
||||
Reference in New Issue
Block a user