Search in sources :

Example 81 with ZkClient

use of org.apache.helix.manager.zk.ZkClient in project helix by apache.

the class ZkPathResource method delete.

@Override
public Representation delete() {
    String zkPath = getZKPath();
    try {
        ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
        zkClient.deleteRecursively(zkPath);
        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 delete zkPath: " + zkPath, e);
    }
    return null;
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) HelixException(org.apache.helix.HelixException)

Example 82 with ZkClient

use of org.apache.helix.manager.zk.ZkClient in project helix by apache.

the class ZkPathResource method post.

@Override
public Representation post(Representation entity) {
    String zkPath = getZKPath();
    try {
        JsonParameters jsonParameters = new JsonParameters(entity);
        String command = jsonParameters.getCommand();
        ZkClient zkClient = (ZkClient) getContext().getAttributes().get(RestAdminApplication.ZKCLIENT);
        if (command.equalsIgnoreCase(JsonParameters.ZK_DELETE_CHILDREN)) {
            List<String> childNames = zkClient.getChildren(zkPath);
            if (childNames != null) {
                for (String childName : childNames) {
                    String childPath = zkPath.equals("/") ? "/" + childName : zkPath + "/" + childName;
                    zkClient.deleteRecursively(childPath);
                }
            }
        } else {
            throw new HelixException("Unsupported command: " + command + ". Should be one of [" + JsonParameters.ZK_DELETE_CHILDREN + "]");
        }
        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 post zkPath: " + zkPath, e);
    }
    return null;
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) HelixException(org.apache.helix.HelixException) HelixException(org.apache.helix.HelixException)

Example 83 with ZkClient

use of org.apache.helix.manager.zk.ZkClient in project helix by apache.

the class AdminTestBase method beforeSuite.

@BeforeSuite
public void beforeSuite() throws Exception {
    // 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);
    // start zk
    _zkServer = TestHelper.startZkServer(ZK_ADDR);
    AssertJUnit.assertTrue(_zkServer != null);
    ZKClientPool.reset();
    _gZkClient = new ZkClient(ZK_ADDR, ZkClient.DEFAULT_CONNECTION_TIMEOUT, ZkClient.DEFAULT_SESSION_TIMEOUT, new ZNRecordSerializer());
    _gSetupTool = new ClusterSetup(_gZkClient);
    // start admin
    _adminThread = new AdminThread(ZK_ADDR, ADMIN_PORT);
    _adminThread.start();
    // create a client
    _gClient = new Client(Protocol.HTTP);
    // wait for the web service to start
    Thread.sleep(100);
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) AdminThread(org.apache.helix.webapp.AdminTestHelper.AdminThread) ClusterSetup(org.apache.helix.tools.ClusterSetup) ZkClient(org.apache.helix.manager.zk.ZkClient) Client(org.restlet.Client) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer) BeforeSuite(org.testng.annotations.BeforeSuite)

Example 84 with ZkClient

use of org.apache.helix.manager.zk.ZkClient in project helix by apache.

the class HelixAdminWebApp method start.

public synchronized void start() throws Exception {
    LOG.info("helixAdminWebApp starting");
    if (_component == null) {
        _zkClient = new ZkClient(_zkServerAddress, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ZNRecordSerializer());
        _rawZkClient = new ZkClient(_zkServerAddress, ZkClient.DEFAULT_SESSION_TIMEOUT, ZkClient.DEFAULT_CONNECTION_TIMEOUT, new ByteArraySerializer());
        _component = new Component();
        _component.getServers().add(Protocol.HTTP, _helixAdminPort);
        Context applicationContext = _component.getContext().createChildContext();
        applicationContext.getAttributes().put(RestAdminApplication.ZKSERVERADDRESS, _zkServerAddress);
        applicationContext.getAttributes().put(RestAdminApplication.PORT, "" + _helixAdminPort);
        applicationContext.getAttributes().put(RestAdminApplication.ZKCLIENT, _zkClient);
        applicationContext.getAttributes().put(ResourceUtil.ContextKey.RAW_ZKCLIENT.toString(), _rawZkClient);
        _adminApp = new RestAdminApplication(applicationContext);
        // Attach the application to the component and start it
        _component.getDefaultHost().attach(_adminApp);
        _component.start();
    }
    LOG.info("helixAdminWebApp started on port: " + _helixAdminPort);
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) Context(org.restlet.Context) Component(org.restlet.Component) ByteArraySerializer(org.apache.helix.manager.zk.ByteArraySerializer) ZNRecordSerializer(org.apache.helix.manager.zk.ZNRecordSerializer)

Example 85 with ZkClient

use of org.apache.helix.manager.zk.ZkClient in project helix by apache.

the class ClusterResource method getClusterRepresentation.

StringRepresentation getClusterRepresentation(String clusterName) throws JsonGenerationException, JsonMappingException, IOException {
    ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
    ClusterSetup setupTool = new ClusterSetup(zkClient);
    List<String> instances = setupTool.getClusterManagementTool().getInstancesInCluster(clusterName);
    ZNRecord clusterSummayRecord = new ZNRecord("Cluster Summary");
    clusterSummayRecord.setListField("participants", instances);
    List<String> resources = setupTool.getClusterManagementTool().getResourcesInCluster(clusterName);
    clusterSummayRecord.setListField("resources", resources);
    List<String> models = setupTool.getClusterManagementTool().getStateModelDefs(clusterName);
    clusterSummayRecord.setListField("stateModelDefs", models);
    HelixDataAccessor accessor = ClusterRepresentationUtil.getClusterDataAccessor(zkClient, clusterName);
    Builder keyBuilder = accessor.keyBuilder();
    LiveInstance leader = accessor.getProperty(keyBuilder.controllerLeader());
    if (leader != null) {
        clusterSummayRecord.setSimpleField("LEADER", leader.getInstanceName());
    } else {
        clusterSummayRecord.setSimpleField("LEADER", "");
    }
    StringRepresentation representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(clusterSummayRecord), MediaType.APPLICATION_JSON);
    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) Builder(org.apache.helix.PropertyKey.Builder) ClusterSetup(org.apache.helix.tools.ClusterSetup) ZNRecord(org.apache.helix.ZNRecord)

Aggregations

ZkClient (org.apache.helix.manager.zk.ZkClient)109 ZNRecordSerializer (org.apache.helix.manager.zk.ZNRecordSerializer)39 ZNRecord (org.apache.helix.ZNRecord)29 StringRepresentation (org.restlet.representation.StringRepresentation)29 ClusterSetup (org.apache.helix.tools.ClusterSetup)26 HelixException (org.apache.helix.HelixException)23 Builder (org.apache.helix.PropertyKey.Builder)18 IOException (java.io.IOException)17 HelixDataAccessor (org.apache.helix.HelixDataAccessor)15 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)15 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)15 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)12 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)10 Test (org.testng.annotations.Test)10 Date (java.util.Date)9 BeforeClass (org.testng.annotations.BeforeClass)9 PropertyKey (org.apache.helix.PropertyKey)8 IdealState (org.apache.helix.model.IdealState)8 InstanceConfig (org.apache.helix.model.InstanceConfig)8 StateModelDefinition (org.apache.helix.model.StateModelDefinition)7