use of com.emc.storageos.db.client.model.ComputeElementHBA 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.storageos.db.client.model.ComputeElementHBA in project coprhd-controller by CoprHD.
the class UcsComputeDevice method setComputeElementAttrFromBoundLsServer.
private void setComputeElementAttrFromBoundLsServer(DbClient dbClient, ComputeElement computeElement, LsServer lsServer, Host host, String systemType, boolean markUnregistered) {
List<ComputeElementHBA> computeElementHBAs = new ArrayList<ComputeElementHBA>();
computeElement.setUuid(lsServer.getUuid());
computeElement.setDn(lsServer.getDn());
String sptName = lsServer.getSrcTemplName();
URIQueryResultList uris = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSystemServiceProfileTemplateConstraint(computeElement.getComputeSystem()), uris);
List<UCSServiceProfileTemplate> serviceTemplates = _dbClient.queryObject(UCSServiceProfileTemplate.class, uris, true);
for (UCSServiceProfileTemplate serviceTemplate : serviceTemplates) {
if (serviceTemplate.getLabel().equals(sptName)) {
computeElement.setSptId(serviceTemplate.getId().toString());
}
}
if (markUnregistered) {
computeElement.setRegistrationStatus(DiscoveredDataObject.RegistrationStatus.UNREGISTERED.name());
}
computeElement.setAvailable(false);
if (lsServer.getContent() != null && !lsServer.getContent().isEmpty()) {
for (Serializable contentElement : lsServer.getContent()) {
if (contentElement instanceof JAXBElement<?>) {
if (((JAXBElement) contentElement).getValue() instanceof VnicFc) {
VnicFc vnicFc = (VnicFc) ((JAXBElement) contentElement).getValue();
ComputeElementHBA computeElementHBA = new ComputeElementHBA();
computeElementHBA.setComputeElement(computeElement.getId());
computeElementHBA.setHost(host.getId());
computeElementHBA.setCreationTime(Calendar.getInstance());
computeElementHBA.setDn(vnicFc.getDn());
computeElementHBA.setId(URIUtil.createId(ComputeElementHBA.class));
computeElementHBA.setInactive(false);
computeElementHBA.setLabel(vnicFc.getName());
computeElementHBA.setProtocol(vnicFc.getType());
computeElementHBA.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(computeElementHBA, systemType));
computeElementHBA.setNode(vnicFc.getNodeAddr());
computeElementHBA.setPort(vnicFc.getAddr());
computeElementHBA.setVsanId(getVsanIdFromvnicFC(vnicFc));
computeElementHBAs.add(computeElementHBA);
}
}
}
}
if (!computeElementHBAs.isEmpty()) {
dbClient.createObject(computeElementHBAs);
}
/**
* For the case where the compute element exists, but we are updating
* it:
*/
if (dbClient.queryObject(ComputeElement.class, computeElement.getId()) != null) {
dbClient.updateObject(computeElement);
}
}
use of com.emc.storageos.db.client.model.ComputeElementHBA in project coprhd-controller by CoprHD.
the class UcsComputeDevice method addHostPortsToVArrayNetworks.
public void addHostPortsToVArrayNetworks(VirtualArray varray, Host host, String stepId) {
LOGGER.info("Adding host ports to networks in Varray : " + varray.getLabel() + "for Host: " + host.getHostName());
WorkflowStepCompleter.stepExecuting(stepId);
try {
if (!NullColumnValueGetter.isNullURI(host.getComputeElement())) {
Map<Network, List<String>> networkToInitiatorMap = Collections.synchronizedMap(new HashMap<Network, List<String>>());
Map<String, Network> networkIdNetworkMapInVarray = getVarrayNetworkMap(_dbClient, varray.getId());
URIQueryResultList ceHBAUriList = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getHostComputeElemetHBAsConstraint(host.getId()), ceHBAUriList);
Iterator<URI> ceHBAUriListIterator = ceHBAUriList.iterator();
Cluster cluster = null;
if (host.getCluster() != null) {
cluster = _dbClient.queryObject(Cluster.class, host.getCluster());
}
while (ceHBAUriListIterator.hasNext()) {
URI ceHBAUri = ceHBAUriListIterator.next();
ComputeElementHBA computeElementHBA = _dbClient.queryObject(ComputeElementHBA.class, ceHBAUri);
Initiator initiator = new Initiator();
initiator.setHost(host.getId());
initiator.setHostName(host.getHostName());
initiator.setId(URIUtil.createId(Initiator.class));
if (cluster != null) {
initiator.setClusterName(cluster.getLabel());
}
initiator.setInitiatorNode(computeElementHBA.getNode());
initiator.setInitiatorPort(computeElementHBA.getPort());
initiator.setProtocol(computeElementHBA.getProtocol() != null ? computeElementHBA.getProtocol().toUpperCase() : null);
// Search against the database, fail if you see the wwn in the database already.
Initiator dbInitiator = ExportUtils.getInitiator(initiator.getInitiatorPort(), _dbClient);
if (dbInitiator != null) {
throw ComputeSystemControllerException.exceptions.illegalInitiator(host.getHostName(), dbInitiator.getInitiatorPort(), dbInitiator.getHostName());
}
Network network = networkIdNetworkMapInVarray.get(computeElementHBA.getVsanId());
// Test mechanism to invoke a failure. No-op on production systems.
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_065);
if (network == null) {
LOGGER.error("No corresponding Network for HBA {} in vArray {}. Network null from DB.", computeElementHBA.getPort(), varray.getId());
throw new RuntimeException(ComputeSystemControllerException.exceptions.noCorrespondingNetworkForHBAInVarray(computeElementHBA.getPort(), varray.getLabel(), null));
} else {
if (networkToInitiatorMap.get(network) == null) {
networkToInitiatorMap.put(network, new ArrayList<String>());
}
networkToInitiatorMap.get(network).add(computeElementHBA.getPort());
}
_dbClient.createObject(initiator);
}
/**
* Add all the newly added endpoints to their respective networks!
*/
for (Network network : networkToInitiatorMap.keySet()) {
network.addEndpoints(networkToInitiatorMap.get(network), false);
_dbClient.updateObject(network);
handleEndpointsAdded(network, networkToInitiatorMap.get(network), _dbClient, _coordinator);
}
}
WorkflowStepCompleter.stepSucceded(stepId);
LOGGER.info("Done adding host ports to networks in Varray : " + varray.getLabel() + "for Host: " + host.getHostName());
} catch (Exception ex) {
LOGGER.error("Exception while adding host ports to vArray networks. {}", ex);
WorkflowStepCompleter.stepFailed(stepId, ComputeSystemControllerException.exceptions.unableToAddHostPortsToVArrayNetworks(varray.getLabel().toString(), ex));
}
}
use of com.emc.storageos.db.client.model.ComputeElementHBA in project coprhd-controller by CoprHD.
the class ComputeSystemService method isServiceProfileTemplateValidForVarrays.
/*
* Check whether the SPT's vsans are in atleast one of the varrays' networks. If yes, valid.
*/
public boolean isServiceProfileTemplateValidForVarrays(StringSet varrayIds, URI sptId) {
boolean isValid = true;
UCSServiceProfileTemplate template = (UCSServiceProfileTemplate) _dbClient.queryObject(sptId);
Set<String> networkVsanIds = new HashSet<String>();
URIQueryResultList uriVhbas = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getServiceProfileTemplateComputeElemetHBAsConstraint(sptId), uriVhbas);
List<ComputeElementHBA> vhbas = _dbClient.queryObject(ComputeElementHBA.class, uriVhbas, true);
// Filter out SPTs without any vhbas
if ((vhbas == null) || vhbas.isEmpty()) {
isValid = false;
_log.info("ServiceProfileTemplate " + template.getLabel() + " does not have any vhbas and hence is not valid for use.");
return isValid;
}
for (String varrayId : varrayIds) {
// get varray networks
List<Network> networks = CustomQueryUtility.queryActiveResourcesByRelation(_dbClient, URI.create(varrayId), Network.class, "connectedVirtualArrays");
// collect network vsanIds
Set<String> varrayNetworkVsanIds = new HashSet<String>();
for (Network network : networks) {
if (StorageProtocol.Transport.FC.name().equalsIgnoreCase(network.getTransportType())) {
varrayNetworkVsanIds.add(network.getNativeId());
// _log.debug("varray vsan :"+ network.getNativeId());
}
}
if (networkVsanIds.isEmpty()) {
networkVsanIds.addAll(varrayNetworkVsanIds);
} else {
networkVsanIds.retainAll(varrayNetworkVsanIds);
}
for (ComputeElementHBA vhba : vhbas) {
String vsanId = vhba.getVsanId();
_log.debug("vhba vsan:" + vsanId);
if (!networkVsanIds.contains(vsanId)) {
isValid = false;
_log.error("SPT " + template.getLabel() + " has hba on vsan " + vsanId + " not included in varray " + varrayId);
return isValid;
}
}
}
if (template.getUpdating()) {
isValid = isUpdatingSPTValidForVarrays(varrayIds, template);
}
return isValid;
}
Aggregations