use of org.apache.helix.rest.server.filters.NamespaceAuth in project helix by apache.
the class ClusterAccessor method createCluster.
@NamespaceAuth
@ResponseMetered(name = HttpConstants.WRITE_REQUEST)
@Timed(name = HttpConstants.WRITE_REQUEST)
@PUT
@Path("{clusterId}")
public Response createCluster(@PathParam("clusterId") String clusterId, @DefaultValue("false") @QueryParam("recreate") String recreate, @DefaultValue("false") @QueryParam("addCloudConfig") String addCloudConfig, String cloudConfigManifest) {
boolean recreateIfExists = Boolean.parseBoolean(recreate);
boolean cloudConfigIncluded = Boolean.parseBoolean(addCloudConfig);
ClusterSetup clusterSetup = getClusterSetup();
CloudConfig cloudConfig = null;
if (cloudConfigIncluded) {
ZNRecord record;
try {
record = toZNRecord(cloudConfigManifest);
cloudConfig = new CloudConfig.Builder(record).build();
} catch (IOException | HelixException e) {
String errMsg = "Failed to generate a valid CloudConfig from " + cloudConfigManifest;
LOG.error(errMsg, e);
return badRequest(errMsg + " Exception: " + e.getMessage());
}
}
try {
clusterSetup.addCluster(clusterId, recreateIfExists, cloudConfig);
} catch (Exception ex) {
LOG.error("Failed to create cluster {}. Exception: {}.", clusterId, ex);
return serverError(ex);
}
return created();
}
use of org.apache.helix.rest.server.filters.NamespaceAuth in project helix by apache.
the class ClusterAccessor method getClusters.
@NamespaceAuth
@ResponseMetered(name = HttpConstants.READ_REQUEST)
@Timed(name = HttpConstants.READ_REQUEST)
@GET
public Response getClusters() {
HelixAdmin helixAdmin = getHelixAdmin();
List<String> clusters = helixAdmin.getClusters();
Map<String, List<String>> dataMap = new HashMap<>();
dataMap.put(ClusterProperties.clusters.name(), clusters);
return JSONRepresentation(dataMap);
}
Aggregations