use of com.emc.storageos.db.client.model.ComputeImageServer in project coprhd-controller by CoprHD.
the class ImageServerControllerImpl method preOsInstallImageServerCheck.
/**
* Performs preOs install check on the imageServer
* @param jobId {@link URI} job id
* @param stepId {@link String} step id
*/
public void preOsInstallImageServerCheck(URI jobId, String stepId) {
log.info("preOsInstallImageServerCheck {} ", jobId);
ImageServerDialog d = null;
try {
WorkflowStepCompleter.stepExecuting(stepId);
ComputeImageJob job = dbClient.queryObject(ComputeImageJob.class, jobId);
ComputeImage img = dbClient.queryObject(ComputeImage.class, job.getComputeImageId());
ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, job.getComputeImageServerId());
SSHSession session = new SSHSession();
session.connect(imageServer.getImageServerIp(), imageServer.getSshPort(), imageServer.getImageServerUser(), imageServer.getImageServerPassword());
d = new ImageServerDialog(session, imageServer.getSshTimeoutMs());
d.init();
log.info("connected to image server");
log.info("verify the image is still there");
if (!d.directoryExists(imageServer.getTftpBootDir() + img.getPathToDirectory())) {
log.error("the image is missing");
throw ImageServerControllerException.exceptions.computeImageIsMissing(img.getPathToDirectory());
}
String pid = d.getServerPid("67");
if (pid == null) {
// dhcp down
throw ImageServerControllerException.exceptions.dhcpServerNotRunning();
}
pid = d.getServerPid("69");
if (pid == null) {
// tftp down
throw ImageServerControllerException.exceptions.tftpServerNotRunning();
}
log.info("make sure the python server is running");
pid = d.getServerPid(imageServer.getImageServerHttpPort());
if (pid == null) {
log.warn("python server is not running, attempt to start it");
d.cd(imageServer.getTftpBootDir() + HTTP_DIR);
d.nohup(String.format("python %s", SERVER_PY_FILE));
pid = d.getServerPid(imageServer.getImageServerHttpPort());
if (pid == null) {
throw ImageServerControllerException.exceptions.httpPythonServerNotRunning();
}
}
WorkflowStepCompleter.stepSucceded(stepId);
} catch (InternalException e) {
log.error("Exception during image server check pre os install: " + e.getMessage(), e);
WorkflowStepCompleter.stepFailed(stepId, e);
} catch (Exception e) {
log.error("Unexpected exception during image server check pre os install: " + e.getMessage(), e);
String opName = ResourceOperationTypeEnum.INSTALL_OPERATING_SYSTEM.getName();
WorkflowStepCompleter.stepFailed(stepId, ImageServerControllerException.exceptions.unexpectedException(opName, e));
} finally {
try {
if (d != null && d.isConnected()) {
d.close();
}
} catch (Exception e) {
log.error(FAILED_TO_CLOSE_STR, e);
}
}
}
use of com.emc.storageos.db.client.model.ComputeImageServer in project coprhd-controller by CoprHD.
the class OsInstallStatusPoller method pollImageServer.
private void pollImageServer() {
log.debug("pollImageServer");
List<URI> ids = dbClient.queryByType(ComputeImageServer.class, true);
for (URI imageServerId : ids) {
ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, imageServerId);
ImageServerDialog d = null;
String[] successes = null;
String[] failures = null;
try {
SSHSession session = new SSHSession();
session.connect(imageServer.getImageServerIp(), imageServer.getSshPort(), imageServer.getImageServerUser(), imageServer.getImageServerPassword());
d = new ImageServerDialog(session, imageServer.getSshTimeoutMs());
d.init();
successes = d.lsDir(imageServer.getTftpBootDir() + HTTP_SUCCESS_DIR);
failures = d.lsDir(imageServer.getTftpBootDir() + HTTP_FAILURE_DIR);
log.info("successes: {}; failures: {}", Arrays.asList(successes), Arrays.asList(failures));
if (successes != null) {
for (String sessionId : successes) {
sessionStatusMap.put(sessionId, OsInstallStatus.SUCCESS);
}
}
if (failures != null) {
for (String sessionId : failures) {
sessionStatusMap.put(sessionId, OsInstallStatus.FAILURE);
}
}
} catch (Exception e) {
log.error("Unexpected exception when polling image server: " + e.getMessage(), e);
} finally {
try {
if (d != null && d.isConnected()) {
d.close();
}
} catch (Exception e) {
log.error("failed to close image server dialog", e);
}
}
}
}
use of com.emc.storageos.db.client.model.ComputeImageServer in project coprhd-controller by CoprHD.
the class ComputeImageServerService method createComputeImageServer.
/**
* Create the Compute image server
*
* @param createParams
* {@link ComputeImageServerCreate} containing the details
*
* @brief Define a new image server, including TFTP info
* @return {@link TaskResourceRep} instance
*/
@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 createComputeImageServer(ComputeImageServerCreate createParams) {
log.info("Create computeImageServer");
String imageServerName = createParams.getName();
String imageServerAddress = createParams.getImageServerIp();
ArgValidator.checkFieldNotEmpty(imageServerName, "imageServerName");
ArgValidator.checkIpIsNotNumeric(imageServerAddress, IMAGESERVER_IP);
checkDuplicateImageServer(null, imageServerAddress, imageServerName);
String bootDir = createParams.getTftpBootDir();
String osInstallAddress = createParams.getImageServerSecondIp();
String username = createParams.getImageServerUser();
String password = createParams.getImageServerPassword();
Integer installTimeout = createParams.getOsInstallTimeout();
Integer sshTimeout = createParams.getSshTimeout();
Integer imageImportTimeout = createParams.getImageImportTimeout();
ArgValidator.checkFieldNotEmpty(bootDir, TFTPBOOTDIR);
ArgValidator.checkIpIsNotNumeric(osInstallAddress, IMAGESERVER_SECONDARY_IP);
ArgValidator.checkFieldNotEmpty(username, IMAGESERVER_USER);
ArgValidator.checkFieldNotEmpty(password, IMAGESERVER_PASSWORD);
ArgValidator.checkFieldNotNull(installTimeout, OS_INSTALL_TIMEOUT_MS);
ArgValidator.checkFieldRange(installTimeout, 0, 2147483, "seconds", "osInstallTimeout");
ArgValidator.checkFieldNotNull(sshTimeout, OS_INSTALL_TIMEOUT_MS);
ArgValidator.checkFieldRange(sshTimeout, 0, 2147483, "seconds", "sshTimeout");
ArgValidator.checkFieldNotNull(imageImportTimeout, OS_INSTALL_TIMEOUT_MS);
ArgValidator.checkFieldRange(installTimeout, 0, 2147483, "seconds", "imageImportTimeout");
ComputeImageServer imageServer = new ComputeImageServer();
imageServer.setId(URIUtil.createId(ComputeImageServer.class));
imageServer.setLabel(imageServerName);
imageServer.setImageServerIp(imageServerAddress);
imageServer.setTftpBootDir(bootDir);
imageServer.setImageServerUser(username);
imageServer.setImageServerPassword(password);
imageServer.setOsInstallTimeoutMs(new Long(TimeUnit.SECONDS.toMillis(installTimeout)).intValue());
imageServer.setImageServerSecondIp(osInstallAddress);
imageServer.setImageDir(_coordinator.getPropertyInfo().getProperty(IMAGE_SERVER_IMAGEDIR));
imageServer.setSshTimeoutMs(new Long(TimeUnit.SECONDS.toMillis(sshTimeout)).intValue());
imageServer.setImageImportTimeoutMs(new Long(TimeUnit.SECONDS.toMillis(imageImportTimeout)).intValue());
auditOp(OperationTypeEnum.IMAGESERVER_VERIFY_IMPORT_IMAGES, true, null, imageServer.getId().toString(), imageServer.getImageServerIp());
_dbClient.createObject(imageServer);
ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>(1);
String taskId = UUID.randomUUID().toString();
AsyncTask task = new AsyncTask(ComputeImageServer.class, imageServer.getId(), taskId);
tasks.add(task);
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.CREATE_VERIFY_COMPUTE_IMAGE_SERVER);
_dbClient.createTaskOpStatus(ComputeImageServer.class, imageServer.getId(), taskId, op);
ImageServerController controller = getController(ImageServerController.class, null);
controller.verifyImageServerAndImportExistingImages(task, op.getName());
return toTask(imageServer, taskId, op);
}
use of com.emc.storageos.db.client.model.ComputeImageServer in project coprhd-controller by CoprHD.
the class ComputeImageServerService method updateComputeImageServer.
/**
* Update the Compute image server details
*
* @param id
* the URN of a ViPR compute image server
*
* @brief Change an image server, including TFTP info
* @return Updated compute image server information.
*/
@PUT
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public ComputeImageServerRestRep updateComputeImageServer(@PathParam("id") URI id, ComputeImageServerUpdate param) {
log.info("Update computeImageServer id {} ", id);
ComputeImageServer imageServer = _dbClient.queryObject(ComputeImageServer.class, id);
if (null == imageServer || imageServer.getInactive()) {
throw APIException.notFound.unableToFindEntityInURL(id);
} else {
StringSet availImages = imageServer.getComputeImages();
// make sure there are no active jobs associated with this imageserver
checkActiveJobsForImageServer(id);
String imageServerName = param.getName();
String imageServerAddress = param.getImageServerIp();
String bootDir = param.getTftpBootDir();
String osInstallAddress = param.getImageServerSecondIp();
String username = param.getImageServerUser();
String password = param.getImageServerPassword();
Integer installTimeout = param.getOsInstallTimeout();
Integer sshTimeout = param.getSshTimeout();
Integer imageImportTimeout = param.getImageImportTimeout();
if (StringUtils.isNotBlank(imageServerName) && !imageServerName.equalsIgnoreCase(imageServer.getLabel())) {
checkDuplicateLabel(ComputeImageServer.class, imageServerName);
imageServer.setLabel(param.getName());
}
if (StringUtils.isNotBlank(imageServerAddress) && !imageServerAddress.equalsIgnoreCase(imageServer.getImageServerIp())) {
checkDuplicateImageServer(id, imageServerAddress, null);
disassociateComputeImages(imageServer);
imageServer.setImageServerIp(imageServerAddress);
}
if (StringUtils.isNotBlank(osInstallAddress)) {
imageServer.setImageServerSecondIp(osInstallAddress);
}
if (StringUtils.isNotBlank(username)) {
imageServer.setImageServerUser(username);
}
if (null != installTimeout) {
ArgValidator.checkFieldRange(installTimeout, 0, 2147483, "seconds", "osInstallTimeout");
imageServer.setOsInstallTimeoutMs(new Long(TimeUnit.SECONDS.toMillis(installTimeout)).intValue());
}
if (null != sshTimeout) {
ArgValidator.checkFieldRange(sshTimeout, 0, 2147483, "seconds", "sshTimeout");
imageServer.setSshTimeoutMs(new Long(TimeUnit.SECONDS.toMillis(sshTimeout)).intValue());
}
if (null != imageImportTimeout) {
ArgValidator.checkFieldRange(imageImportTimeout, 0, 2147483, "seconds", "imageImportTimeout");
imageServer.setImageImportTimeoutMs(new Long(TimeUnit.SECONDS.toMillis(imageImportTimeout)).intValue());
}
if (StringUtils.isNotBlank(bootDir)) {
if (!CollectionUtils.isEmpty(availImages) && !imageServer.getTftpBootDir().equals(bootDir)) {
log.info("Cannot update TFTPBOOT directory, while " + "an image server has associated successful import images.");
throw APIException.badRequests.cannotUpdateTFTPBOOTDirectory();
} else {
imageServer.setTftpBootDir(bootDir);
}
}
if (StringUtils.isNotBlank(password)) {
imageServer.setImageServerPassword(password);
}
auditOp(OperationTypeEnum.IMAGESERVER_VERIFY_IMPORT_IMAGES, true, null, imageServer.getId().toString(), imageServer.getImageServerIp());
_dbClient.updateObject(imageServer);
ArrayList<AsyncTask> tasks = new ArrayList<AsyncTask>(1);
String taskId = UUID.randomUUID().toString();
AsyncTask task = new AsyncTask(ComputeImageServer.class, imageServer.getId(), taskId);
tasks.add(task);
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.UPDATE_VERIFY_COMPUTE_IMAGE_SERVER);
_dbClient.createTaskOpStatus(ComputeImageServer.class, imageServer.getId(), taskId, op);
ImageServerController controller = getController(ImageServerController.class, null);
controller.verifyImageServerAndImportExistingImages(task, op.getName());
}
return map(_dbClient, imageServer);
}
use of com.emc.storageos.db.client.model.ComputeImageServer in project coprhd-controller by CoprHD.
the class ComputeImageServerService method getComputeImageServers.
/**
* Returns a list of all compute image servers.
*
* @brief Show compute image servers
* @return List of all compute image servers.
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.SYSTEM_MONITOR })
public ComputeImageServerList getComputeImageServers() {
List<URI> ids = _dbClient.queryByType(ComputeImageServer.class, true);
ComputeImageServerList imageServerList = new ComputeImageServerList();
Iterator<ComputeImageServer> iter = _dbClient.queryIterativeObjects(ComputeImageServer.class, ids);
while (iter.hasNext()) {
ComputeImageServer imageServer = iter.next();
imageServerList.getComputeImageServers().add(DbObjectMapper.toNamedRelatedResource(imageServer));
}
return imageServerList;
}
Aggregations