Search in sources :

Example 16 with StorageSystemType

use of com.emc.storageos.db.client.model.StorageSystemType 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)

Example 17 with StorageSystemType

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

the class StorageDriverManager method updateUninstallMetadata.

private boolean updateUninstallMetadata(List<StorageDriversInfo> infos) {
    List<StorageSystemType> uninstallingTypes = queryDriversByStatus(StorageSystemType.STATUS.UNISNTALLING);
    List<StorageSystemType> finishedTypes = new ArrayList<StorageSystemType>();
    boolean needRestart = false;
    log.info("Uninstalling storage system types: {}", concatStorageSystemTypeNames(uninstallingTypes));
    for (StorageSystemType type : uninstallingTypes) {
        boolean finished = true;
        for (StorageDriversInfo info : infos) {
            if (info.getInstalledDrivers().contains(type.getDriverFileName())) {
                finished = false;
                break;
            }
        }
        if (finished) {
            dbClient.removeObject(type);
            finishedTypes.add(type);
            log.info("Remove {}", type.getStorageTypeName());
            needRestart = true;
        }
    }
    for (String driver : extractDrivers(finishedTypes)) {
        auditCompleteOperation(OperationTypeEnum.UNINSTALL_STORAGE_DRIVER, AuditLogManager.AUDITLOG_SUCCESS, driver);
    }
    return needRestart;
}
Also used : ArrayList(java.util.ArrayList) StorageSystemType(com.emc.storageos.db.client.model.StorageSystemType) StorageDriversInfo(com.emc.storageos.coordinator.client.model.StorageDriversInfo)

Example 18 with StorageSystemType

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

the class StorageDriverManager method concatStorageSystemTypeNames.

private String concatStorageSystemTypeNames(List<StorageSystemType> types) {
    if (types == null || types.isEmpty()) {
        return "[]";
    }
    StringBuilder builder = new StringBuilder();
    builder.append('[');
    for (StorageSystemType type : types) {
        builder.append(type.getStorageTypeName()).append(',');
    }
    builder.setCharAt(builder.length() - 1, ']');
    return builder.toString();
}
Also used : StorageSystemType(com.emc.storageos.db.client.model.StorageSystemType)

Example 19 with StorageSystemType

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

the class StorageDriverManager method updateUpgradeMetadata.

private boolean updateUpgradeMetadata(List<StorageDriversInfo> infos) {
    List<StorageSystemType> upgradingTypes = queryDriversByStatus(StorageSystemType.STATUS.UPGRADING);
    List<StorageSystemType> finishedTypes = new ArrayList<StorageSystemType>();
    boolean needRestart = false;
    Map<String, StorageDriverMetaData> toInsertNewMetaDatas = new HashMap<String, StorageDriverMetaData>();
    log.info("Upgrading storage system types: {}", concatStorageSystemTypeNames(upgradingTypes));
    for (StorageSystemType type : upgradingTypes) {
        String driverName = type.getDriverName();
        String driverFileName = type.getDriverFileName();
        if (upgradingDriverMap.containsKey(driverName)) {
            StorageDriverMetaData metaData = upgradingDriverMap.get(driverName);
            // last one removes old meta data
            boolean finished = true;
            for (StorageDriversInfo info : infos) {
                if (info.getInstalledDrivers().contains(driverFileName)) {
                    finished = false;
                    break;
                }
            }
            if (finished) {
                toInsertNewMetaDatas.put(metaData.getDriverName(), metaData);
                log.info("DriverUpgradephase1: remove {} ", type.getStorageTypeName());
                dbClient.removeObject(type);
            }
        } else {
            // last one marks active
            boolean finished = true;
            for (StorageDriversInfo info : infos) {
                if (!info.getInstalledDrivers().contains(type.getDriverFileName())) {
                    finished = false;
                    break;
                }
            }
            if (finished) {
                type.setDriverStatus(StorageSystemType.STATUS.ACTIVE.toString());
                dbClient.updateObject(type);
                finishedTypes.add(type);
                log.info("DriverUpgradephase2: mark active for {}", type.getStorageTypeName());
                needRestart = true;
            }
        }
    }
    insertMetadata(toInsertNewMetaDatas);
    for (String driver : extractDrivers(finishedTypes)) {
        auditCompleteOperation(OperationTypeEnum.UPGRADE_STORAGE_DRIVER, AuditLogManager.AUDITLOG_SUCCESS, driver);
    }
    return needRestart;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StorageDriverMetaData(com.emc.storageos.coordinator.client.model.StorageDriverMetaData) StorageSystemType(com.emc.storageos.db.client.model.StorageSystemType) StorageDriversInfo(com.emc.storageos.coordinator.client.model.StorageDriversInfo)

Example 20 with StorageSystemType

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

the class StorageDriverServiceTest method setUp.

@Before
public void setUp() throws Exception {
    // mock dependent members of StorageDriverService instance and wire into
    // them
    dbClient = mock(DbClientImpl.class);
    doNothing().when(dbClient).createObject(any(StorageSystemType.class));
    doNothing().when(dbClient).updateObject(any(StorageSystemType.class));
    coordinator = mock(CoordinatorClientImpl.class);
    coordinatorExt = mock(CoordinatorClientExt.class);
    doReturn(coordinator).when(coordinatorExt).getCoordinatorClient();
    doNothing().when(coordinator).persistServiceConfiguration(any(Configuration.class));
    service = spy(new StorageDriverService());
    service.setDbClient(dbClient);
    service.setCoordinatorExt(coordinatorExt);
    // mock 3 storage system types in db
    type1 = new StorageSystemType();
    type1.setStorageTypeDispName("systemtype1");
    type1.setStorageTypeName("systemtype1");
    type1.setIsNative(false);
    type1.setDriverStatus(StorageSystemType.STATUS.ACTIVE.toString());
    type1.setDriverName("driver1");
    type1.setDriverFileName("driverFileName1");
    type1.setDriverVersion("1.2.3.4");
    type2 = new StorageSystemType();
    type2.setStorageTypeDispName("providertype1");
    type2.setStorageTypeName("providertype1");
    type2.setIsNative(false);
    type2.setDriverStatus(StorageSystemType.STATUS.ACTIVE.toString());
    type2.setDriverName("driver1");
    type2.setDriverFileName("driverFileName1");
    type2.setDriverVersion("1.2.3.4");
    type3 = new StorageSystemType();
    type3.setStorageTypeDispName("systemtype2");
    type3.setStorageTypeName("systemtype2");
    type3.setIsNative(false);
    type3.setDriverStatus(StorageSystemType.STATUS.ACTIVE.toString());
    type3.setDriverName("driver2");
    List<StorageSystemType> types = new ArrayList<StorageSystemType>();
    types.add(type1);
    types.add(type2);
    types.add(type3);
    doReturn(types.iterator()).when(dbClient).queryIterativeObjects(eq(StorageSystemType.class), anyCollectionOf(URI.class));
    // mock that systemtype1 is in use
    Set<String> inUseTypes = new HashSet<String>();
    inUseTypes.add("systemtype1");
    doReturn(inUseTypes).when(service).getUsedStorageProviderTypes();
    // mock that no systemtype is used
    doReturn(new HashSet<String>()).when(service).getUsedStorageSystemTypes();
    // bypass pre-check for environment
    doNothing().when(service).precheckForEnv();
    // mock lock acquire and release
    InterProcessLock lock = mock(InterProcessLock.class);
    doNothing().when(lock).release();
    doReturn(lock).when(service).getStorageDriverOperationLock();
    // mock target list of installed drivers
    StorageDriversInfo drivers = new StorageDriversInfo();
    Set<String> installedDrivers = new HashSet<String>();
    installedDrivers.add("driverFileName1");
    installedDrivers.add("driverFileName2");
    drivers.setInstalledDrivers(installedDrivers);
    doReturn(drivers).when(coordinator).getTargetInfo(anyObject());
    // mock audit operation
    doNothing().when(service).auditOperation(any(OperationTypeEnum.class), anyString(), anyString(), anyObject());
    // mock file moving from tmp dir to data dir
    doNothing().when(service).moveDriverToDataDir(any(File.class));
    // mock updating target innfo
    doNothing().when(coordinator).setTargetInfo(anyObject());
    // mock progess updating
    doNothing().when(coordinatorExt).setNodeSessionScopeInfo(anyObject());
    // mock moving driver file to tmp dir
    doReturn(null).when(service).saveToTmpDir(anyString(), anyObject());
}
Also used : Configuration(com.emc.storageos.coordinator.common.Configuration) OperationTypeEnum(com.emc.storageos.services.OperationTypeEnum) ArrayList(java.util.ArrayList) StorageSystemType(com.emc.storageos.db.client.model.StorageSystemType) StorageDriversInfo(com.emc.storageos.coordinator.client.model.StorageDriversInfo) URI(java.net.URI) CoordinatorClientImpl(com.emc.storageos.coordinator.client.service.impl.CoordinatorClientImpl) DbClientImpl(com.emc.storageos.db.client.impl.DbClientImpl) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) CoordinatorClientExt(com.emc.storageos.systemservices.impl.upgrade.CoordinatorClientExt) File(java.io.File) HashSet(java.util.HashSet) Before(org.junit.Before)

Aggregations

StorageSystemType (com.emc.storageos.db.client.model.StorageSystemType)29 URI (java.net.URI)10 ArrayList (java.util.ArrayList)10 StorageDriversInfo (com.emc.storageos.coordinator.client.model.StorageDriversInfo)8 HashMap (java.util.HashMap)5 InterProcessLock (org.apache.curator.framework.recipes.locks.InterProcessLock)5 StorageDriverMetaData (com.emc.storageos.coordinator.client.model.StorageDriverMetaData)4 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)4 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)4 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 Path (javax.ws.rs.Path)4 File (java.io.File)3 HashSet (java.util.HashSet)3 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)2 AbstractStorageDriver (com.emc.storageos.storagedriver.AbstractStorageDriver)2 ZipFile (java.util.zip.ZipFile)2 Consumes (javax.ws.rs.Consumes)2 GET (javax.ws.rs.GET)2 POST (javax.ws.rs.POST)2