Search in sources :

Example 11 with FCZoneReference

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

the class NetworkZoningParam method updateZoningParamUsingFCZoneReference.

/**
 * Build the zoningMap attribute of zoningParam using FCZoneReference and exportGroup
 *
 * @param zoningParam
 * @param initsToRemoveOnlyFromZone
 * @param exportGroup
 */
public static void updateZoningParamUsingFCZoneReference(List<NetworkZoningParam> zoningParam, List<URI> initsToRemoveOnlyFromZone, ExportGroup exportGroup, DbClient dbClient) {
    HashMap<String, Initiator> initiatorMap = new HashMap<String, Initiator>();
    for (URI initiatorURI : initsToRemoveOnlyFromZone) {
        Initiator iniObject = dbClient.queryObject(Initiator.class, initiatorURI);
        String iniString = iniObject.getInitiatorPort().toUpperCase();
        initiatorMap.put(iniString, iniObject);
    }
    // Retrieve FCZoneReference zone references that have the same initiator WWN.
    // These zone should be removed. since the initiator is no longer available.
    List<FCZoneReference> fcRefs = NetworkUtil.getFCZoneReferencesFromExportGroup(dbClient, exportGroup);
    Set<String> iniConsidered = new HashSet<String>();
    for (NetworkZoningParam networkZoningParam : zoningParam) {
        StringSetMap zoneMap = networkZoningParam.getZoningMap();
        if (zoneMap.isEmpty()) {
            for (FCZoneReference fcZoneReference : fcRefs) {
                String[] initiatorAndPort = getInitiatorAndPortFromPwwnKey(fcZoneReference.getPwwnKey());
                if (initiatorAndPort != null) {
                    String initiator = initiatorAndPort[0];
                    String port = initiatorAndPort[1];
                    Initiator iniObject = initiatorMap.get(initiator);
                    if (iniObject != null) {
                        StoragePort sp = NetworkUtil.getStoragePort(port, dbClient);
                        if (sp != null) {
                            iniConsidered.add(iniObject.getInitiatorPort());
                            zoneMap.put(iniObject.getId().toString(), sp.getId().toString());
                        }
                    }
                } else {
                    _log.warn("Could not obtain initiator and port correctly from the PwwnKey {}", fcZoneReference.getPwwnKey());
                }
            }
            // removed the initiator from map the as this initiator is considered for zone map
            if (!iniConsidered.isEmpty()) {
                initiatorMap.keySet().removeAll(iniConsidered);
            }
        }
    }
}
Also used : StringSetMap(com.emc.storageos.db.client.model.StringSetMap) HashMap(java.util.HashMap) StoragePort(com.emc.storageos.db.client.model.StoragePort) URI(java.net.URI) FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference) Initiator(com.emc.storageos.db.client.model.Initiator) HashSet(java.util.HashSet)

Example 12 with FCZoneReference

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

the class NetworkSystemService method deleteNetworkSystem.

/**
 * Delete a network system. The method will delete the
 * network system and all resources associated with it.
 *
 * @prereq The network system must be unregistered
 * @brief Delete network system
 * @return An asynchronous task.
 *
 * @throws DatabaseException
 *             When an error occurs querying the database.
 */
@POST
@Path("/{id}/deactivate")
@Consumes({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep deleteNetworkSystem(@PathParam("id") URI id) throws DatabaseException {
    NetworkSystem system = queryObject(NetworkSystem.class, id, true);
    ArgValidator.checkEntity(system, id, isIdEmbeddedInURL(id));
    if (!RegistrationStatus.UNREGISTERED.toString().equals(system.getRegistrationStatus())) {
        throw APIException.badRequests.invalidParameterCannotDeactivateRegisteredNetworkSystem(system.getId());
    }
    if (DiscoveredDataObject.DataCollectionJobStatus.IN_PROGRESS.toString().equals(system.getDiscoveryStatus()) || DiscoveredDataObject.DataCollectionJobStatus.SCHEDULED.toString().equals(system.getDiscoveryStatus())) {
        throw APIException.serviceUnavailable.cannotDeactivateStorageSystemWhileInDiscover(system.getId());
    }
    List<Network> networkList = CustomQueryUtility.queryActiveResourcesByConstraint(_dbClient, Network.class, AlternateIdConstraint.Factory.getConstraint(Network.class, "networkSystems", system.getId().toString()));
    for (Network network : networkList) {
        if (network != null && network.getInactive() != true && network.getConnectedVirtualArrays() != null && !network.getConnectedVirtualArrays().isEmpty() && (network.getNetworkSystems() != null && network.getNetworkSystems().contains(system.getId().toString()) && network.getNetworkSystems().size() == 1)) {
            throw APIException.badRequests.invalidParameterNetworkMustBeUnassignedFromVirtualArray(network.getLabel(), system.getLabel());
        }
    }
    Map<String, List<FCZoneReference>> zonesMap = getNetworkSystemZoneRefs(system);
    List<URI> nsystems = null;
    List<FCZoneReference> zones = null;
    // by the purge process
    for (Network network : networkList) {
        // remove references from ports
        nsystems = StringSetUtil.stringSetToUriList(network.getNetworkSystems());
        nsystems.remove(system.getId());
        if (nsystems.isEmpty()) {
            // This network will be removed - Remove any storage port references
            List<StoragePort> netPorts = NetworkAssociationHelper.getNetworkStoragePorts(network.getId().toString(), null, _dbClient);
            NetworkAssociationHelper.clearPortAssociations(netPorts, _dbClient);
        } else {
            // This network will remain, update any zone references to use another network system
            URI nsUri = nsystems.get(0);
            zones = zonesMap.get(network.getNativeId());
            if (zones != null) {
                for (FCZoneReference zone : zones) {
                    zone.setNetworkSystemUri(nsUri);
                }
                _dbClient.updateObject(zones);
            }
        }
    }
    String taskId = UUID.randomUUID().toString();
    Operation op = _dbClient.createTaskOpStatus(NetworkSystem.class, system.getId(), taskId, ResourceOperationTypeEnum.DELETE_NETWORK_SYSTEM);
    PurgeRunnable.executePurging(_dbClient, _dbPurger, _asynchJobService.getExecutorService(), system, _retry_attempts, taskId, 60);
    auditOp(OperationTypeEnum.DELETE_NETWORK_SYSTEM, true, AuditLogManager.AUDITOP_BEGIN, system.getId().toString(), system.getLabel(), system.getPortNumber(), system.getUsername(), system.getSmisProviderIP(), system.getSmisPortNumber(), system.getSmisUserName(), system.getSmisUseSSL(), system.getVersion(), system.getUptime());
    return toTask(system, taskId, op);
}
Also used : NetworkSystem(com.emc.storageos.db.client.model.NetworkSystem) MapNetworkSystem(com.emc.storageos.api.mapper.functions.MapNetworkSystem) StoragePort(com.emc.storageos.db.client.model.StoragePort) Operation(com.emc.storageos.db.client.model.Operation) URI(java.net.URI) FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference) Network(com.emc.storageos.db.client.model.Network) NetworkSystemList(com.emc.storageos.model.network.NetworkSystemList) List(java.util.List) ArrayList(java.util.ArrayList) TaskList(com.emc.storageos.model.TaskList) BulkList(com.emc.storageos.api.service.impl.response.BulkList) 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 13 with FCZoneReference

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

the class AbstractBlockServiceApiImpl method deleteVolumes.

/**
 * {@inheritDoc}
 *
 * @throws InternalException
 */
@Override
public void deleteVolumes(URI systemURI, List<URI> volumeURIs, String deletionType, String task) throws InternalException {
    // Get volume descriptor for all volumes to be deleted.
    List<VolumeDescriptor> volumeDescriptors = getDescriptorsForVolumesToBeDeleted(systemURI, volumeURIs, deletionType);
    // the controller and delete the volumes.
    if (VolumeDeleteTypeEnum.VIPR_ONLY.name().equals(deletionType)) {
        // Do any cleanup necessary for the ViPR only delete.
        cleanupForViPROnlyDelete(volumeDescriptors);
        // Mark them inactive. Note that some of the volumes may be mirrors,
        // which have a different database type.
        List<VolumeDescriptor> descriptorsForMirrors = VolumeDescriptor.getDescriptors(volumeDescriptors, VolumeDescriptor.Type.BLOCK_MIRROR);
        _dbClient.markForDeletion(_dbClient.queryObject(BlockMirror.class, VolumeDescriptor.getVolumeURIs(descriptorsForMirrors)));
        List<VolumeDescriptor> descriptorsForVolumes = VolumeDescriptor.filterByType(volumeDescriptors, null, new VolumeDescriptor.Type[] { VolumeDescriptor.Type.BLOCK_MIRROR });
        _dbClient.markForDeletion(_dbClient.queryObject(Volume.class, VolumeDescriptor.getVolumeURIs(descriptorsForVolumes)));
        // Delete the corresponding FCZoneReferences
        for (URI volumeURI : volumeURIs) {
            List<FCZoneReference> zoneReferences = CustomQueryUtility.queryActiveResourcesByAltId(_dbClient, FCZoneReference.class, "volumeUri", volumeURI.toString());
            for (FCZoneReference zoneReference : zoneReferences) {
                if (zoneReference != null) {
                    _dbClient.markForDeletion(zoneReference);
                }
            }
        }
        // Update the task status for each volume
        for (URI volumeURI : volumeURIs) {
            Volume volume = _dbClient.queryObject(Volume.class, volumeURI);
            Operation op = volume.getOpStatus().get(task);
            op.ready("Volume succesfully deleted from ViPR");
            volume.getOpStatus().updateTaskStatus(task, op);
            _dbClient.updateObject(volume);
        }
    } else {
        BlockOrchestrationController controller = getController(BlockOrchestrationController.class, BlockOrchestrationController.BLOCK_ORCHESTRATION_DEVICE);
        controller.deleteVolumes(volumeDescriptors, task);
    }
}
Also used : VolumeDescriptor(com.emc.storageos.blockorchestrationcontroller.VolumeDescriptor) BlockOrchestrationController(com.emc.storageos.blockorchestrationcontroller.BlockOrchestrationController) BlockMirror(com.emc.storageos.db.client.model.BlockMirror) Volume(com.emc.storageos.db.client.model.Volume) Operation(com.emc.storageos.db.client.model.Operation) NamedURI(com.emc.storageos.db.client.model.NamedURI) URI(java.net.URI) FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference)

Example 14 with FCZoneReference

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

the class ExportUtils method getZoneReferences.

/**
 * Find the san zone information for the initiator/block object.
 *
 * @param blockObjectUri the block object URI
 * @param initiator the initiator
 * @param ports the target ports
 * @param refs a map of port-to-zone-reference
 * @return the list of san zones created for the initiator if any were created. Otherwise, an returns empty map.
 */
private static Map<StoragePort, FCZoneReference> getZoneReferences(URI blockObjectUri, Initiator initiator, List<StoragePort> ports, Map<StoragePort, List<FCZoneReference>> refs) {
    Map<StoragePort, FCZoneReference> targetPortReferences = new HashMap<StoragePort, FCZoneReference>();
    if (initiator.getProtocol().equals(Block.FC.name())) {
        for (StoragePort port : ports) {
            for (FCZoneReference ref : refs.get(port)) {
                if (ref != null && !ref.getInactive() && blockObjectUri.equals(ref.getVolumeUri())) {
                    targetPortReferences.put(port, ref);
                    // there should be one only
                    break;
                }
            }
        }
    }
    _log.debug("Found {} san zone references for initiator {} and block object {}", new Object[] { targetPortReferences.size(), initiator.getInitiatorPort(), blockObjectUri });
    return targetPortReferences;
}
Also used : HashMap(java.util.HashMap) StoragePort(com.emc.storageos.db.client.model.StoragePort) FCZoneReference(com.emc.storageos.db.client.model.FCZoneReference)

Example 15 with FCZoneReference

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

the class ExportUtils method getInitiatorsZoneReferences.

/**
 * Find the san zone information for the initiator and storage ports. Returns
 * a map of zone references per port.
 *
 * @param initiator the initiator
 * @param ports the target ports
 * @param dbClient an instance of {@link DbClient}
 * @return a map of san zones created for the initiator grouped by port for
 *         the list of target ports. Otherwise, an returns empty map.
 */
private static Map<StoragePort, List<FCZoneReference>> getInitiatorsZoneReferences(Initiator initiator, List<StoragePort> ports, DbClient dbClient) {
    Map<StoragePort, List<FCZoneReference>> targetPortReferences = new HashMap<StoragePort, List<FCZoneReference>>();
    if (initiator.getProtocol().equals(Block.FC.name())) {
        List<FCZoneReference> refs = null;
        for (StoragePort port : ports) {
            String key = FCZoneReference.makeEndpointsKey(Arrays.asList(initiator.getInitiatorPort(), port.getPortNetworkId()));
            refs = new ArrayList<FCZoneReference>();
            targetPortReferences.put(port, refs);
            URIQueryResultList queryList = new URIQueryResultList();
            dbClient.queryByConstraint(AlternateIdConstraint.Factory.getFCZoneReferenceKeyConstraint(key), queryList);
            Iterator<FCZoneReference> refsUris = dbClient.queryIterativeObjects(FCZoneReference.class, iteratorToList(queryList));
            FCZoneReference ref = null;
            while (refsUris.hasNext()) {
                ref = refsUris.next();
                if (ref != null && !ref.getInactive()) {
                    refs.add(ref);
                }
            }
        }
    }
    return targetPortReferences;
}
Also used : HashMap(java.util.HashMap) StoragePort(com.emc.storageos.db.client.model.StoragePort) ITLRestRepList(com.emc.storageos.model.block.export.ITLRestRepList) List(java.util.List) ArrayList(java.util.ArrayList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList) 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