-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fb6dcd4
commit 535c88f
Showing
27 changed files
with
953 additions
and
68 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
45 changes: 45 additions & 0 deletions
45
...ples/src/main/java/group/rxcloud/capa/examples/configuration/DemoConfigurationClient.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 |
---|---|---|
@@ -1,4 +1,49 @@ | ||
package group.rxcloud.capa.examples.configuration; | ||
|
||
import group.rxcloud.capa.component.configstore.StoreConfig; | ||
import group.rxcloud.capa.configuration.CapaConfigurationClient; | ||
import group.rxcloud.capa.configuration.CapaConfigurationClientBuilder; | ||
import group.rxcloud.cloudruntimes.domain.core.configuration.ConfigurationItem; | ||
import group.rxcloud.cloudruntimes.domain.core.configuration.ConfigurationRequestItem; | ||
import group.rxcloud.cloudruntimes.domain.core.configuration.SubConfigurationResp; | ||
import group.rxcloud.cloudruntimes.utils.TypeRef; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
public class DemoConfigurationClient { | ||
|
||
public static void main(String[] args) throws InterruptedException { | ||
StoreConfig storeConfig = new StoreConfig(); | ||
storeConfig.setStoreName("config"); | ||
|
||
CapaConfigurationClient capaConfigurationClient = new CapaConfigurationClientBuilder(storeConfig).build(); | ||
|
||
ConfigurationRequestItem configurationRequestItem = new ConfigurationRequestItem(); | ||
configurationRequestItem.setAppId("test"); | ||
configurationRequestItem.setStoreName("config"); | ||
configurationRequestItem.setKeys(Collections.singletonList("test.json")); | ||
|
||
// get | ||
Mono<List<ConfigurationItem<String>>> configuration = | ||
capaConfigurationClient.getConfiguration(configurationRequestItem, TypeRef.STRING); | ||
|
||
List<ConfigurationItem<String>> block = configuration.block(); | ||
|
||
for (ConfigurationItem<String> item : block) { | ||
System.out.println(item); | ||
} | ||
|
||
// subscribe | ||
Flux<SubConfigurationResp<String>> subConfigurationRespFlux = | ||
capaConfigurationClient.subscribeConfiguration(configurationRequestItem, TypeRef.STRING); | ||
|
||
subConfigurationRespFlux.subscribe(resp -> { | ||
System.out.println(resp); | ||
}); | ||
|
||
Thread.sleep(1000 * 10); | ||
} | ||
} |
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
84 changes: 84 additions & 0 deletions
84
...ponent/src/main/java/group/rxcloud/capa/component/configstore/CapaConfigStoreBuilder.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,84 @@ | ||
package group.rxcloud.capa.component.configstore; | ||
|
||
|
||
import group.rxcloud.capa.infrastructure.config.CapaProperties; | ||
import group.rxcloud.capa.infrastructure.serializer.CapaObjectSerializer; | ||
import group.rxcloud.capa.infrastructure.serializer.DefaultObjectSerializer; | ||
|
||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.Properties; | ||
|
||
/** | ||
* A builder for the {@link CapaConfigStore} implementor. | ||
*/ | ||
public class CapaConfigStoreBuilder { | ||
|
||
/** | ||
* Serializer used for request and response objects in CapaClient. | ||
*/ | ||
private CapaObjectSerializer objectSerializer; | ||
|
||
private final StoreConfig storeConfig; | ||
|
||
/** | ||
* Creates a constructor for CapaConfigStore. | ||
* <p> | ||
* {@link DefaultObjectSerializer} is used for object and state serializers by default but is not recommended | ||
* for production scenarios. | ||
*/ | ||
public CapaConfigStoreBuilder(StoreConfig storeConfig) { | ||
this.objectSerializer = new DefaultObjectSerializer(); | ||
this.storeConfig = storeConfig; | ||
} | ||
|
||
/** | ||
* Sets the serializer for objects to be sent and received from Capa. | ||
* See {@link DefaultObjectSerializer} as possible serializer for non-production scenarios. | ||
* | ||
* @param objectSerializer Serializer for objects to be sent and received from Capa. | ||
* @return This instance. | ||
*/ | ||
public CapaConfigStoreBuilder withObjectSerializer(CapaObjectSerializer objectSerializer) { | ||
if (objectSerializer == null) { | ||
throw new IllegalArgumentException("Object serializer is required"); | ||
} | ||
if (objectSerializer.getContentType() == null | ||
|| objectSerializer.getContentType().isEmpty()) { | ||
throw new IllegalArgumentException("Content Type should not be null or empty"); | ||
} | ||
this.objectSerializer = objectSerializer; | ||
return this; | ||
} | ||
|
||
/** | ||
* Build an instance of the client based on the provided setup. | ||
* | ||
* @return an instance of {@link CapaConfigStore} | ||
* @throws IllegalStateException if any required field is missing | ||
*/ | ||
public CapaConfigStore build() { | ||
CapaConfigStore capaConfigStore = buildCapaConfigStore(); | ||
capaConfigStore.init(this.storeConfig); | ||
return capaConfigStore; | ||
} | ||
|
||
/** | ||
* Creates an instance of the {@link CapaConfigStore} implementor. | ||
* | ||
* @return Instance of {@link CapaConfigStore} implementor | ||
*/ | ||
private CapaConfigStore buildCapaConfigStore() { | ||
// load spi capa config store impl | ||
try { | ||
Properties properties = CapaProperties.COMPONENT_PROPERTIES_SUPPLIER.get(); | ||
String capaConfigStoreClassPath = properties.getProperty(CapaConfigStore.class.getName()); | ||
Class<? extends CapaConfigStore> aClass = (Class<? extends CapaConfigStore>) Class.forName(capaConfigStoreClassPath); | ||
Constructor<? extends CapaConfigStore> constructor = aClass.getConstructor(CapaObjectSerializer.class); | ||
Object newInstance = constructor.newInstance(this.objectSerializer); | ||
return (CapaConfigStore) newInstance; | ||
} catch (ClassNotFoundException | NoSuchMethodException | InvocationTargetException | InstantiationException | IllegalAccessException e) { | ||
throw new IllegalArgumentException("No CapaConfigStore Client supported."); | ||
} | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
sdk-component/src/main/java/group/rxcloud/capa/component/configstore/ConfigurationItem.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,80 @@ | ||
package group.rxcloud.capa.component.configstore; | ||
|
||
import java.util.Map; | ||
|
||
public class ConfigurationItem<T> { | ||
|
||
/** | ||
* Required. The key of configuration item | ||
*/ | ||
private String key; | ||
/** | ||
* The content of configuration item | ||
* Empty if the configuration is not set, including the case that the configuration is changed from value-set to value-not-set. | ||
*/ | ||
private T content; | ||
/** | ||
* The group of configuration item. | ||
*/ | ||
private String group; | ||
/** | ||
* The label of configuration item. | ||
*/ | ||
private String label; | ||
/** | ||
* The tag list of configuration item. | ||
*/ | ||
private Map<String, String> tags; | ||
/** | ||
* The metadata which will be passed to configuration store component. | ||
*/ | ||
private Map<String, String> metadata; | ||
|
||
public String getKey() { | ||
return key; | ||
} | ||
|
||
public void setKey(String key) { | ||
this.key = key; | ||
} | ||
|
||
public T getContent() { | ||
return content; | ||
} | ||
|
||
public void setContent(T content) { | ||
this.content = content; | ||
} | ||
|
||
public String getGroup() { | ||
return group; | ||
} | ||
|
||
public void setGroup(String group) { | ||
this.group = group; | ||
} | ||
|
||
public String getLabel() { | ||
return label; | ||
} | ||
|
||
public void setLabel(String label) { | ||
this.label = label; | ||
} | ||
|
||
public Map<String, String> getTags() { | ||
return tags; | ||
} | ||
|
||
public void setTags(Map<String, String> tags) { | ||
this.tags = tags; | ||
} | ||
|
||
public Map<String, String> getMetadata() { | ||
return metadata; | ||
} | ||
|
||
public void setMetadata(Map<String, String> metadata) { | ||
this.metadata = metadata; | ||
} | ||
} |
Oops, something went wrong.