void Dijkstra::calcPath(Workload& request, Graph& network, Stats& stats) { bool pathFound=false; bool exitLoop=false; Element current; // current Element Visited visited; // Visited list Priority items; // priority queue double previousCost=-1; // 1. Get initial Start node current.id=request.origin; current.cost=0; current.parent=request.origin; // TODO - possible problem... items.push(current); // 2. Loop until we have found a valid path //while (!exitLoop && !items.empty()){ while (!items.empty()){ // Pop from the priority queue current=items.top(); //std::cout<<"Current: "<<current.id<<" | Parent: "<<current.parent<< " | Goal:"<<request.destination<<std::endl; items.pop(); // remove the element from the list if (pathFound){ if(current.cost>previousCost){ exitLoop=true; // we want to exit the main loop break; } } previousCost=current.cost; if (visited.find(current.id)==visited.end()) { //visited.find(current.id)==visited.end() // Check if desired node if (current.id==request.destination){ // Found the node! pathFound=true; //std::cout<<std::endl<<request.origin<<request.destination<<std::endl; exitLoop=true; // TODO - remove me in future but currently bug when this is not here ????? map appears to be losing the parent of N for some weird reason.. } else { // push the valid children which have bandwidth and are not allready visited onto the priority queue network.begin(current.id,request.time); while (!network.end()) { pushChild(network.nextChild(),current,visited,items,network,request.time); } } // Append the current node to the visited list visited.insert(std::pair<char,Element>(current.id,current)); // be careful that the node is not allready in the visited list..possibly } } // 3. Choose one valid path at random and backtrack -> calculate and append statistics... if (pathFound){ // we have a valid path... -> backtrack to allocate resources backTrack(request.origin,request.destination,request.time ,request.timeDuration ,visited,network,stats); } else { //Path was impossible -> add blocked circuit stats.addCircuit(false); } }
END_TEST START_TEST (test_WriteL3SBML_Priority) { const char* expected = "<priority/>"; Priority *p = D->createModel()->createEvent()->createPriority(); char* sbml = p->toSBML(); fail_unless( equals(expected,sbml) ); safe_free(sbml); }
void Node::log(Priority pri, const char *file, const char *call, unsigned int line, const char *msg) const { try { // skip if priority's below threshold if( nc_->getThreshold().toInt() > pri.toInt() ) return; // get current time-stamp timeb ts; ftime(&ts); // format string stringstream ss; assert( nc_->getFormatter().get()!=NULL ); nc_->getFormatter()->format(ss, ts, nn_, pri, file, call, line, msg); // append it to configured appender nc_->getAppender()->append( ss.str() ); } catch(const exception &ex) { errorWhileLogging( ex.what() ); } catch(...) { errorWhileLogging(NULL); } }
void Thread::setPriority(Priority pr) { if(pr.validate()==false) errorHandler(INVALID_PARAMETERS); PauseKernelLock lock; Thread *current=getCurrentThread(); //If thread is locking at least one mutex if(current->mutexLocked!=0) { //savedPriority always changes, since when all mutexes are unlocked //setPriority() must become effective if(current->savedPriority==pr) return; current->savedPriority=pr; //Calculate new priority of thread, which is //max(savedPriority, inheritedPriority) Mutex *walk=current->mutexLocked; while(walk!=0) { if(walk->waiting.empty()==false) pr=std::max(pr,walk->waiting.front()->getPriority()); walk=walk->next; } } //If old priority == desired priority, nothing to do. if(pr==current->getPriority()) return; Scheduler::PKsetPriority(current,pr); #ifdef SCHED_TYPE_EDF if(isKernelRunning()) yield(); //Another thread might have a closer deadline #endif //SCHED_TYPE_EDF }
/** Set up the given session with the settings in this profile */ void SetupSession(gnutls_session_t sess) { priority.SetupSession(sess); x509cred.SetupSession(sess); gnutls_dh_set_prime_bits(sess, min_dh_bits); // Request client certificate if we are a server, no-op if we're a client gnutls_certificate_server_set_request(sess, GNUTLS_CERT_REQUEST); }
void Dijkstra::pushChild(char id, const Element& parentNode, Visited& visited, Priority& priority, Graph &network,double startTime) { double cost= findCost(id,parentNode,network,startTime); // get the cost of the node...from the unique function if (visited.find(id) == visited.end()) { // Element is not in visited map -> add it //visited.insert(std::pair<char,Element>(id,Element(id,cost,parentNode.id))); - we are going to check if visited later Element newnode; newnode.id=id;newnode.cost=cost;newnode.parent=parentNode.id; newnode.parents.push_back(parentNode.id); priority.push(newnode); } else { // if the current cost is less than or equal to the elements cost then we may need to update the map if (cost == visited.at(id).cost){ // we have found the node at the same cost... we need to put it as a parent as well visited[id].parents.push_back(parentNode.id); } else if (cost < visited.at(id).cost){ // need to look at node again visited[id].cost=cost; priority.push(visited[id]); } } }
END_TEST START_TEST (test_WriteL3SBML_Event_full) { const char* expected = "<event useValuesFromTriggerTime=\"true\">\n" " <trigger initialValue=\"true\" persistent=\"false\">\n" " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n" " <true/>\n" " </math>\n" " </trigger>\n" " <priority>\n" " <math xmlns=\"http://www.w3.org/1998/Math/MathML\">\n" " <cn type=\"integer\"> 2 </cn>\n" " </math>\n" " </priority>\n" "</event>"; Event *e = D->createModel()->createEvent(); e->setUseValuesFromTriggerTime(true); Trigger *t = e->createTrigger(); t->setInitialValue(true); t->setPersistent(false); ASTNode *math1 = SBML_parseFormula("true"); t->setMath(math1); Priority *p = e->createPriority(); ASTNode *math2 = SBML_parseFormula("2"); p->setMath(math2); char* sbml = e->toSBML(); fail_unless( equals(expected,sbml) ); safe_free(sbml); delete math1; delete math2; }
int main(void) { string rmHost("localhost"); string rmPort("8032"); string schedHost("localhost"); string schedPort("8030"); string amHost("localhost"); int32_t amPort = 0; //cluster node1 /* string rmHost("10.37.7.101"); string rmPort("8032"); string schedHost("10.37.7.101"); string schedPort("8030"); string amHost("10.34.0.134"); int32_t amPort = 0; */ string am_tracking_url("url"); LibYarnClient client(rmHost, rmPort, schedHost, schedPort, amHost, amPort, am_tracking_url); //1. createJob string jobName("libyarn"); string queue("default"); string jobId = client.createJob(jobName, queue); cout<<"jobId:"<<jobId<<endl; //2. allocate ResourceRequest resRequest; string host("*"); resRequest.setResourceName(host); Resource capability; capability.setVirtualCores(1); capability.setMemory(1024); resRequest.setCapability(capability); resRequest.setNumContainers(3); resRequest.setRelaxLocality(true); Priority priority; priority.setPriority(1); resRequest.setPriority(priority); string resGroupId("group_1"); list<string> blackListAdditions; list<string> blackListRemovals; list<Container> allocatedResources = client.allocateResources(jobId, resGroupId, resRequest, blackListAdditions, blackListRemovals); for (list<Container>::iterator it = allocatedResources.begin(); it != allocatedResources.end(); it++) { cout << "allocate: host:" << (*it).getNodeId().getHost() << ", port:" << (*it).getNodeId().getPort() << ", cid:" << (*it).getId().getId() << ", vcores:" << (*it).getResource().getVirtualCores() << ", mem:" << (*it).getResource().getMemory() << endl; } //3. active client.activeResources(jobId, resGroupId); sleep(1); //4. release client.releaseResources(jobId, resGroupId); sleep(2); //5. getQueueInfo QueueInfo queueInfo = client.getQueueInfo(queue, true, true, true); cout << "queueName:" << queueInfo.getQueueName() << ", capacity:" << queueInfo.getCapacity() << ", maximumCapacity:" << queueInfo.getMaximumCapacity() << ", currentCapacity:" << queueInfo.getCurrentCapacity() << ", state:" << queueInfo.getQueueState() << endl; //6. getCluster list<NodeState> nodeStates; nodeStates.push_back(NodeState::NS_RUNNING); list<NodeReport> nodeReports = client.getClusterNodes(nodeStates); for (list<NodeReport>::iterator it = nodeReports.begin(); it != nodeReports.end(); it++) { cout << "host:" << it->getNodeId().getHost() << ", port:" << it->getNodeId().getPort() << ", httpAddress:" << it->getHttpAddress() << ", rackName:" << it->getRackName() << ", used:[vcore:" << it->getUsedResource().getVirtualCores() << ", mem:" << it->getUsedResource().getMemory() << "], capability:[vcore:" << it->getResourceCapability().getVirtualCores() << ", mem:" << it->getResourceCapability().getMemory() << "], numContainers:" << it->getNumContainers() << ", node_state:" << it->getNodeState() << ", health_report:" << it->getHealthReport() << ", last_health_report_time:" << it->getLastHealthReportTime() << endl; } //7. finish cout << "to finish: jobId:" << jobId << endl; client.finishJob(jobId, FinalApplicationStatus::APP_SUCCEEDED); sleep(1); return 0; }
int Submodel::convertTimeAndExtentWith(const ASTNode* tcf, const ASTNode* xcf, const ASTNode* klmod) { if (tcf==NULL && xcf==NULL) return LIBSBML_OPERATION_SUCCESS; Model* model = getInstantiation(); if (model==NULL) { //getInstantiation sets its own error messages. return LIBSBML_OPERATION_FAILED; } ASTNode tcftimes(AST_TIMES); ASTNode tcfdiv(AST_DIVIDE); if (tcf != NULL) { tcftimes.addChild(tcf->deepCopy()); tcfdiv.addChild(tcf->deepCopy()); } ASTNode rxndivide(AST_DIVIDE); if (klmod != NULL) { ASTNode rxnref(AST_NAME); rxndivide.addChild(rxnref.deepCopy()); rxndivide.addChild(klmod->deepCopy()); } List* allElements = model->getAllElements(); for (ListIterator iter = allElements->begin(); iter != allElements->end(); ++iter) { SBase* element = static_cast<SBase*>(*iter); assert(element != NULL); ASTNode* ast1 = NULL; ASTNode* ast2 = NULL; Constraint* constraint = NULL; Delay* delay = NULL; EventAssignment* ea = NULL; InitialAssignment* ia = NULL; KineticLaw* kl = NULL; Priority* priority = NULL; RateRule* rrule = NULL; Rule* rule = NULL; Submodel* submodel = NULL; Trigger* trigger = NULL; string cf = ""; //Reaction math will be converted below, in the bits with the kinetic law. But because of that, we need to handle references *to* the reaction: even if it has no kinetic law, the units have changed, and this needs to be reflected by the flattening routine. if (rxndivide.getNumChildren() != 0 && element->getTypeCode()==SBML_REACTION && element->isSetId()) { rxndivide.getChild(0)->setName(element->getId().c_str()); for (ListIterator iter = allElements->begin(); iter != allElements->end(); ++iter) { SBase* subelement = static_cast<SBase*>(*iter); subelement->replaceSIDWithFunction(element->getId(), &rxndivide); } } //Submodels need their timeConversionFactor and extentConversionFactor attributes converted. We're moving top-down, so all we need to do here is fix the conversion factor attributes themselves, pointing them to new parameters if need be. if ((tcf !=NULL || xcf != NULL) && element->getTypeCode()==SBML_COMP_SUBMODEL) { submodel = static_cast<Submodel*>(element); if (tcf != NULL) { if (submodel->isSetTimeConversionFactor()) { createNewConversionFactor(cf, tcf, submodel->getTimeConversionFactor(), model); submodel->setTimeConversionFactor(cf); } else { submodel->setTimeConversionFactor(tcf->getName()); } } if (xcf != NULL) { if (submodel->isSetExtentConversionFactor()) { createNewConversionFactor(cf, xcf, submodel->getExtentConversionFactor(), model); submodel->setExtentConversionFactor(cf); } else { submodel->setExtentConversionFactor(xcf->getName()); } } } if (tcf==NULL) { if (klmod !=NULL && element->getTypeCode()==SBML_KINETIC_LAW) { kl = static_cast<KineticLaw*>(element); if (kl->isSetMath()) { ast1 = new ASTNode(AST_TIMES); ast1->addChild(klmod->deepCopy()); ast1->addChild(kl->getMath()->deepCopy()); kl->setMath(ast1); delete ast1; } } } else { // All math 'time' and 'delay' csymbols must still be converted. // Also, several constructs are modified directly. switch(element->getTypeCode()) { //This would be a WHOLE LOT SIMPLER if there was a 'hasMath' class in libsbml. But even so, it would have to // handle the kinetic laws, rate rules, and delays separately. case SBML_KINETIC_LAW: //Kinetic laws are multiplied by 'klmod'. kl = static_cast<KineticLaw*>(element); ast1 = kl->getMath()->deepCopy(); convertCSymbols(ast1, &tcfdiv, &tcftimes); if (klmod !=NULL) { kl = static_cast<KineticLaw*>(element); if (kl->isSetMath()) { ast2 = new ASTNode(AST_TIMES); ast2->addChild(klmod->deepCopy()); ast2->addChild(ast1); kl->setMath(ast2); delete ast2; } } else { kl->setMath(ast1); delete ast1; } break; case SBML_DELAY: //Delays are multiplied by the time conversion factor. delay = static_cast<Delay*>(element); if (delay->isSetMath()) { ast1 = delay->getMath()->deepCopy(); convertCSymbols(ast1, &tcfdiv, &tcftimes); tcftimes.addChild(ast1); delay->setMath(&tcftimes); tcftimes.removeChild(1); delete ast1; } break; case SBML_RATE_RULE: //Rate rules are divided by the time conversion factor. rrule = static_cast<RateRule*>(element); if (rrule->isSetMath()) { ast1 = rrule->getMath()->deepCopy(); tcfdiv.insertChild(0, ast1); rrule->setMath(&tcfdiv); tcfdiv.removeChild(0); delete ast1; } //Fall through to: case SBML_ASSIGNMENT_RULE: case SBML_ALGEBRAIC_RULE: //Rules in general need csymbols converted. rule = static_cast<Rule*>(element); if (rule->isSetMath()) { ast1 = rule->getMath()->deepCopy(); convertCSymbols(ast1, &tcfdiv, &tcftimes); rule->setMath(ast1); delete ast1; } break; case SBML_EVENT_ASSIGNMENT: //Event assignments need csymbols converted. ea = static_cast<EventAssignment*>(element); if (ea->isSetMath()) { ast1 = ea->getMath()->deepCopy(); convertCSymbols(ast1, &tcfdiv, &tcftimes); ea->setMath(ast1); delete ast1; } break; case SBML_INITIAL_ASSIGNMENT: //Initial assignments need csymbols converted. ia = static_cast<InitialAssignment*>(element); if (ia->isSetMath()) { ast1 = ia->getMath()->deepCopy(); convertCSymbols(ast1, &tcfdiv, &tcftimes); ia->setMath(ast1); delete ast1; } break; case SBML_CONSTRAINT: //Constraints need csymbols converted. constraint = static_cast<Constraint*>(element); if (constraint->isSetMath()) { ast1 = constraint->getMath()->deepCopy(); convertCSymbols(ast1, &tcfdiv, &tcftimes); constraint->setMath(ast1); delete ast1; } break; case SBML_PRIORITY: //Priorities need csymbols converted. priority = static_cast<Priority*>(element); if (priority->isSetMath()) { ast1 = priority->getMath()->deepCopy(); convertCSymbols(ast1, &tcfdiv, &tcftimes); priority->setMath(ast1); delete ast1; } break; case SBML_TRIGGER: //Triggers need csymbols converted. trigger = static_cast<Trigger*>(element); if (trigger->isSetMath()) { ast1 = trigger->getMath()->deepCopy(); convertCSymbols(ast1, &tcfdiv, &tcftimes); trigger->setMath(ast1); delete ast1; } break; default: //Do nothing! If we wanted to call a plugin routine, this would be the place. The only other alternative is to #ifdef some code in here that deals with the math-containing package objects explicitly. Which might be the best option, all told. break; } } } delete allElements; return LIBSBML_OPERATION_SUCCESS; }
TestApplicationClient(){ string user("postgres"); string rmHost("localhost"); string rmPort("8032"); string tokenService = ""; Yarn::Config config; Yarn::Internal::SessionConfig sessionConfig(config); MockApplicationClientProtocol *protocol = new MockApplicationClientProtocol(user,rmHost,rmPort,tokenService, sessionConfig); ApplicationId appId; appId.setId(100); appId.setClusterTimestamp(1454307175682); GetNewApplicationResponse getNewApplicationResponse; getNewApplicationResponse.setApplicationId(appId); EXPECT_CALL((*protocol),getNewApplication(_)).Times(AnyNumber()).WillOnce(Return(getNewApplicationResponse)); EXPECT_CALL((*protocol),submitApplication(_)).Times(AnyNumber()).WillOnce(Return()); ApplicationReport appReport; appReport.setApplicationId(appId); appReport.setUser(user); string queue("default"); string appName("hawq"); string hostname("master"); appReport.setQueue(queue); appReport.setName(appName); appReport.setHost(hostname); appReport.setRpcPort(8090); appReport.setProgress(0.5); GetApplicationReportResponse appReportResponse; appReportResponse.setApplicationReport(appReport); EXPECT_CALL((*protocol),getApplicationReport(_)).Times(AnyNumber()).WillOnce(Return(appReportResponse)); ContainerId containerId; containerId.setId(501); containerId.setApplicationId(appId); Resource resource; resource.setMemory(1024); resource.setVirtualCores(1); Priority priority; priority.setPriority(1); ContainerReport report; report.setId(containerId); report.setResource(resource); report.setPriority(priority); list<ContainerReport> reportList; reportList.push_back(report); GetContainersResponse getContainersResponse; getContainersResponse.setContainersReportList(reportList); EXPECT_CALL((*protocol),getContainers(_)).Times(AnyNumber()).WillOnce(Return(getContainersResponse)); NodeId nodeId; string nodeHost("node1"); nodeId.setHost(nodeHost); nodeId.setPort(9983); NodeReport nodeReport; nodeReport.setNodeId(nodeId); string rackName("default-rack"); nodeReport.setRackName(rackName); nodeReport.setNumContainers(8); Resource nodeResource; nodeResource.setMemory(2048*8); nodeResource.setVirtualCores(8); nodeReport.setResourceCapablity(nodeResource); nodeReport.setNodeState(NodeState::NS_RUNNING); list<NodeReport> nodeReportList; nodeReportList.push_back(nodeReport); GetClusterNodesResponse getClusterNodesResponse; getClusterNodesResponse.setNodeReports(nodeReportList); EXPECT_CALL((*protocol),getClusterNodes(_)).Times(AnyNumber()).WillOnce(Return(getClusterNodesResponse)); QueueInfo queueInfo; queueInfo.setQueueName(queue); queueInfo.setCapacity(0.67); queueInfo.setMaximumCapacity(0.95); queueInfo.setCurrentCapacity(0.5); queueInfo.setQueueState(QueueState::Q_RUNNING); QueueInfo childQueue; string childQueueName("hawq-queue"); childQueue.setQueueName(childQueueName); childQueue.setCapacity(0.33); childQueue.setMaximumCapacity(0.5); childQueue.setCurrentCapacity(0.25); list<QueueInfo> childQueueList; childQueueList.push_back(childQueue); queueInfo.setChildQueues(childQueueList); list<ApplicationReport> appReportList; appReportList.push_back(appReport); queueInfo.setApplicationReports(appReportList); GetQueueInfoResponse getQueueInfoResponse; getQueueInfoResponse.setQueueInfo(queueInfo); EXPECT_CALL((*protocol),getQueueInfo(_)).Times(AnyNumber()).WillOnce(Return(getQueueInfoResponse)); KillApplicationResponseProto killApplicationResponseProto; EXPECT_CALL((*protocol),forceKillApplication(_)).Times(AnyNumber()).WillOnce(Return(KillApplicationResponse(killApplicationResponseProto))); YarnClusterMetrics metrics; metrics.setNumNodeManagers(10); GetClusterMetricsResponse clusterMetricsResponse; clusterMetricsResponse.setClusterMetrics(metrics); EXPECT_CALL((*protocol),getClusterMetrics(_)).Times(AnyNumber()).WillOnce(Return(clusterMetricsResponse)); GetApplicationsResponse applicationsResponse; applicationsResponse.setApplicationList(appReportList); EXPECT_CALL((*protocol),getApplications(_)).Times(AnyNumber()).WillOnce(Return(applicationsResponse)); QueueUserACLInfo aclInfo; aclInfo.setQueueName(queue); list<QueueACL> queueACLList; QueueACL acl1 = QueueACL::QACL_ADMINISTER_QUEUE; QueueACL acl2 = QueueACL::QACL_SUBMIT_APPLICATIONS; queueACLList.push_back(acl1); queueACLList.push_back(acl2); aclInfo.setUserAcls(queueACLList); list<QueueUserACLInfo> aclInfoList; aclInfoList.push_back(aclInfo); GetQueueUserAclsInfoResponse queueUserAclsInfoResponse; queueUserAclsInfoResponse.setUserAclsInfoList(aclInfoList); EXPECT_CALL((*protocol),getQueueAclsInfo(_)).Times(AnyNumber()).WillOnce(Return(queueUserAclsInfoResponse)); client = new ApplicationClient(protocol); }
/** Set up the given session with the settings in this profile */ void SetupSession(gnutls_session_t sess) { priority.SetupSession(sess); x509cred.SetupSession(sess); gnutls_dh_set_prime_bits(sess, min_dh_bits); }
bool operator()(const Priority &p1, const Priority &p2) const { return p1.getValue() > p2.getValue(); }