Search in sources :

Example 1 with NamespaceAuth

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();
}
Also used : HelixException(org.apache.helix.HelixException) HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) PropertyPathBuilder(org.apache.helix.PropertyPathBuilder) CloudConfig(org.apache.helix.model.CloudConfig) IOException(java.io.IOException) ClusterSetup(org.apache.helix.tools.ClusterSetup) 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) Path(javax.ws.rs.Path) NamespaceAuth(org.apache.helix.rest.server.filters.NamespaceAuth) ResponseMetered(com.codahale.metrics.annotation.ResponseMetered) Timed(com.codahale.metrics.annotation.Timed) PUT(javax.ws.rs.PUT)

Example 2 with NamespaceAuth

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

Aggregations

ResponseMetered (com.codahale.metrics.annotation.ResponseMetered)2 Timed (com.codahale.metrics.annotation.Timed)2 NamespaceAuth (org.apache.helix.rest.server.filters.NamespaceAuth)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 IOException (java.io.IOException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 GET (javax.ws.rs.GET)1 PUT (javax.ws.rs.PUT)1 Path (javax.ws.rs.Path)1 HelixAdmin (org.apache.helix.HelixAdmin)1 HelixException (org.apache.helix.HelixException)1 PropertyPathBuilder (org.apache.helix.PropertyPathBuilder)1 HelixConflictException (org.apache.helix.api.exceptions.HelixConflictException)1 CloudConfig (org.apache.helix.model.CloudConfig)1 HelixConfigScopeBuilder (org.apache.helix.model.builder.HelixConfigScopeBuilder)1 ClusterSetup (org.apache.helix.tools.ClusterSetup)1 ZNRecord (org.apache.helix.zookeeper.datamodel.ZNRecord)1