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;
}
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;
}
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);
}
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);
}
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;
}
Aggregations