use of org.apache.helix.rest.server.filters.ClusterAuth in project helix by apache.
the class ClusterAccessor method getCustomizedStateConfig.
@ClusterAuth
@ResponseMetered(name = HttpConstants.READ_REQUEST)
@Timed(name = HttpConstants.READ_REQUEST)
@GET
@Path("{clusterId}/customized-state-config")
public Response getCustomizedStateConfig(@PathParam("clusterId") String clusterId) {
if (!doesClusterExist(clusterId)) {
return notFound(String.format("Cluster %s does not exist", clusterId));
}
ConfigAccessor configAccessor = getConfigAccessor();
CustomizedStateConfig customizedStateConfig = configAccessor.getCustomizedStateConfig(clusterId);
if (customizedStateConfig != null) {
return JSONRepresentation(customizedStateConfig.getRecord());
}
return notFound();
}
use of org.apache.helix.rest.server.filters.ClusterAuth in project helix by apache.
the class ClusterAccessor method setClusterStateModelDefinition.
@ClusterAuth
@ResponseMetered(name = HttpConstants.WRITE_REQUEST)
@Timed(name = HttpConstants.WRITE_REQUEST)
@POST
@Path("{clusterId}/statemodeldefs/{statemodel}")
public Response setClusterStateModelDefinition(@PathParam("clusterId") String clusterId, @PathParam("statemodel") String statemodel, String content) {
ZNRecord record;
try {
record = toZNRecord(content);
} catch (IOException e) {
LOG.error("Failed to deserialize user's input {}. Exception: {}.", content, e);
return badRequest("Input is not a valid ZNRecord!");
}
StateModelDefinition stateModelDefinition = new StateModelDefinition(record);
HelixDataAccessor dataAccessor = getDataAccssor(clusterId);
PropertyKey key = dataAccessor.keyBuilder().stateModelDef(stateModelDefinition.getId());
boolean retcode = true;
try {
retcode = dataAccessor.setProperty(key, stateModelDefinition);
} catch (Exception e) {
LOG.error("Failed to set StateModelDefinition key: {}. Exception: {}.", key, e);
return badRequest("Failed to set the content " + content);
}
return OK();
}
use of org.apache.helix.rest.server.filters.ClusterAuth in project helix by apache.
the class ClusterAccessor method createClusterStateModelDefinition.
@ClusterAuth
@ResponseMetered(name = HttpConstants.WRITE_REQUEST)
@Timed(name = HttpConstants.WRITE_REQUEST)
@PUT
@Path("{clusterId}/statemodeldefs/{statemodel}")
public Response createClusterStateModelDefinition(@PathParam("clusterId") String clusterId, @PathParam("statemodel") String statemodel, String content) {
ZNRecord record;
try {
record = toZNRecord(content);
} catch (IOException e) {
LOG.error("Failed to deserialize user's input {}. Exception: {}.", content, e);
return badRequest("Input is not a valid ZNRecord!");
}
RealmAwareZkClient zkClient = getRealmAwareZkClient();
String path = PropertyPathBuilder.stateModelDef(clusterId);
try {
ZKUtil.createChildren(zkClient, path, record);
} catch (Exception e) {
LOG.error("Failed to create zk node with path {}. Exception: {}", path, e);
return badRequest("Failed to create a Znode for stateModel! " + e);
}
return OK();
}
use of org.apache.helix.rest.server.filters.ClusterAuth in project helix by apache.
the class ClusterAccessor method createRESTConfig.
@ClusterAuth
@ResponseMetered(name = HttpConstants.WRITE_REQUEST)
@Timed(name = HttpConstants.WRITE_REQUEST)
@PUT
@Path("{clusterId}/restconfig")
public Response createRESTConfig(@PathParam("clusterId") String clusterId, String content) {
ZNRecord record;
try {
record = toZNRecord(content);
} catch (IOException e) {
LOG.error("Failed to deserialize user's input {}. Exception: {}.", content, e);
return badRequest("Input is not a valid ZNRecord!");
}
if (!record.getId().equals(clusterId)) {
return badRequest("ID does not match the cluster name in input!");
}
RESTConfig config = new RESTConfig(record);
ConfigAccessor configAccessor = getConfigAccessor();
try {
configAccessor.setRESTConfig(clusterId, config);
} catch (HelixException ex) {
// TODO: Could use a more generic error for HelixException
return notFound(ex.getMessage());
} catch (Exception ex) {
LOG.error("Failed to create rest config, cluster {}, new config: {}. Exception: {}.", clusterId, content, ex);
return serverError(ex);
}
return OK();
}
use of org.apache.helix.rest.server.filters.ClusterAuth in project helix by apache.
the class ClusterAccessor method getClusterManagementMode.
@ClusterAuth
@ResponseMetered(name = HttpConstants.READ_REQUEST)
@Timed(name = HttpConstants.READ_REQUEST)
@GET
@Path("{clusterId}/management-mode")
public Response getClusterManagementMode(@PathParam("clusterId") String clusterId, @QueryParam("showDetails") boolean showDetails) {
ClusterManagementMode mode = getHelixAdmin().getClusterManagementMode(clusterId);
if (mode == null) {
return notFound("Cluster " + clusterId + " is not in management mode");
}
Map<String, Object> responseMap = new HashMap<>();
responseMap.put("cluster", clusterId);
responseMap.put("mode", mode.getMode());
responseMap.put("status", mode.getStatus());
if (showDetails) {
// To show details, query participants that are in progress to management mode.
responseMap.put("details", getManagementModeDetails(clusterId, mode));
}
return JSONRepresentation(responseMap);
}
Aggregations