Added one more Component Config REST API; for specified component and variable.

Change-Id: I810aa90636c55c8b05c146780ad28c307cefff33
This commit is contained in:
psneha 2018-08-02 01:16:46 -04:00 committed by Andrea Campanella
parent 8b03bc583b
commit f31ac6ff9f
6 changed files with 67 additions and 0 deletions

View File

@ -81,5 +81,14 @@ public interface ComponentConfigService {
*/
void unsetProperty(String componentName, String name);
/**
* Returns configuration property of the named components.
*
* @param componentName component name
* @param attribute component attribute
* @return configuration property
*/
ConfigProperty getProperty(String componentName, String attribute);
}

View File

@ -57,4 +57,9 @@ public class ComponentConfigAdapter implements ComponentConfigService {
public void unsetProperty(String componentName, String name) {
}
@Override
public ConfigProperty getProperty(String componentName, String attribute) {
return null;
}
}

View File

@ -195,6 +195,19 @@ public class ComponentConfigManager implements ComponentConfigService {
store.unsetProperty(componentName, name);
}
@Override
public ConfigProperty getProperty(String componentName, String attribute) {
checkPermission(CONFIG_READ);
Map<String, ConfigProperty> map = properties.get(componentName);
if (map != null) {
return map.get(attribute);
} else {
log.error("Attribute {} not present in component {}", attribute, componentName);
return null;
}
}
private class InternalStoreDelegate implements ComponentConfigStoreDelegate {
@Override

View File

@ -276,5 +276,10 @@ public class GossipIntentStoreTest extends AbstractIntentTest {
public void unsetProperty(String componentName, String name) {
}
@Override
public ConfigProperty getProperty(String componentName, String attribute) {
return null;
}
}
}

View File

@ -273,5 +273,10 @@ public class GrpcNbComponentConfigServiceTest {
public void unsetProperty(String componentName, String name) {
STRING_MAP2.remove(componentName + "#" + name);
}
@Override
public ConfigProperty getProperty(String componentName, String attribute) {
return null;
}
}
}

View File

@ -156,4 +156,34 @@ public class ComponentConfigWebResource extends AbstractWebResource {
props.fieldNames().forEachRemaining(k -> service.unsetProperty(component, k));
return Response.noContent().build();
}
/**
* Gets specified value of a specified component and variable.
*
* @param component component name
* @param attribute attribute name
* @return 200 OK with a collection of component configurations
*/
@GET
@Path("{component}/{attribute}")
@Produces(MediaType.APPLICATION_JSON)
public Response getComponentConfig(@PathParam("component") String component,
@PathParam("attribute") String attribute) {
ComponentConfigService service = get(ComponentConfigService.class);
ObjectNode root = mapper().createObjectNode();
encodeConfigs(component, attribute,
nullIsNotFound(service.getProperty(component, attribute),
(service.getProperties(component) == null) ?
"No such component" : (service.getProperty(component, attribute) == null) ?
("No such attribute in " + component) : "No such attribute and component"), root);
return ok(root).build();
}
// Encodes the specified property with attribute as an object in the given node.
private void encodeConfigs(String component, String attribute, ConfigProperty props,
ObjectNode node) {
ObjectNode compNode = mapper().createObjectNode();
node.set(component, compNode);
compNode.put(attribute, props.value());
}
}