use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class FileOrchestrationDeviceController method createCIFSShare.
@Override
public void createCIFSShare(URI storageSystem, URI uri, FileSMBShare smbShare, String taskId) throws ControllerException {
FileObject fileObj = null;
String stepDescription = null;
String successMessage = null;
String opName = null;
TaskCompleter completer = null;
if (URIUtil.isType(uri, FileShare.class)) {
completer = new FileWorkflowCompleter(uri, taskId);
fileObj = s_dbClient.queryObject(FileShare.class, uri);
stepDescription = String.format("Creating CIFS share for file system : %s, share name: %s ", uri, smbShare.getName());
successMessage = String.format("Creating CIFS share for file system : %s, share name: %s finished succesfully.", uri, smbShare.getName());
opName = ResourceOperationTypeEnum.CREATE_FILE_SYSTEM_SHARE.getName();
} else {
completer = new FileSnapshotWorkflowCompleter(uri, taskId);
fileObj = s_dbClient.queryObject(Snapshot.class, uri);
stepDescription = String.format("Creating CIFS share for file system snapshot : %s, share name: %s ", uri, smbShare.getName());
successMessage = String.format("Creating CIFS share for file system : %s, share name: %s finished succesfully.", uri, smbShare.getName());
opName = ResourceOperationTypeEnum.CREATE_FILE_SNAPSHOT_SHARE.getName();
}
try {
Workflow workflow = _workflowService.getNewWorkflow(this, CREATE_FILESYSTEM_CIFS_SHARE_WF_NAME, false, taskId, completer);
String shareStep = workflow.createStepId();
Object[] args = new Object[] { storageSystem, uri, smbShare };
_fileDeviceController.createMethod(workflow, null, CREATE_FILESYSTEM_SHARE_METHOD, shareStep, stepDescription, storageSystem, args);
workflow.executePlan(completer, successMessage);
} catch (Exception ex) {
s_logger.error(String.format("Creating CIFS share for file system : %s, share name: %s failed.", uri, smbShare.getName()), ex);
ServiceError serviceError = DeviceControllerException.errors.createFileSharesFailed(fileObj.toString(), opName, ex);
completer.error(s_dbClient, _locker, serviceError);
}
}
use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class FileService method getNumSnapshots.
// Counts and returns the number of snapshots on a filesystem
Integer getNumSnapshots(FileShare fs) {
Integer numSnapshots = 0;
URI fsId = fs.getId();
URIQueryResultList snapIDList = new URIQueryResultList();
_dbClient.queryByConstraint(ContainmentConstraint.Factory.getFileshareSnapshotConstraint(fsId), snapIDList);
while (snapIDList.iterator().hasNext()) {
URI uri = snapIDList.iterator().next();
Snapshot snap = _dbClient.queryObject(Snapshot.class, uri);
if (!snap.getInactive()) {
numSnapshots++;
}
}
return numSnapshots;
}
use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class FileService method getSnapshots.
/**
* Get file system snapshots
*
* @param id
* the URN of a ViPR File system
* @brief List file system snapshots
* @return List of snapshots
*/
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshots")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public SnapshotList getSnapshots(@PathParam("id") URI id) {
List<URI> snapIDList = _dbClient.queryByConstraint(ContainmentConstraint.Factory.getFileshareSnapshotConstraint(id));
_log.debug("getSnapshots: FS {}: {} ", id.toString(), snapIDList.toString());
List<Snapshot> snapList = _dbClient.queryObject(Snapshot.class, snapIDList);
SnapshotList list = new SnapshotList();
for (Snapshot snap : snapList) {
list.getSnapList().add(toNamedRelatedResource(snap));
}
return list;
}
use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class FileService method snapshot.
/**
* Create file system snapshot
* <p>
* NOTE: This is an asynchronous operation.
*
* @param id
* the URN of a ViPR File system
* @param param
* file system snapshot parameters
* @brief Create file system snapshot
* @return Task resource representation
* @throws InternalException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/snapshots")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskResourceRep snapshot(@PathParam("id") URI id, FileSystemSnapshotParam param) throws InternalException {
ArgValidator.checkFieldUriType(id, FileShare.class, "id");
FileShare fs = queryResource(id);
ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
VirtualPool vpool = _dbClient.queryObject(VirtualPool.class, fs.getVirtualPool());
if (vpool == null) {
throw APIException.badRequests.invalidParameterFileSystemHasNoVirtualPool(id);
}
if (getNumSnapshots(fs) >= vpool.getMaxNativeSnapshots()) {
throw APIException.methodNotAllowed.maximumNumberSnapshotsReached();
}
String label = TimeUtils.formatDateForCurrent(param.getLabel());
// check duplicate fileshare snapshot names for this fileshare
checkForDuplicateName(label, Snapshot.class, id, "parent", _dbClient);
Snapshot snap = new Snapshot();
snap.setId(URIUtil.createId(Snapshot.class));
snap.setParent(new NamedURI(id, label));
snap.setLabel(label);
snap.setOpStatus(new OpStatusMap());
snap.setProject(new NamedURI(fs.getProject().getURI(), label));
String convertedName = label.replaceAll("[^\\dA-Za-z_]", "");
_log.info("Original name {} and converted name {}", label, convertedName);
snap.setName(convertedName);
fs.setOpStatus(new OpStatusMap());
Operation op = new Operation();
op.setResourceType(ResourceOperationTypeEnum.CREATE_FILE_SYSTEM_SNAPSHOT);
String task = UUID.randomUUID().toString();
snap.getOpStatus().createTaskStatus(task, op);
fs.getOpStatus().createTaskStatus(task, op);
_dbClient.createObject(snap);
_dbClient.persistObject(fs);
// find storageport for fs and based on protocol
if (null == fs.getStoragePort()) {
StoragePort storagePort;
try {
// assigned storageport to fs
storagePort = _fileScheduler.placeFileShareExport(fs, PROTOCOL_NFS, null);
_log.info("FS is not mounted so we are mounting the FS first and then creating the Snapshot and the returned storage port- {} and supported protocol-{}", storagePort.getPortName(), PROTOCOL_NFS);
} catch (APIException e) {
// if we don't find port for NFS protocol then
// in catch exception we get port for CIFS protocol
storagePort = _fileScheduler.placeFileShareExport(fs, PROTOCOL_CIFS, null);
_log.info("FS is not mounted so we are mounting the FS first and then creating the Snapshot and the returned storage port- {} and supported protocol-{}", storagePort.getPortName(), PROTOCOL_NFS);
}
}
// send request to controller
try {
FileServiceApi fileServiceApi = getFileShareServiceImpl(fs, _dbClient);
fileServiceApi.snapshotFS(device.getId(), snap.getId(), fs.getId(), task);
} catch (InternalException e) {
snap.setInactive(true);
_dbClient.persistObject(snap);
// should discriminate between validation problems vs. internal errors
throw e;
}
auditOp(OperationTypeEnum.CREATE_FILE_SYSTEM_SNAPSHOT, true, AuditLogManager.AUDITOP_BEGIN, snap.getLabel(), snap.getId().toString(), fs.getId().toString());
fs = _dbClient.queryObject(FileShare.class, id);
_log.debug("Before sending response, FS ID : {}, Taks : {} ; Status {}", fs.getOpStatus().get(task), fs.getOpStatus().get(task).getStatus());
return toTask(snap, task, op);
}
use of com.emc.storageos.db.client.model.Snapshot in project coprhd-controller by CoprHD.
the class FileSnapshotService method restore.
/**
* Call will restore this snapshot to the File system that it is associated with.
*
* @param id
* [required] - the URN of a ViPR file snapshot to restore from
* @brief Restore file snapshot
* @return TaskResourceRep - Task resource object for tracking this operation
* @throws InternalException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
@Path("/{id}/restore")
public TaskResourceRep restore(@PathParam("id") URI id) throws InternalException {
ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
Snapshot snap = queryResource(id);
FileShare fs = _permissionsHelper.getObjectById(snap.getParent(), FileShare.class);
String task = UUID.randomUUID().toString();
Operation op = null;
if ((snap != null) && (!(snap.getInactive()))) {
StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
StorageSystem.Type storageSystemType = StorageSystem.Type.valueOf(device.getSystemType());
if (storageSystemType.equals(DiscoveredDataObject.Type.isilon)) {
_log.error("Invalid Operation. Restore snapshot is not supported by ISILON");
throw APIException.badRequests.isilonSnapshotRestoreNotSupported();
}
_log.info(String.format("Snapshot restore --- Snapshot id: %1$s, FileShare: %2$s, task %3$s", id, fs.getId(), task));
_dbClient.createTaskOpStatus(FileShare.class, fs.getId(), task, ResourceOperationTypeEnum.RESTORE_FILE_SNAPSHOT);
op = _dbClient.createTaskOpStatus(Snapshot.class, snap.getId(), task, ResourceOperationTypeEnum.RESTORE_FILE_SNAPSHOT);
FileServiceApi fileServiceApi = FileService.getFileShareServiceImpl(fs, _dbClient);
fileServiceApi.restoreFS(device.getId(), fs.getId(), snap.getId(), task);
auditOp(OperationTypeEnum.RESTORE_FILE_SNAPSHOT, true, AuditLogManager.AUDITOP_BEGIN, snap.getId().toString(), fs.getId().toString());
} else {
StringBuilder msg = new StringBuilder("Attempt to use deleted snapshot: " + snap.getName());
msg.append(" to restore File: " + fs.getName());
op = new Operation();
ServiceCoded coded = ServiceError.buildServiceError(ServiceCode.API_BAD_REQUEST, msg.toString());
op.error(coded);
op.setMessage(msg.toString());
op = _dbClient.createTaskOpStatus(Snapshot.class, snap.getId(), task, op);
_log.error(msg.toString());
}
return toTask(snap, task, op);
}
Aggregations