com.huaweicloud.sdk.ccm.v1.region.CcmRegion Maven / Gradle / Ivy
package com.huaweicloud.sdk.ccm.v1.region;
import com.huaweicloud.sdk.core.region.IRegionProvider;
import com.huaweicloud.sdk.core.region.Region;
import com.huaweicloud.sdk.core.region.RegionProviderChain;
import com.huaweicloud.sdk.core.utils.StringUtils;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
public class CcmRegion {
public static final Region CN_NORTH_4 = new Region("cn-north-4", "https://ccm.cn-north-4.myhuaweicloud.com");
public static final Region AP_SOUTHEAST_3 =
new Region("ap-southeast-3", "https://ccm.ap-southeast-3.myhuaweicloud.com");
public static final Region EU_WEST_101 = new Region("eu-west-101", "https://ccm.eu-west-101.myhuaweicloud.com");
public static final Region RU_MOSCOW_1 = new Region("ru-moscow-1", "https://ccm.ru-moscow-1.myhuaweicloud.com");
private static final IRegionProvider PROVIDER = RegionProviderChain.getDefaultRegionProviderChain("CCM");
private static final Map STATIC_FIELDS = createStaticFields();
private static Map createStaticFields() {
Map map = new HashMap<>();
map.put("cn-north-4", CN_NORTH_4);
map.put("ap-southeast-3", AP_SOUTHEAST_3);
map.put("eu-west-101", EU_WEST_101);
map.put("ru-moscow-1", RU_MOSCOW_1);
return Collections.unmodifiableMap(map);
}
public static Region valueOf(String regionId) {
if (StringUtils.isEmpty(regionId)) {
throw new IllegalArgumentException("Unexpected empty parameter: regionId.");
}
Region result = PROVIDER.getRegion(regionId);
if (Objects.nonNull(result)) {
return result;
}
result = STATIC_FIELDS.get(regionId);
if (Objects.nonNull(result)) {
return result;
}
throw new IllegalArgumentException(String.format(Locale.ROOT,
"region id '%s' is not in the following supported regions of service CCM: [%s]",
regionId,
STATIC_FIELDS.keySet().stream().sorted().collect(Collectors.joining(", "))));
}
}