-
Notifications
You must be signed in to change notification settings - Fork 222
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
3 changed files
with
106 additions
and
5 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
...in/java/com/huaweicloud/governance/adapters/loadbalancer/FallbackDiscoveryProperties.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,78 @@ | ||
/* | ||
* Copyright (C) 2020-2024 Huawei Technologies Co., Ltd. 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 com.huaweicloud.governance.adapters.loadbalancer; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
|
||
import org.springframework.beans.factory.InitializingBean; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.cloud.client.DefaultServiceInstance; | ||
import org.springframework.cloud.client.ServiceInstance; | ||
|
||
/** | ||
* Configures fallback address if discovery client do not find any instance or all | ||
* instances are isolated. | ||
*/ | ||
@ConfigurationProperties(prefix = "spring.cloud.discovery.client.fallback") | ||
public class FallbackDiscoveryProperties implements InitializingBean { | ||
private Map<String, DefaultServiceInstance> instances = new HashMap<>(); | ||
|
||
private boolean enabled = false; | ||
|
||
private DefaultServiceInstance global; | ||
|
||
public Map<String, DefaultServiceInstance> getInstances() { | ||
return this.instances; | ||
} | ||
|
||
public void setInstances(Map<String, DefaultServiceInstance> instances) { | ||
this.instances = instances; | ||
} | ||
|
||
public boolean isEnabled() { | ||
return enabled; | ||
} | ||
|
||
public void setEnabled(boolean enabled) { | ||
this.enabled = enabled; | ||
} | ||
|
||
public DefaultServiceInstance getGlobal() { | ||
return global; | ||
} | ||
|
||
public void setGlobal(DefaultServiceInstance global) { | ||
this.global = global; | ||
} | ||
|
||
@Override | ||
public void afterPropertiesSet() { | ||
for (Entry<String, DefaultServiceInstance> entry : instances.entrySet()) { | ||
entry.getValue().setServiceId(entry.getKey()); | ||
} | ||
} | ||
|
||
public ServiceInstance readFallbackServiceInstance(String serviceId) { | ||
if (this.instances.get(serviceId) != null) { | ||
return this.instances.get(serviceId); | ||
} | ||
return global; | ||
} | ||
} |
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