Search in sources :

Example 11 with ClusterSetup

use of org.apache.helix.tools.ClusterSetup in project helix by apache.

the class ControllerResource method post.

/**
 * Enable/disable Helix controller
 * <p>
 * Usage:
 * <code>curl -d 'jsonParameters={"command":"enableCluster","enabled":"{true/false}"}'
 * -H "Content-Type: application/json" http://{host:port}/clusters/{cluster}/Controller
 */
@Override
public Representation post(Representation entity) {
    try {
        String clusterName = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.CLUSTER_NAME);
        ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
        ClusterSetup setupTool = new ClusterSetup(zkClient);
        JsonParameters jsonParameters = new JsonParameters(entity);
        String command = jsonParameters.getCommand();
        if (command == null) {
            throw new HelixException("Could NOT find 'command' in parameterMap: " + jsonParameters._parameterMap);
        } else if (command.equalsIgnoreCase(ClusterSetup.enableCluster)) {
            boolean enabled = Boolean.parseBoolean(jsonParameters.getParameter(JsonParameters.ENABLED));
            setupTool.getClusterManagementTool().enableCluster(clusterName, enabled);
        } else {
            throw new HelixException("Unsupported command: " + command + ". Should be one of [" + ClusterSetup.enableCluster + "]");
        }
        getResponse().setEntity(getControllerRepresentation(clusterName));
        getResponse().setStatus(Status.SUCCESS_OK);
    } catch (Exception e) {
        getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e), MediaType.APPLICATION_JSON);
        getResponse().setStatus(Status.SUCCESS_OK);
    }
    return null;
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) HelixException(org.apache.helix.HelixException) ClusterSetup(org.apache.helix.tools.ClusterSetup) HelixException(org.apache.helix.HelixException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException)

Example 12 with ClusterSetup

use of org.apache.helix.tools.ClusterSetup in project helix by apache.

the class ResourceGroupResource method post.

@Override
public Representation post(Representation entity) {
    try {
        String clusterName = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.CLUSTER_NAME);
        String resourceName = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.RESOURCE_NAME);
        ZkClient zkclient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
        ClusterSetup setupTool = new ClusterSetup(zkclient);
        JsonParameters jsonParameters = new JsonParameters(entity);
        String command = jsonParameters.getCommand();
        if (command.equalsIgnoreCase(ClusterSetup.resetResource)) {
            setupTool.getClusterManagementTool().resetResource(clusterName, Arrays.asList(resourceName));
        } else if (command.equalsIgnoreCase(ClusterSetup.enableResource)) {
            jsonParameters.verifyCommand(ClusterSetup.enableResource);
            boolean enabled = Boolean.parseBoolean(jsonParameters.getParameter(JsonParameters.ENABLED));
            setupTool.getClusterManagementTool().enableResource(clusterName, resourceName, enabled);
        } else {
            throw new HelixException("Unsupported command: " + command + ". Should be one of [" + ClusterSetup.resetResource + "]");
        }
    } catch (Exception e) {
        getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e), MediaType.APPLICATION_JSON);
        getResponse().setStatus(Status.SUCCESS_OK);
        LOG.error("", e);
    }
    return null;
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) HelixException(org.apache.helix.HelixException) ClusterSetup(org.apache.helix.tools.ClusterSetup) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) HelixException(org.apache.helix.HelixException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException)

Example 13 with ClusterSetup

use of org.apache.helix.tools.ClusterSetup in project helix by apache.

the class ResourceGroupsResource method post.

@Override
public Representation post(Representation entity) {
    try {
        String clusterName = ResourceUtil.getAttributeFromRequest(getRequest(), ResourceUtil.RequestKey.CLUSTER_NAME);
        JsonParameters jsonParameters = new JsonParameters(entity);
        String command = jsonParameters.getCommand();
        if (command.equalsIgnoreCase(ClusterSetup.addResource) || JsonParameters.CLUSTERSETUP_COMMAND_ALIASES.get(ClusterSetup.addResource).contains(command)) {
            jsonParameters.verifyCommand(ClusterSetup.addResource);
            String entityName = jsonParameters.getParameter(JsonParameters.RESOURCE_GROUP_NAME);
            String stateModelDefRef = jsonParameters.getParameter(JsonParameters.STATE_MODEL_DEF_REF);
            int partitions = Integer.parseInt(jsonParameters.getParameter(JsonParameters.PARTITIONS));
            String mode = RebalanceMode.SEMI_AUTO.toString();
            if (jsonParameters.getParameter(JsonParameters.IDEAL_STATE_MODE) != null) {
                mode = jsonParameters.getParameter(JsonParameters.IDEAL_STATE_MODE);
            }
            int bucketSize = 0;
            if (jsonParameters.getParameter(JsonParameters.BUCKET_SIZE) != null) {
                try {
                    bucketSize = Integer.parseInt(jsonParameters.getParameter(JsonParameters.BUCKET_SIZE));
                } catch (Exception e) {
                }
            }
            int maxPartitionsPerNode = -1;
            if (jsonParameters.getParameter(JsonParameters.MAX_PARTITIONS_PER_NODE) != null) {
                try {
                    maxPartitionsPerNode = Integer.parseInt(jsonParameters.getParameter(JsonParameters.MAX_PARTITIONS_PER_NODE));
                } catch (Exception e) {
                }
            }
            ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
            ClusterSetup setupTool = new ClusterSetup(zkClient);
            setupTool.addResourceToCluster(clusterName, entityName, partitions, stateModelDefRef, mode, bucketSize, maxPartitionsPerNode);
        } else {
            throw new HelixException("Unsupported command: " + command + ". Should be one of [" + ClusterSetup.addResource + "]");
        }
        getResponse().setEntity(getHostedEntitiesRepresentation(clusterName));
        getResponse().setStatus(Status.SUCCESS_OK);
    } catch (Exception e) {
        getResponse().setEntity(ClusterRepresentationUtil.getErrorAsJsonStringFromException(e), MediaType.APPLICATION_JSON);
        getResponse().setStatus(Status.SUCCESS_OK);
        LOG.error("Error in posting " + entity, e);
    }
    return null;
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) HelixException(org.apache.helix.HelixException) ClusterSetup(org.apache.helix.tools.ClusterSetup) IOException(java.io.IOException) JsonGenerationException(org.codehaus.jackson.JsonGenerationException) HelixException(org.apache.helix.HelixException) JsonMappingException(org.codehaus.jackson.map.JsonMappingException)

Example 14 with ClusterSetup

use of org.apache.helix.tools.ClusterSetup in project helix by apache.

the class SchedulerTasksResource method getSchedulerTasksRepresentation.

StringRepresentation getSchedulerTasksRepresentation() throws JsonGenerationException, JsonMappingException, IOException {
    String clusterName = (String) getRequest().getAttributes().get("clusterName");
    String instanceName = (String) getRequest().getAttributes().get("instanceName");
    ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
    ClusterSetup setupTool = new ClusterSetup(zkClient);
    List<String> instances = setupTool.getClusterManagementTool().getInstancesInCluster(clusterName);
    HelixDataAccessor accessor = ClusterRepresentationUtil.getClusterDataAccessor(zkClient, clusterName);
    LiveInstance liveInstance = accessor.getProperty(accessor.keyBuilder().liveInstance(instanceName));
    String sessionId = liveInstance.getSessionId();
    // (ClusterRepresentationUtil.ObjectToJson(instanceConfigs),
    StringRepresentation representation = new StringRepresentation("");
    return representation;
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) HelixDataAccessor(org.apache.helix.HelixDataAccessor) LiveInstance(org.apache.helix.model.LiveInstance) StringRepresentation(org.restlet.representation.StringRepresentation) ClusterSetup(org.apache.helix.tools.ClusterSetup)

Example 15 with ClusterSetup

use of org.apache.helix.tools.ClusterSetup in project helix by apache.

the class AbstractTestClass method beforeSuite.

@BeforeSuite
public void beforeSuite() throws Exception {
    if (!_init) {
        // TODO: use logging.properties file to config java.util.logging.Logger levels
        java.util.logging.Logger topJavaLogger = java.util.logging.Logger.getLogger("");
        topJavaLogger.setLevel(Level.WARNING);
        _gZkClient = new ZkClient(ZK_ADDR, ZkClient.DEFAULT_CONNECTION_TIMEOUT, ZkClient.DEFAULT_SESSION_TIMEOUT, new ZNRecordSerializer());
        _gZkClientTestNS = new ZkClient(_zkAddrTestNS, ZkClient.DEFAULT_CONNECTION_TIMEOUT, ZkClient.DEFAULT_SESSION_TIMEOUT, new ZNRecordSerializer());
        _gSetupTool = new ClusterSetup(_gZkClient);
        _configAccessor = new ConfigAccessor(_gZkClient);
        _baseAccessor = new ZkBaseDataAccessor<>(_gZkClient);
        _baseAccessorTestNS = new ZkBaseDataAccessor<>(_gZkClientTestNS);
        // wait for the web service to start
        Thread.sleep(100);
        setup();
        _init = true;
    }
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) ConfigAccessor(org.apache.helix.ConfigAccessor) ClusterSetup(org.apache.helix.tools.ClusterSetup) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer) BeforeSuite(org.testng.annotations.BeforeSuite)

Aggregations

ClusterSetup (org.apache.helix.tools.ClusterSetup)79 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)33 BeforeClass (org.testng.annotations.BeforeClass)33 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)28 ZkClient (org.apache.helix.manager.zk.ZkClient)26 Date (java.util.Date)23 IOException (java.io.IOException)14 HelixException (org.apache.helix.HelixException)14 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)11 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)11 Test (org.testng.annotations.Test)11 ConfigAccessor (org.apache.helix.ConfigAccessor)9 ZNRecord (org.apache.helix.ZNRecord)9 HelixDataAccessor (org.apache.helix.HelixDataAccessor)8 IdealState (org.apache.helix.model.IdealState)8 BestPossAndExtViewZkVerifier (org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier)7 HelixAdmin (org.apache.helix.HelixAdmin)6 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)6 StringRepresentation (org.restlet.representation.StringRepresentation)6 ClusterDistributedController (org.apache.helix.integration.manager.ClusterDistributedController)5