Search in sources :

Example 11 with ComputeImageServer

use of com.emc.storageos.db.client.model.ComputeImageServer in project coprhd-controller by CoprHD.

the class ComputeImageServerMigrationTest method verifyResults.

@Override
protected void verifyResults() throws Exception {
    List<URI> imageServerURIs = _dbClient.queryByType(ComputeImageServer.class, true);
    Iterator<ComputeImageServer> iterator = _dbClient.queryIterativeObjects(ComputeImageServer.class, imageServerURIs);
    if (iterator.hasNext()) {
        ComputeImageServer imageServer = iterator.next();
        Assert.assertEquals(imageServer.getImageServerIp(), "10.247.84.185");
    } else {
        Assert.fail("compute image server not found in cassandra db");
    }
}
Also used : ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) URI(java.net.URI)

Example 12 with ComputeImageServer

use of com.emc.storageos.db.client.model.ComputeImageServer in project coprhd-controller by CoprHD.

the class ComputeImageServerMigration method process.

@Override
public void process() throws MigrationCallbackException {
    try {
        // Retrieve data from zk db using coordinator client
        Configuration config1 = coordinatorClient.queryConfiguration(PropertyInfoExt.TARGET_PROPERTY, PropertyInfoExt.TARGET_PROPERTY_ID);
        log.info("imageServerIP:" + config1.getConfig(IMAGE_SERVER_ADDRESS));
        PropertyInfo p = coordinatorClient.getPropertyInfo();
        EncryptionProviderImpl encryptionProvider1 = new EncryptionProviderImpl();
        encryptionProvider1.setCoordinator(coordinatorClient);
        encryptionProvider1.start();
        this.encryptionProvider = encryptionProvider1;
        if (!StringUtils.isBlank(p.getProperty("image_server_address"))) {
            ComputeImageServer imageServer = new ComputeImageServer();
            imageServer.setId(URIUtil.createId(ComputeImageServer.class));
            imageServer.setImageServerIp(p.getProperty(IMAGE_SERVER_ADDRESS));
            imageServer.setLabel(p.getProperty(IMAGE_SERVER_ADDRESS));
            imageServer.setImageServerUser(p.getProperty(IMAGE_SERVER_USERNAME));
            imageServer.setTftpBootDir(p.getProperty(IMAGE_SERVER_TFTPBOOT_DIR));
            imageServer.setImageServerSecondIp(p.getProperty(IMAGE_SERVER_OS_NETWORK_IP));
            imageServer.setImageServerHttpPort(p.getProperty(IMAGE_SERVER_HTTP_PORT));
            imageServer.setImageDir(p.getProperty(IMAGE_SERVER_IMAGEDIR));
            String encryptedPassword = p.getProperty(IMAGE_SERVER_ENC_PWD);
            try {
                imageServer.setImageServerPassword(encryptionProvider.decrypt(Base64.decodeBase64(encryptedPassword)));
            } catch (Exception e) {
                log.error("Can't decrypt image server password :" + e.getLocalizedMessage());
                log.error("Failed to save image server details into database during migration", e);
                throw e;
            }
            associateComputeImages(imageServer);
            dbClient.createObject(imageServer);
            log.info("Saved imageServer info into cassandra db");
            // Associate all existing Compute Systems to this image server
            List<URI> computeSystemURIs = dbClient.queryByType(ComputeSystem.class, true);
            Iterator<ComputeSystem> computeSystemListIterator = dbClient.queryIterativeObjects(ComputeSystem.class, computeSystemURIs);
            while (computeSystemListIterator.hasNext()) {
                ComputeSystem computeSystem = computeSystemListIterator.next();
                computeSystem.setComputeImageServer(imageServer.getId());
                dbClient.persistObject(computeSystem);
            }
            // Delete imageserverConf data from ZK db.
            Configuration config = coordinatorClient.queryConfiguration(PropertyInfoExt.TARGET_PROPERTY, PropertyInfoExt.TARGET_PROPERTY_ID);
            config.removeConfig(IMAGE_SERVER_ADDRESS);
            config.removeConfig(IMAGE_SERVER_USERNAME);
            config.removeConfig(IMAGE_SERVER_ENC_PWD);
            config.removeConfig(IMAGE_SERVER_TFTPBOOT_DIR);
            config.removeConfig(IMAGE_SERVER_HTTP_PORT);
            config.removeConfig(IMAGE_SERVER_OS_NETWORK_IP);
            config.removeConfig(IMAGE_SERVER_IMAGEDIR);
            coordinatorClient.persistServiceConfiguration(config);
        } else {
            log.info("No image server configuration found in Zookeeper db");
        }
    } catch (Exception e) {
        log.error("Exception occured while migrating compute image server information");
        log.error(e.getMessage(), e);
    }
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration) ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) PropertyInfo(com.emc.storageos.model.property.PropertyInfo) EncryptionProviderImpl(com.emc.storageos.db.client.impl.EncryptionProviderImpl) URI(java.net.URI) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException) ComputeSystem(com.emc.storageos.db.client.model.ComputeSystem)

Example 13 with ComputeImageServer

use of com.emc.storageos.db.client.model.ComputeImageServer in project coprhd-controller by CoprHD.

the class UcsDiscoveryWorker method associateComputeImageServer.

/**
 * This method ensures that if the computeSystem does not have an imageServer
 * associated then it assigns an imageServer (if there is only one valid/available imageServer,
 * if there are more than one imageServer then the user has to manually associate the imageServer)
 * @param cs
 */
private void associateComputeImageServer(ComputeSystem cs) {
    if (NullColumnValueGetter.isNullURI(cs.getComputeImageServer())) {
        List<URI> imageServerURIList = _dbClient.queryByType(ComputeImageServer.class, true);
        ArrayList<URI> tempList = Lists.newArrayList(imageServerURIList.iterator());
        if (tempList.size() == 1) {
            Iterator<ComputeImageServer> imageServerItr = _dbClient.queryIterativeObjects(ComputeImageServer.class, tempList);
            while (imageServerItr.hasNext()) {
                ComputeImageServer imageSvr = imageServerItr.next();
                if (imageSvr != null && imageSvr.getComputeImageServerStatus().equals(ComputeImageServerStatus.AVAILABLE.toString())) {
                    _log.info("Automatically associating compute System {} with available image Server {}.", cs.getLabel(), imageSvr.getLabel());
                    cs.setComputeImageServer(imageSvr.getId());
                }
            }
        }
    }
}
Also used : ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) URI(java.net.URI)

Example 14 with ComputeImageServer

use of com.emc.storageos.db.client.model.ComputeImageServer in project coprhd-controller by CoprHD.

the class ComputeImageCompleter method complete.

@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
    log.info("ComputeImageCompleter.complete {}", status.name());
    ComputeImage ci = dbClient.queryObject(ComputeImage.class, getId());
    AuditLogManager auditMgr = AuditLogManagerFactory.getAuditLogManager();
    if (status == Status.error) {
        if (opType == OperationTypeEnum.CREATE_COMPUTE_IMAGE) {
            boolean available = false;
            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(ci.getId().toString())) {
                    available = true;
                    break;
                }
            }
            if (available) {
                ci.setComputeImageStatus(ComputeImageStatus.AVAILABLE.name());
            } else {
                ci.setComputeImageStatus(ComputeImageStatus.NOT_AVAILABLE.name());
            }
            ci.setLastImportStatusMessage(coded.getMessage());
            dbClient.persistObject(ci);
        }
        dbClient.error(ComputeImage.class, getId(), getOpId(), coded);
        auditMgr.recordAuditLog(null, null, serviceType, opType, System.currentTimeMillis(), AuditLogManager.AUDITLOG_FAILURE, AuditLogManager.AUDITOP_END, ci.getId().toString(), ci.getImageUrl(), ci.getComputeImageStatus());
    } else {
        if (opType == OperationTypeEnum.DELETE_COMPUTE_IMAGE) {
            dbClient.markForDeletion(ci);
        } else if (opType == OperationTypeEnum.CREATE_COMPUTE_IMAGE) {
            ci.setComputeImageStatus(ComputeImageStatus.AVAILABLE.name());
            ci.setLastImportStatusMessage("Success");
            dbClient.persistObject(ci);
        }
        dbClient.ready(ComputeImage.class, getId(), getOpId());
        auditMgr.recordAuditLog(null, null, serviceType, opType, System.currentTimeMillis(), AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_END, ci.getId().toString(), ci.getImageUrl(), ci.getComputeImageStatus());
    }
}
Also used : ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) AuditLogManager(com.emc.storageos.security.audit.AuditLogManager) URI(java.net.URI) ComputeImage(com.emc.storageos.db.client.model.ComputeImage)

Example 15 with ComputeImageServer

use of com.emc.storageos.db.client.model.ComputeImageServer in project coprhd-controller by CoprHD.

the class ComputeImageServerCompleter method complete.

/**
 * Method to be invoked on job execution completion
 * @param dbClient {@link DBClient} instance
 * @param Status {@link Status} of job
 * @param coded {@link ServiceCoded} instance
 */
@Override
protected void complete(DbClient dbClient, Status status, ServiceCoded coded) throws DeviceControllerException {
    log.info("ComputeImageServerCompleter.complete {}", status.name());
    ComputeImageServer imageServer = dbClient.queryObject(ComputeImageServer.class, getId());
    AuditLogManager auditMgr = AuditLogManagerFactory.getAuditLogManager();
    if (status == Status.error) {
        dbClient.error(ComputeImageServer.class, getId(), getOpId(), coded);
        auditMgr.recordAuditLog(null, null, serviceType, opType, System.currentTimeMillis(), AuditLogManager.AUDITLOG_FAILURE, AuditLogManager.AUDITOP_END, imageServer.getId().toString(), imageServer.getComputeImageServerStatus());
    } else {
        if (opType == OperationTypeEnum.DELETE_COMPUTE_IMAGESERVER) {
            dbClient.markForDeletion(imageServer);
        } else if (opType == OperationTypeEnum.IMAGESERVER_VERIFY_IMPORT_IMAGES) {
            imageServer.setComputeImageServerStatus(ComputeImageServerStatus.AVAILABLE.name());
            dbClient.persistObject(imageServer);
        }
        dbClient.ready(ComputeImageServer.class, getId(), getOpId());
        auditMgr.recordAuditLog(null, null, serviceType, opType, System.currentTimeMillis(), AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_END, imageServer.getId().toString(), imageServer.getComputeImageServerStatus());
    }
}
Also used : ComputeImageServer(com.emc.storageos.db.client.model.ComputeImageServer) AuditLogManager(com.emc.storageos.security.audit.AuditLogManager)

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