Ejemplo n.º 1
0
ACTION_P2(InvokeRecoverResourcesWithFilters, allocator, timeout)
{
  Filters filters;
  filters.set_refuse_seconds(timeout);

  allocator->real->recoverResources(arg0, arg1, arg2, filters);
}
Ejemplo n.º 2
0
void MainWindow::on_showImageCustomFilterButton_clicked()
{
    if(ui->spinBox_51->value() != 0)
    {
        int ** conversionMatrix;
        conversionMatrix = new int * [5];
        for(int i = 0; i<5 ; i++)
        {
            conversionMatrix [i] = new int[5];
        }
        conversionMatrix[0][0] = (int)ui->spinBox->value();
        conversionMatrix[0][1] = (int)ui->spinBox_2->value();
        conversionMatrix[0][2] = (int)ui->spinBox_3->value();
        conversionMatrix[0][3] = (int)ui->spinBox_4->value();
        conversionMatrix[0][4] = (int)ui->spinBox_5->value();

        conversionMatrix[1][0] = (int)ui->spinBox_6->value();
        conversionMatrix[1][1] = (int)ui->spinBox_7->value();
        conversionMatrix[1][2] = (int)ui->spinBox_8->value();
        conversionMatrix[1][3] = (int)ui->spinBox_9->value();
        conversionMatrix[1][4] = (int)ui->spinBox_10->value();

        conversionMatrix[2][0] = (int)ui->spinBox_11->value();
        conversionMatrix[2][1] = (int)ui->spinBox_12->value();
        conversionMatrix[2][2] = (int)ui->spinBox_13->value();
        conversionMatrix[2][3] = (int)ui->spinBox_14->value();
        conversionMatrix[2][4] = (int)ui->spinBox_15->value();

        conversionMatrix[3][0] = (int)ui->spinBox_16->value();
        conversionMatrix[3][1] = (int)ui->spinBox_17->value();
        conversionMatrix[3][2] = (int)ui->spinBox_18->value();
        conversionMatrix[3][3] = (int)ui->spinBox_19->value();
        conversionMatrix[3][4] = (int)ui->spinBox_20->value();

        conversionMatrix[4][0] = (int)ui->spinBox_21->value();
        conversionMatrix[4][1] = (int)ui->spinBox_22->value();
        conversionMatrix[4][2] = (int)ui->spinBox_23->value();
        conversionMatrix[4][3] = (int)ui->spinBox_24->value();
        conversionMatrix[4][4] = (int)ui->spinBox_25->value();

        Filters * newFilter = new Filters(imageBefore, conversionMatrix);
        newFilter->setSizeMatrix(5);
        newFilter->customFilter(ui->spinBox_51->value(), ui->spinBox_52->value());

        for(int i = 0; i<5; i++)
            delete []conversionMatrix[i];
        delete []conversionMatrix;

        imageAfter = newFilter->getImageAfter();
        showImageAfter();
    }
    else
    {
        QMessageBox::information(this, tr("Wrong scale value"),tr("Scale = \"0\"! Division by 0... Format C: in 3... 2... 1..."));
    }
}
Ejemplo n.º 3
0
ACTION_P2(InvokeUnusedWithFilters, allocator, timeout)
{
  Filters filters;
  filters.set_refuse_seconds(timeout);

  process::dispatch(
      allocator->real,
      &master::allocator::AllocatorProcess::resourcesUnused,
      arg0,
      arg1,
      arg2,
      filters);
}
  void resourceOffers(
      SchedulerDriver* driver,
      const vector<Offer>& offers) override
  {
    LOG(INFO) << "Received " << offers.size()
              << " resource offers. Declining them";

    Filters filters;

    // Refuse for eternity so Master doesn't send us the same
    // offers.
    filters.set_refuse_seconds(Duration::max().secs());

    for (size_t i = 0; i < offers.size(); i++) {
      driver->declineOffer(offers[i].id(), filters);
    }
  }
Ejemplo n.º 5
0
void search_reply_push_filters(SharedPtrData reply, void *filters_json, void *filter_state_json, char **error) {
#if UNITY_SCOPES_VERSION_MAJOR == 0 && (UNITY_SCOPES_VERSION_MINOR < 6 || (UNITY_SCOPES_VERSION_MINOR == 6 && UNITY_SCOPES_VERSION_MICRO < 10))
    std::string errorMessage = "SearchReply.PushFilters() is only available when compiled against libunity-scopes >= 0.6.10";
    *error = strdup(errorMessage.c_str());
    std::cerr << errorMessage << std::endl;
#else
    try {
        Variant filters_var = Variant::deserialize_json(from_gostring(filters_json));
        Variant filter_state_var = Variant::deserialize_json(from_gostring(filter_state_json));
        Filters filters;
        for (const auto &f : filters_var.get_array()) {
            filters.emplace_back(FilterBase::deserialize(f.get_dict()));
        }
        auto filter_state = FilterState::deserialize(filter_state_var.get_dict());
        get_ptr<SearchReply>(reply)->push(filters, filter_state);
    } catch (const std::exception &e) {
        *error = strdup(e.what());
    }
#endif
}
Ejemplo n.º 6
0
 static void New(const v8::FunctionCallbackInfo<v8::Value>& args) {
     v8::Isolate* isolate = v8::Isolate::GetCurrent();
     v8::HandleScope scope(isolate);
     //        if (args.IsConstructCall()) {
     // Invoked as constructor: `new MyObject(...)`
     hid_t value = args[0]->IsUndefined() ? -1 : args[0]->ToInt32()->Value();
     
     std::string name = args[1]->IsUndefined() ? std::string("") : std::string(*v8::String::Utf8Value (args[1]->ToString()));
     Filters* obj = new Filters(value, name);
     obj->Wrap(args.This());
     args.GetReturnValue().Set(args.This());
     //        } else {
     //        std::cout<<"Filters::New plain"<<std::endl;
     //          // Invoked as plain function `MyObject(...)`, turn into construct call.
     //          const int argc = 1;
     //          v8::Local<v8::Value> argv[argc] = { args[0] };
     //          Local<v8::FunctionTemplate> cons = Local<v8::FunctionTemplate>::New(isolate, Constructor);
     //          args.GetReturnValue().Set(cons->GetFunction()->NewInstance(argc, argv));
     //        }
 }
/*
    This method builds prefix tree based on the list of filter strings. Every node of the tree
    contains subcategory name and, optionally, logging level - if node matches complete filter
    string. For example, given following filters:

    a (error)
    a.b.c (trace)
    a.b.x (trace)
    aa (error)
    aa.b (warn)

    The code builds following prefix tree:

    |
    |- a (error) -- b - c (trace)
    |               |
    |               `-- x (trace)
    |
    `- aa (error) - b (warn)
*/
spark::LogHandler::LogHandler(LogLevel level, const Filters &filters) :
        level_(level) {
    for (auto it = filters.begin(); it != filters.end(); ++it) {
        const char* const category = it->first;
        const LogLevel level = it->second;
        std::vector<FilterData> *filters = &filters_; // Root nodes
        size_t pos = 0;
        for (size_t i = 0;; ++i) {
            if (category[i] && category[i] != '.') { // Category name separator
                continue;
            }
            const size_t size = i - pos;
            if (!size) {
                break; // Invalid category name
            }
            const char* const name = category + pos;
            // Use binary search to find existent node or position for new node
            bool found = false;
            auto it = std::lower_bound(filters->begin(), filters->end(), std::make_pair(name, size),
                    [&found](const FilterData &filter, const std::pair<const char*, size_t> &value) {
                const int cmp = std::strncmp(filter.name, value.first, std::min(filter.size, value.second));
                if (cmp == 0) {
                    if (filter.size == value.second) {
                        found = true;
                    }
                    return filter.size < value.second;
                }
                return cmp < 0;
            });
            if (!found) {
                it = filters->insert(it, FilterData(name, size)); // Add node
            }
            if (!category[i]) {
                it->level = level;
                break;
            }
            filters = &it->filters;
            pos = i + 1;
        }
    }
}
Ejemplo n.º 8
0
void MainWindow::denoisingFilter()
{
    Filters * newFilter = new Filters();
    newFilter->setSizeMatrix(7);
    newFilter->denoisingFilter(imageBefore);
    for(int i = 0 ; i < 1 ; i++)
    {
        imageAfter = newFilter->getImageAfter();
        newFilter->denoisingFilter(imageAfter);
    }
    imageAfter = newFilter->getImageAfter();
    showImageAfter();
}
Ejemplo n.º 9
0
  void write( const std::string& message, bool newline=true )
  {
    // Check for filter pass
    bool pass = filters.size() == 0;
    foreach ( filter, filters )
    {
      if (message.compare( 0, filter->length(), *filter ) == 0)
      {
        pass = true;
        break;
      }
    }
    if (!pass) return;

    foreach( i, writers )
    {
      if( i->second.isValid() )
      {
        i->second->write( message, newline );
      }
    }
  }
Ejemplo n.º 10
0
void CephSchedulerAgent<T>::resourceOffers(
      T* driver,
      const vector<Offer>& offers)
{
  LOG(INFO) << "Received " << offers.size() << " offers! ";
  TaskType taskType;
  int token;
  int isInitialMonNode = 0;
  //handle waiting OSD task, give them osdID to start docker
  handleWaitingOSDTasks(driver);
  Phase currentPhase = stateMachine->getCurrentPhase();
  //try start new node
  foreach (const Offer& offer, offers) {
    //check offer with the correct role
    LOG(INFO) << "Hostname: " << offer.hostname();
    if (!hasRole(offer, config->role)) {
      LOG(INFO) << "Decline this offer. Host " << offer.hostname() << " don't have correct role:"
          << config->role;
      Filters refuse;
      refuse.set_refuse_seconds(86400.0);
      driver->declineOffer(offer.id(),refuse);
      continue;
    }
    //reload or new hostconfig
    stateMachine->addConfig(offer.hostname());
    tryLaunchDiskTask(driver, offer, offer.hostname());
    bool accept = stateMachine->nextMove(taskType,token,offer.hostname());
    if (!accept) {
      LOG(INFO) << "In the "
          << static_cast<int>(currentPhase)
          << " Staging Phase, cannot accept offer from "
          << offer.hostname()
          << " in this phase";
      driver->declineOffer(offer.id());
      continue;
    }
    LOG(INFO) << "Check offer's resources from " <<offer.hostname();
    if (offerNotEnoughResources(offer,taskType)) {
      LOG(INFO) << "Not enough, decline it from " << offer.hostname();
      driver->declineOffer(offer.id());
      continue;
    }
    if (currentPhase == Phase::WAINTING_REQUEST){
      accept = fetchPendingRESTfulRequest();
      if (!accept){
        LOG(INFO) << "No pending OSD RESTful request.";
        driver->declineOffer(offer.id());
        stateMachine->decreaseOSDIndex();
        continue;
      }
    }

    LOG(INFO) << "Accepted offer from" << offer.hostname() << ", launch "
        << static_cast<int>(taskType) <<":" << token << " node";
    if (taskType == TaskType::MON && token == 0) {
        LOG(INFO) << "This is the initial MON";
        isInitialMonNode = 1;
    }
    string taskId;
    string executorId;
    launchNode(
        driver,
        offer,
        taskType,
        token,
        isInitialMonNode,
        taskId,
        executorId);
    stateMachine->addStagingTask(
        taskId,
        executorId,
        taskType,
        offer.hostname(),
        offer.slave_id().value());
    if (!isInitialMonNode && taskType == TaskType::OSD) {
      ceph::TaskState initialMon = stateMachine->getInitialMon();
      const string m = lexical_cast<string>(static_cast<int>(MessageToExecutor::REGISTER_OSD));
      ExecutorID eId;
      eId.set_value(initialMon.executorId);
      SlaveID sId;
      sId.set_value(initialMon.slaveId);
      driver->sendFrameworkMessage(
          eId,
          sId,
          m);
    }//end if

  }//end foreach
// This test verifies that the framework can launch a command task
// that specifies both container image and persistent volumes.
TEST_F(LinuxFilesystemIsolatorMesosTest,
       ROOT_ChangeRootFilesystemCommandExecutorPersistentVolume)
{
  Try<Owned<cluster::Master>> master = StartMaster();
  ASSERT_SOME(master);

  string registry = path::join(sandbox.get(), "registry");
  AWAIT_READY(DockerArchive::create(registry, "test_image"));

  slave::Flags flags = CreateSlaveFlags();
  flags.resources = "cpus:2;mem:1024;disk(role1):1024";
  flags.isolation = "filesystem/linux,docker/runtime";
  flags.docker_registry = registry;
  flags.docker_store_dir = path::join(sandbox.get(), "store");
  flags.image_providers = "docker";

  Owned<MasterDetector> detector = master.get()->createDetector();

  Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), flags);
  ASSERT_SOME(slave);

  MockScheduler sched;
  FrameworkInfo frameworkInfo = DEFAULT_FRAMEWORK_INFO;
  frameworkInfo.set_roles(0, "role1");

  MesosSchedulerDriver driver(
      &sched,
      frameworkInfo,
      master.get()->pid,
      DEFAULT_CREDENTIAL);

  Future<FrameworkID> frameworkId;
  EXPECT_CALL(sched, registered(&driver, _, _))
    .WillOnce(FutureArg<1>(&frameworkId));

  Future<vector<Offer>> offers;
  EXPECT_CALL(sched, resourceOffers(&driver, _))
    .WillOnce(FutureArg<1>(&offers))
    .WillRepeatedly(Return()); // Ignore subsequent offers.

  driver.start();

  AWAIT_READY(frameworkId);

  AWAIT_READY(offers);
  ASSERT_FALSE(offers->empty());

  Offer offer = offers.get()[0];

  string dir1 = path::join(sandbox.get(), "dir1");
  ASSERT_SOME(os::mkdir(dir1));

  Resource persistentVolume = createPersistentVolume(
      Megabytes(64),
      "role1",
      "id1",
      "path1",
      None(),
      None(),
      frameworkInfo.principal());

  // We use the filter explicitly here so that the resources will not
  // be filtered for 5 seconds (the default).
  Filters filters;
  filters.set_refuse_seconds(0);

  TaskInfo task = createTask(
      offer.slave_id(),
      Resources::parse("cpus:1;mem:512").get() + persistentVolume,
      "echo abc > path1/file");

  task.mutable_container()->CopyFrom(createContainerInfo(
      "test_image",
      {createVolumeHostPath("/tmp", dir1, Volume::RW)}));

  // Create the persistent volumes and launch task via `acceptOffers`.
  driver.acceptOffers(
      {offer.id()},
      {CREATE(persistentVolume), LAUNCH({task})},
      filters);

  Future<TaskStatus> statusStarting;
  Future<TaskStatus> statusRunning;
  Future<TaskStatus> statusFinished;

  EXPECT_CALL(sched, statusUpdate(&driver, _))
    .WillOnce(FutureArg<1>(&statusStarting))
    .WillOnce(FutureArg<1>(&statusRunning))
    .WillOnce(FutureArg<1>(&statusFinished));

  AWAIT_READY(statusStarting);
  EXPECT_EQ(TASK_STARTING, statusStarting->state());

  AWAIT_READY(statusRunning);
  EXPECT_EQ(TASK_RUNNING, statusRunning->state());

  AWAIT_READY(statusFinished);
  EXPECT_EQ(TASK_FINISHED, statusFinished->state());

  // NOTE: The command executor's id is the same as the task id.
  ExecutorID executorId;
  executorId.set_value(task.task_id().value());

  string directory = slave::paths::getExecutorLatestRunPath(
      flags.work_dir,
      offer.slave_id(),
      frameworkId.get(),
      executorId);

  EXPECT_FALSE(os::exists(path::join(directory, "path1")));

  string volumePath = slave::paths::getPersistentVolumePath(
      flags.work_dir,
      "role1",
      "id1");

  EXPECT_SOME_EQ("abc\n", os::read(path::join(volumePath, "file")));

  driver.stop();
  driver.join();
}
  virtual void resourceOffers(SchedulerDriver* driver,
                              const vector<Offer>& offers)
  {
    foreach (const Offer& offer, offers) {
      LOG(INFO) << "Received offer " << offer.id() << " with "
                << offer.resources();

      // If the framework got this offer for the first time, the state is
      // `State::INIT`; framework will reserve it (sending RESERVE operation
      // to master) in this loop.
      if (!states.contains(offer.slave_id())) {
        // If all tasks were launched, do not reserve more resources; wait
        // for them to finish and unreserve resources.
        if (tasksLaunched == totalTasks) {
          continue;
        }

        states[offer.slave_id()] = State::INIT;
      }

      const State state = states[offer.slave_id()];

      Filters filters;
      filters.set_refuse_seconds(0);

      switch (state) {
        case State::INIT: {
          // Framework reserves resources from this offer for only one task;
          // the task'll be dispatched when reserved resources are re-offered
          // to this framework.
          Resources resources = offer.resources();
          Offer::Operation reserve = RESERVE(taskResources);

          Try<Resources> apply = resources.apply(reserve);
          if (apply.isError()) {
            LOG(INFO) << "Failed to reserve resources for task in offer "
                      << stringify(offer.id()) << ": " << apply.error();
            break;
          }

          driver->acceptOffers({offer.id()}, {reserve}, filters);
          states[offer.slave_id()] = State::RESERVING;
          break;
        }
        case State::RESERVING: {
          Resources resources = offer.resources();
          Resources reserved = resources.reserved(role);
          if (!reserved.contains(taskResources)) {
            break;
          }
          states[offer.slave_id()] = State::RESERVED;

          // We fallthrough here to save an offer cycle.
        }
        case State::RESERVED: {
          Resources resources = offer.resources();
          Resources reserved = resources.reserved(role);

          CHECK(reserved.contains(taskResources));

          // If all tasks were launched, unreserve those resources.
          if (tasksLaunched == totalTasks) {
            driver->acceptOffers(
                {offer.id()}, {UNRESERVE(taskResources)}, filters);
            states[offer.slave_id()] = State::UNRESERVING;
            break;
          }

          // Framework dispatches task on the reserved resources.
          CHECK(tasksLaunched < totalTasks);

          // Launch tasks on reserved resources.
          const string& taskId = stringify(tasksLaunched++);
          LOG(INFO) << "Launching task " << taskId << " using offer "
                    << offer.id();
          TaskInfo task;
          task.set_name("Task " + taskId + ": " + command);
          task.mutable_task_id()->set_value(taskId);
          task.mutable_slave_id()->MergeFrom(offer.slave_id());
          task.mutable_command()->set_shell(true);
          task.mutable_command()->set_value(command);
          task.mutable_resources()->MergeFrom(taskResources);
          driver->launchTasks(offer.id(), {task}, filters);
          states[offer.slave_id()] = State::TASK_RUNNING;
          break;
        }
        case State::TASK_RUNNING:
          LOG(INFO) << "The task on " << offer.slave_id()
                    << " is running, waiting for task done";
          break;
        case State::UNRESERVING: {
          Resources resources = offer.resources();
          Resources reserved = resources.reserved(role);
          if (!reserved.contains(taskResources)) {
            states[offer.slave_id()] = State::UNRESERVED;
          }
          break;
        }
        case State::UNRESERVED:
          // If state of slave is UNRESERVED, ignore it. The driver is stopped
          // when all tasks are done and all resources are unreserved.
          break;
      }
    }