Exemplo n.º 1
0
def rollback_snapshot(cluster_name, snapshot):
    """快照回滚
    """
    # 更新所有正在使用的快照为备份中, 0代表备份中,1代表使用中
    query = ZdSnapshot.update(status="0").where(
        (ZdSnapshot.cluster_name == cluster_name) & (ZdSnapshot.path == snapshot.path) & (ZdSnapshot.status == "1")
    )
    query.execute()
    # 根据快照数据更新zookeeper上znode的data
    ZookeeperService.set_or_create(cluster_name, snapshot.path, str(snapshot.data))
    # 更新回滚的快照状态为正在使用
    snapshot.status = "1"
    snapshot.save()
Exemplo n.º 2
0
def rollback_snapshot(cluster_name, snapshot):
    """快照回滚
    """
    # 更新所有正在使用的快照为备份中, 0代表备份中,1代表使用中
    query = ZdSnapshot.update(status="0").where(
        (ZdSnapshot.cluster_name == cluster_name) &
        (ZdSnapshot.path == snapshot.path) &
        (ZdSnapshot.status == "1")
    )
    query.execute()
    # 根据快照数据更新zookeeper上znode的data
    ZookeeperService.set_or_create(cluster_name, snapshot.path, str(snapshot.data))
    # 更新回滚的快照状态为正在使用
    snapshot.status = "1"
    snapshot.save()
Exemplo n.º 3
0
def set_znode(cluster_name, path, data, znode_type='0', business=''):
    """更新或增加znode节点,包括存储于mysql的元数据和存储于zookeeper上的data
    """
    path = normalize_path(path)

    ZookeeperService.set_or_create(cluster_name, path, data)

    # 在mysql上存储znode的相关元数据,节点类型和业务说明
    znode = ZdZnode.one(cluster_name=cluster_name, path=path, deleted="0")
    if znode is None:
        znode = ZdZnode(cluster_name=cluster_name, path=path)
    znode.type = znode_type
    znode.business = business
    znode.save()

    try:
        # 自动快照(如果配置信息没有变更,实际不会进行快照)
        SnapshotService.make_snapshot(cluster_name, path, data)
    except MakeSnapshotError as exc:
        log.error('make snapshot error: %s', str(exc))
Exemplo n.º 4
0
def set_znode(cluster_name, path, data, znode_type='0', business=''):
    """更新或增加znode节点,包括存储于mysql的元数据和存储于zookeeper上的data
    """
    path = normalize_path(path)

    ZookeeperService.set_or_create(cluster_name, path, data)

    # 在mysql上存储znode的相关元数据,节点类型和业务说明
    znode = ZdZnode.one(cluster_name=cluster_name, path=path, deleted="0")
    if znode is None:
        znode = ZdZnode(cluster_name=cluster_name, path=path)
    znode.type = znode_type
    znode.business = business
    znode.save()

    try:
        # 自动快照(如果配置信息没有变更,实际不会进行快照)
        SnapshotService.make_snapshot(cluster_name, path, data)
    except MakeSnapshotError as exc:
        log.error('make snapshot error: %s', str(exc))