void ProxyScheduler::registered(SchedulerDriver* driver,
                                const FrameworkID& frameworkId,
                                const MasterInfo& masterInfo)
{
  VALUE fid = NULL;
  VALUE minfo = NULL;
  VALUE res = NULL;

  fid = createPythonProtobuf(frameworkId, "FrameworkID");
  if (fid == NULL) {
    driver->abort(); // createPythonProtobuf will have set an exception
  }

  minfo = createPythonProtobuf(masterInfo, "MasterInfo");
  if (minfo == NULL) {
    driver->abort(); // createPythonProtobuf will have set an exception
  }

  res = rb_funcall(impl->pythonScheduler, rb_intern("registered"), 3, impl, fid, minfo);
  if (res == NULL) {
    cerr << "Failed to call scheduler's registered" << endl;
    driver->abort();
  }

}
void ProxyScheduler::frameworkMessage(SchedulerDriver* driver,
                                      const ExecutorID& executorId,
                                      const SlaveID& slaveId,
                                      const string& data)
{
  VALUE eid = NULL;
  VALUE sid = NULL;
  VALUE res = NULL;

  eid = createPythonProtobuf(executorId, "ExecutorID");
  if (eid == NULL) {
    driver->abort(); // createPythonProtobuf will have set an exception
  }

  sid = createPythonProtobuf(slaveId, "SlaveID");
  if (sid == NULL) {
    driver->abort(); // createPythonProtobuf will have set an exception
  }

  res = rb_funcall(impl->pythonScheduler, rb_intern("framework_message"), 4, impl, eid, sid, rb_str_new(data.data(), data.length()));
  if (res == NULL) {
    cerr << "Failed to call scheduler's frameworkMessage" << endl;
    driver->abort();
  }

}
Beispiel #3
0
void ProxyScheduler::reregistered(SchedulerDriver* driver,
                                  const MasterInfo& masterInfo)
{
  InterpreterLock lock;

  PyObject* minfo = NULL;
  PyObject* res = NULL;

  minfo = createPythonProtobuf(masterInfo, "MasterInfo");
  if (minfo == NULL) {
    goto cleanup; // createPythonProtobuf will have set an exception.
  }

  res = PyObject_CallMethod(impl->pythonScheduler,
                            (char*) "reregistered",
                            (char*) "OO",
                            impl,
                            minfo);
  if (res == NULL) {
    cerr << "Failed to call scheduler's reregistered" << endl;
    goto cleanup;
  }

cleanup:
  if (PyErr_Occurred()) {
    PyErr_Print();
    driver->abort();
  }
  Py_XDECREF(minfo);
  Py_XDECREF(res);
}
Beispiel #4
0
void ProxyScheduler::slaveLost(SchedulerDriver* driver, const SlaveID& slaveId)
{
  InterpreterLock lock;

  PyObject* sid = NULL;
  PyObject* res = NULL;

  sid = createPythonProtobuf(slaveId, "SlaveID");
  if (sid == NULL) {
    goto cleanup; // createPythonProtobuf will have set an exception.
  }

  res = PyObject_CallMethod(impl->pythonScheduler,
                            (char*) "slaveLost",
                            (char*) "OO",
                            impl,
                            sid);
  if (res == NULL) {
    cerr << "Failed to call scheduler's slaveLost" << endl;
    goto cleanup;
  }

cleanup:
  if (PyErr_Occurred()) {
    PyErr_Print();
    driver->abort();
  }
  Py_XDECREF(sid);
  Py_XDECREF(res);
}
Beispiel #5
0
void ProxyScheduler::statusUpdate(SchedulerDriver* driver,
                                  const TaskStatus& status)
{
  InterpreterLock lock;

  PyObject* stat = NULL;
  PyObject* res = NULL;

  stat = createPythonProtobuf(status, "TaskStatus");
  if (stat == NULL) {
    goto cleanup; // createPythonProtobuf will have set an exception.
  }

  res = PyObject_CallMethod(impl->pythonScheduler,
                            (char*) "statusUpdate",
                            (char*) "OO",
                            impl,
                            stat);
  if (res == NULL) {
    cerr << "Failed to call scheduler's statusUpdate" << endl;
    goto cleanup;
  }

cleanup:
  if (PyErr_Occurred()) {
    PyErr_Print();
    driver->abort();
  }
  Py_XDECREF(stat);
  Py_XDECREF(res);
}
Beispiel #6
0
void ProxyScheduler::offerRescinded(SchedulerDriver* driver,
                                    const OfferID& offerId)
{
  InterpreterLock lock;

  PyObject* oid = NULL;
  PyObject* res = NULL;

  oid = createPythonProtobuf(offerId, "OfferID");
  if (oid == NULL) {
    goto cleanup; // createPythonProtobuf will have set an exception.
  }

  res = PyObject_CallMethod(impl->pythonScheduler,
                            (char*) "offerRescinded",
                            (char*) "OO",
                            impl,
                            oid);
  if (res == NULL) {
    cerr << "Failed to call scheduler's offerRescinded" << endl;
    goto cleanup;
  }

cleanup:
  if (PyErr_Occurred()) {
    PyErr_Print();
    driver->abort();
  }
  Py_XDECREF(oid);
  Py_XDECREF(res);
}
void ProxyScheduler::resourceOffers(SchedulerDriver* driver,
                                    const vector<Offer>& offers)
{
  VALUE list = NULL;
  VALUE res = NULL;

  list = PyList_New(offers.size());
  if (list == NULL) {
    driver->abort();
  }
  for (size_t i = 0; i < offers.size(); i++) {
    VALUE offer = createPythonProtobuf(offers[i], "Offer");
    if (offer == NULL) {
      driver->abort();
    }
    PyList_SetItem(list, i, offer); // Steals the reference to offer
  }

  res = rb_funcall(impl->pythonScheduler, rb_intern("resource_offers"), 2, impl, list);

  if (res == NULL) {
    cerr << "Failed to call scheduler's resourceOffer" << endl;
    driver->abort();
  }

}
Beispiel #8
0
void ProxyExecutor::killTask(ExecutorDriver* driver,
                             const TaskID& taskId)
{
  InterpreterLock lock;

  PyObject* taskIdObj = NULL;
  PyObject* res = NULL;

  taskIdObj = createPythonProtobuf(taskId, "TaskID");
  if (taskIdObj == NULL) {
    goto cleanup; // createPythonProtobuf will have set an exception.
  }

  res = PyObject_CallMethod(impl->pythonExecutor,
                            (char*) "killTask",
                            (char*) "OO",
                            impl,
                            taskIdObj);
  if (res == NULL) {
    cerr << "Failed to call executor's killTask" << endl;
    goto cleanup;
  }

cleanup:
  if (PyErr_Occurred()) {
    PyErr_Print();
    driver->abort();
  }
  Py_XDECREF(taskIdObj);
  Py_XDECREF(res);
}
Beispiel #9
0
void ProxyExecutor::reregistered(ExecutorDriver* driver,
                                 const SlaveInfo& slaveInfo)
{
  InterpreterLock lock;

  PyObject* slaveInfoObj = NULL;
  PyObject* res = NULL;

  slaveInfoObj = createPythonProtobuf(slaveInfo, "SlaveInfo");

  if (slaveInfoObj == NULL) {
    goto cleanup; // createPythonProtobuf will have set an exception.
  }

  res = PyObject_CallMethod(impl->pythonExecutor,
                            (char*) "reregistered",
                            (char*) "OO",
                            impl,
                            slaveInfoObj);
  if (res == NULL) {
    cerr << "Failed to call executor re-registered" << endl;
    goto cleanup;
  }

cleanup:
  if (PyErr_Occurred()) {
    PyErr_Print();
    driver->abort();
  }
  Py_XDECREF(slaveInfoObj);
  Py_XDECREF(res);
}
Beispiel #10
0
void ProxyExecutor::registered(ExecutorDriver* driver,
                               const ExecutorInfo& executorInfo,
                               const FrameworkInfo& frameworkInfo,
                               const SlaveInfo& slaveInfo)
{
  InterpreterLock lock;

  PyObject* executorInfoObj = nullptr;
  PyObject* frameworkInfoObj = nullptr;
  PyObject* slaveInfoObj = nullptr;
  PyObject* res = nullptr;

  executorInfoObj = createPythonProtobuf(executorInfo, "ExecutorInfo");
  frameworkInfoObj = createPythonProtobuf(frameworkInfo, "FrameworkInfo");
  slaveInfoObj = createPythonProtobuf(slaveInfo, "SlaveInfo");

  if (executorInfoObj == nullptr ||
      frameworkInfoObj == nullptr ||
      slaveInfoObj == nullptr) {
    goto cleanup; // createPythonProtobuf will have set an exception.
  }

  res = PyObject_CallMethod(impl->pythonExecutor,
                            (char*) "registered",
                            (char*) "OOOO",
                            impl,
                            executorInfoObj,
                            frameworkInfoObj,
                            slaveInfoObj);
  if (res == nullptr) {
    cerr << "Failed to call executor registered" << endl;
    goto cleanup;
  }

cleanup:
  if (PyErr_Occurred()) {
    PyErr_Print();
    driver->abort();
  }
  Py_XDECREF(executorInfoObj);
  Py_XDECREF(frameworkInfoObj);
  Py_XDECREF(slaveInfoObj);
  Py_XDECREF(res);
}
Beispiel #11
0
void ProxyScheduler::frameworkMessage(SchedulerDriver* driver,
                                      const ExecutorID& executorId,
                                      const SlaveID& slaveId,
                                      const string& data)
{
  InterpreterLock lock;

  PyObject* eid = NULL;
  PyObject* sid = NULL;
  PyObject* res = NULL;

  eid = createPythonProtobuf(executorId, "ExecutorID");
  if (eid == NULL) {
    goto cleanup; // createPythonProtobuf will have set an exception.
  }

  sid = createPythonProtobuf(slaveId, "SlaveID");
  if (sid == NULL) {
    goto cleanup; // createPythonProtobuf will have set an exception.
  }

  res = PyObject_CallMethod(impl->pythonScheduler,
                            (char*) "frameworkMessage",
                            (char*) "OOOs#",
                            impl,
                            eid,
                            sid,
                            data.data(),
                            data.length());
  if (res == NULL) {
    cerr << "Failed to call scheduler's frameworkMessage" << endl;
    goto cleanup;
  }

cleanup:
  if (PyErr_Occurred()) {
    PyErr_Print();
    driver->abort();
  }
  Py_XDECREF(eid);
  Py_XDECREF(sid);
  Py_XDECREF(res);
}
Beispiel #12
0
void ProxyScheduler::executorLost(SchedulerDriver* driver,
                                  const ExecutorID& executorId,
                                  const SlaveID& slaveId,
                                  int status)
{
  InterpreterLock lock;

  PyObject* executorIdObj = NULL;
  PyObject* slaveIdObj = NULL;
  PyObject* res = NULL;

  executorIdObj = createPythonProtobuf(executorId, "ExecutorID");
  slaveIdObj = createPythonProtobuf(slaveId, "SlaveID");

  if (executorIdObj == NULL || slaveIdObj == NULL) {
    goto cleanup; // createPythonProtobuf will have set an exception.
  }

  res = PyObject_CallMethod(impl->pythonScheduler,
                            (char*) "executorLost",
                            (char*) "OOOi",
                            impl,
                            executorIdObj,
                            slaveIdObj,
                            status);
  if (res == NULL) {
    cerr << "Failed to call scheduler's executorLost" << endl;
    goto cleanup;
  }

cleanup:
  if (PyErr_Occurred()) {
    PyErr_Print();
    driver->abort();
  }
  Py_XDECREF(executorIdObj);
  Py_XDECREF(slaveIdObj);
  Py_XDECREF(res);
}
void ProxyScheduler::executorLost(SchedulerDriver* driver,
                                  const ExecutorID& executorId,
                                  const SlaveID& slaveId,
                                  int status)
{
  VALUE executorIdObj = NULL;
  VALUE slaveIdObj = NULL;
  VALUE res = NULL;

  executorIdObj = createPythonProtobuf(executorId, "ExecutorID");
  slaveIdObj = createPythonProtobuf(slaveId, "SlaveID");

  if (executorIdObj == NULL || slaveIdObj == NULL) {
    driver->abort(); // createPythonProtobuf will have set an exception
  }

  res = rb_funcall(impl->pythonScheduler, rb_intern("executor_lost"), 4, impl, executorIdObj, slaveIdObj, INT2FIX(status));
  if (res == NULL) {
    cerr << "Failed to call scheduler's executorLost" << endl;
    driver->abort();
  }

}
void ProxyScheduler::slaveLost(SchedulerDriver* driver, const SlaveID& slaveId)
{
  VALUE sid = NULL;
  VALUE res = NULL;

  sid = createPythonProtobuf(slaveId, "SlaveID");
  if (sid == NULL) {
    driver->abort(); // createPythonProtobuf will have set an exception
  }

  res = rb_funcall(impl->pythonScheduler, rb_intern("slave_lost"), 2, impl, sid);
  if (res == NULL) {
    cerr << "Failed to call scheduler's slaveLost" << endl;
    driver->abort();
  }

}
void ProxyScheduler::statusUpdate(SchedulerDriver* driver,
                                  const TaskStatus& status)
{
  VALUE stat = NULL;
  VALUE res = NULL;

  stat = createPythonProtobuf(status, "TaskStatus");
  if (stat == NULL) {
    driver->abort(); // createPythonProtobuf will have set an exception
  }

  res = rb_funcall(impl->pythonScheduler, rb_intern("status_update"), 2, impl, stat);
  if (res == NULL) {
    cerr << "Failed to call scheduler's statusUpdate" << endl;
    driver->abort();
  }

}
void ProxyScheduler::offerRescinded(SchedulerDriver* driver,
                                    const OfferID& offerId)
{
  VALUE oid = NULL;
  VALUE res = NULL;

  oid = createPythonProtobuf(offerId, "OfferID");
  if (oid == NULL) {
    driver->abort(); // createPythonProtobuf will have set an exception
  }

  res = rb_funcall(impl->pythonScheduler, rb_intern("offer_rescinded"), 2, impl, oid);
  if (res == NULL) {
    cerr << "Failed to call scheduler's offerRescinded" << endl;
    driver->abort();
  }

}
Beispiel #17
0
void ProxyScheduler::resourceOffers(SchedulerDriver* driver,
                                    const vector<Offer>& offers)
{
  InterpreterLock lock;

  PyObject* list = NULL;
  PyObject* res = NULL;

  list = PyList_New(offers.size());
  if (list == NULL) {
    goto cleanup;
  }
  for (size_t i = 0; i < offers.size(); i++) {
    PyObject* offer = createPythonProtobuf(offers[i], "Offer");
    if (offer == NULL) {
      goto cleanup;
    }
    PyList_SetItem(list, i, offer); // Steals the reference to offer.
  }

  res = PyObject_CallMethod(impl->pythonScheduler,
                            (char*) "resourceOffers",
                            (char*) "OO",
                            impl,
                            list);

  if (res == NULL) {
    cerr << "Failed to call scheduler's resourceOffer" << endl;
    goto cleanup;
  }

cleanup:
  if (PyErr_Occurred()) {
    PyErr_Print();
    driver->abort();
  }
  Py_XDECREF(list);
  Py_XDECREF(res);
}