use of com.emc.cloud.platform.ucs.out.model.LsServer in project coprhd-controller by CoprHD.
the class UcsDiscoveryWorker method reconcileServiceProfileTemplatesHBAs.
private void reconcileServiceProfileTemplatesHBAs(ComputeSystem cs, List<LsServer> lsServers, VhbaHelper vsanLookupMap) {
URIQueryResultList uris = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSystemServiceProfileTemplateConstraint(cs.getId()), uris);
Map<String, LsServer> lsServerMap = new HashMap<>();
for (LsServer lsServer : lsServers) {
lsServerMap.put(lsServer.getDn(), lsServer);
}
List<UCSServiceProfileTemplate> serviceTemplates = _dbClient.queryObject(UCSServiceProfileTemplate.class, uris, true);
for (UCSServiceProfileTemplate serviceProfileTemplate : serviceTemplates) {
LsServer lsServer = lsServerMap.get(serviceProfileTemplate.getDn());
if (lsServer == null) {
continue;
}
Map<String, Object> serviceProfileTemplateDetails = getServiceProfileTemplateDetails(lsServer);
Map<String, ComputeElementHBA> removeVhbas = new HashMap<>();
Map<String, ComputeElementHBA> addVhbas = new HashMap<>();
Map<String, ComputeElementHBA> updateVhbas = new HashMap<>();
URIQueryResultList uriVhbas = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getServiceProfileTemplateComputeElemetHBAsConstraint(serviceProfileTemplate.getId()), uriVhbas);
List<ComputeElementHBA> vbhas = _dbClient.queryObject(ComputeElementHBA.class, uriVhbas, true);
for (ComputeElementHBA hba : vbhas) {
removeVhbas.put(hba.getLabel(), hba);
}
for (VnicFc vnicFc : (List<VnicFc>) serviceProfileTemplateDetails.get("vhbas")) {
ComputeElementHBA hba = removeVhbas.get(vnicFc.getName());
if (hba != null) {
updateVhbas.put(vnicFc.getName(), hba);
removeVhbas.remove(hba.getLabel());
updateComputeElementHBA(hba, vsanLookupMap, vnicFc);
} else {
hba = new ComputeElementHBA();
addVhbas.put(vnicFc.getName(), hba);
createComputeElementHBA(cs, serviceProfileTemplate, hba, vsanLookupMap, vnicFc);
}
}
createDataObjects(new ArrayList<DataObject>(addVhbas.values()));
persistDataObjects(new ArrayList<DataObject>(updateVhbas.values()));
for (String name : removeVhbas.keySet()) {
_log.info("Marked for deletion ComputeElementHBA: " + name);
}
deleteDataObjects(new ArrayList<DataObject>(removeVhbas.values()));
}
}
use of com.emc.cloud.platform.ucs.out.model.LsServer 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.LsServer in project coprhd-controller by CoprHD.
the class UCSMServiceImpl method setLsServerPowerState.
/**
* @param ucsmURL
* @param username
* @param password
* @param lsServerDN
* - is the DN of the lsServer (unique for the UCSM that's
* represented by ucsmURL)
* @param powerState
* - is "up" or "down"
* @return
* @throws ClientGeneralException
*/
@Override
public LsServer setLsServerPowerState(String ucsmURL, String username, String password, String lsServerDN, String powerState, StringBuilder errorMessage) throws ClientGeneralException {
ComputeSession computeSession = sessionManager.getSession(ucsmURL, username, password);
ConfigConfMo configConfMo = new ConfigConfMo();
configConfMo.setInHierarchical("true");
com.emc.cloud.platform.ucs.in.model.LsServer lsServer = new com.emc.cloud.platform.ucs.in.model.LsServer();
lsServer.setDn(lsServerDN);
LsPower lsPower = new LsPower();
lsPower.setRn("power");
lsPower.setState(powerState);
lsServer.getContent().add(factory.createLsPower(lsPower));
ConfigConfig configConfig = new ConfigConfig();
configConfig.setManagedObject(factory.createLsServer(lsServer));
configConfMo.getContent().add(factory.createConfigConfMoInConfig(configConfig));
LsServer returnedLsServer = pushLsServer(computeSession, factory, configConfMo, errorMessage);
List<LsPower> lsPowers = getSubElements(returnedLsServer.getContent(), LsPower.class);
if ((lsPowers == null) || lsPowers.isEmpty() || (lsPowers.get(0) == null) || !lsPowers.get(0).getState().equals(powerState)) {
throw new ClientGeneralException(ClientMessageKeys.UNEXPECTED_FAILURE, new String[] { "Failed to set power state to '" + powerState + "' on LsServer : " + lsServerDN });
}
return returnedLsServer;
}
use of com.emc.cloud.platform.ucs.out.model.LsServer in project coprhd-controller by CoprHD.
the class UCSMServiceImpl method setLsBootDefOnLsServer.
private LsServer setLsBootDefOnLsServer(String ucsmURL, String username, String password, String spDn, BootType bootType, Map<String, Map<String, Integer>> hbaToStoragePortMap, StringBuilder errorMessage) throws ClientGeneralException {
ComputeSession computeSession = sessionManager.getSession(ucsmURL, username, password);
String version = getDeviceVersion(ucsmURL, username, password);
LsServer lsServerCurrent = getManagedObject(ucsmURL, username, password, spDn, true, LsServer.class);
if (lsServerCurrent == null) {
log.error("Unable to fetch LsServer for spDn {}", spDn);
String[] s = { "Unable to fetch LsServer for spDn " + spDn };
throw new ClientGeneralException(ClientMessageKeys.UNEXPECTED_FAILURE, s);
}
ConfigConfMo lsbootDefConfigMo = new ConfigConfMo();
lsbootDefConfigMo.setInHierarchical(Boolean.toString(true));
com.emc.cloud.platform.ucs.in.model.LsServer lsServer = new com.emc.cloud.platform.ucs.in.model.LsServer();
lsServer.setDn(spDn);
lsServer.getContent().add(factory.createLsbootDef(createLsBootDef(bootType, spDn, version, lsServerCurrent, hbaToStoragePortMap)));
ConfigConfig configConfig = new ConfigConfig();
configConfig.setManagedObject(factory.createLsServer(lsServer));
lsbootDefConfigMo.getContent().add(factory.createConfigConfMoInConfig(configConfig));
LsServer returnedLsServer = pushLsServer(computeSession, factory, lsbootDefConfigMo, errorMessage);
List<com.emc.cloud.platform.ucs.out.model.LsbootDef> lsBootDefs = getSubElements(returnedLsServer.getContent(), com.emc.cloud.platform.ucs.out.model.LsbootDef.class);
boolean operationVerified = false;
switch(bootType) {
case LAN:
List<com.emc.cloud.platform.ucs.out.model.LsbootLan> lsBootLans = getSubElements(lsBootDefs.get(0).getContent(), com.emc.cloud.platform.ucs.out.model.LsbootLan.class);
if (lsBootLans != null) {
for (com.emc.cloud.platform.ucs.out.model.LsbootLan lsBootLan : lsBootLans) {
if (lsBootLan.getOrder().equals("1")) {
operationVerified = true;
break;
}
}
}
break;
case SAN:
if (UcsmVersionChecker.verifyVersionDetails("2.2", version) < 0) {
// UCS Model change as of 2.2
List<com.emc.cloud.platform.ucs.out.model.LsbootStorage> lsBootStorages = getSubElements(lsBootDefs.get(0).getContent(), com.emc.cloud.platform.ucs.out.model.LsbootStorage.class);
if (lsBootStorages != null) {
for (com.emc.cloud.platform.ucs.out.model.LsbootStorage lsBootStorage : lsBootStorages) {
if (lsBootStorage.getOrder().equals("1")) {
operationVerified = true;
break;
}
}
}
} else {
List<com.emc.cloud.platform.ucs.out.model.LsbootSan> lsBootSans = getSubElements(lsBootDefs.get(0).getContent(), com.emc.cloud.platform.ucs.out.model.LsbootSan.class);
if (lsBootSans != null) {
for (com.emc.cloud.platform.ucs.out.model.LsbootSan lsBootSan : lsBootSans) {
if (lsBootSan.getOrder().equals("1")) {
operationVerified = true;
break;
}
}
}
}
break;
case NONE:
if ((lsBootDefs != null) && (lsBootDefs.isEmpty())) {
operationVerified = true;
}
break;
case EMPTY:
if ((lsBootDefs != null) && (lsBootDefs.size() == 1) && ((lsBootDefs.get(0).getContent() == null) || (lsBootDefs.get(0).getContent().size() == 0))) {
operationVerified = true;
}
}
if (!operationVerified) {
throw new ClientGeneralException(ClientMessageKeys.UNEXPECTED_FAILURE, new String[] { "Failed to set boot definition '" + bootType.name() + "' on LsServer : " + spDn });
}
return returnedLsServer;
}
use of com.emc.cloud.platform.ucs.out.model.LsServer in project coprhd-controller by CoprHD.
the class UCSMServiceImpl method getAllLsServers.
private List<LsServer> getAllLsServers(String ucsmURL, String username, String password, boolean serviceProfilesOnly) throws ClientGeneralException {
List<LsServer> lsServers = Collections.synchronizedList(new ArrayList<LsServer>());
try {
ComputeSession computeSession = sessionManager.getSession(ucsmURL, username, password);
ConfigResolveClass configResolveClass = new ConfigResolveClass();
configResolveClass.setClassId(NamingClassId.LS_SERVER);
configResolveClass.setInHierarchical("true");
// configResolveClass.getContent();
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 LsServer) {
LsServer lsServer = (LsServer) managedObject.getValue();
if (serviceProfilesOnly && !(lsServer.getType().equals("instance"))) {
continue;
}
lsServers.add(lsServer);
}
}
}
}
}
}
} catch (ClientGeneralException e) {
log.error("Unable to get all lsServers", e);
throw e;
}
return lsServers;
}
Aggregations