Search in sources :

Example 16 with FCZoneReference

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

the class ExportUtils method getItlsForMaskInitiator.

/**
 * For a volume/snapshot-initiator pair find the target ports for the initiator in the list of
 * ports and find the zone name if zoning was performed. Return a list of ITLs for
 * each volume-initiator-target found.
 *
 * @param dbClient db client
 * @param exportMask the export mask the initiator is in
 * @param initiator the initiator
 * @param hlu the lun Id used by the initiator for the volume
 * @param blockObject the volume or snapshot
 * @param initiatorPorts ports to which the initiator is zoned in the export mask
 * @param zoneRefs a map of port-to-zone-reference
 * @param exportGroup the export groups in this export mask
 * @return all ITLs for a volume/snapshot-initiator pair.
 */
private static List<ITLRestRep> getItlsForMaskInitiator(DbClient dbClient, List<ExportGroup> exportGroups, ExportMask exportMask, Initiator initiator, String hlu, BlockObject blockObject, List<StoragePort> initiatorPorts, Map<StoragePort, List<FCZoneReference>> zoneRefs) {
    List<ITLRestRep> list = new ArrayList<ITLRestRep>();
    Map<StoragePort, FCZoneReference> initiatorZoneRefs = null;
    // Find the block object that would appear in the Export Mask
    BlockObject bo = Volume.fetchExportMaskBlockObject(dbClient, blockObject.getId());
    if (bo != null) {
        _log.debug("Finding target ports for initiator {} and block object {}", initiator.getInitiatorPort(), bo.getNativeGuid());
        initiatorZoneRefs = getZoneReferences(bo.getId(), initiator, initiatorPorts, zoneRefs);
        _log.debug("{} target ports and {} SAN zones were found for initiator {} and block object {}", new Object[] { initiatorPorts.size(), initiatorZoneRefs.size(), initiator.getInitiatorPort(), bo.getNativeGuid() });
        // TODO - Should we add special handling of iscsi initiators?
        for (ExportGroup exportGroup : exportGroups) {
            if (exportGroup.getVolumes() != null && exportGroup.getVolumes().containsKey(blockObject.getId().toString()) && exportGroup.getInitiators() != null && exportGroup.getInitiators().contains(initiator.getId().toString())) {
                // We want to check if there are any ports in this export group for this initiator
                List<StoragePort> portsInExportGroupVarray = filterPortsInVarray(exportGroup, exportMask.getStorageDevice(), initiatorPorts);
                if (!portsInExportGroupVarray.isEmpty()) {
                    for (StoragePort port : portsInExportGroupVarray) {
                        list.add(createInitiatorTargetRefRep(exportGroup, blockObject, hlu, initiator, port, initiatorZoneRefs.get(port)));
                    }
                } else {
                    list.add(createInitiatorTargetRefRep(exportGroup, blockObject, hlu, initiator, null, null));
                }
            }
        }
    }
    return list;
}
Also used : ExportGroup(com.emc.storageos.db.client.model.ExportGroup) ArrayList(java.util.ArrayList) StoragePort(com.emc.storageos.db.client.model.StoragePort) ITLRestRep(com.emc.storageos.model.block.export.ITLRestRep) BlockObject(com.emc.storageos.db.client.model.BlockObject) FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference)

Example 17 with FCZoneReference

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

the class ZoneReferencesRemoveCompleter method complete.

@Override
protected void complete(DbClient dbClient, Operation.Status status, ServiceCoded coded) throws DeviceControllerException {
    if (removeZoneReferences || status == Status.error) {
        String refKey = null;
        try {
            for (URI fcZoneReferenceId : getIds()) {
                if (NullColumnValueGetter.isNullURI(fcZoneReferenceId)) {
                    _log.info("fcZoneReferenceId is null. Nothing to remove.");
                    continue;
                }
                FCZoneReference ref = dbClient.queryObject(FCZoneReference.class, fcZoneReferenceId);
                if (ref != null) {
                    refKey = ref.getPwwnKey();
                    _log.info(String.format("Remove FCZoneReference key: %s volume %s id %s", ref.getPwwnKey(), ref.getVolumeUri(), ref.getId().toString()));
                    dbClient.removeObject(ref);
                }
            }
        } catch (DatabaseException ex) {
            _log.error("Could not persist FCZoneReference: " + refKey);
        }
    }
    updateWorkflowStatus(status, coded);
}
Also used : URI(java.net.URI) DatabaseException(com.emc.storageos.db.exceptions.DatabaseException) FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference)

Example 18 with FCZoneReference

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

the class ExportMaskUtils method createFCZoneReference.

/**
 * Creates an instance of FCZoneReference
 *
 * @param info the zone info containing the zone, its network,
 *            its network system, ...
 * @param initiator the zone initiator
 * @param volume volume the FCZoneReference volume
 * @param exportGroup the FCZoneReference export group
 * @param externalZone - should be true for externally managed zone
 * @return an instance of FCZoneReference
 */
private static <T extends BlockObject> FCZoneReference createFCZoneReference(ZoneInfo info, Initiator initiator, T volume, ExportGroup exportGroup, boolean externalZone) {
    FCZoneReference ref = new FCZoneReference();
    ref.setPwwnKey(info.getZoneReferenceKey());
    ref.setFabricId(info.getFabricId());
    ref.setNetworkSystemUri(URI.create(info.getNetworkSystemId()));
    ref.setVolumeUri(volume.getId());
    ref.setGroupUri(exportGroup.getId());
    ref.setZoneName(info.getZoneName());
    ref.setId(URIUtil.createId(FCZoneReference.class));
    ref.setLabel(FCZoneReference.makeLabel(ref.getPwwnKey(), volume.getId().toString()));
    ref.setExistingZone(externalZone);
    return ref;
}
Also used : FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference)

Example 19 with FCZoneReference

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

the class FCZoneReferenceMigration method initializeField.

/**
 * For all FC Zone Reference objects
 */
private void initializeField() {
    log.info("Updating FC Zone reference label object to be more searchable");
    DbClient dbClient = this.getDbClient();
    List<URI> fcZoneRefs = dbClient.queryByType(FCZoneReference.class, false);
    Iterator<FCZoneReference> refs = dbClient.queryIterativeObjects(FCZoneReference.class, fcZoneRefs);
    while (refs.hasNext()) {
        FCZoneReference ref = refs.next();
        log.info("Examining block ref (id={}) for upgrade", ref.getId().toString());
        String label = ref.getLabel();
        // Criteria to switch over the label that is that it does not contain a second underscore
        if (label == null || !label.matches(".*_.*_.*")) {
            log.info("Resetting label:", label);
            ref.setLabel(FCZoneReference.makeLabel(label, ref.getVolumeUri().toString()));
            dbClient.updateObject(ref);
        }
    }
}
Also used : DbClient(com.emc.storageos.db.client.DbClient) URI(java.net.URI) FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference)

Example 20 with FCZoneReference

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

the class ExportMaskUtils method createFCZoneReferences.

/**
 * Create FCZoneReference objects according to the list of zoneInfoMap.
 * This is used for ingestion.
 *
 * The zones will be ingested as existingZone = false (allowing deletion of the zone when the last reference is removed)
 * if all the following criteria are met:
 * 1. The export mask being ingested must have no existing (non-vipr-created) volumes.
 * 2. If the zone must not have more than two members (smartZone), as Vipr cannot yet manage smart zones.
 * 3. The zone name that would be generated for the zone must be the same as the ingested zone's name, unless the
 * controllersvc config variable controller_ingest_zones_with_non_vipr_name is set to true, bypassing the zone name check.
 * 4. The zone must not be used in any other UnManagedExportMask (export mask which has not yet been ingested).
 *
 * @param volume the FCZoneReference volume
 * @param exportGroup the FCZoneReference export group
 * @param exportMask the ExportMask being ingested or initialized
 * @param zoneInfoMap the zone info maps
 * @param initiators the initiators
 * @param updatedZoneReferences OUT parameter of zone references to be updated
 * @param dbClient -- Database handle
 * @return a list of FCZoneReference
 */
private static <T extends BlockObject> List<FCZoneReference> createFCZoneReferences(T volume, ExportGroup exportGroup, ExportMask exportMask, ZoneInfoMap zoneInfoMap, List<Initiator> initiators, List<FCZoneReference> updatedZoneReferences, DbClient dbClient) {
    boolean bypassNameCheck = false;
    if (coordinator == null) {
        ApplicationContext context = AttributeMatcherFramework.getApplicationContext();
        coordinator = (CoordinatorClient) context.getBean("coordinator");
    }
    bypassNameCheck = Boolean.valueOf(ControllerUtils.getPropertyValueFromCoordinator(coordinator, INGEST_ZONES_WITH_NON_VIPR_NAME));
    List<FCZoneReference> createdRefs = new ArrayList<FCZoneReference>();
    if (networkScheduler == null) {
        ApplicationContext context = AttributeMatcherFramework.getApplicationContext();
        networkScheduler = (NetworkScheduler) context.getBean("networkScheduler");
    }
    for (Initiator initiator : initiators) {
        for (ZoneInfo info : zoneInfoMap.values()) {
            if (info.getInitiatorId().equals(initiator.getId().toString())) {
                Boolean hasExistingVolumes = exportMask.hasAnyExistingVolumes();
                // Determine if the zone to be ingested has a compatible zone name.
                Boolean lsanZone = networkScheduler.isLSANZone(info.getZoneName());
                // Determine if the zone has more than two members. We can't currently manage smart zones fully.
                Boolean smartZone = (info.getMemberCount() > 2);
                _log.info(String.format("zone %s existingVolumes %s lsanZone %s smartZone %s", info.getZoneName(), hasExistingVolumes.toString(), lsanZone.toString(), smartZone.toString()));
                String generatedZoneName = networkScheduler.nameZone(volume.getStorageController(), URI.create(info.getNetworkSystemId()), info.getInitiatorWwn(), info.getPortWwn(), info.getFabricId(), lsanZone);
                _log.info(String.format("Zone name %s generated zone name %s", info.getZoneName(), generatedZoneName));
                boolean usedInUnmanagedMasks = checkZoneUseInUnManagedExportMasks(exportMask.getMaskName(), info, dbClient);
                boolean externalZone = hasExistingVolumes || (!bypassNameCheck && !generatedZoneName.equals(info.getZoneName())) || usedInUnmanagedMasks || smartZone;
                if (!externalZone) {
                    // Find any existing zone references so they can be updated to fully managed (i.e. not existingZone)
                    List<FCZoneReference> existingZoneRefs = networkScheduler.getFCZoneReferencesForKey(info.getZoneReferenceKey());
                    for (FCZoneReference zoneRef : existingZoneRefs) {
                        // and the zoneRef URI is invalid, mark the zone reference for deletion as it is stale, and do not process it.
                        if (!exportGroup.hasBlockObject(zoneRef.getVolumeUri())) {
                            BlockObject blockObject = BlockObject.fetch(dbClient, zoneRef.getVolumeUri());
                            if (blockObject == null) {
                                _log.info(String.format("Deleting FCZoneReference %s which has invalid volume URI %s", zoneRef.getZoneName(), zoneRef.getVolumeUri()));
                                dbClient.markForDeletion(zoneRef);
                                continue;
                            }
                        }
                        // Update this reference to fully managed (existingZone = false)
                        zoneRef.setExistingZone(false);
                        updatedZoneReferences.add(zoneRef);
                    }
                }
                createdRefs.add(createFCZoneReference(info, initiator, volume, exportGroup, externalZone));
            }
        }
    }
    return createdRefs;
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) Initiator(com.emc.storageos.db.client.model.Initiator) ArrayList(java.util.ArrayList) ZoneInfo(com.emc.storageos.db.client.model.ZoneInfo) BlockObject(com.emc.storageos.db.client.model.BlockObject) FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference)

Aggregations

FCZoneReference (com.emc.storageos.db.client.model.FCZoneReference)34 URI (java.net.URI)15 ArrayList (java.util.ArrayList)14 StoragePort (com.emc.storageos.db.client.model.StoragePort)10 HashMap (java.util.HashMap)8 ExportGroup (com.emc.storageos.db.client.model.ExportGroup)6 Volume (com.emc.storageos.db.client.model.Volume)6 Initiator (com.emc.storageos.db.client.model.Initiator)5 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)5 List (java.util.List)5 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)4 NetworkSystem (com.emc.storageos.db.client.model.NetworkSystem)4 NetworkFCZoneInfo (com.emc.storageos.networkcontroller.NetworkFCZoneInfo)4 Zone (com.emc.storageos.networkcontroller.impl.mds.Zone)4 ZoneMember (com.emc.storageos.networkcontroller.impl.mds.ZoneMember)4 DbClient (com.emc.storageos.db.client.DbClient)3 BlockObject (com.emc.storageos.db.client.model.BlockObject)3 BulkList (com.emc.storageos.api.service.impl.response.BulkList)2 ExportMask (com.emc.storageos.db.client.model.ExportMask)2 Network (com.emc.storageos.db.client.model.Network)2