void Locality_Splitter::prepare_sub_plan ( uint32_t instance, Deployment::DeploymentPlan &sub_plan, KEY &sub_plan_key) { DANCEX11_LOG_TRACE ("Locality_Splitter::prepare_sub_plan"); // first time? if (sub_plan_key.uuid ().empty ()) { // use UUID to uniquely identify sub plan key sub_plan_key.uuid (sub_plan.UUID ()); } if (sub_plan_key.node () != this->plan_.instance ()[instance].node ()) { // set sub plan key to node name for instance sub_plan_key.node (this->plan_.instance ()[instance].node ()); } if (!sub_plan_key.has_instance (instance)) { sub_plan_key.add_instance (instance); if (!sub_plan_key.has_locality_manager ()) { // check if this is the LocalityManager instance uint32_t impl_idx = this->plan_.instance ()[instance].implementationRef (); if (impl_idx >= this->plan_.implementation ().size ()) { DANCEX11_LOG_ERROR ("Locality_Splitter::prepare_sub_plan - " << "Invalid implementation index"); } else { const std::string instance_type = DAnCE::Utility::get_instance_type ( plan_.implementation ()[impl_idx].execParameter ()); if (!instance_type.empty ()) { if (instance_type == DANCE_LOCALITYMANAGER) { // mark locality manager instance offset sub_plan_key.locality_manager_instance ( sub_plan_key.instances ().size () - 1); DANCEX11_LOG_TRACE ("Locality_Splitter::prepare_sub_plan - " << "Found locality manager instance " << instance << ":" << plan_.instance ()[instance].name ()); } } } } } if (sub_plan.label ().empty ()) { // derive descriptive label std::string sub_label ("Split plan from "); if (!this->plan_.label ().empty ()) { sub_label += this->plan_.label (); } else { sub_label += this->plan_.UUID (); } sub_label += " for a Locality on Node "; sub_label += sub_plan_key.node (); sub_plan.label (sub_label); } }
bool Locality_Splitter::match_sub_plan ( uint32_t instance, const KEY &sub_plan_key) const { DANCEX11_LOG_TRACE ("Locality_Splitter::match_sub_plan"); // check if the node for the instance matches the sub plan bool match = (sub_plan_key.node () == this->plan_.instance ()[instance].node ()); // if the node matches see if the instance is or can be included in the // sub plan if (match) { if (sub_plan_key.has_instance (instance)) return true; // matches // see if the locality constraints allow this instance to be // included in this sub plan uint32_t num_localities = this->plan_.localityConstraint ().size (); for (uint32_t l = 0; l < num_localities; ++l) { const Deployment::PlanLocality &ploc = this->plan_.localityConstraint ()[l]; // only interested in real constraints if (ploc.constraint () != Deployment::PlanLocalityKind::PlanNoConstraint) { // see if the instance we're matching is // included in this constraint bool apply_constraint = false; for (uint32_t i = 0; i < ploc.constrainedInstanceRef ().size (); ++i) { apply_constraint = ploc.constrainedInstanceRef ()[i] == instance; if (apply_constraint) break; } if (ploc.constraint () == Deployment::PlanLocalityKind::PlanDifferentProcess) { if (apply_constraint) // in case the constraint applies { // check if there are no incompatible // instances already in // the sub plan we're matching for (uint32_t i = 0; i < ploc.constrainedInstanceRef ().size (); ++i) { if (ploc.constrainedInstanceRef ()[i] != instance) { uint32_t incompatible_instance = ploc.constrainedInstanceRef ()[i]; if (sub_plan_key.has_instance ( incompatible_instance)) { // sub plan includes an instance which // is constrained to a different locality return false; } } } } // in case the constraint does not apply to the instance // we're matching forget about it } else // Deployment::PlanSameProcess { if (apply_constraint) // in case the constraint applies { // check to see that all instances included in the // sub plan also comply with this constraint // since if one complies with the constraint // than all should, it is enough to test the first // instance in the sub plan if (!sub_plan_key.instances ().empty ()) { uint32_t first_inst_nr = sub_plan_key.instances ().front (); bool included = false; for (uint32_t j = 0; j < ploc.constrainedInstanceRef ().size (); ++j) { if (first_inst_nr == ploc.constrainedInstanceRef ()[j]) { included = true; break; } } if (!included) { // sub plan includes instance(s) which do(es) // not comply with this constraint return false; } } } else { // check to see that the constraint also does *not* // apply to any of the instances included in the sub // plan since if one complies with the constraint than // all should, it is enough to test the first instance // in the sub plan if (!sub_plan_key.instances ().empty ()) { uint32_t first_inst_nr = sub_plan_key.instances ().front (); for (uint32_t j = 0; j < ploc.constrainedInstanceRef ().size (); ++j) { if (first_inst_nr == ploc.constrainedInstanceRef ()[j]) { // sub plan complies with this constraint return false; } } } } } } } } return match; }