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