Search in sources :

Example 1 with ComputeBlade

use of com.emc.cloud.platform.ucs.out.model.ComputeBlade 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 2 with ComputeBlade

use of com.emc.cloud.platform.ucs.out.model.ComputeBlade in project coprhd-controller by CoprHD.

the class UcsComputeDevice method unbindHostFromComputeElement.

/*
     * Unbinds the host's service profile from the associated blade.
     * Determines the service profile to unbind using host's serviceProfile association.
     * In case of host provisioned using pre-Anakin version of ViPR and no serviceProfile association yet set,
     * serviceprofile to unbind will be determined by trying to find a serviceProfile that matches
     * the computeElement's uuid.
     */
private void unbindHostFromComputeElement(ComputeSystem cs, Host host) throws ClientGeneralException {
    // We already checked for empty initiators in a step before we get here
    if (host != null && !NullColumnValueGetter.isNullURI(host.getComputeElement())) {
        ComputeElement computeElement = _dbClient.queryObject(ComputeElement.class, host.getComputeElement());
        if (computeElement == null) {
            LOGGER.error("Host " + host.getLabel() + " has associated computeElementURI: " + host.getComputeElement() + " which is an invalid reference");
            LOGGER.info("Service profile unbind will not be triggered");
            return;
        }
        String spDn = null;
        LOGGER.info("Host.uuid: " + host.getUuid() + " ComputeElement.uuid: " + computeElement.getUuid());
        if (NullColumnValueGetter.isNullURI(host.getServiceProfile())) {
            LOGGER.error("Host has no asscoaited serviceProfile. Service profile unbind will not be triggered.");
            return;
        }
        UCSServiceProfile serviceProfile = _dbClient.queryObject(UCSServiceProfile.class, host.getServiceProfile());
        if (serviceProfile == null) {
            LOGGER.error("Host " + host.getLabel() + " has associated serviceProfileURI: " + host.getServiceProfile() + " which is an invalid reference");
            LOGGER.info("Service profile unbind will not be triggered");
            return;
        } else {
            spDn = serviceProfile.getDn();
            LOGGER.info("Host.uuid: " + host.getUuid() + " ComputeElement.uuid: " + computeElement.getUuid() + "serviceProfile.uuid:" + serviceProfile.getUuid());
        }
        if (spDn != null) {
            LOGGER.info("Unbinding service profile with dn: " + spDn);
            StringBuilder errorMessage = new StringBuilder();
            LsServer unboundServiceProfile = ucsmService.unbindServiceProfile(getUcsmURL(cs).toString(), cs.getUsername(), cs.getPassword(), spDn, errorMessage);
            LOGGER.info("Operational state of Deleted Service Profile : " + unboundServiceProfile.getOperState());
            ComputeBlade computeBlade = pullAndPollManagedObject(getUcsmURL(cs).toString(), cs.getUsername(), cs.getPassword(), computeElement.getLabel(), ComputeBlade.class);
            if (computeBlade == null) {
                LOGGER.info("ComputeBlade " + computeElement.getLabel() + " not found on UCS");
            } else {
                // Release the computeElement back into the pool as soon as we have unbound it from the service profile
                if (LsServerOperStates.UNASSOCIATED.equals(LsServerOperStates.fromString(computeBlade.getOperState()))) {
                    computeElement.setAvailable(true);
                }
                String originalUuid = computeElement.getOriginalUuid();
                LOGGER.info("ComputeBlade " + computeElement.getLabel() + " setting uuid back to originalUUid: " + originalUuid);
                computeElement.setUuid(originalUuid);
                _dbClient.updateObject(computeElement);
            }
        } else {
            LOGGER.error("spDn is null. Cannot determine the service profile to unbind");
        }
    } else {
        LOGGER.info("NO OP. Host is null or has no associated compute element");
    }
}
Also used : UCSServiceProfile(com.emc.storageos.db.client.model.UCSServiceProfile) 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)

Example 3 with ComputeBlade

use of com.emc.cloud.platform.ucs.out.model.ComputeBlade in project coprhd-controller by CoprHD.

the class UCSMServiceImpl method getComputeBlades.

@Override
public List<ComputeBlade> getComputeBlades(String ucsmURL, String username, String password) throws ClientGeneralException {
    List<ComputeBlade> blades = new ArrayList<ComputeBlade>();
    try {
        ComputeSession computeSession = sessionManager.getSession(ucsmURL, username, password);
        ConfigResolveClass configResolveClass = new ConfigResolveClass();
        configResolveClass.setClassId(NamingClassId.COMPUTE_ITEM);
        configResolveClass.setInHierarchical("true");
        com.emc.cloud.platform.ucs.out.model.ConfigResolveClass configResolveClassOut = computeSession.execute(factory.createConfigResolveClass(configResolveClass), com.emc.cloud.platform.ucs.out.model.ConfigResolveClass.class);
        ConfigSet configSet = null;
        if (configResolveClassOut.getContent() != null && !configResolveClassOut.getContent().isEmpty()) {
            for (Object object : configResolveClassOut.getContent()) {
                if (object instanceof JAXBElement<?>) {
                    if (!(((JAXBElement) object).getValue() instanceof ConfigSet)) {
                        continue;
                    }
                    configSet = ((JAXBElement<ConfigSet>) object).getValue();
                    if (configSet != null && configSet.getManagedObject() != null && !configSet.getManagedObject().isEmpty()) {
                        for (JAXBElement<?> managedObject : configSet.getManagedObject()) {
                            if (managedObject.getValue() instanceof ComputeBlade) {
                                blades.add((ComputeBlade) managedObject.getValue());
                            }
                        }
                    }
                }
            }
        }
    } catch (ClientGeneralException e) {
        log.warn("Unable to get compute elements", e);
        throw e;
    }
    return blades;
}
Also used : ComputeBlade(com.emc.cloud.platform.ucs.out.model.ComputeBlade) ArrayList(java.util.ArrayList) ConfigResolveClass(com.emc.cloud.platform.ucs.in.model.ConfigResolveClass) JAXBElement(javax.xml.bind.JAXBElement) ConfigSet(com.emc.cloud.platform.ucs.out.model.ConfigSet) ClientGeneralException(com.emc.cloud.platform.clientlib.ClientGeneralException)

Example 4 with ComputeBlade

use of com.emc.cloud.platform.ucs.out.model.ComputeBlade in project coprhd-controller by CoprHD.

the class UCSMServiceTest method testGetBlades.

@Test(groups = "runByDefault")
public void testGetBlades() throws ClientGeneralException, IllegalAccessException, InvocationTargetException, NoSuchMethodException {
    List<ComputeBlade> blades = ucsmService.getComputeBlades(UCSM_SERVICE, UCSM_HOST_USERNAME, UCSM_HOST_PASSWORD);
    if (blades != null && !blades.isEmpty()) {
        for (ComputeBlade blade : blades) {
            System.out.println(BeanUtils.describe(blade));
        }
    }
    System.out.println("Number of blades found: " + blades.size());
}
Also used : ComputeBlade(com.emc.cloud.platform.ucs.out.model.ComputeBlade) Test(org.testng.annotations.Test)

Example 5 with ComputeBlade

use of com.emc.cloud.platform.ucs.out.model.ComputeBlade in project coprhd-controller by CoprHD.

the class UcsDiscoveryWorker method discoverComputeSystem.

public void discoverComputeSystem(URI computeSystemURI) {
    String ucsmVersion;
    ComputeSystem cs = _dbClient.queryObject(ComputeSystem.class, computeSystemURI);
    _log.info("Inside discoverComputeSystems of class : " + getClass().toString());
    URL ucsmURL = getUcsmURL(cs);
    List<ComputeBlade> computeBlades;
    List<LsServer> allServiceProfiles;
    Map<String, LsServer> associatedLsServers;
    List<LsServer> serviceProfileTemplates;
    List<VnicLanConnTempl> vnicTemplates;
    List<VnicSanConnTempl> vhbaTemplates;
    Map<String, FcPIo> uplinkMap;
    Map<String, SwFcSanEp> fcInterfaceMap;
    List<SwVsan> vsanList;
    Map<String, SwFcSanPc> portChannelMap;
    List<FabricVlan> vlanList;
    List<FabricVsan> vsanFabricList;
    List<com.emc.cloud.platform.ucs.out.model.LsbootPolicy> bootPolicies;
    try {
        ucsmVersion = ucsmService.getDeviceVersion(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        verifyVersion(cs, ucsmVersion);
        computeBlades = ucsmService.getComputeBlades(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        allServiceProfiles = ucsmService.getAllServiceProfiles(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        associatedLsServers = ucsmService.getAllAssociatedLsServers(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        serviceProfileTemplates = ucsmService.getServiceProfileTemplates(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        bootPolicies = ucsmService.getBootPolicies(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        vnicTemplates = ucsmService.getVnicTemplates(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        vhbaTemplates = ucsmService.getVhbaTemplates(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        uplinkMap = ucsmService.getFICUplinkPorts(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        fcInterfaceMap = ucsmService.getSwitchFCInterfaces(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        vsanList = ucsmService.getUcsSwitchVSans(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        portChannelMap = ucsmService.getUplinkPortChannels(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        vlanList = ucsmService.getUcsVlans(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
        vsanFabricList = ucsmService.getUcsFabricVsans(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
    } catch (Exception e) {
        _log.error("Failed to pull device data: " + cs.getId(), e);
        if (e.getCause() != null && e.getCause().getMessage() != null) {
            cs.setLastDiscoveryStatusMessage(e.getCause().getMessage());
        } else {
            cs.setLastDiscoveryStatusMessage(e.getMessage());
        }
        _dbClient.updateObject(cs);
        throw ComputeSystemControllerException.exceptions.discoverFailed(computeSystemURI.toString(), e);
    }
    try {
        reconcileServiceProfileTemplates(cs, serviceProfileTemplates);
        reconcileServiceProfiles(cs, allServiceProfiles);
        reconcileComputeBlades(cs, computeBlades, associatedLsServers);
        reconcileVhbas(cs, associatedLsServers, new VhbaHelper(vsanFabricList));
        reconcileServiceProfileTemplatesHBAs(cs, serviceProfileTemplates, new VhbaHelper(vsanFabricList));
        reconcileServiceProfileTemplatesVnics(cs, serviceProfileTemplates);
        reconcileServiceProfileTemplatesBootDefinitions(cs, serviceProfileTemplates);
        reconcileBootPolicies(cs, bootPolicies);
        reconcileVnicTemplates(cs, vnicTemplates);
        reconcileVhbaTemplates(cs, vhbaTemplates);
        Map<String, Set<String>> unpinnedVsans = getUnpinnedVSans(vsanList, fcInterfaceMap);
        reconcileUplinkPorts(cs, uplinkMap, fcInterfaceMap, unpinnedVsans);
        reconcileUplinkPortChannels(cs, portChannelMap, unpinnedVsans);
        reconcileVlans(cs, vlanList);
        associateComputeImageServer(cs);
        matchComputeBladesToHosts(cs);
        cs.setLastDiscoveryRunTime(Calendar.getInstance().getTimeInMillis());
        cs.setSuccessDiscoveryTime(Calendar.getInstance().getTimeInMillis());
        cs.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.COMPLETE.name());
    } catch (ComputeSystemControllerException e) {
        cs.setLastDiscoveryStatusMessage(e.getMessage());
        throw ComputeSystemControllerException.exceptions.discoverFailed(cs.getId().toString(), e);
    } finally {
        _dbClient.persistObject(cs);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) StringSet(com.emc.storageos.db.client.model.StringSet) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException) ComputeBlade(com.emc.cloud.platform.ucs.out.model.ComputeBlade) FabricVsan(com.emc.cloud.platform.ucs.out.model.FabricVsan) FabricVlan(com.emc.cloud.platform.ucs.out.model.FabricVlan) URL(java.net.URL) FcPIo(com.emc.cloud.platform.ucs.out.model.FcPIo) VnicLanConnTempl(com.emc.cloud.platform.ucs.out.model.VnicLanConnTempl) SwVsan(com.emc.cloud.platform.ucs.out.model.SwVsan) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) LsbootPolicy(com.emc.cloud.platform.ucs.out.model.LsbootPolicy) LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) VnicSanConnTempl(com.emc.cloud.platform.ucs.out.model.VnicSanConnTempl) SwFcSanPc(com.emc.cloud.platform.ucs.out.model.SwFcSanPc) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) MalformedURLException(java.net.MalformedURLException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException) SwFcSanEp(com.emc.cloud.platform.ucs.out.model.SwFcSanEp)

Aggregations

ComputeBlade (com.emc.cloud.platform.ucs.out.model.ComputeBlade)7 LsServer (com.emc.cloud.platform.ucs.out.model.LsServer)3 Test (org.testng.annotations.Test)3 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)2 ClientGeneralException (com.emc.cloud.platform.clientlib.ClientGeneralException)1 ConfigResolveClass (com.emc.cloud.platform.ucs.in.model.ConfigResolveClass)1 ConfigSet (com.emc.cloud.platform.ucs.out.model.ConfigSet)1 FabricVlan (com.emc.cloud.platform.ucs.out.model.FabricVlan)1 FabricVsan (com.emc.cloud.platform.ucs.out.model.FabricVsan)1 FcPIo (com.emc.cloud.platform.ucs.out.model.FcPIo)1 LsbootPolicy (com.emc.cloud.platform.ucs.out.model.LsbootPolicy)1 SwFcSanEp (com.emc.cloud.platform.ucs.out.model.SwFcSanEp)1 SwFcSanPc (com.emc.cloud.platform.ucs.out.model.SwFcSanPc)1 SwVsan (com.emc.cloud.platform.ucs.out.model.SwVsan)1 VnicLanConnTempl (com.emc.cloud.platform.ucs.out.model.VnicLanConnTempl)1 VnicSanConnTempl (com.emc.cloud.platform.ucs.out.model.VnicSanConnTempl)1 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)1 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)1 ComputeSystem (com.emc.storageos.db.client.model.ComputeSystem)1 DataObject (com.emc.storageos.db.client.model.DataObject)1