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));
}
}
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));
}
}
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);
}
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());
}
}
}
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;
}
Aggregations