Search in sources :

Example 26 with StoragePort

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

the class AbstractDefaultMaskingOrchestrator method maskHasStoragePortsInExportVarray.

/**
 * Check that export mask has at least one valid port from virtual array
 *
 * @param virtualArray
 * @param mask
 * @return
 */
protected boolean maskHasStoragePortsInExportVarray(VirtualArray virtualArray, ExportMask mask) {
    boolean isMatched = false;
    for (String uriString : mask.getStoragePorts()) {
        URI uri = URI.create(uriString);
        StoragePort port = _dbClient.queryObject(StoragePort.class, uri);
        // Basic validation of the StoragePort
        if (port == null || port.getInactive()) {
            _log.info(String.format("maskHasStoragePortsInExportVarray - Could not find port or it is inactive %s", uri.toString()));
            continue;
        }
        // StoragePort needs to be in the REGISTERED and VISIBLE status
        if (!port.getRegistrationStatus().equals(StoragePort.RegistrationStatus.REGISTERED.name()) || port.getDiscoveryStatus().equals(DiscoveryStatus.NOTVISIBLE.name())) {
            _log.info(String.format("maskHasStoragePortsInExportVarray - Port %s (%s) is not registered or not visible", port.getPortName(), uri.toString()));
            continue;
        }
        // Look up the StoragePort's network
        NetworkLite storagePortNetwork = BlockStorageScheduler.lookupNetworkLite(_dbClient, StorageProtocol.Transport.valueOf(port.getTransportType()), port.getPortNetworkId());
        if (storagePortNetwork == null) {
            _log.info(String.format("maskHasStoragePortsInExportVarray - Port %s (%s) is not associated with any network", port.getPortName(), uri.toString()));
            continue;
        }
        // Port must belong to the VArray
        if (!port.taggedToVirtualArray(virtualArray.getId())) {
            _log.info(String.format("maskHasStoragePortsInExportVarray - Port %s (%s) is not tagged to VArray %s (%s)", port.getPortName(), uri.toString(), virtualArray.getLabel(), virtualArray.getId()));
            // reverted the fix, as the probability of Consistent lun violation will be more.
            continue;
        }
        // at least one port is in virtualArray
        isMatched = true;
        break;
    }
    return isMatched;
}
Also used : NetworkLite(com.emc.storageos.util.NetworkLite) StoragePort(com.emc.storageos.db.client.model.StoragePort) URI(java.net.URI)

Example 27 with StoragePort

use of com.emc.storageos.db.client.model.StoragePort 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 28 with StoragePort

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

the class StoragePortService method deleteStoragePort.

/**
 * Remove a storage port. The method would remove the deregistered storage port and all resources
 * associated with the storage port from the database.
 * Note they are not removed from the storage system physically,
 * but become unavailable for the user.
 *
 * @param id the URN of a ViPR storage port to be removed.
 *
 * @brief Remove storage port from ViPR
 * @return Status indicating success or failure.
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deactivate")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public TaskResourceRep deleteStoragePort(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, StoragePort.class, "id");
    StoragePort port = queryResource(id);
    if (!RegistrationStatus.UNREGISTERED.toString().equalsIgnoreCase(port.getRegistrationStatus()) || DiscoveryStatus.VISIBLE.name().equalsIgnoreCase(port.getDiscoveryStatus())) {
        throw APIException.badRequests.cannotDeactivateStoragePort();
    }
    String taskId = UUID.randomUUID().toString();
    Operation op = _dbClient.createTaskOpStatus(StoragePool.class, id, taskId, ResourceOperationTypeEnum.DELETE_STORAGE_PORT);
    PurgeRunnable.executePurging(_dbClient, _dbPurger, _asynchJobService.getExecutorService(), port, _retry_attempts, taskId, 60);
    return toTask(port, taskId, op);
}
Also used : MapStoragePort(com.emc.storageos.api.mapper.functions.MapStoragePort) StoragePort(com.emc.storageos.db.client.model.StoragePort) Operation(com.emc.storageos.db.client.model.Operation) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 29 with StoragePort

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

the class StoragePortService method deregisterStoragePort.

/**
 * Allows the user to deregister a registered storage port so that it
 * is no longer used by the system. This simply sets the
 * registration_status of the storage port to UNREGISTERED.
 *
 * @param id the URN of a ViPR storage port.
 *
 * @brief Unregister storage port
 * @return Status response indicating success or failure
 */
@POST
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
@Path("/{id}/deregister")
@CheckPermission(roles = { Role.SYSTEM_ADMIN, Role.RESTRICTED_SYSTEM_ADMIN })
public StoragePortRestRep deregisterStoragePort(@PathParam("id") URI id) {
    ArgValidator.checkFieldUriType(id, StoragePort.class, "id");
    StoragePort port = queryResource(id);
    if (RegistrationStatus.REGISTERED.toString().equalsIgnoreCase(port.getRegistrationStatus())) {
        // Setting status to UNREGISTERED.
        port.setRegistrationStatus(RegistrationStatus.UNREGISTERED.toString());
        _dbClient.persistObject(port);
        // Record the storage port deregister event.
        recordStoragePortEvent(OperationTypeEnum.STORAGE_PORT_DEREGISTER, STORAGEPORT_DEREGISTERED_DESCRIPTION, port.getId());
        auditOp(OperationTypeEnum.DEREGISTER_STORAGE_PORT, true, null, port.getLabel(), port.getId().toString());
    }
    return MapStoragePort.getInstance(_dbClient).toStoragePortRestRep(port);
}
Also used : MapStoragePort(com.emc.storageos.api.mapper.functions.MapStoragePort) StoragePort(com.emc.storageos.db.client.model.StoragePort) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) CheckPermission(com.emc.storageos.security.authorization.CheckPermission)

Example 30 with StoragePort

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

the class StoragePortService method checkForDuplicatePortNetworkIdWithinSystem.

/**
 * Check if a storage port with the same portNetworkId exists for the passed storage system.
 *
 * @param dbClient the db client
 * @param portNetworkId the port network id
 * @param systemURI the system uri
 */
public static void checkForDuplicatePortNetworkIdWithinSystem(DbClient dbClient, String portNetworkId, URI systemURI) {
    URIQueryResultList portUriList = new URIQueryResultList();
    dbClient.queryByConstraint(AlternateIdConstraint.Factory.getStoragePortEndpointConstraint(portNetworkId), portUriList);
    Iterator<URI> storagePortIter = portUriList.iterator();
    while (storagePortIter.hasNext()) {
        StoragePort port = dbClient.queryObject(StoragePort.class, storagePortIter.next());
        if (port != null && !port.getInactive() && port.getStorageDevice().toString().equals(systemURI.toString())) {
            throw APIException.badRequests.duplicateEntityWithField("StoragePort", "portNetworkId");
        }
    }
}
Also used : MapStoragePort(com.emc.storageos.api.mapper.functions.MapStoragePort) StoragePort(com.emc.storageos.db.client.model.StoragePort) URI(java.net.URI) URIQueryResultList(com.emc.storageos.db.client.constraint.URIQueryResultList)

Aggregations

StoragePort (com.emc.storageos.db.client.model.StoragePort)477 URI (java.net.URI)285 ArrayList (java.util.ArrayList)261 URIQueryResultList (com.emc.storageos.db.client.constraint.URIQueryResultList)143 HashMap (java.util.HashMap)134 List (java.util.List)130 NetworkLite (com.emc.storageos.util.NetworkLite)110 StorageSystem (com.emc.storageos.db.client.model.StorageSystem)107 StringSet (com.emc.storageos.db.client.model.StringSet)92 PortAllocationContext (com.emc.storageos.volumecontroller.placement.StoragePortsAllocator.PortAllocationContext)84 HashSet (java.util.HashSet)81 Initiator (com.emc.storageos.db.client.model.Initiator)78 Map (java.util.Map)64 StringSetMap (com.emc.storageos.db.client.model.StringSetMap)62 StoragePool (com.emc.storageos.db.client.model.StoragePool)51 IOException (java.io.IOException)48 StringMap (com.emc.storageos.db.client.model.StringMap)45 BaseCollectionException (com.emc.storageos.plugins.BaseCollectionException)43 DatabaseException (com.emc.storageos.db.exceptions.DatabaseException)42 StorageHADomain (com.emc.storageos.db.client.model.StorageHADomain)34