Search in sources :

Example 91 with VNXeApiClient

use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.

the class VNXUnityUnManagedObjectDiscoverer method discoverUnManagedFileSystems.

public void discoverUnManagedFileSystems(AccessProfile accessProfile, DbClient dbClient, CoordinatorClient coordinator, PartitionManager partitionManager) throws Exception {
    log.info("Started discovery of UnManagedFilesystems for system {}", accessProfile.getSystemId());
    StorageSystem storageSystem = dbClient.queryObject(StorageSystem.class, accessProfile.getSystemId());
    VNXeApiClient apiClient = getVnxUnityClient(accessProfile);
    unManagedFilesystemsInsert = new ArrayList<UnManagedFileSystem>();
    unManagedFilesystemsUpdate = new ArrayList<UnManagedFileSystem>();
    List<VNXeFileSystem> filesystems = apiClient.getAllFileSystems();
    if (filesystems != null && !filesystems.isEmpty()) {
        Map<String, StoragePool> pools = getStoragePoolMap(storageSystem, dbClient);
        for (VNXeFileSystem fs : filesystems) {
            StoragePort storagePort = getStoragePortPool(storageSystem, dbClient, apiClient, fs);
            String fsNativeGuid = NativeGUIDGenerator.generateNativeGuid(storageSystem.getSystemType(), storageSystem.getSerialNumber(), fs.getId());
            StoragePool pool = getStoragePoolOfUnManagedObject(fs.getPool().getId(), storageSystem, pools);
            if (null == pool) {
                log.error("Skipping unmanaged volume discovery as the file system {} storage pool doesn't exist in ViPR", fs.getId());
                continue;
            }
            if (checkStorageFileSystemExistsInDB(fsNativeGuid, dbClient)) {
                log.info("Skipping file system {} as it is already managed by ViPR", fsNativeGuid);
                continue;
            }
            // Create UnManaged FS
            String fsUnManagedFsNativeGuid = NativeGUIDGenerator.generateNativeGuidForPreExistingFileSystem(storageSystem.getSystemType(), storageSystem.getSerialNumber().toUpperCase(), fs.getId());
            UnManagedFileSystem unManagedFs = checkUnManagedFileSystemExistsInDB(dbClient, fsUnManagedFsNativeGuid);
            unManagedFs = createUnManagedFileSystem(unManagedFs, fsUnManagedFsNativeGuid, storageSystem, pool, storagePort, fs, dbClient);
            unManagedFilesystemsReturnedFromProvider.add(unManagedFs.getId());
        }
        if (!unManagedFilesystemsInsert.isEmpty()) {
            // Add UnManagedFileSystem
            partitionManager.insertInBatches(unManagedFilesystemsInsert, Constants.DEFAULT_PARTITION_SIZE, dbClient, UNMANAGED_FILESYSTEM);
        }
        if (!unManagedFilesystemsUpdate.isEmpty()) {
            // Update UnManagedFilesystem
            partitionManager.updateAndReIndexInBatches(unManagedFilesystemsUpdate, Constants.DEFAULT_PARTITION_SIZE, dbClient, UNMANAGED_FILESYSTEM);
        }
        // Process those active unmanaged fs objects available in database but not in newly discovered items, to
        // mark them inactive.
        performStorageUnManagedFSBookKeeping(storageSystem, dbClient, partitionManager);
    } else {
        log.info("There are no file systems found on the system: {}", storageSystem.getId());
    }
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) VNXeFileSystem(com.emc.storageos.vnxe.models.VNXeFileSystem) StoragePort(com.emc.storageos.db.client.model.StoragePort) UnManagedFileSystem(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileSystem) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 92 with VNXeApiClient

use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.

the class VNXUnityUnManagedObjectDiscoverer method discoverAllTreeQuotas.

public void discoverAllTreeQuotas(AccessProfile accessProfile, DbClient dbClient, PartitionManager partitionManager) {
    StorageSystem storageSystem = dbClient.queryObject(StorageSystem.class, accessProfile.getSystemId());
    VNXeApiClient apiClient = getVnxUnityClient(accessProfile);
    log.info("discoverAllTreeQuotas for storage system {} - start", storageSystem.getId());
    unManagedTreeQuotaInsert = new ArrayList<UnManagedFileQuotaDirectory>();
    unManagedTreeQuotaUpdate = new ArrayList<UnManagedFileQuotaDirectory>();
    List<VNXUnityTreeQuota> treeQuotas = apiClient.getAllTreeQuotas();
    for (VNXUnityTreeQuota quota : treeQuotas) {
        log.info("Discovered fS tree quota {}", quota.toString());
        VNXeFileSystem fs = null;
        if (quota.getFilesystem() != null) {
            fs = apiClient.getFileSystemByFSId(quota.getFilesystem().getId());
            String fsNativeGUID = NativeGUIDGenerator.generateNativeGuid(storageSystem.getSystemType(), storageSystem.getSerialNumber(), fs.getId());
            try {
                if (checkStorageFileSystemExistsInDB(fsNativeGUID, dbClient)) {
                    log.info("Skipping file system {} as it is already managed by ViPR", fsNativeGUID);
                    continue;
                }
                String nativeUnmanagedGUID = NativeGUIDGenerator.generateNativeGuidForPreExistingQuotaDirectory(storageSystem.getSystemType(), storageSystem.getSerialNumber(), quota.getId());
                VNXUnityQuotaConfig qc = apiClient.getQuotaConfigById(quota.getQuotaConfigId());
                UnManagedFileQuotaDirectory unManagedFileQuotaDirectory = getExistingUnManagedQuotaDirectory(dbClient, nativeUnmanagedGUID);
                boolean existingUnManagedQD = true;
                if (unManagedFileQuotaDirectory == null) {
                    unManagedFileQuotaDirectory = new UnManagedFileQuotaDirectory();
                    existingUnManagedQD = false;
                    unManagedFileQuotaDirectory.setId(URIUtil.createId(UnManagedFileQuotaDirectory.class));
                }
                unManagedFileQuotaDirectory.setLabel(quota.getPath().substring(1));
                unManagedFileQuotaDirectory.setNativeGuid(nativeUnmanagedGUID);
                unManagedFileQuotaDirectory.setParentFSNativeGuid(fsNativeGUID);
                unManagedFileQuotaDirectory.setSize(quota.getHardLimit());
                Long size = quota.getHardLimit() > 0 ? quota.getHardLimit() : fs.getSizeAllocated();
                Long softLimit = 0L;
                if (quota.getSoftLimit() > 0) {
                    softLimit = quota.getSoftLimit() * 100 / size;
                    int softGrace = qc.getGracePeriod() / (24 * 60 * 60);
                    unManagedFileQuotaDirectory.setSoftGrace(softGrace);
                }
                unManagedFileQuotaDirectory.setSoftLimit(softLimit.intValue());
                unManagedFileQuotaDirectory.setNotificationLimit(0);
                unManagedFileQuotaDirectory.setNativeId(quota.getId());
                if (!existingUnManagedQD) {
                    unManagedTreeQuotaInsert.add(unManagedFileQuotaDirectory);
                } else {
                    unManagedTreeQuotaUpdate.add(unManagedFileQuotaDirectory);
                }
            } catch (IOException e) {
                log.error("IOException occured in discoverAllTreeQuotas()", e);
            }
        }
    }
    if (!unManagedTreeQuotaInsert.isEmpty()) {
        // Add UnManagedFileSystem
        partitionManager.insertInBatches(unManagedTreeQuotaInsert, Constants.DEFAULT_PARTITION_SIZE, dbClient, UNMANAGED_FILEQUOTADIR);
        unManagedTreeQuotaInsert.clear();
    }
    if (!unManagedTreeQuotaUpdate.isEmpty()) {
        // Update UnManagedFilesystem
        partitionManager.updateInBatches(unManagedTreeQuotaUpdate, Constants.DEFAULT_PARTITION_SIZE, dbClient, UNMANAGED_FILEQUOTADIR);
        unManagedTreeQuotaUpdate.clear();
    }
}
Also used : VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) VNXeFileSystem(com.emc.storageos.vnxe.models.VNXeFileSystem) UnManagedFileQuotaDirectory(com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedFileQuotaDirectory) IOException(java.io.IOException) VNXUnityTreeQuota(com.emc.storageos.vnxe.models.VNXUnityTreeQuota) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) VNXUnityQuotaConfig(com.emc.storageos.vnxe.models.VNXUnityQuotaConfig)

Example 93 with VNXeApiClient

use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.

the class VNXUnitySnapshotOperations method restoreGroupSnapshots.

@Override
public void restoreGroupSnapshots(StorageSystem storage, URI volume, URI snapshot, TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        BlockSnapshot snapshotObj = _dbClient.queryObject(BlockSnapshot.class, snapshot);
        VNXeApiClient apiClient = getVnxeClient(storage);
        Snap groupSnap = apiClient.getSnapshot(snapshotObj.getReplicationGroupInstance());
        Snap snap = apiClient.getSnapshot(snapshotObj.getNativeId());
        // Error out if the snapshot is attached
        if (snap.isAttached()) {
            log.error("Snapshot {})is exported and cannot be used for restore", snapshotObj.getLabel());
            ServiceError error = DeviceControllerErrors.vnxe.cannotRestoreAttachedSnapshot(snapshotObj.getLabel());
            taskCompleter.error(_dbClient, error);
        }
        VNXeCommandJob job = apiClient.restoreSnap(groupSnap.getId());
        if (job != null) {
            ControllerServiceImpl.enqueueJob(new QueueJob(new VNXUnityRestoreSnapshotJob(job.getId(), storage.getId(), taskCompleter)));
        }
    } catch (Exception ex) {
        log.error("Restore group snapshot got the exception", ex);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("RestoreSnapshotJob", ex.getMessage());
        taskCompleter.error(_dbClient, error);
    }
}
Also used : VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) VNXUnityRestoreSnapshotJob(com.emc.storageos.volumecontroller.impl.vnxunity.job.VNXUnityRestoreSnapshotJob) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) Snap(com.emc.storageos.vnxe.models.Snap) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 94 with VNXeApiClient

use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.

the class VNXUnitySnapshotOperations method createSingleVolumeSnapshot.

@Override
public void createSingleVolumeSnapshot(StorageSystem storage, URI snapshot, Boolean createInactive, Boolean readOnly, TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        BlockSnapshot snapshotObj = _dbClient.queryObject(BlockSnapshot.class, snapshot);
        if (readOnly) {
            snapshotObj.setIsReadOnly(readOnly);
            _dbClient.updateObject(snapshotObj);
        }
        Volume volume = _dbClient.queryObject(Volume.class, snapshotObj.getParent());
        TenantOrg tenant = _dbClient.queryObject(TenantOrg.class, volume.getTenant().getURI());
        String tenantName = tenant.getLabel();
        String snapLabelToUse = _nameGenerator.generate(tenantName, snapshotObj.getLabel(), snapshot.toString(), '-', SmisConstants.MAX_SNAPSHOT_NAME_LENGTH);
        VNXeApiClient apiClient = getVnxeClient(storage);
        VNXeCommandJob job = apiClient.createSnap(volume.getNativeId(), snapLabelToUse, readOnly);
        if (job != null) {
            ControllerServiceImpl.enqueueJob(new QueueJob(new VNXeBlockSnapshotCreateJob(job.getId(), storage.getId(), !createInactive, taskCompleter)));
        }
    } catch (Exception ex) {
        log.error("Create volume snapshot got the exception", ex);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("CreateVolumeSnapshot", ex.getMessage());
        taskCompleter.error(_dbClient, error);
    }
}
Also used : VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) Volume(com.emc.storageos.db.client.model.Volume) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) TenantOrg(com.emc.storageos.db.client.model.TenantOrg) VNXeBlockSnapshotCreateJob(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeBlockSnapshotCreateJob) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Example 95 with VNXeApiClient

use of com.emc.storageos.vnxe.VNXeApiClient in project coprhd-controller by CoprHD.

the class VNXUnitySnapshotOperations method createGroupSnapshots.

@Override
public void createGroupSnapshots(StorageSystem storage, List<URI> snapshotList, Boolean createInactive, Boolean readOnly, TaskCompleter taskCompleter) throws DeviceControllerException {
    try {
        URI snapshot = snapshotList.get(0);
        BlockSnapshot snapshotObj = _dbClient.queryObject(BlockSnapshot.class, snapshot);
        Volume volume = _dbClient.queryObject(Volume.class, snapshotObj.getParent());
        boolean inApplication = false;
        if (volume.getApplication(_dbClient) != null) {
            inApplication = true;
        } else if (volume.checkInternalFlags(Flag.INTERNAL_OBJECT)) {
            // Check if it is VPLEX backend volume and if the vplex volume is in an application
            final List<Volume> vplexVolumes = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, Volume.class, getVolumesByAssociatedId(volume.getId().toString()));
            for (Volume vplexVolume : vplexVolumes) {
                if (vplexVolume.getApplication(_dbClient) != null) {
                    inApplication = true;
                    break;
                }
            }
        }
        String groupName = volume.getReplicationGroupInstance();
        String snapLabelToUse = null;
        if (NullColumnValueGetter.isNotNullValue(groupName)) {
            String snapsetLabel = snapshotObj.getSnapsetLabel();
            if (inApplication) {
                // When in application, it could have more than one CGs in the same application, when creating
                // snapshot on the application, the snapset label would be the same for all volumes in the application.
                // if we use the same name to create snapshot for multiple CGs, it would fail.
                snapLabelToUse = String.format("%s-%s", snapsetLabel, groupName);
            } else {
                snapLabelToUse = snapsetLabel;
            }
            VNXeApiClient apiClient = getVnxeClient(storage);
            String cgId = apiClient.getConsistencyGroupIdByName(groupName);
            VNXeCommandJob job = apiClient.createSnap(cgId, snapLabelToUse, readOnly);
            if (job != null) {
                ControllerServiceImpl.enqueueJob(new QueueJob(new VNXUnityCreateCGSnapshotJob(job.getId(), storage.getId(), readOnly, taskCompleter)));
            }
        } else {
            String errorMsg = "Unable to find consistency group id when creating snapshot";
            log.error(errorMsg);
            ServiceError error = DeviceControllerErrors.vnxe.jobFailed("CreateCGSnapshot", errorMsg);
            taskCompleter.error(_dbClient, error);
        }
    } catch (Exception ex) {
        log.error("Create volume snapshot got the exception", ex);
        ServiceError error = DeviceControllerErrors.vnxe.jobFailed("CreateCGSnapshot", ex.getMessage());
        taskCompleter.error(_dbClient, error);
    }
}
Also used : VNXeCommandJob(com.emc.storageos.vnxe.models.VNXeCommandJob) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) Volume(com.emc.storageos.db.client.model.Volume) VNXeApiClient(com.emc.storageos.vnxe.VNXeApiClient) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) List(java.util.List) URI(java.net.URI) QueueJob(com.emc.storageos.volumecontroller.impl.job.QueueJob) VNXUnityCreateCGSnapshotJob(com.emc.storageos.volumecontroller.impl.vnxunity.job.VNXUnityCreateCGSnapshotJob) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException)

Aggregations

VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)123 VNXeException (com.emc.storageos.vnxe.VNXeException)79 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)66 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)55 VNXeCommandJob (com.emc.storageos.vnxe.models.VNXeCommandJob)48 ControllerException (com.emc.storageos.volumecontroller.ControllerException)44 QueueJob (com.emc.storageos.volumecontroller.impl.job.QueueJob)40 URI (java.net.URI)37 ArrayList (java.util.ArrayList)34 FileShare (com.emc.storageos.db.client.model.FileShare)33 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)33 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)30 Snapshot (com.emc.storageos.db.client.model.Snapshot)27 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)24 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)23 DbClient (com.emc.storageos.db.client.DbClient)21 Volume (com.emc.storageos.db.client.model.Volume)18 VNXeFileTaskCompleter (com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeFileTaskCompleter)18 FileExport (com.emc.storageos.db.client.model.FileExport)14 HashMap (java.util.HashMap)14