Search in sources :

Example 56 with Snapshot

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

the class FileSystemExportToFileSystemExportRuleMigration method process.

@Override
public void process() throws MigrationCallbackException {
    log.info("FileSystemExport to FileSystem export rule migration: start");
    DbClient dbClient = getDbClient();
    try {
        List<URI> fileExpRuleURIList = dbClient.queryByType(FileExportRule.class, true);
        int exisitingExportRuleCount = 0;
        for (Iterator<URI> iterator = fileExpRuleURIList.iterator(); iterator.hasNext(); ) {
            URI uri = (URI) iterator.next();
            log.debug("Existing export rule URI: {}", uri);
            exisitingExportRuleCount++;
        }
        if (exisitingExportRuleCount > 0) {
            log.info("There are exisiting export rule(s). Skipping migration.");
            return;
        }
        // FileSystems
        List<URI> fileSystemURIList = dbClient.queryByType(FileShare.class, true);
        Iterator<FileShare> fileShareListIterator = dbClient.queryIterativeObjects(FileShare.class, fileSystemURIList);
        while (fileShareListIterator.hasNext()) {
            FileShare fileShare = fileShareListIterator.next();
            // Create FS Export Rule for export Map
            List<FileExportRule> fsExpRules = createFSExportRules(fileShare);
            if (null != fsExpRules && !fsExpRules.isEmpty()) {
                log.debug("Persisting new File Export rule(s): {}", fsExpRules);
                dbClient.createObject(fsExpRules);
            }
        }
        // Snapshots
        List<URI> snapshotURIList = dbClient.queryByType(Snapshot.class, true);
        Iterator<Snapshot> snapshotListIterator = dbClient.queryIterativeObjects(Snapshot.class, snapshotURIList);
        while (snapshotListIterator.hasNext()) {
            Snapshot snapshot = snapshotListIterator.next();
            // Create FS Export Rule for export Map
            List<FileExportRule> snapshotExpRules = createSnapshotExportRules(snapshot);
            if (null != snapshotExpRules && !snapshotExpRules.isEmpty()) {
                log.debug("Persisting new Snapshot Export rule(s): {}", snapshotExpRules);
                dbClient.createObject(snapshotExpRules);
            }
        }
        log.info("FileSystemExport to FileSystem export rule migration: end");
    } catch (Exception e) {
        log.error("Exception occured while migrating FileShare/Snapshot Export Map CF to FileExportRule CF");
        log.error(e.getMessage(), e);
    }
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) DbClient(com.emc.storageos.db.client.DbClient) FileExportRule(com.emc.storageos.db.client.model.FileExportRule) URI(java.net.URI) FileShare(com.emc.storageos.db.client.model.FileShare) MigrationCallbackException(com.emc.storageos.svcs.errorhandling.resources.MigrationCallbackException)

Example 57 with Snapshot

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

the class CinderSnapshotCreateJob method updateStatus.

@Override
public void updateStatus(JobContext jobContext) throws Exception {
    DbClient dbClient = jobContext.getDbClient();
    try {
        // Do nothing if the job is not completed yet
        if (status == JobStatus.IN_PROGRESS) {
            return;
        }
        String opId = getTaskCompleter().getOpId();
        StringBuilder logMsgBuilder = new StringBuilder(String.format("Updating status of job %s to %s", opId, status.name()));
        StorageSystem storageSystem = dbClient.queryObject(StorageSystem.class, getStorageSystemURI());
        CinderApi cinderApi = jobContext.getCinderApiFactory().getApi(storageSystem.getActiveProviderURI(), getEndPointInfo());
        URI snapshotId = getTaskCompleter().getId(0);
        if (status == JobStatus.SUCCESS) {
            SnapshotCreateResponse snapshotDetails = cinderApi.showSnapshot(getJobId());
            BlockSnapshot snapshot = dbClient.queryObject(BlockSnapshot.class, snapshotId);
            snapshot.setNativeId(snapshotDetails.snapshot.id);
            snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storageSystem, snapshot));
            snapshot.setInactive(false);
            snapshot.setCreationTime(Calendar.getInstance());
            dbClient.persistObject(snapshot);
            if (logMsgBuilder.length() != 0) {
                logMsgBuilder.append("\n");
            }
            logMsgBuilder.append(String.format("Created Snapshot successfully .. NativeId: %s, URI: %s", snapshot.getNativeId(), getTaskCompleter().getId()));
        } else if (status == JobStatus.FAILED) {
            logMsgBuilder.append("\n");
            logMsgBuilder.append(String.format("Task %s failed to create volume: %s", opId, getTaskCompleter().getId().toString()));
            Snapshot snapshot = dbClient.queryObject(Snapshot.class, snapshotId);
            snapshot.setInactive(true);
            dbClient.persistObject(snapshot);
        }
        _logger.info(logMsgBuilder.toString());
    } catch (Exception e) {
        _logger.error("Caught an exception while trying to updateStatus for CinderCreateSnapshotJob", e);
        setErrorStatus("Encountered an internal error during snapshot create job status processing : " + e.getMessage());
    } finally {
        super.updateStatus(jobContext);
    }
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) SnapshotCreateResponse(com.emc.storageos.cinder.model.SnapshotCreateResponse) DbClient(com.emc.storageos.db.client.DbClient) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) CinderApi(com.emc.storageos.cinder.api.CinderApi) URI(java.net.URI) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 58 with Snapshot

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

the class IsilonFileStorageDevice method listSanpshotByPolicy.

@Override
public BiosCommandResult listSanpshotByPolicy(StorageSystem storageObj, FileDeviceInputOutput args) {
    FilePolicy sp = args.getFileProtectionPolicy();
    FileShare fs = args.getFs();
    String snapshotScheduleName = sp.getFilePolicyName() + "_" + args.getFsName();
    if (sp.getPolicyStorageResources() != null && !sp.getPolicyStorageResources().isEmpty()) {
        for (String uriResource : sp.getPolicyStorageResources()) {
            PolicyStorageResource policyRes = _dbClient.queryObject(PolicyStorageResource.class, URI.create(uriResource));
            if (policyRes != null && policyRes.getStorageSystem().equals(storageObj.getId())) {
                snapshotScheduleName = policyRes.getPolicyNativeId();
                break;
            }
        }
    }
    IsilonApi isi = getIsilonDevice(storageObj);
    String resumeToken = null;
    try {
        do {
            IsilonList<IsilonSnapshot> snapshots = isi.listSnapshotsCreatedByPolicy(resumeToken, snapshotScheduleName);
            if (snapshots != null) {
                for (IsilonSnapshot islon_snap : snapshots.getList()) {
                    _log.info("file policy snapshot is  : " + islon_snap.getName());
                    Snapshot snap = new Snapshot();
                    snap.setLabel(islon_snap.getName());
                    snap.setMountPath(islon_snap.getPath());
                    snap.setName(islon_snap.getName());
                    snap.setId(URIUtil.createId(Snapshot.class));
                    snap.setOpStatus(new OpStatusMap());
                    snap.setProject(new NamedURI(fs.getProject().getURI(), islon_snap.getName()));
                    snap.setMountPath(getSnapshotPath(islon_snap.getPath(), islon_snap.getName()));
                    snap.setParent(new NamedURI(fs.getId(), islon_snap.getName()));
                    StringMap map = new StringMap();
                    Long createdTime = Long.parseLong(islon_snap.getCreated()) * SEC_IN_MILLI;
                    String expiresTime = "Never";
                    if (islon_snap.getExpires() != null && !islon_snap.getExpires().isEmpty()) {
                        Long expTime = Long.parseLong(islon_snap.getExpires()) * SEC_IN_MILLI;
                        expiresTime = expTime.toString();
                    }
                    map.put("created", createdTime.toString());
                    map.put("expires", expiresTime);
                    map.put("schedule", sp.getFilePolicyName());
                    snap.setExtensions(map);
                    _dbClient.updateObject(snap);
                }
                resumeToken = snapshots.getToken();
            }
        } while (resumeToken != null && !resumeToken.equalsIgnoreCase("null"));
    } catch (IsilonException e) {
        _log.error("listing snapshot by file policy failed.", e);
        return BiosCommandResult.createErrorResult(e);
    }
    Task task = TaskUtils.findTaskForRequestId(_dbClient, fs.getId(), args.getOpId());
    // set task to completed and progress to 100 and store in DB, so waiting thread in apisvc can read it.
    task.ready();
    task.setProgress(100);
    _dbClient.updateObject(task);
    return BiosCommandResult.createSuccessfulResult();
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) Task(com.emc.storageos.db.client.model.Task) FilePolicy(com.emc.storageos.db.client.model.FilePolicy) NamedURI(com.emc.storageos.db.client.model.NamedURI) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) PolicyStorageResource(com.emc.storageos.db.client.model.PolicyStorageResource) Snapshot(com.emc.storageos.db.client.model.Snapshot) IsilonSnapshot(com.emc.storageos.isilon.restapi.IsilonSnapshot) IsilonSnapshot(com.emc.storageos.isilon.restapi.IsilonSnapshot) IsilonApi(com.emc.storageos.isilon.restapi.IsilonApi) IsilonException(com.emc.storageos.isilon.restapi.IsilonException)

Example 59 with Snapshot

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

the class IsilonFileStorageDevice method isiDeleteShares.

private void isiDeleteShares(IsilonApi isi, FileDeviceInputOutput args) throws IsilonException {
    _log.info("IsilonFileStorageDevice:isiDeleteShares()");
    SMBShareMap currentShares = null;
    if (args.getFileOperation()) {
        FileShare fileObj = args.getFs();
        if (fileObj != null) {
            currentShares = fileObj.getSMBFileShares();
        }
    } else {
        Snapshot snap = args.getFileSnapshot();
        if (snap != null) {
            currentShares = snap.getSMBFileShares();
        }
    }
    if (currentShares == null || currentShares.isEmpty()) {
        return;
    }
    Set<String> deletedShares = new HashSet<String>();
    Iterator<Map.Entry<String, SMBFileShare>> it = currentShares.entrySet().iterator();
    String zoneName = getZoneName(args.getvNAS());
    try {
        while (it.hasNext()) {
            Map.Entry<String, SMBFileShare> entry = it.next();
            String key = entry.getKey();
            SMBFileShare smbFileShare = entry.getValue();
            _log.info("delete the share name {} and native id {}", smbFileShare.getName(), smbFileShare.getNativeId());
            if (zoneName != null) {
                isi.deleteShare(smbFileShare.getNativeId(), zoneName);
            } else {
                isi.deleteShare(smbFileShare.getNativeId());
            }
            // Safe removal from the backing map. Can not do this through
            // iterator since this does not track changes and is not
            // reflected in the database.
            deletedShares.add(key);
        }
    } finally {
        // remove shares from the map in database.
        for (String key : deletedShares) {
            currentShares.remove(key);
        }
    }
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) IsilonSnapshot(com.emc.storageos.isilon.restapi.IsilonSnapshot) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) Map(java.util.Map) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) HashMap(java.util.HashMap) SMBShareMap(com.emc.storageos.db.client.model.SMBShareMap) StringMap(com.emc.storageos.db.client.model.StringMap) CifsServerMap(com.emc.storageos.db.client.model.CifsServerMap) HashSet(java.util.HashSet)

Example 60 with Snapshot

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

the class IsilonFileStorageDevice method isiDeleteSnapshots.

/**
 * Deleting snapshots: - deletes snapshots of a file system
 *
 * @param isi
 *            IsilonApi object
 * @param args
 *            FileDeviceInputOutput
 * @throws IsilonException
 */
private void isiDeleteSnapshots(IsilonApi isi, FileDeviceInputOutput args) throws IsilonException {
    List<URI> snapURIList = _dbClient.queryByConstraint(ContainmentConstraint.Factory.getFileshareSnapshotConstraint(args.getFsId()));
    for (URI snapURI : snapURIList) {
        Snapshot snap = _dbClient.queryObject(Snapshot.class, snapURI);
        if (snap != null && (!snap.getInactive())) {
            args.addSnapshot(snap);
            isiDeleteSnapshot(isi, args);
        }
    }
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) IsilonSnapshot(com.emc.storageos.isilon.restapi.IsilonSnapshot) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI)

Aggregations

Snapshot (com.emc.storageos.db.client.model.Snapshot)92 FileShare (com.emc.storageos.db.client.model.FileShare)59 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)52 URI (java.net.URI)36 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)34 ControllerException (com.emc.storageos.volumecontroller.ControllerException)34 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)32 ServiceError (com.emc.storageos.svcs.errorhandling.model.ServiceError)31 ArrayList (java.util.ArrayList)24 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)23 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)22 FileObject (com.emc.storageos.db.client.model.FileObject)21 URISyntaxException (java.net.URISyntaxException)21 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)19 VNXeApiClient (com.emc.storageos.vnxe.VNXeApiClient)19 WorkflowException (com.emc.storageos.workflow.WorkflowException)19 MapFileSnapshot (com.emc.storageos.api.mapper.functions.MapFileSnapshot)18 Path (javax.ws.rs.Path)18 APIException (com.emc.storageos.svcs.errorhandling.resources.APIException)17 Produces (javax.ws.rs.Produces)17