Search in sources :

Example 66 with Snapshot

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);
    }
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) ServiceError(com.emc.storageos.svcs.errorhandling.model.ServiceError) FileWorkflowCompleter(com.emc.storageos.volumecontroller.impl.file.FileWorkflowCompleter) FileSnapshotWorkflowCompleter(com.emc.storageos.volumecontroller.impl.file.FileSnapshotWorkflowCompleter) Workflow(com.emc.storageos.workflow.Workflow) FileObject(com.emc.storageos.db.client.model.FileObject) FileObject(com.emc.storageos.db.client.model.FileObject) VNXeFSSnapshotTaskCompleter(com.emc.storageos.volumecontroller.impl.vnxe.job.VNXeFSSnapshotTaskCompleter) MirrorFileFailoverTaskCompleter(com.emc.storageos.volumecontroller.impl.file.MirrorFileFailoverTaskCompleter) MirrorFileFailbackTaskCompleter(com.emc.storageos.volumecontroller.impl.file.MirrorFileFailbackTaskCompleter) TaskCompleter(com.emc.storageos.volumecontroller.TaskCompleter) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) WorkflowException(com.emc.storageos.workflow.WorkflowException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException)

Example 67 with Snapshot

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;
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Example 68 with Snapshot

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;
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) ScheduleSnapshotList(com.emc.storageos.model.file.ScheduleSnapshotList) SnapshotList(com.emc.storageos.model.SnapshotList) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 69 with Snapshot

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);
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) NamedURI(com.emc.storageos.db.client.model.NamedURI) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) StoragePort(com.emc.storageos.db.client.model.StoragePort) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) MapFileShare(com.emc.storageos.api.mapper.functions.MapFileShare) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 70 with Snapshot

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);
}
Also used : MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) ServiceCoded(com.emc.storageos.svcs.errorhandling.model.ServiceCoded) Operation(com.emc.storageos.db.client.model.Operation) FileShare(com.emc.storageos.db.client.model.FileShare) SMBFileShare(com.emc.storageos.db.client.model.SMBFileShare) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

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