}
@Override
public Representation represent(Variant variant)
{
StringRepresentation representation = null;
String clusterName = getValue("clusterName");
String scopeStr = getValue("scope");
try
{
if (scopeStr == null)
{
// path is "/clusters/{clusterName}/configs"
return getConfigScopes();
}
scopeStr = scopeStr.toUpperCase();
ConfigScopeProperty scopeProperty = ConfigScopeProperty.valueOf(scopeStr);
switch (scopeProperty)
{
case CLUSTER:
case PARTICIPANT:
case RESOURCE:
String scopeKey1 = getValue("scopeKey1");
if (scopeKey1 == null)
{
// path is "/clusters/{clusterName}/configs/cluster|participant|resource"
representation = getConfigKeys(scopeProperty);
}
else
{
// path is "/clusters/{clusterName}/configs/cluster|particicpant|resource/
// {clusterName}|{participantName}|{resourceName}"
ConfigScope scope;
if (scopeProperty == ConfigScopeProperty.CLUSTER)
{
scope = new ConfigScopeBuilder().build(scopeProperty, clusterName);
}
else
{
scope = new ConfigScopeBuilder().build(scopeProperty, clusterName, scopeKey1);
}
representation = getConfigs(scope, scopeProperty, scopeKey1);
}
break;
case PARTITION:
scopeKey1 = getValue("scopeKey1");
String scopeKey2 = getValue("scopeKey2");
if (scopeKey1 == null)
{
// path is "/clusters/{clusterName}/configs/partition"
throw new HelixException("Missing resourceName");
}
else if (scopeKey2 == null)
{
// path is "/clusters/{clusterName}/configs/partition/resourceName"
representation = getConfigKeys(scopeProperty, scopeKey1);
}
else
{
// path is
// "/clusters/{clusterName}/configs/partition/resourceName/partitionName"
ConfigScope scope =
new ConfigScopeBuilder().build(scopeProperty,
clusterName,
scopeKey1,
scopeKey2);
representation = getConfigs(scope, scopeProperty, scopeKey1, scopeKey2);
}
break;
default:
break;
}
}
catch (Exception e)
{
String error = ClusterRepresentationUtil.getErrorAsJsonStringFromException(e);
representation = new StringRepresentation(error, MediaType.APPLICATION_JSON);
LOG.error("", e);
}
return representation;
}