// This test verifies that when the scheduler calls stop() before // abort(), no pending acknowledgements are sent. TEST_F(MesosSchedulerDriverTest, DropAckIfStopCalledBeforeAbort) { Try<Owned<cluster::Master>> master = StartMaster(); ASSERT_SOME(master); MockExecutor exec(DEFAULT_EXECUTOR_ID); TestContainerizer containerizer(&exec); Owned<MasterDetector> detector = master.get()->createDetector(); Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), &containerizer); ASSERT_SOME(slave); MockScheduler sched; MesosSchedulerDriver driver( &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL); EXPECT_CALL(sched, registered(&driver, _, _)); EXPECT_CALL(sched, resourceOffers(&driver, _)) .WillOnce(LaunchTasks(DEFAULT_EXECUTOR_INFO, 1, 1, 16, "*")) .WillRepeatedly(Return()); // Ignore subsequent offers. // When an update is received, stop the driver and then abort it. Future<Nothing> statusUpdate; EXPECT_CALL(sched, statusUpdate(&driver, _)) .WillOnce(DoAll(StopAndAbort(), FutureSatisfy(&statusUpdate))); // Ensure no status update acknowledgements are sent from the driver // to the master. EXPECT_NO_FUTURE_CALLS( mesos::scheduler::Call(), mesos::scheduler::Call::ACKNOWLEDGE, _ , master.get()->pid); EXPECT_CALL(exec, registered(_, _, _, _)); EXPECT_CALL(exec, launchTask(_, _)) .WillOnce(SendStatusUpdateFromTask(TASK_RUNNING)); EXPECT_CALL(exec, shutdown(_)) .Times(AtMost(1)); driver.start(); AWAIT_READY(statusUpdate); // Settle the clock to ensure driver finishes processing the status // update and sends acknowledgement if necessary. In this test it // shouldn't send an acknowledgement. Clock::pause(); Clock::settle(); driver.stop(); driver.join(); }
// This test ensures that the command executor does not send // TASK_KILLING to frameworks that do not support the capability. TEST_F(CommandExecutorTest, NoTaskKillingCapability) { Try<Owned<cluster::Master>> master = StartMaster(); ASSERT_SOME(master); Owned<MasterDetector> detector = master.get()->createDetector(); Try<Owned<cluster::Slave>> slave = StartSlave(detector.get()); ASSERT_SOME(slave); // Start the framework without the task killing capability. MockScheduler sched; MesosSchedulerDriver driver( &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL); EXPECT_CALL(sched, registered(&driver, _, _)); Future<vector<Offer>> offers; EXPECT_CALL(sched, resourceOffers(&driver, _)) .WillOnce(FutureArg<1>(&offers)) .WillRepeatedly(Return()); // Ignore subsequent offers. driver.start(); AWAIT_READY(offers); EXPECT_EQ(1u, offers->size()); // Launch a task with the command executor. TaskInfo task = createTask( offers->front().slave_id(), offers->front().resources(), "sleep 1000"); Future<TaskStatus> statusRunning; EXPECT_CALL(sched, statusUpdate(_, _)) .WillOnce(FutureArg<1>(&statusRunning)); driver.launchTasks(offers->front().id(), {task}); AWAIT_READY(statusRunning); EXPECT_EQ(TASK_RUNNING, statusRunning->state()); // There should only be a TASK_KILLED update. Future<TaskStatus> statusKilled; EXPECT_CALL(sched, statusUpdate(_, _)) .WillOnce(FutureArg<1>(&statusKilled)); driver.killTask(task.task_id()); AWAIT_READY(statusKilled); EXPECT_EQ(TASK_KILLED, statusKilled->state()); driver.stop(); driver.join(); }
void CLogSerializer::Rollover(const char* ClosedPrefix) { Close(); Owned<IFile> file = createIFile(m_FilePath.str()); if(file.get() && file->exists() == true) { StringBuffer newFileName; GetRolloverFileName(m_FileName,newFileName,ClosedPrefix); file->rename(newFileName.str()); } }
void CppCompiler::writeLogFile(const char* filepath, StringBuffer& log) { if(!filepath || !*filepath || !log.length()) return; Owned <IFile> f = createIFile(filepath); if(f->exists()) f->remove(); Owned <IFileIO> fio = f->open(IFOcreaterw); if(fio.get()) fio->write(0, log.length(), log.str()); }
static bool getCluster(const char *clustername,SocketEndpointArray &eps) { Owned<IGroup> grp = queryNamedGroupStore().lookup(clustername); if (grp.get()==NULL) return false; unsigned n = grp->ordinality(); unsigned short p = getDaliServixPort(); for (unsigned i=0;i<n;i++) { SocketEndpoint ep(p,grp->queryNode(i).endpoint()); eps.append(ep); } return eps.ordinality()!=0; }
// Test that the changes made by the resources decorator hook are correctly // propagated to the resource offer. TEST_F(HookTest, VerifySlaveResourcesAndAttributesDecorator) { Try<Owned<cluster::Master>> master = StartMaster(); ASSERT_SOME(master); MockExecutor exec(DEFAULT_EXECUTOR_ID); TestContainerizer containerizer(&exec); Owned<MasterDetector> detector = master.get()->createDetector(); // Start a mock slave since we aren't testing the slave hooks yet. Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), &containerizer); ASSERT_SOME(slave); MockScheduler sched; MesosSchedulerDriver driver( &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL); EXPECT_CALL(sched, registered(&driver, _, _)); Future<vector<Offer>> offers; EXPECT_CALL(sched, resourceOffers(&driver, _)) .WillOnce(FutureArg<1>(&offers)) .WillRepeatedly(Return()); // Ignore subsequent offers. driver.start(); AWAIT_READY(offers); EXPECT_NE(0u, offers.get().size()); Resources resources = offers.get()[0].resources(); // The test hook sets "cpus" to 4. EXPECT_EQ(4, resources.cpus().get()); // The test hook adds a resource named "foo" of type set with values "bar" // and "baz". EXPECT_EQ(Resources::parse("foo:{bar,baz}").get(), resources.get("foo")); // The test hook does not modify "mem", the default value must still be // present. EXPECT_SOME(resources.mem()); // The test hook adds an attribute named "rack" with value "rack1". Attributes attributes = offers.get()[0].attributes(); ASSERT_EQ(attributes.get(0).name(), "rack"); ASSERT_EQ(attributes.get(0).text().value(), "rack1"); driver.stop(); driver.join(); }
bool CLogThread::queueLog(IEspContext & context,const char* serviceName,int RecordsReturned,bool bBlind,bool bEncrypt, IArrayOf<IEspLogInfo>& LogArray, IInterface& logInfo, IConstModelLogInformation* pModelLogInfo) { LOG_INFO _LogStruct(serviceName,RecordsReturned,bBlind); _LogStruct.Encrypt = bEncrypt; serializeRequest(context,logInfo,_LogStruct.RequestStr); Owned<IPropertyTree> pLogTreeInfo = createPTreeFromXMLString(_LogStruct.RequestStr.str(), ipt_none, ptr_none); addLogInfo(LogArray,*pLogTreeInfo.get()); return queueLog(context,_LogStruct, LogArray,pModelLogInfo); }
// Using JSON base file for authentication without // protobuf tools assistance. TEST_F(CredentialsTest, AuthenticatedSlaveJSON) { string path = path::join(os::getcwd(), "credentials"); Try<int_fd> fd = os::open( path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IRGRP); ASSERT_SOME(fd); // This unit tests our capacity to process JSON credentials without // using our protobuf tools. JSON::Object credential; credential.values["principal"] = DEFAULT_CREDENTIAL.principal(); credential.values["secret"] = DEFAULT_CREDENTIAL.secret(); JSON::Array array; array.values.push_back(credential); JSON::Object credentials; credentials.values["credentials"] = array; ASSERT_SOME(os::write(fd.get(), stringify(credentials))) << "Failed to write credentials to '" << path << "'"; ASSERT_SOME(os::close(fd.get())); map<string, Option<string>> values{ {"credentials", Some(uri::from_path(path))}}; master::Flags masterFlags = CreateMasterFlags(); masterFlags.load(values, true); Try<Owned<cluster::Master>> master = StartMaster(masterFlags); ASSERT_SOME(master); Future<SlaveRegisteredMessage> slaveRegisteredMessage = FUTURE_PROTOBUF(SlaveRegisteredMessage(), _, _); slave::Flags slaveFlags = CreateSlaveFlags(); slaveFlags.load(values, true); Owned<MasterDetector> detector = master.get()->createDetector(); Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), slaveFlags); ASSERT_SOME(slave); AWAIT_READY(slaveRegisteredMessage); ASSERT_NE("", slaveRegisteredMessage->slave_id().value()); }
int run() { try { server->run(listenep); } catch (IException *e) { EXCLOG(e,"dfuplus(dafilesrv)"); if (exc.get()) e->Release(); else exc.setown(e); } return 0; }
int HttpProxy::start() { Owned<ISocket> socket1 = ISocket::create(m_localport); if(http_tracelevel > 0) printf("Proxy started\n"); for (;;) { try { Owned<ISocket> client = socket1->accept(); char peername[256]; int port = client->peer_name(peername, 256); if(m_host.length() > 0) { COneServerHttpProxyThread thrd(client.get(), m_host.str(), m_port, m_ofile, m_use_ssl, m_ssctx, m_url_prefix); thrd.start(); } else { Owned<CHttpProxyThread> thrd = new CHttpProxyThread(client.get(), m_ofile); thrd->start(); } } catch(IException *excpt) { StringBuffer errMsg; DBGLOG("%s", excpt->errorMessage(errMsg).str()); } catch(...) { DBGLOG("unknown exception"); } } return 0; }
TEST_F(ResourceOffersTest, ResourcesGetReofferedWhenUnused) { Try<Owned<cluster::Master>> master = StartMaster(); ASSERT_SOME(master); Owned<MasterDetector> detector = master.get()->createDetector(); Try<Owned<cluster::Slave>> slave = StartSlave(detector.get()); ASSERT_SOME(slave); MockScheduler sched1; MesosSchedulerDriver driver1( &sched1, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL); EXPECT_CALL(sched1, registered(&driver1, _, _)) .Times(1); Future<vector<Offer>> offers; EXPECT_CALL(sched1, resourceOffers(&driver1, _)) .WillOnce(FutureArg<1>(&offers)); driver1.start(); AWAIT_READY(offers); EXPECT_NE(0u, offers.get().size()); vector<TaskInfo> tasks; // Use nothing! driver1.launchTasks(offers.get()[0].id(), tasks); MockScheduler sched2; MesosSchedulerDriver driver2( &sched2, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL); EXPECT_CALL(sched2, registered(&driver2, _, _)) .Times(1); EXPECT_CALL(sched2, resourceOffers(&driver2, _)) .WillOnce(FutureArg<1>(&offers)); driver2.start(); AWAIT_READY(offers); // Stop first framework before second so no offers are sent. driver1.stop(); driver1.join(); driver2.stop(); driver2.join(); }
IndexDataSource::IndexDataSource(const char * _logicalName, IHqlExpression * _diskRecord, const char* _username, const char* _password) { logicalName.set(_logicalName); diskRecord.set(_diskRecord); Owned<IUserDescriptor> udesc; if(_username != NULL && *_username != '\0') { udesc.setown(createUserDescriptor()); udesc->set(_username, _password); } df.setown(queryDistributedFileDirectory().lookup(logicalName, udesc.get())); filtered = false; }
// This test verifies that an authenticated slave is // granted registration by the master. TEST_F(CredentialsTest, AuthenticatedSlave) { Try<Owned<cluster::Master>> master = StartMaster(); ASSERT_SOME(master); Future<SlaveRegisteredMessage> slaveRegisteredMessage = FUTURE_PROTOBUF(SlaveRegisteredMessage(), _, _); Owned<MasterDetector> detector = master.get()->createDetector(); Try<Owned<cluster::Slave>> slave = StartSlave(detector.get()); ASSERT_SOME(slave); AWAIT_READY(slaveRegisteredMessage); ASSERT_NE("", slaveRegisteredMessage->slave_id().value()); }
// This test verifies that if master --> slave socket closes and the // slave is not aware of it (i.e., one way network partition), slave // will re-register with the master. TEST_F(PartitionTest, OneWayPartitionMasterToSlave) { // Start a master. master::Flags masterFlags = CreateMasterFlags(); Try<Owned<cluster::Master>> master = StartMaster(masterFlags); ASSERT_SOME(master); Future<Message> slaveRegisteredMessage = FUTURE_MESSAGE(Eq(SlaveRegisteredMessage().GetTypeName()), _, _); // Ensure a ping reaches the slave. Future<Message> ping = FUTURE_MESSAGE( Eq(PingSlaveMessage().GetTypeName()), _, _); Owned<MasterDetector> detector = master.get()->createDetector(); Try<Owned<cluster::Slave>> slave = StartSlave(detector.get()); ASSERT_SOME(slave); AWAIT_READY(slaveRegisteredMessage); AWAIT_READY(ping); Future<Nothing> deactivateSlave = FUTURE_DISPATCH(_, &MesosAllocatorProcess::deactivateSlave); // Inject a slave exited event at the master causing the master // to mark the slave as disconnected. The slave should not notice // it until the next ping is received. process::inject::exited(slaveRegisteredMessage.get().to, master.get()->pid); // Wait until master deactivates the slave. AWAIT_READY(deactivateSlave); Future<SlaveReregisteredMessage> slaveReregisteredMessage = FUTURE_PROTOBUF(SlaveReregisteredMessage(), _, _); // Ensure the slave observer marked the slave as deactivated. Clock::pause(); Clock::settle(); // Let the slave observer send the next ping. Clock::advance(masterFlags.slave_ping_timeout); // Slave should re-register. AWAIT_READY(slaveReregisteredMessage); }
TEST_F_TEMP_DISABLED_ON_WINDOWS( ResourceOffersTest, ResourceOfferWithMultipleSlaves) { Try<Owned<cluster::Master>> master = StartMaster(); ASSERT_SOME(master); Owned<MasterDetector> detector = master.get()->createDetector(); vector<Owned<cluster::Slave>> slaves; // Start 10 slaves. for (int i = 0; i < 10; i++) { slave::Flags flags = CreateSlaveFlags(); flags.launcher = "posix"; flags.resources = Option<std::string>("cpus:2;mem:1024"); Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), flags); ASSERT_SOME(slave); slaves.push_back(slave.get()); } MockScheduler sched; MesosSchedulerDriver driver( &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL); EXPECT_CALL(sched, registered(&driver, _, _)); Future<vector<Offer>> offers; EXPECT_CALL(sched, resourceOffers(&driver, _)) .WillOnce(FutureArg<1>(&offers)) .WillRepeatedly(Return()); // All 10 slaves might not be in first offer. driver.start(); AWAIT_READY(offers); ASSERT_FALSE(offers->empty()); EXPECT_GE(10u, offers->size()); Resources resources(offers.get()[0].resources()); EXPECT_EQ(2, resources.get<Value::Scalar>("cpus")->value()); EXPECT_EQ(1024, resources.get<Value::Scalar>("mem")->value()); driver.stop(); driver.join(); }
TEST_F(ResourceOffersTest, ResourcesGetReofferedAfterFrameworkStops) { Try<Owned<cluster::Master>> master = StartMaster(); ASSERT_SOME(master); Owned<MasterDetector> detector = master.get()->createDetector(); Try<Owned<cluster::Slave>> slave = StartSlave(detector.get()); ASSERT_SOME(slave); MockScheduler sched1; MesosSchedulerDriver driver1( &sched1, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL); EXPECT_CALL(sched1, registered(&driver1, _, _)) .Times(1); Future<vector<Offer>> offers; EXPECT_CALL(sched1, resourceOffers(&driver1, _)) .WillOnce(FutureArg<1>(&offers)); driver1.start(); AWAIT_READY(offers); EXPECT_NE(0u, offers.get().size()); driver1.stop(); driver1.join(); MockScheduler sched2; MesosSchedulerDriver driver2( &sched2, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL); EXPECT_CALL(sched2, registered(&driver2, _, _)) .Times(1); EXPECT_CALL(sched2, resourceOffers(&driver2, _)) .WillOnce(FutureArg<1>(&offers)); driver2.start(); AWAIT_READY(offers); driver2.stop(); driver2.join(); }
void HttpServer::handleOneRequest(ISocket* client) { char peername[256]; int port = client->peer_name(peername, 256); if(httptest_tracelevel > 5) fprintf(m_ofile, "\n>>receivd request from %s:%d\n", peername, port); StringBuffer requestbuf; Owned<IByteOutputStream> reqstream = createOutputStream(requestbuf); if (m_recvDelay>0) sleep(m_recvDelay); receiveData(client, reqstream.get(), false); if(httptest_tracelevel > 10) fprintf(m_ofile, "%s%s%s", sepstr, requestbuf.str(), sepstr); if(m_response.length() == 0) { //const char* resp_body = "<html><head><meta http-equiv=\"refresh\" content=\"3; url=http://ymaxp:8020\"/></head><body>Default response from httptest server mode</body></html>"; //const char* resp_body = "<html><body onLoad=window.setTimeout(\"location.href='http://ymaxp:8020'\",10000)>Default response from httptest server mode</body></html>"; const char* resp_body = "<html><head><title>default response</title></head><body>Default response from httptest server mode</body></html>"; //const char* resp_body = "<html><head><title>default response</title></head><body><IFRAME SRC=\"http://www.yahoo.com\" TITLE=\"esp config xml file\" width=\"100%\" height=\"100%\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\"></IFrame></body></html>"; m_response.append("HTTP/1.1 200 OK\r\n"); m_response.append("Content-Type: text/html; charset=UTF-8\r\n"); m_response.appendf("Content-Length: %d\r\n", (int) strlen(resp_body)); m_response.appendf("Subject: my-title\r\n"); m_response.append("Expires: 0\r\n"); m_response.append("\r\n"); m_response.append(resp_body); } if (m_sendDelay) sleep(m_sendDelay); client->write(m_response.str(), m_response.length()); if(httptest_tracelevel > 10) fprintf(m_ofile, "\n>>sent back response - \n"); if(httptest_tracelevel > 10) fprintf(m_ofile, "%s%s%s\n", sepstr, m_response.str(), sepstr); fflush(m_ofile); if (m_closeDelay) sleep(m_closeDelay); client->close(); }
void saveAsFile(const char * filepath, const char *filename, const char *text, const char *ext) { StringBuffer path(filepath); appendFileName(path, filename); if(ext && *ext) path.append(ext); Owned<IFile> file = createIFile(path.str()); Owned<IFileIO> io = file->open(IFOcreaterw); DBGLOG("Writing to file %s", file->queryFilename()); if (io.get()) io->write(0, strlen(text), text); else DBGLOG("File %s can't be created", file->queryFilename()); }
// This test verifies that the overlayfs backend should fail on // XFS with ftype turned off. TEST_F(ROOT_XFS_FtypeOffTest, OverlayBackendDisabled) { Try<Owned<cluster::Master>> master = StartMaster(); ASSERT_SOME(master); slave::Flags flags = CreateSlaveFlags(); flags.isolation = "docker/runtime,filesystem/linux"; flags.work_dir = mountPoint.get(); flags.image_providers = "docker"; flags.containerizers = "mesos"; flags.image_provisioner_backend = "overlay"; flags.docker_registry = path::join(os::getcwd(), "archives"); flags.docker_store_dir = path::join(os::getcwd(), "store"); Owned<MasterDetector> detector = master.get()->createDetector(); Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), flags); ASSERT_ERROR(slave); }
ESP_FACTORY IEspRpcBinding * esp_binding_factory(const char *name, const char* type, IPropertyTree *cfg, const char *process) { if (strcmp(type, "ws_eclSoapBinding")==0) { StringBuffer xpath; xpath.appendf("Software/EspProcess[@name=\"%s\"]", process); Owned<IPropertyTree> bcfg = cfg->getPropTree(xpath.str()); const char* cfgFile = cfg->queryProp("@config"); if (cfgFile) bcfg->addProp("@config", cfgFile); return new CWsEclBinding(bcfg.get(), name, process); } else { throw MakeStringException(-1, "Unknown binding type %s", type); } return NULL; }
// Test verifing well executed credential authentication // using text formatted credentials so as to test // backwards compatibility. TEST_F(CredentialsTest, AuthenticatedSlaveText) { string path = path::join(os::getcwd(), "credentials"); Try<int_fd> fd = os::open( path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, S_IRUSR | S_IWUSR | S_IRGRP); ASSERT_SOME(fd); string credentials = DEFAULT_CREDENTIAL.principal() + " " + DEFAULT_CREDENTIAL.secret(); ASSERT_SOME(os::write(fd.get(), credentials)) << "Failed to write credentials to '" << path << "'"; ASSERT_SOME(os::close(fd.get())); map<string, Option<string>> values{ {"credentials", Some(uri::from_path(path))}}; master::Flags masterFlags = CreateMasterFlags(); masterFlags.load(values, true); Try<Owned<cluster::Master>> master = StartMaster(masterFlags); ASSERT_SOME(master); Future<SlaveRegisteredMessage> slaveRegisteredMessage = FUTURE_PROTOBUF(SlaveRegisteredMessage(), _, _); slave::Flags slaveFlags = CreateSlaveFlags(); slaveFlags.load(values, true); Owned<MasterDetector> detector = master.get()->createDetector(); Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), slaveFlags); ASSERT_SOME(slave); AWAIT_READY(slaveRegisteredMessage); ASSERT_NE("", slaveRegisteredMessage->slave_id().value()); }
// This test sends a unsupported Accept media type for the Accept // header. The response should be NotAcceptable in this case. TEST_P(ExecutorHttpApiTest, NotAcceptable) { Try<Owned<cluster::Master>> master = StartMaster(); ASSERT_SOME(master); Future<Nothing> __recover = FUTURE_DISPATCH(_, &Slave::__recover); Owned<MasterDetector> detector = master.get()->createDetector(); Try<Owned<cluster::Slave>> slave = StartSlave(detector.get()); ASSERT_SOME(slave); AWAIT_READY(__recover); // Wait for recovery to be complete. Clock::pause(); Clock::settle(); // Retrieve the parameter passed as content type to this test. const ContentType contentType = GetParam(); process::http::Headers headers; headers["Accept"] = "foo"; // Only subscribe needs to 'Accept' JSON or protobuf. Call call; call.mutable_framework_id()->set_value("dummy_framework_id"); call.mutable_executor_id()->set_value("dummy_executor_id"); call.set_type(Call::SUBSCRIBE); call.mutable_subscribe(); Future<Response> response = process::http::streaming::post( slave.get()->pid, "api/v1/executor", headers, serialize(contentType, call), stringify(contentType)); AWAIT_EXPECT_RESPONSE_STATUS_EQ(NotAcceptable().status, response); }
Linked<T> get(long timeout=0) { const long interval=1000; for(;;) { { CriticalBlock b(crit); typename std::vector<Linked<T> >::iterator it; for(it=resources.begin();it!=resources.end();it++) { if(it->get() == NULL) { Owned<T> e = factory->createResource(); if(e) { it->set(e.get()); return e; } } else if(!it->get()->IsShared()) { return *it; } } } long slp=timeout!=INFINITE && timeout<interval ? timeout : interval; if(slp<=0) break; long start=msTick(); long elapsed=sem.wait(slp) ? (msTick()-start) : slp; if(timeout!=INFINITE) timeout-=elapsed; } throw MakeStringException(1, "Run out of resources"); }
// This test sets an unsupported media type as Content-Type. This // should result in a 415 (UnsupportedMediaType) response. TEST_P(ExecutorHttpApiTest, UnsupportedContentMediaType) { Try<Owned<cluster::Master>> master = StartMaster(); ASSERT_SOME(master); Future<Nothing> __recover = FUTURE_DISPATCH(_, &Slave::__recover); Owned<MasterDetector> detector = master.get()->createDetector(); Try<Owned<cluster::Slave>> slave = StartSlave(detector.get()); ASSERT_SOME(slave); AWAIT_READY(__recover); // Wait for recovery to be complete. Clock::pause(); Clock::settle(); ContentType contentType = GetParam(); process::http::Headers headers; headers["Accept"] = stringify(contentType); Call call; call.mutable_framework_id()->set_value("dummy_framework_id"); call.mutable_executor_id()->set_value("dummy_executor_id"); call.set_type(Call::SUBSCRIBE); call.mutable_subscribe(); const string unknownMediaType = "application/unknown-media-type"; Future<Response> response = process::http::post( slave.get()->pid, "api/v1/executor", headers, serialize(contentType, call), unknownMediaType); AWAIT_EXPECT_RESPONSE_STATUS_EQ(UnsupportedMediaType().status, response); }
bool CWsDfuXRefEx::onDFUXRefBuild(IEspContext &context, IEspDFUXRefBuildRequest &req, IEspDFUXRefBuildResponse &resp) { try { if (!context.validateFeatureAccess(FEATURE_URL, SecAccess_Full, false)) throw MakeStringException(ECLWATCH_DFU_XREF_ACCESS_DENIED, "Failed to build Xref. Permission denied."); StringBuffer username; context.getUserID(username); DBGLOG("CWsDfuXRefEx::onDFUXRefBuild User=%s",username.str()); if (!req.getCluster() || !*req.getCluster()) throw MakeStringExceptionDirect(ECLWATCH_INVALID_INPUT, "Cluster not defined."); //create the node if it doesn;t exist Owned<IXRefNode> xRefNode = XRefNodeManager->getXRefNode(req.getCluster()); if (xRefNode.get() == 0) { xRefNode.setown( XRefNodeManager->CreateXRefNode(req.getCluster())); } StringBuffer returnStr; if (m_XRefbuilder->IsQueued(req.getCluster()) ) appendReplyMessage(returnStr,"/WsDFUXRef/DFUXRefList","An XRef build for cluster %s is in process. Click here to return to the main XRef List.",req.getCluster()); else if (!m_XRefbuilder->IsRunning()) appendReplyMessage(returnStr,"/WsDFUXRef/DFUXRefList","Running XRef Process. Click here to return to the main XRef List."); else appendReplyMessage(returnStr,"/WsDFUXRef/DFUXRefList","someone is currently running a Xref build. Your request will be added to the queue. Please click here to return to the main page."); m_XRefbuilder->QueueRequest(xRefNode,req.getCluster()); resp.setDFUXRefActionResult(returnStr.str()); } catch(IException* e) { FORWARDEXCEPTION(context, e, ECLWATCH_INTERNAL_ERROR); } return true; }
// This test sends a Call from an unknown FrameworkID. The call // should return a BadRequest. TEST_P(ExecutorHttpApiTest, MessageFromUnknownFramework) { Try<Owned<cluster::Master>> master = StartMaster(); ASSERT_SOME(master); Future<Nothing> __recover = FUTURE_DISPATCH(_, &Slave::__recover); Owned<MasterDetector> detector = master.get()->createDetector(); Try<Owned<cluster::Slave>> slave = StartSlave(detector.get()); ASSERT_SOME(slave); AWAIT_READY(__recover); // Wait for recovery to be complete. Clock::pause(); Clock::settle(); ContentType contentType = GetParam(); process::http::Headers headers; headers["Accept"] = stringify(contentType); Call call; call.mutable_framework_id()->set_value("dummy_framework_id"); call.mutable_executor_id()->set_value("dummy_executor_id"); call.set_type(Call::MESSAGE); call.mutable_message()->set_data("hello world"); Future<Response> response = process::http::post( slave.get()->pid, "api/v1/executor", headers, serialize(contentType, call), stringify(contentType)); AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response); }
// This test sends a GET request to the executor HTTP endpoint instead // of a POST. The call should return a MethodNotAllowed response. TEST_F(ExecutorHttpApiTest, GetRequest) { Try<Owned<cluster::Master>> master = StartMaster(); ASSERT_SOME(master); Future<Nothing> __recover = FUTURE_DISPATCH(_, &Slave::__recover); Owned<MasterDetector> detector = master.get()->createDetector(); Try<Owned<cluster::Slave>> slave = StartSlave(detector.get()); ASSERT_SOME(slave); AWAIT_READY(__recover); // Wait for recovery to be complete. Clock::pause(); Clock::settle(); Future<Response> response = process::http::get( slave.get()->pid, "api/v1/executor"); AWAIT_READY(response); AWAIT_EXPECT_RESPONSE_STATUS_EQ(MethodNotAllowed({"POST"}).status, response); }
virtual void init() { CDiskReadMasterVF::init(); bool canMatch = container.queryLocalOrGrouped() || helper->canMatchAny(); // if local, assume may match if (!canMatch) totalCountKnown = true; // totalCount = 0; else if (!container.queryLocalOrGrouped()) { if (!helper->hasSegmentMonitors() && !helper->hasFilter() && !(helper->getFlags() & TDXtemporary)) { Owned<IDistributedFile> file = queryThorFileManager().lookup(container.queryJob(), helper->getFileName(), 0 != ((TDXtemporary|TDXjobtemp) & helper->getFlags()), 0 != (TDRoptional & helper->getFlags())); if (file.get() && canMatch) { if (0 != (TDRunfilteredcount & helper->getFlags()) && file->queryAttributes().hasProp("@recordCount")) { totalCount = (rowcount_t)file->queryAttributes().getPropInt64("@recordCount"); if (totalCount > stopAfter) totalCount = stopAfter; totalCountKnown = true; } } } } }
// This test confirms that if a task exceeds configured resource // limits it is forcibly terminated. TEST_F(PosixRLimitsIsolatorTest, TaskExceedingLimit) { Try<Owned<cluster::Master>> master = StartMaster(); ASSERT_SOME(master); slave::Flags flags = CreateSlaveFlags(); flags.isolation = "posix/rlimits"; Owned<MasterDetector> detector = master.get()->createDetector(); Try<Owned<cluster::Slave>> slave = StartSlave(detector.get(), flags); ASSERT_SOME(slave); MockScheduler sched; MesosSchedulerDriver driver( &sched, DEFAULT_FRAMEWORK_INFO, master.get()->pid, DEFAULT_CREDENTIAL); EXPECT_CALL(sched, registered(_, _, _)); Future<vector<Offer>> offers; EXPECT_CALL(sched, resourceOffers(_, _)) .WillOnce(FutureArg<1>(&offers)) .WillRepeatedly(Return()); // Ignore subsequent offers. driver.start(); AWAIT_READY(offers); ASSERT_FALSE(offers->empty()); // The task attempts to use an infinite amount of CPU time. TaskInfo task = createTask( offers.get()[0].slave_id(), offers.get()[0].resources(), "while true; do true; done"); ContainerInfo* container = task.mutable_container(); container->set_type(ContainerInfo::MESOS); // Limit the process to use maximally 1 second of CPU time. RLimitInfo rlimitInfo; RLimitInfo::RLimit* cpuLimit = rlimitInfo.add_rlimits(); cpuLimit->set_type(RLimitInfo::RLimit::RLMT_CPU); cpuLimit->set_soft(1); cpuLimit->set_hard(1); container->mutable_rlimit_info()->CopyFrom(rlimitInfo); Future<TaskStatus> statusRunning; Future<TaskStatus> statusFailed; EXPECT_CALL(sched, statusUpdate(&driver, _)) .WillOnce(FutureArg<1>(&statusRunning)) .WillOnce(FutureArg<1>(&statusFailed)); driver.launchTasks(offers.get()[0].id(), {task}); AWAIT_READY(statusRunning); EXPECT_EQ(task.task_id(), statusRunning->task_id()); EXPECT_EQ(TASK_RUNNING, statusRunning->state()); AWAIT_READY(statusFailed); EXPECT_EQ(task.task_id(), statusFailed->task_id()); EXPECT_EQ(TASK_FAILED, statusFailed->state()); driver.stop(); driver.join(); }
void processMessage(CMessageBuffer &mb) { ICoven &coven=queryCoven(); SessionId id; int fn; mb.read(fn); switch (fn) { case MSR_REGISTER_PROCESS_SESSION: { acceptConnections.wait(); acceptConnections.signal(); Owned<INode> node(deserializeINode(mb)); Owned<INode> servernode(deserializeINode(mb)); // hopefully me, but not if forwarded int role=0; if (mb.length()-mb.getPos()>=sizeof(role)) { // a capability block present mb.read(role); if (!manager.authorizeConnection(role,false)) { SocketEndpoint sender = mb.getSender(); mb.clear(); coven.reply(mb); MilliSleep(100+getRandom()%1000); // Causes client to 'work' for a short time. Owned<INode> node = createINode(sender); coven.disconnect(node); break; } #ifdef _DEBUG StringBuffer eps; PROGLOG("Connection to %s authorized",mb.getSender().getUrlStr(eps).str()); #endif } IGroup *covengrp; id = manager.registerClientProcess(node.get(),covengrp,(DaliClientRole)role); mb.clear().append(id); if (covengrp->rank(servernode)==RANK_NULL) { // must have been redirected covengrp->Release(); // no good, so just use one we know about (may use something more sophisticated later) INode *na = servernode.get(); covengrp = createIGroup(1, &na); } covengrp->serialize(mb); covengrp->Release(); coven.reply(mb); } break; case MSR_SECONDARY_REGISTER_PROCESS_SESSION: { mb.read(id); Owned<INode> node (deserializeINode(mb)); int role; mb.read(role); manager.addProcessSession(id,node.get(),(DaliClientRole)role); mb.clear(); coven.reply(mb); } break; case MSR_REGISTER_SESSION: { SecurityToken tok; SessionId parentid; mb.read(tok).read(parentid); SessionId id = manager.registerSession(tok,parentid); mb.clear().append(id); coven.reply(mb); } break; case MSR_SECONDARY_REGISTER_SESSION: { mb.read(id); manager.addSession(id); mb.clear(); coven.reply(mb); } break; case MSR_LOOKUP_PROCESS_SESSION: { // looks up from node or from id Owned<INode> node (deserializeINode(mb)); if (node->endpoint().isNull()&&(mb.length()-mb.getPos()>=sizeof(id))) { mb.read(id); INode *n = manager.getProcessSessionNode(id); if (n) node.setown(n); node->serialize(mb.clear()); } else { id = manager.lookupProcessSession(node.get()); mb.clear().append(id); } coven.reply(mb); } break; case MSR_STOP_SESSION: { SessionId sessid; bool failed; mb.read(sessid).read(failed); manager.stopSession(sessid,failed); mb.clear(); coven.reply(mb); } break; case MSR_LOOKUP_LDAP_PERMISSIONS: { StringAttr key; StringAttr obj; Owned<IUserDescriptor> udesc=createUserDescriptor(); StringAttr username; StringAttr passwordenc; mb.read(key).read(obj); udesc->deserialize(mb); #ifndef _NO_DALIUSER_STACKTRACE //following debug code to be removed StringBuffer sb; udesc->getUserName(sb); if (0==sb.length()) { DBGLOG("UNEXPECTED USER (NULL) in dasess.cpp CSessionRequestServer::processMessage() line %d", __LINE__); } #endif unsigned auditflags = 0; if (mb.length()-mb.getPos()>=sizeof(auditflags)) mb.read(auditflags); int err = 0; int ret=manager.getPermissionsLDAP(key,obj,udesc,auditflags,&err); mb.clear().append(ret); if (err) mb.append(err); coven.reply(mb); } break; } }