Search in sources :

Example 1 with OpStatusMap

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

the class ExportUtils method createVplexExportGroup.

/**
 * Create an ExportGroup.
 *
 * @param vplex -- VPLEX StorageSystem
 * @param array -- Array StorageSystem
 * @param initiators -- Collection<Initiator> representing VPLEX back-end ports.
 * @param virtualArrayURI
 * @param projectURI
 * @param tenantURI
 * @param numPaths Value of maxPaths to be put in ExportGroup
 * @param exportMask IFF non-null, will add the exportMask to the Export Group.
 * @return newly created ExportGroup persisted in DB.
 */
public static ExportGroup createVplexExportGroup(DbClient dbClient, StorageSystem vplex, StorageSystem array, Collection<Initiator> initiators, URI virtualArrayURI, URI projectURI, URI tenantURI, int numPaths, ExportMask exportMask) {
    String groupName = getExportGroupName(vplex, array) + "_" + UUID.randomUUID().toString().substring(28);
    if (exportMask != null) {
        String arrayName = array.getSystemType().replace("block", "") + array.getSerialNumber().substring(array.getSerialNumber().length() - 4);
        groupName = exportMask.getMaskName() + "_" + arrayName;
    }
    // No existing group has the mask, let's create one.
    ExportGroup exportGroup = new ExportGroup();
    exportGroup.setId(URIUtil.createId(ExportGroup.class));
    exportGroup.setLabel(groupName);
    exportGroup.setProject(new NamedURI(projectURI, exportGroup.getLabel()));
    exportGroup.setVirtualArray(vplex.getVirtualArray());
    exportGroup.setTenant(new NamedURI(tenantURI, exportGroup.getLabel()));
    exportGroup.setGeneratedName(groupName);
    exportGroup.setVolumes(new StringMap());
    exportGroup.setOpStatus(new OpStatusMap());
    exportGroup.setVirtualArray(virtualArrayURI);
    exportGroup.setNumPaths(numPaths);
    // Add the initiators into the ExportGroup.
    for (Initiator initiator : initiators) {
        exportGroup.addInitiator(initiator);
    }
    // If we have an Export Mask, add it into the Export Group.
    if (exportMask != null) {
        exportGroup.addExportMask(exportMask.getId());
    }
    // Persist the ExportGroup
    dbClient.createObject(exportGroup);
    _log.info(String.format("Returning new ExportGroup %s", exportGroup.getLabel()));
    return exportGroup;
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) StringMap(com.emc.storageos.db.client.model.StringMap) NamedURI(com.emc.storageos.db.client.model.NamedURI) Initiator(com.emc.storageos.db.client.model.Initiator) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap)

Example 2 with OpStatusMap

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

the class RPBlockServiceApiImpl method createTaskForVolume.

/**
 * Used to create a task and add it to the TaskList
 *
 * @param volume
 *            Volume that the task is for
 * @param type
 *            type of the task
 * @param taskList
 *            The TaskList to store tasks
 * @param task
 *            Task Id
 */
private void createTaskForVolume(Volume volume, ResourceOperationTypeEnum type, TaskList taskList, String task) {
    // Create the OP
    Operation op = _dbClient.createTaskOpStatus(Volume.class, volume.getId(), task, type);
    volume.setOpStatus(new OpStatusMap());
    volume.getOpStatus().put(task, op);
    // Persist the volume in the db
    _dbClient.updateObject(volume);
    _log.info(String.format("Created task of type [%s] for volume [%s]", type.name(), volume.getLabel()));
    // Create the task and add it to the task list
    taskList.getTaskList().add(toTask(volume, task, op));
}
Also used : OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) Operation(com.emc.storageos.db.client.model.Operation)

Example 3 with OpStatusMap

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

the class SRDFBlockServiceApiImpl method prepareVolume.

/**
 * Prepare Volume for an SRDF protected volume
 *
 * @param volume
 *            pre-created volume from the api service
 * @param param
 *            volume request
 * @param project
 *            project requested
 * @param varray
 *            varray requested
 * @param vpool
 *            vpool requested
 * @param size
 *            size of the volume
 * @param placement
 *            recommendation for placement
 * @param label
 *            volume label
 * @param consistencyGroup
 *            consistency group
 * @param token
 *            task id
 * @param remote
 *            is this a target volume
 * @param personality
 *            normal volume or metadata
 * @param srcVolumeId
 *            source volume ID; only for target volumes
 * @param raGroupURI
 *            RDF Group of the source array to use
 * @param copyMode
 *            copy policy, like async or sync
 *
 * @return a persisted volume
 */
private Volume prepareVolume(Volume volume, final Project project, final VirtualArray varray, final VirtualPool vpool, final String size, final Recommendation placement, final String label, final BlockConsistencyGroup consistencyGroup, final String token, final boolean remote, final Volume.PersonalityTypes personality, final URI srcVolumeId, final URI raGroupURI, final String copyMode) {
    boolean newVolume = false;
    if (volume == null) {
        // check for duplicate label
        validateVolumeLabel(label, project);
        newVolume = true;
        volume = new Volume();
        volume.setId(URIUtil.createId(Volume.class));
        volume.setOpStatus(new OpStatusMap());
    } else {
        volume = _dbClient.queryObject(Volume.class, volume.getId());
    }
    volume.setLabel(label);
    volume.setCapacity(SizeUtil.translateSize(size));
    volume.setThinlyProvisioned(VirtualPool.ProvisioningType.Thin.toString().equalsIgnoreCase(vpool.getSupportedProvisioningType()));
    volume.setVirtualPool(vpool.getId());
    volume.setProject(new NamedURI(project.getId(), volume.getLabel()));
    volume.setTenant(new NamedURI(project.getTenantOrg().getURI(), volume.getLabel()));
    volume.setVirtualArray(varray.getId());
    volume.setSrdfGroup(raGroupURI);
    volume.setSrdfCopyMode(copyMode);
    if (null != placement.getSourceStoragePool()) {
        StoragePool pool = _dbClient.queryObject(StoragePool.class, placement.getSourceStoragePool());
        if (null != pool) {
            volume.setProtocol(new StringSet());
            volume.getProtocol().addAll(VirtualPoolUtil.getMatchingProtocols(vpool.getProtocols(), pool.getProtocols()));
        }
    }
    volume.setPersonality(personality.toString());
    if (personality.equals(Volume.PersonalityTypes.SOURCE)) {
        volume.setAccessState(VolumeAccessState.READWRITE.name());
    } else if (personality.equals(Volume.PersonalityTypes.TARGET)) {
        volume.setAccessState(VolumeAccessState.NOT_READY.name());
    }
    URI storageSystemUri = null;
    if (!remote) {
        storageSystemUri = placement.getSourceStorageSystem();
        volume.setStorageController(storageSystemUri);
        volume.setPool(placement.getSourceStoragePool());
    } else {
        storageSystemUri = ((SRDFRecommendation) placement).getVirtualArrayTargetMap().get(varray.getId()).getTargetStorageDevice();
        volume.setStorageController(storageSystemUri);
        volume.setPool(((SRDFRecommendation) placement).getVirtualArrayTargetMap().get(varray.getId()).getTargetStoragePool());
    }
    StorageSystem storageSystem = _dbClient.queryObject(StorageSystem.class, storageSystemUri);
    String systemType = storageSystem.checkIfVmax3() ? DiscoveredDataObject.Type.vmax3.name() : storageSystem.getSystemType();
    volume.setSystemType(systemType);
    volume.setOpStatus(new OpStatusMap());
    Operation op = new Operation();
    op.setResourceType(ResourceOperationTypeEnum.CREATE_BLOCK_VOLUME);
    op.setStartTime(Calendar.getInstance());
    volume.getOpStatus().put(token, op);
    if (consistencyGroup != null) {
        volume.setConsistencyGroup(consistencyGroup.getId());
        volume.setReplicationGroupInstance(consistencyGroup.getLabel());
    }
    if (null != vpool.getAutoTierPolicyName()) {
        URI autoTierPolicyUri = StorageScheduler.getAutoTierPolicy(volume.getPool(), vpool.getAutoTierPolicyName(), _dbClient);
        if (null != autoTierPolicyUri) {
            volume.setAutoTieringPolicyUri(autoTierPolicyUri);
        }
    }
    // Keep track of target volumes associated with the source volume
    if (srcVolumeId != null) {
        Volume srcVolume = _dbClient.queryObject(Volume.class, srcVolumeId);
        if (srcVolume.getSrdfTargets() == null) {
            srcVolume.setSrdfTargets(new StringSet());
        }
        // This is done in prepare, but the source volume may be a cos change volume that didn't
        // go through that process.
        srcVolume.setPersonality(Volume.PersonalityTypes.SOURCE.toString());
        srcVolume.getSrdfTargets().add(volume.getId().toString());
        _dbClient.updateObject(srcVolume);
        volume.setSrdfParent(new NamedURI(srcVolume.getId(), srcVolume.getLabel()));
        computeCapacityforSRDFV3ToV2(volume, vpool);
    }
    if (newVolume) {
        _dbClient.createObject(volume);
    } else {
        _dbClient.updateObject(volume);
    }
    return volume;
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) Volume(com.emc.storageos.db.client.model.Volume) NamedURI(com.emc.storageos.db.client.model.NamedURI) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) StringSet(com.emc.storageos.db.client.model.StringSet) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) StorageSystem(com.emc.storageos.db.client.model.StorageSystem)

Example 4 with OpStatusMap

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

the class FileService method createQuotaDirectory.

/**
 * Create Quota directory for a file system
 * <p>
 * NOTE: This is an asynchronous operation.
 *
 * @param id
 *            the URN of a ViPR File system
 * @param param
 *            File system Quota directory parameters
 * @brief Create file system Quota directory
 * @return Task resource representation
 * @throws InternalException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/quota-directories")
@CheckPermission(roles = { Role.TENANT_ADMIN }, acls = { ACL.OWN, ACL.ALL })
public TaskResourceRep createQuotaDirectory(@PathParam("id") URI id, QuotaDirectoryCreateParam param) throws InternalException {
    _log.info("FileService::createQtree Request recieved {}", id);
    String origQtreeName = param.getQuotaDirName();
    ArgValidator.checkQuotaDirName(origQtreeName, "name");
    ArgValidator.checkFieldMaximum(param.getSoftLimit(), 100, "softLimit");
    ArgValidator.checkFieldMaximum(param.getNotificationLimit(), 100, "notificationLimit");
    if (param.getSoftLimit() != 0L) {
        ArgValidator.checkFieldMinimum(param.getSoftGrace(), 1L, "softGrace");
    }
    // check duplicate QuotaDirectory names for this fileshare
    checkForDuplicateName(origQtreeName, QuotaDirectory.class, id, "parent", _dbClient);
    String task = UUID.randomUUID().toString();
    ArgValidator.checkFieldUriType(id, FileShare.class, "id");
    if (param.getSecurityStyle() != null) {
        ArgValidator.checkFieldValueFromEnum(param.getSecurityStyle(), "security_style", EnumSet.allOf(QuotaDirectory.SecurityStyles.class));
    }
    // Get the FileSystem object from the URN
    FileShare fs = queryResource(id);
    ArgValidator.checkEntity(fs, id, isIdEmbeddedInURL(id));
    int fsSoftLimit = -1;
    if (null != fs.getSoftLimit()) {
        fsSoftLimit = fs.getSoftLimit().intValue();
    }
    int fsNotifiLimit = -1;
    if (null != fs.getNotificationLimit()) {
        fsNotifiLimit = fs.getNotificationLimit().intValue();
    }
    int fsGraceLimit = -1;
    if (null != fs.getSoftGracePeriod()) {
        fsGraceLimit = fs.getSoftGracePeriod().intValue();
    }
    // Create the QuotaDirectory object for the DB
    QuotaDirectory quotaDirectory = new QuotaDirectory();
    quotaDirectory.setId(URIUtil.createId(QuotaDirectory.class));
    // ICICIC - Curious !
    quotaDirectory.setParent(new NamedURI(id, origQtreeName));
    quotaDirectory.setLabel(origQtreeName);
    quotaDirectory.setOpStatus(new OpStatusMap());
    quotaDirectory.setProject(new NamedURI(fs.getProject().getURI(), origQtreeName));
    quotaDirectory.setTenant(new NamedURI(fs.getTenant().getURI(), origQtreeName));
    quotaDirectory.setSoftLimit(param.getSoftLimit() > 0 ? param.getSoftLimit() : fsSoftLimit > 0 ? fsSoftLimit : 0);
    quotaDirectory.setSoftGrace(param.getSoftGrace() > 0 ? param.getSoftGrace() : fsGraceLimit > 0 ? fsGraceLimit : 0);
    quotaDirectory.setNotificationLimit(param.getNotificationLimit() > 0 ? param.getNotificationLimit() : fsNotifiLimit > 0 ? fsNotifiLimit : 0);
    String convertedName = origQtreeName.replaceAll("[^\\dA-Za-z_]", "");
    _log.info("FileService::QuotaDirectory Original name {} and converted name {}", origQtreeName, convertedName);
    quotaDirectory.setName(convertedName);
    if (param.getOpLock() != null) {
        quotaDirectory.setOpLock(param.getOpLock());
    } else {
        quotaDirectory.setOpLock(true);
    }
    if (param.getSecurityStyle() != null) {
        quotaDirectory.setSecurityStyle(param.getSecurityStyle());
    } else {
        quotaDirectory.setSecurityStyle(SecurityStyles.parent.toString());
    }
    if (param.getSize() != null) {
        // converts the input string in format "<value>GB"
        Long quotaSize = SizeUtil.translateSize(param.getSize());
        // to bytes
        ArgValidator.checkFieldMaximum(quotaSize, fs.getCapacity(), SizeUtil.SIZE_B, "size", true);
        quotaDirectory.setSize(quotaSize);
    } else {
        quotaDirectory.setSize((long) 0);
    }
    fs.setOpStatus(new OpStatusMap());
    Operation op = new Operation();
    op.setResourceType(ResourceOperationTypeEnum.CREATE_FILE_SYSTEM_QUOTA_DIR);
    quotaDirectory.getOpStatus().createTaskStatus(task, op);
    fs.getOpStatus().createTaskStatus(task, op);
    _dbClient.createObject(quotaDirectory);
    _dbClient.persistObject(fs);
    // Create an object of type "FileShareQuotaDirectory" to be passed into the south-bound layers.
    FileShareQuotaDirectory qt = new FileShareQuotaDirectory(quotaDirectory);
    // Now get ready to make calls into the controller
    StorageSystem device = _dbClient.queryObject(StorageSystem.class, fs.getStorageDevice());
    FileController controller = getController(FileController.class, device.getSystemType());
    try {
        controller.createQuotaDirectory(device.getId(), qt, fs.getId(), task);
    } catch (InternalException e) {
        quotaDirectory.setInactive(true);
        _dbClient.persistObject(quotaDirectory);
        // should discriminate between validation problems vs. internal errors
        throw e;
    }
    auditOp(OperationTypeEnum.CREATE_FILE_SYSTEM_QUOTA_DIR, true, AuditLogManager.AUDITOP_BEGIN, quotaDirectory.getLabel(), quotaDirectory.getId().toString(), fs.getId().toString());
    fs = _dbClient.queryObject(FileShare.class, id);
    _log.debug("FileService::QuotaDirectory Before sending response, FS ID : {}, Tasks : {} ; Status {}", fs.getOpStatus().get(task), fs.getOpStatus().get(task).getStatus());
    return toTask(quotaDirectory, task, op);
}
Also used : NamedURI(com.emc.storageos.db.client.model.NamedURI) FileController(com.emc.storageos.volumecontroller.FileController) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) QuotaDirectory(com.emc.storageos.db.client.model.QuotaDirectory) FileShareQuotaDirectory(com.emc.storageos.volumecontroller.FileShareQuotaDirectory) 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) PrefixConstraint(com.emc.storageos.db.client.constraint.PrefixConstraint) AlternateIdConstraint(com.emc.storageos.db.client.constraint.AlternateIdConstraint) ContainmentPrefixConstraint(com.emc.storageos.db.client.constraint.ContainmentPrefixConstraint) ContainmentConstraint(com.emc.storageos.db.client.constraint.ContainmentConstraint) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) SecurityStyles(com.emc.storageos.db.client.model.QuotaDirectory.SecurityStyles) FileShareQuotaDirectory(com.emc.storageos.volumecontroller.FileShareQuotaDirectory) 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 5 with OpStatusMap

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

the class FileService method prepareFileSystem.

/**
 * Allocate, initialize and persist state of the fileSystem being created.
 *
 * @param param
 * @param project
 * @param tenantOrg
 * @param neighborhood
 * @param vpool
 * @param flags
 * @param placement
 * @param token
 * @return
 */
private FileShare prepareFileSystem(FileSystemParam param, Project project, TenantOrg tenantOrg, VirtualArray neighborhood, VirtualPool vpool, DataObject.Flag[] flags, FileRecommendation placement, String token) {
    _log.info("prepareFile System");
    StoragePool pool = null;
    FileShare fs = new FileShare();
    fs.setId(URIUtil.createId(FileShare.class));
    fs.setLabel(param.getLabel());
    // No need to generate any name -- Since the requirement is to use the customizing label we should use the same.
    // Stripping out the special characters like ; /-+!@#$%^&())";:[]{}\ | but allow underscore character _
    String convertedName = param.getLabel().replaceAll("[^\\dA-Za-z\\_]", "");
    _log.info("Original name {} and converted name {}", param.getLabel(), convertedName);
    fs.setName(convertedName);
    Long fsSize = SizeUtil.translateSize(param.getSize());
    fs.setCapacity(fsSize);
    fs.setVirtualPool(param.getVpool());
    if (project != null) {
        fs.setProject(new NamedURI(project.getId(), fs.getLabel()));
    }
    fs.setTenant(new NamedURI(tenantOrg.getId(), param.getLabel()));
    fs.setVirtualArray(neighborhood.getId());
    if (null != placement.getSourceStoragePool()) {
        pool = _dbClient.queryObject(StoragePool.class, placement.getSourceStoragePool());
        if (null != pool) {
            fs.setProtocol(new StringSet());
            fs.getProtocol().addAll(VirtualPoolUtil.getMatchingProtocols(vpool.getProtocols(), pool.getProtocols()));
        }
    }
    fs.setStorageDevice(placement.getSourceStorageSystem());
    fs.setPool(placement.getSourceStoragePool());
    if (param.getSoftLimit() != 0) {
        fs.setSoftLimit(new Long(param.getSoftLimit()));
    }
    if (param.getNotificationLimit() != 0) {
        fs.setNotificationLimit(new Long(param.getNotificationLimit()));
    }
    if (param.getSoftGrace() > 0) {
        fs.setSoftGracePeriod(new Integer(param.getSoftGrace()));
    }
    if (placement.getStoragePorts() != null && !placement.getStoragePorts().isEmpty()) {
        fs.setStoragePort(placement.getStoragePorts().get(0));
    }
    // When a VPool supports "thin" provisioning
    if (VirtualPool.ProvisioningType.Thin.toString().equalsIgnoreCase(vpool.getSupportedProvisioningType())) {
        fs.setThinlyProvisioned(Boolean.TRUE);
    }
    if (placement.getvNAS() != null) {
        fs.setVirtualNAS(placement.getvNAS());
    }
    fs.setOpStatus(new OpStatusMap());
    Operation op = new Operation();
    op.setResourceType(ResourceOperationTypeEnum.CREATE_FILE_SYSTEM);
    fs.getOpStatus().createTaskStatus(token, op);
    if (flags != null) {
        fs.addInternalFlags(flags);
    }
    _dbClient.createObject(fs);
    return fs;
}
Also used : StoragePool(com.emc.storageos.db.client.model.StoragePool) NamedURI(com.emc.storageos.db.client.model.NamedURI) StringSet(com.emc.storageos.db.client.model.StringSet) OpStatusMap(com.emc.storageos.db.client.model.OpStatusMap) 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)

Aggregations

OpStatusMap (com.emc.storageos.db.client.model.OpStatusMap)48 Operation (com.emc.storageos.db.client.model.Operation)29 NamedURI (com.emc.storageos.db.client.model.NamedURI)28 Volume (com.emc.storageos.db.client.model.Volume)15 URI (java.net.URI)15 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)13 StringSet (com.emc.storageos.db.client.model.StringSet)13 FileShare (com.emc.storageos.db.client.model.FileShare)12 ArrayList (java.util.ArrayList)10 SMBFileShare (com.emc.storageos.db.client.model.SMBFileShare)9 StringMap (com.emc.storageos.db.client.model.StringMap)9 HashMap (java.util.HashMap)9 StoragePool (com.emc.storageos.db.client.model.StoragePool)8 InternalException (com.emc.storageos.svcs.errorhandling.resources.InternalException)7 MapFileShare (com.emc.storageos.api.mapper.functions.MapFileShare)6 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)6 DataObject (com.emc.storageos.db.client.model.DataObject)6 CheckPermission (com.emc.storageos.security.authorization.CheckPermission)6 Consumes (javax.ws.rs.Consumes)6 AlternateIdConstraint (com.emc.storageos.db.client.constraint.AlternateIdConstraint)5