Пример #1
0
  def create_pplan(self, topologyName, pplan):
    """ create physical plan """
    if not pplan or not pplan.IsInitialized():
      raise StateException("Physical Plan protobuf not init properly",
                           StateException.EX_TYPE_PROTOBUF_ERROR), None, sys.exc_info()[2]

    path = self.get_pplan_path(topologyName)
    LOG.info("Adding topology: {0} to path: {1}".format(
        topologyName, path))
    pplanString = pplan.SerializeToString()
    try:
      self.client.create(path, value=pplanString, makepath=True)
      return True
    except NoNodeError:
      raise StateException("NoNodeError while creating pplan",
                           StateException.EX_TYPE_NO_NODE_ERROR), None, sys.exc_info()[2]
    except NodeExistsError:
      raise StateException("NodeExistsError while creating pplan",
                           StateException.EX_TYPE_NODE_EXISTS_ERROR), None, sys.exc_info()[2]
    except ZookeeperError:
      raise StateException("Zookeeper while creating pplan",
                           StateException.EX_TYPE_ZOOKEEPER_ERROR), None, sys.exc_info()[2]
    except Exception:
      # Just re raise the exception.
      raise
Пример #2
0
  def create_execution_state(self, topologyName, executionState):
    """ create execution state """
    if not executionState or not executionState.IsInitialized():
      raise StateException("Execution State protobuf not init properly",
                           StateException.EX_TYPE_PROTOBUF_ERROR), None, sys.exc_info()[2]

    path = self.get_execution_state_path(topologyName)
    LOG.info("Adding topology: {0} to path: {1}".format(
        topologyName, path))
    executionStateString = executionState.SerializeToString()
    try:
      self.client.create(path, value=executionStateString, makepath=True)
      return True
    except NoNodeError:
      raise StateException("NoNodeError while creating execution state",
                           StateException.EX_TYPE_NO_NODE_ERROR), None, sys.exc_info()[2]
    except NodeExistsError:
      raise StateException("NodeExistsError while creating execution state",
                           StateException.EX_TYPE_NODE_EXISTS_ERROR), None, sys.exc_info()[2]
    except ZookeeperError:
      raise StateException("Zookeeper while creating execution state",
                           StateException.EX_TYPE_ZOOKEEPER_ERROR), None, sys.exc_info()[2]
    except Exception:
      # Just re raise the exception.
      raise
Пример #3
0
    def create_topology(self, topologyName, topology):
        """ crate topology """
        if not topology or not topology.IsInitialized():
            raise_(
                StateException("Topology protobuf not init properly",
                               StateException.EX_TYPE_PROTOBUF_ERROR),
                sys.exc_info()[2])

        path = self.get_topology_path(topologyName)
        LOG.info("Adding topology: {0} to path: {1}".format(
            topologyName, path))
        topologyString = topology.SerializeToString()
        try:
            self.client.create(path, value=topologyString, makepath=True)
            return True
        except NoNodeError:
            raise_(
                StateException("NoNodeError while creating topology",
                               StateException.EX_TYPE_NO_NODE_ERROR),
                sys.exc_info()[2])
        except NodeExistsError:
            raise_(
                StateException("NodeExistsError while creating topology",
                               StateException.EX_TYPE_NODE_EXISTS_ERROR),
                sys.exc_info()[2])
        except ZookeeperError:
            raise_(
                StateException("Zookeeper while creating topology",
                               StateException.EX_TYPE_ZOOKEEPER_ERROR),
                sys.exc_info()[2])
Пример #4
0
 def delete_execution_state(self, topologyName):
     """ delete execution state """
     path = self.get_execution_state_path(topologyName)
     LOG.info("Removing topology: {0} from path: {1}".format(
         topologyName, path))
     try:
         self.client.delete(path)
         return True
     except NoNodeError:
         raise_(
             StateException("NoNodeError while deleting execution state",
                            StateException.EX_TYPE_NO_NODE_ERROR),
             sys.exc_info()[2])
     except NotEmptyError:
         raise_(
             StateException("NotEmptyError while deleting execution state",
                            StateException.EX_TYPE_NOT_EMPTY_ERROR),
             sys.exc_info()[2])
     except ZookeeperError:
         raise_(
             StateException("Zookeeper while deleting execution state",
                            StateException.EX_TYPE_ZOOKEEPER_ERROR),
             sys.exc_info()[2])
     except Exception:
         # Just re raise the exception.
         raise
Пример #5
0
  def get_topologies(self, callback=None):
    """ get topologies """
    isWatching = False

    # Temp dict used to return result
    # if callback is not provided.
    ret = {
        "result": None
    }
    if callback:
      isWatching = True
    else:
      def callback(data):
        """Custom callback to get the topologies right now."""
        ret["result"] = data

    try:
      self._get_topologies_with_watch(callback, isWatching)
    except NoNodeError as err:
      self.client.stop()
      path = self.get_topologies_path()
      raise StateException("Error required topology path '%s' not found" % (path),
                           StateException.EX_TYPE_NO_NODE_ERROR), None, sys.exc_info()[2]

    # The topologies are now populated with the data.
    return ret["result"]
Пример #6
0
def reraise_from_zk_exceptions(action):
    """Raise StateException from ZookeeperError if raised."""
    try:
        yield
    except NoNodeError as e:
        raise StateException(f"NoNodeError while {action}",
                             StateException.EX_TYPE_NO_NODE_ERROR) from e
    except NodeExistsError as e:
        raise StateException(f"NodeExistsError while {action}",
                             StateException.EX_TYPE_NODE_EXISTS_ERROR) from e
    except NotEmptyError as e:
        raise StateException(f"NotEmptyError while {action}",
                             StateException.EX_TYPE_NOT_EMPTY_ERROR) from e
    except ZookeeperError as e:
        raise StateException(f"Zookeeper while {action}",
                             StateException.EX_TYPE_ZOOKEEPER_ERROR) from e
Пример #7
0
    def get_topologies(self, callback=None):
        """ get topologies """
        isWatching = False

        # Temp dict used to return result
        # if callback is not provided.
        ret = {"result": None}
        if callback:
            isWatching = True
        else:

            def callback(data):
                """Custom callback to get the topologies right now."""
                ret["result"] = data

        try:
            # Ensure the topology path exists. If a topology has never been deployed
            # then the path will not exist so create it and don't crash.
            # (fixme) add a watch instead of creating the path?
            self.client.ensure_path(self.get_topologies_path())

            self._get_topologies_with_watch(callback, isWatching)
        except NoNodeError as e:
            self.client.stop()
            path = self.get_topologies_path()
            raise StateException(
                f"Error required topology path {path!r} not found",
                StateException.EX_TYPE_NO_NODE_ERROR) from e

        # The topologies are now populated with the data.
        return ret["result"]
Пример #8
0
 def delete_pplan(self, topologyName):
   path = self.get_pplan_path(topologyName)
   LOG.info("Removing topology: {0} from path: {1}".format(
     topologyName, path))
   try:
     self.client.delete(path)
     return True
   except NoNodeError as e:
     raise StateException("NoNodeError while deleting pplan",
                       StateException.EX_TYPE_NO_NODE_ERROR), None, sys.exc_info()[2]
   except NotEmptyError as e:
     raise StateException("NotEmptyError while deleting pplan",
                       StateException.EX_TYPE_NOT_EMPTY_ERROR), None, sys.exc_info()[2]
   except ZookeeperError as e:
     raise StateException("Zookeeper while deleting pplan",
                       StateException.EX_TYPE_ZOOKEEPER_ERROR), None, sys.exc_info()[2]
   except Exception as e:
     # Just re raise the exception.
     raise
Пример #9
0
    def create_execution_state(self, topologyName, executionState):
        """ create execution state """
        if not executionState or not executionState.IsInitialized():
            raise StateException("Execution State protobuf not init properly",
                                 StateException.EX_TYPE_PROTOBUF_ERROR)

        path = self.get_execution_state_path(topologyName)
        LOG.info(f"Adding topology: {topologyName} to path: {path}")
        executionStateString = executionState.SerializeToString()
        with reraise_from_zk_exceptions("creating execution state"):
            self.client.create(path, value=executionStateString, makepath=True)
        return True
Пример #10
0
    def create_pplan(self, topologyName, pplan):
        """ create physical plan """
        if not pplan or not pplan.IsInitialized():
            raise StateException("Physical Plan protobuf not init properly",
                                 StateException.EX_TYPE_PROTOBUF_ERROR)

        path = self.get_pplan_path(topologyName)
        LOG.info(f"Adding topology: {topologyName} to path: {path}")
        pplanString = pplan.SerializeToString()
        with reraise_from_zk_exceptions("creating pplan"):
            self.client.create(path, value=pplanString, makepath=True)
        return True
Пример #11
0
    def create_topology(self, topologyName, topology):
        """ crate topology """
        if not topology or not topology.IsInitialized():
            raise StateException("Topology protobuf not init properly",
                                 StateException.EX_TYPE_PROTOBUF_ERROR)

        path = self.get_topology_path(topologyName)
        LOG.info(f"Adding topology: {topologyName} to path: {path}")
        topologyString = topology.SerializeToString()
        with reraise_from_zk_exceptions("creating topology"):
            self.client.create(path, value=topologyString, makepath=True)
        return True
Пример #12
0
 def delete_pplan(self, topologyName):
     """ delete physical plan info """
     path = self.get_pplan_path(topologyName)
     LOG.info("Removing topology: {0} from path: {1}".format(
         topologyName, path))
     try:
         self.client.delete(path)
         return True
     except NoNodeError:
         raise_(
             StateException("NoNodeError while deleting pplan",
                            StateException.EX_TYPE_NO_NODE_ERROR),
             sys.exc_info()[2])
     except NotEmptyError:
         raise_(
             StateException("NotEmptyError while deleting pplan",
                            StateException.EX_TYPE_NOT_EMPTY_ERROR),
             sys.exc_info()[2])
     except ZookeeperError:
         raise_(
             StateException("Zookeeper while deleting pplan",
                            StateException.EX_TYPE_ZOOKEEPER_ERROR),
             sys.exc_info()[2])