예제 #1
0
    def addStateModelDef(self, clusterName, stateModelDef, stateModel):
        """
        Returns void
        Parameters:
            clusterName: StringstateModelDef: StringstateModel: StateModelDefinition
        @Override


        """
        if not ZKUtil.isClusterSetup(clusterName, _zkClient): 
            raise HelixException("cluster " + clusterName + " is not setup yet")


        # String
        stateModelDefPath = HelixUtil.getStateModelDefinitionPath(clusterName)
        # String
        stateModelPath = stateModelDefPath + "/" + stateModelDef
        if _zkClient.exists(stateModelPath): 
            logger.warn("Skip the operation.State Model directory exists:" + stateModelPath)
            raise HelixException("State model path " + stateModelPath + " already exists.")


        # ZKHelixDataAccessor
        accessor = ZKHelixDataAccessor(clusterName, ZkBaseDataAccessor<ZNRecord>(_zkClient))
        # Builder
        keyBuilder = accessor.keyBuilder()
        accessor.setProperty(keyBuilder.stateModelDef(stateModel.getId()), stateModel)
예제 #2
0
    def getStateModelDefs(self, clusterName):
        """
        Returns List<String>
        Parameters:
            clusterName: String
        @Override


        """
        return _zkClient.getChildren(HelixUtil.getStateModelDefinitionPath(clusterName))
예제 #3
0
    def addCluster(self, clusterName, overwritePrevRecord):
        """
        Returns void
        Parameters:
            clusterName: StringoverwritePrevRecord: boolean
        @Override


        """
        # String
        root = "/" + clusterName
        # String
        path = None
        
        if _zkClient.exists(root): 
            logger.warn("Root directory exists.Cleaning the root directory:" + root + " overwritePrevRecord: " + overwritePrevRecord)
            if overwritePrevRecord: 
                _zkClient.deleteRecursive(root)
            else:
                raise HelixException("Cluster " + clusterName + " already exists")



        _zkClient.createPersistent(root)
        _zkClient.createPersistent(HelixUtil.getIdealStatePath(clusterName))
        path = PropertyPathConfig.getPath(PropertyType.CONFIGS, clusterName, ConfigScopeProperty.CLUSTER.toString(), clusterName)
        _zkClient.createPersistent(path, True)
        _zkClient.writeData(path, ZNRecord(clusterName))
        path = PropertyPathConfig.getPath(PropertyType.CONFIGS, clusterName, ConfigScopeProperty.PARTICIPANT.toString())
        _zkClient.createPersistent(path)
        path = PropertyPathConfig.getPath(PropertyType.CONFIGS, clusterName, ConfigScopeProperty.RESOURCE.toString())
        _zkClient.createPersistent(path)
        path = PropertyPathConfig.getPath(PropertyType.PROPERTYSTORE, clusterName)
        _zkClient.createPersistent(path)
        _zkClient.createPersistent(HelixUtil.getLiveInstancesPath(clusterName))
        _zkClient.createPersistent(HelixUtil.getMemberInstancesPath(clusterName))
        _zkClient.createPersistent(HelixUtil.getExternalViewPath(clusterName))
        _zkClient.createPersistent(HelixUtil.getStateModelDefinitionPath(clusterName))
        _zkClient.createPersistent(HelixUtil.getControllerPath(clusterName))
        path = PropertyPathConfig.getPath(PropertyType.HISTORY, clusterName)
        # ZNRecord
        emptyHistory = ZNRecord(PropertyType.HISTORY.toString())
        # List<String>
        emptyList = ArrayList<String>()
        emptyHistory.setListField(clusterName, emptyList)
        _zkClient.createPersistent(path, emptyHistory)
        path = PropertyPathConfig.getPath(PropertyType.MESSAGES_CONTROLLER, clusterName)
        _zkClient.createPersistent(path)
        path = PropertyPathConfig.getPath(PropertyType.STATUSUPDATES_CONTROLLER, clusterName)
        _zkClient.createPersistent(path)
        path = PropertyPathConfig.getPath(PropertyType.ERRORS_CONTROLLER, clusterName)
        _zkClient.createPersistent(path)