Search in sources :

Example 1 with ClusterAuth

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();
}
Also used : CustomizedStateConfig(org.apache.helix.model.CustomizedStateConfig) ConfigAccessor(org.apache.helix.ConfigAccessor) Path(javax.ws.rs.Path) ResponseMetered(com.codahale.metrics.annotation.ResponseMetered) ClusterAuth(org.apache.helix.rest.server.filters.ClusterAuth) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 2 with ClusterAuth

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();
}
Also used : HelixDataAccessor(org.apache.helix.HelixDataAccessor) StateModelDefinition(org.apache.helix.model.StateModelDefinition) IOException(java.io.IOException) ZNRecord(org.apache.helix.zookeeper.datamodel.ZNRecord) PropertyKey(org.apache.helix.PropertyKey) HelixException(org.apache.helix.HelixException) HelixConflictException(org.apache.helix.api.exceptions.HelixConflictException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Path(javax.ws.rs.Path) ResponseMetered(com.codahale.metrics.annotation.ResponseMetered) ClusterAuth(org.apache.helix.rest.server.filters.ClusterAuth) POST(javax.ws.rs.POST) Timed(com.codahale.metrics.annotation.Timed)

Example 3 with ClusterAuth

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();
}
Also used : IOException(java.io.IOException) ZNRecord(org.apache.helix.zookeeper.datamodel.ZNRecord) HelixException(org.apache.helix.HelixException) HelixConflictException(org.apache.helix.api.exceptions.HelixConflictException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) RealmAwareZkClient(org.apache.helix.zookeeper.api.client.RealmAwareZkClient) Path(javax.ws.rs.Path) ResponseMetered(com.codahale.metrics.annotation.ResponseMetered) ClusterAuth(org.apache.helix.rest.server.filters.ClusterAuth) Timed(com.codahale.metrics.annotation.Timed) PUT(javax.ws.rs.PUT)

Example 4 with ClusterAuth

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();
}
Also used : HelixException(org.apache.helix.HelixException) IOException(java.io.IOException) ConfigAccessor(org.apache.helix.ConfigAccessor) ZNRecord(org.apache.helix.zookeeper.datamodel.ZNRecord) HelixException(org.apache.helix.HelixException) HelixConflictException(org.apache.helix.api.exceptions.HelixConflictException) IOException(java.io.IOException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) RESTConfig(org.apache.helix.model.RESTConfig) Path(javax.ws.rs.Path) ResponseMetered(com.codahale.metrics.annotation.ResponseMetered) ClusterAuth(org.apache.helix.rest.server.filters.ClusterAuth) Timed(com.codahale.metrics.annotation.Timed) PUT(javax.ws.rs.PUT)

Example 5 with ClusterAuth

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);
}
Also used : HashMap(java.util.HashMap) ClusterManagementMode(org.apache.helix.api.status.ClusterManagementMode) Path(javax.ws.rs.Path) ResponseMetered(com.codahale.metrics.annotation.ResponseMetered) ClusterAuth(org.apache.helix.rest.server.filters.ClusterAuth) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Aggregations

ResponseMetered (com.codahale.metrics.annotation.ResponseMetered)27 Timed (com.codahale.metrics.annotation.Timed)27 Path (javax.ws.rs.Path)27 ClusterAuth (org.apache.helix.rest.server.filters.ClusterAuth)27 HelixException (org.apache.helix.HelixException)16 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)14 GET (javax.ws.rs.GET)14 HelixConflictException (org.apache.helix.api.exceptions.HelixConflictException)14 IOException (java.io.IOException)13 ConfigAccessor (org.apache.helix.ConfigAccessor)8 HelixDataAccessor (org.apache.helix.HelixDataAccessor)8 ZNRecord (org.apache.helix.zookeeper.datamodel.ZNRecord)8 POST (javax.ws.rs.POST)7 HelixAdmin (org.apache.helix.HelixAdmin)7 HashMap (java.util.HashMap)4 PUT (javax.ws.rs.PUT)4 RealmAwareZkClient (org.apache.helix.zookeeper.api.client.RealmAwareZkClient)4 PropertyKey (org.apache.helix.PropertyKey)3 CloudConfig (org.apache.helix.model.CloudConfig)3 RESTConfig (org.apache.helix.model.RESTConfig)3