Search in sources :

Example 1 with ComputeElement

use of com.emc.storageos.db.client.model.ComputeElement in project coprhd-controller by CoprHD.

the class HostService method pickBladesByStrafingAlgorithm.

private List<URI> pickBladesByStrafingAlgorithm(List<URI> availableList, int numRequiredBlades, List<ComputeElement> usedCEList) throws DatabaseException {
    if (usedCEList == null) {
        usedCEList = new ArrayList<ComputeElement>();
    }
    _log.debug("In pickBladesByStrafingAlgorithm");
    List<URI> selectedCEList = new ArrayList<URI>();
    List<ComputeElement> availableCEList = new ArrayList<ComputeElement>();
    // if useUsedSlots is false, on each of those chassis, find the slot that has maximum available slots
    for (URI uri : availableList) {
        ComputeElement computeElement = _dbClient.queryObject(ComputeElement.class, uri);
        _log.debug("computeElement:" + computeElement.getLabel() + " chassisId:" + computeElement.getChassisId() + " slotId:" + computeElement.getSlotId());
        // ComputeSystem cs = _dbClient.queryObject(ComputeSystem.class,computeElement.getComputeSystem());
        availableCEList.add(computeElement);
    }
    int numChassis = 0;
    int numSlot = 0;
    for (ComputeElement ce : availableCEList) {
        int chassisId = Integer.parseInt(ce.getChassisId());
        long slotId = ce.getSlotId();
        if (chassisId > numChassis) {
            numChassis = chassisId;
        }
        if (slotId > numSlot) {
            numSlot = (int) slotId;
        }
    }
    for (ComputeElement ce : usedCEList) {
        int chassisId = Integer.parseInt(ce.getChassisId());
        long slotId = ce.getSlotId();
        if (chassisId > numChassis) {
            numChassis = chassisId;
        }
        if (slotId > numSlot) {
            numSlot = (int) slotId;
        }
    }
    int M = numChassis + 1;
    int N = numSlot + 1;
    _log.debug("M:" + M + " N:" + N);
    int[][] availableBlades = new int[M][N];
    Map<String, URI> availableBladesByChassisIdAndSlotId = new HashMap<String, URI>();
    for (ComputeElement ce : availableCEList) {
        int chassisId = Integer.parseInt(ce.getChassisId());
        long l_slotId = ce.getSlotId();
        int slotId = (int) l_slotId;
        if (ce.getAvailable()) {
            availableBlades[chassisId][slotId] = 1;
            availableBladesByChassisIdAndSlotId.put(chassisId + "," + slotId, ce.getId());
        } else {
            availableBlades[chassisId][slotId] = 0;
        }
    }
    int[][] usedBlades = new int[M][N];
    for (ComputeElement ce : usedCEList) {
        int chassisId = Integer.parseInt(ce.getChassisId());
        long l_slotId = ce.getSlotId();
        int slotId = (int) l_slotId;
        usedBlades[chassisId][slotId] = 1;
    }
    Map<Integer, Integer> chassisIdToCountMap = new HashMap<Integer, Integer>();
    Map<Integer, Set<Integer>> chassisUsageMap = new TreeMap<Integer, Set<Integer>>();
    List<Integer> unusedChassisIds = new ArrayList<Integer>();
    for (int chassisId = 1; chassisId <= numChassis; chassisId++) {
        int chassisUsageCount = 0;
        for (int slotId = 1; slotId <= numSlot; slotId++) {
            chassisUsageCount = chassisUsageCount + usedBlades[chassisId][slotId];
        }
        Integer key = Integer.valueOf(chassisUsageCount);
        Set<Integer> chassisIdSet = chassisUsageMap.get(key);
        if (chassisIdSet == null) {
            chassisIdSet = new HashSet<Integer>();
        }
        chassisIdSet.add(Integer.valueOf(chassisId));
        chassisUsageMap.put(chassisUsageCount, chassisIdSet);
        chassisIdToCountMap.put(Integer.valueOf(chassisId), Integer.valueOf(chassisUsageCount));
        if (chassisUsageCount == 0) {
            unusedChassisIds.add(chassisId);
        }
        _log.debug("chassisId:" + chassisId + " usageCount:" + chassisUsageCount);
    }
    for (int chassisId : unusedChassisIds) {
        _log.debug("unusedChassis:" + chassisId);
    }
    Map<Integer, Integer> slotIdToCountMap = new HashMap<Integer, Integer>();
    NavigableMap<Integer, Set<Integer>> slotUsageMap = new TreeMap<Integer, Set<Integer>>();
    for (int slotId = 1; slotId <= numSlot; slotId++) {
        int slotUsageCount = 0;
        for (int chassisId = 1; chassisId <= numChassis; chassisId++) {
            slotUsageCount = slotUsageCount + usedBlades[chassisId][slotId];
        }
        Integer key = Integer.valueOf(slotUsageCount);
        Set<Integer> slotIdSet = slotUsageMap.get(key);
        if (slotIdSet == null) {
            slotIdSet = new HashSet<Integer>();
        }
        slotIdSet.add(Integer.valueOf(slotId));
        slotUsageMap.put(slotUsageCount, slotIdSet);
        slotIdToCountMap.put(Integer.valueOf(slotId), Integer.valueOf(slotUsageCount));
        _log.debug("slotId:" + slotId + " usageCount:" + slotUsageCount);
    }
    // sort the slotUsageMap by its keys in descending order
    Map<Integer, Set<Integer>> descSlotUsageMap = slotUsageMap.descendingMap();
    boolean useUsedSlots = true;
    if (usedCEList.isEmpty()) {
        useUsedSlots = false;
    }
    boolean avoidUsedChassis = true;
    if (unusedChassisIds.isEmpty()) {
        avoidUsedChassis = false;
    }
    List<String> selectedBlades = new ArrayList<String>();
    while (numRequiredBlades > 0) {
        if (!useUsedSlots) {
            // No slots used so far.
            // Now find the slot or slots which are max available
            _log.debug("No slots used so far. Find max available slot.");
            int selectedSlotId = 0;
            int maxSum = 0;
            for (int slotId = 1; slotId <= numSlot; slotId++) {
                int sum = 0;
                for (int chassisId = 1; chassisId <= numChassis; chassisId++) {
                    sum = sum + availableBlades[chassisId][slotId];
                }
                if (sum > maxSum) {
                    selectedSlotId = slotId;
                    maxSum = sum;
                    if (sum >= numRequiredBlades) {
                        // satisfy numRequiredBlades
                        break;
                    }
                }
            }
            _log.debug("max available slot is:" + selectedSlotId);
            // From selected slot pick as many blades as possible
            for (int chassisId = 1; chassisId <= numChassis; chassisId++) {
                if (availableBlades[chassisId][selectedSlotId] == 1) {
                    _log.debug("selected blade " + chassisId + "/" + selectedSlotId);
                    selectedBlades.add(chassisId + "," + selectedSlotId);
                    availableBlades[chassisId][selectedSlotId] = 0;
                    numRequiredBlades--;
                    if (numRequiredBlades == 0) {
                        break;
                    }
                }
            }
            useUsedSlots = true;
        } else {
            Set<Integer> preferredChassisIds = new HashSet<Integer>();
            if (avoidUsedChassis) {
                _log.debug("Pick from unused chassis first");
                preferredChassisIds.addAll(unusedChassisIds);
                // Pick blades from the max used slots on the preferred chassis
                // Starting with max used slot, loop thru slots to find ones that are available on preferred chassis
                Iterator<Integer> iter = descSlotUsageMap.keySet().iterator();
                while (iter.hasNext()) {
                    Integer slotUsageCount = iter.next();
                    // slotIds with max usage
                    Set<Integer> preferredSlotIds = descSlotUsageMap.get(slotUsageCount);
                    /*
                         * This is not part of the blade strafing algorithm in UIM. Hence commenting out.
                         * Uncomment if this modification to algorithm is required.
                         * //Order these slots that have same slotUSageCount, in descending order of number of available
                         * blades on unused
                         * chassis.
                         * NavigableMap<Integer,Set<Integer> >slotIdAvailabilityMap = new
                         * TreeMap<Integer,Set<Integer>>();
                         * for (int slotId : preferredSlotIds){
                         * int availabilityCount = 0;
                         * for (int chassisId : preferredChassisIds){
                         * if (availableBlades[chassisId][slotId] ==1){
                         * availabilityCount++;
                         * }
                         * }
                         * Set<Integer> slotIdSet = slotIdAvailabilityMap.get(availabilityCount);
                         * if (slotIdSet ==null){
                         * slotIdSet = new HashSet<Integer>();
                         * }
                         * slotIdSet.add(slotId);
                         * slotIdAvailabilityMap.put(availabilityCount,slotIdSet);
                         * }
                         *
                         * Iterator<Integer> iterator = slotIdAvailabilityMap.keySet().iterator();
                         * while(iterator.hasNext()){
                         * Integer availabilityCount = iterator.next();
                         * Set<Integer> mostPreferredSlotIds = slotIdAvailabilityMap.get(availabilityCount);
                         * for (int slotId : mostPreferredSlotIds){
                         * Comment the next statement - for(int slotId : preferredSlotIds) when uncommenting this
                         * section
                         */
                    for (int slotId : preferredSlotIds) {
                        _log.debug("preferred slotId: " + slotId + " with usage count: " + slotUsageCount);
                        for (int chassisId : preferredChassisIds) {
                            if (availableBlades[chassisId][slotId] == 1) {
                                _log.debug("selected Blade: " + chassisId + "/" + slotId);
                                selectedBlades.add(chassisId + "," + slotId);
                                availableBlades[chassisId][slotId] = 0;
                                numRequiredBlades--;
                                unusedChassisIds.remove((Integer) chassisId);
                                Integer currentCount = chassisIdToCountMap.get(chassisId);
                                chassisIdToCountMap.put(chassisId, currentCount + 1);
                                // updateChassisUsageMap
                                chassisUsageMap = updateChassisUsageMap(chassisIdToCountMap);
                                if (numRequiredBlades == 0) {
                                    break;
                                }
                            }
                        }
                        if (numRequiredBlades == 0) {
                            break;
                        }
                    }
                }
                avoidUsedChassis = false;
            } else {
                _log.debug(" No more blades from unused chassis. Pick from least used chassis.");
                Iterator<Integer> iter = chassisUsageMap.keySet().iterator();
                while (iter.hasNext()) {
                    Integer chassisUsageCount = iter.next();
                    // chassisIds with least usage
                    preferredChassisIds = chassisUsageMap.get(chassisUsageCount);
                    // Pick blades from preferredChassis
                    for (int chassisId : preferredChassisIds) {
                        int count = 0;
                        _log.debug("preferred chassis :" + chassisId + "with usgae count:" + chassisUsageCount);
                        for (int slotId = 1; slotId <= numSlot; slotId++) {
                            if (availableBlades[chassisId][slotId] == 1) {
                                numRequiredBlades--;
                                _log.debug("selected blade: " + chassisId + "/" + slotId);
                                selectedBlades.add(chassisId + "," + slotId);
                                count++;
                                if (preferredChassisIds.size() > 1) {
                                    // preferred chassis
                                    break;
                                }
                                if (numRequiredBlades == 0) {
                                    break;
                                }
                            }
                        }
                        if (count > 0) {
                            unusedChassisIds.remove((Integer) chassisId);
                            Integer currentCount = chassisIdToCountMap.get(chassisId);
                            chassisIdToCountMap.put(chassisId, currentCount + count);
                            // updateChassisUsageMap
                            chassisUsageMap = updateChassisUsageMap(chassisIdToCountMap);
                        }
                        if (numRequiredBlades == 0) {
                            break;
                        }
                    }
                    if (numRequiredBlades == 0) {
                        break;
                    }
                }
            }
        }
    }
    StringBuffer sbuf = new StringBuffer();
    sbuf.append("Selected Blades are:\n");
    for (String blade : selectedBlades) {
        sbuf.append("Blade " + blade);
        URI ceURI = availableBladesByChassisIdAndSlotId.get(blade);
        selectedCEList.add(ceURI);
    }
    _log.debug(sbuf.toString());
    return selectedCEList;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) StringSet(com.emc.storageos.db.client.model.StringSet) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) URI(java.net.URI) HashSet(java.util.HashSet) TreeMap(java.util.TreeMap) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) ComputeElement(com.emc.storageos.db.client.model.ComputeElement)

Example 2 with ComputeElement

use of com.emc.storageos.db.client.model.ComputeElement in project coprhd-controller by CoprHD.

the class HostService method getHost.

/**
 * Gets the information for one host.
 *
 * @param id
 *            the URN of a ViPR Host
 * @brief Show host
 * @return All the non-null attributes of the host.
 * @throws DatabaseException
 *             when a DB error occurs.
 */
@GET
@Path("/{id}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public HostRestRep getHost(@PathParam("id") URI id) throws DatabaseException {
    Host host = queryObject(Host.class, id, false);
    // check the user permissions
    verifyAuthorizedInTenantOrg(host.getTenant(), getUserFromContext());
    ComputeElement computeElement = null;
    UCSServiceProfile serviceProfile = null;
    ComputeSystem computeSystem = null;
    if (!NullColumnValueGetter.isNullURI(host.getComputeElement())) {
        computeElement = queryObject(ComputeElement.class, host.getComputeElement(), false);
    }
    if (!NullColumnValueGetter.isNullURI(host.getServiceProfile())) {
        serviceProfile = queryObject(UCSServiceProfile.class, host.getServiceProfile(), false);
    }
    if (serviceProfile != null) {
        computeSystem = queryObject(ComputeSystem.class, serviceProfile.getComputeSystem(), false);
    } else if (computeElement != null) {
        computeSystem = queryObject(ComputeSystem.class, computeElement.getComputeSystem(), false);
    }
    return map(host, computeElement, serviceProfile, computeSystem);
}
Also used : UCSServiceProfile(com.emc.storageos.db.client.model.UCSServiceProfile) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) Host(com.emc.storageos.db.client.model.Host) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 3 with ComputeElement

use of com.emc.storageos.db.client.model.ComputeElement in project coprhd-controller by CoprHD.

the class UcsDiscoveryWorker method reconcileComputeBlades.

private void reconcileComputeBlades(ComputeSystem cs, List<ComputeBlade> computeBlades, Map<String, LsServer> associatedLsServers) {
    _log.info("reconciling ComputeBlades");
    Map<String, ComputeElement> removeBlades = new HashMap<>();
    Map<String, ComputeElement> updateBlades = new HashMap<>();
    Map<String, ComputeElement> addBlades = new HashMap<>();
    URIQueryResultList uris = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSystemComputeElemetsConstraint(cs.getId()), uris);
    List<ComputeElement> elements = _dbClient.queryObject(ComputeElement.class, uris, true);
    for (ComputeElement element : elements) {
        removeBlades.put(element.getLabel(), element);
    }
    for (ComputeBlade computeBlade : computeBlades) {
        ComputeElement ce = removeBlades.get(computeBlade.getDn());
        LsServer lsServer = associatedLsServers.get(computeBlade.getDn());
        if (ce != null) {
            updateComputeElement(ce, computeBlade, lsServer);
            updateBlades.put(ce.getLabel(), ce);
            removeBlades.remove(computeBlade.getDn());
        } else {
            ce = new ComputeElement();
            createComputeElement(cs, ce, computeBlade, lsServer);
            addBlades.put(computeBlade.getDn(), ce);
        }
    }
    createDataObjects(new ArrayList<DataObject>(addBlades.values()));
    persistDataObjects(new ArrayList<DataObject>(updateBlades.values()));
    if (!removeBlades.isEmpty()) {
        for (String name : removeBlades.keySet()) {
            _log.info("Marked for deletion ComputeElement name:" + name);
        }
        removeBladesFromComputeVirtualPools(removeBlades.values());
        removeBladesFromHosts(removeBlades.values());
        deleteDataObjects(new ArrayList<DataObject>(removeBlades.values()));
    }
}
Also used : DataObject(com.emc.storageos.db.client.model.DataObject) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) HashMap(java.util.HashMap) ComputeBlade(com.emc.cloud.platform.ucs.out.model.ComputeBlade) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 4 with ComputeElement

use of com.emc.storageos.db.client.model.ComputeElement in project coprhd-controller by CoprHD.

the class UcsDiscoveryWorker method removeBladesFromComputeVirtualPools.

private void removeBladesFromComputeVirtualPools(Collection<ComputeElement> removeBlades) {
    List<URI> ids = _dbClient.queryByType(ComputeVirtualPool.class, true);
    Iterator<ComputeVirtualPool> iter = _dbClient.queryIterativeObjects(ComputeVirtualPool.class, ids);
    while (iter.hasNext()) {
        Boolean dbUpdateRequired = false;
        ComputeVirtualPool cvp = iter.next();
        for (ComputeElement computeElement : removeBlades) {
            if (cvp.getMatchedComputeElements() != null && cvp.getMatchedComputeElements().contains(computeElement.getId().toString())) {
                _log.info("Removing ComputeElement {} from ComputeVirtualPool {} ", computeElement.getDn(), cvp.getLabel());
                cvp.removeMatchedComputeElement(computeElement.getId().toString());
                dbUpdateRequired = true;
            }
        }
        if (dbUpdateRequired) {
            _log.info("Persisting ComputeVirtualPool {},after ComputeElement removal", cvp.getLabel());
            _dbClient.persistObject(cvp);
        }
    }
}
Also used : ComputeElement(com.emc.storageos.db.client.model.ComputeElement) URI(java.net.URI) ComputeVirtualPool(com.emc.storageos.db.client.model.ComputeVirtualPool)

Example 5 with ComputeElement

use of com.emc.storageos.db.client.model.ComputeElement in project coprhd-controller by CoprHD.

the class UcsComputeDevice method setNoBoot.

@Override
public void setNoBoot(ComputeSystem cs, URI computeElementId, URI hostId, boolean waitForServerRestart) throws InternalException {
    ComputeElement computeElement = _dbClient.queryObject(ComputeElement.class, computeElementId);
    try {
        if (null != computeElement) {
            StringBuilder errorMessage = new StringBuilder();
            LsServer lsServer = ucsmService.setServiceProfileToNoBoot(getUcsmURL(cs).toString(), cs.getUsername(), cs.getPassword(), computeElement.getDn(), errorMessage);
            if (lsServer != null) {
                if (waitForServerRestart) {
                    pullAndPollManagedObject(getUcsmURL(cs).toString(), cs.getUsername(), cs.getPassword(), computeElement.getDn(), LsServer.class);
                }
            } else {
                throw new RuntimeException("Failed to set no boot target due to error from UCSM Service. \n " + errorMessage.toString());
            }
        } else {
            throw new RuntimeException("ComputeElement object is null for id " + computeElementId);
        }
    } catch (Exception e) {
        throw ComputeSystemControllerException.exceptions.unableToSetNoBoot(computeElement != null ? computeElement.getLabel() : computeElementId.toString(), e);
    }
}
Also used : ComputeElement(com.emc.storageos.db.client.model.ComputeElement) LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ComputeSystemControllerTimeoutException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerTimeoutException) MalformedURLException(java.net.MalformedURLException) ClientGeneralException(com.emc.cloud.platform.clientlib.ClientGeneralException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)

Aggregations

ComputeElement (com.emc.storageos.db.client.model.ComputeElement)52 Host (com.emc.storageos.db.client.model.Host)24 URI (java.net.URI)20 ComputeSystem (com.emc.storageos.db.client.model.ComputeSystem)15 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)12 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)11 ClientGeneralException (com.emc.cloud.platform.clientlib.ClientGeneralException)10 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)10 LsServer (com.emc.cloud.platform.ucs.out.model.LsServer)9 MalformedURLException (java.net.MalformedURLException)9 Produces (javax.ws.rs.Produces)9 ComputeSystemControllerTimeoutException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerTimeoutException)8 HashMap (java.util.HashMap)8 Path (javax.ws.rs.Path)8 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)7 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)7 ComputeVirtualPool (com.emc.storageos.db.client.model.ComputeVirtualPool)6 UCSServiceProfile (com.emc.storageos.db.client.model.UCSServiceProfile)6 UCSServiceProfileTemplate (com.emc.storageos.db.client.model.UCSServiceProfileTemplate)6 Cluster (com.emc.storageos.db.client.model.Cluster)4