Search in sources :

Example 36 with InterProcessLock

use of org.apache.curator.framework.recipes.locks.InterProcessLock 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 37 with InterProcessLock

use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.

the class StorageDriverService method uninstall.

@DELETE
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
@Path("/{driverName}")
public Response uninstall(@PathParam("driverName") String driverName) {
    log.info("Start to uninstall driver {} ...", driverName);
    Set<String> driverNames = getAllDriverNames();
    if (!driverNames.contains(driverName)) {
        throw APIException.badRequests.driverNameNotFound(driverName);
    }
    precheckForEnv();
    List<StorageSystemType> toUninstallTypes = filterTypesByDriver(driverName);
    precheckForDriverStatus(toUninstallTypes, driverName);
    InterProcessLock lock = getStorageDriverOperationLock();
    try {
        StorageDriversInfo info = coordinator.getTargetInfo(StorageDriversInfo.class);
        if (info == null) {
            info = new StorageDriversInfo();
        }
        for (StorageSystemType type : toUninstallTypes) {
            type.setDriverStatus(StorageSystemType.STATUS.UNISNTALLING.toString());
            dbClient.updateObject(type);
            info.getInstalledDrivers().remove(type.getDriverFileName());
        }
        // update target list in ZK
        coordinator.setTargetInfo(info);
        log.info("Successfully triggered uninstall operation for driver {}", driverName);
        auditOperation(OperationTypeEnum.UNINSTALL_STORAGE_DRIVER, AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_BEGIN, driverName);
        return Response.ok().build();
    } catch (Exception e) {
        log.error("Error happened when installing driver file", e);
        auditOperation(OperationTypeEnum.UNINSTALL_STORAGE_DRIVER, AuditLogManager.AUDITLOG_FAILURE, null, driverName);
        throw APIException.internalServerErrors.uninstallDriverFailed(e.getMessage());
    } finally {
        try {
            lock.release();
        } catch (Exception ignore) {
            log.error(String.format("Lock release failed when uninstalling driver %s", driverName));
        }
    }
}
Also used : InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) StorageSystemType(com.emc.storageos.db.client.model.StorageSystemType) StorageDriversInfo(com.emc.storageos.coordinator.client.model.StorageDriversInfo) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 38 with InterProcessLock

use of org.apache.curator.framework.recipes.locks.InterProcessLock 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 39 with InterProcessLock

use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.

the class DrUpgradeVoter method isOKForUpgrade.

@Override
public void isOKForUpgrade(String currentVersion, String targetVersion) {
    List<Site> standbySites = drUtil.listStandbySites();
    if (standbySites.isEmpty()) {
        log.info("Not a DR configuration, skipping all DR pre-checks");
        return;
    }
    InterProcessLock lock = null;
    try {
        lock = drUtil.getDROperationLock();
    } finally {
        if (lock != null) {
            try {
                lock.release();
            } catch (Exception e) {
                log.error("Failed to release the DR lock", e);
            }
        }
    }
    List<Site> pausedSites = drUtil.listSitesInState(SiteState.STANDBY_PAUSED);
    if (pausedSites.isEmpty()) {
        log.error("There's no paused standby site for DR Upgrade");
        throw APIException.internalServerErrors.upgradeNotAllowedWithoutPausedSite();
    }
}
Also used : Site(com.emc.storageos.coordinator.client.model.Site) InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException)

Example 40 with InterProcessLock

use of org.apache.curator.framework.recipes.locks.InterProcessLock in project coprhd-controller by CoprHD.

the class SecretsInit method rotateIPsecKey.

private boolean rotateIPsecKey() {
    InterProcessLock lock = null;
    try {
        if (drUtil.isMultivdc()) {
            log.info("Skip ipsec key initial rotation for multi-vdc configuration");
            return true;
        }
        if (drUtil.isMultisite()) {
            log.info("Skip ipsec key initial rotation for multi-site DR configuration");
            return true;
        }
        String preSharedKey = ipsecConfig.getPreSharedKeyFromZK();
        if (!StringUtils.isBlank(preSharedKey)) {
            log.info("IPsec key has been initialized");
            return true;
        }
        lock = coordinator.getCoordinatorClient().getSiteLocalLock(ipsecLock);
        lock.acquire();
        log.info("Acquired the lock {}", ipsecLock);
        preSharedKey = ipsecConfig.getPreSharedKeyFromZK();
        if (!StringUtils.isBlank(preSharedKey)) {
            log.info("IPsec key has been initialized. No need to regenerate it");
            return true;
        }
        if (drUtil.isAllSitesStable()) {
            log.info("No pre shared key in zk, generate a new key");
            ipsecMgr.rotateKey(true);
            return true;
        }
        return false;
    } catch (ServiceUnavailableException suex) {
        log.warn("cluster is not stable currently.");
        return false;
    } catch (Exception ex) {
        log.warn("error when run ipsec initial rotation: ", ex);
        return false;
    } finally {
        try {
            if (lock != null) {
                lock.release();
                log.info("Released the lock {}", ipsecLock);
            }
        } catch (Exception ex) {
            log.warn("error in releasing the lock {}", ipsecLock);
        }
    }
}
Also used : InterProcessLock(org.apache.curator.framework.recipes.locks.InterProcessLock) ServiceUnavailableException(com.emc.storageos.svcs.errorhandling.resources.ServiceUnavailableException) ServiceUnavailableException(com.emc.storageos.svcs.errorhandling.resources.ServiceUnavailableException)

Aggregations

InterProcessLock (org.apache.curator.framework.recipes.locks.InterProcessLock)98 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)25 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)21 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)15 IOException (java.io.IOException)15 ControllerException (com.emc.storageos.volumecontroller.ControllerException)14 Configuration (com.emc.storageos.coordinator.common.Configuration)12 CoordinatorException (com.emc.storageos.coordinator.exceptions.CoordinatorException)12 UnknownHostException (java.net.UnknownHostException)12 Site (com.emc.storageos.coordinator.client.model.Site)11 RetryableCoordinatorException (com.emc.storageos.coordinator.exceptions.RetryableCoordinatorException)11 NetworkDeviceControllerException (com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException)10 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)9 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)9 BiosCommandResult (com.emc.storageos.volumecontroller.impl.BiosCommandResult)9 ArrayList (java.util.ArrayList)9 POST (javax.ws.rs.POST)9 NetworkSystem (com.emc.storageos.db.client.model.NetworkSystem)8 Path (javax.ws.rs.Path)8 ConfigurationImpl (com.emc.storageos.coordinator.common.impl.ConfigurationImpl)6