use of com.emc.storageos.db.client.model.UCSServiceProfile in project coprhd-controller by CoprHD.
the class HostToComputeElementMatcher method removeDuplicateUuids.
private static void removeDuplicateUuids(URI computeSystem) {
Map<String, URI> ceDuplicateMap = new HashMap<>();
List<URI> ceDuplicateIds = new ArrayList<>();
for (ComputeElement ce : computeElementMap.values()) {
if (NullColumnValueGetter.isNotNullValue(ce.getUuid()) && isValidUuid(ce.getUuid())) {
if (!ceDuplicateMap.containsKey(ce.getUuid())) {
ceDuplicateMap.put(ce.getUuid(), ce.getId());
} else {
ComputeElement duplicateCe = computeElementMap.get(ceDuplicateMap.get(ce.getUuid()));
String errMsg = "ComputeElements found having the same UUID " + info(ce) + " and " + info(duplicateCe);
if (NullColumnValueGetter.isNullURI(computeSystem) || ce.getComputeSystem().equals(computeSystem) || duplicateCe.getComputeSystem().equals(computeSystem)) {
// fail discovery if no UCS or for affected UCS only
failureMessages.append(errMsg);
} else {
// if neither in UCS, just log warning
_log.warn(errMsg);
}
ceDuplicateIds.add(ce.getId());
ceDuplicateIds.add(ceDuplicateMap.get(ce.getUuid()));
}
}
}
computeElementMap.keySet().removeAll(ceDuplicateIds);
Map<String, URI> spDuplicateMap = new HashMap<>();
List<URI> spDuplicateIds = new ArrayList<>();
for (UCSServiceProfile sp : serviceProfileMap.values()) {
if (NullColumnValueGetter.isNotNullValue(sp.getUuid()) && isValidUuid(sp.getUuid())) {
if (!spDuplicateMap.containsKey(sp.getUuid())) {
spDuplicateMap.put(sp.getUuid(), sp.getId());
} else {
UCSServiceProfile duplicateSp = serviceProfileMap.get(spDuplicateMap.get(sp.getUuid()));
String errMsg = "UCS Service Profiles found having the same UUID " + info(sp) + " and " + info(duplicateSp);
if (NullColumnValueGetter.isNullURI(computeSystem) || sp.getComputeSystem().equals(computeSystem) || duplicateSp.getComputeSystem().equals(computeSystem)) {
// fail discovery if no UCS or for affected UCS only
failureMessages.append(errMsg);
} else {
// if neither in UCS, just log warning
_log.warn(errMsg);
}
spDuplicateIds.add(sp.getId());
spDuplicateIds.add(spDuplicateMap.get(sp.getUuid()));
}
}
}
serviceProfileMap.keySet().removeAll(spDuplicateIds);
}
use of com.emc.storageos.db.client.model.UCSServiceProfile in project coprhd-controller by CoprHD.
the class HostService method deactivateHost.
/**
* Deactivates the host and all its interfaces.
*
* @param id
* the URN of a ViPR Host to be deactivated
* @param detachStorage
* if true, will first detach storage.
* @param detachStorageDeprecated
* Deprecated. Use detachStorage instead.
* @param deactivateBootVolume
* if true, and if the host was provisioned by ViPR the associated boot volume (if exists) will be
* deactivated
* @brief Deactivate host
* @return OK if deactivation completed successfully
* @throws DatabaseException
* when a DB error occurs
*/
@POST
@Path("/{id}/deactivate")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN })
public TaskResourceRep deactivateHost(@PathParam("id") URI id, @DefaultValue("false") @QueryParam("detach_storage") boolean detachStorage, @DefaultValue("false") @QueryParam("detach-storage") boolean detachStorageDeprecated, @DefaultValue("true") @QueryParam("deactivate_boot_volume") boolean deactivateBootVolume) throws DatabaseException {
Host host = queryHost(_dbClient, id);
ArgValidator.checkEntity(host, id, true);
boolean hasPendingTasks = hostHasPendingTasks(id);
if (hasPendingTasks) {
throw APIException.badRequests.resourceCannotBeDeleted("Host with another operation in progress");
}
boolean isHostInUse = ComputeSystemHelper.isHostInUse(_dbClient, host.getId());
if (isHostInUse && !(detachStorage || detachStorageDeprecated)) {
throw APIException.badRequests.resourceHasActiveReferences(Host.class.getSimpleName(), id);
}
UCSServiceProfile serviceProfile = null;
if (!NullColumnValueGetter.isNullURI(host.getServiceProfile())) {
serviceProfile = _dbClient.queryObject(UCSServiceProfile.class, host.getServiceProfile());
if (serviceProfile != null && !NullColumnValueGetter.isNullURI(serviceProfile.getComputeSystem())) {
ComputeSystem ucs = _dbClient.queryObject(ComputeSystem.class, serviceProfile.getComputeSystem());
if (ucs != null && ucs.getDiscoveryStatus().equals(DataCollectionJobStatus.ERROR.name())) {
throw APIException.badRequests.resourceCannotBeDeleted("Host has service profile on a Compute System that failed to discover; ");
}
}
}
Collection<URI> hostIds = _dbClient.queryByType(Host.class, true);
Collection<Host> hosts = _dbClient.queryObjectFields(Host.class, Arrays.asList("label", "uuid", "serviceProfile", "computeElement", "registrationStatus", "inactive"), ControllerUtils.getFullyImplementedCollection(hostIds));
for (Host tempHost : hosts) {
if (!tempHost.getId().equals(host.getId()) && !tempHost.getInactive()) {
if (tempHost.getUuid() != null && tempHost.getUuid().equals(host.getUuid())) {
throw APIException.badRequests.resourceCannotBeDeleted("Host " + host.getLabel() + " shares same uuid " + host.getUuid() + " with another active host " + tempHost.getLabel() + " with URI: " + tempHost.getId().toString() + " and ");
}
if (!NullColumnValueGetter.isNullURI(host.getComputeElement()) && host.getComputeElement() == tempHost.getComputeElement()) {
throw APIException.badRequests.resourceCannotBeDeleted("Host " + host.getLabel() + " shares same computeElement " + host.getComputeElement() + " with another active host " + tempHost.getLabel() + " with URI: " + tempHost.getId().toString() + " and ");
}
if (!NullColumnValueGetter.isNullURI(host.getServiceProfile()) && host.getServiceProfile() == tempHost.getServiceProfile()) {
throw APIException.badRequests.resourceCannotBeDeleted("Host " + host.getLabel() + " shares same serviceProfile " + host.getServiceProfile() + " with another active host " + tempHost.getLabel() + " with URI: " + tempHost.getId().toString() + " and ");
}
}
}
if (!NullColumnValueGetter.isNullURI(host.getComputeElement()) && NullColumnValueGetter.isNullURI(host.getServiceProfile())) {
throw APIException.badRequests.resourceCannotBeDeletedVblock(host.getLabel(), "Host " + host.getLabel() + " has a compute element, but no service profile." + " Please re-discover the Vblock Compute System and retry.");
}
// VBDU [DONE]: COP-28452, Running host deactivate even if initiators == null or list empty seems risky
// If initiators are empty, we will not perform any export updates
String taskId = UUID.randomUUID().toString();
Operation op = _dbClient.createTaskOpStatus(Host.class, host.getId(), taskId, ResourceOperationTypeEnum.DELETE_HOST);
ComputeSystemController controller = getController(ComputeSystemController.class, null);
List<VolumeDescriptor> bootVolDescriptors = new ArrayList<>();
if (deactivateBootVolume & !NullColumnValueGetter.isNullURI(host.getBootVolumeId())) {
Volume vol = _dbClient.queryObject(Volume.class, host.getBootVolumeId());
if (vol.isVPlexVolume(_dbClient)) {
bootVolDescriptors.addAll(vplexBlockServiceApiImpl.getDescriptorsForVolumesToBeDeleted(vol.getStorageController(), Arrays.asList(host.getBootVolumeId()), null));
} else {
if (vol.getPool() != null) {
StoragePool storagePool = _dbClient.queryObject(StoragePool.class, vol.getPool());
if (storagePool != null && storagePool.getStorageDevice() != null) {
bootVolDescriptors.add(new VolumeDescriptor(VolumeDescriptor.Type.BLOCK_DATA, storagePool.getStorageDevice(), host.getBootVolumeId(), null, null));
}
}
}
}
controller.detachHostStorage(host.getId(), true, deactivateBootVolume, bootVolDescriptors, taskId);
if (!NullColumnValueGetter.isNullURI(host.getComputeElement())) {
host.setProvisioningStatus(Host.ProvisioningJobStatus.IN_PROGRESS.toString());
}
_dbClient.persistObject(host);
auditOp(OperationTypeEnum.DELETE_HOST, true, op.getStatus(), host.auditParameters());
return toTask(host, taskId, op);
}
Aggregations