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()));
}
}
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");
}
}
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;
}
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());
}
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);
}
}
Aggregations