CF::AllocationManager::AllocationResponseSequence* AllocationManager_impl::allocateDevices(const CF::AllocationManager::AllocationRequestSequence &requests, ossie::DeviceList& devices, const std::string& domainName)
{
    LOG_TRACE(AllocationManager_impl, "Servicing " << requests.length() << " allocation request(s)");
    CF::AllocationManager::AllocationResponseSequence_var response = new CF::AllocationManager::AllocationResponseSequence();

    typedef std::list<ossie::AllocationType*> LocalAllocationList;
    LocalAllocationList local_allocations;

    for (unsigned int request_idx=0; request_idx<requests.length(); request_idx++) {
        const CF::AllocationManager::AllocationRequestType& request = requests[request_idx];
        const std::string requestID(request.requestID);
        LOG_TRACE(AllocationManager_impl, "Allocation request " << requestID
                  << " contains " << request.allocationProperties.length() << " properties");

        // Get device identifiers, and ensure that no device references are nil
        std::vector<std::string> requestedDeviceIDs;
        for (unsigned int device_idx = 0; device_idx < request.requestedDevices.length(); ++device_idx) {
            CF::Device_ptr device = request.requestedDevices[device_idx];
            if (!CORBA::is_nil(device)) {
                requestedDeviceIDs.push_back(ossie::corba::returnString(device->identifier()));
            }
        }
        if (requestedDeviceIDs.size() != request.requestedDevices.length()) {
            // At least one requested device was nil
            continue;
        }

        // If a requested device list was given, skip devices not in list
        ossie::DeviceList requestedDevices = devices;
        if (!requestedDeviceIDs.empty()) {
            for (ossie::DeviceList::iterator node = requestedDevices.begin(); node != requestedDevices.end(); ++node) {
                if (std::find(requestedDeviceIDs.begin(), requestedDeviceIDs.end(), (*node)->identifier) == requestedDeviceIDs.end()) {
                    node = requestedDevices.erase(node);
                }
            }
        }

        std::pair<ossie::AllocationType*,ossie::DeviceList::iterator> result = allocateRequest(requestID, request.allocationProperties, requestedDevices, std::vector<std::string>(), std::vector<ossie::SPD::NameVersionPair>(), domainName);
        if (result.first) {
            local_allocations.push_back(result.first);
            ossie::AllocationType* allocation(result.first);
            const std::string requestID(request.requestID);
            ossie::corba::push_back(response, ossie::assembleResponse(requestID, allocation->allocationID, allocation->allocationProperties, allocation->allocatedDevice, allocation->allocationDeviceManager));
        }
    }

    // Update the database
    boost::recursive_mutex::scoped_lock lock(allocationAccess);
    for (LocalAllocationList::iterator alloc = local_allocations.begin(); alloc != local_allocations.end(); ++alloc) {
        this->_allocations[(*alloc)->allocationID] = **alloc;
        delete *alloc;
    }

    if (response->length() != 0) {
        this->_domainManager->updateLocalAllocations(this->_allocations);
    }
    return response._retn();
}
ossie::AllocationResult AllocationManager_impl::allocateDeployment(const std::string& requestID, const CF::Properties& allocationProperties, ossie::DeviceList& devices, const std::vector<std::string>& processorDeps, const std::vector<ossie::SPD::NameVersionPair>& osDeps)
{
    const std::string domainName = this->_domainManager->getDomainManagerName();
    std::pair<ossie::AllocationType*,ossie::DeviceList::iterator> result = allocateRequest(requestID, allocationProperties, devices, processorDeps, osDeps, domainName);
    if (result.first) {
        // Update the allocation table, including the persistence store
        const std::string allocationID = result.first->allocationID;
        boost::recursive_mutex::scoped_lock lock(allocationAccess);
        this->_allocations[allocationID] = *(result.first);
        this->_domainManager->updateLocalAllocations(this->_allocations);

        // Delete the temporary
        delete result.first;

        return ossie::AllocationResult(allocationID, *result.second);
    }
    return std::make_pair(std::string(), boost::shared_ptr<ossie::DeviceNode>());
}
Пример #3
0
void obtainOptimalStateValue(multimap<double,cEvent>& _event_multimap,vector<cServer>& _server_vec)
{
	multimap<double,cEvent>::iterator iter_event_multimap;
	counting = -1;

	//store the number of accepted requests corresponding to each type of requests
	map<requesttype,unsigned int> hosted_requests_type_num_map;
	map<requesttype,unsigned int>::iterator iter_find_hosted_request_num_map;
	
	map<ID,cRequest*>  hosted_request_map;
	map<ID,cRequest*>::iterator iter_find_request_map;

	
	for (iter_event_multimap = _event_multimap.begin();iter_event_multimap != _event_multimap.end();iter_event_multimap++)
	{		
		if (iter_event_multimap->second.getEventType() == DEPARTURE)
		{
			//set current time
			current_time = iter_event_multimap->first;
			
			//delete the request from the hosting list
			iter_find_request_map = hosted_request_map.find((iter_event_multimap->second.getRequest())->getID());

			if (iter_find_request_map == hosted_request_map.end())
			{
				cout<<"Error!!!Can not locate the request that should exist in the hosting list!"<<endl;
				exit(0);
			}

			hosted_request_map.erase(iter_find_request_map);

			//minus 1 from the entry corresponding the type of currently departing requests in the counting list of hosting requests
			iter_find_hosted_request_num_map = hosted_requests_type_num_map.find((iter_event_multimap->second.getRequest())->getRequestType());
			if (iter_find_hosted_request_num_map == hosted_requests_type_num_map.end())
			{
				cout<<"Error!!!Can not locate the request that should exist in the counting list of types of the hosting requests!"<<endl;
				exit(0);
			}
			else
				(iter_find_hosted_request_num_map->second)--;

			//release the resources allocated to the request
			releaseRequest(iter_event_multimap->second.getRequest());


			//update the value of current system state after any request departure
			//system_state.first = NONE;
			//updateStateValueRequDepar(_server_vec,hosted_request_map,hosted_requests_type_num_map);
			//system_state.second = calculateRequestDepartureStateIndicator(_server_vec,iter_event_multimap->second.getRequest());
		}
		else
		{
			//set current time
			current_time = iter_event_multimap->first;
			
			//a request is arriving
			counting++;
			//update the system state
			system_state.first = (iter_event_multimap->second.getRequest())->getRequestType();

			//we should determine which action should be take base on the purpose of maximizing the expected profits
			//if(obtainOptimalAction(&(iter_event_multimap->second),_server_vec,hosted_requests_type_num_map,hosted_request_map))
            if(obtainOptimalAction(&(iter_event_multimap->second),_server_vec,hosted_requests_type_num_map,hosted_request_map))
			{
				//if the arriving request is accepted, we should allocate physical resources for it and insert a departure event into the event list
				(iter_event_multimap->second.getRequest())->setAccepted(true);
				allocateRequest(iter_event_multimap->second.getRequest());
				insertDepartureEvent(iter_event_multimap->second.getRequest(),_event_multimap);
				accepted_requests_num++;

				hosted_request_map.insert(make_pair((iter_event_multimap->second.getRequest())->getID(),iter_event_multimap->second.getRequest()));

				iter_find_hosted_request_num_map = hosted_requests_type_num_map.find((iter_event_multimap->second.getRequest())->getRequestType());
				if (iter_find_hosted_request_num_map == hosted_requests_type_num_map.end())
				{
					//there is no request in the system which has the same type as currently arriving request
					hosted_requests_type_num_map.insert(make_pair((iter_event_multimap->second.getRequest())->getRequestType(),1));
				}
				else
					(iter_find_hosted_request_num_map->second)++;
				
			}
			else
			{
				//do nothing
				//the arriving request is rejected due to 1) having not enough residual resources, or 2) maximizing profits policy
				(iter_event_multimap->second.getRequest())->setAccepted(false);

				//update the value of current system state after any request departure
				system_state.first = NONE;
				updateStateValueRequDepar(_server_vec,hosted_request_map,hosted_requests_type_num_map);
			}

		}
	}

	return ;
}