use of com.emc.storageos.db.client.model.UCSServiceProfileTemplate in project coprhd-controller by CoprHD.
the class ComputeDeviceControllerImpl method addStepsPostOsInstall.
/**
* Create/Add PostOsInstall steps to the workflow.
*
* @param workflow
* {@link Workflow} instance
* @param waitFor
* If non-null, the step will not be queued for execution in the
* Dispatcher until the Step or StepGroup indicated by the
* waitFor has completed. The waitFor may either be a string
* representation of a Step UUID, or the name of a StepGroup.
* @param computeSystemId
* {@link URI} computeSystem Id
* @param computeElementId
* {@link URI} computeElement Id
* @param hostId
* {@link URI} host Id
* @param contextStepId
* {@link String} step Id
* @param volumeId
* {@link URI} bootvolume Id
* @return waitFor step name
*/
@Override
public String addStepsPostOsInstall(Workflow workflow, String waitFor, URI computeSystemId, URI computeElementId, URI hostId, String contextStepId, URI volumeId) {
ComputeSystem cs = _dbClient.queryObject(ComputeSystem.class, computeSystemId);
waitFor = workflow.createStep(OS_INSTALL_REMOVE_OS_NETWORK, "remove network after os install", waitFor, cs.getId(), cs.getSystemType(), this.getClass(), new Workflow.Method("removeOsInstallNetworkStep", computeSystemId, computeElementId, contextStepId), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
waitFor = workflow.createStep(OS_INSTALL_SET_SAN_BOOT_TARGET, "Set the SAN boot target based on the storage ports used in the volume export", waitFor, cs.getId(), cs.getSystemType(), this.getClass(), new Workflow.Method("setSanBootTargetStep", computeSystemId, computeElementId, hostId, volumeId), new Workflow.Method("setNoBootStep", computeSystemId, computeElementId, hostId), null);
ComputeElement ce = _dbClient.queryObject(ComputeElement.class, computeElementId);
if (ce.getSptId() != null) {
URI sptId = URI.create(ce.getSptId());
UCSServiceProfileTemplate template = _dbClient.queryObject(UCSServiceProfileTemplate.class, sptId);
// TODO COP-28960 check for template not null
if (template.getUpdating()) {
waitFor = workflow.createStep(REBIND_HOST_TO_TEMPLATE, "Rebind host to service profile template after OS install", waitFor, cs.getId(), cs.getSystemType(), this.getClass(), new Workflow.Method("rebindHostToTemplateStep", computeSystemId, hostId), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
}
} else {
log.error("Serviceprofile ID attribute is null.");
throw new IllegalArgumentException("addStepsPostOsInstall method failed. Could not find Serviceprofile template id from computeElement " + ce.getLabel());
}
return waitFor;
}
use of com.emc.storageos.db.client.model.UCSServiceProfileTemplate 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.UCSServiceProfileTemplate 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;
}
use of com.emc.storageos.db.client.model.UCSServiceProfileTemplate in project coprhd-controller by CoprHD.
the class UcsComputeDevice method getSptDNFromVCP.
private String getSptDNFromVCP(ComputeSystem computeSystem, ComputeVirtualPool virtualPool) {
StringSet spts = virtualPool.getServiceProfileTemplates();
if (spts == null) {
return null;
}
for (String sptId : spts) {
URI sptUri = URI.create(sptId);
UCSServiceProfileTemplate serviceProfileTemplate = _dbClient.queryObject(UCSServiceProfileTemplate.class, sptUri);
if (serviceProfileTemplate != null && serviceProfileTemplate.getComputeSystem() != null && serviceProfileTemplate.getComputeSystem().equals(computeSystem.getId())) {
return serviceProfileTemplate.getDn();
}
}
return null;
}
use of com.emc.storageos.db.client.model.UCSServiceProfileTemplate 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);
}
}
Aggregations