Search in sources :

Example 11 with UCSServiceProfile

use of com.emc.storageos.db.client.model.UCSServiceProfile in project coprhd-controller by CoprHD.

the class UcsComputeDevice method deleteLsServer.

public void deleteLsServer(ComputeSystem cs, URI hostURI, String createSpStepId, String stepId) throws ClientGeneralException {
    WorkflowStepCompleter.stepExecuting(stepId);
    String spDn = null;
    try {
        Host host = _dbClient.queryObject(Host.class, hostURI);
        UCSServiceProfile profile = null;
        if (host != null) {
            if (!NullColumnValueGetter.isNullURI(host.getServiceProfile())) {
                profile = _dbClient.queryObject(UCSServiceProfile.class, host.getServiceProfile());
                if (profile == null) {
                    throw ComputeSystemControllerException.exceptions.invalidServiceProfileReference(host.getServiceProfile().toString());
                } else {
                    spDn = profile.getDn();
                    if (spDn != null) {
                        LOGGER.info("Deleting Service Profile : " + spDn);
                        // Test mechanism to invoke a failure. No-op on production systems.
                        InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_066);
                        StringBuilder errorMessage = new StringBuilder();
                        ucsmService.deleteServiceProfile(getUcsmURL(cs).toString(), cs.getUsername(), cs.getPassword(), spDn, errorMessage);
                        LOGGER.info("Done Deleting Service Profile : " + spDn);
                        _dbClient.markForDeletion(profile);
                        host.setServiceProfile(NullColumnValueGetter.getNullURI());
                    } else {
                        throw ComputeSystemControllerException.exceptions.invalidServiceProfile(host.getServiceProfile().toString());
                    }
                }
            }
            if (!NullColumnValueGetter.isNullURI(host.getComputeElement())) {
                ComputeElement computeElement = _dbClient.queryObject(ComputeElement.class, host.getComputeElement());
                if (computeElement != null) {
                    computeElement.setAvailable(true);
                    computeElement.setUuid(computeElement.getOriginalUuid());
                    _dbClient.updateObject(computeElement);
                }
                host.setComputeElement(NullColumnValueGetter.getNullURI());
            }
            _dbClient.updateObject(host);
        }
        WorkflowStepCompleter.stepSucceded(stepId);
    } catch (Exception e) {
        LOGGER.error("Unable to deleteLsServer...", e);
        WorkflowStepCompleter.stepFailed(stepId, ComputeSystemControllerException.exceptions.unableToProvisionHost(spDn, cs.getNativeGuid(), e));
    }
}
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) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ComputeSystemControllerTimeoutException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerTimeoutException) MalformedURLException(java.net.MalformedURLException) ClientGeneralException(com.emc.cloud.platform.clientlib.ClientGeneralException) ComputeSystemControllerException(com.emc.storageos.computesystemcontroller.exceptions.ComputeSystemControllerException)

Example 12 with UCSServiceProfile

use of com.emc.storageos.db.client.model.UCSServiceProfile in project coprhd-controller by CoprHD.

the class UcsDiscoveryWorker method removeServiceProfilesFromHosts.

private void removeServiceProfilesFromHosts(Collection<UCSServiceProfile> serviceProfiles) {
    List<UCSServiceProfile> serviceProfilesToUpdate = new ArrayList<UCSServiceProfile>();
    for (UCSServiceProfile serviceProfile : serviceProfiles) {
        if (!NullColumnValueGetter.isNullURI(serviceProfile.getHost())) {
            Host host = _dbClient.queryObject(Host.class, serviceProfile.getHost());
            if (host != null) {
                _log.info("Removing UCSServiceProfile {} association from Host {} ", serviceProfile.getDn(), host.getLabel());
                host.setServiceProfile(NullColumnValueGetter.getNullURI());
                _dbClient.persistObject(host);
            }
            _log.info("Removing Host association from service profile {}", serviceProfile.getDn());
            serviceProfile.setHost(NullColumnValueGetter.getNullURI());
            serviceProfilesToUpdate.add(serviceProfile);
        }
    }
    if (!serviceProfilesToUpdate.isEmpty()) {
        persistDataObjects(new ArrayList<DataObject>(serviceProfilesToUpdate));
    }
}
Also used : UCSServiceProfile(com.emc.storageos.db.client.model.UCSServiceProfile) DataObject(com.emc.storageos.db.client.model.DataObject) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) ArrayList(java.util.ArrayList) Host(com.emc.storageos.db.client.model.Host)

Example 13 with UCSServiceProfile

use of com.emc.storageos.db.client.model.UCSServiceProfile in project coprhd-controller by CoprHD.

the class UcsDiscoveryWorker method reconcileServiceProfiles.

private void reconcileServiceProfiles(ComputeSystem cs, List<LsServer> allLsServers) {
    _log.info("Reconciling UCS Service Profiles");
    URIQueryResultList uris = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSystemServiceProfilesConstraint(cs.getId()), uris);
    Map<String, UCSServiceProfile> removeServiceProfiles = new HashMap<>();
    Map<String, UCSServiceProfile> updateServiceProfiles = new HashMap<>();
    Map<String, UCSServiceProfile> addServiceProfiles = new HashMap<>();
    List<UCSServiceProfile> serviceProfiles = _dbClient.queryObject(UCSServiceProfile.class, uris, true);
    for (UCSServiceProfile serviceProfile : serviceProfiles) {
        removeServiceProfiles.put(serviceProfile.getDn(), serviceProfile);
    }
    // discovered data
    for (LsServer lsServer : filterLsServers(allLsServers)) {
        UCSServiceProfile serviceProfile = removeServiceProfiles.get(lsServer.getDn());
        if (serviceProfile != null) {
            removeServiceProfiles.remove(lsServer.getDn());
            updateUCSServiceProfile(serviceProfile, lsServer);
            updateServiceProfiles.put(lsServer.getDn(), serviceProfile);
        } else {
            serviceProfile = new UCSServiceProfile();
            createUCSServiceProfile(cs, serviceProfile, lsServer);
            addServiceProfiles.put(lsServer.getDn(), serviceProfile);
        }
    }
    createDataObjects(new ArrayList<DataObject>(addServiceProfiles.values()));
    persistDataObjects(new ArrayList<DataObject>(updateServiceProfiles.values()));
    if (!removeServiceProfiles.isEmpty()) {
        for (String key : removeServiceProfiles.keySet()) {
            _log.info("Marked for deletion UCSServiceProfile: " + key);
        }
        removeServiceProfilesFromHosts(removeServiceProfiles.values());
        deleteDataObjects(new ArrayList<DataObject>(removeServiceProfiles.values()));
    }
    validateServiceProfileUuids(cs);
}
Also used : UCSServiceProfile(com.emc.storageos.db.client.model.UCSServiceProfile) DataObject(com.emc.storageos.db.client.model.DataObject) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) HashMap(java.util.HashMap) LsServer(com.emc.cloud.platform.ucs.out.model.LsServer) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 14 with UCSServiceProfile

use of com.emc.storageos.db.client.model.UCSServiceProfile in project coprhd-controller by CoprHD.

the class UcsDiscoveryWorker method validateServiceProfileUuids.

private void validateServiceProfileUuids(ComputeSystem cs) {
    URIQueryResultList uris = new URIQueryResultList();
    _dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSystemServiceProfilesConstraint(cs.getId()), uris);
    List<UCSServiceProfile> serviceProfiles = _dbClient.queryObject(UCSServiceProfile.class, uris, true);
    Map<String, UCSServiceProfile> uuidMap = new HashMap<>();
    for (UCSServiceProfile serviceProfile : serviceProfiles) {
        UCSServiceProfile anotherProfile = uuidMap.get(serviceProfile.getUuid());
        if (anotherProfile == null) {
            uuidMap.put(serviceProfile.getUuid(), serviceProfile);
        } else {
            _log.info("Found two service profiles {} , {}  that have same uuid: {} ", serviceProfile.getDn(), anotherProfile.getDn(), serviceProfile.getUuid());
            throw ComputeSystemControllerException.exceptions.serviceProfileUuidDuplicate(serviceProfile.getDn(), anotherProfile.getDn(), serviceProfile.getUuid());
        }
    }
}
Also used : UCSServiceProfile(com.emc.storageos.db.client.model.UCSServiceProfile) HashMap(java.util.HashMap) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 15 with UCSServiceProfile

use of com.emc.storageos.db.client.model.UCSServiceProfile in project coprhd-controller by CoprHD.

the class HostToComputeElementMatcher method getMatchingServiceProfile.

private static UCSServiceProfile getMatchingServiceProfile(Host host, Map<String, UCSServiceProfile> spMap) {
    if (!isValidUuid(host.getUuid())) {
        return null;
    }
    // check for matching UUID
    String uuid = host.getUuid();
    UCSServiceProfile spWithSameUuid = null;
    if (spMap.containsKey(uuid) && hostNameMatches(spMap.get(uuid).getDn(), host) && !isUnregistered(spMap.get(uuid))) {
        spWithSameUuid = spMap.get(uuid);
    }
    // check for matching UUID in mixed-endian format
    String uuidReversed = reverseUuidBytes(host.getUuid());
    UCSServiceProfile spWithReversedUuid = null;
    if (spMap.containsKey(uuidReversed) && hostNameMatches(spMap.get(uuidReversed).getDn(), host) && !isUnregistered(spMap.get(uuidReversed))) {
        spWithReversedUuid = spMap.get(uuidReversed);
    }
    if ((// found SP with UUID
    (spWithSameUuid != null) && // found SP with reversed UUID
    (spWithReversedUuid != null)) && !uuid.equalsIgnoreCase(uuidReversed)) {
        // UUID is not same when reversed
        String errMsg = "Host match failed for UCS Service Profile because host " + info(host) + " matches multiple Service Profiles " + info(spWithSameUuid) + " and " + info(spWithReversedUuid);
        _log.error(errMsg);
        failureMessages.append(errMsg);
        return null;
    }
    return spWithSameUuid != null ? spWithSameUuid : spWithReversedUuid;
}
Also used : UCSServiceProfile(com.emc.storageos.db.client.model.UCSServiceProfile)

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