示例#1
0
    def del_resource(self, cluster, resource):
        """delete specified resource from cluster"""
        if cluster not in self.get_clusters():
            raise HelixDoesNotExistException(
                "Cluster {0} does not exist.".format(cluster))

        if resource not in self.get_resource_groups(cluster):
            raise HelixDoesNotExistException(
                "ResourceGroup {0} does not exist".format(resource))

        self.zk.delete(
            self._build_path(
                RESOURCE_IDEAL_STATE_PATH.format(clusterName=cluster,
                                                 resourceName=resource)))
        return True
示例#2
0
    def reset_resource(self, cluster, resource):
        """reset resource"""
        if resource not in self.get_resource_groups(cluster):
            raise HelixDoesNotExistException(
                "ResourceGroup {0} does not exist".format(resource))

        raise NotImplementedError
示例#3
0
    def reset_instance(self, cluster, instance):
        """reset instance"""
        if instance not in self.get_instances(cluster):
            raise HelixDoesNotExistException(
                "Instance {0} does not exist".format(instance))

        raise NotImplementedError
示例#4
0
文件: functions.py 项目: t0791/helix
def add_instance(host, cluster, instances, port):
    """add a list of instances to a cluster"""
    if cluster not in get_clusters(host):
        raise HelixDoesNotExistException(
            "Cluster {0} does not exist".format(cluster))

    if not isinstance(instances, list):
        instances = [instances]
    instances = ["{0}:{1}".format(instance, port) for instance in instances]
    try:
        newinstances = set(instances)
        oldinstances = set(
            [x["id"].replace('_', ':') for x in get_instances(host, cluster)])
        instances = list(newinstances - oldinstances)
    except HelixException:
        # this will get thrown if instances is empty,
        # which if we're just populating should happen
        pass

    if instances:
        data = {"command": "addInstance",
                "instanceNames": ";".join(instances)}

        instance_path = "/clusters/{0}/instances".format(cluster)
        # print "adding to", instance_path
        page = _post_payload(host, instance_path, data)
        return page

    else:
        raise HelixAlreadyExistsException(
            "All instances given already exist in cluster")
示例#5
0
文件: functions.py 项目: t0791/helix
def del_resource(host, cluster, resource):
    """delete specified resource from cluster"""
    if resource not in get_resource_groups(host, cluster):
        raise HelixDoesNotExistException(
            "ResourceGroup {0} does not exist".format(resource))

    page = _delete_page(host, "/clusters/{0}/resourceGroups/{1}".format(
        cluster, resource))
    return page
示例#6
0
文件: functions.py 项目: z3ro3d/helix
    def del_instance(self, cluster, instance):
        """delete instance"""
        if instance not in [x["id"] for x in self.get_instances(cluster)]:
            raise HelixDoesNotExistException(
                "Instance {0} does not exist.".format(instance))

        page = self._delete_page("/clusters/{0}/instances/{1}".format(
            cluster, instance))
        return page
示例#7
0
文件: functions.py 项目: z3ro3d/helix
    def reset_instance(self, cluster, instance):
        """reset instance"""
        if instance not in self.get_instances(cluster):
            raise HelixDoesNotExistException(
                "Instance {0} does not exist".format(instance))

        data = {"command": "resetInstance"}
        return self._post_payload(
            "/clusters/{0}/instances/{1}".format(cluster, instance), data)
示例#8
0
文件: functions.py 项目: z3ro3d/helix
    def reset_resource(self, cluster, resource):
        """reset resource"""
        if resource not in self.get_resource_groups(cluster):
            raise HelixDoesNotExistException(
                "ResourceGroup {0} does not exist".format(resource))

        data = {"command": "resetResource"}
        return self._post_payload(
            "/clusters/{0}/resourceGroups/{1}".format(cluster, resource), data)
示例#9
0
文件: functions.py 项目: z3ro3d/helix
    def add_resource_tag(self, cluster, resource, tag):
        """add tag to resource group"""
        if resource not in self.get_resource_groups(cluster):
            raise HelixDoesNotExistException(
                "ResourceGroup {0} does not exist".format(resource))

        data = {"command": "addResourceProperty", "INSTANCE_GROUP_TAG": tag}
        return self._post_payload(
            "/clusters/{0}/resourceGroups/{1}/idealState".format(
                cluster, resource), data)
示例#10
0
 def enable_partition(self,
                      cluster,
                      resource,
                      partition,
                      instance,
                      enabled=True):
     """enable Partition """
     if resource not in self.get_resource_groups(cluster):
         raise HelixDoesNotExistException(
             "ResourceGroup {0} does not exist".format(resource))
     raise NotImplementedError
示例#11
0
文件: functions.py 项目: t0791/helix
def reset_partition(host, cluster, resource, partitions, instance):
    """reset partition"""
    if resource not in get_resource_groups(host, cluster):
        raise HelixDoesNotExistException(
            "ResourceGroup {0} does not exist".format(resource))

    data = {"command": "resetPartition",
            "resource": resource,
            "partition": " ".join(partitions)}
    return _post_payload(host, "/clusters/{0}/instances/{1}".format(cluster,
                                                                    instance),
                         data)
示例#12
0
    def del_cluster(self, cluster):
        """delete cluster"""
        if cluster not in self.get_clusters():
            raise HelixDoesNotExistException(
                "Cluster {0} does not exist.".format(cluster))

        self.zk.delete(
            self._build_path(CLUSTER_CONFIG_PATH.format(clusterName=cluster)))

        for path in HELIX_ZOOKEEPER_PATHS.get("cluster")[::-1]:
            self.zk.ensure_path(
                self._build_path(path.format(clusterName=cluster)))

        return True
示例#13
0
文件: functions.py 项目: t0791/helix
def enable_partition(host, cluster, resource, partition, instance,
                     enabled=True):
    """enable Partition """
    if resource not in get_resource_groups(host, cluster):
        raise HelixDoesNotExistException(
            "ResourceGroup {0} does not exist".format(resource))

    data = {"command": "enablePartition",
            "resource": resource,
            "partition": partition,
            "enabled": enabled}
    return _post_payload(host, "/clusters/{0}/instances/{1}".format(cluster,
                                                                    instance),
                         data)
示例#14
0
    def del_instance(self, cluster, instance):
        """delete instance"""
        if cluster not in self.get_clusters():
            raise HelixDoesNotExistException(
                "Cluster {0} does not exist.".format(cluster))

        if instance not in [x["id"] for x in self.get_instances(cluster)]:
            raise HelixDoesNotExistException(
                "Instance {0} does not exist.".format(instance))

        self.zk.delete(
            self._build_path(
                PARTICIPANT_CONFIG_PATH.format(clusterName=cluster,
                                               instanceName=instance.replace(
                                                   ':', '_'))))

        # Reverse zookeeper structure for destruction.
        for path in HELIX_ZOOKEEPER_PATHS.get("instance")[::-1]:
            self.zk.delete(
                self._build_path(
                    path.format(clusterName=cluster,
                                instanceName=instance.replace(':', '_'))))
        return True
示例#15
0
    def add_resource_tag(self, cluster, resource, tag):
        """add tag to resource group"""
        if resource not in self.get_resource_groups(cluster):
            raise HelixDoesNotExistException(
                "ResourceGroup {0} does not exist".format(resource))

        resource_data, resource_stat = self._get_resource_group(
            cluster, resource)
        resource_data["simpleFields"]["INSTANCE_GROUP_TAG"] = tag

        self.zk.set(self._build_path(
            RESOURCE_IDEAL_STATE_PATH.format(clusterName=cluster,
                                             resourceName=resource)),
                    json.dumps(resource_data),
                    version=resource_stat.version)
        return True
示例#16
0
    def add_instance(self, cluster, instances, port):
        """add a list of instances to a cluster"""
        if cluster not in self.get_clusters():
            raise HelixDoesNotExistException(
                "Cluster {0} does not exist".format(cluster))

        if not isinstance(instances, list):
            instances = [instances]
        instances = [
            "{instance}:{port}".format(instance=instance, port=port)
            for instance in instances
        ]
        try:
            newinstances = set(instances)
            oldinstances = set([
                x["id"].replace('_', ':') for x in self.get_instances(cluster)
            ])
            instances = list(newinstances - oldinstances)
        except HelixException:
            # this will get thrown if instances is empty,
            # which if we're just populating should happen
            pass

        if instances:
            for instance in instances:
                data = self._build_instance_entry(instance)
                self.zk.create(
                    self._build_path(
                        PARTICIPANT_CONFIG_PATH.format(
                            clusterName=cluster,
                            instanceName=instance.replace(':', '_'))),
                    json.dumps(data))
                for path in HELIX_ZOOKEEPER_PATHS.get("instance"):
                    self.zk.ensure_path(
                        self._build_path(
                            path.format(clusterName=cluster,
                                        instanceName=instance.replace(
                                            ':', '_'))))
            return True
        else:
            raise HelixAlreadyExistsException(
                "All instances given already exist in cluster")
示例#17
0
 def del_resource_tag(self, cluster, resource, tag):
     """Delete resource tag."""
     if resource not in self.get_resource_groups(cluster):
         raise HelixDoesNotExistException(
             "ResourceGroup {0} does not exist".format(resource))
     raise NotImplementedError
示例#18
0
 def del_instance_tag(self, cluster, instance, tag):
     """remove tag from instance"""
     if instance not in [x["id"] for x in self.get_instances(cluster)]:
         raise HelixDoesNotExistException(
             "Instance {0} does not exist.".format(instance))