use of org.apache.helix.HelixAdmin in project helix by apache.
the class InstanceAccessor method addInstance.
@PUT
@Path("{instanceName}")
public Response addInstance(@PathParam("clusterId") String clusterId, @PathParam("instanceName") String instanceName, String content) {
HelixAdmin admin = getHelixAdmin();
ZNRecord record;
try {
record = toZNRecord(content);
} catch (IOException e) {
_logger.error("Failed to deserialize user's input " + content + ", Exception: " + e);
return badRequest("Input is not a vaild ZNRecord!");
}
try {
admin.addInstance(clusterId, new InstanceConfig(record));
} catch (Exception ex) {
_logger.error("Error in adding an instance: " + instanceName, ex);
return serverError(ex);
}
return OK();
}
use of org.apache.helix.HelixAdmin in project helix by apache.
the class InstanceAccessor method updateInstanceConfig.
@PUT
@Path("{instanceName}/configs")
public Response updateInstanceConfig(@PathParam("clusterId") String clusterId, @PathParam("instanceName") String instanceName, String content) throws IOException {
HelixAdmin admin = getHelixAdmin();
ZNRecord record;
try {
record = toZNRecord(content);
} catch (IOException e) {
_logger.error("Failed to deserialize user's input " + content + ", Exception: " + e);
return badRequest("Input is not a vaild ZNRecord!");
}
try {
admin.setInstanceConfig(clusterId, instanceName, new InstanceConfig(record));
} catch (Exception ex) {
_logger.error("Error in update instance config: " + instanceName, ex);
return serverError(ex);
}
return OK();
}
use of org.apache.helix.HelixAdmin in project helix by apache.
the class TestHelixAdminScenariosRest method testGetResources.
@Test
public void testGetResources() throws IOException {
final String clusterName = "TestTagAwareness_testGetResources";
final String TAG = "tag";
final String URL_BASE = "http://localhost:" + ADMIN_PORT + "/clusters/" + clusterName + "/resourceGroups";
_gSetupTool.addCluster(clusterName, true);
HelixAdmin admin = _gSetupTool.getClusterManagementTool();
// Add a tagged resource
IdealState taggedResource = new IdealState("taggedResource");
taggedResource.setInstanceGroupTag(TAG);
taggedResource.setStateModelDefRef("OnlineOffline");
admin.addResource(clusterName, taggedResource.getId(), taggedResource);
// Add an untagged resource
IdealState untaggedResource = new IdealState("untaggedResource");
untaggedResource.setStateModelDefRef("OnlineOffline");
admin.addResource(clusterName, untaggedResource.getId(), untaggedResource);
// Now make a REST call for all resources
Reference resourceRef = new Reference(URL_BASE);
Request request = new Request(Method.GET, resourceRef);
Response response = _gClient.handle(request);
ZNRecord responseRecord = ClusterRepresentationUtil.JsonToObject(ZNRecord.class, response.getEntityAsText());
// Ensure that the tagged resource has information and the untagged one doesn't
Assert.assertNotNull(responseRecord.getMapField("ResourceTags"));
Assert.assertEquals(TAG, responseRecord.getMapField("ResourceTags").get(taggedResource.getId()));
Assert.assertFalse(responseRecord.getMapField("ResourceTags").containsKey(untaggedResource.getId()));
}
use of org.apache.helix.HelixAdmin in project helix by apache.
the class ConfigResource method getConfigKeys.
StringRepresentation getConfigKeys(ConfigScopeProperty scopeProperty, String... keys) throws Exception {
StringRepresentation representation = null;
ZkClient zkClient = ResourceUtil.getAttributeFromCtx(getContext(), ResourceUtil.ContextKey.ZKCLIENT);
ClusterSetup setupTool = new ClusterSetup(zkClient);
HelixAdmin admin = setupTool.getClusterManagementTool();
ZNRecord record = new ZNRecord(scopeProperty + " Config");
HelixConfigScope scope = new HelixConfigScopeBuilder(scopeProperty, keys).build();
List<String> configKeys = admin.getConfigKeys(scope);
record.setListField(scopeProperty.toString(), configKeys);
representation = new StringRepresentation(ClusterRepresentationUtil.ZNRecordToJson(record), MediaType.APPLICATION_JSON);
return representation;
}
use of org.apache.helix.HelixAdmin in project helix by apache.
the class Task method getExternalViews.
private List<ExternalView> getExternalViews() {
String clusterName = helixManager.getClusterName();
List<ExternalView> externalViewList = new ArrayList<ExternalView>();
HelixAdmin helixAdmin = helixManager.getClusterManagmentTool();
List<String> resourcesInCluster = helixAdmin.getResourcesInCluster(clusterName);
for (String resourceName : resourcesInCluster) {
ExternalView ev = helixManager.getClusterManagmentTool().getResourceExternalView(clusterName, resourceName);
if (ev != null) {
externalViewList.add(ev);
}
}
return externalViewList;
}
Aggregations