Search in sources :

Example 1 with StorageDriverMetaData

use of com.emc.storageos.coordinator.client.model.StorageDriverMetaData in project coprhd-controller by CoprHD.

the class StorageDriverService method upgrade.

@POST
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path("/{driverName}")
public Response upgrade(@PathParam("driverName") String driverName, @FormDataParam("driver") InputStream uploadedInputStream, @FormDataParam("driver") FormDataContentDisposition details, @FormDataParam("force") @DefaultValue("false") Boolean force) {
    log.info("Start to upgrade driver for {} ...", driverName);
    String fileName = details.getFileName();
    precheckForDriverFileName(fileName);
    long fileSize = details.getSize();
    log.info("Received driver jar file: {}, size: {}", fileName, fileSize);
    if (fileSize >= MAX_DRIVER_SIZE) {
        throw APIException.badRequests.fileSizeExceedsLimit(MAX_DRIVER_SIZE);
    }
    precheckForEnv();
    File driverFile = saveToTmpDir(fileName, uploadedInputStream);
    StorageDriverMetaData metaData = parseDriverMetaData(driverFile);
    if (!StringUtils.equals(driverName, metaData.getDriverName())) {
        throw APIException.internalServerErrors.upgradeDriverPrecheckFailed(String.format("Driver name specified in jar file is not %s", driverName));
    }
    precheckForMetaData(metaData, true, force);
    InterProcessLock lock = getStorageDriverOperationLock();
    try {
        moveDriverToDataDir(driverFile);
        // save new meta data to ZK
        coordinator.persistServiceConfiguration(metaData.toConfiguration());
        // update status to UPGRADING in db
        StorageDriversInfo targetInfo = coordinator.getTargetInfo(StorageDriversInfo.class);
        if (targetInfo == null) {
            targetInfo = new StorageDriversInfo();
        }
        List<StorageSystemType> types = filterTypesByDriver(driverName);
        for (StorageSystemType type : types) {
            type.setDriverStatus(StorageSystemType.STATUS.UPGRADING.toString());
            dbClient.updateObject(type);
            // remove old driver file name from target list
            targetInfo.getInstalledDrivers().remove(type.getDriverFileName());
        }
        coordinator.setTargetInfo(targetInfo);
        log.info("Successfully triggered upgrade operation for driver", metaData.getDriverName());
        auditOperation(OperationTypeEnum.UPGRADE_STORAGE_DRIVER, AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_BEGIN, driverName);
        return Response.ok().build();
    } catch (Exception e) {
        log.error("Error happened when upgrading driver file", e);
        auditOperation(OperationTypeEnum.UPGRADE_STORAGE_DRIVER, AuditLogManager.AUDITLOG_FAILURE, null, driverName);
        throw APIException.internalServerErrors.upgradeDriverFailed(e.getMessage());
    } finally {
        try {
            lock.release();
        } catch (Exception ignore) {
            log.error(String.format("Lock release failed when upgrading driver %s", metaData.getDriverName()));
        }
    }
}
Also used : StorageDriverMetaData(com.emc.storageos.coordinator.client.model.StorageDriverMetaData) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) StorageDriversInfo(com.emc.storageos.coordinator.client.model.StorageDriversInfo) StorageSystemType(com.emc.storageos.db.client.model.StorageSystemType) ZipFile(java.util.zip.ZipFile) File(java.io.File) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 2 with StorageDriverMetaData

use of com.emc.storageos.coordinator.client.model.StorageDriverMetaData in project coprhd-controller by CoprHD.

the class StorageDriverService method parseDriverMetaData.

protected StorageDriverMetaData parseDriverMetaData(File driverFile) {
    String driverFilePath = driverFile.getAbsolutePath();
    Properties props = extractPropsFromFile(driverFilePath);
    StorageDriverMetaData metaData = new StorageDriverMetaData();
    // check driver name
    String driverName = props.getProperty(DRIVER_NAME);
    precheckForDriverName(driverName);
    metaData.setDriverName(driverName);
    // check driver version and format
    String driverVersion = props.getProperty(DRIVER_VERSION);
    precheckForDriverVersion(driverVersion);
    metaData.setDriverVersion(driverVersion);
    // check storage name
    String storageName = props.getProperty(STORAGE_NAME);
    precheckForNotEmptyField("storage_name", storageName);
    metaData.setStorageName(storageName);
    // check storage display name
    String storageDisplayName = props.getProperty(STORAGE_DISPLAY_NAME);
    precheckForNotEmptyField("storage_display_name", storageDisplayName);
    metaData.setStorageDisplayName(storageDisplayName);
    // check provider name and provider display name
    String providerName = props.getProperty(PROVIDER_NAME);
    String providerDisplayName = props.getProperty(PROVIDER_DISPLAY_NAME);
    precheckForProviderName(providerName, providerDisplayName, metaData);
    // check meta type
    String metaType = props.getProperty(STORAGE_META_TYPE);
    precheckForMetaType(metaType);
    metaData.setMetaType(metaType.toUpperCase());
    // check enable_ssl
    String enableSslStr = props.getProperty(ENABLE_SSL);
    if (StringUtils.isNotEmpty(enableSslStr)) {
        boolean enableSsl = Boolean.valueOf(enableSslStr);
        metaData.setEnableSsl(enableSsl);
    } else {
        // default to false
        metaData.setEnableSsl(false);
    }
    // check ssl port
    try {
        String sslPortStr = props.getProperty(SSL_PORT);
        if (StringUtils.isNotEmpty(sslPortStr)) {
            long sslPort = 0L;
            sslPort = Long.valueOf(sslPortStr);
            metaData.setSslPort(sslPort);
        }
    } catch (NumberFormatException e) {
        throw APIException.internalServerErrors.installDriverPrecheckFailed("SSL port format is not valid");
    }
    // check non ssl port
    try {
        String nonSslPortStr = props.getProperty(NON_SSL_PORT);
        if (StringUtils.isNotEmpty(nonSslPortStr)) {
            long nonSslPort = 0L;
            nonSslPort = Long.valueOf(nonSslPortStr);
            metaData.setNonSslPort(nonSslPort);
        }
    } catch (NumberFormatException e) {
        throw APIException.internalServerErrors.installDriverPrecheckFailed("SSL port format is not valid");
    }
    // check driver class name
    String driverClassName = props.getProperty(DRIVER_CLASS_NAME);
    precheckForNotEmptyField("driver_class_name", driverClassName);
    metaData.setDriverClassName(driverClassName);
    // check if support auto-tier policy
    String supportAutoTierStr = props.getProperty(SUPPORT_AUTO_TIER_POLICY);
    if (StringUtils.isNotEmpty(supportAutoTierStr)) {
        boolean supportAutoTierPolicy = Boolean.valueOf(supportAutoTierStr);
        metaData.setSupportAutoTierPolicy(supportAutoTierPolicy);
    } else {
        // default to false
        metaData.setSupportAutoTierPolicy(false);
    }
    metaData.setDriverFileName(driverFile.getName());
    log.info("Parsed result from jar file: {}", metaData.toString());
    return metaData;
}
Also used : StorageDriverMetaData(com.emc.storageos.coordinator.client.model.StorageDriverMetaData) Properties(java.util.Properties)

Example 3 with StorageDriverMetaData

use of com.emc.storageos.coordinator.client.model.StorageDriverMetaData in project coprhd-controller by CoprHD.

the class StorageDriverService method install.

@POST
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response install(@FormDataParam("driver") InputStream uploadedInputStream, @FormDataParam("driver") FormDataContentDisposition details) {
    String fileName = details.getFileName();
    precheckForDriverFileName(fileName);
    long fileSize = details.getSize();
    log.info("Received driver jar file: {}, size: {}", fileName, fileSize);
    if (fileSize >= MAX_DRIVER_SIZE) {
        throw APIException.badRequests.fileSizeExceedsLimit(MAX_DRIVER_SIZE);
    }
    precheckForEnv();
    File driverFile = saveToTmpDir(fileName, uploadedInputStream);
    StorageDriverMetaData metaData = parseDriverMetaData(driverFile);
    precheckForMetaData(metaData);
    InterProcessLock lock = getStorageDriverOperationLock();
    try {
        // move file from /tmp to /data/drivers
        moveDriverToDataDir(driverFile);
        // insert meta data int db
        List<StorageSystemType> types = StorageDriverMapper.map(metaData);
        for (StorageSystemType type : types) {
            type.setDriverStatus(StorageSystemType.STATUS.INSTALLING.toString());
            type.setIsNative(false);
            dbClient.createObject(type);
            log.info("Added storage system type {}, set status to INSTALLING", type.getStorageTypeName());
        }
        // update local list in ZK
        Set<String> localDrivers = localRepo.getLocalDrivers();
        StorageDriversInfo info = new StorageDriversInfo();
        info.setInstalledDrivers(localDrivers);
        coordinatorExt.setNodeSessionScopeInfo(info);
        log.info("Updated local driver list to syssvc service beacon: {}", Arrays.toString(localDrivers.toArray()));
        // update target list in ZK
        info = coordinator.getTargetInfo(StorageDriversInfo.class);
        if (info == null) {
            info = new StorageDriversInfo();
        }
        info.getInstalledDrivers().add(metaData.getDriverFileName());
        coordinator.setTargetInfo(info);
        log.info("Successfully triggered install operation for driver", metaData.getDriverName());
        auditOperation(OperationTypeEnum.INSTALL_STORAGE_DRIVER, AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_BEGIN, metaData.getDriverName());
        return Response.ok().build();
    } catch (Exception e) {
        log.error("Error happened when installing driver file", e);
        auditOperation(OperationTypeEnum.INSTALL_STORAGE_DRIVER, AuditLogManager.AUDITLOG_FAILURE, null, metaData.getDriverName());
        throw APIException.internalServerErrors.installDriverFailed(e.getMessage());
    } finally {
        try {
            lock.release();
        } catch (Exception ignore) {
            log.error(String.format("Lock release failed when installing driver %s", metaData.getDriverName()));
        }
    }
}
Also used : StorageDriverMetaData(com.emc.storageos.coordinator.client.model.StorageDriverMetaData) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) StorageSystemType(com.emc.storageos.db.client.model.StorageSystemType) StorageDriversInfo(com.emc.storageos.coordinator.client.model.StorageDriversInfo) ZipFile(java.util.zip.ZipFile) File(java.io.File) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 4 with StorageDriverMetaData

use of com.emc.storageos.coordinator.client.model.StorageDriverMetaData in project coprhd-controller by CoprHD.

the class StorageDriverServiceTest method createMetaData.

private StorageDriverMetaData createMetaData() {
    StorageDriverMetaData metaData = new StorageDriverMetaData();
    metaData = new StorageDriverMetaData();
    metaData.setDriverName("driverName");
    metaData.setDriverVersion("1.2.3.4");
    metaData.setStorageName("storage name");
    metaData.setStorageDisplayName("storage display name");
    metaData.setProviderName("provider name");
    metaData.setProviderDisplayName("provider display name");
    metaData.setMetaType("BLOCK");
    metaData.setEnableSsl(true);
    metaData.setSslPort(1234);
    metaData.setNonSslPort(4321);
    metaData.setDriverClassName("driverClassName");
    metaData.setDriverFileName("driverFileName");
    metaData.setSupportAutoTierPolicy(true);
    return metaData;
}
Also used : StorageDriverMetaData(com.emc.storageos.coordinator.client.model.StorageDriverMetaData)

Example 5 with StorageDriverMetaData

use of com.emc.storageos.coordinator.client.model.StorageDriverMetaData in project coprhd-controller by CoprHD.

the class StorageDriverManager method insertMetadata.

/**
 * During upgrade, the last node who finished uninstalling old driver takes responsibility
 * to fetch meta data of new driver from ZK (and delete) and store it into DB, and then add
 * new driver file name to target list, to trigger all nodes to download it.
 */
private void insertMetadata(Map<String, StorageDriverMetaData> toInsertNewMetaDatas) {
    if (toInsertNewMetaDatas.isEmpty()) {
        return;
    }
    StorageDriversInfo info = coordinatorClient.getTargetInfo(StorageDriversInfo.class);
    if (info == null) {
        info = new StorageDriversInfo();
    }
    for (StorageDriverMetaData metaData : toInsertNewMetaDatas.values()) {
        List<StorageSystemType> types = StorageDriverMapper.map(metaData);
        for (StorageSystemType type : types) {
            type.setIsNative(false);
            type.setDriverStatus(StorageSystemType.STATUS.UPGRADING.toString());
        }
        log.info("DriverUpgradePhase1: Delete metadata from zk and insert it into db: {}", metaData.toString());
        dbClient.createObject(types);
        coordinatorClient.removeServiceConfiguration(metaData.toConfiguration());
        info.getInstalledDrivers().add(metaData.getDriverFileName());
    }
    // update target list, trigger new driver downloading
    log.info("DriverUpgradePhase1: trigger downloading for new driver files listed above");
    coordinatorClient.setTargetInfo(info);
}
Also used : StorageDriverMetaData(com.emc.storageos.coordinator.client.model.StorageDriverMetaData) StorageDriversInfo(com.emc.storageos.coordinator.client.model.StorageDriversInfo) StorageSystemType(com.emc.storageos.db.client.model.StorageSystemType)

Aggregations

StorageDriverMetaData (com.emc.storageos.coordinator.client.model.StorageDriverMetaData)8 StorageDriversInfo (com.emc.storageos.coordinator.client.model.StorageDriversInfo)4 StorageSystemType (com.emc.storageos.db.client.model.StorageSystemType)4 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)2 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 ZipFile (java.util.zip.ZipFile)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 InterProcessLock (org.apache.curator.framework.recipes.locks.InterProcessLock)2 Configuration (com.emc.storageos.coordinator.common.Configuration)1 FormDataContentDisposition (com.sun.jersey.core.header.FormDataContentDisposition)1 ArrayList (java.util.ArrayList)1 Properties (java.util.Properties)1 Path (javax.ws.rs.Path)1 Test (org.junit.Test)1