use of com.emc.storageos.db.client.model.ComputeElement in project coprhd-controller by CoprHD.
the class HostService method findComputeElementsUsedInCluster.
private Map<URI, List<ComputeElement>> findComputeElementsUsedInCluster(URI clusterId) throws DatabaseException {
Map<URI, List<ComputeElement>> computeSystemToComputeElementMap = new HashMap<URI, List<ComputeElement>>();
HostList hostList = clusterService.getClusterHosts(clusterId);
List<NamedRelatedResourceRep> list = hostList.getHosts();
for (NamedRelatedResourceRep hostRep : list) {
HostRestRep host = getHost(hostRep.getId());
RelatedResourceRep computeElement = host.getComputeElement();
if (computeElement == null) {
// this can happen if cluster has hosts that were not provisioned by vipr
continue;
}
ComputeElement ce = _dbClient.queryObject(ComputeElement.class, computeElement.getId());
URI computeSystem = ce.getComputeSystem();
List<ComputeElement> usedComputeElements;
if (computeSystemToComputeElementMap.containsKey(computeSystem)) {
usedComputeElements = computeSystemToComputeElementMap.get(computeSystem);
} else {
usedComputeElements = new ArrayList<ComputeElement>();
}
usedComputeElements.add(ce);
computeSystemToComputeElementMap.put(computeSystem, usedComputeElements);
}
return computeSystemToComputeElementMap;
}
use of com.emc.storageos.db.client.model.ComputeElement in project coprhd-controller by CoprHD.
the class HostService method osInstall.
/**
* Install operating system on the host.
*
* @param hostId
* host URI
* @param param
* OS install data
* @brief Install operating system on the host
* @return TaskResourceRep (asynchronous call)
*/
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/os-install")
public TaskResourceRep osInstall(@PathParam("id") URI hostId, OsInstallParam param) {
// validate params
ArgValidator.checkFieldUriType(hostId, Host.class, "id");
ArgValidator.checkFieldNotNull(param.getComputeImage(), "compute_image");
// get data
ComputeImage img = queryObject(ComputeImage.class, param.getComputeImage(), true);
ArgValidator.checkEntity(img, param.getComputeImage(), isIdEmbeddedInURL(param.getComputeImage()));
if (!ComputeImageStatus.AVAILABLE.name().equals(img.getComputeImageStatus())) {
throw APIException.badRequests.invalidParameterComputeImageIsNotAvailable(img.getId());
}
ArgValidator.checkFieldNotEmpty(param.getHostIp(), "host_ip");
Host host = queryObject(Host.class, hostId, true);
ArgValidator.checkEntity(host, hostId, isIdEmbeddedInURL(hostId));
// COP-28718 Fixed by making sure that the host we are installing OS does not cause an IP conflict
// by throwing appropriate exception.
verifyHostForDuplicateIP(host, param);
// only support os install on hosts with compute elements
if (NullColumnValueGetter.isNullURI(host.getComputeElement())) {
throw APIException.badRequests.invalidParameterHostHasNoComputeElement();
}
if (!host.getType().equals(Host.HostType.No_OS.name()) && !param.getForceInstallation()) {
throw APIException.badRequests.invalidParameterHostAlreadyHasOs(host.getType());
}
if (!StringUtils.isNotBlank(param.getRootPassword())) {
throw APIException.badRequests.hostPasswordNotSet();
} else {
host.setPassword(param.getRootPassword());
host.setUsername("root");
}
// check that CS has os install network
ComputeElement ce = queryObject(ComputeElement.class, host.getComputeElement(), true);
ArgValidator.checkEntity(ce, host.getComputeElement(), isIdEmbeddedInURL(host.getComputeElement()));
if (ce.getUuid() == null) {
throw APIException.badRequests.computeElementHasNoUuid();
}
ComputeSystem cs = queryObject(ComputeSystem.class, ce.getComputeSystem(), true);
ArgValidator.checkEntity(cs, ce.getComputeSystem(), isIdEmbeddedInURL(ce.getComputeSystem()));
verifyImagePresentOnImageServer(cs, img);
if (!StringUtils.isNotBlank(cs.getOsInstallNetwork())) {
throw APIException.badRequests.osInstallNetworkNotSet();
}
if (!cs.getVlans().contains(cs.getOsInstallNetwork())) {
throw APIException.badRequests.osInstallNetworkNotValid(cs.getOsInstallNetwork());
}
// check that there is no os install in progress for this host
URIQueryResultList jobUriList = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeImageJobsByHostConstraint(host.getId()), jobUriList);
Iterator<URI> iterator = jobUriList.iterator();
while (iterator.hasNext()) {
ComputeImageJob existingJob = _dbClient.queryObject(ComputeImageJob.class, iterator.next());
if (!existingJob.getInactive() && existingJob.getJobStatus().equals(ComputeImageJob.JobStatus.CREATED.name())) {
throw APIException.badRequests.osInstallAlreadyInProgress();
}
}
// openssl passwd -1 (MD5 encryption of password)
String passwordHash = Md5Crypt.md5Crypt(host.getPassword().getBytes());
// create session
ComputeImageJob job = new ComputeImageJob();
job.setId(URIUtil.createId(ComputeImageJob.class));
job.setComputeImageId(img.getId());
job.setHostId(host.getId());
job.setPasswordHash(passwordHash);
job.setHostName(param.getHostName());
job.setHostIp(param.getHostIp());
job.setNetmask(param.getNetmask());
job.setGateway(param.getGateway());
job.setNtpServer(param.getNtpServer());
job.setDnsServers(param.getDnsServers());
job.setManagementNetwork(param.getManagementNetwork());
job.setPxeBootIdentifier(ImageServerUtils.uuidFromString(host.getUuid()).toString());
job.setComputeImageServerId(cs.getComputeImageServer());
// volume id is optional
if (!NullColumnValueGetter.isNullURI(param.getVolume()) || !NullColumnValueGetter.isNullURI(host.getBootVolumeId())) {
Volume vol = null;
if (!NullColumnValueGetter.isNullURI(param.getVolume())) {
vol = queryObject(Volume.class, param.getVolume(), true);
host.setBootVolumeId(vol.getId());
} else {
vol = queryObject(Volume.class, host.getBootVolumeId(), true);
}
job.setVolumeId(vol.getId());
StorageSystem st = queryObject(StorageSystem.class, vol.getStorageController(), true);
// XtremIO uses some other ID type (e.g. 514f0c5dc9600016)
if (st != null && DiscoveredDataObject.Type.xtremio.name().equals(st.getSystemType())) {
_log.info("xtremio volume id {}", vol.getNativeId());
job.setBootDevice(vol.getNativeId());
} else {
_log.info("volume id {}", vol.getWWN());
job.setBootDevice(ImageServerUtils.uuidFromString(vol.getWWN()).toString());
}
}
host.setProvisioningStatus(ProvisioningJobStatus.IN_PROGRESS.toString());
_dbClient.persistObject(host);
_dbClient.createObject(job);
// create task
String taskId = UUID.randomUUID().toString();
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.INSTALL_OPERATING_SYSTEM);
_dbClient.createTaskOpStatus(Host.class, host.getId(), taskId, op);
ImageServerController controller = getController(ImageServerController.class, null);
AsyncTask task = new AsyncTask(Host.class, host.getId(), taskId);
try {
controller.installOperatingSystem(task, job.getId());
} catch (InternalException e) {
_log.error("Did not install OS due to controller error", e);
job.setJobStatus(ComputeImageJob.JobStatus.FAILED.name());
_dbClient.persistObject(job);
_dbClient.error(Host.class, host.getId(), taskId, e);
}
return toTask(host, taskId, op);
}
use of com.emc.storageos.db.client.model.ComputeElement in project coprhd-controller by CoprHD.
the class ComputeElementService method getComputeElement.
/**
* Gets the data for a compute element.
*
* @param id the URN of a ViPR compute element.
*
* @brief Show compute element
* @return A ComputeElementRestRep reference specifying the data for the
* compute element with the passed id.
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public ComputeElementRestRep getComputeElement(@PathParam("id") URI id) {
ArgValidator.checkFieldUriType(id, ComputeElement.class, "id");
ComputeElement ce = queryResource(id);
ArgValidator.checkEntity(ce, id, isIdEmbeddedInURL(id));
Host associatedHost = getAssociatedHost(ce, _dbClient);
Cluster cluster = null;
if (associatedHost != null && !NullColumnValueGetter.isNullURI(associatedHost.getCluster())) {
cluster = _dbClient.queryObject(Cluster.class, associatedHost.getCluster());
}
return ComputeMapper.map(ce, associatedHost, cluster);
}
use of com.emc.storageos.db.client.model.ComputeElement in project coprhd-controller by CoprHD.
the class ComputeElementService method queryRegisteredResource.
/**
* Gets the compute element with the passed id from the database.
*
* @param id the URN of a ViPR compute element.
*
* @return A reference to the registered compute element.
*
* @throws BadRequestException When the compute element is not registered.
*/
protected ComputeElement queryRegisteredResource(URI id) {
ArgValidator.checkUri(id);
ComputeElement ce = _dbClient.queryObject(ComputeElement.class, id);
ArgValidator.checkEntityNotNull(ce, id, isIdEmbeddedInURL(id));
if (!RegistrationStatus.REGISTERED.toString().equalsIgnoreCase(ce.getRegistrationStatus())) {
throw APIException.badRequests.resourceNotRegistered(ComputeElement.class.getSimpleName(), id);
}
return ce;
}
use of com.emc.storageos.db.client.model.ComputeElement in project coprhd-controller by CoprHD.
the class ComputeSystemService method getComputeElements.
/**
* Fetches all the Compute Elements belonging to a Compute System in ViPR
*
* @param id
* the URN of a ViPR Compute System
* @brief Show compute elements
* @return A detailed representation of compute elements
* @throws InternalException
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/compute-elements")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public ComputeElementListRestRep getComputeElements(@PathParam("id") URI id) throws InternalException {
ComputeElementListRestRep result = new ComputeElementListRestRep();
ArgValidator.checkFieldUriType(id, ComputeSystem.class, "id");
ComputeSystem cs = queryResource(id);
URIQueryResultList ceUriList = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getComputeSystemComputeElemetsConstraint(cs.getId()), ceUriList);
Iterator<URI> iterator = ceUriList.iterator();
Collection<URI> hostIds = _dbClient.queryByType(Host.class, true);
Collection<Host> hosts = _dbClient.queryObjectFields(Host.class, Arrays.asList("label", "computeElement", "cluster"), ControllerUtils.getFullyImplementedCollection(hostIds));
while (iterator.hasNext()) {
ComputeElement ce = _dbClient.queryObject(ComputeElement.class, iterator.next());
if (ce != null) {
Host associatedHost = null;
for (Host host : hosts) {
if (!NullColumnValueGetter.isNullURI(host.getComputeElement()) && host.getComputeElement().equals(ce.getId())) {
associatedHost = host;
break;
}
}
Cluster cluster = null;
if (associatedHost != null && !NullColumnValueGetter.isNullURI(associatedHost.getCluster())) {
cluster = _dbClient.queryObject(Cluster.class, associatedHost.getCluster());
}
ComputeElementRestRep rest = map(ce, associatedHost, cluster);
if (rest != null) {
result.getList().add(rest);
}
}
}
return result;
}
Aggregations