Search in sources :

Example 1 with StringSet

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

the class NetworkDeviceController method refreshZoningMap.

/**
 * Update the zoning map for as export mask previously "accepted". This applies to
 * brown field scenarios where a export mask was found on the storage array. For
 * those export masks, changes outside of the application are expected and the
 * application should get the latest state before making any changes. This
 * function is called from ExportMaskOperations#refreshZoneMap after all
 * updates to the initiators, ports and volumes were made into the export mask and
 * the export group. The update steps are as follow:
 * <ol>
 * <li>Get the current zones for those initiators that were not added by ViPR and the storage ports that exist in the mask.</li>
 * <li>Diff the current zones with those in the export mask and update the zoning map</li>
 * <li>Update the FCZoneReferences to match the zone updates</li>
 * </ol>
 * Note that ViPR does not keep FCZoneReferences only for volumes created by ViPR. As those
 * volumes are not updated by ExportMaskOperations#refreshZoneMap, no additional code
 * is needed to remove FCZoneReferences for removed volumes.
 *
 * @param exportMask the export mask being updated.
 * @param removedInitiators the list of initiators that were removed. This is needed because
 *            these were removed from the zoingMap by {@link ExportMask#removeInitiators(Collection)}
 * @param removedPorts the set of storage ports that were removed
 * @param maskUpdated a flag that indicates if an update was made to the mask that requires
 *            a zoning refresh
 * @param persist a boolean that indicates if the changes should be persisted in the db
 */
public void refreshZoningMap(ExportMask exportMask, Collection<String> removedInitiators, Collection<String> removedPorts, boolean maskUpdated, boolean persist) {
    try {
        // check if zoning is enabled for the mask
        if (!zoningEnabled(exportMask)) {
            _log.info("Zoning not enabled for export mask {}. Zoning refresh will not be done", exportMask.getMaskName());
            return;
        }
        if (!(maskUpdated || alwaysRefreshZone())) {
            _log.info("The mask ports and initiators were not modified and alwaysRefreshZones is false" + " Zoning refresh will not be done for mask {}", exportMask.getMaskName());
            return;
        }
        List<Initiator> initiators = ExportUtils.getExportMaskInitiators(exportMask, _dbClient);
        _log.info("Refreshing zones for export mask {}. \n\tCurrent initiators " + "in this mask are:  {}. \n\tStorage ports in the mask are : {}. \n\tZoningMap is : {}. " + "\n\tRemoved initiators: {}. \n\tRemoved ports: {}", new Object[] { exportMask.getMaskName(), exportMask.getInitiators(), exportMask.getStoragePorts(), exportMask.getZoningMap(), removedInitiators, removedPorts });
        Long start = System.currentTimeMillis();
        // get the current zones in the network system for initiators and ports
        List<StoragePort> storagePorts = ExportUtils.getStoragePorts(exportMask, _dbClient);
        ZoneInfoMap zoneInfoMap = getInitiatorsZoneInfoMap(initiators, storagePorts);
        // Get the full sets of initiators and ports affected. They will be used to find the FCZoneReferences to refresh
        // These sets include new initiators and ports, existing ones that did not change, as well as removed ones
        List<StoragePort> allStoragePorts = DataObjectUtils.iteratorToList(_dbClient.queryIterativeObjects(StoragePort.class, StringSetUtil.stringSetToUriList(removedPorts)));
        allStoragePorts.addAll(storagePorts);
        List<Initiator> allInitiators = DataObjectUtils.iteratorToList(_dbClient.queryIterativeObjects(Initiator.class, StringSetUtil.stringSetToUriList(removedInitiators)));
        allInitiators.addAll(initiators);
        // Make a copy of the zoning mask - Zones have already been removed for removed initiators, put them back
        // This zoning map will be used to do diff between old and new and to get zone references
        StringSetMap allZonesMap = new StringSetMap();
        StringSetMap tempMap = exportMask.getZoningMap() == null ? new StringSetMap() : exportMask.getZoningMap();
        for (String key : tempMap.keySet()) {
            // when the zoning map is removed prematurely, this ports set is empty but not null
            if (removedInitiators.contains(key) && (tempMap.get(key) == null || tempMap.get(key).isEmpty())) {
                // this was prematurely cleared, we will assume all ports
                // were zoned to make sure we clean up all FCZoneReferences
                allZonesMap.put(key, new StringSet(removedPorts));
                if (exportMask.getStoragePorts() != null) {
                    allZonesMap.get(key).addAll(exportMask.getStoragePorts());
                }
            } else {
                allZonesMap.put(key, new StringSet(tempMap.get(key)));
            }
        }
        // get all the zone references that exist in the database for this export mask.
        Map<String, List<FCZoneReference>> existingRefs = getZoneReferences(allZonesMap, allInitiators, allStoragePorts);
        // initialize results collections
        List<ZoneInfo> addedZoneInfos = new ArrayList<ZoneInfo>();
        List<ZoneInfo> updatedZoneInfos = new ArrayList<ZoneInfo>();
        List<String> removedZonesKeys = new ArrayList<String>();
        // Compare old and new zones. Initialize some loop variables.
        ZoneInfo zoneInfo = null;
        String initId = null;
        String portId = null;
        if (exportMask.getZoningMap() == null) {
            exportMask.setZoningMap(new StringSetMap());
        }
        for (Entry<String, ZoneInfo> entry : zoneInfoMap.entrySet()) {
            zoneInfo = entry.getValue();
            initId = zoneInfo.getInitiatorId();
            portId = zoneInfo.getPortId();
            if (exportMask.getZoningMap().containsKey(initId) && exportMask.getZoningMap().get(initId).contains(portId)) {
                _log.debug("Zoning between initiator {} and port {} did not change", zoneInfo.getInitiatorWwn(), zoneInfo.getPortWwn());
                // This is accounted for, let's remove it from our diff map
                allZonesMap.remove(initId, portId);
                // add the zone info so that it can be updated for changes like zone name change
                updatedZoneInfos.add(zoneInfo);
            } else {
                _log.info("New zone was found between initiator {} and port {} and will be added", zoneInfo.getInitiatorWwn(), zoneInfo.getPortWwn());
                // sometimes zones have more than one initiator or port
                if (exportMask.hasExistingInitiator(zoneInfo.getInitiatorWwn())) {
                    // This is a new entry, add it to the zoning map
                    exportMask.getZoningMap().put(initId, portId);
                    // add it to the results so that the appropriate FCZoneReferences are added
                    addedZoneInfos.add(zoneInfo);
                }
                // This zone is not expected to be in the diff map, but try anyway
                allZonesMap.remove(initId, portId);
            }
        }
        // If anything is remaining zones in the diff zoning map, these were removed in the network system
        Initiator initiator = null;
        StoragePort port = null;
        for (String key : allZonesMap.keySet()) {
            initiator = DataObjectUtils.findInCollection(allInitiators, key);
            if (allZonesMap.get(key) != null && !allZonesMap.get(key).isEmpty()) {
                for (String val : allZonesMap.get(key)) {
                    port = DataObjectUtils.findInCollection(allStoragePorts, val);
                    _log.info("Zone between initiator {} and port {} was removed from the network system" + " or no longer belongs to this mask.", key, val);
                    if (port == null || initiator == null) {
                        // the port or initiator were removed at some point
                        exportMask.getZoningMap().remove(key, val);
                        _log.info("Removed zoningMap entry between initiator {} and port {} because " + "the port and/or the initiator were removed from the mask", key, val);
                    } else if (removedInitiators.contains(key) || removedPorts.contains(val)) {
                        // the port or initiator were removed, remove the zone map entry
                        exportMask.getZoningMap().remove(key, val);
                        _log.info("Removed zoningMap entry between initiator {} and port {} because " + "the port and/or the initiator were removed from the mask", initiator.getInitiatorPort(), port.getPortNetworkId());
                    } else if (exportMask.hasExistingInitiator(WWNUtility.getUpperWWNWithNoColons(initiator.getInitiatorPort()))) {
                        exportMask.getZoningMap().remove(key, val);
                        _log.info("Removed zoningMap entry between initiator {} and port {} because " + "this was a brownfield zone for a brownfield initiator", initiator.getInitiatorPort(), port.getPortNetworkId());
                    } else {
                        _log.info("The zone between initiator {} and port {} was removed from " + " the network system but the zoningMap entry will be kept because it was" + " a ViPR initiator-port assignment", initiator.getInitiatorPort(), port.getPortNetworkId());
                    }
                    if (port != null && initiator != null) {
                        removedZonesKeys.add(FCZoneReference.makeEndpointsKey(initiator.getInitiatorPort(), port.getPortNetworkId()));
                    }
                }
            }
        }
        // get all the existing zone references from the database, these are
        refreshFCZoneReferences(exportMask, existingRefs, addedZoneInfos, updatedZoneInfos, removedZonesKeys);
        if (persist) {
            _dbClient.updateAndReindexObject(exportMask);
        }
        _log.info("Changed zones for export mask {} to {}. \nRefreshing zones took {} ms", new Object[] { exportMask.getMaskName(), exportMask.getZoningMap(), (System.currentTimeMillis() - start) });
    } catch (Exception ex) {
        _log.error("An exception occurred while updating zoning map for export mask {} with message {}", new Object[] { exportMask.getMaskName(), ex.getMessage() }, ex);
    }
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) StoragePort(com.emc.storageos.db.client.model.StoragePort) ZoneInfoMap(com.emc.storageos.db.client.model.ZoneInfoMap) ArrayList(java.util.ArrayList) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) DeviceControllerException(com.emc.storageos.exceptions.DeviceControllerException) ControllerException(com.emc.storageos.volumecontroller.ControllerException) NetworkDeviceControllerException(com.emc.storageos.networkcontroller.exceptions.NetworkDeviceControllerException) Initiator(com.emc.storageos.db.client.model.Initiator) StringSet(com.emc.storageos.db.client.model.StringSet) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) DiscoveredDataObject(com.emc.storageos.db.client.model.DiscoveredDataObject) NetworkFCZoneInfo(com.emc.storageos.networkcontroller.NetworkFCZoneInfo) ZoneInfo(com.emc.storageos.db.client.model.ZoneInfo)

Example 2 with StringSet

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

the class ViPRService method addRetainedReplicas.

protected <T extends DataObjectRestRep> void addRetainedReplicas(URI sourceId, String replicaName) {
    if (!isRetentionRequired()) {
        return;
    }
    ScheduledEvent event = ExecutionUtils.currentContext().getScheduledEvent();
    RetainedReplica retention = new RetainedReplica();
    retention.setScheduledEventId(event.getId());
    retention.setResourceId(sourceId);
    StringSet retainedResource = new StringSet();
    retention.setAssociatedReplicaIds(retainedResource);
    retainedResource.add(replicaName);
    modelClient.save(retention);
}
Also used : ScheduledEvent(com.emc.storageos.db.client.model.uimodels.ScheduledEvent) StringSet(com.emc.storageos.db.client.model.StringSet) RetainedReplica(com.emc.storageos.db.client.model.uimodels.RetainedReplica)

Example 3 with StringSet

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

the class ComputeUtils method getContextErrors.

public static String getContextErrors(ModelClient client) {
    String sep = System.lineSeparator();
    StringBuffer errBuff = new StringBuffer();
    StringSet logIds = ExecutionUtils.currentContext().getExecutionState().getLogIds();
    for (ExecutionLog l : client.executionLogs().findByIds(logIds)) {
        if (l.getLevel().equals(LogLevel.ERROR.name())) {
            errBuff.append(sep + sep + l.getMessage());
        }
    }
    return errBuff.toString();
}
Also used : ExecutionLog(com.emc.storageos.db.client.model.uimodels.ExecutionLog) StringSet(com.emc.storageos.db.client.model.StringSet)

Example 4 with StringSet

use of com.emc.storageos.db.client.model.StringSet 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);
    long sizeLong = SizeUtil.translateSize(size);
    volume.setCapacity(sizeLong);
    Long thinVolumePreAllocationSize = 0L;
    if (null != vpool.getThinVolumePreAllocationPercentage()) {
        thinVolumePreAllocationSize = VirtualPoolUtil.getThinVolumePreAllocationSize(vpool.getThinVolumePreAllocationPercentage(), sizeLong);
    }
    if (0 != thinVolumePreAllocationSize) {
        volume.setThinVolumePreAllocationSize(thinVolumePreAllocationSize);
    }
    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 5 with StringSet

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

the class ProjectService method unassignVNasServersFromProject.

/**
 * Unassigns VNAS server from project.
 *
 * @param id the URN of a ViPR Project
 * @param param Assign virtual NAS server parameters
 * @prereq none
 * @brief Unassign VNAS servers from project
 * @return No data returned in response body
 * @throws BadRequestException
 */
@PUT
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/unassign-vnas-servers")
@CheckPermission(roles = { Role.SYSTEM_ADMIN }, acls = { ACL.ALL, ACL.OWN })
public Response unassignVNasServersFromProject(@PathParam("id") URI id, VirtualNasParam param) {
    checkCompatibleVersion();
    Project project = getProjectById(id, true);
    Set<String> vNasIds = param.getVnasServers();
    if (vNasIds != null && !vNasIds.isEmpty()) {
        StringSet vnasServers = project.getAssignedVNasServers();
        if (!vnasServers.containsAll(vNasIds)) {
            throw APIException.badRequests.vNasServersNotAssociatedToProject();
        }
        if (vnasServers != null && !vnasServers.isEmpty()) {
            for (String vId : vNasIds) {
                URI vnasURI = URI.create(vId);
                VirtualNAS vnas = _permissionsHelper.getObjectById(vnasURI, VirtualNAS.class);
                ArgValidator.checkEntity(vnas, vnasURI, isIdEmbeddedInURL(vnasURI));
                if (vnasServers.contains(vId)) {
                    vnas.dissociateProject(id.toString());
                    _dbClient.updateObject(vnas);
                    project.getAssignedVNasServers().remove(vId);
                }
            }
            _dbClient.updateObject(project);
            _log.info("Successfully unassigned the VNAS servers from project : {} ", project.getLabel());
        } else {
            throw APIException.badRequests.noVNasServersAssociatedToProject(project.getLabel());
        }
    } else {
        throw APIException.badRequests.invalidEntryForProjectVNAS();
    }
    return Response.ok().build();
}
Also used : MapProject(com.emc.storageos.api.mapper.functions.MapProject) Project(com.emc.storageos.db.client.model.Project) VirtualNAS(com.emc.storageos.db.client.model.VirtualNAS) StringSet(com.emc.storageos.db.client.model.StringSet) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) PUT(javax.ws.rs.PUT) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Aggregations

StringSet (com.emc.storageos.db.client.model.StringSet)760 URI (java.net.URI)371 ArrayList (java.util.ArrayList)278 Volume (com.emc.storageos.db.client.model.Volume)189 NamedURI (com.emc.storageos.db.client.model.NamedURI)176 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)137 HashMap (java.util.HashMap)132 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)124 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)116 List (java.util.List)108 HashSet (java.util.HashSet)106 StoragePort (com.emc.storageos.db.client.model.StoragePort)90 StoragePool (com.emc.storageos.db.client.model.StoragePool)75 StringMap (com.emc.storageos.db.client.model.StringMap)74 VirtualPool (com.emc.storageos.db.client.model.VirtualPool)71 UnManagedVolume (com.emc.storageos.db.client.model.UnManagedDiscoveredObjects.UnManagedVolume)70 Initiator (com.emc.storageos.db.client.model.Initiator)60 DeviceControllerException (com.emc.storageos.exceptions.DeviceControllerException)60 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)50 Map (java.util.Map)48