Skip to content

Commit

Permalink
xds base class and interface
Browse files Browse the repository at this point in the history
Signed-off-by: daizhenyu <[email protected]>
  • Loading branch information
daizhenyu committed May 21, 2024
1 parent b4c5e35 commit e56c5ac
Show file tree
Hide file tree
Showing 14 changed files with 564 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
<dependency.plugin.version>3.3.0</dependency.plugin.version>
<shade.plugin.version>3.2.4</shade.plugin.version>
<assembly.plugin.version>2.5.3</assembly.plugin.version>
<grpc.version>1.36.1</grpc.version>
<grpc.version>1.52.1</grpc.version>
<os.plugin.version>1.5.0.Final</os.plugin.version>
<protubuf.plugin.version>0.5.1</protubuf.plugin.version>
<version.plugin.version>2.8.1</version.plugin.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ agent.service.inject.enable=true
agent.service.dynamic.config.enable=true
# HTTP server switch
agent.service.httpserver.enable=false
# xDS service switch
agent.service.xds.service.enable=false
#============================= Event configuration =============================#
# Event switch
event.enable=false
Expand Down Expand Up @@ -85,6 +87,15 @@ gateway.nettyPort=6888
#gateway.initReconnectInternalTime=5
# Specify retreat algorithm maximum connection interval (s)
#gateway.maxReconnectInternalTime=180
#=============================xds configuration===============================#
# istio control plane address
xds.config.control.plane.address=istiod.istio-system.svc:15010
# Whether to use secure communication with the control plane
xds.config.security.enable=false
# Certificates used for secure communication with the control plane
xds.config.certificate.path=
# Private key used for secure communication with the control plane
xds.config.private.key.path=
#=============================Metadata===============================#
# Service name for host service instance
service.meta.service=default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public class ServiceConfig implements BaseConfig {
@ConfigFieldKey("httpserver.enable")
private boolean httpserverEnable = false;

@ConfigFieldKey("xds.service.enable")
private boolean xdsServiceEnable = false;

public boolean isHeartBeatEnable() {
return heartBeatEnable;
}
Expand Down Expand Up @@ -94,6 +97,14 @@ public void setHttpserverEnable(boolean httpserverEnable) {
this.httpserverEnable = httpserverEnable;
}

public boolean isXdsServiceEnable() {
return xdsServiceEnable;
}

public void setXdsServiceEnable(boolean xdsServiceEnable) {
this.xdsServiceEnable = xdsServiceEnable;
}

/**
* Check whether the service of the given class name is enabled.
*
Expand All @@ -119,6 +130,9 @@ public boolean checkServiceEnable(String serviceName) {
if (ServiceManager.HTTP_SERVER_SERVICE_IMPL.equals(serviceName)) {
return isHttpserverEnable();
}
if (ServiceManager.XDS_SERVICE_IMPL.equals(serviceName)) {
return isXdsServiceEnable();
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,17 @@ public class ServiceManager {
"io.sermant.implement.service.tracing.TracingServiceImpl";

/**
* HttpServer服务类名
* HttpServer service name
*/
public static final String HTTP_SERVER_SERVICE_IMPL =
"io.sermant.implement.service.httpserver.HttpServerServiceImpl";

/**
* xDS Service Discover
*/
public static final String XDS_SERVICE_IMPL =
"io.sermant.implement.service.xds.XdsServiceImpl";

/**
* logger
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved.
*
* 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 io.sermant.core.service.xds.config;

import io.sermant.core.config.common.BaseConfig;
import io.sermant.core.config.common.ConfigFieldKey;
import io.sermant.core.config.common.ConfigTypeKey;

/**
* XdsConfig
*
* @author daizhenyu
* @since 2024-05-08
**/
@ConfigTypeKey("xds.config")
public class XdsConfig implements BaseConfig {
@ConfigFieldKey("control.plane.address")
private String controlPlaneAddress;

@ConfigFieldKey("security.enable")
private boolean securityEnable = false;

@ConfigFieldKey("certificate.path")
private String certificatePath;

@ConfigFieldKey("private.key.path")
private String privateKeyPath;

public String getControlPlaneAddress() {
return controlPlaneAddress;
}

public void setControlPlaneAddress(String controlPlaneAddress) {
this.controlPlaneAddress = controlPlaneAddress;
}

public boolean isSecurityEnable() {
return securityEnable;
}

public void setSecurityEnable(boolean securityEnable) {
this.securityEnable = securityEnable;
}

public String getCertificatePath() {
return certificatePath;
}

public void setCertificatePath(String certificatePath) {
this.certificatePath = certificatePath;
}

public String getPrivateKeyPath() {
return privateKeyPath;
}

public void setPrivateKeyPath(String privateKeyPath) {
this.privateKeyPath = privateKeyPath;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved.
*
* 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 io.sermant.core.service.xds.entity;

import java.util.Map;

/**
* service instance interface
*
* @author daizhenyu
* @since 2024-05-09
**/
public interface ServiceInstance {
/**
* get xds cluster name
*
* @return cluster name
*/
String getClusterName();

/**
* get service name
*
* @return service name
*/
String getServiceName();

/**
* get service instance host
*
* @return service instance host
*/
String getHost();

/**
* get service instance port
*
* @return service instance port
*/
int getPort();

/**
* get service instance metadata
*
* @return metadata
*/
Map<String, String> getMetaData();

/**
* get service instance health status
*
* @return service instance health status
*/
boolean isHealthy();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved.
*
* 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 io.sermant.core.service.xds.listener;

import io.sermant.core.service.xds.entity.ServiceInstance;

import java.util.EventListener;
import java.util.Set;

/**
* XdsServiceListener
*
* @author daizhenyu
* @since 2024-05-08
**/
public interface XdsServiceDiscoveryListener extends EventListener {
/**
* Process the updated service instance
*
* @param instances updated service instance
*/
void process(Set<ServiceInstance> instances);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
import java.io.FileOutputStream;
import java.io.FilenameFilter;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
Expand Down Expand Up @@ -192,6 +196,26 @@ public boolean accept(File dir, String name) {
});
}

/**
* read file and convert it to string
*
* @param filePath file path
* @return String
*/
public static String readFileToString(String filePath) {
// Read all bytes from the file at once
byte[] bytes = null;
try {
bytes = Files.readAllBytes(Paths.get(filePath));
} catch (IOException e) {
LOGGER.log(Level.SEVERE, "cannot read file content, please check the path");
return StringUtils.EMPTY;
}

// Convert the bytes to a String using UTF-8 encoding
return new String(bytes, StandardCharsets.UTF_8);
}

private static boolean matchFileByWildcard(String name, String[] wcs) {
for (String wc : wcs) {
if (StringUtils.isWildcardMatch(name, wc)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ io.sermant.core.service.send.config.GatewayConfig
io.sermant.core.plugin.config.ServiceMeta
io.sermant.core.notification.config.NotificationConfig
io.sermant.core.service.httpserver.config.HttpServerConfig
io.sermant.core.service.xds.config.XdsConfig
21 changes: 21 additions & 0 deletions sermant-agentcore/sermant-agentcore-implement/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<nexus.staging.plugin.version>1.6.7</nexus.staging.plugin.version>
<nacos.version>2.1.2</nacos.version>
<jackson-databind.version>2.13.4.2</jackson-databind.version>
<envoyproxy.controlplane.version>0.1.32</envoyproxy.controlplane.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -125,6 +126,26 @@
<artifactId>asm-commons</artifactId>
<version>${asm.version}</version>
</dependency>
<dependency>
<groupId>io.envoyproxy.controlplane</groupId>
<artifactId>api</artifactId>
<version>${envoyproxy.controlplane.version}</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-stub</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-protobuf</artifactId>
<version>${grpc.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
Loading

0 comments on commit e56c5ac

Please sign in to comment.