use of com.emc.storageos.model.TaskResourceRep in project coprhd-controller by CoprHD.
the class RPBlockServiceApiImpl method createVolumes.
@Override
public TaskList createVolumes(VolumeCreate param, Project project, VirtualArray varray, VirtualPool vpool, Map<VpoolUse, List<Recommendation>> recommendationMap, TaskList taskList, String task, VirtualPoolCapabilityValuesWrapper capabilities) throws InternalException {
List<Recommendation> recommendations = recommendationMap.get(VpoolUse.ROOT);
// List of volumes to be prepared
List<URI> volumeURIs = new ArrayList<URI>();
// Volume label from the param
String volumeLabel = param.getName();
// List to store the volume descriptors for the Block Orchestration
List<VolumeDescriptor> volumeDescriptors = new ArrayList<VolumeDescriptor>();
// Store capabilities of the CG, so they make it down to the controller
if (vpool.getRpCopyMode() != null) {
capabilities.put(VirtualPoolCapabilityValuesWrapper.RP_COPY_MODE, vpool.getRpCopyMode());
}
if (vpool.getRpRpoType() != null && NullColumnValueGetter.isNotNullValue(vpool.getRpRpoType())) {
capabilities.put(VirtualPoolCapabilityValuesWrapper.RP_RPO_TYPE, vpool.getRpRpoType());
}
if (vpool.checkRpRpoValueSet()) {
capabilities.put(VirtualPoolCapabilityValuesWrapper.RP_RPO_VALUE, vpool.getRpRpoValue());
}
// Get the first recommendation, we need to figure out if this is a change vpool
RPProtectionRecommendation rpProtectionRec = (RPProtectionRecommendation) recommendations.get(0);
boolean isChangeVpool = (rpProtectionRec.getVpoolChangeVolume() != null);
boolean isChangeVpoolForProtectedVolume = rpProtectionRec.isVpoolChangeProtectionAlreadyExists();
// for change vpool, save off the original source volume in case we need to roll back
URI oldVpoolId = null;
if (isChangeVpool || isChangeVpoolForProtectedVolume) {
Volume changeVpoolVolume = _dbClient.queryObject(Volume.class, rpProtectionRec.getVpoolChangeVolume());
oldVpoolId = changeVpoolVolume.getVirtualPool();
}
try {
// Prepare the volumes
prepareRecommendedVolumes(param, task, taskList, project, varray, vpool, capabilities.getResourceCount(), recommendations, volumeLabel, capabilities, volumeDescriptors, volumeURIs);
// Execute the volume creations requests for each recommendation.
Iterator<Recommendation> recommendationsIter = recommendations.iterator();
while (recommendationsIter.hasNext()) {
RPProtectionRecommendation recommendation = (RPProtectionRecommendation) recommendationsIter.next();
volumeDescriptors.addAll(createVolumeDescriptors(recommendation, volumeURIs, capabilities, oldVpoolId, param.getComputeResource()));
logDescriptors(volumeDescriptors);
BlockOrchestrationController controller = getController(BlockOrchestrationController.class, BlockOrchestrationController.BLOCK_ORCHESTRATION_DEVICE);
// TODO might be able to use param.getSize() instead of the below code to find requestedVolumeCapactity
Long requestedVolumeCapactity = 0L;
for (URI volumeURI : volumeURIs) {
Volume volume = _dbClient.queryObject(Volume.class, volumeURI);
if (Volume.PersonalityTypes.SOURCE.name().equalsIgnoreCase(volume.getPersonality())) {
requestedVolumeCapactity = volume.getCapacity();
break;
}
}
computeProtectionCapacity(volumeURIs, requestedVolumeCapactity, false, isChangeVpool, null);
if (isChangeVpool) {
_log.info("Add Recoverpoint Protection to existing volume");
controller.changeVirtualPool(volumeDescriptors, task);
} else {
_log.info("Create RP volumes");
controller.createVolumes(volumeDescriptors, task);
}
}
} catch (Exception e) {
_log.error(e.getMessage(), e);
try {
// We want to return the volume back to its original state.
if (isChangeVpool || isChangeVpoolForProtectedVolume) {
Volume changeVpoolVolume = _dbClient.queryObject(Volume.class, rpProtectionRec.getVpoolChangeVolume());
VirtualPool oldVpool = _dbClient.queryObject(VirtualPool.class, oldVpoolId);
RPHelper.rollbackProtectionOnVolume(changeVpoolVolume, oldVpool, _dbClient);
}
for (URI volumeURI : volumeURIs) {
// completely rollback an existing volume (which the change vpool volume would be).
if (!volumeURI.equals(rpProtectionRec.getVpoolChangeVolume())) {
RPHelper.rollbackVolume(volumeURI, _dbClient);
}
}
} catch (Exception e2) {
// best effort for rollback; still need to set the tasks to error
_log.error("rollback create volume or change vpool failed");
_log.error(e2.getMessage(), e);
}
// Let's check to see if there are existing tasks, if so, put them in error.
if (taskList.getTaskList() != null && !taskList.getTaskList().isEmpty()) {
for (TaskResourceRep volumeTask : taskList.getTaskList()) {
volumeTask.setState(Operation.Status.error.name());
volumeTask.setMessage(e.getMessage());
Operation statusUpdate = new Operation(Operation.Status.error.name(), e.getMessage());
_dbClient.updateTaskOpStatus(Volume.class, volumeTask.getResource().getId(), task, statusUpdate);
}
}
throw APIException.badRequests.rpBlockApiImplPrepareVolumeException(volumeLabel);
}
return taskList;
}
use of com.emc.storageos.model.TaskResourceRep in project coprhd-controller by CoprHD.
the class FileService method stopContinuousCopies.
/**
* Stop continuous copies.
*
* @prereq none
* @param id the URN of a ViPR Source file share
* @brief Stop the replication session between source and target file system.
* @return TaskList
* @throws ControllerException
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/stop")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList stopContinuousCopies(@PathParam("id") URI id, FileReplicationParam param) throws ControllerException {
doMirrorOperationValidation(id, ProtectionOp.STOP.toString());
String task = UUID.randomUUID().toString();
FileShare sourceFileShare = queryResource(id);
Set<URI> unassignFrom = new HashSet<>();
unassignFrom.add(id);
FilePolicy filepolicy = FileSystemReplicationUtils.getReplicationPolicyAppliedOnFS(sourceFileShare, _dbClient);
Operation op = _dbClient.createTaskOpStatus(FileShare.class, id, task, ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_STOP);
op.setDescription("stop the replication link between source and target");
FileOrchestrationController controller = getController(FileOrchestrationController.class, FileOrchestrationController.FILE_ORCHESTRATION_DEVICE);
controller.unassignFilePolicy(filepolicy.getId(), unassignFrom, task);
auditOp(OperationTypeEnum.STOP_FILE_MIRROR, true, "BEGIN", sourceFileShare.getId().toString());
TaskList taskList = new TaskList();
TaskResourceRep taskResp = toTask(sourceFileShare, task, op);
taskList.getTaskList().add(taskResp);
return taskList;
}
use of com.emc.storageos.model.TaskResourceRep in project coprhd-controller by CoprHD.
the class FileService method resumeContinuousCopies.
/**
* Resume continuous copies.
*
* @prereq none
* @param id the URN of a ViPR Source file share
* @brief Resume the replication session between source and target file system.
* @return TaskList
* @throws ControllerException
*/
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/resume")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList resumeContinuousCopies(@PathParam("id") URI id, FileReplicationParam param) throws ControllerException {
doMirrorOperationValidation(id, ProtectionOp.RESUME.toString());
String task = UUID.randomUUID().toString();
FileShare sourceFileShare = queryResource(id);
Operation op = _dbClient.createTaskOpStatus(FileShare.class, id, task, ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_RESUME);
op.setDescription("resume the replication link between source and target");
StorageSystem system = _dbClient.queryObject(StorageSystem.class, sourceFileShare.getStorageDevice());
FileController controller = getController(FileController.class, system.getSystemType());
controller.performFileReplicationOperation(system.getId(), id, ProtectionOp.RESUME.toString().toLowerCase(), task);
TaskList taskList = new TaskList();
TaskResourceRep taskResp = toTask(sourceFileShare, task, op);
taskList.getTaskList().add(taskResp);
return taskList;
}
use of com.emc.storageos.model.TaskResourceRep in project coprhd-controller by CoprHD.
the class FileService method failbackProtection.
/**
* Request to fail Back the protection link associated with the param.copyID.
*
* NOTE: This is an asynchronous operation.
*
* @prereq none
*
* @param id
* the URN of a ViPR Source files hare
* @param param
* FileReplicationParam to fail Back to
*
* @brief Fail Back the fileShare protection link
* @return TaskList
*
* @throws ControllerException
*/
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/protection/continuous-copies/failback")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskList failbackProtection(@PathParam("id") URI id, FileReplicationParam param) throws ControllerException {
doMirrorOperationValidation(id, ProtectionOp.FAILBACK.toString());
TaskResourceRep taskResp = null;
StoragePort storageportNFS = null;
StoragePort storageportCIFS = null;
TaskList taskList = new TaskList();
String task = UUID.randomUUID().toString();
FileShare sourceFileShare = queryResource(id);
Operation op = _dbClient.createTaskOpStatus(FileShare.class, id, task, ResourceOperationTypeEnum.FILE_PROTECTION_ACTION_FAILBACK);
op.setDescription("failback to source file system from target system");
boolean replicateConfiguration = param.isReplicateConfiguration();
if (replicateConfiguration) {
List<String> targetfileUris = new ArrayList<String>();
targetfileUris.addAll(sourceFileShare.getMirrorfsTargets());
FileShare targetFileShare = _dbClient.queryObject(FileShare.class, URI.create(targetfileUris.get(0)));
SMBShareMap smbShareMap = targetFileShare.getSMBFileShares();
if (smbShareMap != null) {
storageportCIFS = _fileScheduler.placeFileShareExport(sourceFileShare, StorageProtocol.File.CIFS.name(), null);
}
FSExportMap nfsExportMap = targetFileShare.getFsExports();
if (nfsExportMap != null) {
storageportNFS = _fileScheduler.placeFileShareExport(sourceFileShare, StorageProtocol.File.NFS.name(), null);
}
}
FileServiceApi fileServiceApi = getFileShareServiceImpl(sourceFileShare, _dbClient);
try {
fileServiceApi.failbackFileShare(sourceFileShare.getId(), storageportNFS, storageportCIFS, replicateConfiguration, task);
} catch (InternalException e) {
if (_log.isErrorEnabled()) {
_log.error("", e);
}
op = sourceFileShare.getOpStatus().get(task);
op.error(e);
sourceFileShare.getOpStatus().updateTaskStatus(task, op);
_dbClient.updateObject(sourceFileShare);
throw e;
}
taskResp = toTask(sourceFileShare, task, op);
taskList.getTaskList().add(taskResp);
return taskList;
}
use of com.emc.storageos.model.TaskResourceRep in project coprhd-controller by CoprHD.
the class FileService method createFileTaskList.
/**
* A method that pre-creates task and FileShare object to return to the caller of the API.
*
* @param param
* @param project
* - project of the FileShare
* @param tenantOrg
* - tenant of the FileShare
* @param varray
* - varray of the FileShare
* @param vpool
* - vpool of the Fileshare
* @param flags
* -
* @param task
* @return
*/
private TaskList createFileTaskList(FileSystemParam param, Project project, TenantOrg tenantOrg, VirtualArray varray, VirtualPool vpool, DataObject.Flag[] flags, String task) {
TaskList taskList = new TaskList();
FileShare fs = prepareEmptyFileSystem(param, project, tenantOrg, varray, vpool, flags, task);
TaskResourceRep fileTask = toTask(fs, task);
taskList.getTaskList().add(fileTask);
_log.info(String.format("FileShare and Task Pre-creation Objects [Init]-- Source FileSystem: %s, Task: %s, Op: %s", fs.getId(), fileTask.getId(), task));
return taskList;
}
Aggregations