use of com.emc.storageos.db.client.model.ComputeSystem in project coprhd-controller by CoprHD.
the class UcsComputeDevice method changePowerState.
private void changePowerState(URI csId, URI ceId, String state) throws DeviceControllerException {
LOGGER.info("changePowerState");
ComputeElement ce = _dbClient.queryObject(ComputeElement.class, ceId);
ComputeSystem cs = _dbClient.queryObject(ComputeSystem.class, csId);
OperationTypeEnum typeEnum = POWER_DOWN.equals(state) ? OperationTypeEnum.POWERDOWN_COMPUTE_ELEMENT : OperationTypeEnum.POWERUP_COMPUTE_ELEMENT;
try {
URL ucsmURL = getUcsmURL(cs);
StringBuilder errorMessage = new StringBuilder();
ucsmService.setLsServerPowerState(ucsmURL.toString(), cs.getUsername(), cs.getPassword(), ce.getDn(), state, errorMessage);
pullAndPollManagedObject(ucsmURL.toString(), cs.getUsername(), cs.getPassword(), ce.getLabel(), ComputeBlade.class);
} catch (ComputeSystemControllerTimeoutException cstoe) {
LOGGER.error("Unable to change power state of compute element due to a device TimeOut", cstoe);
throw cstoe;
} catch (Exception e) {
LOGGER.error("Unable to change power state of compute element due to a exception", e);
throw ComputeSystemControllerException.exceptions.powerStateChangeFailed(state, ce != null ? ce.getId().toString() : null, e);
}
_auditMgr.recordAuditLog(null, null, EVENT_SERVICE_TYPE_CE, typeEnum, System.currentTimeMillis(), AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_END, ce.getId().toString(), ce.getLabel(), ce.getNativeGuid(), ce.getUuid(), ce.getOriginalUuid());
}
use of com.emc.storageos.db.client.model.ComputeSystem in project coprhd-controller by CoprHD.
the class UcsComputeDevice method rebindHostToTemplate.
@Override
public void rebindHostToTemplate(URI computeSystemId, URI hostId) throws InternalException {
LOGGER.info("rebindHostToTemplate");
// re-bind host to SPT
Host host = _dbClient.queryObject(Host.class, hostId);
ComputeSystem cs = _dbClient.queryObject(ComputeSystem.class, computeSystemId);
try {
if (host != null && !NullColumnValueGetter.isNullURI(host.getComputeElement()) && host.getUuid() != null) {
ComputeElement ce = _dbClient.queryObject(ComputeElement.class, host.getComputeElement());
URI sptId = URI.create(ce.getSptId());
UCSServiceProfileTemplate template = _dbClient.queryObject(UCSServiceProfileTemplate.class, sptId);
LsServer sp = ucsmService.getLsServer(getUcsmURL(cs).toString(), cs.getUsername(), cs.getPassword(), host.getUuid());
if (sp != null && template.getLabel() != null) {
if (!sp.getSrcTemplName().equalsIgnoreCase(template.getLabel())) {
StringBuilder errorMessage = new StringBuilder();
URL ucsmURL = getUcsmURL(cs);
if (null == ucsmService.bindSPToTemplate(ucsmURL.toString(), cs.getUsername(), cs.getPassword(), sp.getDn(), template.getLabel(), errorMessage)) {
throw new RuntimeException("Failed to rebind service profile to template. \n " + errorMessage.toString());
}
LOGGER.info("Successfully rebound host {} to template {}", host.getLabel(), template.getLabel());
} else {
LOGGER.info("Host is already bound to template, nothing to do. No OP.");
}
} else {
LOGGER.error("Unable to bind service profile to template. LsServer or UCSServiceProfileTemplate is null");
throw new RuntimeException("Unable to bind service profile to template. LsServer or UCSServiceProfileTemplate is null");
}
} else {
LOGGER.error("Unable to bind service profile to template, due to insufficient host data. Host or ComputeElement or host UUID is null");
throw new RuntimeException("Unable to bind service profile to template, due to insufficient host data. Host or host's computeElement or host UUID is null");
}
} catch (Exception e) {
LOGGER.error("Unable to bind service profile to template due to a exception", e);
throw ComputeSystemControllerException.exceptions.bindHostToTemplateFailed(host != null ? host.getId().toString() : null, e);
}
}
use of com.emc.storageos.db.client.model.ComputeSystem in project coprhd-controller by CoprHD.
the class UcsComputeDevice method removeOsInstallNetwork.
@Override
public void removeOsInstallNetwork(URI computeSystemId, URI computeElementId, Map<String, Boolean> vlanMap) throws InternalException {
LOGGER.info("removeOsInstallNetwork");
ComputeSystem cs = _dbClient.queryObject(ComputeSystem.class, computeSystemId);
ComputeElement ce = _dbClient.queryObject(ComputeElement.class, computeElementId);
String osInstallVlan = cs.getOsInstallNetwork();
try {
ucsmService.removeOsInstallVlan(getUcsmURL(cs).toString(), cs.getUsername(), cs.getPassword(), ce.getDn(), osInstallVlan, vlanMap);
} catch (ClientGeneralException e) {
LOGGER.error("Unable to set os install vlan: " + cs.getOsInstallNetwork() + " On computeElement : " + ce.getId(), e);
throw ComputeSystemControllerException.exceptions.unableToRemoveOsInstallNetwork(osInstallVlan, ce.getId().toString(), e);
}
}
use of com.emc.storageos.db.client.model.ComputeSystem in project coprhd-controller by CoprHD.
the class UcsDiscoveryWorker method discoverComputeSystem.
public void discoverComputeSystem(URI computeSystemURI) {
String ucsmVersion;
ComputeSystem cs = _dbClient.queryObject(ComputeSystem.class, computeSystemURI);
_log.info("Inside discoverComputeSystems of class : " + getClass().toString());
URL ucsmURL = getUcsmURL(cs);
List<ComputeBlade> computeBlades;
List<LsServer> allServiceProfiles;
Map<String, LsServer> associatedLsServers;
List<LsServer> serviceProfileTemplates;
List<VnicLanConnTempl> vnicTemplates;
List<VnicSanConnTempl> vhbaTemplates;
Map<String, FcPIo> uplinkMap;
Map<String, SwFcSanEp> fcInterfaceMap;
List<SwVsan> vsanList;
Map<String, SwFcSanPc> portChannelMap;
List<FabricVlan> vlanList;
List<FabricVsan> vsanFabricList;
List<com.emc.cloud.platform.ucs.out.model.LsbootPolicy> bootPolicies;
try {
ucsmVersion = ucsmService.getDeviceVersion(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
verifyVersion(cs, ucsmVersion);
computeBlades = ucsmService.getComputeBlades(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
allServiceProfiles = ucsmService.getAllServiceProfiles(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
associatedLsServers = ucsmService.getAllAssociatedLsServers(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
serviceProfileTemplates = ucsmService.getServiceProfileTemplates(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
bootPolicies = ucsmService.getBootPolicies(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
vnicTemplates = ucsmService.getVnicTemplates(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
vhbaTemplates = ucsmService.getVhbaTemplates(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
uplinkMap = ucsmService.getFICUplinkPorts(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
fcInterfaceMap = ucsmService.getSwitchFCInterfaces(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
vsanList = ucsmService.getUcsSwitchVSans(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
portChannelMap = ucsmService.getUplinkPortChannels(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
vlanList = ucsmService.getUcsVlans(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
vsanFabricList = ucsmService.getUcsFabricVsans(ucsmURL.toString(), cs.getUsername(), cs.getPassword());
} catch (Exception e) {
_log.error("Failed to pull device data: " + cs.getId(), e);
if (e.getCause() != null && e.getCause().getMessage() != null) {
cs.setLastDiscoveryStatusMessage(e.getCause().getMessage());
} else {
cs.setLastDiscoveryStatusMessage(e.getMessage());
}
_dbClient.updateObject(cs);
throw ComputeSystemControllerException.exceptions.discoverFailed(computeSystemURI.toString(), e);
}
try {
reconcileServiceProfileTemplates(cs, serviceProfileTemplates);
reconcileServiceProfiles(cs, allServiceProfiles);
reconcileComputeBlades(cs, computeBlades, associatedLsServers);
reconcileVhbas(cs, associatedLsServers, new VhbaHelper(vsanFabricList));
reconcileServiceProfileTemplatesHBAs(cs, serviceProfileTemplates, new VhbaHelper(vsanFabricList));
reconcileServiceProfileTemplatesVnics(cs, serviceProfileTemplates);
reconcileServiceProfileTemplatesBootDefinitions(cs, serviceProfileTemplates);
reconcileBootPolicies(cs, bootPolicies);
reconcileVnicTemplates(cs, vnicTemplates);
reconcileVhbaTemplates(cs, vhbaTemplates);
Map<String, Set<String>> unpinnedVsans = getUnpinnedVSans(vsanList, fcInterfaceMap);
reconcileUplinkPorts(cs, uplinkMap, fcInterfaceMap, unpinnedVsans);
reconcileUplinkPortChannels(cs, portChannelMap, unpinnedVsans);
reconcileVlans(cs, vlanList);
associateComputeImageServer(cs);
matchComputeBladesToHosts(cs);
cs.setLastDiscoveryRunTime(Calendar.getInstance().getTimeInMillis());
cs.setSuccessDiscoveryTime(Calendar.getInstance().getTimeInMillis());
cs.setDiscoveryStatus(DiscoveredDataObject.DataCollectionJobStatus.COMPLETE.name());
} catch (ComputeSystemControllerException e) {
cs.setLastDiscoveryStatusMessage(e.getMessage());
throw ComputeSystemControllerException.exceptions.discoverFailed(cs.getId().toString(), e);
} finally {
_dbClient.persistObject(cs);
}
}
use of com.emc.storageos.db.client.model.ComputeSystem 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