Search in sources :

Example 6 with ScopedLabel

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

the class ConsistencyGroupSnapshotService method createConsistencyGroupSnapshot.

/**
 * Create consistency group snapshot
 *
 * @param openstackTenantId
 *            openstack tenant Id
 * @param param
 *            Pojo class to bind request
 * @param isV1Call
 *            cinder V1 api
 * @param header
 *            HTTP header
 * @brief Create Consistency Group Snapshot
 * @return Response
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response createConsistencyGroupSnapshot(@PathParam("tenant_id") String openstackTenantId, final ConsistencyGroupSnapshotCreateRequest param, @HeaderParam("X-Cinder-V1-Call") String isV1Call, @Context HttpHeaders header) {
    // Query Consistency Group
    final String consistencyGroupId = param.cgsnapshot.consistencygroup_id;
    final BlockConsistencyGroup consistencyGroup = findConsistencyGroup(consistencyGroupId, openstackTenantId);
    if (consistencyGroup == null) {
        _log.error("Not Found : No Such Consistency Group Found {}", consistencyGroupId);
        return CinderApiUtils.createErrorResponse(404, "Not Found : No Such Consistency Group Found");
    } else if (!consistencyGroupId.equals(CinderApiUtils.splitString(consistencyGroup.getId().toString(), ":", 3))) {
        _log.error("Bad Request : Invalid Snapshot Id {} : Please enter valid or full Id", consistencyGroupId);
        return CinderApiUtils.createErrorResponse(400, "Bad Request : No such consistency id exist, Please enter valid or full Id");
    }
    if (!isSnapshotCreationpermissible(consistencyGroup)) {
        _log.error("Bad Request : vpool not being configured for the snapshots creation");
        return CinderApiUtils.createErrorResponse(400, "Bad Request : vpool not being configured for the snapshots creation");
    }
    // system types.
    if (!consistencyGroup.created()) {
        CinderApiUtils.createErrorResponse(400, "No such consistency group created");
    }
    Project project = getCinderHelper().getProject(openstackTenantId, getUserFromContext());
    URI cgStorageControllerURI = consistencyGroup.getStorageController();
    if (!NullColumnValueGetter.isNullURI(cgStorageControllerURI)) {
        // No snapshots for VPLEX consistency groups.
        StorageSystem cgStorageController = _dbClient.queryObject(StorageSystem.class, cgStorageControllerURI);
        if ((DiscoveredDataObject.Type.vplex.name().equals(cgStorageController.getSystemType())) && (!consistencyGroup.checkForType(Types.LOCAL))) {
            CinderApiUtils.createErrorResponse(400, "can't create snapshot for VPLEX");
        }
    }
    // Get the block service implementation
    BlockServiceApi blockServiceApiImpl = getBlockServiceImpl(consistencyGroup);
    // Get the volumes in the consistency group.
    List<Volume> volumeList = blockServiceApiImpl.getActiveCGVolumes(consistencyGroup);
    _log.info("Active CG volume list : " + volumeList);
    // Generate task id
    String taskId = UUID.randomUUID().toString();
    // Set snapshot type.
    String snapshotType = BlockSnapshot.TechnologyType.NATIVE.toString();
    if (consistencyGroup.checkForType(BlockConsistencyGroup.Types.RP)) {
        snapshotType = BlockSnapshot.TechnologyType.RP.toString();
    } else if ((!volumeList.isEmpty()) && (volumeList.get(0).checkForSRDF())) {
        snapshotType = BlockSnapshot.TechnologyType.SRDF.toString();
    }
    // Determine the snapshot volume for RP.
    Volume snapVolume = null;
    if (consistencyGroup.checkForType(BlockConsistencyGroup.Types.RP)) {
        for (Volume volumeToSnap : volumeList) {
            // Get the RP source volume.
            if (volumeToSnap.getPersonality() != null && volumeToSnap.getPersonality().equals(Volume.PersonalityTypes.SOURCE.toString())) {
                snapVolume = volumeToSnap;
                break;
            }
        }
    } else if (!volumeList.isEmpty()) {
        // Any volume.
        snapVolume = volumeList.get(0);
    }
    // Set the create inactive flag.
    Boolean createInactive = Boolean.FALSE;
    Boolean readOnly = Boolean.FALSE;
    // Validate the snapshot request.
    String snapshotName = param.cgsnapshot.name;
    blockServiceApiImpl.validateCreateSnapshot(snapVolume, volumeList, snapshotType, snapshotName, readOnly, getFullCopyManager());
    // Prepare and create the snapshots for the group.
    List<URI> snapIdList = new ArrayList<URI>();
    List<BlockSnapshot> snapshotList = new ArrayList<BlockSnapshot>();
    TaskList response = new TaskList();
    snapshotList.addAll(blockServiceApiImpl.prepareSnapshots(volumeList, snapshotType, snapshotName, snapIdList, taskId));
    for (BlockSnapshot snapshot : snapshotList) {
        response.getTaskList().add(toTask(snapshot, taskId));
    }
    blockServiceApiImpl.createSnapshot(snapVolume, snapIdList, snapshotType, createInactive, readOnly, taskId);
    auditBlockConsistencyGroup(OperationTypeEnum.CREATE_CONSISTENCY_GROUP_SNAPSHOT, AuditLogManager.AUDITLOG_SUCCESS, AuditLogManager.AUDITOP_BEGIN, param.cgsnapshot.name, consistencyGroup.getId().toString());
    ConsistencyGroupSnapshotCreateResponse cgSnapshotCreateRes = new ConsistencyGroupSnapshotCreateResponse();
    for (TaskResourceRep rep : response.getTaskList()) {
        URI snapshotUri = rep.getResource().getId();
        BlockSnapshot snap = _dbClient.queryObject(BlockSnapshot.class, snapshotUri);
        snap.setId(snapshotUri);
        snap.setConsistencyGroup(consistencyGroup.getId());
        snap.setLabel(snapshotName);
        if (snap != null) {
            StringMap extensions = snap.getExtensions();
            if (extensions == null) {
                extensions = new StringMap();
            }
            extensions.put("status", CinderConstants.ComponentStatus.CREATING.getStatus().toLowerCase());
            extensions.put("taskid", rep.getId().toString());
            snap.setExtensions(extensions);
            ScopedLabelSet tagSet = new ScopedLabelSet();
            snap.setTag(tagSet);
            tagSet.add(new ScopedLabel(project.getTenantOrg().getURI().toString(), CinderApiUtils.splitString(snapshotUri.toString(), ":", 3)));
        }
        _dbClient.updateObject(snap);
        cgSnapshotCreateRes.id = CinderApiUtils.splitString(snapshotUri.toString(), ":", 3);
        cgSnapshotCreateRes.name = param.cgsnapshot.name;
    }
    return CinderApiUtils.getCinderResponse(cgSnapshotCreateRes, header, true, CinderConstants.STATUS_OK);
}
Also used : StringMap(com.emc.storageos.db.client.model.StringMap) TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) URI(java.net.URI) BlockServiceApi(com.emc.storageos.api.service.impl.resource.BlockServiceApi) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet) BlockConsistencyGroup(com.emc.storageos.db.client.model.BlockConsistencyGroup) Project(com.emc.storageos.db.client.model.Project) Volume(com.emc.storageos.db.client.model.Volume) ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) ConsistencyGroupSnapshotCreateResponse(com.emc.storageos.cinder.model.ConsistencyGroupSnapshotCreateResponse) StorageSystem(com.emc.storageos.db.client.model.StorageSystem) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 7 with ScopedLabel

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

the class ExportService method getListOfInitiators.

private List<Initiator> getListOfInitiators(Connector connector, String tenant_id, String protocol, Volume vol) {
    List<Initiator> initiators = new ArrayList<Initiator>();
    boolean bFound = false;
    if (protocol.equals(Protocol.iSCSI.name())) {
        // this is an iSCSI request
        String port = connector.initiator;
        String hostname = connector.host;
        List<Initiator> iscsi_initiators = new ArrayList<Initiator>();
        Boolean found = searchInDb(port, iscsi_initiators, Protocol.iSCSI.name());
        if (found) {
            initiators.addAll(iscsi_initiators);
        } else {
            // not found, create a new one
            _log.info("Creating new iSCSI initiator, iqn = {}", port);
            // Make sure the port is a valid iSCSI port.
            if (!iSCSIUtility.isValidIQNPortName(port) && !iSCSIUtility.isValidEUIPortName(port))
                throw APIException.badRequests.invalidIscsiInitiatorPort();
            // Find host, and if not found, create new host
            Host host = getHost(hostname, tenant_id);
            // create and populate the initiator
            Initiator initiator = new Initiator();
            initiator.setHost(host.getId());
            initiator.setHostName(connector.host);
            if (!NullColumnValueGetter.isNullURI(host.getCluster())) {
                Cluster cluster = queryObject(Cluster.class, host.getCluster(), false);
                initiator.setClusterName(cluster.getLabel());
            }
            initiator.setId(URIUtil.createId(Initiator.class));
            initiator.setInitiatorPort(port);
            // allows deletion via UI
            initiator.setIsManualCreation(true);
            initiator.setProtocol(HostInterface.Protocol.iSCSI.name());
            addInitiatorToNetwork(initiator, vol);
            ScopedLabelSet tags = new ScopedLabelSet();
            tags.add(new ScopedLabel("openstack", "dynamic"));
            initiator.setTag(tags);
            _dbClient.createObject(initiator);
            initiators.add(initiator);
        }
    } else if (protocol.equals(Protocol.FC.name())) {
        // this is an FC request
        for (String fc_port : connector.wwpns) {
            // See if this initiator exists in our DB
            List<Initiator> fc_initiators = new ArrayList<Initiator>();
            Boolean found = searchInDb(fc_port, fc_initiators, Protocol.FC.name());
            if (found) {
                bFound = true;
                initiators.addAll(fc_initiators);
            } else {
                // not found, we don't create dynamically for FC
                _log.info("FC initiator for wwpn {} not found", fc_port);
            }
        }
        if (!bFound) {
            throw APIException.internalServerErrors.genericApisvcError("Export Failed", new Exception("No FC initiator found for export"));
        }
    } else {
        throw APIException.internalServerErrors.genericApisvcError("Unsupported volume protocol", new Exception("The protocol specified is not supported. The protocols supported are " + Protocol.FC.name() + " and " + Protocol.iSCSI.name()));
    }
    return initiators;
}
Also used : ArrayList(java.util.ArrayList) Cluster(com.emc.storageos.db.client.model.Cluster) Host(com.emc.storageos.db.client.model.Host) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet) APIException(com.emc.storageos.svcs.errorhandling.resources.APIException) InternalException(com.emc.storageos.svcs.errorhandling.resources.InternalException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) Initiator(com.emc.storageos.db.client.model.Initiator) ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) ITLRestRepList(com.emc.storageos.model.block.export.ITLRestRepList) List(java.util.List) ArrayList(java.util.ArrayList) SearchedResRepList(com.emc.storageos.api.service.impl.response.SearchedResRepList)

Example 8 with ScopedLabel

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

the class BlockServiceUtils method validateNotABootVolume.

/**
 * Validate that the passed block object is not marked as a boot volume.
 *
 * @param blockObject A reference to a BlockObject
 * @param force true if an operation should be forced regardless of whether
 *            or not the passed block object is an internal object, false
 *            otherwise.
 */
public static void validateNotABootVolume(BlockObject blockObject, boolean force) {
    if (blockObject != null && blockObject.getTag() != null) {
        Iterator<ScopedLabel> slIter = blockObject.getTag().iterator();
        boolean taggedAsBootVolume = false;
        while (slIter.hasNext()) {
            ScopedLabel sl = slIter.next();
            if (sl.getLabel().startsWith(TagUtils.getBootVolumeTagName())) {
                taggedAsBootVolume = true;
            }
        }
        if (taggedAsBootVolume && !force) {
            throw APIException.badRequests.notSupportedForBootVolumes();
        }
    }
}
Also used : ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel)

Example 9 with ScopedLabel

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

the class SnapshotService method createSnapshot.

/**
 * The snapshot of a volume in Block Store is a point in time copy of the
 * volume. This API allows the user to create snapshot of a volume
 * NOTE: This is an asynchronous operation.
 *
 * @prereq none
 *
 * @param param
 *            POST data containing the snapshot creation information.
 *
 * @brief Create snapshot
 * @return Details of the newly created snapshot
 * @throws InternalException
 */
@POST
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response createSnapshot(@PathParam("tenant_id") String openstack_tenant_id, SnapshotCreateRequestGen param, @Context HttpHeaders header, @HeaderParam("X-Cinder-V1-Call") String isV1Call) throws InternalException {
    // Step 1: Parameter validation
    String snapshotName = null;
    String snapshotDescription = null;
    if (isV1Call != null) {
        snapshotName = param.snapshot.display_name;
        snapshotDescription = param.snapshot.display_description;
    } else {
        snapshotName = param.snapshot.name;
        snapshotDescription = param.snapshot.description;
    }
    // if snapshot name is empty create random name
    if (snapshotName == null) {
        snapshotName = "snapshot-" + RandomStringUtils.random(10);
    }
    if (snapshotName == null || (snapshotName.length() <= 2)) {
        throw APIException.badRequests.parameterIsNotValid(param.snapshot.name);
    }
    URI volumeUri = null;
    Volume volume = null;
    volumeUri = URI.create(param.snapshot.volume_id);
    volume = queryVolumeResource(volumeUri, openstack_tenant_id);
    if (volume == null) {
        _log.error("Invalid source volume id to create snapshot ={} ", param.snapshot.volume_id);
        return CinderApiUtils.createErrorResponse(404, "Not Found : Invalid source volume id " + param.snapshot.volume_id);
    }
    VirtualPool pool = _dbClient.queryObject(VirtualPool.class, volume.getVirtualPool());
    if (pool == null) {
        _log.info("Virtual Pool corresponding to the volume does not exist.");
        throw APIException.badRequests.parameterIsNotValid(volume.getVirtualPool().toString());
    }
    if (!validateSnapshotCreate(openstack_tenant_id, pool, volume.getProvisionedCapacity())) {
        _log.info("The volume can not be created because of insufficient quota for virtual pool.");
        throw APIException.badRequests.insufficientQuotaForVirtualPool(pool.getLabel(), "virtual pool");
    }
    if (!validateSnapshotCreate(openstack_tenant_id, null, volume.getProvisionedCapacity())) {
        _log.info("The volume can not be created because of insufficient quota for Project.");
        throw APIException.badRequests.insufficientQuotaForProject(pool.getLabel(), "project");
    }
    BlockFullCopyManager fcManager = new BlockFullCopyManager(_dbClient, _permissionsHelper, _auditMgr, _coordinator, _placementManager, sc, uriInfo, _request, _tenantsService);
    VolumeIngestionUtil.checkOperationSupportedOnIngestedVolume(volume, ResourceOperationTypeEnum.CREATE_VOLUME_SNAPSHOT, _dbClient);
    // Don't operate on VPLEX backend volumes or RP journal volumes.
    BlockServiceUtils.validateNotAnInternalBlockObject(volume, false);
    validateSourceVolumeHasExported(volume);
    String snapshotType = TechnologyType.NATIVE.toString();
    Boolean createInactive = Boolean.FALSE;
    Boolean readOnly = Boolean.FALSE;
    BlockServiceApi api = getBlockServiceImpl(pool, _dbClient);
    List<Volume> volumesToSnap = new ArrayList<Volume>();
    volumesToSnap.addAll(api.getVolumesToSnap(volume, snapshotType));
    api.validateCreateSnapshot(volume, volumesToSnap, snapshotType, snapshotName, readOnly, fcManager);
    String taskId = UUID.randomUUID().toString();
    List<URI> snapshotURIs = new ArrayList<URI>();
    List<BlockSnapshot> snapshots = api.prepareSnapshots(volumesToSnap, snapshotType, snapshotName, snapshotURIs, taskId);
    TaskList response = new TaskList();
    for (BlockSnapshot snapshot : snapshots) {
        response.getTaskList().add(toTask(snapshot, taskId));
    }
    // Update the task status for the volumes task.
    _dbClient.createTaskOpStatus(Volume.class, volume.getId(), taskId, ResourceOperationTypeEnum.CREATE_VOLUME_SNAPSHOT);
    // Invoke the block service API implementation to create the snapshot
    api.createSnapshot(volume, snapshotURIs, snapshotType, createInactive, readOnly, taskId);
    SnapshotCreateResponse snapCreateResp = new SnapshotCreateResponse();
    for (TaskResourceRep rep : response.getTaskList()) {
        URI snapshotUri = rep.getResource().getId();
        BlockSnapshot snap = _dbClient.queryObject(BlockSnapshot.class, snapshotUri);
        if (snap != null) {
            StringMap extensions = snap.getExtensions();
            if (extensions == null)
                extensions = new StringMap();
            extensions.put("display_description", (snapshotDescription == null) ? "" : snapshotDescription);
            extensions.put("taskid", rep.getId().toString());
            _log.debug("Create snapshot : stored description");
            snap.setExtensions(extensions);
            ScopedLabelSet tagSet = new ScopedLabelSet();
            snap.setTag(tagSet);
            String[] splits = snapshotUri.toString().split(":");
            String tagName = splits[3];
            // this check will verify whether  retrieved data is not corrupted
            if (tagName == null || tagName.isEmpty() || tagName.length() < 2) {
                throw APIException.badRequests.parameterTooShortOrEmpty("Tag", 2);
            }
            Volume parentVol = _permissionsHelper.getObjectById(snap.getParent(), Volume.class);
            URI tenantOwner = parentVol.getTenant().getURI();
            ScopedLabel tagLabel = new ScopedLabel(tenantOwner.toString(), tagName);
            tagSet.add(tagLabel);
            _dbClient.updateObject(snap);
            if (isV1Call != null) {
                _log.debug("Inside V1 call");
                return CinderApiUtils.getCinderResponse(getSnapshotDetail(snap, isV1Call, openstack_tenant_id), header, true, CinderConstants.STATUS_OK);
            } else {
                return CinderApiUtils.getCinderResponse(getSnapshotDetail(snap, isV1Call, openstack_tenant_id), header, true, CinderConstants.STATUS_ACCEPT);
            }
        }
    }
    return CinderApiUtils.getCinderResponse(new CinderSnapshot(), header, true, CinderConstants.STATUS_ACCEPT);
}
Also used : SnapshotCreateResponse(com.emc.storageos.cinder.model.SnapshotCreateResponse) StringMap(com.emc.storageos.db.client.model.StringMap) TaskList(com.emc.storageos.model.TaskList) ArrayList(java.util.ArrayList) BlockSnapshot(com.emc.storageos.db.client.model.BlockSnapshot) TaskResourceRep(com.emc.storageos.model.TaskResourceRep) VirtualPool(com.emc.storageos.db.client.model.VirtualPool) URI(java.net.URI) BlockServiceApi(com.emc.storageos.api.service.impl.resource.BlockServiceApi) ScopedLabelSet(com.emc.storageos.db.client.model.ScopedLabelSet) BlockFullCopyManager(com.emc.storageos.api.service.impl.resource.fullcopy.BlockFullCopyManager) CinderSnapshot(com.emc.storageos.cinder.model.CinderSnapshot) Volume(com.emc.storageos.db.client.model.Volume) ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces)

Example 10 with ScopedLabel

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

the class DbObjectMapper method mapDataObjectFieldsNoLink.

public static void mapDataObjectFieldsNoLink(DataObject from, DataObjectRestRep to) {
    to.setId(from.getId());
    to.setName(from.getLabel());
    to.setCreationTime(from.getCreationTime());
    to.setInactive(from.getInactive());
    to.setGlobal(from.isGlobal());
    to.setRemote(to.getGlobal() ? null : VdcUtil.isRemoteObject(from));
    if (from.getTag() != null) {
        for (ScopedLabel tag : from.getTag()) {
            to.getTags().add(tag.getLabel());
        }
    }
    to.setVdc(toRelatedResource(ResourceTypeEnum.VDC, VdcUtil.getVdcUrn(VdcUtil.getVdcId(from.getClass(), from.getId()).toString())));
    if (from.checkInternalFlags(DataObject.Flag.INTERNAL_OBJECT)) {
        to.setInternal(true);
    } else {
        to.setInternal(false);
    }
}
Also used : ScopedLabel(com.emc.storageos.db.client.model.ScopedLabel)

Aggregations

ScopedLabel (com.emc.storageos.db.client.model.ScopedLabel)23 ScopedLabelSet (com.emc.storageos.db.client.model.ScopedLabelSet)14 URI (java.net.URI)9 Volume (com.emc.storageos.db.client.model.Volume)7 NamedURI (com.emc.storageos.db.client.model.NamedURI)6 ArrayList (java.util.ArrayList)5 Host (com.emc.storageos.db.client.model.Host)4 Project (com.emc.storageos.db.client.model.Project)4 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)4 Consumes (javax.ws.rs.Consumes)4 POST (javax.ws.rs.POST)4 Produces (javax.ws.rs.Produces)4 BlockServiceApi (com.emc.storageos.api.service.impl.resource.BlockServiceApi)3 BlockConsistencyGroup (com.emc.storageos.db.client.model.BlockConsistencyGroup)3 BlockSnapshot (com.emc.storageos.db.client.model.BlockSnapshot)3 StringMap (com.emc.storageos.db.client.model.StringMap)3 TaskList (com.emc.storageos.model.TaskList)3 TaskResourceRep (com.emc.storageos.model.TaskResourceRep)3 BlockFullCopyManager (com.emc.storageos.api.service.impl.resource.fullcopy.BlockFullCopyManager)2 DbClient (com.emc.storageos.db.client.DbClient)2