use of com.emc.storageos.db.client.model.ComputeSystem in project coprhd-controller by CoprHD.
the class ImageServerControllerImpl method installOperatingSystem.
/**
* Install OS
* @param task {@link AsyncTask}
* @param computeImageJob {@link URI} compute imageJob id
* @throws InternalException
*/
@Override
public void installOperatingSystem(AsyncTask task, URI computeImageJob) throws InternalException {
log.info("installOperatingSystem");
Host host = dbClient.queryObject(Host.class, task._id);
ComputeElement ce = dbClient.queryObject(ComputeElement.class, host.getComputeElement());
ComputeSystem cs = dbClient.queryObject(ComputeSystem.class, ce.getComputeSystem());
ComputeImageJob job = dbClient.queryObject(ComputeImageJob.class, computeImageJob);
ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, job.getComputeImageServerId());
ComputeImage img = dbClient.queryObject(ComputeImage.class, job.getComputeImageId());
TaskCompleter completer = null;
try {
completer = new OsInstallCompleter(host.getId(), task._opId, job.getId(), EVENT_SERVICE_TYPE);
boolean imageServerVerified = verifyImageServer(imageServer);
if (!imageServerVerified) {
throw ImageServerControllerException.exceptions.imageServerNotSetup("Can't install operating system: " + imageServerErrorMsg);
}
Workflow workflow = workflowService.getNewWorkflow(this, OS_INSTALL_WF, true, task._opId);
String waitFor = null;
waitFor = workflow.createStep(OS_INSTALL_IMAGE_SERVER_CHECK_STEP, "image server check pre os install", waitFor, img.getId(), img.getImageType(), this.getClass(), new Workflow.Method("preOsInstallImageServerCheck", job.getId()), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
waitFor = workflow.createStep(OS_INSTALL_PREPARE_PXE_STEP, "prepare pxe boot", waitFor, img.getId(), img.getImageType(), this.getClass(), new Workflow.Method("preparePxeBootMethod", job.getId()), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
String prepStepId = workflow.createStepId();
waitFor = computeDeviceController.addStepsPreOsInstall(workflow, waitFor, cs.getId(), host.getId(), prepStepId);
waitFor = workflow.createStep(OS_INSTALL_WAIT_FOR_FINISH_STEP, "wait for os install to finish", waitFor, img.getId(), img.getImageType(), this.getClass(), new Workflow.Method("waitForFinishMethod", job.getId(), host.getHostName()), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
waitFor = computeDeviceController.addStepsPostOsInstall(workflow, waitFor, cs.getId(), ce.getId(), host.getId(), prepStepId, job.getVolumeId());
workflow.executePlan(completer, SUCCESS);
} catch (Exception e) {
log.error("installOperatingSystem caught an exception.", e);
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
completer.error(dbClient, serviceError);
}
}
use of com.emc.storageos.db.client.model.ComputeSystem in project coprhd-controller by CoprHD.
the class HostService method getHost.
/**
* Gets the information for one host.
*
* @param id
* the URN of a ViPR Host
* @brief Show host
* @return All the non-null attributes of the host.
* @throws DatabaseException
* when a DB error occurs.
*/
@GET
@Path("/{id}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public HostRestRep getHost(@PathParam("id") URI id) throws DatabaseException {
Host host = queryObject(Host.class, id, false);
// check the user permissions
verifyAuthorizedInTenantOrg(host.getTenant(), getUserFromContext());
ComputeElement computeElement = null;
UCSServiceProfile serviceProfile = null;
ComputeSystem computeSystem = null;
if (!NullColumnValueGetter.isNullURI(host.getComputeElement())) {
computeElement = queryObject(ComputeElement.class, host.getComputeElement(), false);
}
if (!NullColumnValueGetter.isNullURI(host.getServiceProfile())) {
serviceProfile = queryObject(UCSServiceProfile.class, host.getServiceProfile(), false);
}
if (serviceProfile != null) {
computeSystem = queryObject(ComputeSystem.class, serviceProfile.getComputeSystem(), false);
} else if (computeElement != null) {
computeSystem = queryObject(ComputeSystem.class, computeElement.getComputeSystem(), false);
}
return map(host, computeElement, serviceProfile, computeSystem);
}
use of com.emc.storageos.db.client.model.ComputeSystem in project coprhd-controller by CoprHD.
the class ComputeSystemService method deregisterComputeSystem.
/**
* De-registers a previously registered Compute System. (Creation and
* Discovery of the Compute System marks the Compute System "Registered" by
* default)
*
* @param id
* the URN of a ViPR Compute System
* @brief Deregister compute system
* @return A detailed representation of the Compute System
* @throws ControllerException
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deregister")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public ComputeSystemRestRep deregisterComputeSystem(@PathParam("id") URI id) throws ControllerException {
// Validate the storage system.
ArgValidator.checkUri(id);
ComputeSystem cs = _dbClient.queryObject(ComputeSystem.class, id);
ArgValidator.checkEntity(cs, id, isIdEmbeddedInURL(id));
if (!RegistrationStatus.UNREGISTERED.toString().equalsIgnoreCase(cs.getRegistrationStatus())) {
cs.setRegistrationStatus(RegistrationStatus.UNREGISTERED.toString());
_dbClient.persistObject(cs);
// Fetch all unprovisioned blades for this CS; remove them from any CVPs they are part of
ComputeElementListRestRep result = getComputeElements(cs.getId());
List<ComputeElementRestRep> blades = result.getList();
List<URI> unprovisionedBlades = new ArrayList<URI>();
for (ComputeElementRestRep ce : blades) {
if (ce.getAvailable()) {
unprovisionedBlades.add(ce.getId());
_log.debug("Found unprovisioned blade:" + ce.getName());
}
}
List<URI> cvpIds = _dbClient.queryByType(ComputeVirtualPool.class, true);
Iterator<ComputeVirtualPool> iter = _dbClient.queryIterativeObjects(ComputeVirtualPool.class, cvpIds);
while (iter.hasNext()) {
ComputeVirtualPool cvp = iter.next();
_log.debug("Remove unprovisioned blades from cvp: " + cvp.getLabel());
StringSet currentElements = new StringSet();
if (cvp.getMatchedComputeElements() != null) {
currentElements.addAll(cvp.getMatchedComputeElements());
for (URI bladeId : unprovisionedBlades) {
currentElements.remove(bladeId.toString());
}
}
cvp.setMatchedComputeElements(currentElements);
_dbClient.updateAndReindexObject(cvp);
_log.debug("Removed ces from cvp");
}
recordAndAudit(cs, OperationTypeEnum.DEREGISTER_COMPUTE_SYSTEM, true, null);
}
return getComputeSystem(id);
}
use of com.emc.storageos.db.client.model.ComputeSystem in project coprhd-controller by CoprHD.
the class ComputeSystemService method deleteComputeSystem.
/**
* Deletes a Compute System and the discovered information about it from
* ViPR
*
* @param id
* the URN of a ViPR Compute System to be deleted
* @brief Delete compute system
* @return TaskResourceRep (asynchronous call)
* @throws DatabaseException
*/
@POST
@Path("/{id}/deactivate")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep deleteComputeSystem(@PathParam("id") URI id) throws DatabaseException {
ComputeSystem cs = queryObject(ComputeSystem.class, id, true);
ArgValidator.checkEntity(cs, id, isIdEmbeddedInURL(id));
if (!RegistrationStatus.UNREGISTERED.toString().equals(cs.getRegistrationStatus())) {
throw APIException.badRequests.invalidParameterCannotDeactivateRegisteredComputeSystem(cs.getId());
}
List<String> provHosts = getProvisionedBlades(cs);
if (!provHosts.isEmpty()) {
throw APIException.badRequests.unableToDeactivateProvisionedComputeSystem(cs.getLabel(), org.springframework.util.StringUtils.collectionToCommaDelimitedString(provHosts));
}
ComputeController controller = getController(ComputeController.class, cs.getSystemType());
controller.clearDeviceSession(cs.getId());
String taskId = UUID.randomUUID().toString();
Operation op = _dbClient.createTaskOpStatus(ComputeSystem.class, cs.getId(), taskId, ResourceOperationTypeEnum.DELETE_COMPUTE_SYSTEM);
PurgeRunnable.executePurging(_dbClient, _dbPurger, _asynchJobService.getExecutorService(), cs, 0, /* _retry_attempts */
taskId, 60);
recordAndAudit(cs, OperationTypeEnum.DELETE_COMPUTE_SYSTEM, true, AuditLogManager.AUDITOP_BEGIN);
return toTask(cs, taskId, op);
}
use of com.emc.storageos.db.client.model.ComputeSystem in project coprhd-controller by CoprHD.
the class ComputeSystemService method createComputeSystem.
/**
* Creates and discovers a Compute System in ViPR
*
* @param param
* An instance of {@link ComputeSystemCreate} representing a
* Compute System to be created, not null
* @see ComputeSystemCreate
* @brief Create compute system
* @return Returns an instance of {@link TaskResourceRep} which represents
* the Task created for Discovery. The task can then be queried to
* know status and progress
* @throws DatabaseException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep createComputeSystem(ComputeSystemCreate param) throws DatabaseException {
// check device type
ArgValidator.checkFieldValueFromSystemType(param.getSystemType(), "system_type", Arrays.asList(ComputeSystem.Type.ucs));
ComputeSystem.Type deviceType = ComputeSystem.Type.valueOf(param.getSystemType());
ArgValidator.checkFieldNotNull(param.getName(), "name");
ArgValidator.checkFieldValidIP(param.getIpAddress(), "ip_address");
ArgValidator.checkFieldNotNull(param.getPortNumber(), "port_number");
ArgValidator.checkFieldNotNull(param.getUserName(), "user_name");
ArgValidator.checkFieldNotNull(param.getPassword(), "password");
// Check for existing device.
checkForDuplicateDevice(null, param.getIpAddress(), param.getPortNumber(), param.getName());
ComputeSystem cs = new ComputeSystem();
URI id = URIUtil.createId(ComputeSystem.class);
cs.setId(id);
cs.setLabel(param.getName());
cs.setIpAddress(param.getIpAddress());
cs.setPortNumber(param.getPortNumber());
cs.setSecure(param.getUseSSL());
cs.setUsername(param.getUserName());
cs.setPassword(param.getPassword());
cs.setSystemType(deviceType.name());
if (param.getOsInstallNetwork() != null) {
cs.setOsInstallNetwork(param.getOsInstallNetwork());
}
URI imageServerURI = param.getComputeImageServer();
associateImageServerToComputeSystem(imageServerURI, cs);
cs.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(cs));
cs.setRegistrationStatus(DiscoveredDataObject.RegistrationStatus.REGISTERED.name());
_dbClient.createObject(cs);
recordAndAudit(cs, OperationTypeEnum.CREATE_COMPUTE_SYSTEM, true, AuditLogManager.AUDITOP_BEGIN);
return doDiscoverComputeSystem(cs);
}
Aggregations