-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into fix_sql_error
- Loading branch information
Showing
8 changed files
with
495 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ Licensed to the Apache Software Foundation (ASF) under one or more | ||
~ contributor license agreements. See the NOTICE file distributed with | ||
~ this work for additional information regarding copyright ownership. | ||
~ The ASF licenses this file to You 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. | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> | ||
<parent> | ||
<groupId>org.apache.shenyu</groupId> | ||
<artifactId>shenyu-registry</artifactId> | ||
<version>2.7.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>shenyu-registry-kubernetes</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.shenyu</groupId> | ||
<artifactId>shenyu-registry-api</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-web</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
61 changes: 61 additions & 0 deletions
61
...stry-kubernetes/src/main/java/org/apache/shenyu/registry/kubernetes/KubernetesClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.shenyu.registry.kubernetes; | ||
|
||
import org.springframework.util.CollectionUtils; | ||
import org.springframework.web.client.RestTemplate; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** | ||
* kubernetes client. | ||
*/ | ||
public class KubernetesClient { | ||
|
||
private RestTemplate rest; | ||
|
||
private KubernetesConfig kubernetesConfig; | ||
|
||
public KubernetesClient(final KubernetesConfig kubernetesConfig) { | ||
this.kubernetesConfig = kubernetesConfig; | ||
this.rest = new RestTemplate(); | ||
} | ||
|
||
/** | ||
* get all serviceInstance. | ||
* @param serviceId service identifier | ||
* @return list of serviceInstance | ||
*/ | ||
public List<KubernetesInstance> selectInstances(final String serviceId) { | ||
List<KubernetesInstance> response = Collections.emptyList(); | ||
KubernetesInstance[] responseBody = (KubernetesInstance[]) this.rest.getForEntity(this.kubernetesConfig.getDiscoveryServerUrl() + "/apps/" + serviceId, | ||
KubernetesInstance[].class, new Object[0]).getBody(); | ||
if (responseBody != null && responseBody.length > 0) { | ||
response = (List) Arrays.stream(responseBody).filter(this::matchNamespaces).collect(Collectors.toList()); | ||
} | ||
|
||
return response; | ||
} | ||
|
||
private boolean matchNamespaces(final KubernetesInstance kubernetesInstance) { | ||
return CollectionUtils.isEmpty(this.kubernetesConfig.getNamespaces()) ? true : this.kubernetesConfig.getNamespaces().contains(kubernetesInstance.getNamespace()); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...stry-kubernetes/src/main/java/org/apache/shenyu/registry/kubernetes/KubernetesConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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 org.apache.shenyu.registry.kubernetes; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class KubernetesConfig { | ||
|
||
private String discoveryServerUrl; | ||
|
||
private boolean enabled = true; | ||
|
||
private List<String> namespaces = new ArrayList(); | ||
|
||
public KubernetesConfig() { | ||
} | ||
|
||
/** | ||
* get discoveryServer url. | ||
* @return discoveryServer url. | ||
*/ | ||
public String getDiscoveryServerUrl() { | ||
return this.discoveryServerUrl; | ||
} | ||
|
||
/** | ||
* set discoveryServer url. | ||
* @param discoveryServerUrl discoveryServer url. | ||
*/ | ||
public void setDiscoveryServerUrl(final String discoveryServerUrl) { | ||
this.discoveryServerUrl = discoveryServerUrl; | ||
} | ||
|
||
/** | ||
* get enable status. | ||
* @return enable status. | ||
*/ | ||
public boolean isEnabled() { | ||
return this.enabled; | ||
} | ||
|
||
/** | ||
* set registry enable status. | ||
* @param enabled enable status. | ||
*/ | ||
public void setEnabled(final boolean enabled) { | ||
this.enabled = enabled; | ||
} | ||
|
||
/** | ||
* get namespaces. | ||
* @return namespaces. | ||
*/ | ||
List<String> getNamespaces() { | ||
return this.namespaces; | ||
} | ||
|
||
/** | ||
* set kubernetes namespace. | ||
* @param namespaces list of namespace. | ||
*/ | ||
public void setNamespaces(final List<String> namespaces) { | ||
this.namespaces = namespaces; | ||
} | ||
} |
Oops, something went wrong.