Search in sources :

Example 16 with Snapshot

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

the class FileSnapshotService method getSnapshot.

/**
 * Get info for file share snapshot
 *
 * @param id
 *            the URN of a ViPR Snapshot
 * @brief Show file snapshot
 * @return File snapshot details
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public FileSnapshotRestRep getSnapshot(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
    Snapshot snap = queryResource(id);
    return map(snap);
}
Also used : MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 17 with Snapshot

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

the class FileSnapshotService method getSnapshotShareACLs.

/**
 * Get Snapshot Share ACLs
 *
 * @param id
 *            the file system URI
 * @param shareName
 *            name of the share
 * @brief List snapshot share ACLs
 * @return
 */
@GET
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/shares/{shareName}/acl")
@CheckPermission(roles = { Role.SYSTEM_MONITOR, Role.TENANT_ADMIN }, acls = { ACL.ANY })
public ShareACLs getSnapshotShareACLs(@PathParam("id") URI id, @PathParam("shareName") String shareName) {
    _log.info("Request recieved to get ACLs with Id: {}  shareName: {}", id, shareName);
    // Validate the FS id
    ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
    ArgValidator.checkFieldNotNull(shareName, "shareName");
    Snapshot snapshot = queryResource(id);
    ArgValidator.checkEntity(snapshot, id, isIdEmbeddedInURL(id));
    if (!CifsShareUtility.doesShareExist(snapshot, shareName)) {
        _log.error("CIFS share does not exist {}", shareName);
        throw APIException.notFound.invalidParameterObjectHasNoSuchShare(snapshot.getId(), shareName);
    }
    ShareACLs acls = new ShareACLs();
    CifsShareUtility util = new CifsShareUtility(_dbClient, null, snapshot, shareName);
    List<ShareACL> shareAclList = util.queryExistingShareACLs();
    _log.info("Number of existing ACLs found : {} ", shareAclList.size());
    if (!shareAclList.isEmpty()) {
        acls.setShareACLs(shareAclList);
    }
    return acls;
}
Also used : MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) ShareACLs(com.emc.storageos.model.file.ShareACLs) CifsShareUtility(com.emc.storageos.api.service.impl.resource.utils.CifsShareUtility) ShareACL(com.emc.storageos.model.file.ShareACL) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 18 with Snapshot

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

the class FileSnapshotService method share.

/**
 * Creates SMB file share.
 * <p>
 * Note: This is an asynchronous operation.
 *
 * @param id
 *            the URN of a ViPR Snapshot
 * @param param
 *            File system share parameters
 * @brief Create file snapshot SMB share
 * @return Task resource representation
 * @throws InternalException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/shares")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.ANY })
public TaskResourceRep share(@PathParam("id") URI id, FileSystemShareParam param) throws InternalException {
    String task = UUID.randomUUID().toString();
    ArgValidator.checkFieldUriType(id, Snapshot.class, "id");
    ArgValidator.checkFieldNotNull(param.getShareName(), "name");
    ArgValidator.checkFieldNotEmpty(param.getShareName(), "name");
    Snapshot snap = queryResource(id);
    FileShare fs = _permissionsHelper.getObjectById(snap.getParent(), FileShare.class);
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    FileController controller = getController(FileController.class, device.getSystemType());
    ArgValidator.checkEntity(snap, id, isIdEmbeddedInURL(id));
    // Let us make sure that a share with the same name does not already exist.
    String shareName = param.getShareName();
    if (CifsShareUtility.doesShareExist(snap, shareName)) {
        _log.error("CIFS share: {}, already exists", shareName);
        throw APIException.badRequests.duplicateEntityWithField("CIFS share", "name");
    }
    // If value of permission is not provided, set the value to read-only
    if (param.getPermission() == null || param.getPermission().isEmpty()) {
        param.setPermission(FileSMBShare.Permission.read.name());
    }
    if (!param.getPermission().equals(FileSMBShare.Permission.read.name())) {
        throw APIException.badRequests.snapshotSMBSharePermissionReadOnly();
    }
    // Locate storage port for sharing snapshot
    // Select IP port of the storage array, owning the parent file system, which belongs to the same varray as the
    // file system.
    // We use file system in the call since file snap belongs to the same neighbourhood as its parent file system
    StoragePort sport = _fileScheduler.placeFileShareExport(fs, StorageProtocol.File.CIFS.name(), null);
    // Check if maxUsers is "unlimited" and set it to -1 in this case.
    if (param.getMaxUsers().equalsIgnoreCase(FileService.UNLIMITED_USERS)) {
        param.setMaxUsers("-1");
    }
    String path = snap.getPath();
    _log.info("Path {}", path);
    _log.info("Param Share Name : {} SubDirectory : {}", param.getShareName(), param.getSubDirectory());
    boolean isSubDirPath = false;
    if (ArgValidator.checkSubDirName("subDirectory", param.getSubDirectory())) {
        path += "/" + param.getSubDirectory();
        isSubDirPath = true;
        _log.info("Sub-directory path {}", path);
    }
    FileSMBShare smbShare = new FileSMBShare(param.getShareName(), param.getDescription(), param.getPermissionType(), param.getPermission(), param.getMaxUsers(), null, path);
    smbShare.setStoragePortName(sport.getPortName());
    smbShare.setStoragePortNetworkId(sport.getPortNetworkId());
    smbShare.setStoragePortGroup(sport.getPortGroup());
    smbShare.setSubDirPath(isSubDirPath);
    _log.info(String.format("Create snapshot share --- Snap id: %1$s, Share name: %2$s, StoragePort: %3$s, PermissionType: %4$s, " + "Permissions: %5$s, Description: %6$s, maxUsers: %7$s", id, smbShare.getName(), sport.getPortName(), smbShare.getPermissionType(), smbShare.getPermission(), smbShare.getDescription(), smbShare.getMaxUsers()));
    _log.info("SMB share path: {}", smbShare.getPath());
    Operation op = _dbClient.createTaskOpStatus(Snapshot.class, snap.getId(), task, ResourceOperationTypeEnum.CREATE_FILE_SNAPSHOT_SHARE);
    FileServiceApi fileServiceApi = FileService.getFileShareServiceImpl(fs, _dbClient);
    fileServiceApi.share(device.getId(), snap.getId(), smbShare, task);
    auditOp(OperationTypeEnum.CREATE_FILE_SNAPSHOT_SHARE, true, AuditLogManager.AUDITOP_BEGIN, smbShare.getName(), smbShare.getPermissionType(), smbShare.getPermission(), smbShare.getMaxUsers(), smbShare.getDescription(), snap.getId().toString());
    return toTask(snap, task, op);
}
Also used : MapFileSnapshot(com.emc.storageos.api.mapper.functions.MapFileSnapshot) Snapshot(com.emc.storageos.db.client.model.Snapshot) FileController(com.emc.storageos.volumecontroller.FileController) StoragePort(com.emc.storageos.db.client.model.StoragePort) Operation(com.emc.storageos.db.client.model.Operation) FileSMBShare(com.emc.storageos.volumecontroller.FileSMBShare) 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)

Example 19 with Snapshot

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

the class HDSBlockCreateSnapshotJob 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());
        HDSApiClient hdsApiClient = jobContext.getHdsApiFactory().getClient(HDSUtils.getHDSServerManagementServerInfo(storageSystem), storageSystem.getSmisUserName(), storageSystem.getSmisPassword());
        URI snapshotId = getTaskCompleter().getId(0);
        log.info("snapshotId :{}", snapshotId);
        if (_status == JobStatus.SUCCESS) {
            LogicalUnit logicalUnit = (LogicalUnit) _javaResult.getBean("virtualVolume");
            BlockSnapshot snapshot = dbClient.queryObject(BlockSnapshot.class, snapshotId);
            snapshot.setNativeId(String.valueOf(logicalUnit.getDevNum()));
            snapshot.setNativeGuid(NativeGUIDGenerator.generateNativeGuid(storageSystem, snapshot));
            snapshot.setInactive(false);
            snapshot.setCreationTime(Calendar.getInstance());
            long capacityInBytes = Long.valueOf(logicalUnit.getCapacityInKB()) * 1024L;
            snapshot.setProvisionedCapacity(capacityInBytes);
            snapshot.setAllocatedCapacity(capacityInBytes);
            snapshot.setWWN(HDSUtils.generateHitachiWWN(logicalUnit.getObjectID(), String.valueOf(logicalUnit.getDevNum())));
            snapshot.setIsSyncActive(true);
            dbClient.persistObject(snapshot);
            changeSnapshotName(dbClient, hdsApiClient, 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);
            if (snapshot != null) {
                snapshot.setInactive(true);
                dbClient.persistObject(snapshot);
            }
        }
        log.info(logMsgBuilder.toString());
    } catch (Exception e) {
        log.error("Caught an exception while trying to updateStatus for HDSBlockCreateSnapshotJob", e);
        setErrorStatus("Encountered an internal error during snapshot create job status processing : " + e.getMessage());
    } finally {
        _postProcessingStatus = JobStatus.SUCCESS;
        super.updateStatus(jobContext);
    }
}
Also used : HDSApiClient(com.emc.storageos.hds.api.HDSApiClient) Snapshot(com.emc.storageos.db.client.model.Snapshot) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) DbClient(com.emc.storageos.db.client.DbClient) LogicalUnit(com.emc.storageos.hds.model.LogicalUnit) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) URI(java.net.URI) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 20 with Snapshot

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

the class IsilonFileStorageDevice method isiDeleteExports.

/**
 * Delete isilon export
 *
 * @param isi
 *            IsilonApi object
 * @param exportMap
 *            exports to be deleted
 * @throws IsilonException
 */
private void isiDeleteExports(IsilonApi isi, FileDeviceInputOutput args) throws IsilonException {
    FSExportMap exportMap = null;
    if (args.getFileOperation()) {
        FileShare fileObj = args.getFs();
        if (fileObj != null) {
            exportMap = fileObj.getFsExports();
        }
    } else {
        Snapshot snap = args.getFileSnapshot();
        if (snap != null) {
            exportMap = snap.getFsExports();
        }
    }
    if (exportMap == null || exportMap.isEmpty()) {
        return;
    }
    String zoneName = getZoneName(args.getvNAS());
    Set<String> deletedExports = new HashSet<String>();
    Iterator<Map.Entry<String, FileExport>> it = exportMap.entrySet().iterator();
    try {
        while (it.hasNext()) {
            Map.Entry<String, FileExport> entry = it.next();
            String key = entry.getKey();
            FileExport fsExport = entry.getValue();
            if (zoneName != null) {
                isi.deleteExport(fsExport.getIsilonId(), zoneName);
            } else {
                isi.deleteExport(fsExport.getIsilonId());
            }
            // 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.
            deletedExports.add(key);
        }
    } finally {
        // remove exports from the map in database.
        for (String key : deletedExports) {
            exportMap.remove(key);
        }
    }
}
Also used : Snapshot(com.emc.storageos.db.client.model.Snapshot) IsilonSnapshot(com.emc.storageos.isilon.restapi.IsilonSnapshot) FileExport(com.emc.storageos.db.client.model.FileExport) FSExportMap(com.emc.storageos.db.client.model.FSExportMap) 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)

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