Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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 io.microsphere.spring.cloud.client.actuator;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.client.actuator.FeaturesEndpoint;

import java.util.List;
import java.util.Map;

import static io.microsphere.spring.cloud.client.actuator.constants.FeaturesConstants.PROPERTY_NAME_PREFIX;
import static java.util.Collections.emptyMap;

/**
* The {@link ConfigurationProperties} for {@link FeaturesEndpoint}
*
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @see ConfigurationProperties
* @since 1.0.0
*/
@ConfigurationProperties(prefix = PROPERTY_NAME_PREFIX)
public class FeaturesProperties {

private Map<String, List<String>> _abstract;

private Map<String, Map<String, String>> named;

public void setAbstract(Map<String, List<String>> _abstract) {
this._abstract = _abstract;
}

public Map<String, List<String>> getAbstract() {
if (_abstract == null) {
return emptyMap();
}
return _abstract;
}

public void setNamed(Map<String, Map<String, String>> named) {
this.named = named;
}

public Map<String, Map<String, String>> getNamed() {
if (named == null) {
return emptyMap();
}
return named;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
/*
* 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 io.microsphere.spring.cloud.client.actuator;

import io.microsphere.util.Utils;
import org.springframework.cloud.client.actuator.HasFeatures;

import static io.microsphere.constants.SymbolConstants.COLON_CHAR;
import static io.microsphere.spring.cloud.client.actuator.constants.FeaturesConstants.ABSTRACT_FEATURE_PROPERTY_NAME_PATTERN;
import static io.microsphere.spring.cloud.client.actuator.constants.FeaturesConstants.BEAN_NAME_SUFFIX;
import static io.microsphere.spring.cloud.client.actuator.constants.FeaturesConstants.NAMED_FEATURE_PROPERTY_NAME_PATTERN;
import static io.microsphere.text.FormatUtils.format;

/**
* The {@link Utils utilities} class for Spring Cloud {@link HasFeatures features}
*
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @see HasFeatures
* @see Utils
* @since 1.0.0
*/
public abstract class FeaturesUtils implements Utils {

/**
* Gets the configuration property name for abstract features of the specified module.
* <h3>Example Usage</h3>
* <pre>{@code
* // For module name "jdbc"
* String propertyName = getAbstractFeaturePropertyName("jdbc");
* // Result: "microsphere.spring.cloud.features.abstract.jdbc"
* }</pre>
*
* @param moduleName the name of the module
* @return the configuration property name for abstract features
*/
public static String getAbstractFeaturePropertyName(String moduleName) {
return format(ABSTRACT_FEATURE_PROPERTY_NAME_PATTERN, moduleName);
}

/**
* Gets the configuration property name for a named feature of the specified module.
* <h3>Example Usage</h3>
* <pre>{@code
* // For module name "web" and feature name "rest-template"
* String propertyName = getNamedFeaturePropertyName("web", "rest-template");
* // Result: "microsphere.spring.cloud.features.named.web.rest-template"
* }</pre>
*
* @param moduleName the name of the module
* @param featureName the name of the feature
* @return the configuration property name for the named feature
*/
public static String getNamedFeaturePropertyName(String moduleName, String featureName) {
return format(NAMED_FEATURE_PROPERTY_NAME_PATTERN, moduleName, featureName);
}

/**
* Gets the bean name for {@link HasFeatures} of the specified module.
* <h3>Example Usage</h3>
* <pre>{@code
* // For module name "jdbc"
* String beanName = getHasFeaturesBeanName("jdbc");
* // Result: "jdbc.features"
* }</pre>
*
* @param moduleName the name of the module
* @return the bean name for {@link HasFeatures}
*/
public static String getHasFeaturesBeanName(String moduleName) {
return moduleName + BEAN_NAME_SUFFIX;
}

/**
* Gets the qualified feature name for a named feature of the specified module.
* <h3>Example Usage</h3>
* <pre>{@code
* // For module name "web" and feature name "rest-template"
* String qualifiedName = getQualifierFeatureName("web", "rest-template");
* // Result: "web:rest-template"
* }</pre>
*
* @param moduleName the name of the module
* @param featureName the name of the feature
* @return the qualified feature name
*/
public static String getQualifierFeatureName(String moduleName, String featureName) {
return moduleName + COLON_CHAR + featureName;
}

private FeaturesUtils() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* 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 io.microsphere.spring.cloud.client.actuator;

import org.springframework.cloud.client.actuator.NamedFeature;

import java.util.Comparator;

/**
* The {@link Comparator} class for {@link NamedFeature}
*
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @see Comparator
* @see NamedFeature
* @since 1.0.0
*/
public class NamedFeatureComparator implements Comparator<NamedFeature> {

public static final NamedFeatureComparator INSTANCE = new NamedFeatureComparator();

@Override
public int compare(NamedFeature namedFeature1, NamedFeature namedFeature2) {
int c = namedFeature1.getName().compareTo(namedFeature2.getName());
if (c == 0) {
c = compare(namedFeature1.getType(), namedFeature2.getType());
}
return c;
}

private int compare(Class<?> type1, Class<?> type2) {
return type1.getName().compareTo(type2.getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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 io.microsphere.spring.cloud.client.actuator.constants;

import org.springframework.cloud.client.actuator.HasFeatures;

import static io.microsphere.constants.SymbolConstants.DOT;
import static io.microsphere.spring.cloud.commons.constants.CommonsPropertyConstants.MICROSPHERE_SPRING_CLOUD_PROPERTY_NAME_PREFIX;

/**
* The constants class for Spring Cloud {@link HasFeatures features}
*
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
* @see HasFeatures
* @see org.springframework.cloud.client.actuator.FeaturesEndpoint
* @since 1.0.0
*/
public interface FeaturesConstants {

String FEATURES = "features";

String ABSTRACT = "abstract";

String NAMED = "named";

String PLACEHOLDER = "{}";

/**
* The prefix of the configuration properties for {@link HasFeatures} : "microsphere.spring.cloud.features"
*/
String PROPERTY_NAME_PREFIX = MICROSPHERE_SPRING_CLOUD_PROPERTY_NAME_PREFIX + FEATURES;

/**
* The prefix of the configuration properties for abstract features: "microsphere.spring.cloud.features.abstract."
*/
String ABSTRACT_FEATURE_PROPERTY_NAME_PREFIX = PROPERTY_NAME_PREFIX + DOT + ABSTRACT + DOT;

/**
* The prefix of the configuration properties for named features: "microsphere.spring.cloud.features.named."
*/
String NAMED_FEATURE_PROPERTY_NAME_PREFIX = PROPERTY_NAME_PREFIX + DOT + NAMED + DOT;

/**
* The pattern of the configuration properties for abstract features: "microsphere.spring.cloud.features.abstract.{module-name}"
*/
String ABSTRACT_FEATURE_PROPERTY_NAME_PATTERN = ABSTRACT_FEATURE_PROPERTY_NAME_PREFIX + PLACEHOLDER;

/**
* The pattern of the configuration properties for named features: "microsphere.spring.cloud.features.named.{module-name}.{feature-name}"
*/
String NAMED_FEATURE_PROPERTY_NAME_PATTERN = NAMED_FEATURE_PROPERTY_NAME_PREFIX + PLACEHOLDER + DOT + PLACEHOLDER;

/**
* The suffix of the bean name for {@link HasFeatures} : ".features"
*/
String BEAN_NAME_SUFFIX = DOT + FEATURES;
}
Loading
Loading