Search in sources :

Example 6 with ComputeImageServer

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);
        }
    }
}
Also used : SSHSession(com.emc.storageos.networkcontroller.SSHSession) ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) ComputeImageJob(com.emc.storageos.db.client.model.ComputeImageJob) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MalformedURLException(java.net.MalformedURLException) ImageServerControllerException(com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException) ComputeImage(com.emc.storageos.db.client.model.ComputeImage) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException)

Example 7 with ComputeImageServer

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);
            }
        }
    }
}
Also used : SSHSession(com.emc.storageos.networkcontroller.SSHSession) ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) URI(java.net.URI)

Example 8 with ComputeImageServer

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);
}
Also used : ImageServerController(com.emc.storageos.imageservercontroller.ImageServerController) ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayList(java.util.ArrayList) Operation(com.emc.storageos.db.client.model.Operation) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 9 with ComputeImageServer

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);
}
Also used : ImageServerController(com.emc.storageos.imageservercontroller.ImageServerController) ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) StringSet(com.emc.storageos.db.client.model.StringSet) AsyncTask(com.emc.storageos.volumecontroller.AsyncTask) ArrayList(java.util.ArrayList) Operation(com.emc.storageos.db.client.model.Operation) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Consumes(javax.ws.rs.Consumes) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 10 with ComputeImageServer

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;
}
Also used : ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) ComputeImageServerList(com.emc.storageos.model.compute.ComputeImageServerList) URI(java.net.URI) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

ComputeImageServer (com.emc.storageos.db.client.model.ComputeImageServer)26 URI (java.net.URI)13 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)9 ImageServerControllerException (com.emc.storageos.imageservercontroller.exceptions.ImageServerControllerException)9 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)9 MalformedURLException (java.net.MalformedURLException)9 ComputeImage (com.emc.storageos.db.client.model.ComputeImage)8 Produces (javax.ws.rs.Produces)6 SSHSession (com.emc.storageos.networkcontroller.SSHSession)5 ArrayList (java.util.ArrayList)5 ComputeImageJob (com.emc.storageos.db.client.model.ComputeImageJob)4 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)4 TaskCompleter (com.emc.storageos.volumecontroller.TaskCompleter)4 Workflow (com.emc.storageos.workflow.Workflow)4 Path (javax.ws.rs.Path)4 StringSet (com.emc.storageos.db.client.model.StringSet)3 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)3 Consumes (javax.ws.rs.Consumes)3 GET (javax.ws.rs.GET)3