Esempio n. 1
0
def start_version_async(module, version):
    """Returns a UserRPC  to start all instances for the given module version.

  Args:
    module: String containing the name of the module to affect.
    version: String containing the name of the version of the module to start.

  Returns:
    A UserRPC  to start all instances for the given module version.
  """
    def _ResultHook(rpc):
        mapped_errors = [
            modules_service_pb.ModulesServiceError.INVALID_VERSION,
            modules_service_pb.ModulesServiceError.TRANSIENT_ERROR
        ]
        expected_errors = {
            modules_service_pb.ModulesServiceError.UNEXPECTED_STATE:
            'The specified module: %s, version: %s is already started.' %
            (module, version)
        }
        _CheckAsyncResult(rpc, mapped_errors, expected_errors)

    request = modules_service_pb.StartModuleRequest()
    request.set_module(module)
    request.set_version(version)
    response = modules_service_pb.StartModuleResponse()
    return _MakeAsyncCall('StartModule', request, response, _ResultHook)
Esempio n. 2
0
def start_module(module, version):
    """Start all instances for the given version of the module.

  Args:
    module: String containing the name of the module to affect.
    version: String containing the name of the version of the module to start.

  Raises:
    InvalidVersionError if the given module version is invalid.
    UnexpectedStateError if the module is already started, or cannot be started.
    TransientError if there is a problem persisting the change.
  """
    req = modules_service_pb.StartModuleRequest()
    req.set_module(module)
    req.set_version(version)
    resp = modules_service_pb.StartModuleResponse()
    try:
        apiproxy_stub_map.MakeSyncCall('modules', 'StartModule', req, resp)
    except apiproxy_errors.ApplicationError, e:
        if (e.application_error ==
                modules_service_pb.ModulesServiceError.INVALID_VERSION):
            raise InvalidVersionError()
        elif (e.application_error ==
              modules_service_pb.ModulesServiceError.UNEXPECTED_STATE):
            raise UnexpectedStateError()
        elif (e.application_error ==
              modules_service_pb.ModulesServiceError.TRANSIENT_ERROR):
            raise TransientError()
        else:
            raise Error()