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);
}
}
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);
}
}
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();
}
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);
}
}
}
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);
}
}
}
Aggregations