Skip to content

Commit

Permalink
Add missing data to Dapr Metadata and its components (#1059)
Browse files Browse the repository at this point in the history
* Add missing data to Dapr Metadata and its components

Signed-off-by: Artur Ciocanu <ciocanu@adobe.com>

* Add metadata field to subscription

Signed-off-by: Artur Ciocanu <ciocanu@adobe.com>

---------

Signed-off-by: Artur Ciocanu <ciocanu@adobe.com>
Co-authored-by: Artur Ciocanu <ciocanu@adobe.com>
  • Loading branch information
artur-ciocanu and Artur Ciocanu authored Jun 26, 2024
1 parent 363b6f9 commit 64f291f
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 42 deletions.
27 changes: 22 additions & 5 deletions sdk/src/main/java/io/dapr/client/DaprClientImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import com.google.common.base.Strings;
import com.google.protobuf.ByteString;
import com.google.protobuf.Empty;
import io.dapr.client.domain.ActorMetadata;
import io.dapr.client.domain.AppConnectionPropertiesHealthMetadata;
import io.dapr.client.domain.AppConnectionPropertiesMetadata;
import io.dapr.client.domain.BulkPublishEntry;
Expand Down Expand Up @@ -65,6 +66,8 @@
import io.dapr.v1.CommonProtos;
import io.dapr.v1.DaprGrpc;
import io.dapr.v1.DaprProtos;
import io.dapr.v1.DaprProtos.ActiveActorsCount;
import io.dapr.v1.DaprProtos.ActorRuntime;
import io.dapr.v1.DaprProtos.AppConnectionHealthProperties;
import io.dapr.v1.DaprProtos.AppConnectionProperties;
import io.dapr.v1.DaprProtos.MetadataHTTPEndpoint;
Expand Down Expand Up @@ -1266,22 +1269,35 @@ private DaprMetadata buildDaprMetadata(DaprProtos.GetMetadataResponse response)
String id = response.getId();
String runtimeVersion = response.getRuntimeVersion();
List<String> enabledFeatures = response.getEnabledFeaturesList();
List<ActorMetadata> actors = getActors(response);
Map<String, String> attributes = response.getExtendedMetadataMap();
List<ComponentMetadata> components = getComponents(response);
List<HttpEndpointMetadata> httpEndpoints = getHttpEndpoints(response);
List<SubscriptionMetadata> subscriptions = getSubscriptions(response);
AppConnectionPropertiesMetadata appConnectionProperties = getAppConnectionProperties(response);

return new DaprMetadata(id, runtimeVersion, enabledFeatures, attributes, components, httpEndpoints, subscriptions,
appConnectionProperties);
return new DaprMetadata(id, runtimeVersion, enabledFeatures, actors, attributes, components, httpEndpoints,
subscriptions, appConnectionProperties);
}

private List<ActorMetadata> getActors(DaprProtos.GetMetadataResponse response) {
ActorRuntime actorRuntime = response.getActorRuntime();
List<ActiveActorsCount> activeActorsList = actorRuntime.getActiveActorsList();

List<ActorMetadata> actors = new ArrayList<>();
for (ActiveActorsCount aac : activeActorsList) {
actors.add(new ActorMetadata(aac.getType(), aac.getCount()));
}

return actors;
}

private List<ComponentMetadata> getComponents(DaprProtos.GetMetadataResponse response) {
List<RegisteredComponents> registeredComponentsList = response.getRegisteredComponentsList();

List<ComponentMetadata> components = new ArrayList<>();
for (RegisteredComponents rc : registeredComponentsList) {
components.add(new ComponentMetadata(rc.getName(), rc.getType(), rc.getVersion()));
components.add(new ComponentMetadata(rc.getName(), rc.getType(), rc.getVersion(), rc.getCapabilitiesList()));
}

return components;
Expand All @@ -1295,9 +1311,10 @@ private List<SubscriptionMetadata> getSubscriptions(DaprProtos.GetMetadataRespon
List<PubsubSubscriptionRule> rulesList = s.getRules().getRulesList();
List<RuleMetadata> rules = new ArrayList<>();
for (PubsubSubscriptionRule r : rulesList) {
rules.add(new RuleMetadata(r.getPath()));
rules.add(new RuleMetadata(r.getMatch(), r.getPath()));
}
subscriptions.add(new SubscriptionMetadata(s.getTopic(), s.getPubsubName(), s.getDeadLetterTopic(), rules));
subscriptions.add(new SubscriptionMetadata(s.getPubsubName(), s.getTopic(), s.getMetadataMap(), rules,
s.getDeadLetterTopic()));
}

return subscriptions;
Expand Down
41 changes: 41 additions & 0 deletions sdk/src/main/java/io/dapr/client/domain/ActorMetadata.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2024 The Dapr Authors
* 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 io.dapr.client.domain;

/**
* ActorMetadata describes a registered Dapr Actor.
*/
public final class ActorMetadata {
private final String type;
private final int count;

/**
* Constructor for a ActorMetadata.
*
* @param type of the actor
* @param count number of actors of a particular type
*/
public ActorMetadata(String type, int count) {
this.type = type;
this.count = count;
}

public String getType() {
return type;
}

public int getCount() {
return count;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

package io.dapr.client.domain;

/**
* AppConnectionPropertiesHealthMetadata describes the application health properties.
*/
public final class AppConnectionPropertiesHealthMetadata {

private final String healthCheckPath;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

package io.dapr.client.domain;

/**
* AppConnectionPropertiesMetadata describes the application connection properties.
*/
public final class AppConnectionPropertiesMetadata {

private final int port;
Expand Down
20 changes: 14 additions & 6 deletions sdk/src/main/java/io/dapr/client/domain/ComponentMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,32 @@

package io.dapr.client.domain;

import java.util.Objects;
import java.util.Collections;
import java.util.List;

/**
* ComponentMetadata describes a Dapr Component.
*/
public final class ComponentMetadata {

private String name;
private String type;
private String version;
private final String name;
private final String type;
private final String version;
private final List<String> capabilities;

/**
* Constructor for a ComponentMetadata.
*
* @param name of the component
* @param type component type
* @param version version of the component
* @param capabilities capabilities of the component
*/
public ComponentMetadata(String name, String type, String version) {
public ComponentMetadata(String name, String type, String version, List<String> capabilities) {
this.name = name;
this.type = type;
this.version = version;
this.capabilities = capabilities == null ? Collections.emptyList() : Collections.unmodifiableList(capabilities);
}

public String getName() {
Expand All @@ -48,5 +52,9 @@ public String getType() {
public String getVersion() {
return version;
}


public List<String> getCapabilities() {
return capabilities;
}

}
11 changes: 9 additions & 2 deletions sdk/src/main/java/io/dapr/client/domain/DaprMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public final class DaprMetadata {
private final String id;
private final String runtimeVersion;
private final List<String> enabledFeatures;
private final List<ActorMetadata> actors;
private final Map<String, String> attributes;
private final List<ComponentMetadata> components;
private final List<HttpEndpointMetadata> httpEndpoints;
Expand All @@ -37,19 +38,21 @@ public final class DaprMetadata {
* @param id of the application
* @param runtimeVersion Dapr version
* @param enabledFeatures list of enabled features
* @param actors list of registered features
* @param attributes map of extended attributes
* @param components list of registered components
* @param httpEndpoints list of registered http endpoints
* @param subscriptions list of registered subscription
* @param appConnectionProperties connection properties of the application
*/
public DaprMetadata(String id, String runtimeVersion, List<String> enabledFeatures, Map<String, String> attributes,
List<ComponentMetadata> components, List<HttpEndpointMetadata> httpEndpoints,
public DaprMetadata(String id, String runtimeVersion, List<String> enabledFeatures, List<ActorMetadata> actors,
Map<String, String> attributes, List<ComponentMetadata> components, List<HttpEndpointMetadata> httpEndpoints,
List<SubscriptionMetadata> subscriptions, AppConnectionPropertiesMetadata appConnectionProperties) {
this.id = id;
this.runtimeVersion = runtimeVersion;
this.enabledFeatures = enabledFeatures == null ? Collections.emptyList() :
Collections.unmodifiableList(enabledFeatures);
this.actors = actors == null ? Collections.emptyList() : Collections.unmodifiableList(actors);
this.attributes = attributes == null ? Collections.emptyMap() : Collections.unmodifiableMap(attributes);
this.components = components == null ? Collections.emptyList() : Collections.unmodifiableList(components);
this.httpEndpoints = httpEndpoints == null ? Collections.emptyList() : Collections.unmodifiableList(httpEndpoints);
Expand All @@ -69,6 +72,10 @@ public List<String> getEnabledFeatures() {
return enabledFeatures;
}

public List<ActorMetadata> getActors() {
return actors;
}

public Map<String, String> getAttributes() {
return attributes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@

package io.dapr.client.domain;

/**
* HttpEndpointMetadata describes a registered Dapr HTTP endpoint.
*/
public final class HttpEndpointMetadata {

private final String name;
Expand Down
17 changes: 15 additions & 2 deletions sdk/src/main/java/io/dapr/client/domain/RuleMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,25 @@
* RuleMetadata describes the Subscription Rule's Metadata.
*/
public final class RuleMetadata {
private String path;

public RuleMetadata(String path) {
private final String match;
private final String path;

/**
* Constructor for a RuleMetadata.
*
* @param match CEL expression to match the message
* @param path path to route the message
*/
public RuleMetadata(String match, String path) {
this.match = match;
this.path = path;
}

public String getMatch() {
return match;
}

public String getPath() {
return path;
}
Expand Down
41 changes: 24 additions & 17 deletions sdk/src/main/java/io/dapr/client/domain/SubscriptionMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,55 @@

import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Map;

/**
* SubscriptionMetadata describes the Subscription Metadata.
*/
public final class SubscriptionMetadata {
private String topic;
private String pubsubname;
private String deadLetterTopic;
private List<RuleMetadata> rules;

private final String pubsubname;
private final String topic;
private final Map<String, String> metadata;
private final List<RuleMetadata> rules;
private final String deadLetterTopic;

/**
* Constructor for a SubscriptionMetadata.
*
* @param topic of the pubsub component
* @param pubsubname component name
* @param deadLetterTopic dead letter topic
* @param topic of the pubsub component
* @param metadata of the pubsub component
* @param rules subscription path rules
* @param deadLetterTopic dead letter topic
*/
public SubscriptionMetadata(String topic, String pubsubname, String deadLetterTopic, List<RuleMetadata> rules) {
this.topic = topic;
public SubscriptionMetadata(String pubsubname, String topic, Map<String, String> metadata, List<RuleMetadata> rules,
String deadLetterTopic) {
this.pubsubname = pubsubname;
this.deadLetterTopic = deadLetterTopic;
this.topic = topic;
this.metadata = metadata == null ? Collections.emptyMap() : Collections.unmodifiableMap(metadata);
this.rules = rules == null ? Collections.emptyList() : Collections.unmodifiableList(rules);
}

public String getTopic() {
return topic;
this.deadLetterTopic = deadLetterTopic;
}

public String getPubsubname() {
return pubsubname;
}


public String getDeadLetterTopic() {
return deadLetterTopic;
public String getTopic() {
return topic;
}

public Map<String, String> getMetadata() {
return metadata;
}

public List<RuleMetadata> getRules() {
return rules;
}

public String getDeadLetterTopic() {
return deadLetterTopic;
}

}
Loading

0 comments on commit 64f291f

Please sign in to comment.