Search in sources :

Example 96 with HelixAdmin

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();
}
Also used : InstanceConfig(org.apache.helix.model.InstanceConfig) IOException(java.io.IOException) HelixAdmin(org.apache.helix.HelixAdmin) ZNRecord(org.apache.helix.ZNRecord) HelixException(org.apache.helix.HelixException) IOException(java.io.IOException) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 97 with HelixAdmin

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();
}
Also used : InstanceConfig(org.apache.helix.model.InstanceConfig) IOException(java.io.IOException) HelixAdmin(org.apache.helix.HelixAdmin) ZNRecord(org.apache.helix.ZNRecord) HelixException(org.apache.helix.HelixException) IOException(java.io.IOException) Path(javax.ws.rs.Path) PUT(javax.ws.rs.PUT)

Example 98 with HelixAdmin

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()));
}
Also used : Response(org.restlet.Response) Reference(org.restlet.data.Reference) Request(org.restlet.Request) HelixAdmin(org.apache.helix.HelixAdmin) IdealState(org.apache.helix.model.IdealState) ZNRecord(org.apache.helix.ZNRecord) Test(org.testng.annotations.Test)

Example 99 with HelixAdmin

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;
}
Also used : ZkClient(org.apache.helix.manager.zk.ZkClient) StringRepresentation(org.restlet.representation.StringRepresentation) HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) HelixConfigScope(org.apache.helix.model.HelixConfigScope) ClusterSetup(org.apache.helix.tools.ClusterSetup) HelixAdmin(org.apache.helix.HelixAdmin) ZNRecord(org.apache.helix.ZNRecord)

Example 100 with HelixAdmin

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;
}
Also used : ExternalView(org.apache.helix.model.ExternalView) ArrayList(java.util.ArrayList) HelixAdmin(org.apache.helix.HelixAdmin)

Aggregations

HelixAdmin (org.apache.helix.HelixAdmin)104 IdealState (org.apache.helix.model.IdealState)44 ZKHelixAdmin (org.apache.helix.manager.zk.ZKHelixAdmin)43 Test (org.testng.annotations.Test)40 HashMap (java.util.HashMap)30 ZNRecord (org.apache.helix.ZNRecord)28 Date (java.util.Date)22 InstanceConfig (org.apache.helix.model.InstanceConfig)22 ArrayList (java.util.ArrayList)18 Map (java.util.Map)17 HashSet (java.util.HashSet)16 ExternalView (org.apache.helix.model.ExternalView)16 StateModelDefinition (org.apache.helix.model.StateModelDefinition)16 IOException (java.io.IOException)13 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)13 HelixDataAccessor (org.apache.helix.HelixDataAccessor)12 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)12 TreeMap (java.util.TreeMap)11 PropertyKey (org.apache.helix.PropertyKey)11 HelixConfigScopeBuilder (org.apache.helix.model.builder.HelixConfigScopeBuilder)11