Search in sources :

Example 1 with UCSServiceProfile

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);
}
Also used : UCSServiceProfile(com.emc.storageos.db.client.model.UCSServiceProfile) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) Host(com.emc.storageos.db.client.model.Host) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 2 with UCSServiceProfile

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);
        }
    }
}
Also used : UCSServiceProfile(com.emc.storageos.db.client.model.UCSServiceProfile) HashMap(java.util.HashMap) ComputeElement(com.emc.storageos.db.client.model.ComputeElement) Host(com.emc.storageos.db.client.model.Host)

Example 3 with UCSServiceProfile

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);
}
Also used : UCSServiceProfile(com.emc.storageos.db.client.model.UCSServiceProfile) ArrayList(java.util.ArrayList) Host(com.emc.storageos.db.client.model.Host)

Example 4 with UCSServiceProfile

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);
    }
}
Also used : UCSServiceProfile(com.emc.storageos.db.client.model.UCSServiceProfile) Host(com.emc.storageos.db.client.model.Host)

Example 5 with UCSServiceProfile

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);
        }
    }
}
Also used : UCSServiceProfile(com.emc.storageos.db.client.model.UCSServiceProfile) Host(com.emc.storageos.db.client.model.Host)

Aggregations

UCSServiceProfile (com.emc.storageos.db.client.model.UCSServiceProfile)17 Host (com.emc.storageos.db.client.model.Host)10 ComputeElement (com.emc.storageos.db.client.model.ComputeElement)6 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 LsServer (com.emc.cloud.platform.ucs.out.model.LsServer)3 ComputeSystem (com.emc.storageos.db.client.model.ComputeSystem)3 URI (java.net.URI)3 ClientGeneralException (com.emc.cloud.platform.clientlib.ClientGeneralException)2 ComputeSystemControllerException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)2 ComputeSystemControllerTimeoutException (com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerTimeoutException)2 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)2 DataObject (com.emc.storageos.db.client.model.DataObject)2 DiscoveredDataObject (com.emc.storageos.db.client.model.DiscoveredDataObject)2 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)2 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)2 MalformedURLException (java.net.MalformedURLException)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 ComputeBlade (com.emc.cloud.platform.ucs.out.model.ComputeBlade)1