use of com.emc.storageos.db.client.model.ComputeElement in project coprhd-controller by CoprHD.
the class ComputeDeviceControllerImpl method createHost.
/**
* Create host using the specified params
*
* @param csId
* {@link URI} computesystem Id
* @param vcpoolId
* {@link URI} vcpoolId
* @param varray
* {@link URI} varray Id
* @param hostId
* {@link URI} host Id
* @param opId
* (@link String} operation Id
*/
@Override
public void createHost(URI csId, URI vcpoolId, URI varray, URI hostId, String opId) throws InternalException {
log.info("createHost");
Host host = _dbClient.queryObject(Host.class, hostId);
// TODO COP-28960 check for null -- host, ce, etc.
ComputeElement ce = _dbClient.queryObject(ComputeElement.class, host.getComputeElement());
ComputeVirtualPool vcp = _dbClient.queryObject(ComputeVirtualPool.class, vcpoolId);
VirtualArray vArray = _dbClient.queryObject(VirtualArray.class, varray);
ComputeSystem cs = _dbClient.queryObject(ComputeSystem.class, ce.getComputeSystem());
TaskCompleter tc = new ComputeHostCompleter(hostId, opId, OperationTypeEnum.CREATE_HOST, EVENT_SERVICE_TYPE);
getDevice(cs.getSystemType()).createHost(cs, host, vcp, vArray, tc);
}
use of com.emc.storageos.db.client.model.ComputeElement in project coprhd-controller by CoprHD.
the class ComputeHostCompleter method complete.
@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
Host host = dbClient.queryObject(Host.class, getId());
ComputeElement ce = null;
if (host != null) {
ce = dbClient.queryObject(ComputeElement.class, host.getComputeElement());
}
AuditLogManager auditMgr = AuditLogManagerFactory.getAuditLogManager();
switch(status) {
case ready:
if (host != null) {
if (ce != null) {
host.setUuid(ce.getUuid());
host.setBios(ce.getBios());
}
host.setProvisioningStatus(ProvisioningJobStatus.COMPLETE.toString());
dbClient.updateObject(host);
dbClient.ready(Host.class, getId(), getOpId());
if (ce != null) {
auditMgr.recordAuditLog(null, null, serviceType, opType, System.currentTimeMillis(), AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_END, host.getId().toString(), ce.getAvailable(), ce.getUuid(), ce.getDn());
} else {
auditMgr.recordAuditLog(null, null, serviceType, opType, System.currentTimeMillis(), AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_END, host.getId().toString());
}
}
break;
case error:
if (host != null) {
host.setProvisioningStatus(ProvisioningJobStatus.ERROR.toString());
dbClient.updateObject(host);
dbClient.error(Host.class, getId(), getOpId(), coded);
/**
* Looks like the provisioning of the Host was unsuccessful...
* Set the ComputeElement to available (assuming that the
* rollback method executed properly)
*/
if (ce != null) {
ce.setAvailable(true);
dbClient.updateObject(ce);
auditMgr.recordAuditLog(null, null, serviceType, opType, System.currentTimeMillis(), AuditLogManager.AUDITLOG_FAILURE, AuditLogManager.AUDITOP_END, host.getId().toString(), ce.getAvailable(), ce.getUuid(), ce.getDn());
} else {
auditMgr.recordAuditLog(null, null, serviceType, opType, System.currentTimeMillis(), AuditLogManager.AUDITLOG_FAILURE, AuditLogManager.AUDITOP_END, host.getId().toString());
}
}
break;
default:
throw new DeviceControllerException(new IllegalStateException("Terminal state processing called, when operation was in fact not in a terminal state!"));
}
}
use of com.emc.storageos.db.client.model.ComputeElement in project coprhd-controller by CoprHD.
the class UcsComputeDevice method setSanBootTarget.
@Override
public void setSanBootTarget(ComputeSystem cs, URI computeElementId, URI hostId, URI volumeId, boolean waitForServerRestart) throws InternalException {
ComputeElement computeElement = _dbClient.queryObject(ComputeElement.class, computeElementId);
Map<String, Map<String, Integer>> hbaToStoragePorts = getHBAToStoragePorts(volumeId, hostId);
// zoning map will be empty in older releases. Do we need to still continue this operation?
try {
if (null != computeElement) {
StringBuilder errorMessage = new StringBuilder();
LsServer lsServer = ucsmService.setServiceProfileToSanBoot(getUcsmURL(cs).toString(), cs.getUsername(), cs.getPassword(), computeElement.getDn(), hbaToStoragePorts, errorMessage);
if (lsServer != null) {
if (waitForServerRestart) {
pullAndPollManagedObject(getUcsmURL(cs).toString(), cs.getUsername(), cs.getPassword(), computeElement.getDn(), LsServer.class);
}
} else {
throw new RuntimeException("Failed to set SAN boot target due to error from UCSM Service \n " + errorMessage);
}
} else {
throw new RuntimeException("ComputeElement object is null for id " + computeElementId);
}
} catch (Exception e) {
throw ComputeSystemControllerException.exceptions.unableToSetSanBootTarget(computeElementId.toString(), e);
}
}
use of com.emc.storageos.db.client.model.ComputeElement in project coprhd-controller by CoprHD.
the class UcsComputeDevice method setComputeElementAttrFromBoundLsServer.
private void setComputeElementAttrFromBoundLsServer(DbClient dbClient, ComputeElement computeElement, LsServer lsServer, Host host, String systemType, boolean markUnregistered) {
List<ComputeElementHBA> computeElementHBAs = new ArrayList<ComputeElementHBA>();
computeElement.setUuid(lsServer.getUuid());
computeElement.setDn(lsServer.getDn());
String sptName = lsServer.getSrcTemplName();
URIQueryResultList uris = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSystemServiceProfileTemplateConstraint(computeElement.getComputeSystem()), uris);
List<UCSServiceProfileTemplate> serviceTemplates = _dbClient.queryObject(UCSServiceProfileTemplate.class, uris, true);
for (UCSServiceProfileTemplate serviceTemplate : serviceTemplates) {
if (serviceTemplate.getLabel().equals(sptName)) {
computeElement.setSptId(serviceTemplate.getId().toString());
}
}
if (markUnregistered) {
computeElement.setRegistrationStatus(DiscoveredDataObject.RegistrationStatus.UNREGISTERED.name());
}
computeElement.setAvailable(false);
if (lsServer.getContent() != null && !lsServer.getContent().isEmpty()) {
for (Serializable contentElement : lsServer.getContent()) {
if (contentElement instanceof JAXBElement<?>) {
if (((JAXBElement) contentElement).getValue() instanceof VnicFc) {
VnicFc vnicFc = (VnicFc) ((JAXBElement) contentElement).getValue();
ComputeElementHBA computeElementHBA = new ComputeElementHBA();
computeElementHBA.setComputeElement(computeElement.getId());
computeElementHBA.setHost(host.getId());
computeElementHBA.setCreationTime(Calendar.getInstance());
computeElementHBA.setDn(vnicFc.getDn());
computeElementHBA.setId(URIUtil.createId(ComputeElementHBA.class));
computeElementHBA.setInactive(false);
computeElementHBA.setLabel(vnicFc.getName());
computeElementHBA.setProtocol(vnicFc.getType());
computeElementHBA.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(computeElementHBA, systemType));
computeElementHBA.setNode(vnicFc.getNodeAddr());
computeElementHBA.setPort(vnicFc.getAddr());
computeElementHBA.setVsanId(getVsanIdFromvnicFC(vnicFc));
computeElementHBAs.add(computeElementHBA);
}
}
}
}
if (!computeElementHBAs.isEmpty()) {
dbClient.createObject(computeElementHBAs);
}
/**
* For the case where the compute element exists, but we are updating
* it:
*/
if (dbClient.queryObject(ComputeElement.class, computeElement.getId()) != null) {
dbClient.updateObject(computeElement);
}
}
use of com.emc.storageos.db.client.model.ComputeElement in project coprhd-controller by CoprHD.
the class UcsComputeDevice method unbindHostFromTemplate.
@Override
public String unbindHostFromTemplate(URI computeSystemId, URI hostId) throws InternalException {
LOGGER.info("unbindHostFromTemplate");
Host host = _dbClient.queryObject(Host.class, hostId);
ComputeSystem cs = _dbClient.queryObject(ComputeSystem.class, computeSystemId);
String sptDn = null;
try {
// Test mechanism to invoke a failure. No-op on production systems.
InvokeTestFailure.internalOnlyInvokeTestFailure(InvokeTestFailure.ARTIFICIAL_FAILURE_069);
// No need to check for initiators here, we are only unbinding the service profile template
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);
sptDn = template.getDn();
LsServer sp = ucsmService.getLsServer(getUcsmURL(cs).toString(), cs.getUsername(), cs.getPassword(), host.getUuid());
if (sp != null) {
URL ucsmURL = getUcsmURL(cs);
StringBuilder errorMessage = new StringBuilder();
if (null == ucsmService.unbindSPFromTemplate(ucsmURL.toString(), cs.getUsername(), cs.getPassword(), sp.getDn(), errorMessage)) {
LOGGER.error("Failed to unbind service profile from template due to error from UCSM Service. \n " + errorMessage.toString());
throw new RuntimeException("Failed to unbind service profile from template due to error from UCSM Service. \n " + errorMessage.toString());
}
LOGGER.info("Successfully unbound host {} from template {}", host.getLabel(), template.getLabel());
} else {
LOGGER.error("Unable to unbind service profile to template. LsServer is null");
throw new RuntimeException("Unable to unbind service profile to template. LsServer is null");
}
} else {
LOGGER.error("Unable to unbind service profile to template, due to insufficient host data. Host or ComputeElement or host UUID is null");
throw new RuntimeException("Unable to unbind 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 unbind service profile from template due to a exception", e);
throw ComputeSystemControllerException.exceptions.unbindHostFromTemplateFailed(host != null ? host.getId().toString() : null, e);
}
return sptDn;
}
Aggregations