use of com.emc.storageos.db.client.model.UCSServiceProfile 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);
}
use of com.emc.storageos.db.client.model.UCSServiceProfile in project coprhd-controller by CoprHD.
the class HostToComputeElementMatcher method matchHostsToBladesAndSPs.
private static void matchHostsToBladesAndSPs() {
// lookup map (to find CEs by their UUID)
Map<String, ComputeElement> ceMap = new HashMap<>();
for (ComputeElement ce : computeElementMap.values()) {
if (isValidUuid(ce.getUuid())) {
ceMap.put(ce.getUuid(), ce);
}
}
// lookup map (to find SPs by their UUID)
Map<String, UCSServiceProfile> spMap = new HashMap<>();
for (UCSServiceProfile sp : serviceProfileMap.values()) {
if (isValidUuid(sp.getUuid())) {
spMap.put(sp.getUuid(), sp);
}
}
for (Host host : hostMap.values()) {
_log.info("matching host " + info(host));
// clear blade & SP associations for hosts that are unregistered or have bad UUIDs
if (isUnregistered(host) || !hasValidUuid(host)) {
_log.info("skipping host (unregistered or bad UUID); " + info(host));
clearHostAssociations(host);
// next host
continue;
}
// find matching blade & SP
ComputeElement ce = getMatchingComputeElement(host, ceMap);
UCSServiceProfile sp = getMatchingServiceProfile(host, spMap);
// update Host & ServiceProfile
if (sp == null) {
_log.info("no SP match for host " + info(host));
// clear associations if no SP match
clearHostAssociations(host);
} else {
_log.info("matched host to SP & CE " + info(host) + ", " + info(sp) + ", " + info(ce));
setHostAssociations(host, ce, sp);
}
}
}
use of com.emc.storageos.db.client.model.UCSServiceProfile in project coprhd-controller by CoprHD.
the class HostToComputeElementMatcher method updateDb.
private static void updateDb() {
List<Host> hostsToUpdate = new ArrayList<>();
for (Host host : hostMap.values()) {
if (host.isChanged("computeElement") || host.isChanged("serviceProfile")) {
hostsToUpdate.add(host);
}
}
dbClient.updateObject(hostsToUpdate);
List<UCSServiceProfile> spsToUpdate = new ArrayList<>();
for (UCSServiceProfile sp : serviceProfileMap.values()) {
if (sp.isChanged("host")) {
spsToUpdate.add(sp);
}
}
dbClient.updateObject(spsToUpdate);
}
use of com.emc.storageos.db.client.model.UCSServiceProfile in project coprhd-controller by CoprHD.
the class HostToComputeElementMatcher method setHostAssociations.
private static void setHostAssociations(Host hostIn, ComputeElement ceIn, UCSServiceProfile spIn) {
Host host = hostMap.get(hostIn.getId());
if (NullColumnValueGetter.isNullURI(host.getServiceProfile())) {
// set new SP for host
host.setServiceProfile(spIn.getId());
} else if (!host.getServiceProfile().equals(spIn.getId())) {
// Unexpected SP association changes should result in discovery failure
failureMessages.append("Host's UCS Service Profile unexpectedly tried to change from " + host.getServiceProfile() + " to " + spIn.getId() + " for host " + info(host));
clearHostAssociations(host);
return;
}
if (ceIn == null) {
// happens when blade is not associated
if (!NullColumnValueGetter.isNullURI(host.getComputeElement())) {
host.setComputeElement(NullColumnValueGetter.getNullURI());
}
} else if ((host.getComputeElement() == null) || (!host.getComputeElement().equals(ceIn.getId()))) {
// set new CE for host
host.setComputeElement(ceIn.getId());
}
if (host.isChanged("computeElement") || host.isChanged("serviceProfile")) {
hostMap.put(host.getId(), host);
}
UCSServiceProfile sp = serviceProfileMap.get(spIn.getId());
if ((sp.getHost() == null) || (!sp.getHost().equals(host.getId()))) {
// set new host in SP
sp.setHost(host.getId());
serviceProfileMap.put(sp.getId(), sp);
}
}
use of com.emc.storageos.db.client.model.UCSServiceProfile in project coprhd-controller by CoprHD.
the class HostToComputeElementMatcher method clearHostAssociations.
private static void clearHostAssociations(Host host) {
Host h = hostMap.get(host.getId());
if (!NullColumnValueGetter.isNullURI(h.getComputeElement())) {
h.setComputeElement(NullColumnValueGetter.getNullURI());
}
if (!NullColumnValueGetter.isNullURI(h.getServiceProfile())) {
h.setServiceProfile(NullColumnValueGetter.getNullURI());
}
if (host.isChanged("computeElement") || host.isChanged("serviceProfile")) {
hostMap.put(host.getId(), host);
}
// clear reference from SPs back to this Host
for (UCSServiceProfile sp : serviceProfileMap.values()) {
if ((sp.getHost() != null) && sp.getHost().equals(host.getId())) {
sp.setHost(NullColumnValueGetter.getNullURI());
serviceProfileMap.put(sp.getId(), sp);
}
}
}
Aggregations