Ejemplo n.º 1
0
    def addInstance(self, clusterName, instanceConfig):
        """
        Returns void
        Parameters:
            clusterName: StringinstanceConfig: InstanceConfig
        @Override


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


        # String
        instanceConfigsPath = PropertyPathConfig.getPath(PropertyType.CONFIGS, clusterName, ConfigScopeProperty.PARTICIPANT.toString())
        # String
        nodeId = instanceConfig.getId()
        # String
        instanceConfigPath = instanceConfigsPath + "/" + nodeId
        if _zkClient.exists(instanceConfigPath): 
            raise HelixException("Node " + nodeId + " already exists in cluster " + clusterName)


        ZKUtil.createChildren(_zkClient, instanceConfigsPath, instanceConfig.getRecord())
        _zkClient.createPersistent(HelixUtil.getMessagePath(clusterName, nodeId), True)
        _zkClient.createPersistent(HelixUtil.getCurrentStateBasePath(clusterName, nodeId), True)
        _zkClient.createPersistent(HelixUtil.getErrorsPath(clusterName, nodeId), True)
        _zkClient.createPersistent(HelixUtil.getStatusUpdatesPath(clusterName, nodeId), True)
Ejemplo n.º 2
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)
Ejemplo n.º 3
0
    def dropInstance(self, clusterName, instanceConfig):
        """
        Returns void
        Parameters:
            clusterName: StringinstanceConfig: InstanceConfig
        @Override


        """
        # String
        instanceConfigsPath = PropertyPathConfig.getPath(PropertyType.CONFIGS, clusterName, ConfigScopeProperty.PARTICIPANT.toString())
        # String
        nodeId = instanceConfig.getId()
        # String
        instanceConfigPath = instanceConfigsPath + "/" + nodeId
        # String
        instancePath = HelixUtil.getInstancePath(clusterName, nodeId)
        if not _zkClient.exists(instanceConfigPath): 
            raise HelixException("Node " + nodeId + " does not exist in config for cluster " + clusterName)


        if not _zkClient.exists(instancePath): 
            raise HelixException("Node " + nodeId + " does not exist in instances for cluster " + clusterName)


        ZKUtil.dropChildren(_zkClient, instanceConfigsPath, instanceConfig.getRecord())
        _zkClient.deleteRecursive(instancePath)
Ejemplo n.º 4
0
    def getStateModelDefs(self, clusterName):
        """
        Returns List<String>
        Parameters:
            clusterName: String
        @Override


        """
        return _zkClient.getChildren(HelixUtil.getStateModelDefinitionPath(clusterName))
Ejemplo n.º 5
0
    def getResourcesInCluster(self, clusterName):
        """
        Returns List<String>
        Parameters:
            clusterName: String
        @Override


        """
        return _zkClient.getChildren(HelixUtil.getIdealStatePath(clusterName))
Ejemplo n.º 6
0
    def getInstancesInCluster(self, clusterName):
        """
        Returns List<String>
        Parameters:
            clusterName: String
        @Override


        """
        # String
        memberInstancesPath = HelixUtil.getMemberInstancesPath(clusterName)
        return _zkClient.getChildren(memberInstancesPath)
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
        idealState.setNumPartitions(partitions)
        idealState.setStateModelDefRef(stateModelRef)
        idealState.setIdealStateMode(mode.toString())
        idealState.setReplicas("" + 0)
        idealState.setStateModelFactoryName(HelixConstants.DEFAULT_STATE_MODEL_FACTORY)
        if bucketSize > 0: 
            idealState.setBucketSize(bucketSize)

        # String
        stateModelDefPath = PropertyPathConfig.getPath(PropertyType.STATEMODELDEFS, clusterName, stateModelRef)
        if not _zkClient.exists(stateModelDefPath): 
            raise HelixException("State model " + stateModelRef + " not found in the cluster STATEMODELDEFS path")


        # String
        idealStatePath = HelixUtil.getIdealStatePath(clusterName)
        # String
        dbIdealStatePath = idealStatePath + "/" + resourceName
        if _zkClient.exists(dbIdealStatePath): 
            raise HelixException("Skip the operation. DB ideal state directory exists:" + dbIdealStatePath)


        ZKUtil.createChildren(_zkClient, idealStatePath, idealState.getRecord())


    def getClusters(self):
        """
        Returns List<String>
        @Override