Search in sources :

Example 1 with ConfigAccessor

use of org.apache.helix.ConfigAccessor in project helix by apache.

the class TaskCluster method submitDag.

public void submitDag(Dag dag) throws Exception {
    ConfigAccessor clusterConfig = new ConfigAccessor(_zkclient);
    HelixConfigScope clusterScope = new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(_clusterName).build();
    for (String id : dag.getNodeIds()) {
        Dag.Node node = dag.getNode(id);
        clusterConfig.set(clusterScope, node.getId(), node.toJson());
        _admin.addResource(_clusterName, node.getId(), node.getNumPartitions(), DEFAULT_STATE_MODEL, RebalanceMode.FULL_AUTO.toString());
    }
    for (String id : dag.getNodeIds()) {
        _admin.rebalance(_clusterName, id, 1);
    }
}
Also used : HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) ConfigAccessor(org.apache.helix.ConfigAccessor) HelixConfigScope(org.apache.helix.model.HelixConfigScope)

Example 2 with ConfigAccessor

use of org.apache.helix.ConfigAccessor in project helix by apache.

the class TaskStateModel method onBecomeOnlineFromOffline.

@Transition(to = "ONLINE", from = "OFFLINE")
public void onBecomeOnlineFromOffline(Message message, NotificationContext context) throws Exception {
    LOG.debug(_workerId + " becomes ONLINE from OFFLINE for " + _partition);
    ConfigAccessor clusterConfig = context.getManager().getConfigAccessor();
    HelixManager manager = context.getManager();
    HelixConfigScope clusterScope = new HelixConfigScopeBuilder(ConfigScopeProperty.CLUSTER).forCluster(manager.getClusterName()).build();
    String json = clusterConfig.get(clusterScope, message.getResourceName());
    Dag.Node node = Dag.Node.fromJson(json);
    Set<String> parentIds = node.getParentIds();
    String resourceName = message.getResourceName();
    int numPartitions = node.getNumPartitions();
    Task task = _taskFactory.createTask(resourceName, parentIds, manager, _taskResultStore);
    manager.addExternalViewChangeListener(task);
    LOG.debug("Starting task for " + _partition + "...");
    int partitionNum = Integer.parseInt(_partition.split("_")[1]);
    task.execute(resourceName, numPartitions, partitionNum);
    LOG.debug("Task for " + _partition + " done");
}
Also used : HelixManager(org.apache.helix.HelixManager) HelixConfigScopeBuilder(org.apache.helix.model.builder.HelixConfigScopeBuilder) ConfigAccessor(org.apache.helix.ConfigAccessor) HelixConfigScope(org.apache.helix.model.HelixConfigScope) Transition(org.apache.helix.participant.statemachine.Transition)

Example 3 with ConfigAccessor

use of org.apache.helix.ConfigAccessor 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)

Example 4 with ConfigAccessor

use of org.apache.helix.ConfigAccessor in project helix by apache.

the class ClusterAccessor method getClusterConfig.

@GET
@Path("{clusterId}/configs")
public Response getClusterConfig(@PathParam("clusterId") String clusterId) {
    ConfigAccessor accessor = getConfigAccessor();
    ClusterConfig config = null;
    try {
        config = accessor.getClusterConfig(clusterId);
    } catch (HelixException ex) {
        // cluster not found.
        _logger.info("Failed to get cluster config for cluster " + clusterId + ", cluster not found, Exception: " + ex);
    } catch (Exception ex) {
        _logger.error("Failed to get cluster config for cluster " + clusterId + " Exception: " + ex);
        return serverError(ex);
    }
    if (config == null) {
        return notFound();
    }
    return JSONRepresentation(config.getRecord());
}
Also used : HelixException(org.apache.helix.HelixException) ConfigAccessor(org.apache.helix.ConfigAccessor) HelixException(org.apache.helix.HelixException) IOException(java.io.IOException) ClusterConfig(org.apache.helix.model.ClusterConfig) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 5 with ConfigAccessor

use of org.apache.helix.ConfigAccessor in project helix by apache.

the class ResourceAccessor method getResourceConfig.

@GET
@Path("{resourceName}/configs")
public Response getResourceConfig(@PathParam("clusterId") String clusterId, @PathParam("resourceName") String resourceName) {
    ConfigAccessor accessor = getConfigAccessor();
    ResourceConfig resourceConfig = accessor.getResourceConfig(clusterId, resourceName);
    if (resourceConfig != null) {
        return JSONRepresentation(resourceConfig.getRecord());
    }
    return notFound();
}
Also used : ConfigAccessor(org.apache.helix.ConfigAccessor) ResourceConfig(org.apache.helix.model.ResourceConfig) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

ConfigAccessor (org.apache.helix.ConfigAccessor)41 ClusterConfig (org.apache.helix.model.ClusterConfig)15 ClusterControllerManager (org.apache.helix.integration.manager.ClusterControllerManager)14 BeforeClass (org.testng.annotations.BeforeClass)14 MockParticipantManager (org.apache.helix.integration.manager.MockParticipantManager)10 ClusterSetup (org.apache.helix.tools.ClusterSetup)9 Date (java.util.Date)7 HelixConfigScope (org.apache.helix.model.HelixConfigScope)7 HelixConfigScopeBuilder (org.apache.helix.model.builder.HelixConfigScopeBuilder)7 Test (org.testng.annotations.Test)7 HelixException (org.apache.helix.HelixException)6 Path (javax.ws.rs.Path)5 BestPossibleExternalViewVerifier (org.apache.helix.tools.ClusterVerifiers.BestPossibleExternalViewVerifier)4 HelixClusterVerifier (org.apache.helix.tools.ClusterVerifiers.HelixClusterVerifier)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 GET (javax.ws.rs.GET)3 HelixManager (org.apache.helix.HelixManager)3 ZNRecord (org.apache.helix.ZNRecord)3 ZKHelixDataAccessor (org.apache.helix.manager.zk.ZKHelixDataAccessor)3