当前位置: 首页>>代码示例>>C++>>正文


C++ Future::failure方法代码示例

本文整理汇总了C++中Future::failure方法的典型用法代码示例。如果您正苦于以下问题:C++ Future::failure方法的具体用法?C++ Future::failure怎么用?C++ Future::failure使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Future的用法示例。


在下文中一共展示了Future::failure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Failure

Future<Nothing> HealthCheckerProcess::__tcpHealthCheck(
    const tuple<
        Future<Option<int>>,
        Future<string>,
        Future<string>>& t)
{
  Future<Option<int>> status = std::get<0>(t);
  if (!status.isReady()) {
    return Failure(
        "Failed to get the exit status of the " + string(TCP_CHECK_COMMAND) +
        " process: " + (status.isFailed() ? status.failure() : "discarded"));
  }

  if (status->isNone()) {
    return Failure(
        "Failed to reap the " + string(TCP_CHECK_COMMAND) + " process");
  }

  int statusCode = status->get();
  if (statusCode != 0) {
    Future<string> error = std::get<2>(t);
    if (!error.isReady()) {
      return Failure(
          string(TCP_CHECK_COMMAND) + " returned " +
          WSTRINGIFY(statusCode) + "; reading stderr failed: " +
          (error.isFailed() ? error.failure() : "discarded"));
    }

    return Failure(
        string(TCP_CHECK_COMMAND) + " returned " +
        WSTRINGIFY(statusCode) + ": " + error.get());
  }

  return Nothing();
}
开发者ID:liyubobj,项目名称:mesos,代码行数:35,代码来源:health_checker.cpp

示例2: cancelled

void LeaderContenderProcess::cancelled(const Future<bool>& result)
{
  CHECK_READY(candidacy);
  LOG(INFO) << "Membership cancelled: " << candidacy->id();

  // Can be called as a result of either withdraw() or server side
  // expiration.
  CHECK(withdrawing.isSome() || watching.isSome());

  CHECK(!result.isDiscarded());

  if (result.isFailed()) {
    if (withdrawing.isSome()) {
      withdrawing.get()->fail(result.failure());
    }

    if (watching.isSome()) {
      watching.get()->fail(result.failure());
    }
  } else {
    if (withdrawing.isSome()) {
      withdrawing.get()->set(result);
    }

    if (watching.isSome()) {
      watching.get()->set(Nothing());
    }
  }
}
开发者ID:GrovoLearning,项目名称:mesos,代码行数:29,代码来源:contender.cpp

示例3: Failure

Future<Nothing> untar(const string& file, const string& directory)
{
  const vector<string> argv = {
    "tar",
    "-C",
    directory,
    "-x",
    "-f",
    file
  };

  Try<Subprocess> s = subprocess(
      "tar",
      argv,
      Subprocess::PATH("/dev/null"),
      Subprocess::PATH("/dev/null"),
      Subprocess::PIPE());

  if (s.isError()) {
    return Failure("Failed to execute the subprocess: " + s.error());
  }

  return await(
      s.get().status(),
      process::io::read(s.get().err().get()))
    .then([](const tuple<
        Future<Option<int>>,
        Future<string>>& t) -> Future<Nothing> {
      Future<Option<int>> status = std::get<0>(t);
      if (!status.isReady()) {
        return Failure(
          "Failed to get the exit status of the subprocess: " +
          (status.isFailed() ? status.failure() : "discarded"));
      }

      Future<string> error = std::get<1>(t);
      if (!error.isReady()) {
        return Failure(
          "Failed to read stderr from the subprocess: " +
          (error.isFailed() ? error.failure() : "discarded"));
      }

      if (status->isNone()) {
        return Failure("Failed to reap the subprocess");
      }

      if (status->get() != 0) {
        return Failure(
            "Unexpected result from the subprocess: " +
            WSTRINGIFY(status->get()) +
            ", stderr='" + error.get() + "'");
      }

      return Nothing();
    });
}
开发者ID:lins05,项目名称:mesos,代码行数:56,代码来源:puller.cpp

示例4: watched

void LeaderDetectorProcess::watched(Future<set<Group::Membership> > memberships)
{
  CHECK(!memberships.isDiscarded());

  if (memberships.isFailed()) {
    LOG(ERROR) << "Failed to watch memberships: " << memberships.failure();
    leader = None();
    foreach (Promise<Option<Group::Membership> >* promise, promises) {
      promise->fail(memberships.failure());
      delete promise;
    }
开发者ID:aelovikov,项目名称:mesos,代码行数:11,代码来源:detector.cpp

示例5: Failure

Future<Nothing> NetworkCniIsolatorProcess::_detach(
    const ContainerID& containerId,
    const std::string& networkName,
    const string& plugin,
    const tuple<Future<Option<int>>, Future<string>>& t)
{
  CHECK(infos.contains(containerId));
  CHECK(infos[containerId]->containerNetworks.contains(networkName));

  Future<Option<int>> status = std::get<0>(t);
  if (!status.isReady()) {
    return Failure(
        "Failed to get the exit status of the CNI plugin '" +
        plugin + "' subprocess: " +
        (status.isFailed() ? status.failure() : "discarded"));
  }

  if (status->isNone()) {
    return Failure(
        "Failed to reap the CNI plugin '" + plugin + "' subprocess");
  }

  if (status.get() == 0) {
    const string ifDir = paths::getInterfaceDir(
        rootDir.get(),
        containerId.value(),
        networkName,
        infos[containerId]->containerNetworks[networkName].ifName);

    Try<Nothing> rmdir = os::rmdir(ifDir);
    if (rmdir.isError()) {
      return Failure(
          "Failed to remove interface directory '" +
          ifDir + "': " + rmdir.error());
    }

    return Nothing();
  }

  // CNI plugin will print result (in case of success) or error (in
  // case of failure) to stdout.
  Future<string> output = std::get<1>(t);
  if (!output.isReady()) {
    return Failure(
        "Failed to read stdout from the CNI plugin '" +
        plugin + "' subprocess: " +
        (output.isFailed() ? output.failure() : "discarded"));
  }

  return Failure(
      "The CNI plugin '" + plugin + "' failed to detach container "
      "from network '" + networkName + "': " + output.get());
}
开发者ID:gaoguanguo,项目名称:mesos,代码行数:53,代码来源:cni.cpp

示例6: Failure

static Future<Nothing> _fetch(const Future<std::tuple<
    Future<Option<int>>,
    Future<string>,
    Future<string>>>& future)
{
  CHECK_READY(future);

  Future<Option<int>> status = std::get<0>(future.get());
  if (!status.isReady()) {
    return Failure(
        "Failed to get the exit status of the curl subprocess: " +
        (status.isFailed() ? status.failure() : "discarded"));
  }

  if (status->isNone()) {
    return Failure("Failed to reap the curl subprocess");
  }

  if (status->get() != 0) {
    Future<string> error = std::get<2>(future.get());
    if (!error.isReady()) {
      return Failure(
          "Failed to perform 'curl'. Reading stderr failed: " +
          (error.isFailed() ? error.failure() : "discarded"));
    }

    return Failure("Failed to perform 'curl': " + error.get());
  }

  Future<string> output = std::get<1>(future.get());
  if (!output.isReady()) {
    return Failure(
        "Failed to read stdout from 'curl': " +
        (output.isFailed() ? output.failure() : "discarded"));
  }

  // Parse the output and get the HTTP response code.
  Try<int> code = numify<int>(output.get());
  if (code.isError()) {
    return Failure("Unexpected output from 'curl': " + output.get());
  }

  if (code.get() != http::Status::OK) {
    return Failure(
        "Unexpected HTTP response code: " +
        http::Status::string(code.get()));
  }

  return Nothing();
}
开发者ID:juanramb,项目名称:mesos,代码行数:50,代码来源:curl.cpp

示例7: _recover

void RegistrarProcess::_recover(
    const MasterInfo& info,
    const Future<Variable<Registry> >& recovery)
{
  updating = false;

  CHECK(!recovery.isPending());

  if (!recovery.isReady()) {
    recovered.get()->fail("Failed to recover registrar: " +
        (recovery.isFailed() ? recovery.failure() : "discarded"));
  } else {
    Duration elapsed = metrics.state_fetch.stop();

    LOG(INFO) << "Successfully fetched the registry"
              << " (" << Bytes(recovery.get().get().ByteSize()) << ")"
              << " in " << elapsed;

    // Save the registry.
    variable = recovery.get();

    // Perform the Recover operation to add the new MasterInfo.
    Owned<Operation> operation(new Recover(info));
    operations.push_back(operation);
    operation->future()
      .onAny(defer(self(), &Self::__recover, lambda::_1));

    update();
  }
}
开发者ID:Adyoulike,项目名称:mesos,代码行数:30,代码来源:registrar.cpp

示例8: if

/*
 * Class:     org_apache_mesos_state_ZooKeeperState
 * Method:    __fetch_get
 * Signature: (J)Lorg/apache/mesos/state/Variable;
 */
JNIEXPORT jobject JNICALL Java_org_apache_mesos_state_ZooKeeperState__1_1fetch_1get
  (JNIEnv* env, jobject thiz, jlong jfuture)
{
  Future<Variable>* future = (Future<Variable>*) jfuture;

  future->await();

  if (future->isFailed()) {
    jclass clazz = env->FindClass("java/util/concurrent/ExecutionException");
    env->ThrowNew(clazz, future->failure().c_str());
    return NULL;
  } else if (future->isDiscarded()) {
    jclass clazz = env->FindClass("java/util/concurrent/CancellationException");
    env->ThrowNew(clazz, "Future was discarded");
    return NULL;
  }

  CHECK(future->isReady());

  Variable* variable = new Variable(future->get());

  // Variable variable = new Variable();
  jclass clazz = env->FindClass("org/apache/mesos/state/Variable");

  jmethodID _init_ = env->GetMethodID(clazz, "<init>", "()V");
  jobject jvariable = env->NewObject(clazz, _init_);

  jfieldID __variable = env->GetFieldID(clazz, "__variable", "J");
  env->SetLongField(jvariable, __variable, (jlong) variable);

  return jvariable;
}
开发者ID:WuErPing,项目名称:mesos,代码行数:37,代码来源:org_apache_mesos_state_ZooKeeperState.cpp

示例9:

TEST(HTTPTest, PipeFailure)
{
  http::Pipe pipe;
  http::Pipe::Reader reader = pipe.reader();
  http::Pipe::Writer writer = pipe.writer();

  // Fail the writer after writing some data.
  EXPECT_TRUE(writer.write("hello"));
  EXPECT_TRUE(writer.write("world"));

  EXPECT_TRUE(writer.fail("disconnected!"));

  // The reader should read the data, followed by the failure.
  AWAIT_EQ("hello", reader.read());
  AWAIT_EQ("world", reader.read());

  Future<string> read = reader.read();
  EXPECT_TRUE(read.isFailed());
  EXPECT_EQ("disconnected!", read.failure());

  // The writer cannot close or fail an already failed pipe.
  EXPECT_FALSE(writer.close());
  EXPECT_FALSE(writer.fail("not again"));

  // The writer shouldn't be notified of the reader closing,
  // since the writer had already failed.
  EXPECT_TRUE(reader.close());
  EXPECT_TRUE(writer.readerClosed().isPending());
}
开发者ID:haosdent,项目名称:mesos,代码行数:29,代码来源:http_tests.cpp

示例10: watched

void LeaderDetectorProcess::watched(const Future<set<Group::Membership> >& memberships)
{
  CHECK(!memberships.isDiscarded());

  if (memberships.isFailed()) {
    LOG(ERROR) << "Failed to watch memberships: " << memberships.failure();

    // Setting this error stops the watch loop and the detector
    // transitions to an erroneous state. Further calls to detect()
    // will directly fail as a result.
    error = Error(memberships.failure());
    leader = None();
    foreach (Promise<Option<Group::Membership> >* promise, promises) {
      promise->fail(memberships.failure());
      delete promise;
    }
开发者ID:betepahos,项目名称:mesos,代码行数:16,代码来源:detector.cpp

示例11: if

/*
 * Class:     org_apache_mesos_state_AbstractState
 * Method:    __expunge_get
 * Signature: (J)Ljava/lang/Boolean;
 */
JNIEXPORT jobject JNICALL Java_org_apache_mesos_state_AbstractState__1_1expunge_1get
  (JNIEnv* env, jobject thiz, jlong jfuture)
{
  Future<bool>* future = (Future<bool>*) jfuture;

  future->await();

  if (future->isFailed()) {
    jclass clazz = env->FindClass("java/util/concurrent/ExecutionException");
    env->ThrowNew(clazz, future->failure().c_str());
    return NULL;
  } else if (future->isDiscarded()) {
    // TODO(benh): Consider throwing an ExecutionException since we
    // never return true for 'isCancelled'.
    jclass clazz = env->FindClass("java/util/concurrent/CancellationException");
    env->ThrowNew(clazz, "Future was discarded");
    return NULL;
  }

  CHECK_READY(*future);

  if (future->get()) {
    jclass clazz = env->FindClass("java/lang/Boolean");
    return env->GetStaticObjectField(
        clazz, env->GetStaticFieldID(clazz, "TRUE", "Ljava/lang/Boolean;"));
  }

  jclass clazz = env->FindClass("java/lang/Boolean");
  return env->GetStaticObjectField(
      clazz, env->GetStaticFieldID(clazz, "FALSE", "Ljava/lang/Boolean;"));
}
开发者ID:447327642,项目名称:mesos,代码行数:36,代码来源:org_apache_mesos_state_AbstractState.cpp

示例12: if

/*
 * Class:     org_apache_mesos_state_AbstractState
 * Method:    __fetch_get
 * Signature: (J)Lorg/apache/mesos/state/Variable;
 */
JNIEXPORT jobject JNICALL Java_org_apache_mesos_state_AbstractState__1_1fetch_1get
  (JNIEnv* env, jobject thiz, jlong jfuture)
{
  Future<Variable>* future = (Future<Variable>*) jfuture;

  future->await();

  if (future->isFailed()) {
    jclass clazz = env->FindClass("java/util/concurrent/ExecutionException");
    env->ThrowNew(clazz, future->failure().c_str());
    return nullptr;
  } else if (future->isDiscarded()) {
    // TODO(benh): Consider throwing an ExecutionException since we
    // never return true for 'isCancelled'.
    jclass clazz = env->FindClass("java/util/concurrent/CancellationException");
    env->ThrowNew(clazz, "Future was discarded");
    return nullptr;
  }

  CHECK_READY(*future);

  Variable* variable = new Variable(future->get());

  // Variable variable = new Variable();
  jclass clazz = env->FindClass("org/apache/mesos/state/Variable");

  jmethodID _init_ = env->GetMethodID(clazz, "<init>", "()V");
  jobject jvariable = env->NewObject(clazz, _init_);

  jfieldID __variable = env->GetFieldID(clazz, "__variable", "J");
  env->SetLongField(jvariable, __variable, (jlong) variable);

  return jvariable;
}
开发者ID:The-smooth-operator,项目名称:mesos,代码行数:39,代码来源:org_apache_mesos_state_AbstractState.cpp

示例13: coord

TEST(CoordinatorTest, Truncate)
{
  const std::string path1 = utils::os::getcwd() + "/.log1";
  const std::string path2 = utils::os::getcwd() + "/.log2";

  utils::os::rmdir(path1);
  utils::os::rmdir(path2);

  Replica replica1(path1);
  Replica replica2(path2);

  Network network;

  network.add(replica1.pid());
  network.add(replica2.pid());

  Coordinator coord(2, &replica1, &network);

  {
    Result<uint64_t> result = coord.elect(Timeout(1.0));
    ASSERT_TRUE(result.isSome());
    EXPECT_EQ(0, result.get());
  }

  for (uint64_t position = 1; position <= 10; position++) {
    Result<uint64_t> result =
      coord.append(utils::stringify(position), Timeout(1.0));
    ASSERT_TRUE(result.isSome());
    EXPECT_EQ(position, result.get());
  }

  {
    Result<uint64_t> result = coord.truncate(7, Timeout(1.0));
    ASSERT_TRUE(result.isSome());
    EXPECT_EQ(11, result.get());
  }

  {
    Future<std::list<Action> > actions = replica1.read(6, 10);
    ASSERT_TRUE(actions.await(2.0));
    ASSERT_TRUE(actions.isFailed());
    EXPECT_EQ("Bad read range (truncated position)", actions.failure());
  }

  {
    Future<std::list<Action> > actions = replica1.read(7, 10);
    ASSERT_TRUE(actions.await(2.0));
    ASSERT_TRUE(actions.isReady());
    EXPECT_EQ(4, actions.get().size());
    foreach (const Action& action, actions.get()) {
      ASSERT_TRUE(action.has_type());
      ASSERT_EQ(Action::APPEND, action.type());
      EXPECT_EQ(utils::stringify(action.position()), action.append().bytes());
    }
  }

  utils::os::rmdir(path1);
  utils::os::rmdir(path2);
}
开发者ID:vicever,项目名称:mesos,代码行数:59,代码来源:log_tests.cpp

示例14: _healthCheck

  void _healthCheck()
  {
    if (check.has_http()) {
      promise.fail("HTTP health check is not supported");
    } else if (check.has_command()) {
      const CommandInfo& command = check.command();

      map<string, string> environment;

      foreach (const Environment_Variable& variable,
               command.environment().variables()) {
        environment[variable.name()] = variable.value();
      }

      VLOG(2) << "Launching health command: " << command.value();

      Try<Subprocess> external =
        process::subprocess(
          command.value(),
          // Reading from STDIN instead of PIPE because scripts
          // seeing an open STDIN pipe might behave differently
          // and we do not expect to pass any value from STDIN
          // or PIPE.
          Subprocess::FD(STDIN_FILENO),
          Subprocess::FD(STDERR_FILENO),
          Subprocess::FD(STDERR_FILENO),
          environment);

      if (external.isError()) {
        promise.fail("Error creating subprocess for healthcheck");
      } else {
        Future<Option<int> > status = external.get().status();
        status.await(Seconds(check.timeout_seconds()));

        if (!status.isReady()) {
          string msg = "Shell command check failed with reason: ";
          if (status.isFailed()) {
            msg += "failed with error: " + status.failure();
          } else if (status.isDiscarded()) {
            msg += "status future discarded";
          } else {
            msg += "status still pending after timeout " +
                   stringify(Seconds(check.timeout_seconds()));
          }

          promise.fail(msg);
          return;
        }

        int statusCode = status.get().get();
        if (statusCode != 0) {
          string message = "Health command check " + WSTRINGIFY(statusCode);
          failure(message);
        } else {
          success();
        }
      }
    } else {
开发者ID:Bbarrett,项目名称:mesos,代码行数:58,代码来源:main.cpp

示例15: Nothing

Future<Nothing> _destroy(const Future<Option<int>>& future)
{
  if (future.isReady()) {
    return Nothing();
  } else {
    return Failure("Failed to kill all processes: " +
                   (future.isFailed() ? future.failure() : "unknown error"));
  }
}
开发者ID:mpark,项目名称:mesos,代码行数:9,代码来源:launcher.cpp


注:本文中的Future::failure方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。