use of com.emc.storageos.db.client.model.ComputeImageServer 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.ComputeImageServer in project coprhd-controller by CoprHD.
the class ImageServerControllerImpl method verifyImageServerAndImportExistingImages.
/**
* Method to verify and import images on the imageserver
*
* @param task {@link AsyncTask} instance
* @param opName operation Name
*/
@Override
public void verifyImageServerAndImportExistingImages(AsyncTask task, String opName) {
TaskCompleter completer = null;
log.info("Verifying imageServer and importing any existing images on to the server");
try {
URI computeImageServerID = task._id;
completer = new ComputeImageServerCompleter(computeImageServerID, task._opId, OperationTypeEnum.IMAGESERVER_VERIFY_IMPORT_IMAGES, EVENT_SERVICE_TYPE);
Workflow workflow = workflowService.getNewWorkflow(this, IMAGESERVER_VERIFY_IMPORT_IMAGE_WF, true, task._opId);
workflow.createStep(IMAGESERVER_VERIFICATION_STEP, String.format("Verfiying ImageServer %s", computeImageServerID), null, computeImageServerID, computeImageServerID.toString(), this.getClass(), new Workflow.Method("verifyComputeImageServer", computeImageServerID), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
List<ComputeImage> computeImageList = getAllComputeImages();
if (!CollectionUtils.isEmpty(computeImageList)) {
ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, computeImageServerID);
for (ComputeImage computeImage : computeImageList) {
if (null == imageServer.getComputeImages() || !imageServer.getComputeImages().contains(computeImage.getId().toString())) {
StringBuilder msg = new StringBuilder("Importing image ");
msg.append(computeImage.getLabel()).append(" on to imageServer - ");
msg.append(imageServer.getImageServerIp()).append(".");
workflow.createStep(IMAGESERVER_IMPORT_IMAGES_STEP, msg.toString(), IMAGESERVER_VERIFICATION_STEP, computeImageServerID, computeImageServerID.toString(), this.getClass(), new Workflow.Method("importImageMethod", computeImage.getId(), imageServer, opName), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
}
}
}
workflow.executePlan(completer, SUCCESS);
} catch (Exception ex) {
log.error("Unexpected exception waiting for finish: " + ex.getMessage(), ex);
}
}
use of com.emc.storageos.db.client.model.ComputeImageServer in project coprhd-controller by CoprHD.
the class ImageServerControllerImpl method updateFailedImages.
/**
* Updates the imageServer with the image that failed import, this method updates
* it as failed only after making sure that the image was not previously successful.
* @param imageServerURI {@link URI} imageServerURI instance to which import was made.
* @param image {@link ComputeImage} instance that failed the import.
*/
private void updateFailedImages(URI imageServerURI, ComputeImage image) {
if (null != imageServerURI && null != image) {
String imageURIStr = image.getId().toString();
log.info("updateFailedImages : update failed image import details.");
// first fetch updated imageServer details from DB and
// verify if image was previously loaded successfully on to
// the imageServer, if so then skip updating it as failed else
// update it as failed.
ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, imageServerURI);
if (imageServer.getComputeImages() == null || !imageServer.getComputeImages().contains(imageURIStr)) {
// update the imageServer with the failed image.
if (imageServer.getFailedComputeImages() == null) {
imageServer.setFailedComputeImages(new StringSet());
}
log.info("Image - {} failed to import on imageServer - {}", image.getLabel(), imageServer.getLabel());
imageServer.getFailedComputeImages().add(imageURIStr);
dbClient.updateObject(imageServer);
}
}
}
use of com.emc.storageos.db.client.model.ComputeImageServer in project coprhd-controller by CoprHD.
the class ImageServerControllerImpl method deleteImage.
/**
* Delete image from all available imageServers
*
* @param task {@link AsyncTask} instance
*/
@Override
public void deleteImage(AsyncTask task) throws InternalException {
log.info("deleteImage " + task._id);
URI ciId = task._id;
TaskCompleter completer = null;
try {
completer = new ComputeImageCompleter(ciId, task._opId, OperationTypeEnum.DELETE_COMPUTE_IMAGE, EVENT_SERVICE_TYPE);
Workflow workflow = workflowService.getNewWorkflow(this, DELETE_IMAGE_WF, true, task._opId);
List<URI> ids = dbClient.queryByType(ComputeImageServer.class, true);
for (URI imageServerId : ids) {
ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, imageServerId);
if (imageServer.getComputeImages() != null && imageServer.getComputeImages().contains(ciId.toString())) {
boolean imageServerVerified = verifyImageServer(imageServer);
if (!imageServerVerified) {
throw ImageServerControllerException.exceptions.imageServerNotSetup("Can't delete image: " + imageServerErrorMsg);
}
workflow.createStep(DELETE_IMAGE_STEP, String.format("removing image %s", ciId), null, ciId, ciId.toString(), this.getClass(), new Workflow.Method("deleteImageMethod", ciId, imageServer.getId()), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
}
// So this cleanup needs to be performed.
if (imageServer.getFailedComputeImages() != null && imageServer.getFailedComputeImages().contains(ciId.toString())) {
imageServer.getFailedComputeImages().remove(ciId.toString());
dbClient.updateObject(imageServer);
}
}
workflow.executePlan(completer, SUCCESS);
} catch (Exception e) {
log.error("deleteImage caught an exception.", e);
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
completer.error(dbClient, serviceError);
}
}
use of com.emc.storageos.db.client.model.ComputeImageServer in project coprhd-controller by CoprHD.
the class ImageServerControllerImpl method importImageToServers.
/**
* Import image to all available imageServer
*
* @param task {@link AsyncTask} instance
*/
@Override
public void importImageToServers(AsyncTask task) throws InternalException {
log.info("importImage");
URI ciId = task._id;
boolean wfHasSteps = false;
Workflow workflow = workflowService.getNewWorkflow(this, IMPORT_IMAGE_WF, true, task._opId);
TaskCompleter completer = new ComputeImageCompleter(ciId, task._opId, OperationTypeEnum.CREATE_COMPUTE_IMAGE, EVENT_SERVICE_TYPE);
try {
List<URI> ids = dbClient.queryByType(ComputeImageServer.class, true);
for (URI imageServerId : ids) {
log.info("import to server:" + imageServerId.toString());
ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, imageServerId);
if (imageServer.getComputeImages() == null || !imageServer.getComputeImages().contains(ciId.toString())) {
log.info("verify Image Server");
String verifyServerStepId = workflow.createStep(IMAGESERVER_VERIFICATION_STEP, String.format("Verifying ImageServer %s", imageServerId), null, imageServerId, imageServerId.toString(), this.getClass(), new Workflow.Method("verifyComputeImageServer", imageServerId), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
workflow.createStep(IMPORT_IMAGE_TO_SERVER_STEP, String.format("Importing image for %s", imageServerId), verifyServerStepId, imageServerId, imageServerId.toString(), this.getClass(), new Workflow.Method("importImageMethod", ciId, imageServer, null), new Workflow.Method(ROLLBACK_NOTHING_METHOD), null);
wfHasSteps = true;
}
}
if (wfHasSteps) {
workflow.executePlan(completer, SUCCESS);
}
} catch (Exception e) {
log.error("importImage caught an exception.", e);
ServiceError serviceError = DeviceControllerException.errors.jobFailed(e);
completer.error(dbClient, serviceError);
}
}
Aggregations