Package com.linkedin.helix.model

Examples of com.linkedin.helix.model.StateModelDefinition


    _mgmtTool = new FileHelixAdmin(_fileStore);
    _mgmtTool.addCluster(CLUSTER_NAME, true);
   
    StateModelConfigGenerator generator = new StateModelConfigGenerator();
    _mgmtTool.addStateModelDef(CLUSTER_NAME, "LeaderStandby",
                     new StateModelDefinition(generator.generateConfigForLeaderStandby()));

    _mgmtTool.addStateModelDef(CLUSTER_NAME,
                               "OnlineOffline",
                               new StateModelDefinition(generator.generateConfigForOnlineOffline()));
    _mgmtTool.addResource(CLUSTER_NAME, TEST_DB, 10, STATE_MODEL);
    for (int i = 0; i < NODE_NR; i++)
    {
      addNodeToCluster(CLUSTER_NAME, "localhost", START_PORT + i);
    }
View Full Code Here


          {
            logger.error("pervious current state doesn't have a state model def. skip it. prevCS: "
                + previousCurrentState);
            continue;
          }
          StateModelDefinition stateModel =
              _helixAccessor.getProperty(keyBuilder.stateModelDef(stateModelDefRef));
          for (String partitionName : previousCurrentState.getPartitionStateMap()
                                                          .keySet())
          {

            previousCurrentState.setState(partitionName, stateModel.getInitialState());
          }
          previousCurrentState.setSessionId(_sessionId);
          _helixAccessor.setProperty(keyBuilder.currentState(_instanceName,
                                                             _sessionId,
                                                             previousCurrentState.getId()),
View Full Code Here

    // check if the state model definition exists and cache it
    if (!_stateModelDefs.containsKey(stateModelName))
    {
      HelixDataAccessor accessor = _manager.getHelixDataAccessor();
      Builder keyBuilder = accessor.keyBuilder();
      StateModelDefinition stateModelDef =
          accessor.getProperty(keyBuilder.stateModelDef(stateModelName));
      if (stateModelDef == null)
      {
        throw new HelixException("stateModelDef for " + stateModelName
            + " does NOT exists");
View Full Code Here

      }
    }

    // check stateModelDef exists and get initial state
    String stateModelDef = idealState.getStateModelDefRef();
    StateModelDefinition stateModel =
        accessor.getProperty(keyBuilder.stateModelDef(stateModelDef));
    if (stateModel == null)
    {
      throw new HelixException("Can't reset state for " + resourceName + "/"
          + partitionNames + " on " + instanceName + ", because " + stateModelDef
          + " is NOT found");
    }

    // check there is no pending messages for the partitions exist
    List<Message> messages = accessor.getChildValues(keyBuilder.messages(instanceName));
    for (Message message : messages)
    {
      if (!MessageType.STATE_TRANSITION.toString().equalsIgnoreCase(message.getMsgType())
          || !sessionId.equals(message.getTgtSessionId())
          || !resourceName.equals(message.getResourceName())
          || !resetPartitionNames.contains(message.getPartitionName()))
      {
        continue;
      }

      throw new HelixException("Can't reset state for " + resourceName + "/"
          + partitionNames + " on " + instanceName
          + ", because a pending message exists: " + message);
    }

    String adminName = null;
    try
    {
      adminName = InetAddress.getLocalHost().getCanonicalHostName() + "-ADMIN";
    }
    catch (UnknownHostException e)
    {
      // can ignore it
      logger.info("Unable to get host name. Will set it to UNKNOWN, mostly ignorable", e);
      adminName = "UNKNOWN";
    }

    List<Message> resetMessages = new ArrayList<Message>();
    List<PropertyKey> messageKeys = new ArrayList<PropertyKey>();
    for (String partitionName : resetPartitionNames)
    {
      // send ERROR to initialState message
      String msgId = UUID.randomUUID().toString();
      Message message = new Message(MessageType.STATE_TRANSITION, msgId);
      message.setSrcName(adminName);
      message.setTgtName(instanceName);
      message.setMsgState(MessageState.NEW);
      message.setPartitionName(partitionName);
      message.setResourceName(resourceName);
      message.setTgtSessionId(sessionId);
      message.setStateModelDef(stateModelDef);
      message.setFromState("ERROR");
      message.setToState(stateModel.getInitialState());
      message.setStateModelFactoryName(idealState.getStateModelFactoryName());

      resetMessages.add(message);
      messageKeys.add(keyBuilder.message(instanceName, message.getId()));
    }
View Full Code Here

    }

    idealState.setReplicas(Integer.toString(replica));
    int partitions = idealState.getNumPartitions();
    String stateModelName = idealState.getStateModelDefRef();
    StateModelDefinition stateModDef = getStateModelDef(clusterName, stateModelName);

    if (stateModDef == null)
    {
      throw new HelixException("cannot find state model: " + stateModelName);
    }
    // StateModelDefinition def = new StateModelDefinition(stateModDef);

    List<String> statePriorityList = stateModDef.getStatesPriorityList();

    String masterStateValue = null;
    String slaveStateValue = null;
    replica--;

    for (String state : statePriorityList)
    {
      String count = stateModDef.getNumInstancesPerState(state);
      if (count.equals("1"))
      {
        if (masterStateValue != null)
        {
          throw new HelixException("Invalid or unsupported state model definition");
View Full Code Here

    if (record == null || record.getId() == null
        || !record.getId().equals(stateModelDefName))
    {
      throw new IllegalArgumentException("state model definition must have same id as state model def name");
    }
    addStateModelDef(clusterName, stateModelDefName, new StateModelDefinition(record));

  }
View Full Code Here

      _store.createPropertyNamespace(HelixUtil.getStateModelDefinitionPath(clusterName));

      StateModelConfigGenerator generator = new StateModelConfigGenerator();
      addStateModelDef(clusterName,
                       "MasterSlave",
                       new StateModelDefinition(generator.generateConfigForMasterSlave()));

      // controller
      _store.createPropertyNamespace(HelixUtil.getControllerPath(clusterName));
      path = PropertyPathConfig.getPath(PropertyType.HISTORY, clusterName);
      final ZNRecord emptyHistory = new ZNRecord(PropertyType.HISTORY.toString());
View Full Code Here

    ZKHelixDataAccessor accessor =
        new ZKHelixDataAccessor(clusterName, new ZkBaseDataAccessor(_gZkClient));
    Builder keyBuilder = accessor.keyBuilder();

    StateModelConfigGenerator generator = new StateModelConfigGenerator();
    StateModelDefinition masterSlave =
        new StateModelDefinition(generator.generateConfigForMasterSlave());
    accessor.setProperty(keyBuilder.stateModelDef(masterSlave.getId()), masterSlave);

    StateModelDefinition leaderStandby =
        new StateModelDefinition(generator.generateConfigForLeaderStandby());
    accessor.setProperty(keyBuilder.stateModelDef(leaderStandby.getId()), leaderStandby);

    StateModelDefinition onlineOffline =
        new StateModelDefinition(generator.generateConfigForOnlineOffline());
    accessor.setProperty(keyBuilder.stateModelDef(onlineOffline.getId()), onlineOffline);

  }
View Full Code Here

    _admin.addCluster(clusterName, overwritePrevious);

    StateModelConfigGenerator generator = new StateModelConfigGenerator();
    addStateModelDef(clusterName,
                     "MasterSlave",
                     new StateModelDefinition(generator.generateConfigForMasterSlave()));
    addStateModelDef(clusterName,
                     "LeaderStandby",
                     new StateModelDefinition(generator.generateConfigForLeaderStandby()));
    addStateModelDef(clusterName,
                     "StorageSchemata",
                     new StateModelDefinition(generator.generateConfigForStorageSchemata()));
    addStateModelDef(clusterName,
                     "OnlineOffline",
                     new StateModelDefinition(generator.generateConfigForOnlineOffline()));
  }
View Full Code Here

  public String[] parseStates(String clusterName, String stateModelName)
  {
    String[] result = new String[2];
    String masterStateValue = null, slaveStateValue = null;
    StateModelDefinition stateModDef =
        _admin.getStateModelDef(clusterName, stateModelName);

    if (stateModDef == null)
    {
      throw new HelixException("cannot find state model: " + stateModelName);
    }
    // StateModelDefinition def = new StateModelDefinition(stateModDef);

    List<String> statePriorityList = stateModDef.getStatesPriorityList();

    for (String state : statePriorityList)
    {
      String count = stateModDef.getNumInstancesPerState(state);
      if (count.equals("1"))
      {
        if (masterStateValue != null)
        {
          throw new HelixException("Invalid or unsupported state model definition");
View Full Code Here

TOP

Related Classes of com.linkedin.helix.model.StateModelDefinition

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.